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
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* premium-vw-copy-test.js — a Confluence page or Google Doc in the premium viewer (initiative premium-viewer, R11; planning/prd/premium-viewer-prd.md).
4
+ * Serves the real Briefing page, opens a row's dialog, then opens the copy view with the /api/docs, /api/doc and /api/docs/read routes answered by stand-ins.
5
+ * R11 a linked copy that matches · a copy that changed (dimmed, Use with Undo) · a link-only page (Read it now, then the read text) · R7 floors at 390px, dark
6
+ * Every wait polls the page; no fixed sleep stands in for a state. */
7
+ const path = require('path');
8
+ const { spawn } = require('child_process');
9
+ const { findBrowser } = require('./lib/find-browser');
10
+ const T = require('./test-run').configure({ name: 'premium-vw-copy' });
11
+ const B = require('./lib/briefing-premium.js');
12
+ const F = require('./fixtures/briefing-premium-facts.js');
13
+
14
+ const BASE = T.BASE;
15
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
16
+ const until = async (fn, ms = 10000, step = 100) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
17
+ const results = [];
18
+ const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + extra : ''}`); };
19
+ let srv = null; let browser = null;
20
+ const finish = async (code) => {
21
+ if (browser) await browser.close().catch(() => {});
22
+ if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
23
+ T.killTmux();
24
+ const bad = results.filter((x) => !x.cond).length;
25
+ console.log(`\n${results.length - bad}/${results.length} premium-vw-copy assertions passed`);
26
+ process.exit(code !== undefined ? code : (bad ? 1 : 0));
27
+ };
28
+ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
29
+
30
+ (async () => {
31
+ const exe = findBrowser();
32
+ if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the suite cannot run'); return finish(1); }
33
+ let chromium;
34
+ try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed'); return finish(1); }
35
+ srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
36
+ await T.waitForServer(BASE);
37
+ browser = await chromium.launch({ executablePath: exe });
38
+
39
+ const open = async ({ w = 1280, h = 900, theme = 'light' } = {}) => {
40
+ const ctx = await browser.newContext({ viewport: { width: w, height: h } });
41
+ const page = await ctx.newPage();
42
+ const S = { errors: [] };
43
+ page.on('pageerror', (e) => S.errors.push(String((e && e.message) || e)));
44
+ await page.route('**/api/briefing-premium*', (r) => r.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ ok: true, state: 'ready', model: B.build(F.facts()), as_of: Date.now() }) }));
45
+ await page.goto(BASE + '/premium.html?theme=' + theme);
46
+ S.up = await until(() => page.evaluate(() => document.querySelectorAll('#rank .rr .rhd').length > 0 && !!window.__premiumViewer), 20000);
47
+ return { page, ctx, S };
48
+ };
49
+ /* opens the first row that opens a dialog on this page (a row with its own page would navigate away) */
50
+ const openDialog = async (page) => {
51
+ const n = await page.evaluate(() => document.querySelectorAll('#rank .rr .rhd').length);
52
+ for (let i = 0; i < n; i++) {
53
+ const url = page.url();
54
+ await page.evaluate((k) => document.querySelectorAll('#rank .rr .rhd')[k].click(), i);
55
+ if (await until(() => page.evaluate(() => document.querySelector('#dlg').classList.contains('on')), 3000)) return true;
56
+ if (page.url() !== url) { await page.goBack(); await until(() => page.evaluate(() => document.querySelectorAll('#rank .rr .rhd').length > 0 && !!window.__premiumViewer), 20000); }
57
+ }
58
+ return false;
59
+ };
60
+ const st = (page) => page.evaluate(() => {
61
+ const t = document.querySelector('#vTabs'), m = document.querySelector('#oMain'), lab = document.querySelector('#oLab');
62
+ const vis = (e) => !!e && !e.hidden && getComputedStyle(e).display !== 'none';
63
+ return { ...window.__premiumViewer.vwState(), strip: vis(t), lab: vis(lab), main: vis(m), tabs: t ? [...t.querySelectorAll('.vtab')].map((x) => x.dataset.vw) : [],
64
+ sel: t ? [...t.querySelectorAll('.vtab[aria-selected="true"]')].map((x) => x.dataset.vw) : [], panes: [...document.querySelectorAll('#dOut .obody.vw')].map((p) => [p.dataset.vw, vis(p)]) };
65
+ });
66
+
67
+ const URL_C = 'https://acme.atlassian.net/wiki/spaces/P/pages/1/Launch+plan', URL_G = 'https://docs.google.com/document/d/1abc/edit', URL_M = 'https://docs.google.com/document/d/9memo/edit';
68
+ const stand = async (page, S) => {
69
+ S.sig = 'same'; S.posts = []; S.read = { ok: true, read: null, open: null };
70
+ await page.route('**/api/docs?*', (r) => r.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ ok: true, session: null, open: null, docs: [{ path: 'planning/launch.md', links: [
71
+ { kind: 'confluence', signal: S.sig, words: 'x', checked_at: new Date().toISOString(), title: 'Launch plan', url: URL_C, target: URL_C },
72
+ { kind: 'google', signal: 'behind', words: 'x', checked_at: new Date().toISOString(), remote_modified_at: new Date().toISOString(), title: 'Launch plan (Doc)', url: URL_G, target: URL_G }] }] }) }));
73
+ await page.route('**/api/doc?*', (r) => r.fulfill({ status: 200, contentType: 'text/markdown', body: '---\ntitle: Launch plan\n---\n\n## Goal\n\nOpen the beta to 40 accounts.\n' }));
74
+ await page.route('**/api/docs/read*', (r) => {
75
+ if (r.request().method() === 'POST') { S.posts.push(['read', JSON.parse(r.request().postData() || '{}')]); S.read = { ok: true, read: null, open: { run: 'r-abcdef', started_at: new Date().toISOString() } }; return r.fulfill({ status: 200, contentType: 'application/json', body: '{"ok":true,"session":"s1","run":"r-abcdef"}' }); }
76
+ return r.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(S.read) });
77
+ });
78
+ await page.route('**/api/docs/sync', (r) => { S.posts.push(['sync', JSON.parse(r.request().postData() || '{}')]); return r.fulfill({ status: 200, contentType: 'application/json', body: '{"ok":true,"session":"s2"}' }); });
79
+ await page.route('**/api/docs/check', (r) => { S.posts.push(['check', {}]); return r.fulfill({ status: 200, contentType: 'application/json', body: '{"ok":true,"session":"s3"}' }); });
80
+ };
81
+ const openCopy = (page, o) => page.evaluate((x) => import('/pm/premium-vw-copies.js').then((m) => { m.openCopy(x); }), o);
82
+ const shown = (page) => page.evaluate(() => { const p = document.querySelector('#dOut .obody.vw:not([hidden])'); return p ? p.innerText : ''; });
83
+
84
+ /* R11 desktop */
85
+ {
86
+ const { page, ctx, S } = await open();
87
+ await stand(page, S);
88
+ ok('R11 a row opens the dialog', await openDialog(page));
89
+ await openCopy(page, { ws: '', path: 'planning/launch.md', kind: 'confluence', url: URL_C, title: 'Launch plan' });
90
+ ok('R11 a matching copy shows "Same as PMOS" and the PMOS file as the page', await until(async () => { const t = await shown(page); return /Same as PMOS/.test(t) && /Open the beta to 40 accounts/.test(t); }), await shown(page));
91
+ ok('R11 a matching copy offers no write, only Check again and Open', await page.evaluate(() => { const p = document.querySelector('#dOut .obody.vw:not([hidden])'); return !p.querySelector('[data-cp="use"]') && !!p.querySelector('[data-cp="check"]') && !!p.querySelector('a[href*="atlassian"]'); }));
92
+ ok('R11 the stylesheet loads once', await until(() => page.evaluate(() => document.querySelectorAll('link[data-vw-css="copy"]').length === 1)));
93
+ await page.click('#dOut .obody.vw:not([hidden]) [data-cp="check"]');
94
+ ok('R11 Check again posts one check', await until(() => S.posts.some((p) => p[0] === 'check')));
95
+ await openCopy(page, { ws: '', path: 'planning/launch.md', kind: 'google', url: URL_G, title: 'Launch plan (Doc)' });
96
+ ok('R11 a changed copy says so and labels the text as the PMOS version, dimmed', await until(async () => { const t = await shown(page); return /changed after it last matched PMOS/.test(t) && /PMOS version/.test(t) && (await page.$('#dOut .obody.vw:not([hidden]) .cpv-page.dim')); }), await shown(page));
97
+ await page.click('#dOut .obody.vw:not([hidden]) [data-cp="use"]');
98
+ ok('R11 Use waits behind Undo', await until(async () => /five seconds/.test(await shown(page))));
99
+ await page.click('#dOut .obody.vw:not([hidden]) [data-cp="undo"]');
100
+ await sleep(5600);
101
+ ok('R11 Undo within five seconds posts no sync', !S.posts.some((p) => p[0] === 'sync'), JSON.stringify(S.posts));
102
+ await page.click('#dOut .obody.vw:not([hidden]) [data-cp="use"]');
103
+ ok('R11 without Undo the sync posts once, with use=copy, after five seconds', await until(() => S.posts.filter((p) => p[0] === 'sync').length === 1, 8000) && S.posts.find((p) => p[0] === 'sync')[1].use === 'copy', JSON.stringify(S.posts));
104
+ await openCopy(page, { ws: '', url: URL_M, kind: 'google', title: 'Pricing memo', where: 'material for Weekly sync' });
105
+ ok('R11 a link-only page says PMOS has only the address, with Read it now', await until(async () => { const t = await shown(page); return /PMOS has only the address/.test(t) && /Read it now/.test(t); }), await shown(page));
106
+ await page.click('#dOut .obody.vw:not([hidden]) [data-cp="read"]');
107
+ ok('R11 Read it now posts the page address once and shows that a session is reading', await until(async () => S.posts.filter((p) => p[0] === 'read').length === 1 && /is reading the page/.test(await shown(page))) && S.posts.find((p) => p[0] === 'read')[1].url === URL_M, JSON.stringify(S.posts));
108
+ S.read = { ok: true, open: null, read: { title: 'Pricing memo', text: '## Recommendation\n\nKeep the Pro tier.', read_at: new Date().toISOString(), by: 'doc-read', revision: '212' } };
109
+ ok('R11 when the read lands the text shows, with when and who read it', await until(async () => { const t = await shown(page); return /Keep the Pro tier/.test(t) && /Read today/.test(t) && /revision 212/.test(t); }, 12000), await shown(page));
110
+ ok('R11 four tabs at most: three copy tabs are open beside the main one', (await page.evaluate(() => window.__premiumViewer.vwState().ids.length)) === 3);
111
+ ok('R11 no page error', S.errors.length === 0, S.errors.join(' | '));
112
+ await ctx.close();
113
+ }
114
+
115
+ /* R7 phone and dark theme */
116
+ {
117
+ const { page, ctx, S } = await open({ w: 390, h: 844, theme: 'dark' });
118
+ await stand(page, S);
119
+ ok('R7 a row opens the dialog at 390px', await openDialog(page));
120
+ await openCopy(page, { ws: '', path: 'planning/launch.md', kind: 'google', url: URL_G, title: 'Launch plan (Doc)' });
121
+ await until(() => page.$('#dOut .obody.vw:not([hidden]) [data-cp="use"]'));
122
+ const m = await page.evaluate(() => {
123
+ const p = document.querySelector('#dOut .obody.vw:not([hidden])'), bs = [...p.querySelectorAll('.cpv-acts .dmcta')].filter((b) => b.offsetParent);
124
+ return { minH: Math.min(...bs.map((b) => b.getBoundingClientRect().height)), n: bs.length, over: document.documentElement.scrollWidth > window.innerWidth, bg: getComputedStyle(p.querySelector('.cpv-page')).backgroundColor };
125
+ });
126
+ ok('R7 the view\'s buttons are at least 44px tall at 390px', m.n >= 2 && m.minH >= 44, JSON.stringify(m));
127
+ ok('R7 the page does not scroll sideways', !m.over, JSON.stringify(m));
128
+ ok('R7 in the dark theme the page is not a light card', (() => { const c = (m.bg.match(/\d+/g) || []).slice(0, 3).map(Number); return c.length === 3 && c[0] + c[1] + c[2] < 3 * 160; })(), m.bg);
129
+ ok('R7 no page error', S.errors.length === 0, S.errors.join(' | '));
130
+ await ctx.close();
131
+ }
132
+ finish();
133
+ })();
@@ -74,8 +74,10 @@ const disk = () => fs.readFileSync(path.join(dir, pNew), 'utf8');
74
74
  const st = () => p.evaluate((pth) => { const S = window.__premiumSlides && window.__premiumSlides.state(pth); return S ? { i: S.i, n: S.deck.slides.length, theme: S.deck.theme, dirty: S.dirty, ro: S.ro, sel: S.sel, msg: S.msg, slides: JSON.parse(JSON.stringify(S.deck.slides)) } : null; }, pNew);
75
75
  const openReader = async (slot) => {
76
76
  await p.goto(BASE + '/premium-insights.html');
77
- await until(() => p.evaluate(() => document.querySelectorAll('#repDocs [data-rep]').length === 2));
78
- await tap(`#repDocs [data-rep="rep:${CAD}:${slot}"]`);
77
+ await until(() => p.evaluate(() => !!document.querySelector('#listSeg [data-f="rep"]')));
78
+ await tap('#listSeg [data-f="rep"]'); // the one list (insights-one-list L5): the Reports filter holds the report files
79
+ await until(() => p.evaluate(() => document.querySelectorAll('#listRows [data-rep]').length === 2));
80
+ await tap(`#listRows [data-rep="rep:${CAD}:${slot}"]`);
79
81
  return until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#rdSlide')));
80
82
  };
81
83
  const openEditor = async () => {
@@ -238,8 +240,10 @@ const disk = () => fs.readFileSync(path.join(dir, pNew), 'utf8');
238
240
  const c2 = await browser.newContext({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true, colorScheme: 'dark' }), q = await c2.newPage(), e2 = [];
239
241
  q.on('pageerror', (e) => e2.push(String(e)));
240
242
  await q.goto(BASE + '/premium-insights.html?theme=dark');
241
- await until(() => q.evaluate(() => document.querySelectorAll('#repDocs [data-rep]').length === 2));
242
- await q.$eval(`#repDocs [data-rep="rep:${CAD}:2026-10-12"]`, (x) => x.click());
243
+ await until(() => q.evaluate(() => !!document.querySelector('#listSeg [data-f="rep"]')));
244
+ await q.$eval('#listSeg [data-f="rep"]', (x) => x.click());
245
+ await until(() => q.evaluate(() => document.querySelectorAll('#listRows [data-rep]').length === 2));
246
+ await q.$eval(`#listRows [data-rep="rep:${CAD}:2026-10-12"]`, (x) => x.click());
243
247
  await until(() => q.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#rdSlide')));
244
248
  await q.$eval('#oMain [data-rr="rm"]', (x) => x.click()); await q.$eval('#oMain [data-rr="slides"]', (x) => x.click());
245
249
  await until(() => q.evaluate(() => !!document.querySelector('#dOut .obody.vw:not([hidden]) .sl .sl-stage .sl-cv')));
@@ -3,6 +3,7 @@
3
3
  * /api/doc-sheet routes and POST /api/doc-health/check. A draft has Issue it (POST /api/core-docs/issue) and, where the page asks for it, Draft it again.
4
4
  * The caller gives the page's own facts: { ws(), scope(), rows(), reload(), noteKey(d), sub(), again }. */
5
5
  import { pmPost } from './http.js';
6
+ import { openCopy } from './premium-vw-copies.js';
6
7
  import { proposalsModel, relationsOf, copyKindOf, copyView, editBody, acceptBody, rejectBody, askBody, askLine, issueBody, mdHtml, sectionAttribution, revDiffHtml } from './premium-doc-edit.js';
7
8
  import { $, $$, esc, openDlg, closeDlg, toast, loadThread, logHtml, turnA, ptx, kv, CHECK, CHEV, AI } from './premium-shell.js';
8
9
  import { openDocPage } from './premium-vw-doc.js';
@@ -100,7 +101,7 @@ export function mountDocSheet(ctx) {
100
101
  }
101
102
  /** Copies in other tools: each linked copy with its state, a link to open it, Check now, and a box to link another. The sheet never writes to the copy; updating one stays in the console. */
102
103
  function copiesHtml(s, cps) {
103
- const rows = cps.map((c) => `<div class="dscr"><div><b>${esc(c.title)}</b><span class="chp ${c.tone}">${esc(c.state)}</span></div><small>${esc([c.tool, c.target].filter(Boolean).join(' · '))}</small><p class="note" style="margin:4px 0 0">${esc(c.words)}${c.checked ? ' Last checked ' + esc(when(c.checked)) + '.' : ' Not checked yet.'}</p>${c.url ? `<a class="lk" href="${esc(c.url)}" target="_blank" rel="noopener">Open in ${esc(c.tool)}</a>` : ''}</div>`).join('');
104
+ const rows = cps.map((c, i) => `<div class="dscr"><div><b>${esc(c.title)}</b><span class="chp ${c.tone}">${esc(c.state)}</span></div><small>${esc([c.tool, c.target].filter(Boolean).join(' · '))}</small><p class="note" style="margin:4px 0 0">${esc(c.words)}${c.checked ? ' Last checked ' + esc(when(c.checked)) + '.' : ' Not checked yet.'}</p><button type="button" class="lk" data-ds="cpview:${i}">Preview</button> ${c.url ? `<a class="lk" href="${esc(c.url)}" target="_blank" rel="noopener">Open in ${esc(c.tool)}</a>` : ''}</div>`).join('');
104
105
  return `<div class="dscp" data-copies><p class="label">Copies in other tools</p>${rows || '<p class="note">This document has no copy in Confluence or Google Docs yet. Link one to see whether it is in step.</p>'}`
105
106
  + `<div class="dsrow"><input id="dsCpUrl" class="dsy" type="text" placeholder="Paste a Confluence page or Google Doc link" aria-label="Address of the copy" value="${esc(s.cpUrl || '')}"><button class="dmcta dark" data-ds="cplink">Link</button>${cps.length ? `<button class="dmcta alt" data-ds="cpcheck"${s.checkRun ? ' disabled' : ''}>${s.checkRun ? 'Checking' : 'Check now'}</button>` : ''}</div>`
106
107
  + `${s.cpMsg ? `<p class="note" role="alert" style="margin:6px 0 0;color:var(--ember-ink)">${esc(s.cpMsg)}</p>` : ''}<p class="note" style="margin:8px 0 0">PMOS never writes to a copy from this sheet. Check now starts one agent session that reads the copies with your connectors. Updating a copy is in the console.</p></div>`;
@@ -224,6 +225,7 @@ export function mountDocSheet(ctx) {
224
225
  if (act === 'meta') { s.meta = !s.meta; drawSheet(); return; }
225
226
  if (act === 'page') { openPage({ path: s.d.path, title: s.d.title, iniName: s.d.iniName }); return; }
226
227
  if (act === 'cp') { s.cp = !s.cp; s.cpMsg = ''; drawSheet(); return; }
228
+ if (act.startsWith('cpview:')) { const l = (s.copies || [])[+act.slice(7)]; if (l) openCopy({ ws: ctx.ws(), path: s.d.path, kind: l.kind, url: l.url || l.target, title: l.title || s.d.title }); return; }
227
229
  if (act === 'cplink') {
228
230
  const t = String(s.cpUrl || '').trim(), kind = copyKindOf(t);
229
231
  if (!kind) { s.cpMsg = 'Paste a Confluence page or Google Doc link.'; drawSheet(); const f = $('#dsCpUrl'); if (f) f.focus(); return; }
@@ -165,3 +165,55 @@ button.nfr:hover,button.nfr:focus-visible{background:color-mix(in oklab,var(--in
165
165
  .pdev{margin:0 0 12px;padding-left:18px;display:grid;gap:4px}
166
166
  .pdev small{color:var(--ink-3)}
167
167
  .dplist button[role="switch"]{min-height:44px;width:100%}
168
+ /* insights-one-list: the insight first, the pinned dashboard on top, one paged list of dashboards and reports */
169
+ .ins-hero{margin-top:28px;display:grid;gap:10px;max-width:72ch}
170
+ .ins-hero .brief.ihead{margin:0;max-width:none}
171
+ .ieye{display:flex;align-items:center;gap:6px;margin:0;font:600 var(--fs-1) var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--ember-ink)}
172
+ .ieye svg.i{width:14px;height:14px}
173
+ .ins-hero.calm .ieye{color:var(--ink-3)}
174
+ .ins-hero .ihead{margin:0;font-size:var(--fs-6);line-height:1.15;font-weight:600;letter-spacing:-.03em;color:var(--ink);text-wrap:balance}
175
+ .iwhy{margin:0;font-size:var(--fs-4);line-height:1.5;color:var(--ink-2)}
176
+ .iwhy:empty,.imore:empty,.iact:empty,.inote:empty{display:none}
177
+ .imore{list-style:none;margin:0;padding:0;display:grid;gap:2px}
178
+ .imr{display:flex;align-items:center;justify-content:space-between;gap:10px;width:100%;min-height:44px;padding:8px 10px;margin:0 -10px;border-radius:14px;text-align:left;font-size:var(--fs-3);color:var(--ink-2)}
179
+ .imr:hover,.imr:focus-visible{background:color-mix(in oklab,var(--ink) 6%,transparent);color:var(--ink)}
180
+ .imr svg.i{width:16px;height:16px;flex:none}
181
+ .iact{display:flex;gap:10px;flex-wrap:wrap;margin-top:4px}
182
+ .iact .dmcta{min-height:44px}
183
+ .inote{margin:0}
184
+ @media (max-width:700px){.ihead{font-size:var(--fs-5)}}
185
+ .ptag{font:600 var(--fs-1) var(--mono);font-style:normal;letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3);border:1px solid var(--hair);border-radius:6px;padding:2px 7px}
186
+ .ptag.on{color:var(--on-solid);background:var(--solid);border-color:transparent}
187
+ .ptag:empty{display:none}
188
+ .pdcard .ch small{margin-left:auto}
189
+ .pdbar .dmcta svg.i{width:16px;height:16px;margin-right:4px}
190
+ .nfd .nft b{font-weight:600}
191
+ .nfd li.stall .nfdot,.nfd li.miss .nfdot{background:var(--ember)}
192
+ .nfd li.course .nfdot{background:var(--ok)}
193
+ .lbar{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin:12px 0 0}
194
+ .lbar .nask{flex:1 1 260px;margin:0}
195
+ .lbar .dmcta{min-height:44px}
196
+ .newm{position:relative}
197
+ .lmenu{position:absolute;top:50px;left:0;z-index:5;display:grid;min-width:180px;padding:6px;border-radius:16px;background:var(--card-solid,var(--card));border:1px solid var(--hair);box-shadow:var(--card-shadow)}
198
+ .lmenu button{min-height:44px;padding:0 12px;border-radius:10px;text-align:left;font-weight:600}
199
+ .lmenu button:hover,.lmenu button:focus-visible{background:var(--well)}
200
+ #cRep .mhint{margin:10px 0 0 4px}
201
+ #listRows{margin-top:10px}
202
+ .dmi.c-Dash{background:color-mix(in oklab,var(--ember) 16%,transparent);color:var(--ember-ink)}
203
+ .nil{display:flex;gap:6px;align-items:flex-start;font-size:var(--fs-3);line-height:1.45;color:var(--ink)}
204
+ .nil svg.i{width:14px;height:14px;margin-top:3px;flex:none;color:var(--ember-ink)}
205
+ .nil.q span{color:var(--ink-2)}
206
+ .dmm .t{text-transform:uppercase;letter-spacing:.06em;font-size:var(--fs-1)}
207
+ .npin{width:44px;height:44px;margin-right:6px;border-radius:12px;display:grid;place-items:center;color:var(--ink-3);border:1px solid transparent}
208
+ .npin:hover{border-color:var(--hair);color:var(--ink)}
209
+ .npin[aria-pressed="true"]{background:var(--solid);color:var(--on-solid)}
210
+ .npin[aria-pressed="true"] svg{fill:currentColor}
211
+ .npin svg.i{width:18px;height:18px}
212
+ .lpager{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap;margin-top:12px}
213
+ .lpager .note{margin:0}
214
+ .lpager .pg{display:flex;gap:6px;flex-wrap:wrap}
215
+ .lpager .pg button{min-width:44px;height:44px;display:grid;place-items:center;border-radius:12px;border:1px solid var(--hair);font:500 var(--fs-2) var(--mono)}
216
+ .lpager .pg button[aria-current="page"]{background:var(--solid);color:var(--on-solid);border-color:transparent}
217
+ .lpager .pg button:disabled{opacity:.35;cursor:default}
218
+ .lmenu[hidden]{display:none}
219
+ #listRows .dmr{grid-template-columns:minmax(0,1fr) auto}
@@ -5,7 +5,8 @@
5
5
  * PRD D2 to D6) and the report presses of the console's Reports workspace (POST /api/report-setups/ask | change | cancel | setup | dismiss | pause | resume |
6
6
  * draft, PRD R2 to R4). premium-studio-chart adds a saved chart (POST /api/premium-charts/save, PRD C1, C10) and its four forms (C3). premium-studio-report
7
7
  * adds New report and Shape it in the Studio, whose presses are POST /api/report-setups/setup | from-dashboard and POST /api/report-structure/turn | remove |
8
- * revert | accept (PRD R5 to R8). Nothing else posts, and nothing is sent outward. */
8
+ * revert | accept (PRD R5 to R8). insights-one-list puts the insight first, the pinned dashboard on top and one paged list of dashboards and reports below
9
+ * (PRD L1 to L6); its one new press is Pin, POST /api/premium-dashboards/pin. Nothing else posts, and nothing is sent outward. */
9
10
  import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, crumbHtml, wireCrumb, kv, setPageGaps } from './premium-shell.js';
10
11
  import { pmPost, pmGet } from './http.js';
11
12
  import { openStudio } from './premium-studio.js';
@@ -13,11 +14,15 @@ import { openReport } from './premium-report-read.js';
13
14
  import * as MT from './premium-metric-tiles.js';
14
15
 
15
16
  let M = null; // the model
16
- let dash = 'all'; // the dashboard on screen
17
+ let dash = null; // the dashboard in the top card: the pinned one until a list row opens another
18
+ let listF = 'all', listP = 1; // the list's filter and page
19
+ const PER = 6; // rows to a page (insights-one-list L5)
17
20
  wireRail('rep');
18
21
  const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
19
22
  const DOCI = '<path d="M6 3h9l4 4v14H6z"/><path d="M14 3v5h5M9 13h6M9 17h4"/>';
20
23
  const CHV2 = '<svg class="i" viewBox="0 0 24 24"><path d="M9 6l6 6-6 6"/></svg>';
24
+ const PINI = '<path d="M9 3h6l-1 6 4 3v2H6v-2l4-3z"/><path d="M12 14v7"/>';
25
+ const DASHI = '<path d="M4 20V10M10 20V4M16 20v-8M22 20H2"/>';
21
26
  const AIC = '<path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/>';
22
27
  const byKey = (k) => (M && (M.charts || []).concat(M.mine || []) || []).find((c) => c.key === k) || null;
23
28
  const savedDash = () => (M.dashboards || []).filter((d) => d.saved);
@@ -34,9 +39,28 @@ function drawHead() {
34
39
  $('#snap').textContent = M.header.text;
35
40
  setPageGaps(((M.header && M.header.missing) || []).length);
36
41
  $('#snap').title = 'Every figure on this page comes from a KR metric record. A measure with fewer than two readings is listed, not drawn.';
37
- $('#brief').textContent = M.empty || '';
42
+ drawHero();
38
43
  }
39
44
 
45
+ /* ── the insight (insights-one-list L1, L2): the strongest finding across the board's measures, its reason, two more, and a press to the measure ── */
46
+ function drawHero() {
47
+ const I = M.insight;
48
+ $('#insEye').innerHTML = ICO(AIC) + esc(I.none ? 'Insight' : 'Insight · ' + I.off + ' of ' + I.total + ' behind their line · readings to ' + I.asOf);
49
+ $('#brief').textContent = I.text;
50
+ $('#insWhy').textContent = I.why || '';
51
+ $('#insMore').innerHTML = (I.more || []).map((x) => `<li><button class="imr" data-open="${esc(x.chart)}" aria-haspopup="dialog">${esc(x.text)}${CHV2}</button></li>`).join('');
52
+ $('#insAct').innerHTML = I.chart ? `<button class="dmcta" data-askwhy="${esc(I.chart)}" aria-haspopup="dialog">Ask PMOS why</button><button class="dmcta alt" data-open="${esc(I.chart)}" aria-haspopup="dialog">See the chart</button>` : '';
53
+ $('#insNote').textContent = I.proj || (I.more || []).length ? 'A sentence that says where a measure lands by its target date is a straight line through its last four readings, carried to that date. It is not drawn on a chart.' : '';
54
+ $('#insHero').classList.toggle('calm', !!(I.none || I.calm));
55
+ }
56
+ $('#insHero').addEventListener('click', (e) => {
57
+ const o = e.target.closest('[data-open]'); if (o) { openChart(byKey(o.dataset.open)); return; }
58
+ const a = e.target.closest('[data-askwhy]'); if (!a) return;
59
+ openChart(byKey(a.dataset.askwhy));
60
+ const t = $('#dTabs [data-t="chat"]'); if (t) t.click();
61
+ const inp = $('#askIn'); if (inp) { inp.value = 'Why is this happening, and what would change it?'; inp.focus(); }
62
+ });
63
+
40
64
  /* ── charts ───────────────────────────────────────────────────────────────────────────────────────────────────── */
41
65
  const W = 220, H = 60, P = 5;
42
66
  const X = (fx) => P + fx * (W - 2 * P), Y = (fy) => P + (1 - fy) * (H - 2 * P);
@@ -107,21 +131,25 @@ function chartAt(t, j) {
107
131
  t.setAttribute('aria-label', c.title + ', ' + (last ? 'now ' : '') + val + ', ' + cap + '. Use the arrow keys to read each reading.');
108
132
  }
109
133
 
110
- /* ── the dashboards card ──────────────────────────────────────────────────────────────────────────────────────── */
134
+ /* ── the top card: the pinned dashboard (insights-one-list L4) ─────────────────────────────────────────────────── */
111
135
  const curDash = () => M.dashboards.find((d) => d.id === dash) || M.dashboards[0];
112
- function findingsHtml() {
113
- const F = M.findings.filter((f) => f.text);
114
- if (!F.length) return '';
115
- return `<div class="nfd" role="region" aria-label="What stands out"><p class="label">What stands out</p><ul>${F.map((f) => `<li class="${esc(f.kind)}">${f.chart
116
- ? `<button class="nfr" data-open="${esc(f.chart)}" aria-haspopup="dialog"><i class="nfdot" aria-hidden="true"></i><span class="nft">${esc(f.text)}</span>${CHV2}</button>`
117
- : `<div class="nfr"><i class="nfdot" aria-hidden="true"></i><span class="nft">${esc(f.text)}</span></div>`}</li>`).join('')}</ul></div>`;
136
+ const pinnable = (D) => !!M.board.id && (D.id === 'all' || D.saved);
137
+ /* The dashboard's insight band. The finding the page already leads with is skipped, so the band says what else is on this dashboard. */
138
+ function findingsHtml(D) {
139
+ const I = D.insight; if (!I || I.none) return '';
140
+ const all = I.finds, F = all.filter((f) => f.chart !== M.insight.chart), also = F.length < all.length;
141
+ const label = also ? 'Also on this dashboard' : 'Insight';
142
+ const rows = F.length ? F.map((f) => `<li class="${esc(f.kind)}"><button class="nfr" data-open="${esc(f.chart)}" aria-haspopup="dialog"><i class="nfdot" aria-hidden="true"></i><span class="nft"><b>${esc(f.text)}</b> ${esc(f.why)}</span>${CHV2}</button></li>`).join('')
143
+ : `<li class="calm"><div class="nfr"><i class="nfdot" aria-hidden="true"></i><span class="nft">${esc(also ? 'Nothing else stands out here.' : I.calmText)}</span></div></li>`;
144
+ return `<div class="nfd" role="region" aria-label="${esc(label)}"><p class="label">${esc(label)}</p><ul>${rows}</ul></div>`;
118
145
  }
119
146
  function drawDash() {
120
- const D = curDash(), L = D.keys.map(byKey).filter(Boolean);
121
- $('#dashCap').textContent = M.counts.total ? M.counts.charts + ' drawn · ' + M.counts.noSeries + ' without a series' : '';
122
- const tabs = $('#dashTabs'); tabs.hidden = M.dashboards.length < 2;
123
- if (!tabs.hidden) { tabs.innerHTML = '<i class="pill"></i>' + M.dashboards.map((d) => `<button data-d="${esc(d.id)}" aria-pressed="${d.id === D.id}"${d.main ? ' title="The main dashboard"' : ''}>${esc(d.name)}${d.main ? ' · Main' : ''}</button>`).join(''); pillOf(tabs); }
124
- drawDashBar(D);
147
+ const D = curDash(), L = D.keys.map(byKey).filter(Boolean), isPin = M.pinned === D.id;
148
+ $('#hDash').textContent = D.name;
149
+ $('#dashTag').textContent = isPin ? 'Pinned' : 'Not pinned';
150
+ $('#dashTag').className = 'ptag' + (isPin ? ' on' : '');
151
+ $('#dashCap').textContent = L.length ? (L.length - D.off) + ' of ' + L.length + ' on their line' : '';
152
+ drawDashBar(D, isPin);
125
153
  if (D.saved) { drawSaved(D, L); return; }
126
154
  if (!M.charts.length) {
127
155
  $('#dashBody').innerHTML = `<div class="nempty" style="margin-top:14px"><p><b>${esc(M.counts.total ? 'No KR metric holds two readings yet.' : 'No KR metric is recorded for this workspace.')}</b> ${esc(M.counts.total ? 'A chart needs a series, so nothing is drawn.' : 'There is nothing to chart. Add one where the KR metrics are kept.')}</p></div>` + noSeriesHtml();
@@ -129,22 +157,27 @@ function drawDash() {
129
157
  }
130
158
  const off = D.off, tot = L.length;
131
159
  $('#dashBody').innerHTML = `<div class="mprog" role="progressbar" aria-label="Measures on their line" aria-valuemin="0" aria-valuemax="${tot}" aria-valuenow="${tot - off}"><b style="width:${(tot - off) / tot * 100}%"></b></div>`
132
- + findingsHtml()
160
+ + findingsHtml(D)
133
161
  + `<p class="mhint" style="margin-top:6px"><b>${tot - off} of ${tot}</b> on their line${off ? `. <b class="mflag">${off} ${off === 1 ? 'is' : 'are'} behind it.</b>` : '.'} Each chart is one KR metric, drawn at the dates of its readings. A gap between readings is left as a gap. The dashed line is the target.</p>`
134
- + `<div class="ngrid">${L.map((c) => tileWrap(c)).join('')}</div>` + mineHtml() + noSeriesHtml();
162
+ + `<div class="ngrid">${L.map((c) => tileWrap(c)).join('')}</div>` + (D.id === 'all' ? mineHtml() + noSeriesHtml() : '');
135
163
  }
136
- /* The bar under the switch: a saved dashboard's purpose and Edit, and New dashboard (PRD D3/D4). Hidden when the page has no board to save on. */
137
- function drawDashBar(D) {
164
+ /* The bar under the heading: Pin or Unpin, Back to the pinned one, a saved dashboard's purpose and Edit, and New chart. Hidden with no board to save on. */
165
+ function drawDashBar(D, isPin) {
138
166
  const bar = $('#dashBar'); bar.hidden = !M.board.id;
139
167
  if (bar.hidden) return;
140
- bar.innerHTML = (D.saved ? `<p class="note pdp">${D.main ? '<b>Main dashboard.</b> ' : ''}${esc(D.purpose)}</p><button class="dmcta alt" id="pdEdit" aria-haspopup="dialog">Edit</button>` : '')
141
- + '<button class="dmcta alt" id="pdNew" aria-haspopup="dialog">New dashboard</button>' + (M.charts.length ? '<button class="dmcta alt" id="pcNew" aria-haspopup="dialog">New chart</button>' : '');
168
+ const P = M.pinned ? M.dashboards.find((d) => d.id === M.pinned) : null;
169
+ bar.innerHTML = (D.saved ? `<p class="note pdp">${esc(D.purpose)}</p>` : `<p class="note pdp">${esc(D.id === 'all' ? 'Every KR metric of this board. PMOS makes it, so it cannot be deleted.' : 'The measures of the ' + D.name + ' pillar.')}</p>`)
170
+ + (pinnable(D) ? `<button class="dmcta${isPin ? ' alt' : ''}" id="pdPin" data-pin="${esc(isPin ? '' : D.id)}" aria-pressed="${isPin}">${ICO(PINI)}${isPin ? 'Unpin' : 'Pin'}</button>` : '')
171
+ + (P && !isPin ? `<button class="dmcta alt" id="pdBack">Back to ${esc(P.name)}</button>` : '')
172
+ + (D.saved ? '<button class="dmcta alt" id="pdEdit" aria-haspopup="dialog">Edit</button>' : '')
173
+ + (M.charts.length ? '<button class="dmcta alt" id="pcNew" aria-haspopup="dialog">New chart</button>' : '');
142
174
  }
143
175
  function drawSaved(D, L) {
144
176
  const off = D.off, tot = L.length;
145
177
  const gone = D.gone.length ? `<p class="label ngl">Not drawn · ${D.gone.length}</p><div class="dplist" role="list">${D.gone.map((g) => `<div class="nempty" role="listitem" style="margin-bottom:6px"><p><b>${esc(g.title)}</b><br>${esc(g.why)}</p></div>`).join('')}</div>` : '';
146
178
  const checks = D.checks.length ? `<p class="note pdck">${D.checks.map(esc).join(' ')}</p>` : '';
147
179
  $('#dashBody').innerHTML = (tot ? `<div class="mprog" role="progressbar" aria-label="Measures on their line" aria-valuemin="0" aria-valuemax="${tot}" aria-valuenow="${tot - off}"><b style="width:${(tot - off) / tot * 100}%"></b></div>`
180
+ + findingsHtml(D)
148
181
  + `<p class="mhint" style="margin-top:6px"><b>${tot - off} of ${tot}</b> on their line${off ? `. <b class="mflag">${off} ${off === 1 ? 'is' : 'are'} behind it.</b>` : '.'} The charts are drawn in the order you saved. The dashed line is the target.</p>`
149
182
  + `<div class="ngrid">${L.map((c) => tileWrap(c)).join('')}</div>`
150
183
  : `<div class="nempty" style="margin-top:14px"><p><b>This dashboard draws no chart yet.</b> Press Edit to add a measure with a series.</p></div>`) + checks + gone;
@@ -162,8 +195,21 @@ function noSeriesHtml() {
162
195
  const N = M.noSeries; if (!N.length) return '';
163
196
  return `<p class="label ngl">No series recorded · ${N.length}</p><div class="dplist" role="list">${N.map((n) => `<div class="nempty" role="listitem" style="margin-bottom:6px"><p><b>${esc(n.title)}</b>${n.pillar ? ' · ' + esc(n.pillar) : ''}<br>${esc(n.why)} It is not drawn.</p></div>`).join('')}</div>`;
164
197
  }
165
- $('#dashTabs').addEventListener('click', (e) => { const b = e.target.closest('[data-d]'); if (!b) return; dash = b.dataset.d; drawDash(); });
166
- $('#dashBar').addEventListener('click', (e) => { if (e.target.closest('#pdEdit')) openDashEdit(curDash()); else if (e.target.closest('#pdNew')) openDashEdit(null); else if (e.target.closest('#pcNew')) openChartEdit(null); });
198
+ /* Pin or unpin (PRD L4): one `pin` line in the dashboards ledger. The pinned dashboard shows in the top card of this page, and nowhere else. */
199
+ async function pinDash(id, from) {
200
+ const res = await pmPost('/api/premium-dashboards/pin', { ws: M.board.ws, board: M.board.id, id: id || null });
201
+ if (!res || res.ok !== true) { toast((res && res.error) || 'The pin could not be saved. Nothing changed.'); return; }
202
+ const D = M.dashboards.find((d) => d.id === id);
203
+ dash = res.pinned || 'all';
204
+ toast(res.pinned ? 'Pinned ' + (D ? D.name : 'the dashboard') + '. It shows at the top of Insights.' : 'Unpinned. All measures shows at the top.');
205
+ await load();
206
+ if (from === 'list') { try { $('#cDash').scrollIntoView({ behavior: 'smooth', block: 'start' }); } catch { /* no scroll */ } }
207
+ }
208
+ $('#dashBar').addEventListener('click', (e) => {
209
+ const pin = e.target.closest('#pdPin'); if (pin) { pin.disabled = true; pinDash(pin.dataset.pin || null, 'card'); return; }
210
+ if (e.target.closest('#pdBack')) { dash = M.pinned; drawDash(); drawList(); return; }
211
+ if (e.target.closest('#pdEdit')) openDashEdit(curDash()); else if (e.target.closest('#pcNew')) openChartEdit(null);
212
+ });
167
213
 
168
214
  /* ── a dashboard is made and edited in the Insight Studio (initiative premium-studio-dashboard). Its one press posts POST /api/premium-dashboards/save. ── */
169
215
  async function saveDash(body) { return pmPost('/api/premium-dashboards/save', Object.assign({ ws: M.board.ws, board: M.board.id }, body)); }
@@ -177,8 +223,8 @@ const design = {
177
223
  post: (sub, id, body) => pmPost('/api/report-design/' + sub, Object.assign({ ws: M.board.ws, id }, body)),
178
224
  };
179
225
  const studioOf = (o) => openStudio(Object.assign({ M, tile: tileHtml, derive: deriveChart, save: saveDash, saveChart, setup: (sub, body) => repPost(sub, body), structure, design, reportsChanged: () => load(),
180
- done: async (id) => { dash = id || dash; if (!M.dashboards.some((d) => d.id === dash)) dash = 'all'; await load(); } }, o));
181
- function openDashEdit(D) { studioOf({ mode: 'dash', D, done: async (id) => { dash = id || 'all'; await load(); } }); }
226
+ done: async (id) => { dash = id || dash; await load(); } }, o));
227
+ function openDashEdit(D) { studioOf({ mode: 'dash', D, done: async (id) => { dash = id || null; await load(); } }); }
182
228
  /* A chart is made and edited in the Studio's Chart mode (initiative premium-studio-chart). Save posts POST /api/premium-charts/save. */
183
229
  function openChartEdit(id) { studioOf({ mode: 'chart', C: id ? (M.mineSaved || []).find((x) => x.id === id) || null : null }); }
184
230
  /* A report is set up and shaped in the Studio's Report mode (initiative premium-studio-report). */
@@ -196,45 +242,77 @@ $('#dashBody').addEventListener('pointermove', (e) => {
196
242
  });
197
243
  $('#dashBody').addEventListener('pointerleave', () => $$('#dashBody .mch.hv').forEach((x) => chartAt(x)));
198
244
 
199
- /* ── reports ──────────────────────────────────────────────────────────────────────────────────────────────────── */
245
+ /* ── the list: dashboards, then reports, filtered and paged (insights-one-list L5, L6) ──────────────────────────── */
200
246
  let askTimer = 0;
201
247
  const dismissing = new Map(); // finding id → timer: "Not a report" waits 5 s for an Undo before it is sent
202
248
  const ASKST = { running: ['Working', 'draft'], ready: ['Ready to review', 'issued'], failed: ['Failed', 'none'] };
249
+ const insLine = (t, q) => `<span class="nil${q ? ' q' : ''}">${ICO(AIC)}<span>${esc(t)}</span></span>`;
250
+ function dashRow(D) {
251
+ const I = D.insight || {}, f = I.finds && I.finds[0], on = M.pinned === D.id, shown = curDash().id === D.id;
252
+ const line = I.none ? '' : insLine(f ? f.text : I.calmText);
253
+ const meta = `<span class="t">Dashboard</span>${on ? '<span class="s issued">Pinned</span>' : ''}${shown ? '<span>Shown above</span>' : ''}<span>${D.total} ${D.total === 1 ? 'chart' : 'charts'}</span>${D.off ? `<span class="s none">${D.off} behind</span>` : D.total ? '<span>All on their line</span>' : ''}`;
254
+ return `<div class="dmr" role="listitem"><button class="dmo" data-d="${esc(D.id)}"><span class="dmi c-Dash">${ICO(DASHI)}</span><span class="dmn"><b>${esc(D.name)}</b>${line || `<small>${esc(I.none ? 'No chart is drawn on it yet.' : '')}</small>`}<span class="dmm">${meta}</span></span></button>`
255
+ + (pinnable(D) ? `<button class="npin" data-pin="${esc(D.id)}" aria-pressed="${on}" aria-label="${on ? 'Unpin' : 'Pin'} ${esc(D.name)}" title="${on ? 'Unpin' : 'Pin to the top of Insights'}">${ICO(PINI)}</button>` : '') + '</div>';
256
+ }
257
+ /* A report row's insight is the opening sentence of its latest file, marked as quoted from it. With no file it says no draft is written yet. */
258
+ function setupRow(s) {
259
+ const L = s.latest, line = L && L.lead ? insLine('“' + L.lead + '”', true) : '';
260
+ const from = L ? (L.lead ? 'From the ' + L.date + ' file' : 'The ' + L.date + ' file has no sentence to quote') : 'No draft is written yet';
261
+ return `<div class="dmr" role="listitem"><button class="dmo" data-setup="${esc(s.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(s.name)}</b>${line}<small>${esc([from, s.label, s.audience ? 'for ' + s.audience : ''].filter(Boolean).join(' · '))}</small><span class="dmm"><span class="t">Report</span><span class="s ${s.paused ? 'none' : 'issued'}">${s.paused ? 'Paused' : s.drafting ? 'Drafting' : 'Set up'}</span>${s.next && !s.paused ? `<span>Next draft ${esc(s.next)}</span>` : ''}</span></span></button></div>`;
262
+ }
203
263
  function repRow(r) {
204
- return `<div class="dmr ${esc(r.state)}" role="listitem"><button class="dmo" data-rep="${esc(r.key)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(r.cadence)} · ${esc(r.date || r.slot)}</b><small>${esc(r.path)}</small><span class="dmm"><span class="s ${esc(r.state === 'issued' ? 'issued' : 'draft')}">${esc(r.stateLabel)}</span><span>Deck, present, download, print</span></span></span></button></div>`;
264
+ return `<div class="dmr ${esc(r.state)}" role="listitem"><button class="dmo" data-rep="${esc(r.key)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(r.cadence)} · ${esc(r.date || r.slot)}</b>${r.lead ? insLine('“' + r.lead + '”', true) : ''}<small>${esc(r.path)}</small><span class="dmm"><span class="t">Report</span><span class="s ${esc(r.state === 'issued' ? 'issued' : 'draft')}">${esc(r.stateLabel)}</span><span>Deck, present, download, print</span></span></span></button></div>`;
205
265
  }
206
266
  const foundRow = (f) => `<div class="dmr" role="listitem"><button class="dmo" data-found="${esc(f.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(AIC)}</span><span class="dmn"><b>${esc(f.name)}</b><small>${esc(f.why)}</small><span class="dmm">${f.confidence ? `<span>${esc(f.confidence)}</span>` : ''}<span>${f.evidence.length} ${f.evidence.length === 1 ? 'sign' : 'signs'} in your work</span></span></span></button></div>`;
207
267
  const askRow = (a) => `<div class="dmr" role="listitem"><button class="dmo" data-ask="${esc(a.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(AIC)}</span><span class="dmn"><b>${esc(a.proposal && a.proposal.name ? a.proposal.name : a.text)}</b><small>You asked: ${esc(a.text)}</small><span class="dmm"><span class="s ${ASKST[a.state][1]}">${ASKST[a.state][0]}</span>${a.changed ? '<span>Changed once</span>' : ''}</span></span></button></div>`;
208
- const setupRow = (s) => `<div class="dmr" role="listitem"><button class="dmo" data-setup="${esc(s.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(s.name)}</b><small>${esc([s.label, s.audience ? 'for ' + s.audience : ''].filter(Boolean).join(' · '))}</small><span class="dmm"><span class="s ${s.paused ? 'none' : 'issued'}">${s.paused ? 'Paused' : s.drafting ? 'Drafting' : 'Set up'}</span>${s.next && !s.paused ? `<span>Next draft ${esc(s.next)}</span>` : ''}</span></span></button></div>`;
209
- function drawReps() {
210
- const R = M.reports, found = (R.found || []).filter((f) => !dismissing.has(f.id)), asks = R.asks || [], setups = R.setups || [];
211
- $('#repCap').textContent = R.rows.length ? String(R.rows.length) : '';
212
- const group = (id, label, L, row) => L.length ? `<div class="dmg ngrp" id="${id}" role="list"><p class="label">${esc(label)} · ${L.length}</p>${L.map(row).join('')}</div>` : '';
213
- $('#repBody').innerHTML = `<p class="mhint">A report is a file in the repository. PMOS drafts it, you read it. <b>Nothing is sent from here.</b></p>`
214
- + '<div class="nact"><button class="dmcta" id="repNew" aria-haspopup="dialog">New report</button></div>'
215
- + `<form class="nask" id="repAsk"><input id="repAskIn" maxlength="500" autocomplete="off" placeholder="Ask PMOS to set up a report" aria-label="Ask PMOS to set up a report"><button class="dmcta" id="repAskGo" type="submit">Ask</button></form>`
216
- + '<p class="note nask-n">This starts a background run that only proposes a report. Nothing is set up until you press Set it up.</p>'
217
- + (R.setupsOk === false ? '<div class="nempty"><p><b>The report setups could not be read</b>, so what PMOS found and what you set up are not listed.</p></div>'
218
- : group('repAsks', 'Your requests', asks, askRow) + group('repFound', 'Found in your work', found, foundRow) + group('repSetups', 'Set up', setups, setupRow))
219
- + (R.missing ? '<div class="nempty"><p><b>The report files could not be read</b>, so none is listed.</p></div>'
220
- : R.rows.length ? `<div class="dmg ngrp" id="repDocs" role="list"><p class="label">Documents · <b>${R.counts.draft}</b> ${R.counts.draft === 1 ? 'draft' : 'drafts'} · <b>${R.counts.issued}</b> issued</p>${R.rows.map(repRow).join('')}</div>`
221
- : '<div class="nempty"><p><b>No report file is on record.</b> Set one up above, or ask PMOS for one.</p></div>')
222
- + `<p class="nsch"><button class="lk" id="repOpen">Open the Reports tab</button> to edit or issue a document.</p>`;
268
+ function listItems() {
269
+ const R = M.reports, d = M.dashboards.map((x) => ({ kind: 'dash', x }));
270
+ const r = (R.setupsOk === false ? [] : (R.setups || []).map((x) => ({ kind: 'setup', x }))).concat(R.missing ? [] : R.rows.map((x) => ({ kind: 'file', x })));
271
+ return { d, r, all: d.concat(r) };
272
+ }
273
+ function drawList() {
274
+ const R = M.reports, found = (R.found || []).filter((f) => !dismissing.has(f.id)), asks = R.asks || [];
275
+ const I = listItems(), L = listF === 'dash' ? I.d : listF === 'rep' ? I.r : I.all, pages = Math.max(1, Math.ceil(L.length / PER));
276
+ listP = Math.min(Math.max(1, listP), pages);
277
+ $('#repCap').textContent = String(I.all.length);
278
+ const seg = $('#listSeg');
279
+ seg.innerHTML = '<i class="pill"></i>' + [['all', 'All', I.all.length], ['dash', 'Dashboards', I.d.length], ['rep', 'Reports', I.r.length]].map(([k, t, n]) => `<button data-f="${k}" aria-pressed="${listF === k}">${t}<em>${n}</em></button>`).join('');
280
+ pillOf(seg);
281
+ const group = (id, label, G, row) => G.length ? `<div class="dmg ngrp" id="${id}" role="list"><p class="label">${esc(label)} · ${G.length}</p>${G.map(row).join('')}</div>` : '';
282
+ const row = (it) => it.kind === 'dash' ? dashRow(it.x) : it.kind === 'setup' ? setupRow(it.x) : repRow(it.x);
283
+ const empty = listF !== 'dash' && R.missing ? '<div class="nempty"><p><b>The report files could not be read</b>, so none is listed.</p></div>'
284
+ : listF !== 'dash' && R.setupsOk === false ? '<div class="nempty"><p><b>The report setups could not be read</b>, so what PMOS found and what you set up are not listed.</p></div>' : '';
285
+ const none = listF === 'rep' && !L.length && !R.missing ? '<div class="nempty"><p><b>No report is set up and no report file is on record.</b> Press New, then Report, or ask PMOS for one.</p></div>' : '';
286
+ $('#repBody').innerHTML = (listF === 'dash' ? '' : group('repAsks', 'Your requests', asks, askRow) + group('repFound', 'Found in your work', found, foundRow))
287
+ + empty + none
288
+ + `<div class="dmg" id="listRows" role="list" aria-label="Dashboards and reports">${L.slice((listP - 1) * PER, listP * PER).map(row).join('')}</div>`;
289
+ const from = (listP - 1) * PER + 1, to = Math.min(listP * PER, L.length);
290
+ $('#listPager').innerHTML = pages < 2 ? `<span class="note">${L.length} shown</span>`
291
+ : `<span class="note">${from}–${to} of ${L.length}</span><span class="pg" role="group" aria-label="Pages"><button data-pg="${listP - 1}" ${listP === 1 ? 'disabled' : ''} aria-label="Previous page">‹</button>${Array.from({ length: pages }, (_, i) => `<button data-pg="${i + 1}"${i + 1 === listP ? ' aria-current="page"' : ''} aria-label="Page ${i + 1}">${i + 1}</button>`).join('')}<button data-pg="${listP + 1}" ${listP === pages ? 'disabled' : ''} aria-label="Next page">›</button></span>`;
223
292
  clearTimeout(askTimer);
224
293
  if (asks.some((a) => a.state === 'running')) askTimer = setTimeout(load, 5000);
225
294
  }
295
+ $('#listSeg').addEventListener('click', (e) => { const b = e.target.closest('[data-f]'); if (!b || b.dataset.f === listF) return; listF = b.dataset.f; listP = 1; drawList(); });
296
+ $('#listPager').addEventListener('click', (e) => { const b = e.target.closest('[data-pg]'); if (!b || b.disabled) return; listP = +b.dataset.pg; drawList(); $('#cRep').scrollIntoView({ block: 'nearest' }); });
297
+ const menu = (open) => { $('#listMenu').hidden = !open; $('#listNew').setAttribute('aria-expanded', String(open)); };
298
+ $('#listNew').addEventListener('click', () => { const open = $('#listMenu').hidden; menu(open); if (open) $('#listMenu button').focus(); });
299
+ $('#listMenu').addEventListener('click', (e) => { const b = e.target.closest('button'); if (!b) return; menu(false); if (b.id === 'pdNew') openDashEdit(null); else if (b.id === 'repNew') openReportEdit(null); });
300
+ document.addEventListener('keydown', (e) => { if (e.key === 'Escape' && !$('#listMenu').hidden) { menu(false); $('#listNew').focus(); } });
301
+ document.addEventListener('click', (e) => { if (!$('#listMenu').hidden && !e.target.closest('.newm')) menu(false); });
226
302
  $('#repBody').addEventListener('click', (e) => {
303
+ const pin = e.target.closest('[data-pin]');
304
+ if (pin) { pin.disabled = true; pinDash(M.pinned === pin.dataset.pin ? null : pin.dataset.pin, 'list'); return; }
305
+ const d = e.target.closest('[data-d]');
306
+ if (d) { dash = d.dataset.d; drawDash(); drawList(); try { $('#cDash').scrollIntoView({ behavior: 'smooth', block: 'start' }); } catch { /* no scroll */ } return; }
227
307
  const rp = e.target.closest('[data-rep]');
228
308
  if (rp) { const row = M.reports.rows.find((x) => x.key === rp.dataset.rep), su = row && (M.reports.setups || []).find((x) => x.id === row.cadence); openReport(row, { ws: M.board.ws, name: su ? su.name : null }); return; }
229
- if (e.target.closest('#repOpen')) { location.assign('/console.html?tab=rep'); return; }
230
- if (e.target.closest('#repNew')) { openReportEdit(null); return; }
231
309
  const f = e.target.closest('[data-found]'), a = e.target.closest('[data-ask]'), s = e.target.closest('[data-setup]');
232
310
  if (f) openFound((M.reports.found || []).find((x) => x.id === f.dataset.found));
233
311
  else if (a) openAsk((M.reports.asks || []).find((x) => x.id === a.dataset.ask));
234
312
  else if (s) openSetup((M.reports.setups || []).find((x) => x.id === s.dataset.setup));
235
313
  });
236
- $('#repBody').addEventListener('submit', async (e) => {
237
- if (e.target.id !== 'repAsk') return;
314
+ $('#repOpen').addEventListener('click', () => location.assign('/console.html?tab=rep'));
315
+ $('#repAsk').addEventListener('submit', async (e) => {
238
316
  e.preventDefault();
239
317
  const inp = $('#repAskIn'), text = inp.value.trim(), go = $('#repAskGo');
240
318
  if (!text) { toast('Say what the report is for, then press Ask.'); inp.focus(); return; }
@@ -286,9 +364,9 @@ function openFound(f) {
286
364
  set: press('setup', { finding: f.id, name: f.name }, setupSaid),
287
365
  no: (m) => {
288
366
  const t = setTimeout(async () => { dismissing.delete(f.id); const res = await repPost('dismiss', { finding: f.id, name: f.name }); if (!res || res.ok !== true) toast(pressFailed(res, 'Not a report did not go through.')); await load(); }, 5000);
289
- dismissing.set(f.id, t); drawReps();
367
+ dismissing.set(f.id, t); drawList();
290
368
  m.innerHTML = 'Hidden. It is recorded as not a report in 5 seconds. <button class="lk" id="rxUndo">Undo</button>';
291
- $('#rxUndo').onclick = () => { clearTimeout(dismissing.get(f.id)); dismissing.delete(f.id); drawReps(); m.textContent = 'Undone. Nothing was recorded.'; $$('#oMain [data-rx]').forEach((x) => { x.disabled = false; }); };
369
+ $('#rxUndo').onclick = () => { clearTimeout(dismissing.get(f.id)); dismissing.delete(f.id); drawList(); m.textContent = 'Undone. Nothing was recorded.'; $$('#oMain [data-rx]').forEach((x) => { x.disabled = false; }); };
292
370
  return 'keep-off';
293
371
  },
294
372
  } });
@@ -335,7 +413,7 @@ function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textConten
335
413
  function cardHtml(c) { return `<div class="acard" id="card"><p class="ct">What this page can do</p><p class="nodef" id="holdWhy">${esc(c.dialog.hold)} The switches under On your dashboards save a dashboard and change no record.</p></div>`; }
336
414
  function paneHtml(c) {
337
415
  const p = c.dialog.pane;
338
- return `<article class="paper doc"><p class="dpath">${esc(p.file)}</p><h3 class="d1">${esc(c.title)}</h3><p>${esc(c.dialog.say)}</p><div class="ntw pdchart">${tileHtml(c)}</div><div class="kv2">${c.dialog.facts.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div><h3 class="h2">All ${c.pts.length} readings</h3><div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>${onDashHtml(c)}<p class="xn">Read from the KR metric record. The line status is the record's own: the straight line from its baseline to its target. Nothing here is a forecast.</p></article>`;
416
+ return `<article class="paper doc"><p class="dpath">${esc(p.file)}</p><h3 class="d1">${esc(c.title)}</h3><p>${esc(c.dialog.say)}</p><div class="ntw pdchart">${tileHtml(c)}</div><div class="kv2">${c.dialog.facts.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div><h3 class="h2">All ${c.pts.length} readings</h3><div class="kv2">${p.rows.map(([a, b]) => `<span>${esc(a)}</span><span>${esc(b)}</span>`).join('')}</div>${onDashHtml(c)}<p class="xn">Read from the KR metric record. The line status is the record's own: the straight line from its baseline to its target. Where this page says where a measure lands by its target date, that is a straight line through its last four readings, carried to that date. It is not drawn.</p></article>`;
339
417
  }
340
418
  /* Add to a dashboard (PRD D6): one switch per saved dashboard of the board. A press saves that dashboard with the chart added or taken off. */
341
419
  function onDashHtml(c) {
@@ -417,13 +495,14 @@ MT.wireTiles($('#bmBody'), () => (BM ? BM.tiles : []), bmOpen);
417
495
  $('#bmRange').addEventListener('click', (e) => { const b = e.target.closest('[data-w]'); if (!b || +b.dataset.w === bmWeeks) return; bmWeeks = +b.dataset.w; try { localStorage.setItem(BM_KEY, String(bmWeeks)); } catch { /* not kept */ } bmDraw(); bmLoad(); });
418
496
 
419
497
  /* ── load ─────────────────────────────────────────────────────────────────────────────────────────────────────── */
420
- function draw() { drawHead(); if (!M.dashboards.some((d) => d.id === dash)) dash = 'all'; drawDash(); drawReps(); drawDock(); onScroll(); }
498
+ function draw() { drawHead(); if (!dash || !M.dashboards.some((d) => d.id === dash)) dash = M.pinned || 'all'; drawDash(); drawList(); drawDock(); onScroll(); }
421
499
  async function load() {
422
500
  const p = new URLSearchParams(location.search), q = [p.get('ws') ? 'ws=' + encodeURIComponent(p.get('ws')) : '', p.get('board') ? 'board=' + encodeURIComponent(p.get('board')) : ''].filter(Boolean).join('&');
423
501
  let r = null, status = 0;
424
502
  try { const res = await fetch('/api/insights-premium' + (q ? '?' + q : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
425
503
  if (!r || !r.ok) {
426
504
  $('#snap').textContent = 'The records could not be read';
505
+ $('#insEye').textContent = 'Insight'; $('#insWhy').textContent = '';
427
506
  $('#brief').textContent = 'The KR metric records could not be read, so this page shows nothing rather than guess.' + (r && r.error ? ' The reason: ' + r.error : status ? ' (the server answered ' + status + ')' : ' The server did not answer.');
428
507
  setTimeout(load, 15000);
429
508
  return;