@pi-chamber/web 1.0.7 → 1.0.8-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/AgentsSurface-CcWBqAWV.js +1 -0
- package/dist/assets/ChoicesArtifact-Kk-qvrSB.js +1 -0
- package/dist/assets/DiagramView-DZUBo1uP.js +1 -0
- package/dist/assets/{DiffView-BxW6BuOC.js → DiffView-CiZy4jFA.js} +6 -6
- package/dist/assets/FileSaveConflictDialog-DZ9NDwOO.js +3 -0
- package/dist/assets/FilesView-DqiZ9kw9.js +6 -0
- package/dist/assets/GitHubDetailScaffold-DM2DH7o8.js +11 -0
- package/dist/assets/GitHubLinkPicker-ChB8NZ1h.js +1 -0
- package/dist/assets/GitHubListPrimitives-CibDiJGq.js +1 -0
- package/dist/assets/{GitView-DD33ngnM.js → GitView--EaZQrBr.js} +5 -5
- package/dist/assets/{IssuesSurface-BAY_eyX5.js → IssuesSurface-CySTpaD1.js} +3 -3
- package/dist/assets/{JsonTreeView-DpXbUrAl.js → JsonTreeView-_yMHKKQZ.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cn63lAmn.js → MarkdownRendererImpl-D_-2fQw0.js} +3 -3
- package/dist/assets/PatchDiff-bHObDlhD.js +1 -0
- package/dist/assets/PierreDiffViewer-UY7Cse-s.js +147 -0
- package/dist/assets/PullRequestsSurface-iXy6chwc.js +2 -0
- package/dist/assets/{SessionSwitcherContent-CscYekC1.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
- package/dist/assets/SessionSwitcherDropdown-CDOX-5Y2.js +2 -0
- package/dist/assets/SessionUnreadDot-Dwc3MdvA.js +1 -0
- package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
- package/dist/assets/{SettingsWindow-gxjULdm1.js → SettingsWindow-CUg49Mfh.js} +1 -1
- package/dist/assets/{StickyHorizontalScrollbar-DNsbTLS7.js → StickyHorizontalScrollbar-CMbTn5WQ.js} +1 -1
- package/dist/assets/SubagentsArtifact-DUZX9tDe.js +1 -0
- package/dist/assets/ToolOutputDialog-BuZZaRw4.js +8 -0
- package/dist/assets/ToolPartDiffPreview-CKncG6i2.js +1 -0
- package/dist/assets/{VirtualizedFileDiff-BrbPymTL.js → VirtualizedFileDiff-BGZiLPe_.js} +4 -4
- package/dist/assets/{Virtualizer-okhy9Aq3.js → Virtualizer-PxblpQn6.js} +1 -1
- package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
- package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
- package/dist/assets/{collapsible-D6qdoq7-.js → collapsible-Bro9KrfM.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-G4csGiKs.js → computeVirtualFileMetrics-DJQqK49u.js} +2 -2
- package/dist/assets/contextFileOpenGuard-ByWK3Sru.js +1 -0
- package/dist/assets/{fileTreeStatus-Bskhj4qT.js → fileTreeStatus-CyJ3TOYD.js} +2 -2
- package/dist/assets/gitStatusPredicates-BsXrwngT.js +1 -0
- package/dist/assets/githubLink-g2bmC0qi.js +10 -0
- package/dist/assets/index-B_L9GVYw.css +1 -0
- package/dist/assets/{index-ComwtfT4.js → index-C9rUUQ_Y.js} +1 -1
- package/dist/assets/index-CKKWVoND.js +11 -0
- package/dist/assets/{main-DoiadX0a.js → main-DT-4_fhe.js} +2 -2
- package/dist/assets/main-DsLMU9CT.js +137 -0
- package/dist/assets/{markdownCore-DczkEluO.js → markdownCore-QmM_aOnZ.js} +2 -2
- package/dist/assets/{miniChat-Ck6MEZ9Q.js → miniChat-BqGslD2z.js} +2 -2
- package/dist/assets/{mobile-BucKVm1P.js → mobile-C5JOcDIC.js} +2 -2
- package/dist/assets/{nativeFileSave-Cp9i5QGd.js → nativeFileSave-DSMsJqXM.js} +1 -1
- package/dist/assets/pi-session-focus-preference-Cc_S4zi1.js +9 -0
- package/dist/assets/{renderDiffWithHighlighter-PL82AR81.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-CiSkecEE.js +2 -0
- package/dist/assets/{renderFileWithHighlighter-CYgfbA4F.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
- package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
- package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
- package/dist/assets/runtimeSurface-0K7vuUpd.js +1 -0
- package/dist/assets/selection-CnYkEsu_.js +1 -0
- package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
- package/dist/assets/useGitHubRemoteSearch-CgP-zEBj.js +1 -0
- package/dist/assets/useSwitcherItems-C8G5F0hs.js +1 -0
- package/dist/assets/{vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js → vendor-aparajita-capacitor-secure-storage-DUoR8t1G.js} +1 -1
- package/dist/assets/{vendor-base-ui-BCqPBzDj.js → vendor-base-ui-DE6jnTiC.js} +1 -1
- package/dist/assets/{vendor-boot-3SaHYVb1.js → vendor-boot-D-KEJjsM.js} +29 -29
- package/dist/assets/{vendor-capacitor-app-NbQ-WiPS.js → vendor-capacitor-app-CO5jS31X.js} +1 -1
- package/dist/assets/{vendor-capacitor-keyboard-CgrHt8iN.js → vendor-capacitor-keyboard-335osRpd.js} +1 -1
- package/dist/assets/{vendor-capacitor-status-bar-CWt0OF5t.js → vendor-capacitor-status-bar-lB9y4H9d.js} +1 -1
- package/dist/assets/{vendor-codemirror-autocomplete-WThuuUAz.js → vendor-codemirror-autocomplete-BKvJ8PfM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-angular-BbLGCxF6.js → vendor-codemirror-lang-angular-wjCUD0bM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-cpp-Cceks-9O.js → vendor-codemirror-lang-cpp-LJzlG8sJ.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-css-D1wpUg3Z.js → vendor-codemirror-lang-css-DoEEdEpW.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-go-Cv0zXHHM.js → vendor-codemirror-lang-go-DexsLPb8.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-html-DbL8oT9H.js → vendor-codemirror-lang-html-h25V-Hp5.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-java-CNugenuC.js → vendor-codemirror-lang-java-D8xoT8cv.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-javascript-Bx_FIyZF.js → vendor-codemirror-lang-javascript-DF3GDYje.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-jinja-DDGjB3Zq.js → vendor-codemirror-lang-jinja-BboTHFdn.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-json-DIvqf9Pb.js → vendor-codemirror-lang-json-DCqvG1nE.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-less-D8r9dGG1.js → vendor-codemirror-lang-less-B8ZrSKJM.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-liquid-B24mguYi.js → vendor-codemirror-lang-liquid-DF9S5m5F.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-markdown-v3yG2sbf.js → vendor-codemirror-lang-markdown-6BNbCEPe.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-php-BcZGalqy.js → vendor-codemirror-lang-php-CQwAz1Hd.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-python-b-JqEwQy.js → vendor-codemirror-lang-python-DQym-8Tx.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-rust-B1uZxDW-.js → vendor-codemirror-lang-rust-DknzOTkO.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sass-DqPrngKp.js → vendor-codemirror-lang-sass-dB0Rm5HI.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-sql-UyCnpt-k.js → vendor-codemirror-lang-sql-CCQUnnD-.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-vue-xDwYkovV.js → vendor-codemirror-lang-vue-h1M5bF00.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-wast-CF3169p_.js → vendor-codemirror-lang-wast-DWgtlGfu.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-xml-FCtVhuOb.js → vendor-codemirror-lang-xml-DncwoCUY.js} +1 -1
- package/dist/assets/{vendor-codemirror-lang-yaml-g0sPmAnv.js → vendor-codemirror-lang-yaml-C7QkS5ER.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-B03xgzP2.js → vendor-codemirror-language-data-BUZIlm3G.js} +2 -2
- package/dist/assets/{vendor-codemirror-search-Dw3Wpu15.js → vendor-codemirror-search-BlDCaCMK.js} +1 -1
- package/dist/assets/{vendor-lezer-cpp-Cu3E-KUI.js → vendor-lezer-cpp-B4JK1BC1.js} +1 -1
- package/dist/assets/{vendor-lezer-css-Cb8vp67u.js → vendor-lezer-css-DRxDmhcy.js} +1 -1
- package/dist/assets/{vendor-lezer-go-BTsIaOm7.js → vendor-lezer-go-DsUgfmxi.js} +1 -1
- package/dist/assets/{vendor-lezer-html-UQMsUwj-.js → vendor-lezer-html-qr9pUPmM.js} +1 -1
- package/dist/assets/{vendor-lezer-java-BIWrFrAx.js → vendor-lezer-java-6UyNiQiB.js} +1 -1
- package/dist/assets/{vendor-lezer-javascript-BH2Etgoy.js → vendor-lezer-javascript-CUdJ0VGA.js} +1 -1
- package/dist/assets/{vendor-lezer-json-CE-QUCwM.js → vendor-lezer-json-BKYAA8Hu.js} +1 -1
- package/dist/assets/{vendor-lezer-lr-HY6Yc0Vr.js → vendor-lezer-lr-DluApmOX.js} +1 -1
- package/dist/assets/{vendor-lezer-markdown-xFL3Evwf.js → vendor-lezer-markdown-B-uzYzYT.js} +1 -1
- package/dist/assets/{vendor-lezer-php-Cr_mQGrG.js → vendor-lezer-php-DI6PNjlz.js} +1 -1
- package/dist/assets/{vendor-lezer-python-BNRFWCb0.js → vendor-lezer-python-Bj232yb5.js} +1 -1
- package/dist/assets/{vendor-lezer-rust-BvfOK5cU.js → vendor-lezer-rust-DlPG_Yau.js} +1 -1
- package/dist/assets/{vendor-lezer-sass-qoxiLisk.js → vendor-lezer-sass-CBsyWB2A.js} +1 -1
- package/dist/assets/{vendor-lezer-xml--x8SSpqU.js → vendor-lezer-xml-C1FmgtmE.js} +1 -1
- package/dist/assets/{vendor-lezer-yaml-BDo1JaEr.js → vendor-lezer-yaml-DpHmjriG.js} +1 -1
- package/dist/assets/{vendor-replit-codemirror-vim-D1Fe7FiY.js → vendor-replit-codemirror-vim-Cvk64got.js} +1 -1
- package/dist/assets/{web-components-CGDpzixf.js → web-components-BpncHjnV.js} +4 -4
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +2 -1
- package/plugins/featured.json +12 -0
- package/plugins/registry.json +7 -0
- package/plugins/subagents/LICENSE +25 -0
- package/plugins/subagents/agents/planner.md +36 -0
- package/plugins/subagents/agents/reviewer.md +34 -0
- package/plugins/subagents/agents/scout.md +49 -0
- package/plugins/subagents/agents/worker.md +23 -0
- package/plugins/subagents/extension.js +631 -0
- package/plugins/subagents/extension.test.js +295 -0
- package/plugins/subagents/package.json +41 -0
- package/plugins/visuals/choices.js +168 -0
- package/plugins/visuals/extension.js +90 -0
- package/plugins/visuals/files.js +74 -0
- package/plugins/visuals/package.json +32 -0
- package/server/index.js +103 -24
- package/server/lib/git/DOCUMENTATION.md +4 -0
- package/server/lib/git/service.js +70 -5
- package/server/lib/git/service.test.js +179 -0
- package/server/lib/github/DOCUMENTATION.md +6 -2
- package/server/lib/github/gh-cli.js +35 -9
- package/server/lib/github/gh-cli.test.js +122 -0
- package/server/lib/marketplace/DOCUMENTATION.md +95 -0
- package/server/lib/marketplace/featured.js +176 -0
- package/server/lib/marketplace/featured.test.js +207 -0
- package/server/lib/marketplace/npm-registry.js +255 -0
- package/server/lib/marketplace/npm-registry.test.js +227 -0
- package/server/lib/marketplace/routes.js +64 -0
- package/server/lib/marketplace/routes.test.js +119 -0
- package/server/lib/marketplace/service.js +225 -0
- package/server/lib/marketplace/service.test.js +174 -0
- package/server/lib/notifications/DOCUMENTATION.md +10 -4
- package/server/lib/notifications/pi-notification-watcher.js +95 -33
- package/server/lib/notifications/pi-notification-watcher.test.js +89 -0
- package/server/lib/open-url/DOCUMENTATION.md +2 -1
- package/server/lib/pi/extension-protocol.js +54 -0
- package/server/lib/pi/fixtures/pichamber-gui-demo.ts +12 -13
- package/server/lib/pi/merged-event-stream.js +316 -0
- package/server/lib/pi/merged-event-stream.test.js +95 -0
- package/server/lib/pi/routes-daemon-pool.test.js +348 -0
- package/server/lib/pi/routes-extension-events.test.js +115 -0
- package/server/lib/pi/routes-merged-events.test.js +327 -0
- package/server/lib/pi/routes-sandbox.test.js +1684 -0
- package/server/lib/pi/routes.js +790 -87
- package/server/lib/pi/routes.test.js +381 -1
- package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
- package/server/lib/pi/sandbox/launcher.js +122 -0
- package/server/lib/pi/sandbox/launcher.test.js +91 -0
- package/server/lib/pi/sandbox/nono-launcher.js +455 -0
- package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
- package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
- package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
- package/server/lib/pi/sandbox/nono-profile.json +22 -0
- package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
- package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
- package/server/lib/pi/sandbox/project-sandbox.js +207 -0
- package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
- package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
- package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
- package/server/lib/pi/sandbox/trust-ask.js +135 -0
- package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
- package/server/lib/pi/sandbox/worktree-ids.js +96 -0
- package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +47 -10
- package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
- package/server/lib/pi/session-daemon/daemon-process.js +10 -1
- package/server/lib/pi/session-daemon/extension-bridge.js +89 -29
- package/server/lib/pi/session-daemon/extension-config.js +902 -0
- package/server/lib/pi/session-daemon/extension-config.test.js +798 -0
- package/server/lib/pi/session-daemon/extension-controls.js +177 -0
- package/server/lib/pi/session-daemon/extension-controls.test.js +181 -0
- package/server/lib/pi/session-daemon/extension-name.js +6 -0
- package/server/lib/pi/session-daemon/extension-name.test.js +5 -0
- package/server/lib/pi/session-daemon/extension-palette.js +146 -0
- package/server/lib/pi/session-daemon/extension-palette.test.js +107 -0
- package/server/lib/pi/session-daemon/extension-replacements.js +138 -0
- package/server/lib/pi/session-daemon/extension-replacements.test.js +116 -0
- package/server/lib/pi/session-daemon/extension-ui-mode.js +30 -0
- package/server/lib/pi/session-daemon/extension-ui-mode.test.js +34 -0
- package/server/lib/pi/session-daemon/pichamber-ui.js +44 -0
- package/server/lib/pi/session-daemon/plugin-host.js +245 -0
- package/server/lib/pi/session-daemon/plugin-host.test.js +192 -0
- package/server/lib/pi/session-daemon/session-daemon-controls.e2e.test.js +205 -0
- package/server/lib/pi/session-daemon/session-daemon-drafts.e2e.test.js +409 -0
- package/server/lib/pi/session-daemon/session-daemon-extension-config.e2e.test.js +196 -0
- package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +137 -6
- package/server/lib/pi/session-daemon/session-daemon-plugins.e2e.test.js +272 -0
- package/server/lib/pi/session-daemon/session-daemon-providers.e2e.test.js +153 -0
- package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
- package/server/lib/pi/session-daemon/session-daemon.js +927 -108
- package/server/lib/pi/session-daemon/session-daemon.test.js +391 -4
- package/server/lib/pi/session-daemon/session-engine-router.js +7 -0
- package/server/lib/pi/session-daemon/session-engine-router.test.js +20 -0
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
- package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
- package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
- package/server/lib/pi/session-daemon/session-lease.js +93 -15
- package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
- package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
- package/server/lib/pi/session-daemon/supervisor.js +408 -38
- package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
- package/server/lib/pi/settings-store.js +14 -0
- package/server/lib/pi/settings-store.test.js +11 -0
- package/server/lib/pi/ui-settings-store.js +88 -2
- package/server/lib/pi/ui-settings-store.test.js +118 -0
- package/server/lib/plugins/DOCUMENTATION.md +198 -0
- package/server/lib/plugins/daemon-sync.js +88 -0
- package/server/lib/plugins/daemon-sync.supervisor.test.js +83 -0
- package/server/lib/plugins/daemon-sync.test.js +108 -0
- package/server/lib/plugins/impact.js +139 -0
- package/server/lib/plugins/impact.test.js +83 -0
- package/server/lib/plugins/manifest.js +220 -0
- package/server/lib/plugins/manifest.test.js +127 -0
- package/server/lib/plugins/registry.js +59 -0
- package/server/lib/plugins/routes.js +92 -0
- package/server/lib/plugins/routes.test.js +247 -0
- package/server/lib/plugins/service.js +183 -0
- package/server/lib/plugins/store.js +261 -0
- package/server/lib/plugins/store.test.js +188 -0
- package/server/lib/plugins/visuals-extension.test.js +237 -0
- package/server/lib/server/cross-process-lock.js +28 -3
- package/server/lib/server-browser/DOCUMENTATION.md +32 -7
- package/server/lib/server-browser/browser-tab.js +4 -1
- package/server/lib/server-browser/downloads.js +261 -34
- package/server/lib/server-browser/downloads.test.js +171 -0
- package/server/lib/server-browser/runtime.integration.test.js +47 -0
- package/server/lib/server-browser/runtime.js +16 -0
- package/server/lib/server-browser/server-browser.js +25 -6
- package/server/lib/tunnels/executable-search.js +5 -1
- package/server/lib/tunnels/executable-search.test.js +26 -0
- package/dist/assets/DiagramView-BB-aZobi.js +0 -1
- package/dist/assets/FileSaveConflictDialog-Bzz8FNMq.js +0 -3
- package/dist/assets/FilesView-DECxN8Z0.js +0 -6
- package/dist/assets/GitHubDetailScaffold-CWsWycRd.js +0 -11
- package/dist/assets/GitHubLinkPicker-BVYdg_e8.js +0 -1
- package/dist/assets/GitHubListPrimitives-Dlv3tC4d.js +0 -1
- package/dist/assets/PatchDiff-BklyOEHs.js +0 -1
- package/dist/assets/PierreDiffViewer-wc6cB6qw.js +0 -147
- package/dist/assets/PullRequestsSurface-BZvJkT1I.js +0 -2
- package/dist/assets/SessionSwitcherDropdown-DShvvGwC.js +0 -2
- package/dist/assets/SessionUnreadDot-CbqRq6h_.js +0 -1
- package/dist/assets/SettingsView-DcF-At5E.js +0 -6
- package/dist/assets/ToolOutputDialog-DdMIfrnK.js +0 -8
- package/dist/assets/ToolPartDiffPreview-C6Sm4eVf.js +0 -1
- package/dist/assets/contextFileOpenGuard-UU86YHgI.js +0 -1
- package/dist/assets/gitStatusPredicates-DQEO4Psc.js +0 -1
- package/dist/assets/githubLink-ByPAyFjh.js +0 -10
- package/dist/assets/index-BaLCg7tL.css +0 -1
- package/dist/assets/index-I2QYqABE.js +0 -11
- package/dist/assets/main-DyFfbllq.js +0 -137
- package/dist/assets/pi-session-focus-preference-Dx0UXPoO.js +0 -9
- package/dist/assets/renderElectronMiniChatApp-Cb7s7dWl.js +0 -2
- package/dist/assets/renderMobileApp-Bp74b_Lo.js +0 -11
- package/dist/assets/runtimeEndpointReset-7nWYnKd4.js +0 -62
- package/dist/assets/runtimeSurface-CFwnvks_.js +0 -1
- package/dist/assets/useAppFontEffects-ZTyNwFk6.js +0 -213
- package/dist/assets/useGitHubRemoteSearch-BF3ohpsh.js +0 -1
- package/dist/assets/useSwitcherItems-BJzwyDGX.js +0 -1
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { access, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { spawn as spawnChildProcess } from 'node:child_process';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
import { createPiSessionDaemonSupervisor } from './supervisor.js';
|
|
9
|
+
|
|
10
|
+
const DAEMON_ENTRYPOINT = fileURLToPath(new URL('./daemon-process.js', import.meta.url));
|
|
11
|
+
const SERVER_PID = 1000;
|
|
12
|
+
const LAUNCHER_PID = 4242;
|
|
13
|
+
const DAEMON_PID = 4243;
|
|
14
|
+
// A process the sandbox would like the server to kill (the server itself,
|
|
15
|
+
// the main daemon, anything the user owns).
|
|
16
|
+
const VICTIM_PID = 777;
|
|
17
|
+
|
|
18
|
+
const exists = async (file) => access(file).then(() => true, () => false);
|
|
19
|
+
|
|
20
|
+
const argValue = (args, flag) => args[args.indexOf(flag) + 1];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* A fake host: a process table, a launcher that wraps the daemon command, and
|
|
24
|
+
* a daemon whose health answer echoes whatever its state sidecar says, the
|
|
25
|
+
* way a sandboxed daemon under an attacker's control would.
|
|
26
|
+
*/
|
|
27
|
+
const createWorld = async ({ withLauncher = true } = {}) => {
|
|
28
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-launcher-stop-'));
|
|
29
|
+
const dataDir = join(root, 'data');
|
|
30
|
+
// Short on purpose: nothing binds it, but the path must stay local.
|
|
31
|
+
const runtimeDir = await mkdtemp('/tmp/pls-');
|
|
32
|
+
const processes = new Map([
|
|
33
|
+
[1, { identity: 'start:1', alive: true }],
|
|
34
|
+
[SERVER_PID, { identity: 'start:1000', alive: true }],
|
|
35
|
+
[VICTIM_PID, { identity: 'start:777', alive: true }],
|
|
36
|
+
]);
|
|
37
|
+
const signals = [];
|
|
38
|
+
const requests = [];
|
|
39
|
+
const processLike = {
|
|
40
|
+
pid: SERVER_PID,
|
|
41
|
+
execPath: '/opt/node/bin/node',
|
|
42
|
+
versions: { node: '24.0.0' },
|
|
43
|
+
kill(pid, signal) {
|
|
44
|
+
if (signal !== 0) signals.push([pid, signal]);
|
|
45
|
+
const entry = processes.get(pid);
|
|
46
|
+
if (!entry?.alive) {
|
|
47
|
+
const error = new Error('ESRCH');
|
|
48
|
+
error.code = 'ESRCH';
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
if (signal === 'SIGTERM' && (pid === LAUNCHER_PID || pid === DAEMON_PID)) {
|
|
52
|
+
// The launcher forwards SIGTERM to the daemon and exits after it.
|
|
53
|
+
for (const own of [LAUNCHER_PID, DAEMON_PID]) {
|
|
54
|
+
if (processes.has(own)) processes.get(own).alive = false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const readProcessIdentity = async (pid) => {
|
|
61
|
+
const entry = processes.get(pid);
|
|
62
|
+
return entry?.alive ? entry.identity : null;
|
|
63
|
+
};
|
|
64
|
+
let stateFile;
|
|
65
|
+
const spawn = (command, args) => {
|
|
66
|
+
const daemonArgs = withLauncher ? args.slice(1) : args;
|
|
67
|
+
stateFile = argValue(daemonArgs, '--state-file');
|
|
68
|
+
processes.set(LAUNCHER_PID, { identity: 'start:4242', alive: true });
|
|
69
|
+
processes.set(DAEMON_PID, { identity: 'start:4243', alive: true });
|
|
70
|
+
const state = {
|
|
71
|
+
protocolVersion: 1,
|
|
72
|
+
pid: withLauncher ? DAEMON_PID : LAUNCHER_PID,
|
|
73
|
+
endpoint: argValue(daemonArgs, '--endpoint'),
|
|
74
|
+
profileKey: argValue(daemonArgs, '--profile-key'),
|
|
75
|
+
serverInstanceId: argValue(daemonArgs, '--server-instance-id'),
|
|
76
|
+
serverPid: Number(argValue(daemonArgs, '--server-pid')),
|
|
77
|
+
daemonId: argValue(daemonArgs, '--daemon-id'),
|
|
78
|
+
buildId: argValue(daemonArgs, '--build-id'),
|
|
79
|
+
entrypoint: DAEMON_ENTRYPOINT,
|
|
80
|
+
startedAt: new Date().toISOString(),
|
|
81
|
+
};
|
|
82
|
+
void mkdir(dirname(stateFile), { recursive: true }).then(() => writeFile(stateFile, JSON.stringify(state)));
|
|
83
|
+
return { pid: LAUNCHER_PID, unref() {}, once() {} };
|
|
84
|
+
};
|
|
85
|
+
const request = async ({ command, payload }) => {
|
|
86
|
+
requests.push({ command, payload });
|
|
87
|
+
const daemonAlive = processes.get(DAEMON_PID)?.alive && processes.get(LAUNCHER_PID)?.alive;
|
|
88
|
+
if (!daemonAlive || !stateFile) {
|
|
89
|
+
const error = new Error('refused');
|
|
90
|
+
error.code = 'DAEMON_CONNECTION_REFUSED';
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
const state = JSON.parse(await readFile(stateFile, 'utf8'));
|
|
94
|
+
if (command === 'runtime.health') {
|
|
95
|
+
return {
|
|
96
|
+
state: 'ready',
|
|
97
|
+
daemonPid: state.pid,
|
|
98
|
+
profileKey: state.profileKey,
|
|
99
|
+
daemonId: state.daemonId,
|
|
100
|
+
serverInstanceId: state.serverInstanceId,
|
|
101
|
+
serverPid: state.serverPid,
|
|
102
|
+
buildId: state.buildId,
|
|
103
|
+
capabilities: [],
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// runtime.shutdown is acknowledged but the daemon keeps running, so the
|
|
107
|
+
// stop has to fall back to the signal.
|
|
108
|
+
return {};
|
|
109
|
+
};
|
|
110
|
+
const supervisor = createPiSessionDaemonSupervisor({
|
|
111
|
+
env: { PATH: process.env.PATH, PICHAMBER_DATA_DIR: dataDir, XDG_RUNTIME_DIR: runtimeDir },
|
|
112
|
+
dataDir,
|
|
113
|
+
port: 3000,
|
|
114
|
+
cwd: root,
|
|
115
|
+
platform: 'linux',
|
|
116
|
+
processLike,
|
|
117
|
+
request,
|
|
118
|
+
spawn,
|
|
119
|
+
wait: async () => {},
|
|
120
|
+
startupTimeoutMs: 200,
|
|
121
|
+
daemonReadyTimeoutMs: 2_000,
|
|
122
|
+
readProcessIdentity,
|
|
123
|
+
...(withLauncher
|
|
124
|
+
? { launch: async ({ command, args, env }) => ({ command: '/usr/bin/fake-launcher', args: [command, ...args], env }) }
|
|
125
|
+
: {}),
|
|
126
|
+
});
|
|
127
|
+
const forgeState = async (changes) => {
|
|
128
|
+
const state = JSON.parse(await readFile(supervisor.paths.stateFile, 'utf8'));
|
|
129
|
+
await writeFile(supervisor.paths.stateFile, JSON.stringify({ ...state, ...changes }));
|
|
130
|
+
};
|
|
131
|
+
return { root, dataDir, processes, signals, requests, supervisor, forgeState };
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
describe('launcher daemon stop', () => {
|
|
135
|
+
it('keeps the launcher record and operation lock outside the profile folder the sandbox can write', async () => {
|
|
136
|
+
const world = await createWorld();
|
|
137
|
+
const { paths } = world.supervisor;
|
|
138
|
+
expect(paths.lockFile).toBe(join(world.dataDir, 'pi', 'launchers', paths.profileKey, 'operation.lock'));
|
|
139
|
+
expect(paths.launcherFile).toBe(join(world.dataDir, 'pi', 'launchers', paths.profileKey, 'launcher.json'));
|
|
140
|
+
expect(paths.lockFile.startsWith(`${paths.profileDir}/`)).toBe(false);
|
|
141
|
+
|
|
142
|
+
await expect(world.supervisor.start()).resolves.toMatchObject({ state: 'ready', reused: false });
|
|
143
|
+
expect(JSON.parse(await readFile(paths.launcherFile, 'utf8'))).toMatchObject({
|
|
144
|
+
pid: LAUNCHER_PID,
|
|
145
|
+
identity: 'start:4242',
|
|
146
|
+
profileKey: paths.profileKey,
|
|
147
|
+
serverInstanceId: paths.serverInstanceId,
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('never signals a foreign pid written into the state sidecar', async () => {
|
|
152
|
+
const world = await createWorld();
|
|
153
|
+
await world.supervisor.start();
|
|
154
|
+
// The sandbox rewrites its sidecar; the health answer echoes it.
|
|
155
|
+
await world.forgeState({ pid: VICTIM_PID });
|
|
156
|
+
|
|
157
|
+
await expect(world.supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
158
|
+
expect(world.signals.filter(([pid]) => pid === VICTIM_PID)).toEqual([]);
|
|
159
|
+
expect(world.processes.get(VICTIM_PID).alive).toBe(true);
|
|
160
|
+
expect(world.signals).toEqual([[LAUNCHER_PID, 'SIGTERM']]);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('asks for the authenticated shutdown, then signals the recorded launcher and removes its record', async () => {
|
|
164
|
+
const world = await createWorld();
|
|
165
|
+
await world.supervisor.start();
|
|
166
|
+
|
|
167
|
+
await expect(world.supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
168
|
+
expect(world.requests.map(({ command }) => command)).toContain('runtime.shutdown');
|
|
169
|
+
expect(world.signals).toEqual([[LAUNCHER_PID, 'SIGTERM']]);
|
|
170
|
+
expect(world.processes.get(LAUNCHER_PID).alive).toBe(false);
|
|
171
|
+
expect(await exists(world.supervisor.paths.launcherFile)).toBe(false);
|
|
172
|
+
expect(await exists(world.supervisor.paths.stateFile)).toBe(false);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('stops the recorded launcher even when the sandbox removed its credential and sidecar', async () => {
|
|
176
|
+
const world = await createWorld();
|
|
177
|
+
await world.supervisor.start();
|
|
178
|
+
await rm(world.supervisor.paths.credentialFile);
|
|
179
|
+
await rm(world.supervisor.paths.stateFile);
|
|
180
|
+
|
|
181
|
+
await expect(world.supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
182
|
+
expect(world.signals).toEqual([[LAUNCHER_PID, 'SIGTERM']]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('signals nothing when the recorded pid now belongs to another process', async () => {
|
|
186
|
+
const world = await createWorld();
|
|
187
|
+
await world.supervisor.start();
|
|
188
|
+
// The launcher exited and its pid went to an unrelated process.
|
|
189
|
+
world.processes.set(LAUNCHER_PID, { identity: 'start:9999', alive: true });
|
|
190
|
+
world.processes.get(DAEMON_PID).alive = false;
|
|
191
|
+
|
|
192
|
+
await expect(world.supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
193
|
+
expect(world.signals).toEqual([]);
|
|
194
|
+
expect(world.processes.get(LAUNCHER_PID).alive).toBe(true);
|
|
195
|
+
expect(await exists(world.supervisor.paths.launcherFile)).toBe(false);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it('signals nothing for a launcher daemon without a record, whatever its sidecar says', async () => {
|
|
199
|
+
const world = await createWorld();
|
|
200
|
+
await world.supervisor.start();
|
|
201
|
+
await rm(world.supervisor.paths.launcherFile);
|
|
202
|
+
await world.forgeState({ pid: VICTIM_PID });
|
|
203
|
+
|
|
204
|
+
// The victim stays alive, so the wait for the forged pid times out.
|
|
205
|
+
await expect(world.supervisor.stop()).rejects.toMatchObject({ code: 'DAEMON_STOP_TIMEOUT' });
|
|
206
|
+
expect(world.signals).toEqual([]);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('refuses to stop a launcher daemon whose record names another server instance', async () => {
|
|
210
|
+
const world = await createWorld();
|
|
211
|
+
await world.supervisor.start();
|
|
212
|
+
const record = JSON.parse(await readFile(world.supervisor.paths.launcherFile, 'utf8'));
|
|
213
|
+
await writeFile(world.supervisor.paths.launcherFile, JSON.stringify({ ...record, serverInstanceId: 'newer-instance' }));
|
|
214
|
+
|
|
215
|
+
await expect(world.supervisor.stop()).rejects.toMatchObject({ code: 'DAEMON_OWNERSHIP_MISMATCH' });
|
|
216
|
+
expect(world.signals).toEqual([]);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('is not blocked by an operation lock planted in the profile folder', async () => {
|
|
220
|
+
const world = await createWorld();
|
|
221
|
+
const { paths } = world.supervisor;
|
|
222
|
+
await mkdir(paths.profileDir, { recursive: true });
|
|
223
|
+
// pid 1 is alive, so this lock would never be stolen.
|
|
224
|
+
await writeFile(join(paths.profileDir, 'operation.lock'), JSON.stringify({ pid: 1 }));
|
|
225
|
+
|
|
226
|
+
await expect(world.supervisor.start()).resolves.toMatchObject({ state: 'ready' });
|
|
227
|
+
await expect(world.supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
228
|
+
expect(world.signals).toEqual([[LAUNCHER_PID, 'SIGTERM']]);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('does not start a second daemon beside a recorded launcher that is still running', async () => {
|
|
232
|
+
const world = await createWorld();
|
|
233
|
+
await world.supervisor.start();
|
|
234
|
+
// The daemon stops answering and its sidecar is gone, but the launcher runs.
|
|
235
|
+
world.processes.get(DAEMON_PID).alive = false;
|
|
236
|
+
await rm(world.supervisor.paths.stateFile);
|
|
237
|
+
|
|
238
|
+
await expect(world.supervisor.start()).rejects.toMatchObject({ code: 'DAEMON_UNAVAILABLE' });
|
|
239
|
+
expect(world.signals).toEqual([]);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
describe.runIf(process.platform === 'linux')('launcher identity on Linux', () => {
|
|
244
|
+
it('records a real launcher by its /proc start time', async () => {
|
|
245
|
+
const root = await mkdtemp(join(tmpdir(), 'pichamber-launcher-identity-'));
|
|
246
|
+
const dataDir = join(root, 'data');
|
|
247
|
+
const runtimeDir = await mkdtemp('/tmp/pli-');
|
|
248
|
+
let child;
|
|
249
|
+
const supervisor = createPiSessionDaemonSupervisor({
|
|
250
|
+
env: { PATH: process.env.PATH, PICHAMBER_DATA_DIR: dataDir, XDG_RUNTIME_DIR: runtimeDir },
|
|
251
|
+
dataDir,
|
|
252
|
+
port: 3000,
|
|
253
|
+
cwd: root,
|
|
254
|
+
platform: 'linux',
|
|
255
|
+
// A stand-in launcher that never answers, so the start times out and
|
|
256
|
+
// signals the child it spawned.
|
|
257
|
+
spawn: (_command, _args, options) => {
|
|
258
|
+
child = spawnChildProcess('sleep', ['30'], { ...options, stdio: 'ignore' });
|
|
259
|
+
return child;
|
|
260
|
+
},
|
|
261
|
+
request: async () => {
|
|
262
|
+
const error = new Error('refused');
|
|
263
|
+
error.code = 'DAEMON_CONNECTION_REFUSED';
|
|
264
|
+
throw error;
|
|
265
|
+
},
|
|
266
|
+
wait: (ms) => new Promise((resolveWait) => setTimeout(resolveWait, ms)),
|
|
267
|
+
startupTimeoutMs: 500,
|
|
268
|
+
daemonReadyTimeoutMs: 300,
|
|
269
|
+
launch: async ({ command, args, env }) => ({ command, args, env }),
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
await expect(supervisor.start()).rejects.toMatchObject({ code: 'DAEMON_START_TIMEOUT' });
|
|
273
|
+
const record = JSON.parse(await readFile(supervisor.paths.launcherFile, 'utf8'));
|
|
274
|
+
const stat = await readFile(`/proc/${child.pid}/stat`, 'utf8').catch(() => '');
|
|
275
|
+
expect(record.pid).toBe(child.pid);
|
|
276
|
+
expect(record.identity).toMatch(/^linux-start:\d+$/);
|
|
277
|
+
if (stat) expect(record.identity).toBe(`linux-start:${stat.slice(stat.lastIndexOf(')') + 2).split(' ')[19]}`);
|
|
278
|
+
child.kill('SIGKILL');
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe('main daemon stop', () => {
|
|
283
|
+
it('still signals the pid in its state sidecar and keeps its lock in the profile folder', async () => {
|
|
284
|
+
const world = await createWorld({ withLauncher: false });
|
|
285
|
+
const { paths } = world.supervisor;
|
|
286
|
+
expect(paths.lockFile).toBe(join(paths.profileDir, 'operation.lock'));
|
|
287
|
+
expect(paths.launcherFile).toBeUndefined();
|
|
288
|
+
|
|
289
|
+
await world.supervisor.start();
|
|
290
|
+
await expect(world.supervisor.stop()).resolves.toEqual({ state: 'stopped' });
|
|
291
|
+
expect(world.requests.map(({ command }) => command)).toContain('runtime.shutdown');
|
|
292
|
+
expect(world.signals).toEqual([[LAUNCHER_PID, 'SIGTERM']]);
|
|
293
|
+
expect(await exists(join(world.dataDir, 'pi', 'launchers'))).toBe(false);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { createServer as createHttpServer } from 'node:http';
|
|
4
|
+
import { createServer as createNetServer } from 'node:net';
|
|
5
|
+
import { homedir, tmpdir } from 'node:os';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
|
|
8
|
+
import { createOpenUrlIntake } from '../../open-url/intake.js';
|
|
9
|
+
import { createNonoLauncher } from '../sandbox/nono-launcher.js';
|
|
10
|
+
import { prepareProjectSandbox } from '../sandbox/project-sandbox.js';
|
|
11
|
+
import { getPiSessionDirectory } from './session-jsonl.js';
|
|
12
|
+
import { readSessionLeaseOwner } from './session-lease.js';
|
|
13
|
+
import { createSandboxedPiSessionDaemonSupervisor } from './supervisor.js';
|
|
14
|
+
|
|
15
|
+
// Runs only where nono can sandbox: Linux or WSL2 with Landlock, or macOS,
|
|
16
|
+
// with nono >= 0.82.0. Linux CI and the development container have no
|
|
17
|
+
// Landlock, so this skips there; the macOS CI job runs it. Run it on a
|
|
18
|
+
// Landlock machine before a release.
|
|
19
|
+
const probe = await createNonoLauncher().probe();
|
|
20
|
+
// WSL2 cannot mediate pathname Unix sockets (nono-launcher.js HOST_LIMITS).
|
|
21
|
+
const unixSocketsMediated = !probe.limits?.includes('UNIX_SOCKETS');
|
|
22
|
+
|
|
23
|
+
// Run inside the sandbox by the turn's bash tool: exits 0 when the attempt
|
|
24
|
+
// succeeds.
|
|
25
|
+
const PROBE_SCRIPT = `
|
|
26
|
+
import { connect } from 'node:net';
|
|
27
|
+
const [kind, target] = process.argv.slice(2);
|
|
28
|
+
const done = (ok) => process.exit(ok ? 0 : 1);
|
|
29
|
+
setTimeout(() => done(false), 8000);
|
|
30
|
+
const socket = kind === 'unix' ? connect(target) : connect(Number(target.split(':')[1]), target.split(':')[0]);
|
|
31
|
+
socket.on('connect', () => done(true)).on('error', () => done(false));
|
|
32
|
+
`;
|
|
33
|
+
|
|
34
|
+
const listen = (server, ...args) => new Promise((resolve) => server.listen(...args, () => resolve(server)));
|
|
35
|
+
|
|
36
|
+
// CI sets this where nono must work, so a broken probe fails instead of
|
|
37
|
+
// skipping the suite.
|
|
38
|
+
describe.runIf(process.env.PICHAMBER_REQUIRE_NONO_E2E === '1')('nono on a host that requires the e2e test', () => {
|
|
39
|
+
it('can sandbox', () => {
|
|
40
|
+
expect(probe).toMatchObject({ available: true });
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// The faux model answers the first prompt with one bash tool call carrying
|
|
45
|
+
// the prompt text as its command, then with plain text.
|
|
46
|
+
const EXTENSION = `
|
|
47
|
+
import { fauxProvider, fauxAssistantMessage, fauxToolCall } from '@earendil-works/pi-ai';
|
|
48
|
+
|
|
49
|
+
const lastUserText = (context) => {
|
|
50
|
+
const message = [...context.messages].reverse().find((entry) => entry.role === 'user');
|
|
51
|
+
if (!message) return '';
|
|
52
|
+
return typeof message.content === 'string'
|
|
53
|
+
? message.content
|
|
54
|
+
: message.content.map((part) => part.text || '').join('');
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default function (pi) {
|
|
58
|
+
const faux = fauxProvider({
|
|
59
|
+
provider: 'sandbox-mock-provider',
|
|
60
|
+
models: [{
|
|
61
|
+
id: 'sandbox-mock-model',
|
|
62
|
+
name: 'Sandbox Mock Model',
|
|
63
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
64
|
+
contextWindow: 16384,
|
|
65
|
+
maxTokens: 2048,
|
|
66
|
+
}],
|
|
67
|
+
tokensPerSecond: 1000,
|
|
68
|
+
});
|
|
69
|
+
faux.setResponses([
|
|
70
|
+
(context) => fauxAssistantMessage(
|
|
71
|
+
[fauxToolCall('bash', { command: lastUserText(context) }, { id: 'call-sandbox-1' })],
|
|
72
|
+
{ stopReason: 'toolUse' },
|
|
73
|
+
),
|
|
74
|
+
() => fauxAssistantMessage('done'),
|
|
75
|
+
]);
|
|
76
|
+
pi.registerProvider(faux.provider);
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
|
|
80
|
+
const waitForFile = async (path, timeoutMs = 60_000) => {
|
|
81
|
+
const deadline = Date.now() + timeoutMs;
|
|
82
|
+
while (Date.now() < deadline) {
|
|
83
|
+
try {
|
|
84
|
+
const text = await readFile(path, 'utf8');
|
|
85
|
+
if (text.includes('END')) return text;
|
|
86
|
+
} catch {
|
|
87
|
+
// not written yet
|
|
88
|
+
}
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
90
|
+
}
|
|
91
|
+
throw new Error(`Timed out waiting for ${path}`);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// The test's HOME holds nono's state folder (~/.local/state/nono), which
|
|
95
|
+
// nono refuses to start inside a folder its profile grants. macOS's temp
|
|
96
|
+
// folder sits under /private/var, which nono's macOS system group grants, so
|
|
97
|
+
// on macOS the test works under the real home, as a real home would be.
|
|
98
|
+
const testRootParent = process.platform === 'darwin' ? homedir() : tmpdir();
|
|
99
|
+
const roots = [];
|
|
100
|
+
const makeRoot = async () => {
|
|
101
|
+
const root = await mkdtemp(join(testRootParent, process.platform === 'darwin' ? '.pichamber-nono-e2e-' : 'pichamber-nono-e2e-'));
|
|
102
|
+
roots.push(root);
|
|
103
|
+
return root;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
describe.skipIf(!probe.available)('sandboxed daemon under real nono', () => {
|
|
107
|
+
let supervisor;
|
|
108
|
+
let intake;
|
|
109
|
+
|
|
110
|
+
afterEach(async () => {
|
|
111
|
+
await intake?.stop().catch(() => {});
|
|
112
|
+
intake = undefined;
|
|
113
|
+
await supervisor?.stop().catch(() => {});
|
|
114
|
+
supervisor = undefined;
|
|
115
|
+
// Kept on failure in CI, whose log step reads the daemon logs.
|
|
116
|
+
if (!process.env.CI) await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true, force: true })));
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('lets a turn\'s bash tool write in the project and denies everything outside it', async () => {
|
|
120
|
+
const root = await makeRoot();
|
|
121
|
+
const home = join(root, 'home');
|
|
122
|
+
const agentDir = join(home, '.pi', 'agent');
|
|
123
|
+
const dataDir = join(root, 'data');
|
|
124
|
+
const project = join(root, 'code', 'projA');
|
|
125
|
+
const otherProject = join(root, 'code', 'projB');
|
|
126
|
+
const outside = join(root, 'outside');
|
|
127
|
+
await Promise.all([
|
|
128
|
+
mkdir(join(agentDir, 'extensions'), { recursive: true }),
|
|
129
|
+
mkdir(project, { recursive: true }),
|
|
130
|
+
mkdir(otherProject, { recursive: true }),
|
|
131
|
+
mkdir(outside, { recursive: true }),
|
|
132
|
+
]);
|
|
133
|
+
await writeFile(join(agentDir, 'extensions', 'sandbox-mock.ts'), EXTENSION);
|
|
134
|
+
const settings = JSON.stringify({ defaultProvider: 'sandbox-mock-provider', defaultModel: 'sandbox-mock-model' });
|
|
135
|
+
await writeFile(join(agentDir, 'settings.json'), settings);
|
|
136
|
+
await writeFile(join(agentDir, 'auth.json'), JSON.stringify({
|
|
137
|
+
'sandbox-mock-provider': { type: 'api_key', key: 'faux-test-key' },
|
|
138
|
+
}));
|
|
139
|
+
const otherSessions = getPiSessionDirectory({ cwd: otherProject, agentDir });
|
|
140
|
+
await mkdir(otherSessions, { recursive: true });
|
|
141
|
+
await writeFile(join(otherSessions, 'other.jsonl'), '{"type":"session"}\n');
|
|
142
|
+
// Stand-in for the main daemon's credential in the same data folder.
|
|
143
|
+
const mainCredential = join(dataDir, 'pi', 'daemons', 'web-p3000', 'session-daemon.key');
|
|
144
|
+
await mkdir(join(dataDir, 'pi', 'daemons', 'web-p3000'), { recursive: true });
|
|
145
|
+
await writeFile(mainCredential, 'main-daemon-credential\n');
|
|
146
|
+
const sharedLeases = join(agentDir, '.pichamber', 'locks', 'sessions');
|
|
147
|
+
await mkdir(sharedLeases, { recursive: true });
|
|
148
|
+
// The user's cache folders, so a refused write is the sandbox's doing.
|
|
149
|
+
await mkdir(join(home, '.cache'), { recursive: true });
|
|
150
|
+
await mkdir(join(home, 'Library', 'Caches'), { recursive: true });
|
|
151
|
+
|
|
152
|
+
const env = {
|
|
153
|
+
...process.env,
|
|
154
|
+
HOME: home,
|
|
155
|
+
PI_OFFLINE: '1',
|
|
156
|
+
PICHAMBER_DATA_DIR: dataDir,
|
|
157
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
158
|
+
// The server's own secret, which must not reach the sandbox.
|
|
159
|
+
PICHAMBER_UI_PASSWORD: 'server-ui-password',
|
|
160
|
+
// Short on purpose: the daemon socket path must fit a Unix socket address.
|
|
161
|
+
XDG_RUNTIME_DIR: await mkdtemp('/tmp/pcx-'),
|
|
162
|
+
};
|
|
163
|
+
// Local services outside the sandbox: a Unix socket (like the systemd
|
|
164
|
+
// user manager's or Docker's) and a loopback TCP server (like PiChamber's).
|
|
165
|
+
const outsideSocket = join(outside, 'service.sock');
|
|
166
|
+
const unixServer = await listen(createNetServer(), outsideSocket);
|
|
167
|
+
const tcpServer = await listen(createHttpServer((_request, response) => response.end('ok')), 0, '127.0.0.1');
|
|
168
|
+
// A local port the project allows (like a local model server).
|
|
169
|
+
const grantedServer = await listen(createHttpServer((_request, response) => response.end('ok')), 0, '127.0.0.1');
|
|
170
|
+
const grantedPort = grantedServer.address().port;
|
|
171
|
+
const probeFile = join(project, 'probe.mjs');
|
|
172
|
+
await writeFile(probeFile, PROBE_SCRIPT);
|
|
173
|
+
|
|
174
|
+
const sandbox = await prepareProjectSandbox({
|
|
175
|
+
dataDir, agentDir, projectRoot: project, serverPort: 3000, allowLocalPorts: [grantedPort],
|
|
176
|
+
});
|
|
177
|
+
supervisor = await createSandboxedPiSessionDaemonSupervisor({ env, port: 3000, launcher: createNonoLauncher(), sandbox });
|
|
178
|
+
await supervisor.start();
|
|
179
|
+
|
|
180
|
+
const results = join(project, 'results.txt');
|
|
181
|
+
const check = (name, command) => `if sh -c '${command}' >/dev/null 2>&1; then echo ${name}=allowed; else echo ${name}=denied; fi >> ${results}`;
|
|
182
|
+
const script = [
|
|
183
|
+
check('project', `echo x > ${join(project, 'inside.txt')}`),
|
|
184
|
+
check('outside', `echo x > ${join(outside, 'w.txt')}`),
|
|
185
|
+
check('otherSessionsRead', `cat ${join(otherSessions, 'other.jsonl')}`),
|
|
186
|
+
check('otherSessionsWrite', `echo x > ${join(otherSessions, 'planted.jsonl')}`),
|
|
187
|
+
check('otherProject', `ls ${otherProject}`),
|
|
188
|
+
check('piSettings', `echo pwn >> ${join(agentDir, 'settings.json')}`),
|
|
189
|
+
check('piExtensions', `mkdir ${join(agentDir, 'extensions', 'evil')}`),
|
|
190
|
+
// The session links the server makes: readable through the shadow,
|
|
191
|
+
// never changed from inside.
|
|
192
|
+
check('sessionLinks', `ln -s ${outside} ${join(dataDir, 'pi', 'sandbox', sandbox.projectKey, 'sessions', 'planted')}`),
|
|
193
|
+
check('mainCredential', `cat ${mainCredential}`),
|
|
194
|
+
// Its own credential is the server's file: readable (the daemon
|
|
195
|
+
// started on it), never writable or replaceable.
|
|
196
|
+
check('ownCredentialWrite', `echo x >> ${supervisor.paths.credentialFile}`),
|
|
197
|
+
check('ownCredentialReplace', `rm ${supervisor.paths.credentialFile}`),
|
|
198
|
+
check('serverSecret', 'test -n "$PICHAMBER_UI_PASSWORD"'),
|
|
199
|
+
// Other projects' live session leases.
|
|
200
|
+
check('sharedLeases', `ls ${sharedLeases}`),
|
|
201
|
+
// The user's cache folders are not the sandbox's; it has its own.
|
|
202
|
+
check('userCache', `echo x > "$HOME/.cache/probe" || echo x > "$HOME/Library/Caches/probe"`),
|
|
203
|
+
check('ownCache', `echo x > "$XDG_CACHE_HOME/probe"`),
|
|
204
|
+
check('unixOutside', `node ${probeFile} unix ${outsideSocket}`),
|
|
205
|
+
check('tcpLoopback', `node ${probeFile} tcp 127.0.0.1:${tcpServer.address().port}`),
|
|
206
|
+
check('tcpGranted', `node ${probeFile} tcp 127.0.0.1:${grantedPort}`),
|
|
207
|
+
`echo END >> ${results}`,
|
|
208
|
+
].join('; ');
|
|
209
|
+
|
|
210
|
+
const created = await supervisor.request('sessions.create', { cwd: project });
|
|
211
|
+
await supervisor.request('sessions.prompt', { sessionId: created.session.id, text: script });
|
|
212
|
+
const text = await waitForFile(results);
|
|
213
|
+
unixServer.close();
|
|
214
|
+
tcpServer.close();
|
|
215
|
+
grantedServer.close();
|
|
216
|
+
|
|
217
|
+
expect(text).toContain('project=allowed');
|
|
218
|
+
expect(text).toContain('outside=denied');
|
|
219
|
+
expect(text).toContain('otherSessionsRead=denied');
|
|
220
|
+
expect(text).toContain('otherSessionsWrite=denied');
|
|
221
|
+
expect(text).toContain('otherProject=denied');
|
|
222
|
+
expect(text).toContain('piSettings=denied');
|
|
223
|
+
expect(text).toContain('piExtensions=denied');
|
|
224
|
+
expect(text).toContain('sessionLinks=denied');
|
|
225
|
+
expect(text).toContain('mainCredential=denied');
|
|
226
|
+
expect(text).toContain('ownCredentialWrite=denied');
|
|
227
|
+
expect(text).toContain('ownCredentialReplace=denied');
|
|
228
|
+
expect(text).toContain('serverSecret=denied');
|
|
229
|
+
expect(text).toContain('sharedLeases=denied');
|
|
230
|
+
expect(text).toContain('userCache=denied');
|
|
231
|
+
expect(text).toContain('ownCache=allowed');
|
|
232
|
+
expect(text).toContain('tcpLoopback=denied');
|
|
233
|
+
expect(text).toContain('tcpGranted=allowed');
|
|
234
|
+
// The limit a WSL2 owner accepts: the socket is reachable there.
|
|
235
|
+
expect(text).toContain(unixSocketsMediated ? 'unixOutside=denied' : 'unixOutside=allowed');
|
|
236
|
+
await expect(readFile(join(agentDir, 'settings.json'), 'utf8')).resolves.toBe(settings);
|
|
237
|
+
// The transcript, written through the shadow's links, is in Pi's real
|
|
238
|
+
// session folder.
|
|
239
|
+
const realSessions = getPiSessionDirectory({ cwd: project, agentDir });
|
|
240
|
+
const deadline = Date.now() + 30_000;
|
|
241
|
+
let transcripts = [];
|
|
242
|
+
while (Date.now() < deadline) {
|
|
243
|
+
transcripts = (await readdir(realSessions)).filter((name) => name.endsWith('.jsonl'));
|
|
244
|
+
if (transcripts.length > 0) break;
|
|
245
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
246
|
+
}
|
|
247
|
+
expect(transcripts).toHaveLength(1);
|
|
248
|
+
}, 120_000);
|
|
249
|
+
|
|
250
|
+
it('keys its session lease on the real agent folder and reaches its own Open request intake', async () => {
|
|
251
|
+
const root = await makeRoot();
|
|
252
|
+
const home = join(root, 'home');
|
|
253
|
+
const agentDir = join(home, '.pi', 'agent');
|
|
254
|
+
const dataDir = join(root, 'data');
|
|
255
|
+
const project = join(root, 'code', 'projA');
|
|
256
|
+
await Promise.all([
|
|
257
|
+
mkdir(join(agentDir, 'extensions'), { recursive: true }),
|
|
258
|
+
mkdir(project, { recursive: true }),
|
|
259
|
+
]);
|
|
260
|
+
await writeFile(join(agentDir, 'extensions', 'sandbox-mock.ts'), EXTENSION);
|
|
261
|
+
await writeFile(join(agentDir, 'settings.json'), JSON.stringify({ defaultProvider: 'sandbox-mock-provider', defaultModel: 'sandbox-mock-model' }));
|
|
262
|
+
await writeFile(join(agentDir, 'auth.json'), JSON.stringify({
|
|
263
|
+
'sandbox-mock-provider': { type: 'api_key', key: 'faux-test-key' },
|
|
264
|
+
}));
|
|
265
|
+
const env = {
|
|
266
|
+
...process.env,
|
|
267
|
+
HOME: home,
|
|
268
|
+
PI_OFFLINE: '1',
|
|
269
|
+
PICHAMBER_DATA_DIR: dataDir,
|
|
270
|
+
PICHAMBER_PI_AGENT_DIR: agentDir,
|
|
271
|
+
XDG_RUNTIME_DIR: await mkdtemp('/tmp/pcx-'),
|
|
272
|
+
};
|
|
273
|
+
const sandbox = await prepareProjectSandbox({ dataDir, agentDir, projectRoot: project, serverPort: 3000 });
|
|
274
|
+
supervisor = await createSandboxedPiSessionDaemonSupervisor({ env, port: 3000, launcher: createNonoLauncher(), sandbox });
|
|
275
|
+
const published = [];
|
|
276
|
+
intake = createOpenUrlIntake({
|
|
277
|
+
socketPath: supervisor.paths.openUrlSocket,
|
|
278
|
+
publish: async (payload) => {
|
|
279
|
+
published.push(payload);
|
|
280
|
+
return { published: true };
|
|
281
|
+
},
|
|
282
|
+
hasConnectedDevices: () => true,
|
|
283
|
+
});
|
|
284
|
+
await intake.start();
|
|
285
|
+
await supervisor.start();
|
|
286
|
+
|
|
287
|
+
const results = join(project, 'results.txt');
|
|
288
|
+
const script = `"$BROWSER" https://example.test/from-sandbox >/dev/null 2>&1; echo END >> ${results}`;
|
|
289
|
+
const created = await supervisor.request('sessions.create', { cwd: project });
|
|
290
|
+
await supervisor.request('sessions.prompt', { sessionId: created.session.id, text: script });
|
|
291
|
+
await waitForFile(results);
|
|
292
|
+
|
|
293
|
+
// The lease sits in the project's own lease folder under the real agent
|
|
294
|
+
// folder, where a daemon outside the sandbox looks before it takes the
|
|
295
|
+
// session.
|
|
296
|
+
await expect(readSessionLeaseOwner({ agentDir, cwd: project, sessionId: created.session.id, scope: sandbox.leaseScope }))
|
|
297
|
+
.resolves.toMatchObject({ profileKey: supervisor.paths.profileKey });
|
|
298
|
+
await expect(readSessionLeaseOwner({ agentDir, cwd: project, sessionId: created.session.id })).resolves.toBeNull();
|
|
299
|
+
expect(published).toContainEqual(expect.objectContaining({ url: 'https://example.test/from-sandbox' }));
|
|
300
|
+
}, 120_000);
|
|
301
|
+
});
|