@pi-chamber/web 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{CommitSection-0zl1puqf.js → CommitSection-MZJqMxUT.js} +1 -1
- package/dist/assets/DiagramEditor-DmDE7OFs.js +1 -0
- package/dist/assets/DiagramView-DjMwKAR1.js +1 -0
- package/dist/assets/{DiffView-BoTz2Zqe.js → DiffView-C3F9al7D.js} +2 -2
- package/dist/assets/{FilesView-CVMNE9Pr.js → FilesView-DzboGeAe.js} +6 -6
- package/dist/assets/{GitView-DnsbCAWl.js → GitView-BfyNIPaR.js} +4 -4
- package/dist/assets/{JsonTreeView-Cn1Mk0Wf.js → JsonTreeView-CGH92Uqo.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-DJKD8tNq.js → MarkdownRendererImpl-DAV0eoSb.js} +2 -2
- package/dist/assets/{PatchDiff-GdGq3IlM.js → PatchDiff-Dux9rNuF.js} +1 -1
- package/dist/assets/{PierreDiffViewer-CdkAUt-S.js → PierreDiffViewer-9imQKDgh.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-BTzVmIop.js → SessionSwitcherContent-BL7f43TK.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-D86K7VFR.js +2 -0
- package/dist/assets/SessionUnreadDot-BfH_vRW9.js +1 -0
- package/dist/assets/SettingsView-CRYyy2nz.js +4 -0
- package/dist/assets/SettingsWindow-CAMrbwzB.js +1 -0
- package/dist/assets/{ToolOutputDialog-BHaf293m.js → ToolOutputDialog-D6AeevDV.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BTMXNcqG.js → ToolPartDiffPreview-Bkjc2WKO.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CRVvv23V.js → VirtualizedFileDiff-B2HHw9NH.js} +4 -4
- package/dist/assets/{WindowsWindowControls-CTtxXnD1.js → WindowsWindowControls-D1V7M-q1.js} +131 -126
- package/dist/assets/collapsible-IV1T6v7c.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-D1I8YrPV.js → computeVirtualFileMetrics-BxQbLxY-.js} +1 -1
- package/dist/assets/contextFileOpenGuard-xvnEr8Go.js +1 -0
- package/dist/assets/index--5Zr-fSk.js +8 -0
- package/dist/assets/index--zDkVFU6.css +1 -0
- package/dist/assets/{index-DbghctxK.js → index-Jd0py_uf.js} +1 -1
- package/dist/assets/{isDiffPlainText-BK9bF1l5.js → isDiffPlainText-BEflvkV4.js} +1 -1
- package/dist/assets/{isFilePlainText-Cua0RCRz.js → isFilePlainText-Byt9dFxj.js} +1 -1
- package/dist/assets/{main-CoA--JT-.js → main-DLedH1mh.js} +7 -7
- package/dist/assets/main-DOqxJvVh.js +2 -0
- package/dist/assets/markdownCore-U_gf0I8i.js +3 -0
- package/dist/assets/miniChat-BkwDDO9w.js +2 -0
- package/dist/assets/mobile-BrrYaFh4.js +2 -0
- package/dist/assets/renderElectronMiniChatApp-IM1L48Ek.js +2 -0
- package/dist/assets/renderMobileApp-ChddJ_wj.js +14 -0
- package/dist/assets/{runtimeSurface-UriLeO95.js → runtimeSurface-D3p7a-uO.js} +1 -1
- package/dist/assets/{useInlineCommentController-5XANmO1k.js → useInlineCommentController-BASCWgsn.js} +2 -2
- package/dist/assets/usePanelSlide-UOz-oH7E.js +56 -0
- package/dist/assets/usePushVisibilityBeacon-DAaVsdjo.js +10 -0
- package/dist/assets/{useSwitcherItems-Cc6Tx-LO.js → useSwitcherItems-CAx_SuxF.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-DxpwplIe.js → vendor-codemirror-language-data-UQYGQ5y2.js} +2 -2
- package/dist/assets/{web-components-g7DKkne_.js → web-components-D08z3xzy.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/pi/small-model-generation.js +14 -1
- package/server/lib/pi/small-model-generation.test.js +20 -5
- 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
package/server/lib/pi/routes.js
CHANGED
|
@@ -7,10 +7,13 @@ import { createPiArchiveStore } from './archive-store.js';
|
|
|
7
7
|
import { createPiAttachmentStore } from './attachment-store.js';
|
|
8
8
|
import { checkForUpdates } from '../package-manager.js';
|
|
9
9
|
import { listPiCustomThemes } from './custom-themes.js';
|
|
10
|
-
import { adoptLegacyUiModelDefaults } from './legacy-ui-model-defaults.js';
|
|
11
10
|
import { createPiSettingsStore } from './settings-store.js';
|
|
12
11
|
import { isPiThinkingLevel } from './thinking-levels.js';
|
|
13
12
|
import { createPiSessionFoldersStore } from './session-folders-store.js';
|
|
13
|
+
import {
|
|
14
|
+
MAX_EXTENSION_APP_HTML_CHARS,
|
|
15
|
+
sanitizeExtensionFormFields,
|
|
16
|
+
} from './extension-protocol.js';
|
|
14
17
|
import { createPiUiSettingsStore } from './ui-settings-store.js';
|
|
15
18
|
|
|
16
19
|
const UNAVAILABLE_CODES = new Set([
|
|
@@ -184,7 +187,7 @@ const projectSessionDetail = (value) => {
|
|
|
184
187
|
if (!item || typeof item !== 'object' || !item.message || !Array.isArray(item.parts)) throw protocolMismatch();
|
|
185
188
|
const message = item.message;
|
|
186
189
|
if (typeof message.id !== 'string' || typeof message.sessionId !== 'string' || typeof message.directory !== 'string'
|
|
187
|
-
|| !Number.isFinite(message.createdAt) || (message.role !== 'user' && message.role !== 'assistant')) throw protocolMismatch();
|
|
190
|
+
|| !Number.isFinite(message.createdAt) || (message.role !== 'user' && message.role !== 'assistant' && message.role !== 'extension')) throw protocolMismatch();
|
|
188
191
|
const projected = {
|
|
189
192
|
id: message.id, sessionId: message.sessionId, directory: message.directory, role: message.role, createdAt: message.createdAt,
|
|
190
193
|
...(typeof message.parentId === 'string' ? { parentId: message.parentId } : {}),
|
|
@@ -200,6 +203,9 @@ const projectSessionDetail = (value) => {
|
|
|
200
203
|
}
|
|
201
204
|
: {}),
|
|
202
205
|
...(message.role === 'assistant' && message.usage && projectUsage(message.usage) ? { usage: projectUsage(message.usage) } : {}),
|
|
206
|
+
...(message.role === 'extension' && typeof message.customType === 'string' ? { customType: message.customType } : {}),
|
|
207
|
+
...(message.role === 'extension' && message.data !== undefined ? { data: message.data } : {}),
|
|
208
|
+
...(message.role === 'extension' && message.details !== undefined ? { details: message.details } : {}),
|
|
203
209
|
};
|
|
204
210
|
const parts = item.parts.map((part) => {
|
|
205
211
|
if (!part || typeof part !== 'object' || typeof part.type !== 'string' || typeof part.id !== 'string' || !Number.isSafeInteger(part.index)) throw protocolMismatch();
|
|
@@ -372,7 +378,9 @@ const projectSessionTree = (value) => {
|
|
|
372
378
|
return {
|
|
373
379
|
entryId: node.entryId,
|
|
374
380
|
...(typeof node.parentId === 'string' ? { parentId: node.parentId } : {}),
|
|
375
|
-
...(typeof node.title === 'string' ? { title: node.title } : {}),
|
|
381
|
+
...(typeof node.title === 'string' ? { title: node.title.slice(0, 256) } : {}),
|
|
382
|
+
...(typeof node.label === 'string' && node.label.length > 0 ? { label: node.label.slice(0, 256) } : {}),
|
|
383
|
+
...(typeof node.labelTimestamp === 'string' ? { labelTimestamp: node.labelTimestamp.slice(0, 64) } : {}),
|
|
376
384
|
updatedAt: node.updatedAt,
|
|
377
385
|
children: node.children.map(projectNode),
|
|
378
386
|
};
|
|
@@ -382,7 +390,56 @@ const projectSessionTree = (value) => {
|
|
|
382
390
|
|
|
383
391
|
const sessionIdFrom = (req) => typeof req.params.sessionId === 'string' && req.params.sessionId.length > 0 ? req.params.sessionId : undefined;
|
|
384
392
|
|
|
385
|
-
|
|
393
|
+
|
|
394
|
+
const projectExtensionPanelActions = (actions) => (
|
|
395
|
+
Array.isArray(actions)
|
|
396
|
+
? actions.filter((action) => action && typeof action === 'object' && typeof action.command === 'string').slice(0, 8)
|
|
397
|
+
: undefined
|
|
398
|
+
);
|
|
399
|
+
|
|
400
|
+
const projectExtensionPanelPayload = (panel) => ({
|
|
401
|
+
id: panel.id.slice(0, 128),
|
|
402
|
+
...(typeof panel.title === 'string' ? { title: panel.title.slice(0, 256) } : {}),
|
|
403
|
+
...(typeof panel.component === 'string' ? { component: panel.component.slice(0, 64) } : {}),
|
|
404
|
+
...(panel.props && typeof panel.props === 'object' && !Array.isArray(panel.props) ? { props: panel.props } : {}),
|
|
405
|
+
...(projectExtensionPanelActions(panel.actions) ? { actions: panel.actions } : {}),
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
const projectExtensionAppPayload = (app) => ({
|
|
409
|
+
appId: app.appId.slice(0, 128),
|
|
410
|
+
...(typeof app.title === 'string' ? { title: app.title.slice(0, 256) } : {}),
|
|
411
|
+
html: typeof app.html === 'string' ? app.html.slice(0, MAX_EXTENSION_APP_HTML_CHARS) : '',
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
const EXTENSION_COMMAND_PATTERN = /^[A-Za-z0-9][A-Za-z0-9:_-]{0,127}$/;
|
|
415
|
+
const OPAQUE_EXTENSION_ID_PATTERN = /^[a-f0-9]{16}$/;
|
|
416
|
+
|
|
417
|
+
export const projectExtensionList = (result) => {
|
|
418
|
+
if (!result || typeof result !== 'object' || typeof result.directory !== 'string'
|
|
419
|
+
|| !Array.isArray(result.extensions) || !Array.isArray(result.commands)) throw protocolMismatch();
|
|
420
|
+
const extensions = result.extensions.map((extension) => {
|
|
421
|
+
if (!extension || typeof extension !== 'object'
|
|
422
|
+
|| typeof extension.id !== 'string' || !OPAQUE_EXTENSION_ID_PATTERN.test(extension.id)
|
|
423
|
+
|| typeof extension.name !== 'string' || extension.name.length === 0 || extension.name.length > 256
|
|
424
|
+
|| extension.name.includes('/') || extension.name.includes('\\')) throw protocolMismatch();
|
|
425
|
+
return { id: extension.id, name: extension.name };
|
|
426
|
+
});
|
|
427
|
+
const commands = result.commands.map((command) => {
|
|
428
|
+
if (!command || typeof command !== 'object'
|
|
429
|
+
|| typeof command.name !== 'string' || !EXTENSION_COMMAND_PATTERN.test(command.name)
|
|
430
|
+
|| (command.description !== undefined && typeof command.description !== 'string')
|
|
431
|
+
|| (command.scope !== undefined && typeof command.scope !== 'string')) throw protocolMismatch();
|
|
432
|
+
return {
|
|
433
|
+
name: command.name,
|
|
434
|
+
...(typeof command.description === 'string' ? { description: command.description.slice(0, 500) } : {}),
|
|
435
|
+
source: 'extension',
|
|
436
|
+
...(typeof command.scope === 'string' ? { scope: command.scope.slice(0, 64) } : {}),
|
|
437
|
+
};
|
|
438
|
+
});
|
|
439
|
+
return { directory: result.directory, extensions, commands };
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
export const projectEventFrame = (frame) => {
|
|
386
443
|
if (!frame || frame.kind !== 'event' || typeof frame.event !== 'string' || !Number.isSafeInteger(frame.sequence)
|
|
387
444
|
|| !frame.payload || typeof frame.payload.sessionId !== 'string' || typeof frame.payload.directory !== 'string') return null;
|
|
388
445
|
const { sessionId, directory } = frame.payload;
|
|
@@ -390,6 +447,35 @@ const projectEventFrame = (frame) => {
|
|
|
390
447
|
switch (frame.event) {
|
|
391
448
|
case 'session.snapshot': {
|
|
392
449
|
const snapshot = frame.payload;
|
|
450
|
+
const snapshotExtensionStatuses = Array.isArray(snapshot.extensionStatuses)
|
|
451
|
+
? snapshot.extensionStatuses.filter((entry) => entry && typeof entry.key === 'string' && typeof entry.text === 'string' && entry.key.length > 0 && entry.key.length <= 128 && entry.text.length <= 1000).slice(0, 50).map((entry) => ({ key: entry.key.slice(0, 128), text: entry.text.slice(0, 1000) }))
|
|
452
|
+
: undefined;
|
|
453
|
+
const snapshotExtensionWidgets = Array.isArray(snapshot.extensionWidgets)
|
|
454
|
+
? snapshot.extensionWidgets.filter((entry) => entry && typeof entry.key === 'string' && Array.isArray(entry.lines) && entry.key.length > 0 && entry.key.length <= 128 && entry.lines.length <= 100).slice(0, 50).map((entry) => ({
|
|
455
|
+
key: entry.key.slice(0, 128),
|
|
456
|
+
lines: entry.lines.filter((line) => typeof line === 'string').map((line) => line.slice(0, 2000)).slice(0, 100),
|
|
457
|
+
...(entry.placement === 'belowEditor' ? { placement: 'belowEditor' } : { placement: 'aboveEditor' }),
|
|
458
|
+
}))
|
|
459
|
+
: undefined;
|
|
460
|
+
const snapshotExtensionDialogs = Array.isArray(snapshot.extensionDialogs)
|
|
461
|
+
? snapshot.extensionDialogs.filter((entry) => entry && typeof entry.requestId === 'string' && typeof entry.method === 'string' && typeof entry.title === 'string').slice(0, 20).map((entry) => ({
|
|
462
|
+
requestId: entry.requestId.slice(0, 512),
|
|
463
|
+
method: ['select', 'confirm', 'input', 'editor', 'form'].includes(entry.method) ? entry.method : 'confirm',
|
|
464
|
+
title: entry.title.slice(0, 512),
|
|
465
|
+
...(typeof entry.message === 'string' ? { message: entry.message.slice(0, 2000) } : {}),
|
|
466
|
+
...(Array.isArray(entry.options) ? { options: entry.options.filter((option) => typeof option === 'string').map((option) => option.slice(0, 256)).slice(0, 20) } : {}),
|
|
467
|
+
...(typeof entry.placeholder === 'string' ? { placeholder: entry.placeholder.slice(0, 512) } : {}),
|
|
468
|
+
...(typeof entry.prefill === 'string' ? { prefill: entry.prefill.slice(0, 10000) } : {}),
|
|
469
|
+
...(Array.isArray(entry.fields) ? { fields: sanitizeExtensionFormFields(entry.fields) } : {}),
|
|
470
|
+
...(Number.isFinite(entry.timeoutMs) ? { timeoutMs: Math.floor(entry.timeoutMs) } : {}),
|
|
471
|
+
}))
|
|
472
|
+
: undefined;
|
|
473
|
+
const snapshotExtensionPanels = Array.isArray(snapshot.extensionPanels)
|
|
474
|
+
? snapshot.extensionPanels.filter((entry) => entry && typeof entry.id === 'string' && entry.id.length > 0).slice(0, 24).map(projectExtensionPanelPayload)
|
|
475
|
+
: undefined;
|
|
476
|
+
const snapshotExtensionApps = Array.isArray(snapshot.extensionApps)
|
|
477
|
+
? snapshot.extensionApps.filter((entry) => entry && typeof entry.appId === 'string' && entry.appId.length > 0 && typeof entry.html === 'string' && entry.html.length > 0).slice(0, 8).map(projectExtensionAppPayload)
|
|
478
|
+
: undefined;
|
|
393
479
|
const lifecycle = ['idle', 'busy', 'retry', 'error', 'interrupted'].includes(snapshot.lifecycle) ? snapshot.lifecycle : 'idle';
|
|
394
480
|
const retry = lifecycle === 'retry' ? projectRetryInfo(snapshot.retry) : null;
|
|
395
481
|
const compaction = projectCompactionInfo(snapshot.compaction);
|
|
@@ -406,6 +492,14 @@ const projectEventFrame = (frame) => {
|
|
|
406
492
|
...(Number.isFinite(snapshot.runStartedAt) ? { runStartedAt: Math.floor(snapshot.runStartedAt) } : {}),
|
|
407
493
|
...(Number.isFinite(snapshot.serverNow) ? { serverNow: Math.floor(snapshot.serverNow) } : {}),
|
|
408
494
|
lastSequence: Number.isSafeInteger(snapshot.lastSequence) ? snapshot.lastSequence : frame.sequence,
|
|
495
|
+
...(snapshotExtensionStatuses ? { extensionStatuses: snapshotExtensionStatuses } : {}),
|
|
496
|
+
...(snapshotExtensionWidgets ? { extensionWidgets: snapshotExtensionWidgets } : {}),
|
|
497
|
+
...(snapshotExtensionDialogs ? { extensionDialogs: snapshotExtensionDialogs } : {}),
|
|
498
|
+
...(snapshotExtensionPanels ? { extensionPanels: snapshotExtensionPanels } : {}),
|
|
499
|
+
...(snapshotExtensionApps ? { extensionApps: snapshotExtensionApps } : {}),
|
|
500
|
+
...(typeof snapshot.extensionTitle === 'string' && snapshot.extensionTitle.length > 0
|
|
501
|
+
? { extensionTitle: snapshot.extensionTitle.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, 256) }
|
|
502
|
+
: {}),
|
|
409
503
|
} } };
|
|
410
504
|
}
|
|
411
505
|
case 'session.lifecycle': {
|
|
@@ -418,6 +512,7 @@ const projectEventFrame = (frame) => {
|
|
|
418
512
|
if (title.length === 0 || title.length > 256) return null;
|
|
419
513
|
return { ...common, payload: { title } };
|
|
420
514
|
}
|
|
515
|
+
case 'session.tree.updated': return { ...common, payload: {} };
|
|
421
516
|
case 'assistant.message.start': return { ...common, payload: { messageId: frame.payload.messageId, role: frame.payload.role, startedAt: frame.payload.startedAt, ...(typeof frame.payload.parentId === 'string' ? { parentId: frame.payload.parentId } : {}), ...(typeof frame.payload.text === 'string' ? { text: frame.payload.text } : {}), ...(frame.payload.model ? { model: frame.payload.model } : {}) } };
|
|
422
517
|
case 'assistant.message.delta':
|
|
423
518
|
case 'assistant.thinking.delta': return { ...common, payload: { messageId: frame.payload.messageId, contentIndex: frame.payload.contentIndex, delta: frame.payload.delta, ...(typeof frame.payload.partId === 'string' ? { partId: frame.payload.partId } : {}) } };
|
|
@@ -470,6 +565,126 @@ const projectEventFrame = (frame) => {
|
|
|
470
565
|
...(Number.isFinite(frame.payload.endedAt) ? { endedAt: frame.payload.endedAt } : {}),
|
|
471
566
|
},
|
|
472
567
|
};
|
|
568
|
+
case 'extension.entry': {
|
|
569
|
+
if (typeof frame.payload.id !== 'string' || frame.payload.id.length === 0 || frame.payload.id.length > 512) return null;
|
|
570
|
+
if (typeof frame.payload.customType !== 'string' || frame.payload.customType.length === 0 || frame.payload.customType.length > 256) return null;
|
|
571
|
+
if (!Number.isFinite(frame.payload.createdAt)) return null;
|
|
572
|
+
return { ...common, payload: { id: frame.payload.id.slice(0, 512), customType: frame.payload.customType.slice(0, 256), ...(frame.payload.data !== undefined ? { data: frame.payload.data } : {}), createdAt: frame.payload.createdAt } };
|
|
573
|
+
}
|
|
574
|
+
case 'extension.message': {
|
|
575
|
+
if (typeof frame.payload.id !== 'string' || frame.payload.id.length === 0 || frame.payload.id.length > 512) return null;
|
|
576
|
+
if (typeof frame.payload.customType !== 'string' || frame.payload.customType.length === 0 || frame.payload.customType.length > 256) return null;
|
|
577
|
+
if (typeof frame.payload.text !== 'string') return null;
|
|
578
|
+
if (!Number.isFinite(frame.payload.createdAt)) return null;
|
|
579
|
+
return { ...common, payload: { id: frame.payload.id.slice(0, 512), customType: frame.payload.customType.slice(0, 256), text: frame.payload.text.slice(0, 50000), ...(frame.payload.details !== undefined ? { details: frame.payload.details } : {}), createdAt: frame.payload.createdAt } };
|
|
580
|
+
}
|
|
581
|
+
case 'extension.notify': {
|
|
582
|
+
if (typeof frame.payload.message !== 'string' || frame.payload.message.length === 0) return null;
|
|
583
|
+
const level = ['info', 'warning', 'error'].includes(frame.payload.level) ? frame.payload.level : 'info';
|
|
584
|
+
return { ...common, payload: { message: frame.payload.message.slice(0, 2000), level } };
|
|
585
|
+
}
|
|
586
|
+
case 'extension.catalog': {
|
|
587
|
+
const providers = frame.payload.providers === true;
|
|
588
|
+
const resources = frame.payload.resources === true;
|
|
589
|
+
const commands = frame.payload.commands === true;
|
|
590
|
+
if (!providers && !resources && !commands) return null;
|
|
591
|
+
return { ...common, payload: { ...(providers ? { providers: true } : {}), ...(resources ? { resources: true } : {}), ...(commands ? { commands: true } : {}) } };
|
|
592
|
+
}
|
|
593
|
+
case 'extension.editor': {
|
|
594
|
+
if (typeof frame.payload.text !== 'string' || frame.payload.text.length > 100_000) return null;
|
|
595
|
+
return { ...common, payload: { text: frame.payload.text } };
|
|
596
|
+
}
|
|
597
|
+
case 'extension.title': {
|
|
598
|
+
if (frame.payload.title !== undefined && typeof frame.payload.title !== 'string') return null;
|
|
599
|
+
const title = typeof frame.payload.title === 'string'
|
|
600
|
+
? frame.payload.title.replace(/[\u0000-\u001f\u007f]/g, ' ').trim().slice(0, 256)
|
|
601
|
+
: '';
|
|
602
|
+
return { ...common, payload: title ? { title } : {} };
|
|
603
|
+
}
|
|
604
|
+
case 'extension.status': {
|
|
605
|
+
if (typeof frame.payload.key !== 'string' || frame.payload.key.length === 0 || frame.payload.key.length > 128) return null;
|
|
606
|
+
if (frame.payload.text !== undefined && typeof frame.payload.text !== 'string') return null;
|
|
607
|
+
return { ...common, payload: { key: frame.payload.key.slice(0, 128), ...(typeof frame.payload.text === 'string' ? { text: frame.payload.text.slice(0, 1000) } : {}) } };
|
|
608
|
+
}
|
|
609
|
+
case 'extension.widget': {
|
|
610
|
+
if (typeof frame.payload.key !== 'string' || frame.payload.key.length === 0 || frame.payload.key.length > 128) return null;
|
|
611
|
+
if (frame.payload.lines !== undefined) {
|
|
612
|
+
if (!Array.isArray(frame.payload.lines)) return null;
|
|
613
|
+
if (frame.payload.lines.length > 100) return null;
|
|
614
|
+
for (const line of frame.payload.lines) if (typeof line !== 'string' || line.length > 2000) return null;
|
|
615
|
+
}
|
|
616
|
+
if (frame.payload.placement !== undefined && frame.payload.placement !== 'aboveEditor' && frame.payload.placement !== 'belowEditor') return null;
|
|
617
|
+
return {
|
|
618
|
+
...common,
|
|
619
|
+
payload: {
|
|
620
|
+
key: frame.payload.key.slice(0, 128),
|
|
621
|
+
...(Array.isArray(frame.payload.lines) ? { lines: frame.payload.lines.map((line) => String(line).slice(0, 2000)).slice(0, 100) } : {}),
|
|
622
|
+
...(frame.payload.placement === 'belowEditor' ? { placement: 'belowEditor' } : frame.payload.placement === 'aboveEditor' ? { placement: 'aboveEditor' } : {}),
|
|
623
|
+
},
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
case 'extension.dialog': {
|
|
627
|
+
if (typeof frame.payload.requestId !== 'string' || frame.payload.requestId.length === 0 || frame.payload.requestId.length > 512) return null;
|
|
628
|
+
if (!['select', 'confirm', 'input', 'editor', 'form'].includes(frame.payload.method)) return null;
|
|
629
|
+
if (typeof frame.payload.title !== 'string' || frame.payload.title.length === 0 || frame.payload.title.length > 512) return null;
|
|
630
|
+
return {
|
|
631
|
+
...common,
|
|
632
|
+
payload: {
|
|
633
|
+
requestId: frame.payload.requestId.slice(0, 512),
|
|
634
|
+
method: frame.payload.method,
|
|
635
|
+
title: frame.payload.title.slice(0, 512),
|
|
636
|
+
...(typeof frame.payload.message === 'string' ? { message: frame.payload.message.slice(0, 2000) } : {}),
|
|
637
|
+
...(Array.isArray(frame.payload.options) ? { options: frame.payload.options.filter((option) => typeof option === 'string').map((option) => option.slice(0, 256)).slice(0, 20) } : {}),
|
|
638
|
+
...(typeof frame.payload.placeholder === 'string' ? { placeholder: frame.payload.placeholder.slice(0, 512) } : {}),
|
|
639
|
+
...(typeof frame.payload.prefill === 'string' ? { prefill: frame.payload.prefill.slice(0, 10000) } : {}),
|
|
640
|
+
...(Array.isArray(frame.payload.fields) ? { fields: sanitizeExtensionFormFields(frame.payload.fields) } : {}),
|
|
641
|
+
...(Number.isFinite(frame.payload.timeoutMs) && frame.payload.timeoutMs >= 0 && frame.payload.timeoutMs <= 600000 ? { timeoutMs: Math.floor(frame.payload.timeoutMs) } : {}),
|
|
642
|
+
},
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
case 'extension.dialog.dismiss': {
|
|
646
|
+
if (typeof frame.payload.requestId !== 'string' || frame.payload.requestId.length === 0 || frame.payload.requestId.length > 512) return null;
|
|
647
|
+
if (!['answered', 'cancelled', 'timeout', 'aborted', 'session-closed', 'daemon-stopped'].includes(frame.payload.reason)) return null;
|
|
648
|
+
return {
|
|
649
|
+
...common,
|
|
650
|
+
payload: {
|
|
651
|
+
requestId: frame.payload.requestId.slice(0, 512),
|
|
652
|
+
reason: frame.payload.reason,
|
|
653
|
+
},
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
case 'extension.ui': {
|
|
657
|
+
if (typeof frame.payload.id !== 'string' || frame.payload.id.length === 0 || frame.payload.id.length > 128) return null;
|
|
658
|
+
const hasBody = typeof frame.payload.component === 'string'
|
|
659
|
+
|| typeof frame.payload.title === 'string'
|
|
660
|
+
|| Array.isArray(frame.payload.actions);
|
|
661
|
+
const removed = frame.payload.removed === true || !hasBody;
|
|
662
|
+
return {
|
|
663
|
+
...common,
|
|
664
|
+
payload: removed
|
|
665
|
+
? { id: frame.payload.id.slice(0, 128), removed: true }
|
|
666
|
+
: projectExtensionPanelPayload(frame.payload),
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
case 'extension.app': {
|
|
670
|
+
if (typeof frame.payload.appId !== 'string' || frame.payload.appId.length === 0 || frame.payload.appId.length > 128) return null;
|
|
671
|
+
const html = typeof frame.payload.html === 'string' ? frame.payload.html : '';
|
|
672
|
+
if (html.length === 0) return { ...common, payload: { appId: frame.payload.appId.slice(0, 128), removed: true } };
|
|
673
|
+
if (html.length > MAX_EXTENSION_APP_HTML_CHARS) return null;
|
|
674
|
+
return { ...common, payload: projectExtensionAppPayload({ ...frame.payload, html }) };
|
|
675
|
+
}
|
|
676
|
+
case 'extension.error': {
|
|
677
|
+
if (typeof frame.payload.source !== 'string' || frame.payload.source.length === 0 || frame.payload.source.length > 512) return null;
|
|
678
|
+
if (typeof frame.payload.message !== 'string' || frame.payload.message.length === 0) return null;
|
|
679
|
+
return {
|
|
680
|
+
...common,
|
|
681
|
+
payload: {
|
|
682
|
+
source: frame.payload.source.slice(0, 512),
|
|
683
|
+
...(typeof frame.payload.event === 'string' ? { event: frame.payload.event.slice(0, 128) } : {}),
|
|
684
|
+
message: frame.payload.message.slice(0, 5000),
|
|
685
|
+
},
|
|
686
|
+
};
|
|
687
|
+
}
|
|
473
688
|
default: return null;
|
|
474
689
|
}
|
|
475
690
|
};
|
|
@@ -780,7 +995,7 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
780
995
|
app.get('/api/pi/settings', async (_req, res) => {
|
|
781
996
|
try {
|
|
782
997
|
const pi = projectPiSettings(await getDaemonRuntime(getPiSessionDaemonRuntime).request('settings.get'));
|
|
783
|
-
const pichamber = await
|
|
998
|
+
const pichamber = await settingsStore.read();
|
|
784
999
|
res.json({ ...pi, pichamber });
|
|
785
1000
|
} catch (error) {
|
|
786
1001
|
writeDaemonError(res, error);
|
|
@@ -987,6 +1202,64 @@ export const registerPiRuntimeRoutes = (app, {
|
|
|
987
1202
|
}
|
|
988
1203
|
});
|
|
989
1204
|
|
|
1205
|
+
app.get('/api/pi/extensions', async (req, res) => {
|
|
1206
|
+
const directory = req.query?.directory;
|
|
1207
|
+
if (directory !== undefined && typeof directory !== 'string') {
|
|
1208
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
try {
|
|
1212
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.list', {
|
|
1213
|
+
...(typeof directory === 'string' && directory.length > 0 ? { directory } : {}),
|
|
1214
|
+
});
|
|
1215
|
+
res.json(projectExtensionList(result));
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
writeDaemonError(res, error);
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1221
|
+
app.post('/api/pi/extensions/respond', async (req, res) => {
|
|
1222
|
+
const body = req.body;
|
|
1223
|
+
if (!body || typeof body !== 'object' || Array.isArray(body)
|
|
1224
|
+
|| typeof body.requestId !== 'string' || body.requestId.length === 0
|
|
1225
|
+
|| (body.directory !== undefined && typeof body.directory !== 'string')) {
|
|
1226
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1227
|
+
return;
|
|
1228
|
+
}
|
|
1229
|
+
let values;
|
|
1230
|
+
if (body.values !== undefined) {
|
|
1231
|
+
if (!body.values || typeof body.values !== 'object' || Array.isArray(body.values)) {
|
|
1232
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1233
|
+
return;
|
|
1234
|
+
}
|
|
1235
|
+
values = {};
|
|
1236
|
+
for (const [key, entry] of Object.entries(body.values)) {
|
|
1237
|
+
if (typeof key !== 'string' || key.length === 0 || key.length > 128 || typeof entry !== 'string' || entry.length > 8_000) {
|
|
1238
|
+
res.status(400).json({ error: { code: 'INVALID_ARGUMENT' } });
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
values[key] = entry;
|
|
1242
|
+
}
|
|
1243
|
+
}
|
|
1244
|
+
try {
|
|
1245
|
+
const result = await getDaemonRuntime(getPiSessionDaemonRuntime).request('extensions.respond', {
|
|
1246
|
+
requestId: body.requestId,
|
|
1247
|
+
...(typeof body.directory === 'string' && body.directory.length > 0 ? { directory: body.directory } : {}),
|
|
1248
|
+
...(body.cancelled === true ? { cancelled: true } : {}),
|
|
1249
|
+
...(body.confirmed === true ? { confirmed: true } : {}),
|
|
1250
|
+
...(typeof body.value === 'string' ? { value: body.value } : {}),
|
|
1251
|
+
...(values ? { values } : {}),
|
|
1252
|
+
});
|
|
1253
|
+
if (!result || typeof result !== 'object' || result.resolved !== true) {
|
|
1254
|
+
res.status(404).json({ error: { code: 'EXTENSION_DIALOG_NOT_PENDING' } });
|
|
1255
|
+
return;
|
|
1256
|
+
}
|
|
1257
|
+
res.status(204).end();
|
|
1258
|
+
} catch (error) {
|
|
1259
|
+
writeDaemonError(res, error);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
|
|
990
1263
|
app.get('/api/pi/sessions/:sessionId/tree', async (req, res) => {
|
|
991
1264
|
const result = await requestSessionOperation(req, res, getPiSessionDaemonRuntime, 'sessions.tree');
|
|
992
1265
|
if (result !== undefined) res.json(projectSessionTree(result));
|
|
@@ -276,31 +276,6 @@ describe('Pi runtime route', () => {
|
|
|
276
276
|
await expect((await fetch(`${base}/defaults`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ defaultThinking: 'low' }) })).json()).resolves.toEqual({ pichamber: { version: 1, defaultThinking: 'low' } });
|
|
277
277
|
});
|
|
278
278
|
|
|
279
|
-
it('adopts leftover UI model defaults into the sidecar on settings read', async () => {
|
|
280
|
-
const settingsStore = {
|
|
281
|
-
read: async () => ({ version: 1 }),
|
|
282
|
-
update: async (patch) => ({ version: 1, ...patch }),
|
|
283
|
-
};
|
|
284
|
-
const uiSettingsStore = {
|
|
285
|
-
read: async () => ({ defaultModel: 'openai/gpt-5', themeMode: 'dark' }),
|
|
286
|
-
write: async () => ({}),
|
|
287
|
-
};
|
|
288
|
-
const runtime = {
|
|
289
|
-
request: async (command) => {
|
|
290
|
-
if (command === 'settings.get') return { global: {}, project: { trusted: false } };
|
|
291
|
-
throw new Error(`Unexpected command ${command}`);
|
|
292
|
-
},
|
|
293
|
-
};
|
|
294
|
-
const app = express();
|
|
295
|
-
app.use(express.json());
|
|
296
|
-
registerPiRuntimeRoutes(app, { getPiSessionDaemonRuntime: () => runtime, settingsStore, uiSettingsStore });
|
|
297
|
-
server = await listen(app);
|
|
298
|
-
await expect((await fetch(`http://127.0.0.1:${server.address().port}/api/pi/settings`)).json()).resolves.toEqual({
|
|
299
|
-
pi: { global: {}, project: { trusted: false } },
|
|
300
|
-
pichamber: { version: 1, defaultModel: { providerId: 'openai', modelId: 'gpt-5' } },
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
|
|
304
279
|
it('projects native resources without exposing daemon filesystem paths', async () => {
|
|
305
280
|
const calls = [];
|
|
306
281
|
const runtime = {
|
|
@@ -6,8 +6,11 @@ This module is the Pi-owned session-daemon foundation. A detached local daemon p
|
|
|
6
6
|
|
|
7
7
|
## Entrypoints
|
|
8
8
|
|
|
9
|
+
- `../extension-protocol.js` owns the bounded form descriptor and response validation shared by the private daemon bridge and public route projection, so both sides of the IPC seam accept the same field contract.
|
|
10
|
+
- `extension-bridge.js` owns extension UI bindings, pending dialog lifecycle, normalized status/widget/panel/app state, snapshot projection, and extension event publication. `session-daemon.js` supplies runtime lookup, publication, redaction, and directory dependencies through its narrow factory interface.
|
|
9
11
|
- `session-daemon.js`
|
|
10
|
-
- `createPiSessionRuntime({ cwd, agentDir })` creates a persistent Pi runtime using the selected server-side cwd and Pi agent directory. It uses Pi's normal settings, credentials, models, sessions, skills, prompts,
|
|
12
|
+
- `createPiSessionRuntime({ cwd, agentDir })` creates a persistent Pi runtime using the selected server-side cwd and Pi agent directory. It uses Pi's normal settings, credentials, models, sessions, skills, prompts, context discovery, and native extensions. Every runtime creation binds extensions through `session.bindExtensions()` in rpc-like mode with a daemon-owned UI bridge, so pi extensions load exactly as they do under the Pi CLI's RPC mode. Sessions created outside PiChamber (Pi CLI or any other writer of the cwd-scoped JSONL directory) are the same records: `sessions.list`/`open` hydrate from `getEntries()`, then overlay the live `session.messages` / `state.streamingMessage` turn while `isStreaming` is true, including an unpersisted user prompt that has not flushed to JSONL yet. A later prompt must overlay live turns onto that log rather than replace it. An unmatched `toolCall` projects as `running` only while `isStreaming` is authoritative; the same unmatched call in an idle persisted turn projects as a timestamped interruption error instead of malformed `completed` state. `getSession` also reports `isStreaming` and `lifecycle` so a restarted UI can restore the working/tooling state without waiting for the next token.
|
|
13
|
+
- Extension bridging: blocking dialogs (`ctx.ui.select/confirm/input/editor`, plus the PiChamber-specific `ctx.ui.form` which resolves with a values object keyed by field id) publish an `extension.dialog` event and stay pending until answered by the `extensions.respond` private command; every answer, timeout, abort, session close, or daemon stop publishes an authoritative `extension.dialog.dismiss` event before resolving the extension so every connected client removes the modal (timeouts resolve defaults, abort resolves cancellation, form answers travel as a sanitized `values` record and are rejected unless required fields, number bounds, select options, and checkbox values match the pending form); fire-and-forget calls publish `extension.notify`, `extension.status`, `extension.widget`, session-scoped `extension.editor`, and `extension.title`; extension errors publish `extension.error`; appended custom entries and displayed custom messages publish `extension.entry` / `extension.message`. `pichamber.ui` entries with a stable `id` are additionally mirrored into normalized `extension.ui` panel events (latest wins per id, `removed: true` unregisters) and `pichamber.app` entries into sandboxed `extension.app` app surfaces; both are kept in per-session maps and replayed through `session.snapshot` so reconnects rebuild live panels. TUI-only component replacement, footers, and themes remain intentional no-ops; standard RPC editor replacement and window titles are projected to the focused browser session. Pending dialogs are cancelled when the owning runtime hits idle disposal or daemon stop so no extension thread blocks forever. Unknown dialog responses return `{ resolved: false }` rather than throwing so a stale client retry cannot tear down the shared socket.
|
|
11
14
|
- `createSessionDaemon(options)` starts/stops the authenticated local socket daemon and validates its endpoint and setup inputs.
|
|
12
15
|
- `daemon-process.js` is the detached private-process entrypoint. It reads the daemon credential from its owner-only sidecar, starts the socket, writes non-secret identity state only after readiness, and removes only its own state on signal shutdown.
|
|
13
16
|
- `ipc-client.js` is the server-only authenticated request client. It owns JSONL framing and never exposes endpoint or credential values to callers.
|
|
@@ -25,10 +28,10 @@ This module is the Pi-owned session-daemon foundation. A detached local daemon p
|
|
|
25
28
|
- The public health route deliberately whitelists its response fields. It never returns a daemon endpoint, credential, PID, cwd, agent directory, or transcript data. Public transcript and event projections preserve daemon-redacted assistant error messages so the UI can distinguish provider/runtime failures instead of reducing every failure to `ASSISTANT_ERROR`.
|
|
26
29
|
- A client must send an `authenticate` frame carrying the host-private daemon credential before it can issue a request. Credentials are never logged or returned.
|
|
27
30
|
- Frames are LF-delimited JSON. They have a 1 MiB maximum buffered size. A malformed, oversized, unauthenticated, or invalid request closes the connection.
|
|
28
|
-
- The private core commands are `runtime.health`, `projects.list/select`, `providers.list/config.get/models.set/status/login/login.respond/login.status/logout`, `settings.get/set`, `resources.list/update/prompts.create/prompts.delete`, and session list/create/open/rename/delete/tree/navigate/fork/clone/prompt/steer/followUp/abort/model/thinking/compact operations. Resource lists use opaque IDs and never disclose server paths. Only top-level Pi prompt templates and applicable AGENTS.md sources are editable; package/path resources and skills are browse-only. Resource writes are rejected while a session streams, use an atomic replace, then recreate the idle runtime. Project trust changes are persisted in Pi trust.json and likewise recreate an idle runtime; extensions
|
|
31
|
+
- The private core commands are `runtime.health`, `projects.list/select`, `providers.list/config.get/models.set/status/login/login.respond/login.status/logout`, `settings.get/set`, `resources.list/update/prompts.create/prompts.delete`, `extensions.list/respond`, and session list/create/open/rename/delete/tree/navigate/fork/clone/prompt/steer/followUp/abort/model/thinking/compact operations. Resource lists use opaque IDs and never disclose server paths. Only top-level Pi prompt templates and applicable AGENTS.md sources are editable; package/path resources and skills are browse-only. Resource writes are rejected while a session streams, use an atomic replace, then recreate the idle runtime. Project trust changes are persisted in Pi trust.json and likewise recreate an idle runtime; project-local extensions load through Pi's own trust flow once trust is resolved. Provider login submits API keys only across authenticated private IPC or brokers Pi's OAuth/device/manual-code interaction; public projections contain only opaque login IDs, prompts, URLs/device codes, model catalog/configuration, and stable states, never credentials or write-only headers. `providers.models.set` is rejected while a session streams, atomically persists Pi's `models.json`, then rehydrates the idle runtime so the catalog is authoritative immediately. `providers.list` projects only catalog and authentication-status metadata, including Pi-supported `thinkingLevels` (`null` map entries hidden, `xhigh`/`max` opt-in). Session thinking overrides are clamped to the live model's supported levels. `sessions.list` checks each cwd JSONL header (not the full transcript) so a project with large session logs cannot spend tens of seconds on startup. SDK `SessionManager.list` is not used for that path; `listPiSessionJsonlDirectory` reads a header, a bounded prefix for the first user prompt, and a tail for the latest rename. Concurrent lists of the same directory share one in-flight result. Concurrent `sessions.open` of the same id share one in-flight runtime create; a duplicate that finishes later disposes itself and returns the registered runtime instead of `SESSION_RUNTIME_CONFLICT`. Full-file JSONL validation stays on open of a chosen session. The browser explicitly selects an existing user-chosen project directory before listing it; the daemon's startup cwd is an internal fallback, not a user-visible default project. Unnamed persisted sessions use their first prompt as a readable list title when available. `sessions.open` and `getSession` project the last assistant `provider`/`model`/`thinkingLevel` onto the session record so reopening a chat keeps that cache identity. Session selection validates a persisted JSONL path before Pi opens it; inactive mutations are never directed by a browser-supplied path. `sessions.open` resolves an id by Pi's `timestamp_<id>.jsonl` filename first so a missing deep link 404s without listing or fully reading every transcript in every cwd; SDK list and header scan remain the fallback for non-standard names. Directory-wide JSONL checks on list/create/startup are header-only; full-file validation stays on open of a chosen transcript. Attachment paths originate in the server-local upload map and cross only private IPC into Pi's tool context. Pi may persist or echo those paths in its authoritative JSONL transcript, so every public projection redacts them recursively: session titles/previews, user and assistant text/thinking, tool arguments, errors, snapshots, and live message events never expose the server-local path. Persisted projection first checks for the attachment marker, then redacts matching tokens with a delimiter scan whose work stays linear for large encoded strings and tool payloads. The daemon maps Pi message lifecycle, deltas, tools, queue changes, model/thinking, compaction, interruption state, and session title updates (`session.updated` on create-with-title, first-prompt auto-title, and rename) to canonical events. Pi `model_select`, `thinking_level_changed`, and `session_info_changed` events are authoritative for model, thinking, and session-name changes made by extensions, the TUI, or another client. The bridge observes Pi provider registration and label writes because Pi 0.84.1 emits no corresponding session events: provider mutations publish a catalog invalidation, and label mutations invalidate the bounded session-tree projection. `ctx.reload()` clears old extension UI state, reloads Pi resources, and invalidates provider/resource/command catalogs. `ctx.shutdown()` disposes only the requesting idle session runtime after its command or turn settles; it never stops the shared daemon or unrelated sessions. Compaction events preserve Pi's manual/threshold/overflow reason, active/retrying/terminal phase, retry timing, redacted failure, compact-and-retry intent, and pre/post token estimates. The latest state is included in `getSession` and reconnect snapshots; after daemon restart, the latest persisted Pi `CompactionEntry` restores completed feedback without treating history as live work. Tool events carry redacted input arguments, cumulative partial-output snapshots, final output, error text, renderer metadata (edit diffs, truncation notes), and start/end timestamps. Pi loads skills with the ordinary `read` tool. The daemon matches those read paths against the active runtime's authoritative `resourceLoader.getSkills()` catalog and adds path-free `metadata.pichamber.skill.name` for live events, hydrated history, and reconnect snapshots. PiChamber uses that metadata for its compact Skill row and Settings navigation; an arbitrary file named `SKILL.md` remains a normal read. Persisted `toolResult` entries merge into their assistant `toolCall` parts as output/error/end time so hydrated sessions render complete tool cards; tool-result entries never surface as standalone messages. Assistant message projections and start events carry the owning user-message id so the restored turn renderer can group and display replies; all assistant entries in a tool loop and every retry/compaction continuation remain attached to the latest user turn until `agent_settled` closes the run. Assistant message projections also pass through Pi's per-turn `Usage` (input, output, cacheRead, cacheWrite, totalTokens, and the same five numeric cost fields). The daemon sanitizes the raw payload through `projectUsage` before publication: every numeric must be finite and non-negative, the whole object is omitted when any field is missing or wrong type, and unknown keys are never copied. The `assistant.message.end` event carries the same sanitized usage so the last turn updates without waiting for a full `getSession` refetch. The public route whitelist re-applies the same sanitizer on each projection so a stale or malformed payload from a different daemon version cannot surface as `NaN` or `Infinity` in the reducer.
|
|
29
32
|
- Live `message_start` events use daemon-generated browser message IDs because Pi has not appended the corresponding session entry yet. Pi agent-core emits streaming assistant starts as shallow copies, not as the finalized object it later persists. At `message_end`, `message-entry-aliases.js` therefore rebinds the synthetic ID to the finalized event object, then maps that object by identity to Pi's appended entry in a microtask. `sessions.navigate` and `sessions.fork` resolve the mapping after stripping any part suffix. Alias keys include cwd and session ID, survive idle runtime disposal, and clear only on explicit session deletion or daemon shutdown. Hydrated message projections continue to use the Pi entry ID directly.
|
|
30
33
|
- Each event and reconnect snapshot has a monotonic sequence. A reconnect receives a bounded contiguous replay after its cursor when available, otherwise an authoritative `session.snapshot`; unavailable runtimes are not represented as empty sessions.
|
|
31
|
-
- Prompt, steer, and follow-up requests acknowledge acceptance immediately after Pi accepts the call; the daemon owns the still-running send promise and publishes any asynchronous rejection as `session.error`. Manual compact requests likewise acknowledge startup instead of holding the public/private request open for the summarization call; the daemon-owned promise reports its outcome through `session.compaction`. A second compact request while Pi is compacting fails as `SESSION_BUSY`, and optional `/compact` instructions pass to `AgentSession.compact(customInstructions)`. A later prompt on the same session invalidates an older send rejection so it cannot error the new turn. If the rejected send left Pi streaming, the daemon aborts it. Steer/follow-up against an idle session starts a new prompt instead of `SESSION_NOT_RUNNING`. Agent and compaction completion are never held behind the 30-second public/private request budgets. Pi retryable provider failures remain live: an `agent_end` with `willRetry` does not publish terminal `session.error`, and `auto_retry_start` projects Pi's attempt, next-attempt time, and redacted error text through `session.lifecycle: retry`. Retry metadata is retained in reconnect and `getSession` snapshots until the next `agent_start` begins the attempt. `agent_settled` remains the authoritative idle boundary after retry success, exhaustion, or cancellation and clears the run's user/assistant ownership.
|
|
34
|
+
- Prompt, steer, and follow-up requests acknowledge acceptance immediately after Pi accepts the call; the daemon owns the still-running send promise and publishes any asynchronous rejection as `session.error`. An extension command may resolve without starting an agent turn, so completion of its non-streaming prompt promise publishes the idle lifecycle boundary that Pi does not emit as `agent_settled`. Manual compact requests likewise acknowledge startup instead of holding the public/private request open for the summarization call; the daemon-owned promise reports its outcome through `session.compaction`. A second compact request while Pi is compacting fails as `SESSION_BUSY`, and optional `/compact` instructions pass to `AgentSession.compact(customInstructions)`. A later prompt on the same session invalidates an older send rejection so it cannot error the new turn. If the rejected send left Pi streaming, the daemon aborts it. Steer/follow-up against an idle session starts a new prompt instead of `SESSION_NOT_RUNNING`. Agent and compaction completion are never held behind the 30-second public/private request budgets. Pi retryable provider failures remain live: an `agent_end` with `willRetry` does not publish terminal `session.error`, and `auto_retry_start` projects Pi's attempt, next-attempt time, and redacted error text through `session.lifecycle: retry`. Retry metadata is retained in reconnect and `getSession` snapshots until the next `agent_start` begins the attempt. `agent_settled` remains the authoritative idle boundary after retry success, exhaustion, or cancellation and clears the run's user/assistant ownership.
|
|
32
35
|
- Registry keys combine the SDK session ID with its cwd. A replacement subscription is rebound to the replacement session so old-session events cannot be published under the new identity. A collision is a visible error; it never replaces or disposes an unrelated runtime.
|
|
33
36
|
- After `agent_settled` or a terminal compaction that will not resume the turn, the daemon disposes an idle runtime after five minutes (injectable for tests). Disposal never deletes Pi JSONL; the daemon remembers the selected session file and recreates that runtime on the next private prompt. Agent and compaction starts cancel pending disposal, and the timer refuses to dispose a session while `isStreaming` or `isCompacting` is authoritative.
|
|
34
37
|
- A startup validation failure writes only a stable failure code to the owner-only non-secret state sidecar. It never records a transcript, session path, or credential. The supervisor surfaces that code as unavailable instead of claiming an empty or idle session.
|