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
@@ -1,233 +1,570 @@
1
- /* pm/premium-board.js — the premium Board page (initiative briefing-premium-board, slice 5). Reads GET /api/board-premium and draws the model
2
- * lib/board-premium.js builds from the routes the production Initiatives page reads: the Initiatives card (List, By stage, Timeline), the Sprint and
3
- * Coming up cards, Core documents, the dock and the standard dialog. The presses are Draft it on a core document, through POST /api/core-docs/draft,
4
- * and the board's own presses of pm/premium-acts.js (initiative premium-board-actions): the New asks card, New initiative, and a row's menu (move,
5
- * hold, cancel, archive and their Undo). Issue it on a document draft, read in a dialog, is POST /api/core-docs/issue (initiative premium-core-doc-issue). */
6
- import { openWorkItem, recordPress } from './premium-vw-item.js';
1
+ /* pm/premium-board.js — the premium Board in the Agreed design (initiative premium-agreed-design: the AgBoard* frames; built on briefing-premium-board).
2
+ * Reads GET /api/board-premium and draws the model lib/board-premium.js builds from the routes the production Initiatives page reads.
3
+ * · one toolbar: the product picker, the view toggle, Find, Filter, the shell's bell, New initiative and the shell's ⋯ menu; under it the
4
+ * Initiatives and Documents tabs and the chips (Jira read time, sprint and release, new asks, late, at risk, blocked, idle, This sprint).
5
+ * · the stage track (default): each initiative is a row across the six stages and two milestones (◆), with the parts or tickets counted
6
+ * toward the output that finishes its current step. Monitor and Evaluate rows fold under the table after the first of each.
7
+ * · the timeline (pm/bd-span.js): Quarter, Year and 5 yr.
8
+ * · a row opens the initiative panel and a ticket opens the Jira ticket panel, in the side panel (a bottom sheet on a phone).
9
+ * · the Board has no chat: "Ask about this" sends the question to Home (/premium.html?ask=<initiative>&q=<question>).
10
+ * What the Agreed design has no frame for (List, By stage, Documents, the Sprint, Half and 2 yr spans, Find, Filter, New initiative, the new
11
+ * asks, the sprint and release, Metrics, cancelled and archived, the initiative actions) works as a plain version with a "Waiting for design"
12
+ * tag (pm/bd-acts.js), in the side panel, and no older UI.
13
+ * After the model, GET /api/board-trail (lib/board-trail.js) adds what the model does not carry: days in the step and the usual days, the
14
+ * skipped steps and why, the parts of the output, what waits on you, tickets drafted in PMOS, PRD drift, links, dependencies and themes.
15
+ * Where no record holds a value for an initiative, the element says so: nothing is invented. */
7
16
  import { pmPost } from './http.js';
8
- import { openBacklog } from './premium-vw-backlog.js';
9
- import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, CHECK, AI, store, crumbHtml, wireCrumb, chatAbout, kv, H, openAddDoc, setPageGaps } from './premium-shell.js';
10
- import { issueBody } from './premium-doc-edit.js';
11
- import { mountDocSheet } from './premium-doc-sheet.js';
12
- import * as MT from './premium-metric-tiles.js';
13
- import { openSprint } from './premium-vw-jira.js';
14
- import { dotsBtn, openMenu, closeMenu, menuKey, asksHtml, onAsks, openIniForm } from './premium-acts.js';
17
+ import { $, $$, esc, store, crumbHtml, wireCrumb, chatAbout, setPageGaps } from './premium-shell.js';
18
+ import { mountNav } from './cozy-nav.js';
19
+ import { stepsHelpHtml, rulesHelpHtml } from './bd-stages.js';
20
+ import { timelineHtml, SPANS, GROUPS, md } from './bd-span.js';
21
+ import * as Acts from './bd-acts.js';
22
+ import { open as viewerOpen } from './cozy-viewer.js';
15
23
 
16
- const MODE_KEY = 'pmos.premium.openAs';
17
- let M = null; // the model
18
- const docSheet = mountDocSheet({ ws: () => M.board.ws, scope: () => M.docs.scope, rows: () => M.docs.rows, reload: () => load(), noteKey: (d) => 'doc:' + M.board.id + ':' + d.key, sub: () => M.board.name, again: true });
19
- let view = 'list';
20
- let shown = 25; // rows of the list on screen
24
+ const VIEW_KEY = 'pmos.board.view', SPAN_KEY = 'pmos.board.span', GROUP_KEY = 'pmos.board.group';
25
+ let M = null; // the model
26
+ let TR = null; // the trail (GET /api/board-trail): { usual, themes, items: { [id]: item } }
27
+ let group = GROUPS.some(([k]) => k === store.get(GROUP_KEY)) ? store.get(GROUP_KEY) : 'theme';
28
+ let view = ['track', 'stages', 'time', 'list'].includes(store.get(VIEW_KEY)) ? store.get(VIEW_KEY) : 'track';
29
+ let span = SPANS.some(([k]) => k === store.get(SPAN_KEY)) ? store.get(SPAN_KEY) : 'quarter';
30
+ let tab = 'ini';
21
31
  let readTimer = null;
22
- let showGone = false; // the cancelled and archived rows under the list
23
- wireRail('init');
24
- /** The context of the board presses (pm/premium-acts.js). */
25
- const ctxOf = () => ({ ws: M.board.ws, board: M.board.id, boardName: M.board.name, self: M.board.self, first: (M.board.stages || [])[0] || '', reload: load });
26
- const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
27
- const DOCI = '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>';
28
- const STATE_ICO = { Linked: '<path d="M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"/><path d="M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"/>', Live: '<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>', 'Up to date': '<path d="M5 12.5l4.5 4.5L19 7.5"/>', Draft: '<path d="M4 20l4-1 11-11-3-3L5 16z"/>', 'Not started': '<circle cx="12" cy="12" r="9"/><path d="M12 8v5M12 16.5v.5"/>', Stale: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>', Due: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>' };
32
+ let foldOpen = false; // the Monitor and Evaluate rows under the table
33
+ let sprintSet = false; // "This sprint" starts on, once, when the board has a sprint
34
+ const F = { chips: new Set(), q: '', owners: new Set(), lanes: new Set() }; // the chip filters, Find and Filter
35
+ let peek = null; // the open panel: { kind: 'ini' | 'tk' | 'acts', key, tk, from: 'track' | 'time' }
36
+ mountNav('board');
37
+ const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
38
+ const I = {
39
+ x: 'M6 6l12 12M18 6L6 18', expand: 'M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7', more: 'M5 12h.01M12 12h.01M19 12h.01', go: 'M5 12h14M13 6l6 6-6 6', next: 'M9 6l6 6-6 6',
40
+ ext: 'M14 4h6v6M20 4l-9 9M10 6H5v13h13v-5', refresh: 'M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7', cal: 'M4 6h16v14H4zM4 10h16M9 3v4M15 3v4', jira: 'M12 3l9 9-9 9-9-9z',
41
+ flag: 'M5 21V4M5 4h11l-2 4 2 4H5', note: 'M4 5h16v11h-9l-5 4v-4H4z', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z',
42
+ doc: 'M6 3h9l4 4v14H6zM14 3v5h5', 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', chev: 'M7 10l5 5 5-5', chevUp: 'M7 14l5-5 5 5',
43
+ move: 'M4 12h12M12 6l6 6-6 6M20 5v14', hold: 'M9 5v14M15 5v14', archive: 'M4 5h16v4H4zM6 9v10h12V9M10 13h4', group: 'M3 5h18v4H3zM3 11h18v4H3zM3 17h12v3H3z',
44
+ track: 'M3 5h18v4H3zM3 11h18v4H3zM3 17h12v3H3z', time: 'M4 6h9M8 12h11M6 18h7',
45
+ };
46
+ const plural = (n, a, b) => (n === 1 ? a : b);
47
+ const ago = (iso, short) => { const t = Date.parse(iso || ''); if (!t) return ''; const m = Math.max(0, Math.round((Date.now() - t) / 60000)); return m < 1 ? 'just now' : m < 60 ? m + ' min' + (short ? '' : ' ago') : m < 60 * 36 ? Math.round(m / 60) + ' h' + (short ? '' : ' ago') : Math.round(m / 1440) + ' days' + (short ? '' : ' ago'); };
48
+ const isoDate = (iso) => { const x = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return x ? new Date(+x[1], +x[2] - 1, +x[3]) : null; };
49
+ const fmt = (iso) => { const d = isoDate(iso); return d ? md(d) : ''; };
50
+ const PHONE = matchMedia('(max-width: 720px)');
51
+ const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || null;
52
+
53
+ /** A plain panel of pm/bd-acts.js: it goes in the side panel like the others. */
54
+ function actsPanel(html, from) { peek = { kind: 'acts', key: peek && peek.key }; showPeek(html, from); } // keeps the initiative, so Close goes back to its row
55
+
56
+ /* ── the toast: the Agreed design's dark pill ─────────────────────────────────────────────────────────────────────────────── */
57
+ let toastT = null;
58
+ /** The toast; with `undo`, an Undo button that runs it once (the write's opposite, through the same route). */
59
+ function say(msg, undo) {
60
+ const t = $('#bdToast'); t.innerHTML = `<span>${esc(msg)}</span>${undo ? '<button type="button" class="bd-undo">Undo</button>' : ''}`; t.hidden = false;
61
+ const u = t.querySelector('.bd-undo'); if (u) u.onclick = () => { u.disabled = true; t.hidden = true; undo(); };
62
+ clearTimeout(toastT); toastT = setTimeout(() => { t.hidden = true; }, undo ? 10000 : 5000);
63
+ }
29
64
 
30
- /* ── header ───────────────────────────────────────────────────────────────────────────────────────────── */
65
+ /* ── the toolbar: picker, chips ───────────────────────────────────────────────────────────────────────────────────── */
31
66
  let crumbed = false;
32
67
  function drawHead() {
33
68
  if (!crumbed) {
34
69
  crumbed = true;
35
70
  const boards = M.board.switcher || [];
36
- $('#crumbHost').innerHTML = crumbHtml({ page: 'Board', board: M.board.name || 'Board', boards });
71
+ $('#crumbHost').innerHTML = crumbHtml({ page: '', board: M.board.name || 'Board', boards });
37
72
  wireCrumb({ boards, board: M.board.id, goBoard: (ws, id) => location.assign('/premium-board.html?ws=' + encodeURIComponent(ws) + '&board=' + encodeURIComponent(id)) });
73
+ $('#crBoard').setAttribute('aria-label', 'Product: ' + (M.board.name || 'Board'));
38
74
  chatAbout('board:this-board', M.board.name ? 'the ' + M.board.name + ' board' : 'this board');
39
75
  }
40
76
  $('#snap').textContent = M.header.text;
77
+ $('#newIni').hidden = !!M.board.self; // PMOS-self: new work starts at the pmos-router skill
41
78
  setPageGaps(((M.header && M.header.missing) || []).length);
42
- $('#snap').title = 'Every figure on this page comes from a record of the board. A date, owner or progress shows only when one was set.';
43
- $('#brief').textContent = '';
44
79
  }
80
+ const CHIP_F = [['late', 'late', 'm-warn', (n) => n + ' late'], ['risk', 'risk', 'm-warn', (n) => n + ' at risk'], ['blocked', 'red', 'm-crit', (n) => n + ' blocked'], ['idle', 'q', '', (n) => n + ' idle 30+ days']];
81
+ const longSpan = () => view === 'time' && (span === 'year' || span === 'y5');
82
+ function drawChips() {
83
+ const J = M.jira || {}, C = M.chips || {}, sp = J.sprint, rel = J.release, phone = PHONE.matches;
84
+ const jira = J.readAt ? (phone ? 'Jira ' + ago(J.readAt, true) : 'Jira · read ' + ago(J.readAt)) : phone ? 'Jira not read' : 'Jira · not read';
85
+ const sprint = [sp ? sp.name : null, rel ? rel.name + ' ships ' + rel.at.replace(/^(\d+) (\w+)$/, '$2 $1') : null].filter(Boolean).join(' · ') || 'No sprint on record';
86
+ const asks = C.asks == null ? 'New asks · not read' : null;
87
+ const flt = (keys) => CHIP_F.filter(([k]) => keys.includes(k)).map(([k, tone, mo, word]) => (C[k] ? `<button type="button" class="bd-chip gh${F.chips.has(k) ? ' on' : ''}" data-f="${k}" aria-pressed="${F.chips.has(k)}"><i class="cz-dot ${tone} ${mo}"></i>${esc(word(C[k]))}</button>` : '')).join('');
88
+ const thisSprint = sp && (view === 'track' || phone) ? `<button type="button" class="bd-chip${F.chips.has('sprint') ? ' on' : ''}" data-f="sprint" aria-pressed="${F.chips.has('sprint')}">This sprint</button>` : '';
89
+ if (longSpan()) {
90
+ const gn = (GROUPS.find(([k]) => k === group) || GROUPS[0])[1];
91
+ $('#bdChipset').innerHTML = `<span class="bd-grpw"><button type="button" class="bd-chip" id="chGroup" aria-haspopup="menu" aria-expanded="false">${SV(I.group)}<span>Group:</span><b>${esc(gn)}</b></button><span class="bd-grpm" id="grpMenu" role="menu" hidden>${GROUPS.map(([k, n]) => `<button type="button" role="menuitemradio" aria-checked="${k === group}" data-grp="${k}">${esc(n)}</button>`).join('')}</span></span><span class="bd-sp"></span>${flt(['late', 'risk', 'blocked'])}`;
92
+ return;
93
+ }
94
+ const jiraChip = `<button type="button" class="bd-chip" id="chJira" title="Read Jira again">${SV(I.refresh)}<span>${esc(jira)}</span></button>`;
95
+ const askChip = `<button type="button" class="bd-chip" id="chAsks" aria-haspopup="dialog">${asks ? esc(asks) : `<i class="cz-dot you${C.asks ? ' m-info' : ''}"></i><b>${C.asks}</b> new ${plural(C.asks, 'ask', 'asks')}`}</button>`;
96
+ if (phone) {
97
+ const docs = M.docs && M.docs.rows ? M.docs.rows.length : 0;
98
+ $('#bdChipset').innerHTML = thisSprint + jiraChip + askChip + flt(['late', 'risk', 'blocked', 'idle']) + `<button type="button" class="bd-chip" id="chDocs">Docs ${docs}</button>`;
99
+ return;
100
+ }
101
+ $('#bdChipset').innerHTML = jiraChip
102
+ + `<button type="button" class="bd-chip" id="chSprint" aria-haspopup="dialog">${SV(I.cal)}<span>${esc(sprint)}</span></button>`
103
+ + askChip + '<span class="bd-vr"></span>' + flt(['late', 'risk', 'blocked', 'idle'])
104
+ + (thisSprint ? '<span class="bd-sp"></span>' + thisSprint : '');
105
+ }
106
+ $('#bdChipset').addEventListener('click', (e) => {
107
+ const f = e.target.closest('[data-f]');
108
+ if (f) { const k = f.dataset.f; if (F.chips.has(k)) F.chips.delete(k); else F.chips.add(k); drawChips(); drawInit(); return; }
109
+ const g = e.target.closest('[data-grp]');
110
+ if (g) { group = g.dataset.grp; store.set(GROUP_KEY, group); drawChips(); drawInit(); const c = $('#chGroup'); if (c) c.focus(); return; }
111
+ const b = e.target.closest('button'); if (!b) return;
112
+ if (b.id === 'chJira') refreshJira(b);
113
+ else if (b.id === 'chSprint') Acts.open.sprint(b);
114
+ else if (b.id === 'chAsks') Acts.open.asks(b);
115
+ else if (b.id === 'chGroup') { const m = $('#grpMenu'), o = m.hidden; m.hidden = !o; b.setAttribute('aria-expanded', String(o)); if (o) m.querySelector('[aria-checked="true"]').focus(); }
116
+ else if (b.id === 'chDocs') setTab('docs');
117
+ });
118
+ /** Read Jira again: the Jira source's own refresh (POST /api/sources/refresh), the one the Sources list runs. It starts a read and changes no record. */
119
+ async function refreshJira(btn) {
120
+ if (btn) btn.disabled = true;
121
+ const r = await pmPost('/api/sources/refresh', { ws: (M && M.board.ws) || '', source: 'jira' }).catch(() => null);
122
+ if (btn) btn.disabled = false;
123
+ say(r && r.ok ? 'Reading Jira again. The Board shows it when the read lands.' : 'Jira was not read again: ' + ((r && r.error) || 'the server did not answer') + '.');
124
+ if (r && r.ok) setTimeout(load, 4000);
125
+ }
126
+
127
+ /* ── the popovers: what finishes each step, and the timeline's spans ───────────────────────────────────────────────────── */
128
+ let popBtn = null;
129
+ function closePops(back) { $$('.bd-pop').forEach((p) => { p.hidden = true; }); if (popBtn && back) popBtn.focus(); popBtn = null; }
130
+ function togglePop(id, btn) {
131
+ const p = $('#' + id), open = p.hidden;
132
+ closePops();
133
+ if (!open) return;
134
+ p.hidden = false; popBtn = btn || null;
135
+ const f = p.querySelector('button'); if (f) f.focus({ preventScroll: true });
136
+ }
137
+ $('#popSteps').innerHTML = stepsHelpHtml();
138
+ $('#popRules').innerHTML = rulesHelpHtml();
139
+ document.addEventListener('click', (e) => {
140
+ if (e.target.closest('[data-pop-close]')) { closePops(true); return; }
141
+ if (!e.target.closest('.bd-pop, [data-steps], [data-rules]')) closePops();
142
+ if (!e.target.closest('.bd-grpw')) { const m = $('#grpMenu'); if (m && !m.hidden) { m.hidden = true; $('#chGroup').setAttribute('aria-expanded', 'false'); } }
143
+ });
144
+
145
+ /* ── the rows on screen: the chip filters ─────────────────────────────────────────────────────────────────────────── */
146
+ /** "This sprint": an initiative with Jira tickets shows when one of them is in the current sprint; one with plan dates shows when they
147
+ * overlap the sprint; one with neither (the early stages) always shows. */
148
+ function inSprint(r, sp) {
149
+ const t = r.track || {};
150
+ if ((t.tickets || []).length) return t.tickets.some((k) => k.sprint === sp.name);
151
+ if (r.start && r.end && sp.start && sp.end) return r.start.slice(0, 10) <= sp.end && r.end.slice(0, 10) >= sp.start;
152
+ return true;
153
+ }
154
+ function visible() {
155
+ const sp = M.jira && M.jira.sprint;
156
+ return M.initiatives.list.rows.filter((r) => {
157
+ const t = r.track || {};
158
+ if (F.chips.has('late') && !r.late) return false;
159
+ if (F.chips.has('risk') && r.status !== 'at risk') return false;
160
+ if (F.chips.has('blocked') && !t.blocked) return false;
161
+ if (F.chips.has('idle') && t.idle == null) return false;
162
+ if (F.chips.has('sprint') && sp && (view === 'track' || PHONE.matches) && !inSprint(r, sp)) return false;
163
+ if (F.q && !String(r.title || '').toLowerCase().includes(F.q.toLowerCase())) return false;
164
+ if (F.owners.size && !F.owners.has(r.owner || 'No owner')) return false;
165
+ if (F.lanes.size && !F.lanes.has(r.lane)) return false;
166
+ return true;
167
+ });
168
+ }
169
+ const filtered = () => [...F.chips].some((k) => k !== 'sprint') || !!F.q || F.owners.size > 0 || F.lanes.size > 0;
170
+ const clearFilters = () => { F.chips.forEach((k) => { if (k !== 'sprint') F.chips.delete(k); }); F.q = ''; F.owners.clear(); F.lanes.clear(); };
171
+ /** The status line of a row: on hold, waiting on you, late, at risk, idle, shipping, on track. A blocked ticket stays on its ticket. */
172
+ function statusOf(r) {
173
+ const t = r.track || {};
174
+ if (r.acts && r.acts.life === 'hold') return { tone: 'q', mo: '', text: 'On hold' + (r.acts.back ? ' · back ' + r.acts.back : '') };
175
+ if (t.you) return { tone: 'you', mo: 'm-info', text: t.you };
176
+ if (r.late) return { tone: 'late', mo: 'm-warn', text: r.overDays > 0 ? r.overDays + ' ' + plural(r.overDays, 'day', 'days') + ' over' : 'Late' };
177
+ if (r.status === 'at risk') return { tone: 'risk', mo: 'm-warn', text: 'At risk' + (r.owner ? '' : ' · no owner') };
178
+ if (t.idle != null) return { tone: 'q', mo: '', text: 'Idle ' + t.idle + ' days' };
179
+ if (r.status === 'on track' && r.release && r.release.days != null && r.release.days >= 0 && t.key === 'deliver') {
180
+ const d = r.release.days; return { tone: 'ok', mo: '', text: d === 0 ? 'Ships today' : d === 1 ? 'Ships tomorrow' : 'Ships ' + fmt(r.release.iso) };
181
+ }
182
+ if (r.status === 'on track') return { tone: 'ok', mo: '', text: 'On track' };
183
+ return { tone: 'q', mo: '', text: r.statusLabel || r.sub };
184
+ }
185
+ /** The Output bar: one segment per ticket (a ticket opens its panel) or per part; a progress the record holds fills it as one bar. */
186
+ function segHtml(r, big) {
187
+ const t = r.track || {}, segs = t.segs || [], n = segs.length;
188
+ if (!n) return `<div class="seg5 none${big ? ' big' : ''}" aria-hidden="true"><i class="na"></i></div>`;
189
+ const fill = (i) => { if (t.pct == null) return ''; const f = Math.max(0, Math.min(1, (t.pct / 100) * n - i)) * 100; return f > 0 ? ` style="background:linear-gradient(90deg,var(--bd-done) ${f.toFixed(1)}%,var(--bd-rail) ${f.toFixed(1)}%)"` : ''; };
190
+ return `<div class="seg5${big ? ' big' : ''}"${t.pct != null ? ` role="img" aria-label="${t.pct}% on record"` : ''}>${segs.map((s, i) => (s.tk
191
+ ? `<button type="button" class="bt-tk ${esc(s.cls || 'td')}" data-tk="${esc(s.tk)}" data-ini="${esc(r.key)}" aria-label="${esc(s.tk + ': ' + ((t.tickets.find((k) => k.key === s.tk) || {}).title || '') + ', ' + ((t.tickets.find((k) => k.key === s.tk) || {}).blocked ? 'blocked' : (t.tickets.find((k) => k.key === s.tk) || {}).status))}" title="${esc(s.tk)}"></button>`
192
+ : `<i class="${esc(s.cls || '')}"${fill(i)}></i>`)).join('')}</div>`;
193
+ }
194
+ const lineHtml = (r) => ((r.track && r.track.line) || []).map((x) => (x.tone ? `<em class="s-${x.tone}">${esc(x.text)}</em>` : esc(x.text))).join(' · ');
45
195
 
46
- /* ── initiatives ───────────────────────────────────────────────────────────────────────────────────────────── */
47
- const sub = (r) => `${esc(r.sub)}${r.statusLabel ? ` · <span class="${r.late ? 'bad' : 'warn'}">${esc(r.statusLabel)}</span>` : ''}`;
48
- function listRow(r, i) {
49
- return `<div class="inirw">${listBtn(r)}${r.acts ? dotsBtn(r) : ''}</div>`;
50
- }
51
- function listBtn(r) {
52
- return `<button class="ini2 ibi${r.first ? ' first' : ''}" data-key="${esc(r.key)}"><span class="it"><b>${esc(r.title)}${r.first ? '<em class="tgf">Do this first</em>' : ''}</b><small>${sub(r)}</small></span><span class="wst"><span class="sg2" aria-hidden="true">${r.seg.map((c) => `<i class="${c}"></i>`).join('')}</span><em>${esc(r.stage || 'No stage')}${r.stageNote ? ' · ' + esc(r.stageNote) : ''}</em></span><span class="pg">${r.progress == null ? '' : `<i><b style="width:${r.progress}%"></b></i>`}</span><span class="rl${r.over ? ' over' : ''}">${esc(r.finish)}</span></button>`;
53
- }
54
- function drawList() {
55
- const L = M.initiatives.list.rows;
56
- if (!L.length) return '<p class="empty3 plain">No initiatives are on this board\'s now view.</p>' + goneHtml();
57
- return `<div class="inih"><span>Initiative</span><span>Where it is</span><span>Progress</span><span>Planned finish</span></div><div class="inil">` + L.slice(0, shown).map(listRow).join('') + '</div>'
58
- + (L.length > shown ? `<p class="note" style="margin-top:10px">${L.length - shown} more are loaded. <button class="fold alt" id="more" type="button">Show ${Math.min(25, L.length - shown)} more</button></p>` : '') + goneHtml();
59
- }
60
- /** The cancelled and archived rows, under a fold (initiative premium-board-actions). Their menu offers Reopen or Restore. */
61
- function goneHtml() {
62
- const G = M.initiatives.gone || { cancelled: [], archived: [] }, nc = G.cancelled.length, na = G.archived.length;
63
- if (!nc && !na) return '';
64
- return `<div class="bagone"><button class="dlink" type="button" id="goneT" aria-expanded="${showGone}">${[nc ? nc + ' cancelled' : '', na ? na + ' archived' : ''].filter(Boolean).join(' · ')}. ${showGone ? 'Hide them' : 'Show them'}</button>${showGone ? `<div class="inil">${G.cancelled.concat(G.archived).map((r) => `<div class="inirw gone">${listBtn(r)}${dotsBtn(r)}</div>`).join('')}</div>` : ''}</div>`;
65
- }
66
- function drawStages() {
67
- const S = M.initiatives.stages;
68
- if (!S.length) return '<p class="empty3 plain">This board has no workflow stages on record.</p>';
69
- return `<div class="istg">${S.map((s) => `<div class="isc"><p class="label">${esc(s.stage)} <em>${s.count}</em></p>${s.rows.map((r) => `<button class="icd ibi" data-key="${esc(r.key)}"><b>${esc(r.title)}</b><small>${sub(r)}</small>${r.progress == null ? '' : `<span class="pg"><i><b style="width:${r.progress}%"></b></i></span>`}<small>${esc(r.finish)}</small></button>`).join('') || '<p class="mut">None</p>'}${s.more ? `<p class="mut">${s.more} more</p>` : ''}</div>`).join('')}</div>`;
70
- }
71
- function drawTime() {
72
- const T = M.initiatives.timeline;
73
- if (T.empty) return `<p class="empty3 plain">${esc(T.why)}</p>`;
74
- return `<div class="tll"><div class="tlh" aria-hidden="true"><span>Initiative</span><span>${esc(T.from)} to ${esc(T.to)}</span><span></span></div><div class="tlgrid" aria-hidden="true"><span></span><div class="tlplot"><u class="td" style="left:${T.todayPct}%"></u></div><span></span></div>`
75
- + T.bars.map((b, k) => `<button class="tlr${b.bad ? ' bd' : ''}${b.over ? ' ov' : ''}" data-key="${esc(b.key)}" style="--k:${k}"><span class="tlt"><b>${esc(b.title)}</b><small>${esc(b.sub)}</small></span><span class="tlbar" role="img" aria-label="${esc(b.title)}: ${esc(b.start)} to ${esc(b.end)}"><span class="tlb" style="--l:${b.l}%;--w:${b.w}%"><i class="fl" style="--e:${b.elapsed}%"></i></span></span><span class="tld"><span>${esc(b.start)}</span><span>${esc(b.end)}</span></span><span class="tln"><b>${b.n}</b><small>${esc(b.word)}</small></span></button>`).join('')
76
- + `</div>${T.none ? `<p class="tlnone">${T.none} ${T.none === 1 ? 'initiative has' : 'initiatives have'} no dates on record and ${T.none === 1 ? 'is' : 'are'} not drawn.</p>` : ''}<p class="note" style="margin-top:10px">Each bar runs from a start date to an end date someone set. The filled part is the time elapsed. The line is today.</p>`;
196
+ /* ── the stage track (AgBoard, AgBoardPhone) ──────────────────────────────────────────────────────────────────────────── */
197
+ const LEGEND = '<span class="lg" aria-hidden="true"><span><i class="sk"></i>Skipped</span><span><i class="dn"></i>Done</span><span><i class="rv"></i>Review</span><span><i class="ip"></i>Doing</span><span><i class="yo"></i>You</span><span><i class="bl"></i>Blocked</span></span>';
198
+ const DAYS = (t) => (t.days != null ? t.days + 'd' : '—');
199
+ /** "usually N days": the median of past initiatives in that step (lib/board-trail.js), shown only from 3 samples on. */
200
+ const usualOf = (t) => { const u = TR && TR.usual && t && TR.usual[t.key]; return u && u.n >= 3 && u.days != null ? u : null; };
201
+ const usualText = (u) => (u.days === 0 ? 'usually under a day' : 'usually ' + u.days + ' ' + plural(u.days, 'day', 'days'));
202
+ const dayTitle = (t) => t.label + ' · ' + (t.days != null ? t.days + ' ' + plural(t.days, 'day', 'days') + ' in this step' : 'days in this step are not on record') + (usualOf(t) ? ' · ' + usualText(usualOf(t)) : '');
203
+ function trackRow(r) {
204
+ const t = r.track || { k: -1, label: r.stage || 'No stage', output: '', segs: [], skipped: [] }, s = statusOf(r), k = t.k, sk = new Set(t.skipped || []);
205
+ const cells = M.steps.map((st, j) => {
206
+ const cls = ['sc', j === 0 ? 'f0' : '', j === 7 ? 'l' : '', st.ms ? 'ms' : '', j < k ? 'p' : '', sk.has(j) ? 'k' : '', j === k ? 'c bg' : ''].filter(Boolean).join(' ');
207
+ const why = sk.has(j) && (t.skipWhy || []).find((x) => x.stage === st.key);
208
+ const title = j === k ? dayTitle(t) : sk.has(j) ? st.label + ' skipped' + (why && why.why ? ': ' + why.why : '') : '';
209
+ return `<div class="${cls}" role="cell"${title ? ` title="${esc(title)}"` : ''}>${j === k ? `<span class="cur"><u class="cz-dot ${s.tone} ${s.mo}"></u><small>${DAYS(t)}</small></span>` : '<i></i>'}</div>`;
210
+ }).join('');
211
+ return `<div class="bt-r bt-l${peek && peek.key === r.key && peek.kind !== 'acts' ? ' sel' : ''}${r.acts && r.acts.life === 'hold' ? ' held' : ''}" role="row" data-row="${esc(r.key)}">`
212
+ + `<button type="button" class="ini2 bt-nm" data-key="${esc(r.key)}" role="rowheader" aria-haspopup="dialog"><b>${esc(r.title)}</b><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone}"></i>${esc(s.text)}</span><span class="bt-pst">${t.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(t.label)} · ${DAYS(t)}</span></button>`
213
+ + `<div class="bt-cells" role="presentation">${cells}</div>`
214
+ + `<div class="bt-dl" role="cell"><div class="t1"><b>${esc(t.output)}</b><span>${esc(t.count || '')}</span></div>${segHtml(r)}<div class="t3">${lineHtml(r)}</div></div></div>`;
215
+ }
216
+ const isME = (r) => r.track && r.track.k >= 6;
217
+ function drawTrack(L) {
218
+ const S = M.steps || [];
219
+ const sorted = L.slice().sort((a, b) => ((a.track ? a.track.k : -1) < 0 ? 99 : a.track.k) - ((b.track ? b.track.k : -1) < 0 ? 99 : b.track.k));
220
+ // Monitor and Evaluate fold away after the first row of each (AgBoard: "19 more in Monitor and Evaluate")
221
+ const seen = new Set(), shown = [], folded = [];
222
+ for (const r of sorted) { if (isME(r) && seen.has(r.track.k) && !foldOpen) folded.push(r); else { if (isME(r)) seen.add(r.track.k); shown.push(r); } }
223
+ const meTotal = (S[6] ? S[6].count : 0) + (S[7] ? S[7].count : 0), meShown = shown.filter(isME).length, more = Math.max(folded.length, meTotal - meShown);
224
+ const n = M.initiatives.open || M.initiatives.list.rows.length;
225
+ const head = `<div class="bt-r bt-h" role="row"><div class="bt-nmh" role="columnheader">Initiative <span>${n}</span></div><div class="bt-cells" role="presentation">${S.map((s) => `<div role="columnheader" class="${s.ms ? 'msh' : ''}" data-steps title="What finishes each step" aria-haspopup="dialog" tabindex="0"><span class="bt-hl">${s.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}${esc(s.label)}</span><span>${s.count}</span></div>`).join('')}</div><div class="bt-oh" role="columnheader">Output ${LEGEND}</div></div>`;
226
+ const tf = more > 0 && !foldOpen ? `<button type="button" class="dlink" id="fold" aria-expanded="false">${SV(I.chev)}${more} more in Monitor and Evaluate</button>`
227
+ : foldOpen && meTotal > 1 ? `<button type="button" class="dlink" id="fold" aria-expanded="true">${SV(I.chevUp)}Fold Monitor and Evaluate${meTotal > meShown ? ` · ${meTotal - meShown} more are not loaded` : ''}</button>` : '<span></span>';
228
+ if (!L.length) return `<div class="bt" role="table" aria-label="Initiatives by stage">${head}<p class="bt-empty">${filtered() ? 'No initiative matches the chips, Find or Filter. <button type="button" class="dlink" id="fClear">Clear them</button>' : 'No initiatives are on this board\'s now view.'}</p></div>`;
229
+ return `<div class="bt" role="table" aria-label="Initiatives by stage">${head}${shown.map(trackRow).join('')}<div class="bt-tf">${tf}<span class="bt-srt">Sorted by stage</span></div>${PHONE.matches ? `<div class="bd-whead bd-phx">${Acts.WTAG}<span class="bd-phb"><button type="button" class="bd-chip" data-steps aria-haspopup="dialog">What finishes each step</button><button type="button" class="bd-chip" data-open="metrics" aria-haspopup="dialog">Metrics</button><button type="button" class="bd-chip" data-open="gone" aria-haspopup="dialog">Cancelled and archived</button></span></div>` : ''}</div>`; // the phone has no step heads: a plain entry to the steps help
230
+ }
231
+
232
+ /* ── the timeline (AgBoardTimeline, AgBoardTlYear, AgBoardTl5y, AgBoardTimelinePhone) ───────────────────────────────────────── */
233
+ /** The phone has no frame for the span rules, Year and 5 yr: a plain row under its timeline reaches them, with a "Waiting for design" tag. */
234
+ function phoneSpans(sp) {
235
+ return `<div class="bd-whead bd-phx">${Acts.WTAG}<span class="bd-phb">${[['quarter', 'Quarter'], ['year', 'Year'], ['y5', '5 yr']].map(([k, n]) => `<button type="button" class="bd-chip${sp === k ? ' on' : ''}" data-span-go="${k}" aria-pressed="${sp === k}">${n}</button>`).join('')}<button type="button" class="bd-chip" data-rules aria-haspopup="dialog">How the spans group</button></span></div>`;
236
+ }
237
+ function drawTime(L) {
238
+ const phone = PHONE.matches, long = span === 'year' || span === 'y5';
239
+ const S = M.steps || [], sp = phone && span !== 'sprint' && !long ? 'quarter' : span; // a phone draws Quarter and Sprint (AgBoardTimelinePhone); Year and 5 yr as the desktop frame, scrolled
240
+ const T = timelineHtml(L, M, sp, { phone: phone && !long, sel: peek && peek.kind !== 'acts' ? peek.key : null, status: statusOf, hiddenCount: (S[6] ? S[6].count : 0) + (S[7] ? S[7].count : 0), themes: (TR && TR.themes) || [], group,
241
+ askHref: (none) => askHref(null, 'Propose start and end dates for ' + none.map((r) => r.title).join(', ')) });
242
+ return phone ? (long ? `<div class="bd-phscroll">${T.html}</div>` : T.html) + phoneSpans(sp) : T.html;
77
243
  }
78
244
  function drawInit() {
79
- const I = M.initiatives;
80
- $('#iniCap').innerHTML = I.cap ? `<b>${I.cap.on} of ${I.cap.open}</b> open on track · ${I.risk} at risk · ${I.late} late${I.hold ? ' · ' + I.hold + ' on hold' : ''}` : 'no open initiatives';
81
- const bar = $('#iniBar'); bar.hidden = !I.cap; if (I.cap) { bar.setAttribute('aria-valuemax', I.cap.open); bar.setAttribute('aria-valuenow', I.cap.on); $('b', bar).style.width = (I.cap.open ? I.cap.on / I.cap.open * 100 : 0) + '%'; }
82
- $('#ibBody').innerHTML = view === 'list' ? drawList() : view === 'stages' ? drawStages() : drawTime();
83
- $('#iniNote').textContent = I.note;
84
- $$('#ibTabs button').forEach((b) => b.setAttribute('aria-pressed', b.dataset.v === view));
85
- { const cur = $(`#ibTabs [data-v="${view}"]`).textContent; $('#ibF').firstChild.textContent = cur; $('#ibF').setAttribute('aria-label', 'View: ' + cur); }
86
- }
87
- /* the view is one chip in the card's head; List, By stage and Timeline wait in its menu (premium-calmer-first-screen) */
88
- function ibMenu(open) { $('#ibTabs').hidden = !open; $('#ibF').setAttribute('aria-expanded', String(open)); }
89
- $('#ibF').addEventListener('click', () => { const open = $('#ibTabs').hidden; ibMenu(open); if (open) $('#ibTabs [aria-pressed="true"]').focus(); });
90
- document.addEventListener('click', (e) => { if (!$('#ibTabs').hidden && !e.target.closest('#ibTabs, #ibF')) ibMenu(false); });
91
- document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !$('#ibTabs').hidden) { ibMenu(false); $('#ibF').focus(); } });
92
- $('#ibTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-v]'); if (!b) return; ibMenu(false); view = b.dataset.v; drawInit(); $('#ibF').focus(); });
245
+ $('#nIni').textContent = String(M.initiatives.open || M.initiatives.list.rows.length);
246
+ const L = visible(), v = PHONE.matches && (view === 'stages' || view === 'list') ? 'track' : view;
247
+ const body = $('#ibBody');
248
+ body.dataset.view = v; body.dataset.span = v === 'time' ? span : '';
249
+ body.innerHTML = v === 'track' ? drawTrack(L) : v === 'time' ? drawTime(L) : v === 'list' ? Acts.listHtml(L) : Acts.stagesHtml(L);
250
+ $$('#ibTabs [data-v]').forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.v === v)));
251
+ $('#bdView').innerHTML = SV(v === 'time' ? I.time : I.track); $('#bdView').setAttribute('aria-label', 'Change view. Now: ' + (v === 'time' ? 'Timeline' : 'Stage track'));
252
+ $('#bdSpans').hidden = v !== 'time' || PHONE.matches;
253
+ $$('#bdSpans [data-sp]').forEach((b) => b.setAttribute('aria-pressed', String(b.dataset.sp === span)));
254
+ document.body.dataset.bdView = v;
255
+ }
256
+ PHONE.addEventListener('change', () => { if (M) { drawChips(); drawInit(); } });
257
+ function setView(v) { view = v; store.set(VIEW_KEY, view); closePeek(); drawChips(); drawInit(); }
258
+ $('#ibTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-v]'); if (!b || !M) return; setTab('ini'); setView(b.dataset.v); });
259
+ $('#bdView').addEventListener('click', () => { if (M) setView(view === 'time' ? 'track' : 'time'); });
260
+ $('#bdSpans').addEventListener('click', (e) => { const b = e.target.closest('[data-sp]'); if (!b || !M) return; span = b.dataset.sp; store.set(SPAN_KEY, span); drawChips(); drawInit(); });
93
261
  $('#ibBody').addEventListener('click', (e) => {
94
- if (e.target.closest('#more')) { shown += 25; drawInit(); return; }
95
- if (e.target.closest('#goneT')) { showGone = !showGone; drawInit(); const g = $('#goneT'); if (g) g.focus(); return; }
96
- const im = e.target.closest('[data-im]'); if (im) { const r = rowOf(im.dataset.im); if (r) openMenu(im, ctxOf(), r); return; }
97
- const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key));
262
+ if (e.target.closest('#fold')) { foldOpen = !foldOpen; drawInit(); const f = $('#fold'); if (f) f.focus(); return; }
263
+ if (e.target.closest('#fClear')) { clearFilters(); drawChips(); drawInit(); return; }
264
+ const op = e.target.closest('[data-open]'); if (op) { Acts.open[op.dataset.open](op); return; }
265
+ const st = e.target.closest('[data-steps]'); if (st) { togglePop('popSteps', st); return; }
266
+ const ru = e.target.closest('[data-rules]'); if (ru) { togglePop('popRules', ru); return; }
267
+ const go = e.target.closest('[data-span-go]'); if (go) { span = go.dataset.spanGo; store.set(SPAN_KEY, span); drawChips(); drawInit(); return; }
268
+ const tk = e.target.closest('[data-tk]'); if (tk) { openTicket(tk.dataset.ini, tk.dataset.tk, tk); return; }
269
+ const th = e.target.closest('[data-tgtheme]'); if (th) { span = 'year'; store.set(SPAN_KEY, span); drawChips(); drawInit(); return; }
270
+ if (e.target.closest('[data-act]')) return; // pm/bd-acts.js handles its own presses
271
+ const b = e.target.closest('[data-key]'); if (b) openIni(rowOf(b.dataset.key), b, view === 'time' ? 'time' : 'track');
98
272
  });
99
- /* A click opens the initiative page, as the mockup's Page setting does; the Popup setting opens the dialog. The choice is kept in this browser. */
100
- let openMode = store.get(MODE_KEY) === 'popup' ? 'popup' : 'page';
101
- function drawMode() { $$('#modeSeg button').forEach((b) => b.setAttribute('aria-pressed', b.dataset.m === openMode)); pillOf($('#modeSeg')); }
102
- $('#modeSeg').addEventListener('click', (e) => { const b = e.target.closest('[data-m]'); if (!b) return; openMode = b.dataset.m; store.set(MODE_KEY, openMode); drawMode(); toast('Initiatives now open as a ' + openMode + '.'); });
103
- function openIni(r) {
104
- if (!r) return;
105
- if (openMode === 'popup' || !r.id) { openRow(r); return; }
106
- location.assign('/premium-initiative.html?id=' + encodeURIComponent(r.id) + (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) + '&board=' + encodeURIComponent(M.board.id) : ''));
273
+ $('#ibBody').addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target.matches('[data-steps]')) { e.preventDefault(); togglePop('popSteps', e.target); } });
274
+
275
+ /* ── "Ask about this": the Board has no chat; the question goes to Home as a quick ask in that initiative (B3) ───────────────── */
276
+ function askHref(r, q) {
277
+ const p = new URLSearchParams();
278
+ if (r && r.id) p.set('ask', r.id); else p.set('ask', 'board:' + (M.board.id || ''));
279
+ if (q) p.set('q', q);
280
+ if (M.board.ws) p.set('ws', M.board.ws);
281
+ return '/premium.html?' + p.toString();
107
282
  }
108
- const rowOf = (key) => (M && M.rows || []).find((r) => r.key === key) || null;
283
+ const pageHref = (r) => '/premium-initiative.html?id=' + encodeURIComponent(r.id) + (M.board.ws ? '&ws=' + encodeURIComponent(M.board.ws) + '&board=' + encodeURIComponent(M.board.id) : '');
109
284
 
110
- /* ── sprint, release, documents ─────────────────────────────────────────────────────────────────────────── */
111
- function drawSide() {
112
- const S = M.sprint, R = M.release;
113
- $('#hSpr').textContent = S.name || 'Sprint';
114
- $('#sprCap').textContent = S.cap || '';
115
- $('#sprBody').innerHTML = S.name
116
- ? `<button type="button" class="spr sprb" data-open="board:sprint" aria-haspopup="dialog" aria-label="${esc(S.name)}, ${esc(S.cap || '')}. Open the sprint"><span class="sbar" aria-hidden="true"><i class="d" style="width:${S.pct.done}%"></i><i class="g" style="width:${S.pct.doing}%"></i></span>`
117
- + `<span class="cnt"><span><b>${S.counts.done}</b> done</span><span><b>${S.counts.doing}</b> doing</span><span><b>${S.counts.todo}</b> to do</span></span>`
118
- + `${S.goal ? `<span class="goal2">Goal: ${esc(S.goal)}</span>` : ''}${S.review ? `<span class="sum3">${esc(S.review)}</span>` : ''}</button>`
119
- : `<p class="mut">${esc(S.why)}</p>`;
120
- $('#hRel').textContent = 'Next release';
121
- $('#relCap').textContent = R.at ? '' : R.cap || 'none';
122
- $('#relBody').innerHTML = R.rel && R.rel.length
123
- ? `${R.at ? '' : `<p class="empty3 plain">${esc(R.why)}</p>`}<div class="rels">${R.rel.map((r) => `<button type="button" class="rel" data-open="board:release" aria-haspopup="dialog"><span class="rh"><b>${esc(r.name)}</b><em class="rtag">${esc(r.tag)}</em><time>${esc(r.at)}${r.away ? ' · ' + esc(r.away) : ''}</time></span>${r.ini.map((i) => `<span class="ri"><i class="hd ${i.tone}"></i>${esc(i.title)}${i.status ? ' · ' + esc(i.status) : ''}</span>`).join('')}</button>`).join('')}</div>`
124
- : `<p class="empty3 plain">${esc(R.why)}</p>`;
125
- }
126
- $('#cSpr').addEventListener('click', (e) => { const b = e.target.closest('[data-open]'); if (b) openRow(rowOf(b.dataset.open)); });
127
- $('#cSpr').addEventListener('click', (e) => { if (e.target.closest('[data-open="board:sprint"]')) backlogBtn(); }); // after openRow: the sprint dialog's own detail gets "Open the backlog" (premium-viewer R10)
128
- $('#cRel').addEventListener('click', (e) => { const b = e.target.closest('[data-open]'); if (b) openRow(rowOf(b.dataset.open)); });
129
- function docRow(d) {
130
- const act = !d.act ? '' : d.act.kind === 'draft' ? `<button class="dmcta alt" data-draft="${esc(d.key)}"${d.running ? ' disabled' : ''}>${d.running ? '<span class="spin"></span>' : ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}${esc(d.act.label)}</button>` : `<button class="dmcta alt" data-tab="${esc(d.act.tab)}">${esc(d.act.label)}</button>`;
131
- return `<div class="dmr ${esc(d.st || '')}" role="listitem">${d.path ? `<button class="dmo" data-doc="${esc(d.key)}" aria-haspopup="dialog">` : '<span class="dmo">'}<span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(d.title)}</b><small>${esc(d.what)}</small><span class="dmm"><span class="s ${esc(d.st || 'live')}">${ICO(STATE_ICO[d.state] || STATE_ICO['Not started'])}${esc(d.state)}</span>${d.added ? `<span>${ICO('<rect x="3" y="5" width="18" height="16" rx="3"/><path d="M3 10h18M8 3v4M16 3v4"/>')}added ${esc(d.added)}</span>` : ''}${d.cadence ? `<span>${ICO('<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>')}${esc(d.cadence)}</span>` : ''}${d.by ? `<span>${ICO('<circle cx="12" cy="8" r="4"/><path d="M4 21a8 8 0 0 1 16 0"/>')}${esc(d.by)}</span>` : ''}</span></span>${d.path ? '</button>' : '</span>'}<span class="dmq">${act}</span></div>`;
132
- }
133
- let docFilter = 'all', docQuery = '';
134
- const draftable = () => (M.docs.rows || []).filter((d) => d.st === 'missing' && d.act && d.act.kind === 'draft' && !d.running);
135
- const docMatch = (d) => (docFilter === 'all' || (docFilter === 'none' ? d.st === 'missing' : docFilter === 'draft' ? d.st === 'draft' : d.st === 'ok')) && (!docQuery.trim() || (d.title + ' ' + d.what).toLowerCase().includes(docQuery.trim().toLowerCase()));
136
- function drawDocList() {
137
- const D = M.docs, L = D.rows.filter(docMatch);
138
- $('#docBody').innerHTML = L.length ? L.map(docRow).join('') : `<div class="dmem"><p>No document matches${docQuery.trim() ? ' “' + esc(docQuery.trim()) + '”' : ''}.</p></div>`;
139
- $$('#dmF button').forEach((b) => b.setAttribute('aria-pressed', b.dataset.dmf === docFilter)); if ($('#dmF')) pillOf($('#dmF'));
140
- }
141
- function drawDocs() {
142
- const D = M.docs, c = D.counts;
143
- $('#addDoc').hidden = !D.scope;
144
- $('#docCap').textContent = D.rows.length ? String(c.all) : '';
145
- if (!D.rows.length) { $('#docTop').innerHTML = ''; $('#docBody').innerHTML = `<p class="empty3 plain">${D.missing ? 'The core documents could not be read, so none is shown.' : 'No core documents are on record for this board.'}</p>`; $('#docNote').textContent = ''; return; }
146
- const dot = { ok: 'ok', draft: 'warn', missing: 'mut' };
147
- const hadQ = $('#dmQ') && document.activeElement === $('#dmQ');
148
- $('#docTop').innerHTML = `<p class="dsum"><span><b>${c.draft}</b> ${c.draft === 1 ? 'draft' : 'drafts'} to review</span><span><b>${c.none}</b> not started</span><span><b>${c.ok}</b> up to date</span>${c.linked ? `<span><b>${c.linked}</b> linked</span>` : ''}${draftable().length > 1 ? `<button class="dlink" data-draftall="1">${ICO('<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>')}Draft the ${draftable().length} not started</button>` : ''}</p>
149
- <div class="dprog" role="img" aria-label="${c.ok} of ${c.all} up to date">${D.rows.map((d) => `<i class="${dot[d.st] || (d.st === 'live' ? 'ok' : 'mut')}"></i>`).join('')}</div>
150
- <div class="dtool"><div class="seg" id="dmF" role="group" aria-label="Filter documents"><i class="pill"></i>${[['all', 'All', c.all], ['none', 'Not started', c.none], ['draft', 'Draft', c.draft], ['ok', 'Up to date', c.ok]].map(([k, l, n]) => `<button data-dmf="${k}" aria-pressed="${docFilter === k}">${l}<em>${n}</em></button>`).join('')}</div>
151
- <label class="dmsr">${ICO('<circle cx="11" cy="11" r="6.5"/><path d="m20 20-4-4"/>')}<input id="dmQ" type="search" placeholder="Find a document" aria-label="Find a document" value="${esc(docQuery)}"></label></div>`;
152
- drawDocList();
153
- if (hadQ) { const q = $('#dmQ'); q.focus(); q.setSelectionRange(q.value.length, q.value.length); }
154
- $('#docNote').textContent = 'Draft it starts a read-only agent run that writes a draft for you to read. Nothing is sent. Press a document to read it; a draft has Issue it, which marks it issued and sends nothing. Dropping a document is not built on this page.';
155
- }
156
- $('#docTop').addEventListener('click', async (e) => {
157
- const f = e.target.closest('[data-dmf]'); if (f) { docFilter = f.dataset.dmf; drawDocList(); return; }
158
- const all = e.target.closest('[data-draftall]'); if (!all || all.disabled) return;
159
- all.disabled = true; let n = 0;
160
- for (const d of draftable()) { const res = await pmPost('/api/core-docs/draft', { ws: M.board.ws, scope: M.docs.scope, key: d.key }); if (res && res.ok === true) n++; else { toast((res && res.error) || 'A draft could not be started.'); break; } }
161
- if (n) toast('The agent is drafting ' + n + ' ' + (n === 1 ? 'document' : 'documents') + '. They run in the background and send nothing.');
162
- await load();
285
+ /* ── the side panel: the initiative (AgBoardPanel), the Jira ticket (AgBoardTicket) and the initiative from the timeline (AgBoardTimelinePanel) ── */
286
+ let peekBack = null;
287
+ function ladderHtml(t) {
288
+ const k = t ? t.k : -1, sk = new Set((t && t.skipped) || []);
289
+ return `<div class="pk-lad" role="img" aria-label="${esc(k >= 0 ? 'Step ' + (k + 1) + ' of 8: ' + t.label : 'No step on record')}"><i class="ln"></i><i class="lp" style="width:${k > 0 ? (k / 7) * 87.5 : 0}%"></i>${M.steps.map((s, j) => `<span class="${[j < k ? 'p' : '', j === k ? 'c' : '', s.ms ? 'm' : '', sk.has(j) ? 'k' : ''].filter(Boolean).join(' ')}"><i></i>${esc(s.short)}</span>`).join('')}</div>`;
290
+ }
291
+ function askForm(r, label, o = {}) {
292
+ const J = M.jira || {};
293
+ const ft = o.inside ? `<span>The answer lands in Home, inside ${esc(r.title)}.</span>`
294
+ : `<span>Answer lands in Home</span><span class="sp"></span><span class="jr">${SV(I.jira)}Jira ${J.readAt ? esc(ago(J.readAt)) : 'not read'}</span><button type="button" class="bd-ib sm" data-pk="jira" aria-label="Read Jira again" title="Read Jira again">${SV(I.refresh)}</button>`;
295
+ return `<form class="pk-ask" data-ask="${esc(r.key)}"><div class="in"><input type="text" name="q" maxlength="2000" autocomplete="off" placeholder="Ask about ${esc(label)}…" aria-label="Ask about ${esc(label)}"><button type="submit" class="bd-ib solid" aria-label="Ask in Home" title="Ask in Home">${SV(I.go)}</button></div><div class="ft">${ft}</div></form>`;
296
+ }
297
+ const eyeOf = (r, lower) => [r.lane ? (lower ? r.lane : r.lane.charAt(0).toUpperCase() + r.lane.slice(1)) : '', r.kr, ...(lower ? [] : [r.owner ? 'owner ' + r.owner : 'no owner'])].filter(Boolean);
298
+ const tkState = (k) => (k.blocked ? 'blocked' + (k.reason ? ' by ' + k.reason.replace(/^Waiting on /i, '') : '') : k.status === 'In review' ? 'in review' : k.status === 'In progress' ? 'in progress' : k.status === 'Done' ? 'done' : 'to do');
299
+ /** The output box: the open tickets (blocked first) with their state and assignee, the done ones folded into one line, and Deliver's two
300
+ * parts that are not tickets; for the other steps, the parts of the output, each counted only where a record holds it. */
301
+ function outRows(r) {
302
+ const t = r.track || {};
303
+ if (t.tickets && t.tickets.length && (t.key === 'build' || t.key === 'deliver')) {
304
+ const open = t.tickets.filter((k) => k.status !== 'Done').sort((a, b) => (b.blocked ? 1 : 0) - (a.blocked ? 1 : 0)), done = t.tickets.filter((k) => k.status === 'Done');
305
+ const rows = open.slice(0, 10).map((k) => `<button type="button" class="gi" data-tk="${esc(k.key)}" data-ini="${esc(r.key)}"><i class="k ${esc(k.cls || 'td')}"></i><span class="n"><em>${esc(k.key)}</em>${esc(k.title)} · ${esc(tkState(k))}</span>${k.assignee || k.age != null ? `<span class="r">${esc([k.assignee, k.age != null ? k.age + 'd' : ''].filter(Boolean).join(' · '))}</span>` : ''}</button>`);
306
+ if (open.length > 10) rows.push(`<p class="gi gm"><i class="k"></i><span class="n">${open.length - 10} more open tickets</span></p>`);
307
+ if (done.length) rows.push(`<p class="gi gm"><i class="k dn"></i><span class="n">${done.length} ${plural(done.length, 'ticket', 'tickets')} done · ${esc(done.slice(0, 3).map((k) => k.title.toLowerCase()).join(', '))}${done.length > 3 ? ', …' : ''}</span></p>`);
308
+ if (t.key === 'deliver') rows.push('<p class="gi gm"><i class="k"></i><span class="n">Release notes</span><span class="r">not on record</span></p>', `<p class="gi gm"><i class="k${t.you ? ' yo' : ''}"></i><span class="n">Your sign-off</span><span class="r">${t.you ? 'waiting' : 'after the tickets'}</span></p>`);
309
+ return rows.join('');
310
+ }
311
+ if (t.key === 'build' || t.key === 'deliver') return '<p class="gi gm"><i class="k na"></i><span class="n">No Jira ticket has been read for it yet</span></p>';
312
+ return (t.segs || []).map((s) => `<p class="gi gm"><i class="k ${esc(s.cls || '')}"></i><span class="n">${esc(s.name || '')}</span><span class="r">${esc(s.st || '')}</span></p>`).join('');
313
+ }
314
+ const TI = (r) => (r && r.trail) || null;
315
+ /** The skipped steps, each with its reason: the lane's own ladder or the board move's why (lib/board-trail.js). */
316
+ function skipHtml(t) {
317
+ const sk = (t.skipped || []).map((j) => M.steps[j]).filter(Boolean);
318
+ if (!sk.length) return '';
319
+ const why = sk.map((s) => { const w = (t.skipWhy || []).find((x) => x.stage === s.key); return w && w.why ? s.label + ' skipped. ' + w.why : null; });
320
+ if (why.every(Boolean)) return `<p class="pk-skip">${esc(why.join(' '))}</p>`;
321
+ return `<p class="pk-skip">${esc(sk.map((s) => s.label).join(', '))} skipped: it was moved past ${sk.length === 1 ? 'that step' : 'those steps'}. No reason is on record.</p>`;
322
+ }
323
+ /** What waits on you: the release sign-off (the model), else the trail's next action (the Commit of drafted tickets, a PRD change, the verdict). */
324
+ function nextHtml(r) {
325
+ const t = r.track || {};
326
+ if (t.you && t.youKind) {
327
+ const go = t.youKind === 'drift' && TI(r) && TI(r).links.prd ? `<button type="button" class="bd-ib solid" data-doc="${esc(TI(r).links.prd)}" aria-label="Open the PRD" title="Open the PRD">${SV(I.next)}</button>`
328
+ : r.id ? `<a class="bd-ib solid" href="${esc(pageHref(r))}" aria-label="${esc(t.you)}: open the initiative page" title="Open the initiative page">${SV(I.next)}</a>` : '';
329
+ return `<div class="pk-nb"><div class="t"><b>${esc(t.you)}</b><div>${esc(t.youWhy || '')}</div></div>${go}</div>`;
330
+ }
331
+ if (t.you) return `<div class="pk-nb"><div class="t"><b>Sign off ${esc(r.release ? r.release.name : t.output)}</b><div>Every release ticket is done. Release notes are not on record in PMOS.</div></div>${r.id ? `<a class="bd-ib solid" href="${esc(pageHref(r))}" aria-label="Review the release" title="Review the release">${SV(I.next)}</a>` : ''}</div>`;
332
+ return ''; // nothing waits on you: AgBoardPanel draws the card only when something does
333
+ }
334
+ /** Tickets drafted in PMOS and not yet in Jira: they go to Jira only through your Commit. */
335
+ function draftedHtml(r) {
336
+ const it = TI(r); if (!it) return '';
337
+ const d = (it.drafted || []).filter((x) => !x.key); if (!d.length) return '';
338
+ const g = it.gate || {};
339
+ return `<div class="pk-sec"><p class="lbl">Drafted in PMOS · ${d.length}</p><div class="pk-tks">${d.slice(0, 8).map((x) => `<p class="gi gm"><i class="k${x.waiting ? ' yo' : ''}"></i><span class="n">${x.id ? `<em>${esc(x.id)}</em>` : ''}${esc(x.summary || '')}</span><span class="r">not in Jira</span></p>`).join('')}${d.length > 8 ? `<p class="gi gm"><i class="k"></i><span class="n">${d.length - 8} more drafted</span></p>` : ''}</div><p class="pk-mut">They go to Jira only through your Commit${g.open === false && g.why ? '. The Commit is closed: ' + esc(g.why) : ''}.</p></div>`;
340
+ }
341
+ /** The PRD against what was pushed: tickets whose text came from a PRD that changed after the push. AgBoardPanel and AgBoardTicket draw only the
342
+ * amber card, so nothing shows when Jira and the PRD agree (or nothing is pushed yet). Its button puts a question about the change in the ask box. */
343
+ function driftHtml(r, one) {
344
+ const it = TI(r);
345
+ const keys = ((it && it.drift) || []).filter((k) => !one || k === one);
346
+ if (!keys.length) return '';
347
+ const q = 'What changed in the PRD after ' + keys.join(', ') + ' ' + (keys.length === 1 ? 'was' : 'were') + ' pushed?';
348
+ const btn = `<button type="button" class="bd-ib sm" data-pk="drift" data-q="${esc(q)}" aria-label="Ask about the PRD change" title="Ask about the PRD change">${SV(one ? I.spark : I.note)}</button>`;
349
+ return one
350
+ ? `<div class="pk-wt">${SV(I.flag)}<span><b>The PRD changed after the push.</b> ${esc(keys[0])} was pushed from an older PRD. Review it before the next push.</span>${btn}</div>`
351
+ : `<div class="pk-wt">${SV(I.flag)}<span><b>Jira differs from the PRD</b> · ${esc(keys.join(', '))} ${keys.length === 1 ? 'was' : 'were'} pushed from an older PRD. Review ${keys.length === 1 ? 'it' : 'them'} before the next push.</span>${btn}</div>`;
352
+ }
353
+ const DEP_ST = (d) => (!d.known ? 'not on this repository' : d.done ? 'done' : d.stage || 'open');
354
+ function linkedHtml(r) {
355
+ const it = TI(r), L = (it && it.links) || {}, epic = L.epic || (r.epics || [])[0];
356
+ // AgBoardPanel: PRD v3 · Rubric · Release notes · Blocks <initiative> · Epic <key>. A chip shows only where something is linked.
357
+ const doc = (label, path) => (path ? `<button type="button" class="bd-chip" data-doc="${esc(path)}" title="${esc(path)}">${SV(I.doc)}${esc(label)}</button>` : '');
358
+ const D = (it && it.deps) || [];
359
+ const chips = doc(L.prdVersion ? 'PRD v' + String(L.prdVersion).replace(/^v/i, '') : 'PRD', L.prd) + doc('Rubric', L.rubric) + doc('Evaluation', L.evaluation) + doc('Release notes', L.notes)
360
+ + D.map((d) => `<span class="bd-chip" title="${esc((d.title || d.id) + ': ' + DEP_ST(d))}">${SV(I.link)}${esc('Waits on ' + (d.title || d.id))}</span>`).join('')
361
+ + (epic ? `<span class="bd-chip">${SV(I.jira)}${esc('Epic ' + epic)}</span>` : '');
362
+ return chips ? `<div class="pk-sec"><p class="lbl">Linked</p><div class="pk-lk">${chips}</div></div>` : '';
363
+ }
364
+ function iniPanel(r) {
365
+ const t = r.track || {}, s0 = statusOf(r);
366
+ const s = r.release && /^Ships /.test(s0.text) ? { ...s0, text: 'On track' } : s0; // the line already says when it ships
367
+ const when = r.release ? `<span>·</span><span>ships <b>${esc(fmt(r.release.iso))}</b> with ${esc(r.release.name)}</span>` : r.end ? `<span>·</span><span>plan ends <b>${esc(fmt(r.end))}</b></span>` : '';
368
+ // the status line is one line, as AgBoardPanel draws it; "usually N days" stays in the step's tooltip
369
+ return `<div class="pk-h"><div class="pk-ht"><p class="pk-eye">${esc(eyeOf(r).join(' · '))}</p><h2 id="pkTitle">${esc(r.title)}</h2><p class="pk-st"><span class="cs s-${s.tone}"><i class="cz-dot ${s.tone} ${s.mo}"></i>${esc(s.text)}</span><span>·</span><span title="${esc(dayTitle(t))}">${t.ms ? '<i class="cz-ms" aria-hidden="true"></i>' : ''}<b>${esc(t.label || r.stage || 'No stage')}</b>${t.days != null ? ' day ' + t.days : ''}</span>${when}</p></div>`
370
+ + `<div class="pk-tools">${r.id ? `<a class="bd-ib" data-pk="expand" href="${esc(pageHref(r))}" aria-label="Open the initiative page" title="Open the initiative page">${SV(I.expand)}</a>` : ''}<button type="button" class="bd-ib" data-pk="acts" aria-label="Initiative actions" title="Initiative actions">${SV(I.more)}</button><button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(I.x)}</button></div></div>`
371
+ + `<div class="pk-b">${ladderHtml(t)}${skipHtml(t)}`
372
+ + nextHtml(r)
373
+ + `<div class="pk-box"><div class="t1"><b>${esc(t.output || 'No step on record')}</b><span>${esc(t.count || '')}</span></div>${segHtml(r, true)}<div class="pk-tks">${outRows(r)}</div>${typeof t.next === 'string' && t.next && !(t.tickets || []).length ? `<p class="pk-nx">Next: <b>${esc(t.next)}</b></p>` : ''}</div>`
374
+ + draftedHtml(r) + driftHtml(r) + linkedHtml(r) // the dependencies are Linked chips, as AgBoardPanel draws them
375
+ + `</div>${askForm(r, r.title)}`;
376
+ }
377
+ function timePanel(r) {
378
+ const t = r.track || {}, k = t.k, epic = (r.epics || [])[0];
379
+ const eye = eyeOf(r, true).concat(epic ? ['epic ' + epic] : ['no Jira epic yet']);
380
+ const lad = `<div class="pk-seg" aria-hidden="true">${M.steps.map((_, j) => `<i class="${j < k ? 'p' : j === k ? 'c' : ''}"></i>`).join('')}</div>`;
381
+ const need = t.you
382
+ ? `<div class="pk-need"><i class="cz-dot you m-info"></i><div class="t"><b>${esc(t.you)}</b><div>${esc(t.youKind ? t.youWhy || '' : 'Every release ticket is done.')}</div></div>${r.id ? `<a class="bd-ib" href="${esc(pageHref(r))}" aria-label="Open the initiative page" title="Open the initiative page">${SV(I.ext)}</a>` : ''}</div>`
383
+ : ''; // AgBoardTimelinePanel draws the card only when something waits on you
384
+ const tks = (t.tickets || []).slice(0, 8).map((x) => `<button type="button" class="wi" data-tk="${esc(x.key)}" data-ini="${esc(r.key)}"><span class="wk">${esc(x.key)}</span><span class="wt2">${esc(x.title)}</span><span class="st${x.blocked ? ' r' : x.status === 'Done' ? '' : ' y'}">${esc(x.blocked ? 'Blocked' : x.status)}</span></button>`).join('');
385
+ // AgBoardTimelinePanel: change the plan dates, move, hold, archive. Dates go through Home (no route writes plan dates from the Board).
386
+ const acts = `<a class="bd-ib" href="${esc(askHref(r, 'Propose new start and end dates for ' + r.title))}" aria-label="Change the plan dates" title="Change the plan dates">${SV(I.cal)}</a>`
387
+ + [['move', 'Move to another stage'], ['hold', 'Put on hold'], ['archive', 'Archive']].map(([i, n]) => `<button type="button" class="bd-ib" data-pk="acts" aria-label="${n}" title="${n}">${SV(I[i])}</button>`).join('');
388
+ const D = (TI(r) && TI(r).deps) || [], open = D.filter((d) => d.known && !d.done);
389
+ const dep = D.length ? `<div class="pk-dep">${SV(I.link)}<div><b>Waits on ${esc(D.map((d) => d.title || d.id).join(', '))}</b><div>${esc(D.map((d) => (d.title || d.id) + ': ' + DEP_ST(d)).join(' · '))}.${open.length ? ' Its own dates hold only once ' + (open.length === 1 ? 'that one is' : 'those are') + ' done.' : ''}</div></div></div>`
390
+ : ''; // no card when nothing is on record
391
+ return `<div class="pk-h"><div class="pk-ht"><p class="pk-eye">${esc(eye.join(' · '))}</p><h2 id="pkTitle">${esc(r.title)}</h2></div><div class="pk-tools">${r.id ? `<a class="bd-ib" data-pk="expand" href="${esc(pageHref(r))}" aria-label="Open the initiative page" title="Open the initiative page">${SV(I.ext)}</a>` : ''}<button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(I.x)}</button></div></div>`
392
+ + `<div class="pk-b"><div><p class="pk-stp"><b>${esc(t.label || 'No step')}</b>${k >= 0 ? ' · step ' + (k + 1) + ' of 8' : ''}</p>${lad}</div>${need}`
393
+ + `<div class="pk-sec"><p class="lbl">Dates</p><div class="pk-kv"><span>PMOS plan</span><b>${esc(r.start || r.end ? [r.start ? fmt(r.start) : '…', r.end ? fmt(r.end) : '…'].join(' → ') : 'No dates on record')}</b><span>Jira forecast</span><b>${esc(t.forecastLabel ? fmt(t.forecast) : 'No open ticket in a dated sprint')}</b></div></div>`
394
+ + dep
395
+ + `<div class="pk-sec"><p class="lbl">Tickets · ${(t.tickets || []).length} in Jira</p>${tks ? `<div class="pk-wis">${tks}</div>` : '<p class="pk-mut">No ticket of this initiative is in a Jira reading.</p>'}</div>`
396
+ + `<div class="pk-sec"><p class="lbl">Initiative</p><div class="pk-acts">${acts}</div></div></div>${askForm(r, r.title, { inside: true })}`;
397
+ }
398
+ /** The blocker's own summary, where its key (in the reason) is a ticket of a row on this board. */
399
+ function blockerTitle(reason) {
400
+ const m = /\b([A-Z][A-Z0-9]+-\d+)\b/.exec(String(reason || '')); if (!m) return '';
401
+ for (const r of (M && M.rows) || []) { const x = ((r.track && r.track.tickets) || []).find((y) => y.key === m[1]); if (x && x.title && x.title !== x.key) return x.title; }
402
+ return '';
403
+ }
404
+ function tkPanel(r, k) {
405
+ const t = r.track || {}, x = TI(r) && TI(r).tickets ? TI(r).tickets[k.key] : null, sub = x && x.subtasks;
406
+ // what a blocker delays: the sprint it sits in ends, and the release the initiative rides on
407
+ const slip = k.sprintEnd ? 'If it is not fixed by ' + fmt(k.sprintEnd) + ', the end of ' + (k.sprint || 'its sprint') + ', ' + (r.release ? r.release.name + ' on ' + fmt(r.release.iso) + ' slips.' : 'it carries into the next sprint.') : r.release ? 'It holds up ' + r.release.name + ' on ' + fmt(r.release.iso) + '.' : '';
408
+ // AgBoardTicket: Blocked 2 days · In review · (M) Mei · 5 pts · Sprint 24, each field only where the Jira reading holds it
409
+ const bd = k.blockedDays != null ? ' ' + k.blockedDays + ' ' + plural(k.blockedDays, 'day', 'days') : '';
410
+ const meta = [k.blocked ? `<span class="cs s-red"><i class="cz-dot red m-crit"></i>Blocked${esc(bd)}</span>` : '', esc(k.raw && !(k.blocked && /block/i.test(k.raw)) ? k.raw : k.blocked ? '' : k.status), k.assignee ? `<span class="pk-who"><span class="pk-av" aria-hidden="true">${esc(k.assignee.charAt(0))}</span>${esc(k.assignee)}</span>` : '', k.points != null ? esc(k.points + ' pts') : '', k.sprint ? esc(k.sprint) : ''].filter(Boolean).join('<span>·</span>');
411
+ const reason = k.reason || (x && x.reason) || 'Flagged as blocked in Jira', bt = blockerTitle(reason);
412
+ // the subtasks: one row each where the reading lists them; else the reading's two counts as rows (done, open)
413
+ const items = sub && Array.isArray(sub.items) ? sub.items : null;
414
+ const subRows = items && items.length ? items.map((y) => `<p class="gi gm"><i class="k${y.done ? ' dn' : ''}"></i><span class="n">${esc(y.name || y.summary || '')}</span><span class="r">${y.done ? 'done' : 'open'}</span></p>`).join('')
415
+ : sub && sub.total ? [[sub.done, 'done', ' dn'], [sub.total - sub.done, 'open', '']].filter(([n]) => n > 0).map(([n, w, c]) => `<p class="gi gm"><i class="k${c}"></i><span class="n">${n} ${plural(n, 'subtask', 'subtasks')}</span><span class="r">${w}</span></p>`).join('')
416
+ : '<p class="gi gm"><i class="k"></i><span class="n">No subtasks are in the Jira reading</span></p>';
417
+ return `<div class="pk-h"><div class="pk-ht"><button type="button" class="pk-back" data-pk="back">${SV(I.next)}${esc(r.title)} · ${esc(t.label || '')}</button><h2 id="pkTitle">${esc(k.key)} · ${esc(k.title)}</h2><p class="pk-st">${meta}</p></div>`
418
+ + `<div class="pk-tools">${k.url ? `<a class="bd-ib" href="${esc(k.url)}" target="_blank" rel="noopener" aria-label="Open ${esc(k.key)} in Jira" title="Open in Jira">${SV(I.ext)}</a>` : ''}<button type="button" class="bd-ib" data-pk="close" aria-label="Close" title="Close">${SV(I.x)}</button></div></div>`
419
+ + `<div class="pk-b">${k.blocked ? `<div class="pk-nb red"><div class="t"><b>${esc(reason)}</b>${bt ? `<span class="pk-bt"> · ${esc(bt)}</span>` : ''}${slip ? `<div>${esc(slip)}</div>` : ''}</div>${k.url ? `<a class="bd-ib" href="${esc(k.url)}" target="_blank" rel="noopener" aria-label="Comment in Jira" title="Comment in Jira">${SV(I.note)}</a>` : ''}</div>` : ''}`
420
+ + driftHtml(r, k.key)
421
+ + `<div class="pk-box"><div class="t1"><b>Subtasks</b><span>${sub && sub.total ? sub.done + ' of ' + sub.total : ''}</span></div><div class="pk-tks">${subRows}</div></div>`
422
+ + `<div class="pk-sec"><p class="lbl">Counts toward</p><p class="pk-p">${esc(t.output || '')} · ${esc(t.count || '')}</p></div>`
423
+ + '<p class="pk-mut">PMOS owns the ticket text. Status, sprint and assignee change only in Jira.</p></div>'
424
+ + askForm(r, k.key);
425
+ }
426
+ function showPeek(html, back) {
427
+ const pk = $('#peek'); pk.innerHTML = html; pk.hidden = false; document.body.classList.add('pk-on');
428
+ pk.classList.toggle('pk-tl', !!peek && peek.kind === 'ini' && peek.from === 'time'); // AgBoardTimelinePanel is 420 px wide
429
+ if (back && !$('#peek').contains(back)) peekBack = back; // a press inside the panel keeps the row the panel was opened from
430
+ $$('#ibBody [data-row]').forEach((x) => x.classList.toggle('sel', !!peek && peek.kind !== 'acts' && x.dataset.row === peek.key));
431
+ $$('#ibBody .tgp-r').forEach((x) => x.classList.toggle('sel', !!peek && peek.kind !== 'acts' && x.dataset.key === peek.key));
432
+ const h = $('#pkTitle'); if (h) { h.tabIndex = -1; h.focus({ preventScroll: true }); }
433
+ }
434
+ function closePeek() {
435
+ if ($('#peek').hidden) return;
436
+ const key = peek && peek.key;
437
+ $('#peek').hidden = true; document.body.classList.remove('pk-on'); peek = null;
438
+ $$('#ibBody .sel').forEach((x) => x.classList.remove('sel'));
439
+ // a read can draw the rows again while the panel is open: then the focus goes to the same row as drawn now
440
+ const back = peekBack && document.contains(peekBack) ? peekBack : key ? $$('#ibBody [data-key]').find((x) => x.dataset.key === key) : null;
441
+ if (back) back.focus(); peekBack = null;
442
+ }
443
+ function openIni(r, from, where) {
444
+ if (!r || !r.track) return;
445
+ peek = { kind: 'ini', key: r.key, from: where || 'track' }; showPeek(peek.from === 'time' ? timePanel(r) : iniPanel(r), from);
446
+ }
447
+ function openTicket(iniKey, key, from) {
448
+ const r = rowOf(iniKey); if (!r || !r.track) return;
449
+ const k = (r.track.tickets || []).find((x) => x.key === key); if (!k) return;
450
+ peek = { kind: 'tk', key: r.key, tk: key, from: peek && peek.from }; showPeek(tkPanel(r, k), from);
451
+ }
452
+ $('#peek').addEventListener('click', (e) => {
453
+ const r = peek && rowOf(peek.key);
454
+ const tk = e.target.closest('[data-tk]'); if (tk) { openTicket(tk.dataset.ini, tk.dataset.tk); return; }
455
+ const b = e.target.closest('[data-pk]'); if (!b) return;
456
+ const a = b.dataset.pk;
457
+ if (a === 'close') closePeek();
458
+ else if (a === 'back' && r) { peek = { kind: 'ini', key: r.key, from: peek.from }; showPeek(peek.from === 'time' ? timePanel(r) : iniPanel(r)); }
459
+ else if (a === 'jira') refreshJira(b);
460
+ else if (a === 'drift') { const q = $('#peek form.pk-ask input[name="q"]'); if (q) { q.value = b.dataset.q || ''; q.focus(); } }
461
+ else if (a === 'acts' && r) Acts.open.row(r, b);
163
462
  });
164
- $('#docTop').addEventListener('input', (e) => { if (e.target.id === 'dmQ') { docQuery = e.target.value; drawDocList(); } });
165
- /* A document's Open stays on the premium pages (premium-rows-stay-premium): the board's own cards, the release dialog, Insights for a report, the Briefing's Horizon scan. */
166
- const wsQ = (k) => (M.board.ws ? k + 'ws=' + encodeURIComponent(M.board.ws) : '');
167
- const toCard = (id) => { const c = $(id); if (!c) return false; c.scrollIntoView({ behavior: 'smooth', block: 'start' }); const f = c.querySelector('button, a'); if (f) f.focus({ preventScroll: true }); return true; };
168
- const GOTAB = {
169
- rep: () => location.assign('/premium-insights.html' + wsQ('?')),
170
- init: () => toCard('#cIni'),
171
- asks: () => toCard('#cAsks') || toCard('#cIni'),
172
- rel: () => { const r = rowOf('board:release'); if (r) openRow(r); else toCard('#cRel'); },
173
- scan: () => location.assign('/premium.html?around=scan' + wsQ('&')),
174
- };
175
- $('#docBody').addEventListener('click', async (e) => {
176
- const o = e.target.closest('[data-doc]'); if (o) { docSheet.open(M.docs.rows.find((x) => x.key === o.dataset.doc)); return; }
177
- const t = e.target.closest('[data-tab]'); if (t) { (GOTAB[t.dataset.tab] || GOTAB.init)(); return; }
178
- const b = e.target.closest('[data-draft]'); if (!b || b.disabled) return;
179
- const key = b.dataset.draft, d = M.docs.rows.find((x) => x.key === key);
180
- b.disabled = true;
181
- const res = await pmPost('/api/core-docs/draft', { ws: M.board.ws, scope: M.docs.scope, key });
182
- if (!res || res.ok !== true) { b.disabled = false; toast((res && res.error) || 'The draft could not be started.'); return; }
183
- toast('The agent is drafting “' + (d ? d.title : key) + '”. It runs in the background and sends nothing.');
184
- await load();
463
+ /** A linked document opens in the Viewer: GET /api/doc, shown as its text. */
464
+ document.addEventListener('click', (e) => {
465
+ const d = e.target.closest('[data-doc]'); if (!d || !M) return;
466
+ const path = d.dataset.doc, ws = M.board.ws || '';
467
+ viewerOpen({ kind: 'Document', title: path.split('/').pop(), icon: 'doc', id: 'doc:' + path, render: async (body) => {
468
+ body.innerHTML = '<p class="bd-amut">Reading the document…</p>';
469
+ let text = null; try { const res = await fetch('/api/doc?ws=' + encodeURIComponent(ws) + '&path=' + encodeURIComponent(path), { credentials: 'same-origin' }); text = res.ok ? await res.text() : null; } catch { text = null; }
470
+ body.innerHTML = text == null ? `<p class="bd-amut">${esc(path)} could not be read.</p>` : `<p class="bd-amut">${esc(path)}</p><pre class="bd-doc">${esc(text)}</pre>`;
471
+ } });
472
+ });
473
+ $('#peek').addEventListener('submit', (e) => {
474
+ const f = e.target.closest('form.pk-ask[data-ask]'); if (!f) return;
475
+ e.preventDefault();
476
+ const r = rowOf(f.dataset.ask), q = f.q.value.trim();
477
+ if (!q) { f.q.focus(); return; }
478
+ location.assign(askHref(r, peek && peek.kind === 'tk' ? peek.tk + ': ' + q : q));
185
479
  });
186
480
 
187
- $('#addDoc').onclick = () => openAddDoc({ ws: M.board.ws, scope: M.docs.scope, sub: M.board.name, onAdded: load });
481
+ /* ── the tools the Agreed design draws but has no frame for: plain versions with a "Waiting for design" tag (pm/bd-acts.js) ─────────── */
482
+ $('#bdFind').addEventListener('click', (e) => Acts.open.find(e.currentTarget));
483
+ $('#bdFilter').addEventListener('click', (e) => Acts.open.filter(e.currentTarget));
484
+ $('#newIni').addEventListener('click', (e) => Acts.open.new(e.currentTarget));
485
+ $('#bdBell').addEventListener('click', (e) => { if (M) Acts.open.bell(e.currentTarget); });
188
486
 
189
- /* ── new asks and New initiative (initiative premium-board-actions) ───────────────────────────────────────── */
190
- function drawAsks() {
191
- $('#asksHost').innerHTML = asksHtml(ctxOf(), M.asks);
192
- $('#newIni').hidden = !!M.board.self || !M.board.id;
487
+ /* ── tabs: Initiatives and Documents (Documents has no frame yet: a plain list) ──────────────────────────────────────────────────────── */
488
+ function setTab(t) {
489
+ tab = t;
490
+ $('#tabIni').setAttribute('aria-selected', String(t === 'ini')); $('#tabDocs').setAttribute('aria-selected', String(t === 'docs'));
491
+ $('#cIni').hidden = t !== 'ini'; $('#cDocs').hidden = t !== 'docs';
492
+ if (t === 'docs') { closePeek(); $('#docBody').innerHTML = M ? Acts.docsHtml() : ''; }
193
493
  }
194
- $('#asksHost').addEventListener('click', (e) => { if (M) onAsks(e, ctxOf(), M.asks); });
195
- $('#newIni').onclick = () => { closeMenu(); openIniForm(ctxOf(), null); };
196
-
197
- /* ── dock ───────────────────────────────────────────────────────────────────────────────────────────────── */
198
- function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.label; $('#dNext').innerHTML = (M.dock.next ? `<i></i>First <b>${esc(M.dock.next)}</b>` : 'Nothing is late or at risk') + (M.dock.release ? ` <span class="sep"></span> Next release <b>${esc(M.dock.release.at)}</b> ${esc(M.dock.release.name)}` : ''); }
494
+ $('#tabIni').onclick = () => setTab('ini');
495
+ $('#tabDocs').onclick = () => setTab('docs');
496
+ $('.bd-tabs').addEventListener('keydown', (e) => { if (e.key !== 'ArrowRight' && e.key !== 'ArrowLeft') return; const n = tab === 'ini' ? 'docs' : 'ini'; setTab(n); $(n === 'ini' ? '#tabIni' : '#tabDocs').focus(); });
199
497
 
200
- /* ── the dialog: the initiative's record, no press, the read-only agent beside it ──────────────────────────── */
201
- function cardHtml(r) { return `<div class="acard" id="card"><p class="ct">What this page can do</p><p class="nodef" id="holdWhy">${esc(r.dialog.hold)}</p></div>`; }
202
- function paneHtml(r) {
203
- const p = r.dialog.pane;
204
- return `<article class="paper doc">${p.file ? `<p class="dpath">${esc(p.file)}</p>` : ''}${p.rows.length ? `<div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>` : ''}<p class="xn">${esc(p.note || 'The initiative as the board holds it.')}</p>${r.id && r.dialog.eye === 'Initiative' ? recordPress() : ''}</article>`;
205
- }
206
- function openRow(r) {
207
- if (!r) return;
208
- const d = r.dialog;
209
- openDlg({ eye: d.eye + ' · real data', title: r.title, sub: r.sub + (r.statusLabel ? ' · ' + r.statusLabel : ''), say: d.say, stream: turnA(logHtml(d)) + turnA(ptx(d.say)) + cardHtml(r), noteKey: r.key, pane: paneHtml(r), label: d.pane.label }); // every dialog has the short phone head (premium-shell openDlg), so the sprint board gets the height
210
- const vb = $('#oMain [data-vwopen]'); if (vb) vb.onclick = () => openWorkItem({ kind: 'initiative', id: r.id, title: r.title, ws: M.board.ws, board: M.board.id }); // its record, checks, tasks and links as a viewer tab (premium-viewer S7)
211
- loadThread(r.key);
212
- if (r.key === 'board:sprint') openSprint({ ws: M.board.ws, board: M.board.id, name: r.title }); // the sprint as a board by status, beside its facts (premium-viewer S5)
213
- setTimeout(() => { const b = $('#dBody'); b.scrollTop = b.scrollHeight; }, 120);
214
- }
215
- /* the sprint dialog opens the board's Jira backlog beside it, as a viewer tab (premium-viewer R10); the button is added to #oMain, never re-rendering it */
216
- function backlogBtn() {
217
- const at = $('#oMain .paper'); if (!at || !M.board.id) return;
218
- const w = document.createElement('div'); w.className = 'cact';
219
- const b = document.createElement('button'); b.type = 'button'; b.className = 'cta alt'; b.id = 'openBacklog'; b.textContent = 'Open the backlog';
220
- b.onclick = () => openBacklog({ ws: M.board.ws, board: M.board.id, title: 'Backlog' });
221
- w.append(b); at.append(w);
222
- }
223
- $('#dBody').addEventListener('click', (e) => { const lt = e.target.closest('#logT'); if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); } });
498
+ /* ── the shell's bell sits before New initiative, as the design orders the tools; Escape closes a popover, then the panel ──────── */
499
+ /* the ⋯ menu ("More: sources, archived, export" in AgBoard): the Board adds Metrics and Cancelled and archived, plain versions waiting for design */
500
+ {
501
+ const st = $('#settingsBtn');
502
+ if (st) st.insertAdjacentHTML('beforebegin', ['metrics', 'gone'].map((k) => `<button role="menuitem" id="${k === 'metrics' ? 'bdMetrics' : 'bdGone'}" aria-haspopup="dialog" data-open="${k}">${k === 'metrics' ? 'Metrics' : 'Cancelled and archived'}<span class="bd-wtag">Waiting for design</span></button>`).join(''));
503
+ $$('#moreMenu [data-open]').forEach((b) => { b.onclick = () => { if (M) Acts.open[b.dataset.open]($('#moreBtn')); }; });
504
+ }
505
+ window.addEventListener('keydown', (e) => {
506
+ if (e.key !== 'Escape' || document.querySelector('.pv-ov:not([hidden]), #moreMenu:not([hidden]), #crMenu:not([hidden]), #czMenu:not([hidden])')) return;
507
+ if ($$('.bd-pop').some((p) => !p.hidden)) { closePops(true); return; }
508
+ if (!$('#peek').hidden) closePeek();
509
+ }, true);
224
510
 
225
511
  /* ── load: the routes derive the initiatives in the background, so the first answers are "reading" ───────────── */
512
+ /* ── the trail (GET /api/board-trail): merged into the rows each time the model or the trail lands ──────────────────────── */
513
+ /** Adds to each row what the trail holds: days in the step, the skipped steps and why, the parts of the output and the next one, and what
514
+ * waits on you. Tickets stay the output of Build and Deliver; the parts replace the record's single progress for the other steps. */
515
+ function mergeTrail() {
516
+ if (!M || !TR || !TR.items) return;
517
+ const G = M.initiatives.gone || {}, all = [...(M.rows || []), ...M.initiatives.list.rows, ...(G.cancelled || []), ...(G.archived || [])]; // separate copies after JSON
518
+ for (const r of all) {
519
+ const it = r.id ? TR.items[r.id] : null; r.trail = it || null;
520
+ const t = r.track; if (!it || !t || t.trailed) continue;
521
+ t.trailed = true;
522
+ if (t.days == null && it.days != null) t.days = it.days;
523
+ const sk = new Set(t.skipped || []);
524
+ for (const x of it.skipped || []) { const j = (M.steps || []).findIndex((s) => s.key === x.stage); if (j >= 0) sk.add(j); }
525
+ t.skipped = [...sk].sort((a, b) => a - b); t.skipWhy = it.skipped || [];
526
+ const ticketStep = (t.key === 'build' || t.key === 'deliver') && (t.tickets || []).length;
527
+ if (it.parts && it.parts.length && !ticketStep) {
528
+ const n = it.parts.length, d = it.parts.filter((x) => x.done).length;
529
+ t.segs = it.parts.map((x) => ({ cls: x.done ? 'dn' : x.you ? 'yo' : '', name: x.name.charAt(0).toUpperCase() + x.name.slice(1), st: x.done ? 'done' : x.you ? 'waiting on you' : 'not yet' }));
530
+ t.pct = null; t.count = d + ' of ' + n + ' parts'; t.next = it.next || null;
531
+ t.line = it.next ? [{ text: 'Next: ' + it.next }] : [{ text: 'Every part is done' }];
532
+ }
533
+ if (!t.you && it.you) { t.you = it.you.text; t.youWhy = it.you.why || ''; t.youKind = it.you.kind || 'you'; }
534
+ }
535
+ }
536
+ async function loadTrail() {
537
+ const ids = [...new Set((M.rows || []).filter((r) => r.id && r.track).map((r) => r.id))].slice(0, 150);
538
+ if (!ids.length) return;
539
+ const q = 'ws=' + encodeURIComponent(M.board.ws || '') + (M.board.id ? '&board=' + encodeURIComponent(M.board.id) : '') + '&ids=' + ids.map(encodeURIComponent).join(',');
540
+ let r = null; try { r = await (await fetch('/api/board-trail?' + q, { credentials: 'same-origin' })).json(); } catch { r = null; }
541
+ if (!r || !r.ok) { TR = TR || { usual: {}, themes: [], items: {}, failed: true }; return; }
542
+ TR = r; mergeTrail(); draw();
543
+ }
544
+
226
545
  function draw() {
227
- const mk = menuKey(); closeMenu();
228
- drawMode(); drawHead(); drawInit(); drawAsks(); drawSide(); drawDocs(); drawDock(); onScroll();
229
- // a read that lands while a row's menu is open draws the row again: open its menu again, with what the row holds now
230
- if (mk) { const b = $$('#ibBody [data-im]').find((x) => x.dataset.im === mk), r = rowOf(mk); if (b && r) openMenu(b, ctxOf(), r); }
546
+ mergeTrail();
547
+ if (!sprintSet && M.jira && M.jira.sprint) { F.chips.add('sprint'); sprintSet = true; }
548
+ drawHead(); drawChips(); drawInit();
549
+ $('#docCap').textContent = M.docs && M.docs.rows ? String(M.docs.rows.length) : '';
550
+ { const g = $('#bdGone'), G = M.initiatives.gone || { cancelled: [], archived: [] }, n = [G.cancelled.length ? G.cancelled.length + ' cancelled' : '', G.archived.length ? G.archived.length + ' archived' : ''].filter(Boolean).join(' · ');
551
+ if (g) g.firstChild.textContent = 'Cancelled and archived' + (n ? ' · ' + n : ''); } // the ⋯ menu item counts them
552
+ if (tab === 'docs') $('#docBody').innerHTML = Acts.docsHtml();
553
+ // an open panel follows the new read
554
+ if (peek && peek.kind !== 'acts' && !$('#peek').contains(document.activeElement)) {
555
+ const r = rowOf(peek.key);
556
+ if (!r) closePeek(); else if (peek.kind === 'ini') showPeek(peek.from === 'time' ? timePanel(r) : iniPanel(r));
557
+ }
558
+ }
559
+ /** ?focus=<initiative id> (Insights links here): open that initiative's panel once, on the first read that has it. */
560
+ let focusDone = false;
561
+ function focusOnce() {
562
+ if (focusDone) return;
563
+ const id = new URLSearchParams(location.search).get('focus'); if (!id) { focusDone = true; return; }
564
+ const r = (M.rows || []).find((x) => x.id === id && x.track); if (!r) return;
565
+ focusDone = true;
566
+ const b = $$('#ibBody [data-key]').find((x) => x.dataset.key === r.key);
567
+ openIni(r, b || null, 'track');
231
568
  }
232
569
  async function load() {
233
570
  const p = new URLSearchParams(location.search), q = [p.get('ws') ? 'ws=' + encodeURIComponent(p.get('ws')) : '', p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
@@ -235,68 +572,22 @@ async function load() {
235
572
  try { const res = await fetch('/api/board-premium' + (q ? '?' + q : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
236
573
  clearInterval(readTimer);
237
574
  if (r && r.state === 'reading') {
238
- const t0 = Date.now(), tick = () => { $('#snap').textContent = 'Reading the board · ' + Math.round((Date.now() - t0) / 1000) + ' s so far'; };
575
+ const t0 = Date.now(), tick = () => { const s = 'Reading the board · ' + Math.round((Date.now() - t0) / 1000) + ' s so far'; $('#snap').textContent = s; if (!M) $('#ibBody').innerHTML = `<p class="bd-msg"><b>${esc(s)}</b> The board derives each initiative from its records. This page shows nothing until it has read, rather than guess.</p>`; };
239
576
  tick(); readTimer = setInterval(tick, 1000);
240
- if (!M) { $('#ibBody').innerHTML = '<p class="empty3 plain">The board derives each initiative from its records. This page shows nothing until it has read, rather than guess.</p>'; $('#docBody').innerHTML = ''; }
241
577
  setTimeout(load, 3000);
242
578
  return;
243
579
  }
244
580
  if (!r || !r.ok) {
245
581
  $('#snap').textContent = 'The board could not be read';
246
- $('#brief').textContent = 'The board could not be read, so this page shows nothing rather than guess.' + (r && r.error ? ' The reason: ' + r.error : status ? ' (the server answered ' + status + ')' : ' The server did not answer.');
582
+ if (!M) $('#ibBody').innerHTML = `<p class="bd-msg err" role="alert"><b>The board could not be read</b>, so this page shows nothing rather than guess.${r && r.error ? ' The reason: ' + esc(r.error) : status ? ' The server answered ' + status + '.' : ' The server did not answer.'}</p>`;
247
583
  setTimeout(load, 15000);
248
584
  return;
249
585
  }
250
- $('#brief').textContent = '';
251
- const first = !M; M = r.model; draw();
252
- if (first && M.board.ws) startMetrics(M.board.ws); // the Metrics card of a tenant's board reads apart from the board
253
- if (M.docs.rows.some((d) => d.running) || r.stale) setTimeout(load, r.stale ? 2000 : 5000); // a core-document run is going, or a press is still being derived: ask again // a core-document run is going: ask again until it ends
586
+ M = r.model; draw();
587
+ focusOnce();
588
+ if (r.stale) setTimeout(load, 2000); // a press is still being derived: ask again
589
+ else loadTrail();
254
590
  }
255
- $('#brief').textContent = 'Reading the board.';
591
+ Acts.init({ M: () => M, load, say, panel: actsPanel, close: closePeek, redraw: () => { drawChips(); drawInit(); }, F, rowOf, statusOf, openIni: (r) => openIni(r, $('#bdBell'), 'track') });
592
+ setTab('ini');
256
593
  load();
257
-
258
- /* ── the Metrics card of a tenant's board (initiative briefing-premium-metrics) ─────────────────────────────────
259
- * Reads GET /api/board-metrics-premium?ws= apart from the board's own answer and draws lib/board-metrics-premium.js's tiles: a number and a chart only
260
- * where a record counted one, "Not read" where it could not be. A tile opens the standard dialog. Nothing here writes. */
261
- let MM = null, metTimer = null; // the Metrics card's model and its re-read timer
262
-
263
- function metDraw() {
264
- const card = $('#cMet'); if (!MM) { card.hidden = true; return; }
265
- card.hidden = false;
266
- $('#metCap').textContent = MM.header;
267
- const ins = '/premium-insights.html' + (M.board.ws ? '?ws=' + encodeURIComponent(M.board.ws) + (M.board.id ? '&board=' + encodeURIComponent(M.board.id) : '') : '');
268
- $('#metHint').innerHTML = (MM.lead ? `<b class="mflag">${esc(MM.lead)}</b> ` : '') + esc(MM.body || MM.hint) + ` To set a target, or for longer ranges, <a class="lk" id="metIns" href="${esc(ins)}">open Insights</a>.`;
269
- $('#metBody').style.gridTemplateColumns = 'repeat(' + Math.min(4, MM.tiles.length) + ',minmax(0,1fr))';
270
- $('#metBody').innerHTML = MM.tiles.map(MT.tileHtml).join('');
271
- $('#metNote').textContent = MM.note;
272
- $('#metLead').hidden = !MM.lead; $('#metLead').textContent = MM.lead || ''; // the one line left in view; ⓘ opens the hint and the note
273
- pillOf($('#perTabs'));
274
- }
275
-
276
- function metOpenTile(i) {
277
- const t = MM.tiles[i], r = MM.rows[i]; if (!t || !r) return;
278
- const d = r.dialog;
279
- const rows = MT.factRows(t, MM.repo, MM.weeks);
280
- const vals = t.ser ? H('Values') + `<div class="vtb">${t.ser.map((v, j) => `<div><span>${esc(t.wk[j])}</span><b>${v == null ? (t.since ? 'Not kept yet' : 'No runs') : esc(MT.fmt(t, v))}</b></div>`).join('')}</div>` : '';
281
- const pane = `<article class="paper doc"><p class="lede" style="margin:0 0 10px">${esc(t.def)}</p>${kv(rows)}${vals}<p class="note" style="margin-top:12px">${esc(MM.note)}</p></article>`;
282
- openDlg({ eye: 'Measure · real data', title: t.label, sub: MM.repo, say: d.say, stream: turnA(logHtml({ logTitle: 'Read from the repository', log: ['Read the repository\'s own records', 'Counted them by week', 'Changed nothing'] })) + turnA(ptx(d.say)), noteKey: r.key, pane, label: 'Measure' });
283
- loadThread(r.key);
284
- }
285
-
286
- function metWire() {
287
- MT.wireTiles($('#metBody'), () => MM.tiles, metOpenTile);
288
- $('#perTabs').addEventListener('click', (e) => { const b = e.target.closest('[aria-disabled="true"]'); if (b) toast('PMOS counts runs and merges by week only.'); });
289
- }
290
-
291
- async function startMetrics(ws) {
292
- clearTimeout(metTimer);
293
- let r = null;
294
- try { const res = await fetch('/api/board-metrics-premium?ws=' + encodeURIComponent(ws || ''), { credentials: 'same-origin' }); r = await res.json(); } catch { r = null; }
295
- if (!r || !r.ok || r.state !== 'ready') {
296
- MM = null; metDraw(); $('#cMet').hidden = false; $('#metCap').textContent = 'not read'; $('#metHint').textContent = 'The metrics could not be read, so none is shown.' + (r && r.error ? ' The reason: ' + r.error : ''); $('#metLead').hidden = false; $('#metLead').textContent = $('#metHint').textContent; $('#metBody').innerHTML = ''; $('#metNote').textContent = '';
297
- return;
298
- }
299
- MM = r.model; metDraw();
300
- if (MM.pending) metTimer = setTimeout(() => startMetrics(ws), 4000); // the workflow engine is still deriving the Blocked and Idle tiles
301
- }
302
- metWire();