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

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 (214) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  3. package/dist/builtin/intercom/index.bundle.mjs +11 -7
  4. package/dist/builtin/intercom/package.json +1 -1
  5. package/dist/builtin/mcp/package.json +1 -1
  6. package/dist/builtin/subagents/package.json +1 -1
  7. package/dist/builtin/web-access/package.json +1 -1
  8. package/dist/builtin/workflows/CHANGELOG.md +31 -0
  9. package/dist/builtin/workflows/README.md +5 -10
  10. package/dist/builtin/workflows/builtin/adversarial-verification.js +2 -2
  11. package/dist/builtin/workflows/builtin/{chunk-94f8zfz1.js → chunk-454hz1qt.js} +1 -1
  12. package/dist/builtin/workflows/builtin/{chunk-wf876n16.js → chunk-4bwtzyjq.js} +1 -1
  13. package/dist/builtin/workflows/builtin/{chunk-kb7s3gx2.js → chunk-5eh0brtd.js} +1 -1
  14. package/dist/builtin/workflows/builtin/{chunk-r97ndfvt.js → chunk-bjva9j5k.js} +1 -1
  15. package/dist/builtin/workflows/builtin/{chunk-x6az1sxp.js → chunk-h5fn47y5.js} +1 -1
  16. package/dist/builtin/workflows/builtin/chunk-na3wpwzh.js +3115 -0
  17. package/dist/builtin/workflows/builtin/{chunk-nkj4qhj6.js → chunk-q7dx7kh7.js} +1 -1
  18. package/dist/builtin/workflows/builtin/{chunk-a1ar035d.js → chunk-qdd897wm.js} +1 -1
  19. package/dist/builtin/workflows/builtin/{chunk-gyjck9z8.js → chunk-qjqn389g.js} +1 -1
  20. package/dist/builtin/workflows/builtin/{chunk-ad83gc5p.js → chunk-qrrkfg9v.js} +5 -12
  21. package/dist/builtin/workflows/builtin/{chunk-632fxeb8.js → chunk-x0vvjyzg.js} +1 -1
  22. package/dist/builtin/workflows/builtin/{chunk-3n2bnz64.js → chunk-xg7kkgf8.js} +2 -2
  23. package/dist/builtin/workflows/builtin/classify-and-act.js +2 -2
  24. package/dist/builtin/workflows/builtin/fan-out-and-synthesize.js +2 -2
  25. package/dist/builtin/workflows/builtin/generate-and-filter.js +2 -2
  26. package/dist/builtin/workflows/builtin/goal.js +3 -3
  27. package/dist/builtin/workflows/builtin/index.js +11 -11
  28. package/dist/builtin/workflows/builtin/loop-until-done.js +2 -2
  29. package/dist/builtin/workflows/builtin/open-claude-design.js +2 -2
  30. package/dist/builtin/workflows/builtin/ralph.js +3 -3
  31. package/dist/builtin/workflows/builtin/tournament.js +2 -2
  32. package/dist/builtin/workflows/package.json +1 -1
  33. package/dist/builtin/workflows/src/authoring.d.ts +8 -6
  34. package/dist/builtin/workflows/src/durable/journal/conformance.d.ts +4 -0
  35. package/dist/builtin/workflows/src/durable/journal/memory-run-journal.d.ts +27 -0
  36. package/dist/builtin/workflows/src/durable/journal/node-sqlite.d.ts +20 -0
  37. package/dist/builtin/workflows/src/durable/journal/resolution.d.ts +21 -0
  38. package/dist/builtin/workflows/src/durable/journal/sqlite-run-journal.d.ts +49 -0
  39. package/dist/builtin/workflows/src/durable/journal/types.d.ts +200 -0
  40. package/dist/builtin/workflows/src/durable/journal/values.d.ts +3 -0
  41. package/dist/builtin/workflows/src/extension/index.bundle.mjs +51825 -88089
  42. package/dist/builtin/workflows/src/index.js +9366 -45320
  43. package/dist/builtin/workflows/src/shared/authoring-contract-stage.d.ts +0 -6
  44. package/dist/builtin/workflows/src/shared/authoring-contract-ui.d.ts +4 -6
  45. package/dist/bun/split-loader.js +0 -13
  46. package/dist/bun/split-loader.js.map +1 -1
  47. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  48. package/dist/core/agent-session-compaction.js +1 -0
  49. package/dist/core/agent-session-compaction.js.map +1 -1
  50. package/dist/core/agent-session-tree.d.ts.map +1 -1
  51. package/dist/core/agent-session-tree.js +1 -0
  52. package/dist/core/agent-session-tree.js.map +1 -1
  53. package/dist/core/compaction/branch-summarization.d.ts +2 -1
  54. package/dist/core/compaction/branch-summarization.d.ts.map +1 -1
  55. package/dist/core/compaction/branch-summarization.js +6 -6
  56. package/dist/core/compaction/branch-summarization.js.map +1 -1
  57. package/dist/core/compaction/compaction-runner.d.ts +1 -0
  58. package/dist/core/compaction/compaction-runner.d.ts.map +1 -1
  59. package/dist/core/compaction/compaction-runner.js +4 -1
  60. package/dist/core/compaction/compaction-runner.js.map +1 -1
  61. package/dist/core/compaction/pi-summary-fallback.d.ts +2 -1
  62. package/dist/core/compaction/pi-summary-fallback.d.ts.map +1 -1
  63. package/dist/core/compaction/pi-summary-fallback.js +5 -5
  64. package/dist/core/compaction/pi-summary-fallback.js.map +1 -1
  65. package/dist/core/compaction/utils.d.ts +2 -1
  66. package/dist/core/compaction/utils.d.ts.map +1 -1
  67. package/dist/core/compaction/utils.js +32 -7
  68. package/dist/core/compaction/utils.js.map +1 -1
  69. package/dist/core/extensions/index.d.ts +1 -1
  70. package/dist/core/extensions/index.d.ts.map +1 -1
  71. package/dist/core/extensions/index.js +1 -1
  72. package/dist/core/extensions/index.js.map +1 -1
  73. package/dist/core/extensions/workflow-run-control.d.ts +3 -3
  74. package/dist/core/extensions/workflow-run-control.d.ts.map +1 -1
  75. package/dist/core/extensions/workflow-run-control.js +4 -4
  76. package/dist/core/extensions/workflow-run-control.js.map +1 -1
  77. package/dist/core/model-resolver-defaults.js +4 -4
  78. package/dist/core/model-resolver-defaults.js.map +1 -1
  79. package/dist/core/session-manager-archive.d.ts.map +1 -1
  80. package/dist/core/session-manager-archive.js +3 -8
  81. package/dist/core/session-manager-archive.js.map +1 -1
  82. package/dist/core/session-manager-core.d.ts.map +1 -1
  83. package/dist/core/session-manager-core.js +14 -20
  84. package/dist/core/session-manager-core.js.map +1 -1
  85. package/dist/core/session-manager-list.d.ts.map +1 -1
  86. package/dist/core/session-manager-list.js +4 -13
  87. package/dist/core/session-manager-list.js.map +1 -1
  88. package/dist/core/session-manager-storage.d.ts +1 -0
  89. package/dist/core/session-manager-storage.d.ts.map +1 -1
  90. package/dist/core/session-manager-storage.js +49 -24
  91. package/dist/core/session-manager-storage.js.map +1 -1
  92. package/dist/core/session-manager-types.d.ts +2 -2
  93. package/dist/core/session-manager-types.d.ts.map +1 -1
  94. package/dist/core/session-manager-types.js +2 -1
  95. package/dist/core/session-manager-types.js.map +1 -1
  96. package/dist/core/session-manager-validation.d.ts +3 -0
  97. package/dist/core/session-manager-validation.d.ts.map +1 -1
  98. package/dist/core/session-manager-validation.js +16 -0
  99. package/dist/core/session-manager-validation.js.map +1 -1
  100. package/dist/core/session-manager.d.ts +1 -2
  101. package/dist/core/session-manager.d.ts.map +1 -1
  102. package/dist/core/session-manager.js +1 -2
  103. package/dist/core/session-manager.js.map +1 -1
  104. package/dist/core/settings-schema.d.ts +4 -0
  105. package/dist/core/settings-schema.d.ts.map +1 -1
  106. package/dist/core/settings-schema.js +9 -0
  107. package/dist/core/settings-schema.js.map +1 -1
  108. package/dist/core/storage/database.d.ts +21 -0
  109. package/dist/core/storage/database.d.ts.map +1 -0
  110. package/dist/core/storage/database.js +2 -0
  111. package/dist/core/storage/database.js.map +1 -0
  112. package/dist/core/storage/errors.d.ts +63 -0
  113. package/dist/core/storage/errors.d.ts.map +1 -0
  114. package/dist/core/storage/errors.js +103 -0
  115. package/dist/core/storage/errors.js.map +1 -0
  116. package/dist/core/storage/index.d.ts +6 -0
  117. package/dist/core/storage/index.d.ts.map +1 -0
  118. package/dist/core/storage/index.js +5 -0
  119. package/dist/core/storage/index.js.map +1 -0
  120. package/dist/core/storage/node-sqlite.d.ts +5 -0
  121. package/dist/core/storage/node-sqlite.d.ts.map +1 -0
  122. package/dist/core/storage/node-sqlite.js +161 -0
  123. package/dist/core/storage/node-sqlite.js.map +1 -0
  124. package/dist/core/storage/prefix.d.ts +5 -0
  125. package/dist/core/storage/prefix.d.ts.map +1 -0
  126. package/dist/core/storage/prefix.js +15 -0
  127. package/dist/core/storage/prefix.js.map +1 -0
  128. package/dist/core/storage/schema.d.ts +3 -0
  129. package/dist/core/storage/schema.d.ts.map +1 -0
  130. package/dist/core/storage/schema.js +6 -0
  131. package/dist/core/storage/schema.js.map +1 -0
  132. package/dist/core/storage/session/conformance.d.ts +12 -0
  133. package/dist/core/storage/session/conformance.d.ts.map +1 -0
  134. package/dist/core/storage/session/conformance.js +674 -0
  135. package/dist/core/storage/session/conformance.js.map +1 -0
  136. package/dist/core/storage/session/entry-structure.d.ts +4 -0
  137. package/dist/core/storage/session/entry-structure.d.ts.map +1 -0
  138. package/dist/core/storage/session/entry-structure.js +83 -0
  139. package/dist/core/storage/session/entry-structure.js.map +1 -0
  140. package/dist/core/storage/session/errors.d.ts +54 -0
  141. package/dist/core/storage/session/errors.d.ts.map +1 -0
  142. package/dist/core/storage/session/errors.js +95 -0
  143. package/dist/core/storage/session/errors.js.map +1 -0
  144. package/dist/core/storage/session/jsonl-session-store.d.ts +57 -0
  145. package/dist/core/storage/session/jsonl-session-store.d.ts.map +1 -0
  146. package/dist/core/storage/session/jsonl-session-store.js +482 -0
  147. package/dist/core/storage/session/jsonl-session-store.js.map +1 -0
  148. package/dist/core/storage/session/memory-session-store.d.ts +31 -0
  149. package/dist/core/storage/session/memory-session-store.d.ts.map +1 -0
  150. package/dist/core/storage/session/memory-session-store.js +113 -0
  151. package/dist/core/storage/session/memory-session-store.js.map +1 -0
  152. package/dist/core/storage/session/scratch-directory.d.ts +2 -0
  153. package/dist/core/storage/session/scratch-directory.d.ts.map +1 -0
  154. package/dist/core/storage/session/scratch-directory.js +5 -0
  155. package/dist/core/storage/session/scratch-directory.js.map +1 -0
  156. package/dist/core/storage/session/session-summary.d.ts +24 -0
  157. package/dist/core/storage/session/session-summary.d.ts.map +1 -0
  158. package/dist/core/storage/session/session-summary.js +79 -0
  159. package/dist/core/storage/session/session-summary.js.map +1 -0
  160. package/dist/core/storage/session/sql-session-store.d.ts +46 -0
  161. package/dist/core/storage/session/sql-session-store.d.ts.map +1 -0
  162. package/dist/core/storage/session/sql-session-store.js +227 -0
  163. package/dist/core/storage/session/sql-session-store.js.map +1 -0
  164. package/dist/core/storage/session/types.d.ts +68 -0
  165. package/dist/core/storage/session/types.d.ts.map +1 -0
  166. package/dist/core/storage/session/types.js +2 -0
  167. package/dist/core/storage/session/types.js.map +1 -0
  168. package/dist/core/storage/session/validation.d.ts +7 -0
  169. package/dist/core/storage/session/validation.d.ts.map +1 -0
  170. package/dist/core/storage/session/validation.js +47 -0
  171. package/dist/core/storage/session/validation.js.map +1 -0
  172. package/dist/core/storage/testing.d.ts +13 -0
  173. package/dist/core/storage/testing.d.ts.map +1 -0
  174. package/dist/core/storage/testing.js +264 -0
  175. package/dist/core/storage/testing.js.map +1 -0
  176. package/dist/index-extensions.d.ts +1 -1
  177. package/dist/index-extensions.d.ts.map +1 -1
  178. package/dist/index-extensions.js +1 -1
  179. package/dist/index-extensions.js.map +1 -1
  180. package/dist/index.d.ts +2 -1
  181. package/dist/index.d.ts.map +1 -1
  182. package/dist/index.js +2 -1
  183. package/dist/index.js.map +1 -1
  184. package/dist/modes/interactive/components/chat-session-host.d.ts +1 -1
  185. package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
  186. package/dist/modes/interactive/components/chat-session-host.js +8 -4
  187. package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
  188. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  189. package/dist/modes/interactive/components/scoped-models-selector.js +5 -4
  190. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  191. package/dist/modes/interactive/interactive-queueing.js +8 -5
  192. package/dist/modes/interactive/interactive-queueing.js.map +1 -1
  193. package/docs/docs.json +1 -0
  194. package/docs/getting-started/installation.md +1 -2
  195. package/docs/json.md +1 -1
  196. package/docs/packages/authoring.md +1 -1
  197. package/docs/sdk/reference.md +1 -1
  198. package/docs/sdk/web-server.md +5 -5
  199. package/docs/sdk.md +11 -25
  200. package/docs/session-format.md +4 -10
  201. package/docs/settings.md +5 -29
  202. package/docs/storage.md +43 -0
  203. package/docs/workflows/api-reference.md +17 -55
  204. package/docs/workflows/authoring.md +2 -1
  205. package/docs/workflows/operations.md +31 -175
  206. package/docs/workflows/reliable-design.md +1 -1
  207. package/npm-shrinkwrap.json +32 -448
  208. package/package.json +13 -6
  209. package/schemas/settings.schema.json +27 -0
  210. package/dist/builtin/workflows/builtin/chunk-ymwq372z.js +0 -11609
  211. package/dist/core/session-manager-migrations.d.ts +0 -11
  212. package/dist/core/session-manager-migrations.d.ts.map +0 -1
  213. package/dist/core/session-manager-migrations.js +0 -80
  214. package/dist/core/session-manager-migrations.js.map +0 -1
@@ -85,11 +85,13 @@ InteractiveModeBase.prototype.flushCompactionQueue = async function (options) {
85
85
  const queuedMessages = [...this.compactionQueuedMessages];
86
86
  this.compactionQueuedMessages = [];
87
87
  this.updatePendingMessagesDisplay();
88
- const restoreQueue = (error) => {
89
- this.session.clearQueue();
90
- this.compactionQueuedMessages = queuedMessages;
88
+ const restoreQueue = (error, messages = queuedMessages) => {
89
+ this.compactionQueuedMessages = [
90
+ ...messages,
91
+ ...this.compactionQueuedMessages.filter((message) => !messages.includes(message)),
92
+ ];
91
93
  this.updatePendingMessagesDisplay();
92
- this.showError(`Failed to send queued message${queuedMessages.length > 1 ? "s" : ""}: ${error instanceof Error ? error.message : String(error)}`);
94
+ this.showError(`Failed to send queued message${messages.length > 1 ? "s" : ""}: ${error instanceof Error ? error.message : String(error)}`);
93
95
  };
94
96
  try {
95
97
  if (!options?.willRetry && (this.session.isStreaming || this.session.queuedMessagesPaused)) {
@@ -134,7 +136,7 @@ InteractiveModeBase.prototype.flushCompactionQueue = async function (options) {
134
136
  const promptPromise = this.session
135
137
  .prompt(firstPrompt.text, { streamingBehavior: firstPrompt.mode })
136
138
  .catch((error) => {
137
- restoreQueue(error);
139
+ restoreQueue(error, [firstPrompt]);
138
140
  });
139
141
  // Queue remaining messages
140
142
  for (const message of rest) {
@@ -152,6 +154,7 @@ InteractiveModeBase.prototype.flushCompactionQueue = async function (options) {
152
154
  void promptPromise;
153
155
  }
154
156
  catch (error) {
157
+ this.session.clearQueue();
155
158
  restoreQueue(error);
156
159
  }
157
160
  };
@@ -1 +1 @@
1
- {"version":3,"file":"interactive-queueing.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-queueing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAE1G,mBAAmB,CAAC,SAAS,CAAC,oBAAoB,GAAG;IAIpD,OAAO;QACN,QAAQ,EAAE;YACT,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE;YACrC,GAAG,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;SAC7F;QACD,QAAQ,EAAE;YACT,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE;YACrC,GAAG,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC;SAChG;KACD,CAAC;AACH,CAAC,CAAC;AAEF,mBAAmB,CAAC,SAAS,CAAC,cAAc,GAAG,UAE9C,OAAyD;IAKzD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAChE,MAAM,kBAAkB,GAAG,IAAI,CAAC,wBAAwB;SACtD,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,K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esForEditor, Spacer, TruncatedText, theme } from \"./interactive-mode-deps.ts\";\n\nInteractiveModeBase.prototype.getAllQueuedMessages = function (this: InteractiveModeBase): {\n\tsteering: string[];\n\tfollowUp: string[];\n} {\n\treturn {\n\t\tsteering: [\n\t\t\t...this.session.getSteeringMessages(),\n\t\t\t...this.compactionQueuedMessages.filter((msg) => msg.mode === \"steer\").map((msg) => msg.text),\n\t\t],\n\t\tfollowUp: [\n\t\t\t...this.session.getFollowUpMessages(),\n\t\t\t...this.compactionQueuedMessages.filter((msg) => msg.mode === \"followUp\").map((msg) => msg.text),\n\t\t],\n\t};\n};\n\nInteractiveModeBase.prototype.clearAllQueues = function (\n\tthis: InteractiveModeBase,\n\toptions?: { preserveUnprotectedCustomMessages?: boolean },\n): {\n\tsteering: string[];\n\tfollowUp: string[];\n} {\n\tconst { steering, followUp } = this.session.clearQueue(options);\n\tconst compactionSteering = this.compactionQueuedMessages\n\t\t.filter((msg) => msg.mode === \"steer\")\n\t\t.map((msg) => msg.text);\n\tconst compactionFollowUp = this.compactionQueuedMessages\n\t\t.filter((msg) => msg.mode === \"followUp\")\n\t\t.map((msg) => msg.text);\n\tthis.compactionQueuedMessages = [];\n\treturn {\n\t\tsteering: [...steering, ...compactionSteering],\n\t\tfollowUp: [...followUp, ...compactionFollowUp],\n\t};\n};\n\nInteractiveModeBase.prototype.updatePendingMessagesDisplay = function (this: InteractiveModeBase): void {\n\tthis.pendingMessagesContainer.clear();\n\tconst { steering: steeringMessages, followUp: followUpMessages } = this.getAllQueuedMessages();\n\tif (steeringMessages.length > 0 || followUpMessages.length > 0) {\n\t\tthis.pendingMessagesContainer.addChild(new Spacer(1));\n\t\tfor (const message of steeringMessages) {\n\t\t\tconst text = theme.fg(\"dim\", `Steering: ${message}`);\n\t\t\tthis.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));\n\t\t}\n\t\tfor (const message of followUpMessages) {\n\t\t\tconst text = theme.fg(\"dim\", `Follow-up: ${message}`);\n\t\t\tthis.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));\n\t\t}\n\t\tconst dequeueHint = this.getAppKeyDisplay(\"app.message.dequeue\");\n\t\tconst hintText = theme.fg(\"dim\", `↳ ${dequeueHint} to edit all queued messages`);\n\t\tthis.pendingMessagesContainer.addChild(new TruncatedText(hintText, 1, 0));\n\t}\n};\n\nInteractiveModeBase.prototype.restoreQueuedMessagesToEditor = function (\n\tthis: InteractiveModeBase,\n\toptions?: {\n\t\tabort?: boolean;\n\t\tcurrentText?: string;\n\t\tpreserveUnprotectedCustomMessages?: boolean;\n\t},\n): number {\n\tconst { steering, followUp } = this.clearAllQueues(options);\n\tconst allQueued = [...steering, ...followUp];\n\tif (allQueued.length === 0) {\n\t\tthis.updatePendingMessagesDisplay();\n\t\tif (options?.abort) {\n\t\t\tvoid this.session.abort();\n\t\t}\n\t\treturn 0;\n\t}\n\tconst currentText = options?.currentText ?? this.editor.getText();\n\tconst combinedText = combineQueuedMessagesForEditor(allQueued, currentText);\n\tthis.editor.setText(combinedText);\n\tthis.updatePendingMessagesDisplay();\n\tif (options?.abort) {\n\t\tvoid this.session.abort();\n\t}\n\treturn allQueued.length;\n};\n\nInteractiveModeBase.prototype.queueCompactionMessage = function (\n\tthis: InteractiveModeBase,\n\ttext: string,\n\tmode: \"steer\" | \"followUp\",\n): void {\n\tthis.compactionQueuedMessages.push({ text, mode });\n\tthis.editor.addToHistory?.(text);\n\tthis.editor.setText(\"\");\n\tthis.updatePendingMessagesDisplay();\n\tthis.showStatus(\"Queued message for after compaction\");\n};\n\nInteractiveModeBase.prototype.isExtensionCommand = function (this: InteractiveModeBase, text: string): boolean {\n\tif (!text.startsWith(\"/\")) return false;\n\n\tconst extensionRunner = this.session.extensionRunner;\n\n\tconst spaceIndex = text.indexOf(\" \");\n\tconst commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);\n\treturn !!extensionRunner.getCommand(commandName);\n};\n\nInteractiveModeBase.prototype.flushCompactionQueue = async function (\n\tthis: InteractiveModeBase,\n\toptions?: {\n\t\twillRetry?: boolean;\n\t},\n): Promise<void> {\n\tif (this.compactionQueuedMessages.length === 0) {\n\t\treturn;\n\t}\n\n\tconst queuedMessages = [...this.compactionQueuedMessages];\n\tthis.compactionQueuedMessages = [];\n\tthis.updatePendingMessagesDisplay();\n\n\tconst restoreQueue = (error: unknown) => {\n\t\tthis.session.clearQueue();\n\t\tthis.compactionQueuedMessages = queuedMessages;\n\t\tthis.updatePendingMessagesDisplay();\n\t\tthis.showError(\n\t\t\t`Failed to send queued message${queuedMessages.length > 1 ? \"s\" : \"\"}: ${\n\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t}`,\n\t\t);\n\t};\n\n\ttry {\n\t\tif (!options?.willRetry && (this.session.isStreaming || this.session.queuedMessagesPaused)) {\n\t\t\tawait Promise.all(\n\t\t\t\tqueuedMessages.map((message) => this.session.prompt(message.text, { streamingBehavior: message.mode })),\n\t\t\t);\n\t\t\tthis.updatePendingMessagesDisplay();\n\t\t\treturn;\n\t\t}\n\t\tif (options?.willRetry) {\n\t\t\t// When retry is pending, queue messages for the retry turn\n\t\t\tfor (const message of queuedMessages) {\n\t\t\t\tif (this.isExtensionCommand(message.text)) {\n\t\t\t\t\tawait this.session.prompt(message.text);\n\t\t\t\t} else if (message.mode === \"followUp\") {\n\t\t\t\t\tawait this.session.followUp(message.text);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.session.steer(message.text);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.updatePendingMessagesDisplay();\n\t\t\treturn;\n\t\t}\n\n\t\t// Find first non-extension-command message to use as prompt\n\t\tconst firstPromptIndex = queuedMessages.findIndex((message) => !this.isExtensionCommand(message.text));\n\t\tif (firstPromptIndex === -1) {\n\t\t\t// All extension commands - execute them all\n\t\t\tfor (const message of queuedMessages) {\n\t\t\t\tawait this.session.prompt(message.text);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Execute any extension commands before the first prompt\n\t\tconst preCommands = queuedMessages.slice(0, firstPromptIndex);\n\t\tconst firstPrompt = queuedMessages[firstPromptIndex];\n\t\tconst rest = queuedMessages.slice(firstPromptIndex + 1);\n\n\t\tfor (const message of preCommands) {\n\t\t\tawait this.session.prompt(message.text);\n\t\t}\n\n\t\t// Start a prompt when idle, or preserve its delivery mode if a run is\n\t\t// still winding down after compaction.\n\t\tconst promptPromise = this.session\n\t\t\t.prompt(firstPrompt.text, { streamingBehavior: firstPrompt.mode })\n\t\t\t.catch((error) => {\n\t\t\t\trestoreQueue(error);\n\t\t\t});\n\n\t\t// Queue remaining messages\n\t\tfor (const message of rest) {\n\t\t\tif (this.isExtensionCommand(message.text)) {\n\t\t\t\tawait this.session.prompt(message.text);\n\t\t\t} else if (message.mode === \"followUp\") {\n\t\t\t\tawait this.session.followUp(message.text);\n\t\t\t} else {\n\t\t\t\tawait this.session.steer(message.text);\n\t\t\t}\n\t\t}\n\t\tthis.updatePendingMessagesDisplay();\n\t\tvoid promptPromise;\n\t} catch (error) {\n\t\trestoreQueue(error);\n\t}\n};\n\nInteractiveModeBase.prototype.flushPendingBashComponents = function (this: InteractiveModeBase): void {\n\tfor (const component of this.pendingBashComponents) {\n\t\tthis.pendingMessagesContainer.removeChild(component);\n\t\tthis.chatContainer.addChild(component);\n\t}\n\tthis.pendingBashComponents = [];\n};\n"]}
1
+ {"version":3,"file":"interactive-queueing.js","sourceRoot":"","sources":["../../../src/modes/interactive/interactive-queueing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAE1G,mBAAmB,CAAC,SAAS,CAAC,oBAAoB,GAAG;IAIpD,OAAO;QACN,QAAQ,EAAE;YACT,GAAG,IAAI,CAAC,OAAO,CAAC,mBAAmB,EAAE;YACrC,GAAG,IAAI,CAAC,wBAAwB,CAAC,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AI,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACzC,CAAC;iBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;gBACxC,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC3C,CAAC;iBAAM,CAAC;gBACP,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACxC,CAAC;QACF,CAAC;QACD,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,KAAK,aAAa,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;QAC1B,YAAY,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACF,CAAC,CAAC;AAEF,mBAAmB,CAAC,SAAS,CAAC,0BAA0B,GAAG;IAC1D,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,qBAAqB,EAAE,CAAC;QACpD,IAAI,CAAC,wBAAwB,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;QACrD,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IACD,IAAI,CAAC,qBAAqB,GAAG,EAAE,CAAC;AACjC,CAAC,CAAC","sourcesContent":["import { InteractiveModeBase } from \"./interactive-mode-base.ts\";\nimport { combineQueuedMessagesForEditor, Spacer, TruncatedText, theme } from \"./interactive-mode-deps.ts\";\n\nInteractiveModeBase.prototype.getAllQueuedMessages = function (this: InteractiveModeBase): {\n\tsteering: string[];\n\tfollowUp: string[];\n} {\n\treturn {\n\t\tsteering: [\n\t\t\t...this.session.getSteeringMessages(),\n\t\t\t...this.compactionQueuedMessages.filter((msg) => msg.mode === \"steer\").map((msg) => msg.text),\n\t\t],\n\t\tfollowUp: [\n\t\t\t...this.session.getFollowUpMessages(),\n\t\t\t...this.compactionQueuedMessages.filter((msg) => msg.mode === \"followUp\").map((msg) => msg.text),\n\t\t],\n\t};\n};\n\nInteractiveModeBase.prototype.clearAllQueues = function (\n\tthis: InteractiveModeBase,\n\toptions?: { preserveUnprotectedCustomMessages?: boolean },\n): {\n\tsteering: string[];\n\tfollowUp: string[];\n} {\n\tconst { steering, followUp } = this.session.clearQueue(options);\n\tconst compactionSteering = this.compactionQueuedMessages\n\t\t.filter((msg) => msg.mode === \"steer\")\n\t\t.map((msg) => msg.text);\n\tconst compactionFollowUp = this.compactionQueuedMessages\n\t\t.filter((msg) => msg.mode === \"followUp\")\n\t\t.map((msg) => msg.text);\n\tthis.compactionQueuedMessages = [];\n\treturn {\n\t\tsteering: [...steering, ...compactionSteering],\n\t\tfollowUp: [...followUp, ...compactionFollowUp],\n\t};\n};\n\nInteractiveModeBase.prototype.updatePendingMessagesDisplay = function (this: InteractiveModeBase): void {\n\tthis.pendingMessagesContainer.clear();\n\tconst { steering: steeringMessages, followUp: followUpMessages } = this.getAllQueuedMessages();\n\tif (steeringMessages.length > 0 || followUpMessages.length > 0) {\n\t\tthis.pendingMessagesContainer.addChild(new Spacer(1));\n\t\tfor (const message of steeringMessages) {\n\t\t\tconst text = theme.fg(\"dim\", `Steering: ${message}`);\n\t\t\tthis.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));\n\t\t}\n\t\tfor (const message of followUpMessages) {\n\t\t\tconst text = theme.fg(\"dim\", `Follow-up: ${message}`);\n\t\t\tthis.pendingMessagesContainer.addChild(new TruncatedText(text, 1, 0));\n\t\t}\n\t\tconst dequeueHint = this.getAppKeyDisplay(\"app.message.dequeue\");\n\t\tconst hintText = theme.fg(\"dim\", `↳ ${dequeueHint} to edit all queued messages`);\n\t\tthis.pendingMessagesContainer.addChild(new TruncatedText(hintText, 1, 0));\n\t}\n};\n\nInteractiveModeBase.prototype.restoreQueuedMessagesToEditor = function (\n\tthis: InteractiveModeBase,\n\toptions?: {\n\t\tabort?: boolean;\n\t\tcurrentText?: string;\n\t\tpreserveUnprotectedCustomMessages?: boolean;\n\t},\n): number {\n\tconst { steering, followUp } = this.clearAllQueues(options);\n\tconst allQueued = [...steering, ...followUp];\n\tif (allQueued.length === 0) {\n\t\tthis.updatePendingMessagesDisplay();\n\t\tif (options?.abort) {\n\t\t\tvoid this.session.abort();\n\t\t}\n\t\treturn 0;\n\t}\n\tconst currentText = options?.currentText ?? this.editor.getText();\n\tconst combinedText = combineQueuedMessagesForEditor(allQueued, currentText);\n\tthis.editor.setText(combinedText);\n\tthis.updatePendingMessagesDisplay();\n\tif (options?.abort) {\n\t\tvoid this.session.abort();\n\t}\n\treturn allQueued.length;\n};\n\nInteractiveModeBase.prototype.queueCompactionMessage = function (\n\tthis: InteractiveModeBase,\n\ttext: string,\n\tmode: \"steer\" | \"followUp\",\n): void {\n\tthis.compactionQueuedMessages.push({ text, mode });\n\tthis.editor.addToHistory?.(text);\n\tthis.editor.setText(\"\");\n\tthis.updatePendingMessagesDisplay();\n\tthis.showStatus(\"Queued message for after compaction\");\n};\n\nInteractiveModeBase.prototype.isExtensionCommand = function (this: InteractiveModeBase, text: string): boolean {\n\tif (!text.startsWith(\"/\")) return false;\n\n\tconst extensionRunner = this.session.extensionRunner;\n\n\tconst spaceIndex = text.indexOf(\" \");\n\tconst commandName = spaceIndex === -1 ? text.slice(1) : text.slice(1, spaceIndex);\n\treturn !!extensionRunner.getCommand(commandName);\n};\n\nInteractiveModeBase.prototype.flushCompactionQueue = async function (\n\tthis: InteractiveModeBase,\n\toptions?: {\n\t\twillRetry?: boolean;\n\t},\n): Promise<void> {\n\tif (this.compactionQueuedMessages.length === 0) {\n\t\treturn;\n\t}\n\n\tconst queuedMessages = [...this.compactionQueuedMessages];\n\tthis.compactionQueuedMessages = [];\n\tthis.updatePendingMessagesDisplay();\n\n\tconst restoreQueue = (error: unknown, messages = queuedMessages) => {\n\t\tthis.compactionQueuedMessages = [\n\t\t\t...messages,\n\t\t\t...this.compactionQueuedMessages.filter((message) => !messages.includes(message)),\n\t\t];\n\t\tthis.updatePendingMessagesDisplay();\n\t\tthis.showError(\n\t\t\t`Failed to send queued message${messages.length > 1 ? \"s\" : \"\"}: ${\n\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t}`,\n\t\t);\n\t};\n\n\ttry {\n\t\tif (!options?.willRetry && (this.session.isStreaming || this.session.queuedMessagesPaused)) {\n\t\t\tawait Promise.all(\n\t\t\t\tqueuedMessages.map((message) => this.session.prompt(message.text, { streamingBehavior: message.mode })),\n\t\t\t);\n\t\t\tthis.updatePendingMessagesDisplay();\n\t\t\treturn;\n\t\t}\n\t\tif (options?.willRetry) {\n\t\t\t// When retry is pending, queue messages for the retry turn\n\t\t\tfor (const message of queuedMessages) {\n\t\t\t\tif (this.isExtensionCommand(message.text)) {\n\t\t\t\t\tawait this.session.prompt(message.text);\n\t\t\t\t} else if (message.mode === \"followUp\") {\n\t\t\t\t\tawait this.session.followUp(message.text);\n\t\t\t\t} else {\n\t\t\t\t\tawait this.session.steer(message.text);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthis.updatePendingMessagesDisplay();\n\t\t\treturn;\n\t\t}\n\n\t\t// Find first non-extension-command message to use as prompt\n\t\tconst firstPromptIndex = queuedMessages.findIndex((message) => !this.isExtensionCommand(message.text));\n\t\tif (firstPromptIndex === -1) {\n\t\t\t// All extension commands - execute them all\n\t\t\tfor (const message of queuedMessages) {\n\t\t\t\tawait this.session.prompt(message.text);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Execute any extension commands before the first prompt\n\t\tconst preCommands = queuedMessages.slice(0, firstPromptIndex);\n\t\tconst firstPrompt = queuedMessages[firstPromptIndex];\n\t\tconst rest = queuedMessages.slice(firstPromptIndex + 1);\n\n\t\tfor (const message of preCommands) {\n\t\t\tawait this.session.prompt(message.text);\n\t\t}\n\n\t\t// Start a prompt when idle, or preserve its delivery mode if a run is\n\t\t// still winding down after compaction.\n\t\tconst promptPromise = this.session\n\t\t\t.prompt(firstPrompt.text, { streamingBehavior: firstPrompt.mode })\n\t\t\t.catch((error) => {\n\t\t\t\trestoreQueue(error, [firstPrompt]);\n\t\t\t});\n\n\t\t// Queue remaining messages\n\t\tfor (const message of rest) {\n\t\t\tif (this.isExtensionCommand(message.text)) {\n\t\t\t\tawait this.session.prompt(message.text);\n\t\t\t} else if (message.mode === \"followUp\") {\n\t\t\t\tawait this.session.followUp(message.text);\n\t\t\t} else {\n\t\t\t\tawait this.session.steer(message.text);\n\t\t\t}\n\t\t}\n\t\tthis.updatePendingMessagesDisplay();\n\t\tvoid promptPromise;\n\t} catch (error) {\n\t\tthis.session.clearQueue();\n\t\trestoreQueue(error);\n\t}\n};\n\nInteractiveModeBase.prototype.flushPendingBashComponents = function (this: InteractiveModeBase): void {\n\tfor (const component of this.pendingBashComponents) {\n\t\tthis.pendingMessagesContainer.removeChild(component);\n\t\tthis.chatContainer.addChild(component);\n\t}\n\tthis.pendingBashComponents = [];\n};\n"]}
package/docs/docs.json CHANGED
@@ -204,6 +204,7 @@
204
204
  "extensions/api-reference",
205
205
  "custom-provider/api-reference",
206
206
  "sdk/reference",
207
+ "storage",
207
208
  "sdk/structured-decisions",
208
209
  "rpc/protocol",
209
210
  "tui/reference"
@@ -103,10 +103,9 @@ How you install Atomic decides which runtime hosts it: a package-manager install
103
103
 
104
104
  The shell installer detects Alpine and selects `atomic-linux-x64-musl.tar.gz` or `atomic-linux-arm64-musl.tar.gz`. Keep the complete archive, including payload-local `libgcc` and `libstdc++`; stock Alpine needs no runtime package install.
105
105
 
106
- Two features work differently on musl:
106
+ Clipboard setup depends on your environment:
107
107
 
108
108
  - **Clipboard:** install `wl-clipboard` on Wayland, `xclip` or `xsel` on X11, or the Termux:API app and `termux-api` package on Termux. OSC 52 forwards copies over SSH or Mosh and is a fallback on headless Linux. Set `ATOMIC_CLIPBOARD_OSC52=1`, or the legacy `PI_CLIPBOARD_OSC52=1`, to force terminal forwarding. Your terminal must support it; forwarding does not confirm a successful local clipboard write.
109
- - **Durable workflows:** PostgreSQL is included and provisions offline without Docker or external Postgres. If no durable backend can be provisioned, Atomic warns and uses non-durable in-memory storage.
110
109
 
111
110
  Then start Atomic in the project directory you want it to work on:
112
111
 
package/docs/json.md CHANGED
@@ -106,7 +106,7 @@ Extended messages from [`packages/coding-agent/src/core/messages.ts`](https://gi
106
106
  Each line is a JSON object. The first line is the session header:
107
107
 
108
108
  ```json
109
- {"type":"session","version":3,"id":"uuid","timestamp":"...","cwd":"/path"}
109
+ {"type":"session","version":4,"id":"uuid","timestamp":"...","cwd":"/path"}
110
110
  ```
111
111
 
112
112
  Followed by events as they occur:
@@ -87,7 +87,7 @@ If no app manifest (`atomic`, or legacy `pi`) is present, Atomic auto-discovers
87
87
 
88
88
  Workflow files import `workflow` from `@bastani/atomic/workflows`, import `Type` from `typebox`, and export the definition returned by `workflow({ ... })`. TypeScript resolves the published `@bastani/atomic/workflows` specifier through the `@bastani/atomic` package.
89
89
 
90
- The host supports `typebox`, `typebox/compile`, `typebox/value`, and legacy `@sinclair/typebox` imports. See [Programmatic usage](/workflows/api-reference#programmatic-usage).
90
+ Workflow files support `typebox`, `typebox/compile`, and `typebox/value`. Use these current imports even when an extension in the same package uses the host's additional schema aliases. See [Programmatic usage](/workflows/api-reference#programmatic-usage).
91
91
 
92
92
  When a package manifest exists, declared resource arrays normally define what loads. Workflows are the exception: if `atomic.workflows` / legacy `pi.workflows` is omitted, Atomic still checks conventional `workflows/` and `workflow/` directories.
93
93
 
@@ -922,7 +922,7 @@ WorkflowRunNotResumableError
922
922
  WorkflowStageNotFoundError
923
923
  WorkflowStageAmbiguousError
924
924
  WorkflowStageResumeUnsupportedError
925
- WorkflowRunDatabaseError
925
+ WorkflowRunStorageError
926
926
  WorkflowRunControlUnavailableError
927
927
 
928
928
  // Tool factories
@@ -20,7 +20,7 @@ npm install @bastani/atomic
20
20
 
21
21
  Atomic needs Node.js 22.19 or newer and does not require dependency install scripts.
22
22
 
23
- Bun blocks the install scripts of some dependencies, such as `@embedded-postgres/<platform>`, `protobufjs`, and `@google/genai`, and reports them after `bun add @bastani/atomic`. You don't need to add them to `trustedDependencies` in `package.json`: Atomic prepares the embedded Postgres runtime itself the first time it starts it, and it doesn't depend on the other scripts.
23
+ Dependency install scripts are not required. If your package manager reports blocked scripts, you do not need to enable them for Atomic.
24
24
 
25
25
  ## Keep Atomic out of the server bundle
26
26
 
@@ -300,12 +300,12 @@ export async function POST(request: Request): Promise<Response> {
300
300
 
301
301
  ### Choose workflow durability
302
302
 
303
- By default, `run()` makes workflow state durable by starting a managed local Postgres, so a run can resume after the process exits. Request-scoped servers rarely want that:
303
+ By default, `run()` persists workflow state in a local SQLite journal so eligible runs can resume after the process exits. Keep that file on durable local storage in deployments that need restart recovery.
304
304
 
305
- - **`durability: { mode: "memory" }`** keeps state in memory for this call only. No Postgres starts, and the run can't resume after the process exits. Use it when the request owns the run.
306
- - **`durability: { mode: "durable", systemDatabaseUrl }`** stores state in a Postgres database you run, such as a hosted one, and Atomic doesn't start its own. Use it in deployments that need runs to survive restarts. `DBOS_SYSTEM_DATABASE_URL`, when set, overrides the URL.
305
+ - **`durability: { mode: "durable" }`** explicitly requires persistent state. Journal open or write failures stop the run; they do not select non-durable execution.
306
+ - **`durability: { mode: "memory" }`** explicitly keeps state for this call only and cannot resume after process exit. Use it only when that lifetime is intentional.
307
307
 
308
- One process uses one workflow database. See [Choosing the durable backend](/workflows/api-reference#choosing-the-durable-backend) for the full rules, and [Workflows](/workflows) for writing workflow definitions.
308
+ Set `ATOMIC_WORKFLOW_JOURNAL_PATH` before the first workflow action to choose the journal file. See [Choosing the durable backend](/workflows/api-reference#choosing-the-durable-backend) and [Workflows](/workflows).
309
309
 
310
310
  ## Secure the endpoint
311
311
 
package/docs/sdk.md CHANGED
@@ -24,6 +24,8 @@ This page covers the SDK quick start, its core concepts, and one complete exampl
24
24
 
25
25
  For a custom host that runs background work, see [Owner-bound task supervisor](/sdk/reference#owner-bound-task-supervisor-s1), [Supervised command SDK](/sdk/reference#supervised-command-sdk), and [Task transcript references](/sdk/reference#task-transcript-references).
26
26
 
27
+ For the standalone SQLite facade and adapter conformance suite, see [SQLite storage API](/storage).
28
+
27
29
  Not sure the SDK is the right integration mode? Compare it with RPC and JSON mode on [Programmatic use](/programmatic).
28
30
 
29
31
  To serve an agent over HTTP, see [Embedding Atomic in a web server](/sdk/web-server), which walks through a Next.js App Router route that streams session output to a browser.
@@ -115,7 +117,7 @@ When upgrading an existing host:
115
117
 
116
118
  - Remove manual registration of Atomic's shipped builtin extensions. They and their resources are included by default. Use `builtins` to disable packages; use `tools`/`excludedTools` to control tool access. An empty tool allowlist also excludes Intercom.
117
119
  - Supply all five `HostInput` methods (`confirm`, `select`, `input`, `editor`, `questionnaire`) through `extensionBindings.humanInput`. Preserve question text and option values, honor each request's abort signal, and return literal `true` only for explicit approval. No adapter is not consent: ordinary dialogs reject with `HumanInputUnavailable`, while required durable workflow gates remain pending. Do not translate cancellation into approval.
118
- - Treat a headless workflow launch as acceptance, not completion. Inspect its run ID/status. After reconnecting, resume that existing run and bind the new adapter with `session.bindExtensions({ humanInput })`; do not start a second run to answer an outstanding question. Durable resume requires working workflow persistence; inspect the original run's status and correct the reported database problem before retrying.
120
+ - Treat a headless workflow launch as acceptance, not completion. Inspect its run ID/status. After reconnecting, resume that run and bind the new adapter with `session.bindExtensions({ humanInput })`; do not start a second run to answer an outstanding question. Restore journal access before retrying a storage failure.
119
121
  - Always `await session.dispose()` in `finally`, including on failure. Disposal is asynchronous and can reject with `ShutdownFailed` after attempting all cleanup; do not hide that rejection or call `process.exit()` to force a successful shutdown. Each session owns its own work, even when services are shared.
120
122
 
121
123
  MCP servers and web providers still require their normal configuration and credentials. Importing the SDK does not connect them or take over standard input. Route host diagnostics through `extensionBindings.onDiagnostic`; a missing provider or extractor is an error, not an empty successful result.
@@ -232,7 +234,7 @@ Web provider configuration caches are session-local. Configuration discovery and
232
234
 
233
235
  ### Workflow run control
234
236
 
235
- `session.workflows` controls this session's workflow runs without slash commands or the model-facing `workflow` tool. A fresh session can also inspect a durable root from another session by its full UUID, within the same working directory and configured workflow database. Inspection stays read-only and does not add the run to `listRuns()`.
237
+ `session.workflows` controls this session's runs without slash commands or the model-facing `workflow` tool. A fresh session can inspect a durable root by its full UUID within the same working directory and journal. Inspection stays read-only and does not add the run to `listRuns()`.
236
238
 
237
239
  ```typescript
238
240
  interface SessionWorkflows {
@@ -251,11 +253,11 @@ interface SessionWorkflows {
251
253
 
252
254
  `listRuns()` returns the same per-run data as `workflow status`: id, workflow name, status, active stages, and unanswered prompts (`awaitingInput`). Run IDs accept the full UUID or a unique 8-character prefix. `getRun()`, `getStages()`, `pause()` and `quit()` resolve a prefix against the runs this session holds and reject it at once when none matches, so pass the full UUID for a run recorded by an earlier process. `pause`, `quit` and `resume` resolve with the tool's acknowledged outcome: `action`, `runId` (`--all` for a batch), a `status` of `ok`, `running`, `paused`, `partial`, `noop` or `cancelled`, and a human-readable `message`. A `noop` means the request was understood and found nothing to change, such as pausing a run that already ended. A `partial` outcome means part of the request took effect. For `pause({ all: true })` and `quit({ all: true })`, `partial` means this call stopped at least one run and others are still active: `failedRuns` lists each run that is still active with its `runId`, a `reason` (for example `pause_failed` or `no_active_stages`) and a `message`, so check `outcome.status === "partial"` before treating a batch stop as complete. If active runs could not be stopped and this call stopped none, the call rejects with `WorkflowRunControlError` (`WORKFLOW_RUN_CONTROL_FAILED`) whose `failedRuns` carries the same list, even when other runs were already paused. Runs that are already paused or already ended are not failures, and a batch with no active run left to stop resolves as a `noop`. Call `getRun()` before retrying.
253
255
 
254
- After an owning process crashes, create a new authorized SDK session with the original `cwd` and workflow database configuration. Keep the workflow definition available, then call `getRun(runId)` with the saved full UUID. Once its progress has been stale for about two minutes and its database ownership connection is gone, status reports `crashed`. `resume(runId)` claims the durable run only after the database excludes the previous owner and any unfinished database writes. It continues under the same UUID and replays completed checkpoints. This works with `SessionManager.inMemory()` and does not require reopening a session file. Concurrent recovery attempts admit only one executor; inspect again if another caller won the claim.
256
+ After an owning process crashes, create a new authorized SDK session with the original `cwd` and workflow journal. Keep the workflow definition available, then call `getRun(runId)` with the saved full UUID. Once the journal lease has expired (about two minutes without renewal), status reports `crashed`. `resume(runId)` claims the run under a new fenced lease, keeps its UUID, and replays completed checkpoints. This works with `SessionManager.inMemory()` and does not require reopening a session file. Concurrent recovery attempts admit only one executor; inspect again if another caller won the claim.
255
257
 
256
- A healthy connected foreign owner remains read-only, even while a long-running tool has not refreshed workflow progress or a VM clone cannot see its PID. `pause()` and `quit()` still require its owning session, and `resume()` cannot adopt another session's live or terminal run, or a paused run whose owning session is still open. Missing ownership metadata, a different working directory, or unavailable database ownership verification prevents adoption. Older runs without database-fenced ownership remain inspectable but cannot use this distributed recovery path. Recovery from a crashed foreign process requires the full UUID, not a prefix. A host using only the non-durable in-memory workflow backend cannot recover after process loss.
258
+ A run with a live foreign lease remains read-only, even while a long-running tool has not refreshed progress. `pause()` and `quit()` require the owning session. Missing ownership metadata, a different working directory, or unavailable journal storage prevents adoption. Use the full UUID to recover a foreign run.
257
259
 
258
- A run launched through the model-facing `workflow` tool can also move to another session without a crash. Disposing its owning session with `session.dispose()` stops that session's in-flight runs at their last checkpoint and records in the workflow database that the session released every checkpointed run it paused. Afterward, any authorized SDK session with the same `cwd` and workflow database can call `resume(runId)` with the full UUID, in the same process or after the owning process has exited. The adopting session becomes the run's owner, the run continues under the same UUID, and completed checkpoints replay without rerunning their callbacks.
260
+ Disposing an owning session with `await session.dispose()` stops its in-flight runs at their last checkpoint and records their release in the journal. Another authorized SDK session with the same `cwd` and journal can then call `resume(runId)`. The adopting session becomes the owner, and completed checkpoints replay without rerunning their callbacks.
259
261
 
260
262
  Workflow resume is project-scoped. SDK and workflow-tool resume calls for a run from a different `cwd` return an actionable error without changing it. To continue in a different project, use `/workflow resume <id>` interactively and confirm the fork into the current directory. The fork receives a new run ID and copies saved progress; the original run is left untouched. To keep the original ID, create the successor session with the original `cwd`.
261
263
 
@@ -265,27 +267,11 @@ await owner.dispose(); // quits in-flight runs at their last checkpoint and rele
265
267
  await successor.workflows.resume(runId); // adopts the run, even from another process
266
268
  ```
267
269
 
268
- Switching the host to another session (`/new`, `/fork`, `/resume`) releases the previous session's paused runs the same way, so the new session can adopt them with `resume(runId)`, through its model's `workflow` tool (`action: "resume"`), or with the `/workflow resume <id>` slash command. Until a run is adopted, the new session's model can inspect it with the tool's `status` and `stages` actions; `pause`, `quit`, and `answer` stay refused until it owns the run. The first session to adopt a released run becomes its owner; a later attempt is refused. In the process that released the run the error reads `Workflow <id> is now owned by another session; it was already adopted after its previous session was switched away.`; a different process sharing the database reports `Workflow instance belongs to another caller/session.`. A paused run whose owner crashed or was killed before leaving, and any run whose owning session is still open, stays refused with `Workflow instance belongs to another caller/session.`. Reloading does not release runs. Finished runs are never resumable, whoever owns them.
269
-
270
- Live-cloned SDK hosts must share one authoritative PostgreSQL server and database. Configure a shared database endpoint for those hosts. Copying the managed PostgreSQL directory into another VM creates an independent database, even if both use the same `localhost` URL; separate databases cannot enforce cross-VM ownership exclusion.
271
-
272
- Use a direct PostgreSQL connection or a proxy that preserves each client's database session. Ownership locks and write authorization depend on session affinity. Transaction-mode and statement-mode pooling, including those PgBouncer modes, are unsupported for the workflow database.
273
-
274
- Database fencing protects ownership and durable checkpoints, not arbitrary external effects. If an owner loses its database connection, recovery may overlap an unfinished callback in that still-running process. The old owner cannot save new checkpoints, but an interrupted `ctx.tool` callback can be retried before the old callback stops. Make external effects idempotent, for example by passing a stable run/node operation key to an API that deduplicates requests. Completed checkpoints are replayed without rerunning their callbacks; unfinished callbacks do not have exactly-once execution guarantees.
275
-
276
- An execution that loses its ownership connection cannot silently regain write authority. Restore database availability, inspect the retained run, and resume explicitly. Recovery uses a fresh execution generation while the disconnected generation stays fenced. Keep the database and completed checkpoints; deleting them is not a recovery step.
277
-
278
- For an older run without database-fenced ownership, stop every older Atomic worker connected to its workflow database before enrollment. Upgrade the recovery host, retain the original database and workflow definition, and create an authorized SDK session with the original `cwd`. Inspect the full UUID, then explicitly confirm the stopped-worker prerequisite:
279
-
280
- ```ts
281
- await session.workflows.resume(runId, {
282
- legacyRecovery: { olderWorkersStopped: true },
283
- });
284
- ```
270
+ Switching sessions (`/new`, `/fork`, `/resume`) also releases the previous session's paused runs for adoption. Reloading does not release runs. A paused run whose owning session has not released it stays protected; finished runs are not resumable.
285
271
 
286
- This enrolls an eligible legacy root in database fencing and resumes it under the same UUID, preserving completed checkpoints. The option is an operator assertion, not a mechanism that stops workers. Never pass it while an older worker may still be executing. It does not permit recovery in another working directory, stage-only enrollment, or overriding a healthy fenced owner. Ordinary `resume(runId)` does not automatically adopt an unfenced legacy owner; inspection and existing owner-scoped controls remain available.
272
+ Journal fencing protects ownership and durable checkpoints, not arbitrary external effects. An interrupted `ctx.tool` callback can run again if its result was not checkpointed. Make external effects idempotent, for example by using a stable run/node operation key with an API that deduplicates requests.
287
273
 
288
- If the recovery host crashes after enrollment but before execution starts, inspect the full UUID and retry the same explicit option from a fresh session. Retry is permitted only for an interrupted enrollment whose database owner is no longer live. It does not allow takeover of another session's generally paused or blocked fenced run.
274
+ If storage fails, preserve the journal and run ID, restore access, inspect the retained run, and resume explicitly. A failed pause leaves the local scheduler paused; resume retries the journal transition before releasing it. A failed resume keeps the scheduler paused and surfaces the error.
289
275
 
290
276
  Pausing a run doesn't park a stage that is waiting on a prompt, including an `ask_user_question` delivered through `HostInput.questionnaire`. If no other work is active, `pause(runId)` and `pause({ all: true })` mark the run `paused` without cancelling its question. Questions not yet shown wait until the run resumes. A later pause counts it as already paused. If your host then answers an already-open prompt, the stage can continue its turn before you call `resume`. To keep a paused run fully stopped, hold prompt answers until you resume it.
291
277
 
@@ -299,7 +285,7 @@ Requests that cannot be carried out reject with a subclass of `WorkflowRunContro
299
285
  | `WorkflowStageNotFoundError` | `WORKFLOW_STAGE_NOT_FOUND` | `stageId` matches no stage of the run, or the stage has no control to pause. |
300
286
  | `WorkflowStageAmbiguousError` | `WORKFLOW_STAGE_AMBIGUOUS` | `stageId` matches more than one stage; pass a more specific identifier. |
301
287
  | `WorkflowStageResumeUnsupportedError` | `WORKFLOW_STAGE_RESUME_UNSUPPORTED` | A durable run resumes as a whole; call `resume()` without `stageId`. |
302
- | `WorkflowRunDatabaseError` | `WORKFLOW_RUN_DATABASE` | Workflow durability is unavailable, including when the database cannot be inspected to check a run's owner during `pause()` or `quit()`. Restore the database, then inspect the run before retrying. |
288
+ | `WorkflowRunStorageError` | `WORKFLOW_RUN_STORAGE` | The workflow journal is unavailable, closed, or failed. Restore storage access and inspect the retained run before retrying. |
303
289
  | `WorkflowRunControlError` | `WORKFLOW_RUN_CONTROL_FAILED` | Another failure; `message` explains it. |
304
290
  | `WorkflowRunControlUnavailableError` | `WORKFLOW_RUN_CONTROL_UNAVAILABLE` | The workflows package is disabled, or the session was disposed. |
305
291
 
@@ -18,13 +18,7 @@ Atomic also supports deleting sessions interactively from `/resume` (select a se
18
18
 
19
19
  ## Session Version
20
20
 
21
- Sessions have a version field in the header:
22
-
23
- - **Version 1**: Linear entry sequence (legacy, auto-migrated on load)
24
- - **Version 2**: Tree structure with `id`/`parentId` linking
25
- - **Version 3**: Renamed `hookMessage` role to `custom` (extensions unification)
26
-
27
- Existing sessions are automatically migrated to the current version (v3) when loaded.
21
+ SessionManager writes version 4 headers. Other versions and structurally invalid entries are rejected before loading or forking; unloadable sessions are omitted from resume listings. Session-format migrations have been removed. Start a new session instead of relying on automatic conversion. Reading a file leaves its bytes unchanged. A complete final record without a newline is accepted; a torn final record is rejected.
28
22
 
29
23
  ## Source Files
30
24
 
@@ -203,19 +197,19 @@ interface SessionEntryBase {
203
197
  First line of the file. Metadata only, not part of the tree (no `id`/`parentId`).
204
198
 
205
199
  ```json
206
- {"type":"session","version":3,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project"}
200
+ {"type":"session","version":4,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project"}
207
201
  ```
208
202
 
209
203
  For sessions with a parent (created via `/fork`, `/clone`, or `newSession({ parentSession })`):
210
204
 
211
205
  ```json
212
- {"type":"session","version":3,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project","parentSession":"/path/to/original/session.jsonl"}
206
+ {"type":"session","version":4,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project","parentSession":"/path/to/original/session.jsonl"}
213
207
  ```
214
208
 
215
209
  Workflow-owned sessions carry both `internal: true` and complete `workflow` linkage. Atomic writes this classification before the transcript becomes visible wherever possible, including workflow stage forks and fresh/forked subagents. A session is excluded from normal resume history only when `internal` is the exact boolean `true` and `workflow.runId`, `workflow.stageId`, and `workflow.stageName` are all non-empty strings:
216
210
 
217
211
  ```json
218
- {"type":"session","version":3,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project","internal":true,"workflow":{"runId":"run-1","stageId":"stage-build","stageName":"build"}}
212
+ {"type":"session","version":4,"id":"uuid","timestamp":"2024-12-03T14:00:00.000Z","cwd":"/path/to/project","internal":true,"workflow":{"runId":"run-1","stageId":"stage-build","stageName":"build"}}
219
213
  ```
220
214
 
221
215
  Malformed, incomplete, workflow-only, or truthy non-boolean legacy markers remain visible in normal history. Atomic does not infer workflow ownership from `parentSession`, so ordinary user-created forks are unaffected. Valid workflow classification is inherited when an internal workflow transcript is branched or forked.
package/docs/settings.md CHANGED
@@ -149,7 +149,7 @@ If `retry.enabled` is `false`, Atomic skips same-model retries and moves directl
149
149
 
150
150
  The fallback model and its thinking level remain active for later turns in the same main-chat session. Choose another model explicitly with `/model` or model cycle to change them.
151
151
 
152
- Workflow stages that set their own `model` or `fallbackModels` never use this list; they advance only the chain they declare. See [`fallbackModels` / `fallbackThinkingLevels`](/workflows/api-reference#fallbackmodels-/-fallbackthinkinglevels).
152
+ Workflow stages that set their own `model` or `fallbackModels` never use this list; they advance only the chain they declare. See [`fallbackModels`](/workflows/api-reference#fallbackmodels).
153
153
 
154
154
  A failure that another request to the same model cannot repair — a rejected credential, an unavailable model, a request that model cannot serve — takes that model out of the chain for the rest of the turn at **every** reasoning level, so a candidate that differs only by its `:low`/`:high` suffix is skipped rather than spent. Transient rate-limit and transport failures keep those reasoning variants, because retrying them can succeed.
155
155
 
@@ -548,40 +548,16 @@ Paths in `~/.atomic/agent/settings.json` resolve relative to `~/.atomic/agent`.
548
548
  | `skills` | string[] | `[]` | Local skill file paths or directories |
549
549
  | `prompts` | string[] | `[]` | Local prompt template paths or directories |
550
550
  | `themes` | string[] | `[]` | Local theme file paths or directories |
551
- | `workflows` | string[] or object | `[]` | Local workflow paths, or `{ "paths": [...], "durability": {...} }`; see [Workflow database](#workflow-database) |
551
+ | `workflows` | string[] or object | `[]` | Local workflow paths, or `{ "paths": [...] }`; see [Workflow storage](#workflow-storage) |
552
552
  | `enableSkillCommands` | boolean | `true` | Register skills as `/skill:name` commands |
553
553
 
554
554
  Arrays support glob patterns and exclusions. Use `!pattern` to exclude. Use `+path` to force-include an exact path and `-path` to force-exclude an exact path.
555
555
 
556
- #### Workflow database
556
+ #### Workflow storage
557
557
 
558
- Choose an existing PostgreSQL database in global or trusted project settings:
558
+ Workflow runs use a local SQLite journal at `~/.atomic/workflows/journal.sqlite`. Set `ATOMIC_WORKFLOW_JOURNAL_PATH` before starting Atomic to choose another file. Keep the journal on durable local storage and preserve it when upgrading or restarting. Changing the path selects a different run history; use the original journal to inspect or resume existing runs.
559
559
 
560
- ```json
561
- {
562
- "workflows": {
563
- "paths": ["./workflows"],
564
- "durability": {
565
- "systemDatabaseUrlFile": "~/.atomic/neon/direct.url"
566
- }
567
- }
568
- }
569
- ```
570
-
571
- | Setting | Type | Default | Description |
572
- |---------|------|---------|-------------|
573
- | `workflows.paths` | string[] | `[]` | Workflow resource paths in object-form settings; existing `workflows: [...]` settings remain supported |
574
- | `workflows.durability.systemDatabaseUrl` | string | - | PostgreSQL URL for the workflow database |
575
- | `workflows.durability.poolSize` | integer, at least 2 | `10` | Maximum connections per workflow database pool, for managed or remote PostgreSQL |
576
- | `workflows.durability.systemDatabaseUrlFile` | string | - | Read the PostgreSQL URL from a UTF-8 file instead of storing credentials in settings |
577
-
578
- Set only one URL source per scope. A project `durability` object replaces the global database selection; project settings are ignored unless trusted. Relative URL-file paths resolve beside the settings file that declares them: `~/.atomic/agent` for global settings and `.atomic` for project settings, or the matching `.pi` directory for inherited pi settings. Absolute paths and `~/` are supported. Protect credential files with permissions appropriate for your account, and do not commit them.
579
-
580
- Precedence is nonempty `DBOS_SYSTEM_DATABASE_URL`, then settings, then managed embedded PostgreSQL with Docker as its provisioning fallback. URLs and file contents are trimmed. Invalid settings, including unrecognized `durability` keys, or missing, empty, or invalid URL files stop workflow initialization instead of silently choosing a local database. An explicit URL never starts managed PostgreSQL or Docker, even if the endpoint is unavailable. Existing non-durable fallback warnings still apply when DBOS cannot connect.
581
-
582
- `poolSize` can be set without a URL, and still applies when `DBOS_SYSTEM_DATABASE_URL` supplies the URL. It is **per pool**, not a process-wide connection limit: each process opens at least two pools (DBOS SQL and the ownership fence), plus another fence pool after a recovery. The minimum is 2 because the ownership fence holds one long-lived advisory-lock connection and needs another for transactions. Lower it for hosted plans or poolers such as Neon, Supabase, or PgBouncer with low connection limits, or when many processes share one database. Raise it for one high-throughput process on a large database. Budget for all pools across all processes, and restart Atomic after changing the size.
583
-
584
- Restart Atomic after changing the database selection. Selection takes effect on the first workflow action. Interactive and RPC sessions then report the selected provider and host without credentials; headless sessions report only a Docker fallback, on stderr. Changing databases does not migrate existing runs; use the original database to inspect or resume them. See [Durable workflows](/workflows/operations#durable-workflows-and-cross-session-resume).
560
+ Configure workflow resource paths with `workflows: ["./workflows"]` or `workflows: { "paths": ["./workflows"] }`. Storage does not require a separate server or connection settings. If the journal cannot be opened or written, the workflow action fails rather than switching to non-durable execution. Restore filesystem access and inspect the retained run before retrying. See [Durable workflows](/workflows/operations#durable-workflows-and-cross-session-resume).
585
561
 
586
562
  #### packages
587
563
 
@@ -0,0 +1,43 @@
1
+ # SQLite storage API
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.
4
+
5
+ ```ts
6
+ import { openNodeSqliteDatabase } from "@bastani/atomic/storage";
7
+
8
+ const database = await openNodeSqliteDatabase("./data/example.sqlite");
9
+ try {
10
+ await database.exec("CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, text TEXT)");
11
+ await database.transaction(async (transaction) => {
12
+ await transaction.run("INSERT INTO notes(text) VALUES (?)", "hello");
13
+ });
14
+ const notes = await database.all("SELECT id, text FROM notes ORDER BY id");
15
+ } finally {
16
+ await database.close();
17
+ }
18
+ ```
19
+
20
+ `exec`, `run`, `get`, and `all` return promises. Bind values through positional `?` parameters; `run` returns `{ changes }`, `get` returns a row or `undefined`, and `all` returns an array. Values may be null, number, bigint, string, or Uint8Array. Binary values are copied when the call is made, so reusing a buffer afterward does not change queued work. INTEGER values inside the safe integer range are returned as numbers; larger values are returned as bigints.
21
+
22
+ 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
+
24
+ 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
+
26
+ 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
+
28
+ 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
+
30
+ ## Adapter conformance
31
+
32
+ Implement `SqliteDatabase` and run the exported suite from `@bastani/atomic/storage/testing`:
33
+
34
+ ```ts
35
+ import { describe, it } from "vitest";
36
+ import { registerSqliteDatabaseConformance } from "@bastani/atomic/storage/testing";
37
+
38
+ registerSqliteDatabaseConformance({ describe, it }, "my adapter", withSubject);
39
+ ```
40
+
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.
42
+
43
+ `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.