@bastani/atomic 0.10.9-alpha.1 → 0.10.10-alpha.1

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 (401) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/README.md +211 -155
  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 +27 -12
  7. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
  8. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +47 -7
  9. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
  10. package/dist/_shared/mode-shared-2QJSCUM6.js +48 -19
  11. package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
  12. package/dist/_shared/{p1a-prewarm-UQY3X2UK.js → p1a-prewarm-XIU57JHF.js} +5 -5
  13. package/dist/_shared/{p1a-prewarm-UQY3X2UK.js.map → p1a-prewarm-XIU57JHF.js.map} +1 -1
  14. package/dist/_shared/p2-shell-main-B2WIALFD.js +30 -25
  15. package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
  16. package/dist/_shared/runtime-O4KCSG4C.js +5 -5
  17. package/dist/_shared/{sdk-OSBEPR3Q.js → sdk-RRLVN7ER.js} +15 -9
  18. package/dist/_shared/sdk-RRLVN7ER.js.map +1 -0
  19. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  20. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  21. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +4 -1
  22. package/dist/_shared/settings-startup-8-DNZ2RIHM.js.map +1 -1
  23. package/dist/_shared/{startup-0-0-TYUFUOJZ.js → startup-0-0-4VG2G44V.js} +427 -33
  24. package/dist/_shared/startup-0-0-4VG2G44V.js.map +1 -0
  25. package/dist/_shared/{startup-0-1-W2G2UY7R.js → startup-0-1-XTIL65D4.js} +18 -11
  26. package/dist/_shared/startup-0-1-XTIL65D4.js.map +1 -0
  27. package/dist/_shared/{startup-0-2-UXBUEOXW.js → startup-0-2-27OWFHV6.js} +145 -58
  28. package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -0
  29. package/dist/_shared/startup-0-3-T4DVFYWX.js +15 -25
  30. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +1 -1
  31. package/dist/_shared/{startup-0-4-HN5EB4K7.js → startup-0-4-ZMJV547D.js} +81 -12
  32. package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -0
  33. package/dist/_shared/startup-0-5-FD2P735I.js +90 -50
  34. package/dist/_shared/startup-0-5-FD2P735I.js.map +1 -1
  35. package/dist/_shared/startup-10-0-TDQNBDDL.js +5 -5
  36. package/dist/_shared/startup-12-0-55AAXBJZ.js +13 -7
  37. package/dist/_shared/startup-12-0-55AAXBJZ.js.map +1 -1
  38. package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
  39. package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
  40. package/dist/_shared/startup-15-1-4S7FLMNG.js +88 -28
  41. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  42. package/dist/_shared/startup-8-0-34CBHPZH.js +5 -5
  43. package/dist/_shared/startup-8-1-4KANEHRA.js +61 -17
  44. package/dist/_shared/startup-8-1-4KANEHRA.js.map +1 -1
  45. package/dist/_shared/storage-command-7MGXLJGZ.js +4 -4
  46. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  47. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  48. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  49. package/dist/builtin/intercom/README.md +85 -114
  50. package/dist/builtin/intercom/broker/broker.bundle.mjs +3 -3
  51. package/dist/builtin/intercom/broker/presence-handler.ts +1 -1
  52. package/dist/builtin/intercom/group.ts +7 -3
  53. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  54. package/dist/builtin/intercom/package.json +1 -1
  55. package/dist/builtin/mcp/README.md +37 -27
  56. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  57. package/dist/builtin/mcp/package.json +1 -1
  58. package/dist/builtin/subagents/CHANGELOG.md +8 -0
  59. package/dist/builtin/subagents/README.md +71 -138
  60. package/dist/builtin/subagents/package.json +1 -1
  61. package/dist/builtin/subagents/src/extension/index.bundle.mjs +213 -74
  62. package/dist/builtin/web-access/CHANGELOG.md +9 -0
  63. package/dist/builtin/web-access/README.md +60 -87
  64. package/dist/builtin/web-access/index.bundle.mjs +387 -351
  65. package/dist/builtin/web-access/package.json +1 -1
  66. package/dist/cli/args.js +2 -2
  67. package/dist/cli/auth-cli.code.js +4 -4
  68. package/dist/cli/auth-cli.impl.js +3 -3
  69. package/dist/cli/auth-cli.js +3 -3
  70. package/dist/cli/blueprint-command.code.js +2 -2
  71. package/dist/cli/blueprint-command.impl.js +3 -3
  72. package/dist/cli/blueprint-command.js +3 -3
  73. package/dist/cli/intercom-command.code.js +3 -3
  74. package/dist/cli/intercom-command.impl.js +3 -3
  75. package/dist/cli/intercom-command.js +3 -3
  76. package/dist/cli/list-models.code.js +3 -3
  77. package/dist/cli/list-models.impl.js +3 -3
  78. package/dist/cli/list-models.js +3 -3
  79. package/dist/cli/session-picker.code.js +2 -2
  80. package/dist/cli/session-picker.impl.js +3 -3
  81. package/dist/cli/session-picker.js +3 -3
  82. package/dist/cli/startup-ui.code.js +2 -2
  83. package/dist/cli/startup-ui.impl.js +3 -3
  84. package/dist/cli/startup-ui.js +3 -3
  85. package/dist/cli/storage-command.impl.js +3 -3
  86. package/dist/cli/storage-command.js +3 -3
  87. package/dist/cli/storage-search-session.code.js +2 -2
  88. package/dist/cli/storage-search-session.impl.js +3 -3
  89. package/dist/cli/storage-search-session.js +3 -3
  90. package/dist/cli/team-command.code.js +2 -2
  91. package/dist/cli/team-command.impl.js +3 -3
  92. package/dist/cli/team-command.js +3 -3
  93. package/dist/cli.js +2 -2
  94. package/dist/core/agent-session-methods.d.ts +4 -1
  95. package/dist/core/agent-session-methods.js.map +1 -1
  96. package/dist/core/agent-session.d.ts +3 -0
  97. package/dist/core/compaction/compactor.d.ts +20 -14
  98. package/dist/core/compaction/errors.d.ts +120 -0
  99. package/dist/core/compaction/index.d.ts +1 -0
  100. package/dist/core/compaction/model-resolver.d.ts +2 -2
  101. package/dist/core/debug.impl.js +3 -3
  102. package/dist/core/debug.js +3 -3
  103. package/dist/core/export-html/card-projection.impl.js +3 -3
  104. package/dist/core/export-html/card-projection.js +3 -3
  105. package/dist/core/export-html/index.code.js +2 -2
  106. package/dist/core/export-html/index.impl.js +3 -3
  107. package/dist/core/export-html/index.js +3 -3
  108. package/dist/core/export-html/json-spans.impl.js +3 -3
  109. package/dist/core/export-html/json-spans.js +3 -3
  110. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  111. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  112. package/dist/core/export-html/tool-renderer.code.js +1 -1
  113. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  114. package/dist/core/export-html/tool-renderer.js +3 -3
  115. package/dist/core/extensions/api-types.d.ts +1 -1
  116. package/dist/core/extensions/api-types.js.map +1 -1
  117. package/dist/core/extensions/index.d.ts +1 -1
  118. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  119. package/dist/core/extensions/jiti-loader.js +3 -3
  120. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  121. package/dist/core/extensions/jiti-static-loader.js +3 -3
  122. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  123. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  124. package/dist/core/extensions/loader-host-modules.js +3 -3
  125. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  126. package/dist/core/extensions/provider-types.d.ts +18 -6
  127. package/dist/core/extensions/provider-types.js.map +1 -1
  128. package/dist/core/extensions/runner-context.js +1 -1
  129. package/dist/core/intercom-broker-control-host.code.js +1 -1
  130. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  131. package/dist/core/intercom-broker-control-host.js +3 -3
  132. package/dist/core/intercom-broker-control.code.js +3 -3
  133. package/dist/core/intercom-broker-control.impl.js +3 -3
  134. package/dist/core/intercom-broker-control.js +3 -3
  135. package/dist/core/model-config.d.ts +40 -0
  136. package/dist/core/model-registry.js +1 -1
  137. package/dist/core/model-resolver-scope.d.ts +4 -4
  138. package/dist/core/model-runtime.d.ts +1 -1
  139. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  140. package/dist/core/package-manager-storage-adapters.js +3 -3
  141. package/dist/core/provider-composer-internal.d.ts +11 -2
  142. package/dist/core/sdk.code.js +3 -3
  143. package/dist/core/sdk.impl.js +3 -3
  144. package/dist/core/sdk.js +3 -3
  145. package/dist/core/session-manager-core.js +5 -5
  146. package/dist/core/session-manager-list.impl.js +3 -3
  147. package/dist/core/session-manager-list.js +3 -3
  148. package/dist/core/session-manager.code.js +1 -1
  149. package/dist/core/session-manager.impl.js +3 -3
  150. package/dist/core/session-manager.js +3 -3
  151. package/dist/core/session-storage.impl.js +3 -3
  152. package/dist/core/session-storage.js +3 -3
  153. package/dist/core/settings-manager-basic-accessors.d.ts +6 -2
  154. package/dist/core/storage/index.js +2 -2
  155. package/dist/core/storage/node-sqlite-thread.js +2 -2
  156. package/dist/core/storage/node-sqlite.js +2 -2
  157. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  158. package/dist/core/storage/offline-snapshot-file.js +3 -3
  159. package/dist/core/storage/provider.js +2 -2
  160. package/dist/core/storage/selection.js +2 -2
  161. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  162. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  163. package/dist/core/storage/session/branch-fork-source.js +3 -3
  164. package/dist/core/storage/session/card-view.impl.js +3 -3
  165. package/dist/core/storage/session/card-view.js +3 -3
  166. package/dist/core/storage/session/child-reader.code.js +3 -3
  167. package/dist/core/storage/session/child-reader.impl.js +3 -3
  168. package/dist/core/storage/session/child-reader.js +3 -3
  169. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  170. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  171. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  172. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  173. package/dist/core/storage/session/expanded-child-details.js +3 -3
  174. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  175. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  176. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  177. package/dist/core/storage/session/fork-row-index.js +3 -3
  178. package/dist/core/storage/session/fork-staging.code.js +2 -2
  179. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  180. package/dist/core/storage/session/fork-staging.js +3 -3
  181. package/dist/core/storage/session/fork-window.code.js +3 -3
  182. package/dist/core/storage/session/fork-window.impl.js +3 -3
  183. package/dist/core/storage/session/fork-window.js +3 -3
  184. package/dist/core/storage/session/history-pages.impl.js +3 -3
  185. package/dist/core/storage/session/history-pages.js +3 -3
  186. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  187. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  188. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  189. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  190. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  191. package/dist/core/storage/session/memory-session-store.js +3 -3
  192. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  193. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  194. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  195. package/dist/core/storage/session/released-history-files.code.js +3 -3
  196. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  197. package/dist/core/storage/session/released-history-files.js +3 -3
  198. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  199. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  200. package/dist/core/storage/session/session-resume.impl.js +3 -3
  201. package/dist/core/storage/session/session-resume.js +3 -3
  202. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  203. package/dist/core/storage/session/snapshot-cut.js +3 -3
  204. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  205. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  206. package/dist/core/storage/session/snapshot-history.js +3 -3
  207. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  208. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  209. package/dist/core/storage/session/sql-session-store.js +3 -3
  210. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  211. package/dist/core/storage/session/tree-outline.js +3 -3
  212. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  213. package/dist/core/storage/session/tree-presentation.js +3 -3
  214. package/dist/core/storage/storage-status.impl.js +3 -3
  215. package/dist/core/storage/storage-status.js +3 -3
  216. package/dist/core/storage/team.impl.js +3 -3
  217. package/dist/core/storage/team.js +3 -3
  218. package/dist/core/structured-output/index.code.js +1 -1
  219. package/dist/core/structured-output/index.impl.js +3 -3
  220. package/dist/core/structured-output/index.js +3 -3
  221. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  222. package/dist/core/tasks/task-completion-entry.js +3 -3
  223. package/dist/core/tasks/task-file-history.code.js +3 -3
  224. package/dist/core/tasks/task-file-history.impl.js +3 -3
  225. package/dist/core/tasks/task-file-history.js +3 -3
  226. package/dist/core/tasks/task-reference-archive.code.js +4 -4
  227. package/dist/core/tasks/task-reference-archive.js +3 -3
  228. package/dist/core/tasks/task-reference-identity.code.js +1 -1
  229. package/dist/core/tasks/task-reference-identity.js +3 -3
  230. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  231. package/dist/core/tasks/task-reference-stream.js +3 -3
  232. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  233. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  234. package/dist/core/tasks/task-view-source.impl.js +3 -3
  235. package/dist/core/tasks/task-view-source.js +3 -3
  236. package/dist/core/tools/read-url.code.js +2 -2
  237. package/dist/core/tools/read-url.impl.js +3 -3
  238. package/dist/core/tools/read-url.js +3 -3
  239. package/dist/core/worktree-snapshot/blob-store.js +2 -2
  240. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  241. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  242. package/dist/core/worktree-snapshot/errors.js +3 -3
  243. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  244. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  245. package/dist/extensions/codemode/execute.code.js +1 -1
  246. package/dist/extensions/codemode/execute.impl.js +3 -3
  247. package/dist/extensions/codemode/execute.js +3 -3
  248. package/dist/extensions/codemode/renderer.code.js +2 -2
  249. package/dist/extensions/codemode/renderer.impl.js +3 -3
  250. package/dist/extensions/codemode/renderer.js +3 -3
  251. package/dist/extensions/mcp/cli.code.js +2 -2
  252. package/dist/extensions/mcp/cli.impl.js +3 -3
  253. package/dist/extensions/mcp/cli.js +3 -3
  254. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  255. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  256. package/dist/extensions/mcp/cli.lazy.js +3 -3
  257. package/dist/extensions/mcp/runtime.code.js +1 -1
  258. package/dist/extensions/mcp/runtime.impl.js +3 -3
  259. package/dist/extensions/mcp/runtime.js +3 -3
  260. package/dist/index-extensions.d.ts +1 -1
  261. package/dist/index.d.ts +8 -1
  262. package/dist/index.js +7 -7
  263. package/dist/main-first-time-setup.code.js +2 -2
  264. package/dist/main-first-time-setup.impl.js +3 -3
  265. package/dist/main-first-time-setup.js +3 -3
  266. package/dist/modes/interactive/components/settings-selector-types.d.ts +1 -0
  267. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  268. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  269. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  270. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  271. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  272. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  273. package/dist/modes/interactive/theme/color-utils.d.ts +5 -5
  274. package/dist/modes/interactive/theme/theme-loading.d.ts +1 -0
  275. package/dist/modes/interactive-engine/engine-prewarm.js +1 -1
  276. package/dist/modes/interactive-engine/remote-model-catalog.d.ts +1 -0
  277. package/dist/modes/print-mode.js +1 -1
  278. package/dist/modes/rpc/rpc-client-api.d.ts +6 -0
  279. package/dist/modes/rpc/rpc-types.d.ts +29 -2
  280. package/dist/package-manager-cli.code.js +5 -5
  281. package/dist/package-manager-cli.impl.js +3 -3
  282. package/dist/package-manager-cli.js +3 -3
  283. package/dist/rpc-entry.js +1 -1
  284. package/dist/startup-files.json +1 -1
  285. package/dist/startup-stages/5.js +1 -1
  286. package/dist/startup-stages/7.js +1 -1
  287. package/dist/startup-stages/8.js +1 -2
  288. package/dist/startup-stages/9.js +2 -1
  289. package/dist/utils/native-module.d.ts +44 -0
  290. package/dist/utils/startup-database-spare.code.js +3 -3
  291. package/dist/utils/startup-database-spare.impl.js +3 -3
  292. package/dist/utils/startup-database-spare.js +3 -3
  293. package/dist/utils/tools-manager.code.js +1 -1
  294. package/dist/utils/tools-manager.impl.js +3 -3
  295. package/dist/utils/tools-manager.js +3 -3
  296. package/docs/background-tasks.md +235 -243
  297. package/docs/build.md +12 -11
  298. package/docs/codemode.md +60 -51
  299. package/docs/compaction/reference.md +61 -24
  300. package/docs/compaction.md +117 -65
  301. package/docs/computer-use.md +179 -146
  302. package/docs/containerization.md +79 -33
  303. package/docs/custom-provider/api-reference.md +148 -11
  304. package/docs/custom-provider/oauth.md +44 -27
  305. package/docs/custom-provider/override.md +14 -7
  306. package/docs/custom-provider/registration.md +75 -65
  307. package/docs/custom-provider/streaming.md +42 -19
  308. package/docs/custom-provider.md +25 -61
  309. package/docs/development.md +47 -43
  310. package/docs/docs.json +33 -33
  311. package/docs/environment-variables.md +83 -57
  312. package/docs/extensions/api-reference.md +323 -734
  313. package/docs/extensions/authoring.md +186 -269
  314. package/docs/extensions/events.md +308 -375
  315. package/docs/extensions/examples.md +122 -74
  316. package/docs/extensions/ui.md +217 -197
  317. package/docs/extensions.md +152 -259
  318. package/docs/getting-started/authentication.md +27 -14
  319. package/docs/getting-started/first-session.md +25 -26
  320. package/docs/getting-started/installation.md +62 -84
  321. package/docs/getting-started/project-instructions.md +39 -14
  322. package/docs/guides/configuration.md +42 -20
  323. package/docs/guides/intercom.md +17 -13
  324. package/docs/guides/non-interactive.md +29 -16
  325. package/docs/guides/orchestration.md +16 -10
  326. package/docs/guides/resume-on-any-machine.md +54 -49
  327. package/docs/guides/subagents.md +22 -14
  328. package/docs/guides/team-setup.md +37 -26
  329. package/docs/guides.md +22 -21
  330. package/docs/herdr.md +21 -16
  331. package/docs/index.md +16 -17
  332. package/docs/intercom/operations.md +68 -66
  333. package/docs/intercom/reference.md +196 -191
  334. package/docs/intercom.md +103 -92
  335. package/docs/json.md +71 -71
  336. package/docs/keybindings.md +63 -50
  337. package/docs/libraries/agent-core.md +49 -8
  338. package/docs/libraries/ai.md +21 -12
  339. package/docs/libraries/codemode.md +28 -6
  340. package/docs/libraries/schema.md +7 -7
  341. package/docs/libraries/telemetry.md +7 -7
  342. package/docs/libraries/tui.md +74 -94
  343. package/docs/libraries.md +5 -5
  344. package/docs/llama-cpp.md +38 -33
  345. package/docs/mcp-servers.md +96 -90
  346. package/docs/models/reference.md +46 -33
  347. package/docs/models-configuration.md +12 -6
  348. package/docs/models.md +93 -88
  349. package/docs/orchestration/migrating-workflows.md +21 -19
  350. package/docs/orchestration/patterns.md +35 -20
  351. package/docs/orchestration.md +22 -21
  352. package/docs/packages/authoring.md +28 -19
  353. package/docs/packages/reference.md +75 -16
  354. package/docs/packages.md +31 -33
  355. package/docs/programmatic.md +22 -21
  356. package/docs/prompt-templates.md +63 -41
  357. package/docs/providers/reference.md +35 -19
  358. package/docs/providers.md +61 -71
  359. package/docs/quickstart.md +32 -46
  360. package/docs/reference/cli.md +249 -252
  361. package/docs/reference.md +23 -20
  362. package/docs/rpc/examples.md +74 -17
  363. package/docs/rpc/extension-ui.md +79 -62
  364. package/docs/rpc/protocol.md +816 -358
  365. package/docs/rpc.md +75 -151
  366. package/docs/sdk/reference.md +175 -45
  367. package/docs/sdk/structured-decisions.md +92 -62
  368. package/docs/sdk/web-server.md +79 -46
  369. package/docs/sdk.md +237 -195
  370. package/docs/security.md +106 -43
  371. package/docs/session-format.md +96 -59
  372. package/docs/sessions.md +149 -113
  373. package/docs/settings.md +289 -204
  374. package/docs/shell-aliases.md +15 -6
  375. package/docs/skills/authoring.md +17 -9
  376. package/docs/skills/reference.md +23 -21
  377. package/docs/skills.md +104 -97
  378. package/docs/storage.md +140 -242
  379. package/docs/subagents/authoring.md +147 -16
  380. package/docs/subagents/reference.md +100 -30
  381. package/docs/subagents.md +220 -252
  382. package/docs/terminal-setup.md +97 -69
  383. package/docs/termux.md +51 -85
  384. package/docs/themes/reference.md +51 -37
  385. package/docs/themes.md +49 -54
  386. package/docs/tmux.md +38 -21
  387. package/docs/tools.md +198 -147
  388. package/docs/tui/reference.md +64 -32
  389. package/docs/tui.md +38 -66
  390. package/docs/usage.md +76 -78
  391. package/docs/verification.md +25 -25
  392. package/docs/web-access.md +72 -55
  393. package/docs/windows.md +53 -58
  394. package/docs/worktree-snapshots.md +62 -65
  395. package/package.json +8 -8
  396. package/schemas/models.schema.json +51 -0
  397. package/dist/_shared/sdk-OSBEPR3Q.js.map +0 -1
  398. package/dist/_shared/startup-0-0-TYUFUOJZ.js.map +0 -1
  399. package/dist/_shared/startup-0-1-W2G2UY7R.js.map +0 -1
  400. package/dist/_shared/startup-0-2-UXBUEOXW.js.map +0 -1
  401. package/dist/_shared/startup-0-4-HN5EB4K7.js.map +0 -1
package/docs/storage.md CHANGED
@@ -1,16 +1,17 @@
1
1
  ---
2
- title: "Storage"
3
- description: "Configure local SQLite, PostgreSQL, or Turso/libSQL storage for Atomic sessions and Intercom, export and import sessions, and build custom storage adapters."
2
+ title: "Storage backends"
3
+ sidebarTitle: "Storage"
4
+ description: "Configure local SQLite, PostgreSQL, or Turso/libSQL storage, export and import sessions, and build custom storage adapters."
4
5
  ---
5
6
 
6
- # Storage
7
-
8
- Atomic stores sessions in a local SQLite database by default (`~/.atomic/workflows/journal.sqlite`, using `session_` table prefixes). You can switch to another SQLite file, a JSONL directory, an in-memory store, PostgreSQL, Turso/libSQL, or a custom database adapter through [storage settings](/settings#sessions) or [per-process overrides](#selecting-storage-per-process).
7
+ Atomic saves sessions in a local SQLite database (`~/.atomic/workflows/journal.sqlite`) by default. You can switch to another SQLite file, a JSONL directory, an in-memory store, PostgreSQL, Turso/libSQL, or a custom database adapter through [storage settings](/settings#sessions) or [per-process overrides](#selecting-storage-per-process).
9
8
 
10
9
  - A configured persistent store never silently falls back to memory when it fails to open.
11
10
  - A subagent keeps its session in its launching parent's store unless the launch specifies a `sessionDir` for a fresh subagent. Fresh subagent sessions are marked internal and hidden from normal session lists. See [Subagents](/subagents).
12
11
  - Workflow data written by releases before 0.10.0 stays untouched on disk. See [Workflow data from earlier releases](#workflow-data-from-earlier-releases).
13
12
 
13
+ Sections through [Workflow data from earlier releases](#workflow-data-from-earlier-releases) cover user and operator setup. The later sections cover the SDK SQLite API, custom adapters, and typed errors.
14
+
14
15
  ## Which store to choose
15
16
 
16
17
  | Situation | Choose | Why |
@@ -26,33 +27,38 @@ To move existing sessions between stores, see [Exporting and importing sessions]
26
27
 
27
28
  Local SQLite works out of the box with no external server. Atomic enables WAL mode, `FULL` synchronous writes, foreign keys, and cross-process writer queuing automatically.
28
29
 
30
+ - Passing an empty object `{}` in top-level `storage` selects `<storageHome>/storage.sqlite`. Passing `{}` in `sessions.storage` selects `<storageHome>/workflows/journal.sqlite` (overriding any shared `storage`).
31
+ - JSONL directory stores (`{ "dir": "..." }`) are allowed **only** in `sessions.storage` and `ATOMIC_SESSIONS_STORAGE`. Passing `"dir"` in top-level `storage`, `--storage`, `--storage-file`, or `ATOMIC_STORAGE` fails with `StorageConfigError`.
32
+
29
33
  ### Storage home
30
34
 
31
- Relative `path` and `dir` settings, relative `--storage` and `ATOMIC_STORAGE` paths, relative `secrets.file` paths, and shared `repos/` and `worktrees/` directories resolve against the agent directory's **storage home** (`storageHomeDir(agentDir, settings?)`).
35
+ Relative `path` and `dir` settings, relative `--storage` and `ATOMIC_STORAGE` paths, relative `secrets.file` paths, and shared `repos/` and `worktrees/` directories resolve against the agent directory's **storage home**.
32
36
 
33
37
  - **Default agent directory (`~/.atomic/agent`).** Storage home is `~/.atomic` under the current `HOME`. Moving or remounting the home directory keeps relative paths portable.
34
38
  - **Custom agent directory (`ATOMIC_CODING_AGENT_DIR`, `PI_CODING_AGENT_DIR`, or SDK `agentDir`).** Storage home is `<agentDir>` itself so sibling profiles stay isolated.
35
- - **Upgraded parent store adoption.** When a custom agent directory is upgraded from an older layout that kept a recognized session database or configured relative path in `<parent>` (other than `~/.atomic`), the first eligible profile keeps using `<parent>` and receives a one-time notice. Profiles that already have their own store stay isolated. Use absolute paths to share a local store intentionally across profiles.
39
+ - **Upgrading from an older custom agent directory layout.** When a custom agent directory upgrades from an older layout that kept a recognized session database or configured relative path in `<parent>` (other than `~/.atomic`), the first eligible profile keeps using `<parent>` and prints a one-time notice. Profiles that already have their own store stay isolated. Use absolute paths to share a local store intentionally across profiles.
36
40
  - **Relative secret files.** A relative `secrets.file` reference can still read an existing file in `<parent>`.
37
41
 
38
42
  `atomic storage status` never creates missing agent directories. A read-only agent directory works with a writable storage home, though recording a new storage-home decision requires a writable agent directory.
39
43
 
40
44
  ### Locks in the agent directory
41
45
 
42
- Processes that share an agent directory coordinate writes to `settings.json`, `auth.json`, project trust decisions, and session claims using locks beside those files. When a lock holder exits unexpectedly, the next process takes over the lock through an OS advisory lock on a `*.takeover.lock` file (`flock` on Unix, `LockFileEx` on Windows).
46
+ Processes that share an agent directory coordinate writes to `settings.json`, `auth.json`, project trust decisions, and session claims using lock files beside those files. If a process exits unexpectedly while holding a lock, the next process takes over automatically.
43
47
 
44
48
  These locks protect only processes on the same machine viewing the agent directory through the same local filesystem. Do not share one agent directory:
45
49
 
46
- - across multiple machines on a network filesystem (NFS, SMB, or cloud-synced folders), where advisory locks may not work across hosts;
50
+ - across multiple machines on a network filesystem (NFS, SMB, or cloud-synced folders), where OS file locks may not work across hosts;
47
51
  - on one machine through both a local path and a container volume, bind mount, or network mount of the same directory.
48
52
 
49
53
  Give each machine or container its own agent directory with `ATOMIC_CODING_AGENT_DIR`, and share sessions through a [shared database](#sharing-storage-across-hosts).
50
54
 
51
- If Atomic warns that a `*.takeover.lock` file or a leftover `*.takeover.<id>.dead` directory cannot be opened or removed, another user (such as a previous `sudo` run) owns it. Remove the item or fix ownership, for example `sudo chown $USER ~/.atomic/agent/settings.json.lock.takeover.lock`. Until fixed, lock takeovers fall back to a directory mutex that expires after 10 seconds if a holder dies.
55
+ If Atomic warns that a lock takeover file (such as `settings.json.lock.takeover.lock`) or leftover dead lock directory cannot be opened or removed, another user (such as a previous `sudo` run) owns it. Fix ownership or remove the stale lock, for example `sudo chown $USER ~/.atomic/agent/settings.json.lock.takeover.lock`. Until fixed, stale locks expire after 10 seconds before another process takes over.
52
56
 
53
57
  ## PostgreSQL
54
58
 
55
- `@bastani/atomic-storage-postgres` stores Atomic's shared state in PostgreSQL 16 or later. It works with self-hosted PostgreSQL and managed services, including Azure Database for PostgreSQL Flexible Server, Azure HorizonDB, Amazon RDS and Aurora PostgreSQL, Google Cloud SQL, AlloyDB, Neon, and Supabase.
59
+ `@bastani/atomic-storage-postgres` stores Atomic's shared state in PostgreSQL. **Atomic sessions require PostgreSQL 16 or later** (for session JSON query functions). The adapter itself accepts PostgreSQL 14 or later on connect for non-session tables, and rejects servers older than PostgreSQL 14.
60
+
61
+ It works with self-hosted PostgreSQL and managed services, including Azure Database for PostgreSQL Flexible Server, Azure HorizonDB, Amazon RDS and Aurora PostgreSQL, Google Cloud SQL, AlloyDB, Neon, and Supabase.
56
62
 
57
63
  ### What works on PostgreSQL
58
64
 
@@ -88,6 +94,8 @@ Next, run `atomic storage migrate` from a machine with the owner role credential
88
94
  atomic storage migrate --db 'postgresql://atomic_owner@db.example.com:5432/atomic' --password-file ~/atomic-owner-password
89
95
  ```
90
96
 
97
+ Passing `--token-file`, `--password-file`, `--auth`, or `--prefix` to `atomic storage migrate` requires passing `--db <url>` too. `atomic storage migrate` has no `--schema` flag; to migrate a custom schema, set `options.schema` in `settings.json`, `--storage`, or `ATOMIC_STORAGE` and run `atomic storage migrate` without `--db`.
98
+
91
99
  Then connect to the `atomic` database as `atomic_owner` and grant the runtime role its privileges:
92
100
 
93
101
  ```sql
@@ -104,13 +112,13 @@ These statements grant every privilege the runtime role needs. `LISTEN`, `NOTIFY
104
112
 
105
113
  Provider notes:
106
114
 
107
- - **Self-hosted PostgreSQL (15+) and Amazon RDS / Aurora.** Use the statements above. On RDS, run `GRANT atomic_owner TO <master user>;` before `CREATE DATABASE ... OWNER atomic_owner`.
115
+ - **Self-hosted PostgreSQL (16+) and Amazon RDS / Aurora.** Use the statements above. On RDS, run `GRANT atomic_owner TO <master user>;` before `CREATE DATABASE ... OWNER atomic_owner`.
108
116
  - **Azure Database for PostgreSQL Flexible Server.** Run the statements above as the server administrator (a member of `azure_pg_admin`). If you explicitly select `schema: "public"`, also run `GRANT CREATE ON SCHEMA public TO atomic_owner;` as the administrator.
109
117
  - **Google Cloud SQL.** Run the statements above as `postgres` or another member of `cloudsqlsuperuser`.
110
118
 
111
119
  When the runtime role lacks a required privilege or the schema is behind the current Atomic release, opening the store fails with `StorageConfigError` (`reason: "missing-privilege"`). The error names the exact `GRANT` or `atomic storage migrate` command to run.
112
120
 
113
- The one exception is the session fork staging table used for batched cross-connection cloning. If a low-privilege runtime role finds that table missing, it falls back to cloning in memory and emits a one-time warning asking you to run `atomic storage migrate` as the owner role.
121
+ If you have not run `atomic storage migrate` after an upgrade and a low-privilege runtime role clones a session across connections, Atomic falls back to copying in memory and prints a one-time warning asking you to run `atomic storage migrate` as the owner role.
114
122
 
115
123
  Every Atomic process opens a connection pool of up to 8 connections (`maxConnections`). If your fleet exceeds the server's `max_connections`, lower `maxConnections` or connect through a [connection pooler](#connection-poolers).
116
124
 
@@ -139,8 +147,8 @@ atomic storage status
139
147
  `atomic storage join` accepts `postgres://` and `postgresql://` URLs with a username and no embedded password. Pass exactly one credential option:
140
148
 
141
149
  - `--password-file <path>` copies the password into a private mode-`600` `~/.atomic/agent/storage-token.<id>` file. You can delete the input file afterward.
142
- - `--token-file <path>` saves the path as-is and rereads the file on every new connection. Use this with a Vault agent or secrets sidecar that rotates credentials automatically.
143
- - `--auth azure`, `--auth aws`, or `--auth gcp` authenticates using the machine's cloud identity. See [Cloud identities](#cloud-identities).
150
+ - `--token-file <path>` saves the path as-is and rereads the file on every new connection. Use this with a Vault agent or secrets sidecar that rotates credentials automatically. Atomic strips only one trailing `\n` or `\r\n` when reading PostgreSQL token files, so avoid extra trailing spaces or blank lines.
151
+ - `--auth azure`, `--auth aws`, or `--auth gcp` (the long forms `azure-entra`, `aws-iam`, and `gcp-iam` are also accepted) authenticates using the machine's cloud identity. See [Cloud identities](#cloud-identities).
144
152
 
145
153
  `atomic storage join` tests the connection with `SELECT 1` before writing anything, then updates only the top-level `storage` key in `~/.atomic/agent/settings.json`:
146
154
 
@@ -161,9 +169,9 @@ You can also edit this configuration directly. `secrets.password` accepts `{ "fi
161
169
  | `url` | Required | `postgres://` or `postgresql://` URL with username and no password |
162
170
  | `auth` | `"password"` | `"azure-entra"`, `"aws-iam"`, or `"gcp-iam"` for [cloud identities](#cloud-identities) |
163
171
  | `maxConnections` | `8` | Maximum pooled connections per Atomic process |
164
- | `statementTimeoutMs` | `30000` | Maximum runtime for one statement before server cancellation |
172
+ | `statementTimeoutMs` | `30000` | Maximum runtime for one statement before server cancellation (client cancels the connection 5,000 ms later if the server stops answering; idle connections close after 10,000 ms, and connect/pool-wait timeout is 10,000 ms) |
165
173
  | `listenUrl` | `url` | Direct endpoint for [wake-ups](#wake-ups) when `url` uses a transaction pooler |
166
- | `schema` | `"atomic"` | Lowercase schema name of letters, digits, and `_` |
174
+ | `schema` | `"atomic"` | Schema name starting with a lowercase ASCII letter or `_`, followed by lowercase letters, digits, or `_` (1 to 63 characters) |
167
175
  | `proxy` | From environment | `http://` or `https://` proxy URL for all connections, or `"none"` to connect directly |
168
176
 
169
177
  `atomic team join` supports libSQL URLs only. Use `atomic storage join` for PostgreSQL. SDK callers can import `openPostgresDatabase` directly from `@bastani/atomic-storage-postgres`.
@@ -172,7 +180,7 @@ You can also edit this configuration directly. `secrets.password` accepts `{ "fi
172
180
 
173
181
  Atomic connects over TLS to every remote host by default and verifies both the server certificate and hostname (`sslmode=verify-full`). If the URL omits the host, Atomic checks `PGHOST`.
174
182
 
175
- You can override this by adding a lowercase `sslmode` parameter to the URL. `verify-ca` verifies the CA without checking the hostname, `prefer` and `allow` encrypt without checking the certificate, and `disable` turns TLS off. `require` with `sslrootcert` behaves like `verify-ca`. Without `sslrootcert`, `require` verifies both certificate and hostname like `verify-full`, which is stricter than libpq. Uppercase TLS parameters or unknown `sslmode` values fail with `StorageConfigError`.
183
+ You can override this by adding a lowercase `sslmode` parameter to the URL (`uselibpqcompat` must also be lowercase if used). `verify-ca` verifies the CA without checking the hostname, `prefer` and `allow` encrypt without checking the certificate, and `disable` turns TLS off. `require` with `sslrootcert` behaves like `verify-ca`. Without `sslrootcert`, `require` verifies both certificate and hostname like `verify-full`, which is stricter than libpq. Uppercase TLS parameters or unknown `sslmode` values fail with `StorageConfigError`.
176
184
 
177
185
  Provider CA configuration:
178
186
 
@@ -236,9 +244,9 @@ With `--auth` (or `options.auth` in settings), Atomic requests a short-lived tok
236
244
 
237
245
  | `--auth` | `options.auth` | Install | Credential source |
238
246
  | --- | --- | --- | --- |
239
- | `azure` | `"azure-entra"` | `atomic install npm:@azure/identity` | `AZURE_*` variables, AKS workload identity, VM/App Service/Container App managed identity (`AZURE_CLIENT_ID` selects user-assigned), or `az login` |
240
- | `aws` | `"aws-iam"` | `atomic install npm:@aws-sdk/rds-signer` | Default AWS credentials (`AWS_*` variables, profiles, IRSA, or instance profile) |
241
- | `gcp` | `"gcp-iam"` | `atomic install npm:google-auth-library` | Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS`, Compute Engine/GKE/Cloud Run metadata server, or `gcloud auth application-default login`) |
247
+ | `azure` or `azure-entra` | `"azure-entra"` | `atomic install npm:@azure/identity` | `AZURE_*` variables, AKS workload identity, VM/App Service/Container App managed identity (`AZURE_CLIENT_ID` selects user-assigned), or `az login` |
248
+ | `aws` or `aws-iam` | `"aws-iam"` | `atomic install npm:@aws-sdk/rds-signer` | Default AWS credentials (`AWS_*` variables, profiles, IRSA, or instance profile) |
249
+ | `gcp` or `gcp-iam` | `"gcp-iam"` | `atomic install npm:google-auth-library` | Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS`, Compute Engine/GKE/Cloud Run metadata server, or `gcloud auth application-default login`) |
242
250
 
243
251
  If the SDK is missing or cannot issue a token, opening fails with `StorageConfigError` (`reason: "auth-unavailable"`). Cloud tokens require TLS, so keep the default `sslmode`.
244
252
 
@@ -257,13 +265,13 @@ Running `atomic install npm:@azure/identity` (or the AWS or Google SDK) installs
257
265
  - **`credential-in-url`.** Remove the password from the URL and pass `--password-file` or `--token-file`.
258
266
  - **`unsupported-url` from `atomic team join`.** `atomic team join` supports libSQL only. Use `atomic storage join` for PostgreSQL.
259
267
  - **`unsupported-option`.** `--password-file` and `--auth` apply to PostgreSQL only. libSQL uses `--token-file`.
260
- - **`unsupported-auth`.** `--auth` accepts `azure`, `aws`, or `gcp`.
268
+ - **`unsupported-auth`.** `--auth` accepts `azure` (`azure-entra`), `aws` (`aws-iam`), or `gcp` (`gcp-iam`).
261
269
  - **`adapter-not-installed`.** Run `atomic install npm:@bastani/atomic-storage-postgres` as the user running Atomic.
262
270
  - **`auth-unavailable`.** Install the cloud SDK named in the error and confirm the machine has a valid cloud identity. Atomic does not retry this error.
263
271
  - **`missing-privilege` (`42501` or `3F000`).** Run the `GRANT` named in the error for a runtime role (see [Set up the database](#set-up-the-database)), or run `atomic storage migrate` as the owner role if the error mentions ownership or `CREATE`.
264
272
  - **"This database was upgraded since this process started".** `atomic storage migrate` moved tables from `public` to `atomic` while this process was running. Restart the process.
265
273
  - **Refused token (`28P01` or Azure `28000`).** The token expired, targets the wrong user, or has an invalid format. For Azure, request a token for `https://ossrdbms-aad.database.windows.net` (`az account get-access-token --resource-type oss-rdbms`) or use `--auth azure`.
266
- - **`StorageUnavailableError` on open.** The server rejected credentials (`28P01` or `28000`), the database does not exist (`3D000`), or the server is older than PostgreSQL 14. Sessions require PostgreSQL 16 or newer.
274
+ - **`StorageUnavailableError` on open.** The server rejected credentials (`28P01` or `28000`), the database does not exist (`3D000`), or the server is older than PostgreSQL 14. Atomic sessions require PostgreSQL 16 or newer.
267
275
  - **Certificate untrusted (`self-signed certificate in certificate chain` or `unable to get local issuer certificate`).** Add `sslrootcert` pointing to your server CA. See [TLS](#tls).
268
276
  - **`INVALID_PURPOSE`.** The certificate in `sslrootcert` lacks `basicConstraints=CA:TRUE` or is restricted to client authentication. Point `sslrootcert` to the signing CA or reissue it with `CA:TRUE`. Not retried.
269
277
  - **`PATH_LENGTH_EXCEEDED`.** The certificate chain exceeds its root CA path-length limit. Reissue the root without that limit or sign the server certificate directly. Not retried.
@@ -297,7 +305,7 @@ atomic install npm:@bastani/atomic-storage-libsql
297
305
 
298
306
  - **Self-hosted `sqld`.** Always start `sqld` with `--checkpoint-interval-s 60` (or `SQLD_CHECKPOINT_INTERVAL_S=60`). Without it, `sqld` 0.24.33 and earlier can stall writes during WAL checkpoints. Atomic warns after three consecutive unanswered writes. Interval checkpoints pause writes briefly (up to 5 seconds) while Atomic retries automatically.
299
307
  - **Namespaces and headers.** For `sqld --enable-namespaces`, set `"namespace": "<name>"` in `options` (sent as `x-namespace` over `libsql:`, `https:`, or `http:` URLs). SDK callers can also pass extra `headers` to `openLibsqlDatabase`, which Atomic redacts from errors.
300
- - **Tokens and local files.** Save a Turso token with `turso db tokens create <db> > turso-token && chmod 600 turso-token` (one trailing line ending is stripped, and relative `file` paths resolve against [storage home](#storage-home)), or reference `{ "env": "TURSO_TOKEN" }`. Absolute `file:` URLs need no `secrets`. Add `prefix` to isolate projects or teams.
308
+ - **Tokens and local files.** Save a Turso token with `turso db tokens create <db> > turso-token && chmod 600 turso-token` (one trailing line ending is stripped when read from `secrets.authToken.file`, and relative paths resolve against [storage home](#storage-home)), or reference `{ "env": "TURSO_TOKEN" }`. Absolute `file:` URLs need no `secrets`. Add `prefix` to isolate projects or teams.
301
309
  - **Retries and WebSockets.** Transient outages, expired streams, and 30-second unanswered requests report `StorageTransientError`. Calls that failed before writing retry up to 5 times over about 4 seconds. Writes with an uncertain outcome fail immediately with `outcome: "unknown"` and are not retried automatically. Over `ws:` or `wss:`, a batch whose `COMMIT` does not run reports `StorageUnavailableError` (`TRANSACTION_CLOSED`).
302
310
 
303
311
  SDK callers can import `openLibsqlDatabase` directly from `@bastani/atomic-storage-libsql` as plain ESM with TypeScript declarations. To wrap another driver, see [Bring your own driver](#bring-your-own-driver).
@@ -307,11 +315,11 @@ SDK callers can import `openLibsqlDatabase` directly from `@bastani/atomic-stora
307
315
  Share sessions and Intercom across machines or CI fleets by pointing every host at the same [PostgreSQL](#postgresql) or [Turso / libSQL](#turso-and-libsql) database with the same `prefix`. Never put a local SQLite file on a network filesystem.
308
316
 
309
317
  - **Shared `storage` vs. `sessions.storage`.** Configuring top-level `storage` (in global settings, `--storage`, `--storage-file`, or `ATOMIC_STORAGE`) enables multi-node Intercom routing across hosts. Setting only `sessions.storage` shares sessions without enabling multi-node Intercom. On libSQL, single Intercom messages over 5,000,000 bytes fail with `StoragePayloadTooLargeError`.
310
- - **Data stored and access.** The shared database holds sessions, tool-output blobs, [worktree snapshot](/worktree-snapshots) blobs, and transient Intercom messages. Treat database read access as full read access. To share Intercom while keeping personal sessions local, use `atomic team join` as described in [Team and CI setup](/guides/team-setup). To resume sessions across machines, see [Resume on any machine](/guides/resume-on-any-machine).
318
+ - **Data stored and access.** The shared database holds sessions, tool-output blobs, [worktree snapshot](/worktree-snapshots) blobs, and transient Intercom messages. Treat database read access as full read access. To share Intercom while keeping personal sessions local, use `atomic team join` as described in [Set up teams and CI](/guides/team-setup). To resume sessions across machines, see [Resume sessions on any machine](/guides/resume-on-any-machine).
311
319
 
312
320
  ### Joining a machine to a shared database
313
321
 
314
- > Want shared Intercom while keeping personal sessions local? Use `atomic team join` instead ([Team and CI setup](/guides/team-setup)).
322
+ > Want shared Intercom while keeping personal sessions local? Use `atomic team join` instead ([Set up teams and CI](/guides/team-setup)).
315
323
 
316
324
  **libSQL / Turso:**
317
325
 
@@ -335,15 +343,15 @@ atomic storage status
335
343
  `atomic storage join <url> [options]` runs four steps:
336
344
 
337
345
  1. Validates the URL, adapter installation, and credentials, then runs a read-only `SELECT 1` within 15 seconds. If any check fails, nothing is written.
338
- 2. Stores static credentials (`--token-file` for libSQL, `--password-file` for PostgreSQL) in a mode-`600` `~/.atomic/agent/storage-token.<id>` file, reusing an existing identical file and leaving older files intact for running sessions.
346
+ 2. Stores static credentials (`--token-file` for libSQL, trimming surrounding whitespace; `--password-file` for PostgreSQL) in a mode-`600` `~/.atomic/agent/storage-token.<id>` file, reusing an existing identical file and leaving older files intact for running sessions.
339
347
  3. Updates only the top-level `storage` key in `~/.atomic/agent/settings.json` (plus optional `--prefix`), preserving all other settings.
340
348
  4. Lists any higher-precedence environment variables or project settings and notes if the running Intercom broker still uses the previous store. Run `atomic intercom restart` to switch the broker ([Running Intercom across machines](/intercom/operations#running-intercom-across-machines)).
341
349
 
342
350
  URL and credential rules:
343
351
 
344
352
  - **No embedded secrets.** Userinfo passwords and `authToken=` or `password=` query parameters are refused.
345
- - **libSQL schemes.** Accepts `libsql://`, `https://`, `wss://`, or an absolute `file:` URL (which needs no token). Relative `file:` URLs, `--password-file`, and `--auth` are refused.
346
- - **PostgreSQL credentials.** Pass exactly one of `--password-file <path>` (copied to a private file), `--token-file <path>` (external rotated file referenced by path and reread per connection), or `--auth azure|aws|gcp` (cloud identity). The same flags work with `atomic storage migrate --db`.
353
+ - **libSQL schemes.** Accepts `libsql://`, `https://`, `http://`, `wss://`, `ws://`, or an absolute `file:` URL (which needs no token). Prefer TLS (`libsql://`, `https://`, or `wss://`) for remote hosts; `http://` and `ws://` are intended for local or private-network `sqld`. Relative `file:` URLs, `--password-file`, and `--auth` are refused.
354
+ - **PostgreSQL credentials.** Pass exactly one of `--password-file <path>` (copied to a private file), `--token-file <path>` (external rotated file referenced by path and reread per connection, stripping only one trailing `\n` or `\r\n`), or `--auth azure|aws|gcp` (also accepts `azure-entra`, `aws-iam`, `gcp-iam`). The same flags work with `atomic storage migrate --db`.
347
355
 
348
356
  ### Checking the selected storage
349
357
 
@@ -361,11 +369,11 @@ A host launching Atomic processes (such as `atomic --mode rpc` children) can ove
361
369
 
362
370
  | Option | Applies to | Equivalent setting |
363
371
  | --- | --- | --- |
364
- | `--storage '<json>'` | Sessions and Intercom | Shared `storage` |
365
- | `--storage-file <path>` | Sessions and Intercom (reads JSON from a file) | Shared `storage` |
366
- | `ATOMIC_STORAGE` | Sessions and Intercom | Shared `storage` |
367
- | `ATOMIC_SESSIONS_STORAGE` | Sessions only (also accepts `{ "dir": "..." }`) | `sessions.storage` |
368
- | `ATOMIC_PROFILE=ci` with `ATOMIC_TEAM_URL`, `ATOMIC_TEAM_TOKEN` or `ATOMIC_TEAM_TOKEN_FILE`, and optional `ATOMIC_TEAM_PREFIX` | Sessions and Intercom on the team database | See [CI and swarms](/guides/team-setup#ci-and-swarms) |
372
+ | `--storage '<json>'` | Sessions and Intercom (cannot use `{ "dir": "..." }`) | Shared `storage` |
373
+ | `--storage-file <path>` | Sessions and Intercom (reads JSON from a file; cannot use `{ "dir": "..." }`) | Shared `storage` |
374
+ | `ATOMIC_STORAGE` | Sessions and Intercom (cannot use `{ "dir": "..." }`) | Shared `storage` |
375
+ | `ATOMIC_SESSIONS_STORAGE` | Sessions only (also accepts `{ "dir": "..." }` for JSONL) | `sessions.storage` |
376
+ | `ATOMIC_PROFILE=ci` with `ATOMIC_TEAM_URL`, `ATOMIC_TEAM_TOKEN` or `ATOMIC_TEAM_TOKEN_FILE`, and optional `ATOMIC_TEAM_PREFIX` | Sessions and Intercom on the team libSQL database | See [CI and swarms](/guides/team-setup#ci-and-swarms) |
369
377
 
370
378
  ```bash
371
379
  ATOMIC_STORAGE='{"adapter":"@example/atomic-sqlite","options":{"url":"libsql://team.example"},"secrets":{"authToken":{"env":"TEAM_DB_TOKEN"}},"prefix":"svc_"}' \
@@ -374,7 +382,7 @@ ATOMIC_STORAGE='{"adapter":"@example/atomic-sqlite","options":{"url":"libsql://t
374
382
  atomic --mode rpc --storage-file /etc/atomic/storage.json
375
383
  ```
376
384
 
377
- `--storage` and `--storage-file` cannot be combined. The interactive CLI forwards `--storage` to its background engine, while other child processes inherit environment variables but not CLI flags.
385
+ `--storage` and `--storage-file` cannot be combined. Interactive sessions keep `--storage` active for the session, while spawned child processes inherit environment variables (such as `ATOMIC_STORAGE`) rather than CLI flags.
378
386
 
379
387
  One Intercom broker serves every session in an agent directory and keeps the storage selection of the process that started it until it exits or `atomic intercom restart` replaces it. Project settings never select the broker's storage.
380
388
 
@@ -389,7 +397,7 @@ Precedence for sessions, highest first:
389
397
  7. `ATOMIC_PROFILE=ci`
390
398
  8. `sessions.storage` setting
391
399
  9. Shared `storage` setting
392
- 10. Default local SQLite file
400
+ 10. Default local SQLite file (`~/.atomic/workflows/journal.sqlite`)
393
401
 
394
402
  Override conflicts and path rules:
395
403
 
@@ -398,7 +406,7 @@ Override conflicts and path rules:
398
406
  - Combining `ATOMIC_SESSIONS_STORAGE` or `--storage` / `--storage-file` with a non-empty `ATOMIC_CODING_AGENT_SESSION_DIR` fails startup with `StorageConfigError` (`reason: "conflicting-overrides"`). Unset one variable or pass an explicit session flag.
399
407
  - Relative `path`, `dir`, and `secrets.file` values resolve against [storage home](#storage-home). Relative adapter specifiers resolve from the agent directory. Relative `--storage-file` paths resolve from the current working directory. Empty variables are ignored.
400
408
 
401
- Before starting any session (in every mode, including RPC and SDK `createAgentSession()`), Atomic validates `--storage`, `--storage-file`, `ATOMIC_STORAGE`, `ATOMIC_SESSIONS_STORAGE`, and `ATOMIC_PROFILE=ci`, even when outranked by a higher-precedence override. Invalid JSON, schema violations, unreadable files, or incomplete CI variables raise `StorageConfigError` or `TeamProfileConfigError` without falling back to another store. Errors name only the variable or flag, never secret values.
409
+ Before starting any session (in every mode, including RPC and SDK `createAgentSession()`), Atomic validates `--storage`, `--storage-file`, `ATOMIC_STORAGE`, `ATOMIC_SESSIONS_STORAGE`, and `ATOMIC_PROFILE=ci`, even when outranked by a higher-precedence override. Invalid JSON, schema violations, unreadable files, or incomplete CI variables exit cleanly with `Error: ...` (exit code `1`) on the CLI or throw `StorageConfigError` / `TeamProfileConfigError` in the SDK without falling back to another store. Errors name only the variable or flag, never secret values.
402
410
 
403
411
  Process-level storage options bypass [project trust](/security) because they come from the launching host. Because adapter modules execute code with Atomic's privileges, select only trusted modules and pass credentials through `secrets` instead of `options`. Prefer `--storage-file` or environment variables over `--storage` when the selection itself is sensitive, because command-line arguments can be visible to other local users.
404
412
 
@@ -408,7 +416,7 @@ SDK callers can also keep a token strictly in memory with `inMemorySecret(token)
408
416
 
409
417
  `atomic storage export <dir>` writes sessions to JSONL files, and `atomic storage import <dir>` restores them. Use these commands to move sessions between machines or migrate from one storage backend to another.
410
418
 
411
- ```sh
419
+ ```bash
412
420
  atomic storage export <dir> [--limit <n>] [--since <time>]
413
421
  atomic storage import <dir>
414
422
  ```
@@ -426,8 +434,8 @@ Import reads only `*.jsonl` files inside `<dir>/sessions` and ignores everything
426
434
 
427
435
  Export writes every session by default:
428
436
 
429
- - `--limit <n>` writes only the `n` most recently modified sessions.
430
- - `--since <time>` writes sessions modified at or after `<time>` (such as `2026-11-01` or `2026-11-01T09:30:00Z`).
437
+ - `--limit <n>` writes only the `n` most recently modified sessions (`n` must be an integer `>= 1` made of ASCII digits).
438
+ - `--since <time>` writes sessions modified at or after `<time>` (parsed with JavaScript `Date.parse()`). ISO date-only strings such as `2026-11-01` mean UTC midnight, whereas date-time strings without an offset such as `2026-11-01T09:30:00` use your local timezone. Add `Z` or an explicit offset (for example `2026-11-01T09:30:00Z`) to avoid timezone ambiguity.
431
439
 
432
440
  Export includes sessions from every project and internal sessions, including fresh subagents' internal sessions (so subagent history transfers with its parent) and workflow-stage internal sessions from earlier releases.
433
441
 
@@ -449,7 +457,12 @@ If an import fails partway through writing multiple sessions, it exits `1` and l
449
457
 
450
458
  Both commands use `ATOMIC_CODING_AGENT_DIR` and the active session storage for the current directory. Exporting from or importing into a shared libSQL, Turso, or PostgreSQL database (or an in-memory store) is refused by default because joined machines already share that database.
451
459
 
452
- Pass `--storage <json>` or `--storage-file <path>` to target a specific store explicitly, including a shared database. For example, to migrate sessions from libSQL to PostgreSQL:
460
+ Pass `--storage <json>` or `--storage-file <path>` to target a specific store explicitly, including a shared database:
461
+
462
+ - Relative `"path"` values inside `atomic storage export` / `import --storage` (or `--storage-file`) resolve against the **current working directory (`cwd`)**, not storage home. If you copy a `storage` object from `settings.json` whose `"path"` is relative, convert it to an absolute path first.
463
+ - JSONL `{ "dir": "..." }` and empty `{}` selections are rejected by `export` and `import --storage`.
464
+
465
+ For example, to migrate sessions from libSQL to PostgreSQL:
453
466
 
454
467
  ```bash
455
468
  atomic storage export ~/moved --storage-file old-storage.json
@@ -479,7 +492,7 @@ External tools can redact string values (such as replacing a secret with `***`)
479
492
 
480
493
  On a runner that caches a directory across jobs:
481
494
 
482
- ```sh
495
+ ```bash
483
496
  # Start of job, after restoring $STATE_DIR
484
497
  mkdir -p "$STATE_DIR" && atomic storage import "$STATE_DIR"
485
498
 
@@ -506,7 +519,7 @@ Payloads that still exceed a backend's limit fail non-retryably with `StoragePay
506
519
  - **One-way session schema upgrade.** Writing the first chunked session entry permanently upgrades the session schema from version `1` to `2`. Upgrade every host sharing a database together because older releases reject version 2 stores with `StorageSchemaVersionError`.
507
520
  - **Offline local snapshot chunk migration.** On older local SQLite files, background snapshot collection migrates legacy snapshot chunk tables automatically when free disk space allows. To migrate a cleanly closed local SQLite file offline with bounded WAL growth, stop all Atomic processes using that file and run:
508
521
 
509
- ```sh
522
+ ```bash
510
523
  atomic storage move-snapshot-chunks <sqlite-file> [--prefix <prefix>]
511
524
  ```
512
525
 
@@ -525,9 +538,11 @@ To run an older workflow definition with this release, see [Migrating workflows]
525
538
 
526
539
  ## SDK and local SQLite API
527
540
 
528
- `@bastani/atomic` and `@bastani/atomic/storage` export an async SQLite API and storage path helpers.
541
+ The sections below are for SDK consumers embedding Atomic and developers writing custom storage adapters.
542
+
543
+ `@bastani/atomic` and `@bastani/atomic/storage` export an async SQLite API and storage path helpers:
529
544
 
530
- ```ts
545
+ ```typescript
531
546
  import { openNodeSqliteDatabase } from "@bastani/atomic/storage";
532
547
 
533
548
  const database = await openNodeSqliteDatabase("./data/example.sqlite");
@@ -551,23 +566,20 @@ try {
551
566
 
552
567
  ### SDK path helpers
553
568
 
554
- `@bastani/atomic/storage` and `@bastani/atomic` export `storageHomeDir(agentDir?, settings?)`, `workflowsStorageDir(agentDir?, settings?)`, `defaultSessionDatabasePath(agentDir?, settings?)`, `defaultSharedStoragePath(agentDir?, settings?)`, and `storagePathBaseDir(path, agentDir, settings?)`. Pass merged settings before opening a store so parent-store adoption rules resolve accurately.
569
+ `@bastani/atomic/storage` and `@bastani/atomic` export `storageHomeDir(agentDir?, settings?)`, `workflowsStorageDir(agentDir?, settings?)`, `defaultSessionDatabasePath(agentDir?, settings?)`, `defaultSharedStoragePath(agentDir?, settings?)`, and `storagePathBaseDir(path, agentDir, settings?)`. Pass merged settings before opening a store so legacy parent-directory adoption rules resolve accurately.
555
570
 
556
- ### Concurrency, queues, and diagnostics
571
+ ### Concurrency, options, and diagnostics
557
572
 
558
- - **Database options.** `openNodeSqliteDatabase(path, options?)` creates parent directories and configures WAL mode, `FULL` sync, foreign keys, and `busyTimeoutMs: 5000`. Pass `:memory:` for ephemeral databases or `{ readOnly: true }` to inspect a file without creating it or changing its journal mode.
559
- - **Worker threads.** `openNodeSqliteDatabase` runs each file-backed connection on its own worker thread so your event loop stays responsive while statements wait on locks or disk syncs. `:memory:` databases and connections wrapped with `wrapNodeSqliteDatabase(conn)` run on the calling thread.
560
- - **Async lock waiting.** When a same-thread `openNodeSqliteDatabase` transaction holds a WAL-mode file's write lock, conflicting writes through `wrapNodeSqliteDatabase` wait asynchronously off the event loop instead of blocking it, failing with `SQLITE_BUSY` if the busy timeout expires. Keep raw `DatabaseSync` calls separate from wrapped handles on the same connection, and open shared writers through `openNodeSqliteDatabase` or `wrapNodeSqliteDatabase`.
561
- - **Open locks.** File-backed connections take a shared lock on `<file>-open.lock` so checkpoint cleanup never deletes live journals. Avoid opening crashed hosts' checkpoint journals with external tools while a new host starts.
562
- - **Same-process and cross-process writer queues.** Separate `openNodeSqliteDatabase` handles to the same file share an in-process queue. `wrapNodeSqliteDatabase(conn)` shares a queue per wrapped connection and leaves the underlying connection open on `close()`. Across processes, writers queue FIFO using `<file>-writers`, `<file>-wakes`, and `<file>-holders`.
563
- - **Group commit and lock wait.** `groupCommitHoldMs` (default `100` ms, exported as `DEFAULT_GROUP_COMMIT_HOLD_MS`, `0` commits individually) batches queued transactions per lock acquisition. Waiting writers refresh every 500 ms and bypass dead processes after 2 seconds. Exceeding `lockWaitMs` (default `30000` ms, or per-transaction `{ lockWaitMs }`) with no commits rejects with `StorageWriteLockTimeoutError`.
564
- - **Diagnostics.** `getWriterQueueStats(db)` returns 10-second `lockHeldRatio`, `waiters`, `p50WaitMs`, `p95WaitMs`, and `commitsPerSecond`. `getWriterQueueDegradation(db)` returns recorded `StorageWriterQueueDegradedError` entries (also logged in [debug mode](/development#debugging)). Unusable queue directories reject with `StorageWriterQueueUnusableError`, and non-node-sqlite handles throw `StorageUnsupportedOperationError`.
573
+ - **Database options.** `openNodeSqliteDatabase(path, options?)` creates parent directories and enables WAL mode, `FULL` sync, foreign keys, and `busyTimeoutMs: 5000`. Pass `:memory:` for an ephemeral database or `{ readOnly: true }` to inspect a file without creating it or changing its journal mode. File-backed handles run off the main event loop so statements waiting on locks or disk syncs do not block your application.
574
+ - **Wrapping an existing connection.** `wrapNodeSqliteDatabase(conn)` adapts an existing Node `DatabaseSync` handle on the calling thread and leaves the underlying connection open on `close()`. Avoid mixing raw `DatabaseSync` calls with wrapped calls on the same connection.
575
+ - **Writer queuing and timeouts.** Multiple handles in one process and across processes on the same host share FIFO write queues. `groupCommitHoldMs` (default `100` ms, exported as `DEFAULT_GROUP_COMMIT_HOLD_MS`, `0` commits individually) batches queued transactions per lock acquisition. Waiting longer than `lockWaitMs` (default `30000` ms, or per-transaction `{ lockWaitMs }`) with no commits rejects with `StorageWriteLockTimeoutError`.
576
+ - **Diagnostics.** `getWriterQueueStats(db)` returns 10-second lock utilization, waiter count, wait latency percentiles (`p50WaitMs`, `p95WaitMs`), and `commitsPerSecond`. `getWriterQueueDegradation(db)` returns recorded `StorageWriterQueueDegradedError` entries (also logged in [debug mode](/development#debugging)). Passing a non-node-sqlite handle throws `StorageUnsupportedOperationError`.
565
577
 
566
578
  ## Selecting an adapter
567
579
 
568
580
  A storage adapter is a module whose default export satisfies `StorageAdapterModule`:
569
581
 
570
- ```ts
582
+ ```typescript
571
583
  import type { StorageAdapterModule } from "@bastani/atomic/storage";
572
584
 
573
585
  export default {
@@ -628,7 +640,7 @@ Atomic resolves adapter package names in this order:
628
640
  2. Packages in effective global settings (including legacy `~/.pi/agent/settings.json` for the default agent directory). Project packages are not searched.
629
641
  3. Module resolution from the agent directory.
630
642
 
631
- Child processes that Atomic starts (such as the background engine, subagents, and the Intercom broker) automatically inherit adapters resolved from the host's packages without reloading the host package. `atomic storage status` shows the resolved path when run inside such a process, and resolves from global settings or the agent directory when run directly from a shell.
643
+ Child processes that Atomic starts (such as subagents and the Intercom broker) automatically inherit adapters resolved from the host's packages without reloading the host package. `atomic storage status` shows the resolved path when run inside such a process, and resolves from global settings or the agent directory when run directly from a shell.
632
644
 
633
645
  ## Bring your own driver
634
646
 
@@ -651,213 +663,99 @@ Transient retry and queue bounds:
651
663
  - Recognized transient failures reject with `StorageTransientError`. Statements and batches that failed before writing retry up to `STORAGE_TRANSIENT_RETRY_ATTEMPTS` (5) times starting at 250 ms with exponential backoff and up to 20% jitter. Writes with `outcome: "unknown"` never retry automatically.
652
664
  - Transactions retry (re-running their callback) only when called with `{ retryTransientFailures: true }` and only for callbacks that have no external side effects. Non-boolean values throw `StorageConfigError`. The first retried failure on a database emits a one-time process warning.
653
665
  - While one call runs without settling, waiting priority calls (such as heartbeats or lease renewals) fail after `STORAGE_PRIORITY_CALL_MAX_WAIT_MS` (10 seconds), and other waiting calls fail after `STORAGE_QUEUED_CALL_MAX_WAIT_MS` (60 seconds), both with `StorageUnavailableError`. Timers reset for each call that begins running.
654
- - On a libSQL server, if an outage interrupts an open write transaction, `@bastani/atomic-storage-libsql` retries closing the abandoned stream (250 ms to 8 s backoff, up to 5 minutes) to release the server write lock. If the server already moved past the stream baton, the lock clears when the server expires the stream (about 5 seconds on `sqld`).
655
666
  - For shared local SQLite files, enable WAL mode with `switchToWriteAheadLog(exec, busyTimeoutMs)` from `@bastani/atomic/storage`. It retries `SQLITE_BUSY` up to `busyTimeoutMs` and retries Windows `SQLITE_IOERR_TRUNCATE` for up to 5 seconds (or `busyTimeoutMs`, whichever is shorter).
656
667
 
657
668
  You can also implement `SqliteDatabase` directly. In either case, verify your implementation with the [conformance suite](#adapter-conformance).
658
669
 
659
- ### libSQL / Turso example
660
-
661
- This module is a complete custom adapter. Install `@libsql/client` where the module can import it, such as in an [Atomic package](#adapters-from-atomic-packages). For local `file:` URLs, create the parent directory first.
670
+ ### Custom driver adapter example
662
671
 
663
- Keep `closeEachConnectionOnce` and `releaseClosedConnections` when copying this example. On local files, `@libsql/client` 0.18 wraps a native driver that can close a SQLite handle twice if no statement references the connection. Holding a prepared statement across `close()` and running two GC passes for local files prevents that double close and releases file handles on Windows. `@bastani/atomic-storage-libsql` applies the same workaround.
672
+ For production Turso or `sqld` deployments, install `@bastani/atomic-storage-libsql` (which includes abandoned-stream cleanup, namespace headers, and Windows local-file close safeguards). The minimal example below shows the `createSqliteDatabase` and `StorageAdapterModule` structure for wrapping any SQLite-compatible client:
664
673
 
665
- {/* custom-driver-example */}
666
- ```ts
667
- import { createRequire } from "node:module";
668
- import { setFlagsFromString } from "node:v8";
669
- import { runInNewContext } from "node:vm";
670
- import type { Client, Transaction } from "@libsql/client";
674
+ ```typescript
675
+ import { createClient, type Client, type Transaction } from "@libsql/client";
671
676
  import {
672
- createSqliteDatabase,
673
- redactSecrets,
674
- type SqliteDatabase,
675
- type SqliteDriverExecutor,
676
- type StorageAdapterModule,
677
- StorageAdapterLoadError,
678
- type StorageFailureCause,
677
+ createSqliteDatabase,
678
+ redactSecrets,
679
+ type SqliteDatabase,
680
+ type SqliteDriverExecutor,
681
+ type StorageAdapterModule,
679
682
  } from "@bastani/atomic/storage";
680
683
 
681
- export interface LibsqlDatabaseOptions {
682
- url: string;
683
- authToken?: string;
684
+ export interface CustomDriverOptions {
685
+ url: string;
686
+ authToken?: string;
684
687
  }
685
688
 
686
- /** Credentials a libSQL URL can carry: its userinfo and every `authToken` query value. */
687
- function urlCredentials(url: string): string[] {
688
- const secrets: string[] = [];
689
- // Scan each key/value once, including malformed URLs, without retrying a growing suffix at every '?'.
690
- for (let index = 0; index < url.length; index++) {
691
- if (url[index] !== "?" && url[index] !== "&") continue;
692
- const start = ++index;
693
- while (index < url.length && !"?&=#".includes(url[index]!)) index++;
694
- if (url[index] === "=") {
695
- const valueStart = ++index;
696
- while (index < url.length && url[index] !== "&" && url[index] !== "#") index++;
697
- const token = new URLSearchParams(url.slice(start, index)).get("authToken");
698
- if (token !== null) secrets.push(url.slice(valueStart, index), token);
699
- }
700
- index--;
701
- }
702
- const userinfo = url.match(/\/\/([^/?#]*)@/)?.[1];
703
- if (userinfo !== undefined) secrets.push(...userinfo.split(":"));
704
- return secrets;
689
+ function executor(connection: () => Client | Transaction): SqliteDriverExecutor {
690
+ return {
691
+ async execute(sql, params) {
692
+ const result = await connection().execute({ sql, args: [...params] });
693
+ return { columns: result.columns, rows: result.rows, changes: result.rowsAffected };
694
+ },
695
+ executeMultiple: (sql) => connection().executeMultiple(sql),
696
+ };
705
697
  }
706
698
 
707
- const closesOnce = Symbol.for("@bastani/atomic-storage-libsql.closesOnce");
708
-
709
- interface LibsqlConnection {
710
- open: boolean;
711
- close(): void;
712
- prepare(sql: string): object;
713
- }
714
-
715
- interface LibsqlConnectionClass {
716
- prototype: LibsqlConnection & { [closesOnce]?: true };
717
- }
718
-
719
- const statementsHeldWhileClosing = new Set<object>();
720
-
721
- function statementHoldingConnection(connection: LibsqlConnection): object | undefined {
722
- if (!connection.open) return undefined;
723
- try {
724
- return connection.prepare("SELECT 1");
725
- } catch {
726
- return undefined;
727
- }
728
- }
729
-
730
- function closeEachConnectionOnce(): void {
731
- const client = createRequire(import.meta.url).resolve("@libsql/client");
732
- const Connection = createRequire(client)("libsql") as LibsqlConnectionClass;
733
- if (Connection.prototype[closesOnce]) return;
734
- const close = Connection.prototype.close;
735
- Connection.prototype.close = function (this: LibsqlConnection) {
736
- const statement = statementHoldingConnection(this);
737
- if (statement) statementsHeldWhileClosing.add(statement);
738
- try {
739
- close.call(this);
740
- } finally {
741
- if (statement) statementsHeldWhileClosing.delete(statement);
742
- }
743
- };
744
- Connection.prototype[closesOnce] = true;
745
- }
746
-
747
- interface GarbageCollectingRuntime {
748
- gc?: () => void;
749
- Bun?: { gc(force: boolean): void };
750
- }
751
-
752
- function exposedGc(): () => void {
753
- setFlagsFromString("--expose-gc");
754
- try {
755
- return runInNewContext("gc") as () => void;
756
- } finally {
757
- setFlagsFromString("--no-expose-gc");
758
- }
759
- }
760
-
761
- function collectGarbage(): void {
762
- const runtime = globalThis as GarbageCollectingRuntime;
763
- if (runtime.gc) runtime.gc();
764
- else if (runtime.Bun) runtime.Bun.gc(true);
765
- else exposedGc()();
766
- }
767
-
768
- const COLLECTION_PASSES = 2;
769
-
770
- async function releaseClosedConnections(): Promise<void> {
771
- for (let pass = 0; pass < COLLECTION_PASSES; pass++) {
772
- collectGarbage();
773
- await new Promise((resolve) => setImmediate(resolve));
774
- }
775
- }
776
-
777
- function statements(connection: () => Client | Transaction): SqliteDriverExecutor {
778
- return {
779
- async execute(sql, params) {
780
- const result = await connection().execute({ sql, args: [...params] });
781
- return { columns: result.columns, rows: result.rows, changes: result.rowsAffected };
782
- },
783
- executeMultiple: (sql) => connection().executeMultiple(sql),
784
- };
785
- }
786
-
787
- export async function openLibsqlDatabase({ url, authToken }: LibsqlDatabaseOptions): Promise<SqliteDatabase> {
788
- let createClient: typeof import("@libsql/client").createClient;
789
- try {
790
- ({ createClient } = await import("@libsql/client"));
791
- closeEachConnectionOnce();
792
- } catch (cause) {
793
- throw new StorageAdapterLoadError("@libsql/client", cause as StorageFailureCause);
794
- }
795
- let client: Client | undefined;
796
- // Create the client inside a driver call, so the facade redacts credentials from its failures.
797
- const connection = () => (client ??= createClient({ url, authToken, intMode: "bigint" }));
798
- const database = createSqliteDatabase({
799
- descriptor: { adapter: "libsql", location: url },
800
- redact: redactSecrets([authToken ?? "", ...urlCredentials(url)]),
801
- ...statements(connection),
802
- async beginTransaction() {
803
- const transaction = await connection().transaction("write");
804
- return {
805
- ...statements(() => transaction),
806
- commit: () => transaction.commit(),
807
- rollback: () => transaction.rollback(),
808
- close: () => transaction.close(),
809
- };
810
- },
811
- async close() {
812
- client?.close();
813
- if (/^file:/i.test(url)) await releaseClosedConnections();
814
- },
815
- });
816
- try {
817
- await database.exec("PRAGMA foreign_keys = ON");
818
- return database;
819
- } catch (error) {
820
- await database.close().catch(() => {});
821
- throw error;
822
- }
699
+ export async function openCustomDatabase({ url, authToken }: CustomDriverOptions): Promise<SqliteDatabase> {
700
+ let client: Client | undefined;
701
+ const connection = () => (client ??= createClient({ url, authToken, intMode: "bigint" }));
702
+ const database = createSqliteDatabase({
703
+ descriptor: { adapter: "custom-libsql", location: url },
704
+ redact: redactSecrets(authToken ? [authToken] : []),
705
+ ...executor(connection),
706
+ async beginTransaction() {
707
+ const tx = await connection().transaction("write");
708
+ return {
709
+ ...executor(() => tx),
710
+ commit: () => tx.commit(),
711
+ rollback: () => tx.rollback(),
712
+ close: () => tx.close(),
713
+ };
714
+ },
715
+ async close() {
716
+ client?.close();
717
+ },
718
+ });
719
+ await database.exec("PRAGMA foreign_keys = ON");
720
+ return database;
823
721
  }
824
722
 
825
723
  export default {
826
- atomicStorageAdapter: 1,
827
- openDatabase: (options) =>
828
- openLibsqlDatabase({
829
- url: String(options.url),
830
- authToken: typeof options.authToken === "string" ? options.authToken : undefined,
831
- }),
724
+ atomicStorageAdapter: 1,
725
+ openDatabase: (options) =>
726
+ openCustomDatabase({
727
+ url: String(options.url),
728
+ authToken: typeof options.authToken === "string" ? options.authToken : undefined,
729
+ }),
832
730
  } satisfies StorageAdapterModule;
833
731
  ```
834
- {/* /custom-driver-example */}
835
732
 
836
- The default export lets settings select this module as an [adapter](#selecting-an-adapter). From the SDK, call `openLibsqlDatabase` directly:
733
+ The default export lets settings select this module as an [adapter](#selecting-an-adapter). From the SDK, call your open helper directly and pass the database to `createAgentSession`:
837
734
 
838
- ```ts
839
- import { openLibsqlDatabase } from "./libsql-adapter.js";
735
+ ```typescript
736
+ import { openCustomDatabase } from "./custom-adapter.js";
840
737
 
841
- const database = await openLibsqlDatabase({ url: "file:./data.sqlite" });
842
- // For Turso: { url: "libsql://your-database.turso.io", authToken: token }
738
+ const database = await openCustomDatabase({
739
+ url: "libsql://your-database.turso.io",
740
+ authToken: process.env.TURSO_TOKEN,
741
+ });
843
742
  try {
844
- await database.exec("CREATE TABLE IF NOT EXISTS notes (text TEXT)");
845
- await database.transaction(async (tx) => {
846
- await tx.run("INSERT INTO notes VALUES (?)", "hello");
743
+ const { session } = await createAgentSession({
744
+ sessionStore: { kind: "database", database, prefix: "project_" },
847
745
  });
848
- const notes = await database.all("SELECT text FROM notes");
746
+ await session.prompt("List the failing tests");
849
747
  } finally {
850
748
  await database.close();
851
749
  }
852
750
  ```
853
751
 
854
- Pass the returned database as `sessionStore: { kind: "database", database, prefix: "project_" }`. Multiple stores can share one database without closing it.
752
+ Multiple stores can share one caller-owned `database` without closing it.
855
753
 
856
754
  ### Custom `SessionStore` contracts
857
755
 
858
756
  Non-SQL backends can implement `openSessionStore` directly (each session has one writer):
859
757
 
860
- - **Required for `history://`.** Implement `readEntryRange(id, query)` honoring `fromSeq`, `toSeq`, `maxChars`, `largeEntryBytes`, `skipTypes`, and `signal`. Return freshly owned UTF-8 JSON `rawChunks` buffers (never shared cache buffers) and `{ entries: [{ seq, entry }], throughSeq, lastSeq }` without falling back to whole-session `load()`.
758
+ - **Required for `history://`.** Implement `readEntryRange(id, query)` honoring `fromSeq`, `toSeq`, `maxChars`, `largeEntryBytes`, `skipTypes`, and `signal`. Return freshly owned UTF-8 JSON buffers and `{ entries: [{ seq, entry }], throughSeq, lastSeq }` without falling back to whole-session `load()`.
861
759
  - **Optional fast-path methods.** Implementing these avoids loading entire sessions into memory (stores implementing only `load()` still work with higher memory use):
862
760
 
863
761
  | Method | Purpose |
@@ -870,7 +768,7 @@ Non-SQL backends can implement `openSessionStore` directly (each session has one
870
768
  | `readEntrySizes` / `readEntryChunk` / `readScanPage` | Byte-bounded streaming exports and remote page reads |
871
769
 
872
770
  - **Epochs and indexes.** Keep `epoch` constant on appends, rotate it on `replace` or recreate, and reject mismatched `epoch` writes with `SessionConflictError`. Mark read-only stores `readOnly: true` to skip cleanup writes. Set `estimated: true` on `SessionSummary` when metadata is unindexed.
873
- - **Forks and staging.** `/fork`, `/clone`, and `SessionManager.forkFrom` stream entries in pages (same-store forks copy all branches; cross-store forks copy current context and mark the parent in another store; see [`/tree`, `/fork`, and `/clone`](/sessions#/tree-/fork-and-/clone)). Cross-handle SQL clones stage pages under a 10-minute rolling lease before publishing atomically, and expired staging rows clean up on idle opens, later staged copies, or `atomic storage migrate`.
771
+ - **Forks and cloning.** `/fork`, `/clone`, and `SessionManager.forkFrom` stream entries in pages (same-store forks copy all branches; cross-store forks copy current context and mark the parent in another store; see [`/tree`, `/fork`, and `/clone`](/sessions#tree-fork-and-clone)).
874
772
 
875
773
  ## Storage errors
876
774
 
@@ -897,21 +795,21 @@ Coded storage errors carry a stable `code` and actionable `hint`:
897
795
  | --- | --- | --- | --- | --- |
898
796
  | `StorageWriteLockTimeoutError` (subclass of `StorageUnavailableError`) | `write-lock-timeout` | A node-sqlite transaction waited its full `lockWaitMs` with no commits. Nothing ran. | `adapter`, `location`, `timeoutMs`, `elapsedMs`, `phase` (`"queued"` or `"acquiring"`), `holderPid`/`holderHeldMs` or `holderCandidates`, `retryable: true`, `cause` | Check the holding process or raise `lockWaitMs`, then retry. |
899
797
  | `StorageUnsupportedOperationError` | `unsupported-operation` | `getWriterQueueStats` or `getWriterQueueDegradation` received a non-node-sqlite handle. | `operation`, `adapter`, `location` | Pass a handle from `openNodeSqliteDatabase` or `wrapNodeSqliteDatabase`. |
900
- | `StorageWriterQueueDegradedError` | `writer-queue-degraded` | Recorded once per reason (via `getWriterQueueDegradation` and process warning), never thrown. Covers `watch-unavailable`, `wake-failed`, `stale-ticket-kept`, and `holder-record-unavailable`. | `reason`, `adapter`, `location`, `cause`, `hint` | Raise file-watch limits, fix permissions on `<file>-writers`, `<file>-wakes`, and `<file>-holders`, or remove abandoned entries. |
901
- | `StorageWriterQueueUnusableError` (subclass of `StorageUnavailableError`) | `writer-queue-unusable` | A node-sqlite transaction could not use `<file>-writers` or `<file>-wakes`. Nothing ran. | `adapter`, `location`, `errno`, `cause` | Make `<file>-writers` and `<file>-wakes` readable and writable for all writers. |
798
+ | `StorageWriterQueueDegradedError` | `writer-queue-degraded` | Recorded once per reason (via `getWriterQueueDegradation` and process warning), never thrown. Covers `watch-unavailable`, `wake-failed`, `stale-ticket-kept`, and `holder-record-unavailable`. | `reason`, `adapter`, `location`, `cause`, `hint` | Raise file-watch limits, fix permissions on the writer queue directories beside the database file, or remove abandoned entries. |
799
+ | `StorageWriterQueueUnusableError` (subclass of `StorageUnavailableError`) | `writer-queue-unusable` | A node-sqlite transaction could not use its writer queue directories. Nothing ran. | `adapter`, `location`, `errno`, `cause` | Make the database directory and writer queue directories readable and writable for all writers. |
902
800
  | `StorageTransientError` (subclass of `StorageUnavailableError`) | `stream-expired`, `transaction-timeout`, `connection-refused`, `connection-lost`, `lock-conflict`, `read-only-server` | A temporary server or network failure ended a call (after up to 5 attempts if nothing was written, or immediately if `outcome` is `"unknown"`). | `adapter`, `location`, `outcome` (`"not-applied"` or `"unknown"`), `attempts`, `retryable: true`, `cause`, optional `hop` and `hopFailure` | Check connectivity to the server or named `hop`, then retry. For `"unknown"`, read state back before retrying non-idempotent writes. |
903
801
  | `SessionBlobError` | `blobs-unsupported` | The session store lacks `putBlob` and `getBlob` needed for an import, fork, branch, or `tool-output://` read. | `sessionId`, `adapter` | Use SQLite, libSQL, or PostgreSQL, or implement `putBlob` and `getBlob` on your custom store. |
904
802
  | `SessionBlobError` | `blob-missing` | A `tool-output://<sha256>` blob is missing. Copies, forks, and exports continue without it and emit a warning (or call `onMissingBlob`). | `sessionId`, `hash`, optional `missing` count | Run the tool again to regenerate the output. |
905
803
  | `SessionBlobError` | `blob-incomplete` | A blob record exists, but part of its content is missing. | `sessionId`, `hash`, `bytes` | Run the tool again to regenerate the output. |
906
804
  | `SessionBlobError` | `blob-corrupt` | Imported tool output failed its SHA-256 check. Nothing was written. | `sessionId`, `hash`, `actualHash` | Export the session again from its source. |
907
- | `SessionSpillError` | `spill-read-failed` | `MemorySessionStore` failed to read a released session's spill file under `released-history`. Retryable for `EMFILE`, `ENFILE`, `EAGAIN`, `EBUSY`, and `EINTR`. | `directory`, `sessionId`, `bytes`, `errno`, `cause` | Check directory permissions and file descriptor limits, then reopen the session. |
908
- | `SessionSpillError` | `spill-missing` | A released session's spill file is missing or truncated. History is lost; listings omit it. | `directory`, `sessionId`, `bytes`, optional `foundBytes`, `errno` | Leave `released-history` untouched while Atomic runs, or use a persistent store. |
909
- | `SessionSpillError` | `spill-corrupt` | A spill file failed length, parse, or FNV-1a checksum checks. History is lost; listings omit it. | `directory`, `sessionId`, `bytes`, optional `foundBytes`, optional `cause` | Leave `released-history` untouched while Atomic runs, or use a persistent store. |
805
+ | `SessionSpillError` | `spill-read-failed` | `MemorySessionStore` failed to read a temporary history file under `released-history`. Retryable for `EMFILE`, `ENFILE`, `EAGAIN`, `EBUSY`, and `EINTR`. | `directory`, `sessionId`, `bytes`, `errno`, `cause` | Check directory permissions and file descriptor limits, then reopen the session. |
806
+ | `SessionSpillError` | `spill-missing` | A temporary history file under `released-history` is missing or truncated. History is lost; listings omit it. | `directory`, `sessionId`, `bytes`, optional `foundBytes`, `errno` | Leave `released-history` untouched while Atomic runs, or use a persistent store. |
807
+ | `SessionSpillError` | `spill-corrupt` | A temporary history file failed length, parse, or checksum checks. History is lost; listings omit it. | `directory`, `sessionId`, `bytes`, optional `foundBytes`, optional `cause` | Leave `released-history` untouched while Atomic runs, or use a persistent store. |
910
808
  | `SessionSpillError` | `spill-write-failed`, `spill-dir-refused`, `spill-cleanup-failed` | Recorded once on the store and emitted as a process warning, never thrown. History remains in memory when writes or directory creation fail. | `directory`, optional `sessionId`, optional `bytes`, `errno`, optional `cause` | Free disk space or make the agent directory writable. |
911
809
 
912
810
  ### Error guards, serialization, and session persistence errors
913
811
 
914
- - **Guards.** Each coded error exports a cross-realm guard: `isStorageConfigError`, `isStorageWriteLockTimeoutError`, `isStorageUnsupportedOperationError`, `isStorageWriterQueueDegradedError`, `isStorageWriterQueueUnusableError`, `isStorageTransientError`, `isSessionBlobError`, and `isSessionSpillError`. Constant arrays `STORAGE_TRANSIENT_ERROR_CODES`, `SESSION_BLOB_ERROR_CODES`, and `SESSION_SPILL_ERROR_CODES` list their codes. `isStorageError(error)` matches any storage error above. `findStorageWriteLockTimeoutError(error)` and `isRetryableStorageError(error)` inspect up to eight levels of `cause`.
812
+ - **Guards.** Each coded error exports a cross-realm guard: `isStorageConfigError`, `isStorageWriteLockTimeoutError`, `isStorageUnsupportedOperationError`, `isStorageWriterQueueDegradedError`, `isStorageWriterQueueUnusableError`, `isStorageTransientError`, `isSessionBlobError`, and `isSessionSpillError`. Constant arrays `STORAGE_TRANSIENT_ERROR_CODES`, `SESSION_BLOB_ERROR_CODES`, and `SESSION_SPILL_ERROR_CODES` list their codes. `isStorageError(error)` matches any storage error above. `findStorageWriteLockTimeoutError(error)` and `isRetryableStorageError(error)` inspect up to 8 levels of `cause`.
915
813
  - **Cross-process serialization.** Use `serializeStorageError(error)` and `rehydrateStorageError(json)` to pass storage errors across process boundaries with their class, fields, `cause` chain, `rollbackCause`, and `cleanupCause`. Unknown future error names rehydrate as `StorageError` keeping `name`, `code`, and fields.
916
814
  - **Session store errors.** Session operations can throw `SessionNotFoundError` (`sessionId`), `SessionExistsError` (`sessionId`), `SessionIdMismatchError` (`requested`, `found`), `SessionConflictError` (`sessionId`, `expectedSeq`, `actualSeq`), `SessionFormatVersionError` (`path`, `found`, `supported`), `SessionInvalidTextError` (`field`, `reason`), `SessionInvalidTimestampError` (`field`, `reason`, `value`), and `JsonlStoragePoisonedError` (`location`, `cause`, `rollbackCause`). After a conflict, reopen the session before writing again.
917
815
  - **Save failures during a run.** If a running session cannot save a message, Atomic reports `could not persist the <role> message: <cause>` once and halts that run without starting further model requests, tool calls, retries, fallbacks, or compaction. Print and JSON modes print the error on stderr and exit `1` (print mode still prints the received answer). Interactive mode displays the error, stays open, and retries saving on later prompts.
@@ -919,7 +817,7 @@ Coded storage errors carry a stable `code` and actionable `hint`:
919
817
 
920
818
  ### Team setup errors
921
819
 
922
- `joinTeam()`, `leaveTeam()`, `getTeamProfile()`, `teamProfileSelection()`, `atomic storage join`, `atomic team`, and `ATOMIC_PROFILE=ci` validation throw these classes from `@bastani/atomic/storage`. Cross-process guards `isTeamProfileError()`, `isTeamProfileTimeoutError()`, and `isTeamProfileConfigError()` match by `name` and `code`, and `isRetryableTeamProfileError()` inspects up to eight cause levels. Messages and fields name variables, flags, and files, never token values.
820
+ `joinTeam()`, `leaveTeam()`, `getTeamProfile()`, `teamProfileSelection()`, `atomic storage join`, `atomic team`, and `ATOMIC_PROFILE=ci` validation throw these classes from `@bastani/atomic/storage`. Cross-process guards `isTeamProfileError()`, `isTeamProfileTimeoutError()`, and `isTeamProfileConfigError()` match by `name` and `code`, and `isRetryableTeamProfileError()` inspects up to 8 cause levels. Messages and fields name variables, flags, and files, never token values.
923
821
 
924
822
  `TeamProfileConfigError` extends `StorageConfigError` (`source`: `"sdk"`, `"cli"`, or `"env"`, `field`, `code`, `reason`, `hint`, optional `path` and `missing`, `retryable: false`). Nothing changes when it is thrown:
925
823
 
@@ -928,7 +826,7 @@ Coded storage errors carry a stable `code` and actionable `hint`:
928
826
  | `unknown-profile` | `ATOMIC_PROFILE` or SDK `profile` is not `ci` |
929
827
  | `incomplete-profile` | A team variable is set without `ATOMIC_PROFILE`, or `ATOMIC_PROFILE=ci` lacks a URL or token (`missing` lists all missing variables) |
930
828
  | `missing-url` | No database URL was passed |
931
- | `unsupported-url` | URL is not `libsql://`, `https://`, `wss://`, or `file:` |
829
+ | `unsupported-url` | URL is not `libsql://`, `https://`, `http://`, `wss://`, `ws://`, or `file:` |
932
830
  | `relative-file-url` | A `file:` URL is relative |
933
831
  | `credential-in-url` | URL contains a username, password, or `authToken` |
934
832
  | `missing-token` | Non-`file:` URL has no token, or `tokenEnv` names an unset variable |
@@ -953,13 +851,13 @@ Coded storage errors carry a stable `code` and actionable `hint`:
953
851
  | `broker-restart-failed` | Returned in `broker`, not thrown: settings saved, but Intercom broker failed to restart (`retryable: true`). | Run `atomic intercom restart`. |
954
852
  | `token-delete-failed` | `leaveTeam` removed settings, but could not delete the token file. | Delete the file manually. |
955
853
 
956
- `SHARED_STORAGE_JOIN_HINT` exports the canonical hint string `atomic team join <url> --token-file <path>`. Use `serializeTeamError(error)` and `rehydrateTeamError(json)` to preserve team error classes, fields, and up to eight cause levels across processes without leaking credentials (non-team causes keep only `name` and `code`).
854
+ `SHARED_STORAGE_JOIN_HINT` exports the canonical hint string `atomic team join <url> --token-file <path>`. Use `serializeTeamError(error)` and `rehydrateTeamError(json)` to preserve team error classes, fields, and up to 8 cause levels across processes without leaking credentials (non-team causes keep only `name` and `code`).
957
855
 
958
856
  ## Adapter conformance
959
857
 
960
858
  Validate any `SqliteDatabase` adapter against the conformance suites exported from `@bastani/atomic/storage/testing`:
961
859
 
962
- ```ts
860
+ ```typescript
963
861
  import {
964
862
  registerSqliteConnectionConformance,
965
863
  registerSqliteDatabaseConformance,
@@ -975,6 +873,6 @@ registerSqliteConnectionConformance({ describe, it }, "my adapter connections",
975
873
 
976
874
  Helper utilities exported from `@bastani/atomic/storage` for custom adapters:
977
875
 
978
- - `validateStoragePrefix(prefix, dialect?)` validates optional table prefixes (ASCII letters, digits, and `_`, not starting with `sqlite_`). Passing `"postgres"` also enforces lowercase and `POSTGRES_MAX_STORAGE_PREFIX_LENGTH` (24).
876
+ - `validateStoragePrefix(prefix, dialect?)` validates optional table prefixes (ASCII letters, digits, and `_`, not starting with `sqlite_`, case-insensitively). Passing `"postgres"` also enforces lowercase and `POSTGRES_MAX_STORAGE_PREFIX_LENGTH` (24).
979
877
  - `renderStorageIdentifiers("sessions", names, prefix)` returns a frozen map of table names with the `session_` prefix applied.
980
878
  - `assertStorageSchemaVersion(domain, found, supported)` throws `StorageSchemaVersionError` when stored and supported versions differ.