@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
@@ -34,7 +34,7 @@ afterEach(() => {
34
34
  });
35
35
 
36
36
  /** A journey on fresh stand-ins. `failAt` names a stand-in step that rejects. */
37
- const journeyWith = ({ failAt = null, place = createMemoryPlace(), projects = [PROJECT], historyStatus = 'sent', holdCodeIn = false, holdCodeOut = false, holdIdleSave = false, hostEnvironment = {}, dataDir = null } = {}) => {
37
+ const journeyWith = ({ failAt = null, place = createMemoryPlace(), projects = [PROJECT], historyStatus = 'sent', holdCodeIn = false, holdCodeOut = false, holdIdleSave = false, hostEnvironment = {}, dataDir = null, archiveChats = null, logger = quiet } = {}) => {
38
38
  // With `holdCodeIn`, code in waits until the test lets it go, so a creation stays under way;
39
39
  // `holdCodeOut` does the same for the fetch of an apply.
40
40
  let releaseCodeIn = () => {};
@@ -78,7 +78,11 @@ const journeyWith = ({ failAt = null, place = createMemoryPlace(), projects = [P
78
78
  return { spacePath: `/spaces/${request.spaceId}/project`, projectPath: `/spaces/${request.spaceId}/project`, base: BASE, identityCopied: { name: true, email: false } };
79
79
  },
80
80
  sendHistory: async (request) => { calls.push(['sendHistory', request]); fail('sendHistory'); return { status: historyStatus }; },
81
- removeSpaceRefs: async (request) => { calls.push(['removeSpaceRefs', request]); fail('removeSpaceRefs'); },
81
+ removeSpaceRefs: async (request) => {
82
+ calls.push(['removeSpaceRefs', request]);
83
+ fail('removeSpaceRefs');
84
+ if (failAt === 'projectFolderGone') throw new SpaceError('project_folder_missing', `${request.repository} does not exist, or is not a folder.`);
85
+ },
82
86
  };
83
87
  const codeOut = {
84
88
  bringCodeOut: async (request) => { calls.push(['bringCodeOut', request]); if (holdCodeOut) await codeOutHeld; fail('bringCodeOut'); return { result: 'c'.repeat(40), changedPaths: 3, changedBytes: 10, nestedRepositories: { count: 0, paths: [] }, unmerged: { count: 0, paths: [] } }; },
@@ -91,12 +95,14 @@ const journeyWith = ({ failAt = null, place = createMemoryPlace(), projects = [P
91
95
  const journey = createSpaceJourney({
92
96
  manager, place, gatekeeper, codeIn, codeOut, records, spaceOpenCode, serverInside, restartOpenCodeInside,
93
97
  listProjectDirectories: async () => projects,
98
+ archiveChats,
94
99
  readHostSecret: (name) => hostEnvironment[name],
100
+ folderExists: async () => true,
95
101
  readIdleStop: async () => idle.saved ?? { enabled: true, hours: 4 },
96
102
  saveIdleStop: async (setting) => { if (holdIdleSave) await idleSaveHeld; fail('saveIdleStop'); idle.saved = setting; },
97
103
  announce: (spaceId, payload) => { events.push({ spaceId, ...payload.properties }); },
98
104
  onSpacesChanged: () => { changes.count += 1; },
99
- logger: quiet,
105
+ logger,
100
106
  now: () => new Date('2026-09-26T10:00:00.000Z'),
101
107
  });
102
108
  return { journey, place, records, calls, events, changes, manager, releaseCodeIn, releaseCodeOut, gatekeeper, dataDir, idle };
@@ -150,7 +156,7 @@ describe('the journey: create', () => {
150
156
  expect(await journey.listSpaces()).toEqual([expect.objectContaining({ id, state: 'failed', step: 'failed', failure: expect.objectContaining({ code: `${failAt}_failed` }) })]);
151
157
 
152
158
  // The failure is dismissed by removing it; the place is not asked, there is nothing there.
153
- expect(await journey.removeSpace(id)).toEqual({ id, removed: true, refsRemoved: null, failures: [] });
159
+ expect(await journey.removeSpace(id)).toEqual({ id, removed: true, refsRemoved: null, failures: [], chats: null });
154
160
  expect(await journey.listSpaces()).toEqual([]);
155
161
  });
156
162
 
@@ -190,6 +196,49 @@ describe('the journey: create', () => {
190
196
  });
191
197
  });
192
198
 
199
+ describe('the journey: disk and clean-up', () => {
200
+ const DISK = { imageBytes: 1_632_000_000, toolsBytes: 438_000_000, spacesBytes: 0, freeBytes: 1_632_000_000, freesImage: true };
201
+ const placeWithDisk = (cleaned) => ({
202
+ ...createMemoryPlace(),
203
+ readDisk: async () => DISK,
204
+ cleanUpDisk: async () => { cleaned.count += 1; return cleaned.outcome; },
205
+ });
206
+
207
+ it('answers what was freed and the disk after, keeps Docker\'s words out of the answer and logs them', async () => {
208
+ const warnings = [];
209
+ const cleaned = {
210
+ count: 0,
211
+ outcome: {
212
+ freedBytes: 440_000_000,
213
+ kept: [{ kind: 'image', name: 'node@sha256:0', reason: 'in_use', message: 'image is being used' }, { kind: 'tools', name: 'openchamber-tools-x', reason: 'failed', message: 'disk on fire' }],
214
+ machine: { state: 'failed', message: 'sudo: a password is required' },
215
+ },
216
+ };
217
+ const { journey } = journeyWith({ place: placeWithDisk(cleaned), logger: { warn: (line) => warnings.push(line) } });
218
+ expect(await journey.readDisk('memory')).toEqual(DISK);
219
+ expect(await journey.cleanUpDisk('memory')).toEqual({ freedBytes: 440_000_000, kept: [{ kind: 'image', reason: 'in_use' }, { kind: 'tools', reason: 'failed' }], disk: DISK });
220
+ expect(warnings).toEqual([
221
+ '[spaces] clean-up could not remove tools openchamber-tools-x: disk on fire',
222
+ '[spaces] the Colima machine did not trim its disk: sudo: a password is required',
223
+ ]);
224
+ });
225
+
226
+ it('refuses an unknown place, and a clean-up while a space is being made', async () => {
227
+ const cleaned = { count: 0, outcome: { freedBytes: 0, kept: [], machine: { state: 'skipped' } } };
228
+ const { journey, events, releaseCodeIn } = journeyWith({ place: placeWithDisk(cleaned), holdCodeIn: true });
229
+ await expect(journey.readDisk('kubernetes')).rejects.toMatchObject({ code: 'place_not_found' });
230
+ await expect(journey.cleanUpDisk('kubernetes')).rejects.toMatchObject({ code: 'place_not_found' });
231
+ const { id } = await journey.createSpace(REQUEST);
232
+ expect(await until(() => steps(events, id).includes('bringing_code'))).toBe(true);
233
+ await expect(journey.cleanUpDisk('memory')).rejects.toMatchObject({ code: 'space_preparing' });
234
+ expect(cleaned.count).toBe(0);
235
+ releaseCodeIn();
236
+ expect(await until(() => steps(events, id).includes('ready'))).toBe(true);
237
+ await journey.cleanUpDisk('memory');
238
+ expect(cleaned.count).toBe(1);
239
+ });
240
+ });
241
+
193
242
  describe('the journey: start, stop, remove', () => {
194
243
  const ready = async (options) => {
195
244
  const made = journeyWith(options);
@@ -236,7 +285,7 @@ describe('the journey: start, stop, remove', () => {
236
285
 
237
286
  it('removes the space, the refs in the user\'s repository and the record', async () => {
238
287
  const { journey, place, records, calls, id } = await ready();
239
- expect(await journey.removeSpace(id)).toEqual({ id, removed: true, refsRemoved: true, failures: [] });
288
+ expect(await journey.removeSpace(id)).toEqual({ id, removed: true, refsRemoved: true, failures: [], chats: null });
240
289
  expect(calls).toEqual([['removeSpaceRefs', { repository: PROJECT, spaceId: id }]]);
241
290
  expect(await place.list()).toEqual([]);
242
291
  expect(records.read(id).status).toBe('missing');
@@ -250,6 +299,13 @@ describe('the journey: start, stop, remove', () => {
250
299
  expect(await place.list()).toEqual([]);
251
300
  });
252
301
 
302
+ it('counts a delete as done when the project folder is gone and its refs with it', async () => {
303
+ const { journey, place, records, id } = await ready({ failAt: 'projectFolderGone' });
304
+ expect(await journey.removeSpace(id)).toEqual({ id, removed: true, refsRemoved: false, failures: [], chats: null });
305
+ expect(await place.list()).toEqual([]);
306
+ expect(records.read(id).status).toBe('missing');
307
+ });
308
+
253
309
  it('refuses to start, stop or remove a space that is still being made', async () => {
254
310
  const { journey, events, releaseCodeIn } = journeyWith({ holdCodeIn: true });
255
311
  const { id } = await journey.createSpace(REQUEST);
@@ -685,6 +741,15 @@ describe('the journey: journal and apply', () => {
685
741
  ]);
686
742
  });
687
743
 
744
+ it('refuses to preview or apply a stopped space with its own code, before reaching into it', async () => {
745
+ const { journey, id, calls } = await ready();
746
+ await journey.stopSpace(id);
747
+ calls.splice(0);
748
+ await expect(journey.previewApply(id)).rejects.toMatchObject({ code: 'space_not_running' });
749
+ await expect(journey.applySpace(id, { as: 'changes' })).rejects.toMatchObject({ code: 'space_not_running' });
750
+ expect(calls).toEqual([]);
751
+ });
752
+
688
753
  it('applies as a branch, then removes the space when asked, and only after the apply went through', async () => {
689
754
  const { journey, place, id, calls } = await ready();
690
755
  const outcome = await journey.applySpace(id, { as: 'branch', branch: 'space/fix-login', removeAfterwards: true });
@@ -739,7 +804,56 @@ describe('the journey: journal and apply', () => {
739
804
  const orphan = journeyWith({ projects: [] });
740
805
  const other = await orphan.manager.createSpace({ placeId: 'memory', projectDirectory: PROJECT, name: 'Orphan' });
741
806
  await expect(orphan.journey.previewApply(other.id)).rejects.toMatchObject({ code: 'project_not_registered' });
742
- expect((await orphan.journey.listSpaces())[0]).toMatchObject({ id: other.id, projectDirectory: null, directory: null });
807
+ expect((await orphan.journey.listSpaces())[0]).toMatchObject({ id: other.id, projectDirectory: null, directory: null, projectFolder: { path: null, found: null } });
808
+ });
809
+ });
810
+
811
+ describe('the journey: the project folder of a space', () => {
812
+ const made = async () => {
813
+ const first = journeyWith();
814
+ const { id } = await first.journey.createSpace(REQUEST);
815
+ await until(() => steps(first.events, id).includes('ready'));
816
+ await until(() => first.records.read(id).record?.history !== 'pending');
817
+ return { id, first };
818
+ };
819
+
820
+ it('names the folder the space was made for and whether it is there, while the project is registered and after it is gone', async () => {
821
+ const { id, first } = await made();
822
+ const asked = [];
823
+ // The record names the folder: a journey that no longer has the project still lists it.
824
+ const unregistered = createSpaceJourney({
825
+ manager: first.manager, place: first.place, gatekeeper: first.gatekeeper, codeIn: {}, codeOut: {}, records: first.records,
826
+ spaceOpenCode: {}, serverInside: {}, restartOpenCodeInside: async () => {},
827
+ listProjectDirectories: async () => [],
828
+ folderExists: async (directory) => { asked.push(directory); return false; },
829
+ logger: quiet,
830
+ });
831
+ expect((await unregistered.listSpaces())[0]).toMatchObject({ id, projectDirectory: null, directory: null, projectFolder: { path: PROJECT, found: false } });
832
+ expect(asked).toEqual([PROJECT]);
833
+ });
834
+
835
+ it('says the folder is there by looking at the host', async () => {
836
+ const folder = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-journey-project-'));
837
+ folders.push(folder);
838
+ const file = path.join(folder, 'a-file');
839
+ fs.writeFileSync(file, '');
840
+ const { first } = await made();
841
+ const look = (directory) => createSpaceJourney({
842
+ manager: first.manager, place: first.place, gatekeeper: first.gatekeeper, codeIn: {}, codeOut: {}, records: { read: () => ({ record: { repository: directory } }) },
843
+ spaceOpenCode: {}, serverInside: {}, restartOpenCodeInside: async () => {},
844
+ listProjectDirectories: async () => [],
845
+ logger: quiet,
846
+ }).listSpaces();
847
+ expect((await look(folder))[0].projectFolder).toEqual({ path: folder, found: true });
848
+ // A file where the folder was is not the folder, and neither is nothing.
849
+ expect((await look(file))[0].projectFolder).toEqual({ path: file, found: false });
850
+ expect((await look(path.join(folder, 'gone')))[0].projectFolder).toEqual({ path: path.join(folder, 'gone'), found: false });
851
+ });
852
+
853
+ it('lists a creation under way with its folder not looked at yet', async () => {
854
+ const { journey } = journeyWith({ holdCodeIn: true });
855
+ const { id } = await journey.createSpace(REQUEST);
856
+ expect((await journey.listSpaces()).find((space) => space.id === id)).toMatchObject({ projectFolder: { path: PROJECT, found: null } });
743
857
  });
744
858
  });
745
859
 
@@ -835,8 +949,9 @@ describe('the journey: idle stop', () => {
835
949
  expect(quietStops).toEqual([]);
836
950
 
837
951
  const held = await ready({ holdCodeOut: true });
838
- const heldStops = idleStopped(held.place);
952
+ // The preview takes the lock while the space still runs; the idle stop comes during it.
839
953
  const apply = held.journey.previewApply(held.id);
954
+ const heldStops = idleStopped(held.place);
840
955
  await held.journey.listSpaces();
841
956
  await sleep(20);
842
957
  expect(heldStops).toEqual([]);
@@ -915,7 +1030,7 @@ describe('the journey: setup commands', () => {
915
1030
  const mine = events.filter((event) => event.spaceId === id);
916
1031
  expect(mine.findIndex((event) => event.step === 'ready')).toBeLessThan(mine.findIndex((event) => event.step === undefined));
917
1032
  const listed = (await journey.listSpaces()).find((space) => space.id === id);
918
- expect(listed.setup).toEqual({ state: 'failed', index: 1, total: 3, command: 'npm ci', exitCode: 1, timedOut: false });
1033
+ expect(listed.setup).toEqual({ state: 'failed', index: 1, total: 3, command: 'npm ci', exitCode: 1, timedOut: false, startedAt: '2026-09-26T10:00:00.000Z', finishedAt: '2026-09-26T10:00:00.000Z' });
919
1034
  expect(await journey.readSetup(id)).toEqual({ setup: listed.setup, output: 'npm ERR! 403 Forbidden' });
920
1035
  expect(setupEvents(events, id).length).toBeGreaterThanOrEqual(2);
921
1036
  });
@@ -969,3 +1084,69 @@ describe('the journey: setup commands', () => {
969
1084
  expect((await second.journey.listSpaces()).find((space) => space.id === id).setup).toEqual({ state: 'interrupted', total: 2 });
970
1085
  });
971
1086
  });
1087
+
1088
+ describe('the journey: the chat archive of a deleted space', () => {
1089
+ // A stand-in archive that records what it was asked and the state of the space at that moment.
1090
+ const archiveWith = (place, answer) => {
1091
+ const asked = [];
1092
+ const archiveChats = async (request) => {
1093
+ asked.push({ ...request, stateThen: (await place.list()).find((space) => space.id === request.spaceId)?.state });
1094
+ if (answer instanceof Error) throw answer;
1095
+ return answer;
1096
+ };
1097
+ return { asked, archiveChats };
1098
+ };
1099
+ const ready = async (answer = { saved: 2, tooLarge: [], failed: 0, listed: true }) => {
1100
+ const place = createMemoryPlace();
1101
+ const archive = archiveWith(place, answer);
1102
+ const made = journeyWith({ place, archiveChats: archive.archiveChats });
1103
+ const { id } = await made.journey.createSpace(REQUEST);
1104
+ await until(() => steps(made.events, id).includes('ready'));
1105
+ await until(() => made.records.read(id).record?.history !== 'pending');
1106
+ made.calls.splice(0);
1107
+ return { ...made, ...archive, id };
1108
+ };
1109
+ const notSaved = () => new SpaceError('chats_not_saved', 'The chats of "Fix login" could not be saved.', { name: 'Fix login', tooLarge: ['Big one'], failed: 0, listed: true });
1110
+
1111
+ it('saves the chats of a running space before it goes, and says how many', async () => {
1112
+ const { journey, place, asked, calls, id } = await ready();
1113
+ const outcome = await journey.removeSpace(id);
1114
+ expect(asked).toEqual([{ spaceId: id, name: 'Fix login', projectDirectory: PROJECT, running: true, allowUnsaved: false, stateThen: 'running' }]);
1115
+ expect(outcome).toEqual({ id, removed: true, refsRemoved: true, failures: [], chats: { saved: 2, tooLarge: [], failed: 0, listed: true } });
1116
+ expect(calls.map(([name]) => name)).toEqual(['removeSpaceRefs']);
1117
+ expect(await place.list()).toEqual([]);
1118
+ });
1119
+
1120
+ it('starts a stopped space to take its chats', async () => {
1121
+ const { journey, asked, id } = await ready();
1122
+ await journey.stopSpace(id);
1123
+ await journey.removeSpace(id);
1124
+ expect(asked).toEqual([expect.objectContaining({ running: true, stateThen: 'running' })]);
1125
+ });
1126
+
1127
+ it('deletes nothing when the chats cannot all be saved, and deletes anyway when the user says so', async () => {
1128
+ const { journey, place, records, calls, asked, id } = await ready(notSaved());
1129
+ await expect(journey.removeSpace(id)).rejects.toMatchObject({ code: 'chats_not_saved', details: { tooLarge: ['Big one'] } });
1130
+ expect(await place.list()).toEqual([expect.objectContaining({ id })]);
1131
+ expect(records.read(id).status).toBe('ok');
1132
+ expect(calls).toEqual([]);
1133
+ await expect(journey.removeSpace(id, { allowUnsaved: true })).rejects.toMatchObject({ code: 'chats_not_saved' });
1134
+ expect(asked.map((request) => request.allowUnsaved)).toEqual([false, true]);
1135
+ });
1136
+
1137
+ it('stops a stopped space again when it was started for its chats and they could not be saved', async () => {
1138
+ const { journey, place, id } = await ready(notSaved());
1139
+ await journey.stopSpace(id);
1140
+ await expect(journey.removeSpace(id)).rejects.toMatchObject({ code: 'chats_not_saved' });
1141
+ expect((await place.list()).find((space) => space.id === id)?.state).toBe('exited');
1142
+ });
1143
+
1144
+ it('keeps a space asked to go after an apply when its chats cannot be saved, with the work applied', async () => {
1145
+ const { journey, place, id } = await ready(notSaved());
1146
+ const outcome = await journey.applySpace(id, { as: 'branch', branch: 'space/fix-login', removeAfterwards: true });
1147
+ expect(outcome.applied).toMatchObject({ status: 'applied', branch: 'space/fix-login' });
1148
+ expect(outcome.removal).toBeNull();
1149
+ expect(outcome.kept).toMatchObject({ code: 'chats_not_saved' });
1150
+ expect(await place.list()).toEqual([expect.objectContaining({ id })]);
1151
+ });
1152
+ });
@@ -0,0 +1,151 @@
1
+ // The disk that spaces take on the Docker place, and the clean-up of what OpenChamber can make
2
+ // again by itself (DESIGN.md, journey step 9 and decision 12): this owner's tools volumes but the
3
+ // current one, this owner's leftover one-shot containers, and the space image.
4
+ //
5
+ // Nothing here decides whether a resource is still needed. Every removal goes without force, and
6
+ // Docker refuses a volume a container mounts, an image a container was made from, and a running
7
+ // container. That refusal is the guard: whatever it keeps is in use, and stays.
8
+
9
+ import { SpaceError } from '../errors.js';
10
+ import { labelFilterArgs, parseSpaceLabels, ROLE_VOLUME } from '../labels.js';
11
+
12
+ const QUERY_TIMEOUT_MS = 60_000;
13
+ // `fstrim` inside the Colima machine took about a second on a 40 GiB disk.
14
+ const TRIM_TIMEOUT_MS = 120_000;
15
+ // Docker prints sizes with decimal units: `units.HumanSizeWithPrecision`, three digits.
16
+ const SIZE_UNITS = { B: 1, kB: 1e3, KB: 1e3, MB: 1e6, GB: 1e9, TB: 1e12, PB: 1e15 };
17
+ // A removal Docker refused because something uses the resource, as the engine words it.
18
+ const IN_USE = /\bis in use\b|\bbeing used by\b|\bmust be forced\b|\bcontainer is running\b/i;
19
+ // Colima names its Docker machine `colima`, or `colima-<profile>` for another profile.
20
+ const COLIMA_MACHINE = /^colima(?:-([A-Za-z0-9._-]+))?$/;
21
+
22
+ /** Bytes from a size as `docker system df` prints it; anything else, `N/A` among it, counts as 0. */
23
+ export const parseDockerSize = (text) => {
24
+ const match = /^(\d+(?:\.\d+)?)\s*(B|kB|KB|MB|GB|TB|PB)$/.exec(String(text ?? '').trim());
25
+ return match ? Math.round(Number(match[1]) * SIZE_UNITS[match[2]]) : 0;
26
+ };
27
+
28
+ const parseJson = (text) => {
29
+ try {
30
+ return JSON.parse(text);
31
+ } catch {
32
+ throw new SpaceError('docker_output_unreadable', 'Docker printed something that is not JSON');
33
+ }
34
+ };
35
+
36
+ /**
37
+ * `engine` is the place's docker CLI, `tools` its tools volume with `listOurs`, `image` the pinned
38
+ * space image. `colimaPath` is the colima CLI, or null: after a clean-up that removed anything, a
39
+ * Docker machine that calls itself Colima is asked to hand the freed blocks back to the Mac.
40
+ */
41
+ export function createDockerDisk({ engine, runCommand, colimaPath, owner, image, tools }) {
42
+ /**
43
+ * Docker's own account of the disk: every volume with its size and how many containers mount it,
44
+ * by name, and what each image alone takes, by id. `docker image inspect` is no use for the
45
+ * size: with the containerd image store it reports the compressed download, 400 MB for an image
46
+ * that takes 1.63 GB unpacked.
47
+ */
48
+ const readUsage = async () => {
49
+ const usage = parseJson(await engine.docker(['system', 'df', '--verbose', '--format', '{{json .}}'], QUERY_TIMEOUT_MS)) ?? {};
50
+ return {
51
+ volumes: new Map((usage.Volumes ?? []).map((volume) => [String(volume.Name), { bytes: parseDockerSize(volume.Size), links: Number.parseInt(volume.Links, 10) || 0 }])),
52
+ images: new Map((usage.Images ?? []).map((entry) => [String(entry.ID), parseDockerSize(entry.UniqueSize)])),
53
+ };
54
+ };
55
+
56
+ /** This owner's space volumes, found by label and checked again on the inspect result. */
57
+ const spaceVolumes = async () => (await engine.findByLabel('volume', labelFilterArgs({ owner })))
58
+ .filter((entry) => {
59
+ const labels = parseSpaceLabels(entry.Labels);
60
+ return labels?.owner === owner && labels.role === ROLE_VOLUME;
61
+ })
62
+ .map((entry) => String(entry.Name));
63
+
64
+ /**
65
+ * The image with what it alone takes, or null when it is not there. In use when any container
66
+ * was made from it.
67
+ */
68
+ const readImage = async (images) => {
69
+ const entry = await engine.inspect('image', image);
70
+ if (!entry) return null;
71
+ const users = await engine.docker(['ps', '--all', '--filter', `ancestor=${image}`, '--format', '{{.Names}}'], QUERY_TIMEOUT_MS);
72
+ return { bytes: images.get(String(entry.Id)) ?? 0, inUse: users.trim() !== '' };
73
+ };
74
+
75
+ const measure = async () => {
76
+ const [usage, ours, spaces] = await Promise.all([readUsage(), tools.listOurs(), spaceVolumes()]);
77
+ const { volumes } = usage;
78
+ const sizeOf = (name) => volumes.get(name)?.bytes ?? 0;
79
+ const oldTools = ours.volumes.filter((name) => name !== ours.current);
80
+ return { volumes, ours, oldTools, spaces, image: await readImage(usage.images), sizeOf };
81
+ };
82
+
83
+ /**
84
+ * What the page shows: the image, the tools and the spaces' own volumes in bytes, and what a
85
+ * clean-up would free now. `freesImage` says whether the image is part of that.
86
+ */
87
+ const read = async () => {
88
+ const { volumes, ours, oldTools, spaces, image: imageState, sizeOf } = await measure();
89
+ const freeTools = oldTools.filter((name) => (volumes.get(name)?.links ?? 0) === 0);
90
+ const freesImage = imageState !== null && !imageState.inUse;
91
+ const sum = (names) => names.reduce((total, name) => total + sizeOf(name), 0);
92
+ return {
93
+ imageBytes: imageState?.bytes ?? null,
94
+ toolsBytes: sum(ours.volumes),
95
+ spacesBytes: sum(spaces),
96
+ freeBytes: sum(freeTools) + (freesImage ? imageState.bytes : 0),
97
+ freesImage,
98
+ };
99
+ };
100
+
101
+ /**
102
+ * Asks Colima to trim its machine's disks, which is what gives freed space back to the Mac.
103
+ * Never fails the clean-up: any other engine, a missing CLI, a stopped machine or a `sudo` that
104
+ * wants a password ends here with the reason, for the log.
105
+ */
106
+ const trimMachine = async () => {
107
+ if (!colimaPath) return { state: 'skipped' };
108
+ try {
109
+ const info = await engine.run(['info', '--format', '{{json .Name}}'], QUERY_TIMEOUT_MS);
110
+ const match = info.code === 0 ? COLIMA_MACHINE.exec(String(parseJson(info.stdout))) : null;
111
+ if (!match) return { state: 'skipped' };
112
+ const result = await runCommand(colimaPath, ['ssh', '--profile', match[1] ?? 'default', '--', 'sudo', '-n', 'fstrim', '--all'], { timeoutMs: TRIM_TIMEOUT_MS });
113
+ return result.code === 0 ? { state: 'trimmed' } : { state: 'failed', message: result.stderr.trim().slice(-500) || `exit code ${result.code}` };
114
+ } catch (error) {
115
+ return { state: 'failed', message: error?.message ?? String(error) };
116
+ }
117
+ };
118
+
119
+ /**
120
+ * Removes what OpenChamber can make again, each without force, and says what Docker kept.
121
+ * `freedBytes` counts the sizes measured just before, of what is gone afterwards.
122
+ */
123
+ const cleanUp = async () => {
124
+ const { oldTools, ours, image: imageState, sizeOf } = await measure();
125
+ let freedBytes = 0;
126
+ const kept = [];
127
+ const attempt = async (kind, name, bytes, removal) => {
128
+ const problem = await removal;
129
+ if (!problem) {
130
+ freedBytes += bytes;
131
+ return true;
132
+ }
133
+ kept.push({ kind, name, reason: IN_USE.test(problem.message) ? 'in_use' : 'failed', message: problem.message });
134
+ return false;
135
+ };
136
+ let removedAny = false;
137
+ // Containers first: a one-shot left behind can hold a tools volume.
138
+ for (const name of ours.oneShots) {
139
+ removedAny = (await attempt('container', name, 0, engine.removeStoppedContainer(name))) || removedAny;
140
+ }
141
+ for (const name of oldTools) {
142
+ removedAny = (await attempt('tools', name, sizeOf(name), engine.removeOne('volume', name))) || removedAny;
143
+ }
144
+ if (imageState) {
145
+ removedAny = (await attempt('image', image, imageState.bytes, engine.removeOne('image', image))) || removedAny;
146
+ }
147
+ return { freedBytes, kept, machine: removedAny ? await trimMachine() : { state: 'skipped' } };
148
+ };
149
+
150
+ return { read, cleanUp };
151
+ }
@@ -0,0 +1,167 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { buildSpaceLabels, buildToolsLabels, hashProjectDirectory } from '../labels.js';
4
+ import { createRegistryToolsSource, toolsContentKey } from '../tools.js';
5
+ import { parseDockerSize } from './docker-disk.js';
6
+ import { SPACE_BASE_IMAGE, createDockerPlace } from './docker.js';
7
+ import { createFakeDocker, hardenedContainerEntry } from './fake-docker.js';
8
+
9
+ const OWNER = 'install-a';
10
+ const STRANGER = 'install-b';
11
+ const SOURCE = createRegistryToolsSource({ webVersion: '1.24.2', openCodeVersion: '1.18.31' });
12
+ const KEY = toolsContentKey(SOURCE, SPACE_BASE_IMAGE);
13
+ const OLD_KEY = '0123456789abcdef';
14
+ const OLDER_KEY = 'fedcba9876543210';
15
+ const NOW = new Date('2026-09-30T08:00:00.000Z');
16
+ const ID = 'a1b2c3d4e5f6';
17
+
18
+ const toolsName = (owner, key) => `openchamber-tools-${owner}-${key}`;
19
+ const toolsVolume = (owner, key) => ({
20
+ kind: 'volume',
21
+ name: toolsName(owner, key),
22
+ entry: { Name: toolsName(owner, key), Labels: buildToolsLabels({ role: 'tools', owner, key, description: 'web 1.24.2', created: NOW.toISOString() }) },
23
+ filled: true,
24
+ });
25
+ const oneShot = (key, { running }) => {
26
+ const name = `${toolsName(OWNER, key)}-fill`;
27
+ const labels = buildToolsLabels({ role: 'tools-fill', owner: OWNER, key, description: 'web 1.24.2', created: NOW.toISOString() });
28
+ return { kind: 'container', name, entry: hardenedContainerEntry({ name, labels, network: 'bridge', mounts: [], running }) };
29
+ };
30
+ const spaceLabels = (role) => buildSpaceLabels({ id: ID, role, owner: OWNER, project: hashProjectDirectory('/home/me/project'), name: 'Fix it', created: NOW.toISOString() });
31
+ /** A stopped space of ours on the tools of `key`, with its two volumes. */
32
+ const stoppedSpace = (key) => {
33
+ const name = `openchamber-space-${ID}-space`;
34
+ const work = `openchamber-space-${ID}-volume-work`;
35
+ const home = `openchamber-space-${ID}-volume-home`;
36
+ return [
37
+ { kind: 'container', name, entry: hardenedContainerEntry({ name, labels: spaceLabels('space'), network: `openchamber-space-${ID}-network`, running: false, mounts: [{ volume: work, destination: `/spaces/${ID}` }, { volume: home, destination: '/home/space' }, { volume: toolsName(OWNER, key), destination: '/opt/openchamber-tools', readOnly: true }] }) },
38
+ { kind: 'volume', name: work, entry: { Name: work, Labels: spaceLabels('volume') } },
39
+ { kind: 'volume', name: home, entry: { Name: home, Labels: spaceLabels('volume') } },
40
+ ];
41
+ };
42
+ const strangerContainer = (image) => ({ kind: 'container', name: 'their-app', entry: hardenedContainerEntry({ name: 'their-app', labels: {}, network: 'bridge', mounts: [{ volume: 'their-data', destination: '/data' }], running: false, image }) });
43
+ const strangerVolume = { kind: 'volume', name: 'their-data', entry: { Name: 'their-data', Labels: {} } };
44
+
45
+ const SIZES = {
46
+ [toolsName(OWNER, KEY)]: '438MB',
47
+ [toolsName(OWNER, OLD_KEY)]: '440MB',
48
+ [toolsName(OWNER, OLDER_KEY)]: '441MB',
49
+ [toolsName(STRANGER, OLD_KEY)]: '439MB',
50
+ [`openchamber-space-${ID}-volume-work`]: '1.2GB',
51
+ [`openchamber-space-${ID}-volume-home`]: '300MB',
52
+ 'their-data': '5GB',
53
+ };
54
+
55
+ const makePlace = (fake, options = {}) => createDockerPlace({ runCommand: fake.runCommand, dockerPath: '/usr/bin/docker', owner: OWNER, toolsSource: SOURCE, wait: fake.wait, now: fake.now, ...options });
56
+ const removals = (fake) => fake.calls.map((call) => call.args).filter((args) => args[0] === 'rm' || args[1] === 'rm');
57
+
58
+ describe('parseDockerSize', () => {
59
+ it('reads the decimal units docker system df prints, and counts anything else as nothing', () => {
60
+ expect(parseDockerSize('438MB')).toBe(438_000_000);
61
+ expect(parseDockerSize('1.632GB')).toBe(1_632_000_000);
62
+ expect(parseDockerSize('4.1kB')).toBe(4_100);
63
+ expect(parseDockerSize('0B')).toBe(0);
64
+ expect(parseDockerSize('N/A')).toBe(0);
65
+ expect(parseDockerSize(undefined)).toBe(0);
66
+ });
67
+ });
68
+
69
+ describe('the disk of the Docker place', () => {
70
+ it('counts this owner\'s image, tools and space volumes, and frees only what nothing uses', async () => {
71
+ const fake = createFakeDocker({
72
+ volumeSizes: SIZES,
73
+ resources: [toolsVolume(OWNER, KEY), toolsVolume(OWNER, OLD_KEY), toolsVolume(OWNER, OLDER_KEY), toolsVolume(STRANGER, OLD_KEY), ...stoppedSpace(OLDER_KEY), strangerVolume],
74
+ });
75
+ expect(await makePlace(fake).readDisk()).toEqual({
76
+ imageBytes: 1_632_000_000,
77
+ toolsBytes: 438_000_000 + 440_000_000 + 441_000_000,
78
+ spacesBytes: 1_500_000_000,
79
+ // The old tools nothing mounts; the image and the tools the stopped space holds are in use.
80
+ freeBytes: 440_000_000,
81
+ freesImage: false,
82
+ });
83
+ });
84
+
85
+ it('frees the image when no container at all was made from it, and says nothing when it is not there', async () => {
86
+ const fake = createFakeDocker({ volumeSizes: SIZES, resources: [toolsVolume(OWNER, KEY)] });
87
+ expect(await makePlace(fake).readDisk()).toMatchObject({ imageBytes: 1_632_000_000, freeBytes: 1_632_000_000, freesImage: true });
88
+ const without = createFakeDocker({ imagePresent: false, resources: [toolsVolume(OWNER, KEY)] });
89
+ expect(await makePlace(without).readDisk()).toMatchObject({ imageBytes: null, freeBytes: 0, freesImage: false });
90
+ });
91
+
92
+ it('a failed read rejects rather than answering an empty disk', async () => {
93
+ const fake = createFakeDocker({ failAt: (args) => args[0] === 'system' });
94
+ await expect(makePlace(fake).readDisk()).rejects.toMatchObject({ code: 'docker_command_failed' });
95
+ });
96
+ });
97
+
98
+ describe('clean-up of the Docker place', () => {
99
+ it('removes this owner\'s unused old tools, stopped one-shots and the unused image, without force', async () => {
100
+ const fake = createFakeDocker({
101
+ volumeSizes: SIZES,
102
+ resources: [toolsVolume(OWNER, KEY), toolsVolume(OWNER, OLD_KEY), oneShot(OLD_KEY, { running: false })],
103
+ });
104
+ const outcome = await makePlace(fake).cleanUpDisk();
105
+ expect(outcome).toEqual({ freedBytes: 440_000_000 + 1_632_000_000, kept: [], machine: { state: 'skipped' } });
106
+ expect(fake.names()).toEqual([`volume:${toolsName(OWNER, KEY)}`]);
107
+ expect(fake.imagePresent()).toBe(false);
108
+ expect(removals(fake).some((args) => args.includes('--force'))).toBe(false);
109
+ });
110
+
111
+ it('never touches the current tools, another owner\'s tools, a stranger\'s volume, or anything in use', async () => {
112
+ const fake = createFakeDocker({
113
+ volumeSizes: SIZES,
114
+ resources: [
115
+ toolsVolume(OWNER, KEY),
116
+ toolsVolume(OWNER, OLDER_KEY),
117
+ toolsVolume(STRANGER, OLD_KEY),
118
+ ...stoppedSpace(OLDER_KEY),
119
+ oneShot(OLD_KEY, { running: true }),
120
+ strangerVolume,
121
+ strangerContainer('postgres:17'),
122
+ ],
123
+ });
124
+ const before = fake.names();
125
+ const outcome = await makePlace(fake).cleanUpDisk();
126
+ // Docker refused each one: the stopped space holds its tools and the image, and a fill is running.
127
+ expect(outcome.freedBytes).toBe(0);
128
+ expect(outcome.kept).toEqual([
129
+ expect.objectContaining({ kind: 'container', name: `${toolsName(OWNER, OLD_KEY)}-fill`, reason: 'in_use' }),
130
+ expect.objectContaining({ kind: 'tools', name: toolsName(OWNER, OLDER_KEY), reason: 'in_use' }),
131
+ expect.objectContaining({ kind: 'image', name: SPACE_BASE_IMAGE, reason: 'in_use' }),
132
+ ]);
133
+ expect(fake.names()).toEqual(before);
134
+ expect(fake.imagePresent()).toBe(true);
135
+ // Only our own resources and the one pinned image were ever asked to go.
136
+ expect(removals(fake).map((args) => args[args.length - 1])).toEqual([`${toolsName(OWNER, OLD_KEY)}-fill`, toolsName(OWNER, OLDER_KEY), SPACE_BASE_IMAGE]);
137
+ });
138
+
139
+ it('keeps the image while a stranger\'s container was made from it', async () => {
140
+ const fake = createFakeDocker({ resources: [toolsVolume(OWNER, KEY), strangerContainer(SPACE_BASE_IMAGE)] });
141
+ expect((await makePlace(fake).cleanUpDisk()).kept).toEqual([expect.objectContaining({ kind: 'image', reason: 'in_use' })]);
142
+ expect(fake.imagePresent()).toBe(true);
143
+ });
144
+
145
+ it('on Colima asks the machine to trim its disks after something went, and on any other engine does not', async () => {
146
+ const colimaCalls = [];
147
+ const fake = createFakeDocker({
148
+ engineName: 'colima-work',
149
+ resources: [toolsVolume(OWNER, KEY)],
150
+ colima: (args) => { colimaCalls.push(args); return { code: 0, stdout: '', stderr: '' }; },
151
+ });
152
+ expect((await makePlace(fake, { colimaPath: '/opt/homebrew/bin/colima' }).cleanUpDisk()).machine).toEqual({ state: 'trimmed' });
153
+ expect(colimaCalls).toEqual([['ssh', '--profile', 'work', '--', 'sudo', '-n', 'fstrim', '--all']]);
154
+
155
+ const desktop = createFakeDocker({ resources: [toolsVolume(OWNER, KEY)], colima: () => { throw new Error('must not run'); } });
156
+ expect((await makePlace(desktop, { colimaPath: '/opt/homebrew/bin/colima' }).cleanUpDisk()).machine).toEqual({ state: 'skipped' });
157
+ });
158
+
159
+ it('a trim that fails or finds nothing to do never fails the clean-up', async () => {
160
+ const fake = createFakeDocker({ engineName: 'colima', resources: [toolsVolume(OWNER, KEY)], colima: () => ({ code: 1, stdout: '', stderr: 'sudo: a password is required' }) });
161
+ const outcome = await makePlace(fake, { colimaPath: '/opt/homebrew/bin/colima' }).cleanUpDisk();
162
+ expect(outcome).toMatchObject({ freedBytes: 1_632_000_000, machine: { state: 'failed', message: 'sudo: a password is required' } });
163
+
164
+ const idle = createFakeDocker({ engineName: 'colima', imagePresent: false, resources: [toolsVolume(OWNER, KEY)], colima: () => { throw new Error('must not run'); } });
165
+ expect((await makePlace(idle, { colimaPath: '/opt/homebrew/bin/colima' }).cleanUpDisk()).machine).toEqual({ state: 'skipped' });
166
+ });
167
+ });
@@ -182,5 +182,15 @@ export function createDockerTools({ engine, owner, toolsSource, image, now, wait
182
182
  }
183
183
  };
184
184
 
185
- return { ensure, prune, removeIfUnlabelled };
185
+ /**
186
+ * This owner's tools resources, found by label and checked again on the inspect result, for the
187
+ * disk page: the volume of the current tools, the other volumes, and the one-shot containers.
188
+ */
189
+ const listOurs = async () => ({
190
+ current: volume,
191
+ volumes: await findOurs('volume', { role: ROLE_TOOLS }),
192
+ oneShots: [...(await findOurs('container', { role: ROLE_TOOLS_FILL })), ...(await findOurs('container', { role: ROLE_TOOLS_CHECK }))],
193
+ });
194
+
195
+ return { ensure, prune, removeIfUnlabelled, listOurs };
186
196
  }
@@ -31,6 +31,7 @@ import { SPACE_CONNECT_COMMAND, SPACE_IDLE_EXIT_CODE, SPACE_USER, TOOLS_MOUNT_PA
31
31
  import { openCommandStream as openCommandStreamProcess } from '../run-command.js';
32
32
  import { createSpaceServerChannel, createSpaceToken } from '../space-server.js';
33
33
  import { CHANGE_TIMEOUT_MS, ROLLBACK_SETTLE_MS, createDockerEngine, entryLabels, entryName, isInterrupted, pause } from './docker-engine.js';
34
+ import { createDockerDisk } from './docker-disk.js';
34
35
  import { createDockerTools } from './docker-tools.js';
35
36
 
36
37
  const DOCKER_PLACE_ID = 'docker';
@@ -60,12 +61,13 @@ function execRole(target) {
60
61
  throw new SpaceError('invalid_exec_target', `A command runs in the space or in its gatekeeper, not in '${target}'`);
61
62
  }
62
63
 
63
- export function createDockerPlace({ runCommand, openCommandStream = openCommandStreamProcess, dockerPath, owner, toolsSource, wait = pause, now = () => new Date() }) {
64
+ export function createDockerPlace({ runCommand, openCommandStream = openCommandStreamProcess, dockerPath, colimaPath = null, owner, toolsSource, wait = pause, now = () => new Date() }) {
64
65
  requireOwner(owner);
65
66
 
66
67
  const engine = createDockerEngine({ runCommand, dockerPath });
67
68
  const { run, docker, inspect, removeOne, removeStoppedContainer } = engine;
68
69
  const tools = createDockerTools({ engine, owner, toolsSource, image: SPACE_BASE_IMAGE, now, wait });
70
+ const disk = createDockerDisk({ engine, runCommand, colimaPath, owner, image: SPACE_BASE_IMAGE, tools });
69
71
 
70
72
  /** Every resource that carries our marker and this owner, optionally for one space. Found by label only. */
71
73
  const findResources = async (spaceId) => {
@@ -622,5 +624,5 @@ export function createDockerPlace({ runCommand, openCommandStream = openCommandS
622
624
  return starting.get(spaceId);
623
625
  };
624
626
 
625
- return { id: DOCKER_PLACE_ID, check, create, list, exec, execArgv, connect, stop, start, remove, verify };
627
+ return { id: DOCKER_PLACE_ID, check, create, list, exec, execArgv, connect, stop, start, remove, verify, readDisk: disk.read, cleanUpDisk: disk.cleanUp };
626
628
  }