$npx -y skills add softspark/ai-toolkit --skill fixApplies targeted fix to known bug/lint error, verifies with same command that surfaced it. Triggers: fix, apply fix, fix bug, fix lint, targeted fix.
| 1 | # Fix Command |
| 2 | |
| 3 | $ARGUMENTS |
| 4 | |
| 5 | Attempts to fix code errors autonomously. |
| 6 | |
| 7 | ## Usage |
| 8 | |
| 9 | ```bash |
| 10 | /fix <file_or_scope> |
| 11 | # Example: /fix src/utils.ts |
| 12 | ``` |
| 13 | |
| 14 | ## Automated Error Classification |
| 15 | |
| 16 | Before entering the fix loop, classify errors to prioritize auto-fixable ones: |
| 17 | |
| 18 | ```bash |
| 19 | # Pipe lint or test output |
| 20 | ruff check . 2>&1 | python3 "$(dirname "$0")/scripts/error-classifier.py" |
| 21 | mypy src/ 2>&1 | python3 scripts/error-classifier.py |
| 22 | npx eslint . 2>&1 | python3 scripts/error-classifier.py |
| 23 | ``` |
| 24 | |
| 25 | The script outputs JSON with: |
| 26 | - **total_errors**: count of all parsed errors |
| 27 | - **auto_fixable_count**: errors that tools can fix automatically (e.g., F401 unused imports, formatting) |
| 28 | - **manual_count**: errors requiring human/agent intervention |
| 29 | - **tools_detected**: which linters produced the output (ruff, mypy, eslint, tsc, phpstan) |
| 30 | - **errors[]**: each error with file, line, code, message, and auto_fixable flag |
| 31 | - **suggested_order**: files to fix, auto-fixable first |
| 32 | - **fix_strategy**: recommended approach (auto-fix first, then manual) |
| 33 | |
| 34 | Use this to run auto-fixers (e.g., `ruff check --fix .`) before spending time on manual fixes. |
| 35 | |
| 36 | --- |
| 37 | |
| 38 | ## Protocol (The "Fix Loop") |
| 39 | |
| 40 | 1. **Analyze**: Run validation to get the exact error message. |
| 41 | ```bash |
| 42 | # Get error |
| 43 | npm test src/utils.ts 2>&1 | tee error.log |
| 44 | ``` |
| 45 | |
| 46 | 2. **Diagnose**: Analyze `error.log`. |
| 47 | - Use `debugging-tactics` skill. |
| 48 | - Trace the error to the source line. |
| 49 | |
| 50 | 3. **Patch**: Apply a fix. |
| 51 | - Use `sed` or `write_file`. |
| 52 | |
| 53 | 4. **Verify**: Run validation again. |
| 54 | - If PASS: Stop. |
| 55 | - If FAIL: Repeat (Max 3 retries). |
| 56 | |
| 57 | ## Safety Limits |
| 58 | - **Max Retries**: 3 |
| 59 | - **Scope**: Only modify the specified files. |
| 60 | - **Stop Condition**: If new errors appear that are totally different, STOP and ask user. |
| 61 | |
| 62 | ## Example Flow |
| 63 | ``` |
| 64 | User: /fix app.py |
| 65 | Agent: Running tests... FAIL (NameError) |
| 66 | Agent: Fixing app.py (Import missing module) |
| 67 | Agent: Running tests... PASS |
| 68 | Agent: Fixed NameError in app.py |
| 69 | ``` |
| 70 | |
| 71 | ## Rules |
| 72 | |
| 73 | - **MUST** know the exact symptom (error message, failing test, lint code) before editing — guessing is not fixing |
| 74 | - **MUST** verify the fix by rerunning **the same command** that exposed the problem, not a different validator |
| 75 | - **NEVER** modify tests to make them pass — fixing the test is not fixing the bug |
| 76 | - **NEVER** touch files outside the declared scope — scope creep hides regressions |
| 77 | - **CRITICAL**: hard-stop after 3 iterations. If the fix loop has not converged, the problem is deeper than `/fix` handles — escalate to `/debug`. |
| 78 | - **MANDATORY**: if new, unrelated errors appear during a fix attempt, stop and ask the user — do not chase them |
| 79 | |
| 80 | ## Gotchas |
| 81 | |
| 82 | - `ruff check --fix` reorders imports and rewrites them. On files with circular imports or conditional-imports-under-TYPE_CHECKING, the "fix" can break things silently. Run `--check` first, inspect the diff, then apply. |
| 83 | - `eslint --fix --cache` skips already-cached files even if their content changed (cache invalidation by mtime). On first-run misses, clear the cache with `--no-cache` to force a complete pass. |
| 84 | - `mypy --install-types` auto-installs stub packages, adding dependencies to the environment the user did not request. Reserve it for explicit opt-in; in CI, pass `--non-interactive` to prevent surprise installs. |
| 85 | - `npm test -- path/to/test` in a workspace repo runs the **root** workspace's test runner, not the leaf package's. Use `npm test --workspace=<name>` or the per-package `cd packages/foo && npm test` form. |
| 86 | - Fix loops occasionally produce **cycle diffs** — iteration 1 fixes A which triggers B, iteration 2 fixes B which re-breaks A. After every iteration compare the diff to the previous; identical or inverse diffs mean a cycle — stop. |
| 87 | |
| 88 | ## When NOT to Use |
| 89 | |
| 90 | - When the root cause is unknown — use `/debug` first, then `/fix` with a clear target |
| 91 | - For systemic refactoring across modules — use `/refactor` or `/refactor-plan` |
| 92 | - For writing new features test-first — use `/tdd` |
| 93 | - For CI failures spanning many files — use `/workflow debugging` (coordinated) |
| 94 | - When the failing validation is itself broken — repair the validator separately, do not patch code to satisfy it |