create-pmos 0.355.0 → 0.357.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-pmos",
3
- "version": "0.355.0",
3
+ "version": "0.357.0",
4
4
  "description": "Scaffold the PMOS portable kit — run the PMOS product-management workflow (initiative → lane-fit spec → contract → build → three gates, with work-type lanes for features, research, maintenance, incidents, and content) entirely inside your own repo, with all state as git-versioned files. Includes `workflow-sweep`, which audits the state every board derives from and separates real defects from work you simply have not done. `create-pmos workspace` also installs + launches the local Terminal Workspace GUI. No database, no network, no telemetry.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -32,6 +32,35 @@
32
32
  "audit"
33
33
  ],
34
34
  "pmosChanges": [
35
+ {
36
+ "v": "0.357.0",
37
+ "at": "2026-10-20T09:57:04.765Z",
38
+ "f": 2,
39
+ "prs": [
40
+ {
41
+ "n": 956,
42
+ "t": "End sessions from the list; idle shells fold into one line",
43
+ "s": "Every row has an End button (×) on hover, on focus and always on touch screens."
44
+ }
45
+ ]
46
+ },
47
+ {
48
+ "v": "0.356.0",
49
+ "at": "2026-10-20T09:37:44.880Z",
50
+ "f": 2,
51
+ "prs": [
52
+ {
53
+ "n": 955,
54
+ "t": "Full-screen chat is never blank when the viewer is folded",
55
+ "s": "The panel always shows something."
56
+ },
57
+ {
58
+ "n": 957,
59
+ "t": "A live premium chat stops blinking beside the viewer",
60
+ "s": "The conversation stays still."
61
+ }
62
+ ]
63
+ },
35
64
  {
36
65
  "v": "0.355.0",
37
66
  "at": "2026-10-20T09:07:17.325Z",
@@ -262,30 +291,6 @@
262
291
  "s": "Typing / opens a short menu with /goal, /compact and /clear."
263
292
  }
264
293
  ]
265
- },
266
- {
267
- "v": "0.337.0",
268
- "at": "2026-10-20T02:07:25.408Z",
269
- "f": 2,
270
- "prs": [
271
- {
272
- "n": 832,
273
- "t": "Soft warning in the Sessions dialog when more than six agents work",
274
- "s": "When more than six sessions are in the working state, the dialog shows one note above the list: \"N agents are working at once."
275
- }
276
- ]
277
- },
278
- {
279
- "v": "0.336.0",
280
- "at": "2026-10-20T01:42:17.900Z",
281
- "f": 2,
282
- "prs": [
283
- {
284
- "n": 931,
285
- "t": "Every premium chat panel is a real Claude Code session",
286
- "s": "The first message in a dialog starts one interactive Claude Code session for that row, with the PM's own login, model and permission settings."
287
- }
288
- ]
289
294
  }
290
295
  ]
291
296
  }
@@ -1,3 +1,3 @@
1
- kernel-source: pmos@376fcf1e
1
+ kernel-source: pmos@b76d4b35
2
2
  assembled: 2026-10-20
3
3
  mode: vendor
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Eval calibration log"
4
4
  description: "Append-only record of every PM override of an evaluator verdict."
5
- generated: {by: process:create-pmos, at: "2026-10-20T09:07:14Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-20T09:57:01Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Health budgets"
4
4
  description: "Closed registry of health-budget anchors (D59), edited only by the PM."
5
- generated: {by: process:create-pmos, at: "2026-10-20T09:07:14Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-20T09:57:01Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -2,7 +2,7 @@
2
2
  type: Reference
3
3
  title: "Discoveries and friction log"
4
4
  description: "Append-only record of what runs discovered and where the process rubbed."
5
- generated: {by: process:create-pmos, at: "2026-10-20T09:07:14Z"}
5
+ generated: {by: process:create-pmos, at: "2026-10-20T09:57:01Z"}
6
6
  status: stable
7
7
  ---
8
8
 
@@ -190,6 +190,15 @@ const MOCKUP = path.join(__dirname, '..', 'prototype', 'premium-ux-concept', 'br
190
190
  await p.click('#vFold');
191
191
  const vf = await until(() => p.evaluate(() => { const w = document.querySelector('#dOut').getBoundingClientRect().width; return w > 0 && w < 70 ? Math.round(w) : 0; }), 4000);
192
192
  ok('X13 the viewer folds and the conversation takes the width', vf > 0 && (await p.evaluate(() => document.querySelector('#dBody').getBoundingClientRect().width)) > 800, String(vf));
193
+ /* premium-fullscreen-blank: the folded viewer is a strip that opens again from anywhere on it, and folding never empties the panel */
194
+ const strip = await p.evaluate(() => { const r = document.querySelector('#dOut').getBoundingClientRect(); return { x: r.left + r.width / 2, y: r.top + r.height * 0.6 }; });
195
+ await p.mouse.click(strip.x, strip.y);
196
+ ok('X13b a press anywhere on the folded viewer strip opens the viewer again', !!(await until(() => p.evaluate(() => document.querySelector('#dOut').getBoundingClientRect().width > 300 && !document.querySelector('#dlg').classList.contains('vw-min')), 4000)));
197
+ await p.click('#vFold');
198
+ await p.click('#dExpand'); await p.click('#dPane'); await p.click('#dExpand');
199
+ const det = await until(() => p.evaluate(() => { const d = document.querySelector('#dlg'), o = document.querySelector('#oMain').getBoundingClientRect(); return d.classList.contains('full') && d.dataset.mode === 'detail' && o.width > 300 && o.height > 0 ? { out: Math.round(o.width), fold: getComputedStyle(document.querySelector('#vFold')).display } : null; }), 4000);
200
+ ok('X13c with the conversation hidden, a folded viewer still shows: full screen is never blank', det && det.fold === 'none', JSON.stringify(det));
201
+ await p.click('#dPane');
193
202
  await p.click('#srlFold'); await p.click('#vFold');
194
203
  /* the soft warning: silent at 6 working agents, speaks at 7, at the top of the list */
195
204
  const before = fake.slice();
@@ -1,4 +1,33 @@
1
1
  [
2
+ {
3
+ "v": "0.357.0",
4
+ "at": "2026-10-20T09:57:04.765Z",
5
+ "f": 2,
6
+ "prs": [
7
+ {
8
+ "n": 956,
9
+ "t": "End sessions from the list; idle shells fold into one line",
10
+ "s": "Every row has an End button (×) on hover, on focus and always on touch screens."
11
+ }
12
+ ]
13
+ },
14
+ {
15
+ "v": "0.356.0",
16
+ "at": "2026-10-20T09:37:44.880Z",
17
+ "f": 2,
18
+ "prs": [
19
+ {
20
+ "n": 955,
21
+ "t": "Full-screen chat is never blank when the viewer is folded",
22
+ "s": "The panel always shows something."
23
+ },
24
+ {
25
+ "n": 957,
26
+ "t": "A live premium chat stops blinking beside the viewer",
27
+ "s": "The conversation stays still."
28
+ }
29
+ ]
30
+ },
2
31
  {
3
32
  "v": "0.355.0",
4
33
  "at": "2026-10-20T09:07:17.325Z",
@@ -31,7 +31,9 @@ Every premium page has the same top bar. On the left is where you are, then a ro
31
31
  - **Groups.** **Goals** holds a chat whose goal is started or waiting on you. **Yours** holds the other sessions you started. **Started by PMOS** holds schedules, the day run, the Driver, the Checker, notes, document syncs and other background runs. A PMOS session shows only when it needs you. The rest fold into one line, "N more working on their own · Show".
32
32
  - **Dots.** An orange dot means **Ready**: the session finished its turn and waits for you. A green dot means **Running**. An orange ring means **Maybe blocked**: a call is open and nothing moves, often a permission question. No dot means idle. Ready sessions come first and are bold. Hold the pointer over a row to see its state in words.
33
33
  - **Switch.** Press a row to switch the dialog to that session. A chat opens its own conversation. Any other session shows its conversation from Claude Code's record. You can write to it and answer its permission questions, as in a chat. The viewer shows the session's facts, the question a background run asks with the options it offered, and **Stop**. Stop asks first, and if the session has not exited yet it says so and offers Stop again.
34
- - **Fold.** The button at the top of the list folds it to a strip of icons with dots. The button at the top of the viewer folds the viewer, so the conversation gets the width. PMOS remembers both in this browser.
34
+ - **Fold.** The button at the top of the list folds it to a strip of icons with dots. The button at the top of the viewer folds the viewer to a strip, so the conversation gets the width; press anywhere on the strip to open the viewer again. PMOS remembers both in this browser. When the conversation is hidden, the viewer always shows, so the panel is never empty.
35
+ - **End.** Every row has an **End** button (×) on its right: it shows when the pointer is over the row, and always on a touch screen. An idle session ends at once. A session that is Running, Ready or Maybe blocked asks first, in the row, with **End** and **Keep**. Ending stops the process and removes the row; files it already wrote stay. If it has not exited yet, the toast says so and the row stays.
36
+ - **Idle shells.** A terminal shell with no agent in it and no output for a while folds under **Yours** into one line, "N more idle · Show", with **End all idle**. End all idle ends only those shells, never a goal or a session that needs you. PMOS opens one shell when it starts with no live session; it now checks after your sessions come back, so a restart no longer adds a shell each time.
35
37
  - **When the chat is not full screen,** a chip in the dialog's header shows the loudest dot and, for example, "2 ready". Press it to go full screen with the list. On a phone, it opens the list over the dialog, and a tap on a row switches to that session.
36
38
  - **Sessions in the ⋯ menu** counts the sessions that are Ready or Maybe blocked. It opens the dialog full screen on the session that needs you most. On a phone, it opens the list.
37
39
  - When more than six agents are working at once, a note at the top of the list says how many, and suggests stopping the ones you are not watching. Nothing is stopped for you.
@@ -401,6 +403,7 @@ The conversation beside every premium dialog is a real Claude Code session. Anyt
401
403
  - **What it may do** is set by your own Claude Code settings. Claude can change files and run commands. When your settings say to ask first, the question shows in the panel with its options; press one to answer.
402
404
  - **Stop** shows while Claude works. It presses Esc in the session.
403
405
  - **The conversation** is Claude Code's own record, word for word. Claude's answers are formatted as Claude Code formats them: headings, bold, lists, code, tables, quotes and links (links open in a new tab). Your messages keep their line breaks, and a paste shows without the tags Claude Code wraps around it. A run of tool calls shows as one small grey line, for example "Used Read ×2, slack_read_thread". A connector tool shows its short name.
406
+ - **While a session runs**, the panel reads it again every 2 seconds and changes only when there is something new. The messages already on screen stay still, so nothing blinks beside the viewer.
404
407
  - **A file Claude names** (a path such as `briefs/drafts/plan.md`, or a link to one) is underlined. Press it to read the file beside the conversation, as a tab in the viewer; on a phone, the Detail side shows it. Markdown shows as a page, an HTML file shows as the page it draws (press **Source** for its code), and other text files show as code. An HTML page runs its own scripts, so its toggles and charts work, but it cannot reach PMOS or the internet: a web font falls back to the system font. It is read-only. While the tab is open it shows the newest version, so a file Claude is still writing stays current. A file outside the workspaces PMOS serves says "Not in a workspace" and is not read.
405
408
  - **A link to a Google Doc or a Confluence page** opens beside the conversation too, as the viewer shows a copy: the text PMOS has read, or **Read it now**. **A Claude artifact link** opens a tab with **Open in Claude**: claude.ai does not let another site show an artifact inside it. Other links open in a new browser tab.
406
409
  - **The session** is also listed in **Sessions** and in the console, where you can open its terminal. When it has ended, your next message starts a new one.
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+ /* lib/first-shell.js — the shell the workspace opens at startup so it is never empty (premium-session-end).
3
+ * Asked only after the restore has finished: before, the running server checked while its sessions were still coming back,
4
+ * saw no live pane on every launch and spawned one more `shell`, which tmux kept. One idle shell per restart piled up in the list. */
5
+ function firstShell(list, { canHost, spawn }) {
6
+ if (!canHost || [...(list || [])].some((s) => s && s.pty)) return false;
7
+ spawn();
8
+ return true;
9
+ }
10
+ module.exports = { firstShell };
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "pmos-workspace",
3
- "version": "0.355.0",
3
+ "version": "0.357.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "pmos-workspace",
9
- "version": "0.355.0",
9
+ "version": "0.357.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.355.0",
3
+ "version": "0.357.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,114 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /* premium-viewer-flicker-test.js — the premium dialog stays still while a live chat is open beside an .html file in the viewer (bug 2026-10-20:
4
+ * "When I have Viewer opened, let's say showing HTML file, the PMOS is flickering"). A live chat re-reads its conversation every 2 seconds and
5
+ * the session list every 3. Each read wrote the whole conversation back with innerHTML even when nothing had changed, so every turn was a new
6
+ * node and replayed its `rise` entrance (opacity 0 and a blur): the conversation blinked every 2 seconds beside the report.
7
+ * public/pm/premium-shell.js now writes the conversation and the list only when their HTML changed, and a redraw of a conversation already
8
+ * on screen does not replay the entrance. The real premium page and server; the thread, conversation and file reads are routed.
9
+ * F1 while nothing changes, the turns stay the same nodes and no entrance replays, over several polls
10
+ * F2 the viewer's frame is the same frame and is never reloaded
11
+ * F3 a new message still shows, and the turns already on screen do not replay their entrance
12
+ * PMOS_SHOTS=<dir> also saves the dialog at 1280 and 390, light and dark. */
13
+ const fs = require('fs');
14
+ const path = require('path');
15
+ const { spawn } = require('child_process');
16
+ const { findBrowser } = require('./lib/find-browser');
17
+ const T = require('./test-run').configure({ name: 'premium-viewer-flicker' });
18
+
19
+ const BASE = T.BASE;
20
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
21
+ 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); } };
22
+ const results = [];
23
+ const ok = (name, cond, extra = '') => { results.push({ name, cond: !!cond }); console.log(`${cond ? '✓' : '✗'} ${name}${!cond && extra !== '' ? ' — ' + String(extra).slice(0, 600) : ''}`); };
24
+ let srv = null; let browser = null;
25
+ const finish = async (code) => {
26
+ if (browser) await browser.close().catch(() => {});
27
+ if (srv) { try { srv.kill('SIGKILL'); } catch { /* gone */ } }
28
+ T.killTmux();
29
+ const bad = results.filter((x) => !x.cond).length;
30
+ console.log(`\n${results.length - bad}/${results.length} premium-viewer-flicker assertions passed`);
31
+ process.exit(code !== undefined ? code : (bad ? 1 : 0));
32
+ };
33
+ process.on('unhandledRejection', (e) => { console.error(e); finish(1); });
34
+
35
+ const REPORT = fs.readFileSync(path.join(__dirname, 'fixtures', 'html-viewer-report.html'), 'utf8');
36
+ const HTMLF = 'pmos/state/reports/lightbox-password-conversion/2026-10-19.html';
37
+ const SHOTS = process.env.PMOS_SHOTS || '';
38
+
39
+ (async () => {
40
+ const exe = findBrowser();
41
+ if (!exe) { console.log('✗ no Chrome/Chromium on this machine — the premium-viewer-flicker suite cannot run'); return finish(1); }
42
+ let chromium;
43
+ try { ({ chromium } = require('playwright-core')); } catch { console.log('✗ playwright-core is not installed — the premium-viewer-flicker suite cannot run'); return finish(1); }
44
+ srv = spawn(process.execPath, [path.join(__dirname, 'server.js')], { cwd: __dirname, stdio: 'ignore', env: T.env({ PMOS_WS_PORT: String(T.PORT) }) });
45
+ await T.waitForServer(BASE);
46
+ browser = await chromium.launch({ executablePath: exe });
47
+
48
+ const open = async ({ w = 1280, h = 900, theme = 'light' } = {}) => {
49
+ const ctx = await browser.newContext({ viewport: { width: w, height: h }, colorScheme: theme });
50
+ const page = await ctx.newPage();
51
+ const errors = [];
52
+ page.on('pageerror', (e) => errors.push(String((e && e.message) || e)));
53
+ const conv = { ok: true, state: 'conv', turn: 'user', messages: [
54
+ { role: 'user', text: 'Write the funnel report as an HTML file.' },
55
+ { role: 'assistant', text: 'The report is at `' + HTMLF + '`.' },
56
+ ] };
57
+ const json = (body) => (r) => r.fulfill({ contentType: 'application/json', body: JSON.stringify(typeof body === 'function' ? body() : body) });
58
+ await page.route('**/api/brief-page*', json({ ok: false, error: 'off in this suite' }));
59
+ await page.route('**/api/briefing-premium/thread*', json({ ok: true, session: 's-flicker', turns: [] }));
60
+ await page.route('**/api/sessions/conversation*', json(() => conv));
61
+ await page.route('**/api/sessions', json({ sessions: [{ id: 's-flicker', origin: 'chat:k-flicker', name: 'Funnel report', shown: 'running', state: 'running' }] }));
62
+ await page.route('**/api/doc/locate*', json({ ok: true, ws: 'w0', rel: HTMLF, abs: '/Users/pm/pmos/' + HTMLF, name: '2026-10-19.html', mtime: 1, size: REPORT.length }));
63
+ await page.route('**/api/doc?*', (r) => r.fulfill({ status: 200, contentType: 'text/plain', headers: { 'X-Doc-Kind': 'html' }, body: REPORT }));
64
+ await page.goto(BASE + '/premium.html?theme=' + theme);
65
+ await until(() => page.evaluate(() => !!document.querySelector('#dlg')), 15000);
66
+ await page.evaluate(async () => {
67
+ const S = await import('/pm/premium-shell.js');
68
+ S.openDlg({ eye: 'Your item', title: 'Funnel report', say: 'Ask about the report.', noteKey: 'k-flicker', pane: '<article class="paper doc"><p>Item record</p></article>', label: 'Item record' });
69
+ S.loadThread('k-flicker');
70
+ });
71
+ const fp = await until(() => page.$('#dBody .stream button.fpath[data-file]'), 8000);
72
+ if (fp) await fp.evaluate((b) => b.click()); // on a phone the dialog opens on the Detail side, so the press goes through the button's own handler
73
+ return { ctx, page, errors, conv };
74
+ };
75
+
76
+ {
77
+ const { page, errors, conv, ctx } = await open();
78
+ const fr = await until(() => page.$('#dOut .obody.vw iframe.vwframe'), 8000);
79
+ ok('the chat names the report and the press opens it in the viewer as a frame', !!fr);
80
+ await sleep(1500); // the first draw's entrance has played
81
+ await page.evaluate(() => {
82
+ window.__rise = 0; window.__loads = 0; window.__frame = document.querySelector('#dOut .obody.vw iframe.vwframe');
83
+ window.__turns = [...document.querySelectorAll('#dBody .stream .turn')];
84
+ document.querySelector('#dBody').addEventListener('animationstart', (e) => { if (e.animationName === 'rise') window.__rise++; });
85
+ if (window.__frame) window.__frame.addEventListener('load', () => { window.__loads++; });
86
+ });
87
+ await sleep(7000); // three conversation reads and two list reads
88
+ const st = await page.evaluate(() => ({ rise: window.__rise, turns: window.__turns.length, same: window.__turns.every((t) => t.isConnected), frame: window.__frame === document.querySelector('#dOut .obody.vw iframe.vwframe'), loads: window.__loads }));
89
+ ok('F1 while nothing changes, the turns stay the same nodes over several reads', st.turns >= 2 && st.same, JSON.stringify(st));
90
+ ok('F1 no turn replays its entrance while nothing changes', st.rise === 0, JSON.stringify(st));
91
+ ok('F2 the viewer keeps the same frame and never reloads it', st.frame && st.loads === 0, JSON.stringify(st));
92
+ conv.messages.push({ role: 'user', text: 'Add the weekly view.' }, { role: 'assistant', text: 'Added the weekly view.' });
93
+ const got = await until(() => page.evaluate(() => /Added the weekly view/.test(document.querySelector('#dBody .stream').textContent)), 6000);
94
+ await sleep(800);
95
+ const st2 = await page.evaluate(() => ({ rise: window.__rise, frame: window.__frame === document.querySelector('#dOut .obody.vw iframe.vwframe'), loads: window.__loads }));
96
+ ok('F3 a new message still shows in the conversation', !!got);
97
+ ok('F3 the redraw for it does not replay the entrance of the turns on screen', st2.rise === 0, JSON.stringify(st2));
98
+ ok('F3 the viewer frame is untouched by the new message', st2.frame && st2.loads === 0, JSON.stringify(st2));
99
+ ok('no page errors', errors.length === 0, errors.join(' | '));
100
+ await ctx.close();
101
+ }
102
+
103
+ if (SHOTS) {
104
+ for (const [w, h] of [[1280, 900], [390, 844]]) for (const theme of ['light', 'dark']) {
105
+ const { page, ctx } = await open({ w, h, theme });
106
+ await until(() => page.$('#dOut .obody.vw iframe.vwframe'), 8000);
107
+ await sleep(1500);
108
+ fs.mkdirSync(SHOTS, { recursive: true });
109
+ await page.screenshot({ path: path.join(SHOTS, `after-${w}-${theme}.png`) });
110
+ await ctx.close();
111
+ }
112
+ }
113
+ return finish();
114
+ })();
@@ -8,7 +8,7 @@ import { lineItems, behindOf, refreshTargets, whenRead } from './freshness-words
8
8
  import { splitGoal, shownUser, goalBlockHtml, goalProgressHtml, slashMatches } from './goal-chat.js';
9
9
  import { mdHtml, userHtml, toolLine, webKind } from './chat-md.js';
10
10
  import { padMarkup, padChipMarkup, mountPad, flushPad } from './premium-pad.js';
11
- import { railModel, railHtml, teaser, menuCount, loudestRow, factsOf, titleOf, DOT, WORD } from './session-rail.js';
11
+ import { railModel, railHtml, teaser, menuCount, loudestRow, factsOf, titleOf, endAsks, DOT, WORD } from './session-rail.js';
12
12
  export const $ = (s, r = document) => r.querySelector(s);
13
13
  export const $$ = (s, r = document) => [...r.querySelectorAll(s)];
14
14
  export const esc = (s) => String(s == null ? '' : s).replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
@@ -285,12 +285,22 @@ export function sessionHtml(c, goal = null) {
285
285
  return out.join('');
286
286
  }
287
287
  let threadTimer = null;
288
+ /* A live chat re-reads its conversation every 2 s and the session list every 3 s. Writing the same HTML back made every turn a new node that replayed
289
+ * its `rise` entrance, so the panel blinked beside the viewer (bug 2026-10-20). putHtml writes only what changed, and a redraw of a box already
290
+ * drawn carries .still, so the turns on screen do not replay their entrance. */
291
+ function putHtml(el, html) {
292
+ if (el.__h === html) return false;
293
+ if (el.__h !== undefined) el.classList.add('still');
294
+ el.__h = html; el.innerHTML = html;
295
+ return true;
296
+ }
297
+ function clearHtml(el) { el.__h = undefined; el.classList.remove('still'); el.innerHTML = ''; }
288
298
  export function drawThread(th, key, conv) {
289
299
  if (S.key !== key) return;
290
300
  const box = $('#dBody .stream'); if (!box) return;
291
301
  let t = $('#thr', box); if (!t) { box.insertAdjacentHTML('beforeend', '<div id="thr"></div>'); t = $('#thr', box); }
292
302
  const b = $('#dBody'), atEnd = b.scrollHeight - b.scrollTop - b.clientHeight < 80;
293
- t.innerHTML = threadHtml(th) + sessionHtml(conv, th.goal);
303
+ putHtml(t, threadHtml(th) + sessionHtml(conv, th.goal));
294
304
  S.goal = th.goal || null; S.draft = readyDraft(conv); S.session = th.session || null;
295
305
  const go = $('#askGo'); if (go) go.disabled = !!th.working; // an earlier read-only run still answering
296
306
  const n = $('#askNote'); if (n) n.textContent = th.working ? 'The agent is answering. You can write again when it has.' : conv && conv.ask ? 'Claude is waiting for your answer above.' : CHAT_NOTE;
@@ -874,7 +884,7 @@ export async function openSettings() {
874
884
  * conversations; lib/session-rail.js groups them. Pressing a row switches the dialog to that session: a chat row opens its own conversation,
875
885
  * 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)
876
886
  * 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. */
877
- const R = { rows: [], goals: {}, model: null, sel: null, shut: [], showAll: false, timer: null, asks: {}, ask: null, busy: false, slow: null, err: '', sidTimer: null,
887
+ const R = { rows: [], goals: {}, model: null, sel: null, shut: [], showAll: false, showIdle: false, ending: null, timer: null, asks: {}, ask: null, busy: false, slow: null, err: '', sidTimer: null,
878
888
  railMin: store.get('pmos.srl.rail') === 'min', viewMin: store.get('pmos.srl.view') === 'min' };
879
889
  const SRL_POLL = 3000, BADGE_POLL = 15000;
880
890
  const desk = () => innerWidth >= 1000;
@@ -886,6 +896,7 @@ function railMount() {
886
896
  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>');
887
897
  $('#srlFold').onclick = () => { R.railMin = !R.railMin; store.set('pmos.srl.rail', R.railMin ? 'min' : 'open'); railLayout(); };
888
898
  $('#vFold').onclick = () => { R.viewMin = !R.viewMin; store.set('pmos.srl.view', R.viewMin ? 'min' : 'open'); railLayout(); };
899
+ $('#dOut').addEventListener('click', (e) => { if (R.viewMin && $('#dlg').classList.contains('full') && desk() && !e.target.closest('#vFold')) $('#vFold').click(); }); // the whole folded strip opens the viewer again
889
900
  $('#sTease').onclick = () => {
890
901
  if (desk()) { setFull(true); railLayout(); railRead(); return; }
891
902
  $('#dlg').classList.toggle('srl-open'); railDraw(); if ($('#dlg').classList.contains('srl-open')) railRead();
@@ -893,6 +904,12 @@ function railMount() {
893
904
  $('#srlList').onclick = (e) => {
894
905
  const gh = e.target.closest('[data-sg]'), mo = e.target.closest('[data-smore]'), r = e.target.closest('[data-sid]');
895
906
  if (mo) { R.showAll = !R.showAll; railDraw(); return; }
907
+ const x = e.target.closest('[data-end]'), yes = e.target.closest('[data-endyes]'), no = e.target.closest('[data-endno]'), si = e.target.closest('[data-sidle]'), ei = e.target.closest('[data-endidle]');
908
+ if (si) { R.showIdle = !R.showIdle; railDraw(); return; }
909
+ if (no) { R.ending = null; railDraw(); return; }
910
+ if (x) { const row = R.model && R.model.rows.find((y) => y.id === x.dataset.end); if (!row) return; if (endAsks(row)) { R.ending = row.id; railDraw(); const k = $('#srlList [data-endno]'); if (k) k.focus(); } else endRows([row]); return; }
911
+ if (yes) { const row = R.model && R.model.rows.find((y) => y.id === yes.dataset.endyes); R.ending = null; if (row) endRows([row]); else railDraw(); return; }
912
+ if (ei) { endRows((R.model && R.model.idle) || []); return; }
896
913
  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; }
897
914
  if (r) pickSession(r.dataset.sid);
898
915
  };
@@ -904,9 +921,27 @@ function railLayout() {
904
921
  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)); }
905
922
  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)); }
906
923
  }
924
+ /* premium-session-end: End from the list. The same POST /api/session/remove as the viewer's Stop; an idle row ends at once, any other row asked
925
+ * first (R.ending). "End all idle" ends only the folded idle shells, never a goal or a session that needs the PM. A session that has not exited
926
+ * yet stays listed and says so; it is never claimed ended. */
927
+ async function endRows(rows) {
928
+ if (!rows.length || R.busy) return;
929
+ R.busy = true;
930
+ const res = await Promise.all(rows.map((r) => pmPost('/api/session/remove', { id: r.id }).catch(() => null)));
931
+ R.busy = false;
932
+ const gone = rows.filter((r, i) => res[i] && res[i].ok && res[i].removed !== false), ids = new Set(gone.map((r) => r.id));
933
+ R.rows = R.rows.filter((x) => !ids.has(x.id));
934
+ if (R.sel && ids.has(R.sel)) { if (S.sid === R.sel) S.sid = null; R.sel = null; sessionCard(null); }
935
+ const left = rows.length - gone.length;
936
+ if (rows.length === 1) toast(gone.length ? 'Ended “' + rows[0].name + '”.' : 'Asked “' + rows[0].name + '” to end. It has not exited yet; press End again.');
937
+ else toast('Ended ' + gone.length + (gone.length === 1 ? ' idle session' : ' idle sessions') + '.' + (left ? ' ' + left + ' did not exit yet.' : ''));
938
+ if (!R.model || !R.rows.some((x) => x.agent === 'shell' && x.shown === 'quiet')) R.showIdle = false;
939
+ railDraw(); railRead();
940
+ }
907
941
  function railDraw() {
908
- const m = R.model = railModel(R.rows, R.goals, { showAll: R.showAll });
909
- const l = $('#srlList'); if (l) l.innerHTML = railHtml(m, { sel: R.sel, shut: R.shut, showAll: R.showAll });
942
+ const m = R.model = railModel(R.rows, R.goals, { showAll: R.showAll, showIdle: R.showIdle });
943
+ if (R.ending && !m.rows.some((x) => x.id === R.ending)) R.ending = null;
944
+ const l = $('#srlList'); if (l) putHtml(l, railHtml(m, { sel: R.sel, shut: R.shut, showAll: R.showAll, showIdle: R.showIdle, ending: R.ending }));
910
945
  const t = $('#sTease'), tz = teaser(m);
911
946
  if (t) {
912
947
  t.hidden = !tz || !t.dataset.on || $('#dlg').classList.contains('full');
@@ -939,7 +974,7 @@ function pickSession(id) {
939
974
  clearTimeout(R.sidTimer); R.sel = id; R.ask = null; R.slow = null; R.err = '';
940
975
  $('#dlg').classList.remove('srl-open');
941
976
  $('#dEye').textContent = r.group === 'pmos' ? 'Started by PMOS' : r.goal ? 'Goal' : 'Session'; $('#dTitle').textContent = r.name; $('#dSub').hidden = true;
942
- const st = $('#dBody .stream'); if (st) st.innerHTML = '';
977
+ const st = $('#dBody .stream'); if (st) clearHtml(st);
943
978
  $('#askF').hidden = !!r.headless; $('#askIn').value = ''; $('#askIn').placeholder = r.key ? 'Message Claude, or type /' : 'Message this session';
944
979
  if (r.key) { S.sid = null; S.key = r.key; loadThread(r.key); } else { S.key = null; S.sid = id; loadSid(id); }
945
980
  sessionCard(r); railDraw();
@@ -952,7 +987,7 @@ async function loadSid(id) {
952
987
  if (S.sid !== id) return;
953
988
  const box = $('#dBody .stream'); if (!box) return;
954
989
  const b = $('#dBody'), atEnd = b.scrollHeight - b.scrollTop - b.clientHeight < 80;
955
- box.innerHTML = c && c.ok ? sessionHtml(c) : turnA(ptx('The conversation of this session could not be read.'));
990
+ putHtml(box, c && c.ok ? sessionHtml(c) : turnA(ptx('The conversation of this session could not be read.')));
956
991
  $('#askNote').textContent = c && c.ask ? 'Claude is waiting for your answer above.' : 'Your message goes to this session.';
957
992
  if (atEnd) b.scrollTop = b.scrollHeight;
958
993
  if (c && c.ok && c.state !== 'ended' && $('#dlg').classList.contains('on')) R.sidTimer = setTimeout(() => loadSid(id), 2000);
@@ -274,6 +274,7 @@ a.round{color:inherit;text-decoration:none}
274
274
  .turn.u{justify-items:end}
275
275
  .ub{background:var(--solid);color:var(--on-solid);padding:11px 16px;border-radius:18px 18px 8px 18px;font-size:var(--fs-3);line-height:1.45;max-width:86%}
276
276
  .acard{margin-left:40px;background:var(--well);border-radius:var(--r-in);padding:20px 22px;display:grid;gap:14px;animation:rise .6s var(--ease) both}
277
+ .still .turn,.still .acard{animation:none} /* a redraw of a live chat keeps its turns still (premium-shell.js putHtml) */
277
278
  .acard .ct{margin:0;font:600 var(--t-micro) var(--mono);letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3)}
278
279
  .acard .kv{margin:0;grid-template-columns:110px minmax(0,1fr)!important}
279
280
  .cact{display:flex;justify-content:flex-start;padding-top:4px}
@@ -365,7 +366,7 @@ a.round{color:inherit;text-decoration:none}
365
366
  .otop .ol{display:none}
366
367
  /* 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).
367
368
  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. */
368
- .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)}
369
+ .dlg .dgrid .pane{scrollbar-color:color-mix(in oklab,var(--ink) 24%,transparent) transparent;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)}
369
370
  .dlg .dgrid .pane:has(.vtabs:not([hidden])){padding-top:0;-webkit-mask-image:none;mask-image:none}
370
371
  .otop:has(.vtabs:not([hidden])){top:0;padding-top:4px;background:var(--card-solid)}
371
372
  .obody{padding:0}
@@ -2395,6 +2396,26 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
2395
2396
  .srl-r.on .srl-h{color:inherit;opacity:.75}
2396
2397
  .srl-more{display:block;width:100%;text-align:left;min-height:32px;padding:4px 8px 4px 36px;border-radius:10px;color:var(--ink-3);font-size:var(--fs-2)}
2397
2398
  .srl-more:hover{background:var(--well);color:var(--ink)}
2399
+ /* premium-session-end: every row has an End button beside it (on hover, on focus, and always on touch screens); idle shells fold into one line */
2400
+ .srl-li{display:flex;align-items:center;gap:2px}
2401
+ .srl-li>.srl-r,.srl-li>.srl-more{flex:1;min-width:0}
2402
+ .srl-x{display:none;width:28px;height:28px;border-radius:8px;place-items:center;color:var(--ink-3);flex:none}
2403
+ .srl-x svg{width:14px;height:14px}
2404
+ .srl-x:hover,.srl-x:focus-visible{background:var(--well);color:var(--ink)}
2405
+ .srl-li:hover .srl-x,.srl-li:focus-within .srl-x{display:grid}
2406
+ @media (hover:none){.srl-x{display:grid}}
2407
+ .srl-li:has(.srl-endall){flex-wrap:wrap;row-gap:4px}
2408
+ .srl-li>.srl-more{white-space:nowrap;flex:1 0 auto}
2409
+ .srl-endall{flex:none;margin-left:36px;min-height:28px;padding:2px 10px;border-radius:999px;border:1px solid var(--hair);color:var(--ink-2);font-size:var(--fs-1);white-space:nowrap}
2410
+ .srl-endall:hover{background:var(--well);color:var(--ink)}
2411
+ .srl-cf{flex-wrap:wrap;gap:6px;padding:6px 8px;margin:2px 0;border-radius:10px;background:var(--spot);font-size:var(--fs-2)}
2412
+ .srl-cf span{flex:1 1 100%;color:var(--ink)}
2413
+ .srl-yes,.srl-no{min-height:28px;padding:2px 12px;border-radius:999px;font-size:var(--fs-2)}
2414
+ .srl-yes{background:var(--solid);color:var(--on-solid)}
2415
+ .srl-no{border:1px solid var(--hair);color:var(--ink-2)}
2416
+ .srl-min .srl-x,.srl-min .srl-endall,.srl-min .srl-cf{display:none!important}
2417
+ .dlg.srl-open .srl-x{display:grid;width:44px;height:44px}
2418
+ .dlg.srl-open .srl-endall,.dlg.srl-open .srl-yes,.dlg.srl-open .srl-no{min-height:44px;font-size:var(--fs-2)}
2398
2419
  .srl-lg{display:flex;flex-wrap:wrap;gap:4px 12px;padding:8px 8px 0;border-top:1px solid var(--hair);font-size:var(--fs-1);color:var(--ink-3)}
2399
2420
  .srl-lg span{display:inline-flex;align-items:center;gap:5px}
2400
2421
  .srl-warn{margin:4px 2px 8px;padding:8px 10px;border-radius:10px;background:var(--spot);font-size:var(--fs-2);color:var(--ink-2)}
@@ -2417,16 +2438,17 @@ button.wl-row[aria-pressed="true"] .wl-tog{background:var(--solid);color:var(--o
2417
2438
  .dlg.full.srl-on .dgrid{grid-template-columns:var(--srw,232px) minmax(360px,.75fr) minmax(0,1.25fr);gap:22px}
2418
2439
  .dlg.full.srl-on .srl{display:flex}
2419
2440
  .dlg.full.srl-on.srl-min{--srw:52px}
2420
- .dlg.full.srl-on.vw-min .dgrid{grid-template-columns:var(--srw,232px) minmax(0,1fr) 52px}
2421
- .dlg.full.vw-min:not(.srl-on) .dgrid{grid-template-columns:minmax(0,1fr) 52px}
2441
+ .dlg.full.srl-on.vw-min:not([data-mode="detail"]) .dgrid{grid-template-columns:var(--srw,232px) minmax(0,1fr) 52px}
2442
+ .dlg.full.vw-min:not(.srl-on):not([data-mode="detail"]) .dgrid{grid-template-columns:minmax(0,1fr) 52px}
2422
2443
  .dlg.full[data-mode="detail"].srl-on .dgrid{grid-template-columns:var(--srw,232px) minmax(0,1fr)}
2423
2444
  .dlg.full .vfold{display:grid}
2424
- .dlg.full.vw-min .p-out{background:transparent;overflow:hidden}
2425
- .dlg.full.vw-min .p-out>:not(.otop),.dlg.full.vw-min .otop>:not(#vFold){display:none!important}
2426
- .dlg.full.vw-min .otop{padding:0;background:transparent;justify-content:center}
2445
+ .dlg.full[data-mode="detail"] .vfold{display:none}
2446
+ .dlg.full.vw-min:not([data-mode="detail"]) .p-out{background:transparent;overflow:hidden;border-radius:0;border-left:1px solid var(--hair);padding-left:6px;cursor:pointer}
2447
+ .dlg.full.vw-min:not([data-mode="detail"]) .p-out>:not(.otop),.dlg.full.vw-min:not([data-mode="detail"]) .otop>:not(#vFold){display:none!important}
2448
+ .dlg.full.vw-min:not([data-mode="detail"]) .otop{padding:4px 0 0;background:transparent;justify-content:center}
2427
2449
  .dlg.full.srl-on #dBody .tt,.dlg.full.srl-on #dBody .ub,.dlg.full.srl-on #dBody .md,.dlg.full.srl-on #dBody .md p,.dlg.full.srl-on #dBody .md li{font-size:var(--fs-2)}
2428
2450
  .dlg.full.srl-on .stream{gap:12px}
2429
- .dlg.full.vw-min #dBody{padding-inline:max(0px,calc((100% - 880px) / 2))}
2451
+ .dlg.full.vw-min:not([data-mode="detail"]) #dBody{padding-inline:max(0px,calc((100% - 880px) / 2))}
2430
2452
  .srl-min .srl-hd b,.srl-min .srl-lg,.srl-min .srl-n,.srl-min .srl-h,.srl-min .srl-more,.srl-min .srl-warn,.srl-min .srl-gh>*{display:none!important}
2431
2453
  .srl-min .srl{padding-right:6px}
2432
2454
  .srl-min .srl-hd{justify-content:center;padding-left:0}
@@ -1,7 +1,8 @@
1
1
  /* pm/session-rail.js — the session list beside the chat (initiative premium-session-list, PRD L2). Pure: no DOM, no fetch, so Node tests it.
2
2
  *
3
- * railModel(rows, goals, { showAll }) → { groups: [{ id, title, rows, hidden }], ready, blocked, working, live, warn }
4
- * railHtml(model, { sel, shut, folded }) → the list's markup
3
+ * railModel(rows, goals, { showAll, showIdle }) → { groups: [{ id, title, rows, hidden, idle }], ready, blocked, working, live, warn, idle }
4
+ * railHtml(model, { sel, shut, showAll, showIdle, ending }) → the list's markup; every row has an End button (premium-session-end)
5
+ * endAsks(r) → whether ending this row asks first (anything but an idle session)
5
6
  * teaser(model) → { dot, text } | null the chip in a normal-size chat dialog
6
7
  * menuCount(rows) → how many live sessions need the PM (Ready or Maybe blocked): the ⋯ menu badge
7
8
  * loudestRow(model) → the row the menu's Sessions opens on
@@ -20,7 +21,10 @@ const GROUPS = [['goals', 'Goals'], ['yours', 'Yours'], ['pmos', 'Started by PMO
20
21
 
21
22
  const keyOf = (origin) => (/^chat:/.test(String(origin || '')) ? String(origin).slice(5) : null);
22
23
  const needsYou = (r) => r.state === 'needs' || r.state === 'blocked';
23
- const kindOf = (r) => (r.headless ? 'run' : /^schedule:/.test(r.origin || '') ? 'clock' : r.goal ? 'goal' : r.key ? 'chat' : r.group === 'pmos' ? 'auto' : 'step');
24
+ /** premium-session-end: an idle terminal shell with no agent in it — nothing to read and nothing to answer. Yours folds these into one line. */
25
+ export const idleShell = (r) => r.agent === 'shell' && r.state === 'quiet' && !r.goal && !r.headless;
26
+ export const endAsks = (r) => !(r && r.state === 'quiet');
27
+ const kindOf = (r) => (r.headless || r.agent === 'shell' ? 'run' : /^schedule:/.test(r.origin || '') ? 'clock' : r.goal ? 'goal' : r.key ? 'chat' : r.group === 'pmos' ? 'auto' : 'step');
24
28
 
25
29
  function rowOf(s, goals) {
26
30
  const key = keyOf(s.origin), g = key && goals ? goals[key] : null;
@@ -36,17 +40,17 @@ function rowOf(s, goals) {
36
40
  return r;
37
41
  }
38
42
 
39
- export function railModel(rows, goals = {}, { showAll = false } = {}) {
43
+ export function railModel(rows, goals = {}, { showAll = false, showIdle = false } = {}) {
40
44
  const live = (Array.isArray(rows) ? rows : []).filter((s) => s && s.id && s.shown !== 'exited').map((s) => rowOf(s, goals));
41
45
  live.sort((a, b) => (RANK[b.state] - RANK[a.state]) || (Date.parse(b.created || '') || 0) - (Date.parse(a.created || '') || 0));
42
46
  const groups = GROUPS.map(([id, title]) => {
43
47
  const all = live.filter((r) => r.group === id);
44
- const shown = id === 'pmos' && !showAll ? all.filter(needsYou) : all;
45
- return { id, title, rows: shown, all: all.length, hidden: all.length - shown.length };
48
+ const shown = id === 'pmos' && !showAll ? all.filter(needsYou) : id === 'yours' && !showIdle ? all.filter((r) => !idleShell(r)) : all;
49
+ return { id, title, rows: shown, all: all.length, hidden: id === 'pmos' ? all.length - shown.length : 0, idle: id === 'yours' ? all.filter(idleShell).length : 0 };
46
50
  }).filter((g) => g.all);
47
51
  const n = (st) => live.filter((r) => r.state === st).length;
48
52
  const working = n('working');
49
- return { groups, live: live.length, ready: n('needs'), blocked: n('blocked'), working, warn: working > MANY ? working : 0, rows: live };
53
+ return { groups, live: live.length, ready: n('needs'), blocked: n('blocked'), working, warn: working > MANY ? working : 0, rows: live, idle: live.filter(idleShell) };
50
54
  }
51
55
 
52
56
  export const menuCount = (rows) => (Array.isArray(rows) ? rows : []).filter((s) => s && (s.shown === 'needs' || s.shown === 'blocked')).length;
@@ -69,16 +73,24 @@ const ICON = {
69
73
  clock: '<circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/>', run: '<path d="M4 17l6-6-6-6"/><path d="M12 19h8"/>',
70
74
  };
71
75
  export const icon = (k) => `<svg class="i" viewBox="0 0 24 24" aria-hidden="true">${ICON[k] || ICON.step}</svg>`;
76
+ const XI = '<svg class="i" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg>';
72
77
  const CHEV = '<svg class="i chev" viewBox="0 0 24 24" aria-hidden="true"><path d="M6 9l6 6 6-6"/></svg>';
73
78
 
74
- export function railHtml(m, { sel = null, shut = [], showAll = false } = {}) {
79
+ /* one row: the session button and, beside it, its End button. `ending` is the row whose End asked first: the row becomes the question. */
80
+ function rowHtml(r, sel, ending) {
81
+ if (ending === r.id) return `<li class="srl-li srl-cf" role="group" aria-label="${esc('End ' + r.name)}"><span>End “${esc(r.name)}”? It is ${esc(WORD[r.state].toLowerCase())}.</span><button type="button" class="srl-yes" data-endyes="${esc(r.id)}">End</button><button type="button" class="srl-no" data-endno="1">Keep</button></li>`;
82
+ return `<li class="srl-li"><button type="button" class="srl-r${r.id === sel ? ' on' : ''}${r.state === 'needs' ? ' rd' : ''}" data-sid="${esc(r.id)}" aria-current="${r.id === sel}" aria-label="${esc(r.name + ', ' + r.hint)}" title="${esc(r.name + ' · ' + r.hint)}"><i class="sdot2 ${DOT[r.state]}" aria-hidden="true"></i><span class="srl-ic">${icon(r.kind)}</span><span class="srl-n">${esc(r.name)}</span><span class="srl-h">${esc(r.hint)}</span></button><button type="button" class="srl-x" data-end="${esc(r.id)}" aria-label="${esc('End ' + r.name)}" title="End this session">${XI}</button></li>`;
83
+ }
84
+
85
+ export function railHtml(m, { sel = null, shut = [], showAll = false, showIdle = false, ending = null } = {}) {
75
86
  if (!m || !m.live) return '<p class="srl-none">No sessions are running. Write in a chat to start one.</p>';
76
87
  let h = m.warn ? `<p class="srl-warn" role="status"><b>${m.warn} 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>` : '';
77
88
  for (const g of m.groups) {
78
89
  const open = !shut.includes(g.id);
79
90
  h += `<section class="srl-g"><button type="button" class="srl-gh" data-sg="${g.id}" aria-expanded="${open}">${CHEV}<span>${esc(g.title)}</span><em>${g.all}</em></button>`;
80
91
  if (!open) { h += '</section>'; continue; }
81
- h += '<ul>' + g.rows.map((r) => `<li><button type="button" class="srl-r${r.id === sel ? ' on' : ''}${r.state === 'needs' ? ' rd' : ''}" data-sid="${esc(r.id)}" aria-current="${r.id === sel}" aria-label="${esc(r.name + ', ' + r.hint)}" title="${esc(r.name + ' · ' + r.hint)}"><i class="sdot2 ${DOT[r.state]}" aria-hidden="true"></i><span class="srl-ic">${icon(r.kind)}</span><span class="srl-n">${esc(r.name)}</span><span class="srl-h">${esc(r.hint)}</span></button></li>`).join('');
92
+ h += '<ul>' + g.rows.map((r) => rowHtml(r, sel, ending)).join('');
93
+ if (g.id === 'yours' && g.idle) h += `<li class="srl-li"><button type="button" class="srl-more" data-sidle="1">${showIdle ? 'Hide the idle shells' : g.idle + ' more idle · Show'}</button><button type="button" class="srl-endall" data-endidle="1">End all idle</button></li>`;
82
94
  if (g.id === 'pmos' && (g.hidden || showAll)) h += `<li><button type="button" class="srl-more" data-smore="1">${showAll ? 'Hide the ones that need nothing' : g.hidden + ' more working on their own · Show'}</button></li>`;
83
95
  h += '</ul></section>';
84
96
  }
@@ -236,6 +236,7 @@ const LEGACY_STATE = path.join(__dirname, 'state');
236
236
  // must name its own state directory, and finds out by being told rather than by contaminating the
237
237
  // PM's registry and discovering it a day later.
238
238
  const REQUIRED_AS_LIBRARY = require.main !== module;
239
+ const { firstShell } = require('./lib/first-shell.js'); // premium-session-end: the startup shell, asked after the restore
239
240
  if (REQUIRED_AS_LIBRARY && !stateRoot.overrideDir(process.env)) {
240
241
  throw new Error(
241
242
  'server.js was required as a library with no PMOS_STATE_DIR set. Requiring it runs its module ' +
@@ -2985,9 +2986,11 @@ function restorePersisted(opts = {}) {
2985
2986
  const n = Number(String(meta.id).split('-')[1]); if (Number.isFinite(n) && n >= seq) seq = n + 1;
2986
2987
  } catch {}
2987
2988
  };
2989
+ const done = () => { if (typeof opts.onDone === 'function') { try { opts.onDone(); } catch {} } };
2988
2990
  if (!opts.progressive) {
2989
2991
  for (const f of files) restoreOne(f);
2990
2992
  adoptOrphanTmuxSessions();
2993
+ done();
2991
2994
  return;
2992
2995
  }
2993
2996
  // The running server restores in short slices AFTER it is listening, so the page is reachable at once and the sessions
@@ -2998,6 +3001,7 @@ function restorePersisted(opts = {}) {
2998
3001
  while (queue.length && Date.now() - t0 < 15) restoreOne(queue.shift());
2999
3002
  if (queue.length) { setImmediate(slice); return; }
3000
3003
  try { adoptOrphanTmuxSessions(); } catch {}
3004
+ done();
3001
3005
  try { pushSessions(); } catch {}
3002
3006
  };
3003
3007
  setImmediate(slice);
@@ -9936,14 +9940,13 @@ wss.on('connection', (ws) => {
9936
9940
  loadWorkspaces();
9937
9941
  if (HOME_ENABLED) registerWorkspace(SELF_ROOT); // the home workspace is hosted (PMOS-self, or the repo the launcher named)
9938
9942
  writeTmuxConf(); // must exist before restore may reattach or spawn creates
9939
- restorePersisted({ progressive: !REQUIRED_AS_LIBRARY });
9940
-
9941
9943
  // A first shell so the workspace is never empty on first run (honest real PTY). Only when there
9942
9944
  // is a repo to open it IN: an installed copy with no home and no registered repo yet must wait
9943
9945
  // for the launcher to POST a workspace rather than spawn a shell in the package directory.
9944
- if ((HOME_ENABLED || workspaces.size) && [...sessions.values()].filter((s) => s.pty).length === 0) {
9945
- spawnSession({ name: 'shell', agent: 'shell' });
9946
- }
9946
+ // premium-session-end: asked only once the restore has FINISHED. The running server restores in slices after it listens, so
9947
+ // checking right after the call saw no live pane on every launch and spawned one more `shell`, which tmux then kept: one idle
9948
+ // shell per restart, piling up in the session list.
9949
+ restorePersisted({ progressive: !REQUIRED_AS_LIBRARY, onDone: () => firstShell(sessions.values(), { canHost: HOME_ENABLED || workspaces.size > 0, spawn: () => spawnSession({ name: 'shell', agent: 'shell' }) }) });
9947
9950
 
9948
9951
  if (require.main === module) {
9949
9952
  // pm-os-absorb Run 2 (R25, X11): one nonce per launch, held in memory only. Never in process.env (so no PTY inherits
@@ -0,0 +1,9 @@
1
+ {
2
+ "_comment": "Bug 2026-10-20 (\"When I have Viewer opened, let's say showing HTML file, the PMOS is flickering\"): a live premium chat wrote its whole conversation back every 2 s, so every turn replayed its entrance beside the viewer. It now writes only what changed and keeps the turns on screen still.",
3
+ "panels": [
4
+ "premium-viewer-flicker-test.js"
5
+ ],
6
+ "seconds": {
7
+ "premium-viewer-flicker-test.js": 20
8
+ }
9
+ }