@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,225 @@
|
|
|
1
|
+
// The marketplace: npm search over Pi packages, the curated featured list,
|
|
2
|
+
// one package's details, and latest versions for update checks. Answers are
|
|
3
|
+
// cached in memory and shared by every device on this server; identical
|
|
4
|
+
// requests in flight share one npm call. See DOCUMENTATION.md.
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
MarketplaceError,
|
|
8
|
+
PICHAMBER_KEYWORD,
|
|
9
|
+
PI_PACKAGE_KEYWORD,
|
|
10
|
+
isValidNpmName,
|
|
11
|
+
summarizeManifest,
|
|
12
|
+
summarizePackage,
|
|
13
|
+
} from './npm-registry.js';
|
|
14
|
+
|
|
15
|
+
const PAGE_SIZE = 20;
|
|
16
|
+
const MAX_QUERY_LENGTH = 100;
|
|
17
|
+
const MAX_FROM = 5_000;
|
|
18
|
+
const MAX_VERSION_NAMES = 50;
|
|
19
|
+
const SEARCH_TTL_MS = 5 * 60 * 1000;
|
|
20
|
+
const PACKAGE_TTL_MS = 10 * 60 * 1000;
|
|
21
|
+
const MAX_CACHE_ENTRIES = 300;
|
|
22
|
+
const CONCURRENCY = 6;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A small TTL cache that also shares a running load. A failed load is not
|
|
26
|
+
* kept, so the next request tries again.
|
|
27
|
+
*/
|
|
28
|
+
const createCache = ({ ttlMs, now }) => {
|
|
29
|
+
const entries = new Map();
|
|
30
|
+
return (key, load) => {
|
|
31
|
+
const hit = entries.get(key);
|
|
32
|
+
if (hit && (hit.pending || now() - hit.at < ttlMs)) {
|
|
33
|
+
entries.delete(key);
|
|
34
|
+
entries.set(key, hit);
|
|
35
|
+
return hit.value;
|
|
36
|
+
}
|
|
37
|
+
const value = load();
|
|
38
|
+
const entry = { at: now(), value, pending: true };
|
|
39
|
+
entries.set(key, entry);
|
|
40
|
+
value.then(
|
|
41
|
+
() => {
|
|
42
|
+
entry.pending = false;
|
|
43
|
+
entry.at = now();
|
|
44
|
+
},
|
|
45
|
+
() => {
|
|
46
|
+
if (entries.get(key) === entry) entries.delete(key);
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
while (entries.size > MAX_CACHE_ENTRIES) entries.delete(entries.keys().next().value);
|
|
50
|
+
return value;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Run `task` over `items` with at most `limit` at once, keeping order. */
|
|
55
|
+
const mapLimited = async (items, limit, task) => {
|
|
56
|
+
const results = new Array(items.length);
|
|
57
|
+
let next = 0;
|
|
58
|
+
const worker = async () => {
|
|
59
|
+
while (next < items.length) {
|
|
60
|
+
const index = next;
|
|
61
|
+
next += 1;
|
|
62
|
+
results[index] = await task(items[index], index);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker));
|
|
66
|
+
return results;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Search text as npm should see it: one line, no `keywords:` or other
|
|
71
|
+
* qualifiers (the keyword filter is ours to set), length capped.
|
|
72
|
+
*/
|
|
73
|
+
export const normalizeQuery = (value) => {
|
|
74
|
+
if (typeof value !== 'string') return '';
|
|
75
|
+
return value
|
|
76
|
+
// eslint-disable-next-line no-control-regex
|
|
77
|
+
.replace(/[\u0000-\u001f\u007f]+/g, ' ')
|
|
78
|
+
.replace(/\b[a-z]+:\S*/gi, ' ')
|
|
79
|
+
.replace(/\s+/g, ' ')
|
|
80
|
+
.trim()
|
|
81
|
+
.slice(0, MAX_QUERY_LENGTH);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const queryTokens = (query) => query.toLowerCase().split(/[\s,]+/).filter((token) => token.length >= 2);
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* npm ranks by the text but still returns every package with the keyword,
|
|
88
|
+
* the popular ones last. A hit counts when a word of the query is in its
|
|
89
|
+
* name, description, or keywords.
|
|
90
|
+
*/
|
|
91
|
+
const matches = (summary, tokens) => {
|
|
92
|
+
if (tokens.length === 0) return true;
|
|
93
|
+
const haystack = [summary.name, summary.description ?? '', ...summary.keywords].join(' ').toLowerCase();
|
|
94
|
+
return tokens.some((token) => haystack.includes(token));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const createMarketplaceService = ({
|
|
98
|
+
registry,
|
|
99
|
+
featuredSource,
|
|
100
|
+
bundledPackageNames = async () => [],
|
|
101
|
+
now = () => Date.now(),
|
|
102
|
+
}) => {
|
|
103
|
+
const searchCache = createCache({ ttlMs: SEARCH_TTL_MS, now });
|
|
104
|
+
const packageCache = createCache({ ttlMs: PACKAGE_TTL_MS, now });
|
|
105
|
+
const downloadsCache = createCache({ ttlMs: PACKAGE_TTL_MS, now });
|
|
106
|
+
|
|
107
|
+
/** Names never shown: the hidden list and PiChamber's own plugins. */
|
|
108
|
+
const excludedNames = async () => {
|
|
109
|
+
const [featured, bundled] = await Promise.all([featuredSource.get(), bundledPackageNames().catch(() => [])]);
|
|
110
|
+
return { featured, excluded: new Set([...featured.hidden, ...bundled]) };
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const latest = (name) => packageCache(name, () => registry.latest(name));
|
|
114
|
+
|
|
115
|
+
const weeklyDownloads = (name) => downloadsCache(name, () => registry.weeklyDownloads(name))
|
|
116
|
+
.catch(() => undefined);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* One page. `from` is npm's offset; the answer's `nextFrom` is the offset
|
|
120
|
+
* of the next page, or `null` at the end.
|
|
121
|
+
*/
|
|
122
|
+
const search = async ({ query, from = 0, pichamberOnly = false } = {}) => {
|
|
123
|
+
const text = normalizeQuery(query);
|
|
124
|
+
const offset = Number.isInteger(from) && from >= 0 && from <= MAX_FROM ? from : 0;
|
|
125
|
+
// npm filters on one keyword reliably; with two it loosens. Ask for the
|
|
126
|
+
// rarer one and check both here.
|
|
127
|
+
const keywords = pichamberOnly ? [PI_PACKAGE_KEYWORD, PICHAMBER_KEYWORD] : [PI_PACKAGE_KEYWORD];
|
|
128
|
+
const key = JSON.stringify([text, offset, pichamberOnly]);
|
|
129
|
+
const page = await searchCache(key, () => registry.searchRaw({
|
|
130
|
+
text,
|
|
131
|
+
keywords: [pichamberOnly ? PICHAMBER_KEYWORD : PI_PACKAGE_KEYWORD],
|
|
132
|
+
from: offset,
|
|
133
|
+
size: PAGE_SIZE,
|
|
134
|
+
}));
|
|
135
|
+
const { excluded } = await excludedNames();
|
|
136
|
+
const tokens = queryTokens(text);
|
|
137
|
+
let unrelated = 0;
|
|
138
|
+
const packages = [];
|
|
139
|
+
for (const object of page.objects) {
|
|
140
|
+
const summary = summarizePackage(object?.package, { weeklyDownloads: object?.downloads?.weekly });
|
|
141
|
+
if (!summary) continue;
|
|
142
|
+
// Pi's gallery needs `pi-package`; the filter needs ours as well.
|
|
143
|
+
if (!keywords.every((keyword) => summary.keywords.includes(keyword))) continue;
|
|
144
|
+
if (!matches(summary, tokens)) {
|
|
145
|
+
unrelated += 1;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
if (excluded.has(summary.name)) continue;
|
|
149
|
+
packages.push(summary);
|
|
150
|
+
}
|
|
151
|
+
const consumed = offset + page.objects.length;
|
|
152
|
+
// Past the last hit npm pads with unrelated packages: stop there.
|
|
153
|
+
const more = page.objects.length === PAGE_SIZE && unrelated === 0 && consumed < MAX_FROM
|
|
154
|
+
&& (page.total === undefined || consumed < page.total);
|
|
155
|
+
return {
|
|
156
|
+
packages,
|
|
157
|
+
...(tokens.length === 0 && page.total !== undefined ? { total: page.total } : {}),
|
|
158
|
+
nextFrom: more ? consumed : null,
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The featured packages in their listed order. One that npm cannot answer
|
|
164
|
+
* for is still listed, marked `unavailable`, with its note.
|
|
165
|
+
*/
|
|
166
|
+
const featured = async () => {
|
|
167
|
+
const { featured: list, excluded } = await excludedNames();
|
|
168
|
+
const shown = list.featured.filter((entry) => !excluded.has(entry.name));
|
|
169
|
+
const packages = await mapLimited(shown, CONCURRENCY, async (entry) => {
|
|
170
|
+
try {
|
|
171
|
+
const [manifest, downloads] = await Promise.all([latest(entry.name), weeklyDownloads(entry.name)]);
|
|
172
|
+
const summary = summarizeManifest(manifest);
|
|
173
|
+
if (!summary) throw new MarketplaceError('MARKETPLACE_UNAVAILABLE');
|
|
174
|
+
return {
|
|
175
|
+
...summary,
|
|
176
|
+
...(downloads !== undefined ? { weeklyDownloads: downloads } : {}),
|
|
177
|
+
...(entry.note ? { note: entry.note } : {}),
|
|
178
|
+
};
|
|
179
|
+
} catch {
|
|
180
|
+
return {
|
|
181
|
+
name: entry.name,
|
|
182
|
+
keywords: [],
|
|
183
|
+
pichamberKeyword: false,
|
|
184
|
+
links: { npm: `https://www.npmjs.com/package/${entry.name}` },
|
|
185
|
+
...(entry.note ? { note: entry.note } : {}),
|
|
186
|
+
unavailable: true,
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
return { packages, updated: list.updated, source: list.source };
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/** One package's page. Hidden and bundled names answer not found. */
|
|
194
|
+
const packageDetail = async (name) => {
|
|
195
|
+
if (!isValidNpmName(name)) throw new MarketplaceError('INVALID_MARKETPLACE_REQUEST');
|
|
196
|
+
const { excluded } = await excludedNames();
|
|
197
|
+
if (excluded.has(name)) throw new MarketplaceError('MARKETPLACE_PACKAGE_NOT_FOUND');
|
|
198
|
+
const [manifest, downloads] = await Promise.all([latest(name), weeklyDownloads(name)]);
|
|
199
|
+
const summary = summarizeManifest(manifest);
|
|
200
|
+
if (!summary) throw new MarketplaceError('MARKETPLACE_UNAVAILABLE');
|
|
201
|
+
return { ...summary, ...(downloads !== undefined ? { weeklyDownloads: downloads } : {}) };
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Latest versions for update checks. A name npm cannot answer for is left
|
|
206
|
+
* out, which means unknown, not "no update".
|
|
207
|
+
*/
|
|
208
|
+
const versions = async (names) => {
|
|
209
|
+
if (!Array.isArray(names) || names.length > MAX_VERSION_NAMES || !names.every(isValidNpmName)) {
|
|
210
|
+
throw new MarketplaceError('INVALID_MARKETPLACE_REQUEST');
|
|
211
|
+
}
|
|
212
|
+
const unique = [...new Set(names)];
|
|
213
|
+
const found = await mapLimited(unique, CONCURRENCY, async (name) => {
|
|
214
|
+
try {
|
|
215
|
+
const version = summarizeManifest(await latest(name))?.version;
|
|
216
|
+
return version ? [name, version] : null;
|
|
217
|
+
} catch {
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
return { versions: Object.fromEntries(found.filter(Boolean)) };
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
return { search, featured, packageDetail, versions };
|
|
225
|
+
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { MarketplaceError } from './npm-registry.js';
|
|
4
|
+
import { createMarketplaceService, normalizeQuery } from './service.js';
|
|
5
|
+
|
|
6
|
+
const pkg = (name, overrides = {}) => ({
|
|
7
|
+
name,
|
|
8
|
+
version: '1.0.0',
|
|
9
|
+
description: `The ${name} package`,
|
|
10
|
+
keywords: ['pi-package'],
|
|
11
|
+
...overrides,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const hit = (name, overrides = {}, downloads) => ({
|
|
15
|
+
package: pkg(name, overrides),
|
|
16
|
+
...(downloads === undefined ? {} : { downloads: { weekly: downloads } }),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const setup = ({ objects = [], total = 0, featured = { updated: '2026-01-01', featured: [], hidden: [] }, bundled = [] } = {}) => {
|
|
20
|
+
const registry = {
|
|
21
|
+
searchRaw: vi.fn(async () => ({ total, objects })),
|
|
22
|
+
latest: vi.fn(async (name) => ({ name, version: '1.0.0', keywords: ['pi-package'] })),
|
|
23
|
+
weeklyDownloads: vi.fn(async () => undefined),
|
|
24
|
+
};
|
|
25
|
+
const featuredSource = { get: vi.fn(async () => ({ ...featured, source: 'builtin' })) };
|
|
26
|
+
const service = createMarketplaceService({
|
|
27
|
+
registry,
|
|
28
|
+
featuredSource,
|
|
29
|
+
bundledPackageNames: async () => bundled,
|
|
30
|
+
});
|
|
31
|
+
return { registry, featuredSource, service };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
describe('normalizeQuery', () => {
|
|
35
|
+
it('strips keyword qualifiers and control chars and caps at 100 chars', () => {
|
|
36
|
+
expect(normalizeQuery('keywords:pi-package lens')).toBe('lens');
|
|
37
|
+
expect(normalizeQuery('foo:bar hello')).toBe('hello');
|
|
38
|
+
expect(normalizeQuery('a\x00b')).toBe('a b');
|
|
39
|
+
expect(normalizeQuery('x'.repeat(200)).length).toBe(100);
|
|
40
|
+
expect(normalizeQuery(undefined)).toBe('');
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('search', () => {
|
|
45
|
+
it('drops results without the pi-package keyword', async () => {
|
|
46
|
+
const { service } = setup({ objects: [hit('pi-good'), hit('plain', { keywords: ['other'] })], total: 2 });
|
|
47
|
+
const result = await service.search({ query: '', from: 0 });
|
|
48
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-good']);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('drops hidden and bundled names', async () => {
|
|
52
|
+
const { service } = setup({
|
|
53
|
+
objects: [hit('pi-good'), hit('evil-pkg'), hit('bundled-pkg')],
|
|
54
|
+
total: 3,
|
|
55
|
+
featured: { updated: '2026-01-01', featured: [], hidden: ['evil-pkg'] },
|
|
56
|
+
bundled: ['bundled-pkg'],
|
|
57
|
+
});
|
|
58
|
+
const result = await service.search({ query: '', from: 0 });
|
|
59
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-good']);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('filters unrelated padding and clears nextFrom when any appears', async () => {
|
|
63
|
+
const objects = Array.from({ length: 20 }, (_, index) => (
|
|
64
|
+
index === 19
|
|
65
|
+
? hit('unrelated-zzz', { description: 'zzz qqq www' })
|
|
66
|
+
: hit(`pi-lens-${index}`, { description: 'lens helper' })
|
|
67
|
+
));
|
|
68
|
+
const { service } = setup({ objects, total: 100 });
|
|
69
|
+
const result = await service.search({ query: 'lens', from: 0 });
|
|
70
|
+
expect(result.packages).toHaveLength(19);
|
|
71
|
+
expect(result.nextFrom).toBeNull();
|
|
72
|
+
expect(result).not.toHaveProperty('total');
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('reports total only without a query and nextFrom for a full relevant page', async () => {
|
|
76
|
+
const objects = Array.from({ length: 20 }, (_, index) => hit(`pi-pkg-${index}`));
|
|
77
|
+
const { service } = setup({ objects, total: 100 });
|
|
78
|
+
const result = await service.search({ query: '', from: 0 });
|
|
79
|
+
expect(result.total).toBe(100);
|
|
80
|
+
expect(result.nextFrom).toBe(20);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('asks npm for pichamber-plugin only and requires both keywords', async () => {
|
|
84
|
+
const { registry, service } = setup({
|
|
85
|
+
objects: [
|
|
86
|
+
hit('pi-both', { keywords: ['pi-package', 'pichamber-plugin'] }),
|
|
87
|
+
hit('pi-narrow', { keywords: ['pichamber-plugin'] }),
|
|
88
|
+
],
|
|
89
|
+
total: 2,
|
|
90
|
+
});
|
|
91
|
+
const result = await service.search({ query: '', from: 0, pichamberOnly: true });
|
|
92
|
+
expect(registry.searchRaw).toHaveBeenCalledWith(
|
|
93
|
+
expect.objectContaining({ keywords: ['pichamber-plugin'] }),
|
|
94
|
+
);
|
|
95
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-both']);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('caches results but never caches a failure', async () => {
|
|
99
|
+
const { registry, service } = setup({ objects: [hit('pi-good')], total: 1 });
|
|
100
|
+
await service.search({ query: '', from: 0 });
|
|
101
|
+
await service.search({ query: '', from: 0 });
|
|
102
|
+
expect(registry.searchRaw).toHaveBeenCalledTimes(1);
|
|
103
|
+
|
|
104
|
+
registry.searchRaw.mockRejectedValueOnce(new MarketplaceError('MARKETPLACE_UNAVAILABLE'));
|
|
105
|
+
await expect(service.search({ query: 'retry', from: 0 })).rejects.toMatchObject({ code: 'MARKETPLACE_UNAVAILABLE' });
|
|
106
|
+
const calls = registry.searchRaw.mock.calls.length;
|
|
107
|
+
await service.search({ query: 'retry', from: 0 });
|
|
108
|
+
expect(registry.searchRaw.mock.calls.length).toBe(calls + 1);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('featured', () => {
|
|
113
|
+
it('keeps listed order and marks failures unavailable with their note', async () => {
|
|
114
|
+
const registry = {
|
|
115
|
+
searchRaw: vi.fn(),
|
|
116
|
+
latest: vi.fn(async (name) => {
|
|
117
|
+
if (name === 'missing-pkg') throw new MarketplaceError('MARKETPLACE_PACKAGE_NOT_FOUND');
|
|
118
|
+
return { name, version: '2.0.0', keywords: ['pi-package'], pi: { extensions: ['./e.js'] } };
|
|
119
|
+
}),
|
|
120
|
+
weeklyDownloads: vi.fn(async () => undefined),
|
|
121
|
+
};
|
|
122
|
+
const featuredSource = {
|
|
123
|
+
get: async () => ({
|
|
124
|
+
updated: '2026-01-01',
|
|
125
|
+
featured: [{ name: 'pi-first', note: 'First' }, { name: 'missing-pkg', note: 'Gone' }],
|
|
126
|
+
hidden: [],
|
|
127
|
+
source: 'builtin',
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
const service = createMarketplaceService({ registry, featuredSource, bundledPackageNames: async () => [] });
|
|
131
|
+
const result = await service.featured();
|
|
132
|
+
expect(result.packages.map((entry) => entry.name)).toEqual(['pi-first', 'missing-pkg']);
|
|
133
|
+
expect(result.packages[0]).toMatchObject({ version: '2.0.0', note: 'First' });
|
|
134
|
+
expect(result.packages[0]).not.toHaveProperty('unavailable');
|
|
135
|
+
expect(result.packages[1]).toMatchObject({ note: 'Gone', unavailable: true });
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe('packageDetail', () => {
|
|
140
|
+
it('answers not found for hidden and bundled names', async () => {
|
|
141
|
+
const { service } = setup({
|
|
142
|
+
featured: { updated: '2026-01-01', featured: [], hidden: ['evil-pkg'] },
|
|
143
|
+
bundled: ['bundled-pkg'],
|
|
144
|
+
});
|
|
145
|
+
await expect(service.packageDetail('evil-pkg')).rejects.toMatchObject({ code: 'MARKETPLACE_PACKAGE_NOT_FOUND' });
|
|
146
|
+
await expect(service.packageDetail('bundled-pkg')).rejects.toMatchObject({ code: 'MARKETPLACE_PACKAGE_NOT_FOUND' });
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('versions', () => {
|
|
151
|
+
it('rejects more than 50 names or invalid names', async () => {
|
|
152
|
+
const { service } = setup();
|
|
153
|
+
await expect(service.versions(Array.from({ length: 51 }, (_, index) => `pi-pkg-${index}`)))
|
|
154
|
+
.rejects.toMatchObject({ code: 'INVALID_MARKETPLACE_REQUEST' });
|
|
155
|
+
await expect(service.versions(['Bad Name'])).rejects.toMatchObject({ code: 'INVALID_MARKETPLACE_REQUEST' });
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('leaves out names npm cannot answer for', async () => {
|
|
159
|
+
const registry = {
|
|
160
|
+
searchRaw: vi.fn(),
|
|
161
|
+
latest: vi.fn(async (name) => {
|
|
162
|
+
if (name === 'pi-gone') throw new MarketplaceError('MARKETPLACE_PACKAGE_NOT_FOUND');
|
|
163
|
+
return { name, version: '3.1.0', keywords: ['pi-package'] };
|
|
164
|
+
}),
|
|
165
|
+
weeklyDownloads: vi.fn(),
|
|
166
|
+
};
|
|
167
|
+
const service = createMarketplaceService({
|
|
168
|
+
registry,
|
|
169
|
+
featuredSource: { get: async () => ({ updated: null, featured: [], hidden: [], source: 'builtin' }) },
|
|
170
|
+
bundledPackageNames: async () => [],
|
|
171
|
+
});
|
|
172
|
+
await expect(service.versions(['pi-ok', 'pi-gone'])).resolves.toEqual({ versions: { 'pi-ok': '3.1.0' } });
|
|
173
|
+
});
|
|
174
|
+
});
|
|
@@ -7,8 +7,12 @@ model OpenCode questions, permissions, subagents, or tool completion, and it
|
|
|
7
7
|
sends nothing off the machine: there is no push delivery, no registered
|
|
8
8
|
routes, and no hosted relay.
|
|
9
9
|
|
|
10
|
-
`pi-notification-watcher.js` maintains one server-owned subscription
|
|
11
|
-
session daemon
|
|
10
|
+
`pi-notification-watcher.js` maintains one server-owned subscription per live
|
|
11
|
+
Pi session daemon in the daemon pool (`../pi/session-daemon/daemon-pool.js`).
|
|
12
|
+
It subscribes to daemons registered later, closes the subscription of a
|
|
13
|
+
daemon that is removed, and starts over with a fresh cursor when a key's
|
|
14
|
+
runtime is replaced. One tracker sees every daemon's events; session ids are
|
|
15
|
+
unique across daemons because a session is leased to one daemon at a time. A live `busy` or `retry` lifecycle, or an assistant start,
|
|
12
16
|
opens a turn. The first terminal `idle` emits a completion notification and
|
|
13
17
|
the first `session.error` or terminal `error` emits an error notification.
|
|
14
18
|
Duplicate terminal boundaries do nothing. Bootstrap snapshots seed activity but
|
|
@@ -46,5 +50,7 @@ in place and no migration runs.
|
|
|
46
50
|
|
|
47
51
|
## Failure behavior
|
|
48
52
|
|
|
49
|
-
The watcher reconnects
|
|
50
|
-
replayed terminal events remain deduplicated by the
|
|
53
|
+
The watcher reconnects each daemon with that daemon's own sequence and
|
|
54
|
+
stream epoch, so replayed terminal events remain deduplicated by the
|
|
55
|
+
active-turn state. A daemon that fails retries alone; the others keep
|
|
56
|
+
delivering.
|
|
@@ -21,6 +21,9 @@ export const createPiNotificationTracker = ({ emit }) => {
|
|
|
21
21
|
|
|
22
22
|
const accept = (event) => {
|
|
23
23
|
if (!event || typeof event.sessionId !== 'string') return;
|
|
24
|
+
// A draft session (warmed for a new-session draft, nothing sent yet)
|
|
25
|
+
// only runs its extensions' control commands; that is not work to report.
|
|
26
|
+
if (event.draft === true) return;
|
|
24
27
|
if (event.name === 'session.snapshot') {
|
|
25
28
|
const snapshot = event.payload?.snapshot;
|
|
26
29
|
if (typeof snapshot?.title === 'string' && snapshot.title.trim()) {
|
|
@@ -66,18 +69,80 @@ export const createPiNotificationTracker = ({ emit }) => {
|
|
|
66
69
|
return { accept };
|
|
67
70
|
};
|
|
68
71
|
|
|
72
|
+
// One daemon's subscription: its own replay cursor (sequence and stream
|
|
73
|
+
// epoch are per daemon), retry timer, and close. A subscription that
|
|
74
|
+
// resolves after `close()` is closed at once.
|
|
75
|
+
const createDaemonConnection = ({ runtime, retryMs, onEvent }) => {
|
|
76
|
+
let closed = false;
|
|
77
|
+
let closeSubscription = null;
|
|
78
|
+
let retryTimer = null;
|
|
79
|
+
let fromSequence;
|
|
80
|
+
let streamEpoch;
|
|
81
|
+
|
|
82
|
+
const scheduleReconnect = () => {
|
|
83
|
+
if (closed || retryTimer) return;
|
|
84
|
+
closeSubscription?.();
|
|
85
|
+
closeSubscription = null;
|
|
86
|
+
retryTimer = setTimeout(() => {
|
|
87
|
+
retryTimer = null;
|
|
88
|
+
void connect();
|
|
89
|
+
}, retryMs);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const connect = async () => {
|
|
93
|
+
if (closed) return;
|
|
94
|
+
try {
|
|
95
|
+
closeSubscription?.();
|
|
96
|
+
closeSubscription = null;
|
|
97
|
+
const close = await runtime.subscribe({
|
|
98
|
+
...(Number.isSafeInteger(fromSequence) && streamEpoch ? { fromSequence, streamEpoch } : {}),
|
|
99
|
+
onEvent: (event) => {
|
|
100
|
+
if (typeof event.streamEpoch === 'string') streamEpoch = event.streamEpoch;
|
|
101
|
+
if (Number.isSafeInteger(event.sequence)) fromSequence = event.sequence;
|
|
102
|
+
onEvent(event);
|
|
103
|
+
},
|
|
104
|
+
onError: scheduleReconnect,
|
|
105
|
+
});
|
|
106
|
+
if (closed) close?.();
|
|
107
|
+
else closeSubscription = close;
|
|
108
|
+
} catch {
|
|
109
|
+
scheduleReconnect();
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
runtime,
|
|
115
|
+
connect,
|
|
116
|
+
close: () => {
|
|
117
|
+
closed = true;
|
|
118
|
+
if (retryTimer) clearTimeout(retryTimer);
|
|
119
|
+
retryTimer = null;
|
|
120
|
+
closeSubscription?.();
|
|
121
|
+
closeSubscription = null;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Watches every live session daemon in `daemonPool` (or the single
|
|
128
|
+
* `supervisor`) and follows daemons as they are registered and removed.
|
|
129
|
+
* One daemon failing only retries that daemon.
|
|
130
|
+
*/
|
|
69
131
|
export const createPiNotificationWatcher = ({
|
|
70
132
|
supervisor,
|
|
133
|
+
daemonPool = {
|
|
134
|
+
live: () => (supervisor ? [{ key: 'main', runtime: supervisor }] : []),
|
|
135
|
+
onChange: () => () => {},
|
|
136
|
+
},
|
|
71
137
|
uiSettingsStore,
|
|
72
138
|
notify,
|
|
73
139
|
retryMs = 1_000,
|
|
74
140
|
notifyTimeoutMs = 15_000,
|
|
75
141
|
}) => {
|
|
76
142
|
let stopped = false;
|
|
77
|
-
let
|
|
78
|
-
let
|
|
79
|
-
|
|
80
|
-
let streamEpoch;
|
|
143
|
+
let started = false;
|
|
144
|
+
let unsubscribePool = null;
|
|
145
|
+
const connections = new Map();
|
|
81
146
|
let notifyChain = Promise.resolve();
|
|
82
147
|
|
|
83
148
|
const tracker = createPiNotificationTracker({
|
|
@@ -113,42 +178,39 @@ export const createPiNotificationWatcher = ({
|
|
|
113
178
|
},
|
|
114
179
|
});
|
|
115
180
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
closeSubscription = null;
|
|
120
|
-
retryTimer = setTimeout(() => {
|
|
121
|
-
retryTimer = null;
|
|
122
|
-
void connect();
|
|
123
|
-
}, retryMs);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const connect = async () => {
|
|
181
|
+
// Bring subscriptions in line with the pool: connect new daemons, close
|
|
182
|
+
// removed ones, and start over (fresh cursor) for a replaced runtime.
|
|
183
|
+
const sync = async () => {
|
|
127
184
|
if (stopped) return;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (typeof event.streamEpoch === 'string') streamEpoch = event.streamEpoch;
|
|
134
|
-
if (Number.isSafeInteger(event.sequence)) fromSequence = event.sequence;
|
|
135
|
-
tracker.accept(event);
|
|
136
|
-
},
|
|
137
|
-
onError: scheduleReconnect,
|
|
138
|
-
});
|
|
139
|
-
} catch {
|
|
140
|
-
scheduleReconnect();
|
|
185
|
+
const live = new Map(daemonPool.live().map(({ key, runtime }) => [key, runtime]));
|
|
186
|
+
for (const [key, connection] of connections) {
|
|
187
|
+
if (live.get(key) === connection.runtime) continue;
|
|
188
|
+
connection.close();
|
|
189
|
+
connections.delete(key);
|
|
141
190
|
}
|
|
191
|
+
const opening = [];
|
|
192
|
+
for (const [key, runtime] of live) {
|
|
193
|
+
if (connections.has(key)) continue;
|
|
194
|
+
const connection = createDaemonConnection({ runtime, retryMs, onEvent: tracker.accept });
|
|
195
|
+
connections.set(key, connection);
|
|
196
|
+
opening.push(connection.connect());
|
|
197
|
+
}
|
|
198
|
+
await Promise.all(opening);
|
|
142
199
|
};
|
|
143
200
|
|
|
144
201
|
return {
|
|
145
|
-
start:
|
|
202
|
+
start: async () => {
|
|
203
|
+
if (stopped || started) return;
|
|
204
|
+
started = true;
|
|
205
|
+
unsubscribePool = daemonPool.onChange(() => { void sync(); });
|
|
206
|
+
await sync();
|
|
207
|
+
},
|
|
146
208
|
stop: async () => {
|
|
147
209
|
stopped = true;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
210
|
+
unsubscribePool?.();
|
|
211
|
+
unsubscribePool = null;
|
|
212
|
+
for (const connection of connections.values()) connection.close();
|
|
213
|
+
connections.clear();
|
|
152
214
|
await notifyChain;
|
|
153
215
|
},
|
|
154
216
|
};
|