@pi-chamber/web 1.0.7 → 1.0.8-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/AgentsSurface-BmHImX8m.js +1 -0
- package/dist/assets/ChoicesArtifact-C71fGOm2.js +1 -0
- package/dist/assets/DiagramView-BZQxoiZu.js +1 -0
- package/dist/assets/{DiffView-BxW6BuOC.js → DiffView-C70pbgk-.js} +6 -6
- package/dist/assets/FileSaveConflictDialog-Cu8c3gBV.js +3 -0
- package/dist/assets/FilesView-nFJYEdRw.js +6 -0
- package/dist/assets/GitHubDetailScaffold-Jvv_tgbl.js +11 -0
- package/dist/assets/GitHubLinkPicker-BXD2ODRi.js +1 -0
- package/dist/assets/GitHubListPrimitives-BWI706F0.js +1 -0
- package/dist/assets/{GitView-DD33ngnM.js → GitView-MIDG5RYW.js} +5 -5
- package/dist/assets/{IssuesSurface-BAY_eyX5.js → IssuesSurface-uNlozeu0.js} +2 -2
- package/dist/assets/{JsonTreeView-DpXbUrAl.js → JsonTreeView-CSLsTriz.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cn63lAmn.js → MarkdownRendererImpl-Cs-7BfWi.js} +3 -3
- package/dist/assets/PatchDiff-axbsnbTJ.js +1 -0
- package/dist/assets/PierreDiffViewer-lwn6w_5w.js +147 -0
- package/dist/assets/PullRequestsSurface-o_AXDjbO.js +2 -0
- package/dist/assets/{SessionSwitcherContent-CscYekC1.js → SessionSwitcherContent-C4CMlcbv.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-DCBVuCoo.js +2 -0
- package/dist/assets/SessionUnreadDot-DyeIrsro.js +1 -0
- package/dist/assets/SettingsView-BHBpt2Um.js +7 -0
- package/dist/assets/{SettingsWindow-gxjULdm1.js → SettingsWindow-Cb4st5y5.js} +1 -1
- package/dist/assets/{StickyHorizontalScrollbar-DNsbTLS7.js → StickyHorizontalScrollbar-CMbTn5WQ.js} +1 -1
- package/dist/assets/SubagentsArtifact-BzeMEoFP.js +1 -0
- package/dist/assets/ToolOutputDialog-BP2mOWdV.js +8 -0
- package/dist/assets/ToolPartDiffPreview-D49XBR9b.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-BrbPymTL.js → VirtualizedFileDiff-CLgDONEQ.js} +4 -4
- package/dist/assets/{Virtualizer-okhy9Aq3.js → Virtualizer-PxblpQn6.js} +1 -1
- package/dist/assets/VisualFrame-CJrAvWSo.js +22 -0
- package/dist/assets/VisualsArtifact-DqLGgU-Q.js +1 -0
- package/dist/assets/{collapsible-D6qdoq7-.js → collapsible-BeyKtQGB.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-G4csGiKs.js → computeVirtualFileMetrics-DmO6H8u6.js} +2 -2
- package/dist/assets/contextFileOpenGuard-DOK251YW.js +1 -0
- package/dist/assets/{fileTreeStatus-Bskhj4qT.js → fileTreeStatus-CnzR7kxA.js} +2 -2
- package/dist/assets/gitStatusPredicates-4kPg2t6j.js +1 -0
- package/dist/assets/githubLink-QvaLfNNT.js +10 -0
- package/dist/assets/{index-I2QYqABE.js → index-B2v0_mez.js} +8 -8
- package/dist/assets/index-D3F4JrPN.css +1 -0
- package/dist/assets/{index-ComwtfT4.js → index-DMX9wT1Z.js} +1 -1
- package/dist/assets/{main-DoiadX0a.js → main-BW9J3Y72.js} +2 -2
- package/dist/assets/main-BirYxac2.js +137 -0
- package/dist/assets/{markdownCore-DczkEluO.js → markdownCore-CxmcPur8.js} +2 -2
- package/dist/assets/miniChat-BRB11eEs.js +2 -0
- package/dist/assets/{mobile-BucKVm1P.js → mobile-DJZYYCuB.js} +2 -2
- package/dist/assets/{nativeFileSave-Cp9i5QGd.js → nativeFileSave-B6QpoPRn.js} +1 -1
- package/dist/assets/pi-session-focus-preference-PWoh3LNA.js +9 -0
- package/dist/assets/{renderDiffWithHighlighter-PL82AR81.js → renderDiffWithHighlighter-C48T6YFJ.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-N-BQdJl0.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-CYgfbA4F.js → renderFileWithHighlighter-8Kt2MyTN.js} +1 -1
- package/dist/assets/{renderMobileApp-Bp74b_Lo.js → renderMobileApp-B7cT7m5b.js} +3 -3
- package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +62 -0
- package/dist/assets/runtimeSurface-kIEoYsPP.js +1 -0
- package/dist/assets/selection-BTEdLRVK.js +1 -0
- package/dist/assets/useAppFontEffects-EcTZ_I_I.js +225 -0
- package/dist/assets/useGitHubRemoteSearch-DIBHNu8r.js +1 -0
- package/dist/assets/useSwitcherItems-DfLbfX37.js +1 -0
- package/dist/assets/{vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js → vendor-aparajita-capacitor-secure-storage-DUoR8t1G.js} +1 -1
- package/dist/assets/{vendor-base-ui-BCqPBzDj.js → vendor-base-ui-DE6jnTiC.js} +1 -1
- package/dist/assets/{vendor-boot-3SaHYVb1.js → vendor-boot-D-KEJjsM.js} +29 -29
- package/dist/assets/{vendor-capacitor-app-NbQ-WiPS.js → vendor-capacitor-app-CO5jS31X.js} +1 -1
- package/dist/assets/{vendor-capacitor-keyboard-CgrHt8iN.js → vendor-capacitor-keyboard-335osRpd.js} +1 -1
- package/dist/assets/{vendor-capacitor-status-bar-CWt0OF5t.js → vendor-capacitor-status-bar-lB9y4H9d.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-WThuuUAz.js → vendor-codemirror-autocomplete-BKvJ8PfM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-BbLGCxF6.js → vendor-codemirror-lang-angular-wjCUD0bM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-Cceks-9O.js → vendor-codemirror-lang-cpp-LJzlG8sJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-D1wpUg3Z.js → vendor-codemirror-lang-css-DoEEdEpW.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-Cv0zXHHM.js → vendor-codemirror-lang-go-DexsLPb8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-DbL8oT9H.js → vendor-codemirror-lang-html-h25V-Hp5.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CNugenuC.js → vendor-codemirror-lang-java-D8xoT8cv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Bx_FIyZF.js → vendor-codemirror-lang-javascript-DF3GDYje.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-DDGjB3Zq.js → vendor-codemirror-lang-jinja-BboTHFdn.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-DIvqf9Pb.js → vendor-codemirror-lang-json-DCqvG1nE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-D8r9dGG1.js → vendor-codemirror-lang-less-B8ZrSKJM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-B24mguYi.js → vendor-codemirror-lang-liquid-DF9S5m5F.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-v3yG2sbf.js → vendor-codemirror-lang-markdown-6BNbCEPe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-BcZGalqy.js → vendor-codemirror-lang-php-CQwAz1Hd.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-b-JqEwQy.js → vendor-codemirror-lang-python-DQym-8Tx.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-B1uZxDW-.js → vendor-codemirror-lang-rust-DknzOTkO.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-DqPrngKp.js → vendor-codemirror-lang-sass-dB0Rm5HI.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-UyCnpt-k.js → vendor-codemirror-lang-sql-CCQUnnD-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-xDwYkovV.js → vendor-codemirror-lang-vue-h1M5bF00.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-CF3169p_.js → vendor-codemirror-lang-wast-DWgtlGfu.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-FCtVhuOb.js → vendor-codemirror-lang-xml-DncwoCUY.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-g0sPmAnv.js → vendor-codemirror-lang-yaml-C7QkS5ER.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B03xgzP2.js → vendor-codemirror-language-data-BUZIlm3G.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-Dw3Wpu15.js → vendor-codemirror-search-BlDCaCMK.js} +1 -1
- package/dist/assets/{vendor-lezer-cpp-Cu3E-KUI.js → vendor-lezer-cpp-B4JK1BC1.js} +1 -1
- package/dist/assets/{vendor-lezer-css-Cb8vp67u.js → vendor-lezer-css-DRxDmhcy.js} +1 -1
- package/dist/assets/{vendor-lezer-go-BTsIaOm7.js → vendor-lezer-go-DsUgfmxi.js} +1 -1
- package/dist/assets/{vendor-lezer-html-UQMsUwj-.js → vendor-lezer-html-qr9pUPmM.js} +1 -1
- package/dist/assets/{vendor-lezer-java-BIWrFrAx.js → vendor-lezer-java-6UyNiQiB.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-BH2Etgoy.js → vendor-lezer-javascript-CUdJ0VGA.js} +1 -1
- package/dist/assets/{vendor-lezer-json-CE-QUCwM.js → vendor-lezer-json-BKYAA8Hu.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-HY6Yc0Vr.js → vendor-lezer-lr-DluApmOX.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-xFL3Evwf.js → vendor-lezer-markdown-B-uzYzYT.js} +1 -1
- package/dist/assets/{vendor-lezer-php-Cr_mQGrG.js → vendor-lezer-php-DI6PNjlz.js} +1 -1
- package/dist/assets/{vendor-lezer-python-BNRFWCb0.js → vendor-lezer-python-Bj232yb5.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-BvfOK5cU.js → vendor-lezer-rust-DlPG_Yau.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-qoxiLisk.js → vendor-lezer-sass-CBsyWB2A.js} +1 -1
- package/dist/assets/{vendor-lezer-xml--x8SSpqU.js → vendor-lezer-xml-C1FmgtmE.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-BDo1JaEr.js → vendor-lezer-yaml-DpHmjriG.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-D1Fe7FiY.js → vendor-replit-codemirror-vim-Cvk64got.js} +1 -1
- package/dist/assets/{web-components-CGDpzixf.js → web-components-C_DsTJis.js} +4 -4
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -1
- package/plugins/registry.json +7 -0
- package/plugins/subagents/LICENSE +25 -0
- package/plugins/subagents/agents/planner.md +36 -0
- package/plugins/subagents/agents/reviewer.md +34 -0
- package/plugins/subagents/agents/scout.md +49 -0
- package/plugins/subagents/agents/worker.md +23 -0
- package/plugins/subagents/extension.js +631 -0
- package/plugins/subagents/extension.test.js +295 -0
- package/plugins/subagents/package.json +41 -0
- package/plugins/visuals/choices.js +168 -0
- package/plugins/visuals/extension.js +87 -0
- package/plugins/visuals/files.js +74 -0
- package/plugins/visuals/package.json +32 -0
- package/server/index.js +20 -0
- package/server/lib/github/DOCUMENTATION.md +4 -2
- package/server/lib/github/gh-cli.js +35 -9
- package/server/lib/github/gh-cli.test.js +122 -0
- package/server/lib/notifications/pi-notification-watcher.js +3 -0
- package/server/lib/notifications/pi-notification-watcher.test.js +10 -0
- package/server/lib/open-url/DOCUMENTATION.md +1 -1
- package/server/lib/pi/extension-protocol.js +54 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +12 -13
- package/server/lib/pi/routes-extension-events.test.js +115 -0
- package/server/lib/pi/routes.js +307 -5
- package/server/lib/pi/routes.test.js +296 -1
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +25 -8
- package/server/lib/pi/session-daemon/extension-bridge.js +89 -29
- package/server/lib/pi/session-daemon/extension-config.js +719 -0
- package/server/lib/pi/session-daemon/extension-config.test.js +618 -0
- package/server/lib/pi/session-daemon/extension-controls.js +177 -0
- package/server/lib/pi/session-daemon/extension-controls.test.js +181 -0
- package/server/lib/pi/session-daemon/extension-name.js +6 -0
- package/server/lib/pi/session-daemon/extension-name.test.js +5 -0
- package/server/lib/pi/session-daemon/extension-palette.js +146 -0
- package/server/lib/pi/session-daemon/extension-palette.test.js +107 -0
- package/server/lib/pi/session-daemon/extension-replacements.js +138 -0
- package/server/lib/pi/session-daemon/extension-replacements.test.js +116 -0
- package/server/lib/pi/session-daemon/extension-ui-mode.js +30 -0
- package/server/lib/pi/session-daemon/extension-ui-mode.test.js +34 -0
- package/server/lib/pi/session-daemon/pichamber-ui.js +44 -0
- package/server/lib/pi/session-daemon/plugin-host.js +245 -0
- package/server/lib/pi/session-daemon/plugin-host.test.js +192 -0
- package/server/lib/pi/session-daemon/session-daemon-controls.e2e.test.js +205 -0
- package/server/lib/pi/session-daemon/session-daemon-drafts.e2e.test.js +409 -0
- package/server/lib/pi/session-daemon/session-daemon-extension-config.e2e.test.js +196 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +137 -6
- package/server/lib/pi/session-daemon/session-daemon-plugins.e2e.test.js +272 -0
- package/server/lib/pi/session-daemon/session-daemon-providers.e2e.test.js +153 -0
- package/server/lib/pi/session-daemon/session-daemon.js +568 -61
- package/server/lib/pi/session-daemon/session-daemon.test.js +164 -4
- package/server/lib/pi/session-daemon/session-engine-router.js +7 -0
- package/server/lib/pi/session-daemon/session-engine-router.test.js +20 -0
- package/server/lib/pi/session-daemon/supervisor.js +22 -3
- package/server/lib/pi/settings-store.js +14 -0
- package/server/lib/pi/settings-store.test.js +11 -0
- package/server/lib/plugins/DOCUMENTATION.md +186 -0
- package/server/lib/plugins/daemon-sync.js +78 -0
- package/server/lib/plugins/daemon-sync.supervisor.test.js +83 -0
- package/server/lib/plugins/daemon-sync.test.js +96 -0
- package/server/lib/plugins/impact.js +139 -0
- package/server/lib/plugins/impact.test.js +82 -0
- package/server/lib/plugins/manifest.js +195 -0
- package/server/lib/plugins/manifest.test.js +118 -0
- package/server/lib/plugins/registry.js +59 -0
- package/server/lib/plugins/routes.js +92 -0
- package/server/lib/plugins/routes.test.js +219 -0
- package/server/lib/plugins/service.js +161 -0
- package/server/lib/plugins/store.js +261 -0
- package/server/lib/plugins/store.test.js +188 -0
- package/server/lib/plugins/visuals-extension.test.js +237 -0
- package/server/lib/server-browser/DOCUMENTATION.md +32 -7
- package/server/lib/server-browser/browser-tab.js +4 -1
- package/server/lib/server-browser/downloads.js +261 -34
- package/server/lib/server-browser/downloads.test.js +171 -0
- package/server/lib/server-browser/runtime.integration.test.js +47 -0
- package/server/lib/server-browser/runtime.js +16 -0
- package/server/lib/server-browser/server-browser.js +25 -6
- package/server/lib/tunnels/executable-search.js +5 -1
- package/server/lib/tunnels/executable-search.test.js +26 -0
- package/dist/assets/DiagramView-BB-aZobi.js +0 -1
- package/dist/assets/FileSaveConflictDialog-Bzz8FNMq.js +0 -3
- package/dist/assets/FilesView-DECxN8Z0.js +0 -6
- package/dist/assets/GitHubDetailScaffold-CWsWycRd.js +0 -11
- package/dist/assets/GitHubLinkPicker-BVYdg_e8.js +0 -1
- package/dist/assets/GitHubListPrimitives-Dlv3tC4d.js +0 -1
- package/dist/assets/PatchDiff-BklyOEHs.js +0 -1
- package/dist/assets/PierreDiffViewer-wc6cB6qw.js +0 -147
- package/dist/assets/PullRequestsSurface-BZvJkT1I.js +0 -2
- package/dist/assets/SessionSwitcherDropdown-DShvvGwC.js +0 -2
- package/dist/assets/SessionUnreadDot-CbqRq6h_.js +0 -1
- package/dist/assets/SettingsView-DcF-At5E.js +0 -6
- package/dist/assets/ToolOutputDialog-DdMIfrnK.js +0 -8
- package/dist/assets/ToolPartDiffPreview-C6Sm4eVf.js +0 -1
- package/dist/assets/contextFileOpenGuard-UU86YHgI.js +0 -1
- package/dist/assets/gitStatusPredicates-DQEO4Psc.js +0 -1
- package/dist/assets/githubLink-ByPAyFjh.js +0 -10
- package/dist/assets/index-BaLCg7tL.css +0 -1
- package/dist/assets/main-DyFfbllq.js +0 -137
- package/dist/assets/miniChat-Ck6MEZ9Q.js +0 -2
- package/dist/assets/pi-session-focus-preference-Dx0UXPoO.js +0 -9
- package/dist/assets/renderElectronMiniChatApp-Cb7s7dWl.js +0 -2
- package/dist/assets/runtimeEndpointReset-7nWYnKd4.js +0 -62
- package/dist/assets/runtimeSurface-CFwnvks_.js +0 -1
- package/dist/assets/useAppFontEffects-ZTyNwFk6.js +0 -213
- package/dist/assets/useGitHubRemoteSearch-BF3ohpsh.js +0 -1
- package/dist/assets/useSwitcherItems-BJzwyDGX.js +0 -1
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
isDisplayedExtensionEntryType,
|
|
33
33
|
isIddExtensionEntry,
|
|
34
34
|
} from './extension-bridge.js';
|
|
35
|
+
import { commandName, createComposerControlsExtension, isComposerControlsExtensionPath } from './extension-controls.js';
|
|
35
36
|
import { resolveExtensionName } from './extension-name.js';
|
|
36
37
|
import { createExtensionTheme } from './extension-theme.js';
|
|
37
38
|
import {
|
|
@@ -41,6 +42,9 @@ import {
|
|
|
41
42
|
import { createExtensionMessageRenderer } from './extension-message-render.js';
|
|
42
43
|
import { normalizeOpenRequestUrl, resolveOpenRequestSession } from './open-request.js';
|
|
43
44
|
import { getBuiltinExtensionFactories } from './builtin-extensions.js';
|
|
45
|
+
import { createExtensionConfig } from './extension-config.js';
|
|
46
|
+
import { describeRuntimeReplacements } from './extension-replacements.js';
|
|
47
|
+
import { createPluginHost } from './plugin-host.js';
|
|
44
48
|
import {
|
|
45
49
|
SESSION_DAEMON_DEFAULT_MESSAGE_PAGE_LIMIT,
|
|
46
50
|
SESSION_DAEMON_MAX_FRAME_BYTES as MAX_FRAME_BYTES,
|
|
@@ -78,6 +82,9 @@ import {
|
|
|
78
82
|
import { createSessionEngineRouter } from './session-engine-router.js';
|
|
79
83
|
import { createPendingInputIndex } from './pending-input.js';
|
|
80
84
|
import { createExtensionCustomHost } from './extension-custom-host.js';
|
|
85
|
+
import { resolveExtensionMode } from './extension-ui-mode.js';
|
|
86
|
+
import { createPichamberUi } from './pichamber-ui.js';
|
|
87
|
+
import { createExtensionPaletteResolver, isTerminalColors } from './extension-palette.js';
|
|
81
88
|
|
|
82
89
|
const textFromContent = (content) => (
|
|
83
90
|
Array.isArray(content)
|
|
@@ -87,18 +94,28 @@ const textFromContent = (content) => (
|
|
|
87
94
|
|
|
88
95
|
// Marker so pi extensions can detect PiChamber without an extra dependency.
|
|
89
96
|
// Extensions should use optional detection, e.g.:
|
|
90
|
-
// const
|
|
97
|
+
// const marker = (globalThis as any).__PICHAMBER__;
|
|
91
98
|
// or `process.env.PICHAMBER === "1"`. The object is frozen and versioned.
|
|
99
|
+
// `globalThis.pichamber` holds PiChamber's own dialog calls (`pichamber.ui`),
|
|
100
|
+
// kept off Pi's `ctx.ui` so a method Pi adds later cannot be shadowed.
|
|
92
101
|
if (!globalThis.__PICHAMBER__) {
|
|
93
102
|
try {
|
|
94
103
|
globalThis.__PICHAMBER__ = Object.freeze({
|
|
95
104
|
version: 1,
|
|
96
105
|
protocol: 'pichamber-extension-ui',
|
|
97
|
-
//
|
|
98
|
-
mode
|
|
106
|
+
// The `ctx.mode` new sessions get (extension-ui-mode.js). A session
|
|
107
|
+
// keeps the mode it started with; its `ctx.mode` is authoritative.
|
|
108
|
+
get mode() {
|
|
109
|
+
return resolveExtensionMode({ dataDir: resolvePiChamberDataDir() });
|
|
110
|
+
},
|
|
99
111
|
});
|
|
100
112
|
} catch {}
|
|
101
113
|
}
|
|
114
|
+
if (!globalThis.pichamber) {
|
|
115
|
+
try {
|
|
116
|
+
globalThis.pichamber = Object.freeze({ version: 1, ui: createPichamberUi() });
|
|
117
|
+
} catch {}
|
|
118
|
+
}
|
|
102
119
|
if (!process.env.PICHAMBER) {
|
|
103
120
|
try { process.env.PICHAMBER = '1'; } catch {}
|
|
104
121
|
}
|
|
@@ -146,11 +163,20 @@ export function isLocalSessionDaemonEndpoint(endpoint, platform = process.platfo
|
|
|
146
163
|
// factory to daemon socket state.
|
|
147
164
|
export async function createPiSessionRuntime({ cwd, agentDir = getAgentDir(), sessionFile }, hooks) {
|
|
148
165
|
const createRuntime = async ({ cwd: runtimeCwd, agentDir: runtimeAgentDir, sessionManager, sessionStartEvent }) => {
|
|
166
|
+
// Lets the daemon know a session's id before Pi starts it, so what its
|
|
167
|
+
// extensions publish at `session_start` can already be attributed.
|
|
168
|
+
hooks?.beforeSession?.(sessionManager);
|
|
149
169
|
const services = await createAgentSessionServices({
|
|
150
170
|
cwd: runtimeCwd,
|
|
151
171
|
agentDir: runtimeAgentDir,
|
|
152
172
|
resourceLoaderOptions: {
|
|
153
|
-
|
|
173
|
+
// PiChamber plugins load after Pi's built-ins (plugin-host.js); the
|
|
174
|
+
// composer-controls listener loads last (extension-controls.js).
|
|
175
|
+
extensionFactories: [
|
|
176
|
+
...getBuiltinExtensionFactories(),
|
|
177
|
+
...(hooks?.pluginExtensionFactories?.() ?? []),
|
|
178
|
+
...(hooks?.internalExtensionFactories?.() ?? []),
|
|
179
|
+
],
|
|
154
180
|
},
|
|
155
181
|
});
|
|
156
182
|
|
|
@@ -198,6 +224,10 @@ export function createSessionDaemon({
|
|
|
198
224
|
onShutdown,
|
|
199
225
|
idleTimeoutMs = 5 * 60 * 1_000,
|
|
200
226
|
sendOperationTtlMs = 10 * 60 * 1_000,
|
|
227
|
+
// The `ctx.mode` each new binding reports; the "Extension interface" setting.
|
|
228
|
+
resolveExtensionMode: resolveBindingExtensionMode = () => resolveExtensionMode({ dataDir: resolvePiChamberDataDir() }),
|
|
229
|
+
// Pi's colours for extension surfaces in a given terminal palette (extension-palette.js).
|
|
230
|
+
resolveExtensionPalette = createExtensionPaletteResolver(),
|
|
201
231
|
sessionListCache = createPiSessionJsonlListCache(),
|
|
202
232
|
listSessions = ({ cwd: sessionCwd, agentDir: sessionAgentDir = agentDir }) => listPiSessionJsonlDirectory({
|
|
203
233
|
cwd: sessionCwd,
|
|
@@ -227,6 +257,8 @@ export function createSessionDaemon({
|
|
|
227
257
|
extensionToolRenderer: injectExtensionToolRenderer,
|
|
228
258
|
engines = [],
|
|
229
259
|
extensionMessageRenderer: injectExtensionMessageRenderer,
|
|
260
|
+
// Configured only by the server through `plugins.configure`.
|
|
261
|
+
pluginHost = createPluginHost(),
|
|
230
262
|
} = {}) {
|
|
231
263
|
if (!isLocalSessionDaemonEndpoint(endpoint, platform)) {
|
|
232
264
|
throw new SessionDaemonProtocolError('INVALID_ENDPOINT', 'The session daemon endpoint must be local.');
|
|
@@ -487,12 +519,36 @@ export function createSessionDaemon({
|
|
|
487
519
|
const getToolInput = (sessionId, toolCallId) => toolInputBySession.get(sessionId)?.get(toolCallId);
|
|
488
520
|
|
|
489
521
|
const forgetToolInput = (sessionId, toolCallId) => {
|
|
522
|
+
forgetToolPartial(sessionId, toolCallId);
|
|
490
523
|
const inputs = toolInputBySession.get(sessionId);
|
|
491
524
|
if (!inputs) return;
|
|
492
525
|
inputs.delete(toolCallId);
|
|
493
526
|
if (inputs.size === 0) toolInputBySession.delete(sessionId);
|
|
494
527
|
};
|
|
495
528
|
|
|
529
|
+
// The latest partial result of each running tool. A client that opens the
|
|
530
|
+
// session mid-call gets it on the running part, as live clients did from
|
|
531
|
+
// `session.tool.update`: a tool that reports once and then waits (a Visuals
|
|
532
|
+
// question showing its options) would otherwise stay blank there. Dropped
|
|
533
|
+
// when the tool ends, the run settles, or the session closes.
|
|
534
|
+
const toolPartialBySession = new Map();
|
|
535
|
+
|
|
536
|
+
const rememberToolPartial = (sessionId, toolCallId, projected) => {
|
|
537
|
+
if (projected.output === undefined && projected.metadata === undefined) return;
|
|
538
|
+
const partials = toolPartialBySession.get(sessionId) ?? new Map();
|
|
539
|
+
partials.set(toolCallId, projected);
|
|
540
|
+
toolPartialBySession.set(sessionId, partials);
|
|
541
|
+
};
|
|
542
|
+
|
|
543
|
+
const getToolPartial = (sessionId, toolCallId) => toolPartialBySession.get(sessionId)?.get(toolCallId);
|
|
544
|
+
|
|
545
|
+
const forgetToolPartial = (sessionId, toolCallId) => {
|
|
546
|
+
const partials = toolPartialBySession.get(sessionId);
|
|
547
|
+
if (!partials) return;
|
|
548
|
+
partials.delete(toolCallId);
|
|
549
|
+
if (partials.size === 0) toolPartialBySession.delete(sessionId);
|
|
550
|
+
};
|
|
551
|
+
|
|
496
552
|
const mergeToolPresentationMetadata = (metadata, activeRuntime, directory, toolName, args) => {
|
|
497
553
|
const skill = skillReadClassifierFor(activeRuntime, directory)?.(toolName, args);
|
|
498
554
|
if (!skill) return metadata;
|
|
@@ -595,22 +651,31 @@ export function createSessionDaemon({
|
|
|
595
651
|
cwd: targetCwd,
|
|
596
652
|
agentDir,
|
|
597
653
|
resourceLoaderOptions: {
|
|
598
|
-
extensionFactories: getBuiltinExtensionFactories(),
|
|
654
|
+
extensionFactories: [...getBuiltinExtensionFactories(), ...pluginHost.extensionFactories(), ...internalExtensionFactories()],
|
|
599
655
|
},
|
|
600
656
|
});
|
|
601
657
|
|
|
602
658
|
// The session that most recently produced an event: the carrier for an
|
|
603
659
|
// Open request nobody can attribute (see open-request.js).
|
|
604
660
|
let lastPublishedSession = null;
|
|
661
|
+
// Sessions started for a new-session draft before its first send (see
|
|
662
|
+
// `createSession` with `draft: true`). Listings and the pending-input list
|
|
663
|
+
// leave them out, and their events carry `draft: true`, so no client adds
|
|
664
|
+
// a sidebar row or transcript for them; only the drafting client uses
|
|
665
|
+
// them, for the draft's composer controls and model. Sending adopts the
|
|
666
|
+
// session (`draftSessionId`), which clears the mark.
|
|
667
|
+
const draftSessionIds = new Set();
|
|
605
668
|
const publish = (event, payload, sessionId = runtime?.session?.sessionId, directory) => {
|
|
606
669
|
if (typeof sessionId !== 'string' || sessionId.length === 0) return;
|
|
607
670
|
const targetDirectory = directory || activeDirectory || cwd;
|
|
671
|
+
const draft = draftSessionIds.has(sessionId);
|
|
608
672
|
const message = {
|
|
609
673
|
protocolVersion: PROTOCOL_VERSION,
|
|
610
674
|
kind: 'event',
|
|
611
675
|
event,
|
|
612
676
|
streamEpoch,
|
|
613
677
|
sequence: ++sequence,
|
|
678
|
+
...(draft ? { draft: true } : {}),
|
|
614
679
|
payload: {
|
|
615
680
|
sessionId,
|
|
616
681
|
directory: targetDirectory,
|
|
@@ -618,7 +683,8 @@ export function createSessionDaemon({
|
|
|
618
683
|
},
|
|
619
684
|
};
|
|
620
685
|
const line = `${JSON.stringify(message)}\n`;
|
|
621
|
-
|
|
686
|
+
// A draft is no target for open requests: no client shows it.
|
|
687
|
+
if (!draft) lastPublishedSession = { sessionId, directory: targetDirectory };
|
|
622
688
|
// Live delivery stays full-fidelity even when the event is too large to
|
|
623
689
|
// retain: retention evicts whole oldest events and never truncates content.
|
|
624
690
|
replayLog.append(message.sequence, sessionId, line);
|
|
@@ -638,6 +704,7 @@ export function createSessionDaemon({
|
|
|
638
704
|
event,
|
|
639
705
|
streamEpoch,
|
|
640
706
|
sequence: ++sequence,
|
|
707
|
+
...(draftSessionIds.has(sessionId) ? { draft: true } : {}),
|
|
641
708
|
payload: { sessionId, directory: directory || activeDirectory || cwd, ...payload },
|
|
642
709
|
};
|
|
643
710
|
const line = `${JSON.stringify(message)}\n`;
|
|
@@ -657,7 +724,11 @@ export function createSessionDaemon({
|
|
|
657
724
|
const userBash = createUserBash({
|
|
658
725
|
publish,
|
|
659
726
|
redact: (value) => redactAttachmentPaths(value),
|
|
660
|
-
onSettled: (sessionId) =>
|
|
727
|
+
onSettled: (sessionId) => {
|
|
728
|
+
safeTouchIdleDisposal(sessionId);
|
|
729
|
+
// A settings change that waited for this command can apply now.
|
|
730
|
+
void flushPendingRuntimeRecreation().catch(() => {});
|
|
731
|
+
},
|
|
661
732
|
});
|
|
662
733
|
// What opened a `custom()` surface, for its header: the running top-level
|
|
663
734
|
// tool, else the extension command being run. Pi's ctx.ui is shared per
|
|
@@ -668,6 +739,13 @@ export function createSessionDaemon({
|
|
|
668
739
|
// same id it uses for custom() surfaces): surfaces that input opens are
|
|
669
740
|
// drawn at that tab's size.
|
|
670
741
|
const promptClientBySession = new Map();
|
|
742
|
+
const recordInputClient = (sessionId, clientId) => {
|
|
743
|
+
if (typeof clientId === 'string' && clientId.length > 0 && clientId.length <= 128) {
|
|
744
|
+
promptClientBySession.set(sessionId, clientId);
|
|
745
|
+
} else {
|
|
746
|
+
promptClientBySession.delete(sessionId);
|
|
747
|
+
}
|
|
748
|
+
};
|
|
671
749
|
/**
|
|
672
750
|
* The running extension command while it is the only thing running (no
|
|
673
751
|
* agent turn): the session is busy, as in Pi's interactive mode, which
|
|
@@ -721,7 +799,15 @@ export function createSessionDaemon({
|
|
|
721
799
|
requestSessionShutdown: (sessionId) => shutdownRequestedBySession.add(sessionId),
|
|
722
800
|
pendingInput,
|
|
723
801
|
customHost,
|
|
802
|
+
resolveExtensionMode: resolveBindingExtensionMode,
|
|
724
803
|
});
|
|
804
|
+
// Factories PiChamber itself adds to every runtime, after plugins: the
|
|
805
|
+
// listener for composer controls extensions declare on `pi.events`.
|
|
806
|
+
const composerControlsExtension = createComposerControlsExtension(
|
|
807
|
+
(sessionId, data) => extensionBridge.setComposerControl(sessionId, data),
|
|
808
|
+
);
|
|
809
|
+
const internalExtensionFactories = () => [composerControlsExtension];
|
|
810
|
+
|
|
725
811
|
// `custom()` commands from browsers. Unknown or closed surfaces answer
|
|
726
812
|
// `accepted: false` instead of throwing, like stale dialog responses, so a
|
|
727
813
|
// late key from another device never tears down the daemon socket.
|
|
@@ -796,8 +882,11 @@ export function createSessionDaemon({
|
|
|
796
882
|
// host factories keep their single-argument contract and ignore the hooks.
|
|
797
883
|
const baseCreateRuntime = injectCreateRuntime
|
|
798
884
|
?? ((runtimeOptions, runtimeHooks) => createPiSessionRuntime(runtimeOptions, runtimeHooks));
|
|
799
|
-
const createRuntime = (runtimeOptions) => baseCreateRuntime(runtimeOptions, {
|
|
885
|
+
const createRuntime = (runtimeOptions, extraHooks) => baseCreateRuntime(runtimeOptions, {
|
|
800
886
|
createExtensionBindings: buildExtensionBindings,
|
|
887
|
+
pluginExtensionFactories: pluginHost.extensionFactories,
|
|
888
|
+
internalExtensionFactories,
|
|
889
|
+
...extraHooks,
|
|
801
890
|
});
|
|
802
891
|
|
|
803
892
|
const getSessionState = () => runtime
|
|
@@ -898,6 +987,9 @@ export function createSessionDaemon({
|
|
|
898
987
|
serverNow: Date.now(),
|
|
899
988
|
lastSequence: snapshotSequence,
|
|
900
989
|
...(extensionSnapshot.statuses ? { extensionStatuses: extensionSnapshot.statuses } : {}),
|
|
990
|
+
// Always sent: an empty list is authoritative (no controls), unlike a
|
|
991
|
+
// missing field.
|
|
992
|
+
extensionControls: extensionSnapshot.controls ?? [],
|
|
901
993
|
...(extensionSnapshot.widgets ? { extensionWidgets: extensionSnapshot.widgets } : {}),
|
|
902
994
|
...(extensionSnapshot.dialogs ? { extensionDialogs: extensionSnapshot.dialogs } : {}),
|
|
903
995
|
...(extensionSnapshot.panels ? { extensionPanels: extensionSnapshot.panels } : {}),
|
|
@@ -963,7 +1055,36 @@ export function createSessionDaemon({
|
|
|
963
1055
|
idleDisposeTimers.clear();
|
|
964
1056
|
};
|
|
965
1057
|
|
|
1058
|
+
// A disposed session whose assigned JSONL is positively absent never
|
|
1059
|
+
// reached disk, so nothing can reopen it. Clears the same safe per-session
|
|
1060
|
+
// state as explicit deletion and tells clients it is gone. Callers decide
|
|
1061
|
+
// absence (ENOENT only) and hold a successful lease release first.
|
|
1062
|
+
const forgetEphemeralSession = ({ cwd: sessionCwd, sessionId }) => {
|
|
1063
|
+
if (dormantSession?.sessionId === sessionId) dormantSession = undefined;
|
|
1064
|
+
messageEntryAliases.clearSession({ cwd: sessionCwd, sessionId });
|
|
1065
|
+
retryStateBySession.delete(sessionId);
|
|
1066
|
+
compactionStateBySession.delete(sessionId);
|
|
1067
|
+
activeRunStartedAt.delete(sessionId);
|
|
1068
|
+
shutdownRequestedBySession.delete(sessionId);
|
|
1069
|
+
publish('session.deleted', {}, sessionId, sessionCwd);
|
|
1070
|
+
pendingInput.forgetSession(sessionId);
|
|
1071
|
+
};
|
|
1072
|
+
|
|
1073
|
+
const isSessionFileAbsent = async (sessionFile) => {
|
|
1074
|
+
if (typeof sessionFile !== 'string' || sessionFile.length === 0) return false;
|
|
1075
|
+
try {
|
|
1076
|
+
await stat(sessionFile);
|
|
1077
|
+
return false;
|
|
1078
|
+
} catch (error) {
|
|
1079
|
+
return error?.code === 'ENOENT';
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
|
|
966
1083
|
const disposeRuntime = async () => {
|
|
1084
|
+
// Record the session the active runtime holds now (navigate, fork, or a
|
|
1085
|
+
// first message may have changed it since activation) so the dormant
|
|
1086
|
+
// entry names the file a later `ensureRuntime` would reopen.
|
|
1087
|
+
rememberRuntimeSession();
|
|
967
1088
|
clearAllIdleDisposals();
|
|
968
1089
|
extensionToolRenderer.dispose();
|
|
969
1090
|
activeSessionInputs.clear();
|
|
@@ -994,9 +1115,36 @@ export function createSessionDaemon({
|
|
|
994
1115
|
await runtime?.dispose?.();
|
|
995
1116
|
}
|
|
996
1117
|
runtime = undefined;
|
|
1118
|
+
// Drafts die with their runtimes. Announce each while it is still marked,
|
|
1119
|
+
// so the event carries `draft: true` and only the drafting client hears
|
|
1120
|
+
// it, then drop the mark: no later id may be taken for a live draft.
|
|
997
1121
|
for (const lease of leased) {
|
|
998
|
-
|
|
999
|
-
|
|
1122
|
+
if (!draftSessionIds.has(lease.sessionId)) continue;
|
|
1123
|
+
publish('session.deleted', {}, lease.sessionId, lease.cwd);
|
|
1124
|
+
draftSessionIds.delete(lease.sessionId);
|
|
1125
|
+
}
|
|
1126
|
+
// Pi defers the JSONL until the first user or assistant message, so the
|
|
1127
|
+
// remembered session may never have reached disk (a catalog read on a
|
|
1128
|
+
// fresh install, or a new session with nothing sent). Decide that while
|
|
1129
|
+
// the leases are still held, as idle disposal does. Reopening an absent
|
|
1130
|
+
// file fails as SESSION_JSONL_UNREADABLE on every later `ensureRuntime`,
|
|
1131
|
+
// so the dormant entry is dropped and the next start opens a fresh session.
|
|
1132
|
+
// Capture once: the dormant binding can change during the await, and the
|
|
1133
|
+
// session cleared or announced must be the one whose file was checked.
|
|
1134
|
+
const dormantCandidate = dormantSession;
|
|
1135
|
+
const ephemeralSession = dormantCandidate && await isSessionFileAbsent(dormantCandidate.sessionFile)
|
|
1136
|
+
? dormantCandidate
|
|
1137
|
+
: undefined;
|
|
1138
|
+
let ephemeralReleased = false;
|
|
1139
|
+
for (const lease of leased) {
|
|
1140
|
+
const result = await releaseResidentLease(lease);
|
|
1141
|
+
if (ephemeralSession && lease.sessionId === ephemeralSession.sessionId && result?.released === true) ephemeralReleased = true;
|
|
1142
|
+
}
|
|
1143
|
+
if (!ephemeralSession) return;
|
|
1144
|
+
if (dormantSession === ephemeralSession) dormantSession = undefined;
|
|
1145
|
+
// Only an owned, released session is announced as gone; an implicit
|
|
1146
|
+
// catalog session held no lease and was never listed.
|
|
1147
|
+
if (ephemeralReleased) forgetEphemeralSession({ cwd: ephemeralSession.cwd, sessionId: ephemeralSession.sessionId });
|
|
1000
1148
|
};
|
|
1001
1149
|
|
|
1002
1150
|
const startRuntime = async ({ cwd: runtimeCwd = activeDirectory || cwd, sessionFile, activate = true } = {}) => {
|
|
@@ -1053,7 +1201,10 @@ export function createSessionDaemon({
|
|
|
1053
1201
|
// the active runtime of a different project, whose loaded extensions,
|
|
1054
1202
|
// skills, prompts, and models would then be reported for the wrong project.
|
|
1055
1203
|
const resident = runtimeRegistry?.listByDirectory?.(requestedCwd) ?? [];
|
|
1056
|
-
|
|
1204
|
+
// A draft session never answers as a folder's general runtime: its
|
|
1205
|
+
// events are tagged `draft` and only the drafting client reads them.
|
|
1206
|
+
const general = resident.filter((entry) => !draftSessionIds.has(entry?.session?.sessionId));
|
|
1207
|
+
const candidate = general.includes(runtime) ? runtime : general[0];
|
|
1057
1208
|
if (candidate) return Promise.resolve(candidate);
|
|
1058
1209
|
|
|
1059
1210
|
// Concurrent starts are shared per directory, never across directories.
|
|
@@ -1093,12 +1244,20 @@ export function createSessionDaemon({
|
|
|
1093
1244
|
else activeSessionInputs.delete(targetRuntime);
|
|
1094
1245
|
};
|
|
1095
1246
|
|
|
1247
|
+
// Recreating runtimes disposes every one of them, so it waits for work
|
|
1248
|
+
// that ends by itself: a turn, a compaction, an input being accepted, a
|
|
1249
|
+
// user shell command (`!cmd`, live from acceptance, before Pi reports
|
|
1250
|
+
// `isBashRunning`). A dialog or custom() surface left open does not hold
|
|
1251
|
+
// it back, since nothing says when that ends; recreation cancels it, as a
|
|
1252
|
+
// daemon restart does.
|
|
1096
1253
|
const isRuntimeReloadSafe = (targetRuntime) => {
|
|
1097
1254
|
const session = targetRuntime?.session;
|
|
1098
1255
|
return Boolean(
|
|
1099
1256
|
session?.sessionId
|
|
1100
1257
|
&& session.isStreaming !== true
|
|
1101
1258
|
&& session.isCompacting !== true
|
|
1259
|
+
&& session.isBashRunning !== true
|
|
1260
|
+
&& !userBash.isActive(session.sessionId)
|
|
1102
1261
|
&& !activeSessionInputs.has(targetRuntime)
|
|
1103
1262
|
);
|
|
1104
1263
|
};
|
|
@@ -1221,6 +1380,10 @@ export function createSessionDaemon({
|
|
|
1221
1380
|
|
|
1222
1381
|
const isIdleDisposalSafe = (sessionId, targetRuntime) => {
|
|
1223
1382
|
if (!targetRuntime) return false;
|
|
1383
|
+
// A draft is always disposable: nobody else can see it, so a dialog,
|
|
1384
|
+
// custom() surface, or command left in it would keep it forever.
|
|
1385
|
+
// Disposal ends them (`disposeIdleSessionRuntime`).
|
|
1386
|
+
if (isValidIdleSessionId(sessionId) && draftSessionIds.has(sessionId)) return true;
|
|
1224
1387
|
// A session blocked on a hosted input request (e.g. an extension dialog
|
|
1225
1388
|
// opened while idle) must survive the idle timer so a user who walks
|
|
1226
1389
|
// away finds it still pending later. Deletion and daemon stop still
|
|
@@ -1273,6 +1436,13 @@ export function createSessionDaemon({
|
|
|
1273
1436
|
}
|
|
1274
1437
|
const targetCwd = targetRuntime.cwd || activeDirectory || cwd;
|
|
1275
1438
|
try {
|
|
1439
|
+
if (draftSessionIds.has(sessionId)) {
|
|
1440
|
+
// Forceful for a draft: answer its dialogs, close its surfaces,
|
|
1441
|
+
// stop anything running, and let a control's command settle.
|
|
1442
|
+
clearExtensionState(sessionId);
|
|
1443
|
+
try { await targetRuntime.session?.abort?.(); } catch { /* disposal follows */ }
|
|
1444
|
+
await waitForControlRuns(sessionId);
|
|
1445
|
+
}
|
|
1276
1446
|
if (targetRuntime === runtime) rememberRuntimeSession();
|
|
1277
1447
|
// Kept for safety: while a hosted input request is pending the idle
|
|
1278
1448
|
// guard above refuses disposal, so this cancel path is normally
|
|
@@ -1291,14 +1461,7 @@ export function createSessionDaemon({
|
|
|
1291
1461
|
// here (after dispose, before release) keeps the check
|
|
1292
1462
|
// authoritative: no cross-daemon owner can interleave a recreate
|
|
1293
1463
|
// while this lease is held.
|
|
1294
|
-
|
|
1295
|
-
if (typeof assignedSessionFile === 'string' && assignedSessionFile.length > 0) {
|
|
1296
|
-
try {
|
|
1297
|
-
await stat(assignedSessionFile);
|
|
1298
|
-
} catch (error) {
|
|
1299
|
-
if (error?.code === 'ENOENT') ephemeral = true;
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1464
|
+
const ephemeral = await isSessionFileAbsent(assignedSessionFile);
|
|
1302
1465
|
const releaseResult = await releaseResidentLease({ cwd: targetCwd, sessionId });
|
|
1303
1466
|
const released = releaseResult?.released === true;
|
|
1304
1467
|
shutdownRequestedBySession.delete(sessionId);
|
|
@@ -1312,22 +1475,15 @@ export function createSessionDaemon({
|
|
|
1312
1475
|
// deletion. A confirmed ephemeral expiration clears the same safe
|
|
1313
1476
|
// per-session auxiliary state as explicit deletion where
|
|
1314
1477
|
// applicable (aliases, retry/compaction/run-start/shutdown).
|
|
1315
|
-
if (ephemeral && released) {
|
|
1316
|
-
if (dormantSession?.sessionId === sessionId) dormantSession = undefined;
|
|
1317
|
-
messageEntryAliases.clearSession({ cwd: targetCwd, sessionId });
|
|
1318
|
-
retryStateBySession.delete(sessionId);
|
|
1319
|
-
compactionStateBySession.delete(sessionId);
|
|
1320
|
-
activeRunStartedAt.delete(sessionId);
|
|
1321
|
-
shutdownRequestedBySession.delete(sessionId);
|
|
1322
|
-
publish('session.deleted', {}, sessionId, targetCwd);
|
|
1323
|
-
pendingInput.forgetSession(sessionId);
|
|
1324
|
-
}
|
|
1478
|
+
if (ephemeral && released) forgetEphemeralSession({ cwd: targetCwd, sessionId });
|
|
1325
1479
|
} catch {
|
|
1326
1480
|
// A failed disposal retains ownership (registry entry, lease, and
|
|
1327
1481
|
// global runtime are all still held) and never emits deletion.
|
|
1328
1482
|
publish('session.error', { code: 'RUNTIME_DISPOSAL_FAILED' }, sessionId, targetRuntime.cwd);
|
|
1329
1483
|
} finally {
|
|
1330
1484
|
disposingSessionIds.delete(sessionId);
|
|
1485
|
+
// A draft that idled out is gone; its deletion went out marked.
|
|
1486
|
+
if (!runtimeRegistry?.findBySessionId(sessionId)) draftSessionIds.delete(sessionId);
|
|
1331
1487
|
}
|
|
1332
1488
|
})();
|
|
1333
1489
|
disposingSessionPromises.set(sessionId, tracked);
|
|
@@ -1416,7 +1572,8 @@ export function createSessionDaemon({
|
|
|
1416
1572
|
case 'sessions.bash':
|
|
1417
1573
|
case 'sessions.abortBash':
|
|
1418
1574
|
case 'sessions.delete':
|
|
1419
|
-
case 'sessions.rename':
|
|
1575
|
+
case 'sessions.rename':
|
|
1576
|
+
case 'extensions.control': {
|
|
1420
1577
|
const candidate = message?.payload?.sessionId;
|
|
1421
1578
|
return isValidIdleSessionId(candidate) ? candidate : undefined;
|
|
1422
1579
|
}
|
|
@@ -1479,6 +1636,8 @@ export function createSessionDaemon({
|
|
|
1479
1636
|
}
|
|
1480
1637
|
const extra = [];
|
|
1481
1638
|
for (const entry of activeEntries) {
|
|
1639
|
+
// A draft's session is listed once a send adopts it.
|
|
1640
|
+
if (draftSessionIds.has(entry?.session?.sessionId)) continue;
|
|
1482
1641
|
if (entry?.session?.sessionId && !knownIds.has(entry.session.sessionId)) {
|
|
1483
1642
|
const name = entry.session.sessionManager?.getSessionName?.() || entry.session.title || undefined;
|
|
1484
1643
|
const messageCount = entry.session.messages?.length || 0;
|
|
@@ -1696,6 +1855,9 @@ export function createSessionDaemon({
|
|
|
1696
1855
|
try {
|
|
1697
1856
|
const targetDir = await resolveDirectory(requestedDirectory);
|
|
1698
1857
|
const existing = runtimeRegistry.get({ cwd: targetDir, sessionId });
|
|
1858
|
+
// A draft answers its own commands but never becomes the active
|
|
1859
|
+
// session: a restart must not try to reopen what was never written.
|
|
1860
|
+
if (existing && draftSessionIds.has(sessionId)) return existing;
|
|
1699
1861
|
if (existing) {
|
|
1700
1862
|
runtime = existing;
|
|
1701
1863
|
activeDirectory = targetDir;
|
|
@@ -1704,6 +1866,7 @@ export function createSessionDaemon({
|
|
|
1704
1866
|
} catch {}
|
|
1705
1867
|
}
|
|
1706
1868
|
const existingAnywhere = runtimeRegistry.findBySessionId(sessionId);
|
|
1869
|
+
if (existingAnywhere && draftSessionIds.has(sessionId)) return existingAnywhere;
|
|
1707
1870
|
if (existingAnywhere) {
|
|
1708
1871
|
runtime = existingAnywhere;
|
|
1709
1872
|
if (existingAnywhere.cwd) activeDirectory = existingAnywhere.cwd;
|
|
@@ -1957,7 +2120,8 @@ export function createSessionDaemon({
|
|
|
1957
2120
|
const startedAt = activeStartedAt ?? completedTiming?.startedAt;
|
|
1958
2121
|
const running = streaming && !result;
|
|
1959
2122
|
const interrupted = !running && !result;
|
|
1960
|
-
const
|
|
2123
|
+
const partial = running ? getToolPartial(session.sessionId, part.id) : undefined;
|
|
2124
|
+
const metadata = mergeToolPresentationMetadata(result?.metadata ?? partial?.metadata, activeRuntime, targetDir, part.name, part.arguments);
|
|
1961
2125
|
let resolveRender;
|
|
1962
2126
|
if (running) {
|
|
1963
2127
|
const liveRender = extensionToolRenderer.getLiveRender?.(session.sessionId, part.id);
|
|
@@ -1983,7 +2147,7 @@ export function createSessionDaemon({
|
|
|
1983
2147
|
name: part.name,
|
|
1984
2148
|
input: redactAttachmentValues(part.arguments),
|
|
1985
2149
|
state: result?.isError || interrupted ? 'error' : running ? 'running' : 'completed',
|
|
1986
|
-
...(result?.output ? { output: result.output } : {}),
|
|
2150
|
+
...(result?.output ? { output: result.output } : partial?.output ? { output: partial.output } : {}),
|
|
1987
2151
|
...(result?.error
|
|
1988
2152
|
? { error: result.error }
|
|
1989
2153
|
: interrupted
|
|
@@ -2133,9 +2297,14 @@ export function createSessionDaemon({
|
|
|
2133
2297
|
break;
|
|
2134
2298
|
}
|
|
2135
2299
|
}
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2300
|
+
// The live session is what the next prompt runs on, so it wins. Pi already
|
|
2301
|
+
// restores a reopened session's model and thinking from its branch. The
|
|
2302
|
+
// last assistant turn only fills a gap: after a revert, a failed turn, or
|
|
2303
|
+
// a switch nobody has prompted on yet, it names a model the session is no
|
|
2304
|
+
// longer on, and a client that trusted it would skip the switch it needs.
|
|
2305
|
+
const sessionModel = (model?.provider && model?.id ? { providerId: model.provider, modelId: model.id } : undefined)
|
|
2306
|
+
?? lastAssistant?.model;
|
|
2307
|
+
const sessionThinking = session.thinkingLevel || lastAssistant?.thinkingLevel;
|
|
2139
2308
|
const isStreaming = session.isStreaming === true;
|
|
2140
2309
|
const retry = retryStateBySession.get(session.sessionId);
|
|
2141
2310
|
const compaction = compactionStateFor(session);
|
|
@@ -2159,6 +2328,9 @@ export function createSessionDaemon({
|
|
|
2159
2328
|
...(activeRunStartedAt.has(session.sessionId) ? { runStartedAt: activeRunStartedAt.get(session.sessionId) } : {}),
|
|
2160
2329
|
serverNow: Date.now(),
|
|
2161
2330
|
...(extensionSnapshot.statuses ? { extensionStatuses: extensionSnapshot.statuses } : {}),
|
|
2331
|
+
// Always sent: an empty list is authoritative (no controls), unlike a
|
|
2332
|
+
// missing field.
|
|
2333
|
+
extensionControls: extensionSnapshot.controls ?? [],
|
|
2162
2334
|
...(extensionSnapshot.widgets ? { extensionWidgets: extensionSnapshot.widgets } : {}),
|
|
2163
2335
|
...(extensionSnapshot.dialogs ? { extensionDialogs: extensionSnapshot.dialogs } : {}),
|
|
2164
2336
|
...(extensionSnapshot.panels ? { extensionPanels: extensionSnapshot.panels } : {}),
|
|
@@ -2172,6 +2344,86 @@ export function createSessionDaemon({
|
|
|
2172
2344
|
};
|
|
2173
2345
|
};
|
|
2174
2346
|
|
|
2347
|
+
/**
|
|
2348
|
+
* Send from a draft: its session becomes the new session, with the title,
|
|
2349
|
+
* model, and thinking the send asked for, so what the draft's controls did
|
|
2350
|
+
* (a mode picked, a toggle flipped) carries over. Returns null when the
|
|
2351
|
+
* draft cannot be used (gone, being disposed, another folder, a fork); the
|
|
2352
|
+
* caller then creates a session as usual and a stale draft is dropped.
|
|
2353
|
+
*/
|
|
2354
|
+
const adoptDraftSession = async (payload, targetCwd, parent) => {
|
|
2355
|
+
const sessionId = payload.draftSessionId;
|
|
2356
|
+
if (!draftSessionIds.has(sessionId)) return null;
|
|
2357
|
+
const draftRuntime = runtimeRegistry?.findBySessionId(sessionId);
|
|
2358
|
+
if (!draftRuntime || parent || draftRuntime.cwd !== targetCwd || disposingSessionIds.has(sessionId)) {
|
|
2359
|
+
void discardDraftSession(sessionId).catch(() => {});
|
|
2360
|
+
return null;
|
|
2361
|
+
}
|
|
2362
|
+
// The idle timer stops first: it must not fire during the awaits below.
|
|
2363
|
+
clearIdleDisposal(sessionId);
|
|
2364
|
+
// A control's command still running in the draft lands its effects
|
|
2365
|
+
// before the session is projected for the reply (bounded, in case it
|
|
2366
|
+
// waits on a dialog the user has not answered). The draft keeps its mark
|
|
2367
|
+
// meanwhile, so a turn that command starts is still stopped.
|
|
2368
|
+
await waitForControlRuns(sessionId);
|
|
2369
|
+
// Only one send adopts a draft; another (or a discard during the wait)
|
|
2370
|
+
// leaves this send to create as usual.
|
|
2371
|
+
if (!draftSessionIds.has(sessionId) || runtimeRegistry?.findBySessionId(sessionId) !== draftRuntime
|
|
2372
|
+
|| disposingSessionIds.has(sessionId)) {
|
|
2373
|
+
return null;
|
|
2374
|
+
}
|
|
2375
|
+
draftSessionIds.delete(sessionId);
|
|
2376
|
+
try {
|
|
2377
|
+
const current = draftRuntime.session?.model;
|
|
2378
|
+
if (payload.model && !(current?.provider === payload.model.providerId && current?.id === payload.model.modelId)) {
|
|
2379
|
+
await setSessionModel(draftRuntime, payload.model);
|
|
2380
|
+
publishSessionModel(draftRuntime.session, sessionId, targetCwd);
|
|
2381
|
+
}
|
|
2382
|
+
if (payload.thinking !== undefined && draftRuntime.session?.thinkingLevel !== payload.thinking) {
|
|
2383
|
+
applyThinking(draftRuntime, payload.thinking, sessionId, targetCwd);
|
|
2384
|
+
}
|
|
2385
|
+
} catch (error) {
|
|
2386
|
+
// The draft stays a draft, back on its idle lifetime; the send
|
|
2387
|
+
// reports the failure.
|
|
2388
|
+
draftSessionIds.add(sessionId);
|
|
2389
|
+
safeTouchIdleDisposal(sessionId);
|
|
2390
|
+
throw error;
|
|
2391
|
+
}
|
|
2392
|
+
if (payload.title) draftRuntime.session.sessionManager?.appendSessionInfo?.(payload.title.trim());
|
|
2393
|
+
// From here it is an ordinary new session, whose first send arms the
|
|
2394
|
+
// idle lifetime again.
|
|
2395
|
+
runtime = draftRuntime;
|
|
2396
|
+
activeDirectory = targetCwd;
|
|
2397
|
+
rememberRuntimeSession();
|
|
2398
|
+
// Published before the reply is built, so the reply's sequence covers it.
|
|
2399
|
+
// A client never saw the draft's events (they were marked `draft`); if
|
|
2400
|
+
// this event reached it before the reply and the reply were older, it
|
|
2401
|
+
// would keep its own empty copy of the session's controls.
|
|
2402
|
+
const createdTitle = (typeof payload.title === 'string' ? payload.title.trim() : '')
|
|
2403
|
+
|| draftRuntime.session?.sessionManager?.getSessionName?.();
|
|
2404
|
+
if (createdTitle) {
|
|
2405
|
+
publish('session.updated', { title: redactAttachmentPaths(createdTitle) }, sessionId, targetCwd);
|
|
2406
|
+
}
|
|
2407
|
+
return projectActiveSession(draftRuntime, targetCwd);
|
|
2408
|
+
};
|
|
2409
|
+
|
|
2410
|
+
/**
|
|
2411
|
+
* Stop a draft's session when the draft closes or moves to another folder.
|
|
2412
|
+
* Only a draft can be discarded this way, and always is: its dialogs are
|
|
2413
|
+
* cancelled, its surfaces closed, and anything running stopped first.
|
|
2414
|
+
*/
|
|
2415
|
+
const discardDraftSession = async (sessionId) => {
|
|
2416
|
+
if (!draftSessionIds.has(sessionId)) return { discarded: false };
|
|
2417
|
+
if (!runtimeRegistry?.findBySessionId(sessionId)) {
|
|
2418
|
+
draftSessionIds.delete(sessionId);
|
|
2419
|
+
return { discarded: true };
|
|
2420
|
+
}
|
|
2421
|
+
await disposeIdleSessionRuntime(sessionId);
|
|
2422
|
+
const gone = !runtimeRegistry?.findBySessionId(sessionId);
|
|
2423
|
+
if (gone) draftSessionIds.delete(sessionId);
|
|
2424
|
+
return { discarded: gone };
|
|
2425
|
+
};
|
|
2426
|
+
|
|
2175
2427
|
const createSession = async (payload) => {
|
|
2176
2428
|
const explicitRetryLimit = payload && typeof payload === 'object' ? (payload.maxRetries ?? payload.retryLimit ?? payload.defaultRetryLimit) : undefined;
|
|
2177
2429
|
if (explicitRetryLimit !== undefined && (!Number.isInteger(explicitRetryLimit) || explicitRetryLimit < 0 || explicitRetryLimit > 10)) {
|
|
@@ -2181,9 +2433,14 @@ export function createSessionDaemon({
|
|
|
2181
2433
|
|| (payload.cwd !== undefined && (typeof payload.cwd !== 'string' || payload.cwd.length === 0))
|
|
2182
2434
|
|| (payload.title !== undefined && (typeof payload.title !== 'string' || payload.title.trim().length === 0 || payload.title.length > 256))
|
|
2183
2435
|
|| (payload.thinking !== undefined && !isPiThinkingLevel(payload.thinking))
|
|
2184
|
-
|| (payload.model !== undefined && (!payload.model || typeof payload.model.providerId !== 'string' || typeof payload.model.modelId !== 'string'))
|
|
2436
|
+
|| (payload.model !== undefined && (!payload.model || typeof payload.model.providerId !== 'string' || typeof payload.model.modelId !== 'string'))
|
|
2437
|
+
|| (payload.draft !== undefined && typeof payload.draft !== 'boolean')
|
|
2438
|
+
|| (payload.draftSessionId !== undefined && (typeof payload.draftSessionId !== 'string' || payload.draftSessionId.length === 0 || payload.draftSessionId.length > 128))
|
|
2439
|
+
// A draft has no title, parent, or draft of its own yet.
|
|
2440
|
+
|| (payload.draft === true && (payload.title !== undefined || payload.parentId !== undefined || payload.draftSessionId !== undefined))) {
|
|
2185
2441
|
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The requested session creation options are invalid.');
|
|
2186
2442
|
}
|
|
2443
|
+
const draft = payload.draft === true;
|
|
2187
2444
|
try {
|
|
2188
2445
|
await flushPendingRuntimeRecreation();
|
|
2189
2446
|
} catch {
|
|
@@ -2194,16 +2451,35 @@ export function createSessionDaemon({
|
|
|
2194
2451
|
const targetCwd = await resolveDirectory(payload.cwd);
|
|
2195
2452
|
await validatePiSessionJsonlDirectory({ cwd: targetCwd, agentDir });
|
|
2196
2453
|
const parent = payload.parentId === undefined ? undefined : (await findPersistedSession(payload.parentId, targetCwd)).target;
|
|
2454
|
+
if (payload.draftSessionId !== undefined) {
|
|
2455
|
+
const adopted = await adoptDraftSession(payload, targetCwd, parent);
|
|
2456
|
+
if (adopted) return adopted;
|
|
2457
|
+
}
|
|
2197
2458
|
if (!runtimeRegistry) {
|
|
2198
2459
|
runtimeRegistry = createSessionRuntimeRegistry({
|
|
2199
2460
|
onSessionEvent: ({ cwd: eventCwd, sessionId: eventSessionId }, event) => publishSessionEvent(eventSessionId, event, eventCwd),
|
|
2200
2461
|
});
|
|
2201
2462
|
}
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2463
|
+
// A draft's sessions are marked from the moment Pi assigns their ids:
|
|
2464
|
+
// the runtime's first session (replaced below) and the draft itself.
|
|
2465
|
+
const markedDraftIds = new Set();
|
|
2466
|
+
const markDraft = (manager) => {
|
|
2467
|
+
const id = manager?.getSessionId?.();
|
|
2468
|
+
if (typeof id !== 'string' || id.length === 0) return;
|
|
2469
|
+
markedDraftIds.add(id);
|
|
2470
|
+
draftSessionIds.add(id);
|
|
2471
|
+
};
|
|
2472
|
+
let newRuntime;
|
|
2473
|
+
try {
|
|
2474
|
+
newRuntime = await createRuntime({
|
|
2475
|
+
cwd: targetCwd,
|
|
2476
|
+
agentDir,
|
|
2477
|
+
...(parent ? { sessionFile: parent.path } : {}),
|
|
2478
|
+
}, draft ? { beforeSession: markDraft } : undefined);
|
|
2479
|
+
} catch (error) {
|
|
2480
|
+
for (const id of markedDraftIds) draftSessionIds.delete(id);
|
|
2481
|
+
throw error;
|
|
2482
|
+
}
|
|
2207
2483
|
if (!newRuntime.cwd) newRuntime.cwd = targetCwd;
|
|
2208
2484
|
// Apply default retry limit for new sessions. Explicit per-run overrides win.
|
|
2209
2485
|
// With no PiChamber override configured, Pi's own retry settings stay
|
|
@@ -2233,18 +2509,30 @@ export function createSessionDaemon({
|
|
|
2233
2509
|
result = await newRuntime.newSession({
|
|
2234
2510
|
...(parent ? { parentSession: parent.path } : {}),
|
|
2235
2511
|
...(payload.title ? { setup: async (manager) => manager.appendSessionInfo(payload.title.trim()) } : {}),
|
|
2512
|
+
// An injected runtime factory may not call `beforeSession`.
|
|
2513
|
+
...(draft ? { setup: async (manager) => markDraft(manager) } : {}),
|
|
2236
2514
|
});
|
|
2237
2515
|
} else if (payload.title && newRuntime.session?.sessionManager?.appendSessionInfo) {
|
|
2238
2516
|
newRuntime.session.sessionManager.appendSessionInfo(payload.title.trim());
|
|
2239
2517
|
}
|
|
2240
2518
|
if (result?.cancelled) {
|
|
2519
|
+
// Dispose before unmarking, so what disposal publishes stays `draft`.
|
|
2241
2520
|
try { await newRuntime.dispose?.(); } catch { /* the cancelled create owns nothing */ }
|
|
2521
|
+
for (const id of markedDraftIds) draftSessionIds.delete(id);
|
|
2242
2522
|
throw new SessionDaemonProtocolError('SESSION_CREATE_CANCELLED', 'Pi cancelled session creation.');
|
|
2243
2523
|
}
|
|
2524
|
+
if (draft) {
|
|
2525
|
+
const draftId = newRuntime.session?.sessionId;
|
|
2526
|
+
// The replaced first session is gone; only the draft keeps its mark.
|
|
2527
|
+
for (const id of markedDraftIds) if (id !== draftId) draftSessionIds.delete(id);
|
|
2528
|
+
if (draftId) draftSessionIds.add(draftId);
|
|
2529
|
+
}
|
|
2244
2530
|
try {
|
|
2245
2531
|
await acquireResidentLease({ cwd: targetCwd, sessionId: newRuntime.session.sessionId });
|
|
2246
2532
|
} catch (error) {
|
|
2533
|
+
const failedDraftId = newRuntime.session?.sessionId;
|
|
2247
2534
|
try { await newRuntime.dispose?.(); } catch { /* the failed create owns nothing */ }
|
|
2535
|
+
draftSessionIds.delete(failedDraftId);
|
|
2248
2536
|
throw error;
|
|
2249
2537
|
}
|
|
2250
2538
|
try {
|
|
@@ -2258,9 +2546,13 @@ export function createSessionDaemon({
|
|
|
2258
2546
|
} catch (error) {
|
|
2259
2547
|
const failedSessionId = newRuntime.session?.sessionId;
|
|
2260
2548
|
const failedCwd = targetCwd;
|
|
2549
|
+
// Unmarked only once disposal is done (or failed), so its events stay
|
|
2550
|
+
// `draft`.
|
|
2261
2551
|
try {
|
|
2262
2552
|
await newRuntime.dispose?.();
|
|
2553
|
+
draftSessionIds.delete(failedSessionId);
|
|
2263
2554
|
} catch {
|
|
2555
|
+
draftSessionIds.delete(failedSessionId);
|
|
2264
2556
|
// Dispose-first cleanup rejected: retain ownership for a later
|
|
2265
2557
|
// delete/stop retry. Do not release the lease, install dormant
|
|
2266
2558
|
// state, or register the runtime. The original model/thinking
|
|
@@ -2278,6 +2570,14 @@ export function createSessionDaemon({
|
|
|
2278
2570
|
throw error;
|
|
2279
2571
|
}
|
|
2280
2572
|
runtimeRegistry.register(newRuntime, { cwd: targetCwd });
|
|
2573
|
+
if (draft) {
|
|
2574
|
+
// A draft is not the daemon's active session and is not remembered
|
|
2575
|
+
// for a restart: nothing has been sent in it. It gets the idle
|
|
2576
|
+
// lifetime of any view-only session, so an abandoned draft goes away.
|
|
2577
|
+
rebuildSessionExtensionState(newRuntime);
|
|
2578
|
+
touchIdleDisposal(newRuntime.session.sessionId);
|
|
2579
|
+
return projectActiveSession(newRuntime, targetCwd);
|
|
2580
|
+
}
|
|
2281
2581
|
runtime = newRuntime;
|
|
2282
2582
|
activeDirectory = targetCwd;
|
|
2283
2583
|
rebuildSessionExtensionState(newRuntime);
|
|
@@ -2811,6 +3111,55 @@ export function createSessionDaemon({
|
|
|
2811
3111
|
};
|
|
2812
3112
|
};
|
|
2813
3113
|
|
|
3114
|
+
// `pi config` / `pi list` / `pi remove` for extensions (extension-config.js).
|
|
3115
|
+
// Writes share the resource mutation queue and the shared Pi config lock,
|
|
3116
|
+
// read trust inside the lock, and recreate resident runtimes afterwards.
|
|
3117
|
+
const extensionConfigService = createExtensionConfig({ agentDir, createSettingsManager });
|
|
3118
|
+
const extensionConfigTarget = async (payload) => {
|
|
3119
|
+
const directory = typeof payload?.directory === 'string' && payload.directory.trim().length > 0
|
|
3120
|
+
? await resolveDirectory(payload.directory)
|
|
3121
|
+
: undefined;
|
|
3122
|
+
// Pi's own rule (`resolveProjectTrusted`): a saved decision wins, and a
|
|
3123
|
+
// project with nothing that needs trust counts as trusted, as it does for
|
|
3124
|
+
// `pi config -l`. `resolveDirectory` has already saved trust for a folder
|
|
3125
|
+
// that has project resources, so only a denied project is left out.
|
|
3126
|
+
const decision = directory ? createTrustStore(agentDir).get(directory) : null;
|
|
3127
|
+
return {
|
|
3128
|
+
cwd: activeDirectory || cwd,
|
|
3129
|
+
directory,
|
|
3130
|
+
trusted: directory ? decision ?? !hasTrustRequiringProjectResources(directory) : false,
|
|
3131
|
+
};
|
|
3132
|
+
};
|
|
3133
|
+
// What a live runtime left out because another extension took its names.
|
|
3134
|
+
// Never starts a runtime: with none resident, or one that predates a queued
|
|
3135
|
+
// recreation, the answer is unknown and the field is left out.
|
|
3136
|
+
const liveExtensionReplacements = (target) => {
|
|
3137
|
+
if (pendingRuntimeRecreation) return undefined;
|
|
3138
|
+
const resident = (runtimeRegistry?.listByDirectory?.(resolve(target.directory ?? target.cwd)) ?? [])
|
|
3139
|
+
.filter((entry) => !draftSessionIds.has(entry?.session?.sessionId));
|
|
3140
|
+
const entry = resident.includes(runtime) ? runtime : resident[0];
|
|
3141
|
+
if (!entry) return undefined;
|
|
3142
|
+
return describeRuntimeReplacements({
|
|
3143
|
+
session: entry.session,
|
|
3144
|
+
configuredPluginIds: pluginHost.configuredIds(),
|
|
3145
|
+
registeredNames: pluginHost.registeredNames(),
|
|
3146
|
+
});
|
|
3147
|
+
};
|
|
3148
|
+
const listExtensionConfig = async (payload) => {
|
|
3149
|
+
const target = await extensionConfigTarget(payload);
|
|
3150
|
+
return extensionConfigService.list(target, liveExtensionReplacements(target));
|
|
3151
|
+
};
|
|
3152
|
+
const mutateExtensionConfig = (payload, write) => transactResourceMutation(async () => {
|
|
3153
|
+
const target = await withSharedPiConfigLock(async () => {
|
|
3154
|
+
const resolved = await extensionConfigTarget(payload);
|
|
3155
|
+
await write(resolved);
|
|
3156
|
+
return resolved;
|
|
3157
|
+
});
|
|
3158
|
+
const deferred = activeRuntimes().length > 0 ? await scheduleRuntimeRecreation() : false;
|
|
3159
|
+
const result = await extensionConfigService.list(target, liveExtensionReplacements(target));
|
|
3160
|
+
return deferred ? { ...result, deferred: true } : result;
|
|
3161
|
+
});
|
|
3162
|
+
|
|
2814
3163
|
const resourceId = (kind, filePath) => `${kind}:${createHash('sha256').update(filePath).digest('base64url')}`;
|
|
2815
3164
|
|
|
2816
3165
|
const isPathInside = (parent, candidate) => {
|
|
@@ -3187,8 +3536,18 @@ export function createSessionDaemon({
|
|
|
3187
3536
|
const next = model && (model.reasoning === true || model.thinkingLevelMap)
|
|
3188
3537
|
? clampThinkingLevel(getSupportedThinkingLevels(model), thinking)
|
|
3189
3538
|
: thinking;
|
|
3539
|
+
const previous = runtime.session.thinkingLevel;
|
|
3190
3540
|
runtime.session.setThinkingLevel(next);
|
|
3191
|
-
|
|
3541
|
+
const effective = runtime.session.thinkingLevel ?? next;
|
|
3542
|
+
// Exactly one `session.thinking` per change. Pi emits
|
|
3543
|
+
// `thinking_level_changed` (published by `publishSessionEvent`) when the
|
|
3544
|
+
// level changes on a runtime the registry subscribes to; publish here
|
|
3545
|
+
// only when it will not: an unchanged level (the caller still gets its
|
|
3546
|
+
// echo) or a runtime not yet registered (a session being created).
|
|
3547
|
+
const changed = effective !== previous;
|
|
3548
|
+
const subscribed = runtimeRegistry?.findBySessionId?.(sessionId) === runtime;
|
|
3549
|
+
if (changed && subscribed) return;
|
|
3550
|
+
publish('session.thinking', { thinking: effective }, sessionId, directory);
|
|
3192
3551
|
};
|
|
3193
3552
|
|
|
3194
3553
|
const validateThinking = (thinking) => {
|
|
@@ -3510,12 +3869,18 @@ export function createSessionDaemon({
|
|
|
3510
3869
|
// idle disposal, which reports the session as deleted when its assigned JSONL
|
|
3511
3870
|
// is positively absent (see disposeIdleSessionRuntime).
|
|
3512
3871
|
|
|
3513
|
-
|
|
3872
|
+
// `keepDraft`: a composer control runs a command without sending the
|
|
3873
|
+
// composer, so the extension's view of the draft stays as it is.
|
|
3874
|
+
// `requireExtensionCommand`: the text must be a command the session's
|
|
3875
|
+
// extensions register once the runtime is settled, or nothing runs. A
|
|
3876
|
+
// composer control sets it, so its `/command` never reaches the model as a
|
|
3877
|
+
// prompt when a queued recreation drops the extension behind it.
|
|
3878
|
+
const runSessionInput = async (payload, delivery, { keepDraft = false, requireExtensionCommand = false } = {}) => {
|
|
3514
3879
|
if (!payload || typeof payload !== 'object' || typeof payload.sessionId !== 'string'
|
|
3515
3880
|
|| typeof payload.text !== 'string' || payload.text.length === 0 || Buffer.byteLength(payload.text) > 64 * 1024) {
|
|
3516
3881
|
throw new SessionDaemonProtocolError('INVALID_PROMPT', 'The session prompt is invalid.');
|
|
3517
3882
|
}
|
|
3518
|
-
resetExtensionDraft(payload.sessionId);
|
|
3883
|
+
if (!keepDraft) resetExtensionDraft(payload.sessionId);
|
|
3519
3884
|
if (payload.thinking !== undefined) validateThinking(payload.thinking);
|
|
3520
3885
|
// Idle protection is owned by the request-dispatch guard: it holds the
|
|
3521
3886
|
// session refcount across activation/acceptance, agent_start clears once
|
|
@@ -3581,6 +3946,9 @@ export function createSessionDaemon({
|
|
|
3581
3946
|
&& Array.isArray(registeredExtensionCommands)
|
|
3582
3947
|
&& registeredExtensionCommands.some((command) => command?.invocationName === slashInvocation),
|
|
3583
3948
|
);
|
|
3949
|
+
if (requireExtensionCommand && !isExtensionCommand) {
|
|
3950
|
+
throw new SessionDaemonProtocolError('CONTROL_UNAVAILABLE', 'The command for this control is not available.');
|
|
3951
|
+
}
|
|
3584
3952
|
// Like the Pi CLI, never persist an auto-title. Lists derive the display
|
|
3585
3953
|
// title from the first user prompt; publish that derived title live (not
|
|
3586
3954
|
// persisted) so connected surfaces converge without waiting for a list.
|
|
@@ -3626,11 +3994,7 @@ export function createSessionDaemon({
|
|
|
3626
3994
|
// describeCustomOrigin). Cleared when the command settles.
|
|
3627
3995
|
const commandMarker = isExtensionCommand ? { name: slashInvocation } : undefined;
|
|
3628
3996
|
if (commandMarker) runningCommandBySession.set(payload.sessionId, commandMarker);
|
|
3629
|
-
|
|
3630
|
-
promptClientBySession.set(payload.sessionId, payload.clientId);
|
|
3631
|
-
} else {
|
|
3632
|
-
promptClientBySession.delete(payload.sessionId);
|
|
3633
|
-
}
|
|
3997
|
+
recordInputClient(payload.sessionId, payload.clientId);
|
|
3634
3998
|
// True SDK acceptance: await the prompt preflight signal, not the full
|
|
3635
3999
|
// agent turn. In SDK 1.0.0, preflightResult is called on acceptance with
|
|
3636
4000
|
// a PromptDisposition ("started" | "queued" | "handled"). Rejections
|
|
@@ -3801,6 +4165,69 @@ export function createSessionDaemon({
|
|
|
3801
4165
|
}
|
|
3802
4166
|
};
|
|
3803
4167
|
|
|
4168
|
+
/**
|
|
4169
|
+
* A click on a composer control: run the extension command the control
|
|
4170
|
+
* names for the value the client asks for, as if it had been typed. Only a
|
|
4171
|
+
* command the session's extensions registered runs; anything else would
|
|
4172
|
+
* reach the model as a prompt. A stale click (the control is gone, or
|
|
4173
|
+
* already has that value) runs nothing and answers `ran: false`.
|
|
4174
|
+
*/
|
|
4175
|
+
// Composer-control commands in flight per session, so adopting a draft
|
|
4176
|
+
// can wait for them (`adoptDraftSession`).
|
|
4177
|
+
const controlRunsBySession = new Map();
|
|
4178
|
+
const CONTROL_RUN_ADOPT_WAIT_MS = 5000;
|
|
4179
|
+
const waitForControlRuns = async (sessionId) => {
|
|
4180
|
+
const runs = controlRunsBySession.get(sessionId);
|
|
4181
|
+
if (!runs || runs.size === 0) return;
|
|
4182
|
+
let timer;
|
|
4183
|
+
await Promise.race([
|
|
4184
|
+
Promise.allSettled([...runs]),
|
|
4185
|
+
new Promise((resolveWait) => { timer = setTimeout(resolveWait, CONTROL_RUN_ADOPT_WAIT_MS); }),
|
|
4186
|
+
]);
|
|
4187
|
+
clearTimeout(timer);
|
|
4188
|
+
};
|
|
4189
|
+
|
|
4190
|
+
const runComposerControl = async (payload) => {
|
|
4191
|
+
const sessionId = payload?.sessionId;
|
|
4192
|
+
const id = payload?.id;
|
|
4193
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0 || sessionId.length > 256
|
|
4194
|
+
|| typeof id !== 'string' || id.length === 0 || id.length > 64) {
|
|
4195
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The control request is invalid.');
|
|
4196
|
+
}
|
|
4197
|
+
const resolved = extensionBridge.resolveComposerControl(sessionId, id, payload.value);
|
|
4198
|
+
if (resolved.error === 'CONTROL_NOT_FOUND') return { ran: false };
|
|
4199
|
+
if (resolved.error) throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The control value is invalid.');
|
|
4200
|
+
if (resolved.command === null) return { ran: false };
|
|
4201
|
+
const target = runtimeRegistry?.findBySessionId(sessionId)
|
|
4202
|
+
|| (runtime?.session?.sessionId === sessionId ? runtime : undefined);
|
|
4203
|
+
const registered = target?.session?.extensionRunner?.getRegisteredCommands?.();
|
|
4204
|
+
const name = commandName(resolved.command);
|
|
4205
|
+
if (!Array.isArray(registered) || !registered.some((command) => command?.invocationName === name)) {
|
|
4206
|
+
throw new SessionDaemonProtocolError('CONTROL_UNAVAILABLE', 'The command for this control is not available.');
|
|
4207
|
+
}
|
|
4208
|
+
const clientId = typeof payload.clientId === 'string' && payload.clientId.length > 0 && payload.clientId.length <= 128
|
|
4209
|
+
? payload.clientId
|
|
4210
|
+
: undefined;
|
|
4211
|
+
// Pi runs extension commands at once, also during a turn; `steer` only
|
|
4212
|
+
// lets the daemon accept the input while the session streams.
|
|
4213
|
+
const run = runSessionInput({
|
|
4214
|
+
sessionId,
|
|
4215
|
+
text: `/${resolved.command}`,
|
|
4216
|
+
directory: target.cwd,
|
|
4217
|
+
...(clientId ? { clientId } : {}),
|
|
4218
|
+
}, target.session.isStreaming ? 'steer' : undefined, { keepDraft: true, requireExtensionCommand: true });
|
|
4219
|
+
const runs = controlRunsBySession.get(sessionId) ?? new Set();
|
|
4220
|
+
controlRunsBySession.set(sessionId, runs);
|
|
4221
|
+
runs.add(run);
|
|
4222
|
+
try {
|
|
4223
|
+
await run;
|
|
4224
|
+
} finally {
|
|
4225
|
+
runs.delete(run);
|
|
4226
|
+
if (runs.size === 0 && controlRunsBySession.get(sessionId) === runs) controlRunsBySession.delete(sessionId);
|
|
4227
|
+
}
|
|
4228
|
+
return { ran: true };
|
|
4229
|
+
};
|
|
4230
|
+
|
|
3804
4231
|
const treeForSession = async (sessionId, requestedDirectory) => {
|
|
3805
4232
|
// Idle protection is owned by the request-dispatch guard; the release
|
|
3806
4233
|
// re-arms even when projection below throws.
|
|
@@ -3871,6 +4298,7 @@ export function createSessionDaemon({
|
|
|
3871
4298
|
latestUserMessageIds.delete(sessionId);
|
|
3872
4299
|
latestAssistantMessageIds.delete(sessionId);
|
|
3873
4300
|
toolInputBySession.delete(sessionId);
|
|
4301
|
+
toolPartialBySession.delete(sessionId);
|
|
3874
4302
|
clearToolTimingsForSession(sessionId);
|
|
3875
4303
|
extensionToolRenderer.clearSession(sessionId);
|
|
3876
4304
|
// Explicit typed deletion: every connected and replaying client drops
|
|
@@ -4064,6 +4492,7 @@ export function createSessionDaemon({
|
|
|
4064
4492
|
const activeRuntime = runtimeRegistry?.get({ cwd: directory, sessionId }) || runtime;
|
|
4065
4493
|
const toolArgs = event.args ?? getToolInput(sessionId, event.toolCallId);
|
|
4066
4494
|
const projected = projectToolResult(event.partialResult, false);
|
|
4495
|
+
rememberToolPartial(sessionId, event.toolCallId, projected);
|
|
4067
4496
|
const metadata = mergeToolPresentationMetadata(projected.metadata, activeRuntime, directory, event.toolName, toolArgs);
|
|
4068
4497
|
const definition = extensionToolRenderer.resolve(activeRuntime?.session, event.toolName);
|
|
4069
4498
|
let render;
|
|
@@ -4178,6 +4607,18 @@ export function createSessionDaemon({
|
|
|
4178
4607
|
clearIdleDisposal(sessionId);
|
|
4179
4608
|
retryStateBySession.delete(sessionId);
|
|
4180
4609
|
if (!activeRunStartedAt.has(sessionId)) activeRunStartedAt.set(sessionId, Date.now());
|
|
4610
|
+
// A model turn in a draft (a control's command calling
|
|
4611
|
+
// `sendUserMessage`) ends the draft: Pi has written the session
|
|
4612
|
+
// file with the user message by now, and the turn is real work the
|
|
4613
|
+
// user must be able to see. The session becomes an ordinary one
|
|
4614
|
+
// here, at the first event Pi reports for the turn. The drafting
|
|
4615
|
+
// client hears one last marked event, this busy state without a
|
|
4616
|
+
// `command`, and lets go of the draft; everything after it is
|
|
4617
|
+
// unmarked, so every client lists the session as running.
|
|
4618
|
+
if (draftSessionIds.has(sessionId)) {
|
|
4619
|
+
publish('session.lifecycle', { state: 'busy', runStartedAt: activeRunStartedAt.get(sessionId), serverNow: Date.now() }, sessionId, directory);
|
|
4620
|
+
draftSessionIds.delete(sessionId);
|
|
4621
|
+
}
|
|
4181
4622
|
publish('session.lifecycle', { state: 'busy', runStartedAt: activeRunStartedAt.get(sessionId), serverNow: Date.now() }, sessionId, directory);
|
|
4182
4623
|
break;
|
|
4183
4624
|
case 'agent_end': {
|
|
@@ -4210,6 +4651,7 @@ export function createSessionDaemon({
|
|
|
4210
4651
|
latestUserMessageIds.delete(sessionId);
|
|
4211
4652
|
latestAssistantMessageIds.delete(sessionId);
|
|
4212
4653
|
toolInputBySession.delete(sessionId);
|
|
4654
|
+
toolPartialBySession.delete(sessionId);
|
|
4213
4655
|
clearToolTimingsForSession(sessionId, { keepCompleted: true });
|
|
4214
4656
|
extensionToolRenderer.clearSession(sessionId);
|
|
4215
4657
|
// A missed tool_execution_end must not title later surfaces.
|
|
@@ -4369,11 +4811,12 @@ export function createSessionDaemon({
|
|
|
4369
4811
|
'projects.list', 'projects.select', 'sessions.list', 'sessions.create', 'sessions.open', 'sessions.messages', 'sessions.rename', 'sessions.delete',
|
|
4370
4812
|
'sessions.tree', 'sessions.navigate', 'sessions.fork', 'sessions.clone', 'sessions.prompt',
|
|
4371
4813
|
'sessions.steer', 'sessions.followUp', 'sessions.sendReceipt', 'sessions.pendingInput', 'sessions.abort', 'sessions.setModel',
|
|
4372
|
-
'sessions.setThinking', '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',
|
|
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',
|
|
4373
4815
|
'providers.login.respond', 'providers.login.status', 'providers.logout', 'settings.get', 'settings.set',
|
|
4374
4816
|
'resources.list', 'resources.update', 'resources.prompts.create', 'resources.prompts.update', 'resources.prompts.delete',
|
|
4375
|
-
'extensions.list', 'extensions.respond', 'extensions.draft',
|
|
4376
|
-
'
|
|
4817
|
+
'extensions.list', 'extensions.respond', 'extensions.control', 'extensions.draft', 'extensions.palette',
|
|
4818
|
+
'extensions.config.list', 'extensions.config.set', 'extensions.packages.remove',
|
|
4819
|
+
'openUrl.publish', 'archive.publish', 'plugins.configure',
|
|
4377
4820
|
'extensions.custom.input', 'extensions.custom.viewport', 'extensions.custom.close', 'extensions.custom.focus', 'extensions.custom.refresh',
|
|
4378
4821
|
],
|
|
4379
4822
|
...(Number.isInteger(healthMetadata.daemonPid) ? { daemonPid: healthMetadata.daemonPid } : {}),
|
|
@@ -4542,6 +4985,15 @@ export function createSessionDaemon({
|
|
|
4542
4985
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
4543
4986
|
return;
|
|
4544
4987
|
}
|
|
4988
|
+
case 'plugins.configure': {
|
|
4989
|
+
// Private, server-only. A changed enabled set recreates runtimes at
|
|
4990
|
+
// the next safe edge; a state-only change reaches live runtimes
|
|
4991
|
+
// through their `pichamber.onStateChange` listeners.
|
|
4992
|
+
const { enabledChanged, plugins } = await pluginHost.configure(message.payload);
|
|
4993
|
+
const deferred = enabledChanged ? await scheduleRuntimeRecreation() : false;
|
|
4994
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: { plugins, enabledChanged, deferred } });
|
|
4995
|
+
return;
|
|
4996
|
+
}
|
|
4545
4997
|
case 'resources.list': {
|
|
4546
4998
|
const result = publicResources(await resourceCatalog(message.payload?.directory));
|
|
4547
4999
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
@@ -4567,11 +5019,31 @@ export function createSessionDaemon({
|
|
|
4567
5019
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
4568
5020
|
return;
|
|
4569
5021
|
}
|
|
5022
|
+
case 'extensions.config.list': {
|
|
5023
|
+
const result = await listExtensionConfig(message.payload);
|
|
5024
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5025
|
+
return;
|
|
5026
|
+
}
|
|
5027
|
+
case 'extensions.config.set': {
|
|
5028
|
+
const result = await mutateExtensionConfig(message.payload, (target) => extensionConfigService.set(target, message.payload));
|
|
5029
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5030
|
+
return;
|
|
5031
|
+
}
|
|
5032
|
+
case 'extensions.packages.remove': {
|
|
5033
|
+
const result = await mutateExtensionConfig(message.payload, (target) => extensionConfigService.removePackage(target, message.payload));
|
|
5034
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5035
|
+
return;
|
|
5036
|
+
}
|
|
4570
5037
|
case 'extensions.respond': {
|
|
4571
5038
|
const resolution = await resolveExtensionDialog(message.payload);
|
|
4572
5039
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: resolution });
|
|
4573
5040
|
return;
|
|
4574
5041
|
}
|
|
5042
|
+
case 'extensions.control': {
|
|
5043
|
+
const result = await runComposerControl(message.payload);
|
|
5044
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5045
|
+
return;
|
|
5046
|
+
}
|
|
4575
5047
|
case 'extensions.custom.input':
|
|
4576
5048
|
case 'extensions.custom.viewport':
|
|
4577
5049
|
case 'extensions.custom.close':
|
|
@@ -4592,6 +5064,21 @@ export function createSessionDaemon({
|
|
|
4592
5064
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
4593
5065
|
return;
|
|
4594
5066
|
}
|
|
5067
|
+
case 'extensions.palette': {
|
|
5068
|
+
const terminal = message.payload?.terminal;
|
|
5069
|
+
if (!isTerminalColors(terminal)) {
|
|
5070
|
+
throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The terminal colours are invalid.');
|
|
5071
|
+
}
|
|
5072
|
+
// Pi's theme setting is global; a project's own setting is not read.
|
|
5073
|
+
const settings = createSettingsManager({ cwd: activeDirectory || cwd, agentDir, projectTrusted: false });
|
|
5074
|
+
// Unreadable settings are a failure, not the system theme: the
|
|
5075
|
+
// browser keeps PiChamber's colours instead of caching a wrong answer.
|
|
5076
|
+
if (settings.drainErrors().length > 0) throw new SessionDaemonProtocolError('PI_SETTINGS_INVALID', 'Pi settings could not be read.');
|
|
5077
|
+
const themeSetting = settings.getThemeSetting();
|
|
5078
|
+
const result = await resolveExtensionPalette({ themeSetting, terminal });
|
|
5079
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5080
|
+
return;
|
|
5081
|
+
}
|
|
4595
5082
|
case 'extensions.list': {
|
|
4596
5083
|
const requestedExtensionsDir = message.payload?.directory || message.payload?.cwd;
|
|
4597
5084
|
const activeRuntime = await ensureRuntime(requestedExtensionsDir ? await resolveDirectory(requestedExtensionsDir) : undefined);
|
|
@@ -4610,6 +5097,8 @@ export function createSessionDaemon({
|
|
|
4610
5097
|
directory: activeRuntime.cwd,
|
|
4611
5098
|
extensions: (Array.isArray(extensionPaths) ? extensionPaths : [])
|
|
4612
5099
|
.filter((extensionPath) => typeof extensionPath === 'string' && extensionPath.length > 0)
|
|
5100
|
+
// PiChamber's own listener is part of the app, not an extension.
|
|
5101
|
+
.filter((extensionPath) => !isComposerControlsExtensionPath(extensionPath))
|
|
4613
5102
|
// Opaque id only: server filesystem paths must never reach the
|
|
4614
5103
|
// browser (see DOCUMENTATION.md route invariants).
|
|
4615
5104
|
.map((extensionPath) => ({
|
|
@@ -4661,15 +5150,20 @@ export function createSessionDaemon({
|
|
|
4661
5150
|
const residentRuntimes = new Set();
|
|
4662
5151
|
if (runtime?.session?.sessionId) residentRuntimes.add(runtime);
|
|
4663
5152
|
for (const tracked of runtimeRegistry?.listAll?.() ?? []) residentRuntimes.add(tracked);
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
5153
|
+
// Drafts are no target: no client shows them.
|
|
5154
|
+
const residents = [...residentRuntimes]
|
|
5155
|
+
.filter((tracked) => !draftSessionIds.has(tracked?.session?.sessionId))
|
|
5156
|
+
.map((tracked) => ({
|
|
5157
|
+
sessionId: tracked?.session?.sessionId,
|
|
5158
|
+
directory: typeof tracked?.cwd === 'string' && tracked.cwd.length > 0 ? tracked.cwd : (activeDirectory || cwd),
|
|
5159
|
+
busy: tracked?.session?.isStreaming === true
|
|
5160
|
+
|| tracked?.session?.isCompacting === true
|
|
5161
|
+
|| activeSessionInputs.has(tracked),
|
|
5162
|
+
}));
|
|
4671
5163
|
const target = resolveOpenRequestSession({
|
|
4672
|
-
requestedSessionId: typeof message.payload?.sessionId === 'string'
|
|
5164
|
+
requestedSessionId: typeof message.payload?.sessionId === 'string' && !draftSessionIds.has(message.payload.sessionId)
|
|
5165
|
+
? message.payload.sessionId
|
|
5166
|
+
: undefined,
|
|
4673
5167
|
residents,
|
|
4674
5168
|
recent: lastPublishedSession,
|
|
4675
5169
|
});
|
|
@@ -4699,7 +5193,7 @@ export function createSessionDaemon({
|
|
|
4699
5193
|
protocolVersion: PROTOCOL_VERSION,
|
|
4700
5194
|
kind: 'response',
|
|
4701
5195
|
requestId: message.requestId,
|
|
4702
|
-
result: { sessions: pendingInput.list(), sequence, streamEpoch },
|
|
5196
|
+
result: { sessions: pendingInput.list().filter((entry) => !draftSessionIds.has(entry?.sessionId)), sequence, streamEpoch },
|
|
4703
5197
|
});
|
|
4704
5198
|
return;
|
|
4705
5199
|
}
|
|
@@ -4755,6 +5249,15 @@ export function createSessionDaemon({
|
|
|
4755
5249
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: {} });
|
|
4756
5250
|
return;
|
|
4757
5251
|
}
|
|
5252
|
+
case 'sessions.discardDraft': {
|
|
5253
|
+
// Not in the session-access guard: holding access would make the
|
|
5254
|
+
// disposal it asks for unsafe.
|
|
5255
|
+
const sessionId = message.payload?.sessionId;
|
|
5256
|
+
if (!isValidIdleSessionId(sessionId)) throw new SessionDaemonProtocolError('INVALID_ARGUMENT', 'The draft session is invalid.');
|
|
5257
|
+
const result = await discardDraftSession(sessionId);
|
|
5258
|
+
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result });
|
|
5259
|
+
return;
|
|
5260
|
+
}
|
|
4758
5261
|
case 'sessions.delete': {
|
|
4759
5262
|
await deleteSession(message.payload?.sessionId, message.payload?.directory || message.payload?.cwd);
|
|
4760
5263
|
writeFrame(socket, { protocolVersion: PROTOCOL_VERSION, kind: 'response', requestId: message.requestId, result: {} });
|
|
@@ -4902,6 +5405,9 @@ export function createSessionDaemon({
|
|
|
4902
5405
|
if (commandOnlyRun(message.payload.sessionId, activeRuntime.session)) {
|
|
4903
5406
|
throw new SessionDaemonProtocolError('SESSION_BUSY', 'An extension command is still running.');
|
|
4904
5407
|
}
|
|
5408
|
+
// A `!command` is input too: an extension's user_bash handler can
|
|
5409
|
+
// open custom() surfaces, drawn at the size of the tab that ran it.
|
|
5410
|
+
recordInputClient(message.payload.sessionId, message.payload.clientId);
|
|
4905
5411
|
let started;
|
|
4906
5412
|
try {
|
|
4907
5413
|
started = userBash.start({
|
|
@@ -5143,6 +5649,7 @@ export function createSessionDaemon({
|
|
|
5143
5649
|
compactionStateBySession.clear();
|
|
5144
5650
|
activeRunStartedAt.clear();
|
|
5145
5651
|
toolStartedAt.clear();
|
|
5652
|
+
toolPartialBySession.clear();
|
|
5146
5653
|
completedToolTimings.clear();
|
|
5147
5654
|
shutdownRequestedBySession.clear();
|
|
5148
5655
|
sendGenerationBySession.clear();
|