cohorte 3.0.0-dev.8 → 3.1.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 (251) hide show
  1. package/CHANGELOG.md +1637 -0
  2. package/README.md +322 -62
  3. package/bin/cli.js +213 -0
  4. package/bin/report.js +141 -0
  5. package/core/agents/cohorte-profile-reader.md +40 -0
  6. package/core/agents/cohorte-release.md +61 -0
  7. package/core/agents/cohorte-review.md +200 -0
  8. package/core/agents/implementer.template.md +154 -0
  9. package/core/commands/cohorte-align-ds.md +33 -0
  10. package/core/commands/cohorte-audit.md +74 -0
  11. package/core/commands/cohorte-brainstorm.md +73 -0
  12. package/core/commands/cohorte-build.md +248 -0
  13. package/core/commands/cohorte-doctor.md +135 -0
  14. package/core/commands/cohorte-fix.md +80 -0
  15. package/core/commands/cohorte-fleet.md +111 -0
  16. package/core/commands/cohorte-init-pipeline.md +30 -0
  17. package/core/commands/cohorte-intake.md +92 -0
  18. package/core/commands/cohorte-patch.md +118 -0
  19. package/core/commands/cohorte-refactor.md +122 -0
  20. package/core/commands/cohorte-retro.md +85 -0
  21. package/core/commands/cohorte-revert.md +104 -0
  22. package/core/commands/cohorte-review.md +239 -0
  23. package/core/commands/cohorte-ship.md +167 -0
  24. package/core/commands/cohorte-spec.md +114 -0
  25. package/core/commands/cohorte-update-pipeline.md +119 -0
  26. package/core/commands/cohorte-verify.md +106 -0
  27. package/core/hooks/gate.py +3236 -0
  28. package/core/templates/agent-handoff.md +34 -0
  29. package/core/templates/brainstorm-return.md +42 -0
  30. package/core/templates/decisions.template.md +42 -0
  31. package/core/templates/design-brief.md +37 -0
  32. package/core/templates/patch.template.md +95 -0
  33. package/core/templates/pr-body.md +25 -0
  34. package/core/templates/review-feedback.md +46 -0
  35. package/core/templates/spec.template.md +109 -0
  36. package/core/templates/steps/init-pipeline/01-detect-stack.md +53 -0
  37. package/core/templates/steps/init-pipeline/02-interview-gaps.md +78 -0
  38. package/core/templates/steps/init-pipeline/03-draft-profile.md +10 -0
  39. package/core/templates/steps/init-pipeline/04-write-render.md +95 -0
  40. package/core/templates/steps/init-pipeline/05-report.md +11 -0
  41. package/core/templates/steps/review-pr/01-pr-mode.md +54 -0
  42. package/core/workflows/audit.js +311 -0
  43. package/core/workflows/loop.js +692 -0
  44. package/core/workflows/refactor.js +398 -0
  45. package/core/workflows/review.js +505 -0
  46. package/install.ps1 +72 -0
  47. package/install.sh +69 -0
  48. package/lib/doctor.js +506 -0
  49. package/lib/install.js +386 -0
  50. package/lib/project.js +359 -0
  51. package/lib/render.js +121 -0
  52. package/lib/versions.js +145 -0
  53. package/lib/yaml.js +183 -0
  54. package/package.json +36 -17
  55. package/profile/PIPELINE.template.md +288 -0
  56. package/profile/SCHEMA.md +30 -0
  57. package/profile/cohorte.config.template.yaml +43 -0
  58. package/profile/schema/dead-agents.md +29 -0
  59. package/profile/schema/decisions.md +23 -0
  60. package/profile/schema/deferred.md +22 -0
  61. package/profile/schema/feature-diff.md +20 -0
  62. package/profile/schema/kanban.md +95 -0
  63. package/profile/schema/metrics.md +23 -0
  64. package/profile/schema/output-discipline.md +21 -0
  65. package/profile/schema/preflight.md +81 -0
  66. package/profile/schema/profile-block.md +103 -0
  67. package/profile/schema/project-kinds.md +89 -0
  68. package/profile/schema/readiness.md +17 -0
  69. package/profile/schema/reconcile.md +64 -0
  70. package/profile/schema/release-notes.md +29 -0
  71. package/profile/schema/rendering.md +48 -0
  72. package/profile/schema/retrieval.md +58 -0
  73. package/profile/schema/spec-status.md +79 -0
  74. package/profile/schema/specialization.md +41 -0
  75. package/profile/schema/verify.md +115 -0
  76. package/profile/schema/workflows.md +78 -0
  77. package/scripts/feature-diff.sh +118 -0
  78. package/scripts/kanban-move.sh +349 -0
  79. package/scripts/metrics/collect.mjs +542 -0
  80. package/scripts/metrics/prices.json +42 -0
  81. package/scripts/new-feature.sh.template +122 -0
  82. package/scripts/preflight.sh +114 -0
  83. package/scripts/remove-feature.sh.template +56 -0
  84. package/scripts/verify-run.sh +509 -0
  85. package/assets/manifest.json +0 -203
  86. package/assets/migrations/config/README.md +0 -12
  87. package/assets/migrations/state/0001_init.sql +0 -154
  88. package/assets/prompts/README.md +0 -11
  89. package/assets/prompts/agents/brainstormer.md +0 -3
  90. package/assets/prompts/agents/fixer.md +0 -7
  91. package/assets/prompts/agents/implementer.md +0 -12
  92. package/assets/prompts/agents/reviewer.md +0 -8
  93. package/assets/prompts/agents/security-reviewer.md +0 -7
  94. package/assets/prompts/agents/spec-author.md +0 -3
  95. package/assets/prompts/phases/build.md +0 -5
  96. package/assets/prompts/phases/review.md +0 -5
  97. package/assets/prompts/phases/test.md +0 -5
  98. package/assets/prompts/system.md +0 -11
  99. package/assets/schemas/agent-output.schema.json +0 -225
  100. package/assets/schemas/auth-status.schema.json +0 -87
  101. package/assets/schemas/command-result.schema.json +0 -192
  102. package/assets/schemas/commands.schema.json +0 -959
  103. package/assets/schemas/config.schema.json +0 -2281
  104. package/assets/schemas/doctor-report.schema.json +0 -104
  105. package/assets/schemas/events.schema.json +0 -8514
  106. package/assets/schemas/fake-script.schema.json +0 -549
  107. package/assets/schemas/inspect.schema.json +0 -3133
  108. package/assets/schemas/manifest.schema.json +0 -79
  109. package/assets/schemas/ownership.schema.json +0 -52
  110. package/assets/schemas/policy-verdict.schema.json +0 -282
  111. package/assets/schemas/project-model.schema.json +0 -783
  112. package/assets/schemas/project-status.schema.json +0 -217
  113. package/assets/schemas/reconcile-plan.schema.json +0 -154
  114. package/assets/schemas/run-diff.schema.json +0 -177
  115. package/assets/schemas/run-snapshot-manifest.schema.json +0 -2104
  116. package/assets/schemas/run-state.schema.json +0 -1755
  117. package/assets/schemas/runtime-capabilities.schema.json +0 -1545
  118. package/assets/schemas/sandbox-capabilities.schema.json +0 -116
  119. package/assets/schemas/skill.schema.json +0 -87
  120. package/assets/schemas/spec.schema.json +0 -202
  121. package/assets/schemas/tool-catalogue.schema.json +0 -655
  122. package/assets/schemas/trust-record.schema.json +0 -38
  123. package/assets/skills/README.md +0 -9
  124. package/assets/skills/inspect-surface.md +0 -4
  125. package/dist/agent-host.mjs +0 -2187
  126. package/dist/agent-host.mjs.map +0 -1
  127. package/dist/bundle-manifest.json +0 -128
  128. package/dist/chunks/__host-DgGPyco9.mjs +0 -18
  129. package/dist/chunks/__host-DgGPyco9.mjs.map +0 -1
  130. package/dist/chunks/align-ds-r_X_1aQ_.mjs +0 -93
  131. package/dist/chunks/align-ds-r_X_1aQ_.mjs.map +0 -1
  132. package/dist/chunks/approve-Cv135UqI.mjs +0 -19
  133. package/dist/chunks/approve-Cv135UqI.mjs.map +0 -1
  134. package/dist/chunks/audit-B4ZWQ_DI.mjs +0 -179
  135. package/dist/chunks/audit-B4ZWQ_DI.mjs.map +0 -1
  136. package/dist/chunks/auth-BT5oVp76.mjs +0 -132
  137. package/dist/chunks/auth-BT5oVp76.mjs.map +0 -1
  138. package/dist/chunks/auth-Dnlksuo5.mjs +0 -141
  139. package/dist/chunks/auth-Dnlksuo5.mjs.map +0 -1
  140. package/dist/chunks/brainstorm-SJwOIEif.mjs +0 -123
  141. package/dist/chunks/brainstorm-SJwOIEif.mjs.map +0 -1
  142. package/dist/chunks/build-C_-mbZfD.mjs +0 -19
  143. package/dist/chunks/build-C_-mbZfD.mjs.map +0 -1
  144. package/dist/chunks/cancel-KV_cpsqS.mjs +0 -15
  145. package/dist/chunks/cancel-KV_cpsqS.mjs.map +0 -1
  146. package/dist/chunks/canonical-C8UxeEmB.mjs +0 -57
  147. package/dist/chunks/canonical-C8UxeEmB.mjs.map +0 -1
  148. package/dist/chunks/catalogue-IaCJdfB8.mjs +0 -1549
  149. package/dist/chunks/catalogue-IaCJdfB8.mjs.map +0 -1
  150. package/dist/chunks/compose-DRKjQcn0.mjs +0 -7333
  151. package/dist/chunks/compose-DRKjQcn0.mjs.map +0 -1
  152. package/dist/chunks/config-Cqu5XQoP.mjs +0 -96
  153. package/dist/chunks/config-Cqu5XQoP.mjs.map +0 -1
  154. package/dist/chunks/contract-DjssDPpS.mjs +0 -335
  155. package/dist/chunks/contract-DjssDPpS.mjs.map +0 -1
  156. package/dist/chunks/contract-bQ9FJl4N.mjs +0 -123
  157. package/dist/chunks/contract-bQ9FJl4N.mjs.map +0 -1
  158. package/dist/chunks/deny-ClTxSvHJ.mjs +0 -15
  159. package/dist/chunks/deny-ClTxSvHJ.mjs.map +0 -1
  160. package/dist/chunks/diff-Qw0II0sj.mjs +0 -101
  161. package/dist/chunks/diff-Qw0II0sj.mjs.map +0 -1
  162. package/dist/chunks/discover-BZPolSZG.mjs +0 -21
  163. package/dist/chunks/discover-BZPolSZG.mjs.map +0 -1
  164. package/dist/chunks/doctor-DcDFPvQM.mjs +0 -222
  165. package/dist/chunks/doctor-DcDFPvQM.mjs.map +0 -1
  166. package/dist/chunks/fix-C9roGiQz.mjs +0 -82
  167. package/dist/chunks/fix-C9roGiQz.mjs.map +0 -1
  168. package/dist/chunks/fleet-yWHQY2ya.mjs +0 -297
  169. package/dist/chunks/fleet-yWHQY2ya.mjs.map +0 -1
  170. package/dist/chunks/gc-BBXlBF5w.mjs +0 -161
  171. package/dist/chunks/gc-BBXlBF5w.mjs.map +0 -1
  172. package/dist/chunks/init--FxxkrcT.mjs +0 -63
  173. package/dist/chunks/init--FxxkrcT.mjs.map +0 -1
  174. package/dist/chunks/inspect-Buby4cQD.mjs +0 -22
  175. package/dist/chunks/inspect-Buby4cQD.mjs.map +0 -1
  176. package/dist/chunks/intake-C1pesxCJ.mjs +0 -12
  177. package/dist/chunks/intake-C1pesxCJ.mjs.map +0 -1
  178. package/dist/chunks/logs-Giq5sUau.mjs +0 -25
  179. package/dist/chunks/logs-Giq5sUau.mjs.map +0 -1
  180. package/dist/chunks/loop-BWsUpyus.mjs +0 -212
  181. package/dist/chunks/loop-BWsUpyus.mjs.map +0 -1
  182. package/dist/chunks/migrate-DuYCAbE3.mjs +0 -33
  183. package/dist/chunks/migrate-DuYCAbE3.mjs.map +0 -1
  184. package/dist/chunks/models-Btp6X2YZ.mjs +0 -24
  185. package/dist/chunks/models-Btp6X2YZ.mjs.map +0 -1
  186. package/dist/chunks/obsidian-BHLkXx_H.mjs +0 -235
  187. package/dist/chunks/obsidian-BHLkXx_H.mjs.map +0 -1
  188. package/dist/chunks/patch-sAgVqjpx.mjs +0 -50
  189. package/dist/chunks/patch-sAgVqjpx.mjs.map +0 -1
  190. package/dist/chunks/pause-BASBfKLO.mjs +0 -16
  191. package/dist/chunks/pause-BASBfKLO.mjs.map +0 -1
  192. package/dist/chunks/policy-Du7WVBFX.mjs +0 -139
  193. package/dist/chunks/policy-Du7WVBFX.mjs.map +0 -1
  194. package/dist/chunks/providers-Dx78imKj.mjs +0 -19
  195. package/dist/chunks/providers-Dx78imKj.mjs.map +0 -1
  196. package/dist/chunks/reconcile-BHn66X3C.mjs +0 -50
  197. package/dist/chunks/reconcile-BHn66X3C.mjs.map +0 -1
  198. package/dist/chunks/refactor-DV3RfGjk.mjs +0 -153
  199. package/dist/chunks/refactor-DV3RfGjk.mjs.map +0 -1
  200. package/dist/chunks/render-DyZr5Lgi.mjs +0 -53
  201. package/dist/chunks/render-DyZr5Lgi.mjs.map +0 -1
  202. package/dist/chunks/resume-GJQRb2Eb.mjs +0 -15
  203. package/dist/chunks/resume-GJQRb2Eb.mjs.map +0 -1
  204. package/dist/chunks/retro-Dr-2RTNN.mjs +0 -78
  205. package/dist/chunks/retro-Dr-2RTNN.mjs.map +0 -1
  206. package/dist/chunks/retry-CLrUem1H.mjs +0 -15
  207. package/dist/chunks/retry-CLrUem1H.mjs.map +0 -1
  208. package/dist/chunks/review-ZsBqp3vZ.mjs +0 -35
  209. package/dist/chunks/review-ZsBqp3vZ.mjs.map +0 -1
  210. package/dist/chunks/run-BGabwbDL.mjs +0 -109
  211. package/dist/chunks/run-BGabwbDL.mjs.map +0 -1
  212. package/dist/chunks/run-tool-C3rAv4XF.mjs +0 -26
  213. package/dist/chunks/run-tool-C3rAv4XF.mjs.map +0 -1
  214. package/dist/chunks/scan-C5uDr7Yq.mjs +0 -167
  215. package/dist/chunks/scan-C5uDr7Yq.mjs.map +0 -1
  216. package/dist/chunks/schema-Bq9qtgsd.mjs +0 -583
  217. package/dist/chunks/schema-Bq9qtgsd.mjs.map +0 -1
  218. package/dist/chunks/send-BdnJ85Nz.mjs +0 -19
  219. package/dist/chunks/send-BdnJ85Nz.mjs.map +0 -1
  220. package/dist/chunks/ship-BizfUe62.mjs +0 -140
  221. package/dist/chunks/ship-BizfUe62.mjs.map +0 -1
  222. package/dist/chunks/shutdown-BM92Iyv2.mjs +0 -15
  223. package/dist/chunks/shutdown-BM92Iyv2.mjs.map +0 -1
  224. package/dist/chunks/skip-DZG5kpcH.mjs +0 -18
  225. package/dist/chunks/skip-DZG5kpcH.mjs.map +0 -1
  226. package/dist/chunks/spec-C2h3U64g.mjs +0 -65
  227. package/dist/chunks/spec-C2h3U64g.mjs.map +0 -1
  228. package/dist/chunks/spec-path-tptqR7W8.mjs +0 -10
  229. package/dist/chunks/spec-path-tptqR7W8.mjs.map +0 -1
  230. package/dist/chunks/src-Bfr1yzsn.mjs +0 -1689
  231. package/dist/chunks/src-Bfr1yzsn.mjs.map +0 -1
  232. package/dist/chunks/src-CPW2_Ons.mjs +0 -5487
  233. package/dist/chunks/src-CPW2_Ons.mjs.map +0 -1
  234. package/dist/chunks/src-Cu3TxNob.mjs +0 -783
  235. package/dist/chunks/src-Cu3TxNob.mjs.map +0 -1
  236. package/dist/chunks/src-DNsLSxgm.mjs +0 -928
  237. package/dist/chunks/src-DNsLSxgm.mjs.map +0 -1
  238. package/dist/chunks/src-DbS9gkJy.mjs +0 -117
  239. package/dist/chunks/src-DbS9gkJy.mjs.map +0 -1
  240. package/dist/chunks/src-yi5whv3n.mjs +0 -2118
  241. package/dist/chunks/src-yi5whv3n.mjs.map +0 -1
  242. package/dist/chunks/status-SMjiOMYy.mjs +0 -29
  243. package/dist/chunks/status-SMjiOMYy.mjs.map +0 -1
  244. package/dist/chunks/tail-BuhT-2PH.mjs +0 -25
  245. package/dist/chunks/tail-BuhT-2PH.mjs.map +0 -1
  246. package/dist/chunks/update-BXIppsbi.mjs +0 -16
  247. package/dist/chunks/update-BXIppsbi.mjs.map +0 -1
  248. package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs +0 -56
  249. package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs.map +0 -1
  250. package/dist/cli.mjs +0 -186
  251. package/dist/cli.mjs.map +0 -1
@@ -0,0 +1,122 @@
1
+ ---
2
+ model: sonnet
3
+ description: Apply the refactor backlog for one or more domains via the surface implementer agents (TDD-first, parallel across independent surfaces), re-verify, then freeze a refactor spec for /cohorte-review → /cohorte-ship.
4
+ argument-hint: <domain…> (one or more surface keys, "shared", or "all")
5
+ ---
6
+
7
+ You are the **lead**. Refactor domain **$ARGUMENTS** to match `PIPELINE.md`, using the `/cohorte-audit` backlog.
8
+
9
+ > Read `PIPELINE.md` §`surfaces` (map the domain → a surface + its agent + commands), §`contract`
10
+ > and §`vcs` (§4's branch).
11
+ >
12
+ > **Kanban** (`<core>/pipeline/schema/kanban.md`): §4 runs
13
+ > `<core>/pipeline/scripts/kanban-move.sh auto <spec id> ready --title "[refactor] <domains>"`. `auto`
14
+ > resolves the board from the config itself and exits 0 with a `kanban: <reason>` line when there is
15
+ > none — so **never decide "no board is configured" without running it**.
16
+ >
17
+ > **Workflow variant** (opt-in — `<core>/pipeline/schema/workflows.md`): for BIG domains (many open backlog items
18
+ > across several surfaces), on Claude Code ≥ 2.1.154 with workflows enabled, the human can ask to
19
+ > "run the refactor workflow" (`<core>/workflows/refactor.js`). For a handful of items this
20
+ > conversational path is cheaper — and it stays the default and the fallback.
21
+
22
+ ## 1. Gather
23
+
24
+ - Read `specs/refactor-backlog.md`; select the **open** (`- [ ]`) items for `$ARGUMENTS` (`all` =
25
+ every domain with open items). A ticked line carrying `· refactor:<id>` is done and in flight in
26
+ that spec — never re-dispatch it.
27
+ - Map each domain to a surface. `shared` = the contract package (`contract.path`), owned by you/lead —
28
+ refactor it directly, don't dispatch.
29
+
30
+ ## 2. Dispatch the surface's implementer agent — TDD-first, stateless
31
+
32
+ Spawn the matching `<surface.agent>` with the template below (as `subagent_type: <surface.agent>`).
33
+ Keep it **byte-identical across loop
34
+ rounds** (only the final items slot varies — it sits at the end so repeats hit the prompt cache), and
35
+ never paste a diff — the agent computes its own, scoped to its tree:
36
+
37
+ > "Refactor pass on your surface (no feature spec). Read
38
+ > `PIPELINE.md` first. **Add the missing tests FIRST** (pin current behavior / cover the entry
39
+ > points), watch them pass, **then** refactor to clear each item. Preserve current public behavior
40
+ > unless an item marks it a bug. Migrations stay additive. Need the current state of your tree?
41
+ > Compute it yourself: `<core>/pipeline/scripts/feature-diff.sh --default <default_branch> --patch -- <surface.path>`. Lint + format before handoff;
42
+ > return the handoff in the format your agent instructions define. Backlog items for YOUR surface
43
+ > (self-contained — clear exactly these, reading only the files they name): <the domain's open
44
+ > `- [ ]` lines verbatim, with exact file paths>."
45
+
46
+ **Parallel when domains are independent:** if the human passed several domains (or `all`), dispatch
47
+ their implementers **concurrently in a single message** — surface trees are disjoint by construction,
48
+ so parallel is safe. Exception: `shared` (the contract package) never joins a parallel batch — the
49
+ slices import it, so refactor it alone, first.
50
+
51
+ - **Preserve current public behavior** unless a finding marks it a bug/convention violation — existing
52
+ code has no contract spec, so don't silently change shapes.
53
+ - Migrations stay **additive**; never `PIPELINE.md` §`gate.deny` commands.
54
+ - Touch only its surface; lint + format before handoff.
55
+
56
+ ## 3. Verify & loop
57
+
58
+ After each agent returns: its surface's `test_quiet_cmd`/`lint_quiet_cmd` (else the `tail -40`
59
+ fallback — `<core>/pipeline/schema/output-discipline.md`), `commands.typecheck`, `commands.format --check` (redirect
60
+ output to a file and grep it — don't print gate output into your context). Then verify each backlog item cleared by checking its `file:line` directly — do NOT re-run
61
+ `/cohorte-audit` per round (that repeats the repo-wide gates + a review dispatch you don't need); one optional
62
+ final `/cohorte-audit` once ALL dispatched domains are clean is enough. Check cleared items off in
63
+ `specs/refactor-backlog.md` (`- [ ]` → `- [x]`) as they verify — whatever happens next. Loop until
64
+ each dispatched domain is clean. Verification is per-domain even when the dispatch was parallel — one failing surface loops
65
+ alone, the others don't redo work.
66
+
67
+ ## 4. Deliver — freeze a `kind: refactor` spec, then review → ship
68
+
69
+ The round is code in the working tree with no route to a PR: `/cohorte-ship` ships a spec. So once
70
+ the gates are green and ≥ 1 item cleared (red gates ⇒ no spec — `/cohorte-review`'s preflight would
71
+ abort it anyway), write **one spec for the whole round** — review's diff, the freshness digest and
72
+ the release commit all cover the whole tree, so per-domain specs would each claim the others' code.
73
+
74
+ - **One open refactor spec per branch.** Already on `<feature_branch_prefix>refactor-…` with that
75
+ spec unshipped (`status: frozen`/`in-review`) ⇒ append this round's items to its §6 (new
76
+ `### <domain>` as needed) and skip to linking the ticks — whatever the domains.
77
+ - **Id** otherwise `refactor-<domains>-<YYYY-MM-DD>` (`date +%F`): `<domains>` = the cleared domains'
78
+ keys lowercased, every run of non-`[a-z0-9]` turned into `-`, joined by `-` — or `all` past three.
79
+ A spec of that id already shipped ⇒ suffix `-2`, `-3`…
80
+ - **Branch** — `/cohorte-ship` refuses any branch but `<vcs.feature_branch_prefix><id>`: on
81
+ `<default_branch>`, `git switch -c <prefix><id>` (uncommitted work carries over); already on it ⇒
82
+ fine; on some other branch ⇒ say which and ask.
83
+ - **Write `specs/<id>.md`** — create it, don't ask the human to. No §5: there is no contract, and the
84
+ numbers `/cohorte-review` and `/cohorte-ship` read (§1/§2, §9, `## Remediation`) are kept:
85
+
86
+ ```
87
+ ---
88
+ feature_id: <id>
89
+ kind: refactor # behaviour-preserving backlog pass — no contract; commit as refactor(<scope>)
90
+ title: Refactor <domains> — <n> backlog items
91
+ status: frozen
92
+ branch: <feature_branch_prefix><id>
93
+ created: <YYYY-MM-DD>
94
+ reviewed_base:
95
+ reviewed_digest:
96
+ ---
97
+ # Refactor <domains> — <n> backlog items
98
+ ## 1. Goal
99
+ Clear <n> `specs/refactor-backlog.md` items on <domains> with no change of public behaviour.
100
+ ## 2. Scope
101
+ **In:** the §6 items, verbatim. **Out:** any behaviour change; the items §7 lists.
102
+ ## 6. Surface tasks
103
+ ### <domain>
104
+ - <cleared item, `- [ ] ` prefix dropped>
105
+ ## 7. Out of scope
106
+ - <items still open in the backlog for these domains — not claimed by this spec> (or `none`)
107
+ ## 9. Acceptance criteria / DoD
108
+ - [ ] Public behaviour preserved — no exported signature, route, response shape, CLI flag or persisted format changed (unless an item marks it a bug)
109
+ - [ ] Each §6 item cleared at its file:line
110
+ - [ ] All tests green — behaviour pinned by tests added first; no existing test loosened
111
+ - [ ] `PIPELINE.md` commands.lint · typecheck · test green
112
+ - [ ] Nothing outside §6's surfaces changed
113
+ ## Remediation
114
+ ```
115
+
116
+ - **Link the ticks** — append ` · refactor:<id>` to each line §3 ticked this round, so the backlog
117
+ says where the item went (and `/cohorte-audit` keeps it until that spec merges).
118
+ - `grep -q '^kind: refactor' specs/<id>.md` (the postcondition), then the kanban move above, in the
119
+ same Bash call — report what it printed: `moved #…` or `kanban: <reason>`, never a guess.
120
+ - **Hand off:** `/cohorte-review <id>` → (`/cohorte-fix <id>` → `/cohorte-review <id>`)* →
121
+ `/cohorte-ship <id>` — **recommend a `/clear` first**. Never `/cohorte-build` it, nor the loop
122
+ workflow: both treat any non-patch spec as contract-bearing.
@@ -0,0 +1,85 @@
1
+ ---
2
+ description: Mine the accumulated review findings across features for repeating patterns, and turn the ones the human ratifies into PIPELINE.md §Conventions rules the next build already follows.
3
+ argument-hint: [last <n> | all] (default: every feature with a report on disk)
4
+ ---
5
+
6
+ You are running the **retrospective**. Every review this pipeline has run left structured
7
+ residue on disk — verdicts, Remediation rounds, deferred backlog items. A finding that shows up
8
+ once is a bug; the same finding shape across features is a **missing rule**, and the pipeline
9
+ has a place for rules the implementers actually read: `PIPELINE.md` §Conventions, baked into
10
+ each surface agent at render time. This command closes that loop: findings → patterns →
11
+ ratified rules → re-rendered agents. The next build then never produces the finding again —
12
+ which is cheaper than any number of review rounds catching it.
13
+
14
+ > Read `PIPELINE.md` §`pipeline-profile` (`surfaces`, and skim the existing §Conventions
15
+ > stanzas — a rule that already exists is a finding about *enforcement*, not a missing rule)
16
+ > and `specs/_decisions.md` §Live. _Skip the re-read if already in context and unmodified._
17
+
18
+ ## 1. Collect — mechanical, redirected, no judgment yet
19
+
20
+ Scope: `all` (default), or `last <n>` features by spec mtime. In as few Bash calls as possible,
21
+ **always redirected to `specs/reports/retro-scan.txt` and grepped — never into your context**:
22
+
23
+ - `specs/reports/*.verdict.json` — per feature: `blocking_items` (normalized identities),
24
+ `severity`, per-surface counts. The freshest machine record, one per feature.
25
+ - Every non-`_` spec's `## Remediation` section — the **persistent** history (verdict.json is
26
+ overwritten per round; Remediation accumulates, and collapsed rounds still carry their
27
+ count line). Grep the item lines: `- [x?] <SEVERITY> · <file:line> · <kind> · <fix>`.
28
+ - `specs/refactor-backlog.md` — the `deferred:<id>` tagged items: debt reviews kept finding
29
+ but no feature owned.
30
+
31
+ A repo with fewer than two features' worth of residue ⇒ say the retro has nothing statistical
32
+ to stand on yet, name what exists, and stop — one feature's findings are that feature's story,
33
+ not a pattern.
34
+
35
+ ## 2. Patterns — what repeats, with the evidence attached
36
+
37
+ A **pattern** is a finding shape that recurs where recurrence means something:
38
+
39
+ - same `kind` × same surface across **≥ 2 features** (e.g. `security` findings on `backend`
40
+ twice running — the strongest signal there is);
41
+ - the same file/module named by findings from **≥ 2 features** (a hotspot no single fix loop
42
+ owns);
43
+ - the same *fix wording* family recurring (e.g. three "add the authz check" fixes = one
44
+ missing authorization convention);
45
+ - a `deferred:` cluster in one domain — debt the reviews keep re-discovering because no rule
46
+ makes the implementers avoid adding to it.
47
+
48
+ For each pattern, produce: the evidence lines **verbatim** (`<feature> · <severity> · <file> ·
49
+ <problem/fix>`), the count, and ONE drafted convention rule — **rule-shaped**: a sentence an
50
+ implementer can follow and a reviewer can test a diff against, placed under `### Shared` or the
51
+ owning `### Surface: <key>`. Not advice ("be careful with auth") — a rule ("every route under
52
+ `apps/api/src/routes/` calls `authorize()` before its handler; no exceptions without a spec
53
+ §5 note"). Skip any pattern the existing §Conventions already covers — report those separately
54
+ as **enforcement gaps** (the rule exists and reviews keep finding violations: that is input for
55
+ the human, not a new rule).
56
+
57
+ ## 3. Ratify — the human picks; nothing lands without them
58
+
59
+ Present a compact table: pattern → evidence count → drafted rule → target stanza. Then **stop
60
+ and ask** which to adopt (all / some / none — none is a fine outcome and says the rulebook fits
61
+ the codebase). Rules are standing law every future dispatch pays tokens to carry: the human
62
+ decides what becomes law, exactly as they freeze specs.
63
+
64
+ ## 4. Apply — and keep the baked slices honest
65
+
66
+ For each adopted rule, in this order:
67
+
68
+ 1. Append it to `PIPELINE.md` §Conventions under its stanza (create the `### Surface: <key>`
69
+ stanza if absent; keep it rule-shaped, one line each).
70
+ 2. **Re-render every affected surface agent** per `<core>/pipeline/schema/rendering.md` step 2 — the
71
+ `<SURFACE_CONVENTIONS>` slice is **baked at render time**, so a §Conventions edit without a
72
+ re-render produces the worst outcome available: reviewers (who read the prose live) enforce
73
+ a rule implementers (who carry the stale bake) have never seen, and every future review
74
+ round re-finds the pattern this retro just paid to close. If you cannot re-render on this
75
+ runtime, say so and route to `/cohorte-update-pipeline` (its reconcile step 2 re-renders) —
76
+ but then the rule is **pending**, and you say that too.
77
+ 3. Append ONE line per adopted rule to `specs/_decisions.md` §Live (`<core>/pipeline/schema/decisions.md`):
78
+ `- <date> · conventions · <rule, compressed> — because <kind>×<n> across <features> · retro`.
79
+ A retro rule is a standing decision; the journal is where the next `/cohorte-spec` learns it
80
+ without re-mining the reports.
81
+
82
+ In chat print ONLY: patterns found / adopted / skipped (one line each), enforcement gaps, which
83
+ agents were re-rendered (or the pending route), and the decisions lines appended. The evidence
84
+ stays in `specs/reports/retro-scan.txt`. **Recommend a `/clear`** — everything that matters is
85
+ now in `PIPELINE.md`, the rendered agents, and the journal.
@@ -0,0 +1,104 @@
1
+ ---
2
+ model: sonnet
3
+ description: Prepare the revert of a merged feature — a revert branch and PR, its down migration run only on a dev database. Never pushes to the default branch.
4
+ argument-hint: <feature_id>
5
+ ---
6
+
7
+ You are the **lead**. Prepare the revert of feature **$ARGUMENTS**. The output is a branch and a PR
8
+ that a human reviews and merges. Rules: `<core>/pipeline/schema/verify.md` (§Databases, §Revert).
9
+
10
+ > **Never push to the default branch, never force-push, never merge.** The revert lands the way
11
+ > every change does, through a PR, and the gate confirms git writes on the default branch anyway.
12
+ > **No kanban move.** The board has no revert column, so the card stays in Shipped. This command
13
+ > calls no `kanban-move.sh` on purpose.
14
+ > Never run a migration outside `<core>/pipeline/scripts/verify-run.sh`, never against a
15
+ > shared, staging or production database, and never edit an `.env` to reach one.
16
+
17
+ ## 1. What landed
18
+
19
+ - `grep -E '^(status|branch|pr|migrations|title):' specs/$ARGUMENTS.md`.
20
+ - `merged` ⇒ continue.
21
+ - `shipped` ⇒ check it the way `/cohorte-ship` §0 does (`gh pr view <branch> --json state`).
22
+ `MERGED` ⇒ continue, and leave the status line to `/cohorte-doctor`'s reconcile, because §2
23
+ needs a clean tree. `OPEN` ⇒ there is nothing to revert: the human closes the PR.
24
+ - Anything else ⇒ stop, because nothing merged.
25
+ - **Read `## Rollback` now and keep it.** The revert deletes the spec from the tree (the release
26
+ commit added it). `migrations: true` with an empty Rollback
27
+ (`<core>/pipeline/scripts/verify-run.sh rollback-check specs/$ARGUMENTS.md` exits 1) ⇒ stop and
28
+ have the human fill it. A migration nobody knows how to undo is not reverted blind.
29
+ - Find the PR: the spec's `pr:` if present, else
30
+ `gh pr list --state merged --head <branch> --json number,url,title,mergeCommit --limit 1`.
31
+ No `gh`, or not `vcs.host: github` ⇒ ask the human for the merge commit SHA.
32
+ - `git fetch origin <default_branch>`, then
33
+ `git merge-base --is-ancestor <sha> origin/<default_branch>`. If it is not an ancestor, stop.
34
+ - Work out how the PR merged: `git rev-list --parents -n 1 <sha>`.
35
+ - **Two parents** ⇒ a merge commit: `git revert -m 1`.
36
+ - **One parent** ⇒ compare `git diff-tree --no-commit-id --name-only -r <sha>` with
37
+ `gh pr view <num> --json files --jq '.files[].path'`. The same set ⇒ a squash: a plain
38
+ `git revert`.
39
+ - A different set ⇒ a rebase-merge, with several commits on the default branch. Show
40
+ `git log --oneline -<commits+1> <sha>` and have the human name the range. **Never guess it.**
41
+
42
+ ## 2. A branch off the default branch
43
+
44
+ `git status --porcelain` must be empty, otherwise stop.
45
+ - `isolation.enabled` ⇒ `scripts/new-feature.sh revert-$ARGUMENTS`. It creates its own worktree and
46
+ branch `<feature_branch_prefix>revert-$ARGUMENTS` off `origin/<default_branch>`, plus its own
47
+ database when `isolation.db_per_worktree` is set. Do the rest in that worktree.
48
+ - Otherwise ⇒ `git switch -c revert/$ARGUMENTS origin/<default_branch>`.
49
+
50
+ ## 3. The down migration, on a dev database, before the revert
51
+
52
+ Do this only when `migrations: true`. The down step runs **while the migration files still exist**,
53
+ since the revert deletes them. The step is Rollback's **Migration down** line. Fall back to
54
+ `commands.migrate_down` (or `commands.rollback`) only after the human confirms that this feature's
55
+ migrations are still the newest on the default branch. "Undo the last migration" otherwise undoes
56
+ a later feature's. Run one Bash call with the timeout at 600000 ms:
57
+
58
+ ```
59
+ <core>/pipeline/scripts/verify-run.sh run $ARGUMENTS --phase revert \
60
+ [--migrate "<commands.migrate>"] --migrate-down "<down step>" \
61
+ --db <verify.db, default local> --db-per-worktree <isolation.db_per_worktree, default false> \
62
+ --slots <isolation.registry, default .worktrees/slots.tsv>
63
+ ```
64
+
65
+ Pass `--migrate` when the database is fresh (an isolated worktree's), so that it first reaches the
66
+ default branch's schema. Route on the exit code:
67
+ - **4** ⇒ show the human the gate's list. On yes, re-run with `--confirmed`.
68
+ - **0** ⇒ the down step worked on dev.
69
+ - **1** ⇒ stop and relay `tail -40` of the `migrate-down` log. A down step that fails on dev will
70
+ fail in production, and the human decides what happens next.
71
+ - **3** ⇒ refused or denied: a shared DB, or the step is in `gate.deny`. Carry on, but the PR body
72
+ must say that the down step was **not** exercised.
73
+
74
+ The verdict is in `specs/reports/$ARGUMENTS.revert.json`.
75
+
76
+ ## 4. The revert commit
77
+
78
+ 1. Run `git revert --no-commit [-m 1] <sha>` (or the human's range).
79
+ 2. Keep the spec as history: `git checkout HEAD -- specs/$ARGUMENTS.md`, plus `specs/design/$ARGUMENTS.md`
80
+ if it exists. This also resolves the conflict a later `status: merged` commit causes.
81
+ 3. Any other conflict (`git diff --name-only --diff-filter=U`): a consumed release note is
82
+ `git rm`'d. For everything else, stop, list the files, and leave the tree to the human
83
+ (`git revert --abort` is theirs to run).
84
+ 4. Ask whether the spec becomes `status: abandoned` in this commit. It only says so if the revert
85
+ merges, and it is the human's call (`<core>/pipeline/schema/spec-status.md`).
86
+ 5. `release_notes.enabled` ⇒ write the note yourself per `<core>/pipeline/schema/release-notes.md`,
87
+ describing the removal for the user, and ask the human for the level.
88
+ 6. Commit with `revert: <title> (#<num>)` and the body `This reverts <sha> (PR #<num>).`
89
+
90
+ ## 5. Confirm, push the revert branch, open the PR
91
+
92
+ Show `git show --stat HEAD` and the down-step result, then **ask the human** to confirm the push.
93
+ On yes:
94
+ 1. `git push -u origin <the revert branch>` (never `<default_branch>`, never `--force`).
95
+ 2. `gh pr create --base <default_branch> --head <the revert branch> --title "revert: <title>"`.
96
+ The body has three parts:
97
+ - what is reverted, with a link to the original PR;
98
+ - `## Rollback` verbatim, because these are the steps the operator runs on production
99
+ **before or with** the deploy, in the order it gives;
100
+ - whether the down step was exercised on dev (from `revert.json`).
101
+ 3. No `gh` ⇒ print the compare URL and that body instead.
102
+
103
+ Report the branch, commit SHA, PR URL and down-step verdict. Once the revert PR merges, propose
104
+ `scripts/remove-feature.sh revert-$ARGUMENTS` when a worktree was made.
@@ -0,0 +1,239 @@
1
+ ---
2
+ model: sonnet
3
+ description: Dispatch the read-only review agent to audit the feature against its frozen spec.
4
+ argument-hint: <feature_id> | --pr <num>
5
+ ---
6
+
7
+ You are the **lead**. Dispatch the review for feature **$ARGUMENTS**.
8
+
9
+ > Read `PIPELINE.md` §`vcs.default_branch` (diff base) and the `surfaces`/`contract`/`commands` fields.
10
+ > _Skip the re-read if it's already in your context this session and unmodified since._
11
+ >
12
+ > **Kanban** (`<core>/pipeline/schema/kanban.md`): run
13
+ > `<core>/pipeline/scripts/kanban-move.sh auto $ARGUMENTS review`. `auto` resolves the board from the config itself and
14
+ > exits 0 with a `kanban: <reason>` line when there is none — so **never decide "no board is
15
+ > configured" without running it**. _(PR mode — `--pr` below — skips this entirely: an incoming
16
+ > PR is not a pipeline feature and has no card.)_
17
+ >
18
+ > **Workflow variant** (opt-in — `<core>/pipeline/schema/workflows.md`): on Claude Code ≥ 2.1.154 with workflows
19
+ > enabled, the human can ask to "run the review workflow" (`<core>/workflows/review.js`) instead.
20
+ > This conversational path stays the default and the fallback; `/cohorte-doctor` shows which is available.
21
+
22
+ ## PR mode (`--pr <num>` or a PR URL) — load its step file, only then
23
+
24
+ If `$ARGUMENTS` carries `--pr <num>` (or a GitHub PR URL), this is an **incoming** pull request, not
25
+ a pipeline feature: read `<core>/templates/steps/review-pr/01-pr-mode.md` and follow it **instead of**
26
+ §0–§3.5 below (it reuses §1's staging and §2/§3's dispatch and roll call, and says where). It decides
27
+ whether the PR's code may run on this machine before anything executes. No `--pr` ⇒ never read it.
28
+
29
+ Everything below this line is the normal pipeline-feature flow.
30
+
31
+ ## 0. Deterministic pre-flight — no agents while red
32
+
33
+ Run the profile's mechanical gates in ONE Bash call via the shipped script
34
+ (`<core>/pipeline/scripts/preflight.sh`); note the epoch (`date +%s`) in the same call — §3's
35
+ metrics line needs it:
36
+
37
+ ```
38
+ <core>/pipeline/scripts/preflight.sh specs/reports/$ARGUMENTS.preflight.txt \
39
+ "<commands.typecheck>" "<commands.lint_quiet, else lint>" "<commands.test_quiet, else test>" \
40
+ [": cohorte-security-scans" '<commands.security[0]>' '<commands.security[1]>' …]
41
+ ```
42
+
43
+ The bracketed tail is passed only when `commands.security` (a list, or one string) has entries.
44
+ The marker comes first, then each command in order. Drop empty and `<placeholder>` entries. Any
45
+ command containing `$`, a backtick or `\` is **single-quoted** (a `'` inside becomes `'\''`). In
46
+ double quotes this shell would expand the scan's own variables first. Scans are checks like the
47
+ others: a red one aborts below (`<core>/pipeline/schema/preflight.md` §Security scans).
48
+
49
+ - **Non-zero exit** ⇒ the script already printed the raw last-40 lines. **STOP: relay them verbatim
50
+ and spawn NO agent** — a compiler/test failure needs `/cohorte-fix` (or the human), not a review that
51
+ rediscovers it at agent prices. This abort is the whole point of the step. Before stopping, write
52
+ the **aborted verdict** (§3's contract, degraded form) so an automated driver gets a diagnosis
53
+ rather than silence:
54
+ `{"id":"$ARGUMENTS","phase":"review","ts":"<ISO>","aborted":"preflight","verdict":"BLOCK","blocking":null}`
55
+ → `specs/reports/$ARGUMENTS.verdict.json`. One `printf`, in the same Bash call.
56
+ - **Zero exit** ⇒ it stamped `<state>/preflight.ok`, which the gate hook checks before letting
57
+ `cohorte-review` dispatches through (`<core>/pipeline/schema/preflight.md`). Continue.
58
+ - Script absent (older core) ⇒ run the same commands yourself (marker and security scans
59
+ included), each appended to `specs/reports/$ARGUMENTS.preflight.txt` after a `$ <cmd>` line,
60
+ aborting on the first failure the same way.
61
+
62
+ ## 1. Gather the inputs for stateless reviewers
63
+
64
+ - Confirm `specs/$ARGUMENTS.md` exists. Front-matter **`kind: refactor`** (written by
65
+ `/cohorte-refactor` at the end of a round) ⇒ no contract: the reviewer checks behaviour
66
+ preservation, conventions and over-engineering against §6's backlog items instead of a contract
67
+ (its own check 1). Everything else below is unchanged.
68
+ - **Every diff comes from `<core>/pipeline/scripts/feature-diff.sh`, never a bare `git diff`**
69
+ (`<core>/pipeline/schema/feature-diff.md`): feature work is uncommitted until ship, and `git diff <ref>` drops
70
+ every untracked file and diffs against the branch tip, not the merge-base. Non-zero exit ⇒ **stop
71
+ and relay it** (exit 3 = base unresolvable); script absent ⇒ stop (`cohorte update`). Never fall
72
+ back to `git diff`.
73
+ - **List the changed paths ONCE, patches only for retained surfaces.** One call:
74
+ `<core>/pipeline/scripts/feature-diff.sh --default <default_branch> --numstat > specs/reports/$ARGUMENTS.stat.txt`
75
+ (`added<TAB>deleted<TAB>path`, full paths), then group the paths by `surfaces[].path` prefix with
76
+ one `awk` over that file — deterministic, never file by file. Paths under no surface (contract
77
+ file, root config) are the **`shared` remainder**: attach them to the most relevant surface's
78
+ reviewer and say so in its dispatch. A surface with no changed paths gets no reviewer and no
79
+ `.diff`. **An empty list is not a SHIP:** nothing was reviewed, so nothing is certified — write the
80
+ aborted verdict `{"id":"$ARGUMENTS","phase":"review","ts":"<ISO>","aborted":"empty-diff","verdict":"BLOCK","blocking":null}`
81
+ to `specs/reports/$ARGUMENTS.verdict.json` (it overwrites a stale one), say the diff is empty
82
+ (unbuilt feature? wrong branch?), and stop.
83
+ - **Stage the hunks once per touched surface** (reviewers have no Bash — the staged file is the
84
+ only way they read hunks instead of whole files). Regenerated every round:
85
+ `<core>/pipeline/scripts/feature-diff.sh --default <default_branch> --patch -- <surface.path> [<remainder paths>] > specs/reports/$ARGUMENTS.<surface.key>.diff`.
86
+ Never print a diff into your own context.
87
+
88
+ ## 2. Dispatch review agents — one per touched surface, IN PARALLEL
89
+
90
+ Spawn ONE `cohorte-review` agent per surface that has changed files, in a **single message** (one dispatch
91
+ each, like `/cohorte-build`) so they run concurrently — NEVER serially: review wall-clock must be the
92
+ slowest surface, not the sum. A diff touching a single surface ⇒ a single reviewer.
93
+
94
+ **Small-diff fast path (re-reviews only):** if a surface's staged diff is tiny (≤2 files and ≤~40
95
+ changed lines), touches no contract file, and every open finding it addresses is non-security
96
+ LOW/MEDIUM, skip the dispatch: verify the hunks yourself against the open Remediation items (did the
97
+ prescribed fixes land? — NOT a de-novo audit) and write the same REVIEW REPORT into the §3 flow.
98
+ First-round reviews, contract changes, and security findings always get a full reviewer. For each
99
+ reviewed surface:
100
+
101
+ Keep the dispatch prompt **byte-identical across features and rounds** except the variable block,
102
+ which sits at the END so every repeat hits the prompt-cache prefix:
103
+
104
+ > `subagent_type: cohorte-review` — "Review one feature surface against its frozen spec. Read `PIPELINE.md`
105
+ > first (flags + the §Conventions/§Testing slice for your scope). Check spec conformance first, then
106
+ > correctness, security, conventions, RBAC/mobile-first _if the profile enables them_, and TDD
107
+ > coverage. Your dispatch names a staged diff file — read it FIRST; open a full source file only when
108
+ > a finding demands it. Emit the REVIEW REPORT in the capped format your agent instructions define —
109
+ > every finding self-sufficient (`file:line` · severity · type · one-line concrete fix), no code
110
+ > excerpts. — Variable slots: feature `$ARGUMENTS` · scope: the `<surface.key>` surface only · spec:
111
+ > `specs/$ARGUMENTS.md` (source of truth) · contract: `<contract.path>/$ARGUMENTS.<ext>` (`none` on `kind: refactor`) · staged
112
+ > diff: `specs/reports/$ARGUMENTS.<surface.key>.diff` · changed files: <list>[ · preflight report:
113
+ > `specs/reports/$ARGUMENTS.preflight.txt` (security section from the line `$ : cohorte-security-scans`)]."
114
+
115
+ The bracketed preflight-report slot is added only when `commands.security` has entries.
116
+
117
+ ## 3. Merge & relay the verdict
118
+
119
+ **Roll call FIRST — a dead reviewer is not a clean surface** (`<core>/pipeline/schema/dead-agents.md`: its zero
120
+ findings are byte-identical to a clean surface's). Every surface dispatched in §2 must come back
121
+ with a REVIEW REPORT:
122
+
123
+ - **Retry a silent surface ONCE**, byte-identical dispatch. Most deaths are transient, and the staged
124
+ diff is already on disk — the retry costs one agent, not a re-review.
125
+ - **Silent twice ⇒ that surface is `unreviewed`.** Name it in the report under
126
+ `## NOT reviewed (no verdict on these)`, list it in the verdict JSON's `unreviewed`, and **refuse to
127
+ score `SHIP`** — the merged verdict is at least `REVISE`. Absence of evidence is not evidence of
128
+ absence, and it must never reach `/cohorte-ship` or tick a DoD box.
129
+ - **Never re-review the other surfaces** to compensate: their reports are valid and already on disk.
130
+
131
+ Then merge the returned reports into **one** REVIEW REPORT (same template): findings concatenated and
132
+ re-ordered by severity, counts summed, duplicates collapsed, and the verdict **recomputed from the
133
+ merged findings** by the one verdict rule (`cohorte-review` agent §Severity & verdict: any security ⇒
134
+ `BLOCK`, else any CRITICAL ⇒ `REVISE`, else `SHIP`; plus the roll call's "never `SHIP` with a surface
135
+ unreviewed") — never "the worst verdict a reviewer returned", which can disagree with the counts.
136
+ Each surface's verdict in the JSON is the same rule over that surface's findings. The `## Deferred` sections merge the same way (dedupe by
137
+ `file` + problem) and stay **out of the severity table and out of the verdict** — see §3.5, which
138
+ routes them. Append ONE metrics line for the batch to the **main checkout's**
139
+ `$(dirname "$(git rev-parse --git-common-dir)")/<state>/pipeline-metrics.jsonl` (rules in
140
+ `/cohorte-build` §4; never a bare relative path — from a worktree that strands the lines): `{"ts":"<ISO>","feature":"$ARGUMENTS","phase":"review","seconds":<wall-clock>,"surfaces":{"<key>":"<verdict>:<finding count>",…}}`.
141
+ **Stage the full report to `specs/reports/$ARGUMENTS.md`** (overwrite) — a gitignored buffer so a
142
+ `/cohorte-fix` after a `/clear` can still read the findings; the `specs/reports/` subfolder is skipped by the
143
+ non-recursive `specs/*.md` glob, so it's never mistaken for a spec (no phantom card, no bogus stage).
144
+ **Write the machine-readable verdict** to `specs/reports/$ARGUMENTS.verdict.json` (overwrite) — on
145
+ **every** run, including the small-diff fast path of §2 and a `SHIP`. This file is the ONLY contract
146
+ between the pipeline and any automated driver, which parses no prose:
147
+
148
+ ```json
149
+ { "id": "$ARGUMENTS", "phase": "review", "ts": "<ISO>", "verdict": "REVISE",
150
+ "findings": 7, "blocking": 2, "security": 1, "deferred": 3, "unreviewed": [],
151
+ "severity": {"CRITICAL": 1, "HIGH": 2, "MEDIUM": 3, "LOW": 1},
152
+ "surfaces": {"backend": {"verdict":"BLOCK","findings":4,"blocking":2}},
153
+ "blocking_items": ["backend|apps/api/src/routes/order.ts|missing authz on post"],
154
+ "fingerprint": "b3f1c2a90d4e5f67" }
155
+ ```
156
+
157
+ - **`blocking` = CRITICAL findings + `security` findings, deduplicated** (a finding that is both
158
+ counts once) — the verdict rule restated as a number, so with `unreviewed` empty,
159
+ `blocking == 0` ⟺ `verdict == SHIP`. HIGH/MEDIUM/LOW quality findings are **not** blocking and
160
+ never cost a driver an iteration — a *human* routes them (the table below); a driver ignores them.
161
+ - **`blocking_items`** — one normalized string per **distinct** blocking finding (deduplicated —
162
+ two findings sharing surface, file and problem head are one identity), `<surface>|<file>|<problem>`:
163
+ the file path **without the `:line`** (a fix that inserts lines shifts every line below it — a
164
+ line-bearing identity would change every pass and the drift detection would never fire), and the
165
+ **problem**, not the fix, cut to its first 8 words, lowercased, every run of non-alphanumerics
166
+ collapsed to one space. Identity of a finding, not its wording.
167
+ - **`fingerprint`** — computed in the same Bash call, never by hand:
168
+ `printf '%s\n' "<item>" … | LC_ALL=C sort | sha256sum | cut -c1-16` (`shasum -a 256` where there
169
+ is no `sha256sum`). Empty list ⇒ `""`. A driver comparing two consecutive fingerprints detects a
170
+ fix loop that is treading water.
171
+ - **`deferred`** — the count of merged `## Deferred` items §3.5 parked in the backlog. Informational:
172
+ it never enters `blocking`, so it can never cost a driver an iteration.
173
+ - **`unreviewed`** — the surface keys whose reviewer died twice, `[]` on a complete run. It is
174
+ **separate from `blocking` on purpose**: `blocking` counts real findings (CRITICAL + security), and
175
+ faking a number there to force a driver's hand would corrupt the one field the whole contract rests
176
+ on. A non-empty `unreviewed` means "this run does not cover everything" — a driver treats it as no
177
+ usable verdict, never as clean, whatever `blocking` says.
178
+
179
+ ## 3.5 Route the deferred findings — the backlog, not the fix loop
180
+
181
+ Do this on **every** run, before the verdict branch below, and whatever the verdict — a deferred
182
+ finding that is only routed on a `SHIP` is a deferred finding lost on every other verdict, which is
183
+ exactly the leak this step closes. Append each merged `## Deferred` item to
184
+ **`specs/refactor-backlog.md`**, under the `## <domain>` heading of the surface that owns its
185
+ `file:line` (create the file and/or heading if absent — same grouping `/cohorte-audit` writes, so
186
+ `/cohorte-refactor <domain>` picks them up with no extra plumbing):
187
+
188
+ ```
189
+ - [ ] <SEVERITY> · <file:line> · <quality|security|rule|complexity> · <concrete fix> · deferred:$ARGUMENTS
190
+ ```
191
+
192
+ - **Never into the spec's `## Remediation`** — that list is what `/cohorte-fix` re-dispatches, so a
193
+ deferred item there would re-trigger the very fix round it was deferred out of.
194
+ - **Dedupe before appending:** `grep -F` the backlog for the item's `<file>` + the first words of its
195
+ problem; already there (from a prior round or an `/cohorte-audit`) ⇒ skip it, don't stack duplicates round
196
+ after round.
197
+ - Write in ONE Bash call: insert each line directly under its `## <domain>` heading with one `awk`
198
+ pass (heading absent ⇒ append a new `## <domain>` block with `>>` — a bare `>>` lands under
199
+ whichever domain happens to be last). Never read the whole backlog into context to rewrite it.
200
+ - Report it as **one line** in chat: `deferred: <n> parked in specs/refactor-backlog.md (<domains>)`.
201
+
202
+ In chat print ONLY: the verdict, the severity-count table, a one-line digest of each CRITICAL/security
203
+ finding, and `Full report: specs/reports/$ARGUMENTS.md` — never echo the findings body into chat (it
204
+ would sit in this session's history, re-sent every turn). Then route on **the verdict and the worst
205
+ surviving severity** — exactly one row applies:
206
+
207
+ | verdict | worst surviving finding | DoD tick + freshness stamp | next |
208
+ | --- | --- | --- | --- |
209
+ | `REVISE` / `BLOCK` | any | no | `/cohorte-fix $ARGUMENTS` |
210
+ | `SHIP` | `HIGH` or `MEDIUM` | **no** — not a clean bill | `/cohorte-fix $ARGUMENTS`, or park MEDIUMs (below) |
211
+ | `SHIP` | `LOW` or none | **yes** — the clean bill | `/cohorte-ship $ARGUMENTS` |
212
+
213
+ (`SHIP` is only reachable with `unreviewed` empty — the roll call forbids it otherwise.)
214
+
215
+ - **`/cohorte-fix` route** — it appends the report to the spec's `## Remediation` and re-dispatches
216
+ ONLY the surfaces with findings. The full path (`/cohorte-spec` Mode B then `/cohorte-build`) remains
217
+ for findings that change the contract in ways that ripple into clean surfaces. The report is
218
+ staged, so you can `/clear` first — `/cohorte-fix` reads the findings back from disk.
219
+ - **Parking MEDIUMs** — only MEDIUMs the human *explicitly* chooses to live with (never a HIGH, never
220
+ CRITICAL/security): route each through §3.5 (the backlog, `deferred:$ARGUMENTS`), then **rewrite
221
+ `verdict.json` to match** — subtract them from `findings` and `severity.MEDIUM`, add them to
222
+ `deferred`, add `"parked": <n>` — so `/cohorte-ship`, which reads that file, sees what you decided.
223
+ Once nothing above LOW is left, apply the clean bill below.
224
+ - **The clean bill** (the pipeline certifying what ships — never written over a known HIGH/MEDIUM):
225
+ - **Tick the DoD**: in `specs/$ARGUMENTS.md` §`Acceptance criteria / DoD`, flip `- [ ]` → `- [x]`
226
+ for the criteria the pipeline actually verified — spec conformance + `ui_language` copy (this
227
+ review), tests · lint · typecheck (a green `/cohorte-build`), mobile-first as far as the code
228
+ shows it. On `kind: refactor`: behaviour preserved + items cleared (this review), tests · lint ·
229
+ typecheck green (§0's preflight — no `/cohorte-build` ran). **Leave `- [ ]` (and say which) any item no stage verified** — review never *runs* the
230
+ feature: a criterion tagged `· runtime` stays open for `/cohorte-verify` (which ticks it on a
231
+ passing check) or for the human who exercised it by hand. Ticking is the lead's job (the reviewer is read-only).
232
+ - **Stamp the freshness gate** so `/cohorte-ship` can refuse code edited after this verdict:
233
+ `BASE=$(<core>/pipeline/scripts/feature-diff.sh --default <default_branch> --base-only)`, then
234
+ write into the spec front-matter `reviewed_base: $BASE` and
235
+ `reviewed_digest: $(<core>/pipeline/scripts/feature-diff.sh --base $BASE --digest)` — the
236
+ fingerprint of exactly the source you reviewed, untracked files included (`specs/` and
237
+ `.claude/` excluded, so DoD ticks and the ship status flip don't trip it).
238
+ - Park the leftover LOWs through §3.5 (never as `## Remediation` items — those re-trigger the fix
239
+ loop), then tell the human they can `/cohorte-ship` — **recommend a `/clear` first**.