@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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest';
|
|
2
2
|
|
|
3
3
|
import { createPiNotificationTracker, createPiNotificationWatcher } from './pi-notification-watcher.js';
|
|
4
|
+
import { createPiDaemonPool } from '../pi/session-daemon/daemon-pool.js';
|
|
4
5
|
|
|
5
6
|
const event = (name, sequence, payload = {}, sessionId = 'session-1') => ({
|
|
6
7
|
protocolVersion: 1,
|
|
@@ -29,6 +30,16 @@ describe('Pi notification tracker', () => {
|
|
|
29
30
|
})]);
|
|
30
31
|
});
|
|
31
32
|
|
|
33
|
+
it('ignores a draft session, whose only work is its extensions\' control commands', () => {
|
|
34
|
+
const notifications = [];
|
|
35
|
+
const tracker = createPiNotificationTracker({ emit: (payload) => notifications.push(payload) });
|
|
36
|
+
|
|
37
|
+
tracker.accept({ ...event('session.lifecycle', 1, { state: 'busy' }), draft: true });
|
|
38
|
+
tracker.accept({ ...event('session.lifecycle', 2, { state: 'idle' }), draft: true });
|
|
39
|
+
|
|
40
|
+
expect(notifications).toEqual([]);
|
|
41
|
+
});
|
|
42
|
+
|
|
32
43
|
it('collapses message and lifecycle error boundaries into one notification', () => {
|
|
33
44
|
const notifications = [];
|
|
34
45
|
const tracker = createPiNotificationTracker({ emit: (payload) => notifications.push(payload) });
|
|
@@ -167,4 +178,82 @@ describe('Pi notification tracker', () => {
|
|
|
167
178
|
warn.mockRestore();
|
|
168
179
|
}
|
|
169
180
|
});
|
|
181
|
+
|
|
182
|
+
it('watches every live daemon in the pool and follows daemons that come and go', async () => {
|
|
183
|
+
const seen = [];
|
|
184
|
+
const subscriptions = new Map();
|
|
185
|
+
const fakeDaemon = (name, { fail = false } = {}) => ({
|
|
186
|
+
request: async () => ({}),
|
|
187
|
+
subscribe: async (options) => {
|
|
188
|
+
if (fail) throw new Error('unavailable');
|
|
189
|
+
const entry = { options, closed: false };
|
|
190
|
+
subscriptions.set(name, [...(subscriptions.get(name) ?? []), entry]);
|
|
191
|
+
return () => { entry.closed = true; };
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
const main = fakeDaemon('main');
|
|
195
|
+
const broken = fakeDaemon('broken', { fail: true });
|
|
196
|
+
const sandbox = fakeDaemon('sandbox');
|
|
197
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
198
|
+
pool.register('project-broken', { runtime: broken, directories: ['/broken'] });
|
|
199
|
+
const watcher = createPiNotificationWatcher({
|
|
200
|
+
daemonPool: pool,
|
|
201
|
+
uiSettingsStore: { read: async () => ({ nativeNotificationsEnabled: true }) },
|
|
202
|
+
notify: async (payload) => { seen.push(payload.sessionId); },
|
|
203
|
+
retryMs: 60_000,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
await watcher.start();
|
|
207
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
208
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
209
|
+
|
|
210
|
+
const emit = (name, sessionId, sequence, state) => subscriptions.get(name).at(-1).options
|
|
211
|
+
.onEvent(event('session.lifecycle', sequence, { state }, sessionId));
|
|
212
|
+
emit('main', 'main-session', 1, 'busy');
|
|
213
|
+
emit('sandbox', 'box-session', 1, 'busy');
|
|
214
|
+
emit('sandbox', 'box-session', 2, 'idle');
|
|
215
|
+
emit('main', 'main-session', 2, 'idle');
|
|
216
|
+
|
|
217
|
+
// Each daemon resumes from its own cursor.
|
|
218
|
+
subscriptions.get('sandbox').at(-1).options.onError(new Error('gone'));
|
|
219
|
+
pool.unregister('project-a');
|
|
220
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
221
|
+
expect(subscriptions.get('sandbox').at(-1).closed).toBe(true);
|
|
222
|
+
|
|
223
|
+
await watcher.stop();
|
|
224
|
+
expect(subscriptions.get('main').at(-1).closed).toBe(true);
|
|
225
|
+
expect(seen).toEqual(['box-session', 'main-session']);
|
|
226
|
+
expect(subscriptions.get('main')).toHaveLength(1);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('reconnects each daemon with its own cursor', async () => {
|
|
230
|
+
const subscriptions = { main: [], sandbox: [] };
|
|
231
|
+
const fakeDaemon = (name) => ({
|
|
232
|
+
request: async () => ({}),
|
|
233
|
+
subscribe: async (options) => {
|
|
234
|
+
subscriptions[name].push(options);
|
|
235
|
+
return () => {};
|
|
236
|
+
},
|
|
237
|
+
});
|
|
238
|
+
const main = fakeDaemon('main');
|
|
239
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
240
|
+
pool.register('project-a', { runtime: fakeDaemon('sandbox'), directories: ['/work/a'] });
|
|
241
|
+
const watcher = createPiNotificationWatcher({
|
|
242
|
+
daemonPool: pool,
|
|
243
|
+
uiSettingsStore: { read: async () => ({}) },
|
|
244
|
+
notify: async () => undefined,
|
|
245
|
+
retryMs: 1,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
await watcher.start();
|
|
249
|
+
subscriptions.main[0].onEvent({ ...event('session.lifecycle', 30, { state: 'busy' }), streamEpoch: 'epoch-main' });
|
|
250
|
+
subscriptions.sandbox[0].onEvent({ ...event('session.lifecycle', 4, { state: 'busy' }), streamEpoch: 'epoch-box' });
|
|
251
|
+
subscriptions.sandbox[0].onError(new Error('disconnected'));
|
|
252
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
253
|
+
await watcher.stop();
|
|
254
|
+
|
|
255
|
+
expect(subscriptions.main).toHaveLength(1);
|
|
256
|
+
expect(subscriptions.sandbox).toHaveLength(2);
|
|
257
|
+
expect(subscriptions.sandbox[1]).toMatchObject({ fromSequence: 4, streamEpoch: 'epoch-box' });
|
|
258
|
+
});
|
|
170
259
|
});
|
|
@@ -9,10 +9,11 @@ When a tool on the server machine wants to show the person a URL (an extension s
|
|
|
9
9
|
1. `daemon-process.js` calls `ensureOpenUrlBrowser` (`browser-env.js`) before any session starts. It writes an owner-only launcher script and points `$BROWSER` at it, keeping the previous value in `PICHAMBER_ORIGINAL_BROWSER` and the intake path in `PICHAMBER_OPEN_URL_SOCKET`. Every bash command and in-process extension inherits that environment. A watchdog (`watchOpenUrlBrowser`) re-checks the launcher every minute for the life of the daemon.
|
|
10
10
|
2. The launcher runs `browser-handler.mjs` with the URL arguments. Each http(s) URL is posted to the intake together with `PI_SESSION_ID` when the caller is a bash command.
|
|
11
11
|
3. `intake.js`, bound by the PiChamber server (`index.js`) on `<runtimeDir>/open-url.sock`, asks the daemon to publish (`openUrl.publish`). The daemon attributes the request (`session-daemon/open-request.js`) and publishes `session.openUrl` on that session's event stream.
|
|
12
|
+
A sandboxed project's daemon (`../pi/sandbox/project-sandbox-manager.js`) gets its own intake on `<its runtime folder>/open-url.sock`, started before the daemon and stopped with it, which publishes through that daemon's `openUrl.publish`. A request from a sandboxed bash command never reaches the main daemon. Its published event reaches devices through the merged `/api/pi/events` stream, like any event from that daemon.
|
|
12
13
|
4. Devices ask the person whether to open it (`packages/ui/src/components/chat/OpenRequestAlerts.tsx`). Nothing opens without a click.
|
|
13
14
|
5. The intake answers `{ delivered }`. `delivered` is true only when a device holds a live `/api/pi/events` stream and the daemon published. Otherwise the handler falls back to the original `$BROWSER` list, then `open` (macOS) or `xdg-open`, with `$BROWSER` restored in that child's environment so it cannot loop back.
|
|
14
15
|
|
|
15
|
-
Extensions in PiChamber can call `
|
|
16
|
+
Extensions in PiChamber can call `pichamber.ui.openUrl(ctx, url)` (`globalThis.pichamber`, absent in plain Pi). The older `ctx.ui.openUrl(url)` is removed. The call runs the same handler in-process with the exact session id and resolves whether the URL was shown or opened.
|
|
16
17
|
|
|
17
18
|
## Invariants
|
|
18
19
|
|
|
@@ -61,6 +61,60 @@ export const validateExtensionFormValues = (fields, values) => {
|
|
|
61
61
|
return true;
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
+
// ---------------------------------------------------------------- choose()
|
|
65
|
+
//
|
|
66
|
+
// `pichamber.ui.choose(ctx, title, choices, opts)`: one question, a short list of
|
|
67
|
+
// choices that each have an id, a label and an optional description, and an
|
|
68
|
+
// optional free-text note. A tool can name its own call (`toolCallId`), so a
|
|
69
|
+
// plugin's chat component can draw the question beside what the call shows.
|
|
70
|
+
|
|
71
|
+
const MAX_EXTENSION_CHOICES = 12;
|
|
72
|
+
export const MAX_EXTENSION_CHOICE_ID_CHARS = 64;
|
|
73
|
+
export const MAX_EXTENSION_CHOICE_NOTE_CHARS = 2_000;
|
|
74
|
+
const MAX_EXTENSION_TOOL_CALL_ID_CHARS = 256;
|
|
75
|
+
|
|
76
|
+
/** Choices with a usable id and label, first of each id, at most 12. */
|
|
77
|
+
const sanitizeExtensionChoices = (choices) => {
|
|
78
|
+
if (!Array.isArray(choices)) return [];
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
const out = [];
|
|
81
|
+
for (const choice of choices) {
|
|
82
|
+
if (out.length >= MAX_EXTENSION_CHOICES) break;
|
|
83
|
+
if (!choice || typeof choice !== 'object') continue;
|
|
84
|
+
const id = typeof choice.id === 'string' ? choice.id : '';
|
|
85
|
+
const label = typeof choice.label === 'string' ? choice.label.trim().slice(0, 256) : '';
|
|
86
|
+
if (!id || id.length > MAX_EXTENSION_CHOICE_ID_CHARS || !label || seen.has(id)) continue;
|
|
87
|
+
seen.add(id);
|
|
88
|
+
const description = typeof choice.description === 'string' ? choice.description.trim().slice(0, 512) : '';
|
|
89
|
+
out.push({ id, label, ...(description ? { description } : {}) });
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/** The fields a `choose` dialog adds to the dialog payload, cleaned. */
|
|
95
|
+
export const projectExtensionChooseFields = (payload) => ({
|
|
96
|
+
choices: sanitizeExtensionChoices(payload?.choices),
|
|
97
|
+
...(payload?.allowNote === true ? { allowNote: true } : {}),
|
|
98
|
+
...(typeof payload?.toolCallId === 'string' && payload.toolCallId.length > 0
|
|
99
|
+
&& payload.toolCallId.length <= MAX_EXTENSION_TOOL_CALL_ID_CHARS
|
|
100
|
+
? { toolCallId: payload.toolCallId }
|
|
101
|
+
: {}),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Check a `choose` answer against the dialog that was sent. Answers
|
|
106
|
+
* `{ id, note? }`, or `null` when the id is not one of its choices or a note
|
|
107
|
+
* came for a dialog that takes none.
|
|
108
|
+
*/
|
|
109
|
+
export const validateExtensionChoiceAnswer = (dialog, value, note) => {
|
|
110
|
+
if (typeof value !== 'string' || !Array.isArray(dialog?.choices)) return null;
|
|
111
|
+
if (!dialog.choices.some((choice) => choice.id === value)) return null;
|
|
112
|
+
if (note === undefined) return { id: value };
|
|
113
|
+
if (typeof note !== 'string' || note.length > MAX_EXTENSION_CHOICE_NOTE_CHARS || dialog.allowNote !== true) return null;
|
|
114
|
+
const trimmed = note.trim();
|
|
115
|
+
return { id: value, ...(trimmed ? { note: trimmed } : {}) };
|
|
116
|
+
};
|
|
117
|
+
|
|
64
118
|
// ---------------------------------------------------------------- custom()
|
|
65
119
|
//
|
|
66
120
|
// Public shapes for `ctx.ui.custom()` surfaces (extension-custom-host.js).
|
|
@@ -168,21 +168,20 @@ export default function (pi: ExtensionAPI): void {
|
|
|
168
168
|
|
|
169
169
|
// Structured multi-input dialog. PiChamber renders a native form and
|
|
170
170
|
// resolves with a values object; plain pi falls back to sequential prompts.
|
|
171
|
+
type PichamberHandle = {
|
|
172
|
+
ui: { form: (ctx: unknown, title: string, fields: Array<Record<string, unknown>>) => Promise<Record<string, string> | undefined> };
|
|
173
|
+
};
|
|
171
174
|
type FormCtx = Parameters<NonNullable<Parameters<ExtensionAPI['registerCommand']>[1]['handler']>>[1];
|
|
172
175
|
const askAgent = async (ctx: FormCtx): Promise<{ name: string; task: string } | undefined> => {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
]);
|
|
183
|
-
if (!values?.name || !values.task) return undefined;
|
|
184
|
-
return { name: values.name, task: values.task };
|
|
185
|
-
}
|
|
176
|
+
const pichamber = (globalThis as { pichamber?: PichamberHandle }).pichamber;
|
|
177
|
+
if (isPiChamber(ctx) && pichamber) {
|
|
178
|
+
const values = await pichamber.ui.form(ctx, 'Spawn sub-agent', [
|
|
179
|
+
{ id: 'name', label: 'Name', type: 'text', required: true, placeholder: 'research' },
|
|
180
|
+
{ id: 'task', label: 'Task', type: 'textarea', required: true },
|
|
181
|
+
{ id: 'priority', label: 'Priority', type: 'select', options: ['low', 'normal', 'high'], initial: 'normal' },
|
|
182
|
+
]);
|
|
183
|
+
if (!values?.name || !values.task) return undefined;
|
|
184
|
+
return { name: values.name, task: values.task };
|
|
186
185
|
}
|
|
187
186
|
const name = await ctx.ui.input('Sub-agent name');
|
|
188
187
|
if (!name) return undefined;
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One public `/api/pi/events` subscription over every live session daemon.
|
|
3
|
+
*
|
|
4
|
+
* The main daemon is subscribed exactly as before: same options, same
|
|
5
|
+
* frames, and its failure still ends the connection so the client
|
|
6
|
+
* reconnects. Its resume position keeps travelling as `fromSequence` +
|
|
7
|
+
* `streamEpoch`.
|
|
8
|
+
*
|
|
9
|
+
* Project daemons (sandboxed projects) are subscribed alongside it. Their
|
|
10
|
+
* frames gain `stream` (an opaque id per daemon) and `cursor` (an opaque
|
|
11
|
+
* value carrying every project daemon's epoch and sequence). A client
|
|
12
|
+
* resumes by sending the newest `cursor` it accepted next to its main
|
|
13
|
+
* position. Each project daemon is resumed from its own entry; a daemon
|
|
14
|
+
* whose lifetime changed answers that cursor with a resync snapshot, the
|
|
15
|
+
* same as the main daemon after a restart.
|
|
16
|
+
*
|
|
17
|
+
* Only the affected daemon's sessions resync:
|
|
18
|
+
* - a daemon appearing is subscribed without a cursor (snapshot baseline);
|
|
19
|
+
* - a daemon restarting (its runtime replaced in the pool) or stopping is
|
|
20
|
+
* unsubscribed, and every session this connection saw from it is
|
|
21
|
+
* announced with `session.moved` so clients refetch it from its owner;
|
|
22
|
+
* - a project daemon's subscription failing is the same as a stop, then a
|
|
23
|
+
* bounded retry while it stays registered; it never ends the connection.
|
|
24
|
+
*
|
|
25
|
+
* A project daemon runs inside a sandbox and is not trusted to say which
|
|
26
|
+
* sessions are its own. With `ownsSession`, its frames are delivered only
|
|
27
|
+
* for sessions the server finds in that daemon's folders; the answer is
|
|
28
|
+
* asked once per session and connection, and the daemon's later frames
|
|
29
|
+
* wait for it, so order and cursors are unchanged. Frames for any other
|
|
30
|
+
* session are dropped.
|
|
31
|
+
*
|
|
32
|
+
* A session whose frames arrive from a different daemon than before, or
|
|
33
|
+
* one the pool announces (`announceMove`), is also announced with
|
|
34
|
+
* `session.moved`, before any frame from its new owner.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
import { MAIN_DAEMON_KEY, publicDaemonStreamId } from './session-daemon/daemon-pool.js';
|
|
38
|
+
|
|
39
|
+
const CURSOR_VERSION = 1;
|
|
40
|
+
const MAX_CURSOR_LENGTH = 4096;
|
|
41
|
+
const MAX_CURSOR_STREAMS = 64;
|
|
42
|
+
const MAX_TRACKED_SESSIONS = 4096;
|
|
43
|
+
const RETRY_BASE_MS = 500;
|
|
44
|
+
const RETRY_CAP_MS = 30_000;
|
|
45
|
+
const MAX_WAITING_FRAMES = 4096;
|
|
46
|
+
|
|
47
|
+
const isEpoch = (value) => typeof value === 'string' && value.length > 0 && value.length <= 128;
|
|
48
|
+
const isStreamId = (value) => typeof value === 'string' && /^[A-Za-z0-9_-]{1,64}$/.test(value);
|
|
49
|
+
|
|
50
|
+
/** Decode a client cursor into `Map<streamId, { epoch, sequence }>`, or
|
|
51
|
+
* null when it is malformed. */
|
|
52
|
+
export const decodePiEventCursor = (value) => {
|
|
53
|
+
if (typeof value !== 'string' || value.length === 0 || value.length > MAX_CURSOR_LENGTH || !/^[A-Za-z0-9_-]+$/.test(value)) return null;
|
|
54
|
+
let parsed;
|
|
55
|
+
try {
|
|
56
|
+
parsed = JSON.parse(Buffer.from(value, 'base64url').toString('utf8'));
|
|
57
|
+
} catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
if (!parsed || typeof parsed !== 'object' || parsed.v !== CURSOR_VERSION || !parsed.d || typeof parsed.d !== 'object' || Array.isArray(parsed.d)) return null;
|
|
61
|
+
const entries = Object.entries(parsed.d);
|
|
62
|
+
if (entries.length > MAX_CURSOR_STREAMS) return null;
|
|
63
|
+
const positions = new Map();
|
|
64
|
+
for (const [id, position] of entries) {
|
|
65
|
+
if (!isStreamId(id) || !Array.isArray(position) || position.length !== 2) return null;
|
|
66
|
+
const [epoch, sequence] = position;
|
|
67
|
+
if (!isEpoch(epoch) || !Number.isSafeInteger(sequence) || sequence < 0) return null;
|
|
68
|
+
positions.set(id, { epoch, sequence });
|
|
69
|
+
}
|
|
70
|
+
return positions;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const encodeCursor = (positions) => {
|
|
74
|
+
const d = {};
|
|
75
|
+
for (const [id, { epoch, sequence }] of positions) d[id] = [epoch, sequence];
|
|
76
|
+
return Buffer.from(JSON.stringify({ v: CURSOR_VERSION, d }), 'utf8').toString('base64url');
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const movedFrame = (sessionId, directory) => ({
|
|
80
|
+
protocolVersion: 1, kind: 'event', name: 'session.moved', sequence: 0, sessionId, directory, payload: {},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Subscribe to every live daemon in `pool`. Same contract as a daemon
|
|
85
|
+
* runtime's `subscribe`: resolves to a close function; `onEvent` receives
|
|
86
|
+
* public (already projected) events; `onError` ends the connection.
|
|
87
|
+
*/
|
|
88
|
+
export const subscribeMergedPiEvents = async ({
|
|
89
|
+
pool,
|
|
90
|
+
projectFrame,
|
|
91
|
+
sessionId,
|
|
92
|
+
directory,
|
|
93
|
+
fromSequence,
|
|
94
|
+
streamEpoch,
|
|
95
|
+
cursor,
|
|
96
|
+
onEvent,
|
|
97
|
+
onError,
|
|
98
|
+
signal,
|
|
99
|
+
retryBaseMs = RETRY_BASE_MS,
|
|
100
|
+
ownsSession,
|
|
101
|
+
}) => {
|
|
102
|
+
const main = pool.main();
|
|
103
|
+
let closed = false;
|
|
104
|
+
// Project daemon positions by public stream id, seeded from the client's
|
|
105
|
+
// cursor so a daemon registering after this connection opened still
|
|
106
|
+
// resumes from where the client left it.
|
|
107
|
+
const positions = new Map(cursor ?? []);
|
|
108
|
+
// key -> { runtime, id, close?, failures, retryTimer? }
|
|
109
|
+
const attached = new Map();
|
|
110
|
+
// sessionId -> { key, directory }: the daemon whose frame this
|
|
111
|
+
// connection last delivered for the session.
|
|
112
|
+
const sessions = new Map();
|
|
113
|
+
|
|
114
|
+
const deliver = (event) => {
|
|
115
|
+
if (!closed) onEvent(event);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const announce = (sessionIdToMove, sessionDirectory) => {
|
|
119
|
+
sessions.delete(sessionIdToMove);
|
|
120
|
+
deliver(movedFrame(sessionIdToMove, sessionDirectory));
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const track = (key, event) => {
|
|
124
|
+
const previous = sessions.get(event.sessionId);
|
|
125
|
+
if (previous && previous.key !== key) announce(event.sessionId, event.directory);
|
|
126
|
+
sessions.delete(event.sessionId);
|
|
127
|
+
sessions.set(event.sessionId, { key, directory: event.directory });
|
|
128
|
+
if (sessions.size > MAX_TRACKED_SESSIONS) sessions.delete(sessions.keys().next().value);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const announceSessionsOf = (key) => {
|
|
132
|
+
for (const [id, entry] of [...sessions]) if (entry.key === key) announce(id, entry.directory);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const onMainFrame = (frame) => {
|
|
136
|
+
if (closed) return;
|
|
137
|
+
const event = projectFrame(frame);
|
|
138
|
+
if (!event) return;
|
|
139
|
+
track(MAIN_DAEMON_KEY, event);
|
|
140
|
+
deliver(event);
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// The position advances for a dropped frame too: it is the daemon's own
|
|
144
|
+
// numbering, and a resume must not ask for the frame again.
|
|
145
|
+
const passProjectEvent = (key, entry, event, owned) => {
|
|
146
|
+
if (isEpoch(event.streamEpoch)) {
|
|
147
|
+
const known = positions.get(entry.id);
|
|
148
|
+
if (!known || known.epoch !== event.streamEpoch || event.sequence > known.sequence) {
|
|
149
|
+
positions.set(entry.id, { epoch: event.streamEpoch, sequence: event.sequence });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (!owned) return;
|
|
153
|
+
track(key, event);
|
|
154
|
+
deliver({ ...event, stream: entry.id, cursor: encodeCursor(positions) });
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const passWaiting = async (key, entry) => {
|
|
158
|
+
entry.checking = true;
|
|
159
|
+
try {
|
|
160
|
+
while (entry.waiting.length > 0) {
|
|
161
|
+
if (closed || attached.get(key) !== entry) return;
|
|
162
|
+
const event = entry.waiting[0];
|
|
163
|
+
let owned = entry.owned.get(event.sessionId);
|
|
164
|
+
if (owned === undefined) {
|
|
165
|
+
try {
|
|
166
|
+
owned = Boolean(await ownsSession(key, event.sessionId, event.directory));
|
|
167
|
+
} catch {
|
|
168
|
+
owned = false;
|
|
169
|
+
}
|
|
170
|
+
if (closed || attached.get(key) !== entry) return;
|
|
171
|
+
entry.owned.set(event.sessionId, owned);
|
|
172
|
+
if (entry.owned.size > MAX_TRACKED_SESSIONS) entry.owned.delete(entry.owned.keys().next().value);
|
|
173
|
+
}
|
|
174
|
+
entry.waiting.shift();
|
|
175
|
+
passProjectEvent(key, entry, event, owned);
|
|
176
|
+
}
|
|
177
|
+
} finally {
|
|
178
|
+
entry.checking = false;
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const onProjectFrame = (key, entry, frame) => {
|
|
183
|
+
if (closed || attached.get(key) !== entry) return;
|
|
184
|
+
const event = projectFrame(frame);
|
|
185
|
+
if (!event) return;
|
|
186
|
+
if (!ownsSession || typeof event.sessionId !== 'string') {
|
|
187
|
+
passProjectEvent(key, entry, event, true);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const owned = entry.waiting.length === 0 ? entry.owned.get(event.sessionId) : undefined;
|
|
191
|
+
if (owned !== undefined) {
|
|
192
|
+
passProjectEvent(key, entry, event, owned);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
// A daemon that outruns the check is resubscribed rather than buffered
|
|
196
|
+
// without bound.
|
|
197
|
+
if (entry.waiting.length >= MAX_WAITING_FRAMES) {
|
|
198
|
+
fail(key, entry);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
entry.waiting.push(event);
|
|
202
|
+
if (!entry.checking) void passWaiting(key, entry);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
const detach = (key) => {
|
|
206
|
+
const entry = attached.get(key);
|
|
207
|
+
if (!entry) return;
|
|
208
|
+
attached.delete(key);
|
|
209
|
+
if (entry.retryTimer) clearTimeout(entry.retryTimer);
|
|
210
|
+
try {
|
|
211
|
+
entry.close?.();
|
|
212
|
+
} catch {
|
|
213
|
+
// A subscription that throws on close must not break the others.
|
|
214
|
+
}
|
|
215
|
+
announceSessionsOf(key);
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const scheduleRetry = (key, runtime, failures) => {
|
|
219
|
+
if (closed) return;
|
|
220
|
+
const entry = { runtime, id: publicDaemonStreamId(key), failures, close: undefined, retryTimer: undefined, owned: new Map(), waiting: [], checking: false };
|
|
221
|
+
entry.retryTimer = setTimeout(() => {
|
|
222
|
+
if (attached.get(key) !== entry) return;
|
|
223
|
+
attached.delete(key);
|
|
224
|
+
void attach(key, runtime, failures);
|
|
225
|
+
}, Math.min(RETRY_CAP_MS, retryBaseMs * 2 ** Math.min(failures, 6)));
|
|
226
|
+
entry.retryTimer.unref?.();
|
|
227
|
+
attached.set(key, entry);
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const fail = (key, entry) => {
|
|
231
|
+
if (closed || attached.get(key) !== entry) return;
|
|
232
|
+
detach(key);
|
|
233
|
+
scheduleRetry(key, entry.runtime, entry.failures + 1);
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
const attach = async (key, runtime, failures = 0) => {
|
|
237
|
+
if (closed || typeof runtime?.subscribe !== 'function') return;
|
|
238
|
+
const entry = { runtime, id: publicDaemonStreamId(key), failures, close: undefined, retryTimer: undefined, owned: new Map(), waiting: [], checking: false };
|
|
239
|
+
attached.set(key, entry);
|
|
240
|
+
const position = positions.get(entry.id);
|
|
241
|
+
try {
|
|
242
|
+
const close = await runtime.subscribe({
|
|
243
|
+
sessionId,
|
|
244
|
+
directory,
|
|
245
|
+
...(position ? { fromSequence: position.sequence, streamEpoch: position.epoch } : {}),
|
|
246
|
+
onEvent: (frame) => onProjectFrame(key, entry, frame),
|
|
247
|
+
onError: () => fail(key, entry),
|
|
248
|
+
signal,
|
|
249
|
+
});
|
|
250
|
+
if (closed || attached.get(key) !== entry) {
|
|
251
|
+
close?.();
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
entry.close = close;
|
|
255
|
+
entry.failures = 0;
|
|
256
|
+
} catch {
|
|
257
|
+
if (closed || attached.get(key) !== entry) return;
|
|
258
|
+
attached.delete(key);
|
|
259
|
+
scheduleRetry(key, runtime, failures + 1);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const reconcile = () => {
|
|
264
|
+
if (closed) return;
|
|
265
|
+
const live = new Map(pool.live().filter((item) => item.key !== MAIN_DAEMON_KEY).map((item) => [item.key, item.runtime]));
|
|
266
|
+
for (const [key, entry] of [...attached]) {
|
|
267
|
+
if (live.get(key) === entry.runtime) continue;
|
|
268
|
+
detach(key);
|
|
269
|
+
// A stopped daemon's position is dead; a restarted one keeps it so the
|
|
270
|
+
// new process answers with a resync snapshot.
|
|
271
|
+
if (!live.has(key)) positions.delete(entry.id);
|
|
272
|
+
}
|
|
273
|
+
for (const [key, runtime] of live) {
|
|
274
|
+
if (!attached.has(key)) void attach(key, runtime);
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
let closeMain;
|
|
279
|
+
let stopPoolListener = () => {};
|
|
280
|
+
let stopMoveListener = () => {};
|
|
281
|
+
|
|
282
|
+
const close = () => {
|
|
283
|
+
if (closed) return;
|
|
284
|
+
closed = true;
|
|
285
|
+
stopPoolListener();
|
|
286
|
+
stopMoveListener();
|
|
287
|
+
for (const entry of attached.values()) {
|
|
288
|
+
if (entry.retryTimer) clearTimeout(entry.retryTimer);
|
|
289
|
+
try {
|
|
290
|
+
entry.close?.();
|
|
291
|
+
} catch {
|
|
292
|
+
// Teardown continues for every other daemon.
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
attached.clear();
|
|
296
|
+
try {
|
|
297
|
+
closeMain?.();
|
|
298
|
+
} catch {
|
|
299
|
+
// Teardown continues.
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
try {
|
|
304
|
+
closeMain = await main.subscribe({ sessionId, directory, fromSequence, streamEpoch, onEvent: onMainFrame, onError, signal });
|
|
305
|
+
} catch (error) {
|
|
306
|
+
close();
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
309
|
+
if (closed) return close;
|
|
310
|
+
stopPoolListener = pool.onChange(reconcile);
|
|
311
|
+
stopMoveListener = pool.onMove((movedSessionId, movedDirectory) => {
|
|
312
|
+
if (!closed) announce(movedSessionId, movedDirectory);
|
|
313
|
+
});
|
|
314
|
+
reconcile();
|
|
315
|
+
return close;
|
|
316
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { subscribeMergedPiEvents } from './merged-event-stream.js';
|
|
4
|
+
|
|
5
|
+
const frame = (sessionId, sequence, directory = '/a') => ({
|
|
6
|
+
protocolVersion: 1, kind: 'event', name: 'message.delta', sequence, sessionId, directory, streamEpoch: 'epoch-box', payload: {},
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const fakeRuntime = () => {
|
|
10
|
+
const runtime = {
|
|
11
|
+
emit: null,
|
|
12
|
+
subscribe: async ({ onEvent }) => {
|
|
13
|
+
runtime.emit = onEvent;
|
|
14
|
+
return () => {};
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
return runtime;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const open = async ({ ownsSession } = {}) => {
|
|
21
|
+
const main = fakeRuntime();
|
|
22
|
+
const box = fakeRuntime();
|
|
23
|
+
const events = [];
|
|
24
|
+
const pool = {
|
|
25
|
+
main: () => main,
|
|
26
|
+
live: () => [{ key: 'main', runtime: main }, { key: 'sandbox:proj-a', runtime: box }],
|
|
27
|
+
onChange: () => () => {},
|
|
28
|
+
onMove: () => () => {},
|
|
29
|
+
};
|
|
30
|
+
await subscribeMergedPiEvents({
|
|
31
|
+
pool,
|
|
32
|
+
projectFrame: (value) => value,
|
|
33
|
+
onEvent: (event) => events.push(event),
|
|
34
|
+
onError: () => {},
|
|
35
|
+
...(ownsSession ? { ownsSession } : {}),
|
|
36
|
+
});
|
|
37
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
38
|
+
return { box, events };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const settle = () => new Promise((resolve) => setTimeout(resolve, 10));
|
|
42
|
+
|
|
43
|
+
describe('a project daemon\'s frames', () => {
|
|
44
|
+
it('are delivered only for sessions the server finds in that daemon\'s folders', async () => {
|
|
45
|
+
const asked = [];
|
|
46
|
+
const { box, events } = await open({
|
|
47
|
+
ownsSession: async (key, sessionId, directory) => {
|
|
48
|
+
asked.push([key, sessionId, directory]);
|
|
49
|
+
await new Promise((resolve) => setTimeout(resolve, 2));
|
|
50
|
+
return sessionId === 's-own';
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// The sandbox daemon reports on another project's session between two
|
|
55
|
+
// frames of its own.
|
|
56
|
+
box.emit(frame('s-own', 1));
|
|
57
|
+
box.emit(frame('s-foreign', 2));
|
|
58
|
+
box.emit(frame('s-own', 3));
|
|
59
|
+
await settle();
|
|
60
|
+
box.emit(frame('s-foreign', 4));
|
|
61
|
+
box.emit(frame('s-own', 5));
|
|
62
|
+
|
|
63
|
+
expect(events.map((event) => [event.sessionId, event.sequence])).toEqual([['s-own', 1], ['s-own', 3], ['s-own', 5]]);
|
|
64
|
+
// Asked once per session, with the daemon's key.
|
|
65
|
+
expect(asked).toEqual([['sandbox:proj-a', 's-own', '/a'], ['sandbox:proj-a', 's-foreign', '/a']]);
|
|
66
|
+
// The cursor still moves past the dropped frames.
|
|
67
|
+
const cursor = JSON.parse(Buffer.from(events.at(-1).cursor, 'base64url').toString('utf8'));
|
|
68
|
+
expect(Object.values(cursor.d)).toEqual([['epoch-box', 5]]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('keep their order while a session is being checked', async () => {
|
|
72
|
+
let answer;
|
|
73
|
+
const { box, events } = await open({ ownsSession: () => new Promise((resolve) => { answer = resolve; }) });
|
|
74
|
+
box.emit(frame('s-1', 1));
|
|
75
|
+
box.emit(frame('s-1', 2));
|
|
76
|
+
expect(events).toEqual([]);
|
|
77
|
+
answer(true);
|
|
78
|
+
await settle();
|
|
79
|
+
box.emit(frame('s-1', 3));
|
|
80
|
+
expect(events.map((event) => event.sequence)).toEqual([1, 2, 3]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('drops a session whose check fails', async () => {
|
|
84
|
+
const { box, events } = await open({ ownsSession: async () => { throw new Error('unreadable'); } });
|
|
85
|
+
box.emit(frame('s-1', 1));
|
|
86
|
+
await settle();
|
|
87
|
+
expect(events).toEqual([]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('pass straight through when nothing checks them', async () => {
|
|
91
|
+
const { box, events } = await open();
|
|
92
|
+
box.emit(frame('s-1', 1));
|
|
93
|
+
expect(events.map((event) => event.sequence)).toEqual([1]);
|
|
94
|
+
});
|
|
95
|
+
});
|