@openchamber/web 1.24.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (387) hide show
  1. package/bin/lib/commands-connect-url.js +3 -8
  2. package/bin/lib/commands-tunnel.js +3 -0
  3. package/dist/assets/{CodeMirrorCommentWidgets-B_vBPQYm.js → CodeMirrorCommentWidgets-zm3C1FvM.js} +1 -1
  4. package/dist/assets/DiffView-DNExNi1z.js +4 -0
  5. package/dist/assets/FilesView-DUCLmHBi.js +17 -0
  6. package/dist/assets/{GitView-k0hUF8KB.js → GitView-Bz9z6gZA.js} +4 -4
  7. package/dist/assets/{GuestAttachDialog-DIf2U85Z.js → GuestAttachDialog-UGp4KDlK.js} +1 -1
  8. package/dist/assets/GuestSurfacePane-B3pdB_2u.js +1 -0
  9. package/dist/assets/{JsonTreeView-4AnJ04Pw.js → JsonTreeView-7lVecnZl.js} +1 -1
  10. package/dist/assets/LinearIssuesView-CTGRS9Vq.js +1 -0
  11. package/dist/assets/MarkdownImageGallery-DQk5adUs.js +1 -0
  12. package/dist/assets/MarkdownRendererImpl-DPF8fZpX.js +12 -0
  13. package/dist/assets/OnboardingScreen-CBx6cXPP.js +1 -0
  14. package/dist/assets/{PatchDiff-DpGmHRnV.js → PatchDiff-D7VVpR_l.js} +1 -1
  15. package/dist/assets/{PierreDiffViewer-CgLl_tp7.js → PierreDiffViewer-Gbfks1pk.js} +3 -3
  16. package/dist/assets/PlanView-CPSK0x97.js +5 -0
  17. package/dist/assets/PluginPane-BIGsUx69.js +3 -0
  18. package/dist/assets/SettingsView-Dql7z6Ww.js +30 -0
  19. package/dist/assets/SettingsWindow-D6oi-UmV.js +1 -0
  20. package/dist/assets/SubmoduleDiffSummary-BXA0FAWj.js +1 -0
  21. package/dist/assets/ToolOutputDialog-BQJsSbDm.js +15 -0
  22. package/dist/assets/ToolPartDiffPreview-FY9w0TVT.js +8 -0
  23. package/dist/assets/{VirtualizedFileDiff-BK4aU5qJ.js → VirtualizedFileDiff-B9YhAya5.js} +4 -4
  24. package/dist/assets/{WalkthroughView-Bk6TPNFw.js → WalkthroughView-CmFgOUFN.js} +2 -2
  25. package/dist/assets/appThemeRegistry-BebxalUt.js +1 -0
  26. package/dist/assets/changesTree-CePHbFcj.js +1 -0
  27. package/dist/assets/commitAndPush-Wfxng_IK.js +1 -0
  28. package/dist/assets/{computeVirtualFileMetrics-BVTujWSX.js → computeVirtualFileMetrics-BCOqgixN.js} +2 -2
  29. package/dist/assets/de-CMA45TC-.js +10 -0
  30. package/dist/assets/es-DPL4fBtl.js +16 -0
  31. package/dist/assets/fr-OHBKBseP.js +14 -0
  32. package/dist/assets/index-3TiDNtfN.js +1 -0
  33. package/dist/assets/index-BLUZa5u0.js +41 -0
  34. package/dist/assets/index-Cm2rrq69.css +1 -0
  35. package/dist/assets/{isDiffPlainText-D3yX_vx4.js → isDiffPlainText-DnDYQmWK.js} +1 -1
  36. package/dist/assets/{isFilePlainText-CZR9TcHV.js → isFilePlainText-BA_AHX7d.js} +1 -1
  37. package/dist/assets/ja-DvX4WSRf.js +16 -0
  38. package/dist/assets/ko-BUcLd8YZ.js +16 -0
  39. package/dist/assets/main-B_jri4i-.js +896 -0
  40. package/dist/assets/main-DtUmJp9B.js +2 -0
  41. package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
  42. package/dist/assets/markdownCore-BSnlUXBf.js +7 -0
  43. package/dist/assets/miniChat-BYfLUnDK.js +2 -0
  44. package/dist/assets/mobile-DH3hI6gd.js +2 -0
  45. package/dist/assets/patchFileDiff--L7lt_GZ.js +13 -0
  46. package/dist/assets/pl-BkI_xHqz.js +16 -0
  47. package/dist/assets/pt-BR-7wFtQlV9.js +16 -0
  48. package/dist/assets/renderElectronMiniChatApp-C7kpNW_-.js +2 -0
  49. package/dist/assets/renderMobileApp-i0nq7Dwy.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-CfEYbcCc.js +27 -0
  51. package/dist/assets/scheduledTasksApi-Cy7uZCaI.js +1 -0
  52. package/dist/assets/{shikiHighlight-BfjuB3CD.js → shikiHighlight-D4vxipfr.js} +1 -1
  53. package/dist/assets/{textMateThemeFromAppTheme-BP60t9SX.js → textMateThemeFromAppTheme-BYAHtJwQ.js} +1 -1
  54. package/dist/assets/tr-TsD-AqEH.js +7 -0
  55. package/dist/assets/uk-B-qspCmD.js +16 -0
  56. package/dist/assets/useAppFontEffects-DHZ9-L30.js +7338 -0
  57. package/dist/assets/useInlineCommentController-CvpOMK-R.js +2 -0
  58. package/dist/assets/useRootScrollLock-DzNFi-fn.js +2 -0
  59. package/dist/assets/{vendor-codemirror-language-data-BFm1Ju2w.js → vendor-codemirror-language-data-j3fhlwUM.js} +2 -2
  60. package/dist/assets/vendor-cron-parser-CjvYVigk.js +2 -0
  61. package/dist/assets/vendor-opencode-client-DYdsLbCM.js +12 -0
  62. package/dist/assets/{vendor-remixicon-react-BDmGmFCA.js → vendor-remixicon-react-D6dZ0UwF.js} +1 -1
  63. package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
  64. package/dist/assets/{web-components-2vo9YsZc.js → web-components-BvHNFSEG.js} +2 -2
  65. package/dist/assets/zh-CN-DYuPJV5i.js +16 -0
  66. package/dist/assets/zh-TW-BX_2D_lV.js +16 -0
  67. package/dist/index.html +13 -7
  68. package/dist/mini-chat.html +5 -5
  69. package/dist/mobile.html +5 -5
  70. package/package.json +6 -5
  71. package/server/index.d.ts +1 -0
  72. package/server/index.js +264 -91
  73. package/server/lib/agent-tool/DOCUMENTATION.md +38 -16
  74. package/server/lib/agent-tool/runtime.js +167 -58
  75. package/server/lib/agent-tool/runtime.test.js +170 -87
  76. package/server/lib/browser-control/DOCUMENTATION.md +51 -4
  77. package/server/lib/browser-control/provider.js +217 -0
  78. package/server/lib/browser-control/provider.test.js +251 -0
  79. package/server/lib/context-obligatory/runtime.js +61 -50
  80. package/server/lib/context-obligatory/runtime.test.js +62 -162
  81. package/server/lib/event-stream/DOCUMENTATION.md +12 -1
  82. package/server/lib/event-stream/delta-coalescer.js +0 -0
  83. package/server/lib/event-stream/delta-coalescer.test.js +68 -57
  84. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  85. package/server/lib/event-stream/global-hub.js +10 -1
  86. package/server/lib/event-stream/global-hub.test.js +27 -26
  87. package/server/lib/event-stream/index.js +6 -0
  88. package/server/lib/event-stream/protocol.js +26 -19
  89. package/server/lib/event-stream/protocol.test.js +18 -7
  90. package/server/lib/event-stream/rebind.test.js +5 -5
  91. package/server/lib/event-stream/runtime.test.js +17 -15
  92. package/server/lib/event-stream/translate-v2.js +313 -0
  93. package/server/lib/event-stream/translate-v2.test.js +209 -0
  94. package/server/lib/event-stream/upstream-reader.test.js +16 -16
  95. package/server/lib/fs/DOCUMENTATION.md +4 -2
  96. package/server/lib/fs/byte-range.js +35 -0
  97. package/server/lib/fs/byte-range.test.js +31 -0
  98. package/server/lib/fs/routes.js +47 -42
  99. package/server/lib/fs/routes.test.js +123 -18
  100. package/server/lib/git/DOCUMENTATION.md +1 -1
  101. package/server/lib/git/service.js +34 -0
  102. package/server/lib/git/service.test.js +8 -0
  103. package/server/lib/github/DOCUMENTATION.md +1 -1
  104. package/server/lib/github/pr-status.js +22 -2
  105. package/server/lib/github/pr-status.test.js +27 -14
  106. package/server/lib/guests/DOCUMENTATION.md +16 -2
  107. package/server/lib/guests/catalog.js +31 -1
  108. package/server/lib/guests/catalog.test.js +55 -0
  109. package/server/lib/guests/html-styles.js +5 -3
  110. package/server/lib/guests/html-styles.test.js +3 -1
  111. package/server/lib/guests/routes.js +21 -4
  112. package/server/lib/guests/service.js +197 -14
  113. package/server/lib/guests/service.test.js +201 -1
  114. package/server/lib/guests/surface.js +676 -0
  115. package/server/lib/guests/surface.test.js +536 -0
  116. package/server/lib/markdown-image-grants/routes.js +18 -5
  117. package/server/lib/markdown-image-grants/routes.test.js +9 -6
  118. package/server/lib/message-queue/DOCUMENTATION.md +33 -22
  119. package/server/lib/message-queue/runtime.js +155 -100
  120. package/server/lib/message-queue/runtime.test.js +168 -82
  121. package/server/lib/notifications/DOCUMENTATION.md +38 -0
  122. package/server/lib/notifications/control-stream.http.test.js +68 -0
  123. package/server/lib/notifications/emit-route.js +118 -0
  124. package/server/lib/notifications/emit-route.test.js +112 -0
  125. package/server/lib/notifications/emitter-runtime.js +15 -0
  126. package/server/lib/notifications/emitter-runtime.test.js +32 -0
  127. package/server/lib/notifications/push-runtime.js +5 -1
  128. package/server/lib/notifications/push-runtime.test.js +2 -2
  129. package/server/lib/notifications/routes.js +1 -1
  130. package/server/lib/notifications/runtime.js +115 -26
  131. package/server/lib/notifications/template-runtime.js +13 -15
  132. package/server/lib/notifications/template-runtime.test.js +16 -9
  133. package/server/lib/notifications/trigger-runtime.test.js +187 -0
  134. package/server/lib/openchamber-control/DOCUMENTATION.md +10 -0
  135. package/server/lib/openchamber-control/actions.js +19 -4
  136. package/server/lib/openchamber-control/error.js +1 -1
  137. package/server/lib/openchamber-control/file-open.js +59 -0
  138. package/server/lib/openchamber-control/file-open.test.js +57 -0
  139. package/server/lib/openchamber-control/routes.test.js +12 -0
  140. package/server/lib/openchamber-control/service.js +125 -49
  141. package/server/lib/openchamber-control/service.test.js +115 -44
  142. package/server/lib/openchamber-sessions/archive-store.js +224 -0
  143. package/server/lib/openchamber-sessions/archive-store.test.js +187 -0
  144. package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
  145. package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
  146. package/server/lib/openchamber-sessions/opencode-client.js +22 -0
  147. package/server/lib/openchamber-sessions/routes.js +409 -328
  148. package/server/lib/openchamber-sessions/routes.test.js +795 -740
  149. package/server/lib/openchamber-sessions/session-metadata-store.js +285 -0
  150. package/server/lib/openchamber-sessions/session-metadata-store.test.js +259 -0
  151. package/server/lib/opencode/DOCUMENTATION.md +458 -29
  152. package/server/lib/opencode/agents.js +233 -327
  153. package/server/lib/opencode/auth.js +41 -44
  154. package/server/lib/opencode/auth.test.js +92 -0
  155. package/server/lib/opencode/bootstrap-runtime.js +12 -0
  156. package/server/lib/opencode/cli-upgrade.d.ts +4 -0
  157. package/server/lib/opencode/cli-upgrade.js +18 -0
  158. package/server/lib/opencode/cli-upgrade.test.js +36 -0
  159. package/server/lib/opencode/commands.js +164 -145
  160. package/server/lib/opencode/compatibility.d.ts +16 -0
  161. package/server/lib/opencode/compatibility.js +91 -0
  162. package/server/lib/opencode/compatibility.test.js +70 -0
  163. package/server/lib/opencode/config-entity-routes.js +58 -29
  164. package/server/lib/opencode/config-entity-v2.test.js +290 -0
  165. package/server/lib/opencode/config-mutation-response.js +17 -7
  166. package/server/lib/opencode/config-mutation-response.test.js +4 -7
  167. package/server/lib/opencode/config-paths.test.js +2 -2
  168. package/server/lib/opencode/config-v2.d.ts +185 -0
  169. package/server/lib/opencode/config-v2.js +843 -0
  170. package/server/lib/opencode/config-v2.test.js +483 -0
  171. package/server/lib/opencode/core-routes.js +3 -0
  172. package/server/lib/opencode/core-routes.test.js +15 -0
  173. package/server/lib/opencode/credential-db.js +144 -0
  174. package/server/lib/opencode/credential-db.test.js +104 -0
  175. package/server/lib/opencode/env-runtime.js +47 -15
  176. package/server/lib/opencode/env-runtime.test.js +45 -0
  177. package/server/lib/opencode/feature-routes-runtime.js +16 -5
  178. package/server/lib/opencode/lifecycle-process.test.js +7 -4
  179. package/server/lib/opencode/lifecycle.js +113 -30
  180. package/server/lib/opencode/lifecycle.test.js +107 -8
  181. package/server/lib/opencode/login-shell-env.js +27 -0
  182. package/server/lib/opencode/managed-config-file.js +131 -0
  183. package/server/lib/opencode/managed-config-file.test.js +168 -0
  184. package/server/lib/opencode/managed-plugin-config.js +33 -13
  185. package/server/lib/opencode/mcp.js +43 -149
  186. package/server/lib/opencode/network-runtime.js +6 -7
  187. package/server/lib/opencode/openchamber-routes.js +29 -11
  188. package/server/lib/opencode/openchamber-routes.test.js +18 -1
  189. package/server/lib/opencode/plugin-routes.js +3 -3
  190. package/server/lib/opencode/plugin-routes.test.js +6 -24
  191. package/server/lib/opencode/plugins.js +91 -40
  192. package/server/lib/opencode/plugins.test.js +28 -15
  193. package/server/lib/opencode/provider-source-route.test.js +59 -0
  194. package/server/lib/opencode/providers.js +66 -83
  195. package/server/lib/opencode/providers.test.js +190 -59
  196. package/server/lib/opencode/proxy-agent-wiring.test.js +4 -2
  197. package/server/lib/opencode/proxy.js +179 -129
  198. package/server/lib/opencode/pwa-manifest-routes.js +4 -2
  199. package/server/lib/opencode/pwa-manifest-routes.test.js +3 -2
  200. package/server/lib/opencode/response-envelope.js +14 -0
  201. package/server/lib/opencode/response-envelope.test.js +23 -0
  202. package/server/lib/opencode/routes-upgrade.test.js +73 -116
  203. package/server/lib/opencode/routes.js +138 -428
  204. package/server/lib/opencode/server-utils-runtime.js +10 -4
  205. package/server/lib/opencode/session-activity.js +78 -0
  206. package/server/lib/opencode/session-runtime.js +21 -10
  207. package/server/lib/opencode/session-runtime.test.js +9 -9
  208. package/server/lib/opencode/settings-helpers.js +15 -8
  209. package/server/lib/opencode/settings-helpers.test.js +7 -12
  210. package/server/lib/opencode/settings-registry.json +20 -8
  211. package/server/lib/opencode/settings-runtime.js +19 -1
  212. package/server/lib/opencode/settings-runtime.test.js +31 -2
  213. package/server/lib/opencode/shared.js +86 -24
  214. package/server/lib/opencode/shared.test.js +87 -5
  215. package/server/lib/opencode/shutdown-runtime.js +54 -7
  216. package/server/lib/opencode/shutdown-runtime.test.js +224 -30
  217. package/server/lib/opencode/skill-routes.js +51 -36
  218. package/server/lib/opencode/skill-routes.test.js +121 -1
  219. package/server/lib/opencode/skills.js +7 -5
  220. package/server/lib/opencode/tunnel-wiring-runtime.js +2 -1
  221. package/server/lib/opencode/upgrade-capability.js +0 -14
  222. package/server/lib/opencode/upgrade-capability.test.js +1 -1
  223. package/server/lib/opencode/v1-migration-topup.js +294 -0
  224. package/server/lib/opencode/v1-migration-topup.test.js +274 -0
  225. package/server/lib/opencode/v2-install.d.ts +9 -0
  226. package/server/lib/opencode/v2-install.js +159 -0
  227. package/server/lib/opencode/v2-install.test.js +133 -0
  228. package/server/lib/opencode/watcher.js +10 -3
  229. package/server/lib/opencode/watcher.test.js +17 -21
  230. package/server/lib/opencode/websearch-config.js +78 -0
  231. package/server/lib/permission-auto-accept/runtime.js +38 -22
  232. package/server/lib/permission-auto-accept/runtime.test.js +39 -17
  233. package/server/lib/quota/DOCUMENTATION.md +4 -0
  234. package/server/lib/quota/providers/kimi.js +1 -1
  235. package/server/lib/quota/providers/xai.js +4 -4
  236. package/server/lib/relay/tunnel-host.js +4 -1
  237. package/server/lib/relay/tunnel-host.test.js +7 -0
  238. package/server/lib/routing/DOCUMENTATION.md +52 -21
  239. package/server/lib/routing/defaults.js +23 -6
  240. package/server/lib/routing/jev.js +17 -7
  241. package/server/lib/routing/routes.http.test.js +68 -33
  242. package/server/lib/routing/routes.js +65 -22
  243. package/server/lib/routing/runtime.js +145 -48
  244. package/server/lib/routing/runtime.test.js +79 -55
  245. package/server/lib/scheduled-tasks/DOCUMENTATION.md +4 -0
  246. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +51 -46
  247. package/server/lib/scheduled-tasks/runtime.js +81 -74
  248. package/server/lib/scheduled-tasks/runtime.test.js +53 -1
  249. package/server/lib/session-assist/DOCUMENTATION.md +25 -8
  250. package/server/lib/session-assist/context.js +122 -46
  251. package/server/lib/session-assist/context.test.js +117 -49
  252. package/server/lib/session-assist/runtime.js +71 -24
  253. package/server/lib/session-assist/runtime.test.js +153 -173
  254. package/server/lib/session-goal/DOCUMENTATION.md +34 -15
  255. package/server/lib/session-goal/create.js +9 -12
  256. package/server/lib/session-goal/create.test.js +27 -28
  257. package/server/lib/session-goal/runtime.js +164 -77
  258. package/server/lib/session-goal/runtime.test.js +271 -519
  259. package/server/lib/session-knowledge/DOCUMENTATION.md +5 -0
  260. package/server/lib/session-knowledge/runtime.js +59 -41
  261. package/server/lib/session-knowledge/runtime.test.js +90 -20
  262. package/server/lib/small-model/DOCUMENTATION.md +154 -208
  263. package/server/lib/small-model/client.js +113 -0
  264. package/server/lib/small-model/index.js +296 -158
  265. package/server/lib/small-model/index.test.js +423 -256
  266. package/server/lib/small-model/routes.js +1 -1
  267. package/server/lib/spaces/DOCUMENTATION.md +807 -0
  268. package/server/lib/spaces/code-in-bait.js +185 -0
  269. package/server/lib/spaces/code-in.js +641 -0
  270. package/server/lib/spaces/code-in.test.js +1048 -0
  271. package/server/lib/spaces/errors.js +8 -0
  272. package/server/lib/spaces/exec-http.js +94 -0
  273. package/server/lib/spaces/gatekeeper-channel.js +202 -0
  274. package/server/lib/spaces/gatekeeper-channel.test.js +215 -0
  275. package/server/lib/spaces/gatekeeper-program.cjs +914 -0
  276. package/server/lib/spaces/gatekeeper-program.test.js +1391 -0
  277. package/server/lib/spaces/hardening.js +457 -0
  278. package/server/lib/spaces/hardening.test.js +368 -0
  279. package/server/lib/spaces/host-git.js +127 -0
  280. package/server/lib/spaces/host-git.test.js +137 -0
  281. package/server/lib/spaces/labels.js +234 -0
  282. package/server/lib/spaces/labels.test.js +219 -0
  283. package/server/lib/spaces/layout.js +184 -0
  284. package/server/lib/spaces/layout.test.js +30 -0
  285. package/server/lib/spaces/manager.js +82 -0
  286. package/server/lib/spaces/manager.test.js +114 -0
  287. package/server/lib/spaces/places/code-in.docker.live.test.js +216 -0
  288. package/server/lib/spaces/places/contract-suite.js +156 -0
  289. package/server/lib/spaces/places/contract.docker.live.test.js +7 -0
  290. package/server/lib/spaces/places/contract.test.js +6 -0
  291. package/server/lib/spaces/places/docker-engine.js +126 -0
  292. package/server/lib/spaces/places/docker-live-support.js +202 -0
  293. package/server/lib/spaces/places/docker-tools.js +186 -0
  294. package/server/lib/spaces/places/docker.js +587 -0
  295. package/server/lib/spaces/places/docker.test.js +1610 -0
  296. package/server/lib/spaces/places/escape-suite.js +1018 -0
  297. package/server/lib/spaces/places/escape.docker.live.test.js +7 -0
  298. package/server/lib/spaces/places/fake-docker.js +375 -0
  299. package/server/lib/spaces/places/memory-place.js +103 -0
  300. package/server/lib/spaces/places/packed.docker.live.test.js +77 -0
  301. package/server/lib/spaces/places/registry.js +43 -0
  302. package/server/lib/spaces/places/registry.test.js +50 -0
  303. package/server/lib/spaces/places/server.docker.live.test.js +225 -0
  304. package/server/lib/spaces/run-command.js +261 -0
  305. package/server/lib/spaces/run-command.test.js +396 -0
  306. package/server/lib/spaces/space-server.js +190 -0
  307. package/server/lib/spaces/space-server.test.js +335 -0
  308. package/server/lib/spaces/tools-filler.js +82 -0
  309. package/server/lib/spaces/tools-filler.test.js +148 -0
  310. package/server/lib/spaces/tools-pack.js +49 -0
  311. package/server/lib/spaces/tools-pack.test.js +57 -0
  312. package/server/lib/spaces/tools.js +137 -0
  313. package/server/lib/spaces/tools.test.js +153 -0
  314. package/server/lib/tts/openai-sdk.js +11 -0
  315. package/server/lib/tts/service.js +7 -5
  316. package/server/lib/tts/stt.js +3 -2
  317. package/server/lib/tunnels/DOCUMENTATION.md +2 -0
  318. package/server/lib/tunnels/routes.js +7 -0
  319. package/server/lib/tunnels/routes.test.js +55 -0
  320. package/server/lib/ui-auth/ui-auth.js +38 -2
  321. package/server/lib/ui-auth/ui-auth.test.js +42 -0
  322. package/server/lib/ui-auth/ui-passkeys.js +12 -10
  323. package/server/lib/walkthrough/DOCUMENTATION.md +10 -1
  324. package/server/lib/walkthrough/pull-request.js +61 -8
  325. package/server/lib/walkthrough/pull-request.test.js +54 -1
  326. package/server/lib/walkthrough/routes.js +20 -0
  327. package/server/lib/walkthrough/routes.test.js +19 -0
  328. package/server/opencode-proxy.test.js +190 -166
  329. package/server/opencode-worktree-readiness.test.js +5 -4
  330. package/dist/assets/DiffView-Ce0oBXXQ.js +0 -4
  331. package/dist/assets/FilesView-DtXueAWP.js +0 -13
  332. package/dist/assets/LinearIssuesView-z_9p2GuO.js +0 -1
  333. package/dist/assets/MarkdownImageGallery-BC-BNN-s.js +0 -1
  334. package/dist/assets/MarkdownRendererImpl-DyaBTUbH.js +0 -12
  335. package/dist/assets/OnboardingScreen-DKU_yTb6.js +0 -1
  336. package/dist/assets/PlanView-CrfB4qqY.js +0 -5
  337. package/dist/assets/PluginPane-B5cn-jPy.js +0 -3
  338. package/dist/assets/SettingsView-DMKKwezx.js +0 -29
  339. package/dist/assets/SettingsWindow-DwbnVzOC.js +0 -1
  340. package/dist/assets/SubmoduleDiffSummary-hkGcvs0E.js +0 -1
  341. package/dist/assets/ToolOutputDialog-DuoIOc0j.js +0 -15
  342. package/dist/assets/ToolPartDiffPreview-t1Bvq_2Y.js +0 -8
  343. package/dist/assets/appThemeRegistry-DnOVbJjF.js +0 -1
  344. package/dist/assets/commitAndPush-DLWNZkkY.js +0 -1
  345. package/dist/assets/de-zEHaAIi3.js +0 -10
  346. package/dist/assets/es-CBDgEzgk.js +0 -16
  347. package/dist/assets/fr-DjiTptT_.js +0 -14
  348. package/dist/assets/index-AgOdanig.css +0 -1
  349. package/dist/assets/index-B-2_X4DD.js +0 -40
  350. package/dist/assets/index-CkA4p2IK.js +0 -1
  351. package/dist/assets/ja-CerMgj3r.js +0 -16
  352. package/dist/assets/ko-DHYDAze5.js +0 -16
  353. package/dist/assets/main-BDka4W43.js +0 -896
  354. package/dist/assets/main-Dl7Dyge_.js +0 -2
  355. package/dist/assets/markdownCore-DFmr0rUR.js +0 -5
  356. package/dist/assets/miniChat-CLKQPPpO.js +0 -2
  357. package/dist/assets/mobile--giD2Q1L.js +0 -2
  358. package/dist/assets/patchFileDiff-DRh-AQvd.js +0 -13
  359. package/dist/assets/pl-BTB_93bq.js +0 -16
  360. package/dist/assets/pt-BR-BwA3oyCK.js +0 -16
  361. package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +0 -2
  362. package/dist/assets/renderMobileApp-pMfOuQfl.js +0 -25
  363. package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +0 -25
  364. package/dist/assets/scheduledTasksApi-CeRAIUmW.js +0 -1
  365. package/dist/assets/tr-CcPsJoNM.js +0 -7
  366. package/dist/assets/uk-B68WibXi.js +0 -16
  367. package/dist/assets/useAppFontEffects-DcdrFv2Z.js +0 -7333
  368. package/dist/assets/useInlineCommentController-Cq4SUjsA.js +0 -2
  369. package/dist/assets/useRootScrollLock-CSdR6Wnm.js +0 -2
  370. package/dist/assets/vendor-cron-parser-CUcP7OfX.js +0 -2
  371. package/dist/assets/vendor-opencode-sdk-BJ73u-bH.js +0 -7
  372. package/dist/assets/vendor-zod-CgAdXWZO.js +0 -39
  373. package/dist/assets/zh-CN-DbFHYXwP.js +0 -16
  374. package/dist/assets/zh-TW-DmXAwdty.js +0 -16
  375. package/server/lib/opencode/mcp-oauth-callback.test.js +0 -111
  376. package/server/lib/routing/feature-flag.js +0 -11
  377. package/server/lib/small-model/call.js +0 -851
  378. package/server/lib/small-model/call.test.js +0 -1292
  379. package/server/lib/small-model/catalog.js +0 -13
  380. package/server/lib/small-model/resolve.js +0 -131
  381. package/server/lib/small-model/resolve.test.js +0 -197
  382. package/server/lib/small-model/runtime-providers.js +0 -164
  383. package/server/lib/small-model/runtime-providers.test.js +0 -118
  384. package/server/lib/system-prompt/DOCUMENTATION.md +0 -36
  385. package/server/lib/system-prompt/runtime.js +0 -49
  386. package/server/lib/system-prompt/runtime.test.js +0 -76
  387. package/server/lib/walkthrough/reproduce-2607.test.js +0 -148
@@ -69,15 +69,22 @@ describe('notification template message extraction', () => {
69
69
 
70
70
  it('excludes reasoning parts when fetching assistant messages', async () => {
71
71
  const runtime = createRuntime();
72
- globalThis.fetch = vi.fn(async () => new Response(JSON.stringify([
73
- {
74
- info: { id: 'msg-1', role: 'assistant', finish: 'stop' },
75
- parts: [
76
- { type: 'reasoning', text: 'private chain of thought' },
77
- { type: 'text', text: 'final answer' },
78
- ],
79
- },
80
- ])));
72
+ // v2 pages messages as `{ data, cursor }` and an assistant message is a
73
+ // flat record carrying `content[]`.
74
+ globalThis.fetch = vi.fn(async () => new Response(JSON.stringify({
75
+ data: [
76
+ {
77
+ id: 'msg-1',
78
+ type: 'assistant',
79
+ finish: 'stop',
80
+ content: [
81
+ { type: 'reasoning', text: 'private chain of thought' },
82
+ { type: 'text', text: 'final answer' },
83
+ ],
84
+ },
85
+ ],
86
+ cursor: {},
87
+ })));
81
88
 
82
89
  await expect(runtime.fetchLastAssistantMessageText('session-1', 'msg-1')).resolves.toBe('final answer');
83
90
  });
@@ -0,0 +1,187 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ import { createNotificationTriggerRuntime } from './runtime.js';
4
+
5
+ /**
6
+ * The "ready" push is built from the translated `message.updated` events.
7
+ * v2 splits a turn: the step start names agent and model, the step end
8
+ * carries the finish. What is pinned here: the finish is announced with the
9
+ * agent and model from the start, a user abort announces nothing, and an
10
+ * active goal (which lives in OpenChamber's own metadata) silences the push.
11
+ */
12
+ const makeRuntime = ({ metadata = {} } = {}) => {
13
+ const emitDesktopNotification = vi.fn(() => true);
14
+ const runtime = createNotificationTriggerRuntime({
15
+ readSettingsFromDisk: async () => ({ nativeNotificationsEnabled: true, notificationMode: 'always', notifyOnCompletion: true }),
16
+ prepareNotificationLastMessage: async ({ message }) => message,
17
+ buildTemplateVariables: async () => ({}),
18
+ extractLastMessageText: () => 'done',
19
+ fetchLastAssistantMessageText: async () => 'done',
20
+ resolveNotificationTemplate: () => '',
21
+ shouldApplyResolvedTemplateMessage: () => false,
22
+ emitDesktopNotification,
23
+ broadcastUiNotification: vi.fn(),
24
+ sendPushToAllUiSessions: vi.fn(async () => undefined),
25
+ sendApnsToAllUiSessions: vi.fn(async () => undefined),
26
+ isAnyInteractiveClientVisible: () => true,
27
+ buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
28
+ getOpenCodeAuthHeaders: () => ({}),
29
+ readSessionMetadata: async () => metadata,
30
+ });
31
+ return { runtime, emitDesktopNotification };
32
+ };
33
+
34
+ const stepStarted = (sessionID, id) => ({
35
+ type: 'message.updated',
36
+ properties: { sessionID, info: { id, sessionID, role: 'assistant', agent: 'build', providerID: 'anthropic', modelID: 'claude-sonnet-5', time: { created: 1 } } },
37
+ });
38
+ const stepEnded = (sessionID, id) => ({
39
+ type: 'message.updated',
40
+ properties: { sessionID, info: { id, sessionID, role: 'assistant', finish: 'stop', time: { completed: 2 } } },
41
+ });
42
+
43
+ const turnEnded = (sessionID) => ({ type: 'session.idle', properties: { sessionID } });
44
+
45
+ describe('ready notification on v2 step events', () => {
46
+ it('announces the turn end with the agent and model of its last step', async () => {
47
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
48
+ const { runtime, emitDesktopNotification } = makeRuntime();
49
+
50
+ await runtime.maybeSendPushForTrigger(stepStarted('ses_1', 'msg_1'));
51
+ expect(emitDesktopNotification).not.toHaveBeenCalled();
52
+
53
+ // A step's `stop` is not the end of the turn: the execution may still
54
+ // drain steering input, so only its idle event announces readiness.
55
+ await runtime.maybeSendPushForTrigger(stepEnded('ses_1', 'msg_1'));
56
+ expect(emitDesktopNotification).not.toHaveBeenCalled();
57
+
58
+ await runtime.maybeSendPushForTrigger(turnEnded('ses_1'));
59
+ expect(emitDesktopNotification).toHaveBeenCalledTimes(1);
60
+ expect(emitDesktopNotification.mock.calls[0][0]).toMatchObject({
61
+ kind: 'ready',
62
+ title: 'Build agent is ready',
63
+ body: 'Claude Sonnet 5 completed the task',
64
+ });
65
+ });
66
+
67
+ it('announces nothing for a user abort', async () => {
68
+ const { runtime, emitDesktopNotification } = makeRuntime();
69
+
70
+ await runtime.maybeSendPushForTrigger({
71
+ type: 'session.idle',
72
+ properties: { sessionID: 'ses_2', aborted: true, reason: 'user', error: { name: 'MessageAbortedError', message: 'aborted' } },
73
+ });
74
+
75
+ expect(emitDesktopNotification).not.toHaveBeenCalled();
76
+ });
77
+
78
+ it('stays quiet while a goal from OpenChamber\'s own metadata is active', async () => {
79
+ const { runtime, emitDesktopNotification } = makeRuntime({
80
+ metadata: { openchamber: { goal: { id: 'g', status: 'active', objective: 'x' } } },
81
+ });
82
+
83
+ await runtime.maybeSendPushForTrigger(stepStarted('ses_3', 'msg_3'));
84
+ await runtime.maybeSendPushForTrigger(stepEnded('ses_3', 'msg_3'));
85
+ await runtime.maybeSendPushForTrigger(turnEnded('ses_3'));
86
+
87
+ expect(emitDesktopNotification).not.toHaveBeenCalled();
88
+ });
89
+ });
90
+
91
+ describe('ready notification while background subagents run', () => {
92
+ const stubOpenCode = ({ active, children }) => {
93
+ vi.stubGlobal('fetch', vi.fn(async (input) => {
94
+ const url = new URL(String(input));
95
+ if (url.pathname === '/api/session/active') return Response.json({ data: active() });
96
+ if (url.pathname === '/api/session') return Response.json({ data: children, cursor: {} });
97
+ return Response.json({});
98
+ }));
99
+ };
100
+
101
+ it('stays silent on the pause and announces the real turn end', async () => {
102
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
103
+ let active = { ses_child: { type: 'running' } };
104
+ stubOpenCode({ active: () => active, children: [{ id: 'ses_child', parentID: 'ses_1' }] });
105
+ const { runtime, emitDesktopNotification } = makeRuntime();
106
+
107
+ await runtime.maybeSendPushForTrigger(stepStarted('ses_1', 'msg_1'));
108
+ await runtime.maybeSendPushForTrigger(turnEnded('ses_1'));
109
+ expect(emitDesktopNotification).not.toHaveBeenCalled();
110
+
111
+ // The subagent finished and OpenCode ran the parent again with its result.
112
+ active = {};
113
+ await runtime.maybeSendPushForTrigger(turnEnded('ses_1'));
114
+ expect(emitDesktopNotification).toHaveBeenCalledTimes(1);
115
+ vi.unstubAllGlobals();
116
+ });
117
+
118
+ it('announces the idle when the subagent check cannot be made', async () => {
119
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
120
+ vi.stubGlobal('fetch', vi.fn(async () => new Response('down', { status: 503 })));
121
+ const { runtime, emitDesktopNotification } = makeRuntime();
122
+
123
+ await runtime.maybeSendPushForTrigger(stepStarted('ses_1', 'msg_1'));
124
+ await runtime.maybeSendPushForTrigger(turnEnded('ses_1'));
125
+ expect(emitDesktopNotification).toHaveBeenCalledTimes(1);
126
+ vi.unstubAllGlobals();
127
+ });
128
+ });
129
+
130
+ describe('subagent finish with subagent notifications off', () => {
131
+ const makeSubtaskRuntime = () => {
132
+ const emitDesktopNotification = vi.fn(() => true);
133
+ const runtime = createNotificationTriggerRuntime({
134
+ readSettingsFromDisk: async () => ({ nativeNotificationsEnabled: true, notificationMode: 'always', notifyOnCompletion: true, notifyOnSubtasks: false }),
135
+ prepareNotificationLastMessage: async ({ message }) => message,
136
+ buildTemplateVariables: async () => ({}),
137
+ extractLastMessageText: () => 'done',
138
+ fetchLastAssistantMessageText: async () => 'done',
139
+ resolveNotificationTemplate: () => '',
140
+ shouldApplyResolvedTemplateMessage: () => false,
141
+ emitDesktopNotification,
142
+ broadcastUiNotification: vi.fn(),
143
+ sendPushToAllUiSessions: vi.fn(async () => undefined),
144
+ sendApnsToAllUiSessions: vi.fn(async () => undefined),
145
+ isAnyInteractiveClientVisible: () => true,
146
+ buildOpenCodeUrl: (path) => `http://opencode.test${path}`,
147
+ getOpenCodeAuthHeaders: () => ({}),
148
+ readSessionMetadata: async () => ({}),
149
+ });
150
+ return { runtime, emitDesktopNotification };
151
+ };
152
+
153
+ // OpenCode answers `GET /api/session/:id` as `{ data }` with no `location`.
154
+ const stubSessionRecord = () => {
155
+ vi.stubGlobal('fetch', vi.fn(async (input) => {
156
+ const url = new URL(String(input));
157
+ if (url.pathname === '/api/session/active') return Response.json({ data: {} });
158
+ if (url.pathname === '/api/session/ses_child') return Response.json({ data: { id: 'ses_child', parentID: 'ses_parent' } });
159
+ return Response.json({ data: [], cursor: {} });
160
+ }));
161
+ };
162
+
163
+ it('reads the parent from the session record envelope', async () => {
164
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
165
+ stubSessionRecord();
166
+ const { runtime, emitDesktopNotification } = makeSubtaskRuntime();
167
+
168
+ await runtime.maybeSendPushForTrigger(stepStarted('ses_child', 'msg_c'));
169
+ await runtime.maybeSendPushForTrigger(turnEnded('ses_child'));
170
+ expect(emitDesktopNotification).not.toHaveBeenCalled();
171
+ vi.unstubAllGlobals();
172
+ });
173
+
174
+ it('a partial session update does not erase a known parent', async () => {
175
+ vi.spyOn(console, 'warn').mockImplementation(() => {});
176
+ vi.stubGlobal('fetch', vi.fn(async () => new Response('down', { status: 503 })));
177
+ const { runtime, emitDesktopNotification } = makeSubtaskRuntime();
178
+
179
+ await runtime.maybeSendPushForTrigger({ type: 'session.created', properties: { sessionID: 'ses_child', info: { id: 'ses_child', parentID: 'ses_parent' } } });
180
+ // Usage updates arrive as `session.updated` with a partial record.
181
+ await runtime.maybeSendPushForTrigger({ type: 'session.updated', properties: { sessionID: 'ses_child', info: { id: 'ses_child', cost: 1 } } });
182
+ await runtime.maybeSendPushForTrigger(stepStarted('ses_child', 'msg_c'));
183
+ await runtime.maybeSendPushForTrigger(turnEnded('ses_child'));
184
+ expect(emitDesktopNotification).not.toHaveBeenCalled();
185
+ vi.unstubAllGlobals();
186
+ });
187
+ });
@@ -59,6 +59,16 @@ other.
59
59
  directory and does not erase other session results.
60
60
  - Destructive session/worktree deletion and project-path registration are not
61
61
  part of the action contract.
62
+ - `file.open` shows a file in the user's viewer. `file-open.js` resolves a
63
+ relative path against the session directory (an explicit `directory` wins),
64
+ refuses a relative path with no directory at all, checks the target is an
65
+ existing file, then hands `{ path, directory, sessionId }` to the injected
66
+ `emit`, which `index.js` writes to every UI control stream as
67
+ `openchamber:file-open-request`. Nothing comes back: opening a tab does not
68
+ fail quietly on a client, so the count of clients reached is the signal, and
69
+ zero is a 503, never a claimed success. Paths outside the workspace are
70
+ allowed on purpose: screenshots and recordings often land in a temp
71
+ directory, and the viewer already reads such files.
62
72
  - `browser.capture` writes its image on the server, into
63
73
  `.openchamber/screenshots/` under the scoped project directory, and returns
64
74
  the project-relative path rather than the image bytes. The client that took
@@ -22,6 +22,7 @@ export const OPENCHAMBER_CONTROL_ACTION_DEFINITIONS = Object.freeze([
22
22
  { action: 'schedule.run', title: 'Run a scheduled task', description: 'Run taskId; scope with projectId or directory' },
23
23
  { action: 'schedule.delete', title: 'Delete a scheduled task', description: 'Delete taskId; scope with projectId or directory' },
24
24
  { action: 'schedule.toggle', title: 'Enable or disable a scheduled task', description: 'Enable or disable taskId; requires the disabled boolean' },
25
+ { action: 'file.open', title: 'Show a file to the user', description: 'Open path in the user\'s file panel, in front of whatever they had open, so they can look at a result you produced: a screenshot, report, CSV, recording, or generated page. Relative to the session directory. Use it only when seeing the file moves the work forward, not for every file you touch' },
25
26
  ]);
26
27
 
27
28
  const OPENCHAMBER_CONTROL_ACTIONS = Object.freeze(
@@ -37,8 +38,8 @@ export const OPENCHAMBER_AGENT_TOOL_ACTIONS = Object.freeze(
37
38
  );
38
39
 
39
40
  export const OPENCHAMBER_WEB_ACTION_DEFINITIONS = Object.freeze([
40
- { action: 'browser.open', title: 'Open a page in the browser panel', description: 'Open url in the in-app browser panel; use it to look at the running app. Set viewport to mobile, tablet or desktop to lay the page out at that size' },
41
- { action: 'browser.snapshot', title: 'Read the open page', description: 'Read the open page: url, title, visible text, and interactive elements with the selectors the other browser actions accept. Pass selector to read only that part of a long page. Reports any errors the page logged' },
41
+ { action: 'browser.open', title: 'Open a page in the browser panel', description: 'Open url in the in-app browser panel; use it to look at the running app. Without tabId it opens a new background tab and answers with its tabId: pass that tabId to the following actions to keep working there. With tabId it loads url in that tab. Set viewport to mobile, tablet or desktop to lay the page out at that size' },
42
+ { action: 'browser.snapshot', title: 'Read the open page', description: 'Read the open page: url, title, visible text, and interactive elements with the selectors the other browser actions accept. Pass selector to read only that part of a long page. Reports any errors the page logged, and lists the open tabs with the ids tabId accepts' },
42
43
  { action: 'browser.click', title: 'Click on the open page', description: 'Click an element; give selector, or text to match a link or button by its visible label' },
43
44
  { action: 'browser.type', title: 'Type into the open page', description: 'Type value into the field matched by selector; set submit to press Enter afterwards' },
44
45
  { action: 'browser.scroll', title: 'Scroll the open page', description: 'Scroll the page; direction is up, down, top, or bottom, or pass selector to bring one element into view' },
@@ -65,9 +66,9 @@ export const OPENCHAMBER_WEB_ACTIONS = Object.freeze(
65
66
  * reads as a complete fact is exactly the one whose conditions get lost.
66
67
  */
67
68
  export const OPENCHAMBER_MEMORY_ACTION_DEFINITIONS = Object.freeze([
68
- { action: 'memory.read', title: 'Read a stored memory', description: 'Read the full text of one memory listed in the session index. The index shows titles only, and a title omits the conditions that decide how the memory applies, so read before acting rather than working from the title. Requires title (as the index spells it) or memoryId; scope is optional and both stores are searched without it' },
69
+ { action: 'memory.read', title: 'Read a stored memory', description: 'Read the full text of one memory listed in the session index. The index shows titles only, and a title omits the conditions that decide how the memory applies, so read before acting rather than working from the title. Once read, an entry stays in your context; do not read it again in the same conversation. Requires title (as the index spells it) or memoryId; scope is optional and both stores are searched without it' },
69
70
  { action: 'memory.list', title: 'List stored memories', description: 'List stored memory titles when the session index is missing or stale; scope is global, project, or both (default)' },
70
- { action: 'memory.save', title: 'Remember something', description: 'Store a durable fact, preference, or reference; requires title and body, plus scope global (about the user) or project (about this codebase). Restating something already stored updates it. Do not store secrets, one-off task state, or anything the user asked you not to keep' },
71
+ { action: 'memory.save', title: 'Remember something', description: 'Store a durable fact, preference, or reference; requires title and body, plus scope global (about the user) or project (about this codebase). Restating something already stored updates it. Do not store secrets, one-off task state, or anything the user asked you not to keep; when the user explicitly asks you to remember something, store it unless it is a secret' },
71
72
  { action: 'memory.delete', title: 'Forget a memory', description: 'Delete a memory that turned out to be wrong or obsolete; requires memoryId and scope' },
72
73
  ]);
73
74
 
@@ -75,6 +76,18 @@ export const OPENCHAMBER_MEMORY_ACTIONS = Object.freeze(
75
76
  OPENCHAMBER_MEMORY_ACTION_DEFINITIONS.map(({ action }) => action),
76
77
  );
77
78
 
79
+ /**
80
+ * Notify is its own tool so it can stay off by default and disappear
81
+ * completely: an agent that can page the user is a choice the user makes.
82
+ */
83
+ export const OPENCHAMBER_NOTIFY_ACTION_DEFINITIONS = Object.freeze([
84
+ { action: 'notify.send', title: 'Notify the user', description: 'Send the user a notification; requires title, body is optional. By default it appears only while the user is away from OpenChamber; set showWhenFocused only when it cannot wait' },
85
+ ]);
86
+
87
+ export const OPENCHAMBER_NOTIFY_ACTIONS = Object.freeze(
88
+ OPENCHAMBER_NOTIFY_ACTION_DEFINITIONS.map(({ action }) => action),
89
+ );
90
+
78
91
  /**
79
92
  * Which actions each managed tool may ask for.
80
93
  *
@@ -89,6 +102,7 @@ const ACTIONS_BY_TOOL = Object.freeze({
89
102
  openchamber: OPENCHAMBER_AGENT_TOOL_ACTIONS,
90
103
  openchamber_web: OPENCHAMBER_WEB_ACTIONS,
91
104
  openchamber_memory: OPENCHAMBER_MEMORY_ACTIONS,
105
+ openchamber_notify: OPENCHAMBER_NOTIFY_ACTIONS,
92
106
  });
93
107
 
94
108
  const bareName = (action) => {
@@ -135,4 +149,5 @@ export const OPENCHAMBER_ALL_ACTIONS = Object.freeze([
135
149
  ...OPENCHAMBER_CONTROL_ACTIONS,
136
150
  ...OPENCHAMBER_WEB_ACTIONS,
137
151
  ...OPENCHAMBER_MEMORY_ACTIONS,
152
+ ...OPENCHAMBER_NOTIFY_ACTIONS,
138
153
  ]);
@@ -10,7 +10,7 @@ export class OpenChamberControlError extends Error {
10
10
  export const asControlError = (error, fallbackMessage, fallbackStatus = 500) => {
11
11
  if (error instanceof OpenChamberControlError) return error;
12
12
  const message = error instanceof Error ? error.message : fallbackMessage;
13
- return new OpenChamberControlError(message || fallbackMessage, Number(error?.statusCode) || fallbackStatus, {
13
+ return new OpenChamberControlError(message || fallbackMessage, Number(error?.statusCode) || Number(error?.status) || fallbackStatus, {
14
14
  ...(error?.goalConfigured === true ? { goalConfigured: true } : {}),
15
15
  });
16
16
  };
@@ -0,0 +1,59 @@
1
+ /**
2
+ * The agent asking the user to look at a file.
3
+ *
4
+ * The viewer lives in a renderer, so the server cannot open anything itself;
5
+ * it checks that the file is really there and tells every connected client to
6
+ * show it. No answer comes back: opening a tab is not something that fails
7
+ * quietly on the client, and the agent only needs to know whether anyone was
8
+ * there to see it.
9
+ */
10
+ import path from 'node:path';
11
+ import fsPromises from 'node:fs/promises';
12
+
13
+ import { OpenChamberControlError } from './error.js';
14
+
15
+ /**
16
+ * @param {{
17
+ * emit: (request: { path: string, directory: string | null, sessionId: string | null }) => number,
18
+ * stat?: (target: string) => Promise<{ isFile(): boolean, size: number }>,
19
+ * }} dependencies
20
+ */
21
+ export const createFileOpenRequester = ({ emit, stat = (target) => fsPromises.stat(target) }) => {
22
+ /** `path` arrives already reduced to a trimmed string or null by the service. */
23
+ const request = async ({ path: raw, directory, sessionId }) => {
24
+ if (!raw) throw new OpenChamberControlError('path is required for file.open', 400);
25
+
26
+ // A relative path means "in the project I am working in"; without a
27
+ // project there is nothing to resolve it against.
28
+ let absolute;
29
+ if (path.isAbsolute(raw)) {
30
+ absolute = path.normalize(raw);
31
+ } else if (directory) {
32
+ absolute = path.resolve(directory, raw);
33
+ } else {
34
+ throw new OpenChamberControlError('path must be absolute when no session directory is known', 400);
35
+ }
36
+
37
+ let stats;
38
+ try {
39
+ stats = await stat(absolute);
40
+ } catch (error) {
41
+ if (error?.code === 'ENOENT') {
42
+ throw new OpenChamberControlError(`File not found: ${absolute}`, 404);
43
+ }
44
+ throw new OpenChamberControlError(`Cannot read ${absolute}: ${error instanceof Error ? error.message : String(error)}`, 500);
45
+ }
46
+ if (!stats.isFile()) {
47
+ throw new OpenChamberControlError(`Not a file: ${absolute}`, 400);
48
+ }
49
+
50
+ const delivered = emit({ path: absolute, directory: directory ?? null, sessionId: sessionId ?? null });
51
+ if (delivered === 0) {
52
+ throw new OpenChamberControlError('No OpenChamber window is connected to show the file', 503);
53
+ }
54
+
55
+ return { path: absolute, size: stats.size, opened: true };
56
+ };
57
+
58
+ return { request };
59
+ };
@@ -0,0 +1,57 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+
3
+ import { createFileOpenRequester } from './file-open.js';
4
+
5
+ const file = { isFile: () => true, size: 42 };
6
+
7
+ describe('createFileOpenRequester', () => {
8
+ it('resolves a relative path against the session directory and tells the clients', async () => {
9
+ const emit = vi.fn(() => 2);
10
+ const stat = vi.fn(async () => file);
11
+ const requester = createFileOpenRequester({ emit, stat });
12
+
13
+ const result = await requester.request({ path: 'out/report.csv', directory: '/repo', sessionId: 'ses_1' });
14
+
15
+ expect(stat).toHaveBeenCalledWith('/repo/out/report.csv');
16
+ expect(emit).toHaveBeenCalledWith({ path: '/repo/out/report.csv', directory: '/repo', sessionId: 'ses_1' });
17
+ expect(result).toEqual({ path: '/repo/out/report.csv', size: 42, opened: true });
18
+ });
19
+
20
+ it('keeps an absolute path outside the project, which is where screenshots and recordings often land', async () => {
21
+ const emit = vi.fn(() => 1);
22
+ const requester = createFileOpenRequester({ emit, stat: async () => file });
23
+
24
+ const result = await requester.request({ path: '/tmp/shot.png', directory: '/repo', sessionId: null });
25
+
26
+ expect(result.path).toBe('/tmp/shot.png');
27
+ expect(emit).toHaveBeenCalledWith({ path: '/tmp/shot.png', directory: '/repo', sessionId: null });
28
+ });
29
+
30
+ it('refuses a relative path when no directory is known, instead of guessing one', async () => {
31
+ const requester = createFileOpenRequester({ emit: () => 1, stat: async () => file });
32
+ await expect(requester.request({ path: 'report.csv', directory: null, sessionId: null }))
33
+ .rejects.toMatchObject({ statusCode: 400 });
34
+ });
35
+
36
+ it('reports a missing file and a directory before asking anyone to open them', async () => {
37
+ const emit = vi.fn(() => 1);
38
+ const missing = createFileOpenRequester({
39
+ emit,
40
+ stat: async () => { throw Object.assign(new Error('ENOENT'), { code: 'ENOENT' }); },
41
+ });
42
+ await expect(missing.request({ path: '/repo/gone.png', directory: '/repo' }))
43
+ .rejects.toMatchObject({ statusCode: 404 });
44
+
45
+ const folder = createFileOpenRequester({ emit, stat: async () => ({ isFile: () => false, size: 0 }) });
46
+ await expect(folder.request({ path: '/repo/src', directory: '/repo' }))
47
+ .rejects.toMatchObject({ statusCode: 400 });
48
+
49
+ expect(emit).not.toHaveBeenCalled();
50
+ });
51
+
52
+ it('fails with 503 when no client is connected rather than claiming the file was shown', async () => {
53
+ const requester = createFileOpenRequester({ emit: () => 0, stat: async () => file });
54
+ await expect(requester.request({ path: '/repo/a.png', directory: '/repo' }))
55
+ .rejects.toMatchObject({ statusCode: 503 });
56
+ });
57
+ });
@@ -2,6 +2,7 @@ import express from 'express';
2
2
  import request from 'supertest';
3
3
  import { describe, expect, it, vi } from 'vitest';
4
4
 
5
+ import { BrowserControlError } from '../browser-control/broker.js';
5
6
  import { OpenChamberControlError } from './error.js';
6
7
  import { registerOpenChamberControlRoutes } from './routes.js';
7
8
 
@@ -43,4 +44,15 @@ describe('OpenChamber control route', () => {
43
44
  directory: '/repo',
44
45
  });
45
46
  });
47
+
48
+ it('keeps the status of a browser refusal instead of reporting 500', async () => {
49
+ const execute = vi.fn(async () => {
50
+ throw new BrowserControlError('The user is interacting with this page in the panel right now.', 409);
51
+ });
52
+ const response = await request(createApp(execute))
53
+ .post('/api/openchamber/control')
54
+ .send({ action: 'browser.click', input: {} })
55
+ .expect(409);
56
+ expect(response.body).toEqual({ error: 'The user is interacting with this page in the panel right now.' });
57
+ });
46
58
  });