@tianhai/pi-workflow-kit 0.18.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +79 -62
  2. package/agents/pwk-hazard-reviewer.md +24 -0
  3. package/agents/pwk-smell-reviewer.md +17 -0
  4. package/agents/pwk-spec-reviewer.md +14 -0
  5. package/agents/pwk-tracing-reviewer.md +14 -0
  6. package/docs/developer-usage-guide.md +38 -44
  7. package/docs/lessons.md +2 -7
  8. package/docs/oversight-model.md +18 -14
  9. package/docs/workflow-phases.md +52 -29
  10. package/extensions/workflow-guard.ts +190 -92
  11. package/package.json +18 -3
  12. package/skills/pwk-brainstorming/SKILL.md +19 -18
  13. package/skills/pwk-code-review/SKILL.md +46 -0
  14. package/skills/pwk-diagnose/SKILL.md +2 -1
  15. package/skills/pwk-executing-tasks/SKILL.md +102 -328
  16. package/skills/pwk-finalizing/SKILL.md +36 -84
  17. package/skills/pwk-status/SKILL.md +28 -0
  18. package/skills/pwk-writing-plans/SKILL.md +50 -325
  19. package/docs/plans/2026-06-03-karpathy-guidelines-ab-comparison.md +0 -166
  20. package/docs/plans/completed/2026-04-11-checkpoint-review-gates-design.md +0 -50
  21. package/docs/plans/completed/2026-04-11-checkpoint-review-gates-implementation.md +0 -98
  22. package/docs/plans/completed/2026-04-11-finalizing-merge-options-design.md +0 -33
  23. package/docs/plans/completed/2026-04-11-finalizing-merge-options-implementation.md +0 -75
  24. package/docs/plans/completed/2026-04-11-workspace-setup-design.md +0 -28
  25. package/docs/plans/completed/2026-04-11-workspace-setup-implementation.md +0 -57
  26. package/docs/plans/completed/2026-04-15-bash-guard-design.md +0 -39
  27. package/docs/plans/completed/2026-04-15-bash-guard-implementation.md +0 -229
  28. package/docs/plans/completed/2026-04-21-workflow-guard-safe-commands-design.md +0 -172
  29. package/docs/plans/completed/2026-04-21-workflow-guard-safe-commands-implementation.md +0 -168
  30. package/docs/plans/completed/2026-04-22-go-readonly-safe-commands-implementation.md +0 -54
  31. package/docs/plans/completed/2026-04-28-executing-tasks-redesign-design.md +0 -171
  32. package/docs/plans/completed/2026-04-28-executing-tasks-redesign-implementation.md +0 -208
  33. package/docs/plans/completed/2026-04-28-executing-tasks-redesign-progress.md +0 -14
  34. package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-design.md +0 -154
  35. package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-implementation.md +0 -315
  36. package/docs/plans/completed/2026-05-01-incorporate-mattpocock-skills-progress.md +0 -15
  37. package/docs/plans/completed/2026-05-08-checkpoint-gates-design.md +0 -235
  38. package/docs/plans/completed/2026-05-08-checkpoint-gates-implementation.md +0 -83
  39. package/docs/plans/completed/2026-05-08-checkpoint-gates-progress.md +0 -11
  40. package/docs/plans/completed/2026-05-08-lessons-learned-design.md +0 -76
  41. package/docs/plans/completed/2026-05-08-lessons-learned-implementation.md +0 -219
  42. package/docs/plans/completed/2026-05-08-lessons-learned-progress.md +0 -15
  43. package/docs/plans/completed/2026-05-08-migrate-earendil-works-design.md +0 -39
  44. package/docs/plans/completed/2026-05-08-migrate-earendil-works-implementation.md +0 -45
  45. package/docs/plans/completed/2026-05-08-migrate-earendil-works-progress.md +0 -10
  46. package/docs/plans/completed/2026-05-08-worktree-handoff-design.md +0 -118
  47. package/docs/plans/completed/2026-05-08-worktree-handoff-implementation.md +0 -140
  48. package/docs/plans/completed/2026-05-08-worktree-handoff-progress.md +0 -10
  49. package/docs/plans/completed/2026-05-20-generic-lessons-design.md +0 -70
  50. package/docs/plans/completed/2026-05-20-generic-lessons-implementation.md +0 -114
  51. package/docs/plans/completed/2026-05-20-generic-lessons-progress.md +0 -11
  52. package/docs/plans/completed/2026-05-22-agentic-agile-enhancements-design.md +0 -77
  53. package/docs/plans/completed/2026-05-22-agentic-agile-enhancements-implementation.md +0 -473
  54. package/docs/plans/completed/2026-05-25-design-review-split-implementation.md +0 -622
  55. package/docs/plans/completed/2026-05-25-design-review-split-progress.md +0 -16
  56. package/docs/plans/completed/2026-05-25-pr5-improvements-implementation.md +0 -273
  57. package/docs/plans/completed/2026-05-25-pr5-improvements-progress.md +0 -17
  58. package/docs/plans/completed/2026-06-03-add-verify-skill-design.md +0 -51
  59. package/docs/plans/completed/2026-06-03-add-verify-skill-implementation.md +0 -111
  60. package/docs/plans/completed/2026-06-03-add-verify-skill-progress.md +0 -11
  61. package/docs/plans/completed/2026-06-03-verify-skill-design.md +0 -176
  62. package/docs/plans/completed/2026-06-09-code-review-fixes-implementation.md +0 -74
  63. package/docs/plans/completed/2026-06-09-code-review-fixes-progress.md +0 -14
  64. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-design.md +0 -186
  65. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-implementation.md +0 -675
  66. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-progress.md +0 -18
  67. package/docs/plans/completed/2026-06-09-incremental-workflow-and-rename-verification-report.md +0 -81
  68. package/docs/plans/completed/2026-06-09-verification-fixes-implementation.md +0 -69
  69. package/docs/plans/completed/2026-06-09-verification-fixes-progress.md +0 -14
  70. package/skills/pwk-design-review/SKILL.md +0 -115
  71. package/skills/pwk-verify/SKILL.md +0 -170
@@ -0,0 +1,46 @@
1
+ ---
2
+ name: pwk-code-review
3
+ description: "Review a completed requirement's code — trace the logic, check spec alignment against the acceptance criteria, fix code smells, and run a production hazard check. Runs after each requirement in pwk-executing-tasks. Unlocked: may edit code to apply smell fixes."
4
+ ---
5
+
6
+ # Code Review
7
+
8
+ Review the code just implemented for a requirement. **Unlocked** — you may edit code to apply smell fixes; flag everything else as a follow-up.
9
+
10
+ ## Process
11
+
12
+ 1. **Identify the scope** — the requirement just completed (from the progress file / most recent commit). Read its acceptance criteria and integration tests from the plan doc. Run `git log --oneline -5` and `git diff` to see exactly what changed for this requirement.
13
+
14
+ 2. **🔍 Code tracing** — trace the new/changed code paths end-to-end against the integration tests. For each path: does data flow correctly from entry to the asserted outcome? Note any branch the tests don't exercise, any dead branch, any path where the trace breaks.
15
+
16
+ 3. **📐 Spec alignment** — for each acceptance criterion, point to the code and the test that satisfy it. A criterion with no covering code or no test is a **gap**. Code that does more than the criteria specify is **scope creep** — flag it.
17
+
18
+ 4. **🧹 Code smells — fix these directly:**
19
+ - Shallow modules (interface nearly as complex as the implementation)
20
+ - Duplication
21
+ - Missing seams / premature abstraction
22
+ - Poor naming, magic values, dead code
23
+ Apply the fix, re-run the integration tests (must stay green), and commit. If a smell needs a refactor large enough to risk the requirement, **flag** it instead of applying.
24
+
25
+ 5. **⚠️ Production hazard check** — audit the changed code against the high-risk hazards. For each, write `[SAFE]` (1-line justification) or `[TRIGGERED]` (concrete mitigation):
26
+ 1. **Unbounded operations** — multi-key deletions/scans (`KEYS`, raw `SCAN` loops), or full-table loads filtered in memory.
27
+ 2. **Missing indexes** — hot queries on unindexed columns (table scans under load).
28
+ 3. **Unbounded concurrency** — unthrottled fan-out (`Promise.all` without batch limits).
29
+ 4. **Long-running transactions** — holding DB connections/locks across slow external calls.
30
+ 5. **Query/command interpolation** — raw variables merged into SQL or shell (injection).
31
+ 6. **Unrestricted uploads / temp flooding** — uploads to local temp without limits or `finally` cleanup.
32
+ 7. **Silent swallowing loops** — background workers catching and suppressing exceptions without logging/back-off.
33
+ Also check the design's `## Production-risk areas`, if any.
34
+
35
+ 6. **Report** — summarize: tracing findings, spec gaps, smells fixed (with commits), hazards `[TRIGGERED]`. Non-trivial findings become follow-up items — the user decides whether to address now or defer.
36
+ 7. **Mark done** — update the requirement's progress-file row from `🔎 review` to `✅ done`. Done means reviewed, not just committed.
37
+
38
+ ## Principles
39
+
40
+ - **Tracing and spec alignment are the core** — they catch what tests miss: untested branches, missing criteria, scope creep.
41
+ - **Fix smells in place; flag everything else.** Don't redesign.
42
+ - **Be proportional** — a one-function change doesn't need the depth of a batch pipeline.
43
+
44
+ ## After the review
45
+
46
+ Return to `/skill:pwk-executing-tasks` for the next requirement, or `/skill:pwk-finalizing` if all requirements are done.
@@ -53,4 +53,5 @@ Required before declaring done:
53
53
  - Regression test passes (or absence of seam is documented)
54
54
  - All `[DEBUG-...]` instrumentation removed
55
55
  - Ask: what would have prevented this bug?
56
- - If the bug was caused by an architectural problem (no good test seam, tangled callers, hidden coupling), suggest writing an ADR to `docs/plans/adr/` capturing that insight
56
+ - If the answer is a repeatable pattern, append a **generic** rule to `docs/lessons.md` (strip domain specifics) so future sessions catch it early.
57
+ - If the bug was caused by an architectural problem (no good test seam, tangled callers, hidden coupling), suggest writing an ADR to `docs/adr/` capturing that insight
@@ -1,380 +1,154 @@
1
1
  ---
2
2
  name: pwk-executing-tasks
3
- description: "Use this to implement an approved plan task-by-task. Run after pwk-writing-plans, before finalizing."
3
+ description: "Implement a plan requirement-by-requirement with test-first discipline and full autonomy. Run after pwk-writing-plans. Each requirement: write integration tests (red) → checkpoint → implement to green → checkpoint → pwk-code-review."
4
4
  ---
5
5
 
6
6
  # Executing Tasks
7
7
 
8
- Implement the plan from `docs/plans/*-implementation.md` task by task, with file-based progress tracking and session-aware context management.
8
+ Implement the plan from `docs/plans/*-implementation.md` requirement-by-requirement, with file-based progress tracking.
9
+
10
+ The plan is a **behavioral spec** (acceptance criteria + integration tests). You have **full autonomy** to choose structure, signatures, and internals — the acceptance criteria and integration tests define *what*; you decide *how*. Do not ask the plan for implementation steps; it deliberately doesn't contain them.
9
11
 
10
12
  ## Before you start
11
13
 
12
- 1. **Check git state** — run `git status` and `git log --oneline -5`. Note any uncommitted changes.
13
- 2. **Find the plan** — look for `docs/plans/*-design.md` to get the Features table. Find the feature with status `🔄 planned`. The plan doc is `docs/plans/YYYY-MM-DD-<topic>-<slugified-feature-name>-implementation.md`. If no design doc exists, fall back to looking for a single `*-implementation.md` (backward compatibility with plans not using the feature table). This covers plans created without a brainstorm session (no design doc or Features table). If multiple plan docs exist and no design doc, ask the user which one to execute.
14
- 3. **Check for existing progress** — look for `docs/plans/*-progress.md`. If one exists matching the plan, this is a **resume** (see [Resume](#resume)). If not, this is a **first run** (see [First run](#first-run)).
14
+ 1. **Check git state** — `git status` and `git log --oneline -5`. Note uncommitted changes.
15
+ 2. **Find the plan + report** — look for `docs/plans/*-implementation.md`. If several, list them and ask which. Print a one-line discovery report, e.g. `Found: design "auth" execute phase (1/3 requirements done)`. If a matching `*-progress.md` exists, this is a **resume** (see [Resume](#resume)).
16
+ 3. **Workspace isolation should already be done** — `pwk-writing-plans` set up the branch/worktree before handoff. If you land here still on `main`, tell the user the workspace wasn't set up and suggest doing it before executing.
15
17
 
16
18
  ## First run
17
19
 
18
- 1. **Parse the implementation plan** — read the plan and extract all `## Task N:` headings. Build the progress table with all tasks as `⬜ pending`.
19
- 2. **Suggest workspace isolation** — if the user isn't already on a feature branch or worktree, present the options:
20
-
21
- - **Branch** (smaller changes):
22
- ```
23
- git checkout -b <feature-name>
24
- ```
25
- - **Worktree** (larger features, keeps main clean):
26
- ```
27
- git worktree add ../<repo>-<feature-name> -b <feature-name>
28
- ```
29
-
30
- Derive `<feature-name>` from the plan doc (e.g. `docs/plans/2026-04-16-auth-design.md` → `auth`). Ask the user which they prefer, then wait for confirmation before proceeding.
31
-
32
- 3. **If worktree was chosen — hand off to new session:**
33
-
34
- a. Ensure the worktree's `docs/plans/` directory exists:
35
- ```
36
- mkdir -p <worktree>/docs/plans
37
- mkdir -p <worktree>/docs/plans/adr
38
- ```
39
-
40
- b. Move plan docs into the worktree:
41
-
42
- > When using the feature table, all plan docs for this design move together — completed feature plans, the current feature's plan, and the design doc. This is intentional: the worktree works on one design at a time.
43
-
44
- ```
45
- mv docs/plans/*-design.md <worktree>/docs/plans/ 2>/dev/null || true
46
- mv docs/plans/*-implementation.md <worktree>/docs/plans/ 2>/dev/null || true
47
- mv docs/plans/*-progress.md <worktree>/docs/plans/ 2>/dev/null || true
48
- mv docs/plans/adr/*.md <worktree>/docs/plans/adr/ 2>/dev/null || true
49
- ```
50
-
51
- c. Commit the removal on the current branch (if any plan docs were committed):
52
- ```
53
- git rm docs/plans/*-design.md docs/plans/*-implementation.md docs/plans/*-progress.md 2>/dev/null || true
54
- git rm -r docs/plans/adr/ 2>/dev/null || true
55
- git commit -m "chore: move plan docs to worktree for <feature-name>"
56
- ```
57
-
58
- d. Stop and show the user:
59
- ```
60
- ✅ Worktree created at ../<repo>-<feature-name>
61
- 📄 Plan docs moved to the worktree.
62
-
63
- To continue, start a new session there:
64
- cd ../<repo>-<feature-name> && pi
65
-
66
- Then run: /skill:pwk-executing-tasks
67
- ```
68
-
69
- e. **Create the progress file** in the worktree — save to `<worktree>/docs/plans/<plan-name>-progress.md`:
70
-
71
- ```markdown
72
- # Progress: <topic>
73
-
74
- Plan: docs/plans/YYYY-MM-DD-<topic>-implementation.md
75
- Branch: <feature-name>
76
- Started: <ISO timestamp>
77
- Last updated: <ISO timestamp>
78
-
79
- | # | Status | Task | Commit |
80
- |---|--------|------|--------|
81
- | 1 | ⬜ pending | Task description (preserve checkpoint labels) | — |
82
- ```
83
-
84
- This ensures the new session in the worktree will detect the progress file and resume correctly.
85
-
86
- f. **Do not proceed with task execution.** The session ends here.
87
-
88
- 4. **If branch was chosen — continue with execution:**
89
-
90
- a. **Create the progress file** — save to `docs/plans/<plan-name>-progress.md` (replace `-implementation` with `-progress` in the plan filename):
91
-
92
- ```markdown
93
- # Progress: <topic>
20
+ 1. **Parse the plan** — read all `## Requirement N:` headings. Build the progress table with all requirements as `⬜ pending`. Process them in **listed order** — the plan is already in build order; do not reorder.
21
+ 2. **Setup pre-flight** — if the plan has a `## Setup` section, follow it: install dependencies, apply migrations, and seed data. Run the existing test suite to confirm nothing broke. **⏸ CHECKPOINT: setup** — present the migration/output to the human and wait for approval.
22
+ - **approve** → continue.
23
+ - **request changes** revise and re-present.
24
+ (Only runs on the first `First run` — the progress file is created after this step, so a resumed session skips setup.)
25
+ 3. **Create the progress file** at `docs/plans/<plan-name>-progress.md`:
94
26
 
95
- Plan: docs/plans/YYYY-MM-DD-<topic>-implementation.md
96
- Branch: <actual branch name>
97
- Started: <ISO timestamp>
98
- Last updated: <ISO timestamp>
27
+ ```markdown
28
+ # Progress: <topic>
99
29
 
100
- | # | Status | Task | Commit |
101
- |---|--------|------|--------|
102
- | 1 | ⬜ pending | Task description (preserve checkpoint labels) | — |
103
- ```
30
+ Plan: docs/plans/YYYY-MM-DD-<topic>-implementation.md
31
+ Branch: <branch>
32
+ Started: <ISO timestamp>
33
+ Last updated: <ISO timestamp>
104
34
 
105
- Use the actual branch name whether it's the original branch or a new one from the isolation step.
106
-
107
- b. **Commit the plan docs** if `docs/plans/` has uncommitted files, commit them on the new branch:
108
- ```
109
- git add docs/plans/ && git commit -m "docs: add design and implementation plan"
110
- ```
111
-
112
- c. **Begin task execution** — start with task 1 (see [Per-task execution](#per-task-execution)).
35
+ | # | Status | Requirement | Commit |
36
+ |---|--------|-------------|--------|
37
+ | 1 | pending | <requirement name> | |
38
+ ```
39
+ 4. **Commit the plan docs** — `git add docs/plans/ && git commit -m "docs: add implementation plan"`.
40
+ 5. Begin requirement 1 (see [Per-requirement execution](#per-requirement-execution)).
113
41
 
114
42
  ## Resume
115
43
 
116
- 1. **Read the progress file** find the first task with status `⬜ pending`, `❌ failed`, or `🔄 in-progress`.
117
- 2. **Handle in-progress task** if a task is `🔄 in-progress` (mid-task crash):
118
- - Check `git log --oneline` since the last `✅ done` task's commit
119
- - If commits exist: ask the user — "Task N was in progress and commits were made. Continue from here, or reset it to pending?"
120
- - If no commits: restart the task (reset to `🔄 in-progress` and begin)
121
- 3. **Handle failed task** — if a task is `❌ failed`:
122
- - Show the failure reason from the progress file
123
- - Ask: "Retry, skip, or abort?"
124
- 4. **Handle pending task** — proceed normally
125
- 5. **All done** — if no `⬜ pending` or `❌ failed` tasks remain, show summary and suggest `/skill:pwk-finalizing`
126
- 6. **Begin task execution** — proceed from the identified task
44
+ 1. Read the progress file. Find the first requirement that is `⬜ pending`, `🔄 in-progress`, `⏸ tests-review`, or `⏸ complete-review`.
45
+ 2. Resume from the recorded state:
46
+ - `⏸ tests-review` / `⏸ complete-review` re-present that checkpoint and wait.
47
+ - `🔄 in-progress` mid-write continue the requirement.
48
+ - `⬜ pending` start it.
127
49
 
128
50
  ## Progress file
129
51
 
130
- **Path:** `docs/plans/<plan-name>-progress.md`
131
-
132
- **Status values:**
52
+ Path: `docs/plans/<plan-name>-progress.md`. Update the matching row directly (not via pattern matching that could corrupt the table). Update `Last updated` on every change.
133
53
 
134
54
  | Status | Meaning |
135
55
  |--------|---------|
136
56
  | `⬜ pending` | Not started |
137
- | `🔄 in-progress` | Currently executing plan steps |
138
- | `⏸ test-review` | Paused at checkpoint: test, waiting for human approval |
139
- | `⏸ done-review` | Paused at checkpoint: done, waiting for human approval |
140
- | `✅ done` | Committed successfully |
141
- | `❌ failed` | Could not complete (append `Failed: <reason>`) |
57
+ | `🔄 in-progress` | Writing tests or implementing |
58
+ | `⏸ tests-review` | Paused at checkpoint: tests, awaiting human approval |
59
+ | `⏸ complete-review` | Paused at checkpoint: complete, awaiting human approval |
60
+ | `🔎 review` | Committed; `pwk-code-review` in progress |
61
+ | `✅ done` | `pwk-code-review` complete (smells fixed, hazards noted), all green |
62
+ | `❌ failed` | Could not complete; partial work discarded/reverted (append `Failed: <reason>`) |
142
63
  | `⏭ skipped` | User chose to skip |
143
64
 
144
- **Update rules:**
145
- - Mark `🔄 in-progress` immediately when starting a task
146
- - Mark `⏸ test-review` or `⏸ done-review` when the agent reaches a `⏸ CHECKPOINT` gate in the plan — this must happen BEFORE any `git add` or `git commit`
147
- - Can only return to `🔄 in-progress` after the human explicitly says "approve"
148
- - Mark `✅ done` + record commit hash only after successful `git commit`
149
- - Cannot go from `🔄 in-progress` `✅ done` if the task has a checkpointmust go through the review status first
150
- - `git add` and `git commit` happen AFTER human approval, never before
151
- - Mark `❌ failed` + append reason when the agent can't proceed after retrying
152
- - Mark `⏭ skipped` when the user says "skip"
153
- - Update `Last updated` timestamp on every change
154
- - Preserve checkpoint labels in the task description column
155
-
156
- ## Per-task execution
157
-
158
- For each task:
159
-
160
- 1. **Mark in-progress** — update the progress file: `🔄 in-progress`
161
- 2. **Read the plan** — read the plan's overview section (everything before `## Task 1:`). Extract the `Design:` and `Feature:` metadata to know which design doc and feature row this execution covers. If no `Design:` or `Feature:` metadata is present, the plan covers the entire design (no feature table). Skip design doc reading and proceed directly to task execution. Otherwise, check the current feature's status in the design doc's Features table. Skim all `## Task N:` headings for dependency awareness. Then read the current task's body in full. **Read `docs/lessons.md`** if it exists — follow all rules listed there while working on this task.
162
- 3. **Execute the plan steps** — follow each numbered step in the task body, in order. As you work, shift your cognitive focus through three frames:
163
-
164
- **QA Test frame** (when writing/running tests): Focus entirely on translating the task's `Given/When/Then` Acceptance Criteria into precise failing tests. Before running tests, verify the test environment is sandboxed — no real database connections, API calls, or live services. External dependencies must be mocked or stubbed. Ensure the test environment is isolated (e.g., `NODE_ENV=test`, `GO_ENV=test`, or equivalent for your stack).
165
-
166
- **Pragmatic Developer frame** (when implementing): Focus on the simplest possible code to make the tests green. Do not over-engineer or add code for future requirements. Keep complexity to a bare minimum.
167
-
168
- **Senior Refactoring frame** (when refactoring): Evaluate the craftsmanship of the code. Check for:
169
- - **Shallow modules**is the interface nearly as complex as the implementation? Can complexity be hidden behind a simpler interface?
170
- - **Deletion test** if you deleted this module, would complexity vanish (pass-through) or reappear across callers (earning its keep)?
171
- - **Duplication** — extract repeated patterns
172
- - **Seam discipline** — don't introduce abstraction unless something actually varies across it. One adapter = hypothetical seam. Two adapters = real seam
173
-
174
- Run tests after each refactor step. Never refactor while tests are failing.
175
-
176
- Stop at any `⏸ CHECKPOINT` gate (see [Checkpoint gates](#checkpoint-gates--when-the-plan-says-stop)).
177
- 4. **Verify against task description** — re-read the task from the plan. Does the implementation satisfy every requirement listed? If not, fix before proceeding.
178
- 5. **Learn from mistakes** — if you caught yourself making a mistake during this task that you've made before or that would apply to future tasks, append a rule to `docs/lessons.md`. Only add rules that would change future behavior. If the file doesn't exist, create it with the standard format (see below).
179
-
180
- Before writing, apply the **generalization test**: would this rule apply equally to a completely different feature or domain in this repo? If not, rewrite it — strip out specific service names, entity types, and domain concepts, and express the underlying pattern instead. If you can't express a generic form, don't write the rule.
181
-
182
- ❌ **Domain-specific** (only survives this sprint):
183
- > "Always validate `userId` before calling `UserProfile.Get`"
184
-
185
- ✅ **Generic** (applies across the whole repo):
186
- > "Always validate required ID fields at the service boundary — missing IDs should return 400, not 500"
187
- 6. **Commit** — after all steps are done (no checkpoint gates remain in the task), `git add` the relevant files and commit with a clear message.
188
- 7. **Update progress** — mark `✅ done` + record the commit hash.
189
- 8. **Update design doc** — if the progress file shows all tasks for the current feature are `✅ done`, find the design doc (from plan metadata), and mark the current feature row as `✅ done` in the Features table.
190
- 9. **Suggest session break if needed** — after completing ~3-5 tasks since the last break, suggest:
191
- ```
192
- ✅ Tasks N-M done (commits: abc, def)
193
- Progress: X/Y tasks done
194
- ⏭ Next: Task [N+1] — [description]
195
- 💡 Context is building up. For clean context on remaining tasks:
196
- /new then /skill:pwk-executing-tasks
197
- (or just say "continue" to keep going here)
65
+ ## Per-requirement execution
66
+
67
+ For each requirement:
68
+
69
+ 1. **Mark in-progress** `🔄 in-progress`.
70
+ 2. **Write the integration tests (red).** Read the requirement's acceptance criteria + integration-test cases from the plan and write the actual test files. Run them confirm they **fail** (red). If they pass immediately, the behavior may already exist or the tests are wrong; investigate before proceeding.
71
+ 3. **⏸ CHECKPOINT: tests.** Stop. Do not implement yet. Mark `⏸ tests-review`. Present the integration tests and the failing output to the human, and wait for approval. The human reviews whether the right behaviors are being specified.
72
+ - **approve** return to `🔄 in-progress` and continue.
73
+ - **request changes** revise the tests, re-run, re-present.
74
+ 4. **Implement (green).** With full autonomy, implement whatever is needed to make the integration tests pass and satisfy the acceptance criteria — you choose the structure, modules, signatures, and internals. Run the tests after each meaningful change. Refactor for clarity (shallow modules, no duplication, seam discipline) while tests stay green.
75
+ 5. **Learn.** If you caught a repeat mistake, append a **generic** rule to `docs/lessons.md` (strip domain specifics).
76
+ 6. **⏸ CHECKPOINT: complete.** Stop. Do **not** commit yet. Mark `⏸ complete-review`. Run the tests (show passing output) and `git diff`, present the implementation to the human, and wait for approval.
77
+ - **approve** → return to `🔄 in-progress` and continue.
78
+ - **request changes** → revise, re-run, re-present at this same checkpoint.
79
+ 7. **Commit.** `git add` the relevant files and commit with a clear message. (Status stays `🔄 in-progress` — not done yet.)
80
+ 8. **Code review.** Mark `🔎 review`. Attempt isolated code-review via the `subagent` tool — four agents review the same diff in parallel, each from a different dimension (each gets a fresh context window, zero pollution from previous requirements):
81
+
82
+ Gather the requirement's scope: acceptance criteria, integration test cases, and git diff (`git log --oneline -5 && git diff HEAD~N..HEAD`).
83
+
84
+ **If the `subagent` tool is available**, invoke it with parallel tasks:
85
+ ```json
86
+ {
87
+ "tasks": [
88
+ {"agent": "pwk-spec-reviewer", "task": "<scope + diff here>\n\n## Spec Review\nFor each acceptance criterion, point to the code and test that satisfy it. Flag gaps (criterion with no covering code or test) and scope creep (code beyond criteria). Report only — do not modify files. Your findings are collected by the parent agent which applies fixes and commits changes."},
89
+ {"agent": "pwk-tracing-reviewer", "task": "<scope + diff here>\n\n## Trace Review\nTrace every new/changed code path end-to-end against tests. Note untested branches, dead branches, paths where the trace breaks. Report only — do not modify files. Your findings are collected by the parent agent which applies fixes and commits changes."},
90
+ {"agent": "pwk-smell-reviewer", "task": "<scope + diff here>\n\n## Smell Review\nReport: shallow modules (interface ≈ implementation complexity), duplication, missing seams / premature abstraction, poor naming, magic values, dead code. Flag only: smells requiring risky large refactors. Report only do not modify files. Your findings are collected by the parent agent which applies fixes and commits changes."},
91
+ {"agent": "pwk-hazard-reviewer", "task": "<scope + diff here>\n\n## Hazard Review\nAudit changed code against these hazards: unbounded ops (KEYS/SCAN/full-table loads), missing indexes, unbounded concurrency (Promise.all without limits), long-running transactions, query/command interpolation (injection), unrestricted uploads/temp flooding, silent swallowing loops. Write [SAFE] (1-line reason) or [TRIGGERED] (mitigation). Report only — do not modify files. Your findings are collected by the parent agent which applies fixes and commits changes."}
92
+ ],
93
+ "agentScope": "both",
94
+ "cwd": "<repo-root>"
95
+ }
198
96
  ```
199
- Also suggest at checkpoint review pauses when multiple tasks have been completed since the last break. Respect the user's choice if they say "continue".
200
- 10. **Loop** — go back to step 1 for the next `⬜ pending` task, or see [After all tasks](#after-all-tasks) if none remain.
201
97
 
202
- ### `docs/lessons.md` format
203
-
204
- ```markdown
205
- # Lessons Learned
206
-
207
- <!--
208
- Agent: read this at the start of each task during executing-tasks.
209
- Follow every rule. Add new rules when you catch yourself making repeat mistakes.
210
- Rules must be generic patterns applicable to any domain or feature — not specific to one service, entity, or use case.
211
- Retire rules that no longer apply during finalizing.
212
- -->
213
-
214
- ## Rules
215
-
216
- - <new rule here>
217
- ```
98
+ **On success:** collect all findings. For smell-review findings: identify the smells, apply the fixes yourself (re-run integration tests after changes — must stay green, commit). For trace/spec/hazard findings: flag as follow-ups for human decision or later fix. Update the progress-file row to `✅ done`. Flag non-trivial issues as follow-ups.
218
99
 
219
- When adding a new rule during execution, always append it under `## Rules`. The categorization into specific headers (e.g., `## Tool Usage`, `## Testing Patterns`) is done during finalizing — never during execution.
100
+ **Fallback** (subagent unavailable or returns error): revert to inline review run `/skill:pwk-code-review` for this requirement as before.
101
+ 9. **Loop** — go to step 1 for the next `⬜ pending` requirement, or see [After all requirements](#after-all-requirements).
220
102
 
221
- ### Checkpoint gates when the plan says STOP
103
+ ### Checkpoint gates are mandatory
222
104
 
223
- The plan marks certain steps with `⏸ **CHECKPOINT: test**` or `⏸ **CHECKPOINT: done**`. These are hard stop points. When you reach one:
224
-
225
- 1. **Stop executing immediately.** Do not proceed to the next step in the task. Do not pass go.
226
- 2. **Do NOT run `git add` or `git commit`.** The code stays uncommitted until the human approves.
227
- 3. Update the progress file to `⏸ test-review` or `⏸ done-review`.
228
- 4. Present the checkpoint review (see below).
229
- 5. **Wait for the human to respond.** Do not continue executing steps, do not commit, do not move to the next task.
230
- 6. On approval, update progress back to `🔄 in-progress` and continue with the next step in the task.
231
-
232
- The whole point of checkpoints is that the human reviews code at critical moments before the agent proceeds further. If you skip past a checkpoint without waiting, you defeat this purpose.
233
-
234
- | Checkpoint type | What the agent has done at this point | What needs human approval |
235
- |---|---|---|
236
- | `checkpoint: test` | Written failing tests, confirmed they fail | The test design — are the right things being tested? |
237
- | `checkpoint: done` | Implemented, refactored, written lessons | The implementation approach, the refactoring choices |
238
-
239
- **For `checkpoint: test`:** Only the test file should exist at this point. No implementation code yet. The human reviews the test to confirm the right behavior is being specified.
240
-
241
- **For `checkpoint: done`:** All code changes are made but NOT committed. Run `git diff` (not `git diff --cached` — nothing should be staged) to show the human what changed. The human reviews before anything is committed.
242
-
243
- ## Checkpoint review
244
-
245
- When you hit a checkpoint gate, present a review to the human and **stop all execution** until they respond.
246
-
247
- ### At `checkpoint: test`
248
-
249
- You have written the failing tests and confirmed they fail. No implementation code exists yet.
250
-
251
- Present:
252
- ```
253
- ⏸ Paused at checkpoint: test for task [N]
254
-
255
- **Test file:** `path/to/test.ts`
256
-
257
- **Test code:**
258
- [show the full test code]
259
-
260
- **Test results:** [paste the failing test output showing which tests fail and why]
261
-
262
- **What this validates:** [summarize the behavior these tests specify]
263
- **Next step after approval:** Write the implementation to make these tests pass
264
-
265
- What would you like to do?
266
- - **approve** — I'll implement to make these tests pass
267
- - **request changes** — tell me what to change in the tests
268
- - **revert** — undo this task and go back to pending
269
- - **skip** — skip this task entirely
270
- - **stop** — pause here, resume later with /skill:pwk-executing-tasks
271
- - **status** — show the full progress table
272
- ```
273
-
274
- ### At `checkpoint: done`
275
-
276
- You have implemented the code, run the refactor step, and written any lessons. Nothing is committed yet.
277
-
278
- Present:
279
- ```
280
- ⏸ Paused at checkpoint: done for task [N]
281
-
282
- **What was done:** [brief summary — what feature/fix was implemented]
283
-
284
- **Test results:** [run tests now, paste the passing output]
285
-
286
- **Diff:** [run `git diff` — the unstaged changes are what this task produced]
287
- [paste the full diff]
288
-
289
- **Refactoring done:** [what changed during refactor, or "none needed — [reason]"]
290
- **Lessons learned:** [new rule added to docs/lessons.md, or "none"]
291
- **Next step after approval:** git add, commit, and move to next task
292
-
293
- What would you like to do?
294
- - **approve** — I'll commit and move to the next task
295
- - **request changes** — tell me what to change, I'll update and re-present
296
- - **revert** — undo this task and go back to pending
297
- - **skip** — skip this task entirely
298
- - **stop** — pause here, resume later with /skill:pwk-executing-tasks
299
- - **status** — show the full progress table
300
- ```
301
-
302
- **Do not commit before the human approves.** The diff you show at `checkpoint: done` is the uncommitted work. If the human requests changes, make the edits, re-run tests, and re-present the updated diff at the same checkpoint. Repeat until they say "approve".
303
-
304
- Only after approval: `git add` the relevant files, commit, and mark the task `✅ done`.
305
-
306
- ## Progress file updates
307
-
308
- Update the progress file by reading it, modifying the relevant row's status and commit hash, and writing it back. Target the specific task row — do not use pattern-matching approaches (e.g. sed) that could corrupt the table.
309
-
310
- Update `Last updated` timestamp on every change.
105
+ Both checkpoints are **hard stops, not optional**. When you reach one:
106
+ - Stop executing immediately. Do not pass it without explicit human approval.
107
+ - **Never** `git add` or `git commit` before the human approves at a checkpoint.
108
+ - Mark the progress file to the review status **before** pausing.
311
109
 
312
110
  ## User override commands
313
111
 
314
- The user can issue these commands at any time during execution:
315
-
316
112
  | User says | Agent does |
317
113
  |-----------|-----------|
318
- | `skip` | Mark current task `⏭ skipped`, move to next |
114
+ | `skip` | Mark current requirement `⏭ skipped`, move to next |
319
115
  | `status` | Show the progress table |
320
- | `stop` | Mark current task back to `⬜ pending`, suggest `/new` |
321
- | `retry` | Re-read current task section, start over |
322
-
323
- ## Receiving code review
116
+ | `stop` | Restore current requirement to its pre-in-progress state, suggest `/new` to resume later |
117
+ | `retry` | Re-read the requirement, start over |
324
118
 
325
- When the user shares code review feedback (outside of a checkpoint pause):
119
+ ## Receiving feedback (outside a checkpoint)
326
120
 
327
- 1. **Verify the criticism** read the relevant code. Is the feedback accurate?
328
- 2. **Evaluate the suggestion** — is the proposed fix the right approach? Consider alternatives.
329
- 3. **Implement or push back** — if valid, fix it, re-run tests, and amend the commit. If not, explain why with evidence from the codebase.
330
- 4. **Don't blindly implement** — every suggestion should be verified against the code before accepting.
331
-
332
- ## If you're stuck
121
+ When the user shares review feedback outside a checkpoint: verify the criticism against the code, evaluate the suggestion, then implement (with tests) or push back with evidence. Don't blindly apply.
333
122
 
334
- 1. Re-read the current task section from the plan — you may have drifted from the spec
335
- 2. Check git log — recent commits may reveal context
336
- 3. Ask the user — it's better to clarify than to guess wrong
337
- 4. If still stuck after asking, mark the task `❌ failed` with the reason in the progress file and move to the next task
338
- 5. **Check `docs/lessons.md`** — a previous lesson may be relevant to your current problem.
123
+ ## After all requirements
339
124
 
340
- ## After all tasks
125
+ When no `⬜ pending` or `❌ failed` requirements remain, run the **integration gate** before suggesting finalize. Per-requirement code-review only saw each requirement's diff in isolation — this is where you prove the requirements *compose* into the feature:
341
126
 
342
- When no `⬜ pending` or `❌ failed` tasks remain for the current feature, read the design doc's Features table. Show the per-task summary from the progress file, then check for more features:
127
+ 1. **Run the FULL test suite** (not just the last requirement's tests). Every test must pass. A failure here means one requirement regressed another — fix it now, in execute context, while the progress file and fix autonomy are at hand.
128
+ 2. **Confirm the requirements compose** into the feature the design doc described. Each requirement passed alone; do they deliver the intended end-to-end behavior *together*? If integration exposes a gap, fix it here (with tests) before shipping.
343
129
 
344
- ### More features remaining
130
+ Only when the full suite is green and the feature works end-to-end:
345
131
 
346
132
  ```
347
- Feature "<feature name>" complete.
348
-
349
- | # | Status | Task |
350
- |---|--------|------|
351
- | 1 | ✅ done | Create User model |
352
- | 2 | ✅ done | Add signup endpoint |
353
-
354
- ⏭ Next: "<next pending feature name>"
355
- 💡 Options:
356
- - Plan next feature: /skill:pwk-writing-plans
357
- - Verify this feature first: /skill:pwk-verify
358
- - Or just say "continue"
359
- ```
133
+ All requirements complete — integration verified!
360
134
 
361
- ### All features complete
135
+ | # | Status | Requirement |
136
+ |---|--------|-------------|
137
+ | 1 | ✅ done | <name> |
138
+ | … | … | … |
362
139
 
140
+ - Ship: /skill:pwk-finalizing
363
141
  ```
364
- ✅ All features complete!
365
142
 
366
- | # | Status | Feature |
367
- |---|--------|---------|
368
- | 1 | ✅ done | User signup |
369
- | 2 | ✅ done | Email verification |
370
- | 3 | ⏭ skipped | Password reset |
143
+ ## If you're stuck
371
144
 
372
- | # | Status | Task |
373
- |---|--------|------|
374
- | 1 | done | Create User model |
375
- | 2 | ✅ done | Add signup endpoint |
376
- | ... | ... | ... |
145
+ 1. Re-read the requirement's acceptance criteria — you may have drifted.
146
+ 2. Check `git log` for context.
147
+ 3. Ask the user clarify beats guessing.
148
+ 4. If still stuck:
149
+ - Discard uncommitted changes (`git restore .`).
150
+ - If the requirement has already been committed (step 7 completed), also revert its commit(s) so partial work leaves no trace on the shipped branch (`git revert HEAD --no-edit` if only the requirement commit; `git revert HEAD~N..HEAD --no-edit` if multiple commits including code-review smell fixes).
377
151
 
378
- - Verify everything: /skill:pwk-verify
379
- - Ship: /skill:pwk-finalizing
380
- ```
152
+ **Never leave a failed requirement's partial work on the shipped branch.** Dead code from incomplete requirements must be cleaned up before moving on.
153
+ 5. Mark `❌ failed` with the reason and move on.
154
+ 6. Check `docs/lessons.md` — a prior lesson may apply.