create-pmos 0.413.0 → 0.415.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 (63) 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 +12 -1
  9. package/payload/state/discoveries.md +1 -1
  10. package/workspace/bin/pmos.js +1 -1
  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/guide/programs.md +13 -0
  15. package/workspace/guide/workflows.md +10 -0
  16. package/workspace/home-other-product-test.js +18 -0
  17. package/workspace/lib/board-premium.js +9 -0
  18. package/workspace/lib/engine/boards.js +4 -2
  19. package/workspace/lib/goal-chat.js +46 -15
  20. package/workspace/lib/headless.js +10 -1
  21. package/workspace/lib/initiative-chat.js +5 -3
  22. package/workspace/lib/initiative-premium.js +4 -2
  23. package/workspace/lib/item-cli.js +2 -1
  24. package/workspace/lib/milestone-review.js +120 -0
  25. package/workspace/lib/milestone-suggest.js +176 -0
  26. package/workspace/lib/pmos-verbs.js +6 -0
  27. package/workspace/lib/program-cli.js +56 -0
  28. package/workspace/lib/programs.js +4 -1
  29. package/workspace/lib/routes-boards.js +121 -16
  30. package/workspace/lib/routes-briefing-premium.js +14 -1
  31. package/workspace/lib/routes-programs.js +73 -7
  32. package/workspace/lib/task-cli.js +168 -0
  33. package/workspace/lib/task-items.js +86 -0
  34. package/workspace/milestone-suggest-test.js +175 -0
  35. package/workspace/package-lock.json +2 -2
  36. package/workspace/package.json +1 -1
  37. package/workspace/premium-chat-line-test.js +3 -1
  38. package/workspace/public/pm/bd-ini-model.js +81 -0
  39. package/workspace/public/pm/bd-ini-panel.js +144 -59
  40. package/workspace/public/pm/bd-prog-panel.js +54 -14
  41. package/workspace/public/pm/cozy-home.css +5 -0
  42. package/workspace/public/pm/cozy-panel.css +2 -0
  43. package/workspace/public/pm/cozy-viewer.js +2 -0
  44. package/workspace/public/pm/cozy-xv.css +51 -16
  45. package/workspace/public/pm/cozy-xv.js +6 -5
  46. package/workspace/public/pm/home-app.js +13 -11
  47. package/workspace/public/pm/home-ask.js +9 -3
  48. package/workspace/public/pm/home-chat.js +10 -1
  49. package/workspace/public/pm/home-list.js +12 -7
  50. package/workspace/public/pm/home-stage-card.js +3 -2
  51. package/workspace/public/pm/home-today.js +5 -8
  52. package/workspace/public/pm/ms-suggest.css +50 -0
  53. package/workspace/public/pm/ms-suggest.js +98 -0
  54. package/workspace/public/pm/premium-board.js +11 -2
  55. package/workspace/public/pm/premium-initiative-head.js +25 -6
  56. package/workspace/public/pm/program-charter.js +47 -7
  57. package/workspace/public/pm/program-model.js +4 -1
  58. package/workspace/public/pm/wf-page.js +3 -0
  59. package/workspace/server.js +23 -1
  60. package/workspace/skills/milestone-review.skill +53 -0
  61. package/workspace/test-lists/bd-ini-panel.json +5 -0
  62. package/workspace/test-lists/milestone-suggest.json +6 -0
  63. package/workspace/test-lists/one-task-list.json +5 -0
@@ -14,7 +14,7 @@
14
14
  * `jira` is an optional key that is only read, never written to Jira.
15
15
  *
16
16
  * A LINE is one of:
17
- * { kind: 'program', id, title, owner?, goal?, start?, target?, jira?, from?, milestones?: [{ id, name, date?, waits: [initiative id], stages?: { [initiative]: ◆ stage key }, done? }] } the last wins
17
+ * { kind: 'program', id, title, owner?, goal?, start?, target?, jira?, from?, milestones?: [{ id, name, date?, waits: [initiative id], stages?: { [initiative]: ◆ stage key }, done?, risk? }] } the last wins
18
18
  * `from`: the initiative a turned program came from ("Turn into a program"), in the charter's workspace
19
19
  * { kind: 'check', program, milestone, done: true|false } the PM marks a program check done (canvas PgMilestones); the last line wins
20
20
  * { kind: 'member', program, initiative } the initiative (of the workspace whose ledger holds the line) joins the program
@@ -60,6 +60,9 @@ function validMilestone(m, taken) {
60
60
  const st = m.stages && typeof m.stages === 'object' && !Array.isArray(m.stages) ? Object.entries(m.stages).filter(([k, v]) => waits.includes(k) && typeof v === 'string' && /^[a-z0-9][a-z0-9-]{0,39}$/.test(v)) : [];
61
61
  if (st.length) out.stages = Object.fromEntries(st);
62
62
  if (!waits.length) out.done = m.done === true; // a program check: the PM marks it done; a milestone with initiatives is done when they are
63
+ // at risk (a kept suggestion of Claude's, canvas XmsgB): why, in one line; the charter clears it
64
+ const risk = str(m.risk, 240);
65
+ if (risk) out.risk = risk;
63
66
  return out;
64
67
  }
65
68
 
@@ -24,7 +24,7 @@
24
24
  * POST /api/boards/settings { ws, board, buildDeliver?, jira?, offer?, defTpl? } → { ok, board } jira: one key or a list
25
25
  * POST /api/boards/ini-workflow { ws, board, id, template?, stages, moveTo? } → { ok, row, moved }
26
26
  * POST /api/boards/ini-epics { ws, board, id, epics: [Jira key] } → { ok, row } the Jira epics of an initiative ([] unlinks)
27
- * POST /api/boards/tasks/add { ws, board, initiative, title, type?, epic?, start?, due?, owner? } → { ok, item }
27
+ * POST /api/boards/tasks/add { ws, board, initiative, title, type?, epic?, start?, due?, owner?, notes? } → { ok, item } also `pmos task add`
28
28
  * POST /api/boards/tasks/state { ws, board, task, state } → { ok, item }
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
@@ -82,6 +82,7 @@ const { repoScript } = require('./repo-script.js');
82
82
  const B = require(repoScript('boards.js'));
83
83
  const WF = require(repoScript('workflows.js'));
84
84
  const WS = require('./workflows-store.js');
85
+ const TI = require('./task-items.js');
85
86
  const intake = require(repoScript('intake.js'));
86
87
 
87
88
  const LEDGER = 'boards.jsonl';
@@ -367,6 +368,42 @@ function rowsOfBoard(fr, board, base) {
367
368
  }
368
369
  return rows;
369
370
  }
371
+ /** A stage's To finish entries are tasks of the initiative (feedback batch 5: "Also there is workflow tasks, confusing"). Each entry of the
372
+ * current stage becomes one Board task, once: its `from` marker names the stage and the entry, so a move back and forth makes no second
373
+ * one. It runs on a move, a switch and the first read that finds none, so closing one (on the stage card, in the Tasks section or with
374
+ * `pmos task state`) is one write. Product feature's stages have no To finish list. `by` is who put the initiative on the stage.
375
+ * → the number of tasks made. */
376
+ function stageTasks(file, folded, board, row, by) {
377
+ if (!file || !row || !row.wfStage || board.self || row.ended || row.archived) return 0;
378
+ const st = (row.wfStages || []).find((s) => s.key === row.wfStage.key);
379
+ const list = st && Array.isArray(st.finish) ? st.finish.filter((f) => typeof f === 'string' && f.trim()) : [];
380
+ if (!list.length) return 0;
381
+ const have = new Set();
382
+ for (const t of folded.tasks.values()) if (t.initiative === row.id && t.from && t.from.stage === st.key) have.add(t.from.finish);
383
+ let n = 0;
384
+ for (const f of list) {
385
+ if (have.has(f)) continue;
386
+ append(file, { by: by || 'agent:unknown' }, { kind: 'task', board: board.id, task: `task-${crypto.randomBytes(5).toString('hex')}`, type: 'Task', initiative: row.id,
387
+ title: f.trim().charAt(0).toUpperCase() + f.trim().slice(1), epic: null, owner: null, state: 'To do', from: { stage: st.key, finish: f } });
388
+ have.add(f); n++;
389
+ }
390
+ return n;
391
+ }
392
+ /** Who put an initiative on its current stage: the last move or workflow switch of it on this board. */
393
+ function stagedBy(folded, boardId, id) {
394
+ const m = [...folded.moves].reverse().find((x) => x.board === boardId && x.id === id);
395
+ const own = folded.iniWf ? folded.iniWf.get(B.key(boardId, id)) : null;
396
+ return (m && m.by) || (own && own.by) || null;
397
+ }
398
+ /** The read-time pass of stageTasks over rows of one board; a fresh fold when it made any. */
399
+ function seedRows(ctx, w, fr, board, rows) {
400
+ const file = ledgerFile(ctx, w);
401
+ let n = 0;
402
+ for (const r of rows) if (r.wf && r.wf.id !== 'product-feature') n += stageTasks(file, fr.folded, board, r, stagedBy(fr.folded, board.id, r.id));
403
+ if (n) fr.folded = foldOf(ctx, w);
404
+ return n;
405
+ }
406
+
370
407
  /** The archive entry of an initiative, as a page row carries it, or null while it is not archived. */
371
408
  function archivedOf(folded, id) {
372
409
  const a = folded && folded.archives && folded.archives.get(id);
@@ -412,7 +449,7 @@ const openAsks = (folded, boardId) => [...folded.asks.values()].filter((a) => a.
412
449
  const pageAsk = (a) => ({ ...a, by: actorLib.pageName(a.by) });
413
450
  const pageMove = (m) => ({ ...m, by: actorLib.pageName(m.by) });
414
451
 
415
- /** The work items of a board: its PMOS tasks (the ledger) and, with Build and deliver on, the Jira items of its initiatives
452
+ /** The work items of a board: its PMOS tasks (the ledger and the initiatives' breakdown items) and, with Build and deliver on, the Jira items of its initiatives
416
453
  * (the ticket drafts this repository pushed, with the status of the cached readings; read-only, no dates or people). */
417
454
  function itemsOf(w, fr, board, rows) {
418
455
  const ids = new Set(rows.map((x) => x.id));
@@ -442,6 +479,7 @@ function itemsOf(w, fr, board, rows) {
442
479
  }
443
480
  }
444
481
  for (const t of fr.folded.tasks.values()) if (t.board === board.id && ids.has(t.initiative)) out.push(B.taskItem(t));
482
+ out.push(...TI.rowsOf(w.root, ids, board.id)); // one kind of task: an initiative's breakdown items show as its tasks (lib/task-items.js)
445
483
  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)
446
484
  return B.rollupItems(out);
447
485
  }
@@ -562,6 +600,7 @@ const READS = {
562
600
  if (!base) return fail(ctx, res, 404, `no work-lane initiative ${id} in this workspace`);
563
601
  const own = r.fr.boards.find((b) => b.id === boardIdOf(base, r.fr.boards, r.fr.folded, r.w)) || r.board;
564
602
  const row = boardRow(own, base, r.fr.folded);
603
+ seedRows(ctx, r.w, r.fr, own, [row]);
565
604
  const F = r.fr.folded;
566
605
  const ownRows = own.id === r.board.id ? r.rows : rowsOfBoard(r.fr, own, r.base);
567
606
  const mine = ownRows.find((x) => x.id === id);
@@ -599,6 +638,7 @@ const READS = {
599
638
  const r = boardRead(ctx, res, url);
600
639
  if (!r) return;
601
640
  const live = r.rows.filter((x) => !x.archived); // an archived initiative leaves every list and timeline (c3-initiative-lifecycle)
641
+ seedRows(ctx, r.w, r.fr, r.board, live);
602
642
  ctx.json(res, { ok: true, ws: r.w.id, board: r.board.id, build: r.board.build, jira: r.board.jira, jiraProjects: r.board.jiraProjects, items: itemsOf(r.w, r.fr, r.board, live),
603
643
  initiatives: live.map((x) => ({ id: x.id, title: x.title, stage: x.stage, cat: x.cat, status: x.status, owner: x.owner, horizon: x.horizon, start: x.start, end: x.end, progress: x.progress, template: x.template, epics: x.epics })) });
604
644
  },
@@ -690,7 +730,31 @@ function moveOnWorkflow(ctx, res, body, g, p, own) {
690
730
  for (let i = a + 1; i < b; i++) { const sk = before.wfStages[i]; if (sk && sk.status !== 'skipped' && sk.when.mode !== 'optional') warnings.push('Skipped ' + sk.name); }
691
731
  if (!before.anchor) warnings.push('No anchor');
692
732
  append(p.file, g.actor, { kind: 'move', board: p.board.id, id: body.id, from: before.wfStage.key, to: t.key, why: body.why || '', warnings });
693
- ctx.json(res, { ok: true, row: boardRow(p.board, b0, foldOf(ctx, p.w)), warnings });
733
+ const f1 = foldOf(ctx, p.w), row = boardRow(p.board, b0, f1);
734
+ const made = stageTasks(p.file, f1, p.board, row, g.actor.by); // the new stage's To finish entries, as tasks
735
+ ctx.json(res, { ok: true, row, warnings, ...(made ? { tasksMade: made } : {}) });
736
+ }
737
+
738
+ /** A breakdown item named as a task (lib/task-items.js), when its initiative is on this board; answers and returns null when not. */
739
+ function itemOnBoard(ctx, res, p, id) {
740
+ const it = TI.isItemId(id) ? TI.itemOf(p.w.root, id) : null;
741
+ if (!it) { fail(ctx, res, 404, `no PMOS task ${id} on this board`); return null; }
742
+ const base = needRows(ctx, res, p.w);
743
+ if (!base) return null;
744
+ const b0 = base.find((r) => r.id === it.initiative);
745
+ if (!b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) { fail(ctx, res, 404, `no PMOS task ${id} on this board`); return null; }
746
+ return it;
747
+ }
748
+ /** Writes an item's lines (r: TI.stateEvents or TI.editEvents) as the task routes do and answers the item as a task. */
749
+ function itemWrite(ctx, res, p, it, r, g, extra = {}) {
750
+ if (r.error) return fail(ctx, res, 400, r.error);
751
+ if (!r.same) {
752
+ const w = TI.write(p.w.root, r.events, g.actor, g.cli || null);
753
+ if (!w.ok) return fail(ctx, res, w.status || 400, w.error);
754
+ }
755
+ const ids = new Set([it.initiative]);
756
+ const row = TI.rowsOf(p.w.root, ids, p.board.id).find((x) => x.uid === it.id) || { ...TI.rowsOf(p.w.root, ids, p.board.id)[0], uid: it.id, ref: it.id, title: it.title, status: "Won't do" };
757
+ ctx.json(res, { ok: true, item: B.rollupItems([row])[0], ...extra });
694
758
  }
695
759
 
696
760
  const WRITES = {
@@ -869,8 +933,9 @@ const WRITES = {
869
933
  if (body.to != null) { const t = WF.stageByRef(to, body.to); if (!t) return fail(ctx, res, 400, `"${body.to}" is not a stage of ${to.name}`); target = t.key; }
870
934
  const moved = { from: before.wfStage.key, to: target };
871
935
  append(p.file, g.actor, { kind: 'ini-wf', board: p.board.id, id: body.id, wf: to.id, from: from.id, moved, why: body.why ? body.why.trim() : '', ...(body.pmos === true ? { pmos: true } : {}) });
872
- const row = boardRow(p.board, b0, foldOf(ctx, p.w));
873
- ctx.json(res, { ok: true, row, moved });
936
+ const f1 = foldOf(ctx, p.w), row = boardRow(p.board, b0, f1);
937
+ const made = stageTasks(p.file, f1, p.board, row, g.actor.by);
938
+ ctx.json(res, { ok: true, row, moved, ...(made ? { tasksMade: made } : {}) });
874
939
  },
875
940
  '/api/boards/wontdo': (ctx, res, body, g) => {
876
941
  const p = postFrame(ctx, res, body);
@@ -958,16 +1023,18 @@ const WRITES = {
958
1023
  for (const k of ['start', 'due']) if (body[k] != null && body[k] !== '' && !/^\d{4}-\d{2}-\d{2}$/.test(String(body[k]))) return fail(ctx, res, 400, `${k} is a day, YYYY-MM-DD`);
959
1024
  if (body.owner != null && body.owner !== '' && !ONE_LINE(body.owner, 80)) return fail(ctx, res, 400, 'owner is one line of at most 80 characters');
960
1025
  if (body.epic != null && body.epic !== '' && !ONE_LINE(body.epic, 80)) return fail(ctx, res, 400, 'epic is one line of at most 80 characters');
1026
+ if (body.notes != null && (typeof body.notes !== 'string' || body.notes.length > 4000)) return fail(ctx, res, 400, 'notes are text of at most 4000 characters');
1027
+ if (body.start && body.due && body.start > body.due) return fail(ctx, res, 400, 'the start is after the due day');
961
1028
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
962
1029
  const base = needRows(ctx, res, p.w);
963
1030
  if (!base) return;
964
1031
  const b0 = base.find((r) => r.id === body.initiative);
965
1032
  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`);
966
1033
  const id = `task-${crypto.randomBytes(5).toString('hex')}`;
967
- const start = body.start || B.shiftDay(today(), 1);
1034
+ const start = body.start || (body.due && body.due < B.shiftDay(today(), 1) ? body.due : B.shiftDay(today(), 1));
968
1035
  const due = body.due || B.shiftDay(start, 7);
969
1036
  append(p.file, g.actor, { kind: 'task', board: p.board.id, task: id, type: body.type || 'Task', initiative: body.initiative, title: body.title.trim(), epic: body.epic ? String(body.epic).trim() : null,
970
- owner: body.owner ? String(body.owner).trim() : actorLib.pageName(g.actor.by), state: 'To do', start, due });
1037
+ owner: body.owner ? String(body.owner).trim() : actorLib.pageName(g.actor.by), state: 'To do', start, due, ...(body.notes && body.notes.trim() ? { notes: body.notes.replace(/\s+$/, '') } : {}) });
971
1038
  const t = B.taskOf(B.fold(readLedger(ctx, p.w)), id);
972
1039
  ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t)])[0] });
973
1040
  },
@@ -975,11 +1042,18 @@ const WRITES = {
975
1042
  const p = postFrame(ctx, res, body);
976
1043
  if (!p) return;
977
1044
  const t = B.taskOf(p.fr.folded, body.task);
978
- if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
979
1045
  const state = B.taskState(body.state); // the five task states; an old 'In review' is In progress
1046
+ if (!t && TI.isItemId(body.task)) {
1047
+ // a breakdown item is a task too (one list, feedback batch 5): its state is written to the plan-items ledger
1048
+ if (!state) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
1049
+ const it = itemOnBoard(ctx, res, p, body.task);
1050
+ if (!it) return;
1051
+ return itemWrite(ctx, res, p, it, TI.stateEvents(it, state, body.why), g);
1052
+ }
1053
+ if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
980
1054
  if (!state) return fail(ctx, res, 400, `state is one of ${B.TASK_STATES.join(', ')}`);
981
1055
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
982
- append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, state, why: 'status move' });
1056
+ 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' });
983
1057
  const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
984
1058
  ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t2)])[0] });
985
1059
  },
@@ -999,8 +1073,13 @@ const WRITES = {
999
1073
  const p = postFrame(ctx, res, body);
1000
1074
  if (!p) return;
1001
1075
  const t = B.taskOf(p.fr.folded, body.task);
1002
- if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1003
1076
  if (!ONE_LINE(body.title, 200)) return fail(ctx, res, 400, 'title is one line of 1 to 200 characters');
1077
+ if (!t && TI.isItemId(body.task)) {
1078
+ const it = itemOnBoard(ctx, res, p, body.task);
1079
+ if (!it) return;
1080
+ return itemWrite(ctx, res, p, it, TI.editEvents(it, { title: body.title }), g, { from: it.title });
1081
+ }
1082
+ if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1004
1083
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
1005
1084
  append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, title: body.title.trim(), why: 'renamed' });
1006
1085
  const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
@@ -1010,8 +1089,17 @@ const WRITES = {
1010
1089
  // the task Viewer edits in place (canvas XetX1Rest, XetX1Dates): each change saves at once; Undo sends `from` back
1011
1090
  const p = postFrame(ctx, res, body);
1012
1091
  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`);
1092
+ const t0 = B.taskOf(p.fr.folded, body.task);
1093
+ let t = t0;
1094
+ if (!t0 && TI.isItemId(body.task)) {
1095
+ // a breakdown item: the same checks, on the item's own fields (it stays on its initiative)
1096
+ t = itemOnBoard(ctx, res, p, body.task);
1097
+ if (!t) return;
1098
+ if (body.initiative != null && body.initiative !== t.initiative) return fail(ctx, res, 409, 'a breakdown item stays on its initiative');
1099
+ t = { ...t, owner: TI.ownerName(t.owner), notes: t.note || '', item: true };
1100
+ delete body.initiative;
1101
+ }
1102
+ if (!t || (!t.item && t.board !== p.board.id)) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1015
1103
  const ev = {}, from = {};
1016
1104
  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
1105
  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 || ''; }
@@ -1026,6 +1114,7 @@ const WRITES = {
1026
1114
  ev.initiative = body.initiative; from.initiative = t.initiative;
1027
1115
  }
1028
1116
  if (!Object.keys(ev).length) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due or initiative');
1117
+ if (t.item) return itemWrite(ctx, res, p, t, TI.editEvents(t, ev), g, { from });
1029
1118
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
1030
1119
  append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, ...ev, why: 'edited ' + Object.keys(ev).join(', ') });
1031
1120
  const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
@@ -1046,13 +1135,17 @@ const WRITES = {
1046
1135
  '/api/boards/tasks/reschedule': (ctx, res, body, g) => {
1047
1136
  const p = postFrame(ctx, res, body);
1048
1137
  if (!p) return;
1049
- const t = B.taskOf(p.fr.folded, body.task);
1050
- if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1138
+ const t0 = B.taskOf(p.fr.folded, body.task);
1139
+ const it = !t0 && TI.isItemId(body.task) ? itemOnBoard(ctx, res, p, body.task) : null;
1140
+ if (!t0 && TI.isItemId(body.task) && !it) return;
1141
+ const t = t0 || (it ? { start: it.start, due: it.due } : null);
1142
+ if (!t || (t0 && t0.board !== p.board.id)) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1051
1143
  const days = Number(body.days);
1052
1144
  if (!Number.isInteger(days) || days === 0 || Math.abs(days) > 730) return fail(ctx, res, 400, 'days is a whole number of days, not 0, at most 730 either way');
1053
- if (!p.file) return fail(ctx, res, 409, NO_STATE);
1054
1145
  const start = B.shiftDay(t.start || B.shiftDay(t.due || today(), -7), days);
1055
1146
  const due = B.shiftDay(t.due || B.shiftDay(t.start || today(), 7), days);
1147
+ if (it) return itemWrite(ctx, res, p, it, TI.editEvents(it, { start, due }), g);
1148
+ if (!p.file) return fail(ctx, res, 409, NO_STATE);
1056
1149
  append(p.file, g.actor, { kind: 'task-update', board: p.board.id, task: t.id, start, due, why: `rescheduled ${days > 0 ? '+' : ''}${days} days` });
1057
1150
  const t2 = B.taskOf(B.fold(readLedger(ctx, p.w)), t.id);
1058
1151
  ctx.json(res, { ok: true, item: B.rollupItems([B.taskItem(t2)])[0] });
@@ -1188,6 +1281,10 @@ function writeAs(ctx, route, body, g) {
1188
1281
  function move(ctx, body, g) { return writeAs(ctx, '/api/boards/move', body, g); }
1189
1282
  /** 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
1283
  function switchWorkflow(ctx, body, g) { return writeAs(ctx, '/api/boards/ini-wf', body, g); }
1284
+ /** A Board task's state, by the same function POST /api/boards/tasks/state runs (`pmos task state`). body: { ws, board, task, state, why? }. */
1285
+ function taskState(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/state', body, g); }
1286
+ /** A new Board task, by the same function as the page's Add a task (POST /api/boards/tasks/add; `pmos task add`). body: { ws, board, initiative, title, start?, due?, owner? }. */
1287
+ function taskAdd(ctx, body, g) { return writeAs(ctx, '/api/boards/tasks/add', body, g); }
1191
1288
 
1192
1289
  /** 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
1290
  * 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
@@ -1203,6 +1300,14 @@ function initiativeWorkflow(ctx, w, id) {
1203
1300
  return { ok: true, board, row: boardRow(board, b0, fr.folded) };
1204
1301
  }
1205
1302
 
1303
+ /** stageTasks for one initiative outside HTTP (`pmos task list|state`): its current stage's To finish entries made tasks once. → the number made, or 0. */
1304
+ function seedInitiative(ctx, w, id) {
1305
+ const r = initiativeWorkflow(ctx, w, id);
1306
+ if (!r.ok || !r.row.wf || r.row.wf.id === 'product-feature') return 0;
1307
+ const folded = foldOf(ctx, w);
1308
+ return stageTasks(ledgerFile(ctx, w), folded, r.board, r.row, stagedBy(folded, r.board.id, id));
1309
+ }
1310
+
1206
1311
  /** The board of each initiative of a workspace, for other routes (Reports): { boards: [{ id, title }], of(id) → board id }.
1207
1312
  * Rows still being read fall back to the ledger's assignment, else the default board. */
1208
1313
  function boardIndex(ctx, w) {
@@ -1267,4 +1372,4 @@ function meetingBoards(ctx) {
1267
1372
  return { list, detail };
1268
1373
  }
1269
1374
 
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 };
1375
+ module.exports = { prefixes: ['/api/boards'], handle, move, switchWorkflow, taskState, taskAdd, initiativeWorkflow, seedInitiative, stageTasks, itemsOf, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, workflowRowOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
@@ -213,7 +213,20 @@ module.exports = {
213
213
  const tok = req.headers && req.headers['x-pmos-session'];
214
214
  const who = actor.sessionForToken(Array.isArray(tok) ? tok[0] : tok, { sessDir: ctx.sessDir || path.join(ctx.runtimeDir || '', 'sessions') });
215
215
  if (!who) { ctx.json(res, { ok: false, error: 'no valid session token' }, 401); return true; }
216
- ctx.json(res, Goal.askToolReply());
216
+ const key = ctx.runtimeDir && Goal.keyOfSession(ctx.runtimeDir, who.session, Ag.CHATS);
217
+ ctx.json(res, Goal.askToolReply(key ? Goal.goalOf(ctx.runtimeDir, key) : null));
218
+ return true;
219
+ }
220
+ if (url.pathname === '/api/briefing-premium/goal-tool') {
221
+ // Claude Code's PreToolUse hook for every tool in a chat session: a started goal runs without permission prompts. Any other chat asks as usual.
222
+ if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
223
+ const got = await ctx.readJson(req);
224
+ const tok = req.headers && req.headers['x-pmos-session'];
225
+ const who = actor.sessionForToken(Array.isArray(tok) ? tok[0] : tok, { sessDir: ctx.sessDir || path.join(ctx.runtimeDir || '', 'sessions') });
226
+ if (!who || !ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'no valid session token' }, 401); return true; }
227
+ const key = Goal.keyOfSession(ctx.runtimeDir, who.session, Ag.CHATS);
228
+ const body = got.ok && got.body && typeof got.body === 'object' ? got.body : {};
229
+ ctx.json(res, key ? Goal.goalToolReply(Goal.goalOf(ctx.runtimeDir, key), body.tool_name) : {});
217
230
  return true;
218
231
  }
219
232
  if (url.pathname === '/api/briefing-premium/seen') {
@@ -11,6 +11,14 @@
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.
14
22
  * POST /api/programs/order { program, order: [initiative id] } the PM's sequence of the program's initiatives (drag, or Claude's order
15
23
  * from the dates applied); like a check line it goes to the charter's workspace.
16
24
  * The answer holds `was`, the order before, so the page's Undo writes it back
@@ -21,27 +29,45 @@ const path = require('path');
21
29
  const guard = require('./pm-guard.js');
22
30
  const pmItems = require('./pm-items.js');
23
31
  const P = require('./programs.js');
32
+ const MS = require('./milestone-suggest.js');
24
33
 
25
34
  const str = (v, n) => String(v == null ? '' : v).replace(/[\u0000-\u001f]+/g, ' ').trim().slice(0, n);
26
35
  const DAY_RE = /^\d{4}-\d{2}-\d{2}$/;
27
36
 
28
- 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) {
29
40
  let d = null;
30
- 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; }
31
42
  return d || (w && w.root ? path.join(w.root, 'pmos', 'state') : null);
32
43
  }
33
- 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; };
34
45
  const read = (f) => { try { return f ? pmItems.readLines(f).filter(Boolean) : []; } catch { return []; } };
35
46
 
36
- /** Every registered workspace's ledger, merged. */
37
- 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()) {
38
49
  const list = (ctx.workspaceList ? ctx.workspaceList() : []) || [];
39
- 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 };
40
64
  }
41
65
 
42
66
  module.exports = {
43
67
  prefixes: ['/api/programs'],
44
68
  all,
69
+ reviewOf,
70
+ fileOf: (ctx, w) => fileOf(ctx, w),
45
71
  handle: async (req, res, url, ctx) => {
46
72
  const p = url.pathname;
47
73
  const bad = (error, code) => { ctx.json(res, { ok: false, error }, code || 400); return true; };
@@ -57,7 +83,7 @@ module.exports = {
57
83
  const g = guard.requirePagePress(req, b);
58
84
  if (!g.ok) return bad(g.error, g.status);
59
85
  // a check line belongs with the charter, so every workspace's reader applies it to the same milestones
60
- const home = (p === '/api/programs/check' || p === '/api/programs/order') && 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;
61
87
  const w = ctx.getWs ? ctx.getWs(home || b.ws || null) : null;
62
88
  if (!w) return bad('that workspace is not registered', 404);
63
89
  const file = fileOf(ctx, w);
@@ -128,6 +154,46 @@ module.exports = {
128
154
  ctx.json(res, { ok: true, was, program: known(pid) });
129
155
  return true;
130
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
+ }
131
197
  if (p === '/api/programs/archive') {
132
198
  add({ kind: 'archive', program: pid });
133
199
  ctx.json(res, { ok: true });
@@ -0,0 +1,168 @@
1
+ 'use strict';
2
+ /* task-cli.js — `pmos task …`: an initiative's tasks from a terminal, so an agent the PM asks can add, close or move them (Wawan,
3
+ * 2026-10-25: "I made instruction to move, but agent still ask to move myself from Board"; feedback batch 5: one kind of task).
4
+ *
5
+ * pmos task add <initiative> "<title>" [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]
6
+ * a new task, by the same function as the page's Add a task (lib/routes-boards.js taskAdd, POST /api/boards/tasks/add)
7
+ * pmos task list <initiative> [--all] its open tasks (To do, In progress); --all adds Done, Won't do and Archived
8
+ * pmos task state <task> [<task> …] --to <state> [--why <text>]
9
+ * set each task's state: To do, In progress, Done, Won't do or Archived, by the same function as the Board's press
10
+ * (lib/routes-boards.js taskState, POST /api/boards/tasks/state), with the agent as the writer.
11
+ *
12
+ * ONE KIND OF TASK. The list holds the initiative's Board tasks, its breakdown items (the plan-items ledger, lib/task-items.js) and its
13
+ * current stage's To finish entries, which become tasks the first time they are read (routes-boards stageTasks). `state` closes any of
14
+ * them. A task has no workflow stage: its only stage is its state. The initiative's workflow stage is `pmos workflow of|move`. Who wrote a
15
+ * line is the call path (lib/actor.js), never an argument. Exit codes: 0 done, 1 refused, 2 usage. Nothing is sent. */
16
+ const path = require('path');
17
+ const { execFileSync } = require('child_process');
18
+ const actorLib = require('./actor.js');
19
+ const driver = require('./driver.js');
20
+ const { repoScript } = require('./repo-script.js');
21
+ const B = require(repoScript('boards.js'));
22
+ const TI = require('./task-items.js');
23
+ const rowsLib = require('./initiative-rows.js');
24
+
25
+ const COMMANDS = { task: ['add', 'list', 'state'] };
26
+ const USAGE = [
27
+ 'usage: pmos task add|list|state — an initiative\'s tasks, the ones the PM sees in its Tasks section',
28
+ ' pmos task add <initiative> "<title>" [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]',
29
+ ' Add a task. Every new task goes here; pmos item add is the older breakdown record.',
30
+ ' pmos task list <initiative> [--all] its open tasks; --all adds Done, Won\'t do and Archived',
31
+ ' pmos task state <task> [<task> …] --to <state> [--why <text>]',
32
+ ' Set each task\'s state when the PM asks: To do, In progress, Done, Won\'t do or Archived. The page shows it at once.',
33
+ ' Give --why with Done: it is the evidence the PM reads.',
34
+ ' There is one kind of task: Board tasks, breakdown items and the current stage\'s To finish tasks all list and close here.',
35
+ ' A task has no workflow stage: its only stage is its state. Move the initiative with pmos workflow move.',
36
+ ' every command: [--json] [--root <dir>]. Nothing is sent.',
37
+ ];
38
+ const BOOL = new Set(['json', 'help', 'all']);
39
+ const VALUE = new Set(['to', 'why', 'root', 'due', 'start', 'owner', 'notes']);
40
+ const ONLY = { add: ['due', 'start', 'owner', 'notes'], list: ['all'], state: ['to', 'why'] };
41
+ const OPEN = new Set(['To do', 'In progress']);
42
+ /** The PM's words for a state: any case, with or without the apostrophe or the space. */
43
+ function stateOf(s) {
44
+ const k = String(s || '').toLowerCase().replace(/[^a-z]/g, '');
45
+ return { todo: 'To do', inprogress: 'In progress', doing: 'In progress', done: 'Done', wontdo: "Won't do", archived: 'Archived', archive: 'Archived' }[k] || null;
46
+ }
47
+
48
+ function parse(argv) {
49
+ const pos = []; const flags = {};
50
+ for (let i = 0; i < argv.length; i++) {
51
+ const a = argv[i];
52
+ if (a === '-h') { flags.help = true; continue; }
53
+ if (!a.startsWith('--')) { pos.push(a); continue; }
54
+ const eq = a.indexOf('=');
55
+ const key = eq > 0 ? a.slice(2, eq) : a.slice(2);
56
+ if (BOOL.has(key)) { flags[key] = true; continue; }
57
+ let val;
58
+ if (eq > 0) val = a.slice(eq + 1);
59
+ else { const next = argv[i + 1]; if (next === undefined || next.startsWith('--')) val = ''; else { val = next; i++; } }
60
+ flags[key] = val;
61
+ }
62
+ return { pos, flags };
63
+ }
64
+ function repoRoot(cwd) {
65
+ try { return execFileSync('git', ['rev-parse', '--show-toplevel'], { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim() || cwd; }
66
+ catch { return cwd; }
67
+ }
68
+ /** The Board's routes outside HTTP: this repository as the one workspace, its state folder, and the PMOS checkout as the self board. */
69
+ function boardsCtx(root, stateDir) {
70
+ const w = { id: driver.wsIdOf(root), name: path.basename(root), root };
71
+ return { w, ctx: { getWs: () => w, workspaceList: () => [w], stateDirFor: () => stateDir, selfRoot: path.resolve(__dirname, '..', '..') } };
72
+ }
73
+ const line = (t) => `${t.id} · ${t.state} · ${t.title}${t.kind === 'Epic' ? ' (epic)' : ''}${t.due ? ' · due ' + t.due : ''}`;
74
+ /** The workflow row of an initiative, deriving the rows when they are still being read. */
75
+ function rowOf(boards, ctx, w, id) {
76
+ let r = boards.initiativeWorkflow(ctx, w, id);
77
+ if (r.pending) { try { rowsLib.deriveNow(w.root); } catch { /* answered below */ } r = boards.initiativeWorkflow(ctx, w, id); }
78
+ return r;
79
+ }
80
+
81
+ async function run(argv, { say = (s) => console.log(s), cwd = process.cwd(), isTTY, env } = {}) {
82
+ const args = argv[0] === 'task' ? argv.slice(1) : argv.slice();
83
+ const verb = args[0];
84
+ const { pos, flags } = parse(args.slice(1));
85
+ const json = !!flags.json;
86
+ if (!verb || verb === 'help' || verb === '--help' || verb === '-h' || flags.help) { for (const l of USAGE) say(l); return verb ? 0 : 1; }
87
+ if (!COMMANDS.task.includes(verb)) { say(`unknown task command "${verb}" — one of ${COMMANDS.task.join(', ')}`); return 2; }
88
+ if (verb === 'add' && pos.length > 2) { say('usage: pmos task add <initiative> "<title>" [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]'); return 2; }
89
+ 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; }
90
+ for (const k of Object.keys(flags)) {
91
+ if (!BOOL.has(k) && !VALUE.has(k)) { say(`unknown option --${k}`); return 2; }
92
+ if (VALUE.has(k) && flags[k] === '') { say(`--${k} needs a value`); return 2; }
93
+ }
94
+ const fail = (error, code = 1) => { if (json) say(JSON.stringify({ ok: false, error })); else say(`✗ ${error}`); return code; };
95
+ for (const k of Object.keys(flags)) if (VALUE.has(k) && k !== 'root' && !ONLY[verb].includes(k)) return fail(`--${k} is not an option of ${verb}`, 2);
96
+ if (flags.all && verb !== 'list') return fail(`--all is not an option of ${verb}`, 2);
97
+ const root = flags.root ? path.resolve(cwd, flags.root) : repoRoot(cwd);
98
+ const stateDir = driver.stateDirOf(root, { create: verb !== 'list' });
99
+ if (!stateDir) return fail('this repository has no PMOS state folder (pmos/state, state or .pmos)');
100
+ const boards = require('./routes-boards.js');
101
+ const { w, ctx } = boardsCtx(root, stateDir);
102
+
103
+ const cli = { isTTY: isTTY === undefined ? !!(process.stdin.isTTY && process.stdout.isTTY) : isTTY, env: env === undefined ? process.env : env };
104
+ const g = { ok: true, actor: actorLib.fromCli(cli), cli };
105
+ /** Every task of an initiative: its Board tasks (on any board of this workspace) and its breakdown items. */
106
+ const tasksOf = (id) => {
107
+ const r = rowOf(boards, ctx, w, id);
108
+ const board = r.ok ? r.board.id : null;
109
+ const own = [...(boards.foldOf(ctx, w).tasks || new Map()).values()].filter((t) => t.initiative === id);
110
+ const items = TI.rowsOf(root, new Set([id]), board).map((x) => ({ id: x.uid, board, kind: 'Task', title: x.title, state: x.status, owner: x.owner, due: x.end, store: 'item' }));
111
+ return own.concat(items);
112
+ };
113
+
114
+ if (verb === 'add') {
115
+ const [id, title] = pos;
116
+ if (!id || title === undefined) { say('usage: pmos task add <initiative> "<title>" [--due YYYY-MM-DD] [--start YYYY-MM-DD] [--owner <who>] [--notes <text>]'); return 2; }
117
+ const r = rowOf(boards, ctx, w, id);
118
+ if (!r.ok) return fail(r.error);
119
+ const body = { ws: w.id, board: r.board.id, initiative: id, title };
120
+ for (const k of ['due', 'start', 'owner', 'notes']) if (flags[k] !== undefined) body[k] = flags[k];
121
+ const a = boards.taskAdd(ctx, body, g);
122
+ if (!a.body || a.body.ok !== true) return fail((a.body && a.body.error) || 'the write was refused');
123
+ const t = a.body.item;
124
+ if (json) say(JSON.stringify({ ok: true, task: { id: t.uid, board: t.board, title: t.title, state: t.status, owner: t.owner, start: t.start, due: t.end } }));
125
+ else say(`✓ added ${t.uid} · ${t.status} · ${t.title}${t.end ? ' · due ' + t.end : ''}. The initiative's Tasks section shows it. Nothing was sent.`);
126
+ return 0;
127
+ }
128
+
129
+ if (verb === 'list') {
130
+ const id = pos[0]; if (!id || pos.length > 1) { say('usage: pmos task list <initiative> [--all]'); return 2; }
131
+ try { boards.seedInitiative(ctx, w, id); } catch { /* the To finish tasks are made on the next read */ }
132
+ const all = tasksOf(id);
133
+ const shown = flags.all ? all : all.filter((t) => OPEN.has(t.state));
134
+ 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, ...(t.from ? { from: t.from } : {}) })) })); return 0; }
135
+ if (!shown.length) { say(all.length ? `No open task on ${id}. --all lists the ${all.length} closed.` : `No task on ${id}.`); return 0; }
136
+ for (const t of shown) say(line(t));
137
+ return 0;
138
+ }
139
+ // state
140
+ if (!pos.length || !flags.to) { say('usage: pmos task state <task> [<task> …] --to <state> [--why <text>]'); return 2; }
141
+ const to = stateOf(flags.to);
142
+ if (!to) return fail(`--to is one of ${B.TASK_STATES.join(', ')}`, 2);
143
+ const folded = boards.foldOf(ctx, w);
144
+ const done = [], refused = [];
145
+ for (const id of pos) {
146
+ let t = B.taskOf(folded, id);
147
+ if (!t && TI.isItemId(id)) {
148
+ // a breakdown item: the Board's press writes it to the plan-items ledger (lib/task-items.js)
149
+ const it = TI.itemOf(root, id);
150
+ const r = it ? rowOf(boards, ctx, w, it.initiative) : null;
151
+ if (it && r && r.ok) t = { id, board: r.board.id, title: it.title, state: TI.STATE_OF[it.state] };
152
+ }
153
+ if (!t) { refused.push({ task: id, error: `no task ${id}; pmos task list <initiative> names them` }); continue; }
154
+ if (t.state === to) { done.push({ task: id, title: t.title, state: to, same: true }); continue; }
155
+ const r = boards.taskState(ctx, { ws: w.id, board: t.board, task: id, state: to, ...(flags.why ? { why: flags.why } : {}) }, g);
156
+ if (!r.body || r.body.ok !== true) refused.push({ task: id, error: (r.body && r.body.error) || 'the write was refused' });
157
+ else done.push({ task: id, title: t.title, state: to });
158
+ }
159
+ if (json) say(JSON.stringify({ ok: !refused.length, done, refused }));
160
+ else {
161
+ for (const d of done) say(d.same ? ` ${d.task} was already ${to}: ${d.title}` : `✓ ${d.task} is ${to}: ${d.title}`);
162
+ for (const x of refused) say(`✗ ${x.task}: ${x.error}`);
163
+ if (done.some((d) => !d.same)) say(' The page shows it. Nothing was sent.');
164
+ }
165
+ return refused.length ? 1 : 0;
166
+ }
167
+
168
+ module.exports = { run, COMMANDS, USAGE, stateOf };