@bastani/atomic 0.10.11-alpha.2 → 0.10.11-alpha.4

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 (447) hide show
  1. package/CHANGELOG.md +150 -0
  2. package/README.md +5 -8
  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 +6 -6
  7. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +5 -5
  8. package/dist/_shared/mode-shared-2QJSCUM6.js +6 -6
  9. package/dist/_shared/p0-cli-BB45ZQY6.js +46 -67
  10. package/dist/_shared/p0-cli-BB45ZQY6.js.map +1 -1
  11. package/dist/_shared/p1a-prewarm-XIU57JHF.js +7 -8
  12. package/dist/_shared/p1a-prewarm-XIU57JHF.js.map +1 -1
  13. package/dist/_shared/{p1b-elig-ENCUPKKJ.js → p1b-elig-TVB5CBLL.js} +36 -8
  14. package/dist/_shared/p1b-elig-TVB5CBLL.js.map +1 -0
  15. package/dist/_shared/p2-shell-main-B2WIALFD.js +6 -3
  16. package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
  17. package/dist/_shared/runtime-O4KCSG4C.js +3 -3
  18. package/dist/_shared/{sdk-IQMULKFU.js → sdk-B5LEWGGI.js} +1218 -657
  19. package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
  20. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  21. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  22. package/dist/_shared/{startup-0-0-3IXNMFM2.js → startup-0-0-XJJDOIEC.js} +50 -48
  23. package/dist/_shared/startup-0-0-XJJDOIEC.js.map +1 -0
  24. package/dist/_shared/{startup-0-1-7T2IAE7J.js → startup-0-1-M6OWAYHH.js} +540 -136
  25. package/dist/_shared/startup-0-1-M6OWAYHH.js.map +1 -0
  26. package/dist/_shared/startup-0-2-5QHPCEON.js +47 -48
  27. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -1
  28. package/dist/_shared/startup-0-3-4ZYBYQNM.js +5 -5
  29. package/dist/_shared/startup-0-4-ZMJV547D.js +12 -7
  30. package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
  31. package/dist/_shared/startup-0-5-YDW47QX6.js +7 -7
  32. package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
  33. package/dist/_shared/startup-10-0-TDQNBDDL.js +6 -6
  34. package/dist/_shared/startup-12-0-55AAXBJZ.js +2 -2
  35. package/dist/_shared/startup-14-0-MLX36RBG.js +4 -5
  36. package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
  37. package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
  38. package/dist/_shared/startup-15-1-4S7FLMNG.js +19 -27
  39. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  40. package/dist/_shared/startup-8-0-34CBHPZH.js +2144 -249
  41. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  42. package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +98 -1184
  43. package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
  44. package/dist/_shared/storage-command-7MGXLJGZ.js +188 -37
  45. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  46. package/dist/_shared/storage-status-K7PX2RXA.js +557 -0
  47. package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -0
  48. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  49. package/dist/_shared/team-DOQKICG2.js +376 -0
  50. package/dist/_shared/team-DOQKICG2.js.map +1 -0
  51. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  52. package/dist/builtin/intercom/CHANGELOG.md +42 -0
  53. package/dist/builtin/intercom/README.md +2 -2
  54. package/dist/builtin/intercom/broker/broker.bundle.mjs +1917 -381
  55. package/dist/builtin/intercom/broker/client.ts +8 -0
  56. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +324 -68
  57. package/dist/builtin/intercom/broker/multinode-router.ts +256 -39
  58. package/dist/builtin/intercom/broker/multinode-state-store.ts +71 -5
  59. package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
  60. package/dist/builtin/intercom/broker/send-order-gate.ts +5 -2
  61. package/dist/builtin/intercom/broker/sql-add-column.ts +50 -5
  62. package/dist/builtin/intercom/broker/sql-ended-child-queue-store.ts +3 -2
  63. package/dist/builtin/intercom/broker/sql-held-send-store.ts +2 -2
  64. package/dist/builtin/intercom/broker/sql-known-session-store.ts +43 -19
  65. package/dist/builtin/intercom/broker/sql-lease-store.ts +473 -121
  66. package/dist/builtin/intercom/broker/sql-outbox-store.ts +821 -79
  67. package/dist/builtin/intercom/broker/sql-pending-ask-store.ts +8 -5
  68. package/dist/builtin/intercom/broker/sql-released-ask-store.ts +12 -5
  69. package/dist/builtin/intercom/broker/sql-restoring-reservation-store.ts +256 -8
  70. package/dist/builtin/intercom/broker/sql-retention.ts +150 -0
  71. package/dist/builtin/intercom/broker/sql-schema.ts +175 -24
  72. package/dist/builtin/intercom/broker/sql-sent-message-authority.ts +74 -19
  73. package/dist/builtin/intercom/broker/wake-up-bus.ts +6 -0
  74. package/dist/builtin/intercom/index.bundle.mjs +14 -4
  75. package/dist/builtin/intercom/package.json +1 -1
  76. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  77. package/dist/builtin/mcp/package.json +1 -1
  78. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  79. package/dist/builtin/subagents/package.json +1 -1
  80. package/dist/builtin/subagents/skills/skill-creator/eval-viewer/generate_review.py +8 -1
  81. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  82. package/dist/builtin/web-access/index.bundle.mjs +2 -10
  83. package/dist/builtin/web-access/package.json +1 -1
  84. package/dist/bun/bundled-sqlite.js +41 -0
  85. package/dist/bun/bundled-sqlite.js.map +1 -0
  86. package/dist/cli/args.js +2 -2
  87. package/dist/cli/auth-cli.code.js +4 -4
  88. package/dist/cli/auth-cli.impl.js +3 -3
  89. package/dist/cli/auth-cli.js +3 -3
  90. package/dist/cli/blueprint-command.code.js +3 -3
  91. package/dist/cli/blueprint-command.impl.js +3 -3
  92. package/dist/cli/blueprint-command.js +3 -3
  93. package/dist/cli/intercom-command.code.js +3 -3
  94. package/dist/cli/intercom-command.code.js.map +1 -1
  95. package/dist/cli/intercom-command.impl.js +3 -3
  96. package/dist/cli/intercom-command.js +3 -3
  97. package/dist/cli/list-models.code.js +2 -2
  98. package/dist/cli/list-models.impl.js +3 -3
  99. package/dist/cli/list-models.js +3 -3
  100. package/dist/cli/session-picker.code.js +1 -1
  101. package/dist/cli/session-picker.impl.js +3 -3
  102. package/dist/cli/session-picker.js +3 -3
  103. package/dist/cli/startup-ui.code.js +1 -1
  104. package/dist/cli/startup-ui.impl.js +3 -3
  105. package/dist/cli/startup-ui.js +3 -3
  106. package/dist/cli/storage-command.impl.js +3 -3
  107. package/dist/cli/storage-command.js +3 -3
  108. package/dist/cli/storage-search-session.code.js +3 -3
  109. package/dist/cli/storage-search-session.impl.js +3 -3
  110. package/dist/cli/storage-search-session.js +3 -3
  111. package/dist/cli/team-command.code.js +19 -113
  112. package/dist/cli/team-command.code.js.map +1 -1
  113. package/dist/cli/team-command.impl.js +3 -3
  114. package/dist/cli/team-command.js +3 -3
  115. package/dist/cli.js +5 -18
  116. package/dist/cli.js.map +1 -1
  117. package/dist/core/agent-rehydrate-errors.d.ts +4 -9
  118. package/dist/core/compaction/compactor.d.ts +3 -3
  119. package/dist/core/debug.code.js +1 -1
  120. package/dist/core/debug.impl.js +3 -3
  121. package/dist/core/debug.js +3 -3
  122. package/dist/core/export-html/card-projection.impl.js +3 -3
  123. package/dist/core/export-html/card-projection.js +3 -3
  124. package/dist/core/export-html/index.code.js +4 -4
  125. package/dist/core/export-html/index.code.js.map +1 -1
  126. package/dist/core/export-html/index.impl.js +3 -3
  127. package/dist/core/export-html/index.js +3 -3
  128. package/dist/core/export-html/json-spans.impl.js +3 -3
  129. package/dist/core/export-html/json-spans.js +3 -3
  130. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  131. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  132. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  133. package/dist/core/export-html/tool-renderer.js +3 -3
  134. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  135. package/dist/core/extensions/jiti-loader.js +3 -3
  136. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  137. package/dist/core/extensions/jiti-static-loader.js +3 -3
  138. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  139. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  140. package/dist/core/extensions/loader-host-modules.js +3 -3
  141. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  142. package/dist/core/extensions/runner-context.js +2 -2
  143. package/dist/core/intercom-broker-control-host.code.js +2 -2
  144. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  145. package/dist/core/intercom-broker-control-host.js +3 -3
  146. package/dist/core/intercom-broker-control.code.js +3 -3
  147. package/dist/core/intercom-broker-control.impl.js +3 -3
  148. package/dist/core/intercom-broker-control.js +3 -3
  149. package/dist/core/package-manager-storage-adapters.code.js +1 -1
  150. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  151. package/dist/core/package-manager-storage-adapters.js +3 -3
  152. package/dist/core/process-start-token.d.ts +12 -3
  153. package/dist/core/process-tree-containment.d.ts +16 -0
  154. package/dist/core/sdk-types.d.ts +1 -2
  155. package/dist/core/sdk-types.js.map +1 -1
  156. package/dist/core/sdk.code.js +3 -3
  157. package/dist/core/sdk.impl.js +3 -3
  158. package/dist/core/sdk.js +3 -3
  159. package/dist/core/session-manager-core.js +5 -5
  160. package/dist/core/session-manager-list.impl.js +3 -3
  161. package/dist/core/session-manager-list.js +3 -3
  162. package/dist/core/session-manager.code.js +1 -1
  163. package/dist/core/session-manager.impl.js +3 -3
  164. package/dist/core/session-manager.js +3 -3
  165. package/dist/core/session-storage.code.js +1 -1
  166. package/dist/core/session-storage.impl.js +3 -3
  167. package/dist/core/session-storage.js +3 -3
  168. package/dist/core/settings-schema.d.ts +0 -3
  169. package/dist/core/storage/added-exports-0-10-11.js +19 -0
  170. package/dist/core/storage/added-exports-0-10-11.js.map +1 -0
  171. package/dist/core/storage/creation-time.js +105 -0
  172. package/dist/core/storage/creation-time.js.map +1 -0
  173. package/dist/core/storage/database.d.ts +25 -5
  174. package/dist/core/storage/database.js.map +1 -1
  175. package/dist/core/storage/dialect.d.ts +1 -1
  176. package/dist/core/storage/dialect.js +1 -1
  177. package/dist/core/storage/dialect.js.map +1 -1
  178. package/dist/core/storage/errors.d.ts +13 -13
  179. package/dist/core/storage/errors.js +10 -16
  180. package/dist/core/storage/errors.js.map +1 -1
  181. package/dist/core/storage/fenced-paths.d.ts +18 -6
  182. package/dist/core/storage/fenced-paths.js +18 -6
  183. package/dist/core/storage/fenced-paths.js.map +1 -1
  184. package/dist/core/storage/file-identity.d.ts +2 -0
  185. package/dist/core/storage/file-identity.js +24 -8
  186. package/dist/core/storage/file-identity.js.map +1 -1
  187. package/dist/core/storage/index.d.ts +3 -2
  188. package/dist/core/storage/index.js +5 -3
  189. package/dist/core/storage/index.js.map +1 -1
  190. package/dist/core/storage/libsql-removed.d.ts +71 -0
  191. package/dist/core/storage/libsql-removed.js +123 -0
  192. package/dist/core/storage/libsql-removed.js.map +1 -0
  193. package/dist/core/storage/migrations.d.ts +78 -14
  194. package/dist/core/storage/migrations.js +375 -49
  195. package/dist/core/storage/migrations.js.map +1 -1
  196. package/dist/core/storage/node-sqlite-file-gate.js +0 -15
  197. package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
  198. package/dist/core/storage/node-sqlite-thread.js +215 -30
  199. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  200. package/dist/core/storage/node-sqlite.js +484 -72
  201. package/dist/core/storage/node-sqlite.js.map +1 -1
  202. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  203. package/dist/core/storage/offline-snapshot-file.js +3 -3
  204. package/dist/core/storage/prefix.d.ts +1 -1
  205. package/dist/core/storage/prefix.js +9 -2
  206. package/dist/core/storage/prefix.js.map +1 -1
  207. package/dist/core/storage/process-selection.d.ts +5 -5
  208. package/dist/core/storage/provider.js +2 -2
  209. package/dist/core/storage/schema-catalog.d.ts +76 -15
  210. package/dist/core/storage/schema-catalog.js +359 -68
  211. package/dist/core/storage/schema-catalog.js.map +1 -1
  212. package/dist/core/storage/selection.d.ts +7 -82
  213. package/dist/core/storage/selection.js +20 -235
  214. package/dist/core/storage/selection.js.map +1 -1
  215. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  216. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  217. package/dist/core/storage/session/branch-fork-source.js +3 -3
  218. package/dist/core/storage/session/card-view.impl.js +3 -3
  219. package/dist/core/storage/session/card-view.js +3 -3
  220. package/dist/core/storage/session/child-reader.code.js +3 -3
  221. package/dist/core/storage/session/child-reader.impl.js +3 -3
  222. package/dist/core/storage/session/child-reader.js +3 -3
  223. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  224. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  225. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  226. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  227. package/dist/core/storage/session/expanded-child-details.js +3 -3
  228. package/dist/core/storage/session/fork-detach.d.ts +11 -1
  229. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  230. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  231. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  232. package/dist/core/storage/session/fork-row-index.js +3 -3
  233. package/dist/core/storage/session/fork-staging.code.js +4 -7
  234. package/dist/core/storage/session/fork-staging.code.js.map +1 -1
  235. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  236. package/dist/core/storage/session/fork-staging.js +3 -3
  237. package/dist/core/storage/session/fork-sweep.js +31 -7
  238. package/dist/core/storage/session/fork-sweep.js.map +1 -1
  239. package/dist/core/storage/session/fork-window.code.js +3 -3
  240. package/dist/core/storage/session/fork-window.impl.js +3 -3
  241. package/dist/core/storage/session/fork-window.js +3 -3
  242. package/dist/core/storage/session/history-pages.impl.js +3 -3
  243. package/dist/core/storage/session/history-pages.js +3 -3
  244. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  245. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  246. package/dist/core/storage/session/jsonl-session-lock.d.ts +100 -0
  247. package/dist/core/storage/session/jsonl-session-store.d.ts +46 -24
  248. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  249. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  250. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  251. package/dist/core/storage/session/memory-session-store.js +3 -3
  252. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  253. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  254. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  255. package/dist/core/storage/session/released-history-files.code.js +9 -9
  256. package/dist/core/storage/session/released-history-files.code.js.map +1 -1
  257. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  258. package/dist/core/storage/session/released-history-files.js +3 -3
  259. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  260. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  261. package/dist/core/storage/session/session-resume.impl.js +3 -3
  262. package/dist/core/storage/session/session-resume.js +3 -3
  263. package/dist/core/storage/session/session-search-index.d.ts +52 -5
  264. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  265. package/dist/core/storage/session/snapshot-cut.js +3 -3
  266. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  267. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  268. package/dist/core/storage/session/snapshot-history.js +3 -3
  269. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  270. package/dist/core/storage/session/sql-session-store.d.ts +99 -18
  271. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  272. package/dist/core/storage/session/sql-session-store.js +3 -3
  273. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  274. package/dist/core/storage/session/tree-outline.js +3 -3
  275. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  276. package/dist/core/storage/session/tree-presentation.js +3 -3
  277. package/dist/core/storage/sqlite-facade.d.ts +12 -1
  278. package/dist/core/storage/sqlite-facade.js +310 -33
  279. package/dist/core/storage/sqlite-facade.js.map +1 -1
  280. package/dist/core/storage/sqlite-open-batch.js +10 -0
  281. package/dist/core/storage/sqlite-open-batch.js.map +1 -0
  282. package/dist/core/storage/storage-status.code.js +1 -1
  283. package/dist/core/storage/storage-status.impl.js +3 -3
  284. package/dist/core/storage/storage-status.js +3 -3
  285. package/dist/core/storage/team.code.js +1 -1
  286. package/dist/core/storage/team.d.ts +26 -115
  287. package/dist/core/storage/team.impl.js +3 -3
  288. package/dist/core/storage/team.js +3 -3
  289. package/dist/core/structured-output/index.code.js +1 -1
  290. package/dist/core/structured-output/index.impl.js +3 -3
  291. package/dist/core/structured-output/index.js +3 -3
  292. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  293. package/dist/core/tasks/task-completion-entry.js +3 -3
  294. package/dist/core/tasks/task-file-history.code.js +3 -3
  295. package/dist/core/tasks/task-file-history.impl.js +3 -3
  296. package/dist/core/tasks/task-file-history.js +3 -3
  297. package/dist/core/tasks/task-reference-archive.code.js +4 -4
  298. package/dist/core/tasks/task-reference-archive.js +3 -3
  299. package/dist/core/tasks/task-reference-identity.js +3 -3
  300. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  301. package/dist/core/tasks/task-reference-stream.js +3 -3
  302. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  303. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  304. package/dist/core/tasks/task-view-source.code.js +1 -1
  305. package/dist/core/tasks/task-view-source.impl.js +3 -3
  306. package/dist/core/tasks/task-view-source.js +3 -3
  307. package/dist/core/tools/history-tasks.d.ts +3 -2
  308. package/dist/core/tools/read-url.code.js +4 -4
  309. package/dist/core/tools/read-url.impl.js +3 -3
  310. package/dist/core/tools/read-url.js +3 -3
  311. package/dist/core/worktree-snapshot/blob-store.d.ts +44 -5
  312. package/dist/core/worktree-snapshot/blob-store.js +553 -30
  313. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  314. package/dist/core/worktree-snapshot/errors.code.js +2 -2
  315. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  316. package/dist/core/worktree-snapshot/errors.js +3 -3
  317. package/dist/core/worktree-snapshot/fork-blob-guard.js +81 -0
  318. package/dist/core/worktree-snapshot/fork-blob-guard.js.map +1 -0
  319. package/dist/core/worktree-snapshot/fork-snapshot-index.js +208 -50
  320. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -1
  321. package/dist/core/worktree-snapshot/session-index-reset.code.js +4 -0
  322. package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -1
  323. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  324. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  325. package/dist/extensions/codemode/execute.code.js +1 -1
  326. package/dist/extensions/codemode/execute.impl.js +3 -3
  327. package/dist/extensions/codemode/execute.js +3 -3
  328. package/dist/extensions/codemode/renderer.code.js +2 -2
  329. package/dist/extensions/codemode/renderer.impl.js +3 -3
  330. package/dist/extensions/codemode/renderer.js +3 -3
  331. package/dist/extensions/mcp/cli.code.js +3 -3
  332. package/dist/extensions/mcp/cli.impl.js +3 -3
  333. package/dist/extensions/mcp/cli.js +3 -3
  334. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  335. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  336. package/dist/extensions/mcp/cli.lazy.js +3 -3
  337. package/dist/extensions/mcp/runtime.code.js +1 -1
  338. package/dist/extensions/mcp/runtime.impl.js +3 -3
  339. package/dist/extensions/mcp/runtime.js +3 -3
  340. package/dist/index.d.ts +3 -1
  341. package/dist/index.js +5 -5
  342. package/dist/main-first-time-setup.code.js +1 -1
  343. package/dist/main-first-time-setup.impl.js +3 -3
  344. package/dist/main-first-time-setup.js +3 -3
  345. package/dist/main.js +1 -1
  346. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  347. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  348. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  349. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  350. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  351. package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
  352. package/dist/modes/interactive-engine/engine-prewarm.d.ts +1 -1
  353. package/dist/modes/print-mode.js +1 -1
  354. package/dist/package-manager-cli.code.js +6 -6
  355. package/dist/package-manager-cli.impl.js +3 -3
  356. package/dist/package-manager-cli.js +3 -3
  357. package/dist/rpc-entry.js +1 -1
  358. package/dist/startup-files.json +1 -1
  359. package/dist/startup-stages/10.js +1 -1
  360. package/dist/startup-stages/11.js +1 -1
  361. package/dist/startup-stages/12.js +1 -1
  362. package/dist/startup-stages/2.js +2 -4
  363. package/dist/startup-stages/3.js +1 -3
  364. package/dist/startup-stages/4.js +1 -2
  365. package/dist/startup-stages/5.js +1 -1
  366. package/dist/startup-stages/6.js +5 -7
  367. package/dist/startup-stages/7.js +3 -10
  368. package/dist/startup-stages/8.js +7 -2
  369. package/dist/startup-stages/9.js +1 -7
  370. package/dist/startup-stages/stages.json +1 -1
  371. package/dist/utils/compile-cache-deferral.js +8 -13
  372. package/dist/utils/compile-cache-deferral.js.map +1 -1
  373. package/dist/utils/compile-cache-warmup-host.js +3 -4
  374. package/dist/utils/compile-cache-warmup-host.js.map +1 -1
  375. package/dist/utils/compile-cache.js +12 -100
  376. package/dist/utils/compile-cache.js.map +1 -1
  377. package/dist/utils/startup-database-spare.code.js +2 -2
  378. package/dist/utils/startup-database-spare.impl.js +3 -3
  379. package/dist/utils/startup-database-spare.js +3 -3
  380. package/dist/utils/tools-manager.code.js +1 -1
  381. package/dist/utils/tools-manager.impl.js +3 -3
  382. package/dist/utils/tools-manager.js +3 -3
  383. package/dist/utils/worker-threads.js +2 -15
  384. package/dist/utils/worker-threads.js.map +1 -1
  385. package/docs/build.md +3 -3
  386. package/docs/changelog.mdx +1470 -69
  387. package/docs/compaction/reference.md +5 -5
  388. package/docs/compaction.md +7 -9
  389. package/docs/containerization.md +2 -2
  390. package/docs/custom-provider/api-reference.md +1 -1
  391. package/docs/docs.json +37 -10
  392. package/docs/environment-variables.md +0 -2
  393. package/docs/extensions/api-reference.md +4 -4
  394. package/docs/getting-started/installation.md +3 -0
  395. package/docs/guides/configuration.md +1 -1
  396. package/docs/guides/non-interactive.md +1 -1
  397. package/docs/guides/resume-on-any-machine.md +14 -22
  398. package/docs/guides/team-setup.md +56 -83
  399. package/docs/guides.md +2 -4
  400. package/docs/herdr.md +1 -1
  401. package/docs/index.md +1 -1
  402. package/docs/intercom/operations.md +26 -21
  403. package/docs/intercom/reference.md +2 -2
  404. package/docs/intercom.md +1 -1
  405. package/docs/libraries/storage-postgres.md +9 -9
  406. package/docs/libraries.md +2 -3
  407. package/docs/models-configuration.md +2 -2
  408. package/docs/models.md +2 -3
  409. package/docs/packages/authoring.md +7 -7
  410. package/docs/packages.md +1 -1
  411. package/docs/programmatic.md +2 -2
  412. package/docs/quickstart.md +1 -1
  413. package/docs/reference/cli.md +6 -11
  414. package/docs/reference.md +2 -2
  415. package/docs/rpc/extension-ui.md +2 -2
  416. package/docs/sdk/reference.md +5 -4
  417. package/docs/sdk/storage.md +8 -92
  418. package/docs/sdk/structured-decisions.md +1 -1
  419. package/docs/sdk/web-server.md +3 -3
  420. package/docs/sdk.md +14 -4
  421. package/docs/security.md +1 -1
  422. package/docs/session-format.md +5 -5
  423. package/docs/sessions.md +29 -49
  424. package/docs/settings.md +7 -8
  425. package/docs/storage/custom-adapters.md +255 -0
  426. package/docs/storage/jsonl.md +117 -0
  427. package/docs/{guides/postgres-pgbouncer.md → storage/postgres/pgbouncer.md} +66 -68
  428. package/docs/storage/postgres/tuning.md +337 -0
  429. package/docs/storage/postgres.md +556 -0
  430. package/docs/storage/sqlite.md +99 -0
  431. package/docs/storage.md +326 -990
  432. package/docs/subagents/authoring.md +1 -1
  433. package/docs/subagents.md +2 -2
  434. package/docs/tools.md +1 -1
  435. package/docs/worktree-snapshots.md +2 -2
  436. package/package.json +9 -9
  437. package/schemas/models.schema.json +2 -2
  438. package/schemas/settings.schema.json +0 -14
  439. package/dist/_shared/p1b-elig-ENCUPKKJ.js.map +0 -1
  440. package/dist/_shared/sdk-IQMULKFU.js.map +0 -1
  441. package/dist/_shared/startup-0-0-3IXNMFM2.js.map +0 -1
  442. package/dist/_shared/startup-0-1-7T2IAE7J.js.map +0 -1
  443. package/dist/_shared/startup-8-1-X32CYSXB.js.map +0 -1
  444. package/dist/core/intercom-broker-control.d.ts +0 -129
  445. package/dist/startup-stages/13.js +0 -1
  446. package/docs/guides/postgres-tuning.md +0 -311
  447. package/docs/libraries/storage-libsql.md +0 -97
@@ -1,11 +1,18 @@
1
1
  import { dialectOf } from "./dialect.js";
2
+ import { StorageSchemaVersionError } from "./errors.js";
2
3
  import * as statementSequence from "./statement-sequence.js";
3
4
  /**
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.
5
+ * `transactionFinisher`, `sequenceRunner` and `statementBatch` of `statement-sequence.ts`, which the copies 0.10.3 and
6
+ * 0.10.4 loaded lack: a process an in-place update caught keeps those copies, where a named import would fail to link.
7
+ * Without `statementBatch`, 0.10.3's connection thread cannot run `{ script: true }` entries inside a sequence request,
8
+ * so multi-statement scripts run via `tx.exec` instead.
7
9
  */
8
10
  const finishers = statementSequence;
11
+ function createAsyncScopeStore() {
12
+ const proc = globalThis.process;
13
+ const Ctor = proc?.getBuiltinModule?.("async_hooks")?.AsyncLocalStorage;
14
+ return Ctor === undefined ? undefined : new Ctor();
15
+ }
9
16
  const TABLE_KINDS = new Set(["r", "p", "v", "m", "f"]);
10
17
  /**
11
18
  * Every relation, trigger, column and function of the schema the statement runs in, in one statement and so one
@@ -22,14 +29,14 @@ UNION ALL SELECT 'column', table_name::text, column_name::text
22
29
  UNION ALL SELECT 'function', p.proname::text, CASE WHEN has_function_privilege(p.oid, 'EXECUTE') THEN 'executable' END
23
30
  FROM pg_catalog.pg_proc p WHERE p.pronamespace = current_schema()::regnamespace`;
24
31
  /**
25
- * Every object of a SQLite or libSQL database and every column of its tables, generated ones included, in one
32
+ * Every object of a SQLite database and every column of its tables, generated ones included, in one
26
33
  * statement and so one snapshot: what `tableExists`, `columnExists` and `schemaObjects` ask one at a time (#6560).
27
34
  */
28
35
  const SQLITE_CATALOG_SQL = `SELECT 'object' AS kind, name, type AS detail FROM sqlite_master
29
36
  UNION ALL SELECT 'column', m.name, c.name FROM sqlite_master AS m JOIN pragma_table_xinfo(m.name) AS c
30
37
  WHERE m.type = 'table'`;
31
38
  /**
32
- * @internal The table under `ledger`'s prefix where SQLite and libSQL record which revision of each store's schema
39
+ * @internal The table under `ledger`'s prefix where SQLite record which revision of each store's schema
33
40
  * setup ran, and the database's schema version (`PRAGMA schema_version`) once it had: `domain`, `revision`,
34
41
  * `schema_version`. SQLite counts every change to the schema in that version, whoever makes it, an older Atomic that
35
42
  * records nothing included; a revision is believed only while the version still matches, so any later change is checked
@@ -56,22 +63,12 @@ async function readSqliteSchemaStamps(executor, ledger) {
56
63
  stamps.set(row.domain, Number(row.revision ?? 0));
57
64
  return stamps;
58
65
  }
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 = {}) {
66
+ /** The SQLite statements that create (unless `tableExists`) and upsert `stamps` at the current `PRAGMA schema_version`. */
67
+ function sqliteStampStatements(stamps, tableExists) {
67
68
  const ledger = stamps[0]?.ledger;
68
69
  if (ledger === undefined)
69
- return;
70
+ return [];
70
71
  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
72
  const upsert = {
76
73
  sql: `INSERT INTO ${table} (domain, revision, schema_version)
77
74
  SELECT column1, column2, (SELECT schema_version FROM pragma_schema_version)
@@ -79,11 +76,39 @@ export async function recordSqliteSchemaStamps(tx, stamps, options = {}) {
79
76
  ON CONFLICT(domain) DO UPDATE SET revision = excluded.revision, schema_version = excluded.schema_version`,
80
77
  params: stamps.flatMap(({ domain, revision }) => [stampKey(domain), revision]),
81
78
  };
82
- if (options.last === true && finishers.transactionFinisher?.(tx)?.([upsert]) === true)
79
+ if (tableExists)
80
+ return [upsert];
81
+ return [
82
+ {
83
+ sql: `CREATE TABLE IF NOT EXISTS ${table} (domain TEXT NOT NULL PRIMARY KEY, revision INTEGER NOT NULL, schema_version INTEGER NOT NULL)`,
84
+ params: [],
85
+ script: true,
86
+ },
87
+ upsert,
88
+ ];
89
+ }
90
+ /**
91
+ * @internal Stamps each of `stamps`, in the transaction `tx` that ran their setups, with the schema version as that
92
+ * transaction leaves it: a later open believes their revisions until the schema changes again (#6560). Creates the
93
+ * stamps table first, unless `options.tableExists`, so its own creation is part of the version recorded. With
94
+ * `options.last`, the stamps are the transaction's last statements: where its connection is pipelined, they go out with
95
+ * its commit. SQLite only; every stamp must share a ledger.
96
+ */
97
+ export async function recordSqliteSchemaStamps(tx, stamps, options = {}) {
98
+ const statements = sqliteStampStatements(stamps, options.tableExists === true);
99
+ if (statements.length === 0)
83
100
  return;
84
- await tx.run(upsert.sql, ...upsert.params);
101
+ const canSequence = finishers.statementBatch !== undefined || statements.every((each) => each.script !== true);
102
+ if (options.last === true && canSequence && finishers.transactionFinisher?.(tx)?.(statements) === true)
103
+ return;
104
+ for (const statement of statements) {
105
+ if (statement.script === true)
106
+ await tx.exec(statement.sql);
107
+ else
108
+ await tx.run(statement.sql, ...statement.params);
109
+ }
85
110
  }
86
- /** The catalog of a SQLite or libSQL database, or undefined when it cannot be read, such as on a SQLite too old. */
111
+ /** The catalog of a SQLite database, or undefined when it cannot be read, such as on a SQLite too old. */
87
112
  async function readSqliteCatalog(database, ledger) {
88
113
  let rows;
89
114
  try {
@@ -169,7 +194,7 @@ async function readPostgresCatalog(database, ledger, physicalLedger) {
169
194
  /**
170
195
  * Reads `database`'s schema and the versions `ledger` records, in one read-only transaction that takes no lock. On
171
196
  * 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
197
+ * nothing (#6560). On SQLite, which record no versions, reads the schema alone in one statement. Undefined
173
198
  * when a read fails: the stores then check each object themselves.
174
199
  */
175
200
  export async function readStorageSchemaCatalog(database, ledger) {
@@ -206,18 +231,37 @@ export async function readStorageSchemaCatalog(database, ledger) {
206
231
  };
207
232
  }
208
233
  const scopes = new WeakMap();
234
+ /**
235
+ * Tracks the root open batch active on each `CatalogScope` along the current async call chain: nested opens share their
236
+ * enclosing root's batch and commit together at the root's end, while concurrent sibling opens on the same database
237
+ * handle each own and commit their own batch before returning (#6709).
238
+ */
239
+ const activeOpenBatches = createAsyncScopeStore();
240
+ /** How long a SQLite open batch polls `done` after `tryMaintenance` finds the lock busy before joining the queue. */
241
+ const SQLITE_BATCH_WAIT_MS = 1_000;
242
+ const SQLITE_BATCH_POLL_MS = 20;
243
+ const SQLITE_BATCH_MAX_POLL_MS = 250;
244
+ const pausePoll = (ms) => new Promise((resolve) => setTimeout(resolve, ms * (0.5 + Math.random() / 2)));
209
245
  /**
210
246
  * Runs `body`, an open of one or more stores on `database`, with one catalog read for all of them: the schema checks
211
247
  * 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.
248
+ * transaction and takes no lock. Opens on `database` that overlap share the read. On SQLite, setups queued inside the
249
+ * open ({@link queueSqliteSchemaSetup}) run in one write transaction before the root open returns (#6709). `views` are
250
+ * other handles on the same connection, such as a borrowed view, whose checks answer from the same read.
214
251
  */
215
252
  export async function withStorageSchemaCatalog(database, ledger, body, views = []) {
216
253
  let scope = scopes.get(database);
217
254
  if (scope === undefined || scope.ledger !== ledger) {
218
255
  const read = () => readStorageSchemaCatalog(database, ledger);
219
256
  const catalog = dialectOf(database).name === "sqlite" ? undefined : read();
220
- scope = { ledger, catalog, read, users: 0, stamps: undefined, restamp: new Map() };
257
+ scope = {
258
+ ledger,
259
+ catalog,
260
+ read,
261
+ users: 0,
262
+ stamps: undefined,
263
+ fallbackBatch: { ledger, setups: [], restamp: new Map() },
264
+ };
221
265
  scopes.set(database, scope);
222
266
  }
223
267
  const shared = scope;
@@ -225,11 +269,25 @@ export async function withStorageSchemaCatalog(database, ledger, body, views = [
225
269
  for (const handle of handles.slice(1))
226
270
  scopes.set(handle, shared);
227
271
  shared.users += 1;
228
- try {
272
+ const enclosing = activeOpenBatches?.getStore();
273
+ const isRoot = activeOpenBatches === undefined ? shared.users === 1 : enclosing?.has(shared) !== true;
274
+ const batch = activeOpenBatches === undefined
275
+ ? shared.fallbackBatch
276
+ : isRoot
277
+ ? { ledger, setups: [], restamp: new Map() }
278
+ : enclosing.get(shared);
279
+ const run = async () => {
229
280
  const value = await body();
230
- if (shared.users === 1 && shared.restamp.size > 0)
231
- await restamp(database, shared);
281
+ if (isRoot && (batch.setups.length > 0 || batch.restamp.size > 0))
282
+ await flushOpenBatch(database, shared, batch);
232
283
  return value;
284
+ };
285
+ try {
286
+ if (!isRoot || activeOpenBatches === undefined)
287
+ return await run();
288
+ const next = new Map(enclosing);
289
+ next.set(shared, batch);
290
+ return await activeOpenBatches.run(next, run);
233
291
  }
234
292
  finally {
235
293
  shared.users -= 1;
@@ -246,8 +304,10 @@ export async function withStorageSchemaCatalog(database, ledger, body, views = [
246
304
  */
247
305
  export function refreshStorageSchemaCatalog(database) {
248
306
  const scope = scopes.get(database);
249
- if (scope !== undefined)
307
+ if (scope !== undefined) {
250
308
  scope.catalog = undefined;
309
+ scope.stamps = undefined;
310
+ }
251
311
  }
252
312
  /**
253
313
  * Tells the catalog an open of `database` in progress read that the open created `tables` since, so the stores it
@@ -277,7 +337,7 @@ export async function schemaCatalogOf(database, ledger) {
277
337
  return scope.catalog;
278
338
  }
279
339
  /**
280
- * @internal The revisions the stamps under `ledger` record for the stores of `database` (SQLite and libSQL), by stamp
340
+ * @internal The revisions the stamps under `ledger` record for the stores of `database` (SQLite), by stamp
281
341
  * key (`schema:<domain>`), as the open of `database` in progress read them; only those whose schema version was the
282
342
  * database's then. Undefined outside such an open, and where none could be read, such as before any stamp. The first
283
343
  * question reads them after the open's catalog, and only where it holds their table.
@@ -287,65 +347,296 @@ export async function sqliteSchemaStampsOf(database, ledger) {
287
347
  if (scope === undefined || scope.ledger !== ledger || dialectOf(database).name !== "sqlite")
288
348
  return undefined;
289
349
  // 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.
350
+ // driver may replace its connection.
291
351
  scope.stamps ??= schemaCatalogOf(database, ledger).then((catalog) => catalog?.hasTable(sqliteSchemaStampTable(ledger)) === true
292
352
  ? readSqliteSchemaStamps(database, ledger).then((read) => read, () => undefined)
293
353
  : undefined);
294
354
  return scope.stamps;
295
355
  }
356
+ /** Active root open batch for `database` on SQLite (matching `ledger` when given), or undefined outside one. */
357
+ function activeBatchFor(database, ledger) {
358
+ if (dialectOf(database).name !== "sqlite")
359
+ return undefined;
360
+ const scope = scopes.get(database);
361
+ if (scope === undefined || (ledger !== undefined && scope.ledger !== ledger))
362
+ return undefined;
363
+ const batch = activeOpenBatches === undefined ? scope.fallbackBatch : activeOpenBatches.getStore()?.get(scope);
364
+ return batch === undefined ? undefined : { scope, batch };
365
+ }
366
+ /**
367
+ * @internal Queues `setup` into the active SQLite open scope (`withStorageSchemaCatalog`) so that all needed setups of
368
+ * the open execute in one write transaction before the open returns (#6709). Returns `false` outside a SQLite open
369
+ * scope (or for a different `ledger`), in which case the caller runs `setup` immediately.
370
+ */
371
+ export function queueSqliteSchemaSetup(database, ledger, setup) {
372
+ const active = activeBatchFor(database, ledger);
373
+ if (active === undefined)
374
+ return false;
375
+ active.batch.setups.push(setup);
376
+ return true;
377
+ }
378
+ /**
379
+ * @internal Executes and commits any SQLite schema setups queued so far in the active open scope, before the open
380
+ * needs their committed tables or evaluated outcomes (#6709). No-op when nothing is queued or outside a SQLite open.
381
+ */
382
+ export async function flushStorageSchemaSetups(database, ledger) {
383
+ const active = activeBatchFor(database, ledger);
384
+ if (active === undefined)
385
+ return;
386
+ if (active.batch.setups.length === 0 && active.batch.restamp.size === 0)
387
+ return;
388
+ await flushOpenBatch(database, active.scope, active.batch);
389
+ }
296
390
  /**
297
391
  * @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
392
+ * its stamp (SQLite only): it ran it in a transaction that stamped it, found every object it creates in the
299
393
  * catalog (with `verify`), or leaves it to the end (`deferred`). A schema change later in the same open, such as the
300
394
  * 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.
395
+ * none that is current, so the next open would check it again. The open's end checks or runs them in one transaction
396
+ * and stamps them all with the version it leaves: the next open of a current schema then takes no write lock and answers
397
+ * every such store from its stamp (#6560, #6709). False, and nothing is kept, outside such an open.
305
398
  */
306
399
  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")
400
+ const active = activeBatchFor(database, stamp.ledger);
401
+ if (active === undefined)
402
+ return false;
403
+ active.batch.restamp.set(stamp.domain, { stamp, setup, ...options });
404
+ return true;
405
+ }
406
+ /**
407
+ * Sends `writes` on `tx`, piggybacking onto `COMMIT` when `last` is true and the connection supports it. Returns
408
+ * `true` when sent via `transactionFinisher` (without per-statement `ignoreError` handling).
409
+ */
410
+ async function sendBatchWrites(tx, writes, last) {
411
+ if (writes.length === 0)
412
+ return false;
413
+ const statements = writes.map(({ statement }) => statement);
414
+ const canSequence = finishers.statementBatch !== undefined || statements.every((each) => each.script !== true);
415
+ if (last && canSequence && finishers.transactionFinisher?.(tx)?.(statements) === true)
416
+ return true;
417
+ const runSequence = canSequence ? finishers.sequenceRunner?.(tx) : undefined;
418
+ if (runSequence !== undefined && writes.every(({ ignoreError }) => ignoreError === undefined)) {
419
+ await runSequence({ statements });
420
+ return false;
421
+ }
422
+ for (const { statement, ignoreError } of writes) {
423
+ try {
424
+ if (statement.script === true)
425
+ await tx.exec(statement.sql);
426
+ else
427
+ await tx.run(statement.sql, ...statement.params);
428
+ }
429
+ catch (error) {
430
+ if (ignoreError?.(error) !== true)
431
+ throw error;
432
+ }
433
+ }
434
+ return false;
435
+ }
436
+ /**
437
+ * Checks outside any write lock whether another host completed every queued setup and restamp in this open batch.
438
+ * Updates `scope.catalog` and `scope.stamps` when complete so later questions in the same open see the fresh schema.
439
+ */
440
+ async function batchCompletedElsewhere(database, scope, setups, restamps) {
441
+ const catalog = await readSqliteCatalog(database, scope.ledger);
442
+ if (catalog === undefined)
443
+ return false;
444
+ const stampTable = sqliteSchemaStampTable(scope.ledger);
445
+ const needsStamps = setups.some((each) => each.stamp !== undefined) || restamps.length > 0;
446
+ const stamps = needsStamps && catalog.hasTable(stampTable)
447
+ ? await readSqliteSchemaStamps(database, scope.ledger).catch(() => undefined)
448
+ : undefined;
449
+ for (const entry of setups) {
450
+ if (entry.done !== undefined) {
451
+ if (!(await entry.done(catalog, stamps)))
452
+ return false;
453
+ continue;
454
+ }
455
+ if (entry.stamp !== undefined) {
456
+ if ((stamps?.get(stampKey(entry.stamp.domain)) ?? 0) < entry.stamp.revision)
457
+ return false;
458
+ continue;
459
+ }
460
+ if (entry.verify !== undefined) {
461
+ if (!entry.verify(catalog))
462
+ return false;
463
+ continue;
464
+ }
309
465
  return false;
310
- scope.restamp.set(stamp.domain, { stamp, setup, ...options });
466
+ }
467
+ for (const entry of restamps) {
468
+ if (entry.alongside === true && setups.length === 0)
469
+ continue;
470
+ if ((stamps?.get(stampKey(entry.stamp.domain)) ?? 0) < entry.stamp.revision)
471
+ return false;
472
+ }
473
+ scope.catalog = Promise.resolve(catalog);
474
+ scope.stamps = stamps === undefined ? undefined : Promise.resolve(stamps);
311
475
  return true;
312
476
  }
313
477
  /**
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.
478
+ * Runs every queued setup and restamp of `batch` in ONE SQLite write transaction through `tryMaintenance`, polling
479
+ * `batchCompletedElsewhere` when another host holds the lock and falling back to a normal serial transaction after
480
+ * {@link SQLITE_BATCH_WAIT_MS} (#6709).
318
481
  */
319
- async function restamp(database, scope) {
320
- const pending = [...scope.restamp.values()];
321
- scope.restamp.clear();
322
- if (pending.every((each) => each.alongside === true))
482
+ async function flushOpenBatch(database, scope, batch) {
483
+ const setups = batch.setups.splice(0);
484
+ const pendingRestamps = [...batch.restamp.values()];
485
+ batch.restamp.clear();
486
+ if (setups.length === 0 && pendingRestamps.every((each) => each.alongside === true))
323
487
  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)
488
+ const required = setups.length > 0 || pendingRestamps.some((each) => each.deferred === true);
489
+ const hasOptional = setups.some((each) => each.optional === true);
490
+ const stampTable = sqliteSchemaStampTable(scope.ledger);
491
+ let ignoreErrorPredicates = [];
492
+ let usedFinisher = false;
493
+ const runTransaction = async (tx, isolateOptional) => {
494
+ ignoreErrorPredicates = [];
495
+ usedFinisher = false;
496
+ for (const entry of setups)
497
+ entry.reset?.();
498
+ const catalog = await readSqliteCatalog(tx, scope.ledger);
499
+ const writes = [];
500
+ const addedColumns = new Set();
501
+ const createdTables = new Set();
502
+ const flushWrites = async () => {
503
+ if (writes.length === 0)
504
+ return;
505
+ const batchWrites = writes.splice(0);
506
+ await sendBatchWrites(tx, batchWrites, false);
507
+ };
508
+ const context = {
509
+ tx,
510
+ catalog,
511
+ enqueue(statement, options) {
512
+ const sequenced = typeof statement === "string" ? { sql: statement, params: [], script: true } : statement;
513
+ if (options?.ignoreError !== undefined)
514
+ ignoreErrorPredicates.push(options.ignoreError);
515
+ writes.push({
516
+ statement: sequenced,
517
+ ...(options?.ignoreError === undefined ? {} : { ignoreError: options.ignoreError }),
518
+ });
519
+ },
520
+ flushWrites,
521
+ noteColumnAdded(table, column) {
522
+ addedColumns.add(`${table}\0${column}`);
523
+ },
524
+ hasColumn(table, column) {
525
+ return catalog?.hasColumn(table, column) === true || addedColumns.has(`${table}\0${column}`);
526
+ },
527
+ noteTableCreated(table) {
528
+ createdTables.add(table);
529
+ },
530
+ createdTable(table) {
531
+ return createdTables.has(table);
532
+ },
533
+ tableExisted(table) {
534
+ return catalog?.hasTable(table) === true;
535
+ },
536
+ };
537
+ for (const entry of setups) {
538
+ if (!isolateOptional || entry.optional !== true) {
539
+ await entry.run(context);
540
+ continue;
541
+ }
542
+ await flushWrites();
543
+ await tx.exec("SAVEPOINT atomic_optional_schema_setup");
544
+ try {
545
+ await entry.run(context);
546
+ await flushWrites();
547
+ }
548
+ catch {
549
+ writes.length = 0;
550
+ await tx.exec("ROLLBACK TO SAVEPOINT atomic_optional_schema_setup");
551
+ entry.onFailure?.();
552
+ }
553
+ await tx.exec("RELEASE SAVEPOINT atomic_optional_schema_setup");
554
+ }
555
+ for (const { setup, verify, deferred } of pendingRestamps) {
556
+ if (deferred === true || verify === undefined || catalog === undefined || !verify(catalog)) {
557
+ await flushWrites();
558
+ await setup(tx);
559
+ }
560
+ }
561
+ // Collect stamps for every stamped setup and restamp in this batch (deduplicated by domain, keeping highest revision).
562
+ const stampByDomain = new Map();
563
+ for (const entry of setups) {
564
+ if (entry.stamp === undefined)
565
+ continue;
566
+ const prev = stampByDomain.get(entry.stamp.domain);
567
+ if (prev === undefined || entry.stamp.revision > prev.revision)
568
+ stampByDomain.set(entry.stamp.domain, entry.stamp);
569
+ }
570
+ for (const entry of pendingRestamps) {
571
+ const prev = stampByDomain.get(entry.stamp.domain);
572
+ if (prev === undefined || entry.stamp.revision > prev.revision)
573
+ stampByDomain.set(entry.stamp.domain, entry.stamp);
574
+ }
575
+ if (stampByDomain.size > 0) {
576
+ const stampStmts = sqliteStampStatements([...stampByDomain.values()], catalog?.hasTable(stampTable) === true);
577
+ for (const statement of stampStmts)
578
+ writes.push({ statement });
579
+ }
580
+ usedFinisher = await sendBatchWrites(tx, writes.splice(0), !isolateOptional);
581
+ };
582
+ const executeOnce = async (isolateOptional) => {
583
+ const waiting = () => database.transaction((tx) => runTransaction(tx, isolateOptional), {
584
+ retryTransientFailures: true,
585
+ concurrency: { kind: "serial", domain: scope.ledger },
586
+ });
587
+ const tryMaintenance = database.tryMaintenance?.bind(database);
588
+ if (tryMaintenance === undefined) {
589
+ await waiting();
590
+ scope.catalog = undefined;
591
+ scope.stamps = undefined;
335
592
  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 } });
593
+ }
594
+ const deadline = performance.now() + SQLITE_BATCH_WAIT_MS;
595
+ for (let wait = SQLITE_BATCH_POLL_MS;; wait = Math.min(wait * 2, SQLITE_BATCH_MAX_POLL_MS)) {
596
+ const won = await tryMaintenance((tx) => runTransaction(tx, isolateOptional));
597
+ if (won) {
598
+ scope.catalog = undefined;
599
+ scope.stamps = undefined;
600
+ return;
601
+ }
602
+ if (performance.now() >= deadline) {
603
+ await waiting();
604
+ scope.catalog = undefined;
605
+ scope.stamps = undefined;
606
+ return;
607
+ }
608
+ await pausePoll(wait);
609
+ if (await batchCompletedElsewhere(database, scope, setups, pendingRestamps))
610
+ return;
611
+ }
612
+ };
613
+ try {
614
+ // Pure restamp housekeeping (no queued setups, no deferred seeds): check current stamps first if any entry lacks
615
+ // `verify`, sparing an open that changed nothing since its setups a write transaction.
616
+ if (setups.length === 0 && !required && pendingRestamps.some((each) => each.verify === undefined)) {
617
+ const current = await readSqliteSchemaStamps(database, scope.ledger).catch(() => new Map());
618
+ const behind = pendingRestamps.filter(({ stamp }) => (current.get(stampKey(stamp.domain)) ?? 0) < stamp.revision);
619
+ if (behind.length === 0)
620
+ return;
621
+ }
622
+ await executeOnce(false);
344
623
  }
345
624
  catch (error) {
346
- if (deferred)
625
+ const retryIgnored = usedFinisher && ignoreErrorPredicates.some((match) => match(error));
626
+ if ((hasOptional || retryIgnored) && !(error instanceof StorageSchemaVersionError)) {
627
+ try {
628
+ await executeOnce(true);
629
+ return;
630
+ }
631
+ catch (retryError) {
632
+ if (required)
633
+ throw retryError;
634
+ return;
635
+ }
636
+ }
637
+ if (required)
347
638
  throw error;
348
- // The next open checks them again.
639
+ // Pure housekeeping restamp failure: the next open checks those stores again.
349
640
  }
350
641
  }
351
642
  //# sourceMappingURL=schema-catalog.js.map