@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
@@ -2,17 +2,27 @@
2
2
  * `/api/routing` — configuration and the Jev key. Normal authenticated
3
3
  * OpenChamber routes: do not add them to browser URL-token allowlists.
4
4
  *
5
- * `/api/session/:id/{prompt_async,prompt,command}` — the rewrite that turns
6
- * `openchamber/auto` into a real model before the generic OpenCode proxy
7
- * forwards the request. Registered ahead of the proxy; it parses the JSON body
8
- * only while Auto can actually be selected, so a build without the flag pays
9
- * nothing on the send path.
5
+ * The send-path rewrite, registered ahead of the generic OpenCode proxy. In
6
+ * OpenCode 2.x a prompt body carries no model: the client switches the session
7
+ * first (`POST /session/:id/model`) and sends afterwards. So the rewrite is in
8
+ * two halves:
9
+ *
10
+ * - `POST /session/:id/model` with `openchamber/auto` never reaches OpenCode,
11
+ * which has no such provider. It marks the session as routed and answers as
12
+ * a switch would.
13
+ * - `POST /session/:id/{prompt,command}` in a routed session asks Jev on the
14
+ * request text and switches the session onto the chosen model and agent
15
+ * before the prompt is forwarded.
16
+ *
17
+ * Both parse the JSON body only for JSON requests, so a streamed or non-JSON
18
+ * upload reaches the proxy untouched.
10
19
  */
11
20
  import express from 'express';
12
- import { isRoutingFeatureAvailable } from './feature-flag.js';
21
+ import { isAutoModel } from './defaults.js';
13
22
 
14
- const AUTO_SESSION_PATHS = [
15
- '/api/session/:sessionId/prompt_async',
23
+ const CREATE_PATH = '/api/session';
24
+ const MODEL_PATH = '/api/session/:sessionId/model';
25
+ const SEND_PATHS = [
16
26
  '/api/session/:sessionId/prompt',
17
27
  '/api/session/:sessionId/command',
18
28
  ];
@@ -23,12 +33,9 @@ const sendError = (res, error) => {
23
33
  };
24
34
 
25
35
  export function registerRoutingRoutes(app, runtime) {
26
- const unavailable = (res) => res.status(404).json({ error: 'Routing is not available in this build' });
27
-
28
36
  app.get('/api/routing', async (_req, res) => {
29
37
  try {
30
38
  const state = await runtime.describe();
31
- if (!state.available) return unavailable(res);
32
39
  res.json({ ...state, heldPermissions: runtime.heldPermissions() });
33
40
  } catch (error) {
34
41
  sendError(res, error);
@@ -36,7 +43,6 @@ export function registerRoutingRoutes(app, runtime) {
36
43
  });
37
44
 
38
45
  app.put('/api/routing', express.json({ limit: '256kb' }), async (req, res) => {
39
- if (!isRoutingFeatureAvailable()) return unavailable(res);
40
46
  try {
41
47
  res.json(await runtime.updateConfig(req.body?.config));
42
48
  } catch (error) {
@@ -45,7 +51,6 @@ export function registerRoutingRoutes(app, runtime) {
45
51
  });
46
52
 
47
53
  app.put('/api/routing/token', express.json({ limit: '16kb' }), async (req, res) => {
48
- if (!isRoutingFeatureAvailable()) return unavailable(res);
49
54
  try {
50
55
  res.json(await runtime.setToken(req.body?.token));
51
56
  } catch (error) {
@@ -54,7 +59,6 @@ export function registerRoutingRoutes(app, runtime) {
54
59
  });
55
60
 
56
61
  app.delete('/api/routing/token', async (_req, res) => {
57
- if (!isRoutingFeatureAvailable()) return unavailable(res);
58
62
  try {
59
63
  res.json(await runtime.clearToken());
60
64
  } catch (error) {
@@ -65,17 +69,56 @@ export function registerRoutingRoutes(app, runtime) {
65
69
 
66
70
  export function registerRoutingPromptRewrite(app, runtime) {
67
71
  const parseJson = express.json({ limit: '50mb' });
68
- app.post(AUTO_SESSION_PATHS, (req, res, next) => {
69
- if (!isRoutingFeatureAvailable()) return next();
72
+
73
+ /** Parses the body only for JSON requests; anything else stays a stream. */
74
+ const withParsedBody = (handler) => (req, res, next) => {
70
75
  const contentType = String(req.headers['content-type'] ?? '').toLowerCase();
71
76
  if (!contentType.includes('application/json')) return next();
72
77
  parseJson(req, res, (parseError) => {
73
78
  if (parseError) return next(parseError);
74
- const url = new URL(req.url, 'http://localhost');
75
- const directory = url.searchParams.get('directory') || req.get('x-opencode-directory') || undefined;
76
- runtime.resolvePromptBody(req.body, { sessionId: req.params.sessionId, directory })
77
- .then(() => next())
78
- .catch((error) => sendError(res, error));
79
+ handler(req, res, next);
79
80
  });
80
- });
81
+ };
82
+
83
+ const directoryOf = (req) => {
84
+ const url = new URL(req.url, 'http://localhost');
85
+ return url.searchParams.get('directory') || req.get('x-opencode-directory') || undefined;
86
+ };
87
+
88
+ // Session creation is the other v2 request that carries a model: flows that
89
+ // know their first turn's selection create the session on it (btw forks,
90
+ // auto review, fusion, extension starts). OpenCode accepts the sentinel at
91
+ // creation and only fails the first prompt with "provider.no-route", so the
92
+ // model is dropped here and the session starts on OpenCode's default. No
93
+ // session id exists yet to mark; the first send resends the sentinel through
94
+ // the model switch below because the session's record never matches Auto.
95
+ app.post(CREATE_PATH, withParsedBody((req, _res, next) => {
96
+ if (!isAutoModel(req.body?.model)) return next();
97
+ delete req.body.model;
98
+ next();
99
+ }));
100
+
101
+ app.post(MODEL_PATH, withParsedBody((req, res, next) => {
102
+ const directory = directoryOf(req);
103
+ // Swallowed, not forwarded: OpenCode has no `openchamber` provider, and the
104
+ // real model is only known once the request text arrives.
105
+ if (runtime.noteModelSelection(req.params.sessionId, req.body?.model, directory)) return res.status(204).end();
106
+ next();
107
+ }));
108
+
109
+ // Whether the session is routed is known from the URL alone, so an ordinary
110
+ // send is never read: it reaches the proxy as the stream it arrived as, the
111
+ // way it did before routing existed.
112
+ const routedSendsOnly = (handler) => {
113
+ const parsed = withParsedBody(handler);
114
+ return (req, res, next) => (runtime.isAutoSession(req.params.sessionId) ? parsed(req, res, next) : next());
115
+ };
116
+
117
+ app.post(SEND_PATHS, routedSendsOnly((req, res, next) => {
118
+ const sessionId = req.params.sessionId;
119
+ const directory = directoryOf(req);
120
+ runtime.routeSend({ sessionId, directory, body: req.body })
121
+ .then(() => next())
122
+ .catch((error) => sendError(res, error));
123
+ }));
81
124
  }
@@ -1,16 +1,21 @@
1
1
  /**
2
- * Owns Jev routing at runtime: whether Auto is ready, rewriting a prompt body
3
- * that names the `openchamber/auto` model, and the safety net consulted before
4
- * a permission is auto-accepted. Every failure path keeps the user's own
2
+ * Owns Jev routing at runtime: whether Auto is ready, which model and agent a
3
+ * send that selected `openchamber/auto` runs on, and the safety net consulted
4
+ * before a permission is auto-accepted. Every failure path keeps the user's own
5
5
  * behaviour: a prompt goes to the fallback model, a permission is accepted as
6
6
  * auto-accept would have, and the UI is told why.
7
+ *
8
+ * OpenCode 2.x holds the model and the agent on the session, switched by their
9
+ * own calls, and a prompt body carries only the user's text. So Auto is a
10
+ * per-session state here: the sentinel arrives on `POST /session/:id/model`
11
+ * and is swallowed, and every prompt in that session is routed until a real
12
+ * model is selected.
7
13
  */
8
- import { createOpencodeClient } from '@opencode-ai/sdk/v2';
14
+ import { OpenCode } from '@opencode/client';
9
15
  import { z } from 'zod';
10
- import { isRoutingFeatureAvailable } from './feature-flag.js';
11
- import { BUILTIN_CATEGORIES, isAutoModel } from './defaults.js';
16
+ import { AUTO_MODEL_REF, BUILTIN_CATEGORIES, isAutoModel } from './defaults.js';
12
17
  import { createRoutingStore, parseEffectiveConfig } from './store.js';
13
- import { buildPermissionRequest, buildRoutingRequest, createJevClient, decidePermission, decideRouting } from './jev.js';
18
+ import { buildPermissionRequest, buildRoutingRequest, createJevClient, decidePermission, decideRouting, jevEndpoint } from './jev.js';
14
19
  import { loadRoutingHistory } from './history.js';
15
20
 
16
21
  const HISTORY_TIMEOUT_MS = 2500;
@@ -19,25 +24,31 @@ const PERMISSION_DECISION_TTL_MS = 15 * 60 * 1000;
19
24
 
20
25
  const errorMessage = (error) => (error instanceof Error ? error.message : String(error));
21
26
 
22
- const textPartSchema = z.object({ type: z.literal('text'), text: z.string(), synthetic: z.boolean().optional() });
23
- const commandBodySchema = z.object({ command: z.string(), arguments: z.string().optional() });
24
- const promptBodySchema = z.object({ parts: z.array(z.unknown()).optional() });
27
+ // v2's command body (`session.command` in the protocol) names the command in
28
+ // `name` and carries its arguments in `text`; a prompt body has no `name`.
29
+ const commandBodySchema = z.object({ name: z.string().trim().min(1), text: z.string().nullish() });
30
+ // v2 sends one user turn as flat text; the context the composer attached went
31
+ // ahead of it as synthetic messages, which are never the request being routed.
32
+ const promptBodySchema = z.object({ text: z.string().nullish() });
25
33
 
26
- /** The user's words for this send: text parts the composer authored, or the slash command. */
34
+ /** The user's words for this send: the prompt text, or the slash command. */
27
35
  export const requestTextOf = (body) => {
28
36
  const command = commandBodySchema.safeParse(body);
29
37
  if (command.success) {
30
- const args = command.data.arguments?.trim();
31
- return `/${command.data.command}${args ? ` ${args}` : ''}`;
38
+ const args = command.data.text?.trim();
39
+ return `/${command.data.name}${args ? ` ${args}` : ''}`;
32
40
  }
33
41
  const prompt = promptBodySchema.safeParse(body);
34
- const parts = prompt.success ? prompt.data.parts ?? [] : [];
35
- return parts
36
- .map((part) => textPartSchema.safeParse(part))
37
- .filter((part) => part.success && !part.data.synthetic)
38
- .map((part) => part.data.text)
39
- .join('\n\n')
40
- .trim();
42
+ return (prompt.success ? prompt.data.text ?? '' : '').trim();
43
+ };
44
+
45
+ const agentBodySchema = z.object({ agent: z.string().trim().min(1) });
46
+
47
+ /** OpenChamber stores a model as `{ providerID, modelID }`; v2 wants a `Model.Ref`. */
48
+ const toModelRef = (model, variant) => {
49
+ const ref = { providerID: model.providerID, id: model.modelID };
50
+ if (variant) ref.variant = variant;
51
+ return ref;
41
52
  };
42
53
 
43
54
  export function createRoutingRuntime({
@@ -51,6 +62,14 @@ export function createRoutingRuntime({
51
62
  now = Date.now,
52
63
  }) {
53
64
  const permissionDecisions = new Map();
65
+ // Sessions the user put on Auto. The sentinel never reaches OpenCode, so
66
+ // nothing upstream remembers the choice for us.
67
+ // TODO(v2): this is process memory. A server restart drops the mark and the
68
+ // session silently runs on whatever model it was last switched to while the
69
+ // composer still shows Auto. Either persist it next to `routing.json` or have
70
+ // the client resend the sentinel with every send.
71
+ const autoSessions = new Map();
72
+ const AUTO_SESSION_LIMIT = 1000;
54
73
 
55
74
  const broadcast = (type, properties) => {
56
75
  try {
@@ -64,63 +83,82 @@ export function createRoutingRuntime({
64
83
 
65
84
  /** What the client needs to decide whether to offer Auto and what the settings page shows. */
66
85
  const describe = async () => {
67
- const available = isRoutingFeatureAvailable();
68
- if (!available) return { available: false, autoReady: false, tokenPresent: false, config: null, builtins: [] };
69
86
  const [config, token] = await Promise.all([store.readConfig(), store.readToken()]);
70
87
  const tokenPresent = Boolean(token);
71
- const autoReady = config.enabled && tokenPresent && Boolean(config.fallback) && enabledCategories(config).length >= 2;
88
+ // A key is not a precondition: without one Jev answers through the free
89
+ // model zen serves, so Auto only needs a fallback and two categories.
90
+ const autoReady = config.enabled && Boolean(config.fallback) && enabledCategories(config).length >= 2;
72
91
  // Built-in text travels with the config so "Reset" in Settings restores the shipped wording.
73
- return { available, autoReady, tokenPresent, config, builtins: BUILTIN_CATEGORIES };
92
+ // `available` stays in the payload for the client: a runtime without an
93
+ // OpenChamber server (VS Code) answers 404 and reads it as false.
94
+ return { available: true, autoReady, tokenPresent, jevSource: jevEndpoint(token).source, config, builtins: BUILTIN_CATEGORIES };
74
95
  };
75
96
 
76
97
  const publishUpdated = async () => {
77
98
  const state = await describe();
78
- broadcast('openchamber:routing.updated', { available: state.available, autoReady: state.autoReady, tokenPresent: state.tokenPresent });
99
+ broadcast('openchamber:routing.updated', {
100
+ available: state.available, autoReady: state.autoReady, tokenPresent: state.tokenPresent, jevSource: state.jevSource,
101
+ });
79
102
  return state;
80
103
  };
81
104
 
105
+ const openCodeClient = (directory) => {
106
+ const headers = { ...getOpenCodeAuthHeaders() };
107
+ // v2 scopes by header and rejects non-ASCII header values.
108
+ const scope = z.string().trim().min(1).safeParse(directory);
109
+ if (scope.success) headers['x-opencode-directory'] = encodeURIComponent(scope.data);
110
+ return OpenCode.make({ baseUrl: buildOpenCodeUrl('/', '').replace(/\/$/, ''), headers });
111
+ };
112
+
82
113
  const readHistory = async ({ sessionId, directory }) => {
83
- const baseUrl = buildOpenCodeUrl('/', '').replace(/\/$/, '');
84
- const client = createOpencodeClient({ baseUrl, headers: getOpenCodeAuthHeaders(), throwOnError: true });
114
+ const client = openCodeClient(directory);
85
115
  const signal = AbortSignal.timeout(HISTORY_TIMEOUT_MS);
86
116
  return loadRoutingHistory({
87
117
  signal,
88
- readPage: (page) => client.session.messages({ sessionID: sessionId, directory, ...page }, { signal }),
118
+ // v2 pages a session's messages newest first and returns `{ data, cursor }`.
119
+ readPage: ({ limit, cursor }) => client.message.list(
120
+ { sessionID: sessionId, limit, ...(cursor ? { cursor } : { order: 'desc' }) },
121
+ { signal },
122
+ ),
89
123
  });
90
124
  };
91
125
 
92
126
  // A category without a model of its own means "the fallback pair"; a variant
93
127
  // only travels with the model it was chosen for.
94
- const applyChoice = (body, config, choice) => {
128
+ const chooseSelection = (config, choice, composerAgent) => {
95
129
  const own = Boolean(choice?.model);
96
130
  const model = own ? choice.model : config.fallback.model;
97
131
  const variant = own ? choice.variant : config.fallback.variant;
98
- // Keep the wire shape the route uses: a string on /command, an object on the prompt routes.
99
- body.model = z.string().safeParse(body.model).success
100
- ? `${model.providerID}/${model.modelID}`
101
- : { providerID: model.providerID, modelID: model.modelID };
102
- if (variant) body.variant = variant;
103
- else delete body.variant;
104
- if (choice?.agent) body.agent = choice.agent;
105
- return { providerID: model.providerID, modelID: model.modelID, variant: variant ?? null, agent: choice?.agent ?? null };
132
+ return {
133
+ model: toModelRef(model, variant),
134
+ // A category agent replaces the composer's; an empty one keeps it.
135
+ agent: choice?.agent || composerAgent || null,
136
+ decision: { providerID: model.providerID, modelID: model.modelID, variant: variant ?? null, agent: choice?.agent ?? null },
137
+ };
106
138
  };
107
139
 
108
140
  /**
109
- * Rewrites `body.model` in place when it is the Auto sentinel. Returns the
110
- * decision that was applied, or null when the body named a real model.
141
+ * Resolves one send that named the Auto sentinel. Returns the model and
142
+ * agent the send must use, or null when a real model was selected.
143
+ *
144
+ * v2 carries neither model nor agent in a prompt body — they are session
145
+ * state, switched by their own calls — so the caller applies the selection
146
+ * (`applySessionSelection`, or its own switch calls) instead of the runtime
147
+ * rewriting a body in place the way v1 allowed.
148
+ *
111
149
  * Throws only when Auto cannot be honoured at all (no fallback configured):
112
150
  * the sentinel must never reach OpenCode.
113
151
  */
114
- const resolvePromptBody = async (body, { sessionId, directory }) => {
115
- if (!isAutoModel(body?.model)) return null;
152
+ const resolveAutoSelection = async ({ sessionId, directory, model, agent, requestText }) => {
153
+ if (!isAutoModel(model)) return null;
116
154
  const state = await describe();
117
155
  const config = state.config;
118
156
  if (!config?.fallback) {
119
157
  throw Object.assign(new Error('Auto routing is selected but no fallback model is configured'), { status: 400 });
120
158
  }
121
159
  const decision = { sessionId, at: now(), category: null, confidence: 0, reason: 'not-ready', ms: 0 };
160
+ let selection;
122
161
  if (state.autoReady) {
123
- const request = requestTextOf(body);
124
162
  let history = [];
125
163
  try {
126
164
  history = await readHistory({ sessionId, directory });
@@ -129,23 +167,69 @@ export function createRoutingRuntime({
129
167
  }
130
168
  try {
131
169
  const token = await store.readToken();
170
+ const request = (requestText ?? '').trim();
132
171
  const { answers, ms } = await jev.ask(buildRoutingRequest({ categories: enabledCategories(config), history, request }), token);
133
172
  const result = decideRouting(answers.category, { categories: enabledCategories(config), minConfidence: config.minConfidence });
134
173
  decision.category = result.category?.id ?? null;
135
174
  decision.confidence = result.confidence;
136
175
  decision.reason = result.reason;
137
176
  decision.ms = ms;
138
- Object.assign(decision, applyChoice(body, config, result.category));
177
+ selection = chooseSelection(config, result.category, agent);
139
178
  } catch (error) {
140
179
  decision.reason = 'error';
141
180
  decision.error = errorMessage(error);
142
- Object.assign(decision, applyChoice(body, config, null));
181
+ selection = chooseSelection(config, null, agent);
143
182
  }
144
183
  } else {
145
- Object.assign(decision, applyChoice(body, config, null));
184
+ selection = chooseSelection(config, null, agent);
146
185
  }
186
+ Object.assign(decision, selection.decision);
147
187
  broadcast('openchamber:routing.decision', decision);
148
- return decision;
188
+ return { model: selection.model, agent: selection.agent, decision };
189
+ };
190
+
191
+ /**
192
+ * `POST /session/:id/model` with the sentinel puts the session on Auto;
193
+ * with any real model it takes it off again.
194
+ */
195
+ const noteModelSelection = (sessionId, model, directory) => {
196
+ if (!sessionId) return false;
197
+ if (!isAutoModel(model)) {
198
+ autoSessions.delete(sessionId);
199
+ return false;
200
+ }
201
+ autoSessions.delete(sessionId);
202
+ autoSessions.set(sessionId, { directory: directory ?? null, at: now() });
203
+ while (autoSessions.size > AUTO_SESSION_LIMIT) autoSessions.delete(autoSessions.keys().next().value);
204
+ return true;
205
+ };
206
+
207
+ const isAutoSession = (sessionId) => Boolean(sessionId) && autoSessions.has(sessionId);
208
+
209
+ /** Switches the session onto a resolved selection, the way a v2 send does. */
210
+ const applySessionSelection = async (sessionId, directory, selection) => {
211
+ const client = openCodeClient(directory);
212
+ await client.session.switchModel({ sessionID: sessionId, model: selection.model });
213
+ if (selection.agent) await client.session.switchAgent({ sessionID: sessionId, agent: selection.agent });
214
+ };
215
+
216
+ /**
217
+ * One send in a routed session: asks Jev on the request text, switches the
218
+ * session onto the answer, and keeps the body in step with it.
219
+ */
220
+ const routeSend = async ({ sessionId, directory, body }) => {
221
+ const resolved = await resolveAutoSelection({
222
+ sessionId,
223
+ directory,
224
+ model: AUTO_MODEL_REF,
225
+ agent: agentBodySchema.safeParse(body).data?.agent ?? null,
226
+ requestText: requestTextOf(body),
227
+ });
228
+ if (!resolved) return null;
229
+ // v2 prompt and command bodies carry neither model nor agent: switching
230
+ // the session is the whole application of the decision.
231
+ await applySessionSelection(sessionId, directory, resolved);
232
+ return resolved.decision;
149
233
  };
150
234
 
151
235
  /**
@@ -158,7 +242,7 @@ export function createRoutingRuntime({
158
242
  const cached = permissionDecisions.get(permission.id);
159
243
  if (cached && now() - cached.at < PERMISSION_DECISION_TTL_MS) return cached.result;
160
244
  const state = await describe();
161
- if (!state.available || !state.config?.enabled || !state.config.safetyNet.enabled || !state.tokenPresent) return { action: 'accept' };
245
+ if (!state.config?.enabled || !state.config.safetyNet.enabled) return { action: 'accept' };
162
246
  let result;
163
247
  try {
164
248
  const token = await store.readToken();
@@ -213,5 +297,18 @@ export function createRoutingRuntime({
213
297
  return held;
214
298
  };
215
299
 
216
- return { describe, resolvePromptBody, evaluatePermission, forgetPermission, heldPermissions, updateConfig, setToken, clearToken };
300
+ return {
301
+ describe,
302
+ noteModelSelection,
303
+ isAutoSession,
304
+ resolveAutoSelection,
305
+ applySessionSelection,
306
+ routeSend,
307
+ evaluatePermission,
308
+ forgetPermission,
309
+ heldPermissions,
310
+ updateConfig,
311
+ setToken,
312
+ clearToken,
313
+ };
217
314
  }
@@ -2,9 +2,9 @@ import { describe, expect, it, vi } from 'vitest';
2
2
  import { createRoutingRuntime, requestTextOf } from './runtime.js';
3
3
  import { resolveEffectiveConfig } from './store.js';
4
4
  import { excerptHead, excerptHeadTail, turnsToHistory } from './history.js';
5
- import { decidePermission, decideRouting } from './jev.js';
5
+ import { createJevClient, decidePermission, decideRouting } from './jev.js';
6
6
 
7
- const AUTO = { providerID: 'openchamber', modelID: 'auto' };
7
+ const AUTO = { providerID: 'openchamber', id: 'auto' };
8
8
  const FALLBACK = { model: { providerID: 'anthropic', modelID: 'claude-sonnet-5' }, variant: 'medium' };
9
9
 
10
10
  const readyConfig = () => {
@@ -18,8 +18,7 @@ const readyConfig = () => {
18
18
  return config;
19
19
  };
20
20
 
21
- const makeRuntime = ({ config = readyConfig(), token = 'key', answers, askError, flag = '1' } = {}) => {
22
- process.env.OPENCHAMBER_ROUTING_ENABLE = flag;
21
+ const makeRuntime = ({ config = readyConfig(), token = 'key', answers, askError } = {}) => {
23
22
  const events = [];
24
23
  const store = {
25
24
  readConfig: vi.fn(async () => config),
@@ -41,16 +40,15 @@ const makeRuntime = ({ config = readyConfig(), token = 'key', answers, askError,
41
40
  };
42
41
 
43
42
  describe('requestTextOf', () => {
44
- it('joins authored text parts and ignores synthetic ones and files', () => {
45
- expect(requestTextOf({ parts: [
46
- { type: 'text', text: 'fix the typo' },
47
- { type: 'text', text: 'injected', synthetic: true },
48
- { type: 'file', url: 'data:...' },
49
- { type: 'text', text: 'in README' },
50
- ] })).toBe('fix the typo\n\nin README');
43
+ it('reads the prompt text a v2 send carries', () => {
44
+ expect(requestTextOf({ text: ' fix the typo in README ', files: [{ uri: 'data:...' }] })).toBe('fix the typo in README');
51
45
  });
52
- it('renders a slash command with its arguments', () => {
53
- expect(requestTextOf({ command: 'review', arguments: ' 3650 ' })).toBe('/review 3650');
46
+ it('renders a v2 command body (`name` plus `text`) as the slash command', () => {
47
+ expect(requestTextOf({ name: 'review', text: ' src ' })).toBe('/review src');
48
+ });
49
+ it('keeps the command name when it has no arguments', () => {
50
+ expect(requestTextOf({ name: 'review', text: '' })).toBe('/review');
51
+ expect(requestTextOf({ name: 'review' })).toBe('/review');
54
52
  });
55
53
  });
56
54
 
@@ -85,63 +83,91 @@ describe('decisions', () => {
85
83
  });
86
84
  });
87
85
 
88
- describe('resolvePromptBody', () => {
86
+ describe('resolveAutoSelection', () => {
87
+ const send = (extra = {}) => ({ sessionId: 's1', model: AUTO, requestText: 'find the root cause', ...extra });
88
+
89
89
  it('leaves a real model untouched and does not consult Jev', async () => {
90
90
  const { runtime, jev } = makeRuntime({ answers: {} });
91
- const body = { model: { providerID: 'anthropic', modelID: 'claude-opus-5' }, parts: [] };
92
- expect(await runtime.resolvePromptBody(body, { sessionId: 's1' })).toBeNull();
93
- expect(body.model.modelID).toBe('claude-opus-5');
91
+ expect(await runtime.resolveAutoSelection(send({ model: { providerID: 'anthropic', id: 'claude-opus-5' } }))).toBeNull();
94
92
  expect(jev.ask).not.toHaveBeenCalled();
95
93
  });
96
94
 
97
- it('rewrites the sentinel with the routed category model, variant and agent', async () => {
95
+ it('answers with the routed category model, variant and agent', async () => {
98
96
  const { runtime, events } = makeRuntime({ answers: { category: { choice: 'hard', confidence: 0.97 } } });
99
- const body = { model: AUTO, variant: 'low', agent: 'build', parts: [{ type: 'text', text: 'find the root cause' }] };
100
- const decision = await runtime.resolvePromptBody(body, { sessionId: 's1' });
101
- expect(body).toMatchObject({ model: { providerID: 'openai', modelID: 'gpt-6-astra' }, variant: 'high', agent: 'plan' });
102
- expect(decision).toMatchObject({ category: 'hard', reason: 'routed', confidence: 0.97 });
97
+ const resolved = await runtime.resolveAutoSelection(send({ agent: 'build' }));
98
+ expect(resolved.model).toEqual({ providerID: 'openai', id: 'gpt-6-astra', variant: 'high' });
99
+ expect(resolved.agent).toBe('plan');
100
+ expect(resolved.decision).toMatchObject({ category: 'hard', reason: 'routed', confidence: 0.97 });
103
101
  expect(events.at(-1)).toMatchObject({ type: 'openchamber:routing.decision', properties: { sessionId: 's1', category: 'hard' } });
104
102
  });
105
103
 
106
- it('rewrites the string sentinel the command route sends, keeping the string shape', async () => {
107
- const { runtime } = makeRuntime({ answers: { category: { choice: 'hard', confidence: 0.97 } } });
108
- const body = { model: 'openchamber/auto', command: 'review', arguments: '3650' };
109
- await runtime.resolvePromptBody(body, { sessionId: 's1' });
110
- expect(body.model).toBe('openai/gpt-6-astra');
111
- expect(body.agent).toBe('plan');
112
- });
113
-
114
- it('uses the fallback and keeps the composer agent when the category has no model', async () => {
104
+ it('uses the fallback pair and keeps the composer agent when the category has no model', async () => {
115
105
  const { runtime } = makeRuntime({ answers: { category: { choice: 'trivial', confidence: 0.99 } } });
116
- const body = { model: AUTO, variant: 'high', agent: 'build', parts: [{ type: 'text', text: 'fix typo' }] };
117
- await runtime.resolvePromptBody(body, { sessionId: 's1' });
118
- expect(body).toMatchObject({ model: FALLBACK.model, variant: 'medium', agent: 'build' });
106
+ const resolved = await runtime.resolveAutoSelection(send({ agent: 'build', requestText: 'fix typo' }));
107
+ expect(resolved.model).toEqual({ providerID: 'anthropic', id: 'claude-sonnet-5', variant: 'medium' });
108
+ expect(resolved.agent).toBe('build');
119
109
  });
120
110
 
121
111
  it('falls back on low confidence and on a Jev failure, and records why', async () => {
122
112
  const low = makeRuntime({ answers: { category: { choice: 'hard', confidence: 0.3 } } });
123
- const body = { model: AUTO, parts: [] };
124
- expect((await low.runtime.resolvePromptBody(body, { sessionId: 's1' })).reason).toBe('low-confidence');
125
- expect(body.model).toEqual(FALLBACK.model);
113
+ const lowResolved = await low.runtime.resolveAutoSelection(send());
114
+ expect(lowResolved.decision.reason).toBe('low-confidence');
115
+ expect(lowResolved.model).toMatchObject({ providerID: 'anthropic', id: 'claude-sonnet-5' });
126
116
 
127
117
  const failing = makeRuntime({ askError: Object.assign(new Error('Jev responded 401'), { status: 401 }) });
128
- const body2 = { model: AUTO, parts: [] };
129
- const decision = await failing.runtime.resolvePromptBody(body2, { sessionId: 's1' });
130
- expect(decision).toMatchObject({ reason: 'error', error: 'Jev responded 401' });
131
- expect(body2.model).toEqual(FALLBACK.model);
118
+ const resolved = await failing.runtime.resolveAutoSelection(send());
119
+ expect(resolved.decision).toMatchObject({ reason: 'error', error: 'Jev responded 401' });
120
+ expect(resolved.model).toMatchObject({ providerID: 'anthropic', id: 'claude-sonnet-5' });
132
121
  });
133
122
 
134
123
  it('falls back without asking Jev while Auto is not ready, and refuses without a fallback', async () => {
135
124
  const config = readyConfig();
136
125
  config.enabled = false;
137
126
  const notReady = makeRuntime({ config, answers: {} });
138
- const body = { model: AUTO, parts: [] };
139
- expect((await notReady.runtime.resolvePromptBody(body, { sessionId: 's1' })).reason).toBe('not-ready');
140
- expect(body.model).toEqual(FALLBACK.model);
127
+ const resolved = await notReady.runtime.resolveAutoSelection(send());
128
+ expect(resolved.decision.reason).toBe('not-ready');
129
+ expect(resolved.model).toMatchObject({ providerID: 'anthropic', id: 'claude-sonnet-5' });
141
130
  expect(notReady.jev.ask).not.toHaveBeenCalled();
142
131
 
143
132
  const noFallback = makeRuntime({ config: { ...readyConfig(), fallback: null }, answers: {} });
144
- await expect(noFallback.runtime.resolvePromptBody({ model: AUTO, parts: [] }, { sessionId: 's1' })).rejects.toMatchObject({ status: 400 });
133
+ await expect(noFallback.runtime.resolveAutoSelection(send())).rejects.toMatchObject({ status: 400 });
134
+ });
135
+ });
136
+
137
+ describe('jev endpoint', () => {
138
+ const capture = async (token) => {
139
+ let call = null;
140
+ const fetchImpl = async (url, init) => {
141
+ call = { url, init };
142
+ return { ok: true, status: 200, text: async () => JSON.stringify({ answers: {} }) };
143
+ };
144
+ await createJevClient({ fetchImpl }).ask({ state: 'x', questions: {} }, token);
145
+ return { url: call.url, headers: call.init.headers, body: JSON.parse(call.init.body) };
146
+ };
147
+
148
+ it('sends a saved key to TypeSafe and falls back to the free model zen serves without one', async () => {
149
+ const keyed = await capture('secret');
150
+ expect(keyed.url).toBe('https://api.typesafe.ai/v1/systemone');
151
+ expect(keyed.headers.authorization).toBe('Bearer secret');
152
+ expect(keyed.body.model).toBe('jev-latest');
153
+
154
+ const free = await capture(null);
155
+ expect(free.url).toBe('https://opencode.ai/zen/v1/systemone');
156
+ expect(free.headers.authorization).toBeUndefined();
157
+ // Zen counts our calls by this header, and does not know the `jev-latest` alias.
158
+ expect(free.headers['x-opencode-client']).toBe('openchamber');
159
+ expect(free.body.model).toBe('jev-1.13-free');
160
+ });
161
+ });
162
+
163
+ describe('auto sessions', () => {
164
+ it('remembers the sentinel selection and forgets it when a real model is chosen', () => {
165
+ const { runtime } = makeRuntime({ answers: {} });
166
+ expect(runtime.isAutoSession('s1')).toBe(false);
167
+ expect(runtime.noteModelSelection('s1', AUTO, '/repo')).toBe(true);
168
+ expect(runtime.isAutoSession('s1')).toBe(true);
169
+ expect(runtime.noteModelSelection('s1', { providerID: 'anthropic', id: 'claude-opus-5' }, '/repo')).toBe(false);
170
+ expect(runtime.isAutoSession('s1')).toBe(false);
145
171
  });
146
172
  });
147
173
 
@@ -165,24 +191,22 @@ describe('evaluatePermission', () => {
165
191
  expect(events.at(-1)).toMatchObject({ type: 'openchamber:routing.safety-skipped', properties: { permissionId: 'p1', error: 'Jev timed out after 4000ms' } });
166
192
  });
167
193
 
168
- it('accepts without asking when the safety net is off, the key is missing, or the flag is unset', async () => {
194
+ it('accepts without asking when the safety net is off', async () => {
169
195
  const off = readyConfig();
170
196
  off.safetyNet.enabled = false;
171
- for (const setup of [{ config: off }, { token: null }, { flag: '' }]) {
172
- const { runtime, jev } = makeRuntime({ ...setup, answers: {} });
173
- expect(await runtime.evaluatePermission(permission, '/repo')).toEqual({ action: 'accept' });
174
- expect(jev.ask).not.toHaveBeenCalled();
175
- }
197
+ const { runtime, jev } = makeRuntime({ config: off, answers: {} });
198
+ expect(await runtime.evaluatePermission(permission, '/repo')).toEqual({ action: 'accept' });
199
+ expect(jev.ask).not.toHaveBeenCalled();
176
200
  });
177
201
  });
178
202
 
179
203
  describe('describe', () => {
180
- it('reports Auto ready only with the flag, enabled config, key, fallback and two categories', async () => {
181
- expect((await makeRuntime({ answers: {} }).runtime.describe()).autoReady).toBe(true);
182
- expect((await makeRuntime({ token: null, answers: {} }).runtime.describe())).toMatchObject({ autoReady: false, tokenPresent: false });
204
+ it('reports Auto ready with an enabled config, a fallback and two categories, key or no key', async () => {
205
+ expect((await makeRuntime({ answers: {} }).runtime.describe())).toMatchObject({ autoReady: true, tokenPresent: true, jevSource: 'typesafe' });
206
+ // Without a key the free Jev model on zen answers, so Auto stays available.
207
+ expect((await makeRuntime({ token: null, answers: {} }).runtime.describe())).toMatchObject({ autoReady: true, tokenPresent: false, jevSource: 'zen-free' });
183
208
  const one = readyConfig();
184
209
  one.categories = one.categories.map((c, i) => ({ ...c, enabled: i === 0 }));
185
210
  expect((await makeRuntime({ config: one, answers: {} }).runtime.describe()).autoReady).toBe(false);
186
- expect(await makeRuntime({ flag: '', answers: {} }).runtime.describe()).toEqual({ available: false, autoReady: false, tokenPresent: false, config: null, builtins: [] });
187
211
  });
188
212
  });
@@ -188,3 +188,7 @@ project write lock on every `syncProject` when the project path is known:
188
188
  - `POST /api/projects/:projectId/scheduled-tasks/:taskId/run`
189
189
  - `GET /api/openchamber/scheduled-tasks/status`
190
190
  - `GET /api/openchamber/events`
191
+
192
+ The shared `/api/openchamber/events` stream also carries web notifications.
193
+ Its connection ownership and browser capability flag stay unchanged. Delivery
194
+ and duplicate handling are documented in `../notifications/DOCUMENTATION.md`.