agent: add script healing capability#2899
Draft
arrufat wants to merge 27 commits into
Draft
Conversation
Adds a `--heal` CLI flag and interactive REPL prompt to automatically diagnose and repair failing scripts using the LLM. The agent attempts to fix the script, then validates the revision in a fresh session before overwriting the original file.
Detects when a script runs successfully but returns no data (e.g., due to a stale selector). Treats this as a healable error and prompts the user to heal it with the model.
Tracks extract calls during script execution. If a list field in an extract schema returns empty across all calls, it is treated as a script error (`dry_extracts`) to trigger the heal prompt.
Tracks extract results and persists them as comments in saved scripts. This allows healing to compare replays against record-time reality.
- Add `classifyExtractFields` to share parsing between Baseline and Runtime. - Reuse a scratch arena allocator in Baseline to avoid overhead. - Simplify the retry loop in `Agent.runScriptWithHeal`.
Replaces hardcoded heuristics and programmatic baseline parsing with an LLM turn that judges if empty outputs or dry extracts indicate a broken script or legitimate sparseness. Extracts a `metaTurn` helper to share out-of-conversation LLM execution logic.
Consolidates tool execution into a shared `callTool` helper. Replaces the temporary `Suspicion` and `DryFinding` structs with `ScriptError` to streamline validation and judgment paths.
Instructs the agent to preserve, update, and add intent comments when healing scripts.
- Add `soloTurn` to run LLM verdicts without conversation history. - Swap `Recorder` instead of snapshotting during healing. - Remove `is_list` tracking from extract stats. - Simplify JSON parsing in `parseVerdict`.
- Swap `self.baseline` during `healLoop` to prevent state leakage. - Use `defer` with a `keep_revision` flag for robust temp file cleanup. - Avoid rolling back conversation state on meta-turn cancellation. - Generalize `capToolOutput` to `capOutput` and use it for details. - Remove persistent scratch arena from `Baseline`.
arrufat
marked this pull request as ready for review
July 21, 2026 07:53
karlseguin
reviewed
Jul 22, 2026
karlseguin
left a comment
Collaborator
There was a problem hiding this comment.
Don't really understand, a few simple comments...feel free to ignore. Looks fine mechanically.
Co-authored-by: Karl Seguin <karlseguin@users.noreply.github.com>
# Conflicts: # src/script/Runtime.zig
arrufat
marked this pull request as draft
July 24, 2026 14:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
--healCLI flag and interactive REPL prompt to automatically diagnose and repair failing scripts using the LLM. The agent attempts to fix the script, then validates the revision in a fresh session before overwriting the original file.