@openchamber/web 1.24.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/bin/cli.test.js +22 -0
  2. package/bin/lib/commands-connect-url.js +3 -8
  3. package/bin/lib/commands-status.js +5 -0
  4. package/bin/lib/commands-tunnel.js +3 -0
  5. package/dist/assets/{CodeMirrorCommentWidgets-DvUH815P.js → CodeMirrorCommentWidgets-hJbl3JX4.js} +1 -1
  6. package/dist/assets/DiffView-BucGEJYa.js +4 -0
  7. package/dist/assets/FilesView-CQcaaAVP.js +17 -0
  8. package/dist/assets/{GitView-Bxuv3dfP.js → GitView-DY4pelsO.js} +4 -4
  9. package/dist/assets/{GuestAttachDialog-B0u3Q5uO.js → GuestAttachDialog-D6mHDTB2.js} +1 -1
  10. package/dist/assets/GuestSurfacePane--DJ7rsmY.js +1 -0
  11. package/dist/assets/{JsonTreeView-BBVPFM5K.js → JsonTreeView-DEXI2NvJ.js} +1 -1
  12. package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
  13. package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
  14. package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
  15. package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
  16. package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
  17. package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
  18. package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
  19. package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
  20. package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
  21. package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
  22. package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
  23. package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
  24. package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
  25. package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
  26. package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
  27. package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
  28. package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
  29. package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
  30. package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
  31. package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
  32. package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
  33. package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
  34. package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
  35. package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
  36. package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
  37. package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
  38. package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
  39. package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
  40. package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
  41. package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
  42. package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
  43. package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
  44. package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
  45. package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
  46. package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
  47. package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
  48. package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
  49. package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
  50. package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
  51. package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
  52. package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
  53. package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
  54. package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
  55. package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
  56. package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
  57. package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
  58. package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
  59. package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
  60. package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
  61. package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
  62. package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
  63. package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
  64. package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
  65. package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
  66. package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
  67. package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
  68. package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
  69. package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
  70. package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
  71. package/dist/assets/LinearIssuesView-BTNc-4dN.js +1 -0
  72. package/dist/assets/MarkdownImageGallery-wcUUcf8l.js +1 -0
  73. package/dist/assets/MarkdownRendererImpl-BPe2TVV2.js +12 -0
  74. package/dist/assets/OnboardingScreen-FJUreEgI.js +1 -0
  75. package/dist/assets/{PatchDiff-C4rE5k6z.js → PatchDiff-C0oOkKnO.js} +1 -1
  76. package/dist/assets/PierreDiffViewer-asuSQAsf.js +210 -0
  77. package/dist/assets/PlanView-DGbasNHP.js +5 -0
  78. package/dist/assets/PluginPane-DImv8hV2.js +3 -0
  79. package/dist/assets/SettingsView-DOjuOljf.js +29 -0
  80. package/dist/assets/SettingsWindow-By4cqnqy.js +1 -0
  81. package/dist/assets/SubmoduleDiffSummary-C0P2tXLU.js +1 -0
  82. package/dist/assets/ToolOutputDialog-Cayc-yIM.js +15 -0
  83. package/dist/assets/ToolPartDiffPreview-B0jmpPQz.js +8 -0
  84. package/dist/assets/{VirtualizedFileDiff-CZgXWHjU.js → VirtualizedFileDiff-DsOpvWZD.js} +4 -4
  85. package/dist/assets/{WalkthroughView-wSpED5L4.js → WalkthroughView-CCakjyn9.js} +2 -2
  86. package/dist/assets/appThemeRegistry-Bw5oTm41.js +1 -0
  87. package/dist/assets/{commitAndPush-DZnzlhvc.js → commitAndPush-sGEelpjh.js} +1 -1
  88. package/dist/assets/{computeVirtualFileMetrics-VYnT_A2h.js → computeVirtualFileMetrics-B-4aLf4A.js} +1 -1
  89. package/dist/assets/de-CD9utsNj.js +10 -0
  90. package/dist/assets/es-NNum2rX8.js +16 -0
  91. package/dist/assets/fr-CJLGmduQ.js +14 -0
  92. package/dist/assets/index-B6r0Kv-B.js +1 -0
  93. package/dist/assets/index-DjGPR5vW.js +41 -0
  94. package/dist/assets/index-fCXJ-8Qt.css +1 -0
  95. package/dist/assets/{isDiffPlainText-ImDG3Uhg.js → isDiffPlainText-Ok-kgtJA.js} +1 -1
  96. package/dist/assets/{isFilePlainText-D_YDVYDb.js → isFilePlainText-0dLnkYm8.js} +1 -1
  97. package/dist/assets/ja-BuddHNi6.js +16 -0
  98. package/dist/assets/ko-BrwMbHmf.js +16 -0
  99. package/dist/assets/main-CjXBM_Xe.js +2 -0
  100. package/dist/assets/main-CxVyUDU_.js +896 -0
  101. package/dist/assets/markdownCore-B6PpX409.js +5 -0
  102. package/dist/assets/miniChat-DZ3OAeLN.js +2 -0
  103. package/dist/assets/mobile-CH0LOIF-.js +2 -0
  104. package/dist/assets/{patchFileDiff-DDQ6Rq5e.js → patchFileDiff-BFRGKaGH.js} +3 -3
  105. package/dist/assets/pl-BwN4TNlP.js +16 -0
  106. package/dist/assets/pt-BR-BhMtownO.js +16 -0
  107. package/dist/assets/renderElectronMiniChatApp-CB1uLYvh.js +2 -0
  108. package/dist/assets/renderMobileApp-nQ4sjQtb.js +25 -0
  109. package/dist/assets/runtimeEndpointReset-9ZGlXU4J.js +27 -0
  110. package/dist/assets/scheduledTasksApi-6DsL_SwM.js +1 -0
  111. package/dist/assets/{shikiHighlight-1imXsir9.js → shikiHighlight-CocY80VR.js} +1 -1
  112. package/dist/assets/{textMateThemeFromAppTheme-Dgqc63LZ.js → textMateThemeFromAppTheme-CF77r8FA.js} +1 -1
  113. package/dist/assets/tr-DRzvqMdi.js +7 -0
  114. package/dist/assets/uk-b2aYOSNh.js +16 -0
  115. package/dist/assets/useAppFontEffects-Dc5nTHi8.js +7337 -0
  116. package/dist/assets/useInlineCommentController-Dbza5c8l.js +2 -0
  117. package/dist/assets/useRootScrollLock-CSCLv396.js +2 -0
  118. package/dist/assets/{vendor-codemirror-language-data-BDyxuqK4.js → vendor-codemirror-language-data-CkmYWcRI.js} +2 -2
  119. package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
  120. package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
  121. package/dist/assets/vendor-opencode-client-_BAHQo4R.js +12 -0
  122. package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
  123. package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-Gea9uBlY.js} +4 -4
  124. package/dist/assets/{web-components-D7FinaeH.js → web-components-nsStrYq9.js} +2 -2
  125. package/dist/assets/zh-CN-DZeUThm_.js +16 -0
  126. package/dist/assets/zh-TW-2fRE7uc6.js +16 -0
  127. package/dist/index.html +15 -7
  128. package/dist/mini-chat.html +7 -5
  129. package/dist/mobile.html +7 -5
  130. package/package.json +8 -7
  131. package/server/index.d.ts +1 -0
  132. package/server/index.js +248 -90
  133. package/server/lib/agent-tool/DOCUMENTATION.md +45 -15
  134. package/server/lib/agent-tool/runtime.js +189 -61
  135. package/server/lib/agent-tool/runtime.test.js +229 -75
  136. package/server/lib/browser-control/DOCUMENTATION.md +37 -2
  137. package/server/lib/browser-control/provider.js +217 -0
  138. package/server/lib/browser-control/provider.test.js +251 -0
  139. package/server/lib/context-obligatory/runtime.js +61 -50
  140. package/server/lib/context-obligatory/runtime.test.js +62 -162
  141. package/server/lib/event-stream/DOCUMENTATION.md +12 -1
  142. package/server/lib/event-stream/delta-coalescer.js +0 -0
  143. package/server/lib/event-stream/delta-coalescer.test.js +68 -57
  144. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  145. package/server/lib/event-stream/global-hub.js +10 -1
  146. package/server/lib/event-stream/global-hub.test.js +27 -26
  147. package/server/lib/event-stream/index.js +6 -0
  148. package/server/lib/event-stream/protocol.js +26 -19
  149. package/server/lib/event-stream/protocol.test.js +18 -7
  150. package/server/lib/event-stream/rebind.test.js +5 -5
  151. package/server/lib/event-stream/runtime.test.js +17 -15
  152. package/server/lib/event-stream/translate-v2.js +313 -0
  153. package/server/lib/event-stream/translate-v2.test.js +209 -0
  154. package/server/lib/event-stream/upstream-reader.test.js +16 -16
  155. package/server/lib/fs/DOCUMENTATION.md +6 -3
  156. package/server/lib/fs/byte-range.js +35 -0
  157. package/server/lib/fs/byte-range.test.js +31 -0
  158. package/server/lib/fs/routes.js +103 -46
  159. package/server/lib/fs/routes.test.js +239 -18
  160. package/server/lib/git/DOCUMENTATION.md +2 -2
  161. package/server/lib/git/service.js +106 -9
  162. package/server/lib/git/service.test.js +18 -0
  163. package/server/lib/github/DOCUMENTATION.md +1 -1
  164. package/server/lib/github/pr-status.js +22 -2
  165. package/server/lib/github/pr-status.test.js +27 -14
  166. package/server/lib/guests/DOCUMENTATION.md +13 -0
  167. package/server/lib/guests/catalog.js +12 -0
  168. package/server/lib/guests/catalog.test.js +33 -0
  169. package/server/lib/guests/routes.js +10 -1
  170. package/server/lib/guests/service.js +192 -14
  171. package/server/lib/guests/service.test.js +201 -1
  172. package/server/lib/guests/surface.js +630 -0
  173. package/server/lib/guests/surface.test.js +486 -0
  174. package/server/lib/markdown-image-grants/routes.js +18 -5
  175. package/server/lib/markdown-image-grants/routes.test.js +9 -6
  176. package/server/lib/message-queue/DOCUMENTATION.md +36 -22
  177. package/server/lib/message-queue/runtime.js +170 -100
  178. package/server/lib/message-queue/runtime.test.js +184 -82
  179. package/server/lib/notifications/DOCUMENTATION.md +28 -0
  180. package/server/lib/notifications/control-stream.http.test.js +68 -0
  181. package/server/lib/notifications/emitter-runtime.js +15 -0
  182. package/server/lib/notifications/emitter-runtime.test.js +32 -0
  183. package/server/lib/notifications/push-runtime.js +5 -1
  184. package/server/lib/notifications/push-runtime.test.js +2 -2
  185. package/server/lib/notifications/routes.js +5 -0
  186. package/server/lib/notifications/runtime.js +115 -26
  187. package/server/lib/notifications/template-runtime.js +13 -15
  188. package/server/lib/notifications/template-runtime.test.js +16 -9
  189. package/server/lib/notifications/trigger-runtime.test.js +187 -0
  190. package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
  191. package/server/lib/openchamber-control/actions.js +3 -2
  192. package/server/lib/openchamber-control/error.js +1 -1
  193. package/server/lib/openchamber-control/file-open.js +59 -0
  194. package/server/lib/openchamber-control/file-open.test.js +57 -0
  195. package/server/lib/openchamber-control/routes.test.js +12 -0
  196. package/server/lib/openchamber-control/service.js +102 -49
  197. package/server/lib/openchamber-control/service.test.js +84 -44
  198. package/server/lib/openchamber-sessions/archive-store.js +224 -0
  199. package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
  200. package/server/lib/openchamber-sessions/opencode-client.js +22 -0
  201. package/server/lib/openchamber-sessions/routes.js +398 -328
  202. package/server/lib/openchamber-sessions/routes.test.js +786 -700
  203. package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
  204. package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
  205. package/server/lib/opencode/DOCUMENTATION.md +450 -30
  206. package/server/lib/opencode/agents.js +233 -327
  207. package/server/lib/opencode/auth.js +41 -44
  208. package/server/lib/opencode/auth.test.js +92 -0
  209. package/server/lib/opencode/bootstrap-runtime.js +1 -0
  210. package/server/lib/opencode/cli-upgrade.d.ts +4 -0
  211. package/server/lib/opencode/cli-upgrade.js +18 -0
  212. package/server/lib/opencode/cli-upgrade.test.js +36 -0
  213. package/server/lib/opencode/commands.js +164 -145
  214. package/server/lib/opencode/compatibility.d.ts +16 -0
  215. package/server/lib/opencode/compatibility.js +88 -0
  216. package/server/lib/opencode/compatibility.test.js +62 -0
  217. package/server/lib/opencode/config-entity-routes.js +58 -29
  218. package/server/lib/opencode/config-entity-v2.test.js +290 -0
  219. package/server/lib/opencode/config-mutation-response.js +17 -7
  220. package/server/lib/opencode/config-mutation-response.test.js +4 -7
  221. package/server/lib/opencode/config-paths.test.js +2 -2
  222. package/server/lib/opencode/config-v2.d.ts +183 -0
  223. package/server/lib/opencode/config-v2.js +801 -0
  224. package/server/lib/opencode/config-v2.test.js +466 -0
  225. package/server/lib/opencode/credential-db.js +144 -0
  226. package/server/lib/opencode/credential-db.test.js +104 -0
  227. package/server/lib/opencode/env-runtime.js +48 -9
  228. package/server/lib/opencode/env-runtime.test.js +45 -0
  229. package/server/lib/opencode/feature-routes-runtime.js +15 -5
  230. package/server/lib/opencode/lifecycle-process.test.js +7 -4
  231. package/server/lib/opencode/lifecycle.js +85 -30
  232. package/server/lib/opencode/lifecycle.test.js +80 -8
  233. package/server/lib/opencode/login-shell-env.js +27 -0
  234. package/server/lib/opencode/managed-config-file.js +119 -0
  235. package/server/lib/opencode/managed-config-file.test.js +152 -0
  236. package/server/lib/opencode/managed-plugin-config.js +33 -13
  237. package/server/lib/opencode/mcp.js +43 -149
  238. package/server/lib/opencode/network-runtime.js +6 -7
  239. package/server/lib/opencode/openchamber-routes.test.js +0 -1
  240. package/server/lib/opencode/plugin-routes.js +3 -3
  241. package/server/lib/opencode/plugin-routes.test.js +6 -24
  242. package/server/lib/opencode/plugins.js +91 -40
  243. package/server/lib/opencode/plugins.test.js +28 -15
  244. package/server/lib/opencode/providers.js +63 -83
  245. package/server/lib/opencode/providers.test.js +128 -59
  246. package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
  247. package/server/lib/opencode/proxy.js +179 -129
  248. package/server/lib/opencode/pwa-manifest-routes.js +4 -2
  249. package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
  250. package/server/lib/opencode/response-envelope.js +14 -0
  251. package/server/lib/opencode/response-envelope.test.js +23 -0
  252. package/server/lib/opencode/routes-upgrade.test.js +73 -116
  253. package/server/lib/opencode/routes.js +121 -428
  254. package/server/lib/opencode/server-utils-runtime.js +10 -4
  255. package/server/lib/opencode/session-activity.js +78 -0
  256. package/server/lib/opencode/session-runtime.js +79 -0
  257. package/server/lib/opencode/session-runtime.test.js +43 -0
  258. package/server/lib/opencode/settings-helpers.js +9 -9
  259. package/server/lib/opencode/settings-helpers.test.js +7 -12
  260. package/server/lib/opencode/settings-registry.json +6 -8
  261. package/server/lib/opencode/settings-runtime.js +18 -1
  262. package/server/lib/opencode/settings-runtime.test.js +31 -2
  263. package/server/lib/opencode/shared.js +54 -22
  264. package/server/lib/opencode/shared.test.js +8 -4
  265. package/server/lib/opencode/shutdown-runtime.js +54 -7
  266. package/server/lib/opencode/shutdown-runtime.test.js +224 -30
  267. package/server/lib/opencode/skill-routes.js +23 -24
  268. package/server/lib/opencode/skills.js +7 -5
  269. package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
  270. package/server/lib/opencode/upgrade-capability.test.js +1 -1
  271. package/server/lib/opencode/v1-migration-topup.js +288 -0
  272. package/server/lib/opencode/v1-migration-topup.test.js +266 -0
  273. package/server/lib/opencode/v2-install.d.ts +8 -0
  274. package/server/lib/opencode/v2-install.js +158 -0
  275. package/server/lib/opencode/v2-install.test.js +124 -0
  276. package/server/lib/opencode/watcher.js +10 -3
  277. package/server/lib/opencode/watcher.test.js +17 -21
  278. package/server/lib/opencode/websearch-config.js +66 -0
  279. package/server/lib/permission-auto-accept/runtime.js +38 -22
  280. package/server/lib/permission-auto-accept/runtime.test.js +39 -17
  281. package/server/lib/projects/project-config.js +2 -2
  282. package/server/lib/quota/DOCUMENTATION.md +4 -0
  283. package/server/lib/quota/providers/xai.js +4 -4
  284. package/server/lib/realtime-proxy-terminal.test.js +150 -0
  285. package/server/lib/realtime-proxy.js +2 -0
  286. package/server/lib/relay/tunnel-host.js +4 -1
  287. package/server/lib/relay/tunnel-host.test.js +7 -0
  288. package/server/lib/routing/DOCUMENTATION.md +52 -19
  289. package/server/lib/routing/defaults.js +23 -6
  290. package/server/lib/routing/jev.js +17 -7
  291. package/server/lib/routing/routes.http.test.js +68 -33
  292. package/server/lib/routing/routes.js +65 -22
  293. package/server/lib/routing/runtime.js +145 -48
  294. package/server/lib/routing/runtime.test.js +79 -55
  295. package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
  296. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
  297. package/server/lib/scheduled-tasks/runtime.js +83 -76
  298. package/server/lib/scheduled-tasks/runtime.test.js +67 -1
  299. package/server/lib/session-assist/DOCUMENTATION.md +8 -3
  300. package/server/lib/session-assist/context.js +122 -46
  301. package/server/lib/session-assist/context.test.js +117 -49
  302. package/server/lib/session-assist/runtime.js +52 -22
  303. package/server/lib/session-assist/runtime.test.js +145 -173
  304. package/server/lib/session-goal/DOCUMENTATION.md +23 -15
  305. package/server/lib/session-goal/create.js +9 -12
  306. package/server/lib/session-goal/create.test.js +27 -28
  307. package/server/lib/session-goal/runtime.js +164 -77
  308. package/server/lib/session-goal/runtime.test.js +271 -519
  309. package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
  310. package/server/lib/session-knowledge/runtime.js +59 -41
  311. package/server/lib/session-knowledge/runtime.test.js +90 -20
  312. package/server/lib/small-model/DOCUMENTATION.md +154 -196
  313. package/server/lib/small-model/client.js +113 -0
  314. package/server/lib/small-model/index.js +296 -158
  315. package/server/lib/small-model/index.test.js +423 -256
  316. package/server/lib/small-model/routes.js +1 -1
  317. package/server/lib/spaces/DOCUMENTATION.md +807 -0
  318. package/server/lib/spaces/code-in-bait.js +185 -0
  319. package/server/lib/spaces/code-in.js +641 -0
  320. package/server/lib/spaces/code-in.test.js +1048 -0
  321. package/server/lib/spaces/errors.js +8 -0
  322. package/server/lib/spaces/exec-http.js +94 -0
  323. package/server/lib/spaces/gatekeeper-channel.js +202 -0
  324. package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
  325. package/server/lib/spaces/gatekeeper-program.cjs +914 -0
  326. package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
  327. package/server/lib/spaces/hardening.js +457 -0
  328. package/server/lib/spaces/hardening.test.js +368 -0
  329. package/server/lib/spaces/host-git.js +127 -0
  330. package/server/lib/spaces/host-git.test.js +137 -0
  331. package/server/lib/spaces/labels.js +234 -0
  332. package/server/lib/spaces/labels.test.js +219 -0
  333. package/server/lib/spaces/layout.js +184 -0
  334. package/server/lib/spaces/layout.test.js +30 -0
  335. package/server/lib/spaces/manager.js +82 -0
  336. package/server/lib/spaces/manager.test.js +114 -0
  337. package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
  338. package/server/lib/spaces/places/contract-suite.js +156 -0
  339. package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
  340. package/server/lib/spaces/places/contract.test.js +6 -0
  341. package/server/lib/spaces/places/docker-engine.js +126 -0
  342. package/server/lib/spaces/places/docker-live-support.js +202 -0
  343. package/server/lib/spaces/places/docker-tools.js +186 -0
  344. package/server/lib/spaces/places/docker.js +587 -0
  345. package/server/lib/spaces/places/docker.test.js +1610 -0
  346. package/server/lib/spaces/places/escape-suite.js +1018 -0
  347. package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
  348. package/server/lib/spaces/places/fake-docker.js +375 -0
  349. package/server/lib/spaces/places/memory-place.js +103 -0
  350. package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
  351. package/server/lib/spaces/places/registry.js +43 -0
  352. package/server/lib/spaces/places/registry.test.js +50 -0
  353. package/server/lib/spaces/places/server.docker.live.test.js +225 -0
  354. package/server/lib/spaces/run-command.js +261 -0
  355. package/server/lib/spaces/run-command.test.js +396 -0
  356. package/server/lib/spaces/space-server.js +190 -0
  357. package/server/lib/spaces/space-server.test.js +335 -0
  358. package/server/lib/spaces/tools-filler.js +82 -0
  359. package/server/lib/spaces/tools-filler.test.js +148 -0
  360. package/server/lib/spaces/tools-pack.js +49 -0
  361. package/server/lib/spaces/tools-pack.test.js +57 -0
  362. package/server/lib/spaces/tools.js +137 -0
  363. package/server/lib/spaces/tools.test.js +153 -0
  364. package/server/lib/terminal/DOCUMENTATION.md +21 -2
  365. package/server/lib/terminal/runtime.js +10 -3
  366. package/server/lib/terminal/runtime.test.js +22 -0
  367. package/server/lib/terminal/shutdown.js +106 -0
  368. package/server/lib/terminal/shutdown.test.js +84 -0
  369. package/server/lib/tts/openai-sdk.js +11 -0
  370. package/server/lib/tts/service.js +7 -5
  371. package/server/lib/tts/service.test.js +78 -0
  372. package/server/lib/tts/stt.js +3 -2
  373. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  374. package/server/lib/tunnels/routes.js +7 -0
  375. package/server/lib/tunnels/routes.test.js +55 -0
  376. package/server/lib/ui-auth/ui-auth.js +38 -2
  377. package/server/lib/ui-auth/ui-auth.test.js +42 -0
  378. package/server/lib/ui-auth/ui-passkeys.js +12 -10
  379. package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
  380. package/server/lib/walkthrough/pull-request.js +61 -8
  381. package/server/lib/walkthrough/pull-request.test.js +54 -1
  382. package/server/lib/walkthrough/routes.js +20 -0
  383. package/server/lib/walkthrough/routes.test.js +19 -0
  384. package/server/opencode-proxy.test.js +190 -166
  385. package/server/opencode-worktree-readiness.test.js +5 -4
  386. package/dist/assets/DiffView-DkC3xlRJ.js +0 -4
  387. package/dist/assets/FilesView-D0bM9FVB.js +0 -13
  388. package/dist/assets/LinearIssuesView-UI1FcSC8.js +0 -1
  389. package/dist/assets/MarkdownImageGallery-CUJxH8Le.js +0 -1
  390. package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +0 -12
  391. package/dist/assets/OnboardingScreen-5Gou9cGD.js +0 -1
  392. package/dist/assets/PierreDiffViewer-ByRVu6ss.js +0 -161
  393. package/dist/assets/PlanView-u2yi5XGJ.js +0 -5
  394. package/dist/assets/PluginPane-QxjsKYeO.js +0 -3
  395. package/dist/assets/SettingsView-Fo5ZqMaT.js +0 -29
  396. package/dist/assets/SettingsWindow-HVDVANjJ.js +0 -1
  397. package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +0 -1
  398. package/dist/assets/ToolOutputDialog-3J6IRayW.js +0 -15
  399. package/dist/assets/ToolPartDiffPreview-DarxPjSd.js +0 -8
  400. package/dist/assets/appThemeRegistry-Cf8KitzT.js +0 -1
  401. package/dist/assets/de-BM_8EDD3.js +0 -10
  402. package/dist/assets/es-CxZjlqpo.js +0 -16
  403. package/dist/assets/fr-VCixCnMW.js +0 -14
  404. package/dist/assets/index-3U4CtS9b.js +0 -1
  405. package/dist/assets/index-B9Hvzjwl.css +0 -1
  406. package/dist/assets/index-DLHQogv8.js +0 -40
  407. package/dist/assets/ja-CZ5k_GyD.js +0 -16
  408. package/dist/assets/ko-7YM3A1Xh.js +0 -16
  409. package/dist/assets/main-CycplCph.js +0 -2
  410. package/dist/assets/main-DFYTCx5o.js +0 -896
  411. package/dist/assets/markdownCore-DHvqMxPn.js +0 -5
  412. package/dist/assets/miniChat-DIQKfY2V.js +0 -2
  413. package/dist/assets/mobile-BMwz5q-m.js +0 -2
  414. package/dist/assets/pl-BcgDO_w5.js +0 -16
  415. package/dist/assets/pt-BR-CU2u_1q5.js +0 -16
  416. package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +0 -2
  417. package/dist/assets/renderMobileApp-D0Y8DtkA.js +0 -25
  418. package/dist/assets/runtimeEndpointReset-DhC3REb2.js +0 -25
  419. package/dist/assets/scheduledTasksApi-D8pq6gQz.js +0 -1
  420. package/dist/assets/tr-DuYhOzNe.js +0 -7
  421. package/dist/assets/uk-Cuk7-uvq.js +0 -16
  422. package/dist/assets/useAppFontEffects-BItUWdo4.js +0 -7333
  423. package/dist/assets/useInlineCommentController-CkbKsm7m.js +0 -2
  424. package/dist/assets/useRootScrollLock-vmzxZjWA.js +0 -2
  425. package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
  426. package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
  427. package/dist/assets/zh-CN-CUWoiRHd.js +0 -16
  428. package/dist/assets/zh-TW-CQ8EBSBN.js +0 -16
  429. package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
  430. package/server/lib/routing/feature-flag.js +0 -11
  431. package/server/lib/small-model/call.js +0 -820
  432. package/server/lib/small-model/call.test.js +0 -1110
  433. package/server/lib/small-model/catalog.js +0 -13
  434. package/server/lib/small-model/resolve.js +0 -131
  435. package/server/lib/small-model/resolve.test.js +0 -197
  436. package/server/lib/small-model/runtime-providers.js +0 -164
  437. package/server/lib/small-model/runtime-providers.test.js +0 -118
  438. package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
  439. package/server/lib/system-prompt/runtime.js +0 -49
  440. package/server/lib/system-prompt/runtime.test.js +0 -76
  441. package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
  442. /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
@@ -33,12 +33,19 @@ afterEach(() => {
33
33
  */
34
34
  const createOpenCode = () => {
35
35
  const state = {
36
- statuses: {},
36
+ // `/api/session/active` lists only running sessions; an absent id is idle.
37
+ active: {},
38
+ // Subagent sessions per parent, as `GET /api/session?parentID=` lists them.
39
+ children: {},
37
40
  tail: [],
38
41
  commands: [],
39
42
  sent: [],
43
+ switched: [],
40
44
  failNext: null,
41
45
  };
46
+ // v2 wraps `/api/*` payloads in `{ location, data }`; a message page is
47
+ // `{ data, cursor }` and lists newest first.
48
+ const wrapped = (data) => Response.json({ location: { directory: DIRECTORY }, data });
42
49
  const fetchImpl = vi.fn(async (url, init = {}) => {
43
50
  const { pathname } = new URL(url);
44
51
  const method = init.method ?? 'GET';
@@ -46,19 +53,29 @@ const createOpenCode = () => {
46
53
  state.failNext = null;
47
54
  return new Response('boom', { status: 500 });
48
55
  }
49
- if (pathname === '/session/status') return Response.json(state.statuses);
50
- if (pathname.endsWith('/message')) return Response.json(state.tail);
51
- if (pathname === '/command') return Response.json(state.commands);
52
- if (method === 'POST' && (pathname.endsWith('/prompt_async') || pathname.endsWith('/command'))) {
53
- state.sent.push({ path: pathname, body: JSON.parse(init.body) });
56
+ // Real shape: `{ data }` without a `location`, unlike directory-scoped routes.
57
+ if (pathname === '/api/session/active') return Response.json({ data: state.active });
58
+ if (pathname === '/api/session' && method === 'GET') {
59
+ const parentID = new URL(url).searchParams.get('parentID');
60
+ return Response.json({ data: (state.children[parentID] ?? []).map((id) => ({ id, parentID })), cursor: {} });
61
+ }
62
+ if (pathname.endsWith('/message')) return Response.json({ data: state.tail, cursor: {} });
63
+ if (pathname === '/api/command') return wrapped(state.commands);
64
+ if (method === 'POST' && (pathname.endsWith('/model') || pathname.endsWith('/agent'))) {
65
+ // Kept apart from `sent`: switching the session is not a message.
66
+ state.switched.push({ path: pathname, body: JSON.parse(init.body) });
54
67
  return new Response(null, { status: 204 });
55
68
  }
69
+ if (method === 'POST' && (pathname.endsWith('/prompt') || pathname.endsWith('/command') || pathname.endsWith('/synthetic'))) {
70
+ state.sent.push({ path: pathname, body: JSON.parse(init.body) });
71
+ return wrapped({ id: `msg_${state.sent.length}` });
72
+ }
56
73
  return new Response('not found', { status: 404 });
57
74
  });
58
75
  return { state, fetchImpl };
59
76
  };
60
77
 
61
- const createRuntime = ({ dataDir = makeDataDir(), openCode = createOpenCode(), knowledge = null, retryDelayMs, resolvePromptBody } = {}) => {
78
+ const createRuntime = ({ dataDir = makeDataDir(), openCode = createOpenCode(), knowledge = null, retryDelayMs, resolveAutoSelection, now } = {}) => {
62
79
  let eventHandler = () => {};
63
80
  let statusHandler = () => {};
64
81
  const broadcasts = [];
@@ -79,7 +96,8 @@ const createRuntime = ({ dataDir = makeDataDir(), openCode = createOpenCode(), k
79
96
  abortHoldMs: 50,
80
97
  };
81
98
  if (retryDelayMs) options.retryDelayMs = retryDelayMs;
82
- if (resolvePromptBody) options.resolvePromptBody = resolvePromptBody;
99
+ if (resolveAutoSelection) options.resolveAutoSelection = resolveAutoSelection;
100
+ if (now) options.now = now;
83
101
  const runtime = createMessageQueueRuntime(options);
84
102
  return {
85
103
  runtime,
@@ -87,7 +105,8 @@ const createRuntime = ({ dataDir = makeDataDir(), openCode = createOpenCode(), k
87
105
  dataDir,
88
106
  broadcasts,
89
107
  promptSent,
90
- emit: (payload, directory = DIRECTORY) => eventHandler({ payload, directory }),
108
+ // The hub hands server-side subscribers already-translated events.
109
+ emit: (payload, directory = DIRECTORY) => eventHandler({ payload, directory, translated: () => [payload] }),
91
110
  connect: () => statusHandler({ type: 'connect' }),
92
111
  };
93
112
  };
@@ -97,13 +116,11 @@ const settle = async (ms = 30) => {
97
116
  };
98
117
 
99
118
  describe('auto routing', () => {
100
- it('lets the routing hook rewrite the model of a queued prompt and a queued command', async () => {
101
- const resolvePromptBody = vi.fn(async (body) => {
102
- if (body.model?.modelID === 'auto') body.model = { providerID: 'openai', modelID: 'gpt-6-astra' };
103
- if (body.model === 'openchamber/auto') body.model = 'openai/gpt-6-astra';
104
- return null;
105
- });
106
- const { runtime, openCode, emit } = createRuntime({ resolvePromptBody });
119
+ it('switches a queued prompt and a queued command onto the routed model and agent', async () => {
120
+ const resolveAutoSelection = vi.fn(async ({ model }) => (model?.id === 'auto'
121
+ ? { model: { providerID: 'openai', id: 'gpt-6-astra' }, agent: 'plan', decision: {} }
122
+ : null));
123
+ const { runtime, openCode, emit } = createRuntime({ resolveAutoSelection });
107
124
  runtime.start();
108
125
  openCode.state.statuses = { [SESSION]: { type: 'busy' } };
109
126
  openCode.state.commands = [{ name: 'review', template: 'Review $ARGUMENTS' }];
@@ -117,12 +134,16 @@ describe('auto routing', () => {
117
134
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
118
135
  await settle();
119
136
 
120
- expect(openCode.state.sent.map((entry) => entry.body.model)).toEqual([
121
- { providerID: 'openai', modelID: 'gpt-6-astra' },
122
- 'openai/gpt-6-astra',
137
+ // v2 carries no model in a prompt body: the session is switched first.
138
+ const switched = openCode.state.switched.filter((entry) => entry.path.endsWith('/model'));
139
+ expect(switched.map((entry) => entry.body.model)).toEqual([
140
+ { providerID: 'openai', id: 'gpt-6-astra' },
141
+ { providerID: 'openai', id: 'gpt-6-astra' },
123
142
  ]);
124
- expect(resolvePromptBody).toHaveBeenCalledTimes(2);
125
- expect(resolvePromptBody.mock.calls[0][1]).toEqual({ sessionId: SESSION, directory: DIRECTORY });
143
+ expect(openCode.state.switched.filter((entry) => entry.path.endsWith('/agent')).map((entry) => entry.body.agent))
144
+ .toEqual(['plan', 'plan']);
145
+ expect(resolveAutoSelection).toHaveBeenCalledTimes(2);
146
+ expect(resolveAutoSelection.mock.calls[0][0]).toMatchObject({ sessionId: SESSION, directory: DIRECTORY, requestText: 'plain' });
126
147
  });
127
148
  });
128
149
 
@@ -171,24 +192,22 @@ describe('message queue runtime', () => {
171
192
  it('delivers the head of the queue when the session goes idle, in order', async () => {
172
193
  const { runtime, openCode, emit, promptSent, broadcasts } = createRuntime();
173
194
  runtime.start();
174
- openCode.state.statuses = { [SESSION]: { type: 'busy' } };
195
+ openCode.state.active = { [SESSION]: { type: 'running' } };
175
196
 
176
197
  await runtime.enqueue(SESSION, DIRECTORY, item({ content: 'first', text: 'first' }));
177
198
  await runtime.enqueue(SESSION, DIRECTORY, item({ content: 'second', text: 'second' }));
178
199
  await settle();
179
200
  expect(openCode.state.sent).toHaveLength(0);
180
201
 
181
- openCode.state.statuses = {};
202
+ openCode.state.active = {};
182
203
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
183
204
  await settle();
184
205
 
185
206
  expect(openCode.state.sent).toHaveLength(1);
186
- expect(openCode.state.sent[0].path).toBe(`/session/${SESSION}/prompt_async`);
187
- expect(openCode.state.sent[0].body).toEqual({
188
- model: { providerID: 'anthropic', modelID: 'claude' },
189
- agent: 'build',
190
- parts: [{ type: 'text', text: 'first' }],
191
- });
207
+ expect(openCode.state.sent[0].path).toBe(`/api/session/${SESSION}/prompt`);
208
+ // v2 selects model and agent on the session, so the prompt carries text
209
+ // and attachments only.
210
+ expect(openCode.state.sent[0].body).toEqual({ text: 'first' });
192
211
  expect(promptSent).toEqual([SESSION]);
193
212
  expect(runtime.sessionSnapshot(SESSION).items.map((entry) => entry.content)).toEqual(['second']);
194
213
  // Clients learned about the in-flight item and then the removal.
@@ -205,10 +224,32 @@ describe('message queue runtime', () => {
205
224
  expect(runtime.sessionSnapshot(SESSION).items).toEqual([]);
206
225
  });
207
226
 
208
- it('does not send into a running turn even when the status event says idle', async () => {
227
+ it('waits for a background subagent before sending the queued message', async () => {
209
228
  const { runtime, openCode, emit } = createRuntime();
210
229
  runtime.start();
211
- openCode.state.tail = [{ info: { role: 'assistant', time: { created: 1 } } }];
230
+ // The parent paused: it is idle while its background subagent works.
231
+ openCode.state.children = { [SESSION]: ['ses_child'] };
232
+ openCode.state.active = { ses_child: { type: 'running' } };
233
+
234
+ await runtime.enqueue(SESSION, DIRECTORY, item({ content: 'next', text: 'next' }));
235
+ emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
236
+ await settle();
237
+ expect(openCode.state.sent).toHaveLength(0);
238
+
239
+ // The subagent finished and OpenCode ran the parent again with its result.
240
+ openCode.state.active = {};
241
+ emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'busy' } } });
242
+ emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
243
+ await settle();
244
+ expect(openCode.state.sent).toHaveLength(1);
245
+ expect(openCode.state.sent[0].body).toEqual({ text: 'next' });
246
+ });
247
+
248
+ it('does not send into a running turn even when the status event says idle', async () => {
249
+ const { runtime, openCode, emit } = createRuntime({ now: () => 10_000 });
250
+ runtime.start();
251
+ // Live unfinished turn: created after this runtime started.
252
+ openCode.state.tail = [{ type: 'assistant', time: { created: 10_001 } }];
212
253
  await runtime.enqueue(SESSION, DIRECTORY, item());
213
254
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
214
255
  await settle();
@@ -216,17 +257,31 @@ describe('message queue runtime', () => {
216
257
 
217
258
  // The reply completes: that alone drains the queue (a missed idle event
218
259
  // must not strand it).
219
- openCode.state.tail = [{ info: { role: 'assistant', time: { created: 1, completed: 2 } } }];
220
- emit({ type: 'message.updated', properties: { info: { role: 'assistant', sessionID: SESSION, time: { created: 1, completed: 2 } } } });
260
+ openCode.state.tail = [{ type: 'assistant', time: { created: 10_001, completed: 10_002 } }];
261
+ emit({ type: 'message.updated', properties: { info: { role: 'assistant', sessionID: SESSION, time: { created: 10_001, completed: 10_002 } } } });
262
+ await settle();
263
+ expect(openCode.state.sent).toHaveLength(1);
264
+ });
265
+
266
+ it('delivers past an unfinished tail that predates this runtime (dead pre-restart run)', async () => {
267
+ const { runtime, openCode, emit } = createRuntime({ now: () => 10_000 });
268
+ runtime.start();
269
+ // Assistant reply interrupted by a server restart: unfinished, but older
270
+ // than this runtime — no completion event will ever arrive for it, so it
271
+ // must not block a restored queue forever.
272
+ openCode.state.tail = [{ type: 'assistant', time: { created: 1 } }];
273
+ await runtime.enqueue(SESSION, DIRECTORY, item());
274
+ emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
221
275
  await settle();
222
276
  expect(openCode.state.sent).toHaveLength(1);
277
+ expect(openCode.state.sent[0].path).toBe(`/api/session/${SESSION}/prompt`);
223
278
  });
224
279
 
225
280
  it('treats an unreachable OpenCode as unknown, not idle', async () => {
226
281
  const { runtime, openCode, emit } = createRuntime({ retryDelayMs: () => 10 });
227
282
  runtime.start();
228
283
  await runtime.enqueue(SESSION, DIRECTORY, item());
229
- openCode.state.failNext = /\/session\/status$/;
284
+ openCode.state.failNext = /\/api\/session\/active$/;
230
285
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
231
286
  await settle(5);
232
287
  expect(openCode.state.sent).toHaveLength(0);
@@ -239,7 +294,7 @@ describe('message queue runtime', () => {
239
294
  const { runtime, openCode, emit, broadcasts } = createRuntime({ retryDelayMs: () => 20 });
240
295
  runtime.start();
241
296
  await runtime.enqueue(SESSION, DIRECTORY, item());
242
- openCode.state.failNext = /prompt_async$/;
297
+ openCode.state.failNext = /\/prompt$/;
243
298
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
244
299
  await settle(10);
245
300
  expect(openCode.state.sent).toHaveLength(0);
@@ -255,8 +310,10 @@ describe('message queue runtime', () => {
255
310
  const { runtime, openCode, emit } = createRuntime();
256
311
  runtime.start();
257
312
  await runtime.enqueue(SESSION, DIRECTORY, item());
258
- emit({ type: 'message.updated', properties: { info: { role: 'assistant', sessionID: SESSION, error: { name: 'MessageAbortedError' } } } });
313
+ // v2 reports a user abort as `session.execution.interrupted`, which the
314
+ // translator turns into an aborted `session.idle`.
259
315
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
316
+ emit({ type: 'session.idle', properties: { sessionID: SESSION, aborted: true, reason: 'user' } });
260
317
  await settle(10);
261
318
  expect(openCode.state.sent).toHaveLength(0);
262
319
  await settle(80);
@@ -281,7 +338,7 @@ describe('message queue runtime', () => {
281
338
  const dataDir = makeDataDir();
282
339
  const first = createRuntime({ dataDir });
283
340
  first.runtime.start();
284
- first.openCode.state.statuses = { [SESSION]: { type: 'busy' } };
341
+ first.openCode.state.active = { [SESSION]: { type: 'running' } };
285
342
  await first.runtime.enqueue(SESSION, DIRECTORY, item({ content: 'persisted', text: 'persisted', contextPreview: 'Saved context preview' }));
286
343
  await first.runtime.flush();
287
344
  first.runtime.stop();
@@ -294,7 +351,7 @@ describe('message queue runtime', () => {
294
351
  second.connect();
295
352
  await settle();
296
353
  expect(second.openCode.state.sent).toHaveLength(1);
297
- expect(second.openCode.state.sent[0].body.parts).toEqual([{ type: 'text', text: 'persisted' }]);
354
+ expect(second.openCode.state.sent[0].body).toEqual({ text: 'persisted' });
298
355
  });
299
356
 
300
357
  it('moves an unreadable queue file aside instead of treating it as empty', async () => {
@@ -310,9 +367,13 @@ describe('message queue runtime', () => {
310
367
  const { runtime, openCode, emit } = createRuntime();
311
368
  runtime.start();
312
369
  let release;
313
- // status map, message tail, then the prompt itself (held open until released)
314
- openCode.fetchImpl.mockImplementationOnce(async () => Response.json({}))
315
- .mockImplementationOnce(async () => Response.json([]))
370
+ // active map, message tail, the subagent check (active map, children),
371
+ // model switch, then the prompt itself (held open until released)
372
+ openCode.fetchImpl.mockImplementationOnce(async () => Response.json({ location: {}, data: {} }))
373
+ .mockImplementationOnce(async () => Response.json({ data: [], cursor: {} }))
374
+ .mockImplementationOnce(async () => Response.json({ data: {} }))
375
+ .mockImplementationOnce(async () => Response.json({ data: [], cursor: {} }))
376
+ .mockImplementationOnce(async () => new Response(null, { status: 204 }))
316
377
  .mockImplementationOnce(() => new Promise((resolve) => { release = () => resolve(new Response(null, { status: 204 })); }));
317
378
  const { itemId } = await runtime.enqueue(SESSION, DIRECTORY, item());
318
379
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
@@ -382,7 +443,7 @@ describe('message queue runtime', () => {
382
443
  const { runtime, emit, broadcasts, openCode } = createRuntime();
383
444
  runtime.start();
384
445
  await runtime.enqueue(SESSION, DIRECTORY, item());
385
- openCode.state.statuses = {};
446
+ openCode.state.active = {};
386
447
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
387
448
  await settle();
388
449
 
@@ -418,11 +479,12 @@ describe('message queue runtime', () => {
418
479
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
419
480
  await settle();
420
481
  expect(openCode.state.sent).toHaveLength(1);
421
- expect(openCode.state.sent[0].path).toBe(`/session/${SESSION}/command`);
422
- expect(openCode.state.sent[0].body).toEqual({ command: 'review', arguments: 'src', model: 'p/m', agent: 'build', variant: 'max' });
482
+ expect(openCode.state.sent[0].path).toBe(`/api/session/${SESSION}/command`);
483
+ // v2's command route takes `text`, and the selection lives on the session.
484
+ expect(openCode.state.sent[0].body).toEqual({ name: 'review', text: 'src' });
423
485
  });
424
486
 
425
- it('delivers captured context as synthetic parts, instructions first, before project knowledge', async () => {
487
+ it('delivers captured context as synthetic messages, instructions first, before project knowledge', async () => {
426
488
  const knowledge = {
427
489
  resolvePendingForSession: async () => ({ text: 'pinned notes', signature: 'sig-1' }),
428
490
  recordDelivered: async () => {},
@@ -441,16 +503,29 @@ describe('message queue runtime', () => {
441
503
  }));
442
504
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
443
505
  await settle();
444
- expect(openCode.state.sent[0].body.parts).toEqual([
445
- { type: 'text', text: 'follow up' },
446
- { type: 'file', mime: 'text/plain', filename: 'f.txt', url: 'data:text/plain,hi' },
447
- { type: 'text', text: 'how to read it', synthetic: true },
448
- { type: 'text', text: 'the diff', synthetic: true, metadata },
449
- { type: 'text', text: 'conflict payload', synthetic: true },
450
- { type: 'text', text: 'use the skill', synthetic: true },
451
- { type: 'text', text: 'pinned notes', synthetic: true },
452
- { type: 'agent', name: 'reviewer' },
506
+
507
+ // v2 has no inline synthetic parts: everything attached to the message is
508
+ // admitted as its own synthetic message, before the prompt.
509
+ expect(openCode.state.sent.map((entry) => entry.path)).toEqual([
510
+ `/api/session/${SESSION}/synthetic`,
511
+ `/api/session/${SESSION}/synthetic`,
512
+ `/api/session/${SESSION}/synthetic`,
513
+ `/api/session/${SESSION}/synthetic`,
514
+ `/api/session/${SESSION}/synthetic`,
515
+ `/api/session/${SESSION}/prompt`,
453
516
  ]);
517
+ expect(openCode.state.sent.slice(0, 5).map((entry) => entry.body)).toEqual([
518
+ { text: 'how to read it', resume: false },
519
+ { text: 'the diff', resume: false, metadata },
520
+ { text: 'conflict payload', resume: false },
521
+ { text: 'use the skill', resume: false },
522
+ { text: 'pinned notes', resume: false },
523
+ ]);
524
+ expect(openCode.state.sent.at(-1).body).toEqual({
525
+ text: 'follow up',
526
+ files: [{ uri: 'data:text/plain,hi', name: 'f.txt' }],
527
+ agents: [{ name: 'reviewer' }],
528
+ });
454
529
  });
455
530
 
456
531
  it('keeps files on the command route, which is all that route accepts', async () => {
@@ -464,17 +539,21 @@ describe('message queue runtime', () => {
464
539
  }));
465
540
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
466
541
  await settle();
467
- expect(openCode.state.sent[0].path).toBe(`/session/${SESSION}/command`);
468
- expect(openCode.state.sent[0].body.parts).toEqual([{ type: 'file', mime: 'text/plain', filename: 'f.txt', url: 'data:text/plain,hi' }]);
542
+ expect(openCode.state.sent[0].path).toBe(`/api/session/${SESSION}/command`);
543
+ expect(openCode.state.sent[0].body).toEqual({
544
+ name: 'review',
545
+ text: '',
546
+ files: [{ uri: 'data:text/plain,hi', name: 'f.txt' }],
547
+ });
469
548
  });
470
549
 
471
- it('sends a command queued with context as its expanded prompt, context included', async () => {
472
- // The command route rejects text parts, so a command with captured
473
- // context takes the prompt route with the template expanded, exactly as
474
- // the composer does.
550
+ it('admits captured context as synthetic messages and still runs a queued command through the command route', async () => {
551
+ // The command route takes attachments only, so the context goes ahead as
552
+ // synthetic messages; the command itself keeps its route, because sending
553
+ // "/review ..." as a prompt would skip the template OpenCode expands there.
475
554
  const { runtime, openCode, emit } = createRuntime();
476
555
  runtime.start();
477
- openCode.state.commands = [{ name: 'review', source: 'command', template: 'Review $1 with focus on $2' }];
556
+ openCode.state.commands = [{ name: 'review', description: 'Review' }];
478
557
  const metadata = { openchamberContext: { kind: 'chat-quote', quote: 'q', text: 'why?' } };
479
558
  await runtime.enqueue(SESSION, DIRECTORY, item({
480
559
  content: '/review src "error handling"',
@@ -483,30 +562,50 @@ describe('message queue runtime', () => {
483
562
  }));
484
563
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
485
564
  await settle();
486
- expect(openCode.state.sent[0].path).toBe(`/session/${SESSION}/prompt_async`);
487
- expect(openCode.state.sent[0].body.parts).toEqual([
488
- { type: 'text', text: 'Review src with focus on error handling' },
489
- { type: 'text', text: 'quoted', synthetic: true, metadata },
565
+
566
+ expect(openCode.state.sent.map((entry) => entry.path)).toEqual([
567
+ `/api/session/${SESSION}/synthetic`,
568
+ `/api/session/${SESSION}/command`,
490
569
  ]);
570
+ expect(openCode.state.sent[0].body).toEqual({ text: 'quoted', resume: false, metadata });
571
+ expect(openCode.state.sent[1].body).toEqual({ name: 'review', text: 'src "error handling"' });
491
572
  });
492
573
 
493
- it('sends a skill queued with context as an explicit invocation, context included', async () => {
574
+ it('delivers pending project knowledge ahead of a queued command and records it', async () => {
575
+ const recorded = [];
576
+ const knowledge = {
577
+ resolvePendingForSession: async () => ({ text: 'pinned notes', signature: 'sig-1' }),
578
+ recordDelivered: async (sessionId, directory, signature) => { recorded.push({ sessionId, directory, signature }); },
579
+ };
580
+ const { runtime, openCode, emit } = createRuntime({ knowledge });
581
+ runtime.start();
582
+ openCode.state.commands = [{ name: 'review' }];
583
+ await runtime.enqueue(SESSION, DIRECTORY, item({ content: '/review', text: '/review' }));
584
+ emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
585
+ await settle();
586
+
587
+ expect(openCode.state.sent.map((entry) => entry.path)).toEqual([
588
+ `/api/session/${SESSION}/synthetic`,
589
+ `/api/session/${SESSION}/command`,
590
+ ]);
591
+ expect(openCode.state.sent[0].body).toEqual({ text: 'pinned notes', resume: false });
592
+ expect(recorded).toEqual([{ sessionId: SESSION, directory: DIRECTORY, signature: 'sig-1' }]);
593
+ });
594
+
595
+ it('admits nothing when the command lookup fails, so a retry cannot duplicate the context', async () => {
494
596
  const { runtime, openCode, emit } = createRuntime();
495
597
  runtime.start();
496
- openCode.state.commands = [{ name: 'grill', source: 'skill', template: 'skill body' }];
598
+ openCode.state.failNext = /^\/api\/command$/;
497
599
  await runtime.enqueue(SESSION, DIRECTORY, item({
498
- content: '/grill auth',
499
- text: '/grill auth',
500
- context: [{ kind: 'synthetic', text: 'focus on tests' }],
600
+ content: '/review',
601
+ text: '/review',
602
+ context: [{ kind: 'context', text: 'quoted', metadata: {} }],
501
603
  }));
502
604
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
503
605
  await settle();
504
- expect(openCode.state.sent[0].path).toBe(`/session/${SESSION}/prompt_async`);
505
- expect(openCode.state.sent[0].body.parts).toEqual([
506
- { type: 'text', text: '/grill auth' },
507
- { type: 'text', text: 'focus on tests', synthetic: true },
508
- { type: 'text', text: 'The user explicitly invoked the grill skill. Use the corresponding skill tool to handle this request.', synthetic: true },
509
- ]);
606
+
607
+ expect(openCode.state.sent).toEqual([]);
608
+ expect(runtime.sessionSnapshot(SESSION).items).toHaveLength(1);
510
609
  });
511
610
 
512
611
  it('keeps captured context out of snapshots and broadcasts, and hands it back on take', async () => {
@@ -532,12 +631,15 @@ describe('message queue runtime', () => {
532
631
  await runtime.enqueue(SESSION, DIRECTORY, item({ agentMention: 'reviewer', attachments: [{ id: 'a', filename: 'f.txt', mimeType: 'text/plain', size: 1, source: 'local', dataUrl: 'data:text/plain,hi' }] }));
533
632
  emit({ type: 'session.status', properties: { sessionID: SESSION, status: { type: 'idle' } } });
534
633
  await settle();
535
- expect(openCode.state.sent[0].body.parts).toEqual([
536
- { type: 'text', text: 'follow up' },
537
- { type: 'file', mime: 'text/plain', filename: 'f.txt', url: 'data:text/plain,hi' },
538
- { type: 'text', text: 'pinned notes', synthetic: true },
539
- { type: 'agent', name: 'reviewer' },
540
- ]);
634
+ // Knowledge is admitted as a synthetic message ahead of the prompt.
635
+ expect(openCode.state.sent[0].path).toBe(`/api/session/${SESSION}/synthetic`);
636
+ expect(openCode.state.sent[0].body).toEqual({ text: 'pinned notes', resume: false });
637
+ expect(openCode.state.sent[1].path).toBe(`/api/session/${SESSION}/prompt`);
638
+ expect(openCode.state.sent[1].body).toEqual({
639
+ text: 'follow up',
640
+ files: [{ uri: 'data:text/plain,hi', name: 'f.txt' }],
641
+ agents: [{ name: 'reviewer' }],
642
+ });
541
643
  expect(recorded).toEqual([{ sessionId: SESSION, directory: DIRECTORY, signature: 'sig-1' }]);
542
644
  });
543
645
  });
@@ -47,6 +47,7 @@ This module provides notification message preparation utilities for the web serv
47
47
  - Owns:
48
48
  - completion/error/question/permission trigger routing; permission suppression consults the authoritative permission-auto-accept runtime
49
49
  - session parent cache for subtask suppression
50
+ - no ready notification on a `session.idle` while a subagent of that session is still running (a background-subagent pause; OpenCode runs the parent again with the result and its next idle announces). The check comes from `../opencode/session-activity.js`; when it cannot be made, the idle announces as before
50
51
  - template resolution and fallback behavior
51
52
  - native notification fanout and web push payload fanout
52
53
  - push suppression while any fresh UI visibility heartbeat reports a focused client
@@ -136,3 +137,30 @@ The `settings` parameter for `prepareNotificationLastMessage` supports `maxLastM
136
137
  ### Testing
137
138
  - Run `bun run type-check`, `bun run lint`, and `bun run build` before finalizing changes.
138
139
  - Unit tests should cover truncation behavior and edge cases (empty strings, invalid inputs).
140
+
141
+ ## Browser event delivery
142
+
143
+ Web notifications subscribe to the shared `/api/openchamber/events` control
144
+ stream. The emitter sends each notification there and through the existing
145
+ global broadcaster. The broadcaster owns the main WebSocket and the legacy
146
+ `/api/notifications/stream` endpoint, which remains available to older clients.
147
+ Do not call both global and control broadcasters for one notification: they
148
+ share the WebSocket client set and would send each frame twice.
149
+
150
+ The web hook preserves `tag`, `sessionId`, `kind`, and the remaining notification
151
+ fields so the web notification API recognizes duplicate control-SSE and main-WS
152
+ delivery. Its existing five-second claim suppresses duplicate native alerts.
153
+ Native alerts remain best-effort live events, with no historical replay or
154
+ synthetic catch-up alerts. Authoritative session attention is owned by sync.
155
+
156
+ This removes one persistent HTTP connection per browser tab in both main-WS and
157
+ main-SSE modes. Two tabs use two control SSE connections, or four connections
158
+ when their main event pipelines also use SSE. It does not make HTTP/1.1 support
159
+ an unlimited number of tabs. The notification hook retains the app's background
160
+ work enablement, settings, focus, and runtime gates; it no longer opens a second
161
+ connection or switches sources when the main pipeline changes transport.
162
+
163
+ The control stream retains its browser-control capability declaration, runtime
164
+ switch cleanup, stale-source rejection, heartbeat, and reconnect-ready events.
165
+ Electron uses its native notification path; VS Code does not subscribe to this
166
+ server-only stream. Mobile shells retain their existing push behavior.
@@ -0,0 +1,68 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { createServer } from 'node:http';
3
+ import express from 'express';
4
+ import { createUiAuth } from '../ui-auth/ui-auth.js';
5
+ import { registerScheduledTaskRoutes } from '../scheduled-tasks/routes.js';
6
+ import { createNotificationEmitterRuntime } from './emitter-runtime.js';
7
+
8
+ // Exercise the existing browser URL-token gate and the real SSE route, not an
9
+ // unauthenticated mock endpoint. Notification consolidation adds no auth bypass.
10
+ describe('notifications over the authenticated control stream', () => {
11
+ it('rejects anonymous readers and delivers to a scoped authenticated stream', async () => {
12
+ const auth = createUiAuth({
13
+ requireClientAuth: true,
14
+ clientAuthController: {
15
+ authenticateBearerToken: async (token) => token === 'test-client' ? { ok: true, clientId: 'fixture' } : null,
16
+ },
17
+ });
18
+ const clients = new Set();
19
+ const emitter = createNotificationEmitterRuntime({
20
+ process,
21
+ getDesktopNotifyEnabled: () => false,
22
+ desktopNotifyPrefix: '',
23
+ getUiNotificationClients: () => new Set(),
24
+ getOpenChamberEventClients: () => clients,
25
+ });
26
+ const app = express();
27
+ app.use(express.json());
28
+ app.post('/auth/url-token', auth.handleUrlAuthToken);
29
+ app.use('/api', auth.requireAuth);
30
+ registerScheduledTaskRoutes(app, {
31
+ getOpenChamberEventClients: () => clients,
32
+ writeSseEvent: emitter.writeSseEvent,
33
+ });
34
+ const server = createServer(app);
35
+ await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
36
+ const base = `http://127.0.0.1:${server.address().port}`;
37
+ const abort = new AbortController();
38
+ try {
39
+ const denied = await fetch(`${base}/api/openchamber/events`);
40
+ expect(denied.status).toBe(401);
41
+ expect(clients.size).toBe(0);
42
+ const tokenResponse = await fetch(`${base}/auth/url-token`, {
43
+ method: 'POST', headers: { Authorization: 'Bearer test-client' },
44
+ });
45
+ expect(tokenResponse.status).toBe(200);
46
+ const { token } = await tokenResponse.json();
47
+ expect(token).toBeTruthy();
48
+ const response = await fetch(`${base}/api/openchamber/events?browser=1&oc_url_token=${encodeURIComponent(token)}`, { signal: abort.signal });
49
+ expect(response.status).toBe(200);
50
+ expect(response.headers.get('content-type')).toContain('text/event-stream');
51
+ const reader = response.body.getReader();
52
+ const ready = new TextDecoder().decode((await reader.read()).value);
53
+ expect(ready).toContain('openchamber:event-stream-ready');
54
+ expect(clients.size).toBe(1);
55
+ expect([...clients][0].openchamberBrowserCapable).toBe(true);
56
+ emitter.broadcastUiNotification({ title: 'Done', sessionId: 's1', kind: 'complete' });
57
+ const notification = new TextDecoder().decode((await reader.read()).value);
58
+ expect(notification).toContain('"type":"openchamber:notification"');
59
+ expect(notification).toContain('"sessionId":"s1"');
60
+ await reader.cancel();
61
+ } finally {
62
+ abort.abort();
63
+ server.closeAllConnections();
64
+ await new Promise((resolve) => server.close(resolve));
65
+ auth.dispose();
66
+ }
67
+ });
68
+ });
@@ -4,6 +4,7 @@ export const createNotificationEmitterRuntime = (dependencies) => {
4
4
  getDesktopNotifyEnabled,
5
5
  desktopNotifyPrefix,
6
6
  getUiNotificationClients,
7
+ getOpenChamberEventClients = () => new Set(),
7
8
  getBroadcastGlobalUiEvent,
8
9
  // Optional: in-process desktop shells (Electron main) inject a callback so
9
10
  // notifications are delivered as a direct function call instead of a stdout
@@ -78,6 +79,20 @@ export const createNotificationEmitterRuntime = (dependencies) => {
78
79
  },
79
80
  };
80
81
 
82
+ // New clients share the control SSE; older clients retain their dedicated
83
+ // notification SSE. The global broadcaster still owns WebSocket delivery.
84
+ const controlClients = getOpenChamberEventClients();
85
+ if (controlClients.size > 0) {
86
+ const serializedPayload = JSON.stringify(syntheticPayload);
87
+ for (const client of controlClients) {
88
+ try {
89
+ writeSseEvent(client, syntheticPayload, serializedPayload);
90
+ } catch {
91
+ // One disconnected control client must not block other transports.
92
+ }
93
+ }
94
+ }
95
+
81
96
  const broadcastGlobalUiEvent = typeof getBroadcastGlobalUiEvent === 'function'
82
97
  ? getBroadcastGlobalUiEvent()
83
98
  : null;
@@ -45,3 +45,35 @@ describe('notification emitter runtime', () => {
45
45
  });
46
46
  });
47
47
  });
48
+
49
+
50
+ describe('shared control notification delivery', () => {
51
+ it('writes once to control SSE and once to the legacy/global broadcaster', () => {
52
+ const control = { write: vi.fn() };
53
+ const failed = { write: () => { throw new Error('closed'); } };
54
+ const broadcastGlobalUiEvent = vi.fn();
55
+ const runtime = createRuntime({
56
+ getOpenChamberEventClients: () => new Set([failed, control]),
57
+ getBroadcastGlobalUiEvent: () => broadcastGlobalUiEvent,
58
+ });
59
+ runtime.broadcastUiNotification({ title: 'Done', sessionId: 's1', kind: 'complete' });
60
+ expect(control.write).toHaveBeenCalledTimes(1);
61
+ expect(broadcastGlobalUiEvent).toHaveBeenCalledTimes(1);
62
+ const envelope = broadcastGlobalUiEvent.mock.calls[0][0];
63
+ expect(control.write).toHaveBeenCalledWith(`data: ${JSON.stringify(envelope)}\n\n`);
64
+ expect(envelope.properties.sessionId).toBe('s1');
65
+ });
66
+
67
+ it('preserves legacy notification SSE without a global broadcaster', () => {
68
+ const control = { write: vi.fn() };
69
+ const legacy = { write: vi.fn() };
70
+ const runtime = createRuntime({
71
+ getOpenChamberEventClients: () => new Set([control]),
72
+ getUiNotificationClients: () => new Set([legacy]),
73
+ });
74
+ runtime.broadcastUiNotification({ title: 'Done' });
75
+ expect(control.write).toHaveBeenCalledTimes(1);
76
+ expect(legacy.write).toHaveBeenCalledTimes(1);
77
+ expect(control.write.mock.calls).toEqual(legacy.write.mock.calls);
78
+ });
79
+ });