@bastani/atomic 0.10.11-alpha.1 → 0.10.11-alpha.3

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 (457) hide show
  1. package/CHANGELOG.md +155 -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 +9 -9
  7. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +8 -8
  8. package/dist/_shared/mode-shared-2QJSCUM6.js +9 -9
  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} +14 -2
  14. package/dist/_shared/{p1b-elig-ENCUPKKJ.js.map → p1b-elig-TVB5CBLL.js.map} +1 -1
  15. package/dist/_shared/runtime-O4KCSG4C.js +5 -5
  16. package/dist/_shared/{sdk-AVFII7NK.js → sdk-B5LEWGGI.js} +2633 -488
  17. package/dist/_shared/sdk-B5LEWGGI.js.map +1 -0
  18. package/dist/_shared/session-data-AHTU7IS6.js +3 -3
  19. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  20. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +1 -1
  21. package/dist/_shared/{settings-startup-4QCVCI53.js → settings-startup-HXQLSUWM.js} +8 -2
  22. package/dist/_shared/settings-startup-HXQLSUWM.js.map +1 -0
  23. package/dist/_shared/{startup-0-0-57KF6LZH.js → startup-0-0-EZUKEP4Q.js} +436 -51
  24. package/dist/_shared/startup-0-0-EZUKEP4Q.js.map +1 -0
  25. package/dist/_shared/{startup-0-1-GIY75K46.js → startup-0-1-RTOHJFDJ.js} +240 -279
  26. package/dist/_shared/startup-0-1-RTOHJFDJ.js.map +1 -0
  27. package/dist/_shared/{startup-0-2-27OWFHV6.js → startup-0-2-5QHPCEON.js} +254 -46
  28. package/dist/_shared/startup-0-2-5QHPCEON.js.map +1 -0
  29. package/dist/_shared/{startup-0-3-T4DVFYWX.js → startup-0-3-4ZYBYQNM.js} +273 -14
  30. package/dist/_shared/startup-0-3-4ZYBYQNM.js.map +1 -0
  31. package/dist/_shared/startup-0-4-ZMJV547D.js +14 -9
  32. package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -1
  33. package/dist/_shared/startup-0-5-YDW47QX6.js +10 -10
  34. package/dist/_shared/startup-0-5-YDW47QX6.js.map +1 -1
  35. package/dist/_shared/startup-10-0-TDQNBDDL.js +9 -9
  36. package/dist/_shared/startup-12-0-55AAXBJZ.js +3 -3
  37. package/dist/_shared/startup-14-0-MLX36RBG.js +6 -7
  38. package/dist/_shared/startup-14-0-MLX36RBG.js.map +1 -1
  39. package/dist/_shared/startup-15-0-YUKGAC63.js +7 -7
  40. package/dist/_shared/startup-15-1-4S7FLMNG.js +22 -30
  41. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  42. package/dist/_shared/startup-8-0-34CBHPZH.js +455 -102
  43. package/dist/_shared/startup-8-0-34CBHPZH.js.map +1 -1
  44. package/dist/_shared/{startup-8-1-X32CYSXB.js → startup-8-1-LZFXSD3Z.js} +162 -1184
  45. package/dist/_shared/startup-8-1-LZFXSD3Z.js.map +1 -0
  46. package/dist/_shared/storage-command-7MGXLJGZ.js +189 -36
  47. package/dist/_shared/storage-command-7MGXLJGZ.js.map +1 -1
  48. package/dist/_shared/storage-status-K7PX2RXA.js +557 -0
  49. package/dist/_shared/storage-status-K7PX2RXA.js.map +1 -0
  50. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  51. package/dist/_shared/team-DOQKICG2.js +376 -0
  52. package/dist/_shared/team-DOQKICG2.js.map +1 -0
  53. package/dist/_shared/tree-outline-MUEPK5B7.js +3 -3
  54. package/dist/builtin/intercom/CHANGELOG.md +34 -0
  55. package/dist/builtin/intercom/README.md +2 -2
  56. package/dist/builtin/intercom/broker/broker.bundle.mjs +1091 -344
  57. package/dist/builtin/intercom/broker/database-wake-up-bus.ts +243 -64
  58. package/dist/builtin/intercom/broker/multinode-router.ts +154 -22
  59. package/dist/builtin/intercom/broker/multinode-state-store.ts +30 -3
  60. package/dist/builtin/intercom/broker/open-broker-state.ts +14 -0
  61. package/dist/builtin/intercom/broker/sql-add-column.ts +29 -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 +208 -101
  66. package/dist/builtin/intercom/broker/sql-outbox-store.ts +516 -102
  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 +24 -7
  70. package/dist/builtin/intercom/broker/sql-retention.ts +141 -0
  71. package/dist/builtin/intercom/broker/sql-schema.ts +199 -27
  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 +2 -3
  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/src/extension/index.bundle.mjs +1 -1
  81. package/dist/builtin/web-access/index.bundle.mjs +2 -10
  82. package/dist/builtin/web-access/package.json +1 -1
  83. package/dist/bun/bundled-sqlite.js +41 -0
  84. package/dist/bun/bundled-sqlite.js.map +1 -0
  85. package/dist/cli/args.js +2 -2
  86. package/dist/cli/auth-cli.code.js +6 -6
  87. package/dist/cli/auth-cli.impl.js +3 -3
  88. package/dist/cli/auth-cli.js +3 -3
  89. package/dist/cli/blueprint-command.code.js +4 -4
  90. package/dist/cli/blueprint-command.impl.js +3 -3
  91. package/dist/cli/blueprint-command.js +3 -3
  92. package/dist/cli/intercom-command.code.js +4 -4
  93. package/dist/cli/intercom-command.code.js.map +1 -1
  94. package/dist/cli/intercom-command.impl.js +3 -3
  95. package/dist/cli/intercom-command.js +3 -3
  96. package/dist/cli/list-models.code.js +2 -2
  97. package/dist/cli/list-models.impl.js +3 -3
  98. package/dist/cli/list-models.js +3 -3
  99. package/dist/cli/session-picker.code.js +2 -2
  100. package/dist/cli/session-picker.impl.js +3 -3
  101. package/dist/cli/session-picker.js +3 -3
  102. package/dist/cli/startup-ui.code.js +2 -2
  103. package/dist/cli/startup-ui.impl.js +3 -3
  104. package/dist/cli/startup-ui.js +3 -3
  105. package/dist/cli/storage-command.impl.js +3 -3
  106. package/dist/cli/storage-command.js +3 -3
  107. package/dist/cli/storage-search-session.code.js +3 -3
  108. package/dist/cli/storage-search-session.impl.js +3 -3
  109. package/dist/cli/storage-search-session.js +3 -3
  110. package/dist/cli/team-command.code.js +20 -114
  111. package/dist/cli/team-command.code.js.map +1 -1
  112. package/dist/cli/team-command.impl.js +3 -3
  113. package/dist/cli/team-command.js +3 -3
  114. package/dist/cli.js +5 -18
  115. package/dist/cli.js.map +1 -1
  116. package/dist/core/agent-rehydrate-errors.d.ts +4 -9
  117. package/dist/core/compaction/compactor.d.ts +3 -3
  118. package/dist/core/debug.code.js +1 -1
  119. package/dist/core/debug.impl.js +3 -3
  120. package/dist/core/debug.js +3 -3
  121. package/dist/core/export-html/card-projection.impl.js +3 -3
  122. package/dist/core/export-html/card-projection.js +3 -3
  123. package/dist/core/export-html/index.code.js +2 -2
  124. package/dist/core/export-html/index.impl.js +3 -3
  125. package/dist/core/export-html/index.js +3 -3
  126. package/dist/core/export-html/json-spans.impl.js +3 -3
  127. package/dist/core/export-html/json-spans.js +3 -3
  128. package/dist/core/export-html/oversized-render-inputs.code.js +1 -1
  129. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  130. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  131. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  132. package/dist/core/export-html/tool-renderer.js +3 -3
  133. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  134. package/dist/core/extensions/jiti-loader.js +3 -3
  135. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  136. package/dist/core/extensions/jiti-static-loader.js +3 -3
  137. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  138. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  139. package/dist/core/extensions/loader-host-modules.js +3 -3
  140. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  141. package/dist/core/extensions/runner-context.js +3 -3
  142. package/dist/core/intercom-broker-control-host.code.js +2 -2
  143. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  144. package/dist/core/intercom-broker-control-host.js +3 -3
  145. package/dist/core/intercom-broker-control.code.js +3 -3
  146. package/dist/core/intercom-broker-control.impl.js +3 -3
  147. package/dist/core/intercom-broker-control.js +3 -3
  148. package/dist/core/package-manager-storage-adapters.code.js +1 -1
  149. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  150. package/dist/core/package-manager-storage-adapters.js +3 -3
  151. package/dist/core/process-start-token.d.ts +8 -0
  152. package/dist/core/process-tree-containment.d.ts +16 -0
  153. package/dist/core/sdk-types.d.ts +1 -2
  154. package/dist/core/sdk-types.js.map +1 -1
  155. package/dist/core/sdk.code.js +4 -4
  156. package/dist/core/sdk.impl.js +3 -3
  157. package/dist/core/sdk.js +3 -3
  158. package/dist/core/session-manager-core.js +27 -15
  159. package/dist/core/session-manager-core.js.map +1 -1
  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 +3 -3
  163. package/dist/core/session-manager.impl.js +3 -3
  164. package/dist/core/session-manager.js +3 -3
  165. package/dist/core/session-open-markers.js +3 -0
  166. package/dist/core/session-open-markers.js.map +1 -0
  167. package/dist/core/session-storage.code.js +1 -1
  168. package/dist/core/session-storage.impl.js +3 -3
  169. package/dist/core/session-storage.js +3 -3
  170. package/dist/core/settings-schema.d.ts +0 -3
  171. package/dist/core/storage/added-exports-0-10-11.js +19 -0
  172. package/dist/core/storage/added-exports-0-10-11.js.map +1 -0
  173. package/dist/core/storage/added-exports.js +3 -0
  174. package/dist/core/storage/added-exports.js.map +1 -1
  175. package/dist/core/storage/creation-time.js +105 -0
  176. package/dist/core/storage/creation-time.js.map +1 -0
  177. package/dist/core/storage/database.d.ts +56 -5
  178. package/dist/core/storage/database.js.map +1 -1
  179. package/dist/core/storage/dialect.d.ts +1 -1
  180. package/dist/core/storage/dialect.js +1 -1
  181. package/dist/core/storage/dialect.js.map +1 -1
  182. package/dist/core/storage/errors.d.ts +13 -13
  183. package/dist/core/storage/errors.js +10 -16
  184. package/dist/core/storage/errors.js.map +1 -1
  185. package/dist/core/storage/fenced-paths.d.ts +11 -0
  186. package/dist/core/storage/fenced-paths.js +11 -0
  187. package/dist/core/storage/fenced-paths.js.map +1 -1
  188. package/dist/core/storage/file-identity.d.ts +2 -0
  189. package/dist/core/storage/file-identity.js +24 -8
  190. package/dist/core/storage/file-identity.js.map +1 -1
  191. package/dist/core/storage/index.d.ts +4 -3
  192. package/dist/core/storage/index.js +5 -3
  193. package/dist/core/storage/index.js.map +1 -1
  194. package/dist/core/storage/libsql-removed.d.ts +71 -0
  195. package/dist/core/storage/libsql-removed.js +123 -0
  196. package/dist/core/storage/libsql-removed.js.map +1 -0
  197. package/dist/core/storage/migrations.d.ts +81 -8
  198. package/dist/core/storage/migrations.js +386 -47
  199. package/dist/core/storage/migrations.js.map +1 -1
  200. package/dist/core/storage/node-sqlite-file-gate.js +0 -15
  201. package/dist/core/storage/node-sqlite-file-gate.js.map +1 -1
  202. package/dist/core/storage/node-sqlite-thread.js +36 -12
  203. package/dist/core/storage/node-sqlite-thread.js.map +1 -1
  204. package/dist/core/storage/node-sqlite.js +135 -3
  205. package/dist/core/storage/node-sqlite.js.map +1 -1
  206. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  207. package/dist/core/storage/offline-snapshot-file.js +3 -3
  208. package/dist/core/storage/prefix.d.ts +1 -1
  209. package/dist/core/storage/prefix.js +14 -2
  210. package/dist/core/storage/prefix.js.map +1 -1
  211. package/dist/core/storage/process-selection.d.ts +5 -5
  212. package/dist/core/storage/provider.js +2 -2
  213. package/dist/core/storage/schema-catalog.d.ts +82 -5
  214. package/dist/core/storage/schema-catalog.js +244 -34
  215. package/dist/core/storage/schema-catalog.js.map +1 -1
  216. package/dist/core/storage/selection.d.ts +7 -82
  217. package/dist/core/storage/selection.js +20 -235
  218. package/dist/core/storage/selection.js.map +1 -1
  219. package/dist/core/storage/session/branch-fork-source.code.js +9 -8
  220. package/dist/core/storage/session/branch-fork-source.code.js.map +1 -1
  221. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  222. package/dist/core/storage/session/branch-fork-source.js +3 -3
  223. package/dist/core/storage/session/card-view.impl.js +3 -3
  224. package/dist/core/storage/session/card-view.js +3 -3
  225. package/dist/core/storage/session/child-reader.code.js +4 -4
  226. package/dist/core/storage/session/child-reader.impl.js +3 -3
  227. package/dist/core/storage/session/child-reader.js +3 -3
  228. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  229. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  230. package/dist/core/storage/session/errors.js +1 -1
  231. package/dist/core/storage/session/expanded-child-details.code.js +3 -3
  232. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  233. package/dist/core/storage/session/expanded-child-details.js +3 -3
  234. package/dist/core/storage/session/fork-detach.d.ts +118 -0
  235. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  236. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  237. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  238. package/dist/core/storage/session/fork-row-index.js +3 -3
  239. package/dist/core/storage/session/fork-schema.js +53 -0
  240. package/dist/core/storage/session/fork-schema.js.map +1 -0
  241. package/dist/core/storage/session/fork-segments.d.ts +58 -0
  242. package/dist/core/storage/session/fork-staging.code.js +5 -8
  243. package/dist/core/storage/session/fork-staging.code.js.map +1 -1
  244. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  245. package/dist/core/storage/session/fork-staging.js +3 -3
  246. package/dist/core/storage/session/fork-sweep.js +61 -0
  247. package/dist/core/storage/session/fork-sweep.js.map +1 -0
  248. package/dist/core/storage/session/fork-window.code.js +4 -4
  249. package/dist/core/storage/session/fork-window.impl.js +3 -3
  250. package/dist/core/storage/session/fork-window.js +3 -3
  251. package/dist/core/storage/session/history-pages.impl.js +3 -3
  252. package/dist/core/storage/session/history-pages.js +3 -3
  253. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  254. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  255. package/dist/core/storage/session/jsonl-session-store.d.ts +42 -2
  256. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  257. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  258. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  259. package/dist/core/storage/session/memory-session-store.js +3 -3
  260. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  261. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  262. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  263. package/dist/core/storage/session/released-history-files.code.js +4 -4
  264. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  265. package/dist/core/storage/session/released-history-files.js +3 -3
  266. package/dist/core/storage/session/resident-fork-rows.code.js +1 -1
  267. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  268. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  269. package/dist/core/storage/session/session-resume.impl.js +3 -3
  270. package/dist/core/storage/session/session-resume.js +3 -3
  271. package/dist/core/storage/session/session-search-index.d.ts +43 -4
  272. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  273. package/dist/core/storage/session/snapshot-cut.js +3 -3
  274. package/dist/core/storage/session/snapshot-history.code.js +4 -4
  275. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  276. package/dist/core/storage/session/snapshot-history.js +3 -3
  277. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  278. package/dist/core/storage/session/sql-session-store.d.ts +394 -20
  279. package/dist/core/storage/session/sql-session-store.impl.js +4 -4
  280. package/dist/core/storage/session/sql-session-store.js +4 -4
  281. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  282. package/dist/core/storage/session/tree-outline.js +3 -3
  283. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  284. package/dist/core/storage/session/tree-presentation.js +3 -3
  285. package/dist/core/storage/session/types.d.ts +22 -0
  286. package/dist/core/storage/sqlite-facade.d.ts +23 -2
  287. package/dist/core/storage/sqlite-facade.js +34 -0
  288. package/dist/core/storage/sqlite-facade.js.map +1 -1
  289. package/dist/core/storage/storage-status.code.js +1 -1
  290. package/dist/core/storage/storage-status.impl.js +3 -3
  291. package/dist/core/storage/storage-status.js +3 -3
  292. package/dist/core/storage/team.code.js +1 -1
  293. package/dist/core/storage/team.d.ts +26 -115
  294. package/dist/core/storage/team.impl.js +3 -3
  295. package/dist/core/storage/team.js +3 -3
  296. package/dist/core/structured-output/index.code.js +1 -1
  297. package/dist/core/structured-output/index.impl.js +3 -3
  298. package/dist/core/structured-output/index.js +3 -3
  299. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  300. package/dist/core/tasks/task-completion-entry.js +3 -3
  301. package/dist/core/tasks/task-file-history.code.js +4 -4
  302. package/dist/core/tasks/task-file-history.impl.js +3 -3
  303. package/dist/core/tasks/task-file-history.js +3 -3
  304. package/dist/core/tasks/task-reference-archive.code.js +5 -5
  305. package/dist/core/tasks/task-reference-archive.js +3 -3
  306. package/dist/core/tasks/task-reference-identity.js +3 -3
  307. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  308. package/dist/core/tasks/task-reference-stream.js +3 -3
  309. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  310. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  311. package/dist/core/tasks/task-view-source.code.js +1 -1
  312. package/dist/core/tasks/task-view-source.impl.js +3 -3
  313. package/dist/core/tasks/task-view-source.js +3 -3
  314. package/dist/core/tools/history-session.d.ts +2 -0
  315. package/dist/core/tools/history-tasks.d.ts +3 -2
  316. package/dist/core/tools/read-url.code.js +4 -4
  317. package/dist/core/tools/read-url.impl.js +3 -3
  318. package/dist/core/tools/read-url.js +3 -3
  319. package/dist/core/worktree-snapshot/blob-store.d.ts +71 -3
  320. package/dist/core/worktree-snapshot/blob-store.js +575 -67
  321. package/dist/core/worktree-snapshot/blob-store.js.map +1 -1
  322. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  323. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  324. package/dist/core/worktree-snapshot/errors.js +3 -3
  325. package/dist/core/worktree-snapshot/fork-blob-guard.js +81 -0
  326. package/dist/core/worktree-snapshot/fork-blob-guard.js.map +1 -0
  327. package/dist/core/worktree-snapshot/fork-snapshot-index.js +162 -0
  328. package/dist/core/worktree-snapshot/fork-snapshot-index.js.map +1 -0
  329. package/dist/core/worktree-snapshot/session-index-reset.code.js +4 -0
  330. package/dist/core/worktree-snapshot/session-index-reset.code.js.map +1 -1
  331. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  332. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  333. package/dist/extensions/codemode/execute.code.js +2 -2
  334. package/dist/extensions/codemode/execute.impl.js +3 -3
  335. package/dist/extensions/codemode/execute.js +3 -3
  336. package/dist/extensions/codemode/renderer.code.js +2 -2
  337. package/dist/extensions/codemode/renderer.impl.js +3 -3
  338. package/dist/extensions/codemode/renderer.js +3 -3
  339. package/dist/extensions/mcp/cli.code.js +3 -3
  340. package/dist/extensions/mcp/cli.impl.js +3 -3
  341. package/dist/extensions/mcp/cli.js +3 -3
  342. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  343. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  344. package/dist/extensions/mcp/cli.lazy.js +3 -3
  345. package/dist/extensions/mcp/runtime.code.js +1 -1
  346. package/dist/extensions/mcp/runtime.impl.js +3 -3
  347. package/dist/extensions/mcp/runtime.js +3 -3
  348. package/dist/index.d.ts +3 -1
  349. package/dist/index.js +8 -8
  350. package/dist/main-first-time-setup.code.js +2 -2
  351. package/dist/main-first-time-setup.impl.js +3 -3
  352. package/dist/main-first-time-setup.js +3 -3
  353. package/dist/main.js +1 -1
  354. package/dist/modes/interactive/components/stored-tree-view.code.js +3 -3
  355. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  356. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  357. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  358. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  359. package/dist/modes/interactive/startup-shell-eligibility.js +1 -1
  360. package/dist/modes/interactive-engine/engine-prewarm.d.ts +1 -1
  361. package/dist/modes/print-mode.js +1 -1
  362. package/dist/package-manager-cli.code.js +7 -7
  363. package/dist/package-manager-cli.impl.js +3 -3
  364. package/dist/package-manager-cli.js +3 -3
  365. package/dist/rpc-entry.js +1 -1
  366. package/dist/startup-files.json +1 -1
  367. package/dist/startup-stages/10.js +1 -1
  368. package/dist/startup-stages/11.js +1 -1
  369. package/dist/startup-stages/12.js +1 -1
  370. package/dist/startup-stages/2.js +2 -3
  371. package/dist/startup-stages/3.js +1 -3
  372. package/dist/startup-stages/4.js +1 -2
  373. package/dist/startup-stages/5.js +1 -1
  374. package/dist/startup-stages/6.js +5 -7
  375. package/dist/startup-stages/7.js +3 -6
  376. package/dist/startup-stages/8.js +7 -2
  377. package/dist/startup-stages/9.js +1 -7
  378. package/dist/startup-stages/stages.json +1 -1
  379. package/dist/utils/compile-cache-deferral.js +8 -13
  380. package/dist/utils/compile-cache-deferral.js.map +1 -1
  381. package/dist/utils/compile-cache-warmup-host.js +3 -4
  382. package/dist/utils/compile-cache-warmup-host.js.map +1 -1
  383. package/dist/utils/compile-cache.js +12 -100
  384. package/dist/utils/compile-cache.js.map +1 -1
  385. package/dist/utils/startup-database-spare.code.js +3 -3
  386. package/dist/utils/startup-database-spare.impl.js +3 -3
  387. package/dist/utils/startup-database-spare.js +3 -3
  388. package/dist/utils/tools-manager.code.js +1 -1
  389. package/dist/utils/tools-manager.impl.js +3 -3
  390. package/dist/utils/tools-manager.js +3 -3
  391. package/dist/utils/worker-threads.js +2 -15
  392. package/dist/utils/worker-threads.js.map +1 -1
  393. package/docs/build.md +3 -3
  394. package/docs/changelog.mdx +1421 -69
  395. package/docs/compaction/reference.md +5 -5
  396. package/docs/compaction.md +7 -9
  397. package/docs/containerization.md +2 -2
  398. package/docs/custom-provider/api-reference.md +1 -1
  399. package/docs/docs.json +37 -10
  400. package/docs/environment-variables.md +0 -2
  401. package/docs/extensions/api-reference.md +4 -4
  402. package/docs/getting-started/installation.md +3 -0
  403. package/docs/guides/configuration.md +1 -1
  404. package/docs/guides/non-interactive.md +1 -1
  405. package/docs/guides/resume-on-any-machine.md +14 -22
  406. package/docs/guides/team-setup.md +56 -83
  407. package/docs/guides.md +2 -4
  408. package/docs/herdr.md +1 -1
  409. package/docs/index.md +1 -1
  410. package/docs/intercom/operations.md +26 -21
  411. package/docs/intercom/reference.md +2 -2
  412. package/docs/intercom.md +1 -1
  413. package/docs/libraries/storage-postgres.md +9 -9
  414. package/docs/libraries.md +2 -3
  415. package/docs/models-configuration.md +2 -2
  416. package/docs/models.md +2 -3
  417. package/docs/packages/authoring.md +7 -7
  418. package/docs/packages.md +1 -1
  419. package/docs/programmatic.md +2 -2
  420. package/docs/quickstart.md +1 -1
  421. package/docs/reference/cli.md +6 -11
  422. package/docs/reference.md +2 -2
  423. package/docs/rpc/extension-ui.md +2 -2
  424. package/docs/sdk/reference.md +5 -4
  425. package/docs/sdk/storage.md +8 -92
  426. package/docs/sdk/structured-decisions.md +1 -1
  427. package/docs/sdk/web-server.md +3 -3
  428. package/docs/sdk.md +14 -4
  429. package/docs/security.md +1 -1
  430. package/docs/session-format.md +5 -5
  431. package/docs/sessions.md +31 -42
  432. package/docs/settings.md +7 -8
  433. package/docs/storage/custom-adapters.md +255 -0
  434. package/docs/storage/jsonl.md +117 -0
  435. package/docs/{guides/postgres-pgbouncer.md → storage/postgres/pgbouncer.md} +73 -68
  436. package/docs/storage/postgres/tuning.md +337 -0
  437. package/docs/storage/postgres.md +556 -0
  438. package/docs/storage/sqlite.md +99 -0
  439. package/docs/storage.md +333 -956
  440. package/docs/subagents/authoring.md +1 -1
  441. package/docs/subagents.md +2 -2
  442. package/docs/tools.md +1 -1
  443. package/docs/worktree-snapshots.md +2 -2
  444. package/package.json +9 -9
  445. package/schemas/models.schema.json +2 -2
  446. package/schemas/settings.schema.json +0 -14
  447. package/dist/_shared/sdk-AVFII7NK.js.map +0 -1
  448. package/dist/_shared/settings-startup-4QCVCI53.js.map +0 -1
  449. package/dist/_shared/startup-0-0-57KF6LZH.js.map +0 -1
  450. package/dist/_shared/startup-0-1-GIY75K46.js.map +0 -1
  451. package/dist/_shared/startup-0-2-27OWFHV6.js.map +0 -1
  452. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +0 -1
  453. package/dist/_shared/startup-8-1-X32CYSXB.js.map +0 -1
  454. package/dist/core/intercom-broker-control.d.ts +0 -129
  455. package/dist/startup-stages/13.js +0 -1
  456. package/docs/guides/postgres-tuning.md +0 -311
  457. package/docs/libraries/storage-libsql.md +0 -97
@@ -1,9 +1,16 @@
1
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;
2
9
  const TABLE_KINDS = new Set(["r", "p", "v", "m", "f"]);
3
10
  /**
4
- * Every relation, trigger and column of the schema the statement runs in, in one statement and so one snapshot. The
5
- * catalog, not information_schema, finds relations, as `tableExists` does; columns come from information_schema, as
6
- * `columnExists` reads them.
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.
7
14
  */
8
15
  const CATALOG_SQL = `SELECT 'relation' AS kind, c.relname::text AS name, c.relkind::text AS detail
9
16
  FROM pg_catalog.pg_class c WHERE c.relnamespace = current_schema()::regnamespace
@@ -11,15 +18,72 @@ UNION ALL SELECT 'trigger', t.tgname::text, NULL
11
18
  FROM pg_catalog.pg_trigger t JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid
12
19
  WHERE c.relnamespace = current_schema()::regnamespace AND NOT t.tgisinternal
13
20
  UNION ALL SELECT 'column', table_name::text, column_name::text
14
- FROM information_schema.columns WHERE table_schema = current_schema()`;
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`;
15
24
  /**
16
- * Every object of a SQLite or libSQL database and every column of its tables, generated ones included, in one
25
+ * Every object of a SQLite database and every column of its tables, generated ones included, in one
17
26
  * statement and so one snapshot: what `tableExists`, `columnExists` and `schemaObjects` ask one at a time (#6560).
18
27
  */
19
28
  const SQLITE_CATALOG_SQL = `SELECT 'object' AS kind, name, type AS detail FROM sqlite_master
20
29
  UNION ALL SELECT 'column', m.name, c.name FROM sqlite_master AS m JOIN pragma_table_xinfo(m.name) AS c
21
30
  WHERE m.type = 'table'`;
22
- /** The catalog of a SQLite or libSQL database, or undefined when it cannot be read, such as on a SQLite too old. */
31
+ /**
32
+ * @internal The table under `ledger`'s prefix where SQLite 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 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 database, or undefined when it cannot be read, such as on a SQLite too old. */
23
87
  async function readSqliteCatalog(database, ledger) {
24
88
  let rows;
25
89
  try {
@@ -38,7 +102,7 @@ async function readSqliteCatalog(database, ledger) {
38
102
  }
39
103
  return {
40
104
  ledger,
41
- // SQLite records no versions: its stores set their schemas up as before, checked against what exists.
105
+ // SQLite records no versions: its stores' stamps are read on their own (`sqliteSchemaStampsOf`).
42
106
  recordedVersion: () => 0,
43
107
  hasTable: (table) => types.get(table) === "table",
44
108
  hasObject: (name) => types.has(name),
@@ -46,46 +110,90 @@ async function readSqliteCatalog(database, ledger) {
46
110
  sqliteObjectType: (name) => types.get(name),
47
111
  };
48
112
  }
49
- /**
50
- * Reads `database`'s schema and the versions `ledger` records, in two statements sent at once, without a transaction
51
- * or a lock. On SQLite and libSQL, which record no versions, reads the schema alone in one statement. Undefined when a
52
- * read fails: the stores then check each object themselves.
53
- */
54
- export async function readStorageSchemaCatalog(database, ledger) {
55
- const dialect = dialectOf(database);
56
- if (dialect.name === "sqlite")
57
- return readSqliteCatalog(database, ledger);
58
- if (!dialect.versionedMigrations || dialect.name !== "postgres")
59
- return undefined;
60
- const physicalLedger = dialect.identifier(ledger);
61
- const versions = database
62
- .all(`SELECT domain, MAX(version) AS version FROM ${ledger} GROUP BY domain`)
63
- .then((rows) => rows, () => undefined);
64
- let rows;
65
- try {
66
- rows = await database.all(CATALOG_SQL);
67
- }
68
- catch {
69
- return undefined;
70
- }
113
+ /** The tables, objects, columns and executable functions of PostgreSQL catalog rows (`CATALOG_SQL`'s). */
114
+ function catalogSets(rows) {
71
115
  const tables = new Set();
72
116
  const objects = new Set();
73
117
  const columns = new Set();
118
+ const functions = new Set();
74
119
  for (const row of rows) {
75
120
  if (row.kind === "column")
76
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
+ }
77
126
  else {
78
127
  objects.add(row.name);
79
128
  if (row.kind === "relation" && TABLE_KINDS.has(String(row.detail)))
80
129
  tables.add(row.name);
81
130
  }
82
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, 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);
83
192
  const recorded = new Map();
84
193
  if (tables.has(physicalLedger)) {
85
- const read = await versions;
86
- if (read === undefined)
194
+ if (read.versions === undefined)
87
195
  return undefined;
88
- for (const row of read)
196
+ for (const row of read.versions)
89
197
  recorded.set(row.domain, Number(row.version ?? 0));
90
198
  }
91
199
  return {
@@ -94,6 +202,7 @@ export async function readStorageSchemaCatalog(database, ledger) {
94
202
  hasTable: (table) => tables.has(dialect.identifier(table)),
95
203
  hasObject: (name) => objects.has(dialect.identifier(name)),
96
204
  hasColumn: (table, column) => columns.has(`${dialect.identifier(table)}\0${column}`),
205
+ hasFunction: (name) => functions.has(dialect.identifier(name)),
97
206
  };
98
207
  }
99
208
  const scopes = new WeakMap();
@@ -107,7 +216,8 @@ export async function withStorageSchemaCatalog(database, ledger, body, views = [
107
216
  let scope = scopes.get(database);
108
217
  if (scope === undefined || scope.ledger !== ledger) {
109
218
  const read = () => readStorageSchemaCatalog(database, ledger);
110
- scope = { ledger, catalog: dialectOf(database).name === "sqlite" ? undefined : read(), read, users: 0 };
219
+ const catalog = dialectOf(database).name === "sqlite" ? undefined : read();
220
+ scope = { ledger, catalog, read, users: 0, stamps: undefined, restamp: new Map() };
111
221
  scopes.set(database, scope);
112
222
  }
113
223
  const shared = scope;
@@ -116,7 +226,10 @@ export async function withStorageSchemaCatalog(database, ledger, body, views = [
116
226
  scopes.set(handle, shared);
117
227
  shared.users += 1;
118
228
  try {
119
- return await body();
229
+ const value = await body();
230
+ if (shared.users === 1 && shared.restamp.size > 0)
231
+ await restamp(database, shared);
232
+ return value;
120
233
  }
121
234
  finally {
122
235
  shared.users -= 1;
@@ -127,6 +240,31 @@ export async function withStorageSchemaCatalog(database, ledger, body, views = [
127
240
  scopes.delete(database);
128
241
  }
129
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
+ }
130
268
  /**
131
269
  * The catalog an open of `database` in progress read ({@link withStorageSchemaCatalog}), when it read `ledger`'s
132
270
  * versions or no `ledger` is named; undefined outside such an open, and when it could not be read.
@@ -138,4 +276,76 @@ export async function schemaCatalogOf(database, ledger) {
138
276
  scope.catalog ??= scope.read();
139
277
  return scope.catalog;
140
278
  }
279
+ /**
280
+ * @internal The revisions the stamps under `ledger` record for the stores of `database` (SQLite), 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
+ // driver may 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 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
+ }
141
351
  //# sourceMappingURL=schema-catalog.js.map
@@ -1 +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;AAyBzC,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;;;;;;uEAMmD,CAAC;AAIxE;;;GAGG;AACH,MAAM,kBAAkB,GAAG;;wBAEH,CAAC;AAEzB,oHAAoH;AACpH,KAAK,UAAU,iBAAiB,CAAC,QAAwB,EAAE,MAAc;IACxE,IAAI,IAAkB,CAAC;IACvB,IAAI,CAAC;QACJ,IAAI,GAAG,MAAM,QAAQ,CAAC,GAAG,CAAa,kBAAkB,CAAC,CAAC;IAC3D,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,SAAS,CAAC;IAClB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;IACxC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAClC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACxB,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;;YAChE,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;IAC9C,CAAC;IACD,OAAO;QACN,MAAM;QACN,sGAAsG;QACtG,eAAe,EAAE,GAAG,EAAE,CAAC,CAAC;QACxB,QAAQ,EAAE,CAAC,KAAK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,OAAO,MAAM,IAAI,EAAE,CAAC;IACrB,CAAC;YAAS,CAAC;QACV,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;QAClB,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;YAAE,IAAI,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,MAAM;gBAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QAChG,IAAI,MAAM,CAAC,KAAK,KAAK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,MAAM;YAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACpF,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACpC,QAAwB,EACxB,MAAe;IAEf,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACnC,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,MAAM,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC;QAAE,OAAO,SAAS,CAAC;IAC/F,KAAK,CAAC,OAAO,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;IAC/B,OAAO,KAAK,CAAC,OAAO,CAAC;AACtB,CAAC","sourcesContent":["import type { SqliteDatabase, SqliteRow } from \"./database.js\";\nimport { dialectOf } from \"./dialect.js\";\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 * 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 and column of the schema the statement runs in, in one statement and so one snapshot. The\n * catalog, not information_schema, finds relations, as `tableExists` does; columns come from information_schema, as\n * `columnExists` reads them.\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()`;\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/** 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: SqliteDatabase, 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 set their schemas up as before, checked against what exists.\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\n/**\n * Reads `database`'s schema and the versions `ledger` records, in two statements sent at once, without a transaction\n * or a lock. On SQLite and libSQL, which record no versions, reads the schema alone in one statement. Undefined when a\n * 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 versions = database\n\t\t.all<SqliteRow & { domain: string; version: number | string | null }>(\n\t\t\t`SELECT domain, MAX(version) AS version FROM ${ledger} GROUP BY domain`,\n\t\t)\n\t\t.then(\n\t\t\t(rows) => rows,\n\t\t\t() => undefined,\n\t\t);\n\tlet rows: CatalogRow[];\n\ttry {\n\t\trows = await database.all<CatalogRow>(CATALOG_SQL);\n\t} catch {\n\t\treturn undefined;\n\t}\n\tconst tables = new Set<string>();\n\tconst objects = new Set<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 {\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\tconst recorded = new Map<string, number>();\n\tif (tables.has(physicalLedger)) {\n\t\tconst read = await versions;\n\t\tif (read === undefined) return undefined;\n\t\tfor (const row of read) 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};\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}\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\tscope = { ledger, catalog: dialectOf(database).name === \"sqlite\" ? undefined : read(), read, users: 0 };\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\treturn await body();\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 * 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"]}
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;AA6BpG,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,MAAM,EAAE,CAAC;AAIxD;;;GAGG;AACH,KAAK,UAAU,sBAA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G,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 */\n\treadonly hasFunction?: (name: string) => boolean;\n\t/**\n\t * What kind of object `name` was on SQLite (`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 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 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 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 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, 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), 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// driver may 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 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"]}
@@ -2,7 +2,7 @@ import type { SqliteDatabase } from "./database.js";
2
2
  import { TeamProfileConfigError } from "./errors.js";
3
3
  import type { StorageSteps } from "./file-identity.js";
4
4
  import type { AdapterOptions, SecretRef, StorageSelection } from "./provider.js";
5
- import type { JoinTeamOptions, LeaveTeamOptions, TeamJoinResult, TeamLeaveResult, TeamProfile, TeamProfileOptions } from "./team.js";
5
+ import type { TeamProfile, TeamProfileOptions } from "./team.js";
6
6
  /** A secret held only in this process's memory: it is never written to settings, environments or files. */
7
7
  export interface InMemorySecretRef {
8
8
  readonly value: string;
@@ -29,51 +29,13 @@ export type StorageInputSelection = StorageSettingsSelection | {
29
29
  export declare function selectStorage(value: StorageInputSelection, source: "sdk" | "settings" | "env" | "cli", field: string, defaultPath: string | (() => string)): StorageSelection;
30
30
  export declare function selectStorageAsync(value: StorageInputSelection, source: "sdk" | "settings" | "env" | "cli", field: string, defaultPath: () => Promise<string>): Promise<StorageSelection>;
31
31
  export declare function selectStorageSteps(value: StorageInputSelection, source: "sdk" | "settings" | "env" | "cli", field: string, defaultPath: string | (() => StorageSteps<string>)): StorageSteps<StorageSelection>;
32
- /** The first-party libSQL / Turso adapter package that team setup and `atomic storage join` select. */
33
- export declare const LIBSQL_ADAPTER_PACKAGE = "@bastani/atomic-storage-libsql";
34
- /** Filename prefix for private token files created by `atomic storage join` and `atomic team join` in the agent directory. */
32
+ /** A token file `atomic storage join` created in the agent directory has this filename prefix. */
35
33
  export declare const STORAGE_TOKEN_FILE = "storage-token";
36
- /** The `sessions.storage` value `team join` writes: the local default store, named explicitly. */
34
+ /** The `sessions.storage` value that pins sessions to the local default store, named explicitly. */
37
35
  export declare const LOCAL_SESSIONS_STORAGE: {
38
36
  readonly path: "workflows/journal.sqlite";
39
37
  };
40
- export declare const TEAM_PROFILE_ENV = "ATOMIC_PROFILE";
41
- export declare const TEAM_URL_ENV = "ATOMIC_TEAM_URL";
42
- export declare const TEAM_TOKEN_ENV = "ATOMIC_TEAM_TOKEN";
43
- export declare const TEAM_TOKEN_FILE_ENV = "ATOMIC_TEAM_TOKEN_FILE";
44
- export declare const TEAM_PREFIX_ENV = "ATOMIC_TEAM_PREFIX";
45
- /** The variables `ATOMIC_PROFILE=ci` reads; setting any of them without the profile is an error. */
46
- export declare const TEAM_VARIABLES: readonly string[];
47
- /** A team database selection in the settings form: usable as `createAgentSession({ storage })`. */
48
- export interface TeamStorageSelection {
49
- readonly adapter: string;
50
- readonly options: Readonly<Record<string, string>>;
51
- readonly secrets?: Readonly<Record<string, SecretRef>>;
52
- readonly prefix?: string;
53
- }
54
- export interface TeamProfileSelectionOptions {
55
- readonly profile: "ci";
56
- /** `libsql://`, `https://`, `wss://` or absolute `file:` URL, without a credential. */
57
- readonly url: string;
58
- /** The database token, held as an in-memory `{ value }` secret that is never serialized or written. */
59
- readonly token?: string;
60
- /** A file holding the database token; relative paths resolve against the working directory. */
61
- readonly tokenFile?: string;
62
- /** An environment variable holding the database token, read when the store opens. */
63
- readonly tokenEnv?: string;
64
- readonly prefix?: string;
65
- }
66
38
  export type TeamInputSource = "sdk" | "cli" | "env";
67
- /** Whether a team database URL needs no token: a local `file:` database. */
68
- export declare function isFileUrl(url: string): boolean;
69
- /**
70
- * Check a team database URL: a supported scheme, an absolute `file:` URL, and no credential in it. `postgres` only
71
- * changes the unsupported-URL hint, for the commands that also take a `postgres://` URL through
72
- * {@link checkSharedDatabaseArguments}.
73
- */
74
- export declare function checkTeamUrl(url: string | undefined, source: TeamInputSource, options?: {
75
- readonly postgres?: boolean;
76
- }): string;
77
39
  /** The first-party PostgreSQL adapter package that `atomic storage join postgres://…` and `--db postgres://…` select. */
78
40
  export declare const POSTGRES_ADAPTER_PACKAGE = "@bastani/atomic-storage-postgres";
79
41
  /** The platform credential a Postgres selection's `auth` option names, instead of a password. */
@@ -85,7 +47,7 @@ export declare function isPostgresUrl(url: string): boolean;
85
47
  /** The shared database a command line names: its URL and where its credential comes from. */
86
48
  export interface SharedDatabaseArguments {
87
49
  readonly url: string;
88
- /** libSQL: the token file. Postgres: a password file another process keeps fresh, referenced in place. */
50
+ /** A password or token file another process keeps fresh, referenced in place. */
89
51
  readonly tokenFile?: string;
90
52
  /** Postgres only: a password file. */
91
53
  readonly passwordFile?: string;
@@ -100,9 +62,9 @@ export interface CheckedSharedDatabase {
100
62
  readonly auth?: PostgresAuth;
101
63
  }
102
64
  /**
103
- * Check the database URL and credential flags of `atomic storage join` and `--db`. A `postgres://` or
104
- * `postgresql://` URL takes exactly one of `--password-file`, `--token-file` and `--auth`; any other URL is a libSQL
105
- * one, checked by {@link checkTeamUrl}, and takes only `--token-file`, which the caller requires or not.
65
+ * Check the database URL and credential flags of `atomic storage join` and `--db`: a `postgres://` or
66
+ * `postgresql://` URL that takes exactly one of `--password-file`, `--token-file` and `--auth`. A URL of the removed
67
+ * libSQL adapter is refused with how to move off it.
106
68
  */
107
69
  export declare function checkSharedDatabaseArguments(input: SharedDatabaseArguments): CheckedSharedDatabase;
108
70
  /** Check a table prefix with the same rules as every storage prefix. */
@@ -112,45 +74,8 @@ export declare function checkTeamPrefix(prefix: string | undefined, source: Team
112
74
  * a file a selection references is read for every connection; an unreadable or empty file is an invalid input.
113
75
  */
114
76
  export declare function readTeamTokenFile(path: string, source: TeamInputSource, field?: string, read?: "trimmed" | "as-connections-read"): string;
115
- export declare function readTeamTokenFileAsync(path: string, source: TeamInputSource, field?: string, read?: "trimmed" | "as-connections-read"): Promise<string>;
116
- /** A missing token for a URL that needs one. */
117
- export declare function missingTeamToken(url: string, source: Exclude<TeamInputSource, "env">): TeamProfileConfigError;
118
77
  /** More than one token source. */
119
78
  export declare function conflictingTeamToken(source: TeamInputSource, fields: readonly string[]): TeamProfileConfigError;
120
- /** A whitespace-only literal token, or an empty variable name. */
121
- export declare function emptyTeamToken(source: TeamInputSource, field?: string): TeamProfileConfigError;
122
- /**
123
- * The CI profile as a team database selection, without reading or writing settings: sessions and Intercom can both
124
- * use it. A literal `token` becomes an in-memory `{ value }` secret that serializes as
125
- * `[redacted]` and that only SDK callers can pass; `tokenFile` (absolute path) and `tokenEnv` are references read
126
- * when the store opens. Inputs are checked first; nothing else happens.
127
- */
128
- export declare function teamProfileSelection(options: TeamProfileSelectionOptions): TeamStorageSelection;
129
- /**
130
- * The selection `ATOMIC_PROFILE=ci` makes from `ATOMIC_TEAM_URL` and `ATOMIC_TEAM_TOKEN` or `ATOMIC_TEAM_TOKEN_FILE`
131
- * (plus an optional `ATOMIC_TEAM_PREFIX`), or `undefined` without a profile. The token is referenced, never copied:
132
- * `{ env: "ATOMIC_TEAM_TOKEN" }` or the token file's absolute path, so the selection can be handed to child processes.
133
- * Invalid input throws {@link TeamProfileConfigError} with `source: "env"`: a team variable without the profile, or
134
- * the profile without its URL or token, is `incomplete-profile` naming every missing variable at once.
135
- */
136
- export declare function environmentTeamProfile(env?: NodeJS.ProcessEnv): TeamStorageSelection | undefined;
137
- export declare function environmentTeamProfileSelection(env?: NodeJS.ProcessEnv): TeamStorageSelection | undefined;
138
- export declare function environmentTeamProfileAsync(env?: NodeJS.ProcessEnv): Promise<TeamStorageSelection | undefined>;
139
- /**
140
- * Use a team database for Intercom while sessions stay private: checks every input and the
141
- * connection first, then sets the global `storage` setting to the team database and `sessions.storage` to the local
142
- * default store in one settings write, and restarts the Intercom broker so it routes through the team database.
143
- * Rejects with `TeamProfileConfigError` for an invalid input and `TeamProfileError` otherwise; on any rejection
144
- * nothing was changed. A failed broker restart is reported in `broker`, not thrown.
145
- */
146
- export declare function joinTeam(options: JoinTeamOptions): Promise<TeamJoinResult>;
147
- /**
148
- * Restore the individual layout: remove the global `storage` setting and the `sessions.storage` pin when they hold
149
- * exactly what `joinTeam` writes, leave every other value in place, delete the removed selection's token file unless
150
- * another setting references it, and restart the Intercom broker when `storage` was removed. Running it again
151
- * changes nothing.
152
- */
153
- export declare function leaveTeam(options?: LeaveTeamOptions): Promise<TeamLeaveResult>;
154
79
  /**
155
80
  * The layout in effect for this process and working directory (`individual`, `team`, `ci` or `custom`), from the
156
81
  * storage each domain selects. Reads only; an invalid selection rejects with its `StorageConfigError`.