feat: add auto-fix service — auto-lint and test after AI file edits#508
Open
gnanam1990 wants to merge 7 commits intomainfrom
Open
feat: add auto-fix service — auto-lint and test after AI file edits#508gnanam1990 wants to merge 7 commits intomainfrom
gnanam1990 wants to merge 7 commits intomainfrom
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>
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.
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