@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
@@ -1,71 +1,73 @@
1
1
  /**
2
- * Graph view assembly for the visualization.
2
+ * The Memory graph, served the way a map is.
3
3
  *
4
- * ── What this file is NOT allowed to do any more ─────────────────────────────
5
- * It used to run Louvain on every call. Community detection is stable per
6
- * dataset, so opening the modal, changing a filter, or any conversation
7
- * recording a memory made every connected client pay for the same clustering
8
- * again — and the cost grew with the store rather than with what was on screen.
9
- * It now lives in `graph_layout`, written by the background pass in `layout.ts`,
10
- * and this file only reads it.
4
+ * ── Why tiles ────────────────────────────────────────────────────────────────
5
+ * The view used to answer "show me the graph" with the graph: every memory up
6
+ * to a render budget, and past it a single grid laid over the whole extent that
7
+ * merged whatever shared a cell into one mark — which then had to be clicked to
8
+ * see inside. The cost of a look grew with the store, and past the budget the
9
+ * picture was mostly marks standing in for memories.
11
10
  *
12
- * ── Showing everything, at bounded cost ──────────────────────────────────────
13
- * The old view answered scale with a cap: return the three thousand most
14
- * reinforced memories and set `truncated`. That is not a scale strategy, it is a
15
- * silent ceiling — past it the rest of the store simply was not in the picture,
16
- * with no way to reach it but narrowing a filter.
11
+ * Now the client asks for the squares of the map that are on screen, at the
12
+ * resolution the camera is at, exactly as a map viewer does. The world (see
13
+ * `layout.ts`) is cut into 2^z × 2^z tiles at zoom level z; the client picks the
14
+ * level from its zoom, so a tile is always a few hundred pixels across whatever
15
+ * the zoom. What is on screen therefore costs about the same at any zoom and
16
+ * any store size, and zooming in is how you see more — never clicking.
17
17
  *
18
- * The answer here is to aggregate by POSITION rather than to trim by rank, and
19
- * the difference is what the user sees. Grouping by community — the obvious
20
- * alternative, and the first thing tried — replaces the picture: you get lobes
21
- * instead of memories, and reaching any memory means opening one first. Grouping
22
- * by position keeps the picture. The layout plane is divided into a grid fine
23
- * enough that the number of OCCUPIED cells is bounded, and each occupied cell
24
- * becomes one mark. Marks merge only where their dots would have overlapped
25
- * anyway, so the silhouette, the lobes and the colours are the ones the full
26
- * graph would have drawn, and nothing is missing from it.
18
+ * ── What a tile holds ────────────────────────────────────────────────────────
19
+ * The budget is the SCREEN's, not a tile's: how many marks the client can draw
20
+ * at once. When everything in the requested tiles fits it, every memory arrives
21
+ * individually — so a store of a few thousand memories is drawn in full at every
22
+ * zoom, and zooming in can never fold something the overview showed. Only when
23
+ * the screen holds more than the budget is it shared out: sparse tiles keep
24
+ * every memory, and what is left is split between the crowded ones, which are
25
+ * folded into a grid of cells (a cell holding one memory still arrives as that
26
+ * memory). Zooming in shows less of the map, which fits, so every cluster
27
+ * resolves by zooming alone.
27
28
  *
28
- * Below `RENDER_BUDGET` no cell holds more than one memory, so every mark IS a
29
- * memory and the view is exactly the flat one it always was. Above it, a cell
30
- * holding one memory still returns that memory — fidelity is lost only where
31
- * the display had none to give.
32
- *
33
- * Zooming into a mark asks for its cell as a rectangle, which costs that
34
- * rectangle rather than the store.
29
+ * Edges travel with the tile they leave from, carrying where their far end is,
30
+ * so the client can attach them to whichever mark stands for that end at the
31
+ * moment — the memory itself, or the cluster it is folded into.
35
32
  */
36
33
 
37
- import { graphQueries, graphLayoutQueries, type GraphBinGrid } from '$backend/database/queries/graph-queries';
34
+ import { graphLayoutQueries, graphQueries, type GraphListFilter } from '$backend/database/queries/graph-queries';
35
+ import { getLayoutState, scheduleGraphLayout } from './layout';
38
36
  import type {
39
- GraphNode,
40
- GraphRegion,
41
37
  GraphScope,
42
38
  GraphSource,
43
- GraphView,
44
- GraphViewBin,
45
- GraphViewBinEdge,
46
- GraphViewEdge,
47
- GraphViewNode
39
+ GraphTile,
40
+ GraphTileCellEdge,
41
+ GraphTileCluster,
42
+ GraphTileNode,
43
+ GraphTilesResponse,
44
+ GraphViewMeta
48
45
  } from '$shared/types/memory';
49
46
 
47
+ /** The deepest zoom level a client may ask for — far past one memory per tile. */
48
+ export const MAX_TILE_ZOOM = 20;
49
+
50
+ /** Tiles served per request. A screen needs a few dozen at most. */
51
+ const MAX_TILES_PER_REQUEST = 64;
52
+
53
+ /** The range a client may ask the screen's budget to be in. */
54
+ const MIN_SCREEN_BUDGET = 256;
55
+ const MAX_SCREEN_BUDGET = 40_000;
56
+
50
57
  /**
51
- * Marks the client is asked to draw at once.
58
+ * Cells per side when a crowded tile is folded.
52
59
  *
53
- * A ceiling on the WORK, not on the content: past it marks merge rather than
54
- * disappear. Set where a WebGL scene stays comfortable on a low-powered machine
55
- * — the graph build, sigma's indexation and the per-frame reducers are all
56
- * linear in this number, and it is the only number they are linear in.
60
+ * A tile is drawn a few hundred pixels across, so 32 makes a cell 8–16 pixels —
61
+ * about the size a cluster is drawn, which is what stops neighbouring clusters
62
+ * overlapping. Smaller when the budget is smaller, so a folded tile never holds
63
+ * more marks than its budget.
57
64
  */
58
- const RENDER_BUDGET = 3_000;
59
-
60
- /** Bin edges drawn at once, heaviest first. Lines are cheaper than marks, not free. */
61
- const MAX_BIN_EDGES = 6_000;
65
+ const MAX_CELLS_PER_SIDE = 32;
62
66
 
63
- /** Longest caption a mark carries; the full text belongs to the inspector. */
64
- const BIN_LABEL_MAX = 60;
67
+ /** Edges served per tile, as a multiple of the marks it holds, heaviest first. */
68
+ const EDGES_PER_MARK = 5;
65
69
 
66
70
  export interface GraphViewFilter {
67
- /** `undefined` = every project (cross-project view); `null` = global only. */
68
- projectId?: string | null;
69
71
  /** The multi-select's answer: absent = every project, empty = global only. */
70
72
  projectIds?: string[];
71
73
  /** Narrow to particular subkinds — decisions only, failures only, and so on. */
@@ -76,385 +78,254 @@ export interface GraphViewFilter {
76
78
  includeArchived?: boolean;
77
79
  /** Show memories that have been replaced by a newer belief. Off by default. */
78
80
  includeSuperseded?: boolean;
79
- /**
80
- * A rectangle of the layout to restrict to — how a mark is opened.
81
- *
82
- * Navigation, not filtering: it narrows what is DRAWN without changing what
83
- * the graph is, which is why the totals it reports are the region's.
84
- */
85
- region?: GraphRegion;
86
- limit?: number;
87
81
  }
88
82
 
89
- export function buildGraphView(filter: GraphViewFilter): GraphView {
90
- const limit = Math.min(filter.limit ?? RENDER_BUDGET, RENDER_BUDGET);
91
- const region = filter.region ?? null;
92
-
93
- // Zoomed in: the rectangle is already a bounded slice of the arrangement, so
94
- // it is drawn at full fidelity and counted within itself.
95
- if (region) {
96
- const nodes = graphQueries.listInRegion({ ...filter, limit }, region);
97
- return flat(nodes, region, nodes.length, false);
98
- }
99
-
100
- const extent = graphLayoutQueries.extent(filter);
101
-
102
- // Either it fits, or nothing has been laid out yet — a fresh install, or the
103
- // first fetch after the upgrade added the table. Both draw the flat view: the
104
- // second because binning needs positions, and falling back to what the feature
105
- // always did means the graph is never empty while the background pass catches
106
- // up.
107
- const laidOut = extent.total - extent.unplaced;
108
- if (extent.total <= RENDER_BUDGET || laidOut === 0) {
109
- const nodes = graphQueries.list({ ...filter, limit });
110
- return flat(nodes, null, extent.total, extent.total > nodes.length);
111
- }
83
+ export interface GraphTileRequest extends GraphViewFilter {
84
+ /** The epoch the client's tile addresses were computed against. */
85
+ epoch: number;
86
+ z: number;
87
+ tiles: { x: number; y: number }[];
88
+ /** Marks the client can draw at once, shared out across `tiles`. */
89
+ budget: number;
90
+ }
112
91
 
113
- return binned(filter, extent, limit);
92
+ function listFilter(filter: GraphViewFilter): GraphListFilter {
93
+ return {
94
+ projectIds: filter.projectIds,
95
+ subkinds: filter.subkinds,
96
+ scopes: filter.scopes,
97
+ sources: filter.sources,
98
+ includeArchived: filter.includeArchived,
99
+ includeSuperseded: filter.includeSuperseded
100
+ };
114
101
  }
115
102
 
116
103
  /**
117
- * Every matching memory, drawn individually.
104
+ * What the client needs before it can ask for tiles: the world, its epoch, and
105
+ * the filter's counts and extent.
118
106
  *
119
- * The ordinary case and the one the view is tuned for — below the render budget
120
- * this is the whole story, and it is unchanged from before any of this existed.
107
+ * Also the nudge for anything still waiting to be placed. A memory with no
108
+ * position is counted but not drawn, and the pass that places it is normally
109
+ * already scheduled by the write — this covers a store that was written while
110
+ * the server was not running a pass at all (an upgrade, a clear-data).
121
111
  */
122
- function flat(
123
- nodes: GraphNode[],
124
- region: GraphRegion | null,
125
- totalNodes: number,
126
- truncated: boolean
127
- ): GraphView {
128
- if (nodes.length === 0) {
129
- return {
130
- level: 'flat',
131
- nodes: [],
132
- edges: [],
133
- bins: [],
134
- binEdges: [],
135
- region,
136
- totalNodes,
137
- truncated: false
138
- };
139
- }
140
-
141
- const ids = nodes.map(node => node.id);
142
- const stored = graphQueries.edgesWithin(ids);
143
-
144
- // Two memories about the same subject ARE connected, and that connection is
145
- // stated by extraction rather than inferred from how they are worded. It is
146
- // derived here rather than stored, so it can never outlive the claim it came
147
- // from — see `derivedEdges`.
148
- //
149
- // Without it the episodic half has almost no structure at all. Similarity
150
- // linking used to supply it, badly: on a real graph 144 of 371 edges were
151
- // fabricated by cosine over a corpus with no variance. Removing that was right
152
- // and removing it ALONE was not — the view became ninety-three disconnected
153
- // dots, which is a less honest picture than the wrong one, because these
154
- // memories genuinely do belong together.
155
- const derived: GraphViewEdge[] = graphQueries.derivedEdges(ids).map((edge, index) => ({
156
- // Negative ids, so nothing can mistake a derived edge for a stored row and
157
- // try to delete or re-weight it.
158
- id: -(index + 1),
159
- source: edge.srcId,
160
- target: edge.dstId,
161
- rel: 'relates_to' as const,
162
- weight: edge.weight
163
- }));
164
-
165
- // Degree is counted over what is being DRAWN, so a node's size answers "how
166
- // connected is this within what I am looking at" — which is the question the
167
- // eye is actually asking.
168
- const degree = new Map<string, number>();
169
- const bump = (srcId: string, dstId: string): void => {
170
- degree.set(srcId, (degree.get(srcId) ?? 0) + 1);
171
- degree.set(dstId, (degree.get(dstId) ?? 0) + 1);
172
- };
173
- for (const edge of stored) bump(edge.srcId, edge.dstId);
174
- for (const edge of derived) bump(edge.source, edge.target);
175
-
176
- const layout = graphLayoutQueries.read(ids);
177
- const viewNodes = nodes.map(node => toViewNode(node, degree.get(node.id) ?? 0, layout.get(node.id)));
178
- placeArrivals(viewNodes, [...stored.map(edge => ({ source: edge.srcId, target: edge.dstId })), ...derived]);
112
+ export function buildGraphMeta(filter: GraphViewFilter): GraphViewMeta {
113
+ const narrowing = listFilter(filter);
114
+ const state = getLayoutState();
115
+ const extent = graphLayoutQueries.extent(narrowing);
116
+ if (extent.unplaced > 0) scheduleGraphLayout();
179
117
 
118
+ const placed = extent.total - extent.unplaced;
180
119
  return {
181
- level: 'flat',
182
- nodes: viewNodes,
183
- edges: [
184
- ...stored.map(edge => ({
185
- id: edge.id,
186
- source: edge.srcId,
187
- target: edge.dstId,
188
- rel: edge.rel,
189
- weight: edge.weight
190
- })),
191
- ...derived
192
- ],
193
- bins: [],
194
- binEdges: [],
195
- region,
196
- totalNodes,
197
- truncated
120
+ epoch: state.epoch,
121
+ stamp: state.stamp,
122
+ world: state.world,
123
+ spacing: state.spacing,
124
+ total: extent.total,
125
+ unplaced: extent.unplaced,
126
+ extent:
127
+ placed > 0 ? { minX: extent.minX, maxX: extent.maxX, minY: extent.minY, maxY: extent.maxY } : null,
128
+ degreeScale: placed > 0 ? graphLayoutQueries.degreeScale(narrowing) : 1
198
129
  };
199
130
  }
200
131
 
201
132
  /**
202
- * The whole graph, with crowded neighbourhoods folded into single marks.
133
+ * The requested tiles of the map at one zoom level.
203
134
  *
204
- * Cells holding exactly one memory come back as that memory, so this is a flat
205
- * view everywhere the display could have drawn one — which, in a force layout,
206
- * is most of the periphery. Only the dense middle merges, and only as far as it
207
- * was going to overlap.
135
+ * Answers `stale` instead of tiles when the client's epoch is not the current
136
+ * one: its addresses were computed against a world that no longer exists, and
137
+ * serving them would draw the right memories in the wrong places.
208
138
  */
209
- function binned(
210
- filter: GraphViewFilter,
211
- extent: { total: number; minX: number; maxX: number; minY: number; maxY: number },
212
- limit: number
213
- ): GraphView {
214
- const grid = gridFor(extent);
215
- const cells = graphLayoutQueries.binnedNodes(filter, grid);
216
-
217
- // A cell of one is not a bin, it is a memory. Splitting them here is what
218
- // keeps the picture inspectable: everything the grid did not have to merge
219
- // stays clickable, hoverable and highlightable exactly as before.
220
- const singles = cells.filter(cell => cell.members === 1);
221
- const groups = cells.filter(cell => cell.members > 1);
222
-
223
- const nodes = graphQueries.getByIds(singles.map(cell => cell.id));
224
- const byId = new Map(nodes.map(node => [node.id, node]));
225
- const layout = graphLayoutQueries.read(nodes.map(node => node.id));
226
-
227
- // Which mark each cell is, so the rolled-up edges can name their ends. A
228
- // single's mark is the memory's own id; a group's is the cell.
229
- const markOf = new Map<string, string>();
230
- for (const cell of cells) {
231
- markOf.set(cellKey(cell.cellX, cell.cellY), cell.members === 1 ? cell.id : binId(cell.cellX, cell.cellY));
139
+ export function buildGraphTiles(request: GraphTileRequest): GraphTilesResponse {
140
+ const state = getLayoutState();
141
+ const world = state.world;
142
+ if (!world || request.epoch !== state.epoch) return { epoch: state.epoch, stale: true, tiles: [] };
143
+
144
+ const z = Math.max(0, Math.min(MAX_TILE_ZOOM, Math.floor(request.z)));
145
+ const span = 2 ** z;
146
+ const tileSize = world.size / span;
147
+ const budget = Math.max(MIN_SCREEN_BUDGET, Math.min(MAX_SCREEN_BUDGET, Math.floor(request.budget)));
148
+ const filter = listFilter(request);
149
+
150
+ const wanted: { x: number; y: number }[] = [];
151
+ const seen = new Set<string>();
152
+ for (const tile of request.tiles) {
153
+ const x = Math.floor(tile.x);
154
+ const y = Math.floor(tile.y);
155
+ if (x < 0 || y < 0 || x >= span || y >= span) continue;
156
+ const key = `${x}:${y}`;
157
+ if (seen.has(key)) continue;
158
+ seen.add(key);
159
+ wanted.push({ x, y });
160
+ if (wanted.length >= MAX_TILES_PER_REQUEST) break;
161
+ }
162
+ if (wanted.length === 0) return { epoch: state.epoch, stale: false, tiles: [] };
163
+
164
+ const rectOf = (x: number, y: number) => ({
165
+ minX: world.minX + x * tileSize,
166
+ maxX: world.minX + (x + 1) * tileSize,
167
+ minY: world.minY + y * tileSize,
168
+ maxY: world.minY + (y + 1) * tileSize
169
+ });
170
+
171
+ // One counting query over the union of what was asked, so each tile's
172
+ // resolution is decided before a single label is read.
173
+ let minTileX = Infinity;
174
+ let maxTileX = -Infinity;
175
+ let minTileY = Infinity;
176
+ let maxTileY = -Infinity;
177
+ for (const tile of wanted) {
178
+ minTileX = Math.min(minTileX, tile.x);
179
+ maxTileX = Math.max(maxTileX, tile.x);
180
+ minTileY = Math.min(minTileY, tile.y);
181
+ maxTileY = Math.max(maxTileY, tile.y);
182
+ }
183
+ const union = {
184
+ minX: world.minX + minTileX * tileSize,
185
+ maxX: world.minX + (maxTileX + 1) * tileSize,
186
+ minY: world.minY + minTileY * tileSize,
187
+ maxY: world.minY + (maxTileY + 1) * tileSize
188
+ };
189
+ const counts = new Map<string, number>();
190
+ for (const row of graphLayoutQueries.tileCounts(filter, { originX: world.minX, originY: world.minY, size: tileSize }, union)) {
191
+ counts.set(`${row.tileX}:${row.tileY}`, row.count);
232
192
  }
233
193
 
234
- const binEdges: GraphViewBinEdge[] = [];
235
- const nodeEdges: GraphViewEdge[] = [];
236
- let syntheticId = -1;
194
+ const allowance = shareBudget(
195
+ wanted.map(({ x, y }) => counts.get(`${x}:${y}`) ?? 0),
196
+ budget
197
+ );
198
+
199
+ // An edge between two tiles of the same request would otherwise travel twice,
200
+ // once from each end — measured, that was most of the payload at overview.
201
+ const sentPairs = new Set<string>();
202
+ const firstTime = (a: string, b: string): boolean => {
203
+ const key = a < b ? `${a}|${b}` : `${b}|${a}`;
204
+ if (sentPairs.has(key)) return false;
205
+ sentPairs.add(key);
206
+ return true;
207
+ };
237
208
 
238
- for (const edge of graphLayoutQueries.binnedEdges(filter, grid, MAX_BIN_EDGES)) {
239
- const source = markOf.get(cellKey(edge.srcX, edge.srcY));
240
- const target = markOf.get(cellKey(edge.dstX, edge.dstY));
241
- if (!source || !target || source === target) continue;
209
+ const tiles: GraphTile[] = wanted.map(({ x, y }, index) => {
210
+ const count = counts.get(`${x}:${y}`) ?? 0;
211
+ const allowed = allowance[index];
212
+ const rect = rectOf(x, y);
213
+ const empty: GraphTile = { z, x, y, cells: 0, nodes: [], clusters: [], edges: [], cellEdges: [] };
214
+ if (count === 0) return empty;
215
+ const edgeLimit = Math.max(1, Math.min(count, allowed)) * EDGES_PER_MARK;
216
+
217
+ if (count <= allowed) {
218
+ const nodes = graphLayoutQueries.tileNodes(filter, rect, count).map(round);
219
+ const edges = graphLayoutQueries
220
+ .edgesTouching(
221
+ filter,
222
+ nodes.map(node => node.id),
223
+ edgeLimit
224
+ )
225
+ .filter(edge => firstTime(edge.source, edge.target))
226
+ .map(edge => ({ ...edge, targetX: tidy(edge.targetX), targetY: tidy(edge.targetY) }));
227
+ return { ...empty, nodes, edges };
228
+ }
242
229
 
243
- // An edge between two singles is a real edge between two real memories, and
244
- // the canvas dims and highlights those against the node it is anchored on.
245
- // Demoting it to a bin edge would break hover on exactly the marks that did
246
- // not need binning in the first place.
247
- if (byId.has(source) && byId.has(target)) {
248
- nodeEdges.push({
249
- id: syntheticId--,
230
+ // Folded, into no more cells than its share of the budget. Cell coordinates
231
+ // are global at this zoom, so an edge from any other tile can name the cell
232
+ // it lands in without knowing this tile.
233
+ const cellsPerSide = Math.max(4, Math.min(MAX_CELLS_PER_SIDE, Math.floor(Math.sqrt(allowed))));
234
+ const cellGrid = { originX: world.minX, originY: world.minY, size: tileSize / cellsPerSide };
235
+ const nodes: GraphTileNode[] = [];
236
+ const clusters: GraphTileCluster[] = [];
237
+ const markOfCell = new Map<string, string>();
238
+
239
+ for (const cell of graphLayoutQueries.tileCells(filter, rect, cellGrid)) {
240
+ const key = `${cell.cellX}:${cell.cellY}`;
241
+ if (cell.members === 1) {
242
+ nodes.push(round(cell));
243
+ markOfCell.set(key, cell.id);
244
+ continue;
245
+ }
246
+ const id = `cluster:${z}:${cell.cellX}:${cell.cellY}`;
247
+ clusters.push({
248
+ id,
249
+ members: cell.members,
250
+ label: cell.label,
251
+ community: cell.community,
252
+ x: tidy(cell.x),
253
+ y: tidy(cell.y),
254
+ cellX: cell.cellX,
255
+ cellY: cell.cellY
256
+ });
257
+ markOfCell.set(key, id);
258
+ }
259
+
260
+ const cellEdges: GraphTileCellEdge[] = [];
261
+ for (const edge of graphLayoutQueries.cellEdges(filter, rect, cellGrid, edgeLimit)) {
262
+ const source = markOfCell.get(`${edge.sourceCellX}:${edge.sourceCellY}`);
263
+ if (!source) continue;
264
+ if (!firstTime(`${z}:${edge.sourceCellX}:${edge.sourceCellY}`, `${z}:${edge.targetCellX}:${edge.targetCellY}`)) {
265
+ continue;
266
+ }
267
+ cellEdges.push({
250
268
  source,
251
- target,
252
- rel: 'relates_to',
269
+ targetCellX: edge.targetCellX,
270
+ targetCellY: edge.targetCellY,
253
271
  weight: edge.weight
254
272
  });
255
- } else {
256
- binEdges.push({ source, target, weight: edge.weight });
257
273
  }
258
- }
259
274
 
260
- // Degree over what is drawn, same as the flat path — counting both kinds of
261
- // edge, because a memory next to a dense clump is well connected whether or
262
- // not the thing it connects to had to be merged.
263
- const degree = new Map<string, number>();
264
- const bump = (id: string): void => {
265
- degree.set(id, (degree.get(id) ?? 0) + 1);
266
- };
267
- for (const edge of nodeEdges) {
268
- bump(edge.source);
269
- bump(edge.target);
270
- }
271
- for (const edge of binEdges) {
272
- bump(edge.source);
273
- bump(edge.target);
274
- }
275
+ return { ...empty, cells: cellsPerSide, nodes, clusters, cellEdges };
276
+ });
275
277
 
276
- const bins: GraphViewBin[] = groups.map(cell => ({
277
- id: binId(cell.cellX, cell.cellY),
278
- members: cell.members,
279
- label: truncate(cell.label ?? ''),
280
- community: cell.community,
281
- x: cell.x,
282
- y: cell.y,
283
- region: {
284
- minX: grid.originX + cell.cellX * grid.cellWidth,
285
- maxX: grid.originX + (cell.cellX + 1) * grid.cellWidth,
286
- minY: grid.originY + cell.cellY * grid.cellHeight,
287
- maxY: grid.originY + (cell.cellY + 1) * grid.cellHeight
288
- }
289
- }));
290
-
291
- return {
292
- level: 'binned',
293
- nodes: singles
294
- .map(cell => byId.get(cell.id))
295
- .filter((node): node is GraphNode => node !== undefined)
296
- .map(node => toViewNode(node, degree.get(node.id) ?? 0, layout.get(node.id))),
297
- edges: nodeEdges,
298
- bins,
299
- binEdges,
300
- region: null,
301
- totalNodes: extent.total,
302
- // Nothing was left out — every memory is inside one of these marks. The
303
- // only thing a binned view withholds is which memory is which inside a
304
- // crowd, and opening the mark answers that.
305
- truncated: nodes.length + bins.length > limit
306
- };
278
+ return { epoch: state.epoch, stale: false, tiles };
307
279
  }
308
280
 
309
281
  /**
310
- * The grid, sized so the number of cells cannot exceed the render budget.
282
+ * Share the screen's budget between tiles, sparse ones first.
311
283
  *
312
- * Cells are square in layout space rather than fitted to the extent's aspect
313
- * ratio: a non-square cell merges more readily along one axis than the other,
314
- * which shows up as marks that smear horizontally or vertically — the eye reads
315
- * that as structure, and there is none.
284
+ * Water-filling: walking the tiles from least to most crowded, each takes what
285
+ * it holds if that is within an even split of what is left, and the crowded
286
+ * remainder share the rest equally. So a tile is only ever folded when the
287
+ * screen as a whole could not afford it, and then only the crowded ones are.
316
288
  */
317
- function gridFor(extent: { minX: number; maxX: number; minY: number; maxY: number }): GraphBinGrid {
318
- const width = Math.max(1e-6, extent.maxX - extent.minX);
319
- const height = Math.max(1e-6, extent.maxY - extent.minY);
320
-
321
- // One axis of the grid. Squared, this is the cell count, so it is the budget's
322
- // square root — and the longer side sets the cell size for both.
323
- const perAxis = Math.max(1, Math.floor(Math.sqrt(RENDER_BUDGET)));
324
- const cell = Math.max(width, height) / perAxis;
325
-
326
- return {
327
- originX: extent.minX,
328
- originY: extent.minY,
329
- cellWidth: cell,
330
- cellHeight: cell
331
- };
332
- }
333
-
334
- function toViewNode(
335
- node: GraphNode,
336
- degree: number,
337
- placed?: { community: number; x: number; y: number; placed: number }
338
- ): GraphViewNode {
339
- return {
340
- id: node.id,
341
- subkind: node.subkind,
342
- scope: node.scope,
343
- label: node.label,
344
- projectId: node.projectId,
345
- degree,
346
- weight: node.weight,
347
- pinned: node.pinned,
348
- community: placed?.community ?? 0,
349
- createdAt: node.createdAt,
350
- // Sent ONLY when the simulation computed it. A memory written since the
351
- // last pass has no row at all, and one below the simulation cap has a row
352
- // holding a guess — in both cases the client seeds it from its neighbours,
353
- // which is a far better answer than drawing a whole lobe on one point.
354
- ...(placed?.placed === 1 && { x: placed.x, y: placed.y })
355
- };
289
+ function shareBudget(counts: number[], budget: number): number[] {
290
+ const allowance = new Array<number>(counts.length).fill(0);
291
+ const order = counts.map((count, index) => ({ count, index })).sort((a, b) => a.count - b.count);
292
+ let remaining = budget;
293
+ for (let i = 0; i < order.length; i++) {
294
+ const share = Math.floor(remaining / (order.length - i));
295
+ const take = Math.min(order[i].count, share);
296
+ allowance[order[i].index] = order[i].count <= share ? order[i].count : Math.max(16, share);
297
+ remaining -= take;
298
+ }
299
+ return allowance;
356
300
  }
357
301
 
358
302
  /**
359
- * Give a position to anything the arrangement has not reached yet.
360
- *
361
- * A memory recorded while the modal is open has no layout row: the background
362
- * pass is debounced behind the notification that announces the memory, so the
363
- * first fetch after it lands is always a few seconds early. Sending it without
364
- * coordinates left the client to invent some, and what it invented was the
365
- * middle of the map — a new memory appearing nowhere near the subject it is
366
- * about.
303
+ * Where particular memories are on the map, whatever the client has loaded.
367
304
  *
368
- * Derived HERE instead, from the same rule the layout pass itself uses: the
369
- * centroid of whatever it connects to. The answer is therefore the one the pass
370
- * will confirm a few seconds later rather than one it will have to correct, and
371
- * the client stops having an opinion about placement at all.
372
- *
373
- * Read-time only — nothing is written. A position that has not been through the
374
- * simulation is a guess, and guesses do not belong in the table the simulation
375
- * owns.
376
- *
377
- * A node with no placed neighbour is deliberately LEFT without a position. That
378
- * is the honest signal for "the arrangement does not cover this yet", and it is
379
- * what the client's cold fallback keys on — inventing a centroid for a store that
380
- * has never been laid out would replace a considered scatter with a meaningless
381
- * one.
305
+ * What lets the view go TO a memory it has not drawn: a search result, a
306
+ * connection listed in the inspector, a step back through history. A memory the
307
+ * layout has not placed yet is simply absent from the answer.
382
308
  */
383
- function placeArrivals(nodes: GraphViewNode[], edges: { source: string; target: string }[]): void {
384
- const arrivals = nodes.filter(node => node.x === undefined);
385
- if (arrivals.length === 0) return;
386
-
387
- const byId = new Map(nodes.map(node => [node.id, node]));
388
- const adjacency = new Map<string, string[]>();
389
- const link = (from: string, to: string): void => {
390
- const neighbours = adjacency.get(from);
391
- if (neighbours) neighbours.push(to);
392
- else adjacency.set(from, [to]);
393
- };
394
- for (const edge of edges) {
395
- link(edge.source, edge.target);
396
- link(edge.target, edge.source);
397
- }
398
-
399
- // Three passes, so a small cluster of arrivals resolves outward from whichever
400
- // end touches the existing map rather than all of them giving up at once.
401
- for (let pass = 0; pass < 3; pass++) {
402
- let settled = 0;
403
-
404
- for (const node of arrivals) {
405
- if (node.x !== undefined) continue;
406
-
407
- let sumX = 0;
408
- let sumY = 0;
409
- let count = 0;
410
- for (const neighbour of adjacency.get(node.id) ?? []) {
411
- const other = byId.get(neighbour);
412
- if (!other || other.x === undefined || other.y === undefined) continue;
413
- sumX += other.x;
414
- sumY += other.y;
415
- count++;
416
- }
417
- if (count === 0) continue;
418
-
419
- // Nudged off the exact centroid, or several arrivals about one subject
420
- // land on the same point and read as a single node.
421
- const jitter = jitterOf(node.id);
422
- node.x = sumX / count + jitter.x * 24;
423
- node.y = sumY / count + jitter.y * 24;
424
- settled++;
425
- }
309
+ export function locateNodes(nodeIds: string[]): GraphTileNode[] {
310
+ return graphLayoutQueries.locate(nodeIds.slice(0, 500)).map(round);
311
+ }
426
312
 
427
- if (settled === 0) break;
428
- }
313
+ /** Positions are drawn on a screen; a tenth of a unit is far below a pixel. */
314
+ function tidy(value: number): number {
315
+ return Math.round(value * 10) / 10;
429
316
  }
430
317
 
431
- /** A deterministic offset in [-1, 1]², derived from an id. FNV-1a. */
432
- function jitterOf(id: string): { x: number; y: number } {
433
- let hash = 2166136261;
434
- for (let i = 0; i < id.length; i++) {
435
- hash ^= id.charCodeAt(i);
436
- hash = Math.imul(hash, 16777619);
437
- }
438
- hash = hash >>> 0;
318
+ function round(node: GraphTileNode): GraphTileNode {
439
319
  return {
440
- x: ((hash % 65536) / 65536) * 2 - 1,
441
- y: (((hash >>> 16) % 65536) / 65536) * 2 - 1
320
+ id: node.id,
321
+ label: node.label,
322
+ community: node.community,
323
+ degree: node.degree,
324
+ x: tidy(node.x),
325
+ y: tidy(node.y)
442
326
  };
443
327
  }
444
328
 
445
- /** Namespaced so a bin's id can never collide with a node's. */
446
- function binId(cellX: number, cellY: number): string {
447
- return `bin:${cellX}:${cellY}`;
448
- }
449
-
450
- function cellKey(cellX: number, cellY: number): string {
451
- return `${cellX}:${cellY}`;
452
- }
453
-
454
- function truncate(label: string): string {
455
- return label.length > BIN_LABEL_MAX ? `${label.slice(0, BIN_LABEL_MAX - 1)}…` : label;
456
- }
457
-
458
329
  /**
459
330
  * A node plus the nodes it reaches — what the inspector renders.
460
331
  *