cleargate 0.8.2 → 0.10.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 (98) hide show
  1. package/CHANGELOG.md +190 -0
  2. package/README.md +11 -0
  3. package/dist/MANIFEST.json +259 -28
  4. package/dist/{chunk-OM4FAEA7.js → chunk-Q3BTSXCK.js} +69 -3
  5. package/dist/chunk-Q3BTSXCK.js.map +1 -0
  6. package/dist/cli.cjs +2621 -548
  7. package/dist/cli.cjs.map +1 -1
  8. package/dist/cli.js +2548 -560
  9. package/dist/cli.js.map +1 -1
  10. package/dist/lib/ledger.cjs +120 -0
  11. package/dist/lib/ledger.cjs.map +1 -0
  12. package/dist/lib/ledger.d.cts +64 -0
  13. package/dist/lib/ledger.d.ts +64 -0
  14. package/dist/lib/ledger.js +96 -0
  15. package/dist/lib/ledger.js.map +1 -0
  16. package/dist/templates/cleargate-planning/.claude/agents/architect.md +10 -8
  17. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-contradict.md +108 -0
  18. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-ingest.md +49 -3
  19. package/dist/templates/cleargate-planning/.claude/agents/cleargate-wiki-lint.md +6 -1
  20. package/dist/templates/cleargate-planning/.claude/agents/developer.md +29 -2
  21. package/dist/templates/cleargate-planning/.claude/agents/qa.md +50 -1
  22. package/dist/templates/cleargate-planning/.claude/agents/reporter.md +31 -9
  23. package/dist/templates/cleargate-planning/.claude/hooks/pre-tool-use-task.sh +148 -0
  24. package/dist/templates/cleargate-planning/.claude/hooks/session-start.sh +6 -0
  25. package/dist/templates/cleargate-planning/.claude/hooks/token-ledger.sh +314 -96
  26. package/dist/templates/cleargate-planning/.claude/settings.json +4 -0
  27. package/dist/templates/cleargate-planning/.claude/skills/sprint-execution/SKILL.md +473 -0
  28. package/dist/templates/cleargate-planning/.cleargate/config.example.yml +19 -0
  29. package/dist/templates/cleargate-planning/.cleargate/knowledge/cleargate-enforcement.md +542 -0
  30. package/dist/templates/cleargate-planning/.cleargate/knowledge/cleargate-protocol.md +102 -428
  31. package/dist/templates/cleargate-planning/.cleargate/knowledge/readiness-gates.md +31 -0
  32. package/dist/templates/cleargate-planning/.cleargate/knowledge/sprint-closeout-checklist.md +71 -0
  33. package/dist/templates/cleargate-planning/.cleargate/scripts/assert_story_files.mjs +24 -2
  34. package/dist/templates/cleargate-planning/.cleargate/scripts/close_sprint.mjs +387 -27
  35. package/dist/templates/cleargate-planning/.cleargate/scripts/dedupe_frontmatter.mjs +219 -0
  36. package/dist/templates/cleargate-planning/.cleargate/scripts/lib/report-filename.mjs +54 -0
  37. package/dist/templates/cleargate-planning/.cleargate/scripts/prep_doc_refresh.mjs +378 -0
  38. package/dist/templates/cleargate-planning/.cleargate/scripts/prep_qa_context.mjs +888 -0
  39. package/dist/templates/cleargate-planning/.cleargate/scripts/sprint_trends.mjs +71 -0
  40. package/dist/templates/cleargate-planning/.cleargate/scripts/suggest_improvements.mjs +355 -13
  41. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_flashcard_gate.sh +20 -20
  42. package/dist/templates/cleargate-planning/.cleargate/scripts/test/test_prep_qa_context.sh +482 -0
  43. package/dist/templates/cleargate-planning/.cleargate/scripts/write_dispatch.sh +125 -0
  44. package/dist/templates/cleargate-planning/.cleargate/templates/Bug.md +24 -1
  45. package/dist/templates/cleargate-planning/.cleargate/templates/CR.md +32 -1
  46. package/dist/templates/cleargate-planning/.cleargate/templates/Sprint Plan Template.md +48 -14
  47. package/dist/templates/cleargate-planning/.cleargate/templates/epic.md +37 -3
  48. package/dist/templates/cleargate-planning/.cleargate/templates/hotfix.md +50 -0
  49. package/dist/templates/cleargate-planning/.cleargate/templates/initiative.md +98 -29
  50. package/dist/templates/cleargate-planning/.cleargate/templates/proposal.md +17 -4
  51. package/dist/templates/cleargate-planning/.cleargate/templates/sprint_report.md +23 -4
  52. package/dist/templates/cleargate-planning/.cleargate/templates/story.md +55 -3
  53. package/dist/templates/cleargate-planning/CLAUDE.md +28 -10
  54. package/dist/templates/cleargate-planning/MANIFEST.json +259 -28
  55. package/dist/{whoami-CX7CXJD5.js → whoami-W4U6DPVG.js} +17 -17
  56. package/dist/whoami-W4U6DPVG.js.map +1 -0
  57. package/package.json +13 -2
  58. package/templates/cleargate-planning/.claude/agents/architect.md +10 -8
  59. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-contradict.md +108 -0
  60. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-ingest.md +49 -3
  61. package/templates/cleargate-planning/.claude/agents/cleargate-wiki-lint.md +6 -1
  62. package/templates/cleargate-planning/.claude/agents/developer.md +29 -2
  63. package/templates/cleargate-planning/.claude/agents/qa.md +50 -1
  64. package/templates/cleargate-planning/.claude/agents/reporter.md +31 -9
  65. package/templates/cleargate-planning/.claude/hooks/pre-tool-use-task.sh +148 -0
  66. package/templates/cleargate-planning/.claude/hooks/session-start.sh +6 -0
  67. package/templates/cleargate-planning/.claude/hooks/token-ledger.sh +314 -96
  68. package/templates/cleargate-planning/.claude/settings.json +4 -0
  69. package/templates/cleargate-planning/.claude/skills/sprint-execution/SKILL.md +473 -0
  70. package/templates/cleargate-planning/.cleargate/config.example.yml +19 -0
  71. package/templates/cleargate-planning/.cleargate/knowledge/cleargate-enforcement.md +542 -0
  72. package/templates/cleargate-planning/.cleargate/knowledge/cleargate-protocol.md +102 -428
  73. package/templates/cleargate-planning/.cleargate/knowledge/readiness-gates.md +31 -0
  74. package/templates/cleargate-planning/.cleargate/knowledge/sprint-closeout-checklist.md +71 -0
  75. package/templates/cleargate-planning/.cleargate/scripts/assert_story_files.mjs +24 -2
  76. package/templates/cleargate-planning/.cleargate/scripts/close_sprint.mjs +387 -27
  77. package/templates/cleargate-planning/.cleargate/scripts/dedupe_frontmatter.mjs +219 -0
  78. package/templates/cleargate-planning/.cleargate/scripts/lib/report-filename.mjs +54 -0
  79. package/templates/cleargate-planning/.cleargate/scripts/prep_doc_refresh.mjs +378 -0
  80. package/templates/cleargate-planning/.cleargate/scripts/prep_qa_context.mjs +888 -0
  81. package/templates/cleargate-planning/.cleargate/scripts/sprint_trends.mjs +71 -0
  82. package/templates/cleargate-planning/.cleargate/scripts/suggest_improvements.mjs +355 -13
  83. package/templates/cleargate-planning/.cleargate/scripts/test/test_flashcard_gate.sh +20 -20
  84. package/templates/cleargate-planning/.cleargate/scripts/test/test_prep_qa_context.sh +482 -0
  85. package/templates/cleargate-planning/.cleargate/scripts/write_dispatch.sh +125 -0
  86. package/templates/cleargate-planning/.cleargate/templates/Bug.md +24 -1
  87. package/templates/cleargate-planning/.cleargate/templates/CR.md +32 -1
  88. package/templates/cleargate-planning/.cleargate/templates/Sprint Plan Template.md +48 -14
  89. package/templates/cleargate-planning/.cleargate/templates/epic.md +37 -3
  90. package/templates/cleargate-planning/.cleargate/templates/hotfix.md +50 -0
  91. package/templates/cleargate-planning/.cleargate/templates/initiative.md +98 -29
  92. package/templates/cleargate-planning/.cleargate/templates/sprint_report.md +23 -4
  93. package/templates/cleargate-planning/.cleargate/templates/story.md +55 -3
  94. package/templates/cleargate-planning/CLAUDE.md +28 -10
  95. package/templates/cleargate-planning/MANIFEST.json +259 -28
  96. package/dist/chunk-OM4FAEA7.js.map +0 -1
  97. package/dist/whoami-CX7CXJD5.js.map +0 -1
  98. package/templates/cleargate-planning/.cleargate/templates/proposal.md +0 -61
@@ -0,0 +1,473 @@
1
+ ---
2
+ name: sprint-execution
3
+ description: |
4
+ Use to orchestrate the four-agent sprint loop end-to-end — Architect → Developer →
5
+ QA → Reporter — across one ClearGate sprint. Activates from sprint kickoff
6
+ (preflight + cut sprint branch + state init) through per-story execution
7
+ (worktree → dev → QA → flashcard gate → merge) into walkthrough and Gate-4 close.
8
+ Triggers: SessionStart banner mentioning an active sprint; explicit user phrases
9
+ "start the sprint", "run the sprint", "execute the sprint", "begin sprint
10
+ execution", "kick off SPRINT-NN", "run STORY-NNN-NN"; CLI directives ending
11
+ with `→ Load skill: sprint-execution`. The skill does not draft work items, run
12
+ triage, or manage planning — those stay in always-on CLAUDE.md surface.
13
+ ---
14
+
15
+ # Sprint Execution — The Playbook
16
+
17
+ You are the **Orchestrator**. You read this playbook top to bottom once when a sprint becomes active, then execute it. You never write production code. You delegate every implementation step to the four execution agents (`architect`, `developer`, `qa`, `reporter`) by spawning them via the `Agent` tool with the matching `subagent_type`.
18
+
19
+ This skill is the **execution-time** layer. Triage, drafting, and pre-sprint planning stay in CLAUDE.md and `cleargate-protocol.md`. Read those before deciding to load this skill.
20
+
21
+ ---
22
+
23
+ ## 0. When This Skill Loads
24
+
25
+ Three explicit load points (belt-and-suspenders — the SKILL description handles the rest):
26
+
27
+ 1. **SessionStart banner.** When the doctor banner reports `Active sprint: SPRINT-NN`, the skill auto-loads. (Banner emitted by `.claude/hooks/session-start.sh`; `.cleargate/sprint-runs/.active` is the sentinel file.)
28
+ 2. **CLI directive.** Any `cleargate sprint *` command finishing with the line `→ Load skill: sprint-execution` instructs the orchestrator to load this skill before continuing.
29
+ 3. **Natural-language triggers.** "start the sprint", "kick off SPRINT-NN", "run the sprint", "execute the loop", "run STORY-NNN-NN" → load the skill, do not improvise.
30
+
31
+ If you are running a sprint and you have not loaded this skill yet, **stop and load it now**. Do not orchestrate from memory.
32
+
33
+ ---
34
+
35
+ ## 0.5 Goal-First Execution
36
+
37
+ **The sprint goal is the success criterion — not the count of merged stories.** A sprint where every story passes QA but the goal is not met is a failed sprint. Read `sprint_goal:` from the active sprint plan's frontmatter (or §1 if unstructured) at kickoff and treat it as the anchor for every decision the orchestrator makes.
38
+
39
+ Five touchpoints where the goal is the tiebreaker:
40
+
41
+ 1. **Kickoff (§A.5).** Surface the sprint goal verbatim in chat before any Architect dispatch. State it as the explicit acceptance condition for the sprint.
42
+ 2. **Architect dispatch (§B).** Pass the sprint goal in the dispatch prompt. The milestone plan should reference how each story advances the goal, not only what files it changes.
43
+ 3. **Mid-sprint CR triage (§C.9).** When classifying `CR:scope-change`, evaluate goal alignment before quarantining. If the new requirement is critical to the goal, escalate to the human with "this may need to land THIS sprint, not the next."
44
+ 4. **Escalation (§8).** When `qa_bounces ≥ 3`, `arch_bounces ≥ 3`, or 3 circuit-breaker hits flip a story to `Escalated`, frame the human-decision question through the goal lens: "Drop this story → goal still met? Re-approach → goal still met by sprint end?"
45
+ 5. **Walkthrough + Reporter brief (§D, §E.2).** Walkthrough invitation leads with the goal, not the feature checklist. Reporter brief MUST include a goal-achievement verdict — `met / partial / missed` — as a first-class signal in the close-gate Brief.
46
+
47
+ **What goal-first is NOT:**
48
+ - Not authority to skip stories the orchestrator deems "off-goal" — splits and merges are decomposition-time decisions, never mid-sprint.
49
+ - Not authority to rewrite the goal mid-flight — that requires a CR or a sprint reset.
50
+ - Not a license to relax acceptance criteria — story Gherkin still passes verbatim.
51
+
52
+ It is pure framing: surface deviations from the goal as first-class events, not afterthoughts.
53
+
54
+ ---
55
+
56
+ ## 1. Agent Roster + Dispatch Contract
57
+
58
+ | Subagent | Model | Spawn point | Output artifact |
59
+ |---|---|---|---|
60
+ | `architect` | opus | (a) Sprint Design Review pre-confirm, (b) per-milestone plan | `sprint-runs/<id>/plans/M<N>.md` (per milestone); markdown block §2 (design review) |
61
+ | `developer` | sonnet | One per story, inside its worktree | One commit `feat(<epic>): STORY-NNN-NN <desc>` + `STORY-NNN-NN-dev.md` report |
62
+ | `qa` | sonnet | After Developer reports `STATUS=done` | `STORY-NNN-NN-qa.md` report (no code edits) |
63
+ | `reporter` | sonnet | Once at sprint close, after all stories merged + walkthrough done | `sprint-runs/<id>/SPRINT-<#>_REPORT.md` |
64
+
65
+ ### Wall-clock budgets
66
+
67
+ Each agent dispatch has a target duration. Note the start time before each `Agent` spawn; after the call returns, compare elapsed against the budget. Ran-long stories get flagged in sprint §4 Execution Log even on success.
68
+
69
+ | Agent | Budget | Notes |
70
+ |---|---|---|
71
+ | `architect` (per milestone) | ≤ 10 min | Plan-only output; long runs usually mean too many stories in the milestone |
72
+ | `developer` (per story) | ≤ 30 min | Includes typecheck + tests in the worktree; long runs near the circuit-breaker threshold |
73
+ | `qa` (per story) | ≤ 15 min | Read + re-run gates; should not edit code |
74
+ | `reporter` (per sprint) | ≤ 20 min | Single file write; long runs mean ledger reconciliation issues |
75
+
76
+ If a Task call has been pending for **>2× the budget** with no visible progress, surface it to the human and offer to interrupt. There is no automatic stall detection — the parent session blocks on `Agent` calls and cannot poll mid-run. The human's interrupt is the only reliable kill path until ambient watcher infra exists.
77
+
78
+ ### Dispatch marker — write before every spawn
79
+
80
+ The token-ledger hook attributes tokens by reading `.cleargate/sprint-runs/<sprint>/.dispatch-<session-id>.json`. You write that file immediately before each `Agent` call:
81
+
82
+ ```bash
83
+ bash .cleargate/scripts/write_dispatch.sh <work_item_id> <agent_type>
84
+ ```
85
+
86
+ - `<work_item_id>`: e.g. `STORY-020-02`, `CR-016`, `BUG-021`. For the Reporter at sprint close use the sprint ID (e.g. `SPRINT-19`).
87
+ - `<agent_type>`: exact string — `developer | architect | qa | reporter | cleargate-wiki-contradict`.
88
+
89
+ If you forget the marker, ledger attribution falls back to transcript-grep heuristics (unreliable). The hook deletes the file after consumption — write fresh per dispatch.
90
+
91
+ ---
92
+
93
+ ## 2. v1 / v2 Mode Switch
94
+
95
+ Every step below is gated by the active sprint's `execution_mode:` frontmatter:
96
+
97
+ | Mode | Effect |
98
+ |---|---|
99
+ | `v1` | All §§ rules in `cleargate-enforcement.md` are advisory — document workflow; no script enforcement. Rework counters, flashcard gate, surface contract, etc. are informational. |
100
+ | `v2` | All §§ rules are mandatory. Hooks block on violations. Worktree isolation, pre-gate scans, file-surface contract, flashcard gate, sprint close — all enforced. |
101
+
102
+ Default is `v1`. Read the field before spawning Developer/QA/Reporter. If absent, treat as `v1`. **Do not infer mode from sprint number — read the frontmatter.**
103
+
104
+ ---
105
+
106
+ ## 3. Phase A — Sprint Kickoff (Ready → Active)
107
+
108
+ Run this sequence exactly once, when the human says "start sprint NN" or equivalent. Halt on any failure; do not improvise around a failed gate.
109
+
110
+ ### A.1 Sprint Execution Gate (Gate 3) — preflight
111
+
112
+ ```bash
113
+ cleargate sprint preflight <sprint-id>
114
+ ```
115
+
116
+ Five checks, all must pass:
117
+
118
+ 1. Previous sprint `sprint_status: "Completed"` in `state.json`.
119
+ 2. No leftover worktrees — `git worktree list` must not contain `.worktrees/STORY-*`.
120
+ 3. Sprint branch ref free — `git show-ref refs/heads/sprint/S-NN` returns nothing.
121
+ 4. `main` clean — `git status --porcelain` empty.
122
+ 5. Per-item readiness gates pass — every work-item ID in §1 Consolidated Deliverables has fresh `cached_gate_result.pass: true` (or terminal status). Under `execution_mode: v2` a failing item hard-blocks; under `v1` it warns. Failure punch-list names each item + its failing criteria.
123
+
124
+ On failure, surface the punch list verbatim and halt. Per-item resolution:
125
+
126
+ - Prev sprint not closed → run sprint close on prev first.
127
+ - Leftover worktree → `git worktree remove` if abandoned, otherwise merge.
128
+ - Branch ref exists → investigate; force-deletion only with explicit human approval.
129
+ - Dirty main → human commits/stashes/discards. **Never `git reset --hard` or stash without explicit human approval.**
130
+ - Per-item gate fail → run `cleargate gate check <file> -v` for the named item; fix the failing criterion (e.g., populate `context_source`, resolve TBDs); re-run preflight.
131
+
132
+ ### A.2 Cut sprint branch
133
+
134
+ ```bash
135
+ git checkout -b sprint/S-NN main
136
+ ```
137
+
138
+ Sprint branch is **never committed to directly**. All work lands via story-branch merges.
139
+
140
+ ### A.3 Initialize sprint state
141
+
142
+ ```bash
143
+ node .cleargate/scripts/init_sprint.mjs SPRINT-NN
144
+ ```
145
+
146
+ This writes `.cleargate/sprint-runs/SPRINT-NN/state.json` and flips `.cleargate/sprint-runs/.active` to `SPRINT-NN`. Without `state.json` the lane router, dispatch hook, and close pipeline all fail.
147
+
148
+ ### A.4 Architect Sprint Design Review (v2 only)
149
+
150
+ Mandatory under `execution_mode: v2`; optional but encouraged under `v1`. Spawn the Architect with all candidate stories' §3 Implementation Guides + ADRs + flashcards + sprint plan path:
151
+
152
+ ```
153
+ Task instruction: "SPRINT DESIGN REVIEW — write Sprint Plan §2 Execution Strategy.
154
+ You have WRITE ACCESS to Sprint Plan §2 ONLY. Produce §§2.1–2.4 (Phase Plan,
155
+ Merge Ordering, Shared-Surface Warnings, ADR-Conflict Flags) plus §2.4 Lane Audit."
156
+ ```
157
+
158
+ Architect returns a markdown block; you insert it into the sprint plan file. Then halt and ask the human to confirm the sprint plan before any story executes.
159
+
160
+ ### A.5 Flip sprint status
161
+
162
+ After human confirms, update sprint frontmatter `status: Active` (via `cleargate stamp` after the edit).
163
+
164
+ > 🎯 **Goal check.** Before the first Architect dispatch, surface the sprint goal verbatim from the plan's `sprint_goal:` frontmatter (or §1 if unstructured) in chat: *"Sprint goal: <verbatim>. Success = this is met by close. Stories are the means; this is the end."* All subsequent halts and decisions reference back to this line.
165
+
166
+ ---
167
+
168
+ ## 4. Phase B — Per-Milestone Architect Plan
169
+
170
+ Before any Developer dispatches in a milestone, spawn the Architect once for the whole milestone:
171
+
172
+ ```bash
173
+ bash .cleargate/scripts/write_dispatch.sh M<N> architect
174
+ ```
175
+
176
+ Then `Agent(subagent_type=architect, ...)` with the milestone story IDs and instruction to write `.cleargate/sprint-runs/<sprint-id>/plans/M<N>.md`.
177
+
178
+ **Skip per-milestone Architect for `lane: fast` stories** — they dispatch to Developer without a plan, per the lane contract (see `.claude/agents/architect.md` Lane Classification).
179
+
180
+ > 🎯 **Goal check.** Pass the sprint goal verbatim in the Architect's dispatch prompt. The plan should explicitly tie each story to the goal under "Per-story blueprint" — e.g. *"STORY-NNN-NN advances goal by <one sentence>"*. Plans that don't reference the goal go back to the Architect with a re-dispatch.
181
+
182
+ ---
183
+
184
+ ## 5. Phase C — Per-Story Execution Loop
185
+
186
+ Run this loop **per story**, in the order the milestone plan declares (parallel waves vs sequential chains). Each iteration: Worktree → Developer → QA → (Architect pass for `lane: standard` v2 only) → Merge → Flashcard Gate.
187
+
188
+ > **Naming note.** State-machine values (`Bouncing`, `Ready to Bounce`), `state.json` counter fields (`qa_bounces`, `arch_bounces`), and script names (`validate_bounce_readiness.mjs`) retain the legacy "bounce" term because they are code-bound. The narrative in this skill uses "execution loop", "story cycle", and "rework" to describe the same mechanics.
189
+
190
+ ### C.1 Pre-execution check
191
+
192
+ ```bash
193
+ node .cleargate/scripts/validate_state.mjs
194
+ node .cleargate/scripts/validate_bounce_readiness.mjs STORY-NNN-NN
195
+ ```
196
+
197
+ `state.json` `sprintId` must equal the active sprint. If not, re-run `init_sprint.mjs` — **do not create a worktree with a stale state.json**.
198
+
199
+ `validate_bounce_readiness.mjs` checks: story is "Ready to Bounce", §§1/2/3 present, working tree clean. Fail → halt.
200
+
201
+ ### C.2 Create worktree
202
+
203
+ ```bash
204
+ git worktree add .worktrees/STORY-NNN-NN -b story/STORY-NNN-NN sprint/S-NN
205
+ ```
206
+
207
+ Story branch is cut from the **sprint branch**, never from main. Verify:
208
+
209
+ ```bash
210
+ git worktree list
211
+ ```
212
+
213
+ **Do not run `git worktree add` inside `mcp/`.** It is a nested git repo. If the story touches `mcp/`, the Developer edits `mcp/` from inside `.worktrees/STORY-NNN-NN/mcp/...` — visible as a subdirectory of the outer worktree. (`cleargate-enforcement.md` §1.3.)
214
+
215
+ ### C.3 Spawn Developer
216
+
217
+ ```bash
218
+ bash .cleargate/scripts/write_dispatch.sh STORY-NNN-NN developer
219
+ ```
220
+
221
+ Then spawn with `subagent_type=developer`. Inputs the prompt must include verbatim:
222
+
223
+ - `STORY=NNN-NN` (Developer must echo this on its first response line).
224
+ - Path to story file.
225
+ - Path to milestone plan.
226
+ - Worktree path (assigned).
227
+ - Sprint ID.
228
+
229
+ Developer returns:
230
+
231
+ ```
232
+ STORY: STORY-NNN-NN
233
+ STATUS: done | blocked
234
+ COMMIT: <sha> | none
235
+ TYPECHECK: pass | fail
236
+ TESTS: X passed, Y failed
237
+ FILES_CHANGED: <list>
238
+ flashcards_flagged: [ ... ]
239
+ ```
240
+
241
+ If `STATUS=blocked`: route per §C.7 (Blockers Triage).
242
+
243
+ ### C.4 Spawn QA
244
+
245
+ ```bash
246
+ bash .cleargate/scripts/write_dispatch.sh STORY-NNN-NN qa
247
+ ```
248
+
249
+ QA inputs: story file path, worktree path, Developer commit SHA. QA returns:
250
+
251
+ ```
252
+ QA: PASS | FAIL
253
+ ACCEPTANCE_COVERAGE: N of M scenarios
254
+ MISSING: <list>
255
+ REGRESSIONS: <list>
256
+ flashcards_flagged: [ ... ]
257
+ ```
258
+
259
+ **On `QA: FAIL`:** increment `qa_bounces` via `update_state.mjs STORY-NNN-NN --qa-bounce`. If counter ≥ 3 → flip story to `Escalated`, surface to human, halt. Else → re-spawn Developer with QA's bug report as input. Return to §C.3.
260
+
261
+ **On `QA: PASS`:** update state to `QA Passed`, proceed.
262
+
263
+ ### C.5 Architect Pass (v2, `lane: standard` only)
264
+
265
+ `lane: fast` skips this step entirely.
266
+
267
+ ```bash
268
+ bash .cleargate/scripts/pre_gate_runner.sh arch .worktrees/STORY-NNN-NN/ sprint/S-NN
269
+ ```
270
+
271
+ If pre-gate scan reveals new dependencies / structural issues → return to Developer (do NOT spawn Architect for mechanical failures). 3+ pre-gate failures → escalate.
272
+
273
+ If pre-gate passes, spawn Architect for post-flight review. On `FAIL`: increment `arch_bounces`. ≥ 3 → escalate.
274
+
275
+ ### C.6 Story Merge
276
+
277
+ ```bash
278
+ git checkout sprint/S-NN
279
+ git merge story/STORY-NNN-NN --no-ff -m "merge(story/STORY-NNN-NN): STORY-NNN-NN <title>"
280
+ git worktree remove .worktrees/STORY-NNN-NN
281
+ git branch -d story/STORY-NNN-NN
282
+ ```
283
+
284
+ Verify all required reports exist before merge:
285
+
286
+ - `STORY-NNN-NN-dev.md` (always required, regardless of lane)
287
+ - `STORY-NNN-NN-qa.md` (required unless lane=fast skipped QA)
288
+ - `STORY-NNN-NN-arch.md` (required for v2 standard-lane only)
289
+
290
+ Missing report → return to spawn that agent. **Do not merge with missing reports.**
291
+
292
+ ### C.7 Blockers Triage (Developer circuit breaker)
293
+
294
+ When Developer returns `BLOCKED: circuit breaker triggered`, read `.cleargate/sprint-runs/<id>/reports/STORY-NNN-NN-dev-blockers.md`. The report has three sections:
295
+
296
+ | Non-N/A section | Routing |
297
+ |---|---|
298
+ | `## Test-Pattern` | Re-launch Developer with the pattern hint as additional context. Pass the sentence verbatim in the new prompt. |
299
+ | `## Spec-Gap` | **Halt and surface the sentence to the human.** Do NOT re-launch Developer until human clarifies. |
300
+ | `## Environment` | Re-run `pre_gate_runner.sh`. If pre-gate passes, re-launch Developer; otherwise surface env issue. |
301
+
302
+ 3 consecutive circuit-breaker hits on the same story → `update_state.mjs STORY-NNN-NN Escalated`, halt.
303
+
304
+ ### C.8 Flashcard Gate (v2 mandatory; v1 dogfood)
305
+
306
+ After every story merge — **before creating story N+1's worktree** — process the merged `flashcards_flagged` list (union of dev + QA, dedupe by exact-string):
307
+
308
+ For each card:
309
+
310
+ | Action | Effect |
311
+ |---|---|
312
+ | **Approve** | Append the line verbatim to `.cleargate/FLASHCARD.md` (newest-first). |
313
+ | **Reject** | Discard. Log `FLASHCARD-REJECT YYYY-MM-DD — "<card>" — reason: <one sentence>` in sprint §4 Execution Log. |
314
+
315
+ Then mark each card processed:
316
+
317
+ ```bash
318
+ HASH=$(printf '%s' "<card text>" | shasum -a 1 | cut -c1-12)
319
+ touch .cleargate/sprint-runs/<sprint-id>/.processed-${HASH}
320
+ ```
321
+
322
+ Under v2, the `pending-task-sentinel.sh` PreToolUse hook blocks the next `Task` spawn until every card has a `.processed-<hash>` marker. Bypass only with `SKIP_FLASHCARD_GATE=1` — log the bypass in sprint §4.
323
+
324
+ ### C.9 Mid-cycle User Input — CR Triage
325
+
326
+ If the user injects new input mid-story, classify before routing:
327
+
328
+ | Type | Effect | Routing |
329
+ |---|---|---|
330
+ | `CR:bug` | Defect in current story | Increments `qa_bounces`; re-open story; Dev fixes; QA re-verifies |
331
+ | `CR:spec-clarification` | Removes ambiguity, no new scope | No counter; update §1.2 in place; re-run impacted test |
332
+ | `CR:scope-change` | Net-new requirement | **Quarantine.** New Story file in `pending-sync/`; current story unchanged |
333
+ | `CR:approach-change` | Different impl, same spec | No counter; reset Dev context; re-spawn with updated approach |
334
+
335
+ Log every CR in sprint §4 Execution Log with date + ID.
336
+
337
+ > 🎯 **Goal check on `CR:scope-change`.** Default routing is quarantine-into-next-sprint. **Override the default if the new requirement is critical to the active sprint goal** — escalate to the human with: *"This scope-change is goal-critical: the sprint goal is `<verbatim>` and without this change, the goal will not be met. Add to current sprint? (Adding mid-sprint requires explicit ack per §C.9.)"* Quarantine remains default for goal-incidental scope.
338
+
339
+ ---
340
+
341
+ ## 6. Phase D — Sprint Walkthrough (v2)
342
+
343
+ Mandatory under v2. After all stories merged into `sprint/S-NN` (every story state ∈ `TERMINAL_STATES`) and **before** sprint→main merge, invite the user to test on the sprint branch. Classify every piece of feedback:
344
+
345
+ | Event | Definition | Bug-Fix Tax |
346
+ |---|---|---|
347
+ | `UR:bug` | Defect, crash, behavior broken vs spec | Increments |
348
+ | `UR:review-feedback` | Polish, copy, UX preference | Does not increment |
349
+
350
+ **When in doubt, ask:** "Is this broken vs spec, or a preference?" Do not default to `UR:bug`.
351
+
352
+ Log every event in sprint §4. **Sprint branch MUST NOT merge to main while any `UR:bug` is unresolved.** `UR:review-feedback` may defer with explicit human sign-off.
353
+
354
+ > 🎯 **Goal check.** Open the walkthrough invitation with the sprint goal verbatim, not a feature checklist: *"Sprint goal: `<verbatim>`. The branch is ready on `sprint/S-NN`. Test it and tell me — does the running build achieve the goal?"* This forces the framing to be outcome-vs-spec rather than feature-tour.
355
+
356
+ ---
357
+
358
+ ## 7. Phase E — Gate 4 Close (Reporter + Human Sign-off)
359
+
360
+ This is a **Gate-3-class action**. Authorising sprint execution does NOT authorise close. Close requires its own dedicated human approval.
361
+
362
+ ### E.1 Step A — orchestrator runs close
363
+
364
+ ```bash
365
+ node .cleargate/scripts/close_sprint.mjs <sprint-id>
366
+ ```
367
+
368
+ No flags. Script validates Steps 1–2.6 (lifecycle reconciler runs at Step 2.6; see `cleargate-enforcement.md` §10), prefills `SPRINT-<#>_REPORT.md` stub if missing via the Reporter agent, and exits 0 with the prompt:
369
+
370
+ > Review the report, then confirm close by re-running with --assume-ack.
371
+
372
+ ### E.2 Reporter dispatch (Step 3.5)
373
+
374
+ If the report stub does not exist, dispatch the Reporter:
375
+
376
+ ```bash
377
+ bash .cleargate/scripts/write_dispatch.sh SPRINT-NN reporter
378
+ ```
379
+
380
+ Reporter writes `.cleargate/sprint-runs/<id>/SPRINT-<#>_REPORT.md` and returns the Brief:
381
+
382
+ > **Goal:** `<verbatim sprint goal>` — **Verdict: met | partial | missed.**
383
+ > Delivered N stories, M epics. Observe: X bugs, Y review-feedback. Carry-over: Z. Token cost: T.
384
+ > See SPRINT-\<#>_REPORT.md for full report.
385
+ > Ready to authorize close (Gate 4)?
386
+
387
+ > 🎯 **Goal check.** The verdict line is mandatory and is the first line of the Brief. `met` = goal achieved as written. `partial` = some sprint-goal acceptance criteria met, others not — explain which in REPORT §1. `missed` = goal not achieved despite stories merging. A `partial` or `missed` verdict does NOT block close, but it is a first-class signal to the human that close-ack should be deliberate, not reflexive.
388
+
389
+ ### E.3 Step B — surface and HALT
390
+
391
+ Surface the Brief verbatim to the human. **Halt.** Do not re-run with `--assume-ack`.
392
+
393
+ The human either:
394
+
395
+ - Re-runs `close_sprint.mjs <id> --assume-ack` themselves, OR
396
+ - Says "approved, close it" — at which point you may pass the flag on their behalf.
397
+
398
+ `--assume-ack` is reserved for **automated test environments only**. Passing it autonomously is a Gate-4 breach equivalent to an unauthorized push.
399
+
400
+ ### E.4 Doc & metadata refresh on close
401
+
402
+ During Gate 4 sign-off, read `.cleargate/sprint-runs/<id>/.doc-refresh-checklist.md` (generated by `prep_doc_refresh.mjs`). Apply or punt each `- [ ]` item per `.cleargate/knowledge/sprint-closeout-checklist.md`. Items already `- [x]` mean "no changes detected, skip."
403
+
404
+ ### E.5 Sprint→main merge
405
+
406
+ After sign-off and after all walkthrough `UR:bug` items resolved:
407
+
408
+ ```bash
409
+ git checkout main
410
+ git merge sprint/S-NN --no-ff -m "Sprint S-NN: <goal>"
411
+ ```
412
+
413
+ Then flip sprint frontmatter `status: Completed`, archive the sprint file (`pending-sync/` → `archive/`).
414
+
415
+ ---
416
+
417
+ ## 8. Rework Counter Quick Reference
418
+
419
+ | Counter | Increment trigger | Escalation |
420
+ |---|---|---|
421
+ | `qa_bounces` | Each `QA: FAIL` | ≥ 3 → `Escalated`, halt |
422
+ | `arch_bounces` | Each `Architect: FAIL` | ≥ 3 → `Escalated`, halt |
423
+ | Circuit breaker | 50 tool calls without test pass OR 2 identical failures | 3 hits same story → `Escalated`, halt |
424
+ | Pre-gate failures | Each `pre_gate_runner.sh` non-zero | 3 hits same story → human escalation (descope / re-approach) |
425
+
426
+ > 🎯 **Goal check on escalation.** When a story flips to `Escalated`, frame the human-decision question through the goal lens, not in isolation: *"STORY-NNN-NN escalated after N rework cycles. Sprint goal is `<verbatim>`. Options: (a) drop the story — is the goal still met without it? (b) re-approach with X — same goal met by sprint end? (c) split into smaller stories — which scope serves the goal? (d) defer to next sprint — does the goal change?"* Never present escalation as a generic "what do you want to do?" — always tie options to goal achievement.
427
+
428
+ State updates go through:
429
+
430
+ ```bash
431
+ node .cleargate/scripts/update_state.mjs STORY-NNN-NN [--qa-bounce | --arch-bounce | <new-state>]
432
+ ```
433
+
434
+ `Escalated` halts the loop until human decides: descope, re-assign approach, or split story.
435
+
436
+ ---
437
+
438
+ ## 9. File-Surface Contract (v2)
439
+
440
+ Each story's §3.1 "Context & Files" table is the **authoritative file surface** for its commit. The pre-commit hook (`.git/hooks/pre-commit` → `.claude/hooks/pre-commit-surface-gate.sh`) blocks commits that touch off-surface files.
441
+
442
+ Off-surface edits require **either**:
443
+
444
+ 1. A `CR:scope-change` approved before the commit, OR
445
+ 2. An updated §3.1 table committed in the same story (self-amending — must be justified in commit message).
446
+
447
+ Bypass with `SKIP_SURFACE_GATE=1` only when absolutely necessary; log in sprint §4. Under v1 the hook only warns.
448
+
449
+ ---
450
+
451
+ ## 10. What This Skill Does NOT Cover
452
+
453
+ These live elsewhere — do not duplicate inline:
454
+
455
+ - **Triage / drafting / Gate 1 Brief** → CLAUDE.md + `cleargate-protocol.md` §§1–4.
456
+ - **Worktree command details and edge cases** → `cleargate-enforcement.md` §1.
457
+ - **Lane classification rubric (7 checks)** → `.claude/agents/architect.md` Lane Classification + `cleargate-enforcement.md` §9.
458
+ - **Sprint Plan template / Gate 2 Sprint Ready** → `.cleargate/templates/Sprint Plan Template.md`.
459
+ - **Wiki ingest / lint / contradiction detection** → `cleargate-protocol.md` §10.
460
+ - **Doctor exit codes** → `cleargate-enforcement.md` §8.
461
+ - **Hotfix flow** → V-Bounce-style hotfix handling, see flashcard tag `#hotfix` and `wiki/topics/hotfix-ledger.md`.
462
+
463
+ When in doubt, read the source-of-truth doc — this skill cites them, it does not replace them.
464
+
465
+ ---
466
+
467
+ ## 11. Conversational Discipline During Execution
468
+
469
+ - **Sprint execution is autonomous.** Once started, run the loop end-to-end. Escalate only on blockers, gate failures, or destructive operations.
470
+ - **Terse output.** Status updates one sentence each. Details live in story reports and `SPRINT-<#>_REPORT.md`, not in chat.
471
+ - **Halt at gates without negotiation.** Gate 3 (preflight), Gate 4 (close sign-off), `Escalated` state — these are not advisory. Surface, halt, wait.
472
+ - **Never `--no-verify`, `--assume-ack` autonomously, force-push, or `git reset --hard`.** Every one of these requires explicit per-action human approval.
473
+ - **Verify, don't trust agent self-reports.** A Developer claiming `STATUS=done` is not done — QA verifies. A `QA: PASS` is not approved-to-merge until reports exist and merge prerequisites pass.
@@ -17,6 +17,25 @@
17
17
  # typecheck: "npm run typecheck"
18
18
  # lint: "npm run lint"
19
19
 
20
+ # Node + vitest, AI-orchestrator-friendly (caps worker pool RAM):
21
+ # Vitest defaults to one tinypool worker per CPU. With 3+ parallel agents during
22
+ # sprint waves (developer/QA), workers stack: 9 cores × 3 agents × ~400MB heap
23
+ # = ~10GB peak RAM. Cap the pool by editing vitest.config.ts directly (CLI
24
+ # overrides like `--pool-options.forks.maxForks=N` collide with tinypool's
25
+ # minThreads/maxThreads validation when pool=forks):
26
+ #
27
+ # // vitest.config.ts
28
+ # import { defineConfig } from 'vitest/config';
29
+ # const maxForks = Number(process.env.VITEST_MAX_FORKS ?? 2);
30
+ # export default defineConfig({
31
+ # test: {
32
+ # pool: 'forks',
33
+ # poolOptions: { forks: { minForks: 1, maxForks } },
34
+ # },
35
+ # });
36
+ #
37
+ # CI pipelines with plentiful RAM should set VITEST_MAX_FORKS=<cpu-count>.
38
+
20
39
  # Go example:
21
40
  # gates:
22
41
  # precommit: "go vet ./... && go test ./..."