[Feature] Test/lint-on-save with agent auto-fix loop
Description
Run test or lint commands automatically after the agent modifies code. If the command fails, automatically feed the error output back to the agent for a fixed number of correction attempts.
Use Case
Closes the "edit breaks tests" gap that plagues LLM agents. Instead of the user acting as the middleman (copying the error and pasting it back to the agent), the agent verifies its own work against the test suite immediately.
Proposed Solution
Add nanocoder.testCommand. After edits, run the command. If it returns a non-zero exit code, automatically append the stderr/stdout as a follow-up prompt to the model. Cap this loop using a --max-fix-iterations 3 flag to prevent infinite loops.
Alternatives Considered
- The upcoming Agentic CI/CD Gate (#794), but this is specifically for a tight, local edit loop during standard chat.
Additional Context
- [x] I have searched existing issues to ensure this is not a duplicate
- [x] This feature aligns with the project's goals (local-first AI assistance)
Implementation Notes (optional)
Needs to be hooked into the orchestrator/app state so it can push a new system message and trigger a model re-run without user intervention.
@akramcodez can I take this one?
Most of this already exists through the lifecycle hooks — a post-tool-use
hook can be scoped to the edit tools and its stdout gets folded into the tool
result (lifecycle-hooks.ts:188). The catch is that a non-zero exit is logged and
skipped (lifecycle-hooks.ts:604), so a passing test run reaches the model and a
failing one doesn't. Wrong way round for this.
So: forward the failing output too, tagged with the exit code and still
non-vetoing, add nanocoder.testCommand as sugar for the common case, and cap
the retries per turn.
One thing before I start. Running after every edit means ten runs on a ten-edit turn, so I'd rather fire once when the agent stops editing, but there's no turn-end event in HOOK_EVENTS. Would you add one, or should I debounce inside the turn?
Just spotted #1525 doing this already. didn't see it when I commented. Standing down, ignore my note above.
@akramcodez can you assign this issue to me ??