@openchamber/web 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (264) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-C_zL-eri.js → CodeMirrorCommentWidgets-qlshRzAf.js} +1 -1
  2. package/dist/assets/{DiffView-BeN2_YYF.js → DiffView-BI_YgdKl.js} +3 -3
  3. package/dist/assets/FilesView-B_NJFLBH.js +17 -0
  4. package/dist/assets/{GitView-DLDazOo1.js → GitView-BWKg6TNS.js} +4 -4
  5. package/dist/assets/{GuestAttachDialog-C0xe_Lyy.js → GuestAttachDialog-DO4x4vIR.js} +1 -1
  6. package/dist/assets/{GuestSurfacePane-BdaurnDr.js → GuestSurfacePane-4PY11vEP.js} +1 -1
  7. package/dist/assets/JsonTreeView-u4yx65zn.js +1 -0
  8. package/dist/assets/{LinearIssuesView-BryoAHow.js → LinearIssuesView-C4gGBhU8.js} +1 -1
  9. package/dist/assets/{MarkdownImageGallery-DfuEoaGq.js → MarkdownImageGallery-fqVRCTdC.js} +1 -1
  10. package/dist/assets/MarkdownRendererImpl-Cfb5fTnq.js +39 -0
  11. package/dist/assets/OnboardingScreen-CiTV2_OT.js +1 -0
  12. package/dist/assets/PatchDiff-BrjhzXDM.js +1 -0
  13. package/dist/assets/{PierreDiffViewer-BC950e3F.js → PierreDiffViewer-CVx2e1cx.js} +5 -5
  14. package/dist/assets/{PlanView-B7Xgihqk.js → PlanView-DP9DOnI-.js} +4 -4
  15. package/dist/assets/{PluginPane-2C71F8uF.js → PluginPane-rZvoMQSi.js} +3 -3
  16. package/dist/assets/SettingsView-Dp9jubRs.js +30 -0
  17. package/dist/assets/SettingsWindow-Dst0yiV7.js +1 -0
  18. package/dist/assets/{SubmoduleDiffSummary-BSA9gnIO.js → SubmoduleDiffSummary-CixkM4fI.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DprkVKcj.js → ToolOutputDialog-f0cS2DIf.js} +6 -6
  20. package/dist/assets/ToolPartDiffPreview-CFFIAFFY.js +8 -0
  21. package/dist/assets/{VirtualizedFileDiff-Kp8hKJdT.js → VirtualizedFileDiff-B-U_aQwV.js} +4 -4
  22. package/dist/assets/{WalkthroughView-DGnTzqIU.js → WalkthroughView-C1uB3Pl3.js} +2 -2
  23. package/dist/assets/{appThemeRegistry-BdEHBA4s.js → appThemeRegistry-DU-UKEHq.js} +1 -1
  24. package/dist/assets/{commitAndPush-LwtVa2Oc.js → commitAndPush-CtWGqrtW.js} +1 -1
  25. package/dist/assets/{computeVirtualFileMetrics-6V1xNpO9.js → computeVirtualFileMetrics-BmhViPMt.js} +1 -1
  26. package/dist/assets/de-D4hpTCNY.js +10 -0
  27. package/dist/assets/es-Bw9m3H62.js +16 -0
  28. package/dist/assets/fileTreeStatus-CvPnAWSi.js +1 -0
  29. package/dist/assets/fr-Bhll42P0.js +14 -0
  30. package/dist/assets/index-Btd2mmYT.js +42 -0
  31. package/dist/assets/index-C-7hQnEc.css +1 -0
  32. package/dist/assets/{index-CmNPYddV.js → index-DwtCnbiK.js} +1 -1
  33. package/dist/assets/{isDiffPlainText-1bXcWCrw.js → isDiffPlainText-CPDhzF1K.js} +1 -1
  34. package/dist/assets/{isFilePlainText-CBAppvy1.js → isFilePlainText-n8k0lMTZ.js} +1 -1
  35. package/dist/assets/ja-CsHoT43d.js +16 -0
  36. package/dist/assets/ko-BBNdtFa4.js +16 -0
  37. package/dist/assets/{main-CzjTMTfW.js → main-D6rlXjug.js} +2 -2
  38. package/dist/assets/main-kYkr_urz.js +1000 -0
  39. package/dist/assets/markdownCore-CHm8ycaW.js +7 -0
  40. package/dist/assets/{miniChat-CP68IL8Q.js → miniChat-2JY8K3Qw.js} +2 -2
  41. package/dist/assets/mobile-CviaXnnU.js +2 -0
  42. package/dist/assets/nl-DszyktfH.js +16 -0
  43. package/dist/assets/openSessionFromRoute-BIlcJIf3.js +1 -0
  44. package/dist/assets/{web-components-ngpHPEDU.js → parseDiffFromFile-DeZzEah8.js} +5 -5
  45. package/dist/assets/{patchFileDiff-pqRSHLHI.js → patchFileDiff-BnEHIdM2.js} +2 -2
  46. package/dist/assets/pl-Bk9_mUXc.js +16 -0
  47. package/dist/assets/pt-BR-BIXmm3Gw.js +16 -0
  48. package/dist/assets/{renderElectronMiniChatApp-DKIilR7N.js → renderElectronMiniChatApp-DvUphkjj.js} +2 -2
  49. package/dist/assets/renderMobileApp-Cdc49X8Y.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-Cu6RUve4.js +56 -0
  51. package/dist/assets/shikiHighlight-CcVzlYit.js +1 -0
  52. package/dist/assets/space-apply-CgJ5JYPK.js +1 -0
  53. package/dist/assets/space-close-C1tL-_0t.js +1 -0
  54. package/dist/assets/{textMateThemeFromAppTheme-BSUFChBY.js → textMateThemeFromAppTheme-CAOCeVjl.js} +1 -1
  55. package/dist/assets/tr-C_13w7CX.js +7 -0
  56. package/dist/assets/uk-BZTsG-q_.js +16 -0
  57. package/dist/assets/{useAppFontEffects-Dsl_sLrj.js → useAppFontEffects-CeMgbeVa.js} +185 -177
  58. package/dist/assets/{useInlineCommentController-d5vntsQ_.js → useInlineCommentController-U97JJifS.js} +2 -2
  59. package/dist/assets/useRootScrollLock-DMBY2aTT.js +2 -0
  60. package/dist/assets/{vendor-base-ui-DnNniUWp.js → vendor-base-ui-DWgyZK2k.js} +1 -1
  61. package/dist/assets/vendor-codemirror-autocomplete-DetzHhtC.js +1 -0
  62. package/dist/assets/{vendor-codemirror-commands-B7H_j0iU.js → vendor-codemirror-commands-ConqfjLn.js} +1 -1
  63. package/dist/assets/{vendor-codemirror-lang-angular-DEPs2M5t.js → vendor-codemirror-lang-angular-Dbpx8qe-.js} +1 -1
  64. package/dist/assets/{vendor-codemirror-lang-cpp-DhkseaMo.js → vendor-codemirror-lang-cpp-TRtQWrpl.js} +1 -1
  65. package/dist/assets/{vendor-codemirror-lang-css-O0cZX78y.js → vendor-codemirror-lang-css-DY4CGDG2.js} +1 -1
  66. package/dist/assets/{vendor-codemirror-lang-go-fMdQYcON.js → vendor-codemirror-lang-go-CLKXh6B8.js} +1 -1
  67. package/dist/assets/{vendor-codemirror-lang-html-CfgK872x.js → vendor-codemirror-lang-html-CQnNjmg9.js} +1 -1
  68. package/dist/assets/{vendor-codemirror-lang-java-CQj4S3zl.js → vendor-codemirror-lang-java-CokZKqls.js} +1 -1
  69. package/dist/assets/{vendor-codemirror-lang-javascript-Cc2ZYbgX.js → vendor-codemirror-lang-javascript-Kgp6fZRE.js} +1 -1
  70. package/dist/assets/{vendor-codemirror-lang-jinja-BmZZv8g-.js → vendor-codemirror-lang-jinja-DZchyrN1.js} +1 -1
  71. package/dist/assets/{vendor-codemirror-lang-json-CMBS2tG9.js → vendor-codemirror-lang-json-CkdBRvqj.js} +1 -1
  72. package/dist/assets/{vendor-codemirror-lang-less-C6Eo8hVS.js → vendor-codemirror-lang-less-_k-GKz0A.js} +1 -1
  73. package/dist/assets/{vendor-codemirror-lang-liquid-DSTR47-H.js → vendor-codemirror-lang-liquid-DuHUMKoh.js} +1 -1
  74. package/dist/assets/{vendor-codemirror-lang-markdown-BPGOH9ye.js → vendor-codemirror-lang-markdown-CdG1RXm1.js} +1 -1
  75. package/dist/assets/{vendor-codemirror-lang-php-DD9udfPH.js → vendor-codemirror-lang-php-Ca15KQSA.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-lang-python-HahnQaAS.js → vendor-codemirror-lang-python-B4MRHRva.js} +1 -1
  77. package/dist/assets/{vendor-codemirror-lang-rust-nLTovbjv.js → vendor-codemirror-lang-rust-8fLJdxQA.js} +1 -1
  78. package/dist/assets/{vendor-codemirror-lang-sass-pL2Yc72v.js → vendor-codemirror-lang-sass-CASr_yQ1.js} +1 -1
  79. package/dist/assets/{vendor-codemirror-lang-sql-BVBnan19.js → vendor-codemirror-lang-sql-Dc4ER-re.js} +1 -1
  80. package/dist/assets/{vendor-codemirror-lang-vue-BqGzJVm1.js → vendor-codemirror-lang-vue-fu2BqdK2.js} +1 -1
  81. package/dist/assets/{vendor-codemirror-lang-wast-B0_m5DqU.js → vendor-codemirror-lang-wast-BkCOgSpV.js} +1 -1
  82. package/dist/assets/{vendor-codemirror-lang-xml-Dj3voadT.js → vendor-codemirror-lang-xml-7e-kPepH.js} +1 -1
  83. package/dist/assets/{vendor-codemirror-lang-yaml-yu-9Z5u7.js → vendor-codemirror-lang-yaml-Cq3p_9DI.js} +1 -1
  84. package/dist/assets/vendor-codemirror-language-CZcLdzDM.js +3 -0
  85. package/dist/assets/{vendor-codemirror-language-data-B1EetJur.js → vendor-codemirror-language-data-B8HKnqZy.js} +2 -2
  86. package/dist/assets/vendor-codemirror-search-BZNojiZO.js +2 -0
  87. package/dist/assets/{vendor-codemirror-state-C9awkmn-.js → vendor-codemirror-state--21VQleR.js} +1 -1
  88. package/dist/assets/vendor-codemirror-view-8PpN-8l4.js +4 -0
  89. package/dist/assets/vendor-opencode-client-Byb4ZSqI.js +12 -0
  90. package/dist/assets/vendor-remend-DcBOpbSu.js +24 -0
  91. package/dist/assets/{vendor-replit-codemirror-vim-B2DJlAhT.js → vendor-replit-codemirror-vim-EX7OnecQ.js} +1 -1
  92. package/dist/assets/zh-CN-C62wm2Tg.js +16 -0
  93. package/dist/assets/zh-TW-BgGTiQA6.js +16 -0
  94. package/dist/index.html +4 -4
  95. package/dist/mini-chat.html +4 -4
  96. package/dist/mobile.html +4 -4
  97. package/package.json +4 -4
  98. package/server/index.js +58 -1
  99. package/server/lib/browser-control/DOCUMENTATION.md +8 -1
  100. package/server/lib/dev-tunnel/DOCUMENTATION.md +6 -0
  101. package/server/lib/dev-tunnel/runtime.js +94 -38
  102. package/server/lib/dev-tunnel/tunnel.test.js +16 -2
  103. package/server/lib/dictation/DOCUMENTATION.md +23 -10
  104. package/server/lib/dictation/audio.js +28 -0
  105. package/server/lib/dictation/local/sherpa-recognizer.js +33 -7
  106. package/server/lib/dictation/local/sherpa-recognizer.test.js +94 -0
  107. package/server/lib/dictation/local/worker-client.js +28 -10
  108. package/server/lib/dictation/local/worker-process.js +25 -1
  109. package/server/lib/dictation/stream-manager.js +160 -53
  110. package/server/lib/dictation/stream-manager.test.js +108 -7
  111. package/server/lib/enterprise-mode.d.ts +2 -0
  112. package/server/lib/enterprise-mode.js +84 -9
  113. package/server/lib/enterprise-mode.test.js +115 -0
  114. package/server/lib/fs/DOCUMENTATION.md +3 -2
  115. package/server/lib/fs/routes.js +28 -1
  116. package/server/lib/fs/routes.test.js +31 -5
  117. package/server/lib/git/DOCUMENTATION.md +1 -1
  118. package/server/lib/git/service.js +61 -2
  119. package/server/lib/git/service.test.js +141 -0
  120. package/server/lib/github/DOCUMENTATION.md +18 -0
  121. package/server/lib/github/checks-summary.js +76 -0
  122. package/server/lib/github/pr-summaries.js +282 -0
  123. package/server/lib/github/pr-summaries.test.js +209 -0
  124. package/server/lib/github/routes.js +42 -77
  125. package/server/lib/github/routes.test.js +77 -0
  126. package/server/lib/inherited-env.js +51 -0
  127. package/server/lib/inherited-env.test.js +59 -0
  128. package/server/lib/message-search/DOCUMENTATION.md +83 -0
  129. package/server/lib/message-search/indexer.js +336 -0
  130. package/server/lib/message-search/indexer.test.js +341 -0
  131. package/server/lib/message-search/routes.js +92 -0
  132. package/server/lib/message-search/runtime.js +234 -0
  133. package/server/lib/message-search/runtime.test.js +108 -0
  134. package/server/lib/message-search/sqlite.js +74 -0
  135. package/server/lib/message-search/store.js +289 -0
  136. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
  137. package/server/lib/openchamber-control/actions.js +1 -1
  138. package/server/lib/openchamber-control/service.js +21 -2
  139. package/server/lib/openchamber-control/service.test.js +50 -0
  140. package/server/lib/openchamber-sessions/routes.js +15 -0
  141. package/server/lib/openchamber-sessions/routes.test.js +31 -0
  142. package/server/lib/opencode/DOCUMENTATION.md +43 -38
  143. package/server/lib/opencode/auth.d.ts +24 -0
  144. package/server/lib/opencode/auth.js +130 -66
  145. package/server/lib/opencode/auth.test.js +114 -70
  146. package/server/lib/opencode/compatibility.js +4 -3
  147. package/server/lib/opencode/compatibility.test.js +10 -10
  148. package/server/lib/opencode/feature-routes-runtime.js +3 -0
  149. package/server/lib/opencode/lifecycle.js +21 -12
  150. package/server/lib/opencode/lifecycle.test.js +38 -5
  151. package/server/lib/opencode/provider-source-route.test.js +55 -2
  152. package/server/lib/opencode/routes.js +17 -4
  153. package/server/lib/opencode/settings-helpers.js +6 -0
  154. package/server/lib/opencode/settings-helpers.test.js +1 -1
  155. package/server/lib/opencode/settings-registry.json +16 -0
  156. package/server/lib/opencode/settings-runtime.js +9 -0
  157. package/server/lib/opencode/shutdown-runtime.js +2 -0
  158. package/server/lib/opencode/v1-migration-topup.js +13 -3
  159. package/server/lib/opencode/v2-install.test.js +13 -13
  160. package/server/lib/quota/DOCUMENTATION.md +11 -5
  161. package/server/lib/quota/providers/claude/auth.js +19 -6
  162. package/server/lib/quota/providers/claude/auth.test.js +22 -9
  163. package/server/lib/quota/providers/claude/index.js +3 -3
  164. package/server/lib/quota/providers/claude/index.test.js +3 -2
  165. package/server/lib/quota/providers/cline-pass.js +4 -4
  166. package/server/lib/quota/providers/codex.js +3 -4
  167. package/server/lib/quota/providers/codex.test.js +1 -1
  168. package/server/lib/quota/providers/copilot.js +4 -5
  169. package/server/lib/quota/providers/copilot.test.js +1 -1
  170. package/server/lib/quota/providers/deepseek.js +3 -4
  171. package/server/lib/quota/providers/deepseek.test.js +1 -1
  172. package/server/lib/quota/providers/google/auth.js +1 -3
  173. package/server/lib/quota/providers/google/index.js +3 -2
  174. package/server/lib/quota/providers/hyper.js +4 -4
  175. package/server/lib/quota/providers/index.js +9 -2
  176. package/server/lib/quota/providers/index.test.js +5 -3
  177. package/server/lib/quota/providers/kimi.js +16 -11
  178. package/server/lib/quota/providers/kimi.test.js +81 -38
  179. package/server/lib/quota/providers/minimax-shared.js +3 -4
  180. package/server/lib/quota/providers/nanogpt.js +3 -4
  181. package/server/lib/quota/providers/neuralwatt.js +3 -4
  182. package/server/lib/quota/providers/neuralwatt.test.js +1 -1
  183. package/server/lib/quota/providers/openai.js +2 -8
  184. package/server/lib/quota/providers/opencode-go.js +5 -5
  185. package/server/lib/quota/providers/opencode-go.test.js +1 -1
  186. package/server/lib/quota/providers/openrouter.js +30 -6
  187. package/server/lib/quota/providers/openrouter.test.js +122 -1
  188. package/server/lib/quota/providers/wafer.js +3 -4
  189. package/server/lib/quota/providers/xai.js +12 -12
  190. package/server/lib/quota/providers/zai.js +3 -4
  191. package/server/lib/quota/providers/zai.test.js +1 -1
  192. package/server/lib/quota/providers/zhipuai-coding-plan.js +5 -6
  193. package/server/lib/quota/providers/zhipuai-coding-plan.test.js +1 -1
  194. package/server/lib/quota/routes.js +1 -1
  195. package/server/lib/routing/DOCUMENTATION.md +4 -0
  196. package/server/lib/routing/runtime.js +45 -4
  197. package/server/lib/routing/runtime.test.js +35 -6
  198. package/server/lib/scheduled-tasks/DOCUMENTATION.md +27 -0
  199. package/server/lib/scheduled-tasks/chats-scope.js +50 -0
  200. package/server/lib/scheduled-tasks/runtime.js +57 -23
  201. package/server/lib/scheduled-tasks/runtime.test.js +103 -1
  202. package/server/lib/scheduled-tasks/service.js +37 -29
  203. package/server/lib/scheduled-tasks/service.test.js +39 -0
  204. package/server/lib/spaces/DOCUMENTATION.md +54 -9
  205. package/server/lib/spaces/host.js +24 -3
  206. package/server/lib/spaces/journey.js +111 -11
  207. package/server/lib/spaces/journey.test.js +189 -8
  208. package/server/lib/spaces/places/docker-disk.js +151 -0
  209. package/server/lib/spaces/places/docker-disk.test.js +167 -0
  210. package/server/lib/spaces/places/docker-tools.js +11 -1
  211. package/server/lib/spaces/places/docker.js +4 -2
  212. package/server/lib/spaces/places/fake-docker.js +36 -2
  213. package/server/lib/spaces/routes.js +21 -4
  214. package/server/lib/spaces/routes.test.js +6 -2
  215. package/server/lib/spaces/space-archive.js +275 -0
  216. package/server/lib/spaces/space-archive.test.js +194 -0
  217. package/server/lib/spaces/space-opencode.js +139 -6
  218. package/server/lib/spaces/space-opencode.test.js +82 -1
  219. package/server/lib/spaces/space-records.js +3 -0
  220. package/server/lib/spaces/space-setup.js +10 -5
  221. package/server/lib/spaces/space-setup.test.js +8 -2
  222. package/server/lib/terminal/DOCUMENTATION.md +1 -0
  223. package/server/lib/terminal/runtime.js +6 -1
  224. package/server/lib/terminal/runtime.test.js +19 -0
  225. package/server/lib/tts/routes.js +2 -2
  226. package/server/lib/tts/service.js +8 -8
  227. package/dist/assets/FilesView-CN34wm_N.js +0 -17
  228. package/dist/assets/JsonTreeView-B1Xq-k2t.js +0 -1
  229. package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +0 -12
  230. package/dist/assets/OnboardingScreen-C22bGmnP.js +0 -1
  231. package/dist/assets/PatchDiff-0xd6UeFB.js +0 -1
  232. package/dist/assets/SettingsView-m_zoFiaT.js +0 -30
  233. package/dist/assets/SettingsWindow-CofS020b.js +0 -1
  234. package/dist/assets/ToolPartDiffPreview-Dq0go_fX.js +0 -8
  235. package/dist/assets/de-DlgBHUAI.js +0 -10
  236. package/dist/assets/es-BC8G41U8.js +0 -16
  237. package/dist/assets/fr-I0z3vVjy.js +0 -14
  238. package/dist/assets/index-CgR5rJq_.js +0 -41
  239. package/dist/assets/index-adyy_sEk.css +0 -1
  240. package/dist/assets/ja-BIElEsY8.js +0 -16
  241. package/dist/assets/ko-DRnnHetA.js +0 -16
  242. package/dist/assets/main-DVX34beR.js +0 -886
  243. package/dist/assets/markdownCore-Cxbkn5NR.js +0 -7
  244. package/dist/assets/mobile-BrlBrNfZ.js +0 -2
  245. package/dist/assets/nl-DzUV-kwp.js +0 -16
  246. package/dist/assets/pl-Bb-cb7k7.js +0 -16
  247. package/dist/assets/pt-BR-CyIWrTcE.js +0 -16
  248. package/dist/assets/renderMobileApp-B0z6-x58.js +0 -25
  249. package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +0 -52
  250. package/dist/assets/scheduledTasksApi-BuzWT445.js +0 -1
  251. package/dist/assets/shikiHighlight-BWGrY5YU.js +0 -1
  252. package/dist/assets/tr-DXEDSoYO.js +0 -7
  253. package/dist/assets/uk-C8hN--q_.js +0 -16
  254. package/dist/assets/useRootScrollLock-2rd5Y6gR.js +0 -2
  255. package/dist/assets/vendor-codemirror-autocomplete-DzPz9Wgq.js +0 -1
  256. package/dist/assets/vendor-codemirror-language-BgPj_McA.js +0 -3
  257. package/dist/assets/vendor-codemirror-search-BmS-GmcX.js +0 -2
  258. package/dist/assets/vendor-codemirror-view-CiLROUVV.js +0 -4
  259. package/dist/assets/vendor-opencode-client-DSZl7jSi.js +0 -12
  260. package/dist/assets/vendor-remend-BWYYytN3.js +0 -22
  261. package/dist/assets/zh-CN-CtzXdjMZ.js +0 -16
  262. package/dist/assets/zh-TW-Ds0CADSz.js +0 -16
  263. package/server/lib/opencode/credential-db.js +0 -144
  264. package/server/lib/opencode/credential-db.test.js +0 -104
@@ -0,0 +1,194 @@
1
+ // The chat archive with a stand-in space and a stand-in host OpenCode that records what it imported.
2
+ // What is under test is all-or-nothing, the order of the import, what a space may not claim, and
3
+ // that an archived chat cannot be run through any route that acts on a session.
4
+
5
+ import fs from 'node:fs';
6
+ import os from 'node:os';
7
+ import path from 'node:path';
8
+
9
+ import { afterEach, describe, expect, it } from 'vitest';
10
+
11
+ import { SpaceError } from './errors.js';
12
+ import { ARCHIVE_MAX_CHATS, createSpaceArchive } from './space-archive.js';
13
+
14
+ const SPACE = 'a1b2c3d4e5f6';
15
+ const PARENT = 'ses_parent1';
16
+ const CHILD = 'ses_child1';
17
+ const OTHER = 'ses_other1';
18
+ const HOST_SESSION = 'ses_host1';
19
+ const quiet = { warn: () => {} };
20
+ const folders = [];
21
+
22
+ afterEach(() => {
23
+ for (const folder of folders.splice(0)) fs.rmSync(folder, { recursive: true, force: true });
24
+ });
25
+
26
+ const infoOf = (id, extra = {}) => ({
27
+ id,
28
+ projectID: 'p1',
29
+ cost: 0,
30
+ tokens: { input: 0, output: 0, reasoning: 0, cache: { read: 0, write: 0 } },
31
+ time: { created: 1, updated: 2 },
32
+ title: `chat ${id}`,
33
+ ...extra,
34
+ });
35
+
36
+ /** A space that lists `chats` and exports each, and a host that imports them into a map. */
37
+ const archiveWith = ({ chats, failImportOf = null, dataDir = null, host = new Map(), now = () => 1234 } = {}) => {
38
+ if (dataDir === null) {
39
+ dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-archive-'));
40
+ folders.push(dataDir);
41
+ }
42
+ const removed = [];
43
+ const hostOpenCode = {
44
+ importChat: async (chat) => {
45
+ if (failImportOf === chat.info.id || host.has(chat.info.id)) throw Object.assign(new Error('conflict'), { status: 409 });
46
+ if (chat.info.parentID && !host.has(chat.info.parentID)) throw Object.assign(new Error('parent missing'), { status: 404 });
47
+ host.set(chat.info.id, chat);
48
+ },
49
+ removeChat: async (id) => { removed.push(id); host.delete(id); },
50
+ };
51
+ const archive = createSpaceArchive({ dataDir, hostOpenCode, logger: quiet, now });
52
+ const source = {
53
+ listChats: async () => ({ chats: (chats ?? []).map(({ info }) => ({ id: info.id, title: info.title })), complete: true }),
54
+ exportChat: async (id) => {
55
+ const chat = chats.find((entry) => entry.info.id === id);
56
+ if (chat.fail) throw chat.fail;
57
+ return { info: chat.info, messages: [{ id: `msg_${id}`, type: 'user', text: 'hi' }] };
58
+ },
59
+ };
60
+ const save = (allowUnsaved = false) => archive.saveChats({ spaceId: SPACE, name: 'Fix login', projectDirectory: '/home/me/project', source, allowUnsaved });
61
+ return { archive, host, removed, save, dataDir, source };
62
+ };
63
+
64
+ /** Runs the guard on one request and says whether it passed or what it answered. */
65
+ const through = (archive, method, requestPath) => {
66
+ let answer = 'passed';
67
+ const res = { status: (code) => ({ json: (body) => { answer = { code, body }; } }) };
68
+ archive.guard({ method, path: requestPath }, res, () => {});
69
+ return answer;
70
+ };
71
+
72
+ describe('saving the chats of a space', () => {
73
+ it('imports parents before children at the archive\'s directory, stamped archived, and lists the archive', async () => {
74
+ // The child is listed first, as a space may list them.
75
+ const { archive, host, save, dataDir } = archiveWith({ chats: [{ info: infoOf(CHILD, { parentID: PARENT }) }, { info: infoOf(PARENT) }] });
76
+ expect(await save()).toEqual({ saved: 2, tooLarge: [], failed: 0, listed: true });
77
+ expect(Array.from(host.keys())).toEqual([PARENT, CHILD]);
78
+ const directory = path.join(dataDir, 'spaces', 'archive', SPACE);
79
+ expect(host.get(CHILD).info).toMatchObject({ parentID: PARENT, location: { directory }, time: { archived: 1234 } });
80
+ expect(fs.statSync(directory).isDirectory()).toBe(true);
81
+ expect(archive.listArchives()).toEqual([{ spaceId: SPACE, name: 'Fix login', projectDirectory: '/home/me/project', directory, archivedAt: 1234 }]);
82
+ });
83
+
84
+ it('refuses every tool of every agent in an archived chat, in OpenCode itself', async () => {
85
+ const { host, save } = archiveWith({ chats: [{ info: infoOf(PARENT, { permissions: [{ action: '*', resource: '*', effect: 'allow' }] }) }] });
86
+ await save();
87
+ expect(host.get(PARENT).info.permissions).toEqual([{ action: '*', resource: '*', effect: 'deny' }]);
88
+ });
89
+
90
+ it('keeps the chats an earlier delete saved when the same space is saved again, and counts them as saved', async () => {
91
+ const chats = [{ info: infoOf(PARENT) }, { info: infoOf(CHILD, { parentID: PARENT }) }];
92
+ const first = archiveWith({ chats });
93
+ await first.save();
94
+ // The space was not removed; a second delete saves it again, with one chat more.
95
+ const second = archiveWith({ chats: [...chats, { info: infoOf(OTHER) }], dataDir: first.dataDir, host: first.host });
96
+ expect(await second.save()).toEqual({ saved: 3, tooLarge: [], failed: 0, listed: true });
97
+ for (const id of [PARENT, CHILD, OTHER]) expect(second.archive.isArchivedChat(id)).toBe(true);
98
+
99
+ // A third that fails takes back only what it added.
100
+ const third = archiveWith({ chats: [...chats, { info: infoOf('ses_new1') }], dataDir: first.dataDir, host: first.host, failImportOf: 'ses_new1' });
101
+ await expect(third.save()).rejects.toMatchObject({ code: 'chats_not_saved' });
102
+ for (const id of [PARENT, CHILD, OTHER]) expect(third.archive.isArchivedChat(id)).toBe(true);
103
+ expect(third.removed).toEqual([]);
104
+ });
105
+
106
+ it('stops taking chats out when the whole save runs out of time', async () => {
107
+ let clock = 0;
108
+ const { host, save } = archiveWith({ chats: [{ info: infoOf(PARENT) }, { info: infoOf(OTHER) }], now: () => { clock += 20 * 60_000; return clock; } });
109
+ await expect(save()).rejects.toMatchObject({ code: 'chats_not_saved', details: { failed: 1 } });
110
+ expect(host.size).toBe(0);
111
+ });
112
+
113
+ it('never hangs a chat under a session that is not in the same archive', async () => {
114
+ const { host, save } = archiveWith({ chats: [{ info: infoOf(CHILD, { parentID: HOST_SESSION }) }] });
115
+ await save();
116
+ expect(host.get(CHILD).info).not.toHaveProperty('parentID');
117
+ });
118
+
119
+ it('saves nothing when one chat cannot be taken out, naming a chat too large by its title', async () => {
120
+ const { archive, host, save, dataDir } = archiveWith({ chats: [
121
+ { info: infoOf(PARENT) },
122
+ { info: infoOf(OTHER, { title: 'Big one' }), fail: new SpaceError('chat_too_large', 'too large') },
123
+ ] });
124
+ await expect(save()).rejects.toMatchObject({ code: 'chats_not_saved', details: { name: 'Fix login', tooLarge: ['Big one'], failed: 0 } });
125
+ expect(host.size).toBe(0);
126
+ expect(archive.listArchives()).toEqual([]);
127
+ expect(fs.readdirSync(path.join(dataDir, 'spaces', 'archive'))).toEqual([]);
128
+ });
129
+
130
+ it('with "delete anyway", saves what can be saved and reports the rest', async () => {
131
+ const { host, save } = archiveWith({ chats: [
132
+ { info: infoOf(PARENT) },
133
+ { info: infoOf(OTHER), fail: new SpaceError('chat_export_failed', 'broken') },
134
+ ] });
135
+ expect(await save(true)).toEqual({ saved: 1, tooLarge: [], failed: 1, listed: true });
136
+ expect(Array.from(host.keys())).toEqual([PARENT]);
137
+ });
138
+
139
+ it('takes back what it imported when a later import fails, so the space stays as it was', async () => {
140
+ const { archive, host, removed, save } = archiveWith({ chats: [{ info: infoOf(PARENT) }, { info: infoOf(OTHER) }], failImportOf: OTHER });
141
+ await expect(save()).rejects.toMatchObject({ code: 'chats_not_saved', details: { failed: 1 } });
142
+ expect(removed).toEqual([PARENT]);
143
+ expect(host.size).toBe(0);
144
+ expect(archive.isArchivedChat(PARENT)).toBe(false);
145
+ });
146
+
147
+ it('counts a space that cannot list its chats, and chats past the cap, as not saved', async () => {
148
+ const { archive, save, source } = archiveWith({ chats: [] });
149
+ source.listChats = async () => { throw new SpaceError('space_not_running', 'stopped'); };
150
+ await expect(save()).rejects.toMatchObject({ code: 'chats_not_saved', details: { listed: false } });
151
+ expect(await save(true)).toEqual({ saved: 0, tooLarge: [], failed: 0, listed: false });
152
+ expect(archive.listArchives()).toEqual([]);
153
+
154
+ const many = Array.from({ length: ARCHIVE_MAX_CHATS + 1 }, (_, index) => ({ info: infoOf(`ses_n${index}`) }));
155
+ await expect(archiveWith({ chats: many }).save()).rejects.toMatchObject({ code: 'chats_not_saved', details: { failed: 1 } });
156
+ });
157
+ });
158
+
159
+ describe('an archived chat is read-only', () => {
160
+ it('refuses every route that would run or change it, and lets it be read and deleted', async () => {
161
+ const { archive, save } = archiveWith({ chats: [{ info: infoOf(PARENT) }] });
162
+ await save();
163
+ for (const [method, requestPath] of [
164
+ ['POST', `/api/session/${PARENT}/prompt`],
165
+ ['POST', `/api/session/${PARENT}/shell`],
166
+ ['POST', `/api/session/${PARENT}/command`],
167
+ ['POST', `/api/session/${PARENT}/fork`],
168
+ ['PATCH', `/api/session/${PARENT}`],
169
+ ['POST', `/api/experimental/session/${PARENT}/skill`],
170
+ ['POST', `/api/openchamber/sessions/${PARENT}/send`],
171
+ ['POST', `/api/openchamber/sessions/${PARENT}/fork`],
172
+ ['POST', `/api/message-queue/sessions/${PARENT}/items`],
173
+ ['PUT', `/api/goals/objective/${PARENT}`],
174
+ ['PUT', `/api/permission-auto-accept/sessions/${PARENT}`],
175
+ ['DELETE', `/api/session/${PARENT}/revert`],
176
+ ]) {
177
+ expect(through(archive, method, requestPath)).toEqual({ code: 409, body: expect.objectContaining({ code: 'archived_chat_read_only' }) });
178
+ }
179
+ expect(through(archive, 'POST', `/api/session/${PARENT.replace('_', '%5F')}/prompt`)).toMatchObject({ code: 409 });
180
+ expect(through(archive, 'POST', `/api/session/${PARENT.replace('_', '%5f')}/shell`)).toMatchObject({ code: 409 });
181
+ expect(through(archive, 'GET', `/api/session/${PARENT}/message`)).toBe('passed');
182
+ expect(through(archive, 'DELETE', `/api/session/${PARENT}`)).toBe('passed');
183
+ expect(through(archive, 'POST', `/api/session/${OTHER}/prompt`)).toBe('passed');
184
+ });
185
+
186
+ it('stays read-only after a restart, from the archive\'s file', async () => {
187
+ const first = archiveWith({ chats: [{ info: infoOf(PARENT) }] });
188
+ await first.save();
189
+ const second = archiveWith({ chats: [], dataDir: first.dataDir });
190
+ expect(second.archive.isArchivedChat(PARENT)).toBe(true);
191
+ expect(through(second.archive, 'POST', `/api/session/${PARENT}/prompt`)).toMatchObject({ code: 409 });
192
+ expect(second.archive.listArchives()).toHaveLength(1);
193
+ });
194
+ });
@@ -1,10 +1,15 @@
1
- // The one place that writes OpenCode's own files inside a space, so an OpenCode format change is
1
+ // The one place that knows OpenCode's own formats inside a space, so an OpenCode format change is
2
2
  // a one-file edit (DESIGN.md, "Parts"). Today: the provider configuration that sends a provider's
3
- // model calls through the gatekeeper's window. The login record for the short OpenAI token and
4
- // the move of a chat to the host's archive belong here too, in their stages.
3
+ // model calls through the gatekeeper's window, and since 5e-2 a chat taken out of a space for the
4
+ // host's archive. The login record for the short OpenAI token belongs here too, in its stage.
5
5
  //
6
6
  // What is written here cooperates and enforces nothing. The agent can change or delete the file;
7
7
  // the gatekeeper is what keeps the key out of the space and the space away from the internet.
8
+ //
9
+ // A chat taken out is untrusted data, like everything from a space: its record is rebuilt from a
10
+ // few checked fields, and the messages go to the host's OpenCode, whose import checks their shape.
11
+
12
+ import { z } from 'zod';
8
13
 
9
14
  import { SpaceError } from './errors.js';
10
15
  import { tail } from './exec-http.js';
@@ -37,8 +42,110 @@ export function buildProviderConfig(grants) {
37
42
  return { $schema: 'https://opencode.ai/config.json', provider };
38
43
  }
39
44
 
40
- /** `exec` is the place operation, always for the space container. */
41
- export function createSpaceOpenCode({ exec }) {
45
+ // A chat larger than this is not taken out: the host reads one chat into memory at a time, and a
46
+ // space can answer with as much as it likes. The maintainer's call of 2026-09-30; the largest chat
47
+ // measured on a real OpenCode was 94 MB.
48
+ const CHAT_EXPORT_MAX_BYTES = 256 * 1024 * 1024;
49
+ // A chat that has not come whole in this time is not taken out, however slowly the space keeps
50
+ // sending: a space must not hold its own delete.
51
+ const CHAT_EXPORT_TIMEOUT_MS = 5 * 60_000;
52
+
53
+ // OpenCode's session id, checked before it goes into a path.
54
+ export const chatIdSchema = z.string().regex(/^ses_[A-Za-z0-9]{1,64}$/);
55
+
56
+ const instantSchema = z.number().int().nonnegative();
57
+ const countSchema = z.number().nonnegative();
58
+
59
+ // What the host takes of a chat's record. Everything else the space says about it, its permissions,
60
+ // metadata, agent, model and revert among them, is dropped: an archive is read and never run.
61
+ const exportedInfoSchema = z.object({
62
+ id: chatIdSchema,
63
+ parentID: chatIdSchema.optional(),
64
+ projectID: z.string().min(1).max(256),
65
+ cost: countSchema,
66
+ tokens: z.object({
67
+ input: countSchema,
68
+ output: countSchema,
69
+ reasoning: countSchema,
70
+ cache: z.object({ read: countSchema, write: countSchema }),
71
+ }),
72
+ outcome: z.enum(['succeeded', 'failed', 'interrupted']).optional(),
73
+ time: z.object({ created: instantSchema, updated: instantSchema, idle: instantSchema.optional() }),
74
+ title: z.string().max(4096).optional(),
75
+ });
76
+
77
+ // The messages travel whole; the host's OpenCode checks each one against its own schema on import.
78
+ const exportedChatSchema = z.object({
79
+ data: z.object({
80
+ info: exportedInfoSchema,
81
+ messages: z.array(z.object({ id: z.string().min(1), type: z.string().min(1) }).passthrough()),
82
+ }),
83
+ });
84
+
85
+ /**
86
+ * Reads an answer from inside up to `cap` bytes and until `deadline`; a longer one is
87
+ * `chat_too_large`, a slower one `chat_export_timed_out`.
88
+ */
89
+ const readCapped = (response, cap, timeoutMs) => new Promise((resolve, reject) => {
90
+ const chunks = [];
91
+ let size = 0;
92
+ const fail = (error) => {
93
+ clearTimeout(timer);
94
+ response.destroy();
95
+ reject(error);
96
+ };
97
+ const timer = setTimeout(() => fail(new SpaceError('chat_export_timed_out', `The chat did not come whole in ${timeoutMs} ms`)), timeoutMs);
98
+ response.on('data', (chunk) => {
99
+ size += chunk.length;
100
+ if (size > cap) {
101
+ fail(new SpaceError('chat_too_large', `The chat is larger than ${cap} bytes`));
102
+ return;
103
+ }
104
+ chunks.push(chunk);
105
+ });
106
+ response.on('end', () => {
107
+ clearTimeout(timer);
108
+ resolve(Buffer.concat(chunks));
109
+ });
110
+ response.on('error', (error) => fail(error));
111
+ });
112
+
113
+ // Every tool of every agent refused in an archived chat, by OpenCode itself. The chat lives in the
114
+ // host's OpenCode, which VS Code, the OpenCode CLI and any other client reach without OpenChamber's
115
+ // server; a turn someone starts there anyway runs no tool on the host. OpenCode takes the last
116
+ // rule that matches, and a session's rules come after the agent's.
117
+ const ARCHIVED_CHAT_PERMISSIONS = Object.freeze([Object.freeze({ action: '*', resource: '*', effect: 'deny' })]);
118
+
119
+ /**
120
+ * What the host's OpenCode imports for a chat of a deleted space: the checked record at the
121
+ * archive's own directory, stamped archived, with every tool refused, and with `parentID` only
122
+ * when the parent is in the same archive, so a space cannot hang its chat under a session of the
123
+ * host's.
124
+ */
125
+ export function archivedChatOf({ info, messages }, { directory, archivedAt, keepParent }) {
126
+ const time = { created: info.time.created, updated: info.time.updated, archived: archivedAt };
127
+ if (info.time.idle !== undefined) time.idle = info.time.idle;
128
+ const record = {
129
+ id: info.id,
130
+ projectID: info.projectID,
131
+ cost: info.cost,
132
+ tokens: info.tokens,
133
+ time,
134
+ location: { directory },
135
+ permissions: ARCHIVED_CHAT_PERMISSIONS,
136
+ };
137
+ if (info.parentID && keepParent) record.parentID = info.parentID;
138
+ if (info.outcome) record.outcome = info.outcome;
139
+ if (info.title !== undefined) record.title = info.title;
140
+ return { info: record, messages, location: { directory } };
141
+ }
142
+
143
+ /**
144
+ * `exec` is the place operation, always for the space container. `requestInside` is the
145
+ * dispatcher's own request to the server inside, which a chat is taken out through, and
146
+ * `chatMaxBytes` and `chatTimeoutMs` the caps on one chat, smaller in the tests.
147
+ */
148
+ export function createSpaceOpenCode({ exec, requestInside, chatMaxBytes = CHAT_EXPORT_MAX_BYTES, chatTimeoutMs = CHAT_EXPORT_TIMEOUT_MS }) {
42
149
  /** Writes the whole global configuration from the model grants the record holds. */
43
150
  const writeProviderConfig = async (spaceId, grants) => {
44
151
  const text = `${JSON.stringify(buildProviderConfig(grants), null, 2)}\n`;
@@ -48,5 +155,31 @@ export function createSpaceOpenCode({ exec }) {
48
155
  }
49
156
  };
50
157
 
51
- return { writeProviderConfig };
158
+ /**
159
+ * One chat of a space as OpenCode exports it, checked: `{ info, messages }`. A chat over the cap
160
+ * is `chat_too_large`; anything else that does not come whole is `chat_export_failed`.
161
+ */
162
+ const exportChat = async (spaceId, chatId) => {
163
+ const id = chatIdSchema.parse(chatId);
164
+ const response = await requestInside(spaceId, {
165
+ path: `/api/experimental/session/${id}/export`,
166
+ headers: { accept: 'application/json' },
167
+ timeoutMs: chatTimeoutMs,
168
+ });
169
+ if (response.statusCode !== 200) {
170
+ response.resume();
171
+ throw new SpaceError('chat_export_failed', `The space answered ${response.statusCode} for chat ${id}`);
172
+ }
173
+ const body = await readCapped(response, chatMaxBytes, chatTimeoutMs);
174
+ let parsed;
175
+ try {
176
+ parsed = exportedChatSchema.safeParse(JSON.parse(body.toString('utf8')));
177
+ } catch {
178
+ parsed = { success: false };
179
+ }
180
+ if (!parsed.success || parsed.data.data.info.id !== id) throw new SpaceError('chat_export_failed', `The space did not give chat ${id} whole`);
181
+ return parsed.data.data;
182
+ };
183
+
184
+ return { writeProviderConfig, exportChat };
52
185
  }
@@ -1,6 +1,8 @@
1
+ import { Readable } from 'node:stream';
2
+
1
3
  import { describe, expect, it } from 'vitest';
2
4
 
3
- import { WINDOW_PLACEHOLDER_KEY, buildProviderConfig, createSpaceOpenCode } from './space-opencode.js';
5
+ import { WINDOW_PLACEHOLDER_KEY, archivedChatOf, buildProviderConfig, createSpaceOpenCode } from './space-opencode.js';
4
6
 
5
7
  const ID = 'a1b2c3d4e5f6';
6
8
  const GRANTS = [
@@ -39,3 +41,82 @@ describe('the provider configuration inside a space', () => {
39
41
  await expect(opencode.writeProviderConfig(ID, GRANTS)).rejects.toMatchObject({ code: 'space_setup_failed', message: expect.stringContaining('Read-only file system') });
40
42
  });
41
43
  });
44
+
45
+ describe('a chat taken out of a space for the archive', () => {
46
+ const CHAT = 'ses_f10ac21b9ffeQoN3eUQ3H9hwpf';
47
+ const INFO = {
48
+ id: CHAT,
49
+ projectID: 'p1',
50
+ cost: 0.5,
51
+ tokens: { input: 1, output: 2, reasoning: 0, cache: { read: 0, write: 0 } },
52
+ outcome: 'failed',
53
+ time: { created: 10, updated: 20, idle: 15 },
54
+ title: 'Fix the greeting',
55
+ location: { directory: '/spaces/a1b2c3d4e5f6/demo' },
56
+ permissions: [{ permission: '*', pattern: '*', action: 'allow' }],
57
+ metadata: { goal: 'run forever' },
58
+ agent: 'build',
59
+ };
60
+ const MESSAGES = [{ id: 'msg_1', type: 'user', text: 'hello <script>' }];
61
+ const answering = (statusCode, body) => {
62
+ const asked = [];
63
+ const requestInside = async (spaceId, request) => {
64
+ asked.push({ spaceId, ...request });
65
+ const response = Readable.from([Buffer.from(body instanceof Object ? JSON.stringify(body) : body)]);
66
+ response.statusCode = statusCode;
67
+ return response;
68
+ };
69
+ return { asked, opencode: createSpaceOpenCode({ exec: async () => ({ code: 0 }), requestInside, chatMaxBytes: 4096 }) };
70
+ };
71
+
72
+ it('asks the server inside for the export and keeps only the checked fields of the record', async () => {
73
+ const { asked, opencode } = answering(200, { data: { info: INFO, messages: MESSAGES } });
74
+ const chat = await opencode.exportChat(ID, CHAT);
75
+ expect(asked).toEqual([expect.objectContaining({ spaceId: ID, path: `/api/experimental/session/${CHAT}/export` })]);
76
+ expect(chat.messages).toEqual(MESSAGES);
77
+ expect(chat.info).not.toHaveProperty('permissions');
78
+ expect(chat.info).not.toHaveProperty('metadata');
79
+ expect(chat.info).not.toHaveProperty('agent');
80
+ });
81
+
82
+ it('refuses a chat over the cap, one that is not whole, and one that names another id', async () => {
83
+ await expect(answering(200, 'x'.repeat(5000)).opencode.exportChat(ID, CHAT)).rejects.toMatchObject({ code: 'chat_too_large' });
84
+ await expect(answering(200, '{"data":').opencode.exportChat(ID, CHAT)).rejects.toMatchObject({ code: 'chat_export_failed' });
85
+ await expect(answering(404, {}).opencode.exportChat(ID, CHAT)).rejects.toMatchObject({ code: 'chat_export_failed' });
86
+ await expect(answering(200, { data: { info: { ...INFO, id: 'ses_other' }, messages: [] } }).opencode.exportChat(ID, CHAT)).rejects.toMatchObject({ code: 'chat_export_failed' });
87
+ await expect(answering(200, {}).opencode.exportChat(ID, '../../config')).rejects.toThrow();
88
+ });
89
+
90
+ it('gives up on a chat that does not come whole in time, however slowly the space keeps sending', async () => {
91
+ const requestInside = async () => {
92
+ const response = new Readable({ read() {} });
93
+ response.statusCode = 200;
94
+ response.push('{"data":');
95
+ return response;
96
+ };
97
+ const opencode = createSpaceOpenCode({ exec: async () => ({ code: 0 }), requestInside, chatTimeoutMs: 50 });
98
+ await expect(opencode.exportChat(ID, CHAT)).rejects.toMatchObject({ code: 'chat_export_timed_out' });
99
+ });
100
+
101
+ it('builds the import at the archive directory, stamped archived, with a parent only from the same archive', () => {
102
+ const exported = { info: { ...INFO, parentID: 'ses_parent1' }, messages: MESSAGES };
103
+ const kept = archivedChatOf(exported, { directory: '/data/spaces/archive/a1b2c3d4e5f6', archivedAt: 99, keepParent: true });
104
+ expect(kept).toEqual({
105
+ info: {
106
+ id: CHAT,
107
+ parentID: 'ses_parent1',
108
+ projectID: 'p1',
109
+ cost: 0.5,
110
+ tokens: INFO.tokens,
111
+ outcome: 'failed',
112
+ time: { created: 10, updated: 20, idle: 15, archived: 99 },
113
+ title: 'Fix the greeting',
114
+ location: { directory: '/data/spaces/archive/a1b2c3d4e5f6' },
115
+ permissions: [{ action: '*', resource: '*', effect: 'deny' }],
116
+ },
117
+ messages: MESSAGES,
118
+ location: { directory: '/data/spaces/archive/a1b2c3d4e5f6' },
119
+ });
120
+ expect(archivedChatOf(exported, { directory: '/d', archivedAt: 99, keepParent: false }).info).not.toHaveProperty('parentID');
121
+ });
122
+ });
@@ -69,6 +69,8 @@ const MAX_GRANTS = 100;
69
69
 
70
70
  // The setup commands' last run (5d-4): begun, finished, or failed with the end of its output,
71
71
  // which came from inside the space and is text to show. `space-setup.js` keeps it within these.
72
+ // A failed run keeps when it began, so the client can find what the gatekeeper refused meanwhile;
73
+ // a record from before that has no `startedAt`.
72
74
  const setupCountSchema = z.number().int().min(1).max(MAX_SETUP_COMMANDS);
73
75
  const setupSchema = z.discriminatedUnion('state', [
74
76
  z.object({ state: z.literal('running'), total: setupCountSchema, startedAt: z.string() }).strict(),
@@ -81,6 +83,7 @@ const setupSchema = z.discriminatedUnion('state', [
81
83
  exitCode: z.number().int().nullable(),
82
84
  timedOut: z.boolean(),
83
85
  output: z.string().max(MAX_KEPT_OUTPUT_CHARACTERS),
86
+ startedAt: z.string().optional(),
84
87
  finishedAt: z.string(),
85
88
  }).strict(),
86
89
  ]);
@@ -75,7 +75,7 @@ export const keptOutputOf = (text) => {
75
75
  * clients that a space's setup moved on, so they read the list again.
76
76
  */
77
77
  export function createSpaceSetup({ exec, records, announce = () => {}, logger = console, now = () => new Date() }) {
78
- // The runs under way, by space id: which command of how many.
78
+ // The runs under way, by space id: which command of how many, and when the run began.
79
79
  const runs = new Map();
80
80
 
81
81
  const remember = (spaceId, setup) => {
@@ -125,7 +125,7 @@ export function createSpaceSetup({ exec, records, announce = () => {}, logger =
125
125
  if (index > 0) announce(spaceId);
126
126
  const outcome = await runOne(spaceId, projectPath, command);
127
127
  if (outcome.exitCode !== 0) {
128
- remember(spaceId, { state: 'failed', total: commands.length, index, command, ...outcome, finishedAt: now().toISOString() });
128
+ remember(spaceId, { state: 'failed', total: commands.length, index, command, ...outcome, startedAt: run.startedAt, finishedAt: now().toISOString() });
129
129
  logger.warn?.(`[spaces] setup command ${index + 1} of ${commands.length} failed in space ${spaceId}: exit ${outcome.exitCode}${outcome.timedOut ? ', timed out' : ''}`);
130
130
  return;
131
131
  }
@@ -144,8 +144,9 @@ export function createSpaceSetup({ exec, records, announce = () => {}, logger =
144
144
  const start = (spaceId, { projectPath, commands }) => {
145
145
  if (runs.has(spaceId)) throw new SpaceError('space_setup_running', 'The setup commands of this space are still running. Wait for them to finish.');
146
146
  if (commands.length === 0) throw new SpaceError('invalid_setup_commands', 'There are no setup commands to run.');
147
- runs.set(spaceId, { index: 0, total: commands.length, command: commands[0] });
148
- remember(spaceId, { state: 'running', total: commands.length, startedAt: now().toISOString() });
147
+ const startedAt = now().toISOString();
148
+ runs.set(spaceId, { index: 0, total: commands.length, command: commands[0], startedAt });
149
+ remember(spaceId, { state: 'running', total: commands.length, startedAt });
149
150
  announce(spaceId);
150
151
  void runAll(spaceId, projectPath, commands);
151
152
  };
@@ -163,7 +164,11 @@ export function createSpaceSetup({ exec, records, announce = () => {}, logger =
163
164
  if (kept === null) return null;
164
165
  if (kept.state === 'running') return { state: 'interrupted', total: kept.total };
165
166
  if (kept.state === 'done') return { state: 'done', total: kept.total };
166
- return { state: 'failed', index: kept.index, total: kept.total, command: kept.command, exitCode: kept.exitCode, timedOut: kept.timedOut };
167
+ // The run's span, for the client to read the gatekeeper's refusals within; null from a record before it was kept.
168
+ return {
169
+ state: 'failed', index: kept.index, total: kept.total, command: kept.command, exitCode: kept.exitCode, timedOut: kept.timedOut,
170
+ startedAt: kept.startedAt ?? null, finishedAt: kept.finishedAt,
171
+ };
167
172
  };
168
173
 
169
174
  /** The end of the failed command's output, or null when no command failed. */
@@ -102,8 +102,8 @@ describe('setup commands inside a space', () => {
102
102
  expect(await until(() => !setup.isRunning(ID))).toBe(true);
103
103
  expect(calls).toHaveLength(2);
104
104
  const { record } = records.read(ID);
105
- expect(record.setup).toEqual({ state: 'failed', total: 3, index: 1, command: 'npm ci', exitCode: 1, timedOut: false, output: 'npm ERR! 403 Forbidden\nfetch 100%', finishedAt: '2026-09-28T10:00:00.000Z' });
106
- expect(setup.describe(ID, record)).toEqual({ state: 'failed', index: 1, total: 3, command: 'npm ci', exitCode: 1, timedOut: false });
105
+ expect(record.setup).toEqual({ state: 'failed', total: 3, index: 1, command: 'npm ci', exitCode: 1, timedOut: false, output: 'npm ERR! 403 Forbidden\nfetch 100%', startedAt: '2026-09-28T10:00:00.000Z', finishedAt: '2026-09-28T10:00:00.000Z' });
106
+ expect(setup.describe(ID, record)).toEqual({ state: 'failed', index: 1, total: 3, command: 'npm ci', exitCode: 1, timedOut: false, startedAt: '2026-09-28T10:00:00.000Z', finishedAt: '2026-09-28T10:00:00.000Z' });
107
107
  expect(setup.outputOf(record)).toBe('npm ERR! 403 Forbidden\nfetch 100%');
108
108
  });
109
109
 
@@ -130,6 +130,12 @@ describe('setup commands inside a space', () => {
130
130
  expect(hostWait.records.read(ID).record.setup).toMatchObject({ exitCode: null, timedOut: true });
131
131
  });
132
132
 
133
+ it('answers no start for a failure kept before the start was', () => {
134
+ const { setup, records } = setupWith();
135
+ records.update(ID, { setup: { state: 'failed', total: 1, index: 0, command: 'npm ci', exitCode: 1, timedOut: false, output: 'x', finishedAt: '2026-09-28T10:00:00.000Z' } });
136
+ expect(setup.describe(ID, records.read(ID).record)).toMatchObject({ state: 'failed', startedAt: null, finishedAt: '2026-09-28T10:00:00.000Z' });
137
+ });
138
+
133
139
  it('lists a run the record says began, with no run in this process, as interrupted', () => {
134
140
  const { setup, records } = setupWith();
135
141
  records.update(ID, { setup: { state: 'running', total: 3, startedAt: '2026-09-28T09:00:00.000Z' } });
@@ -30,6 +30,7 @@ HTTP remains the authenticated command plane for create, resize, appearance upda
30
30
  - A client may create before its renderer has mounted. It derives an initial size from the container and font metrics (falling back to 80x24 when unavailable), then sends a resize once Ghostty reports its final dimensions. This allows shell startup and renderer initialization to overlap.
31
31
  - PTY children never inherit `NODE_CHANNEL_FD`; daemon IPC descriptors are host-private and invalid after PTY descriptor cleanup, and an inherited value (even empty) makes Node CLIs such as opencode print `Failed to parse IPC channel number` on exit.
32
32
  - PTY children also strip AppImage `ARGV0` (and other host-private shell vars such as `ELECTRON_RUN_AS_NODE`, `BASH_ENV`, `ENV`, `BASH_XTRACEFD`). An exported `ARGV0` makes zsh rewrite argv[0] for every external command, which breaks Python venv detection and other argv[0]/$0 consumers while leaving `/proc/self/exe` correct. On POSIX, PTY spawn is wrapped with `env -u ARGV0 -u NODE_CHANNEL_FD` (`resolvePosixPtyLaunch`) because `bun-pty` merges the native OS environ and would otherwise reintroduce both after a JS-only delete.
33
+ - Inside a Linux AppImage (`APPDIR` set), PTY children, the managed OpenCode server and the server's git environment (`buildGitEnv`) also lose what the AppImage launcher added to `PATH`, `LD_LIBRARY_PATH`, `GSETTINGS_SCHEMA_DIR` and `XDG_DATA_DIRS` (`stripAppImageLauncherEnv`): the mount's `usr/lib`, `usr/share` and `usr/sbin`, the mount root, the relative `./share/`, and the empty entries the launcher leaves when a variable was unset. Otherwise user tools load the app's bundled libraries, and an empty `LD_LIBRARY_PATH` entry makes the dynamic linker search the current directory (#4177). The user's own entries and the bundled OpenCode CLI directory stay. No `env -u` is needed: only Electron runs from an AppImage, and its `node-pty` uses the given env as is.
33
34
  - `GET /api/terminal/shells` reports shell IDs available on the active server using the same augmented PATH provided to spawned PTYs, plus whether each executable has a supported login-mode argument. `auto` preserves environment/platform fallback order; an explicit unavailable shell fails creation instead of silently running a different shell. Login mode is opt-in and uses only built-in arguments for known shells. Interactive shells still launch as before. Command-mode launches reuse the same environment and login support, but switch argv by shell family: POSIX and Fish use interactive `-c`, Nushell uses `-c`, PowerShell uses `-Command`, and cmd uses `/d /s /c`. Preference changes affect new sessions and explicit restarts, not running PTYs.
34
35
  - PTY data and exit callbacks enter one FIFO queue. The runtime wires those listeners in the same synchronous turn that receives the PTY object. `node-pty` and `bun-pty` both expose the PTY before dispatching registered callbacks. If a backend emitted exit before listener registration, this layer could not recover it, so the wiring stays adjacent to PTY creation.
35
36
  - Scrollback is retained on the server and capped at 512 KiB with UTF-8-safe trimming. Device-status, device-attribute, cursor-position reply, and color-query exchanges are removed from replay history with incomplete control sequences carried across PTY chunks; live output remains byte-for-byte unchanged.
@@ -10,7 +10,7 @@ import {
10
10
  import { sanitizeTerminalHistoryChunk } from './history.js';
11
11
  import { consumeTerminalThemeQueries, terminalThemeModeReport } from './theme-response.js';
12
12
  import { buildTerminalShellLaunch, createTerminalShellResolver, normalizeTerminalShell } from './shells.js';
13
- import { stripAppImageArgv0Leak, resolvePosixPtyLaunch } from '../inherited-env.js';
13
+ import { stripAppImageArgv0Leak, stripAppImageLauncherEnv, resolvePosixPtyLaunch } from '../inherited-env.js';
14
14
  import { shutdownTerminalProcesses } from './shutdown.js';
15
15
 
16
16
  const MAX_SESSIONS = 20;
@@ -131,6 +131,11 @@ export function createTerminalRuntime({
131
131
  delete env.BASH_XTRACEFD; delete env.BASH_ENV; delete env.ENV; delete env.ELECTRON_RUN_AS_NODE;
132
132
  // AppImage exports ARGV0; zsh would otherwise rewrite argv[0] for every command (#2588).
133
133
  stripAppImageArgv0Leak(env);
134
+ // The AppImage launcher also prepends its own directories to PATH, LD_LIBRARY_PATH,
135
+ // GSETTINGS_SCHEMA_DIR and XDG_DATA_DIRS (#4177). Only the desktop app runs from an
136
+ // AppImage, and it spawns through node-pty, which uses this env as given, so these
137
+ // need no `env -u` below.
138
+ stripAppImageLauncherEnv(env);
134
139
  const shellLaunch = buildTerminalShellLaunch(executable, { mode, command, loginShell });
135
140
  // bun-pty merges the native OS environ back in, so the POSIX launch is
136
141
  // wrapped with `env -u` for the variables deleted above.
@@ -459,6 +459,25 @@ describe('terminal runtime', () => {
459
459
  }
460
460
  });
461
461
 
462
+ it('removes the AppImage launcher entries from the PTY environment', async () => {
463
+ const previous = { APPDIR: process.env.APPDIR, LD_LIBRARY_PATH: process.env.LD_LIBRARY_PATH };
464
+ process.env.APPDIR = '/tmp/.mount_OpenChAbC123';
465
+ process.env.LD_LIBRARY_PATH = '/tmp/.mount_OpenChAbC123/usr/lib:/opt/cuda/lib64:';
466
+ const harness = createHarness();
467
+ try {
468
+ const response = createResponse();
469
+ await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'term-ld-path', cwd: '/repo', cols: 80, rows: 24 } }, response);
470
+ expect(response.statusCode).toBe(200);
471
+ expect(harness.processes[0].options.env.LD_LIBRARY_PATH).toBe('/opt/cuda/lib64');
472
+ } finally {
473
+ for (const [key, value] of Object.entries(previous)) {
474
+ if (value === undefined) delete process.env[key];
475
+ else process.env[key] = value;
476
+ }
477
+ await harness.runtime.shutdown();
478
+ }
479
+ });
480
+
462
481
  it('lists available shells and uses the selected shell for create and restart', async () => {
463
482
  const executables = new Set(['/bin/zsh', '/bin/bash', '/bin/sh']);
464
483
  const harness = createHarness({
@@ -74,7 +74,7 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
74
74
  const { ttsService } = await getTtsModule();
75
75
 
76
76
  // Check availability - server-configured key, client-provided key, or custom server URL
77
- const hasServerKey = ttsService.isAvailable();
77
+ const hasServerKey = await ttsService.isAvailable();
78
78
  const hasClientKey = apiKey && typeof apiKey === 'string' && apiKey.trim().length > 0;
79
79
  const hasCustomBaseURL = typeof normalizedBaseURL === 'string' && normalizedBaseURL.length > 0;
80
80
 
@@ -147,7 +147,7 @@ export function registerTtsRoutes(app, { sayTTSCapability }) {
147
147
  const { ttsService } = await getTtsModule();
148
148
  const enterpriseMode = isEnterpriseMode();
149
149
  res.json({
150
- available: !enterpriseMode && ttsService.isAvailable(),
150
+ available: !enterpriseMode && await ttsService.isAvailable(),
151
151
  enterpriseMode,
152
152
  voices: [
153
153
  'alloy', 'ash', 'ballad', 'coral', 'echo', 'fable',