@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,177 @@
|
|
|
1
|
+
// Composer controls declared by Pi extensions.
|
|
2
|
+
//
|
|
3
|
+
// A plain Pi extension puts a control in PiChamber's composer by emitting
|
|
4
|
+
// `pichamber:composer` on Pi's shared extension event bus (`pi.events`). The
|
|
5
|
+
// Pi CLI has no listener, so the same extension keeps working there through
|
|
6
|
+
// its own slash commands. Each control names the extension's own commands; a
|
|
7
|
+
// click in PiChamber runs one of them as if it had been typed, and the
|
|
8
|
+
// extension reports its new value by emitting again. The extension stays the
|
|
9
|
+
// only source of truth for the value.
|
|
10
|
+
//
|
|
11
|
+
// pi.events.emit('pichamber:composer', {
|
|
12
|
+
// id: 'mode', kind: 'cycle', label: 'Mode', value: 'balance',
|
|
13
|
+
// options: [{ value: 'economy', label: 'Economy', command: 'economy' }, ...],
|
|
14
|
+
// });
|
|
15
|
+
// pi.events.emit('pichamber:composer', { id: 'mode', remove: true });
|
|
16
|
+
//
|
|
17
|
+
// Kinds: `toggle` (`value: boolean`, `command` flips it), `cycle` (`value`,
|
|
18
|
+
// 2 to 12 `options`, each with its own command), `action` (`command` only).
|
|
19
|
+
|
|
20
|
+
export const COMPOSER_CONTROL_EVENT = 'pichamber:composer';
|
|
21
|
+
|
|
22
|
+
const ID_PATTERN = /^[a-z0-9][a-z0-9-]{0,39}$/;
|
|
23
|
+
const ICON_PATTERN = /^[a-z0-9][a-z0-9-]{0,47}$/;
|
|
24
|
+
// Pi command invocation names: no spaces; Pi adds `:<n>` to tell apart two
|
|
25
|
+
// extensions' commands of the same name.
|
|
26
|
+
const COMMAND_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,63}$/;
|
|
27
|
+
const KINDS = new Set(['toggle', 'cycle', 'action']);
|
|
28
|
+
export const MAX_CONTROLS_PER_SESSION = 16;
|
|
29
|
+
const MAX_OPTIONS = 12;
|
|
30
|
+
const MAX_PENDING = 64;
|
|
31
|
+
|
|
32
|
+
const cleanText = (value, max) => (typeof value === 'string'
|
|
33
|
+
? value.replace(/[\u0000-\u001f\u007f-\u009f]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, max)
|
|
34
|
+
: '');
|
|
35
|
+
|
|
36
|
+
/** `/plan on` or `plan on` → `plan on`; null when the name is not a command name. */
|
|
37
|
+
const parseCommand = (value) => {
|
|
38
|
+
const text = cleanText(value, 200).replace(/^\//, '');
|
|
39
|
+
const name = text.split(' ')[0];
|
|
40
|
+
return COMMAND_NAME_PATTERN.test(name) ? text : null;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** The command's invocation name: the part before the first space. */
|
|
44
|
+
export const commandName = (command) => command.split(' ')[0];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Validate one `pichamber:composer` payload. Returns the control,
|
|
48
|
+
* `{ id, remove: true }`, or null when the payload is not usable (it is then
|
|
49
|
+
* ignored, like a malformed status).
|
|
50
|
+
*/
|
|
51
|
+
export const parseComposerControl = (raw) => {
|
|
52
|
+
if (!raw || typeof raw !== 'object' || typeof raw.id !== 'string' || !ID_PATTERN.test(raw.id)) return null;
|
|
53
|
+
const id = raw.id;
|
|
54
|
+
if (raw.remove === true) return { id, remove: true };
|
|
55
|
+
if (!KINDS.has(raw.kind)) return null;
|
|
56
|
+
const label = cleanText(raw.label, 40);
|
|
57
|
+
if (!label) return null;
|
|
58
|
+
const description = cleanText(raw.description, 200);
|
|
59
|
+
const common = {
|
|
60
|
+
id,
|
|
61
|
+
kind: raw.kind,
|
|
62
|
+
label,
|
|
63
|
+
...(description ? { description } : {}),
|
|
64
|
+
...(typeof raw.icon === 'string' && ICON_PATTERN.test(raw.icon) ? { icon: raw.icon } : {}),
|
|
65
|
+
};
|
|
66
|
+
if (raw.kind === 'cycle') {
|
|
67
|
+
if (!Array.isArray(raw.options)) return null;
|
|
68
|
+
const options = [];
|
|
69
|
+
for (const option of raw.options.slice(0, MAX_OPTIONS)) {
|
|
70
|
+
const value = cleanText(option?.value, 40);
|
|
71
|
+
const optionLabel = cleanText(option?.label, 40) || value;
|
|
72
|
+
const command = parseCommand(option?.command);
|
|
73
|
+
if (!value || !command || options.some((existing) => existing.value === value)) return null;
|
|
74
|
+
options.push({ value, label: optionLabel, command });
|
|
75
|
+
}
|
|
76
|
+
if (options.length < 2) return null;
|
|
77
|
+
const value = typeof raw.value === 'string' && options.some((option) => option.value === raw.value) ? raw.value : undefined;
|
|
78
|
+
return { ...common, options, ...(value !== undefined ? { value } : {}) };
|
|
79
|
+
}
|
|
80
|
+
const command = parseCommand(raw.command);
|
|
81
|
+
if (!command) return null;
|
|
82
|
+
if (raw.kind === 'toggle') return { ...common, command, value: raw.value === true };
|
|
83
|
+
return { ...common, command };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Per-session control state, kept for snapshots and reconnects like extension
|
|
88
|
+
* statuses. `publish(sessionId, payload)` sends `extension.control` live.
|
|
89
|
+
*/
|
|
90
|
+
export const createComposerControls = ({ publish }) => {
|
|
91
|
+
const bySession = new Map();
|
|
92
|
+
|
|
93
|
+
const set = (sessionId, raw) => {
|
|
94
|
+
if (typeof sessionId !== 'string' || sessionId.length === 0) return false;
|
|
95
|
+
const control = parseComposerControl(raw);
|
|
96
|
+
if (!control) return false;
|
|
97
|
+
const controls = bySession.get(sessionId) ?? new Map();
|
|
98
|
+
if (control.remove) {
|
|
99
|
+
if (!controls.delete(control.id)) return false;
|
|
100
|
+
if (controls.size === 0) bySession.delete(sessionId);
|
|
101
|
+
publish(sessionId, { id: control.id, removed: true });
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
// A session keeps its first 16 controls; another one is ignored.
|
|
105
|
+
if (!controls.has(control.id) && controls.size >= MAX_CONTROLS_PER_SESSION) return false;
|
|
106
|
+
controls.set(control.id, control);
|
|
107
|
+
bySession.set(sessionId, controls);
|
|
108
|
+
publish(sessionId, { control });
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/** Drop a session's controls, telling clients each one is gone. */
|
|
113
|
+
const clear = (sessionId) => {
|
|
114
|
+
const controls = bySession.get(sessionId);
|
|
115
|
+
if (!controls) return;
|
|
116
|
+
bySession.delete(sessionId);
|
|
117
|
+
for (const id of controls.keys()) publish(sessionId, { id, removed: true });
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const snapshot = (sessionId) => {
|
|
121
|
+
const controls = bySession.get(sessionId);
|
|
122
|
+
return controls?.size ? [...controls.values()] : undefined;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The command a click asks for. `value` is the value the client wants:
|
|
127
|
+
* `true`/`false` for a toggle, an option value for a cycle, nothing for an
|
|
128
|
+
* action. A value the control already has needs no command (`{ command:
|
|
129
|
+
* null }`), so a repeated click cannot flip a toggle twice.
|
|
130
|
+
*/
|
|
131
|
+
const resolve = (sessionId, id, value) => {
|
|
132
|
+
const control = bySession.get(sessionId)?.get(id);
|
|
133
|
+
if (!control) return { error: 'CONTROL_NOT_FOUND' };
|
|
134
|
+
if (control.kind === 'action') return { control, command: control.command };
|
|
135
|
+
if (control.kind === 'toggle') {
|
|
136
|
+
if (typeof value !== 'boolean') return { error: 'INVALID_ARGUMENT' };
|
|
137
|
+
return { control, command: value === control.value ? null : control.command };
|
|
138
|
+
}
|
|
139
|
+
const option = control.options.find((candidate) => candidate.value === value);
|
|
140
|
+
if (!option) return { error: 'INVALID_ARGUMENT' };
|
|
141
|
+
return { control, command: value === control.value ? null : option.command };
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const sessionIds = () => [...bySession.keys()];
|
|
145
|
+
|
|
146
|
+
return { set, clear, snapshot, resolve, sessionIds };
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The extension factory that listens on a runtime's event bus. One runtime
|
|
151
|
+
* hosts one session; the id is known from `session_start`, which reaches
|
|
152
|
+
* this factory after the user's extensions (Pi loads factories last), so
|
|
153
|
+
* controls emitted before it are held until then.
|
|
154
|
+
*/
|
|
155
|
+
const COMPOSER_CONTROLS_EXTENSION_NAME = 'pichamber:composer-controls';
|
|
156
|
+
|
|
157
|
+
/** Pi labels a named factory `<inline:name>`; this one is not listed as an extension. */
|
|
158
|
+
export const isComposerControlsExtensionPath = (extensionPath) => extensionPath === `<inline:${COMPOSER_CONTROLS_EXTENSION_NAME}>`;
|
|
159
|
+
|
|
160
|
+
export const createComposerControlsExtension = (onControl) => ({
|
|
161
|
+
name: COMPOSER_CONTROLS_EXTENSION_NAME,
|
|
162
|
+
hidden: true,
|
|
163
|
+
factory: (pi) => {
|
|
164
|
+
let sessionId;
|
|
165
|
+
const pending = [];
|
|
166
|
+
pi.events?.on?.(COMPOSER_CONTROL_EVENT, (data) => {
|
|
167
|
+
if (sessionId) onControl(sessionId, data);
|
|
168
|
+
else if (pending.length < MAX_PENDING) pending.push(data);
|
|
169
|
+
});
|
|
170
|
+
pi.on?.('session_start', (_event, ctx) => {
|
|
171
|
+
const id = ctx?.sessionManager?.getSessionId?.();
|
|
172
|
+
if (typeof id !== 'string' || id.length === 0) return;
|
|
173
|
+
sessionId = id;
|
|
174
|
+
for (const data of pending.splice(0)) onControl(sessionId, data);
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
COMPOSER_CONTROL_EVENT,
|
|
5
|
+
MAX_CONTROLS_PER_SESSION,
|
|
6
|
+
commandName,
|
|
7
|
+
createComposerControls,
|
|
8
|
+
createComposerControlsExtension,
|
|
9
|
+
isComposerControlsExtensionPath,
|
|
10
|
+
parseComposerControl,
|
|
11
|
+
} from './extension-controls.js';
|
|
12
|
+
|
|
13
|
+
const MODES = {
|
|
14
|
+
id: 'mode',
|
|
15
|
+
kind: 'cycle',
|
|
16
|
+
label: 'Mode',
|
|
17
|
+
value: 'balance',
|
|
18
|
+
options: [
|
|
19
|
+
{ value: 'economy', label: 'Economy', command: 'economy' },
|
|
20
|
+
{ value: 'balance', label: 'Balance', command: '/balance' },
|
|
21
|
+
{ value: 'premium', label: 'Premium', command: 'premium' },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
describe('parseComposerControl', () => {
|
|
26
|
+
it('keeps a cycle control and strips the slash from commands', () => {
|
|
27
|
+
expect(parseComposerControl(MODES)).toEqual({
|
|
28
|
+
id: 'mode',
|
|
29
|
+
kind: 'cycle',
|
|
30
|
+
label: 'Mode',
|
|
31
|
+
value: 'balance',
|
|
32
|
+
options: [
|
|
33
|
+
{ value: 'economy', label: 'Economy', command: 'economy' },
|
|
34
|
+
{ value: 'balance', label: 'Balance', command: 'balance' },
|
|
35
|
+
{ value: 'premium', label: 'Premium', command: 'premium' },
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('keeps toggles and actions, with optional description and icon', () => {
|
|
41
|
+
expect(parseComposerControl({ id: 'plan', kind: 'toggle', label: 'Plan', value: true, command: 'plan', icon: 'list-check-3', description: 'Read-only planning' }))
|
|
42
|
+
.toEqual({ id: 'plan', kind: 'toggle', label: 'Plan', value: true, command: 'plan', icon: 'list-check-3', description: 'Read-only planning' });
|
|
43
|
+
// A toggle without a boolean value is off.
|
|
44
|
+
expect(parseComposerControl({ id: 'plan', kind: 'toggle', label: 'Plan', command: 'plan' })).toMatchObject({ value: false });
|
|
45
|
+
expect(parseComposerControl({ id: 'review', kind: 'action', label: 'Review', command: 'review --staged' }))
|
|
46
|
+
.toEqual({ id: 'review', kind: 'action', label: 'Review', command: 'review --staged' });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('reads a removal', () => {
|
|
50
|
+
expect(parseComposerControl({ id: 'mode', remove: true })).toEqual({ id: 'mode', remove: true });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('drops a cycle value that is not one of its options', () => {
|
|
54
|
+
expect(parseComposerControl({ ...MODES, value: 'turbo' })).not.toHaveProperty('value');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('cleans text and ignores a bad icon name', () => {
|
|
58
|
+
const control = parseComposerControl({ id: 'plan', kind: 'toggle', label: ' Plan\nmode ', command: 'plan', icon: '../x' });
|
|
59
|
+
expect(control).toMatchObject({ label: 'Plan mode' });
|
|
60
|
+
expect(control).not.toHaveProperty('icon');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('rejects unusable payloads', () => {
|
|
64
|
+
for (const bad of [
|
|
65
|
+
null,
|
|
66
|
+
'mode',
|
|
67
|
+
{ ...MODES, id: 'Mode' },
|
|
68
|
+
{ ...MODES, id: 'x'.repeat(41) },
|
|
69
|
+
{ ...MODES, kind: 'slider' },
|
|
70
|
+
{ ...MODES, label: ' ' },
|
|
71
|
+
{ ...MODES, options: [MODES.options[0]] },
|
|
72
|
+
{ ...MODES, options: [MODES.options[0], MODES.options[0]] },
|
|
73
|
+
{ ...MODES, options: [MODES.options[0], { value: 'x', label: 'X', command: '' }] },
|
|
74
|
+
{ id: 'plan', kind: 'toggle', label: 'Plan' },
|
|
75
|
+
{ id: 'plan', kind: 'toggle', label: 'Plan', command: 'bad;name' },
|
|
76
|
+
{ id: 'run', kind: 'action', label: 'Run', command: '/' },
|
|
77
|
+
]) {
|
|
78
|
+
expect(parseComposerControl(bad)).toBeNull();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('commandName and the listener path', () => {
|
|
84
|
+
it('reads the invocation name and recognises the listener', () => {
|
|
85
|
+
expect(commandName('review --staged')).toBe('review');
|
|
86
|
+
expect(isComposerControlsExtensionPath('<inline:pichamber:composer-controls>')).toBe(true);
|
|
87
|
+
expect(isComposerControlsExtensionPath('<inline:pichamber:visuals>')).toBe(false);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('createComposerControls', () => {
|
|
92
|
+
const setup = () => {
|
|
93
|
+
const published = [];
|
|
94
|
+
const controls = createComposerControls({ publish: (sessionId, payload) => published.push([sessionId, payload]) });
|
|
95
|
+
return { controls, published };
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
it('stores, replaces, publishes, and removes a session\'s controls', () => {
|
|
99
|
+
const { controls, published } = setup();
|
|
100
|
+
expect(controls.set('s1', MODES)).toBe(true);
|
|
101
|
+
expect(controls.set('s1', { ...MODES, value: 'premium' })).toBe(true);
|
|
102
|
+
expect(controls.snapshot('s1')).toEqual([expect.objectContaining({ id: 'mode', value: 'premium' })]);
|
|
103
|
+
expect(controls.snapshot('s2')).toBeUndefined();
|
|
104
|
+
expect(controls.set('s1', { id: 'mode', remove: true })).toBe(true);
|
|
105
|
+
// Removing what is not there publishes nothing.
|
|
106
|
+
expect(controls.set('s1', { id: 'mode', remove: true })).toBe(false);
|
|
107
|
+
expect(controls.snapshot('s1')).toBeUndefined();
|
|
108
|
+
expect(published.map(([sessionId, payload]) => [sessionId, payload.control?.value ?? payload])).toEqual([
|
|
109
|
+
['s1', 'balance'],
|
|
110
|
+
['s1', 'premium'],
|
|
111
|
+
['s1', { id: 'mode', removed: true }],
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('ignores invalid payloads and controls past the cap', () => {
|
|
116
|
+
const { controls, published } = setup();
|
|
117
|
+
expect(controls.set('s1', { id: 'bad' })).toBe(false);
|
|
118
|
+
expect(controls.set('', MODES)).toBe(false);
|
|
119
|
+
for (let index = 0; index < MAX_CONTROLS_PER_SESSION; index += 1) {
|
|
120
|
+
expect(controls.set('s1', { id: `a${index}`, kind: 'action', label: 'A', command: 'a' })).toBe(true);
|
|
121
|
+
}
|
|
122
|
+
expect(controls.set('s1', { id: 'one-more', kind: 'action', label: 'A', command: 'a' })).toBe(false);
|
|
123
|
+
// An existing control can still change.
|
|
124
|
+
expect(controls.set('s1', { id: 'a0', kind: 'action', label: 'B', command: 'b' })).toBe(true);
|
|
125
|
+
expect(published).toHaveLength(MAX_CONTROLS_PER_SESSION + 1);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('clears a session and tells clients about each control', () => {
|
|
129
|
+
const { controls, published } = setup();
|
|
130
|
+
controls.set('s1', MODES);
|
|
131
|
+
controls.set('s1', { id: 'plan', kind: 'toggle', label: 'Plan', command: 'plan' });
|
|
132
|
+
controls.set('s2', MODES);
|
|
133
|
+
published.length = 0;
|
|
134
|
+
controls.clear('s1');
|
|
135
|
+
controls.clear('s1');
|
|
136
|
+
expect(published).toEqual([['s1', { id: 'mode', removed: true }], ['s1', { id: 'plan', removed: true }]]);
|
|
137
|
+
expect(controls.sessionIds()).toEqual(['s2']);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('resolves a click to a command, and to none when the value is already set', () => {
|
|
141
|
+
const { controls } = setup();
|
|
142
|
+
controls.set('s1', MODES);
|
|
143
|
+
controls.set('s1', { id: 'plan', kind: 'toggle', label: 'Plan', command: 'plan', value: false });
|
|
144
|
+
controls.set('s1', { id: 'review', kind: 'action', label: 'Review', command: 'review --staged' });
|
|
145
|
+
expect(controls.resolve('s1', 'mode', 'premium')).toMatchObject({ command: 'premium' });
|
|
146
|
+
expect(controls.resolve('s1', 'mode', 'balance')).toMatchObject({ command: null });
|
|
147
|
+
expect(controls.resolve('s1', 'mode', 'turbo')).toEqual({ error: 'INVALID_ARGUMENT' });
|
|
148
|
+
expect(controls.resolve('s1', 'plan', true)).toMatchObject({ command: 'plan' });
|
|
149
|
+
expect(controls.resolve('s1', 'plan', false)).toMatchObject({ command: null });
|
|
150
|
+
expect(controls.resolve('s1', 'plan', 'yes')).toEqual({ error: 'INVALID_ARGUMENT' });
|
|
151
|
+
expect(controls.resolve('s1', 'review')).toMatchObject({ command: 'review --staged' });
|
|
152
|
+
expect(controls.resolve('s1', 'gone', true)).toEqual({ error: 'CONTROL_NOT_FOUND' });
|
|
153
|
+
expect(controls.resolve('s2', 'mode', 'premium')).toEqual({ error: 'CONTROL_NOT_FOUND' });
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('createComposerControlsExtension', () => {
|
|
158
|
+
const fakePi = () => {
|
|
159
|
+
const listeners = new Map();
|
|
160
|
+
const handlers = new Map();
|
|
161
|
+
return {
|
|
162
|
+
events: { on: (event, listener) => listeners.set(event, listener), emit: (event, data) => listeners.get(event)?.(data) },
|
|
163
|
+
on: (event, handler) => handlers.set(event, handler),
|
|
164
|
+
start: (sessionId) => handlers.get('session_start')?.({ type: 'session_start' }, { sessionManager: { getSessionId: () => sessionId } }),
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
it('holds controls emitted before session_start, then forwards them with the session id', () => {
|
|
169
|
+
const received = [];
|
|
170
|
+
const extension = createComposerControlsExtension((sessionId, data) => received.push([sessionId, data.id]));
|
|
171
|
+
expect(extension).toMatchObject({ name: 'pichamber:composer-controls', hidden: true });
|
|
172
|
+
const pi = fakePi();
|
|
173
|
+
extension.factory(pi);
|
|
174
|
+
pi.events.emit(COMPOSER_CONTROL_EVENT, { id: 'early' });
|
|
175
|
+
expect(received).toEqual([]);
|
|
176
|
+
pi.start('s1');
|
|
177
|
+
pi.events.emit(COMPOSER_CONTROL_EVENT, { id: 'late' });
|
|
178
|
+
pi.events.emit('other:event', { id: 'ignored' });
|
|
179
|
+
expect(received).toEqual([['s1', 'early'], ['s1', 'late']]);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
@@ -6,6 +6,9 @@ import { basename, dirname, resolve } from 'node:path';
|
|
|
6
6
|
|
|
7
7
|
const GENERIC_NAMES = new Set(['src', 'dist', 'lib', 'build', 'out', 'extensions']);
|
|
8
8
|
const SCRIPT_EXTENSION_PATTERN = /\.[cm]?[jt]sx?$/;
|
|
9
|
+
// Pi labels inline factories `<inline:name>`. PiChamber plugins are inline
|
|
10
|
+
// factories named `pichamber:<id>`; show them like Pi's `builtin:<name>`.
|
|
11
|
+
const PLUGIN_FACTORY_PATTERN = /^<inline:(pichamber:[a-z0-9-]+)>$/;
|
|
9
12
|
|
|
10
13
|
/**
|
|
11
14
|
* Derives a path-free human-readable display name for an extension.
|
|
@@ -20,6 +23,9 @@ export const deriveExtensionName = (extensionPath, sourceInfo) => {
|
|
|
20
23
|
return 'unknown';
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
const plugin = PLUGIN_FACTORY_PATTERN.exec(extensionPath);
|
|
27
|
+
if (plugin) return plugin[1];
|
|
28
|
+
|
|
23
29
|
const base = basename(extensionPath);
|
|
24
30
|
const stem = base.replace(SCRIPT_EXTENSION_PATTERN, '');
|
|
25
31
|
|
|
@@ -2,6 +2,11 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { deriveExtensionName, resolveExtensionName } from './extension-name.js';
|
|
3
3
|
|
|
4
4
|
describe('deriveExtensionName', () => {
|
|
5
|
+
it('names a PiChamber plugin factory like a Pi built-in', () => {
|
|
6
|
+
expect(deriveExtensionName('<inline:pichamber:visuals>')).toBe('pichamber:visuals');
|
|
7
|
+
expect(deriveExtensionName('<inline:other>')).toBe('<inline:other>');
|
|
8
|
+
});
|
|
9
|
+
|
|
5
10
|
it('derives single-file extension name without sourceInfo', () => {
|
|
6
11
|
expect(deriveExtensionName('/home/u/.pi/agent/extensions/modes.ts')).toBe('modes');
|
|
7
12
|
});
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
import { THEME_BG_COLORS, THEME_COLORS } from './extension-theme.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Pi's colours for extension surfaces: the colours Pi would draw with in a
|
|
9
|
+
* terminal that has PiChamber's palette.
|
|
10
|
+
*
|
|
11
|
+
* Extensions colour through Pi's theme names (`accent`, `border`, `dim`,
|
|
12
|
+
* ...); the marker theme (extension-theme.js) sends the names, and this
|
|
13
|
+
* module says what they are:
|
|
14
|
+
* - The `system` theme (Pi's default) is generated from the terminal's
|
|
15
|
+
* background, foreground and 16 colours, here the ones the browser draws
|
|
16
|
+
* the surface with. Tokens Pi leaves to the terminal default are omitted.
|
|
17
|
+
* - A named theme (`dark`, `light`, a custom one) uses its own colours, and
|
|
18
|
+
* its export page background when it has one.
|
|
19
|
+
* - A light/dark pair (`light/dark`) picks by the terminal's appearance.
|
|
20
|
+
* An unknown theme falls back to `system`, as Pi does.
|
|
21
|
+
*
|
|
22
|
+
* Pi exports none of this from its package root, so the theme modules are
|
|
23
|
+
* loaded from Pi's install by path. If they move or change shape, resolving
|
|
24
|
+
* throws and surfaces keep PiChamber's own colours.
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
const PI_PACKAGE = '@earendil-works/pi-coding-agent';
|
|
28
|
+
const TOKENS = new Set([...THEME_COLORS, ...THEME_BG_COLORS]);
|
|
29
|
+
const HEX = /^#[0-9a-f]{6}$/i;
|
|
30
|
+
|
|
31
|
+
const loadPiThemeModules = async () => {
|
|
32
|
+
const entry = fileURLToPath(import.meta.resolve(PI_PACKAGE));
|
|
33
|
+
const themeDir = join(dirname(entry), 'modes', 'interactive', 'theme');
|
|
34
|
+
// pi-tui is Pi's dependency, not ours: resolve it from Pi's package.
|
|
35
|
+
const tuiEntry = createRequire(join(dirname(dirname(entry)), 'package.json')).resolve('@earendil-works/pi-tui');
|
|
36
|
+
const [theme, system, tui] = await Promise.all([
|
|
37
|
+
import(pathToFileURL(join(themeDir, 'theme.js')).href),
|
|
38
|
+
import(pathToFileURL(join(themeDir, 'system-theme.js')).href),
|
|
39
|
+
import(pathToFileURL(tuiEntry).href),
|
|
40
|
+
]);
|
|
41
|
+
for (const name of ['resolveThemeSetting', 'getResolvedThemeColors', 'getThemeExportColors', 'getThemeByName', 'isLightTheme', 'getAvailableThemes']) {
|
|
42
|
+
if (typeof theme[name] !== 'function') throw new Error(`Pi's theme module has no ${name}()`);
|
|
43
|
+
}
|
|
44
|
+
for (const name of ['generateSystemThemeColors', 'terminalAppearance']) {
|
|
45
|
+
if (typeof system[name] !== 'function') throw new Error(`Pi's system theme module has no ${name}()`);
|
|
46
|
+
}
|
|
47
|
+
if (typeof system.SYSTEM_THEME_NAME !== 'string') throw new Error("Pi's system theme module has no SYSTEM_THEME_NAME");
|
|
48
|
+
for (const name of ['parseColor', 'colorToHex']) {
|
|
49
|
+
if (typeof tui[name] !== 'function') throw new Error(`pi-tui has no ${name}()`);
|
|
50
|
+
}
|
|
51
|
+
return { theme, system, toHex: (value) => tui.colorToHex(tui.parseColor(value)) };
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const toRgb = (hex) => {
|
|
55
|
+
const value = Number.parseInt(hex.slice(1), 16);
|
|
56
|
+
return { r: value >> 16, g: (value >> 8) & 255, b: value & 255 };
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** True for `{ background, foreground, palette }` of `#rrggbb` strings, 16 palette entries. */
|
|
60
|
+
export const isTerminalColors = (value) => Boolean(
|
|
61
|
+
value && typeof value === 'object'
|
|
62
|
+
&& typeof value.background === 'string' && HEX.test(value.background)
|
|
63
|
+
&& typeof value.foreground === 'string' && HEX.test(value.foreground)
|
|
64
|
+
&& Array.isArray(value.palette) && value.palette.length === 16
|
|
65
|
+
&& value.palette.every((color) => typeof color === 'string' && HEX.test(color)),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Known tokens with concrete `#rrggbb` colours. Pi's "" (terminal default)
|
|
70
|
+
* is left out, so the surface's own foreground and background apply; for a
|
|
71
|
+
* named theme `getResolvedThemeColors` fills those from Pi's process-wide
|
|
72
|
+
* terminal colours or a guess, so `terminalDefaults` names them to drop.
|
|
73
|
+
*/
|
|
74
|
+
const concreteColors = (colors, terminalDefaults = new Set()) => Object.fromEntries(
|
|
75
|
+
Object.entries(colors ?? {})
|
|
76
|
+
.filter(([token, color]) => TOKENS.has(token) && !terminalDefaults.has(token) && typeof color === 'string' && HEX.test(color))
|
|
77
|
+
.map(([token, color]) => [token, color.toLowerCase()]),
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
/** The tokens a named theme leaves to the terminal default. */
|
|
81
|
+
const terminalDefaultTokens = (themeObject) => new Set([
|
|
82
|
+
...(Array.isArray(themeObject?.defaultForegroundTokens) ? themeObject.defaultForegroundTokens : []),
|
|
83
|
+
...(Array.isArray(themeObject?.defaultBackgroundTokens) ? themeObject.defaultBackgroundTokens : []),
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
/** A theme's export colour as `#rrggbb`: Pi passes `#rgb` and `oklch()` through as written. */
|
|
87
|
+
const exportHex = (value, toHex) => {
|
|
88
|
+
if (typeof value !== 'string' || value === '') return undefined;
|
|
89
|
+
try {
|
|
90
|
+
const hex = toHex(value);
|
|
91
|
+
return typeof hex === 'string' && HEX.test(hex) ? hex.toLowerCase() : undefined;
|
|
92
|
+
} catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const createExtensionPaletteResolver = ({ loadModules = loadPiThemeModules } = {}) => {
|
|
98
|
+
let modules;
|
|
99
|
+
const load = () => {
|
|
100
|
+
modules ??= loadModules().catch((error) => {
|
|
101
|
+
modules = undefined;
|
|
102
|
+
throw error;
|
|
103
|
+
});
|
|
104
|
+
return modules;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @param {{ themeSetting?: string, terminal: { background: string, foreground: string, palette: string[] } }} input
|
|
109
|
+
* @returns {Promise<{ theme: string, appearance: 'light' | 'dark', background?: string, colors: Record<string, string> }>}
|
|
110
|
+
*/
|
|
111
|
+
return async ({ themeSetting, terminal }) => {
|
|
112
|
+
if (!isTerminalColors(terminal)) throw new TypeError('Terminal colours must be #rrggbb values with 16 palette entries.');
|
|
113
|
+
const { theme, system, toHex } = await load();
|
|
114
|
+
const background = toRgb(terminal.background);
|
|
115
|
+
const foreground = toRgb(terminal.foreground);
|
|
116
|
+
const terminalAppearance = system.terminalAppearance(background, foreground);
|
|
117
|
+
const requested = theme.resolveThemeSetting(typeof themeSetting === 'string' ? themeSetting : undefined, terminalAppearance);
|
|
118
|
+
const known = requested && requested !== system.SYSTEM_THEME_NAME && theme.getAvailableThemes().includes(requested);
|
|
119
|
+
if (known) {
|
|
120
|
+
try {
|
|
121
|
+
const colors = concreteColors(theme.getResolvedThemeColors(requested), terminalDefaultTokens(theme.getThemeByName(requested)));
|
|
122
|
+
const pageBg = exportHex(theme.getThemeExportColors(requested)?.pageBg, toHex);
|
|
123
|
+
return {
|
|
124
|
+
theme: requested,
|
|
125
|
+
appearance: theme.isLightTheme(requested) ? 'light' : 'dark',
|
|
126
|
+
...(pageBg ? { background: pageBg } : {}),
|
|
127
|
+
colors,
|
|
128
|
+
};
|
|
129
|
+
} catch {
|
|
130
|
+
// An invalid theme file: Pi falls back to the system theme too.
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
const generated = system.generateSystemThemeColors({
|
|
134
|
+
background,
|
|
135
|
+
foreground,
|
|
136
|
+
palette: terminal.palette.map(toRgb),
|
|
137
|
+
saturation: 1,
|
|
138
|
+
appearanceHint: terminalAppearance,
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
theme: system.SYSTEM_THEME_NAME,
|
|
142
|
+
appearance: generated.appearance === 'light' ? 'light' : 'dark',
|
|
143
|
+
colors: concreteColors(generated.colors),
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
|
|
5
|
+
import { describe, expect, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { createExtensionPaletteResolver, isTerminalColors } from './extension-palette.js';
|
|
8
|
+
|
|
9
|
+
const LIGHT_TERMINAL = {
|
|
10
|
+
background: '#fffcf0',
|
|
11
|
+
foreground: '#100f0f',
|
|
12
|
+
palette: [
|
|
13
|
+
'#100f0f', '#af3029', '#66800b', '#ad8301', '#205ea6', '#a02f6f', '#24837b', '#f2f0e5',
|
|
14
|
+
'#575653', '#d14d41', '#879a39', '#d0a215', '#4385be', '#ce5d97', '#3aa99f', '#fffcf0',
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
const DARK_TERMINAL = { ...LIGHT_TERMINAL, background: '#100f0f', foreground: '#cecdc3' };
|
|
18
|
+
|
|
19
|
+
// These run against the installed Pi, so a Pi update that moves its theme
|
|
20
|
+
// modules fails here rather than silently in the app.
|
|
21
|
+
describe('extension palette', () => {
|
|
22
|
+
const resolve = createExtensionPaletteResolver();
|
|
23
|
+
|
|
24
|
+
it('generates the system theme from the terminal colours by default', async () => {
|
|
25
|
+
const light = await resolve({ themeSetting: undefined, terminal: LIGHT_TERMINAL });
|
|
26
|
+
expect(light.theme).toBe('system');
|
|
27
|
+
expect(light.appearance).toBe('light');
|
|
28
|
+
expect(light.background).toBeUndefined();
|
|
29
|
+
expect(light.colors.accent).toMatch(/^#[0-9a-f]{6}$/);
|
|
30
|
+
for (const color of Object.values(light.colors)) expect(color).toMatch(/^#[0-9a-f]{6}$/);
|
|
31
|
+
|
|
32
|
+
const dark = await resolve({ themeSetting: undefined, terminal: DARK_TERMINAL });
|
|
33
|
+
expect(dark.appearance).toBe('dark');
|
|
34
|
+
expect(dark.colors.accent).not.toBe(light.colors.accent);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("uses a named theme's own colours and page background", async () => {
|
|
38
|
+
const dark = await resolve({ themeSetting: 'dark', terminal: LIGHT_TERMINAL });
|
|
39
|
+
expect(dark).toMatchObject({ theme: 'dark', appearance: 'dark', background: '#21252c' });
|
|
40
|
+
expect(dark.colors.accent).toBe('#a798d7');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('picks from a light/dark pair by the terminal appearance', async () => {
|
|
44
|
+
expect(await resolve({ themeSetting: 'light/dark', terminal: LIGHT_TERMINAL })).toMatchObject({ theme: 'light', appearance: 'light' });
|
|
45
|
+
expect(await resolve({ themeSetting: 'light/dark', terminal: DARK_TERMINAL })).toMatchObject({ theme: 'dark', appearance: 'dark' });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('falls back to the system theme for an unknown theme', async () => {
|
|
49
|
+
expect((await resolve({ themeSetting: 'no-such-theme', terminal: LIGHT_TERMINAL })).theme).toBe('system');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('rejects invalid terminal colours', async () => {
|
|
53
|
+
expect(isTerminalColors(LIGHT_TERMINAL)).toBe(true);
|
|
54
|
+
for (const terminal of [null, { ...LIGHT_TERMINAL, background: 'red' }, { ...LIGHT_TERMINAL, palette: LIGHT_TERMINAL.palette.slice(1) }]) {
|
|
55
|
+
expect(isTerminalColors(terminal)).toBe(false);
|
|
56
|
+
await expect(resolve({ terminal })).rejects.toThrow(TypeError);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("leaves a named theme's terminal-default tokens to the screen, and converts its page background", async () => {
|
|
61
|
+
// Pi's own colour conversion, from Pi's copy of pi-tui as the resolver loads it.
|
|
62
|
+
const piEntry = fileURLToPath(import.meta.resolve('@earendil-works/pi-coding-agent'));
|
|
63
|
+
const tui = await import(pathToFileURL(createRequire(join(dirname(dirname(piEntry)), 'package.json')).resolve('@earendil-works/pi-tui')).href);
|
|
64
|
+
const real = await import(pathToFileURL(join(dirname(piEntry), 'modes', 'interactive', 'theme', 'system-theme.js')).href);
|
|
65
|
+
let pageBg;
|
|
66
|
+
const themed = createExtensionPaletteResolver({
|
|
67
|
+
loadModules: async () => ({
|
|
68
|
+
system: real,
|
|
69
|
+
toHex: (value) => tui.colorToHex(tui.parseColor(value)),
|
|
70
|
+
theme: {
|
|
71
|
+
resolveThemeSetting: (setting) => setting,
|
|
72
|
+
getAvailableThemes: () => ['custom'],
|
|
73
|
+
// `text` and `selectedBg` are "" in the theme file; Pi fills them
|
|
74
|
+
// from its process-wide terminal colours or a guess.
|
|
75
|
+
getResolvedThemeColors: () => ({ accent: '#AA00BB', text: '#e5e5e7', selectedBg: '#000000' }),
|
|
76
|
+
getThemeByName: () => ({ defaultForegroundTokens: ['text'], defaultBackgroundTokens: ['selectedBg'] }),
|
|
77
|
+
getThemeExportColors: () => ({ pageBg }),
|
|
78
|
+
isLightTheme: () => false,
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
pageBg = '#123';
|
|
84
|
+
const first = await themed({ themeSetting: 'custom', terminal: LIGHT_TERMINAL });
|
|
85
|
+
expect(first).toEqual({ theme: 'custom', appearance: 'dark', background: '#112233', colors: { accent: '#aa00bb' } });
|
|
86
|
+
const second = await themed({ themeSetting: 'custom', terminal: DARK_TERMINAL });
|
|
87
|
+
expect(second.colors).toEqual({ accent: '#aa00bb' });
|
|
88
|
+
|
|
89
|
+
pageBg = 'oklch(0.3 0.02 250)';
|
|
90
|
+
expect((await themed({ themeSetting: 'custom', terminal: DARK_TERMINAL })).background).toMatch(/^#[0-9a-f]{6}$/);
|
|
91
|
+
pageBg = 'not a colour';
|
|
92
|
+
expect((await themed({ themeSetting: 'custom', terminal: DARK_TERMINAL })).background).toBeUndefined();
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('reports a failed load and tries again on the next request', async () => {
|
|
96
|
+
let attempts = 0;
|
|
97
|
+
const failing = createExtensionPaletteResolver({
|
|
98
|
+
loadModules: async () => {
|
|
99
|
+
attempts += 1;
|
|
100
|
+
throw new Error('moved');
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
await expect(failing({ terminal: LIGHT_TERMINAL })).rejects.toThrow('moved');
|
|
104
|
+
await expect(failing({ terminal: LIGHT_TERMINAL })).rejects.toThrow('moved');
|
|
105
|
+
expect(attempts).toBe(2);
|
|
106
|
+
});
|
|
107
|
+
});
|