create-pmos 0.441.0 → 0.443.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 (87) 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/adler-seasons-art-test.js +106 -0
  7. package/workspace/adler-seasons-test.js +111 -0
  8. package/workspace/briefing-premium-board-test.js +19 -17
  9. package/workspace/briefing-premium-initiative-test.js +7 -4
  10. package/workspace/changelog.json +24 -0
  11. package/workspace/goals-clear-ui-test.js +249 -0
  12. package/workspace/guide/adler.md +10 -0
  13. package/workspace/guide/home.md +8 -1
  14. package/workspace/guide/metric-drafts.md +8 -2
  15. package/workspace/home-railcard-test.js +193 -0
  16. package/workspace/ini-workflow-test.js +6 -2
  17. package/workspace/intelligence-gaps-ui-test.js +16 -14
  18. package/workspace/lib/engine/records/index.js +9 -2
  19. package/workspace/lib/initiative-layout.js +3 -1
  20. package/workspace/lib/insights-premium.js +22 -1
  21. package/workspace/lib/metric-drafts.js +37 -10
  22. package/workspace/lib/metric-read-runs.js +20 -13
  23. package/workspace/lib/metric-reads.js +208 -23
  24. package/workspace/lib/metrics-cli.js +62 -5
  25. package/workspace/lib/routes-goal-status.js +89 -6
  26. package/workspace/lib/routes-insights-premium.js +1 -1
  27. package/workspace/lib/routes-metric-drafts.js +26 -3
  28. package/workspace/lib/settings-store.js +38 -0
  29. package/workspace/metric-drafts-ui-test.js +7 -4
  30. package/workspace/okr-goals-ui-test.js +7 -5
  31. package/workspace/package-lock.json +2 -2
  32. package/workspace/package.json +1 -1
  33. package/workspace/premium-board-actions-test.js +2 -1
  34. package/workspace/premium-chat-attach-test.js +2 -0
  35. package/workspace/program-panel-test.js +1 -1
  36. package/workspace/public/pm/bd-ini-panel.js +2 -2
  37. package/workspace/public/pm/c3-ini-ui.js +1 -1
  38. package/workspace/public/pm/cozy-adler.css +21 -0
  39. package/workspace/public/pm/cozy-adler.js +415 -8
  40. package/workspace/public/pm/cozy-ev.css +16 -1
  41. package/workspace/public/pm/cozy-home.css +8 -0
  42. package/workspace/public/pm/cozy-insights.css +82 -0
  43. package/workspace/public/pm/cozy-live-pill.css +5 -0
  44. package/workspace/public/pm/cozy-news.js +1 -1
  45. package/workspace/public/pm/cozy-seasons.js +318 -0
  46. package/workspace/public/pm/cozy-settings.js +88 -5
  47. package/workspace/public/pm/cozy-today.css +15 -0
  48. package/workspace/public/pm/cozy-viewer.js +50 -18
  49. package/workspace/public/pm/cozy-vw-shell.css +4 -0
  50. package/workspace/public/pm/cozy.css +65 -0
  51. package/workspace/public/pm/dash-view.js +4 -2
  52. package/workspace/public/pm/goals-clear.js +258 -0
  53. package/workspace/public/pm/home-app.js +59 -5
  54. package/workspace/public/pm/home-chat.js +1 -1
  55. package/workspace/public/pm/home-day.js +7 -4
  56. package/workspace/public/pm/home-ini.js +2 -2
  57. package/workspace/public/pm/home-mentions.js +1 -1
  58. package/workspace/public/pm/home-today.js +51 -10
  59. package/workspace/public/pm/impact.js +1 -1
  60. package/workspace/public/pm/ini-groups.js +28 -17
  61. package/workspace/public/pm/ini-links.js +1 -1
  62. package/workspace/public/pm/ini-tasks.js +246 -48
  63. package/workspace/public/pm/ini-view-model.js +45 -16
  64. package/workspace/public/pm/ini-view.css +330 -1
  65. package/workspace/public/pm/ini-view.js +196 -83
  66. package/workspace/public/pm/metric-drafts.js +4 -1
  67. package/workspace/public/pm/mission.js +238 -0
  68. package/workspace/public/pm/premium-board.js +1 -1
  69. package/workspace/public/pm/premium-insights.js +178 -24
  70. package/workspace/public/pm/premium-welcome.js +2 -2
  71. package/workspace/public/pm/split-merge.js +1 -1
  72. package/workspace/public/pm/stage-line.js +2 -2
  73. package/workspace/server.js +6 -2
  74. package/workspace/skills/metric-read.skill +7 -5
  75. package/workspace/split-merge-ui-test.js +1 -1
  76. package/workspace/stage-card-test.js +56 -11
  77. package/workspace/task-links-test.js +2 -0
  78. package/workspace/task-milestones-test.js +5 -1
  79. package/workspace/task-plans-test.js +3 -3
  80. package/workspace/task-views-test.js +279 -37
  81. package/workspace/test-lists/adler-seasons-art.json +13 -0
  82. package/workspace/test-lists/batch18-adler-seasons.json +13 -0
  83. package/workspace/test-lists/goals-clear.json +15 -0
  84. package/workspace/test-lists/home-railcard.json +9 -0
  85. package/workspace/test-lists/mission.json +5 -0
  86. package/workspace/test-lists/viewer-tasks.json +5 -0
  87. package/workspace/tk-tasks-test.js +27 -32
@@ -0,0 +1,238 @@
1
+ /* pm/mission.js — the initiative as a mission (feedback batch 18 item 1, agreed A; canvas In development: XvpL5Rocket, XvpL6RocketDark,
2
+ * XvpE1States, XvpE2Stages, XvpE3TapMs, XvpD1Desktop; the art is mission() in next18/viewer-on-phone-gen/gen_rocket3.py, ported here). It
3
+ * replaces the stage card's one line in the ONE initiative view (pm/ini-view.js): one picture of the whole initiative, 100 px tall.
4
+ *
5
+ * missionOf(L) → the model, from the stage line's model (pm/stage-line.js lineOf): every place is a % of the same line, so the
6
+ * picture and the line never disagree. Pure.
7
+ * missionSvg(M, o) → the SVG. o: { tap (the milestones are presses: a 44 px hit area each) }. Colours are classes (ini-view.css
8
+ * names the --mi-* tokens of cozy.css): no colour is written here.
9
+ * crowded(points, gap) → the ids of the points closer than gap to another one: those are drawn without a press (the tap on the picture
10
+ * opens the list in place instead).
11
+ *
12
+ * THE STORY (xvpA):
13
+ * the ground strip is the stages, on their plan dates: done green, now blue, late orange, on hold grey, dashed with no dates; Today ticks
14
+ * on it. Small flags are the early milestones (gold when passed, grey ahead, orange when late).
15
+ * Discover: a telescope near the left scans for the target planet, which is a "?" until Discover is done.
16
+ * Plan to Build: the rocket is a dashed blueprint on the pad at the start of Build; through the first half of Build it is built from the
17
+ * bottom up (a clip) with sparks. Past Build 50% it lifts off and flies a curve to the planet.
18
+ * The release milestone (the first one named launch, release, rollout or deploy): it lands on the planet and plants a flag. With no such
19
+ * milestone the planet stands at the end of Deliver; with no Build stage it lifts off at the start of the stage the release falls in.
20
+ * The stages say what happened and the dates how far along it is: the rocket stays a blueprint until Build runs, flies once Build is done,
21
+ * and lands only when the release milestone is done (with none, when Deliver is done).
22
+ * Monitor: a dish at the right edge listens, with waves; the last milestone ("Did it work?") lights it green.
23
+ * Motion (draw-in, flame, sparks, scan, twinkle, waves) is CSS; all of it stops under reduced motion and Settings > Adler > Motion: Still. */
24
+
25
+ export const W = 340, H = 100;
26
+ const GY = 78; // the ground line
27
+ export const PX = W - 62, PY = 27; // the target planet, near the right end, high in the sky (Wawan 12:27: far enough to fly to)
28
+ const DX = W - 16; // the dish, at the right edge
29
+ const TX = 30; // the telescope, near the left end
30
+ export const HIT = 44; // a press's square, in px (the picture draws about 1 px a unit)
31
+ export const NEAR = 24; // two presses closer than this are one press on the picture
32
+ export const RELEASE_RE = /\b(launch(es|ed)?|releas(e|es|ed)|roll[- ]?outs?|deploy(s|ed|ment)?)\b/i;
33
+
34
+ const X = (p) => +(6 + (Math.max(0, Math.min(100, p)) * (W - 12)) / 100).toFixed(1);
35
+ const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
36
+ const f1 = (n) => (+n).toFixed(1);
37
+ const clamp = (v, a, b) => Math.max(a, Math.min(b, v));
38
+ const isBuild = (p) => /^build$/i.test(p.key || '') || /\bbuild\b/i.test(p.name || '');
39
+ const isDiscover = (p) => /^discover/i.test(p.key || '') || /\bdiscover/i.test(p.name || '');
40
+ const isDeliver = (p) => /^deliver/i.test(p.key || '') || /\bdeliver/i.test(p.name || '');
41
+
42
+ /** The release milestone among the line's ◇s: the first item (in date order) named for a launch. → { x, item, at } | null */
43
+ export function releaseOf(ms) {
44
+ for (const [at, m] of (ms || []).entries()) for (const it of m.items || []) if (RELEASE_RE.test(it.name || '')) return { x: m.x, item: it, at };
45
+ return null;
46
+ }
47
+
48
+ /** The mission's model from the stage line's (lineOf). */
49
+ export function missionOf(L) {
50
+ if (!L) return null;
51
+ const finished = !!L.finished, hold = !!(L.chip && L.chip.pause), empty = !!L.empty;
52
+ const now = (L.parts || []).find((p) => p.cls === 'now');
53
+ const late = !hold && !finished && (!!L.over || (L.ms || []).some((m) => m.late && !m.done && now && m.x >= now.l - 0.5 && m.x <= now.l + now.w + 0.5));
54
+ const parts = (L.parts || []).map((p) => ({ key: p.key, name: p.name, l: p.l, w: p.w, dash: !!p.dash,
55
+ cls: finished || p.cls === 'done' ? 'dn' : p.cls === 'now' ? (hold ? 'hold' : late ? 'late' : 'nw') : 'q' }));
56
+ // where it is: Today's place on the line; past every date when it is done, at the start when the work has not begun
57
+ const t = finished ? 101 : L.today != null ? L.today : L.ended ? 101 : 0;
58
+ const ms = empty ? [] : (L.ms || []);
59
+ const rel = releaseOf(ms);
60
+ const endM = ms.find((m) => m.end) || null;
61
+ const evalItem = endM && endM.items && endM.items[0] && !(rel && rel.item === endM.items[0]) ? endM.items[0] : null;
62
+ // the planet's time: the release milestone, else the end of Deliver, else the end of the line
63
+ const del = parts.find(isDeliver);
64
+ const rx = rel ? rel.x : del ? del.l + del.w : 100;
65
+ // the build: the first half of Build, then lift-off; with no Build, it lifts off where the stage the release falls in starts
66
+ const bp = parts.find(isBuild);
67
+ let bA, lift;
68
+ if (bp) { bA = bp.l; lift = bp.l + bp.w / 2; }
69
+ else {
70
+ const i = parts.reduce((k, p, j) => (p.l <= rx + 0.01 ? j : k), -1);
71
+ lift = i >= 0 ? parts[i].l : rx;
72
+ bA = i > 0 ? parts[i - 1].l : 0;
73
+ }
74
+ if (lift <= bA) bA = Math.max(0, lift - 1);
75
+ // the stages say what happened, the dates only how far it is: it never flies before Build runs, nor lands before the release is done
76
+ // (with no Build: built through the stage before the release's, lifted off once the release's stage runs)
77
+ const ri = bp ? -1 : parts.reduce((k, p, j) => (p.l <= rx + 0.01 ? j : k), -1);
78
+ const builtIn = bp || (ri > 0 ? parts[ri - 1] : null), liftIn = bp ? null : ri >= 0 ? parts[ri] : null;
79
+ const mustFly = bp ? bp.cls === 'dn' : !!(liftIn && liftIn.cls !== 'q');
80
+ const landed = finished || (rel ? !!rel.item.done : del ? del.cls === 'dn' : false);
81
+ let phase, frac = 0, fly = 0;
82
+ if (landed) { phase = 'landed'; fly = 1; }
83
+ else if (!mustFly && builtIn && builtIn.cls === 'q') phase = 'pad';
84
+ else if (!mustFly && t < lift) { frac = t <= bA ? 0 : clamp((t - bA) / (lift - bA), 0, 1); phase = frac > 0 ? 'build' : 'pad'; }
85
+ else if (!mustFly && liftIn && liftIn.cls === 'q') { frac = 1; phase = 'build'; }
86
+ else { phase = 'fly'; fly = clamp((t - lift) / Math.max(0.01, rx - lift), 0.05, 0.95); }
87
+ const disc = parts.find(isDiscover);
88
+ const found = finished || !disc || disc.cls === 'dn';
89
+ const heard = finished || !!(evalItem && evalItem.done);
90
+ // the small flags: every ◇ but the release and the last one (a counted ◇ keeps its other milestones)
91
+ const flags = [];
92
+ ms.forEach((m) => {
93
+ if (m.end) return;
94
+ const items = (m.items || []).filter((it) => !rel || it !== rel.item);
95
+ if (!items.length) return;
96
+ flags.push({ x: m.x, n: items.length, items, name: items.length > 1 ? items.length + ' milestones' : items[0].name, date: items.length > 1 ? '' : items[0].date,
97
+ done: items.every((it) => it.done), late: items.some((it) => it.late) });
98
+ });
99
+ return { empty, hold, late, finished, t, today: !empty && !heard && L.today != null ? L.today : null, parts, flags, found, phase, frac, fly, landed, heard,
100
+ listening: landed && !heard, pad: bA, lift, rx,
101
+ planet: rel ? { id: rel.item.id || '', name: rel.item.name, date: rel.item.date || '', done: !!rel.item.done, late: !!rel.item.late } : null,
102
+ dish: evalItem ? { id: evalItem.id || '', name: evalItem.name, date: evalItem.date || '', done: !!evalItem.done, late: !!evalItem.late } : null };
103
+ }
104
+
105
+ /** The presses' centres, in the picture's units: the flags, the planet and the dish. → [{ key, x, y }] */
106
+ export function pointsOf(M) {
107
+ if (!M) return [];
108
+ const out = M.flags.map((f, i) => ({ key: 'f' + i, x: X(f.x) + 3, y: GY - 4 }));
109
+ if (M.planet) out.push({ key: 'planet', x: PX, y: PY });
110
+ if (M.dish) out.push({ key: 'dish', x: DX - 2, y: GY - 12 });
111
+ return out;
112
+ }
113
+ /** The keys of the points closer than gap to another point. */
114
+ export function crowded(points, gap = NEAR) {
115
+ const out = new Set();
116
+ for (let i = 0; i < points.length; i++) for (let j = i + 1; j < points.length; j++) {
117
+ if (Math.hypot(points[i].x - points[j].x, points[i].y - points[j].y) < gap) { out.add(points[i].key); out.add(points[j].key); }
118
+ }
119
+ return out;
120
+ }
121
+
122
+ const rocketBody = (fin = 'mi-fin') => '<path d="M-5 0 L-5 -18 Q-5 -26 0 -31 Q5 -26 5 -18 L5 0Z" class="mi-rb mi-ln" stroke-width="1.1" stroke-linejoin="round"/>'
123
+ + `<path d="M-5 -7 L-10 1 L-5 0Z M5 -7 L10 1 L5 0Z" class="${fin} mi-ln" stroke-width=".9" stroke-linejoin="round"/>`
124
+ + '<circle cx="0" cy="-17" r="2.4" class="mi-win mi-ln" stroke-width=".8"/>';
125
+ const ghostBody = () => '<path d="M-5 0 L-5 -18 Q-5 -26 0 -31 Q5 -26 5 -18 L5 0Z" fill="none" class="mi-gh" stroke-width="1.1" stroke-dasharray="2 2" stroke-linejoin="round"/>'
126
+ + '<path d="M-5 -7 L-10 1 L-5 0Z M5 -7 L10 1 L5 0Z" fill="none" class="mi-gh" stroke-width=".9" stroke-dasharray="2 2" stroke-linejoin="round"/>'
127
+ + '<circle cx="0" cy="-17" r="2.4" fill="none" class="mi-gh" stroke-width=".8" stroke-dasharray="2 2"/>';
128
+
129
+ let seq = 0;
130
+ /** The press around one drawn milestone: a 44 px square, the words for a reader, the task it opens. */
131
+ function press(inner, it, x, y, o, key, hold) {
132
+ if (!o.tap || !it || !it.id || hold.has(key)) return `<g aria-hidden="true">${inner}</g>`;
133
+ const words = it.name + (it.date ? ', ' + it.date : '') + (it.late ? ', late' : it.done ? ', done' : '');
134
+ return `<g class="mi-ms" role="button" tabindex="0" data-mi-ms="${esc(it.id)}" data-mi-tip="${esc(it.name)}" data-mi-date="${esc(it.date || '')}" data-mi-x="${f1((x / W) * 100)}" aria-label="${esc('Milestone ' + words + '. Open its task')}">`
135
+ + `<rect x="${f1(x - HIT / 2)}" y="${f1(y - HIT / 2)}" width="${HIT}" height="${HIT}" fill="transparent"/>${inner}</g>`;
136
+ }
137
+
138
+ /** The SVG of the mission. */
139
+ export function missionSvg(M, o = {}) {
140
+ if (!M) return '';
141
+ const id = 'mi' + (++seq).toString(36);
142
+ const crowd = crowded(pointsOf(M));
143
+ let s = `<defs><linearGradient id="${id}k" x1="0" y1="0" x2="0" y2="1"><stop offset="0" class="mi-s0"/><stop offset="1" class="mi-s1"/></linearGradient>`
144
+ + `<linearGradient id="${id}x" x1="0" x2="1"><stop offset="0" class="mi-t0"/><stop offset="1" class="mi-t1"/></linearGradient></defs>`;
145
+ s += `<rect x="0" y="0" width="${W}" height="${H}" fill="url(#${id}k)"/>`; // the corners are the box's (ini-view.css .iv-mi)
146
+ // the stars
147
+ [[30, 12, 1], [84, 26, 0.8], [124, 9, 1.2], [160, 30, 0.9], [250, 12, 1], [292, 30, 0.8], [W - 26, 8, 1]].forEach(([x, y, r], k) => {
148
+ s += `<circle class="mi-tw mi-star mi-d${k}" transform-origin="${x} ${y}" cx="${x}" cy="${y}" r="${r}"/>`;
149
+ });
150
+ // the target planet
151
+ const planet = `<g class="${M.found ? '' : 'mi-seek'}" transform-origin="${PX} ${PY}">`
152
+ + `<circle cx="${PX}" cy="${PY}" r="12" class="${M.found ? 'mi-pl' : 'mi-pq'}"${M.found ? '' : ' stroke-dasharray="3 3"'} stroke-width="1.4"/>`
153
+ + (M.found ? `<ellipse cx="${PX}" cy="${PY}" rx="18" ry="4.5" fill="none" class="mi-ring" stroke-width="1.6" transform="rotate(-18 ${PX} ${PY})"/>`
154
+ + `<circle cx="${PX - 4}" cy="${PY - 3}" r="2.6" class="mi-spot"/><circle cx="${PX + 4}" cy="${PY + 4}" r="1.8" class="mi-spot"/>`
155
+ : `<text x="${PX}" y="${PY + 4}" text-anchor="middle" class="mi-qm">?</text>`) + '</g>';
156
+ s += press(planet, M.planet, PX, PY, o, 'planet', crowd);
157
+ // the ground and the stage strip
158
+ s += `<path d="M0 ${H} L0 ${GY - 2} Q60 ${GY - 5} 130 ${GY - 2} T${W} ${GY - 3} L${W} ${H}Z" class="mi-gr"/>`;
159
+ for (const p of M.parts) {
160
+ const x = X(p.l), w = Math.max(X(p.l + p.w) - x - 2, 3);
161
+ s += p.dash || M.empty ? `<rect x="${f1(x + 1)}" y="${GY + 4}" width="${f1(w)}" height="6" rx="3" fill="none" class="mi-dsh ${p.cls}" stroke-dasharray="2 2"/>`
162
+ : `<rect x="${f1(x + 1)}" y="${GY + 4}" width="${f1(w)}" height="6" rx="3" class="mi-st ${p.cls}"/>`;
163
+ }
164
+ // the small flags
165
+ M.flags.forEach((f, i) => {
166
+ const x = X(f.x);
167
+ const inner = `<rect x="${f1(x - 0.7)}" y="${GY - 8}" width="1.4" height="12" class="mi-pole"/><path d="M${f1(x + 0.7)} ${GY - 8} L${f1(x + 7)} ${GY - 6} L${f1(x + 0.7)} ${GY - 4}Z" class="mi-fl ${f.late ? 'late' : f.done ? 'dn' : 'q'}"/>`;
168
+ s += press(inner, f.n === 1 ? f.items[0] : null, x + 3, GY - 4, o, 'f' + i, crowd);
169
+ });
170
+ // Discover: the telescope looks for the planet
171
+ const still = M.hold || M.empty;
172
+ const seeking = !M.found && !M.hold;
173
+ const ang = (Math.atan2(PY - (GY - 14), PX - TX) * 180) / Math.PI;
174
+ s += `<g aria-hidden="true"><path d="M${TX - 5} ${GY} L${TX} ${GY - 10} L${TX + 5} ${GY} M${TX} ${GY - 10} L${TX} ${GY}" class="mi-ln" stroke-width="1.1" fill="none" stroke-linecap="round"/>`
175
+ + `<g class="${seeking ? 'mi-scan' : ''}" transform-origin="${TX} ${GY - 12}"><g transform="translate(${TX} ${GY - 12}) rotate(${ang.toFixed(1)})">`
176
+ + '<rect x="-4" y="-2.6" width="15" height="5.2" rx="2" class="mi-wh mi-ln" stroke-width="1.1"/><rect x="10" y="-3.4" width="3" height="6.8" rx="1" class="mi-lens mi-ln" stroke-width=".9"/></g></g></g>';
177
+ if (seeking && !M.empty) s += `<line class="mi-beam" x1="${TX + 10}" y1="${GY - 19}" x2="${PX - 12}" y2="${PY + 4}" stroke-width="1.2" stroke-dasharray="2 5" aria-hidden="true"/>`;
178
+ // Plan to Build: the pad at the start of Build; the rocket is a blueprint, then built from the bottom up; past Build 50% it flies
179
+ // the pad stands in the middle, as the telescope stands left and the dish right (Wawan 12:26): the props keep their places, only the
180
+ // stages under them follow the dates
181
+ const bx = W / 2;
182
+ const fin = M.late ? 'mi-fin late' : 'mi-fin';
183
+ s += `<g aria-hidden="true"><rect x="${f1(bx - 12)}" y="${GY - 1}" width="24" height="3" rx="1.5" class="mi-pad"/>`
184
+ + `<path d="M${f1(bx - 14)} ${GY} L${f1(bx - 14)} ${GY - 34} M${f1(bx - 14)} ${GY - 26} L${f1(bx - 6)} ${GY - 26} M${f1(bx - 14)} ${GY - 14} L${f1(bx - 6)} ${GY - 14}" fill="none" class="mi-padl" stroke-width="1.2"/></g>`;
185
+ if (M.phase === 'pad' || M.phase === 'build') {
186
+ let b = `<g transform="translate(${f1(bx)} ${GY - 1})" role="img" aria-label="${esc(M.phase === 'pad' ? 'The rocket, a blueprint on the pad' : 'The rocket, ' + Math.round(M.frac * 100) + '% built')}">`;
187
+ b += `<g opacity="${M.frac === 0 ? 0.5 : 0.35}">${ghostBody()}</g>`;
188
+ if (M.frac > 0) {
189
+ const h = 34 * M.frac;
190
+ b += `<clipPath id="${id}b"><rect x="-12" y="${f1(2 - h)}" width="24" height="${f1(h)}"/></clipPath><g clip-path="url(#${id}b)">${rocketBody(fin)}</g>`;
191
+ if (!still) for (let k = 0; k < 3; k++) b += `<circle class="mi-spark mi-k${k}" cx="${-6 + k * 6}" cy="${f1(2 - h)}" r="1.1"/>`;
192
+ }
193
+ s += b + '</g>';
194
+ } else {
195
+ s += `<g class="mi-puff" aria-hidden="true"><circle cx="${f1(bx - 6)}" cy="${GY - 3}" r="3.5" class="mi-smoke"/><circle cx="${f1(bx + 5)}" cy="${GY - 4}" r="4" class="mi-smoke"/></g>`;
196
+ const p0 = [bx, GY - 20], c1 = [bx + 10, 4], p1 = [PX - 12, PY - 9]; // it comes down onto the planet's upper left
197
+ const bz = (u) => [(1 - u) ** 2 * p0[0] + 2 * (1 - u) * u * c1[0] + u * u * p1[0], (1 - u) ** 2 * p0[1] + 2 * (1 - u) * u * c1[1] + u * u * p1[1]];
198
+ const all = Array.from({ length: 41 }, (_, i) => bz(i / 40)), pts = Array.from({ length: 41 }, (_, i) => bz((i / 40) * M.fly));
199
+ let len = 0; for (let i = 0; i < 40; i++) len += Math.hypot(pts[i + 1][0] - pts[i][0], pts[i + 1][1] - pts[i][1]);
200
+ const d = (P) => 'M' + P.map(([x, y]) => f1(x) + ' ' + f1(y)).join(' L');
201
+ if (!M.landed) s += `<path d="${d(all)}" fill="none" class="mi-path" stroke-width="1.4" stroke-dasharray="1.5 5" aria-hidden="true"/>`;
202
+ s += `<path class="mi-vn" d="${d(pts)}" fill="none" stroke="url(#${id}x)" stroke-width="${M.landed ? 2.4 : 3}" stroke-linecap="round" opacity="${M.landed ? 0.45 : 1}" pathLength="100" aria-hidden="true"/>`;
203
+ let rx, ry, a, flame = '';
204
+ if (M.landed) { rx = PX - 5; ry = PY - 11; a = -12; }
205
+ else {
206
+ [rx, ry] = pts[40];
207
+ a = (Math.atan2(pts[40][1] - pts[38][1], pts[40][0] - pts[38][0]) * 180) / Math.PI + 90;
208
+ if (!M.hold) flame = '<g class="mi-flame"><path d="M-3.4 1 Q0 12 3.4 1Z" class="mi-fo"/><path d="M-1.8 1 Q0 7 1.8 1Z" class="mi-fy"/></g>';
209
+ }
210
+ // the farther it flies the smaller it looks (Wawan 12:27): from .8 on the pad's side to .4 at the planet
211
+ const sc = M.landed ? 0.4 : 0.8 - 0.4 * M.fly;
212
+ s += `<g class="${M.landed ? '' : 'mi-rk'}" role="img" aria-label="${M.landed ? 'Landed at the release' : 'Flying to the release'}"><g transform="translate(${f1(rx)} ${f1(ry)}) rotate(${a.toFixed(1)}) scale(${sc.toFixed(2)})">${flame}${rocketBody(fin)}</g></g>`;
213
+ if (M.landed) s += `<g aria-hidden="true"><rect x="${PX + 5}" y="${PY - 20}" width="1.4" height="9" class="mi-pole"/><path class="mi-flag" transform-origin="${PX + 6} ${PY - 19}" d="M${PX + 6.4} ${PY - 20} L${PX + 14} ${PY - 17.5} L${PX + 6.4} ${PY - 15}Z"/></g>`;
214
+ }
215
+ // Monitor: the dish listens; the last milestone lights it green
216
+ let dish = `<path d="M${DX} ${GY} L${DX} ${GY - 10}" class="mi-ln" stroke-width="1.2"/>`
217
+ + `<path d="M${DX - 9} ${GY - 18} Q${DX - 2} ${GY - 6} ${DX + 6} ${GY - 10}" class="mi-wh mi-ln" stroke-width="1.1"/>`
218
+ + `<line x1="${DX - 2}" y1="${GY - 12}" x2="${DX - 7}" y2="${GY - 20}" class="mi-ln" stroke-width="1"/>`
219
+ + `<circle cx="${DX - 7}" cy="${GY - 21}" r="1.8" class="mi-lamp ${M.heard ? 'on' : M.listening ? 'ls' : ''}"/>`;
220
+ if (M.listening && !M.hold) for (let k = 0; k < 3; k++) dish += `<path class="mi-wave mi-k${k}" d="M${DX - 14 - k * 7} ${GY - 26 - k * 3} q-4 4 0 8" fill="none" stroke-width="1.3" stroke-linecap="round"/>`;
221
+ s += press(dish, M.dish, DX - 2, GY - 12, o, 'dish', crowd);
222
+ // Today
223
+ if (M.today != null) {
224
+ const xt = X(M.today);
225
+ s += `<g role="img" aria-label="Today"><circle class="mi-glow" cx="${xt}" cy="${GY + 7}" r="5"/><line x1="${xt}" y1="${GY + 1}" x2="${xt}" y2="${GY + 13}" class="mi-td" stroke-width="2" stroke-linecap="round"/></g>`;
226
+ }
227
+ if (M.hold) {
228
+ const xt = X(M.t > 100 ? 100 : M.t);
229
+ s += `<g transform="translate(${f1(xt + 6)} ${GY - 12})" class="mi-pz" role="img" aria-label="On hold"><rect x="0" y="0" width="2" height="7" rx="1"/><rect x="4" y="0" width="2" height="7" rx="1"/></g>`;
230
+ }
231
+ return `<svg class="mi-svg" viewBox="0 0 ${W} ${H}" width="100%" preserveAspectRatio="xMidYMid meet" role="group" aria-label="${esc(o.label || 'The initiative as a mission: its stages and milestones')}">${s}</svg>`;
232
+ }
233
+
234
+ /** The current stage's name under the strip (the desktop's two columns): its place, as a % of the picture. → { name, x, late } | null */
235
+ export function nowName(M) {
236
+ const p = M && M.parts.find((q) => q.cls === 'nw' || q.cls === 'late' || q.cls === 'hold');
237
+ return p ? { name: p.name, x: +((X(p.l + p.w / 2) / W) * 100).toFixed(2), late: p.cls === 'late' } : null;
238
+ }
@@ -82,7 +82,7 @@ PG.goalsFrom((name) => (M ? M.initiatives.list.rows.filter((r) => !M.board.all |
82
82
  const SV = (d) => `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${d}"/></svg>`;
83
83
  const I = {
84
84
  x: 'M6 6l12 12M18 6L6 18', expand: 'M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7', more: 'M5 12h.01M12 12h.01M19 12h.01', go: 'M5 12h14M13 6l6 6-6 6', next: 'M9 6l6 6-6 6',
85
- ext: 'M14 4h6v6M20 4l-9 9M10 6H5v13h13v-5', refresh: 'M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7', cal: 'M4 6h16v14H4zM4 10h16M9 3v4M15 3v4', jira: 'M12 3l9 9-9 9-9-9z',
85
+ ext: 'M14 4h6v6M20 4l-9 9M10 6H5v13h13v-5', refresh: 'M20 11a8 8 0 1 0-2.3 5.7M20 4v7h-7', cal: 'M4 6h16v14H4zM4 10h16M9 3v4M15 3v4', jira: 'M4 7h16v3a2 2 0 0 0 0 4v3H4v-3a2 2 0 0 0 0-4z',
86
86
  flag: 'M5 21V4M5 4h11l-2 4 2 4H5', note: 'M4 5h16v11h-9l-5 4v-4H4z', spark: 'M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z',
87
87
  doc: 'M6 3h9l4 4v14H6zM14 3v5h5', link: 'M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1', chev: 'M7 10l5 5 5-5', chevUp: 'M7 14l5-5 5 5',
88
88
  move: 'M4 12h12M12 6l6 6-6 6M20 5v14', hold: 'M9 5v14M15 5v14', archive: 'M4 5h16v4H4zM6 9v10h12V9M10 13h4',
@@ -39,6 +39,7 @@ import * as AD from './cozy-adler.js'; // Adler in Claude's ✦ line only, nev
39
39
  import * as RL from './ready-lib.js'; // the ready-made reports of every program, product and initiative (batch 17 item 1, PbA6, PbG4)
40
40
  import * as RI from './premium-report-intel.js'; // a report made from Intelligence (batch 15 item 4): the header icon, the ✦ proposals, the draft panel
41
41
  import * as OK from './okr-list.js'; // Claude runs the OKRs (batch 16 item 6, 6-B): the goal list, its drafts, the ✦ line, ⋯ › Metrics, the notify choice
42
+ import * as GC from './goals-clear.js'; // goals made clear (batch 18 item 11, 11-B): the drafts table, the check panel, first readings, failed and held
42
43
 
43
44
  let M = null; // the model
44
45
  let BM = null, bmErr = ''; // the Board measures (Delivery trends)
@@ -386,8 +387,14 @@ const listGoals = () => (PF ? [] : M.goals.filter((g) => isOwnKr(g) && (g.role =
386
387
  /** The ✦ line (GsM1–M5): the one thing that matters this week, from lib/goal-status.js (model.okr.line) or said from the goals and drafts. It is
387
388
  * the strip's first item; the findings and the reports Claude proposes follow it. It never says "There is no insight yet". */
388
389
  function okrLine() {
389
- const run = DR && DR.run;
390
- return OK.lineOf({ okr: M.okr, goals: listGoals(), budgets: M.budgets || [], drafts: drAll(), running: !!(run && run.state === 'running'), failed: run && run.state === 'failed' ? (run.error || 'The run failed') : null, product: M.board.name });
390
+ const run = DR && DR.run, running = !!(run && run.state === 'running');
391
+ const base = OK.lineOf({ okr: M.okr, goals: listGoals(), budgets: M.budgets || [], drafts: drAll(), running, failed: run && run.state === 'failed' ? (run.error || 'The run failed') : null, product: M.board.name });
392
+ if (running || base.tone === 'crit') return base;
393
+ // batch 18 item 11 (GcJ1aTable, GcJ2FirstMonday, GcR4Failed, GcR5Held): a held reading, a failed read or the first readings are the news; else
394
+ // the drafted metrics in the table say what Claude drafted. ✓✓ still keeps every open draft.
395
+ // A goal behind its line stays the news over the drafts; the drafts line replaces only a line about drafts or a calm one.
396
+ const news = GC.lineOf(listGoals(), M.board.name) || (base.tone === 'drafts' || base.tone === 'calm' ? GC.draftsLine(tableRows(), M.board.name) : null);
397
+ return news ? Object.assign({}, news, { keepAll: Math.max(news.keepAll || 0, base.keepAll || 0) }) : base;
391
398
  }
392
399
  function stripList() {
393
400
  const I0 = M.insight || { none: true, text: '' };
@@ -461,6 +468,7 @@ const nsGoal = () => (PF ? null : M.goals.find((g) => g.role === 'north-star' &&
461
468
  * chart is in the Viewer and its inputs are in the more menu, Metrics, as a tree. A drafted North Star (or a drafted input or guardrail) that is not a
462
469
  * record yet is a hollow row with its keep press. Nothing to show: the card is not drawn (zero is silence). */
463
470
  function nsMeta(g) {
471
+ const lk = rowLook(g); if (lk.meta) return lk.meta;
464
472
  if (g.reading && g.reading.txt) return OK.metaOf(g, today());
465
473
  const S = g.series || [];
466
474
  if (!S.length) return OK.metaOf(g, today());
@@ -471,10 +479,10 @@ function nsMeta(g) {
471
479
  function drawNs() {
472
480
  const box = $('#nsRow');
473
481
  if (!M || PF) { box.hidden = true; box.innerHTML = ''; return; }
474
- const g = nsGoal(), loose = looseDrafts().filter((r) => r.kind === 'metric' && (r.group === 'North Star' || r.group === 'Inputs' || r.group === 'Guardrails'));
475
- if (!g && !loose.length) { box.hidden = true; box.innerHTML = ''; return; }
476
- const rows = (g ? OK.rowHtml(g, { meta: nsMeta(g), drafts: draftsFor(g.id), drawDraft: drHtml, noOwner: !OK.whoOf(g), today: today() }) : '')
477
- + loose.map((r) => (drEdit === r.id ? `<div class="okr-row">${drEditHtml(r)}</div>` : OK.draftRowHtml(r))).join('');
482
+ // batch 18 item 11: a drafted North Star is a row of the drafts table, never a second North Star row here
483
+ const g = nsGoal();
484
+ if (!g) { box.hidden = true; box.innerHTML = ''; return; }
485
+ const rows = OK.rowHtml(g, Object.assign({ meta: nsMeta(g), drafts: draftsFor(g.id), drawDraft: drHtml, noOwner: !OK.whoOf(g), today: today() }, rowLook(g)));
478
486
  box.innerHTML = `<div class="okr-sec"><h2 class="okr-h">North Star</h2></div><div class="okr-card">${rows}</div>`;
479
487
  box.hidden = false; box.classList.add('okr-ns');
480
488
  }
@@ -497,7 +505,10 @@ async function draftsLoad() {
497
505
  }
498
506
  const drAll = () => OK.draftsOf(DR);
499
507
  /** The drafts under one goal row. */
500
- const draftsFor = (id) => drAll().filter((r) => r.goal === id);
508
+ // a held reading's drafted ticket (GcR5Held) and a failed read's reconnect (GcR4Failed) are said in the goal's panel, with the reading they
509
+ // are about: not again under the row
510
+ const draftsFor = (id) => { const g = M && M.goals.find((x) => x.id === id), H = g && (g.held || [])[0]; const fx = g && g.failed && g.failed.fix && g.failed.fix.row;
511
+ return drAll().filter((r) => r.goal === id && !(H && r.kind === 'ticket' && (!H.ticket || H.ticket === r.id)) && !(fx && r.id === fx)); };
501
512
  /** A draft with no goal on the list: a drafted North Star or key result is drawn as its own hollow row; inputs and guardrails sit in the North
502
513
  * Star card; anything else in the loose box under the ✦ line. */
503
514
  const looseDrafts = () => { const ids = new Set(M.goals.map((g) => g.id).concat((M.budgets || []).map((b) => b.id))); return drAll().filter((r) => !r.goal || !ids.has(r.goal)); };
@@ -520,9 +531,14 @@ function drawDrafts() {
520
531
  if (!M || PF) { box.hidden = true; box.innerHTML = ''; return; }
521
532
  const placed = new Set(['North Star', 'Inputs', 'Guardrails', 'Key results']);
522
533
  const L = looseDrafts().filter((r) => !(r.kind === 'metric' && placed.has(r.group)));
523
- box.innerHTML = L.length ? `<div class="okr-card">${L.map((r) => `<div class="okr-row">${drHtml(r)}</div>`).join('')}</div>` : '';
524
- box.hidden = !L.length;
534
+ // batch 18 item 11 (GcJ1aTable): the drafted metrics are ONE table, how each is counted and where and how often it is read; the other loose
535
+ // drafts follow it as before
536
+ const T = GC.tableHtml(tableRows(), { busy: tblBusy, sel: CHK && CHK.id });
537
+ box.innerHTML = T + (L.length ? `<div class="okr-card">${L.map((r) => `<div class="okr-row">${drHtml(r)}</div>`).join('')}</div>` : '');
538
+ box.hidden = !T && !L.length;
539
+ box.classList.toggle('gc-on', !!T);
525
540
  if (M) { drawStrip(); drawNs(); drawGoals(); }
541
+ if (CHK) CHK.draw();
526
542
  }
527
543
  /** One press on a draft: keep (its act), drop, edit, save, cancel or undo; keep-all from the ✦ line; start asks Claude to draft the goals. */
528
544
  async function draftPress(k, row, b) {
@@ -549,8 +565,9 @@ async function draftPress(k, row, b) {
549
565
  const name = r0 ? r0.text : 'it';
550
566
  // batch 18 item 4: say only what the server started. The run is in Sessions; the ✦ line follows it and says when it ends, or why it failed.
551
567
  const said = k === 'start' ? (res.already ? 'I am already drafting them. The drafts show here when I finish.' : 'Drafting now. Follow it in Sessions; the drafts show here when I finish.')
552
- : k === 'keep-all' ? 'Kept ' + (res.kept || 'them all') + '. I read them from now on.'
553
- : k === 'keep' ? (res.outbox ? (r0 && r0.kind === 'ticket' ? 'In the outbox for Jira.' : 'In the outbox. It goes as you.') : res.open === 'settings:connectors' ? 'Opening Connectors.' : 'Kept. I read it from now on.')
568
+ // batch 18 item 11: "Kept" names the goal's own rhythm (the server's rhythm.txt, else the recipe), never "every morning"
569
+ : k === 'keep-all' ? (res.rhythm && res.rhythm.txt ? 'Kept ' + (res.kept || 'them all') + '. I read them ' + res.rhythm.txt + '.' : GC.keptSay(tableRows()).replace(/^Kept\. I read it /, 'Kept. I read them '))
570
+ : k === 'keep' ? (res.outbox ? (r0 && r0.kind === 'ticket' ? 'In the outbox for Jira.' : 'In the outbox. It goes as you.') : res.open === 'settings:connectors' ? 'Opening Connectors.' : GC.keptSay(r0 && r0.kind === 'metric' ? [r0] : [], res.rhythm && res.rhythm.txt ? 'Kept. I read it ' + res.rhythm.txt + '.' : null))
554
571
  : k === 'drop' ? 'Not now: ' + name + '.' : k === 'undo' ? 'Undone.' : 'Done.';
555
572
  toast(said, k === 'keep' || k === 'drop' ? { label: 'Undo', fn: async () => { await pmPost('/api/metric-drafts/undo', Object.assign({ row }, base)); await load(); await draftsLoad(); } } : undefined);
556
573
  if (res.open === 'settings:connectors') import('./cozy-settings.js').then((S) => S.openSettings('connectors')).catch(() => {});
@@ -568,6 +585,114 @@ document.addEventListener('keydown', (e) => {
568
585
  if (e.key === 'Escape') { e.preventDefault(); drEdit = null; drawDrafts(); }
569
586
  });
570
587
 
588
+ /* ── goals made clear (batch 18 item 11, 11-B; frames Gc* on In development) ─────────────────────────────────────────────────────────
589
+ * The drafted metrics are one table (GcJ1aTable); a row opens its check panel in the Viewer card (GcJ1Drafts): how it is counted, the live read,
590
+ * Claude's checks, your number to compare (GcS3Differs), how often and the query, then ↗ ✎ ↻ and Keep. A kept goal with fewer than 3 readings says
591
+ * its reading with source and time and no pace yet (GcJ2FirstMonday); a read that failed or a reading that was held never shows as progress: the row
592
+ * keeps the last good reading and says what happened (GcR4Failed, GcR5Held). The reads are GET /api/metric-drafts and GET /api/insights-premium;
593
+ * the writes POST /api/goal-status/test, /read, /compare, /compare-pick and /file-held (lib/routes-goal-status.js), and the draft routes. */
594
+ const tableRows = () => (PF || !M ? [] : looseDrafts().filter((r) => r.kind === 'metric' && r.state === 'open' && ['North Star', 'Inputs', 'Guardrails', 'Key results'].includes(r.group)));
595
+ const tblBusy = new Set();
596
+ let CHK = null; // the check panel shown: { id, st, draw }
597
+ /** A goal row's look while its reading is not ordinary: a read that failed, a held reading, or the first readings (no pace, a grey dot). */
598
+ function rowLook(g) {
599
+ const base = () => OK.metaOf(g, today());
600
+ if (g.failed) return { meta: [base(), 'not read ' + GC.dayTxt(g.failed.at)].filter(Boolean).join(' · ') };
601
+ const H = (g.held || []).length; if (H) return { meta: [base(), H === 1 ? '1 reading held' : H + ' readings held'].join(' · ') };
602
+ if (GC.firstOf(g) && OK.dotOf(g) !== 'broken') return { meta: GC.firstMeta(g), dot: 'q' };
603
+ return {};
604
+ }
605
+ $('#draftBox').addEventListener('click', (e) => {
606
+ const b = e.target.closest('[data-gc]');
607
+ if (b) { e.stopPropagation(); if (!b.disabled) tablePress(b.dataset.gc, b.dataset.row, b); return; }
608
+ const r = e.target.closest('[data-gc-row]'); if (r) openCheck(r.dataset.gcRow);
609
+ });
610
+ $('#draftBox').addEventListener('keydown', (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target.matches && e.target.matches('[data-gc-row]')) { e.preventDefault(); openCheck(e.target.dataset.gcRow); } });
611
+ async function tablePress(k, row, b) {
612
+ if (k !== 'keep' && k !== 'drop') return;
613
+ tblBusy.add(row); drawDrafts();
614
+ await draftPress(k, row, null);
615
+ tblBusy.delete(row); drawDrafts();
616
+ if (CHK && CHK.id === row && !drAll().some((x) => x.id === row && x.state === 'open')) closeViewer();
617
+ }
618
+ /** Reads the drafts again every 3 s until `until()` holds, at most `n` times: a live read or a compare is a run that ends on its own. */
619
+ async function followDrafts(until, n = 20) {
620
+ for (let i = 0; i < n; i++) { await new Promise((ok) => setTimeout(ok, 3000)); if (!CHK) return false; await draftsLoad(); if (until()) return true; }
621
+ return false;
622
+ }
623
+ /** The number the PM typed: "39k", "44,100", "94.1", "1.2m". NaN when it is not one. */
624
+ const typedNum = (raw) => { const m = /^([\d.,]+)\s*([kKmM%]?)$/.exec(String(raw || '').replace(/\s+/g, '')); return m ? Number(m[1].replace(/,/g, '')) * ({ k: 1e3, K: 1e3, m: 1e6, M: 1e6 }[m[2]] || 1) : NaN; };
625
+ /** The check panel of one drafted metric (GcJ1Drafts; GcS3Differs once a number was typed). */
626
+ function openCheck(id) {
627
+ const r0 = drAll().find((x) => x.id === id); if (!r0 || !M.board.ws) return;
628
+ const st = { compare: '', busy: false, msg: '', back: false, edit: false };
629
+ const rowOf = () => drAll().find((x) => x.id === id) || r0;
630
+ const base = { ws: M.board.ws, scope: 'product', id: M.board.ws };
631
+ let el = null;
632
+ const editHtml = (r) => `<form class="gc-ed" data-gc-ed><label class="ins-fl">Name<input class="ins-inp" name="name" maxlength="120" value="${esc(r.name)}"></label>`
633
+ + (r.raw && r.raw.type !== 'Done or not' ? `<label class="ins-fl">Target<input class="ins-inp" name="target" inputmode="decimal" maxlength="20" value="${esc(r.raw && r.raw.target != null ? String(r.raw.target) : '')}"></label>` : '')
634
+ + `<label class="ins-fl">Measured by<input class="ins-inp" name="source" maxlength="40" value="${esc(r.source || '')}"></label><div class="gc-foot"><a class="cz-ib sm" href="${esc(homeAsk('insights', 'Change how ' + r.name + ' is counted: '))}" aria-label="Ask Claude in Home to change how it is counted" title="Ask in Home">${SV('M4 5h16v11H9l-5 4z')}</a><span class="gc-sp"></span>`
635
+ + `<button type="button" class="cz-ib sm" data-gc="edit-x" aria-label="Cancel the edit" title="Cancel">${SV(I.x)}</button><button type="submit" class="cz-ib sm solid" aria-label="Save" title="Save">${SV(I.chk)}</button></div></form>`;
636
+ const draw = () => { if (!el || !document.contains(el)) return; const r = rowOf(), top = el.scrollTop; el.innerHTML = st.edit ? editHtml(r) : GC.checkHtml(r, st); el.scrollTop = top; };
637
+ CHK = { id, st, draw };
638
+ const post = (path, body) => pmPost(path, Object.assign({ ws: M.board.ws }, body)).catch(() => null);
639
+ const live = () => { const r = rowOf(); return r.raw && r.raw.live; };
640
+ const press = async (k) => {
641
+ const r = rowOf();
642
+ if (k === 'edit') { st.edit = true; draw(); const f = el.querySelector('[name="name"]'); if (f) f.focus(); return; }
643
+ if (k === 'edit-x') { st.edit = false; draw(); return; }
644
+ if (k === 'keep') { st.busy = true; draw(); await draftPress('keep', id, null); st.busy = false; if (!drAll().some((x) => x.id === id && x.state === 'open')) closeViewer(); else draw(); return; }
645
+ if (k === 'test') {
646
+ st.busy = true; st.msg = 'Reading it now. Nothing is kept until you keep it.'; draw();
647
+ const was = live() ? live().at : null, res = await post('/api/goal-status/test', { rows: [id] });
648
+ st.busy = false;
649
+ if (!res || res.ok !== true) { st.msg = (res && res.error) || 'It could not be read. Nothing changed.'; draw(); return; }
650
+ draw();
651
+ const got = await followDrafts(() => !!(live() && live().at && live().at !== was));
652
+ st.msg = got ? '' : 'Still reading. Follow it in Sessions; the number shows here when it lands.'; draw(); return;
653
+ }
654
+ if (k === 'pick' || k === 'pick-other') {
655
+ const sg = r.raw && r.raw.compare && r.raw.compare.suggest, want = sg && sg.keep === 'yours' ? 'yours' : 'mine';
656
+ const pick = k === 'pick' ? want : want === 'yours' ? 'mine' : 'yours';
657
+ st.busy = true; draw();
658
+ const res = await post('/api/goal-status/compare-pick', { goal: id, pick });
659
+ st.busy = false;
660
+ if (!res || res.ok !== true) { st.msg = (res && res.error) || 'It could not be saved. Nothing changed.'; draw(); return; }
661
+ st.back = true; st.compare = ''; st.msg = '';
662
+ toast(pick === 'yours' ? 'Done. “How it is counted” says it your way now.' : 'Done. I keep counting it my way.'); await draftsLoad();
663
+ }
664
+ };
665
+ const wire = (body) => {
666
+ el = body; el.classList.add('ins-vbody', 'gc-panel'); draw();
667
+ el.onclick = (e) => { const b = e.target.closest('[data-gc]'); if (b && !b.disabled) { e.preventDefault(); press(b.dataset.gc); } };
668
+ el.onsubmit = async (e) => {
669
+ e.preventDefault(); const f = e.target;
670
+ if (f.matches('[data-gc-ed]')) {
671
+ const body = { row: id, name: f.name.value, source: f.source.value }; if (f.target) body.target = f.target.value;
672
+ st.busy = true; const res = await pmPost('/api/metric-drafts/edit', Object.assign({}, base, body)).catch(() => null); st.busy = false;
673
+ if (!res || res.ok !== true) { toast((res && res.error) || 'It could not be saved. Nothing changed.'); return; }
674
+ st.edit = false; toast(res.changed === false ? 'Nothing changed.' : 'Saved. Keep it to read it as you wrote it.'); await draftsLoad(); return;
675
+ }
676
+ if (!f.matches('[data-gc-cmp]')) return;
677
+ const raw = String(f.v.value || '').trim(), v = typedNum(raw);
678
+ if (!Number.isFinite(v)) { st.msg = 'Type a number, for example 39k or 94.1.'; draw(); return; }
679
+ st.compare = raw; st.busy = true; st.back = false; st.msg = ''; draw();
680
+ const L = live();
681
+ const res = await post('/api/goal-status/compare', { goal: id, value: v, period: (L && L.period) || undefined });
682
+ st.busy = false;
683
+ if (!res || res.ok !== true) { st.msg = (res && res.error) || 'It could not be compared. Nothing changed.'; draw(); return; }
684
+ await draftsLoad();
685
+ const c = rowOf().raw && rowOf().raw.compare;
686
+ if (c && c.differs && !c.why) await followDrafts(() => { const x = rowOf().raw && rowOf().raw.compare; return !!(x && x.why); }, 10);
687
+ };
688
+ };
689
+ const body = vwOpen({ kind: 'Drafted metric', title: r0.name, sub: 'Check it before you keep it', icon: 'goal', id: 'draft:' + id,
690
+ more: [{ label: 'Not now', note: 'drop this draft', on: () => tablePress('drop', id, null) }],
691
+ onClose: () => { if (CHK && CHK.id === id) { CHK = null; drawDrafts(); } }, render: wire });
692
+ if (!body) { openSide({ kind: 'view', eye: 'Check it before you keep it', title: r0.name, body: '', note: '', go: null }); wire($('#sideBody')); }
693
+ drawDrafts();
694
+ }
695
+
571
696
  /* ── Reports and dashboards (⋯; the old Library tab) in a side panel: Found in your work, requests from Home, the reports, then the dashboards ── */
572
697
  let libBack = null;
573
698
  function openLib() {
@@ -639,7 +764,7 @@ function bandSvg(pts, lim, ceil, tone, label, w = 210, h = 40) {
639
764
  /* the goal list (GsM1–M5): Key results, then Health budgets, one row per goal: the dot, the outcome, the reading with its age, and the owner. No
640
765
  * sparkline and no initiative status on a row: the chart and what moves it are in the Viewer. The same list on a phone and a desktop. */
641
766
  const okrRow = (g, o = {}) => OK.rowHtml(g, Object.assign({ today: today(), drafts: PF ? [] : draftsFor(g.id), drawDraft: drHtml, mark: markHtml,
642
- selecting, sel: selecting && picked.includes(g.id), meta: PF ? [g.prod, OK.metaOf(g, today())].filter(Boolean).join(' · ') : undefined }, o));
767
+ selecting, sel: selecting && picked.includes(g.id), meta: PF ? [g.prod, OK.metaOf(g, today())].filter(Boolean).join(' · ') : undefined }, PF ? {} : rowLook(g), o));
643
768
  const budgetOkr = (b) => OK.rowHtml(Object.assign({}, b, { title: b.outcome || b.title }), { budget: true, today: today(), meta: OK.budgetMeta(b, today()), dot: OK.dotOf(Object.assign({ anchor: b.anchor }, b)), drafts: draftsFor(b.id), drawDraft: drHtml, mark: markHtml });
644
769
  function drawGoals() {
645
770
  const G = goalsShown(), T = $('#goalTbl');
@@ -648,11 +773,12 @@ function drawGoals() {
648
773
  $('#goalCards').innerHTML = '';
649
774
  if (dash === TRENDS) { T.innerHTML = bmHtml(true); return; }
650
775
  const D = curDash();
651
- const krDrafts = PF ? [] : looseDrafts().filter((r) => r.kind === 'metric' && r.group === 'Key results');
776
+ const krDrafts = []; // batch 18 item 11: a drafted key result is a row of the drafts table
652
777
  const sub = per ? per.label : '';
653
778
  const head = `<div class="okr-sec"><h2 class="okr-h">Key results</h2><span class="note">${esc(sub)}</span></div>`;
654
779
  if (!M.goals.filter(isKr).length && !krDrafts.length) {
655
- T.innerHTML = head + '<div class="okr-card"><p class="okr-none">No key result is recorded for this workspace.</p></div>' + budgetsHtml(D);
780
+ // the drafts table above says what is drafted: no empty card under it (zero is silence)
781
+ T.innerHTML = PF || !tableRows().length ? head + '<div class="okr-card"><p class="okr-none">No key result is recorded for this workspace.</p></div>' + budgetsHtml(D) : budgetsHtml(D);
656
782
  return;
657
783
  }
658
784
  /* by objective when there is more than one; Portfolio groups by product */
@@ -784,23 +910,32 @@ const historyHtml = (g) => ((g.history || []).length ? (g.history || []).slice()
784
910
  * folds: How I read it, What it counts and History. On dashboards folds under them when the PM keeps a saved dashboard. */
785
911
  function goalBodyHtml(g, o) {
786
912
  const c = g.key ? byKey(g.key) : null, phone = isPhone(), steps = g.type === 'Done or not' && g.steps && g.steps.length;
787
- const chart = steps ? stepsHtml(g) : c ? detailSvg(g, c, phone ? 330 : 470, phone ? 140 : 160) : emptyTrend(g, o.own);
788
- const d = OK.dotOf(g), R = g.reading || {}, prog = R.txt || OK.progressOf(g);
789
- const line = R.line || (d === 'behind' && g.pace && g.pace.sub ? g.pace.sub : '');
913
+ // batch 18 item 11 (GcJ2FirstMonday): one reading is a starting point: the chart waits for the 2nd, and no pace is said before the 3rd
914
+ const first = GC.firstOf(g), wait = first ? GC.firstChart(g) : '';
915
+ const chart = steps ? stepsHtml(g) : c ? detailSvg(g, c, phone ? 330 : 470, phone ? 140 : 160) : wait || emptyTrend(g, o.own);
916
+ const lk = PF ? {} : rowLook(g), d = lk.dot || OK.dotOf(g), R = g.reading || {}, prog = R.txt || OK.progressOf(g);
917
+ // a failed read or a held reading (GcR4Failed, GcR5Held): the number is the last good one, and it says so
918
+ const good = GC.lastGoodSay(g);
919
+ const line = good || (first && d === 'q' ? [first.source, GC.atTxt(first.at)].filter(Boolean).join(' · ') + ' · pace known after 3 readings' : R.line || (d === 'behind' && g.pace && g.pace.sub ? g.pace.sub : ''));
790
920
  const head = `<div class="okr-vh">${OK.dotHtml(d)}<b>${esc(prog || OK.DOT_SAY[d])}</b>${line ? `<span class="note">${esc(line)}</span>` : ''}${PF && g.prod ? `<span class="note">${esc(g.prod)}</span>` : ''}<span class="okr-sp"></span>${OK.avHtml(OK.whoOf(g))}</div>`;
791
921
  const form = !steps && o.adding ? `<form class="ins-mf ins-box" data-rdf><div class="ins-2"><label class="ins-fl">Date<input class="ins-inp" type="date" name="at" value="${esc(M.today || '')}"></label><label class="ins-fl">Value${g.unit ? ' (' + esc(g.unit) + ')' : ''}<input class="ins-inp" name="v" inputmode="decimal" maxlength="16"></label></div><div class="ins-mact"><button type="submit" class="ins-btn sm dark">Add reading</button><button type="button" class="ins-btn sm ghost" data-gx="cancel">Cancel</button><span class="note" data-msg role="status"></span></div></form>` : '';
792
922
  const why = whyOf(g), moves = g.moves || [];
793
923
  const whyCard = why || moves.length ? `<div class="okr-why"><span class="sp" aria-hidden="true">${SV(I.spark)}</span><div>${why ? `<p>${esc(why)}</p>` : ''}${moves.length ? `<div class="ins-mvl">${moves.map(moveRow).join('')}</div>` : ''}</div></div>` : '';
794
924
  const onDash = savedDash().filter((D) => D.charts.includes(g.id)).length;
795
925
  const R0 = g.recipe;
926
+ // batch 18 item 11 (GcR3Goal): how it is counted, where it is read from, how often and the last read are said ONCE, above the chart; the
927
+ // Readings fold keeps the list, and What it counts folds away when the counts say it
928
+ const kr = PF ? '' : GC.krHtml(g, { ticket: heldTicket(g) }), said = !!kr && !!(R0 && R0.connector);
796
929
  const rows = [
797
- { id: 'read', title: 'How I read it', count: R0 && R0.connector ? R0.connector : srcOf(g) === 'Recorded' ? 'typed in' : srcOf(g), open: o.open === 'read', render: () => readHtml(g, o) },
798
- { id: 'counts', title: 'What it counts', count: g.defn ? '' : 'not written yet', render: () => `<p class="note">${esc(g.defn || 'No definition is written for it yet. I write one with how I read it, and you keep it with ✓.')}</p>` },
930
+ said ? { id: 'read', title: 'Readings', count: (g.series || []).length || '', open: o.open === 'read', render: () => readingsHtml(g, o) }
931
+ : { id: 'read', title: 'How I read it', count: R0 && R0.connector ? R0.connector : srcOf(g) === 'Recorded' ? 'typed in' : srcOf(g), open: o.open === 'read', render: () => readHtml(g, o) },
932
+ g.counts && (g.counts.what || g.counts.num_label) ? null : { id: 'counts', title: 'What it counts', count: g.defn ? '' : 'not written yet', render: () => `<p class="note">${esc(g.defn || 'No definition is written for it yet. I write one with how I read it, and you keep it.')}</p>` },
799
933
  { id: 'hist', title: 'History', count: (g.history || []).length || '', render: () => historyHtml(g) },
800
934
  o.own && savedDash().length ? { id: 'dash', title: 'On dashboards', count: onDash, render: () => dashSwitches(g) } : null,
801
935
  ];
802
936
  const ask = `<form class="ins-askf" data-askf><input name="q" maxlength="300" autocomplete="off" placeholder="Ask about this goal" aria-label="Ask about this goal"><button type="submit" class="cz-ib sm solid" aria-label="Ask in Home" title="Ask in Home">${SV(I.up)}</button></form>`;
803
- return head + form + `<div class="ins-gbig">${chart}</div>` + whyCard + window.czViewer.czSections(rows, { key: 'goal' }) + '<p class="note ins-gmsg" data-gmsg role="status"></p>' + ask;
937
+ const failedOrHeld = !!(g.failed || (g.held || []).length);
938
+ return head + form + (failedOrHeld ? kr : '') + `<div class="ins-gbig">${chart}</div>` + (failedOrHeld ? '' : kr) + whyCard + window.czViewer.czSections(rows.filter(Boolean), { key: 'goal' }) + '<p class="note ins-gmsg" data-gmsg role="status"></p>' + ask;
804
939
  }
805
940
  /** The goal as plain text, for Copy as text. */
806
941
  function goalText(g) {
@@ -819,6 +954,8 @@ async function setNotify(g, k) {
819
954
  toast(say, { label: 'Undo', fn: async () => { await pmPost('/api/goals/notify', { ws: goalWs(g), id: goalRid(g), notify: was }); await load(); } });
820
955
  await load();
821
956
  }
957
+ /** The drafted Jira ticket of a goal's held reading (GcR5Held): the row the reading engine named, else an open ticket draft under the goal. */
958
+ const heldTicket = (g) => { const H = (g.held || [])[0]; if (!H) return null; const D = drAll(); return (H.ticket && D.find((r) => r.id === H.ticket)) || D.find((r) => r.goal === g.id && r.kind === 'ticket' && r.state === 'open') || null; };
822
959
  let ovCss = false;
823
960
  function openGoalDetail(id, open0) {
824
961
  let g = goalById(id); if (!g) return;
@@ -826,10 +963,12 @@ function openGoalDetail(id, open0) {
826
963
  const own = goalWs(g) === M.board.ws, st = { open: open0 || '', more: false, adding: false, own };
827
964
  const kr = krId(g);
828
965
  const more = [], stepsGoal = g.type === 'Done or not' && g.steps && g.steps.length;
829
- if (own && g.recipe) more.push({ label: 'Read it now', note: g.recipe.connector || '', on: async () => {
966
+ // ↻ Read now (batch 18 item 11, GcR3Goal): in the header, any time; it files a normal reading and does not move the next scheduled read
967
+ const readNow = async () => {
830
968
  const r = await pmPost('/api/goal-status/read', { ws: goalWs(g), id: goalRid(g) });
831
- toast(r && r.ok === true ? 'Read. The goal shows the new reading.' : (r && r.error) || 'It could not be read. Nothing changed.'); if (r && r.ok === true) await load();
832
- } });
969
+ toast(r && r.ok === true ? 'Reading it now. The goal shows the new reading when it lands; the next read stays ' + ((GC.rhythmOf(g) || {}).long || 'as it was') + '.' : (r && r.error) || 'It could not be read. Nothing changed.');
970
+ if (r && r.ok === true) setTimeout(() => { load(); }, 4000);
971
+ };
833
972
  if (own && !stepsGoal) more.push({ label: 'Add a reading', on: () => { const el = window.czViewer && window.czViewer.body(); st.adding = true; if (el) { el.innerHTML = goalBodyHtml(g, st); const f = el.querySelector('[data-rdf] [name="v"]'); if (f) f.focus(); } } });
834
973
  if (own && M.goals.some((x) => x.id === g.id)) more.push({ label: 'Edit chart', on: () => openChartEdit(g.id) });
835
974
  if (more.length) more.push({ sep: true });
@@ -841,14 +980,29 @@ function openGoalDetail(id, open0) {
841
980
  const moreOf = () => notifyItems().concat(more);
842
981
  const rp = own && !PF ? RI.viewerPress('goal:' + id) : null; // RfA1: a key result's panel makes a report too
843
982
  const subOf = () => [kr, g.targetTxt ? g.targetTxt + (g.byAt ? ' by ' + md(day(g.byAt)) : '') : ''].filter(Boolean).join(' · ');
983
+ const presses = (own && g.recipe && g.recipe.connector ? [{ act: 'gc-read', label: 'Read it now', icon: 'M20 12a8 8 0 1 1-2.3-5.6M20 4v5h-5' }] : []).concat(rp ? [rp] : []);
844
984
  const body = vwOpen({ kind: 'Goal', title: g.title, sub: subOf(), icon: 'goal', id: 'goal:' + id, more: moreOf,
845
- discuss: true, presses: rp ? [rp] : null, onPress: (act) => { if (rp && act === rp.act) rp.run(); },
985
+ discuss: true, presses: presses.length ? presses : null, onPress: (act) => { if (act === 'gc-read') readNow(); else if (rp && act === rp.act) rp.run(); },
846
986
  render: (el) => {
847
987
  el.classList.add('ins-vbody', 'ins-xv');
848
988
  const draw = () => { const top = el.scrollTop; el.innerHTML = goalBodyHtml(g, st); el.scrollTop = top; };
849
989
  const fresh = async (said) => { toast(said); await load(); if (PF) await openPortfolio(); g = goalById(id); if (g) draw(); };
850
990
  draw();
851
991
  el.onclick = async (e) => {
992
+ // batch 18 item 11: a failed read's one fix (reconnect), a held reading's (file it, or its drafted ticket)
993
+ const gx = e.target.closest('[data-gc], [data-okd]');
994
+ if (gx && !gx.disabled) {
995
+ const k = gx.dataset.gc || gx.dataset.okd;
996
+ if (k === 'reconnect') { if (gx.dataset.row) await draftPress('keep', gx.dataset.row, gx); else import('./cozy-settings.js').then((S) => S.openSettings('connectors')).catch(() => {}); return; }
997
+ if (k === 'file-held') {
998
+ gx.disabled = true;
999
+ const r = await pmPost('/api/goal-status/file-held', { ws: goalWs(g), id: goalRid(g), held: gx.dataset.row });
1000
+ if (!r || r.ok !== true) { gx.disabled = false; toast((r && r.error) || 'It could not be filed. Nothing changed.'); return; }
1001
+ await fresh('Filed. It counts as a reading now.'); return;
1002
+ }
1003
+ if (k === 'keep') { await draftPress('keep', gx.dataset.row, gx); g = goalById(id); if (g) draw(); return; }
1004
+ if (k === 'edit') { const t = heldTicket(g); location.assign(homeAsk('goal', 'Change the drafted ticket for ' + g.title + (t ? ' (“' + t.text + '”)' : '') + ': ')); return; }
1005
+ }
852
1006
  const x = e.target.closest('[data-gx], [data-czs-act]'); if (!x || x.disabled) return;
853
1007
  const k = x.dataset.gx || x.dataset.czsAct, msg = el.querySelector('[data-gmsg]');
854
1008
  if (k === 'all') { st.more = true; st.open = 'read'; draw(); }