create-pmos 0.421.0 → 0.422.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 (68) hide show
  1. package/package.json +13 -13
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/scripts/anchor-resolve.js +93 -15
  6. package/payload/state/discoveries.md +1 -1
  7. package/workspace/board-programs-test.js +59 -3
  8. package/workspace/briefing-premium-board-test.js +1 -1
  9. package/workspace/changelog.json +12 -0
  10. package/workspace/fixtures/report-api/draft.json +2 -1
  11. package/workspace/guide/briefing-premium.md +1 -0
  12. package/workspace/guide/home.md +5 -2
  13. package/workspace/guide/programs.md +4 -3
  14. package/workspace/home-other-product-test.js +55 -0
  15. package/workspace/lib/board-premium.js +18 -4
  16. package/workspace/lib/doc-live-root.js +37 -0
  17. package/workspace/lib/engine/anchor-resolve.js +93 -15
  18. package/workspace/lib/engine/boards.js +7 -2
  19. package/workspace/lib/engine/intake.js +1 -1
  20. package/workspace/lib/hold-spans.js +24 -10
  21. package/workspace/lib/kg.js +1 -1
  22. package/workspace/lib/report-draft.js +3 -0
  23. package/workspace/lib/route-modules.js +1 -0
  24. package/workspace/lib/routes-board-premium.js +6 -0
  25. package/workspace/lib/routes-boards.js +48 -9
  26. package/workspace/lib/routes-doc-sheet.js +29 -1
  27. package/workspace/lib/routes-programs.js +44 -5
  28. package/workspace/lib/routes-task-plans.js +333 -0
  29. package/workspace/lib/task-cli.js +16 -9
  30. package/workspace/lib/task-items.js +1 -1
  31. package/workspace/lib/task-plans.js +232 -0
  32. package/workspace/lib/vendor/scripts/anchor-resolve.js +93 -15
  33. package/workspace/lib/vendor/scripts/intake.js +1 -1
  34. package/workspace/package-lock.json +2 -2
  35. package/workspace/package.json +1 -1
  36. package/workspace/premium-vw-doc-test.js +26 -3
  37. package/workspace/program-leave-test.js +203 -0
  38. package/workspace/public/pm/bd-acts.js +5 -2
  39. package/workspace/public/pm/bd-ini-panel.js +20 -7
  40. package/workspace/public/pm/bd-prog-panel.js +22 -7
  41. package/workspace/public/pm/bd-span.js +175 -25
  42. package/workspace/public/pm/cozy-board.css +80 -0
  43. package/workspace/public/pm/cozy-home.css +3 -0
  44. package/workspace/public/pm/doc-follow.js +36 -0
  45. package/workspace/public/pm/home-app.js +38 -7
  46. package/workspace/public/pm/home-ini.js +11 -2
  47. package/workspace/public/pm/home-list.js +2 -2
  48. package/workspace/public/pm/home-today.js +3 -1
  49. package/workspace/public/pm/ini-tasks.js +81 -16
  50. package/workspace/public/pm/ini-versions.js +343 -0
  51. package/workspace/public/pm/ini-view-model.js +27 -41
  52. package/workspace/public/pm/ini-view.css +82 -0
  53. package/workspace/public/pm/ini-view.js +17 -10
  54. package/workspace/public/pm/premium-board.js +109 -18
  55. package/workspace/public/pm/premium-report-read.js +20 -1
  56. package/workspace/public/pm/premium-shell.js +29 -4
  57. package/workspace/public/pm/premium-vw-doc.js +46 -11
  58. package/workspace/public/pm/prog-move.js +69 -0
  59. package/workspace/public/pm/task-card.css +3 -0
  60. package/workspace/public/pm/task-card.js +10 -3
  61. package/workspace/task-milestones-test.js +176 -0
  62. package/workspace/task-plans-test.js +175 -0
  63. package/workspace/task-views-test.js +2 -2
  64. package/workspace/test-lists/program-leave.json +6 -0
  65. package/workspace/test-lists/task-milestones.json +6 -0
  66. package/workspace/test-lists/task-plans.json +6 -0
  67. package/workspace/test-lists/viewer-live-file.json +9 -0
  68. package/workspace/timeline-holds-test.js +61 -4
@@ -13,7 +13,8 @@
13
13
  * wireView(body, h) the presses, once per body: h.check(uid, btn), h.openTask(uid), h.openTicket(key), h.add(btn) (the + icon: the host
14
14
  * redraws with o.adding, an inline field), h.addTask(title, input), h.addCancel(), h.next(btn),
15
15
  * h.primary(act, btn), h.program(id), h.docs(), h.doc(path) (a linked document), h.draft(btn), h.wf(btn), h.redraw() (after a fold opens or closes),
16
- * h.status(uid, state) and h.dates(uid, { start?, due? }) (the quick changes, each saved at once with Undo in the host's toast)
16
+ * h.status(uid, state) and h.dates(uid, { start?, due? }) (the quick changes, each saved at once with Undo in the host's toast);
17
+ * for planned versus actual (pm/ini-versions.js) h.where() → { ws, board }, h.reload() and h.toast(text, undo?)
17
18
  *
18
19
  * Tasks has three views (batch 9 item 5b; canvas In development, row "Tasks views"): the List (the WBS below), Timeline and Kanban
19
20
  * (pm/ini-tasks.js). The icon segment in the Tasks header switches them, and the last one is remembered for the PM.
@@ -22,6 +23,7 @@
22
23
  * their words in aria-label and title. Zero is silence: a part with nothing on record draws nothing. */
23
24
  import { wfIcon } from './wf-model.js';
24
25
  import * as TV from './ini-tasks.js'; // Tasks as List, Timeline or Kanban, and the quick status and dates (batch 9 item 5b)
26
+ import * as VS from './ini-versions.js'; // planned versus actual: the version chip, Make live, a draft's writes (batch 11 item 8)
25
27
 
26
28
  const CSS = new URL('./ini-view.css', import.meta.url).href;
27
29
  if (typeof document !== 'undefined' && document.head && !document.querySelector(`link[href="${CSS}"]`)) {
@@ -32,7 +34,7 @@ const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" heigh
32
34
  const P = {
33
35
  go: 'M5 12h14M13 6l6 6-6 6', check: 'M5 12l5 5 9-10', right: 'M10 7l5 5-5 5', down: 'M7 10l5 5 5-5', plus: 'M12 5v14M5 12h14',
34
36
  prog: 'M12 3l9 5-9 5-9-5zM3 13l9 5 9-5', doc: 'M7 3h7l5 5v13H7zM14 3v5h5', draft: 'M12 3v4M12 17v4M3 12h4M17 12h4M5.6 5.6l2.8 2.8M15.6 15.6l2.8 2.8M5.6 18.4l2.8-2.8M15.6 8.4l2.8-2.8',
35
- skip: 'M7 17L17 7',
37
+ skip: 'M6 7l5 5-5 5M13 7l5 5-5 5', // » a skipped stage (batch 11 item 13: the same mark as the timelines)
36
38
  };
37
39
  const FOLD = new Map(); // `${id}|${key}` → true (open) | false (shut): the PM's own fold, for the session
38
40
  const isOpen = (v, key, dflt) => { const k = (v.id || v.key) + '|' + key; return FOLD.has(k) ? FOLD.get(k) : !!dflt; };
@@ -70,17 +72,19 @@ function stageHtml(st, o) {
70
72
  /* ── the WBS ── */
71
73
  function taskHtml(x, o, arch) {
72
74
  // the box marks done in one press; its caret opens the status picker right under it (an archived task has only the caret)
73
- const car = o.quick && x.uid ? `<button type="button" class="iv-car" data-iv-stat="${esc(x.uid)}" data-st="${esc(x.status)}" aria-haspopup="dialog" aria-label="${esc('Change the status: ' + x.title)}" title="Status">${SVG(P.down, 10, 2.6)}</button>` : '';
75
+ const car = o.quick && x.uid ? `<button type="button" class="iv-car" data-iv-stat="${esc(x.uid)}" data-st="${esc(x.status)}" data-ms="${x.ms ? 1 : 0}" aria-haspopup="dialog" aria-label="${esc('Change the status: ' + x.title)}" title="Status">${SVG(P.down, 10, 2.6)}</button>` : '';
74
76
  const cls = ['iv-cb', x.done ? 'on' : '', x.prog ? 'pr' : '', x.wont ? 'wo' : ''].filter(Boolean).join(' ');
75
- const chk = x.canCheck && !arch ? `<span class="iv-bxw"><button type="button" class="${cls}" data-iv-check="${esc(x.uid)}" aria-pressed="${x.done}" aria-label="${esc((x.done ? 'Reopen: ' : 'Mark done: ') + x.title)}" title="${x.done ? 'Reopen' : 'Mark done'}">${x.done ? SVG(P.check, 12, 3) : ''}</button>${car}</span>`
77
+ const chk = x.dr ? `<span class="iv-bxw"><span class="iv-cb dr" aria-hidden="true"></span>${car}</span>` : x.canCheck && !arch ? `<span class="iv-bxw"><button type="button" class="${cls}" data-iv-check="${esc(x.uid)}" aria-pressed="${x.done}" aria-label="${esc((x.done ? 'Reopen: ' : 'Mark done: ') + x.title)}" title="${x.done ? 'Reopen' : 'Mark done'}">${x.done ? SVG(P.check, 12, 3) : ''}</button>${car}</span>`
76
78
  : `<span class="iv-bxw"><span class="iv-cb off${x.done ? ' on' : ''}" aria-hidden="true">${x.done ? SVG(P.check, 12, 3) : ''}</span>${arch ? car : ''}</span>`;
77
- const t = o.openTask && x.uid ? `<button type="button" class="iv-tt" data-iv-task="${esc(x.uid)}">${esc(x.title)}</button>` : `<b class="iv-tt">${esc(x.title)}</b>`;
79
+ const t = (o.openTask && x.uid && !x.dr ? `<button type="button" class="iv-tt" data-iv-task="${esc(x.uid)}">${esc(x.title)}</button>` : `<b class="iv-tt">${esc(x.title)}</b>`) + TV.msGlyph(x) + TV.addedMark(x);
78
80
  // the meta: In progress, the dates (a press: the start and due picker opens under them), the late days, the owner
79
81
  let meta = x.sub ? `<span class="${x.late ? 'w' : ''}">${esc(x.sub)}</span>` : '';
80
82
  if (o.quick && x.uid) {
81
83
  // no dates: the calendar icon sits last and shows on hover, so an undated row reads the same as before
82
- const parts = [x.prog ? 'In progress' : '', x.days ? TV.dateBtn(x, o) + (x.lateText ? `<span class="iv-late">, ${esc(x.lateText)}</span>` : '') : '', x.owner && x.owner !== 'You' ? esc(x.owner) : ''];
84
+ const parts = [x.prog ? 'In progress' : '', x.days ? TV.dateBtn(x, o) + (x.lateText ? `<span class="iv-late">, ${esc(x.lateText)}</span>` : '') + TV.slipHtml(x) : '', x.owner && x.owner !== 'You' ? esc(x.owner) : ''];
83
85
  meta = `<span class="iv-rm">${parts.filter(Boolean).join('<span class="iv-sep" aria-hidden="true"> · </span>')}${x.days ? '' : TV.dateBtn(x, o)}</span>`;
86
+ } else if (TV.msNoDate(x)) {
87
+ meta = `<span class="iv-rm">${x.sub ? `<span>${esc(x.sub)}</span> ` : ''}<span class="iv-dc ms">Set the due date</span></span>`;
84
88
  }
85
89
  return `<div class="iv-tr${x.closed ? ' done' : ''}${x.wont ? ' wo' : ''}${arch ? ' ar' : ''}">${chk}<span class="w">${t}${meta}</span></div>`;
86
90
  }
@@ -142,8 +146,10 @@ function tasksHtml(v, o) {
142
146
  const add = o.add ? `<button type="button" class="iv-ib" data-iv-add aria-label="Add a task to ${esc(v.title)}" title="Add a task">${SVG(P.plus, 16, 2.2)}</button>` : '';
143
147
  // the view switch shows once there is a task to see another way (zero is silence)
144
148
  const mode = T.empty ? 'list' : TV.viewMode();
145
- const head = `<div class="iv-th"><b>Tasks</b>${T.count ? `<span class="n">${esc(T.count)}</span>` : ''}<span class="iv-sp"></span>${T.empty ? '' : TV.headExtraHtml(v, mode) + TV.switchHtml(mode)}${add}</div>`
146
- + (o.adding ? `<form class="iv-addf" data-iv-addform><input id="ivAddTask" type="text" maxlength="160" autocomplete="off" placeholder="A task for ${esc(v.title)}" aria-label="New task"><button type="submit" class="iv-go" aria-label="Add the task" title="Add (Enter). Esc cancels.">${SVG(P.check, 16, 2.2)}</button></form>` : '');
149
+ // planned versus actual (batch 11 item 8): the version chip and the end slip after the count; Make live (seal) while a draft is shown
150
+ const cnt = VS.countText(v.vs, T.count, T.open + T.done);
151
+ const head = `<div class="iv-th"><b>Tasks</b>${cnt ? `<span class="n">${esc(cnt)}</span>` : ''}${VS.headHtml(v.vs)}<span class="iv-sp"></span>${T.empty ? '' : TV.headExtraHtml(v, mode) + TV.switchHtml(mode)}${VS.liveHtml(v.vs)}${add}</div>`
152
+ + (o.adding ? `<form class="iv-addf" data-iv-addform><input id="ivAddTask" type="text" maxlength="160" autocomplete="off" placeholder="A task for ${esc(v.title)}${o.addHint ? esc(', ' + o.addHint) : ''}" aria-label="New task"><button type="submit" class="iv-go" aria-label="Add the task" title="Add (Enter). Esc cancels.">${SVG(P.check, 16, 2.2)}</button></form>` : '');
147
153
  if (T.empty) {
148
154
  const sk = T.empty.stages.map((s) => `<span class="iv-sk"><span class="iv-no dash${s.ms ? ' ms' : ''}" aria-hidden="true">${s.ms ? '' : s.n}</span>${esc(s.name)}${s.now ? ' <i>· now</i>' : ''}</span>`).join('');
149
155
  return head + `<div class="iv-empty">${sk}<p class="iv-q">Claude drafts the breakdown, one section per stage. Nothing is saved until you keep it.</p>`
@@ -176,7 +182,7 @@ export function viewHtml(v, o = {}) {
176
182
  /* ── the presses ── */
177
183
  export function wireView(body, h) {
178
184
  if (!body) return;
179
- body.__iv = h;
185
+ body.__iv = VS.wrap(h, body, (id) => SHOWN.get(id));
180
186
  if (body.__ivWired) return;
181
187
  body.__ivWired = true;
182
188
  body.addEventListener('click', (e) => {
@@ -184,6 +190,7 @@ export function wireView(body, h) {
184
190
  const root = b.closest('[data-iv]'); if (!root) return;
185
191
  const id = root.dataset.iv;
186
192
  const d = b.dataset;
193
+ if (VS.press(b, d, root, H)) return;
187
194
  if (TV.press(b, d, root, { ...H, __v: SHOWN.get(id) }, e)) return;
188
195
  if (d.ivFold) { e.preventDefault(); const k = id + '|' + d.ivFold; FOLD.set(k, b.getAttribute('aria-expanded') !== 'true'); if (H.redraw) H.redraw(); return; }
189
196
  if (d.ivCheck && H.check) { e.preventDefault(); H.check(d.ivCheck, b); return; }
@@ -208,4 +215,4 @@ export function wireView(body, h) {
208
215
  body.addEventListener('keydown', (e) => { if (e.key === 'Escape' && e.target.id === 'ivAddTask') { e.stopPropagation(); const H = body.__iv || {}; if (H.addCancel) H.addCancel(); } });
209
216
  }
210
217
  /** For the tests: forget every fold the PM opened or shut. */
211
- export const resetFolds = () => { FOLD.clear(); TV.resetViews(); };
218
+ export const resetFolds = () => { FOLD.clear(); TV.resetViews(); VS.resetVersions(); };
@@ -18,11 +18,12 @@
18
18
  * chip row picks one (its own stages become the columns and the track's header) or All (the three categories, each row its own stages).
19
19
  * Where no record holds a value for an initiative, the element says so: nothing is invented. */
20
20
  import { pmPost } from './http.js';
21
+ import { followDoc } from './doc-follow.js';
21
22
  import { $, $$, esc, store, crumbHtml, wireCrumb, chatAbout, setPageGaps } from './premium-shell.js';
22
23
  import { mountNav } from './cozy-nav.js';
23
24
  import { mountLivePill } from './cozy-live-pill.js';
24
25
  import { stepsHelpHtml } from './bd-stages.js';
25
- import { timelineHtml, legendHtml, hasHold, SPANS, md } from './bd-span.js';
26
+ import { timelineHtml, legendHtml, hasHold, planKeys, gapKeys, plainGaps, skipsOf, skipWords, gapWords, SPANS, md } from './bd-span.js';
26
27
  import * as TL from './bd-scroll.js';
27
28
  import * as Acts from './bd-acts.js';
28
29
  import * as V from './bd-views.js';
@@ -30,10 +31,12 @@ import * as WF from './bd-wf.js';
30
31
  import * as Asks from './bd-asks.js';
31
32
  import * as PG from './bd-prog.js';
32
33
  import { programOf } from './program-model.js';
33
- import { open as viewerOpen } from './cozy-viewer.js';
34
+ import { open as viewerOpen, current as viewerCur } from './cozy-viewer.js';
34
35
  import * as VW from './cozy-viewer.js';
35
36
  import * as PP from './bd-prog-panel.js';
36
- import * as PO from './prog-order.js'; // the order of a program's initiatives: the grip and Claude's order from the dates (canvas RoADrag, RoASuggest)
37
+ import * as PO from './prog-order.js';
38
+ import * as PM from './prog-move.js'; // move an initiative out of its program, or to another (canvas LpA1More, LpA2Other)
39
+ import * as Pop from './bd-pop.js'; // the order of a program's initiatives: the grip and Claude's order from the dates (canvas RoADrag, RoASuggest)
37
40
  import * as BI from './bd-ini-panel.js';
38
41
  import { nextHtml } from './bd-next.js';
39
42
  import { statusOf as ivStatus } from './ini-view-model.js';
@@ -54,7 +57,9 @@ const F = { chips: new Set(), q: '', owners: new Set(), cats: new Set(), sprints
54
57
  let GR = {}; // the first questions still open per initiative (GET /api/board-grill?ids=): { [id]: { open, total, later } }
55
58
  let PGS = []; // the programs (GET /api/programs): every view groups the rows a program holds under it (PgBoard)
56
59
  let XR = {}; // the other products' rows a program here holds, read once (GET /api/board-premium?ws=): { [ws]: { name, rows } }
57
- const ALL = new URLSearchParams(location.search).get('all') === '1'; // All products: every product's board on one page (PgBoard)
60
+ // the products picked (batch 11 item 7): ?all=1 every product, ?pick=<ws>|<board> repeated several, else one board
61
+ const PICK = new URLSearchParams(location.search).getAll('pick').filter((x) => /\|/.test(x));
62
+ const ALL = new URLSearchParams(location.search).get('all') === '1' || PICK.length > 1; // All products, or several: their boards on one page (PgBoard)
58
63
  let byProduct = store.get(GROUPING_KEY) === 'product'; // the grouping: programs first (default) or By product (PgBoardProduct)
59
64
  let DM = {}; // the documents' history (GET /api/board-docs): { [path]: { changed, by, log } }
60
65
  let peek = null; // what the Viewer shows for the Board: { kind: 'ini', key } an initiative or its ticket, { kind: 'acts' } an acts panel
@@ -139,10 +144,21 @@ function drawHead() {
139
144
  crumbed = true;
140
145
  // the picker: All products first when there is more than one product, then each product's board
141
146
  const list = M.board.switcher || [], boards = list.length > 1 ? [{ ws: '*', id: '*', name: 'All products' }, ...list] : list;
147
+ // the button says it once: All products, the one product, or the first product and "+N" (several)
148
+ const names = (M.board.products || []).map((p) => p.name), some = ALL && PICK.length > 1;
149
+ const label = some ? esc(names[0] || 'Products') + ' <b>+' + (names.length - 1) + '</b>' : esc(M.board.name || 'Board');
142
150
  $('#crumbHost').innerHTML = crumbHtml({ page: '', board: M.board.name || 'Board', boards });
143
- wireCrumb({ boards, board: ALL ? '*' : M.board.id, goBoard: (ws, id) => location.assign(id === '*' ? '/premium-board.html?all=1' : '/premium-board.html?ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(id)) });
144
- $('#crBoard').setAttribute('aria-label', 'Product: ' + (M.board.name || 'Board'));
145
- chatAbout('board:this-board', ALL ? 'all products' : M.board.name ? 'the ' + M.board.name + ' board' : 'this board');
151
+ $('#crBoard').innerHTML = label;
152
+ // several products can be ticked (batch 11 item 7); the pick goes into the address, so a reload keeps it
153
+ const picked = !ALL ? [M.board.ws + '|' + M.board.id] : (M.board.products || []).map((p) => p.ws + '|' + p.id);
154
+ const goBoard = (ws, id) => location.assign(id === '*' ? '/premium-board.html?all=1' : '/premium-board.html?ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(id));
155
+ wireCrumb({ boards, board: ALL ? '*' : M.board.id, goBoard, picked: list.length > 1 ? picked : null, goPicked: (keys) => {
156
+ if (keys.length === list.length) return goBoard('*', '*');
157
+ if (keys.length === 1) { const [ws, id] = keys[0].split('|'); return goBoard(ws, id); }
158
+ location.assign('/premium-board.html?' + keys.map((k) => 'pick=' + encodeURIComponent(k)).join('&'));
159
+ } });
160
+ $('#crBoard').setAttribute('aria-label', 'Product: ' + (some ? names.join(', ') : M.board.name || 'Board'));
161
+ chatAbout('board:this-board', some ? 'the ' + names.join(', ') + ' boards' : ALL ? 'all products' : M.board.name ? 'the ' + M.board.name + ' board' : 'this board');
146
162
  }
147
163
  $('#snap').textContent = M.header.text;
148
164
  // PMOS-self: new work starts at the pmos-router skill. All products: New asks which product the initiative is for
@@ -171,7 +187,7 @@ function drawChips() {
171
187
  }
172
188
  // the timeline's legend sits at the end of the chip row (PgTimeline), with a program milestone only where a program is drawn and "On hold" only
173
189
  // where a hold is drawn (feedback batch 9 item 8: zero is silence)
174
- const lgd = view === 'time' && span !== 'sprint' ? '<span class="bd-sp"></span>' + legendHtml(!byProduct && !!groups(visible()), hasHold(visible())) : '';
190
+ const lgd = view === 'time' && span !== 'sprint' ? '<span class="bd-sp"></span>' + legendHtml(!byProduct && !!groups(visible()), hasHold(visible()), { ...planKeys(visible()), ...gapKeys(visible()) }) : '';
175
191
  $('#bdChipset').innerHTML = jiraChip
176
192
  + (ALL ? '' : `<button type="button" class="bd-chip" id="chSprint" aria-haspopup="dialog">${SV(I.cal)}<span>${esc(sprint)}</span></button>`)
177
193
  + askChip + '<span class="bd-vr"></span>' + flt(['late', 'risk', 'blocked', 'idle'])
@@ -472,6 +488,12 @@ $('#ibBody').addEventListener('click', (e) => {
472
488
  const tk = e.target.closest('[data-tk]'); if (tk) { openTicket(tk.dataset.ini, tk.dataset.tk, tk); return; }
473
489
  if (e.target.closest('[data-act], [data-hold]')) return; // pm/bd-acts.js handles its own presses (a ⏸ on the timeline opens its hold there)
474
490
  const pg = e.target.closest('[data-prog]'); if (pg) { PG.openProgram(pg.dataset.prog, pg); return; }
491
+ // a counted milestone ◇ lists its milestones right under it; on a phone the row's bar lane opens them in a sheet (batch 11 item 3)
492
+ const mc = e.target.closest('[data-ms-row]'); if (mc) { msPop(mc, rowOf(mc.dataset.msRow), mc.dataset.msIds.split(' ')); return; }
493
+ // a gap's press (batch 11 item 13): its words, and + New task with its dates while part of it is ahead
494
+ const gp = e.target.closest('[data-gap]'); if (gp) { gapPop(gp, rowOf(gp.dataset.gap)); return; }
495
+ // the phone's row sheet lists the milestones, the gaps and the skipped stages in date order (XmlA5Phone, XgapA3Phone)
496
+ const lane = PHONE.matches && e.target.closest('.tgq-r[data-row] > .tg-p'); if (lane) { const r = rowOf(lane.parentElement.dataset.row); if (r && ((r.milestones || []).length || plainGaps(r).length || skipsOf(r).length)) { msPop(lane, r, null, true); return; } }
475
497
  const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key), b, view === 'time' ? 'time' : 'track');
476
498
  });
477
499
  $('#ibBody').addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target.matches('[data-steps]')) { e.preventDefault(); togglePop('popSteps', e.target); } });
@@ -532,6 +554,16 @@ async function turnProgram(r) {
532
554
  say('Now a program · ' + r.title + '.');
533
555
  PG.openProgram(res.program.id);
534
556
  }
557
+ /** The ⋯ items of an initiative in a program: Move out of it, Move to another program (pm/prog-move.js). The rows stay; the panel stays on it. */
558
+ function moveItems(r) {
559
+ return PM.moveItems({ programs: () => PGS, ws: r.ws || M.board.ws || '', id: r.id, product: r.product || M.board.product || M.board.name || '', pmPost, say,
560
+ reload: async () => { await loadPrograms(); load(); }, phone: () => PHONE.matches, stateOf: (p) => progState(p), openList: moveList });
561
+ }
562
+ function moveList(b, label, rows) {
563
+ const host = Pop.open(`<p class="bd-mlbl">${esc(label)}</p>${rows.map((x, i) => `<button type="button" class="bd-mi" role="menuitem" data-pm-to="${i}">${x.icon ? `<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="${x.icon}"/></svg>` : ''}<span class="tx"><span>${esc(x.label)}</span>${x.sub ? `<small>${esc(x.sub)}</small>` : ''}</span></button>`).join('')}`,
564
+ b, { label: 'Move to another program', role: 'menu', width: 280, align: 'right', cls: 'bd-menu', focus: '.bd-mi' });
565
+ if (host) host.onclick = (e) => { const t = e.target.closest('[data-pm-to]'); if (!t) return; const x = rows[+t.dataset.pmTo]; host.onclick = null; Pop.close(true); if (x) x.go(); };
566
+ }
535
567
  async function loadPrograms() {
536
568
  let r = null; try { r = await (await fetch('/api/programs', { credentials: 'same-origin' })).json(); } catch { r = null; }
537
569
  if (!r || !r.ok) return;
@@ -578,6 +610,58 @@ function openTicket(iniKey, key, from) {
578
610
  const r = rowOf(iniKey); if (!r || !r.track) return;
579
611
  const k = (r.track.tickets || []).find((x) => x.key === key); if (k) BI.openTicket(r, k, from);
580
612
  }
613
+ /** A row's milestones as a list (batch 11 item 3, canvas XmlA4Hover and XmlA5Phone): ◇, name, date. Under a counted ◇ it holds that ◇'s
614
+ * milestones; on a phone a sheet holds every milestone of the row. A row opens the task card (a Jira ticket its ticket Viewer). */
615
+ let msEl = null;
616
+ function msClose() { if (msEl) { const a = msEl.__a; msEl.remove(); msEl = null; if (a && a.isConnected) a.setAttribute('aria-expanded', 'false'); } }
617
+ function msPop(anchor, r, ids, sheet) {
618
+ const was = msEl && msEl.__a === anchor; msClose(); if (was || !r) return;
619
+ const today = M.today ? String(M.today).slice(0, 10) : new Date().toISOString().slice(0, 10);
620
+ const L = (r.milestones || []).filter((m) => !ids || ids.includes(m.id));
621
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], md = (iso) => MON[+iso.slice(5, 7) - 1] + ' ' + +iso.slice(8, 10);
622
+ const row = (m) => { const late = !m.done && m.date < today;
623
+ return `<button type="button" role="menuitem" class="o" data-ms-open="${esc(m.id)}"><i class="tg-tm-i${m.done ? ' dn' : late ? ' late' : ''}" aria-hidden="true"></i><span>${esc(m.name)}</span><span class="k${late ? ' late' : ''}">${esc(md(m.date))}</span></button>`; };
624
+ // the sheet adds each gap and each skipped stage, in date order with the milestones (batch 11 item 13, XgapA3Phone): words only, no press
625
+ const ymd = (d) => d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
626
+ const extra = !sheet ? [] : plainGaps(r).map(([a, b]) => ({ at: ymd(a), html: `<div class="o i" role="menuitem" aria-disabled="true"><i class="tg-ng-i" aria-hidden="true"></i><span>${esc(gapWords(a, b, new Date(today + 'T00:00')).map((w) => w.replace(/, .* · /, ' · ')).join(' · '))}</span><span class="k">${esc(md(ymd(a)) + ' – ' + md(ymd(b)))}</span></div>` }))
627
+ .concat(skipsOf(r).flatMap((k) => k.items.map((x) => ({ at: ymd(k.lo), html: `<div class="o i" role="menuitem" aria-disabled="true"><i class="tg-sk-i" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M6 7l5 5-5 5M13 7l5 5-5 5"/></svg></i><span>${esc(x.name + ' skipped')}${x.why ? `<small>${esc(x.why)}</small>` : ''}</span></div>` }))));
628
+ const items = L.map((m) => ({ at: m.date, html: row(m) })).concat(extra).sort((a, b) => (a.at < b.at ? -1 : a.at > b.at ? 1 : 0));
629
+ const el = document.createElement('div');
630
+ el.className = 'tg-msp' + (sheet ? ' sh' : ''); el.setAttribute('role', 'menu'); el.setAttribute('aria-label', (sheet ? '' : 'Milestones of ') + r.title); el.dataset.escLayer = '';
631
+ el.innerHTML = (sheet ? `<i class="gr" aria-hidden="true"></i><b class="h">${esc(r.title)}</b>` : '') + items.map((x) => x.html).join('');
632
+ document.body.appendChild(el); el.__a = anchor; msEl = el; anchor.setAttribute('aria-expanded', 'true');
633
+ if (!sheet) { const b = anchor.getBoundingClientRect(), w = el.offsetWidth; el.style.left = Math.max(8, Math.min(b.left + b.width / 2 - w / 2, innerWidth - w - 8)) + 'px'; el.style.top = b.bottom + 8 + 'px'; }
634
+ el.onclick = (e) => {
635
+ const o = e.target.closest('[data-ms-open]'); if (!o) return;
636
+ const id = o.dataset.msOpen, m = L.find((x) => x.id === id); msClose();
637
+ if (m && m.jira) { const k = ((r.track && r.track.tickets) || []).find((x) => x.key === id); if (k) BI.openTicket(r, k, anchor); else openIni(r, anchor); return; }
638
+ const k = (r.tasks || []).find((x) => x.uid === id); if (k) openTask(r, k); else openIni(r, anchor);
639
+ };
640
+ const f = el.querySelector('button'); if (f) f.focus({ preventScroll: true });
641
+ }
642
+ document.addEventListener('pointerdown', (e) => { if (msEl && !msEl.contains(e.target) && !(msEl.__a && msEl.__a.contains(e.target))) msClose(); }, true);
643
+ document.addEventListener('keydown', (e) => { if (msEl && e.key === 'Escape') { e.stopPropagation(); const a = msEl.__a; msClose(); if (a && a.focus) a.focus(); } }, true);
644
+ addEventListener('resize', () => msClose());
645
+ /** A gap's card (batch 11 item 13; XgapAHard 2): its words under it; while part of it is ahead, + opens New task with those dates filled in. */
646
+ function gapPop(anchor, r) {
647
+ const was = msEl && msEl.__a === anchor; msClose(); if (was || !r) return;
648
+ const today = M.today ? String(M.today).slice(0, 10) : new Date().toISOString().slice(0, 10);
649
+ const a = anchor.dataset.from, b = anchor.dataset.to, d = (v) => new Date(v + 'T00:00');
650
+ const lines = gapWords(d(a), d(b), d(today)), sk = skipsOf(r).filter((k) => { const lo = k.lo < k.hi ? k.lo : k.hi, hi = k.lo < k.hi ? k.hi : k.lo; return d(a) <= hi && d(b) >= lo; });
651
+ // the gap's empty days ahead: from the day after the work before it (or today) to the day before the work after it
652
+ const ymd = (x) => x.getFullYear() + '-' + String(x.getMonth() + 1).padStart(2, '0') + '-' + String(x.getDate()).padStart(2, '0');
653
+ const plus = (v, n) => { const x = d(v); x.setDate(x.getDate() + n); return ymd(x); };
654
+ const first = plus(a, 1), start = first > today ? first : today, due = plus(b, -1);
655
+ const el = document.createElement('div');
656
+ el.className = 'tg-msp tg-gpc'; el.setAttribute('role', 'dialog'); el.setAttribute('aria-label', lines[0]); el.dataset.escLayer = '';
657
+ el.innerHTML = `<div class="w">${lines.map((t, i) => `<p class="${i ? 's' : ''}">${esc(t)}</p>`).join('')}${sk.map((k) => `<p class="s">${esc(skipWords(k.items))}</p>`).join('')}</div>`
658
+ + (anchor.dataset.ahead ? `<button type="button" class="gp-add" aria-label="${esc('New task, ' + md(d(start)) + ' to ' + md(d(due)))}" title="New task">${'<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 5v14M5 12h14"/></svg>'}</button>` : '');
659
+ document.body.appendChild(el); el.__a = anchor; msEl = el; anchor.setAttribute('aria-expanded', 'true');
660
+ const bx = anchor.getBoundingClientRect(), w = el.offsetWidth; el.style.left = Math.max(8, Math.min(bx.left + bx.width / 2 - w / 2, innerWidth - w - 8)) + 'px'; el.style.top = bx.bottom + 6 + 'px';
661
+ const add = el.querySelector('.gp-add');
662
+ if (add) { add.onclick = () => { msClose(); BI.openIni(r, anchor, { addTo: '', addDates: { start, due } }); }; add.focus({ preventScroll: true }); }
663
+ }
664
+
581
665
  /** The Viewer shows an initiative of this board: its row is marked. */
582
666
  function iniShown(key) {
583
667
  peek = { kind: 'ini', key };
@@ -588,14 +672,14 @@ function iniHidden() {
588
672
  if (!peek || peek.kind !== 'ini') return;
589
673
  peek = null; $$('#ibBody .sel').forEach((x) => x.classList.remove('sel'));
590
674
  }
591
- /** A linked document opens in the Viewer: GET /api/doc, shown as its text. */
675
+ /** A linked document opens in the Viewer: GET /api/doc, shown as its text, and drawn again when the file changes (pm/doc-follow.js). */
592
676
  document.addEventListener('click', (e) => {
593
677
  const d = e.target.closest('[data-doc]'); if (!d || !M) return;
594
678
  const path = d.dataset.doc, ws = M.board.ws || '', inVw = !!d.closest('#czViewer');
595
679
  viewerOpen({ kind: 'Document', title: path.split('/').pop(), icon: 'doc', id: 'doc:' + path, back: inVw, render: async (body) => {
596
680
  body.innerHTML = '<p class="bd-amut">Reading the document…</p>';
597
- let text = null; try { const res = await fetch('/api/doc?ws=' + encodeURIComponent(ws) + '&path=' + encodeURIComponent(path), { credentials: 'same-origin' }); text = res.ok ? await res.text() : null; } catch { text = null; }
598
- body.innerHTML = text == null ? `<p class="bd-amut">${esc(path)} could not be read.</p>` : `<p class="bd-amut">${esc(path)}</p><pre class="bd-doc">${esc(text)}</pre>`;
681
+ await followDoc({ ws, path, alive: () => body.isConnected && !!viewerCur() && viewerCur().id === 'doc:' + path,
682
+ onText: (text) => { body.innerHTML = text == null ? `<p class="bd-amut">${esc(path)} could not be read.</p>` : `<p class="bd-amut">${esc(path)}</p><pre class="bd-doc">${esc(text)}</pre>`; } });
599
683
  } });
600
684
  });
601
685
  /* ── the tools the Agreed design draws but has no frame for: plain versions with a "Waiting for design" tag (pm/bd-acts.js) ─────────── */
@@ -745,18 +829,20 @@ async function readBoard(q) {
745
829
  async function readAll(q) {
746
830
  const h = await readBoard(q);
747
831
  if (!h.r || !h.r.ok || h.r.state === 'reading') return h;
748
- const home = h.r.model, list = (home.board.switcher || []).filter((b) => !(b.ws === home.board.ws && b.id === home.board.id));
832
+ // several picked (?pick=): only those boards, the first one read first
833
+ const home = h.r.model, list = (home.board.switcher || []).filter((b) => !(b.ws === home.board.ws && b.id === home.board.id) && (PICK.length < 2 || PICK.includes(b.ws + '|' + b.id)));
749
834
  const got = await Promise.all(list.map((b) => readBoard('ws=' + encodeURIComponent(b.ws) + '&board=' + encodeURIComponent(b.id))));
750
835
  if (got.some((g) => g.r && g.r.state === 'reading')) return { r: { state: 'reading' }, status: 200 };
751
836
  const B = [{ ws: home.board.ws || '', id: home.board.id, name: home.board.name, model: home }];
752
837
  const lost = [];
753
838
  got.forEach((g, i) => { if (g.r && g.r.ok && g.r.model) B.push({ ...list[i], model: g.r.model }); else lost.push(list[i].name + ' board'); });
754
839
  const model = PG.mergeBoards(B);
840
+ if (PICK.length > 1 && B.length < (home.board.switcher || []).length) model.board.name = B.map((b) => model.board.products.find((p) => p.ws === b.ws && p.id === b.id)).filter(Boolean).map((p) => p.name).join(', ');
755
841
  if (lost.length) { model.header.missing = [...model.header.missing, ...lost]; model.header.text += (/not read: /.test(model.header.text) ? ', ' : ' · not read: ') + lost.join(', '); }
756
842
  return { r: { ok: true, model, stale: got.some((g) => g.r && g.r.stale) || h.r.stale }, status: 200 };
757
843
  }
758
844
  async function load() {
759
- const p = new URLSearchParams(location.search), q = [p.get('ws') ? 'ws=' + encodeURIComponent(p.get('ws')) : '', p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
845
+ const p = new URLSearchParams(location.search), [pw, pb] = PICK.length > 1 ? PICK[0].split('|') : [p.get('ws'), p.get('board')], q = [pw ? 'ws=' + encodeURIComponent(pw) : '', pb ? 'board=' + encodeURIComponent(pb) : ''].filter(Boolean).join('&');
760
846
  const { r, status } = ALL ? await readAll(q) : await readBoard(q);
761
847
  clearInterval(readTimer);
762
848
  if (r && r.state === 'reading') {
@@ -795,13 +881,16 @@ async function setTask(r, uid, state) {
795
881
  say(state + ': ' + (k ? k.title : uid) + '.', undo ? async () => { const u = await pmPost('/api/boards/tasks/state', { ...body, state: k.status }).catch(() => null); say(u && u.ok ? 'Back to ' + k.status + '.' : (u && u.error) || 'The undo did not land.'); load(); } : undefined);
796
882
  load();
797
883
  }
798
- /** A task's start and due from the panel's Tasks (the date press, a Timeline drag): POST /api/boards/tasks/edit; Undo puts the old days back. */
884
+ /** A task's start and due from the panel's Tasks (the date press, a Timeline drag), or its ◇ milestone flag (batch 11 item 3): POST
885
+ * /api/boards/tasks/edit; Undo puts the old days or the old flag back. */
799
886
  async function setDates(r, uid, patch) {
800
887
  const k = (r.tasks || []).find((x) => x.uid === uid), body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id, task: uid };
801
888
  const res = await pmPost('/api/boards/tasks/edit', { ...body, ...patch }).catch(() => null);
802
889
  if (!res || res.ok === false) { say((res && res.error) || 'Nothing was changed.'); return; }
803
- const back = {}; for (const f of Object.keys(patch)) back[f] = k ? (f === 'due' ? k.end : k[f]) || '' : '';
804
- say('Dates saved' + (k ? ': ' + k.title : '') + '.', k ? async () => { const u = await pmPost('/api/boards/tasks/edit', { ...body, ...back }).catch(() => null); say(u && u.ok !== false ? 'Dates put back.' : (u && u.error) || 'The undo did not land.'); load(); } : undefined);
890
+ const ms = 'milestone' in patch;
891
+ const back = {}; for (const f of Object.keys(patch)) back[f] = f === 'milestone' ? (res.from && 'milestone' in res.from ? !!res.from.milestone : !patch.milestone) : k ? (f === 'due' ? k.end : k[f]) || '' : '';
892
+ const words = ms ? (patch.milestone ? 'Milestone' : 'Not a milestone') : 'Dates saved';
893
+ say(words + (k ? ': ' + k.title : '') + '.', k || ms ? async () => { const u = await pmPost('/api/boards/tasks/edit', { ...body, ...back }).catch(() => null); say(u && u.ok !== false ? (ms ? 'Put back.' : 'Dates put back.') : (u && u.error) || 'The undo did not land.'); load(); } : undefined);
805
894
  load();
806
895
  }
807
896
  /** A task's title on the initiative view: the one task editor (task-card.js through home-task.js), as Home opens it; ← is the initiative. */
@@ -820,11 +909,13 @@ function openTask(r, k) {
820
909
  }
821
910
  /** A new task from the initiative view's + (the same box Home's page draws): POST /api/boards/tasks/add. → true when it was added.
822
911
  * section: the stage it finishes (the Next cell's +, "Add what finishes <stage>"): the task is placed under it (POST /api/boards/tasks/edit). */
823
- async function addTask(r, title, section) {
912
+ async function addTask(r, title, section, dates) {
824
913
  const body = { ws: r.ws || M.board.ws, board: r.boardId || M.board.id };
825
914
  const res = await pmPost('/api/boards/tasks/add', { ...body, initiative: r.id, title }).catch(() => null);
826
915
  if (!res || res.ok === false) { say((res && res.error) || 'The task was not added.'); return false; }
827
916
  const uid = res.item && res.item.uid;
917
+ // dates: a gap's + (batch 11 item 13) fills the task's start and due with the gap's days ahead
918
+ if (dates && uid) { const s1 = await pmPost('/api/boards/tasks/edit', { ...body, task: uid, start: dates.start, due: dates.due }).catch(() => null); if (!s1 || s1.ok === false) { say('Task added, but not its dates: ' + ((s1 && s1.error) || 'the server did not say why') + '.'); load(); return true; } }
828
919
  if (section && uid) { const s2 = await pmPost('/api/boards/tasks/edit', { ...body, task: uid, section }).catch(() => null); if (!s2 || s2.ok === false) { say('Task added, but not under its stage: ' + ((s2 && s2.error) || 'the server did not say why') + '.'); load(); return true; } }
829
920
  say('Task added.'); load();
830
921
  return true;
@@ -853,7 +944,7 @@ Acts.init({ M: () => M, wf: wfState, load, say, panel: actsPanel, close: closePa
853
944
  BI.mount({ M: () => M, statusOf, dayTitle, usual: usualOf, fmt, md, ago, segHtml, barHtml: V.barHtml, grill: (id) => GR[id], rowOf, pageHref, askHref, refreshJira: () => refreshJira(), viewDoc,
854
945
  send: (r) => import('./tk-send.js').then((S) => S.openSend({ ws: r.ws || M.board.ws || null, board: r.boardId || M.board.id, initiative: r.id, toast: say })),
855
946
  acts: (r, b) => Acts.open.row(r, b), grillOpen: (r, b) => Asks.openGrill(r.id, r.title, (r.track && r.track.label) || 'Triage', false, b), onShow: iniShown, onHide: iniHidden,
856
- programOf: (r) => programOf(PGS, r.ws || M.board.ws || '', r.id), openProgram: (id, b) => PG.openProgram(id, b), rename: renameIni, setTask, setDates, addTask, openTask, turnProgram });
947
+ programOf: (r) => programOf(PGS, r.ws || M.board.ws || '', r.id), openProgram: (id, b) => PG.openProgram(id, b), reload: load, toast: say, rename: renameIni, setTask, setDates, addTask, openTask, turnProgram, moveItems });
857
948
  /** Tap the title to rename (canvas RnAIni): the list, the Timeline and the panel show the new name at once; Undo is the same press.
858
949
  * The Jira box opens Home's chat about it with the request typed, for the PM to send (PMOS holds no Jira credential, D53). */
859
950
  // a name the PM just saved holds over a read that predates it (the board derives off the request path) until a read says it too
@@ -36,7 +36,10 @@
36
36
  * wordsOf(md, fallback) the document as { title, sections: [{ h, lines }] } (pure)
37
37
  * slideHtml(lines) a section's lines as html (pure) · splitRender(html) · slideCard(s, mini) · fit(root) · schedLabel(setup) (pure)
38
38
  *
39
- * READS: GET /api/doc, /api/report-design/cycle and cycle-html (a cycle drawn to its saved design), /api/report-setups (schedule and audience),
39
+ * The open report follows its file (PM, 2026-10-26: "When chat make update on the file that being shown on the current viewer, I should not need to
40
+ * refresh page"): every few seconds GET /api/doc-sheet/stamp gives the text's hash, and a change is read and drawn again. Not while editing or while a
41
+ * popover is open; the next check after that catches it.
42
+ * READS: GET /api/doc, /api/doc-sheet/stamp, /api/report-design/cycle and cycle-html (a cycle drawn to its saved design), /api/report-setups (schedule and audience),
40
43
  * /api/viewer-report/checks, /api/report-structure and /api/report-design (the Brief), /api/report-confirm, /api/insights-premium (Live page),
41
44
  * /api/shares, /api/shares/password, /api/report-export (the files). Every render is HTML the server sanitized, shown in a frame with an empty
42
45
  * sandbox: nothing in it runs.
@@ -870,8 +873,24 @@ export async function openReport(row, hand = {}) {
870
873
  readBrief(); // the Brief tab's count shows at once
871
874
  if (vCur() && vCur().id === me.vid && (vCur().title !== me.name || me.audience)) { me.reopen = true; vOpen(head()); me.reopen = false; } // the name and audience are known now
872
875
  draw();
876
+ watchFile(me);
873
877
  return me;
874
878
  }
879
+ const CHECK_MS = 2500;
880
+ /** Read the report again when its file changed on disk (a chat or a draft run wrote it). Stops when another report opens or the panel closes. */
881
+ async function watchFile(me) {
882
+ const stamp = async () => { const j = await Promise.resolve(pmGet('/api/doc-sheet/stamp?' + q({ ws: me.ws, path: me.row.path }))).catch(() => null); return j && j.ok ? j.hash : null; };
883
+ let seen = await stamp();
884
+ while (R === me) {
885
+ await new Promise((ok) => setTimeout(ok, CHECK_MS));
886
+ if (R !== me) return;
887
+ if (document.hidden || me.edit || me.busy || me.pop) continue;
888
+ const h = await stamp();
889
+ if (R !== me || !h) continue;
890
+ if (seen && h !== seen) { await reread(); if (R === me && !me.edit && !me.pop) draw(); }
891
+ seen = h;
892
+ }
893
+ }
875
894
 
876
895
  /** The window.czViews entry: a report path (reports/<cadence>/<date>.md) or a Reports row. o = { ws, name, cycles, onIssue, onChange } */
877
896
  export async function openReportView(ref, o = {}) {
@@ -826,15 +826,30 @@ export function crumbHtml(o) {
826
826
  : `<nav class="crumb" aria-label="Where you are">${o.page ? `<span class="crpg">${esc(o.page)}</span>` : ''}<button id="crBoard" aria-current="page" disabled>${esc(o.board)}</button>${chev('crSw', 'Switch board', o.boards && o.boards.length > 1)}${menu}</nav>`;
827
827
  return `<div class="where">${left}</div>`;
828
828
  }
829
- /** o: { boards: [{ws,id,name}], board: id, siblings: [{id,title}], ini: id, goBoard(ws, id), goIni(id) }. Escape and a click outside close the menu; the arrows move in it. */
829
+ /** o: { boards: [{ws,id,name}], board: id, siblings: [{id,title}], ini: id, goBoard(ws, id), goIni(id) }. Escape and a click outside close the menu; the arrows move in it.
830
+ * With o.picked (['ws|id', …]) and o.goPicked(keys) the board menu ticks several (the Board's products, batch 11 item 7): a press ticks or unticks
831
+ * and the menu stays open; the board with id '*' (All products) ticks every one; the last tick stays; the pick goes when the menu closes. */
830
832
  export function wireCrumb(o) {
831
833
  const menu = $('#crMenu'); if (!menu) return;
832
- const close = () => { menu.hidden = true; $$('#crSw,#crSw2').forEach((b) => b.setAttribute('aria-expanded', 'false')); };
834
+ const multi = !!(o.picked && o.goPicked), one = (o.boards || []).filter((b) => b.id !== '*'), kOf = (b) => b.ws + '|' + b.id;
835
+ let tick = null; // the ticks while the menu is open (multi): a Set of 'ws|id'
836
+ const close = () => {
837
+ const was = !menu.hidden && menu.dataset.k === 'b' && tick;
838
+ menu.hidden = true; $$('#crSw,#crSw2').forEach((b) => b.setAttribute('aria-expanded', 'false'));
839
+ if (was) { const k = one.map(kOf).filter((x) => tick.has(x)); tick = null; if (k.join(',') !== one.map(kOf).filter((x) => o.picked.includes(x)).join(',')) o.goPicked(k); }
840
+ };
841
+ const TK = '<i class="crtk" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg></i>', PART = '<i class="crtk part" aria-hidden="true"><svg viewBox="0 0 24 24"><path d="M7 12h10"/></svg></i>';
842
+ const ticks = () => (o.boards || []).map((b) => {
843
+ if (b.id === '*') { const n = one.filter((x) => tick.has(kOf(x))).length, st = n === one.length ? 'true' : 'mixed'; return `<button role="menuitemcheckbox" data-sw="*|*" aria-checked="${st}">${esc(b.name)}${st === 'true' ? TK : PART}</button><span class="crsep" role="separator"></span>`; }
844
+ const on = tick.has(kOf(b));
845
+ return `<button role="menuitemcheckbox" data-sw="${esc(kOf(b))}" aria-checked="${on}">${esc(b.name)}${on ? TK : '<i class="crtk"></i>'}</button>`;
846
+ }).join('');
833
847
  const open = (kind, btn) => {
834
848
  if (!menu.hidden && menu.dataset.k === kind) { close(); return; }
835
849
  close(); menu.dataset.k = kind;
850
+ if (kind === 'b' && multi) tick = new Set(o.picked);
836
851
  menu.innerHTML = kind === 'b'
837
- ? (o.boards || []).map((b) => `<button role="menuitem" data-sw="${esc(b.ws + '|' + b.id)}"${b.id === o.board ? ' aria-current="true"' : ''}>${esc(b.name)}</button>`).join('')
852
+ ? multi ? ticks() : (o.boards || []).map((b) => `<button role="menuitem" data-sw="${esc(b.ws + '|' + b.id)}"${b.id === o.board ? ' aria-current="true"' : ''}>${esc(b.name)}</button>`).join('')
838
853
  : (o.siblings || []).map((s) => `<button role="menuitem" data-swi="${esc(s.id)}"${s.id === o.ini ? ' aria-current="true"' : ''}>${esc(s.title)}</button>`).join('');
839
854
  menu.hidden = false; btn.setAttribute('aria-expanded', 'true'); const f = $('button', menu); if (f) f.focus();
840
855
  };
@@ -843,7 +858,17 @@ export function wireCrumb(o) {
843
858
  if (b2) b2.onclick = (e) => { e.stopPropagation(); open('i', b2); };
844
859
  $('#crBoard').onclick = () => { if (o.ini && o.goBoard) { const b = (o.boards || []).find((x) => x.id === o.board); o.goBoard(b ? b.ws : null, o.board); } };
845
860
  menu.onclick = (e) => {
846
- const k = e.target.closest('[data-sw]'); if (k && o.goBoard) { const [ws, id] = k.dataset.sw.split('|'); close(); o.goBoard(ws, id); return; }
861
+ const k = e.target.closest('[data-sw]');
862
+ if (k && tick) {
863
+ // a tick: All products ticks every product; a product ticks or unticks, the last one stays ticked; the menu stays open
864
+ e.stopPropagation();
865
+ if (k.dataset.sw === '*|*') one.forEach((b) => tick.add(kOf(b)));
866
+ else if (!tick.has(k.dataset.sw)) tick.add(k.dataset.sw);
867
+ else if (tick.size > 1) tick.delete(k.dataset.sw);
868
+ const at = k.dataset.sw; menu.innerHTML = ticks(); const f = menu.querySelector(`[data-sw="${CSS.escape(at)}"]`); if (f) f.focus();
869
+ return;
870
+ }
871
+ if (k && o.goBoard) { const [ws, id] = k.dataset.sw.split('|'); close(); o.goBoard(ws, id); return; }
847
872
  const q = e.target.closest('[data-swi]'); if (q && o.goIni) { close(); o.goIni(q.dataset.swi); }
848
873
  };
849
874
  document.addEventListener('click', (e) => { if (!e.target.closest('#crSw,#crSw2,#crMenu')) close(); });
@@ -3,7 +3,11 @@
3
3
  * Undo all. Built on the viewer frame (premium-viewer.js) and the existing /api/doc-sheet routes: log and at to read, edit to save, proposals, accept and
4
4
  * reject for an agent's edit, ask to request one. Nothing here is stored anywhere else. The pure half is premium-vw-doc-model.js.
5
5
  * ctx.host (an element) draws the page editor inside it instead of a viewer tab (the report dialog's Edit, PM 2026-10-22: one place to edit a
6
- * report). It opens in Edit, offers only Edit and Markdown, and Cancel or a save calls ctx.onClose. No Health, Links, Copies, extras or Ask. */
6
+ * report). It opens in Edit, offers only Edit and Markdown, and Cancel or a save calls ctx.onClose. No Health, Links, Copies, extras or Ask.
7
+ * The page follows the file (PM, 2026-10-26: "When chat make update on the file that being shown on the current viewer, I should not need to refresh
8
+ * page. I should not need to manually commit as well"): every few seconds GET /api/doc-sheet/stamp says which workspace holds the live copy (an
9
+ * initiative's own worktree, where its chat writes and does not commit, when ctx.ini names it) and the text's hash. A change is read and drawn again.
10
+ * What the PM typed and did not save is never replaced: the page keeps it and says the file changed, as a save would (409). */
7
11
  import { pmPost } from './http.js';
8
12
  import { vwOpen, vwStyle, vwConfirm } from './premium-viewer.js';
9
13
  import { $, $$, esc, toast, AI, CHECK } from './premium-shell.js';
@@ -73,11 +77,14 @@ const BLOCKS = [
73
77
  { k: 'table', t: 'Table', ic: 'tbl' }, { k: 'info', t: 'Info panel', ic: 'info' }, { k: 'note', t: 'Note panel', ic: 'info' }, { k: 'warning', t: 'Warning panel', ic: 'info' }, { k: 'success', t: 'Success panel', ic: 'info' }, { k: 'decision', t: 'Decision', ic: 'info' },
74
78
  { k: 'status', t: 'Status label', ic: 'dot' }, { k: 'code', t: 'Code block', ic: 'code', kbd: '```' }, { k: 'expand', t: 'Expand', ic: 'chev' }, { k: 'hr', t: 'Divider', g: '—', kbd: '---' },
75
79
  ];
80
+ const CHECK_MS = 2500; // how often an open page asks whether its file changed (premium-vw-file.js checks a chat file as often)
81
+ const STALE = 'The chat changed this file while you were editing. Your edit is kept and is not saved. Cancel shows the new text.';
76
82
  const STATUSES = ['To do', 'In progress', 'In review', 'Done', 'Blocked'];
77
83
  const tb = (c, label, icon) => `<button type="button" class="vwtb" data-c="${c}" title="${label}" aria-label="${label}">${IC[icon] || icon}</button>`;
78
84
 
79
- /** Open a markdown file as a page in the viewer. `d` is { path, title }; `ctx` gives { ws(), onWrite() } — onWrite runs after the file or a proposal changed,
80
- * so the page that opened it can read again. */
85
+ /** Open a markdown file as a page in the viewer. `d` is { path, title }; `ctx` gives { ws(), ini?, onWrite() } — onWrite runs after the file or a proposal
86
+ * changed, so the page that opened it can read again. ini (a string or a function) is the initiative the document is opened from: its worktree's copy is
87
+ * the one shown. */
81
88
  export function openDocPage(d, ctx = {}) {
82
89
  if (!d || !d.path) return null;
83
90
  vwStyle('doc');
@@ -89,17 +96,24 @@ export function openDocPage(d, ctx = {}) {
89
96
  const OPEN = new Map();
90
97
  function makePage(d, ctx) {
91
98
  const id = 'doc:' + d.path;
92
- const ws = () => (ctx.ws ? ctx.ws() : '') || '';
99
+ const baseWs = () => (ctx.ws ? ctx.ws() : '') || '';
100
+ const iniOf = () => String((typeof ctx.ini === 'function' ? ctx.ini() : ctx.ini) || '');
101
+ // live: the workspace GET /api/doc-sheet/stamp named as holding the live copy; every read and write goes there
102
+ const ws = () => P.live || baseWs();
93
103
  const wsq = () => (ws() ? '&ws=' + encodeURIComponent(ws()) : '');
94
104
  // work: the text being edited and not saved yet (null when nothing is); base: the page serialized as drawn, so a save writes back only what was typed
95
- const P = { d, more: null, health: null, lib: undefined, copies: null, cpUrl: '', cpMsg: '', checkRun: null, text: null, log: null, props: null, kept: null, mode: 'read', busy: false, msg: '', why: '', err: null, base: null, work: null, ask: null, askOpen: false, askText: '', pop: null };
105
+ const P = { d, more: null, health: null, lib: undefined, copies: null, cpUrl: '', cpMsg: '', checkRun: null, text: null, log: null, props: null, kept: null, mode: 'read', busy: false, msg: '', why: '', err: null, base: null, work: null, ask: null, askOpen: false, askText: '', pop: null, live: null, stale: false, timer: null };
96
106
  let el = null;
97
107
  const v = () => ((P.log && P.log.revisions) || []).length;
98
108
  const openProp = () => (P.props || []).filter((p) => p.state === 'proposed').slice(-1)[0] || null;
99
109
 
100
- async function load() {
110
+ const stampOf = () => getJson('/api/doc-sheet/stamp?path=' + encodeURIComponent(d.path) + (baseWs() ? '&ws=' + encodeURIComponent(baseWs()) : '') + (iniOf() ? '&ini=' + encodeURIComponent(iniOf()) : ''));
111
+ const shownHash = () => { const r = (P.log && P.log.revisions) || []; return r.length ? r[r.length - 1].after_hash : null; };
112
+ async function load(stamp) {
101
113
  const p = encodeURIComponent(d.path);
102
- P.err = null;
114
+ const s = stamp || (ctx.host ? null : await stampOf());
115
+ if (s && s.ok) P.live = s.ws || null;
116
+ P.err = null; P.stale = false;
103
117
  const [lg, pr] = await Promise.all([getJson('/api/doc-sheet/log?path=' + p + wsq()), getJson('/api/doc-sheet/proposals?path=' + p + wsq())]);
104
118
  P.log = lg && lg.ok ? lg : null;
105
119
  P.props = pr && pr.ok ? pr.proposals || [] : [];
@@ -259,7 +273,7 @@ function makePage(d, ctx) {
259
273
  const o = p ? overlay(P.text, p, P.kept) : null;
260
274
  if (P.mode === 'md') return toolsHtml(p) + `<textarea id="vwMd" class="vwmd" spellcheck="false" aria-label="The file as Markdown">${esc(P.work != null ? P.work : P.text)}</textarea>` + saveRow();
261
275
  const body = o ? overlayBody(h, o) : readBody(h, P.mode === 'edit' && P.work != null ? P.work : P.text);
262
- const unsaved = P.mode === 'read' && P.work != null && P.work !== P.text ? '<p class="vwmut vwline" role="status">You have changes that are not saved yet. Edit shows them again.</p>' : '';
276
+ const unsaved = P.mode === 'read' && P.work != null && P.work !== P.text ? `<p class="vwmut vwline" role="status">You have changes that are not saved yet. Edit shows them again.${P.stale ? ' The chat changed the file since. Cancel there shows the new text.' : ''}</p>` : '';
263
277
  return toolsHtml(p) + (P.mode === 'read' ? moreBar() : '') + unsaved + agentBar(p, o) + (P.mode === 'edit' ? editBar() : '')
264
278
  + `<article class="cf${P.mode === 'edit' ? ' editing' : ''}">${headHtml(h)}<div class="cfb"${P.mode === 'edit' ? ' contenteditable="true" spellcheck="true" aria-label="The page" role="textbox" aria-multiline="true"' : ''}>${body || '<p class="vwmut">The file has no text yet.</p>'}</div>`
265
279
  + `<footer class="cff"><span>${v() ? 'v' + v() + (p ? ' · edited by the agent, not kept yet' : '') : ''}</span><span class="gap"></span><code>${esc(d.path)}</code></footer></article>`
@@ -373,7 +387,7 @@ function makePage(d, ctx) {
373
387
  const p = openProp();
374
388
  if (k === 'mode') { if (P.mode === arg) return; if (P.mode !== 'read') { const t = current(); P.work = t !== P.text ? t : null; } P.mode = arg; P.msg = ''; P.base = null; draw(); return; }
375
389
  if (k === 'more') { P.more = P.more === arg ? null : arg; draw(); if (P.more === 'links' && P.lib === undefined) loadLib(); return; }
376
- if (k === 'open') { openDocPage({ path: arg, title: String(arg).split('/').pop() }, { ws: ctx.ws }); return; }
390
+ if (k === 'open') { openDocPage({ path: arg, title: String(arg).split('/').pop() }, { ws: ctx.ws, ini: ctx.ini }); return; }
377
391
  if (k === 'cplink') {
378
392
  const t = String(($('#vwCpUrl', el) || {}).value || '').trim(), kind = copyKindOf(t); P.cpUrl = t;
379
393
  if (!kind) { P.cpMsg = 'Paste a Confluence page or Google Doc link.'; draw(); const f = $('#vwCpUrl', el); if (f) f.focus(); return; }
@@ -459,6 +473,26 @@ function makePage(d, ctx) {
459
473
  await load(); if (ctx.onWrite) ctx.onWrite();
460
474
  }
461
475
  }
476
+ /** The file changed on disk (a chat wrote it) or moved to the initiative's worktree: read and draw it again, unless the PM has typed something not
477
+ * saved. Then the edit stays and the page says the file changed; a save of it would be refused as stale (409). */
478
+ async function check() {
479
+ P.timer = null;
480
+ if (!el || !el.isConnected) return; // the tab closed: stop checking
481
+ if (!document.hidden && !P.busy && P.text != null) {
482
+ const s = await stampOf();
483
+ if (!el || !el.isConnected) return;
484
+ const moved = s && s.ok && (s.ws || null) !== (P.live || null);
485
+ if (s && s.ok && !P.busy && (moved || s.hash !== shownHash())) {
486
+ if (P.mode === 'read' && P.work == null) await load(s);
487
+ else if (!P.stale) {
488
+ P.stale = true;
489
+ if (P.mode === 'read') draw();
490
+ else { P.msg = STALE; const e = $('#vwErr', el); if (e) e.textContent = STALE; } // no redraw while editing: the caret and the typing stay
491
+ }
492
+ }
493
+ }
494
+ if (el && el.isConnected && !P.timer) P.timer = setTimeout(check, CHECK_MS);
495
+ }
462
496
  async function pollAsk(id) {
463
497
  for (let i = 0; i < 400 && el && el.isConnected; i++) {
464
498
  await new Promise((r) => setTimeout(r, 2000));
@@ -530,11 +564,12 @@ function makePage(d, ctx) {
530
564
 
531
565
  if (ctx.host) { P.mode = 'edit'; el = ctx.host; el.innerHTML = '<p class="vwempty">Reading the file.</p>'; if (!WIRED.has(el)) { WIRED.add(el); wire(el); } load(); return el; }
532
566
  const spec = { id, title: d.title || String(d.path).split('/').pop(), icon: 'doc', render(e) { el = e; draw(); }, wire(e) { if (WIRED.has(e)) return; WIRED.add(e); wire(e); } };
533
- const api = { show(c2) { if (!el || !el.isConnected) { OPEN.delete(id); return makePage(d, c2 || ctx); } if (c2) ctx = c2; el = vwOpen(spec) || el; if (P.mode === 'read') load(); return el; } };
567
+ const api = { show(c2) { if (!el || !el.isConnected) { OPEN.delete(id); return makePage(d, c2 || ctx); } if (c2) ctx = c2; el = vwOpen(spec) || el; if (P.mode === 'read' && P.work == null) load(); watch(); return el; } };
568
+ const watch = () => { if (!P.timer) P.timer = setTimeout(check, CHECK_MS); };
534
569
  OPEN.set(id, api);
535
570
  const pane = vwOpen(spec);
536
571
  if (pane) el = pane;
537
- load();
572
+ load().then(watch);
538
573
  return pane;
539
574
  }
540
575
  const WIRED = new WeakSet();