create-pmos 0.433.0 → 0.434.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 (63) hide show
  1. package/package.json +13 -13
  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 +12 -0
  8. package/workspace/guide/index.md +1 -0
  9. package/workspace/guide/metric-drafts.md +21 -1
  10. package/workspace/guide/your-impact.md +58 -0
  11. package/workspace/impact-screens-test.js +149 -0
  12. package/workspace/intel-report-ui-test.js +1 -1
  13. package/workspace/intelligence-gaps-ui-test.js +13 -9
  14. package/workspace/lib/engine/outbox.js +1 -1
  15. package/workspace/lib/engine/records/index.js +11 -3
  16. package/workspace/lib/goal-status.js +199 -0
  17. package/workspace/lib/goal-watch.js +71 -0
  18. package/workspace/lib/headless.js +24 -2
  19. package/workspace/lib/impact-cli.js +72 -0
  20. package/workspace/lib/impact-runs.js +114 -0
  21. package/workspace/lib/impact.js +195 -0
  22. package/workspace/lib/insights-premium.js +43 -4
  23. package/workspace/lib/metric-draft-runs.js +33 -10
  24. package/workspace/lib/metric-drafts.js +118 -15
  25. package/workspace/lib/metric-read-runs.js +132 -0
  26. package/workspace/lib/metric-reads.js +129 -0
  27. package/workspace/lib/metrics-cli.js +100 -5
  28. package/workspace/lib/pmos-verbs.js +4 -1
  29. package/workspace/lib/route-modules.js +3 -0
  30. package/workspace/lib/routes-goal-status.js +111 -0
  31. package/workspace/lib/routes-impact-views.js +58 -0
  32. package/workspace/lib/routes-impact.js +91 -0
  33. package/workspace/lib/routes-insights-premium.js +20 -0
  34. package/workspace/lib/routes-metric-drafts.js +55 -4
  35. package/workspace/lib/routes-records.js +2 -0
  36. package/workspace/lib/settings-store.js +3 -0
  37. package/workspace/okr-goals-ui-test.js +175 -0
  38. package/workspace/package-lock.json +2 -2
  39. package/workspace/package.json +1 -1
  40. package/workspace/public/pm/bd-ini-panel.js +10 -2
  41. package/workspace/public/pm/cozy-adler.css +5 -0
  42. package/workspace/public/pm/cozy-adler.js +17 -9
  43. package/workspace/public/pm/cozy-insights.css +84 -0
  44. package/workspace/public/pm/cozy-settings.js +11 -1
  45. package/workspace/public/pm/home-app.js +61 -8
  46. package/workspace/public/pm/home-impact.css +16 -0
  47. package/workspace/public/pm/home-impact.js +72 -0
  48. package/workspace/public/pm/home-today.js +4 -2
  49. package/workspace/public/pm/impact.css +37 -0
  50. package/workspace/public/pm/impact.js +201 -0
  51. package/workspace/public/pm/okr-list.js +249 -0
  52. package/workspace/public/pm/premium-insights.js +222 -238
  53. package/workspace/public/pm/premium-vw-mtg.js +4 -1
  54. package/workspace/public/premium-intelligence.html +3 -2
  55. package/workspace/public/premium.html +1 -0
  56. package/workspace/server.js +56 -2
  57. package/workspace/skills/impact-detect.skill +46 -0
  58. package/workspace/skills/metric-read.skill +32 -0
  59. package/workspace/test-lists/goal-watch.json +9 -0
  60. package/workspace/test-lists/impact-screens.json +5 -0
  61. package/workspace/test-lists/impact-ui.json +9 -0
  62. package/workspace/test-lists/impact.json +9 -0
  63. package/workspace/test-lists/okr-goals-ui.json +5 -0
@@ -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>`;