great-cto 3.32.0 → 3.33.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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "great-cto",
3
3
  "description": "You already have the agent. This is everything around it. great_cto runs Claude Code as a pipeline of 70 specialist agents \u2014 an independent model checks each stage before the next builds on it, spending caps refuse rather than warn, and three decisions stay yours: what gets built, how, and whether it ships.",
4
- "version": "3.32.0",
4
+ "version": "3.33.0",
5
5
  "author": {
6
6
  "name": "Alexander Velikiy",
7
7
  "url": "https://hashnode.com/@Greatcto"
@@ -10,6 +10,7 @@
10
10
  * cost_summary — LLM spend, budget burn, top features
11
11
  * pipeline_stages — detailed stage list with verdicts
12
12
  * recent_verdicts — last N agent verdicts (default 10)
13
+ * wait_for_board_change — block until a verdict lands or a session is blocked
13
14
  *
14
15
  * Usage:
15
16
  * # Start as MCP server (board must be running on --port)
@@ -31,6 +32,7 @@
31
32
  */
32
33
 
33
34
  import { createInterface } from 'node:readline';
35
+ import { waitForChange } from '../../scripts/lib/board-watch.mjs';
34
36
 
35
37
  const PORT = parseInt(process.env.GREAT_CTO_PORT || '3141', 10);
36
38
  const BASE_URL = `http://127.0.0.1:${PORT}`;
@@ -115,6 +117,23 @@ const TOOLS = [
115
117
  },
116
118
  },
117
119
  },
120
+ {
121
+ name: 'wait_for_board_change',
122
+ description:
123
+ 'Blocks until something in this project needs you — an agent wrote a verdict ' +
124
+ '(BLOCKED/FAIL first), or a session stopped on a permission prompt — then returns ' +
125
+ 'only those changes. Use it instead of polling status in a loop while parallel ' +
126
+ 'work runs: one call, not a sleep-and-list per turn. Call first with no `since` ' +
127
+ 'to get a cursor; pass the returned `cursor` back each time so nothing between ' +
128
+ 'calls is missed. Reads the project files directly; the board need not be running.',
129
+ inputSchema: {
130
+ type: 'object',
131
+ properties: {
132
+ since: { type: 'string', description: 'Cursor from the previous call. Omit on the first call.' },
133
+ timeout_s: { type: 'number', description: 'Longest wait in seconds (1–600). Default: 300.' },
134
+ },
135
+ },
136
+ },
118
137
  ];
119
138
 
120
139
  // ── HTTP helpers ───────────────────────────────────────────────────────────
@@ -245,6 +264,12 @@ async function callTool(name, args = {}) {
245
264
  return lines.join('\n');
246
265
  }
247
266
 
267
+ if (name === 'wait_for_board_change') {
268
+ // The MCP server runs in the project directory (codex-host starts it there).
269
+ const r = await waitForChange({ cwd: process.cwd(), since: args.since || null, timeoutS: args.timeout_s || 300 });
270
+ return JSON.stringify(r);
271
+ }
272
+
248
273
  throw new Error(`Unknown tool: ${name}`);
249
274
  }
250
275
 
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * board-watch — wait until something in this project needs the caller, then say
4
+ * what. One blocking call instead of a polling loop.
5
+ *
6
+ * Why this exists
7
+ * ---------------
8
+ * An orchestrator waiting on parallel work (coordinator, codex-host) has no way to
9
+ * wait: it sleeps, lists, sleeps, lists, and every round trip is a turn. On the
10
+ * projects measured on 2026-09-21, 69 agent runs ended at their turn cap.
11
+ * fynnfluegge/agtx (Apache-2.0) counted the same cost in one 14-task run — 73
12
+ * sleeps and 96 listings — and replaced it with `wait_for_board_change`: block,
13
+ * and return only the changes that need the caller. Written here, from files the
14
+ * project already has, so it needs no board process:
15
+ *
16
+ * verdict an agent wrote a new verdict (its value and kind: negative first)
17
+ * blocked a session stopped on a permission prompt or an unanswered wait
18
+ *
19
+ * The cursor is the snapshot the caller last saw, so a change that happens between
20
+ * two calls is never missed: pass back the `cursor` from the previous answer.
21
+ *
22
+ * Usage:
23
+ * node scripts/lib/board-watch.mjs [--since <cursor>] [--timeout 300] [--cwd DIR]
24
+ * → one JSON line: { cursor, changes: [...], timedOut }
25
+ * With no --since it answers at once with the current cursor and nothing else.
26
+ */
27
+ import { fileURLToPath } from 'node:url';
28
+ import { latestVerdicts } from './ship-evidence.mjs';
29
+ import { readSessionStatus } from './session-status.mjs';
30
+
31
+ export const MAX_TIMEOUT_S = 600;
32
+
33
+ /** What the caller could need to react to, reduced to comparable keys. */
34
+ export function snapshot(cwd, { now = Date.now() } = {}) {
35
+ const verdicts = {};
36
+ for (const [agent, v] of latestVerdicts(cwd)) verdicts[agent] = { verdict: v.verdict, ts: v.ts, kind: v.kind };
37
+ const blocked = {};
38
+ for (const s of readSessionStatus(cwd, { now })) {
39
+ if (s.state === 'blocked') blocked[s.session] = { since: s.since, reason: s.reason || '' };
40
+ }
41
+ return { verdicts, blocked };
42
+ }
43
+
44
+ /** Changes from `prev` to `next` that need the caller, most urgent first. */
45
+ export function diffSnapshots(prev, next) {
46
+ const out = [];
47
+ for (const [agent, v] of Object.entries(next.verdicts || {})) {
48
+ const p = prev.verdicts?.[agent];
49
+ if (!p || p.ts !== v.ts || p.verdict !== v.verdict) out.push({ type: 'verdict', agent, verdict: v.verdict, kind: v.kind, ts: v.ts });
50
+ }
51
+ for (const [session, b] of Object.entries(next.blocked || {})) {
52
+ const p = prev.blocked?.[session];
53
+ if (!p || p.since !== b.since) out.push({ type: 'blocked', session, reason: b.reason, since: b.since });
54
+ }
55
+ const rank = (c) => (c.type === 'blocked' ? 0 : c.kind === 'negative' ? 1 : 2);
56
+ return out.sort((a, b) => rank(a) - rank(b));
57
+ }
58
+
59
+ export const encodeCursor = (snap) => Buffer.from(JSON.stringify(snap)).toString('base64url');
60
+ export function decodeCursor(c) {
61
+ try { return JSON.parse(Buffer.from(String(c), 'base64url').toString('utf8')); } catch { return null; }
62
+ }
63
+
64
+ /**
65
+ * Block until a change needs the caller, or the timeout passes.
66
+ * @returns {Promise<{cursor:string, changes:object[], timedOut:boolean, note?:string}>}
67
+ */
68
+ export async function waitForChange({ cwd = process.cwd(), since = null, timeoutS = 300, pollMs = 2000, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
69
+ const first = snapshot(cwd);
70
+ const prev = since ? decodeCursor(since) : null;
71
+ if (!prev) {
72
+ return { cursor: encodeCursor(first), changes: [], timedOut: false, note: since ? 'unreadable cursor — here is a fresh one' : 'first call — pass this cursor back to wait' };
73
+ }
74
+ const deadline = Date.now() + Math.min(MAX_TIMEOUT_S, Math.max(1, timeoutS)) * 1000;
75
+ let snap = first;
76
+ for (;;) {
77
+ const changes = diffSnapshots(prev, snap);
78
+ if (changes.length) return { cursor: encodeCursor(snap), changes, timedOut: false };
79
+ if (Date.now() >= deadline) return { cursor: encodeCursor(snap), changes: [], timedOut: true };
80
+ await sleep(Math.min(pollMs, Math.max(0, deadline - Date.now())));
81
+ snap = snapshot(cwd);
82
+ }
83
+ }
84
+
85
+ const isMain = process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1];
86
+ if (isMain) {
87
+ const a = process.argv.slice(2);
88
+ const opt = (k, d) => { const i = a.indexOf(k); return i >= 0 ? a[i + 1] : d; };
89
+ const r = await waitForChange({ cwd: opt('--cwd', process.cwd()), since: opt('--since', null), timeoutS: Number(opt('--timeout', 300)) });
90
+ process.stdout.write(`${JSON.stringify(r)}\n`);
91
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * ship-evidence — what the verdict logs say about whether gate:ship may pass.
3
+ *
4
+ * Read across the 16 projects with verdicts on the measuring machine (2026-09-21):
5
+ *
6
+ * - a healthcare-reviewer BLOCKED was never followed by a later verdict of its
7
+ * own, and the task it blocked was closed an hour later;
8
+ * - 11 of the 16 had no qa-engineer verdict at all;
9
+ * - great_cto's own last QA verdict was three weeks older than its last ship.
10
+ *
11
+ * gate-check read Beads task states and required domain reviewers; it read no
12
+ * verdict's VALUE. This does, three rules:
13
+ *
14
+ * 1. An agent whose LATEST verdict is negative (BLOCKED, FAIL, REJECTED, REWORK)
15
+ * has an open finding. A later positive verdict from the same agent closes it.
16
+ * 2. qa-engineer and security-officer must each have a positive latest verdict.
17
+ * 3. Both must be newer than the last commit that changed code — a verdict from
18
+ * before the change it is supposed to cover is not evidence about it.
19
+ *
20
+ * Agent names are read from the log's file name and normalised: the same agent
21
+ * was found logged as `code-reviewer`, `great-cto:code-reviewer`,
22
+ * `great_cto:code-reviewer`, and QA as both `qa` and `qa-engineer`.
23
+ */
24
+ import { readdirSync, readFileSync } from 'node:fs';
25
+ import { join } from 'node:path';
26
+ import { spawnSync } from 'node:child_process';
27
+ import { parseVerdictLog } from './verdict-record.mjs';
28
+
29
+ export const MANDATORY_FOR_SHIP = ['qa-engineer', 'security-officer'];
30
+
31
+ const ALIASES = { qa: 'qa-engineer', security: 'security-officer', sec: 'security-officer' };
32
+
33
+ /** `great-cto:qa`, `great_cto:qa-engineer`, `qa` → `qa-engineer`. */
34
+ export function canonicalAgent(name) {
35
+ const bare = String(name || '').trim().toLowerCase().replace(/^.*:/, '').replace(/\.log$/, '');
36
+ return ALIASES[bare] || bare;
37
+ }
38
+
39
+ /** negative | positive | neutral, from a verdict value in any dialect written so far. */
40
+ export function verdictKind(v) {
41
+ const s = String(v || '').toUpperCase();
42
+ if (/^(BLOCKED|FAIL|FAILED|REJECTED|REWORK)\b/.test(s)) return 'negative';
43
+ // `APPROVED_WITH_DEFERRED_CRITICALS` and friends are approvals that name open
44
+ // criticals; they are not a clean pass and are read as negative.
45
+ if (/^APPROVED.*(DEFERRED|CRITICAL)/.test(s)) return 'negative';
46
+ if (/^(APPROVED|PASS|PASSED|DONE|OK)\b/.test(s)) return 'positive';
47
+ return 'neutral';
48
+ }
49
+
50
+ const tsOf = (ts) => { const t = Date.parse(ts); return Number.isFinite(t) ? t : null; };
51
+
52
+ /**
53
+ * The latest verdict per agent in `<dir>/.great_cto/verdicts/`.
54
+ * `gate:*.log` files record gate decisions, not an agent's verdict, and are skipped.
55
+ * @returns {Map<string, {verdict:string, ts:string, kind:string}>}
56
+ */
57
+ export function latestVerdicts(projectDir) {
58
+ const dir = join(projectDir, '.great_cto', 'verdicts');
59
+ const out = new Map();
60
+ let files = [];
61
+ try { files = readdirSync(dir).filter((f) => f.endsWith('.log') && !f.startsWith('gate')); } catch { return out; }
62
+ for (const f of files) {
63
+ const agent = canonicalAgent(f);
64
+ let text = '';
65
+ try { text = readFileSync(join(dir, f), 'utf8'); } catch { continue; }
66
+ for (const rec of parseVerdictLog(text, { agent }).records) {
67
+ const t = tsOf(rec.ts);
68
+ if (t === null) continue;
69
+ const prev = out.get(agent);
70
+ if (!prev || t >= tsOf(prev.ts)) out.set(agent, { verdict: rec.verdict, ts: rec.ts, kind: verdictKind(rec.verdict) });
71
+ }
72
+ }
73
+ return out;
74
+ }
75
+
76
+ /** ISO time of the last commit that changed something other than docs and pipeline records. */
77
+ export function lastCodeChange(projectDir) {
78
+ const r = spawnSync('git', ['log', '-1', '--format=%cI', '--', '.',
79
+ ':(exclude).great_cto', ':(exclude)docs', ':(exclude)*.md', ':(exclude).beads'],
80
+ { cwd: projectDir, encoding: 'utf8', timeout: 10_000 });
81
+ return r.status === 0 && r.stdout.trim() ? r.stdout.trim() : null;
82
+ }
83
+
84
+ /**
85
+ * @param {Map} latest from latestVerdicts()
86
+ * @param {string|null} lastChange from lastCodeChange()
87
+ * @param {{as?: string}} opts `as`: the agent running this check about its own
88
+ * verdict — its own latest is not held against it.
89
+ * @returns {{agent:string, why:string}[]} what blocks gate:ship, each with its reason
90
+ */
91
+ export function shipBlockers(latest, lastChange, { as } = {}) {
92
+ const self = as ? canonicalAgent(as) : null;
93
+ const out = [];
94
+ for (const [agent, v] of latest) {
95
+ if (agent === self || v.kind !== 'negative') continue;
96
+ out.push({ agent, why: `latest verdict ${v.verdict} (${v.ts}) — no later verdict from ${agent} closes it` });
97
+ }
98
+ for (const agent of MANDATORY_FOR_SHIP) {
99
+ if (agent === self) continue;
100
+ const v = latest.get(agent);
101
+ if (!v) { out.push({ agent, why: 'no verdict in this project' }); continue; }
102
+ if (v.kind === 'neutral') out.push({ agent, why: `latest verdict ${v.verdict} is not a pass` });
103
+ }
104
+ // A verdict counts for the code it saw. Both post-implementation checks must be
105
+ // newer than the last code change; agtx (fynnfluegge/agtx) applies the same rule
106
+ // to a phase artifact — only one written after the phase began counts.
107
+ for (const agent of MANDATORY_FOR_SHIP) {
108
+ if (agent === self) continue;
109
+ const v = latest.get(agent);
110
+ if (v && v.kind === 'positive' && lastChange && tsOf(v.ts) !== null && tsOf(v.ts) < tsOf(lastChange)) {
111
+ out.push({ agent, why: `verdict ${v.ts} predates the last code change ${lastChange} — re-run ${agent} on what ships` });
112
+ }
113
+ }
114
+ return out;
115
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "great-cto",
3
- "version": "3.32.0",
3
+ "version": "3.33.0",
4
4
  "description": "One command install for the great_cto Claude Code plugin. Auto-detects your stack, picks the right archetype, bootstraps PROJECT.md.",
5
5
  "keywords": [
6
6
  "claude-code",