@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
@@ -6,13 +6,18 @@ This module exposes OpenChamber to agents as typed OpenCode custom tools. There
6
6
  are two, because controlling sessions and driving a page are separate intents
7
7
  the user can want independently:
8
8
 
9
- - `openchamber` — projects, sessions, worktrees, and scheduled tasks. Enabled
10
- while the persisted `agentControlToolEnabled` setting is not `false`.
9
+ - `openchamber` — projects, sessions, worktrees, scheduled tasks, and showing
10
+ a file to the user (`file.open`). Enabled while the persisted
11
+ `agentControlToolEnabled` setting is not `false`.
11
12
  - `openchamber_web` — looking at and interacting with the page in OpenChamber's
12
13
  browser panel. Enabled while `agentWebToolEnabled` is not `false`.
13
14
 
14
- Both default to on, are toggled in Settings → General → OpenCode CLI, and apply
15
- on the next managed OpenCode restart. Each tool carries only its own actions and
15
+ Both default to on, are toggled in Settings → General → OpenCode CLI, and take
16
+ effect in the running OpenCode within a couple of seconds — OpenChamber rewrites
17
+ the managed config file OpenCode watches (see
18
+ `lib/opencode/managed-config-file.js`). Installs where the user's own
19
+ environment sets `OPENCODE_CONFIG` fall back to `OPENCODE_CONFIG_CONTENT` and
20
+ still need a restart for a toggle. Each tool carries only its own actions and
16
21
  only the parameters those actions use, so turning one off removes its inputs
17
22
  from the schema rather than leaving them visible. The plugin is injected only
18
23
  when OpenChamber launches and owns the OpenCode process, and not at all when
@@ -27,13 +32,19 @@ both settings are `false`.
27
32
  ## Runtime flow
28
33
 
29
34
  1. The OpenChamber HTTP listener binds and publishes its authoritative port.
30
- 2. `prepareManagedOpenCodeEnv()` materializes the plugin under
31
- `<openchamber-data-dir>/agent-tool/` and appends its `file://` URL to
32
- `OPENCODE_CONFIG_CONTENT` without replacing existing plugin entries.
33
- 3. A random per-child token and loopback callback URL are added only to the
34
- managed OpenCode child environment.
35
+ 2. `materializePlugin()` writes the plugin under
36
+ `<openchamber-data-dir>/agent-tool/` and returns its directory; the managed
37
+ config layer lists that directory in `<data-dir>/opencode.managed.json` and
38
+ rewrites the file whenever a tool setting changes.
39
+ 3. `createChildEnv()` adds a random per-child token and the callback URL to the
40
+ managed OpenCode child environment. They are present even while every tool
41
+ is off, so a tool switched on later can call back without a restart. The URL
42
+ points at loopback, except when the listener is bound to one concrete
43
+ address (`--host <ip>`): that socket does not answer on loopback, so the URL
44
+ uses the bound address instead.
35
45
  4. The plugin calls `POST /api/openchamber/agent-tool` with its typed input and
36
- OpenCode's authoritative session directory.
46
+ the session id OpenCode gives the tool; OpenChamber resolves the session's
47
+ directory on its own side.
37
48
  5. The route delegates the fixed action allowlist directly to the shared
38
49
  OpenChamber control service. The CLI uses the same service through its
39
50
  authenticated HTTP adapter, so Goal Mode ordering, wait behavior,
@@ -48,6 +59,9 @@ both settings are `false`.
48
59
  - The tool exposes one shared parameter object rather than repeating parameters
49
60
  in a large per-action union. Action descriptions carry only required inputs,
50
61
  defaults, or one non-obvious semantic detail.
62
+ - The action schema carries `oneOf` and no `enum`. A node combining `enum` and
63
+ `oneOf` is valid JSON Schema, but some OpenAI-compatible gateways reject it
64
+ and answer with an empty completion instead of an error.
51
65
  - Obvious fields rely on their names and JSON types. Parameter descriptions are
52
66
  reserved for formats, dependencies, scope, and behavior that cannot be safely
53
67
  inferred from the field name.
@@ -58,8 +72,11 @@ both settings are `false`.
58
72
  `schedule.list` already returns scheduler status, and enable/disable are one
59
73
  `schedule.toggle` action driven by the `disabled` boolean.
60
74
  - The tool description frames intent: created sessions and scheduled tasks are
61
- user-facing work the user follows up with, never a channel for the agent to
62
- delegate parts of its own current task.
75
+ user-facing work the user follows up with. The agent must not decide on its
76
+ own to delegate parts of its current task, but an explicit user request to
77
+ create, send, or schedule always wins, even when it relates to the current
78
+ task (strict models otherwise read the old unconditional "never delegate" as
79
+ a hard ban and refused user-requested sends).
63
80
  - Optional behavior switches (`worktree`, `goal`, `agent`, `variant`, `wait`)
64
81
  state their default and an explicit "only when the user asks" rule so agents
65
82
  do not invent worktrees, goal mode, or waits the user never requested.
@@ -69,14 +86,27 @@ both settings are `false`.
69
86
 
70
87
  ## Security invariants
71
88
 
72
- - The callback accepts loopback requests only and requires the current
73
- per-child bearer token using a timing-safe comparison.
89
+ - The callback accepts same-machine requests only and requires the current
90
+ per-child bearer token using a timing-safe comparison. Same-machine means a
91
+ loopback source, or, for a listener bound to one concrete address, a source
92
+ equal to that address: the OS sources a local connection to `<ip>` from
93
+ `<ip>`. A wildcard bind keeps the loopback-only rule, and another machine on
94
+ the network always arrives with its own address.
74
95
  - The token is never persisted, logged, returned to the UI, or written into
75
96
  the materialized plugin.
97
+ - The plugin adds the callback host to `NO_PROXY`/`no_proxy` inside the managed
98
+ child when it loads. Without that, an `HTTP_PROXY` in the child's environment
99
+ would receive a non-loopback callback, token included, because `fetch` has no
100
+ per-request way to skip the environment proxy.
76
101
  - Inputs map to a fixed action and parameter allowlist. There is no arbitrary
77
102
  CLI, shell, route, or URL forwarding.
78
103
  - Session/worktree deletion and project-path registration are not exposed.
79
- - An aborted tool request propagates an abort signal into the shared service.
104
+ - A cancelled turn aborts the session's in-flight actions. OpenCode 2 gives a
105
+ plugin tool no abort signal and the plugin's request stays open, so the
106
+ server tracks in-flight actions per session and `abortSession(sessionID)` is
107
+ called from the event dispatch in `server/index.js` when the stream reports
108
+ `session.idle` with `aborted: true`; the abort signal then reaches the
109
+ shared service as before. A dropped HTTP request still aborts as well.
80
110
 
81
111
  ## Result contract
82
112
 
@@ -1,5 +1,3 @@
1
- import { pathToFileURL } from 'node:url';
2
- import { appendManagedPlugin } from '../opencode/managed-plugin-config.js';
3
1
  import {
4
2
  OPENCHAMBER_AGENT_TOOL_ACTION_DEFINITIONS,
5
3
  OPENCHAMBER_AGENT_TOOL_ACTIONS,
@@ -11,6 +9,7 @@ import {
11
9
  } from '../openchamber-control/actions.js';
12
10
 
13
11
  const TOOL_SCHEMA_VERSION = 1;
12
+ const PLUGIN_ID = 'openchamber-agent-tool';
14
13
  // Everything either managed tool may ask for; the agent allowlist stays
15
14
  // narrower than the full control surface.
16
15
  const ACTIONS = new Set([...OPENCHAMBER_AGENT_TOOL_ACTIONS, ...OPENCHAMBER_WEB_ACTIONS, ...OPENCHAMBER_MEMORY_ACTIONS]);
@@ -79,6 +78,7 @@ const ALL_PARAMETER_PROPERTIES = {
79
78
  cron: { type: 'string', description: 'Cron expression' },
80
79
  timezone: { type: 'string', description: 'IANA timezone' },
81
80
  disabled: { type: 'boolean', description: 'true disables and false enables; required for schedule.toggle' },
81
+ path: { type: 'string', description: 'File to show for file.open; absolute, or relative to the session directory' },
82
82
  url: { type: 'string', description: 'http(s) URL for browser.open' },
83
83
  selector: { type: 'string', description: 'CSS selector from a browser.snapshot result' },
84
84
  text: { type: 'string', description: 'Visible label to match when no selector is given' },
@@ -108,11 +108,11 @@ const MEMORY_PARAMETER_PROPERTIES = {
108
108
  ...MEMORY_PARAMETER_OVERRIDES,
109
109
  };
110
110
 
111
- const CONTROL_TOOL_DESCRIPTION = "Control OpenChamber projects, sessions, and scheduled tasks on the user's behalf. Sessions and scheduled tasks you create are for the user to follow and interact with; never use this tool to delegate parts of your own current task. Use one action per call. Scope with projectId or directory; omit both to use the current session directory. Session dispatches return immediately by default and you receive no notification when a dispatched session finishes, so never promise to report back on it; the user follows it in OpenChamber; a dispatched session needs no follow-up from you. If the user later asks how it went, use session.messages (add wait to block until it is idle, lastAssistant for just the final answer) — session.send always sends a NEW prompt and never just waits. Set wait only when the user asks or the next step requires the completed result. Session and worktree deletion are unavailable.";
111
+ const CONTROL_TOOL_DESCRIPTION = "Control OpenChamber projects, sessions, and scheduled tasks on the user's behalf. Sessions and scheduled tasks you create are for the user to follow and interact with. Do not decide on your own to hand parts of your current task to another session; when the user asks you to create a session, send a prompt to one, or schedule a task, do it, including when the work relates to your current task. Use one action per call. Scope with projectId or directory; omit both to use the current session directory. Session dispatches return immediately by default and you receive no notification when a dispatched session finishes, so never promise to report back on it; the user follows it in OpenChamber; a dispatched session needs no follow-up from you. If the user later asks how it went, use session.messages (add wait to block until it is idle, lastAssistant for just the final answer) — session.send always sends a NEW prompt and never just waits. Set wait only when the user asks or the next step requires the completed result. Session and worktree deletion are unavailable.";
112
112
 
113
113
  const WEB_TOOL_DESCRIPTION = "Look at and interact with a web page in OpenChamber's browser panel, so you can check your own work rather than describing what you expect. Use one action per call. Open a page, snapshot it to read its text and its interactive elements, then click, type or scroll using the selectors the snapshot returned; snapshots also report any errors the page logged. Pass a selector to browser.snapshot to read one part of a long page. browser.inspect returns computed styles when the question is how something renders. Set viewport to check a layout at mobile, tablet or desktop size. The page runs with the user's real logins, so treat what you see as their live session.";
114
114
 
115
- const MEMORY_TOOL_DESCRIPTION = "Keep what you learn across sessions, so the user does not have to explain the same thing twice. Use one action per call. The session already lists the titles of what is stored. A title is an abbreviation, not the memory: read the entry with memory.read before acting on it, because titles leave out the conditions and exceptions that decide how the memory applies, and the ones that look self-explanatory hide them most often. Save something only when it will still be true in a later session — a stable preference, a project convention, a decision and its reason, or a hard-won pointer. Do not save one-off task state, anything you can read from the code, secrets or credentials, or anything the user asked you not to keep. Choose the scope deliberately: global is about the user and reaches every project, so put a project's conventions in project scope. What you save is shown to the user as unreviewed until they confirm it, so save plainly and say what you saved when it matters.";
115
+ const MEMORY_TOOL_DESCRIPTION = "Keep what you learn across sessions, so the user does not have to explain the same thing twice. Use one action per call. The session already lists the titles of what is stored. A title is an abbreviation, not the memory: read the entry with memory.read once before acting on it (it then stays in your context; do not re-read it on later turns), because titles leave out the conditions and exceptions that decide how the memory applies, and the ones that look self-explanatory hide them most often. Save something only when it will still be true in a later session — a stable preference, a project convention, a decision and its reason, or a hard-won pointer. Do not save one-off task state, anything you can read from the code, secrets or credentials, or anything the user asked you not to keep; when the user explicitly asks you to remember something, save it, unless it is a secret or credential. Choose the scope deliberately: global is about the user and reaches every project, so put a project's conventions in project scope. Save in the moment, without asking first, when the user corrects how you work or states a preference, confirms that a non-obvious approach worked, or when you learn a project fact that took real effort to find. One fact per entry. The user can review and remove what you save, so save when it fits and mention it briefly.";
116
116
 
117
117
  const asNonEmptyString = (value) => {
118
118
  if (typeof value !== 'string') return null;
@@ -129,11 +129,24 @@ const createResult = ({ ok, action, data, error, exitCode }) => ({
129
129
  ...(Number.isInteger(exitCode) ? { exitCode } : {}),
130
130
  });
131
131
 
132
+ // Node reports an IPv4 peer on a dual-stack socket as `::ffff:<ipv4>`.
133
+ const normalizeAddress = (value) => {
134
+ const address = (asNonEmptyString(value) || '').toLowerCase();
135
+ return address.startsWith('::ffff:') ? address.slice('::ffff:'.length) : address;
136
+ };
137
+
132
138
  const isLoopbackAddress = (value) => {
133
- const address = typeof value === 'string' ? value.toLowerCase() : '';
134
- return address === '127.0.0.1'
135
- || address === '::1'
136
- || address === '::ffff:127.0.0.1';
139
+ const address = normalizeAddress(value);
140
+ return address === '127.0.0.1' || address === '::1';
141
+ };
142
+
143
+ const WILDCARD_ADDRESSES = new Set(['0.0.0.0', '::']);
144
+
145
+ // A wildcard listener answers on loopback. A listener bound to one concrete
146
+ // address answers only there, so that address is the only way back in.
147
+ const resolveConcreteBoundAddress = (value) => {
148
+ const address = normalizeAddress(value);
149
+ return address && !WILDCARD_ADDRESSES.has(address) ? address : null;
137
150
  };
138
151
 
139
152
  /**
@@ -143,12 +156,30 @@ const isLoopbackAddress = (value) => {
143
156
  * set, the inputs and the description differ. Generating them from one template
144
157
  * keeps the transport, metadata and failure handling identical, which is what
145
158
  * the caller depends on.
159
+ *
160
+ * OpenCode 2 takes a tool's `input` as plain JSON Schema, so the generated file
161
+ * needs no imports at all — which it must not have, because OpenCode loads the
162
+ * entrypoint with a bare dynamic import and nothing resolves from the generated
163
+ * directory.
164
+ *
165
+ * The action schema carries `oneOf` only. A node combining `enum` and `oneOf`
166
+ * is valid JSON Schema, but some OpenAI-compatible gateways reject it and
167
+ * answer with an empty completion instead of an error, and the `oneOf` branches
168
+ * are what carry the per-action descriptions the model reads.
146
169
  */
147
- const createToolEntry = ({ name, description, actions, definitions, parameters }) => String.raw` ${name}: {
170
+ const createToolEntry = ({ name, description, definitions, parameters }) => String.raw` tools.add({
171
+ name: ${JSON.stringify(name)},
148
172
  description: ${JSON.stringify(description)},
149
- args: {
150
- action: { type: "string", enum: ${JSON.stringify(actions)}, oneOf: ${JSON.stringify(definitions.map((entry) => ({ const: entry.action, description: entry.description })))}, description: "OpenChamber action to perform" },
151
- parameters: { type: "object", properties: ${JSON.stringify(parameters)}, additionalProperties: false, description: "Inputs for the action; use an empty object when none are needed" },
173
+ input: {
174
+ type: "object",
175
+ properties: {
176
+ action: { type: "string", oneOf: ${JSON.stringify(definitions.map((entry) => ({ const: entry.action, description: entry.description })))}, description: "OpenChamber action to perform" },
177
+ parameters: { type: "object", properties: ${JSON.stringify(parameters)}, additionalProperties: false, description: "Inputs for the action; use an empty object when none are needed" },
178
+ },
179
+ required: ["action"],
180
+ // Models routinely put the inputs next to the action; the schema has to
181
+ // let that reach execute() instead of rejecting the call.
182
+ additionalProperties: true,
152
183
  },
153
184
  async execute(input, context) {
154
185
  // Models routinely put the inputs next to the action instead of inside
@@ -159,21 +190,22 @@ const createToolEntry = ({ name, description, actions, definitions, parameters }
159
190
  const args = { ...flattened, ...(parameters ?? {}), action: requestedAction }
160
191
  const actionTitles = ${JSON.stringify(AGENT_TOOL_ACTION_TITLES)}
161
192
  const title = Object.hasOwn(actionTitles, args.action) ? actionTitles[args.action] : args.action
162
- context.metadata({
163
- title,
164
- metadata: {
165
- ${name}: {
166
- schemaVersion: ${TOOL_SCHEMA_VERSION},
167
- action: args.action,
168
- description: title,
169
- },
193
+ const progress = (extra) => context.progress({
194
+ ${name}: {
195
+ schemaVersion: ${TOOL_SCHEMA_VERSION},
196
+ action: args.action,
197
+ description: title,
198
+ ...extra,
170
199
  },
171
200
  })
201
+ await progress()
172
202
  const endpoint = process.env.OPENCHAMBER_AGENT_TOOL_URL
173
203
  const token = process.env.OPENCHAMBER_AGENT_TOOL_TOKEN
204
+ // No output schema is declared, so a result must never carry an output
205
+ // field: OpenCode rejects that with "Tool result declared output
206
+ // without an output schema". The envelope travels as text content.
174
207
  const failure = (payload) => ({
175
- title,
176
- output: JSON.stringify(payload),
208
+ content: JSON.stringify(payload),
177
209
  metadata: { openchamber: { schemaVersion: ${TOOL_SCHEMA_VERSION}, action: args.action, description: title, ok: false } },
178
210
  })
179
211
  if (!endpoint || !token) {
@@ -187,32 +219,25 @@ const createToolEntry = ({ name, description, actions, definitions, parameters }
187
219
  authorization: "Bearer " + token,
188
220
  "content-type": "application/json",
189
221
  },
190
- body: JSON.stringify({ input: args, contextDirectory: context.directory, tool: ${JSON.stringify(name)} }),
191
- signal: context.abort,
222
+ // OpenCode 2 no longer hands a tool its session directory, so the
223
+ // session id goes over instead and OpenChamber resolves the
224
+ // directory on its own side. The signal fires when the session is
225
+ // aborted, so the OpenChamber side stops the action too.
226
+ body: JSON.stringify({ input: args, sessionID: context.sessionID, tool: ${JSON.stringify(name)} }),
227
+ signal: context.signal,
192
228
  })
193
- const output = await response.text()
229
+ const content = await response.text()
194
230
  let result = null
195
- try { result = JSON.parse(output) } catch {}
231
+ try { result = JSON.parse(content) } catch {}
196
232
  const valid = result?.schemaVersion === ${TOOL_SCHEMA_VERSION} && typeof result?.ok === "boolean" && typeof result?.action === "string"
197
- context.metadata({
198
- title,
199
- metadata: {
200
- ${name}: {
201
- schemaVersion: ${TOOL_SCHEMA_VERSION},
202
- action: args.action,
203
- description: title,
204
- ok: valid && result.ok === true,
205
- },
206
- },
207
- })
208
- if (valid) return { title, output, metadata: { openchamber: { schemaVersion: ${TOOL_SCHEMA_VERSION}, action: args.action, description: title, ok: result.ok === true } } }
233
+ await progress({ ok: valid && result.ok === true })
234
+ if (valid) return { content, metadata: { openchamber: { schemaVersion: ${TOOL_SCHEMA_VERSION}, action: args.action, description: title, ok: result.ok === true } } }
209
235
  return failure({ schemaVersion: ${TOOL_SCHEMA_VERSION}, ok: false, action: args.action, error: { message: "OpenChamber returned an invalid response", kind: "runtime", status: response.status } })
210
236
  } catch (error) {
211
- if (context.abort.aborted) throw error
212
237
  return failure({ schemaVersion: ${TOOL_SCHEMA_VERSION}, ok: false, action: args.action, error: { message: error instanceof Error ? error.message : String(error), kind: "runtime" } })
213
238
  }
214
239
  },
215
- },
240
+ })
216
241
  `;
217
242
 
218
243
  const createPluginSource = ({ includeControl, includeWeb, includeMemory }) => {
@@ -221,7 +246,6 @@ const createPluginSource = ({ includeControl, includeWeb, includeMemory }) => {
221
246
  entries.push(createToolEntry({
222
247
  name: 'openchamber',
223
248
  description: CONTROL_TOOL_DESCRIPTION,
224
- actions: OPENCHAMBER_AGENT_TOOL_ACTIONS,
225
249
  definitions: OPENCHAMBER_AGENT_TOOL_ACTION_DEFINITIONS,
226
250
  parameters: CONTROL_PARAMETER_PROPERTIES,
227
251
  }));
@@ -230,7 +254,6 @@ const createPluginSource = ({ includeControl, includeWeb, includeMemory }) => {
230
254
  entries.push(createToolEntry({
231
255
  name: 'openchamber_web',
232
256
  description: WEB_TOOL_DESCRIPTION,
233
- actions: OPENCHAMBER_WEB_ACTIONS,
234
257
  definitions: OPENCHAMBER_WEB_ACTION_DEFINITIONS,
235
258
  parameters: WEB_PARAMETER_PROPERTIES,
236
259
  }));
@@ -239,19 +262,47 @@ const createPluginSource = ({ includeControl, includeWeb, includeMemory }) => {
239
262
  entries.push(createToolEntry({
240
263
  name: 'openchamber_memory',
241
264
  description: MEMORY_TOOL_DESCRIPTION,
242
- actions: OPENCHAMBER_MEMORY_ACTIONS,
243
265
  definitions: OPENCHAMBER_MEMORY_ACTION_DEFINITIONS,
244
266
  parameters: MEMORY_PARAMETER_PROPERTIES,
245
267
  }));
246
268
  }
247
269
 
248
- return `export const OpenChamberPlugin = async () => ({
249
- tool: {
250
- ${entries.join('')} },
251
- })
270
+ // The callback carries the per-child token over plain HTTP. With a proxy in
271
+ // the child's environment, fetch would hand a non-loopback callback, token
272
+ // included, to that proxy, and no per-request option turns that off. The
273
+ // exemption is added inside the child because only there is the final
274
+ // NO_PROXY, merged from the shell and server environments, visible.
275
+ return `const exemptCallbackFromProxy = () => {
276
+ const endpoint = process.env.OPENCHAMBER_AGENT_TOOL_URL
277
+ if (!endpoint || !URL.canParse(endpoint)) return
278
+ const host = new URL(endpoint).hostname.replace(/^\\[|\\]$/g, "")
279
+ for (const key of ["NO_PROXY", "no_proxy"]) {
280
+ const entries = (process.env[key] || "").split(",").map((entry) => entry.trim()).filter(Boolean)
281
+ if (!entries.includes(host)) process.env[key] = [...entries, host].join(",")
282
+ }
283
+ }
284
+
285
+ export default {
286
+ id: ${JSON.stringify(PLUGIN_ID)},
287
+ setup: async (ctx) => {
288
+ exemptCallbackFromProxy()
289
+ await ctx.tool.transform((tools) => {
290
+ ${entries.join('')} })
291
+ },
292
+ }
252
293
  `;
253
294
  };
254
295
 
296
+ // A configured plugin has to be a directory carrying a package.json that
297
+ // resolves an entrypoint; OpenCode skips a plain .js path.
298
+ const PLUGIN_PACKAGE_JSON = `${JSON.stringify({
299
+ name: 'openchamber-agent-tool',
300
+ version: '0.0.0',
301
+ private: true,
302
+ type: 'module',
303
+ exports: { '.': './index.js' },
304
+ }, null, 2)}\n`;
305
+
255
306
  export const createAgentToolRuntime = (dependencies) => {
256
307
  const {
257
308
  crypto,
@@ -259,34 +310,69 @@ export const createAgentToolRuntime = (dependencies) => {
259
310
  path,
260
311
  dataDir,
261
312
  getActivePort,
313
+ getActiveHost = () => null,
262
314
  executeAction,
263
- env = process.env,
315
+ resolveSessionDirectory,
264
316
  } = dependencies;
265
- const pluginDirectory = path.join(dataDir, 'agent-tool');
266
- const pluginPath = path.join(pluginDirectory, 'openchamber-plugin.js');
317
+ const pluginRoot = path.join(dataDir, 'agent-tool');
318
+ const pluginDirectory = path.join(pluginRoot, PLUGIN_ID);
319
+ const pluginPath = path.join(pluginDirectory, 'index.js');
320
+ const pluginManifestPath = path.join(pluginDirectory, 'package.json');
267
321
  let activeToken = null;
268
322
 
269
- const prepareManagedOpenCodeEnv = async ({ includeControl = true, includeWeb = true, includeMemory = true } = {}) => {
270
- const port = getActivePort();
271
- if (!Number.isInteger(port) || port <= 0) {
272
- throw new Error('OpenChamber listener port is unavailable for managed tool injection');
273
- }
323
+ const getConcreteBoundAddress = () => resolveConcreteBoundAddress(getActiveHost());
324
+
325
+ /**
326
+ * Write the plugin for the requested tool set and return its directory.
327
+ *
328
+ * Called both before a managed child starts and whenever the tool settings
329
+ * change while it runs, so the source on disk always matches the settings —
330
+ * the running OpenCode reloads the directory it already has configured.
331
+ */
332
+ const materializePlugin = async ({ includeControl = true, includeWeb = true, includeMemory = true } = {}) => {
274
333
  if (!includeControl && !includeWeb && !includeMemory) {
275
334
  throw new Error('At least one OpenChamber managed tool must be enabled to inject the plugin');
276
335
  }
277
336
  await fsPromises.mkdir(pluginDirectory, { recursive: true });
337
+ await fsPromises.writeFile(pluginManifestPath, PLUGIN_PACKAGE_JSON, { mode: 0o600 });
278
338
  await fsPromises.writeFile(pluginPath, createPluginSource({ includeControl, includeWeb, includeMemory }), { mode: 0o600 });
339
+ return pluginDirectory;
340
+ };
341
+
342
+ /**
343
+ * Callback URL and a fresh per-child token for a managed OpenCode process.
344
+ *
345
+ * These are always part of the child environment, including when every tool
346
+ * is currently off: a tool switched on later reaches a process that already
347
+ * knows where and how to call back, so the toggle needs no restart.
348
+ */
349
+ const createChildEnv = () => {
350
+ const port = getActivePort();
351
+ if (!Number.isInteger(port) || port <= 0) {
352
+ throw new Error('OpenChamber listener port is unavailable for managed tool injection');
353
+ }
279
354
  activeToken = crypto.randomBytes(32).toString('base64url');
280
- const pluginUrl = pathToFileURL(pluginPath).href;
355
+ // A listener bound to one concrete address does not answer on loopback,
356
+ // so the callback has to point at the bound address instead.
357
+ const callbackAddress = getConcreteBoundAddress() || '127.0.0.1';
358
+ const callbackHost = callbackAddress.includes(':') ? `[${callbackAddress}]` : callbackAddress;
281
359
  return {
282
- OPENCODE_CONFIG_CONTENT: appendManagedPlugin(env.OPENCODE_CONFIG_CONTENT, pluginUrl, 'managed tool'),
283
- OPENCHAMBER_AGENT_TOOL_URL: `http://127.0.0.1:${port}/api/openchamber/agent-tool`,
360
+ OPENCHAMBER_AGENT_TOOL_URL: `http://${callbackHost}:${port}/api/openchamber/agent-tool`,
284
361
  OPENCHAMBER_AGENT_TOOL_TOKEN: activeToken,
285
362
  };
286
363
  };
287
364
 
365
+ // The managed child runs on this machine. Reaching a listener bound to one
366
+ // concrete address makes the OS source the connection from that same address,
367
+ // so it stands in for loopback there; any other machine arrives as itself.
368
+ const isSameMachineAddress = (value) => {
369
+ if (isLoopbackAddress(value)) return true;
370
+ const boundAddress = getConcreteBoundAddress();
371
+ return boundAddress !== null && normalizeAddress(value) === boundAddress;
372
+ };
373
+
288
374
  const authorize = (req) => {
289
- if (!activeToken || !isLoopbackAddress(req.socket?.remoteAddress)) return false;
375
+ if (!activeToken || !isSameMachineAddress(req.socket?.remoteAddress)) return false;
290
376
  const header = asNonEmptyString(req.headers?.authorization);
291
377
  if (!header?.startsWith('Bearer ')) return false;
292
378
  const provided = Buffer.from(header.slice(7));
@@ -310,8 +396,22 @@ export const createAgentToolRuntime = (dependencies) => {
310
396
  if (typeof executeAction !== 'function') {
311
397
  return createResult({ ok: false, action, error: { message: 'OpenChamber control service is unavailable', kind: 'runtime' } });
312
398
  }
399
+ // OpenCode 2 tools no longer receive a directory, so the plugin sends the
400
+ // session id and the directory is resolved here. An unresolvable session
401
+ // falls through with no directory, exactly like the old "no directory" path.
402
+ let contextDirectory = asNonEmptyString(payload.contextDirectory) ?? undefined;
403
+ const sessionID = asNonEmptyString(payload.sessionID);
404
+ if (!contextDirectory && sessionID && typeof resolveSessionDirectory === 'function') {
405
+ contextDirectory = await Promise.resolve(resolveSessionDirectory(sessionID))
406
+ .then((value) => asNonEmptyString(value) ?? undefined)
407
+ .catch(() => undefined);
408
+ }
313
409
  try {
314
- const data = await executeAction(action, { ...payload.input, action }, payload.contextDirectory, options);
410
+ // The calling session scopes browser actions to that session's page.
411
+ const contextSessionId = asNonEmptyString(payload.contextSessionId) ?? sessionID;
412
+ const data = await executeAction(action, { ...payload.input, action }, contextDirectory, contextSessionId
413
+ ? { ...options, contextSessionId }
414
+ : options);
315
415
  return createResult({ ok: true, action, data });
316
416
  } catch (error) {
317
417
  return createResult({
@@ -331,6 +431,29 @@ export const createAgentToolRuntime = (dependencies) => {
331
431
  }
332
432
  };
333
433
 
434
+ // In-flight actions per session. The plugin forwards OpenCode's abort
435
+ // signal (2.0.12+), which closes its request and aborts the action here.
436
+ // Before that release the request stayed open after the user cancelled the
437
+ // turn, so the server also listens for the cancel on the event stream
438
+ // (`session.idle` with `aborted: true`) and aborts the actions itself.
439
+ const inflightBySession = new Map();
440
+ const trackInflight = (sessionID, controller) => {
441
+ if (!sessionID) return () => {};
442
+ const set = inflightBySession.get(sessionID) ?? new Set();
443
+ set.add(controller);
444
+ inflightBySession.set(sessionID, set);
445
+ return () => {
446
+ set.delete(controller);
447
+ if (set.size === 0) inflightBySession.delete(sessionID);
448
+ };
449
+ };
450
+ const abortSession = (sessionID) => {
451
+ const set = inflightBySession.get(asNonEmptyString(sessionID));
452
+ if (!set) return 0;
453
+ for (const controller of set) controller.abort();
454
+ return set.size;
455
+ };
456
+
334
457
  const registerRoutes = (app, express) => {
335
458
  app.post('/api/openchamber/agent-tool', express.json({ limit: '1mb' }), async (req, res) => {
336
459
  if (!authorize(req)) return res.status(401).json({ error: 'Unauthorized' });
@@ -340,6 +463,7 @@ export const createAgentToolRuntime = (dependencies) => {
340
463
  };
341
464
  req.once('aborted', abortOnDisconnect);
342
465
  res.once('close', abortOnDisconnect);
466
+ const untrack = trackInflight(asNonEmptyString(req.body?.sessionID), controller);
343
467
  try {
344
468
  return res.json(await execute(req.body, { signal: controller.signal }));
345
469
  } catch (error) {
@@ -349,6 +473,7 @@ export const createAgentToolRuntime = (dependencies) => {
349
473
  error: { message: error instanceof Error ? error.message : String(error), kind: 'runtime' },
350
474
  }));
351
475
  } finally {
476
+ untrack();
352
477
  req.off('aborted', abortOnDisconnect);
353
478
  res.off('close', abortOnDisconnect);
354
479
  }
@@ -356,8 +481,11 @@ export const createAgentToolRuntime = (dependencies) => {
356
481
  };
357
482
 
358
483
  return {
359
- prepareManagedOpenCodeEnv,
484
+ pluginDirectory,
485
+ materializePlugin,
486
+ createChildEnv,
360
487
  registerRoutes,
361
488
  execute,
489
+ abortSession,
362
490
  };
363
491
  };