cohorte 3.1.3 → 3.3.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 CHANGED
@@ -7,6 +7,35 @@ short, user-facing, most recent first. One `## <version> — <YYYY-MM-DD>` secti
7
7
  > They are history and are deliberately not rewritten — every command gained a `cohorte-` prefix
8
8
  > in 2.0.0.
9
9
 
10
+ ## 3.3.0 — 2026-11-18
11
+
12
+ - **`cohorte ui` is now a full dashboard.** The Specs tab shows every spec as a pipeline
13
+ (Spec → Build → Review → Verify → Ship) with the **next command** to run, derived from the spec's
14
+ status and the reports the pipeline writes; opening one lists the review's findings by severity
15
+ with `file:line` and fix. Worktrees show git state (ahead/behind, dirty files, last commit), the
16
+ PR and its checks (with `gh`), the diff against the default branch, and an **Open** link for
17
+ each dev server. Updates are pushed live, a Home screen lists what is running across projects,
18
+ and the page can notify you when a run needs approval or finishes. Run history is kept across
19
+ restarts. Command palette (Ctrl/Cmd-K) and keyboard shortcuts.
20
+ - **Rebuilt in TypeScript.** The page is React + TypeScript (Vite), the server TypeScript compiled
21
+ to plain Node; both ship built, the package still has no runtime dependency. Looks like Francois
22
+ (same design tokens, dark by default, light theme).
23
+
24
+ ## 3.2.0 — 2026-11-18
25
+
26
+ - **`cohorte ui` — a local dashboard over all your Cohorte projects.** Run it in a terminal; it opens
27
+ a page on `127.0.0.1` (session token, loopback Host/Origin checks, strict CSP) listing every
28
+ registered project (add one by path, or pick from the repos Claude Code already knows). Per project:
29
+ an overview, doctor checks, specs with their reports, cost by command, worktrees (create/remove,
30
+ dev servers with live logs) and the **Docker** stack — services, health and ports, start / stop /
31
+ restart / down (never `-v`) and logs. Zero dependencies, nothing leaves the machine.
32
+ - **Run `/cohorte-*` commands from the page.** Headless `claude -p` runs with the project's gate
33
+ asked first; permission asks and interview questions are answered in the page, and a reply resumes
34
+ the same session. It talks to Claude only through Cohorte commands — it is not a chat.
35
+ - **Worktree creation checks Docker first.** `scripts/new-feature.sh` creates the worktree's database
36
+ inside a compose service, and failed late and obscurely when Docker or that service was down; the
37
+ dashboard now says so up front and offers to start the stack.
38
+
10
39
  ## 3.1.3 — 2026-11-16
11
40
 
12
41
  - **Kanban moves on macOS use a kernel lock.** macOS has no `flock(1)`, so parallel moves on one
package/bin/cli.js CHANGED
@@ -35,6 +35,7 @@ Usage:
35
35
  cohorte doctor [project] [--porcelain | --json | --panel]
36
36
  cohorte specs [project] [--porcelain | --json | --panel]
37
37
  cohorte metrics [project] [--days=N] [--since=ISO] [--runs] [--json]
38
+ cohorte ui [--port=N] [--no-open] Local dashboard over every registered project
38
39
  cohorte version
39
40
 
40
41
  Where things go:
@@ -69,7 +70,9 @@ let projectScope = false;
69
70
  const metricsFlags = [];
70
71
  const isMetricsFlag = (a) =>
71
72
  a === '--json' || a === '--runs' || a.startsWith('--days=') || a.startsWith('--since=');
72
- const VERBS = ['install', 'update', 'sync', 'uninstall', 'metrics', 'specs', 'doctor'];
73
+ const VERBS = ['install', 'update', 'sync', 'uninstall', 'metrics', 'specs', 'doctor', 'ui'];
74
+ let uiPort = 0;
75
+ let uiOpen = true;
73
76
 
74
77
  for (const a of args) {
75
78
  if (!mode && VERBS.includes(a)) mode = a;
@@ -77,6 +80,11 @@ for (const a of args) {
77
80
  else if (isMetricsFlag(a)) { if (a === '--json') format = 'json'; metricsFlags.push(a); }
78
81
  else if (a === 'version' || a === '--version' || a === '-v') { console.log(VERSION); process.exit(0); }
79
82
  else if (a === 'help' || a === '--help' || a === '-h') usage(0);
83
+ else if (a.startsWith('--port=') && mode === 'ui') {
84
+ uiPort = Number(a.slice(7));
85
+ if (!Number.isInteger(uiPort) || uiPort < 0 || uiPort > 65535) { console.error('error: --port must be 0-65535'); process.exit(2); }
86
+ }
87
+ else if (a === '--no-open' && mode === 'ui') uiOpen = false;
80
88
  else if (a === '--purge') purge = true;
81
89
  else if (a === '--project') projectScope = true;
82
90
  // 2.x flags. --global is what 3.x always does; --runtime=claude is the only runtime left.
@@ -98,8 +106,37 @@ if ((mode === 'install' || mode === 'update') && target) {
98
106
  + ' 2.x "bundled" installs (a core copied into the repo) no longer exist.');
99
107
  process.exit(2);
100
108
  }
109
+ if (mode === 'ui' && target) {
110
+ console.error('error: `cohorte ui` is a dashboard over all your projects and takes no path.\n'
111
+ + ' Add a project from the page, or open one with its own `cohorte doctor <path>`.');
112
+ process.exit(2);
113
+ }
101
114
  const project = target || process.cwd();
102
115
 
116
+ // --- dashboard ---------------------------------------------------------------
117
+ if (mode === 'ui') {
118
+ const built = path.join(__dirname, '..', 'ui', 'dist-server', 'server', 'server.js');
119
+ if (!fs.existsSync(built) || !fs.existsSync(path.join(__dirname, '..', 'ui', 'dist-web', 'index.html'))) {
120
+ console.error('error: the dashboard is not built in this checkout.\n Run `npm run build:ui` here first (the published package ships it built).');
121
+ process.exit(1);
122
+ }
123
+ const { create } = require(built);
124
+ const ui = create({ globalDir, version: VERSION });
125
+ const bye = () => { ui.jobs.stopAll(); ui.runs.stopAll(); ui.runs.flush(); process.exit(0); };
126
+ process.on('SIGINT', bye);
127
+ process.on('SIGTERM', bye);
128
+ process.on('exit', () => { ui.jobs.stopAll(); ui.runs.stopAll(); ui.runs.flush(); });
129
+ ui.listen(uiPort).then((l) => {
130
+ console.log(`cohorte ui — ${l.url}\n Local only (127.0.0.1); the link carries this session's token. Ctrl-C stops it and the dev servers it started.`);
131
+ if (uiOpen && process.stdout.isTTY) {
132
+ const [cmd, ...a] = process.platform === 'darwin' ? ['open'] : process.platform === 'win32' ? ['cmd', '/c', 'start', ''] : ['xdg-open'];
133
+ const c = spawnSync(cmd, [...a, l.url], { stdio: 'ignore' });
134
+ if (c.error) console.log(' (could not open a browser — open the link above)');
135
+ }
136
+ }).catch((e) => { console.error(`error: ${e && e.message ? e.message : e}`); process.exit(1); });
137
+ return;
138
+ }
139
+
103
140
  // --- read-only reports -------------------------------------------------------
104
141
  if (mode === 'specs' || mode === 'doctor') {
105
142
  const report = require('./report.js');
package/lib/doctor.js CHANGED
@@ -572,4 +572,4 @@ async function state({ projectRoot, globalDir, cliVersion, offline }) {
572
572
  };
573
573
  }
574
574
 
575
- module.exports = { state, scanSpecs };
575
+ module.exports = { state, scanSpecs, checkTrust };
@@ -0,0 +1,118 @@
1
+ 'use strict';
2
+ // cohorte — the list of projects the dashboard (`cohorte ui`) manages.
3
+ //
4
+ // <globalDir>/cohorte.projects.json { "version": 1, "projects": [{ "root": "/abs/path", "addedAt": "ISO" }] }
5
+ //
6
+ // A separate file on purpose: cohorte.config.yaml is the user's own, hand-edited file. The registry
7
+ // stores real paths only — the id a client sees is a hash of the path, so the HTTP layer never
8
+ // accepts a filesystem path for a read, only the id of a project that was registered.
9
+
10
+ const fs = require('fs');
11
+ const os = require('os');
12
+ const path = require('path');
13
+ const crypto = require('crypto');
14
+ const { spawnSync } = require('child_process');
15
+
16
+ const FILE = 'cohorte.projects.json';
17
+
18
+ const realOr = (p) => { try { return fs.realpathSync(p); } catch { return path.resolve(p); } };
19
+ const idOf = (root) => crypto.createHash('sha1').update(root).digest('hex').slice(0, 10);
20
+ const isDir = (p) => { try { return fs.statSync(p).isDirectory(); } catch { return false; } };
21
+ const isCohorteProject = (root) =>
22
+ fs.existsSync(path.join(root, 'PIPELINE.md')) || fs.existsSync(path.join(root, '.claude', 'pipeline.json'));
23
+
24
+ function gitTop(dir) {
25
+ const r = spawnSync('git', ['rev-parse', '--show-toplevel'], { cwd: dir, encoding: 'utf8' });
26
+ return r.status === 0 && r.stdout.trim() ? realOr(r.stdout.trim()) : null;
27
+ }
28
+
29
+ class RegistryError extends Error {}
30
+
31
+ function file(globalDir) { return path.join(globalDir, FILE); }
32
+
33
+ function load(globalDir) {
34
+ let data;
35
+ try { data = JSON.parse(fs.readFileSync(file(globalDir), 'utf8')); } catch { return []; }
36
+ const list = Array.isArray(data && data.projects) ? data.projects : [];
37
+ const seen = new Set();
38
+ const out = [];
39
+ for (const p of list) {
40
+ if (!p || typeof p.root !== 'string' || !path.isAbsolute(p.root) || seen.has(p.root)) continue;
41
+ seen.add(p.root);
42
+ out.push({ id: idOf(p.root), root: p.root, addedAt: typeof p.addedAt === 'string' ? p.addedAt : null });
43
+ }
44
+ return out;
45
+ }
46
+
47
+ function save(globalDir, projects) {
48
+ fs.mkdirSync(globalDir, { recursive: true });
49
+ const body = { version: 1, projects: projects.map((p) => ({ root: p.root, addedAt: p.addedAt })) };
50
+ const tmp = `${file(globalDir)}.${process.pid}.tmp`;
51
+ fs.writeFileSync(tmp, JSON.stringify(body, null, 2) + '\n');
52
+ fs.renameSync(tmp, file(globalDir));
53
+ }
54
+
55
+ // Registers a project by path. The path may be any folder inside the repo: the git root is stored,
56
+ // so two entries for one repo cannot exist. A missing folder or a repo without cohorte is refused.
57
+ function add(globalDir, input) {
58
+ if (typeof input !== 'string' || !input.trim()) throw new RegistryError('a project path is required');
59
+ const expanded = input.trim().replace(/^~(?=$|[\\/])/, os.homedir());
60
+ if (!path.isAbsolute(expanded)) throw new RegistryError('the path must be absolute');
61
+ if (!isDir(expanded)) throw new RegistryError(`${expanded} is not a folder`);
62
+ const root = gitTop(expanded) || realOr(expanded);
63
+ if (!isCohorteProject(root)) {
64
+ throw new RegistryError(`${root} has no PIPELINE.md or .claude/pipeline.json — run /cohorte-init-pipeline in it first`);
65
+ }
66
+ const list = load(globalDir);
67
+ const existing = list.find((p) => p.root === root);
68
+ if (existing) return { project: existing, created: false };
69
+ const project = { id: idOf(root), root, addedAt: new Date().toISOString() };
70
+ save(globalDir, list.concat([project]));
71
+ return { project, created: true };
72
+ }
73
+
74
+ function remove(globalDir, id) {
75
+ const list = load(globalDir);
76
+ const next = list.filter((p) => p.id !== id);
77
+ if (next.length === list.length) return false;
78
+ save(globalDir, next);
79
+ return true;
80
+ }
81
+
82
+ function get(globalDir, id) { return load(globalDir).find((p) => p.id === id) || null; }
83
+
84
+ // Folders Claude Code has been used in (the `projects` keys of its user store) that look like a cohorte
85
+ // project and are not registered yet. Suggestions only: nothing is added without a click.
86
+ function discover(globalDir, storePath) {
87
+ const store = storePath
88
+ || (process.env.CLAUDE_CONFIG_DIR ? path.join(process.env.CLAUDE_CONFIG_DIR, '.claude.json') : path.join(os.homedir(), '.claude.json'));
89
+ let projects = {};
90
+ try { projects = JSON.parse(fs.readFileSync(store, 'utf8')).projects || {}; } catch { return []; }
91
+ const known = new Set(load(globalDir).map((p) => p.root));
92
+ const out = [];
93
+ for (const key of Object.keys(projects)) {
94
+ if (!path.isAbsolute(key) || !isDir(key)) continue;
95
+ const root = realOr(key);
96
+ if (known.has(root) || out.some((o) => o.root === root)) continue;
97
+ if (isCohorteProject(root)) out.push({ root, name: path.basename(root) });
98
+ }
99
+ return out.sort((a, b) => a.name.localeCompare(b.name));
100
+ }
101
+
102
+ // Worktrees of one repo, from git itself. The main checkout comes first.
103
+ function worktrees(root) {
104
+ const r = spawnSync('git', ['worktree', 'list', '--porcelain'], { cwd: root, encoding: 'utf8' });
105
+ if (r.status !== 0) return [];
106
+ const out = [];
107
+ let cur = null;
108
+ for (const line of r.stdout.split('\n')) {
109
+ if (line.startsWith('worktree ')) { cur = { path: line.slice(9), branch: null, head: null, bare: false }; out.push(cur); }
110
+ else if (!cur) continue;
111
+ else if (line.startsWith('HEAD ')) cur.head = line.slice(5, 12);
112
+ else if (line.startsWith('branch ')) cur.branch = line.slice(7).replace(/^refs\/heads\//, '');
113
+ else if (line === 'bare') cur.bare = true;
114
+ }
115
+ return out;
116
+ }
117
+
118
+ module.exports = { load, add, remove, get, discover, worktrees, idOf, isCohorteProject, RegistryError, FILE };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cohorte",
3
- "version": "3.1.3",
3
+ "version": "3.3.0",
4
4
  "description": "Multi-agent development pipeline for Claude Code — install it once, run /cohorte-init-pipeline in a repo, and it adapts to that project's stack.",
5
5
  "bin": {
6
6
  "cohorte": "bin/cli.js"
@@ -11,6 +11,8 @@
11
11
  "core",
12
12
  "profile",
13
13
  "scripts",
14
+ "ui/dist-server",
15
+ "ui/dist-web",
14
16
  "!scripts/new-feature.sh",
15
17
  "!scripts/remove-feature.sh",
16
18
  "!scripts/demo",
@@ -26,7 +28,10 @@
26
28
  "CHANGELOG.md"
27
29
  ],
28
30
  "scripts": {
29
- "test": "node scripts/validate-core.mjs && node scripts/test-install.mjs && node scripts/test-gate.mjs && node scripts/test-lib.mjs && node scripts/test-workflows.mjs && node scripts/test-kanban.mjs && node scripts/test-metrics.mjs && node scripts/test-e2e.mjs && node scripts/test-verify.mjs"
31
+ "build:ui": "node scripts/build-ui.mjs",
32
+ "prepack": "npm run build:ui",
33
+ "pretest": "npm run build:ui",
34
+ "test": "node scripts/validate-core.mjs && node scripts/test-install.mjs && node scripts/test-gate.mjs && node scripts/test-lib.mjs && node scripts/test-workflows.mjs && node scripts/test-kanban.mjs && node scripts/test-metrics.mjs && node scripts/test-e2e.mjs && node scripts/test-verify.mjs && node scripts/test-ui.mjs"
30
35
  },
31
36
  "engines": {
32
37
  "node": ">=20"
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env node
2
+ // Builds the dashboard (ui/): installs its build tooling, then compiles the server (tsc) and the page (vite)
3
+ // into ui/dist-server and ui/dist-web — the only parts of ui/ that ship. Run by `npm run build:ui`, by
4
+ // `prepack`, and by CI before the dashboard's tests.
5
+ //
6
+ // node scripts/build-ui.mjs [--no-install]
7
+
8
+ import { spawnSync } from "node:child_process";
9
+ import { fileURLToPath } from "node:url";
10
+ import { existsSync } from "node:fs";
11
+ import { join } from "node:path";
12
+
13
+ const ui = fileURLToPath(new URL("../ui", import.meta.url));
14
+ const win = process.platform === "win32";
15
+ const install = !process.argv.includes("--no-install") || !existsSync(join(ui, "node_modules"));
16
+
17
+ // A user-level `allow-scripts` setting reaches child npm processes as npm_config_allow_scripts, which npm
18
+ // (11.x) rejects for project-scoped installs — and it is no business of this build.
19
+ const env = { ...process.env };
20
+ for (const k of Object.keys(env)) if (/^npm_config_allow[-_]scripts$/i.test(k)) delete env[k];
21
+
22
+ const step = (args) => {
23
+ const r = spawnSync(win ? "npm.cmd" : "npm", args, { cwd: ui, stdio: "inherit", env, shell: win });
24
+ if (r.status !== 0) { console.error(`\nbuild-ui: \`npm ${args.join(" ")}\` failed (${r.status ?? r.error?.message})`); process.exit(r.status || 1); }
25
+ };
26
+
27
+ if (install) step(["ci", "--no-audit", "--no-fund"]);
28
+ step(["run", "build"]);
@@ -0,0 +1,209 @@
1
+ "use strict";
2
+ // cohorte ui — the project's Docker Compose stack: what is up, and the few things the dashboard may do to it.
3
+ //
4
+ // Same rules as ops.js:
5
+ // - the compose file is the one the profile declares (isolation.compose_file) or a conventional name at the
6
+ // repo root, resolved INSIDE the repo — never a path from the client;
7
+ // - the verbs are fixed (up -d, stop, restart, down, logs); `down` never takes -v, so volumes (the data) stay;
8
+ // - a service name from the client is only accepted when `docker compose config --services` lists it;
9
+ // - the project's gate is asked first, like every other command this dashboard launches.
10
+ // Reads (daemon, ps) never go through a shell and are bounded by a timeout so a hung daemon cannot hang the page.
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ACTIONS = void 0;
16
+ exports.composeFile = composeFile;
17
+ exports.parsePs = parsePs;
18
+ exports.status = status;
19
+ exports.act = act;
20
+ exports.preflight = preflight;
21
+ const fs_1 = __importDefault(require("fs"));
22
+ const path_1 = __importDefault(require("path"));
23
+ const child_process_1 = require("child_process");
24
+ const ops_1 = require("./ops");
25
+ const CANDIDATES = ['compose.yaml', 'compose.yml', 'docker-compose.yaml', 'docker-compose.yml'];
26
+ exports.ACTIONS = ['up', 'stop', 'restart', 'down', 'logs'];
27
+ const bin = () => process.env.COHORTE_DOCKER_BIN || 'docker';
28
+ const realOr = (p) => { try {
29
+ return fs_1.default.realpathSync(p);
30
+ }
31
+ catch {
32
+ return path_1.default.resolve(p);
33
+ } };
34
+ // { file, rel } or null. The declared file wins; it must stay inside the repo.
35
+ function composeFile(root) {
36
+ const declared = (0, ops_1.readProfile)(root).isolation?.compose_file;
37
+ const names = typeof declared === 'string' && declared.trim() ? [declared.trim(), ...CANDIDATES] : CANDIDATES;
38
+ const base = realOr(root);
39
+ for (const n of names) {
40
+ if (path_1.default.isAbsolute(n))
41
+ continue;
42
+ const file = realOr(path_1.default.join(root, n));
43
+ if (!file.startsWith(base + path_1.default.sep))
44
+ continue;
45
+ try {
46
+ if (fs_1.default.statSync(file).isFile())
47
+ return { file, rel: path_1.default.relative(base, file) };
48
+ }
49
+ catch { /* next */ }
50
+ }
51
+ return null;
52
+ }
53
+ function exec(args, { cwd, timeout = 8000 } = {}) {
54
+ return new Promise((resolve) => {
55
+ let out = '';
56
+ let err = '';
57
+ let done = false;
58
+ const finish = (r) => { if (!done) {
59
+ done = true;
60
+ clearTimeout(timer);
61
+ resolve({ code: null, out, err, ...r });
62
+ } };
63
+ let child;
64
+ try {
65
+ child = (0, child_process_1.spawn)(bin(), args, { cwd, stdio: ['ignore', 'pipe', 'pipe'] });
66
+ }
67
+ catch (e) {
68
+ const x = e;
69
+ return resolve({ code: -1, out, err: x.message, missing: x.code === 'ENOENT' });
70
+ }
71
+ const timer = setTimeout(() => { try {
72
+ child.kill('SIGKILL');
73
+ }
74
+ catch { /* gone */ } finish({ code: -1, timedOut: true }); }, timeout);
75
+ child.stdout?.on('data', (d) => { out += d; if (out.length > 2e6)
76
+ out = out.slice(-2e6); });
77
+ child.stderr?.on('data', (d) => { err += d; if (err.length > 2e5)
78
+ err = err.slice(-2e5); });
79
+ child.on('error', (e) => finish({ code: -1, missing: e.code === 'ENOENT', err: e.message }));
80
+ child.on('close', (code) => finish({ code }));
81
+ });
82
+ }
83
+ const firstLine = (s) => String(s || '').trim().split(/\r?\n/).find((l) => l.trim()) || '';
84
+ // `docker compose ps --format json` prints one object per line on recent versions, a JSON array on older ones.
85
+ function parsePs(out) {
86
+ const text = String(out || '').trim();
87
+ if (!text)
88
+ return [];
89
+ let rows = [];
90
+ try {
91
+ const v = JSON.parse(text);
92
+ rows = Array.isArray(v) ? v : [v];
93
+ }
94
+ catch {
95
+ for (const l of text.split(/\r?\n/)) {
96
+ try {
97
+ rows.push(JSON.parse(l));
98
+ }
99
+ catch { /* not a row */ }
100
+ }
101
+ }
102
+ return rows.filter((r) => r && typeof r === 'object');
103
+ }
104
+ function portsOf(row) {
105
+ const pubs = Array.isArray(row.Publishers) ? row.Publishers : [];
106
+ const seen = new Set();
107
+ for (const p of pubs)
108
+ if (p && p.PublishedPort)
109
+ seen.add(`${p.PublishedPort}→${p.TargetPort}`);
110
+ return [...seen];
111
+ }
112
+ async function daemon() {
113
+ const r = await exec(['info', '--format', '{{.ServerVersion}}'], { timeout: 6000 });
114
+ if (r.missing)
115
+ return { installed: false, up: false, error: 'the docker CLI is not installed (or not on PATH)' };
116
+ if (r.timedOut)
117
+ return { installed: true, up: false, error: 'the Docker daemon did not answer in time' };
118
+ if (r.code !== 0)
119
+ return { installed: true, up: false, error: firstLine(r.err) || 'the Docker daemon is not running' };
120
+ return { installed: true, up: true, version: firstLine(r.out) };
121
+ }
122
+ // Everything the Docker tab shows. Each part degrades alone: no daemon still lists the declared services.
123
+ async function status(root) {
124
+ const cf = composeFile(root);
125
+ if (!cf)
126
+ return { configured: false };
127
+ const [d, cfg] = await Promise.all([daemon(), exec(['compose', '-f', cf.file, 'config', '--services'], { cwd: root })]);
128
+ const defined = cfg.code === 0 ? cfg.out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean) : [];
129
+ const out = { configured: true, file: cf.rel, daemon: d, services: [], configError: cfg.code === 0 ? null : firstLine(cfg.err) || 'docker compose could not read the file' };
130
+ let rows = [];
131
+ if (d.up && defined.length) {
132
+ const ps = await exec(['compose', '-f', cf.file, 'ps', '-a', '--format', 'json'], { cwd: root });
133
+ if (ps.code === 0)
134
+ rows = parsePs(ps.out);
135
+ else
136
+ out.psError = firstLine(ps.err);
137
+ }
138
+ const by = new Map();
139
+ for (const r of rows)
140
+ by.set(r.Service || r.Name, r);
141
+ const names = defined.length ? defined : [...by.keys()];
142
+ out.services = names.map((name) => {
143
+ const r = by.get(name);
144
+ if (!r)
145
+ return { name, state: d.up ? 'not created' : 'unknown', health: '', status: '', ports: [], image: '' };
146
+ return { name, state: String(r.State || '').toLowerCase() || 'unknown', health: String(r.Health || '').toLowerCase(), status: String(r.Status || ''), ports: portsOf(r), image: String(r.Image || '') };
147
+ });
148
+ out.running = out.services.filter((s) => s.state === 'running').length;
149
+ return out;
150
+ }
151
+ // Starts up/stop/restart/down/logs as a job. Returns the job.
152
+ async function act(jobs, project, { action, service, confirmed = false }) {
153
+ if (typeof action !== 'string' || !exports.ACTIONS.includes(action))
154
+ throw new ops_1.OpError(`action must be one of ${exports.ACTIONS.join(', ')}`);
155
+ const cf = composeFile(project.root);
156
+ if (!cf)
157
+ throw new ops_1.OpError('this project declares no compose file (isolation.compose_file)', 400);
158
+ const d = await daemon();
159
+ if (!d.up)
160
+ throw new ops_1.OpError(d.error || 'the Docker daemon is not running', 409, { dockerDown: true });
161
+ let svc = null;
162
+ if (service !== undefined && service !== null && service !== '') {
163
+ if (action === 'down')
164
+ throw new ops_1.OpError('down applies to the whole stack');
165
+ const cfg = await exec(['compose', '-f', cf.file, 'config', '--services'], { cwd: project.root });
166
+ const defined = cfg.out.split(/\r?\n/).map((s) => s.trim()).filter(Boolean);
167
+ if (typeof service !== 'string' || !defined.includes(service))
168
+ throw new ops_1.OpError('not a service of this compose file', 404);
169
+ svc = service;
170
+ }
171
+ const verb = { up: ['up', '-d'], stop: ['stop'], restart: ['restart'], down: ['down'], logs: ['logs', '--no-color', '--tail', '200', '-f'] }[action];
172
+ const args = ['compose', '-f', cf.file, ...verb, ...(svc ? [svc] : [])];
173
+ const shown = `docker compose -f ${cf.rel} ${verb.join(' ')}${svc ? ` ${svc}` : ''}`;
174
+ const kind = action === 'logs' ? 'docker-logs' : 'docker';
175
+ const tag = action === 'logs' ? (svc || '*') : 'stack';
176
+ if (jobs.find(project.id, kind, tag))
177
+ throw new ops_1.OpError(action === 'logs' ? 'these logs are already being followed' : 'a docker command is already running for this project', 409);
178
+ (0, ops_1.confirm)((0, ops_1.gateVerdict)(project.root, shown, project.root), confirmed, shown);
179
+ return jobs.start({ projectId: project.id, kind, tag, label: `docker · ${verb[0]}${svc ? ` ${svc}` : ''}`, cwd: project.root, file: bin(), args, display: shown });
180
+ }
181
+ // Before `scripts/new-feature.sh`: the script creates the worktree's database INSIDE a compose service
182
+ // (`docker compose exec -T postgres …`), so it fails — late and obscurely — when Docker or that service is down.
183
+ // Returns null when the script needs nothing, else { ok, reason, services, missing }.
184
+ async function preflight(root) {
185
+ const cf = composeFile(root);
186
+ let script = '';
187
+ try {
188
+ script = fs_1.default.readFileSync(path_1.default.join(root, 'scripts', 'new-feature.sh'), 'utf8');
189
+ }
190
+ catch {
191
+ return null;
192
+ }
193
+ if (!cf || !/\bdocker\b/.test(script))
194
+ return null;
195
+ const needs = new Set();
196
+ const re = /docker\s+compose[^\n]*?\bexec\b\s+(?:-[A-Za-z-]+\s+)*([A-Za-z][\w.-]*)/g;
197
+ for (let m = re.exec(script); m; m = re.exec(script))
198
+ needs.add(m[1]);
199
+ const s = await status(root);
200
+ const dm = s.daemon;
201
+ if (!dm.installed)
202
+ return { ok: false, reason: dm.error || '', services: [...needs], missing: [...needs], daemonUp: false };
203
+ if (!dm.up)
204
+ return { ok: false, reason: `${dm.error || 'the Docker daemon is not running'} — scripts/new-feature.sh needs it to create the worktree's database`, services: [...needs], missing: [...needs], daemonUp: false };
205
+ const down = [...needs].filter((n) => { const x = (s.services || []).find((v) => v.name === n); return !x || x.state !== 'running'; });
206
+ if (down.length)
207
+ return { ok: false, reason: `scripts/new-feature.sh runs commands inside ${down.join(', ')}, which ${down.length > 1 ? 'are' : 'is'} not running`, services: [...needs], missing: down, daemonUp: true };
208
+ return { ok: true, reason: '', services: [...needs], missing: [], daemonUp: true };
209
+ }
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ // Reads a REVIEW REPORT (specs/reports/<id>.md, the shape in core/agents/cohorte-review.md) into rows.
3
+ // One line per finding: - **[SEVERITY]** `file:line` · category · problem → **Fix:** change [· out of scope: why]
4
+ // Anything that does not match stays out: the page also offers the raw report, so a drifting prompt costs rows, not truth.
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseFinding = parseFinding;
7
+ exports.parseReviewReport = parseReviewReport;
8
+ const SEVERITIES = ['CRITICAL', 'HIGH', 'MEDIUM', 'LOW'];
9
+ const LINE = /^\s*[-*]\s+\*\*\[(CRITICAL|HIGH|MEDIUM|LOW)\]\*\*\s*(.*)$/i;
10
+ function parseFinding(line) {
11
+ const m = LINE.exec(line);
12
+ if (!m)
13
+ return null;
14
+ let rest = m[2].trim();
15
+ const severity = m[1].toUpperCase();
16
+ let file = '';
17
+ let ln = null;
18
+ const loc = /^`([^`]+)`\s*(?:·|—|-)?\s*(.*)$/.exec(rest);
19
+ if (loc) {
20
+ rest = loc[2];
21
+ const pos = /^(.*?):(\d+)(?:[-–]\d+)?$/.exec(loc[1]);
22
+ file = pos ? pos[1] : loc[1];
23
+ ln = pos ? Number(pos[2]) : null;
24
+ }
25
+ const parts = rest.split(/\s+·\s+/);
26
+ let category = '';
27
+ if (parts.length > 1 && /^(spec-violation|quality|security|complexity)$/i.test(parts[0].trim()))
28
+ category = parts.shift().trim().toLowerCase();
29
+ let body = parts.join(' · ');
30
+ let scope = '';
31
+ const oos = /\s*·\s*out of scope:\s*(.*)$/i.exec(body);
32
+ if (oos) {
33
+ scope = oos[1].trim();
34
+ body = body.slice(0, oos.index);
35
+ }
36
+ const fix = /^(.*?)\s*(?:→|->)\s*\*\*Fix:\*\*\s*(.*)$/s.exec(body);
37
+ return { severity, file, line: ln, category, problem: (fix ? fix[1] : body).trim(), fix: fix ? fix[2].trim() : '', outOfScope: scope };
38
+ }
39
+ function parseReviewReport(md) {
40
+ const out = { findings: [], deferred: [], verdict: null };
41
+ let section = null;
42
+ for (const raw of md.split(/\r?\n/)) {
43
+ const h = /^##\s+(.*)$/.exec(raw);
44
+ if (h) {
45
+ const t = h[1].trim().toLowerCase();
46
+ section = t.startsWith('findings') ? 'findings' : t.startsWith('deferred') ? 'deferred' : null;
47
+ continue;
48
+ }
49
+ const v = /^Verdict:\s*(SHIP|REVISE|BLOCK)\b/i.exec(raw);
50
+ if (v) {
51
+ out.verdict = v[1].toUpperCase();
52
+ continue;
53
+ }
54
+ if (!section)
55
+ continue;
56
+ const f = parseFinding(raw);
57
+ if (f)
58
+ out[section].push(f);
59
+ }
60
+ const rank = (s) => SEVERITIES.indexOf(s);
61
+ out.findings.sort((a, b) => rank(a.severity) - rank(b.severity));
62
+ out.deferred.sort((a, b) => rank(a.severity) - rank(b.severity));
63
+ return out;
64
+ }