create-pmos 0.316.0 → 0.318.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 (43) hide show
  1. package/package.json +1 -1
  2. package/payload/KIT-VERSION +1 -1
  3. package/payload/planning/evals/eval-calibration.md +1 -1
  4. package/payload/planning/okrs/health-budgets.md +1 -1
  5. package/payload/state/discoveries.md +1 -1
  6. package/workspace/briefing-premium-board-test.js +2 -2
  7. package/workspace/briefing-premium-initiative-test.js +5 -10
  8. package/workspace/briefing-premium-insights-test.js +1 -1
  9. package/workspace/briefing-premium-products-test.js +9 -4
  10. package/workspace/briefing-premium-test.js +12 -10
  11. package/workspace/briefing-premium-work-test.js +1 -1
  12. package/workspace/guide/briefing-premium.md +21 -16
  13. package/workspace/lib/briefing-premium-agent.js +5 -0
  14. package/workspace/lib/capacity-governor.js +5 -3
  15. package/workspace/lib/driver-run.js +46 -7
  16. package/workspace/lib/driver.js +5 -1
  17. package/workspace/lib/headless.js +40 -3
  18. package/workspace/lib/insights-premium.js +1 -1
  19. package/workspace/lib/orchestrator-gate.js +2 -1
  20. package/workspace/lib/orchestrator-health.js +7 -3
  21. package/workspace/lib/orchestrator-quota.js +84 -0
  22. package/workspace/lib/orchestrator-spawn.js +3 -2
  23. package/workspace/lib/routes-briefing-premium.js +1 -1
  24. package/workspace/lib/routes-report-design.js +6 -2
  25. package/workspace/lib/routes-report-structure.js +27 -6
  26. package/workspace/package-lock.json +2 -2
  27. package/workspace/package.json +1 -1
  28. package/workspace/premium-studio-test.js +4 -4
  29. package/workspace/public/pm/premium-board.js +3 -2
  30. package/workspace/public/pm/premium-initiative.js +2 -1
  31. package/workspace/public/pm/premium-insights.js +3 -2
  32. package/workspace/public/pm/premium-shell.js +147 -7
  33. package/workspace/public/pm/premium-work.js +3 -1
  34. package/workspace/public/pm/premium.css +47 -2
  35. package/workspace/public/pm/premium.js +16 -23
  36. package/workspace/public/premium-board.html +2 -6
  37. package/workspace/public/premium-initiative.html +1 -5
  38. package/workspace/public/premium-insights.html +1 -5
  39. package/workspace/public/premium-work.html +2 -6
  40. package/workspace/public/premium.html +3 -7
  41. package/workspace/server.js +27 -5
  42. package/workspace/test-lists/agent-orchestrator-c.json +5 -3
  43. package/workspace/test-lists/agent-orchestrator-e2e.json +9 -0
@@ -1,6 +1,7 @@
1
1
  /* pm/premium-shell.js — what the premium Briefing and My work pages share: the theme, the toast, the standard dialog and the read-only agent's conversation (initiatives briefing-premium and my-work-premium). */
2
2
  import { pmGet, pmPost } from './http.js';
3
3
  import { recChipView, STOP_LINE } from './premium-meeting.js';
4
+ import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words.js';
4
5
  export const $ = (s, r = document) => r.querySelector(s);
5
6
  export const $$ = (s, r = document) => [...r.querySelectorAll(s)];
6
7
  export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
@@ -17,10 +18,142 @@ export function theme(t) {
17
18
  export function flip() {
18
19
  const dark = document.documentElement.dataset.theme ? document.documentElement.dataset.theme === 'dark' : matchMedia('(prefers-color-scheme: dark)').matches;
19
20
  const next = dark ? 'light' : 'dark';
20
- theme(next); store.set(THEME_KEY, next);
21
+ theme(next); store.set(THEME_KEY, next); tbTheme();
21
22
  }
22
23
  { const t = new URLSearchParams(location.search).get('theme') || store.get(THEME_KEY); theme(t); }
23
- $('#theme').onclick = flip; $('#theme2').onclick = flip;
24
+ /* ── the top bar (initiative premium-topbar): where you are and Chat on the left; the Sources chip, the bell and one menu on the right.
25
+ * The menu holds what left the bar: Search, Agent sessions, Console, Theme, Settings, and on Board how an initiative opens. Every item keeps
26
+ * the id the pages and the code below wire, so a press does what it did as a round button. ── */
27
+ export const CHAT = '<svg class="i" viewBox="0 0 24 24"><path d="M4 5h16v11h-9l-5 4v-4H4z"/><path d="M12 7.6l.8 1.9 1.9.8-1.9.8-.8 1.9-.8-1.9-1.9-.8 1.9-.8z"/></svg>';
28
+ const MORE = '<svg class="i" viewBox="0 0 24 24"><circle cx="6" cy="12" r="1.3"/><circle cx="12" cy="12" r="1.3"/><circle cx="18" cy="12" r="1.3"/></svg>';
29
+ const TH = [['light', 'Light'], ['dark', 'Dark'], ['auto', 'Auto']];
30
+ function tbMount() {
31
+ const t = $('.tools-top'); if (!t || $('#tbMore')) return;
32
+ const pc = $('#pgChat'); if (pc) pc.innerHTML = CHAT;
33
+ t.insertAdjacentHTML('beforeend', `<button type="button" class="schip" id="srcChip" aria-haspopup="dialog" title="When each source was last read"><i class="sdot" id="srcDot" aria-hidden="true"></i>Sources</button>`
34
+ + `<span class="mwrap" id="tbMore"><button type="button" class="glass round" id="moreBtn" aria-haspopup="menu" aria-expanded="false" aria-controls="moreMenu" aria-label="More" title="More">${MORE}<i class="mdot" id="moreDot" hidden></i></button>`
35
+ + '<div class="crmenu tbmenu" id="moreMenu" role="menu" aria-label="More" hidden>'
36
+ + '<button role="menuitem" id="pvSearch" aria-haspopup="dialog">Search<em>Ctrl K</em></button>'
37
+ + '<button role="menuitem" id="srcItem" class="tbm-src" aria-haspopup="dialog">Sources</button>'
38
+ + '<button role="menuitem" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions">Agent sessions<em id="sessBdg" hidden></em></button>'
39
+ + '<a role="menuitem" id="toConsole" href="/console.html" aria-label="Open the console">Console</a>'
40
+ + '<div class="tbrow" id="modeRow" hidden><span>Open initiatives</span></div>'
41
+ + `<div class="tbrow" role="group" aria-label="Theme"><span>Theme</span><span class="tbseg" id="tbTheme">${TH.map(([k, w]) => `<button role="menuitemradio" data-th="${k}" aria-checked="false">${w}</button>`).join('')}</span></div>`
42
+ + '<button role="menuitem" id="settingsBtn" aria-haspopup="dialog">Settings</button></div></span>');
43
+ const ms = $('#modeSeg'); if (ms) { $('#modeRow').appendChild(ms); $('#modeRow').hidden = false; }
44
+ tbTheme();
45
+ const btn = $('#moreBtn'), menu = $('#moreMenu');
46
+ const items = () => $$('#moreMenu [role^="menuitem"]').filter((x) => x.offsetParent !== null || x.closest('.tbseg'));
47
+ const close = (back) => { if (menu.hidden) return; menu.hidden = true; btn.setAttribute('aria-expanded', 'false'); if (back) btn.focus(); };
48
+ btn.onclick = (e) => {
49
+ e.stopPropagation();
50
+ if (!menu.hidden) { close(); return; }
51
+ menu.hidden = false; btn.setAttribute('aria-expanded', 'true');
52
+ if ($('#modeSeg', menu)) pillOf($('#modeSeg', menu));
53
+ const f = items()[0]; if (f) f.focus();
54
+ };
55
+ // capture: the menu closes and focus goes back to its button before the item's own press runs, so a dialog it opens returns focus there
56
+ menu.addEventListener('click', (e) => {
57
+ const th = e.target.closest('[data-th]');
58
+ if (th) { const v = th.dataset.th; theme(v === 'auto' ? null : v); store.set(THEME_KEY, v === 'auto' ? '' : v); tbTheme(); return; }
59
+ if (e.target.closest('#modeRow')) return;
60
+ if (e.target.closest('[role="menuitem"]')) close(true);
61
+ }, true);
62
+ document.addEventListener('click', (e) => { if (!e.target.closest('#tbMore')) close(); });
63
+ menu.addEventListener('keydown', (e) => {
64
+ if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); close(true); return; }
65
+ if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return;
66
+ const L = items(), i = L.indexOf(document.activeElement); if (!L.length) return;
67
+ e.preventDefault(); L[(i + (e.key === 'ArrowDown' ? 1 : L.length - 1) + (i < 0 ? 1 : 0)) % L.length].focus();
68
+ });
69
+ $('#srcChip').onclick = () => openSources(); $('#srcItem').onclick = () => openSources();
70
+ if (pc) pc.onclick = () => { if (PAGE_CHAT) PAGE_CHAT(); };
71
+ tbReadSrc();
72
+ setInterval(() => { if (!document.hidden) tbReadSrc(); }, 300000);
73
+ }
74
+ function tbTheme() {
75
+ const cur = document.documentElement.dataset.theme || 'auto';
76
+ $$('#tbTheme [data-th]').forEach((b) => b.setAttribute('aria-checked', String(b.dataset.th === cur)));
77
+ }
78
+ let PAGE_CHAT = null;
79
+ /** The page's Chat press: fn opens the page's conversation (the Briefing and My work), the board's or the initiative's, or the Studio. */
80
+ export function onPageChat(fn) { PAGE_CHAT = fn; }
81
+
82
+ /* ── Sources: when each source was last read, and a Refresh for each (GET /api/sources, POST /api/sources/refresh, as Data freshness) ──
83
+ * The chip says no time: each source is read on its own schedule, so only the dialog's rows carry times. Its dot is orange when a source is
84
+ * old, failed or never read, or when the page itself could not read something (setPageGaps). A page adds its own part with sourcesHook. */
85
+ const TB = { src: null, gaps: 0, extra: null, msg: '', busy: false };
86
+ const SSTATE = { fresh: 'Recent', stale: 'Old', never: 'Never read', building: 'Reading now', failed: 'Failed', off: 'Off' };
87
+ const wsQ = () => { const w = new URLSearchParams(location.search).get('ws'); return w ? '?ws=' + encodeURIComponent(w) : ''; };
88
+ async function tbReadSrc() {
89
+ const r = await pmGet('/api/sources' + wsQ());
90
+ TB.src = r && r.ok && Array.isArray(r.sources) ? r : { ok: false, sources: [] };
91
+ tbDot();
92
+ return TB.src;
93
+ }
94
+ function tbDot() {
95
+ const d = $('#srcDot'), c = $('#srcChip'); if (!d || !c) return;
96
+ const behind = TB.src && TB.src.ok ? behindOf(lineItems(TB.src.sources)) : [];
97
+ const n = behind.length + TB.gaps, known = TB.src && TB.src.ok;
98
+ d.className = 'sdot ' + (n || (TB.src && !TB.src.ok) ? 'warn' : known ? 'ok' : '');
99
+ c.title = TB.src && !TB.src.ok ? 'The sources could not be read' : n ? [behind.length ? behind.map((b) => b.text).join(', ') : '', TB.gaps ? TB.gaps + (TB.gaps === 1 ? ' source this page could not read' : ' sources this page could not read') : ''].filter(Boolean).join(' · ') : known ? 'Every source was read recently' : 'Reading the sources';
100
+ }
101
+ /** n: how many sources the page itself could not read (its header's missing list). */
102
+ export function setPageGaps(n) { TB.gaps = n || 0; tbDot(); }
103
+ /** h: { html() → the page's own part of Sources, mount() after it is drawn, refresh() → what Refresh all also reads again }. */
104
+ export function sourcesHook(h) { TB.extra = h; }
105
+ function park() { $$('#oMain [data-park]').forEach((x) => { const p = document.getElementById(x.dataset.park); if (p) p.appendChild(x); }); }
106
+ const srcRow = (s) => {
107
+ const cls = s.state === 'fresh' ? 'ok' : s.state === 'stale' || s.state === 'failed' || s.state === 'never' ? 'warn' : '';
108
+ const when = s.id === 'repository' && s.state === 'fresh' ? 'watched for changes' : s.as_of ? 'read ' + whenRead(s.as_of) : 'never read';
109
+ const off = s.state === 'off' || s.state === 'building' || TB.busy;
110
+ return `<div class="sr"><span class="sn"><b><i class="sdot ${cls}" aria-hidden="true"></i>${esc(s.label)}</b><em>${esc(SSTATE[s.state] || s.state)}${s.as_of || s.id === 'repository' && s.state === 'fresh' ? ' · ' + esc(when) : ''}</em></span>${s.id === 'repository' ? '' : `<button type="button" class="cta alt" data-sref="${esc(s.id)}" aria-label="Refresh ${esc(s.label)}"${off ? ' disabled' : ''}>Refresh</button>`}</div>`;
111
+ };
112
+ let SPOLL = null;
113
+ export async function openSources() {
114
+ // the frame is drawn once; a re-read redraws only the rows, the button and the message, so the page's own part (the Briefing's picker) is left alone
115
+ const rowsHtml = () => { const s = TB.src; return !s ? '<p class="note">Reading the sources.</p>' : !s.ok ? '<p class="note err" role="alert">The sources could not be read.</p>' : s.sources.map(srcRow).join(''); };
116
+ const draw = () => {
117
+ if ($('#srcRows')) { $('#srcRows').innerHTML = rowsHtml(); $('#srcAll').disabled = TB.busy; $('#srcM').textContent = TB.msg; return; }
118
+ park();
119
+ $('#oMain').innerHTML = `<article class="paper doc"><div class="addf">
120
+ <div class="srctop"><p class="note" style="margin:0">Each source is read on its own schedule, not live. Each row says when it was last read.</p><button type="button" class="cta" id="srcAll"${TB.busy ? ' disabled' : ''}>Refresh all</button></div>
121
+ <div>${TB.extra ? '<span class="label">Sources</span>' : ''}<div id="srcRows">${rowsHtml()}</div></div>
122
+ ${TB.extra ? TB.extra.html() : ''}
123
+ <p class="note" id="srcM" role="status" style="margin:0;min-height:1.2em">${esc(TB.msg)}</p></div></article>`;
124
+ if (TB.extra && TB.extra.mount) TB.extra.mount();
125
+ };
126
+ const say = 'When each source was last read. Each one is read on its own schedule, so the rows say their own times.';
127
+ TB.msg = '';
128
+ openDlg({ eye: 'Sources', title: 'Sources', say, stream: turnA(ptx(say)), noteKey: null, pane: '<article class="paper doc"></article>', label: 'Sources' });
129
+ $('#askF').hidden = true; setMode('detail');
130
+ const poll = (n) => { clearTimeout(SPOLL); if (!n || !TB.src || !TB.src.ok || !TB.src.sources.some((x) => x.state === 'building')) return; SPOLL = setTimeout(async () => { if ($('#dTitle').textContent !== 'Sources' || !$('#dlg').classList.contains('on')) return; await tbReadSrc(); draw(); poll(n - 1); }, 3000); };
131
+ $('#oMain').onclick = async (e) => {
132
+ const one = e.target.closest('[data-sref]'), all = e.target.closest('#srcAll');
133
+ if ((!one && !all) || TB.busy || !TB.src || !TB.src.ok) return;
134
+ const ids = all ? refreshTargets(TB.src.sources) : [one.dataset.sref];
135
+ TB.busy = true; TB.msg = 'Starting.'; draw();
136
+ const got = await Promise.all(ids.map((id) => pmPost('/api/sources/refresh', { ws: TB.src.ws || '', source: id }).catch(() => null)));
137
+ let extra = null; if (all && TB.extra && TB.extra.refresh) extra = await TB.extra.refresh();
138
+ const bad = got.filter((r) => !r || !r.ok).length;
139
+ TB.busy = false;
140
+ TB.msg = (ids.length ? (bad ? bad + ' of ' + ids.length + ' did not start.' : ids.length === 1 ? 'Reading it again.' : 'Reading ' + ids.length + ' sources again.') : '') + (extra ? ' ' + extra : '');
141
+ await tbReadSrc(); draw(); poll(8);
142
+ };
143
+ draw();
144
+ await tbReadSrc(); draw(); poll(8);
145
+ }
146
+
147
+ /* ── Chat on the Briefing and My work: the standard dialog, read-only, about the page as a whole (key src:this-page or work:this-page) ── */
148
+ export function openPageChat(key, page) {
149
+ const lead = (($('#brief') && $('#brief').textContent) || '').replace(/\s+/g, ' ').trim();
150
+ const say = 'Ask anything about this page. The agent reads the records the page shows and answers in words. It cannot change anything.';
151
+ openDlg({ eye: page, title: 'Ask about ' + page, say, stream: turnA(ptx(say)), noteKey: key, pane: `<article class="paper doc"><h3 class="d2">What the page says</h3><p>${esc(lead || 'The page has not read its records yet.')}</p></article>`, label: page });
152
+ $('#askIn').placeholder = 'Ask the agent about this page';
153
+ loadThread(key);
154
+ }
155
+ tbMount(); // the top bar first: the menu holds the Settings, Agent sessions, Console and Search items the code below wires
156
+ { const t2 = $('#theme2'); if (t2) t2.onclick = flip; }
24
157
  { const b = $('#settingsBtn'); if (b) b.onclick = () => openSettings(); } // hoisted: the function below is declared, not assigned
25
158
 
26
159
  /* ── toast ──────────────────────────────────────────────────────────────────────────────────────────────── */
@@ -32,6 +165,7 @@ export const kv = (rows) => `<div class="kv2">${rows.filter((r) => r && r[1]).ma
32
165
  export const H = (t) => `<h3 class="h2">${esc(t)}</h3>`;
33
166
  export function openDlg(o) {
34
167
  S.key = o.noteKey || null;
168
+ park(); // a page's own control lent to the dialog (the Briefing's product picker) goes home before the pane is replaced
35
169
  const ae = document.activeElement; if (ae && ae !== document.body) lastFocus = ae;
36
170
  $$('.rail,main.stage,#dock').forEach((x) => { x.inert = true; });
37
171
  $('#dlg').inert = false; document.documentElement.style.overflow = 'hidden';
@@ -45,6 +179,7 @@ export function openDlg(o) {
45
179
  }
46
180
  export function closeDlg() {
47
181
  clearTimeout(threadTimer); S.key = null;
182
+ park();
48
183
  $('#veil').classList.remove('on'); $$('.rail,main.stage,#dock').forEach((x) => { x.inert = false; });
49
184
  $('#dlg').inert = true; document.documentElement.style.overflow = ''; $('#dlg').classList.remove('on');
50
185
  $('#dock').inert = !document.body.classList.contains('docked');
@@ -188,10 +323,15 @@ export function wireRail(here) {
188
323
  $$('.rail [data-go]').forEach((b) => { b.onclick = () => { if (b.dataset.go !== here) location.assign(GO[b.dataset.go]); }; });
189
324
  }
190
325
 
191
- /* ── the crumb: where you are, a menu to switch board or initiative, and the sparkle that opens the read-only agent ──────────────────── */
326
+ /* ── the crumb: where you are, a menu to switch board or initiative, and Chat, which opens the read-only agent ──────────────────── */
192
327
  export function crumbHtml(o) {
193
328
  const chev = (id, label, show) => `<button id="${id}" class="cri" aria-haspopup="menu" aria-expanded="false" aria-label="${esc(label)}"${show ? '' : ' hidden'}>${CHEV}</button>`;
194
- return `<nav class="crumb" aria-label="Where you are"><button id="crBoard"${o.ini ? '' : ' aria-current="page" disabled'}>${esc(o.board)}</button>${chev('crSw', 'Switch board', o.boards && o.boards.length > 1)}${o.ini ? `<span aria-hidden="true">›</span><span id="crIni" aria-current="page">${esc(o.ini)}</span>${chev('crSw2', 'Switch initiative', o.siblings && o.siblings.length > 1)}` : ''}<button id="crAsk" class="cri crask${o.label ? ' crst' : ''}" aria-label="${esc(o.ask)}">${AI}${o.label ? esc(o.label) : ''}</button><div id="crMenu" class="crmenu" role="menu" hidden></div></nav>`;
329
+ const menu = '<div id="crMenu" class="crmenu" role="menu" hidden></div>';
330
+ // an initiative: a round back button to its board, then one pill with its name and the switcher; a board page: the page, the board and its switcher
331
+ const left = o.ini
332
+ ? `<button id="crBoard" class="glass round crback" aria-label="Back to ${esc(o.board)}" title="Back to ${esc(o.board)}"><svg class="i" viewBox="0 0 24 24"><path d="m14 6-6 6 6 6"/></svg></button><nav class="crumb" aria-label="Where you are"><span id="crIni" aria-current="page">${esc(o.ini)}</span>${chev('crSw2', 'Switch initiative', o.siblings && o.siblings.length > 1)}${menu}</nav>`
333
+ : `<nav class="crumb" aria-label="Where you are">${o.page ? `<span class="crpg">${esc(o.page)}</span>` : ''}<button id="crBoard" aria-current="page" disabled>${esc(o.board)}</button>${chev('crSw', 'Switch board', o.boards && o.boards.length > 1)}${menu}</nav>`;
334
+ return `<div class="where">${left}<button id="crAsk" class="round tbchat" aria-haspopup="dialog" aria-label="${esc(o.ask)}" title="${esc(o.ask)}">${CHAT}</button></div>`;
195
335
  }
196
336
  /** o: { boards: [{ws,id,name}], board: id, siblings: [{id,title}], ini: id, goBoard(ws, id), goIni(id), ask() }. Escape and a click outside close the menu; the arrows move in it. */
197
337
  export function wireCrumb(o) {
@@ -262,8 +402,8 @@ const pvQ = (sep) => (PV_WS ? sep + 'ws=' + encodeURIComponent(PV_WS) : '');
262
402
  async function pvGet(u) { try { const r = await fetch(u, { credentials: 'same-origin' }); return { status: r.status, j: await r.json() }; } catch { return { status: 0, j: null }; } }
263
403
  const pvOv = { kind: null, back: null, at: 0, list: [], pal: null, need: null };
264
404
  function pvMount() {
265
- const a = $('#toConsole'); if (!a || $('#pvSearch')) return;
266
- a.insertAdjacentHTML('beforebegin', `<button class="glass round" id="pvSearch" aria-haspopup="dialog" aria-label="Search (Ctrl K)" title="Search (Ctrl K)">${SRCH}</button><button class="glass round pv-hp" id="pvBell" aria-haspopup="dialog" aria-label="Needs you" title="Needs you">${BELL}<span class="pv-bdg" id="pvBdg" hidden></span></button>`);
405
+ const a = $('#tbMore'); if (!a || $('#pvBell')) return;
406
+ a.insertAdjacentHTML('beforebegin', `<button class="glass round pv-hp" id="pvBell" aria-haspopup="dialog" aria-label="Needs you" title="Needs you">${BELL}<span class="pv-bdg" id="pvBdg" hidden></span></button>`);
267
407
  document.body.insertAdjacentHTML('beforeend', '<div class="pv-scrim" id="pvScrim"></div><div class="pv-ov" id="pvOv" role="dialog" aria-modal="true" hidden inert></div>');
268
408
  $('#pvSearch').onclick = () => pvOpen('pal'); $('#pvBell').onclick = () => pvOpen('bell'); $('#pvScrim').onclick = pvClose;
269
409
  pvNeeds();
@@ -277,7 +417,7 @@ export function pvClose() {
277
417
  function pvOpen(kind) {
278
418
  if (pvOv.kind === kind) { pvClose(); return; }
279
419
  if (pvOv.kind) pvClose();
280
- const ae = document.activeElement; pvOv.back = ae && ae !== document.body ? ae : $(kind === 'pal' ? '#pvSearch' : '#pvBell');
420
+ const ae = document.activeElement; pvOv.back = ae && ae !== document.body ? ae : $(kind === 'pal' ? '#moreBtn' : '#pvBell');
281
421
  pvOv.kind = kind; pvOv.at = 0;
282
422
  $$('.rail,main.stage,#dock').forEach((x) => { x.inert = true; }); document.documentElement.style.overflow = 'hidden';
283
423
  const o = $('#pvOv'); o.className = 'pv-ov ' + kind; o.setAttribute('aria-label', kind === 'pal' ? 'Search' : 'Needs you'); o.hidden = false; o.inert = false; $('#pvScrim').classList.add('on');
@@ -6,7 +6,7 @@
6
6
  import { pmPost, pmGet } from './http.js';
7
7
  import { weekView, stripHtml, foldLine, mountFold } from './premium-meeting.js';
8
8
  import { mdRender } from './markdown.js';
9
- import { $, $$, esc, openDlg, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, turnU, ptx, CHECK, RM, S } from './premium-shell.js';
9
+ import { $, $$, esc, openDlg, closeDlg, setMode, toast, loadThread, onScroll, wireRail, logHtml, turnA, turnU, ptx, CHECK, RM, S, setPageGaps, onPageChat, openPageChat } from './premium-shell.js';
10
10
 
11
11
  let M = null; // the model
12
12
  let openR = null; // the row whose dialog is open
@@ -35,6 +35,7 @@ function drawHero() {
35
35
  $('#date').textContent = M.date;
36
36
  $('#brief').innerHTML = M.hero.map((s) => s.parts.map((p) => (p.s ? `<span class="k">${esc(p.t)}</span>` : esc(p.t))).join('')).join(' ');
37
37
  $('#snap').textContent = M.header.text;
38
+ setPageGaps(((M.header && M.header.missing) || []).length);
38
39
  $('#snap').title = 'Every figure on this page comes from an item on your list. A date shows only when one was set.';
39
40
  }
40
41
  function drawDock() { $('#dN').textContent = M.dock.needs; $('#dLab').textContent = M.dock.needs === 0 ? 'to clear' : M.dock.label; $('#dNext').innerHTML = M.dock.next ? `<i></i>Next <b>${esc(M.dock.next)}</b>` : 'Nothing more on your list'; }
@@ -658,5 +659,6 @@ async function load() {
658
659
  if (mine && dlgKind === 'item') refreshOpen(); else if (mine) drawFocusDlg();
659
660
  }
660
661
  setInterval(() => { if (M && M.agents && M.agents.counts.running > 0 && !document.hidden) load(); }, 15000); // an agent's state changes without a press
662
+ onPageChat(() => openPageChat('work:this-page', 'My work')); // Chat in the top bar: the page as a whole (initiative premium-topbar)
661
663
  $('#brief').textContent = 'Reading your list.';
662
664
  load();
@@ -1531,8 +1531,7 @@ button.dsn:hover{box-shadow:inset 0 0 0 1.5px rgb(79,109,245)}
1531
1531
  .rsm .mchip{font-size:1.8cqw;margin:1.2cqw 0 1.6cqw;display:inline-block}
1532
1532
  .nrep .mhint{margin-bottom:10px}
1533
1533
  .rsg .mt1{margin:0;padding:0;background:none;box-shadow:none}
1534
- /* initiative page: the pill and the theme button sit under the crumb as the mockup draws them; long file names in the check evidence wrap */
1535
- .top:has(#iH1) .tools-top{flex-basis:100%;justify-content:flex-start}
1534
+ /* initiative page: long file names in the check evidence wrap */
1536
1535
  #cIniChk .ckr small{overflow-wrap:anywhere}
1537
1536
 
1538
1537
  /* search and the bell in the header (initiative premium-search-bell); the look is the mockup's overlays ov-pal and ov-bell */
@@ -2021,3 +2020,49 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
2021
2020
  .wkdue span{font:600 var(--fs-2) var(--mono);letter-spacing:.06em;text-transform:uppercase;color:var(--ember-ink)}.wkdue b{font-weight:500}
2022
2021
  .tl.wkday{min-height:0}.tl.wkday .ev{cursor:default}
2023
2022
  #todayCard.wkm .foldb{margin-left:auto}
2023
+
2024
+ /* one top bar on every premium page (initiative premium-topbar): left = where you are + Chat; right = Sources chip, bell, one ⋯ menu */
2025
+ .top{flex-wrap:nowrap}
2026
+ .where{display:flex;align-items:center;gap:10px;min-width:0}
2027
+ .where .crumb{max-width:none;min-width:0}
2028
+ .tbchat{flex:none;background:var(--solid);color:var(--on-solid);border:0;box-shadow:0 10px 30px -10px rgba(20,22,31,.45)}
2029
+ .tbchat svg{width:19px;height:19px}
2030
+ #crBoard.crback{flex:none;width:44px;height:44px;padding:0;border-radius:50%;display:grid;place-items:center;background:var(--card);border:1px solid var(--hair);color:var(--ink);cursor:pointer}
2031
+ #crBoard.crback:hover{text-decoration:none;background:var(--well)}
2032
+ #crBoard.crback svg{width:20px;height:20px}
2033
+ .crumb .crpg{color:var(--ink);font-weight:600;padding:0 4px 0 12px}
2034
+ .top .tools-top{flex-wrap:nowrap;justify-content:flex-end;flex:none}
2035
+ .schip{height:44px;display:inline-flex;align-items:center;gap:8px;padding:0 14px;border-radius:999px;background:var(--card);border:1px solid var(--hair);font:500 var(--t-micro) var(--mono);color:var(--ink-2);flex:none}
2036
+ .schip:hover{background:var(--well)}
2037
+ .sdot{width:8px;height:8px;border-radius:50%;background:var(--ink-3);flex:none;display:inline-block}
2038
+ .sdot.ok{background:var(--ok)}
2039
+ .sdot.warn{background:var(--ember)}
2040
+ .sr .sn b{display:inline-flex;align-items:center;gap:8px}
2041
+ .srctop{display:flex;align-items:center;justify-content:space-between;gap:12px;flex-wrap:wrap}
2042
+ .mwrap{position:relative;display:inline-flex}
2043
+ .mdot{position:absolute;top:2px;right:2px;width:10px;height:10px;border-radius:50%;background:var(--ember);border:2px solid var(--card-solid)}
2044
+ .mdot[hidden]{display:none}
2045
+ .crmenu.tbmenu{left:auto;right:0;min-width:300px;z-index:45}
2046
+ .crmenu.tbmenu > button,.crmenu.tbmenu > a{height:44px}
2047
+ .crmenu .seg button{width:auto;height:38px;padding:0 12px;font-size:var(--fs-2);font-weight:600}
2048
+ .tbrow > span:first-child{white-space:nowrap}
2049
+ .crmenu a{display:flex;align-items:center;height:42px;padding:0 14px;border-radius:14px;font-weight:500;font-size:var(--fs-3);color:inherit;text-decoration:none}
2050
+ .crmenu a:hover,.crmenu a:focus-visible{background:var(--well)}
2051
+ .tbrow{display:flex;align-items:center;gap:10px;min-height:44px;padding:0 6px 0 14px;font-weight:500;font-size:var(--fs-3);border-top:1px solid var(--hair);margin-top:4px}
2052
+ .tbrow[hidden]{display:none}
2053
+ .tbrow + .tbrow{border-top:0;margin-top:0}
2054
+ .tbrow > .seg,.tbseg{margin-left:auto}
2055
+ .tbseg{display:inline-flex;padding:3px;border-radius:999px;background:var(--well);gap:2px}
2056
+ .crmenu .tbseg button{height:38px;width:auto;padding:0 11px;border-radius:999px;font-size:var(--fs-2);font-weight:600;color:var(--ink-2)}
2057
+ .crmenu .tbseg button[aria-checked="true"]{background:var(--solid);color:var(--on-solid)}
2058
+ .tbrow + #settingsBtn{border-top:1px solid var(--hair);border-radius:0 0 14px 14px;margin-top:4px}
2059
+ .crmenu .tbm-src{display:none}
2060
+ #oMain .pkw .pkmenu{left:0;right:auto}
2061
+ #oMain .pkmenu button{height:44px;min-height:44px;box-sizing:border-box}
2062
+ @media (max-width:700px){
2063
+ #srcChip{display:none}
2064
+ .crmenu .tbm-src{display:flex}
2065
+ .where .crumb:has(.crpg) #crBoard{display:none}
2066
+ .where #crIni{max-width:calc(100vw - 316px)}
2067
+ .top .tools-top{gap:8px}
2068
+ }
@@ -9,7 +9,7 @@ import { mountFirst } from './premium-first.js';
9
9
  import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words.js';
10
10
  import { consoleReads, briefOf, needsListOf } from './premium-brief.js';
11
11
  import { momentOf, inText } from './c3-phone-model.js';
12
- import { $, $$, esc, store, THEME_KEY, RM, AI, S, theme, toast, kv, H, openDlg, closeDlg, setTab, setMode, CHECK, CHEV, ptx, turnA, turnU, H1, H2, P1, UL, logHtml, loadThread, onScroll, wireRail, pvFeed } from './premium-shell.js';
12
+ import { $, $$, esc, store, THEME_KEY, RM, AI, S, theme, toast, kv, H, openDlg, closeDlg, setTab, setMode, CHECK, CHEV, ptx, turnA, turnU, H1, H2, P1, UL, logHtml, loadThread, onScroll, wireRail, pvFeed, setPageGaps, sourcesHook, onPageChat, openPageChat } from './premium-shell.js';
13
13
  const ICON = {
14
14
  meeting: '<rect x="4" y="5" width="16" height="15" rx="3"/><path d="M4 10h16M9 3v4M15 3v4"/>',
15
15
  merge: '<circle cx="6" cy="6" r="2"/><circle cx="6" cy="18" r="2"/><circle cx="18" cy="9" r="2"/><path d="M6 8v8M18 11c0 4-6 3-12 5"/>',
@@ -60,6 +60,7 @@ function drawHero() {
60
60
  if (shownBrief == null) $('#brief').innerHTML = M.hero.map((s) => s.parts.map((p) => (p.s ? `<span class="k">${esc(p.t)}</span>` : esc(p.t))).join('')).join(' ');
61
61
  drawConsoleBrief();
62
62
  $('#snap').textContent = M.header.text;
63
+ setPageGaps(M.header.sources ? M.header.sources.filter((x) => x.state === 'not-read').length : (M.header.missing || []).length);
63
64
  $('#snap').title = M.header.missing.length ? 'A source that cannot be read adds nothing. It is named here, and the page does not guess.' : 'Every figure on this page comes from a record in the repository.';
64
65
  }
65
66
 
@@ -947,34 +948,26 @@ async function load() {
947
948
  else if (r.pending) setTimeout(load, 3000);
948
949
  else if (r.refreshing) setTimeout(load, 10000);
949
950
  }
950
- /* ── Refresh and Sources, beside the Real data line: read the repositories again now, and see which source was read, which was not, and why ── */
951
- const RDST = { read: ['fresh', 'Read'], 'not-read': ['failed', 'Not read'], 'not-included': ['off', 'Not included'], off: ['off', 'Off'] };
951
+ /* ── the Briefing's part of Sources (initiative premium-topbar): the products it reads, what it could not read and why, and Refresh all
952
+ * also reads the included repositories again. The product picker is the header's own control, lent to the dialog while it is open. ── */
953
+ const RDST = { read: ['ok', 'Read'], 'not-read': ['warn', 'Not read'], 'not-included': ['', 'Not included'], off: ['', 'Off'] };
952
954
  function sourcesHtml() {
953
955
  const L = (M && M.header && M.header.sources) || [];
954
- if (!L.length) return '<p class="note">The Briefing has not read anything yet.</p>';
955
- const bad = L.filter((x) => x.state === 'not-read').length;
956
- return `<div class="bd-top"><p>${bad ? bad + (bad === 1 ? ' source was' : ' sources were') + ' not read. Each reason is below.' : 'Every source was read.'}</p></div>`
957
- + L.map((x) => { const [c, w] = RDST[x.state] || ['off', x.state]; return `<div class="bd-src"><span><b>${esc(x.name)}</b><small><span class="bd-st ${c}">${w}</span></small><small>${esc(x.reason)}</small></span></div>`; }).join('')
958
- + '<p class="note">Refresh reads the included repositories again. Mail, Jira and the calendar are read by skills: refresh them under Around you, Data freshness.</p>';
959
- }
960
- async function pressRefresh(btn) {
961
- if (btn.disabled) return;
962
- btn.disabled = true; btn.textContent = 'Refreshing';
956
+ const rows = !L.length ? '<p class="note">The Briefing has not read anything yet.</p>'
957
+ : L.map((x) => { const [c, w] = RDST[x.state] || ['', x.state]; return `<div class="sr"><span class="sn"><b><i class="sdot ${c}" aria-hidden="true"></i>${esc(x.name)}</b><em>${esc(w)}${x.reason ? ' · ' + esc(x.reason) : ''}</em></span></div>`; }).join('');
958
+ return `<div id="pkSlot"></div><div><span class="label">What the Briefing read</span>${rows}</div>`;
959
+ }
960
+ async function refreshRepos() {
963
961
  const ws = new URLSearchParams(location.search).get('ws');
964
962
  const r = await pmPost('/api/briefing-premium/refresh' + (ws ? '?ws=' + encodeURIComponent(ws) : ''), {});
965
- if (!r || !r.ok) { btn.disabled = false; btn.textContent = 'Refresh'; toast('Refresh did not start: ' + ((r && r.error) || 'the server did not answer') + '.'); return; }
966
- toast(r.started && r.started.length ? 'Reading again: ' + r.started.join(', ') + '.' : r.already && r.already.length ? 'Already reading ' + r.already.join(', ') + '.' : 'No repository is included, so there is nothing to read.');
967
- clearTimeout(RTIMER); RTIMER = setTimeout(async () => { await load(); btn.disabled = false; btn.textContent = 'Refresh'; }, 4000);
963
+ if (!r || !r.ok) return 'The repositories were not read again: ' + ((r && r.error) || 'the server did not answer') + '.';
964
+ clearTimeout(RTIMER); RTIMER = setTimeout(load, 4000);
965
+ return r.started && r.started.length ? 'Reading again: ' + r.started.join(', ') + '.' : r.already && r.already.length ? 'Already reading ' + r.already.join(', ') + '.' : 'No repository is included.';
968
966
  }
969
967
  let RTIMER = null;
970
- (function mountReal() {
971
- const snap = $('#snap'); if (!snap) return;
972
- const w = document.createElement('span'); w.className = 'rdbtns';
973
- w.innerHTML = '<button type="button" class="fchip" id="rdRefresh" title="Read the included repositories again now">Refresh</button><button type="button" class="fchip" id="rdSources" aria-haspopup="dialog" title="Which source was read, which was not, and why">Sources</button>';
974
- snap.insertAdjacentElement('afterend', w);
975
- $('#rdRefresh').addEventListener('click', (e) => pressRefresh(e.currentTarget));
976
- $('#rdSources').addEventListener('click', () => bdDlg('rd', 'Sources · real data', 'What the Briefing read', 'Which source was read, which was not, and why', M ? 'Each source below says whether it was read and, when it was not, the reason.' : 'The Briefing has not read anything yet.', sourcesHtml, () => {}));
977
- })();
968
+ $('#pkw').dataset.park = 'pkPark';
969
+ sourcesHook({ html: sourcesHtml, mount: () => { const slot = $('#pkSlot'), w = $('#pkw'); if (slot && w) slot.appendChild(w); }, refresh: refreshRepos });
970
+ onPageChat(() => openPageChat('src:this-page', 'the Briefing'));
978
971
  $('#brief').textContent = 'Reading the repository.';
979
972
  load();
980
973
  mountFirst(); // the "Your first Briefing" card, only when the page was opened with first=<import id> (initiative premium-welcome)
@@ -33,12 +33,8 @@
33
33
  <main class="stage" id="stage">
34
34
  <header class="top rise" style="--d:0">
35
35
  <h1 class="vh">Board</h1><div id="crumbHost"></div>
36
- <div class="tools tools-top"><span class="snap" id="snap">Reading the board</span>
37
- <span class="seg modeseg" id="modeSeg" role="group" aria-label="How an initiative opens"><i class="pill"></i><button data-m="page" aria-pressed="true">Page</button><button data-m="popup" aria-pressed="false">Popup</button></span>
38
- <a class="glass round" id="toConsole" href="/console.html" aria-label="Open the console" title="Open the console"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="m7 9 3 3-3 3M13 15h4"/></svg></a>
39
- <button class="glass round sbtn" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions" title="Agent sessions"><svg class="i" viewBox="0 0 24 24"><path d="M4 6h16M4 12h10M4 18h6"/><circle cx="18" cy="16" r="3"/></svg><span class="sbdg" id="sessBdg" aria-hidden="true" hidden></span></button>
40
- <button class="glass round" id="settingsBtn" aria-label="Settings" title="Settings"><svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6 7 7M17 17l1.4 1.4M5.6 18.4 7 17M17 7l1.4-1.4"/></svg></button>
41
- <button class="glass round" id="theme" aria-label="Switch light or dark"><svg class="i" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg></button></div>
36
+ <div class="tools tools-top"><span class="vh" id="snap">Reading the board</span>
37
+ <span id="modePark" hidden><span class="seg modeseg" id="modeSeg" role="group" aria-label="How an initiative opens"><i class="pill"></i><button data-m="page" aria-pressed="true">Page</button><button data-m="popup" aria-pressed="false">Popup</button></span></span></div>
42
38
  </header>
43
39
  <section class="hero hero-slim"><p class="brief rise" style="--d:2" id="brief" aria-live="polite"></p></section>
44
40
  <section class="card rise" style="--d:4" id="cMet" aria-labelledby="hMet" hidden>
@@ -33,11 +33,7 @@
33
33
  <main class="stage" id="stage">
34
34
  <header class="top rise" style="--d:0">
35
35
  <h1 class="vh" id="iH1">Initiative</h1><div id="crumbHost"></div>
36
- <div class="tools tools-top"><span class="snap" id="snap">Reading the initiative</span>
37
- <a class="glass round" id="toConsole" href="/console.html" aria-label="Open the console" title="Open the console"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="m7 9 3 3-3 3M13 15h4"/></svg></a>
38
- <button class="glass round sbtn" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions" title="Agent sessions"><svg class="i" viewBox="0 0 24 24"><path d="M4 6h16M4 12h10M4 18h6"/><circle cx="18" cy="16" r="3"/></svg><span class="sbdg" id="sessBdg" aria-hidden="true" hidden></span></button>
39
- <button class="glass round" id="settingsBtn" aria-label="Settings" title="Settings"><svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6 7 7M17 17l1.4 1.4M5.6 18.4 7 17M17 7l1.4-1.4"/></svg></button>
40
- <button class="glass round" id="theme" aria-label="Switch light or dark"><svg class="i" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg></button></div>
36
+ <div class="tools tools-top"><span class="vh" id="snap">Reading the initiative</span></div>
41
37
  </header>
42
38
  <section class="hero hero-slim"><p class="brief rise" style="--d:2" id="brief" aria-live="polite"></p></section>
43
39
  <div id="iMain"><p class="empty3 plain" id="iRead">The initiative is read from its records. This page shows nothing until it has read, rather than guess.</p></div>
@@ -34,11 +34,7 @@
34
34
  <main class="stage" id="stage">
35
35
  <header class="top rise" style="--d:0">
36
36
  <h1 class="vh">Insights</h1><div id="crumbHost"></div>
37
- <div class="tools tools-top"><span class="snap" id="snap">Reading the records</span>
38
- <a class="glass round" id="toConsole" href="/console.html" aria-label="Open the console" title="Open the console"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="m7 9 3 3-3 3M13 15h4"/></svg></a>
39
- <button class="glass round sbtn" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions" title="Agent sessions"><svg class="i" viewBox="0 0 24 24"><path d="M4 6h16M4 12h10M4 18h6"/><circle cx="18" cy="16" r="3"/></svg><span class="sbdg" id="sessBdg" aria-hidden="true" hidden></span></button>
40
- <button class="glass round" id="settingsBtn" aria-label="Settings" title="Settings"><svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6 7 7M17 17l1.4 1.4M5.6 18.4 7 17M17 7l1.4-1.4"/></svg></button>
41
- <button class="glass round" id="theme" aria-label="Switch light or dark"><svg class="i" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg></button></div>
37
+ <div class="tools tools-top"><span class="vh" id="snap">Reading the records</span></div>
42
38
  </header>
43
39
  <section class="hero hero-slim"><p class="brief rise" style="--d:2" id="brief" aria-live="polite"></p></section>
44
40
  <section class="card rise" style="--d:4" id="cBm" aria-labelledby="hBm" hidden>
@@ -32,12 +32,8 @@
32
32
  <div class="toast glass" id="toast" role="status"></div>
33
33
  <main class="stage" id="stage">
34
34
  <header class="top rise" style="--d:0">
35
- <h1 class="vh">My work</h1><span class="glass name" aria-hidden="true">My work</span>
36
- <div class="tools tools-top"><span class="snap" id="snap">Reading your list</span>
37
- <a class="glass round" id="toConsole" href="/console.html" aria-label="Open the console" title="Open the console"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="m7 9 3 3-3 3M13 15h4"/></svg></a>
38
- <button class="glass round sbtn" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions" title="Agent sessions"><svg class="i" viewBox="0 0 24 24"><path d="M4 6h16M4 12h10M4 18h6"/><circle cx="18" cy="16" r="3"/></svg><span class="sbdg" id="sessBdg" aria-hidden="true" hidden></span></button>
39
- <button class="glass round" id="settingsBtn" aria-label="Settings" title="Settings"><svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6 7 7M17 17l1.4 1.4M5.6 18.4 7 17M17 7l1.4-1.4"/></svg></button>
40
- <button class="glass round" id="theme" aria-label="Switch light or dark"><svg class="i" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg></button></div>
35
+ <h1 class="vh">My work</h1><div class="where"><span class="glass name" aria-hidden="true">My work</span><button class="round tbchat" id="pgChat" aria-haspopup="dialog" aria-label="Ask about this page" title="Ask about this page"></button></div>
36
+ <div class="tools tools-top"><span class="vh" id="snap">Reading your list</span></div>
41
37
  </header>
42
38
  <section class="hero">
43
39
  <p class="date rise" style="--d:1" id="date"></p>
@@ -42,13 +42,9 @@
42
42
  <div class="toast glass" id="toast" role="status"></div>
43
43
  <main class="stage" id="stage">
44
44
  <header class="top rise" style="--d:0">
45
- <h1 class="vh">Briefing</h1><span class="glass name" aria-hidden="true">Briefing</span>
46
- <div class="tools tools-top"><span class="snap" id="snap">Reading the repository</span>
47
- <span class="pkw" id="pkw" hidden><button class="fchip" id="pick" aria-haspopup="menu" aria-expanded="false" aria-controls="pickMenu">Products<em id="pickN"></em></button><div class="crmenu pkmenu" id="pickMenu" role="menu" hidden></div></span>
48
- <a class="glass round" id="toConsole" href="/console.html" aria-label="Open the console" title="Open the console"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="m7 9 3 3-3 3M13 15h4"/></svg></a>
49
- <button class="glass round sbtn" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions" title="Agent sessions"><svg class="i" viewBox="0 0 24 24"><path d="M4 6h16M4 12h10M4 18h6"/><circle cx="18" cy="16" r="3"/></svg><span class="sbdg" id="sessBdg" aria-hidden="true" hidden></span></button>
50
- <button class="glass round" id="settingsBtn" aria-label="Settings" title="Settings"><svg class="i" viewBox="0 0 24 24"><circle cx="12" cy="12" r="3"/><path d="M12 3v2M12 19v2M3 12h2M19 12h2M5.6 5.6 7 7M17 17l1.4 1.4M5.6 18.4 7 17M17 7l1.4-1.4"/></svg></button>
51
- <button class="glass round" id="theme" aria-label="Switch light or dark"><svg class="i" viewBox="0 0 24 24"><path d="M20 14.5A8 8 0 0 1 9.5 4 8 8 0 1 0 20 14.5z"/></svg></button></div>
45
+ <h1 class="vh">Briefing</h1><div class="where"><span class="glass name" aria-hidden="true">Briefing</span><button class="round tbchat" id="pgChat" aria-haspopup="dialog" aria-label="Ask about this page" title="Ask about this page"></button></div>
46
+ <div class="tools tools-top"><span class="vh" id="snap">Reading the repository</span>
47
+ <span id="pkPark" hidden><span class="pkw" id="pkw" hidden><button class="fchip" id="pick" aria-haspopup="menu" aria-expanded="false" aria-controls="pickMenu">Products<em id="pickN"></em></button><div class="crmenu pkmenu" id="pickMenu" role="menu" hidden></div></span></span></div>
52
48
  </header>
53
49
  <section class="hero">
54
50
  <p class="date rise" style="--d:1" id="date"></p>
@@ -2492,7 +2492,7 @@ function fireSchedule(sched, opts = {}) {
2492
2492
  const rsm = require('./lib/routes-report-structure.js');
2493
2493
  const sp = rsm.savedPlan(root, String(sched.args)); if (sp) structured = { id: String(sched.args), saved: sp.n };
2494
2494
  if (opts.release) prompt += rsm.draftBlock(root, String(sched.args), { note: opts.note || null });
2495
- else { const gate = rsm.beforeDraft(reportStructureCtx(), w, String(sched.args), sched); if (gate.hold) held = true; else prompt += gate.block || ''; }
2495
+ else { const gate = rsm.beforeDraft(reportStructureCtx(), w, String(sched.args), sched, { scheduled: !!opts.scheduled }); if (gate.hold) held = true; else prompt += gate.block || ''; }
2496
2496
  } catch (e) { warnWriteFail('report structure (draft gate)', e); }
2497
2497
  }
2498
2498
  // The schedule's recorded profile travels with the process it creates (profiles R8.3). Only an
@@ -2552,7 +2552,8 @@ function fireSchedule(sched, opts = {}) {
2552
2552
  }
2553
2553
  function checkDueSchedules() {
2554
2554
  let fired = 0;
2555
- for (const s of readSchedules()) { try { if (scheduleLogic.isDue(s)) { fireSchedule(s); fired++; } } catch {} }
2555
+ // A fire from this tick is `scheduled`: the source checks of a structured report's draft start through the capacity governor (run-now is a press).
2556
+ for (const s of readSchedules()) { try { if (scheduleLogic.isDue(s)) { fireSchedule(s, { scheduled: true }); fired++; } } catch {} }
2556
2557
  // R11 — a one-off whose moment passed while nothing was running is marked missed and off, never caught up.
2557
2558
  try {
2558
2559
  const list = readSchedules(); let changed = false;
@@ -2583,7 +2584,9 @@ const dashboardScheduleTick = () => {
2583
2584
  // window, and starts its short headless runs. Everything it decides is in lib/driver.js; this only hands it the server's parts.
2584
2585
  // agent-orchestrator: the capacity governor in front of every run the orchestrator may start. The Driver asks it before each start; the status route reads it.
2585
2586
  // PMOS_TICK_MS is the suites' fast clock: a suite runs beside forty others, so the machine-load check is skipped there (the rest of the gate applies).
2586
- const orchGate = require('./lib/orchestrator-gate.js').create({ dir: STATE, ...(process.env.PMOS_TICK_MS ? { load: () => null } : { defaultBackupDir: path.join(require('os').homedir(), 'pmos-backups') }) });
2587
+ // The quota reading is the usage-limit hold a failed headless run left (lib/orchestrator-quota.js; set where a headless run ends, startHeadless).
2588
+ const orchQuota = require('./lib/orchestrator-quota.js');
2589
+ const orchGate = require('./lib/orchestrator-gate.js').create({ dir: STATE, quota: () => orchQuota.gateQuota(STATE), ...(process.env.PMOS_TICK_MS ? { load: () => null } : { defaultBackupDir: path.join(require('os').homedir(), 'pmos-backups') }) });
2587
2590
  const driver = driverRunLib.create({
2588
2591
  mayStart: ({ running }) => orchGate.mayStart({ running }),
2589
2592
  started: () => orchGate.granted(),
@@ -2621,7 +2624,7 @@ const orchKeepRate = () => {
2621
2624
  const orchHealth = () => {
2622
2625
  const backupLib = require('./lib/state-backup.js'), log = backupLib.readLog(STATE);
2623
2626
  return require('./lib/orchestrator-health.js').rows({ now: Date.now(), stopped: orchGate.status({}).stopped, lastTickAt: orchLastTickAt, tickMs: TICK_MS,
2624
- diskFreeFrac: require('./lib/orchestrator-health.js').diskFreeFrac(STATE), loginHeld: driver.loginHeld(),
2627
+ diskFreeFrac: require('./lib/orchestrator-health.js').diskFreeFrac(STATE), loginHeld: driver.loginHeld(), quotaHold: orchQuota.read(STATE),
2625
2628
  backup: { configured: !!orchGate.backupDir(), lastOkAt: log.lastOkAt, lastError: log.lastError, isDefault: orchGate.backupIsDefault(), dir: orchGate.backupDir() }, pause: orchKeepRate().pause });
2626
2629
  };
2627
2630
  // agent-orchestrator: the Checker. One read-only run per ended Driver run with open drafts, started through the gate, one start per tick.
@@ -2713,8 +2716,10 @@ const reportFinder = reportFinderLib.create({
2713
2716
  });
2714
2717
  // report-design-studio: a cycle drafted for a report whose design is saved is rendered to match it. A draft written in this process starts its job at
2715
2718
  // once (lib/routes-report-design.js listens to report-draft.js writeDraft); this tick catches a draft the `pmos report draft` CLI wrote (the schedule).
2719
+ // agent-orchestrator: the render the sweep starts uses spawnScheduled (the capacity governor); a held start is tried again on the next tick. A press uses spawnSession.
2716
2720
  const reportDesignCtx = () => ({ getWs, workspaceList: () => [...workspaces.values()], runtimeDir: STATE,
2717
2721
  spawnSession: (spec) => spawnSession({ ...spec, autoDelete: undefined }),
2722
+ spawnScheduled: (spec) => orchSpawn.spawn({ ...spec, autoDelete: undefined }),
2718
2723
  skillPrompt: (skillId, w) => { const t = taskById(skillId, w ? w.root : SELF_ROOT); return t && t.prompt ? t.prompt : null; },
2719
2724
  stopSession: (id) => { const x = sessions.get(String(id || '')); if (x && x.child) stopHeadless(x); } });
2720
2725
  const reportDesignTick = () => {
@@ -2724,9 +2729,11 @@ const reportDesignTick = () => {
2724
2729
  try { require('./lib/routes-report-design.js').attach(reportDesignCtx); } catch { /* a checkout without the module still starts */ }
2725
2730
  // report-structure: the structure jobs, the source checks (interactive sessions started like Work's approved steps, STEP_FLAGS) and the draft gate.
2726
2731
  // The tick collects check answers and starts the drafts that waited for a failing source (4 hours, then without it).
2732
+ // agent-orchestrator: the checks of a draft the schedule tick fired, and the tick's retries of them, use spawnScheduled (the capacity governor). A press uses spawnSession.
2727
2733
  const reportStructureCtx = () => ({ getWs, workspaceList: () => [...workspaces.values()], runtimeDir: STATE, stepFlags: STEP_FLAGS,
2728
2734
  scheduleStore: { read: readSchedules, write: writeSchedules }, sessionAlive: (id) => { const x = sessions.get(String(id || '')); return !!x && x.state !== 'exited'; },
2729
2735
  spawnSession: (spec) => spawnSession({ ...spec, autoDelete: undefined }),
2736
+ spawnScheduled: (spec) => orchSpawn.spawn({ ...spec, autoDelete: undefined }),
2730
2737
  skillPrompt: (skillId, w) => { const t = taskById(skillId, w ? w.root : SELF_ROOT); return t && t.prompt ? t.prompt : null; },
2731
2738
  stopSession: (id) => { const x = sessions.get(String(id || '')); if (x && x.child) stopHeadless(x); },
2732
2739
  // a check session is a pane: end it when its answer is in (the skill closes its tab and stops; this is the backstop)
@@ -3758,7 +3765,7 @@ function sendToSession(id, text) {
3758
3765
  * session's state keeps working; it has no pty and no tmux, and `child` is the process. The log is read-only. */
3759
3766
  function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDirs, onDone, writePaths) {
3760
3767
  const prompt = safeFirstInput(String(initialInput).replace(/\r+$/, ''));
3761
- // report-design-studio: writePaths names the one render file a report-design run may write (lib/headless.js ignores it for every other kind).
3768
+ // report-design-studio: writePaths names the one render file a report-design run may write; for a skill run, the folders it may write in (lib/headless.js ignores it for every other kind).
3762
3769
  const args = headlessLib.argsFor(kind, { modelArgs: launchArgs, addDirs: Array.isArray(addDirs) ? addDirs : [], writePaths: Array.isArray(writePaths) ? writePaths : [] });
3763
3770
  const s = { ...base, cwd: workdir, state: 'working', pty: null, tmux: null, headless: kind, child: null,
3764
3771
  note: '', buf: '', cols: 80, rows: 24, clients: new Set(), created: nowISO(), lastOutputAt: Date.now() };
@@ -3829,6 +3836,11 @@ function startHeadless(base, workdir, kind, launchArgs, env, initialInput, addDi
3829
3836
  s.outcome = headlessLib.outcomeOf(r, { code, signal, timedOut, stopped: !!s.stoppedByPm, timeoutMin });
3830
3837
  if (!s.outcome.ok && err.trim() && !r.ok) s.outcome.why += ' ' + err.trim().split('\n').filter(Boolean).pop().slice(0, 200);
3831
3838
  if (s.note !== 'exited (code 0)') say(`\x1b[38;5;203m[${s.note}]\x1b[0m\n`);
3839
+ // agent-orchestrator: a failed run that hit the Claude usage limit holds new orchestrator starts until the reset it names (lib/orchestrator-quota.js).
3840
+ // Only a failed run is read, so a run whose answer is about rate limits sets no hold.
3841
+ if (!timedOut && !s.stoppedByPm && (code !== 0 || !r.ok || r.isError)) {
3842
+ try { const hold = orchQuota.detect([r.isError || !r.ok ? r.text : '', err.slice(-4000), resultLine ? '' : out.slice(-4000)].join('\n')); if (hold) orchQuota.record(STATE, hold); } catch (e) { warnWriteFail('usage-limit hold', e); }
3843
+ }
3832
3844
  persist(s); pushSessions();
3833
3845
  // page-starts-agent: a caller that started this run from the page reads its result here (a proposal, never a write).
3834
3846
  // A caller may answer { failed: why } when the run ended without doing its job (a core-doc run that wrote no draft): the run then
@@ -3995,6 +4007,16 @@ function spawnSessionInner({ name, agent, cwd, ws, origin, initialInput, profile
3995
4007
  // ── the headless path (workspace-headless-jobs): a background job that needs no human runs as `claude -p`, with
3996
4008
  // no pane, the same environment and model, a fixed tool list and the prompt on stdin (lib/headless.js says which).
3997
4009
  const hkind = initialInput ? headlessLib.kindFor({ agent, origin: tag, skill: modelAsk && modelAsk.skill }) : null;
4010
+ // A background skill run reads untrusted text, so it writes only in a scratch folder of its own and in the state folders its skill writes
4011
+ // (lib/headless.js skillWriteDirs). The prompt names the scratch folder, and the folder is removed when the run ends.
4012
+ if (hkind === 'skill') {
4013
+ let dir = null;
4014
+ try { dir = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'pmos-skill-'))); } catch { /* no scratch folder: the run writes only its state folders */ }
4015
+ if (dir) { base.scratchDir = dir; initialInput = String(initialInput).replace(/\r+$/, '') + `\n\nThis session's scratch folder is ${dir}. Write temporary files there only; it is removed when the run ends.`; }
4016
+ let repo = workdir; try { repo = fs.realpathSync(workdir); } catch { /* keep the path as given */ }
4017
+ return startHeadless(base, workdir, hkind, argv, penv, initialInput, [...(Array.isArray(addDirs) ? addDirs : []), ...(dir ? [dir] : [])], onDone,
4018
+ headlessLib.skillWriteDirs(modelAsk && modelAsk.skill, { root: repo, scratch: dir }));
4019
+ }
3998
4020
  if (hkind) return startHeadless(base, workdir, hkind, argv, penv, initialInput, addDirs, onDone, writePaths);
3999
4021
 
4000
4022
  // ── the tmux path: the process outlives this server, and we re-attach to it live (R7) ──
@@ -1,13 +1,15 @@
1
1
  {
2
- "_comment": "agent-orchestrator: the keep-rate report (the success measure), the advisory Checker and the tool lists of the reading workers (node, no server).",
2
+ "_comment": "agent-orchestrator: the keep-rate report (the success measure), the advisory Checker, the tool lists of the reading workers and the usage-limit hold that is the governor's quota reading (node, no server).",
3
3
  "modules": [
4
4
  "orchestrator-keeprate.test.js",
5
5
  "orchestrator-checker.test.js",
6
- "orchestrator-readers.test.js"
6
+ "orchestrator-readers.test.js",
7
+ "orchestrator-quota.test.js"
7
8
  ],
8
9
  "seconds": {
9
10
  "orchestrator-keeprate.test.js": 1,
10
11
  "orchestrator-checker.test.js": 1,
11
- "orchestrator-readers.test.js": 1
12
+ "orchestrator-readers.test.js": 1,
13
+ "orchestrator-quota.test.js": 1
12
14
  }
13
15
  }