@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
@@ -0,0 +1,351 @@
1
+ import { dialectOf } from "./dialect.js";
2
+ import * as statementSequence from "./statement-sequence.js";
3
+ /**
4
+ * `transactionFinisher` of `statement-sequence.ts`, which the copy of that module 0.10.3 and 0.10.4 loaded lacks: a
5
+ * process an in-place update caught keeps that copy, where a named import would fail to link. Without it the stamps
6
+ * go out on their own, before the commit.
7
+ */
8
+ const finishers = statementSequence;
9
+ const TABLE_KINDS = new Set(["r", "p", "v", "m", "f"]);
10
+ /**
11
+ * Every relation, trigger, column and function of the schema the statement runs in, in one statement and so one
12
+ * snapshot. The catalog, not information_schema, finds relations, as `tableExists` does; columns come from
13
+ * information_schema, as `columnExists` reads them. A function is listed with whether this role may execute it.
14
+ */
15
+ const CATALOG_SQL = `SELECT 'relation' AS kind, c.relname::text AS name, c.relkind::text AS detail
16
+ FROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace
17
+ UNION ALL SELECT 'trigger', t.tgname::text, NULL
18
+ FROM pg_catalog.pg_trigger t JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid
19
+ WHERE c.relnamespace = current_schema()::regnamespace AND NOT t.tgisinternal
20
+ UNION ALL SELECT 'column', table_name::text, column_name::text
21
+ FROM information_schema.columns WHERE table_schema = current_schema()
22
+ UNION ALL SELECT 'function', p.proname::text, CASE WHEN has_function_privilege(p.oid, 'EXECUTE') THEN 'executable' END
23
+ FROM pg_catalog.pg_proc p WHERE p.pronamespace = current_schema()::regnamespace`;
24
+ /**
25
+ * Every object of a SQLite or libSQL database and every column of its tables, generated ones included, in one
26
+ * statement and so one snapshot: what `tableExists`, `columnExists` and `schemaObjects` ask one at a time (#6560).
27
+ */
28
+ const SQLITE_CATALOG_SQL = `SELECT 'object' AS kind, name, type AS detail FROM sqlite_master
29
+ UNION ALL SELECT 'column', m.name, c.name FROM sqlite_master AS m JOIN pragma_table_xinfo(m.name) AS c
30
+ WHERE m.type = 'table'`;
31
+ /**
32
+ * @internal The table under `ledger`'s prefix where SQLite and libSQL record which revision of each store's schema
33
+ * setup ran, and the database's schema version (`PRAGMA schema_version`) once it had: `domain`, `revision`,
34
+ * `schema_version`. SQLite counts every change to the schema in that version, whoever makes it, an older Atomic that
35
+ * records nothing included; a revision is believed only while the version still matches, so any later change is checked
36
+ * again (#6560). Builds that do not know the table leave it alone.
37
+ */
38
+ export function sqliteSchemaStampTable(ledger) {
39
+ return ledger.endsWith("atomic_migrations")
40
+ ? `${ledger.slice(0, -"atomic_migrations".length)}atomic_schema_stamps`
41
+ : `${ledger}_schema_stamps`;
42
+ }
43
+ /** The key a store's setup is stamped under, as the PostgreSQL ledger records it. */
44
+ const stampKey = (domain) => `schema:${domain}`;
45
+ /**
46
+ * The revisions `ledger`'s stamps record whose schema version is the database's now, by stamp key, read in one
47
+ * statement so the two agree. Stamps of an older schema version are left out: something changed the schema since.
48
+ */
49
+ async function readSqliteSchemaStamps(executor, ledger) {
50
+ const rows = await executor.all(`SELECT domain, revision, schema_version AS stamped FROM ${sqliteSchemaStampTable(ledger)}
51
+ UNION ALL SELECT NULL, NULL, schema_version FROM pragma_schema_version`);
52
+ const now = rows.find((row) => row.domain === null)?.stamped;
53
+ const stamps = new Map();
54
+ for (const row of rows)
55
+ if (row.domain !== null && now !== undefined && Number(row.stamped) === Number(now))
56
+ stamps.set(row.domain, Number(row.revision ?? 0));
57
+ return stamps;
58
+ }
59
+ /**
60
+ * @internal Stamps each of `stamps`, in the transaction `tx` that ran their setups, with the schema version as that
61
+ * transaction leaves it: a later open believes their revisions until the schema changes again (#6560). Creates the
62
+ * stamps table first, unless `options.tableExists`, so its own creation is part of the version recorded. With
63
+ * `options.last`, the stamps are the transaction's last statement: where its connection is pipelined, they go out with
64
+ * its commit. SQLite and libSQL only; every stamp must share a ledger.
65
+ */
66
+ export async function recordSqliteSchemaStamps(tx, stamps, options = {}) {
67
+ const ledger = stamps[0]?.ledger;
68
+ if (ledger === undefined)
69
+ return;
70
+ const table = sqliteSchemaStampTable(ledger);
71
+ if (options.tableExists !== true)
72
+ await tx.exec(`CREATE TABLE IF NOT EXISTS ${table} (domain TEXT NOT NULL PRIMARY KEY, revision INTEGER NOT NULL, schema_version INTEGER NOT NULL)`);
73
+ // The revision this transaction set up, even below a newer build's: the stamp says what was checked at this version.
74
+ // One statement for them all, so a server pays one request.
75
+ const upsert = {
76
+ sql: `INSERT INTO ${table} (domain, revision, schema_version)
77
+ SELECT column1, column2, (SELECT schema_version FROM pragma_schema_version)
78
+ FROM (VALUES ${stamps.map(() => "(?, ?)").join(", ")}) WHERE true
79
+ ON CONFLICT(domain) DO UPDATE SET revision = excluded.revision, schema_version = excluded.schema_version`,
80
+ params: stamps.flatMap(({ domain, revision }) => [stampKey(domain), revision]),
81
+ };
82
+ if (options.last === true && finishers.transactionFinisher?.(tx)?.([upsert]) === true)
83
+ return;
84
+ await tx.run(upsert.sql, ...upsert.params);
85
+ }
86
+ /** The catalog of a SQLite or libSQL database, or undefined when it cannot be read, such as on a SQLite too old. */
87
+ async function readSqliteCatalog(database, ledger) {
88
+ let rows;
89
+ try {
90
+ rows = await database.all(SQLITE_CATALOG_SQL);
91
+ }
92
+ catch {
93
+ return undefined;
94
+ }
95
+ const types = new Map();
96
+ const columns = new Set();
97
+ for (const row of rows) {
98
+ if (row.kind === "column")
99
+ columns.add(`${row.name}\0${row.detail}`);
100
+ else
101
+ types.set(row.name, String(row.detail));
102
+ }
103
+ return {
104
+ ledger,
105
+ // SQLite records no versions: its stores' stamps are read on their own (`sqliteSchemaStampsOf`).
106
+ recordedVersion: () => 0,
107
+ hasTable: (table) => types.get(table) === "table",
108
+ hasObject: (name) => types.has(name),
109
+ hasColumn: (table, column) => columns.has(`${table}\0${column}`),
110
+ sqliteObjectType: (name) => types.get(name),
111
+ };
112
+ }
113
+ /** The tables, objects, columns and executable functions of PostgreSQL catalog rows (`CATALOG_SQL`'s). */
114
+ function catalogSets(rows) {
115
+ const tables = new Set();
116
+ const objects = new Set();
117
+ const columns = new Set();
118
+ const functions = new Set();
119
+ for (const row of rows) {
120
+ if (row.kind === "column")
121
+ columns.add(`${row.name}\0${row.detail}`);
122
+ else if (row.kind === "function") {
123
+ if (row.detail === "executable")
124
+ functions.add(row.name);
125
+ }
126
+ else {
127
+ objects.add(row.name);
128
+ if (row.kind === "relation" && TABLE_KINDS.has(String(row.detail)))
129
+ tables.add(row.name);
130
+ }
131
+ }
132
+ return { tables, objects, columns, functions };
133
+ }
134
+ /**
135
+ * The catalog rows and the ledger's versions of `database`'s schema, read in one read-only transaction whose start
136
+ * carries both reads, so they cost one round trip (#6560). The versions are undefined when the ledger did not exist;
137
+ * the whole read is undefined when it failed.
138
+ */
139
+ async function readPostgresCatalog(database, ledger, physicalLedger) {
140
+ const versionsSql = `SELECT domain, MAX(version) AS version FROM ${ledger} GROUP BY domain`;
141
+ let read;
142
+ try {
143
+ await database.transaction(async (tx) => {
144
+ read = undefined;
145
+ const rows = await tx.all(CATALOG_SQL);
146
+ // Taken even where the ledger does not exist and its read failed, so the transaction ends with its commit,
147
+ // sent at once, rather than with a rollback after it.
148
+ const ledgerExists = catalogSets(rows).tables.has(physicalLedger);
149
+ const versions = await tx.all(versionsSql).catch((error) => {
150
+ if (ledgerExists)
151
+ throw error;
152
+ return undefined;
153
+ });
154
+ read = { rows, versions };
155
+ }, {
156
+ readOnly: true,
157
+ retryTransientFailures: true,
158
+ leading: [
159
+ { sql: CATALOG_SQL, params: [] },
160
+ { sql: versionsSql, params: [] },
161
+ ],
162
+ });
163
+ }
164
+ catch {
165
+ return undefined;
166
+ }
167
+ return read;
168
+ }
169
+ /**
170
+ * Reads `database`'s schema and the versions `ledger` records, in one read-only transaction that takes no lock. On
171
+ * PostgreSQL, an adapter that read them when it opened gives them once (`takeOpenedCatalog`), and the first open reads
172
+ * nothing (#6560). On SQLite and libSQL, which record no versions, reads the schema alone in one statement. Undefined
173
+ * when a read fails: the stores then check each object themselves.
174
+ */
175
+ export async function readStorageSchemaCatalog(database, ledger) {
176
+ const dialect = dialectOf(database);
177
+ if (dialect.name === "sqlite")
178
+ return readSqliteCatalog(database, ledger);
179
+ if (!dialect.versionedMigrations || dialect.name !== "postgres")
180
+ return undefined;
181
+ const physicalLedger = dialect.identifier(ledger);
182
+ const opened = database.takeOpenedCatalog?.();
183
+ const read = opened !== undefined && opened.ledger === physicalLedger
184
+ ? {
185
+ rows: opened.rows,
186
+ versions: opened.versions,
187
+ }
188
+ : await readPostgresCatalog(database, ledger, physicalLedger);
189
+ if (read === undefined)
190
+ return undefined;
191
+ const { tables, objects, columns, functions } = catalogSets(read.rows);
192
+ const recorded = new Map();
193
+ if (tables.has(physicalLedger)) {
194
+ if (read.versions === undefined)
195
+ return undefined;
196
+ for (const row of read.versions)
197
+ recorded.set(row.domain, Number(row.version ?? 0));
198
+ }
199
+ return {
200
+ ledger,
201
+ recordedVersion: (domain) => recorded.get(domain) ?? 0,
202
+ hasTable: (table) => tables.has(dialect.identifier(table)),
203
+ hasObject: (name) => objects.has(dialect.identifier(name)),
204
+ hasColumn: (table, column) => columns.has(`${dialect.identifier(table)}\0${column}`),
205
+ hasFunction: (name) => functions.has(dialect.identifier(name)),
206
+ };
207
+ }
208
+ const scopes = new WeakMap();
209
+ /**
210
+ * Runs `body`, an open of one or more stores on `database`, with one catalog read for all of them: the schema checks
211
+ * of the stores it opens ({@link schemaCatalogOf}) answer from it, so an open whose schema is current runs no schema
212
+ * transaction and takes no lock. Opens on `database` that overlap share the read. `views` are other handles on the
213
+ * same connection, such as a borrowed view, whose checks answer from the same read.
214
+ */
215
+ export async function withStorageSchemaCatalog(database, ledger, body, views = []) {
216
+ let scope = scopes.get(database);
217
+ if (scope === undefined || scope.ledger !== ledger) {
218
+ const read = () => readStorageSchemaCatalog(database, ledger);
219
+ const catalog = dialectOf(database).name === "sqlite" ? undefined : read();
220
+ scope = { ledger, catalog, read, users: 0, stamps: undefined, restamp: new Map() };
221
+ scopes.set(database, scope);
222
+ }
223
+ const shared = scope;
224
+ const handles = [database, ...views.filter((view) => !scopes.has(view))];
225
+ for (const handle of handles.slice(1))
226
+ scopes.set(handle, shared);
227
+ shared.users += 1;
228
+ try {
229
+ const value = await body();
230
+ if (shared.users === 1 && shared.restamp.size > 0)
231
+ await restamp(database, shared);
232
+ return value;
233
+ }
234
+ finally {
235
+ shared.users -= 1;
236
+ for (const handle of handles.slice(1))
237
+ if (scopes.get(handle) === shared)
238
+ scopes.delete(handle);
239
+ if (shared.users === 0 && scopes.get(database) === shared)
240
+ scopes.delete(database);
241
+ }
242
+ }
243
+ /**
244
+ * Drops the catalog an open of `database` in progress read, so the next question reads the schema again: for a step of
245
+ * the open that changed the schema the stores it opens after it ask about.
246
+ */
247
+ export function refreshStorageSchemaCatalog(database) {
248
+ const scope = scopes.get(database);
249
+ if (scope !== undefined)
250
+ scope.catalog = undefined;
251
+ }
252
+ /**
253
+ * Tells the catalog an open of `database` in progress read that the open created `tables` since, so the stores it
254
+ * opens next find them without reading the schema again.
255
+ */
256
+ export function noteStorageSchemaTables(database, tables) {
257
+ const scope = scopes.get(database);
258
+ if (scope?.catalog === undefined)
259
+ return;
260
+ const identifier = dialectOf(database).identifier;
261
+ const created = new Set(tables.map((table) => identifier(table)));
262
+ scope.catalog = scope.catalog.then((catalog) => catalog && {
263
+ ...catalog,
264
+ hasTable: (table) => created.has(identifier(table)) || catalog.hasTable(table),
265
+ hasObject: (name) => created.has(identifier(name)) || catalog.hasObject(name),
266
+ });
267
+ }
268
+ /**
269
+ * The catalog an open of `database` in progress read ({@link withStorageSchemaCatalog}), when it read `ledger`'s
270
+ * versions or no `ledger` is named; undefined outside such an open, and when it could not be read.
271
+ */
272
+ export async function schemaCatalogOf(database, ledger) {
273
+ const scope = scopes.get(database);
274
+ if (scope === undefined || (ledger !== undefined && scope.ledger !== ledger))
275
+ return undefined;
276
+ scope.catalog ??= scope.read();
277
+ return scope.catalog;
278
+ }
279
+ /**
280
+ * @internal The revisions the stamps under `ledger` record for the stores of `database` (SQLite and libSQL), by stamp
281
+ * key (`schema:<domain>`), as the open of `database` in progress read them; only those whose schema version was the
282
+ * database's then. Undefined outside such an open, and where none could be read, such as before any stamp. The first
283
+ * question reads them after the open's catalog, and only where it holds their table.
284
+ */
285
+ export async function sqliteSchemaStampsOf(database, ledger) {
286
+ const scope = scopes.get(database);
287
+ if (scope === undefined || scope.ledger !== ledger || dialectOf(database).name !== "sqlite")
288
+ return undefined;
289
+ // Read once the catalog shows their table: a read of a missing table would fail, which costs a request, and makes a
290
+ // libSQL file driver replace its connection.
291
+ scope.stamps ??= schemaCatalogOf(database, ledger).then((catalog) => catalog?.hasTable(sqliteSchemaStampTable(ledger)) === true
292
+ ? readSqliteSchemaStamps(database, ledger).then((read) => read, () => undefined)
293
+ : undefined);
294
+ return scope.stamps;
295
+ }
296
+ /**
297
+ * @internal Tells the open of `database` in progress that it checked `setup`, the schema setup `stamp` names, without
298
+ * its stamp (SQLite and libSQL only): it ran it in a transaction that stamped it, found every object it creates in the
299
+ * catalog (with `verify`), or leaves it to the end (`deferred`). A schema change later in the same open, such as the
300
+ * next store's setup or a column it adds, leaves a stamp behind the schema version, and a store found in the catalog has
301
+ * none that is current, so the next open would check it again. The open's end reads the stamps once more and, where any
302
+ * of these is behind, checks or runs them in one transaction and stamps them all with the version it leaves: the next
303
+ * open of a current schema then takes no write lock and answers every such store from its stamp (#6560). False, and
304
+ * nothing is kept, outside such an open: the caller then runs `setup` as it would without stamps.
305
+ */
306
+ export function restampStorageSchemaAtOpenEnd(database, stamp, setup, options = {}) {
307
+ const scope = scopes.get(database);
308
+ if (scope === undefined || scope.ledger !== stamp.ledger || dialectOf(database).name !== "sqlite")
309
+ return false;
310
+ scope.restamp.set(stamp.domain, { stamp, setup, ...options });
311
+ return true;
312
+ }
313
+ /**
314
+ * Stamps again, in one transaction, the setups `scope`'s open checked whose stamps are behind: each with `verify` is
315
+ * checked against the catalog the transaction reads, and runs where that finds something missing; each without runs.
316
+ * Every deferred setup runs, and fails the open where the transaction fails. Otherwise housekeeping: a failure leaves the
317
+ * stamps behind, and the next open checks those stores as it would without them.
318
+ */
319
+ async function restamp(database, scope) {
320
+ const pending = [...scope.restamp.values()];
321
+ scope.restamp.clear();
322
+ if (pending.every((each) => each.alongside === true))
323
+ return;
324
+ const deferred = pending.some((each) => each.deferred === true);
325
+ try {
326
+ // Every setup this open checked was behind when it began. Where each is deferred or checked against the catalog,
327
+ // the end's transaction checks it again anyway, so the stamps are not read again; otherwise they are, to spare an
328
+ // open that changed nothing since its setups a transaction. None where no setup made the table yet.
329
+ const reread = pending.some((each) => each.deferred !== true && each.verify === undefined);
330
+ const current = reread
331
+ ? await readSqliteSchemaStamps(database, scope.ledger).catch(() => new Map())
332
+ : new Map();
333
+ const behind = pending.filter(({ stamp, deferred }) => deferred === true || (current.get(stampKey(stamp.domain)) ?? 0) < stamp.revision);
334
+ if (behind.length === 0)
335
+ return;
336
+ const table = sqliteSchemaStampTable(scope.ledger);
337
+ await database.transaction(async (tx) => {
338
+ const catalog = await readSqliteCatalog(tx, scope.ledger);
339
+ for (const { setup, verify, deferred } of behind)
340
+ if (deferred === true || verify === undefined || catalog === undefined || !verify(catalog))
341
+ await setup(tx);
342
+ await recordSqliteSchemaStamps(tx, behind.map(({ stamp }) => stamp), { tableExists: catalog?.hasTable(table) === true, last: true });
343
+ }, { retryTransientFailures: true, concurrency: { kind: "serial", domain: scope.ledger } });
344
+ }
345
+ catch (error) {
346
+ if (deferred)
347
+ throw error;
348
+ // The next open checks them again.
349
+ }
350
+ }
351
+ //# sourceMappingURL=schema-catalog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema-catalog.js","sourceRoot":"","sources":["../../../src/core/storage/schema-catalog.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,KAAK,iBAAiB,MAAM,yBAAyB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,SAAS,GAAmE,iBAAiB,CAAC;AA8BpG,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AAEvD;;;;GAIG;AACH,MAAM,WAAW,GAAG;;;;;;;;iFAQ6D,CAAC;AAIlF;;;GAGG;AACH,MAAM,kBAAkB,GAAG;;wBAEH,CAAC;AAEzB;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAc;IACpD,OAAO,MAAM,CAAC,QAAQ,CAAC,mBAAmB,CAAC;QAC1C,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,mBAAmB,CAAC,MAAM,CAAC,sBAAsB;QACvE,CAAC,CAAC,GAAG,MAAM,gBAAgB,CAAC;AAC9B,CAAC;AAED,qFAAqF;AACrF,MAAM,QAAQ,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,UAAU,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AC,MAAM,KAAK,CAAC;YAAE,OAAO;QAChC,MAAM,KAAK,GAAG,sBAAsB,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnD,MAAM,QAAQ,CAAC,WAAW,CACzB,KAAK,EAAE,EAAE,EAAE,EAAE;YACZ,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,EAAE,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;YAC1D,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,MAAM;gBAC/C,IAAI,QAAQ,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;oBACzF,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC;YAClB,MAAM,wBAAwB,CAC7B,EAAE,EACF,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,KAAK,CAAC,EAChC,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAC9D,CAAC;QACH,CAAC,EACD,EAAE,sBAAsB,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,EAAE,CACvF,CAAC;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,QAAQ;YAAE,MAAM,KAAK,CAAC;QAC1B,mCAAmC;IACpC,CAAC;AACF,CAAC","sourcesContent":["import type { SqliteDatabase, SqliteExecutor, SqliteRow } from \"./database.js\";\nimport { dialectOf } from \"./dialect.js\";\nimport * as statementSequence from \"./statement-sequence.js\";\n\n/**\n * `transactionFinisher` of `statement-sequence.ts`, which the copy of that module 0.10.3 and 0.10.4 loaded lacks: a\n * process an in-place update caught keeps that copy, where a named import would fail to link. Without it the stamps\n * go out on their own, before the commit.\n */\nconst finishers: Partial<Pick<typeof statementSequence, \"transactionFinisher\">> = statementSequence;\n\n/**\n * What a schema held when one open read it: its relations, triggers and columns, and on PostgreSQL the versions its\n * ledger records. Only a positive answer is final: the schema only moves forward, so what existed then still exists,\n * while something missing may have been created since and is checked again under the store's lock.\n */\nexport interface StorageSchemaCatalog {\n\t/** The ledger the versions were read from. */\n\treadonly ledger: string;\n\t/** The highest version `ledger` recorded for `domain`; 0 when none, or when the ledger did not exist. */\n\trecordedVersion(domain: string): number;\n\t/** Whether a table (or view) named `table` existed. */\n\thasTable(table: string): boolean;\n\t/** Whether a relation (table, index, sequence…) or a trigger named `name` existed. */\n\thasObject(name: string): boolean;\n\t/** Whether `table` had a column named `column`. */\n\thasColumn(table: string, column: string): boolean;\n\t/**\n\t * Whether a function named `name` existed in the schema and this role may run it: PostgreSQL only, absent on SQLite\n\t * and libSQL.\n\t */\n\treadonly hasFunction?: (name: string) => boolean;\n\t/**\n\t * What kind of object `name` was on SQLite and libSQL (`table`, `index`, `view` or `trigger`), from one read of\n\t * `sqlite_schema`; undefined when there was none, and always on PostgreSQL.\n\t */\n\treadonly sqliteObjectType?: (name: string) => string | undefined;\n}\n\nconst TABLE_KINDS = new Set([\"r\", \"p\", \"v\", \"m\", \"f\"]);\n\n/**\n * Every relation, trigger, column and function of the schema the statement runs in, in one statement and so one\n * snapshot. The catalog, not information_schema, finds relations, as `tableExists` does; columns come from\n * information_schema, as `columnExists` reads them. A function is listed with whether this role may execute it.\n */\nconst CATALOG_SQL = `SELECT 'relation' AS kind, c.relname::text AS name, c.relkind::text AS detail\n\tFROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace\nUNION ALL SELECT 'trigger', t.tgname::text, NULL\n\tFROM pg_catalog.pg_trigger t JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n\tWHERE c.relnamespace = current_schema()::regnamespace AND NOT t.tgisinternal\nUNION ALL SELECT 'column', table_name::text, column_name::text\n\tFROM information_schema.columns WHERE table_schema = current_schema()\nUNION ALL SELECT 'function', p.proname::text, CASE WHEN has_function_privilege(p.oid, 'EXECUTE') THEN 'executable' END\n\tFROM pg_catalog.pg_proc p WHERE p.pronamespace = current_schema()::regnamespace`;\n\ntype CatalogRow = SqliteRow & { kind: string; name: string; detail: string | null };\n\n/**\n * Every object of a SQLite or libSQL database and every column of its tables, generated ones included, in one\n * statement and so one snapshot: what `tableExists`, `columnExists` and `schemaObjects` ask one at a time (#6560).\n */\nconst SQLITE_CATALOG_SQL = `SELECT 'object' AS kind, name, type AS detail FROM sqlite_master\nUNION ALL SELECT 'column', m.name, c.name FROM sqlite_master AS m JOIN pragma_table_xinfo(m.name) AS c\n\tWHERE m.type = 'table'`;\n\n/**\n * @internal The table under `ledger`'s prefix where SQLite and libSQL record which revision of each store's schema\n * setup ran, and the database's schema version (`PRAGMA schema_version`) once it had: `domain`, `revision`,\n * `schema_version`. SQLite counts every change to the schema in that version, whoever makes it, an older Atomic that\n * records nothing included; a revision is believed only while the version still matches, so any later change is checked\n * again (#6560). Builds that do not know the table leave it alone.\n */\nexport function sqliteSchemaStampTable(ledger: string): string {\n\treturn ledger.endsWith(\"atomic_migrations\")\n\t\t? `${ledger.slice(0, -\"atomic_migrations\".length)}atomic_schema_stamps`\n\t\t: `${ledger}_schema_stamps`;\n}\n\n/** The key a store's setup is stamped under, as the PostgreSQL ledger records it. */\nconst stampKey = (domain: string) => `schema:${domain}`;\n\ntype StampRow = SqliteRow & { domain: string | null; revision: number | bigint | null; stamped: number | bigint };\n\n/**\n * The revisions `ledger`'s stamps record whose schema version is the database's now, by stamp key, read in one\n * statement so the two agree. Stamps of an older schema version are left out: something changed the schema since.\n */\nasync function readSqliteSchemaStamps(executor: SqliteExecutor, ledger: string): Promise<Map<string, number>> {\n\tconst rows = await executor.all<StampRow>(\n\t\t`SELECT domain, revision, schema_version AS stamped FROM ${sqliteSchemaStampTable(ledger)}\n\t\tUNION ALL SELECT NULL, NULL, schema_version FROM pragma_schema_version`,\n\t);\n\tconst now = rows.find((row) => row.domain === null)?.stamped;\n\tconst stamps = new Map<string, number>();\n\tfor (const row of rows)\n\t\tif (row.domain !== null && now !== undefined && Number(row.stamped) === Number(now))\n\t\t\tstamps.set(row.domain, Number(row.revision ?? 0));\n\treturn stamps;\n}\n\n/** @internal A store's schema setup, as its stamp records it: `ledger` names the prefix, `domain` the store. */\nexport interface SqliteSchemaStamp {\n\treadonly ledger: string;\n\treadonly domain: string;\n\treadonly revision: number;\n}\n\n/**\n * @internal Stamps each of `stamps`, in the transaction `tx` that ran their setups, with the schema version as that\n * transaction leaves it: a later open believes their revisions until the schema changes again (#6560). Creates the\n * stamps table first, unless `options.tableExists`, so its own creation is part of the version recorded. With\n * `options.last`, the stamps are the transaction's last statement: where its connection is pipelined, they go out with\n * its commit. SQLite and libSQL only; every stamp must share a ledger.\n */\nexport async function recordSqliteSchemaStamps(\n\ttx: SqliteExecutor,\n\tstamps: readonly SqliteSchemaStamp[],\n\toptions: { readonly tableExists?: boolean; readonly last?: boolean } = {},\n): Promise<void> {\n\tconst ledger = stamps[0]?.ledger;\n\tif (ledger === undefined) return;\n\tconst table = sqliteSchemaStampTable(ledger);\n\tif (options.tableExists !== true)\n\t\tawait tx.exec(\n\t\t\t`CREATE TABLE IF NOT EXISTS ${table} (domain TEXT NOT NULL PRIMARY KEY, revision INTEGER NOT NULL, schema_version INTEGER NOT NULL)`,\n\t\t);\n\t// The revision this transaction set up, even below a newer build's: the stamp says what was checked at this version.\n\t// One statement for them all, so a server pays one request.\n\tconst upsert = {\n\t\tsql: `INSERT INTO ${table} (domain, revision, schema_version)\n\t\tSELECT column1, column2, (SELECT schema_version FROM pragma_schema_version)\n\t\tFROM (VALUES ${stamps.map(() => \"(?, ?)\").join(\", \")}) WHERE true\n\t\tON CONFLICT(domain) DO UPDATE SET revision = excluded.revision, schema_version = excluded.schema_version`,\n\t\tparams: stamps.flatMap(({ domain, revision }) => [stampKey(domain), revision]),\n\t};\n\tif (options.last === true && finishers.transactionFinisher?.(tx)?.([upsert]) === true) return;\n\tawait tx.run(upsert.sql, ...upsert.params);\n}\n\n/** The catalog of a SQLite or libSQL database, or undefined when it cannot be read, such as on a SQLite too old. */\nasync function readSqliteCatalog(database: SqliteExecutor, ledger: string): Promise<StorageSchemaCatalog | undefined> {\n\tlet rows: CatalogRow[];\n\ttry {\n\t\trows = await database.all<CatalogRow>(SQLITE_CATALOG_SQL);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tconst types = new Map<string, string>();\n\tconst columns = new Set<string>();\n\tfor (const row of rows) {\n\t\tif (row.kind === \"column\") columns.add(`${row.name}\\0${row.detail}`);\n\t\telse types.set(row.name, String(row.detail));\n\t}\n\treturn {\n\t\tledger,\n\t\t// SQLite records no versions: its stores' stamps are read on their own (`sqliteSchemaStampsOf`).\n\t\trecordedVersion: () => 0,\n\t\thasTable: (table) => types.get(table) === \"table\",\n\t\thasObject: (name) => types.has(name),\n\t\thasColumn: (table, column) => columns.has(`${table}\\0${column}`),\n\t\tsqliteObjectType: (name) => types.get(name),\n\t};\n}\n\ntype VersionRow = SqliteRow & { domain: string; version: number | string | null };\n\n/** The tables, objects, columns and executable functions of PostgreSQL catalog rows (`CATALOG_SQL`'s). */\nfunction catalogSets(rows: readonly CatalogRow[]) {\n\tconst tables = new Set<string>();\n\tconst objects = new Set<string>();\n\tconst columns = new Set<string>();\n\tconst functions = new Set<string>();\n\tfor (const row of rows) {\n\t\tif (row.kind === \"column\") columns.add(`${row.name}\\0${row.detail}`);\n\t\telse if (row.kind === \"function\") {\n\t\t\tif (row.detail === \"executable\") functions.add(row.name);\n\t\t} else {\n\t\t\tobjects.add(row.name);\n\t\t\tif (row.kind === \"relation\" && TABLE_KINDS.has(String(row.detail))) tables.add(row.name);\n\t\t}\n\t}\n\treturn { tables, objects, columns, functions };\n}\n\n/**\n * The catalog rows and the ledger's versions of `database`'s schema, read in one read-only transaction whose start\n * carries both reads, so they cost one round trip (#6560). The versions are undefined when the ledger did not exist;\n * the whole read is undefined when it failed.\n */\nasync function readPostgresCatalog(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n\tphysicalLedger: string,\n): Promise<{ rows: CatalogRow[]; versions: VersionRow[] | undefined } | undefined> {\n\tconst versionsSql = `SELECT domain, MAX(version) AS version FROM ${ledger} GROUP BY domain`;\n\tlet read: { rows: CatalogRow[]; versions: VersionRow[] | undefined } | undefined;\n\ttry {\n\t\tawait database.transaction(\n\t\t\tasync (tx) => {\n\t\t\t\tread = undefined;\n\t\t\t\tconst rows = await tx.all<CatalogRow>(CATALOG_SQL);\n\t\t\t\t// Taken even where the ledger does not exist and its read failed, so the transaction ends with its commit,\n\t\t\t\t// sent at once, rather than with a rollback after it.\n\t\t\t\tconst ledgerExists = catalogSets(rows).tables.has(physicalLedger);\n\t\t\t\tconst versions = await tx.all<VersionRow>(versionsSql).catch((error: unknown) => {\n\t\t\t\t\tif (ledgerExists) throw error;\n\t\t\t\t\treturn undefined;\n\t\t\t\t});\n\t\t\t\tread = { rows, versions };\n\t\t\t},\n\t\t\t{\n\t\t\t\treadOnly: true,\n\t\t\t\tretryTransientFailures: true,\n\t\t\t\tleading: [\n\t\t\t\t\t{ sql: CATALOG_SQL, params: [] },\n\t\t\t\t\t{ sql: versionsSql, params: [] },\n\t\t\t\t],\n\t\t\t},\n\t\t);\n\t} catch {\n\t\treturn undefined;\n\t}\n\treturn read;\n}\n\n/**\n * Reads `database`'s schema and the versions `ledger` records, in one read-only transaction that takes no lock. On\n * PostgreSQL, an adapter that read them when it opened gives them once (`takeOpenedCatalog`), and the first open reads\n * nothing (#6560). On SQLite and libSQL, which record no versions, reads the schema alone in one statement. Undefined\n * when a read fails: the stores then check each object themselves.\n */\nexport async function readStorageSchemaCatalog(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n): Promise<StorageSchemaCatalog | undefined> {\n\tconst dialect = dialectOf(database);\n\tif (dialect.name === \"sqlite\") return readSqliteCatalog(database, ledger);\n\tif (!dialect.versionedMigrations || dialect.name !== \"postgres\") return undefined;\n\tconst physicalLedger = dialect.identifier(ledger);\n\tconst opened = database.takeOpenedCatalog?.();\n\tconst read =\n\t\topened !== undefined && opened.ledger === physicalLedger\n\t\t\t? {\n\t\t\t\t\trows: opened.rows as readonly CatalogRow[],\n\t\t\t\t\tversions: opened.versions as readonly VersionRow[] | undefined,\n\t\t\t\t}\n\t\t\t: await readPostgresCatalog(database, ledger, physicalLedger);\n\tif (read === undefined) return undefined;\n\tconst { tables, objects, columns, functions } = catalogSets(read.rows);\n\tconst recorded = new Map<string, number>();\n\tif (tables.has(physicalLedger)) {\n\t\tif (read.versions === undefined) return undefined;\n\t\tfor (const row of read.versions) recorded.set(row.domain, Number(row.version ?? 0));\n\t}\n\treturn {\n\t\tledger,\n\t\trecordedVersion: (domain) => recorded.get(domain) ?? 0,\n\t\thasTable: (table) => tables.has(dialect.identifier(table)),\n\t\thasObject: (name) => objects.has(dialect.identifier(name)),\n\t\thasColumn: (table, column) => columns.has(`${dialect.identifier(table)}\\0${column}`),\n\t\thasFunction: (name) => functions.has(dialect.identifier(name)),\n\t};\n}\n\ninterface CatalogScope {\n\treadonly ledger: string;\n\t/** Read when the scope starts on PostgreSQL, whose opens always ask it; on SQLite at the first question. */\n\tcatalog: Promise<StorageSchemaCatalog | undefined> | undefined;\n\treadonly read: () => Promise<StorageSchemaCatalog | undefined>;\n\tusers: number;\n\t/** The stamps valid when read, by stamp key, read at the first question: see {@link sqliteSchemaStampsOf}. */\n\tstamps: Promise<ReadonlyMap<string, number> | undefined> | undefined;\n\t/** The setups this open ran on SQLite, by domain, to stamp again at its end ({@link restampStorageSchemaAtOpenEnd}). */\n\treadonly restamp: Map<string, PendingRestamp>;\n}\n\ninterface PendingRestamp extends SchemaStampAtOpenEnd {\n\treadonly stamp: SqliteSchemaStamp;\n\treadonly setup: (tx: SqliteExecutor) => Promise<unknown>;\n}\n\n/** @internal How the end of an open stamps a store's setup: see {@link restampStorageSchemaAtOpenEnd}. */\nexport interface SchemaStampAtOpenEnd {\n\t/**\n\t * Whether the store's schema, as the end's transaction reads the catalog, holds everything `setup` creates. Given,\n\t * the end runs `setup` only where it does not; absent, it runs `setup` whenever the store's stamp is behind.\n\t */\n\treadonly verify?: (catalog: StorageSchemaCatalog) => boolean;\n\t/**\n\t * `setup` has not run in this open and must: the end runs it whatever the stamp, and a failure fails the open, as\n\t * the setup's own transaction would have. For a setup whose objects all exist and whose only other statements seed\n\t * rows nothing in the open reads, such as a counter's: it then shares the end's transaction instead of taking one.\n\t */\n\treadonly deferred?: boolean;\n\t/**\n\t * `setup` ran in this open, in a transaction that stamped nothing: it is stamped only when the end takes a transaction\n\t * for another store, never in one of its own, so a new database's first open takes none.\n\t */\n\treadonly alongside?: boolean;\n}\n\nconst scopes = new WeakMap<SqliteDatabase, CatalogScope>();\n\n/**\n * Runs `body`, an open of one or more stores on `database`, with one catalog read for all of them: the schema checks\n * of the stores it opens ({@link schemaCatalogOf}) answer from it, so an open whose schema is current runs no schema\n * transaction and takes no lock. Opens on `database` that overlap share the read. `views` are other handles on the\n * same connection, such as a borrowed view, whose checks answer from the same read.\n */\nexport async function withStorageSchemaCatalog<T>(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n\tbody: () => Promise<T>,\n\tviews: readonly SqliteDatabase[] = [],\n): Promise<T> {\n\tlet scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== ledger) {\n\t\tconst read = () => readStorageSchemaCatalog(database, ledger);\n\t\tconst catalog = dialectOf(database).name === \"sqlite\" ? undefined : read();\n\t\tscope = { ledger, catalog, read, users: 0, stamps: undefined, restamp: new Map() };\n\t\tscopes.set(database, scope);\n\t}\n\tconst shared = scope;\n\tconst handles = [database, ...views.filter((view) => !scopes.has(view))];\n\tfor (const handle of handles.slice(1)) scopes.set(handle, shared);\n\tshared.users += 1;\n\ttry {\n\t\tconst value = await body();\n\t\tif (shared.users === 1 && shared.restamp.size > 0) await restamp(database, shared);\n\t\treturn value;\n\t} finally {\n\t\tshared.users -= 1;\n\t\tfor (const handle of handles.slice(1)) if (scopes.get(handle) === shared) scopes.delete(handle);\n\t\tif (shared.users === 0 && scopes.get(database) === shared) scopes.delete(database);\n\t}\n}\n\n/**\n * Drops the catalog an open of `database` in progress read, so the next question reads the schema again: for a step of\n * the open that changed the schema the stores it opens after it ask about.\n */\nexport function refreshStorageSchemaCatalog(database: SqliteDatabase): void {\n\tconst scope = scopes.get(database);\n\tif (scope !== undefined) scope.catalog = undefined;\n}\n\n/**\n * Tells the catalog an open of `database` in progress read that the open created `tables` since, so the stores it\n * opens next find them without reading the schema again.\n */\nexport function noteStorageSchemaTables(database: SqliteDatabase, tables: readonly string[]): void {\n\tconst scope = scopes.get(database);\n\tif (scope?.catalog === undefined) return;\n\tconst identifier = dialectOf(database).identifier;\n\tconst created = new Set(tables.map((table) => identifier(table)));\n\tscope.catalog = scope.catalog.then(\n\t\t(catalog) =>\n\t\t\tcatalog && {\n\t\t\t\t...catalog,\n\t\t\t\thasTable: (table) => created.has(identifier(table)) || catalog.hasTable(table),\n\t\t\t\thasObject: (name) => created.has(identifier(name)) || catalog.hasObject(name),\n\t\t\t},\n\t);\n}\n\n/**\n * The catalog an open of `database` in progress read ({@link withStorageSchemaCatalog}), when it read `ledger`'s\n * versions or no `ledger` is named; undefined outside such an open, and when it could not be read.\n */\nexport async function schemaCatalogOf(\n\tdatabase: SqliteDatabase,\n\tledger?: string,\n): Promise<StorageSchemaCatalog | undefined> {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || (ledger !== undefined && scope.ledger !== ledger)) return undefined;\n\tscope.catalog ??= scope.read();\n\treturn scope.catalog;\n}\n\n/**\n * @internal The revisions the stamps under `ledger` record for the stores of `database` (SQLite and libSQL), by stamp\n * key (`schema:<domain>`), as the open of `database` in progress read them; only those whose schema version was the\n * database's then. Undefined outside such an open, and where none could be read, such as before any stamp. The first\n * question reads them after the open's catalog, and only where it holds their table.\n */\nexport async function sqliteSchemaStampsOf(\n\tdatabase: SqliteDatabase,\n\tledger: string,\n): Promise<ReadonlyMap<string, number> | undefined> {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== ledger || dialectOf(database).name !== \"sqlite\") return undefined;\n\t// Read once the catalog shows their table: a read of a missing table would fail, which costs a request, and makes a\n\t// libSQL file driver replace its connection.\n\tscope.stamps ??= schemaCatalogOf(database, ledger).then((catalog) =>\n\t\tcatalog?.hasTable(sqliteSchemaStampTable(ledger)) === true\n\t\t\t? readSqliteSchemaStamps(database, ledger).then(\n\t\t\t\t\t(read) => read,\n\t\t\t\t\t() => undefined,\n\t\t\t\t)\n\t\t\t: undefined,\n\t);\n\treturn scope.stamps;\n}\n\n/**\n * @internal Tells the open of `database` in progress that it checked `setup`, the schema setup `stamp` names, without\n * its stamp (SQLite and libSQL only): it ran it in a transaction that stamped it, found every object it creates in the\n * catalog (with `verify`), or leaves it to the end (`deferred`). A schema change later in the same open, such as the\n * next store's setup or a column it adds, leaves a stamp behind the schema version, and a store found in the catalog has\n * none that is current, so the next open would check it again. The open's end reads the stamps once more and, where any\n * of these is behind, checks or runs them in one transaction and stamps them all with the version it leaves: the next\n * open of a current schema then takes no write lock and answers every such store from its stamp (#6560). False, and\n * nothing is kept, outside such an open: the caller then runs `setup` as it would without stamps.\n */\nexport function restampStorageSchemaAtOpenEnd(\n\tdatabase: SqliteDatabase,\n\tstamp: SqliteSchemaStamp,\n\tsetup: (tx: SqliteExecutor) => Promise<unknown>,\n\toptions: SchemaStampAtOpenEnd = {},\n): boolean {\n\tconst scope = scopes.get(database);\n\tif (scope === undefined || scope.ledger !== stamp.ledger || dialectOf(database).name !== \"sqlite\") return false;\n\tscope.restamp.set(stamp.domain, { stamp, setup, ...options });\n\treturn true;\n}\n\n/**\n * Stamps again, in one transaction, the setups `scope`'s open checked whose stamps are behind: each with `verify` is\n * checked against the catalog the transaction reads, and runs where that finds something missing; each without runs.\n * Every deferred setup runs, and fails the open where the transaction fails. Otherwise housekeeping: a failure leaves the\n * stamps behind, and the next open checks those stores as it would without them.\n */\nasync function restamp(database: SqliteDatabase, scope: CatalogScope): Promise<void> {\n\tconst pending = [...scope.restamp.values()];\n\tscope.restamp.clear();\n\tif (pending.every((each) => each.alongside === true)) return;\n\tconst deferred = pending.some((each) => each.deferred === true);\n\ttry {\n\t\t// Every setup this open checked was behind when it began. Where each is deferred or checked against the catalog,\n\t\t// the end's transaction checks it again anyway, so the stamps are not read again; otherwise they are, to spare an\n\t\t// open that changed nothing since its setups a transaction. None where no setup made the table yet.\n\t\tconst reread = pending.some((each) => each.deferred !== true && each.verify === undefined);\n\t\tconst current = reread\n\t\t\t? await readSqliteSchemaStamps(database, scope.ledger).catch(() => new Map<string, number>())\n\t\t\t: new Map<string, number>();\n\t\tconst behind = pending.filter(\n\t\t\t({ stamp, deferred }) => deferred === true || (current.get(stampKey(stamp.domain)) ?? 0) < stamp.revision,\n\t\t);\n\t\tif (behind.length === 0) return;\n\t\tconst table = sqliteSchemaStampTable(scope.ledger);\n\t\tawait database.transaction(\n\t\t\tasync (tx) => {\n\t\t\t\tconst catalog = await readSqliteCatalog(tx, scope.ledger);\n\t\t\t\tfor (const { setup, verify, deferred } of behind)\n\t\t\t\t\tif (deferred === true || verify === undefined || catalog === undefined || !verify(catalog))\n\t\t\t\t\t\tawait setup(tx);\n\t\t\t\tawait recordSqliteSchemaStamps(\n\t\t\t\t\ttx,\n\t\t\t\t\tbehind.map(({ stamp }) => stamp),\n\t\t\t\t\t{ tableExists: catalog?.hasTable(table) === true, last: true },\n\t\t\t\t);\n\t\t\t},\n\t\t\t{ retryTransientFailures: true, concurrency: { kind: \"serial\", domain: scope.ledger } },\n\t\t);\n\t} catch (error) {\n\t\tif (deferred) throw error;\n\t\t// The next open checks them again.\n\t}\n}\n"]}
@@ -500,7 +500,7 @@ function __atomicOnDemandFailed(error, feature) {
500
500
  return (async () => {
501
501
  const root = new URL("../../", import.meta.url);
502
502
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
503
- const key = `${root.href}#0.10.10`;
503
+ const key = `${root.href}#0.10.11-alpha.2`;
504
504
  let release = releases.get(key);
505
505
  if (release === undefined) {
506
506
  const current = (async () => {
@@ -528,7 +528,7 @@ function __atomicOnDemandFailed(error, feature) {
528
528
  } catch {
529
529
  // No installation to read, as in a bundle of the package: the release the process runs decides.
530
530
  }
531
- const updatedTo = typeof installed === "string" && installed !== "0.10.10" ? installed : running !== undefined && running.version !== "0.10.10" ? "0.10.10" : undefined;
531
+ 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;
532
532
  if (updatedTo === undefined) throw error;
533
533
  const application = typeof running?.name === "string" ? running.name : "atomic";
534
534
  const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
@@ -1,38 +1,52 @@
1
1
  import "../../../_shared/rolldown-runtime-BGM3D5V3.js";
2
2
  import { createLabelEntry, historyPages, readSessionHistoryChunks } from "../../../_shared/startup-8-0-34CBHPZH.js";
3
- import { SessionEntryError } from "../../../_shared/settings-startup-4QCVCI53.js";
3
+ import { SESSION_HISTORY_SCAN_ENTRIES, SessionEntryError } from "../../../_shared/settings-startup-HXQLSUWM.js";
4
4
  // dist/core/storage/session/branch-fork-source.js
5
- async function forkRow(reader, item) {
6
- if ("entry" in item) return { entry: item.entry };
5
+ /** The row of `item`, which the stream read from session `id` and yields as the source stores it. */
6
+ async function forkRow(reader, id, item) {
7
+ const stored = {
8
+ sessionId: id,
9
+ seq: item.seq
10
+ };
11
+ if ("entry" in item) return {
12
+ entry: item.entry,
13
+ stored
14
+ };
7
15
  const { forkSeedFields } = await import("./chunked-resume-projection.code.js").catch((error) => __atomicOnDemandFailed(error, "session storage"));
8
16
  return {
9
17
  ...await forkSeedFields(() => readSessionHistoryChunks(reader, item)),
10
- reference: item
18
+ reference: item,
19
+ stored
11
20
  };
12
21
  }
13
22
  /** The SDK/CLI same-store clone keeps the original append log, including abandoned branches,
14
23
  * raw labels and recorded leaf moves. Unlike an interactive /fork it never edits structural links. */
15
- function completeSessionForkStream(id, epoch, through, resident) {
24
+ function completeSessionForkStream(id, epoch, through) {
16
25
  return {
17
26
  kind: "complete-session",
27
+ prefix: {
28
+ sessionId: id,
29
+ epoch,
30
+ through
31
+ },
18
32
  async *read(reader, _hasWritten, inlineSnapshot) {
19
- if (resident) {
20
- for (const entry of resident) yield { entry };
21
- return;
22
- }
23
- for await (const { items } of historyPages(reader, id, epoch, through, {})) for (const item of items) {
33
+ for await (const { items } of historyPages(reader, id, epoch, through, { pageEntries: SESSION_HISTORY_SCAN_ENTRIES })) for (const item of items) {
24
34
  if ("kind" in item && inlineSnapshot) {
25
35
  const entry = await inlineSnapshot(item);
26
36
  if (entry) {
27
37
  yield {
28
38
  entry,
29
39
  reference: item,
30
- inlineSnapshot: true
40
+ inlineSnapshot: true,
41
+ stored: {
42
+ sessionId: id,
43
+ seq: item.seq
44
+ }
31
45
  };
32
46
  continue;
33
47
  }
34
48
  }
35
- yield await forkRow(reader, item);
49
+ yield await forkRow(reader, id, item);
36
50
  }
37
51
  }
38
52
  };
@@ -53,8 +67,12 @@ function humanForkStream(id, epoch, through, leaf, leafId, labels, labelTimes) {
53
67
  const row = snapshot && "kind" in item ? {
54
68
  entry: snapshot,
55
69
  reference: item,
56
- inlineSnapshot: true
57
- } : await forkRow(reader, item);
70
+ inlineSnapshot: true,
71
+ stored: {
72
+ sessionId: id,
73
+ seq: item.seq
74
+ }
75
+ } : await forkRow(reader, id, item);
58
76
  const entry = row.entry;
59
77
  if (item.seq === leaf && entry.id === leafId) found = true;
60
78
  if (entry.type === "label") continue;
@@ -65,7 +83,7 @@ function humanForkStream(id, epoch, through, leaf, leafId, labels, labelTimes) {
65
83
  if (start !== void 0 && start < item.seq) {
66
84
  let target = false;
67
85
  search: for await (const earlier of pages(start, item.seq)) for (const x of earlier.items) {
68
- const e = (await forkRow(reader, x)).entry;
86
+ const e = (await forkRow(reader, id, x)).entry;
69
87
  if (!target) {
70
88
  if (x.seq !== start || e.type !== "label" || e.id !== entry.firstKeptEntryId) break search;
71
89
  target = true;
@@ -77,14 +95,18 @@ function humanForkStream(id, epoch, through, leaf, leafId, labels, labelTimes) {
77
95
  }
78
96
  }
79
97
  previous = entry.id;
80
- yield Object.keys(edits).length ? {
81
- ...row,
82
- entry: {
83
- ...entry,
84
- ...edits
85
- },
86
- edits
87
- } : row;
98
+ if (Object.keys(edits).length === 0) yield row;
99
+ else {
100
+ const { stored: _stored, ...edited } = row;
101
+ yield {
102
+ ...edited,
103
+ entry: {
104
+ ...entry,
105
+ ...edits
106
+ },
107
+ edits
108
+ };
109
+ }
88
110
  }
89
111
  if (!found) throw new SessionEntryError(leafId, "missing");
90
112
  for (const [target, label] of labels) {
@@ -105,7 +127,7 @@ function __atomicOnDemandFailed(error, feature) {
105
127
  return (async () => {
106
128
  const root = new URL("../../../", import.meta.url);
107
129
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
108
- const key = `${root.href}#0.10.10`;
130
+ const key = `${root.href}#0.10.11-alpha.2`;
109
131
  let release = releases.get(key);
110
132
  if (release === undefined) {
111
133
  const current = (async () => {
@@ -133,7 +155,7 @@ function __atomicOnDemandFailed(error, feature) {
133
155
  } catch {
134
156
  // No installation to read, as in a bundle of the package: the release the process runs decides.
135
157
  }
136
- const updatedTo = typeof installed === "string" && installed !== "0.10.10" ? installed : running !== undefined && running.version !== "0.10.10" ? "0.10.10" : undefined;
158
+ 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;
137
159
  if (updatedTo === undefined) throw error;
138
160
  const application = typeof running?.name === "string" ? running.name : "atomic";
139
161
  const restart = new Error(`${application} was updated to ${updatedTo} while this session was running; restart it to keep using ${feature}.`, {
@@ -1 +1 @@
1
- {"version":3,"file":"branch-fork-source.code.js","names":[],"sources":["../../../../src/core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AAI,UAAU,WAAW,IAAI,MAAM,CAAC;GAChF,WAAW,EAAE;GACb,MAAM,EAAE,OAAO,EAAC;EACjB;CACD,EACA;AACF"}
1
+ {"version":3,"file":"branch-fork-source.code.js","names":[],"sources":["../../../../src/core/storage/session/branch-fork-source.ts"],"mappings":";;;;;AAYA,eAAe,QAAQ,QAAsB,IAAY,MAAwB;CAChF,MAAM,SAAS;EAAE,WAAW;EAAI,KAAK,KAAK;CAAG;CAC7C,IAAI,WAAW,MAAM,OAAO;EAAE,OAAO,KAAK;EAAO;CAAM;CACvD,MAAM,EAAE,mBAAmB,MAAM,OAAO;CACxC,OAAO;EAAE,GAAI,MAAM,qBAAqB,yBAAyB,QAAQ,IAAI,CAAC;EAAI,WAAW;EAAM;CAAM;AAC1G;;;AAIA,SAAgB,0BAA0B,IAAY,OAA2B,SAAe;CAC/F,OAAO;EACN,MAAM;EACN,QAAQ;GAAE,WAAW;GAAI;GAAO;EAAO;EACvC,OAAO,KAAK,QAAQ,aAAa,gBAAc;GAE9C,WAAW,MAAM,EAAE,WAAW,aAAa,QAAQ,IAAI,OAAO,SAAS,EACtE,aAAa,6BACb,CAAA,GACA,KAAK,MAAM,QAAQ,OAAO;IACzB,IAAI,UAAU,QAAQ,gBAAgB;KACrC,MAAM,QAAQ,MAAM,eAAe,IAAI;KACvC,IAAI,OAAO;MACV,MAAM;OAAE;OAAO,WAAW;OAAM,gBAAgB;OAAM,QAAQ;QAAE,WAAW;QAAI,KAAK,KAAK;OAAG;MAAE;MAC9F;KACD;IACD;IACA,MAAM,MAAM,QAAQ,QAAQ,IAAI,IAAI;GACrC;EACF;CACA;AACF;;;AAIA,SAAgB,gBACf,IACA,OACA,SACA,MACA,QACA,QACA,YAAuC;CAEvC,OAAO,EACN,OAAO,KAAK,QAAQ,YAAY,gBAAc;EAC7C,MAAM,SAAS,SAAiB,UAC/B,aAAa,QAAQ,IAAI,OAAO,SAAS;GAAE,eAAe;GAAM;GAAS;EAAK,CAAE;EACjF,IAA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KAAE,GAAG;KAAQ,OAAO;MAAE,GAAG;MAAO,GAAG;KAAK;KAAI;IAAK;GACxD;EACD;EACD,IAAI,CAAC,OAAO,MAAM,IAAI,kBAAkB,QAAQ,SAAS;EACzD,KAAK,MAAM,CAAC,QAAQ,UAAU,QAAQ;GACrC,IAAI,CAAE,MAAM,WAAW,MAAM,GAAI;GACjC,IAAI,IAAI,iBAAiB,QAAQ,uBAAO,IAAI,IAAG,GAAI,UAAU,WAAW,IAAI,MAAM,CAAC;GACnF,OAAO,MAAM,WAAW,EAAE,EAAE,GAC3B,IAAI,iBAAiB,QAAQ,uBAAO,IAAI,IAAG,GAAI,UAAU,WAAW,IAAI,MAAM,CAAC;GAChF,WAAW,EAAE;GACb,MAAM,EAAE,OAAO,EAAC;EACjB;CACD,EACA;AACF"}
@@ -6,7 +6,7 @@ try {
6
6
  } catch (error) {
7
7
  const root = new URL("../../../", import.meta.url);
8
8
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
9
- const key = `${root.href}#0.10.10`;
9
+ const key = `${root.href}#0.10.11-alpha.2`;
10
10
  let release = releases.get(key);
11
11
  if (release === undefined) {
12
12
  const current = (async () => {
@@ -27,8 +27,8 @@ try {
27
27
  release = current;
28
28
  }
29
29
  const running = await release;
30
- if (running === undefined || running.version === "0.10.10") throw error;
31
- throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.10 while this session was running; restart it to keep using session storage.", {
30
+ if (running === undefined || running.version === "0.10.11-alpha.2") throw error;
31
+ throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using session storage.", {
32
32
  cause: error,
33
33
  });
34
34
  }
@@ -6,7 +6,7 @@ try {
6
6
  } catch (error) {
7
7
  const root = new URL("../../../", import.meta.url);
8
8
  const releases = (globalThis[Symbol.for("atomic.in-place-update-release.v1")] ??= new Map());
9
- const key = `${root.href}#0.10.10`;
9
+ const key = `${root.href}#0.10.11-alpha.2`;
10
10
  let release = releases.get(key);
11
11
  if (release === undefined) {
12
12
  const current = (async () => {
@@ -27,8 +27,8 @@ try {
27
27
  release = current;
28
28
  }
29
29
  const running = await release;
30
- if (running === undefined || running.version === "0.10.10") throw error;
31
- throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.10 while this session was running; restart it to keep using session storage.", {
30
+ if (running === undefined || running.version === "0.10.11-alpha.2") throw error;
31
+ throw new Error((typeof running.name === "string" ? running.name : "atomic") + " was updated to 0.10.11-alpha.2 while this session was running; restart it to keep using session storage.", {
32
32
  cause: error,
33
33
  });
34
34
  }