cohorte 3.0.0-dev.8 → 3.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 (229) hide show
  1. package/CHANGELOG.md +1532 -0
  2. package/README.md +316 -62
  3. package/bin/cli.js +212 -0
  4. package/bin/report.js +141 -0
  5. package/core/agents/cohorte-profile-reader.md +50 -0
  6. package/core/agents/cohorte-release.md +58 -0
  7. package/core/agents/cohorte-review.md +174 -0
  8. package/core/agents/implementer.template.md +146 -0
  9. package/core/commands/cohorte-align-ds.md +33 -0
  10. package/core/commands/cohorte-audit.md +67 -0
  11. package/core/commands/cohorte-brainstorm.md +73 -0
  12. package/core/commands/cohorte-build.md +241 -0
  13. package/core/commands/cohorte-doctor.md +133 -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 +57 -0
  20. package/core/commands/cohorte-retro.md +85 -0
  21. package/core/commands/cohorte-review.md +224 -0
  22. package/core/commands/cohorte-ship.md +155 -0
  23. package/core/commands/cohorte-spec.md +105 -0
  24. package/core/commands/cohorte-update-pipeline.md +115 -0
  25. package/core/hooks/gate.py +2931 -0
  26. package/core/templates/agent-handoff.md +34 -0
  27. package/core/templates/brainstorm-return.md +42 -0
  28. package/core/templates/decisions.template.md +42 -0
  29. package/core/templates/design-brief.md +37 -0
  30. package/core/templates/patch.template.md +86 -0
  31. package/core/templates/pr-body.md +25 -0
  32. package/core/templates/review-feedback.md +46 -0
  33. package/core/templates/spec.template.md +88 -0
  34. package/core/templates/steps/init-pipeline/01-detect-stack.md +44 -0
  35. package/core/templates/steps/init-pipeline/02-interview-gaps.md +55 -0
  36. package/core/templates/steps/init-pipeline/03-draft-profile.md +9 -0
  37. package/core/templates/steps/init-pipeline/04-write-render.md +91 -0
  38. package/core/templates/steps/init-pipeline/05-report.md +11 -0
  39. package/core/templates/steps/review-pr/01-pr-mode.md +54 -0
  40. package/core/workflows/audit.js +306 -0
  41. package/core/workflows/loop.js +687 -0
  42. package/core/workflows/refactor.js +291 -0
  43. package/core/workflows/review.js +491 -0
  44. package/install.ps1 +72 -0
  45. package/install.sh +69 -0
  46. package/lib/doctor.js +472 -0
  47. package/lib/install.js +377 -0
  48. package/lib/project.js +322 -0
  49. package/lib/render.js +121 -0
  50. package/lib/versions.js +145 -0
  51. package/lib/yaml.js +174 -0
  52. package/package.json +36 -17
  53. package/profile/PIPELINE.template.md +250 -0
  54. package/profile/SCHEMA.md +749 -0
  55. package/profile/cohorte.config.template.yaml +43 -0
  56. package/scripts/feature-diff.sh +118 -0
  57. package/scripts/kanban-move.sh +307 -0
  58. package/scripts/metrics/collect.mjs +542 -0
  59. package/scripts/metrics/prices.json +42 -0
  60. package/scripts/new-feature.sh.template +122 -0
  61. package/scripts/preflight.sh +114 -0
  62. package/scripts/remove-feature.sh.template +56 -0
  63. package/assets/manifest.json +0 -203
  64. package/assets/migrations/config/README.md +0 -12
  65. package/assets/migrations/state/0001_init.sql +0 -154
  66. package/assets/prompts/README.md +0 -11
  67. package/assets/prompts/agents/brainstormer.md +0 -3
  68. package/assets/prompts/agents/fixer.md +0 -7
  69. package/assets/prompts/agents/implementer.md +0 -12
  70. package/assets/prompts/agents/reviewer.md +0 -8
  71. package/assets/prompts/agents/security-reviewer.md +0 -7
  72. package/assets/prompts/agents/spec-author.md +0 -3
  73. package/assets/prompts/phases/build.md +0 -5
  74. package/assets/prompts/phases/review.md +0 -5
  75. package/assets/prompts/phases/test.md +0 -5
  76. package/assets/prompts/system.md +0 -11
  77. package/assets/schemas/agent-output.schema.json +0 -225
  78. package/assets/schemas/auth-status.schema.json +0 -87
  79. package/assets/schemas/command-result.schema.json +0 -192
  80. package/assets/schemas/commands.schema.json +0 -959
  81. package/assets/schemas/config.schema.json +0 -2281
  82. package/assets/schemas/doctor-report.schema.json +0 -104
  83. package/assets/schemas/events.schema.json +0 -8514
  84. package/assets/schemas/fake-script.schema.json +0 -549
  85. package/assets/schemas/inspect.schema.json +0 -3133
  86. package/assets/schemas/manifest.schema.json +0 -79
  87. package/assets/schemas/ownership.schema.json +0 -52
  88. package/assets/schemas/policy-verdict.schema.json +0 -282
  89. package/assets/schemas/project-model.schema.json +0 -783
  90. package/assets/schemas/project-status.schema.json +0 -217
  91. package/assets/schemas/reconcile-plan.schema.json +0 -154
  92. package/assets/schemas/run-diff.schema.json +0 -177
  93. package/assets/schemas/run-snapshot-manifest.schema.json +0 -2104
  94. package/assets/schemas/run-state.schema.json +0 -1755
  95. package/assets/schemas/runtime-capabilities.schema.json +0 -1545
  96. package/assets/schemas/sandbox-capabilities.schema.json +0 -116
  97. package/assets/schemas/skill.schema.json +0 -87
  98. package/assets/schemas/spec.schema.json +0 -202
  99. package/assets/schemas/tool-catalogue.schema.json +0 -655
  100. package/assets/schemas/trust-record.schema.json +0 -38
  101. package/assets/skills/README.md +0 -9
  102. package/assets/skills/inspect-surface.md +0 -4
  103. package/dist/agent-host.mjs +0 -2187
  104. package/dist/agent-host.mjs.map +0 -1
  105. package/dist/bundle-manifest.json +0 -128
  106. package/dist/chunks/__host-DgGPyco9.mjs +0 -18
  107. package/dist/chunks/__host-DgGPyco9.mjs.map +0 -1
  108. package/dist/chunks/align-ds-r_X_1aQ_.mjs +0 -93
  109. package/dist/chunks/align-ds-r_X_1aQ_.mjs.map +0 -1
  110. package/dist/chunks/approve-Cv135UqI.mjs +0 -19
  111. package/dist/chunks/approve-Cv135UqI.mjs.map +0 -1
  112. package/dist/chunks/audit-B4ZWQ_DI.mjs +0 -179
  113. package/dist/chunks/audit-B4ZWQ_DI.mjs.map +0 -1
  114. package/dist/chunks/auth-BT5oVp76.mjs +0 -132
  115. package/dist/chunks/auth-BT5oVp76.mjs.map +0 -1
  116. package/dist/chunks/auth-Dnlksuo5.mjs +0 -141
  117. package/dist/chunks/auth-Dnlksuo5.mjs.map +0 -1
  118. package/dist/chunks/brainstorm-SJwOIEif.mjs +0 -123
  119. package/dist/chunks/brainstorm-SJwOIEif.mjs.map +0 -1
  120. package/dist/chunks/build-C_-mbZfD.mjs +0 -19
  121. package/dist/chunks/build-C_-mbZfD.mjs.map +0 -1
  122. package/dist/chunks/cancel-KV_cpsqS.mjs +0 -15
  123. package/dist/chunks/cancel-KV_cpsqS.mjs.map +0 -1
  124. package/dist/chunks/canonical-C8UxeEmB.mjs +0 -57
  125. package/dist/chunks/canonical-C8UxeEmB.mjs.map +0 -1
  126. package/dist/chunks/catalogue-IaCJdfB8.mjs +0 -1549
  127. package/dist/chunks/catalogue-IaCJdfB8.mjs.map +0 -1
  128. package/dist/chunks/compose-DRKjQcn0.mjs +0 -7333
  129. package/dist/chunks/compose-DRKjQcn0.mjs.map +0 -1
  130. package/dist/chunks/config-Cqu5XQoP.mjs +0 -96
  131. package/dist/chunks/config-Cqu5XQoP.mjs.map +0 -1
  132. package/dist/chunks/contract-DjssDPpS.mjs +0 -335
  133. package/dist/chunks/contract-DjssDPpS.mjs.map +0 -1
  134. package/dist/chunks/contract-bQ9FJl4N.mjs +0 -123
  135. package/dist/chunks/contract-bQ9FJl4N.mjs.map +0 -1
  136. package/dist/chunks/deny-ClTxSvHJ.mjs +0 -15
  137. package/dist/chunks/deny-ClTxSvHJ.mjs.map +0 -1
  138. package/dist/chunks/diff-Qw0II0sj.mjs +0 -101
  139. package/dist/chunks/diff-Qw0II0sj.mjs.map +0 -1
  140. package/dist/chunks/discover-BZPolSZG.mjs +0 -21
  141. package/dist/chunks/discover-BZPolSZG.mjs.map +0 -1
  142. package/dist/chunks/doctor-DcDFPvQM.mjs +0 -222
  143. package/dist/chunks/doctor-DcDFPvQM.mjs.map +0 -1
  144. package/dist/chunks/fix-C9roGiQz.mjs +0 -82
  145. package/dist/chunks/fix-C9roGiQz.mjs.map +0 -1
  146. package/dist/chunks/fleet-yWHQY2ya.mjs +0 -297
  147. package/dist/chunks/fleet-yWHQY2ya.mjs.map +0 -1
  148. package/dist/chunks/gc-BBXlBF5w.mjs +0 -161
  149. package/dist/chunks/gc-BBXlBF5w.mjs.map +0 -1
  150. package/dist/chunks/init--FxxkrcT.mjs +0 -63
  151. package/dist/chunks/init--FxxkrcT.mjs.map +0 -1
  152. package/dist/chunks/inspect-Buby4cQD.mjs +0 -22
  153. package/dist/chunks/inspect-Buby4cQD.mjs.map +0 -1
  154. package/dist/chunks/intake-C1pesxCJ.mjs +0 -12
  155. package/dist/chunks/intake-C1pesxCJ.mjs.map +0 -1
  156. package/dist/chunks/logs-Giq5sUau.mjs +0 -25
  157. package/dist/chunks/logs-Giq5sUau.mjs.map +0 -1
  158. package/dist/chunks/loop-BWsUpyus.mjs +0 -212
  159. package/dist/chunks/loop-BWsUpyus.mjs.map +0 -1
  160. package/dist/chunks/migrate-DuYCAbE3.mjs +0 -33
  161. package/dist/chunks/migrate-DuYCAbE3.mjs.map +0 -1
  162. package/dist/chunks/models-Btp6X2YZ.mjs +0 -24
  163. package/dist/chunks/models-Btp6X2YZ.mjs.map +0 -1
  164. package/dist/chunks/obsidian-BHLkXx_H.mjs +0 -235
  165. package/dist/chunks/obsidian-BHLkXx_H.mjs.map +0 -1
  166. package/dist/chunks/patch-sAgVqjpx.mjs +0 -50
  167. package/dist/chunks/patch-sAgVqjpx.mjs.map +0 -1
  168. package/dist/chunks/pause-BASBfKLO.mjs +0 -16
  169. package/dist/chunks/pause-BASBfKLO.mjs.map +0 -1
  170. package/dist/chunks/policy-Du7WVBFX.mjs +0 -139
  171. package/dist/chunks/policy-Du7WVBFX.mjs.map +0 -1
  172. package/dist/chunks/providers-Dx78imKj.mjs +0 -19
  173. package/dist/chunks/providers-Dx78imKj.mjs.map +0 -1
  174. package/dist/chunks/reconcile-BHn66X3C.mjs +0 -50
  175. package/dist/chunks/reconcile-BHn66X3C.mjs.map +0 -1
  176. package/dist/chunks/refactor-DV3RfGjk.mjs +0 -153
  177. package/dist/chunks/refactor-DV3RfGjk.mjs.map +0 -1
  178. package/dist/chunks/render-DyZr5Lgi.mjs +0 -53
  179. package/dist/chunks/render-DyZr5Lgi.mjs.map +0 -1
  180. package/dist/chunks/resume-GJQRb2Eb.mjs +0 -15
  181. package/dist/chunks/resume-GJQRb2Eb.mjs.map +0 -1
  182. package/dist/chunks/retro-Dr-2RTNN.mjs +0 -78
  183. package/dist/chunks/retro-Dr-2RTNN.mjs.map +0 -1
  184. package/dist/chunks/retry-CLrUem1H.mjs +0 -15
  185. package/dist/chunks/retry-CLrUem1H.mjs.map +0 -1
  186. package/dist/chunks/review-ZsBqp3vZ.mjs +0 -35
  187. package/dist/chunks/review-ZsBqp3vZ.mjs.map +0 -1
  188. package/dist/chunks/run-BGabwbDL.mjs +0 -109
  189. package/dist/chunks/run-BGabwbDL.mjs.map +0 -1
  190. package/dist/chunks/run-tool-C3rAv4XF.mjs +0 -26
  191. package/dist/chunks/run-tool-C3rAv4XF.mjs.map +0 -1
  192. package/dist/chunks/scan-C5uDr7Yq.mjs +0 -167
  193. package/dist/chunks/scan-C5uDr7Yq.mjs.map +0 -1
  194. package/dist/chunks/schema-Bq9qtgsd.mjs +0 -583
  195. package/dist/chunks/schema-Bq9qtgsd.mjs.map +0 -1
  196. package/dist/chunks/send-BdnJ85Nz.mjs +0 -19
  197. package/dist/chunks/send-BdnJ85Nz.mjs.map +0 -1
  198. package/dist/chunks/ship-BizfUe62.mjs +0 -140
  199. package/dist/chunks/ship-BizfUe62.mjs.map +0 -1
  200. package/dist/chunks/shutdown-BM92Iyv2.mjs +0 -15
  201. package/dist/chunks/shutdown-BM92Iyv2.mjs.map +0 -1
  202. package/dist/chunks/skip-DZG5kpcH.mjs +0 -18
  203. package/dist/chunks/skip-DZG5kpcH.mjs.map +0 -1
  204. package/dist/chunks/spec-C2h3U64g.mjs +0 -65
  205. package/dist/chunks/spec-C2h3U64g.mjs.map +0 -1
  206. package/dist/chunks/spec-path-tptqR7W8.mjs +0 -10
  207. package/dist/chunks/spec-path-tptqR7W8.mjs.map +0 -1
  208. package/dist/chunks/src-Bfr1yzsn.mjs +0 -1689
  209. package/dist/chunks/src-Bfr1yzsn.mjs.map +0 -1
  210. package/dist/chunks/src-CPW2_Ons.mjs +0 -5487
  211. package/dist/chunks/src-CPW2_Ons.mjs.map +0 -1
  212. package/dist/chunks/src-Cu3TxNob.mjs +0 -783
  213. package/dist/chunks/src-Cu3TxNob.mjs.map +0 -1
  214. package/dist/chunks/src-DNsLSxgm.mjs +0 -928
  215. package/dist/chunks/src-DNsLSxgm.mjs.map +0 -1
  216. package/dist/chunks/src-DbS9gkJy.mjs +0 -117
  217. package/dist/chunks/src-DbS9gkJy.mjs.map +0 -1
  218. package/dist/chunks/src-yi5whv3n.mjs +0 -2118
  219. package/dist/chunks/src-yi5whv3n.mjs.map +0 -1
  220. package/dist/chunks/status-SMjiOMYy.mjs +0 -29
  221. package/dist/chunks/status-SMjiOMYy.mjs.map +0 -1
  222. package/dist/chunks/tail-BuhT-2PH.mjs +0 -25
  223. package/dist/chunks/tail-BuhT-2PH.mjs.map +0 -1
  224. package/dist/chunks/update-BXIppsbi.mjs +0 -16
  225. package/dist/chunks/update-BXIppsbi.mjs.map +0 -1
  226. package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs +0 -56
  227. package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs.map +0 -1
  228. package/dist/cli.mjs +0 -186
  229. package/dist/cli.mjs.map +0 -1
@@ -0,0 +1,491 @@
1
+ // cohorte — /cohorte-review as a deterministic workflow (opt-in; the conversational
2
+ // /cohorte-review command remains the default path and the fallback).
3
+ //
4
+ // Invoke with args = {feature: "<feature_id>"} (or the bare feature id string).
5
+ // Requires Claude Code >= 2.1.154 with workflows enabled — /cohorte-doctor reports this.
6
+ //
7
+ // Shape (SCHEMA.md §Workflows): phase 0 reads the profile through the
8
+ // profile-reader agent (scripts have no filesystem or shell), the deterministic
9
+ // preflight aborts while red (zero reviewers spawned), the diff is staged ONCE
10
+ // per touched surface, one reviewer runs per surface in parallel, an adversarial
11
+ // cross-check tries to refute every CRITICAL/security finding, and only the
12
+ // merged verdict comes back — the full report is staged to specs/reports/.
13
+ // Mechanical phases run on haiku; reviewers run the pinned `cohorte-review` agent (sonnet).
14
+
15
+ export const meta = {
16
+ name: 'cohorte-review',
17
+ description: 'Review a cohorte feature: preflight gate, one reviewer per touched surface, adversarial cross-check, merged verdict only',
18
+ whenToUse: 'Only when the human explicitly asks for the review workflow of a cohorte feature. args = {feature: "<feature_id>"}.',
19
+ phases: [
20
+ { title: 'Profile', detail: 'PIPELINE.md → JSON via profile-reader', model: 'haiku' },
21
+ { title: 'Preflight', detail: 'typecheck + lint + tests — abort while red', model: 'haiku' },
22
+ { title: 'Stage', detail: 'feature-diff.sh: changed paths once, per-surface hunks to disk', model: 'haiku' },
23
+ { title: 'Review', detail: 'one review agent per touched surface' },
24
+ { title: 'Cross-check', detail: 'adversarial refutation of CRITICAL/security findings' },
25
+ { title: 'Merge', detail: 'stage merged report + metrics; return the verdict', model: 'haiku' },
26
+ ],
27
+ }
28
+
29
+ // The Workflow runtime hands `args` to a script verbatim, so a caller that passes a
30
+ // JSON-ENCODED STRING instead of a real object gets that string back here. The old
31
+ // `typeof args === 'string' ? args.trim()` then took the whole blob as the value — which
32
+ // is how a report landed on disk named `specs/reports/{"feature": "x"}.md`, and how
33
+ // maxRounds/smoke were silently dropped on the same run. Parse it back into the object
34
+ // it was meant to be; a bare slug stays valid shorthand.
35
+ const ARGS = (() => {
36
+ if (typeof args === 'string') {
37
+ const t = args.trim()
38
+ if (t.startsWith('{')) {
39
+ try { const o = JSON.parse(t); if (o && typeof o === 'object' && !Array.isArray(o)) return o } catch {}
40
+ }
41
+ return { feature: t, target: t }
42
+ }
43
+ return args && typeof args === 'object' ? args : {}
44
+ })()
45
+ // Approximate cost of this run from the runtime's own output-token counter — the one
46
+ // figure the conversational path cannot record (a lead cannot read a subagent's token
47
+ // count; SCHEMA.md §Measuring cost). Sampled at start, delta stamped into the metrics line.
48
+ const spentNow = () => {
49
+ try {
50
+ const v = (budget && typeof budget.spent === 'function') ? budget.spent() : 0
51
+ return Number.isFinite(v) ? v : 0 // a NaN here would poison the metrics JSON downstream
52
+ } catch { return 0 }
53
+ }
54
+ const spentStart = spentNow()
55
+
56
+ const isSlug = s => typeof s === 'string' && /^[A-Za-z0-9._-]+$/.test(s)
57
+ const feature = ARGS.feature
58
+ if (!feature) throw new Error('cohorte-review needs args = {feature: "<feature_id>"}')
59
+ if (!isSlug(feature)) {
60
+ throw new Error(`cohorte-review got a feature id that is not a slug: ${JSON.stringify(feature)}. ` +
61
+ 'Pass args as a real object, e.g. {feature: "titlebar-project-switcher"} — not a JSON string.')
62
+ }
63
+
64
+ // The profile-reader returns through a StructuredOutput tool call, and a haiku agent
65
+ // intermittently nests the whole profile as a JSON *string* under a single wrapper field
66
+ // ({"output": "{\"surfaces\": …}"}) instead of putting the profile's keys at the top level.
67
+ // The schema here used to be {type:'object', additionalProperties:true} — no declared
68
+ // properties, no required keys — so that wrapper validated cleanly and every field then read
69
+ // as undefined: `surfaces` fell back to [], parallel([]) dispatched zero agents, the
70
+ // dead-agent guard had no surfaces to find missing, and the run reported a verdict having
71
+ // done nothing. On the surface it is indistinguishable from a clean run with an empty diff.
72
+ // Declaring the shape gives the tool layer something to validate and the agent something to
73
+ // aim at; unwrapProfile() salvages a wrapped return that still gets through; and the
74
+ // zero-surface abort below makes the silent-success path impossible either way.
75
+ // See also the structured-output section of core/agents/cohorte-profile-reader.md.
76
+ const PROFILE = {
77
+ type: 'object', additionalProperties: true,
78
+ properties: {
79
+ error: { type: 'string', description: 'set ONLY when PIPELINE.md is missing or unparseable' },
80
+ surfaces: {
81
+ type: 'array',
82
+ description: "one entry per surface, at the TOP LEVEL of this object — never a JSON string",
83
+ items: {
84
+ type: 'object', required: ['key'], additionalProperties: true,
85
+ properties: { key: { type: 'string' }, path: { type: 'string' }, agent: { type: 'string' } },
86
+ },
87
+ },
88
+ },
89
+ }
90
+
91
+ // Salvage a profile handed back as JSON text rather than as an object — either the whole
92
+ // return, or nested under a single wrapper field. Anything already shaped like a profile
93
+ // (has `surfaces`, or is the documented `{error}` failure shape) passes through untouched.
94
+ const unwrapProfile = p => {
95
+ if (typeof p === 'string') { try { return JSON.parse(p) } catch { return null } }
96
+ if (!p || typeof p !== 'object') return null
97
+ if (Array.isArray(p.surfaces) || p.error) return p
98
+ for (const v of Object.values(p)) {
99
+ if (typeof v !== 'string') continue
100
+ try {
101
+ const inner = JSON.parse(v)
102
+ if (inner && typeof inner === 'object' && !Array.isArray(inner)) return inner
103
+ } catch {}
104
+ }
105
+ return p
106
+ }
107
+
108
+ const PREFLIGHT = {
109
+ type: 'object', required: ['pass'], additionalProperties: false,
110
+ properties: {
111
+ pass: { type: 'boolean' },
112
+ epoch: { type: 'integer', description: 'the `date +%s` printed at the START of the Bash call — the run\'s wall-clock origin' },
113
+ tail: { type: 'string', description: 'on failure: the raw last lines the script printed' },
114
+ },
115
+ }
116
+
117
+ const STAGE = {
118
+ type: 'object', required: ['surfaces'], additionalProperties: false,
119
+ properties: {
120
+ error: { type: 'string', description: 'set ONLY when feature-diff.sh is absent or exited non-zero: its stderr line' },
121
+ surfaces: {
122
+ type: 'array',
123
+ items: {
124
+ type: 'object', required: ['key', 'diff', 'files'], additionalProperties: false,
125
+ properties: {
126
+ key: { type: 'string' },
127
+ diff: { type: 'string', description: 'path of the staged .diff file' },
128
+ files: { type: 'array', items: { type: 'string' }, description: 'changed files (from --numstat)' },
129
+ },
130
+ },
131
+ },
132
+ },
133
+ }
134
+
135
+ const FINDING = {
136
+ type: 'object', required: ['severity', 'file', 'line', 'kind', 'problem', 'fix'],
137
+ additionalProperties: false,
138
+ properties: {
139
+ severity: { enum: ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'] },
140
+ file: { type: 'string' }, line: { type: 'integer' },
141
+ kind: { enum: ['spec-violation', 'quality', 'security', 'complexity'] },
142
+ problem: { type: 'string', description: 'one line, no code excerpts' },
143
+ fix: { type: 'string', description: 'one concrete change, one line' },
144
+ },
145
+ }
146
+
147
+ // A DEFERRED finding is real but out of this feature's scope (pre-existing code the
148
+ // diff never touched). It carries its own out-of-scope reason, counts in no severity
149
+ // row, is never cross-checked, and can never move the verdict — it is routed to
150
+ // specs/refactor-backlog.md so /cohorte-refactor owns it. See core/agents/cohorte-review.md §Deferred.
151
+ const DEFERRED = {
152
+ type: 'object', required: ['severity', 'file', 'line', 'kind', 'problem', 'fix', 'outOfScope'],
153
+ additionalProperties: false,
154
+ properties: {
155
+ severity: { enum: ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'] },
156
+ file: { type: 'string' }, line: { type: 'integer' },
157
+ kind: { enum: ['quality', 'security', 'rule', 'complexity'] },
158
+ problem: { type: 'string', description: 'one line, no code excerpts' },
159
+ fix: { type: 'string', description: 'one concrete change, one line' },
160
+ outOfScope: { type: 'string', description: 'one line: why this feature does not own it' },
161
+ },
162
+ }
163
+
164
+ const REPORT = {
165
+ type: 'object', required: ['verdict', 'findings'], additionalProperties: false,
166
+ properties: {
167
+ verdict: { enum: ['SHIP', 'REVISE', 'BLOCK'] },
168
+ findings: { type: 'array', maxItems: 20, items: FINDING },
169
+ deferred: { type: 'array', maxItems: 10, items: DEFERRED },
170
+ overflow: { type: 'integer', description: 'findings beyond the 20-item cap, if any' },
171
+ notes: { type: 'string', description: 'RBAC / mobile-first assessment only, when the profile enables them' },
172
+ },
173
+ }
174
+
175
+ const VERDICT = {
176
+ type: 'object', required: ['refuted', 'reason'], additionalProperties: false,
177
+ properties: {
178
+ refuted: { type: 'boolean' },
179
+ reason: { type: 'string', description: 'one line: why the finding does or does not hold' },
180
+ },
181
+ }
182
+
183
+ // ── Phase 0 — profile ────────────────────────────────────────────────────────
184
+ phase('Profile')
185
+ const profile = unwrapProfile(await agent(
186
+ 'Return this project\'s PIPELINE.md `yaml pipeline-profile` block as JSON, per your instructions.',
187
+ { agentType: 'cohorte-profile-reader', label: 'profile', schema: PROFILE, effort: 'low' },
188
+ ))
189
+ if (!profile || profile.error) {
190
+ return { verdict: 'ABORTED', aborted: 'profile', reason: `profile unreadable: ${(profile && profile.error) || 'profile-reader returned nothing'}` }
191
+ }
192
+ const cmds = profile.commands || {}
193
+ const base = (profile.vcs && profile.vcs.default_branch) || 'main'
194
+ const surfaces = Array.isArray(profile.surfaces) ? profile.surfaces : []
195
+ // A profile with no surfaces cannot do this workflow's work, and every later
196
+ // guard compares against `surfaces` — an empty list makes them all vacuously
197
+ // pass. Fail loudly here instead of finishing with nothing done.
198
+ if (!surfaces.length) {
199
+ return { verdict: 'ABORTED', aborted: 'profile', reason: 'profile has no surfaces — nothing would be reviewed. the `yaml pipeline-profile` block in PIPELINE.md is empty or unparseable, or the profile-reader mis-returned; run /cohorte-doctor' }
200
+ }
201
+ const quiet = (q, full) => (q && !String(q).startsWith('<') ? q : full ? `${full} 2>&1 | tail -40` : '')
202
+ const checks = [cmds.typecheck, quiet(cmds.lint_quiet, cmds.lint), quiet(cmds.test_quiet, cmds.test)]
203
+ .filter(c => c && !String(c).startsWith('<'))
204
+
205
+ // ── Phase 1 — deterministic preflight (abort while red, zero reviewers) ─────
206
+ phase('Preflight')
207
+ const pre = await agent(
208
+ `Run the cohorte deterministic pre-flight for feature ${feature} in ONE Bash call, starting it with ` +
209
+ '`date +%s` (return that number as `epoch` — the run\'s wall-clock origin for the metrics line):\n' +
210
+ `<core>/pipeline/scripts/preflight.sh specs/reports/${feature}.preflight.txt ` +
211
+ checks.map(c => JSON.stringify(c)).join(' ') + '\n' +
212
+ '(<core> = "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/cohorte". ' +
213
+ 'Script absent: run the quoted commands yourself, each appended to the same report file, stopping at the first failure.) ' +
214
+ 'Return pass=true only on a fully green run. On failure set pass=false, put the raw last 40 lines of the report ' +
215
+ 'in `tail` — verbatim, no summarizing — and in the same Bash call write the degraded machine verdict the ' +
216
+ `conversational /cohorte-review §0 writes, so an automated driver gets a diagnosis rather than silence: ` +
217
+ `printf '{"id":"${feature}","phase":"review","ts":"%s","aborted":"preflight","verdict":"BLOCK","blocking":null}' ` +
218
+ `"$(date -u +%Y-%m-%dT%H:%M:%SZ)" > specs/reports/${feature}.verdict.json`,
219
+ { model: 'haiku', label: 'preflight', schema: PREFLIGHT, effort: 'low' },
220
+ )
221
+ if (!pre || !pre.pass) {
222
+ return {
223
+ verdict: 'ABORTED', aborted: 'preflight',
224
+ reason: 'preflight red — fix the mechanical failures (or run /cohorte-fix) before any review; no reviewer was spawned',
225
+ failures: (pre && pre.tail) || 'preflight agent returned nothing',
226
+ }
227
+ }
228
+
229
+ // ── Phase 2 — stage the diff once ────────────────────────────────────────────
230
+ phase('Stage')
231
+ const surfaceList = surfaces.map(s => `${s.key} → ${s.path}`).join(' · ') || '(none declared)'
232
+ // Every diff goes through feature-diff.sh (SCHEMA.md §Feature diff): a throwaway index so
233
+ // UNTRACKED files are reviewed (feature work is uncommitted until ship — a bare `git diff`
234
+ // dropped every new module, and an adds-only feature staged an empty diff that scored SHIP),
235
+ // against the MERGE-BASE with the default branch (its tip blamed the feature for every file
236
+ // main gained since). The human's real index is never touched.
237
+ const FD = `<core>/pipeline/scripts/feature-diff.sh --default ${base}`
238
+ const staged = await agent(
239
+ `Stage the review inputs for cohorte feature ${feature}. Surfaces: ${surfaceList}. ` +
240
+ '(<core> = "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/cohorte".) Never use a bare `git diff` — it misses untracked files.\n' +
241
+ `1. ONE call: ${FD} --numstat > specs/reports/${feature}.stat.txt — never print it. Non-zero exit or script ` +
242
+ 'absent ⇒ return `error` with its stderr line and an empty surfaces array, and do nothing else.\n' +
243
+ '2. Group the changed paths (3rd tab-separated column) by surface path prefix with one awk; paths under no surface are the `shared` remainder — attach them to the most relevant surface.\n' +
244
+ `3. Per surface that has changed paths (ONLY those): ${FD} --patch -- <surface.path> [<remainder paths>] > specs/reports/${feature}.<key>.diff\n` +
245
+ '4. Return the touched surfaces with their staged diff path and changed-file list. No changed paths at all ⇒ return an empty surfaces array.',
246
+ { model: 'haiku', label: 'stage-diff', schema: STAGE, effort: 'low' },
247
+ )
248
+ // A DEAD staging agent returns null, which is not the same fact as "the diff is
249
+ // empty" — conflating them handed back verdict SHIP ("nothing to review") for a
250
+ // feature nobody had looked at. Distinguish them.
251
+ if (!staged) {
252
+ return {
253
+ verdict: 'ABORTED', aborted: 'stage-diff',
254
+ reason: 'the diff-staging agent died — no reviewer was spawned and nothing was reviewed',
255
+ next: `re-run the review workflow, or /cohorte-review ${feature} conversationally`,
256
+ }
257
+ }
258
+ // Every abort after the preflight overwrites verdict.json too: a stale SHIP left on disk from
259
+ // an earlier round is exactly what /cohorte-ship (and a driver) would read.
260
+ const writeAborted = why => agent(
261
+ `Write EXACTLY this to specs/reports/${feature}.verdict.json (overwrite), substituting <ISO now> ` +
262
+ 'with `date -u +%Y-%m-%dT%H:%M:%SZ`, then return the single word done:\n' +
263
+ JSON.stringify({ id: feature, phase: 'review', ts: '<ISO now>', aborted: why, verdict: 'BLOCK', blocking: null }),
264
+ { model: 'haiku', label: 'stage-verdict', effort: 'low' },
265
+ )
266
+ if (staged.error) {
267
+ await writeAborted('stage-diff')
268
+ return {
269
+ verdict: 'ABORTED', aborted: 'stage-diff',
270
+ reason: `feature-diff.sh failed — no diff, no reviewer: ${staged.error}`,
271
+ next: 'fix the cause (exit 3 = the default branch / merge-base cannot be resolved; script absent = run `cohorte update`), then re-run the review',
272
+ }
273
+ }
274
+ const touched = staged.surfaces || []
275
+ if (!touched.length) {
276
+ // An empty diff reviewed NOTHING, so it certifies nothing. It used to score SHIP — and an
277
+ // adds-only feature (before untracked files were diffed) reached /cohorte-ship on it. It is
278
+ // an abort, and the aborted verdict overwrites any stale verdict.json a driver or ship reads.
279
+ await writeAborted('empty-diff')
280
+ return {
281
+ verdict: 'ABORTED', aborted: 'empty-diff',
282
+ reason: `the diff against the merge-base with ${base} is empty (untracked files included) — nothing was reviewed`,
283
+ next: 'nothing to review: check the branch (was the feature built here, in this worktree?) — no verdict, no freshness stamp',
284
+ }
285
+ }
286
+ log(`Touched surfaces: ${touched.map(s => s.key).join(', ')}`)
287
+
288
+ // ── Phases 3+4 — review each surface, cross-check its hard findings ─────────
289
+ // pipeline(): a fast surface's cross-check starts while a slow one still reviews.
290
+ const reviewPrompt = s =>
291
+ 'Review one feature surface against its frozen spec, per your agent instructions (read the staged ' +
292
+ 'diff FIRST; open a full source file only when a finding demands it; capped shape — max 20 findings, ' +
293
+ 'one line each, no code excerpts). Put anything real but OUT of this feature\'s scope in `deferred` ' +
294
+ '(max 10, each with its out-of-scope reason) per your §Deferred rules — never in `findings`. — Variable slots: ' +
295
+ `feature ${feature} · scope: the ${s.key} surface only · spec: specs/${feature}.md · ` +
296
+ `staged diff: ${s.diff} · changed files: ${s.files.join(', ')}`
297
+ // SCHEMA.md §Dead agents, the same rule as the build: a silent reviewer is retried ONCE,
298
+ // byte-identical (the staged diff is already on disk — the retry costs one agent); only a
299
+ // surface silent twice is `unreviewed`.
300
+ const reviewOnce = (s, label) =>
301
+ agent(reviewPrompt(s), { agentType: 'cohorte-review', label, phase: 'Review', schema: REPORT })
302
+ const reviewed = await pipeline(
303
+ touched,
304
+ async s => {
305
+ const r = await reviewOnce(s, `review:${s.key}`)
306
+ if (r != null) return r
307
+ log(`${s.key}: reviewer died — one byte-identical retry`)
308
+ return reviewOnce(s, `review:${s.key}#retry`)
309
+ },
310
+ async (report, s) => {
311
+ if (!report) return null
312
+ const hard = report.findings.filter(f => f.severity === 'CRITICAL' || f.kind === 'security')
313
+ const rest = report.findings.filter(f => !hard.includes(f))
314
+ // Deferred items skip the cross-check entirely: refuting one would spend an agent
315
+ // to argue about something that cannot affect the verdict either way.
316
+ const deferred = report.deferred || []
317
+ if (!hard.length) return { key: s.key, report, kept: rest, refuted: [], deferred }
318
+ const votes = await parallel(hard.map(f => () => agent(
319
+ 'Adversarially verify ONE review finding — your job is to REFUTE it if you can. Read the staged ' +
320
+ 'diff and the exact file:line; refuted=true when the code, a guard, a test, or the spec shows the ' +
321
+ 'finding does not hold. Uncertain ⇒ refuted=false (a real CRITICAL must not die on doubt). — ' +
322
+ `Finding: [${f.severity}/${f.kind}] ${f.file}:${f.line} — ${f.problem} (proposed fix: ${f.fix}). ` +
323
+ `Feature ${feature} · spec: specs/${feature}.md · staged diff: ${s.diff}`,
324
+ { agentType: 'cohorte-review', label: `verify:${s.key}`, phase: 'Cross-check', schema: VERDICT },
325
+ ).then(v => ({ f, refuted: !!(v && v.refuted), reason: v ? v.reason : 'verifier died — kept' }))))
326
+ const checkedVotes = votes.filter(Boolean)
327
+ return {
328
+ key: s.key,
329
+ report,
330
+ kept: rest.concat(checkedVotes.filter(v => !v.refuted).map(v => v.f)),
331
+ refuted: checkedVotes.filter(v => v.refuted).map(v => ({ ...v.f, reason: v.reason })),
332
+ deferred,
333
+ }
334
+ },
335
+ )
336
+
337
+ const results = reviewed.filter(Boolean)
338
+ // A reviewer that DIED returns null — and a dead reviewer produces zero findings,
339
+ // which is byte-identical to a clean surface. Left unchecked, "every reviewer
340
+ // crashed" scores SHIP: the strongest possible verdict from the weakest possible
341
+ // evidence. Name the unreviewed surfaces and refuse to certify them.
342
+ const unreviewed = touched.filter(s => !results.some(r => r.key === s.key)).map(s => s.key)
343
+ if (unreviewed.length) log(`Reviewer died on: ${unreviewed.join(', ')} — those surfaces are NOT reviewed`)
344
+ const kept = results.flatMap(r => r.kept.map(f => ({ ...f, surface: r.key })))
345
+ const refuted = results.flatMap(r => r.refuted.map(f => ({ ...f, surface: r.key })))
346
+ // Deferred findings are deliberately kept OUT of `counts`, out of `verdict` and out
347
+ // of `clean`: they belong to /cohorte-refactor, not to this feature's fix loop.
348
+ const deferredAll = results.flatMap(r => (r.deferred || []).map(f => ({ ...f, surface: r.key })))
349
+ const counts = { CRITICAL: 0, HIGH: 0, MEDIUM: 0, LOW: 0 }
350
+ for (const f of kept) counts[f.severity] = (counts[f.severity] || 0) + 1
351
+ // blocking = CRITICAL + security findings, each counted once — the conversational
352
+ // /cohorte-review §3's contract restated as a number, so blocking == 0 ⟺ verdict SHIP.
353
+ // blocking_items carry the finding's IDENTITY, not its wording: surface | file without
354
+ // `:line` (a fix that inserts lines shifts every line below it — a line-bearing identity
355
+ // would change every pass and drift detection would never fire) | the problem's first 8
356
+ // words, lowercased, runs of non-alphanumerics collapsed. Sorted, so two rounds with the
357
+ // same findings compare equal however the reviewers ordered them.
358
+ const blockingFindings = kept.filter(f => f.severity === 'CRITICAL' || f.kind === 'security')
359
+ const normProblem = p => String(p).toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim().split(' ').slice(0, 8).join(' ')
360
+ const blockingItems = [...new Set(blockingFindings.map(f =>
361
+ `${f.surface}|${String(f.file).replace(/:\d+$/, '')}|${normProblem(f.problem)}`))].sort()
362
+ // THE verdict rule (core/agents/cohorte-review.md §Severity & verdict), applied to the
363
+ // findings that SURVIVED the cross-check — never "the worst verdict a reviewer returned"
364
+ // (a refuted CRITICAL must not force a fix loop): any security ⇒ BLOCK, else any CRITICAL
365
+ // ⇒ REVISE, else SHIP — and never SHIP while a surface went unreviewed (absence of
366
+ // evidence is not evidence of absence). Per-surface verdicts use the same rule.
367
+ const verdictOf = (fs, missing) => fs.some(f => f.kind === 'security') ? 'BLOCK'
368
+ : fs.some(f => f.severity === 'CRITICAL') ? 'REVISE'
369
+ : missing ? 'REVISE' : 'SHIP'
370
+ const verdict = verdictOf(kept, unreviewed.length > 0)
371
+ // Only a SHIP whose leftovers are all LOW is a clean bill of health. The
372
+ // conversational /cohorte-review routes any surviving CRITICAL/HIGH/security to /cohorte-fix, so
373
+ // this path must not answer "/cohorte-ship" on a SHIP that still carries HIGH findings.
374
+ const clean = verdict === 'SHIP' && kept.every(f => f.severity === 'LOW')
375
+
376
+ // ── Phase 5 — stage the merged report; only the verdict leaves the workflow ──
377
+ phase('Merge')
378
+ const findingLine = f =>
379
+ `- [${f.severity}] \`${f.file}:${f.line}\` · ${f.kind} · ${f.problem} → **Fix:** ${f.fix}`
380
+ const reportBody = [
381
+ '# REVIEW REPORT', `feature_id: ${feature} · merged by cohorte-review workflow`, '',
382
+ '| Severity | Count |', '| -------- | ----- |',
383
+ ...['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'].map(s => `| ${s} | ${counts[s] || 0} |`), '',
384
+ `Verdict: ${verdict}`, '', '## Findings', '',
385
+ kept.length ? kept.map(findingLine).join('\n') : 'None.',
386
+ '', '## Deferred', '',
387
+ deferredAll.length
388
+ ? deferredAll.map(f => `${findingLine(f)} · out of scope: ${f.outOfScope} · deferred:${feature}`).join('\n')
389
+ : 'None.',
390
+ ...(unreviewed.length ? ['', '## NOT reviewed (reviewer died — no verdict on these)', '',
391
+ unreviewed.map(k => `- \`${k}\` — re-run /cohorte-review ${feature} (or the review workflow)`).join('\n')] : []),
392
+ ...(refuted.length ? ['', '## Refuted by cross-check (no action needed)', '',
393
+ refuted.map(f => `- ${f.file}:${f.line} · ${f.problem} — refuted: ${f.reason}`).join('\n')] : []),
394
+ ].join('\n')
395
+ // The machine-readable verdict the conversational /cohorte-review §3 guarantees — the
396
+ // ONLY contract between the pipeline and an automated driver (the loop workflow), which
397
+ // parses no prose. Composed HERE so the staging agent substitutes two tokens and can
398
+ // invent nothing; the sha256 fingerprint is computed in its Bash (scripts have no crypto).
399
+ const verdictJson = JSON.stringify({
400
+ id: feature, phase: 'review', ts: '<ISO now>', verdict,
401
+ findings: kept.length, blocking: blockingFindings.length,
402
+ security: kept.filter(f => f.kind === 'security').length,
403
+ deferred: deferredAll.length, unreviewed,
404
+ severity: counts,
405
+ // Per-surface verdicts AFTER the cross-check, by the same rule — the reviewer's own
406
+ // pre-cross-check verdict once marked a surface REVISE over a refuted CRITICAL.
407
+ surfaces: Object.fromEntries(results.map(r => [r.key, {
408
+ verdict: verdictOf(r.kept, false), findings: r.kept.length,
409
+ blocking: r.kept.filter(f => f.severity === 'CRITICAL' || f.kind === 'security').length,
410
+ }])),
411
+ blocking_items: blockingItems, fingerprint: '<FP>',
412
+ })
413
+ const staging = await agent(
414
+ `Stage a cohorte review report and its metrics, mechanically ` +
415
+ '(<core> = "${CLAUDE_CONFIG_DIR:-$HOME/.claude}/cohorte"):\n' +
416
+ `1. Write EXACTLY this content to specs/reports/${feature}.md (overwrite):\n<<<REPORT\n${reportBody}\nREPORT\n` +
417
+ `2. Write EXACTLY this to specs/reports/${feature}.verdict.json (overwrite), substituting <ISO now> with ` +
418
+ '`date -u +%Y-%m-%dT%H:%M:%SZ` and <FP> with the fingerprint — computed in Bash, never by hand: ' +
419
+ (blockingItems.length
420
+ // POSIX-escape embedded quotes ('\'') rather than stripping them: a stripped quote
421
+ // makes the fingerprint disagree with the blocking_items in the same file, and with
422
+ // a conversational re-run computing it per the §3 contract.
423
+ ? `printf '%s\\n' ${blockingItems.map(i => `'${i.replace(/'/g, "'\\''")}'`).join(' ')} | LC_ALL=C sort | sha256sum | cut -c1-16 ` +
424
+ '(`shasum -a 256` then first 16 hex chars where there is no sha256sum):\n'
425
+ : 'the blocking list is empty, so <FP> is the empty string "":\n') +
426
+ `${verdictJson}\n` +
427
+ // Per-surface verdicts (not the merged one stamped on every row — one BLOCK used to
428
+ // mark ALL surfaces failed), and dead reviewers logged as "dead"
429
+ // per SCHEMA.md §Dead agents — an incomplete batch is the batch worth recording.
430
+ `3. Append one line to $(dirname "$(git rev-parse --git-common-dir)")/.claude/pipeline-metrics.jsonl: ` +
431
+ // seconds: the clock lives in Bash (scripts have none) — elapsed since the preflight's
432
+ // `date +%s`. No epoch came back ⇒ the field is OMITTED, never a made-up 0.
433
+ `{"ts":"<ISO now>","feature":"${feature}","phase":"review",${
434
+ Number.isInteger(pre.epoch) && pre.epoch > 0 ? `"seconds":$(($(date +%s)-${pre.epoch})),` : ''
435
+ }"tokens":${Math.max(0, spentNow() - spentStart)},"surfaces":{${
436
+ results.map(r => `"${r.key}":"${verdictOf(r.kept, false)}:${r.kept.length}"`)
437
+ .concat(unreviewed.map(k => `"${k}":"dead"`)).join(',')}}}\n` +
438
+ // Deferred findings must land in the backlog on EVERY verdict — parked only on a
439
+ // SHIP is parked nowhere the rest of the time, which is the leak this closes.
440
+ (deferredAll.length
441
+ ? `4. Route the deferred findings to specs/refactor-backlog.md (create it if absent): for each line below, ` +
442
+ `insert it directly under the \`## <domain>\` heading named in its prefix with one awk pass (heading absent ⇒ ` +
443
+ `append a new \`## <domain>\` block at the end with \`>>\`; a bare \`>>\` under another domain's heading files it ` +
444
+ `in the wrong section) — never by reading the file back and rewriting it, and skip any whose file path + first words already appear there (grep -F first, ` +
445
+ `they may be left from a prior round or an /cohorte-audit):\n` +
446
+ deferredAll.map(f =>
447
+ `${f.surface}||- [ ] ${f.severity} · ${f.file}:${f.line} · ${f.kind} · ${f.fix} · deferred:${feature}`).join('\n') +
448
+ '\n'
449
+ : '') +
450
+ // Stamp + tick only when nothing above LOW survived: the conversational /cohorte-review
451
+ // keeps the stamp only for LOW findings, and a SHIP verdict here can still carry
452
+ // HIGH/MEDIUM ones — certifying those for /cohorte-ship would ship known defects. A dead
453
+ // reviewer already forced the verdict off SHIP, so `clean` covers that too.
454
+ (clean
455
+ ? `5. Stamp the freshness gate in specs/${feature}.md's front-matter, exactly as the conversational /cohorte-review §3 does ` +
456
+ `(so /cohorte-ship can prove the reviewed code is what ships): BASE=$(${FD} --base-only); set reviewed_base: $BASE and ` +
457
+ 'reviewed_digest: $(<core>/pipeline/scripts/feature-diff.sh --base $BASE --digest) — never a bare git diff (it misses untracked files). ' +
458
+ '6. Tick the spec DoD boxes this run verified (spec conformance + copy language — review SHIP; tests/lint/typecheck — green preflight); leave the rest unticked.\n'
459
+ : '') +
460
+ 'Return the single word: done.',
461
+ { model: 'haiku', label: 'stage-report', effort: 'low' },
462
+ )
463
+
464
+ // The staging agent writes the report, the metrics line, and (when clean) the
465
+ // freshness stamp + DoD ticks. If it died, none of that is on disk — returning
466
+ // `report: <path>` and "/cohorte-ship" would point the human at a file that does not
467
+ // exist and certify a stamp that was never written.
468
+ const staged_ok = staging != null && /done/i.test(String(staging))
469
+
470
+ return {
471
+ verdict,
472
+ counts,
473
+ blocking: blockingFindings.length, // CRITICAL + security, each once — 0 ⟺ SHIP; what a driver reduces on
474
+ blockingItems, // the sorted identity list behind verdict.json's fingerprint
475
+ deferred: deferredAll.length, // parked in the backlog for /cohorte-refactor — never blocking
476
+ refutedByCrossCheck: refuted.length,
477
+ reportStaged: staged_ok,
478
+ unreviewedSurfaces: unreviewed, // reviewers that died — these carry NO verdict
479
+ criticals: kept.filter(f => f.severity === 'CRITICAL' || f.kind === 'security')
480
+ .map(f => `[${f.surface}] ${f.file}:${f.line} — ${f.problem}`),
481
+ report: staged_ok ? `specs/reports/${feature}.md` : '(NOT written — the staging agent died)',
482
+ next: !staged_ok
483
+ ? `the report/metrics/freshness stamp were NEVER written (staging agent died) — the verdict above is real, but nothing is on disk: re-run the review workflow, or /cohorte-review ${feature}`
484
+ : unreviewed.length
485
+ ? `re-run the review — no reviewer completed on: ${unreviewed.join(', ')}`
486
+ : clean
487
+ ? `/cohorte-ship ${feature} (DoD ticked + freshness stamped)`
488
+ : verdict === 'SHIP'
489
+ ? `/cohorte-fix ${feature} — SHIP verdict, but ${kept.length} finding(s) above LOW survived; park them in specs/refactor-backlog.md instead if you deliberately defer them`
490
+ : `/cohorte-fix ${feature}`,
491
+ }
package/install.ps1 ADDED
@@ -0,0 +1,72 @@
1
+ # install.ps1 - install cohorte (the multi-agent dev pipeline for Claude Code) on this machine (Windows).
2
+ # Works on Windows PowerShell 5.1 and PowerShell 7+. A thin wrapper around bin\cli.js: Node >= 20 is required.
3
+ #
4
+ # irm https://raw.githubusercontent.com/TheBidouilleAgency/cohorte/main/install.ps1 | iex
5
+ # .\install.ps1 # from a checkout: installs that working tree
6
+ # .\install.ps1 -Update # same thing - install is idempotent
7
+ #
8
+ # The documented route is `npm i -g cohorte; cohorte install`. Piped, this script installs the
9
+ # LATEST RELEASE tag (never the tip of main). Then, in each project, run /cohorte-init-pipeline once.
10
+
11
+ # Keep this file pure ASCII: Windows PowerShell 5.1 reads a BOM-less script in the ANSI code
12
+ # page, and a single em dash inside a string breaks parsing.
13
+
14
+ [CmdletBinding()]
15
+ param(
16
+ [switch]$Update,
17
+ [switch]$Global # 2.x flag - 3.x has a single mode
18
+ )
19
+
20
+ $ErrorActionPreference = 'Stop'
21
+ $repoUrl = $env:PIPELINE_REPO
22
+ if (-not $repoUrl) { $repoUrl = 'https://github.com/TheBidouilleAgency/cohorte' }
23
+
24
+ $node = Get-Command node -ErrorAction SilentlyContinue
25
+ if (-not $node) {
26
+ Write-Error 'cohorte needs Node >= 20 (https://nodejs.org), then: npm i -g cohorte; cohorte install'
27
+ if ($PSCommandPath) { exit 1 }
28
+ return
29
+ }
30
+ # Parse `node --version` rather than `node -p "...split('.')..."`: Windows PowerShell 5.1 strips
31
+ # the inner quotes of a native argument, which made the old probe report every Node as v0.
32
+ $nodeMajor = 0
33
+ try { $nodeMajor = [int](((& $node.Source --version) -replace '^v', '') -split '\.')[0] } catch { }
34
+ if ($nodeMajor -lt 20) {
35
+ Write-Error "cohorte needs Node >= 20 - found $(& $node.Source --version)."
36
+ if ($PSCommandPath) { exit 1 }
37
+ return
38
+ }
39
+
40
+ $tmp = $null
41
+ try {
42
+ if ($PSScriptRoot -and (Test-Path -LiteralPath (Join-Path $PSScriptRoot 'bin\cli.js'))) {
43
+ $src = $PSScriptRoot
44
+ } else {
45
+ if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
46
+ throw 'git is required (or use: npm i -g cohorte; cohorte install).'
47
+ }
48
+ $prevEAP = $ErrorActionPreference
49
+ $ErrorActionPreference = 'Continue'
50
+ $tags = git ls-remote --tags --refs $repoUrl 'v*' 2>$null
51
+ $ErrorActionPreference = $prevEAP
52
+ $tag = $tags | ForEach-Object { ($_ -split 'refs/tags/')[1] } |
53
+ Where-Object { $_ -match '^v\d+\.\d+\.\d+$' } |
54
+ Sort-Object { [version]($_.TrimStart('v')) } | Select-Object -Last 1
55
+ if (-not $tag) { throw "could not list the releases of $repoUrl" }
56
+ Write-Host "-> fetching cohorte $tag from $repoUrl"
57
+ $tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("cohorte-" + [Guid]::NewGuid().ToString('N'))
58
+ New-Item -ItemType Directory -Path $tmp | Out-Null
59
+ $ErrorActionPreference = 'Continue'
60
+ git clone --quiet --depth 1 --branch $tag $repoUrl (Join-Path $tmp 'cohorte') 2>&1 | Out-Null
61
+ $ErrorActionPreference = $prevEAP
62
+ if ($LASTEXITCODE -ne 0) { throw "git clone of $repoUrl ($tag) failed" }
63
+ $src = Join-Path $tmp 'cohorte'
64
+ }
65
+ & $node.Source (Join-Path $src 'bin\cli.js') $(if ($Update) { 'update' } else { 'install' })
66
+ # `exit` under `irm ... | iex` would close the user's interactive session. Exit only as a file.
67
+ if ($PSCommandPath) { exit $LASTEXITCODE }
68
+ } finally {
69
+ if ($tmp -and (Test-Path -LiteralPath $tmp)) {
70
+ Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue
71
+ }
72
+ }
package/install.sh ADDED
@@ -0,0 +1,69 @@
1
+ #!/bin/sh
2
+ #
3
+ # install.sh — install cohorte (the multi-agent dev pipeline for Claude Code) on this machine.
4
+ # POSIX sh (works with dash/bash/zsh). A thin wrapper around bin/cli.js: Node >= 20 is required.
5
+ #
6
+ # curl -fsSL https://raw.githubusercontent.com/TheBidouilleAgency/cohorte/main/install.sh | sh
7
+ # sh install.sh # from a checkout: installs that working tree
8
+ # sh install.sh --update # same thing — install is idempotent
9
+ #
10
+ # The documented route is `npm i -g cohorte && cohorte install`. Piped through curl, this script
11
+ # installs the LATEST RELEASE tag (never the tip of main), so both routes ship the same code.
12
+ # Then, in each project, run /cohorte-init-pipeline once.
13
+
14
+ set -eu
15
+
16
+ REPO_URL="${PIPELINE_REPO:-https://github.com/TheBidouilleAgency/cohorte}"
17
+
18
+ verb="install"
19
+ while [ $# -gt 0 ]; do
20
+ case "$1" in
21
+ --update) verb="update"; shift ;;
22
+ --global) shift ;; # 2.x flag — 3.x has a single mode
23
+ -h|--help)
24
+ sed -n '2,13p' "$0" 2>/dev/null | sed 's/^# \{0,1\}//'
25
+ exit 0 ;;
26
+ *) echo "error: unknown argument: $1 (3.x installs on the machine; wire a project with /cohorte-init-pipeline)" >&2; exit 2 ;;
27
+ esac
28
+ done
29
+
30
+ command -v node >/dev/null 2>&1 || {
31
+ echo "error: cohorte needs Node >= 20 (https://nodejs.org), then: npm i -g cohorte && cohorte install" >&2
32
+ exit 1
33
+ }
34
+ node_major=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0)
35
+ case "$node_major" in *[!0-9]*) node_major=0 ;; esac
36
+ if [ "$node_major" -lt 20 ]; then
37
+ echo "error: cohorte needs Node >= 20 — found $(node --version 2>/dev/null || echo '?')." >&2
38
+ exit 1
39
+ fi
40
+
41
+ # --- locate the source: this checkout, or the latest release ------------------
42
+ src=""
43
+ case "${0:-}" in
44
+ */*) self_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) ;;
45
+ *install.sh*) self_dir=$(pwd) ;;
46
+ *) self_dir="" ;;
47
+ esac
48
+ if [ -n "$self_dir" ] && [ -f "$self_dir/bin/cli.js" ] && [ -d "$self_dir/core" ]; then
49
+ src="$self_dir"
50
+ else
51
+ command -v git >/dev/null 2>&1 || { echo "error: git is required (or use: npm i -g cohorte && cohorte install)" >&2; exit 1; }
52
+ # Highest vX.Y.Z tag without a pre-release suffix.
53
+ tag=$(git ls-remote --tags --refs "$REPO_URL" 'v*' 2>/dev/null \
54
+ | sed 's#.*refs/tags/v##' | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' \
55
+ | sort -t. -k1,1n -k2,2n -k3,3n | tail -1)
56
+ [ -n "$tag" ] && tag="v$tag"
57
+ [ -n "$tag" ] || { echo "error: could not list the releases of $REPO_URL" >&2; exit 1; }
58
+ echo "→ fetching cohorte $tag from $REPO_URL"
59
+ tmp=$(mktemp -d)
60
+ trap 'rm -rf "$tmp"' EXIT
61
+ if ! git clone --quiet --depth 1 --branch "$tag" "$REPO_URL" "$tmp/cohorte"; then
62
+ echo "error: git clone of $REPO_URL ($tag) failed" >&2
63
+ exit 1
64
+ fi
65
+ src="$tmp/cohorte"
66
+ fi
67
+
68
+ # Not `exec`: exec replaces this shell, so the curl-path EXIT trap would never fire.
69
+ node "$src/bin/cli.js" "$verb"