@pi-chamber/web 1.0.7-rc.1 → 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-C3rA5DfE.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-OpFCss_4.js → GitView-MIDG5RYW.js} +5 -5
- package/dist/assets/{IssuesSurface-DD6Gz5Ox.js → IssuesSurface-uNlozeu0.js} +2 -2
- package/dist/assets/{JsonTreeView-Dj75jgH6.js → JsonTreeView-CSLsTriz.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-CnIzmT1p.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-CUz6Cc1-.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-J6YOvGcV.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-Dq8pyTGy.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-uXZ9uhI_.js → computeVirtualFileMetrics-DmO6H8u6.js} +2 -2
- package/dist/assets/contextFileOpenGuard-DOK251YW.js +1 -0
- package/dist/assets/{fileTreeStatus-C_7jbeGv.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-DD0xW5WE.js → index-DMX9wT1Z.js} +1 -1
- package/dist/assets/{main-BnWf2tm9.js → main-BW9J3Y72.js} +2 -2
- package/dist/assets/main-BirYxac2.js +137 -0
- package/dist/assets/{markdownCore-C-Ulh4n9.js → markdownCore-CxmcPur8.js} +2 -2
- package/dist/assets/miniChat-BRB11eEs.js +2 -0
- package/dist/assets/{mobile-BuAWpKj9.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-DD-iWWus.js → renderDiffWithHighlighter-C48T6YFJ.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-N-BQdJl0.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-B0pofdV1.js → renderFileWithHighlighter-8Kt2MyTN.js} +1 -1
- package/dist/assets/{renderMobileApp-B3P_bita.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-DB-GDG7P.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-DyF8zzYx.js +0 -1
- package/dist/assets/FileSaveConflictDialog-CC4F--8H.js +0 -3
- package/dist/assets/FilesView-Dsg-QTJu.js +0 -6
- package/dist/assets/GitHubDetailScaffold-C9WuBMGr.js +0 -11
- package/dist/assets/GitHubLinkPicker-BkVdYxZT.js +0 -1
- package/dist/assets/GitHubListPrimitives-CcVlv_rJ.js +0 -1
- package/dist/assets/PatchDiff-DND5RBnF.js +0 -1
- package/dist/assets/PierreDiffViewer-Cq5CIrmH.js +0 -147
- package/dist/assets/PullRequestsSurface-g8HAvbFg.js +0 -2
- package/dist/assets/SessionSwitcherDropdown-COZ50Y5a.js +0 -2
- package/dist/assets/SessionUnreadDot-DOUcgBw6.js +0 -1
- package/dist/assets/SettingsView-AFymxZYC.js +0 -6
- package/dist/assets/ToolOutputDialog-5Tc7HM4z.js +0 -8
- package/dist/assets/ToolPartDiffPreview-7GiFbVl7.js +0 -1
- package/dist/assets/contextFileOpenGuard-CckKFYjI.js +0 -1
- package/dist/assets/gitStatusPredicates-CNLvdt2V.js +0 -1
- package/dist/assets/githubLink-0EoMGZKd.js +0 -10
- package/dist/assets/index-BaLCg7tL.css +0 -1
- package/dist/assets/main-yQe-k30g.js +0 -137
- package/dist/assets/miniChat-DKK1hotU.js +0 -2
- package/dist/assets/pi-session-focus-preference-DaWQ2rEE.js +0 -9
- package/dist/assets/renderElectronMiniChatApp-CKuFQBRo.js +0 -2
- package/dist/assets/runtimeEndpointReset-DutinXZK.js +0 -62
- package/dist/assets/runtimeSurface-CFwnvks_.js +0 -1
- package/dist/assets/useAppFontEffects-DQlUEhzN.js +0 -213
- package/dist/assets/useGitHubRemoteSearch-BoZvJAk3.js +0 -1
- package/dist/assets/useSwitcherItems-Dy2yumiU.js +0 -1
|
@@ -85,7 +85,12 @@ class FakeSession {
|
|
|
85
85
|
|
|
86
86
|
async setModel(model) { this.model = model; }
|
|
87
87
|
|
|
88
|
-
setThinkingLevel(thinking) {
|
|
88
|
+
setThinkingLevel(thinking) {
|
|
89
|
+
// Like Pi: an actual change emits `thinking_level_changed`.
|
|
90
|
+
const changed = this.thinkingLevel !== thinking;
|
|
91
|
+
this.thinkingLevel = thinking;
|
|
92
|
+
if (changed) this.emit({ type: 'thinking_level_changed', level: thinking });
|
|
93
|
+
}
|
|
89
94
|
|
|
90
95
|
async abort() { this.aborted += 1; this.isStreaming = false; }
|
|
91
96
|
|
|
@@ -1724,6 +1729,151 @@ describe('Pi session daemon spike', () => {
|
|
|
1724
1729
|
await client.close();
|
|
1725
1730
|
});
|
|
1726
1731
|
|
|
1732
|
+
describe('provider changes before any session reaches disk', () => {
|
|
1733
|
+
const customProvider = {
|
|
1734
|
+
providerId: 'custom',
|
|
1735
|
+
label: 'Custom',
|
|
1736
|
+
baseUrl: 'https://api.example.test/v1',
|
|
1737
|
+
api: 'openai-completions',
|
|
1738
|
+
models: [{ id: 'model', providerId: 'custom', label: 'Model' }],
|
|
1739
|
+
};
|
|
1740
|
+
const echoStore = () => ({
|
|
1741
|
+
get: async () => null,
|
|
1742
|
+
update: async (input) => ({ providerId: input.providerId, label: input.label, baseUrl: input.baseUrl, api: input.api, models: input.models }),
|
|
1743
|
+
});
|
|
1744
|
+
|
|
1745
|
+
// Issue #252: Pi assigns a JSONL path to a fresh session but writes it
|
|
1746
|
+
// only with the first message. Recreating the runtime after a provider
|
|
1747
|
+
// save must not try to reopen that never-written file.
|
|
1748
|
+
it('recreates a fresh catalog runtime instead of reopening an unwritten JSONL', async () => {
|
|
1749
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-provider-fresh-'));
|
|
1750
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1751
|
+
const created = [];
|
|
1752
|
+
daemon = createSessionDaemon({
|
|
1753
|
+
endpoint,
|
|
1754
|
+
credential,
|
|
1755
|
+
cwd: root,
|
|
1756
|
+
modelConfigStore: echoStore(),
|
|
1757
|
+
createRuntime: async (options) => {
|
|
1758
|
+
created.push(options);
|
|
1759
|
+
const sessionId = `pi-session-${created.length}`;
|
|
1760
|
+
return { cwd: root, session: new FakeSession(sessionId, join(root, `${sessionId}.jsonl`)), async dispose() {} };
|
|
1761
|
+
},
|
|
1762
|
+
});
|
|
1763
|
+
await daemon.start();
|
|
1764
|
+
const client = connectClient(endpoint);
|
|
1765
|
+
await client.authenticate();
|
|
1766
|
+
|
|
1767
|
+
await expect(client.request('providers.list')).resolves.toMatchObject({ result: { providers: [{ id: 'test' }] } });
|
|
1768
|
+
const saved = await client.request('providers.models.set', customProvider);
|
|
1769
|
+
expect(saved.result).toEqual({ config: expect.objectContaining({ providerId: 'custom' }) });
|
|
1770
|
+
await expect(client.request('providers.list')).resolves.toMatchObject({ result: { providers: [{ id: 'test' }] } });
|
|
1771
|
+
|
|
1772
|
+
expect(created).toHaveLength(2);
|
|
1773
|
+
expect(created[1]).not.toHaveProperty('sessionFile');
|
|
1774
|
+
await client.close();
|
|
1775
|
+
});
|
|
1776
|
+
|
|
1777
|
+
it('still reopens the active session after a provider save once its JSONL exists', async () => {
|
|
1778
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-provider-persisted-'));
|
|
1779
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1780
|
+
const sessionFile = join(root, 'persisted.jsonl');
|
|
1781
|
+
await writeFile(sessionFile, `${JSON.stringify({ type: 'session', id: 'pi-session-persisted', cwd: root })}\n`);
|
|
1782
|
+
const created = [];
|
|
1783
|
+
daemon = createSessionDaemon({
|
|
1784
|
+
endpoint,
|
|
1785
|
+
credential,
|
|
1786
|
+
cwd: root,
|
|
1787
|
+
modelConfigStore: echoStore(),
|
|
1788
|
+
createRuntime: async (options) => {
|
|
1789
|
+
created.push(options);
|
|
1790
|
+
return { cwd: root, session: new FakeSession('pi-session-persisted', sessionFile), async dispose() {} };
|
|
1791
|
+
},
|
|
1792
|
+
});
|
|
1793
|
+
await daemon.start();
|
|
1794
|
+
const client = connectClient(endpoint);
|
|
1795
|
+
await client.authenticate();
|
|
1796
|
+
|
|
1797
|
+
await client.request('providers.list');
|
|
1798
|
+
await client.request('providers.models.set', customProvider);
|
|
1799
|
+
await expect(client.request('providers.list')).resolves.toMatchObject({ result: { providers: [{ id: 'test' }] } });
|
|
1800
|
+
|
|
1801
|
+
expect(created).toHaveLength(2);
|
|
1802
|
+
expect(created[1]).toMatchObject({ sessionFile });
|
|
1803
|
+
await client.close();
|
|
1804
|
+
});
|
|
1805
|
+
|
|
1806
|
+
it('reopens the session the runtime holds at recreation, not the one it activated with', async () => {
|
|
1807
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-provider-switched-'));
|
|
1808
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1809
|
+
const firstFile = join(root, 'first.jsonl');
|
|
1810
|
+
const switchedFile = join(root, 'switched.jsonl');
|
|
1811
|
+
await writeFile(firstFile, `${JSON.stringify({ type: 'session', id: 'pi-session-first', cwd: root })}\n`);
|
|
1812
|
+
await writeFile(switchedFile, `${JSON.stringify({ type: 'session', id: 'pi-session-switched', cwd: root })}\n`);
|
|
1813
|
+
const created = [];
|
|
1814
|
+
let activeSession;
|
|
1815
|
+
daemon = createSessionDaemon({
|
|
1816
|
+
endpoint,
|
|
1817
|
+
credential,
|
|
1818
|
+
cwd: root,
|
|
1819
|
+
modelConfigStore: echoStore(),
|
|
1820
|
+
createRuntime: async (options) => {
|
|
1821
|
+
created.push(options);
|
|
1822
|
+
activeSession = new FakeSession('pi-session-first', firstFile);
|
|
1823
|
+
return { cwd: root, session: activeSession, async dispose() {} };
|
|
1824
|
+
},
|
|
1825
|
+
});
|
|
1826
|
+
await daemon.start();
|
|
1827
|
+
const client = connectClient(endpoint);
|
|
1828
|
+
await client.authenticate();
|
|
1829
|
+
|
|
1830
|
+
await client.request('providers.list');
|
|
1831
|
+
// The runtime moves to another session in place, as navigate or fork does.
|
|
1832
|
+
activeSession.sessionId = 'pi-session-switched';
|
|
1833
|
+
activeSession.sessionManager.getSessionFile = () => switchedFile;
|
|
1834
|
+
await client.request('providers.models.set', customProvider);
|
|
1835
|
+
|
|
1836
|
+
expect(created).toHaveLength(2);
|
|
1837
|
+
expect(created[1]).toMatchObject({ sessionFile: switchedFile });
|
|
1838
|
+
await client.close();
|
|
1839
|
+
});
|
|
1840
|
+
|
|
1841
|
+
it('reports an unsent created session as deleted when a provider save recreates its runtime', async () => {
|
|
1842
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-provider-unsent-'));
|
|
1843
|
+
const endpoint = testDaemonEndpoint(root);
|
|
1844
|
+
const created = [];
|
|
1845
|
+
daemon = createSessionDaemon({
|
|
1846
|
+
endpoint,
|
|
1847
|
+
credential,
|
|
1848
|
+
cwd: root,
|
|
1849
|
+
// A lease owner, as every supervised daemon has: only a released
|
|
1850
|
+
// lease lets the daemon announce the session as deleted.
|
|
1851
|
+
profileKey: 'web-p3000',
|
|
1852
|
+
serverInstanceId: 'server-a',
|
|
1853
|
+
serverPid: process.pid,
|
|
1854
|
+
daemonId: 'daemon-a',
|
|
1855
|
+
modelConfigStore: echoStore(),
|
|
1856
|
+
createRuntime: async (options) => {
|
|
1857
|
+
created.push(options);
|
|
1858
|
+
const sessionId = `pi-session-${created.length}`;
|
|
1859
|
+
return { cwd: root, session: new FakeSession(sessionId, join(root, `${sessionId}.jsonl`)), async dispose() {} };
|
|
1860
|
+
},
|
|
1861
|
+
});
|
|
1862
|
+
await daemon.start();
|
|
1863
|
+
const client = connectClient(endpoint);
|
|
1864
|
+
await client.authenticate();
|
|
1865
|
+
|
|
1866
|
+
const createdSession = await client.request('sessions.create', { cwd: root });
|
|
1867
|
+
const sessionId = createdSession.result.session.id;
|
|
1868
|
+
const deletedEvent = client.next((frame) => frame.event === 'session.deleted');
|
|
1869
|
+
await client.request('providers.models.set', customProvider);
|
|
1870
|
+
await expect(deletedEvent).resolves.toMatchObject({ payload: { sessionId, directory: root } });
|
|
1871
|
+
await expect(client.request('providers.list')).resolves.toMatchObject({ result: { providers: [{ id: 'test' }] } });
|
|
1872
|
+
expect(created.at(-1)).not.toHaveProperty('sessionFile');
|
|
1873
|
+
await client.close();
|
|
1874
|
+
});
|
|
1875
|
+
});
|
|
1876
|
+
|
|
1727
1877
|
it('adds a single model to an existing file provider without replacing other models', async () => {
|
|
1728
1878
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-'));
|
|
1729
1879
|
const endpoint = testDaemonEndpoint(root);
|
|
@@ -3398,7 +3548,7 @@ describe('Pi session daemon spike', () => {
|
|
|
3398
3548
|
await client.close();
|
|
3399
3549
|
});
|
|
3400
3550
|
|
|
3401
|
-
it('projects the
|
|
3551
|
+
it('projects the live model and thinking onto an opened session, not the last assistant turn', async () => {
|
|
3402
3552
|
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-daemon-last-model-'));
|
|
3403
3553
|
const endpoint = testDaemonEndpoint(root);
|
|
3404
3554
|
const projectDir = join(root, 'project');
|
|
@@ -3436,9 +3586,19 @@ describe('Pi session daemon spike', () => {
|
|
|
3436
3586
|
const client = connectClient(endpoint);
|
|
3437
3587
|
await client.authenticate();
|
|
3438
3588
|
const detail = await client.request('sessions.create', { cwd: projectDir });
|
|
3439
|
-
|
|
3440
|
-
|
|
3589
|
+
// The session left anthropic/sonnet after that turn (a switch, a revert):
|
|
3590
|
+
// the detail names what the next prompt runs on, the message keeps its own.
|
|
3591
|
+
expect(detail.result.session.model).toEqual({ providerId: 'openai', modelId: 'gpt-5' });
|
|
3592
|
+
expect(detail.result.session.thinking).toBe('low');
|
|
3593
|
+
expect(detail.result.messages[0].message.model).toEqual({ providerId: 'anthropic', modelId: 'sonnet' });
|
|
3441
3594
|
expect(detail.result.messages[0].message.thinkingLevel).toBe('high');
|
|
3595
|
+
|
|
3596
|
+
// Only a session with no live model or thinking falls back to that turn.
|
|
3597
|
+
session.model = undefined;
|
|
3598
|
+
session.thinkingLevel = undefined;
|
|
3599
|
+
const fallback = await client.request('sessions.open', { sessionId: session.sessionId, directory: projectDir });
|
|
3600
|
+
expect(fallback.result.session.model).toEqual({ providerId: 'anthropic', modelId: 'sonnet' });
|
|
3601
|
+
expect(fallback.result.session.thinking).toBe('high');
|
|
3442
3602
|
await client.close();
|
|
3443
3603
|
});
|
|
3444
3604
|
|
|
@@ -303,6 +303,13 @@ export const createSessionEngineRouter = ({
|
|
|
303
303
|
const createPayload = message?.payload;
|
|
304
304
|
const owner = resolveCreateOwner(createPayload);
|
|
305
305
|
if (!owner) return false;
|
|
306
|
+
// Draft sessions are Pi-native (`sessions.create` with `draft` or
|
|
307
|
+
// `draftSessionId`); an engine knows nothing of them and would create a
|
|
308
|
+
// visible session. Refuse rather than route.
|
|
309
|
+
if (createPayload && typeof createPayload === 'object'
|
|
310
|
+
&& (createPayload.draft === true || createPayload.draftSessionId !== undefined)) {
|
|
311
|
+
return fail(ENGINE_UNSUPPORTED_OPERATION, 'The session engine does not support draft sessions.');
|
|
312
|
+
}
|
|
306
313
|
if (!createPayload || typeof createPayload !== 'object') {
|
|
307
314
|
return invalidArgument(createError, 'The requested session creation options are invalid.');
|
|
308
315
|
}
|
|
@@ -193,6 +193,26 @@ describe('session engine router', () => {
|
|
|
193
193
|
})).rejects.toMatchObject({ code: ENGINE_UNSUPPORTED_OPERATION });
|
|
194
194
|
});
|
|
195
195
|
|
|
196
|
+
it('refuses draft creates and draft adoptions on an engine without creating anything', async () => {
|
|
197
|
+
let created = 0;
|
|
198
|
+
const engine = makeEngine('with-create', {
|
|
199
|
+
ownsProvider: (id) => id === 'owned',
|
|
200
|
+
handlers: { 'sessions.create': async () => { created += 1; return { session: { id: 'new-1' } }; } },
|
|
201
|
+
});
|
|
202
|
+
const { router } = makeRouter({ getRegistry: () => makeRegistry([engine]), resolveDirectory: async (dir) => dir });
|
|
203
|
+
for (const payload of [
|
|
204
|
+
{ cwd: '/work', draft: true, model: { providerId: 'owned', modelId: 'm' } },
|
|
205
|
+
{ cwd: '/work', draft: true, engine: 'with-create' },
|
|
206
|
+
{ cwd: '/work', draftSessionId: 'draft-1', model: { providerId: 'owned', modelId: 'm' } },
|
|
207
|
+
]) {
|
|
208
|
+
await expect(router.create({}, { command: 'sessions.create', requestId: 'r', payload }))
|
|
209
|
+
.rejects.toMatchObject({ code: ENGINE_UNSUPPORTED_OPERATION });
|
|
210
|
+
}
|
|
211
|
+
// A Pi model keeps the Pi-native draft path.
|
|
212
|
+
expect(await router.create({}, { command: 'sessions.create', requestId: 'r', payload: { cwd: '/work', draft: true } })).toBe(false);
|
|
213
|
+
expect(created).toBe(0);
|
|
214
|
+
});
|
|
215
|
+
|
|
196
216
|
it('skips provider routing for engines without a create handler and falls back to Pi', async () => {
|
|
197
217
|
const engine = makeEngine('no-create', {
|
|
198
218
|
ownsProvider: (id) => id === 'owned',
|
|
@@ -234,6 +234,10 @@ export const createPiSessionDaemonSupervisor = ({
|
|
|
234
234
|
port,
|
|
235
235
|
runtime,
|
|
236
236
|
version,
|
|
237
|
+
// Runs after every successful health probe, before the request it precedes.
|
|
238
|
+
// `request` talks to that verified daemon directly. Errors are swallowed:
|
|
239
|
+
// the hook must never fail the caller's request.
|
|
240
|
+
onDaemonReady,
|
|
237
241
|
} = {}) => {
|
|
238
242
|
const paths = resolvePiSessionDaemonPaths({ env, dataDir, platform, profile, port, runtime, version });
|
|
239
243
|
const serverPid = processLike.pid;
|
|
@@ -646,9 +650,24 @@ export const createPiSessionDaemonSupervisor = ({
|
|
|
646
650
|
return { credential, ready: await probe(credential) };
|
|
647
651
|
};
|
|
648
652
|
|
|
653
|
+
const ensureReadyAndNotify = async () => {
|
|
654
|
+
const ready = await ensureReady();
|
|
655
|
+
if (typeof onDaemonReady === 'function') {
|
|
656
|
+
try {
|
|
657
|
+
await onDaemonReady({
|
|
658
|
+
health: ready.ready.health,
|
|
659
|
+
request: (command, payload) => request({ endpoint: paths.endpoint, credential: ready.credential, command, payload }),
|
|
660
|
+
});
|
|
661
|
+
} catch {
|
|
662
|
+
// See onDaemonReady above.
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
return ready;
|
|
666
|
+
};
|
|
667
|
+
|
|
649
668
|
const requestDaemon = async (command, payload) => {
|
|
650
669
|
try {
|
|
651
|
-
const { credential } = await
|
|
670
|
+
const { credential } = await ensureReadyAndNotify();
|
|
652
671
|
return await request({ endpoint: paths.endpoint, credential, command, payload });
|
|
653
672
|
} catch (error) {
|
|
654
673
|
throw new PiSessionDaemonUnavailableError(
|
|
@@ -662,7 +681,7 @@ export const createPiSessionDaemonSupervisor = ({
|
|
|
662
681
|
const subscribe = async ({ sessionId, fromSequence, streamEpoch, onEvent, onError, signal }) => {
|
|
663
682
|
try {
|
|
664
683
|
if (signal?.aborted) return () => {};
|
|
665
|
-
const { credential } = await
|
|
684
|
+
const { credential } = await ensureReadyAndNotify();
|
|
666
685
|
if (signal?.aborted) return () => {};
|
|
667
686
|
return await subscribeSessionDaemon({ endpoint: paths.endpoint, credential, sessionId, fromSequence, streamEpoch, onEvent, onError, signal });
|
|
668
687
|
} catch (error) {
|
|
@@ -676,7 +695,7 @@ export const createPiSessionDaemonSupervisor = ({
|
|
|
676
695
|
|
|
677
696
|
const health = async () => {
|
|
678
697
|
try {
|
|
679
|
-
const { ready } = await
|
|
698
|
+
const { ready } = await ensureReadyAndNotify();
|
|
680
699
|
return {
|
|
681
700
|
state: 'ready',
|
|
682
701
|
protocolVersion: PROTOCOL_VERSION,
|
|
@@ -74,6 +74,17 @@ const normalizeRetryLimit = (value) => {
|
|
|
74
74
|
return value;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
+
// How extensions are told to draw their UI. `terminal` (the default) reports
|
|
78
|
+
// Pi's TUI mode so `ctx.ui.custom()` components render; `dialogs` reports RPC
|
|
79
|
+
// mode so extensions that branch on `ctx.mode` use Pi's standard dialogs.
|
|
80
|
+
export const PI_EXTENSION_UI_MODES = ['terminal', 'dialogs'];
|
|
81
|
+
|
|
82
|
+
const normalizeExtensionUi = (value) => {
|
|
83
|
+
if (value === undefined || value === null) return undefined;
|
|
84
|
+
if (!PI_EXTENSION_UI_MODES.includes(value)) throw invalidSettings();
|
|
85
|
+
return value;
|
|
86
|
+
};
|
|
87
|
+
|
|
77
88
|
const normalize = (value) => {
|
|
78
89
|
if (!value || typeof value !== 'object' || Array.isArray(value)) throw invalidSettings();
|
|
79
90
|
const model = normalizeModel(value.defaultModel);
|
|
@@ -89,6 +100,7 @@ const normalize = (value) => {
|
|
|
89
100
|
fallbackThinking = undefined;
|
|
90
101
|
}
|
|
91
102
|
const retryLimit = normalizeRetryLimit(value.defaultRetryLimit);
|
|
103
|
+
const extensionUi = normalizeExtensionUi(value.extensionUi);
|
|
92
104
|
return {
|
|
93
105
|
version: 1,
|
|
94
106
|
...(model ? { defaultModel: model } : {}),
|
|
@@ -97,6 +109,7 @@ const normalize = (value) => {
|
|
|
97
109
|
...(Object.keys(thinkingByModel).length > 0 ? { defaultThinkingByModel: thinkingByModel } : {}),
|
|
98
110
|
...(fallbackThinking ? { defaultThinking: fallbackThinking } : {}),
|
|
99
111
|
...(retryLimit !== undefined ? { defaultRetryLimit: retryLimit } : {}),
|
|
112
|
+
...(extensionUi !== undefined ? { extensionUi } : {}),
|
|
100
113
|
};
|
|
101
114
|
};
|
|
102
115
|
|
|
@@ -133,6 +146,7 @@ export const createPiSettingsStore = ({ file = join(resolvePiChamberDataDir(), '
|
|
|
133
146
|
...(Object.hasOwn(patch, 'smallModel') ? { smallModel: patch.smallModel } : {}),
|
|
134
147
|
...(Object.hasOwn(patch, 'walkthroughModel') ? { walkthroughModel: patch.walkthroughModel } : {}),
|
|
135
148
|
...(Object.hasOwn(patch, 'defaultRetryLimit') ? { defaultRetryLimit: patch.defaultRetryLimit } : {}),
|
|
149
|
+
...(Object.hasOwn(patch, 'extensionUi') ? { extensionUi: patch.extensionUi } : {}),
|
|
136
150
|
defaultThinkingByModel: Object.hasOwn(patch, 'defaultThinkingByModel')
|
|
137
151
|
? mergeThinkingByModel(current.defaultThinkingByModel ?? {}, patch.defaultThinkingByModel)
|
|
138
152
|
: (current.defaultThinkingByModel ?? {}),
|
|
@@ -132,6 +132,17 @@ describe('Pi settings sidecar', () => {
|
|
|
132
132
|
await expect(store.read()).resolves.toEqual({ version: 1, defaultRetryLimit: 3 });
|
|
133
133
|
});
|
|
134
134
|
|
|
135
|
+
it('round-trips the extension UI mode, rejects unknown modes, and clears with null', async () => {
|
|
136
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-settings-'));
|
|
137
|
+
const file = join(root, 'pi', 'settings.json');
|
|
138
|
+
const store = createPiSettingsStore({ file });
|
|
139
|
+
await expect(store.update({ extensionUi: 'dialogs' })).resolves.toEqual({ version: 1, extensionUi: 'dialogs' });
|
|
140
|
+
await expect(store.update({ defaultRetryLimit: 4 })).resolves.toEqual({ version: 1, defaultRetryLimit: 4, extensionUi: 'dialogs' });
|
|
141
|
+
await expect(store.update({ extensionUi: 'tui' })).rejects.toMatchObject({ code: 'PI_SETTINGS_INVALID' });
|
|
142
|
+
await expect(store.read()).resolves.toEqual({ version: 1, defaultRetryLimit: 4, extensionUi: 'dialogs' });
|
|
143
|
+
await expect(store.update({ extensionUi: null })).resolves.toEqual({ version: 1, defaultRetryLimit: 4 });
|
|
144
|
+
});
|
|
145
|
+
|
|
135
146
|
it('preserves explicit per-run retry over stored default', async () => {
|
|
136
147
|
const resolveEffective = (explicit, stored) => {
|
|
137
148
|
if (Number.isInteger(explicit)) return explicit;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# PiChamber plugins (server)
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
|
|
5
|
+
A plugin is a Pi package with a `pichamber` block in its `package.json`. The
|
|
6
|
+
`pi.extensions[0]` module is the agent half; the `pichamber` block declares
|
|
7
|
+
state and UI contributions. This module owns the bundled plugin list, the
|
|
8
|
+
manifest contract, the stored enabled set and state, measured agent impact,
|
|
9
|
+
the public routes, and pushing the config to the session daemon. The daemon
|
|
10
|
+
side is `../pi/session-daemon/plugin-host.js`.
|
|
11
|
+
|
|
12
|
+
Nothing reaches the agent unless the user turned it on: bundled plugins ship
|
|
13
|
+
disabled, and a disabled plugin loads no agent code.
|
|
14
|
+
|
|
15
|
+
## Entrypoints
|
|
16
|
+
|
|
17
|
+
- `manifest.js` parses a package fail-closed (`PluginManifestError`, code
|
|
18
|
+
`INVALID_PLUGIN_MANIFEST`). Fields: `apiVersion: 1`, `id` (kebab case, at most
|
|
19
|
+
40 characters), `name`, `description`, `icon` (a Remix sprite name),
|
|
20
|
+
`defaultEnabled` (must be false for bundled plugins), `replaceable`
|
|
21
|
+
(maps to the Pi factory's `replaceable`), `state` (`{ type: 'boolean' | 'enum',
|
|
22
|
+
scope: 'global' | 'project', default, label, description?, options? }` per key),
|
|
23
|
+
`contributes.composerToggles` (`{ id, state, label, icon, description? }`,
|
|
24
|
+
bound to a boolean key; optional), `contributes.settings` (ordered keys,
|
|
25
|
+
never a key a composer toggle sets), and
|
|
26
|
+
`contributes.ui` (native UI id). The agent half must be a `.js`/`.mjs`
|
|
27
|
+
module inside the package. The package `version` is the plugin version.
|
|
28
|
+
- `registry.js` reads `packages/web/plugins/registry.json`
|
|
29
|
+
(`{ version: 1, plugins: [id] }`) and loads each listed folder. An invalid
|
|
30
|
+
plugin is skipped with a logged reason; the others still load. A missing or
|
|
31
|
+
malformed registry file is `PLUGINS_UNREADABLE`, never an empty list. The
|
|
32
|
+
entry is resolved through links and must stay in its package.
|
|
33
|
+
- `store.js` owns `<dataDir>/pi/plugins.json`:
|
|
34
|
+
`{ version: 1, enabled: { [id]: bool }, state: { [id]: { global: {..}, projects: { [dir]: {..} }, sessions: { [sessionId]: {..} } } } }`.
|
|
35
|
+
`sessions` holds composer switches: a session's own values, only for keys
|
|
36
|
+
a composer toggle names (`isSessionStateKey`), keyed by Pi session id
|
|
37
|
+
(`[A-Za-z0-9][A-Za-z0-9._:-]*`, at most 256 characters). The server
|
|
38
|
+
stores any valid value it is sent; the UI sends `null` when a switch goes
|
|
39
|
+
back to its default, so a session normally holds only values that differ
|
|
40
|
+
from it. A composer toggle's key has no global or project value:
|
|
41
|
+
`resolvePluginState` always starts it from the manifest default (ignoring
|
|
42
|
+
any stored by an older build) and `setState` refuses it, so every new
|
|
43
|
+
session starts from the default while the plugin is on. Each plugin
|
|
44
|
+
keeps at most 1000 sessions; setting one moves it last, and the least
|
|
45
|
+
recently set are dropped past the cap with a logged warning. Deleting a session
|
|
46
|
+
(`DELETE /api/pi/sessions/:id`, through `registerPiRuntimeRoutes`'
|
|
47
|
+
`onSessionDeleted`) drops its values and pushes the config.
|
|
48
|
+
Files written before sessions existed read as `sessions: {}`.
|
|
49
|
+
A missing file is empty; a malformed one is `PLUGINS_UNREADABLE` for reads
|
|
50
|
+
and writes (it is never overwritten). Writes re-read under an in-process
|
|
51
|
+
chain and a cross-process lock, then replace the file atomically, so a
|
|
52
|
+
write never drops another writer's change. Unknown ids and keys are kept.
|
|
53
|
+
Values are checked against the manifest when resolved: project value over
|
|
54
|
+
global value over default, and a stored value of the wrong type, option, or
|
|
55
|
+
scope falls back to the default. Project directories are absolute and
|
|
56
|
+
normalized (`~` expands to the home folder).
|
|
57
|
+
- `impact.js` imports the agent half and calls it once with a recording
|
|
58
|
+
stand-in for the Pi API and a `pichamber` handle with default state (its `ui` calls resolve with nothing, `openUrl` with `false`). It reports
|
|
59
|
+
`{ tools: [{ name, exposure, tokens }], hooks, commands }`. `tokens` is
|
|
60
|
+
`ceil(chars / 4)` of JSON `{ name, description, parameters }`. `hooks` lists
|
|
61
|
+
the prompt-affecting events the plugin handles (`PROMPT_AFFECTING_EVENTS`:
|
|
62
|
+
`resources_discover`, `input`, `before_agent_start`, `context`,
|
|
63
|
+
`context_with_system`, `before_provider_request`, `tool_result`,
|
|
64
|
+
`message_end`). Results are cached per id and version. A plugin that throws,
|
|
65
|
+
has no default export, or takes over 5 seconds reports `impact: null` with a
|
|
66
|
+
short `impactError`. Measurement runs bundled code in the server process.
|
|
67
|
+
- `service.js` combines the above: public views, mutations, and the daemon
|
|
68
|
+
config.
|
|
69
|
+
- `routes.js` registers the public routes. `index.js` wires them; the global
|
|
70
|
+
`/api` auth gate applies.
|
|
71
|
+
- `daemon-sync.js` pushes the config to the daemon (below).
|
|
72
|
+
|
|
73
|
+
## HTTP contract
|
|
74
|
+
|
|
75
|
+
- `GET /api/pi/plugins?directory=<absolute dir, optional>` answers
|
|
76
|
+
`{ plugins: [PluginView] }`. State is resolved for `directory`.
|
|
77
|
+
- `PUT /api/pi/plugins/:id` with `{ enabled: boolean }` answers the view.
|
|
78
|
+
- `PUT /api/pi/plugins/:id/state` with `{ key, value, directory? }` answers the
|
|
79
|
+
view resolved for `directory`. The scope comes from the manifest; a
|
|
80
|
+
project-scoped key needs `directory`. These are the Settings values every
|
|
81
|
+
session uses. A key a composer toggle sets is refused here
|
|
82
|
+
(`INVALID_PLUGIN_REQUEST`); it changes per session only.
|
|
83
|
+
- `GET /api/pi/plugins/sessions/:sessionId` answers
|
|
84
|
+
`{ sessionId, overrides: { [pluginId]: { [key]: value } } }`, plugins with
|
|
85
|
+
values only.
|
|
86
|
+
- `PUT /api/pi/plugins/:id/sessions/:sessionId` with `{ key, value }` sets one
|
|
87
|
+
session's own value; `value: null` clears it. Answers
|
|
88
|
+
`{ id, sessionId, overrides }` for that plugin. Only keys a composer toggle
|
|
89
|
+
names are accepted.
|
|
90
|
+
- Errors: 404 `{ error: { code: 'PLUGIN_NOT_FOUND' } }`, 400
|
|
91
|
+
`INVALID_PLUGIN_REQUEST`, 500 `PLUGINS_UNREADABLE`.
|
|
92
|
+
|
|
93
|
+
`PluginView` is `{ id, name, description, icon, version, bundled, enabled,
|
|
94
|
+
state, stateSchema, contributes, impact, impactError? }`. It never carries
|
|
95
|
+
module paths.
|
|
96
|
+
|
|
97
|
+
## Daemon push
|
|
98
|
+
|
|
99
|
+
The daemon never reads plugin state or the enabled set from disk: under a
|
|
100
|
+
nono sandbox it cannot read PiChamber's data folder. The server sends the
|
|
101
|
+
private `plugins.configure` command with
|
|
102
|
+
`{ plugins: [{ id, entry, replaceable, state: { global, projects, sessions } }] }`,
|
|
103
|
+
enabled plugins only. `global` holds every key resolved without a project;
|
|
104
|
+
`projects[dir]` holds the project-scoped values that differ;
|
|
105
|
+
`sessions[sessionId]` holds a session's own values. The daemon resolves
|
|
106
|
+
`{ ...global, ...projects[dir], ...sessions[sessionId] }`. A composer switch
|
|
107
|
+
is a committed change like any other, so the push runs before the next daemon
|
|
108
|
+
request, including the prompt sent right after it.
|
|
109
|
+
|
|
110
|
+
When it pushes (`daemon-sync.js`):
|
|
111
|
+
|
|
112
|
+
- A daemon process is identified by its `streamEpoch`, a random id picked at
|
|
113
|
+
daemon start and returned by every `runtime.health`. The supervisor probes
|
|
114
|
+
health before each request, subscription, and health call and then runs its
|
|
115
|
+
`onDaemonReady` hook with the probe result and a request function bound to
|
|
116
|
+
that daemon. The sync pushes when it has not configured that epoch at the
|
|
117
|
+
current revision, so a new, restarted, or reused daemon (after a server
|
|
118
|
+
restart) is configured before the request runs.
|
|
119
|
+
- After each committed change the routes call `changed()`, which bumps the
|
|
120
|
+
revision and runs a health probe, which pushes.
|
|
121
|
+
- At server start, after the daemon starts, `index.js` runs one health probe.
|
|
122
|
+
- Pushes are serialized, and each builds the config when it runs, so an older
|
|
123
|
+
config never lands after a newer one. Concurrent requests share one push.
|
|
124
|
+
- A failed push (daemon error, unreadable store) logs and is retried on a
|
|
125
|
+
later probe, at most every 2 seconds for the same epoch and revision. It
|
|
126
|
+
never fails the request. A daemon that was never configured runs with every
|
|
127
|
+
plugin off.
|
|
128
|
+
- The last 32 epochs are remembered, so a daemon pool is configured per
|
|
129
|
+
daemon as each is reached. A change probes the profile daemon only; others
|
|
130
|
+
pick it up on their next request.
|
|
131
|
+
|
|
132
|
+
## Bundled plugins
|
|
133
|
+
|
|
134
|
+
Listed in `packages/web/plugins/registry.json`, one folder each:
|
|
135
|
+
|
|
136
|
+
- `visuals/`: two tools. `render_html` reads a page from the call's `html`
|
|
137
|
+
or from a file inside the session's folder, and returns it as the result
|
|
138
|
+
details for the UI to draw. `render_choices` (`choices.js`) takes a
|
|
139
|
+
question and 2 to 6 options, each a page (`html`, or `path` to an `.html`
|
|
140
|
+
file) or an image file in the project (`path` to a `.png`, `.jpg`, `.webp`,
|
|
141
|
+
`.gif` or `.svg`, sent as a `data:` URL). It reports the options as a
|
|
142
|
+
partial result, waits a turn of the event loop so they reach clients first,
|
|
143
|
+
then asks with `pichamber.ui.choose(ctx, ...)` and its own tool call id, and returns the
|
|
144
|
+
chosen option and the user's note. The details are
|
|
145
|
+
`{ title, options, answer }`: `answer` is `{ id, note? }`, `null` when the
|
|
146
|
+
question was closed, and absent when the client could not ask. Under plain
|
|
147
|
+
Pi it asks with `ctx.ui.select` (labels only, the variants are not drawn).
|
|
148
|
+
`files.js` resolves every path through links and keeps it inside the
|
|
149
|
+
project. Limits: 512,000 characters a page, 750 KB an image before
|
|
150
|
+
encoding, 1.5 million characters for one call's options together, since
|
|
151
|
+
they are stored in the session file. State `allowNetwork` only: no composer
|
|
152
|
+
toggle, so both tools are in every session while the plugin is on. It adds
|
|
153
|
+
its tools at `session_start` and uses the `pichamber` handle only for `render_choices`.
|
|
154
|
+
- `subagents/`: the `subagent` tool, adapted from Pi's MIT example (credit in
|
|
155
|
+
its `LICENSE`). Runs `pi --mode json -p --no-session` children through the
|
|
156
|
+
daemon's Pi CLI (`process.argv[1]`), so a sandboxed daemon's children stay
|
|
157
|
+
in its sandbox. Bundled agents (`agents/*.md`) use the session's model and
|
|
158
|
+
are overridden by user or project agents of the same name. Details are the
|
|
159
|
+
compact `{ mode, agentScope, results }` shape the UI reads, with updates at
|
|
160
|
+
most every 250 ms. `replaceable`, so a user's own `subagent` extension wins.
|
|
161
|
+
State `on`, set by its composer toggle only (default on).
|
|
162
|
+
|
|
163
|
+
Sub-agents switches its tool with the `on` value through `pi.setActiveTools`,
|
|
164
|
+
so a composer toggle takes effect without recreating the runtime. It reads the
|
|
165
|
+
session id from `ctx.sessionManager.getSessionId()` at `session_start` and
|
|
166
|
+
pass it to `pichamber.state(cwd, sessionId)`, so a composer switch changes that
|
|
167
|
+
session only. It adds or removes only its own tool, and only at
|
|
168
|
+
`session_start` or when their resolved `on` value flips, so an unrelated
|
|
169
|
+
state push leaves a tool list the user edited as it is.
|
|
170
|
+
|
|
171
|
+
## Deliberate limits
|
|
172
|
+
|
|
173
|
+
- Bundled plugins only. User installs and frame-hosted UI are out of scope.
|
|
174
|
+
- A question is live: a daemon restart or a runtime recreation cancels it,
|
|
175
|
+
and the tool returns as if the user had closed it. A message typed while a
|
|
176
|
+
question waits is queued like any other.
|
|
177
|
+
- A forked session starts with the plugin's defaults, not its parent's
|
|
178
|
+
composer switches.
|
|
179
|
+
- No `plugins.changed` event reaches other devices yet; they see changes on
|
|
180
|
+
their next `GET /api/pi/plugins`.
|
|
181
|
+
- Bundled code is trusted: the server imports it to measure impact, and the
|
|
182
|
+
daemon only imports modules under `packages/web/plugins/`.
|
|
183
|
+
|
|
184
|
+
## Replaced plugins
|
|
185
|
+
|
|
186
|
+
Pi leaves a `replaceable` extension out when another extension registers the same tool, command, or flag. Bundled plugins load as replaceable inline factories, so a plugin can be on in Settings and still not loaded (the user's own `subagent` extension replaces Sub-agents, for example). The server does nothing about this itself. The daemon reports it in the `replaced` field of the extension config answers (see `extension-replacements.js` and `plugin-host.js` in `../pi/session-daemon/DOCUMENTATION.md`), and the public routes `GET /api/pi/extensions/config`, `PUT /api/pi/extensions/config/:id`, and `DELETE /api/pi/extensions/packages/:id` pass it through `projectExtensionConfig` in `../pi/routes.js`. That projection keeps only `kind` (`plugin` or `builtin`), `id`, and the optional `registers` and `by`. It drops an entry with a bad kind or id, leaves out a malformed optional part, and copies nothing else. The field is absent when no live runtime answered, which means unknown, not "nothing replaced".
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Pushes the plugin config to every daemon process the server talks to.
|
|
2
|
+
//
|
|
3
|
+
// A daemon process is identified by its `streamEpoch`, a random id it picks at
|
|
4
|
+
// start and reports in every health probe. The supervisor probes health before
|
|
5
|
+
// each request and hands the result to `onDaemonReady`, so a push happens:
|
|
6
|
+
// - before the first request to a daemon process this server has not
|
|
7
|
+
// configured (a new daemon, a restarted one, or one reused from an earlier
|
|
8
|
+
// server run),
|
|
9
|
+
// - after every change (`changed()` bumps the revision and probes), and
|
|
10
|
+
// - again on a later request when a push failed (at most every `retryDelayMs`).
|
|
11
|
+
// A failed push only logs. The request it precedes still runs; a daemon that
|
|
12
|
+
// was never configured runs with every plugin off.
|
|
13
|
+
|
|
14
|
+
const MAX_TRACKED_DAEMONS = 32;
|
|
15
|
+
|
|
16
|
+
export const createPluginDaemonSync = ({
|
|
17
|
+
buildConfig,
|
|
18
|
+
refresh = async () => {},
|
|
19
|
+
logger = console,
|
|
20
|
+
retryDelayMs = 2_000,
|
|
21
|
+
now = Date.now,
|
|
22
|
+
}) => {
|
|
23
|
+
let revision = 0;
|
|
24
|
+
const configured = new Map();
|
|
25
|
+
const inflight = new Map();
|
|
26
|
+
let chain = Promise.resolve();
|
|
27
|
+
let lastFailure = null;
|
|
28
|
+
|
|
29
|
+
const remember = (epoch, pushedRevision) => {
|
|
30
|
+
configured.delete(epoch);
|
|
31
|
+
configured.set(epoch, pushedRevision);
|
|
32
|
+
while (configured.size > MAX_TRACKED_DAEMONS) configured.delete(configured.keys().next().value);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const push = (epoch, target, request) => {
|
|
36
|
+
const key = `${epoch}:${target}`;
|
|
37
|
+
const existing = inflight.get(key);
|
|
38
|
+
if (existing) return existing;
|
|
39
|
+
// Serialized so an older config can never land after a newer one. Each
|
|
40
|
+
// push builds the config when it runs, so it carries the latest state.
|
|
41
|
+
const task = chain.then(async () => {
|
|
42
|
+
if (configured.get(epoch) === revision) return;
|
|
43
|
+
const pushing = revision;
|
|
44
|
+
try {
|
|
45
|
+
await request('plugins.configure', await buildConfig());
|
|
46
|
+
remember(epoch, pushing);
|
|
47
|
+
lastFailure = null;
|
|
48
|
+
} catch (error) {
|
|
49
|
+
lastFailure = { epoch, revision: pushing, at: now() };
|
|
50
|
+
logger.warn?.(`[plugins] could not configure the session daemon: ${error?.code ?? error?.message ?? 'unknown error'}`);
|
|
51
|
+
}
|
|
52
|
+
}).finally(() => inflight.delete(key));
|
|
53
|
+
chain = task;
|
|
54
|
+
inflight.set(key, task);
|
|
55
|
+
return task;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** Supervisor hook: runs after every successful health probe. Never throws. */
|
|
59
|
+
const onDaemonReady = async ({ health, request }) => {
|
|
60
|
+
const epoch = health?.streamEpoch;
|
|
61
|
+
if (typeof epoch !== 'string' || epoch.length === 0 || typeof request !== 'function') return;
|
|
62
|
+
if (configured.get(epoch) === revision) return;
|
|
63
|
+
if (lastFailure && lastFailure.epoch === epoch && lastFailure.revision === revision
|
|
64
|
+
&& now() - lastFailure.at < retryDelayMs) return;
|
|
65
|
+
await push(epoch, revision, request);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** Call after a committed change; pushes in the background. */
|
|
69
|
+
const changed = () => {
|
|
70
|
+
revision += 1;
|
|
71
|
+
lastFailure = null;
|
|
72
|
+
void Promise.resolve().then(refresh).catch((error) => {
|
|
73
|
+
logger.warn?.(`[plugins] could not reach the session daemon: ${error?.code ?? error?.message ?? 'unknown error'}`);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return { onDaemonReady, changed };
|
|
78
|
+
};
|