Repair CAD Script
repair_scriptUse this when evaluate_script reported an error and you want the fix applied rather than described. Takes the candidates why_did_this_fail derives for a diagnostic, applies them one at a time, re-evaluates after each, and keeps the first that clears the diagnostic without introducing new errors. Never edits outside the repair region (failing feature statement + its input statements + the param() lines it reads) — an out-of-region patch is refused with tool.repair.out-of-region. Returns the repaired source in new_code (the caller persists it), a unified diff, and before/after health maps. Pass { file? | code?, diagnostic?: ''|'first-error', strategy?: 'apply-first'|'try-all'|'dry-run', max_attempts?: number }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | Inline kernelCAD script source. | |
| file | No | Path to a .kcad.ts script file. | |
| strategy | No | 'try-all' (default) walks candidates until one clears the diagnostic; 'apply-first' applies only the top candidate and reports what it did; 'dry-run' previews every candidate patch without evaluating. | |
| diagnostic | No | Diagnostic id from why_did_this_fail's `targetDiagnosticId` / `candidates[].diagnosticId`, or 'first-error' (default) for the first error-severity diagnostic. | |
| max_attempts | No | Upper bound on candidates attempted (default 3). Ignored by apply-first and dry-run. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | Yes | Whether a candidate cleared the target diagnostic without new errors. | |
| diff | No | Unified diff of the accepted patch (dry run: every candidate patch). | |
| after | No | Post-repair { ok, featureHealth, diagnostics }. | |
| error | No | ||
| before | No | Pre-repair { ok, featureHealth, diagnostics }. | |
| target | No | The diagnostic this run targeted { id, code, featureId?, message }. | |
| applied | No | Candidate id that was accepted. | |
| attempts | Yes | Per-candidate outcome { candidateId, applied, ok?, clearedDiagnostic?, newErrorCodes?, accepted, diagnostic? }. | |
| new_code | No | Repaired .kcad.ts source (present when a patch applied). Caller persists it. | |
| strategy | Yes | ||
| errorCode | No | ||
| candidates | Yes | ||
| diagnostics | No | tool.repair.* diagnostics when repair could not complete. | |
| repairRegion | No | The line ranges the repair was bound to. | |
| candidateReason | No | ||
| candidateStatus | No |