create-pmos 0.344.0 → 0.346.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.
@@ -14,6 +14,7 @@ const guard = require('./pm-guard.js');
14
14
  const Wr = require('./briefing-premium-writes.js');
15
15
  const Ag = require('./briefing-premium-agent.js');
16
16
  const Goal = require('./goal-chat.js');
17
+ const Inbox = require('./agent-inbox.js');
17
18
  const actor = require('./actor.js');
18
19
  const WP = require('./my-work-premium.js');
19
20
  const BoardP = require('./board-premium.js');
@@ -106,6 +107,7 @@ async function post(req, res, url, ctx) {
106
107
  }
107
108
 
108
109
  module.exports = {
110
+ products,
109
111
  prefixes: ['/api/briefing-premium'],
110
112
  handle: async (req, res, url, ctx) => {
111
113
  if (url.pathname === '/api/briefing-premium/goal-stop') {
@@ -139,8 +141,8 @@ module.exports = {
139
141
  const sel = products(ctx);
140
142
  const sources = await Src.readSources(ctx, Date.now()).catch(() => null);
141
143
  const agent = Drafts.readDrafts(sel.available);
142
- const r = await Prod.modelOfMany({ available: sel.available, engine: enginePath(), runtimeDir: ctx.runtimeDir, sources, agent });
143
- if (r.model && ctx.runtimeDir) r.model = Goal.withGoalRows(r.model, Goal.briefingRows(ctx.runtimeDir)); // premium-chat-session U7: goals read live, not cached
144
+ const r = await Prod.modelOfMany({ available: sel.available, engine: enginePath(), runtimeDir: ctx.runtimeDir, sources, agent, agentAside: true });
145
+ if (r.model) r.model = Inbox.split(r.model, ctx.runtimeDir ? Goal.goalRowsAt(ctx.runtimeDir) : []); // premium-chat-session U7: goals read live, not cached; premium-agent-inbox: they and the drafts go to the bell
144
146
  ctx.json(res, r.state === 'error' ? { ok: false, ...r } : { ok: true, ...r }, r.state === 'ready' ? 200 : r.state === 'reading' ? 202 : 500);
145
147
  return true;
146
148
  }
@@ -148,7 +150,7 @@ module.exports = {
148
150
  try { const w = ctx.getWs && ctx.getWs(url.searchParams.get('ws') || null); root = w && w.root; } catch { root = null; }
149
151
  root = root || path.resolve(__dirname, '..', '..');
150
152
  const r = await BP.modelOf({ root, engine: enginePath(), runtimeDir: ctx.runtimeDir });
151
- if (r.model && ctx.runtimeDir) r.model = Goal.withGoalRows(r.model, Goal.briefingRows(ctx.runtimeDir));
153
+ if (r.model) r.model = Inbox.split(r.model, ctx.runtimeDir ? Goal.goalRowsAt(ctx.runtimeDir) : []);
152
154
  // 200 with the model, 202 while the first read goes on, 500 with the reason when a read failed
153
155
  ctx.json(res, r.state === 'error' ? { ok: false, ...r } : { ok: true, ...r }, r.state === 'ready' ? 200 : r.state === 'reading' ? 202 : 500);
154
156
  return true;
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+ /* routes-inbox.js — the bell's inbox of agent results that wait on the PM (initiative premium-agent-inbox).
3
+ *
4
+ * GET /api/inbox → { ok, count, newCount, items, more, bundles, oldest, seenAt } lib/agent-inbox.js build()
5
+ * POST /api/inbox/seen { ids } | { all } → { ok } one line in <runtime>/inbox-seen.jsonl, a page press only (pm-guard requirePagePress)
6
+ *
7
+ * The read takes the products the premium Briefing reads (routes-briefing-premium products), their Driver ledgers and the goal rows.
8
+ * Seen is not done: an item goes only when its record changes. Nothing here decides a proposal or sends anything. */
9
+ const guard = require('./pm-guard.js');
10
+ const Inbox = require('./agent-inbox.js');
11
+ const Goal = require('./goal-chat.js');
12
+
13
+ module.exports = {
14
+ prefixes: ['/api/inbox'],
15
+ handle: async (req, res, url, ctx) => {
16
+ if (url.pathname === '/api/inbox/seen') {
17
+ if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
18
+ const got = await ctx.readJson(req);
19
+ if (!got.ok) { ctx.json(res, { ok: false, error: 'invalid JSON body' }, 400); return true; }
20
+ const b = got.body || {};
21
+ const g = guard.requirePagePress(req, b);
22
+ if (!g.ok) { ctx.json(res, { ok: false, error: g.error }, g.status); return true; }
23
+ const err = Inbox.badSeen(b);
24
+ if (err) { ctx.json(res, { ok: false, error: err }, 400); return true; }
25
+ if (!ctx.runtimeDir) { ctx.json(res, { ok: false, error: 'no runtime folder' }, 500); return true; }
26
+ Inbox.appendSeen(ctx.runtimeDir, b);
27
+ ctx.json(res, { ok: true });
28
+ return true;
29
+ }
30
+ if (url.pathname !== '/api/inbox') return false;
31
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
32
+ const { products } = require('./routes-briefing-premium.js');
33
+ let available = [];
34
+ try { available = products(ctx).available; } catch { available = []; }
35
+ const out = Inbox.build({
36
+ proposals: Inbox.readProposals(available),
37
+ goals: ctx.runtimeDir ? Goal.goalRowsAt(ctx.runtimeDir) : [],
38
+ seen: ctx.runtimeDir ? Inbox.readSeen(ctx.runtimeDir) : undefined,
39
+ now: Date.now(),
40
+ });
41
+ ctx.json(res, { ok: true, ...out });
42
+ return true;
43
+ },
44
+ };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.344.0",
3
+ "version": "0.346.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.344.0",
9
+ "version": "0.346.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.344.0",
3
+ "version": "0.346.0",
4
4
  "private": true,
5
5
  "description": "PMOS Terminal Workspace — local companion hosting real PTYs beside the library and gates (D62)",
6
6
  "license": "MIT",
@@ -191,7 +191,10 @@ const BRIEFING = { ok: true, items: [{ title: 'Refund reason codes needs an anch
191
191
  await heading(A.page, /Welcome to PMOS/);
192
192
  await mp.close(); mp = await (await mkOf(w, th)).newPage(); await mp.goto('file://' + mockupFile); await CT.applyToPage(mp, CT_VENDOR); await mp.evaluate((t) => { document.documentElement.dataset.theme = t; }, th); await mp.waitForTimeout(500);
193
193
  const diffs = [];
194
- for (const [name, sel, props] of CMP) { const a = await css(A.page, sel, props), m = await css(mp, sel, props); if (a !== m) diffs.push(`${name}: ${a} vs ${m}`); }
194
+ // on a touch phone a text field is 16 px so focus does not zoom the page (premium.css); the mockup's 14 px and its line height do not apply there
195
+ const TOUCH = w === 390 ? { '.wl-f input': ['fontSize'], '.wl-f textarea': ['lineHeight'] } : {};
196
+ for (const [name, sel, all] of CMP) { const props = all.filter((k) => !(TOUCH[sel] || []).includes(k)); const a = await css(A.page, sel, props), m = await css(mp, sel, props); if (a !== m) diffs.push(`${name}: ${a} vs ${m}`); }
197
+ if (w === 390) diffs.push(...(await A.page.evaluate(() => ['.wl-f input', '.wl-f textarea'].map((s) => getComputedStyle(document.querySelector(s)).fontSize).filter((f) => f !== '16px').map((f) => 'a text field on a touch phone: ' + f))));
195
198
  ok(`R11 fidelity at ${w} px (${th}): About you keeps the mockup's type, radii, colours and sizes`, diffs.length === 0, diffs.join(' ; '));
196
199
  const scrolls = [];
197
200
  const floor = async (label) => scrolls.push(await A.page.evaluate((l) => ({ l, scroll: document.documentElement.scrollWidth <= innerWidth + 1, btn: [...document.querySelectorAll('#wlCard button, #wlSkip')].filter((b) => b.offsetParent).map((b) => Math.round(b.getBoundingClientRect().height)) }), label));
@@ -17,6 +17,17 @@ export function looksFile(t) {
17
17
  if (!/\.[A-Za-z0-9]{1,10}$/.test(s)) return false;
18
18
  return s.includes('/') || DOC_EXT.test(s);
19
19
  }
20
+ /* A Claude artifact, a Google Doc, Sheet or Slides file, or a Confluence page opens beside the conversation too (PM, 2026-10-20: "Claude artefact should
21
+ * also can be clicked and show on the detail panel … As well as Google docs link, confluence link"). The link keeps its address, so a new-tab open still works. */
22
+ /** 'artifact' | 'google' | 'confluence' | null for an (escaped) http(s) address. Pure. */
23
+ export function webKind(u) {
24
+ const s = String(u || '').replace(/&amp;/g, '&');
25
+ if (/^https:\/\/claude\.ai\/(code\/)?artifact\/[\w-]+/i.test(s)) return 'artifact';
26
+ if (/^https:\/\/(docs|drive)\.google\.com\//i.test(s)) return 'google';
27
+ if (/^https:\/\/[\w.-]+\.atlassian\.net\/wiki\//i.test(s) || /^https?:\/\/[^/\s]+\/(wiki|confluence)\/.*(pages|display|viewpage|spaces)/i.test(s)) return 'confluence';
28
+ return null;
29
+ }
30
+ const link = (u, txt) => { const k = webKind(u); return `<a href="${u}" target="_blank" rel="noopener noreferrer"${k ? ` data-web="${k}"` : ''}>${txt}</a>`; };
20
31
  const fileBtn = (p, label) => `<button type="button" class="fpath" data-file="${p}" title="Open ${p} beside the conversation">${label}</button>`;
21
32
 
22
33
  /** One line's inline marks, on text that is already escaped: `code`, [links](https://…), bare URLs, file paths, **bold**, *italic*, ~~struck~~. */
@@ -24,9 +35,10 @@ function inline(t) {
24
35
  const keep = [];
25
36
  const hold = (h) => '\u0000' + (keep.push(h) - 1) + '\u0000';
26
37
  let s = t.replace(/`([^`]+)`/g, (_, c) => hold(looksFile(c.trim()) ? fileBtn(c.trim(), `<code>${c}</code>`) : `<code>${c}</code>`));
27
- s = s.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, (_, txt, u) => hold(`<a href="${u}" target="_blank" rel="noopener noreferrer">${txt}</a>`));
38
+ s = s.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, (_, txt, u) => hold(link(u, txt)));
39
+ s = s.replace(/&lt;(https?:\/\/[^\s<>]+?)&gt;/g, (_, u) => hold(link(u, u)));
28
40
  s = s.replace(/\[([^\]]+)\]\(([^\s)]+)\)/g, (m, txt, u) => (looksFile(u) ? hold(fileBtn(u, txt)) : m));
29
- s = s.replace(/(^|[\s(])(https?:\/\/[^\s<]+[^\s<.,;:!?)])/g, (_, pre, u) => pre + hold(`<a href="${u}" target="_blank" rel="noopener noreferrer">${u}</a>`));
41
+ s = s.replace(/(^|[\s(])(https?:\/\/[^\s<]+[^\s<.,;:!?)])/g, (_, pre, u) => pre + hold(link(u, u)));
30
42
  s = s.replace(/(^|[\s(])((?:~|\.{1,2})?\/[^\s<()]*[^\s<().,;:!?])/g, (m, pre, u) => (looksFile(u) ? pre + hold(fileBtn(u, u)) : m));
31
43
  s = s.replace(/(\*\*|__)(?=\S)([\s\S]*?\S)\1/g, '<strong>$2</strong>')
32
44
  .replace(/(^|[^*\w])\*(?=\S)([^*]*?\S)\*(?!\*)/g, '$1<em>$2</em>')
@@ -2,11 +2,11 @@
2
2
  import { pmGet, pmPost } from './http.js';
3
3
  import { recChipView, STOP_LINE } from './premium-meeting.js';
4
4
  import { vwReset } from './premium-viewer.js';
5
- import { openChatFile } from './premium-vw-file.js';
5
+ import { openChatFile, openWebLink } from './premium-vw-file.js';
6
6
  import { chipActs, openLive, openFocus, mountRecord, HL_LINE } from './premium-vw-rec.js';
7
7
  import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words.js';
8
8
  import { splitGoal, shownUser, goalBlockHtml, goalProgressHtml, slashMatches } from './goal-chat.js';
9
- import { mdHtml, userHtml, toolLine } from './chat-md.js';
9
+ import { mdHtml, userHtml, toolLine, webKind } from './chat-md.js';
10
10
  export const $ = (s, r = document) => r.querySelector(s);
11
11
  export const $$ = (s, r = document) => [...r.querySelectorAll(s)];
12
12
  export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
@@ -163,7 +163,14 @@ tbMount(); // the top bar first: the menu holds the Settings, Agent sessions,
163
163
 
164
164
  /* ── toast ──────────────────────────────────────────────────────────────────────────────────────────────── */
165
165
  let tt = null;
166
- export function toast(msg) { const t = $('#toast'); t.textContent = msg; t.classList.add('on'); clearTimeout(tt); tt = setTimeout(() => t.classList.remove('on'), 4200); }
166
+ export function toast(msg, act) {
167
+ const t = $('#toast'); t.textContent = msg; t.classList.add('on'); clearTimeout(tt);
168
+ if (act) { // premium-agent-inbox: one action on the toast (the bell's "Review"), kept a little longer so it can be pressed
169
+ const b = document.createElement('button'); b.type = 'button'; b.className = 'cta'; b.textContent = act.label;
170
+ b.onclick = () => { t.classList.remove('on'); act.fn(); }; t.appendChild(b);
171
+ }
172
+ tt = setTimeout(() => t.classList.remove('on'), act ? 9000 : 4200);
173
+ }
167
174
 
168
175
  /* ── the standard dialog: detail first, the conversation beside it (Detail tab first on a phone) ─────────── */
169
176
  export const kv = (rows) => `<div class="kv2">${rows.filter((r) => r && r[1]).map(([k, v]) => `<span>${esc(k)}</span><span>${esc(v)}</span>`).join('')}</div>`;
@@ -307,6 +314,16 @@ $('#dBody').addEventListener('click', (e) => {
307
314
  openChatFile(f.dataset.file, { session: S.session || null, ws: new URLSearchParams(location.search).get('ws') });
308
315
  if (innerWidth < 1000) setTab('out');
309
316
  });
317
+ /* a Claude artifact, Google Doc or Confluence link in the conversation or in a page the viewer shows opens as a viewer tab too; other links open a new tab */
318
+ const onWebLink = (e) => {
319
+ const a = e.target.closest('a[href]'); if (!a || e.metaKey || e.ctrlKey || e.shiftKey || e.button) return;
320
+ if (!a.closest('#dBody .md, #dOut .cfb, #dOut .cpv-page')) return; // Claude's words and a page's own text; a view's Open in buttons keep opening the tool
321
+ const k = webKind(a.getAttribute('href')); if (!k) return;
322
+ e.preventDefault();
323
+ openWebLink(a.getAttribute('href'), k, a.textContent.trim(), { ws: new URLSearchParams(location.search).get('ws') });
324
+ if (innerWidth < 1000) setTab('out');
325
+ };
326
+ $('#dBody').addEventListener('click', onWebLink); $('#dOut').addEventListener('click', onWebLink);
310
327
  /* /goal (slice 2): a chip sends its answer; Start and Cancel are the PM's presses on the goal card; Change something hands the box back. */
311
328
  async function sendText(key, text) {
312
329
  const go = $('#askGo'); if (go) go.disabled = true; $('#askNote').textContent = 'Sending.';
@@ -499,19 +516,26 @@ const PV_WS = new URLSearchParams(location.search).get('ws');
499
516
  const pvQ = (sep) => (PV_WS ? sep + 'ws=' + encodeURIComponent(PV_WS) : '');
500
517
  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 }; } }
501
518
  const pvOv = { kind: null, back: null, at: 0, list: [], pal: null, need: null };
519
+ /* the bell's inbox (initiative premium-agent-inbox): r is the last GET /api/inbox answer, ids the item ids it held (null before the first read, so the
520
+ * first read never toasts), shown the new ids the open panel shows (closing the panel marks them seen), toastAt the last toast (at most one per 15 min). */
521
+ const IB = { r: null, ids: null, shown: [], toastAt: 0 };
502
522
  function pvMount() {
503
523
  const a = $('#tbMore'); if (!a || $('#pvBell')) return;
504
524
  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>`);
505
525
  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>');
506
526
  $('#pvSearch').onclick = () => pvOpen('pal'); $('#pvBell').onclick = () => pvOpen('bell'); $('#pvScrim').onclick = pvClose;
507
- pvNeeds();
527
+ pvNeeds(); ibRead();
528
+ setInterval(() => { if (!document.hidden) ibRead(); }, 60000);
529
+ document.addEventListener('visibilitychange', () => { if (!document.hidden) ibRead(); });
508
530
  }
509
531
  export function pvClose() {
510
532
  if (!pvOv.kind) return;
533
+ if (pvOv.kind === 'bell' && IB.shown.length) { const ids = IB.shown.slice(0, 100); IB.shown = []; pmPost('/api/inbox/seen', { ids }).then(ibRead); } // seen is not done: they move to Still waiting
511
534
  pvOv.kind = null; $('#pvOv').hidden = true; $('#pvOv').inert = true; $('#pvScrim').classList.remove('on');
512
535
  $$('.rail,main.stage,#dock').forEach((x) => { x.inert = false; }); $('#dock').inert = !document.body.classList.contains('docked'); document.documentElement.style.overflow = '';
513
536
  if (pvOv.back) { try { pvOv.back.focus(); } catch { /* gone */ } }
514
537
  }
538
+ export const pvOpenBell = () => pvOpen('bell');
515
539
  function pvOpen(kind) {
516
540
  if (pvOv.kind === kind) { pvClose(); return; }
517
541
  if (pvOv.kind) pvClose();
@@ -520,7 +544,7 @@ function pvOpen(kind) {
520
544
  $$('.rail,main.stage,#dock').forEach((x) => { x.inert = true; }); document.documentElement.style.overflow = 'hidden';
521
545
  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');
522
546
  if (kind === 'pal') { o.innerHTML = '<div class="pv-pin">' + SRCH + '<input id="pvQ" type="text" placeholder="Search places, initiatives, documents and sessions" aria-label="Search" autocomplete="off" role="combobox" aria-expanded="true" aria-controls="pvList"><kbd>Esc</kbd></div><div id="pvList" role="listbox" aria-label="Results"></div><p class="pv-note">Ctrl K or / opens this from any page. Arrow keys move, Enter opens.</p>'; $('#pvQ').focus(); pvPal(); }
523
- else { o.innerHTML = '<div class="pv-hd"><h2>Needs you</h2><small id="pvN"></small></div><div id="pvList" class="pv-lst"></div><p class="pv-note">Read from the Briefing. A press opens it.</p>'; pvBellDraw(); pvNeeds(); }
547
+ else { o.innerHTML = '<div class="pv-hd"><h2>Needs you</h2><small id="pvN"></small><button type="button" class="ib-all" id="ibAll" hidden>Mark all seen</button></div><div id="pvList" class="pv-lst"></div>'; pvBellDraw(); pvNeeds(); ibRead(); }
524
548
  }
525
549
  const pvGo = (it) => { pvClose(); if (it.go) location.assign(it.go); };
526
550
  const pvRow = (it, i, sel) => `<button type="button" class="pv-row" role="option" id="pvo${i}" data-i="${i}" aria-selected="${sel}"><span class="gl">${GL[it.gl]}</span><span><b>${esc(it.t)}</b>${it.s ? `<small>${esc(it.s)}</small>` : ''}</span></button>`;
@@ -551,13 +575,54 @@ function pvPalDraw() {
551
575
  export function pvFeed(r) {
552
576
  const M = r && r.ok && r.model, L = M && M.list;
553
577
  pvOv.need = r && r.state === 'reading' ? { state: 'reading' } : L ? { state: 'ready', count: L.count, rows: L.rows || [] } : { state: 'error' };
554
- const n = pvOv.need, b = $('#pvBdg'), btn = $('#pvBell'); if (!b) return;
555
- const on = n.state === 'ready' && n.count > 0;
556
- b.hidden = !on; b.textContent = on ? (n.count > 99 ? '99+' : String(n.count)) : '';
557
- btn.setAttribute('aria-label', n.state === 'ready' ? 'Needs you: ' + n.count : 'Needs you');
558
578
  if (pvOv.kind === 'bell') pvBellDraw();
559
579
  }
560
- const pvOnBriefing = () => /^\/premium\.html$/.test(location.pathname);
580
+ /* ── the bell's inbox (initiative premium-agent-inbox): one item per agent result that waits on the PM, a press opens that exact proposal or goal ── */
581
+ const IB_KIND = { proposal: 'Proposal', draft: 'Draft', 'goal-waiting': 'Goal needs you', 'goal-done': 'Goal finished', 'goal-stopped': 'Goal stopped' };
582
+ const IB_ACT = { proposal: 'Review', draft: 'Read', 'goal-waiting': 'Answer', 'goal-done': 'See result', 'goal-stopped': 'See why' };
583
+ const IB_GL = { proposal: IC('M4 20h4L19 9l-4-4L4 16zM14 6l4 4'), draft: GL.doc, 'goal-waiting': IC('M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8'), 'goal-done': IC('M5 12l5 5L20 7'), 'goal-stopped': IC('M6 6h12v12H6z') };
584
+ const ibAgo = (ms) => { if (ms == null) return ''; const m = Math.round((Date.now() - ms) / 60000); return m < 1 ? 'just now' : m < 60 ? m + ' min ago' : m < 1440 ? Math.round(m / 60) + ' h ago' : Math.round(m / 1440) + (Math.round(m / 1440) === 1 ? ' day ago' : ' days ago'); };
585
+ const ibOld = (ms) => { if (ms == null) return ''; const d = Math.floor((Date.now() - ms) / 86400000); return d < 1 ? 'oldest is from today' : 'oldest is ' + d + (d === 1 ? ' day old' : ' days old'); };
586
+ /** The deep link of an inbox item or bundle: the Briefing opens it (premium.js openParam). */
587
+ export const ibHref = (open, pws) => '/premium.html?' + ['open=' + encodeURIComponent(open), pws ? 'pws=' + encodeURIComponent(pws) : '', PV_WS ? 'ws=' + encodeURIComponent(PV_WS) : ''].filter(Boolean).join('&');
588
+ /** The last inbox answer, for the Briefing's count line: { count, newCount, oldest } or null. */
589
+ export const ibState = () => IB.r;
590
+ async function ibRead() {
591
+ const { j } = await pvGet('/api/inbox');
592
+ if (!j || !j.ok) return;
593
+ const before = IB.ids; IB.r = j; IB.ids = new Set(j.items.map((i) => i.id));
594
+ const fresh = before ? j.items.filter((i) => !before.has(i.id)) : [];
595
+ const b = $('#pvBdg'), btn = $('#pvBell');
596
+ if (b) { b.hidden = !j.newCount; b.textContent = j.newCount > 99 ? '99+' : String(j.newCount || ''); btn.setAttribute('aria-label', j.newCount ? 'Needs you: ' + j.newCount + ' new from the agent' : 'Needs you'); }
597
+ if (fresh.length && pvOv.kind !== 'bell' && Date.now() - IB.toastAt >= 15 * 60000) { // at most one toast every 15 minutes, bundled; never on a page's first read
598
+ IB.toastAt = Date.now();
599
+ if (fresh.length === 1) toast('New from the agent: ' + fresh[0].title, { label: IB_ACT[fresh[0].kind] || 'Open', fn: () => ibGo(fresh[0].open, fresh[0].pws, fresh[0].id) });
600
+ else toast(fresh.length + ' new agent results', { label: 'Open', fn: () => pvOpen('bell') });
601
+ }
602
+ if (pvOv.kind === 'bell') pvBellDraw();
603
+ document.dispatchEvent(new CustomEvent('pmos:inbox', { detail: j }));
604
+ }
605
+ /** Open an inbox item: on the Briefing in place (premium.js listens), elsewhere by the deep link. The item opened is seen. */
606
+ function ibGo(open, pws, id) {
607
+ if (id) { IB.shown = IB.shown.filter((x) => x !== id); pmPost('/api/inbox/seen', { ids: [id] }); }
608
+ pvClose();
609
+ if (!pvOnBriefing()) { location.assign(ibHref(open, pws)); return; }
610
+ document.dispatchEvent(new CustomEvent('pmos:open', { detail: { open, pws } }));
611
+ }
612
+ function ibHtml() {
613
+ const j = IB.r; if (!j) return '';
614
+ const item = (it) => `<div class="ib-it"><span class="gl">${IB_GL[it.kind] || GL.need}</span><span class="ib-b"><b><span class="ib-k">${esc(IB_KIND[it.kind] || 'Agent')}</span>${esc(it.title)}</b><small>${esc([it.product, it.target ? it.target.title : '', ibAgo(it.at)].filter(Boolean).join(' · '))}</small><span class="ib-acts"><button type="button" class="cta" data-ibo="${esc(it.open)}" data-ibw="${esc(it.pws || '')}" data-ibi="${esc(it.id)}">${esc(IB_ACT[it.kind] || 'Open')}</button>${/^row:/.test(it.open) ? '' : `<button type="button" class="cta alt" data-ibo="row:${esc(it.session)}" data-ibi="${esc(it.id)}">Session</button>`}</span></span></div>`;
615
+ const bun = (x) => `<button type="button" class="pv-row ib-bun" data-ibo="${esc(x.open)}" data-ibw="${esc(x.pws || '')}"><span class="gl">${GL.ini}</span><span><b>${esc(x.title)}</b><small>${esc([x.product, x.sub, ibOld(x.oldest)].filter(Boolean).join(' · '))}</small></span></button>`;
616
+ IB.shown = j.items.map((i) => i.id);
617
+ return (j.items.length ? `<div class="pv-grp">New from the agent · ${j.newCount}</div>` + j.items.map(item).join('') + (j.more ? `<p class="pv-note">${j.more} more new. Mark all seen to fold them by piece of work.</p>` : '') : '')
618
+ + (j.bundles.length ? '<div class="pv-grp">Still waiting · one line per piece of work</div>' + j.bundles.map(bun).join('') : '');
619
+ }
620
+ document.addEventListener('click', (e) => {
621
+ const o = e.target.closest('#pvOv [data-ibo]');
622
+ if (o) { ibGo(o.dataset.ibo, o.dataset.ibw || '', o.dataset.ibi || ''); return; }
623
+ if (e.target.closest('#ibAll')) { IB.shown = []; pmPost('/api/inbox/seen', { all: true }).then((r) => { if (!r || !r.ok) toast('It was not marked seen: ' + ((r && r.error) || 'the server did not answer') + '.'); ibRead(); }); }
624
+ });
625
+ const pvOnBriefing = () => /^\/(?:premium(?:\.html)?|index\.html)?$/.test(location.pathname); // '/' and '/index.html' serve the Briefing too
561
626
  async function pvNeeds() {
562
627
  if (pvOnBriefing()) return;
563
628
  const r = await pvGet('/api/briefing-premium' + pvQ('?'));
@@ -565,12 +630,15 @@ async function pvNeeds() {
565
630
  }
566
631
  function pvBellDraw() {
567
632
  const n = pvOv.need, box = $('#pvList'); if (!box) return;
568
- $('#pvN').textContent = n && n.state === 'ready' ? String(n.count) : '';
569
- if (!n || n.state === 'reading') { box.innerHTML = '<p class="pv-note" role="status">Reading the initiative state. What needs you is not known yet.</p>'; return; }
570
- if (n.state === 'error') { box.innerHTML = '<p class="pv-note" role="status">What needs you could not be read.</p>'; return; }
571
- if (!n.rows.length) { box.innerHTML = '<p class="pv-note" role="status">Nothing needs you.</p>'; return; }
572
- pvOv.list = n.rows.map((r) => ({ gl: 'need', t: r.title, s: r.subject, go: '/premium.html' + pvQ('?') }));
573
- box.innerHTML = pvOv.list.map((it, i) => pvRow(it, i, false).replace('role="option"', 'role="listitem"').replace(' aria-selected="false"', '')).join('') + (n.count > n.rows.length ? `<p class="pv-note">${n.count - n.rows.length} more on the Briefing.</p>` : '');
633
+ const j = IB.r;
634
+ $('#pvN').textContent = j ? String(j.count) : '';
635
+ $('#ibAll').hidden = !(j && j.newCount);
636
+ // the PM's own work stays on the Briefing: one line here says how much, and a press goes there
637
+ const own = !n || n.state === 'reading' ? 'Your own work is still being read.' : n.state === 'error' ? 'Your own work could not be read.' : n.count ? 'Your own work: ' + n.count + (n.count === 1 ? ' item' : ' items') + ' on the Briefing.' : 'Your own work: nothing waits on the Briefing.';
638
+ pvOv.list = [{ gl: 'need', t: own, s: 'What you need to do', go: '/premium.html' + pvQ('?') }];
639
+ box.innerHTML = (!j ? '<p class="pv-note" role="status">Reading what the agent has for you.</p>' : j.count ? ibHtml() : '<p class="pv-note" role="status">No agent result waits on you.</p>')
640
+ + '<div class="pv-grp">Yours</div>' + pvRow(pvOv.list[0], 0, false).replace('role="option"', 'role="listitem"').replace(' aria-selected="false"', '')
641
+ + '<p class="pv-note">An item leaves when you decide it, wherever you decide it. Closing this marks the new ones seen.</p>';
574
642
  }
575
643
  document.addEventListener('click', (e) => { const b = e.target.closest('#pvList .pv-row'); if (b && pvOv.list[+b.dataset.i]) pvGo(pvOv.list[+b.dataset.i]); });
576
644
  document.addEventListener('input', (e) => { if (e.target.id === 'pvQ') { pvOv.at = 0; pvPalDraw(); } });
@@ -25,6 +25,7 @@ export function inl(s) {
25
25
  .replace(/(^|[\s(])[_*]([^_*\s][^_*]*)[_*](?=[\s.,;:)!?]|$)/g, '$1<em>$2</em>')
26
26
  .replace(/~~([^~]+)~~/g, '<s>$1</s>')
27
27
  .replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (m, t, u) => `<a href="${/^(https?:|mailto:|#|\/)/i.test(u.replace(/&amp;/g, '&')) ? u : '#'}"${/^https?:/i.test(u) ? ' target="_blank" rel="noopener"' : ''}>${t}</a>`)
28
+ .replace(/&lt;(https?:\/\/[^\s<>]+?)&gt;/g, '<a href="$1" target="_blank" rel="noopener">$1</a>') // an <https://…> autolink, as GitHub draws it
28
29
  .replace(/(^|[\s(])(\d{4}-\d{2}-\d{2})(?=$|[\s.,;:)])/g, (m, a, d) => (dayOf(d) ? a + dtp(d) : m));
29
30
  return h.replace(/\u0000(\d+)\u0000/g, (m, i) => `<code>${codes[i]}</code>`);
30
31
  }
@@ -9,6 +9,7 @@
9
9
  .vwmut{color:var(--ink-3);font-size:var(--fs-2);margin:0}
10
10
  .vwline{margin:0 0 10px}
11
11
  .vwfnone{margin:8px 0;padding:22px 20px;border:1px dashed var(--hair);border-radius:8px;display:grid;gap:6px;color:var(--ink-2);font-size:var(--fs-3)}
12
+ .vwart .vwbtn{text-decoration:none;justify-self:start}
12
13
  .vwfnone b{font-weight:500;color:var(--ink)}
13
14
  .vwfnone code{font:400 var(--fs-1) var(--mono);color:var(--ink-3);overflow-wrap:anywhere}
14
15
  .vwempty{color:var(--ink-3);font-size:var(--fs-3);padding:24px 4px}
@@ -70,3 +70,22 @@ export function openChatFile(p, ctx = {}) {
70
70
  st.sig = ''; st.f = { loading: true, path: p }; tick();
71
71
  return pane;
72
72
  }
73
+
74
+ /* ── a web link in Claude's words (PM, 2026-10-20): a Google Doc or Confluence page opens in the viewer's copy view (premium-vw-copies.js: what PMOS holds,
75
+ * and Read it now). A Claude artifact cannot be drawn inside PMOS: claude.ai refuses to be shown in another site's frame (frame-ancestors 'self'), and the
76
+ * server never fetches it (D53). Its tab names the artifact and opens it in Claude. ── */
77
+ /** The artifact tab as HTML. Pure. */
78
+ export function artifactHtml(url, label) {
79
+ const name = label && label !== url ? label : 'Claude artifact';
80
+ return `<div class="vwdoc"><div class="vwfnone vwart" role="status"><b>${esc(name)}</b><p class="vwmut">A Claude artifact opens in Claude: claude.ai does not let another site show its pages inside them, so PMOS cannot draw it here.</p>`
81
+ + `<div class="vwrow"><a class="vwbtn pri" href="${esc(url)}" target="_blank" rel="noopener noreferrer">Open in Claude</a></div><code>${esc(url)}</code></div></div>`;
82
+ }
83
+ /** Open a web link beside the conversation. kind is chat-md.js webKind(): 'artifact' | 'google' | 'confluence'. */
84
+ export async function openWebLink(url, kind, label, ctx = {}) {
85
+ if (kind === 'google' || kind === 'confluence') {
86
+ const { openCopy } = await import('./premium-vw-copies.js');
87
+ return openCopy({ ws: ctx.ws || undefined, url, title: label && label !== url ? label : undefined, where: 'linked in the conversation' });
88
+ }
89
+ vwStyle('doc');
90
+ return vwOpen({ id: 'web:' + url, title: label && label !== url ? label : 'Claude artifact', icon: 'doc', render: (el) => { el.innerHTML = artifactHtml(url, label); } });
91
+ }
@@ -359,7 +359,8 @@ a.round{color:inherit;text-decoration:none}
359
359
  /* a phone: the dialog's panes scroll under its title with no edge of their own, so text slid up to the subtitle and read as overlapping it (PM, 2026-10-20).
360
360
  The top of each scrolling pane now fades, and the viewer's tab strip, which stays at the top, carries the dialog's own surface. */
361
361
  .dlg .dgrid .pane{padding-top:12px;-webkit-mask-image:linear-gradient(to bottom,transparent 0,var(--ink) 14px);mask-image:linear-gradient(to bottom,transparent 0,var(--ink) 14px)}
362
- .otop:has(.vtabs:not([hidden])){top:0;padding-top:12px;margin-top:-12px;background:var(--card-solid)}
362
+ .dlg .dgrid .pane:has(.vtabs:not([hidden])){padding-top:0;-webkit-mask-image:none;mask-image:none}
363
+ .otop:has(.vtabs:not([hidden])){top:0;padding-top:4px;background:var(--card-solid)}
363
364
  .obody{padding:0}
364
365
  .paper.doc{padding:2px 0 28px;border:0;box-shadow:none;background:transparent;border-radius:0}
365
366
  .doc .dpath{display:none}}
@@ -1562,6 +1563,26 @@ button.dsn:hover{box-shadow:inset 0 0 0 1.5px rgb(79,109,245)}
1562
1563
  .pv-note{margin:0;padding:10px 14px 4px;color:var(--ink-3);font-size:var(--t-small)}
1563
1564
  @media (max-width:700px){.pv-ov{top:8vh}.pv-ov.bell{right:16px}}
1564
1565
  .pv-row .gl svg{width:20px;height:20px}
1566
+ /* the bell's inbox (initiative premium-agent-inbox): one item per agent result, its main action and its session; the Briefing's count line */
1567
+ .pv-hd .ib-all{margin-left:auto;min-height:44px;padding:0 6px;color:var(--ink-2);font-size:var(--t-small);font-weight:600}
1568
+ .pv-hd .ib-all[hidden]{display:none}
1569
+ .ib-it{display:grid;grid-template-columns:40px minmax(0,1fr);gap:14px;padding:10px 14px;border-radius:var(--r-in)}
1570
+ .ib-it:hover{background:var(--well)}
1571
+ .ib-it .gl{width:40px;height:40px;border-radius:14px;display:grid;place-items:center;background:var(--spot);color:var(--ember-ink)}
1572
+ .ib-it .gl svg{width:20px;height:20px}
1573
+ .ib-b{min-width:0;display:block}
1574
+ .ib-b b{display:block;font-weight:600;line-height:1.35;overflow-wrap:anywhere}
1575
+ .ib-b small{display:block;color:var(--ink-3);font-size:var(--t-small);margin-top:2px;overflow-wrap:anywhere}
1576
+ .ib-k{display:inline-block;margin-right:8px;padding:1px 9px;border-radius:999px;background:var(--spot);color:var(--ember-ink);font-size:var(--t-small);font-weight:600;vertical-align:1px}
1577
+ .ib-acts{display:flex;flex-wrap:wrap;gap:8px;margin-top:10px}
1578
+ .ib-acts .cta.alt{background:var(--well)}
1579
+ .ib-bun b{white-space:normal}
1580
+ .ib-sum{display:flex;align-items:center;gap:16px;margin-top:14px;padding:14px 16px;border-radius:var(--r-in);background:var(--well)}
1581
+ .ib-sum .ib-n{font:600 var(--fs-6) var(--mono);color:var(--ink)}
1582
+ .ib-sum .ib-b{flex:1}
1583
+ .ib-sum .cta{white-space:nowrap}
1584
+ .toast .cta{height:40px;padding:0 16px}
1585
+ @media (max-width:640px){.ib-sum{flex-wrap:wrap}.ib-sum .cta{width:100%}}
1565
1586
  @media (max-width:700px){.top .tools{position:relative}.pkw{position:static}.pkmenu{left:0;right:0;min-width:0}}
1566
1587
  /* Settings dialog rows (initiative premium-settings) */
1567
1588
  .sr{display:flex;align-items:center;justify-content:space-between;gap:12px;min-height:44px;padding:8px 0;border-bottom:1px solid var(--hair)}
@@ -2241,3 +2262,7 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
2241
2262
  .ub{white-space:normal}
2242
2263
  .toolline{display:block;max-width:100%;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font:400 var(--fs-1) var(--mono);color:var(--ink-3);opacity:.85}
2243
2264
  .toolline::before{content:"";display:inline-block;vertical-align:middle;margin:0 8px 2px 0;width:6px;height:6px;border-radius:50%;background:var(--ink-3);opacity:.6}
2265
+
2266
+ /* phone: iOS zooms the whole page in when a text field under 16px gets focus, and leaves it zoomed (send button off the right edge, sheets at
2267
+ * three quarters of the screen). Every text field is 16px on a touch screen, so focus never zooms. */
2268
+ @media (pointer:coarse){input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=button]):not([type=submit]):not([type=reset]):not([type=file]):not([type=color]):not([type=image]),textarea,select{font-size:var(--fs-4)!important}}
@@ -12,7 +12,7 @@ import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words
12
12
  import { consoleReads, briefOf, needsListOf } from './premium-brief.js';
13
13
  import { mountDocSheet } from './premium-doc-sheet.js';
14
14
  import { momentOf, inText } from './c3-phone-model.js';
15
- import { $, $$, esc, store, THEME_KEY, RM, AI, S, theme, toast, kv, H, openDlg, closeDlg, setTab, setMode, setFull, CHECK, CHEV, ptx, turnA, turnU, H1, H2, P1, UL, logHtml, loadThread, onScroll, wireRail, pvFeed, setPageGaps, sourcesHook, onPageChat, openPageChat } from './premium-shell.js';
15
+ import { $, $$, esc, store, THEME_KEY, RM, AI, S, theme, toast, kv, H, openDlg, closeDlg, setTab, setMode, setFull, CHECK, CHEV, ptx, turnA, turnU, H1, H2, P1, UL, logHtml, loadThread, onScroll, wireRail, pvFeed, setPageGaps, sourcesHook, onPageChat, openPageChat, pvOpenBell, ibState } from './premium-shell.js';
16
16
  const ICON = {
17
17
  meeting: '<rect x="4" y="5" width="16" height="15" rx="3"/><path d="M4 10h16M9 3v4M15 3v4"/>',
18
18
  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"/>',
@@ -75,8 +75,18 @@ const CL_ORDER = 'In the order of Needs you on the console: what cannot wait fir
75
75
  /** The list the page draws: the console's Needs you once it is read, else the model's records-only rows. */
76
76
  function LIST() {
77
77
  if (!CL) return M.list;
78
- return { rows: CL.map((r, i) => ({ ...r, n: i + 1 })), count: CL.length, more: 0, putOff: [], order: CL_ORDER, pendingNote: '' };
78
+ const own = CL.filter((r) => !r.prop); // premium-agent-inbox: the Driver's drafts rows are in the bell; the count line below the rows names them
79
+ return { rows: own.map((r, i) => ({ ...r, n: i + 1 })), count: own.length, more: 0, putOff: [], order: CL_ORDER, pendingNote: '' };
79
80
  }
81
+ /** The count line of the agent's results under the rows (premium-agent-inbox): the total, the new ones and the oldest, and a press opens the bell. */
82
+ function inboxLine() {
83
+ const j = ibState(); if (!j || !j.count) return '';
84
+ const d = j.oldest == null ? null : Math.floor((Date.now() - j.oldest) / 86400000);
85
+ const sub = [j.newCount ? j.newCount + ' new since you last looked' : 'none new since you last looked', d == null ? '' : d < 1 ? 'the oldest is from today' : 'the oldest is ' + d + (d === 1 ? ' day old' : ' days old')].filter(Boolean).join(' · ');
86
+ return `<div class="ib-sum"><span class="ib-n">${j.count}</span><span class="ib-b"><b>${j.count === 1 ? 'agent result waits' : 'agent results wait'} on you.</b><small>${esc(sub)}</small></span><button type="button" class="cta" id="ibOpen" aria-haspopup="dialog">Open Needs you</button></div>`;
87
+ }
88
+ document.addEventListener('pmos:inbox', () => { if (M) drawRows(); });
89
+ document.addEventListener('click', (e) => { if (e.target.closest('#ibOpen')) pvOpenBell(); });
80
90
  function drawRows() {
81
91
  const LS = LIST(), pend = M.pending && !CL;
82
92
  const rows = LS.rows, L = $('#rank');
@@ -85,6 +95,9 @@ function drawRows() {
85
95
  const order = rows.slice().sort((a, b) => (pinned.has(b.key) - pinned.has(a.key)) || (a.n - b.n));
86
96
  L.innerHTML = order.map((r, i) => `<div class="rr${i < 3 ? ' lead' : ''}${i === 0 ? ' first' : ''}" data-key="${esc(r.key)}"${linkOf(r) ? ` data-link="${esc(linkOf(r))}"` : ''}><button class="rhd" aria-haspopup="dialog"><span class="rn">${STAMP(i + 1)}</span><span><span class="rt">${esc(r.title)}${i === 0 ? '<em class="tgf">Do this first</em>' : ''}</span><span class="rs">${r.product ? `<b class="pn">${esc(r.product)}</b>` : ''}${esc(r.subject)}</span><span class="sug"><span>${esc(r.prepared)}</span></span>${r.skip ? `<span class="skip">${esc(r.skip)}</span>` : ''}</span></button><button class="rpin" data-pin="${esc(r.key)}" aria-pressed="${pinned.has(r.key)}" aria-label="Pin ${esc(r.title)} to the top" title="Pin to the top"><svg class="i" viewBox="0 0 24 24"><path d="M9 4h6l-1 6 3 3H7l3-3zM12 13v7"/></svg></button></div>`).join('')
87
97
  + (LS.more ? `<p class="note">${LS.more} more ${LS.more === 1 ? 'row is' : 'rows are'} not shown here.</p>` : '');
98
+ if (!$('#ibLine')) $('#calm').insertAdjacentHTML('afterend', '<div id="ibLine"></div>'); // premium-agent-inbox: the agent's results, one count line under the PM's own rows
99
+ $('#ibLine').innerHTML = inboxLine();
100
+ $('#calm b').textContent = ibState() && ibState().count ? 'Nothing of your own waits right now.' : 'Nothing needs you right now.';
88
101
  const n = LS.count;
89
102
  $('#movesCap').innerHTML = pend ? `${n} ${n === 1 ? 'row' : 'rows'} so far · still reading` : n ? `<b>${done} of ${total}</b> done · ${n} ${n === 1 ? 'row' : 'rows'} left` : 'All clear';
90
103
  $('#movesCap').title = 'Counts rows that cleared since this page first read today. A row clears when its record changes.';
@@ -161,7 +174,7 @@ document.addEventListener('click', (e) => {
161
174
 
162
175
  /* ── dock ───────────────────────────────────────────────────────────────────────────────────────────────── */
163
176
  function drawDock() {
164
- const n = CL ? CL.length : M.dock.needs;
177
+ const n = CL ? LIST().count : M.dock.needs;
165
178
  $('#dN').textContent = n == null ? '·' : n; $('#dLab').textContent = n == null ? 'still reading' : n === 0 ? 'need you' : CL ? (n === 1 ? 'needs you' : 'need you') : M.dock.label;
166
179
  }
167
180
 
@@ -251,7 +264,7 @@ $('#dBody').addEventListener('click', (e) => {
251
264
  const lt = e.target.closest('#logT');
252
265
  if (lt) { const c = $('#alog').classList.toggle('col'); lt.setAttribute('aria-expanded', !c); return; }
253
266
  if (!openR) return;
254
- if (e.target.closest('#openProps')) { closeDlg(); openPropsDlg(); return; }
267
+ if (e.target.closest('#openProps')) { const r = openR; closeDlg(); openPropsDlg(rowTarget(r)); return; } // a drafts row: that target's proposals only
255
268
  const op = e.target.closest('[data-op]');
256
269
  if (op) { WHY[openR.key] = ($('#why') || {}).value || ''; SEL[openR.key] = op.dataset.op; $('#card').outerHTML = cardHtml(openR); $('#oMain').innerHTML = paneHtml(openR); ctaState(openR); return; }
257
270
  const st = e.target.closest('[data-start]');
@@ -615,20 +628,30 @@ async function openCoreDraft(t) {
615
628
  pdSheet.open(d);
616
629
  }
617
630
 
618
- /* PFOCUS: the one target a "What you need to do" row opened the dialog on ({ kind, ws, id }), or null for every proposal. Show all clears it. */
631
+ /* PFOCUS: the one target a "What you need to do" row opened the dialog on ({ kind, ws, id }), the one proposal the bell opened it on ({ proposal, ws }),
632
+ * or null for every proposal. Show all clears it. A focus from the bell (premium-agent-inbox) also carries `bell` and the target's drafts row key `session`. */
619
633
  let PFOCUS = null;
620
- const inFocus = (it) => !PFOCUS || (it.kind === PFOCUS.kind && it.tid === PFOCUS.id && (!PFOCUS.ws || it.ws === PFOCUS.ws));
634
+ const inFocus = (it) => !PFOCUS || (PFOCUS.proposal ? it.id === PFOCUS.proposal && (!PFOCUS.ws || it.ws === PFOCUS.ws) : it.kind === PFOCUS.kind && it.tid === PFOCUS.id && (!PFOCUS.ws || it.ws === PFOCUS.ws));
635
+ /** The Driver target of an agent drafts row (its run id driver-needs:<drafts|blocked>:<kind>:<ws>:<id>), or null: Review the drafts opens that target's proposals. */
636
+ function rowTarget(r) {
637
+ const m = /driver-needs:(?:drafts|blocked):(initiative|work):([^:]+):(.+)$/.exec(String((r && r.from && r.from[0]) || ''));
638
+ return m ? { kind: m[1], ws: m[2], id: m[3] } : null;
639
+ }
640
+ /** The agent's drafts rows and goal rows (in model.agent since premium-agent-inbox) and the list's rows: a deep link opens one by its key. */
641
+ const anyRow = (key) => [].concat(M && M.agent ? M.agent.rows || [] : [], M && M.agent ? M.agent.goals || [] : [], M ? M.list.rows : [], CL || []).find((r) => r.key === key) || null;
621
642
  function propsHtml() {
622
643
  const a = A.prop; if (!a.ok) return `<p class="nodef err" role="alert">Agent proposals ${esc(said(a))}</p>`;
623
644
  const all = a.items.concat([...DEC.values()].map((d) => d.item).filter((it) => !a.items.some((o) => o.id === it.id)));
624
645
  const L = all.filter(inFocus), open = a.items.filter(inFocus).length, rest = PFOCUS ? a.items.length - open : 0;
625
- const more = PFOCUS ? bdActs(bdBtn('Show all proposals', 'pall', null, true)) + (rest ? `<p class="bd-why">${pl(rest, 'more proposal waits', 'more proposals wait')} on other work.</p>` : '') : '';
646
+ const more = PFOCUS ? bdActs(bdBtn('Show all proposals', 'pall', null, true), PFOCUS.session && anyRow(PFOCUS.session) ? bdBtn('Talk to the agent', 'psess', null, true) : '', PFOCUS.bell ? bdBtn('Back to Needs you', 'pbell', null, true) : '') + (rest ? `<p class="bd-why">${pl(rest, 'more proposal waits', 'more proposals wait')} on other work.</p>` : '') : '';
626
647
  return (L.length ? `<p class="bd-top">${open ? pl(open, 'proposal waits', 'proposals wait') + ' for you.' : 'All decided.'} The agent drafts and asks you. Nothing it wrote has changed a record until you keep it.</p><div class="bd-list">${L.map(propItem).join('')}</div>` : `<p class="empty3">${CHECK}${PFOCUS ? 'No proposal waits on this one. It may have been decided since the list was read.' : 'No agent proposals wait.'}</p>`) + more
627
648
  + (a.errs.length ? `<p class="note">Not read: ${esc(a.errs[0])}</p>` : '') + '<p class="note">The agent mode (Off, Shadow, Approve) stays in the console. This list shows a kind only when its mode is Approve.</p>';
628
649
  }
629
650
  async function propPress(e, redraw) {
630
651
  const b = e.target.closest('[data-bda]'); if (!b || BUSY) return;
631
652
  if (b.dataset.bda === 'pall') { PFOCUS = null; redraw(); return; }
653
+ if (b.dataset.bda === 'psess') { const r = anyRow(PFOCUS && PFOCUS.session); closeDlg(); if (r) openRow(r); return; } // the target's drafts row: its conversation is the agent's session
654
+ if (b.dataset.bda === 'pbell') { closeDlg(); pvOpenBell(); return; }
632
655
  const act = b.dataset.bda, id = b.dataset.id, it = openProps().find((x) => x.id === id);
633
656
  if (!it) return;
634
657
  if (act === 'pnote') { PBACK.add(id); redraw(`[data-bdn="${CSS.escape(id)}"]`); return; }
@@ -644,6 +667,29 @@ async function propPress(e, redraw) {
644
667
  toast(act === 'pkeep' ? 'Kept.' : act === 'pback' ? 'Sent back with your note.' : 'Dropped. It counts as a correction.');
645
668
  await readAll(['prop']); redraw(`.bd-it[data-id="${CSS.escape(id)}"] .bd-done`);
646
669
  }
670
+ /** ?open= (premium-agent-inbox): the bell's deep link. prop:<id> opens the Agent proposals dialog on that one proposal, target:<kind>:<id> on that target's,
671
+ * row:<key> a drafts or goal row's dialog, whose conversation is the session. pws names the product. On this page the bell opens it in place ('pmos:open'). */
672
+ function openParam(open, pws) {
673
+ const v = String(open || ''), ws = pws || null;
674
+ let m;
675
+ if ((m = /^prop:(.+)$/.exec(v))) {
676
+ const it = openProps().find((x) => x.id === m[1] && (!ws || x.ws === ws));
677
+ openPropsDlg({ proposal: m[1], ws, bell: true, session: it ? rowKeyOf(it) : null });
678
+ } else if ((m = /^target:(initiative|work):(.+)$/.exec(v))) openPropsDlg({ kind: m[1], id: m[2], ws, bell: true, session: ws ? rowKeyOf({ kind: m[1], ws, tid: m[2] }) : null });
679
+ else if ((m = /^row:(.+)$/.exec(v))) { const r = anyRow(m[1]); if (r) openRow(r); else toast('That item no longer waits on you. It may have been decided since.'); }
680
+ }
681
+ /** The key of a target's drafts row (lib/agent-inbox.js draftsRowKey): the row's conversation is that target's agent session. */
682
+ function rowKeyOf(it) {
683
+ const k = (M && M.agent && M.agent.rows || []).find((r) => { const t = rowTarget(r); return t && t.kind === it.kind && t.ws === it.ws && t.id === it.tid; });
684
+ return k ? k.key : null;
685
+ }
686
+ function openOpenParam() {
687
+ const q = new URLSearchParams(location.search), v = q.get('open');
688
+ if (!v) return;
689
+ try { const u = new URL(location.href); u.searchParams.delete('open'); u.searchParams.delete('pws'); history.replaceState(history.state, '', u); } catch { /* no history */ }
690
+ openParam(v, q.get('pws'));
691
+ }
692
+ document.addEventListener('pmos:open', (e) => { if (!M) return; const d = e.detail || {}; (A.prop ? Promise.resolve() : readAll(['prop'])).then(() => openParam(d.open, d.pws)); });
647
693
  /** ?around=<prop|scan|rep|src|men|pulse> opens that Around you dialog once its read is in: another premium page links here (a board document's Run a scan). */
648
694
  function openAroundParam() {
649
695
  const k = new URLSearchParams(location.search).get('around'), fn = { prop: openPropsDlg, men: openMen, pulse: openPulse, scan: openScan, rep: openReport, src: openSrc }[k];
@@ -652,7 +698,7 @@ function openAroundParam() {
652
698
  fn();
653
699
  }
654
700
  const openPropsDlg = async (focus) => {
655
- PFOCUS = focus && focus.kind && focus.id ? focus : null;
701
+ PFOCUS = focus && ((focus.kind && focus.id) || focus.proposal) ? focus : null;
656
702
  if (PFOCUS && !A.prop) await readAll(['prop']); // pressed before Around you has read: read the proposals first
657
703
  const n = openProps().filter(inFocus).length;
658
704
  bdDlg('prop', 'Agent proposals · real data', 'Agent proposals', 'The Initiative Driver, read from each product\'s ledger',
@@ -982,7 +1028,7 @@ async function load() {
982
1028
  return;
983
1029
  }
984
1030
  M = r.model; drawHero(); drawRows(); drawChips(); drawTl(); readPrep(); drawDock(); drawPick(); onScroll();
985
- if (!AROUND) { AROUND = true; readAll().then(openAroundParam); setInterval(() => { if (!document.hidden && !$('#dlg').classList.contains('on')) readAll(); }, 300000); }
1031
+ if (!AROUND) { AROUND = true; readAll().then(() => { openAroundParam(); openOpenParam(); }); setInterval(() => { if (!document.hidden && !$('#dlg').classList.contains('on')) readAll(); }, 300000); }
986
1032
  const age = Date.now() - r.as_of;
987
1033
  if (age > 5 * 60000) $('#snap').textContent += ' · read ' + ago(age) + (r.refreshing ? ', refreshing' : '');
988
1034
  if (r.error) $('#snap').textContent += ' · the latest read failed: ' + r.error.slice(0, 120);
@@ -55,6 +55,7 @@
55
55
  "briefing-premium-products.test.js",
56
56
  "briefing-premium-sources.test.js",
57
57
  "briefing-premium-drafts.test.js",
58
+ "agent-inbox.test.js",
58
59
  "briefing-premium-metrics.test.js",
59
60
  "premium-welcome.test.js",
60
61
  "calendar-events.test.js",
@@ -230,6 +231,7 @@
230
231
  "briefing-premium-products.test.js": 1,
231
232
  "briefing-premium-sources.test.js": 1,
232
233
  "briefing-premium-drafts.test.js": 1,
234
+ "agent-inbox.test.js": 1,
233
235
  "briefing-premium-metrics.test.js": 1,
234
236
  "premium-welcome.test.js": 1,
235
237
  "calendar-events.test.js": 1,