create-pmos 0.388.0 → 0.390.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 (44) hide show
  1. package/package.json +25 -30
  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/briefing-premium-insights-test.js +22 -27
  8. package/workspace/changelog.json +24 -0
  9. package/workspace/guide/briefing-premium.md +38 -19
  10. package/workspace/lib/briefing-premium-agent.js +3 -0
  11. package/workspace/lib/insights-premium.js +10 -8
  12. package/workspace/lib/report-chat.js +37 -0
  13. package/workspace/lib/routes-insights-premium.js +3 -1
  14. package/workspace/package-lock.json +2 -2
  15. package/workspace/package.json +1 -1
  16. package/workspace/premium-chat-chart-tab-test.js +150 -0
  17. package/workspace/premium-chat-report-tab-test.js +127 -0
  18. package/workspace/premium-report-read-test.js +99 -59
  19. package/workspace/premium-vw-slides-test.js +17 -19
  20. package/workspace/public/pm/goal-chat.js +2 -1
  21. package/workspace/public/pm/premium-chart-draw.js +58 -0
  22. package/workspace/public/pm/premium-chart-tab.js +157 -0
  23. package/workspace/public/pm/premium-chat.js +8 -2
  24. package/workspace/public/pm/premium-insights.js +39 -85
  25. package/workspace/public/pm/premium-report-brief.js +132 -0
  26. package/workspace/public/pm/premium-report-read.js +276 -103
  27. package/workspace/public/pm/premium-report-tab.js +235 -0
  28. package/workspace/public/pm/premium-shell.js +35 -3
  29. package/workspace/public/pm/premium-vw-doc.js +9 -1
  30. package/workspace/public/pm/premium-vw-report.css +60 -0
  31. package/workspace/public/pm/premium-vw-slides.js +14 -5
  32. package/workspace/public/pm/premium.css +71 -122
  33. package/workspace/public/pm/report-chat.js +89 -0
  34. package/workspace/test-lists/premium-chat-chart-tab.json +12 -0
  35. package/workspace/test-lists/premium-chat-report-tab.json +12 -0
  36. package/workspace/premium-studio-chart-test.js +0 -193
  37. package/workspace/premium-studio-report-test.js +0 -277
  38. package/workspace/premium-studio-test.js +0 -185
  39. package/workspace/public/pm/premium-studio-design.js +0 -298
  40. package/workspace/public/pm/premium-studio-report.js +0 -291
  41. package/workspace/public/pm/premium-studio.js +0 -453
  42. package/workspace/test-lists/premium-studio-chart.json +0 -13
  43. package/workspace/test-lists/premium-studio-report.json +0 -9
  44. package/workspace/test-lists/premium-studio.json +0 -9
@@ -1,8 +1,11 @@
1
1
  /* pm/premium-report-read.js — a report document read on the premium Insights page (initiative premium-report-read; planning/prd/premium-report-read-prd.md).
2
- * The mockup's report sheet (prototype/premium-ux-concept/build-src/rep.js.txt): the deck or the page, Present, Download, Print, and the design row
3
- * (versions, samples, This is it). It opens in the page's dialog; the conversation on the left shapes the look.
2
+ * One report, one bar (PM 2026-10-22, mockup /mnt/project-files/premium-reports-from-chat/one-report-editor/report-mockup.html): icon buttons for
3
+ * Slides | Page, the Brief, Edit, Present, Share, Issue and ⋯, the state and the schedule on the same row, and the report's cycles under its name.
4
+ * A new look waits on one line (Use it or Keep current); its samples are chips above the chat box, added with the clip. It opens in the page's
5
+ * dialog; the conversation on the left shapes the look.
4
6
  *
5
- * openReport(row, hand) row = a Reports card document { cadence, slot, date, path, state }; hand = { ws, name (the set-up report's name, or null) }
7
+ * openReport(row, hand) row = a Reports card document { cadence, slot, date, path, state, archived }; hand = { ws, name (the set-up report's name, or
8
+ * null), cycles (every row of the same report, for the cycle chip), onIssue, onChange }
6
9
  * wordsOf(md, fallback) the document as { title, sections: [{ h, lines }] } (pure)
7
10
  * slideHtml(lines) a section's lines as html: paragraphs and lists, as written (pure)
8
11
  *
@@ -11,19 +14,32 @@
11
14
  * shown in a frame with an empty sandbox: nothing in it runs.
12
15
  * WRITES: only the report-design describe, sample, unsample, turn, accept and revert routes, each a press on the page (pmPost, behind the launch nonce). An
13
16
  * issued cycle is frozen: no design row and no turn. Issue (POST /api/report/issue, after a confirm) freezes a draft cycle; the copies in other tools stay in the console.
14
- * Edit opens the report's file as a page in the viewer (premium-vw-doc.js, initiative premium-viewer S2): the one document page every markdown file uses,
15
- * with Present, Print and Download on its bar. Its words are saved there through the /api/doc-sheet routes. */
16
- import { $, esc, openDlg, popKey, toast, turnA, turnU, ptx, setFull } from './premium-shell.js';
17
+ * Edit edits in place (PM 2026-10-22): on Slides it draws the slide editor (premium-vw-slides.js), on Page the page editor (premium-vw-doc.js) inside
18
+ * the dialog, with no viewer tab. Both save through the /api/doc-sheet routes; Save or Cancel brings the report back.
19
+ * The report's lifecycle (initiative premium-reports-from-chat, PM 2026-10-22: the dialog had no Discard, Archive, schedule or Share):
20
+ * Schedule chip the template's schedule (GET /api/report-setups), changed through POST /api/report-setups/edit; Off pauses it. A report with no
21
+ * template has no schedule: the chip says so and opens a chat to set one up.
22
+ * Discard a draft only, after a confirm (POST /api/report-documents/discard); the dialog closes. Issued reports are never deleted.
23
+ * Archive an issued report only, after a confirm (POST /api/report-documents/archive); Bring back undoes it.
24
+ * Share the viewer's share popover (premium-vw-share.js): a password link to a copy of the file as it is now. */
25
+ import { $, esc, openDlg, popKey, toast, turnA, turnU, ptx, setFull, closeDlg } from './premium-shell.js';
17
26
  import { pmGet, pmPost } from './http.js';
18
- import { vwShow } from './premium-viewer.js';
27
+ import { vwStyle } from './premium-viewer.js';
19
28
  import { openDocPage } from './premium-vw-doc.js';
29
+ import { schedWords, schedChoices } from './premium-report-tab.js';
20
30
 
21
31
  const ICO = (p) => `<svg class="i" viewBox="0 0 24 24">${p}</svg>`;
22
32
  const PREV = ICO('<path d="m15 6-6 6 6 6"/>'), NEXT = ICO('<path d="m9 6 6 6-6 6"/>'), CHV = ICO('<path d="M6 9l6 6 6-6"/>'), XI = ICO('<path d="M6 6l12 12M18 6 6 18"/>');
23
33
  const DLI = ICO('<path d="M12 4v11M7 10l5 5 5-5M5 20h14"/>'), PRI = ICO('<path d="M7 9V4h10v5M7 17H5v-6h14v6h-2M8 14h8v6H8z"/>'), PLAY = ICO('<path d="M8 5v14l11-7z"/>');
24
34
  const CHK = ICO('<path d="M5 12.5l4.5 4.5L19 7.5"/>'), PLUS = ICO('<path d="M12 5v14M5 12h14"/>'), SEND = ICO('<path d="M5 12h14M13 6l6 6-6 6"/>');
25
35
  const PEN = ICO('<path d="M4 20h4L19 9l-4-4L4 16z"/>');
26
- const EYE = ICO('<path d="M2 12s4-7 10-7 10 7 10 7-4 7-10 7S2 12 2 12z"/><circle cx="12" cy="12" r="3"/>');
36
+ const SHI = ICO('<circle cx="18" cy="5" r="2.5"/><circle cx="6" cy="12" r="2.5"/><circle cx="18" cy="19" r="2.5"/><path d="m8.2 10.8 7.6-4.4M8.2 13.2l7.6 4.4"/>');
37
+ const BIN = ICO('<path d="M5 7h14M10 7V4h4v3M7 7l1 13h8l1-13"/>'), BOX = ICO('<path d="M4 5h16v4H4zM5 9v10h14V9M10 13h4"/>');
38
+ const DAYS = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'];
39
+ const MORE = ICO('<circle cx="5" cy="12" r="1.6"/><circle cx="12" cy="12" r="1.6"/><circle cx="19" cy="12" r="1.6"/>');
40
+ const CLK = ICO('<circle cx="12" cy="12" r="8"/><path d="M12 8v4l3 2"/>'), CLIP = ICO('<path d="M20 11.5l-8 8a5 5 0 0 1-7-7l8.5-8.5a3.5 3.5 0 0 1 5 5L10 17.5a2 2 0 0 1-3-3l7.5-7.5"/>');
41
+ const SLI = ICO('<rect x="3" y="5" width="18" height="12" rx="1.5"/><path d="M8 21h8M12 17v4"/>'), PGI = ICO('<path d="M6 3h9l4 4v14H6zM14 3v5h5M9 12h7M9 16h7"/>');
42
+ const BRF = ICO('<path d="M5 4h14v16H5zM9 8h6M9 12h6M9 16h3"/>');
27
43
  const W = 1280;
28
44
  const POLL_MS = 800, POLL_MAX = 240000;
29
45
  const DL = [['pptx', 'PowerPoint (.pptx)', 'A title slide, then one slide for each section.'], ['docx', 'Word (.docx)', 'Headings, paragraphs and lists.'],
@@ -100,14 +116,6 @@ function slides() {
100
116
  }
101
117
  return s.X ? s.X.slides.map((x) => ({ k: 'frame', h: x.h, html: x.html, css: s.X.style })) : [];
102
118
  }
103
- function sourceLine() {
104
- const s = source(), d = R.design;
105
- if (s.kind === 'words') return R.err ? 'The document could not be read: ' + R.err : 'The words of the document, as written. ' + (d && d.saved ? 'This cycle is not drawn to the design yet.' : 'No design is saved for this report yet.');
106
- if (s.kind === 'cycle') return 'This cycle, drawn to the saved design' + (R.cycle && R.cycle.design_version ? ' D' + R.cycle.design_version : '') + '.';
107
- if (!s.X) return 'Reading D' + s.n + '.';
108
- return 'Design version D' + s.n + (d && d.saved && d.saved.version === s.n ? ', the saved design.' : ', not saved. Press This is it to keep it.');
109
- }
110
-
111
119
  /* ── drawing ── */
112
120
  export function slideCard(s, mini) {
113
121
  if (s.k === 'frame') return `<div class="rdfc${mini ? ' mini' : ''}">${frame(s.css, s.html, 'pmos-one', s.h)}</div>`;
@@ -131,38 +139,137 @@ function pageHtml() {
131
139
  if (!s.X) return '<p class="note">Reading the render.</p>';
132
140
  return `<div class="rdpf">${frame(s.X.style, s.X.body, '', 'The report as a page')}</div>`;
133
141
  }
134
- function designHtml() {
135
- if (R.issued) return '<div class="rdz"><span class="label">Design</span><span class="rds2">This cycle is issued, so it is frozen with the look it was issued with.</span></div>';
136
- const d = R.design;
137
- if (!d) return `<div class="rdz"><span class="label">Design</span><span class="rds2">${R.dErr ? esc(R.dErr) : 'Reading the design.'}</span></div>`;
138
- const vs = d.versions || [], shown = R.show, saved = d.saved ? d.saved.version : null;
139
- // each sample with its own remove (x): a press, never hover-only, so it works on a phone
140
- const smp = (d.samples || []).length ? 'Follows ' + d.samples.map((x) => `<span class="rdsm"><em title="${esc(x.name)}">${esc(x.name)}</em><button type="button" class="rdsx" data-rr="unsample|${esc(x.id)}" aria-label="Remove the sample ${esc(x.name)}" title="Remove this sample"${R.busy ? ' disabled' : ''}>${XI}</button></span>`).join('') : 'No sample yet.';
141
- const keep = shown === 'cycle' ? '' : saved === shown ? `<span class="s issued">${CHK}Saved as the design</span>` : `<button class="dmcta alt" data-rr="keep"${R.busy ? ' disabled' : ''}>This is it</button>`;
142
- return `<div class="rdz"><span class="label">Design</span><span class="rdv" role="group" aria-label="Design versions"><button data-rr="ver|cycle" aria-pressed="${shown === 'cycle'}">This cycle</button>${vs.map((v) => `<button data-rr="ver|${v.n}" aria-pressed="${shown === v.n}"${R.busy ? ' disabled' : ''} title="${esc(v.turn || '')}">D${v.n}</button>`).join('')}</span>`
143
- + `<span class="rds2">${smp}${d.running || R.busy ? ' <b>PMOS is working on it.</b>' : ''}</span><button class="dlink" data-rr="pick">${PLUS}Add a sample</button><input type="file" id="rdFile" hidden accept=".pdf,.pptx,.docx,.png,.jpg,.jpeg">${keep}</div>`;
144
- }
145
- function mnuHtml(k, label, icon, items) {
146
- return `<span class="dsvw"><button type="button" class="dsvb" data-rr="${k}" aria-haspopup="menu" aria-expanded="${R.mn === k}">${icon}${label}${CHV}</button>${R.mn === k ? `<div class="dsmn" role="menu">${items}</div>` : ''}</span>`;
147
- }
142
+ /** A new look waits (PM 2026-10-22: the This cycle, D1, D2 row was confusing): one line, Use it or Keep current. A new look is a design version
143
+ * that is not the saved one; it is shown below the line while the line is up. */
144
+ const newLook = () => { const d = R.design; return !R.issued && d && d.current != null && (!d.saved || d.saved.version !== d.current) && R.noLook !== d.current ? d.current : null; };
145
+ function lookHtml() {
146
+ if (R.issued) return '';
147
+ if (!R.design) return R.dErr ? `<p class="note rdsrc" role="alert">${esc(R.dErr)}</p>` : '';
148
+ const n = newLook(); if (n == null) return '';
149
+ const v = (R.design.versions || []).find((x) => x.n === n), from = v && v.turn ? '“' + v.turn + '”' : 'your last change';
150
+ return `<div class="dsiss rdlook" role="status"><span><b>New look ready</b> from ${esc(from)}. It is shown below. Use it for this and the next cycles, or keep the current look.</span><span class="dsa"><button type="button" class="dmcta dark" data-rr="lookuse"${R.busy ? ' disabled' : ''}>Use it</button><button type="button" class="dmcta alt" data-rr="lookno"${R.busy ? ' disabled' : ''}>Keep current</button></span></div>`;
151
+ }
152
+ /** The samples the look follows, as chips above the chat box, each with its own remove; the paperclip in the box adds one. */
153
+ function samplesHtml() {
154
+ const L = (R.design && R.design.samples) || [];
155
+ if (!L.length) return '';
156
+ return `<span class="label">Follows</span>` + L.map((x) => `<span class="rdsm"><em title="${esc(x.name)}">${esc(x.name)}</em><button type="button" class="rdsx" data-rr="unsample|${esc(x.id)}" aria-label="Remove the sample ${esc(x.name)}" title="Remove this sample"${R.busy ? ' disabled' : ''}>${XI}</button></span>`).join('');
157
+ }
158
+ function drawSamples() { const el = $('#rdSmp'); if (el) { el.innerHTML = samplesHtml(); el.hidden = !el.innerHTML; } }
159
+ const stLabel = (r) => r.state === 'issued' ? (r.archived ? 'Archived' : 'Issued') : 'Draft';
148
160
  function statusHtml() {
149
- const d = R.design, v = d && d.saved ? d.saved.version : null, file = String(R.row.path).split('/').pop();
150
- return `<div class="dsm2"><span class="chp ${R.issued ? 'ok' : 'warn'}"><i></i>${R.issued ? 'Issued' : 'Draft'}</span>${v ? `<span class="chp mono">D${v}</span>` : ''}<span class="chp mono" title="${esc(R.row.path)}">${esc(file)}</span></div>`;
161
+ return `<span class="chp rdst ${R.issued ? 'ok' : 'warn'}"><i></i>${R.issued ? (R.archived ? 'Archived' : 'Issued') : 'Draft'}${R.edit ? ' · editing' : ''}</span>${R.edit ? '' : schedHtml()}`;
162
+ }
163
+ /** The schedule chip: the template's schedule in a few words, and its choices in a menu. Off is the template paused: nothing drafts it. */
164
+ const curSched = () => R.setup ? (R.setup.status === 'paused' ? 'off' : R.setup.schedule) : null;
165
+ function schedShort(s) {
166
+ if (!s || s === 'off') return 'Off';
167
+ const t = s.time || '09:00';
168
+ return s.cadence === 'daily' ? 'Daily ' + t : s.cadence === 'monthly' ? 'Day ' + (s.dayOfMonth || 1) + ' ' + t : (s.cadence === 'bi-weekly' ? '2 wk ' : '') + (s.day || 'Mon') + ' ' + t;
169
+ }
170
+ function schedHtml() {
171
+ if (R.setup === undefined) return '';
172
+ const cur = curSched(), words = R.setup ? schedWords(cur) : 'none';
173
+ const chip = `<button type="button" class="chp rdsch" data-rr="sched" aria-haspopup="menu" aria-expanded="${!!R.sOpen}" aria-label="Schedule: ${esc(words)}. Change it" title="Schedule: ${esc(words)}"${R.busy ? ' disabled' : ''}>${CLK}<b>${esc(R.setup ? schedShort(cur) : 'None')}</b></button>`;
174
+ if (!R.sOpen) return `<span class="dsvw">${chip}</span>`;
175
+ let menu;
176
+ if (R.setup) {
177
+ const days = cur && cur !== 'off' && (cur.cadence === 'weekly' || cur.cadence === 'bi-weekly')
178
+ ? `<div class="rdsd" role="group" aria-label="Day">${DAYS.map((d) => `<button type="button" data-rr="sday|${d}" aria-pressed="${cur.day === d}">${d}</button>`).join('')}</div>` : '';
179
+ const now = R.setup.source === 'work' && cur !== 'off' ? `<hr><button type="button" role="menuitem" data-rr="draftnow">${SEND}<span>Draft the next cycle now<small>A background run writes it from the saved structure.</small></span></button>` : '';
180
+ menu = schedChoices(cur).map((c, i) => `<button type="button" role="menuitemradio" aria-checked="${schedWords(c) === schedWords(cur)}" data-rr="spick|${i}">${esc(schedWords(c))}${schedWords(c) === schedWords(cur) ? CHK : ''}</button>`).join('')
181
+ + days + '<p class="note rpmn">Off pauses it: nothing drafts it until you pick a schedule again.</p>' + now;
182
+ } else {
183
+ const say = 'Make "' + R.name + '" a report that is drafted every week';
184
+ menu = `<p class="note rpmn">This report has no template, so nothing drafts it on a schedule. Say in a chat how often it should be drafted, then press Set it up.</p><a role="menuitem" data-rr-chat href="/premium-chat.html?say=${esc(encodeURIComponent(say))}">${SEND}<span>Set up a schedule in a chat</span></a>`;
185
+ }
186
+ return `<span class="dsvw">${chip}<div class="dsmn rdsm" role="menu" aria-label="Schedule">${menu}</div></span>`;
151
187
  }
188
+ /** An icon button: its name is its aria-label and its tooltip (PM 2026-10-22: "buttons use icons, no label"). */
189
+ const ib = (k, icon, name, o = {}) => `<button type="button" class="rdib${o.pri ? ' pri' : ''}" data-rr="${k}" aria-label="${esc(name)}" title="${esc(name)}"${o.pressed != null ? ` aria-pressed="${o.pressed}"` : ''}${o.exp != null ? ` aria-haspopup="${o.pop || 'menu'}" aria-expanded="${o.exp}"` : ''}${o.attr || ''}${o.off ? ' disabled' : ''}>${icon}</button>`;
190
+ /** One bar for the report, one row (PM 2026-10-22: "So many different Edit report functions … Fix it", then "too much rows"): Slides | Page, the
191
+ * Brief, the state and the schedule, then Edit, Present, Share, Issue and ⋯. ⋯ names the file and holds Download, Print, and Discard (a draft)
192
+ * or Archive (an issued report). An issued report has no Edit and no Issue. While editing, the bar keeps Slides | Page, which switches the editor. */
152
193
  function barHtml() {
153
- const dm = R.dm ? `<div class="dsmn rpm" role="menu" aria-label="Download"><p class="label">Download a file</p>${DL.map(([k, l, s]) => `<a role="menuitem" data-rr="dl|${k}" href="/api/report-export?${esc(q({ ws: R.ws, path: R.row.path, fmt: k }))}" download>${DLI}<span>${esc(l)}<small>${esc(s)}</small></span></a>`).join('')}<button role="menuitem" data-rr="md">${DLI}<span>Markdown (.md)<small>The file, as written.</small></span></button><p class="note rpmn">The files carry the words, not the look. Print or save as PDF keeps the look.</p></div>` : '';
154
- const item = (k, l, ico, on) => `<button type="button" role="menuitem" data-rr="${k}"${on === undefined ? '' : ` aria-current="${on}"`}>${ico}${l}${on ? CHK : ''}</button>`;
155
- return `<div class="dsvr rdbar">${mnuHtml('rm', 'Read', EYE, item('present', 'Present', PLAY) + item('slides', R.issued ? 'Open the slides' : 'Edit the slides', ICO('<path d="M4 5h16v11H4zM8 20h8M12 16v4"/>')) + item('print', 'Print or save as PDF', PRI))}`
156
- + `<span class="rdsp">${mnuHtml('fm', R.view === 'deck' ? 'Slide deck' : 'Document', ICO('<path d="M12 3 3 8l9 5 9-5-9-5zM3 13l9 5 9-5"/>'), item('view|deck', 'Slide deck', '', R.view === 'deck') + item('view|doc', 'Document', '', R.view === 'doc'))}`
157
- + `<span class="dsvw"><button type="button" class="dsvb" data-rr="dm" aria-haspopup="menu" aria-expanded="${!!R.dm}">${DLI}Download${CHV}</button>${dm}</span>`
158
- + (R.issued ? '' : `<button type="button" class="dsvb" data-rr="page" title="Read and edit the words as a page">${PEN}Edit</button><button type="button" class="dsvb" data-rr="issue" aria-expanded="${!!R.conf}" title="Issue this cycle: it is frozen as it is now">${CHK}Issue</button>`) + '</span></div>';
159
- }
194
+ const views = `<span class="rdvw" role="group" aria-label="${R.edit ? 'Edit as' : 'Read as'}">${ib('view|deck', SLI, 'Slides', { pressed: R.view === 'deck', off: R.edit && R.busy })}${ib('view|doc', PGI, 'Page', { pressed: R.view === 'doc', off: R.edit && R.busy })}</span>`;
195
+ if (R.edit) return `<div class="rdbar">${views}${statusHtml()}<span class="note rdedn">Save or Cancel brings you back.</span></div>`;
196
+ const file = String(R.row.path).split('/').pop();
197
+ const more = R.mo ? `<div class="dsmn rpm rdmo" role="menu" aria-label="More"><p class="note rdfile" title="${esc(R.row.path)}">${esc(file)}</p><p class="label">Download a file</p>${DL.map(([k, l, s2]) => `<a role="menuitem" data-rr="dl|${k}" href="/api/report-export?${esc(q({ ws: R.ws, path: R.row.path, fmt: k }))}" download>${DLI}<span>${esc(l)}<small>${esc(s2)}</small></span></a>`).join('')}`
198
+ + `<button type="button" role="menuitem" data-rr="md">${DLI}<span>Markdown (.md)<small>The file, as written.</small></span></button>`
199
+ + `<button type="button" role="menuitem" data-rr="print">${PRI}<span>Print or save as PDF<small>Keeps the look. The files above carry the words only.</small></span></button><hr>`
200
+ + (R.issued ? `<button type="button" role="menuitem" data-rr="${R.archived ? 'unarchive' : 'archive'}">${BOX}<span>${R.archived ? 'Bring back' : 'Archive'}<small>${R.archived ? 'It goes back with the issued cycles.' : 'Kept for good, listed under Archived in this report’s cycles.'}</small></span></button>`
201
+ : `<button type="button" role="menuitem" class="rdbad" data-rr="discard">${BIN}<span>Discard this draft<small>Asks once. Issued reports are never deleted.</small></span></button>`) + '</div>' : '';
202
+ return `<div class="rdbar">${views}${ib('brief', BRF, 'Brief: how this report is made (opens a tab)')}${statusHtml()}<span class="rdsp"></span>`
203
+ + (R.issued ? '' : ib('edit', PEN, R.view === 'deck' ? 'Edit the slides' : 'Edit the words'))
204
+ + ib('present', PLAY, 'Present')
205
+ + `<span class="dsvw">${ib('share', SHI, 'Share a link to a copy', { exp: false, pop: 'dialog', attr: ' data-fsh' })}</span>`
206
+ + (R.issued ? '' : ib('issue', CHK, 'Issue: freeze this cycle', { pri: 1, exp: !!R.conf, pop: 'true' }))
207
+ + `<span class="dsvw">${ib('mo', MORE, R.issued ? 'More: file, download, print, archive' : 'More: file, download, print, discard', { exp: !!R.mo })}${more}</span></div>`;
208
+ }
209
+ /** The cycle chip under the report's name (PM 2026-10-22: "Each report should have a list of issued/archived/draft report"): this cycle's date,
210
+ * how many cycles the report has, and a menu of them grouped Draft, Issued and Archived. Picking one reads that cycle here. */
211
+ function cycHtml() {
212
+ const C = R.cycles || [], when = R.row.date || R.row.slot;
213
+ if (C.length < 2) return esc(when || '');
214
+ const g = (st, h) => { const L = C.filter((x) => stLabel(x) === st); return L.length ? `<p class="label">${h}</p>` + L.map((x) => `<button type="button" role="menuitemradio" aria-checked="${x.path === R.row.path}" data-rr="cyc|${esc(x.path)}">${esc(x.date || x.slot)}<small>${esc(String(x.path).split('/').pop())}</small>${x.path === R.row.path ? CHK : ''}</button>`).join('') : ''; };
215
+ const menu = R.cOpen ? `<div class="dsmn rdcm" role="menu" aria-label="Cycles">${g('Draft', 'Draft')}${g('Issued', 'Issued')}${g('Archived', 'Archived')}</div>` : '';
216
+ return `<span class="dsvw rdcw"><button type="button" class="chp rdcyc" data-rr="cycm" aria-haspopup="menu" aria-expanded="${!!R.cOpen}" aria-label="Cycle: ${esc(when)}. Pick another cycle">${esc(when)} · ${C.length} cycles${CHV}</button>${menu}</span>`;
217
+ }
218
+ function drawCyc() { const s = $('#dSub'); if (!s || !R) return; s.innerHTML = cycHtml(); s.hidden = !s.innerHTML; }
160
219
  /** Issue it (the console's report Issue, POST /api/report/issue): the press says what it does first, then freezes the bytes the PM read. */
161
220
  function issueHtml() {
162
221
  if (R.issued || !R.conf) return '';
163
222
  return `<div class="dsiss" data-issue-bar="confirm" role="group" aria-label="Issue this cycle"><span>Issue freezes this cycle as it is now. The words and the look stop changing. Nothing is sent to anyone; you share it yourself.</span><span class="dsa"><button type="button" class="dmcta dark" data-rr="issueok"${R.busy ? ' disabled' : ''}>${R.busy ? '<span class="spin"></span>' : CHK}Issue it</button><button type="button" class="dmcta alt" data-rr="issueno"${R.busy ? ' disabled' : ''}>Cancel</button></span></div>`
164
223
  + (R.issueErr ? `<p class="nodef err" role="alert">${esc(R.issueErr)}</p>` : '');
165
224
  }
225
+ /** Discard and Archive ask once, in the same bar as Issue. */
226
+ function askHtml() {
227
+ if (!R.ask) return '';
228
+ const T = { discard: ['Discard this draft? The file is deleted. Issued reports are not touched.', 'Discard', 'Keep it'],
229
+ archive: ['Archive this report? It is kept for good, marked Archived and moved to the end of the Reports list.', 'Archive', 'Cancel'] }[R.ask];
230
+ return `<div class="dsiss" data-ask-bar="${R.ask}" role="group" aria-label="${esc(T[1])}"><span>${esc(T[0])}</span><span class="dsa"><button type="button" class="dmcta dark" data-rr="askok"${R.busy ? ' disabled' : ''}>${R.busy ? '<span class="spin"></span>' : ''}${esc(T[1])}</button><button type="button" class="dmcta alt" data-rr="askno"${R.busy ? ' disabled' : ''}>${esc(T[2])}</button></span></div>`
231
+ + (R.askErr ? `<p class="nodef err" role="alert">${esc(R.askErr)}</p>` : '');
232
+ }
233
+ async function lifeIt(k) {
234
+ const me = R;
235
+ R.busy = true; R.askErr = ''; draw();
236
+ const archived = k === 'archive';
237
+ const r = await pmPost('/api/report-documents/' + (k === 'discard' ? 'discard' : 'archive'), k === 'discard' ? { ws: R.ws, path: R.row.path } : { ws: R.ws, path: R.row.path, archived }).catch(() => null);
238
+ if (R !== me) return;
239
+ R.busy = false;
240
+ if (!r || r.ok !== true) { R.askErr = (k === 'discard' ? 'The draft was not discarded: ' : 'Nothing changed: ') + ((r && r.error) || 'the page could not reach PMOS') + '.'; draw(); return; }
241
+ R.ask = '';
242
+ if (k === 'discard') {
243
+ toast('The draft is discarded.'); if (R.onChange) R.onChange();
244
+ const rest = R.cycles.filter((x) => x.path !== R.row.path);
245
+ if (rest.length) openReport(rest[0], { ...R.hand, cycles: rest }); else closeDlg();
246
+ return;
247
+ }
248
+ R.archived = archived; R.row = { ...R.row, archived };
249
+ R.cycles = R.cycles.map((x) => x.path === R.row.path ? { ...x, archived } : x);
250
+ toast(archived ? 'Archived. It is kept, at the end of the Reports list.' : 'It is back in the Reports list.');
251
+ draw();
252
+ if (R.onChange) R.onChange();
253
+ }
254
+ async function setSched(s) {
255
+ if (!R.setup || R.busy) return;
256
+ const me = R;
257
+ R.busy = true; R.sOpen = false; draw();
258
+ const r = await pmPost('/api/report-setups/edit', { ws: R.ws, id: R.setup.id, schedule: s === 'off' ? { cadence: 'off' } : s }).catch(() => null);
259
+ if (R !== me) return;
260
+ R.busy = false;
261
+ if (!r || r.ok !== true) { toast('The schedule did not change: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'); draw(); return; }
262
+ R.setup = r.setup;
263
+ toast('Schedule: ' + schedWords(curSched()) + '.');
264
+ draw();
265
+ if (R.onChange) R.onChange();
266
+ }
267
+ async function readSetup() {
268
+ const me = R;
269
+ const j = await Promise.resolve(pmGet('/api/report-setups?' + q({ ws: R.ws }))).catch(() => null);
270
+ if (R !== me) return;
271
+ R.setup = j && Array.isArray(j.setups) ? j.setups.find((x) => x.id === R.row.cadence) || null : null;
272
+ }
166
273
  const cycleOf = (row) => {
167
274
  const m = /reports\/([a-z][a-z0-9-]{0,39})\/(\d{4}-\d{2}-\d{2})\.md$/.exec(String(row.path || ''));
168
275
  return { cadence: row.cadence || (m && m[1]) || '', slot: row.slot || (m && m[2]) || '' };
@@ -182,6 +289,7 @@ async function issueIt() {
182
289
  R.busy = false;
183
290
  if (!r || r.ok !== true) { R.issueErr = (r && r.status === 409) || (r && /changed/i.test(r.error || '')) ? 'The file changed since you opened it. Close and open it again, then issue it.' : (r && r.error) || 'The report was not issued.'; draw(); return; }
184
291
  R.issued = true; R.conf = false; R.row = { ...R.row, state: 'issued' };
292
+ R.cycles = R.cycles.map((x) => x.path === R.row.path ? { ...x, state: 'issued' } : x);
185
293
  const eye = $('#dEye'); if (eye) eye.textContent = 'Report · issued';
186
294
  toast('Issued and frozen. Nothing was sent to anyone.');
187
295
  sayA('Issued. This cycle is frozen as you read it. PMOS sends nothing; share it yourself.');
@@ -191,8 +299,16 @@ async function issueIt() {
191
299
  function draw() {
192
300
  if (!R) return;
193
301
  const m = $('#oMain');
302
+ drawCyc(); drawSamples();
303
+ if (R.edit) { // the editor is drawn in #rdEd by its own module: only the head is drawn again, so what is typed stays
304
+ const h = $('#rdHead', m);
305
+ if (h && $('#rdEd', m)) { h.innerHTML = barHtml(); return; }
306
+ m.innerHTML = `<div class="rdr" id="rdR"><div id="rdHead">${barHtml()}</div><div class="rded" id="rdEd"></div></div>`;
307
+ mountEditor();
308
+ return;
309
+ }
194
310
  const keep = document.activeElement && document.activeElement.closest && document.activeElement.closest('#oMain') ? document.activeElement.getAttribute('data-rr') : null;
195
- m.innerHTML = `<div class="rdr" id="rdR">${statusHtml()}${barHtml()}${issueHtml()}<p class="note rdsrc" id="rdSrc">${esc(sourceLine())}</p>${designHtml()}${R.view === 'deck' ? deckHtml() : pageHtml()}<p class="note rdcon">Copies in Confluence or other tools are made in the console. Nothing here sends anything.</p></div>`;
311
+ m.innerHTML = `<div class="rdr" id="rdR"><div id="rdHead">${barHtml()}</div>${issueHtml()}${askHtml()}${R.err ? `<p class="note rdsrc" role="alert">The document could not be read: ${esc(R.err)}</p>` : ''}${lookHtml()}${R.view === 'deck' ? deckHtml() : pageHtml()}</div>`;
196
312
  fit(m);
197
313
  if (keep) { const b = m.querySelector(`[data-rr="${keep}"]`); if (b) b.focus(); }
198
314
  }
@@ -210,6 +326,7 @@ async function onSay(e) {
210
326
  const inp = $('#rdIn'), t = inp.value.trim();
211
327
  if (!t || !R) return;
212
328
  inp.value = ''; sayU(t);
329
+ if (/^Correct "/.test(t)) { await correctBrief(t); return; }
213
330
  if (R.issued) { sayA('This cycle is issued, so its look is frozen. Nothing changed.'); return; }
214
331
  if (R.busy || (R.design && R.design.running)) { sayA('PMOS is still working on the last change. Wait for its answer, then try again.'); return; }
215
332
  const line = sayA('PMOS is working on it.');
@@ -222,10 +339,10 @@ async function onSay(e) {
222
339
  if (!d) return answer(line, 'PMOS did not answer in time. The design is read again when you open the report.');
223
340
  const L = (d.log || []).slice(before).filter((x) => x.kind === 'version' || x.kind === 'error');
224
341
  const last = L[L.length - 1];
225
- if (last && last.kind === 'version' && last.version) { await showVersion(last.version); return answer(line, last.text + ' This is D' + last.version + '. Press This is it to keep it as the design.'); }
342
+ if (last && last.kind === 'version' && last.version) { R.noLook = null; await showVersion(last.version); return answer(line, last.text + ' It is shown in the report. Press Use it to keep it, or Keep current.'); }
226
343
  return answer(line, last ? 'The change did not work: ' + last.text : 'PMOS ended without a new version.');
227
344
  }
228
- function answer(line, t) { R.busy = false; if (line) line.textContent = t; else sayA(t); draw(); }
345
+ function answer(line, t) { R.busy = false; if (line) line.textContent = t; else sayA(t); draw(); refreshBrief(); }
229
346
  /* read the design again until no job runs */
230
347
  async function settle() {
231
348
  const t0 = Date.now();
@@ -255,59 +372,115 @@ async function showVersion(n) {
255
372
  R.i = 0; draw();
256
373
  }
257
374
 
375
+ /** Show the new look when one waits, else this cycle. */
376
+ async function syncShow() { const n = newLook(); if (n != null) await showVersion(n); else if (R.show !== 'cycle') { R.show = 'cycle'; R.i = 0; draw(); } }
377
+ /** A correction of the Brief (its Correct press fills the box with Correct "<section>": …) is a structure turn: a new structure version, shown in
378
+ * the Brief with Use it. The look does not change. */
379
+ async function correctBrief(t) {
380
+ if (!R.setup) { sayA('This report has no template yet, so it has no brief to correct. Say in a chat how often it is drafted, and PMOS sets one up.'); return; }
381
+ const me = R, line = sayA('PMOS is working on the brief.');
382
+ const r = await pmPost('/api/report-structure/turn', { ws: R.ws, id: R.id, text: t }).catch(() => null);
383
+ if (R !== me) return;
384
+ if (!r || r.ok !== true) { line.textContent = 'Nothing changed: ' + ((r && r.error) || 'the correction could not start') + '.'; return; }
385
+ const t0 = Date.now();
386
+ let st = null;
387
+ for (;;) {
388
+ await new Promise((ok) => setTimeout(ok, POLL_MS));
389
+ if (R !== me) return;
390
+ const j = await Promise.resolve(pmGet('/api/report-structure?' + q({ ws: R.ws, id: R.id }))).catch(() => null);
391
+ st = j && j.ok ? j.structure : null;
392
+ if ((st && !st.running) || Date.now() - t0 > POLL_MAX) break;
393
+ }
394
+ if (R !== me) return;
395
+ const last = st && (st.log || []).filter((x) => x.who === 'pmos').pop();
396
+ line.textContent = !st || st.running ? 'PMOS did not answer in time. The brief is read again when you open it.' : (last ? last.text : 'Done.') + (st.current !== st.saved ? ' The Brief shows the new version; press Use it there to keep it.' : '');
397
+ refreshBrief();
398
+ }
399
+
258
400
  /* ── the presses ── */
259
401
  async function act(a) {
260
402
  const [k, v] = a;
261
- if (k === 'view') { R.view = v; R.mn = ''; draw(); return; }
262
- if (k === 'rm' || k === 'fm') { R.mn = R.mn === k ? '' : k; R.dm = false; draw(); return; }
403
+ if (k === 'view') { if (R.view === v) return; R.view = v; R.mo = false; if (R.edit) $('#oMain').innerHTML = ''; draw(); return; }
404
+ if (k === 'mo') { R.mo = !R.mo; R.sOpen = false; R.cOpen = false; draw(); return; }
405
+ if (k === 'cycm') { R.cOpen = !R.cOpen; R.mo = false; R.sOpen = false; draw(); return; }
406
+ if (k === 'cyc') { const row = (R.cycles || []).find((x) => x.path === v); if (row && row.path !== R.row.path) openReport(row, R.hand); else { R.cOpen = false; draw(); } return; }
407
+ if (k === 'brief') { openBrief(); return; }
408
+ if (k === 'draftnow') { R.sOpen = false; await draftNow(); return; }
409
+ if (k === 'lookno') { await lookIt(false); return; }
410
+ if (k === 'lookuse') { await lookIt(true); return; }
411
+ if (k === 'edit') { if (R.issued) return; R.edit = true; R.mo = false; R.sOpen = false; R.conf = false; R.ask = ''; $('#oMain').innerHTML = ''; draw(); return; }
263
412
  if (k === 'prev' || k === 'next') { R.i += k === 'next' ? 1 : -1; draw(); return; }
264
413
  if (k === 'go') { R.i = +v; draw(); return; }
265
- if (k === 'dm') { R.dm = !R.dm; R.mn = ''; draw(); return; }
266
- if (k === 'dl') { R.dm = false; setTimeout(draw, 0); return; }
267
- if (k === 'md') { R.dm = false; saveMd(); draw(); return; }
268
- if (k === 'print') { R.mn = ''; draw(); printIt(); return; }
269
- if (k === 'present') { R.mn = ''; draw(); present(true); return; }
270
- if (k === 'slides') { R.mn = ''; draw(); openSlidesOf(R); return; }
271
- if (k === 'page') { openPage(); return; }
272
- if (k === 'issue') { R.conf = !R.conf; R.issueErr = ''; R.mn = ''; R.dm = false; draw(); return; }
273
- if (k === 'issueno') { R.conf = false; R.issueErr = ''; draw(); return; }
274
- if (k === 'issueok') { if (!R.busy) await issueIt(); return; }
275
- if (k === 'pick') { const f = $('#rdFile'); if (f) f.click(); return; }
276
- if (k === 'unsample') { if (!R.busy) await removeSample(v); return; }
277
- if (k === 'ver') {
278
- if (v === 'cycle') { R.show = 'cycle'; R.i = 0; draw(); return; }
279
- const n = +v;
280
- if (R.design && R.design.current !== n) {
281
- const r = await pmPost('/api/report-design/revert', { ws: R.ws, id: R.id, n }).catch(() => null);
282
- if (!r || r.ok !== true) { toast((r && r.error) || 'D' + n + ' could not be picked.'); return; }
283
- R.design = r.design;
284
- sayA('Back to D' + n + '. The next change builds on it.');
285
- }
286
- await showVersion(n);
414
+ if (k === 'dl') { R.mo = false; setTimeout(draw, 0); return; }
415
+ if (k === 'md') { R.mo = false; saveMd(); draw(); return; }
416
+ if (k === 'print') { R.mo = false; draw(); printIt(); return; }
417
+ if (k === 'present') { R.mo = false; draw(); present(true); return; }
418
+ if (k === 'issue') { R.conf = !R.conf; R.ask = ''; R.issueErr = ''; R.mo = false; R.sOpen = false; draw(); return; }
419
+ if (k === 'discard' || k === 'archive') { R.ask = R.ask === k ? '' : k; R.askErr = ''; R.conf = false; R.mo = false; R.sOpen = false; draw(); return; }
420
+ if (k === 'askno') { R.ask = ''; R.askErr = ''; draw(); return; }
421
+ if (k === 'askok') { if (!R.busy && R.ask) await lifeIt(R.ask); return; }
422
+ if (k === 'unarchive') { R.mo = false; if (!R.busy) await lifeIt('unarchive'); return; }
423
+ if (k === 'sched') { R.sOpen = !R.sOpen; R.mo = false; R.cOpen = false; draw(); return; }
424
+ if (k === 'spick') { await setSched(schedChoices(curSched())[+v]); return; }
425
+ if (k === 'sday') { const c = curSched(); if (c && c !== 'off') await setSched(Object.assign({}, c, { day: v })); return; }
426
+ if (k === 'share') {
427
+ if (R.mo || R.sOpen) { R.mo = false; R.sOpen = false; draw(); }
428
+ const b = $('#oMain [data-rr="share"]'); if (!b) return;
429
+ vwStyle('doc');
430
+ import('./premium-vw-share.js').then((M) => M.shareMenu(b, { name: R.name + ' · ' + (R.row.date || R.row.slot), ws: R.ws, rel: R.row.path, text: R.text || '' }));
287
431
  return;
288
432
  }
289
- if (k === 'keep') {
290
- const n = R.show;
291
- R.busy = true; draw();
292
- const r = await pmPost('/api/report-design/accept', { ws: R.ws, id: R.id, n }).catch(() => null);
293
- R.busy = false;
294
- if (!r || r.ok !== true) { draw(); toast((r && r.error) || 'The design could not be saved.'); return; }
295
- R.design = r.design;
296
- sayA('Saved D' + n + ' as the design of this report. ' + (r.redraw && r.redraw.started ? 'PMOS is drawing this cycle to match it.' : 'Each new cycle is drawn to match it.') + ' Nothing is sent.');
297
- draw();
298
- if (r.redraw && r.redraw.started) { await settle(); await readCycle(); draw(); }
299
- }
433
+ if (k === 'issueno') { R.conf = false; R.issueErr = ''; draw(); return; }
434
+ if (k === 'issueok') { if (!R.busy) await issueIt(); return; }
435
+ if (k === 'unsample') { if (!R.busy) await removeSample(v); }
300
436
  }
301
- /** The report's file as the document page, with this report's Present, Print and Download on its bar. A save there reads the words again here. */
302
- function openPage() {
437
+ /** Use it saves the new look as the design (report-design accept); Keep current goes back to the saved look (revert), or, with none saved yet,
438
+ * puts the line away until the next change. */
439
+ async function lookIt(use) {
440
+ const n = newLook(); if (n == null || R.busy) return;
303
441
  const me = R;
304
- openDocPage({ path: R.row.path, title: R.name + (R.row.slot ? ' · ' + R.row.slot : '') }, {
305
- ws: () => me.ws,
306
- extras: () => [{ k: 'present', label: 'Present', icon: PLAY }, { k: 'slides', label: me.issued ? 'Open the slides' : 'Edit the slides', icon: ICO('<path d="M4 5h16v11H4zM8 20h8M12 16v4"/>') }, { k: 'print', label: 'Print', icon: PRI },
307
- { k: 'dl', label: 'Download', icon: DLI, note: 'The files carry the words, not the look. Print or save as PDF keeps the look.', menu: DL.map(([f, l, sub]) => ({ label: l, sub, icon: DLI, download: true, href: '/api/report-export?' + q({ ws: me.ws, path: me.row.path, fmt: f }) })).concat([{ k: 'md', label: 'Markdown (.md)', sub: 'The file, as written.', icon: DLI }]) }],
308
- onExtra: (k) => { if (R !== me) return; if (k === 'present') { vwShow('main'); act(['present']); } else if (k === 'slides') openSlidesOf(me); else if (k === 'print') printIt(); else if (k === 'md') saveMd(); },
309
- onWrite: async () => { if (R !== me) return; try { R.text = await textOf('/api/doc?' + q({ ws: R.ws, path: R.row.path })); R.W = wordsOf(R.text, R.name); } catch { /* the reader keeps what it had */ } if (R === me) draw(); },
310
- });
442
+ if (!use && !(R.design.saved)) { R.noLook = n; R.show = 'cycle'; R.i = 0; draw(); sayA('Kept the current look. The new one stays in the Brief, under Why it looks like this.'); return; }
443
+ R.busy = true; draw();
444
+ const r = await pmPost('/api/report-design/' + (use ? 'accept' : 'revert'), { ws: R.ws, id: R.id, n: use ? n : R.design.saved.version }).catch(() => null);
445
+ if (R !== me) return;
446
+ R.busy = false;
447
+ if (!r || r.ok !== true) { draw(); toast((r && r.error) || 'The look did not change.'); return; }
448
+ R.design = r.design; R.show = 'cycle'; R.i = 0;
449
+ sayA(use ? 'This look is now the design. ' + (r.redraw && r.redraw.started ? 'PMOS is drawing this cycle to match it.' : 'Each new cycle is drawn to match it.') + ' Earlier looks are listed in the Brief. Nothing is sent.' : 'Kept the current look. The new one stays in the Brief, under Why it looks like this.');
450
+ draw(); refreshBrief();
451
+ if (use && r.redraw && r.redraw.started) { await settle(); if (R !== me) return; await readCycle(); draw(); }
452
+ }
453
+ async function draftNow() {
454
+ const me = R;
455
+ R.busy = true; draw();
456
+ const r = await pmPost('/api/report-setups/draft', { ws: R.ws, id: R.setup.id }).catch(() => null);
457
+ if (R !== me) return;
458
+ R.busy = false; draw();
459
+ if (!r || r.ok !== true) { toast('The next cycle was not drafted: ' + ((r && r.error) || 'the page could not reach PMOS') + '.'); return; }
460
+ toast(r.drafting ? 'Drafting started. The new cycle shows in this report’s cycles when it is written.' : 'Drafted: ' + ((r.drafted && r.drafted.path) || 'the next cycle') + '.');
461
+ if (R.onChange) R.onChange();
462
+ }
463
+ /* ── the Brief: how this report is made, in a viewer tab (premium-report-brief.js) ── */
464
+ function briefCtx() { return { ws: R.ws, id: R.id, name: R.name, issued: R.issued, setup: R.setup, design: R.design, schedWords: schedWords(curSched()), format: R.design && R.design.format,
465
+ correct: (title) => { const inp = $('#rdIn') || $('#askIn'); if (!inp) return; inp.value = 'Correct "' + title + '": '; inp.focus(); },
466
+ goBack: async (n) => { if (!R || R.issued) return; const r = await pmPost('/api/report-design/revert', { ws: R.ws, id: R.id, n }).catch(() => null); if (!r || r.ok !== true) { toast((r && r.error) || 'That look could not be picked.'); return; } R.design = r.design; R.noLook = null; await syncShow(); sayA('That earlier look is shown in the report. Press Use it to keep it, or Keep current.'); refreshBrief(); } }; }
467
+ async function openBrief() { const M = await import('./premium-report-brief.js'); if (R) M.openBrief(briefCtx()); }
468
+ async function refreshBrief() { const M = await import('./premium-report-brief.js'); if (R) M.refreshBrief(briefCtx()); }
469
+ /** Edit in place (PM 2026-10-22): Slides opens the slide editor, Page opens the words, both inside #rdEd. Save or Cancel closes the editor and
470
+ * reads the file again. No viewer tab is opened, so there is one Edit, one Save and one Present for a report. */
471
+ async function mountEditor() {
472
+ const me = R, host = $('#rdEd'); if (!host) return;
473
+ const done = async () => { if (R !== me) return; R.edit = false; await reread(); if (R === me) { $('#oMain').innerHTML = ''; draw(); } };
474
+ if (R.view === 'deck') {
475
+ const m = await import('./premium-vw-slides.js');
476
+ if (R !== me || !host.isConnected) return;
477
+ m.openSlides({ ws: me.ws, path: me.row.path, title: me.name, readOnly: me.issued, host, onClose: done, onSaved: (text) => { if (R !== me) return; R.text = text; R.W = wordsOf(text, R.name); } });
478
+ } else openDocPage({ path: me.row.path, title: me.name + (me.row.slot ? ' · ' + me.row.slot : '') }, { host, ws: () => me.ws, onClose: done });
479
+ }
480
+ async function reread() {
481
+ const me = R;
482
+ try { const t = await textOf('/api/doc?' + q({ ws: R.ws, path: R.row.path })); if (R === me) { R.text = t; R.W = wordsOf(t, R.name); } } catch { /* the reader keeps what it had */ }
483
+ if (R === me) await readCycle();
311
484
  }
312
485
  function saveMd() {
313
486
  const name = (R.row.path.split('/').slice(-2).join('-') || 'report.md');
@@ -322,7 +495,7 @@ async function addSample(file) {
322
495
  if (!data) { toast('The file could not be read.'); return; }
323
496
  const r = await pmPost('/api/report-design/sample', { ws: R.ws, id: R.id, name: file.name, kind, data }).catch((x) => ({ ok: false, error: String(x && x.message || x) }));
324
497
  if (!r || r.ok !== true) { sayA('The sample was not added: ' + ((r && r.error) || 'the press did not go through.')); return; }
325
- await readDesign(); draw();
498
+ await readDesign(); draw(); refreshBrief();
326
499
  sayA('Added "' + file.name + '". Tell me what to take from it, and I make the next version follow it.');
327
500
  }
328
501
 
@@ -334,8 +507,8 @@ async function removeSample(id) {
334
507
  const r = await pmPost('/api/report-design/unsample', { ws: R.ws, id: R.id, sample: id }).catch((x) => ({ ok: false, error: String(x && x.message || x) }));
335
508
  R.busy = false;
336
509
  if (!r || r.ok !== true) { draw(); toast('The sample was not removed: ' + ((r && r.error) || 'the press did not go through.')); return; }
337
- R.design = r.design; draw();
338
- const b = $('#oMain [data-rr="pick"]'); if (b) b.focus();
510
+ R.design = r.design; draw(); refreshBrief();
511
+ const b = $('#rdClip'); if (b) b.focus();
339
512
  sayA('Removed "' + s.name + '". The next version and each new cycle no longer follow it.');
340
513
  }
341
514
 
@@ -382,11 +555,6 @@ function printIt() {
382
555
  }
383
556
 
384
557
  /* ── the slide editor (premium-viewer R-SL1): the same file, in a Slides tab of the viewer; a save reads the words again ── */
385
- async function openSlidesOf(at) {
386
- const m = await import('./premium-vw-slides.js');
387
- m.openSlides({ ws: at.ws, path: at.row.path, title: at.name, readOnly: at.issued, onSaved: (text) => { if (R !== at) return; R.text = text; R.W = wordsOf(text, R.name); draw(); } });
388
- }
389
-
390
558
  /* ── reading the cycle ── */
391
559
  async function readCycle() {
392
560
  const c = await Promise.resolve(pmGet('/api/report-design/cycle?' + q({ ws: R.ws, path: R.row.path }))).catch(() => null);
@@ -398,34 +566,39 @@ async function readCycle() {
398
566
 
399
567
  export async function openReport(row, hand) {
400
568
  if (!row || !row.path) return;
401
- R = { row, ws: hand.ws, id: row.cadence, name: hand.name || row.cadence, issued: row.state === 'issued', text: '', err: '', W: null, view: 'deck', i: 0, cycle: null, cyc: null, show: 'cycle', ver: new Map(), design: null, dErr: '', dm: false, mn: '', busy: false, conf: false, issueErr: '', onIssue: hand.onIssue || null };
569
+ R = { row, ws: hand.ws, id: row.cadence, name: hand.name || row.cadence, issued: row.state === 'issued', text: '', err: '', W: null, view: 'deck', i: 0, cycle: null, cyc: null, show: 'cycle', ver: new Map(), design: null, dErr: '', busy: false, conf: false, issueErr: '',
570
+ onIssue: hand.onIssue || null, onChange: hand.onChange || null, setup: undefined, sOpen: false, ask: '', askErr: '', archived: !!row.archived, edit: false, mo: false,
571
+ hand, cycles: (hand.cycles || []).slice(), cOpen: false, noLook: null };
402
572
  const when = row.date || row.slot;
403
573
  const say = R.issued
404
574
  ? 'This is the ' + when + ' cycle of "' + R.name + '". It is issued, so it is frozen. Read it as a deck or a page, present it, download it or print it. Nothing is sent from here.'
405
- : 'This is the ' + when + ' cycle of "' + R.name + '". Read it as a deck or a page, present it, download it or print it. To change how it looks, add a sample or tell me what to change, then press This is it on the version you want. Nothing is sent from here.';
575
+ : 'This is the ' + when + ' cycle of "' + R.name + '". The Brief (its icon opens a tab) explains how it is made. Tell me how it should look, or attach a sample with the clip. Nothing is sent from here.';
406
576
  openDlg({ eye: 'Report · ' + (R.issued ? 'issued' : 'draft'), title: R.name, sub: when, stream: turnA(ptx(say)), noteKey: R.issued ? popKey('report-cycle', R.id, when) : null, pane: '<p class="note">Reading the document.</p>', label: 'Report' });
407
577
  $('#dlg').classList.add('rdrd');
408
578
  $('#dlg').classList.toggle('rdiss', R.issued); // premium-popup-context P1: an issued cycle has the chat; a draft keeps its own "Say how it should look" box
409
579
  if (!R.issued) { $('#askF').hidden = true; const an = $('#askNote'); if (an) an.hidden = true; }
410
- if (!R.issued) $('#dBody').insertAdjacentHTML('beforeend', `<form class="askbar" id="rdF"><input id="rdIn" placeholder="Say how it should look" maxlength="4000" autocomplete="off" aria-label="Say how the report should look"><button type="submit" aria-label="Send" title="Send">${SEND}</button></form><p class="fine2">A change starts a design run that writes only a new version of the look. The document's words do not change.</p>`);
580
+ if (!R.issued) $('#dBody').insertAdjacentHTML('beforeend', `<div class="rdsmp" id="rdSmp" hidden></div><form class="askbar" id="rdF"><button type="button" class="rdclip" id="rdClip" aria-label="Attach a sample" title="Attach a sample">${CLIP}</button><input type="file" id="rdFile" hidden accept=".pdf,.pptx,.docx,.png,.jpg,.jpeg"><input id="rdIn" placeholder="Say how it should look" maxlength="4000" autocomplete="off" aria-label="Say how the report should look"><button type="submit" aria-label="Send" title="Send">${SEND}</button></form><p class="fine2">A change starts a design run that writes only a new version of the look. The document's words do not change.</p>`);
411
581
  const f = $('#rdF'); if (f) f.onsubmit = onSay;
582
+ const fi = $('#rdFile'), cl = $('#rdClip');
583
+ if (fi && cl) { cl.onclick = () => fi.click(); fi.onchange = () => { if (fi.files && fi.files[0] && R) { addSample(fi.files[0]); fi.value = ''; } }; }
584
+ const sm = $('#rdSmp'); if (sm) sm.onclick = (e) => { const b = e.target.closest('[data-rr^="unsample|"]'); if (b && !b.disabled && R && !R.busy) removeSample(b.dataset.rr.split('|')[1]); };
412
585
  const me = R;
413
586
  try { R.text = await textOf('/api/doc?' + q({ ws: R.ws, path: row.path })); R.W = wordsOf(R.text, R.name); } catch (x) { R.err = String((x && x.message) || x); }
414
587
  if (R !== me) return;
415
- await Promise.all([readCycle(), R.issued ? null : readDesign()]);
588
+ await Promise.all([readCycle(), R.issued ? null : readDesign(), readSetup()]);
416
589
  if (R !== me) return;
417
590
  draw();
591
+ if (!R.issued) await syncShow();
418
592
  }
419
593
 
420
594
  /* The reader's presses. The dialog is shared, so each listener first asks whether the reader is what it holds. */
421
595
  const inReader = (e) => R && $('#dlg').classList.contains('rdrd') && $('#dlg').classList.contains('on') && e.target.closest && e.target.closest('#oMain');
422
596
  document.addEventListener('click', (e) => {
423
- if (!inReader(e)) return;
424
- const t = e.target.closest('[data-rr]');
425
- if (t && !t.disabled) { act(t.dataset.rr.split('|')); return; }
426
- if ((R.dm || R.mn) && !e.target.closest('.dsvw')) { R.dm = false; R.mn = ''; draw(); }
597
+ if (!R || !$('#dlg').classList.contains('rdrd') || !$('#dlg').classList.contains('on') || !e.target.closest) return;
598
+ const inSub = e.target.closest('#dSub');
599
+ if (inReader(e) || inSub) { const t = e.target.closest('[data-rr]'); if (t && !t.disabled) { act(t.dataset.rr.split('|')); return; } }
600
+ if ((R.mo || R.sOpen || R.cOpen) && !e.target.closest('.dsvw')) { R.mo = false; R.sOpen = false; R.cOpen = false; draw(); }
427
601
  });
428
- document.addEventListener('change', (e) => { if (inReader(e) && e.target.id === 'rdFile' && e.target.files && e.target.files[0]) addSample(e.target.files[0]); });
429
602
  document.addEventListener('keydown', (e) => {
430
603
  if (!R) return;
431
604
  if ($('#rdPres')) {