Fix
Failure-driven iterative repair. Detect → Prioritize → Fix ONE thing → Commit → Verify → Keep/Revert → Repeat.
When to Apply / NOT
Apply: user says "fix", "make it pass", "apply findings"; input is a verifier failure, findings file, or bug description.
NOT apply:
- CI/PR workflows with no local context → use
gh-fix-ci
- PR review comments → use
gh-address-comments
- Merge conflicts
- Analysis-only tasks → use
resolve or debug
- Planned change without a failure driver → use
proceed
Detected Mode Acknowledgement [LOAD-BEARING]
First output line before ANY edit:
detected: <mode> — target=TARGET guard=GUARD scope=SCOPE cap=20
Mode values: gh-route, findings, verifier-failure, bug-spec. Full classifier: references/classifier.md.
Input Classifier
First-match wins. Full detail: references/classifier.md.
| Priority |
Mode |
Minimum condition |
| 1 |
gh-route |
GH-flavored input + open PR + gh auth status clean |
| 2 |
findings |
Path to */findings.md, */review/*.md, or structured findings text |
| 3 |
verifier-failure |
Raw verifier stdout (FAILED, error TS, --- FAIL, etc.) |
| 4 |
bug-spec |
Natural-language description — catch-all fallback |
Auto-Detect Gate
Auto-infer: target verifier, scope glob, guard command, iteration cap (default 20).
Trigger AskUserQuestion (single-select per axis, NEVER multiSelect) when:
MIXED_MODE: findings artifact AND verifier-failure output both present
GH_PARTIAL: GH-flavored input but no open PR, or gh auth status fails
LANG_UNKNOWN: verifier-failure detected but verifier undetectable
SCOPE_AMBIGUOUS: bug-spec with no module, file, or component reference
Iterative Loop
Full spec: references/loop.md. Key rules:
- One fix per iteration. Apply fix → stage checkpoint commit → run verifiers → KEEP on green, revert with
git revert HEAD --no-edit on red. A commit is kept only when the guard passes.
- Decide matrix:
delta > 0 + guard ok → KEEP
delta > 0 + guard fail → REWORK (max 2 reworks per item; 4th attempt → SKIP)
delta ≤ 0 → DISCARD — revert immediately
- 3 total skips → HALT with summary
- Revert: always
git revert HEAD --no-edit. Never reset --hard.
- Cap: 20 iterations default. Print progress every 5 iterations.
- Refuse loop on protected branches (
main, master, release/*).
- Override:
iterations: N or --iterations N in invocation.
Verifier Detection
Repo-native first (use fd --max-depth 2 to locate):
Justfile → just test (guard: just check)
Makefile → make test (guard: make check)
package.json → npm test (guard: tsc --noEmit && eslint .)
dune-project → dune build @runtest (guard: dune build)
Language fallbacks:
- Python:
pytest + ruff check . && mypy .
- TypeScript:
vitest run + tsc --noEmit && eslint .
- Rust:
cargo test + cargo clippy -- -D warnings
- Go:
go test ./... + golangci-lint run
- OCaml:
dune build @runtest + dune build
Full matrix: references/verifiers.md.
GH Auto-Route
When open PR + gh auth status clean + GH-flavored input:
| Sub-target |
Trigger language |
gh-fix-ci |
"CI", "Actions", "workflow", "checks", Actions run URL |
gh-address-comments |
"reviewer said", "address comment", "PR feedback", "requested changes" |
Both sets of language → fire AMBIGUOUS_GH_ROUTE (single-select: gh-fix-ci vs gh-address-comments).
Partial match → GH_PARTIAL ambiguity flag.
Hand-off & Integration
debug upstream: unclear root cause — debug findings become the fix target.
triage-issue upstream: bug-spec mode — triage produces repro + TDD plan first.
test-driven partner: failing test ↔ green flip; delegate RED→GREEN cycle.
proceed complement: planned change without failure → proceed; failure-driven → fix.
resolve / review / triage-issue as findings sources: their output paths feed findings mode.
Failure Modes
- No verifier output: emit warning, raise
LANG_UNKNOWN.
- 3 strikes on one item: SKIP, add to
blocked.md, recommend debug.
- 3 total skips: HALT with session summary.
- Guard ambiguous:
AskUserQuestion for guard command.
- Mixed-mode input: raise
MIXED_MODE.
- Protected branch: REFUSE with message before entering loop.
Anti-Patterns
- Never
@ts-ignore / # type: ignore / // eslint-disable to silence errors.
- Never delete tests to make them pass.
- ONE fix per iteration — no "while I'm here" changes.
- No
git reset --hard.
- Recursion guard:
--mode <X> bypasses classifier entirely; gh-fix-ci re-entering as fix --mode verifier-failure cannot loop back into gh-fix-ci.
Constitutional Rules
- Evidence before claims: run verifiers, read output, then state result.
- Compress-first: reduce coupling before behavior change.
- Atomic commits: one concern per commit; guard must pass before a loop commit is kept (KEEP in decide matrix = tests-pass gate).
- Never skip the guard.
- Full specs:
references/loop.md, references/classifier.md, references/verifiers.md.
1---2name: fix-33description: Polymorphic iterative repair loop — accept a verifier failure, structured findings (review/resolve/triage-issue), or a bug description; modify→verify→keep on green, auto-revert on guard regression, until clean or iteration cap. Use when the user says "fix", "make it pass", or "apply the findings", or hands an artifact + repo and expects patches; auto-routes to gh-fix-ci or gh-address-comments when an open PR + gh auth + GH-flavored input is detected.4---5
6# Fix
7
8Failure-driven iterative repair. Detect → Prioritize → Fix ONE thing → Commit → Verify → Keep/Revert → Repeat.
9
10## When to Apply / NOT
11
12**Apply:** user says "fix", "make it pass", "apply findings"; input is a verifier failure, findings file, or bug description.
13
14**NOT apply:**
15- CI/PR workflows with no local context → use `gh-fix-ci`
16- PR review comments → use `gh-address-comments`
17- Merge conflicts
18- Analysis-only tasks → use `resolve` or `debug`
19- Planned change without a failure driver → use `proceed`
20
21## Detected Mode Acknowledgement [LOAD-BEARING]
22
23First output line before ANY edit:
24
25```
26detected: <mode> — target=TARGET guard=GUARD scope=SCOPE cap=20
27```
28
29Mode values: `gh-route`, `findings`, `verifier-failure`, `bug-spec`. Full classifier: `references/classifier.md`.
30
31## Input Classifier
32
33First-match wins. Full detail: `references/classifier.md`.
34
35| Priority | Mode | Minimum condition |
36|----------|------|-------------------|
37| 1 | `gh-route` | GH-flavored input + open PR + `gh auth status` clean |
38| 2 | `findings` | Path to `*/findings.md`, `*/review/*.md`, or structured findings text |
39| 3 | `verifier-failure` | Raw verifier stdout (`FAILED`, `error TS`, `--- FAIL`, etc.) |
40| 4 | `bug-spec` | Natural-language description — catch-all fallback |
41
42## Auto-Detect Gate
43
44Auto-infer: target verifier, scope glob, guard command, iteration cap (default 20).
45
46Trigger `AskUserQuestion` (single-select per axis, NEVER `multiSelect`) when:
47
48- `MIXED_MODE`: findings artifact AND verifier-failure output both present
49- `GH_PARTIAL`: GH-flavored input but no open PR, or `gh auth status` fails
50- `LANG_UNKNOWN`: verifier-failure detected but verifier undetectable
51- `SCOPE_AMBIGUOUS`: bug-spec with no module, file, or component reference
52
53## Iterative Loop
54
55Full spec: `references/loop.md`. Key rules:
56
57- One fix per iteration. Apply fix → stage checkpoint commit → run verifiers → **KEEP** on green, revert with `git revert HEAD --no-edit` on red. A commit is *kept* only when the guard passes.
58- Decide matrix:
59 - `delta > 0` + guard ok → **KEEP**
60 - `delta > 0` + guard fail → **REWORK** (max 2 reworks per item; 4th attempt → SKIP)
61 - `delta ≤ 0` → **DISCARD** — revert immediately
62 - 3 total skips → **HALT** with summary
63- Revert: always `git revert HEAD --no-edit`. Never `reset --hard`.
64- Cap: 20 iterations default. Print progress every 5 iterations.
65- Refuse loop on protected branches (`main`, `master`, `release/*`).
66- Override: `iterations: N` or `--iterations N` in invocation.
67
68## Verifier Detection
69
70Repo-native first (use `fd --max-depth 2` to locate):
71
721. `Justfile` → `just test` (guard: `just check`)
732. `Makefile` → `make test` (guard: `make check`)
743. `package.json` → `npm test` (guard: `tsc --noEmit && eslint .`)
754. `dune-project` → `dune build @runtest` (guard: `dune build`)
76
77Language fallbacks:
78- Python: `pytest` + `ruff check . && mypy .`
79- TypeScript: `vitest run` + `tsc --noEmit && eslint .`
80- Rust: `cargo test` + `cargo clippy -- -D warnings`
81- Go: `go test ./...` + `golangci-lint run`
82- OCaml: `dune build @runtest` + `dune build`
83
84Full matrix: `references/verifiers.md`.
85
86## GH Auto-Route
87
88When open PR + `gh auth status` clean + GH-flavored input:
89
90| Sub-target | Trigger language |
91|------------|-----------------|
92| `gh-fix-ci` | "CI", "Actions", "workflow", "checks", Actions run URL |
93| `gh-address-comments` | "reviewer said", "address comment", "PR feedback", "requested changes" |
94
95Both sets of language → fire `AMBIGUOUS_GH_ROUTE` (single-select: `gh-fix-ci` vs `gh-address-comments`).
96Partial match → `GH_PARTIAL` ambiguity flag.
97
98## Hand-off & Integration
99
100- `debug` upstream: unclear root cause — debug findings become the fix target.
101- `triage-issue` upstream: bug-spec mode — triage produces repro + TDD plan first.
102- `test-driven` partner: failing test ↔ green flip; delegate RED→GREEN cycle.
103- `proceed` complement: planned change without failure → `proceed`; failure-driven → `fix`.
104- `resolve` / `review` / `triage-issue` as findings sources: their output paths feed findings mode.
105
106## Failure Modes
107
108- No verifier output: emit warning, raise `LANG_UNKNOWN`.
109- 3 strikes on one item: SKIP, add to `blocked.md`, recommend `debug`.
110- 3 total skips: HALT with session summary.
111- Guard ambiguous: `AskUserQuestion` for guard command.
112- Mixed-mode input: raise `MIXED_MODE`.
113- Protected branch: REFUSE with message before entering loop.
114
115## Anti-Patterns
116
117- Never `@ts-ignore` / `# type: ignore` / `// eslint-disable` to silence errors.
118- Never delete tests to make them pass.
119- ONE fix per iteration — no "while I'm here" changes.
120- No `git reset --hard`.
121- Recursion guard: `--mode <X>` bypasses classifier entirely; `gh-fix-ci` re-entering as `fix --mode verifier-failure` cannot loop back into `gh-fix-ci`.
122
123## Constitutional Rules
124
125- Evidence before claims: run verifiers, read output, then state result.
126- Compress-first: reduce coupling before behavior change.
127- Atomic commits: one concern per commit; guard must pass before a loop commit is **kept** (KEEP in decide matrix = tests-pass gate).
128- Never skip the guard.
129- Full specs: `references/loop.md`, `references/classifier.md`, `references/verifiers.md`.