@openchamber/web 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/dist/assets/AboutDialog-C1ulAXh5.js +1 -0
  2. package/dist/assets/ArchiveView-DJo1Bpw_.js +1 -0
  3. package/dist/assets/{CommandPalette-1VlA7PbL.js → CommandPalette-B6r6DPF9.js} +2 -2
  4. package/dist/assets/{DiffView-SHdJJ6tl.js → DiffView-mJuVm7Z4.js} +2 -2
  5. package/dist/assets/{FilePreviewCommentMenu-DlVgwRsr.js → FilePreviewCommentMenu-Ca4ziuof.js} +1 -1
  6. package/dist/assets/{FilesView-BeMtsSlV.js → FilesView-BBFbfDp9.js} +3 -3
  7. package/dist/assets/{GitView-npRGKKx8.js → GitView-WL1wkRFF.js} +3 -3
  8. package/dist/assets/GuestSurfacePane-peVDY5gW.js +1 -0
  9. package/dist/assets/HelpDialog-Dxc2yneu.js +1 -0
  10. package/dist/assets/{InProgressOperationBanner-B6iO22_7.js → InProgressOperationBanner-Dy0RiPsD.js} +1 -1
  11. package/dist/assets/JsonTreeView-BKUmh7Iw.js +1 -0
  12. package/dist/assets/MarkdownImageGallery-Cd6hLNmi.js +1 -0
  13. package/dist/assets/MarkdownRendererImpl-C-3B3mBt.js +1 -0
  14. package/dist/assets/MemoryDebugPanel-b116r1SF.js +1 -0
  15. package/dist/assets/OnboardingScreen-vBEhpU3q.js +1 -0
  16. package/dist/assets/OpenCodeStatusDialog-DH7dJ6MH.js +1 -0
  17. package/dist/assets/{PatchDiff-Du2s7T3U.js → PatchDiff-yM7vgQgi.js} +1 -1
  18. package/dist/assets/{PierreDiffViewer-B9K0gBvV.js → PierreDiffViewer-DnHKbYGl.js} +1 -1
  19. package/dist/assets/{PlanView-IkTcPrbw.js → PlanView-j0hLJmto.js} +2 -2
  20. package/dist/assets/RunOverview-ZuFZvDcu.js +2 -0
  21. package/dist/assets/ScheduledTasksDialog-UKXFFI91.js +5 -0
  22. package/dist/assets/{SettingsView-DIy5ZL4-.js → SettingsView-gB_NvyX4.js} +8 -8
  23. package/dist/assets/SettingsWindow-Dfb_RFpD.js +1 -0
  24. package/dist/assets/SourceBoardView-BjaL0nKs.js +1 -0
  25. package/dist/assets/SpaceAccessDialog-XzHRmIdT.js +1 -0
  26. package/dist/assets/SpaceApplyDialog-CxX9mrzT.js +1 -0
  27. package/dist/assets/{SpaceRow-YPmKQKeD.js → SpaceRow-vCpOCANO.js} +1 -1
  28. package/dist/assets/SpaceSetupOutput-CDZvJCf_.js +1 -0
  29. package/dist/assets/SpacesView-D3a9bCzn.js +1 -0
  30. package/dist/assets/{SubmoduleDiffSummary-RDY5md3p.js → SubmoduleDiffSummary-CQyRcvDZ.js} +1 -1
  31. package/dist/assets/{ToolOutputDialog-Dx85XZJs.js → ToolOutputDialog-judR_5mS.js} +2 -2
  32. package/dist/assets/{ToolPartDiffPreview-Dtv0xF9O.js → ToolPartDiffPreview-Ca9ISxfg.js} +1 -1
  33. package/dist/assets/UsageStatsView-C63Emjfj.js +1 -0
  34. package/dist/assets/{Virtualizer-DL535kyR.js → Virtualizer-DNgIEKcx.js} +1 -1
  35. package/dist/assets/{WalkthroughView-DcxbT5tc.js → WalkthroughView-D74b_7sC.js} +2 -2
  36. package/dist/assets/WorktreesView-hcm8Eb_C.js +1 -0
  37. package/dist/assets/appThemeRegistry-COeayQaQ.js +1 -0
  38. package/dist/assets/{ar-lP51qqz9.js → ar-1_zdYVV5.js} +2 -2
  39. package/dist/assets/computeVirtualFileMetrics-MZqvCQy0.js +3 -0
  40. package/dist/assets/{de-CpROAvTV.js → de-Ci7SGEQP.js} +3 -3
  41. package/dist/assets/{decorate-BNB7jeKg.js → decorate-CZeRRVC7.js} +1 -1
  42. package/dist/assets/{es-Bb8LKRhE.js → es-ZJii-6Tt.js} +2 -2
  43. package/dist/assets/{fr-BlNN9FC2.js → fr-C-hK8mvI.js} +2 -2
  44. package/dist/assets/{he-r546pCuc.js → he-t07CylP8.js} +2 -2
  45. package/dist/assets/index-D2tPUss-.js +1 -0
  46. package/dist/assets/{initializeSharedPreferences-dCHO04bl.js → initializeSharedPreferences-FxFkTjgn.js} +1 -1
  47. package/dist/assets/{isDiffPlainText-BwicHPpI.js → isDiffPlainText-C1F9opE5.js} +1 -1
  48. package/dist/assets/{isFilePlainText-Dk2R7BJo.js → isFilePlainText-B4SyJ-ni.js} +1 -1
  49. package/dist/assets/{ja-evNvJAHz.js → ja-iJr8aONy.js} +2 -2
  50. package/dist/assets/{katex-CMY-1eWf.css → katex-BEX7X_K8.css} +1 -1
  51. package/dist/assets/{katex.min-Iw9WSgM9.js → katex.min-C-51hS9A.js} +18 -18
  52. package/dist/assets/{ko-BPQP7lXe.js → ko-D5ow_yz-.js} +2 -2
  53. package/dist/assets/main-BtGnuno4.js +1048 -0
  54. package/dist/assets/main-uj5954n5.js +2 -0
  55. package/dist/assets/markdownCore-rBXCnAJp.js +9 -0
  56. package/dist/assets/miniChat-yWQmT2OS.js +2 -0
  57. package/dist/assets/mobile-NDAeGtzL.js +2 -0
  58. package/dist/assets/{moveWorkspacePath-B31RGdgu.js → moveWorkspacePath-BINgpJ9S.js} +1 -1
  59. package/dist/assets/{nl-CkQXd1nU.js → nl-CfqYrSVe.js} +2 -2
  60. package/dist/assets/{parseDiffFromFile-DcsKSY0J.js → parseDiffFromFile--DE4eHIp.js} +2 -2
  61. package/dist/assets/{patchFileDiff-Cx-HpjyI.js → patchFileDiff-BfFUmWgS.js} +1 -1
  62. package/dist/assets/pierreDiffTint-D9K6_CVD.js +29 -0
  63. package/dist/assets/{pl-C4i9Aizi.js → pl-Bn2_jAhL.js} +4 -4
  64. package/dist/assets/{pt-BR-CoYnG1CH.js → pt-BR-ZSDgn6cI.js} +2 -2
  65. package/dist/assets/relocateRestoredSession-C85Tk2y9.js +1 -0
  66. package/dist/assets/renderElectronMiniChatApp-BvAEmWhZ.js +2 -0
  67. package/dist/assets/{renderMobileApp-gDKxRJQi.js → renderMobileApp-T20l8ise.js} +7 -7
  68. package/dist/assets/{restartOpenCode-dq-SGun3.js → restartOpenCode-VEmIrLer.js} +1 -1
  69. package/dist/assets/runtimeEndpointReset-ExJsaWzA.js +55 -0
  70. package/dist/assets/scheduledTasksApi-NSyxVfHu.js +1 -0
  71. package/dist/assets/{selectionMarkdown-sDTBbKLh.js → selectionMarkdown-BJ2RhTXc.js} +2 -2
  72. package/dist/assets/{sessionOwnership-kZAtwMQd.js → sessionOwnership-BAX1xEJC.js} +1 -1
  73. package/dist/assets/{shikiHighlight-BRNXPlF-.js → shikiHighlight-DOzrE7BE.js} +1 -1
  74. package/dist/assets/{space-apply-CCOKLfrX.js → space-apply-DB_ZfJBW.js} +1 -1
  75. package/dist/assets/space-close-1kNlTkW1.js +1 -0
  76. package/dist/assets/{spaceNetwork-DUxJClu3.js → spaceNetwork-DA16ov_y.js} +1 -1
  77. package/dist/assets/{textMateThemeFromAppTheme-B6UJwdZz.js → textMateThemeFromAppTheme-BfIrjFAU.js} +1 -1
  78. package/dist/assets/{tr-D-_lz-lC.js → tr-C89uz1hs.js} +2 -2
  79. package/dist/assets/{uk-B49PGMYB.js → uk-uTYVPFrO.js} +2 -2
  80. package/dist/assets/{useAppFontEffects-3EN8Ava3.js → useAppFontEffects-C1ceAD51.js} +185 -185
  81. package/dist/assets/useCallableModelProviders-BkLsgs6y.js +1 -0
  82. package/dist/assets/{useInlineCommentController-l9cWyfuR.js → useInlineCommentController-ynkUsoVA.js} +1 -1
  83. package/dist/assets/{useRootScrollLock-UAQn24Y8.js → useRootScrollLock-DnoKH1HE.js} +2 -2
  84. package/dist/assets/{vendor-codemirror-autocomplete-C8FBSI9t.js → vendor-codemirror-autocomplete-BRKmCSiY.js} +1 -1
  85. package/dist/assets/{vendor-codemirror-commands-BhRb6jns.js → vendor-codemirror-commands-MmBpgSOc.js} +1 -1
  86. package/dist/assets/vendor-codemirror-lang-angular-Bj5Pk8sp.js +1 -0
  87. package/dist/assets/vendor-codemirror-lang-cpp-tZt-BOgi.js +1 -0
  88. package/dist/assets/vendor-codemirror-lang-css-DfdrZ848.js +1 -0
  89. package/dist/assets/{vendor-codemirror-lang-go-BHJEONih.js → vendor-codemirror-lang-go-C9OcoXdP.js} +2 -2
  90. package/dist/assets/vendor-codemirror-lang-html-C5kFuJzc.js +1 -0
  91. package/dist/assets/vendor-codemirror-lang-java-Divn2dnj.js +1 -0
  92. package/dist/assets/{vendor-codemirror-lang-javascript-CUmSxayT.js → vendor-codemirror-lang-javascript-DmPuKUEa.js} +2 -2
  93. package/dist/assets/vendor-codemirror-lang-jinja-B-8miA-Q.js +1 -0
  94. package/dist/assets/vendor-codemirror-lang-json-L0wsFFxi.js +1 -0
  95. package/dist/assets/vendor-codemirror-lang-less-CWlCIxCI.js +1 -0
  96. package/dist/assets/vendor-codemirror-lang-liquid-Dm8xthAW.js +1 -0
  97. package/dist/assets/vendor-codemirror-lang-markdown-CPn-qinN.js +1 -0
  98. package/dist/assets/vendor-codemirror-lang-php-DKIOifjN.js +1 -0
  99. package/dist/assets/vendor-codemirror-lang-python-BAVa3Hg5.js +3 -0
  100. package/dist/assets/vendor-codemirror-lang-rust-Dab90hdg.js +1 -0
  101. package/dist/assets/vendor-codemirror-lang-sass-eezaHFBZ.js +1 -0
  102. package/dist/assets/{vendor-codemirror-lang-sql-C1Jj9uuJ.js → vendor-codemirror-lang-sql-Vu-PR7cv.js} +2 -2
  103. package/dist/assets/vendor-codemirror-lang-vue-BthRGZHy.js +1 -0
  104. package/dist/assets/vendor-codemirror-lang-wast-Db6KSic0.js +1 -0
  105. package/dist/assets/vendor-codemirror-lang-xml-DQkh4sc1.js +1 -0
  106. package/dist/assets/vendor-codemirror-lang-yaml-Bt2N__AW.js +1 -0
  107. package/dist/assets/vendor-codemirror-language-DkBxRck3.js +3 -0
  108. package/dist/assets/vendor-codemirror-language-data-CTYHXywt.js +2 -0
  109. package/dist/assets/{vendor-codemirror-search-CvXM_pZg.js → vendor-codemirror-search-BKAwkhkm.js} +1 -1
  110. package/dist/assets/vendor-codemirror-streamparser-CmlTsbN2.js +1 -0
  111. package/dist/assets/vendor-codemirror-view-B66jUSmE.js +4 -0
  112. package/dist/assets/{vendor-replit-codemirror-vim-Ck2X_WZC.js → vendor-replit-codemirror-vim-D0bqFa1D.js} +5 -5
  113. package/dist/assets/{worker-DdhrXE7g.js → worker-BbEdJ2Oi.js} +18 -18
  114. package/dist/assets/workerFactory-Bw5qLmrM.js +1 -0
  115. package/dist/assets/{zh-CN-CS-9Os9n.js → zh-CN-DdTNG52a.js} +2 -2
  116. package/dist/assets/{zh-TW-D0XYVdcl.js → zh-TW-DPm_33Fi.js} +2 -2
  117. package/dist/index.html +3 -3
  118. package/dist/mini-chat.html +3 -3
  119. package/dist/mobile.html +3 -3
  120. package/package.json +2 -2
  121. package/server/index.js +4 -0
  122. package/server/lib/environment/store.js +3 -4
  123. package/server/lib/environment/store.test.js +17 -0
  124. package/server/lib/fs/DOCUMENTATION.md +4 -2
  125. package/server/lib/fs/routes.js +48 -13
  126. package/server/lib/fs/routes.test.js +118 -5
  127. package/server/lib/git/DOCUMENTATION.md +3 -1
  128. package/server/lib/git/contributor-remote.js +4 -0
  129. package/server/lib/git/contributor-remote.test.js +21 -0
  130. package/server/lib/git/service.js +20 -25
  131. package/server/lib/git/service.test.js +99 -0
  132. package/server/lib/git/worktree-creation.js +4 -5
  133. package/server/lib/github/DOCUMENTATION.md +1 -1
  134. package/server/lib/github/routes.auth.test.js +14 -0
  135. package/server/lib/github/routes.js +13 -5
  136. package/server/lib/github/routes.mutations.test.js +18 -2
  137. package/server/lib/message-queue/DOCUMENTATION.md +8 -2
  138. package/server/lib/message-queue/runtime.js +3 -2
  139. package/server/lib/message-queue/runtime.test.js +64 -2
  140. package/server/lib/openchamber-control/service.js +48 -13
  141. package/server/lib/openchamber-control/service.test.js +42 -0
  142. package/server/lib/opencode/DOCUMENTATION.md +3 -1
  143. package/server/lib/opencode/project-start-command.d.ts +11 -0
  144. package/server/lib/opencode/project-start-command.js +56 -0
  145. package/server/lib/opencode/project-start-command.test.js +80 -0
  146. package/server/lib/opencode/session-activity.js +43 -3
  147. package/server/lib/opencode/session-activity.test.js +97 -0
  148. package/server/lib/opencode/settings-runtime.js +19 -1
  149. package/server/lib/opencode/settings-runtime.test.js +23 -0
  150. package/server/lib/opencode/skill-routes.js +34 -1
  151. package/server/lib/opencode/skill-routes.test.js +99 -0
  152. package/server/lib/quota/DOCUMENTATION.md +13 -1
  153. package/server/lib/quota/providers/antigravity/api.js +104 -0
  154. package/server/lib/quota/providers/antigravity/auth.js +45 -0
  155. package/server/lib/quota/providers/antigravity/index.js +76 -0
  156. package/server/lib/quota/providers/antigravity/transforms.js +168 -0
  157. package/server/lib/quota/providers/antigravity/transforms.test.js +162 -0
  158. package/server/lib/quota/providers/codex.js +28 -4
  159. package/server/lib/quota/providers/codex.test.js +29 -0
  160. package/server/lib/quota/providers/google/auth.js +4 -49
  161. package/server/lib/quota/providers/google/transforms.js +3 -22
  162. package/server/lib/quota/providers/index.js +8 -0
  163. package/server/lib/quota/providers/opencode-go.js +3 -1
  164. package/server/lib/quota/providers/opencode-go.test.js +12 -0
  165. package/server/lib/routing/DOCUMENTATION.md +3 -1
  166. package/server/lib/routing/runtime.js +34 -1
  167. package/server/lib/routing/runtime.test.js +43 -1
  168. package/server/lib/scheduled-tasks/DOCUMENTATION.md +11 -0
  169. package/server/lib/scheduled-tasks/existing-session.js +52 -8
  170. package/server/lib/scheduled-tasks/existing-session.test.js +121 -0
  171. package/server/lib/scheduled-tasks/routes.js +26 -0
  172. package/server/lib/scheduled-tasks/runtime.js +1 -0
  173. package/server/lib/session-assist/runtime.js +3 -0
  174. package/server/lib/session-assist/runtime.test.js +47 -0
  175. package/server/lib/skills-catalog/DOCUMENTATION.md +10 -1
  176. package/server/lib/skills-catalog/install.js +1 -1
  177. package/server/lib/skills-catalog/installed-sources.d.ts +17 -0
  178. package/server/lib/skills-catalog/installed-sources.js +112 -0
  179. package/server/lib/skills-catalog/installed-sources.test.js +94 -0
  180. package/server/lib/small-model/DOCUMENTATION.md +12 -5
  181. package/server/lib/small-model/index.js +6 -4
  182. package/server/lib/small-model/index.test.js +40 -0
  183. package/server/lib/small-model/routes.js +3 -2
  184. package/server/lib/source-control/change-request-worktree.js +2 -6
  185. package/server/lib/source-control/mutation-storage.js +4 -1
  186. package/server/lib/source-control/mutation-storage.test.js +21 -0
  187. package/server/lib/spaces/DOCUMENTATION.md +1 -1
  188. package/server/lib/spaces/journey.js +10 -3
  189. package/server/lib/spaces/journey.test.js +13 -1
  190. package/server/lib/terminal/history.js +22 -2
  191. package/server/lib/terminal/history.test.js +23 -0
  192. package/server/lib/terminal/theme-response.js +14 -0
  193. package/server/lib/terminal/theme-response.test.js +10 -0
  194. package/dist/assets/AboutDialog-e8ek_kPI.js +0 -1
  195. package/dist/assets/ArchiveView-CjF4_TFg.js +0 -1
  196. package/dist/assets/GuestSurfacePane-4kmEXPLD.js +0 -1
  197. package/dist/assets/HelpDialog-CITMqPDK.js +0 -1
  198. package/dist/assets/JsonTreeView-xGikhCtL.js +0 -1
  199. package/dist/assets/MarkdownImageGallery-D0FJyr7C.js +0 -1
  200. package/dist/assets/MarkdownRendererImpl-BIM7Pjwk.js +0 -1
  201. package/dist/assets/MemoryDebugPanel-CBk8QW-M.js +0 -1
  202. package/dist/assets/OnboardingScreen-Cy6ARiMS.js +0 -1
  203. package/dist/assets/OpenCodeStatusDialog-YMHuJzwt.js +0 -1
  204. package/dist/assets/RunOverview-CHkGSW1x.js +0 -2
  205. package/dist/assets/ScheduledTasksDialog-77SO8zdJ.js +0 -4
  206. package/dist/assets/SettingsWindow-X74FIkdo.js +0 -1
  207. package/dist/assets/SourceBoardView-Cff2ejOW.js +0 -1
  208. package/dist/assets/SpaceAccessDialog-BXMZNRei.js +0 -1
  209. package/dist/assets/SpaceApplyDialog-BEJd2ryu.js +0 -1
  210. package/dist/assets/SpaceSetupOutput-Cb3XcIII.js +0 -1
  211. package/dist/assets/SpacesView-I3HaRKtW.js +0 -1
  212. package/dist/assets/UsageStatsView-DwTt9zIz.js +0 -1
  213. package/dist/assets/WorktreesView-Bh7GLvrR.js +0 -1
  214. package/dist/assets/appThemeRegistry-Bzb67M9O.js +0 -1
  215. package/dist/assets/computeVirtualFileMetrics-WAp98Bb7.js +0 -3
  216. package/dist/assets/index-BsupKM40.js +0 -1
  217. package/dist/assets/main-C_QGhDBL.js +0 -1048
  218. package/dist/assets/main-pWZ7F_hy.js +0 -2
  219. package/dist/assets/markdownCore-6gz4uJDQ.js +0 -9
  220. package/dist/assets/miniChat-DnaTfdYh.js +0 -2
  221. package/dist/assets/mobile-C7DIJqP8.js +0 -2
  222. package/dist/assets/pierreDiffTint-B297eqF0.js +0 -28
  223. package/dist/assets/relocateRestoredSession-D3lujODj.js +0 -1
  224. package/dist/assets/renderElectronMiniChatApp-BF4hNe69.js +0 -2
  225. package/dist/assets/runtimeEndpointReset-D6Lxhk0S.js +0 -55
  226. package/dist/assets/scheduledTasksApi-DUbAMrjW.js +0 -1
  227. package/dist/assets/space-close-CWcWwH4_.js +0 -1
  228. package/dist/assets/useCallableModelProviders-BB9xkUzM.js +0 -1
  229. package/dist/assets/vendor-codemirror-lang-angular-BpYCRJSk.js +0 -1
  230. package/dist/assets/vendor-codemirror-lang-cpp-BI3uPyjT.js +0 -1
  231. package/dist/assets/vendor-codemirror-lang-css-B2_PZTBl.js +0 -1
  232. package/dist/assets/vendor-codemirror-lang-html-BpvvTxbZ.js +0 -1
  233. package/dist/assets/vendor-codemirror-lang-java-BM5LQZ4u.js +0 -1
  234. package/dist/assets/vendor-codemirror-lang-jinja-D8nLZQPK.js +0 -1
  235. package/dist/assets/vendor-codemirror-lang-json-VDxF27mO.js +0 -1
  236. package/dist/assets/vendor-codemirror-lang-less-BecU2BJP.js +0 -1
  237. package/dist/assets/vendor-codemirror-lang-liquid-DCw83Anh.js +0 -1
  238. package/dist/assets/vendor-codemirror-lang-markdown-CimQAQbQ.js +0 -1
  239. package/dist/assets/vendor-codemirror-lang-php-C5Kpnpyb.js +0 -1
  240. package/dist/assets/vendor-codemirror-lang-python-BFE1OJNx.js +0 -3
  241. package/dist/assets/vendor-codemirror-lang-rust-hqZDyGIJ.js +0 -1
  242. package/dist/assets/vendor-codemirror-lang-sass-CAZML-Jl.js +0 -1
  243. package/dist/assets/vendor-codemirror-lang-vue-BHOTXcKp.js +0 -1
  244. package/dist/assets/vendor-codemirror-lang-wast-DcCHfPUI.js +0 -1
  245. package/dist/assets/vendor-codemirror-lang-xml-BO_V-1wZ.js +0 -1
  246. package/dist/assets/vendor-codemirror-lang-yaml-CPimap_N.js +0 -1
  247. package/dist/assets/vendor-codemirror-language-BBADuAkg.js +0 -3
  248. package/dist/assets/vendor-codemirror-language-data-Cu5ZbrPm.js +0 -2
  249. package/dist/assets/vendor-codemirror-view-1e0FQ6Wn.js +0 -4
  250. package/dist/assets/workerFactory-De9YXIdE.js +0 -1
@@ -165,6 +165,53 @@ describe('session assist runtime', () => {
165
165
  vi.unstubAllGlobals();
166
166
  });
167
167
 
168
+ it('discards the result when a new turn starts during the final archive check', async () => {
169
+ vi.spyOn(console, 'log').mockImplementation(() => {});
170
+ const persistSessionAssist = vi.fn(async () => undefined);
171
+ const records = [
172
+ { id: 'msg_idle', type: 'idle', outcome: 'succeeded' },
173
+ { id: 'msg_a', type: 'assistant', content: [{ type: 'text', text: 'All done.' }], finish: 'stop', time: { completed: 2 }, model: { providerID: 'p', id: 'm' } },
174
+ { id: 'msg_u', type: 'user', text: 'Do the thing' },
175
+ ];
176
+ vi.stubGlobal('fetch', vi.fn(async (input) => {
177
+ const url = new URL(String(input));
178
+ let body;
179
+ if (url.pathname === '/api/session/ses_1') body = { data: { id: 'ses_1', location: { directory: '/repo' } } };
180
+ else if (url.pathname === '/api/session/ses_1/message') body = { data: records.slice(0, Number(url.searchParams.get('limit'))), cursor: {} };
181
+ else throw new Error(`unexpected ${url.pathname}`);
182
+ return new Response(JSON.stringify(body), { status: 200, headers: { 'content-type': 'application/json' } });
183
+ }));
184
+ // The first archive check answers at once; the one before the write waits
185
+ // until the test has started a new turn.
186
+ let finalCheckStarted;
187
+ const finalCheckReached = new Promise((resolve) => { finalCheckStarted = resolve; });
188
+ let finishFinalCheck;
189
+ const isSessionArchived = vi.fn(async () => {
190
+ if (isSessionArchived.mock.calls.length === 1) return false;
191
+ finalCheckStarted();
192
+ return new Promise((answer) => { finishFinalCheck = () => answer(false); });
193
+ });
194
+ const { runtime } = makeRuntime({
195
+ persistSessionAssist,
196
+ buildOpenCodeUrl: (fetchPath) => `http://opencode.test${fetchPath}`,
197
+ isSessionArchived,
198
+ getSmallModelService: async () => ({
199
+ describeSmallModel: async () => ({ inputCharBudget: 20_000 }),
200
+ generateSmallModelText: async () => ({ text: '{"recap":"Did the thing.","suggestion":"Verify it."}' }),
201
+ }),
202
+ });
203
+
204
+ runtime.processPayload(idle());
205
+ await finalCheckReached;
206
+ runtime.processPayload({ type: 'session.status', properties: { sessionID: 'ses_1', status: { type: 'busy' } } });
207
+ finishFinalCheck();
208
+ await new Promise((resolve) => setTimeout(resolve, 20));
209
+
210
+ expect(isSessionArchived).toHaveBeenCalledTimes(2);
211
+ expect(persistSessionAssist).not.toHaveBeenCalled();
212
+ vi.unstubAllGlobals();
213
+ });
214
+
168
215
  it.each([
169
216
  ['skips the session model on a local server', { providerID: 'p', modelID: 'm', source: 'session-model', localEndpoint: true }, 0],
170
217
  ['skips the session model chosen as Small Model on a local server', { providerID: 'p', modelID: 'm', source: 'settings', localEndpoint: true }, 0],
@@ -10,6 +10,7 @@ This module provides skill discovery, scanning, and installation capabilities fo
10
10
  - `github-meta.js`: Best-effort GitHub repository metadata (stars, last push) with in-memory TTL cache.
11
11
  - `git.js`: Git operations helpers for cloning and auth error detection.
12
12
  - `install.js`: Skills installation from git repositories.
13
+ - `installed-sources.js`: Which source and repo subpath each catalog-installed skill came from, for the Installed badge.
13
14
  - `scan.js`: Skills scanning from git repositories.
14
15
  - `source.js`: Source string parsing for git repositories.
15
16
 
@@ -43,6 +44,14 @@ The following functions are exported and used by the web server:
43
44
  ### Git Repository Installation (`install.js`)
44
45
  - `installSkillsFromRepository({ source, subpath, defaultSubpath, identity, credentialResolver, scope, targetSource, workingDirectory, userSkillDir, selections, conflictPolicy, conflictDecisions })`: Install selected skills from a Git repository. It uses the same identity transports as scanning and supports user/project scopes, opencode/agents targets, conflict resolution (prompt/skipAll/overwriteAll), and sparse checkout.
45
46
 
47
+ ### Install provenance (`installed-sources.js`)
48
+ The catalog's Installed badge used to match by name alone, so every same-named entry from every source read as installed (#4756). An install that names its catalog `sourceId` now records `{ skillName, skillDir, sourceId, scope, source, sourceRef }` in `skills-installed-sources.json` in the OpenChamber data dir (`version: 1`, mode 0600, atomic rename through a per-write temporary name).
49
+ - `appendInstalledSources(entries)`: record installs, deduped on source, subpath and scope. Best-effort: a failed write logs and leaves the install successful.
50
+ - `readInstalledSources()`: entries keyed by skill name. A missing or malformed file means "no records", never an error.
51
+ - `removeInstalledSources(skillName)`: forget a deleted skill's records, called after a skill delete.
52
+ - `isInstalledFromSource(byName, skillName, sourceId, skillDir)`: the badge rule. A name with records reads as installed only for a recorded source and subpath; a name without records (installed before the registry existed, or by hand) keeps the plain name match.
53
+ Web (`../opencode/skill-routes.js`) and VS Code (`packages/vscode/src/skillsCatalog.ts`, `bridge-config-runtime.ts`) share this module and file.
54
+
46
55
  ## Internal Helpers
47
56
 
48
57
  The following functions are internal helpers used by exported functions:
@@ -82,7 +91,7 @@ The following functions are internal helpers used by exported functions:
82
91
 
83
92
  ### Install Skills Response
84
93
  - `ok`: Boolean indicating success.
85
- - `installed`: Array of installed skills with `{ skillName, scope, source }`.
94
+ - `installed`: Array of installed skills with `{ skillName, skillDir, scope, source }`; `skillDir` is the repo subpath the skill was copied from.
86
95
  - `skipped`: Array of skipped skills with `{ skillName, reason }`.
87
96
  - `error`: Error object with `{ kind, message, conflicts? }` on failure. Kinds: `authRequired`, `networkError`, `conflicts`, `invalidSource`, `unknown`.
88
97
 
@@ -287,7 +287,7 @@ export async function installSkillsFromRepository({
287
287
 
288
288
  try {
289
289
  await copyDirectoryNoSymlinks(srcDir, targetDir);
290
- installed.push({ skillName: plan.skillName, scope, source: targetSource === 'agents' ? 'agents' : 'opencode' });
290
+ installed.push({ skillName: plan.skillName, skillDir: plan.skillDirPosix, scope, source: targetSource === 'agents' ? 'agents' : 'opencode' });
291
291
  } catch (error) {
292
292
  await safeRm(targetDir);
293
293
  skipped.push({
@@ -0,0 +1,17 @@
1
+ export type InstalledSourceEntry = {
2
+ skillName: string;
3
+ skillDir: string;
4
+ sourceId: string;
5
+ scope?: 'user' | 'project';
6
+ source?: 'opencode' | 'agents';
7
+ sourceRef?: string;
8
+ };
9
+ export function readInstalledSources(): Map<string, InstalledSourceEntry[]>;
10
+ export function appendInstalledSources(entries: InstalledSourceEntry[]): void;
11
+ export function removeInstalledSources(skillName: string): void;
12
+ export function isInstalledFromSource(
13
+ provenanceByName: Map<string, InstalledSourceEntry[]>,
14
+ skillName: string,
15
+ sourceId: string,
16
+ skillDir: string,
17
+ ): boolean;
@@ -0,0 +1,112 @@
1
+ // Provenance for skills installed through the catalog: which source and
2
+ // repo subpath each installed skill came from, so the Installed badge can
3
+ // match a catalog item by source instead of by name alone. Name-only matching
4
+ // badged every same-named entry from every curated source (#4756).
5
+ //
6
+ // Lives in the OpenChamber data dir as one small JSON file. Entries only add
7
+ // a constraint: a name the registry has never heard of keeps the old name
8
+ // match, so skills installed before this file existed, or placed on disk by
9
+ // hand, look exactly as they did before.
10
+ import { randomUUID } from 'node:crypto';
11
+ import fs from 'node:fs';
12
+ import os from 'node:os';
13
+ import path from 'node:path';
14
+ import { asNonEmptyString } from '../shared/guards.js';
15
+
16
+ const VERSION = 1;
17
+ const FILE_NAME = 'skills-installed-sources.json';
18
+
19
+ // Resolved per call so a test can point OPENCHAMBER_DATA_DIR somewhere fresh.
20
+ const installedSourcesPath = () => path.join(
21
+ process.env.OPENCHAMBER_DATA_DIR
22
+ ? path.resolve(process.env.OPENCHAMBER_DATA_DIR)
23
+ : path.join(os.homedir(), '.config', 'openchamber'),
24
+ FILE_NAME,
25
+ );
26
+
27
+ const entryKey = (entry) => [entry.sourceId, entry.skillDir, entry.scope].join(' ');
28
+
29
+ /**
30
+ * All recorded installs keyed by skill name. A missing or malformed file is
31
+ * "no provenance", never an error: the badge falls back to name matching
32
+ * rather than losing its state because one write was interrupted.
33
+ */
34
+ export const readInstalledSources = () => {
35
+ const byName = new Map();
36
+ let payload;
37
+ try {
38
+ payload = JSON.parse(fs.readFileSync(installedSourcesPath(), 'utf8'));
39
+ } catch {
40
+ return byName;
41
+ }
42
+ if (!payload || payload.version !== VERSION || !Array.isArray(payload.entries)) return byName;
43
+ for (const entry of payload.entries) {
44
+ const skillName = asNonEmptyString(entry?.skillName);
45
+ const sourceId = asNonEmptyString(entry?.sourceId);
46
+ const skillDir = asNonEmptyString(entry?.skillDir);
47
+ if (!skillName || !sourceId || !skillDir) continue;
48
+ const list = byName.get(skillName) ?? [];
49
+ list.push(entry);
50
+ byName.set(skillName, list);
51
+ }
52
+ return byName;
53
+ };
54
+
55
+ /**
56
+ * Records provenance for freshly installed skills. Dedupes on source, repo
57
+ * subpath and scope so a reinstall refreshes nothing and a second source for
58
+ * the same name adds its own entry.
59
+ */
60
+ export const appendInstalledSources = (entries) => {
61
+ const valid = (Array.isArray(entries) ? entries : []).filter((entry) =>
62
+ asNonEmptyString(entry?.skillName)
63
+ && asNonEmptyString(entry?.sourceId)
64
+ && asNonEmptyString(entry?.skillDir));
65
+ if (valid.length === 0) return;
66
+
67
+ const existing = readInstalledSources();
68
+ const byName = new Map();
69
+ for (const [name, list] of existing) byName.set(name, [...list]);
70
+
71
+ for (const entry of valid) {
72
+ const list = byName.get(entry.skillName) ?? [];
73
+ if (!list.some((held) => entryKey(held) === entryKey(entry))) list.push(entry);
74
+ byName.set(entry.skillName, list);
75
+ }
76
+
77
+ writeEntries([...byName.values()].flat());
78
+ };
79
+
80
+ /**
81
+ * Forgets every recorded install of a deleted skill, so a later install from
82
+ * another source is not narrowed by a stale entry. Without entries the name
83
+ * falls back to the plain name match.
84
+ */
85
+ export const removeInstalledSources = (skillName) => {
86
+ const existing = readInstalledSources();
87
+ if (!existing.has(skillName)) return;
88
+ existing.delete(skillName);
89
+ writeEntries([...existing.values()].flat());
90
+ };
91
+
92
+ // Atomic: a reader sees the previous file or the new one. The temporary name
93
+ // is unique per write, so two installs finishing together never rename each
94
+ // other's file away.
95
+ const writeEntries = (entries) => {
96
+ const target = installedSourcesPath();
97
+ fs.mkdirSync(path.dirname(target), { recursive: true });
98
+ const tmp = `${target}.${process.pid}.${randomUUID()}.tmp`;
99
+ fs.writeFileSync(tmp, JSON.stringify({ version: VERSION, entries }, null, 2), { mode: 0o600 });
100
+ fs.renameSync(tmp, target);
101
+ };
102
+
103
+ /**
104
+ * Whether a catalog item reads as installed: a skill with that name is on
105
+ * disk, and, when installs of that name were recorded, one of them came from
106
+ * this source and repo subpath.
107
+ */
108
+ export const isInstalledFromSource = (provenanceByName, skillName, sourceId, skillDir) => {
109
+ const provenance = provenanceByName.get(skillName);
110
+ return !provenance || provenance.length === 0
111
+ || provenance.some((entry) => entry.sourceId === sourceId && entry.skillDir === skillDir);
112
+ };
@@ -0,0 +1,94 @@
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
5
+
6
+ import { appendInstalledSources, isInstalledFromSource, readInstalledSources, removeInstalledSources } from './installed-sources.js';
7
+
8
+ let dataDir;
9
+ let previousDataDir;
10
+
11
+ beforeEach(() => {
12
+ dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'oc-installed-sources-'));
13
+ previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
14
+ process.env.OPENCHAMBER_DATA_DIR = dataDir;
15
+ });
16
+
17
+ afterEach(() => {
18
+ if (previousDataDir === undefined) delete process.env.OPENCHAMBER_DATA_DIR;
19
+ else process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
20
+ fs.rmSync(dataDir, { recursive: true, force: true });
21
+ });
22
+
23
+ const entry = (overrides = {}) => ({
24
+ skillName: 'skill-creator',
25
+ skillDir: 'skills/skill-creator',
26
+ scope: 'user',
27
+ source: 'opencode',
28
+ sourceId: 'acme',
29
+ sourceRef: 'acme/skills',
30
+ ...overrides,
31
+ });
32
+
33
+ describe('installed skill provenance registry', () => {
34
+ it('round-trips entries keyed by skill name', () => {
35
+ appendInstalledSources([entry(), entry({ skillName: 'other', sourceId: 'other', skillDir: 'skills/other' })]);
36
+
37
+ const byName = readInstalledSources();
38
+ expect(byName.get('skill-creator')).toHaveLength(1);
39
+ expect(byName.get('skill-creator')[0]).toMatchObject({ sourceId: 'acme', skillDir: 'skills/skill-creator' });
40
+ expect(byName.get('other')[0]).toMatchObject({ sourceId: 'other' });
41
+ });
42
+
43
+ it('adds a second source for the same name and dedupes a reinstall', () => {
44
+ appendInstalledSources([entry()]);
45
+ appendInstalledSources([entry()]);
46
+ appendInstalledSources([entry({ sourceId: 'other', sourceRef: 'other/skills' })]);
47
+
48
+ const entries = readInstalledSources().get('skill-creator');
49
+ expect(entries).toHaveLength(2);
50
+ expect(entries.map((held) => held.sourceId)).toEqual(['acme', 'other']);
51
+ });
52
+
53
+ it('treats a missing or malformed file as no provenance', () => {
54
+ expect(readInstalledSources().size).toBe(0);
55
+
56
+ fs.writeFileSync(path.join(dataDir, 'skills-installed-sources.json'), '{broken');
57
+ expect(readInstalledSources().size).toBe(0);
58
+
59
+ fs.writeFileSync(path.join(dataDir, 'skills-installed-sources.json'), JSON.stringify({ version: 99, entries: [entry()] }));
60
+ expect(readInstalledSources().size).toBe(0);
61
+ });
62
+
63
+ it('ignores entries that are missing their identity', () => {
64
+ appendInstalledSources([entry({ sourceId: '' }), { skillName: '', skillDir: 'x', sourceId: 'a' }, entry({ skillDir: '' })]);
65
+
66
+ expect(readInstalledSources().size).toBe(0);
67
+ });
68
+
69
+ it('appends nothing when every entry is invalid', () => {
70
+ appendInstalledSources([{ nope: true }]);
71
+
72
+ expect(fs.existsSync(path.join(dataDir, 'skills-installed-sources.json'))).toBe(false);
73
+ });
74
+
75
+ it('forgets every entry of a deleted skill and keeps the rest', () => {
76
+ appendInstalledSources([entry(), entry({ sourceId: 'other' }), entry({ skillName: 'kept', skillDir: 'skills/kept' })]);
77
+
78
+ removeInstalledSources('skill-creator');
79
+
80
+ const byName = readInstalledSources();
81
+ expect(byName.has('skill-creator')).toBe(false);
82
+ expect(byName.get('kept')).toHaveLength(1);
83
+ expect(fs.readdirSync(dataDir).filter((name) => name.endsWith('.tmp'))).toEqual([]);
84
+ });
85
+
86
+ it('narrows the badge to recorded sources and falls back to the name without records', () => {
87
+ appendInstalledSources([entry()]);
88
+ const byName = readInstalledSources();
89
+
90
+ expect(isInstalledFromSource(byName, 'skill-creator', 'acme', 'skills/skill-creator')).toBe(true);
91
+ expect(isInstalledFromSource(byName, 'skill-creator', 'other', 'skills/skill-creator')).toBe(false);
92
+ expect(isInstalledFromSource(byName, 'unrecorded', 'any', 'skills/unrecorded')).toBe(true);
93
+ });
94
+ });
@@ -23,7 +23,7 @@ credentials, the provider dispatch and the token refresh. Routes live under
23
23
  retracting it. An empty list is never cached: OpenCode 2 answers with one
24
24
  while it starts, and caching it hid every provider from the pickers.
25
25
  - `index.js` — `generateSmallModelText()`, `describeSmallModel()`,
26
- `listAuthenticatedProviders()`.
26
+ `listAuthenticatedProviders(directory?)`.
27
27
  - `routes.js` — `GET /api/small-model` (resolution preview) and
28
28
  `POST /api/small-model/generate` (`{ prompt, system?, maxOutputTokens?,
29
29
  model?, directory? }` → `{ text, providerID, modelID, source }`).
@@ -173,17 +173,24 @@ capability is not knowable before the call, and callers must read `null` as
173
173
 
174
174
  ## Which providers the pickers may offer
175
175
 
176
- `listAuthenticatedProviders()` answers one question for the Small Model and
176
+ `listAuthenticatedProviders(directory)` answers one question for the Small Model and
177
177
  Changes Walkthrough pickers: which providers OpenCode can call right now. A
178
178
  provider counts when it has at least one enabled model in `GET /api/model` —
179
- the same test OpenCode applies before letting a chat turn use it.
179
+ the same test OpenCode applies before letting a chat turn use it. The model
180
+ list is directory-scoped, so `directory` scopes this answer the same way
181
+ `describeSmallModel` scopes its own; without one the server default applies,
182
+ and a default directory with no model config would report no providers for
183
+ models that work perfectly in the user's project.
180
184
 
181
185
  `GET /api/provider` only contributes names. It comes back empty on setups where
182
186
  models are perfectly usable, so an empty provider list is never read as "no
183
187
  providers". Claude Code is removed from the result for the reason above.
184
188
 
185
- The field is served as `authenticatedProviders` on `GET /api/small-model`. The
186
- name predates this resolution; it now means "callable".
189
+ The field is served as `authenticatedProviders` on `GET /api/small-model`, and
190
+ the route forwards its `?directory=` query to both halves of the answer. The
191
+ Settings pickers send the current directory with the request, so the list
192
+ matches what the user sees in chat for that project. The name predates this
193
+ resolution; it now means "callable".
187
194
 
188
195
  ## describeSmallModel
189
196
 
@@ -377,19 +377,21 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
377
377
  /**
378
378
  * Provider ids the small model can actually call. A provider counts when
379
379
  * OpenCode has at least one enabled model for it — that is the same test
380
- * OpenCode applies before letting a chat turn use it.
380
+ * OpenCode applies before letting a chat turn use it. The model list is
381
+ * directory-scoped, so `directory` scopes this answer the same way
382
+ * `describeSmallModel` scopes its own; without one the server default applies.
381
383
  *
382
384
  * The provider list alone is not enough: it comes back empty on setups where
383
385
  * models are perfectly usable, so the model list is the authority and the
384
386
  * provider list only contributes names.
385
387
  */
386
- export async function listAuthenticatedProviders() {
387
- const client = getSmallModelClient();
388
+ export async function listAuthenticatedProviders(directory) {
389
+ const client = getSmallModelClient(directory);
388
390
  if (!client) return [];
389
391
  try {
390
392
  const [providers, models] = await Promise.all([
391
393
  listProviderInfos(client),
392
- listModelInfos(client),
394
+ listModelInfos(client, directory),
393
395
  ]);
394
396
  const enabled = new Set();
395
397
  for (const model of models) {
@@ -645,6 +645,46 @@ describe('listAuthenticatedProviders', () => {
645
645
 
646
646
  expect(await listAuthenticatedProviders()).toEqual([]);
647
647
  });
648
+
649
+ // The model list is directory-scoped, so an unscoped read answers for
650
+ // OpenCode's own working directory, which need not be where the user works.
651
+ it('scopes the model and provider reads to the requested directory', async () => {
652
+ configureOpenCodeRuntimeProviders({
653
+ buildOpenCodeUrl: (requestPath) => `${baseUrl}${requestPath.startsWith('/') ? requestPath : `/${requestPath}`}`,
654
+ getOpenCodeAuthHeaders: () => ({ Authorization: 'Basic test' }),
655
+ getDefaultDirectory: () => '/last/project',
656
+ });
657
+
658
+ await listAuthenticatedProviders('/proj/sub dir');
659
+
660
+ const reads = state.requests.filter((entry) => entry.path === '/api/model' || entry.path === '/api/provider');
661
+ expect(reads.length).toBeGreaterThan(0);
662
+ expect(reads.every((entry) => entry.headers['x-opencode-directory'] === encodeURIComponent('/proj/sub dir'))).toBe(true);
663
+ });
664
+ });
665
+
666
+ describe('small model routes', () => {
667
+ it('forwards the request directory to the provider list', async () => {
668
+ let getHandler;
669
+ const providerCalls = [];
670
+ registerSmallModelRoutes({
671
+ get(_path, handler) { getHandler = handler; },
672
+ post() {},
673
+ }, {
674
+ getSmallModelService: async () => ({
675
+ describeSmallModel: async () => null,
676
+ listAuthenticatedProviders: async (directory) => {
677
+ providerCalls.push(directory);
678
+ return ['anthropic'];
679
+ },
680
+ }),
681
+ });
682
+ const response = { json() {}, status() { return response; } };
683
+
684
+ await getHandler({ query: { directory: '/proj/sub dir' } }, response);
685
+
686
+ expect(providerCalls).toEqual(['/proj/sub dir']);
687
+ });
648
688
  });
649
689
 
650
690
 
@@ -2,15 +2,16 @@ export function registerSmallModelRoutes(app, { getSmallModelService }) {
2
2
  app.get('/api/small-model', async (req, res) => {
3
3
  try {
4
4
  const { describeSmallModel, listAuthenticatedProviders } = await getSmallModelService();
5
+ const directory = typeof req.query.directory === 'string' ? req.query.directory : undefined;
5
6
  const resolved = await describeSmallModel({
6
- directory: typeof req.query.directory === 'string' ? req.query.directory : undefined,
7
+ directory,
7
8
  preferredProviderID: typeof req.query.providerID === 'string' ? req.query.providerID : undefined,
8
9
  preferredModelID: typeof req.query.modelID === 'string' ? req.query.modelID : undefined,
9
10
  });
10
11
  res.json({
11
12
  available: Boolean(resolved),
12
13
  model: resolved,
13
- authenticatedProviders: await listAuthenticatedProviders(),
14
+ authenticatedProviders: await listAuthenticatedProviders(directory),
14
15
  });
15
16
  } catch (error) {
16
17
  console.error('Failed to resolve small model:', error);
@@ -1,4 +1,5 @@
1
1
  import { hostOf } from './binding-service.js';
2
+ import { forkRemoteName } from '../git/contributor-remote.js';
2
3
 
3
4
  /**
4
5
  * The change-request source for a worktree made from a pull or merge request
@@ -17,11 +18,6 @@ import { hostOf } from './binding-service.js';
17
18
 
18
19
  const sourceControlError = (message, status, code) => Object.assign(new Error(message), { status, code });
19
20
 
20
- // The client names the fork remote this way; the contributor pipeline renames
21
- // it after the provider's own head owner anyway.
22
- const requestedRemoteName = (owner) => `pr-${String(owner || '').trim().toLowerCase()
23
- .replace(/[^a-z0-9._-]+/g, '-').replace(/-+/g, '-').replace(/^-+|-+$/g, '') || 'head'}`;
24
-
25
21
  export const createChangeRequestWorktreeSource = ({
26
22
  readBinding,
27
23
  listGitLabInstances,
@@ -83,7 +79,7 @@ export const createChangeRequestWorktreeSource = ({
83
79
  project: head.project,
84
80
  number,
85
81
  expectedHeadSha: head.headSha,
86
- requestedRemoteName: requestedRemoteName(head.headOwner),
82
+ requestedRemoteName: forkRemoteName(head.headOwner),
87
83
  },
88
84
  };
89
85
  };
@@ -37,6 +37,9 @@ const hasExactKeys = (value, required, optional = []) => {
37
37
  };
38
38
  const isTimestamp = (value) => Number.isSafeInteger(value) && value >= 0;
39
39
  const isPositiveInteger = (value) => Number.isSafeInteger(value) && value > 0;
40
+ // Revision 0 is the designed no-binding state the binding service accepts
41
+ // (DOCUMENTATION.md, binding-service section), so the storage gate matches it.
42
+ const isNonNegativeInteger = (value) => Number.isSafeInteger(value) && value >= 0;
40
43
  const isFailureStatus = (value) => Number.isSafeInteger(value) && value >= 400 && value <= 599;
41
44
 
42
45
  const invalidState = () => {
@@ -71,7 +74,7 @@ const isTarget = (value) => isPlainObject(value)
71
74
  TARGET_OPTIONAL_KEYS,
72
75
  )
73
76
  && isNonEmptyString(value.repositoryId)
74
- && isPositiveInteger(value.bindingRevision)
77
+ && isNonNegativeInteger(value.bindingRevision)
75
78
  && isNonEmptyString(value.primaryRemote)
76
79
  && isProject(value.project)
77
80
  && (value.number === undefined || isPositiveInteger(value.number))
@@ -95,6 +95,27 @@ describe('source-control mutation storage', () => {
95
95
  await expect(store.claim(claimFor('key-one', 'different'))).resolves.toEqual({ status: 'conflict', record: claimed.record });
96
96
  });
97
97
 
98
+ it('claims with binding revision 0, the no-binding repository state', async () => {
99
+ const { store } = await makeStore({ now: () => 100 });
100
+ const zero = claimFor('zero-revision', 'digest-zero', {
101
+ target: { ...claimFor('zero-revision').target, bindingRevision: 0 },
102
+ });
103
+
104
+ await expect(store.claim(zero)).resolves.toMatchObject({ status: 'claimed' });
105
+ await expect(store.read('zero-revision')).resolves.toMatchObject({ key: 'zero-revision' });
106
+ await expect(store.list()).resolves.toHaveLength(1);
107
+ });
108
+
109
+ it('still rejects binding revisions that are not non-negative safe integers', async () => {
110
+ const { store } = await makeStore({ now: () => 100 });
111
+ for (const [index, bindingRevision] of [-1, 1.5, Number.NaN].entries()) {
112
+ const invalid = claimFor(`bad-revision-${index}`, `digest-bad-${index}`, {
113
+ target: { ...claimFor(`bad-revision-${index}`).target, bindingRevision },
114
+ });
115
+ await expect(store.claim(invalid)).rejects.toMatchObject({ code: 'INVALID_SOURCE_CONTROL_MUTATIONS' });
116
+ }
117
+ });
118
+
98
119
  it.each(['constructor', '__proto__'])('treats the opaque key %s as data', async (key) => {
99
120
  const { store } = await makeStore({ now: () => 100 });
100
121
  const claimed = await store.claim(claimFor(key));
@@ -602,7 +602,7 @@ A failure is one JSON answer, `{ code, message, details }`, with the status `rou
602
602
 
603
603
  `POST /` answers as soon as the space has an id, and the rest runs in the background, because a first create pulls the image, fills the tools volume and pushes the code, which can take minutes. The steps, each announced on the host's hub as `openchamber:space-progress` with `{ spaceId, step, failure, timestamp }` in `properties`, the way `openchamber:space-stream` is announced: `checking_place`, the place's `check()`, refused with the place's own code when it is unavailable and with `place_cannot_restrict_network` when an allowlist was asked of an engine without host isolation; `creating`, the manager's create, which is the image, the tools volume, both networks, the gatekeeper and the space container, verified; `setting_network`, the record written and the mode and allowlist said to the gatekeeper, which allowed nothing until then; `bringing_code`, the snapshot and the transfer of code in, with the space path and the base kept in the record; `ready`. The history goes after `ready`, in the background, and its outcome is kept in the record as `history`: `sent`, `already_complete`, `host_shallow` or `failed`, `pending` until then. A start of a space whose history is still `pending` sends it again.
604
604
 
605
- A failure after `creating` removes what was made: the containers, the refs in the user's repository and the record, and the answer of the failed step is kept in the list as `state: 'failed'` with `failure: { code, message, details, cleanup }` until the user dismisses it with `DELETE /<id>`, so an error is never silent; when that clean-up itself failed, `cleanup` says so and the dismissal removes what is still there, so the space cannot come back in the list as damaged after the user was told it was gone. A creation under way is listed as `preparing` with its `step`, over the place's view of it, and refuses start, stop, remove and apply with `space_preparing` until it is ready or failed; a failed one refuses them with `space_creation_failed`. One action runs per space at a time: start, stop, remove, the journal, the preview and the apply take a lock on the space's id and a second action meets `space_busy`, so a remove from another client cannot pull the service refs from under an apply that is writing them. A start of a space whose history is `pending` or `failed` sends it again, because a stop right after the creation is the usual way it fails. The project must be one the host has registered, compared as the label's hash and the path, because the sidebar resolves a space to its project the same way. The four choices are parsed at the boundary, each field refusing with a code of its own: `project_not_registered`, `invalid_space_name`, `invalid_snapshot_mode`, `invalid_network`, and since 5d-4 `invalid_setup_commands` for the project's setup commands, which start in the background right after `ready`.
605
+ A failure after `creating` removes what was made: the containers, the refs in the user's repository and the record, and the answer of the failed step is kept in the list as `state: 'failed'` with `failure: { code, message, details, cleanup }` until the user dismisses it with `DELETE /<id>`, so an error is never silent; when that clean-up itself failed, `cleanup` says so and the dismissal removes what is still there, so the space cannot come back in the list as damaged after the user was told it was gone. A creation under way is listed as `preparing` with its `step`, over the place's view of it, and refuses start, stop, remove and apply with `space_preparing` until it is ready or failed; a failed one refuses them with `space_creation_failed`. One action runs per space at a time: start, stop, remove, the journal, the preview and the apply take a lock on the space's id and a second action meets `space_busy`, so a remove from another client cannot pull the service refs from under an apply that is writing them. A start of a space whose history is `pending` or `failed` sends it again, because a stop right after the creation is the usual way it fails. The project must be one the host has registered, compared as the label's hash and the path, because the sidebar resolves a space to its project the same way. The request may spell the folder any way the host's `path.resolve` turns into the registered one, forward slashes on Windows among them, and the space keeps it as the settings name it. The four choices are parsed at the boundary, each field refusing with a code of its own: `project_not_registered`, `invalid_space_name`, `invalid_snapshot_mode`, `invalid_network`, and since 5d-4 `invalid_setup_commands` for the project's setup commands, which start in the background right after `ready`.
606
606
 
607
607
  ### The record
608
608
 
@@ -36,6 +36,7 @@
36
36
 
37
37
  import crypto from 'node:crypto';
38
38
  import fsPromises from 'node:fs/promises';
39
+ import path from 'node:path';
39
40
 
40
41
  import { z } from 'zod';
41
42
 
@@ -140,7 +141,8 @@ const failureOf = (error) => ({
140
141
  * `archiveChats({ spaceId, name, projectDirectory, running, allowUnsaved })` saves a space's chats
141
142
  * to the host's archive before it goes, see `space-archive.js`; without it the chats go with it.
142
143
  * `folderExists(directory)` says whether the project folder a space was made for is still a
143
- * folder on the host, for the list.
144
+ * folder on the host, for the list. `resolveDirectory` is the host's `path.resolve`, injectable so a
145
+ * test can resolve Windows paths on another system.
144
146
  */
145
147
  export function createSpaceJourney({
146
148
  manager,
@@ -160,6 +162,7 @@ export function createSpaceJourney({
160
162
  readIdleStop = async () => ({ ...DEFAULT_IDLE_STOP }),
161
163
  saveIdleStop = async () => {},
162
164
  folderExists = async (directory) => (await fsPromises.stat(directory).catch(() => null))?.isDirectory() === true,
165
+ resolveDirectory = path.resolve,
163
166
  announce = () => {},
164
167
  onSpacesChanged = () => {},
165
168
  logger = console,
@@ -233,12 +236,16 @@ export function createSpaceJourney({
233
236
  return new Map(directories.map((directory) => [hashProjectDirectory(directory), directory]));
234
237
  };
235
238
 
239
+ // The UI sends a project's folder in its own spelling, with forward slashes on Windows, while the
240
+ // settings keep the system's; both resolve to the same path. The space is made for the folder as
241
+ // the settings name it.
236
242
  const requireRegisteredProject = async (directory) => {
243
+ const resolved = resolveDirectory(directory);
237
244
  const projects = await registeredProjects();
238
- if (projects.get(hashProjectDirectory(directory)) !== directory) {
245
+ if (projects.get(hashProjectDirectory(resolved)) !== resolved) {
239
246
  throw new SpaceError(...CREATE_REFUSALS.projectDirectory);
240
247
  }
241
- return directory;
248
+ return resolved;
242
249
  };
243
250
 
244
251
  const progress = (entry, step, failure = null) => {
@@ -35,7 +35,7 @@ afterEach(() => {
35
35
  });
36
36
 
37
37
  /** A journey on fresh stand-ins. `failAt` names a stand-in step that rejects. */
38
- const journeyWith = ({ readHostLogin = null, failAt = null, place = createMemoryPlace(), morePlaces = [], projects = [PROJECT], historyStatus = 'sent', holdCodeIn = false, holdCodeOut = false, holdIdleSave = false, holdReady = false, holdLoginRow = false, hostEnvironment = {}, hostLogin = null, dataDir = null, archiveChats = null, logger = quiet } = {}) => {
38
+ const journeyWith = ({ readHostLogin = null, failAt = null, place = createMemoryPlace(), morePlaces = [], projects = [PROJECT], historyStatus = 'sent', holdCodeIn = false, holdCodeOut = false, holdIdleSave = false, holdReady = false, holdLoginRow = false, hostEnvironment = {}, hostLogin = null, dataDir = null, archiveChats = null, logger = quiet, resolveDirectory = undefined } = {}) => {
39
39
  // With `holdCodeIn`, code in waits until the test lets it go, so a creation stays under way;
40
40
  // `holdCodeOut` does the same for the fetch of an apply.
41
41
  let releaseCodeIn = () => {};
@@ -119,6 +119,7 @@ const journeyWith = ({ readHostLogin = null, failAt = null, place = createMemory
119
119
  readHostSecret: (name) => hostEnvironment[name],
120
120
  readHostLogin: readHostLogin ?? (async (provider) => (hostLogin && provider === 'openai' ? hostLogin : null)),
121
121
  folderExists: async () => true,
122
+ resolveDirectory,
122
123
  readIdleStop: async () => idle.saved ?? { enabled: true, hours: 4 },
123
124
  saveIdleStop: async (setting) => { if (holdIdleSave) await idleSaveHeld; fail('saveIdleStop'); idle.saved = setting; },
124
125
  announce: (spaceId, payload) => { events.push({ spaceId, ...payload.properties }); },
@@ -203,6 +204,17 @@ describe('the journey: create', () => {
203
204
  expect(await until(() => steps(events, open.id).includes('ready'))).toBe(true);
204
205
  });
205
206
 
207
+ it('takes the project folder in the UI\'s spelling and makes the space for the folder the settings name', async () => {
208
+ // On Windows the UI sends forward slashes and the settings keep backslashes.
209
+ const registered = 'C:\\Users\\me\\project';
210
+ const { journey, events, records } = journeyWith({ projects: [registered], resolveDirectory: path.win32.resolve });
211
+ const space = await journey.createSpace({ ...REQUEST, projectDirectory: 'C:/Users/me/project/' });
212
+ expect(space.projectDirectory).toBe(registered);
213
+ expect(await until(() => steps(events, space.id).includes('ready'))).toBe(true);
214
+ expect(records.read(space.id).record.repository).toBe(registered);
215
+ await expect(journey.createSpace({ ...REQUEST, projectDirectory: 'C:/Users/me/other' })).rejects.toMatchObject({ code: 'project_not_registered' });
216
+ });
217
+
206
218
  it('refuses a bad request before anything runs', async () => {
207
219
  const { journey, place, events } = journeyWith();
208
220
  await expect(journey.createSpace({ ...REQUEST, projectDirectory: '/home/me/other' })).rejects.toMatchObject({ code: 'project_not_registered' });