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.
- package/CHANGELOG.md +1637 -0
- package/README.md +322 -62
- package/bin/cli.js +213 -0
- package/bin/report.js +141 -0
- package/core/agents/cohorte-profile-reader.md +40 -0
- package/core/agents/cohorte-release.md +61 -0
- package/core/agents/cohorte-review.md +200 -0
- package/core/agents/implementer.template.md +154 -0
- package/core/commands/cohorte-align-ds.md +33 -0
- package/core/commands/cohorte-audit.md +74 -0
- package/core/commands/cohorte-brainstorm.md +73 -0
- package/core/commands/cohorte-build.md +248 -0
- package/core/commands/cohorte-doctor.md +135 -0
- package/core/commands/cohorte-fix.md +80 -0
- package/core/commands/cohorte-fleet.md +111 -0
- package/core/commands/cohorte-init-pipeline.md +30 -0
- package/core/commands/cohorte-intake.md +92 -0
- package/core/commands/cohorte-patch.md +118 -0
- package/core/commands/cohorte-refactor.md +122 -0
- package/core/commands/cohorte-retro.md +85 -0
- package/core/commands/cohorte-revert.md +104 -0
- package/core/commands/cohorte-review.md +239 -0
- package/core/commands/cohorte-ship.md +167 -0
- package/core/commands/cohorte-spec.md +114 -0
- package/core/commands/cohorte-update-pipeline.md +119 -0
- package/core/commands/cohorte-verify.md +106 -0
- package/core/hooks/gate.py +3236 -0
- package/core/templates/agent-handoff.md +34 -0
- package/core/templates/brainstorm-return.md +42 -0
- package/core/templates/decisions.template.md +42 -0
- package/core/templates/design-brief.md +37 -0
- package/core/templates/patch.template.md +95 -0
- package/core/templates/pr-body.md +25 -0
- package/core/templates/review-feedback.md +46 -0
- package/core/templates/spec.template.md +109 -0
- package/core/templates/steps/init-pipeline/01-detect-stack.md +53 -0
- package/core/templates/steps/init-pipeline/02-interview-gaps.md +78 -0
- package/core/templates/steps/init-pipeline/03-draft-profile.md +10 -0
- package/core/templates/steps/init-pipeline/04-write-render.md +95 -0
- package/core/templates/steps/init-pipeline/05-report.md +11 -0
- package/core/templates/steps/review-pr/01-pr-mode.md +54 -0
- package/core/workflows/audit.js +311 -0
- package/core/workflows/loop.js +692 -0
- package/core/workflows/refactor.js +398 -0
- package/core/workflows/review.js +505 -0
- package/install.ps1 +72 -0
- package/install.sh +69 -0
- package/lib/doctor.js +506 -0
- package/lib/install.js +386 -0
- package/lib/project.js +359 -0
- package/lib/render.js +121 -0
- package/lib/versions.js +145 -0
- package/lib/yaml.js +183 -0
- package/package.json +36 -17
- package/profile/PIPELINE.template.md +288 -0
- package/profile/SCHEMA.md +30 -0
- package/profile/cohorte.config.template.yaml +43 -0
- package/profile/schema/dead-agents.md +29 -0
- package/profile/schema/decisions.md +23 -0
- package/profile/schema/deferred.md +22 -0
- package/profile/schema/feature-diff.md +20 -0
- package/profile/schema/kanban.md +95 -0
- package/profile/schema/metrics.md +23 -0
- package/profile/schema/output-discipline.md +21 -0
- package/profile/schema/preflight.md +81 -0
- package/profile/schema/profile-block.md +103 -0
- package/profile/schema/project-kinds.md +89 -0
- package/profile/schema/readiness.md +17 -0
- package/profile/schema/reconcile.md +64 -0
- package/profile/schema/release-notes.md +29 -0
- package/profile/schema/rendering.md +48 -0
- package/profile/schema/retrieval.md +58 -0
- package/profile/schema/spec-status.md +79 -0
- package/profile/schema/specialization.md +41 -0
- package/profile/schema/verify.md +115 -0
- package/profile/schema/workflows.md +78 -0
- package/scripts/feature-diff.sh +118 -0
- package/scripts/kanban-move.sh +349 -0
- package/scripts/metrics/collect.mjs +542 -0
- package/scripts/metrics/prices.json +42 -0
- package/scripts/new-feature.sh.template +122 -0
- package/scripts/preflight.sh +114 -0
- package/scripts/remove-feature.sh.template +56 -0
- package/scripts/verify-run.sh +509 -0
- package/assets/manifest.json +0 -203
- package/assets/migrations/config/README.md +0 -12
- package/assets/migrations/state/0001_init.sql +0 -154
- package/assets/prompts/README.md +0 -11
- package/assets/prompts/agents/brainstormer.md +0 -3
- package/assets/prompts/agents/fixer.md +0 -7
- package/assets/prompts/agents/implementer.md +0 -12
- package/assets/prompts/agents/reviewer.md +0 -8
- package/assets/prompts/agents/security-reviewer.md +0 -7
- package/assets/prompts/agents/spec-author.md +0 -3
- package/assets/prompts/phases/build.md +0 -5
- package/assets/prompts/phases/review.md +0 -5
- package/assets/prompts/phases/test.md +0 -5
- package/assets/prompts/system.md +0 -11
- package/assets/schemas/agent-output.schema.json +0 -225
- package/assets/schemas/auth-status.schema.json +0 -87
- package/assets/schemas/command-result.schema.json +0 -192
- package/assets/schemas/commands.schema.json +0 -959
- package/assets/schemas/config.schema.json +0 -2281
- package/assets/schemas/doctor-report.schema.json +0 -104
- package/assets/schemas/events.schema.json +0 -8514
- package/assets/schemas/fake-script.schema.json +0 -549
- package/assets/schemas/inspect.schema.json +0 -3133
- package/assets/schemas/manifest.schema.json +0 -79
- package/assets/schemas/ownership.schema.json +0 -52
- package/assets/schemas/policy-verdict.schema.json +0 -282
- package/assets/schemas/project-model.schema.json +0 -783
- package/assets/schemas/project-status.schema.json +0 -217
- package/assets/schemas/reconcile-plan.schema.json +0 -154
- package/assets/schemas/run-diff.schema.json +0 -177
- package/assets/schemas/run-snapshot-manifest.schema.json +0 -2104
- package/assets/schemas/run-state.schema.json +0 -1755
- package/assets/schemas/runtime-capabilities.schema.json +0 -1545
- package/assets/schemas/sandbox-capabilities.schema.json +0 -116
- package/assets/schemas/skill.schema.json +0 -87
- package/assets/schemas/spec.schema.json +0 -202
- package/assets/schemas/tool-catalogue.schema.json +0 -655
- package/assets/schemas/trust-record.schema.json +0 -38
- package/assets/skills/README.md +0 -9
- package/assets/skills/inspect-surface.md +0 -4
- package/dist/agent-host.mjs +0 -2187
- package/dist/agent-host.mjs.map +0 -1
- package/dist/bundle-manifest.json +0 -128
- package/dist/chunks/__host-DgGPyco9.mjs +0 -18
- package/dist/chunks/__host-DgGPyco9.mjs.map +0 -1
- package/dist/chunks/align-ds-r_X_1aQ_.mjs +0 -93
- package/dist/chunks/align-ds-r_X_1aQ_.mjs.map +0 -1
- package/dist/chunks/approve-Cv135UqI.mjs +0 -19
- package/dist/chunks/approve-Cv135UqI.mjs.map +0 -1
- package/dist/chunks/audit-B4ZWQ_DI.mjs +0 -179
- package/dist/chunks/audit-B4ZWQ_DI.mjs.map +0 -1
- package/dist/chunks/auth-BT5oVp76.mjs +0 -132
- package/dist/chunks/auth-BT5oVp76.mjs.map +0 -1
- package/dist/chunks/auth-Dnlksuo5.mjs +0 -141
- package/dist/chunks/auth-Dnlksuo5.mjs.map +0 -1
- package/dist/chunks/brainstorm-SJwOIEif.mjs +0 -123
- package/dist/chunks/brainstorm-SJwOIEif.mjs.map +0 -1
- package/dist/chunks/build-C_-mbZfD.mjs +0 -19
- package/dist/chunks/build-C_-mbZfD.mjs.map +0 -1
- package/dist/chunks/cancel-KV_cpsqS.mjs +0 -15
- package/dist/chunks/cancel-KV_cpsqS.mjs.map +0 -1
- package/dist/chunks/canonical-C8UxeEmB.mjs +0 -57
- package/dist/chunks/canonical-C8UxeEmB.mjs.map +0 -1
- package/dist/chunks/catalogue-IaCJdfB8.mjs +0 -1549
- package/dist/chunks/catalogue-IaCJdfB8.mjs.map +0 -1
- package/dist/chunks/compose-DRKjQcn0.mjs +0 -7333
- package/dist/chunks/compose-DRKjQcn0.mjs.map +0 -1
- package/dist/chunks/config-Cqu5XQoP.mjs +0 -96
- package/dist/chunks/config-Cqu5XQoP.mjs.map +0 -1
- package/dist/chunks/contract-DjssDPpS.mjs +0 -335
- package/dist/chunks/contract-DjssDPpS.mjs.map +0 -1
- package/dist/chunks/contract-bQ9FJl4N.mjs +0 -123
- package/dist/chunks/contract-bQ9FJl4N.mjs.map +0 -1
- package/dist/chunks/deny-ClTxSvHJ.mjs +0 -15
- package/dist/chunks/deny-ClTxSvHJ.mjs.map +0 -1
- package/dist/chunks/diff-Qw0II0sj.mjs +0 -101
- package/dist/chunks/diff-Qw0II0sj.mjs.map +0 -1
- package/dist/chunks/discover-BZPolSZG.mjs +0 -21
- package/dist/chunks/discover-BZPolSZG.mjs.map +0 -1
- package/dist/chunks/doctor-DcDFPvQM.mjs +0 -222
- package/dist/chunks/doctor-DcDFPvQM.mjs.map +0 -1
- package/dist/chunks/fix-C9roGiQz.mjs +0 -82
- package/dist/chunks/fix-C9roGiQz.mjs.map +0 -1
- package/dist/chunks/fleet-yWHQY2ya.mjs +0 -297
- package/dist/chunks/fleet-yWHQY2ya.mjs.map +0 -1
- package/dist/chunks/gc-BBXlBF5w.mjs +0 -161
- package/dist/chunks/gc-BBXlBF5w.mjs.map +0 -1
- package/dist/chunks/init--FxxkrcT.mjs +0 -63
- package/dist/chunks/init--FxxkrcT.mjs.map +0 -1
- package/dist/chunks/inspect-Buby4cQD.mjs +0 -22
- package/dist/chunks/inspect-Buby4cQD.mjs.map +0 -1
- package/dist/chunks/intake-C1pesxCJ.mjs +0 -12
- package/dist/chunks/intake-C1pesxCJ.mjs.map +0 -1
- package/dist/chunks/logs-Giq5sUau.mjs +0 -25
- package/dist/chunks/logs-Giq5sUau.mjs.map +0 -1
- package/dist/chunks/loop-BWsUpyus.mjs +0 -212
- package/dist/chunks/loop-BWsUpyus.mjs.map +0 -1
- package/dist/chunks/migrate-DuYCAbE3.mjs +0 -33
- package/dist/chunks/migrate-DuYCAbE3.mjs.map +0 -1
- package/dist/chunks/models-Btp6X2YZ.mjs +0 -24
- package/dist/chunks/models-Btp6X2YZ.mjs.map +0 -1
- package/dist/chunks/obsidian-BHLkXx_H.mjs +0 -235
- package/dist/chunks/obsidian-BHLkXx_H.mjs.map +0 -1
- package/dist/chunks/patch-sAgVqjpx.mjs +0 -50
- package/dist/chunks/patch-sAgVqjpx.mjs.map +0 -1
- package/dist/chunks/pause-BASBfKLO.mjs +0 -16
- package/dist/chunks/pause-BASBfKLO.mjs.map +0 -1
- package/dist/chunks/policy-Du7WVBFX.mjs +0 -139
- package/dist/chunks/policy-Du7WVBFX.mjs.map +0 -1
- package/dist/chunks/providers-Dx78imKj.mjs +0 -19
- package/dist/chunks/providers-Dx78imKj.mjs.map +0 -1
- package/dist/chunks/reconcile-BHn66X3C.mjs +0 -50
- package/dist/chunks/reconcile-BHn66X3C.mjs.map +0 -1
- package/dist/chunks/refactor-DV3RfGjk.mjs +0 -153
- package/dist/chunks/refactor-DV3RfGjk.mjs.map +0 -1
- package/dist/chunks/render-DyZr5Lgi.mjs +0 -53
- package/dist/chunks/render-DyZr5Lgi.mjs.map +0 -1
- package/dist/chunks/resume-GJQRb2Eb.mjs +0 -15
- package/dist/chunks/resume-GJQRb2Eb.mjs.map +0 -1
- package/dist/chunks/retro-Dr-2RTNN.mjs +0 -78
- package/dist/chunks/retro-Dr-2RTNN.mjs.map +0 -1
- package/dist/chunks/retry-CLrUem1H.mjs +0 -15
- package/dist/chunks/retry-CLrUem1H.mjs.map +0 -1
- package/dist/chunks/review-ZsBqp3vZ.mjs +0 -35
- package/dist/chunks/review-ZsBqp3vZ.mjs.map +0 -1
- package/dist/chunks/run-BGabwbDL.mjs +0 -109
- package/dist/chunks/run-BGabwbDL.mjs.map +0 -1
- package/dist/chunks/run-tool-C3rAv4XF.mjs +0 -26
- package/dist/chunks/run-tool-C3rAv4XF.mjs.map +0 -1
- package/dist/chunks/scan-C5uDr7Yq.mjs +0 -167
- package/dist/chunks/scan-C5uDr7Yq.mjs.map +0 -1
- package/dist/chunks/schema-Bq9qtgsd.mjs +0 -583
- package/dist/chunks/schema-Bq9qtgsd.mjs.map +0 -1
- package/dist/chunks/send-BdnJ85Nz.mjs +0 -19
- package/dist/chunks/send-BdnJ85Nz.mjs.map +0 -1
- package/dist/chunks/ship-BizfUe62.mjs +0 -140
- package/dist/chunks/ship-BizfUe62.mjs.map +0 -1
- package/dist/chunks/shutdown-BM92Iyv2.mjs +0 -15
- package/dist/chunks/shutdown-BM92Iyv2.mjs.map +0 -1
- package/dist/chunks/skip-DZG5kpcH.mjs +0 -18
- package/dist/chunks/skip-DZG5kpcH.mjs.map +0 -1
- package/dist/chunks/spec-C2h3U64g.mjs +0 -65
- package/dist/chunks/spec-C2h3U64g.mjs.map +0 -1
- package/dist/chunks/spec-path-tptqR7W8.mjs +0 -10
- package/dist/chunks/spec-path-tptqR7W8.mjs.map +0 -1
- package/dist/chunks/src-Bfr1yzsn.mjs +0 -1689
- package/dist/chunks/src-Bfr1yzsn.mjs.map +0 -1
- package/dist/chunks/src-CPW2_Ons.mjs +0 -5487
- package/dist/chunks/src-CPW2_Ons.mjs.map +0 -1
- package/dist/chunks/src-Cu3TxNob.mjs +0 -783
- package/dist/chunks/src-Cu3TxNob.mjs.map +0 -1
- package/dist/chunks/src-DNsLSxgm.mjs +0 -928
- package/dist/chunks/src-DNsLSxgm.mjs.map +0 -1
- package/dist/chunks/src-DbS9gkJy.mjs +0 -117
- package/dist/chunks/src-DbS9gkJy.mjs.map +0 -1
- package/dist/chunks/src-yi5whv3n.mjs +0 -2118
- package/dist/chunks/src-yi5whv3n.mjs.map +0 -1
- package/dist/chunks/status-SMjiOMYy.mjs +0 -29
- package/dist/chunks/status-SMjiOMYy.mjs.map +0 -1
- package/dist/chunks/tail-BuhT-2PH.mjs +0 -25
- package/dist/chunks/tail-BuhT-2PH.mjs.map +0 -1
- package/dist/chunks/update-BXIppsbi.mjs +0 -16
- package/dist/chunks/update-BXIppsbi.mjs.map +0 -1
- package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs +0 -56
- package/dist/chunks/update-pipeline-Du-Gu1Pl.mjs.map +0 -1
- package/dist/cli.mjs +0 -186
- package/dist/cli.mjs.map +0 -1
package/lib/doctor.js
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Programmatic port of the /cohorte-doctor checks (core/commands/cohorte-doctor.md), so
|
|
3
|
+
// `cohorte doctor` can report without a coding agent in the loop.
|
|
4
|
+
// Read-only: inspects files only. Checks that need a live process (MCP connectivity,
|
|
5
|
+
// git worktree state, DesignSync) are reported as `skip` with a note — the node server
|
|
6
|
+
// can't run them, and honest "not checked here" beats a false green.
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const { spawnSync } = require('child_process');
|
|
11
|
+
const { parseProfileBlock, profileJsonText } = require('./yaml');
|
|
12
|
+
const { versions } = require('./versions');
|
|
13
|
+
|
|
14
|
+
// Shipped (non-surface) agent names. 3.x installs them machine-wide; a 2.x bundled repo has
|
|
15
|
+
// the bare names in its .claude/agents. Never reported as stray surface agents.
|
|
16
|
+
const FIXED_AGENTS = new Set([
|
|
17
|
+
'cohorte-review', 'cohorte-release', 'cohorte-profile-reader',
|
|
18
|
+
'review', 'release', 'profile-reader', 'smoke', 'implementer.template',
|
|
19
|
+
]);
|
|
20
|
+
const WORKFLOWS = ['cohorte-review.js', 'cohorte-audit.js', 'cohorte-refactor.js', 'cohorte-loop.js'];
|
|
21
|
+
const GATE_FILE = path.join('.claude', 'hooks', 'cohorte-gate.py');
|
|
22
|
+
const PROFILE_JSON = path.join('.claude', 'profile.json');
|
|
23
|
+
|
|
24
|
+
// The spec lifecycle (profile/schema/spec-status.md). `in-progress` and `blocked` stay valid after
|
|
25
|
+
// /cohorte-loop was retired in 2.2.0: specs in existing repos carry them, and an external driver
|
|
26
|
+
// still needs somewhere to record "a round is under way" / "a round gave up".
|
|
27
|
+
const VALID_STATUS = ['draft', 'frozen', 'in-progress', 'in-review', 'shipped', 'merged', 'blocked', 'abandoned'];
|
|
28
|
+
|
|
29
|
+
// Artifacts the pipeline itself writes into specs/ that are NOT feature specs and have no
|
|
30
|
+
// front-matter status. `/cohorte-audit` writes specs/refactor-backlog.md by design, so scanning it
|
|
31
|
+
// as a spec made /cohorte-doctor warn about a file cohorte had just created — a false positive that
|
|
32
|
+
// fired in every project that had ever run /cohorte-audit. `_`-prefixed files (e.g. _template.md)
|
|
33
|
+
// are already skipped by the reader below.
|
|
34
|
+
const NON_SPEC_FILES = new Set(['refactor-backlog.md']);
|
|
35
|
+
|
|
36
|
+
const exists = p => { try { return fs.existsSync(p); } catch { return false; } };
|
|
37
|
+
const readText = p => { try { return fs.readFileSync(p, 'utf8'); } catch { return null; } };
|
|
38
|
+
const readJson = p => { try { return JSON.parse(fs.readFileSync(p, 'utf8')); } catch { return null; } };
|
|
39
|
+
const isTrue = v => v === true;
|
|
40
|
+
const sameSet = (a, b) => {
|
|
41
|
+
const A = new Set(a || []), B = new Set(b || []);
|
|
42
|
+
if (A.size !== B.size) return false;
|
|
43
|
+
for (const x of A) if (!B.has(x)) return false;
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// Paths are reported to a human looking at a repo: show them relative to it.
|
|
48
|
+
const rel = (projectRoot) => (p) => {
|
|
49
|
+
const r = path.relative(projectRoot, p);
|
|
50
|
+
return r && !r.startsWith('..') ? r : p;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
function mk(id, label, status, detail, fix) {
|
|
54
|
+
return fix ? { id, label, status, detail, fix } : { id, label, status, detail };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// --- individual checks -------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
function checkCore(v, isProject) {
|
|
60
|
+
if (v.installMode === 'none') {
|
|
61
|
+
if (v.legacy.global.present) {
|
|
62
|
+
return mk('core', 'Core & pointer', 'bad',
|
|
63
|
+
`a 2.x core (${v.legacy.global.version}) is installed the old way, straight in ~/.claude`,
|
|
64
|
+
'npm i -g cohorte@latest && cohorte update (migrates it into ~/.claude/cohorte)');
|
|
65
|
+
}
|
|
66
|
+
return mk('core', 'Core & pointer', 'bad', 'cohorte is not installed on this machine',
|
|
67
|
+
'npm i -g cohorte && cohorte install');
|
|
68
|
+
}
|
|
69
|
+
const notes = [];
|
|
70
|
+
if (v.legacy.global.present) notes.push('2.x files still in ~/.claude (run `cohorte update` to migrate them)');
|
|
71
|
+
if (isProject && v.legacy.bundled.present) notes.push(`2.x vendored core in .claude/ (${v.legacy.bundled.version})`);
|
|
72
|
+
if (isProject && v.pointer.present && v.pointer.mode) notes.push(`2.x pointer (mode: ${v.pointer.mode})`);
|
|
73
|
+
if (notes.length) {
|
|
74
|
+
return mk('core', 'Core & pointer', 'warn', notes.join(' · '),
|
|
75
|
+
v.legacy.global.present && !(isProject && (v.legacy.bundled.present || v.pointer.mode))
|
|
76
|
+
? 'cohorte update'
|
|
77
|
+
: '/cohorte-update-pipeline (or cohorte sync — migrates this repo to the 3.x layout)');
|
|
78
|
+
}
|
|
79
|
+
if (isProject && v.pointer.present && v.pointer.core_version && v.pointer.core_version !== v.installedVersion) {
|
|
80
|
+
return mk('core', 'Core & pointer', 'warn',
|
|
81
|
+
`pointer says core ${v.pointer.core_version} but the installed core is ${v.installedVersion}`,
|
|
82
|
+
'cohorte sync (bumps .claude/pipeline.json — commit it)');
|
|
83
|
+
}
|
|
84
|
+
if (v.freshness === -1) {
|
|
85
|
+
return mk('core', 'Core & pointer', 'warn',
|
|
86
|
+
`core ${v.installedVersion} installed; npm latest is ${v.latest}`,
|
|
87
|
+
'npm i -g cohorte@latest && cohorte update');
|
|
88
|
+
}
|
|
89
|
+
const tail = v.latest ? `, npm latest ${v.latest}` : '';
|
|
90
|
+
return mk('core', 'Core & pointer', 'ok', `core ${v.installedVersion}${tail}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function checkProfile(profile, hasPipelineMd) {
|
|
94
|
+
if (!hasPipelineMd) {
|
|
95
|
+
return mk('profile', 'Profile (PIPELINE.md)', 'bad', 'PIPELINE.md not found',
|
|
96
|
+
'/cohorte-init-pipeline (generate the project profile)');
|
|
97
|
+
}
|
|
98
|
+
if (!profile) {
|
|
99
|
+
return mk('profile', 'Profile (PIPELINE.md)', 'bad',
|
|
100
|
+
'PIPELINE.md present but its `yaml pipeline-profile` block is missing or unparseable',
|
|
101
|
+
'/cohorte-init-pipeline (or fix the fenced yaml block)');
|
|
102
|
+
}
|
|
103
|
+
const n = (profile.surfaces || []).length;
|
|
104
|
+
return mk('profile', 'Profile (PIPELINE.md)', n ? 'ok' : 'warn',
|
|
105
|
+
`${profile.name || 'unnamed'} · ${n} surface${n === 1 ? '' : 's'}`,
|
|
106
|
+
n ? undefined : 'add at least one surface to §surfaces');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// `.claude/profile.json` is the parsed machine block agents read instead of the whole PIPELINE.md.
|
|
110
|
+
// The CONTENT decides freshness — compared byte for byte with what `cohorte sync` would write now,
|
|
111
|
+
// through the same serializer. Modification times alone cannot: git does not preserve them (a fresh
|
|
112
|
+
// clone can show the JSON "older" than PIPELINE.md while identical), and sync rightly leaves an
|
|
113
|
+
// identical file alone after a prose-only edit. mtime only names the likely cause of a mismatch.
|
|
114
|
+
function checkProfileJson(pipelineMd, projectRoot) {
|
|
115
|
+
const want = pipelineMd != null ? profileJsonText(pipelineMd) : null;
|
|
116
|
+
if (!want) return mk('profile-json', 'Profile cache (.claude/profile.json)', 'skip', 'no parseable profile block to cache');
|
|
117
|
+
const file = path.join(projectRoot, PROFILE_JSON);
|
|
118
|
+
const have = readText(file);
|
|
119
|
+
if (have == null) {
|
|
120
|
+
return mk('profile-json', 'Profile cache (.claude/profile.json)', 'warn',
|
|
121
|
+
'missing — agents fall back to parsing PIPELINE.md themselves (slower, costlier)',
|
|
122
|
+
'cohorte sync (writes .claude/profile.json — commit it)');
|
|
123
|
+
}
|
|
124
|
+
// A Windows checkout with core.autocrlf rewrites line endings: that is not staleness.
|
|
125
|
+
if (have.replace(/\r\n/g, '\n') !== want) {
|
|
126
|
+
let older = false;
|
|
127
|
+
try { older = fs.statSync(file).mtimeMs < fs.statSync(path.join(projectRoot, 'PIPELINE.md')).mtimeMs; } catch { /* unknown */ }
|
|
128
|
+
return mk('profile-json', 'Profile cache (.claude/profile.json)', 'warn',
|
|
129
|
+
older ? 'stale — PIPELINE.md was edited after the last sync; agents read the old machine block'
|
|
130
|
+
: 'differs from a fresh parse of PIPELINE.md (hand-edited?) — agents read the wrong machine block',
|
|
131
|
+
'cohorte sync (regenerates .claude/profile.json — commit it)');
|
|
132
|
+
}
|
|
133
|
+
if (isTracked(projectRoot, PROFILE_JSON) === false) {
|
|
134
|
+
return mk('profile-json', 'Profile cache (.claude/profile.json)', 'warn',
|
|
135
|
+
'fresh, but not committed — teammates\' agents fall back to parsing PIPELINE.md',
|
|
136
|
+
'git add .claude/profile.json && git commit');
|
|
137
|
+
}
|
|
138
|
+
return mk('profile-json', 'Profile cache (.claude/profile.json)', 'ok', 'matches PIPELINE.md');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function checkAgents(profile, projectRoot, globalDir) {
|
|
142
|
+
if (!profile || !(profile.surfaces || []).length) {
|
|
143
|
+
return mk('agents', 'Surfaces ↔ agents', 'skip', 'no surfaces to reconcile');
|
|
144
|
+
}
|
|
145
|
+
const agentsDir = path.join(projectRoot, '.claude', 'agents');
|
|
146
|
+
const surfaceAgents = profile.surfaces.map(s => s.agent).filter(Boolean);
|
|
147
|
+
const missing = surfaceAgents.filter(a => !exists(path.join(agentsDir, `${a}.md`)));
|
|
148
|
+
let files = [];
|
|
149
|
+
try { files = fs.readdirSync(agentsDir).filter(f => f.endsWith('.md')).map(f => f.slice(0, -3)); }
|
|
150
|
+
catch { /* dir absent → handled by `missing` */ }
|
|
151
|
+
const orphans = files.filter(f => !FIXED_AGENTS.has(f) && !surfaceAgents.includes(f));
|
|
152
|
+
if (missing.length) {
|
|
153
|
+
// A 2.x "global" repo rendered its surface agents into ~/.claude/agents: they still work
|
|
154
|
+
// on THIS machine, but nobody else gets them and another project can overwrite them.
|
|
155
|
+
const inGlobal = missing.filter(a => exists(path.join(globalDir, 'agents', `${a}.md`)));
|
|
156
|
+
if (inGlobal.length === missing.length) {
|
|
157
|
+
return mk('agents', 'Surfaces ↔ agents', 'warn',
|
|
158
|
+
`surface agent(s) only in ~/.claude/agents (2.x layout): ${missing.join(', ')}`,
|
|
159
|
+
'/cohorte-update-pipeline (re-renders them into .claude/agents — commit them)');
|
|
160
|
+
}
|
|
161
|
+
return mk('agents', 'Surfaces ↔ agents', 'bad',
|
|
162
|
+
`surface(s) with no rendered agent in .claude/agents: ${missing.join(', ')}`,
|
|
163
|
+
'/cohorte-update-pipeline (re-renders the surface agents)');
|
|
164
|
+
}
|
|
165
|
+
if (orphans.length) {
|
|
166
|
+
return mk('agents', 'Surfaces ↔ agents', 'warn',
|
|
167
|
+
`agent file(s) with no owning surface: ${orphans.join(', ')}`,
|
|
168
|
+
'remove the stale agent file, or add its surface to PIPELINE.md');
|
|
169
|
+
}
|
|
170
|
+
return mk('agents', 'Surfaces ↔ agents', 'ok',
|
|
171
|
+
`${surfaceAgents.length} surface agent(s) rendered in .claude/agents, no orphans`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function checkGate(profile, projectRoot) {
|
|
175
|
+
const stateDirs = [path.join(projectRoot, '.claude')];
|
|
176
|
+
const gate = profile && profile.gate;
|
|
177
|
+
if (!gate || (!gate.deny && !gate.ask && !gate.ask_on_default_branch && !gate.preflight)) {
|
|
178
|
+
return mk('gate', 'Gate config', 'skip', 'no gate block in the profile');
|
|
179
|
+
}
|
|
180
|
+
const cfgPath = stateDirs.map(d => path.join(d, 'gate-config.json')).find(exists);
|
|
181
|
+
const cfg = cfgPath ? readJson(cfgPath) : null;
|
|
182
|
+
if (!cfg) {
|
|
183
|
+
return mk('gate', 'Gate config', 'bad',
|
|
184
|
+
`gate-config.json missing or unreadable (looked in ${stateDirs.map(rel(projectRoot)).join(', ')})`,
|
|
185
|
+
'/cohorte-init-pipeline (regenerate gate-config.json from the gate block)');
|
|
186
|
+
}
|
|
187
|
+
const drifted = [];
|
|
188
|
+
if (!sameSet(cfg.deny, gate.deny)) drifted.push('deny');
|
|
189
|
+
if (!sameSet(cfg.ask, gate.ask)) drifted.push('ask');
|
|
190
|
+
if (!sameSet(cfg.ask_on_default_branch, gate.ask_on_default_branch)) drifted.push('ask_on_default_branch');
|
|
191
|
+
if ((cfg.default_branch || 'main') !== (gate.default_branch || 'main')) drifted.push('default_branch');
|
|
192
|
+
// The phase gate (1.3.0) lives in the same file: a profile that enables
|
|
193
|
+
// gate.preflight with a pre-1.3.0 gate-config.json silently never fires it.
|
|
194
|
+
const wantPf = gate.preflight || {};
|
|
195
|
+
const havePf = (cfg.preflight && typeof cfg.preflight === 'object') ? cfg.preflight : {};
|
|
196
|
+
if (!!wantPf.enabled !== !!havePf.enabled
|
|
197
|
+
|| !sameSet(wantPf.agents || ['cohorte-review'], havePf.agents || ['cohorte-review'])
|
|
198
|
+
|| Number(wantPf.max_age_minutes || 30) !== Number(havePf.max_age_minutes || 30)) {
|
|
199
|
+
drifted.push('preflight');
|
|
200
|
+
}
|
|
201
|
+
if (drifted.length) {
|
|
202
|
+
return mk('gate', 'Gate config', 'warn',
|
|
203
|
+
`gate-config.json drifted from PIPELINE.md gate block (${drifted.join(', ')})`,
|
|
204
|
+
`regenerate ${rel(projectRoot)(cfgPath)} to mirror the gate block`);
|
|
205
|
+
}
|
|
206
|
+
const branchGated = (gate.ask_on_default_branch || []).length;
|
|
207
|
+
return mk('gate', 'Gate config', 'ok',
|
|
208
|
+
`mirrors the profile (${(gate.deny || []).length} deny, ${(gate.ask || []).length} ask` +
|
|
209
|
+
(branchGated ? `, ${branchGated} gated on ${gate.default_branch || 'main'}` : '') + ')');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Local-only pipeline artifacts, under the project's `.claude` state dir. `preflight.ok` is the
|
|
213
|
+
// one that BREAKS things when versioned rather than merely being noise: the stamp names the tree
|
|
214
|
+
// it verified, committing it moves HEAD past that, and the committed copy then rides into every
|
|
215
|
+
// fresh clone and worktree — the phase gate either blocks a clean tree or greens one it never
|
|
216
|
+
// checked.
|
|
217
|
+
function localArtifacts(stateRels) {
|
|
218
|
+
const out = [];
|
|
219
|
+
for (const d of stateRels) {
|
|
220
|
+
out.push({ path: `${d}/preflight.ok`, stamp: true,
|
|
221
|
+
why: 'the phase-gate stamp — a versioned one breaks the gate in every clone and worktree' });
|
|
222
|
+
out.push({ path: `${d}/pipeline-metrics.jsonl`,
|
|
223
|
+
why: 'the per-dispatch metrics sink (local, append-only)' });
|
|
224
|
+
}
|
|
225
|
+
out.push({ path: 'specs/reports/',
|
|
226
|
+
why: 'the /cohorte-review report buffer (derived, regenerated each run)' });
|
|
227
|
+
return out;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Does any .gitignore in play cover `rel`? Deliberately literal — it recognizes the exact
|
|
231
|
+
// path, its basename, a trailing-slash dir prefix and a `*.<ext>` glob, which is every form
|
|
232
|
+
// /cohorte-init-pipeline writes. Anything more clever would need a real gitignore engine.
|
|
233
|
+
function ignoreCovers(projectRoot, rel) {
|
|
234
|
+
const base = rel.replace(/\/$/, '').split('/').pop();
|
|
235
|
+
const ext = base.includes('.') ? '*' + base.slice(base.lastIndexOf('.')) : null;
|
|
236
|
+
const files = [
|
|
237
|
+
path.join(projectRoot, '.gitignore'),
|
|
238
|
+
path.join(projectRoot, '.claude', '.gitignore'),
|
|
239
|
+
];
|
|
240
|
+
for (const f of files) {
|
|
241
|
+
const text = readText(f);
|
|
242
|
+
if (!text) continue;
|
|
243
|
+
for (let line of text.split('\n')) {
|
|
244
|
+
line = line.trim();
|
|
245
|
+
if (!line || line.startsWith('#')) continue;
|
|
246
|
+
const p = line.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
247
|
+
if (!p) continue;
|
|
248
|
+
if (p === rel.replace(/\/$/, '') || p === base || p === ext) return true;
|
|
249
|
+
// A directory rule covers everything under it (`.claude/` ignores the stamp too).
|
|
250
|
+
if (rel.startsWith(p + '/')) return true;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function checkLocalArtifacts(projectRoot, stateRels) {
|
|
257
|
+
const artifacts = localArtifacts(stateRels);
|
|
258
|
+
const unignored = artifacts.filter(a => !ignoreCovers(projectRoot, a.path));
|
|
259
|
+
if (!unignored.length) {
|
|
260
|
+
return mk('artifacts', 'Local artifacts', 'ok',
|
|
261
|
+
`${artifacts.length} local-only artifact path(s) all gitignored`);
|
|
262
|
+
}
|
|
263
|
+
const stamp = unignored.find(a => a.stamp);
|
|
264
|
+
return mk('artifacts', 'Local artifacts', stamp ? 'bad' : 'warn',
|
|
265
|
+
`not gitignored: ${unignored.map(a => a.path).join(', ')} — ${unignored[0].why}`,
|
|
266
|
+
`add ${unignored.map(a => a.path).join(' + ')} to .gitignore`
|
|
267
|
+
+ (stamp ? `, then \`git rm --cached --ignore-unmatch ${stamp.path}\`` : ''));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Our hook entries in one settings file: the 3.x project gate, or a 2.x one
|
|
271
|
+
// (`.claude/hooks/gate.py` in a repo, `<globalDir>/hooks/gate.py` machine-wide).
|
|
272
|
+
function gateEntries(settingsPath, isOurs) {
|
|
273
|
+
const data = readJson(settingsPath);
|
|
274
|
+
const list = data && data.hooks && Array.isArray(data.hooks.PreToolUse) ? data.hooks.PreToolUse : [];
|
|
275
|
+
const out = [];
|
|
276
|
+
for (const g of list) {
|
|
277
|
+
for (const h of (g && Array.isArray(g.hooks) ? g.hooks : [])) {
|
|
278
|
+
if (h && isOurs(String(h.command || '').replace(/\\/g, '/'))) out.push({ matcher: String(g.matcher || ''), command: h.command });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return out;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const matches = (matcher, name) => {
|
|
285
|
+
if (!matcher || matcher === '*') return true;
|
|
286
|
+
try { return new RegExp(`^(?:${matcher})$`).test(name); } catch { return false; }
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
function isTracked(projectRoot, rel) {
|
|
290
|
+
const r = spawnSync('git', ['-C', projectRoot, 'ls-files', '--error-unmatch', '--', rel], { stdio: 'ignore' });
|
|
291
|
+
return r.status === 0 ? true : r.status === 1 ? false : null;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function checkHooks(projectRoot, globalDir) {
|
|
295
|
+
const settingsPath = path.join(projectRoot, '.claude', 'settings.json');
|
|
296
|
+
if (exists(settingsPath) && readJson(settingsPath) == null) {
|
|
297
|
+
return mk('hooks', 'Gate hook', 'bad', '.claude/settings.json is not valid JSON — Claude Code ignores it, so no gate runs',
|
|
298
|
+
'fix the JSON, then cohorte sync');
|
|
299
|
+
}
|
|
300
|
+
const ours = gateEntries(settingsPath, c => c.includes('cohorte-gate.py'));
|
|
301
|
+
const legacyProject = gateEntries(settingsPath, c => /(^|["'\s/])\.claude\/hooks\/gate\.py/.test(c) && !c.includes('cohorte-gate.py'));
|
|
302
|
+
const legacyGlobal = gateEntries(path.join(globalDir, 'settings.json'),
|
|
303
|
+
c => c.includes(path.join(globalDir, 'hooks', 'gate.py').replace(/\\/g, '/')) || /~\/\.claude\/hooks\/gate\.py/.test(c));
|
|
304
|
+
const problems = [];
|
|
305
|
+
let status = 'ok';
|
|
306
|
+
const worst = (s) => { if (s === 'bad' || (s === 'warn' && status === 'ok')) status = s; };
|
|
307
|
+
|
|
308
|
+
const shell = ours.filter(e => matches(e.matcher, 'Bash'));
|
|
309
|
+
if (!shell.length) {
|
|
310
|
+
worst(legacyProject.length ? 'warn' : 'bad');
|
|
311
|
+
problems.push(legacyProject.length ? '2.x gate registration (.claude/hooks/gate.py)' : 'gate not registered in .claude/settings.json');
|
|
312
|
+
} else {
|
|
313
|
+
if (shell.length > 1) { worst('warn'); problems.push(`registered ${shell.length}× for Bash — it will double-prompt`); }
|
|
314
|
+
if (!shell.some(e => matches(e.matcher, 'Agent'))) {
|
|
315
|
+
worst('bad'); problems.push(`matcher "${shell[0].matcher}" does not cover Agent — the preflight phase gate never fires`);
|
|
316
|
+
}
|
|
317
|
+
if (!ours.some(e => matches(e.matcher, 'Write'))) { worst('warn'); problems.push('no Write|Edit registration — the gate files are not self-protected'); }
|
|
318
|
+
const py = spawnSync('python3', ['-c', 'import sys; sys.exit(0 if sys.version_info >= (3, 9) else 3)'], { stdio: 'ignore' });
|
|
319
|
+
if (py.status !== 0) {
|
|
320
|
+
worst('bad'); problems.push(py.status === 3 ? 'python3 is older than 3.9 — the gate cannot run'
|
|
321
|
+
: 'python3 not found — the fail-closed gate refuses every Bash call');
|
|
322
|
+
}
|
|
323
|
+
if (!exists(path.join(projectRoot, GATE_FILE))) {
|
|
324
|
+
worst('bad'); problems.push(`${GATE_FILE} is registered but missing — every Bash call is refused`);
|
|
325
|
+
} else if (isTracked(projectRoot, GATE_FILE) === false) {
|
|
326
|
+
worst('warn'); problems.push(`${GATE_FILE} is not committed — teammates get no gate`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (legacyGlobal.length) { worst('warn'); problems.push('a 2.x gate is still registered in ~/.claude/settings.json (double-prompts)'); }
|
|
330
|
+
|
|
331
|
+
if (problems.length) {
|
|
332
|
+
const onlyUncommitted = problems.length === 1 && /not committed/.test(problems[0]);
|
|
333
|
+
const blocked = problems.some((p) => /refuse|cannot run/.test(p));
|
|
334
|
+
const fix = problems.some((p) => /python3/.test(p))
|
|
335
|
+
? 'install Python ≥ 3.9 as `python3` — until then Claude Code refuses every Bash call here'
|
|
336
|
+
: blocked
|
|
337
|
+
? 'cohorte sync — from a terminal, or `! cohorte sync` in Claude Code: inside a session every call is refused'
|
|
338
|
+
: onlyUncommitted
|
|
339
|
+
? `git add ${GATE_FILE} .claude/settings.json && git commit`
|
|
340
|
+
: legacyGlobal.length && shell.length && problems.length === 1
|
|
341
|
+
? 'cohorte update (removes the 2.x machine-wide registration)'
|
|
342
|
+
: 'cohorte sync (copies and registers the project gate — then commit .claude/)';
|
|
343
|
+
return mk('hooks', 'Gate hook', status, problems.join(' · '), fix);
|
|
344
|
+
}
|
|
345
|
+
return mk('hooks', 'Gate hook', 'ok', `registered once (${shell[0].matcher} + Write|Edit|MultiEdit|NotebookEdit), committed`);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function checkRetrieval(profile, projectRoot) {
|
|
349
|
+
const provider = profile && profile.retrieval && profile.retrieval.provider;
|
|
350
|
+
if (!provider || provider === 'none' || String(provider).startsWith('<')) {
|
|
351
|
+
return mk('retrieval', 'Code retrieval', 'skip', 'provider: none');
|
|
352
|
+
}
|
|
353
|
+
// The profile alone isn't proof the provider was ever wired: /cohorte-init-pipeline
|
|
354
|
+
// registers it at project scope in .mcp.json. Verify the entry exists on disk;
|
|
355
|
+
// live connectivity still needs a session — note it, don't fake green.
|
|
356
|
+
const mcp = readJson(path.join(projectRoot, '.mcp.json'));
|
|
357
|
+
const servers = (mcp && mcp.mcpServers) || {};
|
|
358
|
+
const wired = Object.keys(servers).some(k => k.toLowerCase().includes(String(provider).toLowerCase()));
|
|
359
|
+
if (!wired) {
|
|
360
|
+
return mk('retrieval', 'Code retrieval', 'warn',
|
|
361
|
+
`profile says provider: ${provider} but .mcp.json has no matching server entry`,
|
|
362
|
+
'/cohorte-init-pipeline or /cohorte-update-pipeline (re-wire the retrieval provider)');
|
|
363
|
+
}
|
|
364
|
+
return mk('retrieval', 'Code retrieval', 'ok',
|
|
365
|
+
`provider: ${provider} — registered in .mcp.json (connectivity needs /cohorte-doctor in-session)`);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function checkDesign(profile, projectRoot) {
|
|
369
|
+
const d = profile && profile.design;
|
|
370
|
+
if (!d || !isTrue(d.enabled)) return mk('design', 'Design system', 'skip', 'design.enabled: false');
|
|
371
|
+
const targets = [['snapshot_dir', d.snapshot_dir], ['ui_kit_path', d.ui_kit_path], ['tokens_path', d.tokens_path]];
|
|
372
|
+
const missing = targets.filter(([, p]) => p && !exists(path.join(projectRoot, p))).map(([k]) => k);
|
|
373
|
+
if (missing.length) {
|
|
374
|
+
return mk('design', 'Design system', 'warn', `missing path(s): ${missing.join(', ')}`,
|
|
375
|
+
'create the missing design paths or fix them in PIPELINE.md §design');
|
|
376
|
+
}
|
|
377
|
+
return mk('design', 'Design system', 'ok', `provider: ${d.provider} — DS paths present`);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function checkIsolation(profile, projectRoot) {
|
|
381
|
+
const iso = profile && profile.isolation;
|
|
382
|
+
if (!iso || !isTrue(iso.enabled)) return mk('isolation', 'Isolation', 'skip', 'isolation.enabled: false');
|
|
383
|
+
const scripts = ['scripts/new-feature.sh', 'scripts/remove-feature.sh'];
|
|
384
|
+
const problems = [];
|
|
385
|
+
for (const rel of scripts) {
|
|
386
|
+
const txt = readText(path.join(projectRoot, rel));
|
|
387
|
+
if (txt == null) problems.push(`${rel} missing`);
|
|
388
|
+
else if (/__[A-Z_]+__/.test(txt)) problems.push(`${rel} has unrendered __TOKEN__`);
|
|
389
|
+
}
|
|
390
|
+
if (problems.length) {
|
|
391
|
+
return mk('isolation', 'Isolation', 'warn', problems.join('; '),
|
|
392
|
+
'/cohorte-init-pipeline (re-render the isolation scripts)');
|
|
393
|
+
}
|
|
394
|
+
return mk('isolation', 'Isolation', 'ok', 'feature scripts rendered (worktree state not checked here)');
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Workflow variants (review/audit/refactor as deterministic multi-agent runs) are opt-in;
|
|
398
|
+
// the conversational commands stay the default path, so nothing here is ever 'bad'.
|
|
399
|
+
function checkWorkflows(globalDir, installMode) {
|
|
400
|
+
if (installMode === 'none') return mk('workflows', 'Workflows', 'skip', 'no core installed');
|
|
401
|
+
const dir = path.join(globalDir, 'workflows');
|
|
402
|
+
const missing = WORKFLOWS.filter(s => !exists(path.join(dir, s)));
|
|
403
|
+
if (missing.length) {
|
|
404
|
+
return mk('workflows', 'Workflows', 'warn', `missing script(s) in ~/.claude/workflows: ${missing.join(', ')}`,
|
|
405
|
+
'cohorte update');
|
|
406
|
+
}
|
|
407
|
+
if (!exists(path.join(globalDir, 'agents', 'cohorte-profile-reader.md'))) {
|
|
408
|
+
return mk('workflows', 'Workflows', 'warn',
|
|
409
|
+
'scripts present but the cohorte-profile-reader agent (their phase 0) is missing', 'cohorte update');
|
|
410
|
+
}
|
|
411
|
+
return mk('workflows', 'Workflows', 'ok',
|
|
412
|
+
'scripts + cohorte-profile-reader installed — opt-in per run; needs Claude Code ≥ 2.1.154 with ' +
|
|
413
|
+
'workflows enabled (run /cohorte-doctor in-session to check the live half)');
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function scanSpecs(projectRoot) {
|
|
417
|
+
const dir = path.join(projectRoot, 'specs');
|
|
418
|
+
const specs = [];
|
|
419
|
+
let files = [];
|
|
420
|
+
try { files = fs.readdirSync(dir).filter(f => f.endsWith('.md') && !f.startsWith('_') && !NON_SPEC_FILES.has(f)); }
|
|
421
|
+
catch { return specs; }
|
|
422
|
+
for (const f of files) {
|
|
423
|
+
const txt = readText(path.join(dir, f)) || '';
|
|
424
|
+
const fm = txt.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
425
|
+
const body = fm ? fm[1] : '';
|
|
426
|
+
const get = k => { const m = body.match(new RegExp(`^${k}:\\s*(.*)$`, 'm')); return m ? m[1].trim() : null; };
|
|
427
|
+
const status = get('status');
|
|
428
|
+
// Legacy resume state from the retired /cohorte-loop driver. Nothing writes it any more;
|
|
429
|
+
// it is still read so a spec left mid-flight by an older core still shows why on the board.
|
|
430
|
+
const pass = parseInt(get('loop_pass'), 10);
|
|
431
|
+
const phase = get('loop_phase');
|
|
432
|
+
specs.push({
|
|
433
|
+
file: f,
|
|
434
|
+
id: get('feature_id') || f.replace(/\.md$/, ''),
|
|
435
|
+
title: get('title'),
|
|
436
|
+
status: status ? status.split('#')[0].trim() : null,
|
|
437
|
+
branch: get('branch'),
|
|
438
|
+
loop: pass > 0 ? { pass, phase: phase && phase !== 'done' ? phase : null } : null,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
return specs;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function checkSpecs(specs) {
|
|
445
|
+
if (!specs.length) return mk('specs', 'Specs', 'skip', 'no specs yet');
|
|
446
|
+
const bad = specs.filter(s => !VALID_STATUS.includes(s.status));
|
|
447
|
+
const counts = {};
|
|
448
|
+
for (const s of specs) counts[s.status || '?'] = (counts[s.status || '?'] || 0) + 1;
|
|
449
|
+
const summary = VALID_STATUS.filter(st => counts[st]).map(st => `${counts[st]} ${st}`).join(', ');
|
|
450
|
+
if (bad.length) {
|
|
451
|
+
return mk('specs', 'Specs', 'warn',
|
|
452
|
+
`invalid status in: ${bad.map(s => s.file).join(', ')}`,
|
|
453
|
+
`set status to one of: ${VALID_STATUS.join(' · ')}`);
|
|
454
|
+
}
|
|
455
|
+
return mk('specs', 'Specs', 'ok', `${specs.length} spec(s) — ${summary}`);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// --- orchestrator ------------------------------------------------------------
|
|
459
|
+
|
|
460
|
+
async function state({ projectRoot, globalDir, cliVersion, offline }) {
|
|
461
|
+
const v = await versions({ projectRoot, globalDir, cliVersion, offline });
|
|
462
|
+
|
|
463
|
+
const pipelineMd = readText(path.join(projectRoot, 'PIPELINE.md'));
|
|
464
|
+
const profile = pipelineMd ? parseProfileBlock(pipelineMd) : null;
|
|
465
|
+
const specs = scanSpecs(projectRoot);
|
|
466
|
+
const isProject = pipelineMd != null || v.pointer.present;
|
|
467
|
+
|
|
468
|
+
const checks = [
|
|
469
|
+
checkCore(v, isProject),
|
|
470
|
+
checkProfile(profile, pipelineMd != null),
|
|
471
|
+
checkProfileJson(pipelineMd, projectRoot),
|
|
472
|
+
checkAgents(profile, projectRoot, globalDir),
|
|
473
|
+
checkGate(profile, projectRoot),
|
|
474
|
+
checkLocalArtifacts(projectRoot, ['.claude']),
|
|
475
|
+
isProject ? checkHooks(projectRoot, globalDir)
|
|
476
|
+
: mk('hooks', 'Gate hook', 'skip', 'not a cohorte project yet (no PIPELINE.md / .claude/pipeline.json)'),
|
|
477
|
+
checkRetrieval(profile, projectRoot),
|
|
478
|
+
checkDesign(profile, projectRoot),
|
|
479
|
+
checkIsolation(profile, projectRoot),
|
|
480
|
+
checkWorkflows(globalDir, v.installMode),
|
|
481
|
+
checkSpecs(specs),
|
|
482
|
+
];
|
|
483
|
+
|
|
484
|
+
const summary = { ok: 0, warn: 0, bad: 0, skip: 0 };
|
|
485
|
+
for (const c of checks) summary[c.status]++;
|
|
486
|
+
|
|
487
|
+
return {
|
|
488
|
+
project: projectRoot,
|
|
489
|
+
runtimes: v.installMode === 'none' ? [] : [{ id: 'claude', label: 'Claude Code', scope: 'global',
|
|
490
|
+
capabilities: { subagents: true, hooks: true, workflows: true }, legacy: false }],
|
|
491
|
+
versions: v,
|
|
492
|
+
profile: profile ? {
|
|
493
|
+
name: profile.name,
|
|
494
|
+
one_liner: profile.one_liner,
|
|
495
|
+
surfaces: (profile.surfaces || []).map(s => ({
|
|
496
|
+
key: s.key, label: s.label, agent: s.agent, path: s.path,
|
|
497
|
+
model: s.model, uses_design: s.uses_design, tools: s.tools,
|
|
498
|
+
})),
|
|
499
|
+
} : null,
|
|
500
|
+
specs,
|
|
501
|
+
checks,
|
|
502
|
+
summary,
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
module.exports = { state, scanSpecs };
|