create-pmos 0.351.0 → 0.353.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.
@@ -80,6 +80,15 @@ function goalOf(runtimeDir, key) {
80
80
  }
81
81
  return g;
82
82
  }
83
+ /** Every key's goal state in one read: { <key>: { state, rounds, limit } } (premium-session-list L1: the session list's Goals group). */
84
+ function statesAt(runtimeDir) {
85
+ let t; try { t = fs.readFileSync(path.join(runtimeDir, RUNS), 'utf8'); } catch { return {}; }
86
+ const keys = new Set();
87
+ for (const l of t.split('\n')) { if (!l.trim()) continue; try { const e = JSON.parse(l); if (e && typeof e.key === 'string') keys.add(e.key); } catch { /* skip */ } }
88
+ const out = {};
89
+ for (const key of keys) { const g = goalOf(runtimeDir, key); if (g) out[key] = { state: g.state, rounds: g.rounds || 0, limit: (g.draft && g.draft.limit) || LIMIT }; }
90
+ return out;
91
+ }
83
92
 
84
93
  /* ── slice 3: until achieved (PRD U1–U7) ───────────────────────────────────────────────────────────────────────────────
85
94
  * Claude Code's Stop hook posts here each time Claude would end its turn in a chat session. While the key's goal is started
@@ -215,9 +224,9 @@ function decide({ runtimeDir, key, id, act, draft, session, sessions, now = new
215
224
  if (!session || !sessions || !sessions.alive(session)) return fail(409, 'No session is running for this conversation. Send /goal again to start one.');
216
225
  let d = null;
217
226
  if (act === 'start') { d = cleanDraft(draft); if (!d) return fail(400, 'The goal needs a sentence and at least one done point before it can start.'); }
218
- if (!sessions.type(session, act === 'start' ? startMessage(d) : cancelMessage())) return fail(409, 'The message did not reach the session. Open it in Agent sessions.');
227
+ if (!sessions.type(session, act === 'start' ? startMessage(d) : cancelMessage())) return fail(409, 'The message did not reach the session. Open it in Sessions.');
219
228
  append(runtimeDir, { event: act === 'start' ? 'started' : 'cancelled', id, key, ...(d ? { draft: d } : {}), at: now.toISOString() });
220
229
  return { status: 200, body: { ok: true, id, state: act === 'start' ? 'started' : 'cancelled' } };
221
230
  }
222
231
 
223
- module.exports = { parseCommand, grillPrompt, startMessage, cancelMessage, cleanDraft, goalOf, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
232
+ module.exports = { parseCommand, grillPrompt, startMessage, cancelMessage, cleanDraft, goalOf, statesAt, begin, decide, onStop, resume, briefingRows, goalRowsAt, withGoalRows, blockOf, keyOfSession, hookSettings, MARK, RUNS, LIMIT, NO_PROGRESS, REASON };
@@ -126,6 +126,11 @@ module.exports = {
126
126
  if (req.method !== 'POST') { ctx.json(res, { ok: false, error: 'POST only' }, 405); return true; }
127
127
  return post(req, res, url, ctx);
128
128
  }
129
+ if (url.pathname === '/api/briefing-premium/goals') { // premium-session-list L1: every conversation's goal state, for the session list's Goals group
130
+ if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
131
+ ctx.json(res, { ok: true, goals: ctx.runtimeDir ? Goal.statesAt(ctx.runtimeDir) : {} });
132
+ return true;
133
+ }
129
134
  if (url.pathname === '/api/briefing-premium/thread') {
130
135
  if (req.method !== 'GET') { ctx.json(res, { ok: false, error: 'GET only' }, 405); return true; }
131
136
  const key = url.searchParams.get('key') || '';
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.351.0",
3
+ "version": "0.353.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.351.0",
9
+ "version": "0.353.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.351.0",
3
+ "version": "0.353.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",
@@ -0,0 +1,139 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* premium-html-viewer-test.js — an .html file Claude names in a premium chat panel opens in the viewer as the page it is (bug 2026-10-20: "HTML file
4
+ * didn't render properly": the viewer printed the report's source in a code block). public/pm/premium-vw-file.js draws it in a frame sandboxed to
5
+ * allow-scripts only, under a CSP that blocks every fetch, with Page and Source on its bar. The real premium page and server; the file reads are routed.
6
+ * H1 the page renders, standards mode, its own scripts run (the report's toggle redraws its bars)
7
+ * H2 the page cannot reach the app: no parent document, no storage, no fetch, and no request leaves for the remote font
8
+ * H3 Source shows the file's text, Page brings the page back
9
+ * H4 a markdown and a plain text file still open as before
10
+ * H5 framedSrc() puts the CSP after the doctype, and before everything when there is none
11
+ * PMOS_SHOTS=<dir> also saves the viewer at 1280 and 390, light and dark (PMOS_SHOTS_TAG=before: the shots alone, for the code before a change). */
12
+ const fs = require('fs');
13
+ const path = require('path');
14
+ const { spawn } = require('child_process');
15
+ const { findBrowser } = require('./lib/find-browser');
16
+ const T = require('./test-run').configure({ name: 'premium-html-viewer' });
17
+
18
+ const BASE = T.BASE;
19
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
20
+ const until = async (fn, ms = 10000, step = 100) => { const t0 = Date.now(); for (;;) { const v = await fn(); if (v) return v; if (Date.now() - t0 > ms) return v; await sleep(step); } };
21
+ const results = [];
22
+ const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 600) : ''}`); };
23
+ let srv = null; let browser = null;
24
+ const finish = async (code) => {
25
+ if (browser) await browser.close().catch(() => {});
26
+ if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
27
+ T.killTmux();
28
+ const bad = results.filter((x) => !x.cond).length;
29
+ console.log(`\n${results.length - bad}/${results.length} premium-html-viewer assertions passed`);
30
+ process.exit(code !== undefined ? code : (bad ? 1 : 0));
31
+ };
32
+ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
33
+
34
+ const REPORT = fs.readFileSync(path.join(__dirname, 'fixtures', 'html-viewer-report.html'), 'utf8');
35
+ const FILES = {
36
+ 'pmos/state/reports/lightbox-password-conversion/2026-10-19.html': { kind: 'html', text: REPORT },
37
+ 'pmos/state/reports/lightbox-password-conversion/2026-10-19.md': { kind: 'markdown', text: '# Funnel\n\nThe **sign-up** rate is 38%.' },
38
+ 'workspace/lib/a.js': { kind: 'text', text: 'const a = 1;\n' },
39
+ };
40
+ const SHOTS = process.env.PMOS_SHOTS || '', TAG = process.env.PMOS_SHOTS_TAG || 'after'; // TAG=before skips the checks and only saves the shots
41
+
42
+ (async () => {
43
+ {
44
+ const M = await import('./public/pm/premium-vw-file.js');
45
+ if (typeof M.framedSrc !== 'function') ok('H5 premium-vw-file.js exports framedSrc', false);
46
+ else {
47
+ const a = M.framedSrc('<!doctype html><html><head></head></html>'), b = M.framedSrc('<p>x</p>'), c = M.framedSrc('<!-- c -->\n<!DOCTYPE html>\n<html>');
48
+ ok('H5 the CSP goes right after the doctype, and first when there is none', a.startsWith('<!doctype html><meta http-equiv="Content-Security-Policy"') && b.startsWith('<meta http-equiv="Content-Security-Policy"') && /^<!-- c -->\n<!DOCTYPE html><meta /.test(c), [a, b, c].join(' | '));
49
+ ok('H5 the CSP blocks every fetch and names no script host', /default-src 'none'/.test(M.FRAME_CSP) && /script-src 'unsafe-inline'$/.test(M.FRAME_CSP) && !/connect-src|https?:/.test(M.FRAME_CSP));
50
+ const src = M.fileHtml({ name: 'r.html', kind: 'html', text: '<b>"x"</b>', rel: 'r.html' });
51
+ ok('H5 the frame is sandboxed to scripts alone', /sandbox="allow-scripts"/.test(src) && !/allow-same-origin/.test(src), src);
52
+ }
53
+ }
54
+ const exe = findBrowser();
55
+ if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the premium-html-viewer suite cannot run'); return finish(1); }
56
+ let chromium;
57
+ try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed — the premium-html-viewer suite cannot run'); return finish(1); }
58
+ srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
59
+ await T.waitForServer(BASE);
60
+ browser = await chromium.launch({ executablePath: exe });
61
+
62
+ const open = async ({ w = 1280, h = 900, theme = 'light' } = {}) => {
63
+ const ctx = await browser.newContext({ viewport: { width: w, height: h }, colorScheme: theme });
64
+ const out = [];
65
+ // a request the CSP refuses still shows as a request; one that left the machine finishes (or fails on the network, not on csp)
66
+ ctx.on('requestfinished', (r) => { if (!r.url().startsWith(BASE) && /^https?:/.test(r.url())) out.push(r.url()); });
67
+ ctx.on('requestfailed', (r) => { if (!r.url().startsWith(BASE) && /^https?:/.test(r.url()) && (r.failure() || {}).errorText !== 'csp') out.push(r.url()); });
68
+ const page = await ctx.newPage();
69
+ const errors = [];
70
+ page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
71
+ const json = (body) => (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify(body) });
72
+ await page.route('**/api/brief-page*', json({ ok: false, error: 'off in this suite' }));
73
+ await page.route('**/api/doc/locate*', (r) => {
74
+ const p = new URL(r.request().url()).searchParams.get('path'), f = FILES[p];
75
+ return json(f ? { ok: true, ws: 'w0', rel: p, abs: '/Users/pm/pmos/' + p, name: p.split('/').pop(), mtime: 1, size: f.text.length } : { ok: false, reason: 'missing', why: 'No such file.' })(r);
76
+ });
77
+ await page.route('**/api/doc?*', (r) => {
78
+ const f = FILES[new URL(r.request().url()).searchParams.get('path')];
79
+ return r.fulfill({ status: 200, contentType: f.kind === 'markdown' ? 'text/markdown' : 'text/plain', headers: { 'X-Doc-Kind': f.kind }, body: f.text });
80
+ });
81
+ await page.goto(BASE + '/premium.html?theme=' + theme);
82
+ await until(() => page.evaluate(() => !!document.querySelector('#dlg')), 15000);
83
+ await page.evaluate(async () => {
84
+ const S = await import('/pm/premium-shell.js');
85
+ S.openDlg({ eye: 'Your item', title: 'Check GA Lightbox', say: 'The report is now an HTML file in the repo.', noteKey: null, pane: '<article class="paper doc"><p>Item record</p></article>', label: 'Item record' });
86
+ });
87
+ return { ctx, page, errors, out };
88
+ };
89
+ const press = (page, file) => page.evaluate((f) => {
90
+ const b = document.createElement('button'); b.type = 'button'; b.className = 'fpath'; b.dataset.file = f; b.textContent = f;
91
+ document.querySelector('#dBody .stream').append(b); b.click();
92
+ }, file);
93
+ const HTMLF = 'pmos/state/reports/lightbox-password-conversion/2026-10-19.html';
94
+ const frameOf = async (page) => { const h = await until(() => page.$('#dOut .obody.vw iframe.vwframe'), 8000); return h ? h.contentFrame() : null; };
95
+
96
+ if (TAG === 'after') {
97
+ const { page, errors, out, ctx } = await open();
98
+ await press(page, HTMLF);
99
+ const fr = await frameOf(page);
100
+ ok('H1 the .html file opens as a frame, not as code', !!fr && !(await page.$('#dOut .obody.vw .cb')));
101
+ const st = fr && await until(() => fr.evaluate(() => (document.body && document.body.dataset.net ? { mode: document.compatMode, title: document.title, rows: document.querySelectorAll('.row').length, m: document.body.dataset.mode, parent: document.body.dataset.parent, store: document.body.dataset.store, net: document.body.dataset.net, h1: (document.querySelector('h1') || {}).textContent } : null)), 8000);
102
+ ok('H1 the page renders in standards mode with its own title and bars', st && st.mode === 'CSS1Compat' && st.h1 === 'Password Conversion Funnel' && st.rows === 6 && st.m === 'events', JSON.stringify(st));
103
+ // the press goes through the page's own handler; a click by coordinates can land on the viewer while it is still laying out
104
+ if (fr) await fr.evaluate(() => document.querySelector('button[data-m="users"]').click());
105
+ const after = fr && await until(() => fr.evaluate(() => (document.body.dataset.mode === 'users' ? document.querySelector('.row span span').textContent : null)), 6000);
106
+ const why = after ? '' : fr && await fr.evaluate(() => JSON.stringify({ mode: document.body.dataset.mode, first: (document.querySelector('.row span span') || {}).textContent })).catch((e) => String(e));
107
+ ok('H1 the page\'s own script runs: its toggle redraws the bars', after === '1,310 · 100%', after || why);
108
+ ok('H2 the page cannot read the app, its storage or the network', st && st.parent === 'blocked' && st.store === 'blocked' && st.net === 'blocked', JSON.stringify(st));
109
+ ok('H2 nothing leaves the machine: the CSP refuses the remote font', out.length === 0, out.join(' '));
110
+ const bar = await page.evaluate(() => [...document.querySelectorAll('#dOut .obody.vw [data-fv]')].map((b) => b.textContent + ':' + b.getAttribute('aria-pressed')).join());
111
+ ok('H3 the bar offers Page and Source, Page pressed', bar === 'Page:true,Source:false', bar);
112
+ await page.click('#dOut .obody.vw [data-fv="source"]');
113
+ const src = await until(() => page.evaluate(() => { const p = document.querySelector('#dOut .obody.vw .cb pre'); return p ? { head: p.textContent.slice(0, 15), frame: !!document.querySelector('#dOut .obody.vw iframe') } : null; }), 4000);
114
+ ok('H3 Source shows the file\'s text', src && src.head === '<!doctype html>' && !src.frame, JSON.stringify(src));
115
+ await page.click('#dOut .obody.vw [data-fv="page"]');
116
+ ok('H3 Page brings the page back', !!(await frameOf(page)));
117
+ await press(page, 'pmos/state/reports/lightbox-password-conversion/2026-10-19.md');
118
+ const md = await until(() => page.evaluate(() => { const p = document.querySelector('#dOut .obody.vw:not([hidden]) .cfb'); return p && p.querySelector('strong') ? p.innerHTML : null; }), 6000);
119
+ ok('H4 a markdown file still opens as a page', md && /<strong>sign-up<\/strong>/.test(md), md);
120
+ await press(page, 'workspace/lib/a.js');
121
+ const js = await until(() => page.evaluate(() => { const p = document.querySelector('#dOut .obody.vw:not([hidden]) .cb'); return p ? p.dataset.lang + ':' + p.querySelector('pre').textContent : null; }), 6000);
122
+ ok('H4 a plain text file still opens as code, with no Page and Source bar', js === 'js:const a = 1;\n' && !(await page.$('#dOut .obody.vw:not([hidden]) [data-fv]')), js);
123
+ ok('H4 no page errors', errors.length === 0, errors.join(' | '));
124
+ await ctx.close();
125
+ }
126
+
127
+ for (const [w, h] of [[1280, 900], [390, 844]]) for (const theme of ['light', 'dark']) {
128
+ const { page, ctx } = await open({ w, h, theme });
129
+ await press(page, HTMLF);
130
+ const fr = await frameOf(page);
131
+ if (fr) await until(() => fr.evaluate(() => document.querySelectorAll('.row').length === 6), 6000);
132
+ else await sleep(1500);
133
+ const geo = await page.evaluate(() => { const f = document.querySelector('#dOut .obody.vw iframe'), r = f && f.getBoundingClientRect(); return r ? { w: Math.round(r.width), h: Math.round(r.height), sx: document.documentElement.scrollWidth - innerWidth } : null; });
134
+ ok(`H1 at ${w} ${theme} the frame fills the viewer's width and has room to read`, geo && geo.w >= (w < 1000 ? 300 : 500) && geo.h >= 400 && geo.sx <= 0, JSON.stringify(geo));
135
+ if (SHOTS) { fs.mkdirSync(SHOTS, { recursive: true }); await sleep(300); await page.screenshot({ path: path.join(SHOTS, `${TAG}-${w}-${theme}.png`) }); }
136
+ await ctx.close();
137
+ }
138
+ return finish();
139
+ })();
@@ -112,6 +112,7 @@ const SPRINTS = { ok: true, source: 'jira', readAt: '2026-10-19T09:00:00Z', velo
112
112
  {
113
113
  const { page, ctx, S } = await open({ w: 390, h: 844, theme: 'dark' });
114
114
  ok('R7 the backlog opens at 390px', await openBacklog(page));
115
+ await page.evaluate(() => Promise.race([Promise.all(document.getAnimations().filter((a) => a.effect && a.effect.getTiming().iterations !== Infinity).map((a) => a.finished.catch(() => {}))), new Promise((r) => setTimeout(r, 3000))])); // the dialog's open transition scales its buttons: measure them once it ends
115
116
  const m = await page.evaluate(() => {
116
117
  const p = document.querySelector('#dOut .obody.vw:not([hidden])');
117
118
  const small = [...p.querySelectorAll('button')].filter((b) => b.getBoundingClientRect().width && b.getBoundingClientRect().height < 44).map((b) => b.textContent.trim().slice(0, 20));
@@ -7,6 +7,7 @@ import { chipActs, openLive, openFocus, mountRecord, HL_LINE } from './premium-v
7
7
  import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words.js';
8
8
  import { splitGoal, shownUser, goalBlockHtml, goalProgressHtml, slashMatches } from './goal-chat.js';
9
9
  import { mdHtml, userHtml, toolLine, webKind } from './chat-md.js';
10
+ import { railModel, railHtml, teaser, menuCount, loudestRow, factsOf, titleOf, DOT, WORD } from './session-rail.js';
10
11
  export const $ = (s, r = document) => r.querySelector(s);
11
12
  export const $$ = (s, r = document) => [...r.querySelectorAll(s)];
12
13
  export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
@@ -14,7 +15,7 @@ export const RM = matchMedia('(prefers-reduced-motion: reduce)').matches;
14
15
  export const store = { get(k) { try { return localStorage.getItem(k); } catch { return null; } }, set(k, v) { try { localStorage.setItem(k, v); } catch { /* no storage */ } } };
15
16
  export const THEME_KEY = 'pmos.c3.theme';
16
17
  export const AI = '<svg class="i" viewBox="0 0 24 24"><path d="M12 3l1.8 4.7L18.5 9.5l-4.7 1.8L12 16l-1.8-4.7L5.5 9.5l4.7-1.8z"/></svg>';
17
- export const S = { key: null }; // the key of the row whose dialog is open (the agent's thread belongs to it)
18
+ export const S = { key: null, sid: null }; // the key of the row whose dialog is open (the agent's thread belongs to it); sid: a session the list opened that has no row (premium-session-list)
18
19
  let lastFocus = null;
19
20
  /* ── theme ──────────────────────────────────────────────────────────────────────────────────────────────── */
20
21
  export function theme(t) {
@@ -27,7 +28,7 @@ export function flip() {
27
28
  }
28
29
  { const t = new URLSearchParams(location.search).get('theme') || store.get(THEME_KEY); theme(t); }
29
30
  /* ── 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.
30
- * The menu holds what left the bar: Search, Agent sessions, Console, Theme, Settings, and on Board how an initiative opens. Every item keeps
31
+ * The menu holds what left the bar: Search, Sessions, Console, Theme, Settings, and on Board how an initiative opens. Every item keeps
31
32
  * the id the pages and the code below wire, so a press does what it did as a round button. ── */
32
33
  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>';
33
34
  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>';
@@ -40,7 +41,7 @@ function tbMount() {
40
41
  + '<div class="crmenu tbmenu" id="moreMenu" role="menu" aria-label="More" hidden>'
41
42
  + '<button role="menuitem" id="pvSearch" aria-haspopup="dialog">Search<em>Ctrl K</em></button>'
42
43
  + '<button role="menuitem" id="srcItem" class="tbm-src" aria-haspopup="dialog">Sources</button>'
43
- + '<button role="menuitem" id="sessBtn" aria-haspopup="dialog" aria-label="Agent sessions">Agent sessions<em id="sessBdg" hidden></em></button>'
44
+ + '<button role="menuitem" id="sessBtn" aria-haspopup="dialog" aria-label="Sessions">Sessions<em id="sessBdg" hidden></em></button>'
44
45
  + '<a role="menuitem" id="toConsole" href="/console.html" aria-label="Open the console">Console</a>'
45
46
  + '<div class="tbrow" id="modeRow" hidden><span>Open initiatives</span></div>'
46
47
  + `<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>`
@@ -157,7 +158,7 @@ export function openPageChat(key, page) {
157
158
  $('#askIn').placeholder = 'Message Claude about this page';
158
159
  loadThread(key);
159
160
  }
160
- tbMount(); // the top bar first: the menu holds the Settings, Agent sessions, Console and Search items the code below wires
161
+ tbMount(); // the top bar first: the menu holds the Settings, Sessions, Console and Search items the code below wires
161
162
  { const t2 = $('#theme2'); if (t2) t2.onclick = flip; }
162
163
  { const b = $('#settingsBtn'); if (b) b.onclick = () => openSettings(); } // hoisted: the function below is declared, not assigned
163
164
 
@@ -197,10 +198,11 @@ export function openDlg(o) {
197
198
  $('#dlg').classList.remove('full'); setMode('split'); setTab('out'); // on a phone the dialog opens on the Detail tab and the Detail / Conversation switch brings the conversation, as the mockup draws it
198
199
  $('#veil').classList.add('on'); $('#dlg').classList.add('on');
199
200
  $$('#dGrid .pane').forEach((p) => { p.scrollTop = 0; });
201
+ railOnOpen(o);
200
202
  setTimeout(() => $('#dlg').focus(), 60);
201
203
  }
202
204
  export function closeDlg() {
203
- clearTimeout(threadTimer); S.key = null;
205
+ clearTimeout(threadTimer); S.key = null; railOnClose();
204
206
  park();
205
207
  $('#veil').classList.remove('on'); $$('.rail,main.stage,#dock').forEach((x) => { x.inert = false; });
206
208
  $('#dlg').inert = true; document.documentElement.style.overflow = ''; $('#dlg').classList.remove('on');
@@ -216,7 +218,7 @@ export function setMode(m) {
216
218
  if (innerWidth < 1000) setTab(m === 'detail' ? 'out' : 'chat');
217
219
  }
218
220
  $('#dPane').onclick = () => setMode($('#dlg').dataset.mode === 'split' ? 'detail' : 'split');
219
- export function setFull(f) { $('#dlg').classList.toggle('full', f); const b = $('#dExpand'); b.setAttribute('aria-pressed', f); b.title = f ? 'Exit full screen' : 'Full screen'; $('#dExpP').setAttribute('d', f ? 'M20 10h-6V4M4 14h6v6M14 10l7-7M3 21l7-7' : 'M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7'); }
221
+ export function setFull(f) { $('#dlg').classList.toggle('full', f); $('#dlg').classList.remove('srl-open'); if (R.model) railDraw(); if (f) { railRead(); railTick(); } const b = $('#dExpand'); b.setAttribute('aria-pressed', f); b.title = f ? 'Exit full screen' : 'Full screen'; $('#dExpP').setAttribute('d', f ? 'M20 10h-6V4M4 14h6v6M14 10l7-7M3 21l7-7' : 'M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7'); }
220
222
  $('#tabGo').onclick = () => setTab('chat');
221
223
  $('#dClose').onclick = closeDlg; $('#veil').onclick = closeDlg;
222
224
  $('#dExpand').onclick = () => setFull(!$('#dlg').classList.contains('full'));
@@ -311,8 +313,9 @@ function readyDraft(conv) {
311
313
  }
312
314
  const chatPost = (act, body) => { const ws = new URLSearchParams(location.search).get('ws'); return pmPost('/api/briefing-premium/' + act + (ws ? '?ws=' + encodeURIComponent(ws) : ''), body).catch(() => null); };
313
315
  $('#dBody').addEventListener('click', async (e) => {
314
- const p = e.target.closest('[data-chat-press]'); if (!p || !S.key) return;
316
+ const p = e.target.closest('[data-chat-press]'); if (!p || (!S.key && !S.sid)) return;
315
317
  p.disabled = true;
318
+ if (S.sid) { const id = S.sid, r = await pmPost('/api/session/keys', { id, press: p.dataset.chatPress }); if (!r || !r.ok) $('#askNote').textContent = (r && r.error) || 'The key did not reach the session.'; setTimeout(() => loadSid(id), 500); return; }
316
319
  const r = await chatPost('press', { key: S.key, press: p.dataset.chatPress });
317
320
  if (!r || !r.ok) $('#askNote').textContent = (r && r.error) || 'The key did not reach the session.';
318
321
  setTimeout(() => loadThread(S.key), 500);
@@ -380,6 +383,12 @@ $('#dBody').addEventListener('keydown', (e) => {
380
383
  $('#dBody').addEventListener('submit', async (e) => {
381
384
  e.preventDefault();
382
385
  const inp = $('#askIn'), text = inp.value.trim(), key = S.key;
386
+ if (!key && S.sid) { // premium-session-list: a session the list opened that has no row of its own
387
+ if (!text) { $('#askNote').textContent = 'Write a message for Claude.'; return; }
388
+ const id = S.sid, r = await pmPost('/api/session/say', { id, text });
389
+ if (!r || !r.ok) { $('#askNote').textContent = (r && r.error) || 'The message was not sent.'; return; }
390
+ inp.value = ''; $('#askNote').textContent = 'Sent.'; drawSlash(); setTimeout(() => loadSid(id), 400); return;
391
+ }
383
392
  if (!key) { $('#askNote').textContent = 'This row has no conversation, so the message was not sent.'; return; }
384
393
  if (!text) { $('#askNote').textContent = 'Write a message for Claude.'; return; }
385
394
  if (await sendText(key, text)) { inp.value = ''; inp.placeholder = 'Message Claude, or type /'; drawSlash(); }
@@ -851,76 +860,152 @@ export async function openSettings() {
851
860
  await load();
852
861
  }
853
862
 
854
- /* ── Agent sessions: the running list with Stop (initiative premium-sessions) ──────────────────────────────────────────────────────────────
855
- * Reads GET /api/sessions, the list the console dock reads. The one write is POST /api/session/remove, a page press. A session's terminal, a new
856
- * session and a run's questions stay in the console. Every word on a row is a field of the session record. */
857
- const sessLive = (s) => s && s.shown !== 'exited';
858
- const SESS_MANY = 6; // more agents than this working at once earns the soft warning in the Sessions dialog
859
- const sessWorking = (l) => l.filter((x) => x.shown === 'working').length;
860
- const readSessions = async () => { const r = await pmGet('/api/sessions'); return r && Array.isArray(r.sessions) ? r.sessions.filter(sessLive) : null; };
861
- // The cards the console's run card reads (GET /api/runs): a session whose card is asking carries the agent's own question and the options it offered.
862
- const readAsks = async () => { const r = await pmGet('/api/runs'); const out = {}; if (r && r.ok && r.cards) for (const [id, c] of Object.entries(r.cards)) if (c && c.state === 'asking' && c.ask && c.ask.q && Array.isArray(c.ask.options) && c.ask.options.length) out[id] = { request: c.asked || c.ask.id, q: c.ask.q, options: c.ask.options }; return out; };
863
- const sessAgo = (t) => { const ms = Date.now() - new Date(t).getTime(); if (!(ms >= 0)) return ''; const m = Math.max(1, Math.round(ms / 60000)); return 'Started ' + (m < 60 ? m + ' min ago' : Math.floor(m / 60) + ' h ' + (m % 60) + ' min ago'); };
864
- function sessBadge(n) { const b = $('#sessBdg'); if (!b) return; b.textContent = String(n || ''); b.hidden = !n; const a = $('#sessBtn'); if (a) a.setAttribute('aria-label', 'Agent sessions, ' + (n ? n + ' running' : 'none running')); }
863
+ /* ── Sessions: the list beside the chat (initiative premium-session-list; PM decisions 2026-10-20) ─────────────────────────────────────────
864
+ * In full screen the dialog has three panels: the session list, the conversation and the viewer; the list and the viewer fold. A normal-size
865
+ * chat dialog shows a chip that opens the list. The list reads GET /api/sessions (the list the console dock reads) and the goals of the chat
866
+ * conversations; lib/session-rail.js groups them. Pressing a row switches the dialog to that session: a chat row opens its own conversation,
867
+ * any other session its transcript. The writes are a page press each: a message or a key (POST /api/session/say|keys), Stop (/api/session/remove)
868
+ * and an answer to a run's question (/api/runs/answer). The Agent sessions popup this replaces is gone; the ⋯ menu's Sessions opens this. */
869
+ const R = { rows: [], goals: {}, model: null, sel: null, shut: [], showAll: false, timer: null, asks: {}, ask: null, busy: false, slow: null, err: '', sidTimer: null,
870
+ railMin: store.get('pmos.srl.rail') === 'min', viewMin: store.get('pmos.srl.view') === 'min' };
871
+ const SRL_POLL = 3000, BADGE_POLL = 15000;
872
+ const desk = () => innerWidth >= 1000;
873
+ const railShowing = () => $('#dlg').classList.contains('on') && $('#dlg').classList.contains('srl-on') && ($('#dlg').classList.contains('full') ? desk() : $('#dlg').classList.contains('srl-open'));
874
+ function railMount() {
875
+ const g = $('#dGrid'); if (!g || $('#sRail')) return;
876
+ g.insertAdjacentHTML('afterbegin', `<aside class="srl" id="sRail" aria-label="Sessions"><div class="srl-hd"><b>Sessions</b><button type="button" class="srl-fold" id="srlFold" aria-label="Fold the list" title="Fold the list"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="M9 4v16"/></svg></button></div><div class="srl-list" id="srlList"></div><div class="srl-lg" aria-hidden="true"><span><i class="sdot2 ready"></i>Ready</span><span><i class="sdot2 run"></i>Running</span><span><i class="sdot2 blk"></i>Maybe blocked</span></div></aside>`);
877
+ $('#dlg .dtools').insertAdjacentHTML('afterbegin', '<button type="button" class="stease" id="sTease" aria-haspopup="true" hidden><i class="sdot2" aria-hidden="true"></i><span>Sessions</span><em></em></button>');
878
+ const ot = $('#dOut .otop'); if (ot) ot.insertAdjacentHTML('afterbegin', '<button type="button" class="vfold" id="vFold" aria-label="Fold the viewer" title="Fold the viewer"><svg class="i" viewBox="0 0 24 24"><rect x="3" y="4" width="18" height="16" rx="3"/><path d="M15 4v16"/></svg></button>');
879
+ $('#srlFold').onclick = () => { R.railMin = !R.railMin; store.set('pmos.srl.rail', R.railMin ? 'min' : 'open'); railLayout(); };
880
+ $('#vFold').onclick = () => { R.viewMin = !R.viewMin; store.set('pmos.srl.view', R.viewMin ? 'min' : 'open'); railLayout(); };
881
+ $('#sTease').onclick = () => {
882
+ if (desk()) { setFull(true); railLayout(); railRead(); return; }
883
+ $('#dlg').classList.toggle('srl-open'); railDraw(); if ($('#dlg').classList.contains('srl-open')) railRead();
884
+ };
885
+ $('#srlList').onclick = (e) => {
886
+ const gh = e.target.closest('[data-sg]'), mo = e.target.closest('[data-smore]'), r = e.target.closest('[data-sid]');
887
+ if (mo) { R.showAll = !R.showAll; railDraw(); return; }
888
+ if (gh) { if (R.railMin) { R.railMin = false; store.set('pmos.srl.rail', 'open'); railLayout(); return; } const k = gh.dataset.sg; R.shut = R.shut.includes(k) ? R.shut.filter((x) => x !== k) : [...R.shut, k]; railDraw(); return; }
889
+ if (r) pickSession(r.dataset.sid);
890
+ };
891
+ }
892
+ function railLayout() {
893
+ const d = $('#dlg');
894
+ d.classList.toggle('srl-min', R.railMin); d.classList.toggle('vw-min', R.viewMin);
895
+ const f = $('#srlFold'), v = $('#vFold');
896
+ if (f) { f.title = R.railMin ? 'Open the list' : 'Fold the list'; f.setAttribute('aria-label', f.title); f.setAttribute('aria-pressed', String(R.railMin)); }
897
+ if (v) { v.title = R.viewMin ? 'Open the viewer' : 'Fold the viewer'; v.setAttribute('aria-label', v.title); v.setAttribute('aria-pressed', String(R.viewMin)); }
898
+ }
899
+ function railDraw() {
900
+ const m = R.model = railModel(R.rows, R.goals, { showAll: R.showAll });
901
+ const l = $('#srlList'); if (l) l.innerHTML = railHtml(m, { sel: R.sel, shut: R.shut, showAll: R.showAll });
902
+ const t = $('#sTease'), tz = teaser(m);
903
+ if (t) {
904
+ t.hidden = !tz || !t.dataset.on || $('#dlg').classList.contains('full');
905
+ if (tz) { $('i', t).className = 'sdot2 ' + tz.dot; $('em', t).textContent = tz.text; t.setAttribute('aria-label', 'Sessions, ' + tz.text + '. Switch between sessions'); t.title = 'Switch between sessions'; t.setAttribute('aria-expanded', String($('#dlg').classList.contains('srl-open'))); }
906
+ }
907
+ sessBadge(menuCount(R.rows));
908
+ }
909
+ async function railRead() {
910
+ const [s, g] = await Promise.all([pmGet('/api/sessions').catch(() => null), pmGet('/api/briefing-premium/goals').catch(() => null)]);
911
+ if (s && Array.isArray(s.sessions)) R.rows = s.sessions;
912
+ if (g && g.ok && g.goals) R.goals = g.goals;
913
+ if (R.sel && !R.rows.some((x) => x.id === R.sel && x.shown !== 'exited') && S.sid === R.sel) { S.sid = null; sessionCard(null); }
914
+ railDraw();
915
+ }
916
+ function railTick() { clearTimeout(R.timer); R.timer = setTimeout(async () => { if (!document.hidden && railShowing()) await railRead(); railTick(); }, SRL_POLL); }
917
+ /** openDlg calls this: a dialog with a conversation shows the chip; the list marks the session this dialog's conversation runs in. */
918
+ function railOnOpen(o) {
919
+ railMount(); clearTimeout(R.sidTimer); S.sid = null; R.ask = null; R.slow = null; R.err = '';
920
+ $('#dlg').classList.remove('srl-open');
921
+ const t = $('#sTease'); if (t) { if (o.noteKey || o.sessions) t.dataset.on = '1'; else delete t.dataset.on; }
922
+ $('#dlg').classList.toggle('srl-on', !!(o.noteKey || o.sessions)); // only a dialog with a conversation gets the list
923
+ R.sel = o.noteKey ? ((R.rows.find((x) => x.origin === 'chat:' + o.noteKey && x.shown !== 'exited') || {}).id || null) : null;
924
+ railLayout(); railDraw(); railRead().then(() => { if (o.noteKey && !R.sel) { R.sel = (R.rows.find((x) => x.origin === 'chat:' + o.noteKey && x.shown !== 'exited') || {}).id || null; railDraw(); } });
925
+ railTick();
926
+ }
927
+ function railOnClose() { clearTimeout(R.timer); clearTimeout(R.sidTimer); S.sid = null; $('#dlg').classList.remove('srl-open'); }
928
+ /** Switch the dialog to one session. A chat row is its own conversation (key); any other session is read from its transcript (S.sid). */
929
+ function pickSession(id) {
930
+ const r = (R.model && R.model.rows.find((x) => x.id === id)) || null; if (!r) return;
931
+ clearTimeout(R.sidTimer); R.sel = id; R.ask = null; R.slow = null; R.err = '';
932
+ $('#dlg').classList.remove('srl-open');
933
+ $('#dEye').textContent = r.group === 'pmos' ? 'Started by PMOS' : r.goal ? 'Goal' : 'Session'; $('#dTitle').textContent = r.name; $('#dSub').hidden = true;
934
+ const st = $('#dBody .stream'); if (st) st.innerHTML = '';
935
+ $('#askF').hidden = !!r.headless; $('#askIn').value = ''; $('#askIn').placeholder = r.key ? 'Message Claude, or type /' : 'Message this session';
936
+ if (r.key) { S.sid = null; S.key = r.key; loadThread(r.key); } else { S.key = null; S.sid = id; loadSid(id); }
937
+ sessionCard(r); railDraw();
938
+ if (!desk()) setTab('chat');
939
+ const go = $('#askIn'); if (go && !r.headless && desk()) go.focus();
940
+ }
941
+ async function loadSid(id) {
942
+ clearTimeout(R.sidTimer);
943
+ const c = await pmGet('/api/sessions/conversation?id=' + encodeURIComponent(id)).catch(() => null);
944
+ if (S.sid !== id) return;
945
+ const box = $('#dBody .stream'); if (!box) return;
946
+ const b = $('#dBody'), atEnd = b.scrollHeight - b.scrollTop - b.clientHeight < 80;
947
+ box.innerHTML = c && c.ok ? sessionHtml(c) : turnA(ptx('The conversation of this session could not be read.'));
948
+ $('#askNote').textContent = c && c.ask ? 'Claude is waiting for your answer above.' : 'Your message goes to this session.';
949
+ if (atEnd) b.scrollTop = b.scrollHeight;
950
+ if (c && c.ok && c.state !== 'ended' && $('#dlg').classList.contains('on')) R.sidTimer = setTimeout(() => loadSid(id), 2000);
951
+ }
952
+ /* the viewer for a session the list opened: its facts, the question a run asks, and Stop (asks first; says so when it has not exited yet) */
953
+ async function sessionCard(r) {
954
+ vwReset(); $('#oLab').textContent = 'Session';
955
+ if (!r) { $('#oMain').innerHTML = '<article class="paper doc"><p class="note">This session has ended. Pick another from the list.</p></article>'; return; }
956
+ const runs = await pmGet('/api/runs').catch(() => null); R.asks = {};
957
+ if (runs && runs.ok && runs.cards) for (const [k, c] of Object.entries(runs.cards)) if (c && c.state === 'asking' && c.ask && c.ask.q && Array.isArray(c.ask.options) && c.ask.options.length) R.asks[k] = { request: c.asked || c.ask.id, q: c.ask.q, options: c.ask.options };
958
+ cardDraw(r);
959
+ }
960
+ function cardDraw(r) {
961
+ if (R.sel !== r.id) return;
962
+ const q = R.asks[r.id], what = r.headless ? 'This ends the background run.' : 'This ends the session and closes its terminal.';
963
+ $('#oMain').innerHTML = `<article class="paper doc scard"><p class="scs"><i class="sdot2 ${DOT[r.state]}" aria-hidden="true"></i>${esc(WORD[r.state])}</p><h3 class="d2">${esc(r.name)}</h3>${kv(factsOf(r))}
964
+ ${q ? `<div class="ssc ssq" role="group" aria-label="${esc(r.name)} asks"><p><b>${esc(q.q)}</b></p><div class="ssx">${q.options.map((o) => `<button type="button" class="cta${o.rec ? '' : ' alt'}" data-ans="${esc(o.label)}"${R.busy ? ' disabled' : ''}>${esc(o.label)}</button>`).join('')}</div></div>` : ''}
965
+ ${R.ask ? `<div class="ssc" role="group" aria-label="Confirm stop"><p><b>Stop “${esc(r.name)}”?</b> ${what} Files it already wrote stay where they are.</p><div class="ssx"><button type="button" class="cta bad" data-yes="1">Stop</button><button type="button" class="cta alt" data-no="1">Keep running</button></div></div>`
966
+ : R.slow ? `<div class="ssc" role="group" aria-label="Still running"><p><b>Asked “${esc(r.name)}” to end.</b> It has not exited yet. Press Stop again to remove it.</p><div class="ssx"><button type="button" class="cta bad" data-yes="1">Stop again</button><button type="button" class="cta alt" data-no="1">Keep running</button></div></div>`
967
+ : `<div class="ssx"><button type="button" class="cta alt" data-stop="1"${R.busy ? ' disabled' : ''}>${R.busy ? 'Ending…' : 'Stop'}</button></div>`}
968
+ <p class="note" role="status">${esc(R.err)}</p><p class="note">Its terminal is in the console. <a href="/console.html">Open the console</a>.</p></article>`;
969
+ }
970
+ $('#oMain').addEventListener('click', async (e) => {
971
+ const card = e.target.closest('.scard'); if (!card || R.busy) return;
972
+ const r = R.model && R.model.rows.find((x) => x.id === R.sel); if (!r) return;
973
+ const an = e.target.closest('[data-ans]'), st = e.target.closest('[data-stop]'), yes = e.target.closest('[data-yes]'), no = e.target.closest('[data-no]');
974
+ R.err = '';
975
+ if (an) {
976
+ const a = R.asks[r.id]; if (!a) return;
977
+ R.busy = true; cardDraw(r);
978
+ const res = await pmPost('/api/runs/answer', { run: r.id, request: a.request, behavior: 'answer', message: an.dataset.ans }); R.busy = false;
979
+ if (res && res.ok) { toast('Answered. The agent continues with your choice.'); delete R.asks[r.id]; } else R.err = (res && (res.error || res.reason)) || 'Not answered.';
980
+ cardDraw(r); return;
981
+ }
982
+ if (st) { R.ask = true; cardDraw(r); const k = $('#oMain [data-no]'); if (k) k.focus(); return; }
983
+ if (no) { R.ask = null; R.slow = null; cardDraw(r); return; }
984
+ if (yes) {
985
+ R.busy = true; R.ask = null; R.slow = null; cardDraw(r);
986
+ const res = await pmPost('/api/session/remove', { id: r.id }); R.busy = false;
987
+ if (res && res.ok && res.removed === false) R.slow = true; // asked to end, not exited yet: say so, never claim an end that did not happen
988
+ else if (res && res.ok) { toast('Ended “' + r.name + '”.'); R.rows = R.rows.filter((x) => x.id !== r.id); if (S.sid === r.id) S.sid = null; R.sel = null; railDraw(); sessionCard(null); railRead(); return; }
989
+ else R.err = (res && (res.error || res.reason)) || 'Not stopped.';
990
+ cardDraw(r);
991
+ }
992
+ });
993
+ function sessBadge(n) { const b = $('#sessBdg'); if (!b) return; b.textContent = String(n || ''); b.hidden = !n; const a = $('#sessBtn'); if (a) a.setAttribute('aria-label', 'Sessions, ' + (n ? n + ' need you' : 'none need you')); }
865
994
  {
866
995
  const b = $('#sessBtn');
867
996
  if (b) {
868
997
  b.onclick = () => openSessions();
869
- const poll = async () => { if (document.hidden) return; const l = await readSessions(); if (l) sessBadge(l.length); };
870
- poll(); setInterval(poll, 15000);
998
+ const poll = async () => { if (document.hidden || railShowing()) return; const s = await pmGet('/api/sessions').catch(() => null); if (s && Array.isArray(s.sessions)) { R.rows = s.sessions; sessBadge(menuCount(R.rows)); } };
999
+ poll(); setInterval(poll, BADGE_POLL);
871
1000
  }
872
1001
  }
1002
+ /** The ⋯ menu's Sessions: the chat panel, full screen with the list (the list itself on a phone), on the session that needs you most. */
873
1003
  export async function openSessions() {
874
- const M = { list: null, ask: null, busy: null, slow: null, done: null, err: '', asks: {}, ans: null };
875
- const draw = () => {
876
- const l = M.list, n = l ? l.length : 0;
877
- $('#dTitle').textContent = l === null ? 'Agent sessions' : n ? n + ' running' : 'None running';
878
- const rows = l === null ? '<p class="note">Reading the sessions.</p>' : n ? `<ul class="ssl">${l.map((x) => {
879
- if (M.done && M.done.id === x.id) return `<li class="ssr"><p class="ssdone">Ended “${esc(x.name)}”.</p></li>`;
880
- const busy = M.busy === x.id, ask = M.ask === x.id, slow = M.slow === x.id;
881
- const what = x.headless ? 'This ends the background run.' : 'This ends the session and closes its terminal.';
882
- return `<li class="ssr"${busy ? ' aria-busy="true"' : ''}><i class="ssd ${esc(x.shown || '')}" aria-hidden="true"></i>
883
- <div class="ssb"><h3>${esc(x.name)}</h3><p class="ssn">${esc(x.note || 'No note')}</p>
884
- <p class="ssm">${[x.headless ? 'Background run' : '', x.agent, x.label, x.cwd, sessAgo(x.created), x.automatic ? 'Started by PMOS' : ''].filter(Boolean).map((t) => `<span>${esc(t)}</span>`).join('')}</p></div>
885
- <button type="button" class="cta alt" data-stop="${esc(x.id)}" aria-label="Stop ${esc(x.name)}"${ask || busy || slow ? ' disabled' : ''}>${busy ? 'Ending…' : 'Stop'}</button>
886
- ${M.asks[x.id] ? `<div class="ssc ssq" role="group" aria-label="${esc(x.name)} asks"><p><b>${esc(M.asks[x.id].q)}</b></p><div class="ssx">${M.asks[x.id].options.map((o) => `<button type="button" class="cta${o.rec ? '' : ' alt'}" data-ans="${esc(x.id)}" data-opt="${esc(o.label)}"${M.ans ? ' disabled' : ''}>${esc(o.label)}</button>`).join('')}</div></div>` : ''}
887
- ${ask && !busy ? `<div class="ssc" role="group" aria-label="Confirm stop"><p><b>Stop “${esc(x.name)}”?</b> ${what} Files it already wrote stay where they are.</p><div class="ssx"><button type="button" class="cta bad" data-yes="${esc(x.id)}">Stop</button><button type="button" class="cta alt" data-no="${esc(x.id)}">Keep running</button></div></div>` : ''}
888
- ${slow ? `<div class="ssc" role="group" aria-label="Still running"><p><b>Asked “${esc(x.name)}” to end.</b> It has not exited yet. Press Stop again to remove it.</p><div class="ssx"><button type="button" class="cta bad" data-yes="${esc(x.id)}">Stop again</button><button type="button" class="cta alt" data-no="${esc(x.id)}">Keep running</button></div></div>` : ''}</li>`;
889
- }).join('')}</ul>` : '<div class="sse"><b>No agent sessions running.</b><p>New sessions start in the console.</p></div>';
890
- const w = l ? sessWorking(l) : 0;
891
- const warn = w > SESS_MANY ? `<p class="note ssw" role="status"><b>${w} agents are working at once.</b> Each one is a program running on this computer, so many at once can slow it. Stop the ones you are not watching.</p>` : '';
892
- $('#oMain').innerHTML = `<article class="paper doc"><div class="addf">${warn}${rows}
893
- <p class="note" id="ssM" role="status" style="margin:0;min-height:1.2em">${esc(M.err)}</p>
894
- <p class="note" style="margin:0">Terminals and new sessions stay in the console. <a href="/console.html">Open the console</a>.</p></div></article>`;
895
- };
896
- openDlg({ eye: 'Agent sessions · real data', title: 'Agent sessions', say: 'The sessions running now. Stop ends one.', stream: turnA(ptx('The sessions running now, read from the same list the console shows. Stop ends one and says so.')), noteKey: null, pane: '<article class="paper doc"></article>', label: 'Sessions' });
897
- $('#askF').hidden = true; setMode('detail'); draw();
898
- const load = async () => { M.list = await readSessions(); M.asks = M.list ? await readAsks() : {}; if (M.list === null) { M.list = []; M.err = 'The sessions could not be read.'; } else sessBadge(M.list.length); draw(); };
899
- const focusNext = () => { const b = $('#oMain [data-stop]:not([disabled])') || $('#dTitle'); if (b) b.focus(); };
900
- $('#oMain').onclick = async (e) => {
901
- if (M.busy) return;
902
- const an = e.target.closest('[data-ans]');
903
- if (an) {
904
- const id = an.dataset.ans, a = M.asks[id]; if (!a) return;
905
- M.ans = id; M.err = ''; draw();
906
- const r = await pmPost('/api/runs/answer', { run: id, request: a.request, behavior: 'answer', message: an.dataset.opt }); M.ans = null;
907
- if (r && r.ok) { toast('Answered. The agent continues with your choice.'); delete M.asks[id]; } else M.err = (r && (r.error || r.reason)) || 'Not answered.';
908
- draw(); return;
909
- }
910
- const st = e.target.closest('[data-stop]'), yes = e.target.closest('[data-yes]'), no = e.target.closest('[data-no]');
911
- M.err = '';
912
- if (st) { M.ask = st.dataset.stop; M.slow = null; draw(); const k = $(`#oMain [data-no="${M.ask}"]`); if (k) k.focus(); }
913
- else if (no) { const id = no.dataset.no; M.ask = null; M.slow = null; draw(); const b = $(`#oMain [data-stop="${id}"]`); if (b) b.focus(); }
914
- else if (yes) {
915
- const id = yes.dataset.yes, x = M.list.find((y) => y.id === id); if (!x) return;
916
- M.busy = id; M.ask = null; M.slow = null; draw();
917
- const r = await pmPost('/api/session/remove', { id }); M.busy = null;
918
- if (r && r.ok && r.removed === false) M.slow = id; // asked to end, not exited yet: say so, never claim an end that did not happen
919
- else if (r && r.ok) { M.done = x; toast('Ended “' + x.name + '”.'); } else M.err = (r && (r.error || r.reason)) || 'Not stopped.';
920
- draw();
921
- if (M.done) setTimeout(async () => { M.done = null; await load(); focusNext(); }, 1600);
922
- else if (M.slow) { const b = $(`#oMain [data-yes="${id}"]`); if (b) b.focus(); }
923
- }
924
- };
925
- await load();
1004
+ openDlg({ eye: 'Sessions', title: 'Sessions', say: 'Pick a session from the list.', stream: turnA(ptx('Pick a session from the list. A dot shows its state: Ready, Running or Maybe blocked.')), noteKey: null, sessions: true, pane: '<article class="paper doc"><p class="note">Pick a session from the list.</p></article>', label: 'Session' });
1005
+ $('#askF').hidden = true;
1006
+ if (desk()) setFull(true); else $('#dlg').classList.add('srl-open');
1007
+ await railRead();
1008
+ if (!R.sel) $('#dTitle').textContent = titleOf(R.model);
1009
+ const top = loudestRow(R.model);
1010
+ if (top && desk()) pickSession(top.id);
926
1011
  }
@@ -174,3 +174,7 @@
174
174
  @media (max-width:640px){.vwchip,.vwli>button{min-height:44px}}
175
175
  @media (hover:hover){.vwbtn:hover{background:var(--well)}.cf a:hover{text-decoration:underline}.vwtb:hover{background:var(--well);color:var(--ink)}.vwpop button:hover{background:var(--well)}.vwxmn a:hover{background:var(--well)}.vwli>button:hover{background:var(--well)}}
176
176
  .cfb .vwcm{display:none}
177
+ /* an .html file Claude named: the page itself in a sandboxed frame (premium-vw-file.js), as wide as the viewer and nearly as tall */
178
+ .vwdoc.vwhtml{max-width:none}
179
+ .vwhtml .vwdt{margin:12px 0}
180
+ .vwframe{display:block;width:100%;height:max(420px,calc(100dvh - 260px));border:1px solid var(--hair);border-radius:8px}