create-pmos 0.396.0 → 0.398.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 (177) hide show
  1. package/package.json +25 -25
  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/scripts/nine-stages.js +49 -20
  6. package/payload/state/discoveries.md +1 -1
  7. package/payload/state/log.md +1 -1
  8. package/workspace/briefing-premium-adddoc-test.js +103 -74
  9. package/workspace/briefing-premium-board-test.js +316 -154
  10. package/workspace/briefing-premium-calendar-2-test.js +135 -195
  11. package/workspace/briefing-premium-calendar-3-test.js +143 -413
  12. package/workspace/briefing-premium-calendar-test.js +86 -185
  13. package/workspace/briefing-premium-doc-edit-test.js +95 -83
  14. package/workspace/briefing-premium-initiative-test.js +166 -294
  15. package/workspace/briefing-premium-insights-test.js +351 -214
  16. package/workspace/briefing-premium-metrics-test.js +53 -118
  17. package/workspace/briefing-premium-products-test.js +40 -27
  18. package/workspace/briefing-premium-sources-test.js +91 -52
  19. package/workspace/briefing-premium-test.js +150 -633
  20. package/workspace/briefing-premium-work-test.js +88 -269
  21. package/workspace/changelog.json +24 -0
  22. package/workspace/fixtures/board-premium-facts.js +2 -1
  23. package/workspace/fixtures/board-premium-jira.js +28 -0
  24. package/workspace/fixtures/board-premium-trail.js +32 -0
  25. package/workspace/fixtures/initiative-premium-facts.js +2 -1
  26. package/workspace/fixtures/initiatives-api/list.json +30 -42
  27. package/workspace/fixtures/initiatives-api/roadmap.json +40 -56
  28. package/workspace/fixtures/initiatives-api/sheet.json +10 -14
  29. package/workspace/fixtures/insights-premium-facts.js +11 -2
  30. package/workspace/fixtures/premium-viewer-fixtures.js +182 -0
  31. package/workspace/guide/briefing-premium.md +3 -1
  32. package/workspace/guide/home.md +47 -0
  33. package/workspace/guide/index.md +2 -0
  34. package/workspace/guide/lifecycle.md +51 -0
  35. package/workspace/home-shot.js +38 -0
  36. package/workspace/lib/agent-roles.js +71 -0
  37. package/workspace/lib/board-premium.js +160 -3
  38. package/workspace/lib/board-trail.js +223 -0
  39. package/workspace/lib/engine/boards.js +15 -14
  40. package/workspace/lib/engine/nine-stages.js +49 -20
  41. package/workspace/lib/engine/signals/detectors.js +13 -11
  42. package/workspace/lib/home-work-item.js +58 -0
  43. package/workspace/lib/insights-goals.js +196 -0
  44. package/workspace/lib/insights-premium.js +126 -1
  45. package/workspace/lib/insights-records.js +101 -0
  46. package/workspace/lib/jira-tickets.js +1 -1
  47. package/workspace/lib/route-modules.js +4 -0
  48. package/workspace/lib/routes-board-premium.js +3 -2
  49. package/workspace/lib/routes-board-trail.js +33 -0
  50. package/workspace/lib/routes-home-desk.js +176 -0
  51. package/workspace/lib/routes-initiatives.js +1 -1
  52. package/workspace/lib/routes-insights-premium.js +19 -3
  53. package/workspace/lib/routes-insights-records.js +129 -0
  54. package/workspace/lib/routes-notes.js +1 -0
  55. package/workspace/lib/routes-viewer.js +108 -0
  56. package/workspace/lib/transcript-steps.js +123 -0
  57. package/workspace/lib/vendor/scripts/nine-stages.js +49 -20
  58. package/workspace/lib/viewer-meeting.js +205 -0
  59. package/workspace/lib/viewer-report.js +89 -0
  60. package/workspace/package-lock.json +2 -2
  61. package/workspace/package.json +1 -1
  62. package/workspace/premium-agreed-viewer-shots.js +76 -0
  63. package/workspace/premium-board-actions-test.js +85 -73
  64. package/workspace/premium-briefing-depth-test.js +66 -53
  65. package/workspace/premium-chat-attach-test.js +54 -63
  66. package/workspace/premium-chat-chart-tab-test.js +35 -36
  67. package/workspace/premium-chat-context-test.js +22 -19
  68. package/workspace/premium-chat-goal-view-test.js +28 -26
  69. package/workspace/premium-chat-notes-test.js +29 -33
  70. package/workspace/premium-chat-report-tab-test.js +35 -25
  71. package/workspace/premium-chat-term-test.js +16 -14
  72. package/workspace/premium-chat-viewer-test.js +60 -53
  73. package/workspace/premium-core-doc-issue-test.js +50 -41
  74. package/workspace/premium-html-viewer-test.js +17 -18
  75. package/workspace/premium-phone-card-test.js +8 -2
  76. package/workspace/premium-phone-room-test.js +42 -31
  77. package/workspace/premium-report-read-test.js +115 -197
  78. package/workspace/premium-viewer-download-test.js +19 -22
  79. package/workspace/premium-viewer-flicker-test.js +11 -16
  80. package/workspace/premium-viewer-share-test.js +6 -9
  81. package/workspace/premium-viewer-test.js +41 -60
  82. package/workspace/premium-vw-backlog-test.js +53 -31
  83. package/workspace/premium-vw-cal-test.js +82 -123
  84. package/workspace/premium-vw-copy-test.js +17 -33
  85. package/workspace/premium-vw-doc-test.js +12 -11
  86. package/workspace/premium-vw-item-test.js +50 -48
  87. package/workspace/premium-vw-jira-test.js +55 -26
  88. package/workspace/premium-vw-meet-test.js +118 -187
  89. package/workspace/premium-vw-notes-test.js +85 -107
  90. package/workspace/premium-vw-rec-test.js +72 -193
  91. package/workspace/premium-vw-slides-test.js +46 -50
  92. package/workspace/premium-welcome-test.js +3 -2
  93. package/workspace/premium-work-depth-test.js +63 -51
  94. package/workspace/public/pm/bd-acts.js +305 -0
  95. package/workspace/public/pm/bd-span.js +224 -0
  96. package/workspace/public/pm/bd-stages.js +47 -0
  97. package/workspace/public/pm/c3-doc-sheet.js +1 -1
  98. package/workspace/public/pm/c3-md.js +3 -395
  99. package/workspace/public/pm/c3-phone-detail.js +1 -1
  100. package/workspace/public/pm/c3-phone-model.js +3 -68
  101. package/workspace/public/pm/chat-term.js +3 -3
  102. package/workspace/public/pm/cozy-board.css +640 -0
  103. package/workspace/public/pm/cozy-home.css +580 -0
  104. package/workspace/public/pm/cozy-home.js +172 -0
  105. package/workspace/public/pm/cozy-initiative.css +138 -0
  106. package/workspace/public/pm/cozy-insights.css +421 -0
  107. package/workspace/public/pm/cozy-md.js +396 -0
  108. package/workspace/public/pm/cozy-nav.js +65 -0
  109. package/workspace/public/pm/cozy-placeholder.js +26 -0
  110. package/workspace/public/pm/cozy-viewer.css +143 -0
  111. package/workspace/public/pm/cozy-viewer.js +144 -0
  112. package/workspace/public/pm/cozy-vw.css +485 -0
  113. package/workspace/public/pm/cozy.css +254 -0
  114. package/workspace/public/pm/home-adddoc.js +48 -0
  115. package/workspace/public/pm/home-app.js +905 -0
  116. package/workspace/public/pm/home-around.js +515 -0
  117. package/workspace/public/pm/home-chat.js +459 -0
  118. package/workspace/public/pm/home-data.js +312 -0
  119. package/workspace/public/pm/home-draft.js +68 -0
  120. package/workspace/public/pm/home-more.js +249 -0
  121. package/workspace/public/pm/home-phone-card.js +109 -0
  122. package/workspace/public/pm/home-work.js +519 -0
  123. package/workspace/public/pm/lifecycle-lens-model.js +45 -27
  124. package/workspace/public/pm/lifecycle-lens.js +22 -11
  125. package/workspace/public/pm/phone-moment.js +69 -0
  126. package/workspace/public/pm/pm-work-view.js +1 -1
  127. package/workspace/public/pm/premium-attach.js +4 -0
  128. package/workspace/public/pm/premium-board.js +544 -253
  129. package/workspace/public/pm/premium-brief.js +1 -1
  130. package/workspace/public/pm/premium-chart-tab.js +110 -62
  131. package/workspace/public/pm/premium-chat.js +17 -10
  132. package/workspace/public/pm/premium-deck.js +3 -3
  133. package/workspace/public/pm/premium-first.js +25 -21
  134. package/workspace/public/pm/premium-initiative-head.js +138 -0
  135. package/workspace/public/pm/premium-initiative.js +28 -4
  136. package/workspace/public/pm/premium-insights.js +950 -440
  137. package/workspace/public/pm/premium-meeting.js +61 -549
  138. package/workspace/public/pm/premium-notes.js +1 -1
  139. package/workspace/public/pm/premium-report-frame.css +20 -0
  140. package/workspace/public/pm/premium-report-read.js +509 -480
  141. package/workspace/public/pm/premium-report-tab.js +87 -63
  142. package/workspace/public/pm/premium-shell.js +107 -124
  143. package/workspace/public/pm/premium-viewer.js +27 -1
  144. package/workspace/public/pm/premium-vw-cal.js +187 -48
  145. package/workspace/public/pm/premium-vw-doc.css +6 -0
  146. package/workspace/public/pm/premium-vw-doc.js +40 -2
  147. package/workspace/public/pm/premium-vw-file.js +2 -2
  148. package/workspace/public/pm/premium-vw-jira-model.js +22 -5
  149. package/workspace/public/pm/premium-vw-jira.css +11 -0
  150. package/workspace/public/pm/premium-vw-jira.js +11 -4
  151. package/workspace/public/pm/premium-vw-meet.js +6 -83
  152. package/workspace/public/pm/premium-vw-mtg.js +731 -0
  153. package/workspace/public/pm/premium-vw-notes.js +56 -69
  154. package/workspace/public/pm/premium-vw-open.js +35 -0
  155. package/workspace/public/pm/premium-vw-page.js +16 -0
  156. package/workspace/public/pm/premium-vw-rec.js +11 -215
  157. package/workspace/public/pm/premium-vw-slides.css +5 -0
  158. package/workspace/public/pm/premium-vw-slides.js +44 -8
  159. package/workspace/public/pm/term-view.js +22 -0
  160. package/workspace/public/premium-board.html +57 -64
  161. package/workspace/public/premium-chat.html +7 -33
  162. package/workspace/public/premium-initiative.html +8 -41
  163. package/workspace/public/premium-insights.html +63 -62
  164. package/workspace/public/premium-viewer.html +20 -0
  165. package/workspace/public/premium-work.html +6 -72
  166. package/workspace/public/premium.html +21 -66
  167. package/workspace/public/vendor/nunito-var.woff2 +0 -0
  168. package/workspace/server.js +25 -3
  169. package/workspace/test-files.json +1 -0
  170. package/workspace/test-lists/home-libs.json +9 -0
  171. package/workspace/test-lists/premium-agreed-viewer.json +9 -0
  172. package/workspace/test-lists/premium-report-read.json +1 -1
  173. package/workspace/test-lists/premium-vw-agreed.json +9 -0
  174. package/workspace/test-lists/premium-vw-notes.json +1 -1
  175. package/workspace/third-party/README.md +1 -0
  176. package/workspace/public/pm/premium-work.js +0 -719
  177. package/workspace/public/pm/premium.js +0 -1133
@@ -0,0 +1,305 @@
1
+ /* pm/bd-acts.js — the Board's features the Agreed design has no frame for, kept working as plain, minimal versions in the cozy style
2
+ * (initiative premium-agreed-design; PM instruction 2026-10-22: "do not drop their function"). Each one carries a small "Waiting for design" tag,
3
+ * opens in the Board's side panel (never the old dialog) and presses the same routes the console uses, behind the launch nonce:
4
+ * New initiative POST /api/boards/asks/add { board, line, source } then /asks/accept { board, ask, title, lane, anchor }; anchors from GET /api/boards/anchors
5
+ * New asks POST /api/boards/asks/accept (the form above, from the intake draft) · /asks/decline { board, ask, why }
6
+ * a row's actions POST /api/boards/move { board, id, to } · /api/lifecycle { initiative_id, state, reason, back? } · /api/boards/archive { board, id, archived, reason? },
7
+ * each with Undo, which writes the opposite line through the same route
8
+ * Cancelled, archived the board's own lists, with Reopen and Restore
9
+ * Documents the board's core documents with their state; Draft it posts POST /api/core-docs/draft { scope, key }
10
+ * Sprint and release the sprint and the release as the Jira reading and the release record hold them
11
+ * Metrics GET /api/board-metrics-premium (read-only)
12
+ * Notifications the toolbar's bell: the rows where something waits on you, and the new asks
13
+ * Find, Filter the rows on screen by title, owner and lane (the page's own filter state)
14
+ * List, By stage the rows as a list and as one column per stage
15
+ * Nothing here invents a value: what a record does not hold is not drawn. */
16
+ import { pmPost } from './http.js';
17
+ import { $, $$, esc } from './premium-shell.js';
18
+
19
+ export const WTAG = '<span class="bd-wtag" title="This part has no Agreed design yet. It works as a plain version until it has one.">Waiting for design</span>';
20
+ const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
21
+ const X = 'M6 6l12 12M18 6L6 18';
22
+ const LANES = [['feature', 'Feature'], ['discovery', 'Discovery'], ['chore', 'Chore'], ['incident', 'Incident'], ['content', 'Content'], ['prototype', 'Prototype']];
23
+ const BACK = [['two', 'In 2 weeks', 14], ['month', 'In a month', 30], ['quarter', 'Next quarter', 80], ['none', 'No date', null]];
24
+ const WHY = ['No longer needed', 'Replaced by another initiative', 'Not worth it now', 'Hit a kill condition', 'Other'];
25
+ const AWHY = ['Not related to this board', 'Old idea, never started', 'Duplicate', 'Other'];
26
+ const dayIso = (n) => { const t = new Date(Date.now() + n * 86400000); return t.getFullYear() + '-' + String(t.getMonth() + 1).padStart(2, '0') + '-' + String(t.getDate()).padStart(2, '0'); };
27
+
28
+ let A = null; // the page: { M(), load(), say(msg, undo?), panel(html, from), close(), redraw(), F, rowOf(key), statusOf(r), openIni(r) }
29
+ export function init(api) { A = api; }
30
+ const M = () => A.M();
31
+ const post = (p, body) => pmPost(p, { ws: M().board.ws, ...body });
32
+ const errOf = (r) => (r && r.error) || 'Nothing was recorded. The server did not say why.';
33
+
34
+ /** A side panel of this module: its title, the tag, a close button and the body. */
35
+ function panel(title, body, from, eye = 'Board') {
36
+ A.panel(`<div class="pk-h"><div class="pk-ht"><p class="pk-eye">${esc(eye)} ${WTAG}</p><h2 id="pkTitle">${esc(title)}</h2></div><div class="pk-tools"><button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(X)}</button></div></div><div class="pk-b bd-pl">${body}</div>`, from);
37
+ }
38
+ const msg = (id) => `<p class="bd-amsg" id="${id}" role="status"></p>`;
39
+ async function press(btn, m, fn) {
40
+ btn.disabled = true; if (m) m.textContent = '';
41
+ const r = await fn().catch(() => null);
42
+ if (r && r.ok === true) return r;
43
+ btn.disabled = false; if (m) m.textContent = errOf(r); return null;
44
+ }
45
+ async function done(r, text, undo) { A.close(); A.say(text, undo); await A.load(); return r; }
46
+ const tagHead = (text) => `<p class="bd-whead">${WTAG}<span>${esc(text)}</span></p>`;
47
+
48
+ /* ── List and By stage ─────────────────────────────────────────────────────────────────────────────────────────── */
49
+ export function listHtml(L) {
50
+ if (!L.length) return tagHead('The list of initiatives') + '<p class="bd-amut">No initiative matches.</p>';
51
+ const row = (r) => { const s = A.statusOf(r); return `<button type="button" class="bd-lr ini2" data-key="${esc(r.key)}"><span class="t"><b>${esc(r.title)}</b><small>${esc([r.owner || 'No owner', r.lane].filter(Boolean).join(' · '))}</small></span><span class="st">${esc((r.track && r.track.label) || r.stage || '')}</span><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone}"></i>${esc(s.text)}</span><span class="fin${r.over ? ' over' : ''}">${esc(r.finish || 'Not planned')}</span></button>`; };
52
+ return tagHead('The list of initiatives, in the board\'s order') + `<div class="bd-rows" role="list">${L.map(row).join('')}</div>` + goneLink();
53
+ }
54
+ export function stagesHtml(L) {
55
+ const S = M().steps || [];
56
+ const col = (s, j) => { const rs = L.filter((r) => r.track && r.track.k === j); return `<section class="bd-col" aria-label="${esc(s.label)}"><h3>${s.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(s.label)} <span>${s.count}</span></h3>${rs.map((r) => { const st = A.statusOf(r); return `<button type="button" class="bd-card ini2" data-key="${esc(r.key)}"><b>${esc(r.title)}</b><span class="cs s-${st.tone}"><i class="cz-dot ${st.tone}"></i>${esc(st.text)}</span></button>`; }).join('') || '<p class="bd-amut">None loaded</p>'}</section>`; };
57
+ return tagHead('One column per stage of the board') + `<div class="bd-cols">${S.map(col).join('')}</div>`;
58
+ }
59
+
60
+ /* ── Cancelled and archived ────────────────────────────────────────────────────────────────────────────────────── */
61
+ export function goneLink() {
62
+ const G = M().initiatives.gone || { cancelled: [], archived: [] }, nc = G.cancelled.length, na = G.archived.length;
63
+ if (!nc && !na) return '';
64
+ return `<p class="bd-gone"><button type="button" class="dlink" data-act="gone">${[nc ? nc + ' cancelled' : '', na ? na + ' archived' : ''].filter(Boolean).join(' · ')}</button></p>`;
65
+ }
66
+ function openGone(from) {
67
+ const G = M().initiatives.gone || { cancelled: [], archived: [] };
68
+ const row = (r, k) => `<div class="bd-ar"><span class="t"><b>${esc(r.title)}</b><small>${esc(k === 'archived' ? (r.acts && r.acts.archived && (r.acts.archived.into ? 'Merged into ' + (r.acts.archived.intoTitle || r.acts.archived.into) : r.acts.archived.reason)) || 'Archived' : (r.acts && r.acts.reason) || 'Cancelled')}</small></span><button type="button" class="bd-btn" data-act="${k === 'archived' ? 'restore' : 'reopen'}" data-id="${esc(r.key)}">${k === 'archived' ? 'Restore' : 'Reopen'}</button></div>`;
69
+ panel('Cancelled and archived', (G.cancelled.length ? `<p class="bd-albl">Cancelled</p>${G.cancelled.map((r) => row(r, 'cancelled')).join('')}` : '') + (G.archived.length ? `<p class="bd-albl">Archived</p>${G.archived.map((r) => row(r, 'archived')).join('')}` : '') + (!G.cancelled.length && !G.archived.length ? '<p class="bd-amut">No initiative of this board is cancelled or archived.</p>' : '') + msg('goneM'), from);
70
+ }
71
+
72
+ /* ── a row's actions: move, hold, resume, cancel, reopen, archive, restore, each with Undo ─────────────────────────── */
73
+ const life = (id, state, reason, back) => post('/api/lifecycle', { initiative_id: id, state, reason: reason || '', ...(back ? { back } : {}) });
74
+ const arch = (id, archived, reason) => post('/api/boards/archive', { board: M().board.id, id, archived, ...(reason ? { reason } : {}) });
75
+ const move = (id, to) => post('/api/boards/move', { board: M().board.id, id, to });
76
+ const prevOf = (r) => ({ life: r.acts.life, reason: r.acts.reason, backDay: r.acts.backDay || null });
77
+ const lifeBack = (r, p) => (p.life === 'hold' ? life(r.id, 'on-hold', p.reason, p.backDay) : p.life === 'cancelled' ? life(r.id, 'cancelled', p.reason) : life(r.id, 'active', 'undo'));
78
+ function itemsOf(r) {
79
+ const a = r.acts || { stages: [], stage: '' }, cur = a.stages.indexOf(a.stage), out = [];
80
+ if (a.archived) return [['restore', 'Restore', 'Back in the lists, as it was']];
81
+ if (a.life === 'cancelled') return [['reopen', 'Reopen', 'Back to ' + (a.stage || 'its stage') + ', active again']];
82
+ if (!M().board.self && !a.life && cur >= 0) {
83
+ if (a.stages[cur + 1]) out.push(['mv:' + (cur + 1), 'Move to ' + a.stages[cur + 1], 'The next stage of its workflow']);
84
+ if (cur > 0) out.push(['mv:' + (cur - 1), 'Back to ' + a.stages[cur - 1], 'The stage before']);
85
+ }
86
+ if (a.life === 'hold') out.push(['resume', 'Resume', 'Back to ' + (a.stage || 'its stage') + ', active again']);
87
+ else out.push(['hold', 'Put on hold', 'Pause it; keeps its stage and work']);
88
+ out.push(['cancel', 'Cancel', 'Stop it for good, with a reason'], ['archive', 'Archive', 'Out of every list; restore any time']);
89
+ return out;
90
+ }
91
+ function openRowActs(r, from) {
92
+ const self = M().board.self ? '<p class="bd-amut">The stage of a PMOS-self initiative comes from the repository. It moves when the files land.</p>' : '';
93
+ panel('Initiative actions', `<p class="bd-asub">${esc(r.title)}</p>${self}<div class="bd-alist">${itemsOf(r).map(([k, l, s]) => `<button type="button" class="bd-ai" data-act="row" data-k="${esc(k)}" data-id="${esc(r.key)}"><b>${esc(l)}</b><small>${esc(s)}</small></button>`).join('')}</div>${msg('rowM')}`, from, r.title);
94
+ }
95
+ async function runRow(r, k, btn) {
96
+ const a = r.acts, p = prevOf(r), m = $('#rowM');
97
+ if (k.startsWith('mv:')) {
98
+ const to = a.stages[+k.slice(3)], fromStage = a.stage; if (!to) return;
99
+ const res = await press(btn, m, () => move(r.id, to)); if (!res) return;
100
+ const w = Array.isArray(res.warnings) && res.warnings.length ? ' Warning: ' + res.warnings.join('; ') + '. Warnings never block.' : '';
101
+ await done(res, 'Moved to ' + to + '. Recorded as a move line in the board ledger.' + w, async () => { const u = await move(r.id, fromStage); A.say(u && u.ok ? 'Back in ' + fromStage + '.' : errOf(u)); await A.load(); });
102
+ return;
103
+ }
104
+ if (k === 'hold') return formHold(r);
105
+ if (k === 'cancel') return formReason(r, 'cancel');
106
+ if (k === 'archive') return formReason(r, 'archive');
107
+ if (k === 'resume' || k === 'reopen') {
108
+ const res = await press(btn, m, () => life(r.id, 'active', k === 'resume' ? 'resumed' : 'reopened')); if (!res) return;
109
+ await done(res, r.title + ' is active again. Recorded as a lifecycle line.', async () => { const u = await lifeBack(r, p); A.say(u && u.ok ? 'Undone.' : errOf(u)); await A.load(); });
110
+ return;
111
+ }
112
+ if (k === 'restore') {
113
+ const res = await press(btn, m, () => arch(r.id, false)); if (!res) return;
114
+ await done(res, r.title + ' is restored. Recorded in the board ledger.', async () => { const u = await arch(r.id, true, a.archived && a.archived.reason); A.say(u && u.ok ? r.title + ' is archived again.' : errOf(u)); await A.load(); });
115
+ }
116
+ }
117
+ const radios = (name, L, cur) => `<div class="bd-rad" role="radiogroup">${L.map(([v, l]) => `<label><input type="radio" name="${name}" value="${esc(v)}"${v === cur ? ' checked' : ''}><span>${esc(l)}</span></label>`).join('')}</div>`;
118
+ function formHold(r) {
119
+ panel('Put on hold', `<p class="bd-asub">${esc(r.title)}</p><form class="bd-form" data-form="hold" data-id="${esc(r.key)}"><label>Why it is paused <em>optional</em><textarea name="why" rows="2" maxlength="500"></textarea></label><p class="bd-albl">Check back</p>${radios('back', BACK.map((b) => [b[0], b[1]]), 'month')}<p class="bd-amut">Keeps its stage, its work and its history. Recorded as one on-hold line in lifecycle.jsonl; Undo writes the state it had before.</p>${msg('formM')}<div class="bd-arow"><button type="submit" class="bd-btn solid">Put on hold</button><button type="button" class="bd-btn" data-pk="close">Not now</button></div></form>`, null, r.title);
120
+ }
121
+ function formReason(r, kind) {
122
+ const L = kind === 'cancel' ? WHY : AWHY;
123
+ panel(kind === 'cancel' ? 'Cancel the initiative' : 'Archive the initiative', `<p class="bd-asub">${esc(r.title)}</p><form class="bd-form" data-form="${kind}" data-id="${esc(r.key)}"><p class="bd-albl">Why</p>${radios('why', L.map((w) => [w, w]), kind === 'archive' ? L[0] : '')}<label>Note <em>optional</em><textarea name="note" rows="2" maxlength="300"></textarea></label><p class="bd-amut">${kind === 'cancel' ? 'Keeps its stage, its work and its history. Reopen it any time. Recorded as one cancelled line in lifecycle.jsonl.' : 'It leaves every list and count of the board. Nothing is deleted. Recorded as one archive line in the board ledger.'}</p>${msg('formM')}<div class="bd-arow"><button type="submit" class="bd-btn solid">${kind === 'cancel' ? 'Cancel initiative' : 'Archive'}</button><button type="button" class="bd-btn" data-pk="close">Not now</button></div></form>`, null, r.title);
124
+ }
125
+
126
+ /* ── New initiative and New asks ──────────────────────────────────────────────────────────────────────────────── */
127
+ let anchors = null;
128
+ async function anchorsOf() {
129
+ const b = M().board, key = b.ws + '/' + b.id;
130
+ if (anchors && anchors.key === key) return anchors.list;
131
+ let r = null;
132
+ try { r = await (await fetch('/api/boards/anchors?ws=' + encodeURIComponent(b.ws || '') + '&board=' + encodeURIComponent(b.id || ''), { credentials: 'same-origin' })).json(); } catch { r = null; }
133
+ anchors = { key, list: r && r.ok && Array.isArray(r.anchors) ? r.anchors : null };
134
+ return anchors.list;
135
+ }
136
+ async function openNew(from, ask) {
137
+ const d = ask ? ask.draft || {} : { title: '', lane: 'feature', anchor: '' }, first = (M().board.stages || [])[0] || 'the first stage';
138
+ panel(ask ? 'Accept ask' : 'New initiative', `${ask ? `<p class="bd-quote">“${esc(ask.line)}”</p>` : ''}<form class="bd-form" data-form="new"${ask ? ` data-ask="${esc(ask.id)}"` : ''}><label>Title<input name="title" maxlength="120" value="${esc(d.title || '')}" placeholder="For example: Per-key API usage for partners"></label><label>Lane<select name="lane">${LANES.map(([v, l]) => `<option value="${v}"${v === (d.lane || 'feature') ? ' selected' : ''}>${l}</option>`).join('')}</select></label><label>Anchor<span id="anW"><select name="anchor" disabled><option>Reading the anchors</option></select></span></label><p class="bd-amut">Every initiative anchors to a KR or a declared health budget. Unanchored work is rejected. It lands in ${esc(first)}.</p>${msg('formM')}<div class="bd-arow"><button type="submit" class="bd-btn solid">${ask ? 'Accept into ' : 'Create in '}${esc(first)}</button><button type="button" class="bd-btn" data-pk="close">Not now</button></div></form>`, from);
139
+ const L = await anchorsOf(), w = $('#anW'); if (!w) return;
140
+ w.innerHTML = L && L.length ? `<select name="anchor"><option value="">Choose a KR or a health budget</option>${L.map((x) => `<option value="${esc(x.value)}"${x.value === d.anchor ? ' selected' : ''}>${esc(x.label || x.value)}</option>`).join('')}</select>`
141
+ : `<input name="anchor" maxlength="120" value="${esc(d.anchor || '')}" placeholder="A KR id or health:<budget>">`;
142
+ }
143
+ function openAsks(from) {
144
+ const A0 = M().asks;
145
+ if (M().board.self) { panel('New asks', '<p class="bd-amut">PMOS-self has no ask source. New work starts at the pmos-router skill.</p>', from); return; }
146
+ const L = (A0 && A0.rows) || [];
147
+ panel('New asks', A0 == null || A0.missing ? '<p class="bd-amut">The new asks could not be read, so none is shown.</p>' : L.length ? L.map((a) => `<div class="bd-ask"><p class="bd-quote">“${esc(a.line)}”</p><small>${esc([a.source, a.by, a.at].filter(Boolean).join(' · '))}</small><div class="bd-arow"><button type="button" class="bd-btn solid" data-act="accept" data-id="${esc(a.id)}">Accept</button><button type="button" class="bd-btn" data-act="decline" data-id="${esc(a.id)}">Decline</button></div></div>`).join('') : '<p class="bd-amut">No new ask waits for triage.</p>', from);
148
+ }
149
+ function openDecline(a) {
150
+ panel('Decline ask', `<p class="bd-quote">“${esc(a.line)}”</p><form class="bd-form" data-form="decline" data-ask="${esc(a.id)}"><label>Reason<textarea name="why" rows="3" maxlength="500" required></textarea></label><p class="bd-amut">The reason is kept with the ask in the board ledger.</p>${msg('formM')}<div class="bd-arow"><button type="submit" class="bd-btn solid">Decline</button><button type="button" class="bd-btn" data-pk="close">Not now</button></div></form>`, null);
151
+ }
152
+
153
+ /* ── Sprint and release, Metrics ─────────────────────────────────────────────────────────────────────────────── */
154
+ function openSprint(from) {
155
+ const s = M().sprint || {}, R = M().release || {};
156
+ const sp = s.name ? `<div class="bd-kv"><span>Sprint</span><b>${esc(s.name)}</b><span>Dates</span><b>${esc([s.start, s.end].filter(Boolean).join(' – '))}</b>${s.cap ? `<span>Where</span><b>${esc(s.cap)}</b>` : ''}${s.goal ? `<span>Goal</span><b>${esc(s.goal)}</b>` : ''}${s.counts ? `<span>Tickets</span><b>${s.counts.done} done · ${s.counts.doing} doing · ${s.counts.todo} to do</b>` : ''}</div>` : '<p class="bd-amut">No sprint is on record. A Jira read writes one.</p>';
157
+ const rel = R.name ? `<div class="bd-kv"><span>Release</span><b>${esc(R.name)}</b><span>Date</span><b>${esc(R.at || '')}${R.away ? ' · ' + esc(R.away) : ''}</b>${(R.ini || []).length ? `<span>Carries</span><b>${R.ini.map((x) => esc(x.title)).join(', ')}</b>` : ''}</div>` : '<p class="bd-amut">No release is on record.</p>';
158
+ panel('Sprint and release', `<p class="bd-albl">Sprint</p>${sp}<p class="bd-albl">Release</p>${rel}<p class="bd-amut">As the cached Jira reading and the release record hold them. Nothing here changes Jira.</p>`, from);
159
+ }
160
+ /** Metrics: the board's four measures (GET /api/board-metrics-premium), each with its value, its week, its change, its target where Insights set
161
+ * one, and a fold with its definition and its values by week. Targets and longer ranges live on Insights. Asks again while Blocked and Idle
162
+ * are still derived. */
163
+ async function openMetrics(from, again) {
164
+ if (!again) panel('Metrics', '<p class="bd-amut" id="metW">Reading the metrics…</p>', from);
165
+ let r = null;
166
+ try { r = await (await fetch('/api/board-metrics-premium?ws=' + encodeURIComponent(M().board.ws || ''), { credentials: 'same-origin' })).json(); } catch { r = null; }
167
+ const w = $('#metW'); if (!w) return; // the panel was closed
168
+ if (!r || !r.ok || !r.model) { w.textContent = 'The metrics could not be read, so none is shown.' + (r && r.error ? ' The reason: ' + r.error + '.' : ''); return; }
169
+ const m = r.model, ws = encodeURIComponent(M().board.ws || '');
170
+ const tile = (t) => {
171
+ const weeks = (t.wk || []).map((k, i) => `<span>${esc(k)}</span><b>${t.ser && t.ser[i] != null ? esc(String(t.ser[i])) : 'Not kept yet'}</b>`).join('');
172
+ return `<details class="bd-met${t.look || t.kind === 'warn' || t.kind === 'bad' ? ' look' : ''}" data-met="${esc(t.key)}"><summary><span>${esc(t.label)}</span><b>${esc(t.absent || t.value || '')}</b><small>${esc(t.absent ? t.why || '' : t.text || '')}</small>`
173
+ + `${t.change && !t.absent ? `<small>${esc(t.change.txt)}</small>` : ''}${t.chip ? `<em class="bd-mchip${t.ok ? ' ok' : ''}">${esc(t.chip)}${t.targetTxt ? ' · ' + esc(t.targetTxt) : ''}</em>` : t.look ? '<em class="bd-mchip">Needs a look</em>' : ''}</summary>`
174
+ + `<p class="bd-amut">${esc(t.def || '')}</p>${weeks ? `<div class="bd-kv">${weeks}</div>` : ''}</details>`;
175
+ };
176
+ w.outerHTML = `<div id="metW"><p class="bd-amut">${esc(m.header || '')}${m.lead ? ' · ' + esc(m.lead) : ''}</p><div class="bd-mets">${(m.tiles || []).map(tile).join('')}</div><p class="bd-amut">${esc(m.note || '')} <a class="bd-alink" href="/premium-insights.html?ws=${ws}">Targets and longer ranges are on Insights</a>.</p></div>`;
177
+ if (m.pending) setTimeout(() => { if ($('#metW')) openMetrics(null, true); }, 3000);
178
+ }
179
+ /* ── Find and Filter: the page's filter state (F.q, F.owners, F.lanes) ─────────────────────────────────────────── */
180
+ function openFind(from) {
181
+ panel('Find', `<label class="bd-form"><span class="bd-albl">Find an initiative by its title</span><input id="bdQ" type="search" maxlength="80" value="${esc(A.F.q || '')}" placeholder="Type part of a title"></label><p class="bd-amut" id="bdQn"></p>`, from);
182
+ const q = $('#bdQ'); if (q) { q.focus(); q.oninput = () => { A.F.q = q.value.trim(); A.redraw(); $('#bdQn').textContent = A.F.q ? 'The board shows the initiatives whose title holds “' + A.F.q + '”.' : ''; }; }
183
+ }
184
+ function openFilter(from) {
185
+ const rows = M().initiatives.list.rows, owners = [...new Set(rows.map((r) => r.owner || 'No owner'))].sort(), lanes = [...new Set(rows.map((r) => r.lane).filter(Boolean))].sort();
186
+ const box = (k, v) => `<label class="bd-chk"><input type="checkbox" data-flt="${k}" value="${esc(v)}"${A.F[k].has(v) ? ' checked' : ''}><span>${esc(v)}</span></label>`;
187
+ panel('Filter', `<p class="bd-albl">Owner</p><div class="bd-chks">${owners.map((o) => box('owners', o)).join('')}</div><p class="bd-albl">Lane</p><div class="bd-chks">${lanes.map((l) => box('lanes', l)).join('')}</div><div class="bd-arow"><button type="button" class="bd-btn" data-act="fclear">Clear</button></div>`, from);
188
+ }
189
+
190
+ /* ── Documents ───────────────────────────────────────────────────────────────────────────────────────────────── */
191
+ export function docsHtml() {
192
+ const D = M().docs || { rows: [] }, L = D.rows || [];
193
+ const add = '<button type="button" class="bd-btn" id="addDoc" data-act="adddoc">Add a document</button>';
194
+ const head = `<div class="bd-dochd">${tagHead('The board\'s core documents' + (D.cap ? ' · ' + D.cap : ''))}${D.scope ? add : ''}</div>`;
195
+ if (!L.length) return head + `<p class="bd-amut">${D.missing ? 'The core documents could not be read, so none is shown.' : 'No document is on this board yet.'}</p>`;
196
+ const row = (d) => `<div class="bd-lr doc" role="listitem" data-doc-key="${esc(d.key)}"><span class="t">${d.path ? `<button type="button" class="bd-dlink" data-act="cdoc" data-key="${esc(d.key)}">${esc(d.title)}</button>` : `<b>${esc(d.title)}</b>`}<small>${esc([d.what, d.cadence, d.by, d.added ? 'added ' + d.added : ''].filter(Boolean).join(' · '))}</small></span><span class="st">${esc(d.state || '')}</span><span class="pth">${esc(d.path || '')}</span>${d.act && d.act.kind === 'draft' ? `<button type="button" class="bd-btn" data-act="draft" data-key="${esc(d.key)}"${d.running ? ' disabled' : ''}>${d.running ? 'Drafting' : esc(d.act.label || 'Draft it')}</button>` : '<span></span>'}</div>`;
197
+ return head + `<div class="bd-rows" role="list">${L.map(row).join('')}</div>`;
198
+ }
199
+ /** A core document with a file: its text, read from the repository (GET /api/doc), and for a draft the Issue it press
200
+ * (POST /api/core-docs/issue { scope, key, slot }), which marks the draft issued and sends nothing to anyone. */
201
+ async function openCoreDoc(key, from) {
202
+ const D = M().docs || {}, d = (D.rows || []).find((x) => x.key === key); if (!d || !d.path) return;
203
+ const draft = d.st === 'draft' && !!d.slot;
204
+ const bar = draft ? `<div class="bd-issue" data-issue-bar="draft"><span>A draft. Nothing is sent: issuing marks it issued and sends nothing to anyone.</span><button type="button" class="bd-btn solid" data-act="issue" data-key="${esc(d.key)}">Issue it</button></div>`
205
+ : `<div class="bd-issue done" data-issue-bar="done"><span>${esc(d.state || 'Issued')}. Nothing was sent to anyone.</span></div>`;
206
+ panel(d.title, `${bar}${msg('formM')}<p class="bd-amut">${esc(d.path)}</p><pre class="bd-doc" id="cdText">Reading the document…</pre>`, from, 'Document');
207
+ let text = null; try { const res = await fetch('/api/doc?ws=' + encodeURIComponent(M().board.ws || '') + '&path=' + encodeURIComponent(d.path), { credentials: 'same-origin' }); text = res.ok ? await res.text() : null; } catch { text = null; }
208
+ const el = $('#cdText'); if (el) el.textContent = text == null ? d.path + ' could not be read.' : text;
209
+ }
210
+ async function issueDoc(key, btn) {
211
+ const D = M().docs || {}, d = (D.rows || []).find((x) => x.key === key); if (!d) return;
212
+ const r = await press(btn, $('#formM'), () => post('/api/core-docs/issue', { scope: D.scope, key: d.key, slot: d.slot }));
213
+ if (!r) return;
214
+ A.say('Issued. Nothing was sent to anyone.'); await A.load(); openCoreDoc(key, null);
215
+ }
216
+ /** Add a document: a board document written by you or drafted by PMOS, kept in PMOS or linked to a page elsewhere (POST /api/custom-docs/add).
217
+ * PMOS saves the title and the address on the board's record; it does not read or sync the linked page. */
218
+ const DKINDS = ['In PMOS', 'Confluence', 'Google Docs', 'Google Slides'];
219
+ function openAddDoc(from) {
220
+ panel('Add a document', `<form class="bd-form" data-form="adddoc"><label>Title<input name="title" maxlength="80" placeholder="For example: UAT plan"></label><p class="bd-albl">Who writes it</p>${radios('writer', [['drafts', 'PMOS drafts it'], ['you', 'I write it']], 'drafts')}<label>Where it lives<select name="kind">${DKINDS.map((k) => `<option>${k}</option>`).join('')}</select></label><label>Address<input name="url" maxlength="300" placeholder="https://" disabled></label><p class="bd-amut">It is saved on the board's record. PMOS does not read or sync a linked page.</p>${msg('formM')}<div class="bd-arow"><button type="submit" class="bd-btn solid">Add</button><button type="button" class="bd-btn" data-pk="close">Not now</button></div></form>`, from);
221
+ const f = $('#peek form[data-form="adddoc"]'); if (f) f.kind.onchange = () => { f.url.disabled = f.kind.value === 'In PMOS'; };
222
+ }
223
+ /* ── the presses ─────────────────────────────────────────────────────────────────────────────────────────────── */
224
+ /* ── Notifications (the toolbar's bell): what waits on you on this board and the new asks ───────────────────────────────── */
225
+ function openBell(from) {
226
+ const rows = (M().rows || []).filter((r) => r.track && r.track.you), na = (M().chips || {}).asks;
227
+ const list = rows.map((r) => `<button type="button" class="bd-ai" data-act="ini" data-id="${esc(r.key)}"><b>${esc(r.title)}</b><small>${esc(r.track.you)}</small></button>`).join('');
228
+ const asks = na ? `<button type="button" class="bd-ai" data-act="asks"><b>${na} new ${na === 1 ? 'ask' : 'asks'}</b><small>Waiting for triage</small></button>` : '';
229
+ panel('Notifications', list || asks ? `<div class="bd-alist">${list}${asks}</div>` : '<p class="bd-amut">Nothing on this board waits on you, and no new ask waits for triage.</p>', from);
230
+ }
231
+ export const open = { new: openNew, asks: openAsks, row: openRowActs, sprint: openSprint, metrics: openMetrics, find: openFind, filter: openFilter, gone: openGone, bell: openBell };
232
+ const askOf = (id) => ((M().asks && M().asks.rows) || []).find((a) => a.id === id);
233
+ document.addEventListener('click', async (e) => {
234
+ const b = e.target.closest('[data-act]'); if (!b || !A || !M()) return;
235
+ const k = b.dataset.act;
236
+ if (k === 'gone') { openGone(b); return; }
237
+ if (k === 'ini') { const r = A.rowOf(b.dataset.id); if (r && A.openIni) A.openIni(r); return; }
238
+ if (k === 'asks') { openAsks(b); return; }
239
+ if (k === 'adddoc') { openAddDoc(b); return; }
240
+ if (k === 'cdoc') { openCoreDoc(b.dataset.key, b); return; }
241
+ if (k === 'issue') { issueDoc(b.dataset.key, b); return; }
242
+ if (k === 'accept') { const a = askOf(b.dataset.id); if (a) openNew(null, a); return; }
243
+ if (k === 'decline') { const a = askOf(b.dataset.id); if (a) openDecline(a); return; }
244
+ if (k === 'fclear') { A.F.owners.clear(); A.F.lanes.clear(); $$('[data-flt]').forEach((x) => { x.checked = false; }); A.redraw(); return; }
245
+ if (k === 'row') { const r = A.rowOf(b.dataset.id); if (r) runRow(r, b.dataset.k, b); return; }
246
+ if (k === 'reopen' || k === 'restore') { const r = A.rowOf(b.dataset.id); if (r) runRow(r, k, b); return; }
247
+ if (k === 'draft') {
248
+ b.disabled = true;
249
+ const r = await pmPost('/api/core-docs/draft', { ws: M().board.ws, scope: M().docs.scope, key: b.dataset.key }).catch(() => null);
250
+ if (r && r.ok) { A.say('The agent is drafting it. It lands as a draft for you to review; nothing is sent.'); await A.load(); } else { b.disabled = false; A.say(errOf(r)); }
251
+ }
252
+ });
253
+ document.addEventListener('change', (e) => {
254
+ const c = e.target.closest('[data-flt]'); if (!c || !A) return;
255
+ const S = A.F[c.dataset.flt]; if (c.checked) S.add(c.value); else S.delete(c.value); A.redraw();
256
+ });
257
+ document.addEventListener('submit', async (e) => {
258
+ const f = e.target.closest('form[data-form]'); if (!f || !A) return;
259
+ e.preventDefault();
260
+ const kind = f.dataset.form, m = $('#formM'), go = f.querySelector('[type="submit"]'), val = (n) => (f.elements[n] ? String(f.elements[n].value || '').trim() : '');
261
+ if (kind === 'new') {
262
+ const title = val('title'), lane = val('lane'), anchor = val('anchor'), askId = f.dataset.ask || null;
263
+ if (!title) { m.textContent = 'Give it a title.'; return; }
264
+ if (!anchor) { m.textContent = 'Choose an anchor. Unanchored work is rejected.'; return; }
265
+ const res = await press(go, m, async () => {
266
+ let ask = askId;
267
+ if (!ask) { const r0 = await post('/api/boards/asks/add', { board: M().board.id, line: title, source: 'New initiative, typed by you' }); if (!r0 || r0.ok !== true) return r0; ask = r0.ask && r0.ask.id; }
268
+ return post('/api/boards/asks/accept', { board: M().board.id, ask, title, lane, anchor });
269
+ });
270
+ if (res) await done(res, '“' + title + '” is ' + (askId ? 'accepted' : 'created') + ' in ' + (res.stage || 'the first stage') + ', anchored to ' + anchor + '.');
271
+ return;
272
+ }
273
+ if (kind === 'adddoc') {
274
+ const title = val('title'), kd = val('kind'), url = val('url'), writer = (f.querySelector('input[name="writer"]:checked') || {}).value || 'drafts';
275
+ if (!title) { m.textContent = 'Give the document a title.'; return; }
276
+ if (kd !== 'In PMOS' && !url) { m.textContent = 'Paste the address of the ' + kd + ' page, or choose In PMOS.'; return; }
277
+ const body = { scope: M().docs.scope, title, writer, ...(kd !== 'In PMOS' ? { kind: kd, url } : {}) };
278
+ const res = await press(go, m, () => post('/api/custom-docs/add', body));
279
+ if (res) await done(res, '“' + title + '” is added to the board\'s documents.');
280
+ return;
281
+ }
282
+ if (kind === 'decline') {
283
+ const why = val('why').replace(/\s+/g, ' '); if (!why) { m.textContent = 'Say why. A decline needs a reason.'; return; }
284
+ const res = await press(go, m, () => post('/api/boards/asks/decline', { board: M().board.id, ask: f.dataset.ask, why }));
285
+ if (res) await done(res, 'Ask declined. The reason is kept in the board ledger.');
286
+ return;
287
+ }
288
+ const r = A.rowOf(f.dataset.id); if (!r) return;
289
+ const p = prevOf(r);
290
+ if (kind === 'hold') {
291
+ const bk = BACK.find((q) => q[0] === val('back')) || BACK[1], day = bk[2] != null ? dayIso(bk[2]) : null;
292
+ const res = await press(go, m, () => life(r.id, 'on-hold', val('why'), day));
293
+ if (res) await done(res, r.title + ' is on hold. Recorded as a lifecycle line.', async () => { const u = await lifeBack(r, p); A.say(u && u.ok ? r.title + ' is back as it was.' : errOf(u)); await A.load(); });
294
+ return;
295
+ }
296
+ const why = val('why'); if (!why) { m.textContent = 'Pick a reason.'; return; }
297
+ const reason = why + (val('note') ? ': ' + val('note').replace(/\s+/g, ' ') : '');
298
+ if (kind === 'cancel') {
299
+ const res = await press(go, m, () => life(r.id, 'cancelled', reason));
300
+ if (res) await done(res, r.title + ' is cancelled. Recorded as a lifecycle line.', async () => { const u = await lifeBack(r, p); A.say(u && u.ok ? r.title + ' is back as it was.' : errOf(u)); await A.load(); });
301
+ } else if (kind === 'archive') {
302
+ const res = await press(go, m, () => arch(r.id, true, reason));
303
+ if (res) await done(res, r.title + ' is archived. Recorded in the board ledger.', async () => { const u = await arch(r.id, false); A.say(u && u.ok ? r.title + ' is restored.' : errOf(u)); await A.load(); });
304
+ }
305
+ });
@@ -0,0 +1,224 @@
1
+ /* pm/bd-span.js — the premium Board's timeline (initiative premium-agreed-design, B2; the AgBoardTimeline, AgBoardTimelinePhone, AgBoardTlYear
2
+ * and AgBoardTl5y frames). PMOS plan dates against the Jira forecast:
3
+ * · Quarter: one row per initiative over seven weeks (three on a phone), the plan bar with its done part, the days over, the Jira forecast,
4
+ * the sprint band, the today line and the release line, with their labels under the axis. Monitor and Evaluate are hidden here.
5
+ * · Year: themes, with their initiatives as bars inside, coloured by theme.
6
+ * · 5 yr: themes only, as one phase each from the dates on record; past 18 months is directional.
7
+ * · Sprint, Half and 2 yr have no Agreed frame: they are plain versions of Quarter (Sprint) and Year (Half, 2 yr), with a "Waiting for design" tag.
8
+ * Themes come from GET /api/board-trail (lib/board-trail.js): one per objective, named by the PRD's theme: key, else the objective's title. The Group
9
+ * control groups the long spans by theme, lane or owner. Milestones: a release's sign-off (◆ with its name), "Push tickets" where drafted tickets
10
+ * wait on the Commit, and "after <initiative>" where a dependency is not done. A bar is drawn only from dates a record holds. Pure: rows and the
11
+ * model in, markup out. */
12
+ import { esc } from './premium-shell.js';
13
+
14
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
15
+ const day = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
16
+ export const md = (d) => MON[d.getMonth()] + ' ' + d.getDate();
17
+ const addDays = (d, n) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
18
+ const addMonths = (d, n) => new Date(d.getFullYear(), d.getMonth() + n, 1);
19
+ export const SPANS = [['sprint', 'Sprint'], ['quarter', 'Quarter'], ['half', 'Half'], ['year', 'Year'], ['y2', '2 yr'], ['y5', '5 yr']];
20
+ /** The spans the Agreed design draws; the others show the "Waiting for design" card. */
21
+ export const DRAWN = new Set(['quarter', 'year', 'y5']);
22
+ /** The trail's theme tones (lib/board-trail.js TONES), in THEME_TONES order. */
23
+ const TONE_KEYS = ['grey', 'blue', 'green', 'amber', 'violet', 'teal'];
24
+ const WTAG = '<span class="bd-wtag" title="This span has no Agreed design yet. It works as a plain version until it has one.">Waiting for design</span>';
25
+ export const GROUPS = [['theme', 'Theme'], ['lane', 'Lane'], ['owner', 'Owner']];
26
+ /** Theme colours, in the order the Agreed design's themes take them (grey, blue, green, amber, then two more). */
27
+ export const THEME_TONES = ['var(--cz-c-8c929b)', 'var(--cz-c-4894ea)', 'var(--cz-c-5e9c6a)', 'var(--cz-c-d4a13a)', 'var(--cz-c-b07cc6)', 'var(--cz-c-d9773f)'];
28
+ const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
29
+ const FLAG = 'M5 21V4M5 4h11l-2 4 2 4H5';
30
+ const LINK = 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1';
31
+
32
+ /** The window and the ticks of a span, around `now`. Quarter: from the Monday of last week, seven weeks (a phone: this week's Monday, three). */
33
+ export function windowOf(span, now, phone, sprint) {
34
+ const t = new Date(now.getFullYear(), now.getMonth(), now.getDate());
35
+ const mon = addDays(t, -((t.getDay() + 6) % 7));
36
+ if (span === 'sprint') {
37
+ // the sprint the Jira reading holds; with none, two weeks from this Monday
38
+ const a = sprint && day(sprint.start), b = sprint && day(sprint.end);
39
+ const from = a && b && b > a ? a : mon, to = a && b && b > a ? addDays(b, 1) : addDays(mon, 14);
40
+ const n = Math.round((to - from) / 86400000), step = phone ? Math.max(2, Math.ceil(n / 4)) : n > 16 ? 2 : 1;
41
+ const ticks = []; for (let i = 0; i < n; i += step) { const d = addDays(from, i); ticks.push({ at: d, label: md(d) }); }
42
+ return { from, to, ticks };
43
+ }
44
+ if (span === 'half') {
45
+ const from = addMonths(t, -1), to = addMonths(from, 6);
46
+ const ticks = []; for (let i = 0; i < 6; i++) { const d = addMonths(from, i); ticks.push({ at: d, label: MON[d.getMonth()], sub: d.getMonth() % 3 === 0 ? 'Q' + (d.getMonth() / 3 + 1) : '' }); }
47
+ return { from, to, ticks };
48
+ }
49
+ if (span === 'y2') {
50
+ const q0 = new Date(t.getFullYear(), t.getMonth() - (t.getMonth() % 3), 1), from = addMonths(q0, -3), to = addMonths(from, 24);
51
+ const ticks = []; for (let i = 0; i < 24; i += 3) { const d = addMonths(from, i); ticks.push({ at: d, label: 'Q' + (d.getMonth() / 3 + 1), sub: '’' + String(d.getFullYear()).slice(2) }); }
52
+ return { from, to, ticks };
53
+ }
54
+ if (span === 'quarter') {
55
+ const from = phone ? mon : addDays(mon, -7), n = phone ? 3 : 7, to = addDays(from, 7 * n);
56
+ const ticks = []; for (let i = 0; i < n; i++) { const d = addDays(from, 7 * i); ticks.push({ at: d, label: md(d) }); }
57
+ return { from, to, ticks };
58
+ }
59
+ if (span === 'year') {
60
+ const from = addMonths(t, -6), to = addMonths(from, 12);
61
+ const ticks = []; for (let i = 0; i < 12; i++) { const d = addMonths(from, i); ticks.push({ at: d, label: MON[d.getMonth()], sub: d.getMonth() % 3 === 0 ? 'Q' + (d.getMonth() / 3 + 1) + (d.getFullYear() !== t.getFullYear() ? ' ’' + String(d.getFullYear()).slice(2) : '') : '' }); }
62
+ return { from, to, ticks };
63
+ }
64
+ const from = new Date(t.getFullYear() - 1, 0, 1), to = new Date(t.getFullYear() + 5, 0, 1);
65
+ const ticks = []; for (let y = from.getFullYear(); y < to.getFullYear(); y++) ticks.push({ at: new Date(y, 0, 1), label: String(y), sub: 'H1 · H2' });
66
+ return { from, to, ticks };
67
+ }
68
+
69
+ const pctOf = (W) => (d) => Math.max(0, Math.min(100, ((d - W.from) / (W.to - W.from)) * 100));
70
+ const P = (x) => x.toFixed(2) + '%';
71
+ const doneOf = (r) => { const p = r.track && r.track.prog; return p ? Math.max(0, Math.min(100, (p.done / Math.max(1, p.total)) * 100)) : 0; };
72
+ const toneOf = (r) => (r.late ? 'late' : r.status === 'at risk' ? 'risk' : r.track && r.track.you ? 'you' : r.status === 'on track' ? 'ok' : 'q');
73
+ const dated = (r) => day(r.start) || day(r.end) || (r.track && day(r.track.forecast));
74
+ const hidden = (r) => r.track && (r.track.key === 'monitor' || r.track.key === 'evaluate');
75
+
76
+ /** One initiative's marks on the quarter: the plan with its done part, the days over, the forecast past the plan, and one label after the furthest mark. */
77
+ function qBar(r, X, now, phone) {
78
+ const s = day(r.start), e = day(r.end), fc = r.track && day(r.track.forecast), tone = toneOf(r);
79
+ let out = marks(r, X, now, phone);
80
+ if (s && e) {
81
+ const l = X(s), w = Math.max(0.8, X(e) - l);
82
+ out += `<span class="tg-bar t-${tone}${r.track && r.track.ms ? ' ms' : ''}" style="left:${P(l)};width:${P(w)}" title="PMOS plan ${esc(md(s))} to ${esc(md(e))}"><b style="width:${doneOf(r).toFixed(1)}%"></b></span>`;
83
+ const over = r.over && now > e, late = fc && fc > e, words = [];
84
+ if (over) { out += `<span class="tg-over" style="left:${P(X(e))};width:${P(Math.max(0.5, X(now) - X(e)))}"></span>`; words.push(r.overDays + ' ' + (r.overDays === 1 ? 'day' : 'days') + ' over'); }
85
+ if (late) { out += `<span class="tg-fc" style="left:${P(X(e))};width:${P(X(fc) - X(e))}" title="Jira forecast ${esc(md(fc))}"></span>`; words.push('Jira forecast ' + md(fc)); }
86
+ if (words.length && !phone) out += `<span class="tg-lab ${over ? 'late' : 'fc'}" style="left:${P(Math.max(over ? X(now) : 0, late ? X(fc) : 0))}">${esc(words.join(' · '))}</span>`;
87
+ } else if (fc) {
88
+ out += `<span class="tg-fc solo" style="left:${P(Math.max(0, X(fc) - 3))};width:3%" title="Jira forecast ${esc(md(fc))}"></span>${phone ? '' : `<span class="tg-lab fc" style="left:${P(X(fc))}">Jira forecast ${esc(md(fc))}</span>`}`;
89
+ } else {
90
+ const d = s || e; out += `<i class="tg-dm" style="left:${P(X(d))}" title="${s ? 'Starts' : 'Ends'} ${esc(md(d))}"></i>`;
91
+ }
92
+ return out;
93
+ }
94
+
95
+ /** A row's milestones: its release's sign-off (◆ at the release date), "Push tickets" where drafted tickets wait on your Commit (today), and
96
+ * "after <initiative>" at the plan start where a dependency is not done. Each one only from a record. */
97
+ function marks(r, X, now, phone) {
98
+ const T = r.trail || {}, out = [], rd = r.release && day(r.release.iso);
99
+ const at = (d) => d && X(d) > 0 && X(d) < 100;
100
+ if (rd && at(rd) && r.track && (r.track.key === 'deliver' || r.track.you)) out.push(`<i class="tg-msd" style="left:${P(X(rd))}" title="${esc(r.release.name)} sign-off"></i>${phone ? '' : `<span class="tg-msl" style="left:${P(X(rd))}">${esc(r.release.name)} sign-off</span>`}`);
101
+ if (T.you && T.you.kind === 'commit' && at(now)) out.push(`<i class="tg-msd you" style="left:${P(X(now))}" title="${esc(T.you.text)}"></i>${phone ? '' : `<span class="tg-msl you" style="left:${P(X(now))}">Push tickets · now</span>`}`);
102
+ const dep = (T.deps || []).find((d) => d.known && !d.done), s = day(r.start);
103
+ if (dep && !phone) out.push(`<span class="tg-dep" style="left:${P(s && at(s) ? X(s) : 0)}" title="Waits on ${esc(dep.title || dep.id)}">${SV(LINK)}after ${esc(dep.title || dep.id)}</span>`);
104
+ return out.join('');
105
+ }
106
+
107
+ /** The overlay of a quarter row: week lines, the sprint band, the release line and the today line. */
108
+ function overlay(W, X, now, sprint, rel) {
109
+ const tl = W.ticks.slice(1).map((k) => `<i class="tg-gl" style="left:${P(X(k.at))}"></i>`).join('');
110
+ const sa = sprint && day(sprint.start), sb = sprint && day(sprint.end);
111
+ const band = sa && sb && sb > W.from && sa < W.to ? `<i class="tg-sb" style="left:${P(X(sa))};width:${P(X(sb) - X(sa))}"></i>` : '';
112
+ const ra = rel && day(rel.iso), rl = ra && ra > W.from && ra < W.to ? `<i class="tg-rl" style="left:${P(X(ra))}"></i>` : '';
113
+ const tn = now > W.from && now < W.to ? `<u class="tg-td" style="left:${P(X(now))}"></u>` : '';
114
+ return tl + band + rl + tn;
115
+ }
116
+
117
+ /** The quarter's markup. o: { now, phone, sel, status(r) → { tone, text }, hiddenCount, askHref } */
118
+ function quarter(rows, M, o) {
119
+ const now = o.now, sprint = M.jira && M.jira.sprint, rel = M.jira && M.jira.release;
120
+ const W = windowOf(o.span === 'sprint' ? 'sprint' : 'quarter', now, o.phone, sprint), X = pctOf(W);
121
+ const shown = rows.filter((r) => !hidden(r)), list = shown.filter(dated), none = shown.filter((r) => !dated(r));
122
+ const ov = overlay(W, X, now, sprint, rel);
123
+ const ra = rel && day(rel.iso), sa = sprint && day(sprint.start), sb = sprint && day(sprint.end);
124
+ const askBtn = none.length ? `<a class="bd-chip tg-ask" id="askDates" href="${esc(o.askHref(none))}">${SV('M4 5h16v11h-9l-5 4v-4H4z')}Ask to propose dates</a>` : '';
125
+ if (o.phone) {
126
+ const head = `<div class="tgp-h">${W.ticks.map((k) => `<span>${esc(k.label)}</span>`).join('')}</div>`;
127
+ const body = list.map((r) => { const s = o.status(r); return `<button type="button" class="tgp-r${o.sel === r.key ? ' sel' : ''}" data-key="${esc(r.key)}"><span class="tgp-t"><b>${esc(r.title)}</b><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone}"></i>${esc(s.text)}</span></span><span class="tgp-p">${ov}${qBar(r, X, now, true)}</span></button>`; }).join('');
128
+ const foot = `<div class="tgp-f"><span>Today ${esc(md(now))}</span>${ra ? `<span class="tg-rel">${SV(FLAG)}${esc(rel.name)} · ${esc(md(ra))}</span>` : ''}</div>`;
129
+ const below = `${none.length ? `<div class="tg-none"><span>${none.length} ${none.length === 1 ? 'has' : 'have'} no dates</span>${askBtn}</div>` : ''}<p class="tg-note">Grey bars are PMOS plan dates. The dark part is points done in Jira.</p>`;
130
+ return { html: `<div class="tgp" data-span="${o.span === 'sprint' ? 'sprint' : 'quarter'}">${head}<div class="tgp-b">${body || '<p class="tg-empty">No initiative on screen has a date on record.</p>'}</div>${foot}</div>${below}`, none };
131
+ }
132
+ const head = `<div class="tg-r tg-h"><button type="button" class="tg-n tg-help" data-rules aria-haspopup="dialog" title="How the timeline groups by span"><b>Initiative</b></button><div class="tg-p">${W.ticks.map((k) => `<span style="left:${P(X(k.at))}"><b>${esc(k.label)}</b></span>`).join('')}</div></div>`;
133
+ const lgd = '<div class="tg-lgd" aria-hidden="true"><span><i class="k dn"></i>done in Jira (points)</span><span><i class="k pl"></i>PMOS plan</span><span><i class="k fc"></i>Jira forecast</span></div>';
134
+ const body = list.map((r) => `<div class="tg-r${o.sel === r.key ? ' sel' : ''}" data-row="${esc(r.key)}"><button type="button" class="tg-n ini2" data-key="${esc(r.key)}"><b>${esc(r.title)}</b><small>${esc([r.owner, r.track ? r.track.label : r.stage].filter(Boolean).join(' · '))}</small></button><div class="tg-p">${ov}${qBar(r, X, now, false)}</div></div>`).join('');
135
+ const axis = `<div class="tg-ax"><span></span><div class="tg-p">${now > W.from && now < W.to ? `<span class="tg-axl td" style="left:${P(X(now))}">Today</span>` : ''}${sa && sb && sb > W.from && sa < W.to ? `<span class="tg-axl sb" style="left:${P(X(sa))}">Jira ${esc(sprint.name.toLowerCase())} · ${esc(md(sa))} – ${esc(md(sb))}</span>` : ''}${ra && ra > W.from && ra < W.to ? `<span class="tg-axl rl" style="left:${P(X(ra))}">${SV(FLAG)}${esc(rel.name)} · ${esc(md(ra))}</span>` : ''}</div></div>`;
136
+ const foot = `<div class="tg-ft">${none.length ? `<span class="tg-none"><b>${none.length} ${none.length === 1 ? 'has' : 'have'} no dates:</b> <span>${esc(none.slice(0, 4).map((r) => r.title).join(', '))}${none.length > 4 ? ' and ' + (none.length - 4) + ' more' : ''}</span>${askBtn}</span>` : '<span></span>'}${o.hiddenCount ? `<span class="tg-hid">Monitor and Evaluate hidden · ${o.hiddenCount}</span>` : ''}</div>`;
137
+ const tag = o.span === 'sprint' ? `<p class="bd-whead">${WTAG}<span>The Sprint span: the current sprint's days${sprint ? ', ' + esc(sprint.name) : ''}</span></p>` : '';
138
+ return { html: `${tag}<div class="tg tg-q" data-span="${o.span === 'sprint' ? 'sprint' : 'quarter'}">${head}<div class="tg-body">${lgd}${body || '<p class="tg-empty">No initiative on screen has a date on record.</p>'}</div>${axis}${foot}</div>`, none };
139
+ }
140
+
141
+ /** The groups of the long spans. By theme (default): the trail's themes (one per objective; the PRD's theme: names it, theme_note: says what it
142
+ * is for, theme_color: picks its colour), in the trail's order; a row the trail has not reached yet takes its anchor's objective. By lane or by owner. */
143
+ const cap = (x) => x.charAt(0).toUpperCase() + x.slice(1);
144
+ function themesOf(rows, o = {}) {
145
+ const g = o.group || 'theme', T = o.themes || [], byKey = new Map(T.map((t) => [t.key, t]));
146
+ const groups = new Map();
147
+ for (const r of rows) {
148
+ let k, base;
149
+ if (g === 'lane') { k = r.lane || 'none'; base = { key: k, label: r.lane ? cap(r.lane) : 'No lane', what: 'Lane', kind: 'lane' }; }
150
+ else if (g === 'owner') { k = r.owner || 'none'; base = { key: k, label: r.owner || 'No owner', what: 'Owner', kind: 'owner' }; }
151
+ else {
152
+ const th = r.trail && byKey.get(r.trail.theme);
153
+ if (th) { k = th.key; base = { key: k, label: th.name, what: th.note || (th.key === 'health' ? 'Upkeep anchored to a health budget' : [th.period ? th.period + ' objective' : 'Objective', th.from ? '' : 'name it with theme: in the PRD'].filter(Boolean).join(' · ')), kind: th.key === 'health' ? 'health' : 'kr', tone: th.tone }; }
154
+ else { const t = r.theme || { key: 'none', label: 'No anchor', kind: 'none', period: '' }; k = 'a:' + t.key; base = { key: k, label: t.label, what: t.kind === 'kr' ? t.period + ' objective' : t.kind === 'health' ? 'Health budgets' : 'No theme', kind: t.kind }; }
155
+ }
156
+ if (!groups.has(k)) groups.set(k, { ...base, rows: [] });
157
+ groups.get(k).rows.push(r);
158
+ }
159
+ const list = [...groups.values()];
160
+ if (g === 'theme' && T.length) list.sort((a, b) => { const ia = T.findIndex((t) => t.key === a.key), ib = T.findIndex((t) => t.key === b.key); return (ia < 0 ? 99 : ia) - (ib < 0 ? 99 : ib); });
161
+ return list.map((t, i) => ({ ...t, tone: THEME_TONES[t.tone && TONE_KEYS.includes(t.tone) ? TONE_KEYS.indexOf(t.tone) : i % THEME_TONES.length] }));
162
+ }
163
+ /** A group's left cell: its colour and name, what it is for, and its counts. */
164
+ function themeCell(t, wide) {
165
+ const late = t.rows.filter((r) => r.late).length, risk = t.rows.filter((r) => r.status === 'at risk').length;
166
+ const anchor = t.kind === 'health' ? 'health budget' : t.kind === 'kr' || t.kind === 'other' ? t.rows.map((r) => r.kr).filter(Boolean)[0] || '' : '';
167
+ return `<div class="tg-n tg-tn"><b><i class="tg-sw" style="background:${t.tone}"></i>${esc(t.label)}</b><small>${esc(t.what)}</small><em>${t.rows.length} ${t.rows.length === 1 ? 'initiative' : 'initiatives'}${anchor ? ' · ' + esc(anchor) : ''}${!wide && late ? ' · ' + late + ' late' : ''}${!wide && risk ? ' · ' + risk + ' at risk' : ''}</em></div>`;
168
+ }
169
+ /** The releases the rows ride on, as milestones of the long spans: name and date, once each. */
170
+ function releasesOf(rows) {
171
+ const seen = new Map();
172
+ for (const r of rows) { const d = r.release && day(r.release.iso); if (d && !seen.has(r.release.name)) seen.set(r.release.name, { name: r.release.name, at: d }); }
173
+ return [...seen.values()];
174
+ }
175
+
176
+ /** Year: themes with their initiatives as bars inside. */
177
+ function year(rows, o) {
178
+ const sp = o.span === 'half' || o.span === 'y2' ? o.span : 'year';
179
+ const now = o.now, W = windowOf(sp, now), X = pctOf(W), T = themesOf(rows, o), G = (GROUPS.find((x) => x[0] === (o.group || 'theme')) || GROUPS[0])[1];
180
+ const tn = now > W.from && now < W.to ? X(now) : null;
181
+ const head = `<div class="tg-r tg-h"><button type="button" class="tg-n tg-help" data-rules aria-haspopup="dialog" title="How the timeline groups by span"><b>${G}</b><small>${T.length} ${T.length === 1 ? G.toLowerCase() : G.toLowerCase() + 's'} · ${rows.length} ${rows.length === 1 ? 'initiative' : 'initiatives'}</small></button><div class="tg-p">${W.ticks.map((k) => `<span style="left:${P(X(k.at))}"><b>${esc(k.label)}</b>${k.sub ? `<small>${esc(k.sub)}</small>` : ''}</span>`).join('')}</div></div>`;
182
+ // AgBoardTlYear draws no release line or flag: a release shows as the ◆ at the end of a bar that rides on it
183
+ const grid = W.ticks.slice(1).map((k) => `<i class="tg-gl" style="left:${P(X(k.at))}"></i>`).join('') + (tn != null ? `<u class="tg-td" style="left:${P(tn)}"></u>` : '');
184
+ const body = T.map((t) => {
185
+ const lines = t.rows.filter(dated).map((r) => {
186
+ const s = day(r.start) || day(r.end) || day(r.track && r.track.forecast), e = day(r.end) || s, l = X(s), w = Math.max(1.2, X(e) - l), st = o.status(r);
187
+ return `<button type="button" class="tg-line" data-key="${esc(r.key)}" aria-label="${esc(r.title)}"><span class="tg-yb${r.track && r.track.ms ? ' ms' : ''}" style="left:${P(l)};width:${P(w)};--tone:${t.tone}"><b style="width:${doneOf(r).toFixed(1)}%"></b><em><i class="cz-dot ${toneOf(r)}"></i><strong>${esc(r.title)}</strong> ${esc([r.track ? r.track.label : '', st.tone === 'late' || st.tone === 'risk' ? st.text.toLowerCase() : ''].filter(Boolean).join(' · '))}</em></span></button>`;
188
+ }).join('');
189
+ return `<div class="tg-r tg-th">${themeCell(t, false)}<div class="tg-p tg-stack">${grid}${lines || '<span class="tg-nod">No dates on record</span>'}</div></div>`;
190
+ }).join('');
191
+ const pill = tn != null ? `<span class="tg-today" style="left:calc(230px + (100% - 230px) * ${(tn / 100).toFixed(4)})">Today · ${esc(md(now))}</span>` : '';
192
+ const tag = sp !== 'year' ? `<p class="bd-whead">${WTAG}<span>The ${sp === 'half' ? 'Half' : '2 yr'} span: the Year view over ${sp === 'half' ? 'six months' : 'two years'}</span></p>` : '';
193
+ return { html: `${tag}<div class="tg tg-y" data-span="${sp}">${head}<div class="tg-body">${pill}${body || '<p class="tg-empty">No initiative is on screen.</p>'}</div><div class="tg-ft"><span>Bars show initiatives inside their ${G.toLowerCase()}. The darker part is done. <i class="cz-ms" aria-hidden="true"></i> is a milestone.</span><button type="button" class="tg-go" data-span-go="quarter">Switch to Quarter to see one row per initiative</button></div></div>`, none: [] };
194
+ }
195
+
196
+ /** 5 yr: themes only, as one phase each from the earliest date on record to the latest; past 18 months is directional (dashed). */
197
+ function fiveYear(rows, o) {
198
+ const now = o.now, W = windowOf('y5', now), X = pctOf(W), T = themesOf(rows, o), G = (GROUPS.find((x) => x[0] === (o.group || 'theme')) || GROUPS[0])[1];
199
+ const far = addMonths(now, 18), fx = X(far), tn = now > W.from && now < W.to ? X(now) : null;
200
+ const head = `<div class="tg-r tg-h"><button type="button" class="tg-n tg-help" data-rules aria-haspopup="dialog" title="How the timeline groups by span"><b>${G}</b><small>what each ${G.toLowerCase()} is for</small></button><div class="tg-p">${fx < 100 ? `<i class="tg-dir" style="left:${P(fx)}"></i>` : ''}${W.ticks.map((k) => `<span style="left:${P(X(k.at))}"><b>${esc(k.label)}</b><small>${esc(k.sub)}</small></span>`).join('')}</div></div>`;
201
+ const grid = W.ticks.slice(1).map((k) => `<i class="tg-gl" style="left:${P(X(k.at))}"></i>`).join('') + (fx < 100 ? `<i class="tg-dir" style="left:${P(fx)}"></i>` : '') + (tn != null ? `<u class="tg-td" style="left:${P(tn)}"></u>` : '');
202
+ const body = T.map((t) => {
203
+ const ds = t.rows.flatMap((r) => [day(r.start), day(r.end), r.track && day(r.track.forecast)]).filter(Boolean).sort((a, b) => a - b);
204
+ const shipped = t.rows.filter((r) => r.track && r.track.k >= 6).length, planned = t.rows.filter((r) => !r.track || r.track.k < 4).length, active = t.rows.length - shipped - planned;
205
+ const a = ds[0], b = ds[ds.length - 1];
206
+ const words = [active ? active + ' active' : '', planned ? planned + ' planned' : '', shipped ? shipped + ' shipped' : ''].filter(Boolean).join(' · ');
207
+ // a milestone sits under the phase, in the theme's colour, with its name right of the ◆ (AgBoardTl5y)
208
+ const ms = releasesOf(t.rows).filter((m) => X(m.at) > 0 && X(m.at) < 100).map((m) => `<i class="tg-msd" style="left:${P(X(m.at))};--tone:${t.tone}" title="${esc(m.name)} · ${esc(md(m.at))}"></i><span class="tg-msl" style="left:${P(X(m.at))}">${esc(m.name)}</span>`).join('');
209
+ const ph = ds.length ? `<button type="button" class="tg-phase${a > far ? ' dir' : ''}" data-tgtheme="${esc(t.key)}" style="left:${P(X(a))};width:${P(Math.max(2, X(b) - X(a)))};--tone:${t.tone}"><b>${esc(t.label)}</b><small>${esc(words)}${a > far ? ' · directional' : ''}</small></button>${ms}` : '<span class="tg-nod">No dates on record</span>';
210
+ return `<div class="tg-r tg-th tg-5">${themeCell(t, true)}<div class="tg-p">${grid}${ph}</div></div>`;
211
+ }).join('');
212
+ const lab = (x) => `calc(230px + (100% - 230px) * ${(x / 100).toFixed(4)})`; // the 230 px theme column
213
+ const marks = (tn != null ? `<span class="tg-today" style="left:${lab(tn)}">Today</span>` : '') + (fx < 100 ? `<span class="tg-far" style="left:${lab(fx)}">Beyond 18 months · directional</span>` : '');
214
+ return { html: `<div class="tg tg-5y" data-span="y5">${head}<div class="tg-body">${marks}${body || '<p class="tg-empty">No initiative is on screen.</p>'}</div><div class="tg-ft"><span>Only themes and their phases at this span. Dashed means directional, not committed.</span><span class="tg-go2">Open a phase to see its initiatives</span></div></div>`, none: [] };
215
+ }
216
+
217
+ /** The timeline's markup for the rows on screen. → { html, none: [rows with no dates] } */
218
+ export function timelineHtml(rows, M, span, o = {}) {
219
+ const opt = { now: new Date(), phone: false, sel: null, status: () => ({ tone: 'q', text: '' }), hiddenCount: 0, askHref: () => '#', ...o };
220
+ opt.span = span;
221
+ if (span === 'year' || span === 'half' || span === 'y2') return year(rows, opt);
222
+ if (span === 'y5') return fiveYear(rows, opt);
223
+ return quarter(rows, M, opt);
224
+ }