Skip to content

agent: add script healing capability#2899

Draft
arrufat wants to merge 27 commits into
mainfrom
agent-self-heal
Draft

agent: add script healing capability#2899
arrufat wants to merge 27 commits into
mainfrom
agent-self-heal

Conversation

@arrufat

@arrufat arrufat commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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.

arrufat added 19 commits July 8, 2026 09:30
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
arrufat marked this pull request as ready for review July 21, 2026 07:53

@karlseguin karlseguin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't really understand, a few simple comments...feel free to ignore. Looks fine mechanically.

Comment thread src/agent/Agent.zig Outdated
Comment thread src/agent/Agent.zig Outdated
Comment thread src/agent/Agent.zig Outdated
@arrufat
arrufat marked this pull request as draft July 24, 2026 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants