create-pmos 0.610.0 → 0.612.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 (164) hide show
  1. package/package.json +135 -27
  2. package/payload/KIT-VERSION +2 -2
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/payload/state/log.md +1 -1
  7. package/workspace/board-columns-test.js +2 -1
  8. package/workspace/board-deliveries-test.js +2 -1
  9. package/workspace/board-programs-test.js +7 -3
  10. package/workspace/board-publish-ui-test.js +2 -1
  11. package/workspace/board-shared-ui-test.js +2 -1
  12. package/workspace/board-workflows-test.js +2 -1
  13. package/workspace/briefing-premium-board-test.js +3 -2
  14. package/workspace/briefing-premium-calendar-2-test.js +3 -2
  15. package/workspace/briefing-premium-calendar-3-test.js +1 -1
  16. package/workspace/briefing-premium-calendar-test.js +1 -1
  17. package/workspace/briefing-premium-doc-edit-test.js +2 -1
  18. package/workspace/briefing-premium-insights-test.js +4 -3
  19. package/workspace/briefing-premium-test.js +3 -2
  20. package/workspace/calm-timeline-test.js +2 -1
  21. package/workspace/changelog.json +134 -0
  22. package/workspace/core-docs-workflow-test.js +2 -1
  23. package/workspace/ev-everywhere-test.js +3 -2
  24. package/workspace/guide/home.md +2 -2
  25. package/workspace/guide/index.md +4 -0
  26. package/workspace/guide/layout.md +97 -3
  27. package/workspace/guide/programs.md +16 -2
  28. package/workspace/guide/routine.md +65 -0
  29. package/workspace/guide/scheduled-tasks-and-cli.md +1 -1
  30. package/workspace/guide/settings-and-switches.md +2 -2
  31. package/workspace/impact-screens-test.js +3 -1
  32. package/workspace/ini-workflow-test.js +2 -1
  33. package/workspace/lib/board-premium.js +12 -4
  34. package/workspace/lib/classic-board.js +15 -0
  35. package/workspace/lib/cos-chat.js +1 -0
  36. package/workspace/lib/doc-library.js +43 -12
  37. package/workspace/lib/doc-path.js +30 -0
  38. package/workspace/lib/engine/boards.js +4 -2
  39. package/workspace/lib/events-place.js +368 -0
  40. package/workspace/lib/events-stated.js +129 -0
  41. package/workspace/lib/initiative-chat.js +1 -0
  42. package/workspace/lib/insights-premium.js +13 -1
  43. package/workspace/lib/library-find.js +162 -0
  44. package/workspace/lib/library-items.js +250 -0
  45. package/workspace/lib/notes.js +9 -1
  46. package/workspace/lib/plan-items.js +17 -3
  47. package/workspace/lib/route-modules.js +4 -0
  48. package/workspace/lib/routes-artefacts.js +5 -2
  49. package/workspace/lib/routes-boards.js +6 -2
  50. package/workspace/lib/routes-doc-sheet.js +1 -0
  51. package/workspace/lib/routes-events-place.js +203 -0
  52. package/workspace/lib/routes-library.js +155 -0
  53. package/workspace/lib/routes-pop-work.js +39 -0
  54. package/workspace/lib/routes-report-setups.js +32 -1
  55. package/workspace/lib/routes-today-log.js +48 -0
  56. package/workspace/lib/routine-reports.js +84 -0
  57. package/workspace/lib/status-when.js +36 -0
  58. package/workspace/lib/task-items.js +5 -3
  59. package/workspace/lib/today-log.js +131 -0
  60. package/workspace/live-pill-round-test.js +10 -7
  61. package/workspace/metric-drafts-ui-test.js +3 -1
  62. package/workspace/milestone-pins-test.js +2 -1
  63. package/workspace/milestone-suggest-test.js +3 -1
  64. package/workspace/package-lock.json +2 -2
  65. package/workspace/package.json +1 -1
  66. package/workspace/panels-test.js +2 -1
  67. package/workspace/premium-board-actions-test.js +3 -1
  68. package/workspace/premium-rec-tab-test.js +2 -1
  69. package/workspace/premium-vw-backlog-test.js +3 -1
  70. package/workspace/premium-vw-item-test.js +3 -1
  71. package/workspace/premium-vw-jira-test.js +3 -1
  72. package/workspace/premium-vw-meet-test.js +2 -1
  73. package/workspace/premium-vw-notes-test.js +3 -2
  74. package/workspace/product-lane-test.js +2 -1
  75. package/workspace/program-charter-test.js +3 -1
  76. package/workspace/program-leave-test.js +2 -1
  77. package/workspace/program-order-test.js +2 -1
  78. package/workspace/program-panel-test.js +3 -1
  79. package/workspace/public/pm/artefact-kind.js +87 -0
  80. package/workspace/public/pm/bd-ini-panel.js +77 -12
  81. package/workspace/public/pm/bd-prog-panel.js +55 -8
  82. package/workspace/public/pm/bd-span.js +5 -0
  83. package/workspace/public/pm/bd-work.css +192 -0
  84. package/workspace/public/pm/bd-work.js +483 -0
  85. package/workspace/public/pm/cozy-bar.css +11 -0
  86. package/workspace/public/pm/cozy-bar.js +99 -0
  87. package/workspace/public/pm/cozy-day-pick.css +27 -0
  88. package/workspace/public/pm/cozy-day-pick.js +97 -0
  89. package/workspace/public/pm/cozy-ev.css +2 -5
  90. package/workspace/public/pm/cozy-events-view.js +274 -0
  91. package/workspace/public/pm/cozy-events.css +179 -0
  92. package/workspace/public/pm/cozy-events.js +278 -0
  93. package/workspace/public/pm/cozy-evmodel.js +1 -1
  94. package/workspace/public/pm/cozy-goals.css +172 -0
  95. package/workspace/public/pm/cozy-library.css +125 -0
  96. package/workspace/public/pm/cozy-live-pill.js +1 -0
  97. package/workspace/public/pm/cozy-nav.js +6 -7
  98. package/workspace/public/pm/cozy-pick.css +3 -0
  99. package/workspace/public/pm/cozy-pop-work.css +224 -0
  100. package/workspace/public/pm/cozy-pop-work.js +668 -0
  101. package/workspace/public/pm/cozy-popup.css +11 -2
  102. package/workspace/public/pm/cozy-popup.js +67 -9
  103. package/workspace/public/pm/cozy-routine-job.js +203 -0
  104. package/workspace/public/pm/cozy-routine-model.js +219 -0
  105. package/workspace/public/pm/cozy-routine-pop.js +318 -0
  106. package/workspace/public/pm/cozy-routine.css +155 -0
  107. package/workspace/public/pm/cozy-routine.js +335 -0
  108. package/workspace/public/pm/cozy-schedwork.js +6 -5
  109. package/workspace/public/pm/cozy-settings.js +1 -5
  110. package/workspace/public/pm/cozy-status-when.js +48 -0
  111. package/workspace/public/pm/cozy-today-app.js +236 -0
  112. package/workspace/public/pm/cozy-today-model.js +176 -0
  113. package/workspace/public/pm/cozy-today-page.css +100 -0
  114. package/workspace/public/pm/cozy-today-view.js +76 -0
  115. package/workspace/public/pm/cozy-viewer.js +19 -8
  116. package/workspace/public/pm/cozy-vw-mtg.css +39 -0
  117. package/workspace/public/pm/goals-model.js +205 -0
  118. package/workspace/public/pm/goals-open.js +124 -0
  119. package/workspace/public/pm/home-app.js +18 -3
  120. package/workspace/public/pm/home-chat.js +4 -2
  121. package/workspace/public/pm/home-ini.js +43 -10
  122. package/workspace/public/pm/ini-edit.js +3 -1
  123. package/workspace/public/pm/ini-view-model.js +1 -1
  124. package/workspace/public/pm/library-model.js +197 -0
  125. package/workspace/public/pm/library-open.js +37 -0
  126. package/workspace/public/pm/page-chat.js +12 -2
  127. package/workspace/public/pm/pop-work-model.js +493 -0
  128. package/workspace/public/pm/premium-board.js +204 -17
  129. package/workspace/public/pm/premium-goals.js +213 -0
  130. package/workspace/public/pm/premium-library.js +436 -0
  131. package/workspace/public/pm/premium-shell.js +1 -1
  132. package/workspace/public/pm/premium-vw-mtg.js +79 -1
  133. package/workspace/public/pm/scope-chip.js +204 -0
  134. package/workspace/public/premium-board.html +1 -0
  135. package/workspace/public/premium-events.html +44 -0
  136. package/workspace/public/premium-goals.html +37 -0
  137. package/workspace/public/premium-library.html +39 -0
  138. package/workspace/public/premium-routine.html +33 -0
  139. package/workspace/public/today.html +50 -0
  140. package/workspace/ready-dash-ui-test.js +3 -1
  141. package/workspace/rename-test.js +2 -1
  142. package/workspace/run-tests.js +4 -1
  143. package/workspace/server.js +4 -2
  144. package/workspace/sort-order-test.js +2 -1
  145. package/workspace/split-merge-ui-test.js +3 -1
  146. package/workspace/stage-card-tasks-test.js +3 -1
  147. package/workspace/stage-card-test.js +2 -1
  148. package/workspace/task-delete-test.js +2 -1
  149. package/workspace/task-links-test.js +2 -1
  150. package/workspace/task-milestones-test.js +4 -2
  151. package/workspace/task-plans-test.js +3 -1
  152. package/workspace/task-press-test.js +3 -1
  153. package/workspace/task-views-test.js +3 -1
  154. package/workspace/test-lists/doc-path.json +9 -0
  155. package/workspace/test-lists/events-place.json +11 -0
  156. package/workspace/test-lists/goals-place.json +9 -0
  157. package/workspace/test-lists/library-place.json +9 -0
  158. package/workspace/test-lists/pop-work.json +9 -0
  159. package/workspace/test-lists/routine-place.json +9 -0
  160. package/workspace/test-lists/status-when.json +9 -0
  161. package/workspace/test-lists/today-log.json +9 -0
  162. package/workspace/test-lists/work-view.json +9 -0
  163. package/workspace/timeline-holds-test.js +3 -1
  164. package/workspace/tk-tasks-test.js +2 -1
@@ -0,0 +1,668 @@
1
+ /* pm/cozy-pop-work.js — what the popup shows for work (slice 3 of the six-place navigation; boards 3, 20, 21, 22, 25, 26, 27 on Exploring 2, page
2
+ * "Navigation: Today, Work, Goals, Events, Library, Routine"). Draws pm/pop-work-model.js in the popup's Viewer (pm/cozy-popup.js) and wires its
3
+ * presses to the host's own handlers, the same ones the old initiative page uses (pm/ini-view.js wireView). The look is cozy-pop-work.css.
4
+ *
5
+ * on(body) → true when the body is in the popup and the PM did not ask for every part (the old page): the host then
6
+ * draws html() and wires wire() in place of viewHtml() and wireView()
7
+ * html(r, v, o) → the initiative: Overview (summary ✦, PMOS suggests, the facts), Work breakdown (one view: the rows and the
8
+ * timeline on their right), Artefacts. o: what workOf() takes, plus ws, board, id (the record id)
9
+ * wire(body, h, x) once per body. h: the host's handlers (status, dates, addTask, openTask, openTicket, stagePick, planDates,
10
+ * next, wf, program, doc, sm, redraw, reload, toast, where); x: { r(), v(), o(), more(): the old ⋯ entries }
11
+ * moreItems(x, h) → the ⋯ entries the popup adds: Every part (the old page, as a drill-in), Dashboard, All PMOS suggests
12
+ * levelHtml(L, o) / wireLevel(body, h, L) a program or a product one level up (boards 26, 27)
13
+ *
14
+ * Writes, each on the PM's press only: a task's status and dates and a new task (the host's), ✓ and ✕ on a suggestion (POST /api/proposals/keep,
15
+ * /drop, Undo /undo), the summary changed or confirmed in place (POST /api/initiative/describe, Undo /api/initiative/describe-undo). Saved on
16
+ * leave, with Undo for a moment. Values read from the work (Gate, Open) and Jira tasks are not edited here.
17
+ * Reads: GET /api/library-items?ws&initiative (the Library's rows, slice 7) once per initiative; when that route is not there the core documents
18
+ * the page already reads stand in. The UI says PMOS, never Claude; icon-only buttons carry aria-label. */
19
+ import * as M from './pop-work-model.js';
20
+ import * as CB from './cozy-bar.js';
21
+ import { openPop, closePop, undoToast } from './hi-pop.js';
22
+ import { pmGet, pmPost } from './http.js';
23
+ import * as VW from './cozy-viewer.js';
24
+ import * as ED from './ini-edit.js';
25
+ import * as SW from './cozy-status-when.js'; // When did this happen? after a status pick (round 3 point 18)
26
+ import * as DP from './cozy-day-pick.js'; // the app's own day field, "15 Oct 2026"
27
+ const { localToday } = DP;
28
+ import * as AK from './artefact-kind.js'; // the Kind of a file and one row per kind (round 3 point 16), shared with the Library // the rename and its Undo, the same write as the old List (batch 18 item 16)
29
+
30
+ const CSS = new URL('./cozy-pop-work.css', import.meta.url).href;
31
+ if (typeof document !== 'undefined' && document.head && !document.querySelector(`link[href="${CSS}"]`)) {
32
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = CSS; document.head.appendChild(l);
33
+ }
34
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
35
+ const SVG = (d, w = 16, sw = 1.8) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="${sw}" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
36
+ const P = {
37
+ more: 'M5 12h.01M12 12h.01M19 12h.01', dia: 'M12 4l8 8-8 8-8-8z', box: 'M6 5h12a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1z',
38
+ check: 'M5 12l5 5 9-10', x: 'M6 6l12 12M18 6L6 18', right: 'M10 7l5 5-5 5', down: 'M7 10l5 5 5-5', plus: 'M12 5v14M5 12h14',
39
+ tune: 'M4 7h10M18 7h2M4 17h4M12 17h8M14 5v4M8 15v4', full: 'M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5', in: 'M9 4v5H4M15 4v5h5M15 20v-5h5M9 20v-5H4',
40
+ hide: 'M13 6l6 6-6 6M5 6l6 6-6 6', show: 'M11 6l-6 6 6 6M19 6l-6 6 6 6', open: 'M14 4h6v6M20 4l-9 9M18 14v6H4V6h6', chat: 'M4 5h16v11H9l-5 4z', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z',
41
+ };
42
+ const STATES = ['To do', 'In progress', 'Done', "Won't do"];
43
+ const store = {
44
+ get(k, d) { try { const v = localStorage.getItem(k); return v == null ? d : JSON.parse(v); } catch { return d; } },
45
+ set(k, v) { try { localStorage.setItem(k, JSON.stringify(v)); } catch { /* a private window */ } },
46
+ };
47
+ // 'pw-cols2': a column choice saved before round 3 (Status and Date hidden by an older tune menu) no longer hides them (round 3 point 5)
48
+ const COLS = 'pw-cols2', SPAN = 'pw-span', BIG = 'pw-big', TLW = 'pw-tlw';
49
+ const cols = () => ({ status: true, date: true, tl: true, kind: true, when: true, ...store.get(COLS, {}) });
50
+ const ST = new Map(); // initiative id → { open, shut, doneOpen, farOpen, details, top }
51
+ const LOOSE = 'pw-loose'; // the initiatives whose Not in a stage row the PM opened (round 3 point 21), remembered on this computer
52
+ const stOf = (id) => {
53
+ if (!ST.has(id)) ST.set(id, { open: new Set((store.get(LOOSE, []) || []).includes(id) ? [''] : []), shut: new Set(), doneOpen: new Set(), moreOpen: new Set(), farOpen: false, details: null, top: 0, msAdd: false });
54
+ return ST.get(id);
55
+ };
56
+ const looseKeep = (id, on) => { const L = (store.get(LOOSE, []) || []).filter((x) => x !== id); if (on) L.push(id); store.set(LOOSE, L.slice(-200)); };
57
+ const ITEMS = new Map(); // initiative id → the Library's rows | null while reading | false when the route is not there
58
+ const ib = (attr, label, d, cls = '') => `<button type="button" class="pw-ib${cls ? ' ' + cls : ''}" ${attr} aria-label="${esc(label)}" title="${esc(label)}">${SVG(d)}</button>`;
59
+
60
+ /** The body is in the popup, and the PM did not ask for the old page there. */
61
+ export function on(body) { return !!(body && body.closest && body.closest('.cz-pop') && !body.closest('[data-pw-all]') && !(body.dataset && body.dataset.pwAll)); }
62
+
63
+ /* ── reads ── */
64
+ function readItems(id, ws, redraw) {
65
+ if (!id || ITEMS.has(id)) return;
66
+ ITEMS.set(id, null);
67
+ pmGet('/api/library-items?initiative=' + encodeURIComponent(id) + (ws ? '&ws=' + encodeURIComponent(ws) : ''))
68
+ .then((x) => { ITEMS.set(id, x && x.ok && Array.isArray(x.items) ? x.items : false); if (x && x.ok && (x.items || []).length) redraw(); })
69
+ .catch(() => ITEMS.set(id, false));
70
+ }
71
+ export const resetItems = () => ITEMS.clear();
72
+ /* the goal's name, not its id (board 25: "De-risk Okta dependency", not KR-C4): GET /api/boards/anchors once per product */
73
+ const GOALS = new Map(); // ws|board → [{ value, kind, label }] | null while reading | false
74
+ let goalsRedraw = null;
75
+ function goalOf(ws, board, anchor) {
76
+ const a = String(anchor || '').trim(); if (!a || !board) return '';
77
+ const k = (ws || '') + '|' + board;
78
+ if (!GOALS.has(k)) {
79
+ GOALS.set(k, null);
80
+ pmGet('/api/boards/anchors?ws=' + encodeURIComponent(ws || '') + '&board=' + encodeURIComponent(board))
81
+ .then((x) => { GOALS.set(k, x && x.ok ? x.anchors || [] : false); if (x && x.ok && goalsRedraw) goalsRedraw(); }).catch(() => GOALS.set(k, false));
82
+ return '';
83
+ }
84
+ return M.goalName(GOALS.get(k) || [], a);
85
+ }
86
+
87
+ /* the initiative's own records for the Overview (round 3 point 10): GET /api/artefacts?scope=experiment:<id> once per initiative */
88
+ const ART = new Map(); // id → artefacts | null while reading | [] when the route is not there
89
+ let artRedraw = null;
90
+ function artOf(id, ws) {
91
+ if (!id) return [];
92
+ if (!ART.has(id)) {
93
+ ART.set(id, null);
94
+ pmGet('/api/artefacts?scope=' + encodeURIComponent('experiment:' + id) + (ws ? '&ws=' + encodeURIComponent(ws) : ''))
95
+ .then((x) => { ART.set(id, x && x.ok && Array.isArray(x.artefacts) ? x.artefacts : []); if (artRedraw) artRedraw(); }).catch(() => ART.set(id, []));
96
+ }
97
+ return ART.get(id);
98
+ }
99
+ /* a product's name, never its id (round 3 point 4): GET /api/workspaces once */
100
+ let WSN = null, wsnRedraw = null;
101
+ function productName(p, ws) {
102
+ const v = String(p || '').trim();
103
+ if (v && !M.idShaped(v) && v !== ws) return v;
104
+ if (WSN == null) {
105
+ WSN = new Map();
106
+ pmGet('/api/workspaces').then((x) => { for (const w of (x && x.workspaces) || []) if (w && w.id) WSN.set(w.id, w.label || w.name || ''); if (wsnRedraw) wsnRedraw(); }).catch(() => {});
107
+ }
108
+ const n = WSN.get(v) || WSN.get(ws || '') || '';
109
+ return n && !M.idShaped(n) ? n : '';
110
+ }
111
+
112
+ /* ── the parts ── */
113
+ /* the Overview explains the initiative (round 3 point 10): Problem, Goal, Done when from its own records, one status line, PMOS suggests, then
114
+ * Details › for the grid. A line with no source says so in grey with a ✦ offer; nothing is invented. */
115
+ function ovLines(ov, oid, edit = true) {
116
+ const dr = dropped();
117
+ return `<div class="pw-ols">${ov.lines.map((L) => {
118
+ const ed = edit && L.edit;
119
+ const words = L.text ? esc(L.text) : 'Not written yet.'; // the label already names it: said once (round 3 design check)
120
+ const tx = ed ? `<span class="pw-otx${L.text ? '' : ' grey'}" data-pw-line="${esc(L.id)}" tabindex="0" role="button" aria-label="${esc((L.text ? 'Change the ' : 'Write the ') + L.k.toLowerCase())}">${words}</span>` : `<span class="${L.text ? '' : 'grey'}">${words}</span>`;
121
+ const src = L.text && L.src ? (L.path ? ` <button type="button" class="pw-osrc" data-pw-src="${esc(L.path)}">from ${esc(L.src)}</button>` : ` <span class="pw-osrc">from ${esc(L.src)}</span>`) : '';
122
+ const sid = 'ov:' + oid + ':' + L.id;
123
+ const off = !L.text && L.ask && !dr.has(sid) ? `<span class="pw-ooff"><span class="pw-oq">${SVG(P.spark, 12, 2)}${esc(L.miss.replace(/^.*?\. /, ''))}</span><span class="pw-sugb">${ib(`data-pw-lkeep="${esc(L.id)}"`, 'Yes, draft it', P.check, 'sm')}${ib(`data-pw-ldrop="${esc(sid)}"`, 'No', P.x, 'sm')}</span></span>` : '';
124
+ return `<div class="pw-ol"><span class="pw-ok">${esc(L.k)}</span><p class="pw-ot">${tx}${L.serves ? ' <span>' + esc(L.serves) + '</span>' : ''}${src}${off}</p></div>`;
125
+ }).join('')}</div>`;
126
+ }
127
+ function overviewHtml(W, S, oid) {
128
+ const ov = W.overview, open = !!S.details;
129
+ const mark = `<span class="pw-spark" role="img" aria-label="PMOS wrote this from the records" title="PMOS wrote this from the records">${SVG(P.spark, 14, 2)}</span>`;
130
+ const st = ov.status ? `<p class="pw-ostat">${esc(ov.status)}</p>` : '';
131
+ const sug = W.suggests.length ? `<div class="pw-sugs" role="list" aria-label="PMOS suggests"><p class="pw-sugh">PMOS suggests</p>${W.suggests.map((s) => sugLine(s)).join('')}${W.more ? `<button type="button" class="pw-lk" data-pw-props>${esc(W.more + ' more')}</button>` : ''}</div>` : '';
132
+ const facts = open ? factsHtml(W.facts) : '';
133
+ const det = `<button type="button" class="pw-det" data-pw-details aria-expanded="${open}">${open ? 'Less' : 'Details'}${SVG(open ? P.down : P.right, 14)}</button>`;
134
+ return `<section class="pw-ov" aria-label="Overview"><div class="pw-ovh"><h3>Overview</h3>${mark}${det}</div>${ovLines(ov, oid)}${st}${sug}${facts}</section>`;
135
+ }
136
+ function factsHtml(F) {
137
+ return `<dl class="pw-facts">${F.map((f) => `<div class="pw-f"><dt>${esc(f.k)}</dt><dd>${f.act && !f.read ? `<button type="button" class="pw-fv" data-pw-fact="${esc(f.act)}">` : '<span class="pw-fv ro">'}<span class="${f.grey ? 'grey' : ''}${f.warn && !f.note ? ' warn' : ''}">${esc(f.v)}</span>${f.note ? ` · <span class="${f.warn ? 'warn' : ''}">${esc(f.note)}</span>` : ''}${f.act && !f.read ? '</button>' : '</span>'}</dd></div>`).join('')}</dl>`;
138
+ }
139
+ function sugLine(s, under) {
140
+ // two choices (round 3 point 13: "Close them, or reopen?"): each is its own press; ✕ hides it
141
+ const acts = s.choices ? s.choices.map((c, i) => `<button type="button" class="pw-chc" data-pw-choice="${esc(s.id + '|' + i)}">${esc(c.label)}</button>`).join('') + ib(`data-pw-drop="${esc(s.id)}"`, 'Not now', P.x, 'sm')
142
+ : ib(`data-pw-keep="${esc(s.id)}"`, 'Yes, do it', P.check, 'sm') + ib(`data-pw-drop="${esc(s.id)}"`, 'No', P.x, 'sm');
143
+ return `<div class="pw-sug${under ? ' under' : ''}" role="listitem"><button type="button" class="pw-sugt" data-pw-sug="${esc(s.id)}">${SVG(P.spark, 13, 2)}<span>${esc(s.say)}</span>${SVG(P.right, 14)}</button>`
144
+ + `<span class="pw-sugb">${acts}</span></div>`;
145
+ }
146
+ function headCells(C, W, mode, kind) {
147
+ const mk = M.marksOf(W.span, W.today), td = mk.today;
148
+ // the Today pill is always on the line when today is in the window (round 3 point 8); a month mark too close to it gives way
149
+ const tl = C.tl ? `<div class="pw-tl pw-tlh" aria-hidden="true">`
150
+ + mk.months.filter((m) => m.x > 3 && m.x < 90 && !(td != null && Math.abs(m.x - td) < 7)).map((m) => `<span class="pw-mk" style="left:${m.x.toFixed(2)}%">${esc(m.label)}</span>`).join('')
151
+ + (td != null ? `<span class="pw-tday" style="left:clamp(24px, ${td.toFixed(2)}%, calc(100% - 24px))">Today</span>` : '') + '</div>' : '';
152
+ return `<div class="pw-tr pw-th" role="row"><span role="columnheader">${kind || 'Item'}</span>${C.status ? '<span role="columnheader">Status</span>' : ''}${C.date ? '<span role="columnheader">Date</span>' : ''}${tl}</div>`;
153
+ }
154
+ /* the grip between the item columns and the timeline (round 3 point 1): drag it left or right; the item columns keep about 220 px (the name)
155
+ * and the timeline about 240 px. Double press or Home: back to the default. The width is remembered on this computer. */
156
+ const tlStyle = () => { const w = +store.get(TLW, 0); return w > 0 ? ` style="--pw-tlw:${Math.round(w)}px"` : ''; };
157
+ const gripHtml = () => `<div class="pw-tlgrip" role="separator" aria-orientation="vertical" tabindex="0" data-pw-grip aria-label="Drag to make the timeline wider or narrower. Double press to reset." title="Drag to make the timeline wider or narrower. Double press to reset."><i></i></div>`;
158
+ function wireGrip(root) {
159
+ if (root.__pwGrip) return; root.__pwGrip = true;
160
+ const set = (card, px) => { const r = card.getBoundingClientRect(), w = Math.max(240, Math.min(px, r.width - 220)); card.style.setProperty('--pw-tlw', Math.round(w) + 'px'); return w; };
161
+ root.addEventListener('pointerdown', (e) => {
162
+ const g = e.target.closest('[data-pw-grip]'); if (!g || e.button !== 0) return;
163
+ const card = g.closest('.pw-wbs'); if (!card) return;
164
+ e.preventDefault(); g.setPointerCapture(e.pointerId); document.body.classList.add('pw-drag');
165
+ let w = 0;
166
+ const mv = (ev) => { w = set(card, card.getBoundingClientRect().right - ev.clientX); };
167
+ const up = () => { g.removeEventListener('pointermove', mv); g.removeEventListener('pointerup', up); g.removeEventListener('pointercancel', up); document.body.classList.remove('pw-drag'); if (w) store.set(TLW, w); };
168
+ g.addEventListener('pointermove', mv); g.addEventListener('pointerup', up); g.addEventListener('pointercancel', up);
169
+ });
170
+ root.addEventListener('dblclick', (e) => { const g = e.target.closest('[data-pw-grip]'); if (!g) return; store.set(TLW, 0); const c = g.closest('.pw-wbs'); if (c) c.style.removeProperty('--pw-tlw'); });
171
+ root.addEventListener('keydown', (e) => {
172
+ const g = e.target.closest && e.target.closest('[data-pw-grip]'); if (!g) return;
173
+ const c = g.closest('.pw-wbs'); if (!c) return;
174
+ const cur = c.querySelector('.pw-th .pw-tl'), now = cur ? cur.getBoundingClientRect().width : 0;
175
+ const d = e.key === 'ArrowLeft' ? 24 : e.key === 'ArrowRight' ? -24 : 0;
176
+ if (d && now) { e.preventDefault(); store.set(TLW, set(c, now + d)); } else if (e.key === 'Home') { e.preventDefault(); store.set(TLW, 0); c.style.removeProperty('--pw-tlw'); }
177
+ });
178
+ }
179
+ /* the bars are the original workspace bars (pm/cozy-bar.js, the same as Work): a stage in its tone with its gap line and ◇s, a task in its box's
180
+ * tone with the late line to Today, a milestone as its ◇ with its card */
181
+ const xOf = (W) => { const a = Date.parse(W.span.a), b = Date.parse(W.span.b); return (v) => ((Date.parse(String(v).slice(0, 10)) - a) / Math.max(864e5, b - a)) * 100; };
182
+ function barHtml(x, W) {
183
+ const X = xOf(W);
184
+ if (x.kind === 'stage') return x.start || x.end ? CB.stageBar({ start: x.start, end: x.end, tone: x.tone, late: x.late, ms: x.ms, name: x.name, gaps: x.gaps, marks: x.open ? [] : x.marks }, X, { today: W.today }) : '';
185
+ if (x.kind === 'done') return x.start || x.end ? CB.stageBar({ start: x.start, end: x.end, tone: 'dn' }, X, { today: W.today }) : '';
186
+ return CB.taskBar(x, X, W.today);
187
+ }
188
+ function rowHtml(x, W, C, sugRows) {
189
+ const tl = C.tl ? `<div class="pw-tl">${(x.kind === 'stage' || x.kind === 'task' || x.kind === 'done') ? barHtml(x, W) : ''}${W.tx != null ? `<i class="pw-now" style="left:${W.tx.toFixed(2)}%"></i>` : ''}</div>` : '';
190
+ const stc = C.status ? `<span class="pw-st">${x.kind === 'task' && !x.jira ? `<button type="button" class="pw-cell" data-pw-status="${esc(x.uid)}" aria-haspopup="menu" aria-label="${esc('Status: ' + x.status + '. Change it')}">${esc(x.status)}</button>` : esc(x.status || '')}</span>` : '';
191
+ const dtc = C.date ? `<span class="pw-dt${x.late ? ' warn' : ''}">${x.kind === 'task' && !x.jira ? `<button type="button" class="pw-cell${x.date ? '' : ' empty'}" data-pw-date="${esc(x.uid)}" aria-label="${esc((x.date ? (x.ms ? 'Milestone ' : 'Due ') + x.date : 'No date') + '. Set the date, or make it a ' + (x.ms ? 'task' : 'milestone'))}">${esc(x.date || 'Set a date')}</button>` : esc(x.date || '')}</span>` : '';
192
+ if (x.kind === 'stage') {
193
+ const lead = `<button type="button" class="pw-stg" data-pw-fold="${esc(x.key)}" aria-expanded="${x.open}"${x.can ? '' : ' disabled'}><span class="pw-n">${esc(x.n)}</span><b>${esc(x.name)}</b>${x.can ? SVG(x.open ? P.down : P.right, 14) : ''}<small>${esc(x.count)}</small></button>`;
194
+ const ls = x.loose ? sugRows.get('stage:') : null; // the one ✦ of the Not in a stage row (round 3 point 21)
195
+ return `<div class="pw-tr pw-sr${x.now ? ' now' : ''}${x.loose ? ' loose' : ''}" role="row"><span class="pw-it">${lead}</span>${stc}${dtc}${x.loose ? (C.tl ? '<div class="pw-tl"></div>' : '') : tl}</div>`
196
+ + (ls ? `<div class="pw-tr pw-sugrow" role="row"><span class="pw-it">${sugLine(ls, true)}</span></div>` : '');
197
+ }
198
+ if (x.kind === 'far') return `<div class="pw-tr pw-sr" role="row"><span class="pw-it"><button type="button" class="pw-stg" data-pw-far aria-expanded="false"><span class="pw-n">${esc(x.n)}</span><b>${esc(x.name)}</b>${SVG(P.right, 14)}<small>${esc(x.count)}</small></button></span>${stc}${C.date ? '<span></span>' : ''}${tl}</div>`;
199
+ if (x.kind === 'more') return `<div class="pw-tr pw-dr" role="row"><span class="pw-it"><button type="button" class="pw-dn" data-pw-more="${esc(x.key)}" aria-expanded="false">${esc(x.label)}${SVG(P.right, 14)}</button></span>${C.status ? '<span></span>' : ''}${C.date ? '<span></span>' : ''}${C.tl ? '<div class="pw-tl"></div>' : ''}</div>`;
200
+ if (x.kind === 'done') return `<div class="pw-tr pw-dr" role="row"><span class="pw-it"><button type="button" class="pw-dn" data-pw-done="${esc(x.key)}" aria-expanded="${x.open}">${esc(x.label)}${SVG(x.open ? P.down : P.right, 14)}</button></span>${C.status ? '<span></span>' : ''}${C.date ? '<span></span>' : ''}${tl}</div>`;
201
+ const s = sugRows.get(x.uid);
202
+ const title = x.jira ? `<span class="pw-tt">${esc(x.title)}</span>` : `<button type="button" class="pw-tt" data-pw-name="${esc(x.uid)}" aria-label="${esc('Rename ' + x.title)}">${esc(x.title)}</button>`;
203
+ return `<div class="pw-tr pw-kr${x.done ? ' done' : ''}" role="row" data-pw-row="${esc(x.uid)}" data-pw-sec="${esc(x.sec)}"><span class="pw-it"><i class="pw-bul${x.ms ? ' ms' : ''}" aria-hidden="true"></i>${title}${ib(`data-pw-open="${esc(x.uid)}"`, 'Open the task', P.open, 'xs hov')}${ib(`data-pw-row-more="${esc(x.uid)}" aria-haspopup="menu"`, 'More for ' + x.title, P.more, 'xs hov')}</span>${stc}${dtc}${tl}</div>`
204
+ + (s ? `<div class="pw-tr pw-sugrow" role="row"><span class="pw-it">${sugLine(s, true)}</span></div>` : '');
205
+ }
206
+ function breakdownHtml(W, C, mode, full, S) {
207
+ const sugRows = W.rowSuggests, ms = !!(S && S.msAdd);
208
+ // the add row (round 3 point 2): "◇" beside it makes the next one a milestone; typing "◇ " first does the same
209
+ const add = (key, name) => `<div class="pw-tr pw-add" role="row"><span class="pw-it"><label class="pw-addf">${SVG(P.plus, 14)}<input data-pw-add="${esc(key)}" data-pw-add-name="${esc(name)}" placeholder="${ms ? 'Add a milestone' : 'Add a task'}" aria-label="${esc((ms ? 'Add a milestone to ' : 'Add a task to ') + name)}" maxlength="200" autocomplete="off"></label>`
210
+ + `<button type="button" class="pw-addty${ms ? ' on' : ''}" data-pw-addty aria-pressed="${ms}" aria-label="${ms ? 'Adds a milestone. Press to add a task' : 'Adds a task. Press to add a milestone'}" title="Task or milestone">${SVG(ms ? P.dia : P.box, 13, 2)}<span>${ms ? 'Milestone' : 'Task'}</span></button></span></div>`;
211
+ let out = '', curSec = null;
212
+ for (let i = 0; i < W.rows.length; i++) {
213
+ const x = W.rows[i];
214
+ out += rowHtml(x, W, C, sugRows);
215
+ if (x.kind === 'stage' && x.open) curSec = x;
216
+ const nx = W.rows[i + 1];
217
+ if (curSec && (!nx || nx.kind === 'stage' || nx.kind === 'far')) { if (curSec.key !== '' ) out += add(curSec.key, curSec.name); curSec = null; }
218
+ }
219
+ const spanB = C.tl ? `<button type="button" class="pw-span" data-pw-span aria-haspopup="menu" aria-label="${esc('Span of the timeline: ' + (M.MODES.find((m) => m[0] === mode) || M.MODES[5])[1])}">${esc((M.MODES.find((m) => m[0] === mode) || M.MODES[5])[1])}${SVG(P.down, 12)}</button>` : '';
220
+ const tools = `<span class="pw-tools">${spanB}${ib(`data-pw-big aria-pressed="${!!full}"`, full ? 'Back to the initiative' : 'Give the work breakdown the whole popup', full ? P.in : P.full)}${ib('data-pw-tune="wbs" aria-haspopup="menu"', 'Show or hide columns', P.tune)}</span>`;
221
+ const show = !C.tl ? ib('data-pw-tl', 'Show the timeline', P.show, 'xs') : '';
222
+ return `<section class="pw-sec" aria-label="Work breakdown">${full ? `<div class="pw-sech">${tools}</div>` : `<div class="pw-sech"><h3>Work breakdown</h3>${show}${tools}</div>`}`
223
+ + `<div class="pw-card pw-wbs${C.tl ? '' : ' notl'}${C.status ? '' : ' nost'}${C.date ? '' : ' nodt'}" role="table" aria-label="Work breakdown"${tlStyle()}>${C.tl ? gripHtml() : ''}${headCells(C, W, mode)}${out || '<div class="pw-tr pw-empty" role="row"><span>No task yet.</span></div>'}</div>`
224
+ + (C.tl ? '<p class="pw-key"><span><i class="k-tb pr"></i>In progress</span><span><i class="k-tb"></i>To do</span><span><i class="k-tb dn"></i>Done</span><span><i class="k-md"></i>Milestone</span><span><i class="k-late"></i>Late</span><span><i class="k-gap"></i>No activity</span></p>' : '') + '</section>';
225
+ }
226
+ /* the Artefacts (round 3 point 16): one row per Kind, in lifecycle order. Kind | Artefact (the current one) | Version | Updated. Versions and the
227
+ * files of a series unfold under the row; several different files of one kind show a count, and one ✦ line above the table proposes to merge
228
+ * them (✓ asks PMOS, ✕ hides it). */
229
+ const ARTOPEN = new Set(); // kinds unfolded, per page
230
+ function artefactsHtml(rows, C, add = true, o = {}) {
231
+ const idx = new Map(rows.map((a, i) => [a, i]));
232
+ const G = AK.group(rows, { at: (a) => a.at || 0, current: (a) => !!(o.recPath && a.path && a.path.replace(/^pmos\//, '') === String(o.recPath).replace(/^pmos\//, '')), dropped: dropped() });
233
+ const scope = o.scope || '';
234
+ const nameCell = (a) => (a.missing ? esc(a.title) : `<button type="button" class="pw-an" data-pw-art="${idx.get(a)}">${esc(a.title)}${a.link ? SVG(P.open, 13) : ''}</button>`);
235
+ const body = G.groups.map((g) => {
236
+ const a = g.cur, k = scope + '|' + g.kind, open = ARTOPEN.has(k), vt = AK.versionText(g);
237
+ const ver = vt && g.earlier.length ? `<button type="button" class="pw-ver" data-pw-ver="${esc(k)}" aria-expanded="${open}">${esc(vt)}${SVG(open ? P.down : P.right, 12)}</button>` : esc(vt);
238
+ const row = `<div class="pw-ar${a.missing ? ' miss' : ''}" role="row"><span role="cell" class="pw-ak">${esc(g.kind)}</span><span role="cell">${nameCell(a)}</span><span role="cell" class="pw-av">${ver}</span>`
239
+ + (C.when ? `<span role="cell"${a.missing ? ' class="warn"' : ''}>${esc(a.missing || a.when || '')}</span>` : '') + '</div>';
240
+ const more = open ? g.earlier.map((e) => `<div class="pw-ar pw-ear" role="row"><span role="cell"></span><span role="cell">${nameCell(e)}</span><span role="cell" class="pw-av">${e.title && AK.versionOf(e.title) ? 'v' + AK.versionOf(e.title) : ''}</span>${C.when ? `<span role="cell">${esc(e.when || '')}</span>` : ''}</div>`).join('') : '';
241
+ return row + more;
242
+ }).join('');
243
+ const mg = G.merge ? `<div class="pw-sugs pw-amg" role="list" aria-label="PMOS suggests">${sugLine({ id: G.merge.id, say: G.merge.say, merge: G.merge })}</div>` : '';
244
+ return `<section class="pw-sec" aria-label="Artefacts"><div class="pw-sech"><h3>Artefacts</h3><span class="pw-tools">${ib('data-pw-tune="art" aria-haspopup="menu"', 'Show or hide columns', P.tune)}</span></div>${mg}`
245
+ + `<div class="pw-card pw-arts${C.when ? '' : ' now'}" role="table" aria-label="Artefacts"><div class="pw-ar pw-th" role="row"><span role="columnheader">Kind</span><span role="columnheader">Artefact</span><span role="columnheader">Version</span>${C.when ? '<span role="columnheader">Updated</span>' : ''}</div>${body}`
246
+ + (add ? `<button type="button" class="pw-ar pw-addart" data-pw-addart>${SVG(P.plus, 14)}<span>Add an artefact: a file, a link, or a new document</span></button>` : '') + '</div></section>';
247
+ }
248
+ const mergeOf = (rows) => AK.group(rows, { dropped: dropped() }).merge;
249
+
250
+ /* ── the initiative ── */
251
+ const keyOf = (v, o) => String((o && o.id) || (v && (v.id || v.key)) || '');
252
+ function model(r, v, o) {
253
+ const id = keyOf(v, o), S = stOf(id), it = ITEMS.get(id);
254
+ const g = o.goal || goalOf(o.ws, o.board, r.anchor || v.anchor);
255
+ const W = M.workOf(r, v, { ...o, goal: M.idShaped(g) ? '' : g, product: productName(o.product, o.ws), art: artOf(id, o.ws), open: S.open, shut: S.shut, doneOpen: S.doneOpen, moreOpen: S.moreOpen, farOpen: S.farOpen, mode: store.get(SPAN, 'full'), items: it || [], dropped: dropped() });
256
+ const mk = M.marksOf(W.span, W.today); W.tx = mk.today;
257
+ return { W, S, id };
258
+ }
259
+ export function html(r, v, o = {}) {
260
+ const { W, S } = model(r, v, o), C = cols(), mode = store.get(SPAN, 'full');
261
+ if (S.big) return `<div class="pw" data-pw-big-on>${breakdownHtml(W, C, mode, true, S)}</div>`;
262
+ return `<div class="pw">${overviewHtml(W, S, keyOf(v, o))}${breakdownHtml(W, C, mode, false, S)}${artefactsHtml(W.artefacts, C, true, { scope: keyOf(v, o), recPath: v.prd && (v.prd.path || v.prd) })}</div>`;
263
+ }
264
+
265
+ /* ── the suggestion as its own page (board 22) ── */
266
+ function sugPageHtml(s, W) {
267
+ const items = (s.items || []).slice(0, 8);
268
+ const ch = items.length && s.group === 'dates' ? `<h4>What changes if you say yes</h4><div class="pw-card pw-chg" role="table"><div class="pw-cr pw-th" role="row"><span>What</span><span>Now</span><span>After</span></div>`
269
+ + items.map((x) => `<div class="pw-cr" role="row"><span>${esc(x.title || x.task || '')}</span><span class="${x.from && x.from.due && x.from.due < W.today ? 'warn' : ''}">${esc(x.from && x.from.due ? M.dateLate(x.from.due, W.today).text : '—')}</span><span><b>${esc(x.to && x.to.due ? M.dayText(x.to.due, W.today) : '—')}</b></span></div>`).join('') + '</div>'
270
+ : items.length ? `<h4>What changes if you say yes</h4><ul class="pw-ul">${items.map((x) => `<li>${esc(x.title || x.task || x.stage || x.text || '')}</li>`).join('')}</ul>` : '';
271
+ const read = (s.sources || []).length ? `<h4>What PMOS read</h4><div class="pw-card">${s.sources.map((x, i) => `<button type="button" class="pw-src" data-pws-src="${i}"><span>${esc(x.label || x.ref || '')}</span>${x.ref ? SVG(P.right, 14) : ''}</button>`).join('')}</div>` : '';
272
+ return `<div class="pw pw-sp"><div class="pw-spc"><p class="pw-sugh">${SVG(P.spark, 13, 2)} PMOS suggests</p><h3>${esc(s.say)}</h3>`
273
+ + `<span class="pw-spb">${ib(`data-pws-keep="${esc(s.id)}"`, 'Yes, do it', P.check, 'solid')}${ib(`data-pws-drop="${esc(s.id)}"`, 'No', P.x)}</span></div>`
274
+ + (s.why ? `<h4>Why</h4><p>${esc(s.why)}</p>` : '') + ch + read
275
+ + `<button type="button" class="pw-ask" data-pws-ask>${SVG(P.chat, 15)}Ask PMOS about this</button></div>`;
276
+ }
277
+
278
+ /* ── writes ── */
279
+ /* the suggestions PMOS reads from the record (pop-work-model.js derivedOf): ✓ puts a task in a stage, or sends the words to Ask PMOS, which
280
+ * does it in a real session; ✕ hides it on this computer */
281
+ const DROP = 'pw-dropped';
282
+ const dropped = () => new Set(store.get(DROP, []));
283
+ function sendToChat(text) {
284
+ const ask = document.querySelector('.cz-pop [data-pop="ask"]'); if (ask && !ask.closest('[hidden]')) ask.click();
285
+ const ta = document.querySelector('.cz-pop-chat textarea'); if (!ta) return false;
286
+ ta.value = text; ta.dispatchEvent(new Event('input', { bubbles: true }));
287
+ const f = ta.closest('form'); if (f && f.requestSubmit) f.requestSubmit(); else ta.focus();
288
+ return true;
289
+ }
290
+ async function keepSug(s, x, h) {
291
+ if (s.derived) {
292
+ if (s.move && h.move) { await h.move(s.move.uid, { to: s.move.to, from: '', name: s.move.name }); return; }
293
+ if (s.moveAll) { await moveAll(s.moveAll, h); return; }
294
+ if (s.ask && !sendToChat(s.ask) && h.toast) h.toast('Open Ask PMOS to send this.');
295
+ return;
296
+ }
297
+ if (s.sm) { if (h.sm) h.sm('yes'); return; }
298
+ const w = h.where ? h.where() : {}, res = await pmPost('/api/proposals/keep', { ...w, initiative: x.o().id, ids: [s.id] }).catch(() => null);
299
+ if (!res || res.ok === false) { if (h.toast) h.toast((res && res.error) || 'Nothing was kept.'); return; }
300
+ const batch = res.batch;
301
+ undoToast(res.said || 'Done.', async () => {
302
+ const u = await pmPost('/api/proposals/undo', { ...w, batch }).catch(() => null);
303
+ if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
304
+ if (h.reload) await h.reload();
305
+ });
306
+ if (h.reload) await h.reload();
307
+ }
308
+ /* the tasks in no stage, all into the stage in progress, with one Undo that puts each back (round 3 point 21) */
309
+ async function moveAll(m, h) {
310
+ const w = h.where ? h.where() : {}, moved = [];
311
+ for (const uid of m.uids) {
312
+ const r = await pmPost('/api/boards/tasks/edit', { ws: w.ws, board: w.board, task: uid, section: m.to }).catch(() => null);
313
+ if (r && r.ok !== false) moved.push(uid);
314
+ }
315
+ if (h.reload) await h.reload();
316
+ if (!moved.length) { if (h.toast) h.toast('Nothing was moved.'); return; }
317
+ undoToast((moved.length === 1 ? '1 task' : moved.length + ' tasks') + ' moved to ' + m.name + '.' + (moved.length < m.uids.length ? ' ' + (m.uids.length - moved.length) + ' could not be moved.' : ''), async () => {
318
+ for (const uid of moved) await pmPost('/api/boards/tasks/edit', { ws: w.ws, board: w.board, task: uid, section: '' }).catch(() => null);
319
+ if (h.reload) await h.reload();
320
+ });
321
+ }
322
+ async function dropSug(s, x, h) {
323
+ if (s.derived) { const d = dropped(); d.add(s.id); store.set(DROP, [...d].slice(-200)); if (h.redraw) h.redraw(); return; }
324
+ if (s.sm) { if (h.sm) h.sm('no'); return; }
325
+ const w = h.where ? h.where() : {}, res = await pmPost('/api/proposals/drop', { ...w, initiative: x.o().id, sig: s.sig }).catch(() => null);
326
+ if (!res || res.ok === false) { if (h.toast) h.toast((res && res.error) || 'Nothing was changed.'); return; }
327
+ if (h.reload) await h.reload();
328
+ }
329
+ async function saveDesc(text, x, h) {
330
+ const w = h.where ? h.where() : {}, id = x.o().id;
331
+ const res = await pmPost('/api/initiative/describe', { ws: w.ws, id, text }).catch(() => null);
332
+ if (!res || res.ok === false) { if (h.toast) h.toast((res && res.error) || 'It was not saved.'); return false; }
333
+ if (!res.same) undoToast('Saved.', async () => {
334
+ const u = await pmPost('/api/initiative/describe-undo', { ws: w.ws, id, from: res.from || '', to: res.text }).catch(() => null);
335
+ if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
336
+ if (h.reload) await h.reload();
337
+ });
338
+ if (h.reload) await h.reload();
339
+ return true;
340
+ }
341
+ const findSug = (W, id) => W.suggests.find((s) => s.id === id) || [...W.rowSuggests.values()].find((s) => s.id === id) || null;
342
+
343
+ /* ── the presses ── */
344
+ export function wire(body, h0, x0) {
345
+ if (!body) return;
346
+ // the Viewer reuses its body for the next item: the presses read the item shown now from the body, so one set of listeners serves all
347
+ body.__pwh = ED.writes(h0); body.__pwx = x0;
348
+ { const c = cur(); if (c) { readItems(c.id, (x0.o() || {}).ws, () => redraw()); if (c.S.top) body.scrollTop = c.S.top; } }
349
+ if (body.__pw) return;
350
+ body.__pw = true;
351
+ function cur() { const x = body.__pwx, r = x && x.r(), v = x && x.v(); return r && v ? { r, v, ...model(r, v, x.o()) } : null; }
352
+ function redraw() { if (body.__pwh && body.__pwh.redraw) body.__pwh.redraw(); }
353
+ goalsRedraw = artRedraw = wsnRedraw = () => { if (body.isConnected && body.querySelector('.pw')) redraw(); };
354
+ wireGrip(body);
355
+ const live = (e) => !!body.__pwx && !!e.target.closest('.pw') && !e.target.closest('.pw-sp, [data-pw-level]');
356
+ body.addEventListener('scroll', () => { if (!body.querySelector(':scope > .pw, .pw:not(.pw-sp)')) return; const c = cur(); if (c) c.S.top = body.scrollTop; }, { passive: true });
357
+ body.addEventListener('click', async (e) => {
358
+ if (!live(e)) return;
359
+ const b = e.target.closest('button, [data-pw-line]'); if (!b || b.disabled || !body.contains(b)) return;
360
+ const c = cur(); if (!c) return;
361
+ const h = body.__pwh, x = body.__pwx;
362
+ const d = b.dataset, S = c.S, W = c.W;
363
+ if ('pwDetails' in d) { S.details = !S.details; redraw(); return; }
364
+ if (d.pwFold != null) { const k = d.pwFold, open = b.getAttribute('aria-expanded') === 'true'; S.open.delete(k); S.shut.delete(k); (open ? S.shut : S.open).add(k); if (k === '') looseKeep(c.id, !open); redraw(); return; }
365
+ if ('pwFar' in d) { S.farOpen = true; redraw(); return; }
366
+ if (d.pwDone != null) { if (S.doneOpen.has(d.pwDone)) S.doneOpen.delete(d.pwDone); else S.doneOpen.add(d.pwDone); redraw(); return; }
367
+ if ('pwTl' in d) { store.set(COLS, { ...cols(), tl: !cols().tl }); redraw(); return; }
368
+ if ('pwSpan' in d) { spanMenu(b, redraw); return; }
369
+ if (d.pwTune) { tuneMenu(b, d.pwTune, redraw); return; }
370
+ if ('pwBig' in d) { big(c, x, h); return; }
371
+ if (d.pwKeep && /^merge:/.test(d.pwKeep)) { const m = mergeOf(W.artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
372
+ if (d.pwDrop && /^merge:/.test(d.pwDrop)) { const dd = dropped(); dd.add(d.pwDrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
373
+ if (d.pwSug && /^merge:/.test(d.pwSug)) { const m = mergeOf(W.artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
374
+ if (d.pwKeep) { const s = findSug(W, d.pwKeep); if (s) { b.disabled = true; await keepSug(s, x, h); if (VW.current() && /^sug:/.test(VW.current().id)) VW.back(); } return; }
375
+ if (d.pwDrop) { const s = findSug(W, d.pwDrop); if (s) { b.disabled = true; await dropSug(s, x, h); if (VW.current() && /^sug:/.test(VW.current().id)) VW.back(); } return; }
376
+ if (d.pwSug) { const s = findSug(W, d.pwSug); if (s) openSug(s, c, x, h); return; }
377
+ if ('pwProps' in d) { if (h.props) h.props(); return; }
378
+ if (d.pwLine) { const L = W.overview.lines.find((q) => q.id === d.pwLine); if (L && L.edit) editLine(b, L, c, x, h); return; }
379
+ if (d.pwLkeep) { const L = W.overview.lines.find((q) => q.id === d.pwLkeep); if (L && L.ask && !sendToChat(L.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
380
+ if (d.pwLdrop) { const dd = dropped(); dd.add(d.pwLdrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
381
+ if (d.pwSrc) { if (h.doc) h.doc(d.pwSrc); return; }
382
+ if (d.pwChoice) { const [sid, k] = d.pwChoice.split('|'), s = findSug(W, sid), ch = s && s.choices && s.choices[+k]; if (ch && !sendToChat(ch.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
383
+ if (d.pwMore != null) { S.moreOpen.add(d.pwMore); redraw(); return; }
384
+ if (d.pwVer) { if (ARTOPEN.has(d.pwVer)) ARTOPEN.delete(d.pwVer); else ARTOPEN.add(d.pwVer); redraw(); return; }
385
+ if (d.pwRowMore) { rowMenu(b, d.pwRowMore, c, h); return; }
386
+ if ('pwAddty' in d) { S.msAdd = !S.msAdd; const f = b.closest('.pw-add'), k = f && f.querySelector('[data-pw-add]') && f.querySelector('[data-pw-add]').dataset.pwAdd; redraw(); if (k != null) setTimeout(() => { const i = body.querySelector(`[data-pw-add="${CSS.escape(k)}"]`); if (i) i.focus(); }, 0); return; }
387
+ if (d.pwFact) { fact(d.pwFact, b, c, h); return; }
388
+ if (d.pwStatus) { statusMenu(b, d.pwStatus, h, c); return; }
389
+ if (d.pwDate) { dateMenu(b, d.pwDate, c, h); return; }
390
+ if (d.pwName) { rename(b, d.pwName, h); return; }
391
+ if (d.pwOpen) { if (h.openTask) h.openTask(d.pwOpen); return; }
392
+ if (d.cbMs != null) { msPop(b, d.cbMs, W, h); return; }
393
+ if (d.pwArt != null) { openArt(W.artefacts[+d.pwArt], h, x); return; }
394
+ if ('pwAddart' in d) { addArt(x, h); return; }
395
+ });
396
+ body.addEventListener('keydown', async (e) => {
397
+ if (!live(e)) return;
398
+ const t = e.target, h = body.__pwh;
399
+ if (t.matches && t.matches('[data-pw-line]') && (e.key === 'Enter' || e.key === ' ')) { e.preventDefault(); t.click(); return; }
400
+ if (t.matches && t.matches('[data-pw-add]') && e.key === 'Enter') {
401
+ e.preventDefault(); const v0 = t.value.trim(); if (!v0 || !h.addTask) return;
402
+ const sec = t.dataset.pwAdd, c = cur();
403
+ // "◇ " first, or the ◇ choice beside the field: a milestone (the same write as the old List's Type chip, pm/ini-edit.js)
404
+ const ms = /^◇\s*/.test(v0) || !!(c && c.S.msAdd), v = v0.replace(/^◇\s*/, '');
405
+ if (!v) return;
406
+ await h.addTask(v, t, { section: sec, name: t.dataset.pwAddName, ...(ms ? { milestone: true } : {}) });
407
+ // Enter only adds the row; the field stays for the next one
408
+ setTimeout(() => { const f = body.querySelector(`[data-pw-add="${CSS.escape(sec)}"]`); if (f) { f.value = ''; f.focus(); } }, 0);
409
+ }
410
+ });
411
+ }
412
+ function big(c, x, h) {
413
+ const S = c.S;
414
+ if (S.big) { S.big = false; VW.back(); return; }
415
+ // the breakdown takes the whole popup (board 25): a drill-in of its own, the chat gives way; ← or the same button comes back
416
+ const r = c.r, title = (x.v() || {}).title || r.title || '';
417
+ S.big = true;
418
+ const hide = document.querySelector('.cz-pop [data-pop="hide"]');
419
+ const hid = !!(hide && !document.querySelector('.cz-pop-card.cz-pop-nochat'));
420
+ if (hide) hide.click();
421
+ VW.drill();
422
+ VW.open({ kind: 'Work breakdown', title: 'Work breakdown', icon: 'list', id: 'wbs:' + c.id, back: true,
423
+ render: (b) => { b.dataset.pwBig = '1'; const o = x.o(); S.big = true; b.innerHTML = html(x.r(), x.v(), o); wire(b, { ...h, redraw: () => { const t = b.scrollTop; b.innerHTML = html(x.r(), x.v(), x.o()); b.scrollTop = t; } }, x); },
424
+ onClose: () => { S.big = false; if (hid) { const ask = document.querySelector('.cz-pop [data-pop="ask"]'); if (ask && !ask.closest('[hidden]')) ask.click(); } } });
425
+ void title;
426
+ }
427
+ function openSug(s, c, x, h) {
428
+ VW.drill();
429
+ VW.open({ kind: 'Suggestion', title: 'Suggestion', icon: 'spark', id: 'sug:' + s.id, back: true,
430
+ render: (b) => {
431
+ const W = model(x.r(), x.v(), x.o()).W, s2 = findSug(W, s.id) || s;
432
+ b.innerHTML = sugPageHtml(s2, W);
433
+ b.onclick = async (e) => {
434
+ const t = e.target.closest('button'); if (!t) return;
435
+ const d = t.dataset;
436
+ if (d.pwsKeep) { t.disabled = true; await keepSug(s2, x, h); VW.back(); return; }
437
+ if (d.pwsDrop) { t.disabled = true; await dropSug(s2, x, h); VW.back(); return; }
438
+ if ('pwsAsk' in d) { askAbout(s2, x); return; }
439
+ if (d.pwsSrc != null) { const src = (s2.sources || [])[+d.pwsSrc]; if (src && src.ref) openRef(src.ref, h); }
440
+ };
441
+ } });
442
+ }
443
+ /** "Ask PMOS about this": the suggestion goes into the chat on the right, as a draft the PM sends. */
444
+ function askAbout(s, x) {
445
+ const ask = document.querySelector('.cz-pop [data-pop="ask"]'); if (ask && !ask.closest('[hidden]')) ask.click();
446
+ const ta = document.querySelector('.cz-pop-chat textarea, .cz-pop-chat [contenteditable="true"]');
447
+ const text = 'About this suggestion on ' + ((x.v() || {}).title || '') + ': "' + s.say + '". ' + (s.why ? 'You said: ' + s.why + ' ' : '') + 'Why do you suggest it, and what else would it change?';
448
+ if (ta) { if ('value' in ta) { ta.value = text; ta.dispatchEvent(new Event('input', { bubbles: true })); } else ta.textContent = text; ta.focus(); }
449
+ }
450
+ function openRef(ref, h) {
451
+ const s = String(ref);
452
+ if (/^https?:/.test(s)) { window.open(s, '_blank', 'noopener'); return; }
453
+ if (/^task:/.test(s) && h.openTask) { h.openTask(s.slice(5)); return; }
454
+ if (/\.(md|txt|html|pdf|docx?)$/i.test(s) && h.doc) h.doc(s);
455
+ }
456
+ function fact(act, b, c, h) {
457
+ if (act === 'stage' && h.stagePick) h.stagePick(b);
458
+ else if (act === 'dates' && h.planDates) h.planDates(b);
459
+ else if (act === 'next' && h.next) h.next(b);
460
+ else if (act === 'wf' && h.wf) h.wf(b);
461
+ else if (act === 'product' && h.product) h.product(b);
462
+ else if (act === 'program' && h.program) { const p = (c.v.summary || {}).program; if (p) h.program(p.id, b); }
463
+ else if (act.startsWith('task:') && h.openTask) h.openTask(act.slice(5));
464
+ }
465
+ /* a line of the Overview changed in place (round 3 point 10): it goes to the record it came from, with Undo. The record's description through
466
+ * POST /api/initiative/describe; an Experiment or Done test line through POST /api/artefacts/set, and its Undo /api/artefacts/undo */
467
+ function editLine(el, L, c, x, h) {
468
+ if (el.querySelector('textarea')) return;
469
+ const was = L.text || '';
470
+ const ta = document.createElement('textarea');
471
+ ta.className = 'pw-sumed'; ta.value = was; ta.rows = 2; ta.maxLength = 600; ta.setAttribute('aria-label', L.k);
472
+ el.replaceWith(ta); ta.focus();
473
+ let done = false;
474
+ const leave = async (save) => {
475
+ if (done) return; done = true;
476
+ const v = ta.value.replace(/\s+/g, ' ').trim();
477
+ if (save && v && v !== was) await saveLine(L, v, x, h);
478
+ else if (h.redraw) h.redraw();
479
+ };
480
+ ta.addEventListener('blur', () => leave(true));
481
+ ta.addEventListener('keydown', (e) => { if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); leave(false); } else if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); ta.blur(); } });
482
+ }
483
+ async function saveLine(L, text, x, h) {
484
+ if (L.edit.to === 'desc') return saveDesc(text, x, h);
485
+ const w = h.where ? h.where() : {}, o = x.o(), id = o.id, ws = w.ws || o.ws;
486
+ const res = await pmPost('/api/artefacts/set', { ws, scope: 'experiment:' + id, artefact: L.edit.artefact, field: L.edit.field, text }).catch(() => null);
487
+ if (!res || res.ok === false || !res.line) { if (h.toast) h.toast((res && res.error) || 'It was not saved.'); return false; }
488
+ const ref = res.line.id;
489
+ ART.delete(id);
490
+ undoToast(L.k + ' saved.', async () => {
491
+ const u = await pmPost('/api/artefacts/undo', { ws, ref }).catch(() => null);
492
+ if (!u || u.ok === false) { if (h.toast) h.toast((u && u.error) || 'The undo did not land.'); return; }
493
+ ART.delete(id); if (h.redraw) h.redraw();
494
+ });
495
+ if (h.redraw) h.redraw();
496
+ return true;
497
+ }
498
+ function rename(btn, uid, h) {
499
+ const inp = document.createElement('input');
500
+ inp.className = 'pw-namei'; inp.value = btn.textContent; inp.maxLength = 200; inp.setAttribute('aria-label', 'Name of the task');
501
+ const was = btn.textContent;
502
+ btn.replaceWith(inp); inp.focus(); inp.select();
503
+ let done = false;
504
+ const leave = async (save) => {
505
+ if (done) return; done = true;
506
+ const v = inp.value.trim();
507
+ if (save && v && v !== was && h.rename) await h.rename(uid, v);
508
+ else if (h.redraw) h.redraw();
509
+ };
510
+ inp.addEventListener('blur', () => leave(true));
511
+ inp.addEventListener('keydown', (e) => {
512
+ if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); leave(false); return; }
513
+ if (e.key === 'Enter') {
514
+ // Enter saves the name and opens "Add a task" under the same stage
515
+ e.preventDefault();
516
+ const row = inp.closest('[data-pw-row]'), sec = row ? row.dataset.pwSec : null;
517
+ inp.blur();
518
+ if (sec != null) setTimeout(() => { const f = document.querySelector(`.cz-pop [data-pw-add="${CSS.escape(sec)}"]`); if (f) f.focus(); }, 60);
519
+ }
520
+ });
521
+ }
522
+ /** A milestone ◇'s card (the original workspace's milestone popup): its name, date and state, and Open the task. */
523
+ function msPop(btn, uid, W, h) {
524
+ const x = W.rows.find((r) => r.uid === uid) || W.rows.flatMap((r) => r.marks || []).find((m) => m.uid === uid);
525
+ if (!x) return;
526
+ openPop(btn, 'pw-ms', CB.msCard({ uid: x.uid, title: x.title, end: x.end, done: !!x.done }, W.today), (b) => {
527
+ if (b.dataset.cbOpen) { closePop(); if (h.openTask) h.openTask(b.dataset.cbOpen); }
528
+ }, { label: 'Milestone' });
529
+ }
530
+ /* A status pick asks when it really happened (round 3 point 18, pm/cozy-status-when.js): the line opens under the list, Today preselected, so a
531
+ * second press of the same status or Enter keeps today. Never a future day, never before the previous move; the toast says both days. */
532
+ function statusMenu(btn, uid, h, c) {
533
+ const row = (c && c.W.rows.find((x) => x.uid === uid)) || {};
534
+ let picked = null;
535
+ const save = (st, day) => { closePop(); if (h.status) h.status(uid, st, day ? { happened: day } : undefined); };
536
+ const el = openPop(btn, 'pw-status', STATES.map((s) => `<button type="button" class="hi-mi" role="menuitemradio" aria-checked="${s === row.status}" data-st="${esc(s)}">${esc(s)}</button>`).join('') + '<div class="pw-when" hidden></div>', (b) => {
537
+ const st = b.dataset.st; if (!st) return;
538
+ if (st === row.status && !picked) { closePop(); return; }
539
+ if (picked === st) { save(st, null); return; }
540
+ picked = st;
541
+ el.querySelectorAll('[data-st]').forEach((x) => x.setAttribute('aria-checked', String(x.dataset.st === st)));
542
+ const w = el.querySelector('.pw-when'); w.hidden = false; w.innerHTML = '';
543
+ SW.askWhen(w, { since: row.since || '', onPick: (day) => save(st, day === localToday() ? null : day) });
544
+ w.querySelector('[data-sw]')?.focus();
545
+ }, { label: 'Status', focus: '[aria-checked="true"]' });
546
+ }
547
+ /* Task or Milestone (round 3 point 2), in three places that do the same write (pm/ini-edit.js milestone, the host's Undo): the choice on top
548
+ * of the date popup, the row's ⋯, and the add row. A task has Start and Due; a milestone one Date. A Jira task's change is PMOS-only. */
549
+ const jiraNote = (row) => (row.jira ? '<p class="hi-small pw-jn">PMOS only. Jira is not changed.</p>' : '');
550
+ function setKind(row, on, h) { ED.milestone(h, { uid: row.uid, start: row.start, end: row.end, ms: row.ms }, on); }
551
+ function dateMenu(btn, uid, c, h) {
552
+ const row = c.W.rows.find((x) => x.uid === uid) || {};
553
+ const seg = `<div class="pw-seg" role="radiogroup" aria-label="Task or milestone"><button type="button" role="radio" aria-checked="${!row.ms}" data-ty="task">${SVG(P.box, 13, 2)}Task</button><button type="button" role="radio" aria-checked="${!!row.ms}" data-ty="ms">${SVG(P.dia, 13, 2)}Milestone</button></div>`;
554
+ // the app's own day form, "15 Oct 2026", with its small calendar (pm/cozy-day-pick.js), never the browser's month-first field
555
+ const fields = row.ms ? '<div class="pw-dp" data-f="due"></div>' : '<div class="pw-dp" data-f="start"></div><div class="pw-dp" data-f="due"></div>';
556
+ const el = openPop(btn, 'pw-date', seg + fields + jiraNote(row) + `<div class="hi-acts"><button type="button" class="hi-btn ghost" data-clear>No date</button></div>`, (b) => {
557
+ if (b.dataset.ty) { const on = b.dataset.ty === 'ms'; closePop(); if (on !== !!row.ms) setKind(row, on, h); return; }
558
+ if ('clear' in b.dataset) { closePop(); if (h.dates) h.dates(uid, row.ms ? { due: '' } : { start: '', due: '' }); }
559
+ }, { label: 'Set the date', focus: '.dp-in' });
560
+ const st = el.querySelector('[data-f="start"]'), due = el.querySelector('[data-f="due"]');
561
+ if (st) DP.mountDay(st, { label: 'Start', value: row.start || '', onPick: (v) => { if (h.dates) h.dates(uid, { start: v }); } });
562
+ DP.mountDay(due, { label: row.ms ? 'Date' : 'Due', value: row.end || row.start || '', open: !st, onPick: (v) => { closePop(); if (h.dates) h.dates(uid, { due: v }); } });
563
+ (st || due).querySelector('.dp-in')?.focus();
564
+ }
565
+ function rowMenu(btn, uid, c, h) {
566
+ const row = c.W.rows.find((x) => x.uid === uid) || {};
567
+ openPop(btn, 'pw-rowm', `<button type="button" class="hi-mi" role="menuitem" data-k="kind">${SVG(row.ms ? P.box : P.dia, 14, 2)} ${row.ms ? 'Make it a task' : 'Make it a milestone'}</button>`
568
+ + `<button type="button" class="hi-mi" role="menuitem" data-k="open">${SVG(P.open, 14)} Open the task</button>` + jiraNote(row), (b) => {
569
+ closePop();
570
+ if (b.dataset.k === 'kind') setKind(row, !row.ms, h);
571
+ else if (b.dataset.k === 'open' && h.openTask) h.openTask(uid);
572
+ }, { menu: true, label: 'Task' });
573
+ }
574
+ function spanMenu(btn, redraw) {
575
+ const cur = store.get(SPAN, 'full');
576
+ openPop(btn, 'pw-span', M.MODES.map(([k, l]) => `<button type="button" class="hi-mi" role="menuitemradio" aria-checked="${k === cur}" data-sp="${k}">${esc(l)}</button>`).join(''), (b) => {
577
+ closePop(); if (b.dataset.sp) { store.set(SPAN, b.dataset.sp); redraw(); }
578
+ }, { menu: true, label: 'Span of the timeline' });
579
+ }
580
+ function tuneMenu(btn, which, redraw) {
581
+ const C = cols();
582
+ const L = which === 'art' ? [['when', 'Updated']] : [['status', 'Status'], ['date', 'Date'], ['tl', 'Timeline, on the right']];
583
+ openPop(btn, 'pw-tune', `<p class="hi-h3">${which === 'art' ? 'Kind and Artefact always show' : 'Item always shows'}</p>` + L.map(([k, l]) => `<button type="button" class="hi-mi pw-sw" role="menuitemcheckbox" aria-checked="${!!C[k]}" data-col="${k}"><span>${esc(l)}</span><i aria-hidden="true"></i></button>`).join('')
584
+ + '<button type="button" class="hi-mi" data-reset>Reset</button>', (b) => {
585
+ if (b.dataset.col) { const n = { ...cols(), [b.dataset.col]: !cols()[b.dataset.col] }; store.set(COLS, n); b.setAttribute('aria-checked', String(!!n[b.dataset.col])); redraw(); return; }
586
+ if ('reset' in b.dataset) { store.set(COLS, {}); store.set(SPAN, 'full'); closePop(); redraw(); }
587
+ }, { menu: true, label: 'Columns' });
588
+ }
589
+ async function openArt(a, h, x) {
590
+ if (!a || a.missing) return;
591
+ if (a.url) { window.open(a.url, '_blank', 'noopener'); return; }
592
+ if (a.item) {
593
+ if (a.item.kind === 'link' && a.item.open && a.item.open.url) { window.open(a.item.open.url, '_blank', 'noopener'); return; }
594
+ try { const L = await import('./library-open.js'); VW.drill(); await L.openItem(a.item); return; } catch { /* the Library's opener is not there: the path below */ }
595
+ const p = a.item.open && a.item.open.path; if (p && h.doc) { h.doc(p); return; }
596
+ }
597
+ // a document the record names opens as the document page, with its name, from the initiative's own workspace (round 3 point 17)
598
+ if (a.path && /\.md$/i.test(a.path)) {
599
+ const o = x.o() || {}, w = h.where ? h.where() : {}, ws = o.ws || w.ws || '';
600
+ try { const L = await import('./library-open.js'); VW.drill(); L.openItem({ id: 'doc:' + a.path, kind: 'doc', name: a.title, open: { doc: { path: a.path, ws } }, about: { ws, ini: o.id } }); return; } catch { /* the path below */ }
601
+ }
602
+ if (a.path && h.doc) h.doc(a.path);
603
+ }
604
+ async function addArt(x, h) {
605
+ const o = x.o(), w = h.where ? h.where() : {};
606
+ if (h.addDoc) { h.addDoc(); return; }
607
+ const A = await import('./home-adddoc.js');
608
+ VW.drill();
609
+ A.openAddDocVw({ VW, pmPost, toast: h.toast || (() => {}), ws: w.ws || o.ws, scope: 'initiative:' + o.id, title: (x.v() || {}).title || '', back: () => VW.back(),
610
+ onAdded: async () => { ITEMS.delete(o.id); if (h.reload) await h.reload(); VW.back(); } });
611
+ }
612
+
613
+ /** The ⋯ entries the popup adds before the host's own: every part of the old page, as a drill-in, and every suggestion. */
614
+ export function moreItems(x, h) {
615
+ const out = [];
616
+ if (h.allParts) out.push({ label: 'Every part', on: () => h.allParts() });
617
+ if (h.props) out.push({ label: 'Everything PMOS suggests', on: () => h.props() });
618
+ return out.length ? out.concat({ sep: true }) : out;
619
+ }
620
+
621
+ /* ── one level up: a program or a product (boards 26, 27) ── */
622
+ export function levelHtml(L, o = {}) {
623
+ const W = M.levelOf(L, { today: o.today, mode: store.get(SPAN, 'full') }), C = cols(), mode = store.get(SPAN, 'full');
624
+ const mk = M.marksOf(W.span, W.today); W.tx = mk.today;
625
+ const sug = W.suggests.length ? `<div class="pw-sugs" role="list" aria-label="PMOS suggests"><p class="pw-sugh">PMOS suggests</p>${W.suggests.map((s) => sugLine(s)).join('')}</div>` : '';
626
+ // the same Overview shape as an initiative (round 3 point 10): what it is for, its goal, done when; then the status line and Details ›
627
+ const lk = 'level:' + W.kind + ':' + (W.title || ''), S = stOf(lk), open = !!S.details;
628
+ const F = W.facts.filter((f) => f && f.v && !M.idShaped(f.v)).map((f) => ({ ...f, read: true }));
629
+ const facts = open && F.length ? factsHtml(F) : '';
630
+ const det = F.length ? `<button type="button" class="pw-det" data-pw-details="${esc(lk)}" aria-expanded="${open}">${open ? 'Less' : 'Details'}${SVG(open ? P.down : P.right, 14)}</button>` : '';
631
+ const mark = `<span class="pw-spark" role="img" aria-label="PMOS wrote this from the records" title="PMOS wrote this from the records">${SVG(P.spark, 14, 2)}</span>`;
632
+ const ov = `<section class="pw-ov" aria-label="Overview"><div class="pw-ovh"><h3>Overview</h3>${mark}${det}</div>${ovLines(W.overview, lk, false)}${W.overview.status ? `<p class="pw-ostat">${esc(W.overview.status)}</p>` : ''}${sug}${facts}</section>`;
633
+ const head = o.rowsTitle || (W.kind === 'product' ? 'Programs and initiatives' : 'Initiatives');
634
+ const rows = W.rows.map((x) => {
635
+ const tl = C.tl ? `<div class="pw-tl">${barHtml({ ...x, kind: 'stage', tone: x.done ? 'dn' : '' }, W)}${W.tx != null ? `<i class="pw-now" style="left:${W.tx.toFixed(2)}%"></i>` : ''}</div>` : '';
636
+ const lead = x.group ? `<b class="pw-grp">${esc(x.title)}</b>` : `<button type="button" class="pw-stg lv${x.sub ? ' sub' : ''}" data-pw-go="${esc(x.kind + ':' + x.id)}"><b>${esc(x.title)}</b>${SVG(P.right, 14)}${x.count ? `<small>${esc(x.count)}</small>` : ''}</button>`;
637
+ return `<div class="pw-tr pw-sr" role="row"><span class="pw-it">${lead}</span>${C.status ? `<span class="pw-st">${esc(x.stage || '')}</span>` : ''}${C.date ? `<span class="pw-dt${x.late ? ' warn' : ''}">${esc(x.date || '')}</span>` : ''}${tl}</div>`;
638
+ }).join('');
639
+ const wbs = `<section class="pw-sec" aria-label="${esc(head)}"><div class="pw-sech"><h3>${esc(head)}</h3>${!C.tl ? ib('data-pw-tl', 'Show the timeline', P.show, 'xs') : ''}<span class="pw-tools">${C.tl ? `<button type="button" class="pw-span" data-pw-span aria-haspopup="menu">${esc((M.MODES.find((m) => m[0] === mode) || M.MODES[5])[1])}${SVG(P.down, 12)}</button>` : ''}${ib('data-pw-tune="wbs" aria-haspopup="menu"', 'Show or hide columns', P.tune)}</span></div>`
640
+ + `<div class="pw-card pw-wbs${C.tl ? '' : ' notl'}${C.status ? '' : ' nost'}${C.date ? '' : ' nodt'}" role="table"${tlStyle()}>${C.tl ? gripHtml() : ''}${headCells(C, W, mode, W.kind === 'product' ? 'Program or initiative' : 'Initiative').replace('<span role="columnheader">Status</span>', '<span role="columnheader">Stage</span>')}${rows || '<div class="pw-tr pw-empty" role="row"><span>Nothing one level down yet.</span></div>'}</div></section>`;
641
+ return `<div class="pw" data-pw-level>${ov}${wbs}${W.artefacts.length || o.add !== false ? artefactsHtml(W.artefacts, C, o.add !== false, { scope: lk }) : ''}</div>`;
642
+ }
643
+ export function wireLevel(body, h0, L0) {
644
+ if (!body) return;
645
+ body.__pwlh = h0; body.__pwlL = L0;
646
+ if (body.__pwl) return;
647
+ body.__pwl = true;
648
+ wireGrip(body);
649
+ body.addEventListener('click', (e) => {
650
+ if (!e.target.closest('[data-pw-level]')) return;
651
+ const h = body.__pwlh, L = body.__pwlL, redraw = () => { if (h.redraw) h.redraw(); };
652
+ const b = e.target.closest('button'); if (!b || b.disabled) return;
653
+ const d = b.dataset;
654
+ if ('pwTl' in d) { store.set(COLS, { ...cols(), tl: !cols().tl }); redraw(); return; }
655
+ if ('pwSpan' in d) { spanMenu(b, redraw); return; }
656
+ if (d.pwTune) { tuneMenu(b, d.pwTune, redraw); return; }
657
+ if (d.pwDetails) { const S = stOf(d.pwDetails); S.details = !S.details; redraw(); return; }
658
+ if (d.pwVer) { if (ARTOPEN.has(d.pwVer)) ARTOPEN.delete(d.pwVer); else ARTOPEN.add(d.pwVer); redraw(); return; }
659
+ if ((d.pwKeep || d.pwSug) && /^merge:/.test(d.pwKeep || d.pwSug)) { const m = mergeOf(M.levelOf(L()).artefacts); if (m && !sendToChat(m.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
660
+ if (d.pwDrop && /^merge:/.test(d.pwDrop)) { const dd = dropped(); dd.add(d.pwDrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
661
+ if (d.pwLkeep) { const x = M.levelOf(L()).overview.lines.find((q) => q.id === d.pwLkeep); if (x && x.ask && !sendToChat(x.ask) && h.toast) h.toast('Open Ask PMOS to send this.'); return; }
662
+ if (d.pwLdrop) { const dd = dropped(); dd.add(d.pwLdrop); store.set(DROP, [...dd].slice(-200)); redraw(); return; }
663
+ if (d.pwGo) { const i = d.pwGo.indexOf(':'); if (h.go) h.go(d.pwGo.slice(0, i), d.pwGo.slice(i + 1), b); return; }
664
+ if (d.pwArt != null) { const a = M.levelOf(L()).artefacts[+d.pwArt]; if (a && h.art && h.art(a, b)) return; if (a && a.url) window.open(a.url, '_blank', 'noopener'); else if (a && a.path && h.doc) h.doc(a.path); return; }
665
+ if ('pwAddart' in d) { if (h.addDoc) h.addDoc(b); return; }
666
+ if (d.pwKeep || d.pwDrop) { if (h.suggest) h.suggest(d.pwKeep ? 'keep' : 'drop', d.pwKeep || d.pwDrop, b); }
667
+ });
668
+ }