@openchamber/web 2.0.2 → 2.0.4

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 (257) hide show
  1. package/bin/lib/DOCUMENTATION.md +1 -1
  2. package/bin/lib/commands-connect-url.js +6 -5
  3. package/bin/lib/commands-tunnel.js +24 -5
  4. package/dist/assets/{CodeMirrorCommentWidgets-CmKmyb9T.js → CodeMirrorCommentWidgets-C_zL-eri.js} +1 -1
  5. package/dist/assets/{DiffView-8-PFpZ2p.js → DiffView-BeN2_YYF.js} +3 -3
  6. package/dist/assets/FilesView-CN34wm_N.js +17 -0
  7. package/dist/assets/{GitView-DNUSu00w.js → GitView-DLDazOo1.js} +4 -4
  8. package/dist/assets/{GuestAttachDialog-Cv6QzjHC.js → GuestAttachDialog-C0xe_Lyy.js} +1 -1
  9. package/dist/assets/{GuestSurfacePane-Bt3jB_Ye.js → GuestSurfacePane-BdaurnDr.js} +1 -1
  10. package/dist/assets/{JsonTreeView-BlyHTRhM.js → JsonTreeView-B1Xq-k2t.js} +1 -1
  11. package/dist/assets/LinearIssuesView-BryoAHow.js +1 -0
  12. package/dist/assets/{MarkdownImageGallery-2UXJF-5B.js → MarkdownImageGallery-DfuEoaGq.js} +1 -1
  13. package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +12 -0
  14. package/dist/assets/OnboardingScreen-C22bGmnP.js +1 -0
  15. package/dist/assets/{PatchDiff-ByvnbG5T.js → PatchDiff-0xd6UeFB.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-BXieg0mH.js → PierreDiffViewer-BC950e3F.js} +3 -3
  17. package/dist/assets/PlanView-B7Xgihqk.js +5 -0
  18. package/dist/assets/PluginPane-2C71F8uF.js +3 -0
  19. package/dist/assets/SettingsView-m_zoFiaT.js +30 -0
  20. package/dist/assets/{SettingsWindow-BIz224xs.js → SettingsWindow-CofS020b.js} +1 -1
  21. package/dist/assets/{SubmoduleDiffSummary-CXKmlps9.js → SubmoduleDiffSummary-BSA9gnIO.js} +1 -1
  22. package/dist/assets/{ToolOutputDialog-BsgAK8xu.js → ToolOutputDialog-DprkVKcj.js} +7 -7
  23. package/dist/assets/{ToolPartDiffPreview-vdPObXOf.js → ToolPartDiffPreview-Dq0go_fX.js} +2 -2
  24. package/dist/assets/{VirtualizedFileDiff-BkFNKWS5.js → VirtualizedFileDiff-Kp8hKJdT.js} +1 -1
  25. package/dist/assets/WalkthroughView-DGnTzqIU.js +4 -0
  26. package/dist/assets/{appThemeRegistry-aHUNHoqP.js → appThemeRegistry-BdEHBA4s.js} +1 -1
  27. package/dist/assets/{commitAndPush-Bon9r94r.js → commitAndPush-LwtVa2Oc.js} +1 -1
  28. package/dist/assets/{computeVirtualFileMetrics-DKqr_1AQ.js → computeVirtualFileMetrics-6V1xNpO9.js} +2 -2
  29. package/dist/assets/de-DlgBHUAI.js +10 -0
  30. package/dist/assets/es-BC8G41U8.js +16 -0
  31. package/dist/assets/fr-I0z3vVjy.js +14 -0
  32. package/dist/assets/index-CgR5rJq_.js +41 -0
  33. package/dist/assets/{index-DpFttslC.js → index-CmNPYddV.js} +1 -1
  34. package/dist/assets/index-adyy_sEk.css +1 -0
  35. package/dist/assets/{isDiffPlainText-kzAgpIgi.js → isDiffPlainText-1bXcWCrw.js} +1 -1
  36. package/dist/assets/{isFilePlainText-Uj6y-jzz.js → isFilePlainText-CBAppvy1.js} +1 -1
  37. package/dist/assets/ja-BIElEsY8.js +16 -0
  38. package/dist/assets/ko-DRnnHetA.js +16 -0
  39. package/dist/assets/{main-CbfMxn-I.js → main-CzjTMTfW.js} +2 -2
  40. package/dist/assets/main-DVX34beR.js +886 -0
  41. package/dist/assets/markdownCore-Cxbkn5NR.js +7 -0
  42. package/dist/assets/{miniChat-CiAKBC10.js → miniChat-CP68IL8Q.js} +2 -2
  43. package/dist/assets/{mobile-CsT4sJwC.js → mobile-BrlBrNfZ.js} +2 -2
  44. package/dist/assets/nl-DzUV-kwp.js +16 -0
  45. package/dist/assets/{patchFileDiff-DeaE08W0.js → patchFileDiff-pqRSHLHI.js} +2 -2
  46. package/dist/assets/pl-Bb-cb7k7.js +16 -0
  47. package/dist/assets/pt-BR-CyIWrTcE.js +16 -0
  48. package/dist/assets/renderElectronMiniChatApp-DKIilR7N.js +2 -0
  49. package/dist/assets/renderMobileApp-B0z6-x58.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +52 -0
  51. package/dist/assets/{scheduledTasksApi-BZCNJ588.js → scheduledTasksApi-BuzWT445.js} +1 -1
  52. package/dist/assets/{shikiHighlight-BSUEa3yF.js → shikiHighlight-BWGrY5YU.js} +1 -1
  53. package/dist/assets/{textMateThemeFromAppTheme-CsATFZIV.js → textMateThemeFromAppTheme-BSUFChBY.js} +1 -1
  54. package/dist/assets/tr-DXEDSoYO.js +7 -0
  55. package/dist/assets/uk-C8hN--q_.js +16 -0
  56. package/dist/assets/useAppFontEffects-Dsl_sLrj.js +7366 -0
  57. package/dist/assets/useInlineCommentController-d5vntsQ_.js +2 -0
  58. package/dist/assets/{useRootScrollLock-Cp1eFoM2.js → useRootScrollLock-2rd5Y6gR.js} +2 -2
  59. package/dist/assets/{vendor-base-ui-CsXYnR5c.js → vendor-base-ui-DnNniUWp.js} +1 -1
  60. package/dist/assets/{vendor-codemirror-language-data-BwwommM0.js → vendor-codemirror-language-data-B1EetJur.js} +2 -2
  61. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
  62. package/dist/assets/{vendor-tanstack-react-virtual-ClYN8CzB.js → vendor-tanstack-react-virtual--0sBrLRh.js} +1 -1
  63. package/dist/assets/{vendor-tanstack-virtual-core-BewVQryB.js → vendor-tanstack-virtual-core-BoA4iGMw.js} +1 -1
  64. package/dist/assets/{vendor-zod-BSoePkpP.js → vendor-zod-CxRSdNoV.js} +4 -4
  65. package/dist/assets/{web-components-D3Yjr4Zx.js → web-components-ngpHPEDU.js} +1 -1
  66. package/dist/assets/zh-CN-CtzXdjMZ.js +16 -0
  67. package/dist/assets/zh-TW-Ds0CADSz.js +16 -0
  68. package/dist/index.html +5 -5
  69. package/dist/mini-chat.html +5 -5
  70. package/dist/mobile.html +5 -5
  71. package/package.json +5 -5
  72. package/server/index.js +82 -4
  73. package/server/lib/agent-tool/DOCUMENTATION.md +8 -1
  74. package/server/lib/agent-tool/runtime.js +13 -4
  75. package/server/lib/agent-tool/runtime.test.js +15 -0
  76. package/server/lib/context-obligatory/DOCUMENTATION.md +10 -7
  77. package/server/lib/context-obligatory/runtime.js +2 -1
  78. package/server/lib/context-obligatory/runtime.test.js +76 -30
  79. package/server/lib/dictation/DOCUMENTATION.md +4 -1
  80. package/server/lib/dictation/openai-compatible-session.js +7 -0
  81. package/server/lib/enterprise-mode.d.ts +30 -0
  82. package/server/lib/enterprise-mode.js +253 -0
  83. package/server/lib/enterprise-mode.test.js +247 -0
  84. package/server/lib/event-stream/translate-v2.js +6 -0
  85. package/server/lib/event-stream/translate-v2.test.js +6 -0
  86. package/server/lib/git/DOCUMENTATION.md +2 -1
  87. package/server/lib/git/routes.js +44 -1
  88. package/server/lib/git/routes.test.js +98 -1
  89. package/server/lib/git/service.js +146 -11
  90. package/server/lib/git/service.test.js +195 -0
  91. package/server/lib/github/routes.js +9 -19
  92. package/server/lib/github/routes.test.js +112 -0
  93. package/server/lib/guests/DOCUMENTATION.md +4 -2
  94. package/server/lib/guests/background.test.js +1 -1
  95. package/server/lib/guests/catalog.js +56 -2
  96. package/server/lib/guests/catalog.test.js +24 -1
  97. package/server/lib/guests/clone-network.test.js +52 -0
  98. package/server/lib/guests/clone.js +30 -4
  99. package/server/lib/guests/enterprise.js +68 -0
  100. package/server/lib/guests/enterprise.test.js +106 -0
  101. package/server/lib/guests/grant-scope.js +8 -2
  102. package/server/lib/guests/grant-scope.test.js +9 -0
  103. package/server/lib/guests/html-styles.js +16 -2
  104. package/server/lib/guests/html-styles.test.js +53 -4
  105. package/server/lib/guests/install.js +10 -0
  106. package/server/lib/guests/persist.js +1 -0
  107. package/server/lib/guests/routes.js +40 -5
  108. package/server/lib/guests/updates.js +9 -2
  109. package/server/lib/notifications/DOCUMENTATION.md +1 -1
  110. package/server/lib/notifications/runtime.js +22 -8
  111. package/server/lib/notifications/trigger-runtime.test.js +45 -0
  112. package/server/lib/openchamber-sessions/session-metadata-store.js +27 -0
  113. package/server/lib/openchamber-sessions/session-metadata-store.test.js +18 -0
  114. package/server/lib/opencode/DOCUMENTATION.md +13 -9
  115. package/server/lib/opencode/auth-state-runtime.js +2 -2
  116. package/server/lib/opencode/config-paths.test.js +1 -0
  117. package/server/lib/opencode/env-runtime.js +26 -3
  118. package/server/lib/opencode/env-runtime.test.js +57 -0
  119. package/server/lib/opencode/feature-routes-runtime.js +2 -0
  120. package/server/lib/opencode/hmr-state-runtime.js +4 -3
  121. package/server/lib/opencode/lifecycle.js +10 -5
  122. package/server/lib/opencode/lifecycle.test.js +6 -2
  123. package/server/lib/opencode/managed-config-file.js +2 -1
  124. package/server/lib/opencode/managed-config-file.test.js +18 -0
  125. package/server/lib/opencode/npm-registry-config.d.ts +1 -0
  126. package/server/lib/opencode/npm-registry-config.js +123 -0
  127. package/server/lib/opencode/npm-registry-config.test.js +167 -0
  128. package/server/lib/opencode/npm-registry.js +5 -6
  129. package/server/lib/opencode/npm-registry.test.js +30 -0
  130. package/server/lib/opencode/openchamber-routes.js +8 -0
  131. package/server/lib/opencode/project-icon-routes.js +2 -2
  132. package/server/lib/opencode/project-icon-routes.test.js +44 -0
  133. package/server/lib/opencode/provider-source-route.test.js +32 -0
  134. package/server/lib/opencode/routes.js +17 -2
  135. package/server/lib/opencode/settings-helpers.js +26 -3
  136. package/server/lib/opencode/settings-helpers.test.js +12 -5
  137. package/server/lib/opencode/settings-registry.json +35 -1
  138. package/server/lib/opencode/settings-runtime.js +1 -0
  139. package/server/lib/opencode/shutdown-runtime.js +2 -0
  140. package/server/lib/opencode/static-routes-runtime.js +9 -1
  141. package/server/lib/opencode/static-routes-runtime.test.js +58 -1
  142. package/server/lib/package-manager.js +4 -1
  143. package/server/lib/package-manager.test.js +24 -0
  144. package/server/lib/permission-auto-accept/DOCUMENTATION.md +23 -15
  145. package/server/lib/permission-auto-accept/modes.js +26 -0
  146. package/server/lib/permission-auto-accept/runtime.js +146 -40
  147. package/server/lib/permission-auto-accept/runtime.test.js +93 -9
  148. package/server/lib/quota/DOCUMENTATION.md +6 -0
  149. package/server/lib/quota/providers/zhipuai-coding-plan.js +74 -30
  150. package/server/lib/quota/providers/zhipuai-coding-plan.test.js +124 -0
  151. package/server/lib/relay/DOCUMENTATION.md +1 -1
  152. package/server/lib/relay/service.js +32 -12
  153. package/server/lib/relay/service.test.js +30 -0
  154. package/server/lib/routing/DOCUMENTATION.md +150 -41
  155. package/server/lib/routing/classifier.js +156 -0
  156. package/server/lib/routing/defaults.js +27 -0
  157. package/server/lib/routing/jev.js +5 -17
  158. package/server/lib/routing/routes.http.test.js +9 -0
  159. package/server/lib/routing/routes.js +27 -1
  160. package/server/lib/routing/runtime.js +199 -33
  161. package/server/lib/routing/runtime.test.js +299 -15
  162. package/server/lib/routing/store.js +57 -0
  163. package/server/lib/routing/store.test.js +37 -0
  164. package/server/lib/session-assist/DOCUMENTATION.md +17 -7
  165. package/server/lib/session-assist/context.js +42 -2
  166. package/server/lib/session-assist/context.test.js +38 -1
  167. package/server/lib/session-assist/runtime.js +57 -13
  168. package/server/lib/session-assist/runtime.test.js +45 -0
  169. package/server/lib/session-goal/DOCUMENTATION.md +47 -22
  170. package/server/lib/session-goal/audit.js +112 -0
  171. package/server/lib/session-goal/audit.test.js +58 -0
  172. package/server/lib/session-goal/runtime.js +113 -134
  173. package/server/lib/session-goal/runtime.test.js +146 -13
  174. package/server/lib/session-lineage.js +52 -0
  175. package/server/lib/session-lineage.test.js +45 -0
  176. package/server/lib/session-work/DOCUMENTATION.md +108 -0
  177. package/server/lib/session-work/questions.js +126 -0
  178. package/server/lib/session-work/runtime.js +278 -0
  179. package/server/lib/session-work/runtime.test.js +255 -0
  180. package/server/lib/session-work/state.js +48 -0
  181. package/server/lib/session-work/state.test.js +34 -0
  182. package/server/lib/small-model/DOCUMENTATION.md +14 -7
  183. package/server/lib/small-model/client.js +7 -4
  184. package/server/lib/small-model/index.js +11 -21
  185. package/server/lib/small-model/index.test.js +13 -26
  186. package/server/lib/spaces/DOCUMENTATION.md +79 -25
  187. package/server/lib/spaces/gatekeeper-channel.js +63 -11
  188. package/server/lib/spaces/gatekeeper-channel.test.js +34 -4
  189. package/server/lib/spaces/gatekeeper-program.cjs +64 -13
  190. package/server/lib/spaces/gatekeeper-program.test.js +115 -3
  191. package/server/lib/spaces/host.js +58 -13
  192. package/server/lib/spaces/host.test.js +34 -1
  193. package/server/lib/spaces/idle-stop.js +98 -0
  194. package/server/lib/spaces/idle-stop.test.js +130 -0
  195. package/server/lib/spaces/journey.js +427 -17
  196. package/server/lib/spaces/journey.test.js +592 -5
  197. package/server/lib/spaces/layout.js +27 -6
  198. package/server/lib/spaces/manager.test.js +1 -1
  199. package/server/lib/spaces/places/contract-suite.js +4 -2
  200. package/server/lib/spaces/places/docker-live-support.js +27 -4
  201. package/server/lib/spaces/places/docker.js +32 -5
  202. package/server/lib/spaces/places/docker.test.js +38 -8
  203. package/server/lib/spaces/places/escape-suite.js +32 -0
  204. package/server/lib/spaces/places/fake-docker.js +3 -1
  205. package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
  206. package/server/lib/spaces/places/memory-place.js +3 -3
  207. package/server/lib/spaces/places/sessions.docker.live.test.js +4 -2
  208. package/server/lib/spaces/routes.js +49 -1
  209. package/server/lib/spaces/routes.test.js +31 -3
  210. package/server/lib/spaces/space-opencode.js +52 -0
  211. package/server/lib/spaces/space-opencode.test.js +41 -0
  212. package/server/lib/spaces/space-records.js +90 -2
  213. package/server/lib/spaces/space-records.test.js +58 -1
  214. package/server/lib/spaces/space-server.js +13 -1
  215. package/server/lib/spaces/space-server.test.js +13 -0
  216. package/server/lib/spaces/space-setup.js +173 -0
  217. package/server/lib/spaces/space-setup.test.js +174 -0
  218. package/server/lib/tts/DOCUMENTATION.md +3 -0
  219. package/server/lib/tts/base-url.js +8 -0
  220. package/server/lib/tts/routes.js +13 -1
  221. package/server/lib/tts/routes.test.js +26 -0
  222. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  223. package/server/lib/tunnels/routes.js +14 -0
  224. package/server/lib/tunnels/routes.test.js +26 -0
  225. package/server/lib/walkthrough/index.js +11 -7
  226. package/server/lib/walkthrough/jobs.test.js +8 -0
  227. package/server/lib/walkthrough/languages.js +1 -0
  228. package/server/lib/walkthrough/routes.js +7 -1
  229. package/dist/assets/FilesView-0Ie20mEk.js +0 -17
  230. package/dist/assets/LinearIssuesView-CSl2MUfA.js +0 -1
  231. package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +0 -12
  232. package/dist/assets/OnboardingScreen-CIdXJpfc.js +0 -1
  233. package/dist/assets/PlanView-DEIi3Q7M.js +0 -5
  234. package/dist/assets/PluginPane-BEPUWVho.js +0 -3
  235. package/dist/assets/SettingsView-CiNh-RbW.js +0 -30
  236. package/dist/assets/WalkthroughView-6oE-MuDL.js +0 -4
  237. package/dist/assets/de-CgAJ51z7.js +0 -10
  238. package/dist/assets/es-zGi_ravM.js +0 -16
  239. package/dist/assets/fr-CPfogrWx.js +0 -14
  240. package/dist/assets/index-CHfphYL3.js +0 -41
  241. package/dist/assets/index-DvMJ3w6V.css +0 -1
  242. package/dist/assets/ja-DMk6wd-U.js +0 -16
  243. package/dist/assets/ko-BFpzJ8jc.js +0 -16
  244. package/dist/assets/main-anyZFMIs.js +0 -896
  245. package/dist/assets/markdownCore-CmM47cAE.js +0 -7
  246. package/dist/assets/pl-VdRPcZrB.js +0 -16
  247. package/dist/assets/pt-BR-BRys_lOW.js +0 -16
  248. package/dist/assets/renderElectronMiniChatApp-C5677jy0.js +0 -2
  249. package/dist/assets/renderMobileApp-D4dBBAqQ.js +0 -25
  250. package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +0 -27
  251. package/dist/assets/tr-CA9ckNnm.js +0 -7
  252. package/dist/assets/uk-byjR-y8D.js +0 -16
  253. package/dist/assets/useAppFontEffects-BWQZ5DeI.js +0 -7341
  254. package/dist/assets/useInlineCommentController-DlFyVfBu.js +0 -2
  255. package/dist/assets/vendor-opencode-client-DYdsLbCM.js +0 -12
  256. package/dist/assets/zh-CN-DRabgxdG.js +0 -16
  257. package/dist/assets/zh-TW-rbY5c9UK.js +0 -16
@@ -11,7 +11,7 @@ This module provides OpenCode server integration utilities for the web server ru
11
11
  - `packages/web/server/lib/opencode/cli-entry-runtime.js`: CLI entrypoint runtime that detects direct execution, parses CLI options, and starts server bootstrap.
12
12
  - `packages/web/server/lib/opencode/routes.js`: OpenCode/provider settings and auth-related route registration.
13
13
  - `packages/web/server/lib/opencode/v1-migration-topup.js`: re-arms OpenCode's own V1 -> V2 session import for V1 sessions changed by 1.x after the last completed import; runs only before a managed spawn. See "v1-migration-topup.js" below.
14
- - `packages/web/server/lib/opencode/lifecycle.js`: OpenCode process lifecycle runtime (startup, restart, readiness, health monitoring). After readiness it warms the most recently used directories (`getWarmupDirectories` dep, sequential and best-effort) because OpenCode initializes each directory lazily on first request and that cost would otherwise be paid by the user's first interactive session open.
14
+ - `packages/web/server/lib/opencode/lifecycle.js`: OpenCode process lifecycle runtime (startup, restart, readiness, health monitoring). After readiness it warms the last-used directory only (first entry of the `getWarmupDirectories` dep, best-effort) because OpenCode initializes each directory lazily on first request and that cost would otherwise be paid by the user's first interactive session open. It warms no other projects: on OpenCode 2 the first directory-scoped read boots that location's whole MCP fleet.
15
15
  - `packages/web/server/lib/opencode/provider-env-aliases.js`: mirrors known provider credential env aliases into the managed OpenCode process environment (for example `GEMINI_API_KEY` → `GOOGLE_GENERATIVE_AI_API_KEY`) so OpenCode connection detection and the upstream AI SDK agree on the same key names. Canonical implementation shared by web lifecycle and the VS Code managed spawn path (`packages/vscode/src/provider-env-aliases.ts` re-exports this module).
16
16
  - `packages/web/server/lib/opencode/env-runtime.js`: OpenCode CLI/binary resolution and shell environment runtime.
17
17
  - `packages/web/server/lib/opencode/env-config.js`: OpenCode-related environment variable parsing and validation (host/port/hostname).
@@ -26,6 +26,7 @@ This module provides OpenCode server integration utilities for the web server ru
26
26
  - `packages/web/server/lib/opencode/cli-options.js`: CLI/environment option parsing for server startup arguments.
27
27
  - `packages/web/server/lib/opencode/core-routes.js`: server status/system routes, auth/access guard routes, and settings utility route registration.
28
28
  - `packages/web/server/lib/opencode/shutdown-runtime.js`: graceful shutdown orchestration runtime for watcher/session/guest-services/terminal/process/server teardown.
29
+ - `packages/web/server/lib/opencode/npm-registry-config.js`: resolves npm package metadata requests from inherited npm registry settings or the user's `.npmrc`, including scoped registries and matching bearer/basic HTTP authentication.
29
30
  - `packages/web/server/lib/opencode/server-startup-runtime.js`: server listen/startup tunnel flow and process/signal handler orchestration runtime.
30
31
  - `packages/web/server/lib/opencode/static-routes-runtime.js`: static asset/SPA fallback route registration and manifest route wiring.
31
32
  - `packages/web/server/lib/opencode/feature-routes-runtime.js`: feature route composition runtime for dynamic import-backed config/skill/provider route registration.
@@ -189,7 +190,7 @@ Hard rules, verified against v2.0.8 (the completion stamp against v2.0.16)
189
190
  ## Public exports (providers.js)
190
191
  - `getProviderSources(providerId, workingDirectory)`: Resolves which OpenCode config layers define a provider.
191
192
  - `listProviderConfigs(workingDirectory)`: Every provider a config layer defines, projected into the canonical v2 `ProviderEntity` shape, with `legacy` marking entries still stored under the v1 `provider` key.
192
- - `upsertProviderConfig(providerId, config, workingDirectory, scope?, options?)`: Validates and writes a custom provider block into the user/project/custom config layer. The payload may use the v2 spelling (`package`, `settings.baseURL`, `headers`) or the v1 spelling (`npm`, `options.baseURL`); what lands on disk is always a v2 `providers` entry with `package: "aisdk:<npm>"` and `settings.baseURL`. The adapter may be OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages. Existing provider, option, and retained-model fields not managed by the form are preserved; omitted models, headers, and env credentials remain explicit removals. A model's `variants` (reasoning levels) are replaced when the payload carries the array, cleared when it carries an empty one, and kept when the key is absent. Updating an entry still stored under the legacy `provider` key rewrites it under `providers` in the same file, dropping the fields v2 accepts but ignores; unrelated legacy siblings are untouched. Does not store API keys. Requires `config.env` or `options.hasStoredAuth` (auth already written via OpenCode `auth.set`). Edit flows must pass the provider's effective existing layer (`custom` > `project` > `user`) so updates do not create a global user override.
193
+ - `upsertProviderConfig(providerId, config, workingDirectory, scope?, options?)`: Validates and writes a custom provider block into the user/project/custom config layer. The payload may use the v2 spelling (`package`, `settings.baseURL`, `headers`) or the v1 spelling (`npm`, `options.baseURL`); what lands on disk is always a v2 `providers` entry with `package: "aisdk:<npm>"` and `settings.baseURL`. The adapter may be OpenAI Chat Completions, OpenAI Responses, or Anthropic Messages. Existing provider, option, and retained-model fields not managed by the form are preserved; omitted models, headers, and env credentials remain explicit removals. A model's `variants` (reasoning levels) are replaced when the payload carries the array, cleared when it carries an empty one, and kept when the key is absent. Updating an entry still stored under the legacy `provider` key rewrites it under `providers` in the same file, dropping the fields v2 accepts but ignores; unrelated legacy siblings are untouched. Does not store API keys. Requires `config.env` or `options.hasStoredAuth`. OpenCode 2 keeps credentials in its own store, so `PUT /api/provider` sets `hasStoredAuth` from the request's `hasCredential` (the form is about to store a key, or the edited provider keeps its credential) as well as a legacy `auth.json` entry. The key itself goes through `integration.connect.key` after this write, because OpenCode registers a custom provider's key method only once the provider is in config. Edit flows must pass the provider's effective existing layer (`custom` > `project` > `user`) so updates do not create a global user override.
193
194
  - `validateCustomProviderConfig(providerId, config, options?)`: Structural validation for custom provider payloads (id format, adapter allowlist `@ai-sdk/openai-compatible`/`@ai-sdk/openai`/`@ai-sdk/anthropic`, http(s) base URL, models, credentials via `env` or `hasStoredAuth`). Accepts both spellings and returns the normalized v2 value.
194
195
  - `removeProviderConfig(providerId, workingDirectory, scope?)`: Removes a provider block from the selected config layer.
195
196
 
@@ -222,6 +223,7 @@ Hard rules, verified against v2.0.8 (the completion stamp against v2.0.16)
222
223
  - `GET /api/provider/:providerId/source`
223
224
  - `PUT /api/provider` (create/update custom OpenAI-compatible provider config in OpenCode user/project/custom layers via `scope`; secrets stay in auth via the OpenCode auth API)
224
225
  - `DELETE /api/provider/:providerId/auth`
226
+ - Enterprise mode (`../enterprise-mode.js`): `PUT /api/provider` and the OpenCode writes that would otherwise pass the generic proxy — every `POST` under `/api/integration/:id/connect` (key, OAuth start and complete, command) and `POST /api/experimental/integration/wellknown`, matched by `isProviderConnectRequest` — answer 403 `enterprise_mode`. The VS Code extension host refuses the same requests with the same matcher. Removing, activating or renaming an existing credential still reaches OpenCode. This closes the way in through the app; OpenCode's `provider.use` policy is the real lock.
225
227
  - Owns lazy auth library loading for provider auth checks/removal.
226
228
  - Keeps route behavior independent from composition root; `index.js` now supplies dependencies only.
227
229
 
@@ -318,8 +320,11 @@ entry to the previous one's config. OpenChamber adds no automatic MCP reconnect
318
320
  loop; recovery after a failed connection is manual for both local and remote
319
321
  servers. Previously generated reconnect plugin files are inert because managed
320
322
  launch no longer registers them. User-configured plugins remain user-owned.
321
- PATH and `OPENCODE_SERVER_PASSWORD` remain lifecycle-owned and cannot
322
- be replaced by injected values. External OpenCode processes receive no
323
+ PATH, `OPENCODE_PASSWORD` and `OPENCODE_SERVER_PASSWORD` remain lifecycle-owned
324
+ and cannot be replaced by injected or inherited values; OpenCode 2 prefers
325
+ `OPENCODE_PASSWORD`, so both carry the managed password. A user-provided
326
+ password is read with the same precedence, and Basic auth always uses the
327
+ `opencode` username because OpenCode 2 accepts no other. External OpenCode processes receive no
323
328
  OpenChamber tool injection. Managed launch env strips AppImage `ARGV0` before
324
329
  spawn so zsh-backed OpenCode tools do not rewrite child argv[0] to the AppImage
325
330
  path (#2588).
@@ -361,7 +366,7 @@ ConPTY or Console Window Host behavior.
361
366
  - `createOpenCodeEnvRuntime(dependencies)`: creates runtime that owns OpenCode CLI environment and binary discovery state.
362
367
  - OpenCode CLI resolution order is persisted settings, environment overrides, bundled Desktop CLI when available, PATH, known install locations, then platform shell discovery.
363
368
  - Automatic bundled resolution under `OPENCHAMBER_RUNTIME=desktop` stays in runtime state and is returned to the managed launch function, including on OpenCode restart. It does not populate `process.env.OPENCODE_BINARY`: AppImage updater relaunch inherits that environment and would mistake the previous bundle path for an explicit override. Explicit settings/env selections and non-desktop or non-bundled resolution retain their existing environment behavior. This prevents future inheritance; it does not reinterpret overrides already inherited from older releases.
364
- - The login-shell snapshot (`$SHELL -lic 'env -0'`) is taken synchronously at import time, so it blocks whatever process embeds the server for as long as the user's shell startup files take. An embedding host that already probed the shell hands its result over before importing the server through `login-shell-env.js` (`provideLoginShellEnvSnapshot(snapshot | null)`); the runtime then uses that and never probes, `null` included. Desktop does this on macOS and Linux; on Windows the server keeps its own registry-based snapshot. The handoff is a module slot, never an environment variable: the snapshot is the user's whole shell environment and `process.env` reaches every child.
369
+ - The login-shell snapshot (`$SHELL -lic 'echo __OPENCHAMBER_ENV__; env -0'`, parsed from after the last marker line so text an rc file prints to stdout never fuses with the first variable) is taken synchronously at import time, so it blocks whatever process embeds the server for as long as the user's shell startup files take. An embedding host that already probed the shell hands its result over before importing the server through `login-shell-env.js` (`provideLoginShellEnvSnapshot(snapshot | null)`); the runtime then uses that and never probes, `null` included. Desktop does this on macOS and Linux; on Windows the server keeps its own registry-based snapshot. The handoff is a module slot, never an environment variable: the snapshot is the user's whole shell environment and `process.env` reaches every child.
365
370
  - Returned API:
366
371
  - `applyLoginShellEnvSnapshot()`
367
372
  - `getLoginShellEnvSnapshot()`
@@ -416,7 +421,7 @@ ConPTY or Console Window Host behavior.
416
421
  - `readSettingsFromDiskMigrated()`
417
422
  - `writeSettingsToDisk(settings)`
418
423
  - `persistSettings(changes)`
419
- - Persistent permission auto-accept policy is stored under `permissionAutoAccept`; execution ownership lives in `lib/permission-auto-accept/`.
424
+ - Persistent per-session permission modes are stored under `permissionAutoAccept`, and the mode for new sessions under `permissionDefaultMode`; execution ownership lives in `lib/permission-auto-accept/`.
420
425
  - Queued follow-up messages live in `<data-dir>/message-queue.json`, not in settings; execution ownership lives in `lib/message-queue/`.
421
426
  - Shared sidebar preferences are stored as validated top-level fields: `sidebarProjectDisplayMode`, `sidebarSessionGroupingMode`, `sidebarProjectSortOrder`, and `sidebarShowRecentSection`. Device-local picker selection and sticky-header state do not enter either settings file.
422
427
  - Two files (`settings-files.js`): `settings.json` holds instance facts and any legacy or unknown keys; `preferences.json` beside it holds every key the generated registry snapshot (`settings-registry.json`) marks `profile`, as `{ version: 1, fields: { key: { value, updatedAt, surfaces? } } }`. Keys the snapshot marks `perSurface` are stored per surface kind: `GET`/`PUT /api/config/settings` read the client's kind from the `surface` query parameter (`settingsSurfaceOf`; the legacy `x-openchamber-surface` header is still honoured, but a header forces a CORS preflight that cross-origin shells and older instances refuse, so clients must not send one) (`web`, `desktop`, `vscode`, `mobile`; anything else means base), `persistSettings(changes, { surface })` writes a changed per-surface key under `surfaces[surface]` and never touches its base, and `readSettingsFromDisk({ surface })` resolves that kind's value first, the base otherwise. Callers without a surface (migrations, the seed, server-side feature writers) read and write the base. `readSettingsFromDisk()` returns the merged document and seeds `preferences.json` once from an existing `settings.json` (which it leaves intact). An existing `preferences.json` that fails to parse is a failure, not an empty profile: it is never seeded or overwritten, the merged read serves the instance part, and `persistSettings` drops profile keys with a warning until the file is fixed or removed. `writeSettingsToDisk(document)` splits by scope and writes `settings.json` as the instance part plus a copy of the profile's base values (`legacySettingsDocumentOf`): a build from before the split reads only that file, so a rollback keeps the user's preferences, while current builds ignore the copy because `preferences.json` wins in the merge; device keys are dropped from writes. Modules that read one profile key off the disk on a hot path use `readMergedSettingsSync`.
@@ -937,9 +942,8 @@ under a running child.
937
942
  always in the child environment, including while every managed tool is off —
938
943
  a tool switched on later then reaches a process that can already call back.
939
944
  - `persistSettings` rewrites the file (temp + rename) whenever
940
- `agentControlToolEnabled`, `agentWebToolEnabled`, `agentMemoryToolEnabled` or
941
- `agentNotifyToolEnabled`
942
- changes. Plugin directories are written before the
945
+ `agentControlToolEnabled`, `agentWebToolEnabled`, `agentMemoryToolEnabled`,
946
+ `agentNotifyToolEnabled` or `agentToolsCodeMode` changes. Plugin directories are written before the
943
947
  file names them, and a disabled plugin is removed from the list. OpenCode
944
948
  reloads within a couple of seconds; no restart is involved.
945
949
  - Fallback: when the user's own environment already sets `OPENCODE_CONFIG`,
@@ -51,8 +51,8 @@ export const createOpenCodeAuthStateRuntime = (dependencies) => {
51
51
  return {};
52
52
  }
53
53
 
54
- const username = process.env.OPENCODE_SERVER_USERNAME?.trim() || 'opencode';
55
- const credentials = Buffer.from(`${username}:${password}`).toString('base64');
54
+ // OpenCode 2 accepts only this username; OPENCODE_SERVER_USERNAME is ignored.
55
+ const credentials = Buffer.from(`opencode:${password}`).toString('base64');
56
56
  return { Authorization: `Basic ${credentials}` };
57
57
  };
58
58
 
@@ -95,6 +95,7 @@ describe('OpenCode global config paths', () => {
95
95
  put(route, ...callbacks) { handlers.set(`PUT ${route}`, callbacks.at(-1)); },
96
96
  post() {},
97
97
  delete() {},
98
+ use() {},
98
99
  };
99
100
  routes.registerOpenCodeRoutes(app, {});
100
101
 
@@ -10,6 +10,24 @@ import { mergePathValues } from './path-utils.js';
10
10
  // hostage: a probe that overruns is abandoned and resolution falls through
11
11
  // to the next candidate. Electron's own login-shell probe uses the same bound.
12
12
  const SHELL_PROBE_TIMEOUT_MS = 5_000;
13
+ // Windows probes run synchronously on the startup path; an unbounded one (a
14
+ // PowerShell profile on a stuck OneDrive folder, `where` walking a dead
15
+ // network drive in PATH) hangs the whole process with no output.
16
+ const WINDOWS_PROBE_TIMEOUT_MS = 10_000;
17
+
18
+ // Interactive rc files may print a banner, motd or other text to stdout before
19
+ // the shell runs the probe command. That text would otherwise fuse with the
20
+ // first `env -0` entry, so a marker line is echoed right before `env -0` and
21
+ // only what follows the last marker line is parsed. Electron's probe does the
22
+ // same.
23
+ const LOGIN_SHELL_ENV_MARKER = '__OPENCHAMBER_ENV__';
24
+ const LOGIN_SHELL_ENV_COMMAND = `echo ${LOGIN_SHELL_ENV_MARKER}; env -0`;
25
+
26
+ const stripShellStartupOutput = (text) => {
27
+ const markerLine = `${LOGIN_SHELL_ENV_MARKER}\n`;
28
+ const markerIndex = text.lastIndexOf(markerLine);
29
+ return markerIndex === -1 ? text : text.slice(markerIndex + markerLine.length);
30
+ };
13
31
 
14
32
  export const createOpenCodeEnvRuntime = (deps) => {
15
33
  const {
@@ -159,11 +177,12 @@ export const createOpenCodeEnvRuntime = (deps) => {
159
177
 
160
178
  for (const shellPath of powershellCandidates) {
161
179
  try {
162
- const result = runSpawnSync(shellPath, ['-NoLogo', '-Command', psScript], {
180
+ const result = runSpawnSync(shellPath, ['-NoLogo', '-NoProfile', '-NonInteractive', '-Command', psScript], {
163
181
  encoding: 'utf8',
164
182
  stdio: ['ignore', 'pipe', 'pipe'],
165
183
  maxBuffer: 10 * 1024 * 1024,
166
184
  windowsHide: true,
185
+ timeout: WINDOWS_PROBE_TIMEOUT_MS,
167
186
  });
168
187
  if (result.status !== 0) {
169
188
  continue;
@@ -183,6 +202,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
183
202
  stdio: ['ignore', 'pipe', 'pipe'],
184
203
  maxBuffer: 10 * 1024 * 1024,
185
204
  windowsHide: true,
205
+ timeout: WINDOWS_PROBE_TIMEOUT_MS,
186
206
  });
187
207
  if (result.status === 0 && typeof result.stdout === 'string' && result.stdout.length > 0) {
188
208
  return parseNullSeparatedEnvSnapshot(result.stdout.replace(/\r?\n/g, '\0'));
@@ -220,7 +240,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
220
240
  }
221
241
 
222
242
  try {
223
- const result = runSpawnSync(shellPath, ['-lic', 'env -0'], {
243
+ const result = runSpawnSync(shellPath, ['-lic', LOGIN_SHELL_ENV_COMMAND], {
224
244
  encoding: 'utf8',
225
245
  stdio: ['ignore', 'pipe', 'pipe'],
226
246
  maxBuffer: 10 * 1024 * 1024,
@@ -232,7 +252,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
232
252
  continue;
233
253
  }
234
254
 
235
- const parsed = parseNullSeparatedEnvSnapshot(result.stdout || '');
255
+ const parsed = parseNullSeparatedEnvSnapshot(stripShellStartupOutput(result.stdout || ''));
236
256
  if (parsed) {
237
257
  state.cachedLoginShellEnvSnapshot = parsed;
238
258
  return parsed;
@@ -449,6 +469,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
449
469
  encoding: 'utf8',
450
470
  stdio: ['ignore', 'pipe', 'pipe'],
451
471
  windowsHide: true,
472
+ timeout: WINDOWS_PROBE_TIMEOUT_MS,
452
473
  });
453
474
  if (result.status === 0) {
454
475
  const lines = (result.stdout || '')
@@ -524,6 +545,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
524
545
  encoding: 'utf8',
525
546
  stdio: ['ignore', 'pipe', 'pipe'],
526
547
  windowsHide: true,
548
+ timeout: WINDOWS_PROBE_TIMEOUT_MS,
527
549
  });
528
550
  if (result.status === 0) {
529
551
  const lines = (result.stdout || '')
@@ -606,6 +628,7 @@ export const createOpenCodeEnvRuntime = (deps) => {
606
628
  encoding: 'utf8',
607
629
  stdio: ['ignore', 'pipe', 'pipe'],
608
630
  windowsHide: true,
631
+ timeout: WINDOWS_PROBE_TIMEOUT_MS,
609
632
  });
610
633
  if (result.status === 0) {
611
634
  const lines = (result.stdout || '')
@@ -240,6 +240,32 @@ describe('OpenCode env runtime', () => {
240
240
  expect(probes).toBe(0);
241
241
  });
242
242
 
243
+ it('keeps shell startup output out of the login-shell snapshot', () => {
244
+ setPlatform('darwin');
245
+ const previousShell = process.env.SHELL;
246
+ const shell = path.join(createTempDir('openchamber-shell-'), 'zsh');
247
+ fs.writeFileSync(shell, '#!/bin/sh\n', { mode: 0o755 });
248
+ process.env.SHELL = shell;
249
+ try {
250
+ const { runtime, state } = createRuntime({}, {
251
+ // Stands in for a shell whose interactive rc file prints a banner to
252
+ // stdout before it runs the probe command: only the `echo` part of the
253
+ // command and `env -0` are emulated.
254
+ spawnSync: (_command, args) => {
255
+ const echoed = args[1].match(/^echo (\S+); /);
256
+ const stdout = `Welcome to test-host\n${echoed ? `${echoed[1]}\n` : ''}HOME=/home/test-user\0PATH=/shell/bin\0`;
257
+ return { status: 0, stdout, stderr: '' };
258
+ },
259
+ });
260
+ state.cachedLoginShellEnvSnapshot = undefined;
261
+
262
+ expect(runtime.getLoginShellEnvSnapshot()).toEqual({ HOME: '/home/test-user', PATH: '/shell/bin' });
263
+ } finally {
264
+ if (previousShell === undefined) delete process.env.SHELL;
265
+ else process.env.SHELL = previousShell;
266
+ }
267
+ });
268
+
243
269
  it('does not probe the shell when the host provided an empty snapshot', () => {
244
270
  let probes = 0;
245
271
  const spawnSyncSpy = () => { probes += 1; return { status: 0, stdout: 'PATH=/from/probe\0' }; };
@@ -457,6 +483,37 @@ describe('OpenCode env runtime', () => {
457
483
  }
458
484
  });
459
485
 
486
+ it('bounds every Windows startup probe and falls through when one overruns', () => {
487
+ setPlatform('win32');
488
+ process.env.LOCALAPPDATA = createTempDir('openchamber-localappdata-');
489
+ process.env.PATH = createTempDir('openchamber-empty-path-');
490
+ process.env.SystemRoot = createTempDir('openchamber-empty-systemroot-');
491
+ delete process.env.OPENCODE_BINARY;
492
+ const calls = [];
493
+ const { runtime, state } = createRuntime({}, {
494
+ homedir: () => createTempDir('openchamber-empty-home-'),
495
+ spawnSync: (command, args, options) => {
496
+ calls.push({ command, args, options });
497
+ return { status: null, signal: 'SIGTERM', error: new Error('spawnSync ETIMEDOUT'), stdout: '', stderr: '' };
498
+ },
499
+ });
500
+
501
+ // Not probed yet, so the PowerShell and cmd snapshot probes run too.
502
+ state.cachedLoginShellEnvSnapshot = undefined;
503
+ expect(runtime.getLoginShellEnvSnapshot()).toBeNull();
504
+ expect(runtime.resolveOpencodeCliPath()).toBeNull();
505
+ expect(calls.some((call) => call.command === 'where')).toBe(true);
506
+ for (const call of calls) {
507
+ expect(call.options.timeout).toBe(10_000);
508
+ }
509
+ const powershellCalls = calls.filter((call) => call.args.includes('-Command'));
510
+ expect(powershellCalls.length).toBeGreaterThan(0);
511
+ for (const call of powershellCalls) {
512
+ expect(call.args).toContain('-NoProfile');
513
+ expect(call.args).toContain('-NonInteractive');
514
+ }
515
+ });
516
+
460
517
  it('does not auto-detect the Windows OpenCode desktop app as a CLI', () => {
461
518
  setPlatform('win32');
462
519
  const localAppData = createTempDir('openchamber-localappdata-');
@@ -334,6 +334,8 @@ export const createFeatureRoutesRuntime = (dependencies) => {
334
334
  await registerBuiltInGuests({ persistPath: extensionsPersistPath(openchamberDataDir), root: routeDependencies.builtInExtensionsDir });
335
335
  registerGuestRoutes(app, { openchamberDataDir, openchamberVersion, resolveGitBinaryForSpawn, resolveOptionalProjectDirectory, getSmallModelService, onGuestDeactivated, surfaceViewerHeaders });
336
336
  registerGitRoutes(app, {
337
+ buildOpenCodeUrl,
338
+ getOpenCodeAuthHeaders,
337
339
  emitWorktreeChanged: ({ directories, at }) => {
338
340
  const clients = getOpenChamberEventClients();
339
341
  for (const client of clients) {
@@ -33,9 +33,10 @@ export const createHmrStateRuntime = (dependencies) => {
33
33
  if (typeof hmrState.userProvidedOpenCodePassword !== 'undefined') {
34
34
  return;
35
35
  }
36
- const initialPassword = typeof processLike.env.OPENCODE_SERVER_PASSWORD === 'string'
37
- ? processLike.env.OPENCODE_SERVER_PASSWORD.trim()
38
- : '';
36
+ // Same precedence as OpenCode 2: OPENCODE_PASSWORD, then the legacy name.
37
+ const initialPassword = [processLike.env.OPENCODE_PASSWORD, processLike.env.OPENCODE_SERVER_PASSWORD]
38
+ .map((value) => (typeof value === 'string' ? value.trim() : ''))
39
+ .find((value) => value.length > 0) || '';
39
40
  hmrState.userProvidedOpenCodePassword = initialPassword || null;
40
41
  };
41
42
 
@@ -48,9 +48,10 @@ const classifyOpenCodeVersion = (version) => {
48
48
  detail: `${OPENCODE_VERSION_REQUIREMENT_DETAIL}, found ${version.trim()}. Update OpenCode and start OpenChamber again.`,
49
49
  };
50
50
  };
51
- // Last-used directory plus the three most recently opened projects — deeper
52
- // tails are unlikely to be the user's first click and just add background work.
53
- const WARMUP_DIRECTORY_LIMIT = 4;
51
+ // Only the directory the user will open anyway. On OpenCode 2 the first
52
+ // directory-scoped read boots that location's whole MCP fleet, so warming
53
+ // other projects "just in case" started processes nobody asked for (#4018).
54
+ const WARMUP_DIRECTORY_LIMIT = 1;
54
55
  const WARMUP_REQUEST_TIMEOUT_MS = 30000;
55
56
  const MANAGED_STDERR_TAIL_MAX_BYTES = 32 * 1024;
56
57
  const HEALTH_FAILURE_DETAIL_MAX_LENGTH = 256;
@@ -775,6 +776,10 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
775
776
  ...process.env,
776
777
  ...managedOpenCodeEnv,
777
778
  PATH: envPath,
779
+ // OpenCode 2 reads OPENCODE_PASSWORD before the legacy name, so a
780
+ // user's own OPENCODE_PASSWORD would otherwise win and every request
781
+ // we send with openCodePassword would get 401.
782
+ OPENCODE_PASSWORD: openCodePassword,
778
783
  OPENCODE_SERVER_PASSWORD: openCodePassword,
779
784
  })),
780
785
  });
@@ -1208,8 +1213,8 @@ export const createOpenCodeLifecycleRuntime = (deps) => {
1208
1213
  // directory-scoped request, and that initialization takes seconds on large
1209
1214
  // session stores. Without warming, the user's first session open pays it
1210
1215
  // interactively (the chat waits on the message fetch until the directory
1211
- // finishes initializing). Warm the most recently used directories right
1212
- // after readiness so the work overlaps UI startup instead. Sequential and
1216
+ // finishes initializing). Warm the last-used directory right after
1217
+ // readiness so the work overlaps UI startup instead. Sequential and
1213
1218
  // best-effort: a failed or slow directory never blocks the others for long,
1214
1219
  // and a restart invalidates the pass via the port/readiness guard.
1215
1220
  const warmOpenCodeDirectories = async () => {
@@ -120,6 +120,7 @@ const createRuntime = (overrides = {}, stateOverrides = {}, envOverrides = {}) =
120
120
  getManagedOpenCodeShellEnvSnapshot: vi.fn(() => ({
121
121
  PATH: '/home/user/.bun/bin:/usr/local/bin:/usr/bin',
122
122
  SHELL_ONLY: 'yes',
123
+ OPENCODE_PASSWORD: 'shell-password',
123
124
  OPENCODE_SERVER_PASSWORD: 'shell-password',
124
125
  })),
125
126
  ...overrides,
@@ -267,7 +268,7 @@ describe('OpenCode lifecycle', () => {
267
268
  expect(runtime.testState.lastOpenCodeError).toContain('1.18.32');
268
269
  });
269
270
 
270
- it('warms recently used directories after a successful bootstrap', async () => {
271
+ it('warms only the last-used directory after a successful bootstrap', async () => {
271
272
  const fetchMock = vi.fn(async () => ({
272
273
  ok: true,
273
274
  json: async () => ({ version: '2.0.15', pid: 1, urls: [], paths: { tmp: '/tmp' } }),
@@ -291,9 +292,9 @@ describe('OpenCode lifecycle', () => {
291
292
  const warmupUrls = fetchMock.mock.calls
292
293
  .map(([url]) => String(url))
293
294
  .filter((url) => url.includes('/api/session?'));
295
+ // Each warmed directory boots its whole MCP fleet on OpenCode 2 (#4018).
294
296
  expect(warmupUrls).toEqual([
295
297
  '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',
297
298
  ]);
298
299
  });
299
300
 
@@ -663,6 +664,7 @@ describe('OpenCode lifecycle', () => {
663
664
  expect(args).toEqual(['serve', '--hostname', '127.0.0.1', '--port', '45678']);
664
665
  expect(options.env.PATH).toBe('/home/user/.bun/bin:/usr/local/bin:/usr/bin');
665
666
  expect(options.env.SHELL_ONLY).toBe('yes');
667
+ expect(options.env.OPENCODE_PASSWORD).toBe('password');
666
668
  expect(options.env.OPENCODE_SERVER_PASSWORD).toBe('password');
667
669
  expect(server.exitCode).toBeNull();
668
670
  expect(server.signalCode).toBeNull();
@@ -738,6 +740,7 @@ describe('OpenCode lifecycle', () => {
738
740
  OPENCODE_CONFIG_CONTENT: '{"plugin":["file:///tool.js"]}',
739
741
  OPENCHAMBER_AGENT_TOOL_TOKEN: 'ephemeral',
740
742
  PATH: '/untrusted/path',
743
+ OPENCODE_PASSWORD: 'untrusted-password',
741
744
  OPENCODE_SERVER_PASSWORD: 'untrusted-password',
742
745
  }));
743
746
 
@@ -749,6 +752,7 @@ describe('OpenCode lifecycle', () => {
749
752
  expect(options.env.OPENCODE_CONFIG_CONTENT).toBe('{"plugin":["file:///tool.js"]}');
750
753
  expect(options.env.OPENCHAMBER_AGENT_TOOL_TOKEN).toBe('ephemeral');
751
754
  expect(options.env.PATH).toBe('/home/user/.bun/bin:/usr/local/bin:/usr/bin');
755
+ expect(options.env.OPENCODE_PASSWORD).toBe('password');
752
756
  expect(options.env.OPENCODE_SERVER_PASSWORD).toBe('password');
753
757
 
754
758
  await server.close();
@@ -82,10 +82,11 @@ export const createManagedConfigRuntime = ({
82
82
  const includeWeb = settings?.agentWebToolEnabled !== false;
83
83
  const includeMemory = isAgentMemoryAvailable() && settings?.agentMemoryToolEnabled === true;
84
84
  const includeNotify = settings?.agentNotifyToolEnabled === true;
85
+ const codeMode = settings?.agentToolsCodeMode === true;
85
86
 
86
87
  const directories = [];
87
88
  if (agentToolRuntime && (includeControl || includeWeb || includeMemory || includeNotify)) {
88
- directories.push(await agentToolRuntime.materializePlugin({ includeControl, includeWeb, includeMemory, includeNotify }));
89
+ directories.push(await agentToolRuntime.materializePlugin({ includeControl, includeWeb, includeMemory, includeNotify, codeMode }));
89
90
  }
90
91
  return directories;
91
92
  };
@@ -108,6 +108,7 @@ describe('managed OpenCode config file', () => {
108
108
  includeWeb: true,
109
109
  includeMemory: false,
110
110
  includeNotify: false,
111
+ codeMode: false,
111
112
  });
112
113
  });
113
114
 
@@ -123,6 +124,23 @@ describe('managed OpenCode config file', () => {
123
124
  includeWeb: false,
124
125
  includeMemory: false,
125
126
  includeNotify: true,
127
+ codeMode: false,
128
+ });
129
+ });
130
+
131
+ it('puts the tools behind Code Mode only when the user asks for it', async () => {
132
+ const { runtime, agentToolRuntime } = await createHarness({
133
+ settings: { agentToolsCodeMode: true },
134
+ });
135
+
136
+ await runtime.buildManagedChildEnv();
137
+
138
+ expect(agentToolRuntime.materializePlugin).toHaveBeenCalledWith({
139
+ includeControl: true,
140
+ includeWeb: true,
141
+ includeMemory: false,
142
+ includeNotify: false,
143
+ codeMode: true,
126
144
  });
127
145
  });
128
146
 
@@ -0,0 +1 @@
1
+ export function resolveNpmRegistryRequest(packageName: string): { url: string; headers: Record<string, string> };
@@ -0,0 +1,123 @@
1
+ import fs from 'fs';
2
+ import os from 'os';
3
+ import path from 'path';
4
+
5
+ const DEFAULT_NPM_REGISTRY = 'https://registry.npmjs.org';
6
+
7
+ function configPath() {
8
+ const configured = [process.env.npm_config_userconfig, process.env.NPM_CONFIG_USERCONFIG]
9
+ .map((value) => value?.trim())
10
+ .find(Boolean);
11
+ return configured || path.join(os.homedir(), '.npmrc');
12
+ }
13
+
14
+ // npm's ini parser accepts `key = "value"`; the quotes are not part of the value.
15
+ function unquote(value) {
16
+ const quoted = value.length >= 2 && (value[0] === '"' || value[0] === "'") && value.at(-1) === value[0];
17
+ return quoted ? value.slice(1, -1) : value;
18
+ }
19
+
20
+ function configValues() {
21
+ try {
22
+ const values = new Map();
23
+ for (const rawLine of fs.readFileSync(configPath(), 'utf8').split(/\r?\n/)) {
24
+ const line = rawLine.trim();
25
+ if (line === '' || line.startsWith('#') || line.startsWith(';')) continue;
26
+
27
+ const separator = line.indexOf('=');
28
+ if (separator < 1) continue;
29
+ values.set(line.slice(0, separator).trim(), unquote(line.slice(separator + 1).trim()));
30
+ }
31
+ return values;
32
+ } catch {
33
+ return new Map();
34
+ }
35
+ }
36
+
37
+ function configuredValue(values, key) {
38
+ const configured = values.get(key);
39
+ if (!configured) return configured;
40
+
41
+ return configured.replace(/\$\{([^}]+)\}/g, (_match, variable) => {
42
+ const value = process.env[variable];
43
+ if (value === undefined) throw new Error('Missing npm configuration environment variable');
44
+ return value;
45
+ });
46
+ }
47
+
48
+ function registryFor(packageName, values) {
49
+ const scope = packageName.startsWith('@') ? packageName.split('/', 1)[0] : null;
50
+ const scopedEnvironmentRegistry = scope && [
51
+ process.env[`npm_config_${scope}:registry`],
52
+ process.env[`NPM_CONFIG_${scope}:REGISTRY`],
53
+ ].map((value) => value?.trim()).find(Boolean);
54
+ if (scopedEnvironmentRegistry) return scopedEnvironmentRegistry;
55
+
56
+ const scopedRegistry = scope && configuredValue(values, `${scope}:registry`);
57
+ if (scopedRegistry) return scopedRegistry;
58
+
59
+ const environmentRegistry = [process.env.npm_config_registry, process.env.NPM_CONFIG_REGISTRY]
60
+ .map((value) => value?.trim())
61
+ .find(Boolean);
62
+ if (environmentRegistry) return environmentRegistry;
63
+
64
+ return configuredValue(values, 'registry') || DEFAULT_NPM_REGISTRY;
65
+ }
66
+
67
+ function authFor(registry, values) {
68
+ const registryScope = `//${registry.host}${registry.pathname.replace(/\/+$/, '')}/`;
69
+ let bestMatch = null;
70
+
71
+ for (const key of values.keys()) {
72
+ const match = /^(\/\/.*\/):(?:_authToken|_auth|username|_password)$/.exec(key);
73
+ if (match && registryScope.startsWith(match[1]) && (!bestMatch || match[1].length > bestMatch.length)) {
74
+ bestMatch = match[1];
75
+ }
76
+ }
77
+
78
+ if (!bestMatch) return {};
79
+
80
+ const token = configuredValue(values, `${bestMatch}:_authToken`);
81
+ if (token) return { Authorization: `Bearer ${token}` };
82
+
83
+ const authorization = configuredValue(values, `${bestMatch}:_auth`);
84
+ if (authorization) return { Authorization: `Basic ${authorization}` };
85
+
86
+ const username = configuredValue(values, `${bestMatch}:username`);
87
+ const password = configuredValue(values, `${bestMatch}:_password`);
88
+ if (username && password) {
89
+ const decodedPassword = Buffer.from(password, 'base64').toString('utf8');
90
+ return { Authorization: `Basic ${Buffer.from(`${username}:${decodedPassword}`).toString('base64')}` };
91
+ }
92
+
93
+ return {};
94
+ }
95
+
96
+ /**
97
+ * Build a credential-safe package metadata request using npm's standard user configuration.
98
+ *
99
+ * @param {string} packageName
100
+ * @returns {{ url: string, headers: Record<string, string> }}
101
+ */
102
+ export function resolveNpmRegistryRequest(packageName) {
103
+ const values = configValues();
104
+ let registry;
105
+ try {
106
+ registry = new URL(registryFor(packageName, values));
107
+ if (!['http:', 'https:'].includes(registry.protocol) || registry.search || registry.hash) {
108
+ throw new Error('invalid registry');
109
+ }
110
+ } catch {
111
+ throw new Error('Invalid npm registry URL');
112
+ }
113
+
114
+ const headers = authFor(registry, values);
115
+ registry.username = '';
116
+ registry.password = '';
117
+ registry.pathname = `${registry.pathname.replace(/\/+$/, '')}/`;
118
+
119
+ return {
120
+ url: `${registry.toString()}${encodeURIComponent(packageName).replace(/^%40/i, '@')}`,
121
+ headers,
122
+ };
123
+ }