create-pmos 0.412.0 → 0.414.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 (91) hide show
  1. package/package.json +25 -25
  2. package/payload/AGENTS.md +2 -2
  3. package/payload/KIT-VERSION +1 -1
  4. package/payload/mods/pmos-cockpit/README.md +1 -1
  5. package/payload/mods/pmos-cockpit/hooks/lib/guard.mjs +11 -5
  6. package/payload/planning/evals/eval-calibration.md +1 -1
  7. package/payload/planning/okrs/health-budgets.md +1 -1
  8. package/payload/scripts/pmos-log.sh +18 -4
  9. package/payload/state/discoveries.md +1 -1
  10. package/workspace/board-programs-test.js +2 -2
  11. package/workspace/briefing-premium-board-test.js +45 -9
  12. package/workspace/briefing-premium-test.js +3 -2
  13. package/workspace/changelog.json +24 -0
  14. package/workspace/core-docs-workflow-test.js +144 -0
  15. package/workspace/guide/programs.md +13 -0
  16. package/workspace/guide/workflows.md +15 -1
  17. package/workspace/home-other-product-test.js +18 -0
  18. package/workspace/lib/board-premium.js +8 -2
  19. package/workspace/lib/briefing-premium-agent.js +16 -4
  20. package/workspace/lib/core-docs.js +79 -14
  21. package/workspace/lib/engine/boards.js +20 -12
  22. package/workspace/lib/headless.js +10 -1
  23. package/workspace/lib/initiative-chat.js +50 -0
  24. package/workspace/lib/initiative-premium.js +17 -7
  25. package/workspace/lib/item-cli.js +7 -2
  26. package/workspace/lib/milestone-review.js +120 -0
  27. package/workspace/lib/milestone-suggest.js +176 -0
  28. package/workspace/lib/plan-items.js +1 -1
  29. package/workspace/lib/pmos-verbs.js +7 -1
  30. package/workspace/lib/program-chat.js +1 -1
  31. package/workspace/lib/program-cli.js +56 -0
  32. package/workspace/lib/programs.js +25 -6
  33. package/workspace/lib/routes-boards.js +77 -13
  34. package/workspace/lib/routes-briefing-premium.js +17 -1
  35. package/workspace/lib/routes-core-docs.js +3 -1
  36. package/workspace/lib/routes-programs.js +84 -7
  37. package/workspace/lib/task-cli.js +120 -0
  38. package/workspace/lib/workflow-chat.js +1 -0
  39. package/workspace/lib/workflow-cli.js +91 -6
  40. package/workspace/milestone-suggest-test.js +175 -0
  41. package/workspace/package-lock.json +2 -2
  42. package/workspace/package.json +1 -1
  43. package/workspace/premium-chat-line-test.js +12 -1
  44. package/workspace/premium-vw-item-test.js +3 -3
  45. package/workspace/premium-vw-jira-test.js +2 -1
  46. package/workspace/program-order-test.js +180 -0
  47. package/workspace/public/pm/bd-ini-model.js +81 -0
  48. package/workspace/public/pm/bd-ini-panel.js +123 -58
  49. package/workspace/public/pm/bd-prog-panel.js +54 -14
  50. package/workspace/public/pm/bd-prog.js +3 -3
  51. package/workspace/public/pm/cozy-home.css +5 -0
  52. package/workspace/public/pm/cozy-panel.css +2 -0
  53. package/workspace/public/pm/cozy-viewer.js +10 -3
  54. package/workspace/public/pm/cozy-xv.css +51 -16
  55. package/workspace/public/pm/cozy-xv.js +6 -5
  56. package/workspace/public/pm/goal-chat.js +1 -1
  57. package/workspace/public/pm/home-app.js +35 -19
  58. package/workspace/public/pm/home-ask.js +9 -3
  59. package/workspace/public/pm/home-chat.js +16 -2
  60. package/workspace/public/pm/home-ini-model.js +42 -29
  61. package/workspace/public/pm/home-ini.css +1 -0
  62. package/workspace/public/pm/home-ini.js +26 -34
  63. package/workspace/public/pm/home-list.js +14 -8
  64. package/workspace/public/pm/home-stage-card.js +3 -1
  65. package/workspace/public/pm/home-task.js +41 -65
  66. package/workspace/public/pm/home-today.js +11 -12
  67. package/workspace/public/pm/ms-suggest.css +50 -0
  68. package/workspace/public/pm/ms-suggest.js +98 -0
  69. package/workspace/public/pm/premium-board.js +13 -7
  70. package/workspace/public/pm/premium-initiative-head.js +32 -13
  71. package/workspace/public/pm/premium-viewer.js +1 -0
  72. package/workspace/public/pm/premium-vw-item-model.js +13 -7
  73. package/workspace/public/pm/premium-vw-item.js +49 -5
  74. package/workspace/public/pm/prog-order.css +47 -0
  75. package/workspace/public/pm/prog-order.js +188 -0
  76. package/workspace/public/pm/program-charter.js +47 -7
  77. package/workspace/public/pm/program-model.js +79 -1
  78. package/workspace/public/pm/task-card.css +108 -0
  79. package/workspace/public/pm/task-card.js +271 -0
  80. package/workspace/public/pm/wf-page.js +3 -0
  81. package/workspace/server.js +23 -1
  82. package/workspace/skills/milestone-review.skill +53 -0
  83. package/workspace/skills/workflow-setup.skill +14 -5
  84. package/workspace/stage-card-test.js +11 -0
  85. package/workspace/task-card-test.js +248 -0
  86. package/workspace/test-lists/bd-ini-panel.json +5 -0
  87. package/workspace/test-lists/core-documents-backend.json +15 -3
  88. package/workspace/test-lists/milestone-suggest.json +6 -0
  89. package/workspace/test-lists/program-order.json +6 -0
  90. package/workspace/test-lists/task-card.json +6 -0
  91. package/workspace/test-lists/workflow-stage.json +5 -0
@@ -45,8 +45,15 @@ function build(f) {
45
45
  const row = f.row || {}, sheet = f.sheet || null, ini = (sheet && sheet.initiative) || {}, board = f.board || {};
46
46
  const missing = (f.missing || []).slice();
47
47
  if (!f.ladder && !missing.includes('workflow steps')) missing.push('workflow steps');
48
- const wf = (row.workflow && row.workflow.length ? row.workflow : board.workflow) || [];
49
- const names = wf.map((s) => s.name), cur = names.indexOf(row.stage);
48
+ // D99: the stages are the initiative's own workflow (row.wfStages, routes-boards workflowRowOf): the strip and the phase read them, and on a
49
+ // library workflow so does a move (bug 2026-10-25: a Tender initiative offered the old board stages Discover, Plan, Build & Deliver,
50
+ // Monitor & Evaluate). A move on Product feature still names the board's stages, which POST /api/boards/move checks. Tasks have no stage.
51
+ const boardWf = (row.workflow && row.workflow.length ? row.workflow : board.workflow) || [];
52
+ const own = Array.isArray(row.wfStages) && row.wfStages.length && row.wfStage ? row.wfStages.filter((s) => s.status !== 'skipped' || s.key === row.wfStage.key) : null;
53
+ const ownWf = !!(own && row.wf && row.wf.id && row.wf.id !== 'product-feature');
54
+ const names = own ? own.map((s) => s.name) : boardWf.map((s) => s.name);
55
+ const cur = own ? own.findIndex((s) => s.key === row.wfStage.key) : names.indexOf(row.stage);
56
+ const moveNames = own && !ownWf ? boardWf.map((s) => s.name) : names;
50
57
  const id = row.id || '';
51
58
  const key = 'init:' + id;
52
59
 
@@ -84,7 +91,7 @@ function build(f) {
84
91
 
85
92
  // ── tasks: PRD requirements (no result per requirement) and the board's tracker items ──
86
93
  const items = (f.items || []).filter((t) => t && t.ini === id).slice(0, MAX_TASKS);
87
- const tracker = items.map((t, n) => ({ key: 'task:' + (t.uid || t.key || n), uid: t.uid || '', pmos: t.src === 'pmos', ref: t.key || t.ref || '', title: clip(t.title, 160), state: t.status || 'To do', src: t.src === 'jira' ? 'Jira (read-only)' : 'PMOS task', owner: t.owner || '', start: t.start || '', end: t.end || '', blocked: !!t.blocked, kind: t.kind || 'Task' }));
94
+ const tracker = items.map((t, n) => ({ key: 'task:' + (t.uid || t.key || n), uid: t.uid || '', pmos: t.src === 'pmos', ref: t.key || t.ref || '', title: clip(t.title, 160), state: t.status || 'To do', src: t.src === 'jira' ? 'Jira (read-only)' : 'PMOS task', owner: t.owner || '', start: t.start || '', end: t.end || '', blocked: !!t.blocked, kind: t.kind || 'Task', notes: t.notes || '', readAt: t.readAt || '' }));
88
95
  const dv = sheet && sheet.derived;
89
96
  const reqs = dv && Array.isArray(dv.items) ? dv.items.slice(0, MAX_TASKS).map((x) => ({ key: 'req:' + x.id, ref: x.ref || x.id, title: clip(x.title, 160), state: null, src: 'PRD requirement' })) : [];
90
97
  const prog = ini.progress || null;
@@ -102,9 +109,11 @@ function build(f) {
102
109
 
103
110
  // ── documents ──
104
111
  const dd = f.docs || null;
112
+ // D99: an initiative on a library workflow groups its documents under its own stages (dd.phases), not Discover/Plan/Build/Evaluate
113
+ const phases = dd && Array.isArray(dd.phases) && dd.phases.length ? dd.phases.slice() : null;
105
114
  const all = dd ? (dd.docs || []).map((d) => ({
106
115
  key: d.key, title: d.title, what: d.for || '', st: d.st, state: d.kind === 'live' ? 'Live' : DOC_STATE[d.st] || d.st || '', by: BY[d.by] || d.by || '', byKey: d.by || '',
107
- when: d.when ? shortDate(d.when) : '', cat: d.cat === 'Do' ? 'Build' : d.cat === 'Learn' ? 'Evaluate' : d.cat || 'Board', path: d.open && d.open.path ? d.open.path : null, slot: d.st === 'draft' && d.draft && d.draft.slot ? d.draft.slot : '', running: !!d.running, tech: TECH.has(d.key), kind: d.kind || '', reader: d.reader || '', cadence: d.cadence || '', sections: ((GUIDE[d.key] || {}).sections || []).slice(),
116
+ when: d.when ? shortDate(d.when) : '', cat: phases ? (d.other ? null : d.cat || null) : d.cat === 'Do' ? 'Build' : d.cat === 'Learn' ? 'Evaluate' : d.cat || 'Board', ...(d.other ? { other: true } : {}), path: d.open && d.open.path ? d.open.path : null, slot: d.st === 'draft' && d.draft && d.draft.slot ? d.draft.slot : '', running: !!d.running, tech: TECH.has(d.key), kind: d.kind || '', reader: d.reader || '', cadence: d.cadence || '', sections: ((GUIDE[d.key] || {}).sections || []).slice(),
108
117
  act: d.act && d.act.do === 'draft' ? { kind: 'draft', label: d.running ? 'Drafting' : d.act.label || 'Draft it' } : null,
109
118
  from: d.from && d.from.text ? { path: d.from.path, heading: d.from.heading, text: d.from.text, cut: !!d.from.cut } : null,
110
119
  })) : [];
@@ -116,13 +125,14 @@ function build(f) {
116
125
  if (nLinked) cnt.linked = nLinked; // a key only when an added document is linked
117
126
  const docs = dd || custom.length ? { rows, counts: cnt, techCount: rows.length - core.length,
118
127
  cap: core.length ? [cnt.draft ? cnt.draft + ' ' + plural(cnt.draft, 'draft', 'drafts') + ' to review' : '', cnt.none ? cnt.none + ' not started' : '', cnt.ok ? cnt.ok + ' up to date' : '', nLinked ? nLinked + ' linked' : ''].filter(Boolean).join(' · ') : '',
119
- scope: (dd && dd.scope) || 'initiative:' + id, missing: !dd } : { rows: [], counts: { all: 0, none: 0, draft: 0, ok: 0 }, techCount: 0, cap: '', missing: true };
128
+ scope: (dd && dd.scope) || 'initiative:' + id, missing: !dd, ...(phases ? { phases, cur: dd.cat || phases[0] } : {}) } : { rows: [], counts: { all: 0, none: 0, draft: 0, ok: 0 }, techCount: 0, cap: '', missing: true };
120
129
  if (!dd && !missing.includes('core documents')) missing.push('core documents');
121
130
 
122
131
  // ── PMOS can help: only things a press can really do. A draft of a core document the initiative has not started (the existing read-only draft run), and a question for the read-only agent ──
123
132
  const phase = Math.max(0, PHASE_OF_CAT[row.cat] != null ? PHASE_OF_CAT[row.cat] : Math.max(0, cur >= 0 && names.length ? Math.floor(cur / Math.max(1, names.length) * 4) : 0));
124
133
  const help = [];
125
- const nd = docs.rows.find((d) => d.st === 'missing' && !d.tech && d.act && d.act.kind === 'draft' && DOC_CAT_ORDER.indexOf(d.cat) <= phase);
134
+ const docAt = (d) => (docs.phases ? docs.phases.indexOf(d.cat) <= docs.phases.indexOf(docs.cur) && docs.phases.includes(d.cat) : DOC_CAT_ORDER.indexOf(d.cat) <= phase);
135
+ const nd = docs.rows.find((d) => d.st === 'missing' && !d.tech && d.act && d.act.kind === 'draft' && docAt(d));
126
136
  if (nd) help.push({ label: 'Draft the ' + nd.title.toLowerCase(), kind: 'draft', key: nd.key });
127
137
  const wantsOptions = bad || (lad && lad.next && /^(review|accept)$/.test(lad.next.step));
128
138
  if (wantsOptions) help.push({ label: lad ? 'Summarise the review findings' : 'Lay out the options', kind: 'ask', q: lad ? 'Summarise the review findings for this initiative, from the evidence you can read in this repository. Say what you could not find.' : 'Lay out the options for this initiative, from what you can read in this repository, and say what you could not find. Do not recommend one unless the records do.' });
@@ -143,7 +153,7 @@ function build(f) {
143
153
  id, key, title: clip(row.title || id, 160), lane: row.lane || '', anchor: row.anchor || '',
144
154
  // the bar's presses (initiative premium-board-actions): the workflow, the lifecycle and the archive entry the row holds
145
155
  acts: {
146
- self: !!board.self, stages: names, stage: row.stage || null,
156
+ self: !!board.self, stages: moveNames, stage: (ownWf ? names[cur] : row.stage) || null,
147
157
  life: status === 'on hold' ? 'hold' : status === 'cancelled' ? 'cancelled' : null,
148
158
  reason: (status === 'on hold' || status === 'cancelled') && row.stopped ? clip(row.stopped.reason || '', 300) : '',
149
159
  back: status === 'on hold' && row.stopped && row.stopped.back ? shortDate(row.stopped.back) : '', backDay: status === 'on hold' && row.stopped && row.stopped.back ? String(row.stopped.back).slice(0, 10) : null,
@@ -10,6 +10,10 @@
10
10
  * pmos item list <initiative> [--json]
11
11
  * common: [--root <dir>]
12
12
  *
13
+ * --stage is the group of the breakdown an item sits in (lib/plan-tree.js stagesFor). It is not the initiative's workflow stage, which the
14
+ * stage card and the Board show and `pmos workflow of|move` read and move (bug 2026-10-25: an agent asked to move an initiative along its
15
+ * workflow changed 47 items' --stage instead). Progress is an item's state: `pmos item move`.
16
+ *
13
17
  * The SAME writer and the SAME fold the workspace page uses (lib/plan-items.js) — no server is needed, and
14
18
  * the terminal and the page cannot disagree about an item. Who wrote a line is decided by the call path,
15
19
  * never by an argument: `pm:wawan` at an interactive terminal, the bound session from PMOS_SESSION, and
@@ -32,7 +36,8 @@ const USAGE = [
32
36
  ' pmos item withdraw <item>',
33
37
  ' pmos item list <initiative>',
34
38
  ' every command: [--json] [--root <dir>]',
35
- 'An item id is <initiative>.<10 characters>. A stage is an id or a label of the initiative\'s stages.',
39
+ 'An item id is <initiative>.<10 characters>. --stage is the group of the breakdown the item sits in, not a workflow stage.',
40
+ 'To report progress, set the item\'s state with pmos item move. To see or move the initiative\'s workflow stage, use pmos workflow of|move.',
36
41
  'Who wrote each line comes from where the command runs: you at a terminal, the agent session otherwise.',
37
42
  'Keep is pressed on the workspace page (Breakdown or Today). This command does not write it.',
38
43
  ];
@@ -128,7 +133,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
128
133
  if (!planItems.INIT_RE.test(initiative) || !planTree.recordPath(root, initiative)) return fail(`no initiative ${initiative} in this repository`);
129
134
  if (!flags.stage) {
130
135
  const stages = planTree.stagesFor(root, initiative);
131
- say(`--stage is required — the stages of ${initiative} are: ${stages.map((s) => `${s.id} (${s.label})`).join(', ')}`);
136
+ say(`--stage is required — the breakdown groups of ${initiative} are: ${stages.map((s) => `${s.id} (${s.label})`).join(', ')}. The initiative's workflow stage is pmos workflow of ${initiative}.`);
132
137
  return 2;
133
138
  }
134
139
  const ev = { ev: 'planned', initiative, title, stage: flags.stage };
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+ /* lib/milestone-review.js — Claude reviews a program's milestones and files suggestions the PM keeps, changes or drops (feedback batch 4 item 6;
3
+ * canvas XmsgB, the sticky xmsgRules).
4
+ *
5
+ * off(env) → true when PMOS_MS_REVIEW=off (or 0, false, no)
6
+ * reviewPrompt(skill, o) → the prompt of one run. o: { program, run, why, now, open, declined, roots, rows }
7
+ * create(deps) → { tick(opts), active() }
8
+ *
9
+ * WHEN (lib/milestone-suggest.js dueOf): Check now at once; else inside the working hours, for a program never reviewed, after an initiative
10
+ * joins or leaves, after the page saw a ◆ date move (a Jira slip moves one too), when a milestone's date comes, and every Monday from 09:00.
11
+ * At most ONE run at a time for the machine, and one start per tick. A run that ends badly waits 6 hours before the next automatic one.
12
+ *
13
+ * WHAT THE RUN MAY DO. It is headless (lib/headless.js kind ms-review, origin `ms-review:<program>:<run>`): it reads and searches the repositories
14
+ * of the program's initiatives (their records, plan items and meeting notes) and, where the PM's own Claude Code settings allow it, reads Jira and
15
+ * the meeting notes through connectors. Its only write is `pmos program suggest`, pinned by the server to this program and run
16
+ * (PMOS_MS_REVIEW_FILE, PMOS_MS_REVIEW_RUN, PMOS_MS_REVIEW_PROGRAM). It never writes the charter: only the PM's press does (POST
17
+ * /api/programs/suggestion). Nothing is sent.
18
+ *
19
+ * deps: { programs() → [program with home], reviewOf(p) → { file, state } | null, rootOf(ws) → root | null, open(now) → bool (working hours),
20
+ * headlessOff() → bool, env, promptFor(skillId) → skill body | null, rowsOf(p) → [{ id, title, stage, deliver }] (what the server's last
21
+ * board read says, or []), spawn(spec) → session row (through the capacity governor), spawnNow(spec) (Check now), stop(session),
22
+ * append(file, line), warn(what, err) }
23
+ */
24
+ const crypto = require('crypto');
25
+ const MS = require('./milestone-suggest.js');
26
+
27
+ const flagOff = (v) => /^(off|0|false|no)$/i.test(String(v || '').trim());
28
+ const off = (env) => flagOff((env || process.env).PMOS_MS_REVIEW);
29
+ const one = (s, n) => String(s == null ? '' : s).replace(/\s+/g, ' ').trim().slice(0, n);
30
+ const WHY = {
31
+ asked: 'The PM pressed Check now.',
32
+ new: 'The program has never been reviewed. If it has no milestones, suggest its first ones.',
33
+ members: 'An initiative joined or left the program.',
34
+ dates: 'A ◆ date of one of its initiatives moved (a plan or Jira change).',
35
+ date: 'A milestone\'s date has come.',
36
+ weekly: 'The weekly review (Monday).',
37
+ };
38
+
39
+ function reviewPrompt(skill, o) {
40
+ const p = o.program;
41
+ const ms = (p.milestones || []).map((m) => `- ${m.id} · ${one(m.name, 80)} · ${m.date || 'no date'} · ${(m.waits || []).length ? 'waits on ' + m.waits.join(', ') : 'a check the PM ticks'}${m.done ? ' · done' : ''}${m.risk ? ' · at risk: ' + one(m.risk, 120) : ''}`);
42
+ const mem = (p.members || []).map((m) => { const r = (o.rows || []).find((x) => x.id === m.initiative); return `- ${m.initiative}${r ? ` · ${one(r.title, 80)} · stage ${one(r.stage, 30) || 'unknown'}${r.deliver ? ' · ◆ ' + r.deliver : ''}` : ''} · repository ${(o.roots || {})[m.ws] || 'not on this machine'}`; });
43
+ const open = (o.open || []).map((i) => `- ${JSON.stringify({ op: i.op, milestone: i.milestone, name: i.name, date: i.date, waits: i.waits, why: i.why, src: i.src })}`);
44
+ const dec = (o.declined || []).map((x) => `- ${x}`);
45
+ const list = (a, none) => (a.length ? a.join('\n') : '- ' + none);
46
+ return `${skill}\n\nThis run:\n- Run: ${o.run}\n- Today: ${new Date(o.now).toISOString().slice(0, 10)}\n- Why it runs: ${WHY[o.why] || WHY.weekly}\n`
47
+ + `- Program: ${p.id} · ${one(p.title, 120)}${p.goal ? ' · goal: ' + one(p.goal, 160) : ''}\n- Span: ${p.start || 'no start'} to ${p.target || 'no target'}${p.jira ? '\n- Jira: ' + one(p.jira, 40) : ''}\n`
48
+ + `- Milestones (${(p.milestones || []).length} of 12):\n${list(ms, 'none yet')}\n- Initiatives in the program:\n${list(mem, 'none')}\n`
49
+ + `- Open suggestions from the last review (file again each one that still holds; one you do not file again is withdrawn):\n${list(open, 'none')}\n`
50
+ + `- Declined by the PM (do not suggest these again from the same source):\n${list(dec, 'none')}\n\n`
51
+ + 'File each suggestion with `pmos program suggest --json -`. File at most 8. Write no charter. Send nothing.';
52
+ }
53
+
54
+ function create(deps) {
55
+ const active = new Map(); // run → { p, file, session }
56
+ const warn = deps.warn || (() => {});
57
+
58
+ function ended(run, r, now = Date.now()) {
59
+ const a = active.get(run); if (!a) return;
60
+ active.delete(run);
61
+ const res = (r && r.result) || {};
62
+ const ok = !!(r && !r.timedOut && !r.stopped && r.code === 0 && res.ok && !res.isError);
63
+ try { deps.append(a.file, { kind: 'review-end', program: a.p.id, run, ok, ...(ok ? {} : { error: one((r && r.note) || res.text || 'the run failed', 200) }) }, new Date(now)); } catch (e) { warn('milestone review end', e); }
64
+ }
65
+
66
+ function start(p, R, why, now) {
67
+ const run = 'r' + now.toString(36) + crypto.randomBytes(3).toString('hex');
68
+ const begin = () => { deps.append(R.file, { kind: 'review-start', program: p.id, run, why, members: MS.membersFp(p) }, new Date(now)); active.set(run, { p, file: R.file, session: null }); };
69
+ const skill = deps.promptFor('milestone-review');
70
+ if (!skill) { begin(); ended(run, { code: 1, note: 'the milestone-review skill is not installed', result: {} }, now); return; }
71
+ const st = R.state;
72
+ const open = st ? MS.openOf(st, p) : [];
73
+ const declined = st ? [...st.items.values()].filter((i) => st.answers.get(i.key) === 'decline').map((i) => `${i.op} ${i.milestone || i.name}${i.date ? ' to ' + i.date : ''} (source: ${i.src.kind}, ${i.src.label})`) : [];
74
+ const roots = {};
75
+ for (const m of p.members || []) if (!(m.ws in roots)) roots[m.ws] = deps.rootOf(m.ws) || '';
76
+ let rows = [];
77
+ try { rows = (deps.rowsOf && deps.rowsOf(p)) || []; } catch { rows = []; }
78
+ const prompt = reviewPrompt(skill, { program: p, run, why, now, open, declined, roots, rows });
79
+ const home = deps.rootOf(p.home);
80
+ const addDirs = [...new Set(Object.values(roots).filter((r) => r && r !== home))];
81
+ // Check now is the PM's press: it starts at once (deps.spawnNow); the rest go through the capacity governor, which may hold a start
82
+ const go = why === 'asked' && deps.spawnNow ? deps.spawnNow : deps.spawn;
83
+ let session = null;
84
+ try {
85
+ session = go({ name: 'Milestone review · ' + one(p.title, 60), ws: p.home, origin: `ms-review:${p.id}:${run}`, initialInput: prompt + '\r', addDirs,
86
+ env: { PMOS_MS_REVIEW_FILE: R.file, PMOS_MS_REVIEW_RUN: run, PMOS_MS_REVIEW_PROGRAM: p.id }, onDone: (r) => ended(run, r) });
87
+ } catch (e) { warn('milestone review', e); }
88
+ if (session && session.held) return; // held by the capacity governor: nothing is written, the next tick tries again
89
+ begin();
90
+ if (!session || session.state === 'exited' || session.headless !== 'ms-review') {
91
+ // a start that did not become a headless run (no `claude`, headless off, a refused model) is a failed run, never a pane
92
+ if (session && session.headless !== 'ms-review' && session.state !== 'exited' && deps.stop) { try { deps.stop(session); } catch { /* best effort */ } }
93
+ ended(run, { code: 1, note: (session && session.note) || 'the review could not start as a background run', result: {} }, now);
94
+ return;
95
+ }
96
+ const a = active.get(run); if (a) a.session = session.id;
97
+ }
98
+
99
+ function tick({ now = Date.now(), env } = {}) {
100
+ if (off(env || deps.env) || (deps.headlessOff && deps.headlessOff())) return { off: true };
101
+ if (active.size) return { running: active.size };
102
+ let open = true;
103
+ try { open = deps.open ? !!deps.open(now) : true; } catch { open = true; }
104
+ for (const p of deps.programs() || []) {
105
+ if (!p || !p.home || p.archived) continue;
106
+ let R = null;
107
+ try { R = deps.reviewOf(p); } catch (e) { warn('milestone review read', e); }
108
+ if (!R) continue;
109
+ const due = MS.dueOf(R.state, p, now, { open });
110
+ if (!due) continue;
111
+ try { start(p, R, due.why, now); } catch (e) { warn('milestone review start', e); }
112
+ return { started: p.id, why: due.why };
113
+ }
114
+ return { started: null };
115
+ }
116
+
117
+ return { tick, active: () => [...active.keys()] };
118
+ }
119
+
120
+ module.exports = { off, reviewPrompt, create, WHY };
@@ -0,0 +1,176 @@
1
+ 'use strict';
2
+ /* lib/milestone-suggest.js — Claude's milestone suggestions for a program, and the reviews that make them (feedback batch 4 item 6; canvas XmsgB,
3
+ * rules on the sticky xmsgRules).
4
+ *
5
+ * validItem(x) → { item } | { error } what one filed suggestion may say
6
+ * sigOf(item) · keyOf(program, item) the source signature (a decline remembers it) and the suggestion's key
7
+ * fold(lines) → { [program]: state } PURE. state: { items: Map key → item, answers: Map key → answer, declined: Set sig,
8
+ * runs: [run], asks: [iso], facts: fp | '' }
9
+ * openOf(state, program, now) → [item] what waits on the PM now: the latest finished review's items, less the answered,
10
+ * the declined and the ones the charter already says
11
+ * viewOf(state, program, now) → { checked, running, open } for GET /api/programs (each program's `review`)
12
+ * applyTo(program, item) → the charter body POST /api/programs/save takes, with the change made (✓ Keep)
13
+ * dueOf(state, program, now, o) → { why } | null should a review start now? o: { open (working hours), membersFp }
14
+ * membersFp(program) the member set as one string: a join or a leave changes it
15
+ * fileOf(stateDir) <state>/milestone-reviews.jsonl, in the charter's workspace
16
+ *
17
+ * A LINE is one of:
18
+ * { kind: 'review-start', program, run, why, members } a review began (why: new | members | asked | dates | date | weekly)
19
+ * { kind: 'review-end', program, run, ok, error? }
20
+ * { kind: 'suggest', program, run, key, item } one suggestion the review run filed (`pmos program suggest`)
21
+ * { kind: 'answer', program, key, answer } the PM's press: keep (written at once) · edit (saved from the charter) · decline
22
+ * { kind: 'review-ask', program, why } Check now (why 'asked'), or the page saw a ◆ date move (why 'dates')
23
+ * { kind: 'facts', program, fp } the ◆ dates the page last saw, so a move asks for a review once
24
+ *
25
+ * THE RULES (xmsgRules). Claude proposes add, move, rename, drop or at risk, each with why and its source. Nothing is written without the PM:
26
+ * keep writes the charter in one press, the pencil opens the charter with the change filled in, decline drops it and Claude does not ask again
27
+ * unless that source changes (the signature holds the source's label, so "Jira, Oct 30" is a new source after "Jira, Oct 22"). A review files
28
+ * the whole list it stands by: a suggestion an older review filed and the latest one did not is no longer open. No change, nothing shows. */
29
+ const path = require('path');
30
+ const crypto = require('crypto');
31
+
32
+ const OPS = ['add', 'move', 'rename', 'drop', 'risk'];
33
+ const SRC = ['deliver', 'jira', 'meeting', 'task', 'target', 'member', 'charter'];
34
+ const ID_RE = /^[a-z0-9][a-z0-9-]{0,60}$/;
35
+ const INI_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
36
+ const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
37
+ const MAX_MS = 12;
38
+ const RUN_MS = 30 * 60 * 1000; // a start with no end after this is over (the server stopped mid-run)
39
+ const GAP_MS = 30 * 60 * 1000; // two automatic reviews of one program are this far apart at least
40
+ const RETRY_MS = 6 * 60 * 60 * 1000; // after a failed run, the next automatic one waits this long
41
+ const SLOT_H = 9; // the weekly review: Monday from 09:00
42
+ const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').replace(/\s+/g, ' ').trim().slice(0, n);
43
+ const slug = (t) => String(t || '').toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '').slice(0, 50);
44
+ const fileOf = (stateDir) => path.join(stateDir, 'milestone-reviews.jsonl');
45
+
46
+ /** One filed suggestion: { op, milestone?, name?, date?, waits?, why, src: { kind, label } }. Each op says what it needs. */
47
+ function validItem(x) {
48
+ if (!x || typeof x !== 'object' || Array.isArray(x)) return { error: 'a suggestion is a JSON object' };
49
+ const op = String(x.op || '');
50
+ if (!OPS.includes(op)) return { error: 'op is one of ' + OPS.join(', ') };
51
+ const why = str(x.why, 240);
52
+ if (!why) return { error: 'why says, in one line, what you read that makes the change' };
53
+ const s = x.src && typeof x.src === 'object' ? x.src : {};
54
+ if (!SRC.includes(String(s.kind || ''))) return { error: 'src.kind is one of ' + SRC.join(', ') };
55
+ const label = str(s.label, 80);
56
+ if (!label) return { error: 'src.label names the source, for example "Steering, Oct 22" or "Jira DSC-41"' };
57
+ const item = { op, why, src: { kind: String(s.kind), label } };
58
+ if (op !== 'add') {
59
+ if (!ID_RE.test(String(x.milestone || ''))) return { error: op + ' names the milestone by its id (milestone)' };
60
+ item.milestone = String(x.milestone);
61
+ }
62
+ if (op === 'add' || op === 'rename') {
63
+ const name = str(x.name, 80);
64
+ if (!name) return { error: op + ' needs the milestone name (name)' };
65
+ item.name = name;
66
+ }
67
+ if (op === 'add' || op === 'move') {
68
+ if (!DAY_RE.test(String(x.date || ''))) return { error: op + ' needs the date as YYYY-MM-DD (date)' };
69
+ item.date = String(x.date);
70
+ }
71
+ if (op === 'add') {
72
+ const w = Array.isArray(x.waits) ? x.waits.map(String) : [];
73
+ const bad = w.find((i) => !INI_RE.test(i));
74
+ if (bad) return { error: 'waits holds initiative ids; ' + str(bad, 40) + ' is not one' };
75
+ item.waits = [...new Set(w)].slice(0, 20);
76
+ }
77
+ return { item };
78
+ }
79
+ /** What a decline remembers: the change and its source. A new source label is a new signature, so Claude may ask again. */
80
+ const sigOf = (i) => [i.op, i.milestone || slug(i.name), i.date || '', i.op === 'rename' ? slug(i.name) : '', i.src.kind, i.src.label.toLowerCase()].join('|');
81
+ const keyOf = (program, i) => 's' + crypto.createHash('sha1').update(program + '|' + sigOf(i)).digest('hex').slice(0, 12);
82
+
83
+ const blank = () => ({ items: new Map(), answers: new Map(), declined: new Set(), runs: [], asks: [], facts: '', factsAt: '' });
84
+ function fold(lines) {
85
+ const out = {};
86
+ const get = (id) => out[id] || (out[id] = blank());
87
+ for (const l of lines || []) {
88
+ if (!l || typeof l !== 'object' || !ID_RE.test(String(l.program || ''))) continue;
89
+ const s = get(String(l.program));
90
+ if (l.kind === 'review-start' && l.run) s.runs.push({ run: String(l.run), start: l.at || '', why: l.why || '', members: l.members || '', end: '', ok: null, error: '' });
91
+ else if (l.kind === 'review-end' && l.run) { const r = s.runs.find((x) => x.run === String(l.run)); if (r && !r.end) Object.assign(r, { end: l.at || '', ok: !!l.ok, error: l.error || '' }); }
92
+ else if (l.kind === 'suggest' && l.key && l.item) { const v = validItem(l.item); if (v.item) s.items.set(String(l.key), { ...v.item, key: String(l.key), run: String(l.run || ''), at: l.at || '' }); }
93
+ else if (l.kind === 'answer' && l.key && ['keep', 'edit', 'decline'].includes(l.answer)) {
94
+ s.answers.set(String(l.key), l.answer);
95
+ const it = s.items.get(String(l.key));
96
+ if (it && l.answer === 'decline') s.declined.add(sigOf(it));
97
+ } else if (l.kind === 'review-ask') s.asks.push({ at: l.at || '', why: l.why || 'asked' });
98
+ else if (l.kind === 'facts' && typeof l.fp === 'string') { s.facts = l.fp; s.factsAt = l.at || ''; }
99
+ }
100
+ return out;
101
+ }
102
+ const ms = (iso) => { const t = Date.parse(iso || ''); return Number.isFinite(t) ? t : 0; };
103
+ const runningOf = (s, now) => (s ? s.runs.filter((r) => !r.end && now - ms(r.start) < RUN_MS) : []);
104
+ const lastDone = (s) => (s ? s.runs.filter((r) => r.end && r.ok).sort((a, b) => ms(a.end) - ms(b.end)).pop() || null : null);
105
+
106
+ /** True when the charter already says what the item would change, or the item no longer has anything to change. */
107
+ function stale(i, p) {
108
+ const M = (p && p.milestones) || [];
109
+ const m = i.milestone ? M.find((x) => x.id === i.milestone) : null;
110
+ if (i.op === 'add') return M.length >= MAX_MS || M.some((x) => slug(x.name) === slug(i.name));
111
+ if (!m) return true;
112
+ if (i.op === 'move') return m.date === i.date;
113
+ if (i.op === 'rename') return m.name === i.name;
114
+ if (i.op === 'risk') return !!m.risk || !!m.done;
115
+ return false;
116
+ }
117
+ function openOf(s, p) {
118
+ const last = lastDone(s);
119
+ if (!last) return [];
120
+ const out = [];
121
+ for (const it of s.items.values()) {
122
+ if (it.run !== last.run || s.answers.has(it.key) || s.declined.has(sigOf(it)) || stale(it, p)) continue;
123
+ out.push(it);
124
+ }
125
+ // the program's own order: by the date the change is about, then what it is
126
+ const dayOf = (i) => i.date || (((p && p.milestones) || []).find((m) => m.id === i.milestone) || {}).date || '9999';
127
+ return out.sort((a, b) => dayOf(a).localeCompare(dayOf(b)) || OPS.indexOf(a.op) - OPS.indexOf(b.op));
128
+ }
129
+ function viewOf(s, p, now = Date.now()) {
130
+ const last = lastDone(s);
131
+ return { checked: last ? last.end : '', running: runningOf(s, now).length > 0, open: s ? openOf(s, p) : [], facts: (s && s.facts) || '' };
132
+ }
133
+
134
+ /** The charter with the item's change made, as validProgram takes it. The milestone keeps its id; a new one gets one from its name. */
135
+ function applyTo(p, i) {
136
+ let L = ((p && p.milestones) || []).map((m) => ({ ...m, waits: (m.waits || []).slice() }));
137
+ if (i.op === 'add') L.push({ name: i.name, date: i.date, waits: (i.waits || []).slice() });
138
+ else {
139
+ const m = L.find((x) => x.id === i.milestone);
140
+ if (!m) return { error: 'that milestone is no longer in the charter' };
141
+ if (i.op === 'move') m.date = i.date;
142
+ else if (i.op === 'rename') m.name = i.name;
143
+ else if (i.op === 'risk') m.risk = i.why;
144
+ else if (i.op === 'drop') L = L.filter((x) => x !== m);
145
+ }
146
+ if (L.length > MAX_MS) return { error: 'the charter holds 12 milestones at most' };
147
+ L.sort((a, b) => String(a.date || '9999').localeCompare(String(b.date || '9999')));
148
+ return { program: { id: p.id, title: p.title, owner: p.owner, goal: p.goal, why: p.why, start: p.start, target: p.target, jira: p.jira, milestones: L } };
149
+ }
150
+
151
+ const membersFp = (p) => ((p && p.members) || []).map((m) => (m.ws || '') + ':' + m.initiative).sort().join(',');
152
+ /** The Monday 00:00 (local) of the week that holds `t`. */
153
+ function weekStart(t) { const d = new Date(t); d.setHours(0, 0, 0, 0); d.setDate(d.getDate() - ((d.getDay() + 6) % 7)); return d.getTime(); }
154
+
155
+ /** Should a review of this program start now? Check now goes at once; the rest wait for the working hours, keep GAP_MS apart, and RETRY_MS
156
+ * after a failed run. The reasons, in order: asked · new (never reviewed) · members (a join or a leave) · dates (the page saw a ◆ date move) ·
157
+ * date (a milestone's date came) · weekly (Monday from 09:00, once a week). */
158
+ function dueOf(s, p, now, o = {}) {
159
+ if (runningOf(s, now).length) return null;
160
+ const runs = (s && s.runs) || [];
161
+ const last = runs.slice().sort((a, b) => ms(a.start) - ms(b.start)).pop() || null;
162
+ const since = last ? ms(last.start) : 0;
163
+ const asks = ((s && s.asks) || []).filter((a) => ms(a.at) > since);
164
+ if (asks.some((a) => a.why === 'asked')) return { why: 'asked' };
165
+ if (o.open === false) return null;
166
+ if (last && now - since < (last.end && !last.ok ? RETRY_MS : GAP_MS)) return null;
167
+ if (!last) return { why: 'new' };
168
+ if ((last.members || '') !== membersFp(p)) return { why: 'members' };
169
+ if (asks.length) return { why: 'dates' };
170
+ if (((p && p.milestones) || []).some((m) => m.date && DAY_RE.test(m.date) && !m.done && (() => { const d = new Date(m.date + 'T00:00:00').getTime(); return d > since && d <= now; })())) return { why: 'date' };
171
+ const d = new Date(now);
172
+ if (d.getDay() === 1 && d.getHours() >= SLOT_H && since < weekStart(now)) return { why: 'weekly' };
173
+ return null;
174
+ }
175
+
176
+ module.exports = { OPS, SRC, validItem, sigOf, keyOf, fold, openOf, viewOf, applyTo, dueOf, membersFp, fileOf, weekStart, RUN_MS };
@@ -534,7 +534,7 @@ function buildRecord(ctx, ev, index) {
534
534
  const stages = stagesOf(initiative);
535
535
  const want = String(v == null ? '' : v).toLowerCase().replace(/\s+/g, ' ').trim();
536
536
  const hit = stages.find((s) => s.id === want || String(s.label).toLowerCase() === want);
537
- if (!hit) return refuse(400, `unknown stage ${JSON.stringify(v)} — the stages of ${initiative} are ${stages.map((s) => s.id).join(', ')}`, index2);
537
+ if (!hit) return refuse(400, `unknown stage ${JSON.stringify(v)} — the stages of ${initiative} are ${stages.map((s) => s.id).join(', ')}. They group the breakdown; the initiative's workflow stage is pmos workflow of ${initiative}`, index2);
538
538
  return { id: hit.id };
539
539
  };
540
540
  /* Only the predecessors a call ADDS are checked: an item whose predecessor was withdrawn later must still be able to
@@ -64,7 +64,13 @@ const VERBS = Object.freeze({
64
64
  help: 'pmos lead put|show|due — Claude\'s short lead for a popup, written ahead from stored reads (pmos lead help)' }),
65
65
  // Not a pm-os-absorb verb (run: null): workflows-per-initiative (D99) added it through the same table.
66
66
  workflow: Object.freeze({ module: 'workflow-cli.js', run: null, guide: 'workflows.md',
67
- help: 'pmos workflow list|show|draft|show-draft|judge … — the workflows of this repository, the New workflow draft, and a reading of an Only-when stage (pmos workflow help)' }),
67
+ help: 'pmos workflow list|show|draft|show-draft|judge|of|move|switch … — the workflows of this repository, the New workflow draft, a reading of an Only-when stage, and an initiative\'s workflow stage (pmos workflow help)' }),
68
+ // Not a pm-os-absorb verb (run: null): feedback batch 4 (Wawan, 2026-10-25) added it through the same table.
69
+ task: Object.freeze({ module: 'task-cli.js', run: null, guide: 'workflows.md',
70
+ help: 'pmos task list|state … — an initiative\'s Board tasks, and setting their state when the PM asks (pmos task help)' }),
71
+ // Not a pm-os-absorb verb (run: null): feedback batch 4 item 6 (Claude suggests program milestones) added it through the same table.
72
+ program: Object.freeze({ module: 'program-cli.js', run: null, guide: 'programs.md',
73
+ help: 'pmos program suggest — Claude\'s milestone suggestions for a program, filed by its review run (pmos program help)' }),
68
74
  // Not a pm-os-absorb verb (run: null): c3-meet-extension added it through the same table.
69
75
  extension: Object.freeze({ module: 'extension-cli.js', run: null, guide: 'console-calendar.md',
70
76
  help: 'pmos extension — the folder of the Chrome extension for Google Meet, and the three steps to load it' }),
@@ -16,7 +16,7 @@ const isAsk = (text) => ASK_RE.test(String(text == null ? '' : text)) && !String
16
16
 
17
17
  const RULE = [
18
18
  'PMOS has programs. A program is the level above initiatives (Program > Initiative > Epic) and can span products. It has no stages of its own: its state, products and stage spread come from its initiatives.',
19
- 'A program is a record in programs.jsonl in a workspace state folder (pmos/state/ or the workspace state folder), one JSON line each: {"kind":"program",…} is the charter, {"kind":"member","program":"<id>","initiative":"<id>"} puts an initiative in it, and "leave", "task", "check" and "archive" lines follow the same pattern. A program id is its title in lower case with dashes, for example project-ascent.',
19
+ 'A program is a record in programs.jsonl in a workspace state folder (pmos/state/ or the workspace state folder), one JSON line each: {"kind":"program",…} is the charter, {"kind":"member","program":"<id>","initiative":"<id>"} puts an initiative in it, and "leave", "task", "check", "order" (the PM\'s sequence of its initiatives) and "archive" lines follow the same pattern. A program id is its title in lower case with dashes, for example project-ascent.',
20
20
  'A program is NOT a key on an initiative. Never add kind, program, programme, parent_program or parent_programme to an initiative record or any front matter: nothing reads them.',
21
21
  'You never make, change, join, leave or archive a program yourself, and you never write programs.jsonl: the routes refuse an agent session, and the PM presses on the Board.',
22
22
  'Tell the PM which press does what they asked:',
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+ /* program-cli.js — `pmos program suggest`: the one write of Claude's milestone review run (feedback batch 4 item 6; canvas XmsgB).
3
+ *
4
+ * pmos program suggest --json <file|-> files one suggestion, or a list of them, for the program the review runs on
5
+ *
6
+ * The server pins the program, the run and the file in the run's environment (PMOS_MS_REVIEW_PROGRAM, PMOS_MS_REVIEW_RUN, PMOS_MS_REVIEW_FILE;
7
+ * lib/milestone-review.js); outside such a run the verb refuses. It writes `suggest` lines and nothing else: the charter changes only when the
8
+ * PM keeps a suggestion, on the page. A suggestion the PM declined from the same source answers `declined`, one this run filed already
9
+ * `duplicate`. Exit codes: 0 filed, 1 refused, 2 usage. Nothing is sent. */
10
+ const fs = require('fs');
11
+ const pmItems = require('./pm-items.js');
12
+ const MS = require('./milestone-suggest.js');
13
+
14
+ const COMMANDS = { program: ['suggest'] };
15
+ const USAGE = [
16
+ 'usage: pmos program suggest — Claude\'s milestone suggestions for a program',
17
+ ' pmos program suggest --json <file|->',
18
+ ' File one suggestion (a JSON object) or a list of them, in a milestone review run only. Each one:',
19
+ ' { "op": "add|move|rename|drop|risk", "milestone": "<id, not for add>", "name": "<add, rename>", "date": "YYYY-MM-DD (add, move)",',
20
+ ' "waits": ["<initiative id>", … (add)], "why": "<one line>", "src": { "kind": "deliver|jira|meeting|task|target|member|charter", "label": "Steering, Oct 22" } }',
21
+ ' It answers filed, duplicate or declined for each. The PM keeps, changes or drops it on the page. Nothing is sent.',
22
+ ];
23
+ const MAX_PER_RUN = 8;
24
+
25
+ async function run(argv, { say = (s) => console.log(s), env = process.env, stdin } = {}) {
26
+ const args = argv[0] === 'program' ? argv.slice(1) : argv.slice();
27
+ const verb = args[0];
28
+ if (!verb || verb === 'help' || verb === '--help' || verb === '-h') { for (const l of USAGE) say(l); return verb ? 0 : 1; }
29
+ if (!COMMANDS.program.includes(verb)) { say(`unknown program command "${verb}" — one of ${COMMANDS.program.join(', ')}`); return 2; }
30
+ const i = args.indexOf('--json'), src = i >= 0 ? args[i + 1] : null;
31
+ if (!src) { say('usage: pmos program suggest --json <file|->'); return 2; }
32
+ const file = env.PMOS_MS_REVIEW_FILE, runId = env.PMOS_MS_REVIEW_RUN, program = env.PMOS_MS_REVIEW_PROGRAM;
33
+ if (!file || !runId || !program) { say('✗ pmos program suggest is for Claude\'s milestone review run. The PM changes milestones in the charter'); return 1; }
34
+ let text;
35
+ try { text = src === '-' ? (stdin !== undefined ? String(stdin) : fs.readFileSync(0, 'utf8')) : fs.readFileSync(src, 'utf8'); } catch (e) { say(`✗ could not read ${src}: ${String((e && e.message) || e).slice(0, 120)}`); return 1; }
36
+ let body;
37
+ try { body = JSON.parse(text); } catch { say('✗ the input is not JSON'); return 1; }
38
+ const list = Array.isArray(body) ? body : [body];
39
+ const st = MS.fold(pmItems.readLines(file))[program] || null;
40
+ const mine = st ? [...st.items.values()].filter((x) => x.run === runId) : [];
41
+ let bad = 0;
42
+ for (const x of list) {
43
+ const v = MS.validItem(x);
44
+ if (v.error) { say(`✗ refused: ${v.error}`); bad++; continue; }
45
+ const key = MS.keyOf(program, v.item);
46
+ if (st && st.declined.has(MS.sigOf(v.item))) { say(`declined ${key}: the PM dropped this change from the same source`); continue; }
47
+ if (mine.some((y) => y.key === key)) { say(`duplicate ${key}`); continue; }
48
+ if (mine.length >= MAX_PER_RUN) { say(`✗ refused: a review files ${MAX_PER_RUN} suggestions at most`); bad++; continue; }
49
+ pmItems.appendEvent(file, { kind: 'suggest', program, run: runId, key, item: v.item });
50
+ mine.push({ ...v.item, key, run: runId });
51
+ say(`filed ${key}`);
52
+ }
53
+ return bad ? 1 : 0;
54
+ }
55
+
56
+ module.exports = { run, COMMANDS, USAGE };
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * fold(lines) → { [id]: program } PURE. The program records of ONE workspace's ledger
5
5
  * merge(perWs) → [program] PURE. perWs: [{ ws, lines }]; the same program id in two workspaces is one program
6
- * program: { id, title, owner, goal, why, start, target, jira, from, milestones, members, tasks, home }
6
+ * program: { id, title, owner, goal, why, start, target, jira, from, milestones, members, tasks, order, home }
7
7
  * validProgram(b) · validMilestone(m, taken) what a write accepts, or { error }; a milestone with no id gets one from its name
8
+ * validOrder(list) the initiative ids of an order line, or { error }
8
9
  *
9
10
  * WHERE A PROGRAM LIVES. A program spans products, and a product is a workspace with its own state folder. So there is no one folder a
10
11
  * program "belongs" to: each workspace's <state>/programs.jsonl holds the program lines written FROM that workspace — the charter where the
@@ -13,7 +14,7 @@
13
14
  * `jira` is an optional key that is only read, never written to Jira.
14
15
  *
15
16
  * A LINE is one of:
16
- * { kind: 'program', id, title, owner?, goal?, start?, target?, jira?, from?, milestones?: [{ id, name, date?, waits: [initiative id], stages?: { [initiative]: ◆ stage key }, done? }] } the last wins
17
+ * { kind: 'program', id, title, owner?, goal?, start?, target?, jira?, from?, milestones?: [{ id, name, date?, waits: [initiative id], stages?: { [initiative]: ◆ stage key }, done?, risk? }] } the last wins
17
18
  * `from`: the initiative a turned program came from ("Turn into a program"), in the charter's workspace
18
19
  * { kind: 'check', program, milestone, done: true|false } the PM marks a program check done (canvas PgMilestones); the last line wins
19
20
  * { kind: 'member', program, initiative } the initiative (of the workspace whose ledger holds the line) joins the program
@@ -21,11 +22,15 @@
21
22
  * { kind: 'task', program, key, title, owner?, due? } a task on the program itself; the last line for a key wins
22
23
  * { kind: 'task-done', program, key, done: true|false }
23
24
  * { kind: 'archive', program }
25
+ * { kind: 'order', program, order: [initiative id] } the PM's sequence of the program's initiatives (canvas RoADrag, RoASuggest); the last
26
+ * line wins. It is a line of its own, not a charter key, so a charter save never drops it
24
27
  * A PROGRAM'S SPAN is `start` to `target` (canvas PgProgram, "Sep 2026 to Jun 2028"): a program can run for years, longer than any one
25
28
  * initiative. A MILESTONE waits on initiatives (it is ready when they pass ◆ Deliver, derived on the page), or on none: then it is "a program
26
29
  * check" (canvas PgMilestones) and its `done` is the PM's own mark, a `check` line. A milestone that waits on initiatives carries no `done`.
27
30
  * Nothing about a program is typed that its initiatives already say: its products, its state and its stage spread are derived on the page
28
- * (public/pm/program-model.js), from the initiatives' own rows. */
31
+ * (public/pm/program-model.js), from the initiatives' own rows.
32
+ * THE ORDER is one per program (option A, agreed 2026-10-25): the planned sequence the work happens in, not a dependency. Every place that lists
33
+ * the program's initiatives uses it (program-model.js inOrder); an initiative it does not name follows the named ones, A to Z. */
29
34
 
30
35
  const ID_RE = /^[a-z0-9][a-z0-9-]{0,60}$/;
31
36
  const INI_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,80}$/;
@@ -55,6 +60,9 @@ function validMilestone(m, taken) {
55
60
  const st = m.stages && typeof m.stages === 'object' && !Array.isArray(m.stages) ? Object.entries(m.stages).filter(([k, v]) => waits.includes(k) && typeof v === 'string' && /^[a-z0-9][a-z0-9-]{0,39}$/.test(v)) : [];
56
61
  if (st.length) out.stages = Object.fromEntries(st);
57
62
  if (!waits.length) out.done = m.done === true; // a program check: the PM marks it done; a milestone with initiatives is done when they are
63
+ // at risk (a kept suggestion of Claude's, canvas XmsgB): why, in one line; the charter clears it
64
+ const risk = str(m.risk, 240);
65
+ if (risk) out.risk = risk;
58
66
  return out;
59
67
  }
60
68
 
@@ -79,7 +87,15 @@ function validProgram(b) {
79
87
  return { kind: 'program', id, title, owner: str(b.owner, 80), goal: str(b.goal, 160), why: str(b.why, 600), start: b.start || '', target: b.target || '', jira: str(b.jira, 40), milestones };
80
88
  }
81
89
 
82
- const blank = (id) => ({ id, title: id, owner: '', goal: '', why: '', start: '', target: '', jira: '', from: '', milestones: [], members: [], tasks: [], archived: false, at: '' });
90
+ /** An order line's ids: initiative ids, each once, at most 80. An empty list is valid: it goes back to A to Z. */
91
+ function validOrder(list) {
92
+ if (!Array.isArray(list)) return { error: 'order is a list of initiative ids' };
93
+ const out = [];
94
+ for (const x of list) { const id = String(x == null ? '' : x); if (!INI_RE.test(id)) return { error: 'order names an initiative that is not an id: ' + str(id, 40) }; if (!out.includes(id)) out.push(id); }
95
+ return out.length > 80 ? { error: 'an order holds at most 80 initiatives' } : out;
96
+ }
97
+
98
+ const blank = (id) => ({ id, title: id, owner: '', goal: '', why: '', start: '', target: '', jira: '', from: '', milestones: [], members: [], tasks: [], order: [], archived: false, at: '' });
83
99
 
84
100
  /** A program check's done mark from the `check` lines (the last line for a milestone wins) over the charter's own `done`. */
85
101
  const withChecks = (milestones, checks) => (milestones || []).map((m) => {
@@ -115,6 +131,7 @@ function fold(lines) {
115
131
  const t = p.tasks.find((x) => x.key === String(l.key));
116
132
  if (t) t.done = !!l.done;
117
133
  } else if (l.kind === 'check' && ID_RE.test(String(l.milestone || ''))) p.checks[String(l.milestone)] = !!l.done;
134
+ else if (l.kind === 'order' && Array.isArray(l.order)) { const v = validOrder(l.order); if (!v.error) { p.order = v; p.orderSet = true; } }
118
135
  else if (l.kind === 'archive') p.archived = true;
119
136
  }
120
137
  for (const p of Object.values(out)) p.milestones = withChecks(p.milestones, p.checks);
@@ -130,15 +147,17 @@ function merge(perWs) {
130
147
  const m = all[p.id] || (all[p.id] = { ...blank(p.id), home: '', checks: {} });
131
148
  if (p.charter) Object.assign(m, { title: p.title, owner: p.owner, goal: p.goal, why: p.why, start: p.start, target: p.target, jira: p.jira, from: p.from, milestones: p.milestones, home: ws, at: p.at });
132
149
  Object.assign(m.checks, p.checks);
150
+ // the route writes the order line to the charter's workspace; a line elsewhere counts only while the charter's has none
151
+ if (p.orderSet && (p.charter || !m.orderHome)) { m.order = p.order; if (p.charter) m.orderHome = true; }
133
152
  for (const ini of p.members) if (!m.members.some((x) => x.ws === ws && x.initiative === ini)) m.members.push({ ws, initiative: ini });
134
153
  for (const t of p.tasks) m.tasks.push({ ...t, ws });
135
154
  if (p.archived) m.archived = true;
136
155
  }
137
156
  }
138
157
  // the check lines of every workspace apply to the charter's milestones (the route writes them to the charter's workspace)
139
- for (const m of Object.values(all)) { m.milestones = withChecks(m.milestones, m.checks); delete m.checks; }
158
+ for (const m of Object.values(all)) { m.milestones = withChecks(m.milestones, m.checks); delete m.checks; delete m.orderHome; }
140
159
  // a program with no charter anywhere is a member line whose program was never made: it is not shown
141
160
  return Object.values(all).filter((p) => p.home && !p.archived).sort((a, b) => String(a.title).localeCompare(String(b.title)));
142
161
  }
143
162
 
144
- module.exports = { fold, merge, validProgram, validMilestone, slug, ID_RE, INI_RE };
163
+ module.exports = { fold, merge, validProgram, validMilestone, validOrder, slug, ID_RE, INI_RE };