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
@@ -59,7 +59,7 @@ export function needsRowOf(x, ws) {
59
59
  const when = r.kind === 'overdue' ? lateWord(Math.max(1, Number(r.days_late) || 1)) : r.kind === 'due-today' ? 'Due today' : r.offline ? 'Outside PMOS' : '';
60
60
  return { key: 'own:' + r.key, src: 'own', title: r.headline || '', subject: ['Yours', when, r.person ? 'with ' + r.person : ''].filter(Boolean).join(' · '),
61
61
  prepared: r.evidence && r.evidence.text ? 'Looks done: ' + r.evidence.text + '. Confirm it in My work.' : 'Open it in My work to mark it done, put it off or drop it.',
62
- go: r.id ? '/premium-work.html?' + [q('item', r.id), ws ? q('ws', ws) : ''].filter(Boolean).join('&') : null };
62
+ go: r.id ? '/premium.html?' + [q('item', r.id), ws ? q('ws', ws) : ''].filter(Boolean).join('&') : null };
63
63
  }
64
64
  if (x.src === 'agent') {
65
65
  const blocked = r.kind === 'driver-blocked', docs = r.kind === 'core-doc-drafts', ini = r.initiative_id || '';
@@ -1,42 +1,46 @@
1
- /* pm/premium-chart-tab.js — the Chart tab beside a chat (initiative premium-reports-from-chat, slice C; PRD C1–C3). It replaces the Insight Studio's
2
- * Chart and Dashboard modes: the PM asks in the chat, Claude ends its answer with a `pmos-report` block of kind chart or dashboard
3
- * (public/pm/report-chat.js), and this tab draws it from the KR metric records, as the Insights page draws it (premium-chart-draw.js).
1
+ /* pm/premium-chart-tab.js — a chart or a dashboard from a chat, in the Viewer card (initiative premium-reports-from-chat, slice C; PRD C1–C3;
2
+ * re-drawn for premium-agreed-design, area viewer: Main.dc.html viewer "metrics"). The PM asks in the chat, Claude ends its answer with a
3
+ * `pmos-report` block of kind chart or dashboard (public/pm/report-chat.js), and this view draws it from the KR metric records.
4
4
  *
5
- * A CHART (block.kind 'chart'): the measure's chart as proposed, with its four forms to pick from. Save chart posts POST /api/premium-charts/save.
6
- * A saved chart (block.id) shows as saved; a change Claude proposes to it shows drawn, and Save the change posts the whole chart. Delete chart
7
- * asks once, then posts { id, remove: true }.
8
- * A DASHBOARD (block.kind 'dashboard'): its name, what it is for and its charts in order. Save dashboard posts POST /api/premium-dashboards/save;
9
- * Delete dashboard asks once, then posts { id, remove: true }. Pinning stays on the Insights page.
5
+ * A CHART (block.kind 'chart'): the design's metrics view: three stat tiles (now, since the last reading, the target), then the readings as a
6
+ * chart with the newest one in ember. Below it, the parts the design does not draw yet ("Waiting for design"): the four forms to pick from
7
+ * (Line, Bars, Number, Meter), Save chart (POST /api/premium-charts/save), and Delete chart, which asks once in the card ({ id, remove: true }).
8
+ * A saved chart (block.id) shows as saved; a change Claude proposes to it shows drawn, and Save the change posts the whole chart.
9
+ * A DASHBOARD (block.kind 'dashboard'): its charts in order as small tiles (a measure with fewer than two readings is named, not drawn), then
10
+ * Save dashboard (POST /api/premium-dashboards/save) and Delete dashboard, Waiting for design. Pinning stays on the Insights page.
10
11
  *
11
- * The model is GET /api/insights-premium (the board the page shows). Every value drawn is a reading of a record; a measure with fewer than two
12
- * readings is named, not drawn. Every write is a press here, behind the launch nonce (http.js pmPost). Claude writes nothing: the routes refuse an
13
- * agent session. Nothing is sent outward. */
12
+ * The model is GET /api/insights-premium (the board Insights shows). Every value drawn is a reading of a record. Every write is a press here,
13
+ * behind the launch nonce (http.js pmPost). Claude writes nothing: the routes refuse an agent session. Nothing is sent outward.
14
+ * The view draws in the czViewer card (cozy-viewer.js): no #dlg, no old tab, no premium.css. */
14
15
  import { pmGet, pmPost } from './http.js';
15
- import { vwOpen, vwStyle, vwConfirm } from './premium-viewer.js';
16
- import { tileHtml, deriveChart } from './premium-chart-draw.js';
16
+ import { open as vOpen, current as vCur, body as vBody } from './cozy-viewer.js';
17
+ import { vzStyle } from './premium-vw-open.js';
18
+ import { deriveChart, unitTxt } from './premium-chart-draw.js';
17
19
 
18
20
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
19
21
  const FORMS = [['line', 'Line'], ['bars', 'Bars'], ['number', 'Number'], ['meter', 'Meter']];
20
22
  const ws = () => new URLSearchParams(location.search).get('ws') || '';
21
23
  const post = (p, body) => pmPost(p, Object.assign(ws() ? { ws: ws() } : {}, body)).catch(() => null);
22
- const btn = (a, label, o = {}) => `<button type="button" class="btn${o.sec ? ' sec' : ''}${o.cls ? ' ' + o.cls : ''}" data-ct="${esc(a)}"${o.off ? ' disabled' : ''}${o.pressed != null ? ` aria-pressed="${o.pressed}"` : ''}>${esc(label)}</button>`;
24
+ const WAIT = (f) => `<span class="vz-wait" data-cz-placeholder="${esc(f)}">Waiting for design</span>`;
25
+ const btn = (a, label, o = {}) => `<button type="button" class="${o.sec ? 'vz-sec2' : 'vz-issue'} vz-hv${o.cls ? ' ' + o.cls : ''}" data-ct="${esc(a)}"${o.off ? ' disabled' : ''}>${esc(label)}</button>`;
23
26
 
24
- const T = new Map(); // tab id → its state
25
- /** Open (or refresh) the Chart tab for a checked chart or dashboard block (report-chat.js cleanBlock). */
27
+ const T = new Map(); // view id → its state
28
+ /** Open (or refresh) the view of a checked chart or dashboard block (report-chat.js cleanBlock). */
26
29
  export function openChartTab(block) {
27
30
  if (!block || (block.kind !== 'chart' && block.kind !== 'dashboard')) return null;
28
- vwStyle('report');
31
+ vzStyle();
29
32
  const P = block.proposal || {};
30
33
  const id = block.kind + ':' + String(block.id || P.measure || P.name || 'new').toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 60);
31
34
  let t = T.get(id);
32
35
  if (!t || JSON.stringify(t.block) !== JSON.stringify(block)) {
33
- t = { id, block, M: null, loaded: false, busy: false, msg: '', d: null, gone: false, removed: false };
36
+ t = { id, block, M: null, loaded: false, busy: false, msg: '', d: null, gone: false, removed: false, ask: null };
34
37
  T.set(id, t);
35
38
  load(t);
36
39
  }
37
- return vwOpen({ id, title: block.kind === 'chart' ? 'Chart' : 'Dashboard', icon: 'list', render: (el) => draw(t, el), wire: (el) => { el.onclick = (e) => press(t, e); } });
40
+ return vOpen({ id, kind: block.kind === 'chart' ? 'Chart' : 'Dashboard', title: titleOf(t), icon: 'chart', render: (el) => { el.onclick = (e) => press(t, e); draw(t, el); } });
38
41
  }
39
- const paneOf = (t) => document.querySelector(`#dOut .obody.vw[data-vw="${CSS.escape(t.id)}"]`);
42
+ const titleOf = (t) => { const P = t.block.proposal || {}, d = t.d || {}; return t.block.kind === 'chart' ? d.title || P.title || P.measure || t.block.id || 'Chart' : d.name || P.name || t.block.id || 'Dashboard'; };
43
+ const paneOf = (t) => (vCur() && vCur().id === t.id ? vBody() : null);
40
44
  const redraw = (t) => { const el = paneOf(t); if (el) draw(t, el); };
41
45
 
42
46
  async function load(t) {
@@ -59,18 +63,43 @@ async function load(t) {
59
63
  redraw(t);
60
64
  }
61
65
 
62
- /** A measure's or a saved chart's tile, as Insights draws it. */
63
- function chartOf(M, ref) {
64
- return (M.mine || []).find((c) => c.id === ref) || (M.charts || []).find((c) => c.id === ref) || null;
66
+ /* ── drawing (Main.dc.html viewer "metrics") ── */
67
+ const shortDay = (s) => String(s || '').replace(/^\d{4}-/, '').replace(/^(\d{2})-(\d{2}).*$/, (m, a, b) => ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][+a - 1] + ' ' + +b);
68
+ const labelOf = (p) => shortDay(String(p.at || p.d || '').slice(0, 10)) || String(p.d || '');
69
+ /** The three stat tiles: the reading now, the step since the last one, and the target. */
70
+ function kpisHtml(c, d) {
71
+ const u = c.unit && /^[%°]/.test(c.unit) ? c.unit : c.unit ? ' ' + c.unit : '';
72
+ const step = c.step === 0 ? 'No change' : (c.step > 0 ? 'Up ' : 'Down ') + Math.abs(c.step) + u;
73
+ const K = [['Now', c.v, 'on ' + c.at], ['Since the last reading', step, c.good === null ? 'Same as before' : c.good ? 'The right way' : 'The wrong way'],
74
+ ['Target', c.target !== null ? unitTxt(c, c.target) : 'None set', d.better === 'lower' ? 'Lower is better' : 'Higher is better']];
75
+ return `<div class="vz-kpis">${K.map(([l, v, n]) => `<div class="vz-kpi"><p>${esc(l)}</p><b>${esc(v)}</b><small>${esc(n)}</small></div>`).join('')}</div>`;
65
76
  }
66
- function draftTile(t) {
67
- const d = t.d, base = (t.M.charts || []).find((c) => c.id === d.measure);
68
- if (!base) {
69
- const m = (t.M.measures || []).find((x) => x.id === d.measure);
70
- return `<p class="rt-msg">${esc(m ? m.title + ' has fewer than two readings, so it has no chart yet.' : 'No KR metric record is called ' + d.measure + ' in this workspace.')}</p>`;
77
+ /** The readings drawn in the picked form, the newest in ember. Bars and a meter start at zero; a value below zero is drawn as a line. */
78
+ function figHtml(c, form, cap) {
79
+ const pts = c.pts, n = pts.length, neg = pts.some((p) => p.v < 0) || (c.target !== null && c.target < 0);
80
+ const f = form === 'bars' && !neg ? 'bars' : form === 'meter' && !neg && c.target !== null ? 'meter' : form === 'number' ? 'number' : 'line';
81
+ const alt = `${c.title}: ${n} readings from ${pts[0].txt} on ${pts[0].d} to ${c.v} on ${c.at}${c.targetTxt ? ', ' + c.targetTxt : ''}`;
82
+ if (f === 'number') return `<figure class="vz-mx-fig" data-form="number"><figcaption>${esc(cap)}</figcaption><p class="vz-mx-big" role="img" aria-label="${esc(alt)}">${esc(c.v)}</p></figure>`;
83
+ const W = 440, H = 150, B = 128, top = 22;
84
+ const hi = Math.max(...pts.map((p) => p.v), c.target !== null ? c.target : 0) || 1;
85
+ if (f === 'meter') {
86
+ const v = pts[n - 1].v, mx = Math.max(v, c.target) * 1.15 || 1, x = (k) => (k / mx * W).toFixed(1);
87
+ return `<figure class="vz-mx-fig" data-form="meter"><figcaption>${esc(cap)}</figcaption><svg class="vz-mx-svg" viewBox="0 0 ${W} 44" role="img" aria-label="${esc(alt)}"><rect class="vz-trk0" x="0" y="14" width="${W}" height="14" rx="7"/><rect class="vz-bar now" x="0" y="14" width="${x(v)}" height="14" rx="7"/><line class="vz-tgt" x1="${x(c.target)}" x2="${x(c.target)}" y1="6" y2="36"/></svg><p class="vz-note">${esc(c.v)} against ${esc(c.targetTxt)}</p></figure>`;
71
88
  }
72
- const c = deriveChart(base, { title: d.title || base.title, form: d.form || 'line', range: d.range || null, target: d.target, better: d.better || 'higher', note: d.note || '' });
73
- return c ? `<div class="ntw ct-tile">${tileHtml(c)}</div>` : '<p class="rt-msg">The range holds fewer than two readings, so nothing is drawn.</p>';
89
+ const slot = W / n, bw = Math.min(36, slot * 0.6), yOf = (v) => B - (v / hi) * (B - top);
90
+ const ty = c.target !== null ? yOf(c.target) : null;
91
+ let g = `<line class="vz-ax" x1="0" x2="${W}" y1="${B}" y2="${B}"/>`;
92
+ if (f === 'bars') g += pts.map((p, i) => { const y = yOf(Math.max(0, p.v)); return `<text class="vz-bv" x="${(slot * i + slot / 2).toFixed(1)}" y="${(y - 6).toFixed(1)}">${esc(p.txt)}</text><rect class="vz-bar${i === n - 1 ? ' now' : ''}" x="${(slot * i + (slot - bw) / 2).toFixed(1)}" y="${y.toFixed(1)}" width="${bw.toFixed(1)}" height="${Math.max(1, B - y).toFixed(1)}" rx="6"/>`; }).join('');
93
+ else {
94
+ const lo = Math.min(...pts.map((p) => p.v), c.target !== null ? c.target : Infinity), rg = (hi - lo) || 1, yL = (v) => B - ((v - lo) / rg) * (B - top);
95
+ const P = pts.map((p, i) => [slot * i + slot / 2, yL(p.v)]);
96
+ g += `<polyline class="vz-ln" points="${P.map((q) => q[0].toFixed(1) + ',' + q[1].toFixed(1)).join(' ')}"/>` + P.map((q, i) => `<circle class="vz-pt${i === n - 1 ? ' now' : ''}" cx="${q[0].toFixed(1)}" cy="${q[1].toFixed(1)}" r="${i === n - 1 ? 6 : 4}"/><text class="vz-bv" x="${q[0].toFixed(1)}" y="${(q[1] - 10).toFixed(1)}">${esc(pts[i].txt)}</text>`).join('');
97
+ if (c.target !== null) g += `<line class="vz-tgt" x1="0" x2="${W}" y1="${yL(c.target).toFixed(1)}" y2="${yL(c.target).toFixed(1)}"/>`;
98
+ }
99
+ if (f === 'bars' && ty !== null) g += `<line class="vz-tgt" x1="0" x2="${W}" y1="${ty.toFixed(1)}" y2="${ty.toFixed(1)}"/>`;
100
+ g += pts.map((p, i) => `<text class="vz-bx" x="${(slot * i + slot / 2).toFixed(1)}" y="${H - 4}">${esc(labelOf(p))}</text>`).join('');
101
+ const why = form !== f ? (neg ? 'A value is below zero, so it is drawn as a line.' : 'No target is set, so it is drawn as a line.') : '';
102
+ return `<figure class="vz-mx-fig" data-form="${f}"><figcaption>${esc(cap)}</figcaption><svg class="vz-mx-svg" viewBox="0 0 ${W} ${H}" role="img" aria-label="${esc(alt)}">${g}</svg>${c.target !== null ? '<p class="vz-note">The dashed line is the target.</p>' : ''}${why ? `<p class="vz-note">${esc(why)}</p>` : ''}</figure>`;
74
103
  }
75
104
  const sameChart = (a, b) => ['measure', 'title', 'question', 'form', 'range', 'target', 'better', 'note'].every((k) => (a[k] == null ? '' : String(a[k])) === (b[k] == null ? '' : String(b[k])));
76
105
 
@@ -78,46 +107,62 @@ function chartHtml(t) {
78
107
  const d = t.d, s = t.saved, base = (t.M.charts || []).find((c) => c.id === d.measure);
79
108
  const changed = !s || !sameChart(s, d);
80
109
  const eye = !s ? 'New chart · from this chat' : changed ? 'Chart change · from this chat' : 'Saved chart';
81
- const forms = `<div class="rt-seg" role="group" aria-label="Form">${FORMS.map(([f, l]) => btn('form|' + f, l, { sec: (d.form || 'line') !== f, pressed: (d.form || 'line') === f })).join('')}</div>`;
82
- const meter = d.form === 'meter' && (d.target === null || d.target === undefined) ? '<p class="rt-note">A meter needs a target. Say one in the chat, or pick another form.</p>' : '';
83
- return `<p class="rt-eye">${esc(eye)}</p><h3 class="rt-h">${esc(d.title || (base ? base.title : d.measure))}</h3>${d.question ? `<p class="rt-sub">${esc(d.question)}</p>` : ''}`
84
- + `<p class="rt-meta">${esc(base ? base.title : d.measure)}${d.range ? ' · last ' + d.range + ' readings' : ' · every reading'}${d.target != null ? ' · target ' + esc(d.target) : ''} · ${d.better === 'lower' ? 'lower is better' : 'higher is better'}</p>`
85
- + forms + draftTile(t) + meter
86
- + `<div class="rt-foot">${changed ? btn('save', t.busy ? 'Saving' : s ? 'Save the change' : 'Save chart', { off: t.busy || !base || !!meter }) : ''}</div>`
87
- + `<p class="rt-note">${s ? 'It shows on Insights under Your charts.' : 'Saved, it shows on Insights under Your charts and can go on a dashboard.'} Ask in the chat to change it.</p>`
88
- + (s ? `<div class="rt-foot rt-end">${btn('remove', 'Delete chart', { sec: true, cls: 'rt-del', off: t.busy })}</div>` : '');
110
+ const form = d.form || 'line';
111
+ let shown;
112
+ if (!base) { const m = (t.M.measures || []).find((x) => x.id === d.measure); shown = `<p class="vz-msg">${esc(m ? m.title + ' has fewer than two readings, so it has no chart yet.' : 'No KR metric record is called ' + d.measure + ' in this workspace.')}</p>`; }
113
+ else {
114
+ const c = deriveChart(base, { title: d.title || base.title, form, range: d.range || null, target: d.target, better: d.better || 'higher', note: d.note || '' });
115
+ const cap = (d.question || c && c.title || base.title) + (d.better === 'lower' ? ' (lower is better)' : '');
116
+ shown = c ? kpisHtml(c, d) + figHtml(c, form, cap) + (d.note ? `<p class="vz-note">${esc(d.note)}</p>` : '') : '<p class="vz-msg">The range holds fewer than two readings, so nothing is drawn.</p>';
117
+ }
118
+ const meter = form === 'meter' && (d.target === null || d.target === undefined) ? '<p class="vz-note">A meter needs a target. Say one in the chat, or pick another form.</p>' : '';
119
+ return shown
120
+ + `<section class="vz-blk" aria-label="${esc(eye)}"><div class="vz-r1"><h3>${esc(eye)}</h3>${WAIT('Chart setup from a chat')}</div>`
121
+ + `<p class="vz-note">${esc(base ? base.title : d.measure)}${d.range ? ' · last ' + d.range + ' readings' : ' · every reading'}${d.target != null ? ' · target ' + esc(d.target) : ''}</p>`
122
+ + `<div class="vz-sg" role="group" aria-label="Form">${FORMS.map(([f, l]) => `<button type="button" data-ct="form|${f}" aria-pressed="${form === f}">${l}</button>`).join('')}</div>${meter}`
123
+ + (changed ? `<div class="vz-r1">${btn('save', t.busy ? 'Saving' : s ? 'Save the change' : 'Save chart', { off: t.busy || !base || !!meter })}</div>` : '')
124
+ + `<p class="vz-note">${s ? 'It shows on Insights under Your charts.' : 'Saved, it shows on Insights under Your charts and can go on a dashboard.'} Ask in the chat to change it.</p>`
125
+ + (s ? `<div class="vz-r1">${btn('remove', 'Delete chart', { sec: true, off: t.busy })}</div>` : '') + '</section>';
126
+ }
127
+ /** A dashboard's chart as a small tile: its name, the reading now and its readings as small bars. */
128
+ function tileHtml(c) {
129
+ const pts = c.pts, n = pts.length, hi = Math.max(...pts.map((p) => Math.max(0, p.v))) || 1, slot = 200 / n, bw = Math.min(16, slot * 0.6);
130
+ return `<div class="vz-mx-tile"><p>${esc(c.title)}</p><b>${esc(c.v)}</b><small>on ${esc(c.at)}${c.targetTxt ? ' · ' + esc(c.targetTxt) : ''}</small>`
131
+ + `<svg class="vz-mx-svg" viewBox="0 0 200 44" role="img" aria-label="${esc(c.title + ': ' + n + ' readings, now ' + c.v)}">${pts.map((p, i) => { const h = Math.max(1, Math.max(0, p.v) / hi * 40); return `<rect class="vz-bar${i === n - 1 ? ' now' : ''}" x="${(slot * i + (slot - bw) / 2).toFixed(1)}" y="${(44 - h).toFixed(1)}" width="${bw.toFixed(1)}" height="${h.toFixed(1)}" rx="3"/>`; }).join('')}</svg></div>`;
89
132
  }
90
133
  function dashHtml(t) {
91
134
  const d = t.d, s = t.saved, M = t.M;
92
135
  const changed = !s || d.name !== s.name || d.purpose !== s.purpose || d.charts.join() !== s.charts.join();
93
136
  const eye = !s ? 'New dashboard · from this chat' : changed ? 'Dashboard change · from this chat' : 'Saved dashboard';
94
137
  const tiles = d.charts.map((ref) => {
95
- const c = chartOf(M, ref);
96
- if (c) return `<div class="ntw">${tileHtml(c)}</div>`;
138
+ const c = (M.mine || []).find((x) => x.id === ref) || (M.charts || []).find((x) => x.id === ref);
139
+ if (c) return tileHtml(c);
97
140
  const m = (M.measures || []).find((x) => x.id === ref);
98
- return `<div class="nempty"><p><b>${esc(m ? m.title : ref)}</b><br>${esc(m ? 'It has fewer than two readings, so it has no chart yet.' : 'No KR metric record or saved chart is called ' + ref + '.')}</p></div>`;
141
+ return `<div class="vz-mx-none"><p><b>${esc(m ? m.title : ref)}</b></p><small>${esc(m ? 'It has fewer than two readings, so it has no chart yet.' : 'No KR metric record or saved chart is called ' + ref + '.')}</small></div>`;
99
142
  }).join('');
100
- const many = d.charts.length > 6 ? '<p class="rt-note">This dashboard holds more than six charts. A dashboard that serves one routine usually holds six or fewer.</p>' : '';
101
- return `<p class="rt-eye">${esc(eye)}</p><h3 class="rt-h">${esc(d.name)}</h3>${d.purpose ? `<p class="rt-sub">${esc(d.purpose)}</p>` : ''}`
102
- + `<p class="rt-meta">${d.charts.length} ${d.charts.length === 1 ? 'chart' : 'charts'}${s && s.main ? ' · pinned on Insights' : ''}</p>`
103
- + `<div class="ngrid ct-grid">${tiles}</div>${many}`
104
- + `<div class="rt-foot">${changed ? btn('save', t.busy ? 'Saving' : s ? 'Save the change' : 'Save dashboard', { off: t.busy }) : ''}</div>`
105
- + `<p class="rt-note">${s ? 'It is in the list on Insights.' : 'Saved, it is in the list on Insights, where you can pin it.'} Ask in the chat to change it.</p>`
106
- + (s ? `<div class="rt-foot rt-end">${btn('remove', 'Delete dashboard', { sec: true, cls: 'rt-del', off: t.busy })}</div>` : '');
143
+ const many = d.charts.length > 6 ? '<p class="vz-note">This dashboard holds more than six charts. A dashboard that serves one routine usually holds six or fewer.</p>' : '';
144
+ return `${d.purpose ? `<p class="vz-sum">${esc(d.purpose)}</p>` : ''}<div class="vz-mx-grid">${tiles}</div>${many}`
145
+ + `<section class="vz-blk" aria-label="${esc(eye)}"><div class="vz-r1"><h3>${esc(eye)}</h3>${WAIT('Dashboard setup from a chat')}</div>`
146
+ + `<p class="vz-note">${d.charts.length} ${d.charts.length === 1 ? 'chart' : 'charts'}${s && s.main ? ' · pinned on Insights' : ''}</p>`
147
+ + (changed ? `<div class="vz-r1">${btn('save', t.busy ? 'Saving' : s ? 'Save the change' : 'Save dashboard', { off: t.busy })}</div>` : '')
148
+ + `<p class="vz-note">${s ? 'It is in the list on Insights.' : 'Saved, it is in the list on Insights, where you can pin it.'} Ask in the chat to change it.</p>`
149
+ + (s ? `<div class="vz-r1">${btn('remove', 'Delete dashboard', { sec: true, off: t.busy })}</div>` : '') + '</section>';
107
150
  }
108
151
  function bodyHtml(t) {
109
152
  const noun = t.block.kind;
110
- if (!t.loaded) return `<p class="rt-note" role="status">Reading the ${noun}.</p>`;
111
- if (!t.M) return `<p class="rt-note">The Insights records could not be read, so the ${noun} cannot be drawn. Try again in a moment.</p>`;
112
- if (t.removed) return `<p class="rt-eye">${noun === 'chart' ? 'Chart' : 'Dashboard'}</p><p class="rt-note">Deleted. Ask in the chat for a new one.</p>`;
113
- if (t.gone) return `<p class="rt-eye">${noun === 'chart' ? 'Chart' : 'Dashboard'}</p><h3 class="rt-h">${esc(t.block.id)}</h3><p class="rt-note">This ${noun} is deleted, or it is not saved on this board.</p>`;
114
- if (!t.M.board.id) return '<p class="rt-note">This workspace has no board to save on, so nothing can be saved here.</p>';
153
+ if (!t.loaded) return `<p class="vz-empty" role="status">Reading the ${noun}.</p>`;
154
+ if (!t.M) return `<p class="vz-msg">The Insights records could not be read, so the ${noun} cannot be drawn. Try again in a moment.</p>`;
155
+ if (t.removed) return '<p class="vz-msg">Deleted. Ask in the chat for a new one.</p>';
156
+ if (t.gone) return `<p class="vz-msg">This ${noun} (${esc(t.block.id)}) is deleted, or it is not saved on this board.</p>`;
157
+ if (!t.M.board.id) return '<p class="vz-msg">This workspace has no board to save on, so nothing can be saved here.</p>';
115
158
  return noun === 'chart' ? chartHtml(t) : dashHtml(t);
116
159
  }
160
+ function askHtml(t) {
161
+ const A = t.ask; if (!A) return '';
162
+ return `<div class="vz-ask2" role="group" aria-label="${esc(A.yes)}"><span>${esc(A.text)}</span><div><button type="button" class="vz-issue vz-hv vz-h36" data-ct="askyes" data-k="bad">${esc(A.yes)}</button><button type="button" class="vz-sec2 vz-hv vz-h36" data-ct="askno">${esc(A.no)}</button></div></div>`;
163
+ }
117
164
  function draw(t, el) {
118
- const ask = el.querySelector(':scope > .vcf'); // an open confirm card outlives a redraw, so its answer still lands
119
- el.innerHTML = `<div class="rt">${bodyHtml(t)}${t.msg ? `<p class="rt-msg" role="status">${esc(t.msg)}</p>` : ''}</div>`;
120
- if (ask) el.prepend(ask);
165
+ el.innerHTML = `<div class="vz vz-mx" data-vw="${esc(t.id)}">${askHtml(t)}${bodyHtml(t)}${t.msg ? `<p class="vz-msg" role="status">${esc(t.msg)}</p>` : ''}</div>`;
121
166
  }
122
167
 
123
168
  async function act(t, fn) { t.busy = true; t.msg = ''; redraw(t); const m = await fn(); t.busy = false; if (m != null) t.msg = m; redraw(t); }
@@ -127,6 +172,8 @@ async function press(t, e) {
127
172
  const [a, v] = [b.dataset.ct.split('|')[0], b.dataset.ct.slice(b.dataset.ct.indexOf('|') + 1)];
128
173
  const board = t.M && t.M.board.id, kind = t.block.kind;
129
174
  if (a === 'form') { t.d = Object.assign({}, t.d, { form: v }); t.msg = ''; redraw(t); return; }
175
+ if (a === 'askno') { t.ask = null; redraw(t); return; }
176
+ if (a === 'askyes') { const A = t.ask; t.ask = null; if (A) await A.run(); return; }
130
177
  if (a === 'save') {
131
178
  await act(t, async () => {
132
179
  if (kind === 'chart') {
@@ -147,11 +194,12 @@ async function press(t, e) {
147
194
  }
148
195
  if (a === 'remove') {
149
196
  const noun = kind === 'chart' ? 'chart' : 'dashboard';
150
- if (!(await vwConfirm(paneOf(t), { text: kind === 'chart' ? 'Delete this chart? A dashboard that holds it shows it as removed.' : 'Delete this dashboard? Its charts and records stay.', yes: 'Delete ' + noun, no: 'Keep it' }))) return;
151
- await act(t, async () => {
152
- const r = await post(kind === 'chart' ? '/api/premium-charts/save' : '/api/premium-dashboards/save', { board, id: t.saved.id, remove: true });
153
- if (!r || !r.ok) return 'It was not deleted: ' + why(r, 'the page could not reach PMOS') + '.';
154
- t.removed = true; return null;
155
- });
197
+ t.ask = { text: kind === 'chart' ? 'Delete this chart? A dashboard that holds it shows it as removed.' : 'Delete this dashboard? Its charts and records stay.', yes: 'Delete ' + noun, no: 'Keep it',
198
+ run: () => act(t, async () => {
199
+ const r = await post(kind === 'chart' ? '/api/premium-charts/save' : '/api/premium-dashboards/save', { board, id: t.saved.id, remove: true });
200
+ if (!r || !r.ok) return 'It was not deleted: ' + why(r, 'the page could not reach PMOS') + '.';
201
+ t.removed = true; return null;
202
+ }) };
203
+ redraw(t);
156
204
  }
157
205
  }
@@ -1,15 +1,22 @@
1
- /* pm/premium-chat.js — the Chat page (initiative premium-chat-page). The rail's middle place: the session list, the conversation and the viewer
2
- * as a page of their own. ?about=<key>&label=<name> is the page the PM came from (the rail's Chat carries it); without it, the PM's own chat.
1
+ /* pm/premium-chat.js — the chat of Home (initiative premium-agreed-design, H2 and H3). It was the Chat page (initiative premium-chat-page);
2
+ * /premium-chat.html now opens Home with the same query, and this file opens the chat there.
3
+ * On a desktop the chat is docked beside Home's list, so it always opens: ?about=<key>&label=<name> is the conversation the PM came from, and
4
+ * without it, the PM's own chat (chat:main). On a phone the list is the page and the chat is a popup: it opens only when the address asks for it.
3
5
  * premium-reports-from-chat (slice C): ?open=report:<id> | chart:<id> | dashboard:<id> opens that one in its tab beside the chat, and ?say=<words>
4
- * puts a first message in the box for the PM to send. Insights links here for New, Edit and Shape it, now that the Insight Studio is removed. */
5
- import { wireRail, openChatPage, openBlockTab, growAsk } from './premium-shell.js';
6
+ * puts a first message in the box for the PM to send. Insights links here for New, Edit and Shape it. */
7
+ import { openChatPage, openBlockTab, growAsk, homeDock } from './premium-shell.js';
6
8
 
7
- wireRail('chat');
8
9
  const q = new URLSearchParams(location.search);
9
10
  // a conversation key as the ask route takes it (lib/briefing-premium-agent.js KEY_RE); anything else is the PM's own chat
10
- const about = /^(decision|blocked|waited|src|ev|work|board|init|doc|ins):[A-Za-z0-9][A-Za-z0-9._:-]{0,100}$/.test(q.get('about') || '') ? q.get('about') : null;
11
- openChatPage(about || 'chat:main', about ? (q.get('label') || '').slice(0, 80) : '');
11
+ // Board's and Insights' "Ask about this" / "Ask why" land here as ?ask=<initiative id> | board:<key> | insights | verdict, with the question in q
12
+ const ask = q.get('ask') || '';
13
+ const asked = !ask ? '' : /^board:/.test(ask) ? ask : /^(insights|verdict)$/.test(ask) ? 'ins:' + ask : 'init:' + ask;
14
+ const KEY = /^(decision|blocked|waited|src|ev|work|board|init|doc|ins):[A-Za-z0-9][A-Za-z0-9._:-]{0,100}$/;
15
+ const about = KEY.test(q.get('about') || '') ? q.get('about') : KEY.test(asked) ? asked : null;
12
16
  const open = /^(report|chart|dashboard):([A-Za-z0-9][A-Za-z0-9._:-]{0,119})$/.exec(q.get('open') || '');
13
- if (open) openBlockTab({ kind: open[1], id: open[2] });
14
- const say = (q.get('say') || '').slice(0, 500);
15
- if (say) { const inp = document.querySelector('#askIn'); if (inp) { inp.value = say; growAsk(); inp.focus(); inp.setSelectionRange(say.length, say.length); } }
17
+ const say = (q.get('say') || q.get('q') || '').slice(0, 500);
18
+ if (homeDock() || about || open || say) {
19
+ openChatPage(about || 'chat:main', about ? (q.get('label') || '').slice(0, 80) : '');
20
+ if (open) openBlockTab({ kind: open[1], id: open[2] });
21
+ if (say) { const inp = document.querySelector('#askIn'); if (inp) { inp.value = say; growAsk(); inp.focus(); inp.setSelectionRange(say.length, say.length); } }
22
+ }
@@ -15,7 +15,7 @@
15
15
  export const W = 960, H = 540;
16
16
  export const LAYOUTS = [['title', 'Title'], ['content', 'Title and text'], ['two', 'Two columns'], ['chart', 'Chart and text'], ['big', 'Big number'], ['image', 'Image and text'], ['quote', 'Quote'], ['section', 'Section break']];
17
17
  export const ROLES = [['title', 'Title'], ['heading', 'Heading'], ['body', 'Body'], ['small', 'Small'], ['kicker', 'Kicker'], ['big', 'Big number'], ['quote', 'Quote']];
18
- export const THEMES = [['ember', 'Ember'], ['paper', 'Paper'], ['sky', 'Sky']];
18
+ export const THEMES = [['report', 'Report blue'], ['ember', 'Ember'], ['paper', 'Paper'], ['sky', 'Sky']]; // report: the report panel's slide (ReportPanel.dc.html), the default
19
19
  export const COLORS = [['', 'Theme text'], ['acc', 'Accent'], ['mut', 'Muted']];
20
20
  export const FILLS = [['acc', 'Accent'], ['fg', 'Text colour'], ['soft', 'Soft']];
21
21
  const has = (list, k) => list.some((x) => x[0] === k);
@@ -108,7 +108,7 @@ export function mkLayout(l, c = {}) {
108
108
  const T = (k, role, x, y, w, h, html, align) => ({ t: 'text', k, role, x, y, w, h, html, align: align || 'left' });
109
109
  const ti = c.title != null ? c.title : '', bo = c.body != null ? c.body : '';
110
110
  switch (l) {
111
- case 'title': return [T('kicker', 'kicker', 72, 232, 816, 28, c.kicker || ''), T('title', 'title', 72, 272, 816, 140, ti), T('body', 'body', 72, 424, 816, 70, bo)];
111
+ case 'title': return [T('kicker', 'kicker', 48, 44, 816, 36, c.kicker || ''), T('title', 'title', 48, 96, 640, 150, ti), T('body', 'body', 48, 420, 816, 80, bo)]; // the report's title slide: tag, title, then the lines at the foot
112
112
  case 'two': return [T('title', 'heading', 72, 60, 816, 56, ti), T('body', 'body', 72, 150, 390, 330, bo), T('body2', 'body', 498, 150, 390, 330, c.body2 || '')];
113
113
  case 'chart': return [T('title', 'heading', 72, 60, 816, 56, ti), c.chart ? { ...c.chart, k: 'chart', x: 72, y: 150, w: 520, h: 320 } : { t: 'chart', k: 'chart', x: 72, y: 150, w: 520, h: 320, kind: 'bar', data: [['', 0]] }, T('body', 'body', 624, 160, 264, 310, bo)];
114
114
  case 'big': return [T('big', 'big', 72, 96, 816, 170, c.big || ''), T('body', 'body', 72, 300, 700, 140, bo), ...(ti ? [T('title', 'small', 72, 470, 700, 40, ti)] : [])];
@@ -158,7 +158,7 @@ function fromSection(head, body, l) {
158
158
  /** The file as a deck. A file with no blocks (a report) is read as its title slide and one slide per section, as the report reader does. */
159
159
  export function parseDeck(md, fallbackTitle) {
160
160
  const { front, rest } = splitFront(String(md || '').replace(/\r\n/g, '\n'));
161
- const theme = has(THEMES, frontVal(front, 'deck_theme')) ? frontVal(front, 'deck_theme') : 'ember';
161
+ const theme = has(THEMES, frontVal(front, 'deck_theme')) ? frontVal(front, 'deck_theme') : 'report';
162
162
  const secs = []; let cur = null, pre = [];
163
163
  for (const line of rest.split('\n')) {
164
164
  const h1 = /^# (?!#)(.*)/.exec(line), h2 = /^## (?!#)(.*)/.exec(line);
@@ -1,36 +1,40 @@
1
- /* pm/premium-first.js — the "Your first Briefing" card on the premium Briefing (initiative premium-welcome). It shows only when the page was opened with
2
- * first=<import id>, which the premium Welcome sets after an import. It reads GET /api/onboarding/briefing, lists each item, the state of the tools the PM
3
- * ticked (what Welcome recorded in this browser) and Undo this import (POST /api/onboarding/undo), which goes back to Welcome's found step.
4
- * The card keeps the page's own rows untouched: it is inserted above the columns. Text from the scanned folder is untrusted and goes through esc(). */
1
+ /* pm/premium-first.js — the "Your first Briefing" card on Home (initiative premium-welcome; rebuilt for the Agreed design, initiative
2
+ * premium-agreed-design, Home). The Agreed design does not draw a first-run card, so this is a plain minimal cozy card with a
3
+ * "Waiting for design" marker. It shows only when Home was opened with first=<import id>, which the premium Welcome sets after an import.
4
+ * It reads GET /api/onboarding/briefing, lists each item, the state of the tools the PM ticked (what Welcome recorded in this browser) and
5
+ * Undo this import (POST /api/onboarding/undo), which goes back to Welcome's found step.
6
+ * mountFirst() → the card element (a <section id="wlFirst">), or null when the address has no first=. Home puts it at the top of its list.
7
+ * Text from the scanned folder is untrusted and goes through esc(). */
5
8
  import { pmGet, pmPost } from './http.js';
6
9
  import { firstView, FIRST_KEY } from './premium-welcome-model.js';
7
10
 
8
11
  const esc = (v) => String(v == null ? '' : v).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
9
- const SUN = '<svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg>';
12
+ const WAIT = '<p class="hx-wait"><i aria-hidden="true"></i>Waiting for design</p>';
10
13
 
11
14
  function toolState() {
12
15
  try { return JSON.parse(sessionStorage.getItem(FIRST_KEY) || '{}'); } catch { return {}; }
13
16
  }
14
- export async function mountFirst() {
17
+ export function mountFirst() {
15
18
  const q = new URLSearchParams(location.search), id = q.get('first'), ws = q.get('ws') || '';
16
- const cols = document.querySelector('.cols2');
17
- if (!id || !cols || document.getElementById('wlFirst')) return;
18
- const r = await pmGet(`/api/onboarding/briefing?ws=${encodeURIComponent(ws)}`);
19
- const v = firstView(r, toolState());
19
+ if (!id) return null;
20
20
  const sec = document.createElement('section');
21
- sec.className = 'card wl-first'; sec.id = 'wlFirst'; sec.setAttribute('aria-labelledby', 'hWl');
22
- const items = v.items.map((f, i) => `<li class="wl-row"><span class="wl-ic wl-n">${String(i + 1).padStart(2, '0')}</span><span><b>${esc(f.title)}</b>${f.why ? `<small>${esc(f.why)}</small>` : ''}<span class="path">${f.ini ? esc(f.ini) + ' · ' : ''}${esc(f.ref)}</span></span><span></span></li>`).join('');
23
- const tools = v.tools.map((t) => `<li class="wl-row"><span class="wl-ic">${SUN}</span><span><b>${esc(t.name)}</b><small${t.started ? '' : ' class="wl-bad"'}>${t.started ? `${esc(t.name)} is being read in an agent session. Its items join your Briefing when it finishes.` : esc(t.error || 'It did not start.')}</small></span><span></span></li>`).join('');
24
- sec.innerHTML = `<div class="ch"><span class="ic">${SUN}</span><h2 id="hWl">Your first Briefing</h2><small>From the scan</small></div>
25
- <p class="note wl-first-note">${r && r.ok ? (v.calm ? 'Your portfolio is in. Nothing needs you right now.' : 'Your portfolio is in. These need you first.') : esc((r && r.error) || 'The scan\'s Briefing could not be read.')}</p>
26
- ${items ? `<ol class="wl-list">${items}</ol>` : ''}${tools ? `<p class="wl-sec">Your tools</p><ul class="wl-list">${tools}</ul>` : ''}
27
- <div class="wl-actions"><button class="wl-btn alt" type="button" id="wlUndo">Undo this import</button></div><p class="note wl-first-err" id="wlUndoErr" role="alert" hidden></p>`;
28
- cols.parentNode.insertBefore(sec, cols);
29
- document.addEventListener('click', async (e) => {
21
+ sec.className = 'hm-first hx'; sec.id = 'wlFirst'; sec.setAttribute('aria-labelledby', 'hWl');
22
+ sec.innerHTML = `${WAIT}<h2 id="hWl">Your first Briefing</h2><p class="hx-n">Reading what the scan found.</p>`;
23
+ pmGet(`/api/onboarding/briefing?ws=${encodeURIComponent(ws)}`).then((r) => {
24
+ const v = firstView(r, toolState());
25
+ const items = v.items.map((f) => `<li class="hx-row"><span class="hx-t"><b>${esc(f.title)}</b>${f.why ? `<em>${esc(f.why)}</em>` : ''}<small>${f.ini ? esc(f.ini) + ' · ' : ''}${esc(f.ref)}</small></span></li>`).join('');
26
+ const tools = v.tools.map((t) => `<li class="hx-row"><span class="hx-t"><b>${esc(t.name)}</b><em${t.started ? '' : ' class="bad"'}>${t.started ? `${esc(t.name)} is being read in an agent session. Its items join your list when it finishes.` : esc(t.error || 'It did not start.')}</em></span></li>`).join('');
27
+ const lede = r && r.ok ? (v.calm ? 'Your portfolio is in. Nothing needs you right now.' : 'Your portfolio is in. These need you first.') : esc((r && r.error) || 'The scan\'s Briefing could not be read.');
28
+ sec.innerHTML = `${WAIT}<h2 id="hWl">Your first Briefing</h2><p class="hx-n">${lede}</p>`
29
+ + (items ? `<ol class="hm-first-l">${items}</ol>` : '') + (tools ? `<h4>Your tools</h4><ul class="hm-first-l">${tools}</ul>` : '')
30
+ + '<div class="hx-top"><button class="hx-b" type="button" id="wlUndo">Undo this import</button></div><p class="hx-n" id="wlUndoErr" role="alert" hidden></p>';
31
+ });
32
+ sec.onclick = async (e) => {
30
33
  const b = e.target.closest('#wlUndo'); if (!b || b.disabled) return;
31
34
  b.disabled = true;
32
35
  const u = await pmPost('/api/onboarding/undo', { ws, import_id: id });
33
- if (!u || !u.ok) { b.disabled = false; const e = document.getElementById('wlUndoErr'); e.textContent = (u && u.error) || 'Undo did not work.'; e.hidden = false; return; }
36
+ if (!u || !u.ok) { b.disabled = false; const m = sec.querySelector('#wlUndoErr'); m.textContent = (u && u.error) || 'Undo did not work.'; m.hidden = false; return; }
34
37
  location.assign('/premium-welcome.html?ws=' + encodeURIComponent(ws) + '&step=found');
35
- });
38
+ };
39
+ return sec;
36
40
  }
@@ -0,0 +1,138 @@
1
+ /* pm/premium-initiative-head.js — the header card of the premium initiative page, after the Agreed design's "Inside one initiative" frames
2
+ * (initiative premium-agreed-design, requirement I1). Pure: headModel(M) reads the model GET /api/initiative-premium answers
3
+ * (lib/initiative-premium.js) and returns what the card draws; headHtml(h, o) returns its markup. A node test imports both.
4
+ *
5
+ * The card: who it waits on (Your turn, Agents working, Engineers on it, Stalled), the step "N of 8 · Stage", the ladder of the eight
6
+ * lifecycle steps with Deliver and Evaluate as milestones (◆), the previous step, the current one and the one it reaches next, what
7
+ * finishes the current step (done, you, agent, Jira, a person), the payoff line ("Then: ..."), the time in the stage, and one CTA.
8
+ *
9
+ * THE RULE (as lib/initiative-premium.js): every item comes from a field of a record. The workflow engine's checks give the done and
10
+ * waiting items; the board's Jira tickets give the build item ("N of M tickets Done in Jira"); the engineers build in Jira, so the card
11
+ * never names a PMOS builder agent, a pull request or CI as the build story. A time in the stage shows only when a record holds one;
12
+ * otherwise the line gives the planned finish, or says the time is not recorded. */
13
+
14
+ /** The lifecycle (PM, 2026-10-22). Deliver and Evaluate are milestones. */
15
+ export const STEPS = [
16
+ { key: 'triage', label: 'Triage', out: 'BRD' },
17
+ { key: 'discover', label: 'Discover', out: 'PRD' },
18
+ { key: 'plan', label: 'Plan', out: 'scope, timeline and WBS' },
19
+ { key: 'prioritize', label: 'Prioritize', out: 'a rank on the roadmap' },
20
+ { key: 'build', label: 'Build', out: 'features delivered in Jira' },
21
+ { key: 'deliver', label: 'Deliver', out: 'the release shipped', ms: true },
22
+ { key: 'monitor', label: 'Monitor', out: 'the outcome report' },
23
+ { key: 'evaluate', label: 'Evaluate', out: 'keep, iterate or stop', ms: true },
24
+ ];
25
+ /** The old keys map onto the eight: ideate counts for Discover, strategize for Prioritize (another builder migrates the model). */
26
+ const ALIAS = { ideate: 'discover', strategize: 'prioritize', strategise: 'prioritize', prioritise: 'prioritize', intake: 'triage', delivery: 'deliver', evaluation: 'evaluate' };
27
+ /** What reaching the next step gives, said once per step. */
28
+ const PAYOFF = {
29
+ triage: 'The BRD is agreed, and Discover writes the PRD.',
30
+ discover: 'The PRD is agreed, and Plan sets the scope, the timeline and the WBS.',
31
+ plan: 'Your Commit pushes the tickets to Jira, and the work is ranked on the roadmap.',
32
+ prioritize: 'Ranked on the roadmap, the engineers pick the tickets up in Jira.',
33
+ build: 'The features are delivered in Jira, and the release ships at Deliver.',
34
+ deliver: 'The release ships with your sign-off, and Monitor reads the outcome.',
35
+ monitor: 'The outcome report is written, and you decide at Evaluate.',
36
+ evaluate: 'You decide to keep it, iterate on it or stop it.',
37
+ };
38
+ const YOU_STEPS = /^(contract|review|accept|commit|signoff|sign-off)$/;
39
+ const STEP_SAY = { spec: 'PRD and rubric written', contract: 'Your go on the done criteria', review: 'Review of the findings', accept: 'Your sign-off', route: 'Lane chosen', commit: 'Your Commit' };
40
+ const CTA_SAY = { contract: 'Review the done criteria', review: 'Review the findings', accept: 'Give your sign-off', spec: 'Ask about the PRD', commit: 'Review the Commit' };
41
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
42
+ const cap1 = (s) => (s ? String(s).charAt(0).toUpperCase() + String(s).slice(1) : '');
43
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
44
+
45
+ /** A stage name of any board ("Build", "Ideate", "strategize") → one of the eight keys, or null. */
46
+ export function stageKey(name) {
47
+ const k = String(name || '').trim().toLowerCase().replace(/^◆\s*/, '');
48
+ if (STEPS.some((s) => s.key === k)) return k;
49
+ return ALIAS[k] || null;
50
+ }
51
+ const dayOf = (iso) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso || '')); return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null; };
52
+ const plural = (n, one, many) => n + ' ' + (n === 1 ? one : many);
53
+
54
+ /** The card's model. M: the page model; now: ms. */
55
+ export function headModel(M, now = Date.now()) {
56
+ const m = M || {}, head = m.head || {}, acts = m.acts || {}, ov = m.overview || {};
57
+ const key = stageKey(head.stage || acts.stage), at = key ? STEPS.findIndex((s) => s.key === key) : -1;
58
+ const cur = at >= 0 ? STEPS[at] : null, next = at >= 0 ? STEPS[at + 1] || null : null, prev = at > 0 ? STEPS[at - 1] : null;
59
+ const items = [];
60
+ // the workflow engine's checks: done and waiting; Build and Quality are the engineers' (Jira below), so they are not listed as PMOS work
61
+ for (const c of m.checks || []) {
62
+ if (c.k === 'build' || c.k === 'quality') continue;
63
+ const say = STEP_SAY[c.k] || cap1(c.label);
64
+ if (c.state === 'done') items.push({ kind: 'done', label: say });
65
+ else if (c.state === 'blocked') items.push({ kind: 'risk', label: say + ' is blocked', note: c.owed || '' });
66
+ else if (c.state === 'pending' || c.state === 'current') items.push({ kind: YOU_STEPS.test(c.k) ? 'you' : 'agent', label: say, note: c.owed || '' });
67
+ }
68
+ // the build story is Jira's: the board's tickets for this initiative
69
+ const jira = ((m.tasks && m.tasks.rows) || []).filter((t) => /^Jira/.test(t.src || ''));
70
+ if (jira.length) {
71
+ const d = jira.filter((t) => t.state === 'Done').length;
72
+ items.push({ kind: d === jira.length ? 'done' : 'jira', label: d + ' of ' + plural(jira.length, 'ticket', 'tickets') + ' Done in Jira' });
73
+ }
74
+ // the waiting record says who; a step that waits on the PM and is not in the list yet is added
75
+ const youWait = ov.who === 'Waits on you';
76
+ const step = String(ov.h || '').replace(/^Next: /, '');
77
+ if (youWait && step && !items.some((x) => x.kind === 'you')) items.push({ kind: 'you', label: STEP_SAY[step] || cap1(step) });
78
+ const done = items.filter((x) => x.kind === 'done'), rest = items.filter((x) => x.kind !== 'done');
79
+ const life = acts.life || null;
80
+ const turn = rest.some((x) => x.kind === 'you') ? 'you' : life === 'hold' || life === 'cancelled' || rest.some((x) => x.kind === 'risk') ? 'stalled'
81
+ : rest.some((x) => x.kind === 'jira') || key === 'build' || key === 'deliver' ? 'jira' : 'agents';
82
+ const TURN = { you: 'Your turn', agents: 'Agents working', jira: 'Engineers on it', stalled: life === 'hold' ? 'On hold' : life === 'cancelled' ? 'Cancelled' : 'Stalled' };
83
+ // time in the stage: a record that holds it (stageSince, usualDays) first, then the planned finish, then say it is not recorded
84
+ let time = '', over = false;
85
+ const since = dayOf(m.stageSince || head.stageSince), usual = Number.isFinite(m.usualDays) ? m.usualDays : Number.isFinite(head.usualDays) ? head.usualDays : null;
86
+ const end = dayOf(m.end || head.end || (m.dock && m.dock.end));
87
+ const finish = (head.meta || []).find((x) => /^planned finish /.test(x));
88
+ if (since && cur) {
89
+ const n = Math.max(0, Math.round((now - since) / 864e5));
90
+ time = 'In ' + cur.label + ' for ' + plural(n, 'day', 'days') + (usual != null ? ' · usually ' + usual : ''); over = usual != null && n > usual;
91
+ } else if (finish && cur) {
92
+ time = 'In ' + cur.label + ' · ' + finish; over = !!end && end < new Date(new Date(now).getFullYear(), new Date(now).getMonth(), new Date(now).getDate()) && life !== 'done';
93
+ } else if (cur) time = 'In ' + cur.label + ' · time in this stage is not recorded';
94
+ // one CTA: your step when it waits on you, else a question for the read-only agent
95
+ const cta = turn === 'you' ? (CTA_SAY[step] || ('Open ' + (step || 'the next step'))) : turn === 'stalled' ? 'Ask what is stuck' : turn === 'jira' ? 'Ask about the tickets' : 'Ask what is next';
96
+ const ask = turn === 'you' ? 'What do I need to do for the ' + (step || 'next') + ' step of this initiative? Read the evidence in this repository, say what you could not find, and change nothing.'
97
+ : turn === 'stalled' ? 'What is stuck in this initiative, and what would move it? Read this repository, say what you could not find, and change nothing.'
98
+ : turn === 'jira' ? 'Where do this initiative\'s Jira tickets stand, from the last Jira read? Name the assignee of each where the read holds one, and change nothing.'
99
+ : 'What happens next in this initiative, and who does it? Read this repository and change nothing.';
100
+ const anchor = m.anchor ? ' Moves ' + m.anchor + '.' : '';
101
+ return {
102
+ key, at, total: STEPS.length, turn, turnLabel: TURN[turn],
103
+ stage: cur ? (at + 1) + ' of ' + STEPS.length + ' · ' + cur.label : head.stage ? head.stage + ' · not on the lifecycle' : 'No stage on record',
104
+ prev: prev ? prev.label : '', cur: cur ? cur.label : head.stage || '', toReach: next ? next.label : cur ? 'Done' : '',
105
+ ladderAria: cur ? 'Stage ' + (at + 1) + ' of ' + STEPS.length + ': ' + cur.label + '.' + (next ? ' Next stage: ' + next.label + '.' : '') : 'No stage on the lifecycle.',
106
+ steps: STEPS.map((s, i) => ({ label: s.label, ms: !!s.ms, cls: at < 0 ? '' : i < at ? 'done' : i === at ? 'now' : '' })),
107
+ checkTitle: next ? 'To reach ' + next.label : cur ? 'To finish ' + cur.label : 'What is next',
108
+ done, rest, doneOf: done.length + ' of ' + items.length + ' done',
109
+ foldSum: done.length + ' of ' + items.length + ' done · ' + ([rest.filter((x) => x.kind === 'you').length ? rest.filter((x) => x.kind === 'you').length + ' for you' : '', rest.filter((x) => x.kind === 'risk').length ? rest.filter((x) => x.kind === 'risk').length + ' blocked' : '', rest.filter((x) => x.kind === 'jira').length ? 'in Jira' : ''].filter(Boolean).join(', ') || (turn === 'agents' ? 'agents on it' : 'nothing waiting')),
110
+ payoff: cur ? PAYOFF[cur.key] + anchor : '', time, over, cta, ask, primary: turn !== 'agents',
111
+ };
112
+ }
113
+
114
+ const CHEV = '<svg aria-hidden="true" viewBox="0 0 24 24"><path d="M9 6l6 6-6 6"/></svg>';
115
+ const DOWN = '<svg aria-hidden="true" viewBox="0 0 24 24"><path d="M7 10l5 5 5-5"/></svg>';
116
+ const CLOCK = '<svg aria-hidden="true" viewBox="0 0 24 24"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>';
117
+ const TAG = { you: 'You', agent: 'Working', jira: 'Jira', risk: 'Blocked', wait: 'Next' };
118
+ function itemHtml(x) {
119
+ const mark = x.kind === 'done' ? '<span class="czi-mk done" aria-hidden="true"><svg class="cz-ck" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l4.5 4.5L19 7"/></svg></span>' : x.kind === 'risk' ? '<span class="czi-mk risk" aria-hidden="true">!</span>'
120
+ : x.kind === 'jira' ? '<span class="czi-mk jira" aria-hidden="true">J</span>' : `<span class="czi-mk ${x.kind}" aria-hidden="true"></span>`;
121
+ return `<div class="czi-it ${x.kind}"${x.note ? ` title="${esc(x.note)}"` : ''}>${mark}<span class="czi-itl">${esc(x.label)}</span>${x.kind === 'done' ? '' : `<span class="czi-tag ${x.kind}">${TAG[x.kind] || ''}</span>`}</div>`;
122
+ }
123
+
124
+ /** The card's box under the top row. o: { folded, doneOpen, title } */
125
+ export function headHtml(h, o = {}) {
126
+ const dot = { you: 'you m-info', agents: 'ok', jira: 'ok', stalled: 'late m-warn' }[h.turn] || 'q';
127
+ const ladder = `<div class="czi-lad" aria-label="${esc(h.ladderAria)}" role="img">${h.prev ? `<span class="czi-prev"><svg class="cz-ck" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l4.5 4.5L19 7"/></svg> ${esc(h.prev)}</span>${CHEV}` : ''}<b>${esc(h.cur)}</b>${h.toReach ? CHEV + `<span class="czi-next">${esc(h.toReach)}</span>` : ''}</div>`
128
+ + `<div class="cz-ladder czi-bars" aria-hidden="true">${h.steps.map((s) => `<i class="${[s.cls, s.ms ? 'ms' : ''].filter(Boolean).join(' ')}" title="${esc(s.label)}"></i>`).join('')}</div>`;
129
+ const folded = `<button type="button" class="czi-fold" data-czfold aria-expanded="false"><b>${esc(h.checkTitle)}</b><span>${esc(h.foldSum)}</span>${DOWN}</button>`;
130
+ const doneRow = h.done.length ? `<button type="button" class="czi-it czi-donerow" data-czdone aria-expanded="${!!o.doneOpen}"><span class="czi-mk done" aria-hidden="true"><svg class="cz-ck" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 12l4.5 4.5L19 7"/></svg></span><span class="czi-itl">${esc(h.done.length + ' done' + (o.doneOpen ? '' : ': ' + h.done.map((x) => x.label).join(' · ')))}</span>${DOWN}</button>` : '';
131
+ const list = `<div class="czi-items"><div class="czi-ckh"><button type="button" class="czi-ckt" data-czfold aria-expanded="true"><b>${esc(h.checkTitle)}</b>${DOWN}</button><span>${esc(h.doneOf)}</span></div>${doneRow}${(o.doneOpen ? h.done : []).map(itemHtml).join('')}${h.rest.map(itemHtml).join('') || '<p class="czi-none">Nothing is waiting on a person or an agent.</p>'}</div>`
132
+ + (h.payoff ? `<p class="czi-pay"><b>Then:</b> ${esc(h.payoff)}</p>` : '')
133
+ + (h.time ? `<p class="czi-time${h.over ? ' over' : ''}">${CLOCK}${esc(h.time)}</p>` : '');
134
+ const t = o.title || 'this initiative';
135
+ return `<div class="czi-box ${esc(h.turn)}"><div class="czi-row"><span class="czi-turn ${esc(h.turn)}"><i class="cz-dot ${dot}" aria-hidden="true"></i>${esc(h.turnLabel)}</span><span class="czi-sp"></span><span class="czi-stage">${esc(h.stage)}</span></div>`
136
+ + ladder + (o.folded ? folded : list)
137
+ + `<div class="czi-acts"><button type="button" class="czi-cta${h.primary ? '' : ' alt'}" data-czcta>${esc(h.cta)}</button><button type="button" class="czi-ov" data-czov aria-label="Overview of ${esc(t)} with Claude" title="Overview of ${esc(t)} with Claude"><span aria-hidden="true">C</span></button></div></div>`;
138
+ }