IMP
Intent
Ship bead-scoped changes end-to-end with proof, then immediately self-review the resulting PR using TRACE and fix what you find.
IMP is a combined execution + review + closure protocol:
- Write code with strong invariants and minimal incision.
- Validate with a full check suite.
- Open a PR.
- Review that PR right away and resolve findings.
- Select the next bead (so bead state is committed).
- Update/monitor/merge/cleanup (CL).
Definition of Done (IMP)
An imp run is done when:
- The bead’s acceptance criteria are satisfied.
- The working tree contains only bead-aligned changes.
- Format + lint/typecheck + build + tests have run (or are explicitly recorded as unavailable).
$close-the-loop is invoked and at least one signal is recorded.
- The worked bead is marked
done before PR creation.
- A PR is opened.
- A TRACE self-review is produced (in chat) and all 🔥 + 🟡 items are resolved.
$select is run once (to pick exactly one next bead), and resulting bead state changes (e.g. issues.jsonl) are committed into the PR.
- The PR is updated and squash-merged when either:
- CI is green, or
- CI is billing-blocked (
billing appears in CI failure text), zig build ci passes, and the PR is squash-mergeable.
- Local state is cleaned up.
- A bead comment exists with PR link + proof summary.
Guardrails
- Explicit-only; never auto-trigger.
- Source of truth:
bd wins.
- Surgeon’s principle: smallest correct change.
- No intentional product/semantic changes without clarifying.
- Don’t split into multiple PRs unless explicitly asked.
- Don’t merge until the final CL step.
Autonomy gate (conviction)
Proceed without asking only when all are true:
- Local repro (or a tight, credible signal).
- Invariant stated.
- Minimal diff.
- At least one validation signal passes.
Otherwise: clarify before editing.
Core doctrine (canonical)
This section is the single source of truth for how we write and review code.
Surgeon’s principle
- Prefer the smallest change that could be correct.
- Make progress legible and reversible.
- Trade breadth for certainty: keep diffs bead-scoped.
TRACE checklist
- Type: make invalid states unrepresentable.
- Readability: understandable in 30 seconds.
- Atomic: one responsibility; explicit side effects.
- Cognitive: minimize branching/hidden deps/cross-file hops.
- Essential: keep only domain-required complexity.
Complexity Mitigator (CM)
- Keep essential complexity; vaporize incidental.
- Default sequence: flatten → rename → extract.
- If simplification requires new invariants, strengthen them first.
Invariant Ace (IA)
- Name the invariant at risk and current protection level.
- Prefer construction-time/compile-time guarantees.
- If that’s not viable, add the tightest test/assertion that locks the invariant.
Universalist (UN)
- Prefer the smallest algebra that fits: product/coproduct/monoid before higher abstractions.
- Name the laws (identity/associativity/composition) and add a lightweight check when feasible.
Workflow
0) Preflight (don’t skip)
- Confirm the repo uses beads (a
.beads/ directory exists).
- Confirm
imp was explicitly invoked.
- If anything blocks progress (missing requirements, no bead, unrelated diffs), stop and resolve before coding.
1) Identify the active bead (source of truth)
- Anchor on
bd (not chat context).
- Find the in-progress bead.
- If no bead is in progress: invoke
$select to pick the next bd ready bead, then mark it in progress.
- Restate what “done” means for this bead (1 sentence + acceptance criteria).
2) Clarify until requirements are implementable
- Ask only judgment calls (preferences, tradeoffs, acceptance thresholds).
- Everything else should be discovered in-repo (code, tests, conventions) or in the bead.
- If you encounter ambiguity mid-implementation, stop and re-clarify.
3) Audit the working tree (scope containment)
- Audit changes early and often.
- Keep only bead-aligned diffs.
- Do not smuggle in drive-by refactors.
If you find unrelated work:
- Revert/stash it (or split it only if explicitly asked).
4) Mandatory TRACE mini-pass (before first incision)
Before changing code, do a small $fix pass:
- Cognitive heat map: note hotspots + surprises.
- Triage failure modes: crash > corruption > logic.
- State the invariant: what must remain true after the change?
- Footgun scan: any misuse-prone surface being touched?
- Incidental complexity: plan to flatten/rename/extract only if it reduces risk.
5) Complexity gate (invoke CPS)
If you identify a complex problem (multi-constraint, cross-subsystem, high uncertainty, or multiple viable designs), invoke $creative-problem-solver.
CPS autonomy rule:
- If a clear Advantage Play or Moonshot emerges, pick one and proceed.
- Otherwise, ask for human selection before implementation.
Record (in chat and later in proof): chosen tier + rationale + escape hatch.
6) Surgeon loop (implement + re-check)
Use a tight loop so progress stays legible and reversible:
- Form a hypothesis: what change likely satisfies the bead?
- Choose the smallest incision: smallest change that could be correct.
- Make it observable: add/adjust a test, invariant, or log to prove/diagnose.
- Implement: modify code with minimal collateral.
- Re-check locally: re-run the closest fast signal (focused test, typecheck, repro script).
- Repeat until acceptance criteria pass.
Heuristics by bead type:
- Bug: reproduce if possible; otherwise create a characterization test or diagnostic signal, then fix.
- Feature: implement the smallest end-to-end slice that users can exercise (vertical slice > layered scaffolding).
- Refactor: preserve behavior; add a characterization test/invariant first.
7) Validation (all musts)
Run these categories every time:
- Formatters (autoformat).
- Lint/typecheck (static analysis).
- Build (compile/package).
- Tests (unit/integration as available).
Order (fastest-first):
- Run the fastest local checks first (formatter + lint/typecheck + focused tests).
- Then run the slower checks (build + full test suites).
Entry points:
- Prefer the repo’s canonical entrypoints (
make, just, task, npm run, cargo, go test, etc.).
- If multiple relevant entrypoints exist for a category, run all of them (or explicitly justify why one is skipped).
If a category genuinely doesn’t exist, record it as N/A in proof with a 1-line reason and run the nearest substitute.
Billing-only CI substitute (Zig):
- Trigger: hosted CI is blocked (CI failure text contains
billing).
- Run
zig build ci before opening the PR.
- If CI is still not green at merge time, run
zig build ci again immediately before squash-merge.
- If
zig build ci is unavailable, record N/A.
8) Invoke $close-the-loop (required)
$close-the-loop is the forcing function: record at least one signal after you’ve made the change and run validations.
9) Close the worked bead (required)
Before creating the PR:
- Mark the worked bead as
done.
Note: this typically updates bead state files (e.g. issues.jsonl). Those changes are part of the workflow and must be included in the PR.
10) Open a PR (do not merge yet)
- Open a single PR.
- Do not merge yet.
11) Immediate TRACE self-review (required, post-PR)
Review the PR output immediately and resolve findings.
Rules:
- Findings must be in severity order.
- Include
file:line references.
- Include violated TRACE letters.
- Resolve all 🔥 + 🟡 items (no deferrals).
If fixes are required:
- Apply smallest sound fixes.
- Re-run validations (Step 7).
- Re-invoke
$close-the-loop (Step 8).
- Repeat review until no 🔥 or 🟡 remain.
12) Select the next bead (required, post-review)
Run the $select workflow once to choose exactly one next bead.
Intent:
- Pick the next
bd ready bead via risk-first heuristics.
- Verify dependency/readiness.
- Add missing deps and restart selection when needed.
- Mark the chosen bead
in_progress and leave a short rationale comment.
Critical requirement:
- The bead state changes produced here (commonly
issues.jsonl updates) must be committed and included in the current PR.
13) CL: update PR → check CI + mergeability → squash → cleanup
Follow codex/prompts/CL.md, with a billing-only CI bypass:
- Update the PR.
- Confirm the PR is squash-mergeable (no merge conflict). If conflicting, merge/rebase the base branch and resolve conflicts.
- Check CI status (e.g.,
gh pr checks).
- If CI is green: squash-merge.
- If CI is not green:
- If CI failure text contains
billing: run zig build ci (again, immediately before merge). If it passes and the PR is squash-mergeable, squash-merge.
- Otherwise: keep fixes minimal, and iterate until CI is green.
- Cleanup local state.
CI policy:
- Default: treat non-
billing CI failures as real (fix → re-run validations + $close-the-loop).
- Bypass: only skip “wait for green” when CI failure text contains
billing.
14) Record proof (make results auditable)
Record proof in both places:
- PR description: full command list + outcomes.
- Bead comment: short proof summary + PR link.
Proof should include:
- Signals: commands run and outcomes.
- Decision: if CPS was used, record tier + rationale + escape hatch.
- Notes: any N/A validations, known limitations.
Deliverable format (chat)
A) Work summary
- Bead:
<id> + 1-sentence “done means”.
- Change summary: what and why.
B) TRACE self-review (severity order)
For each finding:
file:line — issue — violated TRACE letters — fix applied.
C) Proof
- Format:
<cmd> → <ok/fail>
- Lint/typecheck:
<cmd> → <ok/fail>
- Build:
<cmd> → <ok/fail>
- Tests:
<cmd> → <ok/fail>
- CI substitute (if
billing): zig build ci (pre-PR; pre-merge if needed) → <ok/fail>
$close-the-loop: <signal>
- PR:
<url>
- Merge:
<squash ok/fail>
- Bead comment:
<posted/blocked>
Failure paths
- No in-progress bead: invoke
$select, mark chosen bead in progress, then proceed.
- Unclear requirements: stop and ask; do not guess.
- Unrelated diffs: ignore; don't touch or stage; continue. If the requested change would touch the same lines/hunks, stop and ask.
- Validation fails: fix and re-run before opening the PR.
- CI is not green:
- If CI failure text contains
billing, run zig build ci and treat “squash-mergeable + zig build ci ok” as green.
- Otherwise, keep fixing until CI is green.
- PR is not squash-mergeable (merge conflict): merge/rebase the base branch, resolve conflicts, then re-run validations (Step 7) and retry merge.
- Bug can’t be reproduced: add instrumentation or a characterization test; clearly state limits in proof.
Activation cues
- "imp"
- "ship this bead"
- "implement then review"
- "PR-ready with proof"
1---2name: imp3description: Unified shipping + TRACE self-review protocol (beads, proof, PR). Explicit-only.4---5
6# IMP
7
8## Intent
9Ship bead-scoped changes end-to-end with proof, then immediately self-review the resulting PR using TRACE and fix what you find.
10
11IMP is a combined *execution + review + closure* protocol:
12- Write code with strong invariants and minimal incision.
13- Validate with a full check suite.
14- Open a PR.
15- Review that PR right away and resolve findings.
16- Select the next bead (so bead state is committed).
17- Update/monitor/merge/cleanup (CL).
18
19## Definition of Done (IMP)
20An `imp` run is done when:
21- The bead’s acceptance criteria are satisfied.
22- The working tree contains only bead-aligned changes.
23- Format + lint/typecheck + build + tests have run (or are explicitly recorded as unavailable).
24- `$close-the-loop` is invoked and at least one signal is recorded.
25- The worked bead is marked `done` before PR creation.
26- A PR is opened.
27- A TRACE self-review is produced (in chat) and all 🔥 + 🟡 items are resolved.
28- `$select` is run once (to pick exactly one next bead), and resulting bead state changes (e.g. `issues.jsonl`) are committed into the PR.
29- The PR is updated and squash-merged when either:
30 - CI is green, or
31 - CI is billing-blocked (`billing` appears in CI failure text), `zig build ci` passes, and the PR is squash-mergeable.
32- Local state is cleaned up.
33- A bead comment exists with PR link + proof summary.
34
35## Guardrails
36- Explicit-only; never auto-trigger.
37- Source of truth: `bd` wins.
38- Surgeon’s principle: smallest correct change.
39- No intentional product/semantic changes without clarifying.
40- Don’t split into multiple PRs unless explicitly asked.
41- Don’t merge until the final CL step.
42
43## Autonomy gate (conviction)
44Proceed without asking only when all are true:
45- Local repro (or a tight, credible signal).
46- Invariant stated.
47- Minimal diff.
48- At least one validation signal passes.
49
50Otherwise: clarify before editing.
51
52## Core doctrine (canonical)
53This section is the single source of truth for how we write and review code.
54
55### Surgeon’s principle
56- Prefer the smallest change that could be correct.
57- Make progress legible and reversible.
58- Trade breadth for certainty: keep diffs bead-scoped.
59
60### TRACE checklist
61- Type: make invalid states unrepresentable.
62- Readability: understandable in 30 seconds.
63- Atomic: one responsibility; explicit side effects.
64- Cognitive: minimize branching/hidden deps/cross-file hops.
65- Essential: keep only domain-required complexity.
66
67### Complexity Mitigator (CM)
68- Keep essential complexity; vaporize incidental.
69- Default sequence: flatten → rename → extract.
70- If simplification requires new invariants, strengthen them first.
71
72### Invariant Ace (IA)
73- Name the invariant at risk and current protection level.
74- Prefer construction-time/compile-time guarantees.
75- If that’s not viable, add the tightest test/assertion that locks the invariant.
76
77### Universalist (UN)
78- Prefer the smallest algebra that fits: product/coproduct/monoid before higher abstractions.
79- Name the laws (identity/associativity/composition) and add a lightweight check when feasible.
80
81## Workflow
82
83### 0) Preflight (don’t skip)
84- Confirm the repo uses beads (a `.beads/` directory exists).
85- Confirm `imp` was explicitly invoked.
86- If anything blocks progress (missing requirements, no bead, unrelated diffs), stop and resolve before coding.
87
88### 1) Identify the active bead (source of truth)
891. Anchor on `bd` (not chat context).
902. Find the in-progress bead.
913. If no bead is in progress: invoke `$select` to pick the next `bd ready` bead, then mark it in progress.
924. Restate what “done” means for this bead (1 sentence + acceptance criteria).
93
94### 2) Clarify until requirements are implementable
95- Ask only judgment calls (preferences, tradeoffs, acceptance thresholds).
96- Everything else should be discovered in-repo (code, tests, conventions) or in the bead.
97- If you encounter ambiguity mid-implementation, stop and re-clarify.
98
99### 3) Audit the working tree (scope containment)
100- Audit changes early and often.
101- Keep only bead-aligned diffs.
102- Do not smuggle in drive-by refactors.
103
104If you find unrelated work:
105- Revert/stash it (or split it only if explicitly asked).
106
107### 4) Mandatory TRACE mini-pass (before first incision)
108Before changing code, do a small `$fix` pass:
1091. Cognitive heat map: note hotspots + surprises.
1102. Triage failure modes: crash > corruption > logic.
1113. State the invariant: what must remain true after the change?
1124. Footgun scan: any misuse-prone surface being touched?
1135. Incidental complexity: plan to flatten/rename/extract only if it reduces risk.
114
115### 5) Complexity gate (invoke CPS)
116If you identify a *complex problem* (multi-constraint, cross-subsystem, high uncertainty, or multiple viable designs), invoke `$creative-problem-solver`.
117
118CPS autonomy rule:
119- If a clear **Advantage Play** or **Moonshot** emerges, pick one and proceed.
120- Otherwise, ask for human selection before implementation.
121
122Record (in chat and later in proof): chosen tier + rationale + escape hatch.
123
124### 6) Surgeon loop (implement + re-check)
125Use a tight loop so progress stays legible and reversible:
1261. Form a hypothesis: what change likely satisfies the bead?
1272. Choose the smallest incision: smallest change that could be correct.
1283. Make it observable: add/adjust a test, invariant, or log to prove/diagnose.
1294. Implement: modify code with minimal collateral.
1305. Re-check locally: re-run the closest fast signal (focused test, typecheck, repro script).
1316. Repeat until acceptance criteria pass.
132
133Heuristics by bead type:
134- Bug: reproduce if possible; otherwise create a characterization test or diagnostic signal, then fix.
135- Feature: implement the smallest end-to-end slice that users can exercise (vertical slice > layered scaffolding).
136- Refactor: preserve behavior; add a characterization test/invariant first.
137
138### 7) Validation (all musts)
139Run these categories every time:
140- Formatters (autoformat).
141- Lint/typecheck (static analysis).
142- Build (compile/package).
143- Tests (unit/integration as available).
144
145Order (fastest-first):
146- Run the fastest local checks first (formatter + lint/typecheck + focused tests).
147- Then run the slower checks (build + full test suites).
148
149Entry points:
150- Prefer the repo’s canonical entrypoints (`make`, `just`, `task`, `npm run`, `cargo`, `go test`, etc.).
151- If multiple relevant entrypoints exist for a category, run all of them (or explicitly justify why one is skipped).
152
153If a category genuinely doesn’t exist, record it as **N/A** in proof with a 1-line reason and run the nearest substitute.
154
155Billing-only CI substitute (Zig):
156- Trigger: hosted CI is blocked (CI failure text contains `billing`).
157- Run `zig build ci` before opening the PR.
158- If CI is still not green at merge time, run `zig build ci` again immediately before squash-merge.
159- If `zig build ci` is unavailable, record **N/A**.
160
161### 8) Invoke `$close-the-loop` (required)
162`$close-the-loop` is the forcing function: record at least one signal after you’ve made the change and run validations.
163
164### 9) Close the worked bead (required)
165Before creating the PR:
166- Mark the worked bead as `done`.
167
168Note: this typically updates bead state files (e.g. `issues.jsonl`). Those changes are part of the workflow and must be included in the PR.
169
170### 10) Open a PR (do not merge yet)
171- Open a single PR.
172- Do not merge yet.
173
174### 11) Immediate TRACE self-review (required, post-PR)
175Review the PR output immediately and resolve findings.
176
177Rules:
178- Findings must be in severity order.
179- Include `file:line` references.
180- Include violated TRACE letters.
181- Resolve all 🔥 + 🟡 items (no deferrals).
182
183If fixes are required:
184- Apply smallest sound fixes.
185- Re-run validations (Step 7).
186- Re-invoke `$close-the-loop` (Step 8).
187- Repeat review until no 🔥 or 🟡 remain.
188
189### 12) Select the next bead (required, post-review)
190Run the `$select` workflow once to choose exactly one next bead.
191
192Intent:
193- Pick the next `bd ready` bead via risk-first heuristics.
194- Verify dependency/readiness.
195- Add missing deps and restart selection when needed.
196- Mark the chosen bead `in_progress` and leave a short rationale comment.
197
198Critical requirement:
199- The bead state changes produced here (commonly `issues.jsonl` updates) must be committed and included in the current PR.
200
201### 13) CL: update PR → check CI + mergeability → squash → cleanup
202Follow `codex/prompts/CL.md`, with a billing-only CI bypass:
203
2041. Update the PR.
2052. Confirm the PR is squash-mergeable (no merge conflict). If conflicting, merge/rebase the base branch and resolve conflicts.
2063. Check CI status (e.g., `gh pr checks`).
2074. If CI is green: squash-merge.
2085. If CI is not green:
209 - If CI failure text contains `billing`: run `zig build ci` (again, immediately before merge). If it passes and the PR is squash-mergeable, squash-merge.
210 - Otherwise: keep fixes minimal, and iterate until CI is green.
2116. Cleanup local state.
212
213CI policy:
214- Default: treat non-`billing` CI failures as real (fix → re-run validations + `$close-the-loop`).
215- Bypass: only skip “wait for green” when CI failure text contains `billing`.
216
217### 14) Record proof (make results auditable)
218Record proof in both places:
219- PR description: full command list + outcomes.
220- Bead comment: short proof summary + PR link.
221
222Proof should include:
223- Signals: commands run and outcomes.
224- Decision: if CPS was used, record tier + rationale + escape hatch.
225- Notes: any N/A validations, known limitations.
226
227## Deliverable format (chat)
228
229### A) Work summary
230- Bead: `<id>` + 1-sentence “done means”.
231- Change summary: what and why.
232
233### B) TRACE self-review (severity order)
234For each finding:
235- `file:line` — issue — violated TRACE letters — fix applied.
236
237### C) Proof
238- Format: `<cmd>` → `<ok/fail>`
239- Lint/typecheck: `<cmd>` → `<ok/fail>`
240- Build: `<cmd>` → `<ok/fail>`
241- Tests: `<cmd>` → `<ok/fail>`
242- CI substitute (if `billing`): `zig build ci` (pre-PR; pre-merge if needed) → `<ok/fail>`
243- `$close-the-loop`: `<signal>`
244- PR: `<url>`
245- Merge: `<squash ok/fail>`
246- Bead comment: `<posted/blocked>`
247
248## Failure paths
249- No in-progress bead: invoke `$select`, mark chosen bead in progress, then proceed.
250- Unclear requirements: stop and ask; do not guess.
251- Unrelated diffs: ignore; don't touch or stage; continue. If the requested change would touch the same lines/hunks, stop and ask.
252- Validation fails: fix and re-run before opening the PR.
253- CI is not green:
254 - If CI failure text contains `billing`, run `zig build ci` and treat “squash-mergeable + `zig build ci` ok” as green.
255 - Otherwise, keep fixing until CI is green.
256- PR is not squash-mergeable (merge conflict): merge/rebase the base branch, resolve conflicts, then re-run validations (Step 7) and retry merge.
257- Bug can’t be reproduced: add instrumentation or a characterization test; clearly state limits in proof.
258
259## Activation cues
260- "imp"
261- "ship this bead"
262- "implement then review"
263- "PR-ready with proof"