@bastani/atomic 0.10.10 → 0.10.11-alpha.2

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 (402) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/README.md +1 -1
  3. package/dist/_shared/dist-KOELCESV.js +2 -2
  4. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  5. package/dist/_shared/lib-4PES5P4V.js +2 -2
  6. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +11 -13
  7. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
  8. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +9 -9
  9. package/dist/_shared/mode-shared-2QJSCUM6.js +55 -18
  10. package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
  11. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  12. package/dist/_shared/runtime-O4KCSG4C.js +5 -5
  13. package/dist/_shared/{sdk-RRLVN7ER.js → sdk-IQMULKFU.js} +2962 -470
  14. package/dist/_shared/sdk-IQMULKFU.js.map +1 -0
  15. package/dist/_shared/session-data-AHTU7IS6.js +4 -4
  16. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  17. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
  18. package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
  19. package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
  20. package/dist/_shared/{startup-0-0-4VG2G44V.js → startup-0-0-3IXNMFM2.js} +482 -53
  21. package/dist/_shared/startup-0-0-3IXNMFM2.js.map +1 -0
  22. package/dist/_shared/{startup-0-1-XTIL65D4.js → startup-0-1-7T2IAE7J.js} +121 -251
  23. package/dist/_shared/startup-0-1-7T2IAE7J.js.map +1 -0
  24. package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +293 -10
  25. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
  26. package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
  27. package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
  28. package/dist/_shared/startup-0-4-ZMJV547D.js +6 -6
  29. package/dist/_shared/{startup-0-5-FD2P735I.js → startup-0-5-YDW47QX6.js} +29 -71
  30. package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -0
  31. package/dist/_shared/startup-10-0-TDQNBDDL.js +9 -9
  32. package/dist/_shared/startup-12-0-55AAXBJZ.js +4 -4
  33. package/dist/_shared/startup-14-0-MLX36RBG.js +6 -6
  34. package/dist/_shared/startup-15-0-YUKGAC63.js +34 -10
  35. package/dist/_shared/startup-15-0-YUKGAC63.js.map +1 -1
  36. package/dist/_shared/startup-15-1-4S7FLMNG.js +10 -9
  37. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  38. package/dist/_shared/startup-8-0-34CBHPZH.js +421 -84
  39. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  40. package/dist/_shared/{startup-8-1-4KANEHRA.js → startup-8-1-X32CYSXB.js} +1291 -722
  41. package/dist/_shared/startup-8-1-X32CYSXB.js.map +1 -0
  42. package/dist/_shared/storage-command-7MGXLJGZ.js +17 -9
  43. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  44. package/dist/_shared/task-reference-stream-JWMUZSJX.js +1 -1
  45. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  46. package/dist/_shared/tree-outline-MUEPK5B7.js +3 -3
  47. package/dist/builtin/intercom/CHANGELOG.md +29 -0
  48. package/dist/builtin/intercom/broker/broker.bundle.mjs +1138 -384
  49. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +103 -24
  50. package/dist/builtin/intercom/broker/multinode-router.ts +42 -21
  51. package/dist/builtin/intercom/broker/multinode-state-store.ts +22 -1
  52. package/dist/builtin/intercom/broker/open-broker-state.ts +82 -31
  53. package/dist/builtin/intercom/broker/paths.ts +8 -4
  54. package/dist/builtin/intercom/broker/released-asker-remote-replies.ts +18 -6
  55. package/dist/builtin/intercom/broker/sql-add-column.ts +4 -1
  56. package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +65 -44
  57. package/dist/builtin/intercom/broker/sql-held-send-store.ts +11 -3
  58. package/dist/builtin/intercom/broker/sql-known-session-store.ts +24 -12
  59. package/dist/builtin/intercom/broker/sql-lease-store.ts +386 -65
  60. package/dist/builtin/intercom/broker/sql-outbox-store.ts +462 -130
  61. package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +20 -9
  62. package/dist/builtin/intercom/broker/sql-released-ask-store.ts +14 -6
  63. package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +27 -11
  64. package/dist/builtin/intercom/broker/sql-schema.ts +198 -5
  65. package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +97 -34
  66. package/dist/builtin/intercom/index.bundle.mjs +11 -8
  67. package/dist/builtin/intercom/package.json +1 -1
  68. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  69. package/dist/builtin/mcp/package.json +1 -1
  70. package/dist/builtin/subagents/CHANGELOG.md +18 -0
  71. package/dist/builtin/subagents/package.json +1 -1
  72. package/dist/builtin/subagents/skills/skill-creator/SKILL.md +1 -1
  73. package/dist/builtin/subagents/src/extension/index.bundle.mjs +62 -23
  74. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  75. package/dist/builtin/web-access/package.json +1 -1
  76. package/dist/cli/args.js +2 -2
  77. package/dist/cli/auth-cli.code.js +6 -6
  78. package/dist/cli/auth-cli.impl.js +3 -3
  79. package/dist/cli/auth-cli.js +3 -3
  80. package/dist/cli/blueprint-command.code.js +4 -4
  81. package/dist/cli/blueprint-command.impl.js +3 -3
  82. package/dist/cli/blueprint-command.js +3 -3
  83. package/dist/cli/intercom-command.code.js +3 -3
  84. package/dist/cli/intercom-command.impl.js +3 -3
  85. package/dist/cli/intercom-command.js +3 -3
  86. package/dist/cli/list-models.code.js +2 -2
  87. package/dist/cli/list-models.impl.js +3 -3
  88. package/dist/cli/list-models.js +3 -3
  89. package/dist/cli/session-picker.code.js +2 -2
  90. package/dist/cli/session-picker.impl.js +3 -3
  91. package/dist/cli/session-picker.js +3 -3
  92. package/dist/cli/startup-ui.code.js +2 -2
  93. package/dist/cli/startup-ui.impl.js +3 -3
  94. package/dist/cli/startup-ui.js +3 -3
  95. package/dist/cli/storage-command.impl.js +3 -3
  96. package/dist/cli/storage-command.js +3 -3
  97. package/dist/cli/storage-search-session.code.js +3 -3
  98. package/dist/cli/storage-search-session.impl.js +3 -3
  99. package/dist/cli/storage-search-session.js +3 -3
  100. package/dist/cli/team-command.code.js +3 -3
  101. package/dist/cli/team-command.impl.js +3 -3
  102. package/dist/cli/team-command.js +3 -3
  103. package/dist/cli.js +2 -2
  104. package/dist/core/agent-session-methods.d.ts +3 -0
  105. package/dist/core/agent-session-methods.js.map +1 -1
  106. package/dist/core/agent-session.d.ts +1 -0
  107. package/dist/core/compaction/compactor.d.ts +2 -0
  108. package/dist/core/debug.impl.js +3 -3
  109. package/dist/core/debug.js +3 -3
  110. package/dist/core/export-html/card-projection.code.js +1 -1
  111. package/dist/core/export-html/card-projection.impl.js +3 -3
  112. package/dist/core/export-html/card-projection.js +3 -3
  113. package/dist/core/export-html/index.code.js +2 -2
  114. package/dist/core/export-html/index.impl.js +3 -3
  115. package/dist/core/export-html/index.js +3 -3
  116. package/dist/core/export-html/json-spans.impl.js +3 -3
  117. package/dist/core/export-html/json-spans.js +3 -3
  118. package/dist/core/export-html/oversized-render-inputs.code.js +2 -2
  119. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  120. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  121. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  122. package/dist/core/export-html/tool-renderer.js +3 -3
  123. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  124. package/dist/core/extensions/jiti-loader.js +3 -3
  125. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  126. package/dist/core/extensions/jiti-static-loader.js +3 -3
  127. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  128. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  129. package/dist/core/extensions/loader-host-modules.js +3 -3
  130. package/dist/core/extensions/loader-virtual-modules.js +2 -2
  131. package/dist/core/extensions/runner-context.js +4 -4
  132. package/dist/core/extensions/runner-context.js.map +1 -1
  133. package/dist/core/intercom-broker-control-host.code.js +1 -1
  134. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  135. package/dist/core/intercom-broker-control-host.js +3 -3
  136. package/dist/core/intercom-broker-control.code.js +3 -3
  137. package/dist/core/intercom-broker-control.impl.js +3 -3
  138. package/dist/core/intercom-broker-control.js +3 -3
  139. package/dist/core/model-registry.js +1 -1
  140. package/dist/core/model-resolver-defaults.d.ts +3 -2
  141. package/dist/core/package-manager-storage-adapters.code.js +1 -1
  142. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  143. package/dist/core/package-manager-storage-adapters.js +3 -3
  144. package/dist/core/sdk.code.js +4 -5
  145. package/dist/core/sdk.impl.js +3 -3
  146. package/dist/core/sdk.js +3 -3
  147. package/dist/core/session-manager-core.d.ts +5 -2
  148. package/dist/core/session-manager-core.js +39 -23
  149. package/dist/core/session-manager-core.js.map +1 -1
  150. package/dist/core/session-manager-list.impl.js +3 -3
  151. package/dist/core/session-manager-list.js +3 -3
  152. package/dist/core/session-manager.code.js +3 -3
  153. package/dist/core/session-manager.impl.js +3 -3
  154. package/dist/core/session-manager.js +3 -3
  155. package/dist/core/session-open-markers.js +3 -0
  156. package/dist/core/session-open-markers.js.map +1 -0
  157. package/dist/core/session-storage.code.js +1 -1
  158. package/dist/core/session-storage.impl.js +3 -3
  159. package/dist/core/session-storage.js +3 -3
  160. package/dist/core/storage/added-exports.d.ts +6 -0
  161. package/dist/core/storage/added-exports.js +19 -0
  162. package/dist/core/storage/added-exports.js.map +1 -0
  163. package/dist/core/storage/database.d.ts +53 -0
  164. package/dist/core/storage/database.js.map +1 -1
  165. package/dist/core/storage/fenced-paths.d.ts +47 -0
  166. package/dist/core/storage/fenced-paths.js +53 -0
  167. package/dist/core/storage/fenced-paths.js.map +1 -1
  168. package/dist/core/storage/file-identity.js +31 -2
  169. package/dist/core/storage/file-identity.js.map +1 -1
  170. package/dist/core/storage/index.d.ts +4 -1
  171. package/dist/core/storage/index.js +5 -2
  172. package/dist/core/storage/index.js.map +1 -1
  173. package/dist/core/storage/migrations.d.ts +33 -2
  174. package/dist/core/storage/migrations.js +73 -5
  175. package/dist/core/storage/migrations.js.map +1 -1
  176. package/dist/core/storage/node-sqlite-thread.js +48 -6
  177. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  178. package/dist/core/storage/node-sqlite.js +137 -4
  179. package/dist/core/storage/node-sqlite.js.map +1 -1
  180. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  181. package/dist/core/storage/offline-snapshot-file.js +3 -3
  182. package/dist/core/storage/prefix.d.ts +3 -2
  183. package/dist/core/storage/prefix.js +23 -2
  184. package/dist/core/storage/prefix.js.map +1 -1
  185. package/dist/core/storage/provider.js +2 -2
  186. package/dist/core/storage/schema-catalog.d.ts +120 -0
  187. package/dist/core/storage/schema-catalog.js +351 -0
  188. package/dist/core/storage/schema-catalog.js.map +1 -0
  189. package/dist/core/storage/selection.js +2 -2
  190. package/dist/core/storage/session/branch-fork-source.code.js +47 -25
  191. package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
  192. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  193. package/dist/core/storage/session/branch-fork-source.js +3 -3
  194. package/dist/core/storage/session/card-view.impl.js +3 -3
  195. package/dist/core/storage/session/card-view.js +3 -3
  196. package/dist/core/storage/session/child-reader.code.js +4 -4
  197. package/dist/core/storage/session/child-reader.impl.js +3 -3
  198. package/dist/core/storage/session/child-reader.js +3 -3
  199. package/dist/core/storage/session/chunked-resume-projection.code.js +1 -1
  200. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  201. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  202. package/dist/core/storage/session/errors.js +1 -1
  203. package/dist/core/storage/session/expanded-child-details.code.js +4 -4
  204. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  205. package/dist/core/storage/session/expanded-child-details.js +3 -3
  206. package/dist/core/storage/session/fork-detach.d.ts +118 -0
  207. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  208. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  209. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  210. package/dist/core/storage/session/fork-row-index.js +3 -3
  211. package/dist/core/storage/session/fork-schema.js +53 -0
  212. package/dist/core/storage/session/fork-schema.js.map +1 -0
  213. package/dist/core/storage/session/fork-segments.d.ts +58 -0
  214. package/dist/core/storage/session/fork-staging.code.js +176 -36
  215. package/dist/core/storage/session/fork-staging.code.js.map +1 -1
  216. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  217. package/dist/core/storage/session/fork-staging.js +3 -3
  218. package/dist/core/storage/session/fork-sweep.js +61 -0
  219. package/dist/core/storage/session/fork-sweep.js.map +1 -0
  220. package/dist/core/storage/session/fork-window.code.js +4 -4
  221. package/dist/core/storage/session/fork-window.impl.js +3 -3
  222. package/dist/core/storage/session/fork-window.js +3 -3
  223. package/dist/core/storage/session/history-pages.impl.js +3 -3
  224. package/dist/core/storage/session/history-pages.js +3 -3
  225. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  226. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  227. package/dist/core/storage/session/jsonl-session-store.d.ts +37 -1
  228. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  229. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  230. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  231. package/dist/core/storage/session/memory-session-store.js +3 -3
  232. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  233. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  234. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  235. package/dist/core/storage/session/released-history-files.code.js +3 -3
  236. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  237. package/dist/core/storage/session/released-history-files.js +3 -3
  238. package/dist/core/storage/session/resident-fork-rows.code.js +1 -1
  239. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  240. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  241. package/dist/core/storage/session/session-resume.impl.js +3 -3
  242. package/dist/core/storage/session/session-resume.js +3 -3
  243. package/dist/core/storage/session/session-search-index.d.ts +5 -0
  244. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  245. package/dist/core/storage/session/snapshot-cut.js +3 -3
  246. package/dist/core/storage/session/snapshot-history.code.js +4 -4
  247. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  248. package/dist/core/storage/session/snapshot-history.js +3 -3
  249. package/dist/core/storage/session/sql-chat-records.d.ts +15 -0
  250. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  251. package/dist/core/storage/session/sql-session-store.d.ts +445 -11
  252. package/dist/core/storage/session/sql-session-store.impl.js +4 -4
  253. package/dist/core/storage/session/sql-session-store.js +4 -4
  254. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  255. package/dist/core/storage/session/tree-outline.js +3 -3
  256. package/dist/core/storage/session/tree-presentation.code.js +1 -1
  257. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  258. package/dist/core/storage/session/tree-presentation.js +3 -3
  259. package/dist/core/storage/session/types.d.ts +36 -0
  260. package/dist/core/storage/sqlite-facade.d.ts +54 -6
  261. package/dist/core/storage/sqlite-facade.js +384 -18
  262. package/dist/core/storage/sqlite-facade.js.map +1 -1
  263. package/dist/core/storage/statement-sequence.d.ts +83 -0
  264. package/dist/core/storage/statement-sequence.js +21 -0
  265. package/dist/core/storage/statement-sequence.js.map +1 -1
  266. package/dist/core/storage/storage-status.code.js +1 -1
  267. package/dist/core/storage/storage-status.impl.js +3 -3
  268. package/dist/core/storage/storage-status.js +3 -3
  269. package/dist/core/storage/team.code.js +1 -1
  270. package/dist/core/storage/team.impl.js +3 -3
  271. package/dist/core/storage/team.js +3 -3
  272. package/dist/core/structured-output/index.code.js +1 -1
  273. package/dist/core/structured-output/index.impl.js +3 -3
  274. package/dist/core/structured-output/index.js +3 -3
  275. package/dist/core/tasks/task-completion-entry.code.js +1 -1
  276. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  277. package/dist/core/tasks/task-completion-entry.js +3 -3
  278. package/dist/core/tasks/task-file-history.code.js +4 -4
  279. package/dist/core/tasks/task-file-history.impl.js +3 -3
  280. package/dist/core/tasks/task-file-history.js +3 -3
  281. package/dist/core/tasks/task-reference-archive.code.js +5 -5
  282. package/dist/core/tasks/task-reference-archive.js +3 -3
  283. package/dist/core/tasks/task-reference-identity.js +3 -3
  284. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  285. package/dist/core/tasks/task-reference-stream.js +3 -3
  286. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  287. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  288. package/dist/core/tasks/task-view-source.code.js +1 -1
  289. package/dist/core/tasks/task-view-source.impl.js +3 -3
  290. package/dist/core/tasks/task-view-source.js +3 -3
  291. package/dist/core/tools/bash.d.ts +8 -4
  292. package/dist/core/tools/history-session.d.ts +7 -0
  293. package/dist/core/tools/history-tasks.d.ts +123 -0
  294. package/dist/core/tools/kill.d.ts +5 -2
  295. package/dist/core/tools/powershell.d.ts +2 -2
  296. package/dist/core/tools/read-url.code.js +3 -3
  297. package/dist/core/tools/read-url.impl.js +3 -3
  298. package/dist/core/tools/read-url.js +3 -3
  299. package/dist/core/tools/read.d.ts +12 -2
  300. package/dist/core/tools/resource-selectors.d.ts +2 -0
  301. package/dist/core/tools/search.d.ts +12 -2
  302. package/dist/core/worktree-snapshot/blob-store.d.ts +45 -2
  303. package/dist/core/worktree-snapshot/blob-store.js +228 -60
  304. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  305. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  306. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  307. package/dist/core/worktree-snapshot/errors.js +3 -3
  308. package/dist/core/worktree-snapshot/fork-snapshot-index.js +121 -0
  309. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
  310. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  311. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  312. package/dist/extensions/codemode/execute.code.js +3 -3
  313. package/dist/extensions/codemode/execute.impl.js +3 -3
  314. package/dist/extensions/codemode/execute.js +3 -3
  315. package/dist/extensions/codemode/renderer.code.js +2 -2
  316. package/dist/extensions/codemode/renderer.impl.js +3 -3
  317. package/dist/extensions/codemode/renderer.js +3 -3
  318. package/dist/extensions/mcp/cli.code.js +3 -3
  319. package/dist/extensions/mcp/cli.impl.js +3 -3
  320. package/dist/extensions/mcp/cli.js +3 -3
  321. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  322. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  323. package/dist/extensions/mcp/cli.lazy.js +3 -3
  324. package/dist/extensions/mcp/runtime.code.js +1 -1
  325. package/dist/extensions/mcp/runtime.impl.js +3 -3
  326. package/dist/extensions/mcp/runtime.js +3 -3
  327. package/dist/index.js +8 -8
  328. package/dist/main-first-time-setup.code.js +2 -2
  329. package/dist/main-first-time-setup.impl.js +3 -3
  330. package/dist/main-first-time-setup.js +3 -3
  331. package/dist/main.js +1 -1
  332. package/dist/modes/interactive/components/agent-panel.d.ts +1 -0
  333. package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
  334. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  335. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  336. package/dist/modes/interactive/components/task-inspector.d.ts +2 -0
  337. package/dist/modes/interactive/components/user-message-selector-archive.code.js +1 -1
  338. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  339. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  340. package/dist/modes/interactive/interactive-mode-helpers.d.ts +2 -2
  341. package/dist/modes/print-mode.js +1 -1
  342. package/dist/modes/rpc/agent-panel-bridge.d.ts +5 -0
  343. package/dist/package-manager-cli.code.js +7 -7
  344. package/dist/package-manager-cli.impl.js +3 -3
  345. package/dist/package-manager-cli.js +3 -3
  346. package/dist/rpc-entry.js +1 -1
  347. package/dist/startup-files.json +1 -1
  348. package/dist/startup-stages/0.js +1 -1
  349. package/dist/startup-stages/1.js +1 -1
  350. package/dist/startup-stages/10.js +1 -1
  351. package/dist/startup-stages/12.js +1 -1
  352. package/dist/startup-stages/2.js +9 -1
  353. package/dist/startup-stages/3.js +1 -6
  354. package/dist/startup-stages/5.js +1 -1
  355. package/dist/startup-stages/7.js +1 -1
  356. package/dist/startup-stages/8.js +2 -2
  357. package/dist/utils/startup-database-spare.code.js +3 -3
  358. package/dist/utils/startup-database-spare.impl.js +3 -3
  359. package/dist/utils/startup-database-spare.js +3 -3
  360. package/dist/utils/tools-manager.code.js +1 -1
  361. package/dist/utils/tools-manager.impl.js +3 -3
  362. package/dist/utils/tools-manager.js +3 -3
  363. package/docs/background-tasks.md +123 -23
  364. package/docs/compaction.md +18 -0
  365. package/docs/docs.json +2 -0
  366. package/docs/environment-variables.md +1 -1
  367. package/docs/getting-started/installation.md +9 -2
  368. package/docs/guides/postgres-pgbouncer.md +346 -0
  369. package/docs/guides/postgres-tuning.md +311 -0
  370. package/docs/guides/resume-on-any-machine.md +2 -2
  371. package/docs/guides.md +2 -0
  372. package/docs/index.md +1 -1
  373. package/docs/libraries/agent-core.md +1 -1
  374. package/docs/libraries/ai.md +2 -2
  375. package/docs/libraries/codemode.md +1 -1
  376. package/docs/libraries/storage-libsql.md +6 -1
  377. package/docs/libraries/storage-postgres.md +11 -6
  378. package/docs/libraries/tui.md +1 -1
  379. package/docs/libraries.md +2 -2
  380. package/docs/programmatic.md +1 -1
  381. package/docs/quickstart.md +1 -1
  382. package/docs/sdk/storage.md +1 -1
  383. package/docs/sdk/web-server.md +1 -3
  384. package/docs/sdk.md +1 -7
  385. package/docs/sessions.md +67 -2
  386. package/docs/settings.md +20 -1
  387. package/docs/skills/authoring.md +1 -1
  388. package/docs/skills.md +79 -6
  389. package/docs/storage.md +305 -14
  390. package/docs/subagents/reference.md +2 -2
  391. package/docs/subagents.md +4 -3
  392. package/docs/tools.md +44 -10
  393. package/docs/windows.md +1 -1
  394. package/package.json +9 -9
  395. package/dist/_shared/sdk-RRLVN7ER.js.map +0 -1
  396. package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
  397. package/dist/_shared/startup-0-0-4VG2G44V.js.map +0 -1
  398. package/dist/_shared/startup-0-1-XTIL65D4.js.map +0 -1
  399. package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
  400. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
  401. package/dist/_shared/startup-0-5-FD2P735I.js.map +0 -1
  402. package/dist/_shared/startup-8-1-4KANEHRA.js.map +0 -1
@@ -1,8 +1,11 @@
1
+ import { transactionFinisher } from "../storage/added-exports.js";
1
2
  import { dialectOf } from "../storage/dialect.js";
2
3
  import { StorageWriteLockTimeoutError } from "../storage/errors.js";
3
4
  import { applyStorageMigrations, withShortSchemaLockWaits } from "../storage/migrations.js";
4
5
  import { renderStorageIdentifiers, storageMigrationTable, validateStoragePrefix } from "../storage/prefix.js";
6
+ import { schemaCatalogOf } from "../storage/schema-catalog.js";
5
7
  import { statementBatch } from "../storage/statement-batches.js";
8
+ import { entriesIndexComplete, forkSegmentsTable, forkSessionLink, legacyForkLinksTriggerName, parentColumns, snapshotEntryCondition, } from "./fork-snapshot-index.js";
6
9
  /**
7
10
  * The key under which a failed rename's error carries the trigger or view that stopped it, once confirmed in the
8
11
  * database (#5622); `WorkspaceCollectionError` names it in its hint. A `Symbol.for` key, shared without an import.
@@ -40,6 +43,13 @@ export function snapshotBlobHashes(snapshot) {
40
43
  hashes.push(snapshot.bundle.blob);
41
44
  return [...new Set(hashes)];
42
45
  }
46
+ /**
47
+ * Compares two blob hashes as `ORDER BY hash` with the dialect's `byteOrderCollation` does: the hashes are ASCII (hex
48
+ * digests), whose UTF-16 code unit order is their byte order.
49
+ */
50
+ function byteOrder(first, second) {
51
+ return first < second ? -1 : first > second ? 1 : 0;
52
+ }
43
53
  /**
44
54
  * The blob hashes a recorded snapshot names, read as the reference index reads them: a write never fails on a record
45
55
  * whose chain or bundle is not well formed, which references nothing it cannot read.
@@ -419,10 +429,6 @@ function statusCondition(d, column) {
419
429
  const payload = column("payload");
420
430
  return `${column("type")} IN (${STATUS_EVENTS}) AND ${whenValidJson(d, payload, `${d.jsonHasType("text", payload, "workflowId")} AND ${d.jsonHasType("text", payload, "status")} AND ${d.jsonType(payload, "completedCheckpoints")} IN ('integer', 'real') AND ${d.jsonType(payload, "pendingPrompts")} IN ('integer', 'real')`)}`;
421
431
  }
422
- function snapshotEntryCondition(d, column) {
423
- const entry = column("entry_json");
424
- return `${d.contains(entry, `'"worktree_snapshot"'`)} AND ${d.jsonText(entry, "type")} = 'worktree_snapshot' AND ${d.jsonHasType("text", entry, "root")} AND ${d.jsonHasType("text", entry, "snapshotId")}`;
425
- }
426
432
  /**
427
433
  * The SQL form of `isDurableWorkflowResumable` for the status payload `payload`, given that the run has a snapshot
428
434
  * reference and so at least one checkpoint: a root run keeps its snapshots while it is failed or blocked, or running or
@@ -490,7 +496,12 @@ function withMarker(trigger, marker) {
490
496
  const [first, ...rest] = trigger.statements;
491
497
  return { ...trigger, statements: [`/* ${marker} */ ${first}`, ...rest] };
492
498
  }
493
- function indexSources(prefix, t, d) {
499
+ /**
500
+ * The tables whose rows reference snapshot blobs, and how each is indexed. `forkSegments` names the sessions' fork
501
+ * segments table when it exists (#6560): the backfill of the session entries then also links an entry whose parent
502
+ * the session inherits, as the session store does when it writes one (`forkLinkWrites`).
503
+ */
504
+ function indexSources(prefix, t, d, forkSegments) {
494
505
  const { events, runs } = renderStorageIdentifiers("journal", { events: "events", runs: "runs" }, prefix);
495
506
  const { entries } = renderStorageIdentifiers("sessions", { entries: "entries" }, prefix);
496
507
  const payload = { column: "r.payload" };
@@ -573,11 +584,11 @@ function indexSources(prefix, t, d) {
573
584
  };
574
585
  const entryColumns = ["session_id", "seq", "entry_id", "entry_json"];
575
586
  /** One entry as `r`, with its parent named once, so that each statement parses the entry's JSON for it only once. */
576
- const parentColumns = (json) => `${d.jsonText(json, "parentId")} AS parent_id, ${d.jsonType(json, "parentId")} AS parent_type`;
577
- const triggerEntry = `(SELECT ${entryColumns.map((name) => `NEW.${name} AS ${name}`).join(", ")}, ${parentColumns("NEW.entry_json")})`;
578
- const storedEntry = `(SELECT ${entryColumns.join(", ")}, ${parentColumns("entry_json")} FROM ${entries} WHERE ${d.rowOrder()} = ?)`;
579
- const indexComplete = `(SELECT backfilled_through >= watermark FROM ${t.sources} WHERE source = 'session-entries')`;
587
+ const triggerEntry = `(SELECT ${entryColumns.map((name) => `NEW.${name} AS ${name}`).join(", ")}, ${parentColumns(d, "NEW.entry_json")})`;
588
+ const storedEntry = `(SELECT ${entryColumns.join(", ")}, ${parentColumns(d, "entry_json")} FROM ${entries} WHERE ${d.rowOrder()} = ?)`;
589
+ const indexComplete = entriesIndexComplete(t.sources);
580
590
  const newRowOrder = d.rowOrder("NEW");
591
+ const forkLink = (rows) => forkSegments === undefined ? [] : [forkSessionLink(t.sessionLinks, forkSegments, rows, isSnapshot)];
581
592
  const entriesSource = {
582
593
  name: "session-entries",
583
594
  table: entries,
@@ -603,7 +614,7 @@ function indexSources(prefix, t, d) {
603
614
  ]),
604
615
  ].map((trigger) => withMarker(trigger, ENTRIES_OWN_PROGRESS)),
605
616
  backfill: [],
606
- rowwise: [...sessionLink(storedEntry), ...sessionRecord(storedEntry)],
617
+ rowwise: [...sessionLink(storedEntry), ...forkLink(storedEntry), ...sessionRecord(storedEntry)],
607
618
  // The triggers that index degraded pins (#4922). Older builds install theirs under the same names (#5065).
608
619
  version: "session-entries@degraded-pins",
609
620
  own: ENTRIES_OWN_PROGRESS,
@@ -784,8 +795,12 @@ async function installSource(transaction, dialect, t, source, reset) {
784
795
  ? []
785
796
  : [
786
797
  ...(source.reset ?? []).map((sql) => ({ sql, params: [] })),
787
- // Triggers of these names that an older build installed are replaced, not kept (#5065).
788
- ...source.triggers.map((trigger) => dialect.dropTrigger(trigger.name, trigger.table)),
798
+ // Triggers of these names that an older build installed are replaced, not kept (#5065): dropped in one
799
+ // script, as they are created, so a source with more triggers costs a driver no more calls.
800
+ source.triggers.length > 0 &&
801
+ source.triggers
802
+ .map((trigger) => `${dialect.dropTrigger(trigger.name, trigger.table)};`)
803
+ .join("\n"),
789
804
  ]),
790
805
  source.triggers.map((trigger) => dialect.renderTrigger(trigger)).join("\n"),
791
806
  {
@@ -837,9 +852,22 @@ async function installMissingSources(transaction, t, prefix, dialect, reset) {
837
852
  await installSource(transaction, dialect, t, source, reset);
838
853
  }
839
854
  }
840
- /** Which referencing tables exist, whether each has all its triggers and a source row, and whether its backfill is done. */
841
- async function readSourceStates(executor, dialect, t, sources, listRetired = false) {
842
- const names = sources.flatMap((source) => [source.table, ...source.triggers.map((trigger) => trigger.name)]);
855
+ /** The names of `sources`' tables and triggers, whose presence `readSourceStates` reads. */
856
+ function sourceObjectNames(sources) {
857
+ return sources.flatMap((source) => [source.table, ...source.triggers.map((trigger) => trigger.name)]);
858
+ }
859
+ /** The read of every source's progress rows. */
860
+ function sourceProgressRead(t) {
861
+ return { sql: `SELECT source, watermark, backfilled_through FROM ${t.sources}`, params: [] };
862
+ }
863
+ /**
864
+ * Which referencing tables exist, whether each has all its triggers and a source row, and whether its backfill is done.
865
+ * `present`, when given, holds every table and trigger of `sources`, as an open's catalog found them: the objects are
866
+ * not read then (#6560).
867
+ */
868
+ async function readSourceStates(executor, dialect, t, sources, listRetired = false, present, also) {
869
+ // `also` asks, in the same statement, which of other objects exist, as `also.found` tells.
870
+ const names = [...sourceObjectNames(sources), ...(also?.names ?? [])];
843
871
  // Builds before 0.9.88 open SQLite and libSQL databases only, so only there can a trigger of this build's name be
844
872
  // one that indexes less.
845
873
  const sqlite = dialect.name === "sqlite";
@@ -856,12 +884,18 @@ async function readSourceStates(executor, dialect, t, sources, listRetired = fal
856
884
  sql: `SELECT name, ${holds(signatures)} AS signed, ${holds(markers)} AS marked FROM sqlite_schema WHERE name IN (${names.map(() => "?").join(", ")})`,
857
885
  params: [...signatures, ...markers].flatMap((check) => [check.trigger, check.text]).concat(names),
858
886
  };
887
+ const progressRead = sourceProgressRead(t);
859
888
  // Read together: the progress rows do not depend on the objects.
860
889
  const [objectRows, progressRows] = await statementBatch(executor, [], [
861
- () => executor.all(objects.sql, ...objects.params),
862
- () => executor.all(`SELECT source, watermark, backfilled_through FROM ${t.sources}`),
890
+ () => present === undefined
891
+ ? executor.all(objects.sql, ...objects.params)
892
+ : Promise.resolve(names.filter((name) => present.has(name)).map((name) => ({ name }))),
893
+ () => executor.all(progressRead.sql, ...progressRead.params),
863
894
  ]);
864
- const present = new Set(objectRows.map((row) => row.name));
895
+ const found = new Set(objectRows.map((row) => row.name));
896
+ for (const name of also?.names ?? [])
897
+ if (found.has(name))
898
+ also?.found.add(name);
865
899
  // Whether each checked trigger's SQL holds this build's text; every other object reads null.
866
900
  const checked = (column) => new Map(objectRows
867
901
  .filter((row) => row[column] !== null && row[column] !== undefined)
@@ -880,7 +914,7 @@ async function readSourceStates(executor, dialect, t, sources, listRetired = fal
880
914
  return [row.source, row];
881
915
  }));
882
916
  return sources
883
- .filter((source) => present.has(source.table))
917
+ .filter((source) => found.has(source.table))
884
918
  .map((source) => {
885
919
  const row = progress.get(source.name);
886
920
  const version = source.version === undefined ? undefined : progress.get(source.version);
@@ -894,7 +928,7 @@ async function readSourceStates(executor, dialect, t, sources, listRetired = fal
894
928
  // Every trigger the source has is this build's. One a build before 0.9.88 installed again after it went
895
929
  // missing is not, even when its SQL is the same in every build otherwise (#5558).
896
930
  const mine = source.marker !== undefined &&
897
- source.triggers.every((trigger) => !present.has(trigger.name) || marked.get(trigger.name) === true);
931
+ source.triggers.every((trigger) => !found.has(trigger.name) || marked.get(trigger.name) === true);
898
932
  let foreign;
899
933
  // Whether the backfill is done for this build, besides the source's own progress row.
900
934
  let trusted;
@@ -917,7 +951,7 @@ async function readSourceStates(executor, dialect, t, sources, listRetired = fal
917
951
  const installed = row !== undefined &&
918
952
  !foreign &&
919
953
  Number(row.watermark) >= 0 &&
920
- source.triggers.every((trigger) => present.has(trigger.name));
954
+ source.triggers.every((trigger) => found.has(trigger.name));
921
955
  const backfilled = row !== undefined &&
922
956
  !foreign &&
923
957
  trusted &&
@@ -944,12 +978,15 @@ export class SqlSnapshotBlobStore {
944
978
  tables;
945
979
  sources;
946
980
  dialect;
981
+ /** The sessions' fork segments table (#6560), which exists once shared-history forks are on. */
982
+ forkSegments;
947
983
  table;
948
- constructor(database, dialect, tables, sources) {
984
+ constructor(database, dialect, tables, sources, forkSegments = forkSegmentsTable()) {
949
985
  this.database = database;
950
986
  this.dialect = dialect;
951
987
  this.tables = tables;
952
988
  this.sources = sources;
989
+ this.forkSegments = forkSegments;
953
990
  this.table = tables.blobs;
954
991
  }
955
992
  /** Which table this store collects, for telling stores of one database and prefix apart from others. */
@@ -964,17 +1001,39 @@ export class SqlSnapshotBlobStore {
964
1001
  static async open(database, prefix = "") {
965
1002
  const t = snapshotIndexTables(prefix);
966
1003
  const dialect = dialectOf(database);
1004
+ const columns = [
1005
+ [t.blobs, "created_at"],
1006
+ [t.blobs, "chunks"],
1007
+ ...SESSION_REF_COLUMNS.map((column) => [t.sessionRefs, column]),
1008
+ ];
1009
+ const triggers = [`${t.blobs}_chunks_delete_all`, `${t.blobs}_chunks_delete`];
967
1010
  const probes = [
968
1011
  ...Object.values(t).map((table) => dialect.tableExists(table)),
969
- dialect.columnExists(t.blobs, "created_at"),
970
- dialect.columnExists(t.blobs, "chunks"),
971
- dialect.schemaObjects([`${t.blobs}_chunks_delete_all`, `${t.blobs}_chunks_delete`]),
972
- ...SESSION_REF_COLUMNS.map((column) => dialect.columnExists(t.sessionRefs, column)),
1012
+ ...columns.map(([table, column]) => dialect.columnExists(table, column)),
1013
+ dialect.schemaObjects(triggers),
973
1014
  ];
974
- const found = await Promise.all(probes.map((probe) => database.get(probe.sql, ...probe.params)));
1015
+ // One catalog read answers the schema questions where an open read it (#6560): always on Postgres, at the first
1016
+ // question on SQLite.
1017
+ const catalog = await schemaCatalogOf(database);
1018
+ // Whether shared-history forks are on (#6560), from that catalog or asked beside the probes.
1019
+ const segments = forkSegmentsTable(prefix);
1020
+ const segmentsProbe = dialect.tableExists(segments);
1021
+ const shared = catalog !== undefined
1022
+ ? Promise.resolve(catalog.hasTable(segments))
1023
+ : database.get(segmentsProbe.sql, ...segmentsProbe.params).then((row) => row !== undefined);
1024
+ shared.catch(() => { });
1025
+ // A versioned database checks its ledger whatever the probes find, so it does not ask them. Elsewhere the catalog
1026
+ // answers them all, in one read instead of a read each.
1027
+ const current = dialect.versionedMigrations
1028
+ ? false
1029
+ : catalog !== undefined
1030
+ ? Object.values(t).every((table) => catalog.hasTable(table)) &&
1031
+ columns.every(([table, column]) => catalog.hasColumn(table, column)) &&
1032
+ triggers.some((trigger) => catalog.hasObject(trigger))
1033
+ : (await Promise.all(probes.map((probe) => database.get(probe.sql, ...probe.params)))).every((row) => row !== undefined);
975
1034
  // A versioned database always checks its ledger: a newer schema with the same tables is refused, and a step it
976
1035
  // lacks, such as the index triggers, runs even when every table exists.
977
- if (dialect.versionedMigrations || !found.every((row) => row !== undefined)) {
1036
+ if (!current) {
978
1037
  await applyStorageMigrations(database, SNAPSHOT_BLOB_DOMAIN, [
979
1038
  { version: 1, up: (transaction, dialect) => createSnapshotIndexTables(transaction, t, prefix, dialect) },
980
1039
  // Where a ledger records the steps, it records the index triggers too, installed under the migration lock.
@@ -1006,8 +1065,8 @@ export class SqlSnapshotBlobStore {
1006
1065
  : []),
1007
1066
  ], { table: storageMigrationTable(prefix) });
1008
1067
  }
1009
- const store = new SqlSnapshotBlobStore(database, dialect, t, indexSources(prefix, t, dialect));
1010
- await store.installIndex();
1068
+ const store = new SqlSnapshotBlobStore(database, dialect, t, indexSources(prefix, t, dialect, (await shared) ? segments : undefined), segments);
1069
+ await store.installIndex(undefined, false, await schemaCatalogOf(database));
1011
1070
  return store;
1012
1071
  }
1013
1072
  /** Runs only layout maintenance on the offline command's dedicated, exclusively locked SQLite file connection. */
@@ -1085,9 +1144,11 @@ export class SqlSnapshotBlobStore {
1085
1144
  * binds more than one chunk (#4954); the chunks of a blob stored already are not written again. Unknown ages
1086
1145
  * remain protected until collection stamps them.
1087
1146
  */
1088
- async putBlobs(blobs) {
1089
- if (blobs.length === 0)
1147
+ async putBlobs(unordered) {
1148
+ if (unordered.length === 0)
1090
1149
  return;
1150
+ // In hash order, so the rows it locks are taken in the order every other write of them takes them.
1151
+ const blobs = [...unordered].sort((first, second) => byteOrder(first.hash, second.hash));
1091
1152
  const now = this.dialect.nowSeconds;
1092
1153
  const header = `INSERT INTO ${this.table} (hash, bytes, data, created_at, chunks) VALUES (?, ?, ?, ${now}, ?) ON CONFLICT(hash) DO UPDATE SET created_at = ${now} WHERE ${this.table}.created_at > 0`;
1093
1154
  const chunk = `INSERT INTO ${this.tables.blobChunks} (hash, idx, data) SELECT ?, ?, ? WHERE NOT EXISTS (SELECT 1 FROM ${this.table} WHERE hash = ?) ON CONFLICT DO NOTHING`;
@@ -1112,9 +1173,27 @@ export class SqlSnapshotBlobStore {
1112
1173
  return;
1113
1174
  }
1114
1175
  await this.database.transaction(async (transaction) => {
1176
+ // On a pipelined connection the statements go out with the commit: one round trip after the locks.
1177
+ if (transactionFinisher(transaction)?.(statements) === true)
1178
+ return;
1115
1179
  for (const statement of statements)
1116
1180
  await transaction.run(statement.sql, ...statement.params);
1117
- });
1181
+ }, this.blobWrite());
1182
+ }
1183
+ /**
1184
+ * How a put or a refresh of this table's blobs runs: a serial transaction of the blob table's own domain (#6560). On
1185
+ * PostgreSQL it holds the database-wide lock shared, so it waits for and excludes collection, whose writes hold that
1186
+ * lock exclusively, and the blob writers of this table exclude one another, but session writes, which hold the
1187
+ * database-wide lock shared with their session's domain, run beside it. Rows it writes again (`created_at`) are locked
1188
+ * in hash order, as an append's check of the blobs it records locks them (`missingBlob`), so neither waits on the
1189
+ * other in a cycle. Its callback only uses the transaction, so a transient failure runs it again.
1190
+ */
1191
+ blobWrite(leading) {
1192
+ return {
1193
+ retryTransientFailures: true,
1194
+ concurrency: { kind: "serial", domain: this.table },
1195
+ ...(leading === undefined ? {} : { leading }),
1196
+ };
1118
1197
  }
1119
1198
  /**
1120
1199
  * The blob's bytes, read a chunk per statement when it has chunks, so no response holds more than one chunk. A
@@ -1154,10 +1233,18 @@ export class SqlSnapshotBlobStore {
1154
1233
  ]);
1155
1234
  return rows.length === unique.length;
1156
1235
  }
1236
+ // The rows present, locked in hash order before the update writes them (see `blobWrite`). On a pipelined connection
1237
+ // this read goes out with the transaction's start and the update with its commit.
1238
+ const locked = {
1239
+ sql: `${present} ORDER BY hash${this.dialect.byteOrderCollation}${this.dialect.lockClause("update")}`,
1240
+ params,
1241
+ };
1157
1242
  return this.database.transaction(async (transaction) => {
1158
- await transaction.run(update, ...params);
1159
- return (await transaction.all(present, ...params)).length === unique.length;
1160
- });
1243
+ const rows = await transaction.all(locked.sql, ...locked.params);
1244
+ if (transactionFinisher(transaction)?.([{ sql: update, params }]) !== true)
1245
+ await transaction.run(update, ...params);
1246
+ return rows.length === unique.length;
1247
+ }, this.blobWrite([locked]));
1161
1248
  }
1162
1249
  async listBlobHashes() {
1163
1250
  const rows = await this.database.all(`SELECT hash FROM ${this.table}`);
@@ -1172,11 +1259,26 @@ export class SqlSnapshotBlobStore {
1172
1259
  */
1173
1260
  async assertStored(transaction, snapshots) {
1174
1261
  const missing = await this.missingBlob(transaction, snapshots);
1175
- if (missing === undefined)
1176
- return;
1262
+ if (missing !== undefined)
1263
+ await this.refuseCollected(missing);
1264
+ }
1265
+ /** The `blobs-collected` {@link WorkspaceSnapshotError} `assertStored` rejects with for `hash`. */
1266
+ async refuseCollected(hash) {
1177
1267
  // Loaded only when a write is refused, so the storage entry does not load the workspace error family.
1178
1268
  const { WorkspaceSnapshotError } = await import("./errors.code.js").catch((error) => __atomicOnDemandFailed(error, "worktree snapshots"));
1179
- throw new WorkspaceSnapshotError("blobs-collected", missing);
1269
+ throw new WorkspaceSnapshotError("blobs-collected", hash);
1270
+ }
1271
+ /** The blobs of `snapshots` that `assertStored` checks, each once, in the order it reports the first missing one. */
1272
+ storedHashes(snapshots) {
1273
+ return [...new Set(snapshots.flatMap(wellFormedBlobHashes))];
1274
+ }
1275
+ /**
1276
+ * The query `missingBlob` reads, for the blobs named by `source`, an SQL expression of a JSON array of hashes: the
1277
+ * hashes this table holds in full, locked FOR SHARE in hash order. A statement that checks the blobs on the server,
1278
+ * such as the session append function, runs it as it is (#6599).
1279
+ */
1280
+ storedBlobsQuery(source) {
1281
+ return `SELECT hash FROM ${this.table} AS b WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues(source)}) AND (chunks = 0 OR chunks = (SELECT COUNT(*) FROM ${this.tables.blobChunks} AS c WHERE c.hash = b.hash)) ORDER BY hash${this.dialect.byteOrderCollation}${this.dialect.lockClause("share")}`;
1180
1282
  }
1181
1283
  /**
1182
1284
  * A query that returns a row only while this table holds every blob of `snapshots` in full, for a write planned
@@ -1191,12 +1293,15 @@ export class SqlSnapshotBlobStore {
1191
1293
  params: [JSON.stringify(hashes), hashes.length],
1192
1294
  };
1193
1295
  }
1194
- /** The first of `snapshots`' blobs this table does not hold in full, read in `transaction`; undefined when none. */
1296
+ /**
1297
+ * The first of `snapshots`' blobs this table does not hold in full, read in `transaction`; undefined when none. The
1298
+ * rows it finds stay locked FOR SHARE until the transaction ends, taken in hash order as a blob write takes them.
1299
+ */
1195
1300
  async missingBlob(transaction, snapshots) {
1196
- const hashes = [...new Set(snapshots.flatMap(wellFormedBlobHashes))];
1301
+ const hashes = this.storedHashes(snapshots);
1197
1302
  if (hashes.length === 0)
1198
1303
  return undefined;
1199
- const rows = await transaction.all(`SELECT hash FROM ${this.table} AS b WHERE hash IN (SELECT value FROM ${this.dialect.jsonValues("?")}) AND (chunks = 0 OR chunks = (SELECT COUNT(*) FROM ${this.tables.blobChunks} AS c WHERE c.hash = b.hash))${this.dialect.lockClause("share")}`, JSON.stringify(hashes));
1304
+ const rows = await transaction.all(this.storedBlobsQuery("?"), JSON.stringify(hashes));
1200
1305
  const stored = new Set(rows.map((row) => row.hash));
1201
1306
  return hashes.find((hash) => !stored.has(hash));
1202
1307
  }
@@ -1206,14 +1311,27 @@ export class SqlSnapshotBlobStore {
1206
1311
  * above it, indexed by the triggers. A table that has none yet, an empty one included, costs one watermark of 0.
1207
1312
  * Resolves with the state of every referencing table.
1208
1313
  */
1209
- async installIndex(pace, includeDeferred = false) {
1210
- const states = await readSourceStates(this.database, this.dialect, this.tables, this.sources, includeDeferred);
1314
+ async installIndex(pace, includeDeferred = false, catalog) {
1315
+ // The fork links trigger earlier builds of #6560 installed, asked for in the same read: dropped where found, in the
1316
+ // first write below, so a database that has it runs it no longer once a store of this build opened it.
1317
+ const legacy = this.legacyForkLinks();
1318
+ const found = new Set();
1319
+ const states = await this.readStates(includeDeferred, catalog, legacy && { names: [legacy.name], found });
1320
+ let drop = legacy !== undefined && found.has(legacy.name) ? legacy : undefined;
1321
+ const dropLegacy = async (transaction) => {
1322
+ if (drop === undefined)
1323
+ return;
1324
+ const { name, table } = drop;
1325
+ await withShortSchemaLockWaits(transaction, this.dialect, () => transaction.exec(this.dialect.dropTrigger(name, table, true)));
1326
+ drop = undefined;
1327
+ };
1211
1328
  const missing = states.filter((state) => !state.installed && (includeDeferred || !state.deferred));
1212
1329
  for (const { source } of missing) {
1213
1330
  const reset = source.name === "session-entries"
1214
1331
  ? await SqlSnapshotBlobStore.prepareSessionIndexReset(this.database)
1215
1332
  : undefined;
1216
1333
  await this.write(pace, async (transaction) => {
1334
+ await dropLegacy(transaction);
1217
1335
  const [current] = await readSourceStates(transaction, this.dialect, this.tables, [source]);
1218
1336
  if (current === undefined || current.installed || (current.deferred && !includeDeferred))
1219
1337
  return;
@@ -1221,9 +1339,37 @@ export class SqlSnapshotBlobStore {
1221
1339
  await withShortSchemaLockWaits(transaction, this.dialect, () => installSource(transaction, this.dialect, this.tables, source, reset));
1222
1340
  });
1223
1341
  }
1224
- return missing.length === 0
1225
- ? states
1226
- : readSourceStates(this.database, this.dialect, this.tables, this.sources, includeDeferred);
1342
+ if (drop !== undefined)
1343
+ await this.write(pace, dropLegacy);
1344
+ return missing.length === 0 ? states : this.readStates(includeDeferred);
1345
+ }
1346
+ /** The fork links trigger earlier builds of #6560 installed on the session entries, and its table. */
1347
+ legacyForkLinks() {
1348
+ const entries = this.sources.find((source) => source.name === "session-entries");
1349
+ return entries && { name: legacyForkLinksTriggerName(entries.table), table: entries.table };
1350
+ }
1351
+ /**
1352
+ * The state of every source, read outside a transaction. On PostgreSQL the objects and the progress rows are read in
1353
+ * one read-only transaction whose start carries both, so they cost one round trip, not one each. An open's
1354
+ * `catalog` answers which objects exist only when it found every one: only its positive answers are final, and a
1355
+ * source table it lacks may have been created since (#6560). `also` asks which of other objects exist in the same
1356
+ * read, as `readSourceStates` does.
1357
+ */
1358
+ readStates(includeDeferred, catalog, also) {
1359
+ if (this.dialect.name !== "postgres")
1360
+ return readSourceStates(this.database, this.dialect, this.tables, this.sources, includeDeferred, undefined, also);
1361
+ const names = sourceObjectNames(this.sources);
1362
+ const present = catalog !== undefined && names.every((name) => catalog.hasObject(name))
1363
+ ? new Set([...names, ...(also?.names ?? []).filter((name) => catalog.hasObject(name))])
1364
+ : undefined;
1365
+ return this.database.transaction((transaction) => readSourceStates(transaction, this.dialect, this.tables, this.sources, includeDeferred, present, also), {
1366
+ readOnly: true,
1367
+ retryTransientFailures: true,
1368
+ leading: [
1369
+ ...(present === undefined ? [this.dialect.schemaObjects([...names, ...(also?.names ?? [])])] : []),
1370
+ sourceProgressRead(this.tables),
1371
+ ],
1372
+ });
1227
1373
  }
1228
1374
  /**
1229
1375
  * Indexes the rows that referencing tables held before their triggers were installed, in transactions of
@@ -1376,9 +1522,11 @@ export class SqlSnapshotBlobStore {
1376
1522
  options.signal?.throwIfAborted();
1377
1523
  const trigger = `${t.blobs}_chunks_delete_all`;
1378
1524
  const required = [trigger, `${t.blobs}_age`, `${t.blobs}_inline_size`];
1379
- const schema = this.dialect.schemaObjects(required);
1525
+ // Asked with them: whether forks share their parents' histories, whose inherited snapshots the sweep keeps (#6560).
1526
+ const schema = this.dialect.schemaObjects([...required, this.forkSegments]);
1380
1527
  const present = new Set((await this.database.all(schema.sql, ...schema.params)).map((row) => row.name));
1381
- if (present.size < required.length) {
1528
+ const forks = present.has(this.forkSegments);
1529
+ if (!required.every((name) => present.has(name))) {
1382
1530
  options.signal?.throwIfAborted();
1383
1531
  await this.write(options.pace, async (transaction) => {
1384
1532
  if (options.holder !== undefined)
@@ -1408,7 +1556,7 @@ export class SqlSnapshotBlobStore {
1408
1556
  renewedAt = performance.now();
1409
1557
  }
1410
1558
  const page = await this.page(minimumAge, cursor);
1411
- const candidates = await this.unretainedOf(page.map((row) => row.hash), sessions, turns);
1559
+ const candidates = await this.unretainedOf(page.map((row) => row.hash), sessions, turns, forks);
1412
1560
  let incomplete = false;
1413
1561
  for (const batch of sessions.batches(candidates)) {
1414
1562
  // Every delete batch starts on a turn of its own and ends with one: never a turn while it holds the write lock.
@@ -1448,7 +1596,7 @@ export class SqlSnapshotBlobStore {
1448
1596
  * references one of them and that `sessions` has not walked yet, in statements of at most
1449
1597
  * {@link SNAPSHOT_COLLECTION_SESSION_REFS} snapshot entries, with a turn between them.
1450
1598
  */
1451
- async unretainedOf(hashes, sessions, turns) {
1599
+ async unretainedOf(hashes, sessions, turns, forks) {
1452
1600
  if (hashes.length === 0)
1453
1601
  return [];
1454
1602
  const t = this.tables;
@@ -1464,7 +1612,7 @@ export class SqlSnapshotBlobStore {
1464
1612
  sessions.cost(costs);
1465
1613
  for (const group of sessionGroups(costs)) {
1466
1614
  await turns.next();
1467
- sessions.retain(group, await this.retainedBySessions(group));
1615
+ sessions.retain(group, await this.retainedBySessions(group, forks));
1468
1616
  turns.held();
1469
1617
  }
1470
1618
  }
@@ -1484,12 +1632,16 @@ export class SqlSnapshotBlobStore {
1484
1632
  deleteUnretained(batch, minimumAge, options) {
1485
1633
  const t = this.tables;
1486
1634
  return this.write(options.pace, async (transaction) => {
1487
- const states = await readSourceStates(transaction, this.dialect, this.tables, this.sources);
1635
+ const found = new Set();
1636
+ const states = await readSourceStates(transaction, this.dialect, this.tables, this.sources, false, undefined, {
1637
+ names: [this.forkSegments],
1638
+ found,
1639
+ });
1488
1640
  if (!states.every((state) => state.installed && state.backfilled))
1489
1641
  return undefined;
1490
1642
  if (options.holder !== undefined)
1491
1643
  await this.renewClaim(transaction, options.holder);
1492
- const kept = new Set(await this.keptBySessions(transaction, batch));
1644
+ const kept = new Set(await this.keptBySessions(transaction, batch, found.has(this.forkSegments)));
1493
1645
  const unretained = batch.hashes.filter((hash) => !kept.has(hash));
1494
1646
  if (unretained.length === 0)
1495
1647
  return [];
@@ -1527,32 +1679,48 @@ export class SqlSnapshotBlobStore {
1527
1679
  * The blobs that the snapshots `sessions` retain reference, in one statement. A session whose tree the index could
1528
1680
  * not follow retains every snapshot it records.
1529
1681
  */
1530
- async retainedBySessions(sessions) {
1682
+ async retainedBySessions(sessions, forks) {
1531
1683
  const t = this.tables;
1532
1684
  const ids = JSON.stringify(sessions);
1685
+ const inherited = this.inheritedRecord(forks);
1533
1686
  const rows = await this.database.all(`SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record
1534
1687
  WHERE record.session_id IN (SELECT value FROM ${this.dialect.jsonValues("?")})
1535
1688
  AND (
1536
1689
  (record.session_id, record.snapshot_id) IN (${this.sessionHeads(`session_id IN (SELECT value FROM ${this.dialect.jsonValues("?")})`)})
1537
- OR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)
1690
+ OR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)${inherited}
1538
1691
  )`, ids, ids);
1539
1692
  return rows.map((row) => row.hash);
1540
1693
  }
1694
+ /**
1695
+ * A condition, after `OR`, that another session inherits the session record `record` through a fork segment
1696
+ * (#6560); empty when `forks` says the fork segments table is not there, as while shared-history forks are off. A
1697
+ * fork that shares its parent's history stores none of the entries it inherits, so its own references never name
1698
+ * their snapshots: a record a segment names is kept whatever its session retains, as long as the segment lasts. A
1699
+ * delete batch reads whether the table exists in its own transaction, so it sees the segments that hold when it
1700
+ * commits.
1701
+ */
1702
+ inheritedRecord(forks) {
1703
+ if (!forks)
1704
+ return "";
1705
+ return `
1706
+ OR EXISTS (SELECT 1 FROM ${this.forkSegments} AS segment WHERE segment.source_id = record.session_id AND record.seq BETWEEN segment.from_seq AND segment.to_seq)`;
1707
+ }
1541
1708
  /**
1542
1709
  * The blobs of `batch` that a session records and that the delete must keep, in one statement: those the snapshots
1543
1710
  * of `batch.sessions` retain, and those a session not among them records, whose snapshots the sweep did not walk.
1544
1711
  * Walks only `batch.sessions`, whose snapshot entries the sweep bounded when it made the batch (#5530).
1545
1712
  */
1546
- async keptBySessions(executor, batch) {
1713
+ async keptBySessions(executor, batch, forks) {
1547
1714
  const t = this.tables;
1548
1715
  const ids = JSON.stringify(batch.sessions);
1549
1716
  const walked = `(SELECT value FROM ${this.dialect.jsonValues("?")})`;
1717
+ const inherited = this.inheritedRecord(forks);
1550
1718
  const rows = await executor.all(`SELECT DISTINCT record.hash FROM ${t.sessionRecords} AS record
1551
1719
  WHERE record.hash IN (SELECT value FROM ${this.dialect.jsonValues("?")})
1552
1720
  AND (
1553
1721
  record.session_id NOT IN ${walked}
1554
1722
  OR (record.session_id, record.snapshot_id) IN (${this.sessionHeads(`session_id IN ${walked}`)})
1555
- OR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)
1723
+ OR EXISTS (SELECT 1 FROM ${t.sessionLinks} AS broken WHERE broken.session_id = record.session_id AND broken.broken = 1)${inherited}
1556
1724
  )`, JSON.stringify(batch.hashes), ids, ids);
1557
1725
  return rows.map((row) => row.hash);
1558
1726
  }
@@ -1993,7 +2161,7 @@ function __atomicOnDemandFailed(error, feature) {
1993
2161
  return (async () => {
1994
2162
  const root = new URL("../../", import.meta.url);
1995
2163
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
1996
- const key = `${root.href}#0.10.10`;
2164
+ const key = `${root.href}#0.10.11-alpha.2`;
1997
2165
  let release = releases.get(key);
1998
2166
  if (release === undefined) {
1999
2167
  const current = (async () => {
@@ -2021,7 +2189,7 @@ function __atomicOnDemandFailed(error, feature) {
2021
2189
  } catch {
2022
2190
  // No installation to read, as in a bundle of the package: the release the process runs decides.
2023
2191
  }
2024
- const updatedTo = typeof installed === "string" && installed !== "0.10.10" ? installed : running !== undefined && running.version !== "0.10.10" ? "0.10.10" : undefined;
2192
+ const updatedTo = typeof installed === "string" && installed !== "0.10.11-alpha.2" ? installed : running !== undefined && running.version !== "0.10.11-alpha.2" ? "0.10.11-alpha.2" : undefined;
2025
2193
  if (updatedTo === undefined) throw error;
2026
2194
  const application = typeof running?.name === "string" ? running.name : "atomic";
2027
2195
  const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {