create-pmos 0.480.0 → 0.481.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 (47) hide show
  1. package/package.json +13 -14
  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-board-test.js +1 -3
  7. package/workspace/briefing-premium-insights-test.js +6 -6
  8. package/workspace/briefing-premium-metrics-test.js +5 -84
  9. package/workspace/briefing-premium-sources-test.js +6 -1
  10. package/workspace/changelog.json +12 -0
  11. package/workspace/guide/briefing-premium.md +9 -3
  12. package/workspace/guide/programs.md +4 -2
  13. package/workspace/lib/board-pack.js +1 -1
  14. package/workspace/lib/goal-chat.js +3 -0
  15. package/workspace/lib/metric-drafts.js +37 -6
  16. package/workspace/lib/ready-reports.js +6 -4
  17. package/workspace/lib/report-chat.js +1 -0
  18. package/workspace/lib/routes-metric-drafts.js +2 -1
  19. package/workspace/lib/routes-ready-reports.js +6 -2
  20. package/workspace/package-lock.json +2 -2
  21. package/workspace/package.json +1 -1
  22. package/workspace/premium-html-viewer-test.js +2 -0
  23. package/workspace/public/pm/bd-acts.js +2 -20
  24. package/workspace/public/pm/bd-prog-panel.js +1 -2
  25. package/workspace/public/pm/cozy-board.css +0 -11
  26. package/workspace/public/pm/cozy-home.css +5 -0
  27. package/workspace/public/pm/cozy-insights.css +31 -0
  28. package/workspace/public/pm/cozy-vw-rp.css +5 -0
  29. package/workspace/public/pm/dash-view.css +19 -0
  30. package/workspace/public/pm/dash-view.js +49 -11
  31. package/workspace/public/pm/goal-chat.js +10 -3
  32. package/workspace/public/pm/home-app.js +31 -89
  33. package/workspace/public/pm/home-chat.js +19 -4
  34. package/workspace/public/pm/home-goal.js +1 -1
  35. package/workspace/public/pm/home-line.js +16 -1
  36. package/workspace/public/pm/home-list.js +1 -1
  37. package/workspace/public/pm/premium-board.js +2 -2
  38. package/workspace/public/pm/premium-insights.js +64 -11
  39. package/workspace/public/pm/premium-report-read.js +34 -4
  40. package/workspace/public/pm/premium-report-tab.js +57 -6
  41. package/workspace/public/pm/premium-vw-file.js +4 -0
  42. package/workspace/public/pm/prog-page.css +1 -1
  43. package/workspace/public/pm/prog-page.js +6 -3
  44. package/workspace/public/pm/report-chat.js +8 -2
  45. package/workspace/public/pm/trends-review.js +55 -0
  46. package/workspace/ready-dash-ui-test.js +1 -3
  47. package/workspace/test-files.json +1 -0
@@ -159,8 +159,11 @@ export function mountChat(el, host) {
159
159
  }
160
160
  function queuedHtml() {
161
161
  const q = host.queued ? host.queued(sid()) : [];
162
- const said = new Set(((C.conv && C.conv.messages) || []).filter((m) => m.role === 'user').map((m) => shownUser(m.text))); // as typed: PMOS wraps a report ask in its rule
163
- return q.filter((x) => !said.has(shownUser(x.text))).map((x) => `<div class="hm-q"><div class="hm-qb">${userHtml(x.text)}</div><span class="hm-qn">${esc(role().name)} reads it after this tool call, in seconds<button type="button" class="hm-qx" data-hm-qdel="${esc(x.at)}" aria-label="Take it back" title="Take it back">${SVG(XX, 13)}</button></span></div>`).join('');
162
+ // as typed: PMOS wraps a report ask or a /goal in its rule, adds the files line, and a live session joins the lines (batch 22 item 10:
163
+ // a /goal sent with a file stayed "reads it after this tool call" after Claude had read it), so compare the words alone
164
+ const key = (t) => splitFiles(shownUser(t)).text.replace(/\s+/g, ' ').trim();
165
+ const said = new Set(((C.conv && C.conv.messages) || []).filter((m) => m.role === 'user').map((m) => key(m.text)));
166
+ return q.filter((x) => !said.has(key(x.text))).map((x) => `<div class="hm-q"><div class="hm-qb">${userHtml(x.text)}</div><span class="hm-qn">${esc(role().name)} reads it after this tool call, in seconds<button type="button" class="hm-qx" data-hm-qdel="${esc(x.at)}" aria-label="Take it back" title="Take it back">${SVG(XX, 13)}</button></span></div>`).join('');
164
167
  }
165
168
  const sid = () => (C.t && C.t.sid) || (C.th && C.th.session) || null;
166
169
  // A loose chat that reads like one initiative gets one quiet chip at its top: "Looks like <initiative> · Link it ×" (XvALinkSuggest).
@@ -257,11 +260,19 @@ export function mountChat(el, host) {
257
260
  put(pl, h); pl.hidden = !h;
258
261
  }
259
262
  /** The Goal view in the Viewer: the steps of a goal or session at work, else the goal's plan or how it ended. */
263
+ /** The draft of Claude's newest goal question: what is known so far, before a plan is ready. */
264
+ function askedDraft() {
265
+ const ms = (C.conv && C.conv.messages) || [];
266
+ for (let i = ms.length - 1; i >= 0; i--) { if (ms[i].role !== 'assistant') continue; const b = splitGoal(ms[i].text).block; if (b && b.draft && typeof b.draft === 'object' && Object.keys(b.draft).length) return b.draft; }
267
+ return null;
268
+ }
260
269
  function goalViewNow() {
261
270
  const vo = GU.viewOpts(); // the plan editor, while the PM changes a working goal in the Viewer (home-goal.js)
262
271
  if (vo.edit) return goalViewHtml(C.th && C.th.goal, readyDraft(C.conv), vo);
263
272
  const m = lineModel({ view: true }), g = C.th && C.th.goal;
264
273
  if (m && m.kind === 'goal' && g && (g.state === 'started' || g.state === 'waiting')) m.change = true;
274
+ // while the goal is still being agreed, the Viewer shows the goal as agreed so far, not an empty "Steps" (batch 22 item 10)
275
+ if (g && g.state === 'grilling') { const h = goalViewHtml(g, readyDraft(C.conv) || askedDraft(), vo); if (h) return h; }
265
276
  return m ? viewHtml(m) : goalViewHtml(g, readyDraft(C.conv), vo);
266
277
  }
267
278
  function plPress(k) {
@@ -331,7 +342,7 @@ export function mountChat(el, host) {
331
342
  function openGoal() {
332
343
  const html = goalViewNow(); if (!html) return null;
333
344
  const m = lineModel({ view: true });
334
- return import('./premium-viewer.js').then((V) => { V.vwStyle('doc'); return V.vwOpen({ id: 'goal', title: m && m.kind !== 'goal' ? 'Steps' : 'Goal', icon: 'goal', render: (p) => { p.innerHTML = p.__h = goalViewNow(); GU.fill(p); GU.wire(p); p.onclick = async (e) => { const b = e.target.closest('[data-pl]'); if (b) { plPress(b.dataset.pl); return; } const gb = e.target.closest('button'); if (gb && await GU.press(gb)) return; const g = e.target.closest('[data-goal]'); if (g) goalPress(g); }; } }); }).then((r) => { drawLine(); return r; });
345
+ return import('./premium-viewer.js').then((V) => { V.vwStyle('doc'); return V.vwOpen({ id: 'goal', title: m && m.kind !== 'goal' && !(C.th && C.th.goal && C.th.goal.state === 'grilling') ? 'Steps' : 'Goal', icon: 'goal', render: (p) => { p.innerHTML = p.__h = goalViewNow(); GU.fill(p); GU.wire(p); p.onclick = async (e) => { const b = e.target.closest('[data-pl]'); if (b) { plPress(b.dataset.pl); return; } const gb = e.target.closest('button'); if (gb && await GU.press(gb)) return; const g = e.target.closest('[data-goal]'); if (g) goalPress(g); }; } }); }).then((r) => { drawLine(); return r; });
335
346
  }
336
347
  async function goalPress(gb) {
337
348
  const act = gb.dataset.goal;
@@ -468,7 +479,11 @@ export function mountChat(el, host) {
468
479
  if ('goalOpen' in d) { e.preventDefault(); openGoal(); return; }
469
480
  if (await GU.press(b)) return; // home-goal.js: the method menu, the plan editor, skip and Undo, the /goal choice
470
481
  if (d.goal) { goalPress(b); return; }
471
- if (d.chatSay) { b.disabled = true; send(d.chatSay); return; }
482
+ if (d.chatSay) { // a goal answer stays pressed until Claude's next turn (batch 22 item 10: a press did not feel pressed)
483
+ b.disabled = true; b.classList.add('on');
484
+ if (b.classList.contains('gchip')) { C.said = { n: ((C.conv && C.conv.messages) || []).length, text: d.chatSay }; b.parentElement.querySelectorAll('button').forEach((x) => { x.disabled = true; }); }
485
+ send(d.chatSay); return;
486
+ }
472
487
  if (d.slash) { pickSlash(d.slash); return; }
473
488
  if (d.askPick) {
474
489
  const card = b.closest('.tc'), btn = card && card.querySelector('[data-ask-send]'), at = btn ? btn.dataset.askSend : null, ask = at != null && askOf(at); if (!ask) return;
@@ -36,7 +36,7 @@ export function goalUi(cx) {
36
36
  function blockOpts(mi, block, live) {
37
37
  const g = goal();
38
38
  const b = block && block.step === 'ready' && mi === newestReady() ? { ...block, draft: readyDraft() || block.draft } : block;
39
- return { block: b, live, state: g && g.state, menu: live && C.goalMenu === mi, edit: live && C.goalEdit && C.goalEdit.where === 'chat' ? C.goalEdit.snap : null };
39
+ return { block: b, live, state: g && g.state, menu: live && C.goalMenu === mi, edit: live && C.goalEdit && C.goalEdit.where === 'chat' ? C.goalEdit.snap : null, said: live && C.said && C.said.n === ((C.conv && C.conv.messages) || []).length ? C.said.text : '' };
40
40
  }
41
41
  /** The Goal view in the Viewer: the editor while the PM changes a working goal there. */
42
42
  const viewOpts = () => ({ live: cx.live(), edit: C.goalEdit && C.goalEdit.where === 'view' ? C.goalEdit.snap : null });
@@ -68,13 +68,28 @@ function window5(items, cur, all) {
68
68
  return { items: items.slice(from, from + CAP), more: items.length };
69
69
  }
70
70
 
71
+ const normP = (x) => String(x == null ? '' : x).toLowerCase().replace(/[^a-z0-9]+/g, ' ').trim();
72
+ /** The same match as lib/goal-chat.js matchPoints: equal, or one holds the other when both are 12 characters or more. */
73
+ const samePoint = (a, b) => { const n = normP(a), r = normP(b); return !!n && !!r && (n === r || (r.length >= 12 && n.length >= 12 && (r.includes(n) || n.includes(r)))); };
74
+ /** The done points the session's to-do list marks completed, and the one it marks in progress. */
75
+ export function liveOf(pts, conv) {
76
+ const steps = conv && Array.isArray(conv.steps) ? conv.steps : [];
77
+ const done = pts.filter((p) => steps.some((s) => s && s.state === 'done' && samePoint(p, s.text)));
78
+ const st = steps.find((s) => s && s.state === 'now'), now = st ? pts.find((p) => samePoint(p, st.text)) || null : null;
79
+ return { done, now };
80
+ }
71
81
  /** A working goal (started, or waiting on the PM) as the line's model. goal: the GET /thread goal record. */
72
82
  export function goalModel(goal, conv, o = {}) {
73
83
  if (!goal || !goal.draft || !['started', 'waiting'].includes(goal.state)) return null;
74
84
  const d = goal.draft, pts = Array.isArray(d.done) ? d.done : [], met = new Set(goal.met || []);
75
85
  const skip = new Set(goal.skipped || []);
86
+ // live, inside a round (batch 22 item 11): the session's own to-do list names the done points (lib/goal-chat.js startMessage), so a
87
+ // point Claude marked completed ticks now and the one in progress is the current one. The round's report still decides at its end.
88
+ const live = liveOf(pts, conv);
89
+ for (const x of live.done) met.add(x);
76
90
  const count = pts.filter((x) => !skip.has(x)).length;
77
- const cur = pts.findIndex((x) => !met.has(x) && !skip.has(x));
91
+ const nowAt = live.now ? pts.indexOf(live.now) : -1;
92
+ const cur = nowAt >= 0 && !met.has(live.now) && !skip.has(live.now) ? nowAt : pts.findIndex((x) => !met.has(x) && !skip.has(x));
78
93
  const limit = Number.isInteger(d.limit) ? d.limit : 12;
79
94
  const asking = goal.state === 'waiting' || !!o.asking;
80
95
  const run = running(conv) || goal.state === 'started';
@@ -186,7 +186,7 @@ export function programGroups(D, groups, products, o, now) {
186
186
  return { id: 'pt:' + pr.id + ':' + t.key, kind: 'ptask', program: pr.id, key: t.key, ws: t.ws, name: t.title, check: true, state: 'quiet', mine: isMe(D, t.owner), late: d != null && d < 0, due: t.due || '',
187
187
  hint: [t.owner, d == null ? '' : d < 0 ? plural(-d, 'day', 'days') + ' late' : d === 0 ? 'due today' : 'due ' + shortDay(t.due)].filter(Boolean).join(' · ') };
188
188
  });
189
- const subs = ((G && G.products) || []).map((sp) => { const at = products.findIndex((p) => p.name === sp.name); return { name: sp.name, initials: at >= 0 ? products[at].initials : initialsOf(sp.name), tone: at >= 0 ? products[at].tone : 0, inis: sp.rows.map((x) => x.r) }; });
189
+ const subs = ((G && G.products) || []).map((sp) => { const at = products.findIndex((p) => p.name === sp.name); return { name: sp.name, ws: at >= 0 ? products[at].ws || '' : '', initials: at >= 0 ? products[at].initials : initialsOf(sp.name), tone: at >= 0 ? products[at].tone : 0, inis: sp.rows.map((x) => x.r) }; });
190
190
  const inis = subs.flatMap((x) => x.inis);
191
191
  // a program with no open initiative here (just made, or its initiatives all cancelled or archived) still shows, under all products or its
192
192
  // home product, so the PM finds it and can move initiatives in; an unticked home product takes it off Home (batch 12 item 5)
@@ -895,11 +895,11 @@ async function loadDocMeta(list) {
895
895
  const docMeta = (p, ws) => { const d = DM[(ws || (M && M.board.ws) || '') + ':' + p]; return d && !d.none ? d : null; };
896
896
 
897
897
  /* ── the shell's bell sits before New initiative, as the design orders the tools; Escape closes a popover, then the panel ──────── */
898
- /* the ⋯ menu ("More: sources, archived, export" in AgBoard and BdHead): the Board adds Metrics and Cancelled and archived */
898
+ /* the ⋯ menu ("More: sources, archived, export" in AgBoard and BdHead): the Board adds Cancelled and archived (Metrics moved to Intelligence › Delivery trends, batch 22 item 4) */
899
899
  {
900
900
  const st = $('#settingsBtn'), mb = $('#moreBtn');
901
901
  if (mb) { mb.setAttribute('aria-label', 'More: sources, archived, export'); mb.title = 'More: sources, archived, export'; }
902
- if (st) st.insertAdjacentHTML('beforebegin', ['metrics', 'gone'].map((k) => `<button role="menuitem" id="${k === 'metrics' ? 'bdMetrics' : 'bdGone'}" aria-haspopup="dialog" data-open="${k}">${k === 'metrics' ? 'Metrics' : 'Cancelled and archived'}</button>`).join(''));
902
+ if (st) st.insertAdjacentHTML('beforebegin', '<button role="menuitem" id="bdGone" aria-haspopup="dialog" data-open="gone">Cancelled and archived</button>');
903
903
  $$('#moreMenu [data-open]').forEach((b) => { b.onclick = () => { if (M) Acts.open[b.dataset.open]($('#moreBtn')); }; });
904
904
  }
905
905
  window.addEventListener('keydown', (e) => {
@@ -40,6 +40,7 @@ import * as IM from './impact.js'; // Your impact's ✦ line (batch 16 item 7)
40
40
  import * as AD from './cozy-adler.js'; // Adler in Claude's ✦ line only, never in a chart (batch 16 item 2, canvas AdH3, AdM3)
41
41
  import * as RL from './ready-lib.js'; // the ready-made reports of every program, product and initiative (batch 17 item 1, PbA6, PbG4)
42
42
  import * as RI from './premium-report-intel.js'; // a report made from Intelligence (batch 15 item 4): the header icon, the ✦ proposals, the draft panel
43
+ import * as TRV from './trends-review.js'; // Delivery trends' words (batch 22 item 4): the month line, Up N vs last week, What moved it
43
44
  import * as OK from './okr-list.js'; // Claude runs the OKRs (batch 16 item 6, 6-B): the goal list, its drafts, the ✦ line, ⋯ › Metrics, the notify choice
44
45
  import * as IP2 from './ins-pane.js'; // Intelligence as the first panel (panels on Board and Intelligence, P-B): the narrow form, Moved by, the open row
45
46
  import * as GC from './goals-clear.js';
@@ -229,7 +230,7 @@ document.addEventListener('cz-viewer', (e) => {
229
230
  const d = e.detail || {}, id = d.open && /^goal:/.test(d.id || '') ? d.id.slice(5) : null;
230
231
  if ((new URLSearchParams(location.search).get('goal') || null) !== id) addr({ goal: id });
231
232
  });
232
- function setView(id) { dash = id; closeLib(); redraw(); noteOpen(); }
233
+ function setView(id) { dash = id; if (new URLSearchParams(location.search).has('view')) addr({ view: null }); closeLib(); redraw(); noteOpen(); }
233
234
  /* the view on screen, noted once a day per view (feedback batch 16 item 1; POST /api/page-opens, local only): it is what lets the ✦ strip say
234
235
  * "You open this every week" from a record, never from a guess. Portfolio is no one product's view, so it is not noted. */
235
236
  const NOTED = new Set();
@@ -978,7 +979,7 @@ const GRP_PILL = (L) => {
978
979
  function drawGoals() {
979
980
  const G = goalsShown(), T = $('#goalTbl');
980
981
  document.body.classList.toggle('ins-trv', dash === TRENDS);
981
- if (dash === TRENDS) { T.innerHTML = bmHtml(true); $('#goalCards').innerHTML = ''; return; }
982
+ if (dash === TRENDS) { T.innerHTML = bmHtml(true); T.hidden = false; $('#goalCards').innerHTML = ''; return; }
982
983
  const head = `<div class="ins-tr ins-th ${COLS}" role="row"><div role="columnheader">Key results <span>${G.length} · ${esc(per ? per.label : '')}</span></div><div role="columnheader">Now, of target <span class="ins-lg"><span><i class="ins-tdk"></i>today</span></span></div><div role="columnheader">So far</div><div role="columnheader">By its date</div><div role="columnheader" class="ins-mvh">Moved by <span class="ins-lg"><span><i class="ins-trk"><i class="k"></i></i>Skipped</span><span><i class="ins-trk"><i class="p m"></i></i>Milestone</span></span></div></div>`;
983
984
  const D = curDash();
984
985
  if (!M.goals.filter(isKr).length) {
@@ -1029,7 +1030,7 @@ $('#goalCards').addEventListener('click', (e) => { if (e.target.closest('a, .okr
1029
1030
  $('#goalTbl').addEventListener('click', (e) => {
1030
1031
  if (e.target.closest('#goalsAll')) { find = ''; $('#findIn').value = ''; clearFilter(); per = periods()[3]; redraw(); return; }
1031
1032
  if (e.target.closest('a')) return;
1032
- const tile = e.target.closest('[data-tile]'); if (tile) { if (tgOpen === tile.dataset.tile) closeTarget(true); else openTarget(tile.dataset.tile); return; }
1033
+ const tile = e.target.closest('[data-tile], [data-mt]'); if (tile) { if (tgOpen) closeTarget(); openTile(tile.dataset.tile || tile.dataset.mt); return; }
1033
1034
  if (e.target.closest('.okr-dr')) return; // a draft under a row has its own presses
1034
1035
  const bu = e.target.closest('[data-budget]'); if (bu) { openBudget(bu.dataset.budget); return; }
1035
1036
  const r = e.target.closest('[data-goal]'); if (r) pressGoal(r.dataset.goal);
@@ -1341,6 +1342,7 @@ $('#goalCards').addEventListener('click', (e) => { if (e.target.closest('a')) re
1341
1342
  * target's line under it. A press opens the target popover over the tiles. In the Delivery trends view the tiles stand three to a row. ─── */
1342
1343
  const TILES = [['blocked', 'Blocked tickets'], ['late', 'Late initiatives'], ['idle', 'Idle 30+ days'], ['scope', 'Scope added'], ['merges', 'Merged a week'], ['corrections', 'Corrections / 100 runs']];
1343
1344
  const TILE_DIR = { merges: 'at least' }; // more merges is better; every other measure is better lower
1345
+ const TILE_DEF = { late: 'Open initiatives the workflow engine reports as late today. Earlier weeks count the initiatives late today whose end date had already passed; the Board keeps no history of a status.', scope: 'Initiatives whose planned start falls in the week.' };
1344
1346
  const numsOf = (ser) => (ser || []).filter((v) => typeof v === 'number' && Number.isFinite(v));
1345
1347
  /** How a tile's target is read: its direction and its start (POST /api/insights-records/tile), whether the latest reading meets it, and the tile's
1346
1348
  * colour: amber only after the last two readings both miss it (IsTarget), or the one value when there is no series. */
@@ -1358,14 +1360,16 @@ function tileOf(key) {
1358
1360
  if (key === 'late' || key === 'scope') {
1359
1361
  const x = TR[key] || {};
1360
1362
  if (x.value == null) return { v: 'Not read', s: 'the initiatives are not read', abs: true, T: { line: '' } };
1361
- const tg = Number.isFinite(own) ? own : null;
1362
- t = { v: String(x.value), ser: x.ser || null, s: key === 'late' ? 'late today' : 'started this week', tg, base: key === 'late' && x.value > 0 };
1363
+ const tg = Number.isFinite(own) ? own : null, bw = BM && (BM.tiles || []).find((y) => y.wk);
1364
+ t = { v: String(x.value), ser: x.ser || null, s: key === 'late' ? 'late today' : 'started this week', note: key === 'late' ? 'late today' : 'started this week', tg, base: key === 'late' && x.value > 0,
1365
+ change: TRV.changeOf(x.ser, 0), wk: bw ? bw.wk : null, def: TILE_DEF[key] };
1363
1366
  } else {
1364
1367
  if (!BM) return { v: bmErr ? 'Not read' : 'Reading', s: '', abs: true, T: { line: '' } };
1365
1368
  const b = (BM.tiles || []).find((x) => x.key === key);
1366
1369
  if (!b) return { v: 'Not read', s: '', abs: true, T: { line: '' } };
1367
- if (b.absent) return { v: b.absent, s: '', abs: true, T: { line: '' } };
1368
- t = { v: b.value, ser: b.ser, s: b.targetTxt || '', tg: b.tg != null ? b.tg : null, base: !!b.look || b.kind === 'warn' || b.kind === 'bad' };
1370
+ if (b.absent) return { v: b.absent, s: '', abs: true, why: b.why || '', def: b.def, T: { line: '' } };
1371
+ t = { v: b.value, ser: b.ser, s: b.targetTxt || '', note: b.text || '', tg: b.tg != null ? b.tg : null, base: !!b.look || b.kind === 'warn' || b.kind === 'bad',
1372
+ change: b.change || null, wk: b.wk || null, nt: b.nt || null, def: b.def, dec: b.dec || 0 };
1369
1373
  }
1370
1374
  t.T = targetOf(key, t);
1371
1375
  t.warn = t.T.tg !== null ? t.T.miss2 : t.base;
@@ -1379,12 +1383,60 @@ function miniSpark(ser, W = 150, H = 18) {
1379
1383
  return `<svg class="ins-tsp" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" preserveAspectRatio="none" role="presentation"><polygon class="ar" points="${first[0]},${H} ${pts.join(' ')} ${last[0]},${H}"/><polyline class="ln" points="${pts.join(' ')}"/><circle class="dt" cx="${last[0]}" cy="${last[1]}" r="3.6"/></svg>`;
1380
1384
  }
1381
1385
  let tgOpen = null; // the tile whose target popover is open
1386
+ /** The six tiles with their words (label, value, change) as the trends view reads them. */
1387
+ const trendTiles = () => TILES.map(([k, l]) => Object.assign({ key: k, label: l }, tileOf(k)));
1388
+ const CHAT = 'M4 5h16v11H9l-5 4z';
1389
+ /** The ✦ month line (canvas MxA): the Board's measures in one sentence; the chat icon takes it to Strategist. Nothing read, no line. */
1390
+ function monthStrip() {
1391
+ const d = new Date((M.today || iso(today())) + 'T00:00:00Z'), open = BM && BM.counted ? BM.counted.open : 0;
1392
+ const line = TRV.monthLine({ month: MONTH[d.getUTCMonth()], tiles: trendTiles(), open });
1393
+ if (!line) return '';
1394
+ return `<div class="ins-strip ins-trstrip"><span class="sp" aria-hidden="true">${SV(I.spark)}</span><p class="t" id="trLine">${esc(line)}</p><a class="cz-ib sm" href="${esc(homeAsk('insights', 'Why? ' + line))}" aria-label="Discuss with Strategist" title="Discuss with Strategist">${SV(CHAT)}</a></div>`;
1395
+ }
1396
+ /** What moved it (MxA): only the tiles that moved since last week. Zero is silence. */
1397
+ function movedCard() {
1398
+ const R = TRV.movedRows(trendTiles());
1399
+ if (!R.length) return '';
1400
+ return `<section class="ins-mvd" aria-labelledby="hMvd"><h3 class="ins-h3" id="hMvd">What moved it</h3><div class="ins-mcard">${R.map((r) => `<button type="button" class="ins-mrow" data-mt="${esc(r.key)}"><span>${esc(r.label)}</span><span class="note">${esc(r.note)}</span><b>${esc(r.effect)}</b></button>`).join('')}</div></section>`;
1401
+ }
1402
+ /** Goals that moved (MxA): the key results and health budgets that are at risk, as the goal rows themselves (said once, not twice). */
1403
+ const goalHead = () => `<div class="ins-tr ins-th ${COLS}" role="row"><div role="columnheader">Goal</div><div role="columnheader">Now, of target</div><div role="columnheader">So far</div><div role="columnheader">By its date</div><div role="columnheader" class="ins-mvh">Moved by</div></div>`;
1404
+ /** A goal is at risk when its pace says so; one reading has no pace to judge, so it is not called at risk (honest state). */
1405
+ const riskTone = (g) => { const t = g.pace && g.pace.tone !== 'q' ? g.pace.tone : (g.readings || 0) > 1 ? g.tone : null; return t === 'late' || t === 'red' || t === 'risk'; };
1406
+ function movedGoals() {
1407
+ if (PF) return '';
1408
+ const G = listGoals().filter((g) => g.readings && riskTone(g)), B = (M.budgets || []).filter((b) => (b.reading && b.reading.over) || (b.burn && Number.isFinite(b.burn.weeksLeft) && b.burn.weeksLeft < 8));
1409
+ if (!G.length && !B.length) return ''; // zero is silence
1410
+ // wide: the goal rows themselves. Narrow (the phone, or the page beside the Viewer): one line each, its title and At risk (MxC)
1411
+ const cmp = G.map((g) => `<button type="button" class="ins-mrow" data-goal="${esc(g.id)}"><span>${esc(g.title)}</span><span class="cz-pill risk">At risk</span></button>`).concat(B.map((b) => `<button type="button" class="ins-mrow" data-budget="${esc(b.id)}"><span>${esc(b.title)}</span><span class="cz-pill risk">At risk</span></button>`)).join('');
1412
+ return `<section class="ins-mvd" aria-labelledby="hMvg"><h3 class="ins-h3" id="hMvg">Goals that moved</h3><div class="ins-tbl ins-mg-full" role="table" aria-label="Goals that moved">${goalHead()}${G.map(goalRow).join('')}${B.map(budgetRow).join('')}</div><div class="ins-mcard ins-mg-cmp">${cmp}</div></section>`;
1413
+ }
1382
1414
  function bmHtml(big) {
1383
1415
  if (!M.board || !M.board.ws) return big ? '<div class="ins-empty">Delivery trends are read from a board, and this workspace has none.</div>' : '';
1384
- const head = big ? '<div class="ins-trh" role="row"><h2 id="hBm" role="cell">Delivery trends</h2> <span class="note">Last 8 weeks · from the Board and its initiatives · press a tile to set its target</span></div>'
1416
+ const head = big ? '<div class="ins-trh" role="row"><h2 id="hBm" role="cell">Delivery trends</h2> <span class="note">Last 8 weeks · from the Board and its initiatives · press a tile for its weeks</span></div>'
1385
1417
  : '<div class="ins-grp" role="row"><h2 id="hBm" role="cell">Delivery trends</h2> <span class="q">the Board shows today’s counts as chips · press a tile to set its target</span></div>';
1386
- return `<section class="ins-trends${big ? ' big' : ''}" id="cBm" aria-labelledby="hBm">${head}`
1387
- + `<div class="ins-tiles" id="bmBody">${TILES.map(([k, l]) => { const t = tileOf(k), on = tgOpen === k; return `<div class="ins-tile${t.warn ? ' warn' : ''}${t.abs ? ' abs' : ''}${on ? ' sel' : ''}" data-tile="${k}" role="button" tabindex="0" aria-expanded="${on}" aria-label="${esc(l + ', ' + t.v + (t.s ? ', ' + t.s : '') + (t.T.line ? ', ' + t.T.line : ''))}"${t.s ? ` title="${esc(t.s)}"` : ''}><span class="l">${esc(l)}</span><span class="v">${esc(t.v)}</span>${big ? miniSpark(t.ser, 300, 34) : miniSpark(t.ser)}<span class="tg">${on ? 'Setting target…' : esc(t.T.line)}</span></div>`; }).join('')}</div></section>`;
1418
+ const mv = (t) => (big && !t.abs && t.change && t.change.d !== 0 ? `<span class="mv">${esc(t.change.txt)}</span>` : '');
1419
+ return `<section class="ins-trends${big ? ' big' : ''}" id="cBm" aria-labelledby="hBm">${head}${big ? monthStrip() : ''}`
1420
+ + `<div class="ins-tiles" id="bmBody">${TILES.map(([k, l]) => { const t = tileOf(k), on = tgOpen === k; return `<div class="ins-tile${t.warn ? ' warn' : ''}${t.abs ? ' abs' : ''}${on ? ' sel' : ''}" data-tile="${k}" role="button" tabindex="0" aria-expanded="${on}" aria-label="${esc(l + ', ' + t.v + (t.s ? ', ' + t.s : '') + (t.change && t.change.d !== 0 ? ', ' + t.change.txt : '') + (t.T.line ? ', ' + t.T.line : ''))}"${t.s ? ` title="${esc(t.s)}"` : ''}><span class="l">${esc(l)}</span><span class="v">${esc(t.v)}</span>${big ? miniSpark(t.ser, 300, 34) : miniSpark(t.ser)}${mv(t)}<span class="tg">${on ? 'Setting target…' : esc(t.T.line)}</span></div>`; }).join('')}</div>`
1421
+ + (big ? movedCard() + movedGoals() : '') + '</section>';
1422
+ }
1423
+ /** A tile in the Viewer (MxB): its weeks as bars, a blank week dashed with its reason, the definition, where it is counted from, and the target. */
1424
+ function openTile(key) {
1425
+ const L = (TILES.find((x) => x[0] === key) || [])[1] || key;
1426
+ viewer({ kind: 'Intelligence · Delivery trends', title: L, icon: 'chart', id: 'trend:' + key, eye: 'Delivery trends', render: (el) => {
1427
+ const t = tileOf(key), ser = t.ser || [], N = ser.length, vs = numsOf(ser), mx = Math.max(0, ...vs) || 1, dec = t.dec || 0, wk = t.wk || [];
1428
+ const month = MONTH[new Date((M.today || iso(today())) + 'T00:00:00Z').getUTCMonth()];
1429
+ const say = t.abs ? (key === 'corrections' && t.why ? month + ': ' + t.why : (t.why || 'It is not read, so it has no weeks to show.'))
1430
+ : t.v + (t.note ? ' · ' + t.note : '') + (t.change && t.change.d !== 0 ? ' · ' + t.change.txt : '');
1431
+ const bars = N ? `<div class="ins-bars" role="img" aria-label="${esc(L + ' by week: ' + ser.map((v, i) => (wk[i] || 'W' + (i + 1)) + ' ' + (v == null ? 'blank' : v)).join(', '))}">${ser.map((v, i) => `<div><span>${v == null ? '' : esc(String(dec ? Number(v).toFixed(dec) : v))}</span><i class="${v == null ? 'blank' : ''}${i === N - 1 ? ' now' : ''}"${v == null ? '' : ` style="height:${Math.max(4, Math.round(v / mx * 100))}px"`}></i>${esc(wk[i] || 'W' + (i + 1))}</div>`).join('')}</div>` : '';
1432
+ const lowB = TRV.LOW_BETTER[key];
1433
+ el.innerHTML = `<div class="ins-gd"><div class="ins-sayc"><p class="ins-sayv">${esc(say)}</p></div>`
1434
+ + (bars ? `<h3 class="ins-h3">By week${lowB ? ', lower is better' : ', higher is better'}</h3>${bars}<p class="note">${key === 'corrections' ? 'A week with fewer than 10 runs stays blank. ' : ''}The bars fill in as weeks qualify; this week is blue.</p>` : '')
1435
+ + (t.def ? `<p class="note">${esc(t.def)}</p>` : '') + (BM && BM.note ? `<p class="note ins-from">${esc(BM.note)}</p>` : '')
1436
+ + `<div class="ins-acts"><button type="button" class="cz-ib sm" data-tgset aria-label="Set a target" title="Set a target">${SV('M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0-18 0M12 12m-4 0a4 4 0 1 0 8 0a4 4 0 1 0-8 0')}</button>`
1437
+ + `<a class="cz-ib sm" href="${esc(homeAsk('insights', 'About ' + L + ': ' + say))}" aria-label="Discuss with Strategist" title="Discuss with Strategist">${SV(CHAT)}</a></div></div>`;
1438
+ el.addEventListener('click', (e) => { if (e.target.closest('[data-tgset]')) { e.stopPropagation(); closeViewer(); setTimeout(() => openTarget(key), 0); } }); // not in this press: the page's outside-press closes a popover opened by it
1439
+ } });
1388
1440
  }
1389
1441
  async function bmLoad() {
1390
1442
  if (!M || !M.board || !M.board.ws) return;
@@ -2045,7 +2097,8 @@ async function load() {
2045
2097
  setTimeout(load, 15000);
2046
2098
  return;
2047
2099
  }
2048
- const first = !M; M = r.model; loadedAt = Date.now(); draw(); if (first || !BM) bmLoad();
2100
+ const first = !M; M = r.model; loadedAt = Date.now(); if (first && !PF && new URLSearchParams(location.search).get('view') === 'trends') dash = TRENDS; // an old Metrics link, the monthly routine and the product page's chart icon land here
2101
+ draw(); if (first || !BM) bmLoad();
2049
2102
  if (on.length > 1 && first) await openPortfolio(on, true);
2050
2103
  // A shared goal link (?goal=<id>, from "Copy link" in the goal's ⋯) opens that goal once, after the first read.
2051
2104
  if (first) { const gid = new URLSearchParams(location.search).get('goal'); if (gid && allGoals().some((g) => g.id === gid)) openGoalDetail(gid); }
@@ -53,7 +53,7 @@ import { open as vOpen, current as vCur, czSections } from './cozy-viewer.js';
53
53
  import * as MP from './premium-mtg-present.js'; // the one presenter window for every kind (canvas note xvPresent)
54
54
  import { presentInRecording } from './cozy-rec-bridge.js'; // while a meeting records, the recording tab presents it (rule 10)
55
55
  import { placeholderHtml } from './cozy-placeholder.js';
56
- import './premium-vw-open.js'; // registers window.czViews
56
+ import { vzStyle } from './premium-vw-open.js'; // registers window.czViews; vzStyle adds the Viewer's sheet (cozy-vw.css)
57
57
  import { cycleGroups, cycleName, briefModel, briefGlanceHtml, briefConfirmHtml, briefWhyHtml, briefLooksHtml, paperModel, paperHtml, liveModel, liveHtml, presentHtml, dayMon, reportSummary,
58
58
  rpSumHtml, rpBarHtml, cadenceWords, goesOutWords, FORMATS } from './rp-parts.js';
59
59
 
@@ -434,7 +434,35 @@ function bodyHtml() {
434
434
  }
435
435
  const view = R.err ? `<p class="vz-msg" data-tone="bad" role="alert">The document could not be read: ${esc(R.err)}</p>` : !R.W ? '<p class="vz-empty" role="status">Reading the report.</p>'
436
436
  : R.view === 'deck' ? deckHtml() : R.view === 'live' ? liveView() : pageHtml();
437
- return `<div class="vz-rpb">${R.conf ? confHtml() : R.W ? sumHtml() : ''}${R.W && !R.err ? cutsHtml() : ''}${R.msg ? `<p class="vz-msg" role="status" data-tone="${R.msg.tone || ''}">${esc(R.msg.text)}</p>` : ''}${R.W && !R.err ? barHtml() : ''}${view}${R.W && !R.err ? foldsHtml() : ''}${askHtml()}</div>`;
437
+ return `<div class="vz-rpb">${R.conf ? confHtml() : R.W ? sumHtml() : ''}${R.W && !R.err ? cutsHtml() : ''}${R.msg ? `<p class="vz-msg" role="status" data-tone="${R.msg.tone || ''}">${esc(R.msg.text)}</p>` : ''}${R.edit ? '' : waitHtml()}${R.W && !R.err ? barHtml() : ''}${view}${R.W && !R.err ? foldsHtml() : ''}${askHtml()}</div>`;
438
+ }
439
+ /** What Claude is still doing on this report, said where the PM reads it (Wawan, 2026-11-01, batch 22 item 13: "I have to wait, but there's
440
+ * no indication of me having to wait"). Nothing running → ''. */
441
+ export function waitWords(x, draft) {
442
+ const st = x && x.structure, de = x && x.design, out = [];
443
+ if (draft && draft.state === 'drafting') out.push('Claude is writing this report again with your sections. It takes a few minutes; the new draft opens here when it lands.');
444
+ else if (draft && draft.state === 'held') out.push('The new draft waits for a check of ' + (draft.sources || []).join(', ') + '.');
445
+ if (st && st.running) out.push('Claude is reshaping the sections to your change. It takes a minute or two. Until you keep it, this draft has the standard sections.');
446
+ else if (st && st.current != null && st.current !== st.saved) out.push('New sections are ready. Open the report from your chat and press Use this; Claude then writes the draft again with them.');
447
+ if (de && de.running) out.push('Claude is making the look' + ((de.samples || []).length ? ' from ' + de.samples.map((y) => y.name).join(', ') : '') + '. It takes a minute or two. Until then, the slides use the standard PMOS look.');
448
+ return out;
449
+ }
450
+ function waitHtml() {
451
+ const L = waitWords(R.bfRaw, R.setup && R.setup.draft);
452
+ return L.length ? `<p class="vz-msg rp-wait" role="status">${L.map(esc).join(' ')}</p>` : '';
453
+ }
454
+ /** While Claude works on the report, read its state again every few seconds, so the line above clears and the new draft shows. */
455
+ let waitT = null;
456
+ function waitPoll() {
457
+ clearTimeout(waitT);
458
+ if (!R || !waitWords(R.bfRaw, R.setup && R.setup.draft).length) return;
459
+ const me = R, wasDrafting = !!(R.setup && R.setup.draft);
460
+ waitT = setTimeout(async () => {
461
+ if (R !== me) return;
462
+ await readSetup(); if (R !== me) return;
463
+ if (wasDrafting && !(R.setup && R.setup.draft)) await reread();
464
+ await readBrief(); if (R === me) waitPoll();
465
+ }, 4000);
438
466
  }
439
467
  const tipText = (i, n) => `Slide ${i + 1} of ${n}. Click an item to change it; double-click text to type.`;
440
468
  /** The editor's slide and its undo history changed: the tip and the dimmed Undo and Redo follow it. */
@@ -652,7 +680,7 @@ async function readBrief() {
652
680
  ].map((x) => Promise.resolve(x).catch(() => null)));
653
681
  if (R !== me) return;
654
682
  R.bfRaw = { structure: st && st.ok ? st.structure : null, design: de && de.ok ? de.design : null, checks: ch, confirms: cf && cf.ok ? cf.keys : [] };
655
- buildBrief(); draw();
683
+ buildBrief(); draw(); waitPoll();
656
684
  }
657
685
  function buildBrief() {
658
686
  const x = R.bfRaw; if (!x) return;
@@ -893,7 +921,9 @@ export async function openReport(row, hand = {}) {
893
921
  if (!row || !row.path) return null;
894
922
  const c = cycleOf(row);
895
923
  row = { ...row, cadence: c.cadence, slot: c.slot };
896
- rpStyle();
924
+ // the slides, the title card and the thumbnails are drawn by cozy-vw.css: a report opened from Home had no sheet, so its slides showed as
925
+ // plain text (Wawan, 2026-11-01, batch 22 item 13)
926
+ vzStyle(); rpStyle();
897
927
  if (R) present(false);
898
928
  const me = R = { row, ws: hand.ws || '', id: c.cadence, name: hand.name || row.name || c.cadence || 'Report', audience: hand.audience || '', issued: row.state === 'issued', archived: !!row.archived,
899
929
  text: '', err: '', W: null, view: 'deck', BF: null, bfRaw: null, bfMsg: '', LV: null, blank: false, i: 0, cyc: null, setup: undefined, pop: null, conf: false, checks: null, issueErr: '', busy: false, ask: '', askErr: '', edit: false, msg: null,
@@ -60,6 +60,9 @@ export function openReportTab(block) {
60
60
  vzStyle(); rpStyle();
61
61
  const id = 'report:' + (block.id || block.proposal.name).toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 60);
62
62
  let t = T.get(id);
63
+ // a proposal that is set up already opens its report, never "New · Set it up" again (Wawan, 2026-11-01, batch 22 item 13: "it goes back here again")
64
+ if (t && block.proposal && t.block.id && !t.gone) return show(t);
65
+ if (!t && block.proposal) { setTimeout(() => adoptSetUp(id, block.proposal.name), 0); }
63
66
  if (!t || JSON.stringify(t.block) !== JSON.stringify(block)) {
64
67
  t = { id, block, nv: 'deck', sched: block.proposal ? (block.proposal.schedule || 'off') : null, open: false, view: 'structure', busy: false, msg: '', setup: null, docs: [], S: null, Z: null, sv: null, dv: null, render: new Map(), gone: false, loaded: false, i: 0, ask: null };
65
68
  T.set(id, t);
@@ -67,6 +70,16 @@ export function openReportTab(block) {
67
70
  }
68
71
  return show(t);
69
72
  }
73
+ /** The chat's proposal names a report that is set up already (an earlier page, or a reload): open that report instead of the proposal. */
74
+ async function adoptSetUp(id, name) {
75
+ const L = await get('/api/report-setups');
76
+ const t = T.get(id);
77
+ const hit = t && t.block.proposal && L && Array.isArray(L.setups) ? L.setups.find((x) => x.status !== 'removed' && String(x.name || '').trim().toLowerCase() === String(name || '').trim().toLowerCase()) : null;
78
+ if (!hit) return;
79
+ t.block = { kind: 'report', id: hit.id }; t.loaded = false;
80
+ if (paneOf(t)) show(t);
81
+ await load(t);
82
+ }
70
83
  function show(t) {
71
84
  const P = t.block.proposal;
72
85
  return vOpen({ id: t.id, kind: P ? 'Report' + (P.audience ? ' · ' + P.audience : '') : 'Report template', title: P ? P.name : (t.setup && t.setup.name) || t.block.id, icon: 'report',
@@ -169,12 +182,16 @@ function newHtml(t) {
169
182
  + `<div class="vz-dkn"><button type="button" class="vz-dkb vz-hv" data-rt="sl|-1" aria-label="Previous slide"${i === 0 ? ' disabled' : ''}>${SV('M15 6l-6 6 6 6')}</button><span aria-live="polite">Slide ${i + 1} of ${L.length}</span><button type="button" class="vz-dkb vz-hv" data-rt="sl|1" aria-label="Next slide"${i === L.length - 1 ? ' disabled' : ''}>${SV('M9 6l6 6-6 6')}</button></div>`
170
183
  + `<div class="vz-dkt" role="group" aria-label="Slides">${L.map((x, k) => `<button type="button" class="vz-hv" data-rt="go|${k}" aria-label="Slide ${k + 1}: ${esc(x.h)}"${k === i ? ' aria-current="true"' : ''}><span>${esc(x.h)}</span></button>`).join('')}</div>`;
171
184
  const page = `<article class="vz-dkp"><h2>${esc(p.name)}</h2>${p.purpose ? `<p class="vz-note">${esc(p.purpose)}</p>` : ''}${sectionsHtml(F)}</article>`;
185
+ // the look Claude proposed with the report (batch 22 item 13): the PM's words, or the file it follows
186
+ const smp = t.block.sample ? String(t.block.sample).split('/').pop() : '';
187
+ const lookAsk = t.block.design || smp ? `<div class="vz-ask"><p>Look: <b>“${esc(t.block.design || 'Follow ' + smp)}”</b></p><p class="vz-note">Claude ${smp ? 'follows ' + esc(smp) : 'makes this look'} as soon as the report is set up.</p></div>` : '';
172
188
  const folds = czSections([
173
189
  { id: 'glance', title: 'At a glance', count: 'For, read by, goes out', render: () => `<div class="rp-brief">${glance(p.purpose, p.audience, esc(schedWords(t.sched)), OUT[p.output] || p.output)}</div>` },
174
190
  { id: 'look', title: 'Structure and look', count: named ? F.length + ' sections' : t.block.structure ? 'change' : 'new', render: () => named
175
- ? `${sectionsHtml(F)}<p class="vz-note">The sections you named in the chat. It uses the standard PMOS look until you say how it should look.</p>`
176
- : (t.block.structure ? `<div class="vz-ask"><p>Your change: <b>“${esc(t.block.structure)}”</b></p><p class="vz-note">Claude makes this change as soon as the report is set up. The first draft uses the sections below.</p></div>` : '')
177
- + `${sectionsHtml(FRAME)}<p class="vz-note">Every new report has these sections. ${t.block.structure ? '' : 'Once it is set up, ask in the chat to shape them. '}It uses the standard PMOS look until you say how it should look.</p>` },
191
+ ? `${lookAsk}${sectionsHtml(F)}<p class="vz-note">The sections you named in the chat.${lookAsk ? '' : ' It uses the standard PMOS look until you say how it should look.'}</p>`
192
+ : (t.block.structure ? `<div class="vz-ask"><p>Your change: <b>“${esc(t.block.structure)}”</b></p><p class="vz-note">Claude makes this change as soon as the report is set up. When you keep it, Claude writes the draft again with it.</p></div>` : '')
193
+ + lookAsk
194
+ + `${sectionsHtml(FRAME)}<p class="vz-note">Every new report has these sections. ${t.block.structure ? '' : 'Once it is set up, ask in the chat to shape them. '}${lookAsk ? '' : 'It uses the standard PMOS look until you say how it should look.'}</p>` },
178
195
  ], { key: 'report-new' });
179
196
  return sum + schedMenu(t, t.sched) + bar + (t.nv === 'doc' ? page : deck) + folds;
180
197
  }
@@ -203,7 +220,7 @@ function structureHtml(t) {
203
220
  const L = plan && plan.outline ? plan.outline.map((x) => [x.title, x.notes || '']) : FRAME;
204
221
  const want = shapeOf(t.block);
205
222
  const ask = want && !(S && S.running) ? `<div class="vz-ask"><p>Your change: <b>“${esc(want)}”</b></p><div>${btn('s-turn', 'Make the next version', { off: t.busy })}</div></div>` : '';
206
- const working = S && S.running ? '<p class="vz-note" role="status">PMOS is making the next version.</p>' : '';
223
+ const working = S && S.running ? '<p class="vz-msg rp-wait" role="status">Claude is reshaping the sections to your change. It takes a minute or two; Use this shows here when it is ready.</p>' : '';
207
224
  const held = t.busy || !!(S && S.running); // a running job holds only these two; Discard and Delete template stay free
208
225
  const save = shown != null && S && shown !== S.saved ? btn('s-accept', 'Use this', { off: held }) : '';
209
226
  const undo = V.some((v) => v.n < (S ? S.current : 0)) ? btn('s-undo', 'Undo', { sec: true, off: held }) : '';
@@ -216,7 +233,7 @@ function designHtml(t) {
216
233
  if (Z.err) return `<p class="vz-msg">${esc(Z.err)}</p>`;
217
234
  const V = Z.versions || [], saved = Z.saved ? Z.saved.version : null, s = t.setup || {};
218
235
  const ask = t.block.design && !Z.running ? `<div class="vz-ask"><p>Your change: <b>“${esc(t.block.design)}”</b></p><div>${btn('d-turn', 'Make the next version', { off: t.busy })}</div></div>` : '';
219
- const working = Z.running ? '<p class="vz-note" role="status">PMOS is making the next look.</p>' : '';
236
+ const working = Z.running ? '<p class="vz-msg rp-wait" role="status">Claude is making the look. It takes a minute or two; Use it shows here when it is ready.</p>' : '';
220
237
  const preview = t.dv != null && t.dv !== saved;
221
238
  const head = `<div class="vz-r1"><div class="rp-grow"><h2 class="rp-h2">${esc(s.name || t.block.id)}</h2><p class="vz-note">${esc([s.audience, OUT[s.output] || s.output, s.status === 'paused' ? 'not scheduled' : 'goes out ' + schedWords(s.schedule).replace(/^./, (c) => c.toLowerCase())].filter(Boolean).join(' · '))}</p></div>`
222
239
  + (preview ? '<span class="cz-pill you">Previewing new look</span>' : t.dv != null ? '<span class="cz-pill ok">Saved look</span>' : '') + '</div>';
@@ -274,7 +291,10 @@ async function press(t, e) {
274
291
  const id = t.block.id;
275
292
  if (a === 's-turn') { t.busy = true; t.msg = ''; redraw(t); const r = await post('/api/report-structure/turn', { id, text: shapeOf(t.block) }); if (!r || !r.ok) { t.busy = false; t.msg = 'That did not start: ' + why(r, 'no answer') + '.'; redraw(t); return; } t.busy = false; t.S = Object.assign({}, t.S, { running: true }); t.block = Object.assign({}, t.block, { structure: undefined, sections: undefined }); redraw(t); poll(t, 'structure'); return; }
276
293
  if (a === 'd-turn') { t.busy = true; t.msg = ''; redraw(t); const r = await post('/api/report-design/turn', { id, text: t.block.design, points: [] }); if (!r || !r.ok) { t.busy = false; t.msg = 'That did not start: ' + why(r, 'no answer') + '.'; redraw(t); return; } t.busy = false; t.Z = Object.assign({}, t.Z, { running: true }); t.block = Object.assign({}, t.block, { design: undefined }); redraw(t); poll(t, 'design'); return; }
277
- if (a === 's-accept') { await act(t, async () => { const r = await post('/api/report-structure/accept', { id, n: t.sv }); if (!r || !r.ok) return why(r, 'The structure was not saved.'); t.S = r.structure; return 'S' + t.sv + ' is saved. The next cycle follows it.'; }); return; }
294
+ if (a === 's-accept') { await act(t, async () => { const r = await post('/api/report-structure/accept', { id, n: t.sv }); if (!r || !r.ok) return why(r, 'The structure was not saved.'); t.S = r.structure;
295
+ // the open draft is written again with these sections, so the PM reads the report they asked for now, not next cycle (batch 22 item 13)
296
+ const d = await post('/api/report-setups/draft', { id });
297
+ return 'S' + t.sv + ' is saved. ' + (d && d.ok ? 'Claude is writing the draft again with these sections. It opens under Reports when it lands.' : 'The next cycle follows it. The draft was not written again: ' + why(d, 'no answer') + '.'); }); return; }
278
298
  if (a === 's-undo') { const V = t.S.versions.filter((x) => x.n < t.S.current); const to = V[V.length - 1].n; await act(t, async () => { const r = await post('/api/report-structure/revert', { id, n: to }); if (!r || !r.ok) return why(r, 'Undo did not go through.'); t.S = r.structure; t.sv = t.S.current; return 'Back to S' + to + '.'; }); return; }
279
299
  if (a === 'd-accept') { await act(t, async () => { const r = await post('/api/report-design/accept', { id, n: t.dv }); if (!r || !r.ok) return why(r, 'The design was not saved.'); t.Z = r.design; return 'Using the new look (D' + t.dv + '). The next cycle follows it, and every section and figure stays.'; }); return; }
280
300
  if (a === 'd-keep') {
@@ -301,6 +321,33 @@ async function press(t, e) {
301
321
  redraw(t);
302
322
  }
303
323
  }
324
+ const KIND_OF = { pdf: 'pdf', pptx: 'pptx', docx: 'docx', png: 'image', jpg: 'image', jpeg: 'image' };
325
+ /** A workspace file as base64, read through /api/asset. null when it cannot be read. */
326
+ async function fileB64(path) {
327
+ try {
328
+ const res = await fetch('/api/asset?' + qs({ ws: ws(), path }));
329
+ if (!res.ok) return null;
330
+ const u8 = new Uint8Array(await res.arrayBuffer());
331
+ let bin = ''; for (let i = 0; i < u8.length; i += 0x8000) bin += String.fromCharCode.apply(null, u8.subarray(i, i + 0x8000));
332
+ return btoa(bin);
333
+ } catch { return null; }
334
+ }
335
+ /** Adds the sample file to the report's look, then starts the look from the PM's words. → the sentence for the PM. */
336
+ async function startLook(t, id, look) {
337
+ let added = '';
338
+ if (look.sample) {
339
+ const ext = (look.sample.split('.').pop() || '').toLowerCase(), name = look.sample.split('/').pop();
340
+ const data = KIND_OF[ext] ? await fileB64(look.sample) : null;
341
+ const a = data ? await post('/api/report-design/sample', { id, name, kind: KIND_OF[ext], data }) : null;
342
+ added = a && a.ok ? name : '';
343
+ if (!added) return ' The look could not read ' + name + (a ? ': ' + why(a, 'no answer') : '') + '. Attach it in the chat and ask again.';
344
+ }
345
+ const text = look.text || 'Follow the look and layout of ' + added + '.';
346
+ const d = await post('/api/report-design/turn', { id, text, points: [] });
347
+ if (!d || !d.ok) { t.block = Object.assign({}, t.block, { design: text }); return ' The look did not start: ' + why(d, 'no answer') + '. Press Make the next version to try again.'; }
348
+ t.Z = Object.assign({}, t.Z, { running: true }); poll(t, 'design');
349
+ return ' Claude is making the look' + (added ? ' from ' + added : '') + ' now.';
350
+ }
304
351
  async function setUp(t) {
305
352
  const p = t.block.proposal;
306
353
  const schedule = t.sched === 'off' ? { cadence: 'weekly', day: 'Mon', time: '09:00' } : t.sched;
@@ -311,6 +358,7 @@ async function setUp(t) {
311
358
  if (!r || !r.ok) return 'It was not set up: ' + why(r, 'the page could not reach PMOS') + '.';
312
359
  if (t.sched === 'off') await post('/api/report-setups/edit', { id: r.setup.id, schedule: { cadence: 'off' } });
313
360
  // the view now shows the set-up report, under the same id, so the card stays on it
361
+ const look = { text: t.block.design || '', sample: t.block.sample || '' };
314
362
  const shape = r.structure ? null : named ? 'Use exactly these sections, in this order: ' + named.join('; ') + '.' : t.block.structure;
315
363
  t.block = { kind: 'report', id: r.setup.id }; t.loaded = false; show(t); await load(t);
316
364
  const d = r.drafted || {};
@@ -321,6 +369,9 @@ async function setUp(t) {
321
369
  if (s && s.ok) { t.S = Object.assign({}, t.S, { running: true }); t.view = 'structure'; poll(t, 'structure'); shaping = ' Claude is reshaping the sections to your change now.'; }
322
370
  else { t.block = Object.assign({}, t.block, { structure: shape }); shaping = ' The change to its sections did not start: ' + why(s, 'no answer') + '. Press Make the next version to try again.'; }
323
371
  }
372
+ // the look Claude proposed with it (the PM's words, and the file to follow, such as a draft deck): add the sample, then start the look
373
+ // (Wawan, 2026-11-01, batch 22 item 13: "Deck format and layout follow the draft deck" was dropped at set-up)
374
+ if (look.text || look.sample) shaping += await startLook(t, r.setup.id, look);
324
375
  if (r.structure) t.view = 'structure';
325
376
  const first = d.drafting ? 'Claude is writing the first draft with your ' + named.length + ' sections. It opens under Reports when it lands.'
326
377
  : d.path ? 'The first draft is written.' : 'The first draft was not written' + (d.error ? ': ' + d.error : '') + '.';
@@ -100,6 +100,8 @@ export function fileHtml(f, view = 'page') {
100
100
  return `<div class="vwdoc"><div class="vwfnone" role="status"><b>${esc(head)}</b><p class="vwmut">${esc(f.why || '')}</p><code>${esc(f.path)}</code></div></div>`;
101
101
  }
102
102
  if (f.err) return `<div class="vwdoc"><div class="vwfnone" role="status"><b>The file could not be shown</b><p class="vwmut">${esc(f.err)}</p><code>${esc(f.abs || f.path)}</code></div></div>`;
103
+ if (f.kind === 'pdf' && f.src) return `<div class="vwdoc vwpdf"><article class="cf vwfile">${headHtml(f, f.name)}<iframe class="vwframe vwpdff" title="${esc(f.name)}" src="${esc(f.src)}#view=FitH"></iframe>`
104
+ + `<footer class="cff"><span>Read-only · PDF</span><span class="gap"></span><code>${esc(f.abs || f.rel)}</code></footer></article></div>`;
103
105
  const foot = `<footer class="cff"><span>Read-only · ${readMinutes(f.text)} min read</span><span class="gap"></span><code>${esc(f.abs || f.rel)}</code></footer>`;
104
106
  if (f.kind === 'markdown') {
105
107
  const h = pageHead(f.text), sd = splitDoc(f.text);
@@ -171,6 +173,8 @@ export function openChatFile(p, ctx = {}) {
171
173
  if (!loc.ok) { const sig = 'x:' + loc.reason; if (sig === st.sig) return false; st.sig = sig; st.f = { path: p, reason: loc.reason, why: loc.why }; return true; }
172
174
  const sig = loc.ws + '/' + loc.rel + '@' + loc.mtime + ':' + loc.size;
173
175
  if (sig === st.sig) return false;
176
+ // a PDF is not text: the browser's own PDF viewer shows it, streamed by /api/asset (batch 22 item 12: "The file could not be shown")
177
+ if (/\.pdf$/i.test(loc.name || loc.rel || '')) { st.sig = sig; st.f = { path: p, name: loc.name, ws: loc.ws, rel: loc.rel, abs: loc.abs, kind: 'pdf', src: '/api/asset?' + q({ ws: loc.ws, path: loc.rel }) + '&v=' + encodeURIComponent(String(loc.mtime || '')) }; return true; }
174
178
  const got = await getText('/api/doc?' + q({ ws: loc.ws, path: loc.rel }));
175
179
  st.sig = sig;
176
180
  st.f = got.ok ? { path: p, name: loc.name, ws: loc.ws, rel: loc.rel, abs: loc.abs, kind: got.kind, text: got.text } : { path: p, abs: loc.abs, err: got.text };
@@ -25,7 +25,7 @@ button.pv-gr { cursor: pointer; }
25
25
  .pv-gr:focus-visible, .pv-one:focus-visible, .pv-tab:focus-visible { outline: 2px solid var(--cz-blue); outline-offset: 2px; border-radius: 10px; }
26
26
  .pv-rt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
27
27
  .pv-rt b { font-size: var(--fs-4); font-weight: 800; line-height: 1.3; }
28
- .pv-gr .pv-rt b { font-size: var(--fs-5); }
28
+ .pv-rt b.q { font-weight: 600; color: var(--cz-ink2); } /* no goal text yet: a known fact, not a goal title */
29
29
  .pv-rt small { font-size: var(--fs-2); color: var(--cz-ink3); line-height: 1.4; }
30
30
  .pv-kr { flex: none; font-size: var(--fs-1); font-weight: 800; border-radius: 6px; padding: 2px 6px; background: var(--cz-bluebg); color: var(--cz-blueink); }
31
31
  .pv-fc { display: flex; align-items: center; gap: 10px; padding-left: 19px; }
@@ -61,8 +61,11 @@ export function pageHtml(m) {
61
61
  + (m.tabs.length ? tabsHtml(m, on) + `<div class="pv-panel" id="pvp" role="tabpanel" aria-labelledby="pvt-${esc(on)}">${t ? t.html() : ''}</div>` : '') + (m.tail || '') + '</div>';
62
62
  }
63
63
  /** The tab presses and the proposals fold, once per body. A press keeps the tab for this page and draws again (h.redraw). */
64
- export function wirePage(body, h) {
65
- if (body.dataset.pvWired) return; body.dataset.pvWired = '1';
64
+ export function wirePage(body, h0) {
65
+ // the Viewer keeps ONE body for every item: the listeners go on once, and each page's own h is kept on the body, so a press redraws the page
66
+ // on screen and not the one wired first (batch 22 item 6: the program page's proposals row did nothing after the product page)
67
+ body._pvH = h0; if (body._pvOn) return; body._pvOn = true;
68
+ const h = { redraw: () => body._pvH.redraw() };
66
69
  const pageOf = () => { const p = body.querySelector('[data-pv-page]'); return p ? p.dataset.pvPage : ''; };
67
70
  const go = (k) => { keepTab(pageOf(), k); h.redraw(); const t = body.querySelector(`[data-pv="tab"][data-k="${k}"]`); if (t) t.focus(); };
68
71
  body.addEventListener('click', (e) => {
@@ -98,7 +101,7 @@ export function goalRow(g, o = {}) {
98
101
  const tag = o.button === false ? 'div' : 'button type="button"', end = o.button === false ? 'div' : 'button';
99
102
  return `<${tag} class="pv-gr"${o.button === false ? '' : ` data-db="goal" data-k="${esc(g.id)}"${g.ws ? ` data-ws="${esc(g.ws)}"` : ''}`} title="${esc(g.title || '')}">`
100
103
  + `<span class="db-dot ${DOT[g.dot] || 'q'}" role="img" aria-label="${esc(dotWord(g.dot))}"></span>${g.kr ? `<span class="pv-kr">${esc(g.kr)}</span>` : ''}`
101
- + `<span class="pv-rt"><b>${esc(g.short || g.title)}</b>${g.sub ? `<small>${esc(g.sub)}</small>` : ''}</span></${end}>${rangeHtml(g.fc)}`;
104
+ + `<span class="pv-rt"><b${g.noText ? ' class="q"' : ''}>${esc(g.short || g.title)}</b>${g.sub ? `<small>${esc(g.sub)}</small>` : ''}</span></${end}>${rangeHtml(g.fc)}`;
102
105
  }
103
106
  /** The goal card: the goals (or the one Claude proposes), then the milestones inside it; '' when it holds nothing. */
104
107
  const GOALS_SHOWN = 3; // the card stays one card: the goals behind their line first, 3 shown, the rest one fold away (a product has many)
@@ -51,6 +51,12 @@ function cleanSections(v) {
51
51
  return out.length ? out : null;
52
52
  }
53
53
 
54
+ /** A sample file the look follows: a workspace path to a .pdf, .pptx, .docx, .png or .jpg, with no '..'. null otherwise. */
55
+ export function cleanSample(v) {
56
+ const t = clip(v, 300).replace(/\\/g, '/');
57
+ return t && !t.split('/').includes('..') && /\.(pdf|pptx|docx|png|jpe?g)$/i.test(t) ? t : null;
58
+ }
59
+
54
60
  /** The block as the tab uses it, or null when it is not a block. Unknown keys are dropped; text is clipped. */
55
61
  export function cleanBlock(b) {
56
62
  if (b && typeof b === 'object' && (b.kind === 'chart' || b.kind === 'dashboard')) return cleanChartBlock(b);
@@ -64,8 +70,8 @@ export function cleanBlock(b) {
64
70
  }
65
71
  const p = b.proposal && typeof b.proposal === 'object' ? b.proposal : null;
66
72
  if (!p || !clip(p.name, 80)) return null;
67
- const shape = clip(b.structure, 600), secs = cleanSections(b.sections);
68
- return { kind: 'report', ...(shape ? { structure: shape } : {}), ...(secs ? { sections: secs } : {}), proposal: {
73
+ const shape = clip(b.structure, 600), secs = cleanSections(b.sections), look = clip(b.design, 600), sample = cleanSample(b.sample);
74
+ return { kind: 'report', ...(shape ? { structure: shape } : {}), ...(secs ? { sections: secs } : {}), ...(look ? { design: look } : {}), ...(sample ? { sample } : {}), proposal: {
69
75
  name: clip(p.name, 80), purpose: clip(p.purpose, 400), audience: clip(p.audience, 120) || 'The team',
70
76
  output: OUTPUTS.includes(p.output) ? p.output : 'google-doc', schedule: cleanSchedule(p.schedule) === 'off' ? null : cleanSchedule(p.schedule),
71
77
  sources: (Array.isArray(p.sources) ? p.sources : []).map((x) => clip(x, 160)).filter(Boolean).slice(0, 8),