@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.
Files changed (265) hide show
  1. package/dist/assets/AgentsSurface-CcWBqAWV.js +1 -0
  2. package/dist/assets/ChoicesArtifact-Kk-qvrSB.js +1 -0
  3. package/dist/assets/DiagramView-DZUBo1uP.js +1 -0
  4. package/dist/assets/{DiffView-BxW6BuOC.js → DiffView-CiZy4jFA.js} +6 -6
  5. package/dist/assets/FileSaveConflictDialog-DZ9NDwOO.js +3 -0
  6. package/dist/assets/FilesView-DqiZ9kw9.js +6 -0
  7. package/dist/assets/GitHubDetailScaffold-DM2DH7o8.js +11 -0
  8. package/dist/assets/GitHubLinkPicker-ChB8NZ1h.js +1 -0
  9. package/dist/assets/GitHubListPrimitives-CibDiJGq.js +1 -0
  10. package/dist/assets/{GitView-DD33ngnM.js → GitView--EaZQrBr.js} +5 -5
  11. package/dist/assets/{IssuesSurface-BAY_eyX5.js → IssuesSurface-CySTpaD1.js} +3 -3
  12. package/dist/assets/{JsonTreeView-DpXbUrAl.js → JsonTreeView-_yMHKKQZ.js} +1 -1
  13. package/dist/assets/{MarkdownRendererImpl-Cn63lAmn.js → MarkdownRendererImpl-D_-2fQw0.js} +3 -3
  14. package/dist/assets/PatchDiff-bHObDlhD.js +1 -0
  15. package/dist/assets/PierreDiffViewer-UY7Cse-s.js +147 -0
  16. package/dist/assets/PullRequestsSurface-iXy6chwc.js +2 -0
  17. package/dist/assets/{SessionSwitcherContent-CscYekC1.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
  18. package/dist/assets/SessionSwitcherDropdown-CDOX-5Y2.js +2 -0
  19. package/dist/assets/SessionUnreadDot-Dwc3MdvA.js +1 -0
  20. package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
  21. package/dist/assets/{SettingsWindow-gxjULdm1.js → SettingsWindow-CUg49Mfh.js} +1 -1
  22. package/dist/assets/{StickyHorizontalScrollbar-DNsbTLS7.js → StickyHorizontalScrollbar-CMbTn5WQ.js} +1 -1
  23. package/dist/assets/SubagentsArtifact-DUZX9tDe.js +1 -0
  24. package/dist/assets/ToolOutputDialog-BuZZaRw4.js +8 -0
  25. package/dist/assets/ToolPartDiffPreview-CKncG6i2.js +1 -0
  26. package/dist/assets/{VirtualizedFileDiff-BrbPymTL.js → VirtualizedFileDiff-BGZiLPe_.js} +4 -4
  27. package/dist/assets/{Virtualizer-okhy9Aq3.js → Virtualizer-PxblpQn6.js} +1 -1
  28. package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
  29. package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
  30. package/dist/assets/{collapsible-D6qdoq7-.js → collapsible-Bro9KrfM.js} +1 -1
  31. package/dist/assets/{computeVirtualFileMetrics-G4csGiKs.js → computeVirtualFileMetrics-DJQqK49u.js} +2 -2
  32. package/dist/assets/contextFileOpenGuard-ByWK3Sru.js +1 -0
  33. package/dist/assets/{fileTreeStatus-Bskhj4qT.js → fileTreeStatus-CyJ3TOYD.js} +2 -2
  34. package/dist/assets/gitStatusPredicates-BsXrwngT.js +1 -0
  35. package/dist/assets/githubLink-g2bmC0qi.js +10 -0
  36. package/dist/assets/index-B_L9GVYw.css +1 -0
  37. package/dist/assets/{index-ComwtfT4.js → index-C9rUUQ_Y.js} +1 -1
  38. package/dist/assets/index-CKKWVoND.js +11 -0
  39. package/dist/assets/{main-DoiadX0a.js → main-DT-4_fhe.js} +2 -2
  40. package/dist/assets/main-DsLMU9CT.js +137 -0
  41. package/dist/assets/{markdownCore-DczkEluO.js → markdownCore-QmM_aOnZ.js} +2 -2
  42. package/dist/assets/{miniChat-Ck6MEZ9Q.js → miniChat-BqGslD2z.js} +2 -2
  43. package/dist/assets/{mobile-BucKVm1P.js → mobile-C5JOcDIC.js} +2 -2
  44. package/dist/assets/{nativeFileSave-Cp9i5QGd.js → nativeFileSave-DSMsJqXM.js} +1 -1
  45. package/dist/assets/pi-session-focus-preference-Cc_S4zi1.js +9 -0
  46. package/dist/assets/{renderDiffWithHighlighter-PL82AR81.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
  47. package/dist/assets/renderElectronMiniChatApp-CiSkecEE.js +2 -0
  48. package/dist/assets/{renderFileWithHighlighter-CYgfbA4F.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
  49. package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
  50. package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
  51. package/dist/assets/runtimeSurface-0K7vuUpd.js +1 -0
  52. package/dist/assets/selection-CnYkEsu_.js +1 -0
  53. package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
  54. package/dist/assets/useGitHubRemoteSearch-CgP-zEBj.js +1 -0
  55. package/dist/assets/useSwitcherItems-C8G5F0hs.js +1 -0
  56. package/dist/assets/{vendor-aparajita-capacitor-secure-storage-DVZvgYu4.js → vendor-aparajita-capacitor-secure-storage-DUoR8t1G.js} +1 -1
  57. package/dist/assets/{vendor-base-ui-BCqPBzDj.js → vendor-base-ui-DE6jnTiC.js} +1 -1
  58. package/dist/assets/{vendor-boot-3SaHYVb1.js → vendor-boot-D-KEJjsM.js} +29 -29
  59. package/dist/assets/{vendor-capacitor-app-NbQ-WiPS.js → vendor-capacitor-app-CO5jS31X.js} +1 -1
  60. package/dist/assets/{vendor-capacitor-keyboard-CgrHt8iN.js → vendor-capacitor-keyboard-335osRpd.js} +1 -1
  61. package/dist/assets/{vendor-capacitor-status-bar-CWt0OF5t.js → vendor-capacitor-status-bar-lB9y4H9d.js} +1 -1
  62. package/dist/assets/{vendor-codemirror-autocomplete-WThuuUAz.js → vendor-codemirror-autocomplete-BKvJ8PfM.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-angular-BbLGCxF6.js → vendor-codemirror-lang-angular-wjCUD0bM.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-cpp-Cceks-9O.js → vendor-codemirror-lang-cpp-LJzlG8sJ.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-css-D1wpUg3Z.js → vendor-codemirror-lang-css-DoEEdEpW.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-go-Cv0zXHHM.js → vendor-codemirror-lang-go-DexsLPb8.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-html-DbL8oT9H.js → vendor-codemirror-lang-html-h25V-Hp5.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-java-CNugenuC.js → vendor-codemirror-lang-java-D8xoT8cv.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-javascript-Bx_FIyZF.js → vendor-codemirror-lang-javascript-DF3GDYje.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-jinja-DDGjB3Zq.js → vendor-codemirror-lang-jinja-BboTHFdn.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-json-DIvqf9Pb.js → vendor-codemirror-lang-json-DCqvG1nE.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-less-D8r9dGG1.js → vendor-codemirror-lang-less-B8ZrSKJM.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-liquid-B24mguYi.js → vendor-codemirror-lang-liquid-DF9S5m5F.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-markdown-v3yG2sbf.js → vendor-codemirror-lang-markdown-6BNbCEPe.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-php-BcZGalqy.js → vendor-codemirror-lang-php-CQwAz1Hd.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-python-b-JqEwQy.js → vendor-codemirror-lang-python-DQym-8Tx.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-rust-B1uZxDW-.js → vendor-codemirror-lang-rust-DknzOTkO.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-lang-sass-DqPrngKp.js → vendor-codemirror-lang-sass-dB0Rm5HI.js} +1 -1
  79. package/dist/assets/{vendor-codemirror-lang-sql-UyCnpt-k.js → vendor-codemirror-lang-sql-CCQUnnD-.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-lang-vue-xDwYkovV.js → vendor-codemirror-lang-vue-h1M5bF00.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-lang-wast-CF3169p_.js → vendor-codemirror-lang-wast-DWgtlGfu.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-xml-FCtVhuOb.js → vendor-codemirror-lang-xml-DncwoCUY.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-yaml-g0sPmAnv.js → vendor-codemirror-lang-yaml-C7QkS5ER.js} +1 -1
  84. package/dist/assets/{vendor-codemirror-language-data-B03xgzP2.js → vendor-codemirror-language-data-BUZIlm3G.js} +2 -2
  85. package/dist/assets/{vendor-codemirror-search-Dw3Wpu15.js → vendor-codemirror-search-BlDCaCMK.js} +1 -1
  86. package/dist/assets/{vendor-lezer-cpp-Cu3E-KUI.js → vendor-lezer-cpp-B4JK1BC1.js} +1 -1
  87. package/dist/assets/{vendor-lezer-css-Cb8vp67u.js → vendor-lezer-css-DRxDmhcy.js} +1 -1
  88. package/dist/assets/{vendor-lezer-go-BTsIaOm7.js → vendor-lezer-go-DsUgfmxi.js} +1 -1
  89. package/dist/assets/{vendor-lezer-html-UQMsUwj-.js → vendor-lezer-html-qr9pUPmM.js} +1 -1
  90. package/dist/assets/{vendor-lezer-java-BIWrFrAx.js → vendor-lezer-java-6UyNiQiB.js} +1 -1
  91. package/dist/assets/{vendor-lezer-javascript-BH2Etgoy.js → vendor-lezer-javascript-CUdJ0VGA.js} +1 -1
  92. package/dist/assets/{vendor-lezer-json-CE-QUCwM.js → vendor-lezer-json-BKYAA8Hu.js} +1 -1
  93. package/dist/assets/{vendor-lezer-lr-HY6Yc0Vr.js → vendor-lezer-lr-DluApmOX.js} +1 -1
  94. package/dist/assets/{vendor-lezer-markdown-xFL3Evwf.js → vendor-lezer-markdown-B-uzYzYT.js} +1 -1
  95. package/dist/assets/{vendor-lezer-php-Cr_mQGrG.js → vendor-lezer-php-DI6PNjlz.js} +1 -1
  96. package/dist/assets/{vendor-lezer-python-BNRFWCb0.js → vendor-lezer-python-Bj232yb5.js} +1 -1
  97. package/dist/assets/{vendor-lezer-rust-BvfOK5cU.js → vendor-lezer-rust-DlPG_Yau.js} +1 -1
  98. package/dist/assets/{vendor-lezer-sass-qoxiLisk.js → vendor-lezer-sass-CBsyWB2A.js} +1 -1
  99. package/dist/assets/{vendor-lezer-xml--x8SSpqU.js → vendor-lezer-xml-C1FmgtmE.js} +1 -1
  100. package/dist/assets/{vendor-lezer-yaml-BDo1JaEr.js → vendor-lezer-yaml-DpHmjriG.js} +1 -1
  101. package/dist/assets/{vendor-replit-codemirror-vim-D1Fe7FiY.js → vendor-replit-codemirror-vim-Cvk64got.js} +1 -1
  102. package/dist/assets/{web-components-CGDpzixf.js → web-components-BpncHjnV.js} +4 -4
  103. package/dist/index.html +4 -4
  104. package/dist/mini-chat.html +3 -3
  105. package/dist/mobile.html +3 -3
  106. package/package.json +2 -1
  107. package/plugins/featured.json +12 -0
  108. package/plugins/registry.json +7 -0
  109. package/plugins/subagents/LICENSE +25 -0
  110. package/plugins/subagents/agents/planner.md +36 -0
  111. package/plugins/subagents/agents/reviewer.md +34 -0
  112. package/plugins/subagents/agents/scout.md +49 -0
  113. package/plugins/subagents/agents/worker.md +23 -0
  114. package/plugins/subagents/extension.js +631 -0
  115. package/plugins/subagents/extension.test.js +295 -0
  116. package/plugins/subagents/package.json +41 -0
  117. package/plugins/visuals/choices.js +168 -0
  118. package/plugins/visuals/extension.js +90 -0
  119. package/plugins/visuals/files.js +74 -0
  120. package/plugins/visuals/package.json +32 -0
  121. package/server/index.js +103 -24
  122. package/server/lib/git/DOCUMENTATION.md +4 -0
  123. package/server/lib/git/service.js +70 -5
  124. package/server/lib/git/service.test.js +179 -0
  125. package/server/lib/github/DOCUMENTATION.md +6 -2
  126. package/server/lib/github/gh-cli.js +35 -9
  127. package/server/lib/github/gh-cli.test.js +122 -0
  128. package/server/lib/marketplace/DOCUMENTATION.md +95 -0
  129. package/server/lib/marketplace/featured.js +176 -0
  130. package/server/lib/marketplace/featured.test.js +207 -0
  131. package/server/lib/marketplace/npm-registry.js +255 -0
  132. package/server/lib/marketplace/npm-registry.test.js +227 -0
  133. package/server/lib/marketplace/routes.js +64 -0
  134. package/server/lib/marketplace/routes.test.js +119 -0
  135. package/server/lib/marketplace/service.js +225 -0
  136. package/server/lib/marketplace/service.test.js +174 -0
  137. package/server/lib/notifications/DOCUMENTATION.md +10 -4
  138. package/server/lib/notifications/pi-notification-watcher.js +95 -33
  139. package/server/lib/notifications/pi-notification-watcher.test.js +89 -0
  140. package/server/lib/open-url/DOCUMENTATION.md +2 -1
  141. package/server/lib/pi/extension-protocol.js +54 -0
  142. package/server/lib/pi/fixtures/pichamber-gui-demo.ts +12 -13
  143. package/server/lib/pi/merged-event-stream.js +316 -0
  144. package/server/lib/pi/merged-event-stream.test.js +95 -0
  145. package/server/lib/pi/routes-daemon-pool.test.js +348 -0
  146. package/server/lib/pi/routes-extension-events.test.js +115 -0
  147. package/server/lib/pi/routes-merged-events.test.js +327 -0
  148. package/server/lib/pi/routes-sandbox.test.js +1684 -0
  149. package/server/lib/pi/routes.js +790 -87
  150. package/server/lib/pi/routes.test.js +381 -1
  151. package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
  152. package/server/lib/pi/sandbox/launcher.js +122 -0
  153. package/server/lib/pi/sandbox/launcher.test.js +91 -0
  154. package/server/lib/pi/sandbox/nono-launcher.js +455 -0
  155. package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
  156. package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
  157. package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
  158. package/server/lib/pi/sandbox/nono-profile.json +22 -0
  159. package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
  160. package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
  161. package/server/lib/pi/sandbox/project-sandbox.js +207 -0
  162. package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
  163. package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
  164. package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
  165. package/server/lib/pi/sandbox/trust-ask.js +135 -0
  166. package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
  167. package/server/lib/pi/sandbox/worktree-ids.js +96 -0
  168. package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
  169. package/server/lib/pi/session-daemon/DOCUMENTATION.md +47 -10
  170. package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
  171. package/server/lib/pi/session-daemon/daemon-process.js +10 -1
  172. package/server/lib/pi/session-daemon/extension-bridge.js +89 -29
  173. package/server/lib/pi/session-daemon/extension-config.js +902 -0
  174. package/server/lib/pi/session-daemon/extension-config.test.js +798 -0
  175. package/server/lib/pi/session-daemon/extension-controls.js +177 -0
  176. package/server/lib/pi/session-daemon/extension-controls.test.js +181 -0
  177. package/server/lib/pi/session-daemon/extension-name.js +6 -0
  178. package/server/lib/pi/session-daemon/extension-name.test.js +5 -0
  179. package/server/lib/pi/session-daemon/extension-palette.js +146 -0
  180. package/server/lib/pi/session-daemon/extension-palette.test.js +107 -0
  181. package/server/lib/pi/session-daemon/extension-replacements.js +138 -0
  182. package/server/lib/pi/session-daemon/extension-replacements.test.js +116 -0
  183. package/server/lib/pi/session-daemon/extension-ui-mode.js +30 -0
  184. package/server/lib/pi/session-daemon/extension-ui-mode.test.js +34 -0
  185. package/server/lib/pi/session-daemon/pichamber-ui.js +44 -0
  186. package/server/lib/pi/session-daemon/plugin-host.js +245 -0
  187. package/server/lib/pi/session-daemon/plugin-host.test.js +192 -0
  188. package/server/lib/pi/session-daemon/session-daemon-controls.e2e.test.js +205 -0
  189. package/server/lib/pi/session-daemon/session-daemon-drafts.e2e.test.js +409 -0
  190. package/server/lib/pi/session-daemon/session-daemon-extension-config.e2e.test.js +196 -0
  191. package/server/lib/pi/session-daemon/session-daemon-extensions.test.js +137 -6
  192. package/server/lib/pi/session-daemon/session-daemon-plugins.e2e.test.js +272 -0
  193. package/server/lib/pi/session-daemon/session-daemon-providers.e2e.test.js +153 -0
  194. package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
  195. package/server/lib/pi/session-daemon/session-daemon.js +927 -108
  196. package/server/lib/pi/session-daemon/session-daemon.test.js +391 -4
  197. package/server/lib/pi/session-daemon/session-engine-router.js +7 -0
  198. package/server/lib/pi/session-daemon/session-engine-router.test.js +20 -0
  199. package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
  200. package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
  201. package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
  202. package/server/lib/pi/session-daemon/session-lease.js +93 -15
  203. package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
  204. package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
  205. package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
  206. package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
  207. package/server/lib/pi/session-daemon/supervisor.js +408 -38
  208. package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
  209. package/server/lib/pi/settings-store.js +14 -0
  210. package/server/lib/pi/settings-store.test.js +11 -0
  211. package/server/lib/pi/ui-settings-store.js +88 -2
  212. package/server/lib/pi/ui-settings-store.test.js +118 -0
  213. package/server/lib/plugins/DOCUMENTATION.md +198 -0
  214. package/server/lib/plugins/daemon-sync.js +88 -0
  215. package/server/lib/plugins/daemon-sync.supervisor.test.js +83 -0
  216. package/server/lib/plugins/daemon-sync.test.js +108 -0
  217. package/server/lib/plugins/impact.js +139 -0
  218. package/server/lib/plugins/impact.test.js +83 -0
  219. package/server/lib/plugins/manifest.js +220 -0
  220. package/server/lib/plugins/manifest.test.js +127 -0
  221. package/server/lib/plugins/registry.js +59 -0
  222. package/server/lib/plugins/routes.js +92 -0
  223. package/server/lib/plugins/routes.test.js +247 -0
  224. package/server/lib/plugins/service.js +183 -0
  225. package/server/lib/plugins/store.js +261 -0
  226. package/server/lib/plugins/store.test.js +188 -0
  227. package/server/lib/plugins/visuals-extension.test.js +237 -0
  228. package/server/lib/server/cross-process-lock.js +28 -3
  229. package/server/lib/server-browser/DOCUMENTATION.md +32 -7
  230. package/server/lib/server-browser/browser-tab.js +4 -1
  231. package/server/lib/server-browser/downloads.js +261 -34
  232. package/server/lib/server-browser/downloads.test.js +171 -0
  233. package/server/lib/server-browser/runtime.integration.test.js +47 -0
  234. package/server/lib/server-browser/runtime.js +16 -0
  235. package/server/lib/server-browser/server-browser.js +25 -6
  236. package/server/lib/tunnels/executable-search.js +5 -1
  237. package/server/lib/tunnels/executable-search.test.js +26 -0
  238. package/dist/assets/DiagramView-BB-aZobi.js +0 -1
  239. package/dist/assets/FileSaveConflictDialog-Bzz8FNMq.js +0 -3
  240. package/dist/assets/FilesView-DECxN8Z0.js +0 -6
  241. package/dist/assets/GitHubDetailScaffold-CWsWycRd.js +0 -11
  242. package/dist/assets/GitHubLinkPicker-BVYdg_e8.js +0 -1
  243. package/dist/assets/GitHubListPrimitives-Dlv3tC4d.js +0 -1
  244. package/dist/assets/PatchDiff-BklyOEHs.js +0 -1
  245. package/dist/assets/PierreDiffViewer-wc6cB6qw.js +0 -147
  246. package/dist/assets/PullRequestsSurface-BZvJkT1I.js +0 -2
  247. package/dist/assets/SessionSwitcherDropdown-DShvvGwC.js +0 -2
  248. package/dist/assets/SessionUnreadDot-CbqRq6h_.js +0 -1
  249. package/dist/assets/SettingsView-DcF-At5E.js +0 -6
  250. package/dist/assets/ToolOutputDialog-DdMIfrnK.js +0 -8
  251. package/dist/assets/ToolPartDiffPreview-C6Sm4eVf.js +0 -1
  252. package/dist/assets/contextFileOpenGuard-UU86YHgI.js +0 -1
  253. package/dist/assets/gitStatusPredicates-DQEO4Psc.js +0 -1
  254. package/dist/assets/githubLink-ByPAyFjh.js +0 -10
  255. package/dist/assets/index-BaLCg7tL.css +0 -1
  256. package/dist/assets/index-I2QYqABE.js +0 -11
  257. package/dist/assets/main-DyFfbllq.js +0 -137
  258. package/dist/assets/pi-session-focus-preference-Dx0UXPoO.js +0 -9
  259. package/dist/assets/renderElectronMiniChatApp-Cb7s7dWl.js +0 -2
  260. package/dist/assets/renderMobileApp-Bp74b_Lo.js +0 -11
  261. package/dist/assets/runtimeEndpointReset-7nWYnKd4.js +0 -62
  262. package/dist/assets/runtimeSurface-CFwnvks_.js +0 -1
  263. package/dist/assets/useAppFontEffects-ZTyNwFk6.js +0 -213
  264. package/dist/assets/useGitHubRemoteSearch-BF3ohpsh.js +0 -1
  265. package/dist/assets/useSwitcherItems-BJzwyDGX.js +0 -1
@@ -0,0 +1,166 @@
1
+ import { isAbsolute, normalize } from 'node:path';
2
+
3
+ import { normalizeNetwork, SANDBOX_LIMIT_CODES } from './launcher.js';
4
+
5
+ // A project's sandbox setting (#242 "Settings and storage"). It lives on the
6
+ // project entry in host-local settings (runtime-state.json) and is never
7
+ // portable: a sandbox claimed on one machine means nothing on another.
8
+ // `default` follows the host's sandbox default (`normalizeSandboxDefaults`);
9
+ // a project with no stored setting follows it too.
10
+ const SANDBOX_MODES = ['default', 'off', 'nono'];
11
+ const DEFAULT_MODES = ['off', 'nono'];
12
+
13
+ const MAX_HOSTS = 64;
14
+ const MAX_PORTS = 32;
15
+ const MAX_FOLDERS = 32;
16
+ // A port grant applies to every host and bypasses the proxy (nono-launcher.js).
17
+ const REFUSED_PORTS = new Set([80, 443]);
18
+
19
+ export class ProjectSandboxSettingError extends Error {
20
+ /** `reason` names the part that was refused (`HOSTS`, `PORTS`,
21
+ * `REFUSED_PORT`, `FOLDERS`, or `MODE` for a default update that must
22
+ * name a mode), so the form can say which to fix. */
23
+ constructor(reason, code = 'INVALID_SANDBOX_SETTING') {
24
+ super('The project sandbox setting is invalid.');
25
+ this.code = code;
26
+ if (reason) this.reason = reason;
27
+ }
28
+ }
29
+
30
+ /** A validated setting, or `ProjectSandboxSettingError`. */
31
+ const normalizeProjectSandboxSetting = (value) => {
32
+ if (!value || typeof value !== 'object' || Array.isArray(value) || !SANDBOX_MODES.includes(value.mode)) {
33
+ throw new ProjectSandboxSettingError();
34
+ }
35
+ const allowHosts = value.allowHosts ?? [];
36
+ const allowLocalPorts = value.allowLocalPorts ?? [];
37
+ const extraFolders = value.extraFolders ?? [];
38
+ if (!Array.isArray(allowHosts) || allowHosts.length > MAX_HOSTS
39
+ || !Array.isArray(allowLocalPorts) || allowLocalPorts.length > MAX_PORTS
40
+ || !Array.isArray(extraFolders) || extraFolders.length > MAX_FOLDERS) {
41
+ throw new ProjectSandboxSettingError();
42
+ }
43
+ let network;
44
+ try {
45
+ network = normalizeNetwork({ mode: 'proxy', allowHosts, allowLocalPorts });
46
+ } catch {
47
+ // Find out which list it was, for the reason.
48
+ let hostsValid = true;
49
+ try {
50
+ normalizeNetwork({ mode: 'proxy', allowHosts, allowLocalPorts: [] });
51
+ } catch {
52
+ hostsValid = false;
53
+ }
54
+ throw new ProjectSandboxSettingError(hostsValid ? 'PORTS' : 'HOSTS');
55
+ }
56
+ if (network.allowLocalPorts.some((port) => REFUSED_PORTS.has(port))) throw new ProjectSandboxSettingError('REFUSED_PORT');
57
+ const folders = new Map();
58
+ for (const folder of extraFolders) {
59
+ if (!folder || typeof folder.path !== 'string' || !isAbsolute(folder.path) || /[\0\n\r]/.test(folder.path)
60
+ || !['read', 'readWrite'].includes(folder.access)) {
61
+ throw new ProjectSandboxSettingError('FOLDERS');
62
+ }
63
+ const path = normalize(folder.path).replace(/(.)\/+$/, '$1');
64
+ folders.set(path, { path, access: folder.access });
65
+ }
66
+ return {
67
+ mode: value.mode,
68
+ allowHosts: network.allowHosts,
69
+ allowLocalPorts: network.allowLocalPorts,
70
+ extraFolders: [...folders.values()],
71
+ };
72
+ };
73
+
74
+ const PROJECT_SETTING_FIELDS = ['mode', 'allowHosts', 'allowLocalPorts', 'extraFolders'];
75
+
76
+ /**
77
+ * The stored setting of `project` with the fields of `patch` (`mode`,
78
+ * `allowHosts`, `allowLocalPorts`, `extraFolders`, or several) laid over
79
+ * it, validated. A field the patch leaves out keeps its stored value, so a
80
+ * device holding an old copy cannot undo what another device just saved. A
81
+ * project with no stored setting starts from the default with empty lists,
82
+ * and one whose stored setting is unreadable from a sandboxed one, which is
83
+ * what it runs as. A patch with none of the fields is refused.
84
+ */
85
+ export const mergeProjectSandboxSetting = (project, patch) => {
86
+ if (!patch || typeof patch !== 'object' || Array.isArray(patch)
87
+ || PROJECT_SETTING_FIELDS.every((field) => patch[field] === undefined)) {
88
+ throw new ProjectSandboxSettingError();
89
+ }
90
+ const { setting, invalid } = readProjectSandbox(project);
91
+ const current = setting ?? { mode: invalid ? 'nono' : 'default' };
92
+ return normalizeProjectSandboxSetting(Object.fromEntries(
93
+ PROJECT_SETTING_FIELDS.map((field) => [field, patch[field] === undefined ? current[field] : patch[field]]),
94
+ ));
95
+ };
96
+
97
+ /**
98
+ * The host's sandbox default: whether projects that follow it are sandboxed,
99
+ * hosts every sandboxed project may reach on top of its own, and the host
100
+ * limits (`SANDBOX_LIMIT_CODES`) the owner accepted. Host-local, like project
101
+ * settings. Validated, or `ProjectSandboxSettingError`.
102
+ */
103
+ const normalizeSandboxDefaults = (value) => {
104
+ if (!value || typeof value !== 'object' || Array.isArray(value) || !DEFAULT_MODES.includes(value.mode)) {
105
+ throw new ProjectSandboxSettingError();
106
+ }
107
+ const allowHosts = value.allowHosts ?? [];
108
+ if (!Array.isArray(allowHosts) || allowHosts.length > MAX_HOSTS) throw new ProjectSandboxSettingError();
109
+ const acceptedLimits = value.acceptedLimits ?? [];
110
+ if (!Array.isArray(acceptedLimits) || acceptedLimits.some((limit) => !SANDBOX_LIMIT_CODES.includes(limit))) {
111
+ throw new ProjectSandboxSettingError();
112
+ }
113
+ let hosts;
114
+ try {
115
+ hosts = normalizeNetwork({ mode: 'proxy', allowHosts, allowLocalPorts: [] }).allowHosts;
116
+ } catch {
117
+ throw new ProjectSandboxSettingError();
118
+ }
119
+ return {
120
+ mode: value.mode,
121
+ allowHosts: hosts,
122
+ acceptedLimits: SANDBOX_LIMIT_CODES.filter((limit) => acceptedLimits.includes(limit)),
123
+ };
124
+ };
125
+
126
+ /**
127
+ * `current` with the fields of `patch` (`mode`, `allowHosts`,
128
+ * `acceptedLimits`, or several) laid over it, validated. A patch with none
129
+ * of them is refused.
130
+ */
131
+ export const mergeSandboxDefaults = (current, patch) => {
132
+ if (!patch || typeof patch !== 'object' || Array.isArray(patch)
133
+ || (patch.mode === undefined && patch.allowHosts === undefined && patch.acceptedLimits === undefined)) {
134
+ throw new ProjectSandboxSettingError();
135
+ }
136
+ return normalizeSandboxDefaults({
137
+ mode: patch.mode === undefined ? current.mode : patch.mode,
138
+ allowHosts: patch.allowHosts === undefined ? [...current.allowHosts] : patch.allowHosts,
139
+ acceptedLimits: patch.acceptedLimits === undefined ? [...current.acceptedLimits] : patch.acceptedLimits,
140
+ });
141
+ };
142
+
143
+ const SANDBOX_DEFAULTS_OFF = Object.freeze({ mode: 'off', allowHosts: Object.freeze([]), acceptedLimits: Object.freeze([]) });
144
+
145
+ /** The stored host default, or off when there is none. An unreadable one
146
+ * is `invalid`, so projects that follow it fail closed. */
147
+ export const readSandboxDefaults = (settings) => {
148
+ const value = settings && typeof settings === 'object' ? settings.sandboxDefaults : undefined;
149
+ if (value === undefined) return { defaults: SANDBOX_DEFAULTS_OFF };
150
+ try {
151
+ return { defaults: normalizeSandboxDefaults(value) };
152
+ } catch {
153
+ return { defaults: SANDBOX_DEFAULTS_OFF, invalid: true };
154
+ }
155
+ };
156
+
157
+ /** The stored setting of a project entry, or null when it has none or it is
158
+ * unreadable (an unreadable setting is reported by `readProjectSandbox`). */
159
+ export function readProjectSandbox(project) {
160
+ if (!project || typeof project !== 'object' || project.sandbox === undefined) return { setting: null };
161
+ try {
162
+ return { setting: normalizeProjectSandboxSetting(project.sandbox) };
163
+ } catch {
164
+ return { setting: null, invalid: true }
165
+ }
166
+ };
@@ -0,0 +1,207 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { realpathSync } from 'node:fs';
3
+ import { lstat, mkdir, readlink, rm, stat, symlink } from 'node:fs/promises';
4
+ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ import { getPiSessionDirectory } from '../session-daemon/session-jsonl.js';
8
+ import { scopedLeaseDir } from '../session-daemon/session-lease.js';
9
+ import { normalizeNetwork, SandboxLaunchError } from './launcher.js';
10
+
11
+ // Pi reads these single files from its agent folder. They are granted
12
+ // read-only on the real file and reached through a symlink in the shadow
13
+ // folder, so Pi's lock folders land in the shadow, not beside the real file.
14
+ const PI_CONFIG_FILES = ['settings.json', 'auth.json', 'models.json', 'trust.json', 'mcp.json'];
15
+ const PI_RESOURCE_FOLDERS = ['extensions', 'prompts', 'themes', 'skills', 'tools', 'bin'];
16
+ const REFUSED_PORTS = new Set([80, 443]);
17
+
18
+ const WEB_PACKAGE_ROOT = fileURLToPath(new URL('../../../../', import.meta.url));
19
+
20
+ const exists = async (path) => {
21
+ try {
22
+ await stat(path);
23
+ return true;
24
+ } catch (error) {
25
+ if (error?.code === 'ENOENT') return false;
26
+ throw error;
27
+ }
28
+ };
29
+
30
+ const isWithin = (parent, child) => {
31
+ const rel = relative(parent, child);
32
+ return rel === '' || (!rel.startsWith('..') && !isAbsolute(rel));
33
+ };
34
+
35
+ const overlaps = (a, b) => isWithin(a, b) || isWithin(b, a);
36
+
37
+ const sandboxProjectKey = (projectRoot) => createHash('sha256')
38
+ .update(resolve(projectRoot))
39
+ .digest('hex')
40
+ .slice(0, 12);
41
+
42
+ const realpathOr = (path) => {
43
+ try {
44
+ return realpathSync(path);
45
+ } catch {
46
+ return path;
47
+ }
48
+ };
49
+
50
+ /**
51
+ * Folders the daemon process itself needs to read: the runtime (the real
52
+ * Node install prefix, or the Electron app folder) and the PiChamber install
53
+ * with the Pi SDK.
54
+ */
55
+ const resolveDaemonReadRoots = ({
56
+ execPath = process.execPath,
57
+ electron = Boolean(process.versions?.electron),
58
+ resolveSdk = () => fileURLToPath(import.meta.resolve('@earendil-works/pi-coding-agent')),
59
+ } = {}) => {
60
+ const runtime = realpathOr(execPath);
61
+ const roots = [electron ? dirname(runtime) : dirname(dirname(runtime))];
62
+ const webRoot = realpathOr(WEB_PACKAGE_ROOT);
63
+ roots.push(webRoot);
64
+ const sdk = realpathOr(resolveSdk());
65
+ if (!isWithin(webRoot, sdk)) {
66
+ // Hoisted or isolated installs keep dependencies in an outer
67
+ // node_modules; grant the outermost one that holds the SDK.
68
+ const marker = `${sep}node_modules${sep}`;
69
+ const index = sdk.indexOf(marker);
70
+ if (index > 0) roots.push(sdk.slice(0, index + marker.length - 1));
71
+ }
72
+ return [...new Set(roots)];
73
+ };
74
+
75
+ // Points `linkPath` at `target`. Only the last name is read, removed or
76
+ // created, and none of those follow a link, so the caller must own the
77
+ // folder that holds it: the shadow folder itself (which sandboxed code can
78
+ // fill but never replace) or a folder the sandbox cannot write.
79
+ const ensureSymlink = async (linkPath, target) => {
80
+ try {
81
+ const info = await lstat(linkPath);
82
+ // Never delete real content (for example transcripts) to make room.
83
+ if (!info.isSymbolicLink()) throw new SandboxLaunchError('SANDBOX_SHADOW_CONFLICT');
84
+ if (await readlink(linkPath) === target) return;
85
+ await rm(linkPath, { force: true });
86
+ } catch (error) {
87
+ if (error?.code !== 'ENOENT') throw error;
88
+ }
89
+ await symlink(target, linkPath);
90
+ };
91
+
92
+ /**
93
+ * Build the launch request for one sandboxed project: grants, network,
94
+ * the shadow Pi agent folder and the private temp folder. Creates the
95
+ * folders it grants, so nono never sees a missing path.
96
+ */
97
+ export const prepareProjectSandbox = async ({
98
+ dataDir,
99
+ agentDir,
100
+ projectRoot,
101
+ projectId,
102
+ worktreeDirs = [],
103
+ serverPort,
104
+ readRoots = resolveDaemonReadRoots(),
105
+ extraFolders = [],
106
+ allowHosts = [],
107
+ allowLocalPorts = [],
108
+ }) => {
109
+ if (![dataDir, agentDir, projectRoot].every((value) => typeof value === 'string' && isAbsolute(value))) {
110
+ throw new SandboxLaunchError('SANDBOX_INVALID_GRANT');
111
+ }
112
+ for (const port of allowLocalPorts) {
113
+ if (REFUSED_PORTS.has(port) || port === serverPort) throw new SandboxLaunchError('SANDBOX_PORT_REFUSED');
114
+ }
115
+ const network = normalizeNetwork({ mode: 'proxy', allowHosts, allowLocalPorts });
116
+ for (const extra of extraFolders) {
117
+ if (typeof extra?.path !== 'string' || !isAbsolute(extra.path) || !['read', 'readWrite'].includes(extra.access)) {
118
+ throw new SandboxLaunchError('SANDBOX_INVALID_GRANT');
119
+ }
120
+ }
121
+ // PiChamber's data folder and the Pi agent folder hold credentials, other
122
+ // projects' state and code the server runs. Nothing granted may reach
123
+ // them, by name or through a symlink: a grant follows links, and the
124
+ // agent can replace a folder inside its project with one.
125
+ const protectedDirs = [...new Set([dataDir, agentDir].flatMap((path) => [resolve(path), realpathOr(path)]))];
126
+ const spellings = (path) => [...new Set([resolve(path), realpathOr(path)])];
127
+ for (const extra of extraFolders) {
128
+ if (spellings(extra.path).some((path) => protectedDirs.some((dir) => overlaps(path, dir)))) {
129
+ throw new SandboxLaunchError('SANDBOX_GRANT_REFUSED');
130
+ }
131
+ }
132
+ // The project folder is granted read-write as a whole, so it must not
133
+ // hold either folder (a home folder as a project would), nor sit inside
134
+ // one, except as a PiChamber worktree.
135
+ const worktreeBases = spellings(join(dataDir, 'worktree'));
136
+ for (const root of spellings(projectRoot)) {
137
+ const inWorktrees = worktreeBases.some((base) => isWithin(base, root) && root !== base);
138
+ if (protectedDirs.some((dir) => isWithin(root, dir) || (isWithin(dir, root) && !inWorktrees))) {
139
+ throw new SandboxLaunchError('SANDBOX_GRANT_REFUSED');
140
+ }
141
+ }
142
+
143
+ const projectKey = sandboxProjectKey(projectRoot);
144
+ const sandboxRoot = join(dataDir, 'pi', 'sandbox', projectKey);
145
+ const shadowDir = join(sandboxRoot, 'agent');
146
+ // The links to this project's real session folders. They sit beside the
147
+ // shadow, not in it: everything below the shadow is writable from inside
148
+ // the sandbox, so any folder there may have been swapped for a link, and
149
+ // the server, which runs with the user's access, would create whatever it
150
+ // puts in that folder wherever the link points (Pi's real extensions
151
+ // folder, for one). The shadow's own `sessions` entry is a link to here,
152
+ // and the sandbox may only read here.
153
+ const sessionLinksDir = join(sandboxRoot, 'sessions');
154
+ const tmpDir = join(sandboxRoot, 'tmp');
155
+ // A cache of its own: the user's cache folders hold code that tools
156
+ // outside the sandbox run later (browser builds, package managers), so
157
+ // the sandbox is never given them.
158
+ const cacheDir = join(sandboxRoot, 'cache');
159
+ // The project's own lease folder. The shared one holds every other
160
+ // project's live sessions and is not granted.
161
+ const leaseDir = scopedLeaseDir(agentDir, projectKey);
162
+ await Promise.all([shadowDir, sessionLinksDir, tmpDir, cacheDir, leaseDir].map((path) => mkdir(path, { recursive: true, mode: 0o700 })));
163
+
164
+ const grants = [
165
+ { kind: 'readWrite', path: projectRoot },
166
+ { kind: 'readWrite', path: shadowDir },
167
+ { kind: 'readWrite', path: tmpDir },
168
+ { kind: 'readWrite', path: cacheDir },
169
+ { kind: 'readWrite', path: leaseDir },
170
+ { kind: 'read', path: sessionLinksDir },
171
+ ...readRoots.map((path) => ({ kind: 'read', path })),
172
+ ];
173
+ await ensureSymlink(join(shadowDir, 'sessions'), sessionLinksDir);
174
+
175
+ if (typeof projectId === 'string' && /^[A-Za-z0-9_-]+$/.test(projectId)) {
176
+ const worktreeRoot = join(dataDir, 'worktree', projectId);
177
+ await mkdir(worktreeRoot, { recursive: true, mode: 0o700 });
178
+ grants.push({ kind: 'readWrite', path: worktreeRoot });
179
+ }
180
+
181
+ // Only this project's own session folders, never the sessions/ parent.
182
+ for (const cwd of [projectRoot, ...worktreeDirs]) {
183
+ const real = getPiSessionDirectory({ cwd, agentDir });
184
+ await mkdir(real, { recursive: true, mode: 0o700 });
185
+ // `<sandboxRoot>/sessions/<encoded cwd>`, the same name Pi looks up
186
+ // below the shadow.
187
+ await ensureSymlink(getPiSessionDirectory({ cwd, agentDir: sandboxRoot }), real);
188
+ grants.push({ kind: 'readWrite', path: real });
189
+ }
190
+
191
+ for (const name of PI_CONFIG_FILES) {
192
+ const real = join(agentDir, name);
193
+ if (!await exists(real)) continue;
194
+ await ensureSymlink(join(shadowDir, name), real);
195
+ grants.push({ kind: 'readFile', path: real });
196
+ }
197
+ for (const name of PI_RESOURCE_FOLDERS) {
198
+ const real = join(agentDir, name);
199
+ if (!await exists(real)) continue;
200
+ await ensureSymlink(join(shadowDir, name), real);
201
+ grants.push({ kind: 'read', path: real });
202
+ }
203
+
204
+ for (const extra of extraFolders) grants.push({ kind: extra.access, path: extra.path });
205
+
206
+ return { projectKey, cwd: projectRoot, agentDir: shadowDir, leaseAgentDir: resolve(agentDir), leaseScope: projectKey, tmpDir, cacheDir, grants, network };
207
+ };
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Public sandbox routes (#242 "Public API"). Responses carry launcher ids,
3
+ * versions, stable reason codes and the project's own settings; never PIDs,
4
+ * credentials or the data folder's layout. The profile routes are the one
5
+ * exception to "no server paths, no launcher output": the owner asked where
6
+ * the profile is so they can edit it, and a refused profile comes back with
7
+ * what nono said is wrong with it.
8
+ *
9
+ * GET /api/pi/sandbox launcher status
10
+ * POST /api/pi/sandbox/recheck probe the launcher again
11
+ * GET /api/pi/sandbox/projects every project's sandbox state
12
+ * PUT /api/pi/sandbox/projects/:projectId save one project's setting
13
+ * GET /api/pi/sandbox/defaults the host's sandbox default
14
+ * PUT /api/pi/sandbox/defaults save it and apply it
15
+ * GET /api/pi/sandbox/profile the launcher profile in use
16
+ * PUT /api/pi/sandbox/profile save `{ content }` as the custom profile
17
+ * DELETE /api/pi/sandbox/profile back to the built-in profile
18
+ */
19
+ export const registerPiSandboxRoutes = (app, { sandboxManager }) => {
20
+ const fail = (res, error) => {
21
+ const code = typeof error?.code === 'string' ? error.code : 'SANDBOX_REQUEST_FAILED';
22
+ const status = code === 'INVALID_SANDBOX_SETTING' || code === 'INVALID_SANDBOX_PROFILE' ? 400 : code === 'PROJECT_NOT_FOUND' ? 404 : 500;
23
+ if (status === 500) console.warn('[pi-sandbox] request failed', code);
24
+ const reason = status === 400 && typeof error?.reason === 'string' && /^[A-Z][A-Z_]{1,31}$/.test(error.reason) ? error.reason : undefined;
25
+ const messages = code === 'INVALID_SANDBOX_PROFILE' && Array.isArray(error?.messages)
26
+ ? error.messages.filter((message) => typeof message === 'string')
27
+ : undefined;
28
+ res.status(status).json({
29
+ error: {
30
+ code: status === 500 ? 'SANDBOX_REQUEST_FAILED' : code,
31
+ ...(reason ? { reason } : {}),
32
+ ...(messages ? { messages } : {}),
33
+ },
34
+ });
35
+ };
36
+
37
+ app.get('/api/pi/sandbox', async (_req, res) => {
38
+ try {
39
+ res.json({ launchers: await sandboxManager.launcherStatus() });
40
+ } catch (error) {
41
+ fail(res, error);
42
+ }
43
+ });
44
+
45
+ app.post('/api/pi/sandbox/recheck', async (_req, res) => {
46
+ try {
47
+ res.json({ launchers: await sandboxManager.launcherStatus({ recheck: true }) });
48
+ } catch (error) {
49
+ fail(res, error);
50
+ }
51
+ });
52
+
53
+ app.get('/api/pi/sandbox/projects', async (_req, res) => {
54
+ try {
55
+ res.json({ projects: await sandboxManager.listProjects() });
56
+ } catch (error) {
57
+ fail(res, error);
58
+ }
59
+ });
60
+
61
+ app.get('/api/pi/sandbox/defaults', async (_req, res) => {
62
+ try {
63
+ res.json({ defaults: await sandboxManager.sandboxDefaults() });
64
+ } catch (error) {
65
+ fail(res, error);
66
+ }
67
+ });
68
+
69
+ app.put('/api/pi/sandbox/defaults', async (req, res) => {
70
+ try {
71
+ const defaults = await sandboxManager.setSandboxDefaults(req.body);
72
+ res.json({ defaults, projects: await sandboxManager.listProjects() });
73
+ } catch (error) {
74
+ fail(res, error);
75
+ }
76
+ });
77
+
78
+ app.put('/api/pi/sandbox/projects/:projectId', async (req, res) => {
79
+ try {
80
+ const project = await sandboxManager.setProjectSandbox(req.params.projectId, req.body);
81
+ res.json({ project });
82
+ } catch (error) {
83
+ fail(res, error);
84
+ }
85
+ });
86
+
87
+ app.get('/api/pi/sandbox/profile', async (_req, res) => {
88
+ try {
89
+ res.json({ profile: await sandboxManager.sandboxProfile() });
90
+ } catch (error) {
91
+ fail(res, error);
92
+ }
93
+ });
94
+
95
+ app.put('/api/pi/sandbox/profile', async (req, res) => {
96
+ try {
97
+ res.json({ profile: await sandboxManager.setSandboxProfile(req.body?.content) });
98
+ } catch (error) {
99
+ fail(res, error);
100
+ }
101
+ });
102
+
103
+ app.delete('/api/pi/sandbox/profile', async (_req, res) => {
104
+ try {
105
+ res.json({ profile: await sandboxManager.resetSandboxProfile() });
106
+ } catch (error) {
107
+ fail(res, error);
108
+ }
109
+ });
110
+ };
@@ -0,0 +1,100 @@
1
+ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
2
+ import { readFileSync, realpathSync, statSync } from 'node:fs';
3
+ import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
4
+
5
+ const MAX_DIRECTORIES = 4096;
6
+
7
+ /**
8
+ * The folders that sandbox daemons own (#242): each sandboxed project's
9
+ * root, its real path, and its worktree root. The server writes the list
10
+ * whenever ownership changes and the main daemon reads it before it starts
11
+ * a Pi runtime, so nothing it is asked (a request without a folder, a
12
+ * catalog read, a reopened session) can load a sandboxed project's
13
+ * extensions outside the sandbox. The list lives in PiChamber's data
14
+ * folder, which no sandbox can write.
15
+ */
16
+ export const sandboxedFoldersFile = (dataDir) => join(dataDir, 'pi', 'sandboxed-folders.json');
17
+
18
+ const normalizeList = (value) => {
19
+ if (!value || typeof value !== 'object' || !Array.isArray(value.directories)) return null;
20
+ if (!value.directories.every((dir) => typeof dir === 'string' && isAbsolute(dir))) return null;
21
+ return value.directories.map((dir) => resolve(dir));
22
+ };
23
+
24
+ const inside = (root, directory) => directory === root
25
+ || directory.startsWith(root.endsWith(sep) ? root : `${root}${sep}`);
26
+
27
+ export const createSandboxedFoldersStore = ({ dataDir, file = sandboxedFoldersFile(dataDir) }) => {
28
+ let queue = Promise.resolve();
29
+ let written = null;
30
+ return {
31
+ /**
32
+ * Replace the list. Writes run one at a time; a list is not written
33
+ * again while the file still holds it (a deleted or changed file is
34
+ * put back). A list too long to record is refused: a folder left
35
+ * out would be the main daemon's to run.
36
+ */
37
+ set: (directories) => {
38
+ const next = [...new Set(directories.map((dir) => resolve(dir)))].sort();
39
+ const run = queue.then(async () => {
40
+ if (next.length > MAX_DIRECTORIES) {
41
+ throw Object.assign(new Error('Too many sandboxed folders to record.'), { code: 'SANDBOXED_FOLDERS_FULL' });
42
+ }
43
+ const body = `${JSON.stringify({ version: 1, directories: next }, null, 2)}\n`;
44
+ if (body === written && await readFile(file, 'utf8').catch(() => null) === body) return;
45
+ await mkdir(dirname(file), { recursive: true, mode: 0o700 });
46
+ const temp = `${file}.${process.pid}.${Date.now()}.tmp`;
47
+ await writeFile(temp, body, { mode: 0o600 });
48
+ await rename(temp, file);
49
+ written = body;
50
+ });
51
+ queue = run.catch(() => {});
52
+ return run;
53
+ },
54
+ };
55
+ };
56
+
57
+ /**
58
+ * Daemon-side check, synchronous because it guards runtime creation:
59
+ * whether `directory`, by its written or its real path, is a sandboxed
60
+ * folder or inside one. Reread only when the file changes. A missing file
61
+ * lists nothing; a malformed or unreadable one counts as every folder.
62
+ */
63
+ export const createSandboxedFoldersReader = ({ file } = {}) => {
64
+ let cachedStamp = null;
65
+ let cached = [];
66
+ const load = () => {
67
+ if (!file) return [];
68
+ let stamp;
69
+ try {
70
+ const info = statSync(file);
71
+ stamp = `${info.ino}:${info.size}:${info.mtimeMs}`;
72
+ } catch (error) {
73
+ cachedStamp = null;
74
+ cached = [];
75
+ return error?.code === 'ENOENT' ? [] : null;
76
+ }
77
+ if (stamp === cachedStamp) return cached;
78
+ try {
79
+ cached = normalizeList(JSON.parse(readFileSync(file, 'utf8')));
80
+ } catch {
81
+ cached = null;
82
+ }
83
+ cachedStamp = stamp;
84
+ return cached;
85
+ };
86
+ return (directory) => {
87
+ const list = load();
88
+ if (list === null) return true;
89
+ if (list.length === 0 || typeof directory !== 'string' || directory.length === 0) return false;
90
+ const target = resolve(directory);
91
+ if (list.some((root) => inside(root, target))) return true;
92
+ let real = target;
93
+ try {
94
+ real = realpathSync(target);
95
+ } catch {
96
+ // A folder that does not exist has no other spelling.
97
+ }
98
+ return real !== target && list.some((root) => inside(root, real));
99
+ };
100
+ };
@@ -0,0 +1,65 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { mkdir, mkdtemp, readFile, rm, symlink, writeFile } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+
6
+ import { createSandboxedFoldersReader, createSandboxedFoldersStore, sandboxedFoldersFile } from './sandboxed-folders.js';
7
+
8
+ describe('sandboxed folder record', () => {
9
+ it('lists nothing before the first write, then the folders and everything inside them', async () => {
10
+ const dataDir = await mkdtemp(join(tmpdir(), 'pichamber-sandboxed-folders-'));
11
+ const file = sandboxedFoldersFile(dataDir);
12
+ const isSandboxed = createSandboxedFoldersReader({ file });
13
+ expect(isSandboxed('/work/a')).toBe(false);
14
+
15
+ const store = createSandboxedFoldersStore({ dataDir });
16
+ await store.set(['/work/b', '/work/a', '/work/a']);
17
+ expect(JSON.parse(await readFile(file, 'utf8')).directories).toEqual(['/work/a', '/work/b']);
18
+ expect(isSandboxed('/work/a')).toBe(true);
19
+ expect(isSandboxed('/work/a/src')).toBe(true);
20
+ expect(isSandboxed('/work/ab')).toBe(false);
21
+
22
+ await store.set(['/work/b']);
23
+ expect(isSandboxed('/work/a')).toBe(false);
24
+ await store.set([]);
25
+ expect(isSandboxed('/work/b')).toBe(false);
26
+ });
27
+
28
+ it('puts the list back when its file was deleted or changed', async () => {
29
+ const dataDir = await mkdtemp(join(tmpdir(), 'pichamber-sandboxed-folders-'));
30
+ const file = sandboxedFoldersFile(dataDir);
31
+ const store = createSandboxedFoldersStore({ dataDir });
32
+ await store.set(['/work/a']);
33
+ await rm(file);
34
+ await store.set(['/work/a']);
35
+ expect(JSON.parse(await readFile(file, 'utf8')).directories).toEqual(['/work/a']);
36
+ await writeFile(file, JSON.stringify({ version: 1, directories: [] }));
37
+ await store.set(['/work/a']);
38
+ expect(createSandboxedFoldersReader({ file })('/work/a')).toBe(true);
39
+ });
40
+
41
+ it('matches a folder that reaches a sandboxed one through a symlink', async () => {
42
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-sandboxed-folders-link-'));
43
+ const project = join(root, 'project');
44
+ await mkdir(join(project, 'src'), { recursive: true });
45
+ await symlink(project, join(root, 'alias'));
46
+ await createSandboxedFoldersStore({ dataDir: root }).set([project]);
47
+ const isSandboxed = createSandboxedFoldersReader({ file: sandboxedFoldersFile(root) });
48
+ expect(isSandboxed(join(root, 'alias'))).toBe(true);
49
+ expect(isSandboxed(join(root, 'alias', 'src'))).toBe(true);
50
+ expect(isSandboxed(join(root, 'elsewhere'))).toBe(false);
51
+ });
52
+
53
+ it('treats an unreadable record as every folder, and refuses a list too long to record', async () => {
54
+ const dataDir = await mkdtemp(join(tmpdir(), 'pichamber-sandboxed-folders-bad-'));
55
+ await mkdir(join(dataDir, 'pi'), { recursive: true });
56
+ await writeFile(sandboxedFoldersFile(dataDir), 'not json');
57
+ expect(createSandboxedFoldersReader({ file: sandboxedFoldersFile(dataDir) })('/anything')).toBe(true);
58
+
59
+ const store = createSandboxedFoldersStore({ dataDir });
60
+ await expect(store.set(Array.from({ length: 4097 }, (_, index) => `/work/${index}`))).rejects.toMatchObject({ code: 'SANDBOXED_FOLDERS_FULL' });
61
+ // The refused list wrote nothing; the next one replaces the bad file.
62
+ await store.set(['/work/c']);
63
+ expect(createSandboxedFoldersReader({ file: sandboxedFoldersFile(dataDir) })('/anything')).toBe(false);
64
+ });
65
+ });