create-pmos 0.412.0 → 0.413.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 (62) hide show
  1. package/package.json +13 -13
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/scripts/pmos-log.sh +6 -3
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/board-programs-test.js +2 -2
  8. package/workspace/changelog.json +12 -0
  9. package/workspace/core-docs-workflow-test.js +144 -0
  10. package/workspace/guide/workflows.md +8 -1
  11. package/workspace/lib/board-premium.js +7 -2
  12. package/workspace/lib/briefing-premium-agent.js +16 -4
  13. package/workspace/lib/core-docs.js +79 -14
  14. package/workspace/lib/engine/boards.js +20 -12
  15. package/workspace/lib/initiative-chat.js +49 -0
  16. package/workspace/lib/initiative-premium.js +17 -7
  17. package/workspace/lib/item-cli.js +7 -2
  18. package/workspace/lib/plan-items.js +1 -1
  19. package/workspace/lib/pmos-verbs.js +1 -1
  20. package/workspace/lib/program-chat.js +1 -1
  21. package/workspace/lib/programs.js +21 -5
  22. package/workspace/lib/routes-boards.js +75 -13
  23. package/workspace/lib/routes-briefing-premium.js +17 -1
  24. package/workspace/lib/routes-core-docs.js +3 -1
  25. package/workspace/lib/routes-programs.js +12 -1
  26. package/workspace/lib/workflow-chat.js +1 -0
  27. package/workspace/lib/workflow-cli.js +91 -6
  28. package/workspace/package-lock.json +2 -2
  29. package/workspace/package.json +1 -1
  30. package/workspace/premium-chat-line-test.js +9 -0
  31. package/workspace/premium-vw-item-test.js +3 -3
  32. package/workspace/premium-vw-jira-test.js +2 -1
  33. package/workspace/program-order-test.js +180 -0
  34. package/workspace/public/pm/bd-prog.js +3 -3
  35. package/workspace/public/pm/cozy-viewer.js +8 -3
  36. package/workspace/public/pm/goal-chat.js +1 -1
  37. package/workspace/public/pm/home-app.js +22 -8
  38. package/workspace/public/pm/home-chat.js +6 -1
  39. package/workspace/public/pm/home-ini-model.js +42 -29
  40. package/workspace/public/pm/home-ini.css +1 -0
  41. package/workspace/public/pm/home-ini.js +26 -34
  42. package/workspace/public/pm/home-list.js +2 -1
  43. package/workspace/public/pm/home-stage-card.js +3 -1
  44. package/workspace/public/pm/home-task.js +41 -65
  45. package/workspace/public/pm/home-today.js +7 -5
  46. package/workspace/public/pm/premium-board.js +12 -6
  47. package/workspace/public/pm/premium-initiative-head.js +21 -11
  48. package/workspace/public/pm/premium-viewer.js +1 -0
  49. package/workspace/public/pm/premium-vw-item-model.js +13 -7
  50. package/workspace/public/pm/premium-vw-item.js +49 -5
  51. package/workspace/public/pm/prog-order.css +47 -0
  52. package/workspace/public/pm/prog-order.js +188 -0
  53. package/workspace/public/pm/program-model.js +75 -0
  54. package/workspace/public/pm/task-card.css +108 -0
  55. package/workspace/public/pm/task-card.js +271 -0
  56. package/workspace/skills/workflow-setup.skill +14 -5
  57. package/workspace/stage-card-test.js +11 -0
  58. package/workspace/task-card-test.js +248 -0
  59. package/workspace/test-lists/core-documents-backend.json +15 -3
  60. package/workspace/test-lists/program-order.json +6 -0
  61. package/workspace/test-lists/task-card.json +6 -0
  62. package/workspace/test-lists/workflow-stage.json +5 -0
@@ -20,7 +20,7 @@
20
20
  * INI_TEMPLATES · isBuildStage · templateBuilds · boardSettings(board) the per-initiative workflows (console3-initiatives-parity)
21
21
  * workflowOf(board, id, folded) → the stages an initiative runs: its own (ini-workflow), else the board's
22
22
  * applyIniWorkflow(board, wfNow, stage, template, stages, moveTo) → { ok, template, workflow, moved } | { ok:false, status, error }
23
- * taskOf(folded, id) · TASK_STATES · shiftDay(iso, days) PMOS tasks on a board
23
+ * taskOf(folded, id) · TASK_STATES · taskState(s) · shiftDay(iso, days) PMOS tasks on a board
24
24
  * itemStatus(status, category) · taskItem(task) · rollupItems(items) work items (PMOS tasks and Jira items) in one shape
25
25
  *
26
26
  * THE LEDGER. One append-only file per repository, <state dir>/boards.jsonl. A line is { at, by, kind, board, ... }:
@@ -36,7 +36,8 @@
36
36
  * new initiatives may pick, the template they start with)
37
37
  * ini-workflow { id, template, stages: [{ name, cat, hint }], moved: { from, to } | null } one initiative's own workflow
38
38
  * task { task, type: Task|Epic, initiative, title, epic, owner, state, start, due } a PMOS task (or PMOS epic) on the board
39
- * task-update { task, state?, start?, due?, title?, why } a status move, a reschedule or a rename
39
+ * task-update { task, state?, start?, due?, title?, owner?, notes?, initiative?, why } a status move, a reschedule, a rename or an edit in the Viewer
40
+ * ticket-note { ref, notes } the PM's own notes on a Jira ticket (Jira keeps its fields)
40
41
  * Nothing is deleted. A line that is not an object with a known kind is skipped.
41
42
  *
42
43
  * STAGE OF AN INITIATIVE on a team board: the last move recorded for it on that board (a workflow edit's `moved` and an
@@ -157,8 +158,10 @@ function foundOf(f) {
157
158
  const sources = Array.isArray(f.sources) ? f.sources.filter((x) => x && typeof x.ref === 'string').slice(0, 8).map((x) => ({ label: String(x.label || ''), ref: x.ref })) : [];
158
159
  return { why: typeof f.why === 'string' ? f.why : '', sources, match: typeof f.match === 'string' && f.match ? f.match : null, scan: typeof f.scan === 'string' ? f.scan : null, run: typeof f.run === 'string' ? f.run : null };
159
160
  }
160
- const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'task-remove', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto']);
161
- const TASK_STATES = Object.freeze(['To do', 'In progress', 'In review', 'Done']);
161
+ const KINDS = new Set(['board', 'workflow', 'move', 'assign', 'ask', 'ask-accept', 'ask-decline', 'ask-more', 'ini-workflow', 'task', 'task-update', 'task-remove', 'ticket-note', 'ini-epics', 'ini-archive', 'ini-notdup', 'ini-wf', 'ini-end', 'stage-judge', 'ini-auto']);
162
+ // A task's state is its only stage (Wawan, 2026-10-25): the same five every workflow ends in. An old 'In review' reads as In progress (taskState).
163
+ const TASK_STATES = Object.freeze(['To do', 'In progress', 'Done', "Won't do", 'Archived']);
164
+ const taskState = (s) => (s === 'In review' ? 'In progress' : TASK_STATES.includes(s) ? s : null);
162
165
 
163
166
  const copyStages = (stages) => stages.map((s) => ({ name: s.name, cat: s.cat, hint: s.hint || '' }));
164
167
  function templateWorkflow(name) {
@@ -184,6 +187,7 @@ function fold(events) {
184
187
  const stages = new Map(); // key(board, id) → stage name (the last move)
185
188
  const iniWorkflows = new Map(); // key(board, id) → { template, stages } (the initiative's own workflow)
186
189
  const tasks = new Map(); // task id → { id, board, initiative, title, epic, owner, state, start, due, at, by, history }
190
+ const ticketNotes = new Map(); // key(board, Jira key) → the PM's notes on that ticket (the last ticket-note line wins)
187
191
  const epics = new Map(); // initiative id → the Jira epic keys the PM linked to it (the last ini-epics line wins)
188
192
  const archives = new Map(); // initiative id → { at, by, reason, into, moved } while archived (an `archived: false` line restores it)
189
193
  const notDup = new Map(); // initiative id → Set of initiative ids the PM said it is not a duplicate of
@@ -250,16 +254,20 @@ function fold(events) {
250
254
  }
251
255
  } else if (e.kind === 'task' && b && typeof e.task === 'string' && typeof e.initiative === 'string' && !tasks.has(e.task)) {
252
256
  tasks.set(e.task, { id: e.task, board: b, initiative: e.initiative, kind: e.type === 'Epic' ? 'Epic' : 'Task', title: String(e.title || ''), epic: typeof e.epic === 'string' && e.epic ? e.epic : null,
253
- owner: typeof e.owner === 'string' && e.owner ? e.owner : null, state: TASK_STATES.includes(e.state) ? e.state : 'To do',
257
+ owner: typeof e.owner === 'string' && e.owner ? e.owner : null, notes: typeof e.notes === 'string' ? e.notes : '', state: taskState(e.state) || 'To do',
254
258
  start: typeof e.start === 'string' ? e.start : null, due: typeof e.due === 'string' ? e.due : null, at: e.at || null, by: e.by || null, history: [] });
255
259
  } else if (e.kind === 'task-update' && typeof e.task === 'string' && tasks.has(e.task)) {
256
260
  const t = tasks.get(e.task);
257
- if (TASK_STATES.includes(e.state)) t.state = e.state;
261
+ if (taskState(e.state)) t.state = taskState(e.state);
258
262
  if (typeof e.initiative === 'string' && e.initiative) t.initiative = e.initiative; // a merge moves the task (and its undo moves it back)
259
263
  if (typeof e.start === 'string') t.start = e.start;
260
264
  if (typeof e.due === 'string') t.due = e.due;
261
265
  if (typeof e.title === 'string' && e.title.trim()) t.title = e.title.trim(); // a rename (canvas RnATask)
266
+ if (typeof e.owner === 'string') t.owner = e.owner.trim() || null; // the Viewer's edits (canvas XetX1Rest); '' clears
267
+ if (typeof e.notes === 'string') t.notes = e.notes;
262
268
  t.history.push({ at: e.at || null, by: e.by || null, state: e.state || null, start: e.start || null, due: e.due || null, why: e.why || '' });
269
+ } else if (e.kind === 'ticket-note' && b && typeof e.ref === 'string' && typeof e.notes === 'string') {
270
+ if (e.notes) ticketNotes.set(key(b, e.ref), e.notes); else ticketNotes.delete(key(b, e.ref));
263
271
  } else if (e.kind === 'task-remove' && typeof e.task === 'string' && tasks.has(e.task)) {
264
272
  tasks.delete(e.task); // the Undo of a task just added (routes-boards.js tasks/undo-add)
265
273
  } else if (e.kind === 'ini-epics' && typeof e.id === 'string' && Array.isArray(e.epics)) {
@@ -300,7 +308,7 @@ function fold(events) {
300
308
  Object.assign(a, { state: 'declined', why: e.why || '', closedAt: e.at || null });
301
309
  }
302
310
  }
303
- return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, epics, archives, notDup, iniWf, ends, judged, autoOver, events: list };
311
+ return { boards, moves, assigns, asks, stages, iniWorkflows, tasks, ticketNotes, epics, archives, notDup, iniWf, ends, judged, autoOver, events: list };
304
312
  }
305
313
 
306
314
  /** The stages an initiative runs on a board: its own workflow when one is recorded, else the board's. */
@@ -316,7 +324,7 @@ function templateOf(board, id, folded) {
316
324
  }
317
325
  const taskOf = (folded, id) => (folded && folded.tasks ? folded.tasks.get(id) || null : null);
318
326
  /* ── work items: PMOS tasks and Jira items, one shape ── */
319
- const ITEM_PROGRESS = Object.freeze({ 'To do': 0, 'In progress': 0.45, 'In review': 0.8, Done: 1 });
327
+ const ITEM_PROGRESS = Object.freeze({ 'To do': 0, 'In progress': 0.45, 'In review': 0.8, Done: 1, "Won't do": 0, Archived: 0 });
320
328
  /** A Jira status (and its category) as one of the four item statuses. */
321
329
  function itemStatus(status, category) {
322
330
  const s = String(status || '');
@@ -327,17 +335,17 @@ function itemStatus(status, category) {
327
335
  }
328
336
  /** A PMOS task as a work item. */
329
337
  function taskItem(t) {
330
- return { uid: t.id, key: '', kind: t.kind === 'Epic' ? 'Epic' : 'Task', src: 'pmos', title: t.title, status: t.state, blocked: false, owner: t.owner || null,
338
+ return { uid: t.id, key: '', kind: t.kind === 'Epic' ? 'Epic' : 'Task', src: 'pmos', title: t.title, status: t.state, blocked: false, owner: t.owner || null, notes: t.notes || '',
331
339
  ini: t.initiative, epic: t.epic || null, start: t.start || null, end: t.due || null, ref: t.id, board: t.board };
332
340
  }
333
341
  /** Progress per item, and an epic's status, progress, blocked flag and dates rolled up from its items. Mutates and returns items. */
334
342
  function rollupItems(items) {
335
343
  for (const w of items) w.progress = ITEM_PROGRESS[w.status] || 0;
336
344
  for (const e of items.filter((w) => w.kind === 'Epic')) {
337
- const kids = items.filter((w) => w.epic && w.epic === e.uid);
345
+ const kids = items.filter((w) => w.epic && w.epic === e.uid && w.status !== 'Archived');
338
346
  if (!kids.length) continue;
339
347
  e.progress = Math.round((kids.reduce((n, w) => n + w.progress, 0) / kids.length) * 100) / 100;
340
- e.status = kids.every((w) => w.status === 'Done') ? 'Done' : kids.some((w) => w.status !== 'To do') ? 'In progress' : 'To do';
348
+ e.status = kids.every((w) => w.status === 'Done' || w.status === "Won't do") && kids.some((w) => w.status === 'Done') ? 'Done' : kids.some((w) => w.status !== 'To do') ? 'In progress' : 'To do';
341
349
  e.blocked = kids.some((w) => w.blocked);
342
350
  const starts = kids.map((w) => w.start).filter(Boolean).sort();
343
351
  const ends = kids.map((w) => w.end).filter(Boolean).sort();
@@ -787,6 +795,6 @@ module.exports = {
787
795
  CATEGORIES, WORKFLOW_TEMPLATES, TOOLS, SELF_LADDER, READING_CAT, STATUSES, ACTIVE, isActive, duplicatesOf, VIEWS, SORTS,
788
796
  templateWorkflow, isTemplateEdited, fold, readingOf, deriveStage, stageOf, catOf, moveWarnings, cardWarnings,
789
797
  applyWorkflowEdit, filterRows, health, counts, sprintsOf, backlogOf, key,
790
- INI_TEMPLATES, TASK_STATES, isBuildStage, templateBuilds, boardSettings, jiraProjectsOf, JIRA_KEY_RE, JIRA_PROJECT_RE, workflowOf, templateOf, applyIniWorkflow, taskOf, shiftDay,
798
+ INI_TEMPLATES, TASK_STATES, taskState, isBuildStage, templateBuilds, boardSettings, jiraProjectsOf, JIRA_KEY_RE, JIRA_PROJECT_RE, workflowOf, templateOf, applyIniWorkflow, taskOf, shiftDay,
791
799
  ITEM_PROGRESS, itemStatus, taskItem, rollupItems,
792
800
  };
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+ /* initiative-chat — what an initiative's chat knows about the initiative's workflow (bug 2026-10-25, Tender new CIAM).
3
+ * The PM changed an initiative's workflow on the page and asked its chat to move the initiative along it. The agent found no command that
4
+ * names an initiative's workflow, said the initiative was "not attached" to it, read the task stages of `pmos item` (lib/plan-tree.js) as
5
+ * the board's columns and moved 47 tasks. Two things are kept apart here, in the words the agent gets:
6
+ * the WORKFLOW stage is on the initiative (the stage card, the Board; `pmos workflow of|move|switch`, lib/workflow-cli.js);
7
+ * a task has no workflow stage: its only stage is its state (To do, In progress, Done, Won't do, Archived; Wawan, 2026-10-25).
8
+ * The chat's opening states the initiative's workflow and current stage (lib/briefing-premium-agent.js openingFor); in a live session, a
9
+ * message about a stage, a workflow or a move reaches the session with this rule first, read fresh, as lib/program-chat.js does for programs.
10
+ *
11
+ * infoOf(answer) → { id, title, wf: { id, name }, stage: { key, name, n, of }, stages: [{ key, name, status }], ended } | null
12
+ * from lib/routes-boards.js initiativeWorkflow's answer
13
+ * rule(info, id) → the rule's lines, with the workflow and stage when info is known
14
+ * isAsk(text) → whether a message is about a stage, a workflow or a move
15
+ * wrap(text, info, id) → the message as PMOS types it into a live session */
16
+
17
+ // The first line of every message PMOS wraps. The page reads it to show the PM's turn as typed (public/pm/goal-chat.js shownUser).
18
+ const MARK = '[PMOS initiative]';
19
+ const SAYS = 'The PM says: ';
20
+ const ASK_RE = /\b(stages?|workflows?|move[sd]?|moving|phases?|advance|next step)\b/i;
21
+
22
+ const isAsk = (text) => ASK_RE.test(String(text == null ? '' : text)) && !String(text).trim().startsWith('/');
23
+
24
+ function infoOf(a) {
25
+ if (!a || !a.ok || !a.row || !a.row.wf) return null;
26
+ const r = a.row, st = r.wfStage || {};
27
+ return { id: r.id, title: r.title, wf: { id: r.wf.id, name: r.wf.name }, stage: { key: st.key, name: st.name, n: st.n, of: st.of },
28
+ stages: (r.wfStages || []).map((s) => ({ key: s.key, name: s.name, status: s.status })), ended: r.ended ? r.ended.as : null };
29
+ }
30
+
31
+ function rule(info, id) {
32
+ const ini = (info && info.id) || id || '<initiative>';
33
+ const out = [];
34
+ if (info) {
35
+ out.push(`This initiative, ${info.title} (${info.id}), runs the workflow ${info.wf.name} (${info.wf.id}). ` +
36
+ (info.ended ? `It ended (${info.ended === 'wontdo' ? "Won't do" : 'Archived'}).` : `It is in stage ${info.stage.n} of ${info.stage.of}: ${info.stage.name} [${info.stage.key}].`));
37
+ out.push('Its stages: ' + info.stages.map((s, i) => `${i + 1}. ${s.name} [${s.key}]${s.status === 'done' ? ' done' : s.status === 'current' ? ' current' : s.status === 'skipped' ? ' skipped' : ''}`).join('; ') + '.');
38
+ } else out.push(`Run \`pmos workflow of ${ini}\` to see the workflow this initiative runs and its current stage.`);
39
+ out.push(
40
+ `The workflow stage is on the initiative: the stage card and the Board show it. \`pmos workflow of ${ini}\` reads it. When the PM asks to move the initiative, run \`pmos workflow move ${ini} --stage <key> --why "<reason>"\`. When the PM asks to change its workflow, run \`pmos workflow switch ${ini} --to <workflow id>\`. Both write what the page's press writes, under your name.`,
41
+ 'A task has no workflow stage. Its only stage is its state: To do, In progress, Done, Won\'t do or Archived. When the PM asks about a task, set its state (`pmos item move <item> todo|doing|done`). Never set a task\'s stage, and never change tasks to move the initiative.',
42
+ );
43
+ return out;
44
+ }
45
+
46
+ /** The message as PMOS types it into a live session: the rule, then the PM's words. */
47
+ function wrap(text, info, id) { return MARK + ' ' + rule(info, id).join('\n') + '\n\n' + SAYS + String(text == null ? '' : text); }
48
+
49
+ module.exports = { MARK, isAsk, infoOf, rule, wrap };
@@ -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 };
@@ -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,7 @@ 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
68
  // Not a pm-os-absorb verb (run: null): c3-meet-extension added it through the same table.
69
69
  extension: Object.freeze({ module: 'extension-cli.js', run: null, guide: 'console-calendar.md',
70
70
  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:',
@@ -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
@@ -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}$/;
@@ -79,7 +84,15 @@ function validProgram(b) {
79
84
  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
85
  }
81
86
 
82
- const blank = (id) => ({ id, title: id, owner: '', goal: '', why: '', start: '', target: '', jira: '', from: '', milestones: [], members: [], tasks: [], archived: false, at: '' });
87
+ /** An order line's ids: initiative ids, each once, at most 80. An empty list is valid: it goes back to A to Z. */
88
+ function validOrder(list) {
89
+ if (!Array.isArray(list)) return { error: 'order is a list of initiative ids' };
90
+ const out = [];
91
+ 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); }
92
+ return out.length > 80 ? { error: 'an order holds at most 80 initiatives' } : out;
93
+ }
94
+
95
+ const blank = (id) => ({ id, title: id, owner: '', goal: '', why: '', start: '', target: '', jira: '', from: '', milestones: [], members: [], tasks: [], order: [], archived: false, at: '' });
83
96
 
84
97
  /** A program check's done mark from the `check` lines (the last line for a milestone wins) over the charter's own `done`. */
85
98
  const withChecks = (milestones, checks) => (milestones || []).map((m) => {
@@ -115,6 +128,7 @@ function fold(lines) {
115
128
  const t = p.tasks.find((x) => x.key === String(l.key));
116
129
  if (t) t.done = !!l.done;
117
130
  } else if (l.kind === 'check' && ID_RE.test(String(l.milestone || ''))) p.checks[String(l.milestone)] = !!l.done;
131
+ else if (l.kind === 'order' && Array.isArray(l.order)) { const v = validOrder(l.order); if (!v.error) { p.order = v; p.orderSet = true; } }
118
132
  else if (l.kind === 'archive') p.archived = true;
119
133
  }
120
134
  for (const p of Object.values(out)) p.milestones = withChecks(p.milestones, p.checks);
@@ -130,15 +144,17 @@ function merge(perWs) {
130
144
  const m = all[p.id] || (all[p.id] = { ...blank(p.id), home: '', checks: {} });
131
145
  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
146
  Object.assign(m.checks, p.checks);
147
+ // the route writes the order line to the charter's workspace; a line elsewhere counts only while the charter's has none
148
+ if (p.orderSet && (p.charter || !m.orderHome)) { m.order = p.order; if (p.charter) m.orderHome = true; }
133
149
  for (const ini of p.members) if (!m.members.some((x) => x.ws === ws && x.initiative === ini)) m.members.push({ ws, initiative: ini });
134
150
  for (const t of p.tasks) m.tasks.push({ ...t, ws });
135
151
  if (p.archived) m.archived = true;
136
152
  }
137
153
  }
138
154
  // 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; }
155
+ for (const m of Object.values(all)) { m.milestones = withChecks(m.milestones, m.checks); delete m.checks; delete m.orderHome; }
140
156
  // a program with no charter anywhere is a member line whose program was never made: it is not shown
141
157
  return Object.values(all).filter((p) => p.home && !p.archived).sort((a, b) => String(a.title).localeCompare(String(b.title)));
142
158
  }
143
159
 
144
- module.exports = { fold, merge, validProgram, validMilestone, slug, ID_RE, INI_RE };
160
+ module.exports = { fold, merge, validProgram, validMilestone, validOrder, slug, ID_RE, INI_RE };
@@ -29,6 +29,9 @@
29
29
  * POST /api/boards/tasks/reschedule { ws, board, task, days } → { ok, item }
30
30
  * POST /api/boards/tasks/undo-add { ws, board, task } → { ok } takes back a task added in the last 2 minutes, still To do
31
31
  * POST /api/boards/tasks/rename { ws, board, task, title } → { ok, from, item } only the title changes
32
+ * POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative? } → { ok, from, item } the Viewer's edits in place
33
+ * (canvas XetX1Rest); `from` holds the fields as they were, so Undo is the same call with `from`
34
+ * POST /api/boards/tickets/note { ws, board, ref, notes } → { ok, from, notes } the PM's notes on a Jira ticket
32
35
  * POST /api/boards/archive { ws, board, id, archived, reason? } → { ok, row } archive (hidden everywhere, kept whole) or restore;
33
36
  * restoring a merged initiative moves its epics and tasks back
34
37
  * POST /api/boards/merge { ws, board, id, into, epics?, tasks? } → { ok, row, into } moves the picked Jira epic links and PMOS
@@ -309,7 +312,8 @@ const wfRowFields = (x) => {
309
312
  return {
310
313
  wf: { id: x.wf.id, name: x.wf.name, icon: x.wf.icon, ...(x.own && x.own.pmos ? { setBy: 'pmos', why: x.own.why, from: x.own.from || null } : {}) },
311
314
  wfStage: { key: st.key, name: st.name, cat: st.cat, milestone: !!st.milestone, n: st.n, of: st.of },
312
- wfStages: x.stages.map((s) => ({ key: s.key, name: s.name, cat: s.cat, milestone: !!s.milestone, auto: !!s.auto, when: s.when, status: s.status, reading: s.reading })),
315
+ wfStages: x.stages.map((s) => ({ key: s.key, name: s.name, cat: s.cat, milestone: !!s.milestone, auto: !!s.auto, when: s.when, status: s.status, reading: s.reading,
316
+ output: s.output, finish: s.finish })), // output and finish: what finishes the stage (the stage card's exit steps on a library workflow)
313
317
  ended: x.ended ? { as: x.ended.as, reason: x.ended.reason, note: x.ended.note, at: x.ended.at } : null,
314
318
  };
315
319
  };
@@ -425,19 +429,20 @@ function itemsOf(w, fr, board, rows) {
425
429
  const epicKey = /^[A-Za-z][A-Za-z0-9_]*-\d+$/.test(String((d.fm && d.fm.epic) || '')) ? String(d.fm.epic).toUpperCase() : null;
426
430
  if (epicKey) {
427
431
  const rd = reading(epicKey);
428
- out.push({ uid: epicKey, key: epicKey, kind: 'Epic', src: 'jira', title: (rd && rd.summary) || row.title, status: B.itemStatus(rd && rd.status, rd && rd.category), blocked: !!(rd && rd.flagged), owner: null, ini: row.id, epic: null, start: null, end: null, ref: null, board: board.id });
432
+ out.push({ uid: epicKey, key: epicKey, kind: 'Epic', src: 'jira', title: (rd && rd.summary) || row.title, status: B.itemStatus(rd && rd.status, rd && rd.category), blocked: !!(rd && rd.flagged), owner: null, ini: row.id, epic: null, start: null, end: null, ref: null, board: board.id, readAt: (snap && snap.fetchedAt) || null });
429
433
  jiraKeys.add(epicKey);
430
434
  }
431
435
  for (const t of d.tickets || []) {
432
436
  if (!t.jira || jiraKeys.has(t.jira)) continue;
433
437
  const rd = reading(t.jira);
434
438
  out.push({ uid: t.jira, key: t.jira, kind: ['Story', 'Task', 'Bug'].includes(t.type) ? t.type : 'Task', src: 'jira', title: (rd && rd.summary) || t.summary || t.jira,
435
- status: B.itemStatus(rd && rd.status, rd && rd.category), blocked: !!(rd && rd.flagged), owner: null, ini: row.id, epic: epicKey, start: null, end: null, ref: null, board: board.id });
439
+ status: B.itemStatus(rd && rd.status, rd && rd.category), blocked: !!(rd && rd.flagged), owner: null, ini: row.id, epic: epicKey, start: null, end: null, ref: null, board: board.id, readAt: (snap && snap.fetchedAt) || null });
436
440
  jiraKeys.add(t.jira);
437
441
  }
438
442
  }
439
443
  }
440
444
  for (const t of fr.folded.tasks.values()) if (t.board === board.id && ids.has(t.initiative)) out.push(B.taskItem(t));
445
+ for (const x of out) if (x.src === 'jira') x.notes = (fr.folded.ticketNotes && fr.folded.ticketNotes.get(board.id + '\u0000' + x.key)) || ''; // the PM's notes (canvas XetX1Jira)
441
446
  return B.rollupItems(out);
442
447
  }
443
448
 
@@ -447,7 +452,7 @@ function epicItems(row, board, snap, seen, out) {
447
452
  if (!snap || !snap.tickets || !snap.tickets.size || !(row.epics || []).length) return;
448
453
  const epics = row.epics.filter((k) => snap.tickets.has(k));
449
454
  const first = epics[0] || null;
450
- const item = (r, kind, epic) => ({ uid: r.key, key: r.key, kind, src: 'jira', title: r.summary || r.key, status: B.itemStatus(r.status, r.category), blocked: !!r.flagged, owner: null, ini: row.id, epic, start: null, end: null, ref: null, board: board.id });
455
+ const item = (r, kind, epic) => ({ uid: r.key, key: r.key, kind, src: 'jira', title: r.summary || r.key, status: B.itemStatus(r.status, r.category), blocked: !!r.flagged, owner: null, ini: row.id, epic, start: null, end: null, ref: null, board: board.id, readAt: snap.fetchedAt || null });
451
456
  for (const k of epics) { if (!seen.has(k)) { out.push(item(snap.tickets.get(k), 'Epic', null)); seen.add(k); } }
452
457
  for (const r of snap.tickets.values()) {
453
458
  if (seen.has(r.key) || (r.parent && !row.epics.includes(r.parent)) || (!r.parent && r.type === 'Epic')) continue; // a reading of an epic no longer linked
@@ -971,9 +976,10 @@ const WRITES = {
971
976
  if (!p) return;
972
977
  const t = B.taskOf(p.fr.folded, body.task);
973
978
  if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
974
- if (!B.TASK_STATES.includes(body.state)) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
979
+ const state = B.taskState(body.state); // the five task states; an old 'In review' is In progress
980
+ if (!state) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
975
981
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
976
- append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, state: body.state, why: 'status move' });
982
+ append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, state, why: 'status move' });
977
983
  const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
978
984
  ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t2)])[0] });
979
985
  },
@@ -1000,6 +1006,43 @@ const WRITES = {
1000
1006
  const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
1001
1007
  ctx.json(res, { ok: true, from: t.title, item: B.rollupItems([B.taskItem(t2)])[0] });
1002
1008
  },
1009
+ '/api/boards/tasks/edit': (ctx, res, body, g) => {
1010
+ // the task Viewer edits in place (canvas XetX1Rest, XetX1Dates): each change saves at once; Undo sends `from` back
1011
+ const p = postFrame(ctx, res, body);
1012
+ if (!p) return;
1013
+ const t = B.taskOf(p.fr.folded, body.task);
1014
+ if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1015
+ const ev = {}, from = {};
1016
+ if (body.owner != null) { if (body.owner !== '' && !ONE_LINE(body.owner, 80)) return fail(ctx, res, 400, 'owner is one line of at most 80 characters'); ev.owner = String(body.owner).trim(); from.owner = t.owner || ''; }
1017
+ if (body.notes != null) { if (typeof body.notes !== 'string' || body.notes.length > 4000) return fail(ctx, res, 400, 'notes are text of at most 4000 characters'); ev.notes = body.notes.replace(/\s+$/, ''); from.notes = t.notes || ''; }
1018
+ for (const k of ['start', 'due']) if (body[k] != null) { if (body[k] !== '' && !/^\d{4}-\d{2}-\d{2}$/.test(String(body[k]))) return fail(ctx, res, 400, `${k} is a day, YYYY-MM-DD, or '' for none`); ev[k] = String(body[k]); from[k] = t[k] || ''; }
1019
+ if ((ev.start || t.start) && (ev.due != null ? ev.due : t.due) && (ev.start != null ? ev.start : t.start) > (ev.due != null ? ev.due : t.due)) return fail(ctx, res, 400, 'the start is after the due day');
1020
+ if (body.initiative != null) {
1021
+ if (typeof body.initiative !== 'string' || !body.initiative) return fail(ctx, res, 400, 'initiative is an initiative id');
1022
+ const base = needRows(ctx, res, p.w);
1023
+ if (!base) return;
1024
+ const b0 = base.find((r) => r.id === body.initiative);
1025
+ if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no initiative ${body.initiative} on this board`);
1026
+ ev.initiative = body.initiative; from.initiative = t.initiative;
1027
+ }
1028
+ if (!Object.keys(ev).length) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due or initiative');
1029
+ if (!p.file) return fail(ctx, res, 409, NO_STATE);
1030
+ append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, ...ev, why: 'edited ' + Object.keys(ev).join(', ') });
1031
+ const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
1032
+ ctx.json(res, { ok: true, from, item: B.rollupItems([B.taskItem(t2)])[0] });
1033
+ },
1034
+ '/api/boards/tickets/note': (ctx, res, body, g) => {
1035
+ // the PM's own notes on a Jira ticket (canvas XetX1Jira): Jira keeps the title, status, dates and assignee
1036
+ const p = postFrame(ctx, res, body);
1037
+ if (!p) return;
1038
+ if (typeof body.ref !== 'string' || !B.JIRA_KEY_RE.test(body.ref)) return fail(ctx, res, 400, 'ref is a Jira key, like IDPF-2685');
1039
+ if (typeof body.notes !== 'string' || body.notes.length > 4000) return fail(ctx, res, 400, 'notes are text of at most 4000 characters');
1040
+ if (!p.file) return fail(ctx, res, 409, NO_STATE);
1041
+ const ref = body.ref.toUpperCase(), from = p.fr.folded.ticketNotes.get(p.board.id + '\u0000' + ref) || '';
1042
+ const notes = body.notes.replace(/\s+$/, '');
1043
+ append(p.file, g.actor, { kind: 'ticket-note', board: p.board.id, ref, notes });
1044
+ ctx.json(res, { ok: true, from, notes });
1045
+ },
1003
1046
  '/api/boards/tasks/reschedule': (ctx, res, body, g) => {
1004
1047
  const p = postFrame(ctx, res, body);
1005
1048
  if (!p) return;
@@ -1131,15 +1174,34 @@ async function handle(req, res, url, ctx) {
1131
1174
  return true;
1132
1175
  }
1133
1176
 
1134
- /** The PM's move of one initiative, by the same function POST /api/boards/move runs (initiative initiative-driver: Keep on a
1135
- * driver proposal). `g` is the guard's answer ({ ok, actor }); nothing is chosen by the caller. Answers { status, body } with the
1136
- * body the route would send ({ ok, row, warnings } or { ok: false, error }); the route's validation and warnings apply. */
1137
- function move(ctx, body, g) {
1138
- let out = { status: 500, body: { ok: false, error: 'the move was not answered' } };
1177
+ /** One write route run outside HTTP, by the same function the page's press runs, so its validation, warnings and ledger line are the
1178
+ * route's own. `g` is { ok, actor }: who writes comes from the call path, never from the body. Answers { status, body } with the body the
1179
+ * route would send. */
1180
+ function writeAs(ctx, route, body, g) {
1181
+ let out = { status: 500, body: { ok: false, error: 'the write was not answered' } };
1139
1182
  const cap = { ...ctx, json: (_res, obj, code) => { out = { status: code || 200, body: obj }; } };
1140
- WRITES['/api/boards/move'](cap, null, body, g);
1183
+ WRITES[route](cap, null, body, g);
1141
1184
  return out;
1142
1185
  }
1186
+ /** The PM's move of one initiative, by the same function POST /api/boards/move runs (initiative initiative-driver: Keep on a
1187
+ * driver proposal). On a library workflow (D99) `to` is a stage key or name of the initiative's own workflow. */
1188
+ function move(ctx, body, g) { return writeAs(ctx, '/api/boards/move', body, g); }
1189
+ /** A switch of the initiative's workflow, by the same function POST /api/boards/ini-wf runs. body: { ws, board, id, wf, to?, why? }. */
1190
+ function switchWorkflow(ctx, body, g) { return writeAs(ctx, '/api/boards/ini-wf', body, g); }
1191
+
1192
+ /** The workflow one initiative runs and where it stands in it, as the Board's row has it (boardRow: wf, wfStage, wfStages, ended), with the
1193
+ * board it is on. For `pmos workflow of|move|switch` and the initiative chat's opening (bug 2026-10-25: an agent that could not see the
1194
+ * initiative's workflow moved task stages instead). → { ok, board, row } | { ok: false, pending?, status, error } */
1195
+ function initiativeWorkflow(ctx, w, id) {
1196
+ const fr = frameFor(ctx, w);
1197
+ const b = baseRows(w);
1198
+ if (b.pending) return { ok: false, pending: true, status: 202, error: PENDING };
1199
+ if (!b.ok) return { ok: false, status: 500, error: b.error };
1200
+ const b0 = b.rows.find((r) => r.id === id);
1201
+ if (!b0) return { ok: false, status: 404, error: `no initiative ${id} on a board of this workspace` };
1202
+ const board = fr.boards.find((x) => x.id === boardIdOf(b0, fr.boards, fr.folded, w));
1203
+ return { ok: true, board, row: boardRow(board, b0, fr.folded) };
1204
+ }
1143
1205
 
1144
1206
  /** The board of each initiative of a workspace, for other routes (Reports): { boards: [{ id, title }], of(id) → board id }.
1145
1207
  * Rows still being read fall back to the ledger's assignment, else the default board. */
@@ -1205,4 +1267,4 @@ function meetingBoards(ctx) {
1205
1267
  return { list, detail };
1206
1268
  }
1207
1269
 
1208
- module.exports = { prefixes: ['/api/boards'], handle, move, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, workflowRowOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
1270
+ module.exports = { prefixes: ['/api/boards'], handle, move, switchWorkflow, initiativeWorkflow, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, workflowRowOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
@@ -54,6 +54,22 @@ const rootOf = (url, ctx) => {
54
54
  };
55
55
 
56
56
  /** The PM's own calls (initiative briefing-premium-writes). Each appends one record and answers with the rebuilt model. */
57
+ /** An initiative chat's workflow and stage (lib/initiative-chat.js infoOf), from the Board's own row (lib/routes-boards.js initiativeWorkflow):
58
+ * the chat's workspace first, then the others (Home opens initiatives of other products too). null while the rows are being read. */
59
+ function iniInfoOf(ctx, key, wsId) {
60
+ const id = String(key || '').replace(/^init:/, '').replace(/:\d+$/, '');
61
+ if (!/^init:/.test(String(key || '')) || !id) return null;
62
+ const Boards = require('./routes-boards.js');
63
+ const IniChat = require('./initiative-chat.js');
64
+ const list = ctx.workspaceList ? ctx.workspaceList() : [];
65
+ const first = wsId && ctx.getWs ? ctx.getWs(wsId) : null;
66
+ for (const w of [first, ...list.filter((x) => !first || x.id !== first.id)].filter(Boolean)) {
67
+ let a; try { a = Boards.initiativeWorkflow(ctx, w, id); } catch { a = null; }
68
+ if (a && a.ok) return IniChat.infoOf(a);
69
+ }
70
+ return null;
71
+ }
72
+
57
73
  async function post(req, res, url, ctx) {
58
74
  const act = url.pathname.slice('/api/briefing-premium/'.length);
59
75
  const got = await ctx.readJson(req);
@@ -94,7 +110,7 @@ async function post(req, res, url, ctx) {
94
110
  // premium-chat-attach A5: the files a message names must be saved files of its conversation; one closing line names each for Claude
95
111
  const att = Files.pathsOf({ runtimeDir, key: b.key, names: b.files });
96
112
  if (!att.ok) { ctx.json(res, { ok: false, error: att.error }, att.status); return true; }
97
- const a = (ctx.chatSessions ? Ag.chat : Ag.ask)({ runtimeDir, key: b.key, text: Files.withFiles(b.text, att.paths), context: b.context, sessions: ctx.chatSessions, model: /^work:/.test(String(b.key || '')) ? WP.peekModel() : /^board:/.test(String(b.key || '')) ? BoardP.peekModel() : /^ins:/.test(String(b.key || '')) ? InsP.peekModel() : /^(init|doc):/.test(String(b.key || '')) ? InitP.peekModel() : sk || (/^src:/.test(String(b.key || '')) && !(b.key === 'src:this-page' && url.searchParams.get('ws'))) ? Prod.peekModel() : BP.peekModel(root), spawnSession: ctx.spawnSession, wsId });
113
+ const a = (ctx.chatSessions ? Ag.chat : Ag.ask)({ runtimeDir, key: b.key, text: Files.withFiles(b.text, att.paths), context: b.context, sessions: ctx.chatSessions, model: /^work:/.test(String(b.key || '')) ? WP.peekModel() : /^board:/.test(String(b.key || '')) ? BoardP.peekModel() : /^ins:/.test(String(b.key || '')) ? InsP.peekModel() : /^(init|doc):/.test(String(b.key || '')) ? InitP.peekModel() : sk || (/^src:/.test(String(b.key || '')) && !(b.key === 'src:this-page' && url.searchParams.get('ws'))) ? Prod.peekModel() : BP.peekModel(root), spawnSession: ctx.spawnSession, wsId, iniInfo: () => iniInfoOf(ctx, b.key, wsId) });
98
114
  ctx.json(res, a.body, a.status);
99
115
  return true;
100
116
  }
@@ -52,11 +52,13 @@ const isRunning = (ws) => (scope, key) => runs.has(runKey(ws, scope, key));
52
52
  function resolve(ctx, w, scope, key, now) {
53
53
  const p = CD.parseScope(scope);
54
54
  if (!p) return { ok: false, status: 400, error: 'scope must be portfolio, board:<id> or initiative:<id>' };
55
- const entry = CD.entryOf(p.level, key);
55
+ let entry = CD.entryOf(p.level, key);
56
56
  if (!entry) return { ok: false, status: 400, error: `no core document ${String(key).slice(0, 40)} at the ${p.level} level` };
57
57
  const g = CD.gather(ctx, w, { level: p.level, board: p.level === 'board' ? p.id : null, id: p.level === 'initiative' ? p.id : null, now });
58
58
  if (g.pending) return { ok: false, status: 202, error: 'The initiatives are being read. Ask again in a few seconds.' };
59
59
  if (!g.ok) return g;
60
+ // D99: the initiative's own set holds the full entry (a workflow stage's document carries its name, stage and template)
61
+ if (p.level === 'initiative') { const hit = g.facts.list.find((x) => x.entry.key === key); if (hit) entry = hit.entry; }
60
62
  return { ok: true, entry, facts: g.facts, level: p.level, id: p.id };
61
63
  }
62
64