@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,122 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { posix } from 'node:path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sandbox launcher contract (see ../session-daemon/DOCUMENTATION.md).
|
|
6
|
+
*
|
|
7
|
+
* A launcher turns a daemon launch request into a command:
|
|
8
|
+
*
|
|
9
|
+
* {
|
|
10
|
+
* id, platforms, transport: 'local-socket',
|
|
11
|
+
* probe(): Promise<{ available: true, version, capabilities, limits? } | { available: false, code }>,
|
|
12
|
+
* identity({ grants, network }): string,
|
|
13
|
+
* prepare({ argv, env, cwd, grants, network, tmpDir }): Promise<{ command, args, env, cleanup? }>,
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* Grants are structured, never raw user strings:
|
|
17
|
+
* { kind: 'read' | 'readWrite', path } folder, recursive
|
|
18
|
+
* { kind: 'readFile' | 'readWriteFile', path } single file
|
|
19
|
+
* { kind: 'unixSocketBind', dir } bind sockets in a folder
|
|
20
|
+
* Network:
|
|
21
|
+
* { mode: 'proxy', allowHosts: string[], allowLocalPorts: number[] } | { mode: 'none' }
|
|
22
|
+
*
|
|
23
|
+
* `limits` names what the sandbox cannot enforce on this host, from
|
|
24
|
+
* `SANDBOX_LIMIT_CODES`. A host with limits runs sandboxes only after its
|
|
25
|
+
* owner accepts every one of them (`sandboxDefaults.acceptedLimits`).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/** What a launcher may report it cannot enforce on a host.
|
|
29
|
+
* UNIX_SOCKETS: pathname Unix sockets are not mediated (nono on WSL2).
|
|
30
|
+
* PROXY_PORT: connections on the proxy's port are not held to the proxy, so
|
|
31
|
+
* they reach any host (nono on WSL2). */
|
|
32
|
+
export const SANDBOX_LIMIT_CODES = Object.freeze(['UNIX_SOCKETS', 'PROXY_PORT']);
|
|
33
|
+
|
|
34
|
+
export class SandboxLaunchError extends Error {
|
|
35
|
+
constructor(code) {
|
|
36
|
+
super('The sandbox launch request is invalid.');
|
|
37
|
+
this.code = code;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const GRANT_KINDS = new Set(['read', 'readWrite', 'readFile', 'readWriteFile', 'unixSocketBind']);
|
|
42
|
+
const HOST_PATTERN = /^(\*\.)?[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/;
|
|
43
|
+
|
|
44
|
+
// Hosts a sandboxed agent may reach through nono's proxy. The PiChamber
|
|
45
|
+
// server's own API is on the same machine, so anything that could name it
|
|
46
|
+
// (loopback, local names, raw IPs) is refused, as are names too broad or
|
|
47
|
+
// too long to be public host names.
|
|
48
|
+
const isRefusedHost = (value) => {
|
|
49
|
+
const name = value.startsWith('*.') ? value.slice(2) : value;
|
|
50
|
+
if (value.length > 253) return true;
|
|
51
|
+
const labels = name.split('.');
|
|
52
|
+
// One label (`localhost`, `com`), or one label under a wildcard (`*.com`).
|
|
53
|
+
if (labels.length < 2) return true;
|
|
54
|
+
if (labels.some((label) => label.length > 63)) return true;
|
|
55
|
+
if (name === 'localhost' || name.endsWith('.localhost') || name.endsWith('.local')) return true;
|
|
56
|
+
// IP literals in any spelling a resolver takes (`127.0.0.1`, `1.2.3.0x4`):
|
|
57
|
+
// no public top-level name starts with a digit.
|
|
58
|
+
if (/^\d/.test(labels[labels.length - 1])) return true;
|
|
59
|
+
return false;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** Whether `host` is a name `normalizeNetwork` accepts as an allowed host. */
|
|
63
|
+
export const isAllowedSandboxHost = (host) => {
|
|
64
|
+
const value = typeof host === 'string' ? host.trim().toLowerCase() : '';
|
|
65
|
+
return HOST_PATTERN.test(value) && !isRefusedHost(value);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const normalizePath = (value) => {
|
|
69
|
+
if (typeof value !== 'string' || !value.startsWith('/') || /[\0\n\r]/.test(value)) {
|
|
70
|
+
throw new SandboxLaunchError('SANDBOX_INVALID_GRANT');
|
|
71
|
+
}
|
|
72
|
+
const normalized = posix.normalize(value);
|
|
73
|
+
return normalized.length > 1 ? normalized.replace(/\/+$/, '') : normalized;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/** Validated, de-duplicated grants in a stable order. */
|
|
77
|
+
export const normalizeGrants = (grants) => {
|
|
78
|
+
if (!Array.isArray(grants)) throw new SandboxLaunchError('SANDBOX_INVALID_GRANT');
|
|
79
|
+
const seen = new Map();
|
|
80
|
+
for (const grant of grants) {
|
|
81
|
+
if (!grant || !GRANT_KINDS.has(grant.kind)) throw new SandboxLaunchError('SANDBOX_INVALID_GRANT');
|
|
82
|
+
const path = normalizePath(grant.kind === 'unixSocketBind' ? grant.dir : grant.path);
|
|
83
|
+
seen.set(`${grant.kind}\0${path}`, { kind: grant.kind, path });
|
|
84
|
+
}
|
|
85
|
+
return [...seen.values()].sort((a, b) => (a.kind === b.kind
|
|
86
|
+
? (a.path < b.path ? -1 : a.path > b.path ? 1 : 0)
|
|
87
|
+
: (a.kind < b.kind ? -1 : 1)));
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export const normalizeNetwork = (network) => {
|
|
91
|
+
if (network?.mode === 'none') return { mode: 'none' };
|
|
92
|
+
if (network?.mode !== 'proxy') throw new SandboxLaunchError('SANDBOX_INVALID_NETWORK');
|
|
93
|
+
const hosts = (network.allowHosts ?? []).map((host) => {
|
|
94
|
+
if (!isAllowedSandboxHost(host)) throw new SandboxLaunchError('SANDBOX_INVALID_NETWORK');
|
|
95
|
+
return host.trim().toLowerCase();
|
|
96
|
+
});
|
|
97
|
+
const ports = (network.allowLocalPorts ?? []).map((port) => {
|
|
98
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new SandboxLaunchError('SANDBOX_INVALID_NETWORK');
|
|
99
|
+
return port;
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
mode: 'proxy',
|
|
103
|
+
allowHosts: [...new Set(hosts)].sort(),
|
|
104
|
+
allowLocalPorts: [...new Set(ports)].sort((a, b) => a - b),
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Short hash of everything that shapes a sandbox: launcher, its version, its
|
|
110
|
+
* policy file, grants and network. It goes into the daemon profile key, so a
|
|
111
|
+
* change in any of them starts a new daemon instead of reusing an old one.
|
|
112
|
+
*/
|
|
113
|
+
export const launchIdentity = ({ launcher, version, profile, grants, network }) => createHash('sha256')
|
|
114
|
+
.update(JSON.stringify({
|
|
115
|
+
launcher,
|
|
116
|
+
version,
|
|
117
|
+
profile,
|
|
118
|
+
grants: normalizeGrants(grants),
|
|
119
|
+
network: normalizeNetwork(network),
|
|
120
|
+
}))
|
|
121
|
+
.digest('hex')
|
|
122
|
+
.slice(0, 12);
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { normalizeNetwork, SandboxLaunchError } from './launcher.js';
|
|
4
|
+
|
|
5
|
+
const allowHosts = (allowHosts) =>
|
|
6
|
+
normalizeNetwork({ mode: 'proxy', allowHosts, allowLocalPorts: [] }).allowHosts;
|
|
7
|
+
|
|
8
|
+
const expectRefused = (host) => {
|
|
9
|
+
let error;
|
|
10
|
+
try {
|
|
11
|
+
allowHosts([host]);
|
|
12
|
+
} catch (cause) {
|
|
13
|
+
error = cause;
|
|
14
|
+
}
|
|
15
|
+
expect(error).toBeInstanceOf(SandboxLaunchError);
|
|
16
|
+
expect(error?.code).toBe('SANDBOX_INVALID_NETWORK');
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
describe('normalizeNetwork hosts', () => {
|
|
20
|
+
it('accepts ordinary public host names and wildcards with two or more labels', () => {
|
|
21
|
+
expect(allowHosts([
|
|
22
|
+
'api.anthropic.com',
|
|
23
|
+
'registry.npmjs.org',
|
|
24
|
+
'*.githubusercontent.com',
|
|
25
|
+
'index.rubygems.org',
|
|
26
|
+
'npm.jsr.io',
|
|
27
|
+
'repo.maven.apache.org',
|
|
28
|
+
'proxy.golang.org',
|
|
29
|
+
])).toEqual([
|
|
30
|
+
'*.githubusercontent.com',
|
|
31
|
+
'api.anthropic.com',
|
|
32
|
+
'index.rubygems.org',
|
|
33
|
+
'npm.jsr.io',
|
|
34
|
+
'proxy.golang.org',
|
|
35
|
+
'registry.npmjs.org',
|
|
36
|
+
'repo.maven.apache.org',
|
|
37
|
+
]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('accepts a 63-character label', () => {
|
|
41
|
+
expect(allowHosts([`${'a'.repeat(63)}.com`])).toEqual([`${'a'.repeat(63)}.com`]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('lowercases, trims, de-duplicates and sorts hosts', () => {
|
|
45
|
+
expect(allowHosts([' GitHub.com ', 'github.com', 'api.github.com', 'GITHUB.COM'])).toEqual([
|
|
46
|
+
'api.github.com',
|
|
47
|
+
'github.com',
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('refuses one-label names', () => {
|
|
52
|
+
for (const host of ['localhost', 'com', 'myserver', 'LocalHost']) expectRefused(host);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('refuses localhost and .local names', () => {
|
|
56
|
+
for (const host of ['foo.localhost', '*.localhost', 'printer.local', 'myserver.local']) {
|
|
57
|
+
expectRefused(host);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('refuses IPv4 literals and names ending in a number', () => {
|
|
62
|
+
for (const host of ['127.0.0.1', '10.0.0.5', '1.2.3.4', 'example.123', '1.2.3.0x4', '0x7f.0.0.1']) expectRefused(host);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('refuses wildcards wider than *.example.com', () => {
|
|
66
|
+
expectRefused('*.com');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('refuses malformed names', () => {
|
|
70
|
+
for (const host of ['', 'https://x', 'a..b', '-bad.com', 'bad-.com', 'under_score.com', '*.']) {
|
|
71
|
+
expectRefused(host);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('refuses a label above 63 characters or a name above 253 characters', () => {
|
|
76
|
+
expectRefused(`${'a'.repeat(64)}.com`);
|
|
77
|
+
expectRefused(Array(5).fill('a'.repeat(50)).join('.'));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('keeps refusing non-proxy and malformed network values', () => {
|
|
81
|
+
expect(normalizeNetwork({ mode: 'none' })).toEqual({ mode: 'none' });
|
|
82
|
+
expect(() => normalizeNetwork({})).toThrowError(expect.objectContaining({ code: 'SANDBOX_INVALID_NETWORK' }));
|
|
83
|
+
expect(() => normalizeNetwork({ mode: 'proxy', allowHosts: ['ok.example.com'], allowLocalPorts: [0] }))
|
|
84
|
+
.toThrowError(expect.objectContaining({ code: 'SANDBOX_INVALID_NETWORK' }));
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('sorts and de-duplicates local ports', () => {
|
|
88
|
+
expect(normalizeNetwork({ mode: 'proxy', allowHosts: [], allowLocalPorts: [11434, 8080, 8080] }))
|
|
89
|
+
.toEqual({ mode: 'proxy', allowHosts: [], allowLocalPorts: [8080, 11434] });
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { execFile as execFileCallback } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { closeSync, constants as fsConstants, fstatSync, openSync, readFileSync, readSync } from 'node:fs';
|
|
4
|
+
import { chmod, mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
import { launchIdentity, normalizeGrants, normalizeNetwork, SandboxLaunchError } from './launcher.js';
|
|
9
|
+
|
|
10
|
+
const NONO_MIN_VERSION = '0.82.0';
|
|
11
|
+
// Landlock V4 filters TCP. Below it nono cannot hold a WSL2 sandbox to its
|
|
12
|
+
// proxy (WSL2 also lacks the seccomp fallback), so domain rules would not
|
|
13
|
+
// be enforced.
|
|
14
|
+
const MIN_WSL2_LANDLOCK_ABI = 4;
|
|
15
|
+
export const NONO_PROFILE_FILE = fileURLToPath(new URL('./nono-profile.json', import.meta.url));
|
|
16
|
+
// One policy per host kind. WSL2 drops `linux.af_unix_mediation`, which
|
|
17
|
+
// needs seccomp user notification and makes nono refuse to start there;
|
|
18
|
+
// macOS uses Seatbelt's groups and paths.
|
|
19
|
+
export const NONO_PROFILE_FILES = Object.freeze({
|
|
20
|
+
linux: NONO_PROFILE_FILE,
|
|
21
|
+
wsl2: fileURLToPath(new URL('./nono-profile-wsl2.json', import.meta.url)),
|
|
22
|
+
macos: fileURLToPath(new URL('./nono-profile-macos.json', import.meta.url)),
|
|
23
|
+
});
|
|
24
|
+
// What the sandbox cannot enforce on each host kind. WSL2 has no seccomp
|
|
25
|
+
// user notification (init holds the only listener), so:
|
|
26
|
+
// - pathname Unix sockets stay reachable, and code in the sandbox can ask a
|
|
27
|
+
// local service (systemd user manager, D-Bus, an agent or Docker socket) to
|
|
28
|
+
// act outside it;
|
|
29
|
+
// - Landlock filters TCP by port only, and nono's seccomp check of the
|
|
30
|
+
// destination is missing, so the proxy's port is open to every host.
|
|
31
|
+
const HOST_LIMITS = Object.freeze({ linux: [], wsl2: ['UNIX_SOCKETS', 'PROXY_PORT'], macos: [] });
|
|
32
|
+
const WSL_PATTERN = /microsoft|wsl/i;
|
|
33
|
+
|
|
34
|
+
const PROBE_TIMEOUT_MS = 10_000;
|
|
35
|
+
const PROBE_ENV = { NONO_NO_UPDATE_CHECK: '1', NONO_NO_SAVE_PROMPT: '1' };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Point the tools an agent runs at the sandbox's own cache folder. The
|
|
39
|
+
* profiles grant no user cache folder (`~/.cache`, `~/Library/Caches`):
|
|
40
|
+
* what is cached there is run later by tools outside the sandbox. Tools
|
|
41
|
+
* that follow `XDG_CACHE_HOME` need nothing else; the rest are named.
|
|
42
|
+
*/
|
|
43
|
+
const cacheEnv = (cacheDir) => ({
|
|
44
|
+
XDG_CACHE_HOME: cacheDir,
|
|
45
|
+
npm_config_cache: join(cacheDir, 'npm'),
|
|
46
|
+
YARN_CACHE_FOLDER: join(cacheDir, 'yarn'),
|
|
47
|
+
BUN_INSTALL_CACHE_DIR: join(cacheDir, 'bun'),
|
|
48
|
+
COREPACK_HOME: join(cacheDir, 'node', 'corepack'),
|
|
49
|
+
PIP_CACHE_DIR: join(cacheDir, 'pip'),
|
|
50
|
+
UV_CACHE_DIR: join(cacheDir, 'uv'),
|
|
51
|
+
PRE_COMMIT_HOME: join(cacheDir, 'pre-commit'),
|
|
52
|
+
GOCACHE: join(cacheDir, 'go-build'),
|
|
53
|
+
PLAYWRIGHT_BROWSERS_PATH: join(cacheDir, 'ms-playwright'),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const runFile = (execFile, command, args, env) => new Promise((resolve) => {
|
|
57
|
+
execFile(command, args, { env, timeout: PROBE_TIMEOUT_MS, windowsHide: true }, (error, stdout, stderr) => {
|
|
58
|
+
resolve({
|
|
59
|
+
error,
|
|
60
|
+
code: error ? (typeof error.code === 'number' ? error.code : null) : 0,
|
|
61
|
+
spawnCode: error && typeof error.code === 'string' ? error.code : null,
|
|
62
|
+
stdout: `${stdout ?? ''}`,
|
|
63
|
+
output: `${stdout ?? ''}\n${stderr ?? ''}`,
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const parseVersion = (output) => {
|
|
69
|
+
const match = /\bnono\s+v?(\d+)\.(\d+)\.(\d+)\b/i.exec(output);
|
|
70
|
+
return match ? [Number(match[1]), Number(match[2]), Number(match[3])] : null;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const compareVersions = (left, right) => {
|
|
74
|
+
for (let index = 0; index < 3; index += 1) {
|
|
75
|
+
if (left[index] !== right[index]) return left[index] - right[index];
|
|
76
|
+
}
|
|
77
|
+
return 0;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const defaultReadProcVersion = async () => {
|
|
81
|
+
try {
|
|
82
|
+
return await readFile('/proc/version', 'utf8');
|
|
83
|
+
} catch {
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// Electron reads files inside app.asar through its patched fs; nono is a
|
|
89
|
+
// separate binary and sees only the archive file.
|
|
90
|
+
const ASAR_SEGMENT = /[\\/][^\\/]+\.asar(?:[\\/]|$)/i;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The profile path to hand nono. A profile inside an asar archive (packaged
|
|
94
|
+
* desktop) is copied to a real file under `stageDir`, named by its content
|
|
95
|
+
* hash so a changed policy never reuses an old copy.
|
|
96
|
+
*/
|
|
97
|
+
const createProfileResolver = ({ profileFile, profileContent, profileHash, stageDir }) => {
|
|
98
|
+
if (!ASAR_SEGMENT.test(profileFile)) return async () => profileFile;
|
|
99
|
+
// One staging at a time: concurrent first launches would share the
|
|
100
|
+
// temporary file and the second rename would fail. A failure is retried.
|
|
101
|
+
let staging = null;
|
|
102
|
+
const stage = async () => {
|
|
103
|
+
if (typeof stageDir !== 'string' || !stageDir.startsWith('/')) {
|
|
104
|
+
throw new SandboxLaunchError('SANDBOX_PROFILE_UNREADABLE');
|
|
105
|
+
}
|
|
106
|
+
try {
|
|
107
|
+
await mkdir(stageDir, { recursive: true, mode: 0o700 });
|
|
108
|
+
const target = join(stageDir, `nono-profile-${profileHash.slice(0, 12)}.json`);
|
|
109
|
+
const temporary = `${target}.${process.pid}.tmp`;
|
|
110
|
+
await writeFile(temporary, profileContent, { mode: 0o600 });
|
|
111
|
+
await chmod(temporary, 0o600);
|
|
112
|
+
await rename(temporary, target);
|
|
113
|
+
return target;
|
|
114
|
+
} catch {
|
|
115
|
+
throw new SandboxLaunchError('SANDBOX_PROFILE_UNREADABLE');
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
return () => {
|
|
119
|
+
staging ??= stage().catch((error) => {
|
|
120
|
+
staging = null;
|
|
121
|
+
throw error;
|
|
122
|
+
});
|
|
123
|
+
return staging;
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const GRANT_FLAGS = {
|
|
128
|
+
read: '--read',
|
|
129
|
+
readWrite: '--allow',
|
|
130
|
+
readFile: '--read-file',
|
|
131
|
+
readWriteFile: '--allow-file',
|
|
132
|
+
unixSocketBind: '--allow-unix-socket-dir-bind',
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// On Linux a connect-port grant applies to that port on every host and
|
|
136
|
+
// bypasses the proxy for it, so the web ports would defeat the host allowlist.
|
|
137
|
+
const REFUSED_PORTS = new Set([80, 443]);
|
|
138
|
+
|
|
139
|
+
const networkFlags = (network, hostKind) => {
|
|
140
|
+
if (network.mode === 'none') return ['--block-net'];
|
|
141
|
+
for (const port of network.allowLocalPorts) {
|
|
142
|
+
if (REFUSED_PORTS.has(port)) throw new SandboxLaunchError('SANDBOX_PORT_REFUSED');
|
|
143
|
+
}
|
|
144
|
+
const hosts = network.allowHosts.flatMap((host) => ['--allow-domain', host]);
|
|
145
|
+
if (hostKind === 'macos') {
|
|
146
|
+
// Seatbelt cannot filter TCP by port, so nono refuses
|
|
147
|
+
// `--allow-connect-port` there. `--open-port` allows that port on
|
|
148
|
+
// localhost only; Seatbelt then allows binding and inbound connections
|
|
149
|
+
// on any port. Blocked mode keeps those localhost rules, so with no
|
|
150
|
+
// allowed host the network is still blocked apart from the ports.
|
|
151
|
+
const ports = network.allowLocalPorts.flatMap((port) => ['--open-port', String(port)]);
|
|
152
|
+
return hosts.length > 0 ? [...hosts, ...ports] : ['--block-net', ...ports];
|
|
153
|
+
}
|
|
154
|
+
const ports = network.allowLocalPorts.flatMap((port) => ['--allow-connect-port', String(port)]);
|
|
155
|
+
if (hosts.length > 0) return [...hosts, ...ports];
|
|
156
|
+
// Without an allowed host nono starts no proxy. Port grants alone still
|
|
157
|
+
// limit TCP to those ports; with neither, nothing may leave the sandbox.
|
|
158
|
+
return ports.length > 0 ? ports : ['--block-net'];
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const loadProfile = (profileFile, stageDir) => {
|
|
162
|
+
const profileContent = readFileSync(profileFile);
|
|
163
|
+
const profileHash = createHash('sha256').update(profileContent).digest('hex');
|
|
164
|
+
return {
|
|
165
|
+
file: profileFile,
|
|
166
|
+
content: profileContent.toString('utf8'),
|
|
167
|
+
hash: profileHash,
|
|
168
|
+
resolve: createProfileResolver({ profileFile, profileContent, profileHash, stageDir }),
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// A profile is a few hundred bytes of policy; anything near this is not one.
|
|
173
|
+
const NONO_PROFILE_MAX_BYTES = 64 * 1024;
|
|
174
|
+
const MAX_PROFILE_MESSAGES = 8;
|
|
175
|
+
const MAX_PROFILE_MESSAGE_LENGTH = 600;
|
|
176
|
+
|
|
177
|
+
/** A custom profile that cannot be used. `messages` are for the owner: what
|
|
178
|
+
* nono (or the JSON parser) said is wrong with the text. */
|
|
179
|
+
class NonoProfileError extends Error {
|
|
180
|
+
constructor(messages = []) {
|
|
181
|
+
super('The nono profile is not valid.');
|
|
182
|
+
this.name = 'NonoProfileError';
|
|
183
|
+
this.code = 'INVALID_SANDBOX_PROFILE';
|
|
184
|
+
this.messages = messages
|
|
185
|
+
.filter((message) => typeof message === 'string' && message.trim().length > 0)
|
|
186
|
+
.slice(0, MAX_PROFILE_MESSAGES)
|
|
187
|
+
.map((message) => message.trim().slice(0, MAX_PROFILE_MESSAGE_LENGTH));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The owner's custom profile, or null when there is none. Read as a small
|
|
193
|
+
* regular file and never through a symlink. A file that is there but cannot
|
|
194
|
+
* be read this way throws: the launcher then refuses to start a sandbox
|
|
195
|
+
* instead of quietly using the built-in profile the owner replaced.
|
|
196
|
+
*/
|
|
197
|
+
const readCustomProfile = (file) => {
|
|
198
|
+
let handle;
|
|
199
|
+
try {
|
|
200
|
+
handle = openSync(file, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW | fsConstants.O_NONBLOCK);
|
|
201
|
+
} catch (error) {
|
|
202
|
+
if (error?.code === 'ENOENT') return null;
|
|
203
|
+
throw new SandboxLaunchError('SANDBOX_PROFILE_INVALID');
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const stats = fstatSync(handle);
|
|
207
|
+
if (!stats.isFile() || stats.size > NONO_PROFILE_MAX_BYTES) throw new SandboxLaunchError('SANDBOX_PROFILE_INVALID');
|
|
208
|
+
const buffer = Buffer.alloc(stats.size);
|
|
209
|
+
let read = 0;
|
|
210
|
+
while (read < buffer.length) {
|
|
211
|
+
const count = readSync(handle, buffer, read, buffer.length - read, read);
|
|
212
|
+
if (count === 0) break;
|
|
213
|
+
read += count;
|
|
214
|
+
}
|
|
215
|
+
const content = buffer.subarray(0, read);
|
|
216
|
+
return { content: content.toString('utf8'), hash: createHash('sha256').update('custom\n').update(content).digest('hex') };
|
|
217
|
+
} catch (error) {
|
|
218
|
+
if (error instanceof SandboxLaunchError) throw error;
|
|
219
|
+
throw new SandboxLaunchError('SANDBOX_PROFILE_INVALID');
|
|
220
|
+
} finally {
|
|
221
|
+
closeSync(handle);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const isJsonObject = (text) => {
|
|
226
|
+
try {
|
|
227
|
+
const value = JSON.parse(text);
|
|
228
|
+
return Boolean(value) && typeof value === 'object' && !Array.isArray(value);
|
|
229
|
+
} catch {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* nono launcher: runs the daemon under `nono run` with PiChamber's static
|
|
236
|
+
* profile for this host kind (Linux, WSL2 or macOS). Every path arrives as a
|
|
237
|
+
* per-launch flag built from structured grants; the profile file holds only
|
|
238
|
+
* policy.
|
|
239
|
+
*/
|
|
240
|
+
export const createNonoLauncher = ({
|
|
241
|
+
command = 'nono',
|
|
242
|
+
platform = process.platform,
|
|
243
|
+
execFile = execFileCallback,
|
|
244
|
+
readProcVersion = defaultReadProcVersion,
|
|
245
|
+
profileFiles = NONO_PROFILE_FILES,
|
|
246
|
+
// One file for every host kind (tests).
|
|
247
|
+
profileFile,
|
|
248
|
+
// A real folder for the profile copy when a profile sits inside an asar
|
|
249
|
+
// archive (`<dataDir>/pi/sandbox`).
|
|
250
|
+
stageDir,
|
|
251
|
+
// The owner's own profile, used in place of the built-in one while the
|
|
252
|
+
// file exists (`<dataDir>/pi/sandbox/nono-profile.custom.json`). It must
|
|
253
|
+
// sit where no sandbox can write.
|
|
254
|
+
customProfileFile,
|
|
255
|
+
env = process.env,
|
|
256
|
+
} = {}) => {
|
|
257
|
+
const profiles = new Map(Object.keys(HOST_LIMITS).map((hostKind) => [
|
|
258
|
+
hostKind,
|
|
259
|
+
loadProfile(profileFile ?? profileFiles[hostKind], stageDir),
|
|
260
|
+
]));
|
|
261
|
+
const profileFor = (hostKind) => profiles.get(hostKind);
|
|
262
|
+
// Set by a successful probe: the nono version and the host kind whose
|
|
263
|
+
// profile every launch uses.
|
|
264
|
+
let probed = null;
|
|
265
|
+
// Custom profile hashes nono has accepted, so a launch checks each text once.
|
|
266
|
+
const acceptedCustom = new Set();
|
|
267
|
+
|
|
268
|
+
const detectHostKind = async () => (platform === 'darwin'
|
|
269
|
+
? 'macos'
|
|
270
|
+
: platform === 'linux'
|
|
271
|
+
? (WSL_PATTERN.test(await readProcVersion()) ? 'wsl2' : 'linux')
|
|
272
|
+
: null);
|
|
273
|
+
|
|
274
|
+
/** The profile launches use: the custom file while it exists. */
|
|
275
|
+
const activeProfile = (hostKind) => {
|
|
276
|
+
const custom = customProfileFile ? readCustomProfile(customProfileFile) : null;
|
|
277
|
+
return custom
|
|
278
|
+
? { custom: true, hash: custom.hash, content: custom.content, resolve: async () => customProfileFile }
|
|
279
|
+
: { custom: false, ...profileFor(hostKind) };
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Ask nono whether a profile file is valid. `null` when nono could not
|
|
284
|
+
* answer (not installed, or output that is not its report), otherwise
|
|
285
|
+
* `{ valid, messages }`.
|
|
286
|
+
*/
|
|
287
|
+
const validateProfileFile = async (file) => {
|
|
288
|
+
const run = await runFile(execFile, command, ['profile', 'validate', '--json', file], { ...env, ...PROBE_ENV });
|
|
289
|
+
if (run.spawnCode) return null;
|
|
290
|
+
let report;
|
|
291
|
+
try {
|
|
292
|
+
report = JSON.parse(run.stdout);
|
|
293
|
+
} catch {
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
if (typeof report?.valid !== 'boolean') return null;
|
|
297
|
+
return { valid: report.valid, messages: Array.isArray(report.errors) ? report.errors : [] };
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const probe = async () => {
|
|
301
|
+
probed = null;
|
|
302
|
+
const hostKind = await detectHostKind();
|
|
303
|
+
if (!hostKind) return { available: false, code: 'UNSUPPORTED_PLATFORM' };
|
|
304
|
+
|
|
305
|
+
const probeEnv = { ...env, ...PROBE_ENV };
|
|
306
|
+
const versionRun = await runFile(execFile, command, ['--version'], probeEnv);
|
|
307
|
+
if (versionRun.spawnCode === 'ENOENT') return { available: false, code: 'NOT_INSTALLED' };
|
|
308
|
+
if (versionRun.error) return { available: false, code: 'VERSION_UNKNOWN' };
|
|
309
|
+
const version = parseVersion(versionRun.output);
|
|
310
|
+
if (!version) return { available: false, code: 'VERSION_UNKNOWN' };
|
|
311
|
+
if (compareVersions(version, NONO_MIN_VERSION.split('.').map(Number)) < 0) {
|
|
312
|
+
return { available: false, code: 'TOO_OLD' };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const setupRun = await runFile(execFile, command, ['setup', '--check-only'], probeEnv);
|
|
316
|
+
let capability;
|
|
317
|
+
if (hostKind === 'macos') {
|
|
318
|
+
if (setupRun.code !== 0 || !/Seatbelt sandbox support verified/i.test(setupRun.output)) {
|
|
319
|
+
return { available: false, code: 'SETUP_CHECK_FAILED' };
|
|
320
|
+
}
|
|
321
|
+
capability = 'seatbelt';
|
|
322
|
+
} else {
|
|
323
|
+
if (setupRun.code !== 0) {
|
|
324
|
+
return { available: false, code: /landlock is not available/i.test(setupRun.output) ? 'NO_LANDLOCK' : 'SETUP_CHECK_FAILED' };
|
|
325
|
+
}
|
|
326
|
+
const abi = /Landlock V(\d+)/.exec(setupRun.output);
|
|
327
|
+
if (!abi) return { available: false, code: 'NO_LANDLOCK' };
|
|
328
|
+
if (hostKind === 'wsl2' && Number(abi[1]) < MIN_WSL2_LANDLOCK_ABI) return { available: false, code: 'WSL_KERNEL_TOO_OLD' };
|
|
329
|
+
capability = `landlock-abi-${abi[1]}`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
probed = { version: version.join('.'), hostKind };
|
|
333
|
+
const limits = HOST_LIMITS[hostKind];
|
|
334
|
+
return {
|
|
335
|
+
available: true,
|
|
336
|
+
version: probed.version,
|
|
337
|
+
capabilities: [capability],
|
|
338
|
+
...(limits.length > 0 ? { limits: [...limits] } : {}),
|
|
339
|
+
};
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const requireProbe = () => {
|
|
343
|
+
if (!probed) throw new SandboxLaunchError('SANDBOX_NOT_PROBED');
|
|
344
|
+
return probed;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
const identity = (request) => {
|
|
348
|
+
const { version, hostKind } = requireProbe();
|
|
349
|
+
return launchIdentity({
|
|
350
|
+
launcher: 'nono',
|
|
351
|
+
version,
|
|
352
|
+
profile: activeProfile(hostKind).hash,
|
|
353
|
+
grants: request.grants,
|
|
354
|
+
network: request.network,
|
|
355
|
+
});
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const prepare = async ({ argv, env: childEnv = {}, grants, network, tmpDir, cacheDir }) => {
|
|
359
|
+
const { hostKind } = requireProbe();
|
|
360
|
+
if (!Array.isArray(argv) || argv.length === 0) throw new SandboxLaunchError('SANDBOX_INVALID_COMMAND');
|
|
361
|
+
if (typeof tmpDir !== 'string' || !tmpDir.startsWith('/')) throw new SandboxLaunchError('SANDBOX_INVALID_GRANT');
|
|
362
|
+
if (cacheDir !== undefined && (typeof cacheDir !== 'string' || !cacheDir.startsWith('/'))) throw new SandboxLaunchError('SANDBOX_INVALID_GRANT');
|
|
363
|
+
const grantFlags = normalizeGrants(grants).flatMap((grant) => [GRANT_FLAGS[grant.kind], grant.path]);
|
|
364
|
+
const profile = activeProfile(hostKind);
|
|
365
|
+
if (profile.custom && !acceptedCustom.has(profile.hash)) {
|
|
366
|
+
// Edited on disk since nono last saw it: a profile nono refuses must
|
|
367
|
+
// read as a profile problem, not as a daemon that failed to start.
|
|
368
|
+
const report = isJsonObject(profile.content) ? await validateProfileFile(customProfileFile) : { valid: false };
|
|
369
|
+
if (report && !report.valid) throw new SandboxLaunchError('SANDBOX_PROFILE_INVALID');
|
|
370
|
+
if (report) acceptedCustom.add(profile.hash);
|
|
371
|
+
}
|
|
372
|
+
const readableProfile = await profile.resolve();
|
|
373
|
+
return {
|
|
374
|
+
command,
|
|
375
|
+
args: [
|
|
376
|
+
'run', '-s', '--profile', readableProfile, '--no-rollback', '--no-audit', '--no-diagnostics',
|
|
377
|
+
...grantFlags,
|
|
378
|
+
...networkFlags(normalizeNetwork(network), hostKind),
|
|
379
|
+
'--', ...argv,
|
|
380
|
+
],
|
|
381
|
+
env: { ...childEnv, ...(cacheDir ? cacheEnv(cacheDir) : {}), NONO_NO_SAVE_PROMPT: '1', NONO_NO_UPDATE_CHECK: '1', TMPDIR: tmpDir },
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* The profile in use on this host, for Settings: the built-in file for
|
|
387
|
+
* this host kind, the custom file's place, which of them launches use, and
|
|
388
|
+
* that one's text. Null on a platform nono does not run on.
|
|
389
|
+
*/
|
|
390
|
+
const profile = async () => {
|
|
391
|
+
const hostKind = probed?.hostKind ?? await detectHostKind();
|
|
392
|
+
if (!hostKind) return null;
|
|
393
|
+
const builtIn = profileFor(hostKind);
|
|
394
|
+
const base = { hostKind, builtInPath: builtIn.file, customPath: customProfileFile ?? null };
|
|
395
|
+
let custom;
|
|
396
|
+
try {
|
|
397
|
+
custom = customProfileFile ? readCustomProfile(customProfileFile) : null;
|
|
398
|
+
} catch {
|
|
399
|
+
// There, but not a file PiChamber will read: sandboxes do not start.
|
|
400
|
+
return { ...base, custom: true, unreadable: true, path: customProfileFile, content: '', hash: 'unreadable' };
|
|
401
|
+
}
|
|
402
|
+
return custom
|
|
403
|
+
? { ...base, custom: true, path: customProfileFile, content: custom.content, hash: custom.hash }
|
|
404
|
+
: { ...base, custom: false, path: builtIn.file, content: builtIn.content, hash: builtIn.hash };
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Save the owner's profile text as the custom profile. Refused with
|
|
409
|
+
* `NonoProfileError` unless it is a JSON object nono accepts; when nono is
|
|
410
|
+
* not installed only the JSON is checked, and a launch checks the rest.
|
|
411
|
+
* The text is checked in a temporary file beside the target and renamed
|
|
412
|
+
* over it, so launches never see a half-written or refused profile.
|
|
413
|
+
*/
|
|
414
|
+
const saveProfile = async (content) => {
|
|
415
|
+
if (!customProfileFile) throw new SandboxLaunchError('SANDBOX_PROFILE_UNREADABLE');
|
|
416
|
+
if (typeof content !== 'string' || content.trim().length === 0) throw new NonoProfileError(['The profile is empty.']);
|
|
417
|
+
if (Buffer.byteLength(content) > NONO_PROFILE_MAX_BYTES) throw new NonoProfileError(['The profile is too large.']);
|
|
418
|
+
try {
|
|
419
|
+
const value = JSON.parse(content);
|
|
420
|
+
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new NonoProfileError(['The profile must be a JSON object.']);
|
|
421
|
+
} catch (error) {
|
|
422
|
+
if (error instanceof NonoProfileError) throw error;
|
|
423
|
+
throw new NonoProfileError([`The profile is not valid JSON: ${error?.message ?? 'syntax error'}`]);
|
|
424
|
+
}
|
|
425
|
+
const folder = dirname(customProfileFile);
|
|
426
|
+
const temporary = join(folder, `nono-profile.check-${process.pid}-${Date.now()}.json`);
|
|
427
|
+
try {
|
|
428
|
+
await mkdir(folder, { recursive: true, mode: 0o700 });
|
|
429
|
+
await writeFile(temporary, content, { mode: 0o600, flag: 'wx' });
|
|
430
|
+
const report = await validateProfileFile(temporary);
|
|
431
|
+
if (report && !report.valid) {
|
|
432
|
+
// nono names the file it checked; the owner knows it as the profile.
|
|
433
|
+
throw new NonoProfileError(report.messages.map((message) => (
|
|
434
|
+
typeof message === 'string' ? message.split(temporary).join('the profile') : message)));
|
|
435
|
+
}
|
|
436
|
+
await rename(temporary, customProfileFile);
|
|
437
|
+
} catch (error) {
|
|
438
|
+
await rm(temporary, { force: true }).catch(() => {});
|
|
439
|
+
if (error instanceof NonoProfileError) throw error;
|
|
440
|
+
throw new SandboxLaunchError('SANDBOX_PROFILE_UNREADABLE');
|
|
441
|
+
}
|
|
442
|
+
return profile();
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
/** Go back to the built-in profile by removing the custom file. */
|
|
446
|
+
const resetProfile = async () => {
|
|
447
|
+
if (customProfileFile) await rm(customProfileFile, { force: true });
|
|
448
|
+
return profile();
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
return {
|
|
452
|
+
id: 'nono', platforms: ['linux', 'darwin'], transport: 'local-socket',
|
|
453
|
+
probe, identity, prepare, profile, saveProfile, resetProfile,
|
|
454
|
+
};
|
|
455
|
+
};
|