create-pmos 0.327.0 → 0.329.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 (35) hide show
  1. package/package.json +1 -1
  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 +56 -25
  7. package/workspace/guide/briefing-premium.md +11 -5
  8. package/workspace/guide/docs.md +3 -0
  9. package/workspace/lib/doc-reads-store.js +90 -0
  10. package/workspace/lib/doc-reads.js +128 -0
  11. package/workspace/lib/doc-sync-store.js +1 -1
  12. package/workspace/lib/docs-cli.js +48 -3
  13. package/workspace/lib/insights-premium.js +111 -26
  14. package/workspace/lib/premium-dashboards.js +25 -5
  15. package/workspace/lib/routes-insights-premium.js +19 -4
  16. package/workspace/lib/routes-premium-dashboards.js +12 -1
  17. package/workspace/package-lock.json +2 -2
  18. package/workspace/package.json +1 -1
  19. package/workspace/premium-report-read-test.js +4 -2
  20. package/workspace/premium-studio-chart-test.js +3 -3
  21. package/workspace/premium-studio-report-test.js +1 -1
  22. package/workspace/premium-studio-test.js +4 -4
  23. package/workspace/premium-vw-copy-test.js +133 -0
  24. package/workspace/premium-vw-slides-test.js +8 -4
  25. package/workspace/public/pm/premium-doc-sheet.js +3 -1
  26. package/workspace/public/pm/premium-insights.css +52 -0
  27. package/workspace/public/pm/premium-insights.js +129 -50
  28. package/workspace/public/pm/premium-meeting.js +3 -2
  29. package/workspace/public/pm/premium-vw-copies.js +133 -0
  30. package/workspace/public/pm/premium-vw-copy.css +27 -0
  31. package/workspace/public/premium-insights.html +29 -19
  32. package/workspace/server.js +42 -0
  33. package/workspace/skills/doc-read.skill +32 -0
  34. package/workspace/test-lists/doc-reads.json +5 -0
  35. package/workspace/test-lists/premium-vw-copy.json +12 -0
@@ -12,6 +12,9 @@
12
12
  * pmos docs sync-start <file> google|google-slides|google-sheets|confluence --use pmos|copy [--json] open a sync of one copy (the sync session)
13
13
  * pmos docs sync-finish <sync> --version <v> [--modified-at <t>] [--url <u>] close it: both sides now the same
14
14
  * pmos docs sync-fail <sync> --reason "…" close it: nothing was written, and why
15
+ * pmos docs read-start <address> [--json] open a read of one Google Doc or Confluence page (the read session)
16
+ * pmos docs read-finish <read> [--file <text.md>|-] [--title t] [--revision r] [--modified-at t] record what was read (stdin without --file)
17
+ * pmos docs read-fail <read> --reason "…" close a read: nothing was read, and why
15
18
  *
16
19
  * The same module the Docs place reads (lib/doc-sync-store.js), so a terminal line and a row cannot disagree.
17
20
  * No command writes a document. A check reads; a sync (amended 2026-10-06: the PM presses Use … version for one copy) is
@@ -26,11 +29,12 @@ const path = require('path');
26
29
  const { execFileSync } = require('child_process');
27
30
  const D = require('./doc-sync');
28
31
  const store = require('./doc-sync-store');
32
+ const reads = require('./doc-reads-store');
29
33
  const { parseArgs } = require('./schedule-cli');
30
34
 
31
- const COMMANDS = { docs: ['list', 'link', 'unlink', 'check-start', 'record', 'check-finish', 'find', 'sync-start', 'sync-finish', 'sync-fail'] };
35
+ const COMMANDS = { docs: ['list', 'link', 'unlink', 'check-start', 'record', 'check-finish', 'find', 'sync-start', 'sync-finish', 'sync-fail', 'read-start', 'read-finish', 'read-fail'] };
32
36
  const USAGE = [
33
- 'usage: pmos docs [list|link|unlink|find|check-start|record|check-finish|sync-start|sync-finish|sync-fail] — is each linked document the same as its Google Docs and Confluence copy',
37
+ 'usage: pmos docs [list|link|unlink|find|check-start|record|check-finish|sync-start|sync-finish|sync-fail|read-start|read-finish|read-fail] — is each linked document the same as its Google Docs and Confluence copy',
34
38
  ' pmos docs [list] [--attention] [--json] each linked document and its signal: same, ahead, behind, edited in both',
35
39
  ' pmos docs link <file> <link> link a repository file to a Google Doc or a Confluence page',
36
40
  ' pmos docs unlink <file> google|google-slides|google-sheets|confluence remove that link; the copy is not touched',
@@ -41,6 +45,9 @@ const USAGE = [
41
45
  ' pmos docs sync-start <file> google|google-slides|google-sheets|confluence --use pmos|copy (sync session) open a sync of one copy',
42
46
  ' pmos docs sync-finish <sync> --version <v> [--modified-at <t>] [--url <u>] (sync session) both sides are now the same',
43
47
  ' pmos docs sync-fail <sync> --reason "…" (sync session) nothing was written, and why',
48
+ ' pmos docs read-start <address> (read session) open a read of one Google Doc or Confluence page',
49
+ ' pmos docs read-finish <read> [--file <text.md>|-] [--title t] [--revision r] [--modified-at t] (read session) record the text read (stdin without --file)',
50
+ ' pmos docs read-fail <read> --reason "…" (read session) nothing was read, and why',
44
51
  'Nothing here writes a document. Press Check now, or Use … version on one copy, in Docs.',
45
52
  ];
46
53
  const BOOL = new Set(['json', 'attention', 'help']);
@@ -76,7 +83,12 @@ const ago = (iso, now) => {
76
83
  return `${Math.round(m / 1440)} days ago`;
77
84
  };
78
85
 
79
- async function run(argv, { say = console.log, cwd = process.cwd(), env = process.env, now = Date.now() } = {}) {
86
+ const readStdin = () => {
87
+ if (process.stdin.isTTY) throw new Error('give --file <text.md>, or pipe the text on stdin');
88
+ return fs.readFileSync(0, 'utf8');
89
+ };
90
+
91
+ async function run(argv, { say = console.log, cwd = process.cwd(), env = process.env, now = Date.now(), stdin = readStdin } = {}) {
80
92
  const { pos, flags } = parse(argv.slice(1));
81
93
  const sub = pos[0] || 'list';
82
94
  if (flags.help || sub === 'help') { USAGE.forEach((l) => say(l)); return 0; }
@@ -211,6 +223,39 @@ async function run(argv, { say = console.log, cwd = process.cwd(), env = process
211
223
  if (json) say(JSON.stringify({ ok: true })); else say('✓ Sync closed as failed. Nothing was written.');
212
224
  return 0;
213
225
  }
226
+ if (sub === 'read-start') {
227
+ const address = pos[1];
228
+ if (!address) return fail('usage: pmos docs read-start <address>', 2);
229
+ if (!by) return fail('a read must name who reads: run it in a workspace session, or add --by <profile>');
230
+ const s = reads.readStart(root, { url: address, by, now: new Date(now) });
231
+ if (!s.ok) return fail(s.error);
232
+ if (json) { say(JSON.stringify(s)); return 0; }
233
+ say(`Read ${s.run} · ${s.label} · ${s.url}`);
234
+ return 0;
235
+ }
236
+ if (sub === 'read-finish') {
237
+ const runId = pos[1];
238
+ if (!runId) return fail('usage: pmos docs read-finish <read> [--file <text.md>|-] [--title t] [--revision r] [--modified-at t]', 2);
239
+ if (!by) return fail('a read must name who read: run it in a workspace session, or add --by <profile>');
240
+ let text;
241
+ try { text = flags.file && flags.file !== '-' ? fs.readFileSync(path.resolve(cwd, flags.file), 'utf8') : stdin(); }
242
+ catch (e) { return fail(`could not read the text: ${String((e && e.message) || e).slice(0, 160)}`); }
243
+ const r = reads.readFinish(root, { run: runId, by, text, title: flags.title || null, revision: flags.revision || null,
244
+ modified_at: flags['modified-at'] || null, now: new Date(now) });
245
+ if (!r.ok) return fail(r.error);
246
+ if (json) say(JSON.stringify(r));
247
+ else say(`✓ Read recorded · ${r.chars} characters${r.truncated ? ' (cut to the limit)' : ''}.`);
248
+ return 0;
249
+ }
250
+ if (sub === 'read-fail') {
251
+ const runId = pos[1];
252
+ if (!runId || !flags.reason) return fail('usage: pmos docs read-fail <read> --reason "…"', 2);
253
+ if (!by) return fail('a read must name who ran it: run it in a workspace session, or add --by <profile>');
254
+ const r = reads.readFail(root, { run: runId, by, reason: String(flags.reason), now: new Date(now) });
255
+ if (!r.ok) return fail(r.error);
256
+ if (json) say(JSON.stringify({ ok: true })); else say('✓ Read closed as failed.');
257
+ return 0;
258
+ }
214
259
  return fail(`pmos docs ${sub} is not a command. ${USAGE[0]}`, 2);
215
260
  }
216
261
 
@@ -2,7 +2,7 @@
2
2
  /* lib/insights-premium.js — the premium Insights page's model, built from the KR metric records and the report files the console's Reports tab reads
3
3
  * (initiative briefing-premium-insights).
4
4
  *
5
- * build(facts) → model PURE. facts = { now, board, boards, outcomes, reports, reportsOk, missing[], saved, setups }
5
+ * build(facts) → model PURE. facts = { now, board, boards, outcomes, reports, reportsOk, missing[], saved, setups, pinned, leads }
6
6
  * peekModel() → the last model built, for the agent to find a chart in (null before the first)
7
7
  *
8
8
  * facts come from the routes of lib/routes-c3-strategy.js and lib/routes-reports.js:
@@ -11,10 +11,13 @@
11
11
  * reports GET /api/report → .reports [{ cadence, slot, path, status, issued: { at, by } | null, edited }]
12
12
  * saved lib/premium-dashboards.js list(root, board.id) → [{ id, name, purpose, charts: [KR metric id], main, at }] (briefing-premium-reports D1)
13
13
  * setups GET /api/report-setups → { setups, findings, asks } | null when it could not be read (briefing-premium-reports R1)
14
+ * pinned lib/premium-dashboards.js pinned(root, board.id) → 'all' | a saved id | null (insights-one-list L4)
15
+ * leads { [report path]: the opening sentence of that file } — read by the route; a path left out has none (insights-one-list L6)
14
16
  *
15
17
  * THE RULE THE FILE FOLLOWS (as the other premium models): a number, chip, line or date is made only from a field of a record. A measure with fewer than two
16
18
  * readings gets no chart and says why. The time between two readings is drawn as the time it is, so a gap in a series shows as a gap and never as a zero. No
17
- * forecast is drawn and no cause is given. Run-based series (corrections per 100 runs, merges a week) belong to the Board's Metrics card and are not built here (PRD decision 4). */
19
+ * forecast is drawn and no cause is given. One projection is said in words (initiative insights-one-list L2, amending briefing-premium-insights I6): for a
20
+ * measure short of its target with a target date ahead, a straight line through its last four readings carried to that date. Its method is stated. Run-based series (corrections per 100 runs, merges a week) belong to the Board's Metrics card and are not built here (PRD decision 4). */
18
21
 
19
22
  const MON = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
20
23
  const isoDay = (v) => { const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(v || '')); return m ? Date.UTC(+m[1], +m[2] - 1, +m[3]) : null; };
@@ -22,9 +25,12 @@ const shortDate = (v) => { const t = isoDay(v); if (t === null) return ''; const
22
25
  const clip = (s, n) => { s = String(s == null ? '' : s).replace(/\s+/g, ' ').trim(); return s.length > n ? s.slice(0, n - 1).trimEnd() + '…' : s; };
23
26
  const fin = (v) => typeof v === 'number' && Number.isFinite(v);
24
27
  const r2 = (v) => Math.round(v * 100) / 100;
28
+ const r1 = (v) => Math.round(v * 10) / 10;
25
29
  const num = (v, unit) => { const u = String(unit || '').trim(), s = String(r2(v)); return u ? (/^[A-Za-z]/.test(u) ? s + ' ' + u : s + u) : s; };
26
30
  const CHIP = { ok: ['On its line', 'ok'], drift: ['Behind its line', 'warn'], off: ['Well behind its line', 'bad'] };
27
31
  const MAX_FINDINGS = 3;
32
+ const DAY = 864e5, WEEK = 7 * DAY;
33
+ const PROJ_N = 4; // the projection's line runs through the last four readings (insights-one-list L2)
28
34
  const KR_FILE = 'planning/records/kr-metrics.jsonl';
29
35
 
30
36
  let last = null;
@@ -56,7 +62,7 @@ function chartOf(o) {
56
62
  const rid = clip(o.id, 100);
57
63
  return {
58
64
  key: 'ins:' + rid, id: o.id, title: clip(o.name, 120), sub: [o.pillar, rs.length + ' readings'].filter(Boolean).join(' · '), pillar: o.pillar || '',
59
- unit: u, v: num(now, u), at: shortDate(rs[rs.length - 1].at), target: tgt, targetTxt: tgt !== null ? 'target ' + num(tgt, u) : '', by: o.by ? shortDate(o.by) : '',
65
+ unit: u, v: num(now, u), at: shortDate(rs[rs.length - 1].at), target: tgt, targetTxt: tgt !== null ? 'target ' + num(tgt, u) : '', by: o.by ? shortDate(o.by) : '', byAt: isoDay(o.by) !== null ? String(o.by).slice(0, 10) : null,
60
66
  ty: tgt !== null ? (tgt - lo) / range : null, state: o.status || 'unscored', chip: chip[0], chipKind: chip[1], off: o.status === 'drift' || o.status === 'off', pivot: !!o.pivot,
61
67
  step: r2(step), good, dir, first: rs[0].at, lastAt: rs[rs.length - 1].at, pts, range: [lo, hi],
62
68
  ticks: [shortDate(rs[0].at), shortDate(rs[rs.length - 1].at)],
@@ -85,34 +91,73 @@ function mineOf(m, outcomes) {
85
91
  });
86
92
  }
87
93
 
88
- /** Up to three plain sentences about what stands out, from the series alone. No forecast and no cause. */
89
- function findingsOf(charts) {
94
+ /** The projection of one chart (insights-one-list L2): a straight line through its last four readings (all, when fewer), at the dates they were taken,
95
+ * carried to the record's target date. null when the chart has no target, no target date after its last reading, or has reached its target. */
96
+ function projectionOf(c) {
97
+ if (c.target === null || !c.dir || !c.byAt) return null;
98
+ const P = c.pts.slice(-PROJ_N), a = P[0], z = P[P.length - 1], t0 = isoDay(a.at), t1 = isoDay(z.at), due = isoDay(c.byAt);
99
+ if (due === null || due <= t1 || t1 <= t0) return null;
100
+ if (c.dir > 0 ? z.v >= c.target : z.v <= c.target) return null;
101
+ const perDay = (z.v - a.v) / (t1 - t0) * DAY, atDue = z.v + perDay * (due - t1) / DAY;
102
+ const reaches = c.dir > 0 ? atDue >= c.target : atDue <= c.target, toward = perDay * c.dir > 0;
103
+ const when = toward ? t1 + (c.target - z.v) / perDay * DAY : null;
104
+ return { n: P.length, from: a, now: z.v, perWeek: perDay * 7, atDue, reaches, toward, when, short: Math.abs(c.target - atDue) };
105
+ }
106
+ const amount = (v, u) => String(u).trim() === '%' ? r2(v) + (r2(v) === 1 ? ' point' : ' points') : num(v, u);
107
+ const dayTxt = (t) => { const d = new Date(t); return d.getUTCDate() + ' ' + MON[d.getUTCMonth()] + ' ' + d.getUTCFullYear(); };
108
+
109
+ /** Every finding of one chart, the strongest first. Each is { kind, score, text, why, key, chart }: `text` the headline, `why` one sentence with its numbers.
110
+ * Every number is a reading, the record's target or target date, or the projection said in words. No cause is given. */
111
+ function findingsOfChart(c) {
112
+ const u = c.unit, f = [];
113
+ const move = (a, b) => 'from ' + num(a, u) + ' to ' + num(b, u);
114
+ const prev = c.pts[c.pts.length - 2].v, now = c.pts[c.pts.length - 1].v, at = c.pts[c.pts.length - 1].d;
115
+ const spread = (c.range[1] - c.range[0]) || 1, tg = c.target !== null ? num(c.target, u) : '', by = c.by ? ' by ' + c.by : '';
116
+ const p = projectionOf(c);
117
+ if (c.pivot) f.push({ kind: 'stuck', score: 100, text: c.title + ' has been behind its line at three readings in a row, and the gap is not closing.', why: 'It is at ' + num(now, u) + ' on ' + at + (tg ? ', against a target of ' + tg + by : '') + '.' });
118
+ else if (c.off && c.good === false && c.step !== 0) f.push({ kind: 'worse', score: 90, text: c.title + ' is behind its line, and its last reading moved away from the target (' + move(prev, now) + ').', why: 'Its latest reading is ' + num(now, u) + ' on ' + at + (tg ? ', against a target of ' + tg + by : '') + '.' });
119
+ else if (c.off && c.good) f.push({ kind: 'closing', score: 60, text: c.title + ' is behind its line, and its last reading moved toward the target (' + move(prev, now) + ').', why: 'Its latest reading is ' + num(now, u) + ' on ' + at + (tg ? ', against a target of ' + tg + by : '') + '.' });
120
+ else if (c.off) f.push({ kind: 'off', score: 55, text: c.title + ' is behind its line at ' + num(now, u) + '.', why: tg ? 'The target is ' + tg + by + '.' : 'The record holds no target for it.' });
121
+ else if (c.state === 'ok' && c.good === false && c.step !== 0) f.push({ kind: 'slip', score: 50, text: c.title + ' is on its line, but its last reading moved away from the target (' + move(prev, now) + ').', why: 'The reading was taken on ' + at + (tg ? '. The target is ' + tg + by : '') + '.' });
122
+ if (c.target !== null && c.dir && (c.dir > 0 ? now >= c.target : now <= c.target)) f.push({ kind: 'reached', score: 58, text: c.title + ' has reached its target of ' + tg + '.', why: 'It read ' + num(now, u) + ' on ' + at + '.' });
123
+ if (p && !p.toward) f.push({ kind: 'stall', score: c.pivot ? 101 : 96, text: c.title + ' will miss its ' + tg + ' target on ' + c.by + ' unless it turns.', proj: true,
124
+ why: (c.pivot ? 'It has been behind its line at three readings in a row. ' : '') + 'Over its last ' + p.n + ' readings it went ' + move(p.from.v, p.now) + ', which is ' + (p.perWeek === 0 ? 'no move' : 'away from the target') + '. A straight line through them never reaches ' + tg + '.' });
125
+ else if (p && !p.reaches) f.push({ kind: 'miss', score: 95, text: c.title + ' will miss its ' + tg + ' target on ' + c.by + ' at this pace.', proj: true,
126
+ why: 'It is at ' + num(now, u) + ' and moving ' + amount(Math.abs(p.perWeek), u) + ' a week toward it, so it reaches about ' + num(r1(p.atDue), u) + ' by ' + c.by + ', ' + amount(r1(p.short), u) + ' short.'
127
+ + (p.when && p.when - isoDay(c.lastAt) < 5 * 365 * DAY ? ' At this pace it gets there around ' + dayTxt(p.when) + '.' : '') });
128
+ else if (p) f.push({ kind: 'course', score: 62, text: c.title + ' is short of its target but on course to reach ' + tg + by + '.', proj: true,
129
+ why: 'It is at ' + num(now, u) + ' and moving ' + amount(Math.abs(p.perWeek), u) + ' a week toward it.' });
130
+ if (Math.abs(now - prev) / spread >= 0.4 && !f.some((x) => x.score >= 90)) f.push({ kind: 'move', score: 70, text: c.title + ' moved ' + move(prev, now) + ' in one reading.', why: 'That is ' + Math.round(Math.abs(now - prev) / spread * 100) + '% of the range its readings span. The reading was taken on ' + at + '.' });
131
+ f.sort((a, b) => b.score - a.score);
132
+ return f.map((x) => Object.assign(x, { key: c.key, chart: c.key }));
133
+ }
134
+
135
+ /** The strongest finding of each chart, strongest first. `max` caps the list (three on the page). */
136
+ function findingsOf(charts, max = MAX_FINDINGS) {
90
137
  const out = [];
91
- for (const c of charts) {
92
- const u = c.unit, f = [];
93
- const move = (a, b) => 'from ' + num(a, u) + ' to ' + num(b, u);
94
- const prev = c.pts[c.pts.length - 2].v, now = c.pts[c.pts.length - 1].v;
95
- const spread = (c.range[1] - c.range[0]) || 1;
96
- if (c.pivot) f.push({ kind: 'stuck', score: 100, text: c.title + ' has been behind its line at three readings in a row, and the gap is not closing.' });
97
- else if (c.off && c.good === false && c.step !== 0) f.push({ kind: 'worse', score: 90, text: c.title + ' is behind its line, and its last reading moved away from the target (' + move(prev, now) + ').' });
98
- else if (c.off && c.good) f.push({ kind: 'closing', score: 60, text: c.title + ' is behind its line, and its last reading moved toward the target (' + move(prev, now) + ').' });
99
- else if (c.off) f.push({ kind: 'off', score: 55, text: c.title + ' is behind its line at ' + num(now, u) + '.' });
100
- else if (c.state === 'ok' && c.good === false && c.step !== 0) f.push({ kind: 'slip', score: 50, text: c.title + ' is on its line, but its last reading moved away from the target (' + move(prev, now) + ').' });
101
- if (c.target !== null && c.dir && (c.dir > 0 ? now >= c.target : now <= c.target)) f.push({ kind: 'reached', score: 58, text: c.title + ' has reached its target of ' + num(c.target, u) + '.' });
102
- if (Math.abs(now - prev) / spread >= 0.4 && !(f[0] && f[0].score >= 90)) f.push({ kind: 'move', score: 70, text: c.title + ' moved ' + move(prev, now) + ' in one reading.' });
103
- f.sort((a, b) => b.score - a.score);
104
- if (f[0]) out.push(Object.assign(f[0], { key: c.key, chart: c.key }));
105
- }
138
+ for (const c of charts) { const f = findingsOfChart(c); if (f[0]) out.push(f[0]); }
106
139
  out.sort((a, b) => b.score - a.score);
107
- return out.slice(0, MAX_FINDINGS);
140
+ return out.slice(0, max);
141
+ }
142
+
143
+ /** A dashboard's insight (insights-one-list L4, L6): its charts' findings, strongest first, at most three. The page shows the first; the pinned card skips
144
+ * the one the page already leads with. `calm` when no chart has a finding. */
145
+ function dashInsightOf(L) {
146
+ if (!L.length) return { finds: [], calm: false, none: true };
147
+ const finds = findingsOf(L, 3).map(({ kind, text, why, chart, proj }) => ({ kind, text, why, chart, proj: !!proj }));
148
+ return { finds, calm: !finds.length, none: false, calmText: L.some((c) => c.target !== null) ? 'Nothing stands out here. No measure moved much, and none is far behind its line.' : 'Nothing stands out here. No measure on it has a target.' };
108
149
  }
109
150
 
110
- function reportRows(reports) {
111
- return (reports || []).slice().sort((a, b) => String(b.slot).localeCompare(String(a.slot)) || String(a.cadence).localeCompare(String(b.cadence))).slice(0, 12).map((r) => {
151
+ const REPORTS_MAX = 60;
152
+ /** The report files, newest first. `lead` is the opening sentence of the file as the route read it (insights-one-list L6), '' when it has none. */
153
+ function reportRows(reports, leads) {
154
+ const L = leads || {};
155
+ return (reports || []).slice().sort((a, b) => String(b.slot).localeCompare(String(a.slot)) || String(a.cadence).localeCompare(String(b.cadence))).slice(0, REPORTS_MAX).map((r) => {
112
156
  const issued = !!r.issued;
113
157
  return {
114
158
  key: 'rep:' + r.cadence + ':' + r.slot, cadence: r.cadence, slot: r.slot, date: shortDate(r.slot), state: issued ? 'issued' : r.status === 'draft' ? 'draft' : 'file',
115
159
  stateLabel: issued ? 'Issued' + (r.issued.at ? ' ' + shortDate(r.issued.at) : '') : r.status === 'draft' ? 'Draft' : 'Report file', path: r.path || '',
160
+ lead: typeof L[r.path] === 'string' ? clip(L[r.path], 240) : '',
116
161
  };
117
162
  });
118
163
  }
@@ -169,6 +214,42 @@ function proposalOf(p) {
169
214
  return { name: p.name ? clip(p.name, 120) : '', rows };
170
215
  }
171
216
 
217
+ /** Each setup's latest report file (a row whose cadence is the setup's id; the rows are newest first), so its row can quote that file's opening sentence. */
218
+ function latestOf(su, rows) {
219
+ for (const s of su.setups) { const r = rows.find((x) => x.cadence === s.id); s.latest = r ? { key: r.key, date: r.date, path: r.path, lead: r.lead } : null; }
220
+ return su;
221
+ }
222
+
223
+ /** The page's insight (insights-one-list L1): the strongest finding across the board's measures with its reason, up to two more, and the counts it rests on.
224
+ * With no chart it says why there is no insight, and makes no number. */
225
+ function insightOf(charts, findings, total) {
226
+ if (!charts.length) return { none: true, text: total ? 'There is no insight yet. No KR metric holds two readings.' : 'There is no insight yet. No KR metric is recorded for this workspace.',
227
+ why: total ? 'PMOS draws an insight from the readings of your KR metrics. A measure needs two readings before it has a series.' : 'PMOS draws an insight from the readings of your KR metrics. Add one where the KR metrics are kept, and it shows here after two readings.' };
228
+ const last = charts.map((c) => c.lastAt).sort().pop(), off = charts.filter((c) => c.off).length;
229
+ const head = findings[0] || null;
230
+ return { none: false, off, total: charts.length, asOf: shortDate(last), calm: !head,
231
+ text: head ? head.text : charts.some((c) => c.target !== null) ? 'Nothing stands out. No measure moved much, and none is far behind its line.' : 'Nothing stands out. No measure here has a target, so the series can only be described.',
232
+ why: head ? head.why : '', chart: head ? head.chart : null, kind: head ? head.kind : 'calm', proj: !!(head && head.proj),
233
+ more: findings.slice(1, 3).map((x) => ({ text: x.text, chart: x.chart })) };
234
+ }
235
+
236
+ /** The opening sentence of a report file (insights-one-list L6): the first prose paragraph after the frontmatter, past headings, lists, tables, quotes, code
237
+ * and comments, cut at its first sentence end and clipped. '' when the file holds no prose. PURE. The page marks it as quoted from the file. */
238
+ function leadOf(text) {
239
+ let t = String(text || '').replace(/\r/g, '');
240
+ if (/^---\n/.test(t)) { const e = t.indexOf('\n---', 4); t = e < 0 ? '' : t.slice(e + 4); }
241
+ t = t.replace(/<!--[\s\S]*?-->/g, '').replace(/```[\s\S]*?```/g, '');
242
+ for (const para of t.split(/\n\s*\n/)) {
243
+ const lines = para.split('\n').map((x) => x.trim()).filter(Boolean);
244
+ if (!lines.length || lines.some((x) => /^(#|[-*+] |\d+[.)] |\||>|<|!\[)/.test(x))) continue;
245
+ const prose = lines.join(' ').replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/[*_`]{1,3}([^*_`]+)[*_`]{1,3}/g, '$1').replace(/\s+/g, ' ').trim();
246
+ if (prose.length < 12) continue;
247
+ const m = /^(.+?[.!?])(\s+(?=[A-Z0-9"“(])|$)/.exec(prose);
248
+ return clip(m ? m[1] : prose, 220);
249
+ }
250
+ return '';
251
+ }
252
+
172
253
  function build(facts) {
173
254
  const f = facts || {};
174
255
  const outcomes = f.outcomes || [], missing = (f.missing || []).slice();
@@ -185,7 +266,9 @@ function build(facts) {
185
266
  const dash = (id, name, L) => ({ id, name, keys: L.map((c) => c.key), total: L.length, off: offOf(L), chip: !L.length ? '' : offOf(L) ? offOf(L) + ' off its line' : 'On their lines' });
186
267
  const dashboards = [dash('all', 'All measures', charts)].concat(savedOf(f.saved, outcomes, charts.concat(mine), mineAll), pillars.length > 1 ? pillars.map((p) => dash('p:' + p, p, charts.filter((c) => c.pillar === p))) : []);
187
268
  const findings = findingsOf(charts);
188
- const rep = reportRows(f.reports);
269
+ const rep = reportRows(f.reports, f.leads);
270
+ for (const d of dashboards) Object.assign(d, { insight: dashInsightOf(d.keys.map((k) => charts.concat(mine).find((c) => c.key === k)).filter(Boolean)) });
271
+ const pin0 = f.pinned !== undefined ? f.pinned : ((f.saved || []).find((d) => d.main) || {}).id, pinned = pin0 && dashboards.some((d) => d.id === pin0) ? pin0 : null;
189
272
  const off = offOf(charts);
190
273
  const board = f.board || {};
191
274
  const model = {
@@ -194,7 +277,9 @@ function build(facts) {
194
277
  charts, mine, mineGone, mineSaved: mineAll, noSeries, dashboards, rows: charts,
195
278
  findings: findings.length ? findings : [{ kind: 'calm', key: null, text: charts.length ? (charts.some((c) => c.target !== null) ? 'Nothing stands out. No measure moved much, and none is far behind its line.' : 'Nothing stands out. No measure here has a target, so the series can only be described.') : '' }],
196
279
  calm: !findings.length && charts.length > 0,
197
- reports: Object.assign({ rows: rep, ok: f.reportsOk !== false, counts: { draft: rep.filter((r) => r.state === 'draft').length, issued: rep.filter((r) => r.state === 'issued').length }, missing: f.reportsOk === false }, setupsOf(f.setups, f.now)),
280
+ reports: Object.assign({ rows: rep, ok: f.reportsOk !== false, counts: { draft: rep.filter((r) => r.state === 'draft').length, issued: rep.filter((r) => r.state === 'issued').length }, missing: f.reportsOk === false }, latestOf(setupsOf(f.setups, f.now), rep)),
281
+ insight: insightOf(charts, findings, outcomes.length),
282
+ pinned,
198
283
  measures: outcomes.map((o) => ({ id: o.id, title: clip(o.name, 120), pillar: o.pillar || '', charted: charts.some((c) => c.id === o.id) })),
199
284
  empty: !outcomes.length ? 'No KR metric is recorded for this workspace, so there is nothing to chart. Add one where the KR metrics are kept.' : !charts.length ? 'No KR metric holds two readings yet, so nothing is drawn.' : '',
200
285
  dock: { needs: off, label: off === 1 ? 'measure off its line' : 'measures off their line', next: findings[0] && findings[0].chart ? (charts.find((c) => c.key === findings[0].chart) || {}).title || null : null },
@@ -204,4 +289,4 @@ function build(facts) {
204
289
  return model;
205
290
  }
206
291
 
207
- module.exports = { build, peekModel, chartOf, mineOf, findingsOf, shortDate, num };
292
+ module.exports = { build, peekModel, chartOf, mineOf, findingsOf, findingsOfChart, projectionOf, leadOf, shortDate, num };
@@ -8,10 +8,13 @@
8
8
  * fold(lines) → { [board]: [{ id, board, name, purpose, charts, main, at }] } PURE
9
9
  * list(root, board) → the dashboards of one board, the main one first, then in the order they were made
10
10
  * save(root, input, actor, { now, known }) → { ok: true, dashboard, dashboards } | { ok: false, status, error }
11
+ * pinned(root, board) → the id of the board's pinned dashboard ('all' for All measures, or a saved id) | null
12
+ * pin(root, input, actor, { now }) → { ok: true, pinned } | { ok: false, status, error } input = { board, id: 'all' | saved id | null }
11
13
  *
12
14
  * THE LEDGER. Lines { v: 1, ev: save | remove, id, board, name, purpose, charts, main, actor, at }. `board` is the board's id in the workspace whose
13
15
  * state folder holds the file. `charts` is an ordered list of KR metric ids. The fold keeps the last save of each id and drops an id once it is removed.
14
- * One dashboard per board is main: the latest save that says main wins, and the others read as not main. The file is never rewritten. A torn line, or one
16
+ * One dashboard per board is main (the pinned one, initiative insights-one-list L4): the latest save that says main, or the latest `pin` line, wins, and the
17
+ * others read as not main. A `pin` line { v, ev: 'pin', board, id, actor, at } names 'all' (All measures), a saved id, or null (nothing pinned). The file is never rewritten. A torn line, or one
15
18
  * without an id and a board, is skipped. This store is the premium page's own: the console's dashboard layouts (lib/report-dashboards.js) are not touched.
16
19
  */
17
20
  const fs = require('fs');
@@ -39,7 +42,7 @@ function readLines(file) {
39
42
  const out = [];
40
43
  for (const raw of text.split('\n')) {
41
44
  if (!raw.trim()) continue;
42
- try { const l = JSON.parse(raw); if (isObj(l) && (l.ev === 'save' || l.ev === 'remove') && typeof l.id === 'string' && typeof l.board === 'string') out.push(l); } catch { /* a torn line is skipped */ }
45
+ try { const l = JSON.parse(raw); if (isObj(l) && typeof l.board === 'string' && (((l.ev === 'save' || l.ev === 'remove') && typeof l.id === 'string') || (l.ev === 'pin' && (l.id === null || typeof l.id === 'string')))) out.push(l); } catch { /* a torn line is skipped */ }
43
46
  }
44
47
  return out;
45
48
  }
@@ -73,11 +76,13 @@ function check(input) {
73
76
 
74
77
  /** Every board's dashboards after the ledger's lines, in order. PURE. The main one of a board is the last one saved with main; a later save of that
75
78
  * same dashboard without main, or its removal, leaves the board with none. */
76
- function fold(lines) {
79
+ function fold(lines) { return walk(lines).out; }
80
+ function walk(lines) {
77
81
  const byId = new Map(); // id → dashboard; `first` keeps the order they were first made
78
82
  const mainOf = new Map(); // board → id
79
83
  let made = 0;
80
84
  for (const l of lines || []) {
85
+ if (l.ev === 'pin') { if (l.id === null) mainOf.delete(l.board); else mainOf.set(l.board, l.id); continue; }
81
86
  const prev = byId.get(l.id);
82
87
  if (prev && prev.board !== l.board) continue; // an id never moves between boards
83
88
  if (l.ev === 'remove') { byId.delete(l.id); if (mainOf.get(l.board) === l.id) mainOf.delete(l.board); continue; }
@@ -91,10 +96,25 @@ function fold(lines) {
91
96
  .sort((a, z) => (z.main - a.main) || (a.first - z.first))
92
97
  .map(({ id, board, name, purpose, charts, main, at }) => ({ id, board, name, purpose, charts, main, at }));
93
98
  }
94
- return out;
99
+ return { out, mainOf };
95
100
  }
96
101
 
97
102
  const list = (root, board) => fold(readLines(ledgerFile(root)))[board] || [];
103
+ const pinned = (root, board) => walk(readLines(ledgerFile(root))).mainOf.get(board) || null;
104
+
105
+ /** Pin a dashboard to the top of Insights, or unpin (id null). 'all' is All measures; any other id must be a saved dashboard of the board. */
106
+ function pin(root, input, actor, { now } = {}) {
107
+ const i = isObj(input) ? input : {};
108
+ const board = typeof i.board === 'string' ? i.board : '';
109
+ if (!ID_RE.test(board)) return refuse(400, 'Name the board the dashboard belongs to.');
110
+ const id = i.id == null || i.id === '' ? null : i.id;
111
+ if (id !== null && (typeof id !== 'string' || !ID_RE.test(id))) return refuse(400, 'That dashboard id is not valid.');
112
+ if (id !== null && id !== 'all' && !list(root, board).some((d) => d.id === id)) return refuse(404, 'That dashboard is not on this board.');
113
+ const file = ledgerFile(root), t = now == null ? Date.now() : now;
114
+ fs.mkdirSync(path.dirname(file), { recursive: true });
115
+ fs.appendFileSync(file, JSON.stringify({ v: 1, ev: 'pin', board, id, actor: actor || null, at: new Date(t).toISOString() }) + '\n');
116
+ return { ok: true, pinned: pinned(root, board) };
117
+ }
98
118
 
99
119
  /** THE SINGLE WRITER of premium-dashboards.jsonl. `v`, `id` (for a new one) and `at` are set here.
100
120
  * known = { charts: Set of KR metric ids of the workspace } — a chart outside it is refused. */
@@ -124,4 +144,4 @@ function save(root, input, actor, { now, known } = {}) {
124
144
  return { ok: true, dashboard: v.remove ? null : after.find((d) => d.id === line.id) || null, dashboards: after };
125
145
  }
126
146
 
127
- module.exports = { NAME_MAX, PURPOSE_MAX, CHARTS_MAX, ADVISED_MAX, ledgerFile, readLines, check, fold, list, save };
147
+ module.exports = { NAME_MAX, PURPOSE_MAX, CHARTS_MAX, ADVISED_MAX, ledgerFile, readLines, check, fold, list, pinned, pin, save };
@@ -8,7 +8,8 @@
8
8
  * premium-studio-chart adds the board's saved charts (lib/premium-charts.js list).
9
9
  * briefing-premium-reports adds the board's saved dashboards (lib/premium-dashboards.js list) and the workspace's GET /api/report-setups answer
10
10
  * (setups, findings, asks). That GET is the console's own read: like the console, it may move old dashboard schedules into recurring reports once
11
- * per repository. This route itself writes nothing. The page's presses post to /api/report-setups/* and /api/premium-dashboards/save. */
11
+ * per repository. insights-one-list adds the pinned dashboard (lib/premium-dashboards.js pinned) and the opening sentence of each report file, read here
12
+ * from the workspace's repository. This route itself writes nothing. The page's presses post to /api/report-setups/* and /api/premium-dashboards/save. */
12
13
  const Insights = require('./insights-premium.js');
13
14
  const boards = require('./routes-boards.js');
14
15
  const strategy = require('./routes-c3-strategy.js');
@@ -26,6 +27,19 @@ async function via(mod, pathAndQuery, req, ctx) {
26
27
  const handled = await mod.handle({ method: 'GET', headers: (req && req.headers) || {} }, {}, u, c);
27
28
  return handled === false ? { status: 404, body: null } : out;
28
29
  }
30
+ /** The opening sentence of each listed report file (insights-one-list L6), read from the workspace's repository. A file that cannot be read has none. */
31
+ const LEADS_MAX = 60;
32
+ function leadsOf(ctx, ws, list) {
33
+ const out = {};
34
+ let root = null;
35
+ try { root = require('path').resolve(ctx.getWs(ws).root); } catch { return out; }
36
+ for (const r of list.slice().sort((a, b) => String(b.slot).localeCompare(String(a.slot))).slice(0, LEADS_MAX)) {
37
+ const rel = String(r.path || '');
38
+ if (!rel || rel.includes('..') || require('path').isAbsolute(rel)) continue;
39
+ try { out[rel] = Insights.leadOf(require('fs').readFileSync(require('path').join(root, rel), 'utf8').slice(0, 20000)); } catch { /* an unreadable file has no lead */ }
40
+ }
41
+ return out;
42
+ }
29
43
  const qs = (o) => '?' + Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
30
44
 
31
45
  module.exports = {
@@ -49,16 +63,17 @@ module.exports = {
49
63
  } catch (e) { return fail('the KR metric records could not be read: ' + ((e && e.message) || e)); }
50
64
  const reportsOk = !!(rp.body && rp.body.ok !== false);
51
65
  const missing = reportsOk ? [] : ['reports'];
52
- let saved = [], mine = [];
53
- if (pick && pick.id) { try { saved = PD.list(require('path').resolve(ctx.getWs(pick.ws).root), pick.id); } catch { missing.push('dashboards'); } }
66
+ let saved = [], mine = [], pinned = null;
67
+ if (pick && pick.id) { try { const root = require('path').resolve(ctx.getWs(pick.ws).root); saved = PD.list(root, pick.id); pinned = PD.pinned(root, pick.id); } catch { missing.push('dashboards'); } }
54
68
  if (pick && pick.id) { try { mine = require('./premium-charts.js').list(require('path').resolve(ctx.getWs(pick.ws).root), pick.id); } catch { missing.push('saved charts'); } }
55
69
  const su = await via(setups, '/api/report-setups' + q, req, ctx).catch(() => ({ status: 500, body: null }));
56
70
  const setupsOk = su.status === 200 && !!su.body && Array.isArray(su.body.setups);
57
71
  if (!setupsOk) missing.push('report setups');
72
+ const leads = reportsOk ? leadsOf(ctx, ws, rp.body.reports || []) : {};
58
73
  const model = Insights.build({
59
74
  now: Date.now(), board: pick ? { ws: pick.ws, id: pick.id, name: pick.name } : { ws, id: null, name: 'Insights' }, boards: all.map((x) => ({ ws: x.ws, id: x.id, name: x.name })),
60
75
  outcomes, reports: reportsOk ? rp.body.reports || [] : [], reportsOk, missing, saved, mine,
61
- setups: setupsOk ? su.body : null,
76
+ setups: setupsOk ? su.body : null, pinned, leads,
62
77
  });
63
78
  ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
64
79
  return true;
@@ -4,6 +4,9 @@
4
4
  * POST /api/premium-dashboards/save { ws, board, id?, name, purpose, charts, main, remove? } → { ok, dashboard, dashboards }
5
5
  * one `save` or `remove` line in <state>/premium-dashboards.jsonl (lib/premium-dashboards.js, the one writer)
6
6
  *
7
+ * POST /api/premium-dashboards/pin { ws, board, id: 'all' | saved id | null } → { ok, pinned } (initiative insights-one-list L4)
8
+ * one `pin` line in the same ledger: the dashboard shown at the top of Insights, and nowhere else
9
+ *
7
10
  * The page reads the dashboards through GET /api/insights-premium, so this module has no GET.
8
11
  *
9
12
  * WHO WRITES. The POST refuses a request that carries an agent session header (403), as routes-custom-docs.js does, and passes pm-guard
@@ -33,7 +36,8 @@ function krIds(ctx, ws) {
33
36
 
34
37
  async function handle(req, res, url, ctx) {
35
38
  const send = (r) => { ctx.json(res, r.body, r.status); return true; };
36
- if (url.pathname !== '/api/premium-dashboards/save') return send(bad(404, 'no such premium-dashboards route'));
39
+ const isPin = url.pathname === '/api/premium-dashboards/pin';
40
+ if (url.pathname !== '/api/premium-dashboards/save' && !isPin) return send(bad(404, 'no such premium-dashboards route'));
37
41
  if (req.method !== 'POST') return send(bad(405, 'POST only'));
38
42
  const read = await ctx.readJson(req);
39
43
  if (!read.ok) return send(bad(400, 'the body is not JSON'));
@@ -43,6 +47,13 @@ async function handle(req, res, url, ctx) {
43
47
  if (!g.ok) return send(bad(g.status, g.error));
44
48
  const w = wsOf(ctx, text(body.ws));
45
49
  if (!w) return send(bad(404, 'no such workspace'));
50
+ if (isPin) {
51
+ const ids = boardIds(ctx, w);
52
+ if (!ids) return send(bad(503, 'The boards could not be read. Try again in a moment.'));
53
+ if (!ids.has(text(body.board))) return send(bad(404, 'no such board in this workspace'));
54
+ const r = PD.pin(w.root, body, g.actor, { now: Date.now() });
55
+ return send(r.ok ? { status: 200, body: { ok: true, pinned: r.pinned } } : bad(r.status, r.error));
56
+ }
46
57
  const c = PD.check(body);
47
58
  if (!c.ok) return send(bad(c.status, c.error));
48
59
  const ids = boardIds(ctx, w);
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.327.0",
3
+ "version": "0.329.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.327.0",
9
+ "version": "0.329.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.327.0",
3
+ "version": "0.329.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -96,8 +96,10 @@ fs.writeFileSync(path.join(base, 'q3-deck.png'), PNG);
96
96
  const bigTitle = () => p.evaluate(() => { const h = document.querySelector('#rdSlide h3'); return h ? h.textContent : (document.querySelector('#rdSlide iframe') ? 'frame' : ''); });
97
97
  const say = async (t) => { await p.fill('#rdIn', t); await p.press('#rdIn', 'Enter'); };
98
98
  await p.goto(BASE + '/premium-insights.html');
99
- await until(() => p.evaluate(() => document.querySelectorAll('#repDocs [data-rep]').length === 2));
100
- const rowSel = (slot) => `#repDocs [data-rep="rep:${CAD}:${slot}"]`;
99
+ await until(() => p.evaluate(() => !!document.querySelector('#listSeg [data-f="rep"]')));
100
+ await p.click('#listSeg [data-f="rep"]'); // the one list (insights-one-list L5): the Reports filter holds the report files
101
+ await until(() => p.evaluate(() => document.querySelectorAll('#listRows [data-rep]').length === 2));
102
+ const rowSel = (slot) => `#listRows [data-rep="rep:${CAD}:${slot}"]`;
101
103
 
102
104
  /* O: a document row opens the reader on the page */
103
105
  await tap(rowSel('2026-10-12'));
@@ -64,7 +64,7 @@ const model = async () => (await (await fetch(BASE + '/api/insights-premium')).j
64
64
  const pv = () => p.evaluate(() => { const t = document.querySelector('#stPv .mt1'); return t ? { cls: t.className, title: t.querySelector('.mlab').firstChild.textContent, val: (t.querySelector('.mval') || {}).textContent, bars: [...t.querySelectorAll('.bw i')].map((i) => parseFloat(i.style.height)), foot: (t.querySelector('.mfoot') || {}).textContent || '' } : null; });
65
65
  const checksTxt = () => p.evaluate(() => (document.querySelector('#stCk .suckb b') || {}).textContent || '');
66
66
  const tap = (sel) => p.$eval(sel, (b) => b.click());
67
- const open = async (sel) => { await p.click(sel); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#oMain .stu'))); await sleep(300); };
67
+ const open = async (sel) => { if (sel === '#pdNew' || sel === '#repNew') await p.click('#listNew'); await p.click(sel); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#oMain .stu'))); await sleep(300); };
68
68
  const mode = () => p.evaluate(() => (document.querySelector('#oMain .stmd [aria-pressed="true"]') || {}).textContent || '');
69
69
 
70
70
  /* O: New chart opens the Studio in Chart mode */
@@ -136,8 +136,8 @@ const model = async () => (await (await fetch(BASE + '/api/insights-premium')).j
136
136
  await tap('#oMain [data-st="save"]');
137
137
  await until(async () => (await model()).dashboards.some((d) => d.saved && d.name === 'Weekly'));
138
138
  // the Studio has closed and the page has drawn the new dashboard; Your charts is under All measures
139
- await until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#dashTabs [data-d="all"]')));
140
- await p.$eval('#dashTabs [data-d="all"]', (b) => b.click());
139
+ await until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on') && document.querySelector('#hDash').textContent === 'Weekly' && !!document.querySelector('#repBody [data-d="all"]')));
140
+ await p.$eval('#repBody [data-d="all"]', (b) => b.click());
141
141
  await until(() => p.evaluate((id) => !!document.querySelector(`#dashBody [data-ced="${id}"]`), cid));
142
142
  await p.$eval(`#dashBody [data-ced="${cid}"]`, (b) => b.click());
143
143
  await until(async () => await mode() === 'Chart');
@@ -100,7 +100,7 @@ const model = async () => (await (await fetch(BASE + '/api/insights-premium')).j
100
100
  const cta = () => p.evaluate(() => { const b = document.querySelector('#stFt [data-st="save"]'); return b ? b.textContent + (b.disabled ? ':off' : ':on') : ''; });
101
101
 
102
102
  /* O: New report opens the Studio in Report mode */
103
- await p.click('#repNew');
103
+ await p.click('#listNew'); await p.click('#repNew');
104
104
  await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#oMain .stu')));
105
105
  ok('O1 New report opens the Studio in Report mode, with the brief of the mockup', await mode() === 'Report' && await chipv('title') === bname + ' weekly report' && await chipv('purpose') === 'Not set'
106
106
  && await chipv('aud') === 'The team' && await chipv('out') === 'Google Doc' && await chipv('sched') === 'Weekly, Mondays at 09:00' && await chipv('from') === 'Your work' && await chipv('secs') === '7', [await mode(), await chipv('title'), await chipv('sched')].join());
@@ -60,7 +60,7 @@ const saved = async () => { const j = await (await fetch(BASE + '/api/insights-p
60
60
  const tiles = () => p.evaluate(() => [...document.querySelectorAll('#stPv .mch .mlab')].map((e) => e.firstChild.textContent));
61
61
  const checksTxt = () => p.evaluate(() => (document.querySelector('#stCk .suckb b') || {}).textContent || '');
62
62
  const tap = (sel) => p.$eval(sel, (b) => b.click());
63
- const open = async (sel) => { await p.click(sel); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#oMain .stu'))); await sleep(300); };
63
+ const open = async (sel) => { if (sel === '#pdNew' || sel === '#repNew') await p.click('#listNew'); await p.click(sel); await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#oMain .stu'))); await sleep(300); };
64
64
  const shut = async () => { for (let i = 0; i < 2 && await p.evaluate(() => document.querySelector('#dlg').classList.contains('on')); i++) { await p.keyboard.press('Escape'); await sleep(150); } };
65
65
 
66
66
  /* O0: the bar's Chat button opens the Studio on the dashboard shown (premium-topbar: the Studio is this page's chat) */
@@ -135,7 +135,7 @@ const saved = async () => { const j = await (await fetch(BASE + '/api/insights-p
135
135
 
136
136
  /* S: save, read back, edit, remove */
137
137
  await tap('#oMain [data-st="save"]');
138
- ok('S1 Save closes the Studio and the page draws the saved dashboard as the main one', await until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on') && [...document.querySelectorAll('#dashTabs button')].some((b) => b.textContent === 'Partner review · Main' && b.getAttribute('aria-pressed') === 'true'))));
138
+ ok('S1 Save closes the Studio and the page draws the saved dashboard as the main one', await until(() => p.evaluate(() => !document.querySelector('#dlg').classList.contains('on') && document.querySelector('#hDash').textContent === 'Partner review' && document.querySelector('#dashTag').textContent === 'Pinned')));
139
139
  let S = await saved();
140
140
  ok('S2 the ledger holds the name, purpose, order and Main', S.length === 1 && S[0].name === 'Partner review' && S[0].purpose === 'the Monday partner review' && S[0].charts.join() === 'krm-a,krm-t' && S[0].main, JSON.stringify(S));
141
141
  await open('#pdEdit');
@@ -166,10 +166,10 @@ const saved = async () => { const j = await (await fetch(BASE + '/api/insights-p
166
166
  for (const theme of ['light', 'dark']) {
167
167
  const c2 = await browser.newContext({ viewport: { width: 390, height: 844 }, colorScheme: theme }), q = await c2.newPage();
168
168
  await q.goto(BASE + '/premium-insights.html');
169
- await until(() => q.evaluate(() => !!document.querySelector('#pdNew')));
169
+ await until(() => q.evaluate(() => !!document.querySelector('#crAsk') && !!document.querySelector('#listRows .dmr')));
170
170
  const pill = await q.evaluate(() => { const b = document.querySelector('#crAsk'), r = b.getBoundingClientRect(); return { txt: b.textContent.trim(), w: r.width, h: r.height, right: r.right, vw: innerWidth, vis: !!b.offsetParent }; });
171
171
  ok(`F0 at 390 px (${theme}) the Chat button shows, fits the width and is 44 px`, pill.vis && pill.right <= pill.vw && Math.round(pill.h) >= 44 && Math.round(pill.w) >= 44, JSON.stringify(pill));
172
- await q.click('#pdNew'); await until(() => q.evaluate(() => !!document.querySelector('#oMain .stu'))); await sleep(400);
172
+ await q.click('#listNew'); await q.click('#pdNew'); await until(() => q.evaluate(() => !!document.querySelector('#oMain .stu'))); await sleep(400);
173
173
  // measured once the dialog has finished opening: its rise animation scales the targets while it runs
174
174
  const measure = () => q.evaluate(() => {
175
175
  const sm = [...document.querySelectorAll('#oMain .stu button')].filter((b) => b.offsetParent).filter((b) => { const r = b.getBoundingClientRect(); return r.height < 44 || r.width < 44; }).map((b) => (b.dataset.st || b.textContent) + ':' + Math.round(b.getBoundingClientRect().width) + 'x' + Math.round(b.getBoundingClientRect().height));