@pi-chamber/web 1.0.7 → 1.0.8-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/AgentsSurface-CcWBqAWV.js +1 -0
- package/dist/assets/ChoicesArtifact-Kk-qvrSB.js +1 -0
- package/dist/assets/DiagramView-DZUBo1uP.js +1 -0
- package/dist/assets/{DiffView-BxW6BuOC.js → DiffView-CiZy4jFA.js} +6 -6
- package/dist/assets/FileSaveConflictDialog-DZ9NDwOO.js +3 -0
- package/dist/assets/FilesView-DqiZ9kw9.js +6 -0
- package/dist/assets/GitHubDetailScaffold-DM2DH7o8.js +11 -0
- package/dist/assets/GitHubLinkPicker-ChB8NZ1h.js +1 -0
- package/dist/assets/GitHubListPrimitives-CibDiJGq.js +1 -0
- package/dist/assets/{GitView-DD33ngnM.js → GitView--EaZQrBr.js} +5 -5
- package/dist/assets/{IssuesSurface-BAY_eyX5.js → IssuesSurface-CySTpaD1.js} +3 -3
- package/dist/assets/{JsonTreeView-DpXbUrAl.js → JsonTreeView-_yMHKKQZ.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cn63lAmn.js → MarkdownRendererImpl-D_-2fQw0.js} +3 -3
- package/dist/assets/PatchDiff-bHObDlhD.js +1 -0
- package/dist/assets/PierreDiffViewer-UY7Cse-s.js +147 -0
- package/dist/assets/PullRequestsSurface-iXy6chwc.js +2 -0
- package/dist/assets/{SessionSwitcherContent-CscYekC1.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-CDOX-5Y2.js +2 -0
- package/dist/assets/SessionUnreadDot-Dwc3MdvA.js +1 -0
- package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
- package/dist/assets/{SettingsWindow-gxjULdm1.js → SettingsWindow-CUg49Mfh.js} +1 -1
- package/dist/assets/{StickyHorizontalScrollbar-DNsbTLS7.js → StickyHorizontalScrollbar-CMbTn5WQ.js} +1 -1
- package/dist/assets/SubagentsArtifact-DUZX9tDe.js +1 -0
- package/dist/assets/ToolOutputDialog-BuZZaRw4.js +8 -0
- package/dist/assets/ToolPartDiffPreview-CKncG6i2.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-BrbPymTL.js → VirtualizedFileDiff-BGZiLPe_.js} +4 -4
- package/dist/assets/{Virtualizer-okhy9Aq3.js → Virtualizer-PxblpQn6.js} +1 -1
- package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
- package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
- package/dist/assets/{collapsible-D6qdoq7-.js → collapsible-Bro9KrfM.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-G4csGiKs.js → computeVirtualFileMetrics-DJQqK49u.js} +2 -2
- package/dist/assets/contextFileOpenGuard-ByWK3Sru.js +1 -0
- package/dist/assets/{fileTreeStatus-Bskhj4qT.js → fileTreeStatus-CyJ3TOYD.js} +2 -2
- package/dist/assets/gitStatusPredicates-BsXrwngT.js +1 -0
- package/dist/assets/githubLink-g2bmC0qi.js +10 -0
- package/dist/assets/index-B_L9GVYw.css +1 -0
- package/dist/assets/{index-ComwtfT4.js → index-C9rUUQ_Y.js} +1 -1
- package/dist/assets/index-CKKWVoND.js +11 -0
- package/dist/assets/{main-DoiadX0a.js → main-DT-4_fhe.js} +2 -2
- package/dist/assets/main-DsLMU9CT.js +137 -0
- package/dist/assets/{markdownCore-DczkEluO.js → markdownCore-QmM_aOnZ.js} +2 -2
- package/dist/assets/{miniChat-Ck6MEZ9Q.js → miniChat-BqGslD2z.js} +2 -2
- package/dist/assets/{mobile-BucKVm1P.js → mobile-C5JOcDIC.js} +2 -2
- package/dist/assets/{nativeFileSave-Cp9i5QGd.js → nativeFileSave-DSMsJqXM.js} +1 -1
- package/dist/assets/pi-session-focus-preference-Cc_S4zi1.js +9 -0
- package/dist/assets/{renderDiffWithHighlighter-PL82AR81.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-CiSkecEE.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-CYgfbA4F.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
- package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
- package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
- package/dist/assets/runtimeSurface-0K7vuUpd.js +1 -0
- package/dist/assets/selection-CnYkEsu_.js +1 -0
- package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
- package/dist/assets/useGitHubRemoteSearch-CgP-zEBj.js +1 -0
- package/dist/assets/useSwitcherItems-C8G5F0hs.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-BpncHjnV.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/featured.json +12 -0
- 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 +90 -0
- package/plugins/visuals/files.js +74 -0
- package/plugins/visuals/package.json +32 -0
- package/server/index.js +103 -24
- package/server/lib/git/DOCUMENTATION.md +4 -0
- package/server/lib/git/service.js +70 -5
- package/server/lib/git/service.test.js +179 -0
- package/server/lib/github/DOCUMENTATION.md +6 -2
- package/server/lib/github/gh-cli.js +35 -9
- package/server/lib/github/gh-cli.test.js +122 -0
- package/server/lib/marketplace/DOCUMENTATION.md +95 -0
- package/server/lib/marketplace/featured.js +176 -0
- package/server/lib/marketplace/featured.test.js +207 -0
- package/server/lib/marketplace/npm-registry.js +255 -0
- package/server/lib/marketplace/npm-registry.test.js +227 -0
- package/server/lib/marketplace/routes.js +64 -0
- package/server/lib/marketplace/routes.test.js +119 -0
- package/server/lib/marketplace/service.js +225 -0
- package/server/lib/marketplace/service.test.js +174 -0
- package/server/lib/notifications/DOCUMENTATION.md +10 -4
- package/server/lib/notifications/pi-notification-watcher.js +95 -33
- package/server/lib/notifications/pi-notification-watcher.test.js +89 -0
- package/server/lib/open-url/DOCUMENTATION.md +2 -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/merged-event-stream.js +316 -0
- package/server/lib/pi/merged-event-stream.test.js +95 -0
- package/server/lib/pi/routes-daemon-pool.test.js +348 -0
- package/server/lib/pi/routes-extension-events.test.js +115 -0
- package/server/lib/pi/routes-merged-events.test.js +327 -0
- package/server/lib/pi/routes-sandbox.test.js +1684 -0
- package/server/lib/pi/routes.js +790 -87
- package/server/lib/pi/routes.test.js +381 -1
- package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
- package/server/lib/pi/sandbox/launcher.js +122 -0
- package/server/lib/pi/sandbox/launcher.test.js +91 -0
- package/server/lib/pi/sandbox/nono-launcher.js +455 -0
- package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
- package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
- package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
- package/server/lib/pi/sandbox/nono-profile.json +22 -0
- package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
- package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
- package/server/lib/pi/sandbox/project-sandbox.js +207 -0
- package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
- package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
- package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
- package/server/lib/pi/sandbox/trust-ask.js +135 -0
- package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
- package/server/lib/pi/sandbox/worktree-ids.js +96 -0
- package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +47 -10
- package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
- package/server/lib/pi/session-daemon/daemon-process.js +10 -1
- package/server/lib/pi/session-daemon/extension-bridge.js +89 -29
- package/server/lib/pi/session-daemon/extension-config.js +902 -0
- package/server/lib/pi/session-daemon/extension-config.test.js +798 -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-read-persisted.test.js +167 -0
- package/server/lib/pi/session-daemon/session-daemon.js +927 -108
- package/server/lib/pi/session-daemon/session-daemon.test.js +391 -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/session-idle-residency.test.js +98 -1
- package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
- package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
- package/server/lib/pi/session-daemon/session-lease.js +93 -15
- package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
- package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
- package/server/lib/pi/session-daemon/supervisor.js +408 -38
- package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
- package/server/lib/pi/settings-store.js +14 -0
- package/server/lib/pi/settings-store.test.js +11 -0
- package/server/lib/pi/ui-settings-store.js +88 -2
- package/server/lib/pi/ui-settings-store.test.js +118 -0
- package/server/lib/plugins/DOCUMENTATION.md +198 -0
- package/server/lib/plugins/daemon-sync.js +88 -0
- package/server/lib/plugins/daemon-sync.supervisor.test.js +83 -0
- package/server/lib/plugins/daemon-sync.test.js +108 -0
- package/server/lib/plugins/impact.js +139 -0
- package/server/lib/plugins/impact.test.js +83 -0
- package/server/lib/plugins/manifest.js +220 -0
- package/server/lib/plugins/manifest.test.js +127 -0
- package/server/lib/plugins/registry.js +59 -0
- package/server/lib/plugins/routes.js +92 -0
- package/server/lib/plugins/routes.test.js +247 -0
- package/server/lib/plugins/service.js +183 -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/cross-process-lock.js +28 -3
- 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/index-I2QYqABE.js +0 -11
- package/dist/assets/main-DyFfbllq.js +0 -137
- package/dist/assets/pi-session-focus-preference-Dx0UXPoO.js +0 -9
- package/dist/assets/renderElectronMiniChatApp-Cb7s7dWl.js +0 -2
- package/dist/assets/renderMobileApp-Bp74b_Lo.js +0 -11
- 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
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { mkdir, mkdtemp, readFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { createPiSessionDaemonSupervisor } from '../pi/session-daemon/supervisor.js';
|
|
7
|
+
import { createPluginDaemonSync } from './daemon-sync.js';
|
|
8
|
+
|
|
9
|
+
const waitForExit = async (pid) => {
|
|
10
|
+
for (let attempt = 0; attempt < 100; attempt += 1) {
|
|
11
|
+
try {
|
|
12
|
+
process.kill(pid, 0);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
if (error?.code === 'ESRCH') return;
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
18
|
+
}
|
|
19
|
+
throw new Error('The daemon process did not exit.');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe('plugin push through the daemon supervisor', () => {
|
|
23
|
+
let supervisor;
|
|
24
|
+
|
|
25
|
+
afterEach(async () => {
|
|
26
|
+
await supervisor?.stop().catch(() => {});
|
|
27
|
+
supervisor = undefined;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('configures a daemon before its first request and again after it restarts', async () => {
|
|
31
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-plugin-sync-'));
|
|
32
|
+
const cwd = join(root, 'project');
|
|
33
|
+
const agentDir = join(root, 'agent');
|
|
34
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir)]);
|
|
35
|
+
const env = {
|
|
36
|
+
...process.env,
|
|
37
|
+
PI_OFFLINE: '1',
|
|
38
|
+
PICHAMBER_DATA_DIR: join(root, 'data'),
|
|
39
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
40
|
+
XDG_RUNTIME_DIR: join(root, 'runtime'),
|
|
41
|
+
};
|
|
42
|
+
const buildConfig = vi.fn(async () => ({ plugins: [] }));
|
|
43
|
+
const sync = createPluginDaemonSync({ buildConfig, refresh: () => supervisor.health(), logger: { warn: vi.fn() } });
|
|
44
|
+
const onDaemonReady = vi.fn(sync.onDaemonReady);
|
|
45
|
+
supervisor = createPiSessionDaemonSupervisor({ env, cwd, onDaemonReady });
|
|
46
|
+
|
|
47
|
+
await supervisor.start();
|
|
48
|
+
await expect(supervisor.request('sessions.list')).resolves.toMatchObject({ sessions: expect.any(Array) });
|
|
49
|
+
expect(buildConfig).toHaveBeenCalledTimes(1);
|
|
50
|
+
await supervisor.request('sessions.list');
|
|
51
|
+
expect(buildConfig).toHaveBeenCalledTimes(1);
|
|
52
|
+
|
|
53
|
+
// A change pushes through a health probe.
|
|
54
|
+
sync.changed();
|
|
55
|
+
await vi.waitFor(() => expect(buildConfig).toHaveBeenCalledTimes(2));
|
|
56
|
+
|
|
57
|
+
// A new daemon process (new stream epoch) is configured before the request.
|
|
58
|
+
const firstEpoch = onDaemonReady.mock.calls.at(-1)[0].health.streamEpoch;
|
|
59
|
+
const state = JSON.parse(await readFile(supervisor.paths.stateFile, 'utf8'));
|
|
60
|
+
process.kill(state.pid, 'SIGKILL');
|
|
61
|
+
await waitForExit(state.pid);
|
|
62
|
+
await supervisor.request('sessions.list');
|
|
63
|
+
expect(buildConfig).toHaveBeenCalledTimes(3);
|
|
64
|
+
expect(onDaemonReady.mock.calls.at(-1)[0].health.streamEpoch).not.toBe(firstEpoch);
|
|
65
|
+
}, 30_000);
|
|
66
|
+
|
|
67
|
+
it('never fails the request when the hook throws', async () => {
|
|
68
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-plugin-sync-'));
|
|
69
|
+
const cwd = join(root, 'project');
|
|
70
|
+
const agentDir = join(root, 'agent');
|
|
71
|
+
await Promise.all([mkdir(cwd), mkdir(agentDir)]);
|
|
72
|
+
const env = {
|
|
73
|
+
...process.env,
|
|
74
|
+
PI_OFFLINE: '1',
|
|
75
|
+
PICHAMBER_DATA_DIR: join(root, 'data'),
|
|
76
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
77
|
+
XDG_RUNTIME_DIR: join(root, 'runtime'),
|
|
78
|
+
};
|
|
79
|
+
supervisor = createPiSessionDaemonSupervisor({ env, cwd, onDaemonReady: async () => { throw new Error('hook failed'); } });
|
|
80
|
+
await supervisor.start();
|
|
81
|
+
await expect(supervisor.request('sessions.list')).resolves.toMatchObject({ sessions: expect.any(Array) });
|
|
82
|
+
}, 30_000);
|
|
83
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createPluginDaemonSync } from './daemon-sync.js';
|
|
4
|
+
|
|
5
|
+
const deferred = () => {
|
|
6
|
+
let resolve;
|
|
7
|
+
const promise = new Promise((done) => { resolve = done; });
|
|
8
|
+
return { promise, resolve };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
describe('plugin daemon sync', () => {
|
|
12
|
+
it('configures each daemon process once per revision, before its request', async () => {
|
|
13
|
+
let config = { plugins: [] };
|
|
14
|
+
const sync = createPluginDaemonSync({ buildConfig: async () => config, logger: { warn: vi.fn() } });
|
|
15
|
+
const request = vi.fn(async () => ({}));
|
|
16
|
+
|
|
17
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
18
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
19
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
20
|
+
expect(request).toHaveBeenLastCalledWith('plugins.configure', { plugins: [] });
|
|
21
|
+
|
|
22
|
+
// A restarted or different daemon process has a new epoch.
|
|
23
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'b' }, request });
|
|
24
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
25
|
+
|
|
26
|
+
config = { plugins: [{ id: 'visuals' }] };
|
|
27
|
+
sync.changed();
|
|
28
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
29
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'b' }, request });
|
|
30
|
+
expect(request).toHaveBeenCalledTimes(4);
|
|
31
|
+
expect(request).toHaveBeenLastCalledWith('plugins.configure', config);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('builds a scoped hook\'s config with its scope', async () => {
|
|
35
|
+
const buildConfig = vi.fn(async (scope) => ({ plugins: [], scope: scope ?? null }));
|
|
36
|
+
const sync = createPluginDaemonSync({ buildConfig, logger: { warn: vi.fn() } });
|
|
37
|
+
const request = vi.fn(async () => ({}));
|
|
38
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'main' }, request });
|
|
39
|
+
await sync.onDaemonReadyFor({ roots: ['/work/night'] })({ health: { streamEpoch: 'sandbox' }, request });
|
|
40
|
+
expect(request.mock.calls).toEqual([
|
|
41
|
+
['plugins.configure', { plugins: [], scope: null }],
|
|
42
|
+
['plugins.configure', { plugins: [], scope: { roots: ['/work/night'] } }],
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('shares one push between concurrent requests', async () => {
|
|
47
|
+
const gate = deferred();
|
|
48
|
+
const sync = createPluginDaemonSync({ buildConfig: async () => ({ plugins: [] }) });
|
|
49
|
+
const request = vi.fn(() => gate.promise);
|
|
50
|
+
const first = sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
51
|
+
const second = sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
52
|
+
gate.resolve({});
|
|
53
|
+
await Promise.all([first, second]);
|
|
54
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('logs a failed push, never throws, and retries after the delay', async () => {
|
|
58
|
+
let time = 0;
|
|
59
|
+
const logger = { warn: vi.fn() };
|
|
60
|
+
const sync = createPluginDaemonSync({ buildConfig: async () => ({ plugins: [] }), logger, retryDelayMs: 1_000, now: () => time });
|
|
61
|
+
const request = vi.fn(async () => {
|
|
62
|
+
const error = new Error('down');
|
|
63
|
+
error.code = 'DAEMON_UNAVAILABLE';
|
|
64
|
+
throw error;
|
|
65
|
+
});
|
|
66
|
+
await expect(sync.onDaemonReady({ health: { streamEpoch: 'a' }, request })).resolves.toBeUndefined();
|
|
67
|
+
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('DAEMON_UNAVAILABLE'));
|
|
68
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
69
|
+
expect(request).toHaveBeenCalledTimes(1);
|
|
70
|
+
time = 1_500;
|
|
71
|
+
request.mockResolvedValueOnce({});
|
|
72
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
73
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
74
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
75
|
+
expect(request).toHaveBeenCalledTimes(2);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('a config that cannot be built is a failed push, not a thrown request', async () => {
|
|
79
|
+
const logger = { warn: vi.fn() };
|
|
80
|
+
const sync = createPluginDaemonSync({ buildConfig: async () => { throw Object.assign(new Error('x'), { code: 'PLUGINS_UNREADABLE' }); }, logger });
|
|
81
|
+
const request = vi.fn();
|
|
82
|
+
await sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
83
|
+
expect(request).not.toHaveBeenCalled();
|
|
84
|
+
expect(logger.warn).toHaveBeenCalledWith(expect.stringContaining('PLUGINS_UNREADABLE'));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('pushes changes in order and probes on change', async () => {
|
|
88
|
+
const pushed = [];
|
|
89
|
+
let value = 0;
|
|
90
|
+
const gate = deferred();
|
|
91
|
+
const refresh = vi.fn();
|
|
92
|
+
const sync = createPluginDaemonSync({ buildConfig: async () => ({ value }), refresh });
|
|
93
|
+
const request = vi.fn(async (_command, payload) => {
|
|
94
|
+
if (pushed.length === 0) await gate.promise;
|
|
95
|
+
pushed.push(payload.value);
|
|
96
|
+
});
|
|
97
|
+
const first = sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
98
|
+
value = 1;
|
|
99
|
+
sync.changed();
|
|
100
|
+
await Promise.resolve();
|
|
101
|
+
expect(refresh).toHaveBeenCalledTimes(1);
|
|
102
|
+
const second = sync.onDaemonReady({ health: { streamEpoch: 'a' }, request });
|
|
103
|
+
gate.resolve();
|
|
104
|
+
await Promise.all([first, second]);
|
|
105
|
+
// The first push already carried the newer value; nothing older lands last.
|
|
106
|
+
expect(pushed.at(-1)).toBe(1);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { pathToFileURL } from 'node:url';
|
|
2
|
+
|
|
3
|
+
import { defaultPluginState } from './manifest.js';
|
|
4
|
+
import { createInertPichamberUi } from '../pi/session-daemon/pichamber-ui.js';
|
|
5
|
+
|
|
6
|
+
// Agent impact is measured, not declared: the server runs a plugin's agent
|
|
7
|
+
// half once against a recording stand-in for the Pi extension API and reports
|
|
8
|
+
// what reaches the model.
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Events whose handlers can change what the model sees: the prompt, the
|
|
12
|
+
* context, the provider request, tool results, or discovered resources.
|
|
13
|
+
*/
|
|
14
|
+
const PROMPT_AFFECTING_EVENTS = Object.freeze([
|
|
15
|
+
'resources_discover',
|
|
16
|
+
'input',
|
|
17
|
+
'before_agent_start',
|
|
18
|
+
'context',
|
|
19
|
+
'context_with_system',
|
|
20
|
+
'before_provider_request',
|
|
21
|
+
'tool_result',
|
|
22
|
+
'message_end',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
const PROMPT_AFFECTING = new Set(PROMPT_AFFECTING_EVENTS);
|
|
26
|
+
const MEASURE_TIMEOUT_MS = 5_000;
|
|
27
|
+
|
|
28
|
+
/** Token estimate for one tool declaration: ceil(chars / 4) of its JSON. */
|
|
29
|
+
export const estimateToolTokens = ({ name, description, parameters }) => (
|
|
30
|
+
Math.ceil(JSON.stringify({ name, description, parameters }).length / 4)
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// Methods that return values Pi code commonly reads during load.
|
|
34
|
+
const RETURNING = {
|
|
35
|
+
getActiveTools: () => [],
|
|
36
|
+
getAllTools: () => [],
|
|
37
|
+
getCommands: () => [],
|
|
38
|
+
getThinkingLevel: () => 'off',
|
|
39
|
+
getSessionName: () => undefined,
|
|
40
|
+
getFlag: () => undefined,
|
|
41
|
+
on: () => () => {},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const createRecordingApi = () => {
|
|
45
|
+
const tools = [];
|
|
46
|
+
const hooks = new Set();
|
|
47
|
+
const commands = [];
|
|
48
|
+
const recorders = {
|
|
49
|
+
registerTool: (tool) => {
|
|
50
|
+
tools.push({
|
|
51
|
+
name: String(tool?.name ?? ''),
|
|
52
|
+
exposure: typeof tool?.exposure === 'string' ? tool.exposure : 'direct',
|
|
53
|
+
tokens: estimateToolTokens(tool ?? {}),
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
on: (event) => {
|
|
57
|
+
if (PROMPT_AFFECTING.has(event)) hooks.add(event);
|
|
58
|
+
return () => {};
|
|
59
|
+
},
|
|
60
|
+
registerCommand: (name) => {
|
|
61
|
+
if (typeof name === 'string') commands.push(name);
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
// Every other API member is a no-op, so plugins that set up renderers,
|
|
65
|
+
// flags, or event buses still load.
|
|
66
|
+
const api = new Proxy({}, {
|
|
67
|
+
get: (_target, property) => {
|
|
68
|
+
if (typeof property !== 'string') return undefined;
|
|
69
|
+
if (Object.hasOwn(recorders, property)) return recorders[property];
|
|
70
|
+
if (Object.hasOwn(RETURNING, property)) return RETURNING[property];
|
|
71
|
+
if (property === 'events') return { on: () => () => {}, emit: () => {} };
|
|
72
|
+
if (property === 'then') return undefined;
|
|
73
|
+
return () => undefined;
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
api,
|
|
78
|
+
result: () => ({ tools, hooks: PROMPT_AFFECTING_EVENTS.filter((event) => hooks.has(event)), commands }),
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const withTimeout = (promise, ms) => {
|
|
83
|
+
let timer;
|
|
84
|
+
return Promise.race([
|
|
85
|
+
promise,
|
|
86
|
+
new Promise((_resolve, reject) => {
|
|
87
|
+
timer = setTimeout(() => reject(new Error('measurement timed out')), ms);
|
|
88
|
+
timer.unref?.();
|
|
89
|
+
}),
|
|
90
|
+
]).finally(() => clearTimeout(timer));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const shortReason = (error) => {
|
|
94
|
+
const message = typeof error?.message === 'string' ? error.message : 'the agent half failed to load';
|
|
95
|
+
return message.length > 160 ? `${message.slice(0, 157)}...` : message;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Measure one plugin. Resolves `{ impact }` or `{ impact: null, impactError }`;
|
|
100
|
+
* it never rejects.
|
|
101
|
+
*/
|
|
102
|
+
export const measurePluginImpact = async (manifest, {
|
|
103
|
+
importModule = (entry) => import(pathToFileURL(entry).href),
|
|
104
|
+
timeoutMs = MEASURE_TIMEOUT_MS,
|
|
105
|
+
} = {}) => {
|
|
106
|
+
try {
|
|
107
|
+
const module = await withTimeout(importModule(manifest.entry), timeoutMs);
|
|
108
|
+
const factory = module?.default;
|
|
109
|
+
if (typeof factory !== 'function') throw new Error('the agent half has no default export');
|
|
110
|
+
const recording = createRecordingApi();
|
|
111
|
+
const defaults = defaultPluginState(manifest);
|
|
112
|
+
const pichamber = {
|
|
113
|
+
id: manifest.id,
|
|
114
|
+
ui: createInertPichamberUi(),
|
|
115
|
+
state: () => ({ ...defaults }),
|
|
116
|
+
onStateChange: () => () => {},
|
|
117
|
+
};
|
|
118
|
+
await withTimeout(Promise.resolve(factory(recording.api, pichamber)), timeoutMs);
|
|
119
|
+
return { impact: recording.result() };
|
|
120
|
+
} catch (error) {
|
|
121
|
+
return { impact: null, impactError: shortReason(error) };
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/** Caches measurements per plugin id and version. */
|
|
126
|
+
export const createImpactCache = ({ measure = measurePluginImpact } = {}) => {
|
|
127
|
+
const cache = new Map();
|
|
128
|
+
return {
|
|
129
|
+
get: (manifest) => {
|
|
130
|
+
const key = `${manifest.id}@${manifest.version}`;
|
|
131
|
+
let entry = cache.get(key);
|
|
132
|
+
if (!entry) {
|
|
133
|
+
entry = measure(manifest);
|
|
134
|
+
cache.set(key, entry);
|
|
135
|
+
}
|
|
136
|
+
return entry;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { mkdtemp, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { createImpactCache, estimateToolTokens, measurePluginImpact } from './impact.js';
|
|
7
|
+
|
|
8
|
+
const fixture = async (source) => {
|
|
9
|
+
const dir = await mkdtemp(join(tmpdir(), 'pichamber-plugin-impact-'));
|
|
10
|
+
const entry = join(dir, 'extension.js');
|
|
11
|
+
await writeFile(entry, source);
|
|
12
|
+
return {
|
|
13
|
+
id: 'fixture',
|
|
14
|
+
version: '1.0.0',
|
|
15
|
+
entry,
|
|
16
|
+
stateSchema: { on: { type: 'boolean', scope: 'global', default: true, label: 'On' } },
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('plugin impact', () => {
|
|
21
|
+
it('records tools, prompt-affecting hooks and commands', async () => {
|
|
22
|
+
const manifest = await fixture(`
|
|
23
|
+
export default function (pi, pichamber) {
|
|
24
|
+
if (pichamber.state().on !== true) throw new Error('defaults missing');
|
|
25
|
+
pichamber.ui.choose({}, 'T', []).then(() => {});
|
|
26
|
+
pi.registerTool({ name: 'a_tool', description: 'Does a.', parameters: { type: 'object' } });
|
|
27
|
+
pi.registerTool({ name: 'b_tool', description: 'Does b.', parameters: { type: 'object' }, exposure: 'deferred' });
|
|
28
|
+
pi.on('before_agent_start', () => {});
|
|
29
|
+
pi.on('context', () => {});
|
|
30
|
+
pi.on('session_start', () => {});
|
|
31
|
+
pi.registerCommand('demo', { handler: () => {} });
|
|
32
|
+
pi.registerMessageRenderer('x', () => null);
|
|
33
|
+
pi.getActiveTools().includes('a_tool');
|
|
34
|
+
}
|
|
35
|
+
`);
|
|
36
|
+
const { impact } = await measurePluginImpact(manifest);
|
|
37
|
+
expect(impact).toEqual({
|
|
38
|
+
tools: [
|
|
39
|
+
{ name: 'a_tool', exposure: 'direct', tokens: estimateToolTokens({ name: 'a_tool', description: 'Does a.', parameters: { type: 'object' } }) },
|
|
40
|
+
{ name: 'b_tool', exposure: 'deferred', tokens: expect.any(Number) },
|
|
41
|
+
],
|
|
42
|
+
hooks: ['before_agent_start', 'context'],
|
|
43
|
+
commands: ['demo'],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('estimates tokens as ceil(chars / 4) of the declaration JSON', () => {
|
|
48
|
+
const tool = { name: 'x', description: 'y', parameters: { type: 'object' } };
|
|
49
|
+
expect(estimateToolTokens(tool)).toBe(Math.ceil(JSON.stringify(tool).length / 4));
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('reports a throwing or invalid plugin as unmeasured', async () => {
|
|
53
|
+
const throwing = await fixture('export default function () { throw new Error("boom"); }');
|
|
54
|
+
await expect(measurePluginImpact(throwing)).resolves.toEqual({ impact: null, impactError: 'boom' });
|
|
55
|
+
const noDefault = await fixture('export const x = 1;');
|
|
56
|
+
await expect(measurePluginImpact(noDefault)).resolves.toMatchObject({ impact: null, impactError: expect.stringMatching(/default export/) });
|
|
57
|
+
const hanging = await fixture('export default function () { return new Promise(() => {}); }');
|
|
58
|
+
await expect(measurePluginImpact(hanging, { timeoutMs: 20 })).resolves.toMatchObject({ impact: null, impactError: expect.stringMatching(/timed out/) });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('measures the bundled Visuals plugin', async () => {
|
|
62
|
+
const entry = new URL('../../../plugins/visuals/extension.js', import.meta.url).pathname;
|
|
63
|
+
const { impact } = await measurePluginImpact({ id: 'visuals', version: '1.0.0', entry, stateSchema: {} });
|
|
64
|
+
expect(impact.tools).toEqual([
|
|
65
|
+
{ name: 'render_html', exposure: 'direct', tokens: expect.any(Number) },
|
|
66
|
+
{ name: 'render_choices', exposure: 'direct', tokens: expect.any(Number) },
|
|
67
|
+
]);
|
|
68
|
+
// Includes the layout, text-size and colour rules that keep pages in the chat's look.
|
|
69
|
+
expect(impact.tools[0].tokens).toBeLessThan(330);
|
|
70
|
+
expect(impact.tools[1].tokens).toBeLessThan(400);
|
|
71
|
+
expect(impact.hooks).toEqual([]);
|
|
72
|
+
expect(impact.commands).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('caches per plugin id and version', async () => {
|
|
76
|
+
const measure = vi.fn(async () => ({ impact: { tools: [], hooks: [], commands: [] } }));
|
|
77
|
+
const cache = createImpactCache({ measure });
|
|
78
|
+
await cache.get({ id: 'a', version: '1.0.0' });
|
|
79
|
+
await cache.get({ id: 'a', version: '1.0.0' });
|
|
80
|
+
await cache.get({ id: 'a', version: '1.0.1' });
|
|
81
|
+
expect(measure).toHaveBeenCalledTimes(2);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { isAbsolute, relative, resolve } from 'node:path';
|
|
2
|
+
|
|
3
|
+
// A plugin is a Pi package whose package.json carries a `pichamber` block.
|
|
4
|
+
// Parsing fails closed: any field that is missing, of the wrong type, or out
|
|
5
|
+
// of range rejects the whole plugin with a short reason.
|
|
6
|
+
|
|
7
|
+
const PLUGIN_API_VERSION = 1;
|
|
8
|
+
|
|
9
|
+
const ID_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
10
|
+
const MAX_ID_LENGTH = 40;
|
|
11
|
+
const STATE_KEY_PATTERN = /^[a-zA-Z][a-zA-Z0-9_]{0,39}$/;
|
|
12
|
+
const ICON_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
13
|
+
const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$/;
|
|
14
|
+
const MAX_NAME = 60;
|
|
15
|
+
const MAX_LABEL = 80;
|
|
16
|
+
const MAX_DESCRIPTION = 240;
|
|
17
|
+
const MAX_STATE_KEYS = 32;
|
|
18
|
+
const MAX_ENUM_OPTIONS = 32;
|
|
19
|
+
const MAX_TOGGLES = 4;
|
|
20
|
+
const FORBIDDEN_KEYS = new Set(['__proto__', 'prototype', 'constructor']);
|
|
21
|
+
// Discovery keywords every Pi package or PiChamber plugin carries; they say
|
|
22
|
+
// nothing about what one plugin does, so they are left out of its keywords.
|
|
23
|
+
const DISCOVERY_KEYWORDS = new Set(['pi-package', 'pichamber-plugin']);
|
|
24
|
+
const MAX_KEYWORDS = 16;
|
|
25
|
+
const MAX_KEYWORD_LENGTH = 40;
|
|
26
|
+
|
|
27
|
+
class PluginManifestError extends Error {
|
|
28
|
+
constructor(reason) {
|
|
29
|
+
super(reason);
|
|
30
|
+
this.code = 'INVALID_PLUGIN_MANIFEST';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fail = (reason) => {
|
|
35
|
+
throw new PluginManifestError(reason);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
39
|
+
|
|
40
|
+
const text = (value, max, field, { optional = false } = {}) => {
|
|
41
|
+
if (value === undefined && optional) return undefined;
|
|
42
|
+
if (typeof value !== 'string' || value.trim().length === 0 || value.length > max) fail(`${field} is invalid`);
|
|
43
|
+
return value.trim();
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const pluginId = (value, field) => {
|
|
47
|
+
if (typeof value !== 'string' || value.length > MAX_ID_LENGTH || !ID_PATTERN.test(value)) fail(`${field} is invalid`);
|
|
48
|
+
return value;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const icon = (value, field) => {
|
|
52
|
+
if (typeof value !== 'string' || value.length > 64 || !ICON_PATTERN.test(value)) fail(`${field} is invalid`);
|
|
53
|
+
return value;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const parseStateField = (key, value) => {
|
|
57
|
+
if (!isRecord(value)) fail(`state.${key} is invalid`);
|
|
58
|
+
const { type, scope } = value;
|
|
59
|
+
if (type !== 'boolean' && type !== 'enum') fail(`state.${key}.type is invalid`);
|
|
60
|
+
if (scope !== 'global' && scope !== 'project') fail(`state.${key}.scope is invalid`);
|
|
61
|
+
const label = text(value.label, MAX_LABEL, `state.${key}.label`);
|
|
62
|
+
const description = text(value.description, MAX_DESCRIPTION, `state.${key}.description`, { optional: true });
|
|
63
|
+
const field = { type, scope, default: value.default, label };
|
|
64
|
+
if (description) field.description = description;
|
|
65
|
+
if (type === 'boolean') {
|
|
66
|
+
if (typeof value.default !== 'boolean') fail(`state.${key}.default is invalid`);
|
|
67
|
+
if (value.options !== undefined) fail(`state.${key}.options is only for enum values`);
|
|
68
|
+
return field;
|
|
69
|
+
}
|
|
70
|
+
if (!Array.isArray(value.options) || value.options.length === 0 || value.options.length > MAX_ENUM_OPTIONS) {
|
|
71
|
+
fail(`state.${key}.options is invalid`);
|
|
72
|
+
}
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
field.options = value.options.map((option, index) => {
|
|
75
|
+
if (!isRecord(option) || typeof option.value !== 'string' || option.value.length === 0 || option.value.length > 64) {
|
|
76
|
+
fail(`state.${key}.options[${index}] is invalid`);
|
|
77
|
+
}
|
|
78
|
+
if (seen.has(option.value)) fail(`state.${key}.options repeats ${option.value}`);
|
|
79
|
+
seen.add(option.value);
|
|
80
|
+
return { value: option.value, label: text(option.label, MAX_LABEL, `state.${key}.options[${index}].label`) };
|
|
81
|
+
});
|
|
82
|
+
if (typeof value.default !== 'string' || !seen.has(value.default)) fail(`state.${key}.default is invalid`);
|
|
83
|
+
return field;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const parseState = (value) => {
|
|
87
|
+
if (value === undefined) return {};
|
|
88
|
+
if (!isRecord(value)) fail('state is invalid');
|
|
89
|
+
const entries = Object.entries(value);
|
|
90
|
+
if (entries.length > MAX_STATE_KEYS) fail('state has too many values');
|
|
91
|
+
const schema = {};
|
|
92
|
+
for (const [key, field] of entries) {
|
|
93
|
+
if (!STATE_KEY_PATTERN.test(key) || FORBIDDEN_KEYS.has(key)) fail(`state key ${key} is invalid`);
|
|
94
|
+
schema[key] = parseStateField(key, field);
|
|
95
|
+
}
|
|
96
|
+
return schema;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const parseContributes = (value, stateSchema) => {
|
|
100
|
+
if (value === undefined) return { composerToggles: [], settings: [] };
|
|
101
|
+
if (!isRecord(value)) fail('contributes is invalid');
|
|
102
|
+
const toggles = value.composerToggles ?? [];
|
|
103
|
+
if (!Array.isArray(toggles) || toggles.length > MAX_TOGGLES) fail('contributes.composerToggles is invalid');
|
|
104
|
+
const toggleIds = new Set();
|
|
105
|
+
const composerToggles = toggles.map((toggle, index) => {
|
|
106
|
+
const field = `contributes.composerToggles[${index}]`;
|
|
107
|
+
if (!isRecord(toggle)) fail(`${field} is invalid`);
|
|
108
|
+
const id = pluginId(toggle.id, `${field}.id`);
|
|
109
|
+
if (toggleIds.has(id)) fail(`${field}.id repeats`);
|
|
110
|
+
toggleIds.add(id);
|
|
111
|
+
if (typeof toggle.state !== 'string' || stateSchema[toggle.state]?.type !== 'boolean') {
|
|
112
|
+
fail(`${field}.state must name a boolean state value`);
|
|
113
|
+
}
|
|
114
|
+
const description = text(toggle.description, MAX_DESCRIPTION, `${field}.description`, { optional: true });
|
|
115
|
+
return {
|
|
116
|
+
id,
|
|
117
|
+
state: toggle.state,
|
|
118
|
+
label: text(toggle.label, MAX_LABEL, `${field}.label`),
|
|
119
|
+
icon: icon(toggle.icon, `${field}.icon`),
|
|
120
|
+
...(description ? { description } : {}),
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
const settingsInput = value.settings ?? [];
|
|
124
|
+
if (!Array.isArray(settingsInput)) fail('contributes.settings is invalid');
|
|
125
|
+
const settings = [];
|
|
126
|
+
for (const key of settingsInput) {
|
|
127
|
+
if (typeof key !== 'string' || !Object.hasOwn(stateSchema, key)) fail('contributes.settings names an unknown state value');
|
|
128
|
+
if (settings.includes(key)) fail(`contributes.settings repeats ${key}`);
|
|
129
|
+
// A composer switch's default is the plugin's own switch in Settings; a
|
|
130
|
+
// second Settings control for it would be a confusing duplicate.
|
|
131
|
+
if (composerToggles.some((toggle) => toggle.state === key)) fail(`contributes.settings lists ${key}, which a composer toggle sets`);
|
|
132
|
+
settings.push(key);
|
|
133
|
+
}
|
|
134
|
+
const contributes = { composerToggles, settings };
|
|
135
|
+
if (value.ui !== undefined) contributes.ui = pluginId(value.ui, 'contributes.ui');
|
|
136
|
+
return contributes;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The agent half is the package's first `pi.extensions` entry. It must be a
|
|
141
|
+
* relative path that stays inside the package folder.
|
|
142
|
+
*/
|
|
143
|
+
const parseEntry = (packageJson, packageDir) => {
|
|
144
|
+
const extensions = packageJson?.pi?.extensions;
|
|
145
|
+
if (!Array.isArray(extensions) || extensions.length === 0) fail('pi.extensions is missing');
|
|
146
|
+
const entry = extensions[0];
|
|
147
|
+
if (typeof entry !== 'string' || entry.length === 0 || isAbsolute(entry)) fail('pi.extensions[0] is invalid');
|
|
148
|
+
const absolute = resolve(packageDir, entry);
|
|
149
|
+
const fromPackage = relative(packageDir, absolute);
|
|
150
|
+
if (fromPackage.length === 0 || fromPackage.startsWith('..') || isAbsolute(fromPackage)) {
|
|
151
|
+
fail('pi.extensions[0] leaves the package');
|
|
152
|
+
}
|
|
153
|
+
if (!/\.m?js$/.test(absolute)) fail('pi.extensions[0] must be a JavaScript module');
|
|
154
|
+
return absolute;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* What the plugin is about, for matching a marketplace search to it: the
|
|
159
|
+
* package keywords without the discovery ones. Bad entries are skipped, not
|
|
160
|
+
* fatal, since they only help search.
|
|
161
|
+
*/
|
|
162
|
+
const parseKeywords = (value) => {
|
|
163
|
+
if (!Array.isArray(value)) return [];
|
|
164
|
+
const keywords = [];
|
|
165
|
+
for (const entry of value) {
|
|
166
|
+
if (typeof entry !== 'string') continue;
|
|
167
|
+
const keyword = entry.trim().toLowerCase();
|
|
168
|
+
if (keyword.length === 0 || keyword.length > MAX_KEYWORD_LENGTH || DISCOVERY_KEYWORDS.has(keyword) || keywords.includes(keyword)) continue;
|
|
169
|
+
keywords.push(keyword);
|
|
170
|
+
if (keywords.length === MAX_KEYWORDS) break;
|
|
171
|
+
}
|
|
172
|
+
return keywords;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Parse one plugin package. `packageDir` must be absolute. Returns the
|
|
177
|
+
* normalized manifest or throws `PluginManifestError`.
|
|
178
|
+
*/
|
|
179
|
+
export const parsePluginPackage = (packageJson, { packageDir, bundled = false }) => {
|
|
180
|
+
if (!isRecord(packageJson)) fail('package.json is invalid');
|
|
181
|
+
if (typeof packageDir !== 'string' || !isAbsolute(packageDir)) fail('package folder is invalid');
|
|
182
|
+
const block = packageJson.pichamber;
|
|
183
|
+
if (!isRecord(block)) fail('pichamber block is missing');
|
|
184
|
+
if (block.apiVersion !== PLUGIN_API_VERSION) fail('pichamber.apiVersion is unsupported');
|
|
185
|
+
const id = pluginId(block.id, 'pichamber.id');
|
|
186
|
+
if (typeof packageJson.version !== 'string' || !VERSION_PATTERN.test(packageJson.version)) fail('version is invalid');
|
|
187
|
+
const defaultEnabled = block.defaultEnabled ?? false;
|
|
188
|
+
if (typeof defaultEnabled !== 'boolean') fail('pichamber.defaultEnabled is invalid');
|
|
189
|
+
if (bundled && defaultEnabled) fail('a bundled plugin must ship disabled');
|
|
190
|
+
if (block.replaceable !== undefined && typeof block.replaceable !== 'boolean') fail('pichamber.replaceable is invalid');
|
|
191
|
+
const stateSchema = parseState(block.state);
|
|
192
|
+
return {
|
|
193
|
+
id,
|
|
194
|
+
name: text(block.name, MAX_NAME, 'pichamber.name'),
|
|
195
|
+
description: text(block.description, MAX_DESCRIPTION, 'pichamber.description'),
|
|
196
|
+
icon: icon(block.icon, 'pichamber.icon'),
|
|
197
|
+
version: packageJson.version,
|
|
198
|
+
...(typeof packageJson.name === 'string' && packageJson.name.length > 0 ? { packageName: packageJson.name } : {}),
|
|
199
|
+
keywords: parseKeywords(packageJson.keywords),
|
|
200
|
+
bundled,
|
|
201
|
+
defaultEnabled,
|
|
202
|
+
replaceable: block.replaceable === true,
|
|
203
|
+
stateSchema,
|
|
204
|
+
contributes: parseContributes(block.contributes, stateSchema),
|
|
205
|
+
entry: parseEntry(packageJson, packageDir),
|
|
206
|
+
packageDir,
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
/** Default value for every state key of a manifest. */
|
|
211
|
+
export const defaultPluginState = (manifest) => Object.fromEntries(
|
|
212
|
+
Object.entries(manifest.stateSchema).map(([key, field]) => [key, field.default]),
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
/** Whether `value` is allowed for state field `field`. */
|
|
216
|
+
export const isValidStateValue = (field, value) => {
|
|
217
|
+
if (!field) return false;
|
|
218
|
+
if (field.type === 'boolean') return typeof value === 'boolean';
|
|
219
|
+
return typeof value === 'string' && field.options.some((option) => option.value === value);
|
|
220
|
+
};
|