Skip to content

feat: add auto-fix service — auto-lint and test after AI file edits#508

Open
gnanam1990 wants to merge 7 commits intomainfrom
feat/auto-fix-service
Open

feat: add auto-fix service — auto-lint and test after AI file edits#508
gnanam1990 wants to merge 7 commits intomainfrom
feat/auto-fix-service

Conversation

@gnanam1990
Copy link
Copy Markdown
Collaborator

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 with enabled, lint, test, maxRetries (0–10, default 3), and timeout (1–300s, default 30s). Rejects enabled configs with no lint or test command.

  • Runner (src/services/autoFix/autoFixRunner.ts) — Executes lint/test commands via child_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 as hook_additional_context attachment messages.

  • /auto-fix slash 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 optional autoFix field to SettingsSchema.

Configuration

Add to .claude/settings.json or .claude/settings.local.json:

{
  "autoFix": {
    "enabled": true,
    "lint": "eslint . --fix",
    "test": "bun test",
    "maxRetries": 3,
    "timeout": 30000
  }
}

Or run /auto-fix for guided setup.

How it works

AI edits file → lint runs → errors? → feed back to AI → AI fixes → re-lint
                         ↓ no errors
                    tests run → failures? → feed back to AI → AI fixes → re-test
                             ↓ no failures
                        clean result delivered

Test coverage

  • 29 tests across 4 test files (config, runner, hook, integration)
  • 541/541 full suite tests pass
  • Zero new type errors
  • Build succeeds

Files changed

File Change
src/services/autoFix/autoFixConfig.ts New — config schema and reader
src/services/autoFix/autoFixConfig.test.ts New — 11 tests
src/services/autoFix/autoFixRunner.ts New — command execution engine
src/services/autoFix/autoFixRunner.test.ts New — 8 tests
src/services/autoFix/autoFixHook.ts New — hook helpers
src/services/autoFix/autoFixHook.test.ts New — 8 tests
src/services/autoFix/autoFixIntegration.test.ts New — 2 e2e tests
src/commands/auto-fix.ts New — slash command
src/commands.ts Register /auto-fix command
src/services/tools/toolHooks.ts Wire auto-fix into PostToolUse
src/utils/settings/types.ts Add autoFix to settings schema

gnanam1990 and others added 6 commits April 8, 2026 14:51
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>
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.

1 participant