@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
@@ -23,8 +23,8 @@ export function excerpt(text, limit) {
23
23
  return text.slice(0, head) + marker + (tail > 0 ? text.slice(-tail) : '');
24
24
  }
25
25
 
26
- function attachedText(part) {
27
- const context = part.metadata?.openchamberContext;
26
+ function attachedText(message) {
27
+ const context = message.metadata?.openchamberContext;
28
28
  if (QUOTE_FIELDS.has(context?.kind)) {
29
29
  const source = (context[QUOTE_FIELDS.get(context.kind)] ?? '').trim();
30
30
  const authored = (context.text ?? '').trim();
@@ -33,8 +33,8 @@ function attachedText(part) {
33
33
  const quote = excerpt(source, 4_000).split('\n').map((line) => `> ${line}`).join('\n');
34
34
  return { text: `Attached ${context.kind}${label ? ` (${label}${location})` : ''}:\n${quote}\n\nUser comment:\n${excerpt(authored, USER_CHAR_LIMIT)}`, authored };
35
35
  }
36
- if (LINK_KINDS.has(context?.kind)) return { text: excerpt(part.text, USER_CHAR_LIMIT), authored: '' };
37
- const comment = part.metadata?.opencodeComment;
36
+ if (LINK_KINDS.has(context?.kind)) return { text: excerpt(message.text ?? '', USER_CHAR_LIMIT), authored: '' };
37
+ const comment = message.metadata?.opencodeComment;
38
38
  if (comment) {
39
39
  const authored = comment.comment.trim();
40
40
  const source = (comment.preview ?? '').trim();
@@ -44,51 +44,119 @@ function attachedText(part) {
44
44
  return null;
45
45
  }
46
46
 
47
- /** SDK message records are chronological; tool payloads never enter this view. */
48
- function readMessage({ info, parts }) {
47
+ // Records OpenCode appends around a turn that carry no conversation content:
48
+ // the `idle` marker that closes every turn and the agent/model/location
49
+ // switches. They are invisible to turn boundaries and to "what is the newest
50
+ // message". An `idle` whose outcome is not `succeeded` is not transparent: it
51
+ // is the evidence that the turn failed or was interrupted.
52
+ const TRANSPARENT_TYPES = new Set(['agent-switched', 'model-switched', 'location-switched']);
53
+
54
+ function isTransparent(record) {
55
+ if (record?.type === 'idle') return record.outcome === 'succeeded';
56
+ return TRANSPARENT_TYPES.has(record?.type);
57
+ }
58
+
59
+ /**
60
+ * The id of the newest record that is conversation content, given a page in
61
+ * v2's newest-first order; null when the page holds only service records.
62
+ * Both the assist reader and the pre-write re-check use it so they agree on
63
+ * what "the last message" is.
64
+ */
65
+ export function newestContentId(records) {
66
+ for (const record of Array.isArray(records) ? records : []) {
67
+ if (!record?.id || isTransparent(record)) continue;
68
+ return record.id;
69
+ }
70
+ return null;
71
+ }
72
+
73
+ /**
74
+ * v2 message records are flat: an assistant message carries `content[]`, a user
75
+ * message a single `text` plus its attachments, and context items that used to
76
+ * ride along as `synthetic` text parts are their own `synthetic` messages now.
77
+ * Tool payloads never enter this view.
78
+ */
79
+ function readMessage(message) {
80
+ const role = message.type;
49
81
  const blocks = [];
50
82
  const authored = [];
51
- for (const part of parts) {
52
- if (part.type !== 'text' || part.ignored) continue;
53
- const attached = info.role === 'user' ? attachedText(part) : null;
83
+
84
+ if (role === 'user') {
85
+ const attached = attachedText(message);
54
86
  if (attached) {
55
87
  blocks.push(attached.text);
56
88
  authored.push(attached.authored);
57
- } else if (!part.synthetic) {
58
- blocks.push(part.text);
59
- if (info.role === 'user') {
60
- // Legacy terminal selections are source material, not a language sample.
61
- authored.push(part.text.replace(/\n*<terminal_context>\n[\s\S]*?\n<\/terminal_context>\s*$/, ''));
62
- }
89
+ } else if (typeof message.text === 'string') {
90
+ blocks.push(message.text);
91
+ // Legacy terminal selections are source material, not a language sample.
92
+ authored.push(message.text.replace(/\n*<terminal_context>\n[\s\S]*?\n<\/terminal_context>\s*$/, ''));
93
+ }
94
+ } else if (role === 'assistant') {
95
+ for (const part of Array.isArray(message.content) ? message.content : []) {
96
+ if (part?.type === 'text' && typeof part.text === 'string') blocks.push(part.text);
97
+ }
98
+ } else if (role === 'synthetic') {
99
+ // Context the user attached to the message that follows: in v1 it was a
100
+ // `synthetic` text part inside the user message, in v2 it is its own turn.
101
+ const attached = attachedText(message);
102
+ if (attached) {
103
+ blocks.push(attached.text);
104
+ authored.push(attached.authored);
105
+ } else if (typeof message.text === 'string') {
106
+ blocks.push(message.text);
63
107
  }
64
108
  }
109
+
65
110
  return {
66
- id: info.id, role: info.role, parentID: info.parentID,
67
- providerID: info.providerID, modelID: info.modelID,
68
- complete: info.role === 'assistant' && info.finish === 'stop' && Boolean(info.time?.completed) && !info.error && !info.summary,
69
- summary: Boolean(info.summary),
70
- text: excerpt(blocks.join('\n\n').trim(), info.role === 'user' ? USER_CHAR_LIMIT : ANSWER_CHAR_LIMIT),
111
+ id: message.id,
112
+ role,
113
+ transparent: isTransparent(message),
114
+ // v2 has no `parentID` on a message: a turn is the run of messages between
115
+ // one user message and the assistant reply that follows it, which is what
116
+ // `collectTurns` walks.
117
+ providerID: message.model?.providerID,
118
+ modelID: message.model?.id,
119
+ complete: role === 'assistant'
120
+ && message.finish === 'stop'
121
+ && Boolean(message.time?.completed)
122
+ && !message.error,
123
+ text: excerpt(blocks.join('\n\n').trim(), role === 'user' ? USER_CHAR_LIMIT : ANSWER_CHAR_LIMIT),
71
124
  authored: excerpt(authored.filter(Boolean).join('\n\n').trim(), USER_CHAR_LIMIT),
72
125
  };
73
126
  }
74
127
 
128
+ /**
129
+ * A turn is one user message and the assistant reply that closes it. v2 dropped
130
+ * `parentID`, so the boundary is positional: everything between two user
131
+ * messages belongs to the turn the earlier one opened.
132
+ *
133
+ * Synthetic messages are the context the user attached to the message they are
134
+ * about to send — v1 carried them as parts of that user message — so they are
135
+ * folded into the next user message instead of opening a turn of their own.
136
+ */
75
137
  function collectTurns(messages) {
76
138
  const turns = [];
77
139
  let active = null;
78
- let parents = new Set();
140
+ let attached = [];
79
141
  for (const message of messages) {
80
- if (message.role === 'user' && message.text) {
81
- active = { user: message, assistant: null, complete: false };
82
- parents = new Set([message.id]);
142
+ if (message.transparent) continue;
143
+ if (message.role === 'synthetic') {
144
+ if (message.text) attached.push(message);
145
+ continue;
146
+ }
147
+ if (message.role === 'user') {
148
+ const text = [...attached.map((entry) => entry.text), message.text].filter(Boolean).join('\n\n');
149
+ const authored = [...attached.map((entry) => entry.authored), message.authored].filter(Boolean).join('\n\n');
150
+ attached = [];
151
+ if (!text) continue;
152
+ active = { user: { ...message, text, authored }, assistant: null, complete: false };
83
153
  turns.push(active);
84
- } else if (active && message.role === 'user') {
85
- parents.add(message.id);
86
- } else if (active && message.role === 'assistant' && parents.has(message.parentID) && !message.summary) {
87
- // Compaction's synthetic continuation users belong to the same human
88
- // turn. Parent IDs alone would lose its eventual final answer.
89
- if (message.text) active.assistant = message;
90
- active.complete = message.complete && Boolean(message.text);
154
+ continue;
91
155
  }
156
+ attached = [];
157
+ if (!active || message.role !== 'assistant') continue;
158
+ if (message.text) active.assistant = message;
159
+ active.complete = message.complete && Boolean(message.text);
92
160
  }
93
161
  return turns.slice(-TURN_LIMIT);
94
162
  }
@@ -96,32 +164,40 @@ function collectTurns(messages) {
96
164
  /** Failure is thrown; null means no eligible final answer within bounded history. */
97
165
  export async function loadAssistContext({ readPage, signal }) {
98
166
  let messages = [];
99
- let before;
167
+ let cursor;
100
168
  const cursors = new Set();
101
169
  const ids = new Set();
102
170
  for (let pageNumber = 0; pageNumber < MAX_PAGES; pageNumber++) {
103
171
  signal.throwIfAborted();
104
- const page = await readPage({ limit: PAGE_SIZE, before });
172
+ // v2 pages messages newest first and returns `{ data, cursor }`.
173
+ const page = await readPage({ limit: PAGE_SIZE, cursor });
105
174
  signal.throwIfAborted();
106
- if (!Array.isArray(page.data)) throw new Error('Session message page is unavailable');
175
+ if (!Array.isArray(page?.data)) throw new Error('Session message page is unavailable');
107
176
  const older = [];
108
177
  for (const record of page.data) {
109
- if (ids.has(record.info.id)) continue;
110
- ids.add(record.info.id);
178
+ if (!record?.id || ids.has(record.id)) continue;
179
+ ids.add(record.id);
111
180
  older.push(readMessage(record));
112
181
  }
182
+ older.reverse();
113
183
  messages = older.concat(messages);
114
- const last = messages.at(-1);
115
- if (!last?.complete || !last.text) return null;
116
- const turns = collectTurns(messages);
117
- const cursor = page.response.headers.get('x-next-cursor');
118
- if (turns.length === TURN_LIMIT || !cursor || pageNumber === MAX_PAGES - 1) {
119
- if (!turns.at(-1)?.complete || turns.at(-1).assistant.id !== last.id) return null;
120
- return { turns, last };
184
+ const next = typeof page.cursor?.next === 'string' ? page.cursor.next : null;
185
+ // A successful turn ends with an `idle` marker after the answer; look past
186
+ // it and its siblings to the newest content record.
187
+ const last = messages.findLast((message) => !message.transparent);
188
+ if (!last) {
189
+ if (!next || pageNumber === MAX_PAGES - 1) return null;
190
+ } else {
191
+ if (!last.complete || !last.text) return null;
192
+ const turns = collectTurns(messages);
193
+ if (turns.length === TURN_LIMIT || !next || pageNumber === MAX_PAGES - 1) {
194
+ if (!turns.at(-1)?.complete || turns.at(-1).assistant.id !== last.id) return null;
195
+ return { turns, last };
196
+ }
121
197
  }
122
- if (cursors.has(cursor)) throw new Error('Session message pagination made no progress');
123
- cursors.add(cursor);
124
- before = cursor;
198
+ if (cursors.has(next)) throw new Error('Session message pagination made no progress');
199
+ cursors.add(next);
200
+ cursor = next;
125
201
  }
126
202
  return null;
127
203
  }
@@ -1,40 +1,57 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { excerpt, loadAssistContext } from './context.js';
2
+ import { excerpt, loadAssistContext, newestContentId } from './context.js';
3
3
  import { buildAssistPrompt } from './prompt.js';
4
4
 
5
- const record = (id, role, text, extra = {}, parts = []) => ({
6
- info: { id, role, parentID: 'user', finish: 'stop', time: { completed: 1 }, providerID: 'provider', modelID: 'model', ...extra },
7
- parts: [...(text ? [{ type: 'text', text }] : []), ...parts],
5
+ // v2 message records are flat and a page lists them newest first.
6
+ const user = (id, text, extra = {}) => ({ id, type: 'user', text, ...extra });
7
+ const assistant = (id, text, extra = {}) => ({
8
+ id,
9
+ type: 'assistant',
10
+ content: text ? [{ type: 'text', text }] : [],
11
+ finish: 'stop',
12
+ time: { completed: 1 },
13
+ model: { providerID: 'provider', id: 'model' },
14
+ ...extra,
8
15
  });
9
- const pair = (id) => [record(`u${id}`, 'user', `request ${id}`), record(`a${id}`, 'assistant', `answer ${id}`, { parentID: `u${id}` })];
10
- const page = (data, cursor = '') => ({ data, response: { headers: new Headers({ 'x-next-cursor': cursor }) } });
16
+ const synthetic = (id, text, extra = {}) => ({ id, type: 'synthetic', text, ...extra });
17
+ // OpenCode closes every turn with an idle marker; a switch is appended when
18
+ // the user changes model or agent between turns.
19
+ const idle = (id, outcome = 'succeeded') => ({ id, type: 'idle', outcome, time: { created: 2 } });
20
+ const modelSwitch = (id) => ({ id, type: 'model-switched', model: { providerID: 'p', id: 'm' } });
21
+
22
+ const pair = (id) => [user(`u${id}`, `request ${id}`), assistant(`a${id}`, `answer ${id}`)];
23
+
24
+ /** `data` is given oldest-first here and reversed, the way OpenCode serves it. */
25
+ const page = (data, next = null) => ({ data: [...data].reverse(), cursor: next ? { next } : {} });
11
26
  const load = (readPage) => loadAssistContext({ readPage, signal: new AbortController().signal });
12
27
 
13
28
  describe('session assist context', () => {
14
29
  it('stops paging at three human turns and excludes tools and injected instructions', async () => {
15
30
  let calls = 0;
16
31
  const records = [...pair(1), ...pair(2), ...pair(3), ...pair(4)];
17
- records.at(-1).parts.push({ type: 'tool', state: { output: 'TOOL_PAYLOAD' } }, { type: 'text', synthetic: true, text: 'INJECTED_PROMPT' });
18
- const context = await load(async ({ limit, before }) => {
32
+ records.at(-1).content.push(
33
+ { type: 'tool', tool: 'bash', state: { output: 'TOOL_PAYLOAD' } },
34
+ );
35
+ const context = await load(async ({ limit, cursor }) => {
19
36
  calls++;
20
37
  expect(limit).toBe(50);
21
- expect(before).toBeUndefined();
38
+ expect(cursor).toBeUndefined();
22
39
  return page(records, 'more');
23
40
  });
24
41
  expect(calls).toBe(1);
25
42
  expect(context.turns.map((t) => t.user.id)).toEqual(['u2', 'u3', 'u4']);
26
43
  expect(context.last.text).toBe('answer 4');
27
44
  expect(JSON.stringify(context)).not.toContain('TOOL_PAYLOAD');
28
- expect(JSON.stringify(context)).not.toContain('INJECTED_PROMPT');
29
45
  });
30
46
 
31
- it('finds the real user across a page boundary and compaction continuations', async () => {
32
- const summary = record('summary', 'assistant', 'INTERNAL SUMMARY', { summary: true });
33
- const continuation = record('continuation', 'user', '', {}, [{ type: 'text', synthetic: true, text: 'Continue' }]);
34
- const final = record('final', 'assistant', 'All requested work done', { parentID: 'continuation' });
35
- const context = await load(async ({ before }) => before
36
- ? page([...pair(1), ...pair(2), record('human', 'user', 'Finish the requested work')])
37
- : page([summary, continuation, final], 'older'));
47
+ it('finds the real user across a page boundary and past a compaction', async () => {
48
+ // v2 gives compaction its own message role instead of an assistant message
49
+ // flagged `summary`.
50
+ const compaction = { id: 'summary', type: 'compaction', status: 'completed', summary: 'INTERNAL SUMMARY' };
51
+ const final = assistant('final', 'All requested work done');
52
+ const context = await load(async ({ cursor }) => (cursor
53
+ ? page([...pair(1), ...pair(2), user('human', 'Finish the requested work')])
54
+ : page([compaction, final], 'older')));
38
55
  expect(context.last.id).toBe('final');
39
56
  expect(context.turns.at(-1).user.id).toBe('human');
40
57
  expect(context.turns.at(-1).assistant.id).toBe('final');
@@ -43,8 +60,8 @@ describe('session assist context', () => {
43
60
 
44
61
  it('retains interrupted requests as progress, not as completed turns', async () => {
45
62
  const context = await load(async () => page([
46
- record('u1', 'user', 'Implement both fixes'),
47
- record('a1', 'assistant', 'First fix done', { finish: 'tool-calls', parentID: 'u1' }),
63
+ user('u1', 'Implement both fixes'),
64
+ assistant('a1', 'First fix done', { finish: 'tool-calls' }),
48
65
  ...pair(2),
49
66
  ]));
50
67
  expect(context.turns[0].complete).toBe(false);
@@ -52,22 +69,31 @@ describe('session assist context', () => {
52
69
  expect(context.turns[1].complete).toBe(true);
53
70
  });
54
71
 
55
- it('keeps synthetic annotations and separates author language from quoted material', async () => {
56
- const user = record('u', 'user', '', {}, [{
57
- type: 'text', synthetic: true, text: 'Serialized attachment',
72
+ it('folds an attached synthetic into the user message it belongs to', async () => {
73
+ // v1 carried an attachment as a synthetic part of the user message; v2
74
+ // sends it as its own turn just before the prompt.
75
+ const attachment = synthetic('s', 'Serialized attachment', {
58
76
  metadata: { openchamberContext: { kind: 'chat-quote', quote: 'English quoted source', text: 'Виправ саме це' } },
59
- }]);
60
- const context = await load(async () => page([user, record('a', 'assistant', 'Done', { parentID: 'u' })]));
77
+ });
78
+ const context = await load(async () => page([attachment, user('u', 'Fix it'), assistant('a', 'Done')]));
79
+ expect(context.turns).toHaveLength(1);
61
80
  expect(context.turns[0].user.text).toContain('> English quoted source');
62
81
  expect(context.turns[0].user.text).toContain('User comment:\nВиправ саме це');
63
- expect(context.turns[0].user.authored).toBe('Виправ саме це');
82
+ expect(context.turns[0].user.text).toContain('Fix it');
83
+ expect(context.turns[0].user.authored).toContain('Виправ саме це');
64
84
  });
65
85
 
66
86
  it('retains the comment after a large quote and the conclusion after a long answer', async () => {
67
- const user = record('u', 'user', '', {}, [{ type: 'text', synthetic: true, text: 'attachment', metadata: {
68
- openchamberContext: { kind: 'browser-annotation', prompt: 'x'.repeat(30_000), text: 'USER_REQUEST_END' },
69
- } }]);
70
- const context = await load(async () => page([user, record('a', 'assistant', `START${'x'.repeat(30_000)}CONCLUSION`, { parentID: 'u' })]));
87
+ const attachment = synthetic('s', 'attachment', {
88
+ metadata: {
89
+ openchamberContext: { kind: 'browser-annotation', prompt: 'x'.repeat(30_000), text: 'USER_REQUEST_END' },
90
+ },
91
+ });
92
+ const context = await load(async () => page([
93
+ attachment,
94
+ user('u', 'Look at this'),
95
+ assistant('a', `START${'x'.repeat(30_000)}CONCLUSION`),
96
+ ]));
71
97
  expect(context.turns[0].user.text).toContain('USER_REQUEST_END');
72
98
  expect(context.last.text).toMatch(/^START/);
73
99
  expect(context.last.text).toMatch(/CONCLUSION$/);
@@ -75,10 +101,10 @@ describe('session assist context', () => {
75
101
  });
76
102
 
77
103
  it('fails explicitly on malformed annotation text instead of losing the comment', async () => {
78
- const user = record('u', 'user', '', {}, [{ type: 'text', synthetic: true, text: 'attachment', metadata: {
79
- openchamberContext: { kind: 'chat-quote', quote: 'source', text: 42 },
80
- } }]);
81
- await expect(load(async () => page([user, record('a', 'assistant', 'done')]))).rejects.toThrow();
104
+ const attachment = synthetic('s', 'attachment', {
105
+ metadata: { openchamberContext: { kind: 'chat-quote', quote: 'source', text: 42 } },
106
+ });
107
+ await expect(load(async () => page([attachment, user('u', 'Fix'), assistant('a', 'done')]))).rejects.toThrow();
82
108
  });
83
109
 
84
110
  it('does not treat a failed or repeated page as complete history', async () => {
@@ -93,24 +119,68 @@ describe('session assist context', () => {
93
119
 
94
120
  it('bounds retrieval and refuses to invent a user for an orphaned answer', async () => {
95
121
  let calls = 0;
96
- const context = await load(async () => page([record(`a${++calls}`, 'assistant', 'answer')], `cursor${calls}`));
122
+ const context = await load(async () => page([assistant(`a${++calls}`, 'answer')], `cursor${calls}`));
97
123
  expect(calls).toBe(8);
98
124
  expect(context).toBeNull();
99
125
  });
100
126
 
101
- it('skips unfinished, failed, summary, and user tails', async () => {
127
+ it('looks past the idle marker that closes a finished turn', async () => {
128
+ // The ordinary v2 transcript: answer, then `idle`, possibly followed by a
129
+ // switch the user made afterwards. The answer is still the last message.
130
+ for (const tail of [[idle('i')], [idle('i'), modelSwitch('m')], [modelSwitch('m'), idle('i')]]) {
131
+ const context = await load(async () => page([...pair(1), ...tail]));
132
+ expect(context?.last.id).toBe('a1');
133
+ expect(context.turns).toHaveLength(1);
134
+ expect(context.turns[0].assistant.id).toBe('a1');
135
+ }
136
+ });
137
+
138
+ it('keeps an attachment glued to its prompt across a switch, and a turn across an idle', async () => {
139
+ const attachment = synthetic('s', 'Attached note');
140
+ const context = await load(async () => page([
141
+ ...pair(1), idle('i1'),
142
+ attachment, modelSwitch('m'), user('u2', 'Use the note'), assistant('a2', 'Used'), idle('i2'),
143
+ ]));
144
+ expect(context.turns.map((turn) => turn.user.id)).toEqual(['u1', 'u2']);
145
+ expect(context.turns[1].user.text).toBe('Attached note\n\nUse the note');
146
+ expect(context.turns[0].complete).toBe(true);
147
+ });
148
+
149
+ it('treats a failed or interrupted idle as evidence the turn did not finish', async () => {
150
+ for (const outcome of ['failed', 'interrupted']) {
151
+ expect(await load(async () => page([...pair(1), idle('i', outcome)]))).toBeNull();
152
+ }
153
+ });
154
+
155
+ it('keeps paging when a page holds only service records', async () => {
156
+ const context = await load(async ({ cursor }) => (cursor
157
+ ? page([...pair(1)])
158
+ : page([idle('i1'), modelSwitch('m'), idle('i2')], 'older')));
159
+ expect(context?.last.id).toBe('a1');
160
+ });
161
+
162
+ it('names the newest content record of a newest-first page', () => {
163
+ expect(newestContentId([idle('i'), modelSwitch('m'), assistant('a', 'x'), user('u', 'y')])).toBe('a');
164
+ expect(newestContentId([idle('i', 'failed'), assistant('a', 'x')])).toBe('i');
165
+ expect(newestContentId([idle('i')])).toBeNull();
166
+ expect(newestContentId(undefined)).toBeNull();
167
+ });
168
+
169
+ it('skips unfinished, failed, compaction, and user tails', async () => {
102
170
  for (const tail of [
103
- record('tail', 'user', 'New request'),
104
- record('tail', 'assistant', 'Working', { finish: 'tool-calls' }),
105
- record('tail', 'assistant', 'Failed', { error: { name: 'error' } }),
106
- record('tail', 'assistant', 'Summary', { summary: true }),
171
+ user('tail', 'New request'),
172
+ assistant('tail', 'Working', { finish: 'tool-calls' }),
173
+ assistant('tail', 'Failed', { error: { type: 'APIError', message: 'boom' } }),
174
+ { id: 'tail', type: 'compaction', status: 'completed', summary: 'Summary' },
107
175
  ]) expect(await load(async () => page([...pair(1), tail]))).toBeNull();
108
176
  });
109
177
 
110
178
  it('keeps both sides of the newest exchange within a small model budget', async () => {
111
179
  const context = await load(async () => page([
112
- ...pair(1), ...pair(2), record('latest', 'user', `REQUEST_START${'u'.repeat(8000)}REQUEST_END`),
113
- record('answer', 'assistant', `ANSWER_START${'a'.repeat(16000)}ANSWER_END`, { parentID: 'latest' }),
180
+ ...pair(1),
181
+ ...pair(2),
182
+ user('latest', `REQUEST_START${'u'.repeat(8000)}REQUEST_END`),
183
+ assistant('answer', `ANSWER_START${'a'.repeat(16000)}ANSWER_END`),
114
184
  ]));
115
185
  for (const budget of [1_000, 4_000, 14_000, 32_000, 1_000_000]) {
116
186
  const prompt = buildAssistPrompt(context.turns, { recap: true, suggestion: true }, budget);
@@ -118,15 +188,13 @@ describe('session assist context', () => {
118
188
  for (const marker of ['REQUEST_START', 'REQUEST_END', 'ANSWER_START', 'ANSWER_END']) expect(prompt.text).toContain(marker);
119
189
  }
120
190
  expect(buildAssistPrompt(context.turns, { recap: true }, 500)).toBeNull();
121
- expect(excerpt('long text', 0)).toBe('');
122
- expect(excerpt('long text', 2)).toBe('lo');
123
- for (let limit = 0; limit < 60; limit++) expect(excerpt('x'.repeat(100), limit).length).toBeLessThanOrEqual(limit);
124
191
  });
125
192
 
126
- it('does not assign an older parent\'s late answer to a newer user request', async () => {
127
- expect(await load(async () => page([
128
- ...pair(1), record('new-user', 'user', 'A different request'),
129
- record('late-answer', 'assistant', 'Old work done', { parentID: 'u1' }),
130
- ]))).toBeNull();
193
+ it('excerpts from both ends so the start and the end both survive', () => {
194
+ expect(excerpt('abcdef', 10)).toBe('abcdef');
195
+ const trimmed = excerpt(`START${'x'.repeat(500)}END`, 100);
196
+ expect(trimmed.length).toBeLessThanOrEqual(100);
197
+ expect(trimmed).toMatch(/^START/);
198
+ expect(trimmed).toMatch(/END$/);
131
199
  });
132
200
  });
@@ -1,11 +1,12 @@
1
1
  // Background session assistance. Only live idle events arm generation; there
2
- // is no backfill. Clients hide results whose forMessageID is no longer current.
2
+ // is no backfill. A new turn deletes the assist this process wrote; clients
3
+ // retire any other payload older than the session's `time.idle`.
3
4
  import fs from 'fs';
4
5
  import os from 'os';
5
6
  import path from 'path';
6
- import { createOpencodeClient } from '@opencode-ai/sdk/v2';
7
+ import { OpenCode } from '@opencode/client';
7
8
  import { readMergedSettingsSync } from '../opencode/settings-files.js';
8
- import { loadAssistContext } from './context.js';
9
+ import { loadAssistContext, newestContentId } from './context.js';
9
10
  import { buildAssistPrompt, buildAssistSystemPrompt } from './prompt.js';
10
11
 
11
12
  const OPENCHAMBER_SETTINGS_FILE = path.join(
@@ -28,6 +29,8 @@ const RECAP_CHAR_LIMIT = 320;
28
29
  const SUGGESTION_CHAR_LIMIT = 500;
29
30
  const FETCH_TIMEOUT_MS = 5_000;
30
31
  const GENERATION_TIMEOUT_MS = 120_000;
32
+ // Enough records to look past the idle marker and a couple of switches.
33
+ const TAIL_RECHECK_LIMIT = 8;
31
34
  const QUIET_FAILURE_CODES = new Set(['context-too-small', 'output-exhausted']);
32
35
 
33
36
  const extractJsonObject = (value) => {
@@ -77,16 +80,28 @@ const extractUserMessage = (payload) => {
77
80
  };
78
81
  };
79
82
 
83
+ /**
84
+ * The recap and the suggestion live in OpenChamber's own session metadata
85
+ * store: OpenCode 2.x accepts session metadata only when a session is created.
86
+ * `persistSessionAssist(sessionID, directory, assist)` writes it; without that
87
+ * seam the runtime stays inert rather than generating text it cannot save.
88
+ */
80
89
  export const createSessionAssistRuntime = ({
81
90
  buildOpenCodeUrl,
82
91
  getOpenCodeAuthHeaders,
83
92
  getSmallModelService,
84
93
  getTargets = getSessionAssistTargets,
85
94
  quietMs = IDLE_QUIET_MS,
95
+ persistSessionAssist = null,
96
+ // Archive state is OpenChamber's own in v2 (no OpenCode route sets it), so
97
+ // the runtime asks rather than reading `time.archived` off the record.
98
+ isSessionArchived = async () => false,
86
99
  }) => {
87
100
  const timers = new Map();
88
101
  const inflight = new Map();
89
102
  const ready = new Map();
103
+ // Sessions holding an assist this process wrote, keyed to their directory.
104
+ const persisted = new Map();
90
105
  let stopped = false;
91
106
 
92
107
  const clearTimer = (sessionId) => {
@@ -103,24 +118,46 @@ export const createSessionAssistRuntime = ({
103
118
  inflight.get(sessionId)?.controller.abort();
104
119
  };
105
120
 
121
+ // A new turn makes the stored recap and suggestion describe an older turn:
122
+ // delete them so "has a suggestion" in metadata means the same everywhere.
123
+ const retireStored = (sessionId, directory) => {
124
+ if (!persisted.has(sessionId)) return;
125
+ const storedDirectory = persisted.get(sessionId);
126
+ persisted.delete(sessionId);
127
+ Promise.resolve(persistSessionAssist(sessionId, directory || storedDirectory, null))
128
+ .catch(() => console.warn('[session-assist] failed to retire a stale assist'));
129
+ };
130
+
106
131
  const generateAssist = async (sessionId, directory, signal) => {
107
132
  const targets = getTargets();
108
133
  if (!targets.recap && !targets.suggestion) return;
109
134
  const baseUrl = buildOpenCodeUrl('/', '').replace(/\/$/, '');
110
- const client = createOpencodeClient({ baseUrl, headers: getOpenCodeAuthHeaders(), throwOnError: true });
135
+ const client = OpenCode.make({
136
+ baseUrl,
137
+ headers: {
138
+ ...getOpenCodeAuthHeaders(),
139
+ // v2 scopes by header and rejects non-ASCII header values.
140
+ ...(directory ? { 'x-opencode-directory': encodeURIComponent(directory) } : {}),
141
+ },
142
+ });
111
143
  const requestOptions = () => ({ signal: AbortSignal.any([signal, AbortSignal.timeout(FETCH_TIMEOUT_MS)]) });
112
144
  const checkCurrent = () => {
113
145
  signal.throwIfAborted();
114
146
  if (buildOpenCodeUrl('/', '').replace(/\/$/, '') !== baseUrl) throw new Error('Session assist runtime changed');
115
147
  };
116
- const { data: session } = await client.session.get({ sessionID: sessionId, directory }, requestOptions());
148
+ const session = await client.session.get({ sessionID: sessionId }, requestOptions());
117
149
  checkCurrent();
118
150
  // Reverted history is not the active conversation. A new prompt clears
119
151
  // the revert boundary before its next idle event.
120
- if (session?.id !== sessionId || session.parentID || session.revert?.messageID || session.time?.archived) return;
152
+ if (session?.id !== sessionId || session.parentID || session.revert?.messageID) return;
153
+ // An archived session is put away: no recap or suggestion is generated for it.
154
+ if (await isSessionArchived(sessionId)) return;
121
155
  const context = await loadAssistContext({
122
156
  signal,
123
- readPage: (page) => client.session.messages({ sessionID: sessionId, directory, ...page }, requestOptions()),
157
+ readPage: ({ limit, cursor }) => client.message.list(
158
+ { sessionID: sessionId, limit, ...(cursor ? { cursor } : { order: 'desc' }) },
159
+ requestOptions(),
160
+ ),
124
161
  });
125
162
  checkCurrent();
126
163
  if (!context) return;
@@ -160,30 +197,29 @@ export const createSessionAssistRuntime = ({
160
197
  if (recap && scriptMismatch(recap)) recap = '';
161
198
  if (suggestion && scriptMismatch(suggestion)) suggestion = '';
162
199
  if (!recap && !suggestion) return;
163
- const { data: latest } = await client.session.messages({ sessionID: sessionId, directory, limit: 1 }, requestOptions());
200
+ // v2 lists newest first. The answer is followed by its `idle` marker and
201
+ // possibly a model or agent switch, so read a short tail and compare the
202
+ // newest content record rather than the newest record.
203
+ const latestPage = await client.message.list({ sessionID: sessionId, limit: TAIL_RECHECK_LIMIT, order: 'desc' }, requestOptions());
164
204
  checkCurrent();
165
- if (latest?.at(-1)?.info.id !== last.id) return;
205
+ if (newestContentId(latestPage?.data) !== last.id) return;
166
206
  // Never fall back to the pre-generation metadata snapshot after a failed
167
207
  // fresh read: doing so overwrites dismissals and unrelated metadata.
168
- const { data: freshSession } = await client.session.get({ sessionID: sessionId, directory }, requestOptions());
208
+ const freshSession = await client.session.get({ sessionID: sessionId }, requestOptions());
169
209
  checkCurrent();
170
- if (freshSession?.id !== sessionId || freshSession.revert?.messageID || freshSession.time?.archived || freshSession.directory !== session.directory) return;
210
+ if (freshSession?.id !== sessionId || freshSession.revert?.messageID || freshSession.location?.directory !== session.location?.directory) return;
211
+ if (await isSessionArchived(sessionId)) return;
171
212
  const enabled = getTargets();
172
213
  if (!enabled.recap) recap = '';
173
214
  if (!enabled.suggestion) suggestion = '';
174
215
  if (!recap && !suggestion) return;
175
- const currentMetadata = freshSession.metadata ?? {};
176
- const currentNamespace = currentMetadata.openchamber ?? {};
177
- await client.session.update({
178
- sessionID: sessionId, directory,
179
- metadata: {
180
- ...currentMetadata,
181
- openchamber: {
182
- ...currentNamespace,
183
- assist: { recap, suggestion, forMessageID: last.id, generatedAt: Date.now() },
184
- },
185
- },
186
- }, requestOptions());
216
+ await persistSessionAssist(sessionId, directory, {
217
+ recap,
218
+ suggestion,
219
+ forMessageID: last.id,
220
+ generatedAt: Date.now(),
221
+ });
222
+ persisted.set(sessionId, directory);
187
223
  };
188
224
 
189
225
  const startGeneration = (sessionId, directory, armedAt) => {
@@ -219,12 +255,23 @@ export const createSessionAssistRuntime = ({
219
255
  timers.set(sessionId, { timer, armedAt });
220
256
  };
221
257
 
258
+ let parkedNoticeLogged = false;
222
259
  const processPayload = (payload, directoryHint = '') => {
223
260
  if (stopped) return;
261
+ if (typeof persistSessionAssist !== 'function') {
262
+ if (!parkedNoticeLogged) {
263
+ parkedNoticeLogged = true;
264
+ console.log('[session-assist] parked: no session metadata store is wired, so a recap could not be saved');
265
+ }
266
+ return;
267
+ }
224
268
  const status = extractSessionStatus(payload);
225
269
  if (status) {
226
270
  if (status.type === 'idle') armTimer(status.sessionId, status.directory || directoryHint);
227
- else invalidate(status.sessionId);
271
+ else {
272
+ invalidate(status.sessionId);
273
+ retireStored(status.sessionId, status.directory || directoryHint);
274
+ }
228
275
  return;
229
276
  }
230
277
  const userMessage = extractUserMessage(payload);