@pi-chamber/web 1.0.8-rc.1 → 1.0.8-rc.2
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/{AgentsSurface-BmHImX8m.js → AgentsSurface-CcWBqAWV.js} +1 -1
- package/dist/assets/{ChoicesArtifact-C71fGOm2.js → ChoicesArtifact-Kk-qvrSB.js} +1 -1
- package/dist/assets/{DiagramView-BZQxoiZu.js → DiagramView-DZUBo1uP.js} +1 -1
- package/dist/assets/{DiffView-C70pbgk-.js → DiffView-CiZy4jFA.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-Cu8c3gBV.js → FileSaveConflictDialog-DZ9NDwOO.js} +1 -1
- package/dist/assets/{FilesView-nFJYEdRw.js → FilesView-DqiZ9kw9.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-Jvv_tgbl.js → GitHubDetailScaffold-DM2DH7o8.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-BXD2ODRi.js → GitHubLinkPicker-ChB8NZ1h.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-BWI706F0.js → GitHubListPrimitives-CibDiJGq.js} +1 -1
- package/dist/assets/{GitView-MIDG5RYW.js → GitView--EaZQrBr.js} +5 -5
- package/dist/assets/{IssuesSurface-uNlozeu0.js → IssuesSurface-CySTpaD1.js} +3 -3
- package/dist/assets/{JsonTreeView-CSLsTriz.js → JsonTreeView-_yMHKKQZ.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cs-7BfWi.js → MarkdownRendererImpl-D_-2fQw0.js} +1 -1
- package/dist/assets/{PatchDiff-axbsnbTJ.js → PatchDiff-bHObDlhD.js} +1 -1
- package/dist/assets/{PierreDiffViewer-lwn6w_5w.js → PierreDiffViewer-UY7Cse-s.js} +1 -1
- package/dist/assets/{PullRequestsSurface-o_AXDjbO.js → PullRequestsSurface-iXy6chwc.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-C4CMlcbv.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DCBVuCoo.js → SessionSwitcherDropdown-CDOX-5Y2.js} +2 -2
- package/dist/assets/{SessionUnreadDot-DyeIrsro.js → SessionUnreadDot-Dwc3MdvA.js} +1 -1
- package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
- package/dist/assets/{SettingsWindow-Cb4st5y5.js → SettingsWindow-CUg49Mfh.js} +1 -1
- package/dist/assets/{SubagentsArtifact-BzeMEoFP.js → SubagentsArtifact-DUZX9tDe.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BP2mOWdV.js → ToolOutputDialog-BuZZaRw4.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-D49XBR9b.js → ToolPartDiffPreview-CKncG6i2.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CLgDONEQ.js → VirtualizedFileDiff-BGZiLPe_.js} +1 -1
- package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
- package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
- package/dist/assets/{collapsible-BeyKtQGB.js → collapsible-Bro9KrfM.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DmO6H8u6.js → computeVirtualFileMetrics-DJQqK49u.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DOK251YW.js → contextFileOpenGuard-ByWK3Sru.js} +1 -1
- package/dist/assets/{fileTreeStatus-CnzR7kxA.js → fileTreeStatus-CyJ3TOYD.js} +1 -1
- package/dist/assets/{gitStatusPredicates-4kPg2t6j.js → gitStatusPredicates-BsXrwngT.js} +1 -1
- package/dist/assets/{githubLink-QvaLfNNT.js → githubLink-g2bmC0qi.js} +1 -1
- package/dist/assets/index-B_L9GVYw.css +1 -0
- package/dist/assets/{index-DMX9wT1Z.js → index-C9rUUQ_Y.js} +1 -1
- package/dist/assets/index-CKKWVoND.js +11 -0
- package/dist/assets/{main-BW9J3Y72.js → main-DT-4_fhe.js} +2 -2
- package/dist/assets/{main-BirYxac2.js → main-DsLMU9CT.js} +4 -4
- package/dist/assets/{markdownCore-CxmcPur8.js → markdownCore-QmM_aOnZ.js} +1 -1
- package/dist/assets/{miniChat-BRB11eEs.js → miniChat-BqGslD2z.js} +2 -2
- package/dist/assets/{mobile-DJZYYCuB.js → mobile-C5JOcDIC.js} +2 -2
- package/dist/assets/{nativeFileSave-B6QpoPRn.js → nativeFileSave-DSMsJqXM.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-PWoh3LNA.js → pi-session-focus-preference-Cc_S4zi1.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-C48T6YFJ.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-N-BQdJl0.js → renderElectronMiniChatApp-CiSkecEE.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-8Kt2MyTN.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
- package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
- package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
- package/dist/assets/{runtimeSurface-kIEoYsPP.js → runtimeSurface-0K7vuUpd.js} +1 -1
- package/dist/assets/{selection-BTEdLRVK.js → selection-CnYkEsu_.js} +1 -1
- package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
- package/dist/assets/{useGitHubRemoteSearch-DIBHNu8r.js → useGitHubRemoteSearch-CgP-zEBj.js} +1 -1
- package/dist/assets/{useSwitcherItems-DfLbfX37.js → useSwitcherItems-C8G5F0hs.js} +1 -1
- package/dist/assets/{web-components-C_DsTJis.js → web-components-BpncHjnV.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/plugins/featured.json +12 -0
- package/plugins/subagents/package.json +1 -1
- package/plugins/visuals/extension.js +7 -4
- package/plugins/visuals/package.json +1 -1
- package/server/index.js +86 -27
- package/server/lib/git/DOCUMENTATION.md +4 -0
- package/server/lib/git/service.js +70 -5
- package/server/lib/git/service.test.js +179 -0
- package/server/lib/github/DOCUMENTATION.md +2 -0
- package/server/lib/marketplace/DOCUMENTATION.md +95 -0
- package/server/lib/marketplace/featured.js +176 -0
- package/server/lib/marketplace/featured.test.js +207 -0
- package/server/lib/marketplace/npm-registry.js +255 -0
- package/server/lib/marketplace/npm-registry.test.js +227 -0
- package/server/lib/marketplace/routes.js +64 -0
- package/server/lib/marketplace/routes.test.js +119 -0
- package/server/lib/marketplace/service.js +225 -0
- package/server/lib/marketplace/service.test.js +174 -0
- package/server/lib/notifications/DOCUMENTATION.md +10 -4
- package/server/lib/notifications/pi-notification-watcher.js +92 -33
- package/server/lib/notifications/pi-notification-watcher.test.js +79 -0
- package/server/lib/open-url/DOCUMENTATION.md +1 -0
- package/server/lib/pi/merged-event-stream.js +316 -0
- package/server/lib/pi/merged-event-stream.test.js +95 -0
- package/server/lib/pi/routes-daemon-pool.test.js +348 -0
- package/server/lib/pi/routes-merged-events.test.js +327 -0
- package/server/lib/pi/routes-sandbox.test.js +1684 -0
- package/server/lib/pi/routes.js +491 -90
- package/server/lib/pi/routes.test.js +87 -2
- package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
- package/server/lib/pi/sandbox/launcher.js +122 -0
- package/server/lib/pi/sandbox/launcher.test.js +91 -0
- package/server/lib/pi/sandbox/nono-launcher.js +455 -0
- package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
- package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
- package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
- package/server/lib/pi/sandbox/nono-profile.json +22 -0
- package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
- package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
- package/server/lib/pi/sandbox/project-sandbox.js +207 -0
- package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
- package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
- package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
- package/server/lib/pi/sandbox/trust-ask.js +135 -0
- package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
- package/server/lib/pi/sandbox/worktree-ids.js +96 -0
- package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +26 -6
- package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
- package/server/lib/pi/session-daemon/daemon-process.js +10 -1
- package/server/lib/pi/session-daemon/extension-config.js +206 -23
- package/server/lib/pi/session-daemon/extension-config.test.js +180 -0
- package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
- package/server/lib/pi/session-daemon/session-daemon.js +368 -56
- package/server/lib/pi/session-daemon/session-daemon.test.js +227 -0
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
- package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
- package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
- package/server/lib/pi/session-daemon/session-lease.js +93 -15
- package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
- package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
- package/server/lib/pi/session-daemon/supervisor.js +386 -35
- package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
- package/server/lib/pi/ui-settings-store.js +88 -2
- package/server/lib/pi/ui-settings-store.test.js +118 -0
- package/server/lib/plugins/DOCUMENTATION.md +17 -5
- package/server/lib/plugins/daemon-sync.js +16 -6
- package/server/lib/plugins/daemon-sync.test.js +12 -0
- package/server/lib/plugins/impact.test.js +2 -1
- package/server/lib/plugins/manifest.js +25 -0
- package/server/lib/plugins/manifest.test.js +9 -0
- package/server/lib/plugins/routes.test.js +28 -0
- package/server/lib/plugins/service.js +24 -2
- package/server/lib/server/cross-process-lock.js +28 -3
- package/dist/assets/SettingsView-BHBpt2Um.js +0 -7
- package/dist/assets/VisualFrame-CJrAvWSo.js +0 -22
- package/dist/assets/VisualsArtifact-DqLGgU-Q.js +0 -1
- package/dist/assets/index-B2v0_mez.js +0 -11
- package/dist/assets/index-D3F4JrPN.css +0 -1
- package/dist/assets/renderMobileApp-B7cT7m5b.js +0 -11
- package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +0 -62
- package/dist/assets/useAppFontEffects-EcTZ_I_I.js +0 -225
|
@@ -5,7 +5,7 @@ import { createReadStream, existsSync, readFileSync } from 'node:fs';
|
|
|
5
5
|
import { homedir } from 'node:os';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { createInterface } from 'node:readline';
|
|
8
|
-
import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
8
|
+
import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
9
9
|
import { hasTrustRequiringProjectResources } from '@earendil-works/pi-coding-agent';
|
|
10
10
|
import { StringDecoder } from 'node:string_decoder';
|
|
11
11
|
import {
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
createAgentSessionRuntime,
|
|
14
14
|
createAgentSessionServices,
|
|
15
15
|
getAgentDir,
|
|
16
|
+
parseSessionEntries,
|
|
16
17
|
ProjectTrustStore,
|
|
17
18
|
SessionManager,
|
|
18
19
|
SettingsManager,
|
|
@@ -75,6 +76,7 @@ import {
|
|
|
75
76
|
validatePiSessionJsonlFile,
|
|
76
77
|
} from './session-jsonl.js';
|
|
77
78
|
import { resolvePiChamberDataDir } from '../../pichamber-data-dir.js';
|
|
79
|
+
import { createTrustAskReader } from '../sandbox/trust-ask.js';
|
|
78
80
|
import {
|
|
79
81
|
createSessionEngineRegistry,
|
|
80
82
|
logSessionEngineError,
|
|
@@ -211,6 +213,12 @@ export function createSessionDaemon({
|
|
|
211
213
|
credential,
|
|
212
214
|
cwd,
|
|
213
215
|
agentDir = getAgentDir(),
|
|
216
|
+
// Session leases key on the real Pi agent folder. A sandbox daemon runs on
|
|
217
|
+
// a shadow agent folder, so it passes the real one here; leases then match
|
|
218
|
+
// the main daemon's for the same session.
|
|
219
|
+
leaseAgentDir = agentDir,
|
|
220
|
+
// A sandbox daemon's own lease folder (session-lease.js); unset otherwise.
|
|
221
|
+
leaseScope,
|
|
214
222
|
createRuntime: injectCreateRuntime,
|
|
215
223
|
createServices: injectCreateServices = createAgentSessionServices,
|
|
216
224
|
healthMetadata = {},
|
|
@@ -240,6 +248,12 @@ export function createSessionDaemon({
|
|
|
240
248
|
{ projectTrusted },
|
|
241
249
|
),
|
|
242
250
|
createTrustStore = (settingsAgentDir = agentDir) => new ProjectTrustStore(settingsAgentDir),
|
|
251
|
+
// Folders whose trust a server reset to "ask" when their sandbox was
|
|
252
|
+
// turned off (../sandbox/trust-ask.js): never trusted automatically.
|
|
253
|
+
isTrustAskDirectory = createTrustAskReader({ dataDir: resolvePiChamberDataDir() }),
|
|
254
|
+
// Folders a sandbox daemon owns (../sandbox/sandboxed-folders.js). Only
|
|
255
|
+
// the main daemon is given the check: it never starts a runtime in one.
|
|
256
|
+
isSandboxedDirectory = () => false,
|
|
243
257
|
modelConfigStore = createPiModelConfigStore({ file: join(agentDir, 'models.json') }),
|
|
244
258
|
renamePersistedSession = ({ sessionFile, title, cwd: sessionCwd = cwd, agentDir: sessionAgentDir = agentDir }) => {
|
|
245
259
|
const manager = SessionManager.open(sessionFile, getPiSessionDirectory({ cwd: sessionCwd, agentDir: sessionAgentDir }), sessionCwd);
|
|
@@ -302,27 +316,60 @@ export function createSessionDaemon({
|
|
|
302
316
|
// Exclusive cross-daemon ownership of one resident session. The session
|
|
303
317
|
// stays visible in listings; contention reports SESSION_IN_USE instead of
|
|
304
318
|
// pretending the session is absent or idle.
|
|
305
|
-
|
|
319
|
+
// Lease changes for one session run one at a time, so the retry of a
|
|
320
|
+
// failed release (`sessions.release`) cannot remove a lease that an
|
|
321
|
+
// activation of the same session took in the meantime.
|
|
322
|
+
const leaseChains = new Map();
|
|
323
|
+
const withSessionLease = (sessionId, work) => {
|
|
324
|
+
const run = (leaseChains.get(sessionId) ?? Promise.resolve()).then(work);
|
|
325
|
+
const tail = run.catch(() => {});
|
|
326
|
+
leaseChains.set(sessionId, tail);
|
|
327
|
+
void tail.then(() => {
|
|
328
|
+
if (leaseChains.get(sessionId) === tail) leaseChains.delete(sessionId);
|
|
329
|
+
});
|
|
330
|
+
return run;
|
|
331
|
+
};
|
|
332
|
+
const acquireResidentLease = ({ cwd: leaseCwd, sessionId }) => {
|
|
306
333
|
const owner = leaseOwner();
|
|
307
|
-
if (!owner || typeof sessionId !== 'string' || sessionId.length === 0) return;
|
|
334
|
+
if (!owner || typeof sessionId !== 'string' || sessionId.length === 0) return Promise.resolve();
|
|
335
|
+
return withSessionLease(sessionId, () => acquireLeaseNow({ owner, leaseCwd, sessionId }));
|
|
336
|
+
};
|
|
337
|
+
const acquireLeaseNow = async ({ owner, leaseCwd, sessionId }) => {
|
|
308
338
|
let result;
|
|
309
339
|
try {
|
|
310
|
-
result = await acquireSessionLease({ agentDir, cwd: leaseCwd, sessionId, owner });
|
|
340
|
+
result = await acquireSessionLease({ agentDir: leaseAgentDir, cwd: leaseCwd, sessionId, owner, scope: leaseScope });
|
|
311
341
|
} catch (error) {
|
|
312
342
|
throw new SessionDaemonProtocolError('SESSION_LEASE_UNAVAILABLE', 'The session ownership check is temporarily unavailable.');
|
|
313
343
|
}
|
|
314
344
|
if (!result.acquired) {
|
|
315
345
|
throw new SessionDaemonProtocolError('SESSION_IN_USE', 'Another PiChamber instance is currently using this session.');
|
|
316
346
|
}
|
|
347
|
+
unreleasedLeases.delete(sessionId);
|
|
317
348
|
};
|
|
318
|
-
|
|
349
|
+
// Leases this daemon still holds for sessions it no longer runs, because
|
|
350
|
+
// releasing them failed. While this daemon lives, such a lease keeps every
|
|
351
|
+
// other daemon out of the session, so `sessions.release` retries it and
|
|
352
|
+
// reports the session as pending until it is gone.
|
|
353
|
+
const unreleasedLeases = new Map();
|
|
354
|
+
// `onlyUnreleased` is the retry: it does nothing (`skipped`) when the
|
|
355
|
+
// lease is no longer one left over from a failed release.
|
|
356
|
+
const releaseResidentLease = ({ cwd: leaseCwd, sessionId }, { onlyUnreleased = false } = {}) => {
|
|
319
357
|
const owner = leaseOwner();
|
|
320
|
-
if (!owner || typeof sessionId !== 'string' || sessionId.length === 0) return { released: false };
|
|
358
|
+
if (!owner || typeof sessionId !== 'string' || sessionId.length === 0) return Promise.resolve({ released: false });
|
|
359
|
+
return withSessionLease(sessionId, () => {
|
|
360
|
+
if (onlyUnreleased && !unreleasedLeases.has(sessionId)) return { released: false, skipped: true };
|
|
361
|
+
return releaseLeaseNow({ owner, leaseCwd, sessionId });
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
const releaseLeaseNow = async ({ owner, leaseCwd, sessionId }) => {
|
|
321
365
|
try {
|
|
322
|
-
|
|
366
|
+
const result = await releaseSessionLease({ agentDir: leaseAgentDir, cwd: leaseCwd, sessionId, owner, scope: leaseScope });
|
|
367
|
+
unreleasedLeases.delete(sessionId);
|
|
368
|
+
return result;
|
|
323
369
|
} catch {
|
|
324
370
|
// Lease release is best-effort; a stale lease is reclaimable by the
|
|
325
371
|
// next owner once this daemon pid is dead.
|
|
372
|
+
unreleasedLeases.set(sessionId, { cwd: leaseCwd, sessionId });
|
|
326
373
|
return { released: false };
|
|
327
374
|
}
|
|
328
375
|
};
|
|
@@ -348,6 +395,19 @@ export function createSessionDaemon({
|
|
|
348
395
|
let stopping = false;
|
|
349
396
|
const knownDirectories = new Set([cwd]);
|
|
350
397
|
let activeDirectory = cwd;
|
|
398
|
+
// The folder a request without one is answered for. While the active
|
|
399
|
+
// folder (or the startup folder) belongs to a sandbox daemon, this daemon
|
|
400
|
+
// answers from a folder outside every sandbox instead: starting a runtime
|
|
401
|
+
// in the project would load its extensions outside its sandbox.
|
|
402
|
+
const neutralDirectory = () => [cwd, agentDir].find((directory) => typeof directory === 'string'
|
|
403
|
+
&& directory.length > 0 && !isSandboxedDirectory(directory)) ?? agentDir;
|
|
404
|
+
const outsideSandbox = (directory) => (isSandboxedDirectory(directory) ? neutralDirectory() : directory);
|
|
405
|
+
const defaultDirectory = () => outsideSandbox(activeDirectory || cwd);
|
|
406
|
+
const refuseSandboxedRuntime = (directory) => {
|
|
407
|
+
if (isSandboxedDirectory(directory)) {
|
|
408
|
+
throw new SessionDaemonProtocolError('DIRECTORY_SANDBOXED', 'The folder belongs to a sandboxed project.');
|
|
409
|
+
}
|
|
410
|
+
};
|
|
351
411
|
const clients = new Set();
|
|
352
412
|
// A reconnect replays only a contiguous retained suffix; otherwise it receives
|
|
353
413
|
// a new authoritative snapshot before later events can arrive. The suffix is
|
|
@@ -485,6 +545,10 @@ export function createSessionDaemon({
|
|
|
485
545
|
if (!hasPendingUserStarts(buckets)) pendingUserStartsBySession.delete(sessionId);
|
|
486
546
|
};
|
|
487
547
|
const shutdownRequestedBySession = new Set();
|
|
548
|
+
// Sessions in folders the server asked this daemon to release (#247):
|
|
549
|
+
// the session moves to another daemon, so it is disposed at its next idle
|
|
550
|
+
// edge instead of after the idle timeout.
|
|
551
|
+
const releaseRequestedBySession = new Set();
|
|
488
552
|
const disposingSessionIds = new Set();
|
|
489
553
|
const streamingRedactionBuffers = new Map();
|
|
490
554
|
const loginAttempts = new Map();
|
|
@@ -496,7 +560,7 @@ export function createSessionDaemon({
|
|
|
496
560
|
|
|
497
561
|
const skillReadClassifierFor = (activeRuntime, directory) => {
|
|
498
562
|
if (!activeRuntime || typeof activeRuntime !== 'object') return undefined;
|
|
499
|
-
const classifierCwd = activeRuntime.cwd || directory ||
|
|
563
|
+
const classifierCwd = activeRuntime.cwd || directory || defaultDirectory();
|
|
500
564
|
const cached = skillReadClassifierByRuntime.get(activeRuntime);
|
|
501
565
|
if (cached?.cwd === classifierCwd) return cached.classifier;
|
|
502
566
|
const loader = activeRuntime.services?.resourceLoader;
|
|
@@ -593,13 +657,13 @@ export function createSessionDaemon({
|
|
|
593
657
|
// so skills (and other resources) never trigger the trust popup for known dirs.
|
|
594
658
|
try {
|
|
595
659
|
const trustStore = createTrustStore(agentDir);
|
|
596
|
-
if (trustStore.get(validated) === null && hasTrustRequiringProjectResources(validated)) {
|
|
660
|
+
if (trustStore.get(validated) === null && !isTrustAskDirectory(validated) && hasTrustRequiringProjectResources(validated)) {
|
|
597
661
|
trustStore.set(validated, true);
|
|
598
662
|
}
|
|
599
663
|
} catch {}
|
|
600
664
|
return validated;
|
|
601
665
|
}
|
|
602
|
-
return
|
|
666
|
+
return defaultDirectory();
|
|
603
667
|
};
|
|
604
668
|
|
|
605
669
|
// Listing or deleting a folder's sessions reads Pi's session store, not the
|
|
@@ -608,7 +672,7 @@ export function createSessionDaemon({
|
|
|
608
672
|
// still be a directory, and opening or creating a session keeps the strict
|
|
609
673
|
// check in `resolveDirectory`.
|
|
610
674
|
const resolveSessionStoreDirectory = async (requested) => {
|
|
611
|
-
if (typeof requested !== 'string' || requested.trim().length === 0) return
|
|
675
|
+
if (typeof requested !== 'string' || requested.trim().length === 0) return defaultDirectory();
|
|
612
676
|
const trimmed = requested.trim();
|
|
613
677
|
const normalized = trimmed === '~' ? homedir() : trimmed;
|
|
614
678
|
if (!isAbsolute(normalized)) {
|
|
@@ -647,8 +711,8 @@ export function createSessionDaemon({
|
|
|
647
711
|
// no watchers, intervals, or listeners), so dropping the reference lets GC
|
|
648
712
|
// reclaim it. Retaining them only grew the daemon and fanned provider
|
|
649
713
|
// refreshes out to orphan ModelRuntimes whose catalogs are never read.
|
|
650
|
-
const createFreshPromptServices = async (targetCwd =
|
|
651
|
-
cwd: targetCwd,
|
|
714
|
+
const createFreshPromptServices = async (targetCwd = defaultDirectory()) => injectCreateServices({
|
|
715
|
+
cwd: outsideSandbox(targetCwd),
|
|
652
716
|
agentDir,
|
|
653
717
|
resourceLoaderOptions: {
|
|
654
718
|
extensionFactories: [...getBuiltinExtensionFactories(), ...pluginHost.extensionFactories(), ...internalExtensionFactories()],
|
|
@@ -667,7 +731,7 @@ export function createSessionDaemon({
|
|
|
667
731
|
const draftSessionIds = new Set();
|
|
668
732
|
const publish = (event, payload, sessionId = runtime?.session?.sessionId, directory) => {
|
|
669
733
|
if (typeof sessionId !== 'string' || sessionId.length === 0) return;
|
|
670
|
-
const targetDirectory = directory ||
|
|
734
|
+
const targetDirectory = directory || defaultDirectory();
|
|
671
735
|
const draft = draftSessionIds.has(sessionId);
|
|
672
736
|
const message = {
|
|
673
737
|
protocolVersion: PROTOCOL_VERSION,
|
|
@@ -705,7 +769,7 @@ export function createSessionDaemon({
|
|
|
705
769
|
streamEpoch,
|
|
706
770
|
sequence: ++sequence,
|
|
707
771
|
...(draftSessionIds.has(sessionId) ? { draft: true } : {}),
|
|
708
|
-
payload: { sessionId, directory: directory ||
|
|
772
|
+
payload: { sessionId, directory: directory || defaultDirectory(), ...payload },
|
|
709
773
|
};
|
|
710
774
|
const line = `${JSON.stringify(message)}\n`;
|
|
711
775
|
for (const client of clients) writeLine(client, line);
|
|
@@ -772,7 +836,7 @@ export function createSessionDaemon({
|
|
|
772
836
|
pendingInput,
|
|
773
837
|
agentDir,
|
|
774
838
|
theme: extensionTheme,
|
|
775
|
-
directoryForSession: (sessionId) => findRuntimeForSession(sessionId)?.cwd ||
|
|
839
|
+
directoryForSession: (sessionId) => findRuntimeForSession(sessionId)?.cwd || defaultDirectory(),
|
|
776
840
|
redactLine: (line) => redactAttachmentPaths(line),
|
|
777
841
|
describeOrigin: describeCustomOrigin,
|
|
778
842
|
openerClientFor: (sessionId) => promptClientBySession.get(sessionId),
|
|
@@ -792,7 +856,7 @@ export function createSessionDaemon({
|
|
|
792
856
|
redactAttachmentValues: (value) => redactAttachmentValues(value),
|
|
793
857
|
findRuntimeBySessionId: (sessionId) => runtimeRegistry?.findBySessionId(sessionId)
|
|
794
858
|
|| (runtime?.session?.sessionId === sessionId ? runtime : undefined),
|
|
795
|
-
getDefaultDirectory: () =>
|
|
859
|
+
getDefaultDirectory: () => defaultDirectory(),
|
|
796
860
|
getSequence: () => sequence,
|
|
797
861
|
protocolError: (code, message) => new SessionDaemonProtocolError(code, message),
|
|
798
862
|
renderExtensionMessage: (session, message) => extensionMessageRenderer.renderMessage(session, message),
|
|
@@ -853,7 +917,7 @@ export function createSessionDaemon({
|
|
|
853
917
|
event: 'extension.custom.frame',
|
|
854
918
|
streamEpoch,
|
|
855
919
|
sequence: ++sequence,
|
|
856
|
-
payload: { sessionId, directory: findRuntimeForSession(sessionId)?.cwd ||
|
|
920
|
+
payload: { sessionId, directory: findRuntimeForSession(sessionId)?.cwd || defaultDirectory(), ...payload },
|
|
857
921
|
});
|
|
858
922
|
}
|
|
859
923
|
};
|
|
@@ -923,7 +987,7 @@ export function createSessionDaemon({
|
|
|
923
987
|
dormantSession = {
|
|
924
988
|
sessionId,
|
|
925
989
|
sessionFile,
|
|
926
|
-
cwd: runtime.cwd ||
|
|
990
|
+
cwd: runtime.cwd || defaultDirectory(),
|
|
927
991
|
};
|
|
928
992
|
};
|
|
929
993
|
|
|
@@ -948,7 +1012,7 @@ export function createSessionDaemon({
|
|
|
948
1012
|
const activeSession = targetRuntime?.session || runtime?.session;
|
|
949
1013
|
const retry = session.sessionId ? retryStateBySession.get(session.sessionId) : undefined;
|
|
950
1014
|
const compaction = compactionStateFor(activeSession);
|
|
951
|
-
const targetDirectory = targetRuntime?.cwd ||
|
|
1015
|
+
const targetDirectory = targetRuntime?.cwd || defaultDirectory();
|
|
952
1016
|
const lastAssistant = activeSession ? projectLatestAssistantMessage(targetRuntime || runtime) : undefined;
|
|
953
1017
|
const model = activeSession?.model;
|
|
954
1018
|
const snapshotSequence = ++sequence;
|
|
@@ -1097,14 +1161,14 @@ export function createSessionDaemon({
|
|
|
1097
1161
|
try {
|
|
1098
1162
|
for (const tracked of runtimeRegistry?.listAll?.() ?? []) {
|
|
1099
1163
|
if (typeof tracked?.session?.sessionId === 'string') {
|
|
1100
|
-
leased.push({ cwd: tracked.cwd ||
|
|
1164
|
+
leased.push({ cwd: tracked.cwd || defaultDirectory(), sessionId: tracked.session.sessionId });
|
|
1101
1165
|
}
|
|
1102
1166
|
}
|
|
1103
1167
|
} catch {
|
|
1104
1168
|
// Registry enumeration must never block teardown.
|
|
1105
1169
|
}
|
|
1106
1170
|
if (runtime && typeof runtime.session?.sessionId === 'string') {
|
|
1107
|
-
leased.push({ cwd: runtime.cwd ||
|
|
1171
|
+
leased.push({ cwd: runtime.cwd || defaultDirectory(), sessionId: runtime.session.sessionId });
|
|
1108
1172
|
}
|
|
1109
1173
|
if (runtimeRegistry) {
|
|
1110
1174
|
const hadTrackedRuntime = runtimeRegistry.size > 0;
|
|
@@ -1147,7 +1211,7 @@ export function createSessionDaemon({
|
|
|
1147
1211
|
if (ephemeralReleased) forgetEphemeralSession({ cwd: ephemeralSession.cwd, sessionId: ephemeralSession.sessionId });
|
|
1148
1212
|
};
|
|
1149
1213
|
|
|
1150
|
-
const startRuntime = async ({ cwd: runtimeCwd =
|
|
1214
|
+
const startRuntime = async ({ cwd: runtimeCwd = defaultDirectory(), sessionFile, activate = true } = {}) => {
|
|
1151
1215
|
if (sessionFile) await validatePiSessionJsonlFile(sessionFile);
|
|
1152
1216
|
const canonicalRuntimeCwd = sessionFile && dormantSession?.cwd
|
|
1153
1217
|
? dormantSession.cwd
|
|
@@ -1157,6 +1221,7 @@ export function createSessionDaemon({
|
|
|
1157
1221
|
}
|
|
1158
1222
|
let newRuntime;
|
|
1159
1223
|
try {
|
|
1224
|
+
refuseSandboxedRuntime(canonicalRuntimeCwd);
|
|
1160
1225
|
newRuntime = await createRuntime({ cwd: canonicalRuntimeCwd, agentDir, ...(sessionFile ? { sessionFile } : {}) });
|
|
1161
1226
|
} catch (error) {
|
|
1162
1227
|
if (sessionFile && dormantSession?.sessionId) {
|
|
@@ -1194,7 +1259,7 @@ export function createSessionDaemon({
|
|
|
1194
1259
|
return newRuntime;
|
|
1195
1260
|
};
|
|
1196
1261
|
|
|
1197
|
-
const ensureRuntime = (targetCwd =
|
|
1262
|
+
const ensureRuntime = (targetCwd = defaultDirectory()) => {
|
|
1198
1263
|
const requestedCwd = resolve(targetCwd);
|
|
1199
1264
|
// Runtime state is owned per working directory. A request that names a
|
|
1200
1265
|
// directory is answered by a runtime resident in that directory, never by
|
|
@@ -1223,7 +1288,7 @@ export function createSessionDaemon({
|
|
|
1223
1288
|
// runtime, adopts what it starts. After idle disposal clears `runtime`,
|
|
1224
1289
|
// `activeDirectory` still names the user's project, so reading another
|
|
1225
1290
|
// project's catalog leaves that project and its dormant session intact.
|
|
1226
|
-
activate: !runtime && requestedCwd === resolve(
|
|
1291
|
+
activate: !runtime && requestedCwd === resolve(defaultDirectory()),
|
|
1227
1292
|
}).finally(() => {
|
|
1228
1293
|
if (runtimeStartPromises.get(requestedCwd) === pendingStart) {
|
|
1229
1294
|
runtimeStartPromises.delete(requestedCwd);
|
|
@@ -1363,7 +1428,7 @@ export function createSessionDaemon({
|
|
|
1363
1428
|
? (runtimeRegistry?.listAll?.() ?? [])
|
|
1364
1429
|
: (runtimeRegistry?.listByDirectory?.(targetDir) ?? [])
|
|
1365
1430
|
);
|
|
1366
|
-
if (runtime && (affectsGlobal || resolve(runtime.cwd ||
|
|
1431
|
+
if (runtime && (affectsGlobal || resolve(runtime.cwd || defaultDirectory()) === resolve(targetDir))) {
|
|
1367
1432
|
candidates.add(runtime);
|
|
1368
1433
|
}
|
|
1369
1434
|
await Promise.all([...candidates].map(async (targetRuntime) => {
|
|
@@ -1434,7 +1499,7 @@ export function createSessionDaemon({
|
|
|
1434
1499
|
} catch {
|
|
1435
1500
|
assignedSessionFile = undefined;
|
|
1436
1501
|
}
|
|
1437
|
-
const targetCwd = targetRuntime.cwd ||
|
|
1502
|
+
const targetCwd = targetRuntime.cwd || defaultDirectory();
|
|
1438
1503
|
try {
|
|
1439
1504
|
if (draftSessionIds.has(sessionId)) {
|
|
1440
1505
|
// Forceful for a draft: answer its dialogs, close its surfaces,
|
|
@@ -1453,6 +1518,7 @@ export function createSessionDaemon({
|
|
|
1453
1518
|
extensionToolRenderer.clearSession(sessionId);
|
|
1454
1519
|
runningToolsBySession.delete(sessionId);
|
|
1455
1520
|
await runtimeRegistry.dispose(targetRuntime);
|
|
1521
|
+
releaseRequestedBySession.delete(sessionId);
|
|
1456
1522
|
// Positively determine ephemerality while the resident lease is
|
|
1457
1523
|
// still held, before any release. A stat success means persisted;
|
|
1458
1524
|
// ENOENT means the assigned JSONL never reached disk; any other
|
|
@@ -1493,6 +1559,42 @@ export function createSessionDaemon({
|
|
|
1493
1559
|
return tracked;
|
|
1494
1560
|
};
|
|
1495
1561
|
|
|
1562
|
+
// Let go of every resident session in `directories` (and folders inside
|
|
1563
|
+
// them): idle ones are disposed now, busy ones (turn, compaction, shell
|
|
1564
|
+
// command, custom surface, pending dialog) at their next idle edge. The
|
|
1565
|
+
// server polls until nothing is pending, announcing each move.
|
|
1566
|
+
const releaseDirectories = async (payload) => {
|
|
1567
|
+
const directories = payload?.directories;
|
|
1568
|
+
if (!Array.isArray(directories) || directories.length === 0 || directories.length > 64
|
|
1569
|
+
|| directories.some((directory) => typeof directory !== 'string' || !isAbsolute(directory))) {
|
|
1570
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The folders to release are invalid.');
|
|
1571
|
+
}
|
|
1572
|
+
const roots = directories.map((directory) => resolve(directory));
|
|
1573
|
+
const owns = (directory) => roots.some((root) => directory === root || directory.startsWith(root.endsWith(sep) ? root : `${root}${sep}`));
|
|
1574
|
+
const released = [];
|
|
1575
|
+
const pending = [];
|
|
1576
|
+
for (const target of runtimeRegistry?.listAll() ?? []) {
|
|
1577
|
+
const sessionId = target.session?.sessionId;
|
|
1578
|
+
const directory = typeof target.cwd === 'string' && target.cwd.length > 0 ? resolve(target.cwd) : null;
|
|
1579
|
+
if (!isValidIdleSessionId(sessionId) || !directory || !owns(directory)) continue;
|
|
1580
|
+
releaseRequestedBySession.add(sessionId);
|
|
1581
|
+
await disposeIdleSessionRuntime(sessionId);
|
|
1582
|
+
if (runtimeRegistry.findBySessionId(sessionId) === target || unreleasedLeases.has(sessionId)) pending.push({ sessionId, directory });
|
|
1583
|
+
else released.push({ sessionId, directory });
|
|
1584
|
+
}
|
|
1585
|
+
// Sessions disposed earlier whose lease could not be released then.
|
|
1586
|
+
for (const lease of [...unreleasedLeases.values()]) {
|
|
1587
|
+
const directory = typeof lease.cwd === 'string' && lease.cwd.length > 0 ? resolve(lease.cwd) : null;
|
|
1588
|
+
if (!directory || !owns(directory) || runtimeRegistry?.findBySessionId(lease.sessionId)) continue;
|
|
1589
|
+
if (released.some((item) => item.sessionId === lease.sessionId) || pending.some((item) => item.sessionId === lease.sessionId)) continue;
|
|
1590
|
+
// Skipped means the session is being opened here again: still this
|
|
1591
|
+
// daemon's, so not released.
|
|
1592
|
+
const { skipped } = await releaseResidentLease(lease, { onlyUnreleased: true });
|
|
1593
|
+
(skipped || unreleasedLeases.has(lease.sessionId) ? pending : released).push({ sessionId: lease.sessionId, directory });
|
|
1594
|
+
}
|
|
1595
|
+
return { released, pending, streamEpoch };
|
|
1596
|
+
};
|
|
1597
|
+
|
|
1496
1598
|
const completeRequestedShutdown = (sessionId) => {
|
|
1497
1599
|
if (!shutdownRequestedBySession.has(sessionId)) return false;
|
|
1498
1600
|
void disposeIdleSessionRuntime(sessionId);
|
|
@@ -1505,7 +1607,7 @@ export function createSessionDaemon({
|
|
|
1505
1607
|
const timer = setTimeout(() => {
|
|
1506
1608
|
idleDisposeTimers.delete(sessionId);
|
|
1507
1609
|
void disposeIdleSessionRuntime(sessionId);
|
|
1508
|
-
}, idleTimeoutMs);
|
|
1610
|
+
}, releaseRequestedBySession.has(sessionId) ? 0 : idleTimeoutMs);
|
|
1509
1611
|
idleDisposeTimers.set(sessionId, timer);
|
|
1510
1612
|
};
|
|
1511
1613
|
|
|
@@ -1711,7 +1813,7 @@ export function createSessionDaemon({
|
|
|
1711
1813
|
}
|
|
1712
1814
|
const sessionId = payload.sessionId;
|
|
1713
1815
|
const title = payload.title.trim();
|
|
1714
|
-
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (
|
|
1816
|
+
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (defaultDirectory());
|
|
1715
1817
|
const activeRuntime = runtimeRegistry?.get({ cwd: targetDir, sessionId })
|
|
1716
1818
|
|| runtimeRegistry?.findBySessionId(sessionId)
|
|
1717
1819
|
|| (runtime?.session?.sessionId === sessionId ? runtime : undefined);
|
|
@@ -1738,11 +1840,13 @@ export function createSessionDaemon({
|
|
|
1738
1840
|
|
|
1739
1841
|
// Deletion passes `allowRemovedDirectory`: a session whose folder has since
|
|
1740
1842
|
// been removed is still found in the store. Opening keeps the strict check.
|
|
1741
|
-
const findPersistedSession = async (sessionId, requestedDirectory, { allowRemovedDirectory = false } = {}) => {
|
|
1843
|
+
const findPersistedSession = async (sessionId, requestedDirectory, { allowRemovedDirectory = false, readOnly = false } = {}) => {
|
|
1742
1844
|
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
1743
1845
|
throw new SessionDaemonProtocolError('INVALID_SESSION', 'The Pi session does not exist.');
|
|
1744
1846
|
}
|
|
1745
|
-
|
|
1847
|
+
// A read-only lookup only checks the folder: `resolveDirectory` also
|
|
1848
|
+
// records it and may trust it, which a transcript read must not do.
|
|
1849
|
+
const resolve = allowRemovedDirectory ? resolveSessionStoreDirectory : (readOnly ? validateDirectoryPath : resolveDirectory);
|
|
1746
1850
|
const candidateDirs = new Set();
|
|
1747
1851
|
let requestedTargetDirectory;
|
|
1748
1852
|
if (requestedDirectory) {
|
|
@@ -1876,6 +1980,7 @@ export function createSessionDaemon({
|
|
|
1876
1980
|
await acquireResidentLease({ cwd: directory, sessionId });
|
|
1877
1981
|
let newRuntime;
|
|
1878
1982
|
try {
|
|
1983
|
+
refuseSandboxedRuntime(directory);
|
|
1879
1984
|
newRuntime = await createRuntime({ cwd: directory, agentDir, sessionFile: target.path });
|
|
1880
1985
|
if (!newRuntime.cwd) newRuntime.cwd = directory;
|
|
1881
1986
|
if (newRuntime.session?.sessionId !== sessionId && typeof newRuntime.switchSession === 'function') {
|
|
@@ -1983,7 +2088,7 @@ export function createSessionDaemon({
|
|
|
1983
2088
|
return undefined;
|
|
1984
2089
|
};
|
|
1985
2090
|
|
|
1986
|
-
const projectMessageEntries = (activeRuntime, targetDir =
|
|
2091
|
+
const projectMessageEntries = (activeRuntime, targetDir = defaultDirectory()) => {
|
|
1987
2092
|
const session = activeRuntime?.session;
|
|
1988
2093
|
// Use the active branch, not the full file. `getEntries()` returns every
|
|
1989
2094
|
// entry ever written, so a bare `branch()`/`resetLeaf()` would appear to
|
|
@@ -2276,7 +2381,7 @@ export function createSessionDaemon({
|
|
|
2276
2381
|
|
|
2277
2382
|
const projectActiveSession = (
|
|
2278
2383
|
activeRuntime = runtime,
|
|
2279
|
-
targetDir = activeRuntime?.cwd ||
|
|
2384
|
+
targetDir = activeRuntime?.cwd || defaultDirectory(),
|
|
2280
2385
|
pageOptions = {},
|
|
2281
2386
|
) => {
|
|
2282
2387
|
const session = activeRuntime?.session;
|
|
@@ -2344,6 +2449,51 @@ export function createSessionDaemon({
|
|
|
2344
2449
|
};
|
|
2345
2450
|
};
|
|
2346
2451
|
|
|
2452
|
+
/**
|
|
2453
|
+
* A transcript read straight from its JSONL file (#242, fail closed). The
|
|
2454
|
+
* server asks for it when a sandboxed project's session cannot open in its
|
|
2455
|
+
* sandbox: no Pi runtime, extension, or tool starts, nothing is written
|
|
2456
|
+
* (an in-memory session manager over the parsed entries), and no lease is
|
|
2457
|
+
* taken. The detail is metadata only: `readOnly`, idle, `lastSequence` -1,
|
|
2458
|
+
* and no stream epoch, input state, extension state, or bash executions,
|
|
2459
|
+
* because none of that is this daemon's to claim.
|
|
2460
|
+
*/
|
|
2461
|
+
const readPersistedSession = async (payload) => {
|
|
2462
|
+
const sessionId = payload?.sessionId;
|
|
2463
|
+
const { target, directory } = await findPersistedSession(sessionId, payload?.directory || payload?.cwd, { readOnly: true });
|
|
2464
|
+
const entries = parseSessionEntries(await readFile(target.path, 'utf8'));
|
|
2465
|
+
const header = entries[0];
|
|
2466
|
+
const createdAt = Date.parse(header?.timestamp);
|
|
2467
|
+
if (header?.type !== 'session' || header.id !== sessionId || !Number.isFinite(createdAt)) {
|
|
2468
|
+
throw new SessionDaemonProtocolError('INVALID_SESSION', 'The Pi session does not exist.');
|
|
2469
|
+
}
|
|
2470
|
+
const sessionManager = SessionManager.inMemory(directory, undefined, entries);
|
|
2471
|
+
const session = { sessionId, sessionManager, sessionName: sessionManager.getSessionName(), isStreaming: false };
|
|
2472
|
+
const allMessages = projectMessageEntries({ cwd: directory, session }, directory);
|
|
2473
|
+
const page = projectMessagePage(allMessages, { before: payload?.before, limit: payload?.limit });
|
|
2474
|
+
let lastAssistant;
|
|
2475
|
+
for (let index = allMessages.length - 1; index >= 0 && !lastAssistant; index -= 1) {
|
|
2476
|
+
if (allMessages[index]?.message?.role === 'assistant') lastAssistant = allMessages[index].message;
|
|
2477
|
+
}
|
|
2478
|
+
return {
|
|
2479
|
+
session: {
|
|
2480
|
+
id: sessionId, directory, createdAt, updatedAt: createdAt,
|
|
2481
|
+
...(session.sessionName ? { title: session.sessionName } : {}),
|
|
2482
|
+
...(lastAssistant?.model ? { model: lastAssistant.model } : {}),
|
|
2483
|
+
...(lastAssistant?.thinkingLevel ? { thinking: lastAssistant.thinkingLevel } : {}),
|
|
2484
|
+
messageCount: allMessages.length,
|
|
2485
|
+
},
|
|
2486
|
+
messages: page.messages,
|
|
2487
|
+
hasMoreBefore: page.hasMoreBefore === true,
|
|
2488
|
+
...(page.hasMoreBefore ? { beforeCursor: page.beforeCursor } : {}),
|
|
2489
|
+
lastSequence: -1,
|
|
2490
|
+
isStreaming: false,
|
|
2491
|
+
lifecycle: 'idle',
|
|
2492
|
+
readOnly: true,
|
|
2493
|
+
serverNow: Date.now(),
|
|
2494
|
+
};
|
|
2495
|
+
};
|
|
2496
|
+
|
|
2347
2497
|
/**
|
|
2348
2498
|
* Send from a draft: its session becomes the new session, with the title,
|
|
2349
2499
|
* model, and thinking the send asked for, so what the draft's controls did
|
|
@@ -2460,6 +2610,7 @@ export function createSessionDaemon({
|
|
|
2460
2610
|
onSessionEvent: ({ cwd: eventCwd, sessionId: eventSessionId }, event) => publishSessionEvent(eventSessionId, event, eventCwd),
|
|
2461
2611
|
});
|
|
2462
2612
|
}
|
|
2613
|
+
refuseSandboxedRuntime(targetCwd);
|
|
2463
2614
|
// A draft's sessions are marked from the moment Pi assigns their ids:
|
|
2464
2615
|
// the runtime's first session (replaced below) and the draft itself.
|
|
2465
2616
|
const markedDraftIds = new Set();
|
|
@@ -2598,7 +2749,7 @@ export function createSessionDaemon({
|
|
|
2598
2749
|
} catch {
|
|
2599
2750
|
// A failed rebuild stays queued for a later edge; the ensure below retries startup.
|
|
2600
2751
|
}
|
|
2601
|
-
const targetDir = requestedDirectory ? await resolveDirectory(requestedDirectory) : (
|
|
2752
|
+
const targetDir = requestedDirectory ? await resolveDirectory(requestedDirectory) : (defaultDirectory());
|
|
2602
2753
|
const activeRuntime = await ensureRuntime(targetDir);
|
|
2603
2754
|
const modelRuntime = activeRuntime.session?.modelRuntime;
|
|
2604
2755
|
const models = modelRuntime?.getModels?.();
|
|
@@ -2626,6 +2777,58 @@ export function createSessionDaemon({
|
|
|
2626
2777
|
return { providers: [...providers.values()] };
|
|
2627
2778
|
};
|
|
2628
2779
|
|
|
2780
|
+
// Host names of signed-in providers' model endpoints: the default network
|
|
2781
|
+
// allowlist of a sandboxed project. Loopback hosts are left out; a local
|
|
2782
|
+
// model server is allowed per project by port.
|
|
2783
|
+
// The runtime that answers a provider question for the server's sandbox
|
|
2784
|
+
// manager. `exclude` names the folders of sandboxed projects: this daemon
|
|
2785
|
+
// must not start (or reopen a dormant session in) a runtime there, since
|
|
2786
|
+
// that would load the project's extensions outside its sandbox. A resident
|
|
2787
|
+
// runtime elsewhere is used as it is; otherwise one starts in the active
|
|
2788
|
+
// folder, or in the agent folder when the active folder is excluded.
|
|
2789
|
+
const providerRuntime = async (exclude) => {
|
|
2790
|
+
if (exclude !== undefined && (!Array.isArray(exclude) || exclude.length > 4096
|
|
2791
|
+
|| exclude.some((directory) => typeof directory !== 'string' || !isAbsolute(directory)))) {
|
|
2792
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The folders to stay out of are invalid.');
|
|
2793
|
+
}
|
|
2794
|
+
const roots = (exclude ?? []).map((directory) => resolve(directory));
|
|
2795
|
+
if (roots.length === 0) return ensureRuntime(defaultDirectory());
|
|
2796
|
+
const excluded = (directory) => {
|
|
2797
|
+
const target = resolve(directory);
|
|
2798
|
+
return roots.some((root) => target === root || target.startsWith(root.endsWith(sep) ? root : `${root}${sep}`));
|
|
2799
|
+
};
|
|
2800
|
+
const residents = [...(runtime ? [runtime] : []), ...(runtimeRegistry?.listAll?.() ?? [])];
|
|
2801
|
+
const resident = residents.find((candidate) => typeof candidate?.cwd === 'string' && candidate.cwd.length > 0 && !excluded(candidate.cwd));
|
|
2802
|
+
if (resident) return resident;
|
|
2803
|
+
const target = [defaultDirectory(), agentDir].find((directory) => typeof directory === 'string' && directory.length > 0 && !excluded(directory));
|
|
2804
|
+
if (!target) throw new SessionDaemonProtocolError('PROVIDER_UNAVAILABLE', 'No folder outside the sandboxed projects can answer for the providers.');
|
|
2805
|
+
return ensureRuntime(target);
|
|
2806
|
+
};
|
|
2807
|
+
|
|
2808
|
+
const listProviderHosts = async (payload) => {
|
|
2809
|
+
const activeRuntime = await providerRuntime(payload?.exclude);
|
|
2810
|
+
const modelRuntime = activeRuntime.session?.modelRuntime;
|
|
2811
|
+
const models = modelRuntime?.getModels?.();
|
|
2812
|
+
if (!Array.isArray(models)) throw new SessionDaemonProtocolError('PROVIDER_UNAVAILABLE', 'Pi did not provide a model catalog.');
|
|
2813
|
+
const hosts = new Set();
|
|
2814
|
+
for (const model of models) {
|
|
2815
|
+
if (!model || typeof model.provider !== 'string' || typeof model.baseUrl !== 'string') continue;
|
|
2816
|
+
if (modelRuntime.getProviderAuthStatus?.(model.provider)?.configured !== true) continue;
|
|
2817
|
+
let hostname;
|
|
2818
|
+
try {
|
|
2819
|
+
const url = new URL(model.baseUrl);
|
|
2820
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') continue;
|
|
2821
|
+
hostname = url.hostname.toLowerCase();
|
|
2822
|
+
} catch {
|
|
2823
|
+
continue;
|
|
2824
|
+
}
|
|
2825
|
+
if (!hostname || hostname === 'localhost' || hostname.endsWith('.localhost')
|
|
2826
|
+
|| /^[\d.]+$/.test(hostname) || hostname.startsWith('[')) continue;
|
|
2827
|
+
hosts.add(hostname);
|
|
2828
|
+
}
|
|
2829
|
+
return { hosts: [...hosts].sort() };
|
|
2830
|
+
};
|
|
2831
|
+
|
|
2629
2832
|
// In-flight refreshes are shared per resolved directory, never across
|
|
2630
2833
|
// directories, so a concurrent refresh for another project cannot return
|
|
2631
2834
|
// this project's catalog. Refreshes for different directories still run one
|
|
@@ -2639,7 +2842,7 @@ export function createSessionDaemon({
|
|
|
2639
2842
|
} catch {
|
|
2640
2843
|
// A failed rebuild stays queued for a later edge; the catalog refresh below retries startup.
|
|
2641
2844
|
}
|
|
2642
|
-
const targetDir = resolve(await resolveDirectory(requestedDirectory));
|
|
2845
|
+
const targetDir = outsideSandbox(resolve(await resolveDirectory(requestedDirectory)));
|
|
2643
2846
|
const existing = refreshProvidersInflight.get(targetDir);
|
|
2644
2847
|
if (existing) return existing;
|
|
2645
2848
|
const task = refreshProvidersQueue.then(async () => {
|
|
@@ -2856,6 +3059,32 @@ export function createSessionDaemon({
|
|
|
2856
3059
|
return { config, ...(deferred ? { deferred: true } : {}) };
|
|
2857
3060
|
};
|
|
2858
3061
|
|
|
3062
|
+
// The main daemon owns OAuth token refresh: a sandbox daemon reads
|
|
3063
|
+
// auth.json through a read-only grant, so before one starts (and after a
|
|
3064
|
+
// sandboxed turn failed to refresh) the server asks here. Each signed-in
|
|
3065
|
+
// OAuth provider whose token expires within `minValidityMs` is refreshed
|
|
3066
|
+
// through Pi under its auth lock. Only failed provider ids are reported.
|
|
3067
|
+
const refreshOAuthTokens = async (payload) => {
|
|
3068
|
+
const minValidityMs = payload?.minValidityMs;
|
|
3069
|
+
if (!Number.isSafeInteger(minValidityMs) || minValidityMs < 0 || minValidityMs > 24 * 60 * 60_000) {
|
|
3070
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The OAuth refresh window is invalid.');
|
|
3071
|
+
}
|
|
3072
|
+
const activeRuntime = await providerRuntime(payload?.exclude);
|
|
3073
|
+
const modelRuntime = activeRuntime.session?.modelRuntime;
|
|
3074
|
+
const providers = typeof modelRuntime?.getProviders === 'function' ? modelRuntime.getProviders() : [];
|
|
3075
|
+
const ids = [...new Set(providers.map((provider) => provider?.id).filter((id) => typeof id === 'string' && id.length > 0))]
|
|
3076
|
+
.filter((id) => modelRuntime.isUsingOAuth?.(id) === true);
|
|
3077
|
+
const failed = [];
|
|
3078
|
+
for (const id of ids) {
|
|
3079
|
+
try {
|
|
3080
|
+
await modelRuntime.getAuth(id, { minOAuthValidityMs: minValidityMs });
|
|
3081
|
+
} catch {
|
|
3082
|
+
failed.push(id);
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
return { checked: ids.length, failed };
|
|
3086
|
+
};
|
|
3087
|
+
|
|
2859
3088
|
const providerStatus = async (providerId) => {
|
|
2860
3089
|
if (typeof providerId !== 'string' || providerId.length === 0 || providerId.length > 256) {
|
|
2861
3090
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The requested provider is invalid.');
|
|
@@ -3015,12 +3244,12 @@ export function createSessionDaemon({
|
|
|
3015
3244
|
};
|
|
3016
3245
|
|
|
3017
3246
|
const readPiSettings = (requestedDirectory) => {
|
|
3018
|
-
const targetDir = requestedDirectory ||
|
|
3247
|
+
const targetDir = requestedDirectory || defaultDirectory();
|
|
3019
3248
|
const trustStore = createTrustStore(agentDir);
|
|
3020
3249
|
let trust = trustStore.get(targetDir);
|
|
3021
3250
|
// Auto-trust known PiChamber projects so the skills popup never appears.
|
|
3022
3251
|
// `knownDirectories` tracks every dir the user explicitly added/selected.
|
|
3023
|
-
if (trust === null && knownDirectories.has(targetDir) && hasTrustRequiringProjectResources(targetDir)) {
|
|
3252
|
+
if (trust === null && knownDirectories.has(targetDir) && !isTrustAskDirectory(targetDir) && hasTrustRequiringProjectResources(targetDir)) {
|
|
3024
3253
|
try {
|
|
3025
3254
|
trustStore.set(targetDir, true);
|
|
3026
3255
|
trust = true;
|
|
@@ -3051,7 +3280,7 @@ export function createSessionDaemon({
|
|
|
3051
3280
|
if (!payload || typeof payload !== 'object' || !['global', 'project'].includes(payload.scope)) {
|
|
3052
3281
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi settings request is invalid.');
|
|
3053
3282
|
}
|
|
3054
|
-
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (
|
|
3283
|
+
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (defaultDirectory());
|
|
3055
3284
|
const hasModel = Object.hasOwn(payload, 'defaultModel');
|
|
3056
3285
|
const hasThinking = Object.hasOwn(payload, 'defaultThinking');
|
|
3057
3286
|
const hasTrust = Object.hasOwn(payload, 'trust');
|
|
@@ -3111,8 +3340,8 @@ export function createSessionDaemon({
|
|
|
3111
3340
|
};
|
|
3112
3341
|
};
|
|
3113
3342
|
|
|
3114
|
-
// `pi config` / `pi list` / `pi remove` for
|
|
3115
|
-
// Writes share the resource mutation queue and the shared Pi config lock,
|
|
3343
|
+
// `pi config` / `pi list` / `pi install` / `pi update` / `pi remove` for
|
|
3344
|
+
// extensions (extension-config.js). Writes share the resource mutation queue and the shared Pi config lock,
|
|
3116
3345
|
// read trust inside the lock, and recreate resident runtimes afterwards.
|
|
3117
3346
|
const extensionConfigService = createExtensionConfig({ agentDir, createSettingsManager });
|
|
3118
3347
|
const extensionConfigTarget = async (payload) => {
|
|
@@ -3125,7 +3354,7 @@ export function createSessionDaemon({
|
|
|
3125
3354
|
// that has project resources, so only a denied project is left out.
|
|
3126
3355
|
const decision = directory ? createTrustStore(agentDir).get(directory) : null;
|
|
3127
3356
|
return {
|
|
3128
|
-
cwd:
|
|
3357
|
+
cwd: defaultDirectory(),
|
|
3129
3358
|
directory,
|
|
3130
3359
|
trusted: directory ? decision ?? !hasTrustRequiringProjectResources(directory) : false,
|
|
3131
3360
|
};
|
|
@@ -3149,16 +3378,55 @@ export function createSessionDaemon({
|
|
|
3149
3378
|
const target = await extensionConfigTarget(payload);
|
|
3150
3379
|
return extensionConfigService.list(target, liveExtensionReplacements(target));
|
|
3151
3380
|
};
|
|
3381
|
+
// Recreates resident runtimes after a change and answers with the fresh
|
|
3382
|
+
// list. Runs inside the resource mutation queue.
|
|
3383
|
+
const answerExtensionConfigChange = async (target) => {
|
|
3384
|
+
const deferred = activeRuntimes().length > 0 ? await scheduleRuntimeRecreation() : false;
|
|
3385
|
+
const result = await extensionConfigService.list(target, liveExtensionReplacements(target));
|
|
3386
|
+
return deferred ? { ...result, deferred: true } : result;
|
|
3387
|
+
};
|
|
3152
3388
|
const mutateExtensionConfig = (payload, write) => transactResourceMutation(async () => {
|
|
3153
3389
|
const target = await withSharedPiConfigLock(async () => {
|
|
3154
3390
|
const resolved = await extensionConfigTarget(payload);
|
|
3155
3391
|
await write(resolved);
|
|
3156
3392
|
return resolved;
|
|
3157
3393
|
});
|
|
3158
|
-
|
|
3159
|
-
const result = await extensionConfigService.list(target, liveExtensionReplacements(target));
|
|
3160
|
-
return deferred ? { ...result, deferred: true } : result;
|
|
3394
|
+
return answerExtensionConfigChange(target);
|
|
3161
3395
|
});
|
|
3396
|
+
// `pi install` / `pi update` run npm or git for minutes, so they never hold
|
|
3397
|
+
// the shared Pi config lock (other writers give up after 5 s) or the
|
|
3398
|
+
// resource mutation queue. They queue here instead: one package download
|
|
3399
|
+
// at a time per daemon. Only the settings write afterwards takes the lock.
|
|
3400
|
+
let packageInstallTail = Promise.resolve();
|
|
3401
|
+
const serializePackageInstall = (operation) => {
|
|
3402
|
+
const pending = packageInstallTail.then(operation);
|
|
3403
|
+
packageInstallTail = pending.catch(() => {});
|
|
3404
|
+
return pending;
|
|
3405
|
+
};
|
|
3406
|
+
const installExtensionPackage = async (payload) => {
|
|
3407
|
+
let target = await extensionConfigTarget(payload);
|
|
3408
|
+
let answer;
|
|
3409
|
+
const { installedId } = await extensionConfigService.installPackage(target, payload, {
|
|
3410
|
+
serializeInstall: serializePackageInstall,
|
|
3411
|
+
resolveTarget: () => extensionConfigTarget(payload),
|
|
3412
|
+
withWriteLock: (write) => transactResourceMutation(async () => {
|
|
3413
|
+
await withSharedPiConfigLock(async () => {
|
|
3414
|
+
target = await extensionConfigTarget(payload);
|
|
3415
|
+
await write(target);
|
|
3416
|
+
});
|
|
3417
|
+
answer = await answerExtensionConfigChange(target);
|
|
3418
|
+
}),
|
|
3419
|
+
});
|
|
3420
|
+
return { ...answer, installedId };
|
|
3421
|
+
};
|
|
3422
|
+
const updateExtensionPackage = async (payload) => {
|
|
3423
|
+
const target = await extensionConfigTarget(payload);
|
|
3424
|
+
await extensionConfigService.updatePackage(target, payload, {
|
|
3425
|
+
serializeInstall: serializePackageInstall,
|
|
3426
|
+
resolveTarget: () => extensionConfigTarget(payload),
|
|
3427
|
+
});
|
|
3428
|
+
return transactResourceMutation(async () => answerExtensionConfigChange(await extensionConfigTarget(payload)));
|
|
3429
|
+
};
|
|
3162
3430
|
|
|
3163
3431
|
const resourceId = (kind, filePath) => `${kind}:${createHash('sha256').update(filePath).digest('base64url')}`;
|
|
3164
3432
|
|
|
@@ -3183,7 +3451,8 @@ export function createSessionDaemon({
|
|
|
3183
3451
|
}));
|
|
3184
3452
|
|
|
3185
3453
|
const resourceCatalog = async (requestedDirectory) => {
|
|
3186
|
-
|
|
3454
|
+
// A sandboxed project's own resources are read by its sandbox daemon.
|
|
3455
|
+
const targetDir = outsideSandbox(requestedDirectory ? await resolveDirectory(requestedDirectory) : defaultDirectory());
|
|
3187
3456
|
// A settings page may be the first caller after a turn settles without a
|
|
3188
3457
|
// lifecycle event reaching this daemon, so give queued configuration a
|
|
3189
3458
|
// chance to activate before reading the catalog.
|
|
@@ -3318,7 +3587,7 @@ export function createSessionDaemon({
|
|
|
3318
3587
|
if (!payload || typeof payload.resourceId !== 'string' || typeof payload.content !== 'string' || payload.content.length > 200_000) {
|
|
3319
3588
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi resource update is invalid.');
|
|
3320
3589
|
}
|
|
3321
|
-
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (
|
|
3590
|
+
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (defaultDirectory());
|
|
3322
3591
|
const catalog = await resourceCatalog(targetDir);
|
|
3323
3592
|
const resource = [...catalog.prompts, ...catalog.agents].find((item) => item.id === payload.resourceId && item.editable === true);
|
|
3324
3593
|
if (!resource?.filePath) throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi resource is not editable.');
|
|
@@ -3345,7 +3614,7 @@ export function createSessionDaemon({
|
|
|
3345
3614
|
if (payload.location === 'project' && !payload.directory) {
|
|
3346
3615
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'Project prompt templates require an explicit directory.');
|
|
3347
3616
|
}
|
|
3348
|
-
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (
|
|
3617
|
+
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (defaultDirectory());
|
|
3349
3618
|
const trust = createTrustStore(agentDir).get(targetDir);
|
|
3350
3619
|
if (payload.location === 'project' && trust !== true) throw new SessionDaemonProtocolError('PROJECT_UNTRUSTED', 'The project is not trusted.');
|
|
3351
3620
|
const filePath = join(payload.location === 'global' ? agentDir : join(targetDir, '.pi'), 'prompts', `${payload.name}.md`);
|
|
@@ -3361,7 +3630,7 @@ export function createSessionDaemon({
|
|
|
3361
3630
|
|
|
3362
3631
|
const deletePrompt = (payload) => transactResourceMutation(async () => {
|
|
3363
3632
|
if (!payload || typeof payload.resourceId !== 'string') throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template is invalid.');
|
|
3364
|
-
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (
|
|
3633
|
+
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (defaultDirectory());
|
|
3365
3634
|
const catalog = await resourceCatalog(targetDir);
|
|
3366
3635
|
const resource = catalog.prompts.find((item) => item.id === payload.resourceId && item.editable === true);
|
|
3367
3636
|
if (!resource?.filePath) throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi prompt template is not editable.');
|
|
@@ -3437,7 +3706,7 @@ export function createSessionDaemon({
|
|
|
3437
3706
|
if (hasLocation && payload.location !== 'global' && payload.location !== 'project') {
|
|
3438
3707
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The Pi prompt template location is invalid.');
|
|
3439
3708
|
}
|
|
3440
|
-
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (
|
|
3709
|
+
const targetDir = payload.directory ? await resolveDirectory(payload.directory) : (defaultDirectory());
|
|
3441
3710
|
const catalog = await resourceCatalog(targetDir);
|
|
3442
3711
|
const resource = catalog.prompts.find((item) => item.id === payload.resourceId && item.editable === true);
|
|
3443
3712
|
if (!resource?.filePath) throw new SessionDaemonProtocolError('RESOURCE_NOT_FOUND', 'The requested Pi prompt template is not editable.');
|
|
@@ -4259,7 +4528,7 @@ export function createSessionDaemon({
|
|
|
4259
4528
|
throw new SessionDaemonProtocolError('RUNTIME_DISPOSAL_FAILED', 'The Pi session runtime could not be disposed.');
|
|
4260
4529
|
}
|
|
4261
4530
|
const active = runtimeRegistry?.findBySessionId(sessionId);
|
|
4262
|
-
let targetDir = requestedDirectory ? await resolveSessionStoreDirectory(requestedDirectory) : active?.cwd ||
|
|
4531
|
+
let targetDir = requestedDirectory ? await resolveSessionStoreDirectory(requestedDirectory) : active?.cwd || defaultDirectory();
|
|
4263
4532
|
const activeSessionFile = active?.session?.sessionManager?.getSessionFile?.();
|
|
4264
4533
|
if (active) {
|
|
4265
4534
|
if (active.session?.isStreaming) await active.session.abort();
|
|
@@ -4314,7 +4583,7 @@ export function createSessionDaemon({
|
|
|
4314
4583
|
}
|
|
4315
4584
|
};
|
|
4316
4585
|
|
|
4317
|
-
const publishSessionEvent = (sessionId, event, directory =
|
|
4586
|
+
const publishSessionEvent = (sessionId, event, directory = defaultDirectory()) => {
|
|
4318
4587
|
const owningRuntime = runtimeRegistry?.get({ cwd: directory, sessionId })
|
|
4319
4588
|
|| (runtime?.session?.sessionId === sessionId ? runtime : undefined);
|
|
4320
4589
|
switch (event.type) {
|
|
@@ -4802,20 +5071,24 @@ export function createSessionDaemon({
|
|
|
4802
5071
|
sessionId: getSessionState().sessionId,
|
|
4803
5072
|
lastSequence: sequence,
|
|
4804
5073
|
streamEpoch,
|
|
5074
|
+
// Resident Pi runtimes, starting ones included. A server stops an
|
|
5075
|
+
// idle project daemon only when this is zero.
|
|
5076
|
+
residentSessions: (runtimeRegistry?.size ?? 0) + runtimeStartPromises.size,
|
|
4805
5077
|
capabilities: [
|
|
4806
5078
|
// Public stream-lifetime identification: every event, snapshot,
|
|
4807
5079
|
// and health result carries `streamEpoch`, and session read
|
|
4808
5080
|
// responses stamp it so clients can reject stale-epoch data.
|
|
4809
5081
|
'events.streamEpoch',
|
|
4810
5082
|
'runtime.claim', 'runtime.shutdown',
|
|
4811
|
-
'projects.list', 'projects.select', 'sessions.list', 'sessions.create', 'sessions.open', 'sessions.messages', 'sessions.rename', 'sessions.delete',
|
|
5083
|
+
'projects.list', 'projects.select', 'sessions.list', 'sessions.create', 'sessions.open', 'sessions.messages', 'sessions.readPersisted', 'sessions.rename', 'sessions.delete',
|
|
4812
5084
|
'sessions.tree', 'sessions.navigate', 'sessions.fork', 'sessions.clone', 'sessions.prompt',
|
|
4813
5085
|
'sessions.steer', 'sessions.followUp', 'sessions.sendReceipt', 'sessions.pendingInput', 'sessions.abort', 'sessions.setModel',
|
|
4814
|
-
'sessions.setThinking', 'sessions.discardDraft', 'sessions.compact', 'sessions.bash', 'sessions.abortBash', 'engines.list', 'providers.list', 'providers.refresh', 'providers.config.get', 'providers.models.set', 'providers.models.add', 'providers.status', 'providers.login',
|
|
5086
|
+
'sessions.setThinking', 'sessions.discardDraft', 'sessions.compact', 'sessions.bash', 'sessions.abortBash', 'sessions.release', 'engines.list', 'providers.list', 'providers.refresh', 'providers.config.get', 'providers.models.set', 'providers.models.add', 'providers.status', 'providers.hosts', 'providers.oauth.refresh', 'providers.login',
|
|
4815
5087
|
'providers.login.respond', 'providers.login.status', 'providers.logout', 'settings.get', 'settings.set',
|
|
4816
5088
|
'resources.list', 'resources.update', 'resources.prompts.create', 'resources.prompts.update', 'resources.prompts.delete',
|
|
4817
5089
|
'extensions.list', 'extensions.respond', 'extensions.control', 'extensions.draft', 'extensions.palette',
|
|
4818
5090
|
'extensions.config.list', 'extensions.config.set', 'extensions.packages.remove',
|
|
5091
|
+
'extensions.packages.install', 'extensions.packages.update',
|
|
4819
5092
|
'openUrl.publish', 'archive.publish', 'plugins.configure',
|
|
4820
5093
|
'extensions.custom.input', 'extensions.custom.viewport', 'extensions.custom.close', 'extensions.custom.focus', 'extensions.custom.refresh',
|
|
4821
5094
|
],
|
|
@@ -4946,6 +5219,16 @@ export function createSessionDaemon({
|
|
|
4946
5219
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
4947
5220
|
return;
|
|
4948
5221
|
}
|
|
5222
|
+
case 'providers.oauth.refresh': {
|
|
5223
|
+
const result = await refreshOAuthTokens(message.payload);
|
|
5224
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5225
|
+
return;
|
|
5226
|
+
}
|
|
5227
|
+
case 'providers.hosts': {
|
|
5228
|
+
const result = await listProviderHosts(message.payload);
|
|
5229
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5230
|
+
return;
|
|
5231
|
+
}
|
|
4949
5232
|
case 'providers.status': {
|
|
4950
5233
|
const result = await providerStatus(message.payload?.providerId);
|
|
4951
5234
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
@@ -5034,6 +5317,16 @@ export function createSessionDaemon({
|
|
|
5034
5317
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5035
5318
|
return;
|
|
5036
5319
|
}
|
|
5320
|
+
case 'extensions.packages.install': {
|
|
5321
|
+
const result = await installExtensionPackage(message.payload);
|
|
5322
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5323
|
+
return;
|
|
5324
|
+
}
|
|
5325
|
+
case 'extensions.packages.update': {
|
|
5326
|
+
const result = await updateExtensionPackage(message.payload);
|
|
5327
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5328
|
+
return;
|
|
5329
|
+
}
|
|
5037
5330
|
case 'extensions.respond': {
|
|
5038
5331
|
const resolution = await resolveExtensionDialog(message.payload);
|
|
5039
5332
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: resolution });
|
|
@@ -5070,7 +5363,7 @@ export function createSessionDaemon({
|
|
|
5070
5363
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The terminal colours are invalid.');
|
|
5071
5364
|
}
|
|
5072
5365
|
// Pi's theme setting is global; a project's own setting is not read.
|
|
5073
|
-
const settings = createSettingsManager({ cwd:
|
|
5366
|
+
const settings = createSettingsManager({ cwd: defaultDirectory(), agentDir, projectTrusted: false });
|
|
5074
5367
|
// Unreadable settings are a failure, not the system theme: the
|
|
5075
5368
|
// browser keeps PiChamber's colours instead of caching a wrong answer.
|
|
5076
5369
|
if (settings.drainErrors().length > 0) throw new SessionDaemonProtocolError('PI_SETTINGS_INVALID', 'Pi settings could not be read.');
|
|
@@ -5081,7 +5374,7 @@ export function createSessionDaemon({
|
|
|
5081
5374
|
}
|
|
5082
5375
|
case 'extensions.list': {
|
|
5083
5376
|
const requestedExtensionsDir = message.payload?.directory || message.payload?.cwd;
|
|
5084
|
-
const activeRuntime = await ensureRuntime(requestedExtensionsDir ? await resolveDirectory(requestedExtensionsDir) : undefined);
|
|
5377
|
+
const activeRuntime = await ensureRuntime(requestedExtensionsDir ? outsideSandbox(await resolveDirectory(requestedExtensionsDir)) : undefined);
|
|
5085
5378
|
const extensionSession = activeRuntime.session;
|
|
5086
5379
|
const extensionPaths = typeof extensionSession?.extensionRunner?.getExtensionPaths === 'function'
|
|
5087
5380
|
? extensionSession.extensionRunner.getExtensionPaths()
|
|
@@ -5155,7 +5448,7 @@ export function createSessionDaemon({
|
|
|
5155
5448
|
.filter((tracked) => !draftSessionIds.has(tracked?.session?.sessionId))
|
|
5156
5449
|
.map((tracked) => ({
|
|
5157
5450
|
sessionId: tracked?.session?.sessionId,
|
|
5158
|
-
directory: typeof tracked?.cwd === 'string' && tracked.cwd.length > 0 ? tracked.cwd : (
|
|
5451
|
+
directory: typeof tracked?.cwd === 'string' && tracked.cwd.length > 0 ? tracked.cwd : (defaultDirectory()),
|
|
5159
5452
|
busy: tracked?.session?.isStreaming === true
|
|
5160
5453
|
|| tracked?.session?.isCompacting === true
|
|
5161
5454
|
|| activeSessionInputs.has(tracked),
|
|
@@ -5185,6 +5478,15 @@ export function createSessionDaemon({
|
|
|
5185
5478
|
});
|
|
5186
5479
|
return;
|
|
5187
5480
|
}
|
|
5481
|
+
case 'sessions.release': {
|
|
5482
|
+
writeFrame(socket, {
|
|
5483
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
5484
|
+
kind: 'response',
|
|
5485
|
+
requestId: message.requestId,
|
|
5486
|
+
result: await releaseDirectories(message.payload),
|
|
5487
|
+
});
|
|
5488
|
+
return;
|
|
5489
|
+
}
|
|
5188
5490
|
case 'sessions.pendingInput': {
|
|
5189
5491
|
// Daemon-level pending-input state for every session with an open
|
|
5190
5492
|
// request. No arguments, not session-scoped, never routed to
|
|
@@ -5244,6 +5546,15 @@ export function createSessionDaemon({
|
|
|
5244
5546
|
});
|
|
5245
5547
|
return;
|
|
5246
5548
|
}
|
|
5549
|
+
case 'sessions.readPersisted': {
|
|
5550
|
+
const detail = await readPersistedSession(message.payload);
|
|
5551
|
+
const frame = { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: detail };
|
|
5552
|
+
if (Buffer.byteLength(JSON.stringify(frame)) > MAX_FRAME_BYTES) {
|
|
5553
|
+
throw new SessionDaemonProtocolError('DAEMON_RESPONSE_TOO_LARGE', 'The daemon response exceeds the IPC frame limit.');
|
|
5554
|
+
}
|
|
5555
|
+
writeFrame(socket, frame);
|
|
5556
|
+
return;
|
|
5557
|
+
}
|
|
5247
5558
|
case 'sessions.rename': {
|
|
5248
5559
|
await renameSession(message.payload);
|
|
5249
5560
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: {} });
|
|
@@ -5652,6 +5963,7 @@ export function createSessionDaemon({
|
|
|
5652
5963
|
toolPartialBySession.clear();
|
|
5653
5964
|
completedToolTimings.clear();
|
|
5654
5965
|
shutdownRequestedBySession.clear();
|
|
5966
|
+
releaseRequestedBySession.clear();
|
|
5655
5967
|
sendGenerationBySession.clear();
|
|
5656
5968
|
settledSendGenerationBySession.clear();
|
|
5657
5969
|
runningToolsBySession.clear();
|