@pi-chamber/web 1.0.6-rc.6 → 1.0.7-rc.1
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/dist/assets/{DiagramView-BxBfOrN5.js → DiagramView-DyF8zzYx.js} +1 -1
- package/dist/assets/{DiffView-CSC9GMrb.js → DiffView-C3rA5DfE.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-C_MNWp6w.js → FileSaveConflictDialog-CC4F--8H.js} +1 -1
- package/dist/assets/{FilesView-DeN6KmNt.js → FilesView-Dsg-QTJu.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-CrtJwlqV.js → GitHubDetailScaffold-C9WuBMGr.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-g6w8K95J.js → GitHubLinkPicker-BkVdYxZT.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-lAi2ywE3.js → GitHubListPrimitives-CcVlv_rJ.js} +1 -1
- package/dist/assets/{GitView-D9_em8Vx.js → GitView-OpFCss_4.js} +3 -3
- package/dist/assets/{IssuesSurface-DCiHe6TE.js → IssuesSurface-DD6Gz5Ox.js} +2 -2
- package/dist/assets/{JsonTreeView-D64mTfTx.js → JsonTreeView-Dj75jgH6.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DwE90rTA.js → MarkdownRendererImpl-CnIzmT1p.js} +1 -1
- package/dist/assets/{PatchDiff-CcIwURzW.js → PatchDiff-DND5RBnF.js} +1 -1
- package/dist/assets/{PierreDiffViewer-tN7awL0-.js → PierreDiffViewer-Cq5CIrmH.js} +1 -1
- package/dist/assets/{PullRequestsSurface-iX4r3QlS.js → PullRequestsSurface-g8HAvbFg.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-DrrM0ObM.js → SessionSwitcherContent-CUz6Cc1-.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-B9_0JwY7.js → SessionSwitcherDropdown-COZ50Y5a.js} +2 -2
- package/dist/assets/{SessionUnreadDot-Bpgp2gLO.js → SessionUnreadDot-DOUcgBw6.js} +1 -1
- package/dist/assets/{SettingsView-C4hec1iy.js → SettingsView-AFymxZYC.js} +3 -3
- package/dist/assets/{SettingsWindow-Bepcpy0R.js → SettingsWindow-J6YOvGcV.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Dl9-vpvL.js → ToolOutputDialog-5Tc7HM4z.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-CLlHEPYD.js → ToolPartDiffPreview-7GiFbVl7.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-D9OpUpR3.js → VirtualizedFileDiff-Dq8pyTGy.js} +1 -1
- package/dist/assets/{collapsible-ZT74WYMA.js → collapsible-D6qdoq7-.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-CDv_UBXL.js → computeVirtualFileMetrics-uXZ9uhI_.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-BJ2sAhZG.js → contextFileOpenGuard-CckKFYjI.js} +1 -1
- package/dist/assets/{fileTreeStatus-B2PDFobt.js → fileTreeStatus-C_7jbeGv.js} +1 -1
- package/dist/assets/{gitStatusPredicates-BDdOjxH_.js → gitStatusPredicates-CNLvdt2V.js} +1 -1
- package/dist/assets/{githubLink-wwC2_C_9.js → githubLink-0EoMGZKd.js} +1 -1
- package/dist/assets/{index-MXKT8Ir9.js → index-DD0xW5WE.js} +1 -1
- package/dist/assets/{index-fmzQmSSv.js → index-I2QYqABE.js} +3 -3
- package/dist/assets/{main-CnW7qm2b.js → main-BnWf2tm9.js} +2 -2
- package/dist/assets/{main-DmHVgAh0.js → main-yQe-k30g.js} +4 -4
- package/dist/assets/{markdownCore-DOFhfL5i.js → markdownCore-C-Ulh4n9.js} +1 -1
- package/dist/assets/{miniChat-D_Wl2jlx.js → miniChat-DKK1hotU.js} +2 -2
- package/dist/assets/{mobile-Cl-KcfGW.js → mobile-BuAWpKj9.js} +2 -2
- package/dist/assets/{nativeFileSave-B4Rg6n8u.js → nativeFileSave-Cp9i5QGd.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-BqEU9Iq6.js → pi-session-focus-preference-DaWQ2rEE.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-U7WjeGm9.js → renderDiffWithHighlighter-DD-iWWus.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-BJxNc9OP.js → renderElectronMiniChatApp-CKuFQBRo.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-DiwpFgMp.js → renderFileWithHighlighter-B0pofdV1.js} +1 -1
- package/dist/assets/{renderMobileApp-d5KpyvBc.js → renderMobileApp-B3P_bita.js} +3 -3
- package/dist/assets/runtimeEndpointReset-DutinXZK.js +62 -0
- package/dist/assets/{runtimeSurface-X62LLBLv.js → runtimeSurface-CFwnvks_.js} +1 -1
- package/dist/assets/{useAppFontEffects-FKnY7Fe2.js → useAppFontEffects-DQlUEhzN.js} +85 -87
- package/dist/assets/{useGitHubRemoteSearch-4QMXIODG.js → useGitHubRemoteSearch-BoZvJAk3.js} +1 -1
- package/dist/assets/{useSwitcherItems-DtCNsq8u.js → useSwitcherItems-Dy2yumiU.js} +1 -1
- package/dist/assets/{web-components-D5QImbWv.js → web-components-DB-GDG7P.js} +1 -1
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +2 -2
- package/dist/mobile.html +2 -2
- package/package.json +1 -1
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +3 -3
- package/server/lib/pi/session-daemon/extension-custom-host.js +37 -4
- package/server/lib/pi/session-daemon/extension-custom-host.test.js +231 -2
- package/server/lib/pi/session-daemon/session-daemon-list-live.test.js +115 -1
- package/server/lib/pi/session-daemon/session-daemon.js +52 -12
- package/server/lib/pi/session-daemon/session-engine-router.js +5 -1
- package/server/lib/pi/session-daemon/session-engine-router.test.js +21 -0
- package/dist/assets/runtimeEndpointReset-Cd4yJDsk.js +0 -62
|
@@ -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
|
-
/**
|
|
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
|
-
|
|
1160
|
-
|
|
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: '
|
|
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
|
-
//
|
|
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]));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
-
import { mkdir, mkdtemp } from 'node:fs/promises';
|
|
2
|
+
import { mkdir, mkdtemp, stat, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { createConnection } from 'node:net';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
@@ -227,6 +227,65 @@ describe('session daemon list live status', () => {
|
|
|
227
227
|
expect(Object.keys(live).sort()).toEqual(['lifecycle', 'retry', 'runStartedAt', 'sequence', 'serverNow']);
|
|
228
228
|
});
|
|
229
229
|
|
|
230
|
+
it("lists a removed folder's sessions from the session store, and rejects a path that is not a folder", async () => {
|
|
231
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-list-live-'));
|
|
232
|
+
await mkdir(join(root, 'agent'), { recursive: true });
|
|
233
|
+
const removed = join(root, 'removed-worktree');
|
|
234
|
+
const listedDirectories = [];
|
|
235
|
+
const { daemon, endpoint } = await startDaemon(root, new FakeSession('unused'), async ({ cwd }) => {
|
|
236
|
+
listedDirectories.push(cwd);
|
|
237
|
+
return cwd === removed ? [{ ...diskRow(removed, 'orphan'), cwd: removed }] : [];
|
|
238
|
+
});
|
|
239
|
+
daemons.push(daemon);
|
|
240
|
+
const client = connectClient(endpoint);
|
|
241
|
+
sockets.push(client);
|
|
242
|
+
await client.authenticate();
|
|
243
|
+
|
|
244
|
+
const listed = await client.request('sessions.list', { directory: removed });
|
|
245
|
+
expect(listed.error).toBeUndefined();
|
|
246
|
+
expect(listed.result.sessions.map((item) => item.session.id)).toEqual(['orphan']);
|
|
247
|
+
expect(listedDirectories).toContain(removed);
|
|
248
|
+
|
|
249
|
+
// A failed request closes the connection with an error frame, so each case gets its own client.
|
|
250
|
+
const rejects = async (directory) => {
|
|
251
|
+
const other = connectClient(endpoint);
|
|
252
|
+
sockets.push(other);
|
|
253
|
+
await other.authenticate();
|
|
254
|
+
other.socket.write(`${JSON.stringify({ protocolVersion: 1, kind: 'request', requestId: 'bad', command: 'sessions.list', payload: { directory } })}\n`);
|
|
255
|
+
return (await other.next((message) => message.kind === 'error')).error.code;
|
|
256
|
+
};
|
|
257
|
+
const file = join(root, 'not-a-folder.txt');
|
|
258
|
+
await writeFile(file, 'x');
|
|
259
|
+
expect(await rejects(file)).toBe('INVALID_ARGUMENT');
|
|
260
|
+
expect(await rejects('relative/folder')).toBe('INVALID_ARGUMENT');
|
|
261
|
+
// A Windows client's home is not an absolute path on a POSIX server.
|
|
262
|
+
if (process.platform !== 'win32') expect(await rejects('C:/Users/Someone')).toBe('INVALID_ARGUMENT');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("deletes a removed folder's session from a freshly started daemon", async () => {
|
|
266
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-list-live-'));
|
|
267
|
+
await mkdir(join(root, 'agent'), { recursive: true });
|
|
268
|
+
const removed = join(root, 'removed-worktree');
|
|
269
|
+
// The transcript lives in the session store; its folder is gone.
|
|
270
|
+
const sessionFile = join(root, 'orphan.jsonl');
|
|
271
|
+
await writeFile(sessionFile, `${JSON.stringify({ type: 'session', id: 'orphan', cwd: removed })}\n`);
|
|
272
|
+
// A new daemon has never seen the folder, as after a restart.
|
|
273
|
+
const { daemon, endpoint } = await startDaemon(root, new FakeSession('unused'), async ({ cwd }) => (
|
|
274
|
+
cwd === removed ? [{ ...diskRow(root, 'orphan'), cwd: removed }] : []
|
|
275
|
+
));
|
|
276
|
+
daemons.push(daemon);
|
|
277
|
+
const client = connectClient(endpoint);
|
|
278
|
+
sockets.push(client);
|
|
279
|
+
await client.authenticate();
|
|
280
|
+
|
|
281
|
+
const deleted = await client.request('sessions.delete', { sessionId: 'orphan', directory: removed });
|
|
282
|
+
expect(deleted.error).toBeUndefined();
|
|
283
|
+
await expect(stat(sessionFile)).rejects.toMatchObject({ code: 'ENOENT' });
|
|
284
|
+
// The removed folder does not become a known project.
|
|
285
|
+
const projects = await client.request('projects.list', {});
|
|
286
|
+
expect(JSON.stringify(projects.result)).not.toContain('removed-worktree');
|
|
287
|
+
});
|
|
288
|
+
|
|
230
289
|
it('an unpersisted resident session is listed with its live status too', async () => {
|
|
231
290
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-list-live-'));
|
|
232
291
|
await mkdir(join(root, 'agent'), { recursive: true });
|
|
@@ -242,6 +301,61 @@ describe('session daemon list live status', () => {
|
|
|
242
301
|
expect(response.result.sessions[0].live).toMatchObject({ lifecycle: 'idle' });
|
|
243
302
|
});
|
|
244
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
|
+
|
|
245
359
|
it('prefers the resident runtime name over the disk name, including clears', async () => {
|
|
246
360
|
const { session, list } = await setup();
|
|
247
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;
|
|
@@ -544,6 +546,26 @@ export function createSessionDaemon({
|
|
|
544
546
|
return activeDirectory || cwd;
|
|
545
547
|
};
|
|
546
548
|
|
|
549
|
+
// Listing or deleting a folder's sessions reads Pi's session store, not the
|
|
550
|
+
// folder, so a folder that has since been removed still resolves: its
|
|
551
|
+
// sessions stay listable, archivable, and deletable. A path that exists must
|
|
552
|
+
// still be a directory, and opening or creating a session keeps the strict
|
|
553
|
+
// check in `resolveDirectory`.
|
|
554
|
+
const resolveSessionStoreDirectory = async (requested) => {
|
|
555
|
+
if (typeof requested !== 'string' || requested.trim().length === 0) return activeDirectory || cwd;
|
|
556
|
+
const trimmed = requested.trim();
|
|
557
|
+
const normalized = trimmed === '~' ? homedir() : trimmed;
|
|
558
|
+
if (!isAbsolute(normalized)) {
|
|
559
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The directory path must be absolute.');
|
|
560
|
+
}
|
|
561
|
+
try {
|
|
562
|
+
await stat(normalized);
|
|
563
|
+
} catch (error) {
|
|
564
|
+
if (error?.code === 'ENOENT') return normalized;
|
|
565
|
+
}
|
|
566
|
+
return resolveDirectory(normalized);
|
|
567
|
+
};
|
|
568
|
+
|
|
547
569
|
const deriveSessionTitle = (text, maxLength = 50) => {
|
|
548
570
|
if (!text || typeof text !== 'string') return '';
|
|
549
571
|
const cleaned = text
|
|
@@ -1003,6 +1025,11 @@ export function createSessionDaemon({
|
|
|
1003
1025
|
});
|
|
1004
1026
|
}
|
|
1005
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);
|
|
1006
1033
|
rebuildSessionExtensionState(newRuntime);
|
|
1007
1034
|
if (activate) {
|
|
1008
1035
|
runtime = newRuntime;
|
|
@@ -1453,11 +1480,20 @@ export function createSessionDaemon({
|
|
|
1453
1480
|
const extra = [];
|
|
1454
1481
|
for (const entry of activeEntries) {
|
|
1455
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;
|
|
1456
1492
|
extra.push({
|
|
1457
1493
|
id: entry.session.sessionId,
|
|
1458
1494
|
cwd: targetDir,
|
|
1459
|
-
name
|
|
1460
|
-
messageCount
|
|
1495
|
+
name,
|
|
1496
|
+
messageCount,
|
|
1461
1497
|
created: new Date(),
|
|
1462
1498
|
modified: new Date(),
|
|
1463
1499
|
});
|
|
@@ -1499,7 +1535,7 @@ export function createSessionDaemon({
|
|
|
1499
1535
|
};
|
|
1500
1536
|
|
|
1501
1537
|
const listSessionItems = async (requestedDirectory) => {
|
|
1502
|
-
const targetDir =
|
|
1538
|
+
const targetDir = await resolveSessionStoreDirectory(requestedDirectory);
|
|
1503
1539
|
const inflight = listInflightByDirectory.get(targetDir);
|
|
1504
1540
|
if (inflight) return inflight;
|
|
1505
1541
|
const pending = listSessionItemsUnshared(targetDir).finally(() => {
|
|
@@ -1541,15 +1577,18 @@ export function createSessionDaemon({
|
|
|
1541
1577
|
publish('session.updated', { title: redactAttachmentPaths(title) }, sessionId, targetDir);
|
|
1542
1578
|
};
|
|
1543
1579
|
|
|
1544
|
-
|
|
1580
|
+
// Deletion passes `allowRemovedDirectory`: a session whose folder has since
|
|
1581
|
+
// been removed is still found in the store. Opening keeps the strict check.
|
|
1582
|
+
const findPersistedSession = async (sessionId, requestedDirectory, { allowRemovedDirectory = false } = {}) => {
|
|
1545
1583
|
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
1546
1584
|
throw new SessionDaemonProtocolError('INVALID_SESSION', 'The Pi session does not exist.');
|
|
1547
1585
|
}
|
|
1586
|
+
const resolve = allowRemovedDirectory ? resolveSessionStoreDirectory : resolveDirectory;
|
|
1548
1587
|
const candidateDirs = new Set();
|
|
1549
1588
|
let requestedTargetDirectory;
|
|
1550
1589
|
if (requestedDirectory) {
|
|
1551
1590
|
try {
|
|
1552
|
-
requestedTargetDirectory = await
|
|
1591
|
+
requestedTargetDirectory = await resolve(requestedDirectory);
|
|
1553
1592
|
candidateDirs.add(requestedTargetDirectory);
|
|
1554
1593
|
} catch {}
|
|
1555
1594
|
}
|
|
@@ -1587,8 +1626,9 @@ export function createSessionDaemon({
|
|
|
1587
1626
|
const named = await findPiSessionJsonlById({ sessionId, agentDir });
|
|
1588
1627
|
if (named?.path && named.cwd) {
|
|
1589
1628
|
await validatePiSessionJsonlFile(named.path);
|
|
1590
|
-
|
|
1591
|
-
|
|
1629
|
+
// `resolveDirectory` records an existing folder as known; a removed
|
|
1630
|
+
// one is never added.
|
|
1631
|
+
const directory = await resolve(named.cwd);
|
|
1592
1632
|
return { target: { id: sessionId, path: named.path }, directory };
|
|
1593
1633
|
}
|
|
1594
1634
|
} catch {
|
|
@@ -1629,8 +1669,7 @@ export function createSessionDaemon({
|
|
|
1629
1669
|
lines.close();
|
|
1630
1670
|
if (fileId === sessionId && sessionCwd) {
|
|
1631
1671
|
await validatePiSessionJsonlFile(fullPath);
|
|
1632
|
-
const validated = await
|
|
1633
|
-
knownDirectories.add(validated);
|
|
1672
|
+
const validated = await resolve(sessionCwd);
|
|
1634
1673
|
return { target: { id: sessionId, path: fullPath }, directory: validated };
|
|
1635
1674
|
}
|
|
1636
1675
|
} catch {}
|
|
@@ -3793,7 +3832,7 @@ export function createSessionDaemon({
|
|
|
3793
3832
|
throw new SessionDaemonProtocolError('RUNTIME_DISPOSAL_FAILED', 'The Pi session runtime could not be disposed.');
|
|
3794
3833
|
}
|
|
3795
3834
|
const active = runtimeRegistry?.findBySessionId(sessionId);
|
|
3796
|
-
let targetDir = requestedDirectory ? await
|
|
3835
|
+
let targetDir = requestedDirectory ? await resolveSessionStoreDirectory(requestedDirectory) : active?.cwd || activeDirectory || cwd;
|
|
3797
3836
|
const activeSessionFile = active?.session?.sessionManager?.getSessionFile?.();
|
|
3798
3837
|
if (active) {
|
|
3799
3838
|
if (active.session?.isStreaming) await active.session.abort();
|
|
@@ -3804,7 +3843,7 @@ export function createSessionDaemon({
|
|
|
3804
3843
|
if (active && typeof activeSessionFile === 'string' && activeSessionFile.length > 0) {
|
|
3805
3844
|
await rm(activeSessionFile, { force: true });
|
|
3806
3845
|
} else if (!active) {
|
|
3807
|
-
const { target, directory } = await findPersistedSession(sessionId, targetDir);
|
|
3846
|
+
const { target, directory } = await findPersistedSession(sessionId, targetDir, { allowRemovedDirectory: true });
|
|
3808
3847
|
targetDir = directory;
|
|
3809
3848
|
await acquireResidentLease({ cwd: targetDir, sessionId });
|
|
3810
3849
|
try {
|
|
@@ -4281,6 +4320,7 @@ export function createSessionDaemon({
|
|
|
4281
4320
|
const engineRouter = createSessionEngineRouter({
|
|
4282
4321
|
getRegistry: () => engineRegistry,
|
|
4283
4322
|
resolveDirectory,
|
|
4323
|
+
resolveSessionStoreDirectory,
|
|
4284
4324
|
sessionInput,
|
|
4285
4325
|
redact: (value) => redactAttachmentValues(value),
|
|
4286
4326
|
createError: (code, message) => new SessionDaemonProtocolError(code, message),
|
|
@@ -4677,7 +4717,7 @@ export function createSessionDaemon({
|
|
|
4677
4717
|
return;
|
|
4678
4718
|
}
|
|
4679
4719
|
const listDir = message.payload?.directory || message.payload?.cwd;
|
|
4680
|
-
const listTargetDir =
|
|
4720
|
+
const listTargetDir = await resolveSessionStoreDirectory(listDir);
|
|
4681
4721
|
const merged = await engineRouter.mergeSessionList(sessions, listTargetDir);
|
|
4682
4722
|
writeFrame(socket, {
|
|
4683
4723
|
protocolVersion: PROTOCOL_VERSION,
|
|
@@ -43,6 +43,7 @@ const invalidArgument = (createError, message) => {
|
|
|
43
43
|
* @param {{
|
|
44
44
|
* getRegistry: () => ({ size: number } | undefined),
|
|
45
45
|
* resolveDirectory: (requested: unknown) => Promise<string>,
|
|
46
|
+
* resolveSessionStoreDirectory?: (requested: unknown) => Promise<string>,
|
|
46
47
|
* sessionInput: (payload: object, delivery?: string, execute?: (payload: object) => Promise<object>) => Promise<object>,
|
|
47
48
|
* redact: (value: unknown) => unknown,
|
|
48
49
|
* createError: (code: string, message: string) => Error,
|
|
@@ -60,6 +61,8 @@ const invalidArgument = (createError, message) => {
|
|
|
60
61
|
export const createSessionEngineRouter = ({
|
|
61
62
|
getRegistry,
|
|
62
63
|
resolveDirectory,
|
|
64
|
+
// Deleting reads the session store, so a removed folder still resolves.
|
|
65
|
+
resolveSessionStoreDirectory = resolveDirectory,
|
|
63
66
|
sessionInput,
|
|
64
67
|
redact,
|
|
65
68
|
createError,
|
|
@@ -228,8 +231,9 @@ export const createSessionEngineRouter = ({
|
|
|
228
231
|
if (owner) {
|
|
229
232
|
const payload = message.payload ?? {};
|
|
230
233
|
const requestedDir = payload.directory || payload.cwd;
|
|
234
|
+
const resolve = message.command === 'sessions.delete' ? resolveSessionStoreDirectory : resolveDirectory;
|
|
231
235
|
const enginePayload = requestedDir !== undefined
|
|
232
|
-
? { ...payload, directory: await
|
|
236
|
+
? { ...payload, directory: await resolve(requestedDir) }
|
|
233
237
|
: payload;
|
|
234
238
|
if (PROMPT_COMMANDS.has(message.command)) {
|
|
235
239
|
const delivery = deliveryOf(message.command);
|
|
@@ -106,6 +106,27 @@ describe('session engine router', () => {
|
|
|
106
106
|
})).rejects.toMatchObject({ code: ENGINE_UNSUPPORTED_OPERATION });
|
|
107
107
|
});
|
|
108
108
|
|
|
109
|
+
it('resolves a delete through the session store and every other command strictly', async () => {
|
|
110
|
+
const seen = [];
|
|
111
|
+
const engine = makeEngine('fake', {
|
|
112
|
+
ownsSession: (id) => id === 'engine-1',
|
|
113
|
+
handlers: {
|
|
114
|
+
'sessions.delete': async (payload) => { seen.push(['delete', payload.directory]); return {}; },
|
|
115
|
+
'sessions.rename': async (payload) => { seen.push(['rename', payload.directory]); return {}; },
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
const { router } = makeRouter({
|
|
119
|
+
getRegistry: () => makeRegistry([engine]),
|
|
120
|
+
resolveDirectory: async () => { throw Object.assign(new Error('missing'), { code: 'INVALID_ARGUMENT' }); },
|
|
121
|
+
resolveSessionStoreDirectory: async (dir) => `store:${dir}`,
|
|
122
|
+
});
|
|
123
|
+
await router.dispatch({}, { command: 'sessions.delete', requestId: 'r1', payload: { sessionId: 'engine-1', directory: '/gone' } });
|
|
124
|
+
expect(seen).toEqual([['delete', 'store:/gone']]);
|
|
125
|
+
await expect(router.dispatch({}, {
|
|
126
|
+
command: 'sessions.rename', requestId: 'r2', payload: { sessionId: 'engine-1', directory: '/gone', title: 'x' },
|
|
127
|
+
})).rejects.toMatchObject({ code: 'INVALID_ARGUMENT' });
|
|
128
|
+
});
|
|
129
|
+
|
|
109
130
|
it('throws unsupported automatically when the handler is missing', async () => {
|
|
110
131
|
const engine = makeEngine('fake', {
|
|
111
132
|
ownsSession: () => true,
|