cohorte 3.3.0 → 4.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 +63 -0
- package/README.md +23 -3
- package/core/agents/cohorte-review.md +11 -3
- package/core/agents/implementer.template.md +19 -1
- package/core/commands/cohorte-acceptance.md +35 -0
- package/core/commands/cohorte-build.md +17 -0
- package/core/commands/cohorte-fix.md +6 -0
- package/core/commands/cohorte-foundation.md +90 -0
- package/core/commands/cohorte-lead.md +90 -0
- package/core/commands/cohorte-learn.md +67 -0
- package/core/commands/cohorte-po.md +76 -0
- package/core/commands/cohorte-product-map.md +53 -0
- package/core/commands/cohorte-retro.md +44 -13
- package/core/commands/cohorte-scaffold.md +59 -0
- package/core/commands/cohorte-vision.md +80 -0
- package/lib/install.js +2 -0
- package/lib/project.js +1 -1
- package/lib/registry.js +4 -3
- package/package.json +2 -2
- package/profile/PIPELINE.template.md +3 -1
- package/profile/schema/kanban.md +23 -0
- package/scripts/kanban-move.sh +45 -11
- package/ui/dist-server/server/agents.js +100 -0
- package/ui/dist-server/server/decider.js +241 -0
- package/ui/dist-server/server/features.js +128 -0
- package/ui/dist-server/server/flow.js +934 -0
- package/ui/dist-server/server/founding.js +706 -0
- package/ui/dist-server/server/gitinfo.js +22 -0
- package/ui/dist-server/server/history.js +10 -3
- package/ui/dist-server/server/legacy.js +3 -1
- package/ui/dist-server/server/next.js +91 -0
- package/ui/dist-server/server/runs.js +73 -11
- package/ui/dist-server/server/server.js +222 -6
- package/ui/dist-server/server/settings.js +81 -0
- package/ui/dist-server/server/tracker.js +438 -0
- package/ui/dist-server/shared/blocks.js +165 -0
- package/ui/dist-web/assets/index-BfN944Jm.js +165 -0
- package/ui/dist-web/assets/{style-0oNNMjwU.css → style-BMfadlCl.css} +1 -1
- package/ui/dist-web/index.html +2 -2
- package/ui/dist-web/assets/index-Clp1YW4S.js +0 -152
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// The decider — settles a question an agent asked mid-run, on the developer's behalf, only when what is already
|
|
3
|
+
// settled answers it. Same shape as a classifier (Jev-style): a STATE (the question, its options, the feature's
|
|
4
|
+
// settled context) in, a TYPED ANSWER out (one of the options, a category, a cited source), with a probability.
|
|
5
|
+
//
|
|
6
|
+
// The probability is not a number a model makes up: it is the agreement of N independent votes (`claude -p`,
|
|
7
|
+
// one turn, no tools, the context inlined). Unanimous on a light model ⇒ settled. Split ⇒ the same question goes
|
|
8
|
+
// to the next model up. Still split, or no source to cite, or a category a human must own ⇒ it goes to the
|
|
9
|
+
// developer, with the decider's best reading attached so they decide in one click.
|
|
10
|
+
//
|
|
11
|
+
// It NEVER settles: a behaviour or UX the business would see, a contract change, security, cost, or anything
|
|
12
|
+
// irreversible. Those are the developer's, whatever the votes say.
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Decider = exports.Preferences = exports.CATEGORIES = void 0;
|
|
18
|
+
exports.headerCategory = headerCategory;
|
|
19
|
+
exports.parseVote = parseVote;
|
|
20
|
+
exports.tally = tally;
|
|
21
|
+
exports.refusal = refusal;
|
|
22
|
+
exports.reversibleDefault = reversibleDefault;
|
|
23
|
+
exports.promptFor = promptFor;
|
|
24
|
+
exports.conventionsOf = conventionsOf;
|
|
25
|
+
const fs_1 = __importDefault(require("fs"));
|
|
26
|
+
const path_1 = __importDefault(require("path"));
|
|
27
|
+
const child_process_1 = require("child_process");
|
|
28
|
+
exports.CATEGORIES = ['reversible', 'visible', 'behavior', 'contract', 'cost', 'security', 'irreversible'];
|
|
29
|
+
const HUMAN_ONLY = ['behavior', 'contract', 'cost', 'security', 'irreversible'];
|
|
30
|
+
const SOURCE_KINDS = ['spec', 'plan', 'decision', 'convention', 'preference', 'code', 'none']; // a vote never claims `recommendation`
|
|
31
|
+
const SETTLED = ['spec', 'plan', 'decision', 'convention', 'preference'];
|
|
32
|
+
const clip = (s, n) => { const t = typeof s === 'string' ? s : ''; return t.length > n ? `${t.slice(0, n)}…` : t; };
|
|
33
|
+
/** The category a question's header already declares (the commands set it), if it is one. */
|
|
34
|
+
function headerCategory(header) {
|
|
35
|
+
const h = header.trim().toLowerCase();
|
|
36
|
+
return exports.CATEGORIES.includes(h) ? h : null;
|
|
37
|
+
}
|
|
38
|
+
/** One vote from a model's reply text. Tolerant: the first JSON object in the text; anything malformed is a null vote. */
|
|
39
|
+
function parseVote(text, options) {
|
|
40
|
+
const none = { choice: null, category: 'reversible', source: { kind: 'none', ref: '', quote: '' }, rationale: '' };
|
|
41
|
+
const m = text.match(/\{[\s\S]*\}/);
|
|
42
|
+
if (!m)
|
|
43
|
+
return none;
|
|
44
|
+
let o;
|
|
45
|
+
try {
|
|
46
|
+
o = JSON.parse(m[0]);
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return none;
|
|
50
|
+
}
|
|
51
|
+
const choice = typeof o.choice === 'string' ? options.find((x) => x.trim().toLowerCase() === o.choice.trim().toLowerCase()) ?? null : null;
|
|
52
|
+
const category = exports.CATEGORIES.includes(o.category) ? o.category : 'behavior'; // unknown ⇒ the cautious reading
|
|
53
|
+
const s = o.source && typeof o.source === 'object' ? o.source : {};
|
|
54
|
+
const kind = SOURCE_KINDS.includes(s.kind) ? s.kind : 'none';
|
|
55
|
+
return { choice, category, source: { kind, ref: clip(s.ref, 200), quote: clip(s.quote, 400) }, rationale: clip(o.rationale, 600) };
|
|
56
|
+
}
|
|
57
|
+
/** Majority choice, its share of the votes, and the MOST severe category any vote saw. */
|
|
58
|
+
function tally(votes) {
|
|
59
|
+
const count = new Map();
|
|
60
|
+
for (const v of votes)
|
|
61
|
+
if (v.choice)
|
|
62
|
+
count.set(v.choice, (count.get(v.choice) || 0) + 1);
|
|
63
|
+
let choice = null;
|
|
64
|
+
let best = 0;
|
|
65
|
+
for (const [c, n] of count)
|
|
66
|
+
if (n > best) {
|
|
67
|
+
best = n;
|
|
68
|
+
choice = c;
|
|
69
|
+
}
|
|
70
|
+
const severity = (c) => exports.CATEGORIES.indexOf(c);
|
|
71
|
+
const category = votes.reduce((a, v) => (severity(v.category) > severity(a) ? v.category : a), 'reversible');
|
|
72
|
+
const backing = votes.filter((v) => v.choice === choice);
|
|
73
|
+
const cited = backing.find((v) => v.source.kind !== 'none') || backing[0];
|
|
74
|
+
return { choice, agreement: votes.length ? best / votes.length : 0, votes: votes.length, category, source: cited?.source || { kind: 'none', ref: '', quote: '' }, rationale: cited?.rationale || '' };
|
|
75
|
+
}
|
|
76
|
+
/** Whether a tally may be acted on at this autonomy. `null` = yes; otherwise why not. */
|
|
77
|
+
function refusal(t, autonomy) {
|
|
78
|
+
if (!t.choice)
|
|
79
|
+
return 'no option was picked';
|
|
80
|
+
if (HUMAN_ONLY.includes(t.category))
|
|
81
|
+
return `a ${t.category} decision is yours`;
|
|
82
|
+
if (autonomy === 'prudent' && t.category !== 'reversible')
|
|
83
|
+
return `prudent: only reversible choices are settled alone (this one is ${t.category})`;
|
|
84
|
+
if (t.source.kind === 'none')
|
|
85
|
+
return 'nothing settled answers it (no source)';
|
|
86
|
+
if (t.source.kind === 'code' && autonomy !== 'autonomous' && t.category !== 'reversible')
|
|
87
|
+
return 'only a precedent in the code backs it';
|
|
88
|
+
if (autonomy === 'prudent' && !SETTLED.includes(t.source.kind))
|
|
89
|
+
return 'prudent: needs a written decision, not a code precedent';
|
|
90
|
+
const need = autonomy === 'autonomous' ? 2 / 3 : 1;
|
|
91
|
+
if (t.agreement + 1e-9 < need)
|
|
92
|
+
return `the votes split (${Math.round(t.agreement * t.votes)}/${t.votes})`;
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* A reversible choice nothing written settles (every vote said `reversible`, none could cite a source): not worth a
|
|
97
|
+
* person's attention. Outside `prudent`, the asking agent's own recommended option is taken — and listed at CP3 like
|
|
98
|
+
* any other decision, so it can still be contested.
|
|
99
|
+
*/
|
|
100
|
+
function reversibleDefault(t, q, autonomy) {
|
|
101
|
+
if (autonomy === 'prudent' || t.category !== 'reversible' || t.votes === 0)
|
|
102
|
+
return null;
|
|
103
|
+
const rec = q.options.find((o) => /\(recommended\)\s*$/i.test(o.label));
|
|
104
|
+
if (!rec)
|
|
105
|
+
return null;
|
|
106
|
+
return { decided: true, choice: rec.label, model: 'recommendation',
|
|
107
|
+
tally: { ...t, choice: rec.label, source: { kind: 'recommendation', ref: '', quote: '' }, rationale: 'reversible, and nothing written settles it — took the agent\'s recommendation' } };
|
|
108
|
+
}
|
|
109
|
+
class Preferences {
|
|
110
|
+
dir;
|
|
111
|
+
constructor(dir) {
|
|
112
|
+
this.dir = dir;
|
|
113
|
+
}
|
|
114
|
+
file(projectId) { return path_1.default.join(this.dir, `${projectId.replace(/[^A-Za-z0-9._-]/g, '')}.jsonl`); }
|
|
115
|
+
add(projectId, p) {
|
|
116
|
+
try {
|
|
117
|
+
fs_1.default.mkdirSync(this.dir, { recursive: true });
|
|
118
|
+
fs_1.default.appendFileSync(this.file(projectId), `${JSON.stringify({ at: new Date().toISOString(), ...p, question: clip(p.question, 500), answer: clip(p.answer, 300), note: p.note ? clip(p.note, 500) : undefined })}\n`);
|
|
119
|
+
}
|
|
120
|
+
catch { /* a convenience */ }
|
|
121
|
+
}
|
|
122
|
+
list(projectId, limit = 60) {
|
|
123
|
+
try {
|
|
124
|
+
return fs_1.default.readFileSync(this.file(projectId), 'utf8').split('\n').filter(Boolean).slice(-limit).map((l) => JSON.parse(l));
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.Preferences = Preferences;
|
|
132
|
+
function promptFor(q, ctx) {
|
|
133
|
+
const prefs = ctx.preferences.map((p) => `- Q: ${p.question} → ${p.answer} (${p.kind === 'answer' ? 'the developer answered' : p.kind === 'confirmed' ? 'decided for them, they confirmed' : `decided for them, they CONTESTED${p.note ? `: ${p.note}` : ''}`})`).join('\n');
|
|
134
|
+
const plan = ctx.plan ? [ctx.plan.summary, ...ctx.plan.criteria.map((c) => `${c.id} ${c.text}`), ...ctx.plan.assumptions.map((a) => `assumed: ${a}`)].join('\n') : '';
|
|
135
|
+
return [
|
|
136
|
+
'You are the DECIDER of a software team. An agent of an automated pipeline asked the question below while working on',
|
|
137
|
+
`feature "${ctx.feature}" (stage: ${ctx.stage}). You answer on the developer's behalf ONLY when what is already settled`,
|
|
138
|
+
'for this project answers it — the plan and spec they validated, the project\'s written decisions and conventions, their',
|
|
139
|
+
'past answers. You never invent a preference. When nothing settled answers it, say so (choice null, source none).',
|
|
140
|
+
'',
|
|
141
|
+
'Categories (pick the one that fits the CONSEQUENCE of the answer, the most severe when unsure):',
|
|
142
|
+
' reversible — internal, invisible outside the code, cheap to change later (naming, structure, a helper)',
|
|
143
|
+
' visible — visible to the developer but not the business (a library, a file layout, a test approach)',
|
|
144
|
+
' behavior — changes what a user or the business sees or experiences (UX, copy, an edge case\'s outcome)',
|
|
145
|
+
' contract — changes an interface other code depends on (API shape, schema, events)',
|
|
146
|
+
' cost — spends money or paid resources',
|
|
147
|
+
' security — authentication, authorization, data exposure, secrets',
|
|
148
|
+
' irreversible — data loss, destructive migration, publishing, anything that cannot be undone',
|
|
149
|
+
'',
|
|
150
|
+
'Reply with ONLY this JSON object, nothing else:',
|
|
151
|
+
'{"choice": "<one option label, exactly as written, or null>", "category": "<one category>",',
|
|
152
|
+
' "source": {"kind": "plan|spec|decision|convention|preference|code|none", "ref": "<section, line or id>", "quote": "<the words that settle it>"},',
|
|
153
|
+
' "rationale": "<one sentence>"}',
|
|
154
|
+
'',
|
|
155
|
+
`QUESTION${q.header ? ` [${q.header}]` : ''}: ${q.question}`,
|
|
156
|
+
'OPTIONS:',
|
|
157
|
+
...q.options.map((o) => `- ${o.label}${o.description ? ` — ${o.description}` : ''}`),
|
|
158
|
+
'',
|
|
159
|
+
'=== PLAN (validated by the developer at CP1) ===', plan || '(none)',
|
|
160
|
+
'', '=== SPEC ===', clip(ctx.spec, 24000) || '(none)',
|
|
161
|
+
'', '=== PROJECT DECISIONS (specs/_decisions.md) ===', clip(ctx.decisions, 6000) || '(none)',
|
|
162
|
+
'', '=== CONVENTIONS (PIPELINE.md) ===', clip(ctx.conventions, 6000) || '(none)',
|
|
163
|
+
'', '=== THE DEVELOPER\'S PAST ANSWERS ===', prefs || '(none yet)',
|
|
164
|
+
].join('\n');
|
|
165
|
+
}
|
|
166
|
+
/** §Conventions of a PIPELINE.md (the prose section after the machine block). */
|
|
167
|
+
function conventionsOf(pipelineMd) {
|
|
168
|
+
const m = pipelineMd.match(/^## Conventions\s*$([\s\S]*?)(?=^## |$(?![\s\S]))/m);
|
|
169
|
+
return m ? m[1].trim() : '';
|
|
170
|
+
}
|
|
171
|
+
// ---------------------------------------------------------------------------------------------------------------
|
|
172
|
+
// The votes
|
|
173
|
+
class Decider {
|
|
174
|
+
bin;
|
|
175
|
+
constructor({ bin } = {}) { this.bin = bin || process.env.COHORTE_CLAUDE_BIN || 'claude'; }
|
|
176
|
+
vote(prompt, model, cwd, options) {
|
|
177
|
+
return new Promise((resolve) => {
|
|
178
|
+
// A vote is one turn with no tools, no MCP servers, no settings and a one-line system prompt: measured at
|
|
179
|
+
// ~700 input tokens ($0.0001 on haiku) where a default session costs 230k tokens before it says a word.
|
|
180
|
+
const args = ['-p', '--output-format', 'json', '--model', model, '--tools', '', '--strict-mcp-config', '--setting-sources', '',
|
|
181
|
+
'--no-session-persistence', '--system-prompt', 'You are a careful decider. You reply with exactly one JSON object and nothing else.'];
|
|
182
|
+
let out = '';
|
|
183
|
+
let child;
|
|
184
|
+
try {
|
|
185
|
+
child = (0, child_process_1.spawn)(this.bin, args, { cwd, stdio: ['pipe', 'pipe', 'ignore'], env: { ...process.env, COHORTE_DECIDER: '1' } });
|
|
186
|
+
}
|
|
187
|
+
catch {
|
|
188
|
+
resolve(parseVote('', options));
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const timer = setTimeout(() => { try {
|
|
192
|
+
child.kill();
|
|
193
|
+
}
|
|
194
|
+
catch { /* gone */ } }, 120000);
|
|
195
|
+
child.stdout.on('data', (d) => { out += d; });
|
|
196
|
+
child.on('error', () => { clearTimeout(timer); resolve(parseVote('', options)); });
|
|
197
|
+
child.on('close', () => {
|
|
198
|
+
clearTimeout(timer);
|
|
199
|
+
let text = out;
|
|
200
|
+
try {
|
|
201
|
+
const v = JSON.parse(out);
|
|
202
|
+
if (typeof v.result === 'string')
|
|
203
|
+
text = v.result;
|
|
204
|
+
}
|
|
205
|
+
catch { /* plain text */ }
|
|
206
|
+
resolve(parseVote(text, options));
|
|
207
|
+
});
|
|
208
|
+
child.stdin.on('error', () => { });
|
|
209
|
+
child.stdin.end(prompt);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
async round(prompt, model, n, cwd, options) {
|
|
213
|
+
return tally(await Promise.all(Array.from({ length: n }, () => this.vote(prompt, model, cwd, options))));
|
|
214
|
+
}
|
|
215
|
+
/** One question (single-select). Multi-select and free-text questions always go to the human. */
|
|
216
|
+
async decide(q, ctx, s, cwd) {
|
|
217
|
+
const declared = headerCategory(q.header);
|
|
218
|
+
const advice = (t, why) => ({ decided: false, advice: { choice: t?.choice ?? null, rationale: t?.rationale || '', agreement: t?.agreement ?? 0, category: t?.category || declared || '', escalated: why } });
|
|
219
|
+
if (q.multiSelect || !q.options.length)
|
|
220
|
+
return advice(null, 'multi-select or open question');
|
|
221
|
+
if (declared && HUMAN_ONLY.includes(declared))
|
|
222
|
+
return advice(null, `the agent marked it ${declared}`);
|
|
223
|
+
const options = q.options.map((o) => o.label);
|
|
224
|
+
const prompt = promptFor(q, ctx);
|
|
225
|
+
const first = await this.round(prompt, s.model, s.votes, cwd, options);
|
|
226
|
+
const why1 = refusal(first, s.autonomy);
|
|
227
|
+
if (!why1)
|
|
228
|
+
return { decided: true, choice: first.choice, tally: first, model: s.model };
|
|
229
|
+
if (reversibleDefault(first, q, s.autonomy))
|
|
230
|
+
return reversibleDefault(first, q, s.autonomy);
|
|
231
|
+
// Escalate only a split: a refusal on category or source would be the same on a bigger model.
|
|
232
|
+
if (!/votes split|no option/.test(why1) || s.escalation === s.model)
|
|
233
|
+
return advice(first, why1);
|
|
234
|
+
const second = await this.round(prompt, s.escalation, s.votes, cwd, options);
|
|
235
|
+
const why2 = refusal(second, s.autonomy);
|
|
236
|
+
if (!why2)
|
|
237
|
+
return { decided: true, choice: second.choice, tally: second, model: s.escalation };
|
|
238
|
+
return reversibleDefault(second, q, s.autonomy) || advice(second, why2);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.Decider = Decider;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// A feature is a ticket a developer took: its worktree, where it stands between checkpoints, every stage the
|
|
3
|
+
// autopilot ran (and on which model), every decision taken on the developer's behalf, every correction they asked
|
|
4
|
+
// for. Kept by cohorte ui on this machine: <globalDir>/cohorte-ui/features/<projectId>/<id>.json — the pipeline's
|
|
5
|
+
// own artifacts (spec, reports, contract) stay in the worktree, where the commands read them.
|
|
6
|
+
//
|
|
7
|
+
// The record is also mirrored into the worktree as specs/reports/<id>.decisions.md (gitignored report buffer), so
|
|
8
|
+
// /cohorte-learn — which runs in the worktree and cannot see this store — reads the decisions and corrections.
|
|
9
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.FeatureStore = void 0;
|
|
14
|
+
const fs_1 = __importDefault(require("fs"));
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
17
|
+
const SAFE = /^[A-Za-z0-9._-]+$/;
|
|
18
|
+
class FeatureStore {
|
|
19
|
+
dir;
|
|
20
|
+
cache = new Map();
|
|
21
|
+
constructor(dir) {
|
|
22
|
+
this.dir = dir;
|
|
23
|
+
}
|
|
24
|
+
file(projectId, id) {
|
|
25
|
+
return SAFE.test(projectId) && SAFE.test(id) ? path_1.default.join(this.dir, projectId, `${id}.json`) : null;
|
|
26
|
+
}
|
|
27
|
+
create(projectId, ticketId, title) {
|
|
28
|
+
const now = new Date().toISOString();
|
|
29
|
+
const f = {
|
|
30
|
+
v: 1, id: ticketId, projectId, ticketId, title, worktree: null, branch: null, phase: 'provisioning', checkpoint: null,
|
|
31
|
+
leadRunId: null, currentRunId: null, stages: [], rounds: 0, decisions: [], corrections: [], pr: null, plan: null, error: null, warning: null,
|
|
32
|
+
createdAt: now, updatedAt: now, costUsd: 0, reservationsAck: false, lastBlocking: null, failures: {},
|
|
33
|
+
};
|
|
34
|
+
this.save(f);
|
|
35
|
+
return f;
|
|
36
|
+
}
|
|
37
|
+
get(projectId, id) {
|
|
38
|
+
const key = `${projectId}/${id}`;
|
|
39
|
+
const hit = this.cache.get(key);
|
|
40
|
+
if (hit)
|
|
41
|
+
return hit;
|
|
42
|
+
const f = this.file(projectId, id);
|
|
43
|
+
if (!f)
|
|
44
|
+
return null;
|
|
45
|
+
try {
|
|
46
|
+
const v = JSON.parse(fs_1.default.readFileSync(f, 'utf8'));
|
|
47
|
+
if (v.v !== 1 || v.id !== id)
|
|
48
|
+
return null;
|
|
49
|
+
this.cache.set(key, v);
|
|
50
|
+
return v;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
list(projectId) {
|
|
57
|
+
let names = [];
|
|
58
|
+
try {
|
|
59
|
+
names = fs_1.default.readdirSync(path_1.default.join(this.dir, projectId)).filter((n) => n.endsWith('.json'));
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
return names.map((n) => this.get(projectId, n.slice(0, -5))).filter((x) => !!x).sort((a, b) => b.updatedAt.localeCompare(a.updatedAt));
|
|
65
|
+
}
|
|
66
|
+
all(projectIds) { return projectIds.flatMap((p) => this.list(p)); }
|
|
67
|
+
save(f) {
|
|
68
|
+
f.updatedAt = new Date().toISOString();
|
|
69
|
+
f.costUsd = Math.round(f.stages.reduce((s, x) => s + (x.costUsd || 0), 0) * 10000) / 10000;
|
|
70
|
+
this.cache.set(`${f.projectId}/${f.id}`, f);
|
|
71
|
+
const file = this.file(f.projectId, f.id);
|
|
72
|
+
if (!file)
|
|
73
|
+
return;
|
|
74
|
+
try {
|
|
75
|
+
fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true });
|
|
76
|
+
fs_1.default.writeFileSync(`${file}.tmp`, JSON.stringify(f, null, 1));
|
|
77
|
+
fs_1.default.renameSync(`${file}.tmp`, file);
|
|
78
|
+
}
|
|
79
|
+
catch { /* a convenience record: never take the flow down */ }
|
|
80
|
+
this.mirror(f);
|
|
81
|
+
}
|
|
82
|
+
phase(f, phase, checkpoint = null, error = null) {
|
|
83
|
+
f.phase = phase;
|
|
84
|
+
f.checkpoint = checkpoint;
|
|
85
|
+
f.error = error;
|
|
86
|
+
this.save(f);
|
|
87
|
+
}
|
|
88
|
+
addDecision(f, d) {
|
|
89
|
+
const rec = { ...d, id: crypto_1.default.randomBytes(3).toString('hex'), at: new Date().toISOString(), contested: null, confirmed: false };
|
|
90
|
+
f.decisions.push(rec);
|
|
91
|
+
this.save(f);
|
|
92
|
+
return rec;
|
|
93
|
+
}
|
|
94
|
+
/** specs/reports/<id>.decisions.md in the worktree — what /cohorte-learn reads. */
|
|
95
|
+
mirror(f) {
|
|
96
|
+
if (!f.worktree || !fs_1.default.existsSync(f.worktree))
|
|
97
|
+
return;
|
|
98
|
+
const lines = [`# Decisions & corrections — ${f.id}`, '', '> Written by cohorte ui. Read by /cohorte-learn. Do not edit.', ''];
|
|
99
|
+
if (f.decisions.length) {
|
|
100
|
+
lines.push('## Decisions', '');
|
|
101
|
+
for (const d of f.decisions) {
|
|
102
|
+
const src = d.source && d.source.kind !== 'none' ? ` · source: ${d.source.kind}${d.source.ref ? ` (${d.source.ref})` : ''}` : '';
|
|
103
|
+
const state = d.contested ? ` · CONTESTED by the developer: ${d.contested.note || '(no note)'}` : d.confirmed ? ' · confirmed at CP3' : '';
|
|
104
|
+
lines.push(`- [${d.by}] ${d.stage} · ${d.header ? `${d.header} · ` : ''}${d.question} → **${d.chosen}**${src}${state}`);
|
|
105
|
+
}
|
|
106
|
+
lines.push('');
|
|
107
|
+
}
|
|
108
|
+
if (f.corrections.length) {
|
|
109
|
+
lines.push('## Corrections asked by the developer', '');
|
|
110
|
+
for (const c of f.corrections)
|
|
111
|
+
lines.push(`- ${c.at.slice(0, 10)} · at ${c.checkpoint} · ${c.text.replace(/\n+/g, ' ')}`);
|
|
112
|
+
lines.push('');
|
|
113
|
+
}
|
|
114
|
+
if (f.stages.length) {
|
|
115
|
+
lines.push('## Stages', '');
|
|
116
|
+
for (const s of f.stages)
|
|
117
|
+
lines.push(`- ${s.stage} · ${s.model} · ${s.status}${s.note ? ` · ${s.note}` : ''}`);
|
|
118
|
+
lines.push('');
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
const dir = path_1.default.join(f.worktree, 'specs', 'reports');
|
|
122
|
+
fs_1.default.mkdirSync(dir, { recursive: true });
|
|
123
|
+
fs_1.default.writeFileSync(path_1.default.join(dir, `${f.id}.decisions.md`), lines.join('\n'));
|
|
124
|
+
}
|
|
125
|
+
catch { /* the worktree may be read-only or gone */ }
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.FeatureStore = FeatureStore;
|