@pi-chamber/web 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/assets/{DiagramView-DsCdfDOP.js → DiagramView-BB-aZobi.js} +1 -1
  2. package/dist/assets/{DiffView-BWo7yT-P.js → DiffView-BxW6BuOC.js} +1 -1
  3. package/dist/assets/{FileSaveConflictDialog-IFbuQCcP.js → FileSaveConflictDialog-Bzz8FNMq.js} +1 -1
  4. package/dist/assets/{FilesView-DLIQkVep.js → FilesView-DECxN8Z0.js} +1 -1
  5. package/dist/assets/{GitHubDetailScaffold-CxGg6x7R.js → GitHubDetailScaffold-CWsWycRd.js} +1 -1
  6. package/dist/assets/{GitHubLinkPicker-BmqbTUpE.js → GitHubLinkPicker-BVYdg_e8.js} +1 -1
  7. package/dist/assets/{GitHubListPrimitives-a1DxU6Zp.js → GitHubListPrimitives-Dlv3tC4d.js} +1 -1
  8. package/dist/assets/{GitView-DbqM8Qi1.js → GitView-DD33ngnM.js} +3 -3
  9. package/dist/assets/{IssuesSurface-B2EfICtZ.js → IssuesSurface-BAY_eyX5.js} +2 -2
  10. package/dist/assets/{JsonTreeView-DzVqgwz-.js → JsonTreeView-DpXbUrAl.js} +1 -1
  11. package/dist/assets/{MarkdownRendererImpl-7yTzCIEI.js → MarkdownRendererImpl-Cn63lAmn.js} +1 -1
  12. package/dist/assets/{PatchDiff-Dvfm6eOV.js → PatchDiff-BklyOEHs.js} +1 -1
  13. package/dist/assets/{PierreDiffViewer-ByYaUifK.js → PierreDiffViewer-wc6cB6qw.js} +1 -1
  14. package/dist/assets/{PullRequestsSurface-1IP_dDn8.js → PullRequestsSurface-BZvJkT1I.js} +2 -2
  15. package/dist/assets/{SessionSwitcherContent-DVxWhG4x.js → SessionSwitcherContent-CscYekC1.js} +1 -1
  16. package/dist/assets/{SessionSwitcherDropdown-DiBGmmtD.js → SessionSwitcherDropdown-DShvvGwC.js} +2 -2
  17. package/dist/assets/{SessionUnreadDot-qw67HcBO.js → SessionUnreadDot-CbqRq6h_.js} +1 -1
  18. package/dist/assets/{SettingsView-CMTIIpWD.js → SettingsView-DcF-At5E.js} +3 -3
  19. package/dist/assets/{SettingsWindow-DZUSs5Is.js → SettingsWindow-gxjULdm1.js} +1 -1
  20. package/dist/assets/{ToolOutputDialog-pgTNzNPN.js → ToolOutputDialog-DdMIfrnK.js} +1 -1
  21. package/dist/assets/{ToolPartDiffPreview-Cvnr4JkU.js → ToolPartDiffPreview-C6Sm4eVf.js} +1 -1
  22. package/dist/assets/{VirtualizedFileDiff-D8dSHI_H.js → VirtualizedFileDiff-BrbPymTL.js} +1 -1
  23. package/dist/assets/{collapsible-ZT74WYMA.js → collapsible-D6qdoq7-.js} +1 -1
  24. package/dist/assets/{computeVirtualFileMetrics-g1aOl5nF.js → computeVirtualFileMetrics-G4csGiKs.js} +1 -1
  25. package/dist/assets/{contextFileOpenGuard-IWdho_6z.js → contextFileOpenGuard-UU86YHgI.js} +1 -1
  26. package/dist/assets/{fileTreeStatus-trDHgX4B.js → fileTreeStatus-Bskhj4qT.js} +1 -1
  27. package/dist/assets/{gitStatusPredicates-CfBh9Rne.js → gitStatusPredicates-DQEO4Psc.js} +1 -1
  28. package/dist/assets/{githubLink-CuQ2WFBa.js → githubLink-ByPAyFjh.js} +1 -1
  29. package/dist/assets/{index-CK9t5Znh.js → index-ComwtfT4.js} +1 -1
  30. package/dist/assets/{index-fmzQmSSv.js → index-I2QYqABE.js} +3 -3
  31. package/dist/assets/{main-DOlk_lfi.js → main-DoiadX0a.js} +2 -2
  32. package/dist/assets/{main-UnRe9F68.js → main-DyFfbllq.js} +4 -4
  33. package/dist/assets/{markdownCore-DuZmdypZ.js → markdownCore-DczkEluO.js} +1 -1
  34. package/dist/assets/{miniChat-Dy9h0B6G.js → miniChat-Ck6MEZ9Q.js} +2 -2
  35. package/dist/assets/{mobile-CWrtn0Si.js → mobile-BucKVm1P.js} +2 -2
  36. package/dist/assets/{nativeFileSave-B4Rg6n8u.js → nativeFileSave-Cp9i5QGd.js} +1 -1
  37. package/dist/assets/{pi-session-focus-preference-q-s-Bhf0.js → pi-session-focus-preference-Dx0UXPoO.js} +1 -1
  38. package/dist/assets/{renderDiffWithHighlighter-HRnE6vfE.js → renderDiffWithHighlighter-PL82AR81.js} +1 -1
  39. package/dist/assets/{renderElectronMiniChatApp-OZ2fG5eY.js → renderElectronMiniChatApp-Cb7s7dWl.js} +2 -2
  40. package/dist/assets/{renderFileWithHighlighter-tJRUQWjE.js → renderFileWithHighlighter-CYgfbA4F.js} +1 -1
  41. package/dist/assets/{renderMobileApp-D1nkBJLP.js → renderMobileApp-Bp74b_Lo.js} +3 -3
  42. package/dist/assets/{runtimeEndpointReset-Bby2E_Je.js → runtimeEndpointReset-7nWYnKd4.js} +6 -6
  43. package/dist/assets/{runtimeSurface-X62LLBLv.js → runtimeSurface-CFwnvks_.js} +1 -1
  44. package/dist/assets/{useAppFontEffects-BFgKpDYT.js → useAppFontEffects-ZTyNwFk6.js} +85 -87
  45. package/dist/assets/{useGitHubRemoteSearch-MxC4J-VO.js → useGitHubRemoteSearch-BF3ohpsh.js} +1 -1
  46. package/dist/assets/{useSwitcherItems-D5TsQEbM.js → useSwitcherItems-BJzwyDGX.js} +1 -1
  47. package/dist/assets/{web-components-B_NMC-2c.js → web-components-CGDpzixf.js} +1 -1
  48. package/dist/index.html +3 -3
  49. package/dist/mini-chat.html +2 -2
  50. package/dist/mobile.html +2 -2
  51. package/package.json +1 -1
  52. package/server/lib/pi/session-daemon/DOCUMENTATION.md +2 -2
  53. package/server/lib/pi/session-daemon/extension-custom-host.js +37 -4
  54. package/server/lib/pi/session-daemon/extension-custom-host.test.js +231 -2
  55. package/server/lib/pi/session-daemon/session-daemon-list-live.test.js +55 -0
  56. package/server/lib/pi/session-daemon/session-daemon.js +18 -2
@@ -34,7 +34,6 @@ const MAX_INPUT_ITEMS = MAX_CUSTOM_INPUT_ITEMS;
34
34
  const MAX_INPUT_CHARS = MAX_CUSTOM_INPUT_CHARS;
35
35
  const FRAME_INTERVAL_MS = 33;
36
36
  const SIZE_SETTLE_MS = 150;
37
-
38
37
  const CUSTOM_VIEWPORT_LIMITS = Object.freeze({
39
38
  columns: [20, 200],
40
39
  screenColumns: [20, 400],
@@ -1150,14 +1149,48 @@ export const createExtensionCustomHost = ({
1150
1149
  return { accepted: true };
1151
1150
  };
1152
1151
 
1153
- /** The host Close button: resolve `undefined`, as Pi's Escape would not. */
1152
+ /**
1153
+ * The host Esc button (`extensions.custom.close`). Pi has no host Close:
1154
+ * components end on their own keys, and extensions that keep a handle to
1155
+ * their overlay (pi-btw) track it open until their Esc handler runs. So
1156
+ * the button presses Esc for the user, once per press, and does nothing a
1157
+ * typed Esc would not: it goes where a key typed at the surface would (an
1158
+ * overlay it opened and focused, such as a confirmation, else its own
1159
+ * component), even when the surface is non-capturing, unfocused, or
1160
+ * hidden, so it never reaches another surface or the session's turn. A
1161
+ * component that stays open (an Esc that only stopped a running answer,
1162
+ * or one it ignores) stays open, as in Pi. Only a target with no
1163
+ * `handleInput`, or whose Esc throws, can never take the key, so the
1164
+ * surface ends at once: `custom()` resolves `undefined`, nested overlays
1165
+ * go with it, and the dismissal is `cancelled`.
1166
+ */
1154
1167
  const close = ({ sessionId, surfaceId, clientId, viewport } = {}) => {
1155
1168
  const state = sessions.get(sessionId);
1156
1169
  const surface = findSurface(state, surfaceId);
1157
1170
  if (!surface) return { closed: false };
1158
1171
  recordClient(state, clientId, viewport, true);
1159
- if (surface.settle) surface.settle('cancelled');
1160
- else removeSurface(state, surface, 'cancelled');
1172
+ const focus = state.focus;
1173
+ const useFocus = Boolean(focus?.surface && state.surfaces.includes(focus.surface) && isWithin(state, focus.surface, surface));
1174
+ const target = useFocus ? focus.component : surface.component;
1175
+ const targetSurface = useFocus ? focus.surface : surface;
1176
+ const end = () => {
1177
+ if (!state.surfaces.includes(surface)) return;
1178
+ if (surface.settle) surface.settle('cancelled');
1179
+ else removeSurface(state, surface, 'cancelled');
1180
+ };
1181
+ if (typeof target?.handleInput !== 'function') {
1182
+ end();
1183
+ return { closed: true };
1184
+ }
1185
+ try {
1186
+ target.handleInput('\x1b');
1187
+ } catch (error) {
1188
+ onError(state.sessionId, 'input', error);
1189
+ end();
1190
+ return { closed: true };
1191
+ }
1192
+ // Pi's TUI renders after every key it hands to a component.
1193
+ if (state.surfaces.includes(targetSurface)) scheduleRender(state, targetSurface);
1161
1194
  return { closed: true };
1162
1195
  };
1163
1196
 
@@ -151,11 +151,234 @@ describe('createExtensionCustomHost', () => {
151
151
  expect(harness.host.close({ sessionId: SESSION, surfaceId })).toEqual({ closed: true });
152
152
  await expect(result).resolves.toBeUndefined();
153
153
  expect(component.dispose).toHaveBeenCalledOnce();
154
- expect(harness.events.at(-1).payload).toEqual({ surfaceId, reason: 'cancelled' });
154
+ expect(harness.events.at(-1).payload).toEqual({ surfaceId, reason: 'done' });
155
155
  expect(harness.host.close({ sessionId: SESSION, surfaceId })).toEqual({ closed: false });
156
156
  expect(harness.host.input({ sessionId: SESSION, surfaceId, items: ['x'] })).toEqual({ accepted: false });
157
157
  });
158
158
 
159
+ describe('Close (the Esc button)', () => {
160
+ const dismissals = (harness) => harness.events
161
+ .filter((entry) => entry.event === 'extension.custom.dismiss')
162
+ .map((entry) => entry.payload);
163
+
164
+ /**
165
+ * An extension like pi-btw: it keeps its own "open" flag, clears it only
166
+ * when its component's Esc handler calls done() (after an await), and
167
+ * refuses to open again while the flag is set. Its overlay is
168
+ * non-capturing and takes focus through its handle.
169
+ */
170
+ const btwExtension = (host) => {
171
+ // `streaming`: a side answer is running. Like pi-btw, the first Esc
172
+ // then only starts aborting it and says "press Esc again to dismiss".
173
+ const ext = { open: false, handle: null, result: null, streaming: false, aborting: false };
174
+ ext.run = () => {
175
+ if (ext.open) {
176
+ ext.handle?.focus();
177
+ return false;
178
+ }
179
+ ext.open = true;
180
+ ext.result = host.open(SESSION, (_tui, _theme, _kb, done) => ({
181
+ render: () => [ext.aborting ? 'Aborted. Press Esc again to dismiss.' : 'btw'],
182
+ handleInput: (data) => {
183
+ if (data !== '\x1b') return;
184
+ if (ext.streaming && !ext.aborting) {
185
+ ext.aborting = true;
186
+ return;
187
+ }
188
+ void Promise.resolve().then(() => {
189
+ ext.open = false;
190
+ done();
191
+ });
192
+ },
193
+ dispose: vi.fn(),
194
+ }), {
195
+ overlay: true,
196
+ overlayOptions: { nonCapturing: true, anchor: 'top-center', width: '78%' },
197
+ onHandle: (handle) => {
198
+ ext.handle = handle;
199
+ handle.focus();
200
+ },
201
+ });
202
+ return true;
203
+ };
204
+ return ext;
205
+ };
206
+
207
+ it('presses Esc, so an extension that tracks its overlay closes it and can open it again', async () => {
208
+ const harness = createHarness();
209
+ const btw = btwExtension(harness.host);
210
+ expect(btw.run()).toBe(true);
211
+ await flushPromises();
212
+ const [surfaceId] = harness.opened();
213
+
214
+ expect(harness.host.close({ sessionId: SESSION, surfaceId, clientId: 'a' })).toEqual({ closed: true });
215
+ await flushPromises();
216
+ await expect(btw.result).resolves.toBeUndefined();
217
+ expect(btw.open).toBe(false);
218
+ // The extension closed it on its own key, as Esc in Pi's terminal would.
219
+ expect(dismissals(harness)).toEqual([{ surfaceId, reason: 'done' }]);
220
+ expect(harness.host.hasOpenSurfaces(SESSION)).toBe(false);
221
+ expect(vi.getTimerCount()).toBe(0);
222
+
223
+ expect(btw.run()).toBe(true);
224
+ await flushPromises();
225
+ expect(new Set(harness.opened().filter((id) => id !== surfaceId)).size).toBe(1);
226
+ expect(harness.host.hasOpenSurfaces(SESSION)).toBe(true);
227
+ });
228
+
229
+ it('presses Esc once per click: an Esc that only stopped work leaves the overlay to the next click', async () => {
230
+ const harness = createHarness();
231
+ const btw = btwExtension(harness.host);
232
+ btw.run();
233
+ await flushPromises();
234
+ const [surfaceId] = harness.opened();
235
+ btw.streaming = true;
236
+
237
+ harness.host.close({ sessionId: SESSION, surfaceId });
238
+ await flushPromises();
239
+ expect(btw.aborting).toBe(true);
240
+ // The extension's own "press Esc again" stays on screen; nothing else
241
+ // happens until the user presses again.
242
+ vi.advanceTimersByTime(5000);
243
+ await flushPromises();
244
+ expect(btw.open).toBe(true);
245
+ expect(harness.host.hasOpenSurfaces(SESSION)).toBe(true);
246
+ expect(harness.frames(surfaceId).at(-1).payload.lines[0]).toContain('Press Esc again');
247
+ expect(vi.getTimerCount()).toBe(0);
248
+
249
+ harness.host.close({ sessionId: SESSION, surfaceId });
250
+ await expect(btw.result).resolves.toBeUndefined();
251
+ expect(btw.open).toBe(false);
252
+ expect(dismissals(harness)).toEqual([{ surfaceId, reason: 'done' }]);
253
+ });
254
+
255
+ it('presses Esc on an overlay that does not hold focus', async () => {
256
+ const harness = createHarness();
257
+ const btw = btwExtension(harness.host);
258
+ btw.run();
259
+ await flushPromises();
260
+ const [surfaceId] = harness.opened();
261
+ btw.handle.unfocus();
262
+ expect(btw.handle.isFocused()).toBe(false);
263
+
264
+ harness.host.close({ sessionId: SESSION, surfaceId });
265
+ await flushPromises();
266
+ expect(btw.open).toBe(false);
267
+ expect(harness.host.hasOpenSurfaces(SESSION)).toBe(false);
268
+ });
269
+
270
+ it('leaves open a component that ignores Esc, as Pi would', async () => {
271
+ const harness = createHarness();
272
+ const handleInput = vi.fn();
273
+ const dispose = vi.fn();
274
+ void harness.host.open(SESSION, () => ({ render: () => ['stubborn'], handleInput, dispose }));
275
+ await flushPromises();
276
+ const [surfaceId] = harness.opened();
277
+
278
+ expect(harness.host.close({ sessionId: SESSION, surfaceId })).toEqual({ closed: true });
279
+ expect(handleInput).toHaveBeenCalledExactlyOnceWith('\x1b');
280
+ vi.advanceTimersByTime(5000);
281
+ expect(handleInput).toHaveBeenCalledOnce();
282
+ expect(harness.host.hasOpenSurfaces(SESSION)).toBe(true);
283
+ expect(dispose).not.toHaveBeenCalled();
284
+ expect(dismissals(harness)).toEqual([]);
285
+ expect(vi.getTimerCount()).toBe(0);
286
+
287
+ // Each press is one more Esc.
288
+ harness.host.close({ sessionId: SESSION, surfaceId });
289
+ expect(handleInput).toHaveBeenCalledTimes(2);
290
+ });
291
+
292
+ it('closes a component without handleInput, or whose Esc throws, at once', async () => {
293
+ const harness = createHarness();
294
+ const plain = harness.host.open(SESSION, () => ({ render: () => ['plain'] }));
295
+ await flushPromises();
296
+ harness.host.close({ sessionId: SESSION, surfaceId: harness.opened()[0] });
297
+ await expect(plain).resolves.toBeUndefined();
298
+
299
+ const throwing = harness.host.open(SESSION, () => ({
300
+ render: () => ['throws'],
301
+ handleInput: () => {
302
+ throw new Error('esc boom');
303
+ },
304
+ }));
305
+ await flushPromises();
306
+ harness.host.close({ sessionId: SESSION, surfaceId: harness.opened().at(-1) });
307
+ await expect(throwing).resolves.toBeUndefined();
308
+ expect(harness.errors).toEqual([{ sessionId: SESSION, stage: 'input', message: 'esc boom' }]);
309
+ expect(dismissals(harness).map((entry) => entry.reason)).toEqual(['cancelled', 'cancelled']);
310
+ expect(vi.getTimerCount()).toBe(0);
311
+ });
312
+
313
+ it('sends the next press to a confirmation the first one opened', async () => {
314
+ const harness = createHarness();
315
+ const editorKeys = [];
316
+ const confirmKeys = [];
317
+ void harness.host.open(SESSION, (tui) => ({
318
+ render: () => ['editor'],
319
+ handleInput: (data) => {
320
+ editorKeys.push(data);
321
+ // Esc asks before discarding; the confirmation hides on Esc.
322
+ if (data === '\x1b') {
323
+ const confirm = tui.showOverlay({
324
+ render: () => ['Discard?'],
325
+ handleInput: (key) => {
326
+ confirmKeys.push(key);
327
+ if (key === '\x1b') confirm.hide();
328
+ },
329
+ }, { anchor: 'center', width: 20 });
330
+ }
331
+ },
332
+ }), { overlay: true });
333
+ await flushPromises();
334
+ const [surfaceId] = harness.opened();
335
+
336
+ harness.host.close({ sessionId: SESSION, surfaceId });
337
+ const confirmId = harness.opened().at(-1);
338
+ expect(confirmId).not.toBe(surfaceId);
339
+ expect(harness.lastMeta(confirmId)).toMatchObject({ parentId: surfaceId, focused: true });
340
+ vi.advanceTimersByTime(5000);
341
+ expect(harness.host.hasOpenSurfaces(SESSION)).toBe(true);
342
+ expect(confirmKeys).toEqual([]);
343
+
344
+ // The next press goes where a key typed now would: the confirmation.
345
+ harness.host.close({ sessionId: SESSION, surfaceId });
346
+ expect(confirmKeys).toEqual(['\x1b']);
347
+ expect(editorKeys).toEqual(['\x1b']);
348
+ expect(dismissals(harness)).toEqual([{ surfaceId: confirmId, reason: 'done' }]);
349
+ // Only the redraw after the key; Close itself leaves no timer.
350
+ vi.advanceTimersByTime(100);
351
+ expect(vi.getTimerCount()).toBe(0);
352
+ });
353
+
354
+ it('presses Esc on a nested panel without touching its parent', async () => {
355
+ const harness = createHarness();
356
+ let tuiRef;
357
+ const result = harness.host.open(SESSION, (tui, _theme, _kb, done) => {
358
+ tuiRef = tui;
359
+ return listComponent(['parent'], done);
360
+ }, { overlay: true });
361
+ await flushPromises();
362
+ const [parentId] = harness.opened();
363
+
364
+ // A panel that closes itself on Esc, as Pi panels do.
365
+ const panelHandle = tuiRef.showOverlay({
366
+ render: () => ['panel'],
367
+ handleInput: (data) => {
368
+ if (data === '\x1b') panelHandle.hide();
369
+ },
370
+ }, { anchor: 'top-left', width: 10 });
371
+ const panelId = harness.opened().at(-1);
372
+ expect(harness.host.close({ sessionId: SESSION, surfaceId: panelId })).toEqual({ closed: true });
373
+ expect(dismissals(harness)).toEqual([{ surfaceId: panelId, reason: 'done' }]);
374
+
375
+ // The parent never saw the Esc and is still open.
376
+ expect(harness.host.hasOpenSurfaces(SESSION)).toBe(true);
377
+ harness.host.input({ sessionId: SESSION, surfaceId: parentId, items: ['\r'] });
378
+ await expect(result).resolves.toBe('parent');
379
+ });
380
+ });
381
+
159
382
  it('rejects when the factory throws and shows nothing', async () => {
160
383
  const harness = createHarness();
161
384
  await expect(harness.host.open(SESSION, () => {
@@ -307,11 +530,13 @@ describe('createExtensionCustomHost', () => {
307
530
  const harness = createHarness();
308
531
  const panelKeys = vi.fn();
309
532
  const panelHandles = [];
533
+ let finishController;
310
534
  const result = harness.host.open(SESSION, (tui, _theme, _kb, done) => {
311
535
  for (const label of ['alpha', 'beta']) {
312
536
  const panel = { render: () => [label], handleInput: panelKeys, invalidate: vi.fn(), dispose: vi.fn() };
313
537
  panelHandles.push(tui.showOverlay(panel, { nonCapturing: true, anchor: 'top-left', width: 12 }));
314
538
  }
539
+ finishController = done;
315
540
  return listComponent(['controller'], done);
316
541
  }, { overlay: true });
317
542
  await flushPromises();
@@ -324,8 +549,12 @@ describe('createExtensionCustomHost', () => {
324
549
  expect(harness.host.input({ sessionId: SESSION, surfaceId: controllerId, items: ['x'] })).toEqual({ accepted: true });
325
550
  expect(panelKeys).toHaveBeenCalledWith('x');
326
551
 
327
- // Ending the controller takes its panels along.
552
+ // Esc from Close goes there too, as a typed Esc would.
328
553
  harness.host.close({ sessionId: SESSION, surfaceId: controllerId });
554
+ expect(panelKeys).toHaveBeenLastCalledWith('\x1b');
555
+
556
+ // Ending the controller takes its panels along.
557
+ finishController(undefined);
329
558
  await expect(result).resolves.toBeUndefined();
330
559
  const dismissed = harness.events.filter((entry) => entry.event === 'extension.custom.dismiss').map((entry) => entry.payload.surfaceId);
331
560
  expect(dismissed).toEqual(expect.arrayContaining([alphaId, betaId, controllerId]));
@@ -301,6 +301,61 @@ describe('session daemon list live status', () => {
301
301
  expect(response.result.sessions[0].live).toMatchObject({ lifecycle: 'idle' });
302
302
  });
303
303
 
304
+ it("a folder's catalog read lists no session, while a created empty session is still listed", async () => {
305
+ // Switching folders reads that folder's catalogs, which starts a runtime
306
+ // with a fresh, empty Pi session. Nobody asked for that session, so it
307
+ // must not appear as an "Awaiting first prompt" row.
308
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-list-live-'));
309
+ await mkdir(join(root, 'agent'), { recursive: true });
310
+ const sessions = [];
311
+ let created = 0;
312
+ const endpoint = testDaemonEndpoint(root);
313
+ const daemon = createSessionDaemon({
314
+ endpoint,
315
+ credential,
316
+ cwd: root,
317
+ agentDir: join(root, 'agent'),
318
+ createRuntime: async () => {
319
+ const session = new FakeSession(`session-${(created += 1)}`);
320
+ sessions.push(session);
321
+ return { session, async dispose() {} };
322
+ },
323
+ listSessions: async () => [],
324
+ });
325
+ await daemon.start();
326
+ daemons.push(daemon);
327
+ const client = connectClient(endpoint);
328
+ sockets.push(client);
329
+ await client.authenticate();
330
+ const ids = async () => {
331
+ const response = await client.request('sessions.list', { directory: root });
332
+ expect(response.error).toBeUndefined();
333
+ return response.result.sessions.map((row) => row.session.id);
334
+ };
335
+
336
+ const catalog = await client.request('extensions.list', { directory: root });
337
+ expect(catalog.error).toBeUndefined();
338
+ expect(sessions).toHaveLength(1);
339
+ expect(await ids()).toEqual([]);
340
+
341
+ // An explicitly created session is listed before its first prompt.
342
+ const createdSession = await client.request('sessions.create', { cwd: root });
343
+ expect(createdSession.error).toBeUndefined();
344
+ expect(await ids()).toEqual([createdSession.result.session.id]);
345
+
346
+ // An extension's session_start message, shown or hidden, lands in every
347
+ // such session and does not make it a conversation.
348
+ sessions[0].messages = [
349
+ { role: 'custom', customType: 'greeting', content: 'hi', display: true, timestamp: 1 },
350
+ { role: 'custom', customType: 'state', content: '', display: false, timestamp: 1 },
351
+ ];
352
+ expect(await ids()).toEqual([createdSession.result.session.id]);
353
+
354
+ // The catalog session is listed once it holds a conversation.
355
+ sessions[0].messages.push({ role: 'user', content: 'hello', timestamp: 2 });
356
+ expect(new Set(await ids())).toEqual(new Set([sessions[0].sessionId, createdSession.result.session.id]));
357
+ });
358
+
304
359
  it('prefers the resident runtime name over the disk name, including clears', async () => {
305
360
  const { session, list } = await setup();
306
361
  let liveName = 'Not yet flushed';
@@ -300,6 +300,8 @@ export function createSessionDaemon({
300
300
  // zero-engine path runs exactly the Pi-only code.
301
301
  let engineRegistry;
302
302
  const runtimeStartPromises = new Map();
303
+ // Fresh Pi sessions started implicitly by `startRuntime` (see there).
304
+ const implicitSessions = new WeakSet();
303
305
  let idleDisposeTimer;
304
306
  let dormantSession;
305
307
  let sequence = 0;
@@ -1023,6 +1025,11 @@ export function createSessionDaemon({
1023
1025
  });
1024
1026
  }
1025
1027
  runtimeRegistry.register(newRuntime, { cwd: canonicalRuntimeCwd });
1028
+ // With no JSONL to reopen, Pi starts a fresh empty session that only
1029
+ // answers catalog reads (models, resources, extensions) for this folder.
1030
+ // No client asked for it, so listings skip it until it holds a
1031
+ // conversation or a name.
1032
+ if (!sessionFile && newRuntime.session) implicitSessions.add(newRuntime.session);
1026
1033
  rebuildSessionExtensionState(newRuntime);
1027
1034
  if (activate) {
1028
1035
  runtime = newRuntime;
@@ -1473,11 +1480,20 @@ export function createSessionDaemon({
1473
1480
  const extra = [];
1474
1481
  for (const entry of activeEntries) {
1475
1482
  if (entry?.session?.sessionId && !knownIds.has(entry.session.sessionId)) {
1483
+ const name = entry.session.sessionManager?.getSessionName?.() || entry.session.title || undefined;
1484
+ const messageCount = entry.session.messages?.length || 0;
1485
+ // A session started only to answer this folder's catalogs is not a
1486
+ // conversation; listing it shows an "Awaiting first prompt" row on
1487
+ // every folder switch. What an extension adds at session_start
1488
+ // (custom messages, shown or hidden, and appended entries) lands in
1489
+ // every such session, so only a non-custom message or a name lists it.
1490
+ if (implicitSessions.has(entry.session) && !name
1491
+ && !(entry.session.messages ?? []).some((message) => message?.role !== 'custom')) continue;
1476
1492
  extra.push({
1477
1493
  id: entry.session.sessionId,
1478
1494
  cwd: targetDir,
1479
- name: entry.session.sessionManager?.getSessionName?.() || entry.session.title || undefined,
1480
- messageCount: entry.session.messages?.length || 0,
1495
+ name,
1496
+ messageCount,
1481
1497
  created: new Date(),
1482
1498
  modified: new Date(),
1483
1499
  });