@pi-chamber/web 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CommitSection-0zl1puqf.js → CommitSection-Cz-ACBaD.js} +1 -1
- package/dist/assets/DiagramEditor-BNUOrd9m.js +1 -0
- package/dist/assets/DiagramView-D4YR9YRt.js +1 -0
- package/dist/assets/{DiffView-BoTz2Zqe.js → DiffView-DPW8dcg_.js} +3 -3
- package/dist/assets/{FilesView-CVMNE9Pr.js → FilesView-BFGIdY6b.js} +6 -6
- package/dist/assets/{GitView-DnsbCAWl.js → GitView-CKtiKOfJ.js} +4 -4
- package/dist/assets/{JsonTreeView-Cn1Mk0Wf.js → JsonTreeView-c-UJUw3D.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DJKD8tNq.js → MarkdownRendererImpl-CvC9eXoa.js} +2 -2
- package/dist/assets/{PatchDiff-GdGq3IlM.js → PatchDiff-YGHsZUIR.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CdkAUt-S.js → PierreDiffViewer-CoXa-JJK.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-BTzVmIop.js → SessionSwitcherContent-B7eep3dO.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-CZOFeJHH.js +2 -0
- package/dist/assets/SessionUnreadDot-ClpeYFPz.js +1 -0
- package/dist/assets/SettingsView-CPmHHDbQ.js +4 -0
- package/dist/assets/SettingsWindow-2CBpoJ8H.js +1 -0
- package/dist/assets/{ToolOutputDialog-BHaf293m.js → ToolOutputDialog-HMW-Kh19.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-BTMXNcqG.js → ToolPartDiffPreview-C3nbNbxk.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CRVvv23V.js → VirtualizedFileDiff-DEX83nQ0.js} +4 -4
- package/dist/assets/{WindowsWindowControls-CTtxXnD1.js → WindowsWindowControls-PPk5H89-.js} +129 -124
- package/dist/assets/collapsible-Dux-9hAC.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-D1I8YrPV.js → computeVirtualFileMetrics-Cy0nxMJB.js} +1 -1
- package/dist/assets/contextFileOpenGuard-Dn_38hd9.js +1 -0
- package/dist/assets/index--zDkVFU6.css +1 -0
- package/dist/assets/index-DU2OBBy5.js +8 -0
- package/dist/assets/{index-DbghctxK.js → index-EN7MioVf.js} +1 -1
- package/dist/assets/{isDiffPlainText-BK9bF1l5.js → isDiffPlainText-DSWRVq-W.js} +1 -1
- package/dist/assets/{isFilePlainText-Cua0RCRz.js → isFilePlainText-7RAjjrQ5.js} +1 -1
- package/dist/assets/{main-CoA--JT-.js → main-BGKjg-qW.js} +7 -7
- package/dist/assets/main-DGHrBx_u.js +2 -0
- package/dist/assets/markdownCore-BYPqQtbE.js +3 -0
- package/dist/assets/miniChat-DW2PVX49.js +2 -0
- package/dist/assets/mobile-0Gxc02iO.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-C-qpqp1i.js +2 -0
- package/dist/assets/renderMobileApp-UB9bhC1x.js +14 -0
- package/dist/assets/{runtimeSurface-UriLeO95.js → runtimeSurface-DefD-2Iv.js} +1 -1
- package/dist/assets/{useInlineCommentController-5XANmO1k.js → useInlineCommentController-B8p2XwXA.js} +2 -2
- package/dist/assets/usePanelSlide-CbqVf-y8.js +56 -0
- package/dist/assets/usePushVisibilityBeacon-CvjN-47R.js +10 -0
- package/dist/assets/{useSwitcherItems-Cc6Tx-LO.js → useSwitcherItems-B6_F-J-z.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DxpwplIe.js → vendor-codemirror-language-data-BhBdEPsJ.js} +2 -2
- package/dist/assets/{web-components-g7DKkne_.js → web-components-C9yVPsWN.js} +4 -4
- package/dist/index.html +7 -4
- package/dist/mini-chat.html +6 -3
- package/dist/mobile.html +6 -3
- package/package.json +1 -1
- package/server/lib/git/DOCUMENTATION.md +2 -2
- package/server/lib/git/issue-2746-longpaths.test.js +11 -11
- package/server/lib/git/service.js +16 -53
- package/server/lib/git/service.test.js +40 -40
- package/server/lib/pi/extension-protocol.js +62 -0
- package/server/lib/pi/extension-protocol.test.js +34 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +251 -0
- package/server/lib/pi/routes-extension-events.test.js +152 -0
- package/server/lib/pi/routes.js +278 -5
- package/server/lib/pi/routes.test.js +0 -25
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +6 -3
- package/server/lib/pi/session-daemon/extension-bridge.js +488 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.e2e.test.js +215 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +559 -0
- package/server/lib/pi/session-daemon/session-daemon.js +304 -34
- package/server/lib/pi/session-daemon/session-daemon.test.js +89 -1
- package/server/lib/server/cors.js +0 -2
- package/server/lib/server/cors.test.js +4 -4
- package/server/lib/stt/providers/openai-compatible-provider.test.js +1 -1
- package/server/lib/workspace/host.js +1 -1
- package/dist/assets/DiagramEditor-CFV_TjE2.js +0 -1
- package/dist/assets/DiagramView-0I4PZUpw.js +0 -1
- package/dist/assets/SessionSwitcherDropdown-DuPmnk3k.js +0 -2
- package/dist/assets/SessionUnreadDot-ogHL0INY.js +0 -1
- package/dist/assets/SettingsView-SHhVrRdh.js +0 -4
- package/dist/assets/SettingsWindow-D_D1qqLF.js +0 -1
- package/dist/assets/collapsible-BO4qEdib.js +0 -1
- package/dist/assets/contextFileOpenGuard-w5xG9Qz2.js +0 -1
- package/dist/assets/index-3zee2IYy.css +0 -1
- package/dist/assets/index-CI-cd-mw.js +0 -8
- package/dist/assets/main-BNJQ6mSF.js +0 -2
- package/dist/assets/markdownCore-BGlLZrb8.js +0 -3
- package/dist/assets/miniChat-DU2jFhXq.js +0 -2
- package/dist/assets/mobile-B3lJ_CJR.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-BfXYv3zl.js +0 -2
- package/dist/assets/renderMobileApp-Cd_F7yMe.js +0 -14
- package/dist/assets/usePanelSlide-CBZw2Cjo.js +0 -56
- package/dist/assets/useWindowTitle-Bf8ZNN_R.js +0 -10
- package/server/lib/pi/legacy-ui-model-defaults.js +0 -57
- package/server/lib/pi/legacy-ui-model-defaults.test.js +0 -65
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { createHash, randomUUID } from 'node:crypto';
|
|
2
2
|
import { createServer } from 'node:net';
|
|
3
3
|
import { chmod, mkdir, lstat, readFile, readdir, rename, rm, stat, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { createReadStream } from 'node:fs';
|
|
4
|
+
import { createReadStream, existsSync, readFileSync } from 'node:fs';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { createInterface } from 'node:readline';
|
|
6
7
|
import { basename, dirname, isAbsolute, join } from 'node:path';
|
|
7
8
|
import { hasTrustRequiringProjectResources } from '@earendil-works/pi-coding-agent';
|
|
@@ -16,8 +17,14 @@ import {
|
|
|
16
17
|
SettingsManager,
|
|
17
18
|
} from '@earendil-works/pi-coding-agent';
|
|
18
19
|
|
|
20
|
+
import {
|
|
21
|
+
MAX_EXTENSION_APP_HTML_CHARS,
|
|
22
|
+
sanitizeExtensionFormFields,
|
|
23
|
+
validateExtensionFormValues,
|
|
24
|
+
} from '../extension-protocol.js';
|
|
19
25
|
import { createPiModelConfigStore } from '../model-config-store.js';
|
|
20
26
|
import { clampThinkingLevel, getSupportedThinkingLevels, isPiThinkingLevel } from '../thinking-levels.js';
|
|
27
|
+
import { createExtensionBridge } from './extension-bridge.js';
|
|
21
28
|
import { createMessageEntryAliases } from './message-entry-aliases.js';
|
|
22
29
|
import { resolveEffectiveRetryLimitFromDataDir as resolveEffectiveRetryLimit } from './session-retry-limits.js';
|
|
23
30
|
import { createSkillReadClassifier } from './skill-read-classifier.js';
|
|
@@ -32,6 +39,51 @@ import {
|
|
|
32
39
|
import { resolvePiChamberDataDir } from '../../pichamber-data-dir.js';
|
|
33
40
|
|
|
34
41
|
const PROTOCOL_VERSION = 1;
|
|
42
|
+
|
|
43
|
+
const textFromContent = (content) => (
|
|
44
|
+
Array.isArray(content)
|
|
45
|
+
? content.filter((part) => part?.type === 'text' && typeof part.text === 'string').map((part) => part.text).join('')
|
|
46
|
+
: ''
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// Marker so pi extensions can detect PiChamber without an extra dependency.
|
|
50
|
+
// Extensions should use optional detection, e.g.:
|
|
51
|
+
// const chamber = (globalThis as any).__PICHAMBER__;
|
|
52
|
+
// or `process.env.PICHAMBER === "1"`. The object is frozen and versioned.
|
|
53
|
+
if (!globalThis.__PICHAMBER__) {
|
|
54
|
+
try {
|
|
55
|
+
globalThis.__PICHAMBER__ = Object.freeze({
|
|
56
|
+
version: 1,
|
|
57
|
+
protocol: 'pichamber-extension-ui',
|
|
58
|
+
mode: 'rpc',
|
|
59
|
+
});
|
|
60
|
+
} catch {}
|
|
61
|
+
}
|
|
62
|
+
if (!process.env.PICHAMBER) {
|
|
63
|
+
try { process.env.PICHAMBER = '1'; } catch {}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Extensions that spawn the pi CLI as a child process (subagent runners,
|
|
67
|
+
// task delegators) locate it through `process.argv[1]`. Inside this detached
|
|
68
|
+
// daemon that path is daemon-process.js — a bare invocation exits 64 with no
|
|
69
|
+
// output, which the extension then reports as "failed (no output)". Re-point
|
|
70
|
+
// argv at the installed pi CLI entry before any extension loads so child
|
|
71
|
+
// spawns run the real CLI. Scoped to the detached entrypoint so tests and
|
|
72
|
+
// in-process hosts keep their own argv.
|
|
73
|
+
try {
|
|
74
|
+
if (process.argv[1]?.endsWith('daemon-process.js')) {
|
|
75
|
+
// The SDK is ESM-only, so resolve through import.meta rather than require.
|
|
76
|
+
const mainEntry = fileURLToPath(import.meta.resolve('@earendil-works/pi-coding-agent'));
|
|
77
|
+
const packageRoot = dirname(dirname(mainEntry));
|
|
78
|
+
const pkg = JSON.parse(readFileSync(join(packageRoot, 'package.json'), 'utf8'));
|
|
79
|
+
const bin = typeof pkg.bin === 'string' ? pkg.bin : pkg.bin?.pi;
|
|
80
|
+
if (bin) {
|
|
81
|
+
const cliEntry = join(packageRoot, bin);
|
|
82
|
+
if (existsSync(cliEntry)) process.argv[1] = cliEntry;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch {}
|
|
86
|
+
|
|
35
87
|
const MAX_FRAME_BYTES = 16 * 1024 * 1024;
|
|
36
88
|
|
|
37
89
|
class SessionDaemonProtocolError extends Error {
|
|
@@ -51,18 +103,18 @@ export function isLocalSessionDaemonEndpoint(endpoint, platform = process.platfo
|
|
|
51
103
|
return isAbsolute(endpoint);
|
|
52
104
|
}
|
|
53
105
|
|
|
54
|
-
|
|
106
|
+
// Hooks let the daemon thread extension bindings into every Pi runtime
|
|
107
|
+
// creation (initial, new/resume/fork replacement) without coupling this
|
|
108
|
+
// factory to daemon socket state.
|
|
109
|
+
export async function createPiSessionRuntime({ cwd, agentDir = getAgentDir(), sessionFile }, hooks) {
|
|
55
110
|
const createRuntime = async ({ cwd: runtimeCwd, agentDir: runtimeAgentDir, sessionManager, sessionStartEvent }) => {
|
|
56
111
|
const services = await createAgentSessionServices({
|
|
57
112
|
cwd: runtimeCwd,
|
|
58
113
|
agentDir: runtimeAgentDir,
|
|
59
|
-
resourceLoaderOptions: {
|
|
60
|
-
// Third-party native extensions are intentionally disabled for the Pi core milestone.
|
|
61
|
-
noExtensions: true,
|
|
62
|
-
},
|
|
114
|
+
resourceLoaderOptions: {},
|
|
63
115
|
});
|
|
64
116
|
|
|
65
|
-
|
|
117
|
+
const result = {
|
|
66
118
|
...(await createAgentSessionFromServices({
|
|
67
119
|
services,
|
|
68
120
|
sessionManager,
|
|
@@ -71,6 +123,12 @@ async function createPiSessionRuntime({ cwd, agentDir = getAgentDir(), sessionFi
|
|
|
71
123
|
services,
|
|
72
124
|
diagnostics: services.diagnostics,
|
|
73
125
|
};
|
|
126
|
+
|
|
127
|
+
if (hooks?.createExtensionBindings && typeof result.session?.bindExtensions === 'function') {
|
|
128
|
+
await result.session.bindExtensions(hooks.createExtensionBindings(result.session));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return result;
|
|
74
132
|
};
|
|
75
133
|
|
|
76
134
|
return createAgentSessionRuntime(createRuntime, {
|
|
@@ -87,7 +145,7 @@ export function createSessionDaemon({
|
|
|
87
145
|
credential,
|
|
88
146
|
cwd,
|
|
89
147
|
agentDir = getAgentDir(),
|
|
90
|
-
createRuntime
|
|
148
|
+
createRuntime: injectCreateRuntime,
|
|
91
149
|
healthMetadata = {},
|
|
92
150
|
idleTimeoutMs = 5 * 60 * 1_000,
|
|
93
151
|
listSessions = ({ cwd: sessionCwd, agentDir: sessionAgentDir = agentDir }) => listPiSessionJsonlDirectory({
|
|
@@ -145,8 +203,14 @@ export function createSessionDaemon({
|
|
|
145
203
|
const compactionStateBySession = new Map();
|
|
146
204
|
const activeRunStartedAt = new Map();
|
|
147
205
|
const sendGenerationBySession = new Map();
|
|
206
|
+
const settledSendGenerationBySession = new Map();
|
|
207
|
+
const shutdownRequestedBySession = new Set();
|
|
208
|
+
const disposingSessionIds = new Set();
|
|
148
209
|
const streamingRedactionBuffers = new Map();
|
|
149
210
|
const loginAttempts = new Map();
|
|
211
|
+
// Server-side normalized extension live state: statuses, widgets, panels,
|
|
212
|
+
// apps, and pending dialogs are kept per session so a reconnect can
|
|
213
|
+
// reconstruct the current UI without requiring the extension to re-emit.
|
|
150
214
|
const messageEntryAliases = createMessageEntryAliases();
|
|
151
215
|
const skillReadClassifierByRuntime = new WeakMap();
|
|
152
216
|
const MAX_REPLAY_EVENTS = 1_024;
|
|
@@ -249,7 +313,7 @@ export function createSessionDaemon({
|
|
|
249
313
|
const services = await createAgentSessionServices({
|
|
250
314
|
cwd: targetCwd,
|
|
251
315
|
agentDir,
|
|
252
|
-
resourceLoaderOptions: {
|
|
316
|
+
resourceLoaderOptions: {},
|
|
253
317
|
});
|
|
254
318
|
servicesCache.set(targetCwd, services);
|
|
255
319
|
return services;
|
|
@@ -274,6 +338,35 @@ export function createSessionDaemon({
|
|
|
274
338
|
for (const client of clients) writeFrame(client, message);
|
|
275
339
|
};
|
|
276
340
|
|
|
341
|
+
const extensionBridge = createExtensionBridge({
|
|
342
|
+
publish,
|
|
343
|
+
resolveDirectory,
|
|
344
|
+
redactAttachmentPaths: (value) => redactAttachmentPaths(value),
|
|
345
|
+
redactAttachmentValues: (value) => redactAttachmentValues(value),
|
|
346
|
+
findRuntimeBySessionId: (sessionId) => runtimeRegistry?.findBySessionId(sessionId)
|
|
347
|
+
|| (runtime?.session?.sessionId === sessionId ? runtime : undefined),
|
|
348
|
+
getDefaultDirectory: () => activeDirectory || cwd,
|
|
349
|
+
getSequence: () => sequence,
|
|
350
|
+
protocolError: (code, message) => new SessionDaemonProtocolError(code, message),
|
|
351
|
+
requestSessionShutdown: (sessionId) => shutdownRequestedBySession.add(sessionId),
|
|
352
|
+
});
|
|
353
|
+
const {
|
|
354
|
+
buildExtensionBindings,
|
|
355
|
+
clearExtensionState,
|
|
356
|
+
mirrorExtensionApp,
|
|
357
|
+
mirrorExtensionPanel,
|
|
358
|
+
publishExtensionCustomMessage,
|
|
359
|
+
resolveExtensionDialog,
|
|
360
|
+
} = extensionBridge;
|
|
361
|
+
|
|
362
|
+
// Thread extension hooks through our own default factory. Injected test or
|
|
363
|
+
// host factories keep their single-argument contract and ignore the hooks.
|
|
364
|
+
const baseCreateRuntime = injectCreateRuntime
|
|
365
|
+
?? ((runtimeOptions, runtimeHooks) => createPiSessionRuntime(runtimeOptions, runtimeHooks));
|
|
366
|
+
const createRuntime = (runtimeOptions) => baseCreateRuntime(runtimeOptions, {
|
|
367
|
+
createExtensionBindings: buildExtensionBindings,
|
|
368
|
+
});
|
|
369
|
+
|
|
277
370
|
const getSessionState = () => runtime
|
|
278
371
|
? { sessionId: runtime.session.sessionId, isStreaming: runtime.session.isStreaming }
|
|
279
372
|
: { sessionId: dormantSession?.sessionId, isStreaming: false };
|
|
@@ -319,6 +412,11 @@ export function createSessionDaemon({
|
|
|
319
412
|
const lastAssistant = [...messages].reverse().find((entry) => entry.message.role === 'assistant')?.message;
|
|
320
413
|
const model = activeSession?.model;
|
|
321
414
|
const snapshotSequence = ++sequence;
|
|
415
|
+
// Snapshot must carry enough extension live state for a reconnect that
|
|
416
|
+
// missed the gap: statuses, widgets, and pending blocking dialogs per
|
|
417
|
+
// session. Without it, a phone that reconnects after the 1k replay
|
|
418
|
+
// window would lose its sub-agent panel or approval prompt.
|
|
419
|
+
const extensionSnapshot = extensionBridge.getSnapshotState(session.sessionId);
|
|
322
420
|
writeFrame(socket, {
|
|
323
421
|
protocolVersion: PROTOCOL_VERSION,
|
|
324
422
|
kind: 'event',
|
|
@@ -342,6 +440,12 @@ export function createSessionDaemon({
|
|
|
342
440
|
...(session.sessionId && activeRunStartedAt.has(session.sessionId) ? { runStartedAt: activeRunStartedAt.get(session.sessionId) } : {}),
|
|
343
441
|
serverNow: Date.now(),
|
|
344
442
|
lastSequence: snapshotSequence,
|
|
443
|
+
...(extensionSnapshot.statuses ? { extensionStatuses: extensionSnapshot.statuses } : {}),
|
|
444
|
+
...(extensionSnapshot.widgets ? { extensionWidgets: extensionSnapshot.widgets } : {}),
|
|
445
|
+
...(extensionSnapshot.dialogs ? { extensionDialogs: extensionSnapshot.dialogs } : {}),
|
|
446
|
+
...(extensionSnapshot.panels ? { extensionPanels: extensionSnapshot.panels } : {}),
|
|
447
|
+
...(extensionSnapshot.apps ? { extensionApps: extensionSnapshot.apps } : {}),
|
|
448
|
+
...(extensionSnapshot.title ? { extensionTitle: extensionSnapshot.title } : {}),
|
|
345
449
|
},
|
|
346
450
|
});
|
|
347
451
|
};
|
|
@@ -361,6 +465,7 @@ export function createSessionDaemon({
|
|
|
361
465
|
|
|
362
466
|
const disposeRuntime = async () => {
|
|
363
467
|
clearIdleDisposal();
|
|
468
|
+
clearExtensionState(undefined);
|
|
364
469
|
if (runtimeRegistry) {
|
|
365
470
|
const hadTrackedRuntime = runtimeRegistry.size > 0;
|
|
366
471
|
await runtimeRegistry.disposeAll();
|
|
@@ -400,24 +505,41 @@ export function createSessionDaemon({
|
|
|
400
505
|
return runtimeStartPromise;
|
|
401
506
|
};
|
|
402
507
|
|
|
508
|
+
const disposeIdleSessionRuntime = async (sessionId) => {
|
|
509
|
+
if (disposingSessionIds.has(sessionId)) return;
|
|
510
|
+
const targetRuntime = runtimeRegistry?.findBySessionId(sessionId);
|
|
511
|
+
if (!targetRuntime) {
|
|
512
|
+
shutdownRequestedBySession.delete(sessionId);
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (targetRuntime.session?.isStreaming || targetRuntime.session?.isCompacting) return;
|
|
516
|
+
disposingSessionIds.add(sessionId);
|
|
517
|
+
clearIdleDisposal(sessionId);
|
|
518
|
+
try {
|
|
519
|
+
if (targetRuntime === runtime) rememberRuntimeSession();
|
|
520
|
+
clearExtensionState(sessionId);
|
|
521
|
+
await runtimeRegistry.dispose(targetRuntime);
|
|
522
|
+
shutdownRequestedBySession.delete(sessionId);
|
|
523
|
+
compactionStateBySession.delete(sessionId);
|
|
524
|
+
if (targetRuntime === runtime) runtime = undefined;
|
|
525
|
+
} catch {
|
|
526
|
+
publish('session.error', { code: 'RUNTIME_DISPOSAL_FAILED' }, sessionId, targetRuntime.cwd);
|
|
527
|
+
} finally {
|
|
528
|
+
disposingSessionIds.delete(sessionId);
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
const completeRequestedShutdown = (sessionId) => {
|
|
533
|
+
if (!shutdownRequestedBySession.has(sessionId)) return false;
|
|
534
|
+
void disposeIdleSessionRuntime(sessionId);
|
|
535
|
+
return true;
|
|
536
|
+
};
|
|
537
|
+
|
|
403
538
|
const scheduleIdleDisposal = (sessionId) => {
|
|
404
539
|
clearIdleDisposal(sessionId);
|
|
405
|
-
const timer = setTimeout(
|
|
540
|
+
const timer = setTimeout(() => {
|
|
406
541
|
idleDisposeTimers.delete(sessionId);
|
|
407
|
-
|
|
408
|
-
if (!targetRuntime || targetRuntime.session?.isStreaming || targetRuntime.session?.isCompacting) return;
|
|
409
|
-
try {
|
|
410
|
-
if (targetRuntime === runtime) {
|
|
411
|
-
rememberRuntimeSession();
|
|
412
|
-
}
|
|
413
|
-
await runtimeRegistry.dispose(targetRuntime);
|
|
414
|
-
compactionStateBySession.delete(sessionId);
|
|
415
|
-
if (targetRuntime === runtime) {
|
|
416
|
-
runtime = undefined;
|
|
417
|
-
}
|
|
418
|
-
} catch {
|
|
419
|
-
publish('session.error', { code: 'RUNTIME_DISPOSAL_FAILED' }, sessionId);
|
|
420
|
-
}
|
|
542
|
+
void disposeIdleSessionRuntime(sessionId);
|
|
421
543
|
}, idleTimeoutMs);
|
|
422
544
|
idleDisposeTimers.set(sessionId, timer);
|
|
423
545
|
};
|
|
@@ -732,6 +854,42 @@ export function createSessionDaemon({
|
|
|
732
854
|
}
|
|
733
855
|
let latestUserMessageId;
|
|
734
856
|
return entries.flatMap((entry) => {
|
|
857
|
+
// Extension-authored content: custom entries (`appendEntry`) and custom
|
|
858
|
+
// messages (`sendMessage`) both surface as extension-role items so the
|
|
859
|
+
// UI can render them through its extension renderer registry.
|
|
860
|
+
if (entry?.type === 'custom') {
|
|
861
|
+
if (typeof entry.customType !== 'string' || entry.customType.length === 0 || typeof entry.id !== 'string') return [];
|
|
862
|
+
const timestamp = Date.parse(entry.timestamp);
|
|
863
|
+
return [{
|
|
864
|
+
message: {
|
|
865
|
+
id: entry.id, sessionId: session.sessionId, directory: targetDir, role: 'extension',
|
|
866
|
+
customType: entry.customType,
|
|
867
|
+
createdAt: Number.isFinite(timestamp) ? timestamp : 0,
|
|
868
|
+
...(entry.data !== undefined ? { data: redactAttachmentValues(entry.data) } : {}),
|
|
869
|
+
},
|
|
870
|
+
parts: [],
|
|
871
|
+
}];
|
|
872
|
+
}
|
|
873
|
+
if (entry?.type === 'custom_message') {
|
|
874
|
+
if (typeof entry.customType !== 'string' || entry.customType.length === 0 || typeof entry.id !== 'string') return [];
|
|
875
|
+
if (entry.display === false) return [];
|
|
876
|
+
const timestamp = Date.parse(entry.timestamp);
|
|
877
|
+
const text = typeof entry.content === 'string'
|
|
878
|
+
? entry.content
|
|
879
|
+
: Array.isArray(entry.content)
|
|
880
|
+
? textFromContent(entry.content)
|
|
881
|
+
: '';
|
|
882
|
+
return [{
|
|
883
|
+
message: {
|
|
884
|
+
id: entry.id, sessionId: session.sessionId, directory: targetDir, role: 'extension',
|
|
885
|
+
customType: entry.customType,
|
|
886
|
+
text: redactAttachmentPaths(text),
|
|
887
|
+
createdAt: Number.isFinite(timestamp) ? timestamp : 0,
|
|
888
|
+
...(entry.details !== undefined ? { details: redactAttachmentValues(entry.details) } : {}),
|
|
889
|
+
},
|
|
890
|
+
parts: [],
|
|
891
|
+
}];
|
|
892
|
+
}
|
|
735
893
|
if (entry?.type !== 'message' || !entry.message || typeof entry.id !== 'string') return [];
|
|
736
894
|
const timestamp = Date.parse(entry.timestamp);
|
|
737
895
|
const createdAt = Number.isFinite(timestamp) ? timestamp : 0;
|
|
@@ -739,13 +897,13 @@ export function createSessionDaemon({
|
|
|
739
897
|
const text = redactAttachmentPaths(typeof entry.message.content === 'string'
|
|
740
898
|
? entry.message.content
|
|
741
899
|
: Array.isArray(entry.message.content)
|
|
742
|
-
? entry.message.content
|
|
900
|
+
? textFromContent(entry.message.content)
|
|
743
901
|
: '');
|
|
744
902
|
latestUserMessageId = entry.id;
|
|
745
903
|
return [{ message: { id: entry.id, sessionId: session.sessionId, directory: targetDir, role: 'user', text, createdAt }, parts: [] }];
|
|
746
904
|
}
|
|
747
905
|
if (entry.message.role !== 'assistant' || !Array.isArray(entry.message.content)) return [];
|
|
748
|
-
const text = redactAttachmentPaths(entry.message.content
|
|
906
|
+
const text = redactAttachmentPaths(textFromContent(entry.message.content));
|
|
749
907
|
const thinking = redactAttachmentPaths(entry.message.content.filter((part) => part?.type === 'thinking').map((part) => part.thinking).join(''));
|
|
750
908
|
const usage = projectUsage(entry.message.usage);
|
|
751
909
|
const parts = entry.message.content.flatMap((part, index) => {
|
|
@@ -1547,7 +1705,7 @@ export function createSessionDaemon({
|
|
|
1547
1705
|
*/
|
|
1548
1706
|
const projectToolResult = (result, isError) => {
|
|
1549
1707
|
const content = result && typeof result === 'object' && Array.isArray(result.content) ? result.content : [];
|
|
1550
|
-
const output = redactAttachmentPaths(content
|
|
1708
|
+
const output = redactAttachmentPaths(textFromContent(content));
|
|
1551
1709
|
let metadata;
|
|
1552
1710
|
if (result && typeof result === 'object' && result.details && typeof result.details === 'object') {
|
|
1553
1711
|
const details = redactAttachmentValues(result.details);
|
|
@@ -1733,9 +1891,26 @@ export function createSessionDaemon({
|
|
|
1733
1891
|
// report asynchronous failure through the existing session event channel.
|
|
1734
1892
|
const generation = (sendGenerationBySession.get(payload.sessionId) ?? 0) + 1;
|
|
1735
1893
|
sendGenerationBySession.set(payload.sessionId, generation);
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1894
|
+
// Slash-prefixed input dispatches extension commands and skill/template
|
|
1895
|
+
// expansion exactly like the pi CLI and RPC modes; plain text keeps the
|
|
1896
|
+
// sendUserMessage path so it is never expanded.
|
|
1897
|
+
const sendCall = content.startsWith('/')
|
|
1898
|
+
? activeRuntime.session.prompt(content, {
|
|
1899
|
+
source: 'rpc',
|
|
1900
|
+
...(deliverAs ? { streamingBehavior: deliverAs } : {}),
|
|
1901
|
+
})
|
|
1902
|
+
: activeRuntime.session.sendUserMessage(content, deliverAs ? { deliverAs } : undefined);
|
|
1903
|
+
Promise.resolve(sendCall).then(() => {
|
|
1904
|
+
if (sendGenerationBySession.get(payload.sessionId) !== generation) return;
|
|
1905
|
+
if (settledSendGenerationBySession.get(payload.sessionId) === generation) return;
|
|
1906
|
+
if (activeRuntime.session?.isStreaming) return;
|
|
1907
|
+
settledSendGenerationBySession.set(payload.sessionId, generation);
|
|
1908
|
+
// Extension commands can complete without starting an agent turn, so Pi
|
|
1909
|
+
// emits no agent_settled event. Close the optimistic browser lifecycle
|
|
1910
|
+
// when the command promise itself is the authoritative completion edge.
|
|
1911
|
+
publish('session.lifecycle', { state: 'idle', serverNow: Date.now() }, payload.sessionId, activeRuntime.cwd);
|
|
1912
|
+
completeRequestedShutdown(payload.sessionId);
|
|
1913
|
+
}).catch((error) => {
|
|
1739
1914
|
if (sendGenerationBySession.get(payload.sessionId) !== generation) return;
|
|
1740
1915
|
publish('session.error', {
|
|
1741
1916
|
code: 'ASSISTANT_ERROR',
|
|
@@ -1743,7 +1918,10 @@ export function createSessionDaemon({
|
|
|
1743
1918
|
? { message: redactAttachmentPaths(error.message) }
|
|
1744
1919
|
: {}),
|
|
1745
1920
|
}, payload.sessionId, activeRuntime.cwd);
|
|
1746
|
-
if (!activeRuntime.session?.isStreaming)
|
|
1921
|
+
if (!activeRuntime.session?.isStreaming) {
|
|
1922
|
+
completeRequestedShutdown(payload.sessionId);
|
|
1923
|
+
return;
|
|
1924
|
+
}
|
|
1747
1925
|
Promise.resolve(activeRuntime.session.abort()).catch(() => {});
|
|
1748
1926
|
});
|
|
1749
1927
|
return { accepted: true, messageId };
|
|
@@ -1757,6 +1935,8 @@ export function createSessionDaemon({
|
|
|
1757
1935
|
entryId: node.entry.id,
|
|
1758
1936
|
parentId: node.entry.parentId,
|
|
1759
1937
|
...(node.entry.type === 'session_info' && typeof node.entry.name === 'string' ? { title: node.entry.name } : {}),
|
|
1938
|
+
...(typeof node.label === 'string' && node.label.length > 0 ? { label: node.label.slice(0, 256) } : {}),
|
|
1939
|
+
...(typeof node.labelTimestamp === 'string' ? { labelTimestamp: node.labelTimestamp } : {}),
|
|
1760
1940
|
updatedAt: Date.parse(node.entry.timestamp) || 0,
|
|
1761
1941
|
children: node.children.map(project),
|
|
1762
1942
|
});
|
|
@@ -1783,6 +1963,9 @@ export function createSessionDaemon({
|
|
|
1783
1963
|
retryStateBySession.delete(sessionId);
|
|
1784
1964
|
compactionStateBySession.delete(sessionId);
|
|
1785
1965
|
activeRunStartedAt.delete(sessionId);
|
|
1966
|
+
shutdownRequestedBySession.delete(sessionId);
|
|
1967
|
+
sendGenerationBySession.delete(sessionId);
|
|
1968
|
+
settledSendGenerationBySession.delete(sessionId);
|
|
1786
1969
|
latestUserMessageIds.delete(sessionId);
|
|
1787
1970
|
latestAssistantMessageIds.delete(sessionId);
|
|
1788
1971
|
toolInputBySession.delete(sessionId);
|
|
@@ -1797,7 +1980,7 @@ export function createSessionDaemon({
|
|
|
1797
1980
|
const text = redactAttachmentPaths(typeof content === 'string'
|
|
1798
1981
|
? content
|
|
1799
1982
|
: Array.isArray(content)
|
|
1800
|
-
? content
|
|
1983
|
+
? textFromContent(content)
|
|
1801
1984
|
: '');
|
|
1802
1985
|
const messageId = `user-${sessionId}-${sequence + 1}`;
|
|
1803
1986
|
messageEntryAliases.retain({ cwd: directory, sessionId, syntheticMessageId: messageId, message: event.message });
|
|
@@ -1861,7 +2044,7 @@ export function createSessionDaemon({
|
|
|
1861
2044
|
const usage = projectUsage(event.message.usage);
|
|
1862
2045
|
publish('assistant.message.end', {
|
|
1863
2046
|
messageId,
|
|
1864
|
-
text: redactAttachmentPaths(content
|
|
2047
|
+
text: redactAttachmentPaths(textFromContent(content)),
|
|
1865
2048
|
thinking: redactAttachmentPaths(content.filter((part) => part?.type === 'thinking').map((part) => part.thinking).join('')),
|
|
1866
2049
|
durationMs,
|
|
1867
2050
|
...(content.some((part) => part?.type === 'toolCall') ? { continuing: true } : {}),
|
|
@@ -1870,6 +2053,34 @@ export function createSessionDaemon({
|
|
|
1870
2053
|
}, sessionId, directory);
|
|
1871
2054
|
streamingMessageIds.delete(sessionId);
|
|
1872
2055
|
clearStreamingRedactionBuffers(sessionId);
|
|
2056
|
+
} else if (event.message?.role === 'custom') {
|
|
2057
|
+
publishExtensionCustomMessage(sessionId, event.message, directory);
|
|
2058
|
+
}
|
|
2059
|
+
break;
|
|
2060
|
+
}
|
|
2061
|
+
case 'entry_appended': {
|
|
2062
|
+
const entry = event.entry;
|
|
2063
|
+
if (entry?.type !== 'custom' || typeof entry.customType !== 'string') break;
|
|
2064
|
+
const timestamp = Date.parse(entry.timestamp);
|
|
2065
|
+
publish('extension.entry', {
|
|
2066
|
+
id: typeof entry.id === 'string' ? entry.id : `ext-${sessionId}-${sequence + 1}`,
|
|
2067
|
+
customType: entry.customType,
|
|
2068
|
+
...(entry.data !== undefined ? { data: redactAttachmentValues(entry.data) } : {}),
|
|
2069
|
+
createdAt: Number.isFinite(timestamp) ? timestamp : Date.now(),
|
|
2070
|
+
}, sessionId, directory);
|
|
2071
|
+
// Declarative GUI payloads are additionally mirrored into normalized
|
|
2072
|
+
// live state so panels/apps update in place and survive reconnects.
|
|
2073
|
+
if (entry.customType === 'pichamber.ui' || entry.customType.startsWith('pichamber.')) {
|
|
2074
|
+
const descriptor = entry.data && typeof entry.data === 'object' && !Array.isArray(entry.data)
|
|
2075
|
+
? (entry.data.ui && typeof entry.data.ui === 'object' && !Array.isArray(entry.data.ui) ? entry.data.ui : entry.data)
|
|
2076
|
+
: undefined;
|
|
2077
|
+
if (descriptor) {
|
|
2078
|
+
if (entry.customType === 'pichamber.app') {
|
|
2079
|
+
mirrorExtensionApp(sessionId, descriptor, directory);
|
|
2080
|
+
} else {
|
|
2081
|
+
mirrorExtensionPanel(sessionId, descriptor, directory);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
1873
2084
|
}
|
|
1874
2085
|
break;
|
|
1875
2086
|
}
|
|
@@ -1971,11 +2182,24 @@ export function createSessionDaemon({
|
|
|
1971
2182
|
case 'agent_settled':
|
|
1972
2183
|
retryStateBySession.delete(sessionId);
|
|
1973
2184
|
activeRunStartedAt.delete(sessionId);
|
|
2185
|
+
settledSendGenerationBySession.set(sessionId, sendGenerationBySession.get(sessionId) ?? 0);
|
|
1974
2186
|
latestUserMessageIds.delete(sessionId);
|
|
1975
2187
|
latestAssistantMessageIds.delete(sessionId);
|
|
1976
2188
|
toolInputBySession.delete(sessionId);
|
|
1977
2189
|
publish('session.lifecycle', { state: 'idle', serverNow: Date.now() }, sessionId, directory);
|
|
1978
|
-
scheduleIdleDisposal(sessionId);
|
|
2190
|
+
if (!completeRequestedShutdown(sessionId)) scheduleIdleDisposal(sessionId);
|
|
2191
|
+
break;
|
|
2192
|
+
case 'session_info_changed': {
|
|
2193
|
+
const title = typeof event.name === 'string' ? event.name.trim() : '';
|
|
2194
|
+
if (title) publish('session.updated', { title: redactAttachmentPaths(title).slice(0, 256) }, sessionId, directory);
|
|
2195
|
+
break;
|
|
2196
|
+
}
|
|
2197
|
+
case 'model_select':
|
|
2198
|
+
if (event.model?.provider && event.model?.id) {
|
|
2199
|
+
publish('session.model', {
|
|
2200
|
+
model: { providerId: event.model.provider, modelId: event.model.id },
|
|
2201
|
+
}, sessionId, directory);
|
|
2202
|
+
}
|
|
1979
2203
|
break;
|
|
1980
2204
|
case 'thinking_level_changed':
|
|
1981
2205
|
publish('session.thinking', { thinking: event.level }, sessionId, directory);
|
|
@@ -2060,6 +2284,7 @@ export function createSessionDaemon({
|
|
|
2060
2284
|
'sessions.setThinking', 'sessions.compact', 'providers.list', 'providers.refresh', 'providers.config.get', 'providers.models.set', 'providers.status', 'providers.login',
|
|
2061
2285
|
'providers.login.respond', 'providers.login.status', 'providers.logout', 'settings.get', 'settings.set',
|
|
2062
2286
|
'resources.list', 'resources.update', 'resources.prompts.create', 'resources.prompts.delete',
|
|
2287
|
+
'extensions.list', 'extensions.respond',
|
|
2063
2288
|
],
|
|
2064
2289
|
...(Number.isInteger(healthMetadata.daemonPid) ? { daemonPid: healthMetadata.daemonPid } : {}),
|
|
2065
2290
|
},
|
|
@@ -2163,6 +2388,47 @@ export function createSessionDaemon({
|
|
|
2163
2388
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
2164
2389
|
return;
|
|
2165
2390
|
}
|
|
2391
|
+
case 'extensions.respond': {
|
|
2392
|
+
const resolution = await resolveExtensionDialog(message.payload);
|
|
2393
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: resolution });
|
|
2394
|
+
return;
|
|
2395
|
+
}
|
|
2396
|
+
case 'extensions.list': {
|
|
2397
|
+
const requestedExtensionsDir = message.payload?.directory || message.payload?.cwd;
|
|
2398
|
+
const activeRuntime = await ensureRuntime(requestedExtensionsDir ? await resolveDirectory(requestedExtensionsDir) : undefined);
|
|
2399
|
+
const extensionSession = activeRuntime.session;
|
|
2400
|
+
const extensionPaths = typeof extensionSession?.extensionRunner?.getExtensionPaths === 'function'
|
|
2401
|
+
? extensionSession.extensionRunner.getExtensionPaths()
|
|
2402
|
+
: [];
|
|
2403
|
+
const registeredCommands = typeof extensionSession?.extensionRunner?.getRegisteredCommands === 'function'
|
|
2404
|
+
? extensionSession.extensionRunner.getRegisteredCommands()
|
|
2405
|
+
: [];
|
|
2406
|
+
writeFrame(socket, {
|
|
2407
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
2408
|
+
kind: 'response',
|
|
2409
|
+
requestId: message.requestId,
|
|
2410
|
+
result: {
|
|
2411
|
+
directory: activeRuntime.cwd,
|
|
2412
|
+
extensions: (Array.isArray(extensionPaths) ? extensionPaths : [])
|
|
2413
|
+
.filter((extensionPath) => typeof extensionPath === 'string' && extensionPath.length > 0)
|
|
2414
|
+
// Opaque id only: server filesystem paths must never reach the
|
|
2415
|
+
// browser (see DOCUMENTATION.md route invariants).
|
|
2416
|
+
.map((extensionPath) => ({
|
|
2417
|
+
id: createHash('sha256').update(extensionPath).digest('hex').slice(0, 16),
|
|
2418
|
+
name: basename(extensionPath).replace(/\.(ts|js)$/, ''),
|
|
2419
|
+
})),
|
|
2420
|
+
commands: (Array.isArray(registeredCommands) ? registeredCommands : [])
|
|
2421
|
+
.filter((command) => command && typeof command.invocationName === 'string')
|
|
2422
|
+
.map((command) => ({
|
|
2423
|
+
name: command.invocationName,
|
|
2424
|
+
...(typeof command.description === 'string' ? { description: command.description } : {}),
|
|
2425
|
+
source: 'extension',
|
|
2426
|
+
...(typeof command.sourceInfo?.scope === 'string' ? { scope: command.sourceInfo.scope } : {}),
|
|
2427
|
+
})),
|
|
2428
|
+
},
|
|
2429
|
+
});
|
|
2430
|
+
return;
|
|
2431
|
+
}
|
|
2166
2432
|
case 'sessions.list': {
|
|
2167
2433
|
const sessions = await listSessionItems(message.payload?.directory || message.payload?.cwd);
|
|
2168
2434
|
writeFrame(socket, {
|
|
@@ -2435,6 +2701,10 @@ export function createSessionDaemon({
|
|
|
2435
2701
|
retryStateBySession.clear();
|
|
2436
2702
|
compactionStateBySession.clear();
|
|
2437
2703
|
activeRunStartedAt.clear();
|
|
2704
|
+
shutdownRequestedBySession.clear();
|
|
2705
|
+
disposingSessionIds.clear();
|
|
2706
|
+
sendGenerationBySession.clear();
|
|
2707
|
+
settledSendGenerationBySession.clear();
|
|
2438
2708
|
latestUserMessageIds.clear();
|
|
2439
2709
|
latestAssistantMessageIds.clear();
|
|
2440
2710
|
for (const client of clients) client.destroy();
|
|
@@ -986,7 +986,18 @@ describe('Pi session daemon spike', () => {
|
|
|
986
986
|
],
|
|
987
987
|
}],
|
|
988
988
|
});
|
|
989
|
-
|
|
989
|
+
runtime.session.sessionManager.getTree = () => [{
|
|
990
|
+
entry: { id: 'fake-entry', parentId: undefined, timestamp: '2026-01-01T00:00:00.000Z' },
|
|
991
|
+
label: 'checkpoint',
|
|
992
|
+
labelTimestamp: '2026-01-01T00:00:04.000Z',
|
|
993
|
+
children: [],
|
|
994
|
+
}];
|
|
995
|
+
await expect(client.request('sessions.tree', { sessionId: 'pi-session-persisted' })).resolves.toMatchObject({
|
|
996
|
+
result: {
|
|
997
|
+
rootId: 'pi-session-persisted',
|
|
998
|
+
nodes: [{ entryId: 'fake-entry', label: 'checkpoint', labelTimestamp: '2026-01-01T00:00:04.000Z' }],
|
|
999
|
+
},
|
|
1000
|
+
});
|
|
990
1001
|
await expect(client.request('sessions.navigate', { sessionId: 'pi-session-persisted', messageId: 'fake-entry' })).resolves.toMatchObject({ result: { session: { id: 'pi-session-persisted' } } });
|
|
991
1002
|
await expect(client.request('sessions.fork', { sessionId: 'pi-session-persisted', messageId: 'fake-entry' })).resolves.toMatchObject({ result: { session: { id: 'pi-session-forked' } } });
|
|
992
1003
|
await expect(client.request('sessions.clone', { sessionId: 'pi-session-forked' })).resolves.toMatchObject({ result: { session: { id: 'pi-session-forked' } } });
|
|
@@ -1389,6 +1400,52 @@ describe('Pi session daemon spike', () => {
|
|
|
1389
1400
|
await client.close();
|
|
1390
1401
|
});
|
|
1391
1402
|
|
|
1403
|
+
it('publishes extension-authored session names through the catalog event', async () => {
|
|
1404
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-session-name-'));
|
|
1405
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1406
|
+
const session = new FakeSession('pi-session-name');
|
|
1407
|
+
daemon = createSessionDaemon({ endpoint, credential, cwd: root, createRuntime: async () => ({ session, async dispose() {} }) });
|
|
1408
|
+
await daemon.start();
|
|
1409
|
+
const client = connectClient(endpoint);
|
|
1410
|
+
await client.authenticate();
|
|
1411
|
+
await client.request('sessions.create', { cwd: root });
|
|
1412
|
+
|
|
1413
|
+
const updated = client.next((frame) => frame.event === 'session.updated');
|
|
1414
|
+
session.emit({ type: 'session_info_changed', name: 'Extension title' });
|
|
1415
|
+
await expect(updated).resolves.toMatchObject({
|
|
1416
|
+
payload: { sessionId: 'pi-session-name', directory: root, title: 'Extension title' },
|
|
1417
|
+
});
|
|
1418
|
+
await client.close();
|
|
1419
|
+
});
|
|
1420
|
+
|
|
1421
|
+
it('publishes model selections made through the Pi session event stream', async () => {
|
|
1422
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-model-select-'));
|
|
1423
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1424
|
+
const session = new FakeSession('pi-session-model-select');
|
|
1425
|
+
daemon = createSessionDaemon({ endpoint, credential, cwd: root, createRuntime: async () => ({ session, async dispose() {} }) });
|
|
1426
|
+
await daemon.start();
|
|
1427
|
+
const client = connectClient(endpoint);
|
|
1428
|
+
await client.authenticate();
|
|
1429
|
+
await client.request('sessions.create', { cwd: root });
|
|
1430
|
+
|
|
1431
|
+
const selected = client.next((frame) => frame.event === 'session.model');
|
|
1432
|
+
session.emit({
|
|
1433
|
+
type: 'model_select',
|
|
1434
|
+
model: { provider: 'moonshot', id: 'kimi-k2' },
|
|
1435
|
+
previousModel: { provider: 'openai', id: 'gpt-5' },
|
|
1436
|
+
source: 'extension',
|
|
1437
|
+
});
|
|
1438
|
+
|
|
1439
|
+
await expect(selected).resolves.toMatchObject({
|
|
1440
|
+
payload: {
|
|
1441
|
+
sessionId: 'pi-session-model-select',
|
|
1442
|
+
directory: root,
|
|
1443
|
+
model: { providerId: 'moonshot', modelId: 'kimi-k2' },
|
|
1444
|
+
},
|
|
1445
|
+
});
|
|
1446
|
+
await client.close();
|
|
1447
|
+
});
|
|
1448
|
+
|
|
1392
1449
|
it('keeps retry attempts attached to the original user turn until Pi settles', async () => {
|
|
1393
1450
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-retry-'));
|
|
1394
1451
|
const endpoint = testDaemonEndpoint(root);
|
|
@@ -1650,6 +1707,37 @@ describe('Pi session daemon spike', () => {
|
|
|
1650
1707
|
await client.close();
|
|
1651
1708
|
});
|
|
1652
1709
|
|
|
1710
|
+
it('settles an extension command that completes without starting an agent turn', async () => {
|
|
1711
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-command-settle-'));
|
|
1712
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1713
|
+
const sessionFile = join(root, 'session-1.jsonl');
|
|
1714
|
+
await writeFile(sessionFile, `{"type":"session","id":"session-1","cwd":"${root}"}\n`);
|
|
1715
|
+
const session = new FakeSession('session-1', sessionFile);
|
|
1716
|
+
daemon = createSessionDaemon({
|
|
1717
|
+
endpoint,
|
|
1718
|
+
credential,
|
|
1719
|
+
cwd: root,
|
|
1720
|
+
createRuntime: async () => new FakeRuntime({ cwd: root, session }),
|
|
1721
|
+
listSessions: async () => [
|
|
1722
|
+
{ path: sessionFile, id: 'session-1', cwd: root, created: new Date(), modified: new Date(), messageCount: 0 },
|
|
1723
|
+
],
|
|
1724
|
+
});
|
|
1725
|
+
await daemon.start();
|
|
1726
|
+
const client = connectClient(endpoint);
|
|
1727
|
+
await client.authenticate();
|
|
1728
|
+
|
|
1729
|
+
const settled = client.next((frame) => frame.event === 'session.lifecycle' && frame.payload.state === 'idle');
|
|
1730
|
+
await expect(client.request('sessions.prompt', {
|
|
1731
|
+
sessionId: 'session-1',
|
|
1732
|
+
text: '/balance',
|
|
1733
|
+
})).resolves.toMatchObject({ result: { accepted: true } });
|
|
1734
|
+
|
|
1735
|
+
await expect(settled).resolves.toMatchObject({
|
|
1736
|
+
payload: { sessionId: 'session-1', directory: root, state: 'idle' },
|
|
1737
|
+
});
|
|
1738
|
+
await client.close();
|
|
1739
|
+
});
|
|
1740
|
+
|
|
1653
1741
|
it('acknowledges a prompt without waiting for the agent turn to finish', async () => {
|
|
1654
1742
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-prompt-ack-'));
|
|
1655
1743
|
const endpoint = testDaemonEndpoint(root);
|
|
@@ -9,7 +9,6 @@ const ALLOWED_CORS_HEADER_NAMES = new Set([
|
|
|
9
9
|
'authorization',
|
|
10
10
|
'cache-control',
|
|
11
11
|
'content-type',
|
|
12
|
-
'x-opencode-directory',
|
|
13
12
|
'x-pichamber-directory',
|
|
14
13
|
'x-requested-with',
|
|
15
14
|
]);
|
|
@@ -20,7 +19,6 @@ const DEFAULT_ALLOWED_CORS_HEADERS = [
|
|
|
20
19
|
'Accept',
|
|
21
20
|
'X-Requested-With',
|
|
22
21
|
'Cache-Control',
|
|
23
|
-
'x-opencode-directory',
|
|
24
22
|
'x-pichamber-directory',
|
|
25
23
|
].join(',');
|
|
26
24
|
|