create-pmos 0.851.0 → 0.852.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.
Files changed (39) hide show
  1. package/package.json +79 -105
  2. package/payload/AGENTS.md +63 -0
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/planning/evals/eval-calibration.md +1 -1
  5. package/payload/planning/okrs/health-budgets.md +1 -1
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/changelog.json +78 -22
  8. package/workspace/guide/cli.md +20 -0
  9. package/workspace/guide/initiatives-and-next-steps.md +11 -0
  10. package/workspace/guide/programs.md +1 -0
  11. package/workspace/lib/features.json +2 -0
  12. package/workspace/lib/knowledge-cli.js +6 -0
  13. package/workspace/lib/on-item-routes.js +68 -0
  14. package/workspace/lib/on-item.js +272 -0
  15. package/workspace/lib/one-person-knows.js +403 -0
  16. package/workspace/lib/pmos-verbs.js +6 -0
  17. package/workspace/lib/route-modules.js +2 -0
  18. package/workspace/lib/routes-capture.js +1 -1
  19. package/workspace/lib/routes-one-person-knows.js +40 -0
  20. package/workspace/lib/routes-screen-map.js +47 -0
  21. package/workspace/lib/routes-stage-signoffs.js +4 -1
  22. package/workspace/lib/screen-map.js +381 -0
  23. package/workspace/lib/signoffs.js +4 -1
  24. package/workspace/package-lock.json +2 -2
  25. package/workspace/package.json +1 -1
  26. package/workspace/public/pm/bd-prog-panel.js +25 -1
  27. package/workspace/public/pm/cozy-board.css +3 -0
  28. package/workspace/public/pm/cozy-pop-work.js +5 -2
  29. package/workspace/public/pm/home-app.js +5 -0
  30. package/workspace/public/pm/on-item.js +155 -0
  31. package/workspace/public/pm/one-person-knows.js +66 -0
  32. package/workspace/public/pm/premium-board.js +2 -0
  33. package/workspace/public/pm/screen-map.css +23 -0
  34. package/workspace/public/pm/screen-map.js +187 -0
  35. package/workspace/public/premium-board.html +2 -0
  36. package/workspace/test-lists/kit-agents-verbs.json +9 -0
  37. package/workspace/test-lists/one-person-knows.json +9 -0
  38. package/workspace/test-lists/screen-map.json +9 -0
  39. package/workspace/test-lists/surface-on-item.json +9 -0
@@ -0,0 +1,68 @@
1
+ 'use strict';
2
+ /* on-item-routes.js — what PMOS can do for the open initiative or program, shown on it with no typed ask (job #1986, surface-on-item;
3
+ * lib/on-item.js).
4
+ *
5
+ * GET /api/on-item?ws=<id>&ini=<id>&stage=<name> → { ok, signoffs, numbers, press } read only
6
+ * POST /api/on-item/evidence { ws, ini, id, ref, quote } | { ws, ini, id, undo: true, before } a picked line becomes the sign-off's source
7
+ * POST /api/on-item/numbers { ws, ini, baseline, min_change, weekly_traffic } | { ws, ini, undo: true, before }
8
+ * POST /api/on-item/press-release { ws, ini } | { ws, ini, undo: true } pmos press-release in the background, or stop it
9
+ * GET /api/on-item/program-drafts?program=<id> → { ok, n } n: PMOS's first milestones for a program with none and no open suggestion
10
+ * POST /api/on-item/program-drafts { program } | { program, undo: true } pmos program draft, or an empty review (none stays open)
11
+ *
12
+ * lib/routes-stage-signoffs.js owns the prefix and hands it here. Every POST is a page press (lib/pm-guard.js requirePagePress). Nothing is sent. */
13
+ const OI = require('./on-item.js');
14
+
15
+ let spawnForTest = null;
16
+ /** Tests stub the press release's background run. */
17
+ function setSpawn(fn) { spawnForTest = fn || null; }
18
+
19
+ async function handle(req, res, url, ctx) {
20
+ const p = url.pathname;
21
+ if (p !== '/api/on-item' && !p.startsWith('/api/on-item/')) return false;
22
+ const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
23
+ let body = {};
24
+ if (req.method === 'POST') {
25
+ const got = await ctx.readJson(req);
26
+ if (!got.ok) return bad('invalid JSON body');
27
+ body = got.body || {};
28
+ const g = require('./pm-guard.js').requirePagePress(req, body);
29
+ if (!g.ok) return bad(g.error, g.status);
30
+ } else if (req.method !== 'GET') return bad('GET or POST only', 405);
31
+ const q = (k) => (req.method === 'POST' ? body[k] : url.searchParams.get(k));
32
+
33
+ if (p === '/api/on-item/program-drafts') {
34
+ const id = String(q('program') || '');
35
+ const prog = (require('./routes-programs.js').all(ctx) || []).find((x) => x.id === id);
36
+ if (!prog) return bad('no such program', 404);
37
+ let w = null; try { w = ctx.getWs(prog.home || null); } catch { w = null; }
38
+ if (!w || !w.root) return bad('the charter of this program is in a product this computer does not have', 404);
39
+ const empty = !(prog.milestones || []).length && !((prog.review && prog.review.open) || []).length;
40
+ if (req.method === 'GET') { ctx.json(res, { ok: true, n: empty ? OI.programDrafts(w.root, id).n : 0 }); return true; }
41
+ if (body.undo === true) { ctx.json(res, OI.undoProgramDrafts(w.root, id)); return true; }
42
+ if (!empty) return bad('this program has milestones or suggestions already');
43
+ const r = OI.fileProgramDrafts(w.root, id);
44
+ ctx.json(res, r, r.ok ? 200 : 400);
45
+ return true;
46
+ }
47
+
48
+ let w = null; try { w = ctx.getWs(q('ws') || null); } catch { w = null; }
49
+ if (!w || !w.root) return bad('no such workspace', 404);
50
+ const ini = String(q('ini') || '');
51
+ if (!/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(ini)) return bad('name the initiative');
52
+
53
+ if (p === '/api/on-item') {
54
+ if (req.method !== 'GET') return bad('GET only', 405);
55
+ ctx.json(res, OI.readOf(w.root, ini, { stage: url.searchParams.get('stage') || '' }));
56
+ return true;
57
+ }
58
+ if (req.method !== 'POST') return bad('POST only', 405);
59
+ let r;
60
+ if (p === '/api/on-item/evidence') r = body.undo === true ? OI.undoEvidence(w.root, { id: body.id, before: body.before || null }) : OI.setEvidence(w.root, { ini, id: body.id, ref: body.ref, quote: body.quote });
61
+ else if (p === '/api/on-item/numbers') r = body.undo === true ? OI.undoNumbers(w.root, ini, body.before || {}) : OI.setNumbers(w.root, ini, body);
62
+ else if (p === '/api/on-item/press-release') r = body.undo === true ? OI.stopPress(w.root, ini) : OI.startPress(w.root, ini, { spawn: spawnForTest });
63
+ else return bad('no such route', 404);
64
+ ctx.json(res, r, r.ok ? 200 : 400);
65
+ return true;
66
+ }
67
+
68
+ module.exports = { prefixes: ['/api/on-item'], handle, setSpawn };
@@ -0,0 +1,272 @@
1
+ 'use strict';
2
+ /* on-item.js — what PMOS can do for the initiative or program that is open shows on it, with no typed ask (job #1986, surface-on-item;
3
+ * LINE.md Rule 12; board SfA on the Exploring 3 canvas, page `surface`, agreed 2026-11-25). Before this, six features answered only a
4
+ * typed ask: what an approver asked before (#1878), where a sign-off's yes is written (#1869), the numbers that say whether an experiment
5
+ * can conclude (#1849), the press release and FAQ at Plan (#1624) and a program's first milestones (#1702). (The grill, #1830, already
6
+ * starts by itself: lib/grill-runs.js grills an initiative never grilled in its monthly look.)
7
+ *
8
+ * readOf(root, ini, { stage, now, runtimeDir }) → { ok, signoffs: [signoff], numbers: offer | null, press: offer | null } READ ONLY
9
+ * signoff { id, who, what, asked, due, past: [approver-memory item], evidence: { ref, quote, ok, why } | null, picks: [{ ref, quote }] }
10
+ * past: what that person asked or objected to on other work (lib/approver-memory.js historyOf), at most 3, newest first
11
+ * picks: with no source yet, the lines in the initiative's own files that name them with a yes, at most 3
12
+ * numbers { metric, due, missing: [key], ask } the record's outcome_metric is a rate and it has a check date, but not the numbers
13
+ * lib/experiment-power.js needs; ask is the ✦ draft's words (lib/star-draft.js runs it)
14
+ * press { say, state: 'offer' | 'drafting' } a feature at Plan (or Discovery) with no press release beside its record
15
+ * setEvidence(root, { ini, id, ref, quote }, now) → { ok, before } the pick becomes the sign-off's source (lib/signoffs.js evidence)
16
+ * undoEvidence(root, { id, before }, now) → { ok } the source it had, or none
17
+ * setNumbers(root, ini, { baseline, min_change, weekly_traffic }) → { ok, before } | { ok: false, error } three frontmatter keys
18
+ * undoNumbers(root, ini, before) → { ok } the keys as they were
19
+ * startPress(root, ini, { spawn, now }) → { ok, started } `pmos press-release <ini>` in the background
20
+ * stopPress(root, ini) → { ok, removed } stops it, and removes a draft it wrote
21
+ * programDrafts(home, id, { env, now }) → { n } pmos program draft's count for a program with no milestones
22
+ * fileProgramDrafts(home, id, o) · undoProgramDrafts(home, id, o) file them as suggestions · file an empty review (none stays open)
23
+ *
24
+ * Zero is silence: every part is empty when its condition is false. Every write is a page press (lib/on-item-routes.js) and has an Undo.
25
+ * Nothing is sent. The copy says PMOS, never Claude. */
26
+ const fs = require('fs');
27
+ const path = require('path');
28
+
29
+ const TAG = '[on-item]';
30
+ const MAX_PAST = 3;
31
+ const MAX_PICKS = 3;
32
+ const MAX_FILES = 400;
33
+ const MAX_SIZE = 256 * 1024;
34
+ const FOLDERS = ['planning', 'docs', 'notes', path.join('pmos', 'state')];
35
+ const YES_RE = /\b(yes|approv(?:e|ed|al|es)|agree(?:d|s)?|signed[- ]?off|sign[- ]?off given|go[- ]ahead|lgtm|accept(?:ed|s)?|confirm(?:ed|s)?)\b/i;
36
+ const NOT_FEATURE = new Set(['chore', 'incident', 'discovery', 'content', 'prototype']);
37
+ const PLAN_RE = /\b(plan|planning|discover|discovery|define|shape|shaping)\b/i;
38
+ const RATE_RE = /%|\brate\b|\bshare\b|\bpercent|\bconversion|\bratio\b|\bproportion\b|\bout of\b/i;
39
+ const NUM_KEYS = ['baseline', 'min_change', 'weekly_traffic'];
40
+ const PRESS = new Map(); // root|ini → { child, at, file }: the press release drafts this server started
41
+
42
+ const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
43
+ const esc = (s) => String(s).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
44
+ const dayOf = (v) => { const m = /^(\d{4}-\d{2}-\d{2})/.exec(String(v || '').trim()); return m ? m[1] : ''; };
45
+
46
+ function signoffFile(root) {
47
+ let dir = null;
48
+ try { dir = require('./jira-tickets.js').stateDirOf(root); } catch { dir = null; }
49
+ return dir ? require('./signoffs.js').fileOf(dir) : null;
50
+ }
51
+
52
+ /** The markdown files that may hold an initiative's notes: under planning/, docs/, notes/ and pmos/state/, the ones whose path names the
53
+ * initiative or whose text does, newest first. */
54
+ function filesOf(root, ini) {
55
+ const out = [], top = path.resolve(root);
56
+ let seen = 0;
57
+ const walk = (dir, depth) => {
58
+ if (depth > 5 || seen > MAX_FILES) return;
59
+ let list = [];
60
+ try { list = fs.readdirSync(dir, { withFileTypes: true }); } catch { return; }
61
+ for (const e of list) {
62
+ if (seen > MAX_FILES) return;
63
+ if (e.name.startsWith('.') || e.name === 'node_modules') continue;
64
+ const f = path.join(dir, e.name);
65
+ if (e.isDirectory()) { walk(f, depth + 1); continue; }
66
+ if (!/\.(md|txt)$/i.test(e.name)) continue;
67
+ seen++;
68
+ let st; try { st = fs.statSync(f); } catch { continue; }
69
+ if (st.size > MAX_SIZE) continue;
70
+ const rel = path.relative(top, f).split(path.sep).join('/');
71
+ out.push({ rel, abs: f, at: st.mtimeMs, named: rel.toLowerCase().includes(ini.toLowerCase()) });
72
+ }
73
+ };
74
+ for (const d of FOLDERS) walk(path.join(top, d), 0);
75
+ return out.sort((a, b) => b.at - a.at);
76
+ }
77
+
78
+ /** The lines of the initiative's files that name `who` with a yes ("Ana: approved the PRD"), each as a source the sign-off check reads. */
79
+ function picksOf(root, ini, who) {
80
+ const first = String(who || '').trim().split(/\s+/)[0];
81
+ if (!first || first.length < 2) return [];
82
+ const name = new RegExp('(^|[^\\p{L}])' + esc(first) + '($|[^\\p{L}])', 'iu');
83
+ const LD = require('./line-driver.js'), read = LD.readerOf(root, ini);
84
+ const out = [];
85
+ for (const f of filesOf(root, ini)) {
86
+ let text = '';
87
+ try { text = fs.readFileSync(f.abs, 'utf8'); } catch { continue; }
88
+ if (!f.named && !text.includes(ini)) continue;
89
+ for (const raw of text.split(/\r?\n/)) {
90
+ const line = raw.replace(/^\s*(?:[-*+>]|\d+[.)])\s*/, '').trim();
91
+ if (line.length < 12 || line.length > 400 || !name.test(line) || !YES_RE.test(line)) continue;
92
+ if (!LD.quoteCheck([{ item: 'pick', quote: line, ref: f.rel }], read).ok) continue;
93
+ out.push({ ref: f.rel, quote: line });
94
+ if (out.length >= MAX_PICKS) return out;
95
+ }
96
+ }
97
+ return out;
98
+ }
99
+
100
+ function signoffsOf(root, ini) {
101
+ const file = signoffFile(root); if (!file) return [];
102
+ const SO = require('./signoffs.js'), SS = require('./stage-signoffs.js'), AM = require('./approver-memory.js');
103
+ const open = SO.list(file, { ini, open: true });
104
+ if (!open.length) return [];
105
+ let items = [];
106
+ try { items = AM.itemsOf(root); } catch { items = []; }
107
+ return open.map((s) => {
108
+ const ev = s.evidence && s.evidence.ref ? s.evidence : null;
109
+ const c = ev ? SS.checkOf(root, ini, ev, s.what) : null;
110
+ return { id: s.id, who: s.who, what: s.what, asked: s.asked || null, due: s.due || null,
111
+ past: AM.historyOf(items, s.who, { except: ini }).slice(0, MAX_PAST),
112
+ evidence: ev ? { ref: ev.ref, quote: ev.quote, ok: !!c.ok, why: c.why } : null,
113
+ picks: ev ? [] : picksOf(root, ini, s.who) };
114
+ });
115
+ }
116
+
117
+ function recordOf(root, ini) {
118
+ const I = require('./item-why.js');
119
+ const f = I.recordPathOf(root, ini); if (!f) return null;
120
+ let text = ''; try { text = fs.readFileSync(f, 'utf8'); } catch { return null; }
121
+ return { file: f, text, fm: I.frontOf(text) };
122
+ }
123
+
124
+ function numbersOf(rec, today) {
125
+ if (!rec) return null;
126
+ const fm = rec.fm, EP = require('./experiment-power.js');
127
+ if (EP.inputsOf(fm)) return null;
128
+ const metric = one(fm.outcome_metric, 300), due = dayOf(fm.outcome_horizon) || dayOf(fm.check_date);
129
+ if (!metric || !RATE_RE.test(metric) || !due || due < today) return null;
130
+ const missing = NUM_KEYS.filter((k) => fm[k] == null || String(fm[k]).trim() === '');
131
+ const title = one(fm.title, 160) || '';
132
+ const ask = `Draft the three numbers that tell whether the experiment "${title}" can conclude by ${due}. Its metric: ${metric}. `
133
+ + 'Read its record, its metric readings and its notes. Answer with exactly three lines and nothing else:\n'
134
+ + 'baseline: <the metric today, like 12%>\nmin_change: <the smallest change worth seeing, like 2pp>\nweekly_traffic: <people a week in the experiment, both arms, like 4000>\n'
135
+ + 'Write "unknown" after a key when the records do not say it. This is a draft for the PM to read.';
136
+ return { metric, due, missing, ask };
137
+ }
138
+
139
+ function pressOf(root, ini, rec, stage) {
140
+ if (!rec) return null;
141
+ const lane = String(rec.fm.lane || '').trim().toLowerCase();
142
+ if (NOT_FEATURE.has(lane) || !PLAN_RE.test(String(stage || ''))) return null;
143
+ const file = path.join(require('./press-release.js').dirOf(rec.file), ini + '.md');
144
+ const run = PRESS.get(root + '|' + ini);
145
+ if (run && !fs.existsSync(file) && Date.now() - run.at < 10 * 60e3) return { state: 'drafting', say: 'PMOS is drafting the press release and FAQ. It lands in Artefacts.' };
146
+ if (fs.existsSync(file)) return null;
147
+ return { state: 'offer', say: 'At Plan, a press release and FAQ says what this bet promises. PMOS drafts it from the record.' };
148
+ }
149
+
150
+ function readOf(root, ini, { stage = '', now = Date.now() } = {}) {
151
+ if (!root || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,119}$/.test(String(ini || ''))) return { ok: false, error: 'name the initiative' };
152
+ const today = new Date(now).toISOString().slice(0, 10);
153
+ let signoffs = [];
154
+ try { signoffs = signoffsOf(root, ini); } catch { signoffs = []; }
155
+ const rec = recordOf(root, ini);
156
+ const numbers = numbersOf(rec, today), press = pressOf(root, ini, rec, stage);
157
+ console.info(`${TAG} ini=${ini} signoffs=${signoffs.length} past=${signoffs.filter((s) => s.past.length).length} picks=${signoffs.reduce((n, s) => n + s.picks.length, 0)} numbers=${numbers ? 1 : 0} press=${press ? press.state : 0}`);
158
+ return { ok: true, signoffs, numbers, press };
159
+ }
160
+
161
+ /* ── writes, each on the PM's press ── */
162
+
163
+ function setEvidence(root, { ini, id, ref, quote } = {}, now = Date.now()) {
164
+ const file = signoffFile(root); if (!file) return { ok: false, error: 'this product has no PMOS state folder' };
165
+ const SO = require('./signoffs.js'), SS = require('./stage-signoffs.js');
166
+ const s = SO.list(file, { ini }).find((x) => x.id === id);
167
+ if (!s || s.state !== 'open') return { ok: false, error: 'no open sign-off ' + id };
168
+ const c = SS.checkOf(root, ini, { ref, quote }, s.what);
169
+ if (!c.quote.ok) return { ok: false, error: c.quote.why };
170
+ const before = s.evidence && s.evidence.ref ? { ref: s.evidence.ref, quote: s.evidence.quote, doc: s.evidence.doc || null } : null;
171
+ const r = SO.evidence(file, id, { ref, quote }, now);
172
+ if (!r.ok) return r;
173
+ console.info(`${TAG} evidence ini=${ini} id=${id} ref=${one(ref, 120)}`);
174
+ return { ok: true, before, check: c };
175
+ }
176
+ function undoEvidence(root, { id, before } = {}, now = Date.now()) {
177
+ const file = signoffFile(root); if (!file) return { ok: false, error: 'this product has no PMOS state folder' };
178
+ const SO = require('./signoffs.js');
179
+ const r = before && before.ref ? SO.evidence(file, id, before, now) : SO.clearEvidence(file, id, now);
180
+ if (r.ok) console.info(`${TAG} evidence undone id=${id}`);
181
+ return r.ok ? { ok: true } : r;
182
+ }
183
+
184
+ /** The record with these frontmatter keys set (null removes one). Keys not in the frontmatter go at its end. PURE. */
185
+ function withFront(text, kv) {
186
+ const L = String(text).split('\n');
187
+ if (!/^---\s*$/.test(L[0] || '')) return null;
188
+ let end = L.findIndex((l, i) => i > 0 && /^---\s*$/.test(l));
189
+ if (end < 0) return null;
190
+ for (const [k, v] of Object.entries(kv)) {
191
+ const at = L.findIndex((l, i) => i > 0 && i < end && new RegExp('^' + esc(k) + ':').test(l));
192
+ if (v == null) { if (at > 0) { L.splice(at, 1); end--; } continue; }
193
+ const line = k + ': ' + JSON.stringify(String(v));
194
+ if (at > 0) L[at] = line; else { L.splice(end, 0, line); end++; }
195
+ }
196
+ return L.join('\n');
197
+ }
198
+ function setNumbers(root, ini, given = {}) {
199
+ const rec = recordOf(root, ini); if (!rec) return { ok: false, error: 'no record for ' + ini };
200
+ const kv = {};
201
+ for (const k of NUM_KEYS) { const v = one(given[k], 40); if (!v || /unknown/i.test(v)) return { ok: false, error: `the draft has no ${k.replace('_', ' ')}: write it in the record, or draft again` }; kv[k] = v; }
202
+ const next = withFront(rec.text, kv);
203
+ if (!next) return { ok: false, error: 'the record has no frontmatter' };
204
+ if (!require('./experiment-power.js').inputsOf(require('./item-why.js').frontOf(next))) return { ok: false, error: 'PMOS cannot read these as numbers: a baseline like 12%, a change like 2pp, a weekly traffic like 4000' };
205
+ const before = Object.fromEntries(NUM_KEYS.map((k) => [k, rec.fm[k] == null ? null : rec.fm[k]]));
206
+ fs.writeFileSync(rec.file, next);
207
+ console.info(`${TAG} numbers ini=${ini} ${NUM_KEYS.map((k) => k + '=' + kv[k]).join(' ')}`);
208
+ return { ok: true, before };
209
+ }
210
+ function undoNumbers(root, ini, before = {}) {
211
+ const rec = recordOf(root, ini); if (!rec) return { ok: false, error: 'no record for ' + ini };
212
+ const kv = Object.fromEntries(NUM_KEYS.map((k) => [k, before && before[k] != null ? before[k] : null]));
213
+ const next = withFront(rec.text, kv); if (!next) return { ok: false, error: 'the record has no frontmatter' };
214
+ fs.writeFileSync(rec.file, next);
215
+ console.info(`${TAG} numbers undone ini=${ini}`);
216
+ return { ok: true };
217
+ }
218
+
219
+ function startPress(root, ini, { spawn, now = Date.now() } = {}) {
220
+ const rec = recordOf(root, ini); if (!rec) return { ok: false, error: 'no record for ' + ini };
221
+ const file = path.join(require('./press-release.js').dirOf(rec.file), ini + '.md');
222
+ if (fs.existsSync(file)) return { ok: false, error: 'this bet already has a press release' };
223
+ const key = root + '|' + ini, run = PRESS.get(key);
224
+ if (run && now - run.at < 10 * 60e3) return { ok: true, started: false };
225
+ const args = [path.join(__dirname, '..', 'bin', 'pmos.js'), 'press-release', ini, '--root', root];
226
+ const sp = spawn || ((cmd, a) => { const c = require('child_process').spawn(cmd, a, { cwd: root, stdio: 'ignore', detached: true }); c.unref(); return c; });
227
+ let child = null;
228
+ try { child = sp(process.execPath, args); } catch (e) { return { ok: false, error: 'PMOS could not start the draft: ' + one(e && e.message, 120) }; }
229
+ PRESS.set(key, { child, at: now, file });
230
+ console.info(`${TAG} press-release started ini=${ini}`);
231
+ return { ok: true, started: true };
232
+ }
233
+ function stopPress(root, ini) {
234
+ const key = root + '|' + ini, run = PRESS.get(key);
235
+ PRESS.delete(key);
236
+ if (!run) return { ok: true, removed: false };
237
+ try { if (run.child && run.child.kill && run.child.exitCode == null) run.child.kill(); } catch { /* it ended */ }
238
+ let removed = false;
239
+ try { const st = fs.statSync(run.file); if (st.mtimeMs >= run.at - 1000) { fs.unlinkSync(run.file); removed = true; } } catch { /* nothing written */ }
240
+ console.info(`${TAG} press-release stopped ini=${ini} removed=${removed}`);
241
+ return { ok: true, removed };
242
+ }
243
+
244
+ /* ── a program's first milestones (pmos program draft, lib/program-cli.js lineVerb) ── */
245
+
246
+ function lineCall(home, verb, args, o = {}) {
247
+ const lines = [];
248
+ const code = require('./program-cli.js').lineVerb(verb, args, { say: (l) => lines.push(String(l)), cwd: home, env: o.env || process.env, now: o.now || Date.now(), read: o.read });
249
+ return { code, lines };
250
+ }
251
+ function programDrafts(home, id, o = {}) {
252
+ const r = lineCall(home, 'line', [id, '--json'], o);
253
+ let j = null; try { j = JSON.parse(r.lines[r.lines.length - 1] || ''); } catch { j = null; }
254
+ const L = j && j.ok ? (j.programs || []).find((x) => x.id === id) : null;
255
+ return { n: L ? require('./program-line.js').draftsOf(L).length : 0 };
256
+ }
257
+ function fileProgramDrafts(home, id, o = {}) {
258
+ const r = lineCall(home, 'draft', [id], o);
259
+ console.info(`${TAG} program drafts filed program=${id} code=${r.code}`);
260
+ return r.code === 0 ? { ok: true, said: r.lines[0] || '' } : { ok: false, error: (r.lines[0] || 'PMOS could not draft the milestones').replace(/^✗\s*/, '') };
261
+ }
262
+ function undoProgramDrafts(home, id, { now = Date.now() } = {}) {
263
+ const dir = require('./driver.js').stateDirOf(home); if (!dir) return { ok: false, error: 'this product has no PMOS state folder' };
264
+ const MS = require('./milestone-suggest.js'), PI = require('./pm-items.js'), file = MS.fileOf(dir), run = 'undo' + now.toString(36), at = new Date(now);
265
+ PI.appendEvent(file, { kind: 'review-start', program: id, run, why: 'line', members: '' }, at);
266
+ PI.appendEvent(file, { kind: 'review-end', program: id, run, ok: true }, at);
267
+ console.info(`${TAG} program drafts undone program=${id}`);
268
+ return { ok: true };
269
+ }
270
+
271
+ module.exports = { TAG, readOf, picksOf, filesOf, withFront, setEvidence, undoEvidence, setNumbers, undoNumbers, startPress, stopPress,
272
+ programDrafts, fileProgramDrafts, undoProgramDrafts, NUM_KEYS };