@openchamber/web 1.24.1 → 2.0.0

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 (442) hide show
  1. package/bin/cli.test.js +22 -0
  2. package/bin/lib/commands-connect-url.js +3 -8
  3. package/bin/lib/commands-status.js +5 -0
  4. package/bin/lib/commands-tunnel.js +3 -0
  5. package/dist/assets/{CodeMirrorCommentWidgets-DvUH815P.js → CodeMirrorCommentWidgets-hJbl3JX4.js} +1 -1
  6. package/dist/assets/DiffView-BucGEJYa.js +4 -0
  7. package/dist/assets/FilesView-CQcaaAVP.js +17 -0
  8. package/dist/assets/{GitView-Bxuv3dfP.js → GitView-DY4pelsO.js} +4 -4
  9. package/dist/assets/{GuestAttachDialog-B0u3Q5uO.js → GuestAttachDialog-D6mHDTB2.js} +1 -1
  10. package/dist/assets/GuestSurfacePane--DJ7rsmY.js +1 -0
  11. package/dist/assets/{JsonTreeView-BBVPFM5K.js → JsonTreeView-DEXI2NvJ.js} +1 -1
  12. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  13. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  14. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  15. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  16. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  17. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  18. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  19. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  20. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  21. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  22. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  23. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  24. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  25. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  26. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  27. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  28. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  29. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  30. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  31. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  32. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  33. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  34. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  35. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  36. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  37. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  38. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  39. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  40. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  41. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  42. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  43. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  44. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  45. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  46. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  47. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  48. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  49. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  50. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  51. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  52. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  53. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  54. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  55. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  56. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  57. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  58. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  59. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  60. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  61. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  62. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  63. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  64. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  65. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  66. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  67. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  68. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  69. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  70. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  71. package/dist/assets/LinearIssuesView-BTNc-4dN.js +1 -0
  72. package/dist/assets/MarkdownImageGallery-wcUUcf8l.js +1 -0
  73. package/dist/assets/MarkdownRendererImpl-BPe2TVV2.js +12 -0
  74. package/dist/assets/OnboardingScreen-FJUreEgI.js +1 -0
  75. package/dist/assets/{PatchDiff-C4rE5k6z.js → PatchDiff-C0oOkKnO.js} +1 -1
  76. package/dist/assets/PierreDiffViewer-asuSQAsf.js +210 -0
  77. package/dist/assets/PlanView-DGbasNHP.js +5 -0
  78. package/dist/assets/PluginPane-DImv8hV2.js +3 -0
  79. package/dist/assets/SettingsView-DOjuOljf.js +29 -0
  80. package/dist/assets/SettingsWindow-By4cqnqy.js +1 -0
  81. package/dist/assets/SubmoduleDiffSummary-C0P2tXLU.js +1 -0
  82. package/dist/assets/ToolOutputDialog-Cayc-yIM.js +15 -0
  83. package/dist/assets/ToolPartDiffPreview-B0jmpPQz.js +8 -0
  84. package/dist/assets/{VirtualizedFileDiff-CZgXWHjU.js → VirtualizedFileDiff-DsOpvWZD.js} +4 -4
  85. package/dist/assets/{WalkthroughView-wSpED5L4.js → WalkthroughView-CCakjyn9.js} +2 -2
  86. package/dist/assets/appThemeRegistry-Bw5oTm41.js +1 -0
  87. package/dist/assets/{commitAndPush-DZnzlhvc.js → commitAndPush-sGEelpjh.js} +1 -1
  88. package/dist/assets/{computeVirtualFileMetrics-VYnT_A2h.js → computeVirtualFileMetrics-B-4aLf4A.js} +1 -1
  89. package/dist/assets/de-CD9utsNj.js +10 -0
  90. package/dist/assets/es-NNum2rX8.js +16 -0
  91. package/dist/assets/fr-CJLGmduQ.js +14 -0
  92. package/dist/assets/index-B6r0Kv-B.js +1 -0
  93. package/dist/assets/index-DjGPR5vW.js +41 -0
  94. package/dist/assets/index-fCXJ-8Qt.css +1 -0
  95. package/dist/assets/{isDiffPlainText-ImDG3Uhg.js → isDiffPlainText-Ok-kgtJA.js} +1 -1
  96. package/dist/assets/{isFilePlainText-D_YDVYDb.js → isFilePlainText-0dLnkYm8.js} +1 -1
  97. package/dist/assets/ja-BuddHNi6.js +16 -0
  98. package/dist/assets/ko-BrwMbHmf.js +16 -0
  99. package/dist/assets/main-CjXBM_Xe.js +2 -0
  100. package/dist/assets/main-CxVyUDU_.js +896 -0
  101. package/dist/assets/markdownCore-B6PpX409.js +5 -0
  102. package/dist/assets/miniChat-DZ3OAeLN.js +2 -0
  103. package/dist/assets/mobile-CH0LOIF-.js +2 -0
  104. package/dist/assets/{patchFileDiff-DDQ6Rq5e.js → patchFileDiff-BFRGKaGH.js} +3 -3
  105. package/dist/assets/pl-BwN4TNlP.js +16 -0
  106. package/dist/assets/pt-BR-BhMtownO.js +16 -0
  107. package/dist/assets/renderElectronMiniChatApp-CB1uLYvh.js +2 -0
  108. package/dist/assets/renderMobileApp-nQ4sjQtb.js +25 -0
  109. package/dist/assets/runtimeEndpointReset-9ZGlXU4J.js +27 -0
  110. package/dist/assets/scheduledTasksApi-6DsL_SwM.js +1 -0
  111. package/dist/assets/{shikiHighlight-1imXsir9.js → shikiHighlight-CocY80VR.js} +1 -1
  112. package/dist/assets/{textMateThemeFromAppTheme-Dgqc63LZ.js → textMateThemeFromAppTheme-CF77r8FA.js} +1 -1
  113. package/dist/assets/tr-DRzvqMdi.js +7 -0
  114. package/dist/assets/uk-b2aYOSNh.js +16 -0
  115. package/dist/assets/useAppFontEffects-Dc5nTHi8.js +7337 -0
  116. package/dist/assets/useInlineCommentController-Dbza5c8l.js +2 -0
  117. package/dist/assets/useRootScrollLock-CSCLv396.js +2 -0
  118. package/dist/assets/{vendor-codemirror-language-data-BDyxuqK4.js → vendor-codemirror-language-data-CkmYWcRI.js} +2 -2
  119. package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
  120. package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
  121. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +12 -0
  122. package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
  123. package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-Gea9uBlY.js} +4 -4
  124. package/dist/assets/{web-components-D7FinaeH.js → web-components-nsStrYq9.js} +2 -2
  125. package/dist/assets/zh-CN-DZeUThm_.js +16 -0
  126. package/dist/assets/zh-TW-2fRE7uc6.js +16 -0
  127. package/dist/index.html +15 -7
  128. package/dist/mini-chat.html +7 -5
  129. package/dist/mobile.html +7 -5
  130. package/package.json +8 -7
  131. package/server/index.d.ts +1 -0
  132. package/server/index.js +248 -90
  133. package/server/lib/agent-tool/DOCUMENTATION.md +45 -15
  134. package/server/lib/agent-tool/runtime.js +189 -61
  135. package/server/lib/agent-tool/runtime.test.js +229 -75
  136. package/server/lib/browser-control/DOCUMENTATION.md +37 -2
  137. package/server/lib/browser-control/provider.js +217 -0
  138. package/server/lib/browser-control/provider.test.js +251 -0
  139. package/server/lib/context-obligatory/runtime.js +61 -50
  140. package/server/lib/context-obligatory/runtime.test.js +62 -162
  141. package/server/lib/event-stream/DOCUMENTATION.md +12 -1
  142. package/server/lib/event-stream/delta-coalescer.js +0 -0
  143. package/server/lib/event-stream/delta-coalescer.test.js +68 -57
  144. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  145. package/server/lib/event-stream/global-hub.js +10 -1
  146. package/server/lib/event-stream/global-hub.test.js +27 -26
  147. package/server/lib/event-stream/index.js +6 -0
  148. package/server/lib/event-stream/protocol.js +26 -19
  149. package/server/lib/event-stream/protocol.test.js +18 -7
  150. package/server/lib/event-stream/rebind.test.js +5 -5
  151. package/server/lib/event-stream/runtime.test.js +17 -15
  152. package/server/lib/event-stream/translate-v2.js +313 -0
  153. package/server/lib/event-stream/translate-v2.test.js +209 -0
  154. package/server/lib/event-stream/upstream-reader.test.js +16 -16
  155. package/server/lib/fs/DOCUMENTATION.md +6 -3
  156. package/server/lib/fs/byte-range.js +35 -0
  157. package/server/lib/fs/byte-range.test.js +31 -0
  158. package/server/lib/fs/routes.js +103 -46
  159. package/server/lib/fs/routes.test.js +239 -18
  160. package/server/lib/git/DOCUMENTATION.md +2 -2
  161. package/server/lib/git/service.js +106 -9
  162. package/server/lib/git/service.test.js +18 -0
  163. package/server/lib/github/DOCUMENTATION.md +1 -1
  164. package/server/lib/github/pr-status.js +22 -2
  165. package/server/lib/github/pr-status.test.js +27 -14
  166. package/server/lib/guests/DOCUMENTATION.md +13 -0
  167. package/server/lib/guests/catalog.js +12 -0
  168. package/server/lib/guests/catalog.test.js +33 -0
  169. package/server/lib/guests/routes.js +10 -1
  170. package/server/lib/guests/service.js +192 -14
  171. package/server/lib/guests/service.test.js +201 -1
  172. package/server/lib/guests/surface.js +630 -0
  173. package/server/lib/guests/surface.test.js +486 -0
  174. package/server/lib/markdown-image-grants/routes.js +18 -5
  175. package/server/lib/markdown-image-grants/routes.test.js +9 -6
  176. package/server/lib/message-queue/DOCUMENTATION.md +36 -22
  177. package/server/lib/message-queue/runtime.js +170 -100
  178. package/server/lib/message-queue/runtime.test.js +184 -82
  179. package/server/lib/notifications/DOCUMENTATION.md +28 -0
  180. package/server/lib/notifications/control-stream.http.test.js +68 -0
  181. package/server/lib/notifications/emitter-runtime.js +15 -0
  182. package/server/lib/notifications/emitter-runtime.test.js +32 -0
  183. package/server/lib/notifications/push-runtime.js +5 -1
  184. package/server/lib/notifications/push-runtime.test.js +2 -2
  185. package/server/lib/notifications/routes.js +5 -0
  186. package/server/lib/notifications/runtime.js +115 -26
  187. package/server/lib/notifications/template-runtime.js +13 -15
  188. package/server/lib/notifications/template-runtime.test.js +16 -9
  189. package/server/lib/notifications/trigger-runtime.test.js +187 -0
  190. package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
  191. package/server/lib/openchamber-control/actions.js +3 -2
  192. package/server/lib/openchamber-control/error.js +1 -1
  193. package/server/lib/openchamber-control/file-open.js +59 -0
  194. package/server/lib/openchamber-control/file-open.test.js +57 -0
  195. package/server/lib/openchamber-control/routes.test.js +12 -0
  196. package/server/lib/openchamber-control/service.js +102 -49
  197. package/server/lib/openchamber-control/service.test.js +84 -44
  198. package/server/lib/openchamber-sessions/archive-store.js +224 -0
  199. package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
  200. package/server/lib/openchamber-sessions/opencode-client.js +22 -0
  201. package/server/lib/openchamber-sessions/routes.js +398 -328
  202. package/server/lib/openchamber-sessions/routes.test.js +786 -700
  203. package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
  204. package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
  205. package/server/lib/opencode/DOCUMENTATION.md +450 -30
  206. package/server/lib/opencode/agents.js +233 -327
  207. package/server/lib/opencode/auth.js +41 -44
  208. package/server/lib/opencode/auth.test.js +92 -0
  209. package/server/lib/opencode/bootstrap-runtime.js +1 -0
  210. package/server/lib/opencode/cli-upgrade.d.ts +4 -0
  211. package/server/lib/opencode/cli-upgrade.js +18 -0
  212. package/server/lib/opencode/cli-upgrade.test.js +36 -0
  213. package/server/lib/opencode/commands.js +164 -145
  214. package/server/lib/opencode/compatibility.d.ts +16 -0
  215. package/server/lib/opencode/compatibility.js +88 -0
  216. package/server/lib/opencode/compatibility.test.js +62 -0
  217. package/server/lib/opencode/config-entity-routes.js +58 -29
  218. package/server/lib/opencode/config-entity-v2.test.js +290 -0
  219. package/server/lib/opencode/config-mutation-response.js +17 -7
  220. package/server/lib/opencode/config-mutation-response.test.js +4 -7
  221. package/server/lib/opencode/config-paths.test.js +2 -2
  222. package/server/lib/opencode/config-v2.d.ts +183 -0
  223. package/server/lib/opencode/config-v2.js +801 -0
  224. package/server/lib/opencode/config-v2.test.js +466 -0
  225. package/server/lib/opencode/credential-db.js +144 -0
  226. package/server/lib/opencode/credential-db.test.js +104 -0
  227. package/server/lib/opencode/env-runtime.js +48 -9
  228. package/server/lib/opencode/env-runtime.test.js +45 -0
  229. package/server/lib/opencode/feature-routes-runtime.js +15 -5
  230. package/server/lib/opencode/lifecycle-process.test.js +7 -4
  231. package/server/lib/opencode/lifecycle.js +85 -30
  232. package/server/lib/opencode/lifecycle.test.js +80 -8
  233. package/server/lib/opencode/login-shell-env.js +27 -0
  234. package/server/lib/opencode/managed-config-file.js +119 -0
  235. package/server/lib/opencode/managed-config-file.test.js +152 -0
  236. package/server/lib/opencode/managed-plugin-config.js +33 -13
  237. package/server/lib/opencode/mcp.js +43 -149
  238. package/server/lib/opencode/network-runtime.js +6 -7
  239. package/server/lib/opencode/openchamber-routes.test.js +0 -1
  240. package/server/lib/opencode/plugin-routes.js +3 -3
  241. package/server/lib/opencode/plugin-routes.test.js +6 -24
  242. package/server/lib/opencode/plugins.js +91 -40
  243. package/server/lib/opencode/plugins.test.js +28 -15
  244. package/server/lib/opencode/providers.js +63 -83
  245. package/server/lib/opencode/providers.test.js +128 -59
  246. package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
  247. package/server/lib/opencode/proxy.js +179 -129
  248. package/server/lib/opencode/pwa-manifest-routes.js +4 -2
  249. package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
  250. package/server/lib/opencode/response-envelope.js +14 -0
  251. package/server/lib/opencode/response-envelope.test.js +23 -0
  252. package/server/lib/opencode/routes-upgrade.test.js +73 -116
  253. package/server/lib/opencode/routes.js +121 -428
  254. package/server/lib/opencode/server-utils-runtime.js +10 -4
  255. package/server/lib/opencode/session-activity.js +78 -0
  256. package/server/lib/opencode/session-runtime.js +79 -0
  257. package/server/lib/opencode/session-runtime.test.js +43 -0
  258. package/server/lib/opencode/settings-helpers.js +9 -9
  259. package/server/lib/opencode/settings-helpers.test.js +7 -12
  260. package/server/lib/opencode/settings-registry.json +6 -8
  261. package/server/lib/opencode/settings-runtime.js +18 -1
  262. package/server/lib/opencode/settings-runtime.test.js +31 -2
  263. package/server/lib/opencode/shared.js +54 -22
  264. package/server/lib/opencode/shared.test.js +8 -4
  265. package/server/lib/opencode/shutdown-runtime.js +54 -7
  266. package/server/lib/opencode/shutdown-runtime.test.js +224 -30
  267. package/server/lib/opencode/skill-routes.js +23 -24
  268. package/server/lib/opencode/skills.js +7 -5
  269. package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
  270. package/server/lib/opencode/upgrade-capability.test.js +1 -1
  271. package/server/lib/opencode/v1-migration-topup.js +288 -0
  272. package/server/lib/opencode/v1-migration-topup.test.js +266 -0
  273. package/server/lib/opencode/v2-install.d.ts +8 -0
  274. package/server/lib/opencode/v2-install.js +158 -0
  275. package/server/lib/opencode/v2-install.test.js +124 -0
  276. package/server/lib/opencode/watcher.js +10 -3
  277. package/server/lib/opencode/watcher.test.js +17 -21
  278. package/server/lib/opencode/websearch-config.js +66 -0
  279. package/server/lib/permission-auto-accept/runtime.js +38 -22
  280. package/server/lib/permission-auto-accept/runtime.test.js +39 -17
  281. package/server/lib/projects/project-config.js +2 -2
  282. package/server/lib/quota/DOCUMENTATION.md +4 -0
  283. package/server/lib/quota/providers/xai.js +4 -4
  284. package/server/lib/realtime-proxy-terminal.test.js +150 -0
  285. package/server/lib/realtime-proxy.js +2 -0
  286. package/server/lib/relay/tunnel-host.js +4 -1
  287. package/server/lib/relay/tunnel-host.test.js +7 -0
  288. package/server/lib/routing/DOCUMENTATION.md +52 -19
  289. package/server/lib/routing/defaults.js +23 -6
  290. package/server/lib/routing/jev.js +17 -7
  291. package/server/lib/routing/routes.http.test.js +68 -33
  292. package/server/lib/routing/routes.js +65 -22
  293. package/server/lib/routing/runtime.js +145 -48
  294. package/server/lib/routing/runtime.test.js +79 -55
  295. package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
  296. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
  297. package/server/lib/scheduled-tasks/runtime.js +83 -76
  298. package/server/lib/scheduled-tasks/runtime.test.js +67 -1
  299. package/server/lib/session-assist/DOCUMENTATION.md +8 -3
  300. package/server/lib/session-assist/context.js +122 -46
  301. package/server/lib/session-assist/context.test.js +117 -49
  302. package/server/lib/session-assist/runtime.js +52 -22
  303. package/server/lib/session-assist/runtime.test.js +145 -173
  304. package/server/lib/session-goal/DOCUMENTATION.md +23 -15
  305. package/server/lib/session-goal/create.js +9 -12
  306. package/server/lib/session-goal/create.test.js +27 -28
  307. package/server/lib/session-goal/runtime.js +164 -77
  308. package/server/lib/session-goal/runtime.test.js +271 -519
  309. package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
  310. package/server/lib/session-knowledge/runtime.js +59 -41
  311. package/server/lib/session-knowledge/runtime.test.js +90 -20
  312. package/server/lib/small-model/DOCUMENTATION.md +154 -196
  313. package/server/lib/small-model/client.js +113 -0
  314. package/server/lib/small-model/index.js +296 -158
  315. package/server/lib/small-model/index.test.js +423 -256
  316. package/server/lib/small-model/routes.js +1 -1
  317. package/server/lib/spaces/DOCUMENTATION.md +807 -0
  318. package/server/lib/spaces/code-in-bait.js +185 -0
  319. package/server/lib/spaces/code-in.js +641 -0
  320. package/server/lib/spaces/code-in.test.js +1048 -0
  321. package/server/lib/spaces/errors.js +8 -0
  322. package/server/lib/spaces/exec-http.js +94 -0
  323. package/server/lib/spaces/gatekeeper-channel.js +202 -0
  324. package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
  325. package/server/lib/spaces/gatekeeper-program.cjs +914 -0
  326. package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
  327. package/server/lib/spaces/hardening.js +457 -0
  328. package/server/lib/spaces/hardening.test.js +368 -0
  329. package/server/lib/spaces/host-git.js +127 -0
  330. package/server/lib/spaces/host-git.test.js +137 -0
  331. package/server/lib/spaces/labels.js +234 -0
  332. package/server/lib/spaces/labels.test.js +219 -0
  333. package/server/lib/spaces/layout.js +184 -0
  334. package/server/lib/spaces/layout.test.js +30 -0
  335. package/server/lib/spaces/manager.js +82 -0
  336. package/server/lib/spaces/manager.test.js +114 -0
  337. package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
  338. package/server/lib/spaces/places/contract-suite.js +156 -0
  339. package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
  340. package/server/lib/spaces/places/contract.test.js +6 -0
  341. package/server/lib/spaces/places/docker-engine.js +126 -0
  342. package/server/lib/spaces/places/docker-live-support.js +202 -0
  343. package/server/lib/spaces/places/docker-tools.js +186 -0
  344. package/server/lib/spaces/places/docker.js +587 -0
  345. package/server/lib/spaces/places/docker.test.js +1610 -0
  346. package/server/lib/spaces/places/escape-suite.js +1018 -0
  347. package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
  348. package/server/lib/spaces/places/fake-docker.js +375 -0
  349. package/server/lib/spaces/places/memory-place.js +103 -0
  350. package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
  351. package/server/lib/spaces/places/registry.js +43 -0
  352. package/server/lib/spaces/places/registry.test.js +50 -0
  353. package/server/lib/spaces/places/server.docker.live.test.js +225 -0
  354. package/server/lib/spaces/run-command.js +261 -0
  355. package/server/lib/spaces/run-command.test.js +396 -0
  356. package/server/lib/spaces/space-server.js +190 -0
  357. package/server/lib/spaces/space-server.test.js +335 -0
  358. package/server/lib/spaces/tools-filler.js +82 -0
  359. package/server/lib/spaces/tools-filler.test.js +148 -0
  360. package/server/lib/spaces/tools-pack.js +49 -0
  361. package/server/lib/spaces/tools-pack.test.js +57 -0
  362. package/server/lib/spaces/tools.js +137 -0
  363. package/server/lib/spaces/tools.test.js +153 -0
  364. package/server/lib/terminal/DOCUMENTATION.md +21 -2
  365. package/server/lib/terminal/runtime.js +10 -3
  366. package/server/lib/terminal/runtime.test.js +22 -0
  367. package/server/lib/terminal/shutdown.js +106 -0
  368. package/server/lib/terminal/shutdown.test.js +84 -0
  369. package/server/lib/tts/openai-sdk.js +11 -0
  370. package/server/lib/tts/service.js +7 -5
  371. package/server/lib/tts/service.test.js +78 -0
  372. package/server/lib/tts/stt.js +3 -2
  373. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  374. package/server/lib/tunnels/routes.js +7 -0
  375. package/server/lib/tunnels/routes.test.js +55 -0
  376. package/server/lib/ui-auth/ui-auth.js +38 -2
  377. package/server/lib/ui-auth/ui-auth.test.js +42 -0
  378. package/server/lib/ui-auth/ui-passkeys.js +12 -10
  379. package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
  380. package/server/lib/walkthrough/pull-request.js +61 -8
  381. package/server/lib/walkthrough/pull-request.test.js +54 -1
  382. package/server/lib/walkthrough/routes.js +20 -0
  383. package/server/lib/walkthrough/routes.test.js +19 -0
  384. package/server/opencode-proxy.test.js +190 -166
  385. package/server/opencode-worktree-readiness.test.js +5 -4
  386. package/dist/assets/DiffView-DkC3xlRJ.js +0 -4
  387. package/dist/assets/FilesView-D0bM9FVB.js +0 -13
  388. package/dist/assets/LinearIssuesView-UI1FcSC8.js +0 -1
  389. package/dist/assets/MarkdownImageGallery-CUJxH8Le.js +0 -1
  390. package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +0 -12
  391. package/dist/assets/OnboardingScreen-5Gou9cGD.js +0 -1
  392. package/dist/assets/PierreDiffViewer-ByRVu6ss.js +0 -161
  393. package/dist/assets/PlanView-u2yi5XGJ.js +0 -5
  394. package/dist/assets/PluginPane-QxjsKYeO.js +0 -3
  395. package/dist/assets/SettingsView-Fo5ZqMaT.js +0 -29
  396. package/dist/assets/SettingsWindow-HVDVANjJ.js +0 -1
  397. package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +0 -1
  398. package/dist/assets/ToolOutputDialog-3J6IRayW.js +0 -15
  399. package/dist/assets/ToolPartDiffPreview-DarxPjSd.js +0 -8
  400. package/dist/assets/appThemeRegistry-Cf8KitzT.js +0 -1
  401. package/dist/assets/de-BM_8EDD3.js +0 -10
  402. package/dist/assets/es-CxZjlqpo.js +0 -16
  403. package/dist/assets/fr-VCixCnMW.js +0 -14
  404. package/dist/assets/index-3U4CtS9b.js +0 -1
  405. package/dist/assets/index-B9Hvzjwl.css +0 -1
  406. package/dist/assets/index-DLHQogv8.js +0 -40
  407. package/dist/assets/ja-CZ5k_GyD.js +0 -16
  408. package/dist/assets/ko-7YM3A1Xh.js +0 -16
  409. package/dist/assets/main-CycplCph.js +0 -2
  410. package/dist/assets/main-DFYTCx5o.js +0 -896
  411. package/dist/assets/markdownCore-DHvqMxPn.js +0 -5
  412. package/dist/assets/miniChat-DIQKfY2V.js +0 -2
  413. package/dist/assets/mobile-BMwz5q-m.js +0 -2
  414. package/dist/assets/pl-BcgDO_w5.js +0 -16
  415. package/dist/assets/pt-BR-CU2u_1q5.js +0 -16
  416. package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +0 -2
  417. package/dist/assets/renderMobileApp-D0Y8DtkA.js +0 -25
  418. package/dist/assets/runtimeEndpointReset-DhC3REb2.js +0 -25
  419. package/dist/assets/scheduledTasksApi-D8pq6gQz.js +0 -1
  420. package/dist/assets/tr-DuYhOzNe.js +0 -7
  421. package/dist/assets/uk-Cuk7-uvq.js +0 -16
  422. package/dist/assets/useAppFontEffects-BItUWdo4.js +0 -7333
  423. package/dist/assets/useInlineCommentController-CkbKsm7m.js +0 -2
  424. package/dist/assets/useRootScrollLock-vmzxZjWA.js +0 -2
  425. package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
  426. package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
  427. package/dist/assets/zh-CN-CUWoiRHd.js +0 -16
  428. package/dist/assets/zh-TW-CQ8EBSBN.js +0 -16
  429. package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
  430. package/server/lib/routing/feature-flag.js +0 -11
  431. package/server/lib/small-model/call.js +0 -820
  432. package/server/lib/small-model/call.test.js +0 -1110
  433. package/server/lib/small-model/catalog.js +0 -13
  434. package/server/lib/small-model/resolve.js +0 -131
  435. package/server/lib/small-model/resolve.test.js +0 -197
  436. package/server/lib/small-model/runtime-providers.js +0 -164
  437. package/server/lib/small-model/runtime-providers.test.js +0 -118
  438. package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
  439. package/server/lib/system-prompt/runtime.js +0 -49
  440. package/server/lib/system-prompt/runtime.test.js +0 -76
  441. package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
  442. /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
@@ -0,0 +1,57 @@
1
+ import path from 'node:path';
2
+
3
+ import { describe, expect, it } from 'vitest';
4
+
5
+ import { packLocalTools } from './tools-pack.js';
6
+
7
+ const CHECKOUT = path.resolve('/checkout');
8
+ const OUT = path.resolve('/out');
9
+
10
+ /** A stand-in for bun. `pack` is what `bun pm pack --quiet` prints for a package. */
11
+ const fakeBun = ({ pack = (name) => `${path.join(OUT, `openchamber-${name}-1.24.2.tgz`)}\n`, failAt = () => false } = {}) => {
12
+ const calls = [];
13
+ const runCommand = async (file, args, options) => {
14
+ calls.push({ file, args, cwd: options.cwd, timeoutMs: options.timeoutMs });
15
+ if (failAt(args, options.cwd)) return { code: 1, stdout: '', stderr: 'error: Script not found "build"\n' };
16
+ return { code: 0, stdout: args[0] === 'pm' ? pack(path.basename(options.cwd)) : '', stderr: '' };
17
+ };
18
+ return { runCommand, calls };
19
+ };
20
+
21
+ describe('packLocalTools', () => {
22
+ it('builds the sdk, then packs the sdk and web from their own directories', async () => {
23
+ const bun = fakeBun();
24
+ const result = await packLocalTools({ runCommand: bun.runCommand, bunPath: '/opt/bun', checkoutRoot: CHECKOUT, outputDirectory: OUT });
25
+
26
+ expect(result).toEqual({
27
+ sdkTarballPath: path.join(OUT, 'openchamber-sdk-1.24.2.tgz'),
28
+ webTarballPath: path.join(OUT, 'openchamber-web-1.24.2.tgz'),
29
+ });
30
+ expect(bun.calls.map((call) => [call.file, call.args.join(' '), call.cwd])).toEqual([
31
+ ['/opt/bun', 'run build', path.join(CHECKOUT, 'packages', 'sdk')],
32
+ ['/opt/bun', `pm pack --destination ${OUT} --quiet`, path.join(CHECKOUT, 'packages', 'sdk')],
33
+ ['/opt/bun', `pm pack --destination ${OUT} --quiet`, path.join(CHECKOUT, 'packages', 'web')],
34
+ ]);
35
+ for (const call of bun.calls) expect(call.timeoutMs).toBeGreaterThan(0);
36
+ });
37
+
38
+ it('takes the last line as the tarball, because the prepack script prints before it', async () => {
39
+ const bun = fakeBun({ pack: (name) => `Built 0 built-in extension(s).\n${path.join(OUT, `openchamber-${name}-1.24.2.tgz`)}\n\n` });
40
+ const result = await packLocalTools({ runCommand: bun.runCommand, checkoutRoot: CHECKOUT, outputDirectory: OUT });
41
+ expect(result.webTarballPath).toBe(path.join(OUT, 'openchamber-web-1.24.2.tgz'));
42
+ });
43
+
44
+ it('says which step failed and what to do', async () => {
45
+ const bun = fakeBun({ failAt: (args) => args[0] === 'run' });
46
+ await expect(packLocalTools({ runCommand: bun.runCommand, checkoutRoot: CHECKOUT, outputDirectory: OUT })).rejects.toMatchObject({
47
+ code: 'tools_pack_failed',
48
+ message: expect.stringMatching(/build the sdk package.*Script not found.*bun install/s),
49
+ });
50
+ expect(bun.calls).toHaveLength(1);
51
+ });
52
+
53
+ it('rejects when bun does not name a tarball', async () => {
54
+ const bun = fakeBun({ pack: () => 'Done\n' });
55
+ await expect(packLocalTools({ runCommand: bun.runCommand, checkoutRoot: CHECKOUT, outputDirectory: OUT })).rejects.toMatchObject({ code: 'tools_pack_failed' });
56
+ });
57
+ });
@@ -0,0 +1,137 @@
1
+ // Tools sources: what goes into a tools volume. A source is plain data, made once.
2
+ //
3
+ // registry exact published versions, for a released host
4
+ // packed local tarballs of `web` and `sdk`, for a development build, whose
5
+ // packages differ from the published ones with the same version number
6
+ //
7
+ // Deciding which one a host needs is wiring and belongs to a later stage.
8
+
9
+ import crypto from 'node:crypto';
10
+ import fs from 'node:fs';
11
+
12
+ import { SpaceError } from './errors.js';
13
+ import { FILLER_PROGRAM } from './tools-filler.js';
14
+
15
+ // Where the filler puts the tarballs of a packed source. It is a tmpfs, so they vanish with the filler.
16
+ export const TOOLS_STAGING_PATH = '/tmp/openchamber-fill';
17
+
18
+ const WEB_TARBALL_NAME = 'openchamber-web.tgz';
19
+ const SDK_TARBALL_NAME = 'openchamber-sdk.tgz';
20
+
21
+ // Exact versions for the three packages this module names, never a range or a URL.
22
+ // That pins those three only. Their own dependencies are still ranges, and no lock file travels
23
+ // with the source, so two fills of one key can differ in a transitive package. A known limit.
24
+ const EXACT_VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
25
+
26
+ const requireVersion = (value, what) => {
27
+ if (!EXACT_VERSION_PATTERN.test(value ?? '')) {
28
+ throw new SpaceError('invalid_tools_version', `${what} needs an exact version such as 1.2.3, got '${value}'`);
29
+ }
30
+ return value;
31
+ };
32
+
33
+ const sha256 = (bytes) => crypto.createHash('sha256').update(bytes).digest('hex');
34
+
35
+ const packageJsonText = (fields) => JSON.stringify({ name: 'openchamber-space-tools', private: true, ...fields });
36
+
37
+ // Every source made here. The Docker place accepts no other object as a source.
38
+ const madeHere = new WeakSet();
39
+
40
+ const finishSource = (source) => {
41
+ madeHere.add(Object.freeze(source));
42
+ return source;
43
+ };
44
+
45
+ // A revision changes the key and nothing else: the same packages, filled again into a new volume.
46
+ const REVISION_PATTERN = /^[A-Za-z0-9._-]{0,64}$/;
47
+
48
+ const requireRevision = (value) => {
49
+ if (!REVISION_PATTERN.test(value)) {
50
+ throw new SpaceError('invalid_tools_revision', 'A tools revision may hold only letters, digits, dots, dashes and underscores, 64 at most');
51
+ }
52
+ return value;
53
+ };
54
+
55
+ /** OpenCode and its plugin always share one version. */
56
+ const openCodePackages = (version) => ({ '@opencode/cli': version, '@opencode/plugin': version });
57
+
58
+ /**
59
+ * The versions a released host installs: its own `@openchamber/web`, and OpenCode at the
60
+ * version of the `@opencode/client` this server was built against.
61
+ */
62
+ export function readHostToolVersions(packageJsonUrl = new URL('../../../package.json', import.meta.url)) {
63
+ let manifest;
64
+ try {
65
+ manifest = JSON.parse(fs.readFileSync(packageJsonUrl, 'utf8'));
66
+ } catch (error) {
67
+ throw new SpaceError('tools_versions_unreadable', `Could not read the package.json of the OpenChamber server: ${error.message}`);
68
+ }
69
+ return {
70
+ webVersion: requireVersion(manifest.version, '@openchamber/web'),
71
+ openCodeVersion: requireVersion(manifest.dependencies?.['@opencode/client'], 'OpenCode'),
72
+ };
73
+ }
74
+
75
+ export function createRegistryToolsSource({ webVersion, openCodeVersion, revision = '' }) {
76
+ const packages = {
77
+ '@openchamber/web': requireVersion(webVersion, '@openchamber/web'),
78
+ ...openCodePackages(requireVersion(openCodeVersion, 'OpenCode')),
79
+ };
80
+ return finishSource({
81
+ kind: 'registry',
82
+ description: `web ${webVersion}, opencode ${openCodeVersion}`,
83
+ canonical: { kind: 'registry', packages, revision: requireRevision(revision) },
84
+ packageJson: packageJsonText({ dependencies: packages }),
85
+ files: [],
86
+ });
87
+ }
88
+
89
+ /**
90
+ * A development build. The two tarballs are read and hashed here, once.
91
+ * The override makes every `@openchamber/sdk` in the tree the local tarball, also the one
92
+ * that `web` asks for by version number.
93
+ */
94
+ export function createPackedToolsSource({ webTarballPath, sdkTarballPath, openCodeVersion, revision = '' }) {
95
+ const read = (filePath, what) => {
96
+ try {
97
+ return fs.readFileSync(filePath);
98
+ } catch (error) {
99
+ throw new SpaceError('tools_tarball_unreadable', `Could not read the packed ${what} package at ${filePath}: ${error.message}`);
100
+ }
101
+ };
102
+ const files = [
103
+ { name: WEB_TARBALL_NAME, bytes: read(webTarballPath, 'web') },
104
+ { name: SDK_TARBALL_NAME, bytes: read(sdkTarballPath, 'sdk') },
105
+ ];
106
+ const packages = openCodePackages(requireVersion(openCodeVersion, 'OpenCode'));
107
+ return finishSource({
108
+ kind: 'packed',
109
+ description: 'development build',
110
+ canonical: { kind: 'packed', tarballs: files.map((file) => ({ name: file.name, sha256: sha256(file.bytes) })), packages, revision: requireRevision(revision) },
111
+ packageJson: packageJsonText({
112
+ dependencies: {
113
+ '@openchamber/web': `file:${TOOLS_STAGING_PATH}/${WEB_TARBALL_NAME}`,
114
+ '@openchamber/sdk': `file:${TOOLS_STAGING_PATH}/${SDK_TARBALL_NAME}`,
115
+ ...packages,
116
+ },
117
+ overrides: { '@openchamber/sdk': '$@openchamber/sdk' },
118
+ }),
119
+ files,
120
+ });
121
+ }
122
+
123
+ export function requireToolsSource(source) {
124
+ if (!madeHere.has(source)) {
125
+ throw new SpaceError('invalid_tools_source', 'The Docker place needs a tools source from createRegistryToolsSource or createPackedToolsSource');
126
+ }
127
+ return source;
128
+ }
129
+
130
+ /**
131
+ * First 16 hex characters of a sha256 over everything that decides the content of a tools
132
+ * volume: the source, the base image the filler runs in, and the filler program itself.
133
+ */
134
+ export function toolsContentKey(source, image) {
135
+ const description = JSON.stringify({ source: requireToolsSource(source).canonical, image, filler: sha256(FILLER_PROGRAM) });
136
+ return sha256(description).slice(0, 16);
137
+ }
@@ -0,0 +1,153 @@
1
+ import crypto from 'node:crypto';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { pathToFileURL } from 'node:url';
6
+
7
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
8
+
9
+ import { createPackedToolsSource, createRegistryToolsSource, readHostToolVersions, requireToolsSource, toolsContentKey } from './tools.js';
10
+
11
+ const IMAGE = 'node@sha256:aaaa';
12
+ const VERSIONS = { webVersion: '1.24.2', openCodeVersion: '1.18.31' };
13
+
14
+ let directory;
15
+ const tarball = (name, content) => {
16
+ const filePath = path.join(directory, name);
17
+ fs.writeFileSync(filePath, content);
18
+ return filePath;
19
+ };
20
+
21
+ beforeAll(() => {
22
+ directory = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-tools-test-'));
23
+ });
24
+
25
+ afterAll(() => {
26
+ fs.rmSync(directory, { recursive: true, force: true });
27
+ });
28
+
29
+ describe('readHostToolVersions', () => {
30
+ it('reads the version of this server and the OpenCode version it was built against', () => {
31
+ const versions = readHostToolVersions();
32
+ expect(versions.webVersion).toMatch(/^\d+\.\d+\.\d+/);
33
+ expect(versions.openCodeVersion).toMatch(/^\d+\.\d+\.\d+/);
34
+ });
35
+
36
+ it('rejects a manifest whose OpenCode dependency is a range', () => {
37
+ const manifest = tarball('range.json', JSON.stringify({ version: '1.0.0', dependencies: { '@opencode/client': '^1.18.0' } }));
38
+ expect(() => readHostToolVersions(pathToFileURL(manifest))).toThrow(expect.objectContaining({ code: 'invalid_tools_version' }));
39
+ });
40
+
41
+ it('says when the manifest cannot be read', () => {
42
+ expect(() => readHostToolVersions(pathToFileURL(path.join(directory, 'missing.json')))).toThrow(expect.objectContaining({ code: 'tools_versions_unreadable' }));
43
+ });
44
+ });
45
+
46
+ describe('createRegistryToolsSource', () => {
47
+ it('asks for exact versions, with the plugin at the OpenCode version', () => {
48
+ const source = createRegistryToolsSource(VERSIONS);
49
+
50
+ expect(source.description).toBe('web 1.24.2, opencode 1.18.31');
51
+ expect(source.files).toEqual([]);
52
+ expect(JSON.parse(source.packageJson)).toEqual({
53
+ name: 'openchamber-space-tools',
54
+ private: true,
55
+ dependencies: { '@openchamber/web': '1.24.2', '@opencode/cli': '1.18.31', '@opencode/plugin': '1.18.31' },
56
+ });
57
+ });
58
+
59
+ it.each(['^1.24.2', 'latest', '1.24', '', undefined, 'https://example.com/x.tgz', '1.24.2 || 2'])('rejects the version %j', (version) => {
60
+ expect(() => createRegistryToolsSource({ ...VERSIONS, webVersion: version })).toThrow(expect.objectContaining({ code: 'invalid_tools_version' }));
61
+ expect(() => createRegistryToolsSource({ ...VERSIONS, openCodeVersion: version })).toThrow(expect.objectContaining({ code: 'invalid_tools_version' }));
62
+ });
63
+
64
+ it('accepts a prerelease version', () => {
65
+ expect(createRegistryToolsSource({ ...VERSIONS, webVersion: '1.25.0-beta.1' }).description).toContain('1.25.0-beta.1');
66
+ });
67
+ });
68
+
69
+ describe('createPackedToolsSource', () => {
70
+ it('installs both tarballs by path and makes every sdk in the tree the local one', () => {
71
+ const source = createPackedToolsSource({ webTarballPath: tarball('web.tgz', 'web bytes'), sdkTarballPath: tarball('sdk.tgz', 'sdk bytes'), openCodeVersion: '1.18.31' });
72
+
73
+ expect(source.description).toBe('development build');
74
+ expect(source.files).toEqual([
75
+ { name: 'openchamber-web.tgz', bytes: Buffer.from('web bytes') },
76
+ { name: 'openchamber-sdk.tgz', bytes: Buffer.from('sdk bytes') },
77
+ ]);
78
+ expect(JSON.parse(source.packageJson)).toEqual({
79
+ name: 'openchamber-space-tools',
80
+ private: true,
81
+ dependencies: {
82
+ '@openchamber/web': 'file:/tmp/openchamber-fill/openchamber-web.tgz',
83
+ '@openchamber/sdk': 'file:/tmp/openchamber-fill/openchamber-sdk.tgz',
84
+ '@opencode/cli': '1.18.31',
85
+ '@opencode/plugin': '1.18.31',
86
+ },
87
+ overrides: { '@openchamber/sdk': '$@openchamber/sdk' },
88
+ });
89
+ });
90
+
91
+ it('hashes the tarballs once, when the source is made', () => {
92
+ const webTarballPath = tarball('web-once.tgz', 'first');
93
+ const source = createPackedToolsSource({ webTarballPath, sdkTarballPath: tarball('sdk-once.tgz', 'sdk'), openCodeVersion: '1.18.31' });
94
+ const key = toolsContentKey(source, IMAGE);
95
+
96
+ fs.writeFileSync(webTarballPath, 'changed later');
97
+ expect(toolsContentKey(source, IMAGE)).toBe(key);
98
+ expect(source.canonical.tarballs[0].sha256).toBe(crypto.createHash('sha256').update('first').digest('hex'));
99
+ });
100
+
101
+ it('says which tarball it could not read', () => {
102
+ const missing = path.join(directory, 'nowhere.tgz');
103
+ expect(() => createPackedToolsSource({ webTarballPath: missing, sdkTarballPath: missing, openCodeVersion: '1.18.31' }))
104
+ .toThrow(expect.objectContaining({ code: 'tools_tarball_unreadable', message: expect.stringContaining('web') }));
105
+ });
106
+ });
107
+
108
+ describe('toolsContentKey', () => {
109
+ const packed = (webContent) => createPackedToolsSource({ webTarballPath: tarball(`web-${webContent}.tgz`, webContent), sdkTarballPath: tarball('sdk-key.tgz', 'sdk'), openCodeVersion: '1.18.31' });
110
+
111
+ it('is 16 hex characters and the same for the same content', () => {
112
+ const key = toolsContentKey(createRegistryToolsSource(VERSIONS), IMAGE);
113
+ expect(key).toMatch(/^[0-9a-f]{16}$/);
114
+ expect(toolsContentKey(createRegistryToolsSource(VERSIONS), IMAGE)).toBe(key);
115
+ });
116
+
117
+ it('changes with a version, with the base image, with a tarball byte, and between the two kinds', () => {
118
+ const keys = [
119
+ toolsContentKey(createRegistryToolsSource(VERSIONS), IMAGE),
120
+ toolsContentKey(createRegistryToolsSource({ ...VERSIONS, webVersion: '1.24.3' }), IMAGE),
121
+ toolsContentKey(createRegistryToolsSource({ ...VERSIONS, openCodeVersion: '1.18.32' }), IMAGE),
122
+ toolsContentKey(createRegistryToolsSource(VERSIONS), 'node@sha256:bbbb'),
123
+ toolsContentKey(packed('a'), IMAGE),
124
+ toolsContentKey(packed('b'), IMAGE),
125
+ toolsContentKey(createRegistryToolsSource({ ...VERSIONS, revision: 'refill-1' }), IMAGE),
126
+ ];
127
+ expect(new Set(keys).size).toBe(keys.length);
128
+ });
129
+ });
130
+
131
+ describe('revision', () => {
132
+ it('changes the key and nothing that gets installed', () => {
133
+ const plain = createRegistryToolsSource(VERSIONS);
134
+ const revised = createRegistryToolsSource({ ...VERSIONS, revision: 'refill-1' });
135
+ expect(revised.packageJson).toBe(plain.packageJson);
136
+ expect(revised.description).toBe(plain.description);
137
+ });
138
+
139
+ it.each(['two words', 'a/b', 'x'.repeat(65)])('rejects %j', (revision) => {
140
+ expect(() => createRegistryToolsSource({ ...VERSIONS, revision })).toThrow(expect.objectContaining({ code: 'invalid_tools_revision' }));
141
+ });
142
+ });
143
+
144
+ describe('requireToolsSource', () => {
145
+ it.each([undefined, null, 'registry', {}, { ...createRegistryToolsSource(VERSIONS) }])('rejects %j, which no factory here made', (source) => {
146
+ expect(() => requireToolsSource(source)).toThrow(expect.objectContaining({ code: 'invalid_tools_source' }));
147
+ });
148
+
149
+ it('accepts a source from either factory', () => {
150
+ const source = createRegistryToolsSource(VERSIONS);
151
+ expect(requireToolsSource(source)).toBe(source);
152
+ });
153
+ });
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Ownership
4
4
 
5
- `runtime.js` owns terminal identity, PTY processes, launch mode, session purpose, ordered output, bounded scrollback, WebSocket attachments, and lifecycle routes. `shells.js` discovers executable shell families, resolves the persisted shell ID, and builds the per-shell argv for interactive versus command launches. Clients own tab arrangement. Interactive terminals use stable IDs; project actions keep a stable UI tab and allocate a fresh terminal ID for each command execution. Electron uses this same runtime in-process; VS Code returns an explicit unsupported error.
5
+ `runtime.js` owns terminal identity, PTY processes, launch mode, session purpose, ordered output, bounded scrollback, WebSocket attachments, and lifecycle routes. `shutdown.js` owns bounded runtime-wide process cleanup. `shells.js` discovers executable shell families, resolves the persisted shell ID, and builds the per-shell argv for interactive versus command launches. Clients own tab arrangement. Interactive terminals use stable IDs; project actions keep a stable UI tab and allocate a fresh terminal ID for each command execution. Electron uses this same runtime in-process; VS Code returns an explicit unsupported error.
6
6
 
7
7
  ## Protocol
8
8
 
@@ -39,8 +39,9 @@ HTTP remains the authenticated command plane for create, resize, appearance upda
39
39
  - Restarts are serialized per terminal. Each restart spawns and wires the replacement before terminating the old process, retaining the terminal ID. Command-mode sessions reject restart with HTTP 400 instead of silently turning into interactive shells with stale action metadata.
40
40
  - A restart rechecks session ownership before and after PTY creation. Close, force-kill, idle removal, or shutdown can invalidate it while spawn is pending. A late replacement is terminated instead of being attached to a retired session.
41
41
  - A delete that arrives while create is still pending leaves a cancellation tombstone. When the PTY arrives, the runtime terminates it immediately, never inserts the session into the live map, and returns a create error while the delete still succeeds.
42
- - Close uses SIGTERM with bounded SIGKILL escalation. Force-kill, idle cleanup, and runtime shutdown terminate process groups immediately where supported. Removal explicitly sends a fatal scoped closure and evicts client projections even when a PTY backend fails to emit `onExit`; attached terminals are not considered idle.
42
+ - Close uses SIGTERM with bounded SIGKILL escalation. Force-kill and idle cleanup terminate process groups immediately where supported. Removal explicitly sends a fatal scoped closure and evicts client projections even when a PTY backend fails to emit `onExit`; attached terminals are not considered idle.
43
43
  - Shutdown is single-flight, rejects new creates, cancels pending creates, and waits for pending creates and restarts before clearing live sessions. A PTY that arrives during shutdown follows the same cancellation cleanup as a pending create that was explicitly closed.
44
+ - On POSIX, shutdown disconnects input and gives terminal workloads a shared 20-second SIGTERM grace. Process-table snapshots retain descendant ownership across shell exit and separate job-control groups; PID start times guard against reused PIDs. Linux reads `/proc` directly so minimal containers do not need `ps`. Shells remain open until the workloads exit, then receive SIGHUP. An exec'ed server receives SIGTERM and the full grace even though it occupies the shell PID. Remaining processes receive SIGKILL at the deadline. A process-table failure warns and forces known owned processes closed. Windows retains ConPTY-owned teardown because it has no POSIX signal protocol.
44
45
 
45
46
  ## Security And Relay
46
47
 
@@ -52,5 +53,23 @@ Run:
52
53
 
53
54
  ```sh
54
55
  bun test packages/web/server/lib/terminal/runtime.test.js packages/web/server/lib/terminal/terminal-ws-protocol.test.js
56
+ bun run --cwd packages/web test server/lib/terminal/shutdown.test.js
55
57
  bun test packages/web/server/lib/ui-auth/ui-auth.test.js packages/web/server/lib/relay/cross-compat.test.js
56
58
  ```
59
+
60
+ The #3389 macOS ARM64 reproduction used real Electron 43.7.0 PTYs and HTTP
61
+ servers with signal handlers that took 15 seconds to finish cleanup. On the
62
+ baseline, File > Restart and Quit sent SIGKILL to the exec'ed server within
63
+ 3–4 ms; a foreground child in another process group received SIGHUP and outlived
64
+ Electron. After the fix, both workloads completed after SIGTERM before Electron
65
+ exited, in bundled and HMR runs. A noncooperative workload was killed after the
66
+ shared 20-second deadline.
67
+
68
+ Packaged test builds 1.24.90 and 1.24.91 exercised the real macOS Squirrel install
69
+ with a loopback feed, isolated app identity/profile, and a shared test signing
70
+ requirement. Both the normal update and closing the window during cleanup
71
+ installed and relaunched N+1 after the terminal workloads finished. The installed
72
+ ASAR matched N+1, and OpenCode remained bundled after its own restart. A rejected
73
+ signature also reached the installer error handler after the 15-second cleanup.
74
+ Linux ARM64 process regressions pass without `ps` installed. Native Windows
75
+ ConPTY and Linux Electron installer behavior were not exercised for this fix.
@@ -11,6 +11,7 @@ import { sanitizeTerminalHistoryChunk } from './history.js';
11
11
  import { consumeTerminalThemeQueries, terminalThemeModeReport } from './theme-response.js';
12
12
  import { buildTerminalShellLaunch, createTerminalShellResolver, normalizeTerminalShell } from './shells.js';
13
13
  import { stripAppImageArgv0Leak, resolvePosixPtyLaunch } from '../inherited-env.js';
14
+ import { shutdownTerminalProcesses } from './shutdown.js';
14
15
 
15
16
  const MAX_SESSIONS = 20;
16
17
  const MAX_HISTORY_BYTES = 512 * 1024;
@@ -91,7 +92,7 @@ const trimHistory = (history) => {
91
92
  export function createTerminalRuntime({
92
93
  app, server, fs, path, uiAuthController, buildAugmentedPath, searchPathFor, isExecutable,
93
94
  isRequestOriginAllowed, rejectWebSocketUpgrade, TERMINAL_INPUT_WS_HEARTBEAT_INTERVAL_MS,
94
- loadPtyProvider, terminalTerminationGraceMs = TERMINATION_GRACE_MS,
95
+ loadPtyProvider, terminalTerminationGraceMs = TERMINATION_GRACE_MS, shutdownProcesses = shutdownTerminalProcesses,
95
96
  }) {
96
97
  const sessions = new Map();
97
98
  const pendingSessionCreates = new Map();
@@ -136,7 +137,7 @@ export function createTerminalRuntime({
136
137
  const launch = resolvePosixPtyLaunch(shellLaunch.executable, shellLaunch.args);
137
138
  const options = { name: 'xterm-256color', cwd, cols, rows, env };
138
139
  if (process.platform === 'win32') options.useConpty = true;
139
- return { process: await provider.spawn(launch.executable, launch.args, options), backend: provider.backend, shell: resolvedShell.id, loginShell };
140
+ return { process: await provider.spawn(launch.executable, launch.args, options), backend: provider.backend, shell: resolvedShell.id, shellExecutable: executable, loginShell };
140
141
  } catch (error) { lastError = error; }
141
142
  }
142
143
  throw lastError ?? new Error('No executable shell found');
@@ -274,6 +275,7 @@ export function createTerminalRuntime({
274
275
  if (clear) { session.history = ''; session.pendingHistoryControlSequence = ''; session.pendingThemeControlSequence = ''; session.themeModeEnabled = false; }
275
276
  session.cwd = cwd; session.cols = cols; session.rows = rows; session.process = spawned.process;
276
277
  session.backend = spawned.backend; session.shell = spawned.shell; session.loginShell = spawned.loginShell; session.status = 'running'; session.exitCode = null; session.signal = null;
278
+ session.shellExecutable = spawned.shellExecutable;
277
279
  session.mode = mode; session.command = mode === COMMAND_TERMINAL_MODE ? command : null;
278
280
  session.purpose = purpose;
279
281
  session.themeMode = themeMode === 'light' ? 'light' : 'dark'; session.terminalBackground = terminalBackground; session.terminalForeground = terminalForeground;
@@ -519,6 +521,7 @@ export function createTerminalRuntime({
519
521
  throw new Error('Terminal session was closed during restart');
520
522
  }
521
523
  session.process = spawned.process; session.backend = spawned.backend; session.shell = spawned.shell; session.loginShell = spawned.loginShell; session.cwd = cwd; session.cols = cols; session.rows = rows;
524
+ session.shellExecutable = spawned.shellExecutable;
522
525
  session.history = ''; session.pendingHistoryControlSequence = ''; session.pendingThemeControlSequence = ''; session.themeModeEnabled = false; session.status = 'running'; session.exitCode = null; session.signal = null; session.eventQueue.length = 0;
523
526
  session.themeMode = themeMode === 'light' ? 'light' : 'dark'; session.terminalBackground = terminalBackground; session.terminalForeground = terminalForeground;
524
527
  wire(session, spawned.process); void terminateProcess(oldProcess); publish(session, { t: 'restarted', history: '' });
@@ -569,13 +572,17 @@ export function createTerminalRuntime({
569
572
 
570
573
  const stop = async () => {
571
574
  server.off('upgrade', upgradeHandler); clearInterval(idleSweep);
575
+ for (const client of wsServer?.clients ?? []) client.terminate();
572
576
  for (const pending of pendingSessionCreates.values()) pending.cancelled = true;
573
577
  await Promise.allSettled([
574
578
  ...[...pendingSessionCreates.values()].map((pending) => pending.promise),
575
579
  ...pendingSessionRestarts.values(),
576
580
  ]);
577
- for (const session of sessions.values()) void terminateProcess(session.process, true);
581
+ const terminals = [...sessions.values()]
582
+ .filter(session => session.status === 'running' && session.process)
583
+ .map(session => ({ process: session.process, shellExecutable: session.shellExecutable }));
578
584
  sessions.clear();
585
+ await shutdownProcesses(terminals);
579
586
  await Promise.allSettled([...pendingTerminations]);
580
587
  if (!wsServer) return;
581
588
  for (const client of wsServer.clients) client.terminate();
@@ -134,6 +134,7 @@ function createRuntime(server, overrides = {}) {
134
134
  isExecutable: () => false,
135
135
  isRequestOriginAllowed: async () => true,
136
136
  rejectWebSocketUpgrade() {},
137
+ shutdownProcesses: async terminals => { for (const terminal of terminals) terminal.process.kill('SIGKILL'); },
137
138
  TERMINAL_INPUT_WS_HEARTBEAT_INTERVAL_MS: 30_000,
138
139
  TERMINAL_INPUT_WS_REBIND_WINDOW_MS: 1_000,
139
140
  TERMINAL_INPUT_WS_MAX_REBINDS_PER_WINDOW: 3,
@@ -229,6 +230,27 @@ describe('terminal runtime', () => {
229
230
  await harness.runtime.shutdown();
230
231
  });
231
232
 
233
+ it('joins terminal cleanup and retires sessions before waiting for shutdown', async () => {
234
+ const gate = deferred();
235
+ let terminals;
236
+ const harness = createHarness({ shutdownProcesses: async current => { terminals = current; await gate.promise; } });
237
+ await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'running', cwd: '/repo' } }, createResponse());
238
+ let done = false;
239
+ const closing = harness.runtime.shutdown();
240
+ expect(harness.runtime.shutdown()).toBe(closing);
241
+ closing.then(() => { done = true; });
242
+ await new Promise(resolve => setImmediate(resolve));
243
+ expect(terminals).toHaveLength(1);
244
+ expect(terminals[0].process).toBe(harness.processes[0]);
245
+ expect(done).toBe(false);
246
+ const later = createResponse();
247
+ await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'later', cwd: '/repo' } }, later);
248
+ expect(later.statusCode).toBe(400);
249
+ gate.resolve();
250
+ await closing;
251
+ expect(done).toBe(true);
252
+ });
253
+
232
254
  for (const removal of ['close', 'force-kill']) {
233
255
  it(`reaps a replacement PTY when ${removal} wins a pending restart`, async () => {
234
256
  const gate = { promise: Promise.resolve() };
@@ -0,0 +1,106 @@
1
+ import { execFile } from 'node:child_process';
2
+ import fs from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { promisify } from 'node:util';
5
+
6
+ const execFileAsync = promisify(execFile);
7
+ const SHUTDOWN_GRACE_MS = 20_000;
8
+
9
+ // Job-control shells give foreground/background jobs their own process groups.
10
+ // Killing only -pty.pid misses those jobs; closing the PTY first sends SIGHUP.
11
+ const readProcesses = async () => {
12
+ // Minimal server/container installations need not ship procps.
13
+ if (process.platform === 'linux') {
14
+ const processes = new Map();
15
+ for (const entry of await fs.readdir('/proc')) {
16
+ if (!/^\d+$/.test(entry)) continue;
17
+ let stat;
18
+ try { stat = await fs.readFile(`/proc/${entry}/stat`, 'utf8'); }
19
+ catch (error) { if (error.code === 'ENOENT' || error.code === 'ESRCH') continue; throw error; }
20
+ const end = stat.lastIndexOf(')');
21
+ const fields = stat.slice(end + 2).trim().split(/\s+/);
22
+ const pid = Number(entry);
23
+ processes.set(pid, { pid, parent: Number(fields[1]), group: Number(fields[2]), zombie: fields[0] === 'Z', started: fields[19], command: stat.slice(stat.indexOf('(') + 1, end) });
24
+ }
25
+ return processes;
26
+ }
27
+ const { stdout } = await execFileAsync('/bin/ps', ['-axo', 'pid=,ppid=,pgid=,stat=,lstart=,comm='], { timeout: 1000, maxBuffer: 4 * 1024 * 1024 });
28
+ return new Map(stdout.trim().split('\n').map(line => {
29
+ const fields = line.trim().split(/\s+/);
30
+ return [Number(fields[0]), { pid: Number(fields[0]), parent: Number(fields[1]), group: Number(fields[2]), zombie: fields[3].startsWith('Z'), started: fields.slice(4, 9).join(' '), command: fields.slice(9).join(' ') }];
31
+ }));
32
+ };
33
+
34
+ const signal = (pid, name) => {
35
+ try { process.kill(pid, name); } catch (error) { if (error.code !== 'ESRCH') throw error; }
36
+ };
37
+
38
+ export async function shutdownTerminalProcesses(terminals, { graceMs = SHUTDOWN_GRACE_MS } = {}) {
39
+ if (!terminals.length) return;
40
+ // ConPTY has no POSIX signal protocol. Its backend owns tree teardown.
41
+ if (process.platform === 'win32') {
42
+ for (const { process: pty } of terminals) {
43
+ try { pty.kill(); } catch { /* already gone; other terminals still need cleanup */ }
44
+ }
45
+ return;
46
+ }
47
+
48
+ const deadline = Date.now() + graceMs;
49
+ const owned = new Map();
50
+ const shells = new Map();
51
+ try {
52
+ let snapshot = await readProcesses();
53
+ for (const terminal of terminals) {
54
+ const current = snapshot.get(terminal.process.pid);
55
+ if (!current || current.zombie) continue;
56
+ owned.set(current.pid, { ...current, terminal: current.pid });
57
+ // An exec'ed server occupies the shell PID, but must get the same grace
58
+ // as a child. Only an actual shell is held open until its jobs finish.
59
+ if (path.basename(current.command) === path.basename(terminal.shellExecutable)) shells.set(current.pid, terminal.process);
60
+ }
61
+ const signalled = new Set();
62
+ while (owned.size) {
63
+ for (const [pid, previous] of owned) {
64
+ const current = snapshot.get(pid);
65
+ if (!current || current.zombie || current.started !== previous.started) { owned.delete(pid); shells.delete(pid); }
66
+ else if (current.command !== previous.command) shells.delete(pid);
67
+ }
68
+ // Retain descendants before signalling anything, including separate job
69
+ // groups and children still cleaning up after their parent has exited.
70
+ let added;
71
+ do {
72
+ added = false;
73
+ for (const current of snapshot.values()) {
74
+ if (!current.zombie && !owned.has(current.pid) && owned.has(current.parent)) {
75
+ owned.set(current.pid, { ...current, terminal: owned.get(current.parent).terminal });
76
+ added = true;
77
+ }
78
+ }
79
+ } while (added);
80
+ for (const pid of owned.keys()) {
81
+ if (!shells.has(pid) && !signalled.has(pid)) { signal(pid, 'SIGTERM'); signalled.add(pid); }
82
+ }
83
+ for (const [pid, pty] of shells) {
84
+ const hasJobs = [...owned.values()].some(current => current.terminal === pid && current.pid !== pid);
85
+ if (!hasJobs && !signalled.has(pid)) { pty.kill('SIGHUP'); signalled.add(pid); }
86
+ }
87
+ if (!owned.size) return;
88
+ if (Date.now() >= deadline) {
89
+ for (const current of owned.values()) {
90
+ if (current.group === current.pid) signal(-current.group, 'SIGKILL');
91
+ signal(current.pid, 'SIGKILL');
92
+ }
93
+ return;
94
+ }
95
+ await new Promise(resolve => setTimeout(resolve, 250));
96
+ snapshot = await readProcesses();
97
+ }
98
+ } catch (error) {
99
+ // A failed process-table read is not evidence that the jobs exited.
100
+ console.warn('Terminal graceful shutdown failed; forcing owned PTYs closed:', error.message);
101
+ for (const pid of owned.keys()) { try { signal(pid, 'SIGKILL'); } catch { /* best effort */ } }
102
+ for (const { process: pty } of terminals) {
103
+ try { pty.kill('SIGKILL'); } catch { /* continue with the remaining PTYs */ }
104
+ }
105
+ }
106
+ }