@myrialabs/clopen 0.4.50 → 0.4.51

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 (457) hide show
  1. package/README.md +2 -1
  2. package/backend/chat/attachments.test.ts +106 -17
  3. package/backend/chat/attachments.ts +131 -34
  4. package/backend/chat/engine-handoff.ts +42 -6
  5. package/backend/chat/stream-manager.ts +41 -5
  6. package/backend/containers/actions.ts +22 -0
  7. package/backend/control/actions/projects.ts +93 -37
  8. package/backend/control/folders.test.ts +27 -2
  9. package/backend/control/index.ts +2 -1
  10. package/backend/database/migrations/056_support_mssql_driver.ts +7 -0
  11. package/backend/database/migrations/077_create_integration_db_links.ts +7 -0
  12. package/backend/database/migrations/086_single_owner.ts +66 -73
  13. package/backend/database/migrations/090_create_storage_tables.ts +83 -0
  14. package/backend/database/migrations/index.ts +11 -2
  15. package/backend/database/queries/integration-queries.ts +10 -0
  16. package/backend/database/queries/memory-queue-queries.ts +11 -0
  17. package/backend/database/queries/project-queries.ts +6 -0
  18. package/backend/database/queries/session-queries.ts +3 -0
  19. package/backend/database/utils/migration-runner.test.ts +196 -0
  20. package/backend/database/utils/migration-runner.ts +61 -16
  21. package/backend/database/utils/seeder-runner.ts +22 -16
  22. package/backend/engine/adapters/claude/stream.ts +5 -0
  23. package/backend/engine/adapters/cursor/environment.ts +1 -1
  24. package/backend/engine/adapters/qwen/session-store.ts +10 -1
  25. package/backend/engine/types.ts +7 -0
  26. package/backend/git/identity/cli.ts +35 -0
  27. package/backend/git/identity/env.test.ts +52 -1
  28. package/backend/git/identity/env.ts +69 -10
  29. package/backend/git/identity/index.ts +25 -6
  30. package/backend/git/identity/resolve.ts +2 -1
  31. package/backend/git/identity/scope-config.ts +13 -7
  32. package/backend/git-hosts/accounts.ts +106 -0
  33. package/backend/git-hosts/auth/client-ids.ts +34 -0
  34. package/backend/git-hosts/auth/connect.ts +110 -0
  35. package/backend/git-hosts/auth/endpoints.ts +130 -0
  36. package/backend/git-hosts/auth/flows.ts +355 -0
  37. package/backend/git-hosts/auth/local.ts +152 -0
  38. package/backend/git-hosts/ci.ts +18 -0
  39. package/backend/git-hosts/cli.test.ts +82 -0
  40. package/backend/git-hosts/cli.ts +342 -0
  41. package/backend/git-hosts/credentials.ts +173 -0
  42. package/backend/git-hosts/git-credential.ts +30 -0
  43. package/backend/git-hosts/health.ts +39 -0
  44. package/backend/git-hosts/http.ts +174 -0
  45. package/backend/git-hosts/index.ts +34 -0
  46. package/backend/git-hosts/providers/bitbucket.ts +186 -0
  47. package/backend/git-hosts/providers/gitea.ts +208 -0
  48. package/backend/git-hosts/providers/github.ts +270 -0
  49. package/backend/git-hosts/providers/gitlab-client.ts +70 -0
  50. package/backend/git-hosts/providers/gitlab.ts +285 -0
  51. package/backend/git-hosts/providers/locators.test.ts +68 -0
  52. package/backend/git-hosts/registry.ts +50 -0
  53. package/backend/git-hosts/service.ts +432 -0
  54. package/backend/git-hosts/types.ts +82 -0
  55. package/backend/git-hosts/urls.test.ts +42 -0
  56. package/backend/git-hosts/urls.ts +69 -0
  57. package/backend/index.ts +50 -10
  58. package/backend/integrations/accounts.ts +50 -3
  59. package/backend/integrations/registry/define.ts +9 -0
  60. package/backend/integrations/registry/index.ts +11 -0
  61. package/backend/integrations/registry/providers/bitbucket.ts +51 -0
  62. package/backend/integrations/registry/providers/gitea.ts +53 -0
  63. package/backend/integrations/registry/providers/github.ts +24 -7
  64. package/backend/integrations/registry/providers/gitlab.ts +57 -0
  65. package/backend/integrations/registry/types.ts +13 -1
  66. package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +115 -31
  67. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -0
  68. package/backend/mentions/diff.ts +63 -0
  69. package/backend/mentions/index.ts +109 -0
  70. package/backend/mentions/mentions.test.ts +27 -0
  71. package/backend/mentions/shared.ts +82 -0
  72. package/backend/mentions/sources/ai-changes.ts +140 -0
  73. package/backend/mentions/sources/chats.ts +122 -0
  74. package/backend/mentions/sources/database.ts +211 -0
  75. package/backend/mentions/sources/files.ts +240 -0
  76. package/backend/mentions/sources/git.ts +308 -0
  77. package/backend/mentions/sources/notes-memory.ts +121 -0
  78. package/backend/mentions/sources/ops.ts +125 -0
  79. package/backend/mentions/sources/preview.ts +153 -0
  80. package/backend/mentions/sources/projects.ts +114 -0
  81. package/backend/mentions/sources/system.ts +135 -0
  82. package/backend/mentions/sources/terminal.ts +50 -0
  83. package/backend/mentions/types.ts +75 -0
  84. package/backend/preview/browser/bot-check-frames.test.ts +49 -0
  85. package/backend/preview/browser/bot-check-frames.ts +66 -0
  86. package/backend/preview/browser/browser-dialog-handler.ts +6 -5
  87. package/backend/preview/browser/browser-host-bridge.ts +4 -2
  88. package/backend/preview/browser/browser-native-ui-handler.ts +21 -0
  89. package/backend/preview/browser/browser-pool.ts +26 -17
  90. package/backend/preview/browser/browser-preview-service.ts +164 -2
  91. package/backend/preview/browser/browser-screenshot.test.ts +113 -0
  92. package/backend/preview/browser/browser-screenshot.ts +396 -0
  93. package/backend/preview/browser/browser-tab-manager.ts +35 -186
  94. package/backend/preview/browser/browser-video-capture.ts +12 -17
  95. package/backend/preview/browser/element-describe.ts +125 -0
  96. package/backend/preview/browser/page-binding.ts +141 -0
  97. package/backend/preview/browser/screenshot-files.test.ts +117 -0
  98. package/backend/preview/browser/screenshot-files.ts +134 -0
  99. package/backend/preview/browser/user-agent.test.ts +25 -0
  100. package/backend/preview/browser/user-agent.ts +100 -0
  101. package/backend/projects/engine-transcripts.ts +153 -0
  102. package/backend/projects/folder-guard.ts +55 -0
  103. package/backend/projects/move.test.ts +208 -0
  104. package/backend/projects/move.ts +277 -0
  105. package/backend/projects/project-cleanup.integration.test.ts +3 -1
  106. package/backend/projects/project-cleanup.ts +10 -0
  107. package/backend/storage/actions.ts +260 -0
  108. package/backend/storage/chats.test.ts +57 -0
  109. package/backend/storage/chats.ts +170 -0
  110. package/backend/storage/database.ts +105 -0
  111. package/backend/storage/engine-homes.ts +145 -0
  112. package/backend/storage/fs-size.ts +111 -0
  113. package/backend/storage/history.ts +39 -0
  114. package/backend/storage/policy.ts +156 -0
  115. package/backend/storage/preview-profiles.ts +169 -0
  116. package/backend/storage/purge.ts +158 -0
  117. package/backend/storage/scanner.ts +339 -0
  118. package/backend/storage/session-index.ts +208 -0
  119. package/backend/storage/snapshots.ts +99 -0
  120. package/backend/storage/storage-flow.test.ts +137 -0
  121. package/backend/storage/transcripts/aliases.ts +75 -0
  122. package/backend/storage/transcripts/claude-dedupe.test.ts +101 -0
  123. package/backend/storage/transcripts/claude-dedupe.ts +152 -0
  124. package/backend/storage/transcripts/claude.ts +155 -0
  125. package/backend/storage/transcripts/cursor.ts +165 -0
  126. package/backend/storage/transcripts/file-stores.ts +224 -0
  127. package/backend/storage/transcripts/index.ts +207 -0
  128. package/backend/storage/transcripts/opencode.ts +124 -0
  129. package/backend/storage/transcripts/references.ts +42 -0
  130. package/backend/storage/transcripts/types.ts +58 -0
  131. package/backend/storage/worktrees.ts +114 -0
  132. package/backend/terminal/ptykit.ts +25 -0
  133. package/backend/update/registry.ts +24 -0
  134. package/backend/update/release-notes.test.ts +110 -0
  135. package/backend/update/release-notes.ts +132 -0
  136. package/backend/update/restart.ts +159 -0
  137. package/backend/utils/env.test.ts +64 -0
  138. package/backend/utils/env.ts +23 -55
  139. package/backend/utils/port-utils.ts +13 -0
  140. package/backend/work/index.ts +13 -2
  141. package/backend/work/providers/github/actions-logs.ts +1 -1
  142. package/backend/work/providers/github/adapter.ts +32 -1
  143. package/backend/work/providers/github/client.ts +7 -3
  144. package/backend/work/providers/gitlab/adapter.ts +770 -0
  145. package/backend/work/providers/gitlab/system-notes.test.ts +24 -0
  146. package/backend/work/service.ts +60 -36
  147. package/backend/work/start-work.ts +1 -1
  148. package/backend/work/types.ts +4 -0
  149. package/backend/worktrees/index.ts +1 -0
  150. package/backend/worktrees/service.ts +23 -2
  151. package/backend/ws/chat/composer.ts +47 -6
  152. package/backend/ws/files/search.ts +1 -1
  153. package/backend/ws/files/write.ts +27 -0
  154. package/backend/ws/hosting/index.ts +231 -0
  155. package/backend/ws/index.ts +12 -2
  156. package/backend/ws/integrations/crud.ts +31 -5
  157. package/backend/ws/integrations/hosting-auth.ts +227 -0
  158. package/backend/ws/integrations/index.ts +2 -0
  159. package/backend/ws/mentions/index.ts +81 -0
  160. package/backend/ws/preview/browser/screenshot.ts +184 -0
  161. package/backend/ws/preview/index.ts +23 -0
  162. package/backend/ws/projects/crud.ts +66 -58
  163. package/backend/ws/sessions/crud.ts +7 -95
  164. package/backend/ws/snapshot/changes.ts +3 -3
  165. package/backend/ws/storage/index.ts +102 -0
  166. package/backend/ws/system/index.ts +7 -0
  167. package/backend/ws/system/operations.ts +125 -69
  168. package/backend/ws/work/context.ts +3 -4
  169. package/backend/ws/work/crud.ts +33 -0
  170. package/backend/ws/work/schemas.ts +4 -1
  171. package/bin/clopen.ts +15 -16
  172. package/dist/assets/{index-By6KdSLT.js → index-B9rHDvjg.js} +1 -1
  173. package/dist/assets/index-B9rHDvjg.js.br +0 -0
  174. package/dist/assets/index-B9rHDvjg.js.gz +0 -0
  175. package/dist/assets/{index-DV4TiDn1.js → index-DFlwOd7k.js} +1 -1
  176. package/dist/assets/index-DFlwOd7k.js.br +0 -0
  177. package/dist/assets/index-DFlwOd7k.js.gz +0 -0
  178. package/dist/assets/main-Bz_brxxS.css +1 -0
  179. package/dist/assets/main-Bz_brxxS.css.br +0 -0
  180. package/dist/assets/main-Bz_brxxS.css.gz +0 -0
  181. package/dist/assets/main-DRcX9SHx.js +1273 -0
  182. package/dist/assets/main-DRcX9SHx.js.br +0 -0
  183. package/dist/assets/main-DRcX9SHx.js.gz +0 -0
  184. package/dist/assets/pdf-DfwfQPLy.js +57 -0
  185. package/dist/assets/pdf-DfwfQPLy.js.br +0 -0
  186. package/dist/assets/pdf-DfwfQPLy.js.gz +0 -0
  187. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
  188. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.br +0 -0
  189. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.gz +0 -0
  190. package/dist/assets/pdf.worker.min-BOrSNwfp.js +1 -0
  191. package/dist/index.html +2 -2
  192. package/dist/index.html.br +0 -0
  193. package/dist/index.html.gz +0 -0
  194. package/dist/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
  195. package/dist/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
  196. package/dist/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
  197. package/dist/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
  198. package/dist/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
  199. package/dist/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
  200. package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
  201. package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
  202. package/dist/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
  203. package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
  204. package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
  205. package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
  206. package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
  207. package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
  208. package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
  209. package/dist/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
  210. package/dist/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
  211. package/dist/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
  212. package/dist/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
  213. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
  214. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
  215. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
  216. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
  217. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
  218. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
  219. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
  220. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  221. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
  222. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
  223. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
  224. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
  225. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
  226. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
  227. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  228. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
  229. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
  230. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
  231. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
  232. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
  233. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
  234. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
  235. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  236. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
  237. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
  238. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
  239. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  240. package/dist/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
  241. package/dist/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
  242. package/dist/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
  243. package/dist/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
  244. package/dist/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
  245. package/dist/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
  246. package/dist/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
  247. package/dist/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
  248. package/dist/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
  249. package/dist/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
  250. package/dist/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
  251. package/dist/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
  252. package/dist/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
  253. package/dist/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
  254. package/dist/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
  255. package/dist/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
  256. package/dist/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
  257. package/dist/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
  258. package/dist/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
  259. package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
  260. package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
  261. package/dist/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
  262. package/dist/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
  263. package/dist/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
  264. package/dist/vendor/pdfjs/cmaps/GB-H.bcmap +6 -0
  265. package/dist/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
  266. package/dist/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
  267. package/dist/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
  268. package/dist/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
  269. package/dist/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
  270. package/dist/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
  271. package/dist/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
  272. package/dist/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
  273. package/dist/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
  274. package/dist/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
  275. package/dist/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
  276. package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
  277. package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
  278. package/dist/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
  279. package/dist/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
  280. package/dist/vendor/pdfjs/cmaps/H.bcmap +0 -0
  281. package/dist/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
  282. package/dist/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
  283. package/dist/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
  284. package/dist/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
  285. package/dist/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
  286. package/dist/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
  287. package/dist/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
  288. package/dist/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
  289. package/dist/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
  290. package/dist/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
  291. package/dist/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
  292. package/dist/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
  293. package/dist/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
  294. package/dist/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
  295. package/dist/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
  296. package/dist/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
  297. package/dist/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
  298. package/dist/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
  299. package/dist/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
  300. package/dist/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
  301. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
  302. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  303. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  304. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
  305. package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
  306. package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
  307. package/dist/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
  308. package/dist/vendor/pdfjs/cmaps/LICENSE +36 -0
  309. package/dist/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
  310. package/dist/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
  311. package/dist/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
  312. package/dist/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
  313. package/dist/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
  314. package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  315. package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  316. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  317. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  318. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  319. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  320. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  321. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  322. package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
  323. package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
  324. package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
  325. package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
  326. package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
  327. package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
  328. package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
  329. package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
  330. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  331. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  332. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  333. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  334. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  335. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  336. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  337. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  338. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  339. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  340. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  341. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  342. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  343. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  344. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  345. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  346. package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  347. package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  348. package/dist/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  349. package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  350. package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  351. package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  352. package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  353. package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
  354. package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
  355. package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
  356. package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
  357. package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
  358. package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
  359. package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
  360. package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
  361. package/dist/vendor/pdfjs/cmaps/V.bcmap +0 -0
  362. package/dist/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
  363. package/dist/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
  364. package/dist/vendor/pdfjs/iccs/LICENSE +116 -0
  365. package/dist/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  366. package/dist/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  367. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  368. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  369. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  370. package/dist/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  371. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  372. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  373. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  374. package/dist/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  375. package/dist/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  376. package/dist/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  377. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  378. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  379. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  380. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  381. package/dist/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  382. package/dist/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  383. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  384. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  385. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  386. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QUICKJS +21 -0
  387. package/dist/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
  388. package/dist/vendor/pdfjs/wasm/LICENSE_QUICKJS +22 -0
  389. package/dist/vendor/pdfjs/wasm/jbig2.wasm +0 -0
  390. package/dist/vendor/pdfjs/wasm/jbig2.wasm.br +0 -0
  391. package/dist/vendor/pdfjs/wasm/jbig2.wasm.gz +0 -0
  392. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +2 -0
  393. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.br +0 -0
  394. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.gz +0 -0
  395. package/dist/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
  396. package/dist/vendor/pdfjs/wasm/openjpeg.wasm.br +0 -0
  397. package/dist/vendor/pdfjs/wasm/openjpeg.wasm.gz +0 -0
  398. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +2 -0
  399. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.br +0 -0
  400. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.gz +0 -0
  401. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
  402. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.br +0 -0
  403. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.gz +0 -0
  404. package/dist/vendor/pdfjs/wasm/quickjs-eval.js +16 -0
  405. package/dist/vendor/pdfjs/wasm/quickjs-eval.js.br +0 -0
  406. package/dist/vendor/pdfjs/wasm/quickjs-eval.js.gz +0 -0
  407. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm +0 -0
  408. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.br +0 -0
  409. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.gz +0 -0
  410. package/package.json +6 -7
  411. package/scripts/start.ts +21 -4
  412. package/shared/constants/binary-extensions.ts +20 -4
  413. package/shared/constants/support.test.ts +27 -0
  414. package/shared/constants/support.ts +79 -0
  415. package/shared/constants/tool-icons.ts +7 -1
  416. package/shared/types/database/schema.ts +6 -0
  417. package/shared/types/git-hosting.ts +241 -0
  418. package/shared/types/integrations.ts +51 -1
  419. package/shared/types/mentions.ts +96 -0
  420. package/shared/types/release-notes.ts +31 -0
  421. package/shared/types/storage.ts +175 -0
  422. package/shared/types/stores/settings.ts +16 -0
  423. package/shared/types/unified/index.ts +1 -0
  424. package/shared/types/unified/message.ts +26 -1
  425. package/shared/types/unified/tool.ts +4 -0
  426. package/shared/types/work.ts +6 -0
  427. package/shared/utils/attachment-mentions.test.ts +39 -0
  428. package/shared/utils/attachment-mentions.ts +100 -0
  429. package/shared/utils/context-document.test.ts +53 -0
  430. package/shared/utils/context-document.ts +226 -0
  431. package/shared/utils/device-frame.test.ts +73 -0
  432. package/shared/utils/device-frame.ts +320 -0
  433. package/shared/utils/fuzzy.ts +79 -0
  434. package/shared/utils/launcher-fingerprint.test.ts +73 -0
  435. package/shared/utils/launcher-fingerprint.ts +108 -0
  436. package/shared/utils/logger.ts +2 -0
  437. package/shared/utils/page-colors.test.ts +17 -0
  438. package/shared/utils/page-colors.ts +24 -0
  439. package/shared/utils/process-supervisor.test.ts +18 -1
  440. package/shared/utils/process-supervisor.ts +12 -23
  441. package/shared/utils/restart-intent.test.ts +57 -0
  442. package/shared/utils/restart-intent.ts +80 -0
  443. package/shared/utils/semver.test.ts +33 -0
  444. package/shared/utils/semver.ts +35 -0
  445. package/shared/utils/supervised-child.ts +44 -0
  446. package/shared/utils/supervisor-protocol.ts +20 -0
  447. package/.env.example +0 -9
  448. package/dist/assets/index-By6KdSLT.js.br +0 -0
  449. package/dist/assets/index-By6KdSLT.js.gz +0 -0
  450. package/dist/assets/index-DV4TiDn1.js.br +0 -0
  451. package/dist/assets/index-DV4TiDn1.js.gz +0 -0
  452. package/dist/assets/main-DIESTGTD.css +0 -1
  453. package/dist/assets/main-DIESTGTD.css.br +0 -0
  454. package/dist/assets/main-DIESTGTD.css.gz +0 -0
  455. package/dist/assets/main-Da3JKoua.js +0 -1240
  456. package/dist/assets/main-Da3JKoua.js.br +0 -0
  457. package/dist/assets/main-Da3JKoua.js.gz +0 -0
@@ -0,0 +1,196 @@
1
+ /**
2
+ * Migrations either happen completely or not at all, so a start that is
3
+ * interrupted halfway — a crash, Ctrl+C, a restart from the UI — leaves a
4
+ * schema the next start can still migrate.
5
+ */
6
+
7
+ import { describe, expect, test } from 'bun:test';
8
+ import { Database } from 'bun:sqlite';
9
+ import { readdirSync, readFileSync } from 'node:fs';
10
+ import { join } from 'node:path';
11
+ import type { DatabaseConnection } from '$shared/types/database/connection';
12
+ import { MigrationRunner, type Migration } from './migration-runner';
13
+ import { migrations } from '../migrations';
14
+
15
+ /** As production opens it (backend/database/utils/connection.ts). */
16
+ function freshDb(): Database {
17
+ const db = new Database(':memory:');
18
+ db.exec('PRAGMA foreign_keys = ON');
19
+ return db;
20
+ }
21
+
22
+ function runner(db: Database, list: Migration[]): MigrationRunner {
23
+ const migrationRunner = new MigrationRunner(db as unknown as DatabaseConnection);
24
+ for (const migration of list) migrationRunner.addMigration(migration);
25
+ return migrationRunner;
26
+ }
27
+
28
+ function tableExists(db: Database, name: string): boolean {
29
+ return !!db.query(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = ?`).get(name);
30
+ }
31
+
32
+ describe('MigrationRunner', () => {
33
+ test('every migration runs on an empty database', async () => {
34
+ const db = freshDb();
35
+ const migrationRunner = runner(db, migrations as Migration[]);
36
+ await migrationRunner.runMigrations();
37
+ expect(migrationRunner.getPendingMigrations()).toEqual([]);
38
+ });
39
+
40
+ test('a migration that fails halfway leaves nothing behind, and runs again next time', async () => {
41
+ const db = freshDb();
42
+ let fail = true;
43
+ const migration: Migration = {
44
+ id: '001',
45
+ description: 'two steps',
46
+ up: (conn) => {
47
+ conn.exec('CREATE TABLE first_step (id TEXT)');
48
+ if (fail) throw new Error('interrupted');
49
+ conn.exec('CREATE TABLE second_step (id TEXT)');
50
+ },
51
+ down: () => {}
52
+ };
53
+
54
+ await expect(runner(db, [migration]).runMigrations()).rejects.toThrow('interrupted');
55
+ expect(tableExists(db, 'first_step')).toBe(false);
56
+ expect(runner(db, [migration]).getExecutedMigrations()).toEqual([]);
57
+
58
+ fail = false;
59
+ await runner(db, [migration]).runMigrations();
60
+ expect(tableExists(db, 'first_step')).toBe(true);
61
+ expect(tableExists(db, 'second_step')).toBe(true);
62
+ expect(runner(db, [migration]).getExecutedMigrations()).toEqual(['001']);
63
+ });
64
+
65
+ test('a table rebuild with foreignKeysOff keeps the rows that reference the table', async () => {
66
+ const seeded = () => {
67
+ const db = freshDb();
68
+ db.exec('CREATE TABLE parent (id TEXT PRIMARY KEY, kind TEXT)');
69
+ db.exec('CREATE TABLE child (id TEXT PRIMARY KEY, parent_id TEXT REFERENCES parent(id) ON DELETE CASCADE)');
70
+ db.exec(`INSERT INTO parent VALUES ('p1', 'a')`);
71
+ db.exec(`INSERT INTO child VALUES ('c1', 'p1')`);
72
+ return db;
73
+ };
74
+
75
+ const rebuild = (foreignKeysOff: boolean): Migration => ({
76
+ id: '001',
77
+ description: 'rebuild parent',
78
+ foreignKeysOff,
79
+ up: (conn) => {
80
+ conn.exec('CREATE TABLE parent_new (id TEXT PRIMARY KEY, kind TEXT NOT NULL)');
81
+ conn.exec('INSERT INTO parent_new SELECT id, kind FROM parent');
82
+ conn.exec('DROP TABLE parent');
83
+ conn.exec('ALTER TABLE parent_new RENAME TO parent');
84
+ },
85
+ down: () => {}
86
+ });
87
+
88
+ // Why the flag exists: with foreign keys on, dropping the old table
89
+ // cascade-deletes the children.
90
+ const unsafe = seeded();
91
+ await runner(unsafe, [rebuild(false)]).runMigrations();
92
+ expect(unsafe.query('SELECT id FROM child').all()).toEqual([]);
93
+
94
+ const db = seeded();
95
+ await runner(db, [rebuild(true)]).runMigrations();
96
+ expect(db.query('SELECT id FROM child').all()).toEqual([{ id: 'c1' }]);
97
+ // And foreign keys are enforced again afterwards.
98
+ expect((db.query('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys).toBe(1);
99
+ });
100
+
101
+ test('a rebuild that fails with foreignKeysOff rolls back and turns foreign keys back on', async () => {
102
+ const db = freshDb();
103
+ const migration: Migration = {
104
+ id: '001',
105
+ description: 'fails',
106
+ foreignKeysOff: true,
107
+ up: (conn) => {
108
+ conn.exec('CREATE TABLE half (id TEXT)');
109
+ throw new Error('interrupted');
110
+ },
111
+ down: () => {}
112
+ };
113
+ await expect(runner(db, [migration]).runMigrations()).rejects.toThrow('interrupted');
114
+ expect(tableExists(db, 'half')).toBe(false);
115
+ expect((db.query('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys).toBe(1);
116
+ });
117
+ });
118
+
119
+ describe('migration sources', () => {
120
+ const dir = join(import.meta.dir, '../migrations');
121
+ const files = readdirSync(dir).filter(file => /^\d{3}_.*\.ts$/.test(file) && !file.endsWith('.test.ts'));
122
+
123
+ const TURNS_OFF_FOREIGN_KEYS = /PRAGMA\s+foreign_keys\s*=\s*OFF/i;
124
+ const OPENS_TRANSACTION = /exec\(\s*['"`]\s*(BEGIN|COMMIT|ROLLBACK)\b/i;
125
+
126
+ test.each(files)('%s declares foreignKeysOff exactly when its SQL turns them off', (file) => {
127
+ const source = readFileSync(join(dir, file), 'utf-8');
128
+ const entry = (migrations as Migration[]).find(migration => migration.id === file.slice(0, 3));
129
+ expect(entry).toBeDefined();
130
+ expect(!!entry!.foreignKeysOff).toBe(TURNS_OFF_FOREIGN_KEYS.test(source));
131
+ });
132
+
133
+ test.each(files)('%s leaves the transaction to the runner', (file) => {
134
+ // A migration's own BEGIN fails inside the runner's, and its own COMMIT
135
+ // would separate the change from its record again.
136
+ expect(OPENS_TRANSACTION.test(readFileSync(join(dir, file), 'utf-8'))).toBe(false);
137
+ });
138
+ });
139
+
140
+ /**
141
+ * The migrations that did not use to be wrapped, run over data rather than an
142
+ * empty database: the rebuild in 056 must keep the rows that cascade from the
143
+ * table it rebuilds, and 086 must still reduce two accounts to the owner.
144
+ */
145
+ describe('existing migrations over data', () => {
146
+ async function migratedTo(lastBefore: string): Promise<Database> {
147
+ const db = freshDb();
148
+ await runner(db, (migrations as Migration[]).filter(migration => migration.id < lastBefore)).runMigrations();
149
+ return db;
150
+ }
151
+
152
+ /** Insert a row, filling the NOT NULL columns the test does not care about. */
153
+ function insert(db: Database, table: string, values: Record<string, string | null>): void {
154
+ const columns = db.query(`PRAGMA table_info(${table})`).all() as { name: string; notnull: number; dflt_value: unknown; pk: number }[];
155
+ const row: Record<string, string | null> = { ...values };
156
+ for (const column of columns) {
157
+ if (!column.notnull || column.dflt_value !== null || column.pk || column.name in row) continue;
158
+ row[column.name] = column.name.endsWith('_at') ? new Date().toISOString() : `${table}-${column.name}`;
159
+ }
160
+ const keys = Object.keys(row);
161
+ db.prepare(`INSERT INTO ${table} (${keys.join(', ')}) VALUES (${keys.map(() => '?').join(', ')})`).run(...keys.map(key => row[key]));
162
+ }
163
+
164
+ async function migrateRest(db: Database): Promise<void> {
165
+ const migrationRunner = runner(db, migrations as Migration[]);
166
+ await migrationRunner.runMigrations();
167
+ expect(migrationRunner.getPendingMigrations()).toEqual([]);
168
+ expect((db.query('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys).toBe(1);
169
+ expect(db.query('PRAGMA foreign_key_check').all()).toEqual([]);
170
+ }
171
+
172
+ test('056 keeps the query history of the connection table it rebuilds', async () => {
173
+ const db = await migratedTo('056');
174
+ insert(db, 'db_client_connections', { id: 'c1', name: 'pg', driver: 'postgres' });
175
+ insert(db, 'db_client_query_history', { id: 'h1', connection_id: 'c1', status: 'success' });
176
+
177
+ await migrateRest(db);
178
+ expect(db.query('SELECT id FROM db_client_connections').all()).toEqual([{ id: 'c1' }]);
179
+ expect(db.query('SELECT id FROM db_client_query_history').all()).toEqual([{ id: 'h1' }]);
180
+ });
181
+
182
+ test('086 reduces two accounts to the owner and keeps the chats', async () => {
183
+ const db = await migratedTo('086');
184
+ insert(db, 'users', { id: 'owner', role: 'admin', created_at: '2020-01-01T00:00:00Z' });
185
+ insert(db, 'users', { id: 'member', role: 'member', created_at: '2021-01-01T00:00:00Z' });
186
+ insert(db, 'projects', { id: 'p1', name: 'Repo', path: '/tmp/clopen-migration-test-repo', kind: 'project', owner_user_id: null });
187
+ insert(db, 'chat_sessions', { id: 's1', project_id: 'p1' });
188
+ insert(db, 'auth_sessions', { id: 'a-member', user_id: 'member', token_hash: 'h-member' });
189
+ insert(db, 'auth_sessions', { id: 'a-owner', user_id: 'owner', token_hash: 'h-owner' });
190
+
191
+ await migrateRest(db);
192
+ expect(db.query('SELECT id FROM users').all()).toEqual([{ id: 'owner' }]);
193
+ expect(db.query('SELECT id FROM auth_sessions').all()).toEqual([{ id: 'a-owner' }]);
194
+ expect(db.query('SELECT id FROM chat_sessions').all()).toEqual([{ id: 's1' }]);
195
+ });
196
+ });
@@ -1,11 +1,58 @@
1
1
  import type { DatabaseConnection } from '$shared/types/database/connection';
2
2
 
3
3
  import { debug } from '$shared/utils/logger';
4
- interface Migration {
4
+
5
+ export interface Migration {
5
6
  id: string;
6
7
  description: string;
7
8
  up: (db: DatabaseConnection) => void;
8
9
  down: (db: DatabaseConnection) => void;
10
+ /**
11
+ * Run with foreign keys off, for a migration that rebuilds a table (SQLite
12
+ * cannot alter a constraint in place). Dropping the old table with foreign
13
+ * keys on would cascade-delete every row that references it. The pragma is
14
+ * a no-op inside a transaction, so the migration cannot switch it itself —
15
+ * the runner switches it before opening the transaction and back after,
16
+ * the order SQLite documents for a table rebuild. migration-runner.test.ts
17
+ * keeps this flag in agreement with each migration's SQL.
18
+ */
19
+ foreignKeysOff?: boolean;
20
+ }
21
+
22
+ /**
23
+ * Run `step` so that it either happens completely or not at all — a
24
+ * migration with its record, or a seeder with its record.
25
+ *
26
+ * A migration that stopped halfway — a crash, an error, Ctrl+C, a restart —
27
+ * used to leave its first statements applied and itself unrecorded, so the
28
+ * next start ran it again over a half-changed schema and failed for good
29
+ * ("table already exists"). Inside one transaction with its record, an
30
+ * interrupted migration simply has not happened, and the next start does it.
31
+ */
32
+ export function atomically(db: DatabaseConnection, step: () => void, options: { foreignKeysOff?: boolean } = {}): void {
33
+ // Put back what the connection had, rather than assume it was on.
34
+ const foreignKeysWere = options.foreignKeysOff
35
+ ? (db.prepare('PRAGMA foreign_keys').get() as { foreign_keys: number }).foreign_keys
36
+ : null;
37
+ if (foreignKeysWere !== null) db.exec('PRAGMA foreign_keys = OFF');
38
+ try {
39
+ db.exec('BEGIN IMMEDIATE');
40
+ try {
41
+ step();
42
+ db.exec('COMMIT');
43
+ } catch (error) {
44
+ // Some failures (a full disk) end the transaction themselves; the
45
+ // ROLLBACK then fails too, and must not hide the error that matters.
46
+ try {
47
+ db.exec('ROLLBACK');
48
+ } catch {
49
+ // Already rolled back.
50
+ }
51
+ throw error;
52
+ }
53
+ } finally {
54
+ if (foreignKeysWere !== null) db.exec(`PRAGMA foreign_keys = ${foreignKeysWere ? 'ON' : 'OFF'}`);
55
+ }
9
56
  }
10
57
 
11
58
  export class MigrationRunner {
@@ -51,14 +98,13 @@ export class MigrationRunner {
51
98
  debug.log('database', `📋 Running migration: ${migration.id} - ${migration.description}`);
52
99
 
53
100
  try {
54
- // Execute migration
55
- migration.up(this.db);
56
-
57
- // Record migration as executed
58
- this.db.prepare(`
59
- INSERT INTO migrations (id, description, executed_at)
60
- VALUES (?, ?, ?)
61
- `).run(migration.id, migration.description, new Date().toISOString());
101
+ atomically(this.db, () => {
102
+ migration.up(this.db);
103
+ this.db.prepare(`
104
+ INSERT INTO migrations (id, description, executed_at)
105
+ VALUES (?, ?, ?)
106
+ `).run(migration.id, migration.description, new Date().toISOString());
107
+ }, migration);
62
108
 
63
109
  executedCount++;
64
110
  debug.log('database', `✅ Migration ${migration.id} completed`);
@@ -85,13 +131,12 @@ export class MigrationRunner {
85
131
  }
86
132
 
87
133
  try {
88
- // Execute rollback
89
- migration.down(this.db);
90
-
91
- // Remove migration record
92
- this.db.prepare(`
93
- DELETE FROM migrations WHERE id = ?
94
- `).run(migrationId);
134
+ atomically(this.db, () => {
135
+ migration.down(this.db);
136
+ this.db.prepare(`
137
+ DELETE FROM migrations WHERE id = ?
138
+ `).run(migrationId);
139
+ }, migration);
95
140
 
96
141
  debug.log('database', `✅ Migration ${migrationId} rolled back successfully`);
97
142
  } catch (error) {
@@ -1,6 +1,8 @@
1
1
  import type { DatabaseConnection } from '$shared/types/database/connection';
2
2
 
3
3
  import { debug } from '$shared/utils/logger';
4
+ import { atomically } from './migration-runner';
5
+
4
6
  interface Seeder {
5
7
  name: string;
6
8
  description: string;
@@ -47,22 +49,26 @@ export class SeederRunner {
47
49
  debug.log('database', `🌱 Running seeder: ${seeder.name} - ${seeder.description}`);
48
50
 
49
51
  try {
50
- // Execute seeder
51
- seeder.seed(this.db);
52
-
53
- // Record seeder as executed (replace if force)
54
- if (force && executedNames.has(seeder.name)) {
55
- this.db.prepare(`
56
- UPDATE seeders
57
- SET description = ?, executed_at = ?
58
- WHERE name = ?
59
- `).run(seeder.description, new Date().toISOString(), seeder.name);
60
- } else {
61
- this.db.prepare(`
62
- INSERT OR REPLACE INTO seeders (name, description, executed_at)
63
- VALUES (?, ?, ?)
64
- `).run(seeder.name, seeder.description, new Date().toISOString());
65
- }
52
+ // The seeder and its record together, like a migration: an
53
+ // interrupted seeder must not leave half its rows behind and
54
+ // then run again on top of them.
55
+ atomically(this.db, () => {
56
+ seeder.seed(this.db);
57
+
58
+ // Record seeder as executed (replace if force)
59
+ if (force && executedNames.has(seeder.name)) {
60
+ this.db.prepare(`
61
+ UPDATE seeders
62
+ SET description = ?, executed_at = ?
63
+ WHERE name = ?
64
+ `).run(seeder.description, new Date().toISOString(), seeder.name);
65
+ } else {
66
+ this.db.prepare(`
67
+ INSERT OR REPLACE INTO seeders (name, description, executed_at)
68
+ VALUES (?, ?, ?)
69
+ `).run(seeder.name, seeder.description, new Date().toISOString());
70
+ }
71
+ });
66
72
 
67
73
  executedCount++;
68
74
  debug.log('database', `✅ Seeder ${seeder.name} completed`);
@@ -138,6 +138,7 @@ export class ClaudeCodeEngine implements AIEngine {
138
138
  projectPath,
139
139
  prompt,
140
140
  resume,
141
+ resumeAt,
141
142
  maxTurns = undefined,
142
143
  modelId,
143
144
  includePartialMessages = false,
@@ -333,6 +334,10 @@ export class ClaudeCodeEngine implements AIEngine {
333
334
  }),
334
335
  ...(modelId && { model: modelId }),
335
336
  ...(resume && { resume }),
337
+ // A deduplicated fork: `resume` holds this conversation and more, so it
338
+ // is cut where the original ended. forkSession stays on, so the cut is a
339
+ // new session and the shared transcript is never rewritten.
340
+ ...(resume && resumeAt && { resumeSessionAt: resumeAt }),
336
341
  ...(maxTurns && { maxTurns }),
337
342
  ...(includePartialMessages && { includePartialMessages }),
338
343
  forwardSubagentText: true,
@@ -23,7 +23,7 @@ export function getCursorStoreRoot(): string {
23
23
  }
24
24
 
25
25
  /** Per-project isolated store directory. */
26
- function getCursorStoreDir(projectPath: string): string {
26
+ export function getCursorStoreDir(projectPath: string): string {
27
27
  return join(getCursorStoreRoot(), projectPath.replace(/[^a-zA-Z0-9]/g, '-') || 'default');
28
28
  }
29
29
 
@@ -57,8 +57,17 @@ function resolveCliCwd(projectPath: string): string {
57
57
  }
58
58
  }
59
59
 
60
+ /**
61
+ * The directory the CLI keeps a cwd's chats in, for that exact cwd string —
62
+ * no symlink resolution, so a caller relocating a project's chats can name
63
+ * the old path after it is gone.
64
+ */
65
+ export function getQwenProjectDir(cwd: string): string {
66
+ return path.join(QWEN_PROJECTS_DIR, sanitizeCwd(cwd));
67
+ }
68
+
60
69
  function getSessionStatePath(projectPath: string, sessionId: string): string {
61
- return path.join(QWEN_PROJECTS_DIR, sanitizeCwd(resolveCliCwd(projectPath)), 'chats', `${sessionId}.jsonl`);
70
+ return path.join(getQwenProjectDir(resolveCliCwd(projectPath)), 'chats', `${sessionId}.jsonl`);
62
71
  }
63
72
 
64
73
  export function sessionStateExists(projectPath: string, sessionId: string): boolean {
@@ -29,6 +29,13 @@ export interface EngineQueryOptions {
29
29
  projectPath: string;
30
30
  prompt: UserMessage;
31
31
  resume?: string;
32
+ /**
33
+ * Cut the resumed session at this entry (Claude: `resumeSessionAt`). Set when
34
+ * `resume` is an alias target — the transcript the user is continuing was
35
+ * deduplicated into a later fork that holds it, and this is where it ended.
36
+ * Engines that cannot cut a session never receive one.
37
+ */
38
+ resumeAt?: string;
32
39
  forkSession?: boolean;
33
40
  maxTurns?: number;
34
41
  /** Provider slug (e.g. 'anthropic', 'openai'). Required for OpenCode. */
@@ -101,6 +101,8 @@ async function runCredentialHelper(argv: string[]): Promise<number> {
101
101
  const operation = argv.find((a) => !a.startsWith('--')) ?? 'get';
102
102
  if (operation !== 'get') return 0;
103
103
 
104
+ if (argv.includes('--hosted')) return runHostedCredentialHelper(argv);
105
+
104
106
  const identityId = identityIdFrom(argv);
105
107
  if (!identityId) return 0;
106
108
 
@@ -143,6 +145,39 @@ async function runCredentialHelper(argv: string[]): Promise<number> {
143
145
  return 0;
144
146
  }
145
147
 
148
+ /** `--project=<id>` out of the helper's own arguments. */
149
+ export function projectIdFrom(argv: string[]): string | null {
150
+ for (const arg of argv) {
151
+ if (arg.startsWith('--project=')) {
152
+ const value = arg.slice('--project='.length).trim();
153
+ if (value) return value;
154
+ }
155
+ }
156
+ return null;
157
+ }
158
+
159
+ /**
160
+ * Answer for a host a connected hosting account serves.
161
+ *
162
+ * Git sends the host and — because `useHttpPath` is set for these hosts — the
163
+ * repository path, so the account is chosen by the repository's owner exactly
164
+ * as the Git panel chooses it. Ambiguity answers nothing, same rule as above.
165
+ */
166
+ async function runHostedCredentialHelper(argv: string[]): Promise<number> {
167
+ const request = parseCredentialRequest(await readStdin());
168
+ if ((request.protocol ?? 'https') !== 'https') return 0;
169
+ const host = (request.host ?? '').toLowerCase().split(':')[0] ?? '';
170
+ if (!host) return 0;
171
+
172
+ await connectReadOnly();
173
+ const { answerHostedCredential } = await import('$backend/git-hosts/git-credential');
174
+ const answer = await answerHostedCredential(host, request.path ?? '', projectIdFrom(argv));
175
+ if (!answer) return 0;
176
+
177
+ process.stdout.write(`username=${answer.username}\npassword=${answer.password}\n`);
178
+ return 0;
179
+ }
180
+
146
181
  /**
147
182
  * Answer `ssh`'s passphrase prompt.
148
183
  *
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'bun:test';
2
2
  import { mkdtemp, rm } from 'node:fs/promises';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
- import { buildGitConfigPairs, buildGitIdentityEnv, remoteHost } from './env';
5
+ import { buildGitConfigPairs, buildGitIdentityEnv, buildHostedCredentialPairs, remoteHost } from './env';
6
6
 
7
7
  const helper = { runtime: '/usr/local/bin/bun', script: '/opt/clopen/index.js' };
8
8
 
@@ -212,3 +212,54 @@ describe('the env block against real git', () => {
212
212
  }
213
213
  });
214
214
  });
215
+
216
+ describe('buildHostedCredentialPairs', () => {
217
+ test('scopes a reset plus Clopen\'s helper to each served host, with the path sent', () => {
218
+ const pairs = buildHostedCredentialPairs(['gitlab.com', 'github.com', 'github.com'], 'proj-1', helper);
219
+ expect(pairs.filter(([key]) => key === 'credential.https://github.com.helper')).toHaveLength(2);
220
+ expect(pairs[0]).toEqual(['credential.https://github.com.helper', '']);
221
+ expect(pairs[1]![1]).toContain('git-credential --hosted');
222
+ expect(pairs[1]![1]).toContain("'--project=proj-1'");
223
+ expect(pairs).toContainEqual(['credential.https://gitlab.com.useHttpPath', 'true']);
224
+ });
225
+
226
+ test('no helper or no hosts means nothing — the machine keeps its own helpers', () => {
227
+ expect(buildHostedCredentialPairs(['github.com'], 'p')).toEqual([]);
228
+ expect(buildHostedCredentialPairs([], 'p', helper)).toEqual([]);
229
+ });
230
+
231
+ test('hosted pairs alone still produce an environment', () => {
232
+ const env = buildGitIdentityEnv(null, helper, buildHostedCredentialPairs(['github.com'], 'p', helper));
233
+ expect(pairsOf(env).some(([key]) => key === 'user.name')).toBe(false);
234
+ expect(Number(env.GIT_CONFIG_COUNT)).toBe(3);
235
+ });
236
+ });
237
+
238
+ describe('helper commands carry the data directory', () => {
239
+ // Git starts the helper with Clopen's cleaned environment, which has no
240
+ // NODE_ENV. Without the directory in the command, a dev or relocated
241
+ // instance's helper opened the default database and found no account.
242
+ const pinned = { ...helper, dataDir: '/home/user/.clopen-dev' };
243
+
244
+ test('the hosted helper is prefixed with CLOPEN_DATA_DIR', () => {
245
+ const [, command] = buildHostedCredentialPairs(['github.com'], 'p', pinned)[1]!;
246
+ expect(command.startsWith("!CLOPEN_DATA_DIR='/home/user/.clopen-dev' ")).toBe(true);
247
+ });
248
+
249
+ test('the identity helper is prefixed too', () => {
250
+ const pairs = buildGitConfigPairs(
251
+ { id: 'i', name: 'A', email: 'a@example.com', credentialHosts: ['github.com'], httpsUsername: 'a' },
252
+ pinned
253
+ );
254
+ const helperValue = pairs.filter(([key]) => key === 'credential.helper').map(([, value]) => value).find(Boolean);
255
+ expect(helperValue).toContain("CLOPEN_DATA_DIR='/home/user/.clopen-dev'");
256
+ });
257
+
258
+ test('a passphrase askpass gets the directory as a variable, since ssh runs it without a shell', () => {
259
+ const env = buildGitIdentityEnv(
260
+ { id: 'i', name: 'A', email: 'a@example.com', sshKeyPath: '/k', needsPassphrase: true },
261
+ pinned
262
+ );
263
+ expect(env.CLOPEN_DATA_DIR).toBe('/home/user/.clopen-dev');
264
+ });
265
+ });
@@ -48,6 +48,27 @@ export interface HelperCommand {
48
48
  runtime: string;
49
49
  /** The entry script (`Bun.main`). */
50
50
  script: string;
51
+ /**
52
+ * The data directory of the Clopen that wrote this command.
53
+ *
54
+ * Git runs the helper as a brand-new process with the environment Clopen
55
+ * spawned git with — and that environment is deliberately cleaned of
56
+ * `NODE_ENV`. Without the directory pinned here, a helper started for a
57
+ * development instance (`~/.clopen-dev`) or one with `CLOPEN_DATA_DIR` set
58
+ * opened the DEFAULT database, found no account, answered nothing, and git
59
+ * fell through to "could not read Username".
60
+ */
61
+ dataDir?: string;
62
+ }
63
+
64
+ /**
65
+ * The start of a helper command line: the data directory, then runtime and
66
+ * script. Git runs `!`-helpers through a POSIX shell, so a leading
67
+ * `NAME=value` sets the variable for that one command only.
68
+ */
69
+ function helperInvocation(helper: HelperCommand): string {
70
+ const parts = [shellQuote(helper.runtime), shellQuote(helper.script)];
71
+ return helper.dataDir ? `CLOPEN_DATA_DIR=${shellQuote(helper.dataDir)} ${parts.join(' ')}` : parts.join(' ');
51
72
  }
52
73
 
53
74
  /**
@@ -107,8 +128,7 @@ export function buildGitConfigPairs(
107
128
  // this through a shell (the `!` prefix), passes the request on stdin, and
108
129
  // reads the answer from stdout.
109
130
  const command = [
110
- shellQuote(helper.runtime),
111
- shellQuote(helper.script),
131
+ helperInvocation(helper),
112
132
  'git-credential',
113
133
  shellQuote(`--identity=${identity.id}`)
114
134
  ].join(' ');
@@ -127,18 +147,54 @@ export function buildGitConfigPairs(
127
147
  }
128
148
 
129
149
  /**
130
- * The environment fragment for an identity.
150
+ * Credential pairs for hosts served by a connected hosting account.
151
+ *
152
+ * Scoped per host (`credential.https://github.com.*`), so a host no account
153
+ * serves keeps the machine's own helpers untouched. For a host that IS served,
154
+ * the same reset-then-ours rule as above applies — otherwise the system
155
+ * keychain would answer first with whatever account it happens to hold.
131
156
  *
132
- * Returns `{}` for no identity so every caller can merge unconditionally and a
133
- * project without one behaves exactly as Clopen did before this feature.
157
+ * `useHttpPath` makes git send the repository path to the helper. That is what
158
+ * lets one helper choose between two accounts on the same host by the
159
+ * repository's owner, the way the Git panel does.
160
+ */
161
+ export function buildHostedCredentialPairs(
162
+ hosts: string[],
163
+ projectId: string,
164
+ helper?: HelperCommand
165
+ ): Array<[string, string]> {
166
+ if (!helper || hosts.length === 0) return [];
167
+ const command = [
168
+ helperInvocation(helper),
169
+ 'git-credential',
170
+ '--hosted',
171
+ shellQuote(`--project=${projectId}`)
172
+ ].join(' ');
173
+
174
+ const pairs: Array<[string, string]> = [];
175
+ for (const host of [...new Set(hosts)].sort()) {
176
+ pairs.push([`credential.https://${host}.helper`, '']);
177
+ pairs.push([`credential.https://${host}.helper`, `!${command}`]);
178
+ pairs.push([`credential.https://${host}.useHttpPath`, 'true']);
179
+ }
180
+ return pairs;
181
+ }
182
+
183
+ /**
184
+ * The environment fragment for an identity, plus any hosted-credential pairs.
185
+ *
186
+ * Returns `{}` when there is neither, so every caller can merge
187
+ * unconditionally and a project without them behaves exactly as Clopen did
188
+ * before this feature.
134
189
  */
135
190
  export function buildGitIdentityEnv(
136
191
  identity: GitEnvIdentity | null,
137
- helper?: HelperCommand
192
+ helper?: HelperCommand,
193
+ extraPairs: Array<[string, string]> = []
138
194
  ): Record<string, string> {
139
- if (!identity) return {};
195
+ if (!identity && extraPairs.length === 0) return {};
140
196
 
141
- const pairs = buildGitConfigPairs(identity, helper);
197
+ const pairs = [...(identity ? buildGitConfigPairs(identity, helper) : []), ...extraPairs];
142
198
  const env: Record<string, string> = { GIT_CONFIG_COUNT: String(pairs.length) };
143
199
 
144
200
  pairs.forEach(([key, value], index) => {
@@ -146,7 +202,7 @@ export function buildGitIdentityEnv(
146
202
  env[`GIT_CONFIG_VALUE_${index}`] = value;
147
203
  });
148
204
 
149
- if (identity.sshKeyPath && identity.needsPassphrase && helper) {
205
+ if (identity?.sshKeyPath && identity.needsPassphrase && helper) {
150
206
  // `ssh` only consults SSH_ASKPASS when it has no terminal to prompt on.
151
207
  // A PTY-backed shell HAS one, so without REQUIRE=force a passphrased key
152
208
  // would hang the terminal waiting for input git can never deliver.
@@ -157,13 +213,16 @@ export function buildGitIdentityEnv(
157
213
  shellQuote(`--identity=${identity.id}`)
158
214
  ].join(' ');
159
215
  env.SSH_ASKPASS = askpass;
216
+ // ssh runs the askpass program directly, not through a shell, so the
217
+ // data directory travels as a variable rather than a command prefix.
218
+ if (helper.dataDir) env.CLOPEN_DATA_DIR = helper.dataDir;
160
219
  env.SSH_ASKPASS_REQUIRE = 'force';
161
220
  // Older OpenSSH consults DISPLAY before SSH_ASKPASS. The value is never
162
221
  // connected to, it only has to be non-empty.
163
222
  env.DISPLAY = env.DISPLAY || ':0';
164
223
  }
165
224
 
166
- debug.log('git', `Git identity env built for ${identity.email} (${pairs.length} config pairs)`);
225
+ debug.log('git', `Git identity env built for ${identity?.email ?? 'hosted accounts only'} (${pairs.length} config pairs)`);
167
226
  return env;
168
227
  }
169
228