create-pmos 0.479.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 (50) hide show
  1. package/package.json +26 -27
  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 +25 -0
  11. package/workspace/guide/briefing-premium.md +11 -4
  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 +8 -4
  18. package/workspace/lib/report-draft.js +14 -5
  19. package/workspace/lib/report-structure.js +35 -1
  20. package/workspace/lib/routes-metric-drafts.js +2 -1
  21. package/workspace/lib/routes-ready-reports.js +6 -2
  22. package/workspace/lib/routes-report-setups.js +24 -4
  23. package/workspace/package-lock.json +2 -2
  24. package/workspace/package.json +1 -1
  25. package/workspace/premium-html-viewer-test.js +2 -0
  26. package/workspace/public/pm/bd-acts.js +2 -20
  27. package/workspace/public/pm/bd-prog-panel.js +1 -2
  28. package/workspace/public/pm/cozy-board.css +0 -11
  29. package/workspace/public/pm/cozy-home.css +5 -0
  30. package/workspace/public/pm/cozy-insights.css +31 -0
  31. package/workspace/public/pm/cozy-vw-rp.css +5 -0
  32. package/workspace/public/pm/dash-view.css +19 -0
  33. package/workspace/public/pm/dash-view.js +49 -11
  34. package/workspace/public/pm/goal-chat.js +10 -3
  35. package/workspace/public/pm/home-app.js +31 -89
  36. package/workspace/public/pm/home-chat.js +19 -4
  37. package/workspace/public/pm/home-goal.js +1 -1
  38. package/workspace/public/pm/home-line.js +16 -1
  39. package/workspace/public/pm/home-list.js +1 -1
  40. package/workspace/public/pm/premium-board.js +2 -2
  41. package/workspace/public/pm/premium-insights.js +64 -11
  42. package/workspace/public/pm/premium-report-read.js +42 -5
  43. package/workspace/public/pm/premium-report-tab.js +89 -24
  44. package/workspace/public/pm/premium-vw-file.js +4 -0
  45. package/workspace/public/pm/prog-page.css +1 -1
  46. package/workspace/public/pm/prog-page.js +6 -3
  47. package/workspace/public/pm/report-chat.js +20 -3
  48. package/workspace/public/pm/trends-review.js +55 -0
  49. package/workspace/ready-dash-ui-test.js +1 -3
  50. package/workspace/test-files.json +1 -0
@@ -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',
@@ -108,13 +121,13 @@ async function poll(t, kind) {
108
121
  await new Promise((ok) => setTimeout(ok, POLL_MS));
109
122
  if (kind === 'structure') {
110
123
  const S = await get('/api/report-structure', { id: t.block.id });
111
- if (S && S.ok && !S.structure.running) { t.S = S.structure; t.sv = t.S.current; t.busy = false; t.msg = lastSaid(t.S.log); redraw(t); return; }
124
+ if (S && S.ok && !S.structure.running) { t.S = S.structure; t.sv = t.S.current; t.msg = lastSaid(t.S.log); redraw(t); return; }
112
125
  } else {
113
126
  const r = await get('/api/report-design', { id: t.block.id });
114
- if (r && r.ok && !r.design.running) { t.Z = r.design; t.dv = t.Z.current; await renderOf(t, t.dv); t.busy = false; t.msg = lastSaid(t.Z.log); redraw(t); return; }
127
+ if (r && r.ok && !r.design.running) { t.Z = r.design; t.dv = t.Z.current; await renderOf(t, t.dv); t.msg = lastSaid(t.Z.log); redraw(t); return; }
115
128
  }
116
129
  }
117
- t.busy = false; t.msg = 'PMOS has not answered yet. The new version shows when you open this report again.'; redraw(t);
130
+ t.msg = 'PMOS has not answered yet. The new version shows when you open this report again.'; redraw(t);
118
131
  }
119
132
  const lastSaid = (log) => { const l = (log || []).filter((x) => x.who === 'pmos').pop(); return l ? l.text : ''; };
120
133
 
@@ -145,9 +158,11 @@ function draw(t, el) {
145
158
  el.querySelectorAll('iframe[data-rt-frame]').forEach((f) => { f.srcdoc = t.render.get(+f.dataset.rtFrame) || ''; });
146
159
  }
147
160
  /** The new report as slides: its title slide, then one slide per section every new report has. */
148
- export function deckOf(p) {
149
- return [{ eye: p.audience ? 'For ' + p.audience : 'New report', h: p.name, t: p.purpose || '' }].concat(FRAME.map(([h, d]) => ({ eye: p.name, h, t: d })));
161
+ export function deckOf(p, sections) {
162
+ return [{ eye: p.audience ? 'For ' + p.audience : 'New report', h: p.name, t: p.purpose || '' }].concat(frameOf(sections).map(([h, d]) => ({ eye: p.name, h, t: d })));
150
163
  }
164
+ /** The sections a new report will have: the ones the PM named in the chat (block.sections), else the standard frame. */
165
+ export const frameOf = (sections) => (Array.isArray(sections) && sections.length ? sections.map((h) => [h, '']) : FRAME);
151
166
  /**
152
167
  * A new report from the chat: the one report Viewer in its first state (canvas OvReport). The summary says it is new and not set up, what
153
168
  * it will hold, and its one primary, Set it up (a check icon); its chips are the schedule (Once until one is picked; it opens the choices)
@@ -155,21 +170,28 @@ export function deckOf(p) {
155
170
  * At a glance and Structure and look ("new"). Edit, Present, Share and Download have nothing to act on until it is set up, so they are not drawn.
156
171
  */
157
172
  function newHtml(t) {
158
- const p = t.block.proposal, L = deckOf(p), i = t.i = Math.max(0, Math.min(t.i, L.length - 1)), s = L[i];
173
+ const p = t.block.proposal, named = t.block.sections, F = frameOf(named), L = deckOf(p, named), i = t.i = Math.max(0, Math.min(t.i, L.length - 1)), s = L[i];
159
174
  const sum = rpSumHtml({ line: 'New · from your chat', tone: 'you', right: 'Not set up yet',
160
- text: t.block.structure ? 'It starts with the standard sections. When you set it up, Claude reshapes them to your change, and you keep it with one press. Nothing goes out until you set it up.'
161
- : 'One slide per section: ' + FRAME.map(([h]) => h).join(', ') + '. Nothing goes out until you set it up.',
175
+ text: named ? 'One slide per section: ' + F.map(([h]) => h).join(', ') + '. Press the check to set it up: it keeps these sections and drafts the first report with them. Nothing goes out.'
176
+ : t.block.structure ? 'It starts with the standard sections. When you set it up, Claude reshapes them to your change, and you keep it with one press. Nothing goes out until you set it up.'
177
+ : 'One slide per section: ' + FRAME.map(([h]) => h).join(', ') + '. Press the check to set it up. Nothing goes out.',
162
178
  chips: [{ icon: 'repeat', label: cadenceWords(t.sched), act: 'sched', exp: t.open }, { icon: 'file', label: OUT[p.output] || p.output || 'PDF' }],
163
179
  primary: { act: 'setup', label: t.busy ? 'Setting it up' : 'Set it up', icon: 'check', disabled: t.busy } }, 'data-rt');
164
180
  const bar = rpBarHtml({ view: t.nv, views: [['deck', 'Slides'], ['doc', 'Document']] }, 'data-rt');
165
181
  const deck = `<div class="vz-dks" role="group" aria-roledescription="slide" aria-label="Slide ${i + 1} of ${L.length}: ${esc(s.h)}"><p class="vz-dke">${esc(s.eye)}</p><h2>${esc(s.h)}</h2>${s.t ? `<p>${esc(s.t)}</p>` : ''}</div>`
166
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>`
167
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>`;
168
- const page = `<article class="vz-dkp"><h2>${esc(p.name)}</h2>${p.purpose ? `<p class="vz-note">${esc(p.purpose)}</p>` : ''}${sectionsHtml(FRAME)}</article>`;
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>` : '';
169
188
  const folds = czSections([
170
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>` },
171
- { id: 'look', title: 'Structure and look', count: t.block.structure ? 'change' : 'new', render: () => (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>` : '')
172
- + `${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>` },
190
+ { id: 'look', title: 'Structure and look', count: named ? F.length + ' sections' : t.block.structure ? 'change' : 'new', render: () => named
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>` },
173
195
  ], { key: 'report-new' });
174
196
  return sum + schedMenu(t, t.sched) + bar + (t.nv === 'doc' ? page : deck) + folds;
175
197
  }
@@ -190,14 +212,18 @@ function stepper(kind, n, list, saved) {
190
212
  return `<div class="vz-r1 vz-g6"><button type="button" class="vz-nav vz-hv" data-rt="${kind}|${list[i - 1] ? list[i - 1].n : n}" aria-label="Earlier version"${i <= 0 ? ' disabled' : ''}>${SV('M15 6l-6 6 6 6', 14)}</button>`
191
213
  + `<span class="vz-t13">${kind === 'sv' ? 'S' : 'D'}${n}${n === saved ? ' · saved' : ' · not saved'}</span><button type="button" class="vz-nav vz-hv" data-rt="${kind}|${list[i + 1] ? list[i + 1].n : n}" aria-label="Later version"${i >= list.length - 1 ? ' disabled' : ''}>${SV('M9 6l6 6-6 6', 14)}</button></div>`;
192
214
  }
215
+ /** The change to a set-up report's sections in words: the titles the PM named, else the change Claude carried. */
216
+ const shapeOf = (b) => (b.sections && b.sections.length ? 'Use exactly these sections, in this order: ' + b.sections.join('; ') + '.' : b.structure || '');
193
217
  function structureHtml(t) {
194
218
  const S = t.S, V = (S && S.versions) || [];
195
219
  const plan = S && S.plan, shown = t.sv;
196
220
  const L = plan && plan.outline ? plan.outline.map((x) => [x.title, x.notes || '']) : FRAME;
197
- const ask = t.block.structure && !(S && S.running) ? `<div class="vz-ask"><p>Your change: <b>“${esc(t.block.structure)}”</b></p><div>${btn('s-turn', 'Make the next version', { off: t.busy })}</div></div>` : '';
198
- const working = S && S.running ? '<p class="vz-note" role="status">PMOS is making the next version.</p>' : '';
199
- const save = shown != null && S && shown !== S.saved ? btn('s-accept', 'Use this', { off: t.busy }) : '';
200
- const undo = V.some((v) => v.n < (S ? S.current : 0)) ? btn('s-undo', 'Undo', { sec: true, off: t.busy }) : '';
221
+ const want = shapeOf(t.block);
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>` : '';
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>' : '';
224
+ const held = t.busy || !!(S && S.running); // a running job holds only these two; Discard and Delete template stay free
225
+ const save = shown != null && S && shown !== S.saved ? btn('s-accept', 'Use this', { off: held }) : '';
226
+ const undo = V.some((v) => v.n < (S ? S.current : 0)) ? btn('s-undo', 'Undo', { sec: true, off: held }) : '';
201
227
  return `${stepper('sv', shown, V, S && S.saved)}${ask}${working}${sectionsHtml(L)}${!V.length ? '<p class="vz-note">No structure version yet: each cycle uses these sections. Say in the chat how to shape them.</p>' : ''}${save || undo ? `<div class="vz-r1">${undo}${save}</div>` : ''}`;
202
228
  }
203
229
  /** The look conversation's card (RpDesign): the preview of the shown look against the saved one, Use it and Keep current. */
@@ -207,7 +233,7 @@ function designHtml(t) {
207
233
  if (Z.err) return `<p class="vz-msg">${esc(Z.err)}</p>`;
208
234
  const V = Z.versions || [], saved = Z.saved ? Z.saved.version : null, s = t.setup || {};
209
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>` : '';
210
- 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>' : '';
211
237
  const preview = t.dv != null && t.dv !== saved;
212
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>`
213
239
  + (preview ? '<span class="cz-pill you">Previewing new look</span>' : t.dv != null ? '<span class="cz-pill ok">Saved look</span>' : '') + '</div>';
@@ -219,8 +245,9 @@ function designHtml(t) {
219
245
  + `<button type="button" class="rp-thumb on" data-rt="dv|${t.dv}" aria-current="true"><span class="rp-tf">${fr(t.dv, 'The new look D' + t.dv)}</span><span class="rp-tl"><b>New look</b> · D${t.dv}</span></button></div>` : '';
220
246
  const frame = t.dv != null ? (t.render.has(t.dv) ? `<div class="vz-pagefr"><iframe sandbox="" title="Design version D${t.dv}" data-rt-frame="${t.dv}"></iframe></div>` : '<p class="vz-note">This version could not be read.</p>')
221
247
  : '<p class="vz-note">No look yet. Say in the chat how it should look, or attach a sample. Each cycle uses the standard look until then.</p>';
222
- const use = preview ? btn('d-accept', 'Use it', { off: t.busy }) + btn('d-keep', 'Keep current', { sec: true, off: t.busy }) : '';
223
- const undo = !preview && V.some((v) => v.n < (Z.current || 0)) ? btn('d-undo', 'Undo', { sec: true, off: t.busy }) : '';
248
+ const held = t.busy || !!Z.running;
249
+ const use = preview ? btn('d-accept', 'Use it', { off: held }) + btn('d-keep', 'Keep current', { sec: true, off: held }) : '';
250
+ const undo = !preview && V.some((v) => v.n < (Z.current || 0)) ? btn('d-undo', 'Undo', { sec: true, off: held }) : '';
224
251
  return `${head}${stepper('dv', t.dv, V, saved)}${ask}${working}${fol}${pair}${frame}${use || undo ? `<div class="vz-r1">${use}${undo}</div>` : ''}`;
225
252
  }
226
253
  function cyclesHtml(t) {
@@ -262,9 +289,12 @@ async function press(t, e) {
262
289
  if (a === 'setup') { await setUp(t); return; }
263
290
  if (a === 'open') { const d = t.docs.find((x) => x.path === v); if (window.czViews) window.czViews.openReport(d ? { path: d.path, slot: d.slot, state: d.state, archived: !!d.archived } : v, { ws: ws(), name: t.setup ? t.setup.name : '' }); return; }
264
291
  const id = t.block.id;
265
- if (a === 's-turn') { t.busy = true; t.msg = ''; redraw(t); const r = await post('/api/report-structure/turn', { id, text: t.block.structure }); if (!r || !r.ok) { t.busy = false; t.msg = 'That did not start: ' + why(r, 'no answer') + '.'; redraw(t); return; } t.S = Object.assign({}, t.S, { running: true }); t.block = Object.assign({}, t.block, { structure: undefined }); redraw(t); poll(t, 'structure'); return; }
266
- 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.Z = Object.assign({}, t.Z, { running: true }); t.block = Object.assign({}, t.block, { design: undefined }); redraw(t); poll(t, 'design'); return; }
267
- 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; }
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; }
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; }
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; }
268
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; }
269
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; }
270
300
  if (a === 'd-keep') {
@@ -291,16 +321,45 @@ async function press(t, e) {
291
321
  redraw(t);
292
322
  }
293
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
+ }
294
351
  async function setUp(t) {
295
352
  const p = t.block.proposal;
296
353
  const schedule = t.sched === 'off' ? { cadence: 'weekly', day: 'Mon', time: '09:00' } : t.sched;
297
354
  await act(t, async () => {
355
+ const named = t.block.sections;
298
356
  const r = await post('/api/report-setups/setup', { proposal: { name: p.name, purpose: p.purpose || p.name, audience: p.audience, source: 'work', output: p.output, schedule,
299
- sources: p.sources.length ? p.sources : ['The records of this workspace'], learned_from: 'Set up from a chat.' } });
357
+ sources: p.sources.length ? p.sources : ['The records of this workspace'], learned_from: 'Set up from a chat.' }, ...(named ? { sections: named } : {}) });
300
358
  if (!r || !r.ok) return 'It was not set up: ' + why(r, 'the page could not reach PMOS') + '.';
301
359
  if (t.sched === 'off') await post('/api/report-setups/edit', { id: r.setup.id, schedule: { cadence: 'off' } });
302
360
  // the view now shows the set-up report, under the same id, so the card stays on it
303
- const shape = t.block.structure;
361
+ const look = { text: t.block.design || '', sample: t.block.sample || '' };
362
+ const shape = r.structure ? null : named ? 'Use exactly these sections, in this order: ' + named.join('; ') + '.' : t.block.structure;
304
363
  t.block = { kind: 'report', id: r.setup.id }; t.loaded = false; show(t); await load(t);
305
364
  const d = r.drafted || {};
306
365
  // the change Claude proposed with the new report: start it now, the PM keeps it with Use this (batch 20 item 9)
@@ -310,6 +369,12 @@ async function setUp(t) {
310
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.'; }
311
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.'; }
312
371
  }
313
- return 'Set up. ' + (d.path ? 'The first draft is written.' : 'The first draft was not written' + (d.error ? ': ' + d.error : '') + '.') + (t.sched === 'off' ? ' Schedule is Off, so it runs once.' : '') + shaping;
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);
375
+ if (r.structure) t.view = 'structure';
376
+ const first = d.drafting ? 'Claude is writing the first draft with your ' + named.length + ' sections. It opens under Reports when it lands.'
377
+ : d.path ? 'The first draft is written.' : 'The first draft was not written' + (d.error ? ': ' + d.error : '') + '.';
378
+ return 'Set up' + (r.structure ? ' with your sections. ' : '. ') + first + (t.sched === 'off' ? ' Schedule is Off, so it runs once.' : '') + shaping;
314
379
  });
315
380
  }
@@ -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)
@@ -43,6 +43,20 @@ function cleanChartBlock(b) {
43
43
  return out;
44
44
  }
45
45
 
46
+ /** The sections the PM named, in order: up to 10 short titles, each once. null when there are none. */
47
+ function cleanSections(v) {
48
+ if (!Array.isArray(v)) return null;
49
+ const seen = new Set();
50
+ const out = v.filter((x) => typeof x === 'string').map((x) => clip(x, 80)).filter((x) => x && !seen.has(x.toLowerCase()) && seen.add(x.toLowerCase())).slice(0, 10);
51
+ return out.length ? out : null;
52
+ }
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
+
46
60
  /** The block as the tab uses it, or null when it is not a block. Unknown keys are dropped; text is clipped. */
47
61
  export function cleanBlock(b) {
48
62
  if (b && typeof b === 'object' && (b.kind === 'chart' || b.kind === 'dashboard')) return cleanChartBlock(b);
@@ -51,12 +65,13 @@ export function cleanBlock(b) {
51
65
  const out = { kind: 'report', id: b.id };
52
66
  if (b.schedule !== undefined) { const s = cleanSchedule(b.schedule); if (s) out.schedule = s; }
53
67
  for (const k of ['structure', 'design']) { const v = clip(b[k], 600); if (v) out[k] = v; }
68
+ const secs = cleanSections(b.sections); if (secs) out.sections = secs;
54
69
  return out;
55
70
  }
56
71
  const p = b.proposal && typeof b.proposal === 'object' ? b.proposal : null;
57
72
  if (!p || !clip(p.name, 80)) return null;
58
- const shape = clip(b.structure, 600);
59
- return { kind: 'report', ...(shape ? { structure: shape } : {}), 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: {
60
75
  name: clip(p.name, 80), purpose: clip(p.purpose, 400), audience: clip(p.audience, 120) || 'The team',
61
76
  output: OUTPUTS.includes(p.output) ? p.output : 'google-doc', schedule: cleanSchedule(p.schedule) === 'off' ? null : cleanSchedule(p.schedule),
62
77
  sources: (Array.isArray(p.sources) ? p.sources : []).map((x) => clip(x, 160)).filter(Boolean).slice(0, 8),
@@ -86,5 +101,7 @@ export function reportChipHtml(block, i) {
86
101
  const what = k === 'report' && !P ? (block.schedule ? 'Schedule change' : block.structure || block.design ? 'Report change' : 'Report')
87
102
  : P && !block.id ? 'New ' + noun : P ? noun[0].toUpperCase() + noun.slice(1) + ' change' : noun[0].toUpperCase() + noun.slice(1);
88
103
  const tab = k === 'report' ? 'Report' : k === 'chart' ? 'Chart' : 'Dashboard';
89
- return `<div class="ctxc"><button type="button" class="ctxchip lead" data-report-open="${i}"><span><b>${esc(name)}</b><em>${esc(what)} · View in the ${tab} tab</em></span></button></div>`;
104
+ // a new report waits for one press, so the chip names it (Wawan, 2026-11-01: "I still don't know how to set it up")
105
+ const next = k === 'report' && P && !block.id ? 'Set it up in the Report tab' : 'View in the ' + tab + ' tab';
106
+ return `<div class="ctxc"><button type="button" class="ctxchip lead" data-report-open="${i}"><span><b>${esc(name)}</b><em>${esc(what)} · ${esc(next)}</em></span></button></div>`;
90
107
  }
@@ -0,0 +1,55 @@
1
+ /* trends-review.js — the words of Intelligence › Delivery trends (batch 22 item 4, canvas MxA–MxD): the month in one ✦ line, "Up N vs last week"
2
+ * on each tile, and "What moved it". PURE: no DOM, no fetch. Every sentence is made from a tile's own value and series; a tile that is not read
3
+ * says nothing, and a number that is not there is never guessed.
4
+ *
5
+ * changeOf(ser, dec) → { d, txt } | null the last week against the one before it, as "Up 7 vs last week"; null when either week is blank
6
+ * movedRows(tiles) → [{ key, label, note, effect }] only the tiles that moved (zero is silence)
7
+ * monthLine(o) → text | null { month, tiles, open } → "November so far: merges are up (...), but 7 of your 14 open initiatives are blocked."
8
+ *
9
+ * A tile here: { key, label, v, ser, abs, change, s } — v is the text shown, ser the weekly series, abs set when the tile is not read, change the
10
+ * server's own { d, txt } where the Board measure has one. lowBetter says which way is good. */
11
+ export const LOW_BETTER = { blocked: true, late: true, idle: true, scope: true, corrections: true, merges: false };
12
+
13
+ const num = (v) => (typeof v === 'number' && Number.isFinite(v) ? v : null);
14
+ const round = (v, dec) => Math.round(v * 10 ** dec) / 10 ** dec;
15
+
16
+ export function changeOf(ser, dec = 0) {
17
+ const S = Array.isArray(ser) ? ser : [], n = S.length, cur = num(S[n - 1]), prev = num(S[n - 2]);
18
+ if (cur === null || prev === null) return null;
19
+ const d = round(cur - prev, dec), a = Math.abs(d).toFixed(dec);
20
+ return { d, txt: (d === 0 ? 'No change' : (d > 0 ? 'Up ' : 'Down ') + a) + ' vs last week' };
21
+ }
22
+
23
+ const moved = (t) => !t.abs && t.change && t.change.d !== 0 && !/^No change/.test(t.change.txt);
24
+ export function movedRows(tiles) {
25
+ return (tiles || []).filter(moved).map((t) => ({ key: t.key, label: t.label, note: t.note || '', effect: t.change.txt }));
26
+ }
27
+
28
+ const list = (a) => (a.length < 2 ? a.join('') : a.slice(0, -1).join(', ') + ' and ' + a[a.length - 1]);
29
+ export function monthLine({ month, tiles, open }) {
30
+ const T = (k) => (tiles || []).find((t) => t.key === k && !t.abs) || null, n = (t) => (t ? Number(t.v) : NaN);
31
+ const good = [], bad = [];
32
+ const mer = T('merges'), cor = T('corrections'), blk = T('blocked'), idl = T('idle'), lat = T('late');
33
+ if (cor) {
34
+ const c = cor.change;
35
+ if (c && c.d < 0) good.push('corrections fell to ' + cor.v + ' per 100 runs');
36
+ else if (c && c.d > 0) bad.push('corrections rose to ' + cor.v + ' per 100 runs'); // no change: the tile says the value, the line stays quiet
37
+ }
38
+ if (mer && Number.isFinite(n(mer))) {
39
+ const d = mer.change ? mer.change.d : null, v = n(mer);
40
+ if (d > 0) good.push('merges are up (' + v + ' this week, ' + d + ' more than last week)');
41
+ else if (d < 0) bad.push('merges are down (' + v + ' this week, ' + -d + ' fewer than last week)');
42
+ else if (d === 0) good.push('merges held at ' + v);
43
+ }
44
+ const of = open ? 'of your ' + open + ' open initiatives ' : '';
45
+ const bl = n(blk), id = n(idl), la = n(lat);
46
+ const tail = [];
47
+ if (bl > 0) tail.push(open ? bl + ' ' + of + (bl === 1 ? 'is' : 'are') + ' blocked' : bl + ' open ' + (bl === 1 ? 'initiative is' : 'initiatives are') + ' blocked');
48
+ if (id > 0) tail.push(id + (open && !tail.length ? ' ' + of : ' ') + (id === 1 ? 'has' : 'have') + ' been idle for a month');
49
+ if (la > 0) tail.push(la + (la === 1 ? ' is' : ' are') + ' late');
50
+ bad.push(...tail);
51
+ if (!good.length && !bad.length) return null;
52
+ const head = (month ? month + ' so far: ' : '');
53
+ const s = good.length ? list(good) + (bad.length ? ', but ' + list(bad) : '') : list(bad);
54
+ return head + s + '.';
55
+ }
@@ -195,9 +195,7 @@ const SPONSORS = '# Inline login slips to early December unless passkeys move to
195
195
  const pd = await until(() => pg.evaluate(() => { const v = document.querySelector('#czViewer .pv'); if (!v) return null; return { goal: !!v.querySelector('.pv-gc'), tabs: [...v.querySelectorAll('[data-pv="tab"]')].map((t) => t.dataset.k + (t.getAttribute('aria-selected') === 'true' ? '*' : '')), over: v.scrollWidth > v.clientWidth + 1, toggle: !!document.querySelector('#czViewer [data-cz-vw-p="dash"]') }; }), 15000);
196
196
  ok('P (' + nm + ') the product page is the one page: the goal card, Tasks, Initiatives (open first), Reports, Documents; no toggle', !!pd && pd.goal && pd.tabs.join() === 'tasks,initiatives*,reports,documents' && !pd.toggle && !pd.over, JSON.stringify(pd));
197
197
  await pg.click('#czViewer [data-pv="tab"][data-k="reports"]');
198
- const mx = await until(() => pg.evaluate(() => { const b = document.querySelector('#czViewer [data-hp="metrics"]'); if (!b) return null; const r = b.getBoundingClientRect(); return { h: r.height, text: b.textContent }; }), 4000);
199
- ok('P (' + nm + ') the metrics review keeps its way in: a row in the Reports tab, 40 px', !!mx && /Metrics review/.test(mx.text) && mx.h >= 40, JSON.stringify(mx));
200
- if (nm === 'desk') { await pg.click('#czViewer [data-hp="metrics"]'); ok('P the row opens the metrics review, ← back to the product', !!(await until(() => pg.evaluate(() => { const c = window.czViewer && window.czViewer.current(); return c && c.id !== 'product' ? c.id : null; })))); }
198
+ ok('P (' + nm + ') the Reports tab has no Metrics review row: it is Intelligence › Delivery trends now', await pg.evaluate(() => !document.querySelector('#czViewer [data-hp="metrics"]')));
201
199
  ok('P (' + nm + ') read as a page to read (scope product)', gets.some((g) => g.scope === 'product' && g.from === 'read'), JSON.stringify(gets));
202
200
  await shot(pg, 'RdProgProduct-' + nm + '-built');
203
201
  ok('0 no page error (product, ' + nm + ')', errs.length === 0, errs.join(' | '));
@@ -65,6 +65,7 @@
65
65
  "agent-inbox.test.js",
66
66
  "session-rail.test.js",
67
67
  "briefing-premium-metrics.test.js",
68
+ "trends-review.test.js",
68
69
  "premium-welcome.test.js",
69
70
  "calendar-events.test.js",
70
71
  "calendar-supersede.test.js",