Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/opencode/src/altimate/native/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,7 @@ export interface SchemaDiffResult {

export interface AltimateCoreValidateParams {
sql: string
dialect?: string
schema_path?: string
schema_context?: Record<string, any>
}
Expand Down Expand Up @@ -708,6 +709,7 @@ export interface AltimateCoreExplainParams {

export interface AltimateCoreCheckParams {
sql: string
dialect?: string
schema_path?: string
schema_context?: Record<string, any>
}
Expand All @@ -722,20 +724,23 @@ export interface AltimateCoreResult {

export interface AltimateCoreFixParams {
sql: string
dialect?: string
schema_path?: string
schema_context?: Record<string, any>
max_iterations?: number
}

export interface AltimateCorePolicyParams {
sql: string
dialect?: string
policy_json: string
schema_path?: string
schema_context?: Record<string, any>
}

export interface AltimateCoreSemanticsParams {
sql: string
dialect?: string
schema_path?: string
schema_context?: Record<string, any>
}
Expand All @@ -751,6 +756,7 @@ export interface AltimateCoreTestgenParams {
export interface AltimateCoreEquivalenceParams {
sql1: string
sql2: string
dialect?: string
schema_path?: string
schema_context?: Record<string, any>
}
Expand All @@ -776,6 +782,7 @@ export interface AltimateCoreRewriteParams {

export interface AltimateCoreCorrectParams {
sql: string
dialect?: string
schema_path?: string
schema_context?: Record<string, any>
}
Expand Down
9 changes: 8 additions & 1 deletion packages/opencode/src/altimate/tools/altimate-core-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
"Run full analysis pipeline: validate + lint + safety scan + PII check. Single call for comprehensive SQL analysis. Provide schema_context or schema_path for accurate table/column resolution.",
parameters: z.object({
sql: z.string().describe("SQL query to analyze"),
dialect: z
.string()
.optional()
.default("snowflake")
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
Expand All @@ -16,6 +21,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
try {
const result = await Dispatcher.call("altimate_core.check", {
sql: args.sql,
dialect: args.dialect,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
Expand All @@ -40,6 +46,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
title: `Check: ${formatCheckTitle(data)}`,
metadata: {
success: result.success,
dialect: args.dialect,
has_schema: hasSchema,
...(error && { error }),
...(findings.length > 0 && { findings }),
Expand All @@ -50,7 +57,7 @@ export const AltimateCoreCheckTool = Tool.define("altimate_core_check", {
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Check: ERROR",
metadata: { success: false, has_schema: hasSchema, error: msg },
metadata: { success: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
output: `Failed: ${msg}`,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
"Iteratively correct SQL using a propose-verify-refine loop. More thorough than fix — applies multiple correction rounds to produce valid SQL. Provide schema_context or schema_path for accurate table/column resolution.",
parameters: z.object({
sql: z.string().describe("SQL query to correct"),
dialect: z
.string()
.optional()
.default("snowflake")
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
Expand All @@ -16,6 +21,7 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
try {
const result = await Dispatcher.call("altimate_core.correct", {
sql: args.sql,
dialect: args.dialect,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
Expand All @@ -32,6 +38,7 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
metadata: {
success: result.success,
iterations: data.iterations,
dialect: args.dialect,
has_schema: hasSchema,
...(error && { error }),
...(findings.length > 0 && { findings }),
Expand All @@ -42,7 +49,7 @@ export const AltimateCoreCorrectTool = Tool.define("altimate_core_correct", {
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Correct: ERROR",
metadata: { success: false, iterations: 0, has_schema: hasSchema, error: msg },
metadata: { success: false, iterations: 0, dialect: args.dialect, has_schema: hasSchema, error: msg },
output: `Failed: ${msg}`,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
parameters: z.object({
sql1: z.string().describe("First SQL query"),
sql2: z.string().describe("Second SQL query"),
dialect: z
.string()
.optional()
.default("snowflake")
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
Expand All @@ -27,6 +32,7 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
const result = await Dispatcher.call("altimate_core.equivalence", {
sql1: args.sql1,
sql2: args.sql2,
dialect: args.dialect,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
Expand All @@ -48,6 +54,7 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
metadata: {
success: !isRealFailure,
equivalent: data.equivalent,
dialect: args.dialect,
has_schema: hasSchema,
...(error && { error }),
...(findings.length > 0 && { findings }),
Expand All @@ -58,7 +65,7 @@ export const AltimateCoreEquivalenceTool = Tool.define("altimate_core_equivalenc
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Equivalence: ERROR",
metadata: { success: false, equivalent: false, has_schema: hasSchema, error: msg },
metadata: { success: false, equivalent: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
output: `Failed: ${msg}`,
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/opencode/src/altimate/tools/altimate-core-fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
"Auto-fix SQL errors using fuzzy matching and iterative re-validation. Corrects syntax errors, typos, and schema reference issues. IMPORTANT: Provide schema_context or schema_path — without schema, table/column references cannot be resolved or fixed.",
parameters: z.object({
sql: z.string().describe("SQL query to fix"),
dialect: z
.string()
.optional()
.default("snowflake")
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
max_iterations: z.number().optional().describe("Maximum fix iterations (default: 5)"),
Expand All @@ -17,6 +22,7 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
try {
const result = await Dispatcher.call("altimate_core.fix", {
sql: args.sql,
dialect: args.dialect,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
max_iterations: args.max_iterations ?? 5,
Expand All @@ -40,6 +46,7 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
metadata: {
success,
fixed: !!data.fixed_sql,
dialect: args.dialect,
has_schema: hasSchema,
...(error && { error }),
...(findings.length > 0 && { findings }),
Expand All @@ -50,7 +57,7 @@ export const AltimateCoreFixTool = Tool.define("altimate_core_fix", {
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Fix: ERROR",
metadata: { success: false, fixed: false, has_schema: hasSchema, error: msg },
metadata: { success: false, fixed: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
output: `Failed: ${msg}`,
}
}
Expand Down
9 changes: 8 additions & 1 deletion packages/opencode/src/altimate/tools/altimate-core-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
"Check SQL against YAML-based governance policy guardrails. Validates compliance with custom rules like allowed tables, forbidden operations, and data access restrictions. Provide schema_context or schema_path for accurate table/column resolution.",
parameters: z.object({
sql: z.string().describe("SQL query to check against policy"),
dialect: z
.string()
.optional()
.default("snowflake")
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
policy_json: z.string().describe("JSON string defining the policy rules"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
Expand All @@ -17,6 +22,7 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
try {
const result = await Dispatcher.call("altimate_core.policy", {
sql: args.sql,
dialect: args.dialect,
policy_json: args.policy_json,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
Expand All @@ -34,6 +40,7 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
metadata: {
success: true, // engine ran — violations are findings, not failures
pass: data.pass,
dialect: args.dialect,
has_schema: hasSchema,
...(error && { error }),
...(findings.length > 0 && { findings }),
Expand All @@ -44,7 +51,7 @@ export const AltimateCorePolicyTool = Tool.define("altimate_core_policy", {
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Policy: ERROR",
metadata: { success: false, pass: false, has_schema: hasSchema, error: msg },
metadata: { success: false, pass: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
output: `Failed: ${msg}`,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
"Run semantic validation rules against SQL. Detects logical issues like cartesian products, wrong JOIN conditions, NULL misuse, and type mismatches that syntax checking alone misses. Provide schema_context or schema_path for accurate table/column resolution.",
parameters: z.object({
sql: z.string().describe("SQL query to validate semantically"),
dialect: z
.string()
.optional()
.default("snowflake")
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
Expand All @@ -25,6 +30,7 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
try {
const result = await Dispatcher.call("altimate_core.semantics", {
sql: args.sql,
dialect: args.dialect,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
Expand All @@ -44,6 +50,7 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
success: true, // engine ran — semantic issues are findings, not failures
valid: data.valid,
issue_count: issueCount,
dialect: args.dialect,
has_schema: hasSchema,
...(error && { error }),
...(findings.length > 0 && { findings }),
Expand All @@ -54,7 +61,7 @@ export const AltimateCoreSemanticsTool = Tool.define("altimate_core_semantics",
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Semantics: ERROR",
metadata: { success: false, valid: false, issue_count: 0, has_schema: hasSchema, error: msg },
metadata: { success: false, valid: false, issue_count: 0, dialect: args.dialect, has_schema: hasSchema, error: msg },
output: `Failed: ${msg}`,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
"Validate SQL syntax and schema references. Checks if tables/columns exist in the schema and if SQL is valid for the target dialect. IMPORTANT: Provide schema_context or schema_path — without schema, all table/column references will report as 'not found'.",
parameters: z.object({
sql: z.string().describe("SQL query to validate"),
dialect: z
.string()
.optional()
.default("snowflake")
.describe("SQL dialect (snowflake, postgres, bigquery, duckdb, etc.)"),
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
schema_context: z.record(z.string(), z.any()).optional().describe("Inline schema definition"),
}),
Expand All @@ -26,6 +31,7 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
try {
const result = await Dispatcher.call("altimate_core.validate", {
sql: args.sql,
dialect: args.dialect,
schema_path: args.schema_path ?? "",
schema_context: args.schema_context,
})
Expand All @@ -42,6 +48,7 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
metadata: {
success: true, // engine ran — validation errors are findings, not failures
valid: data.valid,
dialect: args.dialect,
has_schema: hasSchema,
...(error && { error }),
...(findings.length > 0 && { findings }),
Expand All @@ -52,7 +59,7 @@ export const AltimateCoreValidateTool = Tool.define("altimate_core_validate", {
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Validate: ERROR",
metadata: { success: false, valid: false, has_schema: hasSchema, error: msg },
metadata: { success: false, valid: false, dialect: args.dialect, has_schema: hasSchema, error: msg },
output: `Failed: ${msg}`,
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages/opencode/src/altimate/tools/impact-analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const ImpactAnalysisTool = Tool.define("impact_analysis", {
transitive_count: transitive.length,
test_count: affectedTestCount,
column_impact: columnImpact.length,
dialect: args.dialect,
has_schema: false,
...(findings.length > 0 && { findings }),
},
Expand All @@ -148,7 +149,7 @@ export const ImpactAnalysisTool = Tool.define("impact_analysis", {
const msg = e instanceof Error ? e.message : String(e)
return {
title: "Impact: ERROR",
metadata: { success: false, has_schema: false, error: msg },
metadata: { success: false, dialect: args.dialect, has_schema: false, error: msg },
output: `Failed to analyze impact: ${msg}\n\nEnsure the dbt manifest exists (run \`dbt compile\`) and the dispatcher is running.`,
}
}
Expand Down
Loading
Loading