feat: add auto-fix service — auto-lint and test after AI file edits - #508
Conversation
Implements AutoFixConfigSchema (Zod v4) with validation for lint/test commands, maxRetries (0-10, default 3), and timeout (1000-300000ms, default 30000). Adds getAutoFixConfig helper that returns null for disabled or invalid configs. All 9 unit tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements AutoFixRunner (Task 2) - executes lint and test shell commands sequentially, short-circuits on lint failure, handles timeouts, and produces structured AutoFixResult with AI-friendly error summaries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Integrates AutoFixConfigSchema into SettingsSchema so autoFix settings are validated at the settings layer. Adds two integration tests verifying that valid configs are accepted and invalid configs (enabled with no commands) are rejected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements shouldRunAutoFix and buildAutoFixContext functions used by the PostToolUse hook to determine when to run auto-fix and format errors as AI-readable context for injection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add auto-fix lint/test check after existing PostToolUse hooks in runPostToolUseHooks. When autoFix is configured in settings, runs lint/test commands after file_edit/file_write tools and yields errors as hook_additional_context for the model to act on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds the /auto-fix prompt command that helps users configure autoFix settings (lint/test commands, maxRetries, timeout) in .claude/settings.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
kevincodex1
left a comment
There was a problem hiding this comment.
this looks great a much needed feature indeed! thanks @gnanam1990
|
@auriti @Vasanthdev2004 @anandh8x see this |
There was a problem hiding this comment.
-
maxRetriesis exposed as part of the new user-facing config (src/services/autoFix/autoFixConfig.ts), but the feature never reads or enforces it in the actual auto-fix path (src/services/tools/toolHooks.ts,src/services/autoFix/autoFixRunner.ts). In practice that means the new self-repair loop has no feature-specific retry cap: every failingfile_editorfile_writecan emit anotherhook_additional_contextand keep the model cycling until some unrelated outer limit stops it. If this setting is documented and shown in the example config, the loop needs to honor it or the docs/config should be removed. -
Cancellation is threaded into the API but not into the subprocess.
toolHooks.tspassestoolUseContext.abortController.signalintorunAutoFixCheck(), andrunAutoFixCheck()passes it down torunCommand(), butrunCommand()never subscribes to the signal or kills the child on abort. The practical failure mode is a long or mutating command likeeslint --fix,bun test --watch, etc.: if the user interrupts the turn, the auto-fix process keeps running until timeout or natural exit, still consuming resources and potentially still editing files after the user thinks execution stopped. -
runCommand()hardcodesspawn('bash', ['-c', command], ...)insrc/services/autoFix/autoFixRunner.ts. That bypasses the existing shell abstraction (src/utils/Shell.ts,src/utils/hooks.ts) and will fail on Windows setups where the app works via a resolved shell path or Git Bash helper but plainbashis not onPATH. Since this feature is exposed as a general cross-platform config option, it should execute commands through the same shell/provider resolution the rest of the app already uses rather than assuming abashexecutable exists.
… use cross-platform shell
1. Enforce maxRetries: track auto-fix attempts per query chain in toolHooks.ts
and stop feeding errors back after the configured limit is reached.
2. Wire abort signal to subprocess: subscribe to AbortController signal in
runCommand() and kill the process tree on abort. Uses detached process
groups on Unix to ensure child processes are also terminated.
3. Replace hardcoded bash with shell:true: use Node's cross-platform shell
resolution instead of spawn('bash', ['-c', ...]) so auto-fix commands
work on Windows and non-bash environments.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@Vasanthdev2004 Addressed all three items in ff7eccc: 1. 2. Abort signal wired to subprocess — 3. Cross-platform shell resolution — Replaced All 29 auto-fix tests pass, build succeeds, zero new type errors. |
Vasanthdev2004
left a comment
There was a problem hiding this comment.
Rechecked the current head ff7eccc36c6997b94de769b4ce14f2c154c4b255.
Scope
This is a targeted current-head re-review of the auto-fix feature after the earlier blocker-level feedback.
Verdict
Approve-ready
What I rechecked on the current head:
maxRetriesis now actually enforced in the auto-fix loop insrc/services/tools/toolHooks.ts, instead of only existing in the user-facing config schema- cancellation is now wired through to the spawned subprocess path in
src/services/autoFix/autoFixRunner.ts, including process-tree termination behavior on Unix - the hardcoded
bash -cpath was replaced with a cross-platformshell: truespawn flow, which removes the earlier bash-on-PATH assumption - current test surface for config parsing, hook behavior, integration, and runner coverage is in place
- current checks are green
This looks like a coherent feature now, and the earlier blocker-level concerns appear addressed on the current head.
|
@kevincodex1 @auriti @anandh8x take a look and I will be helping community as much as possible as I can to improve it |
|
@FluxLuFFy looking forward to it. thank you |
…wigpine#508) * feat: add AutoFix config schema and reader module Implements AutoFixConfigSchema (Zod v4) with validation for lint/test commands, maxRetries (0-10, default 3), and timeout (1000-300000ms, default 30000). Adds getAutoFixConfig helper that returns null for disabled or invalid configs. All 9 unit tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix runner with lint/test command execution Implements AutoFixRunner (Task 2) - executes lint and test shell commands sequentially, short-circuits on lint failure, handles timeouts, and produces structured AutoFixResult with AI-friendly error summaries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix field to SettingsSchema with integration tests Integrates AutoFixConfigSchema into SettingsSchema so autoFix settings are validated at the settings layer. Adds two integration tests verifying that valid configs are accepted and invalid configs (enabled with no commands) are rejected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix hook integration helpers (Task 4) Implements shouldRunAutoFix and buildAutoFixContext functions used by the PostToolUse hook to determine when to run auto-fix and format errors as AI-readable context for injection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: wire autoFix into PostToolUse hook flow (Task 5) Add auto-fix lint/test check after existing PostToolUse hooks in runPostToolUseHooks. When autoFix is configured in settings, runs lint/test commands after file_edit/file_write tools and yields errors as hook_additional_context for the model to act on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add /auto-fix slash command Adds the /auto-fix prompt command that helps users configure autoFix settings (lint/test commands, maxRetries, timeout) in .claude/settings.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: remove unused imports in autoFixRunner test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address review feedback — enforce maxRetries, wire abort signal, use cross-platform shell 1. Enforce maxRetries: track auto-fix attempts per query chain in toolHooks.ts and stop feeding errors back after the configured limit is reached. 2. Wire abort signal to subprocess: subscribe to AbortController signal in runCommand() and kill the process tree on abort. Uses detached process groups on Unix to ensure child processes are also terminated. 3. Replace hardcoded bash with shell:true: use Node's cross-platform shell resolution instead of spawn('bash', ['-c', ...]) so auto-fix commands work on Windows and non-bash environments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…wigpine#508) * feat: add AutoFix config schema and reader module Implements AutoFixConfigSchema (Zod v4) with validation for lint/test commands, maxRetries (0-10, default 3), and timeout (1000-300000ms, default 30000). Adds getAutoFixConfig helper that returns null for disabled or invalid configs. All 9 unit tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix runner with lint/test command execution Implements AutoFixRunner (Task 2) - executes lint and test shell commands sequentially, short-circuits on lint failure, handles timeouts, and produces structured AutoFixResult with AI-friendly error summaries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix field to SettingsSchema with integration tests Integrates AutoFixConfigSchema into SettingsSchema so autoFix settings are validated at the settings layer. Adds two integration tests verifying that valid configs are accepted and invalid configs (enabled with no commands) are rejected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix hook integration helpers (Task 4) Implements shouldRunAutoFix and buildAutoFixContext functions used by the PostToolUse hook to determine when to run auto-fix and format errors as AI-readable context for injection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: wire autoFix into PostToolUse hook flow (Task 5) Add auto-fix lint/test check after existing PostToolUse hooks in runPostToolUseHooks. When autoFix is configured in settings, runs lint/test commands after file_edit/file_write tools and yields errors as hook_additional_context for the model to act on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add /auto-fix slash command Adds the /auto-fix prompt command that helps users configure autoFix settings (lint/test commands, maxRetries, timeout) in .claude/settings.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: remove unused imports in autoFixRunner test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address review feedback — enforce maxRetries, wire abort signal, use cross-platform shell 1. Enforce maxRetries: track auto-fix attempts per query chain in toolHooks.ts and stop feeding errors back after the configured limit is reached. 2. Wire abort signal to subprocess: subscribe to AbortController signal in runCommand() and kill the process tree on abort. Uses detached process groups on Unix to ensure child processes are also terminated. 3. Replace hardcoded bash with shell:true: use Node's cross-platform shell resolution instead of spawn('bash', ['-c', ...]) so auto-fix commands work on Windows and non-bash environments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…wigpine#508) * feat: add AutoFix config schema and reader module Implements AutoFixConfigSchema (Zod v4) with validation for lint/test commands, maxRetries (0-10, default 3), and timeout (1000-300000ms, default 30000). Adds getAutoFixConfig helper that returns null for disabled or invalid configs. All 9 unit tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix runner with lint/test command execution Implements AutoFixRunner (Task 2) - executes lint and test shell commands sequentially, short-circuits on lint failure, handles timeouts, and produces structured AutoFixResult with AI-friendly error summaries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix field to SettingsSchema with integration tests Integrates AutoFixConfigSchema into SettingsSchema so autoFix settings are validated at the settings layer. Adds two integration tests verifying that valid configs are accepted and invalid configs (enabled with no commands) are rejected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix hook integration helpers (Task 4) Implements shouldRunAutoFix and buildAutoFixContext functions used by the PostToolUse hook to determine when to run auto-fix and format errors as AI-readable context for injection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: wire autoFix into PostToolUse hook flow (Task 5) Add auto-fix lint/test check after existing PostToolUse hooks in runPostToolUseHooks. When autoFix is configured in settings, runs lint/test commands after file_edit/file_write tools and yields errors as hook_additional_context for the model to act on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add /auto-fix slash command Adds the /auto-fix prompt command that helps users configure autoFix settings (lint/test commands, maxRetries, timeout) in .claude/settings.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: remove unused imports in autoFixRunner test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address review feedback — enforce maxRetries, wire abort signal, use cross-platform shell 1. Enforce maxRetries: track auto-fix attempts per query chain in toolHooks.ts and stop feeding errors back after the configured limit is reached. 2. Wire abort signal to subprocess: subscribe to AbortController signal in runCommand() and kill the process tree on abort. Uses detached process groups on Unix to ensure child processes are also terminated. 3. Replace hardcoded bash with shell:true: use Node's cross-platform shell resolution instead of spawn('bash', ['-c', ...]) so auto-fix commands work on Windows and non-bash environments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
…wigpine#508) * feat: add AutoFix config schema and reader module Implements AutoFixConfigSchema (Zod v4) with validation for lint/test commands, maxRetries (0-10, default 3), and timeout (1000-300000ms, default 30000). Adds getAutoFixConfig helper that returns null for disabled or invalid configs. All 9 unit tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix runner with lint/test command execution Implements AutoFixRunner (Task 2) - executes lint and test shell commands sequentially, short-circuits on lint failure, handles timeouts, and produces structured AutoFixResult with AI-friendly error summaries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix field to SettingsSchema with integration tests Integrates AutoFixConfigSchema into SettingsSchema so autoFix settings are validated at the settings layer. Adds two integration tests verifying that valid configs are accepted and invalid configs (enabled with no commands) are rejected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: add autoFix hook integration helpers (Task 4) Implements shouldRunAutoFix and buildAutoFixContext functions used by the PostToolUse hook to determine when to run auto-fix and format errors as AI-readable context for injection. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * feat: wire autoFix into PostToolUse hook flow (Task 5) Add auto-fix lint/test check after existing PostToolUse hooks in runPostToolUseHooks. When autoFix is configured in settings, runs lint/test commands after file_edit/file_write tools and yields errors as hook_additional_context for the model to act on. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * feat: add /auto-fix slash command Adds the /auto-fix prompt command that helps users configure autoFix settings (lint/test commands, maxRetries, timeout) in .claude/settings.json. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * fix: remove unused imports in autoFixRunner test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: address review feedback — enforce maxRetries, wire abort signal, use cross-platform shell 1. Enforce maxRetries: track auto-fix attempts per query chain in toolHooks.ts and stop feeding errors back after the configured limit is reached. 2. Wire abort signal to subprocess: subscribe to AbortController signal in runCommand() and kill the process tree on abort. Uses detached process groups on Unix to ensure child processes are also terminated. 3. Replace hardcoded bash with shell:true: use Node's cross-platform shell resolution instead of spawn('bash', ['-c', ...]) so auto-fix commands work on Windows and non-bash environments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Adds a built-in auto-fix service that automatically runs user-configured lint and test commands after AI file edits (FileEdit, FileWrite). When errors are detected, they are fed back to the AI as additional context so it can self-repair — closing the manual feedback loop that currently requires users to run lint/test, copy errors, and paste them back.
Inspired by Aider's auto-lint-and-test loop, which is their #1 user satisfaction driver.
What's included
Config schema (
src/services/autoFix/autoFixConfig.ts) — Zod-validated settings withenabled,lint,test,maxRetries(0–10, default 3), andtimeout(1–300s, default 30s). Rejects enabled configs with no lint or test command.Runner (
src/services/autoFix/autoFixRunner.ts) — Executes lint/test commands viachild_process.spawn, captures stdout/stderr, enforces timeouts, skips tests if lint fails first, and builds an AI-readable error summary.Hook integration (
src/services/autoFix/autoFixHook.ts) —shouldRunAutoFix()gates execution to file_edit/file_write tools only.buildAutoFixContext()wraps errors in<auto_fix_feedback>tags that the AI can act on.PostToolUse wiring (
src/services/tools/toolHooks.ts) — After the existing PostToolUse hook loop, runs the auto-fix check and yields errors ashook_additional_contextattachment messages./auto-fixslash command (src/commands/auto-fix.ts) — Guided setup wizard that helps users configure their lint/test commands in settings.Settings schema (
src/utils/settings/types.ts) — Added optionalautoFixfield toSettingsSchema.Configuration
Add to
.claude/settings.jsonor.claude/settings.local.json:{ "autoFix": { "enabled": true, "lint": "eslint . --fix", "test": "bun test", "maxRetries": 3, "timeout": 30000 } }Or run
/auto-fixfor guided setup.How it works
Test coverage
Files changed
src/services/autoFix/autoFixConfig.tssrc/services/autoFix/autoFixConfig.test.tssrc/services/autoFix/autoFixRunner.tssrc/services/autoFix/autoFixRunner.test.tssrc/services/autoFix/autoFixHook.tssrc/services/autoFix/autoFixHook.test.tssrc/services/autoFix/autoFixIntegration.test.tssrc/commands/auto-fix.tssrc/commands.ts/auto-fixcommandsrc/services/tools/toolHooks.tssrc/utils/settings/types.tsautoFixto settings schema