create-pmos 0.482.0 → 0.484.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 (39) hide show
  1. package/package.json +27 -27
  2. package/payload/KIT-VERSION +2 -2
  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/payload/state/log.md +1 -1
  7. package/workspace/changelog.json +26 -0
  8. package/workspace/guide/briefing-premium.md +6 -2
  9. package/workspace/guide/home.md +1 -1
  10. package/workspace/home-rows-test.js +3 -1
  11. package/workspace/lib/goal-chat.js +29 -5
  12. package/workspace/lib/report-chat.js +3 -2
  13. package/workspace/lib/report-templates.js +172 -0
  14. package/workspace/lib/route-modules.js +1 -0
  15. package/workspace/lib/routes-report-flow.js +184 -0
  16. package/workspace/lib/routes-reports.js +4 -1
  17. package/workspace/package-lock.json +2 -2
  18. package/workspace/package.json +1 -1
  19. package/workspace/premium-chat-report-tab-test.js +40 -33
  20. package/workspace/premium-html-viewer-test.js +6 -0
  21. package/workspace/public/pm/cozy-vw-rp.css +48 -0
  22. package/workspace/public/pm/home-app.js +6 -2
  23. package/workspace/public/pm/home-chat.js +3 -3
  24. package/workspace/public/pm/home-list.js +10 -3
  25. package/workspace/public/pm/home-today.js +2 -2
  26. package/workspace/public/pm/premium-report-read.js +40 -6
  27. package/workspace/public/pm/premium-report-tab.js +163 -74
  28. package/workspace/public/pm/premium-vw-doc.css +6 -1
  29. package/workspace/public/pm/premium-vw-file.js +7 -2
  30. package/workspace/public/pm/premium-vw-pdf.js +42 -0
  31. package/workspace/public/pm/report-chat.js +5 -3
  32. package/workspace/public/pm/report-flow.js +163 -0
  33. package/workspace/public/vendor/pdf.min.js +28 -0
  34. package/workspace/public/vendor/pdf.worker.min.js +28 -0
  35. package/workspace/ready-dash-ui-test.js +2 -1
  36. package/workspace/server.js +3 -0
  37. package/workspace/test-lists/report-flow.json +11 -0
  38. package/workspace/third-party/README.md +9 -4
  39. package/workspace/third-party/pdfjs-dist-5.4.296.LICENSE +177 -0
@@ -53,7 +53,9 @@ 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 { vzStyle } from './premium-vw-open.js'; // registers window.czViews; vzStyle adds the Viewer's sheet (cozy-vw.css)
56
+ import { vzStyle } from './premium-vw-open.js';
57
+ import { reviewHtml, ICON as RF_ICON } from './report-flow.js'; // Claude's review and the template icon (batch 22 item 14, canvas RfH2, RfH6)
58
+ import { adler } from './cozy-adler.js'; // registers window.czViews; vzStyle adds the Viewer's sheet (cozy-vw.css)
57
59
  import { cycleGroups, cycleName, briefModel, briefGlanceHtml, briefConfirmHtml, briefWhyHtml, briefLooksHtml, paperModel, paperHtml, liveModel, liveHtml, presentHtml, dayMon, reportSummary,
58
60
  rpSumHtml, rpBarHtml, cadenceWords, goesOutWords, FORMATS } from './rp-parts.js';
59
61
 
@@ -434,8 +436,35 @@ function bodyHtml() {
434
436
  }
435
437
  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
438
  : 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.edit ? '' : waitHtml()}${R.W && !R.err ? barHtml() : ''}${view}${R.W && !R.err ? foldsHtml() : ''}${askHtml()}</div>`;
439
+ 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 && !R.issued ? rvHtml() : ''}${R.W && !R.err ? foldsHtml() : ''}${askHtml()}</div>`;
438
440
  }
441
+ /* ── Claude's review (batch 22 item 14, canvas RfH2): the checks PMOS runs on the draft, as ✦ fixes the report's own session makes ── */
442
+ function rvHtml() {
443
+ if (!R.rv) return '';
444
+ const n = (R.rv.fix || []).filter((f) => !R.rvHide.has(f.id) && !R.rvSent.has(f.id)).length;
445
+ return reviewHtml(R.rv, { hidden: R.rvHide, sent: R.rvSent, busy: R.busy, face: adler(n ? 'needs-you' : 'handled', 36) });
446
+ }
447
+ async function readReview() {
448
+ const me = R; if (!R || R.issued || !R.row.path) return;
449
+ const j = await Promise.resolve(pmGet('/api/report-flow/review?' + q({ ws: R.ws, path: R.row.path }))).catch(() => null);
450
+ if (R !== me) return;
451
+ R.rv = j && j.ok && j.review ? j.review : null; draw();
452
+ }
453
+ /** Do it (one fix, or all of them): the change goes to the report's own session, never to the PM's chat. */
454
+ async function rvAct(k, v) {
455
+ const me = R, L = (R.rv && R.rv.fix) || [];
456
+ if (k === 'rv-no') { R.rvHide.add(v); return draw(); }
457
+ const todo = (k === 'rv-all' ? L : L.filter((f) => f.id === v)).filter((f) => !R.rvHide.has(f.id) && !R.rvSent.has(f.id));
458
+ if (!todo.length || R.busy) return;
459
+ R.busy = true; draw();
460
+ const r = await pmPost('/api/report-flow/ask', { ws: R.ws, id: R.id, path: R.row.path, text: todo.map((f) => f.title + ' (' + f.why + ')').join('; ') }).catch(() => null);
461
+ if (R !== me) return;
462
+ R.busy = false;
463
+ if (!r || !r.ok) return say('That was not passed on: ' + ((r && r.error) || 'the page could not reach PMOS') + '.', 'bad');
464
+ todo.forEach((f) => R.rvSent.add(f.id));
465
+ say((r.started ? 'The report\'s session started with ' : 'Passed to the report\'s session: ') + (todo.length === 1 ? 'one change' : todo.length + ' changes') + '. They show here as it writes them. Nothing is issued.');
466
+ }
467
+ function openTemplate() { import('./premium-report-tab.js').then((M) => M.openReportTab({ kind: 'report', id: R.id }, { panel: 'template' })); }
439
468
  /** 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
469
  * no indication of me having to wait"). Nothing running → ''. */
441
470
  export function waitWords(x, draft) {
@@ -526,7 +555,7 @@ function wire(b) {
526
555
  const top = b.getBoundingClientRect().top + 80; let n = 1; pgs.forEach((g, k) => { if (g.getBoundingClientRect().top <= top) n = k + 1; });
527
556
  const t = 'Page ' + n + ' of ' + pgs.length; if (c.textContent !== t) c.textContent = t;
528
557
  };
529
- b.onmousemove = (e) => { if (R.view !== 'live' || !R.LV) return; const pt = e.target.closest('.rp-pt'); if (pt) { const h = +pt.dataset.r.split('|')[2]; if (R.LV.hover !== h) { R.LV.hover = h; draw(); } } };
558
+ b.onmousemove = (e) => { if (!R || R.view !== 'live' || !R.LV) return; const pt = e.target.closest('.rp-pt'); if (pt) { const h = +pt.dataset.r.split('|')[2]; if (R.LV.hover !== h) { R.LV.hover = h; draw(); } } };
530
559
  }
531
560
  /* a 1280 x 720 frame scales to its slide's width */
532
561
  const RO = typeof ResizeObserver === 'function' ? new ResizeObserver((es) => { for (const e of es) scaleOf(e.target, e.contentRect.width); }) : null;
@@ -536,6 +565,7 @@ export function fit(root) { root.querySelectorAll('.vz-fr').forEach((c) => { if
536
565
  /* ── the presses ── */
537
566
  const say = (text, tone) => { R.msg = { text, tone }; draw(); };
538
567
  async function act([k, v], t) {
568
+ if (k === 'rv-do' || k === 'rv-no' || k === 'rv-all') return rvAct(k, v);
539
569
  if (k === 'pop') { R.pop = v || null; return draw(); }
540
570
  if (k === 'cut') return cutTo(v);
541
571
  if (k === 'bf') return briefAct(v, t.dataset.r.split('|').slice(2).join('|'));
@@ -927,8 +957,10 @@ export async function openReport(row, hand = {}) {
927
957
  if (R) present(false);
928
958
  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,
929
959
  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,
930
- sch: schedPick(null), schErr: '', shr: null, shares: null, more: [], hand, cuts: hand.cuts ? { on: 'team', team: null, sponsors: null, err: '' } : null, cycles: (hand.cycles || []).slice(), onIssue: hand.onIssue || null, onChange: hand.onChange || null, vid: 'report:' + row.path };
960
+ sch: schedPick(null), schErr: '', shr: null, rv: null, rvHide: new Set(), rvSent: new Set(), shares: null, more: [], hand, cuts: hand.cuts ? { on: 'team', team: null, sponsors: null, err: '' } : null, cycles: (hand.cycles || []).slice(), onIssue: hand.onIssue || null, onChange: hand.onChange || null, vid: 'report:' + row.path };
931
961
  const head = me.head = () => ({ id: me.vid, kind: 'Report' + (me.audience ? ' · ' + me.audience : ''), title: me.name, icon: me.view === 'doc' ? 'doc' : 'report', full: true, url: viewUrl(row, me.ws), more: me.more,
962
+ // the template behind one icon (batch 22 item 14, canvas RfH1): format, readers, when it goes out, and its history
963
+ presses: me.setup ? [{ act: 'template', label: 'Template: format, readers, look, sources', icon: RF_ICON.tune }] : [], onPress: (a) => { if (a === 'template' && R === me) openTemplate(); },
932
964
  render: (b) => { syncMore(); b.innerHTML = panelHtml(); wire(b); }, onClose: () => { if (R === me && !me.reopen) { present(false); R = null; } } });
933
965
  vOpen(head());
934
966
  try { R.text = await textOf('/api/doc?' + q({ ws: R.ws, path: row.path })); R.W = wordsOf(R.text, R.name); if (!hand.name && R.W.title) R.name = R.W.title; } catch (x) { R.err = String((x && x.message) || x); R.W = { title: R.name, sections: [] }; }
@@ -941,7 +973,9 @@ export async function openReport(row, hand = {}) {
941
973
  await Promise.all([readCycle(), readSetup(), readShares()]);
942
974
  if (R !== me) return me;
943
975
  readBrief(); // the Brief tab's count shows at once
944
- if (vCur() && vCur().id === me.vid && (vCur().title !== me.name || me.audience)) { me.reopen = true; vOpen(head()); me.reopen = false; } // the name and audience are known now
976
+ readReview();
977
+ if (hand.say) me.msg = { text: hand.say };
978
+ if (vCur() && vCur().id === me.vid && (vCur().title !== me.name || me.audience || me.setup)) { me.reopen = true; vOpen(head()); me.reopen = false; } // the name and audience are known now
945
979
  draw();
946
980
  watchFile(me);
947
981
  return me;
@@ -957,7 +991,7 @@ async function watchFile(me) {
957
991
  if (document.hidden || me.edit || me.busy || me.pop || (me.cuts && me.cuts.on === 'sponsors')) continue; // the sponsors cut is read from the file, not the file
958
992
  const h = await stamp();
959
993
  if (R !== me || !h) continue;
960
- if (seen && h !== seen) { await reread(); if (R === me && !me.edit && !me.pop) draw(); }
994
+ if (seen && h !== seen) { await reread(); if (R === me && !me.edit && !me.pop) { draw(); readReview(); } }
961
995
  seen = h;
962
996
  }
963
997
  }
@@ -14,12 +14,25 @@
14
14
  * while the shown version is not the saved one, what the look follows (its samples and rules), Current beside New look, the preview, then
15
15
  * Use it (accept) and Keep current (revert to the saved look). GET /api/report-design and its version renders. A confirm asks in the card.
16
16
  *
17
+ * THE REPORT BUILDING FLOW (batch 22 item 14, "A+ on Home", canvas RfH1–RfH7) now leads:
18
+ * A NEW REPORT opens its questions first, Claude's picks filled in (report-flow.js questionsHtml): Format, Readers, Goes out, Look, Sources,
19
+ * "Nothing goes out" and Draft it. Draft it sets it up (POST /api/report-setups/setup), records T1 and the conversation it came from
20
+ * (POST /api/report-flow/start), and opens the report's current state.
21
+ * A SET-UP REPORT opens its current state (GET /api/report-flow): the newest cycle in the reader (premium-report-read.js, with Claude's review),
22
+ * or, while no cycle is written, the drafting line of the report's own session.
23
+ * A CHANGE Claude passes from the chat (block.change) goes to the report's own session (POST /api/report-flow/ask), then the report opens.
24
+ * THE TEMPLATE (panel 'template', the header icon): the same questions on the current version, "changed" marks, Template history with Go back
25
+ * (POST /api/report-flow/restore), Keep the current template and Make a different template (POST /api/report-flow/template). Its sections and
26
+ * look, the cycles and Delete template stay one press further (panel 'manage', the view described above).
27
+ *
17
28
  * Every write is a press here, behind the launch nonce (http.js pmPost). Claude writes nothing: the routes refuse an agent session. A render is
18
29
  * HTML the server sanitized, shown in a frame with an empty sandbox, so nothing in it runs. Nothing is sent outward. */
19
30
  import { pmGet, pmPost } from './http.js';
20
- import { open as vOpen, current as vCur, body as vBody, czSections } from './cozy-viewer.js';
21
- import { rpSumHtml, rpBarHtml, cadenceWords, FORMATS } from './rp-parts.js';
31
+ import { open as vOpen, current as vCur, body as vBody } from './cozy-viewer.js';
32
+ import { FORMATS } from './rp-parts.js';
22
33
  import { vzStyle } from './premium-vw-open.js';
34
+ import * as RF from './report-flow.js';
35
+ import { adler } from './cozy-adler.js';
23
36
 
24
37
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
25
38
  const OUT = FORMATS;
@@ -48,28 +61,75 @@ export function schedChoices(cur) {
48
61
  }
49
62
 
50
63
  const T = new Map(); // view id → its state
64
+ const PASSED = new Set(); // the chat changes passed to a report's session on this page: a second press of the same chip passes nothing
51
65
  /** The report parts' sheet (cozy-vw-rp.css), added to the page once (premium-report-read.js adds the same one). */
52
66
  function rpStyle() {
53
67
  if (typeof document === 'undefined' || document.querySelector('link[data-rp-css]')) return;
54
68
  const l = document.createElement('link'); l.rel = 'stylesheet'; l.href = new URL('./cozy-vw-rp.css', import.meta.url).href; l.setAttribute('data-rp-css', ''); document.head.appendChild(l);
55
69
  }
56
70
  const SV = (d, n = 16) => `<svg viewBox="0 0 24 24" width="${n}" height="${n}" aria-hidden="true"><path d="${d}"/></svg>`;
57
- /** Open (or refresh) the view of a checked report block (report-chat.js cleanBlock). */
58
- export function openReportTab(block) {
71
+ /** Open (or refresh) the view of a checked report block (report-chat.js cleanBlock). o = { chat (the conversation key), panel: 'template' | 'manage', auto (opened by a new answer, not a press) } */
72
+ export function openReportTab(block, o = {}) {
59
73
  if (!block) return null;
60
74
  vzStyle(); rpStyle();
61
75
  const id = 'report:' + (block.id || block.proposal.name).toLowerCase().replace(/[^a-z0-9]+/g, '-').slice(0, 60);
62
76
  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);
77
+ // a proposal that is set up already opens its report, never the questions again (Wawan, 2026-11-01, batch 22 item 13: "it goes back here again")
78
+ if (t && block.proposal && t.block.id && !t.gone) return current(t);
65
79
  if (!t && block.proposal) { setTimeout(() => adoptSetUp(id, block.proposal.name), 0); }
66
- if (!t || JSON.stringify(t.block) !== JSON.stringify(block)) {
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 };
80
+ if (!t || JSON.stringify(t.block) !== JSON.stringify(block) || (o.panel && o.panel !== t.panel)) {
81
+ 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,
82
+ q: block.proposal ? RF.picksOf(block.proposal) : null, panel: block.proposal ? 'new' : o.panel || 'current', chat: o.chat || (t && t.chat) || null, F: null, tq: null, passed: t ? t.passed : false };
68
83
  T.set(id, t);
69
- if (block.id) load(t);
70
- }
84
+ if (block.id && t.panel === 'manage') load(t);
85
+ } else if (o.chat) t.chat = o.chat;
86
+ // a change passes on the PM's press of the chip only; an answer that opens the view by itself shows the report as it is
87
+ if (block.id && block.change && !t.passed && !o.auto && !PASSED.has(JSON.stringify(block))) { PASSED.add(JSON.stringify(block)); t.passed = true; passChange(t); return show(t); }
88
+ if (block.id && t.panel === 'current') return current(t);
89
+ if (block.id && t.panel === 'template') { const v = show(t); loadFlow(t).then(() => redraw(t)); return v; }
71
90
  return show(t);
72
91
  }
92
+ /** The report's state from GET /api/report-flow; for the template, the answers start from its current version. */
93
+ async function loadFlow(t) {
94
+ const F = await get('/api/report-flow', { id: t.block.id });
95
+ t.F = F && F.ok ? F : { err: (F && F.error) || 'The report could not be read.' };
96
+ if (t.F.ok) { const v = (t.F.template.versions || []).find((x) => x.current); t.base = v ? v.settings : { output: t.F.output, audience: t.F.audience, schedule: t.F.status === 'paused' ? 'off' : t.F.schedule }; t.tq = RF.picksOfSettings(t.base); }
97
+ return t.F;
98
+ }
99
+ /** The report's current state: its newest cycle in the reader, or the drafting line until one is written (then the cycle opens by itself). */
100
+ async function current(t, say) {
101
+ t.panel = 'current'; t.F = null; show(t);
102
+ const F = await loadFlow(t);
103
+ if (T.get(t.id) !== t || t.panel !== 'current') return;
104
+ if (F.ok && F.latest) {
105
+ const M = await import('./premium-report-read.js');
106
+ return M.openReportView(F.latest.path, { ws: ws(), name: F.name, ...(say || t.msg ? { say: say || t.msg } : {}) });
107
+ }
108
+ if (say) t.msg = say;
109
+ redraw(t);
110
+ if (F.ok && !t.waiting) waitFor(t);
111
+ }
112
+ /** While the report's own session drafts, read its state every few seconds; the first cycle opens when it lands. */
113
+ async function waitFor(t) {
114
+ t.waiting = true;
115
+ const end = Date.now() + 20 * 60000;
116
+ while (Date.now() < end && T.get(t.id) === t && t.panel === 'current' && paneOf(t)) {
117
+ await new Promise((ok) => setTimeout(ok, 3000));
118
+ if (T.get(t.id) !== t || t.panel !== 'current' || !paneOf(t)) break;
119
+ const F = await get('/api/report-flow', { id: t.block.id });
120
+ if (F && F.ok && F.latest) { t.waiting = false; return current(t); }
121
+ if (F && F.ok && JSON.stringify(F.drafting) !== JSON.stringify(t.F && t.F.drafting)) { t.F = F; redraw(t); }
122
+ }
123
+ t.waiting = false;
124
+ }
125
+ /** A change Claude passed from the chat: to the report's own session, then the report opens (RfH2). */
126
+ async function passChange(t) {
127
+ const r = await post('/api/report-flow/ask', { id: t.block.id, text: t.block.change });
128
+ const said = r && r.ok ? (r.started ? "The report's session started with your change. It shows in the report as it writes it. Nothing is issued." : "Passed to the report's session. It shows in the report as it writes it. Nothing is issued.")
129
+ : 'The change was not passed on: ' + why(r, 'the page could not reach PMOS') + '.';
130
+ t.block = { kind: 'report', id: t.block.id }; t.passed = false;
131
+ return current(t, said);
132
+ }
73
133
  /** 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
134
  async function adoptSetUp(id, name) {
75
135
  const L = await get('/api/report-setups');
@@ -77,13 +137,16 @@ async function adoptSetUp(id, name) {
77
137
  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
138
  if (!hit) return;
79
139
  t.block = { kind: 'report', id: hit.id }; t.loaded = false;
80
- if (paneOf(t)) show(t);
81
- await load(t);
140
+ if (paneOf(t)) await current(t);
82
141
  }
142
+ const TPL = { act: 'template', label: 'Template: format, readers, look, sources', icon: RF.ICON.tune };
143
+ const BACK = { act: 'back', label: 'Back to the report', icon: RF.ICON.back };
83
144
  function show(t) {
84
145
  const P = t.block.proposal;
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',
86
- render: (el) => { el.onclick = (e) => press(t, e); draw(t, el); } });
146
+ const presses = P ? [] : t.panel === 'template' || t.panel === 'manage' ? [BACK] : [TPL];
147
+ return vOpen({ id: t.id, kind: P ? 'Report' + (P.audience ? ' · ' + P.audience : '') : t.panel === 'current' ? 'Report' : 'Report template', title: P ? P.name : (t.F && t.F.name) || (t.setup && t.setup.name) || t.block.id, icon: 'report',
148
+ presses, onPress: (a) => { if (a === 'template') { t.panel = 'template'; show(t); loadFlow(t).then(() => redraw(t)); } else if (a === 'back') current(t); },
149
+ render: (el) => { el.onclick = (e) => press(t, e); el.oninput = (e) => typed(t, e); el.onchange = (e) => picked(t, e); draw(t, el); } });
87
150
  }
88
151
  const paneOf = (t) => (vCur() && vCur().id === t.id ? vBody() : null);
89
152
  const redraw = (t) => { const el = paneOf(t); if (el) draw(t, el); };
@@ -154,7 +217,10 @@ function askHtml(t) {
154
217
  return `<div class="vz-ask2" role="group" aria-label="${esc(A.yes)}"><span>${esc(A.text)}</span><div><button type="button" class="vz-issue vz-hv vz-h36" data-rt="askyes" data-k="bad">${esc(A.yes)}</button><button type="button" class="vz-sec2 vz-hv vz-h36" data-rt="askno">${esc(A.no)}</button></div></div>`;
155
218
  }
156
219
  function draw(t, el) {
157
- el.innerHTML = `<div class="vz ${t.block.proposal ? 'vz-dk' : 'vz-rtp'}" data-vw="${esc(t.id)}">${askHtml(t)}${t.block.proposal ? newHtml(t) : setupHtml(t)}${t.msg ? `<p class="vz-msg" role="status">${esc(t.msg)}</p>` : ''}</div>`;
220
+ const P = t.block.proposal, flow = !!P || t.panel === 'template';
221
+ const inner = P ? RF.questionsHtml(t.q, { look: t.block.design || (t.block.sample ? 'Follow ' + String(t.block.sample).split('/').pop() : ''), sources: P.sources, busy: t.busy, msg: t.msg })
222
+ : t.panel === 'template' ? templateHtml(t) : t.panel === 'manage' ? setupHtml(t) : currentHtml(t);
223
+ el.innerHTML = `<div class="vz vz-rtp" data-vw="${esc(t.id)}"${t.panel ? ` data-panel="${esc(t.panel)}"` : ''}>${askHtml(t)}${inner}${t.msg && !flow ? `<p class="vz-msg" role="status">${esc(t.msg)}</p>` : ''}</div>`;
158
224
  el.querySelectorAll('iframe[data-rt-frame]').forEach((f) => { f.srcdoc = t.render.get(+f.dataset.rtFrame) || ''; });
159
225
  }
160
226
  /** The new report as slides: its title slide, then one slide per section every new report has. */
@@ -163,37 +229,37 @@ export function deckOf(p, sections) {
163
229
  }
164
230
  /** The sections a new report will have: the ones the PM named in the chat (block.sections), else the standard frame. */
165
231
  export const frameOf = (sections) => (Array.isArray(sections) && sections.length ? sections.map((h) => [h, '']) : FRAME);
166
- /**
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
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)
169
- * and the format. Slides | Document, then the deck (the slide, ‹ Slide n of N ›, the thumbnails) or the outline as a page. The folds are
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.
171
- */
172
- function newHtml(t) {
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];
174
- const sum = rpSumHtml({ line: 'New · from your chat', tone: 'you', right: 'Not set up yet',
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.',
178
- chips: [{ icon: 'repeat', label: cadenceWords(t.sched), act: 'sched', exp: t.open }, { icon: 'file', label: OUT[p.output] || p.output || 'PDF' }],
179
- primary: { act: 'setup', label: t.busy ? 'Setting it up' : 'Set it up', icon: 'check', disabled: t.busy } }, 'data-rt');
180
- const bar = rpBarHtml({ view: t.nv, views: [['deck', 'Slides'], ['doc', 'Document']] }, 'data-rt');
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>`
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>`
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>`;
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>` : '';
188
- const folds = czSections([
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>` },
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>` },
195
- ], { key: 'report-new' });
196
- return sum + schedMenu(t, t.sched) + bar + (t.nv === 'doc' ? page : deck) + folds;
232
+ /** The report's current state while no cycle is written yet (RfH1). */
233
+ function currentHtml(t) {
234
+ if (!t.F) return '<p class="vz-empty" role="status">Reading the report.</p>';
235
+ if (t.F.err) return `<p class="vz-msg" data-tone="bad">${esc(t.F.err)}</p>`;
236
+ return RF.waitHtml(t.F, adler(t.F.drafting && t.F.drafting.state === 'ended' ? 'honest' : 'thinking', 36));
237
+ }
238
+ /** The template (RfH3): the questions on its current version, what changed, its history, Keep the current template | Make a different template. */
239
+ function templateHtml(t) {
240
+ if (!t.F) return '<p class="vz-empty" role="status">Reading the template.</p>';
241
+ if (t.F.err) return `<p class="vz-msg" data-tone="bad">${esc(t.F.err)}</p>`;
242
+ const T0 = t.F.template || {};
243
+ const tpl = { base: t.base, current: T0.current, versions: T0.versions || [], diff: RF.diffOf(t.tq, t.base) };
244
+ return RF.questionsHtml(t.tq, { template: tpl, busy: t.busy, msg: t.msg })
245
+ + `<p class="vz-note">Its sections and look, and its cycles: <button type="button" class="rp-linkbtn vz-hv" data-rt="manage">Sections, look and cycles</button></p>`;
246
+ }
247
+ const qOf = (t) => (t.block.proposal ? t.q : t.tq);
248
+ /** Readers, typed: kept as typed; Draft it and Make a different template wait for a name. */
249
+ function typed(t, e) {
250
+ const k = e.target && e.target.dataset ? e.target.dataset.rt : '';
251
+ const q = qOf(t); if (k !== 'aud' || !q) return;
252
+ q.audience = e.target.value;
253
+ const b = paneOf(t) && paneOf(t).querySelector(t.block.proposal ? '[data-rt="draftit"]' : '[data-rt="maketpl"]');
254
+ if (b) b.disabled = t.busy || !q.audience.trim() || (!t.block.proposal && !RF.diffOf(q, t.base).length);
255
+ }
256
+ /** A pick in Goes out (how often, the day, the time). The template redraws, so its "changed" marks follow. */
257
+ function picked(t, e) {
258
+ const k = e.target && e.target.dataset ? e.target.dataset.rt : '';
259
+ const q = qOf(t); if (!q) return;
260
+ if (k === 'aud') { q.audience = e.target.value; redraw(t); return; }
261
+ if (k === 'cad') q.cadence = e.target.value; else if (k === 'day') q.day = e.target.value; else if (k === 'dom') q.dayOfMonth = +e.target.value || 1; else if (k === 'time') q.time = e.target.value; else return;
262
+ redraw(t);
197
263
  }
198
264
  function setupHtml(t) {
199
265
  const s = t.setup;
@@ -274,6 +340,33 @@ async function press(t, e) {
274
340
  const b = e.target.closest('[data-rt]'); if (!b || b.disabled) return;
275
341
  const [a, v] = [b.dataset.rt.split('|')[0], b.dataset.rt.slice(b.dataset.rt.indexOf('|') + 1)];
276
342
  const cur = t.block.proposal ? t.sched : t.setup && (t.setup.status === 'paused' ? 'off' : t.setup.schedule);
343
+ if (a === 'fmt' || a === 'rep') { const q = qOf(t); if (!q) return; if (a === 'fmt') q.output = v; else q.repeat = v === '1'; redraw(t); return; }
344
+ if (a === 'draftit') { await setUp(t); return; }
345
+ if (a === 'keep') { await current(t); return; }
346
+ if (a === 'manage') { t.panel = 'manage'; t.loaded = false; show(t); await load(t); return; }
347
+ if (a === 'maketpl') {
348
+ await act(t, async () => {
349
+ const r = await post('/api/report-flow/template', { id: t.block.id, settings: RF.settingsOfPicks(t.tq) });
350
+ if (!r || !r.ok) return 'The template did not change: ' + why(r, 'the page could not reach PMOS') + '.';
351
+ if (r.state) t.F = r.state; await loadFlow(t);
352
+ return 'T' + r.n + ' is the current template. The next draft follows it; the earlier drafts and cycles stay with their own.';
353
+ });
354
+ return;
355
+ }
356
+ if (a === 'restore') {
357
+ await act(t, async () => {
358
+ const r = await post('/api/report-flow/restore', { id: t.block.id, n: +v });
359
+ if (!r || !r.ok) return 'It did not go back: ' + why(r, 'the page could not reach PMOS') + '.';
360
+ await loadFlow(t);
361
+ return 'Back to T' + r.n + '. It is the current template again. Nothing is deleted.';
362
+ });
363
+ return;
364
+ }
365
+ if (a === 'redraft') {
366
+ await act(t, async () => { const r = await post('/api/report-setups/draft', { id: t.block.id }); if (!r || !r.ok) return 'The draft did not start: ' + why(r, 'the page could not reach PMOS') + '.'; return null; });
367
+ await current(t);
368
+ return;
369
+ }
277
370
  if (a === 'askno') { t.ask = null; redraw(t); return; }
278
371
  if (a === 'askyes') { const A = t.ask; t.ask = null; if (A) await A.run(); return; }
279
372
  if (a === 'sl') { t.i += +v; redraw(t); return; }
@@ -348,33 +441,29 @@ async function startLook(t, id, look) {
348
441
  t.Z = Object.assign({}, t.Z, { running: true }); poll(t, 'design');
349
442
  return ' Claude is making the look' + (added ? ' from ' + added : '') + ' now.';
350
443
  }
444
+ /** Draft it (RfH4, RfH7): the answers set the report up, T1 and the conversation are recorded, and its current state opens (RfH1). */
351
445
  async function setUp(t) {
352
- const p = t.block.proposal;
353
- const schedule = t.sched === 'off' ? { cadence: 'weekly', day: 'Mon', time: '09:00' } : t.sched;
354
- await act(t, async () => {
355
- const named = t.block.sections;
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,
357
- sources: p.sources.length ? p.sources : ['The records of this workspace'], learned_from: 'Set up from a chat.' }, ...(named ? { sections: named } : {}) });
358
- if (!r || !r.ok) return 'It was not set up: ' + why(r, 'the page could not reach PMOS') + '.';
359
- if (t.sched === 'off') await post('/api/report-setups/edit', { id: r.setup.id, schedule: { cadence: 'off' } });
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 || '' };
362
- const shape = r.structure ? null : named ? 'Use exactly these sections, in this order: ' + named.join('; ') + '.' : t.block.structure;
363
- t.block = { kind: 'report', id: r.setup.id }; t.loaded = false; show(t); await load(t);
364
- const d = r.drafted || {};
365
- // the change Claude proposed with the new report: start it now, the PM keeps it with Use this (batch 20 item 9)
366
- let shaping = '';
367
- if (shape) {
368
- const s = await post('/api/report-structure/turn', { id: r.setup.id, text: shape });
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.'; }
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.'; }
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);
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;
379
- });
446
+ const p = t.block.proposal, q = t.q, st = RF.settingsOfPicks(q), once = st.schedule === 'off';
447
+ const schedule = once ? { cadence: 'weekly', day: 'Mon', time: '09:00' } : st.schedule;
448
+ const named = t.block.sections;
449
+ t.busy = true; t.msg = ''; redraw(t);
450
+ const r = await post('/api/report-setups/setup', { proposal: { name: p.name, purpose: p.purpose || p.name, audience: st.audience || p.audience, source: 'work', output: st.output, schedule,
451
+ sources: p.sources.length ? p.sources : ['The records of this workspace'], learned_from: 'Set up from a chat.' }, ...(named ? { sections: named } : {}) });
452
+ if (!r || !r.ok) { t.busy = false; t.msg = 'It was not drafted: ' + why(r, 'the page could not reach PMOS') + '.'; redraw(t); return; }
453
+ if (once) await post('/api/report-setups/edit', { id: r.setup.id, schedule: { cadence: 'off' } });
454
+ await post('/api/report-flow/start', { id: r.setup.id, ...(t.chat ? { chat: t.chat } : {}) });
455
+ const look = { text: t.block.design || '', sample: t.block.sample || '' };
456
+ const shape = r.structure ? null : named ? 'Use exactly these sections, in this order: ' + named.join('; ') + '.' : t.block.structure;
457
+ t.block = { kind: 'report', id: r.setup.id }; t.busy = false;
458
+ // the change Claude proposed with the new report starts now; the PM keeps it with Use this under Sections, look and cycles (batch 20 item 9)
459
+ let shaping = '';
460
+ if (shape) {
461
+ const s2 = await post('/api/report-structure/turn', { id: r.setup.id, text: shape });
462
+ shaping = s2 && s2.ok ? ' Claude is reshaping the sections to your change.' : ' The change to its sections did not start: ' + why(s2, 'no answer') + '.';
463
+ }
464
+ // the look Claude proposed with it (batch 22 item 13): the PM's words, and the file to follow
465
+ if (look.text || look.sample) shaping += await startLook(t, r.setup.id, look);
466
+ const d = r.drafted || {};
467
+ const first = d.drafting ? "The report's own session is drafting it." : d.path ? 'The first draft is written. Claude reads it as your readers would.' : 'The first draft was not written' + (d.error ? ': ' + d.error : '') + '.';
468
+ return current(t, first + (once ? ' It goes out once.' : '') + shaping);
380
469
  }
@@ -257,4 +257,9 @@ iframe.vwprint{position:fixed;right:0;bottom:0;width:1px;height:1px;border:0;opa
257
257
  .vwdoc.vwpdf{max-width:none;padding:0 0 8px}
258
258
  .vwpdf .vwfile{display:flex;flex-direction:column;gap:6px}
259
259
  .vwpdf .vwpdff{height:calc(100dvh - 150px);min-height:420px}
260
- .vwpdf .cff{display:flex;gap:8px;font-size:var(--fs-1);color:var(--ink3);padding:0 2px}
260
+ .vwpdf .cff{display:flex;gap:8px;font-size:var(--fs-1);color:var(--ink-3);padding:0 2px}
261
+ .vwpdfr{display:flex;flex-direction:column;gap:8px}
262
+ .vwpdfp{display:flex;flex-direction:column;gap:8px}
263
+ .vwpdfp canvas{display:block;border-radius:4px;box-shadow:0 0 0 1px var(--hair)}
264
+ .vwpdfs{margin:0;font-size:var(--fs-1);color:var(--ink-3)}
265
+ .vwpdfs:empty{display:none}
@@ -9,6 +9,7 @@
9
9
  * openChatFile(path, { session, ws }) -> the tab's pane */
10
10
  import { vwOpen, vwStyle } from './premium-viewer.js';
11
11
  import { bodyHtml, pageHead, splitDoc, readMinutes } from './premium-vw-doc-model.js';
12
+ import { needsReader, drawPdf } from './premium-vw-pdf.js';
12
13
 
13
14
  const CHECK_MS = 2500;
14
15
  const esc = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
@@ -100,7 +101,10 @@ export function fileHtml(f, view = 'page') {
100
101
  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
102
  }
102
103
  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="vwfile">${''/* the Viewer's header names the file: the PDF takes the whole width (Wawan, 2026-11-02) */}<iframe class="vwframe vwpdff" title="${esc(f.name)}" src="${esc(f.src)}#view=FitH"></iframe>`
104
+ if (f.kind === 'pdf' && f.src) return `<div class="vwdoc vwpdf"><article class="vwfile">${''/* the Viewer's header names the file: the PDF takes the whole width (Wawan, 2026-11-02) */}`
105
+ // a phone cannot show a PDF in a frame: the Viewer draws every page itself (premium-vw-pdf.js, batch 22 item 18)
106
+ + (f.reader ? `<div class="vwpdfr" data-pdf-src="${esc(f.src)}"><p class="vwpdfs" role="status">Drawing the pages.</p><div class="vwpdfp"></div></div>`
107
+ : `<iframe class="vwframe vwpdff" title="${esc(f.name)}" src="${esc(f.src)}#view=FitH"></iframe>`)
104
108
  + `<footer class="cff"><span>Read-only · PDF</span><span class="gap"></span><code>${esc(f.abs || f.rel)}</code></footer></article></div>`;
105
109
  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>`;
106
110
  if (f.kind === 'markdown') {
@@ -137,6 +141,7 @@ export function openChatFile(p, ctx = {}) {
137
141
  // Page and Source on an .html file: the press draws the other view; the choice stays while the tab is open
138
142
  // the download icon: one format saves at once; more open a menu under the icon (Escape or a press elsewhere closes it)
139
143
  const wire = (el) => {
144
+ const r = el.querySelector('.vwpdfr[data-pdf-src]'); if (r) drawPdf(r, r.dataset.pdfSrc);
140
145
  el.onclick = (e) => {
141
146
  const d = e.target.closest('[data-fdl]');
142
147
  if (d) { const opts = downloadsOf(st.f); if (opts.length === 1) download(st.f, opts[0].fmt); else dlMenu(d, opts); return; }
@@ -174,7 +179,7 @@ export function openChatFile(p, ctx = {}) {
174
179
  const sig = loc.ws + '/' + loc.rel + '@' + loc.mtime + ':' + loc.size;
175
180
  if (sig === st.sig) return false;
176
181
  // 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; }
182
+ 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', reader: needsReader(typeof navigator === 'undefined' ? null : navigator), src: '/api/asset?' + q({ ws: loc.ws, path: loc.rel }) + '&v=' + encodeURIComponent(String(loc.mtime || '')) }; return true; }
178
183
  const got = await getText('/api/doc?' + q({ ws: loc.ws, path: loc.rel }));
179
184
  st.sig = sig;
180
185
  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 };
@@ -0,0 +1,42 @@
1
+ /* pm/premium-vw-pdf.js — every page of a PDF, drawn in the Viewer where the browser's own PDF viewer cannot (batch 22 item 18,
2
+ * Wawan 2026-11-02: "PDF viewer didn't work on mobile"). iPhone and iPad Safari draw only the first page of a PDF inside a frame,
3
+ * and a phone's Chrome draws none. There the Viewer draws each page itself with pdf.js 5.4.296, vendored offline under D86 as
4
+ * amended 2026-11-02 (public/vendor/pdf.min.js and pdf.worker.min.js). A desktop keeps the browser's own viewer.
5
+ * needsReader(nav) -> true when the browser cannot show a PDF in a frame. Pure, for Node.
6
+ * drawPdf(box, src) -> draws the pages into box (a .vwpdfr); a later call on the same box replaces them. */
7
+ export function needsReader(nav) {
8
+ if (!nav) return false;
9
+ const ua = String(nav.userAgent || '');
10
+ if (/iPad|iPhone|iPod/.test(ua)) return true;
11
+ if (/Macintosh/.test(ua) && (nav.maxTouchPoints || 0) > 1) return true; // an iPad that asks for the desktop site
12
+ return nav.pdfViewerEnabled === false; // a phone's Chrome, Firefox on Android
13
+ }
14
+
15
+ let lib = null;
16
+ const load = () => (lib = lib || import('/vendor/pdf.min.js').then((m) => { m.GlobalWorkerOptions.workerSrc = '/vendor/pdf.worker.min.js'; return m; }));
17
+
18
+ export async function drawPdf(box, src) {
19
+ if (!box) return;
20
+ const run = (box._pdfRun = (box._pdfRun || 0) + 1);
21
+ const say = (t) => { const s = box.querySelector('.vwpdfs'); if (s) s.textContent = t; };
22
+ try {
23
+ const pdf = await (await load()).getDocument({ url: src, isEvalSupported: false }).promise;
24
+ if (run !== box._pdfRun) return;
25
+ const width = Math.max(240, box.clientWidth || 360), dpr = Math.min(2, (typeof devicePixelRatio === 'number' && devicePixelRatio) || 1);
26
+ const pages = box.querySelector('.vwpdfp');
27
+ for (let n = 1; n <= pdf.numPages; n++) {
28
+ const page = await pdf.getPage(n);
29
+ if (run !== box._pdfRun || !box.isConnected) return;
30
+ const vp = page.getViewport({ scale: width / page.getViewport({ scale: 1 }).width });
31
+ const c = document.createElement('canvas');
32
+ c.width = Math.floor(vp.width * dpr); c.height = Math.floor(vp.height * dpr);
33
+ c.style.width = '100%'; c.setAttribute('role', 'img'); c.setAttribute('aria-label', `Page ${n} of ${pdf.numPages}`);
34
+ pages.append(c);
35
+ await page.render({ canvasContext: c.getContext('2d'), viewport: vp, transform: dpr === 1 ? null : [dpr, 0, 0, dpr, 0, 0] }).promise;
36
+ say(n < pdf.numPages ? `Page ${n} of ${pdf.numPages}` : '');
37
+ }
38
+ box.dataset.pages = String(pdf.numPages);
39
+ } catch (e) {
40
+ if (run === box._pdfRun) say('The PDF could not be drawn here.');
41
+ }
42
+ }
@@ -64,7 +64,7 @@ export function cleanBlock(b) {
64
64
  if (typeof b.id === 'string' && ID_RE.test(b.id)) {
65
65
  const out = { kind: 'report', id: b.id };
66
66
  if (b.schedule !== undefined) { const s = cleanSchedule(b.schedule); if (s) out.schedule = s; }
67
- for (const k of ['structure', 'design']) { const v = clip(b[k], 600); if (v) out[k] = v; }
67
+ for (const k of ['structure', 'design', 'change']) { const v = clip(b[k], 600); if (v) out[k] = v; }
68
68
  const secs = cleanSections(b.sections); if (secs) out.sections = secs;
69
69
  return out;
70
70
  }
@@ -98,10 +98,12 @@ export function reportChipHtml(block, i) {
98
98
  const k = block.kind, P = block.proposal;
99
99
  const name = k === 'report' ? (P ? P.name : block.id) : P ? (k === 'chart' ? P.title || P.measure : P.name) : block.id;
100
100
  const noun = k === 'report' ? 'report' : k;
101
- const what = k === 'report' && !P ? (block.schedule ? 'Schedule change' : block.structure || block.design ? 'Report change' : 'Report')
101
+ const what = k === 'report' && !P ? (block.change ? 'Change to the draft' : block.schedule ? 'Schedule change' : block.structure || block.design ? 'Report change' : 'Report')
102
102
  : P && !block.id ? 'New ' + noun : P ? noun[0].toUpperCase() + noun.slice(1) + ' change' : noun[0].toUpperCase() + noun.slice(1);
103
103
  const tab = k === 'report' ? 'Report' : k === 'chart' ? 'Chart' : 'Dashboard';
104
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';
105
+ // a new report: the questions come first, with Claude's picks filled in, then Draft it (batch 22 item 14, canvas RfH4).
106
+ // A set-up report's chip opens its current state; a change goes to the report's own session (RfH2).
107
+ const next = k === 'report' && P && !block.id ? 'Answer a few questions, then Draft it' : k === 'report' && block.change ? "Pass it to the report's session" : k === 'report' ? 'Open the report' : 'View in the ' + tab + ' tab';
106
108
  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>`;
107
109
  }