cohorte 4.0.0 → 4.1.1

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.
@@ -4,6 +4,7 @@
4
4
  // Read-only and bounded: every call is async, has a timeout and never goes through a shell. A file to diff must be
5
5
  // one that `git` itself lists for the worktree — the client never names a path git did not report.
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.probe = void 0;
7
8
  exports.baseRef = baseRef;
8
9
  exports.parseStatus = parseStatus;
9
10
  exports.parseShortstat = parseShortstat;
@@ -12,6 +13,7 @@ exports.pullFor = pullFor;
12
13
  exports.ghAvailable = ghAvailable;
13
14
  exports.changedFiles = changedFiles;
14
15
  exports.fileDiff = fileDiff;
16
+ exports.remoteInfo = remoteInfo;
15
17
  const child_process_1 = require("child_process");
16
18
  function run(file, args, cwd, timeout = 8000, max = 400_000) {
17
19
  return new Promise((resolve) => {
@@ -169,3 +171,23 @@ async function fileDiff(wtPath, base, file) {
169
171
  const r = await git(wtPath, 'diff', '--no-color', '--no-ext-diff', range, '--', file);
170
172
  return { file, status: entry.status, diff: r.out.slice(0, 200_000), truncated: r.out.length > 200_000 };
171
173
  }
174
+ const ghBin = () => process.env.COHORTE_GH_BIN || 'gh';
175
+ /** Where the code is hosted, and whether `gh` could create a GitHub repository from here. Read-only. */
176
+ async function remoteInfo(root) {
177
+ const [origin, branch, ahead, ghv] = await Promise.all([
178
+ git(root, 'remote', 'get-url', 'origin'), git(root, 'rev-parse', '--abbrev-ref', 'HEAD'),
179
+ git(root, 'rev-list', '--count', '@{u}..HEAD'), run(ghBin(), ['--version'], root, 4000),
180
+ ]);
181
+ let authed = false;
182
+ let user = null;
183
+ if (ghv.code === 0) {
184
+ const who = await run(ghBin(), ['api', 'user', '--jq', '.login'], root, 10000);
185
+ authed = who.code === 0 && !!who.out.trim();
186
+ user = authed ? who.out.trim().split('\n')[0].slice(0, 100) : null;
187
+ }
188
+ return { origin: origin.code === 0 ? origin.out.trim() || null : null, branch: branch.code === 0 ? branch.out.trim() || null : null,
189
+ ahead: ahead.code === 0 ? Number(ahead.out.trim()) || 0 : null, gh: { installed: ghv.code === 0, authed, user } };
190
+ }
191
+ /** A bounded, shell-less process run (tool probes for the foundations context). */
192
+ const probe = (file, args, cwd, timeout = 4000) => run(file, args, cwd, timeout, 20_000);
193
+ exports.probe = probe;
@@ -44,7 +44,7 @@ class RunStore {
44
44
  const cut = Math.max(0, run.events.length - KEEP_EVENTS);
45
45
  const body = { v: 1, id: run.id, projectId: run.projectId, cwd: run.cwd, command: run.command, permissionMode: run.permissionMode, status: run.status,
46
46
  startedAt: run.startedAt, endedAt: run.endedAt, result: run.result, sessionId: run.sessionId, dropped: run.dropped + cut, events: run.events.slice(cut),
47
- meta: run.meta, model: run.model, disallowedTools: run.disallowedTools, seen: run.seen, tickets: run.tickets, strictMcp: run.strictMcp, mcpConfig: run.mcpConfig };
47
+ meta: run.meta, model: run.model, disallowedTools: run.disallowedTools, allowedTools: run.allowedTools, addDirs: run.addDirs, seen: run.seen, tickets: run.tickets, strictMcp: run.strictMcp, mcpConfig: run.mcpConfig };
48
48
  const tmp = `${f}.${process.pid}.tmp`;
49
49
  fs_1.default.writeFileSync(tmp, JSON.stringify(body));
50
50
  fs_1.default.renameSync(tmp, f);
@@ -89,6 +89,8 @@ class RunStore {
89
89
  pending: new Map(), result: v.result || null, sessionId: v.sessionId || null, child: null, closeTimer: null, stopping: false,
90
90
  meta: v.meta && typeof v.meta === 'object' && typeof v.meta.role === 'string' ? v.meta : { role: 'command' }, model: typeof v.model === 'string' ? v.model : null,
91
91
  disallowedTools: Array.isArray(v.disallowedTools) ? v.disallowedTools.filter((t) => typeof t === 'string') : [],
92
+ allowedTools: Array.isArray(v.allowedTools) ? v.allowedTools.filter((t) => typeof t === 'string') : [],
93
+ addDirs: Array.isArray(v.addDirs) ? v.addDirs.filter((t) => typeof t === 'string') : [],
92
94
  seen: typeof v.seen === 'number' ? v.seen : 0, tickets: v.tickets && typeof v.tickets === 'object' ? v.tickets : {},
93
95
  strictMcp: v.strictMcp === true, mcpConfig: typeof v.mcpConfig === 'string' ? v.mcpConfig : null });
94
96
  }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.parseProfileBlock = exports.report = exports.doctor = exports.registry = exports.RegistryErrorBase = exports.uiDir = exports.repo = void 0;
6
+ exports.project = exports.parseProfileBlock = exports.report = exports.doctor = exports.registry = exports.RegistryErrorBase = exports.uiDir = exports.repo = void 0;
7
7
  // Typed views of the plain-JS modules shared with the CLI (lib/*.js, bin/report.js). They stay JavaScript —
8
8
  // the CLI, the installer and the tests use them directly — so the dashboard describes only what it uses.
9
9
  const fs_1 = __importDefault(require("fs"));
@@ -27,3 +27,5 @@ exports.registry = load('lib/registry.js');
27
27
  exports.doctor = load('lib/doctor.js');
28
28
  exports.report = load('bin/report.js');
29
29
  exports.parseProfileBlock = load('lib/yaml.js').parseProfileBlock;
30
+ /** `cohorte sync` — re-wires a repo from its PIPELINE.md (profile.json, gate, pointer). */
31
+ exports.project = load('lib/project.js');
@@ -22,7 +22,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.Runs = exports.MODEL = exports.MODES = void 0;
25
+ exports.Runs = exports.MODEL = exports.ALLOWED_RULE = exports.MODES = void 0;
26
+ const path_1 = __importDefault(require("path"));
26
27
  const crypto_1 = __importDefault(require("crypto"));
27
28
  const readline_1 = __importDefault(require("readline"));
28
29
  const child_process_1 = require("child_process");
@@ -50,6 +51,8 @@ function summarize(name, input) {
50
51
  return '';
51
52
  }
52
53
  }
54
+ /** A permission rule: a tool name, optionally with a specifier — `Bash(npm:*)`, `Bash(docker compose:*)`. No comma (the list separator). */
55
+ exports.ALLOWED_RULE = /^[A-Za-z][\w]{0,40}(\([^(),\r\n]{1,400}\))?$/;
53
56
  exports.MODEL = /^[A-Za-z0-9][A-Za-z0-9._:\[\]-]{0,80}$/;
54
57
  class Runs {
55
58
  runs = new Map();
@@ -72,6 +75,8 @@ class Runs {
72
75
  permissionMode: mode, status: 'running', startedAt: new Date().toISOString(), endedAt: null,
73
76
  events: [], dropped: 0, pending: new Map(), result: null, sessionId: null, child: null, closeTimer: null, stopping: false,
74
77
  meta: opts.meta || { role: 'command' }, model, disallowedTools: (opts.disallowedTools || []).filter((t) => /^[A-Za-z][\w:-]{0,60}$/.test(t)),
78
+ allowedTools: (opts.allowedTools || []).filter((t) => exports.ALLOWED_RULE.test(t)),
79
+ addDirs: (opts.addDirs || []).filter((d) => typeof d === 'string' && path_1.default.isAbsolute(d)),
75
80
  seen: 0, tickets: {}, strictMcp: opts.strictMcp === true, mcpConfig: typeof opts.mcpConfig === 'string' ? opts.mcpConfig : null,
76
81
  };
77
82
  this.#spawn(run, null);
@@ -90,6 +95,10 @@ class Runs {
90
95
  args.push('--model', run.model);
91
96
  if (run.disallowedTools.length)
92
97
  args.push('--disallowedTools', run.disallowedTools.join(','));
98
+ if (run.allowedTools.length)
99
+ args.push('--allowedTools', run.allowedTools.join(','));
100
+ for (const d of run.addDirs)
101
+ args.push('--add-dir', d);
93
102
  if (run.strictMcp)
94
103
  args.push('--strict-mcp-config');
95
104
  if (run.mcpConfig)
@@ -61,6 +61,7 @@ const docker = __importStar(require("./docker"));
61
61
  const pipeline_1 = require("./pipeline");
62
62
  const findings_1 = require("./findings");
63
63
  const flow_1 = require("./flow");
64
+ const founding_1 = require("./founding");
64
65
  const settings_1 = require("./settings");
65
66
  const tracker_1 = require("./tracker");
66
67
  const { state, scanSpecs } = legacy_1.doctor;
@@ -146,7 +147,12 @@ function create({ globalDir, version, token = crypto_1.default.randomBytes(24).t
146
147
  }
147
148
  }, 120);
148
149
  };
149
- const flow = new flow_1.Flow({ globalDir, runs, jobs, dataDir: path_1.default.join(globalDir, 'cohorte-ui'), changed: (projectId) => notify({ type: 'flow', projectId, id: projectId, status: 'changed' }) });
150
+ const flow = new flow_1.Flow({ globalDir, runs, jobs, dataDir: path_1.default.join(globalDir, 'cohorte-ui'), changed: (projectId) => {
151
+ const pr = legacy_1.registry.get(globalDir, projectId);
152
+ if (pr)
153
+ cacheDoctor.clear(pr.root); // a founding step may have just written PIPELINE.md
154
+ notify({ type: 'flow', projectId, id: projectId, status: 'changed' });
155
+ } });
150
156
  jobs.onChange = (j) => {
151
157
  notify({ type: 'job', projectId: j.projectId, id: j.id, status: j.status });
152
158
  try {
@@ -167,12 +173,12 @@ function create({ globalDir, version, token = crypto_1.default.randomBytes(24).t
167
173
  const counts = {};
168
174
  for (const sp of s.specs)
169
175
  counts[sp.status || 'unknown'] = (counts[sp.status || 'unknown'] || 0) + 1;
170
- return { ...base, missing: false, title: s.profile && s.profile.name || base.name,
176
+ return { ...base, missing: false, founding: flow.founding.phaseOf(p.id), title: s.profile && s.profile.name || base.name,
171
177
  oneLiner: s.profile && s.profile.one_liner || '', summary: s.summary, specCounts: counts,
172
178
  specTotal: s.specs.length, core: s.versions && s.versions.core || null };
173
179
  }
174
180
  catch (e) {
175
- return { ...base, missing: false, error: String(e?.message || e) };
181
+ return { ...base, missing: false, founding: flow.founding.phaseOf(p.id), error: String(e?.message || e) };
176
182
  }
177
183
  }
178
184
  async function detail(p) {
@@ -288,6 +294,26 @@ function create({ globalDir, version, token = crypto_1.default.randomBytes(24).t
288
294
  if (parts[0] === 'discover' && method === 'GET') {
289
295
  return send(res, 200, { suggestions: legacy_1.registry.discover(globalDir, storePath) });
290
296
  }
297
+ if (parts[0] === 'founding' && parts.length === 1 && method === 'POST') {
298
+ let body;
299
+ try {
300
+ body = await readBody(req);
301
+ }
302
+ catch (e) {
303
+ return fail(res, 400, e.message);
304
+ }
305
+ try {
306
+ const r = await flow.founding.create(body);
307
+ return send(res, 201, { project: await summary(r.project), founding: r.founding });
308
+ }
309
+ catch (e) {
310
+ if (e instanceof ops.OpError)
311
+ return send(res, e.code, { error: e.message });
312
+ if (e instanceof legacy_1.registry.RegistryError)
313
+ return fail(res, 400, e.message);
314
+ throw e;
315
+ }
316
+ }
291
317
  if (parts[0] === 'projects' && parts.length === 1 && method === 'POST') {
292
318
  let body;
293
319
  try {
@@ -302,7 +328,7 @@ function create({ globalDir, version, token = crypto_1.default.randomBytes(24).t
302
328
  }
303
329
  catch (e) {
304
330
  if (e instanceof legacy_1.registry.RegistryError)
305
- return fail(res, 400, e.message);
331
+ return send(res, 400, { error: e.message, notCohorte: /has no PIPELINE\.md/.test(e.message) });
306
332
  throw e;
307
333
  }
308
334
  }
@@ -364,6 +390,17 @@ function create({ globalDir, version, token = crypto_1.default.randomBytes(24).t
364
390
  catch (e) {
365
391
  return fail(res, 400, e.message);
366
392
  }
393
+ if (founding_1.FOUNDING_ROLES.includes(run.meta.role)) {
394
+ try {
395
+ flow.founding.reply(p.id, body.text);
396
+ return send(res, 202, { run: runs.view(run, 0) });
397
+ }
398
+ catch (e) {
399
+ if (e instanceof ops.OpError)
400
+ return fail(res, e.code, e.message);
401
+ throw e;
402
+ }
403
+ }
367
404
  if (run.meta.role === 'lead' && run.meta.featureId) {
368
405
  try {
369
406
  flow.replyLead(p.id, run.meta.featureId, body.text);
@@ -451,6 +488,32 @@ function create({ globalDir, version, token = crypto_1.default.randomBytes(24).t
451
488
  return flowCall(() => { cacheDoctor.clear(p.root); return { feature: flow.take(p.id, tid, { confirmed: b.confirmed === true }) }; }, 202);
452
489
  }
453
490
  }
491
+ if (parts[2] === 'founding') {
492
+ if (parts.length === 3 && method === 'GET')
493
+ return flowCall(() => flow.founding.view(p.id));
494
+ if (parts[3] === 'reply' && method === 'POST') {
495
+ const b = await bodyOf();
496
+ if (!b)
497
+ return;
498
+ return flowCall(() => flow.founding.reply(p.id, b.text), 202);
499
+ }
500
+ if (parts[3] === 'checkpoint' && method === 'POST') {
501
+ const b = await bodyOf();
502
+ if (!b)
503
+ return;
504
+ return flowCall(async () => { const v = await flow.founding.checkpoint(p.id, b); cacheDoctor.clear(p.root); return v; });
505
+ }
506
+ }
507
+ if (parts[2] === 'remote' && parts.length === 3) {
508
+ if (method === 'GET')
509
+ return flowCall(() => flow.founding.remote(p.id));
510
+ if (method === 'POST') {
511
+ const b = await bodyOf();
512
+ if (!b)
513
+ return;
514
+ return flowCall(async () => ({ job: jobs.view(await flow.founding.connectRemote(p.id, b)) }), 202);
515
+ }
516
+ }
454
517
  if (parts[2] === 'po' && parts.length === 3 && method === 'POST') {
455
518
  const b = await bodyOf();
456
519
  if (!b)
@@ -22,7 +22,7 @@ exports.DEFAULTS = {
22
22
  autonomy: 'balanced',
23
23
  models: {
24
24
  po: 'opus', lead: 'opus', build: 'sonnet', implementer: 'sonnet', review: 'sonnet', fix: 'sonnet', verify: 'haiku',
25
- ship: 'sonnet', learn: 'sonnet', acceptance: 'sonnet', productMap: 'sonnet', decider: 'haiku', deciderEscalation: 'sonnet',
25
+ ship: 'sonnet', learn: 'sonnet', acceptance: 'sonnet', productMap: 'sonnet', scaffold: 'sonnet', setup: 'sonnet', decider: 'haiku', deciderEscalation: 'sonnet',
26
26
  },
27
27
  deciderVotes: 3, maxRounds: 3, mergeMethod: 'squash', autopilot: true, requester: '',
28
28
  };
@@ -7,6 +7,9 @@
7
7
  // ```cohorte-ticket one ticket proposal (PO) → TicketProposal
8
8
  // ```cohorte-plan the lead's plan, what CP1 validates → Plan
9
9
  // ```cohorte-acceptance the PO's acceptance note (CP4) → AcceptanceNote (minus `at`)
10
+ // ```cohorte-vision a new product's vision (PO) → Vision
11
+ // ```cohorte-foundation a new project's stack (lead) → Foundation
12
+ // ```cohorte-scaffold the skeleton's report → ScaffoldReport
10
13
  //
11
14
  // Everything here is pure and total: malformed JSON or a missing field yields null or a default, never a throw.
12
15
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -17,6 +20,9 @@ exports.slug = slug;
17
20
  exports.toProposal = toProposal;
18
21
  exports.toPlan = toPlan;
19
22
  exports.toAcceptance = toAcceptance;
23
+ exports.toVision = toVision;
24
+ exports.toFoundation = toFoundation;
25
+ exports.toScaffold = toScaffold;
20
26
  exports.lastOf = lastOf;
21
27
  exports.proposalsOf = proposalsOf;
22
28
  /** Every ```<kind> block in `text`, parsed as JSON (blocks that do not parse are skipped). */
@@ -33,7 +39,7 @@ function blocksOf(text, kind) {
33
39
  }
34
40
  /** The text with its machine blocks removed — what a person reads in the chat. */
35
41
  function stripBlocks(text) {
36
- return text.replace(/```cohorte-(ticket|plan|acceptance)[^\n]*\n[\s\S]*?\n?```/g, '').replace(/\n{3,}/g, '\n\n').trim();
42
+ return text.replace(/```cohorte-(ticket|plan|acceptance|vision|foundation|scaffold)[^\n]*\n[\s\S]*?\n?```/g, '').replace(/\n{3,}/g, '\n\n').trim();
37
43
  }
38
44
  const str = (v, max = 4000) => (typeof v === 'string' ? v.trim().slice(0, max) : '');
39
45
  const list = (v, max = 40) => (Array.isArray(v) ? v.map((x) => str(x, 1000)).filter(Boolean).slice(0, max) : []);
@@ -86,6 +92,52 @@ function toAcceptance(v) {
86
92
  return null;
87
93
  return { summary, changes: list(o.changes), howToTest: list(o.howToTest ?? o.how_to_test), outOfScope: list(o.outOfScope ?? o.out_of_scope) };
88
94
  }
95
+ function toVision(v) {
96
+ if (!v || typeof v !== 'object')
97
+ return null;
98
+ const o = v;
99
+ const pitch = str(o.pitch, 1000);
100
+ const firstVersion = list(o.firstVersion ?? o.first_version);
101
+ if (!pitch || !firstVersion.length)
102
+ return null;
103
+ return { name: str(o.name, 120), pitch, users: list(o.users), problem: str(o.problem), today: str(o.today), firstVersion, later: list(o.later),
104
+ success: str(o.success, 1000), constraints: list(o.constraints), language: str(o.language, 60) };
105
+ }
106
+ const cmd = (v) => str(v, 400).replace(/[\r\n]+/g, ' ');
107
+ function toFoundation(v) {
108
+ if (!v || typeof v !== 'object')
109
+ return null;
110
+ const o = v;
111
+ const summary = str(o.summary);
112
+ const surfaces = (Array.isArray(o.surfaces) ? o.surfaces : []).map((x) => {
113
+ const r = (x || {});
114
+ const raw = str(r.key, 40);
115
+ const key = raw ? slug(raw, 40) : '';
116
+ return { key, path: str(r.path, 120).replace(/^\.?\/+/, '') || key, stack: str(r.stack, 300), generate: cmd(r.generate) || null,
117
+ packageManager: str(r.packageManager ?? r.package_manager, 20), test: cmd(r.test), lint: cmd(r.lint), build: cmd(r.build) };
118
+ }).filter((x) => x.key).slice(0, 12);
119
+ if (!summary || !surfaces.length)
120
+ return null;
121
+ return { summary, surfaces, data: str(o.data, 1000), auth: str(o.auth, 1000), hosting: str(o.hosting, 1000), devCommand: cmd(o.devCommand ?? o.dev_command), ci: str(o.ci, 1000),
122
+ basedOn: str(o.basedOn ?? o.based_on, 200) || null, conventions: list(o.conventions), skeleton: str(o.skeleton, 1000), decisions: list(o.decisions),
123
+ assumptions: list(o.assumptions), questions: list(o.questions) };
124
+ }
125
+ function toScaffold(v) {
126
+ if (!v || typeof v !== 'object')
127
+ return null;
128
+ const o = v;
129
+ if (o.status !== 'ok' && o.status !== 'failed')
130
+ return null;
131
+ const surfaces = (Array.isArray(o.surfaces) ? o.surfaces : []).map((x) => {
132
+ const r = (x || {});
133
+ return { key: str(r.key, 40), path: str(r.path, 120), test: cmd(r.test), lint: cmd(r.lint), build: cmd(r.build), ok: r.ok === true };
134
+ }).filter((x) => x.key).slice(0, 12);
135
+ const checks = (Array.isArray(o.checks) ? o.checks : []).map((x) => {
136
+ const r = (x || {});
137
+ return { command: cmd(r.command), ok: r.ok === true, note: str(r.note, 500) };
138
+ }).filter((x) => x.command).slice(0, 40);
139
+ return { status: o.status, surfaces, devCommand: cmd(o.devCommand ?? o.dev_command), checks, assumptions: list(o.assumptions), notes: str(o.notes, 2000) };
140
+ }
89
141
  /** The last parseable block of `kind` across a run's text events, in order. */
90
142
  function lastOf(texts, kind, conv) {
91
143
  for (let i = texts.length - 1; i >= 0; i--) {