Skip to content

Commit 3fbcd2c

Browse files
authored
Merge pull request #4206 from BrighterCommand/bug_flow
docs: add lightweight /bugfix workflow (#4204)
2 parents b142ad8 + 0ee406a commit 3fbcd2c

11 files changed

Lines changed: 814 additions & 18 deletions

File tree

.agent_instructions/skills_overview.md

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@ Skills are slash commands that automate multi-step workflows and enforce Brighte
1515
| `/test-first` | TDD with mandatory approval | `/test-first <behavior description>` |
1616
| `/tidy-first` | Separate refactoring from features | `/tidy-first <change description>` |
1717
| `/adr` | Create Architecture Decision Record | `/adr <title>` |
18+
| `/bugfix:*` | Diagnosis-first bug workflow (Confirm gate) | `/bugfix:triage [issue \| description]` |
19+
20+
### Bugfix Workflow Skills
21+
22+
| Skill | Purpose | Usage |
23+
|-------|---------|-------|
24+
| `/bugfix:triage` | Restate symptom, locate code, form hypothesis | `/bugfix:triage [issue-number \| description]` |
25+
| `/bugfix:confirm` | ✋ Prove the root cause before any fix | `/bugfix:confirm` |
26+
| `/bugfix:test` | Failing regression test (via `/test-first`) | `/bugfix:test` |
27+
| `/bugfix:fix` | Minimal fix scoped to the confirmed cause | `/bugfix:fix` |
28+
| `/bugfix:verify` | Run suite; capture root cause + `Fixes #N` | `/bugfix:verify` |
29+
| `/bugfix:status` | Show all bugs and their phase | `/bugfix:status` |
30+
| `/bugfix:switch` | Switch the active bug | `/bugfix:switch <NNNN-slug>` |
1831

1932
### Specification Workflow Skills
2033

@@ -39,6 +52,12 @@ Skills are slash commands that automate multi-step workflows and enforce Brighte
3952
│ Quick Reference │
4053
└────────────────────────────────────────────────────────────────┘
4154
55+
🐞 BUGFIX (DIAGNOSIS-FIRST)
56+
/bugfix:triage → :confirm → :test → :fix → :verify
57+
• Triage → ✋Confirm gate → Test-first → Fix → Verify
58+
• Proves the root cause BEFORE writing a fix
59+
• Example: /bugfix:triage 4054
60+
4261
🧪 TEST-DRIVEN DEVELOPMENT
4362
/test-first <behavior>
4463
• Write test → Approve → Implement → Refactor
@@ -74,24 +93,28 @@ Skills are slash commands that automate multi-step workflows and enforce Brighte
7493
## Decision Tree: Which Skill Should I Use?
7594

7695
```
77-
Need to document decision?
96+
Need to document a decision?
7897
79-
┌─────────┴─────────┐
80-
YES NO
81-
│ │
82-
/adr ↓
83-
Adding behavior?
84-
85-
┌──────────┴──────────┐
86-
YES NO
87-
│ │
88-
↓ ↓
89-
Code needs cleanup? Just refactoring?
90-
│ │
91-
┌───────┴───────┐ │
92-
YES NO │
93-
│ │ │
94-
/tidy-first /test-first /tidy-first
98+
┌───────────┴───────────┐
99+
YES NO
100+
│ │
101+
/adr Fixing a bug?
102+
103+
┌────────────────┴────────────────┐
104+
YES NO
105+
│ │
106+
Root cause proven? Adding behavior?
107+
│ │
108+
┌─────────┴─────────┐ ┌─────────┴─────────┐
109+
NO YES YES NO
110+
│ │ │ │
111+
/bugfix:triage /test-first Code needs Just refactoring
112+
(Confirm gate) cleanup? → /tidy-first
113+
114+
┌─────────┴─────────┐
115+
YES NO
116+
│ │
117+
/tidy-first /test-first
95118
```
96119

97120
## Enforcement of Brighter Practices
@@ -134,6 +157,25 @@ Each skill enforces specific practices from `.agent_instructions/`:
134157

135158
## Common Workflows
136159

160+
### Workflow 0: Fix a Bug (Diagnosis-First)
161+
162+
```bash
163+
# 1. Triage — restate symptom, locate code, form hypothesis (suggested fix is UNVERIFIED)
164+
/bugfix:triage 4054
165+
166+
# 2. ✋ Confirm — prove the root cause BEFORE any fix (may widen the scope)
167+
/bugfix:confirm
168+
169+
# 3. ✋ Test-first — failing regression test (delegates to /test-first)
170+
/bugfix:test
171+
172+
# 4. Fix — minimal change to green, scoped to the confirmed cause
173+
/bugfix:fix
174+
175+
# 5. Verify — run the suite; commit captures root cause + Fixes #4054
176+
/bugfix:verify
177+
```
178+
137179
### Workflow 1: Add New Feature (Clean Code)
138180

139181
```bash

.claude/commands/README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,45 @@ Skills are invoked using slash commands in Claude Code:
111111

112112
---
113113

114+
### 4. Bugfix - Diagnosis-First Bug Workflow
115+
116+
**Commands**: `/bugfix:triage`, `/bugfix:confirm`, `/bugfix:test`, `/bugfix:fix`, `/bugfix:verify` (plus `/bugfix:status`, `/bugfix:switch`)
117+
118+
**Purpose**: A lightweight, diagnosis-first workflow for fixing bugs. It is `/test-first` wrapped with an explicit **Confirm** gate up front — because a bug's root cause is a hypothesis until proven.
119+
120+
**When to use**:
121+
- A defect whose root cause is not yet proven
122+
- An issue that arrived with a suggested fix (including agent-authored) you should verify before trusting
123+
- Anywhere `/test-first` alone would jump to a test for an *assumed* cause
124+
125+
**Workflow**:
126+
1. **Triage** (`/bugfix:triage [issue|description]`) - Restate the symptom, locate the code, form a root-cause hypothesis (any suggested fix is UNVERIFIED)
127+
2.**Confirm** (`/bugfix:confirm`) - Prove the hypothesis by code-trace and/or red repro before any fix; surfaces scope changes / extra defects
128+
3.**Test-first** (`/bugfix:test`) - Delegates to `/test-first` for the failing regression test
129+
4. **Fix** (`/bugfix:fix`) - Minimal change to green, scoped to the confirmed cause
130+
5. **Verify** (`/bugfix:verify`) - Run the suite; capture the root cause and `Fixes #N` in the commit/PR
131+
132+
**Example**:
133+
```bash
134+
/bugfix:triage 4054 # ASB SessionId case-sensitivity
135+
/bugfix:confirm # proves CamelCase round-trip cause; finds a 2nd defect
136+
/bugfix:test # red regression test (via /test-first)
137+
/bugfix:fix # minimal fix scoped to the confirmed cause
138+
/bugfix:verify # suite green; fix: commit with Fixes #4054
139+
```
140+
141+
**Why it matters**: The Confirm gate stops you fixing a symptom or trusting a wrong suggested fix — and frequently changes the scope of the fix. It deliberately omits the ADR/requirements/review rounds that `/spec` mandates.
142+
143+
📖 **Documentation**: [.claude/commands/bugfix/README.md](bugfix/README.md)
144+
145+
---
146+
114147
## Skill Categories
115148

116149
### Development Workflow Skills
117150
- **`/test-first`** - TDD with approval gate
118151
- **`/tidy-first`** - Safe refactoring workflow
152+
- **`/bugfix:*`** - Diagnosis-first bug workflow (Triage → Confirm → Test-first → Fix → Verify)
119153

120154
### Documentation Skills
121155
- **`/adr`** - Architecture Decision Records
@@ -142,7 +176,14 @@ Do you need to document an architectural decision?
142176
├─ Yes → /adr <title>
143177
└─ No ↓
144178
145-
Are you adding new behavior or fixing a bug?
179+
Are you fixing a bug?
180+
├─ Yes ↓
181+
│ └─ Is the root cause already proven/obvious?
182+
│ ├─ No → /bugfix:triage (Triage → Confirm gate → Test-first → Fix → Verify)
183+
│ └─ Yes → /test-first <behavior> (cause is clear; just need the test)
184+
└─ No ↓
185+
186+
Are you adding new behavior?
146187
├─ Yes ↓
147188
│ └─ Does existing code need refactoring first?
148189
│ ├─ Yes → /tidy-first <description>
@@ -401,6 +442,7 @@ Three new skills enforce Brighter's mandatory engineering practices:
401442
| `/test-first` | TDD with approval | Tests → Implementation → Refactoring |
402443
| `/adr` | Documented decisions | Numbered ADR files |
403444
| `/tidy-first` | Structural/behavioral separation | Two commits: refactor + feat |
445+
| `/bugfix:*` | Confirm root cause before fixing | Bug record + regression test + scoped `fix:` commit |
404446

405447
**Key insight**: These skills make the **correct approach the easy path** by automating multi-step workflows and enforcing approval gates.
406448

.claude/commands/bugfix/README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Bugfix Workflow Commands
2+
3+
This directory contains Claude Code commands that implement a **lightweight, diagnosis-first
4+
workflow for fixing bugs**. It is the bug-shaped counterpart to the heavyweight `/spec:*`
5+
workflow: where `/spec` runs Requirements → ADR → adversarial review → tasks → implement (right
6+
for *features*), `/bugfix` runs **Triage → Confirm → Test-first → Fix → Verify** and deliberately
7+
omits the ADR/requirements/review rounds.
8+
9+
## Why a separate workflow?
10+
11+
Bugs differ from features in one important way: **the root cause is a hypothesis until proven.**
12+
Issues often arrive with a suggested fix (sometimes from an automated agent), but a suggested fix
13+
can be wrong, incomplete, or address a *symptom* rather than the cause. `/test-first` jumps
14+
straight to writing a test for an *assumed* behaviour — it has no gate for *confirming the
15+
diagnosis first*.
16+
17+
`/bugfix` is essentially `/test-first` wrapped with an explicit **Confirm** gate up front, plus a
18+
triage step that records the hypothesis.
19+
20+
**Worked example — #4054 (ASB `SessionId` case-sensitivity).** The issue arrived with a plausible
21+
suggested fix. Before writing any code, Confirm proved the root cause by reading
22+
`JsonSerialisationOptions` (`PropertyNamingPolicy = JsonNamingPolicy.CamelCase`) — keys are
23+
camelCased on serialization round-trips — and surfaced a *second* defect the suggested fix only
24+
partially addressed (reserved-header stripping is also case-sensitive, so reserved keys leak into
25+
`ApplicationProperties`). Confirming the theory **changed the scope of the fix.** That is exactly
26+
what the Confirm gate exists to catch.
27+
28+
## Workflow
29+
30+
```
31+
┌─────────────────────────────────────────────────────────────────┐
32+
│ Bugfix Workflow │
33+
└─────────────────────────────────────────────────────────────────┘
34+
35+
GitHub Issue / bug report
36+
37+
38+
Triage ──────────────► /bugfix:triage [issue-number | description]
39+
│ (restate symptom, locate code, form hypothesis;
40+
│ any suggested fix is UNVERIFIED)
41+
42+
Confirm ─────────────► /bugfix:confirm
43+
│ ✋ Confirm gate — prove the hypothesis (code-trace
44+
│ and/or red repro) before any fix; .confirm-approved
45+
│ (refuted → back to triage)
46+
47+
Test-first ──────────► /bugfix:test
48+
│ ✋ delegates to /test-first (approve test in IDE)
49+
50+
Fix ─────────────────► /bugfix:fix
51+
│ (minimal change to green, scoped to confirmed cause;
52+
│ /tidy-first if structural cleanup needed first)
53+
54+
Verify ──────────────► /bugfix:verify
55+
│ (run suite; regression test stays; capture root cause,
56+
│ Fixes #N — no auto-close)
57+
58+
Pull Request
59+
```
60+
61+
## The two gates
62+
63+
| Gate | Where | What it guarantees |
64+
|------|-------|--------------------|
65+
|**Confirm** | `/bugfix:confirm` | The root-cause diagnosis is **proven**, not assumed, and the fix's scope (including any extra defects) is agreed before code is written. The one on-disk marker: `.confirm-approved`. |
66+
|**Test approval** | `/bugfix:test``/test-first` | The failing regression test is reviewed in the IDE before any implementation (inherited from `/test-first`). |
67+
68+
### Confirm evidence standard — red repro preferred, code-trace allowed
69+
70+
Confirm passes on **either**:
71+
- an executable **red reproduction** (preferred when the bug reproduces cheaply — pure logic, no
72+
live infra), **or**
73+
- a documented **code-trace** that proves the cause (the accepted path when a repro would need a
74+
real broker/database/etc., as in #4054).
75+
76+
The durable, executable regression test is written later by `/bugfix:test` (via `/test-first`) —
77+
Confirm itself stays read-only and writes no source.
78+
79+
## Sub-agents & model policy
80+
81+
Modelled on `/spec` (see `.claude/commands/spec/README.md` → "Sub-agents & model policy"):
82+
reasoning-heavy, read-only steps delegate to a **`Plan`** sub-agent (no file-editing tool, no
83+
`AskUserQuestion`) which RETURNS its findings as text; the **main agent** owns all user
84+
interaction (the Confirm gate) and all bookkeeping (writing `bugfix.md`, markers, `gh`, git).
85+
86+
| Command | Sub-agent (type) | Model | Rationale |
87+
|---------|------------------|-------|-----------|
88+
| `/bugfix:triage` | Yes — `Plan` (read-only) | **opus** | Diagnostic analysis / locating code |
89+
| `/bugfix:confirm` | Yes — `Plan` (read-only) | **opus** | Adversarial root-cause proof |
90+
| `/bugfix:test` | No — delegates to `/test-first` | **sonnet** | Implementation (interactive approval gate) |
91+
| `/bugfix:fix` | No (main agent) | **sonnet** | Implementation work |
92+
| `/bugfix:verify` | No (main agent) || Mechanical: run suite, prepare commit/PR |
93+
| `/bugfix:status`, `/bugfix:switch` | No || Bookkeeping |
94+
95+
`triage` and `confirm` use `Plan` so the "return as text, don't write the file" rule is hard to
96+
violate accidentally (no `Write`/`Edit`). `test`/`fix` run in the **main agent** because the
97+
test-approval gate is interactive and the fix writes source — set the session model to **sonnet**
98+
for those, matching the implementation policy.
99+
100+
## State model (lightweight — single record + one marker)
101+
102+
```
103+
bugfixes/
104+
├── .current-bug # tracks the active bug (like specs/.current-spec)
105+
└── 0001-asb-sessionid-case/
106+
├── .issue-number # linked GitHub issue (optional)
107+
├── .confirm-approved # the ONE gate marker
108+
└── bugfix.md # symptom / hypothesis / root cause / evidence / fix
109+
```
110+
111+
Unlike `/spec` (three approval markers), `/bugfix` has a **single** marker (`.confirm-approved`).
112+
Every other phase is inferred from the content of `bugfix.md`, keeping the workflow light.
113+
114+
### `bugfix.md` sections (filled progressively)
115+
116+
| Section | Filled by |
117+
|---------|-----------|
118+
| Symptom, Suspected Location, Root-Cause Hypothesis | `/bugfix:triage` |
119+
| Confirmed Root Cause, Evidence, Scope Notes | `/bugfix:confirm` |
120+
| Regression Test | `/bugfix:test` |
121+
| Fix | `/bugfix:fix` |
122+
| Status (Triaged → Confirmed → Tested → Fixed → Verified) | each step |
123+
124+
## Commands
125+
126+
### `/bugfix:triage [issue-number | description]`
127+
Start a bug. Sets up `bugfixes/NNNN-slug/` and `.current-bug`, pulls the issue via `gh`, and (via
128+
a `Plan` sub-agent) restates the symptom, locates the suspect code, and forms a root-cause
129+
hypothesis. Any suggested fix is recorded as **UNVERIFIED**. Offers a `bugfix/N-slug` branch.
130+
131+
### `/bugfix:confirm`
132+
The ✋ Confirm gate. A `Plan` sub-agent proves or refutes the hypothesis by tracing the code
133+
(and/or describing a red repro), citing `file:line` evidence, and hunts for scope changes /
134+
additional defects. The main agent writes the findings into `bugfix.md` and asks the user to
135+
approve the diagnosis; on approval it creates `.confirm-approved`. A refuted hypothesis loops back
136+
to triage.
137+
138+
### `/bugfix:test`
139+
Requires `.confirm-approved`. Delegates to `/test-first` to write the failing regression test for
140+
the confirmed behaviour (and one per additional defect in the Scope Notes). The `/test-first`
141+
IDE-approval gate applies.
142+
143+
### `/bugfix:fix`
144+
Requires `.confirm-approved` + a red test. Makes the test green with the **minimal** change scoped
145+
to the confirmed cause — no speculative edits, no default changes. If structural cleanup is needed
146+
first, defers to `/tidy-first` (separate `refactor:` commit, then the `fix:` commit).
147+
148+
### `/bugfix:verify`
149+
Runs the regression test(s) and the broader suite; the regression test stays. Suggests a `fix:`
150+
commit and PR body that capture the confirmed root cause and link the issue with `Fixes #N`
151+
without closing the issue directly (merge closes it).
152+
153+
### `/bugfix:status`
154+
Lists all bugs and derives each phase from `bugfix.md` + `.confirm-approved`.
155+
156+
### `/bugfix:switch <bug-slug>`
157+
Switches the active bug (updates `bugfixes/.current-bug`).
158+
159+
## When to use `/bugfix` vs other workflows
160+
161+
- **`/bugfix`** — a defect whose root cause is not yet proven, or that arrived with a suggested fix
162+
you should verify before trusting. The Confirm gate is the value-add.
163+
- **`/test-first`** — a small change whose behaviour/cause is already obvious; you just need the
164+
test-first discipline.
165+
- **`/tidy-first`** — the change is (or includes) structural cleanup; keep refactor and behaviour
166+
in separate commits. `/bugfix:fix` calls this when a fix needs cleanup first.
167+
- **`/spec:*`** — a *feature* or capability needing requirements + ADR design, not a bug fix.
168+
169+
## Related Commands
170+
- **`/test-first`**`.claude/commands/tdd/test-first.md` (the test step delegates here)
171+
- **`/tidy-first`**`.claude/commands/refactor/tidy-first.md` (the fix step defers here when needed)
172+
- **`/spec:*`**`.claude/commands/spec/README.md` (the heavyweight feature workflow this mirrors)

0 commit comments

Comments
 (0)