@openchamber/web 1.24.2 → 2.0.1

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 (387) hide show
  1. package/bin/lib/commands-connect-url.js +3 -8
  2. package/bin/lib/commands-tunnel.js +3 -0
  3. package/dist/assets/{CodeMirrorCommentWidgets-B_vBPQYm.js → CodeMirrorCommentWidgets-zm3C1FvM.js} +1 -1
  4. package/dist/assets/DiffView-DNExNi1z.js +4 -0
  5. package/dist/assets/FilesView-DUCLmHBi.js +17 -0
  6. package/dist/assets/{GitView-k0hUF8KB.js → GitView-Bz9z6gZA.js} +4 -4
  7. package/dist/assets/{GuestAttachDialog-DIf2U85Z.js → GuestAttachDialog-UGp4KDlK.js} +1 -1
  8. package/dist/assets/GuestSurfacePane-B3pdB_2u.js +1 -0
  9. package/dist/assets/{JsonTreeView-4AnJ04Pw.js → JsonTreeView-7lVecnZl.js} +1 -1
  10. package/dist/assets/LinearIssuesView-CTGRS9Vq.js +1 -0
  11. package/dist/assets/MarkdownImageGallery-DQk5adUs.js +1 -0
  12. package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +12 -0
  13. package/dist/assets/OnboardingScreen-CBx6cXPP.js +1 -0
  14. package/dist/assets/{PatchDiff-DpGmHRnV.js → PatchDiff-D7VVpR_l.js} +1 -1
  15. package/dist/assets/{PierreDiffViewer-CgLl_tp7.js → PierreDiffViewer-Gbfks1pk.js} +3 -3
  16. package/dist/assets/PlanView-CPSK0x97.js +5 -0
  17. package/dist/assets/PluginPane-BIGsUx69.js +3 -0
  18. package/dist/assets/SettingsView-Dql7z6Ww.js +30 -0
  19. package/dist/assets/SettingsWindow-D6oi-UmV.js +1 -0
  20. package/dist/assets/SubmoduleDiffSummary-BXA0FAWj.js +1 -0
  21. package/dist/assets/ToolOutputDialog-BQJsSbDm.js +15 -0
  22. package/dist/assets/ToolPartDiffPreview-FY9w0TVT.js +8 -0
  23. package/dist/assets/{VirtualizedFileDiff-BK4aU5qJ.js → VirtualizedFileDiff-B9YhAya5.js} +4 -4
  24. package/dist/assets/{WalkthroughView-Bk6TPNFw.js → WalkthroughView-CmFgOUFN.js} +2 -2
  25. package/dist/assets/appThemeRegistry-BebxalUt.js +1 -0
  26. package/dist/assets/changesTree-CePHbFcj.js +1 -0
  27. package/dist/assets/commitAndPush-Wfxng_IK.js +1 -0
  28. package/dist/assets/{computeVirtualFileMetrics-BVTujWSX.js → computeVirtualFileMetrics-BCOqgixN.js} +2 -2
  29. package/dist/assets/de-CMA45TC-.js +10 -0
  30. package/dist/assets/es-DPL4fBtl.js +16 -0
  31. package/dist/assets/fr-OHBKBseP.js +14 -0
  32. package/dist/assets/index-3TiDNtfN.js +1 -0
  33. package/dist/assets/index-BLUZa5u0.js +41 -0
  34. package/dist/assets/index-Cm2rrq69.css +1 -0
  35. package/dist/assets/{isDiffPlainText-D3yX_vx4.js → isDiffPlainText-DnDYQmWK.js} +1 -1
  36. package/dist/assets/{isFilePlainText-CZR9TcHV.js → isFilePlainText-BA_AHX7d.js} +1 -1
  37. package/dist/assets/ja-DvX4WSRf.js +16 -0
  38. package/dist/assets/ko-BUcLd8YZ.js +16 -0
  39. package/dist/assets/main-B_jri4i-.js +896 -0
  40. package/dist/assets/main-DtUmJp9B.js +2 -0
  41. package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
  42. package/dist/assets/markdownCore-BSnlUXBf.js +7 -0
  43. package/dist/assets/miniChat-BYfLUnDK.js +2 -0
  44. package/dist/assets/mobile-DH3hI6gd.js +2 -0
  45. package/dist/assets/patchFileDiff--L7lt_GZ.js +13 -0
  46. package/dist/assets/pl-BkI_xHqz.js +16 -0
  47. package/dist/assets/pt-BR-7wFtQlV9.js +16 -0
  48. package/dist/assets/renderElectronMiniChatApp-C7kpNW_-.js +2 -0
  49. package/dist/assets/renderMobileApp-i0nq7Dwy.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +27 -0
  51. package/dist/assets/scheduledTasksApi-Cy7uZCaI.js +1 -0
  52. package/dist/assets/{shikiHighlight-BfjuB3CD.js → shikiHighlight-D4vxipfr.js} +1 -1
  53. package/dist/assets/{textMateThemeFromAppTheme-BP60t9SX.js → textMateThemeFromAppTheme-BYAHtJwQ.js} +1 -1
  54. package/dist/assets/tr-TsD-AqEH.js +7 -0
  55. package/dist/assets/uk-B-qspCmD.js +16 -0
  56. package/dist/assets/useAppFontEffects-DHZ9-L30.js +7338 -0
  57. package/dist/assets/useInlineCommentController-CvpOMK-R.js +2 -0
  58. package/dist/assets/useRootScrollLock-DzNFi-fn.js +2 -0
  59. package/dist/assets/{vendor-codemirror-language-data-BFm1Ju2w.js → vendor-codemirror-language-data-j3fhlwUM.js} +2 -2
  60. package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
  61. package/dist/assets/vendor-opencode-client-DYdsLbCM.js +12 -0
  62. package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
  63. package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
  64. package/dist/assets/{web-components-2vo9YsZc.js → web-components-BvHNFSEG.js} +2 -2
  65. package/dist/assets/zh-CN-DYuPJV5i.js +16 -0
  66. package/dist/assets/zh-TW-BX_2D_lV.js +16 -0
  67. package/dist/index.html +13 -7
  68. package/dist/mini-chat.html +5 -5
  69. package/dist/mobile.html +5 -5
  70. package/package.json +6 -5
  71. package/server/index.d.ts +1 -0
  72. package/server/index.js +264 -91
  73. package/server/lib/agent-tool/DOCUMENTATION.md +38 -16
  74. package/server/lib/agent-tool/runtime.js +167 -58
  75. package/server/lib/agent-tool/runtime.test.js +170 -87
  76. package/server/lib/browser-control/DOCUMENTATION.md +51 -4
  77. package/server/lib/browser-control/provider.js +217 -0
  78. package/server/lib/browser-control/provider.test.js +251 -0
  79. package/server/lib/context-obligatory/runtime.js +61 -50
  80. package/server/lib/context-obligatory/runtime.test.js +62 -162
  81. package/server/lib/event-stream/DOCUMENTATION.md +12 -1
  82. package/server/lib/event-stream/delta-coalescer.js +0 -0
  83. package/server/lib/event-stream/delta-coalescer.test.js +68 -57
  84. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  85. package/server/lib/event-stream/global-hub.js +10 -1
  86. package/server/lib/event-stream/global-hub.test.js +27 -26
  87. package/server/lib/event-stream/index.js +6 -0
  88. package/server/lib/event-stream/protocol.js +26 -19
  89. package/server/lib/event-stream/protocol.test.js +18 -7
  90. package/server/lib/event-stream/rebind.test.js +5 -5
  91. package/server/lib/event-stream/runtime.test.js +17 -15
  92. package/server/lib/event-stream/translate-v2.js +313 -0
  93. package/server/lib/event-stream/translate-v2.test.js +209 -0
  94. package/server/lib/event-stream/upstream-reader.test.js +16 -16
  95. package/server/lib/fs/DOCUMENTATION.md +4 -2
  96. package/server/lib/fs/byte-range.js +35 -0
  97. package/server/lib/fs/byte-range.test.js +31 -0
  98. package/server/lib/fs/routes.js +47 -42
  99. package/server/lib/fs/routes.test.js +123 -18
  100. package/server/lib/git/DOCUMENTATION.md +1 -1
  101. package/server/lib/git/service.js +34 -0
  102. package/server/lib/git/service.test.js +8 -0
  103. package/server/lib/github/DOCUMENTATION.md +1 -1
  104. package/server/lib/github/pr-status.js +22 -2
  105. package/server/lib/github/pr-status.test.js +27 -14
  106. package/server/lib/guests/DOCUMENTATION.md +16 -2
  107. package/server/lib/guests/catalog.js +31 -1
  108. package/server/lib/guests/catalog.test.js +55 -0
  109. package/server/lib/guests/html-styles.js +5 -3
  110. package/server/lib/guests/html-styles.test.js +3 -1
  111. package/server/lib/guests/routes.js +21 -4
  112. package/server/lib/guests/service.js +197 -14
  113. package/server/lib/guests/service.test.js +201 -1
  114. package/server/lib/guests/surface.js +676 -0
  115. package/server/lib/guests/surface.test.js +536 -0
  116. package/server/lib/markdown-image-grants/routes.js +18 -5
  117. package/server/lib/markdown-image-grants/routes.test.js +9 -6
  118. package/server/lib/message-queue/DOCUMENTATION.md +33 -22
  119. package/server/lib/message-queue/runtime.js +155 -100
  120. package/server/lib/message-queue/runtime.test.js +168 -82
  121. package/server/lib/notifications/DOCUMENTATION.md +38 -0
  122. package/server/lib/notifications/control-stream.http.test.js +68 -0
  123. package/server/lib/notifications/emit-route.js +118 -0
  124. package/server/lib/notifications/emit-route.test.js +112 -0
  125. package/server/lib/notifications/emitter-runtime.js +15 -0
  126. package/server/lib/notifications/emitter-runtime.test.js +32 -0
  127. package/server/lib/notifications/push-runtime.js +5 -1
  128. package/server/lib/notifications/push-runtime.test.js +2 -2
  129. package/server/lib/notifications/routes.js +1 -1
  130. package/server/lib/notifications/runtime.js +115 -26
  131. package/server/lib/notifications/template-runtime.js +13 -15
  132. package/server/lib/notifications/template-runtime.test.js +16 -9
  133. package/server/lib/notifications/trigger-runtime.test.js +187 -0
  134. package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
  135. package/server/lib/openchamber-control/actions.js +19 -4
  136. package/server/lib/openchamber-control/error.js +1 -1
  137. package/server/lib/openchamber-control/file-open.js +59 -0
  138. package/server/lib/openchamber-control/file-open.test.js +57 -0
  139. package/server/lib/openchamber-control/routes.test.js +12 -0
  140. package/server/lib/openchamber-control/service.js +125 -49
  141. package/server/lib/openchamber-control/service.test.js +115 -44
  142. package/server/lib/openchamber-sessions/archive-store.js +224 -0
  143. package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
  144. package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
  145. package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
  146. package/server/lib/openchamber-sessions/opencode-client.js +22 -0
  147. package/server/lib/openchamber-sessions/routes.js +409 -328
  148. package/server/lib/openchamber-sessions/routes.test.js +795 -740
  149. package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
  150. package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
  151. package/server/lib/opencode/DOCUMENTATION.md +458 -29
  152. package/server/lib/opencode/agents.js +233 -327
  153. package/server/lib/opencode/auth.js +41 -44
  154. package/server/lib/opencode/auth.test.js +92 -0
  155. package/server/lib/opencode/bootstrap-runtime.js +12 -0
  156. package/server/lib/opencode/cli-upgrade.d.ts +4 -0
  157. package/server/lib/opencode/cli-upgrade.js +18 -0
  158. package/server/lib/opencode/cli-upgrade.test.js +36 -0
  159. package/server/lib/opencode/commands.js +164 -145
  160. package/server/lib/opencode/compatibility.d.ts +16 -0
  161. package/server/lib/opencode/compatibility.js +91 -0
  162. package/server/lib/opencode/compatibility.test.js +70 -0
  163. package/server/lib/opencode/config-entity-routes.js +58 -29
  164. package/server/lib/opencode/config-entity-v2.test.js +290 -0
  165. package/server/lib/opencode/config-mutation-response.js +17 -7
  166. package/server/lib/opencode/config-mutation-response.test.js +4 -7
  167. package/server/lib/opencode/config-paths.test.js +2 -2
  168. package/server/lib/opencode/config-v2.d.ts +185 -0
  169. package/server/lib/opencode/config-v2.js +843 -0
  170. package/server/lib/opencode/config-v2.test.js +483 -0
  171. package/server/lib/opencode/core-routes.js +3 -0
  172. package/server/lib/opencode/core-routes.test.js +15 -0
  173. package/server/lib/opencode/credential-db.js +144 -0
  174. package/server/lib/opencode/credential-db.test.js +104 -0
  175. package/server/lib/opencode/env-runtime.js +47 -15
  176. package/server/lib/opencode/env-runtime.test.js +45 -0
  177. package/server/lib/opencode/feature-routes-runtime.js +16 -5
  178. package/server/lib/opencode/lifecycle-process.test.js +7 -4
  179. package/server/lib/opencode/lifecycle.js +113 -30
  180. package/server/lib/opencode/lifecycle.test.js +107 -8
  181. package/server/lib/opencode/login-shell-env.js +27 -0
  182. package/server/lib/opencode/managed-config-file.js +131 -0
  183. package/server/lib/opencode/managed-config-file.test.js +168 -0
  184. package/server/lib/opencode/managed-plugin-config.js +33 -13
  185. package/server/lib/opencode/mcp.js +43 -149
  186. package/server/lib/opencode/network-runtime.js +6 -7
  187. package/server/lib/opencode/openchamber-routes.js +29 -11
  188. package/server/lib/opencode/openchamber-routes.test.js +18 -1
  189. package/server/lib/opencode/plugin-routes.js +3 -3
  190. package/server/lib/opencode/plugin-routes.test.js +6 -24
  191. package/server/lib/opencode/plugins.js +91 -40
  192. package/server/lib/opencode/plugins.test.js +28 -15
  193. package/server/lib/opencode/provider-source-route.test.js +59 -0
  194. package/server/lib/opencode/providers.js +66 -83
  195. package/server/lib/opencode/providers.test.js +190 -59
  196. package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
  197. package/server/lib/opencode/proxy.js +179 -129
  198. package/server/lib/opencode/pwa-manifest-routes.js +4 -2
  199. package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
  200. package/server/lib/opencode/response-envelope.js +14 -0
  201. package/server/lib/opencode/response-envelope.test.js +23 -0
  202. package/server/lib/opencode/routes-upgrade.test.js +73 -116
  203. package/server/lib/opencode/routes.js +138 -428
  204. package/server/lib/opencode/server-utils-runtime.js +10 -4
  205. package/server/lib/opencode/session-activity.js +78 -0
  206. package/server/lib/opencode/session-runtime.js +21 -10
  207. package/server/lib/opencode/session-runtime.test.js +9 -9
  208. package/server/lib/opencode/settings-helpers.js +15 -8
  209. package/server/lib/opencode/settings-helpers.test.js +7 -12
  210. package/server/lib/opencode/settings-registry.json +20 -8
  211. package/server/lib/opencode/settings-runtime.js +19 -1
  212. package/server/lib/opencode/settings-runtime.test.js +31 -2
  213. package/server/lib/opencode/shared.js +86 -24
  214. package/server/lib/opencode/shared.test.js +87 -5
  215. package/server/lib/opencode/shutdown-runtime.js +54 -7
  216. package/server/lib/opencode/shutdown-runtime.test.js +224 -30
  217. package/server/lib/opencode/skill-routes.js +51 -36
  218. package/server/lib/opencode/skill-routes.test.js +121 -1
  219. package/server/lib/opencode/skills.js +7 -5
  220. package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
  221. package/server/lib/opencode/upgrade-capability.js +0 -14
  222. package/server/lib/opencode/upgrade-capability.test.js +1 -1
  223. package/server/lib/opencode/v1-migration-topup.js +294 -0
  224. package/server/lib/opencode/v1-migration-topup.test.js +274 -0
  225. package/server/lib/opencode/v2-install.d.ts +9 -0
  226. package/server/lib/opencode/v2-install.js +159 -0
  227. package/server/lib/opencode/v2-install.test.js +133 -0
  228. package/server/lib/opencode/watcher.js +10 -3
  229. package/server/lib/opencode/watcher.test.js +17 -21
  230. package/server/lib/opencode/websearch-config.js +78 -0
  231. package/server/lib/permission-auto-accept/runtime.js +38 -22
  232. package/server/lib/permission-auto-accept/runtime.test.js +39 -17
  233. package/server/lib/quota/DOCUMENTATION.md +4 -0
  234. package/server/lib/quota/providers/kimi.js +1 -1
  235. package/server/lib/quota/providers/xai.js +4 -4
  236. package/server/lib/relay/tunnel-host.js +4 -1
  237. package/server/lib/relay/tunnel-host.test.js +7 -0
  238. package/server/lib/routing/DOCUMENTATION.md +52 -21
  239. package/server/lib/routing/defaults.js +23 -6
  240. package/server/lib/routing/jev.js +17 -7
  241. package/server/lib/routing/routes.http.test.js +68 -33
  242. package/server/lib/routing/routes.js +65 -22
  243. package/server/lib/routing/runtime.js +145 -48
  244. package/server/lib/routing/runtime.test.js +79 -55
  245. package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
  246. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
  247. package/server/lib/scheduled-tasks/runtime.js +81 -74
  248. package/server/lib/scheduled-tasks/runtime.test.js +53 -1
  249. package/server/lib/session-assist/DOCUMENTATION.md +25 -8
  250. package/server/lib/session-assist/context.js +122 -46
  251. package/server/lib/session-assist/context.test.js +117 -49
  252. package/server/lib/session-assist/runtime.js +71 -24
  253. package/server/lib/session-assist/runtime.test.js +153 -173
  254. package/server/lib/session-goal/DOCUMENTATION.md +34 -15
  255. package/server/lib/session-goal/create.js +9 -12
  256. package/server/lib/session-goal/create.test.js +27 -28
  257. package/server/lib/session-goal/runtime.js +164 -77
  258. package/server/lib/session-goal/runtime.test.js +271 -519
  259. package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
  260. package/server/lib/session-knowledge/runtime.js +59 -41
  261. package/server/lib/session-knowledge/runtime.test.js +90 -20
  262. package/server/lib/small-model/DOCUMENTATION.md +154 -208
  263. package/server/lib/small-model/client.js +113 -0
  264. package/server/lib/small-model/index.js +296 -158
  265. package/server/lib/small-model/index.test.js +423 -256
  266. package/server/lib/small-model/routes.js +1 -1
  267. package/server/lib/spaces/DOCUMENTATION.md +807 -0
  268. package/server/lib/spaces/code-in-bait.js +185 -0
  269. package/server/lib/spaces/code-in.js +641 -0
  270. package/server/lib/spaces/code-in.test.js +1048 -0
  271. package/server/lib/spaces/errors.js +8 -0
  272. package/server/lib/spaces/exec-http.js +94 -0
  273. package/server/lib/spaces/gatekeeper-channel.js +202 -0
  274. package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
  275. package/server/lib/spaces/gatekeeper-program.cjs +914 -0
  276. package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
  277. package/server/lib/spaces/hardening.js +457 -0
  278. package/server/lib/spaces/hardening.test.js +368 -0
  279. package/server/lib/spaces/host-git.js +127 -0
  280. package/server/lib/spaces/host-git.test.js +137 -0
  281. package/server/lib/spaces/labels.js +234 -0
  282. package/server/lib/spaces/labels.test.js +219 -0
  283. package/server/lib/spaces/layout.js +184 -0
  284. package/server/lib/spaces/layout.test.js +30 -0
  285. package/server/lib/spaces/manager.js +82 -0
  286. package/server/lib/spaces/manager.test.js +114 -0
  287. package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
  288. package/server/lib/spaces/places/contract-suite.js +156 -0
  289. package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
  290. package/server/lib/spaces/places/contract.test.js +6 -0
  291. package/server/lib/spaces/places/docker-engine.js +126 -0
  292. package/server/lib/spaces/places/docker-live-support.js +202 -0
  293. package/server/lib/spaces/places/docker-tools.js +186 -0
  294. package/server/lib/spaces/places/docker.js +587 -0
  295. package/server/lib/spaces/places/docker.test.js +1610 -0
  296. package/server/lib/spaces/places/escape-suite.js +1018 -0
  297. package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
  298. package/server/lib/spaces/places/fake-docker.js +375 -0
  299. package/server/lib/spaces/places/memory-place.js +103 -0
  300. package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
  301. package/server/lib/spaces/places/registry.js +43 -0
  302. package/server/lib/spaces/places/registry.test.js +50 -0
  303. package/server/lib/spaces/places/server.docker.live.test.js +225 -0
  304. package/server/lib/spaces/run-command.js +261 -0
  305. package/server/lib/spaces/run-command.test.js +396 -0
  306. package/server/lib/spaces/space-server.js +190 -0
  307. package/server/lib/spaces/space-server.test.js +335 -0
  308. package/server/lib/spaces/tools-filler.js +82 -0
  309. package/server/lib/spaces/tools-filler.test.js +148 -0
  310. package/server/lib/spaces/tools-pack.js +49 -0
  311. package/server/lib/spaces/tools-pack.test.js +57 -0
  312. package/server/lib/spaces/tools.js +137 -0
  313. package/server/lib/spaces/tools.test.js +153 -0
  314. package/server/lib/tts/openai-sdk.js +11 -0
  315. package/server/lib/tts/service.js +7 -5
  316. package/server/lib/tts/stt.js +3 -2
  317. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  318. package/server/lib/tunnels/routes.js +7 -0
  319. package/server/lib/tunnels/routes.test.js +55 -0
  320. package/server/lib/ui-auth/ui-auth.js +38 -2
  321. package/server/lib/ui-auth/ui-auth.test.js +42 -0
  322. package/server/lib/ui-auth/ui-passkeys.js +12 -10
  323. package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
  324. package/server/lib/walkthrough/pull-request.js +61 -8
  325. package/server/lib/walkthrough/pull-request.test.js +54 -1
  326. package/server/lib/walkthrough/routes.js +20 -0
  327. package/server/lib/walkthrough/routes.test.js +19 -0
  328. package/server/opencode-proxy.test.js +190 -166
  329. package/server/opencode-worktree-readiness.test.js +5 -4
  330. package/dist/assets/DiffView-Ce0oBXXQ.js +0 -4
  331. package/dist/assets/FilesView-DtXueAWP.js +0 -13
  332. package/dist/assets/LinearIssuesView-z_9p2GuO.js +0 -1
  333. package/dist/assets/MarkdownImageGallery-BC-BNN-s.js +0 -1
  334. package/dist/assets/MarkdownRendererImpl-DyaBTUbH.js +0 -12
  335. package/dist/assets/OnboardingScreen-DKU_yTb6.js +0 -1
  336. package/dist/assets/PlanView-CrfB4qqY.js +0 -5
  337. package/dist/assets/PluginPane-B5cn-jPy.js +0 -3
  338. package/dist/assets/SettingsView-DMKKwezx.js +0 -29
  339. package/dist/assets/SettingsWindow-DwbnVzOC.js +0 -1
  340. package/dist/assets/SubmoduleDiffSummary-hkGcvs0E.js +0 -1
  341. package/dist/assets/ToolOutputDialog-DuoIOc0j.js +0 -15
  342. package/dist/assets/ToolPartDiffPreview-t1Bvq_2Y.js +0 -8
  343. package/dist/assets/appThemeRegistry-DnOVbJjF.js +0 -1
  344. package/dist/assets/commitAndPush-DLWNZkkY.js +0 -1
  345. package/dist/assets/de-zEHaAIi3.js +0 -10
  346. package/dist/assets/es-CBDgEzgk.js +0 -16
  347. package/dist/assets/fr-DjiTptT_.js +0 -14
  348. package/dist/assets/index-AgOdanig.css +0 -1
  349. package/dist/assets/index-B-2_X4DD.js +0 -40
  350. package/dist/assets/index-CkA4p2IK.js +0 -1
  351. package/dist/assets/ja-CerMgj3r.js +0 -16
  352. package/dist/assets/ko-DHYDAze5.js +0 -16
  353. package/dist/assets/main-BDka4W43.js +0 -896
  354. package/dist/assets/main-Dl7Dyge_.js +0 -2
  355. package/dist/assets/markdownCore-DFmr0rUR.js +0 -5
  356. package/dist/assets/miniChat-CLKQPPpO.js +0 -2
  357. package/dist/assets/mobile--giD2Q1L.js +0 -2
  358. package/dist/assets/patchFileDiff-DRh-AQvd.js +0 -13
  359. package/dist/assets/pl-BTB_93bq.js +0 -16
  360. package/dist/assets/pt-BR-BwA3oyCK.js +0 -16
  361. package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +0 -2
  362. package/dist/assets/renderMobileApp-pMfOuQfl.js +0 -25
  363. package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +0 -25
  364. package/dist/assets/scheduledTasksApi-CeRAIUmW.js +0 -1
  365. package/dist/assets/tr-CcPsJoNM.js +0 -7
  366. package/dist/assets/uk-B68WibXi.js +0 -16
  367. package/dist/assets/useAppFontEffects-DcdrFv2Z.js +0 -7333
  368. package/dist/assets/useInlineCommentController-Cq4SUjsA.js +0 -2
  369. package/dist/assets/useRootScrollLock-CSdR6Wnm.js +0 -2
  370. package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
  371. package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
  372. package/dist/assets/vendor-zod-CgAdXWZO.js +0 -39
  373. package/dist/assets/zh-CN-DbFHYXwP.js +0 -16
  374. package/dist/assets/zh-TW-DmXAwdty.js +0 -16
  375. package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
  376. package/server/lib/routing/feature-flag.js +0 -11
  377. package/server/lib/small-model/call.js +0 -851
  378. package/server/lib/small-model/call.test.js +0 -1292
  379. package/server/lib/small-model/catalog.js +0 -13
  380. package/server/lib/small-model/resolve.js +0 -131
  381. package/server/lib/small-model/resolve.test.js +0 -197
  382. package/server/lib/small-model/runtime-providers.js +0 -164
  383. package/server/lib/small-model/runtime-providers.test.js +0 -118
  384. package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
  385. package/server/lib/system-prompt/runtime.js +0 -49
  386. package/server/lib/system-prompt/runtime.test.js +0 -76
  387. package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
@@ -1,9 +1,11 @@
1
+ import { readOpenCodeInfo, readExternalOpenCodeVersion, isSupportedOpenCodeVersion, requireOpenCodeV2, UnsupportedOpenCodeVersionError } from './compatibility.js';
1
2
  import { spawn, spawnSync } from 'node:child_process';
2
3
  import net from 'node:net';
3
4
  import { stripAppImageArgv0Leak } from '../inherited-env.js';
4
5
  import { registerManagedProcess, unregisterManagedProcess, reapOrphanedProcesses } from './managed-process-registry.js';
5
6
  import { applyProviderEnvAliases } from './provider-env-aliases.js';
6
7
  import { recordStartupPerformance } from './startup-performance.js';
8
+ import { topUpV1Migration } from './v1-migration-topup.js';
7
9
 
8
10
  const parsePositiveInt = (value, fallback) => {
9
11
  const parsed = Number.parseInt(String(value ?? ''), 10);
@@ -17,7 +19,35 @@ const HEALTH_CHECK_MAX_CONSECUTIVE_FAILURES = parsePositiveInt(
17
19
  );
18
20
  const HEALTH_CHECK_INTERVAL_OVERRIDE_MS = parsePositiveInt(process.env.OPENCHAMBER_OPENCODE_HEALTH_INTERVAL_MS, 0);
19
21
  const HEALTH_CHECK_RESULT_CACHE_MS = parsePositiveInt(process.env.OPENCHAMBER_OPENCODE_HEALTH_CACHE_MS, 750);
20
- const OPENCODE_HEALTH_PATH = '/global/health';
22
+ const OPENCODE_HEALTH_PATH = '/api/info';
23
+ const OPENCODE_REQUIRED_MAJOR_VERSION = 2;
24
+
25
+ /**
26
+ * OpenChamber talks to OpenCode 2.x only. v1 serves its routes without the
27
+ * `/api` prefix, publishes a different event vocabulary and has no `plugins`
28
+ * config key, so an older binary fails in a hundred small ways instead of one
29
+ * clear one.
30
+ *
31
+ * The version comes from the health payload rather than from `opencode
32
+ * --version`: it costs no extra process, and it also covers an external
33
+ * OpenCode the user started themselves. `/api/info` only exists in 2.x (2.0.8
34
+ * removed the older `/api/health`), so a 404 there is the same answer by
35
+ * another route. A 200 is the readiness signal; the payload has no `healthy`
36
+ * field, only `{ version, pid, urls, paths }`.
37
+ */
38
+ const OPENCODE_VERSION_REQUIREMENT_DETAIL =
39
+ `OpenChamber requires OpenCode ${OPENCODE_REQUIRED_MAJOR_VERSION}.x`;
40
+
41
+ const classifyOpenCodeVersion = (version) => {
42
+ if (typeof version !== 'string') return { ok: true };
43
+ const match = version.match(/v?(\d+)\./);
44
+ if (!match) return { ok: true };
45
+ if (Number(match[1]) >= OPENCODE_REQUIRED_MAJOR_VERSION) return { ok: true };
46
+ return {
47
+ ok: false,
48
+ detail: `${OPENCODE_VERSION_REQUIREMENT_DETAIL}, found ${version.trim()}. Update OpenCode and start OpenChamber again.`,
49
+ };
50
+ };
21
51
  // Last-used directory plus the three most recently opened projects — deeper
22
52
  // tails are unlikely to be the user's first click and just add background work.
23
53
  const WARMUP_DIRECTORY_LIMIT = 4;
@@ -111,8 +141,12 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
111
141
  onOpenCodeRestarted = null,
112
142
  managedStartupTimeoutMs = 30_000,
113
143
  now = Date.now,
144
+ topUpV1SessionMigration = topUpV1Migration,
145
+ checkOpenCodeBinary = requireOpenCodeV2,
114
146
  } = deps;
115
147
 
148
+ let managedPreflight = null;
149
+
116
150
  const killProcessOnPortWin32 = (port) => {
117
151
  try {
118
152
  // Get-NetTCPConnection reads the same locale-independent WinNT API
@@ -472,12 +506,10 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
472
506
  stdout += chunk.toString();
473
507
  const lines = stdout.split('\n');
474
508
  for (const line of lines) {
475
- if (!line.startsWith('opencode server listening')) continue;
476
- const match = line.match(/on\s+(https?:\/\/[^\s]+)/);
477
- if (!match) {
478
- finish(reject, new Error(`Failed to parse server url from output: ${line}`));
479
- return;
480
- }
509
+ // OpenCode 2.x prints `server listening on http://host:port` with no
510
+ // "opencode" prefix.
511
+ const match = line.match(/server listening on\s+(https?:\/\/\S+)/);
512
+ if (!match) continue;
481
513
  attachRuntimeStderrCapture();
482
514
  finish(resolve, match[1]);
483
515
  return;
@@ -584,7 +616,9 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
584
616
  healthy: false,
585
617
  failure: {
586
618
  class: 'invalid_response',
587
- detail: `Health endpoint returned HTTP ${response.status ?? 'unknown'}`,
619
+ detail: response.status === 404
620
+ ? `${OPENCODE_VERSION_REQUIREMENT_DETAIL}: this server has no /api/info, which every 2.x server serves.`
621
+ : `Info endpoint returned HTTP ${response.status ?? 'unknown'}`,
588
622
  },
589
623
  };
590
624
  }
@@ -596,17 +630,15 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
596
630
  healthy: false,
597
631
  failure: {
598
632
  class: 'invalid_response',
599
- detail: 'Health endpoint returned invalid JSON',
633
+ detail: 'Info endpoint returned invalid JSON',
600
634
  },
601
635
  };
602
636
  }
603
- if (body?.healthy !== true) {
637
+ const version = classifyOpenCodeVersion(body?.version);
638
+ if (!version.ok) {
604
639
  return {
605
640
  healthy: false,
606
- failure: {
607
- class: 'invalid_response',
608
- detail: 'Health endpoint did not report healthy=true',
609
- },
641
+ failure: { class: 'invalid_response', detail: version.detail },
610
642
  };
611
643
  }
612
644
  return { healthy: true, failure: null };
@@ -638,14 +670,23 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
638
670
  signal: controller.signal,
639
671
  });
640
672
  clearTimeout(timeout);
641
- if (!response.ok) return false;
642
- const body = await response.json().catch(() => null);
643
- return body?.healthy === true;
673
+ const info = await readOpenCodeInfo(response);
674
+ return info !== null && isSupportedOpenCodeVersion(info.version);
644
675
  } catch {
645
676
  return false;
646
677
  }
647
678
  };
648
679
 
680
+ // The version of an explicitly configured server that answered but is not a
681
+ // supported OpenCode (v1, or 2.x below the minimum); null for anything else,
682
+ // including a server that is down.
683
+ const readUnsupportedExternalOpenCodeVersion = async (port, origin) => {
684
+ if (!port || port <= 0) return null;
685
+ const version = await readExternalOpenCodeVersion(origin ?? `http://127.0.0.1:${port}`, getOpenCodeAuthHeaders())
686
+ .catch(() => null);
687
+ return version && !isSupportedOpenCodeVersion(version) ? version : null;
688
+ };
689
+
649
690
  const waitForOpenCodePort = async (timeoutMs = 15000) => {
650
691
  if (state.openCodePort !== null) {
651
692
  return state.openCodePort;
@@ -680,6 +721,9 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
680
721
 
681
722
  await applyOpencodeBinaryFromSettings({ strict: true });
682
723
  const resolvedBinary = ensureOpencodeCliEnv();
724
+ const preflight = checkOpenCodeBinary(resolveManagedOpenCodeLaunchSpec(resolvedBinary));
725
+ managedPreflight = preflight.then(() => true, () => false);
726
+ await preflight;
683
727
  recordStartupPerformance('opencode.binary.ready', {
684
728
  attempt,
685
729
  durationMs: performance.now() - phaseStartedAt,
@@ -704,6 +748,18 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
704
748
  });
705
749
  phaseStartedAt = performance.now();
706
750
 
751
+ // Re-arm OpenCode's own V1 -> V2 session import for sessions a bundled
752
+ // OpenCode 1.x created after the migration already completed. Only for the
753
+ // managed process, only while it is not running, and never fatal.
754
+ try {
755
+ const topUp = topUpV1SessionMigration();
756
+ if (topUp && topUp.status !== 'skipped') {
757
+ console.log('[OpenCode] V1 session migration top-up:', topUp);
758
+ }
759
+ } catch (error) {
760
+ console.warn('[OpenCode] V1 session migration top-up failed:', error instanceof Error ? error.message : error);
761
+ }
762
+
707
763
  let serverInstance;
708
764
  try {
709
765
  if (state.isShuttingDown) throw new Error('OpenCode startup cancelled during shutdown');
@@ -776,13 +832,14 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
776
832
  };
777
833
 
778
834
  const startOpenCode = async () => {
835
+ managedPreflight = null;
779
836
  let lastError = null;
780
837
  for (let attempt = 1; attempt <= START_OPEN_CODE_MAX_ATTEMPTS; attempt += 1) {
781
838
  try {
782
839
  return await startOpenCodeOnce(attempt);
783
840
  } catch (error) {
784
841
  lastError = error;
785
- if (state.isShuttingDown || error?.code === 'OPENCODE_BINARY_INVALID') {
842
+ if (state.isShuttingDown || error instanceof UnsupportedOpenCodeVersionError || error?.code === 'OPENCODE_BINARY_INVALID') {
786
843
  break;
787
844
  }
788
845
  if (attempt >= START_OPEN_CODE_MAX_ATTEMPTS) {
@@ -810,6 +867,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
810
867
  }
811
868
 
812
869
  state.currentRestartPromise = (async () => {
870
+ managedPreflight = null;
813
871
  state.isRestartingOpenCode = true;
814
872
  state.isOpenCodeReady = false;
815
873
  state.openCodeNotReadySince = Date.now();
@@ -937,18 +995,14 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
937
995
  timeout = null;
938
996
 
939
997
  if (!response.ok) {
940
- lastError = new Error(`OpenCode health endpoint responded with status ${response.status}`);
941
- await new Promise((resolve) => setTimeout(resolve, intervalMs));
942
- continue;
943
- }
944
-
945
- const body = await response.json().catch(() => null);
946
- if (body?.healthy !== true) {
947
- lastError = new Error('OpenCode health endpoint returned unhealthy response');
998
+ lastError = new Error(`OpenCode info endpoint responded with status ${response.status}`);
948
999
  await new Promise((resolve) => setTimeout(resolve, intervalMs));
949
1000
  continue;
950
1001
  }
951
1002
 
1003
+ const info = await readOpenCodeInfo(response);
1004
+ if (!info) throw new Error('The server did not identify itself as OpenCode 2.x. OpenChamber requires OpenCode 2.x; if the server runs an older OpenCode, upgrade it.');
1005
+ if (!isSupportedOpenCodeVersion(info.version)) throw new UnsupportedOpenCodeVersionError(info.version);
952
1006
  state.isOpenCodeReady = true;
953
1007
  state.lastOpenCodeError = null;
954
1008
  return;
@@ -981,14 +1035,16 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
981
1035
  const deadline = Date.now() + timeoutMs;
982
1036
  while (Date.now() < deadline) {
983
1037
  try {
984
- const response = await fetch(buildOpenCodeUrl('/agent'), {
1038
+ const response = await fetch(buildOpenCodeUrl('/api/agent'), {
985
1039
  method: 'GET',
986
1040
  headers: { Accept: 'application/json', ...getOpenCodeAuthHeaders() },
987
1041
  });
988
1042
 
989
1043
  if (response.ok) {
990
- const agents = await response.json();
991
- if (Array.isArray(agents) && agents.some((agent) => agent?.name === agentName)) {
1044
+ // OpenCode 2.x answers `/api/*` with `{ location, data }`.
1045
+ const body = await response.json();
1046
+ const agents = Array.isArray(body) ? body : body?.data;
1047
+ if (Array.isArray(agents) && agents.some((agent) => agent?.id === agentName)) {
992
1048
  return;
993
1049
  }
994
1050
  }
@@ -1044,6 +1100,7 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
1044
1100
  const bootstrapOpenCodeAtStartup = async () => {
1045
1101
  const bootstrapStartedAt = performance.now();
1046
1102
  let bootstrapError = null;
1103
+ let unsupportedExternalVersion = null;
1047
1104
  recordStartupPerformance('opencode.bootstrap.start');
1048
1105
  try {
1049
1106
  // Before doing anything, reap any OpenCode process WE spawned in a prior
@@ -1084,6 +1141,20 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
1084
1141
  state.lastOpenCodeError = null;
1085
1142
  state.openCodeNotReadySince = 0;
1086
1143
  syncToHmrState();
1144
+ } else if (env.ENV_EFFECTIVE_PORT && (unsupportedExternalVersion = await readUnsupportedExternalOpenCodeVersion(
1145
+ env.ENV_EFFECTIVE_PORT,
1146
+ env.ENV_CONFIGURED_OPENCODE_HOST?.origin,
1147
+ ))) {
1148
+ // The configured server is an OpenCode this OpenChamber cannot use.
1149
+ // Attach to it anyway, not ready, so the compatibility check reports
1150
+ // its version instead of a managed instance silently replacing it.
1151
+ const label = env.ENV_CONFIGURED_OPENCODE_HOST ? env.ENV_CONFIGURED_OPENCODE_HOST.origin : `http://localhost:${env.ENV_EFFECTIVE_PORT}`;
1152
+ console.warn(`OpenCode ${unsupportedExternalVersion} at ${label} is not supported by this OpenChamber`);
1153
+ state.openCodeBaseUrl = env.ENV_CONFIGURED_OPENCODE_HOST?.origin ?? null;
1154
+ setOpenCodePort(env.ENV_EFFECTIVE_PORT);
1155
+ state.isExternalOpenCode = true;
1156
+ syncToHmrState();
1157
+ throw new UnsupportedOpenCodeVersionError(unsupportedExternalVersion);
1087
1158
  } else {
1088
1159
  // We never auto-attach to an arbitrary pre-existing OpenCode instance.
1089
1160
  // Attaching to an external server requires explicit opt-in via env
@@ -1110,6 +1181,9 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
1110
1181
  await waitForOpenCodeReady();
1111
1182
  } catch (error) {
1112
1183
  bootstrapError = error;
1184
+ // Skip-start mode assumed readiness up front; a server that never
1185
+ // proved itself must not keep reporting ready to startup diagnostics.
1186
+ state.isOpenCodeReady = false;
1113
1187
  console.error(`OpenCode readiness check failed: ${error.message}`);
1114
1188
  }
1115
1189
  } catch (error) {
@@ -1155,7 +1229,10 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
1155
1229
  try {
1156
1230
  const controller = new AbortController();
1157
1231
  timeout = setTimeout(() => controller.abort(), WARMUP_REQUEST_TIMEOUT_MS);
1158
- const url = `${buildOpenCodeUrl('/session/status', '')}?directory=${encodeURIComponent(directory)}`;
1232
+ // Warming a directory is the point, not the answer: any directory-scoped
1233
+ // read makes OpenCode initialise it. `/api/session` is the cheapest one
1234
+ // that takes a directory (`/api/session/active` is global).
1235
+ const url = `${buildOpenCodeUrl('/api/session', '')}?directory=${encodeURIComponent(directory)}&limit=1`;
1159
1236
  await fetch(url, {
1160
1237
  method: 'GET',
1161
1238
  headers: { Accept: 'application/json', ...getOpenCodeAuthHeaders() },
@@ -1321,6 +1398,12 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
1321
1398
  };
1322
1399
 
1323
1400
  return {
1401
+ getManagedOpenCodePreflight: async () => {
1402
+ const preflight = managedPreflight;
1403
+ if (!preflight || state.isExternalOpenCode || state.isShuttingDown) return false;
1404
+ const compatible = await preflight;
1405
+ return compatible && preflight === managedPreflight && !state.isExternalOpenCode && !state.isShuttingDown;
1406
+ },
1324
1407
  killProcessOnPort,
1325
1408
  startOpenCode,
1326
1409
  restartOpenCode,
@@ -102,7 +102,8 @@ const createRuntime = (overrides = {}, stateOverrides = {}, envOverrides = {}) =
102
102
  waitForReady: vi.fn(async () => true),
103
103
  normalizeApiPrefix: vi.fn(() => ''),
104
104
  applyOpencodeBinaryFromSettings: vi.fn(async () => null),
105
- ensureOpencodeCliEnv: vi.fn(),
105
+ checkOpenCodeBinary: async () => '2.0.14',
106
+ ensureOpencodeCliEnv: vi.fn(),
106
107
  ensureLocalOpenCodeServerPassword: vi.fn(async () => 'password'),
107
108
  resolveManagedOpenCodeLaunchSpec: vi.fn((binary) => ({ binary, args: [], wrapperType: null })),
108
109
  setOpenCodePort: vi.fn((port) => {
@@ -114,6 +115,8 @@ const createRuntime = (overrides = {}, stateOverrides = {}, envOverrides = {}) =
114
115
  clearResolvedOpenCodeBinary: vi.fn(),
115
116
  buildAugmentedPath: vi.fn(() => '/home/user/.bun/bin:/usr/local/bin:/usr/bin'),
116
117
  buildManagedOpenCodePath: vi.fn(() => '/home/user/.bun/bin:/usr/local/bin:/usr/bin'),
118
+ // Never let a test touch the real `~/.local/share/opencode/opencode.db`.
119
+ topUpV1SessionMigration: vi.fn(() => ({ status: 'skipped', missing: 0, revisited: 0, reason: 'no-database' })),
117
120
  getManagedOpenCodeShellEnvSnapshot: vi.fn(() => ({
118
121
  PATH: '/home/user/.bun/bin:/usr/local/bin:/usr/bin',
119
122
  SHELL_ONLY: 'yes',
@@ -158,7 +161,7 @@ describe('OpenCode lifecycle', () => {
158
161
  it('records an authoritative ready terminal event for external startup', async () => {
159
162
  globalThis.fetch = vi.fn(async () => ({
160
163
  ok: true,
161
- json: async () => ({ healthy: true }),
164
+ json: async () => ({ version: '2.0.15', pid: 1, urls: [], paths: { tmp: '/tmp' } }),
162
165
  }));
163
166
  const runtime = createRuntime({
164
167
  env: {
@@ -190,7 +193,7 @@ describe('OpenCode lifecycle', () => {
190
193
  it('recovers an external OPENCODE_HOST connection using its configured endpoint', async () => {
191
194
  const fetchMock = vi.fn(async () => ({
192
195
  ok: true,
193
- json: async () => ({ healthy: true }),
196
+ json: async () => ({ version: '2.0.15', pid: 1, urls: [], paths: { tmp: '/tmp' } }),
194
197
  }));
195
198
  globalThis.fetch = fetchMock;
196
199
  const runtime = createRuntime({}, {
@@ -206,7 +209,7 @@ describe('OpenCode lifecycle', () => {
206
209
  await runtime.restartOpenCode();
207
210
 
208
211
  expect(fetchMock).toHaveBeenCalledWith(
209
- 'http://seamus:4095/global/health',
212
+ 'http://seamus:4095/api/info',
210
213
  expect.objectContaining({ method: 'GET' }),
211
214
  );
212
215
  expect(runtime.testState.openCodePort).toBe(4095);
@@ -237,10 +240,37 @@ describe('OpenCode lifecycle', () => {
237
240
  expect(runtime.testState.openCodeBaseUrl).toBe('http://seamus:4095');
238
241
  });
239
242
 
243
+ it('attaches to an OPENCODE_HOST running OpenCode v1 instead of starting a managed server', async () => {
244
+ const requested = [];
245
+ globalThis.fetch = vi.fn(async (url) => {
246
+ const href = String(url);
247
+ requested.push(href);
248
+ if (href.endsWith('/global/health')) return Response.json({ healthy: true, version: '1.18.32' });
249
+ return new Response('<html>OpenCode</html>', { headers: { 'content-type': 'text/html' } });
250
+ });
251
+ const runtime = createRuntime({
252
+ reapManagedOrphanedProcesses: vi.fn(async () => ({ reaped: 0 })),
253
+ }, {}, {
254
+ ENV_CONFIGURED_OPENCODE_PORT: null,
255
+ ENV_CONFIGURED_OPENCODE_HOST: { origin: 'http://seamus:4095', port: 4095 },
256
+ ENV_EFFECTIVE_PORT: 4095,
257
+ });
258
+
259
+ await runtime.bootstrapOpenCodeAtStartup();
260
+
261
+ expect(spawnMock).not.toHaveBeenCalled();
262
+ expect(requested).toContain('http://seamus:4095/global/health');
263
+ expect(runtime.testState.isExternalOpenCode).toBe(true);
264
+ expect(runtime.testState.isOpenCodeReady).toBe(false);
265
+ expect(runtime.testState.openCodeBaseUrl).toBe('http://seamus:4095');
266
+ expect(runtime.testState.openCodePort).toBe(4095);
267
+ expect(runtime.testState.lastOpenCodeError).toContain('1.18.32');
268
+ });
269
+
240
270
  it('warms recently used directories after a successful bootstrap', async () => {
241
271
  const fetchMock = vi.fn(async () => ({
242
272
  ok: true,
243
- json: async () => ({ healthy: true }),
273
+ json: async () => ({ version: '2.0.15', pid: 1, urls: [], paths: { tmp: '/tmp' } }),
244
274
  }));
245
275
  globalThis.fetch = fetchMock;
246
276
  const runtime = createRuntime({
@@ -260,10 +290,10 @@ describe('OpenCode lifecycle', () => {
260
290
 
261
291
  const warmupUrls = fetchMock.mock.calls
262
292
  .map(([url]) => String(url))
263
- .filter((url) => url.includes('/session/status'));
293
+ .filter((url) => url.includes('/api/session?'));
264
294
  expect(warmupUrls).toEqual([
265
- 'http://127.0.0.1:45678/session/status?directory=%2Ftmp%2Fworktree-a',
266
- 'http://127.0.0.1:45678/session/status?directory=%2Ftmp%2Fproject-b',
295
+ 'http://127.0.0.1:45678/api/session?directory=%2Ftmp%2Fworktree-a&limit=1',
296
+ 'http://127.0.0.1:45678/api/session?directory=%2Ftmp%2Fproject-b&limit=1',
267
297
  ]);
268
298
  });
269
299
 
@@ -876,6 +906,28 @@ describe('OpenCode lifecycle', () => {
876
906
  expect(spawnMock).toHaveBeenCalledTimes(2);
877
907
  await server.close();
878
908
  });
909
+
910
+ it('tops up the v1 session migration before spawning managed OpenCode', async () => {
911
+ const calls = [];
912
+ const topUpV1SessionMigration = vi.fn(() => {
913
+ calls.push('top-up');
914
+ return { status: 'scheduled', missing: 3, revisited: 0 };
915
+ });
916
+ spawnMock.mockImplementation(() => {
917
+ calls.push('spawn');
918
+ const child = createMockChild();
919
+ queueMicrotask(() => child.stdout.emit('data', 'opencode server listening on http://127.0.0.1:45678\n'));
920
+ return child;
921
+ });
922
+ globalThis.fetch = vi.fn(async () => ({ ok: false }));
923
+
924
+ const runtime = createRuntime({ topUpV1SessionMigration });
925
+ await runtime.startOpenCode();
926
+
927
+ expect(topUpV1SessionMigration).toHaveBeenCalledTimes(1);
928
+ expect(calls).toEqual(['top-up', 'spawn']);
929
+ });
930
+
879
931
  });
880
932
 
881
933
  describe('killProcessOnPort on Windows', () => {
@@ -944,3 +996,50 @@ describe('killProcessOnPort on Windows', () => {
944
996
  expect(spawnSyncMock).not.toHaveBeenCalledWith('taskkill', expect.anything(), expect.anything());
945
997
  });
946
998
  });
999
+
1000
+ it('shares the managed CLI preflight with desktop while startup is pending', async () => {
1001
+ let finish;
1002
+ let entered;
1003
+ const checking = new Promise(resolve => { entered = resolve; });
1004
+ const check = new Promise(resolve => { finish = resolve; });
1005
+ let checks = 0;
1006
+ const runtime = createRuntime({
1007
+ checkOpenCodeBinary: () => { checks += 1; entered(); return check; },
1008
+ ensureOpencodeCliEnv: () => '/tmp/opencode',
1009
+ });
1010
+ spawnMock.mockImplementation(() => {
1011
+ const child = createMockChild();
1012
+ queueMicrotask(() => child.stdout.emit('data', 'opencode server listening on http://127.0.0.1:45678\n'));
1013
+ return child;
1014
+ });
1015
+ expect(await runtime.getManagedOpenCodePreflight()).toBe(false);
1016
+ const starting = runtime.startOpenCode();
1017
+ await checking;
1018
+ const desktopVerdict = runtime.getManagedOpenCodePreflight();
1019
+ expect(runtime.testState.isOpenCodeReady).toBe(false);
1020
+ finish('2.0.15');
1021
+ expect(await desktopVerdict).toBe(true);
1022
+ expect(checks).toBe(1);
1023
+ const server = await starting;
1024
+ try {
1025
+ expect(await runtime.getManagedOpenCodePreflight()).toBe(true);
1026
+ runtime.testState.isExternalOpenCode = true;
1027
+ expect(await runtime.getManagedOpenCodePreflight()).toBe(false);
1028
+ runtime.testState.isExternalOpenCode = false;
1029
+ runtime.testState.isShuttingDown = true;
1030
+ expect(await runtime.getManagedOpenCodePreflight()).toBe(false);
1031
+ } finally {
1032
+ await server.close();
1033
+ }
1034
+ });
1035
+
1036
+ it('a rejected CLI preflight never permits desktop bootstrap', async () => {
1037
+ const runtime = createRuntime({
1038
+ checkOpenCodeBinary: async () => {
1039
+ throw Object.assign(new Error('Unsupported CLI'), { code: 'OPENCODE_BINARY_INVALID' });
1040
+ },
1041
+ });
1042
+ await expect(runtime.startOpenCode()).rejects.toThrow('Unsupported CLI');
1043
+ expect(await runtime.getManagedOpenCodePreflight()).toBe(false);
1044
+ expect(spawnMock).not.toHaveBeenCalled();
1045
+ });
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Handoff of a login-shell environment snapshot from an embedding host.
3
+ *
4
+ * The server snapshots the user's login shell (`$SHELL -lic 'env -0'`) at
5
+ * import time to learn the PATH a Finder- or Dock-launched process never
6
+ * inherits. Desktop already runs the same probe asynchronously while its
7
+ * window comes up; running it again here would block the Electron main
8
+ * thread for as long as the user's shell startup files take, a second time.
9
+ * A host that has a snapshot hands it over before importing the server, and
10
+ * the server uses it instead of probing. `null` means the host probed and got
11
+ * nothing: the server does not retry, because that retry would be
12
+ * synchronous and bounded only by the probe timeout.
13
+ *
14
+ * Kept in this module rather than in the environment on purpose: the
15
+ * snapshot is the user's full shell environment, secrets included, and
16
+ * process.env is inherited by every child the server spawns.
17
+ */
18
+
19
+ let provided;
20
+
21
+ // `snapshot` is the parsed `env -0` map, or null when the host's probe failed.
22
+ export const provideLoginShellEnvSnapshot = (snapshot) => {
23
+ provided = snapshot ? { ...snapshot } : null;
24
+ };
25
+
26
+ // `undefined` when no host provided one, so the server probes itself.
27
+ export const providedLoginShellEnvSnapshot = () => provided;
@@ -0,0 +1,131 @@
1
+ import { appendManagedPlugin } from './managed-plugin-config.js';
2
+
3
+ export const MANAGED_CONFIG_FILE_NAME = 'opencode.managed.json';
4
+
5
+ /**
6
+ * Built-in OpenCode plugins OpenChamber switches off for its managed child.
7
+ *
8
+ * `opencode.browser` only works when OpenCode's own desktop app attaches a
9
+ * browser to the session; OpenChamber does not implement that protocol, so its
10
+ * tools always fail with `browser.disconnected` and agents conclude browsing is
11
+ * unavailable instead of using `openchamber_web`. A project config that lists
12
+ * `opencode.browser` still re-enables it, because that layer sits above ours.
13
+ */
14
+ const DISABLED_BUILTIN_PLUGINS = ['-opencode.browser'];
15
+
16
+ /**
17
+ * The managed OpenCode config layer.
18
+ *
19
+ * OpenCode 2 watches every config source it reads, including the file named by
20
+ * the `OPENCODE_CONFIG` environment variable, and reloads its plugin list when
21
+ * that file changes. Writing OpenChamber's own plugin entries into a file we
22
+ * own therefore makes toggling a managed tool take effect in the running
23
+ * process — where `OPENCODE_CONFIG_CONTENT` (an environment variable) could
24
+ * only ever change across a restart.
25
+ *
26
+ * The file is OpenChamber-owned and holds nothing but `plugins`: the built-in
27
+ * plugins OpenChamber disables, then its own plugin directories. It sits above
28
+ * the user's global `opencode.json` and below their project config, so it never
29
+ * shadows a project-level choice.
30
+ *
31
+ * When the user's own environment already sets `OPENCODE_CONFIG`, that file is
32
+ * theirs: OpenChamber does not hijack it and falls back to merging its plugins
33
+ * into `OPENCODE_CONFIG_CONTENT`, which keeps the old restart requirement for
34
+ * managed-tool toggles.
35
+ *
36
+ * @param {object} dependencies
37
+ * @param {typeof import('node:fs/promises')} dependencies.fsPromises
38
+ * @param {typeof import('node:path')} dependencies.path
39
+ * @param {string} dependencies.dataDir OpenChamber data directory
40
+ * @param {NodeJS.ProcessEnv} [dependencies.env] environment the managed child inherits
41
+ * @param {object|null} [dependencies.agentToolRuntime]
42
+ * @param {() => Promise<object|null>} dependencies.readSettings
43
+ * @param {() => boolean} dependencies.isAgentMemoryAvailable
44
+ */
45
+ export const createManagedConfigRuntime = ({
46
+ fsPromises,
47
+ path,
48
+ dataDir,
49
+ env = process.env,
50
+ agentToolRuntime = null,
51
+ readSettings,
52
+ isAgentMemoryAvailable,
53
+ }) => {
54
+ const filePath = path.join(dataDir, MANAGED_CONFIG_FILE_NAME);
55
+
56
+ /** The user owns `OPENCODE_CONFIG` when their environment already set it. */
57
+ const ownsConfigFile = () => (env.OPENCODE_CONFIG ?? '').trim().length === 0;
58
+
59
+ const writeConfigFile = async (pluginDirectories) => {
60
+ await fsPromises.mkdir(dataDir, { recursive: true });
61
+ const text = `${JSON.stringify({ plugins: [...DISABLED_BUILTIN_PLUGINS, ...pluginDirectories] }, null, 2)}\n`;
62
+ // Temp + rename: OpenCode reacts to the write immediately, and a partial
63
+ // read would make it drop every managed plugin until the next change.
64
+ const tmp = `${filePath}.tmp-${process.pid}-${Date.now()}`;
65
+ try {
66
+ await fsPromises.writeFile(tmp, text, { encoding: 'utf8', mode: 0o600 });
67
+ await fsPromises.rename(tmp, filePath);
68
+ } catch (error) {
69
+ await fsPromises.rm(tmp, { force: true }).catch(() => {});
70
+ throw error;
71
+ }
72
+ };
73
+
74
+ /**
75
+ * Materialize the plugins the current settings ask for and return their
76
+ * directories in load order. Directories exist on disk before the config
77
+ * file names them.
78
+ */
79
+ const materializeEnabledPlugins = async () => {
80
+ const settings = await Promise.resolve(readSettings()).catch(() => null);
81
+ const includeControl = settings?.agentControlToolEnabled !== false;
82
+ const includeWeb = settings?.agentWebToolEnabled !== false;
83
+ const includeMemory = isAgentMemoryAvailable() && settings?.agentMemoryToolEnabled === true;
84
+ const includeNotify = settings?.agentNotifyToolEnabled === true;
85
+
86
+ const directories = [];
87
+ if (agentToolRuntime && (includeControl || includeWeb || includeMemory || includeNotify)) {
88
+ directories.push(await agentToolRuntime.materializePlugin({ includeControl, includeWeb, includeMemory, includeNotify }));
89
+ }
90
+ return directories;
91
+ };
92
+
93
+ /**
94
+ * Environment for a managed OpenCode child: the callback URL and per-child
95
+ * token are always present, so a tool enabled later in the session can still
96
+ * call back without a restart.
97
+ */
98
+ const buildManagedChildEnv = async () => {
99
+ const directories = await materializeEnabledPlugins();
100
+ const childEnv = agentToolRuntime ? agentToolRuntime.createChildEnv() : {};
101
+ if (ownsConfigFile()) {
102
+ await writeConfigFile(directories);
103
+ return { ...childEnv, OPENCODE_CONFIG: filePath };
104
+ }
105
+ let content = env.OPENCODE_CONFIG_CONTENT;
106
+ for (const directory of [...DISABLED_BUILTIN_PLUGINS, ...directories]) {
107
+ content = appendManagedPlugin(content, directory, 'managed plugin');
108
+ }
109
+ return { ...childEnv, OPENCODE_CONFIG_CONTENT: content };
110
+ };
111
+
112
+ /**
113
+ * Rewrite the managed config file after a managed-plugin setting changed, so
114
+ * the running OpenCode picks the new plugin list up. A no-op when the user
115
+ * owns `OPENCODE_CONFIG`; those installs still need a restart.
116
+ *
117
+ * @returns {Promise<{updated: boolean, reason?: string}>}
118
+ */
119
+ const refreshManagedConfigFile = async () => {
120
+ if (!ownsConfigFile()) return { updated: false, reason: 'external-config' };
121
+ await writeConfigFile(await materializeEnabledPlugins());
122
+ return { updated: true };
123
+ };
124
+
125
+ return {
126
+ filePath,
127
+ ownsConfigFile,
128
+ buildManagedChildEnv,
129
+ refreshManagedConfigFile,
130
+ };
131
+ };