create-pmos 0.433.0 → 0.435.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 (89) hide show
  1. package/package.json +25 -25
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-insights-test.js +63 -58
  7. package/workspace/changelog.json +24 -0
  8. package/workspace/fixtures/ready-reports.js +145 -0
  9. package/workspace/guide/index.md +2 -0
  10. package/workspace/guide/metric-drafts.md +21 -1
  11. package/workspace/guide/ready-made-dashboards.md +62 -0
  12. package/workspace/guide/your-impact.md +58 -0
  13. package/workspace/impact-screens-test.js +149 -0
  14. package/workspace/intel-report-ui-test.js +1 -1
  15. package/workspace/intelligence-gaps-ui-test.js +13 -9
  16. package/workspace/lib/board-premium.js +1 -1
  17. package/workspace/lib/engine/outbox.js +1 -1
  18. package/workspace/lib/engine/records/index.js +11 -3
  19. package/workspace/lib/goal-status.js +199 -0
  20. package/workspace/lib/goal-watch.js +71 -0
  21. package/workspace/lib/headless.js +24 -2
  22. package/workspace/lib/impact-cli.js +72 -0
  23. package/workspace/lib/impact-runs.js +114 -0
  24. package/workspace/lib/impact.js +195 -0
  25. package/workspace/lib/insights-premium.js +43 -4
  26. package/workspace/lib/intel-report.js +36 -5
  27. package/workspace/lib/metric-draft-runs.js +33 -10
  28. package/workspace/lib/metric-drafts.js +118 -15
  29. package/workspace/lib/metric-read-runs.js +132 -0
  30. package/workspace/lib/metric-reads.js +129 -0
  31. package/workspace/lib/metrics-cli.js +100 -5
  32. package/workspace/lib/pmos-verbs.js +4 -1
  33. package/workspace/lib/ready-reports.js +616 -0
  34. package/workspace/lib/report-dashboards.js +5 -0
  35. package/workspace/lib/report-setups.js +16 -7
  36. package/workspace/lib/route-modules.js +4 -0
  37. package/workspace/lib/routes-board-premium.js +5 -0
  38. package/workspace/lib/routes-boards.js +1 -1
  39. package/workspace/lib/routes-goal-status.js +111 -0
  40. package/workspace/lib/routes-impact-views.js +58 -0
  41. package/workspace/lib/routes-impact.js +91 -0
  42. package/workspace/lib/routes-insights-premium.js +20 -0
  43. package/workspace/lib/routes-metric-drafts.js +55 -4
  44. package/workspace/lib/routes-ready-reports.js +455 -0
  45. package/workspace/lib/routes-records.js +2 -0
  46. package/workspace/lib/routes-report-setups.js +4 -3
  47. package/workspace/lib/settings-store.js +3 -0
  48. package/workspace/okr-goals-ui-test.js +175 -0
  49. package/workspace/package-lock.json +2 -2
  50. package/workspace/package.json +1 -1
  51. package/workspace/program-charter-test.js +11 -7
  52. package/workspace/program-panel-test.js +1 -1
  53. package/workspace/public/pm/bd-ini-panel.js +33 -8
  54. package/workspace/public/pm/bd-prog-panel.js +58 -10
  55. package/workspace/public/pm/cozy-adler.css +5 -0
  56. package/workspace/public/pm/cozy-adler.js +17 -9
  57. package/workspace/public/pm/cozy-insights.css +84 -0
  58. package/workspace/public/pm/cozy-settings.js +11 -1
  59. package/workspace/public/pm/cozy-viewer.js +2 -2
  60. package/workspace/public/pm/cozy-vw-rp.css +13 -0
  61. package/workspace/public/pm/dash-view.css +111 -0
  62. package/workspace/public/pm/dash-view.js +261 -0
  63. package/workspace/public/pm/home-app.js +87 -8
  64. package/workspace/public/pm/home-data.js +3 -2
  65. package/workspace/public/pm/home-impact.css +16 -0
  66. package/workspace/public/pm/home-impact.js +72 -0
  67. package/workspace/public/pm/home-ini.js +19 -1
  68. package/workspace/public/pm/home-today.js +4 -2
  69. package/workspace/public/pm/impact.css +37 -0
  70. package/workspace/public/pm/impact.js +201 -0
  71. package/workspace/public/pm/okr-list.js +249 -0
  72. package/workspace/public/pm/premium-insights.js +232 -240
  73. package/workspace/public/pm/premium-report-read.js +36 -5
  74. package/workspace/public/pm/premium-vw-mtg.js +4 -1
  75. package/workspace/public/pm/ready-lib.css +29 -0
  76. package/workspace/public/pm/ready-lib.js +62 -0
  77. package/workspace/public/premium-intelligence.html +3 -2
  78. package/workspace/public/premium.html +1 -0
  79. package/workspace/ready-dash-ui-test.js +227 -0
  80. package/workspace/server.js +58 -2
  81. package/workspace/skills/impact-detect.skill +46 -0
  82. package/workspace/skills/metric-read.skill +32 -0
  83. package/workspace/test-lists/batch17-ready-reports.json +9 -0
  84. package/workspace/test-lists/goal-watch.json +9 -0
  85. package/workspace/test-lists/impact-screens.json +5 -0
  86. package/workspace/test-lists/impact-ui.json +9 -0
  87. package/workspace/test-lists/impact.json +9 -0
  88. package/workspace/test-lists/okr-goals-ui.json +5 -0
  89. package/workspace/test-lists/ready-reports-ui.json +6 -0
@@ -0,0 +1,201 @@
1
+ /* pm/impact.js — Your impact, the screens (feedback batch 16 item 7, Phases 2 to 4; canvas In development "Your impact": GmA1Home, GmA3Garden,
2
+ * GmA4Moments, GmA2Board, GmP4Chapter; brief next16/briefs/7-your-impact-build.md). The ledger, the weekly check in chat and the Settings switch
3
+ * are the backend's (lib/impact.js, pm/impact-check.js); this file only reads GET /api/impact/week and /weeks (contract 7-impact-api.md) and
4
+ * GET /api/impact-views/chapter (lib/routes-impact-views.js), and marks items read (POST /api/impact/seen).
5
+ *
6
+ * readWeek() → the week's body, kept for the page (cached()); { ok, on, live, grow, celebrate, quiet, items } or { ok: false }
7
+ * shows(W) true when a Phase 2 surface may draw: the switch is on and the 9-of-10 gate passed (live)
8
+ * faceHtml(W, o) Home's greeting face as its own press: Adler with the week's leaves on his sprout (grow), "Your impact this week"
9
+ * openWeek(o) the Viewer "Your impact this week": one row per ✓ item with an open icon to its source
10
+ * openLog(o) the Viewer "Your impact": the weeks in plain words, newest first; a quiet week says so and nothing else; past weeks fold
11
+ * celebrate(W, o) once, on a real event: the newest unread ✓ item; a thanks says itself in the toast (the notification moment)
12
+ * meetingLine() the line under a meeting's decisions · intelItem(W) the ✦ line on Intelligence (a key result moved)
13
+ * madeOf(r, today) the Board's "who made it happen" for a milestone delivered in the last 30 days: Jira assignees, unranked
14
+ * madeHtml(x, W) its section · chapterHtml(c, title, o) the Friday card · firstHtml() the empty log's first-run card
15
+ *
16
+ * The rules (Wawan, binding): only you see it and nothing leaves PMOS (no send press anywhere, and every write is the seen mark, local);
17
+ * no numbers (nothing here prints a count, a score or a streak: an item's own sentence and its source label are the only words that may
18
+ * hold a digit, as a ticket key or a date); the leaf is only on Adler's sprout (everything else is plain PM words); every item has a
19
+ * source you can open, so an item whose source has no safe address is not drawn. Pure string builders above the Viewer part. */
20
+ import { pmGet, pmPost } from './http.js';
21
+ import { open as vwOpen, current as vwCurrent } from './cozy-viewer.js';
22
+ import { adler, prefs as adPrefs } from './cozy-adler.js';
23
+
24
+ const CSS = new URL('./impact.css', import.meta.url).href;
25
+ function addCss() {
26
+ if (typeof document === 'undefined' || !document.head || document.querySelector(`link[href="${CSS}"]`)) return;
27
+ const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = CSS; document.head.append(l);
28
+ }
29
+ export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
30
+ const svg = (d, w = 18) => `<svg aria-hidden="true" width="${w}" height="${w}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="${d}"/></svg>`;
31
+ const I = {
32
+ open: 'M14 4h6v6M20 4l-9 9M18 14v5a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1h5', lock: 'M7 11V8a5 5 0 0 1 10 0v3M5 11h14v9H5z',
33
+ quote: 'M7 7h4v4c0 3-2 5-4 5M14 7h4v4c0 3-2 5-4 5', unlock: 'M7 11V8a5 5 0 0 1 9.6-2M5 11h14v9H5z', doc: 'M7 3h7l5 5v13H7zM14 3v5h5',
34
+ kr: 'M4 20V10M10 20V4M16 20v-8M22 20H2', ship: 'M12 3l8 9-8 9-8-9z', list: 'M8 6h12M8 12h12M8 18h12M4 6h.01M4 12h.01M4 18h.01',
35
+ person: 'M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8M4 21a8 8 0 0 1 16 0',
36
+ };
37
+ const KIND = { thanks: ['quote', 'b'], unblock: ['unlock', ''], used: ['doc', ''], kr: ['kr', 'g'] };
38
+ const LOCK = `<p class="im-lock">${svg(I.lock, 14)}<span>Only you see this. Nothing leaves PMOS.</span></p>`;
39
+ const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
40
+ const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
41
+ 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; };
42
+ const md = (d) => MON[d.getMonth()] + ' ' + d.getDate();
43
+ const wd = (iso) => { const d = new Date(iso); return isNaN(d) ? '' : WD[d.getDay()]; };
44
+
45
+ /** A source's address PMOS will open: https anywhere, or a page of PMOS itself ("/…", never "//…"). '' otherwise, and the item is not drawn. */
46
+ export const safeUrl = (u) => { const s = String(u || '').trim(); return /^https:\/\/[^\s"'<>]+$/i.test(s) || /^\/(?!\/)[^\s"'<>]*$/.test(s) ? s : ''; };
47
+ const linkAttrs = (u) => (/^https:/i.test(u) ? ' target="_blank" rel="noopener noreferrer"' : '');
48
+ /** The items worth drawing: ✓ (real), with a source that opens. */
49
+ export const itemsOf = (W) => ((W && Array.isArray(W.items)) ? W.items : []).filter((it) => it && it.real !== false && it.text && it.source && safeUrl(it.source.url));
50
+ export const shows = (W) => !!(W && W.ok !== false && W.on && W.live);
51
+
52
+ /* ── reads ── */
53
+ let W0 = null, R0 = null;
54
+ export const cached = () => W0;
55
+ export async function readWeek(get = pmGet) {
56
+ const r = await get('/api/impact/week');
57
+ W0 = r && r.ok ? r : { ok: false, on: false, live: false, error: (r && r.error) || 'not read' };
58
+ return W0;
59
+ }
60
+ /* the Settings switch (7-A fires 'pmos:impact' { on }): off hides every surface at once, then the next read says what is true */
61
+ if (typeof window !== 'undefined') window.addEventListener('pmos:impact', (e) => { if (e && e.detail && e.detail.on === false) W0 = { ok: true, on: false }; readWeek().catch(() => {}); });
62
+ export async function readWeeks(get = pmGet) { const r = await get('/api/impact/weeks'); R0 = r && r.ok ? r : { ok: false, error: (r && r.error) || 'not read' }; return R0; }
63
+ /** Marks items read (the only write here; local, never sent anywhere). */
64
+ export async function seen(ids, post = pmPost) { const L = (ids || []).filter(Boolean); if (!L.length) return { ok: true }; return post('/api/impact/seen', { ids: L }); }
65
+
66
+ /* ── one item, the same row everywhere (GmA1Home, GmA3Garden) ── */
67
+ export function rowHtml(it) {
68
+ const u = safeUrl(it.source.url), [ic, tone] = KIND[it.kind] || KIND.used, when = wd(it.at);
69
+ const sub = [it.source.label, when].filter(Boolean).join(' · ');
70
+ return `<div class="im-row" data-im-id="${esc(it.id)}"><span class="im-tile${tone ? ' ' + tone : ''}" aria-hidden="true">${svg(I[ic])}</span>`
71
+ + `<span class="im-tx"><span class="im-t">${esc(it.text)}</span>${sub ? `<span class="im-s">${esc(sub)}</span>` : ''}</span>`
72
+ + `<a class="im-ib" href="${esc(u)}"${linkAttrs(u)} data-im-open aria-label="Open the source: ${esc(it.source.label || it.text)}" title="Open the source">${svg(I.open, 20)}</a></div>`;
73
+ }
74
+
75
+ /** The first-run card (GmA4Moments, FIRST RUN): the log starts empty and says so once. */
76
+ export const firstHtml = () => `<div class="im-first">${adler('resting', 44, { label: false })}<span class="im-tx"><b class="im-t">Your impact log starts empty.</b><span class="im-s">It fills when your work helps someone. Only you see it.</span></span></div>`;
77
+
78
+ /** "Your impact this week" (GmA1Home's Viewer). No count: the headline says what happened, the rows say who. */
79
+ export function weekHtml(W) {
80
+ const L = itemsOf(W);
81
+ if (!L.length) return (W && W.first ? firstHtml() : `<div class="im-hd"><b>A quiet week.</b><span>Nothing is lost. The sprout rests until your work helps someone.</span></div>`) + LOCK;
82
+ return `<div class="im-hd"><b>People got further because of your work.</b><span>Thank you for that. Each one is a leaf on Adler’s sprout.</span></div>`
83
+ + `<div class="im-card">${L.map(rowHtml).join('')}</div>` + LOCK;
84
+ }
85
+
86
+ /** The log (GmA3Garden): this week open, past weeks folded, a quiet week one plain line. → markup */
87
+ export function logHtml(R) {
88
+ const weeks = ((R && R.weeks) || []).map((w) => ({ ...w, items: itemsOf(w) }));
89
+ if (!weeks.some((w) => w.items.length)) return firstHtml() + LOCK;
90
+ const one = (w, i) => {
91
+ const label = esc(w.label || 'Week of ' + w.week);
92
+ if (!w.items.length) return `<div class="im-wk quiet"><span class="im-wl">${label}</span><span class="im-s">A quiet week</span></div>`;
93
+ const lead = esc(w.items[0].text);
94
+ if (i === 0) return `<section class="im-wk" aria-label="${label}"><span class="im-wl">${label}</span><div class="im-card">${w.items.map(rowHtml).join('')}</div></section>`;
95
+ return `<details class="im-wk"><summary><span class="im-wl">${label}</span><span class="im-s">${lead}</span>${svg('M7 10l5 5 5-5', 16)}</summary><div class="im-card">${w.items.map(rowHtml).join('')}</div></details>`;
96
+ };
97
+ return `<div class="im-log">${adler('handled', 'l', { label: 'Adler, his sprout grows from your work', grow: R.grow || (weeks[0].items.length ? 'leaf' : 'rest') })}</div>` + weeks.map(one).join('') + LOCK;
98
+ }
99
+
100
+ /** Home's greeting face (GmA1Home): its own press beside "Good morning". Adler's sprout carries the week's leaves. o: { mood, size, joy } */
101
+ export function faceHtml(W, o = {}) {
102
+ if (!shows(W)) return '';
103
+ addCss();
104
+ const joy = !!o.joy, mood = joy ? 'celebrating' : o.mood || 'handled';
105
+ return `<button type="button" class="im-face" data-hm-impact aria-label="Your impact this week" title="Your impact this week">${adler(mood, o.size || 36, { label: false, cls: 'hv-ad', grow: W.grow || 'rest', growNew: joy })}</button>`;
106
+ }
107
+
108
+ /* ── the Viewer pages ── */
109
+ const VIEW = { kind: 'Your impact', icon: I.person };
110
+ function markRead(L) { const ids = L.filter((x) => x.read === false).map((x) => x.id); if (ids.length) seen(ids).then(() => { for (const x of L) if (ids.includes(x.id)) x.read = true; }); }
111
+ export function openWeek(o = {}) {
112
+ addCss();
113
+ const body = vwOpen({ ...VIEW, id: 'impact-week', title: 'Your impact this week', back: !!o.back,
114
+ presses: [{ act: 'log', label: 'Your impact log', icon: I.list }], onPress: (act) => { if (act === 'log') openLog({ back: true }); },
115
+ render: (b) => { b.innerHTML = `<div class="im">${W0 && W0.ok ? weekHtml(W0) : '<p class="im-s">Reading your impact.</p>'}</div>`; } });
116
+ readWeek(o.get).then((W) => {
117
+ const c = vwCurrent(); if (!c || c.id !== 'impact-week' || !body || !body.isConnected) return;
118
+ if (!shows(W)) { body.innerHTML = `<div class="im"><p class="im-s">${W.ok === false ? 'Your impact could not be read: ' + esc(W.error) + '.' : 'Your impact is off. Turn it on in Settings › General.'}</p></div>`; return; }
119
+ body.innerHTML = `<div class="im">${weekHtml(W)}</div>`; markRead(itemsOf(W));
120
+ });
121
+ return body;
122
+ }
123
+ export function openLog(o = {}) {
124
+ addCss();
125
+ const body = vwOpen({ ...VIEW, id: 'impact-log', title: 'Your impact', back: !!o.back, render: (b) => { b.innerHTML = '<div class="im"><p class="im-s">Reading your impact.</p></div>'; } });
126
+ readWeeks(o.get).then((R) => {
127
+ const c = vwCurrent(); if (!c || c.id !== 'impact-log' || !body || !body.isConnected) return;
128
+ if (!shows(R)) { body.innerHTML = `<div class="im"><p class="im-s">${R.ok === false ? 'Your impact could not be read: ' + esc(R.error) + '.' : 'Your impact is off. Turn it on in Settings › General.'}</p></div>`; return; }
129
+ body.innerHTML = `<div class="im">${logHtml({ ...R, grow: W0 && W0.grow })}</div>`;
130
+ markRead(((R.weeks || [])[0] || {}).items ? itemsOf(R.weeks[0]) : []);
131
+ });
132
+ return body;
133
+ }
134
+
135
+ /** The one celebration (GmA4Moments NOTIFICATION): Adler grows his newest leaf once, and an inbound thanks says itself in the toast. Then the
136
+ * item is marked read, so the next open is still. Never with Settings › Adler › Celebrations: Never. → the item celebrated, or null */
137
+ export function celebrate(W, o = {}) {
138
+ if (!shows(W) || !W.celebrate || adPrefs()['adler.celebrate'] !== 'real') return null;
139
+ const it = itemsOf(W).find((x) => x.id === W.celebrate);
140
+ if (!it) return null;
141
+ if (it.kind === 'thanks' && o.toast) o.toast(it.who ? it.who + ' thanked you · ' + it.text : it.text);
142
+ seen([it.id], o.post);
143
+ W.celebrate = null;
144
+ return it;
145
+ }
146
+
147
+ /** The meeting moment (GmA4Moments MEETING NOTES): one quiet line under a meeting's decisions. '' when Your impact is not showing. */
148
+ export const meetingLine = (W = W0) => (shows(W) ? `<p class="im-mt">${svg(I.unlock, 14)}<span>Recorded. If it unblocks someone, it goes in your impact log.</span></p>` : '');
149
+
150
+ /** The Intelligence moment (GmA4Moments INTELLIGENCE): this week's key-result item, as one more ✦ line on the strip. null when none. */
151
+ export function intelItem(W = W0) {
152
+ if (!shows(W)) return null;
153
+ const it = itemsOf(W).find((x) => x.kind === 'kr');
154
+ return it ? { text: it.text, why: 'Your part in it. Only you see this line.', impact: { url: safeUrl(it.source.url), label: it.source.label || 'Open the source' } } : null;
155
+ }
156
+
157
+ /* ── Phase 3: who made it happen (GmA2Board). Read from the Board's own row: no API, no send, no ranking. ── */
158
+ /** The milestone delivered most recently, within 30 days of today, and the people on its tickets. null when there is none or nobody. */
159
+ export function madeOf(r, today) {
160
+ const t = dayOf(today) || new Date(); t.setHours(0, 0, 0, 0);
161
+ const ms = ((r && r.milestones) || []).filter((m) => m && m.done && dayOf(m.date)).map((m) => ({ ...m, d: dayOf(m.date) }))
162
+ .filter((m) => m.d <= t && (t - m.d) / 864e5 <= 30).sort((a, b) => b.d - a.d)[0];
163
+ if (!ms) return null;
164
+ const by = new Map();
165
+ for (const k of (r.track && r.track.tickets) || []) {
166
+ const who = String(k.assignee || '').trim(); if (!who || by.has(who)) continue;
167
+ const url = safeUrl(k.url); if (!url) continue;
168
+ by.set(who, { who, what: k.title || k.key, key: k.key, url });
169
+ }
170
+ const people = [...by.values()].sort((a, b) => a.who.localeCompare(b.who)); // unranked: by name, never by amount of work
171
+ return people.length ? { ms: { name: ms.name, date: md(ms.d) }, people } : null;
172
+ }
173
+ const initial = (s) => esc(String(s || '?').trim().charAt(0).toUpperCase() || '?');
174
+ export function madeHtml(x, W = W0) {
175
+ if (!x || !shows(W)) return '';
176
+ addCss();
177
+ return `<section class="im im-made" aria-label="Who made it happen"><div class="im-mh">${adler('celebrating', 44, { label: false })}<span class="im-tx"><b class="im-t">${esc(x.ms.name)} delivered on ${esc(x.ms.date)}.</b><span class="im-s">Here’s who made it happen.</span></span></div>`
178
+ + `<div class="im-card">${x.people.map((p) => `<div class="im-row"><span class="im-av" aria-hidden="true">${initial(p.who)}</span><span class="im-tx"><b class="im-t">${esc(p.who)}</b><span class="im-s">${esc(p.what)}</span></span>`
179
+ + `<a class="im-ib" href="${esc(p.url)}"${linkAttrs(p.url)} aria-label="Open ${esc(p.key || p.what)}" title="Open ${esc(p.key || 'the ticket')}">${svg(I.open, 20)}</a></div>`).join('')}</div>${LOCK}</section>`;
180
+ }
181
+
182
+ /* ── Phase 4: the Friday chapter (GmP4Chapter) ── */
183
+ /** The chapter to show today: Fridays only, Your impact showing, and a stage of one of Home's initiatives closed this week. c is one of
184
+ * GET /api/impact-views/chapter's chapters; titleOf(id) → the initiative's title from Home's rows, or ''. → { c, title } | null */
185
+ export function chapterToday(chapters, titleOf, now = Date.now(), W = W0) {
186
+ if (!shows(W) || new Date(now).getDay() !== 5) return null;
187
+ for (const c of chapters || []) { const title = titleOf(c.id); if (title) return { c, title }; }
188
+ return null;
189
+ }
190
+ /** o: { href } the initiative's own page in PMOS (its source) */
191
+ export function chapterHtml(x, o = {}) {
192
+ if (!x) return '';
193
+ addCss();
194
+ const { c, title } = x, then = dayOf(c.then && c.then.at), href = safeUrl(o.href);
195
+ const rows = [[then ? md(then).toUpperCase() : 'THEN', c.then && c.then.line ? c.then.line : 'It started on the board'], ['TODAY', c.closed + ' closed. ' + title + ' is in ' + c.now + '.']];
196
+ return `<section class="im im-ch" aria-label="This week’s chapter"><div class="im-hd"><b>Look how far ${esc(title)} came.</b><span>${esc(c.closed)} closed this week. Thank you for the push.</span></div>`
197
+ + `<div class="im-card">${rows.map(([k, v]) => `<div class="im-row"><span class="im-wl">${esc(k)}</span><span class="im-tx"><span class="im-t">${esc(v)}</span></span></div>`).join('')}`
198
+ + (href ? `<div class="im-row"><span class="im-tile" aria-hidden="true">${svg(I.ship)}</span><span class="im-tx"><span class="im-t">${esc(title)}</span><span class="im-s">${esc(c.closed)} → ${esc(c.now)}</span></span><a class="im-ib" href="${esc(href)}" aria-label="Open ${esc(title)}" title="Open ${esc(title)}">${svg(I.open, 20)}</a></div>` : '')
199
+ + `</div></section>`;
200
+ }
201
+ export async function readChapters(get = pmGet) { const r = await get('/api/impact-views/chapter'); return r && r.ok ? r.chapters || [] : []; }
@@ -0,0 +1,249 @@
1
+ /* pm/okr-list.js — "Claude runs the OKRs" (batch 16 item 6, build 6-B; frames GsM1Day1…GsM5Quarter, GsViewer, GsMetrics, GsMetricsTree, GsNotify,
2
+ * GsProduct). PURE: every function takes the Intelligence model's goals and budgets (lib/insights-premium.js, with the fields of lib/goal-status.js)
3
+ * and the metric-drafts view (GET /api/metric-drafts), and returns data or HTML. Nothing here reads, writes or keeps a clock of its own.
4
+ *
5
+ * dotOf(g) 'on' | 'behind' | 'close' | 'broken' | 'none' | 'q' g.reading.dot when the server sent it; else read from today's fields
6
+ * metaOf(g, today) the row's second line: the reading against its target, and its age ("Mon", "12 days old")
7
+ * whoOf(g) { name, initials } | null: the owner the avatar shows
8
+ * draftsOf(view) the open and just-made drafts, each { id, kind, goal, group, text, why, old, act, state, … }
9
+ * lineOf(o) the ✦ line { head, sub, tone, keepAll }: o.okr.line when sent, else said from the goals, budgets and drafts
10
+ * rowHtml(g, o) · draftHtml(r) · budgetMeta(b, today)
11
+ * metricsOf(model) the ⋯ › Metrics list: goals first, then watched metrics (tag "watch", no status)
12
+ * treeOf(model) the same list as a tree: the North Star, its inputs, the guardrails, and what is not placed yet
13
+ * productLine(goals) "3 on their line · checkout sign-in is behind" with one dot per goal (GsProduct)
14
+ *
15
+ * THE RULE (as the other premium models): a number, a dot or an age is made only from a field of a record. A goal with no reading has a hollow dot
16
+ * and no status. Initiative delivery status never sets a dot. */
17
+
18
+ export const DAY = 864e5;
19
+ const WD = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
20
+ export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
21
+ const day = (s) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(s || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
22
+ const fin = (v) => typeof v === 'number' && Number.isFinite(v);
23
+ const r2 = (v) => Math.round(v * 100) / 100;
24
+
25
+ /* the icons of the rows and drafts (the frames' set: 24 × 24, stroke 1.8) */
26
+ export const P = {
27
+ spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z', alert: 'M12 4l9 16H3zM12 10v4M12 17v.5', chk: 'M5 12l5 5 9-10',
28
+ checks: 'M2 12l5 5 9-10M9 17l1 1 11-12', x: 'M6 6l12 12M18 6L6 18', pen: 'M4 20h4L19 9l-4-4L4 16zM14 6l4 4', plug: 'M9 3v5M15 3v5M6 8h12v3a6 6 0 0 1-12 0zM12 17v4',
29
+ ticket: 'M4 7h16v3a2 2 0 0 0 0 4v3H4v-3a2 2 0 0 0 0-4z', msg: 'M4 5h16v11H9l-5 4z', flag: 'M6 21V4M6 4h11l-2 4 2 4H6', book: 'M5 4h11a3 3 0 0 1 3 3v13H8a3 3 0 0 1-3-3zM5 17a3 3 0 0 1 3-3h11',
30
+ user: 'M12 12a4 4 0 1 0 0-8a4 4 0 1 0 0 8M4 21a8 8 0 0 1 16 0', chart: 'M4 20V10M10 20V4M16 20v-8M22 20H2', clock: 'M12 3a9 9 0 1 0 0 18a9 9 0 1 0 0-18M12 7v5l3 2',
31
+ down: 'M6 9l6 6 6-6', list: 'M9 6h11M9 12h11M9 18h11M4.5 6h.01M4.5 12h.01M4.5 18h.01', tree: 'M9 3h6v5H9zM3 16h6v5H3zM15 16h6v5h-6zM12 8v4M6 16v-4h12v4',
32
+ bell: 'M6 16V11a6 6 0 0 1 12 0v5l2 2H4zM10 21h4', quiet: 'M6 16V11a6 6 0 0 1 9.5-4.9M18 11v5l2 2H8M4 4l16 16', undo: 'M9 14L4 9l5-5M4 9h11a5 5 0 0 1 0 10h-3',
33
+ };
34
+ export const SV = (d, s = 18) => `<svg viewBox="0 0 24 24" width="${s}" height="${s}" aria-hidden="true"><path d="${d}"/></svg>`;
35
+
36
+ /* ── the dot ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── */
37
+ const DOTS = ['on', 'behind', 'close', 'broken', 'none', 'q'];
38
+ /** The goal's dot. The server's one status function (lib/goal-status.js, reading.dot) wins. Before it, the dot is read from today's fields: no
39
+ * reading → 'none'; a limit goal past its limit → 'broken'; the line status drift or off, or a pace past its date → 'behind'; on its line or on
40
+ * course → 'on'; a reading with no line to judge it → 'q' (grey, no status). Never from the initiatives that move it. */
41
+ export function dotOf(g) {
42
+ if (!g) return 'none';
43
+ const R = g.reading;
44
+ if (R && DOTS.includes(R.dot)) return R.dot;
45
+ if (typeof g.anchor === 'string' && /^health:/.test(g.anchor)) return budgetDot(g);
46
+ if (!g.readings && !(g.series || []).length && g.now == null) return 'none';
47
+ const tone = g.pace && g.pace.tone;
48
+ if (g.type === 'Stay within') return tone === 'late' ? 'broken' : tone === 'ok' ? 'on' : 'q';
49
+ if (g.state === 'drift' || g.state === 'off' || tone === 'late') return 'behind';
50
+ if (g.state === 'ok' || tone === 'ok') return 'on';
51
+ return 'q';
52
+ }
53
+ /** A health budget's dot before lib/goal-status.js: its share of open initiatives against its cap (D59), the reading the page had. */
54
+ function budgetDot(b) {
55
+ if (b.limit && DOTS.includes(b.limit.dot) && b.limit.dot !== 'none') return b.limit.dot; // the budget's own reading record (lib/goal-status.js); unread, the share judges it
56
+ const R = b.reading;
57
+ if (R && DOTS.includes(R.dot)) return R.dot;
58
+ if (!R || R.share == null) return 'none';
59
+ return R.over ? 'broken' : 'on';
60
+ }
61
+ /** The dot's class on .cz-dot (cozy.css): a broken limit pulses (m-crit), the one time a dot moves. */
62
+ export const DOT_CLS = { on: 'ok', behind: 'risk', close: 'risk', broken: 'red m-crit', none: 'hollow', q: 'q' };
63
+ export const DOT_SAY = { on: 'On its line', behind: 'Behind its line', close: 'Close to its limit', broken: 'Over its limit', none: 'No reading yet', q: 'No line to judge it by' };
64
+ export const dotHtml = (d, cls = '') => `<span class="cz-dot okr-dot ${DOT_CLS[d] || 'hollow'}${cls ? ' ' + cls : ''}" role="img" aria-label="${esc(DOT_SAY[d] || '')}"></span>`;
65
+
66
+ /* ── the row's second line ─────────────────────────────────────────────────────────────────────────────────────────────────────── */
67
+ /** How old the latest reading is: "today", "yesterday", the weekday within the week, else "12 days old". A reading past its cadence is stale. */
68
+ export function ageOf(at, today, ageDays) {
69
+ const t = day(at); if (t === null) return '';
70
+ const n = fin(ageDays) ? ageDays : Math.round((today - t) / DAY);
71
+ if (n <= 0) return 'today';
72
+ if (n === 1) return 'yesterday';
73
+ if (n < 7) return WD[new Date(t).getUTCDay()];
74
+ return n + ' days old';
75
+ }
76
+ const unitOf = (g, v) => { const u = String(g.unit || '').trim(); const s = String(r2(v)); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
77
+ const sgn = (v) => (v > 0 ? '+' : v < 0 ? '−' : '') + String(r2(Math.abs(v)));
78
+ /** The reading against the target, as the frames say it: "+2.1 of +5 points" from a baseline, "41% of 50%" without one. '' with no reading. */
79
+ export function progressOf(g) {
80
+ if (g.now == null) return '';
81
+ const base = fin(g.base) ? g.base : fin(g.start) ? g.start : null, tgt = fin(g.target) ? g.target : null;
82
+ if (g.type === 'Stay within') return g.nowTxt || unitOf(g, g.now);
83
+ if (tgt === null) return g.nowTxt || unitOf(g, g.now);
84
+ if (base !== null && base !== tgt && g.type !== 'Count') {
85
+ const pct = /^%$/.test(String(g.unit || '').trim());
86
+ return sgn(g.now - base) + ' of ' + sgn(tgt - base) + (pct ? ' points' : g.unit && /^[A-Za-z]/.test(g.unit) ? ' ' + g.unit : String(g.unit || ''));
87
+ }
88
+ return (g.nowTxt || unitOf(g, g.now)) + ' of ' + (g.targetTxt || unitOf(g, tgt));
89
+ }
90
+ /** A goal row's second line. The server's reading.txt and reading.line win; else the progress, then what it is behind by or the reading's age.
91
+ * With no reading: what replaced it ("Was …"), how it will be read, or "No reading yet". */
92
+ export function metaOf(g, today) {
93
+ const R = g.reading || {}, d = dotOf(g), last = (g.series || []).length ? g.series[g.series.length - 1].at : R.at || null;
94
+ const was = g.was ? 'Was “' + g.was + '”' : '';
95
+ if (d === 'none') {
96
+ const how = g.recipe && g.recipe.connector ? 'reads from ' + g.recipe.connector + (g.recipe.cadence ? ' ' + g.recipe.cadence : '') : '';
97
+ return [was, how].filter(Boolean).join(' · ') || 'No reading yet';
98
+ }
99
+ const txt = R.txt || progressOf(g);
100
+ const age = ageOf(last, today, R.ageDays), stale = R.stale === true || (R.stale === undefined && last && Math.round((today - day(last)) / DAY) > 8);
101
+ const line = R.line || (d === 'behind' && g.pace && g.pace.sub && g.pace.head !== '—' ? g.pace.sub : '');
102
+ // on its line, the line is noise: the row says how fresh the reading is instead. Off it (or reached), the line is the point. Stale always says so.
103
+ const showLine = !!line && (d !== 'on' || /reached/.test(line)), old = age && stale ? 'read ' + age.replace(/ old$/, ' ago') : '';
104
+ return [txt, showLine ? line : '', old || (showLine ? '' : age)].filter(Boolean).join(' · ');
105
+ }
106
+ /** A health budget's second line: its reading (from the budget's own kr-metrics record once lib/goal-status.js sends it), else its share. */
107
+ export function budgetMeta(b, today) {
108
+ if (b.limit && b.limit.txt) return [b.limit.txt, ageOf(b.limit.at, today, b.limit.ageDays)].filter(Boolean).join(' · ');
109
+ const R = b.reading || {};
110
+ if (R.txt) return [R.txt, ageOf(R.at, today, R.ageDays)].filter(Boolean).join(' · ');
111
+ if (R.share != null) return Math.round(R.share * 100) + '% of open initiatives' + (b.cap != null ? ' · cap ' + Math.round(b.cap * 100) + '%' : '');
112
+ return b.declared === false ? 'Not in the budget registry' : 'No reading yet';
113
+ }
114
+ /** The owner on the avatar: the server's who (from Jira or the PM), else today's owner string. */
115
+ export function whoOf(g) {
116
+ const w = g && g.who;
117
+ if (w && w.name) return { name: w.name, initials: w.initials || initials(w.name), from: w.from || '' };
118
+ if (g && typeof g.owner === 'string' && g.owner.trim()) return { name: g.owner.trim(), initials: initials(g.owner), from: 'pm' };
119
+ return null;
120
+ }
121
+ const initials = (n) => String(n || '').replace(/[@.].*$/, '').split(/[\s_-]+/).filter(Boolean).slice(0, 2).map((w) => w[0].toUpperCase()).join('') || '?';
122
+ export const avHtml = (w) => (w ? `<span class="okr-av" title="Owner: ${esc(w.name)}" aria-label="Owner: ${esc(w.name)}">${esc(w.initials)}</span>` : '<span class="okr-av none" title="No owner yet" aria-label="No owner yet"></span>');
123
+
124
+ /* ── drafts ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── */
125
+ export const KIND_ICON = { outcome: 'spark', connect: 'plug', recipe: 'book', chase: 'msg', ticket: 'ticket', 'next-quarter': 'flag', carry: 'flag', owner: 'user', metric: 'chart' };
126
+ const ACT = { connect: 'Connect', chase: 'Send', ticket: 'Send to Jira' };
127
+ /** The rows of a metric-drafts view as drafts under the list: open ones, and ones made in this visit (kept or dropped, for Undo). Today's metric
128
+ * rows have no kind: they are 'metric' drafts with their Now and Target in the line. */
129
+ export function draftsOf(view) {
130
+ return ((view && view.rows) || []).filter((r) => r && (r.state === 'open' || r.state === 'kept' || r.state === 'dropped')).map((r) => {
131
+ const kind = r.kind && KIND_ICON[r.kind] ? r.kind : 'metric';
132
+ const why = kind === 'metric' ? [r.nowTxt ? 'test read ' + r.nowTxt + ' today' : '', r.targetTxt ? 'target ' + r.targetTxt : '', r.why || ''].filter(Boolean).join(' · ') : r.why || '';
133
+ return { id: r.id, kind, goal: r.goal || null, group: r.group || '', text: r.text || r.name || '', name: r.name || r.text || '', why, old: r.old || '', act: r.act || ACT[kind] || 'Keep', state: r.state, nowTxt: r.nowTxt || '', targetTxt: r.targetTxt || '', source: r.source || '', ticket: r.ticket || null, raw: r };
134
+ });
135
+ }
136
+ /** One draft under the row it repairs: its icon, what it was ("Was …"), what it does, why, and ✕ / ✎ / ✓ as icon buttons. ✓ says its own act
137
+ * (Keep, Send, Connect a source, Send to Jira). A made draft says so, with Undo. */
138
+ export function draftHtml(r, o = {}) {
139
+ const icon = SV(P[KIND_ICON[r.kind] || 'spark'], 18);
140
+ const was = r.old ? `<div class="okr-old">Was “${esc(r.old)}”</div>` : '';
141
+ const acts = r.state === 'open'
142
+ ? `<button type="button" class="cz-ib sm" data-okd="drop" data-row="${esc(r.id)}" aria-label="Not now: ${esc(r.text)}" title="Not now">${SV(P.x)}</button>`
143
+ + (o.noEdit ? '' : `<button type="button" class="cz-ib sm" data-okd="edit" data-row="${esc(r.id)}" aria-label="Edit: ${esc(r.text)}" title="Edit">${SV(P.pen)}</button>`)
144
+ + `<button type="button" class="cz-ib sm solid" data-okd="keep" data-row="${esc(r.id)}" aria-label="${esc(r.act)}: ${esc(r.text)}" title="${esc(r.act)}">${SV(r.kind === 'connect' ? P.plug : P.chk)}</button>`
145
+ : `<span class="cz-pill ${r.state === 'kept' ? 'ok' : 'q'}">${r.state === 'kept' ? (r.kind === 'chase' || r.kind === 'ticket' ? 'Sent' : 'Kept') : 'Not now'}</span><button type="button" class="cz-ib sm" data-okd="undo" data-row="${esc(r.id)}" aria-label="Undo" title="Undo">${SV(P.undo)}</button>`;
146
+ return `<div class="okr-dr${r.state !== 'open' ? ' made' : ''}" data-draft="${esc(r.id)}"><span class="k">${icon}</span><div class="tx">${was}<b>${esc(r.text)}</b>${r.why ? `<span class="note">${esc(r.why)}</span>` : ''}</div><div class="acts">${acts}</div></div>`;
147
+ }
148
+
149
+ /* ── a row ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── */
150
+ /** One goal: the dot, the outcome, the reading with its age, the owner. No sparkline (the chart is in the Viewer). Its drafts sit under it. */
151
+ export function rowHtml(g, o = {}) {
152
+ const d = o.dot || dotOf(g), meta = o.meta != null ? o.meta : metaOf(g, o.today);
153
+ const drafts = (o.drafts || []).map((r) => (o.drawDraft ? o.drawDraft(r) : draftHtml(r, o))).join('');
154
+ const attr = o.budget ? `data-budget="${esc(g.id)}"` : `data-goal="${esc(g.id)}"`;
155
+ return `<div class="okr-row${o.sel ? ' sel' : ''}${d === 'broken' ? ' crit' : ''}" ${attr}${o.selecting ? ` aria-selected="${!!o.sel}"` : ''}><div class="okr-main" role="button" tabindex="0" aria-label="${esc((o.title || g.title) + ', ' + (DOT_SAY[d] || ''))}">${dotHtml(d)}<span class="okr-t"><b>${o.mark ? o.mark(o.title || g.title) : esc(o.title || g.title)}</b><span class="note">${esc(meta)}</span></span>${o.noOwner ? '' : avHtml(whoOf(g))}</div>${drafts}</div>`;
156
+ }
157
+ /** A goal Claude drafted that is not a record yet (a North Star or a key result): a hollow row that is the draft itself. */
158
+ export function draftRowHtml(r) {
159
+ return `<div class="okr-row drafted" data-draft-row="${esc(r.id)}"><div class="okr-main">${dotHtml('none')}<span class="okr-t"><b>${esc(r.text)}</b><span class="note">${esc(r.why || 'Drafted, not kept yet')}</span></span></div>${draftHtml(Object.assign({}, r, { text: r.kind === 'metric' ? 'Keep this as ' + (r.group === 'North Star' ? 'the North Star' : r.group === 'Key results' ? 'a key result' : r.group ? 'one of the ' + r.group.toLowerCase() : 'a goal') : r.text, why: '' }), { noEdit: false })}</div>`;
160
+ }
161
+
162
+ /* ── the ✦ line ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────── */
163
+ const plural = (n, a, b) => n + ' ' + (n === 1 ? a : b);
164
+ /** The ✦ line: the one thing that matters this week (GsM1–M5). The server's okr.line wins. Before it: a broken limit (red, the one time); else
165
+ * the drafts waiting (✓✓ keeps them all); else the goal furthest behind with why; else a stale reading; else all on their line. It never says
166
+ * "no insight": with nothing read it says what Claude does next. o = { okr, goals, budgets, drafts, running, product } */
167
+ export function lineOf(o) {
168
+ const L = o.okr && o.okr.line;
169
+ const G = (o.goals || []).concat(o.budgets || []), open = (o.drafts || []).filter((r) => r.state === 'open'), name = o.product || 'this product';
170
+ // The server's line leads (lib/goal-status.js lineOf: one status everywhere). The drafts the page just loaded are fresher than the model, so
171
+ // they set ✓✓ and the drafted sub; with none left, a sub about drafts is stale and goes.
172
+ if (L && L.head && !(L.tone === 'calm' && open.length)) {
173
+ const out = { head: L.head, sub: L.sub || '', tone: L.tone || 'calm', keepAll: L.keepAll || 0 };
174
+ if (o.drafts) {
175
+ out.keepAll = open.length > 1 ? open.length : 0;
176
+ if (open.length && out.tone !== 'drafts') out.sub = open.length === 1 ? 'I drafted one fix under it.' : 'I drafted ' + open.length + ' fixes. Keep them all at once, or one by one.';
177
+ else if (!open.length && L.keepAll) out.sub = '';
178
+ }
179
+ if (!(o.goals || []).length && !open.length && !o.running) { out.start = true; out.sub = out.sub || 'Or press ✦ and I draft the North Star and key results from your PRDs now, each with how I will read it.'; }
180
+ return out;
181
+ }
182
+ if (o.running) return { head: 'I am drafting the goals for ' + name + '.', sub: o.runningSay || 'I read the PRDs and the sources first, then I propose each goal with how I will read it.', tone: 'drafts', keepAll: 0 };
183
+ const broken = G.filter((g) => dotOf(g) === 'broken');
184
+ if (broken.length) {
185
+ const b = broken[0], fix = open.find((r) => r.goal === b.id);
186
+ return { head: b.title + ' is over its limit.', sub: [b.reading && b.reading.txt ? 'It reads ' + b.reading.txt + '.' : '', fix ? 'I drafted a fix under it.' : ''].filter(Boolean).join(' '), tone: 'crit', keepAll: 0 };
187
+ }
188
+ if (open.length) {
189
+ const was = open.filter((r) => r.kind === 'outcome').length;
190
+ const head = was > 1 ? 'Your ' + plural(was, 'goal was a project', 'goals were projects') + ', so I drafted the outcome each one is for.'
191
+ : open.length === 1 ? 'I drafted one change to your goals.' : 'I drafted ' + open.length + ' changes to your goals.';
192
+ return { head, sub: 'Each one sits under the goal it fixes.' + (open.length > 1 ? ' Keep them one by one, or all at once.' : ''), tone: 'drafts', keepAll: open.length > 1 ? open.length : 0 };
193
+ }
194
+ if (!(o.goals || []).length) return { head: 'No goal is set for ' + name + ' yet.', sub: 'I can draft a North Star and key results from your PRDs, each with how I will read it.', tone: 'calm', keepAll: 0, start: true };
195
+ const behind = G.filter((g) => dotOf(g) === 'behind' || dotOf(g) === 'close');
196
+ if (behind.length) {
197
+ const g = behind[0], why = (g.reading && g.reading.why) || (g.pace && g.pace.head && g.pace.head !== '—' ? g.pace.head + (g.pace.sub ? ', ' + g.pace.sub : '') + '.' : '');
198
+ return { head: g.title + (dotOf(g) === 'close' ? ' is close to its limit.' : ' is behind its line.') + (behind.length > 1 ? ' ' + plural(behind.length - 1, 'other is', 'others are') + ' too.' : ''), sub: why, tone: 'behind', keepAll: 0 };
199
+ }
200
+ const read = G.filter((g) => dotOf(g) !== 'none');
201
+ if (!read.length) return { head: G.length === 1 ? 'Your goal has no reading yet.' : 'None of your ' + G.length + ' goals has a reading yet.', sub: 'I can draft how to read each one, and test-read it before you keep it.', tone: 'calm', keepAll: 0, start: true };
202
+ const unread = G.length - read.length;
203
+ return { head: read.length === 1 && G.length === 1 ? 'Your goal is on its line this week.' : 'All ' + read.length + ' goals I can read are on their line this week.', sub: unread ? plural(unread, 'goal has', 'goals have') + ' no reading yet.' : 'Nothing needs you.', tone: 'calm', keepAll: 0 };
204
+ }
205
+
206
+ /* ── ⋯ › Metrics: one list, and the same list as a tree ─────────────────────────────────────────────────────────────────────────── */
207
+ const ROLE_SAY = { 'north-star': 'North Star', input: 'Input', guardrail: 'Guardrail', kr: 'Key result', budget: 'Health budget', watch: '' };
208
+ /** The Metrics list: the server's model.metrics, else made from the goals and budgets. Goal metrics come first, then the watched ones (no status). */
209
+ export function metricsOf(model, today) {
210
+ if (model && Array.isArray(model.metrics)) return model.metrics.map((m) => Object.assign({ meta: '', dot: m.role === 'watch' ? 'none' : m.dot || 'none' }, m));
211
+ const own = (g) => !g.program && !g.initiative;
212
+ const G = ((model && model.goals) || []).filter(own).map((g) => ({ id: g.id, title: g.title, role: g.role || 'kr', parent: g.parent || null, dot: dotOf(g),
213
+ meta: [ROLE_SAY[g.role || 'kr'], g.recipe && g.recipe.connector ? g.recipe.connector : g.source && g.source !== 'typed' ? g.source : '', ageOf((g.series || []).length ? g.series[g.series.length - 1].at : null, today)].filter(Boolean).join(' · ') }));
214
+ const B = ((model && model.budgets) || []).map((b) => ({ id: b.id, title: b.title, role: 'budget', dot: budgetDot(b), meta: ['Health budget', budgetMeta(b, today)].join(' · '), budget: true }));
215
+ const ORDER = ['north-star', 'input', 'kr', 'guardrail', 'budget', 'watch'];
216
+ return G.concat(B).sort((a, b) => ORDER.indexOf(a.role) - ORDER.indexOf(b.role));
217
+ }
218
+ /** The tree: the North Star, its inputs under it, the guardrails (and budgets) that must not get worse, and the goals not placed in it yet. */
219
+ export function treeOf(L) {
220
+ const ns = L.find((m) => m.role === 'north-star') || null;
221
+ return { ns, inputs: L.filter((m) => m.role === 'input'), guards: L.filter((m) => m.role === 'guardrail' || m.role === 'budget'), loose: L.filter((m) => m.role === 'kr'), watch: L.filter((m) => m.role === 'watch') };
222
+ }
223
+ export function metricsHtml(L, view) {
224
+ const row = (m) => `<button type="button" class="okr-mrow" data-${m.budget || m.role === 'budget' ? 'budget' : 'goal'}="${esc(m.id)}">${dotHtml(m.role === 'watch' ? 'none' : m.dot)}<span class="okr-t"><b>${esc(m.title)}</b><span class="note">${esc(m.meta || '')}</span></span>${m.role === 'watch' ? '<span class="okr-tag">watch</span>' : ''}</button>`;
225
+ if (!L.length) return '<p class="note">No metric is recorded for this product yet. The ✦ line on Intelligence says what I can draft.</p>';
226
+ if (view === 'tree') {
227
+ const T = treeOf(L), node = (m, cls = '') => `<button type="button" class="okr-node${cls}" data-${m.role === 'budget' ? 'budget' : 'goal'}="${esc(m.id)}">${dotHtml(m.dot)}<span class="okr-t"><b>${esc(m.title)}</b><span class="note">${esc(ROLE_SAY[m.role] || m.meta || '')}</span></span></button>`;
228
+ return (T.ns ? `<div class="okr-tree"><div class="okr-tr0">${node(T.ns, ' ns')}</div>${T.inputs.length ? `<div class="okr-trk" aria-hidden="true"></div><div class="okr-tr1${T.inputs.length === 1 ? ' one' : ''}">${T.inputs.map((m) => node(m)).join('')}</div>` : '<p class="note">No input is placed under the North Star yet.</p>'}</div>`
229
+ : '<p class="note">There is no North Star yet, so the tree has no top. The ✦ line on Intelligence drafts one.</p>')
230
+ + (T.guards.length ? `<p class="okr-sh">Must not get worse</p><div class="okr-tr1">${T.guards.map((m) => node(m)).join('')}</div>` : '')
231
+ + (T.loose.length ? `<p class="okr-sh">Not placed in the tree yet</p><div class="okr-tr1 loose">${T.loose.map((m) => node(m)).join('')}</div>` : '')
232
+ + (T.watch.length ? `<p class="okr-sh">Watched, no goal</p><div class="okr-tr1">${T.watch.map((m) => node(m)).join('')}</div>` : '');
233
+ }
234
+ const on = L.filter((m) => m.role !== 'watch'), w = L.filter((m) => m.role === 'watch');
235
+ return (on.length ? `<p class="okr-sh">On a goal</p><div class="okr-card">${on.map(row).join('')}</div>` : '') + (w.length ? `<p class="okr-sh">Watched, no goal</p><div class="okr-card">${w.map(row).join('')}</div>` : '');
236
+ }
237
+
238
+ /* ── the product page's Goals line (GsProduct) ─────────────────────────────────────────────────────────────────────────────────── */
239
+ /** "3 on their line · checkout sign-in is behind", one dot per goal. S = GET /api/goal-status → { on, behind, broken, dots, line }. */
240
+ export function productLine(S) {
241
+ if (!S || !Array.isArray(S.dots)) return null;
242
+ if (!S.dots.length) return { text: S.line || 'No goal yet · Claude can draft them', dots: [] };
243
+ const low = (t) => String(t || '').replace(/^./, (c) => c.toLowerCase());
244
+ const bad = (S.broken || []).map((t) => low(t) + ' is over its limit').concat((S.behind || []).map((t) => low(t) + ' is behind'));
245
+ const none = S.dots.filter((d) => d.dot === 'none').length;
246
+ const text = S.line || [S.on ? S.on + ' on ' + (S.on === 1 ? 'its' : 'their') + ' line' : '', bad[0] || '', bad.length > 1 ? (bad.length - 1) + ' more need' + (bad.length === 2 ? 's' : '') + ' you' : '', none ? none + ' not read yet' : ''].filter(Boolean).join(' · ');
247
+ return { text, dots: S.dots.map((d) => d.dot) };
248
+ }
249
+ export const productLineHtml = (L) => `<span class="okr-pl"><span class="okr-plt">${esc(L.text)}</span><span class="okr-pld" aria-hidden="true">${L.dots.map((d) => dotHtml(d)).join('')}</span></span>`;