@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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
2
|
import { mkdir, open, readdir, stat } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import { createInterface } from 'node:readline';
|
|
@@ -33,6 +33,22 @@ class SessionJsonlError extends Error {
|
|
|
33
33
|
const malformed = () => new SessionJsonlError('MALFORMED_SESSION_JSONL');
|
|
34
34
|
const unreadable = () => new SessionJsonlError('SESSION_JSONL_UNREADABLE');
|
|
35
35
|
|
|
36
|
+
// Session folders of a sandboxed project are writable by code in the sandbox,
|
|
37
|
+
// and the server and main daemon read them. A FIFO planted under a transcript
|
|
38
|
+
// name would hold a thread of Node's file pool for as long as nothing writes
|
|
39
|
+
// to it, so transcripts are opened without blocking and anything that is not
|
|
40
|
+
// a regular file is refused.
|
|
41
|
+
const openTranscript = async (filePath) => {
|
|
42
|
+
const handle = await open(filePath, constants.O_RDONLY | (constants.O_NONBLOCK ?? 0));
|
|
43
|
+
try {
|
|
44
|
+
if (!(await handle.stat()).isFile()) throw unreadable();
|
|
45
|
+
} catch (error) {
|
|
46
|
+
await handle.close().catch(() => {});
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
return handle;
|
|
50
|
+
};
|
|
51
|
+
|
|
36
52
|
const LIST_PREVIEW_CHARS = 500;
|
|
37
53
|
/** Bound in-directory JSONL listing so a large folder is not one file at a time. */
|
|
38
54
|
const LIST_FILE_CONCURRENCY = 8;
|
|
@@ -107,8 +123,14 @@ export const matchesPiSessionJsonlName = (fileName, sessionId) => (
|
|
|
107
123
|
* Read only the session header. Callers that are looking up an id must
|
|
108
124
|
* not scan the rest of a multi-megabyte transcript.
|
|
109
125
|
*/
|
|
110
|
-
async function readPiSessionJsonlHeader(filePath) {
|
|
111
|
-
|
|
126
|
+
export async function readPiSessionJsonlHeader(filePath) {
|
|
127
|
+
let handle;
|
|
128
|
+
try {
|
|
129
|
+
handle = await openTranscript(filePath);
|
|
130
|
+
} catch {
|
|
131
|
+
throw unreadable();
|
|
132
|
+
}
|
|
133
|
+
const input = handle.createReadStream({ encoding: 'utf8' });
|
|
112
134
|
const lines = createInterface({ input, crlfDelay: Infinity });
|
|
113
135
|
try {
|
|
114
136
|
for await (const line of lines) {
|
|
@@ -137,17 +159,24 @@ async function readPiSessionJsonlHeader(filePath) {
|
|
|
137
159
|
* or `<id>.jsonl`) without listing or fully reading every transcript. A miss
|
|
138
160
|
* is `null`, not an empty success.
|
|
139
161
|
*/
|
|
140
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Every transcript under `agentDir` whose header holds `sessionId`. Session
|
|
164
|
+
* ids are unique, so more than one match means some file was written by
|
|
165
|
+
* something other than Pi; callers that route by transcript choose among
|
|
166
|
+
* them (see the project sandbox manager).
|
|
167
|
+
*/
|
|
168
|
+
export async function findPiSessionJsonlsById({ sessionId, agentDir, resolvePath = resolve, limit = Infinity }) {
|
|
141
169
|
if (typeof sessionId !== 'string' || sessionId.length === 0 || typeof agentDir !== 'string') {
|
|
142
|
-
return
|
|
170
|
+
return [];
|
|
143
171
|
}
|
|
144
172
|
const sessionsRoot = join(resolvePath(agentDir), 'sessions');
|
|
145
173
|
let dirEntries;
|
|
146
174
|
try {
|
|
147
175
|
dirEntries = await readdir(sessionsRoot, { withFileTypes: true });
|
|
148
176
|
} catch {
|
|
149
|
-
return
|
|
177
|
+
return [];
|
|
150
178
|
}
|
|
179
|
+
const matches = [];
|
|
151
180
|
for (const dirEntry of dirEntries) {
|
|
152
181
|
if (!dirEntry.isDirectory()) continue;
|
|
153
182
|
const dirPath = join(sessionsRoot, dirEntry.name);
|
|
@@ -164,20 +193,28 @@ export async function findPiSessionJsonlById({ sessionId, agentDir, resolvePath
|
|
|
164
193
|
try {
|
|
165
194
|
const header = await readPiSessionJsonlHeader(fullPath);
|
|
166
195
|
if (header.id === sessionId) {
|
|
167
|
-
|
|
196
|
+
matches.push({ id: sessionId, path: fullPath, cwd: header.cwd });
|
|
197
|
+
if (matches.length >= limit) return matches;
|
|
168
198
|
}
|
|
169
199
|
} catch {
|
|
170
200
|
continue;
|
|
171
201
|
}
|
|
172
202
|
}
|
|
173
203
|
}
|
|
174
|
-
return
|
|
204
|
+
return matches;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export async function findPiSessionJsonlById({ sessionId, agentDir, resolvePath = resolve }) {
|
|
208
|
+
const [found] = await findPiSessionJsonlsById({ sessionId, agentDir, resolvePath, limit: 1 });
|
|
209
|
+
return found ?? null;
|
|
175
210
|
}
|
|
176
211
|
|
|
177
212
|
export async function validatePiSessionJsonlFile(filePath) {
|
|
178
213
|
let sawHeader = false;
|
|
214
|
+
let handle;
|
|
179
215
|
try {
|
|
180
|
-
|
|
216
|
+
handle = await openTranscript(filePath);
|
|
217
|
+
const input = handle.createReadStream({ encoding: 'utf8' });
|
|
181
218
|
const lines = createInterface({ input, crlfDelay: Infinity });
|
|
182
219
|
for await (const line of lines) {
|
|
183
220
|
if (!line.trim()) continue;
|
|
@@ -196,6 +233,8 @@ export async function validatePiSessionJsonlFile(filePath) {
|
|
|
196
233
|
} catch (error) {
|
|
197
234
|
if (error instanceof SessionJsonlError) throw error;
|
|
198
235
|
throw unreadable();
|
|
236
|
+
} finally {
|
|
237
|
+
await handle?.close().catch(() => {});
|
|
199
238
|
}
|
|
200
239
|
if (!sawHeader) throw malformed();
|
|
201
240
|
}
|
|
@@ -293,7 +332,7 @@ const applyCompleteLines = (state, buffer, end) => {
|
|
|
293
332
|
async function scanPiSessionJsonlRange(filePath, state, size, stats) {
|
|
294
333
|
let handle;
|
|
295
334
|
try {
|
|
296
|
-
handle = await
|
|
335
|
+
handle = await openTranscript(filePath);
|
|
297
336
|
let position = state.offset;
|
|
298
337
|
let carry = [];
|
|
299
338
|
let carryBytes = 0;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
1
2
|
import { appendFile, mkdir, mkdtemp, rename, writeFile } from 'node:fs/promises';
|
|
2
3
|
import { tmpdir } from 'node:os';
|
|
3
4
|
import { join } from 'node:path';
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
listPiSessionJsonlDirectory,
|
|
13
14
|
matchesPiSessionJsonlName,
|
|
14
15
|
normalizeWindowsShellPath,
|
|
16
|
+
readPiSessionJsonlHeader,
|
|
15
17
|
validatePiSessionJsonlDirectory,
|
|
16
18
|
validatePiSessionJsonlFile,
|
|
17
19
|
} from './session-jsonl.js';
|
|
@@ -273,4 +275,13 @@ describe('Pi session JSONL validation', () => {
|
|
|
273
275
|
expect(cache.entries.size).toBe(0);
|
|
274
276
|
});
|
|
275
277
|
});
|
|
278
|
+
|
|
279
|
+
// A sandboxed project's session folder is writable from inside its sandbox.
|
|
280
|
+
it.skipIf(process.platform === 'win32')('refuses a FIFO under a transcript name instead of waiting on it', async () => {
|
|
281
|
+
const dir = await mkdtemp(join(tmpdir(), 'pichamber-jsonl-fifo-'));
|
|
282
|
+
const file = join(dir, 'x_abc.jsonl');
|
|
283
|
+
execFileSync('mkfifo', [file]);
|
|
284
|
+
await expect(readPiSessionJsonlHeader(file)).rejects.toMatchObject({ code: 'SESSION_JSONL_UNREADABLE' });
|
|
285
|
+
await expect(validatePiSessionJsonlFile(file)).rejects.toMatchObject({ code: 'SESSION_JSONL_UNREADABLE' });
|
|
286
|
+
});
|
|
276
287
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createHash } from 'node:crypto';
|
|
2
|
-
import { mkdir,
|
|
1
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
2
|
+
import { mkdir, readdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
|
|
5
|
-
import { withCrossProcessLock } from '../../server/cross-process-lock.js';
|
|
5
|
+
import { readSmallRegularFile, withCrossProcessLock } from '../../server/cross-process-lock.js';
|
|
6
6
|
|
|
7
7
|
export class SessionLeaseError extends Error {
|
|
8
8
|
constructor(code, message = 'The Pi session lease is unavailable.') {
|
|
@@ -20,6 +20,15 @@ const isPidAlive = (processLike, pid) => {
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
const isSignallablePid = (processLike, pid) => {
|
|
24
|
+
try {
|
|
25
|
+
processLike.kill(pid, 0);
|
|
26
|
+
return true;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
23
32
|
export const canonicalizeLeaseDir = (value, platform = process.platform) => {
|
|
24
33
|
const resolved = resolve(String(value ?? ''));
|
|
25
34
|
if (platform === 'win32') {
|
|
@@ -33,15 +42,38 @@ const leaseHash = ({ agentDir, cwd, sessionId }) => createHash('sha256')
|
|
|
33
42
|
.digest('hex')
|
|
34
43
|
.slice(0, 32);
|
|
35
44
|
|
|
36
|
-
|
|
45
|
+
const LEASE_SCOPE = /^[A-Za-z0-9_-]{1,64}$/;
|
|
46
|
+
|
|
47
|
+
/** The folder holding every sandbox's own lease folder, one per scope. */
|
|
48
|
+
const scopedLeaseRoot = (agentDir, platform = process.platform) => (
|
|
49
|
+
join(canonicalizeLeaseDir(agentDir, platform), '.pichamber', 'locks', 'sandbox-sessions')
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
/** The lease folder of one scope: all a sandbox daemon is granted. */
|
|
53
|
+
export const scopedLeaseDir = (agentDir, scope, platform = process.platform) => {
|
|
54
|
+
if (typeof scope !== 'string' || !LEASE_SCOPE.test(scope)) throw new SessionLeaseError('INVALID_LEASE_SCOPE');
|
|
55
|
+
return join(scopedLeaseRoot(agentDir, platform), scope);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Where a session's lease lives. A daemon with a `scope` (a sandbox daemon)
|
|
60
|
+
* keeps its leases in its own folder, the only lease folder it can reach;
|
|
61
|
+
* every other daemon uses the shared one. The file name is the same in
|
|
62
|
+
* both, so a daemon outside a sandbox can look a session up in each scope.
|
|
63
|
+
*/
|
|
64
|
+
export const resolveSessionLeaseFile = ({ agentDir, cwd, sessionId, scope, platform = process.platform } = {}) => {
|
|
37
65
|
if (typeof sessionId !== 'string' || sessionId.length === 0) {
|
|
38
66
|
throw new SessionLeaseError('INVALID_SESSION_ID');
|
|
39
67
|
}
|
|
40
68
|
const canonicalAgentDir = canonicalizeLeaseDir(agentDir, platform);
|
|
41
69
|
const canonicalCwd = canonicalizeLeaseDir(cwd, platform);
|
|
42
70
|
const name = `${leaseHash({ agentDir: canonicalAgentDir, cwd: canonicalCwd, sessionId })}.json`;
|
|
71
|
+
const directory = scope === undefined
|
|
72
|
+
? join(canonicalAgentDir, '.pichamber', 'locks', 'sessions')
|
|
73
|
+
: scopedLeaseDir(canonicalAgentDir, scope, platform);
|
|
43
74
|
return {
|
|
44
|
-
file: join(
|
|
75
|
+
file: join(directory, name),
|
|
76
|
+
name,
|
|
45
77
|
canonicalAgentDir,
|
|
46
78
|
canonicalCwd,
|
|
47
79
|
};
|
|
@@ -67,6 +99,35 @@ const isOwnLease = (lease, owner) => (
|
|
|
67
99
|
&& lease?.daemonPid === owner?.daemonPid
|
|
68
100
|
);
|
|
69
101
|
|
|
102
|
+
// A live lease a sandbox daemon holds on this session, read from the scope
|
|
103
|
+
// folders. Those folders are written by sandboxed code: a file there is read
|
|
104
|
+
// as a small regular file or not at all, and only a lease for this very
|
|
105
|
+
// session counts.
|
|
106
|
+
const scopedLeaseHolder = async ({ canonicalAgentDir, name, sessionId, owner, platform, processLike }) => {
|
|
107
|
+
const root = scopedLeaseRoot(canonicalAgentDir, platform);
|
|
108
|
+
let scopes;
|
|
109
|
+
try {
|
|
110
|
+
scopes = await readdir(root, { withFileTypes: true });
|
|
111
|
+
} catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
for (const scope of scopes) {
|
|
115
|
+
if (!scope.isDirectory() || !LEASE_SCOPE.test(scope.name)) continue;
|
|
116
|
+
let lease;
|
|
117
|
+
try {
|
|
118
|
+
lease = JSON.parse(await readSmallRegularFile(join(root, scope.name, name)));
|
|
119
|
+
} catch {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (!isValidLease(lease) || lease.sessionId !== sessionId || isOwnLease(lease, owner)) continue;
|
|
123
|
+
// A sandbox daemon runs as this user, so its pid can be signalled. A
|
|
124
|
+
// pid that answers EPERM (pid 1, another user's process) was written by
|
|
125
|
+
// sandboxed code to hold the session forever; it is not a holder.
|
|
126
|
+
if (isSignallablePid(processLike, lease.daemonPid)) return lease;
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
};
|
|
130
|
+
|
|
70
131
|
/**
|
|
71
132
|
* Acquire exclusive cross-daemon ownership of one Pi session.
|
|
72
133
|
*
|
|
@@ -83,14 +144,15 @@ export const acquireSessionLease = async ({
|
|
|
83
144
|
platform = process.platform,
|
|
84
145
|
processLike = process,
|
|
85
146
|
timeoutMs = 5_000,
|
|
147
|
+
scope,
|
|
86
148
|
} = {}) => {
|
|
87
149
|
if (!owner || typeof owner !== 'object') throw new SessionLeaseError('INVALID_OWNER');
|
|
88
|
-
const { file, canonicalAgentDir, canonicalCwd } = resolveSessionLeaseFile({ agentDir, cwd, sessionId, platform });
|
|
150
|
+
const { file, name, canonicalAgentDir, canonicalCwd } = resolveSessionLeaseFile({ agentDir, cwd, sessionId, scope, platform });
|
|
89
151
|
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
90
152
|
return withCrossProcessLock(`${file}.lock`, async () => {
|
|
91
153
|
let current = null;
|
|
92
154
|
try {
|
|
93
|
-
current = JSON.parse(await
|
|
155
|
+
current = JSON.parse(await readSmallRegularFile(file));
|
|
94
156
|
} catch (error) {
|
|
95
157
|
if (error?.code !== 'ENOENT') throw new SessionLeaseError('LEASE_UNREADABLE');
|
|
96
158
|
}
|
|
@@ -99,6 +161,12 @@ export const acquireSessionLease = async ({
|
|
|
99
161
|
return { acquired: false, owner: current };
|
|
100
162
|
}
|
|
101
163
|
}
|
|
164
|
+
// A sandbox daemon may be running the session. It cannot see this
|
|
165
|
+
// daemon's leases, so the check is made from this side only.
|
|
166
|
+
if (scope === undefined) {
|
|
167
|
+
const holder = await scopedLeaseHolder({ canonicalAgentDir, name, sessionId, owner, platform, processLike });
|
|
168
|
+
if (holder) return { acquired: false, owner: holder };
|
|
169
|
+
}
|
|
102
170
|
const lease = {
|
|
103
171
|
profileKey: owner.profileKey,
|
|
104
172
|
serverInstanceId: owner.serverInstanceId,
|
|
@@ -109,9 +177,18 @@ export const acquireSessionLease = async ({
|
|
|
109
177
|
agentDir: canonicalAgentDir,
|
|
110
178
|
acquiredAt: new Date().toISOString(),
|
|
111
179
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
180
|
+
// Sandbox daemons share this folder, so a name that can be guessed could
|
|
181
|
+
// be planted as a symlink to any file. A random name created with `wx`
|
|
182
|
+
// never writes through one, and the rename replaces whatever sits at the
|
|
183
|
+
// lease path rather than following it.
|
|
184
|
+
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
185
|
+
try {
|
|
186
|
+
await writeFile(temporary, JSON.stringify(lease), { flag: 'wx', mode: 0o600 });
|
|
187
|
+
await rename(temporary, file);
|
|
188
|
+
} catch {
|
|
189
|
+
await rm(temporary, { force: true }).catch(() => {});
|
|
190
|
+
throw new SessionLeaseError('LEASE_UNREADABLE');
|
|
191
|
+
}
|
|
115
192
|
return { acquired: true, lease };
|
|
116
193
|
}, { timeoutMs, processLike });
|
|
117
194
|
};
|
|
@@ -124,12 +201,13 @@ export const releaseSessionLease = async ({
|
|
|
124
201
|
platform = process.platform,
|
|
125
202
|
processLike = process,
|
|
126
203
|
timeoutMs = 5_000,
|
|
204
|
+
scope,
|
|
127
205
|
} = {}) => {
|
|
128
|
-
const { file } = resolveSessionLeaseFile({ agentDir, cwd, sessionId, platform });
|
|
206
|
+
const { file } = resolveSessionLeaseFile({ agentDir, cwd, sessionId, scope, platform });
|
|
129
207
|
return withCrossProcessLock(`${file}.lock`, async () => {
|
|
130
208
|
let current = null;
|
|
131
209
|
try {
|
|
132
|
-
current = JSON.parse(await
|
|
210
|
+
current = JSON.parse(await readSmallRegularFile(file));
|
|
133
211
|
} catch (error) {
|
|
134
212
|
if (error?.code === 'ENOENT') return { released: false };
|
|
135
213
|
throw new SessionLeaseError('LEASE_UNREADABLE');
|
|
@@ -140,10 +218,10 @@ export const releaseSessionLease = async ({
|
|
|
140
218
|
}, { timeoutMs, processLike });
|
|
141
219
|
};
|
|
142
220
|
|
|
143
|
-
export const readSessionLeaseOwner = async ({ agentDir, cwd, sessionId, platform = process.platform } = {}) => {
|
|
144
|
-
const { file } = resolveSessionLeaseFile({ agentDir, cwd, sessionId, platform });
|
|
221
|
+
export const readSessionLeaseOwner = async ({ agentDir, cwd, sessionId, scope, platform = process.platform } = {}) => {
|
|
222
|
+
const { file } = resolveSessionLeaseFile({ agentDir, cwd, sessionId, scope, platform });
|
|
145
223
|
try {
|
|
146
|
-
const current = JSON.parse(await
|
|
224
|
+
const current = JSON.parse(await readSmallRegularFile(file));
|
|
147
225
|
return isValidLease(current) ? current : null;
|
|
148
226
|
} catch {
|
|
149
227
|
return null;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, symlink, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { tmpdir } from 'node:os';
|
|
4
5
|
import { join } from 'node:path';
|
|
5
6
|
|
|
@@ -7,6 +8,8 @@ import {
|
|
|
7
8
|
acquireSessionLease,
|
|
8
9
|
readSessionLeaseOwner,
|
|
9
10
|
releaseSessionLease,
|
|
11
|
+
resolveSessionLeaseFile,
|
|
12
|
+
scopedLeaseDir,
|
|
10
13
|
} from './session-lease.js';
|
|
11
14
|
|
|
12
15
|
const ownerA = {
|
|
@@ -105,4 +108,107 @@ describe('session lease', () => {
|
|
|
105
108
|
acquired: true,
|
|
106
109
|
});
|
|
107
110
|
});
|
|
111
|
+
// Sandbox daemons can write the lease folder, so nothing in it is trusted.
|
|
112
|
+
describe.skipIf(process.platform === 'win32')('a lease folder untrusted code can write', () => {
|
|
113
|
+
const setup = async () => {
|
|
114
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-lease-'));
|
|
115
|
+
const agentDir = join(root, 'agent');
|
|
116
|
+
const cwd = join(root, 'project');
|
|
117
|
+
const { file } = resolveSessionLeaseFile({ agentDir, cwd, sessionId: 'session-1' });
|
|
118
|
+
await mkdir(join(file, '..'), { recursive: true });
|
|
119
|
+
const victim = join(root, 'victim.txt');
|
|
120
|
+
await writeFile(victim, 'keep me');
|
|
121
|
+
return { agentDir, cwd, file, victim };
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
it('never writes through a symlink planted at the old temp name', async () => {
|
|
125
|
+
const { agentDir, cwd, file, victim } = await setup();
|
|
126
|
+
await symlink(victim, `${file}.${process.pid}.tmp`);
|
|
127
|
+
|
|
128
|
+
await expect(acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: ownerA }))
|
|
129
|
+
.resolves.toMatchObject({ acquired: true });
|
|
130
|
+
expect(await readFile(victim, 'utf8')).toBe('keep me');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('does not follow a symlink planted as the lease file', async () => {
|
|
134
|
+
const { agentDir, cwd, file, victim } = await setup();
|
|
135
|
+
await writeFile(victim, JSON.stringify({ ...ownerB, sessionId: 'session-1' }));
|
|
136
|
+
await symlink(victim, file);
|
|
137
|
+
|
|
138
|
+
await expect(acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: ownerA }))
|
|
139
|
+
.rejects.toMatchObject({ code: 'LEASE_UNREADABLE' });
|
|
140
|
+
expect(await readSessionLeaseOwner({ agentDir, cwd, sessionId: 'session-1' })).toBeNull();
|
|
141
|
+
expect(JSON.parse(await readFile(victim, 'utf8')).daemonId).toBe('daemon-b');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('does not wait on a FIFO planted as the lease file', async () => {
|
|
145
|
+
const { agentDir, cwd, file } = await setup();
|
|
146
|
+
execFileSync('mkfifo', [file]);
|
|
147
|
+
|
|
148
|
+
await expect(acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: ownerA, timeoutMs: 500 }))
|
|
149
|
+
.rejects.toMatchObject({ code: 'LEASE_UNREADABLE' });
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
// A sandbox daemon keeps its leases in its own folder (its scope).
|
|
153
|
+
describe('a sandbox daemon\'s lease folder', () => {
|
|
154
|
+
const dirs = async () => {
|
|
155
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-lease-'));
|
|
156
|
+
return { agentDir: join(root, 'agent'), cwd: join(root, 'project') };
|
|
157
|
+
};
|
|
158
|
+
const sandboxOwner = { ...ownerB, daemonId: 'daemon-sandbox' };
|
|
159
|
+
|
|
160
|
+
it('holds the lease where no other project\'s leases are', async () => {
|
|
161
|
+
const { agentDir, cwd } = await dirs();
|
|
162
|
+
await acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: sandboxOwner, scope: 'proj-a' });
|
|
163
|
+
const { file } = resolveSessionLeaseFile({ agentDir, cwd, sessionId: 'session-1', scope: 'proj-a' });
|
|
164
|
+
expect(file.startsWith(`${scopedLeaseDir(agentDir, 'proj-a')}/`)).toBe(true);
|
|
165
|
+
expect(await readSessionLeaseOwner({ agentDir, cwd, sessionId: 'session-1' })).toBeNull();
|
|
166
|
+
expect((await readSessionLeaseOwner({ agentDir, cwd, sessionId: 'session-1', scope: 'proj-a' }))?.daemonId).toBe('daemon-sandbox');
|
|
167
|
+
expect(() => resolveSessionLeaseFile({ agentDir, cwd, sessionId: 'session-1', scope: '../sessions' })).toThrow();
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it('keeps a daemon outside the sandbox out of a session the sandbox runs, until it lets go', async () => {
|
|
171
|
+
const { agentDir, cwd } = await dirs();
|
|
172
|
+
await acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: sandboxOwner, scope: 'proj-a' });
|
|
173
|
+
|
|
174
|
+
const contention = await acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: ownerA });
|
|
175
|
+
expect(contention).toMatchObject({ acquired: false, owner: { daemonId: 'daemon-sandbox' } });
|
|
176
|
+
// Another session is not affected.
|
|
177
|
+
await expect(acquireSessionLease({ agentDir, cwd, sessionId: 'session-2', owner: ownerA })).resolves.toMatchObject({ acquired: true });
|
|
178
|
+
|
|
179
|
+
await releaseSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: sandboxOwner, scope: 'proj-a' });
|
|
180
|
+
await expect(acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: ownerA })).resolves.toMatchObject({ acquired: true });
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('lets a replacement daemon of the same project see the lease', async () => {
|
|
184
|
+
const { agentDir, cwd } = await dirs();
|
|
185
|
+
await acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: sandboxOwner, scope: 'proj-a' });
|
|
186
|
+
const next = await acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: { ...sandboxOwner, daemonId: 'daemon-next' }, scope: 'proj-a' });
|
|
187
|
+
expect(next.acquired).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('ignores a file in a sandbox folder that is not a lease for the session', async () => {
|
|
191
|
+
const { agentDir, cwd } = await dirs();
|
|
192
|
+
const { name } = resolveSessionLeaseFile({ agentDir, cwd, sessionId: 'session-1' });
|
|
193
|
+
const scope = scopedLeaseDir(agentDir, 'proj-a');
|
|
194
|
+
await mkdir(scope, { recursive: true });
|
|
195
|
+
// A lease for another session copied under this session's name.
|
|
196
|
+
await writeFile(join(scope, name), JSON.stringify({ ...sandboxOwner, sessionId: 'session-9' }));
|
|
197
|
+
await expect(acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: ownerA })).resolves.toMatchObject({ acquired: true });
|
|
198
|
+
});
|
|
199
|
+
it('ignores a forged lease that names a process this user cannot signal', async () => {
|
|
200
|
+
const { agentDir, cwd } = await dirs();
|
|
201
|
+
// Written through the real path so the file is a well-formed lease.
|
|
202
|
+
await acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: { ...sandboxOwner, daemonPid: 1 }, scope: 'proj-a' });
|
|
203
|
+
const processLike = {
|
|
204
|
+
pid: process.pid,
|
|
205
|
+
kill: (pid) => {
|
|
206
|
+
if (pid === 1) throw Object.assign(new Error('EPERM'), { code: 'EPERM' });
|
|
207
|
+
return true;
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
await expect(acquireSessionLease({ agentDir, cwd, sessionId: 'session-1', owner: ownerA, processLike }))
|
|
211
|
+
.resolves.toMatchObject({ acquired: true });
|
|
212
|
+
});
|
|
213
|
+
});
|
|
108
214
|
});
|