create-pmos 0.421.0 → 0.423.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 (112) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/scripts/anchor-resolve.js +93 -15
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/board-programs-test.js +87 -3
  8. package/workspace/briefing-premium-adddoc-test.js +1 -1
  9. package/workspace/briefing-premium-board-test.js +13 -11
  10. package/workspace/briefing-premium-initiative-test.js +30 -38
  11. package/workspace/changelog.json +24 -0
  12. package/workspace/fixtures/report-api/draft.json +2 -1
  13. package/workspace/guide/briefing-premium.md +2 -1
  14. package/workspace/guide/home.md +14 -4
  15. package/workspace/guide/programs.md +5 -3
  16. package/workspace/guide/workflows.md +5 -1
  17. package/workspace/home-other-product-test.js +55 -0
  18. package/workspace/ini-workflow-test.js +4 -4
  19. package/workspace/lib/board-premium.js +21 -6
  20. package/workspace/lib/custom-docs.js +65 -3
  21. package/workspace/lib/doc-live-root.js +37 -0
  22. package/workspace/lib/engine/anchor-resolve.js +93 -15
  23. package/workspace/lib/engine/boards.js +30 -2
  24. package/workspace/lib/engine/intake.js +1 -1
  25. package/workspace/lib/hold-spans.js +24 -10
  26. package/workspace/lib/initiative-writer.js +63 -1
  27. package/workspace/lib/kg.js +1 -1
  28. package/workspace/lib/plan-items.js +36 -5
  29. package/workspace/lib/programs.js +11 -3
  30. package/workspace/lib/report-draft.js +3 -0
  31. package/workspace/lib/route-modules.js +2 -0
  32. package/workspace/lib/routes-board-premium.js +28 -0
  33. package/workspace/lib/routes-boards.js +92 -13
  34. package/workspace/lib/routes-doc-sheet.js +29 -1
  35. package/workspace/lib/routes-initiatives.js +12 -0
  36. package/workspace/lib/routes-programs.js +44 -5
  37. package/workspace/lib/routes-task-links.js +329 -0
  38. package/workspace/lib/routes-task-plans.js +333 -0
  39. package/workspace/lib/split-merge-suggest.js +162 -0
  40. package/workspace/lib/split-merge.js +379 -0
  41. package/workspace/lib/task-cli.js +73 -13
  42. package/workspace/lib/task-items.js +15 -3
  43. package/workspace/lib/task-links.js +422 -0
  44. package/workspace/lib/task-plans.js +232 -0
  45. package/workspace/lib/vendor/scripts/anchor-resolve.js +93 -15
  46. package/workspace/lib/vendor/scripts/intake.js +1 -1
  47. package/workspace/package-lock.json +2 -2
  48. package/workspace/package.json +1 -1
  49. package/workspace/premium-board-actions-test.js +2 -2
  50. package/workspace/premium-core-doc-issue-test.js +2 -2
  51. package/workspace/premium-vw-backlog-test.js +3 -3
  52. package/workspace/premium-vw-doc-test.js +26 -3
  53. package/workspace/premium-vw-item-test.js +3 -3
  54. package/workspace/premium-vw-jira-test.js +6 -6
  55. package/workspace/product-lane-test.js +165 -0
  56. package/workspace/program-leave-test.js +203 -0
  57. package/workspace/program-panel-test.js +1 -1
  58. package/workspace/public/pm/bd-acts.js +5 -2
  59. package/workspace/public/pm/bd-ini-panel.js +32 -9
  60. package/workspace/public/pm/bd-prog-panel.js +22 -7
  61. package/workspace/public/pm/bd-prog.js +6 -1
  62. package/workspace/public/pm/bd-span.js +234 -30
  63. package/workspace/public/pm/bd-views.js +3 -2
  64. package/workspace/public/pm/cozy-board.css +90 -0
  65. package/workspace/public/pm/cozy-home.css +3 -0
  66. package/workspace/public/pm/doc-follow.js +36 -0
  67. package/workspace/public/pm/home-app.js +62 -14
  68. package/workspace/public/pm/home-ini-model.js +0 -34
  69. package/workspace/public/pm/home-ini.js +81 -204
  70. package/workspace/public/pm/home-list.js +2 -2
  71. package/workspace/public/pm/home-today.js +3 -1
  72. package/workspace/public/pm/ini-groups.js +228 -0
  73. package/workspace/public/pm/ini-links.js +561 -0
  74. package/workspace/public/pm/ini-tasks.js +131 -30
  75. package/workspace/public/pm/ini-versions.js +348 -0
  76. package/workspace/public/pm/ini-view-model.js +113 -43
  77. package/workspace/public/pm/ini-view.css +341 -18
  78. package/workspace/public/pm/ini-view.js +153 -38
  79. package/workspace/public/pm/premium-board.js +160 -21
  80. package/workspace/public/pm/premium-report-read.js +20 -1
  81. package/workspace/public/pm/premium-shell.js +29 -4
  82. package/workspace/public/pm/premium-vw-doc.js +46 -11
  83. package/workspace/public/pm/prog-move.js +69 -0
  84. package/workspace/public/pm/split-merge.css +77 -0
  85. package/workspace/public/pm/split-merge.js +265 -0
  86. package/workspace/public/pm/stage-line.js +414 -0
  87. package/workspace/public/pm/task-card.css +3 -0
  88. package/workspace/public/pm/task-card.js +15 -6
  89. package/workspace/public/pm/wf-page.css +2 -0
  90. package/workspace/public/pm/wf-page.js +2 -0
  91. package/workspace/public/pm/wf-stage.js +2 -1
  92. package/workspace/server.js +15 -1
  93. package/workspace/split-merge-ui-test.js +175 -0
  94. package/workspace/stage-card-test.js +12 -11
  95. package/workspace/task-card-test.js +3 -2
  96. package/workspace/task-delete-test.js +126 -0
  97. package/workspace/task-links-test.js +227 -0
  98. package/workspace/task-milestones-test.js +176 -0
  99. package/workspace/task-plans-test.js +181 -0
  100. package/workspace/task-views-test.js +3 -3
  101. package/workspace/test-lists/bd-ini-panel.json +8 -2
  102. package/workspace/test-lists/product-lane.json +6 -0
  103. package/workspace/test-lists/program-leave.json +6 -0
  104. package/workspace/test-lists/split-merge.json +15 -0
  105. package/workspace/test-lists/task-delete.json +5 -0
  106. package/workspace/test-lists/task-links.json +6 -0
  107. package/workspace/test-lists/task-milestones.json +6 -0
  108. package/workspace/test-lists/task-plans.json +6 -0
  109. package/workspace/test-lists/viewer-live-file.json +9 -0
  110. package/workspace/timeline-holds-test.js +61 -4
  111. package/workspace/tk-tasks-test.js +173 -57
  112. package/workspace/workflows-setup-test.js +4 -3
@@ -37,7 +37,8 @@ const consoleState = require('./console-state');
37
37
  const actorLib = require('./actor.js');
38
38
 
39
39
  const LEDGER = 'plan-items.jsonl';
40
- const EVENTS = ['planned', 'set', 'moved', 'flagged', 'withdrawn', 'kept'];
40
+ // `restored` (batch 11 item 16) is the Undo of a Delete: it brings back a withdrawn item as it was. A delete is a withdraw with why "deleted".
41
+ const EVENTS = ['planned', 'set', 'moved', 'flagged', 'withdrawn', 'kept', 'restored'];
41
42
  const STATES = ['todo', 'doing', 'review', 'done'];
42
43
  const PM_SLUG = 'wawan';
43
44
  const ID_RE = /^(.+)\.([0-9a-z]{10})$/;
@@ -218,7 +219,8 @@ function lineErr(r) {
218
219
  if (r.blocked === true) return oneLine(r.reason, 200) ? null : 'a block reason is 1 to 200 characters';
219
220
  if (r.blocked === false) return null;
220
221
  return 'blocked is not true or false';
221
- case 'withdrawn': return null;
222
+ case 'withdrawn': return r.why === undefined || oneLine(r.why, 200) ? null : 'a why is 1 to 200 characters on one line';
223
+ case 'restored': return null;
222
224
  case 'kept':
223
225
  if (r.item !== undefined) return 'a kept line names no item';
224
226
  if (!isStr(r.batch) || !/^agent:/.test(r.batch)) return 'batch is not agent:<session>';
@@ -278,13 +280,14 @@ function historyOf(rec) {
278
280
  if (rec.ev === 'set') h.fields = { ...rec.fields };
279
281
  if (rec.ev === 'moved') { h.to = rec.to; if (rec.evidence) h.evidence = { ...rec.evidence }; if (rec.override) h.override = true; }
280
282
  if (rec.ev === 'flagged') { h.blocked = rec.blocked; if (rec.blocked) h.reason = rec.reason; }
283
+ if (rec.ev === 'withdrawn' && rec.why) h.why = rec.why;
281
284
  return h;
282
285
  }
283
286
  const touch = (it, rec) => { it.updatedBy = rec.by; it.updatedVia = rec.via; it.updatedAt = rec.at; it.history.push(historyOf(rec)); };
284
287
 
285
288
  /** A mutable fold state, so the writer can apply the events of one call to a working copy as it checks them. */
286
289
  function createState() {
287
- return { items: new Map(), withdrawn: new Set(), flags: [] };
290
+ return { items: new Map(), withdrawn: new Set(), gone: new Map(), flags: [] }; // gone: each withdrawn item as it was, for a restore
288
291
  }
289
292
  function flag(S, kind, rec, n, message) {
290
293
  S.flags.push({ kind, line: n == null ? null : n, eid: (rec && rec.eid) || null, item: (rec && rec.item) || null,
@@ -315,6 +318,16 @@ function applyLine(S, rec, n) {
315
318
  }
316
319
  return;
317
320
  }
321
+ if (rec.ev === 'restored') {
322
+ const was = S.gone.get(rec.item);
323
+ if (!S.withdrawn.has(rec.item) || !was) { flag(S, 'restore-not-withdrawn', rec, n, `restored names ${rec.item}, which is not withdrawn — it has no effect`); return; }
324
+ S.withdrawn.delete(rec.item); S.gone.delete(rec.item);
325
+ was.state = was.withdrawnFrom || 'todo';
326
+ delete was.withdrawnFrom;
327
+ S.items.set(rec.item, was);
328
+ touch(was, rec);
329
+ return;
330
+ }
318
331
  if (S.withdrawn.has(rec.item)) { flag(S, 'after-terminal', rec, n, `${rec.item} was withdrawn — a later ${rec.ev} line has no effect`); return; }
319
332
  const it = S.items.get(rec.item);
320
333
  if (!it) { flag(S, 'unknown-item', rec, n, `${rec.ev} names ${rec.item}, which was never planned — it has no effect`); return; }
@@ -346,9 +359,11 @@ function applyLine(S, rec, n) {
346
359
  it.blocked = rec.blocked ? { reason: rec.reason.trim(), by: rec.by, at: rec.at } : null;
347
360
  break;
348
361
  case 'withdrawn':
362
+ it.withdrawnFrom = it.state;
349
363
  it.state = 'withdrawn';
350
364
  S.items.delete(rec.item);
351
365
  S.withdrawn.add(rec.item);
366
+ S.gone.set(rec.item, it);
352
367
  touch(it, rec);
353
368
  return;
354
369
  default: return;
@@ -451,6 +466,8 @@ function finish(S, { now = Date.now(), dupes = 0 } = {}) {
451
466
  return {
452
467
  items, order: list.map((x) => x.id), batches, flags: S.flags.slice(), dupes,
453
468
  withdrawnCount: S.withdrawn.size, withdrawnIds: [...S.withdrawn].sort(),
469
+ // each withdrawn item as it was when it went, so a restore (and the writer's working copy) can bring it back
470
+ withdrawnItems: Object.fromEntries([...S.gone].map(([id, it]) => [id, { ...it, after: it.after.slice(), history: it.history.slice() }])),
454
471
  };
455
472
  }
456
473
 
@@ -513,7 +530,8 @@ function buildRecord(ctx, ev, index) {
513
530
  set: ['ev', 'item', 'initiative', 'fields'],
514
531
  moved: ['ev', 'item', 'initiative', 'to', 'evidence'],
515
532
  flagged: ['ev', 'item', 'initiative', 'blocked', 'reason'],
516
- withdrawn: ['ev', 'item', 'initiative'],
533
+ withdrawn: ['ev', 'item', 'initiative', 'why'],
534
+ restored: ['ev', 'item', 'initiative'],
517
535
  kept: ['ev', 'initiative', 'batch', 'items'],
518
536
  }[ev.ev];
519
537
  for (const k of Object.keys(ev)) if (!allowed.includes(k)) return refuse(400, `field ${k} is not part of a ${ev.ev} line`, index);
@@ -663,7 +681,19 @@ function buildRecord(ctx, ev, index) {
663
681
  case 'withdrawn': {
664
682
  const ex = existing(); if (ex.ok === false) return ex;
665
683
  // D98: any actor withdraws any item; the line names who did it.
666
- return { rec: common(ex.init, ex.it.id, ex.it.updatedAt) };
684
+ if (ev.why !== undefined && !oneLine(ev.why, 200)) return refuse(400, 'a why is 1 to 200 characters on one line', index);
685
+ const rec = common(ex.init, ex.it.id, ex.it.updatedAt);
686
+ if (ev.why !== undefined) rec.why = ev.why.trim();
687
+ return { rec };
688
+ }
689
+ case 'restored': {
690
+ // the Undo of a Delete (batch 11 item 16): only a withdrawn item comes back, as it was
691
+ if (!isStr(ev.item) || !ID_RE.test(ev.item)) return refuse(400, 'item must be an item id, <initiative>.<10 characters>', index);
692
+ const init = initiativeOf(ev.item);
693
+ if (ev.initiative !== undefined && ev.initiative !== init) return refuse(400, `item ${ev.item} does not belong to initiative ${ev.initiative}`, index);
694
+ const was = S.gone.get(ev.item);
695
+ if (!S.withdrawn.has(ev.item) || !was) return refuse(409, `${ev.item} is not withdrawn`, index);
696
+ return { rec: common(init, ev.item, was.updatedAt) };
667
697
  }
668
698
  case 'kept': {
669
699
  const init = ev.initiative;
@@ -715,6 +745,7 @@ function append(root, events, actor, { now, allowKept }) {
715
745
  S.items.set(id, { ...it, after: it.after.slice(), history: it.history.slice() });
716
746
  }
717
747
  for (const id of base.withdrawnIds) S.withdrawn.add(id);
748
+ for (const [id, it] of Object.entries(base.withdrawnItems || {})) S.gone.set(id, { ...it, after: it.after.slice(), history: it.history.slice() });
718
749
  /* Strictly increasing `at`. Lines written by one call (a planned then a set in the same millisecond) must
719
750
  * sort in the order they were written, and the fold sorts by (at, eid). A line dated more than a second
720
751
  * ahead of this clock is ignored for the GLOBAL floor, so one forged future date cannot drag every later write
@@ -107,7 +107,7 @@ const withChecks = (milestones, checks) => (milestones || []).map((m) => {
107
107
  /** The programs one workspace's ledger says, members carrying no workspace yet (merge adds it). `checks` holds the check lines, by milestone id. */
108
108
  function fold(lines) {
109
109
  const out = {};
110
- const get = (id) => out[id] || (out[id] = { ...blank(id), charter: false, checks: {} });
110
+ const get = (id) => out[id] || (out[id] = { ...blank(id), charter: false, checks: {}, touched: [] });
111
111
  for (const l of lines || []) {
112
112
  if (!l || typeof l !== 'object') continue;
113
113
  if (l.kind === 'program' && ID_RE.test(String(l.id || ''))) {
@@ -122,6 +122,7 @@ function fold(lines) {
122
122
  if (l.kind === 'member' || l.kind === 'leave') {
123
123
  if (!INI_RE.test(String(l.initiative || ''))) continue;
124
124
  p.members = p.members.filter((x) => x !== l.initiative);
125
+ if (!p.touched.includes(String(l.initiative))) p.touched.push(String(l.initiative));
125
126
  if (l.kind === 'member') p.members.push(String(l.initiative));
126
127
  } else if (l.kind === 'task' && l.key && l.title) {
127
128
  const t = { key: String(l.key), title: String(l.title), owner: l.owner || '', due: l.due || '', done: false };
@@ -144,18 +145,25 @@ function merge(perWs) {
144
145
  for (const { ws, lines } of perWs || []) {
145
146
  const one = fold(lines);
146
147
  for (const p of Object.values(one)) {
147
- const m = all[p.id] || (all[p.id] = { ...blank(p.id), home: '', checks: {} });
148
+ const m = all[p.id] || (all[p.id] = { ...blank(p.id), home: '', checks: {}, touched: [] });
148
149
  if (p.charter) Object.assign(m, { title: p.title, owner: p.owner, goal: p.goal, why: p.why, start: p.start, target: p.target, jira: p.jira, from: p.from, milestones: p.milestones, home: ws, at: p.at });
149
150
  Object.assign(m.checks, p.checks);
150
151
  // the route writes the order line to the charter's workspace; a line elsewhere counts only while the charter's has none
151
152
  if (p.orderSet && (p.charter || !m.orderHome)) { m.order = p.order; if (p.charter) m.orderHome = true; }
152
153
  for (const ini of p.members) if (!m.members.some((x) => x.ws === ws && x.initiative === ini)) m.members.push({ ws, initiative: ini });
153
154
  for (const t of p.tasks) m.tasks.push({ ...t, ws });
155
+ for (const ini of p.touched) m.touched.push({ ws, initiative: ini });
154
156
  if (p.archived) m.archived = true;
155
157
  }
156
158
  }
157
159
  // the check lines of every workspace apply to the charter's milestones (the route writes them to the charter's workspace)
158
- for (const m of Object.values(all)) { m.milestones = withChecks(m.milestones, m.checks); delete m.checks; delete m.orderHome; }
160
+ // a program turned from Home before batch 11 item 18 wrote its initiative's member line to the charter's workspace, not the initiative's own:
161
+ // a member or leave line for that initiative in another workspace says where it really is, so the charter's stale line is dropped (else it
162
+ // shows twice once the PM adds it again, or stays under its product)
163
+ for (const m of Object.values(all)) {
164
+ if (m.from && m.touched.some((x) => x.initiative === m.from && x.ws !== m.home)) m.members = m.members.filter((x) => !(x.ws === m.home && x.initiative === m.from));
165
+ m.milestones = withChecks(m.milestones, m.checks); delete m.checks; delete m.orderHome; delete m.touched;
166
+ }
159
167
  // a program with no charter anywhere is a member line whose program was never made: it is not shown
160
168
  return Object.values(all).filter((p) => p.home && !p.archived).sort((a, b) => String(a.title).localeCompare(String(b.title)));
161
169
  }
@@ -372,6 +372,8 @@ function draftOf(root, { cadence, slot, now, health } = {}) {
372
372
  milestones: [...new Set(spans.filter((s) => s.milestone).map((s) => s.due))].sort(),
373
373
  holds: (() => { const all = itemSpans.initiativeSpan(spans);
374
374
  return (holdsBy.get(b.id) || []).filter((h) => !h.to || !all || (h.to > all.start && h.from < all.due)).map((h) => ({ from: h.from, to: h.to, back: h.back, reason: h.reason })); })(),
375
+ // a stretch of 2 weeks or more with no dated item: "No activity" on the strip, as on the Board (batch 11 item 13); not pressable
376
+ gaps: holdSpans.planGaps(spans, 14).map((g) => ({ from: g.from, to: g.to })),
375
377
  });
376
378
  }
377
379
 
@@ -526,6 +528,7 @@ function render(draft, { notes } = {}) {
526
528
  for (const r of draft.timeline.rows) {
527
529
  r.spans.forEach((s, i) => push(`| ${i ? '' : esc(r.title)} | ${esc(s.stage || '-')} | ${s.start || '-'} | ${s.due || '-'} | ${i ? '' : (r.milestones.map(short).join(', ') || '-')} |`));
528
530
  for (const h of r.holds || []) push(`| | On hold${h.reason ? ': ' + esc(h.reason) : ''} | ${h.from} | ${h.to || (h.back ? h.back + ' (return date)' : 'no return date')} | |`);
531
+ for (const g of r.gaps || []) push(`| | No activity | ${g.from} | ${g.to} | |`);
529
532
  }
530
533
  } else push('No initiative in this report has dated items.');
531
534
  push('');
@@ -73,6 +73,8 @@ const MODULES = Object.freeze([
73
73
  'routes-c3-reports', // console3 Reports dashboards: library, per-scope data, page-press layouts (layouts are the only write)
74
74
  'routes-onboarding', // onboarding-scan-and-map slice 2: first run (scan read-only, structure, import into the overlay, undo, first Briefing)
75
75
  'routes-boards', // c3-initiative-boards: Portfolio, Board, Backlog, Triage asks, workflows and moves (boards.jsonl)
76
+ 'routes-task-plans', // batch 11 item 8: drafts of an initiative's tasks, saved plans, Make live (task-plans.jsonl; page-press POST)
77
+ 'routes-task-links', // batch 11 item 15: links between tasks, Claude's proposals, the quiet moves (task-links.jsonl; page-press POST)
76
78
  'routes-workflows', // workflows-per-initiative (D99): the workflow library, save, copy, archive and the chat's draft (workflows.jsonl; page-press POST)
77
79
  'routes-settings', // console3 Settings: the settings store for settings with no home of their own (GET; page-press POST)
78
80
  'routes-hooks', // planning-flows run 7: CLI hook endpoints (session token, per-run JSONL)
@@ -16,6 +16,9 @@ const Custom = require('./custom-docs.js');
16
16
  const path = require('path');
17
17
  const fs = require('fs');
18
18
  const Metrics = require('./board-metrics-premium.js');
19
+ const TaskPlans = require('./task-plans.js');
20
+ const TaskLinks = require('./task-links.js');
21
+ const Suggest = require('./split-merge-suggest.js');
19
22
  const { ENGINE_PATHS } = require('./console-state.js');
20
23
 
21
24
  /** GET `pathAndQuery` from a route module's own handler, as the Work page's route does, and return { status, body }. */
@@ -90,6 +93,31 @@ module.exports = {
90
93
  rows: listOf(rk, nw), columns: c ? c.columns : [], sprints: s || { source: 'none', sprints: [] }, docs: d, custom,
91
94
  items: its && its.body && its.body.ok !== false && Array.isArray(its.body.items) ? its.body.items : [], held: hd ? hd.rows : [], cancelled: cn ? cn.rows : [], archived: ar ? ar.rows : [], asks: ak ? ak.asks || [] : null,
92
95
  });
96
+ // planned versus actual (batch 11 item 8): each row's drafts and saved plans, from task-plans.jsonl
97
+ try {
98
+ const w = ctx.getWs ? ctx.getWs(pick.ws) : null, dir = w && ctx.stateDirFor ? ctx.stateDirFor(w) : null;
99
+ if (dir) { const F = TaskPlans.read(dir); for (const L of [model.rows, ...(model.stages || []).map((x) => x.rows), model.cancelled, model.archived]) TaskPlans.decorate(L, F); }
100
+ } catch { missing.push('saved plans'); }
101
+ // links between tasks (batch 11 item 15): each row's links, Claude's proposals, the quiet moves and what waits on the PM (task-links.jsonl)
102
+ try {
103
+ const w = ctx.getWs ? ctx.getWs(pick.ws) : null, dir = w && ctx.stateDirFor ? ctx.stateDirFor(w) : null;
104
+ if (dir) {
105
+ const F = TaskLinks.read(dir), items = its && its.body && Array.isArray(its.body.items) ? its.body.items : [], TLR = require('./routes-task-links.js');
106
+ const src = (ini) => TLR.sourcesOf(w.root, ini, items);
107
+ for (const L of [model.rows, ...(model.stages || []).map((x) => x.rows)]) TaskLinks.decorate(L, F, items, { today: model.today || new Date().toISOString().slice(0, 10), src });
108
+ }
109
+ } catch { missing.push('task links'); }
110
+ // Claude's suggestion to split an initiative or merge two (batch 11 item 14): made from the tasks and tickets on every read, never a timer;
111
+ // the PM's ✕ Not now hides one until its tasks change. A failure here only leaves the suggestions out.
112
+ try {
113
+ const w = ctx.getWs ? ctx.getWs(pick.ws) : null;
114
+ let dismissed = null;
115
+ try { const f = w ? boards.foldOf(ctx, w) : null; dismissed = f ? f.suggestNo : null; } catch { dismissed = null; }
116
+ const items = its && its.body && Array.isArray(its.body.items) ? its.body.items : [];
117
+ const open = ((model.initiatives && model.initiatives.list && model.initiatives.list.rows) || []).filter((r) => r && r.id && r.status !== 'done' && r.status !== 'on hold');
118
+ const got = Suggest.suggest(open, items, { dismissed });
119
+ for (const L of [model.rows, model.initiatives.list.rows, ...(model.initiatives.stages || []).map((x) => x.rows)]) for (const r of L || []) if (r && r.id && got.has(r.id)) r.suggest = got.get(r.id);
120
+ } catch { /* no suggestions this read */ }
93
121
  // a press re-derives the rows in the background; while the answer is stale the page asks again (initiative premium-board-actions)
94
122
  let stale = false;
95
123
  try { const w = ctx.getWs ? ctx.getWs(pick.ws) : null; const pk = w ? Rows.peek(w.root) : null; stale = !!(pk && (pk.pending || pk.stale)); } catch { stale = false; }
@@ -29,7 +29,8 @@
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?, section? } → { ok, from, item } the Viewer's edits in place
32
+ * POST /api/boards/tasks/edit { ws, board, task, owner?, notes?, start?, due?, initiative?, section?, milestone? } → { ok, from, item } the Viewer's edits in place
33
+ * (milestone: true | false, the ◇ flag of batch 11 item 3; a Jira key takes the flag only)
33
34
  * (section: the task's place in the breakdown, a stage key of its initiative's workflow or '' — a task-section line)
34
35
  * (canvas XetX1Rest); `from` holds the fields as they were, so Undo is the same call with `from`
35
36
  * POST /api/boards/tickets/note { ws, board, ref, notes } → { ok, from, notes } the PM's notes on a Jira ticket
@@ -281,7 +282,7 @@ function baseRows(w) {
281
282
  stopped: rec.stopped ? { reason: rec.stopped.reason || '', at: rec.stopped.at || null, back: rec.stopped.back || null } : null,
282
283
  hasSpec, record: relRec || null, domainFolder: dm ? dm[1] : null,
283
284
  recordEpic: jiraTickets.anchorOf(fm),
284
- holds: holds.get(id) || [], workSpans: work.map((x) => ({ start: x.start, due: x.due })),
285
+ holds: holds.get(id) || [], workSpans: work.map((x) => ({ start: x.start, due: x.due, stage: x.stage || null })),
285
286
  });
286
287
  }
287
288
  rowCache.set(w.root, { key: cacheKey, rows });
@@ -349,16 +350,19 @@ function taskSpanOf(folded, id) {
349
350
  }
350
351
  return start ? { start, end } : null;
351
352
  }
352
- /** Each dated task of an initiative as { start, due } (Won't do and Archived left out). */
353
+ /** Each dated task of an initiative as { start, due, stage } (Won't do and Archived left out). stage: the PM's placement (a task-section line),
354
+ * else the stage whose To finish entry made it, else null. */
353
355
  function taskSpansOf(folded, id) {
354
- const out = [];
356
+ const out = [], SEC = (folded && folded.sections) || new Map();
355
357
  for (const t of (folded && folded.tasks ? folded.tasks.values() : [])) {
356
358
  if (!t || t.initiative !== id || t.state === "Won't do" || t.state === 'Archived') continue;
357
359
  const a = t.start || t.due, z = t.due || t.start;
358
- if (a) out.push({ start: String(a).slice(0, 10), due: String(z).slice(0, 10) });
360
+ const stage = SEC.has(t.id) ? SEC.get(t.id) || null : (t.from && t.from.stage) || null;
361
+ if (a) out.push({ start: String(a).slice(0, 10), due: String(z).slice(0, 10), stage });
359
362
  }
360
363
  return out;
361
364
  }
365
+ const gapFields = (spans) => ({ gaps: holdSpans.planGaps(spans, 14), stageSpans: holdSpans.stageSpans(spans) });
362
366
  const minDay = (a, b) => (!a ? b || null : !b ? a : a < b ? a : b);
363
367
  const maxDay = (a, b) => (!a ? b || null : !b ? a : a > b ? a : b);
364
368
 
@@ -372,8 +376,9 @@ function boardRow(board, base, folded, lib) {
372
376
  horizon: base.horizon, status: base.status, start: ts ? minDay(base.start, ts.start) : base.start, end: ts ? maxDay(base.end, ts.end) : base.end, progress: base.progress, warnings: [],
373
377
  rank: base.rank, health: B.isActive(base) ? base.health : null, updated: base.updated, reading: base.reading, stageSource: s.source, lifecycle: base.lifecycle,
374
378
  stopped: base.stopped || null, archived: archivedOf(folded, base.id),
375
- // feedback batch 9 item 8: every hold of the initiative, and the stretches of 4 weeks or more that no dated work-item or task covers
376
- holds: base.holds || [], gaps: holdSpans.planGaps((base.workSpans || []).concat(taskSpansOf(folded, base.id)), 28),
379
+ // feedback batch 9 item 8: every hold of the initiative, and the stretches of 2 weeks or more that no dated work-item or task covers (batch 11
380
+ // item 13); stageSpans: where the dated work of each stage runs, so a skipped stage between two of them is marked » (XgapAGrill)
381
+ holds: base.holds || [], ...gapFields((base.workSpans || []).concat(taskSpansOf(folded, base.id))),
377
382
  template: B.templateOf(board, base.id, folded), workflow: wf.map((x) => ({ name: x.name, cat: x.cat })),
378
383
  ...epicsOf(base, folded),
379
384
  };
@@ -530,9 +535,18 @@ function itemsOf(w, fr, board, rows) {
530
535
  for (const t of fr.folded.tasks.values()) if (t.board === board.id && ids.has(t.initiative)) out.push(B.taskItem(t));
531
536
  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)
532
537
  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)
538
+ // the PM's own days for a Jira ticket (batch 11 item 23): kept in PMOS, they win over Jira's, and the row says so
539
+ const TD = fr.folded.ticketDates || new Map();
540
+ if (TD.size) for (const x of out) if (x.src === 'jira' && x.key) { const v = TD.get(board.id + '\u0000' + String(x.key).toUpperCase()); if (v) { if (v.start) x.start = v.start; if (v.due) x.end = v.due; x.datesHere = true; } }
541
+ // a split or a merge took a Jira ticket to another initiative (batch 11 item 14): PMOS holds where it belongs; Jira is not written to
542
+ const TM = fr.folded.ticketMoves || new Map();
543
+ if (TM.size) for (const x of out) if (x.src === 'jira' && x.key && TM.has(x.key)) x.ini = TM.get(x.key);
533
544
  // a task's place in the breakdown (one view): the PM's own choice, else the stage whose To finish entry made it
534
545
  const SEC = fr.folded.sections || new Map();
535
546
  for (const x of out) if (x.src === 'pmos' && x.kind !== 'Epic') { if (SEC.has(x.uid)) x.section = SEC.get(x.uid); else if (x.from && x.from.stage) x.section = x.from.stage; }
547
+ // a task flagged as a milestone (feedback batch 11 item 3): the PM's flag on the board ledger, else a breakdown item's own plan-items flag
548
+ const MS = fr.folded.milestones || new Map();
549
+ for (const x of out) if (x.kind !== 'Epic') { const on = MS.has(x.uid) ? MS.get(x.uid) : !!x.milestone; if (on) x.milestone = true; else delete x.milestone; }
536
550
  return B.rollupItems(out);
537
551
  }
538
552
 
@@ -663,7 +677,9 @@ const READS = {
663
677
  for (const m of F.moves) if (m.id === id) history.push({ kind: m.via === 'move' ? 'move' : m.via, ...pageMove(m) });
664
678
  for (const e of F.events) {
665
679
  if (e.kind === 'assign' && e.id === id) history.push({ kind: 'assign', at: e.at || null, by: actorLib.pageName(e.by || null), board: e.board || null, to: e.to });
666
- if (e.kind === 'ini-archive' && (e.id === id || e.into === id)) history.push({ kind: e.archived === false ? 'restore' : (e.into ? 'merge' : 'archive'), at: e.at || null, by: actorLib.pageName(e.by || null), board: e.board || null, id: e.id, into: e.into || null, reason: e.reason || '' });
680
+ if (e.kind === 'ini-archive' && !e.op && (e.id === id || e.into === id)) history.push({ kind: e.archived === false ? 'restore' : (e.into ? 'merge' : 'archive'), at: e.at || null, by: actorLib.pageName(e.by || null), board: e.board || null, id: e.id, into: e.into || null, reason: e.reason || '' });
681
+ // split or merge (batch 11 item 14): one line on each side; an undone one says so
682
+ if ((e.kind === 'ini-split' || e.kind === 'ini-merge') && (e.id === id || e.to === id)) history.push({ kind: e.kind === 'ini-split' ? (e.id === id ? 'split-off' : 'split-from') : (e.id === id ? 'merged-into' : 'merged-in'), at: e.at || null, by: actorLib.pageName(e.by || null), board: e.board || null, id: e.id, to: e.to, title: e.id === id ? e.toTitle || e.to : e.fromTitle || e.id, undone: F.smUndone ? F.smUndone.has(e.op) : false });
667
683
  if (e.kind === 'ini-workflow' && e.id === id && Array.isArray(e.stages)) history.push({ kind: 'workflow', at: e.at || null, by: actorLib.pageName(e.by || null), board: e.board || null, template: e.template || null, stages: e.stages.map((x) => x && x.name).filter(Boolean) });
668
684
  }
669
685
  history.sort((a, b) => String(b.at || '').localeCompare(String(a.at || '')));
@@ -1151,13 +1167,19 @@ const WRITES = {
1151
1167
  },
1152
1168
  '/api/boards/tasks/delete': (ctx, res, body, g) => {
1153
1169
  // a task added by mistake (batch 7 item 5): the task-remove line takes it out everywhere; tasks/restore is its Undo. Archived stays for
1154
- // work that stopped. A breakdown item is withdrawn (Won't do), never deleted.
1170
+ // work that stopped. A breakdown item is withdrawn with why "deleted", and a restored line is its Undo (batch 11 item 16).
1155
1171
  const p = postFrame(ctx, res, body);
1156
1172
  if (!p) return;
1157
- if (TI.isItemId(body.task)) return fail(ctx, res, 409, `${body.task} is a breakdown item: set it to Won't do instead`);
1173
+ if (body.why != null && (typeof body.why !== 'string' || body.why.length > 500)) return fail(ctx, res, 400, 'why is text of at most 500 characters');
1174
+ if (!B.taskOf(p.fr.folded, body.task) && TI.isItemId(body.task)) {
1175
+ const it = itemOnBoard(ctx, res, p, body.task);
1176
+ if (!it) return;
1177
+ const w = TI.write(p.w.root, TI.deleteEvents(it, body.why).events, g.actor, g.cli || null);
1178
+ if (!w.ok) return fail(ctx, res, w.status || 400, w.error);
1179
+ return ctx.json(res, { ok: true, task: it.id, title: it.title });
1180
+ }
1158
1181
  const t = B.taskOf(p.fr.folded, body.task);
1159
1182
  if (!t || t.board !== p.board.id) return fail(ctx, res, 404, `no PMOS task ${body.task} on this board`);
1160
- if (body.why != null && (typeof body.why !== 'string' || body.why.length > 500)) return fail(ctx, res, 400, 'why is text of at most 500 characters');
1161
1183
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
1162
1184
  append(p.file, g.actor, { kind: 'task-remove', board: p.board.id, task: t.id, why: body.why ? String(body.why).trim() : 'deleted' });
1163
1185
  ctx.json(res, { ok: true, task: t.id, title: t.title });
@@ -1167,6 +1189,17 @@ const WRITES = {
1167
1189
  if (!p) return;
1168
1190
  if (typeof body.task !== 'string' || !body.task) return fail(ctx, res, 400, 'task is required');
1169
1191
  if (B.taskOf(p.fr.folded, body.task)) return fail(ctx, res, 409, `${body.task} is not deleted`);
1192
+ if (TI.isItemId(body.task)) {
1193
+ if (TI.itemOf(p.w.root, body.task)) return fail(ctx, res, 409, `${body.task} is not deleted`);
1194
+ const was = TI.goneOf(p.w.root, body.task);
1195
+ const base = was && needRows(ctx, res, p.w);
1196
+ if (was && !base) return;
1197
+ const b0 = base && base.find((r) => r.id === was.initiative);
1198
+ if (!was || !b0 || boardIdOf(b0, p.fr.boards, p.fr.folded, p.w) !== p.board.id) return fail(ctx, res, 404, `no deleted task ${body.task} on this board`);
1199
+ const w = TI.write(p.w.root, TI.restoreEvents(body.task).events, g.actor, g.cli || null);
1200
+ if (!w.ok) return fail(ctx, res, w.status || 400, w.error);
1201
+ return ctx.json(res, { ok: true, task: body.task });
1202
+ }
1170
1203
  const ev = [...p.fr.folded.events].reverse().find((e) => e.kind === 'task-remove' && e.task === body.task);
1171
1204
  if (!ev || ev.board !== p.board.id) return fail(ctx, res, 404, `no deleted task ${body.task} on this board`);
1172
1205
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
@@ -1194,6 +1227,30 @@ const WRITES = {
1194
1227
  // the task Viewer edits in place (canvas XetX1Rest, XetX1Dates): each change saves at once; Undo sends `from` back
1195
1228
  const p = postFrame(ctx, res, body);
1196
1229
  if (!p) return;
1230
+ if (body.milestone != null && typeof body.milestone !== 'boolean') return fail(ctx, res, 400, 'milestone is true or false');
1231
+ // a Jira ticket takes the milestone flag (feedback batch 11 item 3) and the PM's own start and due days, kept in PMOS only (item 23):
1232
+ // Jira keeps its title, status and assignee, and nothing is written to Jira
1233
+ if (typeof body.task === 'string' && B.JIRA_KEY_RE.test(body.task) && !B.taskOf(p.fr.folded, body.task)) {
1234
+ if (['owner', 'notes', 'initiative', 'section'].some((k) => body[k] != null)) return fail(ctx, res, 409, 'Jira owns this ticket: only its dates and its milestone flag change here');
1235
+ if (body.milestone == null && body.start == null && body.due == null) return fail(ctx, res, 400, 'nothing to change: send start, due or milestone');
1236
+ 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, or '' for none`);
1237
+ if (!p.file) return fail(ctx, res, 409, NO_STATE);
1238
+ const from = {}, ref = body.task.toUpperCase();
1239
+ if (body.start != null || body.due != null) {
1240
+ const TD = p.fr.folded.ticketDates || new Map(), was = TD.get(p.board.id + '\u0000' + ref) || { start: '', due: '' };
1241
+ const next = { start: body.start != null ? String(body.start) : was.start, due: body.due != null ? String(body.due) : was.due };
1242
+ if (next.start && next.due && next.start > next.due) return fail(ctx, res, 400, 'the start is after the due day');
1243
+ if (body.start != null) from.start = was.start;
1244
+ if (body.due != null) from.due = was.due;
1245
+ append(p.file, g.actor, { kind: 'ticket-dates', board: p.board.id, ref, ...next, why: 'dates kept in PMOS' });
1246
+ }
1247
+ if (body.milestone != null) {
1248
+ const MS0 = p.fr.folded.milestones || new Map();
1249
+ from.milestone = !!MS0.get(body.task);
1250
+ append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: body.task, milestone: body.milestone, why: body.milestone ? 'made a milestone' : 'no longer a milestone' });
1251
+ }
1252
+ return ctx.json(res, { ok: true, from, item: null });
1253
+ }
1197
1254
  const t0 = B.taskOf(p.fr.folded, body.task);
1198
1255
  let t = t0;
1199
1256
  if (!t0 && TI.isItemId(body.task)) {
@@ -1234,8 +1291,16 @@ const WRITES = {
1234
1291
  sec = body.section; from.section = S0.has(t.id) ? S0.get(t.id) : (t.from && t.from.stage) || '';
1235
1292
  if (!p.file) return fail(ctx, res, 409, NO_STATE);
1236
1293
  }
1237
- if (!Object.keys(ev).length && sec == null) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, initiative or section');
1294
+ // the milestone flag (feedback batch 11 item 3): a board-ledger line for every kind of task, like the section
1295
+ let ms = null;
1296
+ if (body.milestone != null) {
1297
+ if (!p.file) return fail(ctx, res, 409, NO_STATE);
1298
+ const MS0 = p.fr.folded.milestones || new Map();
1299
+ ms = body.milestone; from.milestone = MS0.has(t.id) ? MS0.get(t.id) : !!t.milestone;
1300
+ }
1301
+ if (!Object.keys(ev).length && sec == null && ms == null) return fail(ctx, res, 400, 'nothing to change: send owner, notes, start, due, initiative, section or milestone');
1238
1302
  if (sec != null) append(p.file, g.actor, { kind: 'task-section', board: p.board.id, task: t.id, section: sec, why: sec ? 'placed under ' + sec : 'placed under no stage' });
1303
+ if (ms != null) append(p.file, g.actor, { kind: 'task-milestone', board: p.board.id, task: t.id, milestone: ms, why: ms ? 'made a milestone' : 'no longer a milestone' });
1239
1304
  if (!Object.keys(ev).length) {
1240
1305
  const items = itemsOf(p.w, { ...p.fr, folded: B.fold(readLedger(ctx, p.w)) }, p.board, (needRows(ctx, res, p.w) || []).filter((r) => r.id === t.initiative));
1241
1306
  return ctx.json(res, { ok: true, from, item: items.find((x) => x.uid === t.id) || null });
@@ -1393,6 +1458,20 @@ async function handle(req, res, url, ctx) {
1393
1458
  return true;
1394
1459
  }
1395
1460
 
1461
+ /** Planned versus actual (batch 11 item 8): a move into Build saves the plan "Build start" once, when the initiative has none
1462
+ * (lib/routes-task-plans.js buildStart). It runs after the move's answer is ready, and never changes it. */
1463
+ for (const route of ['/api/boards/move', '/api/boards/ini-wf']) {
1464
+ const plain = WRITES[route];
1465
+ if (!plain) continue;
1466
+ WRITES[route] = (ctx, res, body, g) => plain({ ...ctx, json: (r, obj, code) => {
1467
+ if (obj && obj.ok && obj.row && obj.row.id) {
1468
+ const w = wsOf(ctx, typeof body.ws === 'string' ? body.ws : null), b = w && frameFor(ctx, w).boards.find((x) => x.id === body.board);
1469
+ if (w && b) require('./routes-task-plans.js').buildStart(ctx, w, b, obj.row, g.actor);
1470
+ }
1471
+ ctx.json(r, obj, code);
1472
+ } }, res, body, g);
1473
+ }
1474
+
1396
1475
  /** One write route run outside HTTP, by the same function the page's press runs, so its validation, warnings and ledger line are the
1397
1476
  * 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
1398
1477
  * route would send. */
@@ -1503,4 +1582,4 @@ function meetingBoards(ctx) {
1503
1582
  return { list, detail };
1504
1583
  }
1505
1584
 
1506
- module.exports = { prefixes: ['/api/boards'], handle, move, switchWorkflow, taskState, taskAdd, taskEdit, taskDelete, taskRestore, initiativeWorkflow, seedInitiative, stageTasks, itemsOf, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, taskSpanOf, workflowRowOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
1585
+ module.exports = { prefixes: ['/api/boards'], handle, postFrame, needRows, itemsOf, readLedger, foldOf, epicsOf, rowsOfBoard, invalidateRows: (w) => { rowsLib.invalidate(w.root); rowCache.delete(w.root); }, move, switchWorkflow, taskState, taskAdd, taskEdit, taskDelete, taskRestore, initiativeWorkflow, seedInitiative, stageTasks, boardIndex, appendScanAsk, scanDeclineSignal, createAndPlace, ledgerFile, append, frameFor, boardIdOf, meetingBoards, boardsOf, baseRows, boardRow, taskSpanOf, workflowRowOf, foldOf, portfolio, SELF_REFUSAL, NO_STATE };
@@ -19,6 +19,9 @@
19
19
  * POST /api/doc-sheet/why { path, rev, why } page press; a reason for a revision that has none (an outside change);
20
20
  * appended to annotations.jsonl, the revision itself is not rewritten
21
21
  * POST /api/doc-sheet/mark-current { path, why } page press; "still current" with a reason; it counts as the last change
22
+ * GET /api/doc-sheet/stamp?path=&ini= → { ok, ws, hash } which workspace holds the live copy and its text's hash. With an initiative id,
23
+ * the initiative's own worktree when it holds the file (lib/doc-live-root.js): a chat edits there and
24
+ * does not commit. The page checks this every few seconds and reads again when it changed.
22
25
  *
23
26
  * Every revision says who wrote the text and how it came in: via 'sheet' (an edit here), 'proposal' (accepted; text_by 'agent',
24
27
  * by 'pm', the proposal id and the sections taken) or 'outside' (the file changed outside the sheet; git's last commit of
@@ -372,11 +375,35 @@ function changeNote(root, body, runtimeDir) {
372
375
  return { status: 200, body: { ok: true, note } };
373
376
  }
374
377
 
378
+ // the live copy (GET /api/doc-sheet/stamp). git is asked at most every few seconds per repository: an open page asks every 2.5 s.
379
+ const GIT_TTL_MS = 3000;
380
+ const gitCache = new Map();
381
+ function cached(key, fn) {
382
+ const hit = gitCache.get(key);
383
+ if (hit && Date.now() - hit.at < GIT_TTL_MS) return hit.v;
384
+ const v = fn(); gitCache.set(key, { at: Date.now(), v });
385
+ if (gitCache.size > 200) gitCache.delete(gitCache.keys().next().value);
386
+ return v;
387
+ }
388
+ function stampRoute(q, w, ctx) {
389
+ const gitInfo = require('./git-info.js');
390
+ const base = w || { id: null, root: ctx.root || ROOT };
391
+ const live = require('./doc-live-root.js').liveWs({
392
+ base, ini: q.ini, rel: q.path,
393
+ workspaces: ctx.workspaceList ? ctx.workspaceList() : [],
394
+ topOf: (root) => cached('top|' + root, () => gitInfo.repoRoot(root)),
395
+ worktreesOf: (top) => cached('wt|' + top, () => gitInfo.worktrees(top)),
396
+ has: (root, rel) => !resolveDoc(root, rel).error,
397
+ });
398
+ const r = resolveDoc(live.root, q.path); if (r.error) return r.error;
399
+ return { status: 200, body: { ok: true, path: r.rel, ws: live.id || null, hash: S.hashText(r.text) } };
400
+ }
401
+
375
402
  const respond = (ctx, res, r) => { ctx.json(res, r.body, r.status); return true; };
376
403
 
377
404
  module.exports = {
378
405
  prefixes: ['/api/doc-sheet'],
379
- resolveDoc, revisionsRoute, atRoute, edit, propose, accept, changeNote, proposalsRoute, logRoute, reject, addWhy, markCurrent, lastSheetChange, ask, askState, askPrompt, parseAsk, settleAsk,
406
+ resolveDoc, stampRoute, revisionsRoute, atRoute, edit, propose, accept, changeNote, proposalsRoute, logRoute, reject, addWhy, markCurrent, lastSheetChange, ask, askState, askPrompt, parseAsk, settleAsk,
380
407
  handle: async (req, res, url, ctx) => {
381
408
  const p = url.pathname;
382
409
  const w = (url.searchParams.get('ws') && ctx.getWs) ? ctx.getWs(url.searchParams.get('ws')) : null;
@@ -385,6 +412,7 @@ module.exports = {
385
412
  if (req.method === 'GET' && p === '/api/doc-sheet/ask') return respond(ctx, res, askState(Object.fromEntries(url.searchParams), base));
386
413
  if (req.method === 'GET' && p === '/api/doc-sheet/at') return respond(ctx, res, atRoute(base.root, Object.fromEntries(url.searchParams), base.runtimeDir));
387
414
  if (req.method === 'GET' && p === '/api/doc-sheet/proposals') return respond(ctx, res, proposalsRoute(base.root, Object.fromEntries(url.searchParams), base.runtimeDir));
415
+ if (req.method === 'GET' && p === '/api/doc-sheet/stamp') return respond(ctx, res, stampRoute(Object.fromEntries(url.searchParams), w, ctx));
388
416
  if (req.method === 'GET' && p === '/api/doc-sheet/log') return respond(ctx, res, logRoute(base.root, Object.fromEntries(url.searchParams), base.runtimeDir));
389
417
  const fn = req.method === 'POST' && { '/api/doc-sheet/edit': edit, '/api/doc-sheet/propose': propose, '/api/doc-sheet/accept': accept,
390
418
  '/api/doc-sheet/reject': reject, '/api/doc-sheet/why': addWhy, '/api/doc-sheet/mark-current': markCurrent, '/api/doc-sheet/ask': ask,
@@ -662,6 +662,18 @@ async function handle(req, res, url, ctx) {
662
662
  ctx.json(res, { ok: true, id: r.id, from: r.from, title: r.title, path: r.path, sig: sigOf(w.root) });
663
663
  return true;
664
664
  }
665
+ // split or merge initiatives (feedback batch 11 item 14; lib/split-merge.js): the editor's button or ✓ on Claude's card, Undo, and ✕ Not now
666
+ const SM_ROUTES = { '/api/initiatives/split': 'split', '/api/initiatives/merge': 'merge', '/api/initiatives/sm-undo': 'undo', '/api/initiatives/suggest': 'dismiss' };
667
+ if (SM_ROUTES[p]) {
668
+ const g = guard.requirePagePress(req, body);
669
+ if (!g.ok) return answer(ctx, res, g), true;
670
+ let r;
671
+ try { r = require('./split-merge.js')[SM_ROUTES[p]](ctx, w, body, g.actor); }
672
+ catch (e) { r = { ok: false, status: 500, error: String((e && e.message) || e).slice(0, 200) }; }
673
+ if (!r.ok) { const { ok: _o, status, ...rest } = r; ctx.json(res, { ok: false, ...rest }, status || 400); return true; }
674
+ ctx.json(res, { ...r, ws: w.id, sig: sigOf(w.root) });
675
+ return true;
676
+ }
665
677
  if (p === '/api/initiatives') {
666
678
  const g = guard.requirePagePress(req, body);
667
679
  if (!g.ok) return answer(ctx, res, g), true;
@@ -3,7 +3,10 @@
3
3
  *
4
4
  * GET /api/programs → { ok, programs: [program] } merged from every registered workspace (lib/programs.js merge)
5
5
  * POST /api/programs/save { ws, program } the charter: title, owner, goal, why, start, target, jira, milestones (the last save wins)
6
- * POST /api/programs/member { ws, program, initiative, leave? } an initiative of workspace `ws` joins (or leaves) the program
6
+ * POST /api/programs/member { ws, program, initiative, leave?, back? } an initiative of workspace `ws` joins (or leaves) the program. A leave
7
+ * takes it off the charter's milestones that wait on it and answers `off`: [{ id, name, stage? }];
8
+ * a join that leaves another program answers `left`: { program, title, off }. Undo rejoins with
9
+ * `back` (an `off` list), which puts it back on those milestones (canvas LpA3Done)
7
10
  * POST /api/programs/turn { ws, initiative, title? } "Turn into a program": a charter named after the initiative, which joins it; the
8
11
  * charter keeps `from` (the initiative), so the panel can count its tasks with no level
9
12
  * POST /api/programs/task { ws, program, title, owner?, due?, key? } a task on the program itself
@@ -116,11 +119,47 @@ module.exports = {
116
119
  if (!P.ID_RE.test(pid)) return bad('program must name a program');
117
120
  if (!known(pid)) return bad('no such program', 404);
118
121
  if (p === '/api/programs/member') {
119
- if (!P.INI_RE.test(String(b.initiative || ''))) return bad('initiative must name an initiative');
122
+ const ini = String(b.initiative || '');
123
+ if (!P.INI_RE.test(ini)) return bad('initiative must name an initiative');
124
+ const charter = (prog, milestones) => { // one charter line in the charter's workspace, as a Save writes it (the last line wins)
125
+ const v = P.validProgram({ ...prog, milestones }), cw = ctx.getWs ? ctx.getWs(prog.home || null) : null, cf = cw ? fileOf(ctx, cw) : null;
126
+ if (!v.error && cf) pmItems.appendEvent(cf, v, now);
127
+ };
128
+ // a milestone that waits on an initiative that left could never be done (program-model.js counts it unread): the leave takes it off
129
+ // the charter's milestones, and answers which, with the ◆ stage each picked, so Undo puts them back (canvas LpA3Done, "off 1 milestone")
130
+ const takeOff = (prog) => {
131
+ const off = [];
132
+ const ms = (prog.milestones || []).map((m) => {
133
+ if (!(m.waits || []).includes(ini)) return m;
134
+ const st = { ...(m.stages || {}) }, one = { id: m.id, name: m.name };
135
+ if (st[ini]) { one.stage = st[ini]; delete st[ini]; }
136
+ off.push(one);
137
+ return { ...m, waits: m.waits.filter((x) => x !== ini), stages: st };
138
+ });
139
+ if (off.length) charter(prog, ms);
140
+ return off;
141
+ };
142
+ let left = null, off = [];
120
143
  // an initiative is in one program at most: joining one leaves any other it is in, in this workspace
121
- if (!b.leave) for (const o of all(ctx)) if (o.id !== pid && o.members.some((m) => m.ws === w.id && m.initiative === b.initiative)) add({ kind: 'leave', program: o.id, initiative: String(b.initiative) });
122
- add({ kind: b.leave ? 'leave' : 'member', program: pid, initiative: String(b.initiative) });
123
- ctx.json(res, { ok: true, program: known(pid) });
144
+ if (!b.leave) for (const o of all(ctx)) if (o.id !== pid && o.members.some((m) => m.ws === w.id && m.initiative === ini)) { add({ kind: 'leave', program: o.id, initiative: ini }); left = { program: o.id, title: o.title, off: takeOff(o) }; }
145
+ if (b.leave) off = takeOff(known(pid));
146
+ add({ kind: b.leave ? 'leave' : 'member', program: pid, initiative: ini });
147
+ // Undo of a leave rejoins with `back`: the milestones it was taken off, [{ id, stage? }]; a milestone the charter no longer has is skipped
148
+ const back = !b.leave && Array.isArray(b.back) ? b.back.filter((x) => x && P.ID_RE.test(String(x.id || ''))).slice(0, 12) : [];
149
+ if (back.length) {
150
+ const prog = known(pid);
151
+ let n = 0;
152
+ const ms = (prog.milestones || []).map((m) => {
153
+ const x = back.find((y) => y.id === m.id);
154
+ if (!x || (m.waits || []).includes(ini)) return m;
155
+ n++;
156
+ const st = { ...(m.stages || {}) };
157
+ if (x.stage && /^[a-z0-9][a-z0-9-]{0,39}$/.test(String(x.stage))) st[ini] = String(x.stage);
158
+ return { ...m, waits: [...(m.waits || []), ini], stages: st };
159
+ });
160
+ if (n) charter(prog, ms);
161
+ }
162
+ ctx.json(res, { ok: true, program: known(pid), off, left });
124
163
  return true;
125
164
  }
126
165
  if (p === '/api/programs/task') {