Skip to content

Commit 0126fa0

Browse files
mhallidaclaude
andcommitted
fix: altimate_core_correct fixes [object Object] and handles keyword typos
1. Fixed serialization bug: CorrectionResult.iterations is an array of CorrectionIteration objects, not a scalar. Now properly formats each iteration step instead of printing [object Object]. 2. Added keyword typo pre-correction (same as altimate_core_fix) so SELCT→SELECT, WERE→WHERE etc. are fixed before the Rust correction loop. Fixes TICKET-008 in #422. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent f0fc9d3 commit 0126fa0

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,32 @@ register("altimate_core.rewrite", async (params) => {
460460
}
461461
})
462462

463-
// 15. altimate_core.correct
463+
// 15. altimate_core.correct — with keyword typo correction
464464
register("altimate_core.correct", async (params) => {
465465
try {
466+
// Pre-fix keyword typos before passing to Rust
467+
const { sql: preprocessed, corrections } = fixKeywordTypos(params.sql)
468+
466469
const schema = schemaOrEmpty(params.schema_path, params.schema_context)
467-
const raw = await core.correct(params.sql, schema)
470+
const raw = await core.correct(preprocessed, schema)
468471
const data = toData(raw)
472+
473+
// If we fixed keyword typos, merge that info
474+
if (corrections.length > 0) {
475+
data.original_sql = params.sql
476+
if (data.status === "unfixable" && preprocessed !== params.sql) {
477+
// Rust couldn't fix further, but keyword corrections succeeded
478+
data.status = corrections.length > 0 ? "fixed" : data.status
479+
data.corrected_sql = data.corrected_sql ?? preprocessed
480+
}
481+
data.changes = [
482+
...corrections.map((c) => ({
483+
description: `Fixed keyword typo: ${c}`,
484+
})),
485+
...((data.changes as any[]) ?? []),
486+
]
487+
}
488+
469489
return ok(data.status !== "unfixable", data)
470490
} catch (e) {
471491
return fail(e)

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,22 @@ function formatCorrect(data: Record<string, any>): string {
3737
lines.push("Corrected SQL:")
3838
lines.push(data.corrected_sql)
3939
}
40-
if (data.iterations) lines.push(`\nIterations: ${data.iterations}`)
40+
// iterations is CorrectionIteration[] — serialize properly
41+
if (data.iterations != null) {
42+
if (Array.isArray(data.iterations)) {
43+
lines.push(`\nIterations: ${data.iterations.length}`)
44+
for (const iter of data.iterations) {
45+
const desc = iter.fix_description ?? iter.result ?? "correction step"
46+
lines.push(` ${iter.iteration ?? "-"}. ${desc}`)
47+
}
48+
} else if (typeof data.iterations === "number") {
49+
lines.push(`\nIterations: ${data.iterations}`)
50+
}
51+
}
4152
if (data.changes?.length) {
4253
lines.push("\nCorrections applied:")
4354
for (const c of data.changes) {
44-
lines.push(` - ${c.description ?? c}`)
55+
lines.push(` - ${typeof c === "string" ? c : c.description ?? c.fix_description ?? JSON.stringify(c)}`)
4556
}
4657
}
4758
if (!data.corrected_sql && !data.changes?.length) {

0 commit comments

Comments
 (0)