Skip to content

Commit 6b16d7f

Browse files
anandgupta42claude
andcommitted
chore: upgrade @altimateai/altimate-core to 0.7.0 and sync consumer contracts
Engine upgrade 0.5.1 → 0.7.0 (through 0.6.0). Both releases are correctness releases whose output differs where the old output was wrong: more lineage edges (derived tables, CTE chains, CTAS/INSERT…SELECT), more PII exposures, stricter migration verdicts, a new `unbalanced_quote` safety rule, and validate/transpile/equivalence fixes. One type-surface addition: `PiiColumnAccess.query_targets`. Contract sync (consumers still read legacy pre-native-core shapes): - `altimate-core-migration` tool: read `findings`/`safe`/`overall_risk` (engine `MigrationResult`) instead of nonexistent `risks` — previously ANY migration, including `DROP COLUMN`, rendered "Migration: SAFE"; never render SAFE when the engine call errored; count only non-"safe" findings as risks. - `altimate_core.migration` handler: coerce empty dialect `"" → undefined` (`|| undefined`, same as the equivalence handler) so `Schema.fromDdl` does not throw on the default empty-string dialect. - `check --checks safety`: read engine `threats[]` (`rule`/`message`/`detail`) so real threats (e.g. `unbalanced_quote`) render with rule and message instead of a generic warning. - `normalizeSeverity`: map engine severities `high → error`, `medium → warning` — previously both degraded to `info`, so `--fail-on`/`--severity` silently passed high-risk injections. - `check --checks pii`: map engine `PiiColumnAccess` (`table`/`column`/ `classification`/`query_targets`/`suggested_masking`); stop assigning the column NAME to the numeric column-position field; report the exposing alias; stringify `{ Custom: string }` classifications (also in the query-pii tool renderer, which printed `[object Object]`). - `altimate-core-track-lineage` tool: collect edges from `queries[].edges` (engine `LineageResult`) instead of flat `edges` — previously always "0 edges"; render `impact_map`; format `{table, column}` refs; render ERROR instead of "0 edges" when the engine call fails. - `altimate-core-query-pii` tool: surface new 0.7.0 `query_targets` field as "Exposed via: …". - `altimate-core-check` tool: safety renderer and telemetry read `rule`/`message` with legacy fallback. Test updates for 0.7.0 behavior: - Dialect-forwarding fixture: `payload:f` now parses in the default dialect, so it no longer discriminates; switched to Snowflake time-travel `AT(OFFSET => -60)` which still does. - Grade comparison made apples-to-apples (same table, projection-only diff). - New real-engine tests: `query_targets` contract + rendering, migration destructive/safe/empty-dialect/error + tool-title regression, track-lineage edge surfacing + error rendering, check CLI safety `ThreatFinding` (incl. `high → error` normalization) and PII `PiiColumnAccess` shapes (incl. `{ Custom }` classification). - Strengthened previously vacuous migration e2e assertions. Verification: typecheck clean; test/altimate + test/cli fully green (4750 pass / 0 fail); full-suite failures (MCP/TUI-sound/subprocess) reproduced identically on 0.5.1 or shown run-to-run flaky with no engine coupling — pre-existing. Marker check: no upstream-shared files modified. Codex reviewed twice (found the legacy-shape consumers; verified all fixes non-tautological). Closes #1089 Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 54a8f32 commit 6b16d7f

12 files changed

Lines changed: 319 additions & 55 deletions

‎bun.lock‎

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/opencode/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
"@ai-sdk/togetherai": "2.0.41",
7979
"@ai-sdk/vercel": "2.0.39",
8080
"@ai-sdk/xai": "3.0.82",
81-
"@altimateai/altimate-core": "0.5.1",
81+
"@altimateai/altimate-core": "0.7.0",
8282
"@altimateai/drivers": "workspace:*",
8383
"@aws-sdk/credential-providers": "3.1057.0",
8484
"@clack/prompts": "1.0.0-alpha.1",

‎packages/opencode/src/altimate/native/altimate-core.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,10 @@ export function registerAll(): void {
337337
// 12. altimate_core.migration
338338
register("altimate_core.migration", async (params) => {
339339
try {
340-
// Build schema from old_ddl, analyze new_ddl against it
341-
const schema = core.Schema.fromDdl(params.old_ddl, params.dialect ?? undefined)
340+
// Build schema from old_ddl, analyze new_ddl against it.
341+
// `|| undefined` (not `??`): "" must mean auto-detect — the engine
342+
// throws on an unknown dialect "" (same coercion as equivalence above).
343+
const schema = core.Schema.fromDdl(params.old_ddl, params.dialect || undefined)
342344
const raw = core.analyzeMigration(params.new_ddl, schema)
343345
const data = toData(raw)
344346
return ok(true, data)

‎packages/opencode/src/altimate/tools/altimate-core-check.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
3030
findings.push({ category: f.rule ?? "lint" })
3131
}
3232
for (const t of data.safety?.threats ?? []) {
33-
findings.push({ category: t.type ?? "safety_threat" })
33+
findings.push({ category: t.rule ?? t.type ?? "safety_threat" })
3434
}
3535
for (const p of data.pii?.findings ?? []) {
3636
findings.push({ category: "pii_detected" })
@@ -93,7 +93,7 @@ export function formatCheck(data: Record<string, any>): string {
9393
lines.push("Safe — no threats.")
9494
} else {
9595
for (const t of data.safety?.threats ?? []) {
96-
lines.push(` [${t.severity ?? "warning"}] ${t.type ?? "safety"}: ${t.description ?? ""}`)
96+
lines.push(` [${t.severity ?? "warning"}] ${t.rule ?? t.type ?? "safety"}: ${t.message ?? t.description ?? ""}`)
9797
}
9898
}
9999

‎packages/opencode/src/altimate/tools/altimate-core-migration.ts‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,21 @@ export const AltimateCoreMigrationTool = Tool.define("altimate_core_migration",
1818
dialect: args.dialect ?? "",
1919
})
2020
const data = (result.data ?? {}) as Record<string, any>
21-
const riskCount = data.risks?.length ?? 0
21+
// Engine shape (MigrationResult): findings[], safe, overall_risk.
22+
// Informational findings carry risk "safe" — only count real risks.
23+
const findings = (data.findings ?? data.risks ?? []) as Array<Record<string, any>>
24+
const riskCount = findings.filter((f) => (f.risk ?? f.severity ?? "risk") !== "safe").length
2225
const error = result.error ?? data.error
26+
// Never render SAFE when the engine call itself failed.
27+
const title = error
28+
? "Migration: ERROR"
29+
: data.safe === false || riskCount > 0
30+
? `Migration: ${(data.overall_risk ?? "risk").toString().toUpperCase()} — ${riskCount} risk(s)`
31+
: "Migration: SAFE"
2332
return {
24-
title: `Migration: ${riskCount === 0 ? "SAFE" : `${riskCount} risk(s)`}`,
33+
title,
2534
metadata: { success: result.success, risk_count: riskCount, ...(error && { error }) },
26-
output: formatMigration(data),
35+
output: formatMigration(data, error),
2736
}
2837
} catch (e) {
2938
const msg = e instanceof Error ? e.message : String(e)
@@ -36,13 +45,17 @@ export const AltimateCoreMigrationTool = Tool.define("altimate_core_migration",
3645
},
3746
})
3847

39-
function formatMigration(data: Record<string, any>): string {
40-
if (data.error) return `Error: ${data.error}`
41-
if (!data.risks?.length) return "Migration appears safe. No risks detected."
42-
const lines = ["Migration risks:\n"]
43-
for (const r of data.risks) {
44-
lines.push(` [${r.severity ?? "warning"}] ${r.type}: ${r.message}`)
45-
if (r.recommendation) lines.push(` Recommendation: ${r.recommendation}`)
48+
function formatMigration(data: Record<string, any>, error?: string): string {
49+
if (error ?? data.error) return `Error: ${error ?? data.error}`
50+
const findings = data.findings ?? data.risks ?? []
51+
if (!findings.length && data.safe !== false) return "Migration appears safe. No risks detected."
52+
const lines: string[] = []
53+
if (data.overall_risk) lines.push(`Overall risk: ${data.overall_risk}`)
54+
lines.push("Migration findings:\n")
55+
for (const r of findings) {
56+
lines.push(` [${r.risk ?? r.severity ?? "warning"}] ${r.operation ?? r.type ?? "operation"}: ${r.message ?? ""}`)
57+
if (r.mitigation ?? r.recommendation) lines.push(` Mitigation: ${r.mitigation ?? r.recommendation}`)
58+
if (r.rollback_sql) lines.push(` Rollback: ${r.rollback_sql}`)
4659
}
4760
return lines.join("\n")
4861
}

‎packages/opencode/src/altimate/tools/altimate-core-query-pii.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,13 @@ function formatQueryPii(data: Record<string, any>): string {
4545
if (data.risk_level) lines.push(`Risk level: ${data.risk_level}`)
4646
lines.push("PII exposure detected:\n")
4747
for (const e of piiCols) {
48-
const classification = e.classification ?? e.category ?? "PII"
48+
// Classification is a string OR { Custom: string }.
49+
const raw = e.classification ?? e.category ?? "PII"
50+
const classification = typeof raw === "string" ? raw : (raw?.Custom ?? "PII")
4951
const table = e.table ?? "unknown"
5052
const column = e.column ?? "unknown"
5153
lines.push(` ${table}.${column}: ${classification}`)
54+
if (e.query_targets?.length) lines.push(` Exposed via: ${e.query_targets.join(", ")}`)
5255
if (e.suggested_masking) lines.push(` Masking: ${e.suggested_masking}`)
5356
}
5457
if (data.suggested_alternatives?.length) {

‎packages/opencode/src/altimate/tools/altimate-core-track-lineage.ts‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ export const AltimateCoreTrackLineageTool = Tool.define("altimate_core_track_lin
1818
schema_context: args.schema_context,
1919
})
2020
const data = (result.data ?? {}) as Record<string, any>
21-
const edgeCount = data.edges?.length ?? 0
21+
const edgeCount = collectEdges(data).length
2222
const error = result.error ?? data.error
2323
return {
24-
title: `Track Lineage: ${edgeCount} edge(s) across ${args.queries.length} queries`,
24+
// Never render "0 edges" when the engine call itself failed.
25+
title: error ? "Track Lineage: ERROR" : `Track Lineage: ${edgeCount} edge(s) across ${args.queries.length} queries`,
2526
metadata: { success: result.success, edge_count: edgeCount, ...(error && { error }) },
26-
output: formatTrackLineage(data),
27+
output: error ? `Error: ${error}` : formatTrackLineage(data),
2728
}
2829
} catch (e) {
2930
const msg = e instanceof Error ? e.message : String(e)
@@ -36,12 +37,34 @@ export const AltimateCoreTrackLineageTool = Tool.define("altimate_core_track_lin
3637
},
3738
})
3839

40+
/** Engine shape (LineageResult): edges live under queries[].edges, not at the top level. */
41+
function collectEdges(data: Record<string, any>): any[] {
42+
if (Array.isArray(data.queries)) return data.queries.flatMap((q: any) => q.edges ?? [])
43+
return data.edges ?? []
44+
}
45+
46+
/** Column refs are { table, column } objects; legacy shape was a plain string. */
47+
function refToString(ref: any): string {
48+
if (ref == null) return "?"
49+
if (typeof ref === "string") return ref
50+
return [ref.table, ref.column].filter(Boolean).join(".") || "?"
51+
}
52+
3953
function formatTrackLineage(data: Record<string, any>): string {
4054
if (data.error) return `Error: ${data.error}`
41-
if (!data.edges?.length) return "No lineage edges found across queries."
55+
const edges = collectEdges(data)
56+
if (!edges.length) return "No lineage edges found across queries."
4257
const lines = ["Lineage graph:\n"]
43-
for (const edge of data.edges) {
44-
lines.push(` ${edge.source ?? "?"} -> ${edge.target ?? "?"}${edge.transform ? ` (${edge.transform})` : ""}`)
58+
for (const edge of edges) {
59+
const transform = edge.transform_type ?? edge.transform
60+
lines.push(` ${refToString(edge.source)} -> ${refToString(edge.target)}${transform ? ` (${transform})` : ""}`)
61+
}
62+
if (Array.isArray(data.impact_map) && data.impact_map.length) {
63+
lines.push("\nImpact map:")
64+
for (const entry of data.impact_map) {
65+
const affected = (entry.affected ?? []).map(refToString).join(", ")
66+
lines.push(` ${refToString(entry.source)} affects: ${affected || "(none)"}`)
67+
}
4568
}
4669
return lines.join("\n")
4770
}

‎packages/opencode/src/cli/cmd/check-helpers.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ export const VALID_CHECKS = new Set(["lint", "validate", "safety", "policy", "pi
5252
export function normalizeSeverity(s?: string | unknown): Severity {
5353
if (!s || typeof s !== "string") return "warning"
5454
const lower = s.toLowerCase()
55-
if (lower === "error" || lower === "fatal" || lower === "critical") return "error"
56-
if (lower === "warning" || lower === "warn") return "warning"
55+
// Engine safety severities are low|medium|high|critical — high-risk threats
56+
// must not degrade to info or --fail-on/--severity filters silently pass.
57+
if (lower === "error" || lower === "fatal" || lower === "critical" || lower === "high") return "error"
58+
if (lower === "warning" || lower === "warn" || lower === "medium") return "warning"
5759
return "info"
5860
}
5961

‎packages/opencode/src/cli/cmd/check.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ async function runSafety(sql: string, file: string): Promise<Finding[]> {
9797
try {
9898
const result = await Dispatcher.call("altimate_core.safety", { sql })
9999
if (result.success && result.data.safe !== false) return []
100-
const issues = (result.data.issues ?? result.data.findings ?? []) as Array<Record<string, unknown>>
100+
const issues = (result.data.threats ??
101+
result.data.issues ??
102+
result.data.findings ??
103+
[]) as Array<Record<string, unknown>>
101104
if (issues.length > 0) {
102105
return issues.map((f) => ({
103106
file,
@@ -107,7 +110,7 @@ async function runSafety(sql: string, file: string): Promise<Finding[]> {
107110
rule: (f.rule ?? f.category ?? "safety") as string,
108111
severity: normalizeSeverity(f.severity as string),
109112
message: (f.message ?? f.description ?? "") as string,
110-
suggestion: f.suggestion as string | undefined,
113+
suggestion: (f.suggestion ?? f.detail) as string | undefined,
111114
}))
112115
}
113116
if (!result.success || result.data.safe === false) {
@@ -174,17 +177,29 @@ async function runPii(sql: string, file: string, schemaPath?: string): Promise<F
174177
if (!result.success) {
175178
return [dispatcherErrorFinding("pii", file, result.error ?? "altimate_core.query_pii failed")]
176179
}
180+
// Engine shape (PiiColumnAccess): table, column, classification,
181+
// query_targets, suggested_masking. `column` is the column NAME — not a
182+
// position — so it must not populate the numeric location field.
177183
const piiFindings = (result.data.pii_columns ?? result.data.findings ?? []) as Array<Record<string, unknown>>
178-
return piiFindings.map((f) => ({
179-
file,
180-
line: f.line as number | undefined,
181-
column: f.column as number | undefined,
182-
code: f.code as string | undefined,
183-
rule: (f.category ?? f.pii_type ?? "pii") as string,
184-
severity: "warning" as const,
185-
message: (f.message ?? f.description ?? `PII detected: ${f.column_name ?? f.name ?? "unknown"}`) as string,
186-
suggestion: f.suggestion as string | undefined,
187-
}))
184+
return piiFindings.map((f) => {
185+
const qualified = [f.table, f.column].filter(Boolean).join(".")
186+
const targets = Array.isArray(f.query_targets) && f.query_targets.length ? ` (exposed via: ${(f.query_targets as string[]).join(", ")})` : ""
187+
// Classification is a string OR { Custom: string }.
188+
const classification = f.classification as string | { Custom: string } | undefined
189+
const rule =
190+
typeof classification === "string"
191+
? classification
192+
: (classification?.Custom ?? (f.category as string) ?? (f.pii_type as string) ?? "pii")
193+
return {
194+
file,
195+
line: f.line as number | undefined,
196+
code: f.code as string | undefined,
197+
rule,
198+
severity: "warning" as const,
199+
message: (f.message ?? f.description ?? `PII detected: ${qualified || "unknown"}${targets}`) as string,
200+
suggestion: (f.suggestion ?? f.suggested_masking) as string | undefined,
201+
}
202+
})
188203
} catch (e) {
189204
console.error(`[pii] error processing ${file}: ${e instanceof Error ? e.message : String(e)}`)
190205
return [dispatcherErrorFinding("pii", file, e)]

0 commit comments

Comments
 (0)