create-pmos 0.389.0 → 0.391.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 (30) hide show
  1. package/package.json +30 -35
  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 +6 -6
  8. package/workspace/changelog.json +29 -0
  9. package/workspace/guide/briefing-premium.md +19 -10
  10. package/workspace/guide/phone-companion.md +10 -1
  11. package/workspace/lib/insights-premium.js +10 -8
  12. package/workspace/lib/routes-insights-premium.js +3 -1
  13. package/workspace/package-lock.json +2 -2
  14. package/workspace/package.json +1 -1
  15. package/workspace/premium-report-read-test.js +101 -59
  16. package/workspace/premium-vw-slides-test.js +17 -19
  17. package/workspace/public/pm/audio-capture.js +7 -5
  18. package/workspace/public/pm/notes-capture-worklet.js +3 -2
  19. package/workspace/public/pm/notes-lock.js +66 -0
  20. package/workspace/public/pm/premium-insights.js +25 -6
  21. package/workspace/public/pm/premium-meeting.js +2 -1
  22. package/workspace/public/pm/premium-report-brief.js +132 -0
  23. package/workspace/public/pm/premium-report-read.js +276 -103
  24. package/workspace/public/pm/premium-report-tab.js +3 -1
  25. package/workspace/public/pm/premium-vw-doc.js +9 -1
  26. package/workspace/public/pm/premium-vw-report.css +1 -1
  27. package/workspace/public/pm/premium-vw-slides.js +14 -5
  28. package/workspace/public/pm/premium.css +70 -2
  29. package/workspace/public/pm/view-notes.js +92 -5
  30. package/workspace/test-lists/meeting-notes.json +8 -4
@@ -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,26 @@ 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
+ await p.evaluate(() => document.fonts.ready); await until(() => p.evaluate(() => !!document.querySelector('#oMain .rdbar [data-rr="sched"]'))); // the schedule chip lands after the template read; measure the finished row
114
+ const bar = await p.evaluate(() => { const L = [...document.querySelectorAll('#oMain .rdbar > *')].filter((x) => x.offsetWidth && x.offsetHeight), c = L.map((x) => { const r = x.getBoundingClientRect(); return r.top + r.height / 2; }); return { spread: Math.round(Math.max(...c) - Math.min(...c)), words: [...document.querySelectorAll('#oMain .rdbar .rdib')].filter((b) => b.textContent.trim() || !b.getAttribute('aria-label') || !b.title).length }; }); // one row: every item's centre within a few px (the empty spacer is left out)
115
+ await shot('reader-bar-1280');
116
+ ok('O3 the bar is one row of icon buttons, each named by its label and tooltip', bar.spread <= 6 && bar.words === 0, JSON.stringify(bar));
117
+ 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"]')));
118
+ /* C: the cycle chip under the name lists this report's cycles, grouped */
119
+ await p.click('#dSub [data-rr="cycm"]');
120
+ 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 }));
121
+ 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));
122
+ await p.click('#dSub [data-rr="cycm"]');
111
123
 
112
124
  /* D: the deck */
113
125
  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 +134,18 @@ fs.writeFileSync(path.join(base, 'brand.png'), PNG);
122
134
  await shot('reader-deck-1280');
123
135
 
124
136
  /* G: the page */
125
- await tap('#oMain [data-rr="fm"]'); await tap('#oMain [data-rr="view|doc"]');
137
+ await tap('#oMain [data-rr="view|doc"]');
126
138
  const heads = await p.evaluate(() => [...document.querySelectorAll('.rdpg h3')].map((h) => h.textContent));
127
139
  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"]');
140
+ await tap('#oMain [data-rr="view|deck"]');
129
141
 
130
142
  /* N: Present */
131
143
  await tap('#oMain [data-rr="go|0"]');
132
- await tap('#oMain [data-rr="rm"]'); await tap('#oMain [data-rr="present"]');
144
+ 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()));
145
+ await tap('#oMain [data-rr="sched"]');
146
+ 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"]'));
147
+ await tap('#oMain [data-rr="sched"]');
148
+ await tap('#oMain [data-rr="present"]');
133
149
  await until(() => p.$('#rdPres'));
134
150
  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
151
  await p.keyboard.press('ArrowRight');
@@ -138,86 +154,103 @@ fs.writeFileSync(path.join(base, 'brand.png'), PNG);
138
154
  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
155
 
140
156
  /* W: download */
141
- await tap('#oMain [data-rr="dm"]');
157
+ await tap('#oMain [data-rr="mo"]');
142
158
  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(' / '));
159
+ ok('W0 More names the file first', await p.evaluate((f) => document.querySelector('.rdmo .rdfile').textContent === f, pNew.split('/').pop()));
160
+ 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
161
  const [dl] = await Promise.all([p.waitForEvent('download'), p.click('.rpm [data-rr="dl|pptx"]')]);
145
162
  const pptx = fs.readFileSync(await dl.path());
146
163
  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"]');
164
+ await tap('#oMain [data-rr="mo"]');
148
165
  const [md] = await Promise.all([p.waitForEvent('download'), p.click('.rpm [data-rr="md"]')]);
149
166
  ok('W3 Markdown downloads the file as written', fs.readFileSync(await md.path(), 'utf8') === DOC && /\.md$/.test(md.suggestedFilename()), md.suggestedFilename());
150
167
 
151
168
  /* X: print */
152
169
  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);
170
+ await tap('#oMain [data-rr="mo"]'); await tap('#oMain [data-rr="print"]'); await sleep(450);
154
171
  const pr = await p.evaluate(() => ({ h: window.__pr || '', printed: !!window.__printed }));
155
172
  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
173
 
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);
174
+ /* 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 */
175
+ await tap('#oMain [data-rr="view|doc"]');
176
+ await tap('#oMain [data-rr="edit"]');
177
+ const VP = '#rdEd .vwdoc';
178
+ await until(() => p.evaluate((v) => !!document.querySelector(v + ' .cf.editing'), VP));
179
+ 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));
180
+ 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'));
181
+ await p.click(VP + ' [data-vd="cancel"]');
182
+ await until(() => p.evaluate(() => !document.querySelector('#rdEd') && !!document.querySelector('#oMain [data-rr="edit"]')));
183
+ ok('E3 Cancel brings the report back', await p.evaluate(() => !!document.querySelector('#oMain .rdpg') && !document.querySelector('#rdEd')));
184
+ await tap('#oMain [data-rr="view|deck"]');
171
185
 
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')));
186
+ /* 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) */
187
+ 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
188
  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());
189
+ await until(() => p.evaluate(() => /q3-deck\.png/.test(document.querySelector('#rdSmp').textContent)));
190
+ 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
191
  await say('A dark title band, like the sample');
178
192
  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());
193
+ await until(() => p.evaluate(() => /shown in the report/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 30000);
194
+ 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
195
  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');
196
+ 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)));
197
+ ok('L6 the deck of the new look has its two slides', await counter() === '1 / 2');
184
198
  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'));
199
+ await until(() => p.evaluate(() => /Added a slide/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 30000);
200
+ 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());
201
+ const nPosts = posts.length;
202
+ await tap('#oMain [data-rr="lookno"]');
203
+ await until(() => p.evaluate(() => !document.querySelector('#oMain .rdlook')));
204
+ 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());
205
+
206
+ /* K: the Brief, in its own viewer tab */
207
+ await tap('#oMain [data-rr="brief"]');
208
+ await until(() => p.evaluate(() => !!document.querySelector('[data-vw="brief:partner-review"] .rbs')));
209
+ const BR = '[data-vw="brief:partner-review"]';
210
+ 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);
211
+ ok('K1 Brief opens in its own viewer tab, not beside the report', bk.tab === 'brief:partner-review', JSON.stringify(bk));
212
+ 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));
213
+ 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));
214
+ await p.click(BR + ' [data-rb="back|1"]');
215
+ await until(() => p.evaluate(() => !!document.querySelector('#oMain .rdlook')));
216
+ 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'));
217
+ await tap('#oMain [data-rr="lookuse"]');
218
+ await until(() => p.evaluate(() => /This look is now the design/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 15000);
219
+ 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());
220
+ await until(() => bigTitle().then((t) => t === 'frame'), 30000);
221
+ 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
222
  await shot('reader-look-1280');
198
223
  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());
224
+ await until(() => p.evaluate(() => /brand\.png/.test(document.querySelector('#rdSmp').textContent)));
225
+ 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');
226
+ await p.click('#rdSmp [aria-label="Remove the sample q3-deck.png"]');
227
+ await until(() => p.evaluate(() => !/q3-deck\.png/.test(document.querySelector('#rdSmp').textContent)));
228
+ 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());
229
+ await tap(BR + ' [data-rb="fix|Why it looks like this"]');
230
+ const fixT = await p.evaluate(() => document.querySelector('#rdIn').value);
231
+ ok('K5 Correct puts the section in the chat box', fixT === 'Correct "Why it looks like this": ', fixT);
232
+ await p.fill('#rdIn', 'Correct "Why it looks like this": the title band is navy'); await p.press('#rdIn', 'Enter');
233
+ await until(() => p.evaluate(() => /no template yet/.test([...document.querySelectorAll('#dBody .stream .turn.a .tt')].pop().textContent)), 10000);
234
+ 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
235
  await p.click('#dClose'); await sleep(200);
205
236
 
206
- /* I: an issued cycle is frozen */
207
- await tap(rowSel('2026-10-05'));
237
+ /* I: an issued cycle is frozen; the cycle chip opens it */
238
+ await tap(ROW);
208
239
  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')));
240
+ await toCycle(pOld);
241
+ await until(() => p.evaluate(() => /issued/.test(document.querySelector('#dEye').textContent) && !!document.querySelector('#rdSlide')));
242
+ 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
243
  ok('I2 an issued cycle still reads as a deck', await counter() === '1 / 3');
211
244
  await p.click('#dClose'); await sleep(200);
212
245
 
213
246
  /* 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());
247
+ 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']);
248
+ 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
249
  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
250
  ok('P3 the document file is unchanged', fs.readFileSync(path.join(dir, pNew), 'utf8') === DOC);
218
251
 
219
252
  /* F: floors */
220
- await tap(rowSel('2026-10-12'));
253
+ await tap(ROW);
221
254
  await until(() => p.evaluate(() => !!document.querySelector('#rdSlide')));
222
255
  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
256
  ok('F1 every control of the reader is at least 44 px tall', small.length === 0, JSON.stringify(small));
@@ -235,10 +268,19 @@ fs.writeFileSync(path.join(base, 'brand.png'), PNG);
235
268
  const small2 = await p.evaluate(() => [...document.querySelectorAll('[data-issue-bar] button')].filter((b) => b.offsetHeight < 44).length);
236
269
  ok('S3 the confirm buttons are at least 44 px tall', small2 === 0);
237
270
  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)
271
+ 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
272
  && posts.slice(before).join() === '/api/report/issue', posts.slice(before).join());
240
273
  await shot('reader-issued-1280');
241
274
  ok('S5 the issue is recorded in the issues ledger', issues.isIssued(issues.readIssues(dir), CAD, '2026-10-12'));
275
+ /* A: an issued cycle archives from ⋯, after one confirm, and comes back */
276
+ const b2 = posts.length;
277
+ await tap('#oMain [data-rr="mo"]'); await tap('#oMain [data-rr="archive"]');
278
+ ok('A1 Archive first asks, and posts nothing', await until(() => p.$('[data-ask-bar="archive"]')) && posts.length === b2);
279
+ await tap('#oMain [data-rr="askok"]');
280
+ 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());
281
+ ok('A2b Insights hides the archived cycle: the row counts 1 issued and says nothing of archived (PM 2026-10-22)', await until(() => p.evaluate((r) => { const t = document.querySelector(r).textContent; return /1 issued/.test(t) && !/archived/i.test(t); }, ROW), 8000), await p.textContent(ROW));
282
+ await tap('#oMain [data-rr="mo"]'); await tap('#oMain [data-rr="unarchive"]');
283
+ ok('A3 Bring back undoes it', await until(() => p.evaluate(() => !/Archived/.test(document.querySelector('#oMain .rdst').textContent)), 8000));
242
284
  ok('F3 no page error', errs.length === 0, errs.join(' | '));
243
285
  return finish();
244
286
  })().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;
@@ -2,7 +2,8 @@
2
2
  *
3
3
  * makeResampler(inRate) a stateful low-pass resampler: push(float32 block) → Int16Array at 16 kHz, flush() → the tail
4
4
  * toInt16(input, inRate) one block, whole: the same filter, run once. Pure.
5
- * openCapture(ac, src, sink, onBlock) → { mode, node } an AudioWorklet that hands float32 blocks to onBlock;
5
+ * openCapture(ac, src, sink, onBlock) → { mode, node } an AudioWorklet that hands float32 blocks to onBlock(block, stamp), stamp
6
+ * being the audio clock at the block's end in seconds;
6
7
  * a ScriptProcessor does the same where the browser has no worklet
7
8
  *
8
9
  * WHY A FILTER. A context that cannot run at 16 kHz gives 44.1 or 48 kHz blocks. Averaging the samples under each output sample
@@ -83,20 +84,21 @@ export function toInt16(input, inRate) {
83
84
  return out;
84
85
  }
85
86
 
86
- /** Take blocks of the first channel from `src` and give each to onBlock as a Float32Array. `sink` is a muted node that keeps the
87
- * graph pulling. Returns { mode: 'worklet' | 'script', node }. */
87
+ /** Take blocks of the first channel from `src` and give each to onBlock as a Float32Array, with the audio clock at its end in seconds.
88
+ * `sink` is a muted node that keeps the graph pulling. Returns { mode: 'worklet' | 'script', node }; a source opened again later
89
+ * (a microphone after the phone was locked) is connected to the same node. */
88
90
  export async function openCapture(ac, src, sink, onBlock) {
89
91
  if (ac.audioWorklet && typeof AudioWorkletNode === 'function') {
90
92
  try {
91
93
  await ac.audioWorklet.addModule(new URL('./notes-capture-worklet.js', import.meta.url).href);
92
94
  const node = new AudioWorkletNode(ac, 'notes-capture', { numberOfInputs: 1, numberOfOutputs: 1, channelCount: 1, channelCountMode: 'explicit' });
93
- node.port.onmessage = (e) => onBlock(e.data);
95
+ node.port.onmessage = (e) => { const d = e.data; if (d && d.b) onBlock(d.b, d.t); else onBlock(d); };
94
96
  src.connect(node); node.connect(sink);
95
97
  return { mode: 'worklet', node };
96
98
  } catch { /* the module did not load: the older route below */ }
97
99
  }
98
100
  const node = ac.createScriptProcessor(4096, 1, 1);
99
- node.onaudioprocess = (e) => onBlock(new Float32Array(e.inputBuffer.getChannelData(0)));
101
+ node.onaudioprocess = (e) => onBlock(new Float32Array(e.inputBuffer.getChannelData(0)), e.playbackTime + e.inputBuffer.duration);
100
102
  src.connect(node); node.connect(sink);
101
103
  return { mode: 'script', node };
102
104
  }
@@ -1,5 +1,6 @@
1
1
  /* notes-capture-worklet.js — runs on the audio thread (notes-audio-quality R4). It copies the first channel of what it hears into
2
- * blocks of 2048 samples and posts each block to the page, which resamples and sends it. It makes no sound. */
2
+ * blocks of 2048 samples and posts each block to the page, which resamples and sends it. It makes no sound. Each block goes with the
3
+ * audio clock at its end (`t`, seconds), so the page can tell a stretch with no sound from a page that was only late (notes-lock.js). */
3
4
  class NotesCapture extends AudioWorkletProcessor {
4
5
  constructor() { super(); this.block = new Float32Array(2048); this.at = 0; }
5
6
  process(inputs) {
@@ -7,7 +8,7 @@ class NotesCapture extends AudioWorkletProcessor {
7
8
  if (!ch) return true;
8
9
  for (let i = 0; i < ch.length; i++) {
9
10
  this.block[this.at++] = ch[i];
10
- if (this.at === this.block.length) { this.port.postMessage(this.block, [this.block.buffer]); this.block = new Float32Array(2048); this.at = 0; }
11
+ if (this.at === this.block.length) { this.port.postMessage({ b: this.block, t: currentTime + (i + 1) / sampleRate }, [this.block.buffer]); this.block = new Float32Array(2048); this.at = 0; }
11
12
  }
12
13
  return true;
13
14
  }
@@ -0,0 +1,66 @@
1
+ /* notes-lock.js — a recording when the phone locks or the page goes to the background (notes-lock-recovery).
2
+ *
3
+ * makeGapClock({ gapMs }) one per source: block(n, rate, { nowMs, ctxSec, stamp }) → the ms of sound that never arrived
4
+ * before this block, or 0. Pure, for the suite.
5
+ * makeWakeLock(nav, doc) hold() asks the browser to keep the screen on; again() asks once more after the page is shown
6
+ * (the browser lets the lock go whenever the page is hidden); release() lets the screen sleep.
7
+ *
8
+ * WHAT A PHONE DOES. A web page cannot record while the phone is locked. iOS freezes the page and interrupts its AudioContext;
9
+ * Android may end the microphone track or let the page fall behind. When the PM unlocks the phone the page runs again, but
10
+ * the context stays interrupted until it is resumed and an ended track stays ended until it is opened again. Before this
11
+ * module the page did neither, so the recording stopped for good at the first lock, and audio that did come after it was
12
+ * written straight after the audio before it: every later line and the replay were early by the time the phone was locked.
13
+ *
14
+ * WHAT THE PAGE NOW DOES (view-notes.js startAudio). While it records it holds a screen wake lock, so the phone does not lock
15
+ * by itself. The press of the power button still locks it. When the page is shown again it resumes the context and opens an
16
+ * ended microphone again; when the browser wants a tap first, the next tap anywhere does it. The time that was missed is
17
+ * counted here, and the chunk offset jumps over it: the replay keeps silence there, the line times stay on the meeting
18
+ * clock, and the PM is told how long the gap was.
19
+ *
20
+ * WHICH TIME IS MISSING. Two cases, and they never overlap:
21
+ * the audio clock ran but no sound came (an input that ended, a context that kept time while it was interrupted): the
22
+ * block's own audio-thread time (`stamp`, the end of the block) is later than the end of the block before it plus this
23
+ * block's length;
24
+ * the audio clock stopped (an interrupted context that keeps no time): the wall clock moved further than the context's
25
+ * clock (`ctxSec`, read on the page when the block arrives) between two blocks.
26
+ * A page that was only late (a busy main thread that the audio thread did not wait for) gets a backlog of blocks with
27
+ * steady stamps, and both clocks move together, so it is not a gap. Under gapMs nothing is counted: that is jitter.
28
+ */
29
+ export const GAP_MS = 2000;
30
+
31
+ export function makeGapClock({ gapMs = GAP_MS } = {}) {
32
+ let prev = null; // { now, ctx, stamp } of the block before, in ms
33
+ return {
34
+ block(n, rate, { nowMs, ctxSec, stamp } = {}) {
35
+ const len = (n / rate) * 1000;
36
+ const cur = { now: nowMs, ctx: Number.isFinite(ctxSec) ? ctxSec * 1000 : null, stamp: Number.isFinite(stamp) ? stamp * 1000 : null };
37
+ const p = prev; prev = cur;
38
+ if (!p) return 0;
39
+ const silent = cur.stamp !== null && p.stamp !== null ? cur.stamp - p.stamp - len : 0;
40
+ const stalled = cur.ctx !== null && p.ctx !== null ? (cur.now - p.now) - (cur.ctx - p.ctx) : 0;
41
+ const gap = (silent > gapMs ? silent : 0) + (stalled > gapMs ? stalled : 0);
42
+ return Math.round(gap);
43
+ },
44
+ };
45
+ }
46
+
47
+ export function makeWakeLock(nav = typeof navigator !== 'undefined' ? navigator : null, doc = typeof document !== 'undefined' ? document : null) {
48
+ let want = false; let lock = null; let asking = null;
49
+ async function ask() {
50
+ if (!want || lock || asking || !nav || !nav.wakeLock || (doc && doc.visibilityState !== 'visible')) return;
51
+ asking = nav.wakeLock.request('screen').then((l) => {
52
+ if (!want) { l.release().catch(() => {}); return; }
53
+ lock = l;
54
+ l.addEventListener('release', () => { if (lock === l) lock = null; });
55
+ }).catch(() => { /* refused (battery saver, no permission): the screen may lock, and the page says what then happens */ })
56
+ .finally(() => { asking = null; });
57
+ await asking;
58
+ }
59
+ return {
60
+ hold() { want = true; return ask(); },
61
+ again() { return ask(); },
62
+ release() { want = false; const l = lock; lock = null; if (l) l.release().catch(() => {}); },
63
+ held: () => !!lock,
64
+ supported: () => !!(nav && nav.wakeLock),
65
+ };
66
+ }
@@ -207,14 +207,33 @@ 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 live = g.files.filter((x) => !x.archived), L = live[0], n = (f) => live.filter(f).length, d = n((x) => x.state !== 'issued'), i = n((x) => x.state === 'issued'), s = g.setup;
215
+ const pills = [d ? `<span class="s draft">${d} draft</span>` : '', i ? `<span class="s issued">${i} issued</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). Archived cycles are hidden (PM
221
+ * 2026-10-22: "Archived report should be hidden"): a report whose cycles are all archived has no row (a set-up one keeps its set-up row), and
222
+ * its archived cycles stay reachable from the reader's cycle chip. */
223
+ function reportGroups() {
224
+ const R = M.reports, by = new Map();
225
+ for (const f of R.missing ? [] : R.rows) { if (!by.has(f.cadence)) by.set(f.cadence, []); by.get(f.cadence).push(f); }
226
+ const out = [];
227
+ const shown = (fs) => fs && fs.some((x) => !x.archived);
228
+ for (const s of R.setupsOk === false ? [] : (R.setups || [])) { const fs = by.get(s.id); by.delete(s.id); out.push(shown(fs) ? { kind: 'file', x: { id: s.id, name: s.name, setup: s, files: fs } } : { kind: 'setup', x: s }); }
229
+ for (const [id, fs] of by) if (shown(fs)) out.push({ kind: 'file', x: { id, name: id, setup: null, files: fs } });
230
+ return out;
212
231
  }
213
232
  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
233
  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
234
  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 })));
235
+ const d = M.dashboards.map((x) => ({ kind: 'dash', x }));
236
+ const r = reportGroups();
218
237
  return { d, r, all: d.concat(r) };
219
238
  }
220
239
  function drawList() {
@@ -258,8 +277,8 @@ $('#repBody').addEventListener('click', (e) => {
258
277
  if (pin) { pin.disabled = true; pinDash(M.pinned === pin.dataset.pin ? null : pin.dataset.pin, 'list'); return; }
259
278
  const d = e.target.closest('[data-d]');
260
279
  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; }
280
+ const rp = e.target.closest('[data-rpt]');
281
+ if (rp) { const g = reportGroups().find((x) => x.kind === 'file' && x.x.id === rp.dataset.rpt); if (g) openReport(g.x.files.find((x) => !x.archived), { ws: M.board.ws, name: g.x.setup ? g.x.setup.name : null, cycles: g.x.files, onIssue: () => load(), onChange: () => load() }); return; }
263
282
  const f = e.target.closest('[data-found]'), a = e.target.closest('[data-ask]'), s = e.target.closest('[data-setup]');
264
283
  if (f) openFound((M.reports.found || []).find((x) => x.id === f.dataset.found));
265
284
  else if (a) openAsk((M.reports.asks || []).find((x) => x.id === a.dataset.ask));
@@ -460,7 +460,8 @@ export function mountMeeting(d) {
460
460
  note: (id) => NR.find((n) => n.id === id) || null, refresh: readNotes, open: (id) => openNote(id) };
461
461
  /* Leaving the Briefing while it holds the recorder: the browser asks first, and if the PM leaves, the meeting is paused (it stays open for an hour) so the record never says "recording" for audio nobody is capturing. */
462
462
  addEventListener('beforeunload', (e) => { if (HOLD) { e.preventDefault(); e.returnValue = ''; } });
463
- addEventListener('pagehide', () => { if (HOLD) d.pmPost('/api/notes/pause', { id: HOLD.id }, { keepalive: true }); });
463
+ // a page kept for Back (persisted) is not left: a phone that locks or switches apps can hide the page this way, and comes back to it
464
+ addEventListener('pagehide', (e) => { if (HOLD && !(e && e.persisted)) d.pmPost('/api/notes/pause', { id: HOLD.id }, { keepalive: true }); });
464
465
  setInterval(() => { readNotes(); }, 20000);
465
466
  addEventListener('premium-rec', () => { if (cur && cur.alive()) cur.repaint(); mark(); });
466
467