@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
@@ -74,6 +74,17 @@ const normalizeRetryLimit = (value) => {
74
74
  return value;
75
75
  };
76
76
 
77
+ // How extensions are told to draw their UI. `terminal` (the default) reports
78
+ // Pi's TUI mode so `ctx.ui.custom()` components render; `dialogs` reports RPC
79
+ // mode so extensions that branch on `ctx.mode` use Pi's standard dialogs.
80
+ export const PI_EXTENSION_UI_MODES = ['terminal', 'dialogs'];
81
+
82
+ const normalizeExtensionUi = (value) => {
83
+ if (value === undefined || value === null) return undefined;
84
+ if (!PI_EXTENSION_UI_MODES.includes(value)) throw invalidSettings();
85
+ return value;
86
+ };
87
+
77
88
  const normalize = (value) => {
78
89
  if (!value || typeof value !== 'object' || Array.isArray(value)) throw invalidSettings();
79
90
  const model = normalizeModel(value.defaultModel);
@@ -89,6 +100,7 @@ const normalize = (value) => {
89
100
  fallbackThinking = undefined;
90
101
  }
91
102
  const retryLimit = normalizeRetryLimit(value.defaultRetryLimit);
103
+ const extensionUi = normalizeExtensionUi(value.extensionUi);
92
104
  return {
93
105
  version: 1,
94
106
  ...(model ? { defaultModel: model } : {}),
@@ -97,6 +109,7 @@ const normalize = (value) => {
97
109
  ...(Object.keys(thinkingByModel).length > 0 ? { defaultThinkingByModel: thinkingByModel } : {}),
98
110
  ...(fallbackThinking ? { defaultThinking: fallbackThinking } : {}),
99
111
  ...(retryLimit !== undefined ? { defaultRetryLimit: retryLimit } : {}),
112
+ ...(extensionUi !== undefined ? { extensionUi } : {}),
100
113
  };
101
114
  };
102
115
 
@@ -133,6 +146,7 @@ export const createPiSettingsStore = ({ file = join(resolvePiChamberDataDir(), '
133
146
  ...(Object.hasOwn(patch, 'smallModel') ? { smallModel: patch.smallModel } : {}),
134
147
  ...(Object.hasOwn(patch, 'walkthroughModel') ? { walkthroughModel: patch.walkthroughModel } : {}),
135
148
  ...(Object.hasOwn(patch, 'defaultRetryLimit') ? { defaultRetryLimit: patch.defaultRetryLimit } : {}),
149
+ ...(Object.hasOwn(patch, 'extensionUi') ? { extensionUi: patch.extensionUi } : {}),
136
150
  defaultThinkingByModel: Object.hasOwn(patch, 'defaultThinkingByModel')
137
151
  ? mergeThinkingByModel(current.defaultThinkingByModel ?? {}, patch.defaultThinkingByModel)
138
152
  : (current.defaultThinkingByModel ?? {}),
@@ -132,6 +132,17 @@ describe('Pi settings sidecar', () => {
132
132
  await expect(store.read()).resolves.toEqual({ version: 1, defaultRetryLimit: 3 });
133
133
  });
134
134
 
135
+ it('round-trips the extension UI mode, rejects unknown modes, and clears with null', async () => {
136
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-pi-settings-'));
137
+ const file = join(root, 'pi', 'settings.json');
138
+ const store = createPiSettingsStore({ file });
139
+ await expect(store.update({ extensionUi: 'dialogs' })).resolves.toEqual({ version: 1, extensionUi: 'dialogs' });
140
+ await expect(store.update({ defaultRetryLimit: 4 })).resolves.toEqual({ version: 1, defaultRetryLimit: 4, extensionUi: 'dialogs' });
141
+ await expect(store.update({ extensionUi: 'tui' })).rejects.toMatchObject({ code: 'PI_SETTINGS_INVALID' });
142
+ await expect(store.read()).resolves.toEqual({ version: 1, defaultRetryLimit: 4, extensionUi: 'dialogs' });
143
+ await expect(store.update({ extensionUi: null })).resolves.toEqual({ version: 1, defaultRetryLimit: 4 });
144
+ });
145
+
135
146
  it('preserves explicit per-run retry over stored default', async () => {
136
147
  const resolveEffective = (explicit, stored) => {
137
148
  if (Number.isInteger(explicit)) return explicit;
@@ -4,6 +4,7 @@ import { dirname, join } from 'node:path';
4
4
  import { writeFileAtomic } from '../fs/atomic-write.js';
5
5
  import { resolvePiChamberDataDir } from '../pichamber-data-dir.js';
6
6
  import { withCrossProcessLock } from '../server/cross-process-lock.js';
7
+ import { mergeProjectSandboxSetting, mergeSandboxDefaults, ProjectSandboxSettingError, readSandboxDefaults } from './sandbox/project-sandbox-setting.js';
7
8
 
8
9
  const MAX_SETTINGS_BYTES = 2 * 1024 * 1024;
9
10
  const PORTABLE_SETTINGS_MARKER = '__pichamberSettingsScope';
@@ -56,7 +57,7 @@ const PORTABLE_FIELDS = new Set([
56
57
  // still be consumed by the existing authenticated API without entering the
57
58
  // portable file.
58
59
  const LOCAL_FIELDS = new Set([
59
- 'lastDirectory', 'homeDirectory', 'projects', 'activeProjectId',
60
+ 'lastDirectory', 'homeDirectory', 'projects', 'activeProjectId', 'sandboxDefaults',
60
61
  'securityScopedBookmarks', 'pinnedDirectories', 'openInAppId',
61
62
  'terminalShell', 'terminalLoginShells', 'desktopLanAccessEnabled',
62
63
  'desktopKeepAwakeEnabled', 'desktopProcessPerformanceRecordingEnabled',
@@ -156,6 +157,28 @@ export const createDockerInitialLocalSettings = () => {
156
157
  };
157
158
  };
158
159
 
160
+ // A project's `sandbox` setting changes only through `setProjectSandbox`.
161
+ // Clients write the whole project list back and drop fields they do not
162
+ // know, so the stored setting is carried over by project id and any value a
163
+ // client sends is ignored. Without this an older client could turn a
164
+ // project's sandbox off just by reordering projects.
165
+ const withoutSandbox = (project) => {
166
+ if (!isRecord(project) || !Object.hasOwn(project, 'sandbox')) return project;
167
+ const { sandbox: _ignored, ...rest } = project;
168
+ return rest;
169
+ };
170
+
171
+ const carrySandboxSettings = (incoming, current) => {
172
+ if (!Array.isArray(incoming)) return incoming;
173
+ const stored = new Map((Array.isArray(current) ? current : [])
174
+ .filter((project) => isRecord(project) && typeof project.id === 'string' && Object.hasOwn(project, 'sandbox'))
175
+ .map((project) => [project.id, project.sandbox]));
176
+ return incoming.map((project) => {
177
+ const next = withoutSandbox(project);
178
+ return isRecord(next) && stored.has(next.id) ? { ...next, sandbox: stored.get(next.id) } : next;
179
+ });
180
+ };
181
+
159
182
  const writeRecord = async (file, value, fs) => {
160
183
  const serialized = `${JSON.stringify(value, null, 2)}\n`;
161
184
  if (Buffer.byteLength(serialized) > MAX_SETTINGS_BYTES) throw new Error('UI_SETTINGS_INVALID');
@@ -185,6 +208,13 @@ export const createPiUiSettingsStore = ({
185
208
  ...selectFields(runtimeRoot, LOCAL_FIELDS),
186
209
  ...selectFields(portableRoot, LOCAL_FIELDS),
187
210
  };
211
+ // A legacy flat settings.json may have come from another machine; a
212
+ // sandbox setting is only ever made on this host.
213
+ delete migratedRuntime.sandboxDefaults;
214
+ if (Object.hasOwn(runtimeRoot, 'sandboxDefaults')) migratedRuntime.sandboxDefaults = runtimeRoot.sandboxDefaults;
215
+ if (Object.hasOwn(selectFields(portableRoot, LOCAL_FIELDS), 'projects')) {
216
+ migratedRuntime.projects = carrySandboxSettings(portableRoot.projects, runtimeRoot.projects);
217
+ }
188
218
  const migratedPortable = {
189
219
  [PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
190
220
  ...selectFields(portableRoot, PORTABLE_FIELDS),
@@ -239,6 +269,12 @@ export const createPiUiSettingsStore = ({
239
269
  const current = await readLocked();
240
270
  const portableChanges = selectFields(changes, PORTABLE_FIELDS);
241
271
  const localChanges = selectFields(changes, LOCAL_FIELDS);
272
+ if (Object.hasOwn(localChanges, 'projects')) {
273
+ localChanges.projects = carrySandboxSettings(localChanges.projects, current.projects);
274
+ }
275
+ // Like a project's setting, the sandbox default changes only through
276
+ // `setSandboxDefaults`.
277
+ delete localChanges.sandboxDefaults;
242
278
  const nextPortable = {
243
279
  [PORTABLE_SETTINGS_MARKER]: PORTABLE_SETTINGS_VERSION,
244
280
  ...selectFields(current, PORTABLE_FIELDS),
@@ -254,5 +290,55 @@ export const createPiUiSettingsStore = ({
254
290
  });
255
291
  };
256
292
 
257
- return { file, runtimeFile, read, write };
293
+ /**
294
+ * Save one project's sandbox setting (host-local only). `patch` holds
295
+ * `mode`, `allowHosts`, `allowLocalPorts`, `extraFolders`, or several; a
296
+ * field it leaves out keeps the stored value. The merge happens under the
297
+ * store lock, so a device that only adds a host cannot turn off a sandbox
298
+ * another device just turned on.
299
+ */
300
+ const setProjectSandbox = async (projectId, patch) => {
301
+ // Refuse a malformed patch before taking the lock.
302
+ mergeProjectSandboxSetting(null, patch);
303
+ return runMutation(async () => {
304
+ const current = await readLocked();
305
+ const projects = Array.isArray(current.projects) ? current.projects : [];
306
+ const stored = typeof projectId === 'string'
307
+ ? projects.find((project) => isRecord(project) && project.id === projectId)
308
+ : undefined;
309
+ if (!stored) throw new ProjectSandboxSettingError(undefined, 'PROJECT_NOT_FOUND');
310
+ const sandbox = mergeProjectSandboxSetting(stored, patch);
311
+ const nextRuntime = {
312
+ ...selectFields(current, LOCAL_FIELDS),
313
+ projects: projects.map((project) => (isRecord(project) && project.id === projectId ? { ...project, sandbox } : project)),
314
+ };
315
+ await writeRecord(runtimeFile, nextRuntime, fs);
316
+ return { ...selectFields(current, PORTABLE_FIELDS), ...selectFields(nextRuntime, LOCAL_FIELDS) };
317
+ });
318
+ };
319
+
320
+ /**
321
+ * Save the host's sandbox default (host-local only). `patch` holds `mode`,
322
+ * `allowHosts`, or both; a field it leaves out keeps the stored value. The
323
+ * merge happens under the store lock, so a device that only adds a host
324
+ * cannot undo a mode another device just set.
325
+ */
326
+ const setSandboxDefaults = async (patch) => {
327
+ // Refuse a malformed patch before taking the lock.
328
+ mergeSandboxDefaults(readSandboxDefaults({}).defaults, patch);
329
+ return runMutation(async () => {
330
+ const current = await readLocked();
331
+ const stored = readSandboxDefaults(current);
332
+ // The mode of an unreadable stored default is a placeholder (off),
333
+ // while projects that follow it stay closed. A patch without a mode
334
+ // would store that placeholder and run them unsandboxed.
335
+ if (stored.invalid && patch.mode === undefined) throw new ProjectSandboxSettingError('MODE');
336
+ const sandboxDefaults = mergeSandboxDefaults(stored.defaults, patch);
337
+ const nextRuntime = { ...selectFields(current, LOCAL_FIELDS), sandboxDefaults };
338
+ await writeRecord(runtimeFile, nextRuntime, fs);
339
+ return { ...selectFields(current, PORTABLE_FIELDS), ...selectFields(nextRuntime, LOCAL_FIELDS) };
340
+ });
341
+ };
342
+
343
+ return { file, runtimeFile, read, write, setProjectSandbox, setSandboxDefaults };
258
344
  };
@@ -407,4 +407,122 @@ describe('Pi UI settings store', () => {
407
407
  expect(await readlink(file)).toBe('../dotfiles/settings.json');
408
408
  expect(await readJson(target)).toMatchObject({ themeId: 'new' });
409
409
  });
410
+
411
+ describe('project sandbox setting', () => {
412
+ const nono = { mode: 'nono', allowHosts: ['registry.npmjs.org'], allowLocalPorts: [8080], extraFolders: [{ path: '/srv/docs', access: 'read' }] };
413
+
414
+ it('stores the setting with the project in host-local state and survives a restart', async () => {
415
+ const { file, runtimeFile, store } = await makeStore();
416
+ await store.write({ projects: [{ id: 'one', path: '/work/one' }, { id: 'two', path: '/work/two' }] });
417
+
418
+ await store.setProjectSandbox('one', nono);
419
+
420
+ const restarted = createPiUiSettingsStore({ file, runtimeFile });
421
+ await expect(restarted.read()).resolves.toMatchObject({
422
+ projects: [{ id: 'one', path: '/work/one', sandbox: nono }, { id: 'two', path: '/work/two' }],
423
+ });
424
+ expect((await readJson(runtimeFile)).projects[0].sandbox).toEqual(nono);
425
+ // The portable file, the one copied between machines, never holds it.
426
+ expect(JSON.stringify(await readJson(file))).not.toContain('sandbox');
427
+ });
428
+
429
+ it('keeps the setting when a client rewrites the project list without it, and ignores one a client sends', async () => {
430
+ const { store } = await makeStore();
431
+ await store.write({ projects: [{ id: 'one', path: '/work/one' }, { id: 'two', path: '/work/two' }] });
432
+ await store.setProjectSandbox('one', nono);
433
+
434
+ // Clients send the whole list back (for example after a reorder) and
435
+ // drop fields they do not know. Neither path may change the setting.
436
+ await store.write({
437
+ projects: [
438
+ { id: 'two', path: '/work/two', sandbox: { mode: 'nono', allowHosts: [], allowLocalPorts: [], extraFolders: [] } },
439
+ { id: 'one', path: '/work/one', label: 'One' },
440
+ ],
441
+ });
442
+
443
+ await expect(store.read()).resolves.toMatchObject({
444
+ projects: [{ id: 'two', path: '/work/two' }, { id: 'one', path: '/work/one', label: 'One', sandbox: nono }],
445
+ });
446
+ expect((await store.read()).projects[0].sandbox).toBeUndefined();
447
+ });
448
+
449
+ it('turns the setting off, and refuses an unknown project or an invalid setting', async () => {
450
+ const { store } = await makeStore();
451
+ await store.write({ projects: [{ id: 'one', path: '/work/one' }] });
452
+ await store.setProjectSandbox('one', nono);
453
+ await store.setProjectSandbox('one', { ...nono, mode: 'off' });
454
+ await expect(store.read()).resolves.toMatchObject({ projects: [{ id: 'one', sandbox: { ...nono, mode: 'off' } }] });
455
+
456
+ await expect(store.setProjectSandbox('missing', nono)).rejects.toMatchObject({ code: 'PROJECT_NOT_FOUND' });
457
+ for (const [invalid, reason] of [
458
+ [{ mode: 'docker' }, undefined],
459
+ [{ mode: 'nono', allowHosts: ['https://x'] }, 'HOSTS'],
460
+ [{ mode: 'nono', allowLocalPorts: [443] }, 'REFUSED_PORT'],
461
+ [{ mode: 'nono', allowLocalPorts: [70000] }, 'PORTS'],
462
+ [{ mode: 'nono', extraFolders: [{ path: 'relative', access: 'read' }] }, 'FOLDERS'],
463
+ [{ mode: 'nono', extraFolders: [{ path: '/srv', access: 'write' }] }, 'FOLDERS'],
464
+ ]) {
465
+ const refused = await store.setProjectSandbox('one', invalid).catch((error) => error);
466
+ expect(refused).toMatchObject({ code: 'INVALID_SANDBOX_SETTING' });
467
+ expect(refused.reason).toBe(reason);
468
+ }
469
+ });
470
+
471
+ it('merges the fields a project update names, so a stale copy cannot turn a sandbox off', async () => {
472
+ const { store, runtimeFile } = await makeStore();
473
+ await store.write({ projects: [{ id: 'one', path: '/work/one' }] });
474
+ // A project with no setting starts from the default with empty lists.
475
+ await store.setProjectSandbox('one', { allowHosts: ['github.com'] });
476
+ await expect(store.read()).resolves.toMatchObject({
477
+ projects: [{ id: 'one', sandbox: { mode: 'default', allowHosts: ['github.com'], allowLocalPorts: [], extraFolders: [] } }],
478
+ });
479
+ // One device turns it on; another, still showing Off, adds a port.
480
+ await store.setProjectSandbox('one', { mode: 'nono' });
481
+ await store.setProjectSandbox('one', { allowLocalPorts: [8080] });
482
+ await expect(store.read()).resolves.toMatchObject({
483
+ projects: [{ id: 'one', sandbox: { mode: 'nono', allowHosts: ['github.com'], allowLocalPorts: [8080], extraFolders: [] } }],
484
+ });
485
+ // No field at all is refused.
486
+ await expect(store.setProjectSandbox('one', {})).rejects.toMatchObject({ code: 'INVALID_SANDBOX_SETTING' });
487
+
488
+ // An unreadable stored setting runs sandboxed, so that is what a
489
+ // partial update starts from.
490
+ const state = JSON.parse(await readFile(runtimeFile, 'utf8'));
491
+ state.projects[0].sandbox = { mode: 'sometimes' };
492
+ await writeFile(runtimeFile, JSON.stringify(state));
493
+ await store.setProjectSandbox('one', { allowHosts: ['npmjs.org'] });
494
+ await expect(store.read()).resolves.toMatchObject({
495
+ projects: [{ id: 'one', sandbox: { mode: 'nono', allowHosts: ['npmjs.org'], allowLocalPorts: [], extraFolders: [] } }],
496
+ });
497
+ });
498
+
499
+ it('does not store the placeholder mode of an unreadable default: an update must name a mode', async () => {
500
+ const { store, runtimeFile } = await makeStore();
501
+ await store.write({ projects: [{ id: 'one', path: '/work/one' }] });
502
+ const state = JSON.parse(await readFile(runtimeFile, 'utf8'));
503
+ await writeFile(runtimeFile, JSON.stringify({ ...state, sandboxDefaults: { mode: 'sometimes' } }));
504
+ for (const patch of [{ acceptedLimits: [] }, { allowHosts: ['github.com'] }]) {
505
+ const refused = await store.setSandboxDefaults(patch).catch((error) => error);
506
+ expect(refused).toMatchObject({ code: 'INVALID_SANDBOX_SETTING', reason: 'MODE' });
507
+ }
508
+ expect(JSON.parse(await readFile(runtimeFile, 'utf8')).sandboxDefaults).toEqual({ mode: 'sometimes' });
509
+ await store.setSandboxDefaults({ mode: 'nono', allowHosts: ['github.com'] });
510
+ expect((await store.read()).sandboxDefaults).toEqual({ mode: 'nono', allowHosts: ['github.com'], acceptedLimits: [] });
511
+ // Readable again: a later update may leave the mode out.
512
+ await store.setSandboxDefaults({ allowHosts: [] });
513
+ expect((await store.read()).sandboxDefaults.mode).toBe('nono');
514
+ });
515
+
516
+ it('never takes a sandbox setting from a settings file copied from another machine', async () => {
517
+ const root = await mkdtemp(join(tmpdir(), 'pichamber-ui-settings-'));
518
+ const file = join(root, 'settings.json');
519
+ const runtimeFile = join(root, 'runtime-state.json');
520
+ // A legacy flat file still carries projects; its local fields migrate,
521
+ // but a sandbox setting is only ever made on this host.
522
+ await writeFile(file, JSON.stringify({ projects: [{ id: 'one', path: '/work/one', sandbox: nono }] }));
523
+ const store = createPiUiSettingsStore({ file, runtimeFile });
524
+ const read = await store.read();
525
+ expect(read.projects).toEqual([{ id: 'one', path: '/work/one' }]);
526
+ });
527
+ });
410
528
  });
@@ -0,0 +1,198 @@
1
+ # PiChamber plugins (server)
2
+
3
+ ## Purpose
4
+
5
+ A plugin is a Pi package with a `pichamber` block in its `package.json`. The
6
+ `pi.extensions[0]` module is the agent half; the `pichamber` block declares
7
+ state and UI contributions. This module owns the bundled plugin list, the
8
+ manifest contract, the stored enabled set and state, measured agent impact,
9
+ the public routes, and pushing the config to the session daemon. The daemon
10
+ side is `../pi/session-daemon/plugin-host.js`.
11
+
12
+ Nothing reaches the agent unless the user turned it on: bundled plugins ship
13
+ disabled, and a disabled plugin loads no agent code.
14
+
15
+ ## Entrypoints
16
+
17
+ - `manifest.js` parses a package fail-closed (`PluginManifestError`, code
18
+ `INVALID_PLUGIN_MANIFEST`). Fields: `apiVersion: 1`, `id` (kebab case, at most
19
+ 40 characters), `name`, `description`, `icon` (a Remix sprite name),
20
+ `defaultEnabled` (must be false for bundled plugins), `replaceable`
21
+ (maps to the Pi factory's `replaceable`), `state` (`{ type: 'boolean' | 'enum',
22
+ scope: 'global' | 'project', default, label, description?, options? }` per key),
23
+ `contributes.composerToggles` (`{ id, state, label, icon, description? }`,
24
+ bound to a boolean key; optional), `contributes.settings` (ordered keys,
25
+ never a key a composer toggle sets), and
26
+ `contributes.ui` (native UI id). The agent half must be a `.js`/`.mjs`
27
+ module inside the package. The package `version` is the plugin version,
28
+ its `name` is `packageName`, and its `keywords` (lowercased, at most 16,
29
+ without the listing keywords `pi-package` and `pichamber-plugin`) are
30
+ `keywords`, which the marketplace matches a search against.
31
+ - `registry.js` reads `packages/web/plugins/registry.json`
32
+ (`{ version: 1, plugins: [id] }`) and loads each listed folder. An invalid
33
+ plugin is skipped with a logged reason; the others still load. A missing or
34
+ malformed registry file is `PLUGINS_UNREADABLE`, never an empty list. The
35
+ entry is resolved through links and must stay in its package.
36
+ - `store.js` owns `<dataDir>/pi/plugins.json`:
37
+ `{ version: 1, enabled: { [id]: bool }, state: { [id]: { global: {..}, projects: { [dir]: {..} }, sessions: { [sessionId]: {..} } } } }`.
38
+ `sessions` holds composer switches: a session's own values, only for keys
39
+ a composer toggle names (`isSessionStateKey`), keyed by Pi session id
40
+ (`[A-Za-z0-9][A-Za-z0-9._:-]*`, at most 256 characters). The server
41
+ stores any valid value it is sent; the UI sends `null` when a switch goes
42
+ back to its default, so a session normally holds only values that differ
43
+ from it. A composer toggle's key has no global or project value:
44
+ `resolvePluginState` always starts it from the manifest default (ignoring
45
+ any stored by an older build) and `setState` refuses it, so every new
46
+ session starts from the default while the plugin is on. Each plugin
47
+ keeps at most 1000 sessions; setting one moves it last, and the least
48
+ recently set are dropped past the cap with a logged warning. Deleting a session
49
+ (`DELETE /api/pi/sessions/:id`, through `registerPiRuntimeRoutes`'
50
+ `onSessionDeleted`) drops its values and pushes the config.
51
+ Files written before sessions existed read as `sessions: {}`.
52
+ A missing file is empty; a malformed one is `PLUGINS_UNREADABLE` for reads
53
+ and writes (it is never overwritten). Writes re-read under an in-process
54
+ chain and a cross-process lock, then replace the file atomically, so a
55
+ write never drops another writer's change. Unknown ids and keys are kept.
56
+ Values are checked against the manifest when resolved: project value over
57
+ global value over default, and a stored value of the wrong type, option, or
58
+ scope falls back to the default. Project directories are absolute and
59
+ normalized (`~` expands to the home folder).
60
+ - `impact.js` imports the agent half and calls it once with a recording
61
+ stand-in for the Pi API and a `pichamber` handle with default state (its `ui` calls resolve with nothing, `openUrl` with `false`). It reports
62
+ `{ tools: [{ name, exposure, tokens }], hooks, commands }`. `tokens` is
63
+ `ceil(chars / 4)` of JSON `{ name, description, parameters }`. `hooks` lists
64
+ the prompt-affecting events the plugin handles (`PROMPT_AFFECTING_EVENTS`:
65
+ `resources_discover`, `input`, `before_agent_start`, `context`,
66
+ `context_with_system`, `before_provider_request`, `tool_result`,
67
+ `message_end`). Results are cached per id and version. A plugin that throws,
68
+ has no default export, or takes over 5 seconds reports `impact: null` with a
69
+ short `impactError`. Measurement runs bundled code in the server process.
70
+ - `service.js` combines the above: public views, mutations, and the daemon
71
+ config.
72
+ - `routes.js` registers the public routes. `index.js` wires them; the global
73
+ `/api` auth gate applies.
74
+ - `daemon-sync.js` pushes the config to the daemon (below).
75
+
76
+ ## HTTP contract
77
+
78
+ - `GET /api/pi/plugins?directory=<absolute dir, optional>` answers
79
+ `{ plugins: [PluginView] }`. State is resolved for `directory`.
80
+ - `PUT /api/pi/plugins/:id` with `{ enabled: boolean }` answers the view.
81
+ - `PUT /api/pi/plugins/:id/state` with `{ key, value, directory? }` answers the
82
+ view resolved for `directory`. The scope comes from the manifest; a
83
+ project-scoped key needs `directory`. These are the Settings values every
84
+ session uses. A key a composer toggle sets is refused here
85
+ (`INVALID_PLUGIN_REQUEST`); it changes per session only.
86
+ - `GET /api/pi/plugins/sessions/:sessionId` answers
87
+ `{ sessionId, overrides: { [pluginId]: { [key]: value } } }`, plugins with
88
+ values only.
89
+ - `PUT /api/pi/plugins/:id/sessions/:sessionId` with `{ key, value }` sets one
90
+ session's own value; `value: null` clears it. Answers
91
+ `{ id, sessionId, overrides }` for that plugin. Only keys a composer toggle
92
+ names are accepted.
93
+ - Errors: 404 `{ error: { code: 'PLUGIN_NOT_FOUND' } }`, 400
94
+ `INVALID_PLUGIN_REQUEST`, 500 `PLUGINS_UNREADABLE`.
95
+
96
+ `PluginView` is `{ id, name, description, icon, version, keywords, bundled,
97
+ enabled, state, stateSchema, contributes, impact, impactError? }`. It never
98
+ carries module paths.
99
+
100
+ `service.bundledPackageNames()` lists the npm names of the bundled plugins.
101
+ The marketplace (`../marketplace/`) leaves them out of every answer, since
102
+ PiChamber already ships them.
103
+
104
+ ## Daemon push
105
+
106
+ The daemon never reads plugin state or the enabled set from disk: under a
107
+ nono sandbox it cannot read PiChamber's data folder. The server sends the
108
+ private `plugins.configure` command with
109
+ `{ plugins: [{ id, entry, replaceable, state: { global, projects, sessions } }] }`,
110
+ enabled plugins only. `global` holds every key resolved without a project;
111
+ `projects[dir]` holds the project-scoped values that differ;
112
+ `sessions[sessionId]` holds a session's own values. The daemon resolves
113
+ `{ ...global, ...projects[dir], ...sessions[sessionId] }`. A composer switch
114
+ is a committed change like any other, so the push runs before the next daemon
115
+ request, including the prompt sent right after it.
116
+
117
+ When it pushes (`daemon-sync.js`):
118
+
119
+ - A daemon process is identified by its `streamEpoch`, a random id picked at
120
+ daemon start and returned by every `runtime.health`. The supervisor probes
121
+ health before each request, subscription, and health call and then runs its
122
+ `onDaemonReady` hook with the probe result and a request function bound to
123
+ that daemon. The sync pushes when it has not configured that epoch at the
124
+ current revision, so a new, restarted, or reused daemon (after a server
125
+ restart) is configured before the request runs.
126
+ - After each committed change the routes call `changed()`, which bumps the
127
+ revision and runs a health probe, which pushes.
128
+ - At server start, after the daemon starts, `index.js` runs one health probe.
129
+ - Pushes are serialized, and each builds the config when it runs, so an older
130
+ config never lands after a newer one. Concurrent requests share one push.
131
+ - A failed push (daemon error, unreadable store) logs and is retried on a
132
+ later probe, at most every 2 seconds for the same epoch and revision. It
133
+ never fails the request. A daemon that was never configured runs with every
134
+ plugin off.
135
+ - The last 32 epochs are remembered, so a daemon pool is configured per
136
+ daemon as each is reached. A change probes the profile daemon only; others
137
+ pick it up on their next request.
138
+ - A sandboxed project's daemon gets its hook from
139
+ `onDaemonReadyFor({ roots })`, the folders it owns. Its config is
140
+ `daemonConfig({ roots })`: `projects` keeps only folders at or below those
141
+ roots, so sandboxed code never learns where other projects live.
142
+ `sessions` holds opaque ids and values and is sent whole.
143
+
144
+ ## Bundled plugins
145
+
146
+ Listed in `packages/web/plugins/registry.json`, one folder each:
147
+
148
+ - `visuals/`: two tools. `render_html` reads a page from the call's `html`
149
+ or from a file inside the session's folder, and returns it as the result
150
+ details for the UI to draw. `render_choices` (`choices.js`) takes a
151
+ question and 2 to 6 options, each a page (`html`, or `path` to an `.html`
152
+ file) or an image file in the project (`path` to a `.png`, `.jpg`, `.webp`,
153
+ `.gif` or `.svg`, sent as a `data:` URL). It reports the options as a
154
+ partial result, waits a turn of the event loop so they reach clients first,
155
+ then asks with `pichamber.ui.choose(ctx, ...)` and its own tool call id, and returns the
156
+ chosen option and the user's note. The details are
157
+ `{ title, options, answer }`: `answer` is `{ id, note? }`, `null` when the
158
+ question was closed, and absent when the client could not ask. Under plain
159
+ Pi it asks with `ctx.ui.select` (labels only, the variants are not drawn).
160
+ `files.js` resolves every path through links and keeps it inside the
161
+ project. Limits: 512,000 characters a page, 750 KB an image before
162
+ encoding, 1.5 million characters for one call's options together, since
163
+ they are stored in the session file. State `allowNetwork` only: no composer
164
+ toggle, so both tools are in every session while the plugin is on. It adds
165
+ its tools at `session_start` and uses the `pichamber` handle only for `render_choices`.
166
+ - `subagents/`: the `subagent` tool, adapted from Pi's MIT example (credit in
167
+ its `LICENSE`). Runs `pi --mode json -p --no-session` children through the
168
+ daemon's Pi CLI (`process.argv[1]`), so a sandboxed daemon's children stay
169
+ in its sandbox. Bundled agents (`agents/*.md`) use the session's model and
170
+ are overridden by user or project agents of the same name. Details are the
171
+ compact `{ mode, agentScope, results }` shape the UI reads, with updates at
172
+ most every 250 ms. `replaceable`, so a user's own `subagent` extension wins.
173
+ State `on`, set by its composer toggle only (default on).
174
+
175
+ Sub-agents switches its tool with the `on` value through `pi.setActiveTools`,
176
+ so a composer toggle takes effect without recreating the runtime. It reads the
177
+ session id from `ctx.sessionManager.getSessionId()` at `session_start` and
178
+ pass it to `pichamber.state(cwd, sessionId)`, so a composer switch changes that
179
+ session only. It adds or removes only its own tool, and only at
180
+ `session_start` or when their resolved `on` value flips, so an unrelated
181
+ state push leaves a tool list the user edited as it is.
182
+
183
+ ## Deliberate limits
184
+
185
+ - Bundled plugins only. User installs and frame-hosted UI are out of scope.
186
+ - A question is live: a daemon restart or a runtime recreation cancels it,
187
+ and the tool returns as if the user had closed it. A message typed while a
188
+ question waits is queued like any other.
189
+ - A forked session starts with the plugin's defaults, not its parent's
190
+ composer switches.
191
+ - No `plugins.changed` event reaches other devices yet; they see changes on
192
+ their next `GET /api/pi/plugins`.
193
+ - Bundled code is trusted: the server imports it to measure impact, and the
194
+ daemon only imports modules under `packages/web/plugins/`.
195
+
196
+ ## Replaced plugins
197
+
198
+ Pi leaves a `replaceable` extension out when another extension registers the same tool, command, or flag. Bundled plugins load as replaceable inline factories, so a plugin can be on in Settings and still not loaded (the user's own `subagent` extension replaces Sub-agents, for example). The server does nothing about this itself. The daemon reports it in the `replaced` field of the extension config answers (see `extension-replacements.js` and `plugin-host.js` in `../pi/session-daemon/DOCUMENTATION.md`), and the public routes `GET /api/pi/extensions/config`, `PUT /api/pi/extensions/config/:id`, `POST /api/pi/extensions/packages`, `POST /api/pi/extensions/packages/:id/update`, and `DELETE /api/pi/extensions/packages/:id` pass it through `projectExtensionConfig` in `../pi/routes.js`. That projection keeps only `kind` (`plugin` or `builtin`), `id`, and the optional `registers` and `by`. It drops an entry with a bad kind or id, leaves out a malformed optional part, and copies nothing else. The field is absent when no live runtime answered, which means unknown, not "nothing replaced".
@@ -0,0 +1,88 @@
1
+ // Pushes the plugin config to every daemon process the server talks to.
2
+ //
3
+ // A daemon process is identified by its `streamEpoch`, a random id it picks at
4
+ // start and reports in every health probe. The supervisor probes health before
5
+ // each request and hands the result to `onDaemonReady`, so a push happens:
6
+ // - before the first request to a daemon process this server has not
7
+ // configured (a new daemon, a restarted one, or one reused from an earlier
8
+ // server run),
9
+ // - after every change (`changed()` bumps the revision and probes), and
10
+ // - again on a later request when a push failed (at most every `retryDelayMs`).
11
+ // A failed push only logs. The request it precedes still runs; a daemon that
12
+ // was never configured runs with every plugin off.
13
+ //
14
+ // A sandboxed project's daemon gets its own hook from `onDaemonReadyFor`,
15
+ // whose scope (`{ roots }`) reaches `buildConfig`, so the config it receives
16
+ // can leave out other projects.
17
+
18
+ const MAX_TRACKED_DAEMONS = 32;
19
+
20
+ export const createPluginDaemonSync = ({
21
+ buildConfig,
22
+ refresh = async () => {},
23
+ logger = console,
24
+ retryDelayMs = 2_000,
25
+ now = Date.now,
26
+ }) => {
27
+ let revision = 0;
28
+ const configured = new Map();
29
+ const inflight = new Map();
30
+ let chain = Promise.resolve();
31
+ let lastFailure = null;
32
+
33
+ const remember = (epoch, pushedRevision) => {
34
+ configured.delete(epoch);
35
+ configured.set(epoch, pushedRevision);
36
+ while (configured.size > MAX_TRACKED_DAEMONS) configured.delete(configured.keys().next().value);
37
+ };
38
+
39
+ const push = (epoch, target, request, scope) => {
40
+ const key = `${epoch}:${target}`;
41
+ const existing = inflight.get(key);
42
+ if (existing) return existing;
43
+ // Serialized so an older config can never land after a newer one. Each
44
+ // push builds the config when it runs, so it carries the latest state.
45
+ const task = chain.then(async () => {
46
+ if (configured.get(epoch) === revision) return;
47
+ const pushing = revision;
48
+ try {
49
+ await request('plugins.configure', await buildConfig(scope));
50
+ remember(epoch, pushing);
51
+ lastFailure = null;
52
+ } catch (error) {
53
+ lastFailure = { epoch, revision: pushing, at: now() };
54
+ logger.warn?.(`[plugins] could not configure the session daemon: ${error?.code ?? error?.message ?? 'unknown error'}`);
55
+ }
56
+ }).finally(() => inflight.delete(key));
57
+ chain = task;
58
+ inflight.set(key, task);
59
+ return task;
60
+ };
61
+
62
+ /**
63
+ * Supervisor hook for a daemon whose config is built with `scope`: runs
64
+ * after every successful health probe. Never throws.
65
+ */
66
+ const onDaemonReadyFor = (scope) => async ({ health, request }) => {
67
+ const epoch = health?.streamEpoch;
68
+ if (typeof epoch !== 'string' || epoch.length === 0 || typeof request !== 'function') return;
69
+ if (configured.get(epoch) === revision) return;
70
+ if (lastFailure && lastFailure.epoch === epoch && lastFailure.revision === revision
71
+ && now() - lastFailure.at < retryDelayMs) return;
72
+ await push(epoch, revision, request, scope);
73
+ };
74
+
75
+ /** The main daemon's hook: its config covers every project. */
76
+ const onDaemonReady = onDaemonReadyFor(undefined);
77
+
78
+ /** Call after a committed change; pushes in the background. */
79
+ const changed = () => {
80
+ revision += 1;
81
+ lastFailure = null;
82
+ void Promise.resolve().then(refresh).catch((error) => {
83
+ logger.warn?.(`[plugins] could not reach the session daemon: ${error?.code ?? error?.message ?? 'unknown error'}`);
84
+ });
85
+ };
86
+
87
+ return { onDaemonReady, onDaemonReadyFor, changed };
88
+ };