@bastani/atomic 0.9.38-alpha.5 → 0.9.38-alpha.7

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 (484) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +8 -6
  3. package/dist/builtin/intercom/CHANGELOG.md +9 -0
  4. package/dist/builtin/intercom/broker/broker.ts +6 -4
  5. package/dist/builtin/intercom/broker/delivered-message-cache.ts +50 -4
  6. package/dist/builtin/intercom/broker/send-handler.ts +6 -4
  7. package/dist/builtin/intercom/index.bundle.mjs +78 -33
  8. package/dist/builtin/intercom/package.json +2 -2
  9. package/dist/builtin/mcp/package.json +1 -1
  10. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  11. package/dist/builtin/subagents/package.json +3 -3
  12. package/dist/builtin/subagents/src/extension/index.bundle.mjs +140 -145
  13. package/dist/builtin/web-access/CHANGELOG.md +7 -0
  14. package/dist/builtin/web-access/index.bundle.mjs +53 -15
  15. package/dist/builtin/web-access/package.json +2 -2
  16. package/dist/builtin/workflows/CHANGELOG.md +48 -0
  17. package/dist/builtin/workflows/builtin/{chunk-q7dx7kh7.js → chunk-85mx6wcf.js} +6 -6
  18. package/dist/builtin/workflows/builtin/{chunk-xg7kkgf8.js → chunk-8kkv04hz.js} +15 -15
  19. package/dist/builtin/workflows/builtin/{chunk-na3wpwzh.js → chunk-8x61e0s7.js} +396 -363
  20. package/dist/builtin/workflows/builtin/{chunk-qrrkfg9v.js → chunk-y45tkftg.js} +7 -7
  21. package/dist/builtin/workflows/builtin/goal.js +2 -2
  22. package/dist/builtin/workflows/builtin/index.js +4 -4
  23. package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
  24. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  25. package/dist/builtin/workflows/package.json +2 -2
  26. package/dist/builtin/workflows/src/authoring.d.ts +3 -8
  27. package/dist/builtin/workflows/src/durable/journal/conformance.d.ts +9 -1
  28. package/dist/builtin/workflows/src/durable/journal/internal.d.ts +1 -0
  29. package/dist/builtin/workflows/src/durable/journal/lease-expiry.d.ts +2 -0
  30. package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +9 -1
  31. package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +19 -8
  32. package/dist/builtin/workflows/src/durable/journal/sql-run-journal.d.ts +45 -0
  33. package/dist/builtin/workflows/src/durable/journal/sqlite-run-journal.d.ts +5 -47
  34. package/dist/builtin/workflows/src/durable/journal/types.d.ts +9 -114
  35. package/dist/builtin/workflows/src/durable/journal/values.d.ts +2 -0
  36. package/dist/builtin/workflows/src/extension/index.bundle.mjs +6963 -6181
  37. package/dist/builtin/workflows/src/index.js +9078 -8395
  38. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +8 -8
  39. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +0 -14
  40. package/dist/cli/args.d.ts +3 -0
  41. package/dist/cli/args.d.ts.map +1 -1
  42. package/dist/cli/args.js +35 -5
  43. package/dist/cli/args.js.map +1 -1
  44. package/dist/cli/session-picker.d.ts +2 -2
  45. package/dist/cli/session-picker.d.ts.map +1 -1
  46. package/dist/cli/session-picker.js +5 -5
  47. package/dist/cli/session-picker.js.map +1 -1
  48. package/dist/core/agent-session-auto-compaction.d.ts +1 -1
  49. package/dist/core/agent-session-auto-compaction.d.ts.map +1 -1
  50. package/dist/core/agent-session-auto-compaction.js +2 -2
  51. package/dist/core/agent-session-auto-compaction.js.map +1 -1
  52. package/dist/core/agent-session-bash.d.ts +2 -3
  53. package/dist/core/agent-session-bash.d.ts.map +1 -1
  54. package/dist/core/agent-session-bash.js +18 -10
  55. package/dist/core/agent-session-bash.js.map +1 -1
  56. package/dist/core/agent-session-boundaries.d.ts +6 -6
  57. package/dist/core/agent-session-boundaries.d.ts.map +1 -1
  58. package/dist/core/agent-session-boundaries.js +22 -22
  59. package/dist/core/agent-session-boundaries.js.map +1 -1
  60. package/dist/core/agent-session-compaction.js +2 -2
  61. package/dist/core/agent-session-compaction.js.map +1 -1
  62. package/dist/core/agent-session-custom-message-commit.d.ts.map +1 -1
  63. package/dist/core/agent-session-custom-message-commit.js +10 -12
  64. package/dist/core/agent-session-custom-message-commit.js.map +1 -1
  65. package/dist/core/agent-session-events.d.ts.map +1 -1
  66. package/dist/core/agent-session-events.js +26 -14
  67. package/dist/core/agent-session-events.js.map +1 -1
  68. package/dist/core/agent-session-export.js +1 -1
  69. package/dist/core/agent-session-export.js.map +1 -1
  70. package/dist/core/agent-session-extension-bindings.d.ts +2 -2
  71. package/dist/core/agent-session-extension-bindings.d.ts.map +1 -1
  72. package/dist/core/agent-session-extension-bindings.js +75 -59
  73. package/dist/core/agent-session-extension-bindings.js.map +1 -1
  74. package/dist/core/agent-session-message-queue.d.ts +2 -2
  75. package/dist/core/agent-session-message-queue.d.ts.map +1 -1
  76. package/dist/core/agent-session-message-queue.js +17 -8
  77. package/dist/core/agent-session-message-queue.js.map +1 -1
  78. package/dist/core/agent-session-methods.d.ts +15 -15
  79. package/dist/core/agent-session-methods.d.ts.map +1 -1
  80. package/dist/core/agent-session-methods.js.map +1 -1
  81. package/dist/core/agent-session-models.d.ts +2 -2
  82. package/dist/core/agent-session-models.d.ts.map +1 -1
  83. package/dist/core/agent-session-models.js +59 -42
  84. package/dist/core/agent-session-models.js.map +1 -1
  85. package/dist/core/agent-session-persistent-custom-messages.d.ts +4 -4
  86. package/dist/core/agent-session-persistent-custom-messages.d.ts.map +1 -1
  87. package/dist/core/agent-session-persistent-custom-messages.js +16 -17
  88. package/dist/core/agent-session-persistent-custom-messages.js.map +1 -1
  89. package/dist/core/agent-session-prompt.d.ts.map +1 -1
  90. package/dist/core/agent-session-prompt.js +6 -8
  91. package/dist/core/agent-session-prompt.js.map +1 -1
  92. package/dist/core/agent-session-retry.d.ts.map +1 -1
  93. package/dist/core/agent-session-retry.js +17 -15
  94. package/dist/core/agent-session-retry.js.map +1 -1
  95. package/dist/core/agent-session-runtime.d.ts +7 -8
  96. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  97. package/dist/core/agent-session-runtime.js +88 -100
  98. package/dist/core/agent-session-runtime.js.map +1 -1
  99. package/dist/core/agent-session-services.d.ts +1 -1
  100. package/dist/core/agent-session-services.d.ts.map +1 -1
  101. package/dist/core/agent-session-services.js +2 -2
  102. package/dist/core/agent-session-services.js.map +1 -1
  103. package/dist/core/agent-session-summary.js +1 -1
  104. package/dist/core/agent-session-summary.js.map +1 -1
  105. package/dist/core/agent-session-tree.d.ts +1 -1
  106. package/dist/core/agent-session-tree.d.ts.map +1 -1
  107. package/dist/core/agent-session-tree.js +7 -7
  108. package/dist/core/agent-session-tree.js.map +1 -1
  109. package/dist/core/cache-warmer.js +1 -1
  110. package/dist/core/cache-warmer.js.map +1 -1
  111. package/dist/core/compaction/branch-summarization.d.ts +1 -4
  112. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  113. package/dist/core/compaction/branch-summarization.js +0 -4
  114. package/dist/core/compaction/branch-summarization.js.map +1 -1
  115. package/dist/core/compaction/pi-summary-fallback.d.ts.map +1 -1
  116. package/dist/core/compaction/pi-summary-fallback.js +1 -3
  117. package/dist/core/compaction/pi-summary-fallback.js.map +1 -1
  118. package/dist/core/export-html/index.js +1 -1
  119. package/dist/core/export-html/index.js.map +1 -1
  120. package/dist/core/export-html/template-js/entries-navigation.js +1 -1
  121. package/dist/core/export-html/template.js +1 -1
  122. package/dist/core/extensions/api-types.d.ts +12 -12
  123. package/dist/core/extensions/api-types.d.ts.map +1 -1
  124. package/dist/core/extensions/api-types.js.map +1 -1
  125. package/dist/core/extensions/context-types.d.ts +4 -2
  126. package/dist/core/extensions/context-types.d.ts.map +1 -1
  127. package/dist/core/extensions/context-types.js.map +1 -1
  128. package/dist/core/extensions/extension-work.d.ts +1 -0
  129. package/dist/core/extensions/extension-work.d.ts.map +1 -1
  130. package/dist/core/extensions/extension-work.js +5 -1
  131. package/dist/core/extensions/extension-work.js.map +1 -1
  132. package/dist/core/extensions/loader-api.d.ts.map +1 -1
  133. package/dist/core/extensions/loader-api.js +40 -42
  134. package/dist/core/extensions/loader-api.js.map +1 -1
  135. package/dist/core/extensions/loader-host-modules.d.ts +1 -1
  136. package/dist/core/extensions/loader-host-modules.d.ts.map +1 -1
  137. package/dist/core/extensions/loader-host-modules.js +6 -2
  138. package/dist/core/extensions/loader-host-modules.js.map +1 -1
  139. package/dist/core/extensions/loader-rollback.d.ts.map +1 -1
  140. package/dist/core/extensions/loader-rollback.js +1 -0
  141. package/dist/core/extensions/loader-rollback.js.map +1 -1
  142. package/dist/core/extensions/loader-virtual-modules.d.ts.map +1 -1
  143. package/dist/core/extensions/loader-virtual-modules.js +1 -0
  144. package/dist/core/extensions/loader-virtual-modules.js.map +1 -1
  145. package/dist/core/extensions/runner-context.d.ts +1 -0
  146. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  147. package/dist/core/extensions/runner-context.js +10 -3
  148. package/dist/core/extensions/runner-context.js.map +1 -1
  149. package/dist/core/extensions/runner-handlers.d.ts +1 -1
  150. package/dist/core/extensions/runner-handlers.d.ts.map +1 -1
  151. package/dist/core/extensions/runner-handlers.js.map +1 -1
  152. package/dist/core/extensions/runner.d.ts +3 -2
  153. package/dist/core/extensions/runner.d.ts.map +1 -1
  154. package/dist/core/extensions/runner.js +20 -12
  155. package/dist/core/extensions/runner.js.map +1 -1
  156. package/dist/core/extensions/runtime-types.d.ts +7 -7
  157. package/dist/core/extensions/runtime-types.d.ts.map +1 -1
  158. package/dist/core/extensions/runtime-types.js.map +1 -1
  159. package/dist/core/extensions/session-events.d.ts +5 -5
  160. package/dist/core/extensions/session-events.d.ts.map +1 -1
  161. package/dist/core/extensions/session-events.js.map +1 -1
  162. package/dist/core/fast-model-routing.d.ts.map +1 -1
  163. package/dist/core/fast-model-routing.js +1 -0
  164. package/dist/core/fast-model-routing.js.map +1 -1
  165. package/dist/core/intercom-runtime-group.js +1 -1
  166. package/dist/core/intercom-runtime-group.js.map +1 -1
  167. package/dist/core/model-config.d.ts +765 -0
  168. package/dist/core/model-config.d.ts.map +1 -1
  169. package/dist/core/model-config.js +46 -24
  170. package/dist/core/model-config.js.map +1 -1
  171. package/dist/core/model-resolver-defaults.js +1 -1
  172. package/dist/core/model-resolver-defaults.js.map +1 -1
  173. package/dist/core/provider-attribution.js +1 -1
  174. package/dist/core/provider-attribution.js.map +1 -1
  175. package/dist/core/resource-loader-reload.js +1 -1
  176. package/dist/core/resource-loader-reload.js.map +1 -1
  177. package/dist/core/resource-loader-types.d.ts +1 -1
  178. package/dist/core/resource-loader-types.d.ts.map +1 -1
  179. package/dist/core/resource-loader-types.js.map +1 -1
  180. package/dist/core/sdk-types.d.ts +4 -0
  181. package/dist/core/sdk-types.d.ts.map +1 -1
  182. package/dist/core/sdk-types.js.map +1 -1
  183. package/dist/core/sdk.d.ts +1 -1
  184. package/dist/core/sdk.d.ts.map +1 -1
  185. package/dist/core/sdk.js +50 -20
  186. package/dist/core/sdk.js.map +1 -1
  187. package/dist/core/session-lifecycle-work.d.ts +3 -0
  188. package/dist/core/session-lifecycle-work.d.ts.map +1 -1
  189. package/dist/core/session-lifecycle-work.js +2 -0
  190. package/dist/core/session-lifecycle-work.js.map +1 -1
  191. package/dist/core/session-manager-archive.d.ts +2 -16
  192. package/dist/core/session-manager-archive.d.ts.map +1 -1
  193. package/dist/core/session-manager-archive.js +8 -104
  194. package/dist/core/session-manager-archive.js.map +1 -1
  195. package/dist/core/session-manager-core.d.ts +53 -51
  196. package/dist/core/session-manager-core.d.ts.map +1 -1
  197. package/dist/core/session-manager-core.js +547 -307
  198. package/dist/core/session-manager-core.js.map +1 -1
  199. package/dist/core/session-manager-entries.d.ts.map +1 -1
  200. package/dist/core/session-manager-entries.js +5 -10
  201. package/dist/core/session-manager-entries.js.map +1 -1
  202. package/dist/core/session-manager-errors.d.ts +10 -0
  203. package/dist/core/session-manager-errors.d.ts.map +1 -0
  204. package/dist/core/session-manager-errors.js +27 -0
  205. package/dist/core/session-manager-errors.js.map +1 -0
  206. package/dist/core/session-manager-list.d.ts +1 -0
  207. package/dist/core/session-manager-list.d.ts.map +1 -1
  208. package/dist/core/session-manager-list.js +21 -14
  209. package/dist/core/session-manager-list.js.map +1 -1
  210. package/dist/core/session-manager-storage.d.ts +3 -13
  211. package/dist/core/session-manager-storage.d.ts.map +1 -1
  212. package/dist/core/session-manager-storage.js +28 -69
  213. package/dist/core/session-manager-storage.js.map +1 -1
  214. package/dist/core/session-manager-types.d.ts +3 -11
  215. package/dist/core/session-manager-types.d.ts.map +1 -1
  216. package/dist/core/session-manager-types.js.map +1 -1
  217. package/dist/core/session-manager-validation.d.ts.map +1 -1
  218. package/dist/core/session-manager-validation.js +3 -2
  219. package/dist/core/session-manager-validation.js.map +1 -1
  220. package/dist/core/session-manager.d.ts +2 -1
  221. package/dist/core/session-manager.d.ts.map +1 -1
  222. package/dist/core/session-manager.js +2 -1
  223. package/dist/core/session-manager.js.map +1 -1
  224. package/dist/core/session-mutation-queue.d.ts +3 -0
  225. package/dist/core/session-mutation-queue.d.ts.map +1 -0
  226. package/dist/core/session-mutation-queue.js +14 -0
  227. package/dist/core/session-mutation-queue.js.map +1 -0
  228. package/dist/core/session-resume-args.d.ts +4 -0
  229. package/dist/core/session-resume-args.d.ts.map +1 -0
  230. package/dist/core/session-resume-args.js +9 -0
  231. package/dist/core/session-resume-args.js.map +1 -0
  232. package/dist/core/session-storage.d.ts +26 -0
  233. package/dist/core/session-storage.d.ts.map +1 -0
  234. package/dist/core/session-storage.js +155 -0
  235. package/dist/core/session-storage.js.map +1 -0
  236. package/dist/core/session-store-list.d.ts +4 -0
  237. package/dist/core/session-store-list.d.ts.map +1 -0
  238. package/dist/core/session-store-list.js +28 -0
  239. package/dist/core/session-store-list.js.map +1 -0
  240. package/dist/core/settings-manager-basic-accessors.d.ts +0 -1
  241. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  242. package/dist/core/settings-manager-basic-accessors.js +0 -5
  243. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  244. package/dist/core/settings-merge.d.ts.map +1 -1
  245. package/dist/core/settings-merge.js +8 -2
  246. package/dist/core/settings-merge.js.map +1 -1
  247. package/dist/core/settings-schema.d.ts +74 -8
  248. package/dist/core/settings-schema.d.ts.map +1 -1
  249. package/dist/core/settings-schema.js +29 -29
  250. package/dist/core/settings-schema.js.map +1 -1
  251. package/dist/core/storage/errors.d.ts +1 -0
  252. package/dist/core/storage/errors.d.ts.map +1 -1
  253. package/dist/core/storage/errors.js.map +1 -1
  254. package/dist/core/storage/index.d.ts +5 -1
  255. package/dist/core/storage/index.d.ts.map +1 -1
  256. package/dist/core/storage/index.js +4 -1
  257. package/dist/core/storage/index.js.map +1 -1
  258. package/dist/core/storage/node-sqlite.d.ts +2 -0
  259. package/dist/core/storage/node-sqlite.d.ts.map +1 -1
  260. package/dist/core/storage/node-sqlite.js +47 -6
  261. package/dist/core/storage/node-sqlite.js.map +1 -1
  262. package/dist/core/storage/provider.d.ts +58 -0
  263. package/dist/core/storage/provider.d.ts.map +1 -0
  264. package/dist/core/storage/provider.js +243 -0
  265. package/dist/core/storage/provider.js.map +1 -0
  266. package/dist/core/storage/run-journal.d.ts +93 -0
  267. package/dist/core/storage/run-journal.d.ts.map +1 -0
  268. package/dist/core/storage/run-journal.js +15 -0
  269. package/dist/core/storage/run-journal.js.map +1 -0
  270. package/dist/core/storage/selection.d.ts +16 -0
  271. package/dist/core/storage/selection.d.ts.map +1 -0
  272. package/dist/core/storage/selection.js +87 -0
  273. package/dist/core/storage/selection.js.map +1 -0
  274. package/dist/core/storage/session/jsonl-session-store.d.ts +11 -2
  275. package/dist/core/storage/session/jsonl-session-store.d.ts.map +1 -1
  276. package/dist/core/storage/session/jsonl-session-store.js +127 -54
  277. package/dist/core/storage/session/jsonl-session-store.js.map +1 -1
  278. package/dist/core/storage/session/legacy-format.d.ts +18 -0
  279. package/dist/core/storage/session/legacy-format.d.ts.map +1 -0
  280. package/dist/core/storage/session/legacy-format.js +63 -0
  281. package/dist/core/storage/session/legacy-format.js.map +1 -0
  282. package/dist/core/storage/session/memory-session-store.d.ts +3 -1
  283. package/dist/core/storage/session/memory-session-store.d.ts.map +1 -1
  284. package/dist/core/storage/session/memory-session-store.js +9 -2
  285. package/dist/core/storage/session/memory-session-store.js.map +1 -1
  286. package/dist/core/storage/session/sql-session-store.d.ts +4 -1
  287. package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
  288. package/dist/core/storage/session/sql-session-store.js +25 -6
  289. package/dist/core/storage/session/sql-session-store.js.map +1 -1
  290. package/dist/core/storage/session/types.d.ts +4 -0
  291. package/dist/core/storage/session/types.d.ts.map +1 -1
  292. package/dist/core/storage/session/types.js.map +1 -1
  293. package/dist/core/storage/session/validation.js +1 -1
  294. package/dist/core/storage/session/validation.js.map +1 -1
  295. package/dist/core/storage/testing.d.ts +2 -0
  296. package/dist/core/storage/testing.d.ts.map +1 -1
  297. package/dist/core/storage/testing.js +45 -0
  298. package/dist/core/storage/testing.js.map +1 -1
  299. package/dist/core/tasks/completion.d.ts.map +1 -1
  300. package/dist/core/tasks/completion.js +2 -4
  301. package/dist/core/tasks/completion.js.map +1 -1
  302. package/dist/core/tools/bash-session-environment.d.ts.map +1 -1
  303. package/dist/core/tools/bash-session-environment.js +0 -2
  304. package/dist/core/tools/bash-session-environment.js.map +1 -1
  305. package/dist/core/tools/read-url.d.ts.map +1 -1
  306. package/dist/core/tools/read-url.js +6 -1
  307. package/dist/core/tools/read-url.js.map +1 -1
  308. package/dist/core/tools/todos-model.js +3 -3
  309. package/dist/core/tools/todos-model.js.map +1 -1
  310. package/dist/core/tools/todos-mutations.js +2 -2
  311. package/dist/core/tools/todos-mutations.js.map +1 -1
  312. package/dist/core/tools/todos-render.js +1 -1
  313. package/dist/core/tools/todos-render.js.map +1 -1
  314. package/dist/core/tools/todos-storage.js +2 -2
  315. package/dist/core/tools/todos-storage.js.map +1 -1
  316. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  317. package/dist/extensions/codemode/execute.js +14 -1
  318. package/dist/extensions/codemode/execute.js.map +1 -1
  319. package/dist/extensions/codemode/tool.d.ts +1 -1
  320. package/dist/extensions/codemode/tool.d.ts.map +1 -1
  321. package/dist/extensions/codemode/tool.js.map +1 -1
  322. package/dist/extensions/herdr/index.d.ts.map +1 -1
  323. package/dist/extensions/herdr/index.js +6 -8
  324. package/dist/extensions/herdr/index.js.map +1 -1
  325. package/dist/extensions/mcp/index.js +1 -1
  326. package/dist/extensions/mcp/index.js.map +1 -1
  327. package/dist/extensions/mcp/tools.d.ts.map +1 -1
  328. package/dist/extensions/mcp/tools.js +6 -1
  329. package/dist/extensions/mcp/tools.js.map +1 -1
  330. package/dist/index.d.ts +3 -1
  331. package/dist/index.d.ts.map +1 -1
  332. package/dist/index.js +3 -1
  333. package/dist/index.js.map +1 -1
  334. package/dist/main-session.d.ts +12 -2
  335. package/dist/main-session.d.ts.map +1 -1
  336. package/dist/main-session.js +148 -53
  337. package/dist/main-session.js.map +1 -1
  338. package/dist/main.d.ts.map +1 -1
  339. package/dist/main.js +97 -42
  340. package/dist/main.js.map +1 -1
  341. package/dist/modes/interactive/components/chat-session-host.d.ts +3 -1
  342. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  343. package/dist/modes/interactive/components/chat-session-host.js +16 -7
  344. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  345. package/dist/modes/interactive/components/extension-input.d.ts +1 -1
  346. package/dist/modes/interactive/components/extension-input.d.ts.map +1 -1
  347. package/dist/modes/interactive/components/extension-input.js +2 -2
  348. package/dist/modes/interactive/components/extension-input.js.map +1 -1
  349. package/dist/modes/interactive/components/host-session-picker.js +1 -1
  350. package/dist/modes/interactive/components/host-session-picker.js.map +1 -1
  351. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  352. package/dist/modes/interactive/components/scoped-models-selector.js +4 -1
  353. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  354. package/dist/modes/interactive/components/session-selector-delete.d.ts +1 -1
  355. package/dist/modes/interactive/components/session-selector-delete.d.ts.map +1 -1
  356. package/dist/modes/interactive/components/session-selector-delete.js.map +1 -1
  357. package/dist/modes/interactive/components/session-selector-list.d.ts +12 -9
  358. package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
  359. package/dist/modes/interactive/components/session-selector-list.js +27 -25
  360. package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
  361. package/dist/modes/interactive/components/session-selector.d.ts +8 -4
  362. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  363. package/dist/modes/interactive/components/session-selector.js +27 -18
  364. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  365. package/dist/modes/interactive/components/tree-selector-component.d.ts +5 -1
  366. package/dist/modes/interactive/components/tree-selector-component.d.ts.map +1 -1
  367. package/dist/modes/interactive/components/tree-selector-component.js +20 -3
  368. package/dist/modes/interactive/components/tree-selector-component.js.map +1 -1
  369. package/dist/modes/interactive/interactive-bash-compact.js +1 -1
  370. package/dist/modes/interactive/interactive-bash-compact.js.map +1 -1
  371. package/dist/modes/interactive/interactive-deferred-startup.js +2 -2
  372. package/dist/modes/interactive/interactive-deferred-startup.js.map +1 -1
  373. package/dist/modes/interactive/interactive-editor-actions.js +2 -2
  374. package/dist/modes/interactive/interactive-editor-actions.js.map +1 -1
  375. package/dist/modes/interactive/interactive-extension-runtime.js +2 -0
  376. package/dist/modes/interactive/interactive-extension-runtime.js.map +1 -1
  377. package/dist/modes/interactive/interactive-input-handling.js +6 -4
  378. package/dist/modes/interactive/interactive-input-handling.js.map +1 -1
  379. package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
  380. package/dist/modes/interactive/interactive-mode-helpers.js +7 -3
  381. package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
  382. package/dist/modes/interactive/interactive-mode-surface.d.ts +5 -5
  383. package/dist/modes/interactive/interactive-mode-surface.d.ts.map +1 -1
  384. package/dist/modes/interactive/interactive-mode-surface.js.map +1 -1
  385. package/dist/modes/interactive/interactive-model-routing.js +12 -7
  386. package/dist/modes/interactive/interactive-model-routing.js.map +1 -1
  387. package/dist/modes/interactive/interactive-selectors.js +2 -2
  388. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  389. package/dist/modes/interactive/interactive-session-routing.js +38 -14
  390. package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
  391. package/dist/modes/interactive/interactive-slash-commands.js +5 -3
  392. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  393. package/dist/modes/interactive-engine/create-isolated-runtime.d.ts.map +1 -1
  394. package/dist/modes/interactive-engine/create-isolated-runtime.js +8 -1
  395. package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
  396. package/dist/modes/interactive-engine/engine-args.d.ts.map +1 -1
  397. package/dist/modes/interactive-engine/engine-args.js +11 -4
  398. package/dist/modes/interactive-engine/engine-args.js.map +1 -1
  399. package/dist/modes/interactive-engine/isolated-runtime.d.ts +1 -1
  400. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  401. package/dist/modes/interactive-engine/isolated-runtime.js +99 -74
  402. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  403. package/dist/modes/rpc/rpc-bash-request-owners.js +1 -1
  404. package/dist/modes/rpc/rpc-bash-request-owners.js.map +1 -1
  405. package/dist/modes/rpc/rpc-client-api.d.ts +1 -1
  406. package/dist/modes/rpc/rpc-client-api.d.ts.map +1 -1
  407. package/dist/modes/rpc/rpc-client-api.js +2 -2
  408. package/dist/modes/rpc/rpc-client-api.js.map +1 -1
  409. package/dist/modes/rpc/rpc-client-process.d.ts +2 -2
  410. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  411. package/dist/modes/rpc/rpc-client-process.js +20 -7
  412. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  413. package/dist/modes/rpc/rpc-client.d.ts +4 -1
  414. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  415. package/dist/modes/rpc/rpc-client.js +6 -2
  416. package/dist/modes/rpc/rpc-client.js.map +1 -1
  417. package/dist/modes/rpc/rpc-command-handler.d.ts.map +1 -1
  418. package/dist/modes/rpc/rpc-command-handler.js +12 -9
  419. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  420. package/dist/modes/rpc/rpc-provider-auth.js +2 -2
  421. package/dist/modes/rpc/rpc-provider-auth.js.map +1 -1
  422. package/dist/modes/rpc/rpc-terminal-drain.d.ts.map +1 -1
  423. package/dist/modes/rpc/rpc-terminal-drain.js +11 -2
  424. package/dist/modes/rpc/rpc-terminal-drain.js.map +1 -1
  425. package/dist/modes/rpc/rpc-types.d.ts +6 -2
  426. package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
  427. package/dist/modes/rpc/rpc-types.js.map +1 -1
  428. package/dist/utils/canonical-path.d.ts +5 -0
  429. package/dist/utils/canonical-path.d.ts.map +1 -0
  430. package/dist/utils/canonical-path.js +26 -0
  431. package/dist/utils/canonical-path.js.map +1 -0
  432. package/dist/utils/paths.d.ts +1 -7
  433. package/dist/utils/paths.d.ts.map +1 -1
  434. package/dist/utils/paths.js +1 -15
  435. package/dist/utils/paths.js.map +1 -1
  436. package/docs/codemode.md +2 -0
  437. package/docs/compaction.md +2 -2
  438. package/docs/custom-provider/oauth.md +2 -2
  439. package/docs/custom-provider/override.md +3 -3
  440. package/docs/custom-provider/registration.md +7 -7
  441. package/docs/custom-provider/streaming.md +1 -1
  442. package/docs/custom-provider.md +5 -5
  443. package/docs/docs.json +1 -0
  444. package/docs/environment-variables.md +10 -2
  445. package/docs/extensions/api-reference.md +40 -19
  446. package/docs/extensions/authoring.md +1 -1
  447. package/docs/extensions/events.md +8 -8
  448. package/docs/extensions.md +2 -2
  449. package/docs/getting-started/installation.md +1 -2
  450. package/docs/models/reference.md +2 -0
  451. package/docs/models-configuration.md +206 -0
  452. package/docs/models.md +11 -1
  453. package/docs/providers.md +4 -4
  454. package/docs/quickstart.md +2 -1
  455. package/docs/reference/cli.md +7 -3
  456. package/docs/rpc/protocol.md +10 -4
  457. package/docs/sdk/reference.md +15 -13
  458. package/docs/sdk/web-server.md +5 -6
  459. package/docs/sdk.md +56 -2
  460. package/docs/session-format.md +35 -28
  461. package/docs/sessions.md +50 -17
  462. package/docs/settings.md +44 -7
  463. package/docs/storage.md +346 -2
  464. package/docs/usage.md +3 -2
  465. package/docs/workflows/api-reference.md +80 -16
  466. package/docs/workflows/operations.md +6 -4
  467. package/docs/workflows/reliable-design.md +16 -16
  468. package/examples/extensions/bookmark.ts +2 -2
  469. package/examples/extensions/handoff.ts +2 -2
  470. package/examples/extensions/plan-mode/index.ts +15 -13
  471. package/examples/extensions/preset.ts +8 -8
  472. package/examples/extensions/session-name.ts +1 -1
  473. package/examples/extensions/snake.ts +3 -1
  474. package/examples/extensions/space-invaders.ts +3 -1
  475. package/examples/extensions/tic-tac-toe.ts +80 -80
  476. package/examples/sdk/11-sessions.ts +5 -5
  477. package/examples/sdk/13-session-runtime.ts +7 -7
  478. package/examples/sdk/README.md +1 -1
  479. package/npm-shrinkwrap.json +53 -53
  480. package/package.json +7 -6
  481. package/schemas/models.schema.json +62 -29
  482. package/schemas/settings.schema.json +137 -53
  483. package/dist/builtin/workflows/builtin/chunk-h5fn47y5.js +0 -8
  484. package/dist/builtin/workflows/src/durable/journal/node-sqlite.d.ts +0 -20
package/docs/storage.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # SQLite storage API
2
2
 
3
- The SDK exposes an async SQLite API from `@bastani/atomic` and `@bastani/atomic/storage`. It does not change where Atomic stores sessions or workflow runs.
3
+ The SDK exposes an async SQLite API from `@bastani/atomic` and `@bastani/atomic/storage`. Sessions and workflow runs default to one local file, `~/.atomic/workflows/journal.sqlite`, with `session_` and `wf_` table prefixes. Use [storage settings](/settings#sessions) to choose a different file, explicit JSONL sessions, explicit memory, or an adapter module. A failed persistent store never falls back to memory.
4
+
5
+ For CLI storage selection and resume commands, see [Choosing a store](/sessions#choosing-a-store).
4
6
 
5
7
  ```ts
6
8
  import { openNodeSqliteDatabase } from "@bastani/atomic/storage";
@@ -21,12 +23,352 @@ try {
21
23
 
22
24
  The node adapter creates parent directories and enables WAL, full synchronization, and foreign keys. Its busy timeout defaults to 5000 ms; override it with `openNodeSqliteDatabase(path, { busyTimeoutMs: 1000 })`. Use `:memory:` for an ephemeral database.
23
25
 
26
+ Transactions from separate `openNodeSqliteDatabase` connections to the same file queue asynchronously within one process; symlink paths refer to the same queue. Separate in-memory databases remain independent. SQLite locking and the busy timeout still govern contention from other processes. Wrap a caller-owned connection consistently: its transaction queue is shared by wrappers of that connection, not by other connections to its file.
27
+
28
+ Use `wrapNodeSqliteDatabase(connection)` to adapt an existing `node:sqlite` `DatabaseSync`. Closing that facade drains its accepted work but leaves your connection open. Route concurrent work through the same facade rather than issuing raw connection commands while a facade transaction is active.
29
+
24
30
  Use only the supplied transaction handle inside a transaction callback. Calling the database itself there waits behind the transaction and deadlocks. Keep callbacks short and await only handle operations. A rejected callback rolls back and preserves the rejection. A failed commit rolls back and rejects with `StorageUnavailableError`. Handles expire after their callbacks settle. Other database operations execute in call order. `close()` drains accepted work, releases the database files, and is idempotent; new calls after closing begins reject with `StoreClosedError`.
25
31
 
26
32
  Errors are exported classes with typed fields. `StorageUnavailableError` provides `adapter`, `location`, and `cause`; stop using the affected store after this error. `StorageRollbackError` retains the original `cause` and `rollbackCause` when rollback also fails. Do not assume that transaction rolled back. Branch on error classes rather than message text.
27
33
 
28
34
  String bindings containing U+0000 are rejected before SQL executes with `StorageInvalidTextError`. Its `parameterIndex` is zero-based and its `reason` is `"nul-character"`. This rule applies to database calls and transaction handles. Store JSON with `JSON.stringify`, which escapes NUL characters, or use `Uint8Array` for binary data containing zero bytes. This validation does not inspect SQL source or SQL-generated values.
29
35
 
36
+ ## Bring your own driver
37
+
38
+ Atomic does not bundle remote database drivers. Install your chosen SQLite-compatible driver in your own project and wrap it as a `SqliteDatabase` from `@bastani/atomic/storage`. The interface consists of a diagnostic `descriptor`, async `exec`, `run`, `get`, `all`, `transaction(callback)`, and `close()` methods, with the return values and transaction-handle rules described above.
39
+
40
+ A wrapper must queue database operations in call order, keeping unrelated calls outside active transactions. Reject NUL text with `StorageInvalidTextError`, snapshot binary parameters before queueing, and normalize returned integers and blobs. Use `StorageUnavailableError` for driver failures, preserve callback failures, and report failed rollbacks with `StorageRollbackError`. Expire transaction handles after their callback settles. On close, reject new calls, drain accepted work, and release driver resources. Do not include credentials in diagnostics or fall back to memory after an opening failure.
41
+
42
+ ### libSQL / Turso example
43
+
44
+ Install `@libsql/client` separately. Save the complete wrapper below as `storage-libsql-wrapper.ts` in your project. It accepts caller-provided credentials only. For a local file, create its parent directory first; no network or credentials are needed.
45
+
46
+ ```ts
47
+ import type { SqliteDatabase } from "@bastani/atomic/storage";
48
+ import { openLibsqlDatabase } from "./storage-libsql-wrapper.js";
49
+
50
+ const database: SqliteDatabase = await openLibsqlDatabase({ url: "file:./data.sqlite" });
51
+ // For Turso instead: { url: "libsql://your-database.turso.io", authToken: token }
52
+ try {
53
+ await database.exec("CREATE TABLE IF NOT EXISTS notes (text TEXT)");
54
+ await database.transaction(async (tx) => {
55
+ await tx.run("INSERT INTO notes VALUES (?)", "hello");
56
+ });
57
+ const notes = await database.all("SELECT text FROM notes");
58
+ } finally {
59
+ await database.close();
60
+ }
61
+ ```
62
+
63
+ Pass the returned facade as SDK `sessionStore: { kind: "database", database, prefix: "project_" }` or workflow `journal: { database, prefix: "project_" }`. Both can use the same facade without closing your database. To select it from settings, expose `openLibsqlDatabase` through an adapter module as described below.
64
+
65
+ <details>
66
+ <summary>Complete wrapper</summary>
67
+
68
+ {/* custom-driver-example */}
69
+ ```ts
70
+ import type { Client, ResultSet, Row, Transaction } from "@libsql/client";
71
+ import {
72
+ type SqliteDatabase,
73
+ type SqliteExecutor,
74
+ type SqliteRow,
75
+ type SqliteValue,
76
+ type StorageDescriptor,
77
+ StorageAdapterLoadError,
78
+ StorageError,
79
+ type StorageFailureCause,
80
+ StorageInvalidTextError,
81
+ StorageRollbackError,
82
+ StorageTransactionClosedError,
83
+ StorageUnavailableError,
84
+ StoreClosedError,
85
+ } from "@bastani/atomic/storage";
86
+
87
+ export interface LibsqlDatabaseOptions {
88
+ url: string;
89
+ authToken?: string;
90
+ }
91
+
92
+ function credentialRedactor(options: LibsqlDatabaseOptions): (text: string) => string {
93
+ const secrets = [options.authToken ?? ""];
94
+ for (const match of options.url.matchAll(/[?&]([^=&#]*)=([^&#]*)/g)) {
95
+ const token = new URLSearchParams(match[0].slice(1)).get("authToken");
96
+ if (token !== null) secrets.push(match[2] ?? "", token);
97
+ }
98
+ const userinfo = options.url.match(/\/\/([^/?#]*)@/)?.[1];
99
+ if (userinfo !== undefined) secrets.push(...userinfo.split(":"));
100
+ try {
101
+ const url = new URL(options.url);
102
+ secrets.push(url.username, url.password, ...url.searchParams.getAll("authToken"));
103
+ } catch {}
104
+ for (const secret of [...secrets]) {
105
+ try {
106
+ secrets.push(encodeURIComponent(secret));
107
+ secrets.push(decodeURIComponent(secret));
108
+ } catch {}
109
+ }
110
+ return (text) =>
111
+ secrets
112
+ .filter(Boolean)
113
+ .sort((first, second) => second.length - first.length)
114
+ .reduce((value, secret) => value.replaceAll(secret, "[redacted]"), text);
115
+ }
116
+
117
+ function redactCause(cause: StorageFailureCause, redact: (text: string) => string): StorageFailureCause {
118
+ if (typeof cause === "string") return redact(cause);
119
+ if (!(cause instanceof Error)) return cause;
120
+ const nested = cause.cause as StorageFailureCause;
121
+ const safeCause = redactCause(nested, redact);
122
+ const message = redact(cause.message);
123
+ const stack = cause.stack === undefined ? undefined : redact(cause.stack);
124
+ if (message === cause.message && stack === cause.stack && safeCause === nested) return cause;
125
+ const safe = new StorageError(message, { cause: safeCause });
126
+ safe.stack = stack;
127
+ return safe;
128
+ }
129
+
130
+ function normalizeRow(row: Row, columns: readonly string[]): SqliteRow {
131
+ return Object.fromEntries(
132
+ columns.map((key, index) => {
133
+ const value = row[index];
134
+ return [
135
+ key,
136
+ typeof value === "bigint" &&
137
+ value >= -BigInt(Number.MAX_SAFE_INTEGER) &&
138
+ value <= BigInt(Number.MAX_SAFE_INTEGER)
139
+ ? Number(value)
140
+ : value instanceof ArrayBuffer
141
+ ? new Uint8Array(value.slice(0))
142
+ : value,
143
+ ];
144
+ }),
145
+ );
146
+ }
147
+
148
+ class LibsqlDatabase implements SqliteDatabase {
149
+ readonly descriptor: StorageDescriptor;
150
+ private readonly client: Client;
151
+ private readonly redact: (text: string) => string;
152
+ private tail: Promise<void> = Promise.resolve();
153
+ private closing = false;
154
+ private closePromise?: Promise<void>;
155
+ private readonly executor: SqliteExecutor;
156
+
157
+ constructor(client: Client, descriptor: StorageDescriptor, redact: (text: string) => string) {
158
+ this.client = client;
159
+ this.descriptor = descriptor;
160
+ this.redact = redact;
161
+ this.executor = this.createExecutor(client, () => true);
162
+ }
163
+
164
+ private async driver<T>(operation: () => T | Promise<T>): Promise<T> {
165
+ try {
166
+ return await operation();
167
+ } catch (cause) {
168
+ throw new StorageUnavailableError(this.descriptor, redactCause(cause as StorageFailureCause, this.redact));
169
+ }
170
+ }
171
+
172
+ private createExecutor(connection: Client | Transaction, active: () => boolean): SqliteExecutor {
173
+ const execute = async <T>(operation: () => Promise<T>, params: readonly SqliteValue[] = []): Promise<T> => {
174
+ if (!active()) throw new StorageTransactionClosedError();
175
+ const invalidIndex = params.findIndex((value) => typeof value === "string" && value.includes("\0"));
176
+ if (invalidIndex !== -1) throw new StorageInvalidTextError(invalidIndex);
177
+ return this.driver(operation);
178
+ };
179
+ const statement = (sql: string, params: readonly SqliteValue[]): Promise<ResultSet> =>
180
+ connection.execute({
181
+ sql,
182
+ args: params.map((value) => (value instanceof Uint8Array ? new Uint8Array(value) : value)),
183
+ });
184
+ return {
185
+ exec: (sql) => execute(() => connection.executeMultiple(sql)),
186
+ run: (sql, ...params) =>
187
+ execute(async () => ({ changes: (await statement(sql, params)).rowsAffected }), params),
188
+ get: <T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]) =>
189
+ execute(async () => {
190
+ const result = await statement(sql, params);
191
+ const row = result.rows[0];
192
+ return row === undefined ? undefined : (normalizeRow(row, result.columns) as T);
193
+ }, params),
194
+ all: <T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]) =>
195
+ execute(async () => {
196
+ const result = await statement(sql, params);
197
+ return result.rows.map((row) => normalizeRow(row, result.columns) as T);
198
+ }, params),
199
+ };
200
+ }
201
+
202
+ private enqueue<T>(operation: () => Promise<T>): Promise<T> {
203
+ if (this.closing) return Promise.reject(new StoreClosedError(this.descriptor));
204
+ const result = this.tail.then(operation);
205
+ this.tail = result.then(
206
+ () => {},
207
+ () => {},
208
+ );
209
+ return result;
210
+ }
211
+
212
+ exec(sql: string): Promise<void> {
213
+ return this.enqueue(() => this.executor.exec(sql));
214
+ }
215
+
216
+ run(sql: string, ...params: readonly SqliteValue[]) {
217
+ const bound = params.map((value) => (value instanceof Uint8Array ? new Uint8Array(value) : value));
218
+ return this.enqueue(() => this.executor.run(sql, ...bound));
219
+ }
220
+
221
+ get<T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]): Promise<T | undefined> {
222
+ const bound = params.map((value) => (value instanceof Uint8Array ? new Uint8Array(value) : value));
223
+ return this.enqueue(() => this.executor.get<T>(sql, ...bound));
224
+ }
225
+
226
+ all<T extends SqliteRow>(sql: string, ...params: readonly SqliteValue[]): Promise<T[]> {
227
+ const bound = params.map((value) => (value instanceof Uint8Array ? new Uint8Array(value) : value));
228
+ return this.enqueue(() => this.executor.all<T>(sql, ...bound));
229
+ }
230
+
231
+ transaction<T>(callback: (transaction: SqliteExecutor) => Promise<T>): Promise<T> {
232
+ return this.enqueue(async () => {
233
+ const connection = await this.driver(() => this.client.transaction("write"));
234
+ let active = true;
235
+ try {
236
+ const result = await callback(this.createExecutor(connection, () => active));
237
+ active = false;
238
+ await this.driver(() => connection.commit());
239
+ return result;
240
+ } catch (cause) {
241
+ active = false;
242
+ try {
243
+ await this.driver(() => connection.rollback());
244
+ } catch (rollbackCause) {
245
+ throw new StorageRollbackError(cause as StorageFailureCause, rollbackCause as StorageFailureCause);
246
+ }
247
+ throw cause;
248
+ } finally {
249
+ await this.driver(() => connection.close());
250
+ }
251
+ });
252
+ }
253
+
254
+ close(): Promise<void> {
255
+ if (!this.closePromise) {
256
+ this.closing = true;
257
+ this.closePromise = this.tail.then(() => this.driver(() => this.client.close()));
258
+ }
259
+ return this.closePromise;
260
+ }
261
+ }
262
+
263
+ export async function openLibsqlDatabase(options: LibsqlDatabaseOptions): Promise<SqliteDatabase> {
264
+ const config = { url: options.url, authToken: options.authToken };
265
+ const redact = credentialRedactor(config);
266
+ const descriptor = { adapter: "libsql", location: redact(config.url) };
267
+ let createClient: typeof import("@libsql/client").createClient;
268
+ try {
269
+ ({ createClient } = await import("@libsql/client"));
270
+ } catch (cause) {
271
+ throw new StorageAdapterLoadError("@libsql/client", redactCause(cause as StorageFailureCause, redact));
272
+ }
273
+ let client: Client | undefined;
274
+ try {
275
+ client = createClient({ ...config, intMode: "bigint" });
276
+ const database = new LibsqlDatabase(client, descriptor, redact);
277
+ await database.exec("PRAGMA foreign_keys = ON");
278
+ return database;
279
+ } catch (cause) {
280
+ try {
281
+ client?.close();
282
+ } catch {}
283
+ throw new StorageUnavailableError(descriptor, redactCause(cause as StorageFailureCause, redact));
284
+ }
285
+ }
286
+ ```
287
+ {/* /custom-driver-example */}
288
+
289
+ </details>
290
+
291
+ ## Selecting an adapter
292
+
293
+ Install your driver separately and export a default `StorageAdapterModule` from your module:
294
+
295
+ ```ts
296
+ import type { StorageAdapterModule } from "@bastani/atomic/storage";
297
+ import { openLibsqlDatabase } from "./storage-libsql-wrapper.js";
298
+
299
+ export default {
300
+ atomicStorageAdapter: 1,
301
+ async openDatabase(options, context) {
302
+ return openLibsqlDatabase({ url: String(options.url), authToken: String(options.authToken) });
303
+ },
304
+ } satisfies StorageAdapterModule;
305
+ ```
306
+
307
+ Select it with `sessions.storage: { "adapter": "@example/atomic-sqlite" }`, `workflows.journal`, or shared top-level `storage` in [settings](/settings#workflow-storage). SDK sessions accept `sessionStore: { kind: "adapter", module, options, secrets, prefix }`; workflow runs accept `journal: { adapter, options, secrets, prefix }`. Module specifiers resolve from the agent directory, normally `~/.atomic/agent`; absolute module paths also work. Project settings follow the same trust boundary as project extensions. A module executes with Atomic's privileges.
308
+
309
+ `options` is an object of SQLite scalar values or booleans. In JSON settings use strings, numbers, booleans, or null. `secrets` maps option names to `{ env }` or `{ file }`; resolved values override same-named options without trimming file contents. Keep credentials out of `options` and database descriptors. `context` contains `agentDir`, `domain: "sessions" | "journal"`, and an optional `signal`.
310
+
311
+ A SQLite adapter implements `openDatabase(options, context): Promise<SqliteDatabase>`. Atomic applies its domain schema and optional table prefix. A full adapter can instead implement `openSessionStore(options, context, storage)` or `openRunJournal(options, context, storage)`; the domain hook takes priority over `openDatabase`. The typed third argument is `{ readonly prefix?: string }`. Domain adapters must honor this prefix to isolate selected stores. A missing domain/database hook raises `StorageConfigError` with reason `"adapter-domain-unsupported"`. Load failures and invalid module contracts raise `StorageAdapterLoadError`; driver opening failures raise `StorageUnavailableError`. None selects memory as a fallback.
312
+
313
+ The exported `StorageProvider` can open either domain explicitly. Construct it with `{ memory: (descriptor) => new MemoryRunJournal(descriptor), sql: SqlRunJournal.open }` from `@bastani/atomic/workflows`, then call `openSessionStore(selection, context)` or `openRunJournal(selection, context)`. For sessions alone, `new StorageProvider()` needs no journal factories. `StorageSelection` uses `kind: "memory"`, `"jsonl"` with `dir` for sessions only, `"sqlite"` with `path`, `"database"` with a caller-owned facade, or `"adapter"` with `module`, optional options/secrets/prefix.
314
+
315
+ One provider shares a database for matching owned SQLite or adapter selections. Close every returned store; the last store closes the owned database. Closing a store is idempotent. A caller-owned `database` is never closed by the provider. A full domain adapter owns its returned store's lifecycle. Invalid configuration stops selection, and a configured persistent store that cannot open never becomes an in-memory store.
316
+
317
+ If opening storage fails and closing its owned database also fails, the original typed opening error is thrown with a `cleanupCause` field containing the cleanup failure. Inspect both errors when diagnosing the failed open.
318
+
319
+ Factory-created journal headers record a credential-free `storage` descriptor for diagnostics. Full domain adapters are responsible for recording their own safe descriptor. Directly supplied journals and their caller-provided headers are not rewritten.
320
+
321
+ ## Sharing storage across hosts
322
+
323
+ By default, sessions and workflow runs live in a local file that serves one machine. To share them across machines, for example several service replicas or a CI fleet, select the same remote SQLite-compatible database on every host through an [adapter](#selecting-an-adapter), such as the libSQL/Turso wrapper above. Give each project or tenant its own `prefix`. Do not put the local SQLite file on a network filesystem; use a database driver instead.
324
+
325
+ With a shared journal:
326
+
327
+ - Any host can inspect any run with `status` or `stages` without taking ownership.
328
+ - Each run has one executor at a time. A run whose owner is alive cannot be claimed from another host. After its owner crashes and stops renewing its lease for about two minutes, the run appears as `crashed` and any host can resume it. Concurrent resume attempts admit one executor.
329
+ - Lease expiry uses the database clock, so clock differences between hosts do not affect ownership.
330
+ - A displaced executor cannot save new checkpoints; its writes fail with `StaleLeaseError`.
331
+
332
+ The database stores sessions and workflow checkpoints only. To resume a run on another host, that host also needs the same workflow definition and the run's original working directory, including any worktrees and artifacts the run uses. Effects that were not checkpointed may run again after a takeover, so make external effects idempotent. Every checkpoint commits before it is reported, so a remote database adds network latency to each durable `ctx.*` step. Backends may also enforce payload limits that raise `StoragePayloadTooLargeError`.
333
+
334
+ Scale by running more workflows, not by splitting one: a single run and a single session each have one writer. The built-in journal uses SQLite SQL, so `openDatabase` adapters need a SQLite-compatible driver. For another kind of database, implement `openRunJournal` and `openSessionStore` and validate them with the conformance suites below.
335
+
336
+ ## Storage errors
337
+
338
+ Use error classes and their fields, not message matching. Configuration and facade errors are exported from `@bastani/atomic/storage`. `@bastani/atomic/workflows` exports the journal contract's error classes.
339
+
340
+ | Error | Fields and response |
341
+ |---|---|
342
+ | `StorageConfigError` | `source`, `field`, `reason` identify an invalid selected option. Correct that selection; Atomic does not try a lower-precedence store. |
343
+ | `StorageAdapterLoadError` | `module`, `cause`. Check installation and the module's default export. |
344
+ | `StorageUnavailableError` | `adapter`, `location`, `cause`. Restore access to the selected store before retrying. |
345
+ | `StoragePrefixError` | `prefix`, `reason`. Use a valid non-reserved prefix. |
346
+ | `StorageSchemaVersionError` | `domain`, `found`, `supported`. Use a supported database; Atomic does not migrate an unknown schema. |
347
+ | `StoreClosedError` / `StorageTransactionClosedError` | The store is closing/closed, or the transaction callback has ended. Open a new store or use the live callback handle. |
348
+ | `StorageRollbackError` | `cause`, `rollbackCause`. Do not assume the transaction rolled back. |
349
+ | `StorageOutcomeUnknownError` | `domain`, `id`, `key`. A driver cannot confirm the write outcome; inspect the keyed record before retrying. |
350
+ | `StoragePayloadTooLargeError` | `limitBytes`, `actualBytes`. Reduce the payload for that backend. |
351
+ | `StorageInvalidTextError` | `parameterIndex`, `reason`. Remove NUL from scalar text bindings or encode the value as JSON/binary. |
352
+
353
+ Session operations can raise `SessionNotFoundError` or `SessionExistsError` with `sessionId`; `SessionIdMismatchError` with `requested` and `found`; and `SessionConflictError` with `sessionId`, `expectedSeq`, and `actualSeq`. Keep one writer per session. After a conflict, reopen the session rather than writing from stale state.
354
+
355
+ `SessionFormatVersionError` identifies `path`, `found`, and `supported`; `SessionInvalidTextError` identifies `field` and `reason`, and `SessionInvalidTimestampError` adds `value`. A JSONL append whose rollback also fails raises `JsonlStoragePoisonedError` with `location`, `cause`, and `rollbackCause`; stop using that store and inspect the file before reopening. These failures never silently select another store.
356
+
357
+ Journal errors include:
358
+
359
+ | Error | Fields and response |
360
+ |---|---|
361
+ | `StaleLeaseError` | `runId`, `heldEpoch`, `currentEpoch`. Stop writing under stale ownership. |
362
+ | `JournalCasConflictError` | `runId`, `expectedSeq`, `actualSeq`. Reload the run before retrying a conflicting operation. |
363
+ | `RunNotFoundError` | `runId`. Check the selected journal and ID. |
364
+ | `JournalSchemaVersionError` | `domain`, `found`, `supported`. No automatic schema migration. |
365
+ | `JournalInvalidTextError` | `field`, `reason`. Identifiers must be well-formed Unicode without NUL. JSON payload text is not restricted this way. |
366
+ | `JournalCounterRangeError` | `runId`, `field`, `value`, `reason`. Sequence and epoch counters must remain non-negative safe integers. |
367
+ | `JournalMetaCorruptError` | `path`, `rowCount`. Inspect or restore the affected database. |
368
+ | `JournalClosedError` | Open another journal before issuing new operations. |
369
+
370
+ Workflow execution can also fail with `JournalOwnershipError` with `runId` and `holderId`, `JournalBackendClosedError`, `JournalOperationAbortedError` with `runId` and optional `cause`, or `JournalExecutionRetiredError` with `runId`. Stop work after losing ownership or cancellation; do not keep using a closed or retired execution. A local database failure does not justify deleting the shared file, which may hold both session and workflow history.
371
+
30
372
  ## Adapter conformance
31
373
 
32
374
  Implement `SqliteDatabase` and run the exported suite from `@bastani/atomic/storage/testing`:
@@ -38,6 +380,8 @@ import { registerSqliteDatabaseConformance } from "@bastani/atomic/storage/testi
38
380
  registerSqliteDatabaseConformance({ describe, it }, "my adapter", withSubject);
39
381
  ```
40
382
 
41
- `withSubject` creates a fresh database for every case and calls the supplied callback with `{ database, reopen, withRollbackFailure }`. Clean up afterward, including on failure. `reopen()` closes and reopens the same persistent database and returns the new facade. `withRollbackFailure(error, callback)` injects a driver rollback failure only while running the callback, then restores normal behavior. The suite covers normal operation and reopening.
383
+ `withSubject` creates a fresh database for every case and calls the supplied callback with `{ database, reopen, withRollbackFailure }`. Clean up afterward, including on failure. `reopen()` closes and reopens the same persistent database and returns the new facade. `withRollbackFailure(error, callback)` injects a driver rollback failure only while running the callback, then restores normal behavior. Run the full suite against a persistent local database: it covers bindings, exact integers, binary snapshots, NUL rejection, transaction ordering and handle lifetime, commit/rollback failures, reopening, and close semantics.
384
+
385
+ For adapters supporting multiple connections to one database, also run `registerSqliteConnectionConformance({ describe, it }, "my adapter connections", withConnections)`. The fixture must open two facades on the same fresh database, pass both to the callback, and close both afterward. This checks concurrent transaction writes and event-loop responsiveness while one callback yields.
42
386
 
43
387
  `validateStoragePrefix(prefix)` accepts an empty prefix or ASCII letters/underscores followed by ASCII letters, digits, or underscores. It rejects names beginning with `sqlite_`, regardless of case. Validate before opening files. `renderStorageIdentifiers(domain, names, prefix)` returns an immutable name map with `wf_` for `journal` or `session_` for `sessions`. `assertStorageSchemaVersion(domain, found, supported)` rejects a mismatched stored version without changing it.
package/docs/usage.md CHANGED
@@ -122,10 +122,11 @@ Sessions are saved automatically to `~/.atomic/agent/sessions/`, organized by wo
122
122
  atomic -c # Continue most recent session
123
123
  atomic -r # Browse and select a session
124
124
  atomic --no-session # Ephemeral mode; do not save
125
- atomic --session <path|id> # Use a file, exact ID, or unique 8-hex UUID prefix
125
+ atomic --session <id|prefix> # Use an exact ID or unique 8-hex UUID prefix
126
+ atomic --import <file> # Import a format-4 JSONL export into session storage
126
127
  atomic --session-id <id> # Use/create an exact project-local session ID
127
128
  atomic --name "Refactor" # Set the session display name
128
- atomic --fork <path|id> # Fork a file, exact ID, or unique 8-hex UUID prefix
129
+ atomic --fork <id|prefix> # Fork an exact ID or unique 8-hex UUID prefix
129
130
  ```
130
131
 
131
132
  When `--session-id` does not match an exact session in the current project, Atomic warns that no session was found and then creates the requested new session. Reusing an existing exact ID opens it without that warning.
@@ -330,6 +330,8 @@ ctx.stage(name: string, options?: StageOptions): StageContext;
330
330
 
331
331
  Creates and registers a named stage synchronously; work starts when you call a method such as `prompt()` or `complete()`. Use it when `ctx.task` is too coarse and direct session control is required.
332
332
 
333
+ On resume, a cached stage declaration stays synchronous. Its replay metadata is saved before the next checkpoint, prompt, task, tool, or workflow completion. Await those operations and handle their rejection normally; a storage failure is not treated as a successful replay.
334
+
333
335
  ### `ctx.ui`
334
336
 
335
337
  ```typescript
@@ -513,14 +515,14 @@ For large handoffs, write artifacts to files, pass their paths with `reads`, and
513
515
 
514
516
  See [Compression and Artifact Handoffs](/workflows/reliable-design#compression-and-artifact-handoffs) and [Filesystem Context](/workflows/reliable-design#filesystem-context) for complete patterns.
515
517
 
516
- ### `context` / `forkFromSessionFile`
518
+ ### `context` / `forkFromSessionId`
517
519
 
518
520
  ```typescript
519
521
  readonly context?: "fresh" | "fork";
520
- readonly forkFromSessionFile?: string;
522
+ readonly forkFromSessionId?: string;
521
523
  ```
522
524
 
523
- Select a clean session or a forked context, with `forkFromSessionFile` naming an explicit fork source. Omitting `context` creates a fresh session unless the runtime is reopening durable state; see [Locally Scoped Stage Prompts](/workflows/reliable-design#locally-scoped-stage-prompts) for choosing fresh reviewer context versus coherent implementation context.
525
+ Select a clean session or a forked context, with `forkFromSessionId` naming an explicit session ID in the selected session store. Use the earlier task's `sessionId`, not its transcript file path. IDs are preserved verbatim, including an empty stored ID. Omitting `context` creates a fresh session unless the runtime is reopening durable state; see [Locally Scoped Stage Prompts](/workflows/reliable-design#locally-scoped-stage-prompts) for choosing fresh reviewer context versus coherent implementation context.
524
526
 
525
527
  ### `group`
526
528
 
@@ -767,7 +769,7 @@ readonly orchestrationContext?: CreateAgentSessionOptions["orchestrationContext"
767
769
 
768
770
  These are advanced host-supplied SDK seams on the runtime `StageOptions` used by embedded integrations, not ordinary workflow-file defaults. The standalone workflow-package authoring declaration intentionally omits most of them and types `sessionManager` and `settingsManager` as `never`, so package-authored workflows should not pass these fields directly.
769
771
 
770
- The runtime strips workflow-owned fields before forwarding session options. Internal durable fields such as `resumeFromSessionFile`, `durableReplayKey`, and `durableAccumulatedDurationMs` are not public authoring options.
772
+ The runtime strips workflow-owned fields before forwarding session options. Internal durable fields such as `resumeFromSessionId`, `durableReplayKey`, and `durableAccumulatedDurationMs` are not public authoring options.
771
773
 
772
774
  ### `name` (step items)
773
775
 
@@ -924,7 +926,7 @@ readonly sessionId: string;
924
926
  readonly sessionFile: string | undefined;
925
927
  ```
926
928
 
927
- Expose the retained session identifier and its optional transcript file. `sessionFile` is `undefined` when no file is available.
929
+ Expose the retained session identifier and its optional transcript file. Use `sessionId` to identify a session in its selected store. `sessionFile` is display metadata and is `undefined` when no file is available; it cannot be used as a fork or resume identity.
928
930
 
929
931
  ### `stage.setModel(model)` / `stage.setThinkingLevel(level)` / `stage.cycleModel()` / `stage.cycleThinkingLevel()`
930
932
 
@@ -1264,7 +1266,7 @@ Executes a compiled definition programmatically with validated inputs. Empty-inp
1264
1266
 
1265
1267
  #### Stage sessions and adapters
1266
1268
 
1267
- When `opts.adapters` supplies neither `agentSession` nor `prompt`, `run()` uses `createAgentSessionAdapter({ cwd: opts.cwd })`. Each stage then runs its own in-process Atomic `createAgentSession` session with an in-memory `SessionManager`, unless the stage sets `sessionDir` or resumes or forks a session. Stage sessions resolve models, credentials, settings, and resources the same way `createAgentSession` does. A `prompt` adapter on its own answers stage prompts itself, so `run()` adds no default session adapter beside it.
1269
+ When `opts.adapters` supplies neither `agentSession` nor `prompt`, `run()` uses `createAgentSessionAdapter({ cwd: opts.cwd })`. Each stage then runs its own in-process Atomic `createAgentSession` session with persistent session storage by default. Use the stage's `sessionDir` to choose its session directory, or supply an explicitly selected in-memory session manager through a custom adapter for ephemeral stages. A persistent storage failure fails stage creation; it never falls back to memory. Stage sessions resolve models, credentials, settings, and resources the same way `createAgentSession` does. A `prompt` adapter on its own answers stage prompts itself, so `run()` adds no default session adapter beside it.
1268
1270
 
1269
1271
  ```typescript
1270
1272
  function createAgentSessionAdapter(
@@ -1286,7 +1288,7 @@ A custom adapter's `create(options, meta)` receives the stage's session options,
1286
1288
  ```ts
1287
1289
  import { createAgentSessionAdapter, run } from "@bastani/atomic/workflows";
1288
1290
 
1289
- // Default: in-process stage sessions with in-memory session managers.
1291
+ // Default: in-process stage sessions with persistent session storage.
1290
1292
  await run(helloWorld, { name: "Atomic" }, { cwd: process.cwd() });
1291
1293
 
1292
1294
  // Shared options for every stage.
@@ -1331,7 +1333,7 @@ interface RunOpts {
1331
1333
  readonly signal?: AbortSignal;
1332
1334
  readonly deferWorkflowStart?: boolean;
1333
1335
  readonly config?: WorkflowRuntimeConfig;
1334
- readonly durability?: WorkflowDurability;
1336
+ readonly journal?: RunJournalOption;
1335
1337
  readonly models?: WorkflowModelCatalogPort;
1336
1338
  readonly registry?: WorkflowRegistry;
1337
1339
  readonly depth?: number;
@@ -1362,24 +1364,86 @@ The public authoring declaration intentionally excludes runtime-only executor fi
1362
1364
  #### Choosing the durable backend
1363
1365
 
1364
1366
  ```typescript
1365
- type WorkflowDurability =
1366
- | { readonly mode: "memory" }
1367
- | { readonly mode: "durable" };
1367
+ import type { RunJournalOption } from "@bastani/atomic/workflows";
1368
+ ```
1369
+
1370
+ `run()` uses the local SQLite journal at `~/.atomic/workflows/journal.sqlite` by default, shared with sessions under separate `wf_` and `session_` table prefixes. It releases the run's lease when execution settles. Select a journal with `RunOpts.journal`:
1371
+
1372
+ - `{ path }` opens that SQLite file.
1373
+ - `{ database, prefix? }` uses a caller-owned async `SqliteDatabase` facade. Atomic initializes the journal schema on it but does not close the database.
1374
+ - `{ memory: true }` explicitly selects `MemoryRunJournal`. Records last only for the process and cannot recover runs after exit.
1375
+ - `{ adapter, options?, secrets?, prefix? }` loads your installed adapter module. See [Storage adapters](/storage#selecting-an-adapter).
1376
+ - A `RunJournal` instance is used as supplied. `SqlRunJournal`, `openSqlRunJournal`, `MemoryRunJournal`, journal error classes, and `registerRunJournalConformance` are exported from `@bastani/atomic/workflows`.
1377
+
1378
+ Use `await openSqlRunJournal(path)` to open a file directly, or omit `path` for the default journal. It also accepts a caller-owned `node:sqlite` `DatabaseSync` directly and wraps the connection itself. Pass an async `SqliteDatabase` facade to `SqlRunJournal.open` or `RunOpts.journal.database` instead. `await resolveRunJournal(options)` applies the selection rules below.
1379
+
1380
+ To attach your own SQLite-compatible driver, implement the [async SQLite storage API](/storage) and pass its facade to `SqlRunJournal.open`:
1381
+
1382
+ ```ts
1383
+ import { openNodeSqliteDatabase } from "@bastani/atomic/storage";
1384
+ import { SqlRunJournal, run } from "@bastani/atomic/workflows";
1385
+
1386
+ const database = await openNodeSqliteDatabase("./shared.sqlite");
1387
+ const journal = await SqlRunJournal.open(database, { prefix: "project_" });
1388
+ try {
1389
+ await run(helloWorld, { name: "Atomic" }, { journal });
1390
+ } finally {
1391
+ await journal.close();
1392
+ await database.close();
1393
+ }
1394
+ ```
1395
+
1396
+ `SqlRunJournal.open` leaves ownership of the facade with you. Journal tables use `wf_` names, optionally preceded by your prefix; session tables use a separate namespace in the same database. A new prefix selects an empty journal, not a migration. Bare journal table names from earlier unreleased builds are not read. SQL event and lease timestamps, including expiry checks, use the database clock. Journal storage failures expose `StorageUnavailableError.adapter`, `.location`, and `.cause`; use `.location` rather than `.path`.
1397
+
1398
+ Custom journals implement this full async interface. The named types are exported from `@bastani/atomic/workflows`:
1399
+
1400
+ ```ts
1401
+ interface RunJournal {
1402
+ createRun(header: RunHeader): Promise<"created" | "exists">;
1403
+ getRun(runId: string): Promise<RunSummary | undefined>;
1404
+ listRuns(filter?: { cwd?: string }): Promise<readonly RunSummary[]>;
1405
+ acquire(runId: string, holderId: string): Promise<LeaseOutcome>;
1406
+ takeover(runId: string, holderId: string, expectedHolder: string): Promise<LeaseOutcome>;
1407
+ takeoverExpired(runId: string, holderId: string, staleAfterMs: number): Promise<LeaseOutcome>;
1408
+ leaseState(runId: string): Promise<LeaseState | undefined>;
1409
+ renew(lease: Lease): Promise<void>;
1410
+ release(lease: Lease): Promise<void>;
1411
+ append(lease: Lease, event: RunEvent, options?: { key?: string; expectSeq?: number }): Promise<AppendOutcome>;
1412
+ read(runId: string, fromSeq?: number): AsyncIterable<JournalEntry>;
1413
+ readKey(runId: string, key: string): Promise<JournalEntry | undefined>;
1414
+ deleteOwnedRun(lease: Lease, expectSeq?: number): Promise<void>;
1415
+ deleteRun(runId: string): Promise<void>;
1416
+ close(): Promise<void>;
1417
+ }
1368
1418
  ```
1369
1419
 
1370
- `run()` initializes the process's local SQLite journal on first use and releases each run's lease when execution settles. The journal remains available to other runs in the same process.
1420
+ `getRun` returns the current summary or `undefined`. `leaseState` returns the current lease with its `renewedAt` timestamp and `ageMs`, or `undefined` when unheld. `ageMs` is the journal-clock time since renewal, computed in the same read and clamped to a non-negative safe integer. Use it for expiry decisions instead of subtracting `renewedAt` from the process clock. `takeoverExpired` measures a duration on the journal's clock and atomically refuses a foreign lease unless its renewal is strictly older than `staleAfterMs`, returning the `held` outcome while fresh. `read` loads bounded pages only as consumed, in sequence order starting at the inclusive `fromSeq`, which defaults to 1. Stopping iteration must stop further page reads.
1421
+
1422
+ `append` checks lease fencing first, then the idempotency key before `expectSeq`. A committed keyed retry returns `{ status: "exists", entry }` with the original entry even when the retry's sequence expectation is stale. A new key with a stale expectation rejects with `JournalCasConflictError` without writing.
1423
+
1424
+ `SqlRunJournal.append` serializes its payload once at invocation, before asynchronous lease and key checks, so later caller mutation cannot change the event. This invokes `toJSON` once even for a keyed duplicate, which still returns the original entry without writing. For `StatusChanged`, text validation and the run summary's status use the serialized payload, not the original object's status. Header and payload serialization failures retain their original cause in `StorageUnavailableError`; append reports such a failure only after the lease, key, and sequence checks above. A payload that cannot serialize has no status snapshot to validate, even if its original status contains invalid text.
1371
1425
 
1372
- - **Omitted or `{ mode: "durable" }`:** writes durable state to the journal. Storage failures reject the call; Atomic does not silently switch to memory.
1373
- - **`{ mode: "memory" }`:** explicitly chooses state that lasts only for this call and cannot resume after process exit.
1426
+ `deleteOwnedRun` atomically deletes a run only while the lease's `runId`, `holderId`, and `epoch` still match; otherwise it rejects with `StaleLeaseError` and preserves the run and its events. An optional `expectSeq` must equal the latest sequence or the operation rejects with `JournalCasConflictError` without deleting anything. Deletion keeps the last epoch so an old lease cannot delete or write a recreated run. `deleteRun` is an unconditional administrative operation. Inputs and returned records must be detached. `close()` is idempotent, and every later operation rejects.
1374
1427
 
1375
- The default journal is `~/.atomic/workflows/journal.sqlite`. Set `ATOMIC_WORKFLOW_JOURNAL_PATH` before the first workflow action to choose another file. Keep the same journal and working directory when resuming stored runs.
1428
+ Custom journals need only the async contract; no synchronous journal methods are required. Use `registerRunJournalConformance(runner, name, open, observeRead)` to check a fresh journal per case. Supply a read observer that reports actual page sizes and entries loaded or copied, with `restore()` and `reset()` methods, so the suite can verify lazy reads without consuming the whole history.
1429
+
1430
+ Precedence is `RunOpts.journal`, non-empty `ATOMIC_WORKFLOW_JOURNAL_PATH`, `workflows.journal`, shared top-level `storage`, then the default `~/.atomic/workflows/journal.sqlite`. Nearer settings selections replace whole objects, never merge options or secrets. Relative settings paths resolve against Atomic home. Invalid selected values raise `StorageConfigError`; storage failures reject the call without selecting memory. Keep the same journal and working directory when resuming stored runs.
1376
1431
 
1377
1432
  ```ts
1378
1433
  import { run } from "@bastani/atomic/workflows";
1379
1434
 
1380
- await run(helloWorld, { name: "Atomic" }, { durability: { mode: "durable" } });
1435
+ await run(helloWorld, { name: "Atomic" }, { journal: { path: "./workflow-runs.sqlite" } });
1436
+ await run(helloWorld, { name: "Atomic" }, { journal: { memory: true } });
1381
1437
  ```
1382
1438
 
1439
+ #### Durable writes
1440
+
1441
+ Await asynchronous workflow operations before using their results. Atomic commits a successful write before publishing its new state, and shutdown drains accepted journal writes before releasing ownership. A write failure rejects with a typed storage error, not an in-memory fallback.
1442
+
1443
+ For direct durable-backend use, open `JournalDurableBackend` with `await JournalDurableBackend.open(journal, { ownsJournal: false })`, not a constructor. Omit `ownsJournal: false` to let the backend close the journal. Await `commitWorkflowRegistration`, `commitWorkflowStatus`, `commitWorkflowStatusTransition`, `commitPendingPromptAdjustment`, `commitReset`, and `commitCheckpoint`; use `commitAdditiveCheckpointBestEffort` for additive writes.
1444
+
1445
+ `ctx.stage()` remains synchronous. For a cached stage, Atomic commits its replay metadata before the next async execution boundary; callers do not need an extra checkpoint or flush. See [Storage errors](/storage#storage-errors) for configuration, driver, and ownership failures.
1446
+
1383
1447
  ### `resolveInputs(schema, provided)`
1384
1448
 
1385
1449
  ```typescript
@@ -458,9 +458,9 @@ The readiness prompt can be answered in the attached stage UI or with `workflow(
458
458
 
459
459
  ## Durable Workflows and Cross-Session Resume
460
460
 
461
- Atomic workflows use a **local SQLite journal as their only persistent store**. It opens on the first workflow action and commits registrations, checkpoints, and control transitions before reporting them as durable. The default file is `~/.atomic/workflows/journal.sqlite`; set `ATOMIC_WORKFLOW_JOURNAL_PATH` before starting Atomic to select another file. Keep it on durable local storage. Storage failures stop the action rather than selecting another store.
461
+ Atomic workflows persist runs in a SQLite journal. It opens on the first workflow action and commits registrations, checkpoints, and control transitions before reporting them as durable. The default file is `~/.atomic/workflows/journal.sqlite`; set `ATOMIC_WORKFLOW_JOURNAL_PATH` before starting Atomic to select another file. Keep a journal file on durable local storage. To share runs across machines, select a remote SQLite-compatible database through a [storage adapter](/storage#sharing-storage-across-hosts) rather than placing the file on a network filesystem. Storage failures stop the action rather than selecting another store.
462
462
 
463
- SDK callers can explicitly choose per-call non-durable execution; see [Choosing the durable backend](/workflows/api-reference#choosing-the-durable-backend).
463
+ Select process-local memory explicitly with `workflows.journal.memory: true` or SDK `RunOpts.journal: { memory: true }`. It supports checkpoint replay within the process but not recovery after exit. See [Choosing the durable backend](/workflows/api-reference#choosing-the-durable-backend).
464
464
 
465
465
  ### Storage failures and recovery
466
466
 
@@ -470,7 +470,7 @@ If recovery reports `Workflow definition not found`, restore the matching defini
470
470
 
471
471
  ### Multiple sessions
472
472
 
473
- A run with a live journal lease cannot be claimed by another executor, even when a long-running tool has not updated its progress. After a process crashes and its lease expires (about two minutes without renewal), inspection reports `crashed`. Concurrent resume attempts admit one executor.
473
+ A run with a live journal lease cannot be claimed by another executor, even when a long-running tool has not updated its progress. After a process crashes and its lease expires (about two minutes without renewal), inspection reports `crashed`. Concurrent resume attempts admit one executor. The same rules apply across machines that share a journal database; see [Sharing storage across hosts](/storage#sharing-storage-across-hosts).
474
474
 
475
475
  SDK recovery requires the original working directory and journal. `session.workflows.getRun(runId)` and `getStages(runId)` inspect saved state without taking ownership; `resume(runId)` explicitly claims eligible work. Save the full UUID. An owning session can also release checkpointed paused runs through `await session.dispose()` or a session switch, allowing another authorized session to adopt them. See [SDK run control](/sdk#workflow-run-control).
476
476
 
@@ -653,7 +653,9 @@ That history does not authorize any live release action.
653
653
 
654
654
  ### Configuring journal storage
655
655
 
656
- Set `ATOMIC_WORKFLOW_JOURNAL_PATH` before starting Atomic to select a durable local file. Otherwise Atomic uses `~/.atomic/workflows/journal.sqlite`. Preserve that file and its SQLite sidecar files; use the same journal and working directory to resume an existing run. See [Workflow storage settings](/settings#workflow-storage).
656
+ Set `workflows.journal.path` in `settings.json` or set `ATOMIC_WORKFLOW_JOURNAL_PATH` before starting Atomic to select a local SQLite file. The non-empty environment value overrides settings; SDK `RunOpts.journal` overrides both. Relative settings paths resolve against the Atomic home directory, normally `~/.atomic`. With no override, Atomic uses `~/.atomic/workflows/journal.sqlite`. To use a remote database, select an [adapter module](/storage#selecting-an-adapter) in `workflows.journal` or shared `storage`.
657
+
658
+ For process-local storage, use `workflows.journal.memory: true` without a non-empty settings path, or pass `journal: { memory: true }` to SDK `run()`. Memory is never selected after a storage failure. Preserve a SQLite journal and its sidecar files; use the same journal and working directory to resume an existing run. See [Workflow storage settings](/settings#workflow-storage).
657
659
 
658
660
  Pending-stage Intercom cleanup checks durable ownership only for runs with messages that need settlement. Repeated failures with the same message produce one warning per extension instance. Interactive hosts receive a display-only notification, never a console stack trace, even if notification delivery fails; headless hosts retain a console diagnostic. Pending messages are not discarded when cleanup fails.
659
661