@pi-chamber/web 0.9.1 → 0.9.4
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/README.md +2 -2
- package/bin/lib/cli-paths.js +22 -6
- package/dist/assets/{DiagramEditor-DoEOH0hY.js → DiagramEditor-DuGmiPZ5.js} +1 -1
- package/dist/assets/{DiagramView-y9Ystuhv.js → DiagramView-CHy1Glsl.js} +1 -1
- package/dist/assets/{DiffView-ScM4XoqZ.js → DiffView-CBOrV4hS.js} +1 -1
- package/dist/assets/{FilesView-CjkhMFqJ.js → FilesView-CK2YVs_W.js} +1 -1
- package/dist/assets/{GitView-Bqi6H8I-.js → GitView-BEFLOv_7.js} +3 -3
- package/dist/assets/{JsonTreeView-DWhlH6NK.js → JsonTreeView-CKWGm5MS.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CEOKZ1qH.js → MarkdownRendererImpl-hE_nmSqe.js} +1 -1
- package/dist/assets/{PatchDiff-ClnfJJ2J.js → PatchDiff-BagRxMON.js} +1 -1
- package/dist/assets/{SessionSwitcherContent-e6JzUXD_.js → SessionSwitcherContent-z9VYCXrT.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-C4etG8dv.js → SessionSwitcherDropdown-icxJk_lT.js} +2 -2
- package/dist/assets/{SessionUnreadDot-BVTSwRiG.js → SessionUnreadDot-Bv-5KguB.js} +1 -1
- package/dist/assets/SettingsView-Ck0qxtKP.js +2 -0
- package/dist/assets/{SettingsWindow-Cy9tmnMg.js → SettingsWindow-GQRL2CdD.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Csrc0Uk2.js → ToolOutputDialog-CxJUXVZW.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-6oH6KD44.js → ToolPartDiffPreview-BXuLRWHT.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-DJNcTQNp.js → VirtualizedFileDiff-DfaXovGB.js} +1 -1
- package/dist/assets/{collapsible-DxgVLhi9.js → collapsible-szfZ0Syc.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-B-WoeBMW.js → computeVirtualFileMetrics-DG_E6iaN.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DQ4U9xRH.js → contextFileOpenGuard-DPBE3ELv.js} +1 -1
- package/dist/assets/{gitStatusPredicates-CIFSGjJs.js → gitStatusPredicates-OljV4Bb2.js} +1 -1
- package/dist/assets/{index-DmNPBaSo.js → index-DmexVlTQ.js} +1 -1
- package/dist/assets/{index-D2C3q2xD.js → index-KIdiBFJs.js} +1 -1
- package/dist/assets/{isDiffPlainText-CrvpUauF.js → isDiffPlainText-aikgiqLb.js} +1 -1
- package/dist/assets/{isFilePlainText-CKvhS32g.js → isFilePlainText-D-Dl6LqX.js} +1 -1
- package/dist/assets/{main-CjM7g4Gq.js → main-BXdraZTZ.js} +3 -3
- package/dist/assets/{main-BFv8slLp.js → main-DG1oZ0Wj.js} +2 -2
- package/dist/assets/{markdownCore-DKrraAqT.js → markdownCore-DUjQU2i0.js} +1 -1
- package/dist/assets/{miniChat-hQnLS5mt.js → miniChat-BEAtOkr9.js} +2 -2
- package/dist/assets/{mobile-DuXOBGs_.js → mobile-DOFBBQg2.js} +2 -2
- package/dist/assets/{renderElectronMiniChatApp-ClJBZVGy.js → renderElectronMiniChatApp-B0K72YnS.js} +2 -2
- package/dist/assets/{renderMobileApp-DofX2wjB.js → renderMobileApp-Ca_BO_s4.js} +3 -3
- package/dist/assets/{runtimeEndpointReset-BZeYg6eN.js → runtimeEndpointReset-Cx2tsgTo.js} +15 -15
- package/dist/assets/{runtimeSurface-C7CBxDbh.js → runtimeSurface-CySRuLbN.js} +1 -1
- package/dist/assets/{useAppFontEffects-Cs0f1dKn.js → useAppFontEffects-C4JL1x7k.js} +85 -85
- package/dist/assets/{useFilesViewSearch-D1hcbBEc.js → useFilesViewSearch-Du0DnmKs.js} +1 -1
- package/dist/assets/{usePushVisibilityBeacon-DqHkuVS5.js → usePushVisibilityBeacon-BnHxIv4r.js} +1 -1
- package/dist/assets/{useSwitcherItems-BEoW7LlC.js → useSwitcherItems-C91mwPJD.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B8Ac62S_.js → vendor-codemirror-language-data-C493X_9w.js} +2 -2
- package/dist/assets/{web-components-Dy-Tz_LJ.js → web-components-B2Rw__yK.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/routes.js +48 -4
- package/server/lib/pi/routes.test.js +108 -1
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +4 -5
- package/server/lib/pi/session-daemon/ipc-client.js +20 -9
- package/server/lib/pi/session-daemon/ipc-client.test.js +88 -0
- package/server/lib/pi/session-daemon/ipc-protocol.js +9 -0
- package/server/lib/pi/session-daemon/prompt-operations.test.js +51 -0
- package/server/lib/pi/session-daemon/session-daemon.js +316 -80
- package/server/lib/pi/session-daemon/session-daemon.test.js +327 -0
- package/server/lib/pi/ui-settings-store.js +130 -25
- package/server/lib/pi/ui-settings-store.test.js +58 -7
- package/dist/assets/SettingsView-C0S0Sx-S.js +0 -2
|
@@ -6,6 +6,7 @@ import { homedir, tmpdir } from 'node:os';
|
|
|
6
6
|
import { join } from 'node:path';
|
|
7
7
|
import { StringDecoder } from 'node:string_decoder';
|
|
8
8
|
|
|
9
|
+
import { requestSessionDaemon } from './ipc-client.js';
|
|
9
10
|
import { createMessageEntryAliases } from './message-entry-aliases.js';
|
|
10
11
|
import { createSessionDaemon as createSessionDaemonImpl, isLocalSessionDaemonEndpoint } from './session-daemon.js';
|
|
11
12
|
|
|
@@ -296,6 +297,66 @@ describe('Pi session daemon spike', () => {
|
|
|
296
297
|
await reconnectingClient.close();
|
|
297
298
|
});
|
|
298
299
|
|
|
300
|
+
it('projects the authoritative tool start through session hydration for active and completed calls', async () => {
|
|
301
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
302
|
+
const endpoint = testDaemonEndpoint(root);
|
|
303
|
+
const session = new FakeSession();
|
|
304
|
+
daemon = createSessionDaemon({ endpoint, credential, cwd: root, createRuntime: async () => ({ session, async dispose() {} }) });
|
|
305
|
+
await daemon.start();
|
|
306
|
+
|
|
307
|
+
const client = connectClient(endpoint);
|
|
308
|
+
await client.authenticate();
|
|
309
|
+
await client.request('sessions.create', { cwd: root });
|
|
310
|
+
session.isStreaming = true;
|
|
311
|
+
session.entries = [{
|
|
312
|
+
type: 'message',
|
|
313
|
+
id: 'assistant-entry',
|
|
314
|
+
timestamp: '2026-01-01T00:00:01.000Z',
|
|
315
|
+
message: {
|
|
316
|
+
role: 'assistant',
|
|
317
|
+
provider: 'test',
|
|
318
|
+
model: 'model',
|
|
319
|
+
content: [{ type: 'toolCall', id: 'tool-1', name: 'read', arguments: { path: 'file.txt' } }],
|
|
320
|
+
},
|
|
321
|
+
}];
|
|
322
|
+
|
|
323
|
+
const toolStartPromise = client.next((message) => message.event === 'session.tool.start');
|
|
324
|
+
session.emit({ type: 'tool_execution_start', toolCallId: 'tool-1', toolName: 'read', args: { path: 'file.txt' } });
|
|
325
|
+
const toolStart = await toolStartPromise;
|
|
326
|
+
const activeDetail = await client.request('sessions.open', { sessionId: session.sessionId, directory: root });
|
|
327
|
+
const activeTool = activeDetail.result.messages[0].parts[0];
|
|
328
|
+
expect(activeTool).toMatchObject({
|
|
329
|
+
toolCallId: 'tool-1',
|
|
330
|
+
state: 'running',
|
|
331
|
+
startedAt: toolStart.payload.startedAt,
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
session.entries.push({
|
|
335
|
+
type: 'message',
|
|
336
|
+
id: 'tool-result-entry',
|
|
337
|
+
timestamp: new Date(Date.now()).toISOString(),
|
|
338
|
+
message: {
|
|
339
|
+
role: 'toolResult',
|
|
340
|
+
toolCallId: 'tool-1',
|
|
341
|
+
isError: false,
|
|
342
|
+
content: [{ type: 'text', text: 'file contents' }],
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
const toolEndPromise = client.next((message) => message.event === 'session.tool.end');
|
|
346
|
+
session.emit({ type: 'tool_execution_end', toolCallId: 'tool-1', toolName: 'read', result: { content: [{ type: 'text', text: 'file contents' }] }, isError: false });
|
|
347
|
+
const toolEnd = await toolEndPromise;
|
|
348
|
+
const completedDetail = await client.request('sessions.open', { sessionId: session.sessionId, directory: root });
|
|
349
|
+
const completedTool = completedDetail.result.messages[0].parts[0];
|
|
350
|
+
expect(completedTool).toMatchObject({
|
|
351
|
+
toolCallId: 'tool-1',
|
|
352
|
+
state: 'completed',
|
|
353
|
+
startedAt: toolStart.payload.startedAt,
|
|
354
|
+
endedAt: expect.any(Number),
|
|
355
|
+
});
|
|
356
|
+
expect(toolEnd.payload.startedAt).toBe(toolStart.payload.startedAt);
|
|
357
|
+
await client.close();
|
|
358
|
+
});
|
|
359
|
+
|
|
299
360
|
it('replays a contiguous reconnect gap and sends a snapshot when the cursor predates retained events', async () => {
|
|
300
361
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
301
362
|
const endpoint = testDaemonEndpoint(root);
|
|
@@ -1241,6 +1302,146 @@ describe('Pi session daemon spike', () => {
|
|
|
1241
1302
|
await client.close();
|
|
1242
1303
|
}, 2_000);
|
|
1243
1304
|
|
|
1305
|
+
it('opens a transcript whose complete projection exceeds the IPC frame limit', async () => {
|
|
1306
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-paged-transcript-'));
|
|
1307
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1308
|
+
const persistedSessionFile = join(root, 'persisted.jsonl');
|
|
1309
|
+
await writeFile(persistedSessionFile, `{"type":"session","id":"pi-session-paged","cwd":"${root}"}\n`);
|
|
1310
|
+
const session = new FakeSession('pi-session-paged', persistedSessionFile);
|
|
1311
|
+
const largeOutput = 'A'.repeat(1_100_000);
|
|
1312
|
+
session.entries = [{
|
|
1313
|
+
type: 'message',
|
|
1314
|
+
id: 'user-0',
|
|
1315
|
+
timestamp: '2026-01-01T00:00:00.000Z',
|
|
1316
|
+
message: { role: 'user', content: 'Inspect the large fixture.' },
|
|
1317
|
+
}, ...Array.from({ length: 17 }, (_, index) => [{
|
|
1318
|
+
type: 'message',
|
|
1319
|
+
id: `assistant-${index}`,
|
|
1320
|
+
timestamp: new Date(Date.UTC(2026, 0, 1, 0, 0, index * 2)).toISOString(),
|
|
1321
|
+
message: {
|
|
1322
|
+
role: 'assistant',
|
|
1323
|
+
provider: 'test',
|
|
1324
|
+
model: 'model',
|
|
1325
|
+
content: [{ type: 'toolCall', id: `tool-${index}`, name: 'read', arguments: { index } }],
|
|
1326
|
+
},
|
|
1327
|
+
}, {
|
|
1328
|
+
type: 'message',
|
|
1329
|
+
id: `result-${index}`,
|
|
1330
|
+
timestamp: new Date(Date.UTC(2026, 0, 1, 0, 0, index * 2 + 1)).toISOString(),
|
|
1331
|
+
message: {
|
|
1332
|
+
role: 'toolResult',
|
|
1333
|
+
toolCallId: `tool-${index}`,
|
|
1334
|
+
toolName: 'read',
|
|
1335
|
+
content: [{ type: 'text', text: largeOutput }],
|
|
1336
|
+
isError: false,
|
|
1337
|
+
},
|
|
1338
|
+
}]).flat()];
|
|
1339
|
+
const runtime = new FakeRuntime({ cwd: root, session });
|
|
1340
|
+
daemon = createSessionDaemon({
|
|
1341
|
+
endpoint,
|
|
1342
|
+
credential,
|
|
1343
|
+
cwd: root,
|
|
1344
|
+
createRuntime: async () => runtime,
|
|
1345
|
+
listSessions: async () => [{
|
|
1346
|
+
path: persistedSessionFile,
|
|
1347
|
+
id: 'pi-session-paged',
|
|
1348
|
+
cwd: root,
|
|
1349
|
+
created: new Date('2026-01-01T00:00:00.000Z'),
|
|
1350
|
+
modified: new Date('2026-01-01T00:00:01.000Z'),
|
|
1351
|
+
messageCount: session.entries.length,
|
|
1352
|
+
}],
|
|
1353
|
+
});
|
|
1354
|
+
await daemon.start();
|
|
1355
|
+
|
|
1356
|
+
const opened = await requestSessionDaemon({
|
|
1357
|
+
endpoint,
|
|
1358
|
+
credential,
|
|
1359
|
+
command: 'sessions.open',
|
|
1360
|
+
payload: { sessionId: 'pi-session-paged', directory: root },
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
expect(opened.messages.length).toBeLessThan(17);
|
|
1364
|
+
expect(opened.hasMoreBefore).toBe(true);
|
|
1365
|
+
expect(typeof opened.beforeCursor).toBe('string');
|
|
1366
|
+
expect(Buffer.byteLength(JSON.stringify(opened))).toBeLessThan(16 * 1024 * 1024);
|
|
1367
|
+
|
|
1368
|
+
const pages = [opened.messages];
|
|
1369
|
+
let before = opened.beforeCursor;
|
|
1370
|
+
while (before) {
|
|
1371
|
+
const page = await requestSessionDaemon({
|
|
1372
|
+
endpoint,
|
|
1373
|
+
credential,
|
|
1374
|
+
command: 'sessions.messages',
|
|
1375
|
+
payload: { sessionId: 'pi-session-paged', directory: root, before },
|
|
1376
|
+
});
|
|
1377
|
+
pages.unshift(page.messages);
|
|
1378
|
+
before = page.beforeCursor;
|
|
1379
|
+
}
|
|
1380
|
+
const messages = pages.flat();
|
|
1381
|
+
const uniqueMessages = [...new Map(messages.map((entry) => [entry.message.id, entry])).values()];
|
|
1382
|
+
expect(uniqueMessages.map((entry) => entry.message.id)).toEqual([
|
|
1383
|
+
'user-0',
|
|
1384
|
+
...Array.from({ length: 17 }, (_, index) => `assistant-${index}`),
|
|
1385
|
+
]);
|
|
1386
|
+
expect(uniqueMessages.filter((entry) => entry.message.role === 'assistant')
|
|
1387
|
+
.every((entry) => entry.parts[0].output === largeOutput)).toBe(true);
|
|
1388
|
+
expect(opened.messages.some((entry) => entry.message.id === 'user-0')).toBe(true);
|
|
1389
|
+
}, 30_000);
|
|
1390
|
+
|
|
1391
|
+
it('reports a single unpageable message as too large instead of malformed', async () => {
|
|
1392
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-oversized-'));
|
|
1393
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1394
|
+
const persistedSessionFile = join(root, 'persisted.jsonl');
|
|
1395
|
+
await writeFile(persistedSessionFile, `{"type":"session","id":"pi-session-oversized","cwd":"${root}"}\n`);
|
|
1396
|
+
const session = new FakeSession('pi-session-oversized', persistedSessionFile);
|
|
1397
|
+
const hugeOutput = 'B'.repeat(17 * 1024 * 1024);
|
|
1398
|
+
session.entries = [{
|
|
1399
|
+
type: 'message',
|
|
1400
|
+
id: 'assistant-huge',
|
|
1401
|
+
timestamp: '2026-01-01T00:00:02.000Z',
|
|
1402
|
+
message: {
|
|
1403
|
+
role: 'assistant',
|
|
1404
|
+
provider: 'test',
|
|
1405
|
+
model: 'model',
|
|
1406
|
+
content: [{ type: 'toolCall', id: 'huge-tool', name: 'read', arguments: {} }],
|
|
1407
|
+
},
|
|
1408
|
+
}, {
|
|
1409
|
+
type: 'message',
|
|
1410
|
+
id: 'result-huge',
|
|
1411
|
+
timestamp: '2026-01-01T00:00:03.000Z',
|
|
1412
|
+
message: {
|
|
1413
|
+
role: 'toolResult',
|
|
1414
|
+
toolCallId: 'huge-tool',
|
|
1415
|
+
toolName: 'read',
|
|
1416
|
+
content: [{ type: 'text', text: hugeOutput }],
|
|
1417
|
+
isError: false,
|
|
1418
|
+
},
|
|
1419
|
+
}];
|
|
1420
|
+
const runtime = new FakeRuntime({ cwd: root, session });
|
|
1421
|
+
daemon = createSessionDaemon({
|
|
1422
|
+
endpoint,
|
|
1423
|
+
credential,
|
|
1424
|
+
cwd: root,
|
|
1425
|
+
createRuntime: async () => runtime,
|
|
1426
|
+
listSessions: async () => [{
|
|
1427
|
+
path: persistedSessionFile,
|
|
1428
|
+
id: 'pi-session-oversized',
|
|
1429
|
+
cwd: root,
|
|
1430
|
+
created: new Date('2026-01-01T00:00:00.000Z'),
|
|
1431
|
+
modified: new Date('2026-01-01T00:00:01.000Z'),
|
|
1432
|
+
messageCount: 1,
|
|
1433
|
+
}],
|
|
1434
|
+
});
|
|
1435
|
+
await daemon.start();
|
|
1436
|
+
|
|
1437
|
+
await expect(requestSessionDaemon({
|
|
1438
|
+
endpoint,
|
|
1439
|
+
credential,
|
|
1440
|
+
command: 'sessions.open',
|
|
1441
|
+
payload: { sessionId: 'pi-session-oversized', directory: root },
|
|
1442
|
+
})).rejects.toMatchObject({ code: 'DAEMON_RESPONSE_TOO_LARGE' });
|
|
1443
|
+
}, 30_000);
|
|
1444
|
+
|
|
1244
1445
|
it('keeps Pi global/project defaults and trust decisions authoritative', async () => {
|
|
1245
1446
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-settings-'));
|
|
1246
1447
|
const cwd = join(root, 'project');
|
|
@@ -1266,6 +1467,80 @@ describe('Pi session daemon spike', () => {
|
|
|
1266
1467
|
await client.close();
|
|
1267
1468
|
});
|
|
1268
1469
|
|
|
1470
|
+
it('persists project trust while streaming and refreshes after settlement', async () => {
|
|
1471
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-settings-busy-'));
|
|
1472
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1473
|
+
const session = new FakeSession();
|
|
1474
|
+
const runtimeState = { createCount: 0, disposeCount: 0 };
|
|
1475
|
+
daemon = createSessionDaemon({
|
|
1476
|
+
endpoint,
|
|
1477
|
+
credential,
|
|
1478
|
+
cwd: root,
|
|
1479
|
+
createRuntime: async () => {
|
|
1480
|
+
runtimeState.createCount += 1;
|
|
1481
|
+
return {
|
|
1482
|
+
cwd: root,
|
|
1483
|
+
session,
|
|
1484
|
+
async dispose() { runtimeState.disposeCount += 1; },
|
|
1485
|
+
};
|
|
1486
|
+
},
|
|
1487
|
+
});
|
|
1488
|
+
await daemon.start();
|
|
1489
|
+
const client = connectClient(endpoint);
|
|
1490
|
+
await client.authenticate();
|
|
1491
|
+
await client.request('sessions.create', { cwd: root });
|
|
1492
|
+
|
|
1493
|
+
session.isStreaming = true;
|
|
1494
|
+
const result = await client.request('settings.set', { scope: 'project', trust: true });
|
|
1495
|
+
expect(result.result).toMatchObject({ project: { trusted: true }, deferred: true });
|
|
1496
|
+
expect(runtimeState).toEqual({ createCount: 1, disposeCount: 0 });
|
|
1497
|
+
|
|
1498
|
+
session.isStreaming = false;
|
|
1499
|
+
session.emit({ type: 'agent_settled' });
|
|
1500
|
+
await expect.poll(() => runtimeState.disposeCount).toBe(1);
|
|
1501
|
+
expect(runtimeState.createCount).toBe(2);
|
|
1502
|
+
await client.close();
|
|
1503
|
+
});
|
|
1504
|
+
|
|
1505
|
+
it('reports deferred activation when an idle runtime cannot be recreated after trust commits', async () => {
|
|
1506
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-settings-recreate-failure-'));
|
|
1507
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1508
|
+
let createCount = 0;
|
|
1509
|
+
daemon = createSessionDaemon({
|
|
1510
|
+
endpoint,
|
|
1511
|
+
credential,
|
|
1512
|
+
cwd: root,
|
|
1513
|
+
createRuntime: async () => {
|
|
1514
|
+
createCount += 1;
|
|
1515
|
+
if (createCount === 2) throw new Error('runtime recreation failed');
|
|
1516
|
+
return {
|
|
1517
|
+
cwd: root,
|
|
1518
|
+
session: new FakeSession(),
|
|
1519
|
+
services: {
|
|
1520
|
+
resourceLoader: {
|
|
1521
|
+
getSkills: () => ({ skills: [] }),
|
|
1522
|
+
getPrompts: () => ({ prompts: [] }),
|
|
1523
|
+
getAgentsFiles: () => ({ agentsFiles: [] }),
|
|
1524
|
+
},
|
|
1525
|
+
},
|
|
1526
|
+
async dispose() {},
|
|
1527
|
+
};
|
|
1528
|
+
},
|
|
1529
|
+
});
|
|
1530
|
+
await daemon.start();
|
|
1531
|
+
const client = connectClient(endpoint);
|
|
1532
|
+
await client.authenticate();
|
|
1533
|
+
await client.request('sessions.create', { cwd: root });
|
|
1534
|
+
|
|
1535
|
+
const result = await client.request('settings.set', { scope: 'project', trust: true });
|
|
1536
|
+
expect(result.result).toMatchObject({ project: { trusted: true }, deferred: true });
|
|
1537
|
+
expect(createCount).toBe(2);
|
|
1538
|
+
|
|
1539
|
+
await expect(client.request('resources.list')).resolves.toMatchObject({ result: { agents: expect.any(Array) } });
|
|
1540
|
+
expect(createCount).toBe(3);
|
|
1541
|
+
await client.close();
|
|
1542
|
+
});
|
|
1543
|
+
|
|
1269
1544
|
it('lists and edits only opaque Pi resource identifiers without disclosing server paths', async () => {
|
|
1270
1545
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-resources-'));
|
|
1271
1546
|
const cwd = join(root, 'project');
|
|
@@ -1370,6 +1645,58 @@ describe('Pi session daemon spike', () => {
|
|
|
1370
1645
|
await client.close();
|
|
1371
1646
|
});
|
|
1372
1647
|
|
|
1648
|
+
it('persists provider model changes while streaming and refreshes after settlement', async () => {
|
|
1649
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-provider-busy-'));
|
|
1650
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1651
|
+
const session = new FakeSession();
|
|
1652
|
+
const runtimeState = { createCount: 0, disposeCount: 0 };
|
|
1653
|
+
const updates = [];
|
|
1654
|
+
const modelConfigStore = {
|
|
1655
|
+
get: async () => null,
|
|
1656
|
+
update: async (input) => {
|
|
1657
|
+
updates.push(input);
|
|
1658
|
+
return { providerId: input.providerId, label: input.label, baseUrl: input.baseUrl, api: input.api, models: input.models };
|
|
1659
|
+
},
|
|
1660
|
+
};
|
|
1661
|
+
daemon = createSessionDaemon({
|
|
1662
|
+
endpoint,
|
|
1663
|
+
credential,
|
|
1664
|
+
cwd: root,
|
|
1665
|
+
modelConfigStore,
|
|
1666
|
+
createRuntime: async () => {
|
|
1667
|
+
runtimeState.createCount += 1;
|
|
1668
|
+
return {
|
|
1669
|
+
cwd: root,
|
|
1670
|
+
session,
|
|
1671
|
+
async dispose() { runtimeState.disposeCount += 1; },
|
|
1672
|
+
};
|
|
1673
|
+
},
|
|
1674
|
+
});
|
|
1675
|
+
await daemon.start();
|
|
1676
|
+
const client = connectClient(endpoint);
|
|
1677
|
+
await client.authenticate();
|
|
1678
|
+
|
|
1679
|
+
await client.request('sessions.create', { cwd: root });
|
|
1680
|
+
session.isStreaming = true;
|
|
1681
|
+
const result = await client.request('providers.models.set', {
|
|
1682
|
+
providerId: 'custom',
|
|
1683
|
+
label: 'Custom',
|
|
1684
|
+
baseUrl: 'https://api.example.test/v1',
|
|
1685
|
+
api: 'openai-completions',
|
|
1686
|
+
models: [{ id: 'model', providerId: 'custom', label: 'Model' }],
|
|
1687
|
+
});
|
|
1688
|
+
|
|
1689
|
+
expect(result.result).toMatchObject({ config: { providerId: 'custom' }, deferred: true });
|
|
1690
|
+
expect(updates).toHaveLength(1);
|
|
1691
|
+
expect(runtimeState).toEqual({ createCount: 1, disposeCount: 0 });
|
|
1692
|
+
|
|
1693
|
+
session.isStreaming = false;
|
|
1694
|
+
session.emit({ type: 'agent_settled' });
|
|
1695
|
+
await expect.poll(() => runtimeState.disposeCount).toBe(1);
|
|
1696
|
+
expect(runtimeState.createCount).toBe(2);
|
|
1697
|
+
await client.close();
|
|
1698
|
+
});
|
|
1699
|
+
|
|
1373
1700
|
it('runs persisted API-key and interactive OAuth logins without exposing credential values in daemon responses', async () => {
|
|
1374
1701
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1375
1702
|
const endpoint = testDaemonEndpoint(root);
|
|
@@ -6,6 +6,58 @@ import { resolvePiChamberDataDir } from '../pichamber-data-dir.js';
|
|
|
6
6
|
import { withCrossProcessLock } from '../server/cross-process-lock.js';
|
|
7
7
|
|
|
8
8
|
const MAX_SETTINGS_BYTES = 2 * 1024 * 1024;
|
|
9
|
+
const PORTABLE_SETTINGS_MARKER = '__pichamberSettingsScope';
|
|
10
|
+
const PORTABLE_SETTINGS_VERSION = 'portable-v1';
|
|
11
|
+
|
|
12
|
+
// Keep this list explicit. settings.json is intended to be copied between hosts.
|
|
13
|
+
const PORTABLE_FIELDS = new Set([
|
|
14
|
+
'themeId', 'useSystemTheme', 'themeVariant', 'lightThemeId', 'darkThemeId',
|
|
15
|
+
'splashBgLight', 'splashFgLight', 'splashBgDark', 'splashFgDark',
|
|
16
|
+
'showReasoningTraces', 'collapsibleThinkingBlocks', 'collapseThinkingByDefault',
|
|
17
|
+
'showDeletionDialog', 'nativeNotificationsEnabled', 'notificationMode',
|
|
18
|
+
'notifyOnSubtasks', 'notifyOnCompletion', 'notifyOnError', 'notifyOnQuestion',
|
|
19
|
+
'notificationTemplates', 'summarizeLastMessage', 'summaryThreshold', 'summaryLength',
|
|
20
|
+
'maxLastMessageLength', 'usageAutoRefresh', 'usageRefreshIntervalMs',
|
|
21
|
+
'usageDisplayMode', 'usageShowPredValues', 'usageDropdownProviders',
|
|
22
|
+
'usageSelectedModels', 'usageCollapsedFamilies', 'usageExpandedFamilies', 'usageModelGroups',
|
|
23
|
+
'autoDeleteEnabled', 'autoSaveEnabled', 'autoDeleteAfterDays', 'sessionRetentionAction',
|
|
24
|
+
'defaultModel', 'defaultVariant', 'smallModelUseDefault', 'smallModelOverride',
|
|
25
|
+
'walkthroughModelOverride', 'followUpBehavior', 'queueModeEnabled', 'gitmojiEnabled',
|
|
26
|
+
'defaultFileViewerPreview', 'zenModel', 'gitProviderId', 'gitModelId',
|
|
27
|
+
'inputSpellcheckEnabled', 'showToolFileIcons', 'codeBlockLineWrap', 'showTurnChangedFiles',
|
|
28
|
+
'showExpandedBashTools', 'showExpandedEditTools', 'timeFormatPreference',
|
|
29
|
+
'weekStartPreference', 'mermaidRenderingMode', 'userMessageRenderingMode',
|
|
30
|
+
'collapsibleUserMessages', 'stickyUserHeader', 'promptNavigatorEnabled',
|
|
31
|
+
'expandedEditorToolbar', 'wideChatLayoutEnabled', 'showSplitAssistantMessageActions',
|
|
32
|
+
'fontSize', 'terminalFontSize', 'editorFontSize', 'uiFont', 'monoFont', 'padding',
|
|
33
|
+
'cornerRadius', 'inputBarOffset', 'shortcutOverrides', 'commandTriggers',
|
|
34
|
+
'favoriteModels', 'hiddenModels', 'collapsedModelProviders', 'recentModels',
|
|
35
|
+
'recentAgents', 'recentEfforts', 'diffLayoutPreference', 'gitChangesViewMode',
|
|
36
|
+
'directoryShowHidden', 'filesViewShowGitignored', 'messageLimit',
|
|
37
|
+
'responseStyleEnabled', 'responseStylePreset', 'responseStyleCustomInstructions',
|
|
38
|
+
'draftStarters', 'draftStartersVisible', 'draftStartersScheduleTaskAdded',
|
|
39
|
+
'autoCreateWorktree', 'globalBehaviorPrompt', 'skillCatalogs', 'messageStreamTransport',
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
// These values describe one host or device. Secrets are local too, so they can
|
|
43
|
+
// still be consumed by the existing authenticated API without entering the
|
|
44
|
+
// portable file.
|
|
45
|
+
const LOCAL_FIELDS = new Set([
|
|
46
|
+
'lastDirectory', 'homeDirectory', 'projects', 'activeProjectId',
|
|
47
|
+
'securityScopedBookmarks', 'pinnedDirectories', 'defaultGitIdentityId', 'openInAppId',
|
|
48
|
+
'terminalShell', 'terminalLoginShells', 'desktopLanAccessEnabled',
|
|
49
|
+
'desktopKeepAwakeEnabled', 'desktopProcessPerformanceRecordingEnabled',
|
|
50
|
+
'desktopMinimizeToTrayEnabled', 'desktopMacMenuBarEnabled',
|
|
51
|
+
'desktopWindowControlsPosition', 'desktopWindowControlsStyle',
|
|
52
|
+
'desktopWindowState', 'desktopLocalPort', 'desktopInstallId', 'desktopHosts',
|
|
53
|
+
'desktopDefaultHostId', 'desktopInitialHostChoiceCompleted',
|
|
54
|
+
'pwaAppName', 'pwaOrientation', 'mobileKeyboardMode',
|
|
55
|
+
'tunnelProvider', 'tunnelMode', 'tunnelBootstrapTtlMs', 'tunnelSessionTtlMs',
|
|
56
|
+
'managedLocalTunnelConfigPath', 'managedRemoteTunnelHostname',
|
|
57
|
+
'managedRemoteTunnelPresets', 'managedRemoteTunnelSelectedPresetId',
|
|
58
|
+
'managedRemoteTunnelToken', 'managedRemoteTunnelPresetTokens',
|
|
59
|
+
'hasManagedRemoteTunnelToken', 'desktopUiPassword', 'desktopLocalClientToken',
|
|
60
|
+
]);
|
|
9
61
|
|
|
10
62
|
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
11
63
|
|
|
@@ -28,42 +80,95 @@ const validateRecord = (value) => {
|
|
|
28
80
|
return value;
|
|
29
81
|
};
|
|
30
82
|
|
|
83
|
+
const selectFields = (value, fields) => Object.fromEntries(
|
|
84
|
+
Object.entries(value).filter(([key]) => fields.has(key)),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const readRecord = async (file, fs) => {
|
|
88
|
+
try {
|
|
89
|
+
const raw = await fs.readFile(file, 'utf8');
|
|
90
|
+
if (Buffer.byteLength(raw) > MAX_SETTINGS_BYTES) throw new Error('UI_SETTINGS_INVALID');
|
|
91
|
+
return validateRecord(JSON.parse(raw));
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (error?.code === 'ENOENT') return {};
|
|
94
|
+
if (error?.message === 'UI_SETTINGS_INVALID') throw error;
|
|
95
|
+
throw new Error('UI_SETTINGS_INVALID');
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const writeRecord = async (file, value, fs) => {
|
|
100
|
+
const serialized = `${JSON.stringify(value, null, 2)}\n`;
|
|
101
|
+
if (Buffer.byteLength(serialized) > MAX_SETTINGS_BYTES) throw new Error('UI_SETTINGS_INVALID');
|
|
102
|
+
const parent = dirname(file);
|
|
103
|
+
await fs.mkdir(parent, { recursive: true, mode: 0o700 });
|
|
104
|
+
const temporary = `${file}.tmp-${process.pid}-${randomUUID()}`;
|
|
105
|
+
await fs.writeFile(temporary, serialized, { encoding: 'utf8', mode: 0o600 });
|
|
106
|
+
await fs.rename(temporary, file);
|
|
107
|
+
if (process.platform !== 'win32') await fs.chmod(file, 0o600);
|
|
108
|
+
};
|
|
109
|
+
|
|
31
110
|
export const createPiUiSettingsStore = ({
|
|
32
111
|
file = join(resolvePiChamberDataDir(), 'settings.json'),
|
|
112
|
+
runtimeFile = join(dirname(file), 'runtime-state.json'),
|
|
33
113
|
fs = { chmod, mkdir, readFile, rename, writeFile },
|
|
34
114
|
} = {}) => {
|
|
35
115
|
let mutation = Promise.resolve();
|
|
36
116
|
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
117
|
+
const readLocked = async () => {
|
|
118
|
+
const portableRoot = await readRecord(file, fs);
|
|
119
|
+
const runtimeRoot = await readRecord(runtimeFile, fs);
|
|
120
|
+
const migrated = portableRoot[PORTABLE_SETTINGS_MARKER] === PORTABLE_SETTINGS_VERSION;
|
|
121
|
+
|
|
122
|
+
if (!migrated) {
|
|
123
|
+
const migratedRuntime = {
|
|
124
|
+
...selectFields(runtimeRoot, LOCAL_FIELDS),
|
|
125
|
+
...selectFields(portableRoot, LOCAL_FIELDS),
|
|
126
|
+
};
|
|
127
|
+
const migratedPortable = {
|
|
128
|
+
[PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
|
|
129
|
+
...selectFields(portableRoot, PORTABLE_FIELDS),
|
|
130
|
+
};
|
|
131
|
+
// Local state goes first. A failure cannot strand host state only in a
|
|
132
|
+
// portable file that a later successful write might replace.
|
|
133
|
+
await writeRecord(runtimeFile, migratedRuntime, fs);
|
|
134
|
+
await writeRecord(file, migratedPortable, fs);
|
|
135
|
+
return { ...selectFields(migratedPortable, PORTABLE_FIELDS), ...selectFields(migratedRuntime, LOCAL_FIELDS) };
|
|
46
136
|
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
...selectFields(portableRoot, PORTABLE_FIELDS),
|
|
140
|
+
...selectFields(runtimeRoot, LOCAL_FIELDS),
|
|
141
|
+
};
|
|
47
142
|
};
|
|
48
143
|
|
|
144
|
+
const runMutation = (operation) => {
|
|
145
|
+
const next = mutation.then(() => withCrossProcessLock(`${file}.lock`, operation));
|
|
146
|
+
mutation = next.catch(() => {});
|
|
147
|
+
return next;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const read = () => runMutation(readLocked);
|
|
151
|
+
|
|
49
152
|
const write = async (changes) => {
|
|
50
153
|
validateRecord(changes);
|
|
51
|
-
|
|
52
|
-
const current = await
|
|
53
|
-
const
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
154
|
+
return runMutation(async () => {
|
|
155
|
+
const current = await readLocked();
|
|
156
|
+
const portableChanges = selectFields(changes, PORTABLE_FIELDS);
|
|
157
|
+
const localChanges = selectFields(changes, LOCAL_FIELDS);
|
|
158
|
+
const nextPortable = {
|
|
159
|
+
[PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
|
|
160
|
+
...selectFields(current, PORTABLE_FIELDS),
|
|
161
|
+
...portableChanges,
|
|
162
|
+
};
|
|
163
|
+
const nextRuntime = {
|
|
164
|
+
...selectFields(current, LOCAL_FIELDS),
|
|
165
|
+
...localChanges,
|
|
166
|
+
};
|
|
167
|
+
await writeRecord(runtimeFile, nextRuntime, fs);
|
|
168
|
+
await writeRecord(file, nextPortable, fs);
|
|
169
|
+
return { ...selectFields(nextPortable, PORTABLE_FIELDS), ...selectFields(nextRuntime, LOCAL_FIELDS) };
|
|
170
|
+
});
|
|
66
171
|
};
|
|
67
172
|
|
|
68
|
-
return { file, read, write };
|
|
173
|
+
return { file, runtimeFile, read, write };
|
|
69
174
|
};
|
|
@@ -8,28 +8,79 @@ import { createPiUiSettingsStore } from './ui-settings-store.js';
|
|
|
8
8
|
const makeStore = async () => {
|
|
9
9
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-ui-settings-'));
|
|
10
10
|
const file = join(root, 'settings.json');
|
|
11
|
-
|
|
11
|
+
const runtimeFile = join(root, 'runtime-state.json');
|
|
12
|
+
return { file, runtimeFile, store: createPiUiSettingsStore({ file, runtimeFile }) };
|
|
12
13
|
};
|
|
13
14
|
|
|
15
|
+
const readJson = async (file) => JSON.parse(await readFile(file, 'utf8'));
|
|
16
|
+
|
|
14
17
|
describe('Pi UI settings store', () => {
|
|
15
|
-
it('distinguishes
|
|
18
|
+
it('distinguishes malformed persisted settings from a fresh store', async () => {
|
|
16
19
|
const { file, store } = await makeStore();
|
|
17
20
|
await expect(store.read()).resolves.toEqual({});
|
|
18
21
|
await writeFile(file, '{broken');
|
|
19
22
|
await expect(store.read()).rejects.toThrow('UI_SETTINGS_INVALID');
|
|
20
23
|
});
|
|
21
24
|
|
|
22
|
-
it('
|
|
23
|
-
const { file, store } = await makeStore();
|
|
25
|
+
it('migrates a flat settings file into portable and local allowlists', async () => {
|
|
26
|
+
const { file, runtimeFile, store } = await makeStore();
|
|
27
|
+
await writeFile(file, JSON.stringify({
|
|
28
|
+
themeId: 'nord',
|
|
29
|
+
homeDirectory: '/old-home',
|
|
30
|
+
projects: [{ id: 'old', path: '/old-home/project' }],
|
|
31
|
+
desktopUiPassword: 'secret',
|
|
32
|
+
unknownField: 'drop-me',
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
await expect(store.read()).resolves.toMatchObject({
|
|
36
|
+
themeId: 'nord',
|
|
37
|
+
homeDirectory: '/old-home',
|
|
38
|
+
projects: [{ id: 'old', path: '/old-home/project' }],
|
|
39
|
+
desktopUiPassword: 'secret',
|
|
40
|
+
});
|
|
41
|
+
await expect(readJson(file)).resolves.toEqual({
|
|
42
|
+
__pichamberSettingsScope: 'portable-v1',
|
|
43
|
+
themeId: 'nord',
|
|
44
|
+
});
|
|
45
|
+
await expect(readJson(runtimeFile)).resolves.toEqual({
|
|
46
|
+
homeDirectory: '/old-home',
|
|
47
|
+
projects: [{ id: 'old', path: '/old-home/project' }],
|
|
48
|
+
desktopUiPassword: 'secret',
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('does not apply local fields copied in from another home', async () => {
|
|
53
|
+
const source = await makeStore();
|
|
54
|
+
await source.store.write({ themeId: 'nord', homeDirectory: '/mnt/data', projects: [{ id: 'one', path: '/mnt/data/project' }] });
|
|
55
|
+
|
|
56
|
+
const target = await makeStore();
|
|
57
|
+
await target.store.write({ homeDirectory: '/root', projects: [{ id: 'two', path: '/root/project' }] });
|
|
58
|
+
await writeFile(target.file, await readFile(source.file));
|
|
59
|
+
|
|
60
|
+
await expect(target.store.read()).resolves.toEqual({
|
|
61
|
+
themeId: 'nord',
|
|
62
|
+
homeDirectory: '/root',
|
|
63
|
+
projects: [{ id: 'two', path: '/root/project' }],
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('serializes scoped merge writes without dropping unrelated fields', async () => {
|
|
68
|
+
const { file, runtimeFile, store } = await makeStore();
|
|
24
69
|
await Promise.all([
|
|
25
|
-
store.write({
|
|
70
|
+
store.write({ themeId: 'dark' }),
|
|
26
71
|
store.write({ projects: [{ id: 'one', path: '/one' }] }),
|
|
27
72
|
]);
|
|
28
73
|
await expect(store.read()).resolves.toEqual({
|
|
29
|
-
|
|
74
|
+
themeId: 'dark',
|
|
75
|
+
projects: [{ id: 'one', path: '/one' }],
|
|
76
|
+
});
|
|
77
|
+
await expect(readJson(file)).resolves.toEqual({
|
|
78
|
+
__pichamberSettingsScope: 'portable-v1',
|
|
79
|
+
themeId: 'dark',
|
|
80
|
+
});
|
|
81
|
+
await expect(readJson(runtimeFile)).resolves.toEqual({
|
|
30
82
|
projects: [{ id: 'one', path: '/one' }],
|
|
31
83
|
});
|
|
32
|
-
expect(JSON.parse(await readFile(file, 'utf8'))).toMatchObject({ themeMode: 'dark' });
|
|
33
84
|
});
|
|
34
85
|
|
|
35
86
|
it('rejects prototype-polluting keys', async () => {
|