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
@@ -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: typeof body.why === 'string' && body.why.trim() ? body.why.trim().slice(0, 300) : '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,36 @@ 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
+ /** A Board task's state, by the same function POST /api/boards/tasks/state runs (`pmos task state`). body: { ws, board, task, state, why? }. */
1192
+ function taskState(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/state', body, g); }
1193
+
1194
+ /** 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
1195
+ * 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
1196
+ * initiative's workflow moved task stages instead). → { ok, board, row } | { ok: false, pending?, status, error } */
1197
+ function initiativeWorkflow(ctx, w, id) {
1198
+ const fr = frameFor(ctx, w);
1199
+ const b = baseRows(w);
1200
+ if (b.pending) return { ok: false, pending: true, status: 202, error: PENDING };
1201
+ if (!b.ok) return { ok: false, status: 500, error: b.error };
1202
+ const b0 = b.rows.find((r) => r.id === id);
1203
+ if (!b0) return { ok: false, status: 404, error: `no initiative ${id} on a board of this workspace` };
1204
+ const board = fr.boards.find((x) => x.id === boardIdOf(b0, fr.boards, fr.folded, w));
1205
+ return { ok: true, board, row: boardRow(board, b0, fr.folded) };
1206
+ }
1143
1207
 
1144
1208
  /** The board of each initiative of a workspace, for other routes (Reports): { boards: [{ id, title }], of(id) → board id }.
1145
1209
  * Rows still being read fall back to the ledger's assignment, else the default board. */
@@ -1205,4 +1269,4 @@ function meetingBoards(ctx) {
1205
1269
  return { list, detail };
1206
1270
  }
1207
1271
 
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 };
1272
+ module.exports = { prefixes: ['/api/boards'], handle, move, switchWorkflow, taskState, 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
 
@@ -11,6 +11,17 @@
11
11
  * POST /api/programs/check { program, milestone, done } the PM marks a program check (a milestone that waits on no initiative) done or
12
12
  * not; the line goes to the workspace the charter is in, whatever `ws` says
13
13
  * POST /api/programs/archive { ws, program }
14
+ * POST /api/programs/suggestion { program, key, answer } the PM's answer to one of Claude's milestone suggestions (canvas XmsgB): keep writes
15
+ * the charter at once, edit marks one the PM saved from the charter, decline drops
16
+ * it for good unless its source changes (lib/milestone-suggest.js)
17
+ * POST /api/programs/review { program } Check now: Claude reviews the milestones at the next tick (lib/milestone-review.js)
18
+ * POST /api/programs/facts { program, fp } the ◆ dates the page reads for the program's initiatives, as one string; a change
19
+ * asks for a review once (a Jira slip moves a ◆ date too). The first one only records
20
+ * Every program in GET /api/programs carries `review`: { checked, running, open: [suggestion], facts } from <state>/milestone-reviews.jsonl of the
21
+ * charter's workspace.
22
+ * POST /api/programs/order { program, order: [initiative id] } the PM's sequence of the program's initiatives (drag, or Claude's order
23
+ * from the dates applied); like a check line it goes to the charter's workspace.
24
+ * The answer holds `was`, the order before, so the page's Undo writes it back
14
25
  *
15
26
  * FILE MODE ONLY (D64/D66): <state>/programs.jsonl of the workspace named by `ws`, append-only. Every POST is a page press (pm-guard
16
27
  * requirePagePress): an agent session may make, join or archive a program too (D98). Nothing here writes to Jira. */
@@ -18,27 +29,45 @@ const path = require('path');
18
29
  const guard = require('./pm-guard.js');
19
30
  const pmItems = require('./pm-items.js');
20
31
  const P = require('./programs.js');
32
+ const MS = require('./milestone-suggest.js');
21
33
 
22
34
  const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
23
35
  const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
24
36
 
25
- function stateDir(ctx, w) {
37
+ /** The workspace's state folder. A read passes create false: the 1-minute milestone-review tick reads every workspace through all(), and
38
+ * making pmos/state in a repository that has no program wrote into it (day-run E14). */
39
+ function stateDir(ctx, w, create = true) {
26
40
  let d = null;
27
- try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create: true }) : null; } catch { d = null; }
41
+ try { d = ctx.stateDirFor ? ctx.stateDirFor(w, { create }) : null; } catch { d = null; }
28
42
  return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
29
43
  }
30
- const fileOf = (ctx, w) => { const d = stateDir(ctx, w); return d ? path.join(d, 'programs.jsonl') : null; };
44
+ const fileOf = (ctx, w, create = true) => { const d = stateDir(ctx, w, create); return d ? path.join(d, 'programs.jsonl') : null; };
31
45
  const read = (f) => { try { return f ? pmItems.readLines(f).filter(Boolean) : []; } catch { return []; } };
32
46
 
33
- /** Every registered workspace's ledger, merged. */
34
- function all(ctx) {
47
+ /** Every registered workspace's ledger, merged; each program with Claude's milestone review from its charter's workspace. */
48
+ function all(ctx, now = Date.now()) {
35
49
  const list = (ctx.workspaceList ? ctx.workspaceList() : []) || [];
36
- return P.merge(list.map((w) => ({ ws: w.id, lines: read(fileOf(ctx, w)) })));
50
+ const progs = P.merge(list.map((w) => ({ ws: w.id, lines: read(fileOf(ctx, w, false)) })));
51
+ const R = new Map();
52
+ for (const p of progs) {
53
+ if (!R.has(p.home)) { const w = list.find((x) => x.id === p.home), d = w ? stateDir(ctx, w, false) : null; R.set(p.home, MS.fold(read(d ? MS.fileOf(d) : null))); }
54
+ p.review = MS.viewOf(R.get(p.home)[p.id], p, now);
55
+ }
56
+ return progs;
57
+ }
58
+ /** The review ledger of a program's charter workspace: { file, state } (state is that program's fold), or null. */
59
+ function reviewOf(ctx, p) {
60
+ const w = ctx.getWs ? ctx.getWs(p.home || null) : null, d = w ? stateDir(ctx, w, false) : null;
61
+ if (!d) return null;
62
+ const file = MS.fileOf(d);
63
+ return { file, state: MS.fold(read(file))[p.id] || null };
37
64
  }
38
65
 
39
66
  module.exports = {
40
67
  prefixes: ['/api/programs'],
41
68
  all,
69
+ reviewOf,
70
+ fileOf: (ctx, w) => fileOf(ctx, w),
42
71
  handle: async (req, res, url, ctx) => {
43
72
  const p = url.pathname;
44
73
  const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
@@ -54,7 +83,7 @@ module.exports = {
54
83
  const g = guard.requirePagePress(req, b);
55
84
  if (!g.ok) return bad(g.error, g.status);
56
85
  // a check line belongs with the charter, so every workspace's reader applies it to the same milestones
57
- const home = p === '/api/programs/check' && P.ID_RE.test(String(b.program || '')) ? (all(ctx).find((x) => x.id === b.program) || {}).home : null;
86
+ const home = ['/api/programs/check', '/api/programs/order', '/api/programs/suggestion', '/api/programs/review', '/api/programs/facts'].includes(p) && P.ID_RE.test(String(b.program || '')) ? (all(ctx).find((x) => x.id === b.program) || {}).home : null;
58
87
  const w = ctx.getWs ? ctx.getWs(home || b.ws || null) : null;
59
88
  if (!w) return bad('that workspace is not registered', 404);
60
89
  const file = fileOf(ctx, w);
@@ -117,6 +146,54 @@ module.exports = {
117
146
  ctx.json(res, { ok: true, program: known(pid) });
118
147
  return true;
119
148
  }
149
+ if (p === '/api/programs/order') {
150
+ const v = P.validOrder(b.order);
151
+ if (v.error) return bad(v.error);
152
+ const was = known(pid).order || [];
153
+ add({ kind: 'order', program: pid, order: v });
154
+ ctx.json(res, { ok: true, was, program: known(pid) });
155
+ return true;
156
+ }
157
+ if (p === '/api/programs/suggestion' || p === '/api/programs/review' || p === '/api/programs/facts') {
158
+ const prog = known(pid), R = reviewOf(ctx, prog);
159
+ if (!R) return bad('the program\'s workspace has no state folder', 409);
160
+ const note = (line) => pmItems.appendEvent(R.file, { ...line, program: pid }, now);
161
+ if (p === '/api/programs/review') {
162
+ note({ kind: 'review-ask', why: 'asked' });
163
+ ctx.json(res, { ok: true, review: MS.viewOf(reviewOf(ctx, prog).state, prog) });
164
+ return true;
165
+ }
166
+ if (p === '/api/programs/facts') {
167
+ const fp = str(b.fp, 4000);
168
+ if (!fp) return bad('fp holds the ◆ dates as one string');
169
+ const was = (R.state && R.state.facts) || '';
170
+ if (fp === was) { ctx.json(res, { ok: true, asked: false }); return true; }
171
+ note({ kind: 'facts', fp });
172
+ // the first reading only records; a later change asks Claude once (the tick starts the review in the working hours)
173
+ if (was) note({ kind: 'review-ask', why: 'dates' });
174
+ ctx.json(res, { ok: true, asked: !!was });
175
+ return true;
176
+ }
177
+ const key = String(b.key || ''), answer = String(b.answer || '');
178
+ if (!['keep', 'edit', 'decline'].includes(answer)) return bad('answer is keep, edit or decline');
179
+ const it = R.state && R.state.items.get(key);
180
+ if (!it) return bad('no such suggestion', 404);
181
+ if (R.state.answers.has(key)) return bad('this suggestion is answered already', 409);
182
+ if (answer === 'keep') {
183
+ // ✓ writes the change at once, through the same charter line a Save writes (the last line wins)
184
+ const a = MS.applyTo(prog, it);
185
+ if (a.error) return bad(a.error, 409);
186
+ const v = P.validProgram(a.program);
187
+ if (v.error) return bad(v.error);
188
+ const cw = ctx.getWs ? ctx.getWs(prog.home || null) : null, cf = cw ? fileOf(ctx, cw) : null;
189
+ if (!cf) return bad('the program\'s workspace has no state folder', 409);
190
+ pmItems.appendEvent(cf, v, now);
191
+ }
192
+ note({ kind: 'answer', key, answer });
193
+ const after = known(pid);
194
+ ctx.json(res, { ok: true, program: after });
195
+ return true;
196
+ }
120
197
  if (p === '/api/programs/archive') {
121
198
  add({ kind: 'archive', program: pid });
122
199
  ctx.json(res, { ok: true });
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+ /* task-cli.js — `pmos task …`: an initiative's Board tasks from a terminal, so an agent the PM asks can close or move them (Wawan,
3
+ * 2026-10-25: "I made instruction to move, but agent still ask to move myself from Board").
4
+ *
5
+ * pmos task list <initiative> [--all] its open tasks (To do, In progress); --all adds Done, Won't do and Archived
6
+ * pmos task state <task> [<task> …] --to <state> [--why <text>]
7
+ * set each task's state: To do, In progress, Done, Won't do or Archived. One task-update line per task in boards.jsonl, written by
8
+ * the same function as the Board's press (lib/routes-boards.js taskState, POST /api/boards/tasks/state), with the agent as the writer.
9
+ *
10
+ * A Board task is not a breakdown item (`pmos item`) and has no workflow stage: its only stage is its state. The initiative's workflow
11
+ * stage is `pmos workflow of|move`. Who wrote a line is the call path (lib/actor.js), never an argument. Exit codes: 0 done, 1 refused,
12
+ * 2 usage. Nothing is sent. */
13
+ const path = require('path');
14
+ const { execFileSync } = require('child_process');
15
+ const actorLib = require('./actor.js');
16
+ const driver = require('./driver.js');
17
+ const { repoScript } = require('./repo-script.js');
18
+ const B = require(repoScript('boards.js'));
19
+
20
+ const COMMANDS = { task: ['list', 'state'] };
21
+ const USAGE = [
22
+ 'usage: pmos task list|state — an initiative\'s Board tasks',
23
+ ' pmos task list <initiative> [--all] its open tasks; --all adds Done, Won\'t do and Archived',
24
+ ' pmos task state <task> [<task> …] --to <state> [--why <text>]',
25
+ ' Set each task\'s state when the PM asks: To do, In progress, Done, Won\'t do or Archived. The Board shows it at once.',
26
+ ' A Board task has no workflow stage: its only stage is its state. Move the initiative with pmos workflow move.',
27
+ ' every command: [--json] [--root <dir>]. Nothing is sent.',
28
+ ];
29
+ const BOOL = new Set(['json', 'help', 'all']);
30
+ const VALUE = new Set(['to', 'why', 'root']);
31
+ const OPEN = new Set(['To do', 'In progress']);
32
+ /** The PM's words for a state: any case, with or without the apostrophe or the space. */
33
+ function stateOf(s) {
34
+ const k = String(s || '').toLowerCase().replace(/[^a-z]/g, '');
35
+ return { todo: 'To do', inprogress: 'In progress', doing: 'In progress', done: 'Done', wontdo: "Won't do", archived: 'Archived', archive: 'Archived' }[k] || null;
36
+ }
37
+
38
+ function parse(argv) {
39
+ const pos = []; const flags = {};
40
+ for (let i = 0; i < argv.length; i++) {
41
+ const a = argv[i];
42
+ if (a === '-h') { flags.help = true; continue; }
43
+ if (!a.startsWith('--')) { pos.push(a); continue; }
44
+ const eq = a.indexOf('=');
45
+ const key = eq > 0 ? a.slice(2, eq) : a.slice(2);
46
+ if (BOOL.has(key)) { flags[key] = true; continue; }
47
+ let val;
48
+ if (eq > 0) val = a.slice(eq + 1);
49
+ else { const next = argv[i + 1]; if (next === undefined || next.startsWith('--')) val = ''; else { val = next; i++; } }
50
+ flags[key] = val;
51
+ }
52
+ return { pos, flags };
53
+ }
54
+ function repoRoot(cwd) {
55
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
56
+ catch { return cwd; }
57
+ }
58
+ /** The Board's routes outside HTTP: this repository as the one workspace, its state folder, and the PMOS checkout as the self board. */
59
+ function boardsCtx(root, stateDir) {
60
+ const w = { id: driver.wsIdOf(root), name: path.basename(root), root };
61
+ return { w, ctx: { getWs: () => w, workspaceList: () => [w], stateDirFor: () => stateDir, selfRoot: path.resolve(__dirname, '..', '..') } };
62
+ }
63
+ const line = (t) => `${t.id} · ${t.state} · ${t.title}${t.kind === 'Epic' ? ' (epic)' : ''}${t.due ? ' · due ' + t.due : ''}`;
64
+
65
+ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isTTY, env } = {}) {
66
+ const args = argv[0] === 'task' ? argv.slice(1) : argv.slice();
67
+ const verb = args[0];
68
+ const { pos, flags } = parse(args.slice(1));
69
+ const json = !!flags.json;
70
+ if (!verb || verb === 'help' || verb === '--help' || verb === '-h' || flags.help) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
71
+ if (!COMMANDS.task.includes(verb)) { say(`unknown task command "${verb}" — one of ${COMMANDS.task.join(', ')}`); return 2; }
72
+ if ('by' in flags || 'via' in flags) { say(`attribution is set from the call path; --${'by' in flags ? 'by' : 'via'} is not accepted`); return 2; }
73
+ for (const k of Object.keys(flags)) {
74
+ if (!BOOL.has(k) && !VALUE.has(k)) { say(`unknown option --${k}`); return 2; }
75
+ if (VALUE.has(k) && flags[k] === '') { say(`--${k} needs a value`); return 2; }
76
+ }
77
+ const fail = (error, code = 1) => { if (json) say(JSON.stringify({ ok: false, error })); else say(`✗ ${error}`); return code; };
78
+ const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
79
+ const stateDir = driver.stateDirOf(root, { create: verb === 'state' });
80
+ if (!stateDir) return fail('this repository has no PMOS state folder (pmos/state, state or .pmos)');
81
+ const boards = require('./routes-boards.js');
82
+ const { w, ctx } = boardsCtx(root, stateDir);
83
+
84
+ if (verb === 'list') {
85
+ const id = pos[0]; if (!id || pos.length > 1) { say('usage: pmos task list <initiative> [--all]'); return 2; }
86
+ for (const k of ['to', 'why']) if (k in flags) return fail(`--${k} is not an option of list`, 2);
87
+ const all = [...(boards.foldOf(ctx, w).tasks || new Map()).values()].filter((t) => t.initiative === id);
88
+ const shown = flags.all ? all : all.filter((t) => OPEN.has(t.state));
89
+ if (json) { say(JSON.stringify({ ok: true, tasks: shown.map((t) => ({ id: t.id, board: t.board, kind: t.kind, title: t.title, state: t.state, owner: t.owner, due: t.due })) })); return 0; }
90
+ if (!shown.length) { say(all.length ? `No open task on ${id}. --all lists the ${all.length} closed.` : `No Board task on ${id}.`); return 0; }
91
+ for (const t of shown) say(line(t));
92
+ return 0;
93
+ }
94
+ // state
95
+ if (!pos.length || !flags.to) { say('usage: pmos task state <task> [<task> …] --to <state> [--why <text>]'); return 2; }
96
+ if (flags.all) return fail('--all is not an option of state', 2);
97
+ const to = stateOf(flags.to);
98
+ if (!to) return fail(`--to is one of ${B.TASK_STATES.join(', ')}`, 2);
99
+ const actor = actorLib.fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env: env === undefined ? process.env : env });
100
+ const g = { ok: true, actor };
101
+ const folded = boards.foldOf(ctx, w);
102
+ const done = [], refused = [];
103
+ for (const id of pos) {
104
+ const t = B.taskOf(folded, id);
105
+ if (!t) { refused.push({ task: id, error: `no Board task ${id}; pmos task list <initiative> names them` }); continue; }
106
+ if (t.state === to) { done.push({ task: id, title: t.title, state: to, same: true }); continue; }
107
+ const r = boards.taskState(ctx, { ws: w.id, board: t.board, task: id, state: to, ...(flags.why ? { why: flags.why } : {}) }, g);
108
+ if (!r.body || r.body.ok !== true) refused.push({ task: id, error: (r.body && r.body.error) || 'the write was refused' });
109
+ else done.push({ task: id, title: t.title, state: to });
110
+ }
111
+ if (json) say(JSON.stringify({ ok: !refused.length, done, refused }));
112
+ else {
113
+ for (const d of done) say(d.same ? ` ${d.task} was already ${to}: ${d.title}` : `✓ ${d.task} is ${to}: ${d.title}`);
114
+ for (const x of refused) say(`✗ ${x.task}: ${x.error}`);
115
+ if (done.some((d) => !d.same)) say(' The Board shows it. Nothing was sent.');
116
+ }
117
+ return refused.length ? 1 : 0;
118
+ }
119
+
120
+ module.exports = { run, COMMANDS, USAGE, stateOf };
@@ -15,6 +15,7 @@ const RULE = [
15
15
  'The PM is in Settings › Workflows, describing a new workflow: the stages one kind of initiative goes through. Follow the workflow-setup skill (workspace/skills/workflow-setup.skill).',
16
16
  'Draft it with `pmos workflow draft --file <json>`: the page shows the draft beside this chat at once. Draft again after each answer or change; the newest draft replaces the one before.',
17
17
  'A workflow is ONE numbered list of stages. Triage is always the first stage, in To do. Each stage sits in To do, In progress or Done. Won\'t do and Archived are in every workflow: do not draft them as stages.',
18
+ 'When the PM did not name Triage, say in one line that PMOS puts it first in every workflow: a new initiative waits there until PMOS reads its BRD and picks its workflow.',
18
19
  'Write conditions in the PM\'s plain words ("Only when they touch customer data"), never as a rule or code.',
19
20
  'In the chat, say in one line per choice why you drafted it so (quote the PM or the file they added), then ask at most one question when something is unclear.',
20
21
  'You never save, copy or archive a workflow: the PM presses Create workflow. Never write a .jsonl file by hand.',
@@ -10,9 +10,19 @@
10
10
  * pmos workflow judge --board <id> --id <initiative> --stage <key> --runs yes|no|unsure --why <reason> [--cite <where>]
11
11
  * pmos workflow judge --board <id> --id <initiative> --stage <key> --undo
12
12
  * records PMOS's reading of an Only-when stage (one stage-judge line in boards.jsonl): yes runs it, no skips it, unsure asks the PM.
13
+ * pmos workflow of <initiative> the workflow the initiative runs, its current stage, and every stage numbered (done, current, skipped)
14
+ * pmos workflow move <initiative> --stage <key|name> [--why <text>]
15
+ * pmos workflow switch <initiative> --to <workflow id> [--stage <key|name>] [--why <text>]
16
+ * move the initiative along its workflow, or put it on another workflow, as the PM asked (bug 2026-10-25). These run the Board's own
17
+ * write routes (lib/routes-boards.js move, switchWorkflow) outside HTTP, so the checks, the warnings and the boards.jsonl line are the
18
+ * page press's, with the agent as the writer. `of` reads the same row the Board reads (routes-boards initiativeWorkflow).
13
19
  *
14
- * WHO WRITES. These write through lib/workflows-store.js, never over HTTP. An agent may draft and judge; it never saves, copies or archives a
15
- * workflow: Create, Copy and Archive are the PM's presses on the Workflows page. Who wrote a line is the call path (lib/actor.js), never an
20
+ * THE WORKFLOW STAGE IS THE INITIATIVE'S. A task has no workflow stage: its only stage is its state (To do, In progress, Done, Won't do,
21
+ * Archived; Wawan, 2026-10-25). Moving an initiative never touches its tasks.
22
+ *
23
+ * WHO WRITES. These write through lib/workflows-store.js and lib/routes-boards.js, never over HTTP. An agent may draft, judge, and move or
24
+ * switch an initiative when the PM asks; it never saves, copies or archives a workflow: Create, Copy and Archive are the PM's presses on the
25
+ * Workflows page. Who wrote a line is the call path (lib/actor.js), never an
16
26
  * argument. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
17
27
  const fs = require('fs');
18
28
  const path = require('path');
@@ -23,9 +33,9 @@ const WS = require('./workflows-store.js');
23
33
  const { repoScript } = require('./repo-script.js');
24
34
  const WF = require(repoScript('workflows.js'));
25
35
 
26
- const COMMANDS = { workflow: ['list', 'show', 'draft', 'show-draft', 'judge'] };
36
+ const COMMANDS = { workflow: ['list', 'show', 'draft', 'show-draft', 'judge', 'of', 'move', 'switch'] };
27
37
  const USAGE = [
28
- 'usage: pmos workflow list|show|draft|show-draft|judge — the workflows each kind of initiative goes through (D99)',
38
+ 'usage: pmos workflow list|show|draft|show-draft|judge|of|move|switch — the workflows each kind of initiative goes through (D99)',
29
39
  ' pmos workflow list the workflows of this repository',
30
40
  ' pmos workflow show <id> one workflow, its stages numbered',
31
41
  ' pmos workflow draft --file <path|-> [--note <text>]',
@@ -34,10 +44,17 @@ const USAGE = [
34
44
  ' pmos workflow judge --board <id> --id <initiative> --stage <key> --runs yes|no|unsure --why <reason> [--cite <where>]',
35
45
  ' pmos workflow judge --board <id> --id <initiative> --stage <key> --undo',
36
46
  ' Record PMOS\'s reading of an Only-when stage: yes runs it, no skips it, unsure asks the PM. Give the reason and where you read it.',
47
+ ' pmos workflow of <initiative> the workflow it runs and its current stage, every stage numbered',
48
+ ' pmos workflow move <initiative> --stage <key|name> [--why <text>]',
49
+ ' Move the initiative to a stage of its own workflow, when the PM asks. The stage card and the Board show it at once.',
50
+ ' pmos workflow switch <initiative> --to <workflow id> [--stage <key|name>] [--why <text>]',
51
+ ' Put the initiative on another workflow, when the PM asks. Without --stage it lands where the Board\'s switch puts it.',
52
+ ' These are the initiative\'s workflow stages. They are not task stages: a task\'s only stage is its state (To do, In progress,',
53
+ ' Done, Won\'t do, Archived), and moving the initiative never changes a task.',
37
54
  ' every command: [--json] [--root <dir>]. Nothing is sent.',
38
55
  ];
39
56
  const BOOL = new Set(['json', 'help', 'undo']);
40
- const VALUE = new Set(['file', 'note', 'board', 'id', 'stage', 'runs', 'why', 'cite', 'root']);
57
+ const VALUE = new Set(['file', 'note', 'board', 'id', 'stage', 'runs', 'why', 'cite', 'root', 'to']);
41
58
  const RUNS = { yes: true, no: false, unsure: null };
42
59
 
43
60
  function parse(argv) {
@@ -81,7 +98,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
81
98
  }
82
99
  const fail = (error, code = 1) => { if (json) say(JSON.stringify({ ok: false, error })); else say(`✗ ${error}`); return code; };
83
100
  const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
84
- const stateDir = driver.stateDirOf(root, { create: verb === 'draft' || verb === 'judge' });
101
+ const stateDir = driver.stateDirOf(root, { create: ['draft', 'judge', 'move', 'switch'].includes(verb) });
85
102
  if (!stateDir) return fail('this repository has no PMOS state folder (pmos/state, state or .pmos)');
86
103
  const e = env === undefined ? process.env : env;
87
104
  const actor = actorLib.fromCli({ isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env: e });
@@ -123,6 +140,7 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
123
140
  else say(`✓ drafted ${r.draft.name} with ${r.draft.stages.length} stages. The Workflows page shows it beside the chat; the PM presses Create workflow. Nothing was sent.`);
124
141
  return 0;
125
142
  }
143
+ if (verb === 'of' || verb === 'move' || verb === 'switch') return onInitiative(verb, { pos, flags, json, say, fail, root, stateDir, actor });
126
144
  // judge
127
145
  if (!flags.board || !flags.id || !flags.stage) { say('usage: pmos workflow judge --board <id> --id <initiative> --stage <key> --runs yes|no|unsure --why <reason> [--cite <where>]'); return 2; }
128
146
  let r;
@@ -138,4 +156,71 @@ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isT
138
156
  return 0;
139
157
  }
140
158
 
159
+ /* ── an initiative's own workflow: of, move, switch ── */
160
+ const MARK = { done: '✓', current: '▶', skipped: '–', next: ' ' };
161
+ /** The Board's routes outside HTTP: this repository as the one workspace, its state folder, and the PMOS checkout as the self board. */
162
+ function boardsCtx(root, stateDir) {
163
+ const w = { id: driver.wsIdOf(root), name: path.basename(root), root };
164
+ return { w, ctx: { getWs: () => w, workspaceList: () => [w], stateDirFor: () => stateDir, selfRoot: path.resolve(__dirname, '..', '..') } };
165
+ }
166
+ /** The initiative's row, reading the records now when nothing is cached (a CLI process starts with an empty cache). */
167
+ function rowOf(ctx, w, id) {
168
+ const boards = require('./routes-boards.js');
169
+ const rowsLib = require('./initiative-rows.js');
170
+ const was = rowsLib.setBackground(false);
171
+ try {
172
+ let r = boards.initiativeWorkflow(ctx, w, id);
173
+ if (r.pending) { rowsLib.deriveNow(w.root); r = boards.initiativeWorkflow(ctx, w, id); }
174
+ return r;
175
+ } finally { rowsLib.setBackground(was); }
176
+ }
177
+ function ofLines(r) {
178
+ const row = r.row, st = row.wfStage || {};
179
+ const out = [`${row.title} (${row.id}) runs ${row.wf.name} (${row.wf.id}) on the board ${r.board.name}.`];
180
+ out.push(row.ended ? `It ended: ${row.ended.as === 'wontdo' ? "Won't do" : 'Archived'}.` : `Stage ${st.n} of ${st.of}: ${st.name} [${st.key}]`);
181
+ (row.wfStages || []).forEach((s, i) => out.push(` ${MARK[s.status] || ' '} ${String(i + 1).padStart(2)}. ${s.milestone ? '◆ ' : ''}${s.name} [${s.key}]${s.status === 'current' ? ' · current' : s.status === 'skipped' ? ' · skipped' : ''}`));
182
+ out.push(`Move it: pmos workflow move ${row.id} --stage <key>. A task has no workflow stage; moving the initiative changes no task.`);
183
+ return out;
184
+ }
185
+ const ofJson = (r) => ({ initiative: { id: r.row.id, title: r.row.title }, board: { id: r.board.id, name: r.board.name }, wf: r.row.wf, stage: r.row.wfStage, stages: r.row.wfStages, ended: r.row.ended });
186
+
187
+ function onInitiative(verb, { pos, flags, json, say, fail, root, stateDir, actor }) {
188
+ const id = pos[0];
189
+ const usage = { of: 'pmos workflow of <initiative>', move: 'pmos workflow move <initiative> --stage <key|name> [--why <text>]', switch: 'pmos workflow switch <initiative> --to <workflow id> [--stage <key|name>] [--why <text>]' }[verb];
190
+ if (!id) { say('usage: ' + usage); return 2; }
191
+ if (verb === 'move' && !flags.stage) { say('usage: ' + usage); return 2; }
192
+ if (verb === 'switch' && !flags.to) { say('usage: ' + usage); return 2; }
193
+ for (const k of ['board', 'runs', 'cite', 'file', 'note', 'undo']) if (k in flags) return fail(`--${k} is not an option of ${verb}`, 2);
194
+ if (verb === 'of') for (const k of ['stage', 'to', 'why']) if (k in flags) return fail(`--${k} is not an option of of`, 2);
195
+ if (verb === 'move' && 'to' in flags) return fail('--to names a workflow: use pmos workflow switch. Move takes --stage', 2);
196
+ const { w, ctx } = boardsCtx(root, stateDir);
197
+ const before = rowOf(ctx, w, id);
198
+ if (!before.ok) return fail(before.error);
199
+ if (verb === 'of') {
200
+ if (json) { say(JSON.stringify({ ok: true, ...ofJson(before) })); return 0; }
201
+ for (const l of ofLines(before)) say(l);
202
+ return 0;
203
+ }
204
+ const boards = require('./routes-boards.js');
205
+ const g = { ok: true, actor };
206
+ const base = { ws: w.id, board: before.board.id, id, ...(flags.why ? { why: flags.why } : {}) };
207
+ let to = flags.stage;
208
+ let r;
209
+ if (verb === 'move') {
210
+ // Product feature: the Board's move names the stage; a key of Product feature reads as its name
211
+ if (!before.row.wf || before.row.wf.id === WF.PRODUCT_FEATURE_ID) { const t = WF.stageByRef(WF.PRODUCT_FEATURE, to); if (t) to = t.name; }
212
+ r = boards.move(ctx, { ...base, to }, g);
213
+ } else r = boards.switchWorkflow(ctx, { ...base, wf: flags.to, ...(to ? { to } : {}) }, g);
214
+ if (!r.body || r.body.ok !== true) return fail((r.body && r.body.error) || 'the write was refused');
215
+ const after = rowOf(ctx, w, id);
216
+ const warnings = r.body.warnings || [];
217
+ if (json) { say(JSON.stringify({ ok: true, ...(after.ok ? ofJson(after) : {}), warnings })); return 0; }
218
+ const row = after.ok ? after.row : before.row;
219
+ say(verb === 'move' ? `✓ moved ${row.title} to ${row.wfStage.name}, stage ${row.wfStage.n} of ${row.wfStage.of} of ${row.wf.name}.`
220
+ : `✓ ${row.title} now runs ${row.wf.name}, in ${row.wfStage.name} (stage ${row.wfStage.n} of ${row.wfStage.of}).`);
221
+ for (const x of warnings) say(' ' + x);
222
+ say(' The stage card and the Board show it. No task was moved. Nothing was sent.');
223
+ return 0;
224
+ }
225
+
141
226
  module.exports = { run, COMMANDS, USAGE };