create-pmos 0.389.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.
@@ -3,7 +3,8 @@
3
3
  /* premium-report-read-test.js — a report document read on the premium Insights page (initiative premium-report-read;
4
4
  * planning/prd/premium-report-read-prd.md R1 to R11). A real server on a scratch git repository with two cycles of one report (one issued), and a
5
5
  * stub `claude` on the PATH that plays the report-design job (as c3-report-design-real-test.js does). The real page presses the real routes:
6
- * O opening · D the deck · G the page · N Present · W download · X print · L the look · I issued · P the POST allow-list · F floors
6
+ * O opening · C the cycles · D the deck · G the page · N Present · W download · X print · E edit · L the look · K the Brief · I issued
7
+ * P the POST allow-list · F floors · S issue · A archive
7
8
  * Set READ_SHOTS=<dir> to save screenshots at 1280 and 390 wide. */
8
9
  const fs = require('fs');
9
10
  const os = require('os');
@@ -99,15 +100,25 @@ fs.writeFileSync(path.join(base, 'brand.png'), PNG);
99
100
  await p.goto(BASE + '/premium-insights.html');
100
101
  await until(() => p.evaluate(() => !!document.querySelector('#listSeg [data-f="rep"]')));
101
102
  await (async (pg, sel) => { if (await pg.locator('#listSeg').isHidden()) await pg.click('#listF'); await pg.click(sel); })(p, '#listSeg [data-f="rep"]'); // the one list (insights-one-list L5): the Reports filter holds the report files
102
- await until(() => p.evaluate(() => document.querySelectorAll('#listRows [data-rep]').length === 2));
103
- const rowSel = (slot) => `#listRows [data-rep="rep:${CAD}:${slot}"]`;
103
+ await until(() => p.evaluate(() => document.querySelectorAll('#listRows [data-rpt]').length === 1));
104
+ const ROW = `#listRows [data-rpt="${CAD}"]`;
105
+ ok('C0 one row for the report, with its cycles counted (PM 2026-10-22: no duplicate of the same report)', /1 draft/.test(await p.textContent(ROW)) && /1 issued/.test(await p.textContent(ROW)), await p.textContent(ROW));
106
+ const toCycle = async (rel) => { await p.click('#dSub [data-rr="cycm"]'); await p.click(`#dSub [data-rr="cyc|${rel}"]`); };
104
107
 
105
- /* O: a document row opens the reader on the page */
106
- await tap(rowSel('2026-10-12'));
108
+ /* O: the report row opens its latest cycle in the reader on the page */
109
+ await tap(ROW);
107
110
  await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#rdSlide')));
108
111
  ok('O1 a document row opens the reader on the page, not the console', p.url().includes('/premium-insights.html') && await p.evaluate(() => document.querySelector('#dlg').classList.contains('rdrd')), p.url());
109
112
  ok('O2 the dialog names the report, its date and its state', await p.textContent('#dTitle') === CAD && /2026-10-12|12 Oct/.test(await p.textContent('#dSub')) && /draft/.test(await p.textContent('#dEye')), await p.textContent('#dEye'));
110
- ok('O3 the reader says it reads the words, as written', /The words of the document, as written/.test(await p.textContent('#rdSrc')), await p.textContent('#rdSrc'));
113
+ const bar = await p.evaluate(() => { const L = [...document.querySelectorAll('#oMain .rdbar > *')].filter((x) => x.offsetWidth); return { rows: new Set(L.map((x) => Math.round(x.getBoundingClientRect().top + x.offsetHeight / 2))).size, words: [...document.querySelectorAll('#oMain .rdbar .rdib')].filter((b) => b.textContent.trim() || !b.getAttribute('aria-label') || !b.title).length }; });
114
+ await shot('reader-bar-1280');
115
+ ok('O3 the bar is one row of icon buttons, each named by its label and tooltip', bar.rows === 1 && bar.words === 0, JSON.stringify(bar));
116
+ ok('O4 no source line, no design row and no Add a sample in the report pane', await p.evaluate(() => !document.querySelector('#rdSrc') && !document.querySelector('.rdz') && !document.querySelector('#oMain [data-rr="pick"]')));
117
+ /* C: the cycle chip under the name lists this report's cycles, grouped */
118
+ await p.click('#dSub [data-rr="cycm"]');
119
+ const cm = await p.evaluate(() => ({ chip: document.querySelector('#dSub [data-rr="cycm"]').textContent, groups: [...document.querySelectorAll('#dSub .rdcm .label')].map((x) => x.textContent), items: document.querySelectorAll('#dSub .rdcm [data-rr^="cyc|"]').length }));
120
+ ok('C1 the cycle chip says the date and 2 cycles; its menu groups them Draft and Issued', /12 Oct · 2 cycles/.test(cm.chip) && cm.groups.join() === 'Draft,Issued' && cm.items === 2, JSON.stringify(cm));
121
+ await p.click('#dSub [data-rr="cycm"]');
111
122
 
112
123
  /* D: the deck */
113
124
  ok('D1 the deck has a title slide and one slide per section', await counter() === '1 / 5' && await bigTitle() === 'Partner review, 12 Oct', await counter());
@@ -122,14 +133,18 @@ fs.writeFileSync(path.join(base, 'brand.png'), PNG);
122
133
  await shot('reader-deck-1280');
123
134
 
124
135
  /* G: the page */
125
- await tap('#oMain [data-rr="fm"]'); await tap('#oMain [data-rr="view|doc"]');
136
+ await tap('#oMain [data-rr="view|doc"]');
126
137
  const heads = await p.evaluate(() => [...document.querySelectorAll('.rdpg h3')].map((h) => h.textContent));
127
138
  ok('G1 Document shows the headings as written', heads.join() === 'Headline,Initiatives,Needs your call,Sources' && await p.evaluate(() => document.querySelector('.rdpg h2').textContent) === 'Partner review, 12 Oct', heads.join());
128
- await tap('#oMain [data-rr="fm"]'); await tap('#oMain [data-rr="view|deck"]');
139
+ await tap('#oMain [data-rr="view|deck"]');
129
140
 
130
141
  /* N: Present */
131
142
  await tap('#oMain [data-rr="go|0"]');
132
- await tap('#oMain [data-rr="rm"]'); await tap('#oMain [data-rr="present"]');
143
+ ok('B1 one bar: Slides | Page, Brief, the schedule, Edit, Present, Share, Issue and More', await p.evaluate(() => [...document.querySelectorAll('#oMain .rdbar button')].map((b) => b.dataset.rr).join()) === 'view|deck,view|doc,brief,sched,edit,present,share,issue,mo', await p.evaluate(() => [...document.querySelectorAll('#oMain .rdbar button')].map((b) => b.dataset.rr).join()));
144
+ await tap('#oMain [data-rr="sched"]');
145
+ ok('B2 a report with no template says so in its schedule menu, and offers a chat to set one up', /None/.test(await p.textContent('#oMain [data-rr="sched"]')) && /no template/.test(await p.textContent('#oMain .rdsm')) && !!await p.$('#oMain .rdsm a[href*="premium-chat.html"]'));
146
+ await tap('#oMain [data-rr="sched"]');
147
+ await tap('#oMain [data-rr="present"]');
133
148
  await until(() => p.$('#rdPres'));
134
149
  ok('N1 Present shows the current slide over the whole page', await p.evaluate(() => { const r = document.querySelector('#rdPres').getBoundingClientRect(); return r.width >= innerWidth - 1 && r.height >= innerHeight - 1 && !!document.querySelector('#rdPres .rds.title'); }));
135
150
  await p.keyboard.press('ArrowRight');
@@ -138,86 +153,103 @@ fs.writeFileSync(path.join(base, 'brand.png'), PNG);
138
153
  ok('N3 Escape stops presenting and the reader stays open on that slide', !await p.$('#rdPres') && await p.evaluate(() => document.querySelector('#dlg').classList.contains('on')) && await counter() === '2 / 5');
139
154
 
140
155
  /* W: download */
141
- await tap('#oMain [data-rr="dm"]');
156
+ await tap('#oMain [data-rr="mo"]');
142
157
  const items = await p.evaluate(() => [...document.querySelectorAll('.rpm [role="menuitem"]')].map((a) => a.textContent.split('(')[0].trim() + '|' + (a.getAttribute('href') || '')));
143
- ok('W1 Download offers PowerPoint, Word, Excel, CSV and Markdown, through report-export', items.length === 5 && items.slice(0, 4).every((x, i) => x.includes('/api/report-export?') && x.includes('fmt=' + ['pptx', 'docx', 'xlsx', 'csv'][i]) && x.includes('path=' + encodeURIComponent(pNew))), items.join(' / '));
158
+ ok('W0 More names the file first', await p.evaluate((f) => document.querySelector('.rdmo .rdfile').textContent === f, pNew.split('/').pop()));
159
+ ok('W1 More offers PowerPoint, Word, Excel, CSV and Markdown through report-export, then Print and Discard', items.length === 7 && /Print/.test(items[5]) && /Discard/.test(items[6]) && items.slice(0, 4).every((x, i) => x.includes('/api/report-export?') && x.includes('fmt=' + ['pptx', 'docx', 'xlsx', 'csv'][i]) && x.includes('path=' + encodeURIComponent(pNew))), items.join(' / '));
144
160
  const [dl] = await Promise.all([p.waitForEvent('download'), p.click('.rpm [data-rr="dl|pptx"]')]);
145
161
  const pptx = fs.readFileSync(await dl.path());
146
162
  ok('W2 PowerPoint downloads a .pptx of the document', /\.pptx$/.test(dl.suggestedFilename()) && pptx.slice(0, 2).toString() === 'PK', dl.suggestedFilename());
147
- await tap('#oMain [data-rr="dm"]');
163
+ await tap('#oMain [data-rr="mo"]');
148
164
  const [md] = await Promise.all([p.waitForEvent('download'), p.click('.rpm [data-rr="md"]')]);
149
165
  ok('W3 Markdown downloads the file as written', fs.readFileSync(await md.path(), 'utf8') === DOC && /\.md$/.test(md.suggestedFilename()), md.suggestedFilename());
150
166
 
151
167
  /* X: print */
152
168
  await p.evaluate(() => { window.__pr = null; window.open = () => ({ document: { open() {}, write(h) { window.__pr = h; }, close() {} }, focus() {}, print() { window.__printed = true; } }); });
153
- await tap('#oMain [data-rr="rm"]'); await tap('#oMain [data-rr="print"]'); await sleep(450);
169
+ await tap('#oMain [data-rr="mo"]'); await tap('#oMain [data-rr="print"]'); await sleep(450);
154
170
  const pr = await p.evaluate(() => ({ h: window.__pr || '', printed: !!window.__printed }));
155
171
  ok('X1 Print opens the print page with one slide to a page', pr.printed && /pmos-print-deck/.test(pr.h) && (pr.h.match(/class="pmos-slide"/g) || []).length === 5 && pr.h.includes('premium-report-print.css'), pr.h.slice(0, 300));
156
172
 
157
- /* E: Edit opens the report's file as the one document page (premium-viewer S2), with this report's Present, Print and Download on its bar */
158
- await tap('#oMain [data-rr="page"]');
159
- const VP = '.obody.vw:not([hidden]) .vwdoc';
160
- await until(() => p.evaluate((v) => !!document.querySelector(v + ' .cf'), VP));
161
- ok('E1 Edit opens the report as a page in a viewer tab, with Page, Edit and Markdown', await p.evaluate((v) => { const st = window.__premiumViewer.vwState(); return st.on.startsWith('doc:') && document.querySelectorAll(v + ' .vwseg').length === 3 && /Partner review, 12 Oct/.test(document.querySelector(v + ' .cft').textContent); }, VP));
162
- ok('E2 the page bar carries Present, Print and Download', await p.evaluate((v) => ['Present', 'Print', 'Download'].every((t) => [...document.querySelectorAll(v + ' .vwdt .vwbtn')].some((b) => b.textContent.trim() === t)), VP));
163
- await p.click(VP + ' [data-vd="xm:dl"]');
164
- const pitems = await p.evaluate((v) => [...document.querySelectorAll(v + ' .vwxmn [role="menuitem"]')].map((a) => a.getAttribute('href') || a.dataset.vwx), VP);
165
- ok('E3 its Download lists the same four files through report-export, and the Markdown file', pitems.length === 5 && pitems.slice(0, 4).every((h, i) => h.includes('/api/report-export?') && h.includes('fmt=' + ['pptx', 'docx', 'xlsx', 'csv'][i])) && pitems[4] === 'md', JSON.stringify(pitems));
166
- await p.click(VP + ' [data-vd="xm:dl"]');
167
- await p.click(VP + ' [data-vwx="present"]');
168
- await until(() => p.$('#rdPres'));
169
- ok('E4 Present from the page presents the deck over the whole page', !!(await p.$('#rdPres')) && await p.evaluate(() => window.__premiumViewer.vwState().on === 'main'));
170
- await p.keyboard.press('Escape'); await sleep(200);
173
+ /* E: Edit edits in place (PM 2026-10-22): on Page the page editor, inside the dialog, with no viewer tab; Cancel brings the report back */
174
+ await tap('#oMain [data-rr="view|doc"]');
175
+ await tap('#oMain [data-rr="edit"]');
176
+ const VP = '#rdEd .vwdoc';
177
+ await until(() => p.evaluate((v) => !!document.querySelector(v + ' .cf.editing'), VP));
178
+ ok('E1 Edit on Page opens the page editor in the dialog, in Edit, with Edit and Markdown only', await p.evaluate((v) => document.querySelectorAll(v + ' .vwseg').length === 2 && /Partner review, 12 Oct/.test(document.querySelector(v + ' .cft').textContent) && !document.querySelector(v + ' .vwbtn[data-vwx]') && !document.querySelector(v + ' [data-vd="askt"]'), VP));
179
+ ok('E2 no viewer tab is opened, and the bar keeps only Slides | Page', await p.evaluate(() => !String(window.__premiumViewer.vwState().on || '').startsWith('doc:') && [...document.querySelectorAll('#oMain .rdbar button')].map((b) => b.dataset.rr).join() === 'view|deck,view|doc'));
180
+ await p.click(VP + ' [data-vd="cancel"]');
181
+ await until(() => p.evaluate(() => !document.querySelector('#rdEd') && !!document.querySelector('#oMain [data-rr="edit"]')));
182
+ ok('E3 Cancel brings the report back', await p.evaluate(() => !!document.querySelector('#oMain .rdpg') && !document.querySelector('#rdEd')));
183
+ await tap('#oMain [data-rr="view|deck"]');
171
184
 
172
- /* L: the look */
173
- ok('L1 with no design yet, the design row shows This cycle and no version', await p.evaluate(() => [...document.querySelectorAll('.rdv button')].map((b) => b.textContent).join()) === 'This cycle' && /No sample yet/.test(await p.textContent('.rdz')));
185
+ /* L: the look (PM 2026-10-22: no This cycle / D1 / D2 row; a new look waits on one line, Use it or Keep current; samples sit above the chat box) */
186
+ ok('L1 with no design yet, there is no look line and no sample chip', await p.evaluate(() => !document.querySelector('#oMain .rdlook') && document.querySelector('#rdSmp').hidden));
174
187
  await p.setInputFiles('#rdFile', path.join(base, 'q3-deck.png'));
175
- await until(() => p.evaluate(() => /Follows q3-deck\.png/.test(document.querySelector('.rdz').textContent)));
176
- ok('L2 Add a sample adds the file, and the row says the design follows it', /Follows q3-deck\.png/.test(await p.textContent('.rdz')) && /Added "q3-deck.png"/.test(await lastA()), await lastA());
188
+ await until(() => p.evaluate(() => /q3-deck\.png/.test(document.querySelector('#rdSmp').textContent)));
189
+ ok('L2 the clip adds a sample, shown as a chip above the chat box', /Follows/.test(await p.textContent('#rdSmp')) && !await p.evaluate(() => document.querySelector('#rdSmp').hidden) && /Added "q3-deck.png"/.test(await lastA()), await lastA());
177
190
  await say('A dark title band, like the sample');
178
191
  ok('L3 a turn says PMOS is working', /PMOS is working on it/.test(await lastA()));
179
- await until(() => p.evaluate(() => /This is D1/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 30000);
180
- ok('L4 the job\'s answer shows, and D1 is shown', /Made a dark title band\. This is D1/.test(await lastA()) && await p.evaluate(() => document.querySelector('.rdv [aria-pressed="true"]').textContent) === 'D1' && /Design version D1, not saved/.test(await p.textContent('#rdSrc')), await lastA());
192
+ await until(() => p.evaluate(() => /shown in the report/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 30000);
193
+ ok('L4 the job\'s answer shows, and the new look waits on one line with Use it and Keep current', /Made a dark title band\. It is shown in the report/.test(await lastA()) && /New look ready/.test(await p.textContent('#oMain .rdlook')) && !!await p.$('#oMain [data-rr="lookuse"]') && !!await p.$('#oMain [data-rr="lookno"]'), await lastA());
181
194
  const fr = await p.evaluate(() => [...document.querySelectorAll('#oMain iframe')].map((f) => ({ sb: f.getAttribute('sandbox'), doc: f.getAttribute('srcdoc') || '' })));
182
- ok('L5 the version shows in frames with an empty sandbox, and its script and handlers were dropped', fr.length >= 1 && fr.every((f) => f.sb === '' && !/<script|onclick|steal/.test(f.doc)) && await p.evaluate(() => !window.hacked), JSON.stringify(fr.map((f) => f.sb)));
183
- ok('L6 the deck of D1 has its two slides', await counter() === '1 / 2');
195
+ ok('L5 the new look shows in frames with an empty sandbox, and its script and handlers were dropped', fr.length >= 1 && fr.every((f) => f.sb === '' && !/<script|onclick|steal/.test(f.doc)) && await p.evaluate(() => !window.hacked), JSON.stringify(fr.map((f) => f.sb)));
196
+ ok('L6 the deck of the new look has its two slides', await counter() === '1 / 2');
184
197
  await say('Add a slide for what needs your call');
185
- await until(() => p.evaluate(() => /This is D2/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 30000);
186
- ok('L7 a second turn builds D2 on D1', await counter() === '1 / 3' && await p.evaluate(() => [...document.querySelectorAll('.rdv button')].map((b) => b.textContent).join()) === 'This cycle,D1,D2', await lastA());
187
- await tap('#oMain [data-rr="ver|1"]');
188
- await until(() => p.evaluate(() => document.querySelector('.rdv [aria-pressed="true"]').textContent === 'D1'));
189
- ok('L8 picking D1 goes back to it, and says the next change builds on it', /Back to D1/.test(await lastA()) && posts.filter((x) => x === '/api/report-design/revert').length === 1, await lastA());
190
- await tap('#oMain [data-rr="keep"]');
191
- await until(() => p.evaluate(() => /Saved as the design/.test(document.querySelector('.rdz').textContent)));
192
- ok('L9 This is it saves D1 as the design and says the cycle is drawn to match', /Saved D1 as the design of this report/.test(await lastA()) && !await p.$('#oMain [data-rr="keep"]'), await lastA());
193
- await until(() => p.evaluate(() => !/PMOS is working/.test(document.querySelector('.rdz').textContent)), 30000);
194
- await tap('#oMain [data-rr="ver|cycle"]');
195
- await until(() => p.evaluate(() => /drawn to the saved design/.test(document.querySelector('#rdSrc').textContent)), 10000);
196
- ok('L10 this cycle, redrawn, shows in the saved design in sandboxed frames', /This cycle, drawn to the saved design D1/.test(await p.textContent('#rdSrc')) && await bigTitle() === 'frame' && await p.evaluate(() => [...document.querySelectorAll('#oMain iframe')].every((f) => f.getAttribute('sandbox') === '')), await p.textContent('#rdSrc'));
198
+ await until(() => p.evaluate(() => /Added a slide/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 30000);
199
+ ok('L7 a second turn builds on it, and the line names the latest request', await counter() === '1 / 3' && /Add a slide for what needs your call/.test(await p.textContent('#oMain .rdlook')), await lastA());
200
+ const nPosts = posts.length;
201
+ await tap('#oMain [data-rr="lookno"]');
202
+ await until(() => p.evaluate(() => !document.querySelector('#oMain .rdlook')));
203
+ ok('L8 Keep current, with no look saved yet, puts the line away, shows the words again and posts nothing', await counter() === '1 / 5' && posts.length === nPosts && /Kept the current look/.test(await lastA()), await lastA());
204
+
205
+ /* K: the Brief, in its own viewer tab */
206
+ await tap('#oMain [data-rr="brief"]');
207
+ await until(() => p.evaluate(() => !!document.querySelector('[data-vw="brief:partner-review"] .rbs')));
208
+ const BR = '[data-vw="brief:partner-review"]';
209
+ const bk = await p.evaluate((B) => ({ tab: window.__premiumViewer.vwState().on, heads: [...document.querySelectorAll(B + ' .rbs h4')].map((h) => h.firstChild.textContent), conf: (document.querySelector(B + ' .rbto') || {}).textContent || '', glance: document.querySelector(B + ' #rb-glance').textContent }), BR);
210
+ ok('K1 Brief opens in its own viewer tab, not beside the report', bk.tab === 'brief:partner-review', JSON.stringify(bk));
211
+ ok('K2 a report with no template says so: no schedule, and a question to confirm', /None: it has no template/.test(bk.glance) && /1 to confirm/.test(bk.conf) && /no template/.test(await p.textContent(BR + ' #rb-open')), JSON.stringify(bk));
212
+ ok('K3 Why it looks like this lists the sample and the earlier looks, each with Go back to it', /q3-deck\.png/.test(await p.textContent(BR + ' #rb-design')) && await p.evaluate((B) => document.querySelectorAll(B + ' [data-rb^="back|"]').length === 2, BR));
213
+ await p.click(BR + ' [data-rb="back|1"]');
214
+ await until(() => p.evaluate(() => !!document.querySelector('#oMain .rdlook')));
215
+ ok('K4 Go back to it shows that earlier look in the report with the Use it line', /A dark title band, like the sample/.test(await p.textContent('#oMain .rdlook')) && await counter() === '1 / 2' && posts.filter((x) => x === '/api/report-design/revert').length === 1, await p.textContent('#oMain .rdlook'));
216
+ await tap('#oMain [data-rr="lookuse"]');
217
+ await until(() => p.evaluate(() => /This look is now the design/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 15000);
218
+ ok('L9 Use it saves the look as the design and puts the line away', !await p.$('#oMain .rdlook') && posts.filter((x) => x === '/api/report-design/accept').length === 1, await lastA());
219
+ await until(() => bigTitle().then((t) => t === 'frame'), 30000);
220
+ ok('L10 this cycle, redrawn, shows in the saved design in sandboxed frames', await bigTitle() === 'frame' && await p.evaluate(() => [...document.querySelectorAll('#oMain iframe')].every((f) => f.getAttribute('sandbox') === '')));
197
221
  await shot('reader-look-1280');
198
222
  await p.setInputFiles('#rdFile', path.join(base, 'brand.png'));
199
- await until(() => p.evaluate(() => /brand\.png/.test(document.querySelector('.rdz').textContent)));
200
- ok('L11 each sample has its own remove button, named for the sample', await p.evaluate(() => [...document.querySelectorAll('.rdz [data-rr^="unsample|"]')].map((b) => b.getAttribute('aria-label')).join()) === 'Remove the sample q3-deck.png,Remove the sample brand.png');
201
- await tap('#oMain [aria-label="Remove the sample q3-deck.png"]');
202
- await until(() => p.evaluate(() => !/q3-deck\.png/.test(document.querySelector('.rdz').textContent)));
203
- ok('L12 removing a sample drops it from the row, keeps the other, and says the next version stops following it', /Follows brand\.png/.test(await p.textContent('.rdz')) && !/q3-deck/.test(await p.textContent('.rdz')) && /Removed "q3-deck.png"\. The next version and each new cycle no longer follow it/.test(await lastA()), await lastA());
223
+ await until(() => p.evaluate(() => /brand\.png/.test(document.querySelector('#rdSmp').textContent)));
224
+ ok('L11 each sample chip has its own remove button, named for the sample', await p.evaluate(() => [...document.querySelectorAll('#rdSmp [data-rr^="unsample|"]')].map((b) => b.getAttribute('aria-label')).join()) === 'Remove the sample q3-deck.png,Remove the sample brand.png');
225
+ await p.click('#rdSmp [aria-label="Remove the sample q3-deck.png"]');
226
+ await until(() => p.evaluate(() => !/q3-deck\.png/.test(document.querySelector('#rdSmp').textContent)));
227
+ ok('L12 removing a sample drops its chip, keeps the other, and says the next version stops following it', /brand\.png/.test(await p.textContent('#rdSmp')) && /Removed "q3-deck.png"\. The next version and each new cycle no longer follow it/.test(await lastA()), await lastA());
228
+ await tap(BR + ' [data-rb="fix|Why it looks like this"]');
229
+ const fixT = await p.evaluate(() => document.querySelector('#rdIn').value);
230
+ ok('K5 Correct puts the section in the chat box', fixT === 'Correct "Why it looks like this": ', fixT);
231
+ await p.fill('#rdIn', 'Correct "Why it looks like this": the title band is navy'); await p.press('#rdIn', 'Enter');
232
+ await until(() => p.evaluate(() => /no template yet/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 10000);
233
+ ok('K6 a correction of a report with no template says how to set one up, and posts nothing', /no template yet/.test(await lastA()) && posts[posts.length - 1] === '/api/report-design/unsample', await lastA());
204
234
  await p.click('#dClose'); await sleep(200);
205
235
 
206
- /* I: an issued cycle is frozen */
207
- await tap(rowSel('2026-10-05'));
236
+ /* I: an issued cycle is frozen; the cycle chip opens it */
237
+ await tap(ROW);
208
238
  await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#rdSlide')));
209
- ok('I1 an issued cycle has no design versions and no turn, and says it is frozen', !await p.$('#rdF') && !await p.$('.rdv') && /issued, so it is frozen/.test(await p.textContent('.rdz')) && /issued/.test(await p.textContent('#dEye')));
239
+ await toCycle(pOld);
240
+ await until(() => p.evaluate(() => /issued/.test(document.querySelector('#dEye').textContent) && !!document.querySelector('#rdSlide')));
241
+ ok('I1 the cycle chip reads the issued cycle: no turn, no Edit, no Issue, and it says it is frozen', !await p.$('#rdF') && !await p.$('#oMain .rdlook') && !await p.$('#oMain [data-rr="edit"]') && !await p.$('#oMain [data-rr="issue"]') && /issued, so it is frozen/.test(await p.textContent('#dBody .stream')) && /5 Oct/.test(await p.textContent('#dSub')));
210
242
  ok('I2 an issued cycle still reads as a deck', await counter() === '1 / 3');
211
243
  await p.click('#dClose'); await sleep(200);
212
244
 
213
245
  /* P: the writes */
214
- const allowed = new Set(['/api/report-design/describe', '/api/report-design/sample', '/api/report-design/turn', '/api/report-design/accept', '/api/report-design/revert', '/api/report-design/unsample']);
215
- ok('P1 before Issue, the only POSTs are the report-design describe, sample, unsample, turn, accept and revert routes', posts.length > 0 && posts.every((x) => allowed.has(x)), posts.join());
246
+ const allowed = new Set(['/api/report-design/describe', '/api/report-design/sample', '/api/report-design/turn', '/api/report-design/accept', '/api/report-design/revert', '/api/report-design/unsample', '/api/report-structure/turn']);
247
+ ok('P1 before Issue, the only POSTs are the report-design describe, sample, unsample, turn, accept and revert routes and the structure turn of a correction', posts.length > 0 && posts.every((x) => allowed.has(x)), posts.join());
216
248
  ok('P2 the first turn described the look first, and each later press posted once', posts.join() === ['sample', 'describe', 'turn', 'turn', 'revert', 'accept', 'sample', 'unsample'].map((x) => '/api/report-design/' + x).join(), posts.join());
217
249
  ok('P3 the document file is unchanged', fs.readFileSync(path.join(dir, pNew), 'utf8') === DOC);
218
250
 
219
251
  /* F: floors */
220
- await tap(rowSel('2026-10-12'));
252
+ await tap(ROW);
221
253
  await until(() => p.evaluate(() => !!document.querySelector('#rdSlide')));
222
254
  const small = await p.evaluate(() => [...document.querySelectorAll('#oMain button, #oMain a')].filter((b) => b.offsetParent && !b.closest('.rdt')).map((b) => { return { t: (b.textContent || b.getAttribute('aria-label') || '').trim().slice(0, 30), h: b.offsetHeight }; }).filter((x) => x.h < 44 && x.t !== 'Open in the console'));
223
255
  ok('F1 every control of the reader is at least 44 px tall', small.length === 0, JSON.stringify(small));
@@ -235,10 +267,18 @@ fs.writeFileSync(path.join(base, 'brand.png'), PNG);
235
267
  const small2 = await p.evaluate(() => [...document.querySelectorAll('[data-issue-bar] button')].filter((b) => b.offsetHeight < 44).length);
236
268
  ok('S3 the confirm buttons are at least 44 px tall', small2 === 0);
237
269
  await p.click('#oMain [data-rr="issueok"]');
238
- ok('S4 Issue it issues the cycle on the report route and the reader says it is frozen', await until(() => p.evaluate(() => /issued/.test(document.querySelector('#dEye').textContent) && !document.querySelector('#oMain [data-rr="issue"]') && /Issued/.test(document.querySelector('#oMain .dsm2').textContent)), 15000)
270
+ ok('S4 Issue it issues the cycle on the report route and the reader says it is frozen', await until(() => p.evaluate(() => /issued/.test(document.querySelector('#dEye').textContent) && !document.querySelector('#oMain [data-rr="issue"]') && /Issued/.test(document.querySelector('#oMain .rdst').textContent)), 15000)
239
271
  && posts.slice(before).join() === '/api/report/issue', posts.slice(before).join());
240
272
  await shot('reader-issued-1280');
241
273
  ok('S5 the issue is recorded in the issues ledger', issues.isIssued(issues.readIssues(dir), CAD, '2026-10-12'));
274
+ /* A: an issued cycle archives from ⋯, after one confirm, and comes back */
275
+ const b2 = posts.length;
276
+ await tap('#oMain [data-rr="mo"]'); await tap('#oMain [data-rr="archive"]');
277
+ ok('A1 Archive first asks, and posts nothing', await until(() => p.$('[data-ask-bar="archive"]')) && posts.length === b2);
278
+ await tap('#oMain [data-rr="askok"]');
279
+ ok('A2 Archive it posts the archive route and the chip says Archived', await until(() => p.evaluate(() => /Archived/.test(document.querySelector('#oMain .rdst').textContent)), 8000) && posts.slice(b2).join() === '/api/report-documents/archive', posts.slice(b2).join());
280
+ await tap('#oMain [data-rr="mo"]'); await tap('#oMain [data-rr="unarchive"]');
281
+ ok('A3 Bring back undoes it', await until(() => p.evaluate(() => !/Archived/.test(document.querySelector('#oMain .rdst').textContent)), 8000));
242
282
  ok('F3 no page error', errs.length === 0, errs.join(' | '));
243
283
  return finish();
244
284
  })().catch((e) => { console.error(e); finish(1); });
@@ -70,27 +70,27 @@ const disk = () => fs.readFileSync(path.join(dir, pNew), 'utf8');
70
70
  p.on('request', (r) => { if (r.method() === 'POST') posts.push(new URL(r.url()).pathname); });
71
71
  const shot = async (n) => { if (process.env.SLIDES_SHOTS) await p.screenshot({ path: path.join(process.env.SLIDES_SHOTS, n + '.png') }); };
72
72
  const tap = (sel) => p.$eval(sel, (b) => b.click());
73
- const V = '#dOut .obody.vw:not([hidden])';
73
+ const V = '#oMain #rdEd'; // Edit draws the slide editor inside the report dialog (PM 2026-10-22: one place to edit a report)
74
74
  const st = () => p.evaluate((pth) => { const S = window.__premiumSlides && window.__premiumSlides.state(pth); return S ? { i: S.i, n: S.deck.slides.length, theme: S.deck.theme, dirty: S.dirty, ro: S.ro, sel: S.sel, msg: S.msg, slides: JSON.parse(JSON.stringify(S.deck.slides)) } : null; }, pNew);
75
75
  const openReader = async (slot) => {
76
76
  await p.goto(BASE + '/premium-insights.html');
77
77
  await until(() => p.evaluate(() => !!document.querySelector('#listSeg [data-f="rep"]')));
78
78
  if (await p.locator('#listSeg').isHidden()) await tap('#listF'); await tap('#listSeg [data-f="rep"]'); // the one list (insights-one-list L5): the Reports filter holds the report files
79
- await until(() => p.evaluate(() => document.querySelectorAll('#listRows [data-rep]').length === 2));
80
- await tap(`#listRows [data-rep="rep:${CAD}:${slot}"]`);
79
+ await until(() => p.evaluate(() => document.querySelectorAll('#listRows [data-rpt]').length === 1)); // one row per report (PM 2026-10-22); it opens the latest cycle
80
+ await tap(`#listRows [data-rpt="${CAD}"]`);
81
+ await until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#rdSlide')));
82
+ if (slot !== '2026-10-12') { await tap('#dSub [data-rr="cycm"]'); await tap(`#dSub [data-rr="cyc|${RDraft.draftPath(dir, CAD, slot)}"]`); await until(() => p.evaluate(() => /issued/.test(document.querySelector('#dEye').textContent))); }
81
83
  return until(() => p.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#rdSlide')));
82
84
  };
83
85
  const openEditor = async () => {
84
- await tap('#oMain [data-rr="rm"]');
85
- await tap('#oMain [data-rr="slides"]');
86
- return until(() => p.evaluate(() => !!document.querySelector('#dOut .obody.vw:not([hidden]) .sl .sl-stage .sl-cv')));
86
+ await tap('#oMain [data-rr="edit"]');
87
+ return until(() => p.evaluate(() => !!document.querySelector('#oMain #rdEd .sl .sl-stage .sl-cv')));
87
88
  };
88
89
 
89
90
  /* O: opening */
90
91
  ok('O1 a draft report opens in the reader', await openReader('2026-10-12'));
91
- ok('O2 the Read menu offers Edit the slides', /Edit the slides/.test(await p.evaluate(() => { document.querySelector('#oMain [data-rr="rm"]').click(); return (document.querySelector('#oMain [data-rr="slides"]') || {}).textContent || ''; })));
92
- await tap('#oMain [data-rr="rm"]');
93
- ok('O3 Edit the slides opens the editor as a tab beside the report', await openEditor() && await p.evaluate((pth) => { const s = window.__premiumViewer.vwState(); return s.on === 'slides:' + pth && s.ids.length === 1 && document.querySelector('#oMain').hidden; }, pNew));
92
+ ok('O2 on Slides, the bar\'s Edit says it edits the slides, and there is no other Edit the slides', await p.evaluate(() => /slides/i.test(document.querySelector('#oMain [data-rr="edit"]').title) && !document.querySelector('#oMain [data-rr="slides"]')));
93
+ ok('O3 Edit opens the slide editor inside the report dialog: no viewer tab', await openEditor() && await p.evaluate(() => { const s = window.__premiumViewer.vwState(); return !s.ids.length && !document.querySelector('#oMain').hidden && !!document.querySelector('#rdEd [data-c="close"]'); }));
94
94
  let s = await st();
95
95
  ok('O4 the report reads as a title slide and one slide per section', s && s.n === 5 && s.slides[0].l === 'title' && s.slides.map((x) => x.els[0].html).join('|') === 'Partner review, 12 Oct|Headline|Initiatives|Partner note|Sources', s && s.slides.map((x) => x.els[0].html).join('|'));
96
96
  ok('O5 the view says the document has no slide layout yet', /no slide layout yet/.test(await p.textContent(V + ' .sl-msg')));
@@ -160,17 +160,17 @@ const disk = () => fs.readFileSync(path.join(dir, pNew), 'utf8');
160
160
 
161
161
  /* S: save, and read back from disk */
162
162
  posts.length = 0;
163
+ const wsNow = await p.evaluate((pth) => window.__premiumSlides.state(pth).ws, pNew);
163
164
  await tap(V + ' [data-c="save"]');
164
165
  await until(() => p.$(V + ' .sl-savef'));
165
166
  await p.fill(V + ' .sl-savef input[name="why"]', 'Slides for Thursday'); await tap(V + ' .sl-savef [type="submit"]');
166
- await until(() => p.evaluate((pth) => !window.__premiumSlides.state(pth).dirty, pNew));
167
+ await until(() => p.evaluate(() => !document.querySelector('#rdEd'))); // Save writes, then brings the report back
167
168
  const md = disk();
168
169
  ok('S1 Save writes once through the document sheet\'s edit route', JSON.stringify(posts) === '["/api/doc-sheet/edit"]', JSON.stringify(posts));
169
170
  ok('S2 the file is markdown with a slide block under each heading', (md.match(/^<!-- pmos:slide \{/gm) || []).length === 6 && /^# Partner review, 12 Oct\n<!-- pmos:slide/m.test(md) && /\ndeck_theme: sky\n/.test(md), md.slice(0, 300));
170
171
  ok('S3 the slide\'s text, its chart data and its image are written as markdown', md.includes('## Headline this week\n') && md.includes('| Sep | 30 |') && md.includes('![The setup screen](planning/design/screen.png)'));
171
172
  ok('S4 the speaker notes and the report note are in the file', md.includes('"notes":"Say the number first."') && md.includes('<!-- pmos:note partner-activation -->\nThe PM\'s words.\n<!-- /pmos:note -->'));
172
- ok('S5 the reason is kept in the document\'s revision log', await p.evaluate(async ([pth]) => { const S = window.__premiumSlides.state(pth); const r = await fetch('/api/doc-sheet/log?' + new URLSearchParams({ ...(S.ws ? { ws: S.ws } : {}), path: pth })).then((x) => x.json()); return JSON.stringify(r).includes('Slides for Thursday'); }, [pNew]));
173
- await tap('#vTabs .vtab[data-vw="main"]');
173
+ ok('S5 the reason is kept in the document\'s revision log', await p.evaluate(async ([pth, ws]) => { const r = await fetch('/api/doc-sheet/log?' + new URLSearchParams({ ...(ws ? { ws } : {}), path: pth })).then((x) => x.json()); return JSON.stringify(r).includes('Slides for Thursday'); }, [pNew, wsNow]));
174
174
  ok('S6 the report reader shows the saved words, without the slide blocks', await until(() => p.evaluate(() => { const t = document.querySelector('#oMain').textContent; return t.includes('Headline this week') && !t.includes('pmos:slide'); })));
175
175
  await openReader('2026-10-12'); await openEditor();
176
176
  s = await st();
@@ -228,9 +228,7 @@ const disk = () => fs.readFileSync(path.join(dir, pNew), 'utf8');
228
228
 
229
229
  /* I: an issued report */
230
230
  await openReader('2026-10-05');
231
- ok('I1 an issued report offers Open the slides', /Open the slides/.test(await p.evaluate(() => { document.querySelector('#oMain [data-rr="rm"]').click(); return (document.querySelector('#oMain [data-rr="slides"]') || {}).textContent || ''; })));
232
- await tap('#oMain [data-rr="rm"]'); await openEditor();
233
- ok('I2 its slides are read-only: no Save, no editing tools, and it says why', await p.evaluate((v) => !document.querySelector(v + ' [data-c="save"]') && !document.querySelector(v + ' [data-c="text"]') && !document.querySelector(v + ' .sl-cv.ed') && /issued, so its slides are read-only/.test(document.querySelector(v + ' .sl-msg').textContent), V));
231
+ ok('I1 an issued report has no Edit and no Issue: it reads as Slides or Page', await p.evaluate(() => !document.querySelector('#oMain [data-rr="edit"]') && !document.querySelector('#oMain [data-rr="issue"]') && !!document.querySelector('#oMain [data-rr="view|deck"]')));
234
232
  ok('I3 the issued file is not changed', fs.readFileSync(path.join(dir, pOld), 'utf8') === OLD);
235
233
  ok('X no page error', errs.length === 0, errs.join(' | '));
236
234
  await ctx.close();
@@ -242,11 +240,11 @@ const disk = () => fs.readFileSync(path.join(dir, pNew), 'utf8');
242
240
  await q.goto(BASE + '/premium-insights.html?theme=dark');
243
241
  await until(() => q.evaluate(() => !!document.querySelector('#listSeg [data-f="rep"]')));
244
242
  await q.$eval('#listSeg [data-f="rep"]', (x) => x.click());
245
- await until(() => q.evaluate(() => document.querySelectorAll('#listRows [data-rep]').length === 2));
246
- await q.$eval(`#listRows [data-rep="rep:${CAD}:2026-10-12"]`, (x) => x.click());
243
+ await until(() => q.evaluate(() => document.querySelectorAll('#listRows [data-rpt]').length === 1));
244
+ await q.$eval(`#listRows [data-rpt="${CAD}"]`, (x) => x.click());
247
245
  await until(() => q.evaluate(() => document.querySelector('#dlg').classList.contains('on') && !!document.querySelector('#rdSlide')));
248
- await q.$eval('#oMain [data-rr="rm"]', (x) => x.click()); await q.$eval('#oMain [data-rr="slides"]', (x) => x.click());
249
- await until(() => q.evaluate(() => !!document.querySelector('#dOut .obody.vw:not([hidden]) .sl .sl-stage .sl-cv')));
246
+ await q.$eval('#oMain [data-rr="edit"]', (x) => x.click());
247
+ await until(() => q.evaluate(() => !!document.querySelector('#oMain #rdEd .sl .sl-stage .sl-cv')));
250
248
  await sleep(300);
251
249
  const m = await q.evaluate((v) => {
252
250
  const r = (e) => e.getBoundingClientRect(), vis = (e) => e.offsetParent !== null && r(e).width > 0;
@@ -207,14 +207,30 @@ function setupRow(s) {
207
207
  const from = L ? (L.lead ? 'From the ' + L.date + ' file' : 'The ' + L.date + ' file has no sentence to quote') : 'No draft is written yet';
208
208
  return `<div class="dmr" role="listitem"><button class="dmo" data-setup="${esc(s.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(s.name)}</b>${line}<small>${esc([from, s.label, s.audience ? 'for ' + s.audience : ''].filter(Boolean).join(' · '))}</small><span class="dmm"><span class="t">Report</span><span class="s ${s.paused ? 'none' : 'issued'}">${s.paused ? 'Paused' : s.drafting ? 'Drafting' : 'Set up'}</span>${s.next && !s.paused ? `<span>Next draft ${esc(s.next)}</span>` : ''}</span></span></button></div>`;
209
209
  }
210
- function repRow(r) {
211
- return `<div class="dmr ${esc(r.state)}" role="listitem"><button class="dmo" data-rep="${esc(r.key)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(r.cadence)} · ${esc(r.date || r.slot)}</b>${r.lead ? insLine('“' + r.lead + '”', true) : ''}<small>${esc(r.path)}</small><span class="dmm"><span class="t">Report</span><span class="s ${esc(r.state === 'issued' ? 'issued' : 'draft')}">${esc(r.stateLabel)}</span><span>Deck, present, download, print</span></span></span></button></div>`;
210
+ /* One row per report (PM 2026-10-22: "Each report should have a list of issued/archived/draft report, so there's no duplication of the same report
211
+ * on the Insight page"): its name, the opening sentence of its latest cycle, and how many cycles are draft, issued and archived. The row opens the
212
+ * latest cycle in the reader, whose cycle chip lists the others. */
213
+ function repRow(g) {
214
+ const L = g.files[0], n = (f) => g.files.filter(f).length, d = n((x) => x.state !== 'issued'), i = n((x) => x.state === 'issued' && !x.archived), a = n((x) => x.archived), s = g.setup;
215
+ const pills = [d ? `<span class="s draft">${d} draft</span>` : '', i ? `<span class="s issued">${i} issued</span>` : '', a ? `<span class="s none">${a} archived</span>` : ''].join('');
216
+ const st = s ? (s.paused ? '<span>Paused</span>' : s.drafting ? '<span>Drafting</span>' : s.next ? `<span>Next draft ${esc(s.next)}</span>` : '') : '<span>No template</span>';
217
+ return `<div class="dmr" role="listitem"><button class="dmo" data-rpt="${esc(g.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(DOCI)}</span><span class="dmn"><b>${esc(g.name)}</b>${L.lead ? insLine('“' + L.lead + '”', true) : ''}<small>${esc('Latest: ' + (L.date || L.slot) + (s && s.label ? ' · ' + s.label : '') + (s && s.audience ? ' · for ' + s.audience : ''))}</small><span class="dmm"><span class="t">Report</span>${pills}${st}</span></span></button></div>`;
218
+ }
219
+ /** The report files grouped by report: a set-up report with files is one report row, one with none keeps its set-up row, and a cadence with
220
+ * files and no template is a report row of its own. Files keep their order (newest first, archived last). */
221
+ function reportGroups() {
222
+ const R = M.reports, by = new Map();
223
+ for (const f of R.missing ? [] : R.rows) { if (!by.has(f.cadence)) by.set(f.cadence, []); by.get(f.cadence).push(f); }
224
+ const out = [];
225
+ for (const s of R.setupsOk === false ? [] : (R.setups || [])) { const fs = by.get(s.id); by.delete(s.id); out.push(fs ? { kind: 'file', x: { id: s.id, name: s.name, setup: s, files: fs } } : { kind: 'setup', x: s }); }
226
+ for (const [id, fs] of by) out.push({ kind: 'file', x: { id, name: id, setup: null, files: fs } });
227
+ return out;
212
228
  }
213
229
  const foundRow = (f) => `<div class="dmr" role="listitem"><button class="dmo" data-found="${esc(f.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(AIC)}</span><span class="dmn"><b>${esc(f.name)}</b><small>${esc(f.why)}</small><span class="dmm">${f.confidence ? `<span>${esc(f.confidence)}</span>` : ''}<span>${f.evidence.length} ${f.evidence.length === 1 ? 'sign' : 'signs'} in your work</span></span></span></button></div>`;
214
230
  const askRow = (a) => `<div class="dmr" role="listitem"><button class="dmo" data-ask="${esc(a.id)}" aria-haspopup="dialog"><span class="dmi c-Board">${ICO(AIC)}</span><span class="dmn"><b>${esc(a.proposal && a.proposal.name ? a.proposal.name : a.text)}</b><small>You asked: ${esc(a.text)}</small><span class="dmm"><span class="s ${ASKST[a.state][1]}">${ASKST[a.state][0]}</span>${a.changed ? '<span>Changed once</span>' : ''}</span></span></button></div>`;
215
231
  function listItems() {
216
- const R = M.reports, d = M.dashboards.map((x) => ({ kind: 'dash', x }));
217
- const r = (R.setupsOk === false ? [] : (R.setups || []).map((x) => ({ kind: 'setup', x }))).concat(R.missing ? [] : R.rows.map((x) => ({ kind: 'file', x })));
232
+ const d = M.dashboards.map((x) => ({ kind: 'dash', x }));
233
+ const r = reportGroups();
218
234
  return { d, r, all: d.concat(r) };
219
235
  }
220
236
  function drawList() {
@@ -258,8 +274,8 @@ $('#repBody').addEventListener('click', (e) => {
258
274
  if (pin) { pin.disabled = true; pinDash(M.pinned === pin.dataset.pin ? null : pin.dataset.pin, 'list'); return; }
259
275
  const d = e.target.closest('[data-d]');
260
276
  if (d) { dash = d.dataset.d; drawDash(); drawList(); try { $('#cDash').scrollIntoView({ behavior: 'smooth', block: 'start' }); } catch { /* no scroll */ } return; }
261
- const rp = e.target.closest('[data-rep]');
262
- if (rp) { const row = M.reports.rows.find((x) => x.key === rp.dataset.rep), su = row && (M.reports.setups || []).find((x) => x.id === row.cadence); openReport(row, { ws: M.board.ws, name: su ? su.name : null, onIssue: () => load() }); return; }
277
+ const rp = e.target.closest('[data-rpt]');
278
+ if (rp) { const g = reportGroups().find((x) => x.kind === 'file' && x.x.id === rp.dataset.rpt); if (g) openReport(g.x.files[0], { ws: M.board.ws, name: g.x.setup ? g.x.setup.name : null, cycles: g.x.files, onIssue: () => load(), onChange: () => load() }); return; }
263
279
  const f = e.target.closest('[data-found]'), a = e.target.closest('[data-ask]'), s = e.target.closest('[data-setup]');
264
280
  if (f) openFound((M.reports.found || []).find((x) => x.id === f.dataset.found));
265
281
  else if (a) openAsk((M.reports.asks || []).find((x) => x.id === a.dataset.ask));
@@ -0,0 +1,132 @@
1
+ /* pm/premium-report-brief.js — the Brief of a report: how it is made, in its own viewer tab beside the report (initiative premium-reports-from-chat;
2
+ * PM 2026-10-22: "the Report Design Brief alongside the design, so I know what the report is, how it is structured, how the data is gathered, how
3
+ * it is calculated … not part of the report … so I can validate and make corrections", then "Report brief can be open on Viewer tab").
4
+ *
5
+ * openBrief(ctx) open (or show) the Brief tab of the open report
6
+ * refreshBrief(ctx) draw it again if it is open (after a correction)
7
+ * briefParts(x) the sections as [{ id, t, html }] and the open questions, from the stored records (pure; x = { structure, design, ctx })
8
+ * ctx = { ws, id, name, issued, setup, design, schedWords, format, correct(title), goBack(n) }
9
+ *
10
+ * READS: GET /api/report-structure (the structure plan, its sources, charts and outline, and their checks) and the design the reader holds
11
+ * (GET /api/report-design). Nothing new is stored: the Brief is what PMOS already keeps, said in words. Where a record is silent, the Brief says
12
+ * "not said" and lists it under Please confirm; it never fills a gap with a guess.
13
+ * WRITES: only on a press: Use it on a new structure version (POST /api/report-structure/accept). Correct puts `Correct "<section>": ` in the
14
+ * chat box; the reader sends it as a structure turn. Go back to it (an earlier look) is the reader's revert. */
15
+ import { esc, toast } from './premium-shell.js';
16
+ import { pmGet, pmPost } from './http.js';
17
+ import { vwOpen, vwState } from './premium-viewer.js';
18
+
19
+ const tabId = (ctx) => 'brief:' + ctx.id;
20
+ const day = (s) => { const d = new Date(String(s || '')); return isNaN(d) ? '' : d.toLocaleDateString('en-GB', { day: 'numeric', month: 'short' }); };
21
+ const NS = '<span class="tag as">not said</span>';
22
+ const say = (v) => v ? esc(v) : NS;
23
+ const STATE = { reached: ['reached', 'ok'], 'needs-you': ['needs you', 'no'], 'not-connected': ['not connected', 'no'], later: ['later', ''], off: ['off', ''] };
24
+ const KIND = { deck: 'Slide deck in PMOS', page: 'A page in PMOS', doc: 'A page in PMOS' };
25
+
26
+ /** The Brief's sections from the records. Each open question also counts toward "N to confirm". */
27
+ export function briefParts({ structure, design, ctx }) {
28
+ const S = structure || null, plan = S && S.plan, D = design || null, su = ctx.setup || null, open = [];
29
+ const sec = [];
30
+ const pu = (plan && plan.purpose) || {};
31
+ const ver = S && S.current != null ? 'S' + S.current + (S.saved === S.current ? '' : S.saved ? ' (S' + S.saved + ' is saved)' : ', not saved yet') : '';
32
+ if (!plan) open.push(su ? 'No structure is saved for this report yet. Say in the chat who reads it and what it answers.' : 'This report has no template, so PMOS keeps no structure or design for it. Say in a chat how often it is drafted, and PMOS sets one up.');
33
+ else {
34
+ if (!pu.readers) open.push('Who reads it?');
35
+ if (!pu.decision) open.push('What decision does it help make?');
36
+ if (!pu.scope) open.push('What is in it, and what is left out?');
37
+ if (!(pu.questions || []).length) open.push('Which questions should it answer?');
38
+ }
39
+ const made = !su ? 'By hand: a file with no template' : su.source === 'work' ? 'The schedule, from the saved structure' + (D && D.saved ? ' and design' : '') : su.source ? 'The schedule, from ' + su.source : 'The schedule';
40
+ sec.push({ id: 'glance', t: 'At a glance', html: `<dl class="rbkv"><dt>What it is</dt><dd>${say((su && su.purpose) || pu.decision)}</dd><dt>For</dt><dd>${say(pu.readers || (su && su.audience))}</dd><dt>Decision</dt><dd>${say(pu.decision)}</dd>`
41
+ + `<dt>Schedule</dt><dd>${su ? esc(ctx.schedWords) : 'None: it has no template'}</dd><dt>Format</dt><dd>${esc(KIND[ctx.format] || KIND.deck)}</dd><dt>Made by</dt><dd>${esc(made)}</dd>${ver ? `<dt>Structure</dt><dd>${esc(ver)}</dd>` : ''}</dl>` });
42
+ if (!plan) return { sections: sec.concat(lookSections(D, ctx, open)).concat(openSection(open)), open };
43
+ sec.push({ id: 'questions', t: 'Questions it answers', html: (pu.questions || []).length ? '<ol>' + pu.questions.map((x) => `<li>${esc(x)}</li>`).join('') + '</ol>' : `<p>${NS}</p>` });
44
+ sec.push({ id: 'scope', t: 'In and out of scope', html: `<p>${say(pu.scope)}</p>${pu.cadence ? `<p><b>Covers:</b> ${esc(pu.cadence)}</p>` : ''}` });
45
+ const chartName = (id) => { const c = (plan.charts || []).find((x) => x.id === id); return c ? c.name : id; };
46
+ sec.push({ id: 'structure', t: 'How it is structured', html: '<ol>' + (plan.outline || []).map((o) => `<li><b>${esc(o.title)}</b>${o.notes ? ': ' + esc(o.notes) : ''}${(o.charts || []).length ? ' <span class="rbsub">Shows ' + esc(o.charts.map(chartName).join(', ')) + '.</span>' : ''}${o.fixed ? ' <span class="rbsub">In every report.</span>' : ''}</li>`).join('') + '</ol>' });
47
+ sec.push({ id: 'data', t: 'Where the data comes from', html: (plan.sources || []).length ? '<ul>' + plan.sources.map((s) => {
48
+ const st = STATE[s.state] || [s.state || '', ''];
49
+ if (!s.use) open.push('What is ' + s.name + ' used for?');
50
+ if (s.state === 'needs-you') open.push(s.name + ' could not be reached. Check its sign-in, or say what to use instead.');
51
+ if (s.state === 'not-connected') open.push(s.name + ' is not connected. Connect it, or say what to use instead.');
52
+ return `<li><b>${esc(s.name)}</b>${s.via ? ', through ' + esc(s.via) : ''}${s.ref ? ', <code>' + esc(s.ref) + '</code>' : ''}. ${s.use ? esc(s.use) : 'Use ' + NS}${st[0] ? ` <span class="tag ${st[1]}">${esc(st[0])}</span>` : ''}</li>`;
53
+ }).join('') + '</ul>' : `<p>No source is named. ${NS}</p>` });
54
+ const srcName = (id) => ((plan.sources || []).find((x) => x.id === id) || { name: id }).name;
55
+ sec.push({ id: 'calc', t: 'How each number is worked out', html: (plan.charts || []).length ? plan.charts.map((c) => {
56
+ if (!c.how) open.push('How is "' + c.name + '" worked out?');
57
+ return `<div class="rbcalc"><b>${esc(c.name)}</b>${c.question ? `<p>Answers: ${esc(c.question)}</p>` : ''}<p><b>From</b> ${esc(srcName(c.source))}${c.from ? ': ' + esc(c.from) : ''}</p><p><b>Worked out</b> ${say(c.how)}</p>${c.compare ? `<p><b>Compared with</b> ${esc(c.compare)}</p>` : ''}${c.flag ? `<p><b>Flagged when</b> ${esc(c.flag)}</p>` : ''}</div>`;
58
+ }).join('') : `<p>No number is worked out: the report is words only.</p>` });
59
+ const checks = Object.entries(S.checks || {}).map(([sid, c]) => `<li>${esc(srcName(sid))}: ${c.ok ? 'checked, it works <span class="tag ok">passed</span>' : esc(c.why || c.error || c.note || 'the last check did not pass') + ' <span class="tag no">needs you</span>'}${c.at ? ' (' + esc(day(c.at)) + ')' : ''}</li>`);
60
+ const errs = (S.errors || []).slice(-2).map((e) => `<li>The last structure run failed: ${esc(e.text)}</li>`);
61
+ sec.push({ id: 'checks', t: 'Checks and caveats', html: checks.length || errs.length ? '<ul>' + checks.concat(errs).join('') + '</ul>' : '<p>No source check has run. A source that PMOS reads itself needs none.</p>' });
62
+ if (S.current != null && S.saved !== S.current) open.push('The brief has a new version (S' + S.current + ') that is not saved. Press Use it at the top to keep it.');
63
+ return { sections: sec.concat(lookSections(D, ctx, open), historySection(S, D), openSection(open)), open };
64
+ }
65
+ function lookSections(D, ctx, open) {
66
+ if (!D) return ctx.issued ? [{ id: 'design', t: 'Why it looks like this', html: '<p>This cycle is issued, so its look is frozen as it was.</p>' }] : [];
67
+ const r = D.rules || { same: [], changes: [], learned: [] }, saved = D.saved ? D.saved.version : null;
68
+ if (!D.description && !(D.samples || []).length && !saved) open.push('How should it look? Say it in the chat, or attach a sample.');
69
+ const L = (h, xs) => (xs || []).length ? `<li><b>${h}</b> ${xs.map(esc).join('; ')}.</li>` : '';
70
+ const smp = (D.samples || []).map((s) => `<li>Follows <i>${esc(s.name)}</i>${s.took ? ': ' + esc(typeof s.took === 'string' ? s.took : s.took.took || '') : ''}.</li>`).join('');
71
+ const earlier = (D.versions || []).filter((v) => v.n !== saved).slice().reverse().slice(0, 5)
72
+ .map((v) => `<li>${esc(day(v.made_at))}: ${esc(v.turn || 'a version without a request')}${ctx.issued ? '' : ` <button type="button" class="rbfix" data-rb="back|${v.n}">Go back to it</button>`}</li>`).join('');
73
+ return [{ id: 'design', t: 'Why it looks like this', html: `<ul>${D.description ? `<li>${esc(D.description)}</li>` : ''}${smp}${L('Stays the same each cycle:', r.same)}${L('Changes each cycle:', r.changes)}${L('Learned from you:', r.learned)}</ul>`
74
+ + (saved ? '' : '<p>No look is saved yet: each cycle uses the standard PMOS look.</p>') + (earlier ? `<p><b>Earlier looks</b></p><ul>${earlier}</ul>` : '') }];
75
+ }
76
+ function historySection(S, D) {
77
+ const E = [];
78
+ for (const v of (S && S.versions) || []) E.push({ at: v.at, t: 'Structure: ' + (v.turn || 'S' + v.n) });
79
+ for (const v of (D && D.versions) || []) E.push({ at: v.made_at, t: 'Look: ' + (v.turn || 'D' + v.n) });
80
+ E.sort((a, b) => String(b.at).localeCompare(String(a.at)));
81
+ return { id: 'history', t: 'What changed', html: E.length ? '<ul>' + E.slice(0, 8).map((e) => `<li>${esc(day(e.at))}: ${esc(e.t)}</li>`).join('') + '</ul>' : '<p>Nothing has changed since it was set up.</p>' };
82
+ }
83
+ const openSection = (open) => ({ id: 'open', t: 'Please confirm', html: open.length ? '<ol>' + open.map((x) => `<li>${esc(x)}</li>`).join('') + '</ol>' : '<p>Nothing open.</p>' });
84
+
85
+ const B = new Map(); // tab id → { ctx, structure, err }
86
+ function html(id) {
87
+ const b = B.get(id), ctx = b.ctx;
88
+ if (b.loading) return '<div class="rbrief"><p class="note">Reading how this report is made.</p></div>';
89
+ const { sections, open } = briefParts({ structure: b.structure, design: ctx.design, ctx });
90
+ const S = b.structure, use = S && S.plan && S.current != null && S.saved !== S.current && !ctx.issued;
91
+ return `<div class="rbrief"><div class="rbhd"><span><b>How this report is made</b><small>Not part of the report${b.err ? ' · ' + esc(b.err) : ''}</small></span>${open.length ? `<span class="rbto">${open.length} to confirm</span>` : ''}${use ? `<button type="button" class="dmcta dark" data-rb="use|${S.current}">Use it</button>` : ''}</div>`
92
+ + `<nav class="rbtoc" aria-label="Brief sections">${sections.map((x) => `<button type="button" data-rb="go|${x.id}">${esc(x.t)}</button>`).join('')}</nav>`
93
+ + sections.map((x) => `<section class="rbs" id="rb-${x.id}"><h4>${esc(x.t)}${x.id === 'glance' || x.id === 'history' ? '' : `<button type="button" class="rbfix" data-rb="fix|${esc(x.t)}" aria-label="Correct ${esc(x.t)}">Correct</button>`}</h4>${x.html}</section>`).join('') + '</div>';
94
+ }
95
+ async function load(id) {
96
+ const b = B.get(id), ctx = b.ctx;
97
+ const j = await Promise.resolve(pmGet('/api/report-structure?ws=' + encodeURIComponent(ctx.ws) + '&id=' + encodeURIComponent(ctx.id))).catch(() => null);
98
+ b.structure = j && j.ok ? j.structure : null;
99
+ b.err = j && !j.ok && j.status !== 404 && j.error ? 'the structure could not be read: ' + j.error : '';
100
+ b.loading = false;
101
+ }
102
+ function show(id) {
103
+ vwOpen({ id, title: 'Brief', icon: 'doc', html: html(id), wire: (el) => { el.onclick = (e) => press(id, e); } });
104
+ }
105
+ async function press(id, e) {
106
+ const t = e.target.closest('[data-rb]'); if (!t || t.disabled) return;
107
+ const [k, v] = t.dataset.rb.split('|'), b = B.get(id);
108
+ if (k === 'go') { const s = document.getElementById('rb-' + v); if (s) s.scrollIntoView({ behavior: 'smooth', block: 'start' }); return; }
109
+ if (k === 'fix') { b.ctx.correct(v); return; }
110
+ if (k === 'back') { t.disabled = true; await b.ctx.goBack(+v); return; }
111
+ if (k === 'use') {
112
+ t.disabled = true;
113
+ const r = await pmPost('/api/report-structure/accept', { ws: b.ctx.ws, id: b.ctx.id, n: +v }).catch(() => null);
114
+ if (!r || r.ok !== true) { t.disabled = false; toast((r && r.error) || 'The brief was not saved.'); return; }
115
+ toast('Saved. The next cycle is drafted from this brief.');
116
+ b.structure = r.structure || b.structure; show(id);
117
+ }
118
+ }
119
+ export async function openBrief(ctx) {
120
+ const id = tabId(ctx);
121
+ B.set(id, { ctx, structure: null, err: '', loading: true });
122
+ show(id);
123
+ await load(id);
124
+ if (B.get(id) && B.get(id).ctx === ctx) show(id);
125
+ }
126
+ export async function refreshBrief(ctx) {
127
+ const id = tabId(ctx);
128
+ if (!vwState().ids.includes(id)) return;
129
+ B.set(id, { ...(B.get(id) || {}), ctx, loading: false });
130
+ await load(id);
131
+ show(id);
132
+ }