create-pmos 0.312.0 → 0.314.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.
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+ /* routes-board-metric-targets.js — the targets the PM sets for the Board's four measures on the premium Insights page (initiative briefing-premium-metrics, option C).
3
+ *
4
+ * POST /api/board-metric-targets/save { ws, key, target } → { ok, targets }
5
+ * one `set` line (or a `clear` line when target is null or empty) in <state>/board-metric-targets.jsonl (lib/board-metric-records.js, the one writer)
6
+ *
7
+ * The Board and Insights read the targets through GET /api/board-metrics-premium, so this module has no GET.
8
+ * WHO WRITES. As routes-premium-dashboards.js: an agent session header is refused (403), and pm-guard requirePagePress checks the launch nonce and the page's
9
+ * origin. The route stores the number the PM typed and nothing else. */
10
+ const guard = require('./pm-guard.js');
11
+ const Rec = require('./board-metric-records.js');
12
+
13
+ const bad = (status, error) => ({ status, body: { ok: false, error } });
14
+
15
+ async function handle(req, res, url, ctx) {
16
+ const send = (r) => { ctx.json(res, r.body, r.status); return true; };
17
+ if (url.pathname !== '/api/board-metric-targets/save') return send(bad(404, 'no such board-metric-targets route'));
18
+ if (req.method !== 'POST') return send(bad(405, 'POST only'));
19
+ const read = await ctx.readJson(req);
20
+ if (!read.ok) return send(bad(400, 'the body is not JSON'));
21
+ const body = read.body || {};
22
+ if (req.headers && req.headers['x-pmos-session']) return send(bad(403, 'an agent session cannot set a target. Only a press on the page does'));
23
+ const g = guard.requirePagePress(req, body);
24
+ if (!g.ok) return send(bad(g.status, g.error));
25
+ const id = typeof body.ws === 'string' ? body.ws : '';
26
+ const w = ctx.getWs(id || null);
27
+ if (!w || !w.root || (id && w.id !== id)) return send(bad(404, 'no such workspace'));
28
+ const r = Rec.saveTarget(w.root, body, g.actor, { now: Date.now() });
29
+ if (!r.ok) return send(bad(r.status, r.error));
30
+ return send({ status: 200, body: { ok: true, targets: r.targets } });
31
+ }
32
+
33
+ module.exports = { prefixes: ['/api/board-metric-targets'], handle };
@@ -28,15 +28,16 @@ async function via(mod, pathAndQuery, req, ctx) {
28
28
  }
29
29
  const qs = (o) => '?' + Object.entries(o).filter(([, v]) => v != null && v !== '').map(([k, v]) => k + '=' + encodeURIComponent(v)).join('&');
30
30
 
31
- /** GET /api/board-metrics-premium?ws=<id> — the Metrics card of a tenant's Board (initiative briefing-premium-metrics). Read-only, and apart from the Board's own
32
- * route so the Board never waits for it. Every board has the card, the PMOS board's counted from the PMOS repository. */
31
+ /** GET /api/board-metrics-premium?ws=<id>[&weeks=8|26|52] — the Metrics card of a tenant's Board (initiative briefing-premium-metrics), and the same measures
32
+ * on Insights over a longer range. Apart from the Board's own route so the Board never waits for it. Its one write is the once-a-day Blocked/Idle history line
33
+ * (lib/board-metric-records.js record). Every board has the card, the PMOS board's counted from the PMOS repository. */
33
34
  async function metrics(req, res, url, ctx) {
34
35
  if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
35
36
  try {
36
37
  const w = ctx.getWs && ctx.getWs(url.searchParams.get('ws') || null);
37
38
  if (!w || !w.root) { ctx.json(res, { ok: false, state: 'error', error: 'that workspace is not registered' }, 404); return true; }
38
39
  const engine = ENGINE_PATHS.find((p) => fs.existsSync(p)) || null;
39
- const model = await Metrics.read({ root: w.root, engine, now: Date.now() });
40
+ const model = await Metrics.read({ root: w.root, engine, now: Date.now(), weeks: Number(url.searchParams.get('weeks')) || undefined });
40
41
  // the read-only agent finds a tile's row in the Board's model
41
42
  const bm = BoardP.peekModel(); if (bm && Array.isArray(bm.rows)) bm.rows = bm.rows.filter((r) => !/^board:metric-/.test(r.key)).concat(model.rows);
42
43
  ctx.json(res, { ok: true, state: 'ready', model, as_of: Date.now() });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.312.0",
3
+ "version": "0.314.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.312.0",
9
+ "version": "0.314.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.312.0",
3
+ "version": "0.314.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",
@@ -7,6 +7,7 @@ import { pmPost } from './http.js';
7
7
  import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, logHtml, turnA, ptx, pillOf, CHECK, AI, store, crumbHtml, wireCrumb, kv, H, openAddDoc } from './premium-shell.js';
8
8
  import { issueBody } from './premium-doc-edit.js';
9
9
  import { mountDocSheet } from './premium-doc-sheet.js';
10
+ import * as MT from './premium-metric-tiles.js';
10
11
  import { dotsBtn, openMenu, closeMenu, menuKey, asksHtml, onAsks, openIniForm } from './premium-acts.js';
11
12
 
12
13
  const MODE_KEY = 'pmos.premium.openAs';
@@ -227,44 +228,15 @@ load();
227
228
  * Reads GET /api/board-metrics-premium?ws= apart from the board's own answer and draws lib/board-metrics-premium.js's tiles: a number and a chart only
228
229
  * where a record counted one, "Not read" where it could not be. A tile opens the standard dialog. Nothing here writes. */
229
230
  let MM = null, metTimer = null; // the Metrics card's model and its re-read timer
230
- const MET_GEO = { W: 220, H: 60, P: 5 };
231
- const metGeo = (m) => { const n = m.ser.length, { W, H: Ht, P } = MET_GEO, vs = m.ser.filter((v) => v != null), lo = Math.min(...vs), hi = Math.max(...vs), sp = hi - lo || 1; return { n, W, H: Ht, P, X: (j) => P + j * (W - 2 * P) / (n - 1), Y: (v) => P + (1 - (v - lo) / sp) * (Ht - 2 * P) }; };
232
- const metFmt = (m, v) => (+v).toFixed(m.dec) + (m.suf || '');
233
-
234
- function metTileHtml(t, i) {
235
- if (t.absent) return `<div class="mt1" data-m="${i}" data-op="m:${i}" tabindex="0" role="button" aria-label="${esc(t.label)}: ${esc(t.absent)}. ${esc(t.why)}"><span>${esc(t.label)}</span><b class="mval">${esc(t.absent)}</b><em class="mwk">${esc(t.why)}</em></div>`;
236
- const lab = t.look ? `<span class="mlab">${esc(t.label)}<i class="mchip warn">Needs a look</i></span>` : `<span>${esc(t.label)}</span>`, off = t.look ? ' off' : '';
237
- const chg = t.change ? `<span class="mchg ${t.change.d === 0 ? '' : t.change.good ? 'good' : 'bad'}">${t.change.d === 0 ? '' : t.change.d > 0 ? '▲ ' : '▼ '}${esc(t.change.txt)}</span>` : '';
238
- if (!t.ser) return `<div class="mt1 ${t.kind}${off}" data-m="${i}" data-op="m:${i}" tabindex="0" role="button" aria-label="${esc(t.label)}, ${esc(t.value)}, ${esc(t.text)}${t.look ? ', needs a look' : ''}">${lab}<b class="mval">${esc(t.value)}</b><em class="mwk">${esc(t.text)}</em></div>`;
239
- const g = metGeo(t); let ln = '', op = false;
240
- t.ser.forEach((v, j) => { if (v == null) { op = false; return; } ln += (op ? 'L' : 'M') + g.X(j).toFixed(1) + ',' + g.Y(v).toFixed(1); op = true; });
241
- const f = Math.max(0, t.ser.findIndex((v) => v != null)), gap = t.ser.slice(f).some((v) => v == null), n1 = g.n - 1, lastJ = t.ser.reduce((a, v, j) => (v != null ? j : a), f);
242
- return `<div class="mt1 mch ${t.kind}${off}" data-m="${i}" data-op="m:${i}" tabindex="0" role="button" aria-label="${esc(t.label)} over eight weeks, now ${esc(t.value)}${t.look ? ', needs a look' : ''}. Use the arrow keys to read each week.">${lab}<b class="mval">${esc(t.value)}</b><em class="mwk">${esc(t.text)}</em>${chg}`
243
- + `<svg viewBox="0 0 ${g.W} ${g.H}">${f > 0 ? `<line class="gp" x1="${g.X(0)}" x2="${g.X(f)}" y1="${g.H - g.P}" y2="${g.H - g.P}"/>` : ''}${gap ? '' : `<path class="ar" d="${ln}L${g.X(n1)},${g.H}L${g.X(f)},${g.H}Z"/>`}<path class="ln2" d="${ln}"/><line class="cx" x1="0" x2="0" y1="0" y2="${g.H}"/><circle class="dt" cx="${g.X(lastJ)}" cy="${g.Y(t.ser[lastJ])}" r="3.5"/></svg>`
244
- + `<span class="mfoot"><i>${esc(t.wk[0])}</i><i>${esc(t.wk[t.wk.length - 1])}</i></span></div>`;
245
- }
246
-
247
- /** Read one week of a chart tile: the guide line and dot move, the value and caption change. */
248
- function metChartAt(el, j) {
249
- const t = MM.tiles[+el.dataset.m]; if (!t || !t.ser) return;
250
- const g = metGeo(t); j = j == null ? t.ser.reduce((a, v, k) => (v != null ? k : a), 0) : Math.max(0, Math.min(g.n - 1, j));
251
- const v = t.ser[j], has = v != null, x = g.X(j), y = has ? g.Y(v) : 0, now = j === t.ser.reduce((a, w, k) => (w != null ? k : a), 0);
252
- const cx = $('.cx', el), dt = $('.dt', el);
253
- cx.setAttribute('x1', x); cx.setAttribute('x2', x); dt.setAttribute('cx', x); dt.setAttribute('cy', y); dt.style.opacity = has ? '' : '0';
254
- el.classList.toggle('hv', !now); el.dataset.j = j;
255
- const val = now ? t.value : has ? metFmt(t, v) : 'No runs', cap = now ? t.text : 'Week to ' + t.wk[j] + (t.nt[j] ? ' · ' + t.nt[j] : '');
256
- $('.mval', el).textContent = val; $('.mwk', el).textContent = cap;
257
- el.setAttribute('aria-label', t.label + ', ' + (now ? 'now ' : '') + val + ', ' + cap + '. Use the arrow keys to read each week.');
258
- }
259
231
 
260
232
  function metDraw() {
261
233
  const card = $('#cMet'); if (!MM) { card.hidden = true; return; }
262
234
  card.hidden = false;
263
235
  $('#metCap').textContent = MM.header;
264
236
  const ins = '/premium-insights.html' + (M.board.ws ? '?ws=' + encodeURIComponent(M.board.ws) + (M.board.id ? '&board=' + encodeURIComponent(M.board.id) : '') : '');
265
- $('#metHint').innerHTML = (MM.lead ? `<b class="mflag">${esc(MM.lead)}</b> ` : '') + esc(MM.body || MM.hint) + ` For the KR measures and your own set of charts, <a class="lk" id="metIns" href="${esc(ins)}">open Insights</a>.`;
237
+ $('#metHint').innerHTML = (MM.lead ? `<b class="mflag">${esc(MM.lead)}</b> ` : '') + esc(MM.body || MM.hint) + ` To set a target, or for longer ranges, <a class="lk" id="metIns" href="${esc(ins)}">open Insights</a>.`;
266
238
  $('#metBody').style.gridTemplateColumns = 'repeat(' + Math.min(4, MM.tiles.length) + ',minmax(0,1fr))';
267
- $('#metBody').innerHTML = MM.tiles.map(metTileHtml).join('');
239
+ $('#metBody').innerHTML = MM.tiles.map(MT.tileHtml).join('');
268
240
  $('#metNote').textContent = MM.note;
269
241
  pillOf($('#perTabs'));
270
242
  }
@@ -272,26 +244,15 @@ function metDraw() {
272
244
  function metOpenTile(i) {
273
245
  const t = MM.tiles[i], r = MM.rows[i]; if (!t || !r) return;
274
246
  const d = r.dialog;
275
- const rows = t.absent ? [['Now', t.absent], ['Why', t.why], ['Counted from', MM.repo]]
276
- : [['Now', t.value], ['Counted', t.text], ['Change', t.change ? t.change.txt : ''], ['Better when', t.lowBetter ? 'Lower' : t.lowBetter === false ? 'Higher' : ''], ['Period', t.ser ? 'Week · last 8 weeks' : 'Now'], ['Source', MM.repo]];
277
- const vals = t.ser ? H('Values') + `<div class="vtb">${t.ser.map((v, j) => `<div><span>${esc(t.wk[j])}</span><b>${v == null ? 'No runs' : esc(metFmt(t, v))}</b></div>`).join('')}</div>` : '';
247
+ const rows = MT.factRows(t, MM.repo, MM.weeks);
248
+ const vals = t.ser ? H('Values') + `<div class="vtb">${t.ser.map((v, j) => `<div><span>${esc(t.wk[j])}</span><b>${v == null ? (t.since ? 'Not kept yet' : 'No runs') : esc(MT.fmt(t, v))}</b></div>`).join('')}</div>` : '';
278
249
  const pane = `<article class="paper doc"><p class="lede" style="margin:0 0 10px">${esc(t.def)}</p>${kv(rows)}${vals}<p class="note" style="margin-top:12px">${esc(MM.note)}</p></article>`;
279
250
  openDlg({ eye: 'Measure · real data', title: t.label, sub: MM.repo, say: d.say, stream: turnA(logHtml({ logTitle: 'Read from the repository', log: ['Read the repository\'s own records', 'Counted them by week', 'Changed nothing'] })) + turnA(ptx(d.say)), noteKey: r.key, pane, label: 'Measure' });
280
251
  loadThread(r.key);
281
252
  }
282
253
 
283
- const metIdx = (e) => { const t = e.target.closest('[data-m]'); return t ? t : null; };
284
- const metBody = () => $('#metBody');
285
254
  function metWire() {
286
- metBody().addEventListener('click', (e) => { const t = metIdx(e); if (t) metOpenTile(+t.dataset.m); });
287
- metBody().addEventListener('keydown', (e) => {
288
- const t = metIdx(e); if (!t) return;
289
- if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); metOpenTile(+t.dataset.m); return; }
290
- if (!t.classList.contains('mch') || !/^Arrow(Left|Right)$/.test(e.key)) return;
291
- e.preventDefault(); const m = MM.tiles[+t.dataset.m], now = t.dataset.j == null ? m.ser.length - 1 : +t.dataset.j; metChartAt(t, now + (e.key === 'ArrowLeft' ? -1 : 1));
292
- });
293
- metBody().addEventListener('pointermove', (e) => { const t = metIdx(e); if (!t || !t.classList.contains('mch')) return; const s = $('svg', t).getBoundingClientRect(), m = MM.tiles[+t.dataset.m], g = metGeo(m); metChartAt(t, Math.round(((e.clientX - s.left) / s.width * g.W - g.P) / (g.W - 2 * g.P) * (g.n - 1))); });
294
- metBody().addEventListener('pointerout', (e) => { const t = metIdx(e); if (t && t.classList.contains('mch') && !t.contains(e.relatedTarget)) metChartAt(t, null); });
255
+ MT.wireTiles($('#metBody'), () => MM.tiles, metOpenTile);
295
256
  $('#perTabs').addEventListener('click', (e) => { const b = e.target.closest('[aria-disabled="true"]'); if (b) toast('PMOS counts runs and merges by week only.'); });
296
257
  }
297
258
 
@@ -3,6 +3,7 @@
3
3
  * consoleBrief(now?) → Promise of { parts: [{ t, go? }], sources } | null reads what the console Briefing reads, composes with composeBrief
4
4
  * briefNeeds(b, page, agent) → { decisions, own, agentN } PURE. The rows the console's Needs you holds, in its ranked order (c3-brief-needs.js)
5
5
  * briefInputOf(...) → the composeBrief input PURE
6
+ * needsListOf(reads, ws) → the rows of "What you need to do", one per console Needs you row, in its order PURE
6
7
  * The same five reads, the same row rules and the same composer as the console: GET /api/briefing, GET /api/brief-page, GET /api/needs (agent drafts),
7
8
  * the calendar quarter, and the day part of the clock. A read that fails leaves its sentence out. null when the needs reads failed, so the page keeps
8
9
  * its own records-only hero rather than guess. No write, no model call. */
@@ -37,7 +38,39 @@ export function briefNeeds(b, page, agent) {
37
38
  const ordered = [...R.first, ...R.rest].filter((r) => !(R.byKey.get(r.key) || {}).members).map((r) => byKey.get(r.key)).filter(Boolean);
38
39
  const decisions = ordered.filter((x) => x.src === 'decision').map((x) => { const m = meta.get(String(x.raw.key)) || {}; return { key: String(x.raw.key), headline: x.raw.headline || '', time: m.time || null, decide: !!m.decide, overdue: !!m.overdue, days_late: m.days_late || 0 }; });
39
40
  const own = ordered.filter((x) => x.src === 'own').map((x) => ({ key: String(x.raw.key), headline: x.raw.headline || '', kind: x.raw.kind, days_late: x.raw.days_late || 0 }));
40
- return { decisions, own, agentN: ordered.filter((x) => x.src === 'agent').length };
41
+ return { decisions, own, agentN: ordered.filter((x) => x.src === 'agent').length, ordered };
42
+ }
43
+
44
+ const lateWord = (d) => (d === 1 ? '1 day late' : d + ' days late');
45
+ const factText = (f) => (f && typeof f === 'object' ? f.text : f);
46
+ /** One row of "What you need to do" from one row of the console's Needs you. A row says only what the console row's own data says:
47
+ * no "If you skip" line (no record holds one). go: where a press goes, the item's own page; null opens the Briefing's dialog. */
48
+ export function needsRowOf(x, ws) {
49
+ const r = x.raw, q = (k, v) => k + '=' + encodeURIComponent(v);
50
+ if (x.src === 'own') {
51
+ const when = r.kind === 'overdue' ? lateWord(Math.max(1, Number(r.days_late) || 1)) : r.kind === 'due-today' ? 'Due today' : r.offline ? 'Outside PMOS' : '';
52
+ return { key: 'own:' + r.key, src: 'own', title: r.headline || '', subject: ['Yours', when, r.person ? 'with ' + r.person : ''].filter(Boolean).join(' · '),
53
+ prepared: r.evidence && r.evidence.text ? 'Looks done: ' + r.evidence.text + '. Confirm it in My work.' : 'Open it in My work to mark it done, put it off or drop it.',
54
+ go: r.id ? '/premium-work.html?' + [q('item', r.id), ws ? q('ws', ws) : ''].filter(Boolean).join('&') : null };
55
+ }
56
+ if (x.src === 'agent') {
57
+ const blocked = r.kind === 'driver-blocked', ini = r.initiative_id || '';
58
+ return { key: 'agent:' + r.run_id, src: 'agent', title: r.question || '', subject: ['From the agent', blocked ? 'waiting on you' : 'drafts to review', ini].filter(Boolean).join(' · '),
59
+ prepared: blocked ? 'The agent will not go on until you decide.' : r.kind === 'core-doc-drafts' ? 'Review each draft, then issue it.' : 'Keep, send back or drop each draft.',
60
+ go: ini ? '/premium-initiative.html?' + [q('id', ini), r.ws ? q('ws', r.ws) : ''].filter(Boolean).join('&') : '/console.html' };
61
+ }
62
+ const v = r.view || null;
63
+ const facts = v ? v.facts : (r.facts || []).map(factText).filter(Boolean);
64
+ const say = (v ? v.why : r.why) || '';
65
+ return { key: 'dec:' + r.key, src: 'decision', title: r.headline || '', subject: [v ? v.tag : r.kind, r.dueText || (v && v.deadline && v.deadline.text) || r.time || '', r.src && r.src !== (v && v.tag) ? r.src : ''].filter(Boolean).join(' · '),
66
+ prepared: say || facts[0] || '', facts, options: v ? v.options.map((o) => o.label) : [], url: (v ? v.url : r.url) || null, urlLabel: (v ? v.urlLabel : r.url_label) || null, go: null };
67
+ }
68
+
69
+ /** "What you need to do" in the console's Needs you order. null when the needs reads failed. */
70
+ export function needsListOf({ b, page, agent }, ws) {
71
+ if (!page || page.ok === false) return null;
72
+ const { ordered } = briefNeeds(b, page, agent);
73
+ return ordered.map((x) => needsRowOf(x, ws));
41
74
  }
42
75
 
43
76
  export function briefInputOf({ b, page, agent, quarter, now }) {
@@ -48,9 +81,17 @@ export function briefInputOf({ b, page, agent, quarter, now }) {
48
81
  pulse: quarter && quarter.ok !== false ? pulseRows(quarter.gantt) : null };
49
82
  }
50
83
 
51
- export async function consoleBrief(now) {
84
+ /** The console Briefing's reads, once. */
85
+ export async function consoleReads() {
52
86
  const [b, page, agent, quarter] = await Promise.all([loadBriefing(true), loadBriefPage(), loadDriverNeeds().catch(() => []), readQuarter().catch(() => null)]);
87
+ return { b, page, agent, quarter };
88
+ }
89
+
90
+ export function briefOf(reads, now) {
91
+ const { page } = reads;
53
92
  if (!page || page.ok === false) return null; // the needs reads failed: keep the records-only hero rather than half a brief
54
- const r = composeBrief(briefInputOf({ b, page, agent, quarter, now }));
93
+ const r = composeBrief(briefInputOf({ ...reads, now }));
55
94
  return r.parts.length ? r : null;
56
95
  }
96
+
97
+ export async function consoleBrief(now) { return briefOf(await consoleReads(), now); }
@@ -10,6 +10,7 @@ import { $, $$, esc, openDlg, closeDlg, toast, loadThread, onScroll, wireRail, l
10
10
  import { pmPost, pmGet } from './http.js';
11
11
  import { openStudio } from './premium-studio.js';
12
12
  import { openReport } from './premium-report-read.js';
13
+ import * as MT from './premium-metric-tiles.js';
13
14
 
14
15
  let M = null; // the model
15
16
  let dash = 'all'; // the dashboard on screen
@@ -363,6 +364,57 @@ function openChart(c) {
363
364
  }
364
365
  $('#dBody').addEventListener('click', (e) => { const lt = e.target.closest('#logT'); if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); } });
365
366
 
367
+ /* ── the Board measures card (initiative briefing-premium-metrics, option C) ─────────────────────────────────────────
368
+ * The Board's four measures from GET /api/board-metrics-premium?ws=&weeks=, drawn with the Board's own tiles over 8, 26 or 52 weeks. A measure's dialog
369
+ * holds the page's one target press: POST /api/board-metric-targets/save, which the Board then draws as the chip, the dashed line and the outline. */
370
+ let BM = null, bmWeeks = 8, bmTimer = null;
371
+ const BM_KEY = 'pmos.premium.bmWeeks';
372
+ try { const w = Number(localStorage.getItem(BM_KEY)); if ([8, 26, 52].includes(w)) bmWeeks = w; } catch { /* a blocked store keeps 8 weeks */ }
373
+ function bmDraw() {
374
+ const card = $('#cBm'); card.hidden = false;
375
+ $$('#bmRange button').forEach((b) => b.setAttribute('aria-pressed', String(+b.dataset.w === bmWeeks))); pillOf($('#bmRange'));
376
+ if (!BM) return;
377
+ $('#bmCap').textContent = BM.header;
378
+ $('#bmHint').innerHTML = (BM.lead ? `<b class="mflag">${esc(BM.lead)}</b> ` : '') + esc(BM.body) + ' Press a measure to set its target. The Board draws the same target.';
379
+ $('#bmBody').style.gridTemplateColumns = 'repeat(' + Math.min(4, BM.tiles.length) + ',minmax(0,1fr))';
380
+ $('#bmBody').innerHTML = BM.tiles.map(MT.tileHtml).join('');
381
+ $('#bmNote').textContent = BM.note;
382
+ }
383
+ async function bmLoad() {
384
+ clearTimeout(bmTimer);
385
+ if (!M || !M.board || !M.board.ws) { $('#cBm').hidden = true; return; }
386
+ let r = null;
387
+ try { const res = await fetch('/api/board-metrics-premium?ws=' + encodeURIComponent(M.board.ws) + '&weeks=' + bmWeeks, { credentials: 'same-origin' }); r = await res.json(); } catch { r = null; }
388
+ if (!r || !r.ok || r.state !== 'ready') { BM = null; bmDraw(); $('#bmCap').textContent = 'not read'; $('#bmHint').textContent = 'The Board measures could not be read, so none is shown.' + (r && r.error ? ' The reason: ' + r.error : ''); $('#bmBody').innerHTML = ''; $('#bmNote').textContent = ''; return; }
389
+ BM = r.model; bmDraw();
390
+ if (BM.pending) bmTimer = setTimeout(bmLoad, 4000); // the workflow engine is still deriving Blocked and Idle
391
+ }
392
+ function bmOpen(i) {
393
+ const t = BM && BM.tiles[i]; if (!t) return;
394
+ const vals = t.ser ? `<h3 class="sh">Values</h3><div class="vtb">${t.ser.map((v, j) => `<div><span>${esc(t.wk[j])}</span><b>${v == null ? (t.since ? 'Not kept yet' : 'No runs') : esc(MT.fmt(t, v))}</b></div>`).join('')}</div>` : '';
395
+ const form = t.absent ? `<p class="note" style="margin:12px 0 0">A target can be set once this measure is counted.</p>`
396
+ : `<div class="addf" style="margin-top:14px"><label>Target (${t.lowBetter ? 'at most' : 'at least'})<input id="bmT" inputmode="decimal" maxlength="12" value="${t.tg != null ? esc(String(t.tg)) : ''}" placeholder="For example: ${t.key === 'corrections' ? '10' : t.key === 'merges' ? '5' : '0'}"></label>
397
+ <p class="note" id="bmM" role="status" style="margin:0;min-height:1.2em"></p><div class="cact"><button class="cta" id="bmGo">Save target</button>${t.tg != null ? '<button class="cta alt" id="bmClr">Clear target</button>' : ''}</div></div>`;
398
+ const pane = `<article class="paper doc"><p class="lede" style="margin:0 0 10px">${esc(t.def)}</p>${kv(MT.factRows(t, BM.repo, BM.weeks))}${form}${vals}<p class="note" style="margin-top:12px">${esc(BM.note)}</p></article>`;
399
+ const say = t.tg != null ? `The target is ${t.tg}. Change it or clear it here; the Board draws it too.` : 'No target is set. Type one and save it; the Board draws it too.';
400
+ openDlg({ eye: 'Board measure · real data', title: t.label, sub: BM.repo, say, stream: turnA(ptx(say)), noteKey: null, pane, label: 'Measure' });
401
+ $('#askF').hidden = true;
402
+ $('#oMain').onchange = null;
403
+ $('#oMain').onclick = async (e) => {
404
+ const go = e.target.closest('#bmGo'), clr = e.target.closest('#bmClr'); if (!go && !clr) return;
405
+ const target = clr ? null : $('#bmT').value.trim();
406
+ if (go && target === '') { $('#bmM').textContent = 'Type a number first.'; return; }
407
+ (go || clr).disabled = true; $('#bmM').textContent = 'Saving.';
408
+ const res = await pmPost('/api/board-metric-targets/save', { ws: M.board.ws, key: t.key, target });
409
+ (go || clr).disabled = false;
410
+ if (!res || res.ok !== true) { $('#bmM').textContent = (res && res.error) || 'The target could not be saved.'; return; }
411
+ closeDlg(); toast(clr ? 'The target of ' + t.label + ' is cleared.' : 'The target of ' + t.label + ' is ' + target + '.');
412
+ bmLoad();
413
+ };
414
+ }
415
+ MT.wireTiles($('#bmBody'), () => (BM ? BM.tiles : []), bmOpen);
416
+ $('#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(); });
417
+
366
418
  /* ── load ─────────────────────────────────────────────────────────────────────────────────────────────────────── */
367
419
  function draw() { drawHead(); if (!M.dashboards.some((d) => d.id === dash)) dash = 'all'; drawDash(); drawReps(); drawDock(); onScroll(); }
368
420
  async function load() {
@@ -375,7 +427,7 @@ async function load() {
375
427
  setTimeout(load, 15000);
376
428
  return;
377
429
  }
378
- M = r.model; draw();
430
+ M = r.model; draw(); bmLoad();
379
431
  }
380
432
  $('#brief').textContent = 'Reading the records.';
381
433
  load();
@@ -0,0 +1,68 @@
1
+ /* pm/premium-metric-tiles.js — the tiles of the Board's four measures (initiative briefing-premium-metrics), drawn the same way on the Board's Metrics
2
+ * card and on the Insights page's Board measures card. It draws lib/board-metrics-premium.js's tiles: a number and a chart only where a record counted
3
+ * one, "Not read" where it could not be, and a target's chip, dashed line and outline only where the PM set one on Insights. Nothing here writes.
4
+ *
5
+ * tileHtml(t, i) → one tile's HTML
6
+ * chartAt(el, t, j) → read week j of a chart tile (null: the latest week)
7
+ * wireTiles(body, tiles, open) → pointer and arrow-key reading, Enter and press to open(i) */
8
+ import { $, esc } from './premium-shell.js';
9
+
10
+ const GEO = { W: 220, H: 60, P: 5 };
11
+ export function geo(m) {
12
+ const n = m.ser.length, { W, H, P } = GEO, vs = m.ser.filter((v) => v != null).concat(m.tg != null ? [m.tg] : []);
13
+ const lo = Math.min(...vs), hi = Math.max(...vs), sp = hi - lo || 1;
14
+ return { n, W, H, P, X: (j) => (n > 1 ? P + j * (W - 2 * P) / (n - 1) : W / 2), Y: (v) => P + (1 - (v - lo) / sp) * (H - 2 * P) };
15
+ }
16
+ export const fmt = (m, v) => (+v).toFixed(m.dec) + (m.suf || '');
17
+ const lastJ = (t) => t.ser.reduce((a, v, j) => (v != null ? j : a), 0);
18
+
19
+ export function tileHtml(t, i) {
20
+ if (t.absent) return `<div class="mt1" data-m="${i}" data-op="m:${i}" tabindex="0" role="button" aria-label="${esc(t.label)}: ${esc(t.absent)}. ${esc(t.why)}"><span>${esc(t.label)}</span><b class="mval">${esc(t.absent)}</b><em class="mwk">${esc(t.why)}</em></div>`;
21
+ const chip = t.tg != null ? `<i class="mchip ${t.ok ? 'ok' : 'warn'}">${esc(t.chip)}</i>` : t.look ? '<i class="mchip warn">Needs a look</i>' : '';
22
+ const lab = chip ? `<span class="mlab">${esc(t.label)}${chip}</span>` : `<span>${esc(t.label)}</span>`, off = t.look ? ' off' : '';
23
+ const tgt = t.tg != null ? `<em class="mtg">${esc(t.targetTxt)}</em>` : '';
24
+ const chg = t.change ? `<span class="mchg ${t.change.d === 0 ? '' : t.change.good ? 'good' : 'bad'}">${t.change.d === 0 ? '' : t.change.d > 0 ? '▲ ' : '▼ '}${esc(t.change.txt)}</span>` : '';
25
+ const say = (t.look ? ', needs a look' : '') + (t.tg != null ? ', ' + t.targetTxt + ', ' + t.chip : '');
26
+ if (!t.ser) return `<div class="mt1 ${t.kind}${off}" data-m="${i}" data-op="m:${i}" tabindex="0" role="button" aria-label="${esc(t.label)}, ${esc(t.value)}, ${esc(t.text)}${esc(say)}">${lab}<b class="mval">${esc(t.value)}</b><em class="mwk">${esc(t.text)}</em>${tgt}</div>`;
27
+ const g = geo(t); let ln = '', op = false;
28
+ t.ser.forEach((v, j) => { if (v == null) { op = false; return; } ln += (op ? 'L' : 'M') + g.X(j).toFixed(1) + ',' + g.Y(v).toFixed(1); op = true; });
29
+ const f = Math.max(0, t.ser.findIndex((v) => v != null)), gap = t.ser.slice(f).some((v) => v == null), n1 = g.n - 1, lj = lastJ(t);
30
+ const tgl = t.tg != null ? `<line class="tg" x1="${g.P}" x2="${g.W - g.P}" y1="${g.Y(t.tg).toFixed(1)}" y2="${g.Y(t.tg).toFixed(1)}"/>` : '';
31
+ return `<div class="mt1 mch ${t.kind}${off}" data-m="${i}" data-op="m:${i}" tabindex="0" role="button" aria-label="${esc(t.label)} over ${t.ser.length} weeks, now ${esc(t.value)}${esc(say)}. Use the arrow keys to read each week.">${lab}<b class="mval">${esc(t.value)}</b><em class="mwk">${esc(t.text)}</em>${tgt}${chg}`
32
+ + `<svg viewBox="0 0 ${g.W} ${g.H}">${f > 0 ? `<line class="gp" x1="${g.X(0)}" x2="${g.X(f)}" y1="${g.H - g.P}" y2="${g.H - g.P}"/>` : ''}${gap || f === n1 ? '' : `<path class="ar" d="${ln}L${g.X(n1)},${g.H}L${g.X(f)},${g.H}Z"/>`}${tgl}<path class="ln2" d="${ln}"/><line class="cx" x1="0" x2="0" y1="0" y2="${g.H}"/><circle class="dt" cx="${g.X(lj)}" cy="${g.Y(t.ser[lj])}" r="3.5"/></svg>`
33
+ + `<span class="mfoot"><i>${esc(t.wk[0])}</i>${t.tg != null ? '<i class="tgl">dashed line is the target</i>' : ''}<i>${esc(t.wk[t.wk.length - 1])}</i></span></div>`;
34
+ }
35
+
36
+ /** Read one week of a chart tile: the guide line and dot move, the value and caption change. */
37
+ export function chartAt(el, t, j) {
38
+ if (!t || !t.ser) return;
39
+ const g = geo(t), lj = lastJ(t); j = j == null ? lj : Math.max(0, Math.min(g.n - 1, j));
40
+ const v = t.ser[j], has = v != null, x = g.X(j), y = has ? g.Y(v) : 0, now = j === lj;
41
+ const cx = $('.cx', el), dt = $('.dt', el);
42
+ cx.setAttribute('x1', x); cx.setAttribute('x2', x); dt.setAttribute('cx', x); dt.setAttribute('cy', y); dt.style.opacity = has ? '' : '0';
43
+ el.classList.toggle('hv', !now); el.dataset.j = j;
44
+ const none = t.since ? 'Not kept yet' : 'No runs';
45
+ const val = now ? t.value : has ? fmt(t, v) : none, cap = now ? t.text : 'Week to ' + t.wk[j] + (t.nt[j] ? ' · ' + t.nt[j] : '') + (has && t.tg != null ? ' · ' + t.targetTxt : '');
46
+ $('.mval', el).textContent = val; $('.mwk', el).textContent = cap;
47
+ el.setAttribute('aria-label', t.label + ', ' + (now ? 'now ' : '') + val + ', ' + cap + '. Use the arrow keys to read each week.');
48
+ }
49
+
50
+ /** Pointer and arrow-key reading of the chart tiles in `body`, and Enter, Space or a press to open(i). tiles() gives the tiles drawn now. */
51
+ export function wireTiles(body, tiles, open) {
52
+ const at = (e) => e.target.closest('[data-m]');
53
+ body.addEventListener('click', (e) => { const t = at(e); if (t) open(+t.dataset.m); });
54
+ body.addEventListener('keydown', (e) => {
55
+ const t = at(e); if (!t) return;
56
+ if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); open(+t.dataset.m); return; }
57
+ if (!t.classList.contains('mch') || !/^Arrow(Left|Right)$/.test(e.key)) return;
58
+ e.preventDefault(); const m = tiles()[+t.dataset.m], now = t.dataset.j == null ? lastJ(m) : +t.dataset.j; chartAt(t, m, now + (e.key === 'ArrowLeft' ? -1 : 1));
59
+ });
60
+ body.addEventListener('pointermove', (e) => { const t = at(e); if (!t || !t.classList.contains('mch')) return; const s = $('svg', t).getBoundingClientRect(), m = tiles()[+t.dataset.m], g = geo(m); chartAt(t, m, Math.round(((e.clientX - s.left) / s.width * g.W - g.P) / (g.W - 2 * g.P) * (g.n - 1))); });
61
+ body.addEventListener('pointerout', (e) => { const t = at(e); if (t && t.classList.contains('mch') && !t.contains(e.relatedTarget)) chartAt(t, tiles()[+t.dataset.m], null); });
62
+ }
63
+
64
+ /** The rows of a measure's dialog: what it is now, its target and gap where one is set, how it changed, and where it was counted. */
65
+ export function factRows(t, repo, weeks) {
66
+ return t.absent ? [['Now', t.absent], ['Why', t.why], ['Counted from', repo]]
67
+ : [['Now', t.value], ['Counted', t.text], ['Target', t.tg != null ? fmt(t, t.tg) : 'None set. Set one on Insights'], ['Gap', t.tg != null ? (t.ok ? 'On target' : t.chip + ' the target') : ''], ['Change', t.change ? t.change.txt : ''], ['Better when', t.lowBetter ? 'Lower' : t.lowBetter === false ? 'Higher' : ''], ['Period', 'Week · last ' + (weeks || 8) + ' weeks'], ['Source', repo]].filter((r) => r[1] !== '');
68
+ }
@@ -637,6 +637,13 @@ $('#cap').addEventListener('submit', async (e) => {
637
637
  });
638
638
 
639
639
  /* ── load ────────────────────────────────────────────────────────────────────────────────────────────────── */
640
+ /* ?item=<id> (a row of the Briefing's "What you need to do"): open that item's dialog once, after the first read. */
641
+ let ASKED = new URLSearchParams(location.search).get('item');
642
+ function openAsked() {
643
+ if (!ASKED) return;
644
+ const r = rowOf('work:' + ASKED); ASKED = null;
645
+ if (r) openRow(r); else toast('That item is not on your list any more.');
646
+ }
640
647
  async function load() {
641
648
  let r = null, status = 0;
642
649
  try { const res = await fetch('/api/my-work-premium', { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
@@ -646,6 +653,7 @@ async function load() {
646
653
  return;
647
654
  }
648
655
  M = r.model; draw();
656
+ openAsked();
649
657
  if (!WK) readWk();
650
658
  const mine = dlgOpen() && ((dlgKind === 'item' && openR && S.key === openR.key) || (dlgKind === 'fjobs' && S.key === 'focus:today'));
651
659
  if (mine && dlgKind === 'item') refreshOpen(); else if (mine) drawFocusDlg();
@@ -7,7 +7,7 @@ import { startAgent } from './page-agent.js';
7
7
  import { mountMeeting } from './premium-meeting.js';
8
8
  import { mountFirst } from './premium-first.js';
9
9
  import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words.js';
10
- import { consoleBrief } from './premium-brief.js';
10
+ import { consoleReads, briefOf, needsListOf } from './premium-brief.js';
11
11
  import { momentOf, inText } from './c3-phone-model.js';
12
12
  import { $, $$, esc, store, THEME_KEY, RM, AI, S, theme, toast, kv, H, openDlg, closeDlg, setTab, setMode, CHECK, CHEV, ptx, turnA, turnU, H1, H2, P1, UL, logHtml, loadThread, onScroll, wireRail, pvFeed } from './premium-shell.js';
13
13
  const ICON = {
@@ -39,10 +39,17 @@ function baseline(keys) {
39
39
  /* The headline is the console's "The brief", from the same reads and the same composer (premium-brief.js). Until it comes back, or when its reads fail, the
40
40
  * records-only sentences above stay. Each draw asks again; a late answer to an older ask is dropped. */
41
41
  let briefAsk = 0, shownBrief = null; // once the console brief is shown, a re-read keeps it on screen until the next answer: the hero does not flip back
42
+ /* "What you need to do" is the console's Needs you, from the same reads (premium-brief.js needsListOf). null until they come back, and while the
43
+ * needs reads fail: the records-only rows of the model stay. */
44
+ let CL = null;
42
45
  function drawConsoleBrief() {
43
46
  const ask = ++briefAsk;
44
- consoleBrief().then((r) => {
45
- if (ask !== briefAsk || !r) return;
47
+ consoleReads().then((reads) => {
48
+ if (ask !== briefAsk) return;
49
+ const list = needsListOf(reads, new URLSearchParams(location.search).get('ws'));
50
+ if (list) { CL = list; drawRows(); drawDock(); pvFeed({ ok: true, model: { list: LIST() } }); }
51
+ const r = briefOf(reads);
52
+ if (!r) return;
46
53
  shownBrief = r.parts.map((p) => (p.go ? `<span class="k">${esc(p.t)}</span>` : esc(p.t))).join('');
47
54
  if ($('#brief').innerHTML !== shownBrief) { $('#brief').innerHTML = shownBrief; onScroll(); }
48
55
  $('#brief').title = 'The same paragraph as The brief on the console Briefing. Read from: ' + r.sources.join(', ') + '.';
@@ -58,21 +65,28 @@ function drawHero() {
58
65
 
59
66
  /* ── rows ───────────────────────────────────────────────────────────────────────────────────────────────── */
60
67
  const STAMP = (n) => String(n).padStart(2, '0');
68
+ const CL_ORDER = 'In the order of Needs you on the console: what cannot wait first, then by impact, urgency and effort.';
69
+ /** The list the page draws: the console's Needs you once it is read, else the model's records-only rows. */
70
+ function LIST() {
71
+ if (!CL) return M.list;
72
+ return { rows: CL.map((r, i) => ({ ...r, n: i + 1 })), count: CL.length, more: 0, putOff: [], order: CL_ORDER, pendingNote: '' };
73
+ }
61
74
  function drawRows() {
62
- const rows = M.list.rows, L = $('#rank');
63
- const keys = rows.map((r) => r.key), off = (M.list.putOff || []).map((x) => x.key); // a row put off is not done: it leaves both counts and is named below the list
64
- const base = (M.pending ? keys : baseline(keys)).filter((k) => !off.includes(k)), done = base.filter((k) => !keys.includes(k)).length, total = base.length;
75
+ const LS = LIST(), pend = M.pending && !CL;
76
+ const rows = LS.rows, L = $('#rank');
77
+ const keys = rows.map((r) => r.key), off = (LS.putOff || []).map((x) => x.key); // a row put off is not done: it leaves both counts and is named below the list
78
+ const base = (pend ? keys : baseline(keys)).filter((k) => !off.includes(k)), done = base.filter((k) => !keys.includes(k)).length, total = base.length;
65
79
  const order = rows.slice().sort((a, b) => (pinned.has(b.key) - pinned.has(a.key)) || (a.n - b.n));
66
- L.innerHTML = order.map((r, i) => `<div class="rr${i < 3 ? ' lead' : ''}${i === 0 ? ' first' : ''}" data-key="${esc(r.key)}"${linkOf(r) ? ` data-link="${esc(linkOf(r))}"` : ''}><button class="rhd" aria-haspopup="dialog"><span class="rn">${STAMP(i + 1)}</span><span><span class="rt">${esc(r.title)}${i === 0 ? '<em class="tgf">Do this first</em>' : ''}</span><span class="rs">${r.product ? `<b class="pn">${esc(r.product)}</b>` : ''}${esc(r.subject)}</span><span class="sug"><span>${esc(r.prepared)}</span></span><span class="skip">${esc(r.skip)}</span></span></button><button class="rpin" data-pin="${esc(r.key)}" aria-pressed="${pinned.has(r.key)}" aria-label="Pin ${esc(r.title)} to the top" title="Pin to the top"><svg class="i" viewBox="0 0 24 24"><path d="M9 4h6l-1 6 3 3H7l3-3zM12 13v7"/></svg></button></div>`).join('')
67
- + (M.list.more ? `<p class="note">${M.list.more} more ${M.list.more === 1 ? 'row is' : 'rows are'} not shown here.</p>` : '');
68
- const n = M.list.count;
69
- $('#movesCap').innerHTML = M.pending ? `${n} ${n === 1 ? 'row' : 'rows'} so far · still reading` : n ? `<b>${done} of ${total}</b> done · ${n} ${n === 1 ? 'row' : 'rows'} left` : 'All clear';
80
+ L.innerHTML = order.map((r, i) => `<div class="rr${i < 3 ? ' lead' : ''}${i === 0 ? ' first' : ''}" data-key="${esc(r.key)}"${linkOf(r) ? ` data-link="${esc(linkOf(r))}"` : ''}><button class="rhd" aria-haspopup="dialog"><span class="rn">${STAMP(i + 1)}</span><span><span class="rt">${esc(r.title)}${i === 0 ? '<em class="tgf">Do this first</em>' : ''}</span><span class="rs">${r.product ? `<b class="pn">${esc(r.product)}</b>` : ''}${esc(r.subject)}</span><span class="sug"><span>${esc(r.prepared)}</span></span>${r.skip ? `<span class="skip">${esc(r.skip)}</span>` : ''}</span></button><button class="rpin" data-pin="${esc(r.key)}" aria-pressed="${pinned.has(r.key)}" aria-label="Pin ${esc(r.title)} to the top" title="Pin to the top"><svg class="i" viewBox="0 0 24 24"><path d="M9 4h6l-1 6 3 3H7l3-3zM12 13v7"/></svg></button></div>`).join('')
81
+ + (LS.more ? `<p class="note">${LS.more} more ${LS.more === 1 ? 'row is' : 'rows are'} not shown here.</p>` : '');
82
+ const n = LS.count;
83
+ $('#movesCap').innerHTML = pend ? `${n} ${n === 1 ? 'row' : 'rows'} so far · still reading` : n ? `<b>${done} of ${total}</b> done · ${n} ${n === 1 ? 'row' : 'rows'} left` : 'All clear';
70
84
  $('#movesCap').title = 'Counts rows that cleared since this page first read today. A row clears when its record changes.';
71
- const p = $('#mprog'); p.hidden = !total || !!M.pending; p.setAttribute('aria-valuemax', total); p.setAttribute('aria-valuenow', done); $('b', p).style.width = (total ? done / total * 100 : 0) + '%';
72
- $('#calm').hidden = n > 0 || !!M.pending; $('#calmNext').textContent = '';
73
- $('#order').textContent = M.pending ? M.list.pendingNote : n ? M.list.order : '';
74
- $('#order').hidden = !n && !M.pending;
75
- const po = M.list.putOff || [];
85
+ const p = $('#mprog'); p.hidden = !total || pend; p.setAttribute('aria-valuemax', total); p.setAttribute('aria-valuenow', done); $('b', p).style.width = (total ? done / total * 100 : 0) + '%';
86
+ $('#calm').hidden = n > 0 || pend; $('#calmNext').textContent = '';
87
+ $('#order').textContent = pend ? LS.pendingNote : n ? LS.order : '';
88
+ $('#order').hidden = !n && !pend;
89
+ const po = LS.putOff || [];
76
90
  $('#putoff').textContent = po.length ? 'Put off by you: ' + po.map((x) => x.text).join('; ') + '. Not counted as done.' : '';
77
91
  $('#putoff').hidden = !po.length;
78
92
  }
@@ -80,13 +94,16 @@ $('#rank').addEventListener('click', (e) => {
80
94
  const pin = e.target.closest('.rpin');
81
95
  if (pin) { const k = pin.dataset.pin; pinned.has(k) ? pinned.delete(k) : pinned.add(k); drawRows(); toast(pinned.has(k) ? 'Pinned to the top for this session.' : 'Unpinned.'); return; }
82
96
  const h = e.target.closest('.rhd');
83
- if (h) openRow(M.list.rows.find((r) => r.key === h.closest('.rr').dataset.key));
97
+ if (!h) return;
98
+ const r = LIST().rows.find((x) => x.key === h.closest('.rr').dataset.key);
99
+ if (r && r.go) { location.assign(r.go); return; } // a console row opens its item on its own page: My work, the initiative, or the console
100
+ openRow(r);
84
101
  });
85
102
 
86
103
  /* ── today ──────────────────────────────────────────────────────────────────────────────────────────────── */
87
104
  const linkOf = (r) => ((r.from || []).find((x) => /^meeting:/.test(x)) || '').replace(/^meeting:/, '');
88
105
  function evHtml(e, i) {
89
- const lnk = e.kind === 'meeting' && (M.list.rows || []).some((r) => linkOf(r) === e.title) ? e.title : '';
106
+ const lnk = e.kind === 'meeting' && (LIST().rows || []).some((r) => linkOf(r) === e.title) ? e.title : '';
90
107
  return `<button class="ev src-${e.kind}"${lnk ? ` data-link="${esc(lnk)}"` : ''} data-i="${i}" style="animation:rise .6s var(--ease) both"><time>${esc(e.t)}</time><span class="gl-t"><svg class="i" viewBox="0 0 24 24">${ICON[e.kind]}</svg></span><span><b>${esc(e.title)}</b><span class="d">${esc(e.sub)}${e.product ? ' · ' + esc(e.product) : ''}</span></span></button>`;
91
108
  }
92
109
  const ALL = () => M.today.ahead.concat(M.today.earlier);
@@ -135,7 +152,10 @@ document.addEventListener('click', (e) => {
135
152
  });
136
153
 
137
154
  /* ── dock ───────────────────────────────────────────────────────────────────────────────────────────────── */
138
- function drawDock() { $('#dN').textContent = M.dock.needs == null ? '·' : M.dock.needs; $('#dLab').textContent = M.dock.needs == null ? 'still reading' : M.dock.needs === 0 ? 'need you' : M.dock.label; }
155
+ function drawDock() {
156
+ const n = CL ? CL.length : M.dock.needs;
157
+ $('#dN').textContent = n == null ? '·' : n; $('#dLab').textContent = n == null ? 'still reading' : n === 0 ? 'need you' : CL ? (n === 1 ? 'needs you' : 'need you') : M.dock.label;
158
+ }
139
159
 
140
160
  const SEL = {}; // the option chosen on each row, for this session
141
161
  const START = {}; // 'ask' while the PM is confirming a start, by row key
@@ -189,13 +209,20 @@ let openR = null;
189
209
  function plainDialog(r) {
190
210
  return { eye: 'Detail', logTitle: 'Read from the repository', log: ['Read the record'], say: [r.prepared, r.skip].filter(Boolean).join(' '), head: 'What is known', facts: [['Subject', r.subject], ['Next', r.prepared], ['If you skip', r.skip && r.skip.replace(/^If you skip: /, '')]].filter((x) => x[1]), opts: [], sel: null, nodef: '', pane: { label: 'Detail', file: '', h: r.title, intro: r.subject || '', rows: [], paras: [] } };
191
211
  }
212
+ /* A decision from the console's Needs you: what its record says, and its source. Choosing an option on an engine card is not recorded from here. */
213
+ function consoleDialog(r) {
214
+ const facts = [['Kind', r.subject]].concat((r.facts || []).map((f) => ['Fact', f]), r.options && r.options.length ? [['Options', r.options.join(' · ')]] : []);
215
+ return { eye: 'Needs you', logTitle: 'Read from the console Briefing', log: ['Read GET /api/briefing', 'Kept the row Needs you shows'], say: r.prepared || 'This is on the console\'s Needs you.', head: 'What is known', facts, opts: [], sel: null,
216
+ nodef: r.options && r.options.length ? 'Choosing an option is recorded on the console Briefing, not here.' : '', link: r.url || null, linkLabel: r.urlLabel || null, noAsk: true,
217
+ pane: { label: 'Detail', file: 'Needs you', h: r.title, intro: r.subject || '', rows: [], paras: (r.facts || []).slice(0, 6) } };
218
+ }
192
219
  function openRow(r) {
193
220
  if (!r) return;
194
- if (!r.dialog) r = { ...r, dialog: plainDialog(r) };
221
+ if (!r.dialog) r = { ...r, dialog: r.src ? consoleDialog(r) : plainDialog(r) };
195
222
  openR = r; const d = r.dialog;
196
223
  openDlg({ eye: d.eye + ' · real data', title: d.title || r.title, sub: d.sub || r.subject, say: d.say, stream: turnA(logHtml(d)) + turnA(ptx(d.say)) + cardHtml(r), noteKey: r.key, pane: paneHtml(r), label: d.pane.label });
197
224
  ctaState(r);
198
- loadThread(r.key);
225
+ if (r.dialog.noAsk) { $('#askF').hidden = true; $('#askNote').hidden = true; } else loadThread(r.key); // the read-only agent answers about the model's rows only
199
226
  setTimeout(() => { const b = $('#dBody'); b.scrollTop = b.scrollHeight; }, 120);
200
227
  }
201
228
  function showErr(msg) { const e = $('#cardErr'); if (!e) { toast(msg); return; } e.textContent = msg; e.hidden = false; }
@@ -899,7 +926,7 @@ async function load() {
899
926
  const ws = new URLSearchParams(location.search).get('ws');
900
927
  try { const res = await fetch('/api/briefing-premium' + (ws ? '?ws=' + encodeURIComponent(ws) : ''), { credentials: 'same-origin' }); status = res.status; r = await res.json(); } catch { r = null; }
901
928
  clearInterval(readTimer);
902
- pvFeed(r);
929
+ pvFeed(CL && r && r.ok ? { ok: true, model: { list: LIST() } } : r); // the bell counts what the list shows: the console's Needs you once it is read
903
930
  if (r && r.state === 'reading') {
904
931
  // the first read has no end I can promise: say how long it has run, and ask again
905
932
  const t0 = Date.now() - (r.elapsed_ms || 0), tick = () => { $('#brief').textContent = 'Reading the products for the first time. ' + Math.round((Date.now() - t0) / 1000) + ' s so far. This page shows nothing until it has read, rather than guess.'; };
@@ -5,7 +5,7 @@
5
5
  <meta name="pmos-nonce" content="" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
7
7
  <title>PMOS · Insights</title>
8
- <!-- The premium Insights (initiative briefing-premium-insights, slice 9). The fourth place on the rail, in the Briefing's shell. It reads GET /api/insights-premium, built from the KR metric records and the report files the console's Reports tab reads. It presses nothing and writes nothing. -->
8
+ <!-- The premium Insights (initiative briefing-premium-insights, slice 9). The fourth place on the rail, in the Briefing's shell. It reads GET /api/insights-premium, built from the KR metric records and the report files the console's Reports tab reads, and GET /api/board-metrics-premium for the Board measures card, whose one press sets a target (POST /api/board-metric-targets/save). -->
9
9
  <link rel="preload" href="/vendor/geist-var.woff2" as="font" type="font/woff2" crossorigin />
10
10
  <link rel="stylesheet" href="/pm/premium.css" />
11
11
  <link rel="stylesheet" href="/pm/premium-insights.css" />
@@ -41,6 +41,12 @@
41
41
  <button class="glass round" id="theme" aria-label="Switch light or dark"><svg class="i" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg></button></div>
42
42
  </header>
43
43
  <section class="hero hero-slim"><p class="brief rise" style="--d:2" id="brief" aria-live="polite"></p></section>
44
+ <section class="card rise" style="--d:4" id="cBm" aria-labelledby="hBm" hidden>
45
+ <div class="ch"><span class="ic"><svg class="i" viewBox="0 0 24 24"><path d="M4 20V10M10 20V4M16 20v-8M22 20H2"/></svg></span><h2 id="hBm">Board measures</h2><small id="bmCap"></small><div class="seg mper" id="bmRange" role="group" aria-label="Range"><i class="pill"></i><button data-w="8" aria-pressed="true">8 weeks</button><button data-w="26" aria-pressed="false">26 weeks</button><button data-w="52" aria-pressed="false">52 weeks</button></div></div>
46
+ <p class="mhint" id="bmHint"></p>
47
+ <div class="bt2 ibt" id="bmBody"></div>
48
+ <p class="note" id="bmNote"></p>
49
+ </section>
44
50
  <div class="nl">
45
51
  <div class="nlc">
46
52
  <section class="card rise" style="--d:5" id="cDash" aria-labelledby="hDash">
@@ -57,7 +63,7 @@
57
63
  </section>
58
64
  </aside>
59
65
  </div>
60
- <p class="foot" id="foot">Charts read the KR metric records of this workspace and never invent a number. A press here records only what it says: a dashboard or a chart in the workspace's state folder, a report setup, request or dismissal in the report ledger, or a report's look in its design folder. Left out: run-based charts such as corrections per 100 runs (they belong to the Board's Metrics card), and any measure no record holds. Nothing is sent from this page.</p>
66
+ <p class="foot" id="foot">Charts read the KR metric records of this workspace and never invent a number. A press here records only what it says: a dashboard or a chart in the workspace's state folder, a report setup, request or dismissal in the report ledger, or a report's look in its design folder. The Board measures card counts the Board's four measures from the repository, over 8, 26 or 52 weeks; a target set there is saved in the workspace's state folder and drawn on the Board too. Left out: any measure no record holds. Nothing is sent from this page.</p>
61
67
  </main>
62
68
  <noscript>This page needs JavaScript.</noscript>
63
69
  <script type="module" src="/pm/premium-insights.js"></script>