@myrialabs/clopen 0.4.49 → 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 (486) 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/background-wait.test.ts +28 -0
  5. package/backend/chat/engine-handoff.ts +42 -6
  6. package/backend/chat/message-pages.test.ts +17 -0
  7. package/backend/chat/message-pages.ts +6 -2
  8. package/backend/chat/stream-manager.ts +114 -19
  9. package/backend/containers/actions.ts +22 -0
  10. package/backend/control/actions/projects.ts +93 -37
  11. package/backend/control/folders.test.ts +27 -2
  12. package/backend/control/index.ts +2 -1
  13. package/backend/database/migrations/056_support_mssql_driver.ts +7 -0
  14. package/backend/database/migrations/077_create_integration_db_links.ts +7 -0
  15. package/backend/database/migrations/086_single_owner.ts +66 -73
  16. package/backend/database/migrations/088_create_messages_fts_map.ts +52 -0
  17. package/backend/database/migrations/089_add_memory_layout_tiles.ts +58 -0
  18. package/backend/database/migrations/090_create_storage_tables.ts +83 -0
  19. package/backend/database/migrations/index.ts +25 -2
  20. package/backend/database/queries/graph-queries.ts +392 -135
  21. package/backend/database/queries/integration-queries.ts +10 -0
  22. package/backend/database/queries/memory-queue-queries.ts +11 -0
  23. package/backend/database/queries/message-fts.test.ts +120 -0
  24. package/backend/database/queries/message-queries.ts +45 -9
  25. package/backend/database/queries/project-queries.ts +6 -0
  26. package/backend/database/queries/session-queries.ts +6 -2
  27. package/backend/database/queries/utils-queries.ts +3 -0
  28. package/backend/database/utils/migration-runner.test.ts +196 -0
  29. package/backend/database/utils/migration-runner.ts +61 -16
  30. package/backend/database/utils/seeder-runner.ts +22 -16
  31. package/backend/engine/adapters/claude/environment.ts +4 -0
  32. package/backend/engine/adapters/claude/input-gate.test.ts +59 -0
  33. package/backend/engine/adapters/claude/input-gate.ts +74 -0
  34. package/backend/engine/adapters/claude/message-converter.test.ts +16 -0
  35. package/backend/engine/adapters/claude/message-converter.ts +8 -0
  36. package/backend/engine/adapters/claude/stream.ts +20 -0
  37. package/backend/engine/adapters/cursor/environment.ts +1 -1
  38. package/backend/engine/adapters/qwen/session-store.ts +10 -1
  39. package/backend/engine/types.ts +7 -0
  40. package/backend/git/identity/cli.ts +35 -0
  41. package/backend/git/identity/env.test.ts +52 -1
  42. package/backend/git/identity/env.ts +69 -10
  43. package/backend/git/identity/index.ts +25 -6
  44. package/backend/git/identity/resolve.ts +2 -1
  45. package/backend/git/identity/scope-config.test.ts +7 -4
  46. package/backend/git/identity/scope-config.ts +13 -7
  47. package/backend/git-hosts/accounts.ts +106 -0
  48. package/backend/git-hosts/auth/client-ids.ts +34 -0
  49. package/backend/git-hosts/auth/connect.ts +110 -0
  50. package/backend/git-hosts/auth/endpoints.ts +130 -0
  51. package/backend/git-hosts/auth/flows.ts +355 -0
  52. package/backend/git-hosts/auth/local.ts +152 -0
  53. package/backend/git-hosts/ci.ts +18 -0
  54. package/backend/git-hosts/cli.test.ts +82 -0
  55. package/backend/git-hosts/cli.ts +342 -0
  56. package/backend/git-hosts/credentials.ts +173 -0
  57. package/backend/git-hosts/git-credential.ts +30 -0
  58. package/backend/git-hosts/health.ts +39 -0
  59. package/backend/git-hosts/http.ts +174 -0
  60. package/backend/git-hosts/index.ts +34 -0
  61. package/backend/git-hosts/providers/bitbucket.ts +186 -0
  62. package/backend/git-hosts/providers/gitea.ts +208 -0
  63. package/backend/git-hosts/providers/github.ts +270 -0
  64. package/backend/git-hosts/providers/gitlab-client.ts +70 -0
  65. package/backend/git-hosts/providers/gitlab.ts +285 -0
  66. package/backend/git-hosts/providers/locators.test.ts +68 -0
  67. package/backend/git-hosts/registry.ts +50 -0
  68. package/backend/git-hosts/service.ts +432 -0
  69. package/backend/git-hosts/types.ts +82 -0
  70. package/backend/git-hosts/urls.test.ts +42 -0
  71. package/backend/git-hosts/urls.ts +69 -0
  72. package/backend/index.ts +84 -17
  73. package/backend/integrations/accounts.ts +50 -3
  74. package/backend/integrations/registry/define.ts +9 -0
  75. package/backend/integrations/registry/index.ts +11 -0
  76. package/backend/integrations/registry/providers/bitbucket.ts +51 -0
  77. package/backend/integrations/registry/providers/gitea.ts +53 -0
  78. package/backend/integrations/registry/providers/github.ts +24 -7
  79. package/backend/integrations/registry/providers/gitlab.ts +57 -0
  80. package/backend/integrations/registry/types.ts +13 -1
  81. package/backend/mcp/internal/servers/browser-automation/actions/inspect.ts +115 -31
  82. package/backend/mcp/internal/servers/browser-automation/description.ts +5 -0
  83. package/backend/memory/README.md +7 -4
  84. package/backend/memory/layout.test.ts +377 -0
  85. package/backend/memory/layout.ts +1029 -265
  86. package/backend/memory/view.ts +257 -386
  87. package/backend/mentions/diff.ts +63 -0
  88. package/backend/mentions/index.ts +109 -0
  89. package/backend/mentions/mentions.test.ts +27 -0
  90. package/backend/mentions/shared.ts +82 -0
  91. package/backend/mentions/sources/ai-changes.ts +140 -0
  92. package/backend/mentions/sources/chats.ts +122 -0
  93. package/backend/mentions/sources/database.ts +211 -0
  94. package/backend/mentions/sources/files.ts +240 -0
  95. package/backend/mentions/sources/git.ts +308 -0
  96. package/backend/mentions/sources/notes-memory.ts +121 -0
  97. package/backend/mentions/sources/ops.ts +125 -0
  98. package/backend/mentions/sources/preview.ts +153 -0
  99. package/backend/mentions/sources/projects.ts +114 -0
  100. package/backend/mentions/sources/system.ts +135 -0
  101. package/backend/mentions/sources/terminal.ts +50 -0
  102. package/backend/mentions/types.ts +75 -0
  103. package/backend/preview/browser/bot-check-frames.test.ts +49 -0
  104. package/backend/preview/browser/bot-check-frames.ts +66 -0
  105. package/backend/preview/browser/browser-dialog-handler.ts +6 -5
  106. package/backend/preview/browser/browser-host-bridge.ts +4 -2
  107. package/backend/preview/browser/browser-native-ui-handler.ts +21 -0
  108. package/backend/preview/browser/browser-pool.ts +26 -17
  109. package/backend/preview/browser/browser-preview-service.ts +164 -2
  110. package/backend/preview/browser/browser-screenshot.test.ts +113 -0
  111. package/backend/preview/browser/browser-screenshot.ts +396 -0
  112. package/backend/preview/browser/browser-tab-manager.ts +35 -186
  113. package/backend/preview/browser/browser-video-capture.ts +12 -17
  114. package/backend/preview/browser/element-describe.ts +125 -0
  115. package/backend/preview/browser/page-binding.ts +141 -0
  116. package/backend/preview/browser/screenshot-files.test.ts +117 -0
  117. package/backend/preview/browser/screenshot-files.ts +134 -0
  118. package/backend/preview/browser/user-agent.test.ts +25 -0
  119. package/backend/preview/browser/user-agent.ts +100 -0
  120. package/backend/project/status-manager.ts +4 -2
  121. package/backend/projects/engine-transcripts.ts +153 -0
  122. package/backend/projects/folder-guard.ts +55 -0
  123. package/backend/projects/move.test.ts +208 -0
  124. package/backend/projects/move.ts +277 -0
  125. package/backend/projects/project-cleanup.integration.test.ts +3 -1
  126. package/backend/projects/project-cleanup.ts +10 -0
  127. package/backend/storage/actions.ts +260 -0
  128. package/backend/storage/chats.test.ts +57 -0
  129. package/backend/storage/chats.ts +170 -0
  130. package/backend/storage/database.ts +105 -0
  131. package/backend/storage/engine-homes.ts +145 -0
  132. package/backend/storage/fs-size.ts +111 -0
  133. package/backend/storage/history.ts +39 -0
  134. package/backend/storage/policy.ts +156 -0
  135. package/backend/storage/preview-profiles.ts +169 -0
  136. package/backend/storage/purge.ts +158 -0
  137. package/backend/storage/scanner.ts +339 -0
  138. package/backend/storage/session-index.ts +208 -0
  139. package/backend/storage/snapshots.ts +99 -0
  140. package/backend/storage/storage-flow.test.ts +137 -0
  141. package/backend/storage/transcripts/aliases.ts +75 -0
  142. package/backend/storage/transcripts/claude-dedupe.test.ts +101 -0
  143. package/backend/storage/transcripts/claude-dedupe.ts +152 -0
  144. package/backend/storage/transcripts/claude.ts +155 -0
  145. package/backend/storage/transcripts/cursor.ts +165 -0
  146. package/backend/storage/transcripts/file-stores.ts +224 -0
  147. package/backend/storage/transcripts/index.ts +207 -0
  148. package/backend/storage/transcripts/opencode.ts +124 -0
  149. package/backend/storage/transcripts/references.ts +42 -0
  150. package/backend/storage/transcripts/types.ts +58 -0
  151. package/backend/storage/worktrees.ts +114 -0
  152. package/backend/terminal/ptykit.ts +25 -0
  153. package/backend/update/registry.ts +24 -0
  154. package/backend/update/release-notes.test.ts +110 -0
  155. package/backend/update/release-notes.ts +132 -0
  156. package/backend/update/restart.ts +159 -0
  157. package/backend/utils/env.test.ts +64 -0
  158. package/backend/utils/env.ts +23 -55
  159. package/backend/utils/port-utils.ts +13 -0
  160. package/backend/work/index.ts +13 -2
  161. package/backend/work/providers/github/actions-logs.ts +1 -1
  162. package/backend/work/providers/github/adapter.ts +32 -1
  163. package/backend/work/providers/github/client.ts +7 -3
  164. package/backend/work/providers/gitlab/adapter.ts +770 -0
  165. package/backend/work/providers/gitlab/system-notes.test.ts +24 -0
  166. package/backend/work/service.ts +60 -36
  167. package/backend/work/start-work.ts +1 -1
  168. package/backend/work/types.ts +4 -0
  169. package/backend/worktrees/index.ts +1 -0
  170. package/backend/worktrees/service.ts +23 -2
  171. package/backend/ws/chat/composer.ts +47 -6
  172. package/backend/ws/chat/stream.ts +19 -10
  173. package/backend/ws/files/search.ts +1 -1
  174. package/backend/ws/files/write.ts +27 -0
  175. package/backend/ws/hosting/index.ts +231 -0
  176. package/backend/ws/index.ts +12 -2
  177. package/backend/ws/integrations/crud.ts +31 -5
  178. package/backend/ws/integrations/hosting-auth.ts +227 -0
  179. package/backend/ws/integrations/index.ts +2 -0
  180. package/backend/ws/memory/crud.ts +118 -81
  181. package/backend/ws/mentions/index.ts +81 -0
  182. package/backend/ws/messages/crud.ts +3 -1
  183. package/backend/ws/preview/browser/screenshot.ts +184 -0
  184. package/backend/ws/preview/index.ts +23 -0
  185. package/backend/ws/projects/crud.ts +66 -58
  186. package/backend/ws/sessions/crud.ts +7 -95
  187. package/backend/ws/snapshot/changes.ts +3 -3
  188. package/backend/ws/storage/index.ts +102 -0
  189. package/backend/ws/system/index.ts +7 -0
  190. package/backend/ws/system/operations.ts +125 -69
  191. package/backend/ws/work/context.ts +3 -4
  192. package/backend/ws/work/crud.ts +33 -0
  193. package/backend/ws/work/schemas.ts +4 -1
  194. package/bin/clopen.ts +18 -18
  195. package/dist/assets/{index-DD0-3EWg.js → index-B9rHDvjg.js} +1 -1
  196. package/dist/assets/index-B9rHDvjg.js.br +0 -0
  197. package/dist/assets/index-B9rHDvjg.js.gz +0 -0
  198. package/dist/assets/{index-CrVWZH_D.js → index-DFlwOd7k.js} +1 -1
  199. package/dist/assets/index-DFlwOd7k.js.br +0 -0
  200. package/dist/assets/index-DFlwOd7k.js.gz +0 -0
  201. package/dist/assets/main-Bz_brxxS.css +1 -0
  202. package/dist/assets/main-Bz_brxxS.css.br +0 -0
  203. package/dist/assets/main-Bz_brxxS.css.gz +0 -0
  204. package/dist/assets/main-DRcX9SHx.js +1273 -0
  205. package/dist/assets/main-DRcX9SHx.js.br +0 -0
  206. package/dist/assets/main-DRcX9SHx.js.gz +0 -0
  207. package/dist/assets/pdf-DfwfQPLy.js +57 -0
  208. package/dist/assets/pdf-DfwfQPLy.js.br +0 -0
  209. package/dist/assets/pdf-DfwfQPLy.js.gz +0 -0
  210. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs +27 -0
  211. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.br +0 -0
  212. package/dist/assets/pdf.worker.min-B5Yc7dP4.mjs.gz +0 -0
  213. package/dist/assets/pdf.worker.min-BOrSNwfp.js +1 -0
  214. package/dist/index.html +2 -2
  215. package/dist/index.html.br +0 -0
  216. package/dist/index.html.gz +0 -0
  217. package/dist/vendor/pdfjs/cmaps/78-EUC-H.bcmap +0 -0
  218. package/dist/vendor/pdfjs/cmaps/78-EUC-V.bcmap +0 -0
  219. package/dist/vendor/pdfjs/cmaps/78-H.bcmap +0 -0
  220. package/dist/vendor/pdfjs/cmaps/78-RKSJ-H.bcmap +0 -0
  221. package/dist/vendor/pdfjs/cmaps/78-RKSJ-V.bcmap +0 -0
  222. package/dist/vendor/pdfjs/cmaps/78-V.bcmap +0 -0
  223. package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-H.bcmap +0 -0
  224. package/dist/vendor/pdfjs/cmaps/78ms-RKSJ-V.bcmap +0 -0
  225. package/dist/vendor/pdfjs/cmaps/83pv-RKSJ-H.bcmap +0 -0
  226. package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-H.bcmap +0 -0
  227. package/dist/vendor/pdfjs/cmaps/90ms-RKSJ-V.bcmap +0 -0
  228. package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-H.bcmap +0 -0
  229. package/dist/vendor/pdfjs/cmaps/90msp-RKSJ-V.bcmap +0 -0
  230. package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-H.bcmap +0 -0
  231. package/dist/vendor/pdfjs/cmaps/90pv-RKSJ-V.bcmap +0 -0
  232. package/dist/vendor/pdfjs/cmaps/Add-H.bcmap +0 -0
  233. package/dist/vendor/pdfjs/cmaps/Add-RKSJ-H.bcmap +0 -0
  234. package/dist/vendor/pdfjs/cmaps/Add-RKSJ-V.bcmap +0 -0
  235. package/dist/vendor/pdfjs/cmaps/Add-V.bcmap +0 -0
  236. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-0.bcmap +0 -0
  237. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-1.bcmap +0 -0
  238. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-2.bcmap +0 -0
  239. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-3.bcmap +0 -0
  240. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-4.bcmap +0 -0
  241. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-5.bcmap +0 -0
  242. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-6.bcmap +0 -0
  243. package/dist/vendor/pdfjs/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  244. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-0.bcmap +0 -0
  245. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-1.bcmap +0 -0
  246. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-2.bcmap +0 -0
  247. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-3.bcmap +0 -0
  248. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-4.bcmap +0 -0
  249. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-5.bcmap +0 -0
  250. package/dist/vendor/pdfjs/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  251. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-0.bcmap +0 -0
  252. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-1.bcmap +0 -0
  253. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-2.bcmap +0 -0
  254. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-3.bcmap +0 -0
  255. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-4.bcmap +0 -0
  256. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-5.bcmap +0 -0
  257. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-6.bcmap +0 -0
  258. package/dist/vendor/pdfjs/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  259. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-0.bcmap +0 -0
  260. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-1.bcmap +0 -0
  261. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-2.bcmap +0 -0
  262. package/dist/vendor/pdfjs/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  263. package/dist/vendor/pdfjs/cmaps/B5-H.bcmap +0 -0
  264. package/dist/vendor/pdfjs/cmaps/B5-V.bcmap +0 -0
  265. package/dist/vendor/pdfjs/cmaps/B5pc-H.bcmap +0 -0
  266. package/dist/vendor/pdfjs/cmaps/B5pc-V.bcmap +0 -0
  267. package/dist/vendor/pdfjs/cmaps/CNS-EUC-H.bcmap +0 -0
  268. package/dist/vendor/pdfjs/cmaps/CNS-EUC-V.bcmap +0 -0
  269. package/dist/vendor/pdfjs/cmaps/CNS1-H.bcmap +0 -0
  270. package/dist/vendor/pdfjs/cmaps/CNS1-V.bcmap +0 -0
  271. package/dist/vendor/pdfjs/cmaps/CNS2-H.bcmap +0 -0
  272. package/dist/vendor/pdfjs/cmaps/CNS2-V.bcmap +3 -0
  273. package/dist/vendor/pdfjs/cmaps/ETHK-B5-H.bcmap +0 -0
  274. package/dist/vendor/pdfjs/cmaps/ETHK-B5-V.bcmap +0 -0
  275. package/dist/vendor/pdfjs/cmaps/ETen-B5-H.bcmap +0 -0
  276. package/dist/vendor/pdfjs/cmaps/ETen-B5-V.bcmap +0 -0
  277. package/dist/vendor/pdfjs/cmaps/ETenms-B5-H.bcmap +3 -0
  278. package/dist/vendor/pdfjs/cmaps/ETenms-B5-V.bcmap +0 -0
  279. package/dist/vendor/pdfjs/cmaps/EUC-H.bcmap +0 -0
  280. package/dist/vendor/pdfjs/cmaps/EUC-V.bcmap +0 -0
  281. package/dist/vendor/pdfjs/cmaps/Ext-H.bcmap +0 -0
  282. package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-H.bcmap +0 -0
  283. package/dist/vendor/pdfjs/cmaps/Ext-RKSJ-V.bcmap +0 -0
  284. package/dist/vendor/pdfjs/cmaps/Ext-V.bcmap +0 -0
  285. package/dist/vendor/pdfjs/cmaps/GB-EUC-H.bcmap +0 -0
  286. package/dist/vendor/pdfjs/cmaps/GB-EUC-V.bcmap +0 -0
  287. package/dist/vendor/pdfjs/cmaps/GB-H.bcmap +6 -0
  288. package/dist/vendor/pdfjs/cmaps/GB-V.bcmap +0 -0
  289. package/dist/vendor/pdfjs/cmaps/GBK-EUC-H.bcmap +0 -0
  290. package/dist/vendor/pdfjs/cmaps/GBK-EUC-V.bcmap +0 -0
  291. package/dist/vendor/pdfjs/cmaps/GBK2K-H.bcmap +0 -0
  292. package/dist/vendor/pdfjs/cmaps/GBK2K-V.bcmap +0 -0
  293. package/dist/vendor/pdfjs/cmaps/GBKp-EUC-H.bcmap +0 -0
  294. package/dist/vendor/pdfjs/cmaps/GBKp-EUC-V.bcmap +0 -0
  295. package/dist/vendor/pdfjs/cmaps/GBT-EUC-H.bcmap +0 -0
  296. package/dist/vendor/pdfjs/cmaps/GBT-EUC-V.bcmap +0 -0
  297. package/dist/vendor/pdfjs/cmaps/GBT-H.bcmap +0 -0
  298. package/dist/vendor/pdfjs/cmaps/GBT-V.bcmap +0 -0
  299. package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-H.bcmap +0 -0
  300. package/dist/vendor/pdfjs/cmaps/GBTpc-EUC-V.bcmap +0 -0
  301. package/dist/vendor/pdfjs/cmaps/GBpc-EUC-H.bcmap +0 -0
  302. package/dist/vendor/pdfjs/cmaps/GBpc-EUC-V.bcmap +0 -0
  303. package/dist/vendor/pdfjs/cmaps/H.bcmap +0 -0
  304. package/dist/vendor/pdfjs/cmaps/HKdla-B5-H.bcmap +0 -0
  305. package/dist/vendor/pdfjs/cmaps/HKdla-B5-V.bcmap +0 -0
  306. package/dist/vendor/pdfjs/cmaps/HKdlb-B5-H.bcmap +0 -0
  307. package/dist/vendor/pdfjs/cmaps/HKdlb-B5-V.bcmap +0 -0
  308. package/dist/vendor/pdfjs/cmaps/HKgccs-B5-H.bcmap +0 -0
  309. package/dist/vendor/pdfjs/cmaps/HKgccs-B5-V.bcmap +0 -0
  310. package/dist/vendor/pdfjs/cmaps/HKm314-B5-H.bcmap +0 -0
  311. package/dist/vendor/pdfjs/cmaps/HKm314-B5-V.bcmap +0 -0
  312. package/dist/vendor/pdfjs/cmaps/HKm471-B5-H.bcmap +0 -0
  313. package/dist/vendor/pdfjs/cmaps/HKm471-B5-V.bcmap +0 -0
  314. package/dist/vendor/pdfjs/cmaps/HKscs-B5-H.bcmap +0 -0
  315. package/dist/vendor/pdfjs/cmaps/HKscs-B5-V.bcmap +0 -0
  316. package/dist/vendor/pdfjs/cmaps/Hankaku.bcmap +0 -0
  317. package/dist/vendor/pdfjs/cmaps/Hiragana.bcmap +0 -0
  318. package/dist/vendor/pdfjs/cmaps/KSC-EUC-H.bcmap +0 -0
  319. package/dist/vendor/pdfjs/cmaps/KSC-EUC-V.bcmap +0 -0
  320. package/dist/vendor/pdfjs/cmaps/KSC-H.bcmap +0 -0
  321. package/dist/vendor/pdfjs/cmaps/KSC-Johab-H.bcmap +0 -0
  322. package/dist/vendor/pdfjs/cmaps/KSC-Johab-V.bcmap +0 -0
  323. package/dist/vendor/pdfjs/cmaps/KSC-V.bcmap +0 -0
  324. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-H.bcmap +0 -0
  325. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  326. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  327. package/dist/vendor/pdfjs/cmaps/KSCms-UHC-V.bcmap +0 -0
  328. package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-H.bcmap +0 -0
  329. package/dist/vendor/pdfjs/cmaps/KSCpc-EUC-V.bcmap +0 -0
  330. package/dist/vendor/pdfjs/cmaps/Katakana.bcmap +0 -0
  331. package/dist/vendor/pdfjs/cmaps/LICENSE +36 -0
  332. package/dist/vendor/pdfjs/cmaps/NWP-H.bcmap +0 -0
  333. package/dist/vendor/pdfjs/cmaps/NWP-V.bcmap +0 -0
  334. package/dist/vendor/pdfjs/cmaps/RKSJ-H.bcmap +0 -0
  335. package/dist/vendor/pdfjs/cmaps/RKSJ-V.bcmap +0 -0
  336. package/dist/vendor/pdfjs/cmaps/Roman.bcmap +0 -0
  337. package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  338. package/dist/vendor/pdfjs/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  339. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  340. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  341. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  342. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  343. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  344. package/dist/vendor/pdfjs/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  345. package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-H.bcmap +0 -0
  346. package/dist/vendor/pdfjs/cmaps/UniGB-UCS2-V.bcmap +0 -0
  347. package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-H.bcmap +0 -0
  348. package/dist/vendor/pdfjs/cmaps/UniGB-UTF16-V.bcmap +0 -0
  349. package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-H.bcmap +0 -0
  350. package/dist/vendor/pdfjs/cmaps/UniGB-UTF32-V.bcmap +0 -0
  351. package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-H.bcmap +0 -0
  352. package/dist/vendor/pdfjs/cmaps/UniGB-UTF8-V.bcmap +0 -0
  353. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  354. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  355. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  356. package/dist/vendor/pdfjs/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  357. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  358. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  359. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  360. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  361. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  362. package/dist/vendor/pdfjs/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  363. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  364. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  365. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  366. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  367. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  368. package/dist/vendor/pdfjs/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  369. package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  370. package/dist/vendor/pdfjs/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  371. package/dist/vendor/pdfjs/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  372. package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  373. package/dist/vendor/pdfjs/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  374. package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  375. package/dist/vendor/pdfjs/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  376. package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-H.bcmap +0 -0
  377. package/dist/vendor/pdfjs/cmaps/UniKS-UCS2-V.bcmap +0 -0
  378. package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-H.bcmap +0 -0
  379. package/dist/vendor/pdfjs/cmaps/UniKS-UTF16-V.bcmap +0 -0
  380. package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-H.bcmap +0 -0
  381. package/dist/vendor/pdfjs/cmaps/UniKS-UTF32-V.bcmap +0 -0
  382. package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-H.bcmap +0 -0
  383. package/dist/vendor/pdfjs/cmaps/UniKS-UTF8-V.bcmap +0 -0
  384. package/dist/vendor/pdfjs/cmaps/V.bcmap +0 -0
  385. package/dist/vendor/pdfjs/cmaps/WP-Symbol.bcmap +0 -0
  386. package/dist/vendor/pdfjs/iccs/CGATS001Compat-v2-micro.icc +0 -0
  387. package/dist/vendor/pdfjs/iccs/LICENSE +116 -0
  388. package/dist/vendor/pdfjs/standard_fonts/FoxitDingbats.pfb +0 -0
  389. package/dist/vendor/pdfjs/standard_fonts/FoxitFixed.pfb +0 -0
  390. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBold.pfb +0 -0
  391. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedBoldItalic.pfb +0 -0
  392. package/dist/vendor/pdfjs/standard_fonts/FoxitFixedItalic.pfb +0 -0
  393. package/dist/vendor/pdfjs/standard_fonts/FoxitSerif.pfb +0 -0
  394. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBold.pfb +0 -0
  395. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifBoldItalic.pfb +0 -0
  396. package/dist/vendor/pdfjs/standard_fonts/FoxitSerifItalic.pfb +0 -0
  397. package/dist/vendor/pdfjs/standard_fonts/FoxitSymbol.pfb +0 -0
  398. package/dist/vendor/pdfjs/standard_fonts/LICENSE_FOXIT +27 -0
  399. package/dist/vendor/pdfjs/standard_fonts/LICENSE_LIBERATION +363 -0
  400. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Bold.ttf +0 -0
  401. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-BoldItalic.ttf +0 -0
  402. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Italic.ttf +0 -0
  403. package/dist/vendor/pdfjs/standard_fonts/LiberationSans-Regular.ttf +0 -0
  404. package/dist/vendor/pdfjs/wasm/LICENSE_JBIG2 +196 -0
  405. package/dist/vendor/pdfjs/wasm/LICENSE_OPENJPEG +39 -0
  406. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_JBIG2 +13 -0
  407. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_OPENJPEG +22 -0
  408. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QCMS +19 -0
  409. package/dist/vendor/pdfjs/wasm/LICENSE_PDFJS_QUICKJS +21 -0
  410. package/dist/vendor/pdfjs/wasm/LICENSE_QCMS +21 -0
  411. package/dist/vendor/pdfjs/wasm/LICENSE_QUICKJS +22 -0
  412. package/dist/vendor/pdfjs/wasm/jbig2.wasm +0 -0
  413. package/dist/vendor/pdfjs/wasm/jbig2.wasm.br +0 -0
  414. package/dist/vendor/pdfjs/wasm/jbig2.wasm.gz +0 -0
  415. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js +2 -0
  416. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.br +0 -0
  417. package/dist/vendor/pdfjs/wasm/jbig2_nowasm_fallback.js.gz +0 -0
  418. package/dist/vendor/pdfjs/wasm/openjpeg.wasm +0 -0
  419. package/dist/vendor/pdfjs/wasm/openjpeg.wasm.br +0 -0
  420. package/dist/vendor/pdfjs/wasm/openjpeg.wasm.gz +0 -0
  421. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js +2 -0
  422. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.br +0 -0
  423. package/dist/vendor/pdfjs/wasm/openjpeg_nowasm_fallback.js.gz +0 -0
  424. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm +0 -0
  425. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.br +0 -0
  426. package/dist/vendor/pdfjs/wasm/qcms_bg.wasm.gz +0 -0
  427. package/dist/vendor/pdfjs/wasm/quickjs-eval.js +16 -0
  428. package/dist/vendor/pdfjs/wasm/quickjs-eval.js.br +0 -0
  429. package/dist/vendor/pdfjs/wasm/quickjs-eval.js.gz +0 -0
  430. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm +0 -0
  431. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.br +0 -0
  432. package/dist/vendor/pdfjs/wasm/quickjs-eval.wasm.gz +0 -0
  433. package/package.json +8 -9
  434. package/scripts/start.ts +21 -4
  435. package/shared/constants/binary-extensions.ts +20 -4
  436. package/shared/constants/support.test.ts +27 -0
  437. package/shared/constants/support.ts +79 -0
  438. package/shared/constants/tool-icons.ts +7 -1
  439. package/shared/types/database/schema.ts +6 -0
  440. package/shared/types/git-hosting.ts +241 -0
  441. package/shared/types/integrations.ts +51 -1
  442. package/shared/types/memory.ts +96 -73
  443. package/shared/types/mentions.ts +96 -0
  444. package/shared/types/release-notes.ts +31 -0
  445. package/shared/types/storage.ts +175 -0
  446. package/shared/types/stores/settings.ts +16 -0
  447. package/shared/types/unified/index.ts +2 -0
  448. package/shared/types/unified/message.ts +26 -1
  449. package/shared/types/unified/stream.ts +22 -1
  450. package/shared/types/unified/tool.ts +4 -0
  451. package/shared/types/work.ts +6 -0
  452. package/shared/utils/attachment-mentions.test.ts +39 -0
  453. package/shared/utils/attachment-mentions.ts +100 -0
  454. package/shared/utils/context-document.test.ts +53 -0
  455. package/shared/utils/context-document.ts +226 -0
  456. package/shared/utils/device-frame.test.ts +73 -0
  457. package/shared/utils/device-frame.ts +320 -0
  458. package/shared/utils/fuzzy.ts +79 -0
  459. package/shared/utils/launcher-fingerprint.test.ts +73 -0
  460. package/shared/utils/launcher-fingerprint.ts +108 -0
  461. package/shared/utils/logger.ts +2 -0
  462. package/shared/utils/page-colors.test.ts +17 -0
  463. package/shared/utils/page-colors.ts +24 -0
  464. package/shared/utils/process-supervisor.test.ts +88 -1
  465. package/shared/utils/process-supervisor.ts +123 -29
  466. package/shared/utils/process-tree.ts +99 -0
  467. package/shared/utils/restart-intent.test.ts +57 -0
  468. package/shared/utils/restart-intent.ts +80 -0
  469. package/shared/utils/semver.test.ts +33 -0
  470. package/shared/utils/semver.ts +35 -0
  471. package/shared/utils/supervised-child.ts +44 -0
  472. package/shared/utils/supervisor-protocol.ts +20 -0
  473. package/.env.example +0 -9
  474. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js +0 -1
  475. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.br +0 -0
  476. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js.gz +0 -0
  477. package/dist/assets/index-CrVWZH_D.js.br +0 -0
  478. package/dist/assets/index-CrVWZH_D.js.gz +0 -0
  479. package/dist/assets/index-DD0-3EWg.js.br +0 -0
  480. package/dist/assets/index-DD0-3EWg.js.gz +0 -0
  481. package/dist/assets/main-D2_TmcwQ.js +0 -1240
  482. package/dist/assets/main-D2_TmcwQ.js.br +0 -0
  483. package/dist/assets/main-D2_TmcwQ.js.gz +0 -0
  484. package/dist/assets/main-Yucigcmf.css +0 -1
  485. package/dist/assets/main-Yucigcmf.css.br +0 -0
  486. package/dist/assets/main-Yucigcmf.css.gz +0 -0
@@ -156,6 +156,26 @@ export interface NotificationEvent {
156
156
  message: string;
157
157
  }
158
158
 
159
+ /**
160
+ * The background work an engine is still running for this stream — commands or
161
+ * agents it started without waiting for them — as the COMPLETE current list
162
+ * (empty once everything finished).
163
+ *
164
+ * Some engines start a turn on their own when such work finishes, after the
165
+ * turn that started it already ended (Claude Code; Open Code with background
166
+ * sub-agents enabled). Others hold their completion signal until it is done
167
+ * (Qwen Code holds `result`, Copilot holds `session.idle`), and Codex, Cursor,
168
+ * Pi and Cline have no such work; those never emit this. An adapter that does
169
+ * must keep its stream — and its channel back to Clopen for tools and
170
+ * permissions — open until the list is empty and the engine is idle. The
171
+ * stream manager shows the gap between turns as "waiting for background work".
172
+ */
173
+ export interface BackgroundWorkEvent {
174
+ type: 'background_work';
175
+ sessionId: string;
176
+ tasks: Array<{ id: string; description?: string }>;
177
+ }
178
+
159
179
  // ============================================================
160
180
  // Engine Output
161
181
  // ============================================================
@@ -173,7 +193,8 @@ export type EngineOutput =
173
193
  | ResultEvent
174
194
  | SystemInitEvent
175
195
  | RateLimitEvent
176
- | NotificationEvent;
196
+ | NotificationEvent
197
+ | BackgroundWorkEvent;
177
198
 
178
199
  // ============================================================
179
200
  // Stream Transport (WebSocket layer)
@@ -485,6 +485,7 @@ export interface ToolResult {
485
485
  * ToolUseBlock is the unified type for tool invocations in assistant messages.
486
486
  *
487
487
  * It includes enrichment fields (result, subActivities, etc.) directly.
488
+ * `durationMs` (result time minus call time) exists only on display copies.
488
489
  * These are null/empty when the message is first created from the engine,
489
490
  * and get populated by the message grouper when preparing for display.
490
491
  *
@@ -505,6 +506,7 @@ type KnownToolUseBlock = {
505
506
  subActivities: SubAgentActivity[];
506
507
  skillPrompt: string | null;
507
508
  interrupted: boolean;
509
+ durationMs?: number;
508
510
  };
509
511
  }[KnownToolName];
510
512
 
@@ -517,6 +519,7 @@ export interface McpToolUseBlock {
517
519
  subActivities: SubAgentActivity[];
518
520
  skillPrompt: string | null;
519
521
  interrupted: boolean;
522
+ durationMs?: number;
520
523
  }
521
524
 
522
525
  export interface UnknownToolUseBlock {
@@ -528,6 +531,7 @@ export interface UnknownToolUseBlock {
528
531
  subActivities: SubAgentActivity[];
529
532
  skillPrompt: string | null;
530
533
  interrupted: boolean;
534
+ durationMs?: number;
531
535
  }
532
536
 
533
537
  export type ToolUseBlock = KnownToolUseBlock | McpToolUseBlock | UnknownToolUseBlock;
@@ -57,6 +57,8 @@ export interface WorkItem {
57
57
  headSha?: string;
58
58
  baseBranch?: string;
59
59
  isDraft?: boolean;
60
+ /** Pull requests only: who has been asked to review. */
61
+ reviewers?: string[];
60
62
  }
61
63
 
62
64
  /**
@@ -269,6 +271,10 @@ export interface WorkProviderCapabilities {
269
271
  createIssue: boolean;
270
272
  merge: boolean;
271
273
  assign: boolean;
274
+ /** Setting an item's labels. */
275
+ labels: boolean;
276
+ /** Requesting reviewers on a pull request. */
277
+ reviewers: boolean;
272
278
  /** Commits and per-file diffs for a pull request. */
273
279
  diff: boolean;
274
280
  }
@@ -0,0 +1,39 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { mentionedIndexes, removeAllMentions, removeMention, rewriteMentions, shiftMentions, splitMentions } from './attachment-mentions';
3
+
4
+ describe('attachment mentions', () => {
5
+ test('finds standalone tokens only', () => {
6
+ expect(mentionedIndexes('compare @1 with @3, then (@2) and "@1"')).toEqual([1, 3, 2]);
7
+ expect(mentionedIndexes('mail me@2x.com or use @2x assets')).toEqual([]);
8
+ expect(mentionedIndexes('@4 at the start')).toEqual([4]);
9
+ });
10
+
11
+ test('removing deletes the removed file’s tokens and renumbers the rest', () => {
12
+ expect(removeMention('compare @1 with @2 and @3', 2, 3)).toBe('compare @1 with and @2');
13
+ expect(removeMention('Lorem Ipsum @2', 2, 2)).toBe('Lorem Ipsum');
14
+ expect(removeMention('@1 fix this', 1, 1)).toBe('fix this');
15
+ expect(removeMention('look (@2) here\n@2\nnext', 2, 3)).toBe('look () here\n\nnext');
16
+ });
17
+
18
+ test('removing leaves numbers beyond the attachments alone', () => {
19
+ expect(removeMention('@1 and @9', 1, 2)).toBe('and @9');
20
+ });
21
+
22
+ test('clearing deletes every attachment token', () => {
23
+ expect(removeAllMentions('see @1 and @2, not @7', 2)).toBe('see and, not @7');
24
+ });
25
+
26
+ test('shifting moves only the appended message’s own numbers', () => {
27
+ expect(shiftMentions('@1 vs @2 vs @7', 3, 2)).toBe('@4 vs @5 vs @7');
28
+ expect(shiftMentions('@1', 0, 1)).toBe('@1');
29
+ });
30
+
31
+ test('rewrite can leave a token as it is', () => {
32
+ expect(rewriteMentions('@1 @2', (n) => (n === 1 ? null : 5))).toBe('@1 @5');
33
+ });
34
+
35
+ test('split keeps the text around in-range tokens', () => {
36
+ expect(splitMentions('look at @2 and @5.', 3)).toEqual(['look at ', 2, ' and @5.']);
37
+ expect(splitMentions('@1', 1)).toEqual([1]);
38
+ });
39
+ });
@@ -0,0 +1,100 @@
1
+ /**
2
+ * `@3` in a message names its third attachment.
3
+ *
4
+ * Attachments are numbered per message, from 1, in the order they were
5
+ * attached. The composer shows the numbers on its cards, the sent message shows
6
+ * them on its own, and the prompt labels every file with the same token — so
7
+ * "compare @1 with @3" means the same two files to the user and to the model.
8
+ */
9
+
10
+ /**
11
+ * A token stands on its own: at the start, or after whitespace or an opening
12
+ * bracket or quote (so `me@2x.com` is not one), and not running on into a
13
+ * word (so `@2x` is not one either).
14
+ */
15
+ const MENTION = /(^|[\s([{"'“‘])@(\d{1,4})(?![\w@])/g;
16
+
17
+ export function mentionToken(index: number): string {
18
+ return `@${index}`;
19
+ }
20
+
21
+ /** The attachment numbers a text mentions, in order of first appearance. */
22
+ export function mentionedIndexes(text: string): number[] {
23
+ const seen = new Set<number>();
24
+ for (const match of text.matchAll(MENTION)) seen.add(Number(match[2]));
25
+ return [...seen];
26
+ }
27
+
28
+ /**
29
+ * Rewrite every token. `replace` returns the new number, a replacement text,
30
+ * or null to leave the token as it is.
31
+ */
32
+ export function rewriteMentions(text: string, replace: (index: number) => number | string | null): string {
33
+ return text.replace(MENTION, (whole, lead: string, digits: string) => {
34
+ const next = replace(Number(digits));
35
+ if (next === null) return whole;
36
+ return lead + (typeof next === 'number' ? mentionToken(next) : next);
37
+ });
38
+ }
39
+
40
+ /** Stands in for a token being deleted, until the space around it is tidied. */
41
+ const DROPPED = '\u0000';
42
+
43
+ /**
44
+ * Rewrite tokens, deleting the ones `next` answers `false` for together with
45
+ * the space they leave: "compare @1 with @2" without @2 reads "compare @1
46
+ * with", not "compare @1 with ".
47
+ */
48
+ function rewriteDropping(text: string, next: (index: number) => number | false | null): string {
49
+ const marked = rewriteMentions(text, (index) => {
50
+ const answer = next(index);
51
+ return answer === false ? DROPPED : answer;
52
+ });
53
+ if (!marked.includes(DROPPED)) return marked;
54
+ return marked.replace(/[ \t]*\u0000[ \t]*/g, (match: string, offset: number, whole: string) => {
55
+ const before = whole[offset - 1];
56
+ const after = whole[offset + match.length];
57
+ // Between two words one space stays; at the edge of a line, none.
58
+ const between = before !== undefined && before !== '\n' && after !== undefined && after !== '\n';
59
+ return between && /^[ \t]/.test(match) && /[ \t]$/.test(match) ? ' ' : '';
60
+ });
61
+ }
62
+
63
+ /**
64
+ * The text after attachment `removed` (1-based) is taken out of `count`: its
65
+ * own tokens are deleted — the file is gone, and so is the reference — and
66
+ * later numbers move down one.
67
+ */
68
+ export function removeMention(text: string, removed: number, count: number): string {
69
+ return rewriteDropping(text, (index) => {
70
+ if (index === removed) return false;
71
+ return index > removed && index <= count ? index - 1 : null;
72
+ });
73
+ }
74
+
75
+ /** Every token naming one of `count` attachments, deleted — they were all removed. */
76
+ export function removeAllMentions(text: string, count: number): string {
77
+ return rewriteDropping(text, (index) => (index >= 1 && index <= count ? false : null));
78
+ }
79
+
80
+ /** Text written against its own attachments, appended after `offset` others. */
81
+ export function shiftMentions(text: string, offset: number, count: number): string {
82
+ if (offset === 0) return text;
83
+ return rewriteMentions(text, (index) => (index >= 1 && index <= count ? index + offset : null));
84
+ }
85
+
86
+ /** Split a text around the tokens that name one of `count` attachments. */
87
+ export function splitMentions(text: string, count: number): Array<string | number> {
88
+ const parts: Array<string | number> = [];
89
+ let last = 0;
90
+ for (const match of text.matchAll(MENTION)) {
91
+ const index = Number(match[2]);
92
+ if (index < 1 || index > count) continue;
93
+ const start = (match.index ?? 0) + match[1].length;
94
+ if (start > last) parts.push(text.slice(last, start));
95
+ parts.push(index);
96
+ last = start + match[0].length - match[1].length;
97
+ }
98
+ if (last < text.length) parts.push(text.slice(last));
99
+ return parts;
100
+ }
@@ -0,0 +1,53 @@
1
+ import { describe, expect, it } from 'bun:test';
2
+ import {
3
+ buildContextDocument,
4
+ contextFileSlug,
5
+ countLines,
6
+ readContextHeader,
7
+ readContextHeaderFromBase64,
8
+ textToBase64
9
+ } from './context-document';
10
+
11
+ describe('context documents', () => {
12
+ it('carry what they are in their first line', () => {
13
+ const document = buildContextDocument({
14
+ kind: 'git-commit',
15
+ label: 'fix: stop the leak\n',
16
+ detail: 'abc123',
17
+ capturedAt: '2026-11-27T00:00:00.000Z',
18
+ facts: [['Commit', 'abc123'], ['Empty', null]],
19
+ sections: [{ title: 'Commit', body: 'diff --git a b', fence: 'diff' }]
20
+ });
21
+ expect(document.fileName).toBe('git-commit-fix-stop-the-leak.md');
22
+ expect(document.source).toEqual({ kind: 'git-commit', label: 'fix: stop the leak', detail: 'abc123', capturedAt: '2026-11-27T00:00:00.000Z' });
23
+ expect(readContextHeader(document.text)).toEqual(document.source);
24
+ expect(document.text).toContain('# Git commit: fix: stop the leak');
25
+ expect(document.text).toContain('- Commit: abc123');
26
+ expect(document.text).not.toContain('Empty');
27
+ expect(document.text).toContain('```diff\ndiff --git a b\n```');
28
+ });
29
+
30
+ it('survive a label that would end the comment and a body that holds a fence', () => {
31
+ const document = buildContextDocument({ kind: 'note', label: 'a --> b', sections: [{ body: '```js\nx\n```', fence: 'md' }] });
32
+ expect(document.text.split('\n')[0].endsWith(' -->')).toBe(true);
33
+ expect(document.text.split('\n')[0].indexOf('-->')).toBe(document.text.split('\n')[0].length - 3);
34
+ expect(readContextHeader(document.text)?.label).toBe('a --> b');
35
+ expect(document.text).toContain('````md\n```js\nx\n```\n````');
36
+ });
37
+
38
+ it('are told apart from any other file by their bytes', () => {
39
+ const document = buildContextDocument({ kind: 'terminal', label: 'Ünïcode tab', sections: [{ body: 'x'.repeat(20_000) }] });
40
+ expect(readContextHeaderFromBase64(textToBase64(document.text), 'text/markdown')?.label).toBe('Ünïcode tab');
41
+ expect(readContextHeaderFromBase64(textToBase64('# just notes'), 'text/markdown')).toBeNull();
42
+ expect(readContextHeaderFromBase64(textToBase64(document.text), 'image/png')).toBeNull();
43
+ expect(readContextHeader('<!-- clopen-context {"kind":"nope","label":"x"} -->')).toBeNull();
44
+ });
45
+
46
+ it('name files and lines the way people read them', () => {
47
+ expect(contextFileSlug(' ')).toBe('context');
48
+ expect(contextFileSlug('src/App.svelte:10-20')).toBe('src-app-svelte-10-20');
49
+ expect(countLines('')).toBe('0 lines');
50
+ expect(countLines('a\n')).toBe('1 line');
51
+ expect(countLines('a\nb\nc')).toBe('3 lines');
52
+ });
53
+ });
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Context documents — the file a mention is turned into.
3
+ *
4
+ * A snapshot is plain markdown the model can read with its own tools, and its
5
+ * first line is a comment saying what it is:
6
+ *
7
+ * <!-- clopen-context {"kind":"terminal","label":"dev server",…} -->
8
+ *
9
+ * The header travels with the bytes, so every path an attachment already takes
10
+ * — the draft, the queue, an edit, a message returned to the box — carries it
11
+ * without knowing about it. The composer and the timeline read it to draw the
12
+ * card; the server reads it to label the attachment for the engine.
13
+ */
14
+
15
+ import type { ContextKind, ContextSource } from '$shared/types/mentions';
16
+
17
+ const HEADER_START = '<!-- clopen-context ';
18
+ const HEADER_END = ' -->';
19
+
20
+ /** The media type every context document is written in. */
21
+ export const CONTEXT_MEDIA_TYPE = 'text/markdown';
22
+
23
+ /** How a kind is named in a label: "Attachment @2: terminal output …". */
24
+ export const CONTEXT_NOUNS: Record<ContextKind, string> = {
25
+ file: 'project file',
26
+ folder: 'folder listing',
27
+ code: 'code selection',
28
+ terminal: 'terminal output',
29
+ 'terminal-selection': 'terminal selection',
30
+ 'git-changes': 'git working-tree changes',
31
+ 'git-staged': 'git staged changes',
32
+ 'git-file': 'git file diff',
33
+ 'git-commit': 'git commit',
34
+ 'git-branch': 'git branch diff',
35
+ 'git-stash': 'git stash',
36
+ 'git-conflicts': 'git merge conflicts',
37
+ 'preview-tab': 'preview tab',
38
+ 'preview-element': 'preview page element',
39
+ 'preview-console': 'preview console log',
40
+ 'chat-session': 'chat transcript',
41
+ 'chat-message': 'chat message',
42
+ project: 'project overview',
43
+ 'ai-changes': 'changes made by the AI',
44
+ 'work-item': 'issue or pull request',
45
+ note: 'note',
46
+ memory: 'memory',
47
+ 'db-connection': 'database schema',
48
+ 'db-table': 'database table',
49
+ 'db-result': 'database query result',
50
+ deployment: 'deployment',
51
+ container: 'container',
52
+ port: 'listening port',
53
+ 'env-file': 'environment file'
54
+ };
55
+
56
+ /** Kinds that point at a real file instead of carrying a snapshot of it. */
57
+ export function isReferenceKind(kind: ContextKind): boolean {
58
+ return kind === 'file';
59
+ }
60
+
61
+ export interface ContextSection {
62
+ /** A `##` heading; omitted for the lead section. */
63
+ title?: string;
64
+ body: string;
65
+ /** Fenced as code in this language; `''` fences without one. Omit for prose. */
66
+ fence?: string;
67
+ }
68
+
69
+ export interface ContextDocumentInput {
70
+ kind: ContextKind;
71
+ label: string;
72
+ detail?: string;
73
+ path?: string;
74
+ /** `- key: value` lines under the title. */
75
+ facts?: Array<[string, string | number | null | undefined]>;
76
+ sections?: ContextSection[];
77
+ /** Defaults to now. */
78
+ capturedAt?: string;
79
+ }
80
+
81
+ export interface ContextDocument {
82
+ fileName: string;
83
+ text: string;
84
+ source: ContextSource;
85
+ }
86
+
87
+ /** A fence long enough that nothing inside the body can close it. */
88
+ function fenceFor(body: string): string {
89
+ let longest = 0;
90
+ for (const match of body.matchAll(/`{3,}/g)) longest = Math.max(longest, match[0].length);
91
+ return '`'.repeat(Math.max(3, longest + 1));
92
+ }
93
+
94
+ /** `name` as a file name: lowercase words joined by dashes, never empty. */
95
+ export function contextFileSlug(name: string): string {
96
+ const slug = name
97
+ .normalize('NFKD')
98
+ .replace(/[^\w\s.-]+/g, ' ')
99
+ .trim()
100
+ .replace(/[\s.]+/g, '-')
101
+ .replace(/-+/g, '-')
102
+ .toLowerCase()
103
+ .slice(0, 60)
104
+ .replace(/^-|-$/g, '');
105
+ return slug || 'context';
106
+ }
107
+
108
+ /** Build the document a mention attaches. */
109
+ export function buildContextDocument(input: ContextDocumentInput): ContextDocument {
110
+ const source: ContextSource = {
111
+ kind: input.kind,
112
+ // The header has to fit in the bytes a reader probes (see below).
113
+ label: input.label.replace(/\s+/g, ' ').trim().slice(0, 200),
114
+ ...(input.detail && { detail: input.detail.slice(0, 200) }),
115
+ ...(input.path && { path: input.path }),
116
+ capturedAt: input.capturedAt ?? new Date().toISOString()
117
+ };
118
+
119
+ const lines: string[] = [
120
+ // `-->` inside the JSON would end the comment early.
121
+ `${HEADER_START}${JSON.stringify(source).replace(/-->/g, '--\\u003e')}${HEADER_END}`,
122
+ `# ${capitalise(CONTEXT_NOUNS[input.kind])}: ${source.label}`,
123
+ ''
124
+ ];
125
+
126
+ const facts = (input.facts ?? []).filter(([, value]) => value !== null && value !== undefined && value !== '');
127
+ if (input.detail) facts.unshift(['Detail', input.detail]);
128
+ facts.push(['Captured', source.capturedAt]);
129
+ for (const [key, value] of facts) lines.push(`- ${key}: ${value}`);
130
+
131
+ for (const section of input.sections ?? []) {
132
+ lines.push('');
133
+ if (section.title) lines.push(`## ${section.title}`, '');
134
+ if (section.fence === undefined) {
135
+ lines.push(section.body.trimEnd() || '_Empty._');
136
+ } else {
137
+ const fence = fenceFor(section.body);
138
+ lines.push(`${fence}${section.fence}`, section.body.replace(/\n+$/, ''), fence);
139
+ }
140
+ }
141
+
142
+ return {
143
+ fileName: `${input.kind}-${contextFileSlug(source.label)}.md`,
144
+ text: `${lines.join('\n')}\n`,
145
+ source
146
+ };
147
+ }
148
+
149
+ /**
150
+ * A mentioned project file. The document only names it: the engine is pointed
151
+ * at the file itself (see backend/chat/attachments), so it reads the version
152
+ * on disk when it runs, not a copy from when it was mentioned.
153
+ */
154
+ export function fileReferenceDocument(path: string): ContextDocument {
155
+ return buildContextDocument({ kind: 'file', label: path, path, facts: [['Path', path]] });
156
+ }
157
+
158
+ function capitalise(text: string): string {
159
+ return text.charAt(0).toUpperCase() + text.slice(1);
160
+ }
161
+
162
+ /** What a document says it is, or null for any other file. */
163
+ export function readContextHeader(text: string): ContextSource | null {
164
+ if (!text.startsWith(HEADER_START)) return null;
165
+ const end = text.indexOf(HEADER_END, HEADER_START.length);
166
+ if (end === -1) return null;
167
+ try {
168
+ const parsed = JSON.parse(text.slice(HEADER_START.length, end)) as Partial<ContextSource>;
169
+ if (typeof parsed.kind !== 'string' || !(parsed.kind in CONTEXT_NOUNS)) return null;
170
+ if (typeof parsed.label !== 'string') return null;
171
+ return {
172
+ kind: parsed.kind as ContextKind,
173
+ label: parsed.label,
174
+ ...(typeof parsed.detail === 'string' && parsed.detail && { detail: parsed.detail }),
175
+ ...(typeof parsed.path === 'string' && parsed.path && { path: parsed.path }),
176
+ capturedAt: typeof parsed.capturedAt === 'string' ? parsed.capturedAt : ''
177
+ };
178
+ } catch {
179
+ return null;
180
+ }
181
+ }
182
+
183
+ /** Enough of a document's start to hold its header. */
184
+ export const CONTEXT_HEADER_PROBE_BYTES = 4096;
185
+
186
+ /**
187
+ * The header of a document held as base64, decoding only its start. Works on
188
+ * any attachment: a file that is not a context document answers null.
189
+ */
190
+ export function readContextHeaderFromBase64(base64: string, mediaType: string): ContextSource | null {
191
+ if (mediaType !== CONTEXT_MEDIA_TYPE && mediaType !== 'text/plain') return null;
192
+ try {
193
+ // Four base64 characters are three bytes; cut on a whole group.
194
+ const head = base64.slice(0, Math.ceil((CONTEXT_HEADER_PROBE_BYTES * 4) / 3 / 4) * 4);
195
+ const binary = atob(head);
196
+ const bytes = new Uint8Array(binary.length);
197
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
198
+ return readContextHeader(new TextDecoder().decode(bytes));
199
+ } catch {
200
+ return null;
201
+ }
202
+ }
203
+
204
+ /** UTF-8 text as base64, the form attachments travel in. */
205
+ export function textToBase64(text: string): string {
206
+ const bytes = new TextEncoder().encode(text);
207
+ let binary = '';
208
+ for (let i = 0; i < bytes.length; i += 0x8000) binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));
209
+ return btoa(binary);
210
+ }
211
+
212
+ /** What a context attachment is, as a card names it: "Terminal output". */
213
+ export function contextNoun(kind: ContextKind): string {
214
+ return capitalise(CONTEXT_NOUNS[kind]);
215
+ }
216
+
217
+ /** How the picker and the viewer name a context attachment: "Terminal output · dev server". */
218
+ export function describeContext(source: ContextSource): string {
219
+ return `${contextNoun(source.kind)} · ${source.label}`;
220
+ }
221
+
222
+ /** A line count as people write it: "1,240 lines". */
223
+ export function countLines(text: string): string {
224
+ const lines = text ? text.replace(/\n$/, '').split('\n').length : 0;
225
+ return `${lines.toLocaleString('en-US')} ${lines === 1 ? 'line' : 'lines'}`;
226
+ }
@@ -0,0 +1,73 @@
1
+ import { describe, expect, test } from 'bun:test';
2
+ import { drawDeviceFrame, frameDrawInput, hasDeviceFrame } from './device-frame';
3
+
4
+ /** A 2D context that accepts every call, for running the drawing without a browser. */
5
+ function fakeContext(): unknown {
6
+ const gradient = { addColorStop() {} };
7
+ return new Proxy(
8
+ {},
9
+ {
10
+ get(_target, key) {
11
+ if (key === 'createLinearGradient' || key === 'createRadialGradient') return () => gradient;
12
+ if (key === 'measureText') return () => ({ width: 10 });
13
+ return () => {};
14
+ },
15
+ set: () => true
16
+ }
17
+ );
18
+ }
19
+
20
+ function withFakeDocument<T>(run: () => T): T {
21
+ const scope = globalThis as unknown as { document?: unknown };
22
+ const previous = scope.document;
23
+ scope.document = {
24
+ createElement: () => ({ width: 0, height: 0, getContext: () => fakeContext() })
25
+ };
26
+ try {
27
+ return run();
28
+ } finally {
29
+ scope.document = previous;
30
+ }
31
+ }
32
+
33
+ const phone = { deviceSize: 'mobile', viewport: { width: 402, height: 874 }, deviceModel: 'iphone-16' } as const;
34
+
35
+ describe('device frame', () => {
36
+ test('only devices with a mockup get a frame', () => {
37
+ expect(hasDeviceFrame(phone)).toBe(true);
38
+ expect(hasDeviceFrame({ deviceSize: 'responsive', viewport: { width: 900, height: 700 }, deviceModel: null })).toBe(false);
39
+ expect(frameDrawInput({ deviceSize: 'responsive', viewport: { width: 900, height: 700 }, deviceModel: null })).toBeNull();
40
+ });
41
+
42
+ test('ink follows the page colours it sits on', () => {
43
+ const input = frameDrawInput({ ...phone, pageColors: { statusBar: '#0f172a', background: '#ffffff' } });
44
+ expect(input?.statusInk).toBe('#fff');
45
+ expect(input?.backgroundInk).toBe('#111113');
46
+ });
47
+
48
+ test('the canvas is the whole mockup, at the image’s scale', () => {
49
+ const input = frameDrawInput(phone)!;
50
+ const canvas = withFakeDocument(() => drawDeviceFrame({ width: 804, height: 1748 } as never, input));
51
+ expect(canvas?.width).toBe(Math.round(input.layout.footprint.width * 2));
52
+ expect(canvas?.height).toBe(Math.round(input.layout.footprint.height * 2));
53
+ });
54
+
55
+ // The server ships the function into a browser page as source text. Rebuilt
56
+ // from that text alone, it must still run: anything it reached outside its
57
+ // own body would be a ReferenceError there.
58
+ test('runs from its source text alone, as the server sends it', () => {
59
+ const rebuilt = new Function(`return (${drawDeviceFrame.toString()})`)() as typeof drawDeviceFrame;
60
+ for (const spec of [
61
+ phone,
62
+ { deviceSize: 'mobile', viewport: { width: 412, height: 923 }, deviceModel: 'pixel-9' },
63
+ { deviceSize: 'mobile', viewport: { width: 375, height: 667 }, deviceModel: 'iphone-se' },
64
+ { deviceSize: 'tablet', viewport: { width: 834, height: 1194 }, deviceModel: 'ipad-pro-11' },
65
+ { deviceSize: 'laptop', viewport: { width: 1440, height: 900 }, deviceModel: 'macbook-air-13' },
66
+ { deviceSize: 'desktop', viewport: { width: 1920, height: 1080 }, deviceModel: 'monitor-fhd' }
67
+ ] as const) {
68
+ const input = frameDrawInput(spec)!;
69
+ const canvas = withFakeDocument(() => rebuilt(spec.viewport as never, input));
70
+ expect(canvas).not.toBeNull();
71
+ }
72
+ });
73
+ });