@bastani/atomic 0.9.38-alpha.6 → 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 (248) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/builtin/intercom/package.json +2 -2
  3. package/dist/builtin/mcp/package.json +1 -1
  4. package/dist/builtin/subagents/CHANGELOG.md +6 -0
  5. package/dist/builtin/subagents/package.json +3 -3
  6. package/dist/builtin/subagents/src/extension/index.bundle.mjs +120 -121
  7. package/dist/builtin/web-access/package.json +2 -2
  8. package/dist/builtin/workflows/CHANGELOG.md +19 -0
  9. package/dist/builtin/workflows/builtin/{chunk-q7dx7kh7.js → chunk-85mx6wcf.js} +6 -6
  10. package/dist/builtin/workflows/builtin/{chunk-neszcj53.js → chunk-8kkv04hz.js} +15 -15
  11. package/dist/builtin/workflows/builtin/{chunk-g1a4hw0s.js → chunk-8x61e0s7.js} +13 -25
  12. package/dist/builtin/workflows/builtin/{chunk-2qgfyvzs.js → chunk-y45tkftg.js} +7 -7
  13. package/dist/builtin/workflows/builtin/goal.js +2 -2
  14. package/dist/builtin/workflows/builtin/index.js +4 -4
  15. package/dist/builtin/workflows/builtin/open-claude-design.js +1 -1
  16. package/dist/builtin/workflows/builtin/ralph.js +2 -2
  17. package/dist/builtin/workflows/package.json +2 -2
  18. package/dist/builtin/workflows/src/durable/journal/internal.d.ts +0 -19
  19. package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +3 -11
  20. package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +15 -9
  21. package/dist/builtin/workflows/src/durable/journal/types.d.ts +3 -93
  22. package/dist/builtin/workflows/src/extension/index.bundle.mjs +992 -756
  23. package/dist/builtin/workflows/src/index.js +547 -394
  24. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +1 -1
  25. package/dist/cli/args.d.ts +2 -0
  26. package/dist/cli/args.d.ts.map +1 -1
  27. package/dist/cli/args.js +29 -3
  28. package/dist/cli/args.js.map +1 -1
  29. package/dist/cli/session-picker.d.ts +1 -1
  30. package/dist/cli/session-picker.d.ts.map +1 -1
  31. package/dist/cli/session-picker.js +2 -2
  32. package/dist/cli/session-picker.js.map +1 -1
  33. package/dist/core/agent-session-events.d.ts.map +1 -1
  34. package/dist/core/agent-session-events.js +6 -1
  35. package/dist/core/agent-session-events.js.map +1 -1
  36. package/dist/core/agent-session-runtime.d.ts +4 -0
  37. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  38. package/dist/core/agent-session-runtime.js +44 -4
  39. package/dist/core/agent-session-runtime.js.map +1 -1
  40. package/dist/core/agent-session-services.d.ts +1 -1
  41. package/dist/core/agent-session-services.d.ts.map +1 -1
  42. package/dist/core/agent-session-services.js +2 -2
  43. package/dist/core/agent-session-services.js.map +1 -1
  44. package/dist/core/compaction/branch-summarization.d.ts +1 -4
  45. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  46. package/dist/core/compaction/branch-summarization.js +0 -4
  47. package/dist/core/compaction/branch-summarization.js.map +1 -1
  48. package/dist/core/compaction/pi-summary-fallback.d.ts.map +1 -1
  49. package/dist/core/compaction/pi-summary-fallback.js +1 -3
  50. package/dist/core/compaction/pi-summary-fallback.js.map +1 -1
  51. package/dist/core/extensions/loader-api.js +1 -1
  52. package/dist/core/extensions/loader-api.js.map +1 -1
  53. package/dist/core/extensions/runner-context.d.ts.map +1 -1
  54. package/dist/core/extensions/runner-context.js +7 -1
  55. package/dist/core/extensions/runner-context.js.map +1 -1
  56. package/dist/core/fast-model-routing.js +1 -1
  57. package/dist/core/fast-model-routing.js.map +1 -1
  58. package/dist/core/model-config.d.ts +765 -0
  59. package/dist/core/model-config.d.ts.map +1 -1
  60. package/dist/core/model-config.js +46 -24
  61. package/dist/core/model-config.js.map +1 -1
  62. package/dist/core/model-resolver-defaults.js +1 -1
  63. package/dist/core/model-resolver-defaults.js.map +1 -1
  64. package/dist/core/resource-loader-reload.js +1 -1
  65. package/dist/core/resource-loader-reload.js.map +1 -1
  66. package/dist/core/resource-loader-types.d.ts +1 -1
  67. package/dist/core/resource-loader-types.d.ts.map +1 -1
  68. package/dist/core/resource-loader-types.js.map +1 -1
  69. package/dist/core/sdk-types.d.ts +4 -0
  70. package/dist/core/sdk-types.d.ts.map +1 -1
  71. package/dist/core/sdk-types.js.map +1 -1
  72. package/dist/core/sdk.d.ts +1 -1
  73. package/dist/core/sdk.d.ts.map +1 -1
  74. package/dist/core/sdk.js +48 -19
  75. package/dist/core/sdk.js.map +1 -1
  76. package/dist/core/session-lifecycle-work.d.ts +3 -0
  77. package/dist/core/session-lifecycle-work.d.ts.map +1 -1
  78. package/dist/core/session-lifecycle-work.js +2 -0
  79. package/dist/core/session-lifecycle-work.js.map +1 -1
  80. package/dist/core/session-manager-core.d.ts +7 -4
  81. package/dist/core/session-manager-core.d.ts.map +1 -1
  82. package/dist/core/session-manager-core.js +149 -41
  83. package/dist/core/session-manager-core.js.map +1 -1
  84. package/dist/core/session-manager-list.d.ts.map +1 -1
  85. package/dist/core/session-manager-list.js +7 -7
  86. package/dist/core/session-manager-list.js.map +1 -1
  87. package/dist/core/session-manager-storage.d.ts +3 -2
  88. package/dist/core/session-manager-storage.d.ts.map +1 -1
  89. package/dist/core/session-manager-storage.js +25 -9
  90. package/dist/core/session-manager-storage.js.map +1 -1
  91. package/dist/core/session-manager-types.d.ts +1 -1
  92. package/dist/core/session-manager-types.d.ts.map +1 -1
  93. package/dist/core/session-manager-types.js.map +1 -1
  94. package/dist/core/session-manager.d.ts +1 -1
  95. package/dist/core/session-manager.d.ts.map +1 -1
  96. package/dist/core/session-manager.js +1 -1
  97. package/dist/core/session-manager.js.map +1 -1
  98. package/dist/core/session-resume-args.d.ts +4 -0
  99. package/dist/core/session-resume-args.d.ts.map +1 -0
  100. package/dist/core/session-resume-args.js +9 -0
  101. package/dist/core/session-resume-args.js.map +1 -0
  102. package/dist/core/session-storage.d.ts +26 -0
  103. package/dist/core/session-storage.d.ts.map +1 -0
  104. package/dist/core/session-storage.js +155 -0
  105. package/dist/core/session-storage.js.map +1 -0
  106. package/dist/core/session-store-list.d.ts +4 -0
  107. package/dist/core/session-store-list.d.ts.map +1 -0
  108. package/dist/core/session-store-list.js +28 -0
  109. package/dist/core/session-store-list.js.map +1 -0
  110. package/dist/core/settings-manager-basic-accessors.d.ts +0 -1
  111. package/dist/core/settings-manager-basic-accessors.d.ts.map +1 -1
  112. package/dist/core/settings-manager-basic-accessors.js +0 -5
  113. package/dist/core/settings-manager-basic-accessors.js.map +1 -1
  114. package/dist/core/settings-merge.d.ts.map +1 -1
  115. package/dist/core/settings-merge.js +5 -0
  116. package/dist/core/settings-merge.js.map +1 -1
  117. package/dist/core/settings-schema.d.ts +74 -3
  118. package/dist/core/settings-schema.d.ts.map +1 -1
  119. package/dist/core/settings-schema.js +28 -14
  120. package/dist/core/settings-schema.js.map +1 -1
  121. package/dist/core/storage/errors.d.ts +1 -0
  122. package/dist/core/storage/errors.d.ts.map +1 -1
  123. package/dist/core/storage/errors.js.map +1 -1
  124. package/dist/core/storage/index.d.ts +4 -0
  125. package/dist/core/storage/index.d.ts.map +1 -1
  126. package/dist/core/storage/index.js +3 -0
  127. package/dist/core/storage/index.js.map +1 -1
  128. package/dist/core/storage/provider.d.ts +58 -0
  129. package/dist/core/storage/provider.d.ts.map +1 -0
  130. package/dist/core/storage/provider.js +243 -0
  131. package/dist/core/storage/provider.js.map +1 -0
  132. package/dist/core/storage/run-journal.d.ts +93 -0
  133. package/dist/core/storage/run-journal.d.ts.map +1 -0
  134. package/dist/core/storage/run-journal.js +15 -0
  135. package/dist/core/storage/run-journal.js.map +1 -0
  136. package/dist/core/storage/selection.d.ts +16 -0
  137. package/dist/core/storage/selection.d.ts.map +1 -0
  138. package/dist/core/storage/selection.js +87 -0
  139. package/dist/core/storage/selection.js.map +1 -0
  140. package/dist/core/storage/session/jsonl-session-store.d.ts +2 -0
  141. package/dist/core/storage/session/jsonl-session-store.d.ts.map +1 -1
  142. package/dist/core/storage/session/jsonl-session-store.js +58 -29
  143. package/dist/core/storage/session/jsonl-session-store.js.map +1 -1
  144. package/dist/core/storage/session/legacy-format.d.ts +18 -0
  145. package/dist/core/storage/session/legacy-format.d.ts.map +1 -0
  146. package/dist/core/storage/session/legacy-format.js +63 -0
  147. package/dist/core/storage/session/legacy-format.js.map +1 -0
  148. package/dist/core/storage/session/memory-session-store.d.ts +3 -1
  149. package/dist/core/storage/session/memory-session-store.d.ts.map +1 -1
  150. package/dist/core/storage/session/memory-session-store.js +9 -2
  151. package/dist/core/storage/session/memory-session-store.js.map +1 -1
  152. package/dist/core/storage/session/sql-session-store.d.ts +4 -1
  153. package/dist/core/storage/session/sql-session-store.d.ts.map +1 -1
  154. package/dist/core/storage/session/sql-session-store.js +25 -6
  155. package/dist/core/storage/session/sql-session-store.js.map +1 -1
  156. package/dist/core/storage/session/types.d.ts +4 -0
  157. package/dist/core/storage/session/types.d.ts.map +1 -1
  158. package/dist/core/storage/session/types.js.map +1 -1
  159. package/dist/core/tools/read-url.d.ts.map +1 -1
  160. package/dist/core/tools/read-url.js +6 -1
  161. package/dist/core/tools/read-url.js.map +1 -1
  162. package/dist/extensions/codemode/execute.d.ts.map +1 -1
  163. package/dist/extensions/codemode/execute.js +13 -0
  164. package/dist/extensions/codemode/execute.js.map +1 -1
  165. package/dist/extensions/herdr/index.d.ts.map +1 -1
  166. package/dist/extensions/herdr/index.js +5 -3
  167. package/dist/extensions/herdr/index.js.map +1 -1
  168. package/dist/index.d.ts +3 -1
  169. package/dist/index.d.ts.map +1 -1
  170. package/dist/index.js +3 -1
  171. package/dist/index.js.map +1 -1
  172. package/dist/main-session.d.ts +5 -1
  173. package/dist/main-session.d.ts.map +1 -1
  174. package/dist/main-session.js +106 -45
  175. package/dist/main-session.js.map +1 -1
  176. package/dist/main.d.ts.map +1 -1
  177. package/dist/main.js +49 -15
  178. package/dist/main.js.map +1 -1
  179. package/dist/modes/interactive/components/chat-session-host.d.ts +3 -1
  180. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  181. package/dist/modes/interactive/components/chat-session-host.js +15 -7
  182. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  183. package/dist/modes/interactive/components/session-selector-delete.d.ts +1 -1
  184. package/dist/modes/interactive/components/session-selector-delete.d.ts.map +1 -1
  185. package/dist/modes/interactive/components/session-selector-delete.js.map +1 -1
  186. package/dist/modes/interactive/components/session-selector-list.d.ts +4 -4
  187. package/dist/modes/interactive/components/session-selector-list.d.ts.map +1 -1
  188. package/dist/modes/interactive/components/session-selector-list.js +13 -12
  189. package/dist/modes/interactive/components/session-selector-list.js.map +1 -1
  190. package/dist/modes/interactive/components/session-selector.d.ts +1 -0
  191. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  192. package/dist/modes/interactive/components/session-selector.js +16 -5
  193. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  194. package/dist/modes/interactive/interactive-mode-helpers.d.ts.map +1 -1
  195. package/dist/modes/interactive/interactive-mode-helpers.js +6 -2
  196. package/dist/modes/interactive/interactive-mode-helpers.js.map +1 -1
  197. package/dist/modes/interactive/interactive-session-routing.js +19 -7
  198. package/dist/modes/interactive/interactive-session-routing.js.map +1 -1
  199. package/dist/modes/interactive/interactive-slash-commands.js +3 -1
  200. package/dist/modes/interactive/interactive-slash-commands.js.map +1 -1
  201. package/dist/modes/interactive-engine/create-isolated-runtime.d.ts.map +1 -1
  202. package/dist/modes/interactive-engine/create-isolated-runtime.js +8 -1
  203. package/dist/modes/interactive-engine/create-isolated-runtime.js.map +1 -1
  204. package/dist/modes/interactive-engine/engine-args.d.ts.map +1 -1
  205. package/dist/modes/interactive-engine/engine-args.js +5 -1
  206. package/dist/modes/interactive-engine/engine-args.js.map +1 -1
  207. package/dist/modes/interactive-engine/isolated-runtime.d.ts.map +1 -1
  208. package/dist/modes/interactive-engine/isolated-runtime.js +21 -15
  209. package/dist/modes/interactive-engine/isolated-runtime.js.map +1 -1
  210. package/dist/modes/rpc/rpc-client-process.d.ts.map +1 -1
  211. package/dist/modes/rpc/rpc-client-process.js +3 -1
  212. package/dist/modes/rpc/rpc-client-process.js.map +1 -1
  213. package/dist/modes/rpc/rpc-command-handler.js +1 -1
  214. package/dist/modes/rpc/rpc-command-handler.js.map +1 -1
  215. package/dist/modes/rpc/rpc-terminal-drain.d.ts.map +1 -1
  216. package/dist/modes/rpc/rpc-terminal-drain.js +11 -2
  217. package/dist/modes/rpc/rpc-terminal-drain.js.map +1 -1
  218. package/dist/utils/canonical-path.d.ts +5 -0
  219. package/dist/utils/canonical-path.d.ts.map +1 -0
  220. package/dist/utils/canonical-path.js +26 -0
  221. package/dist/utils/canonical-path.js.map +1 -0
  222. package/dist/utils/paths.d.ts +1 -7
  223. package/dist/utils/paths.d.ts.map +1 -1
  224. package/dist/utils/paths.js +1 -15
  225. package/dist/utils/paths.js.map +1 -1
  226. package/docs/codemode.md +2 -0
  227. package/docs/compaction.md +2 -2
  228. package/docs/docs.json +1 -0
  229. package/docs/environment-variables.md +6 -2
  230. package/docs/getting-started/installation.md +1 -1
  231. package/docs/models/reference.md +2 -0
  232. package/docs/models-configuration.md +206 -0
  233. package/docs/models.md +11 -1
  234. package/docs/providers.md +2 -2
  235. package/docs/reference/cli.md +4 -0
  236. package/docs/sdk/web-server.md +3 -3
  237. package/docs/sdk.md +40 -3
  238. package/docs/session-format.md +30 -25
  239. package/docs/sessions.md +41 -17
  240. package/docs/settings.md +31 -9
  241. package/docs/storage.md +85 -2
  242. package/docs/workflows/api-reference.md +23 -15
  243. package/docs/workflows/operations.md +3 -3
  244. package/docs/workflows/reliable-design.md +16 -16
  245. package/npm-shrinkwrap.json +53 -53
  246. package/package.json +7 -6
  247. package/schemas/models.schema.json +62 -29
  248. package/schemas/settings.schema.json +136 -31
package/docs/sessions.md CHANGED
@@ -8,9 +8,13 @@ This page covers working with sessions: storage, commands, resuming, naming, and
8
8
 
9
9
  ## Session Storage
10
10
 
11
- Sessions auto-save to `~/.atomic/agent/sessions/`, organized by working directory. Each session is a JSONL file with a tree structure.
11
+ Sessions auto-save to the local SQLite database at `~/.atomic/workflows/journal.sqlite`. Workflow runs use the same file, with `session_` and `wf_` table prefixes separating their records. Session history remains a tree regardless of the selected store.
12
12
 
13
- The session picker also scans linked project directories inside this default store, so project aliases or relocated session folders remain discoverable through `/resume` and `atomic -r`.
13
+ To choose another store, set `sessions.storage` in settings. Use shared `storage` to select one database for both sessions and workflow runs. JSONL is available only when explicitly selected. Memory is available through `--no-session`, `{ "memory": true }` in settings, or an explicit SDK option; it is never a fallback for a failed persistent store.
14
+
15
+ Project-local storage settings apply after you approve project trust, including on the first launch. Atomic re-selects storage before saving a new conversation; resumed conversations stay in their original store. Generated resume commands for JSONL sessions include `--session-dir`; keep that option when reopening the conversation, even if the directory was previously the default.
16
+
17
+ For SQLite, resume with `atomic --session-store "/data/project A/sessions.sqlite" --session-prefix project_ --session <id>`.
14
18
 
15
19
  ```bash
16
20
  atomic -c # Continue most recent session
@@ -18,27 +22,47 @@ atomic -r # Browse and select from past sessions
18
22
  atomic --no-session # Ephemeral mode; do not save
19
23
  atomic --name "my task" # Set session display name at startup
20
24
  atomic --session <id|prefix> # Use an exact ID or unique 8-hex UUID prefix
21
- atomic --import <file> # Import a format-4 JSONL export into session storage
25
+ atomic --import <file> # Import a JSONL export into session storage
22
26
  atomic --fork <id|prefix> # Fork an exact ID or unique 8-hex UUID prefix
23
27
  ```
24
28
 
25
- Use `/session` in interactive mode to see the current session file, session ID, message count, tokens, and cost. You can use it while a run is active; its totals update after each completed message, not each streaming text chunk. Detailed cost and cache-waste breakdowns are shown after the run finishes only when the available session history matches those totals; otherwise, only the total cost is shown.
29
+ Use `/session` in interactive mode to see the current session ID, message count, tokens, and cost. A JSONL session also has a file location. You can use it while a run is active; its totals update after each completed message, not each streaming text chunk. Detailed cost and cache-waste breakdowns are shown after the run finishes only when the available session history matches those totals; otherwise, only the total cost is shown.
26
30
 
27
31
  For UUID-backed sessions, `--session` and `--fork` accept either the full UUID or exactly eight hexadecimal prefix characters. A prefix must be unique within the current project (or, if no local session matches, across the global session store); collisions list the matching UUIDs and require the full value. Exact custom session IDs keep their existing priority. `--session-id` remains an exact project-local ID used to open or create a session, not a prefix selector.
28
32
 
29
- Session locations are for display, not selection. Use `--import <file>` or `/import <file>` to copy a format-4 JSONL export into the selected store. The session ID and entries are preserved. An ID already present in that store raises `SessionExistsError`; importing never replaces an existing session. Older session formats are not accepted.
33
+ Session locations are for display, not selection. Use `--import <file>` or `/import <file>` to copy a JSONL export into the selected store. The session ID and entries are preserved. An ID already present in that store raises `SessionExistsError`; importing never replaces an existing session. Older supported formats are upgraded automatically when opened for import.
30
34
 
31
35
  Use `atomic --no-session --import <file>` to work with an imported conversation without saving it. `--import` cannot be combined with `--session`, `--fork`, `--session-id`, `--continue`, or `--resume`; choose one way to select the conversation. `--session-dir` remains available when importing into a persistent store.
32
36
 
33
37
  Imported IDs are kept verbatim, including an empty ID. Resume an imported empty ID with `atomic --session ""` or choose its row in the session picker. Picker actions stay bound to the selected project's store even when another project uses the same ID.
34
38
 
35
- ### Custom session directories
39
+ ### Choosing a store
40
+
41
+ ```json
42
+ { "sessions": { "storage": { "dir": "sessions" } } }
43
+ ```
44
+
45
+ This selects JSONL under `~/.atomic/sessions`. Use `{ "path": "sessions.sqlite" }` for another local SQLite file, `{ "memory": true }` for ephemeral sessions, or an adapter selection for a user-installed database driver. The `sessionDir` setting has been removed without an alias.
46
+
47
+ Precedence is SDK `sessionStore`, `--no-session`, `--session-dir <dir>` or `--session-store <path>` (mutually exclusive CLI selections), non-empty `ATOMIC_CODING_AGENT_SESSION_DIR`, `sessions.storage`, shared `storage`, then the default SQLite file. Each selection wins as a whole; project selections replace global ones rather than merging fields. Relative settings paths resolve against Atomic home; CLI paths and environment directories resolve against the working directory. Changing stores selects a different history without migrating sessions; keep the original store to return to it.
48
+
49
+ `--session-store` cannot be combined with `--session-dir` or `--no-session`. `--session-prefix` requires `--session-store` and defaults to empty, giving `session_` table names. A non-empty prefix is prepended to those names, must match `[A-Za-z_][A-Za-z0-9_]*`, and must not start with `sqlite_` (case-insensitive). Invalid configuration or unavailable storage raises a typed error, never a fallback to another store.
36
50
 
37
- Use `--session-dir <dir>`, `ATOMIC_CODING_AGENT_SESSION_DIR`, or the matching settings override to save the active chat outside `~/.atomic/agent/sessions/`.
51
+ Generated SQLite resume hints and Herdr commands always include `--session-store` and include `--session-prefix` when non-empty, regardless of project trust or settings. Keep these flags when reopening the conversation.
52
+
53
+ From the SDK, pass a `SessionStore` or `StorageSelection`:
54
+
55
+ ```ts
56
+ const { session } = await createAgentSession({
57
+ sessionStore: { kind: "sqlite", path: "/data/sessions.sqlite" },
58
+ });
59
+ ```
60
+
61
+ Use `{ kind: "memory" }` for an explicit ephemeral SDK session or `{ kind: "jsonl", dir: "/data/sessions" }` for JSONL. An existing `sessionManager` remains caller-owned and bypasses store selection.
38
62
 
39
63
  Workflows launched from a non-default session directory also save their stage transcripts there. A headless command such as `atomic --mode json --session-dir <dir> -p '/workflow <name> ...'` therefore captures the main and stage transcripts together. An explicit per-stage `sessionDir` overrides the inherited directory.
40
64
 
41
- When the host uses the default session store, stages keep the previous behavior: they write to the global store unless a stage explicitly sets `sessionDir`.
65
+ When the host uses the default store, stages also use the default SQLite database unless they explicitly choose a directory.
42
66
 
43
67
  For the JSONL file format and SessionManager API, see [Session Format](/session-format).
44
68
 
@@ -61,6 +85,8 @@ For the JSONL file format and SessionManager API, see [Session Format](/session-
61
85
 
62
86
  `/resume` opens an interactive session picker for the current project. `atomic -r` opens the same picker at startup.
63
87
 
88
+ Sessions written in formats 1, 2, and 3 appear in the picker and upgrade automatically to format 4 when opened, including with `--continue`, `--session`, or `--fork`. Browsing the picker does not change session files. Opening an older session rewrites only that file; no flag or confirmation is needed.
89
+
64
90
  Resuming restores saved verbatim compaction without another planning request. Older sessions with retired logical-deletion compaction can bring previously hidden content back into context.
65
91
 
66
92
  When you resume at startup with the default tool selection, Atomic restores the tools recorded in the session, including tools activated during the conversation. `--tools +name,-name` modifies that restored selection. Explicit `--tools name,...`, `--no-tools`, and `--no-builtin-tools` keep their requested tool restrictions, and excluded tools stay excluded. Sessions with no recorded tool selection use the current defaults.
@@ -76,11 +102,11 @@ In the picker you can:
76
102
  - rename with CTRL+R
77
103
  - delete with CTRL+D, then confirm
78
104
 
79
- When available, Atomic uses the `trash` CLI for deletion instead of permanently removing files.
105
+ JSONL stores use the `trash` CLI when available. Database stores delete the selected session record, not the database.
80
106
 
81
107
  ### Session summaries
82
108
 
83
- Each row shows a short generated description of what the session was about in its own column, beside the session name or first message, so you can recognize a conversation without opening it. Atomic writes one after the agent goes idle, using the model the session is already configured with, and stores it in the session file as a `session_summary` entry.
109
+ Each row shows a short generated description of what the session was about in its own column, beside the session name or first message, so you can recognize a conversation without opening it. Atomic writes one after the agent goes idle, using the model the session is already configured with, and saves it as a `session_summary` entry in the selected store.
84
110
 
85
111
  A summary describes the conversation up to a specific message and remains visible as newer messages arrive. A later branch summary retires it. "No summary available." means no summary has been generated for the current branch, generation failed, or it is still in flight. The session name and first message are never displaced by a summary, and the column only appears once at least one listed session has a summary. Summaries are also searchable along with the rest of the session text.
86
112
 
@@ -90,9 +116,7 @@ You can search, navigate, or cancel while the picker loads sessions. Closing it
90
116
 
91
117
  ### Internal (workflow) sessions
92
118
 
93
- Sessions created by workflow stage execution are marked as **internal** and are excluded from the standard `/resume`, `atomic -r`, and `--continue` history by default. This keeps the resume picker focused on your interactive coding sessions. Workflow stage sessions remain fully discoverable and resumable through the workflow-specific path: use `/workflow resume <runId>` (or the workflow tool's resume/status actions) to inspect and continue a workflow run and its stages. A workflow stage session can still be opened directly by passing its file path to `--session`.
94
-
95
- Legacy workflow sessions created before this behavior lack the internal marker and will continue to appear in the standard history until they age out or are deleted.
119
+ Sessions created by workflow stage execution are marked as **internal** and are excluded from the standard `/resume`, `atomic -r`, and `--continue` history by default. Use `/workflow resume <runId>` or the workflow tool's resume/status actions to inspect and continue a workflow run and its stages. A workflow stage session can also be opened directly by passing its session ID to `--session`.
96
120
 
97
121
  ## Naming Sessions
98
122
 
@@ -113,7 +137,7 @@ Named sessions are easier to find in `/resume` and `atomic -r`.
113
137
 
114
138
  ## Branching with `/tree`
115
139
 
116
- Sessions are stored as trees. Every entry has an `id` and `parentId`, and the current position is the active leaf. `/tree` lets you jump to any previous point and continue from there without creating a new file.
140
+ Sessions are stored as trees. Every entry has an `id` and `parentId`, and the current position is the active leaf. `/tree` lets you jump to any previous point and continue from there without creating a new session.
117
141
 
118
142
  <p align="center"><img src="images/tree-view.png" alt="Tree View" width="600" /></p>
119
143
 
@@ -166,12 +190,12 @@ Selecting the root user message resets the leaf to an empty conversation and pla
166
190
 
167
191
  | Feature | `/tree` | `/fork` | `/clone` |
168
192
  |---------|---------|---------|----------|
169
- | Output | Same session file | New session file | New session file |
193
+ | Output | Same session | New session | New session |
170
194
  | View | Full tree | User-message selector | Current active branch |
171
195
  | Typical use | Explore alternatives in place | Start a new session from an earlier prompt | Duplicate current work before continuing |
172
196
  | Summary | Optional branch summary | None | None |
173
197
 
174
- Use `/tree` when you want to keep alternatives together. Use `/fork` or `/clone` when you want a separate session file.
198
+ Use `/tree` when you want to keep alternatives together. Use `/fork` or `/clone` when you want a separate session.
175
199
 
176
200
  ## Branch Summaries
177
201
 
@@ -181,6 +205,6 @@ Moved to [Compaction & Branch Summarization](/compaction#branch-summaries).
181
205
 
182
206
  ## Session Format
183
207
 
184
- Session files are JSONL and contain message entries, model changes, thinking-level changes, context-window changes, labels, active verbatim `compaction` boundaries, branch summaries, and extension entries. Retired `context_compaction` and non-verbatim `compaction` records remain parseable but inert.
208
+ Sessions contain message entries, model changes, thinking-level changes, context-window changes, labels, active verbatim `compaction` boundaries, branch summaries, and extension entries. Explicit JSONL stores and exports serialize those entries as JSONL. Retired `context_compaction` and non-verbatim `compaction` records remain parseable but inert.
185
209
 
186
210
  For parsers, extensions, SDK usage, and the full SessionManager API, see [Session Format](/session-format).
package/docs/settings.md CHANGED
@@ -280,7 +280,7 @@ On a genuine first run, Atomic previews available themes and asks whether to opt
280
280
  | Setting | Type | Default | Description |
281
281
  |---------|------|---------|-------------|
282
282
  | `compaction.enabled` | boolean | `true` | Enable automatic verbatim line compaction |
283
- | `compaction.reserveTokens` | number | `16384` | Tokens reserved for the next model response; automatic threshold compaction begins before this reserve is consumed |
283
+ | `compaction.reserveTokens` | number | `16384` | Free context tokens below which automatic compaction starts; does not limit summary output |
284
284
  | `compaction.compression_ratio` | number | `0.5` | Fraction of compactable transcript **lines to keep** (`0 < value < 1`) |
285
285
  | `compaction.preserve_recent` | number | `2` | Exact number of newest context-visible messages kept outside the compactable region; `0` keeps none |
286
286
  | `compaction.query` | string | last user message | Optional relevance focus for selecting older lines to retain |
@@ -323,7 +323,7 @@ Both fields must be non-negative safe integers, including ordinary settings. Inv
323
323
 
324
324
  | Setting | Type | Default | Description |
325
325
  |---------|------|---------|-------------|
326
- | `branchSummary.reserveTokens` | number | `16384` | Tokens reserved when selecting branch history; output is capped at 4096 tokens |
326
+ | `branchSummary.reserveTokens` | number | `16384` | Tokens reserved when selecting branch history; the provider sizes summary output |
327
327
  | `branchSummary.skipPrompt` | boolean | `false` | Skip "Summarize branch?" prompt on `/tree` navigation (defaults to no summary) |
328
328
 
329
329
  ### Session Summary
@@ -500,13 +500,20 @@ Plain names establish a replacement list before its modifiers apply. A project l
500
500
 
501
501
  | Setting | Type | Default | Description |
502
502
  |---------|------|---------|-------------|
503
- | `sessionDir` | string | - | Directory where session files are stored. Accepts absolute or relative paths, plus `~`. |
503
+ | `sessions.storage` | object | Local SQLite | Session-only storage selection: `{ "path": "..." }`, `{ "dir": "..." }`, `{ "memory": true }`, or `{ "adapter": "...", "options": {}, "secrets": {}, "prefix": "..." }`. |
504
+ | `storage` | object | Local SQLite | Shared selection for sessions and workflow runs. Accepts the same forms except `dir`. |
504
505
 
505
506
  ```json
506
- { "sessionDir": ".atomic/sessions" }
507
+ { "sessions": { "storage": { "path": "sessions.sqlite" } } }
507
508
  ```
508
509
 
509
- When multiple sources specify a session directory, precedence is `--session-dir`, `ATOMIC_CODING_AGENT_SESSION_DIR`, then `sessionDir` in settings.json.
510
+ Without configuration, sessions and workflow runs share `~/.atomic/workflows/journal.sqlite`. Session tables use `session_` names; workflow tables use `wf_` names. If `ATOMIC_CODING_AGENT_DIR` changes the agent directory, this default is `workflows/journal.sqlite` under its parent. JSONL is opt-in through `dir`, `--session-dir`, or `ATOMIC_CODING_AGENT_SESSION_DIR`. The `sessionDir` setting has been removed; use `sessions.storage.dir` instead.
511
+
512
+ Session precedence is SDK `sessionStore`, `--no-session`, `--session-dir` or `--session-store` (mutually exclusive CLI selections), non-empty `ATOMIC_CODING_AGENT_SESSION_DIR`, `sessions.storage`, shared `storage`, then the default SQLite file. Empty environment values are ignored. Project selections replace global selections as whole objects, including options, secrets and prefix; fields are never merged. A present empty `sessions.storage` selects the default session database rather than inheriting `storage`. Relative settings paths resolve against Atomic home, normally `~/.atomic`. CLI paths and environment directories resolve against the working directory.
513
+
514
+ See [Choosing a store](/sessions#choosing-a-store) for CLI selection, prefix rules, and conflicts.
515
+
516
+ Only the selected source is validated; invalid lower-precedence selections do not block an explicit override. Memory must be selected explicitly and is lost on exit. Invalid selected configuration raises `StorageConfigError`, whose `source`, `field`, and `reason` identify the problem. If a selected store cannot open, Atomic raises a typed storage error rather than falling back to memory. See [Sessions](/sessions#session-storage) and [Storage errors](/storage#storage-errors).
510
517
 
511
518
  ### Models
512
519
 
@@ -555,7 +562,7 @@ Arrays support glob patterns and exclusions. Use `!pattern` to exclude. Use `+pa
555
562
 
556
563
  #### Workflow storage
557
564
 
558
- Workflow runs use a local SQLite journal at `~/.atomic/workflows/journal.sqlite`. Set `workflows.journal.path` in `settings.json` to choose another file:
565
+ Workflow runs use a SQLite journal, by default the local file `~/.atomic/workflows/journal.sqlite`. Set `workflows.journal.path` in `settings.json` to choose another file:
559
566
 
560
567
  ```json
561
568
  {
@@ -566,13 +573,28 @@ Workflow runs use a local SQLite journal at `~/.atomic/workflows/journal.sqlite`
566
573
  }
567
574
  ```
568
575
 
569
- Relative settings paths resolve against the Atomic home directory, normally `~/.atomic`, not the project directory. A non-empty `ATOMIC_WORKFLOW_JOURNAL_PATH` overrides the settings path. SDK `RunOpts.journal` takes precedence over both. Empty environment and settings paths leave the next source in effect.
576
+ Relative settings paths resolve against the Atomic home directory, normally `~/.atomic`, not the project directory. Precedence is SDK `RunOpts.journal`, non-empty `ATOMIC_WORKFLOW_JOURNAL_PATH`, `workflows.journal`, shared top-level `storage`, then the default journal file. An empty environment variable is ignored. A present empty journal block selects the journal default rather than inheriting shared storage.
570
577
 
571
578
  To keep workflow records only in memory, set `"journal": { "memory": true }`. Do not combine `memory: true` with a non-empty `path`. Memory must be selected explicitly and cannot recover runs after the process exits; an environment path still takes precedence over this setting.
572
579
 
573
- Project `workflows.journal` replaces the global journal block as a whole. For example, a project can select `{ "memory": true }` over a global path, or a project path over global memory. Within either settings file, combining `memory: true` with a non-empty `path` is still an error.
580
+ Project `workflows.journal` and `storage` each replace their global selection as a whole, including options, secrets, and prefix. For example, a project can select `{ "memory": true }` over a global path. Invalid selected settings raise `StorageConfigError` instead of trying a lower-precedence selection. Combining `memory: true` with a non-empty `path` is an error.
581
+
582
+ To use your own database driver, install an adapter module and select it by module specifier:
583
+
584
+ ```json
585
+ {
586
+ "storage": {
587
+ "adapter": "@example/atomic-sqlite",
588
+ "options": { "url": "libsql://database.example" },
589
+ "secrets": { "authToken": { "env": "DATABASE_TOKEN" } },
590
+ "prefix": "project_"
591
+ }
592
+ }
593
+ ```
594
+
595
+ The shared `storage` setting supplies defaults for both sessions and the journal. Use `sessions.storage` or `workflows.journal` for a domain-only override. A shared empty selection uses `~/.atomic/storage.sqlite`. Atomic bundles no remote driver. Adapter modules execute code, so review them before trusting project settings. Secret references accept `{ "env": "VARIABLE" }` or `{ "file": "token.txt" }`; relative secret files resolve against Atomic home and their contents are passed verbatim. See [Storage adapters](/storage#selecting-an-adapter).
574
596
 
575
- Changing the journal selects a different run history. Preserve the original file to inspect or resume its runs. Storage needs no separate server. If the selected journal cannot be opened or written, the action fails with a typed storage error rather than selecting memory. Restore filesystem access and inspect the retained run before retrying. See [Durable workflows](/workflows/operations#durable-workflows-and-cross-session-resume).
597
+ Changing the journal selects a different run history. Preserve the original file to inspect or resume its runs. The default local file needs no separate server; a remote database requires an adapter, and every host that shares runs must select the same database and prefix. See [Sharing storage across hosts](/storage#sharing-storage-across-hosts). If the selected journal cannot be opened or written, the action fails with a typed storage error rather than selecting memory. Restore access to the store and inspect the retained run before retrying. See [Durable workflows](/workflows/operations#durable-workflows-and-cross-session-resume).
576
598
 
577
599
  #### packages
578
600
 
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";
@@ -58,7 +60,7 @@ try {
58
60
  }
59
61
  ```
60
62
 
61
- The returned value can be passed to your own SDK application code that accepts `SqliteDatabase`. This does not select a custom driver for Atomic sessions or workflow runs.
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.
62
64
 
63
65
  <details>
64
66
  <summary>Complete wrapper</summary>
@@ -286,6 +288,87 @@ export async function openLibsqlDatabase(options: LibsqlDatabaseOptions): Promis
286
288
 
287
289
  </details>
288
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
+
289
372
  ## Adapter conformance
290
373
 
291
374
  Implement `SqliteDatabase` and run the exported suite from `@bastani/atomic/storage/testing`:
@@ -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
 
@@ -1331,7 +1333,7 @@ interface RunOpts {
1331
1333
  readonly signal?: AbortSignal;
1332
1334
  readonly deferWorkflowStart?: boolean;
1333
1335
  readonly config?: WorkflowRuntimeConfig;
1334
- readonly journal?: { path: string } | { database: DatabaseSync } | { memory: true } | RunJournal;
1336
+ readonly journal?: RunJournalOption;
1335
1337
  readonly models?: WorkflowModelCatalogPort;
1336
1338
  readonly registry?: WorkflowRegistry;
1337
1339
  readonly depth?: number;
@@ -1362,20 +1364,18 @@ The public authoring declaration intentionally excludes runtime-only executor fi
1362
1364
  #### Choosing the durable backend
1363
1365
 
1364
1366
  ```typescript
1365
- import type { DatabaseSync } from "node:sqlite";
1366
- import type { RunJournal } from "@bastani/atomic/workflows";
1367
-
1368
- type JournalOption = { path: string } | { database: DatabaseSync } | { memory: true } | RunJournal;
1367
+ import type { RunJournalOption } from "@bastani/atomic/workflows";
1369
1368
  ```
1370
1369
 
1371
- `run()` uses a local SQLite journal by default and releases the run's lease when execution settles. Select a journal with `RunOpts.journal`:
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`:
1372
1371
 
1373
1372
  - `{ path }` opens that SQLite file.
1374
- - `{ database }` uses a caller-owned `node:sqlite` connection. Atomic initializes the journal schema on it but does not close the connection.
1373
+ - `{ database, prefix? }` uses a caller-owned async `SqliteDatabase` facade. Atomic initializes the journal schema on it but does not close the database.
1375
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
1376
  - A `RunJournal` instance is used as supplied. `SqlRunJournal`, `openSqlRunJournal`, `MemoryRunJournal`, journal error classes, and `registerRunJournalConformance` are exported from `@bastani/atomic/workflows`.
1377
1377
 
1378
- Use `await openSqlRunJournal(path)` to open a file directly, or omit `path` for the default journal. It also accepts a caller-owned `DatabaseSync`. `await resolveRunJournal(options)` applies the selection rules below.
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
1379
 
1380
1380
  To attach your own SQLite-compatible driver, implement the [async SQLite storage API](/storage) and pass its facade to `SqlRunJournal.open`:
1381
1381
 
@@ -1425,9 +1425,9 @@ interface RunJournal {
1425
1425
 
1426
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.
1427
1427
 
1428
- 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 a `restore()` method, so the suite can verify lazy reads without consuming the whole history. Synchronous backend fast paths are internal and are not part of the custom-journal contract.
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
1429
 
1430
- Precedence is `RunOpts.journal`, non-empty `ATOMIC_WORKFLOW_JOURNAL_PATH`, `workflows.journal.path` or `workflows.journal.memory`, then the default `~/.atomic/workflows/journal.sqlite`. Relative settings paths resolve against the Atomic home directory. Storage failures reject the call; Atomic never selects memory as a recovery step. Keep the same journal and working directory when resuming stored runs.
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.
1431
1431
 
1432
1432
  ```ts
1433
1433
  import { run } from "@bastani/atomic/workflows";
@@ -1436,6 +1436,14 @@ await run(helloWorld, { name: "Atomic" }, { journal: { path: "./workflow-runs.sq
1436
1436
  await run(helloWorld, { name: "Atomic" }, { journal: { memory: true } });
1437
1437
  ```
1438
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
+
1439
1447
  ### `resolveInputs(schema, provided)`
1440
1448
 
1441
1449
  ```typescript
@@ -458,7 +458,7 @@ 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
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
 
@@ -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,7 @@ That history does not authorize any live release action.
653
653
 
654
654
  ### Configuring journal storage
655
655
 
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`.
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
657
 
658
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).
659
659
 
@@ -529,7 +529,7 @@ Ordinary `intercom` is enabled by default but respects `tools`, `excludedTools`,
529
529
  - Persist decisions under stable keys. Pause/resume, model fallback, durable replay, and nested workflows then reread the artifact instead of sending duplicate interventions.
530
530
  - Omit `group` for ordinary use. The worker, guard, nested workflows, and delegated subagents inherit the top-level workflow invocation's stable Intercom group. Set an explicit group only for intentional isolation; an override isolates that stage from ordinary same-group peers while leaving it steerable from the invocation context, which retains directional list/send/live-ask control over the subgroups it owns.
531
531
  - Use `context: "fresh"` for guards, reviewers, and judges. They should see only the contract, candidate, decision artifacts, and current files.
532
- - Use `context: "fork"` plus `forkFromSessionFile` for implementation, debugging, and repair roles that need continuity with an owned earlier session. `context: "fork"` alone does not name a fork source; an initial worker with no prior lineage may start fresh. A later continuation should use the earlier worker's `sessionFile` when available. Do not fork an independent guard from the worker it judges.
532
+ - Use `context: "fork"` plus `forkFromSessionId` for implementation, debugging, and repair roles that need continuity with an owned earlier session. `context: "fork"` alone does not name a fork source; an initial worker with no prior lineage may start fresh. A later continuation should use the earlier worker's `sessionId` in the selected session store when available. Do not fork an independent guard from the worker it judges.
533
533
  - Send a forked continuation only the delta after the fork point: new evidence, the decision artifact, any human answer, and the next action. Keep the full shared contract in its canonical file.
534
534
 
535
535
  Expected lifecycle state is not a defect. If the contract says `candidate → validation → approval → push/publish`, a guard at the candidate or validation boundary must not reject the patch merely because it is unpushed or unpublished. Only the later publication stage owns that action.
@@ -568,10 +568,10 @@ const decisionLogSchema = Type.Object(
568
568
 
569
569
  type DecisionLog = Static<typeof decisionLogSchema>;
570
570
 
571
- function continueWorker(sessionFile: string | undefined) {
572
- return sessionFile === undefined
571
+ function continueWorker(sessionId: string | undefined) {
572
+ return sessionId === undefined
573
573
  ? { context: "fork" as const }
574
- : { context: "fork" as const, forkFromSessionFile: sessionFile };
574
+ : { context: "fork" as const, forkFromSessionId: sessionId };
575
575
  }
576
576
 
577
577
  export default workflow({
@@ -627,7 +627,7 @@ export default workflow({
627
627
  ].join("\n"));
628
628
 
629
629
  await ctx.task("continue worker", {
630
- ...continueWorker(worker.sessionFile),
630
+ ...continueWorker(worker.sessionId),
631
631
  reads: [contract, decisionLog],
632
632
  prompt: [
633
633
  `Read the decision log at ${decisionLog}.`,
@@ -653,10 +653,10 @@ Use `ctx.stage(...)` when one independent checker needs a retained conversation.
653
653
  import { workflow } from "@bastani/atomic/workflows";
654
654
  import { Type } from "typebox";
655
655
 
656
- function continueWorker(sessionFile: string | undefined) {
657
- return sessionFile === undefined
656
+ function continueWorker(sessionId: string | undefined) {
657
+ return sessionId === undefined
658
658
  ? { context: "fork" as const }
659
- : { context: "fork" as const, forkFromSessionFile: sessionFile };
659
+ : { context: "fork" as const, forkFromSessionId: sessionId };
660
660
  }
661
661
 
662
662
  export default workflow({
@@ -703,7 +703,7 @@ export default workflow({
703
703
  );
704
704
 
705
705
  await ctx.task("apply retained decision", {
706
- ...continueWorker(worker.sessionFile),
706
+ ...continueWorker(worker.sessionId),
707
707
  reads: [contract, decisionLog],
708
708
  prompt: [
709
709
  `Read ${decisionLog}.`,
@@ -742,10 +742,10 @@ const coordinationSchema = Type.Object(
742
742
 
743
743
  type Coordination = Static<typeof coordinationSchema>;
744
744
 
745
- function workerContext(sessionFile: string | undefined) {
746
- return sessionFile === undefined
745
+ function workerContext(sessionId: string | undefined) {
746
+ return sessionId === undefined
747
747
  ? { context: "fresh" as const }
748
- : { context: "fork" as const, forkFromSessionFile: sessionFile };
748
+ : { context: "fork" as const, forkFromSessionId: sessionId };
749
749
  }
750
750
 
751
751
  export default workflow({
@@ -753,7 +753,7 @@ export default workflow({
753
753
  description: "Run a worker with a live same-group scope peer.",
754
754
  inputs: {
755
755
  scope_contract: Type.String(),
756
- worker_session_file: Type.Optional(Type.String({
756
+ worker_session_id: Type.Optional(Type.String({
757
757
  description: "Earlier worker session to continue; omit when no worker lineage exists.",
758
758
  })),
759
759
  fallback_policy: Type.Union([
@@ -778,7 +778,7 @@ export default workflow({
778
778
  [
779
779
  {
780
780
  name: "worker",
781
- ...workerContext(ctx.inputs.worker_session_file),
781
+ ...workerContext(ctx.inputs.worker_session_id),
782
782
  reads: [contract],
783
783
  prompt: [
784
784
  `Read the immutable scope contract at ${contract}.`,
@@ -910,11 +910,11 @@ State important constraints once. Reserve absolute wording for safety, required
910
910
 
911
911
  Avoid unrelated workflow internals such as reducer algorithms, future PR stages, sibling reviewer names, loop implementation details, or project-specific nicknames unless they are explicitly part of the current stage contract. If a term such as a gate name, ledger field, or workflow nickname is necessary, define it in the prompt before using it.
912
912
 
913
- Choose context mode deliberately. Use `context: "fork"` or `forkFromSessionFile` for coherent long-running implementation stages that need continuity from their own earlier work. Use `context: "fresh"` for unbiased reviewer, evaluator, and gate stages so they inspect the current files and explicit artifacts rather than inheriting the implementer's assumptions. When continuity is needed across fresh stages, pass it explicitly through files, declared outputs, and `reads`.
913
+ Choose context mode deliberately. Use `context: "fork"` or `forkFromSessionId` for coherent long-running implementation stages that need continuity from their own earlier work. Use `context: "fresh"` for unbiased reviewer, evaluator, and gate stages so they inspect the current files and explicit artifacts rather than inheriting the implementer's assumptions. When continuity is needed across fresh stages, pass it explicitly through files, declared outputs, and `reads`.
914
914
 
915
915
  ### Context-Mode-Aware Prompt Text
916
916
 
917
- Context mode is an execution property configured with `context`/`forkFromSessionFile`; the model cannot act on context mode, so keep it out of prompt text:
917
+ Context mode is an execution property configured with `context`/`forkFromSessionId`; the model cannot act on context mode, so keep it out of prompt text:
918
918
 
919
919
  - **Never describe the stage's own context mode.** Sentences like "you are running in a fresh context window", "your context is clean/non-forked", or "this is a forked session" add tokens without changing behavior. State the concrete action, inputs, and success criteria instead.
920
920
  - **Fresh stages must not reference invisible context.** A fresh stage has no "previous conversation", cannot see sibling stages' transcripts, and does not know the surrounding graph, so instructions like "compare against previous workflow reasoning" or "this runs in parallel with the locator pass" do not help and may confuse the model. Phrase the same intent stage-locally ("compare the working tree against the baseline branch"; "do your own scan; do not assume any other stage's output is available") and pass any state the stage needs through files, declared outputs, and `reads`. If a stage should talk to a live peer, say so explicitly and tell it how to find that peer with `intercom list`; see [peer coordination between stages](#peer-coordination-between-stages).