Skip to content

Commit a47ada3

Browse files
committed
chore(workflow): fix principle priority order and add post-mortem workflow hardening
- Fix YAGNI > KISS > DRY > SOLID > ObjCal > patterns order across all 8 files (developer.md, reviewer.md, implementation/SKILL.md, session-workflow/SKILL.md, verify/SKILL.md, AGENTS.md) - Add gen_todo.py merge-write script for TODO.md structural enforcement - Rewrite session-workflow, implementation, tdd, verify skills v2.1 with mandatory Cycle State, WIP check, prereq check, STOP/WAIT language, gen-tests --check - Add D6 global @id duplicate detection (WARNING + continue) to gen_test_stubs.py - Add gen-todo task to pyproject.toml
1 parent 302c57a commit a47ada3

File tree

10 files changed

+538
-54
lines changed

10 files changed

+538
-54
lines changed

.opencode/agents/developer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Load `skill implementation` (which includes Step 2 instructions).
4545
```
4646
2. Read both `docs/features/discovery.md` (project-level) and `docs/features/in-progress/<name>/discovery.md`
4747
3. Read all `.feature` files — understand every `@id` and its Examples
48-
4. Run a silent pre-mortem: design patterns, SOLID, DRY, KISS, Object Calisthenics
48+
4. Run a silent pre-mortem: YAGNI, KISS, DRY, SOLID, Object Calisthenics, design patterns
4949
5. Add `## Architecture` section to `docs/features/in-progress/<name>/discovery.md`
5050
6. **Architecture contradiction check**: compare each ADR against each AC. If any ADR contradicts an AC, resolve with PO before proceeding.
5151
7. If a user story is not technically feasible, escalate to the PO.

.opencode/agents/reviewer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Load `skill verify`. Run all commands, check all criteria, produce a written rep
5151
### Per-test review during Step 4
5252
When the developer requests a review after making a test green, check:
5353
- Does the implementation satisfy the `@id`'s Example (Given/When/Then)?
54-
- Does the code follow SOLID, DRY, KISS, Object Calisthenics?
54+
- Does the code follow YAGNI > KISS > DRY > SOLID > Object Calisthenics (in priority order)?
5555
- Would the test survive a full internal rewrite?
5656

5757
## Zero-Tolerance Rules

.opencode/skills/implementation/SKILL.md

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: implementation
33
description: Step 4 — Red-Green-Refactor cycle, one test at a time, with commit per green test
4-
version: "2.0"
4+
version: "2.1"
55
author: developer
66
audience: developer
77
workflow: feature-lifecycle
@@ -15,7 +15,7 @@ Make the failing tests pass one at a time. Each green test gets its own commit a
1515

1616
During Step 4, correctness priorities are (in order):
1717

18-
1. **Design correctness** — YAGNI, KISS, DRY, SOLID, Object Calisthenics, appropriate design patterns
18+
1. **Design correctness** — YAGNI > KISS > DRY > SOLID > Object Calisthenics > appropriate design patterns
1919
2. **One test green** — the specific test under work passes, plus `test-fast` still passes
2020
3. **Reviewer code-design check** — reviewer verifies design + semantic alignment (no lint/pyright/coverage)
2121
4. **Commit** — only after reviewer APPROVED
@@ -34,24 +34,33 @@ Pick one failing test
3434
→ REVIEWER CHECK: reviewer verifies code design + semantic alignment
3535
─── WAIT for APPROVED ───
3636
→ COMMIT (only after reviewer APPROVED)
37+
→ Update TODO.md: mark @id [x], update Cycle State to next test
3738
→ pick next failing test
3839
```
3940

4041
**Hard gates**: The cycle has two hard gates — you must STOP before the reviewer check, and WAIT for APPROVED before committing. Never batch multiple tests before a reviewer interaction. Never commit without reviewer approval.
4142

4243
Never write production code before picking a specific failing test. Never refactor while tests are red.
4344

45+
**TODO.md Cycle State is mandatory.** Update `## Cycle State` at every phase transition (RED → GREEN → REFACTOR → REVIEWER → COMMITTED). If the Cycle State block is missing, add it before proceeding.
46+
4447
## Step 2 — Architecture (do this first)
4548

46-
Before writing any production code, add `## Architecture` to `docs/features/in-progress/<name>/discovery.md`:
49+
**Prerequisites — verify before starting:**
50+
1. `docs/features/in-progress/` contains only `.gitkeep` (no feature folders). If another feature folder exists, **STOP** — another feature is already in progress.
51+
2. The feature's `discovery.md` has `Status: BASELINED`. If not, escalate to the PO — Step 1 is incomplete.
52+
3. At least one `.feature` file in the feature folder contains `Example:` blocks with `@id` tags. If not, escalate to PO — criteria have not been written.
53+
54+
**Steps:**
4755

4856
1. Move the feature folder from `backlog/` to `in-progress/`:
4957
```bash
5058
mv docs/features/backlog/<name>/ docs/features/in-progress/<name>/
5159
```
52-
2. Read both `docs/features/discovery.md` (project-level) and the feature's `discovery.md`
53-
3. Run a silent pre-mortem: design patterns, SOLID, DRY, KISS, Object Calisthenics
54-
4. Add the Architecture section:
60+
2. Update `TODO.md` Source path from `backlog/` to `in-progress/`.
61+
3. Read both `docs/features/discovery.md` (project-level) and the feature's `discovery.md`
62+
4. Run a silent pre-mortem: YAGNI, KISS, DRY, SOLID, Object Calisthenics, design patterns
63+
5. Add the Architecture section to `docs/features/in-progress/<name>/discovery.md`:
5564

5665
```markdown
5766
## Architecture
@@ -70,12 +79,15 @@ Alternatives considered: <what was rejected and why>
7079
- New runtime dependency: <name> — reason: <why>
7180
```
7281

73-
5. **Architecture contradiction check**: Compare each ADR against each AC. If any architectural decision contradicts or circumvents an acceptance criterion, flag it and resolve with the PO before writing any production code.
74-
6. If a user story is not technically feasible, escalate to the PO.
75-
7. If any build changes need PO approval, stop and ask before proceeding.
82+
6. **Architecture contradiction check**: Compare each ADR against each AC. If any architectural decision contradicts or circumvents an acceptance criterion, flag it and resolve with the PO before writing any production code.
83+
7. **PO domain acknowledgement**: Share the Architecture section with the PO for domain model acknowledgement before Step 3 begins. A one-line response ("no contradictions") is sufficient.
84+
8. If a user story is not technically feasible, escalate to the PO.
85+
9. If any build changes need PO approval, stop and ask before proceeding.
7686

7787
Commit: `feat(<feature-name>): add architecture`
7888

89+
**After committing:** Run `uv run task gen-tests -- --check` to verify stub sync. If changes are shown, run `uv run task gen-tests` to apply them.
90+
7991
## Implementation Order
8092

8193
1. Start with the simplest test: data classes, value objects, pure functions
@@ -90,6 +102,12 @@ uv run pytest tests/features/<name>/<story>_test.py::test_<func> -v
90102

91103
Expected: `FAILED` or `ERROR`. If it passes before you've written code, the test is wrong — fix it.
92104

105+
Update `## Cycle State` in TODO.md:
106+
```
107+
Test: `@id:<hex>` — <description>
108+
Phase: RED
109+
```
110+
93111
## GREEN — Minimum Implementation
94112

95113
Write the least code that makes **this one test** pass. "Green" means the specific test under work passes — not the full suite.
@@ -105,6 +123,8 @@ uv run pytest tests/features/<name>/<story>_test.py::test_<func> -v # this tes
105123
uv run task test-fast # no regressions
106124
```
107125

126+
Update `## Cycle State` Phase: `GREEN`
127+
108128
## REFACTOR — Apply Principles (in priority order)
109129

110130
1. **DRY**: extract duplication
@@ -146,6 +166,14 @@ Use when a pattern solves a structural problem you already have:
146166
| External dependency (I/O, DB, network) | Repository/Adapter pattern | Enables testing via Protocol |
147167
| Event-driven flow | Observer or pub/sub | Decouples producers from consumers |
148168

169+
### Doctest Check
170+
171+
If you added or modified a `Examples:` block in a Google-style docstring, verify it passes:
172+
173+
```bash
174+
uv run pytest --doctest-modules <module_path>
175+
```
176+
149177
> **Note**: `uv run task test` runs `--doctest-modules`. Keep `Examples:` blocks in Google-style docstrings valid and executable.
150178
151179
```bash
@@ -154,12 +182,19 @@ uv run task test-fast # must still pass — the ONLY check during refactor
154182

155183
Do NOT run `uv run task lint` or `uv run task static-check` during the cycle. Those are handoff-only checks (before Step 5).
156184

185+
Update `## Cycle State` Phase: `REFACTOR`
186+
157187
## REVIEWER CHECK — Code Design Only
158188

159-
After each test goes green + refactor, **STOP** and request a reviewer check. The reviewer loads the `verify` skill but is scoped to **code design only**:
189+
After each test goes green + refactor, **STOP** and request a reviewer check.
190+
191+
**STOP — request a reviewer check of code design and semantic alignment.**
192+
**WAIT for APPROVED before committing.**
193+
194+
The reviewer is scoped to **code design only** (not full Step 5):
160195

161196
**What the reviewer checks (code-design scope)**:
162-
- **YAGNI, KISS, DRY, SOLID, Object Calisthenics** — are design principles followed in priority order?
197+
- **YAGNI > KISS > DRY > SOLID > Object Calisthenics** — are design principles followed in priority order?
163198
- **Appropriate design patterns** — is the code structure right for the problem?
164199
- **Semantic alignment** — does the test operate at the same abstraction level as the AC?
165200
- **No internal-state testing** — assertions on observable behavior, not private attributes
@@ -170,7 +205,26 @@ After each test goes green + refactor, **STOP** and request a reviewer check. Th
170205
- Coverage metrics
171206
- Full test suite
172207

173-
The reviewer responds with **APPROVED** or **REJECTED** with specific issues. If REJECTED, fix the issues and request review again. This is a **hard gate** — do not commit until APPROVED.
208+
The reviewer responds using this template:
209+
210+
```markdown
211+
## Code-Design Check — @id:<hex>
212+
213+
Design principles: PASS/FAIL — <note>
214+
Semantic alignment: PASS/FAIL — <note>
215+
Decision: APPROVED / REJECTED
216+
```
217+
218+
If REJECTED:
219+
- Mark the `@id` row as `[~]` in TODO.md (do not downgrade to `[ ]`)
220+
- Update `## Cycle State` Phase to `REVIEWER(code-design)`
221+
- Fix the specific issues raised
222+
- Do not commit
223+
- Request re-review after fix
224+
225+
This is a **hard gate** — do not commit until APPROVED.
226+
227+
Update `## Cycle State` Phase: `REVIEWER(code-design)`
174228

175229
## COMMIT (after reviewer approval)
176230

@@ -179,6 +233,11 @@ git add -A
179233
git commit -m "feat(<feature-name>): implement <what this test covers>"
180234
```
181235

236+
Update TODO.md:
237+
- Mark the `@id` row `[x]` with ` — reviewer(code-design) APPROVED`
238+
- Update `## Cycle State` Phase to `COMMITTED`
239+
- Update `## Next` to the next failing test
240+
182241
Then move to the next failing test.
183242

184243
## Handling Spec Gaps
@@ -218,16 +277,7 @@ class UserRepository(Protocol):
218277

219278
## Self-Verification Before Handoff
220279

221-
After all tests are green, before telling the reviewer you are ready for full Step 5 review:
222-
223-
```bash
224-
uv run task lint # exit 0
225-
uv run task static-check # exit 0, 0 errors
226-
uv run task test # exit 0, all pass, coverage 100%
227-
timeout 10s uv run task run # exit non-124; exit 124 = hung process = fix it
228-
```
229-
230-
All four must pass. Do not hand off broken work.
280+
After all tests are green, load `skill code-quality` for the full pre-handoff verification procedure.
231281

232282
**Manual verification**: Run the app and verify it does what the AC says, not just what the tests check.
233283

.opencode/skills/session-workflow/SKILL.md

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: session-workflow
33
description: Session start and end protocol — read TODO.md, continue from checkpoint, update and commit
4-
version: "2.0"
4+
version: "2.1"
55
author: developer
66
audience: all-agents
77
workflow: session-management
@@ -13,27 +13,41 @@ Every session starts by reading state. Every session ends by writing state. This
1313

1414
## Session Start
1515

16-
1. Read `TODO.md` — find current feature, current step, and the "Next" line
16+
1. Read `TODO.md` — find current feature, current step, and the "Next" line.
17+
- If `TODO.md` does not exist, run `uv run task gen-todo` to create it, then read the result.
1718
2. If a feature is active, read:
1819
- `docs/features/in-progress/<name>/discovery.md` — feature discovery
1920
- `docs/features/discovery.md` — project-level discovery (for context)
2021
3. Run `git status` — understand what is committed vs. what is not
2122
4. Confirm scope: you are working on exactly one step of one feature
2223

23-
If TODO.md says "No feature in progress", check `docs/features/backlog/` for feature folders. If the backlog is empty, the PO needs to define the next feature.
24+
If TODO.md says "No feature in progress", report to the PO that backlog features are waiting. **The developer never self-selects a feature from the backlog — only the PO picks.**
2425

2526
## Session End
2627

2728
1. Update TODO.md:
2829
- Mark completed criteria `[x]`
2930
- Mark in-progress criteria `[~]`
3031
- Update the "Next" line with one concrete action
31-
2. Commit any uncommitted work (even WIP):
32+
2. Run `uv run task gen-todo` to sync any new @id rows from .feature files into TODO.md.
33+
3. Commit any uncommitted work (even WIP):
3234
```bash
3335
git add -A
3436
git commit -m "WIP(<feature-name>): <what was done>"
3537
```
36-
3. If a step is fully complete, use the proper commit message instead of WIP.
38+
4. If a step is fully complete, use the proper commit message instead of WIP.
39+
40+
## Step Completion Protocol
41+
42+
When a step completes within a session:
43+
44+
1. Update TODO.md to reflect the completed step before doing any other work.
45+
2. Commit the TODO.md update:
46+
```bash
47+
git add TODO.md
48+
git commit -m "chore: complete step <N> for <feature-name>"
49+
```
50+
3. Only then begin the next step (in a new session where possible — see Rule 4).
3751

3852
## TODO.md Format
3953

@@ -45,14 +59,19 @@ Step: <1-6> (<step name>)
4559
Source: docs/features/in-progress/<name>/discovery.md
4660

4761
## Progress
48-
- [x] `<@id:hex>`: <description>
49-
- [~] `<@id:hex>`: <description> ← IN PROGRESS
50-
- [ ] `<@id:hex>`: <description>
62+
- [x] `@id:<hex>`: <description>
63+
- [~] `@id:<hex>`: <description> ← IN PROGRESS
64+
- [ ] `@id:<hex>`: <description>
5165

5266
## Next
5367
<One sentence: exactly what to do in the next session>
5468
```
5569

70+
**Source path by step:**
71+
- Step 1: `Source: docs/features/backlog/<name>/discovery.md`
72+
- Steps 2–5: `Source: docs/features/in-progress/<name>/discovery.md`
73+
- Step 6: `Source: docs/features/completed/<name>/discovery.md`
74+
5675
Status markers:
5776
- `[ ]` — not started
5877
- `[~]` — in progress
@@ -69,7 +88,7 @@ Next: PO picks feature from docs/features/backlog/ and moves it to docs/features
6988

7089
## Step 4 Cycle-Aware TODO Format
7190

72-
During Step 4 (Implementation), the TODO.md format includes cycle state to track Red-Green-Refactor-Review progress:
91+
During Step 4 (Implementation), TODO.md **must** include a `## Cycle State` block to track Red-Green-Refactor-Review progress. This block is **mandatory** — missing it means the cycle is unverifiable.
7392

7493
```markdown
7594
# Current Work
@@ -79,14 +98,13 @@ Step: 4 (implement)
7998
Source: docs/features/in-progress/<name>/discovery.md
8099

81100
## Cycle State
82-
Test: `<@id:hex>` — <description>
101+
Test: `@id:<hex>` — <description>
83102
Phase: RED | GREEN | REFACTOR | REVIEWER(code-design) | COMMITTED
84103

85104
## Progress
86-
- [x] `<@id:hex>`: <description> ← done
87-
- [x] `<@id:hex>`: <description> — reviewer(code-design) APPROVED
88-
- [~] `<@id:hex>`: <description> ← in progress (see Cycle State)
89-
- [ ] `<@id:hex>`: <description> ← next
105+
- [x] `@id:<hex>`: <description> — reviewer(code-design) APPROVED
106+
- [~] `@id:<hex>`: <description> ← in progress (see Cycle State)
107+
- [ ] `@id:<hex>`: <description> ← next
90108

91109
## Next
92110
<One actionable sentence>
@@ -95,9 +113,26 @@ Phase: RED | GREEN | REFACTOR | REVIEWER(code-design) | COMMITTED
95113
### Reviewer Scope Legend
96114

97115
When referencing reviewer interactions in TODO.md:
98-
- `reviewer(code-design)` — per-test design check during Step 4 (SOLID/DRY/KISS/ObjCal/patterns + semantic alignment only)
116+
- `reviewer(code-design)` — per-test design check during Step 4 (YAGNI/KISS/DRY/SOLID/ObjCal/patterns + semantic alignment only)
99117
- `reviewer(full-verify)` — Step 5 full verification (lint, pyright, coverage, semantic review, adversarial testing)
100118

119+
## gen-todo Script
120+
121+
`uv run task gen-todo` keeps TODO.md in sync with `.feature` files:
122+
123+
```bash
124+
uv run task gen-todo # merge-write: add missing @id rows, preserve existing status
125+
uv run task gen-todo -- --check # dry run — report what would change
126+
```
127+
128+
**Merge rules:**
129+
- Adds any `@id` rows from in-progress `.feature` files that are missing in `## Progress`
130+
- Never removes or downgrades existing `[x]`, `[~]`, `[-]` rows
131+
- Preserves the `Step:` field and `## Next` line from the current TODO.md
132+
- If no feature is in-progress, writes the "No feature in progress" format
133+
134+
Run `gen-todo` at session start (after reading TODO.md) and at session end (before committing).
135+
101136
## Rules
102137

103138
1. Never skip reading TODO.md at session start
@@ -106,3 +141,4 @@ When referencing reviewer interactions in TODO.md:
106141
4. One step per session where possible; do not start Step N+1 in the same session as Step N
107142
5. The "Next" line must be actionable enough that a fresh AI can execute it without asking questions
108143
6. During Step 4, always update `## Cycle State` when transitioning between RED/GREEN/REFACTOR/REVIEWER phases
144+
7. When a step completes, update TODO.md and commit **before** any further work

0 commit comments

Comments
 (0)