@bastani/atomic 0.10.14 → 0.10.15-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (341) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/_shared/dist-KOELCESV.js +2 -2
  3. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  4. package/dist/_shared/lib-4PES5P4V.js +2 -2
  5. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +3 -3
  6. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
  7. package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
  8. package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
  9. package/dist/_shared/runtime-O4KCSG4C.js +2 -2
  10. package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
  11. package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
  12. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  13. package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
  14. package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
  15. package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
  16. package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
  17. package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
  18. package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
  19. package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
  20. package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
  21. package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
  22. package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
  23. package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
  24. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  25. package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
  26. package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
  27. package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
  28. package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
  29. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  30. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  31. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  32. package/dist/builtin/intercom/package.json +1 -1
  33. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  34. package/dist/builtin/mcp/package.json +1 -1
  35. package/dist/builtin/subagents/package.json +1 -1
  36. package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
  37. package/dist/builtin/web-access/index.bundle.mjs +1 -1
  38. package/dist/builtin/web-access/package.json +1 -1
  39. package/dist/cli/auth-cli.code.js +1 -1
  40. package/dist/cli/auth-cli.impl.js +3 -3
  41. package/dist/cli/auth-cli.js +3 -3
  42. package/dist/cli/blueprint-command.impl.js +3 -3
  43. package/dist/cli/blueprint-command.js +3 -3
  44. package/dist/cli/intercom-command.code.js +3 -3
  45. package/dist/cli/intercom-command.impl.js +3 -3
  46. package/dist/cli/intercom-command.js +3 -3
  47. package/dist/cli/list-models.impl.js +3 -3
  48. package/dist/cli/list-models.js +3 -3
  49. package/dist/cli/session-picker.code.js +1 -1
  50. package/dist/cli/session-picker.impl.js +3 -3
  51. package/dist/cli/session-picker.js +3 -3
  52. package/dist/cli/startup-ui.code.js +1 -1
  53. package/dist/cli/startup-ui.impl.js +3 -3
  54. package/dist/cli/startup-ui.js +3 -3
  55. package/dist/cli/storage-command.impl.js +3 -3
  56. package/dist/cli/storage-command.js +3 -3
  57. package/dist/cli/storage-search-session.code.js +1 -1
  58. package/dist/cli/storage-search-session.impl.js +3 -3
  59. package/dist/cli/storage-search-session.js +3 -3
  60. package/dist/cli/team-command.code.js +1 -1
  61. package/dist/cli/team-command.impl.js +3 -3
  62. package/dist/cli/team-command.js +3 -3
  63. package/dist/cli.js +2 -2
  64. package/dist/core/compaction/compactor.d.ts +0 -8
  65. package/dist/core/debug.impl.js +3 -3
  66. package/dist/core/debug.js +3 -3
  67. package/dist/core/export-html/card-projection.impl.js +3 -3
  68. package/dist/core/export-html/card-projection.js +3 -3
  69. package/dist/core/export-html/index.code.js +2 -2
  70. package/dist/core/export-html/index.impl.js +3 -3
  71. package/dist/core/export-html/index.js +3 -3
  72. package/dist/core/export-html/json-spans.impl.js +3 -3
  73. package/dist/core/export-html/json-spans.js +3 -3
  74. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  75. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  76. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  77. package/dist/core/export-html/tool-renderer.js +3 -3
  78. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  79. package/dist/core/extensions/jiti-loader.js +3 -3
  80. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  81. package/dist/core/extensions/jiti-static-loader.js +3 -3
  82. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  83. package/dist/core/extensions/loader-host-modules.js +3 -3
  84. package/dist/core/intercom-broker-control-host.code.js +1 -1
  85. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  86. package/dist/core/intercom-broker-control-host.js +3 -3
  87. package/dist/core/intercom-broker-control.code.js +2 -2
  88. package/dist/core/intercom-broker-control.impl.js +3 -3
  89. package/dist/core/intercom-broker-control.js +3 -3
  90. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  91. package/dist/core/package-manager-storage-adapters.js +3 -3
  92. package/dist/core/sdk.code.js +1 -1
  93. package/dist/core/sdk.impl.js +3 -3
  94. package/dist/core/sdk.js +3 -3
  95. package/dist/core/session-manager-core.js +3 -3
  96. package/dist/core/session-manager-list.impl.js +3 -3
  97. package/dist/core/session-manager-list.js +3 -3
  98. package/dist/core/session-manager.impl.js +3 -3
  99. package/dist/core/session-manager.js +3 -3
  100. package/dist/core/session-storage.impl.js +3 -3
  101. package/dist/core/session-storage.js +3 -3
  102. package/dist/core/storage/index.js +2 -2
  103. package/dist/core/storage/node-sqlite-thread.js +2 -2
  104. package/dist/core/storage/node-sqlite.js +2 -2
  105. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  106. package/dist/core/storage/offline-snapshot-file.js +3 -3
  107. package/dist/core/storage/provider.js +2 -2
  108. package/dist/core/storage/selection.js +2 -2
  109. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  110. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  111. package/dist/core/storage/session/branch-fork-source.js +3 -3
  112. package/dist/core/storage/session/card-view.impl.js +3 -3
  113. package/dist/core/storage/session/card-view.js +3 -3
  114. package/dist/core/storage/session/child-reader.code.js +2 -2
  115. package/dist/core/storage/session/child-reader.impl.js +3 -3
  116. package/dist/core/storage/session/child-reader.js +3 -3
  117. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  118. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  119. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  120. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  121. package/dist/core/storage/session/expanded-child-details.js +3 -3
  122. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  123. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  124. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  125. package/dist/core/storage/session/fork-row-index.js +3 -3
  126. package/dist/core/storage/session/fork-staging.code.js +1 -1
  127. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  128. package/dist/core/storage/session/fork-staging.js +3 -3
  129. package/dist/core/storage/session/fork-window.code.js +2 -2
  130. package/dist/core/storage/session/fork-window.impl.js +3 -3
  131. package/dist/core/storage/session/fork-window.js +3 -3
  132. package/dist/core/storage/session/history-pages.impl.js +3 -3
  133. package/dist/core/storage/session/history-pages.js +3 -3
  134. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  135. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  136. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  137. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  138. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  139. package/dist/core/storage/session/memory-session-store.js +3 -3
  140. package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
  141. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  142. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  143. package/dist/core/storage/session/released-history-files.code.js +1 -1
  144. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  145. package/dist/core/storage/session/released-history-files.js +3 -3
  146. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  147. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  148. package/dist/core/storage/session/session-resume.impl.js +3 -3
  149. package/dist/core/storage/session/session-resume.js +3 -3
  150. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  151. package/dist/core/storage/session/snapshot-cut.js +3 -3
  152. package/dist/core/storage/session/snapshot-history.code.js +2 -2
  153. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  154. package/dist/core/storage/session/snapshot-history.js +3 -3
  155. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  156. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  157. package/dist/core/storage/session/sql-session-store.js +3 -3
  158. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  159. package/dist/core/storage/session/tree-outline.js +3 -3
  160. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  161. package/dist/core/storage/session/tree-presentation.js +3 -3
  162. package/dist/core/storage/storage-status.impl.js +3 -3
  163. package/dist/core/storage/storage-status.js +3 -3
  164. package/dist/core/storage/team.impl.js +3 -3
  165. package/dist/core/storage/team.js +3 -3
  166. package/dist/core/structured-output/index.code.js +1 -1
  167. package/dist/core/structured-output/index.impl.js +3 -3
  168. package/dist/core/structured-output/index.js +3 -3
  169. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  170. package/dist/core/tasks/task-completion-entry.js +3 -3
  171. package/dist/core/tasks/task-file-history.code.js +2 -2
  172. package/dist/core/tasks/task-file-history.impl.js +3 -3
  173. package/dist/core/tasks/task-file-history.js +3 -3
  174. package/dist/core/tasks/task-reference-archive.code.js +2 -2
  175. package/dist/core/tasks/task-reference-archive.js +3 -3
  176. package/dist/core/tasks/task-reference-identity.js +3 -3
  177. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  178. package/dist/core/tasks/task-reference-stream.js +3 -3
  179. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  180. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  181. package/dist/core/tasks/task-view-source.impl.js +3 -3
  182. package/dist/core/tasks/task-view-source.js +3 -3
  183. package/dist/core/tools/read-url.impl.js +3 -3
  184. package/dist/core/tools/read-url.js +3 -3
  185. package/dist/core/worktree-snapshot/blob-store.js +2 -2
  186. package/dist/core/worktree-snapshot/errors.code.js +1 -1
  187. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  188. package/dist/core/worktree-snapshot/errors.js +3 -3
  189. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  190. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  191. package/dist/extensions/codemode/execute.impl.js +3 -3
  192. package/dist/extensions/codemode/execute.js +3 -3
  193. package/dist/extensions/codemode/renderer.impl.js +3 -3
  194. package/dist/extensions/codemode/renderer.js +3 -3
  195. package/dist/extensions/mcp/cli.code.js +1 -1
  196. package/dist/extensions/mcp/cli.impl.js +3 -3
  197. package/dist/extensions/mcp/cli.js +3 -3
  198. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  199. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  200. package/dist/extensions/mcp/cli.lazy.js +3 -3
  201. package/dist/extensions/mcp/runtime.code.js +1 -1
  202. package/dist/extensions/mcp/runtime.impl.js +3 -3
  203. package/dist/extensions/mcp/runtime.js +3 -3
  204. package/dist/index.d.ts +21 -1
  205. package/dist/index.js +2 -2
  206. package/dist/main-first-time-setup.code.js +1 -1
  207. package/dist/main-first-time-setup.impl.js +3 -3
  208. package/dist/main-first-time-setup.js +3 -3
  209. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  210. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  211. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  212. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  213. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  214. package/dist/modes/print-mode.js +1 -1
  215. package/dist/package-manager-cli.code.js +2 -2
  216. package/dist/package-manager-cli.impl.js +3 -3
  217. package/dist/package-manager-cli.js +3 -3
  218. package/dist/startup-files.json +1 -1
  219. package/dist/startup-stages/6.js +1 -1
  220. package/dist/utils/startup-database-spare.code.js +1 -1
  221. package/dist/utils/startup-database-spare.impl.js +3 -3
  222. package/dist/utils/startup-database-spare.js +3 -3
  223. package/dist/utils/tools-manager.impl.js +3 -3
  224. package/dist/utils/tools-manager.js +3 -3
  225. package/docs/background-tasks/reference.md +182 -0
  226. package/docs/background-tasks.md +98 -405
  227. package/docs/build.md +67 -27
  228. package/docs/changelog.mdx +1 -1
  229. package/docs/codemode.md +108 -39
  230. package/docs/compaction/branch-summaries.md +54 -0
  231. package/docs/compaction/custom-compactors.md +161 -0
  232. package/docs/compaction/memory-compaction.md +77 -0
  233. package/docs/compaction/reference.md +86 -38
  234. package/docs/compaction.md +51 -252
  235. package/docs/computer-use.md +169 -321
  236. package/docs/containerization.md +71 -57
  237. package/docs/custom-provider/api-reference.md +119 -25
  238. package/docs/custom-provider/oauth.md +114 -132
  239. package/docs/custom-provider/override.md +37 -27
  240. package/docs/custom-provider/registration.md +107 -83
  241. package/docs/custom-provider/streaming.md +85 -71
  242. package/docs/custom-provider.md +85 -52
  243. package/docs/development.md +39 -29
  244. package/docs/docs.json +76 -63
  245. package/docs/environment-variables.md +94 -44
  246. package/docs/extensions/api-reference.md +86 -43
  247. package/docs/extensions/authoring.md +162 -154
  248. package/docs/extensions/events.md +80 -25
  249. package/docs/extensions/examples.md +90 -85
  250. package/docs/extensions/ui.md +206 -82
  251. package/docs/extensions.md +79 -108
  252. package/docs/getting-started/authentication.md +67 -36
  253. package/docs/getting-started/first-session.md +53 -43
  254. package/docs/getting-started/installation.md +116 -89
  255. package/docs/getting-started/project-instructions.md +48 -34
  256. package/docs/guides/configuration.md +82 -20
  257. package/docs/guides/non-interactive.md +66 -24
  258. package/docs/guides/resume-on-any-machine.md +135 -82
  259. package/docs/guides/team-setup.md +114 -105
  260. package/docs/guides.md +76 -32
  261. package/docs/herdr.md +15 -16
  262. package/docs/how-atomic-works.md +140 -0
  263. package/docs/index.md +58 -44
  264. package/docs/intercom/operations.md +141 -151
  265. package/docs/intercom/reference.md +85 -108
  266. package/docs/intercom.md +84 -145
  267. package/docs/json.md +120 -67
  268. package/docs/keybindings.md +85 -49
  269. package/docs/libraries/agent-core.md +137 -275
  270. package/docs/libraries/ai.md +100 -84
  271. package/docs/libraries/codemode.md +210 -300
  272. package/docs/libraries/schema.md +59 -53
  273. package/docs/libraries/storage-postgres.md +49 -35
  274. package/docs/libraries/telemetry.md +153 -354
  275. package/docs/libraries/tui.md +265 -393
  276. package/docs/libraries.md +42 -26
  277. package/docs/llama-cpp.md +171 -161
  278. package/docs/mcp-servers.md +90 -51
  279. package/docs/models/choose-a-model.md +188 -0
  280. package/docs/models/reference.md +74 -30
  281. package/docs/models.md +153 -88
  282. package/docs/orchestration/migrating-workflows.md +23 -16
  283. package/docs/orchestration/patterns.md +39 -44
  284. package/docs/orchestration.md +65 -26
  285. package/docs/packages/authoring.md +51 -29
  286. package/docs/packages/reference.md +42 -21
  287. package/docs/packages.md +69 -58
  288. package/docs/programmatic.md +118 -24
  289. package/docs/prompt-templates.md +84 -83
  290. package/docs/providers/reference.md +43 -48
  291. package/docs/providers.md +219 -451
  292. package/docs/quickstart.md +140 -120
  293. package/docs/reference/cli.md +135 -97
  294. package/docs/reference.md +20 -18
  295. package/docs/rpc/examples.md +76 -20
  296. package/docs/rpc/extension-ui.md +64 -38
  297. package/docs/rpc/protocol.md +361 -110
  298. package/docs/rpc.md +57 -17
  299. package/docs/sdk/reference.md +409 -534
  300. package/docs/sdk/storage.md +53 -13
  301. package/docs/sdk/structured-decisions.md +82 -56
  302. package/docs/sdk/web-server.md +57 -43
  303. package/docs/sdk.md +106 -84
  304. package/docs/security.md +42 -64
  305. package/docs/session-format.md +62 -38
  306. package/docs/sessions.md +99 -214
  307. package/docs/settings.md +165 -195
  308. package/docs/shell-aliases.md +9 -6
  309. package/docs/skills/authoring.md +69 -48
  310. package/docs/skills/reference.md +51 -20
  311. package/docs/skills.md +99 -148
  312. package/docs/slash-commands.md +129 -0
  313. package/docs/storage/custom-adapters.md +160 -85
  314. package/docs/storage/jsonl.md +81 -66
  315. package/docs/storage/postgres/pgbouncer.md +120 -126
  316. package/docs/storage/postgres/tuning.md +120 -143
  317. package/docs/storage/postgres.md +314 -330
  318. package/docs/storage/sqlite.md +71 -42
  319. package/docs/storage.md +298 -302
  320. package/docs/subagents/authoring.md +55 -38
  321. package/docs/subagents/reference.md +73 -33
  322. package/docs/subagents.md +119 -187
  323. package/docs/terminal-setup.md +50 -38
  324. package/docs/termux.md +67 -41
  325. package/docs/themes/reference.md +23 -19
  326. package/docs/themes.md +142 -127
  327. package/docs/tmux.md +47 -55
  328. package/docs/tools.md +147 -109
  329. package/docs/tui/reference.md +166 -214
  330. package/docs/tui.md +196 -341
  331. package/docs/usage.md +118 -138
  332. package/docs/verification.md +79 -51
  333. package/docs/web-access.md +121 -101
  334. package/docs/windows.md +26 -27
  335. package/docs/worktree-snapshots/reference.md +245 -0
  336. package/docs/worktree-snapshots.md +71 -259
  337. package/package.json +8 -8
  338. package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
  339. package/docs/guides/intercom.md +0 -32
  340. package/docs/guides/orchestration.md +0 -28
  341. package/docs/guides/subagents.md +0 -37
@@ -4,15 +4,15 @@ sidebarTitle: "@bastani/atomic-schema"
4
4
  description: "Build and validate JSON Schema drafts 2020-12 and 7 without eval, with zero runtime dependencies and optional coercion."
5
5
  ---
6
6
 
7
- JSON Schema builders and validation without `eval`. Each schema compiles once into plain closures, so validation runs without code generation, works under a strict Content Security Policy, and needs no runtime dependencies.
7
+ JSON Schema builders and validation without `eval`. Each schema compiles once into plain closures, so validation runs without code generation, works under a strict Content Security Policy, and requires zero runtime dependencies.
8
8
 
9
9
  - Supports JSON Schema drafts 2020-12 and 7.
10
10
  - Builders return plain JSON Schema objects typed with the values they accept, and compiled checks narrow values to that type.
11
- - Errors include JSON Pointer paths. Missing and unknown fields report at the field path.
11
+ - Errors include JSON Pointer paths; missing and unknown fields report at the field path.
12
12
  - Schemas are never mutated, so frozen schemas work.
13
- - Format checks live in an optional subpath import.
13
+ - Format checks live in an optional subpath import (`@bastani/atomic-schema/formats`).
14
14
 
15
- Atomic validates tool arguments with `@bastani/atomic-schema`. See [Tool parameter schemas](/extensions#tool-parameter-schemas) and [Standalone libraries](/libraries). Extensions can import `@bastani/atomic-schema` from the host without installing it.
15
+ Atomic validates tool arguments with `@bastani/atomic-schema` (see [Tool parameter schemas](/extensions#tool-parameter-schemas) and [Standalone libraries](/libraries)). Extensions can import it without installing it.
16
16
 
17
17
  ## Installation
18
18
 
@@ -26,16 +26,16 @@ npm install @bastani/atomic-schema
26
26
  import { compile, int, obj, oneOf, opt, type Static, str } from "@bastani/atomic-schema";
27
27
 
28
28
  const Read = obj({
29
- path: str({ description: "Path to the file", minLength: 1 }),
30
- offset: opt(int({ minimum: 1 })),
31
- mode: oneOf(["text", "binary"]),
29
+ path: str({ description: "Path to the file", minLength: 1 }),
30
+ offset: opt(int({ minimum: 1 })),
31
+ mode: oneOf(["text", "binary"]),
32
32
  });
33
33
  type Read = Static<typeof Read>; // { path: string; mode: "text" | "binary"; offset?: number }
34
34
 
35
35
  const read = compile(Read);
36
36
  const value: unknown = { path: "README.md", mode: "text" };
37
37
  if (read.check(value)) {
38
- console.log(value.path); // value is narrowed to Read
38
+ console.log(value.path); // narrowed to Read
39
39
  }
40
40
 
41
41
  read.errors({ offset: 0, extra: true });
@@ -47,15 +47,15 @@ read.errors({ offset: 0, extra: true });
47
47
  // ]
48
48
  ```
49
49
 
50
- `Read` is plain JSON Schema (`{ type: "object", properties: {...}, required: ["path", "mode"], additionalProperties: false }`), ready for a tool definition or `JSON.stringify`. `compile()` accepts any JSON Schema, whether created with the builders or written by hand.
50
+ `Read` is a plain JSON Schema object (`{ type: "object", properties: {...}, required: ["path", "mode"], additionalProperties: false }`), ready for tool definitions or `JSON.stringify`. `compile()` accepts any JSON Schema, built or handwritten.
51
51
 
52
- `check(value)` is the fast boolean path. It is a standalone function you can pass around, and it avoids allocations for most schemas.
53
-
54
- `errors(value)` explains failures and returns `ValidationError[]` (`{ path: string; keyword: string; message: string }`), or `[]` for valid values. The error explainer is built on the first failure and reused, so schemas whose inputs always pass never pay for it. `validate(value)` runs both without modifying the input and returns `ParseResult<T>` (`{ ok: true; value: T } | { ok: false; errors: ValidationError[] }`).
52
+ - `check(value)` is the fast boolean path (standalone function, allocation-free for most schemas).
53
+ - `errors(value)` returns `ValidationError[]` (`{ path, keyword, message }`), building the error explainer lazily on the first failure.
54
+ - `validate(value)` returns `ParseResult<T>` (`{ ok: true; value: T } | { ok: false; errors: ValidationError[] }`) without modifying the input.
55
55
 
56
56
  ### Builders
57
57
 
58
- | Builder | Schema | Type |
58
+ | Builder | Schema | Inferred type |
59
59
  | --- | --- | --- |
60
60
  | `str({ minLength, maxLength, pattern, format })` | `{ type: "string", ... }` | `string` |
61
61
  | `num({ minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf })`, `int(...)` | `{ type: "number" }`, `{ type: "integer" }` | `number` |
@@ -73,26 +73,31 @@ read.errors({ offset: 0, extra: true });
73
73
  | `unsafe<T>(schema)` | `schema` as given (`{}` by default) | `T`, unchecked |
74
74
  | `recursive<T>(id, (self) => schema)` | `schema` with `$id: id`; `self` is `{ $ref: id }` | `T` |
75
75
 
76
- Every builder also accepts `title`, `description`, `examples`, `deprecated`, and `default`. A `default` is an annotation only, and validation never inserts it.
76
+ Every builder accepts `title`, `description`, `examples`, `deprecated`, and `default`.
77
+
78
+ <Note>
79
+ `default` is a schema annotation only—validation and coercion never insert default values into your data.
80
+ </Note>
77
81
 
78
- A union of objects tagged by a `lit()` property checks and reports errors by the tag. Only the branch matching the tag runs.
82
+ Unions of objects discriminated by a `lit()` property check only the matching branch and report tag errors directly:
79
83
 
80
84
  ```typescript
81
- const Block = union([obj({ kind: lit("text"), text: str() }), obj({ kind: lit("image"), width: int({ minimum: 0 }) })]);
85
+ const Block = union([
86
+ obj({ kind: lit("text"), text: str() }),
87
+ obj({ kind: lit("image"), width: int({ minimum: 0 }) }),
88
+ ]);
82
89
  compile(Block).errors({ kind: "video" });
83
90
  // [{ path: "/kind", keyword: "anyOf", message: 'expected one of ["text","image"]' }]
84
91
  ```
85
92
 
86
- A recursive schema needs an explicit type argument because TypeScript cannot infer recursive types from builders. Its `id` must be unique among recursive schemas inside the same root schema:
93
+ Recursive schemas require an explicit type argument and a unique `id` within the root schema:
87
94
 
88
95
  ```typescript
89
96
  type Tree = { name: string; children: Tree[] };
90
97
  const Tree = recursive<Tree>("Tree", (self) => obj({ name: str(), children: arr(self) }));
91
98
  ```
92
99
 
93
- `Static` also infers types for TypeBox 1.x schemas by reading TypeBox's type shapes without importing TypeBox. Supported TypeBox kinds are `String`, `Number`, `Integer`, `Boolean`, `Null`, `Literal`, `Array`, `Object` (with `Type.Optional` and `Type.Readonly` properties), `Union`, `Record`, `Enum`, `Tuple`, `BigInt`, `Undefined`, `Unsafe`, `Unknown`, and `Any`. For example, `Static<typeof Type.Object({ path: Type.String() })>` resolves to `{ path: string }`.
94
-
95
- Other TypeBox kinds such as `Intersect`, `Cyclic`, and `Ref` resolve to `unknown`, as do plain JSON Schema objects without builder brands.
100
+ `Static` also infers types for TypeBox 1.x schemas without importing TypeBox (`String`, `Number`, `Integer`, `Boolean`, `Null`, `Literal`, `Array`, `Object` with `Type.Optional`/`Type.Readonly`, `Union`, `Record`, `Enum`, `Tuple`, `BigInt`, `Undefined`, `Unsafe`, `Unknown`, and `Any`). Other TypeBox kinds (`Intersect`, `Cyclic`, `Ref`) and unbranded plain JSON Schemas resolve to `unknown`.
96
101
 
97
102
  ### Options
98
103
 
@@ -100,74 +105,75 @@ Other TypeBox kinds such as `Intersect`, `Cyclic`, and `Ref` resolve to `unknown
100
105
  import { formats } from "@bastani/atomic-schema/formats";
101
106
 
102
107
  const validator = compile(schema, {
103
- draft: "7", // "2020-12" (default) or "7"
104
- formats, // check `format`; without it `format` is an annotation, as 2020-12 specifies
105
- schemas: { "https://example.com/point.json": point }, // documents for $refs to other documents, by URI
106
- unresolvedRefs: "reject", // a $ref that names nothing rejects values at its place; default "throw"
107
- coerce: true, // adds coerce() and parse(), see Coercion
108
+ draft: "7", // "2020-12" (default) or "7"
109
+ formats, // check `format`; omitted keeps `format` as an annotation
110
+ schemas: { "https://example.com/point.json": point }, // external $ref documents by URI
111
+ unresolvedRefs: "reject", // compile dangling $ref as false instead of throwing (default "throw")
112
+ coerce: true, // enable coerce() and parse() (see Coercion below)
108
113
  });
109
114
  ```
110
115
 
111
- `formats` includes all 21 supported format keys: `date`, `date-time`, `duration`, `email`, `hostname`, `idn-email`, `idn-hostname`, `ipv4`, `ipv6`, `iri`, `iri-reference`, `json-pointer`, `json-pointer-uri-fragment`, `regex`, `relative-json-pointer`, `time`, `uri`, `uri-reference`, `uri-template`, `url`, and `uuid`. Pass your own record to check a subset of formats or add custom checks.
116
+ `formats` provides 21 checks: `date`, `date-time`, `duration`, `email`, `hostname`, `idn-email`, `idn-hostname`, `ipv4`, `ipv6`, `iri`, `iri-reference`, `json-pointer`, `json-pointer-uri-fragment`, `regex`, `relative-json-pointer`, `time`, `uri`, `uri-reference`, `uri-template`, `url`, and `uuid`. You can also pass a custom format map.
112
117
 
113
- By default, an unresolved `$ref` (a missing definition or a document not in `schemas`) throws during `compile()`. With `unresolvedRefs: "reject"`, that reference compiles as `false` instead. Only values at that position fail, with the error `unresolved reference <ref>`, while the rest of the schema continues to validate. Use this option for external schemas such as MCP tool schemas whose references may dangle.
118
+ With `unresolvedRefs: "reject"`, a dangling `$ref` compiles as `false` so only values at that location fail with `unresolved reference <ref>` while the rest of the schema validates normally (useful for external MCP tool schemas).
114
119
 
115
120
  ### TypeBox schemas
116
121
 
117
- TypeBox 1.x schemas are JSON Schema objects, so they compile directly. Inside Atomic extensions and SDK apps, import `Type` from `@bastani/atomic/typebox`; in standalone apps using `@bastani/atomic-schema` alone, import from `typebox` directly:
122
+ TypeBox 1.x schemas are plain JSON Schema objects and compile directly. Inside Atomic extensions and SDK apps, import `Type` from `@bastani/atomic/typebox`; in standalone apps, import from `typebox`:
118
123
 
119
124
  ```typescript
120
- import Type from "typebox"; // standalone app; inside Atomic use: import { Type } from "@bastani/atomic/typebox"
125
+ import Type from "typebox"; // inside Atomic use: import { Type } from "@bastani/atomic/typebox"
121
126
 
122
127
  const user = compile(Type.Object({ name: Type.String(), tags: Type.Array(Type.String()) }));
123
128
  ```
124
129
 
125
- TypeBox's `BigInt` and `Undefined` types are supported (see Values). JavaScript-only types such as `Function` and `Symbol`, along with refinements and codecs, are not JSON Schema and are not supported.
130
+ TypeBox's `BigInt` and `Undefined` types are supported (see [Values](#values)). JavaScript-only types (`Function`, `Symbol`), refinements, and codecs are not JSON Schema and are not supported.
126
131
 
127
132
  ### Coercion
128
133
 
129
- `compile(schema, { coerce: true })` adds `coerce()` and `parse()` for loosely typed inputs such as model tool call arguments. Without `coerce: true`, the validator exposes neither method and builds no coercion code. Even with `coerce: true`, coercion rules are built lazily on the first call to `coerce()` or `parse()`.
134
+ Pass `{ coerce: true }` to `compile()` to enable `coerce()` and `parse()` for loosely typed inputs such as model tool-call arguments. Without `coerce: true`, neither method is exposed and no coercion code is built; with it, coercion compiles lazily on the first call.
130
135
 
131
136
  ```typescript
132
137
  const read = compile(Read, { coerce: true });
133
138
 
134
- read.coerce({ path: "a.txt", offset: "10", mode: "text" }); // { path: "a.txt", offset: 10, mode: "text" }
139
+ read.coerce({ path: "a.txt", offset: "10", mode: "text" });
140
+ // { path: "a.txt", offset: 10, mode: "text" }
135
141
 
136
142
  const result = read.parse({ path: "a.txt", offset: "ten", mode: "text" });
137
143
  if (result.ok) result.value.offset; // number
138
144
  else result.errors; // [{ path: "/offset", keyword: "type", message: "expected integer, got string" }]
139
145
  ```
140
146
 
141
- `coerce(value)` returns the coerced value. It copies only changed paths, returns `value` unchanged when no rule applies, and never mutates `value`. `parse(value)` coerces and then validates, returning `{ ok: true, value }` for a valid coerced value or `{ ok: false, errors }` when validation fails.
147
+ `coerce(value)` returns the converted value without mutating `value` (copying only changed paths and returning `value` unchanged when nothing changes). `parse(value)` coerces and then validates, returning `{ ok: true, value }` or `{ ok: false, errors }`.
142
148
 
143
- Three passes run in order:
149
+ Coercion runs three passes in order:
144
150
 
145
- 1. **Optional nulls.** A `null` in an optional property whose schema rejects `null` is dropped as if omitted.
146
- 2. **TypeBox-style conversions.** Runs on the first applicable JSON Schema keyword. `$ref` follows the reference. `const` and `enum` pick the member the value converts to. `anyOf` and `oneOf` keep a value one branch already accepts, or take the first branch conversion that passes the whole schema. `allOf` converts with each member in order. Otherwise, conversion follows `type`:
147
- * `string`: numbers and booleans become text, and `null` becomes `"null"`.
148
- * `number`: numeric strings (`""` becomes `0`), `"true"` and `"false"`, booleans become `1` or `0`, and `null` becomes `0`.
149
- * `integer`: same as `number`, then truncated (`"3.5"` and `3.5` become `3`).
150
- * `boolean`: `"true"` and `"false"` in any case, `"1"` and `"0"`, `1` and `0`, and `null` becomes `false`.
151
- * `null`: `"null"`, `"undefined"`, `""`, `"0"`, `0`, and `false`.
152
- * `bigint`: integer strings (`"12"`, `"12n"`, with `"12.9"` truncated), numbers truncated, `"true"`, `"false"`, and booleans become `1n` or `0n`, and `null` becomes `0n`.
153
- * `undefined`: `"undefined"`, `"null"`, `""`, `"0"`, `0`, `0n`, `false`, and `null`.
154
- * `array`: a single value becomes a one-item array, then each item converts. A tuple (`prefixItems` or a draft-7 `items` array) converts its items without wrapping.
155
- * `object`: each property converts according to `properties`, `patternProperties`, or `additionalProperties`.
156
- 3. **Scalar coercion by type.** Matches Ajv's `coerceTypes` for values left by pass 2, such as type arrays like `["integer", "null"]`. Numbers convert from numeric strings and booleans, booleans from `"true"`, `"false"`, `1`, and `0`, strings from numbers and booleans, `null` from `""`, `0`, and `false`, and `null` converts to `""`, `0`, or `false`. A value that already matches one type in a type array stays unchanged.
151
+ 1. **Drop optional nulls:** Removes `null` from any optional object property (under `properties`, `patternProperties`, or `additionalProperties`) whose schema rejects `null`, treating the field as omitted.
152
+ 2. **Schema-driven conversion:** Follows `$ref`, `const`/`enum` (converting to a matching member), `anyOf`/`oneOf` (keeping an already-valid value, or picking the first branch conversion that satisfies the full schema), and `allOf` (converting through each member in order). For typed schemas, converts according to the table below:
157
153
 
158
- Where passes 2 and 3 disagree, pass 2 wins. For example, `null` for a required string becomes `"null"`, not `""`.
154
+ | Target type | Accepted conversions (Pass 2) |
155
+ | --- | --- |
156
+ | `string` | Numbers and booleans convert to text; `null` converts to `"null"`. |
157
+ | `number` | Numeric strings (`""` → `0`), `"true"`/`"false"`, booleans (`true` → `1`, `false` → `0`), and `null` (`0`). |
158
+ | `integer` | Same as `number`, then truncated toward zero (`"3.5"` and `3.5` → `3`). |
159
+ | `boolean` | `"true"`/`"false"` (case-insensitive), `"1"`/`"0"`, `1`/`0`, and `null` (`false`). |
160
+ | `null` | `"null"`, `"undefined"`, `""`, `"0"`, `0`, and `false`. |
161
+ | `bigint` | Integer strings (`"12"`, `"12n"`, `"12.9"` → `12n`), truncated numbers, `"true"`/`"false"`, booleans (`1n`/`0n`), and `null` (`0n`). |
162
+ | `undefined` | `"undefined"`, `"null"`, `""`, `"0"`, `0`, `0n`, `false`, and `null`. |
163
+ | `array` | Wraps a non-array value in a single-item array, then converts each item. Tuples (`prefixItems` or draft-7 `items` arrays) convert items in place without wrapping. |
164
+ | `object` | Converts each property using `properties`, `patternProperties`, or `additionalProperties`. |
159
165
 
160
- Union branches convert in order and stop at the first accepted branch. If a union node also declares properties, those properties convert into each candidate before checking it. In recursive schemas reached through `$ref`, a value that cannot convert stays unchanged so `check()` reports it, and `$ref` results are reused within one call so recursive unions do not re-convert the same child for every branch.
166
+ 3. **Type-array scalar fallback:** For values untouched by pass 2—most notably multi-type arrays such as `["integer", "null"]`—applies standard scalar conversions (numeric strings/booleans to numbers, `"true"`/`"false"`/`1`/`0` to booleans, numbers/booleans to strings, `""`/`0`/`false` to `null`, and `null` to `""`/`0`/`false`) while leaving any value that already matches one type in the array unchanged.
161
167
 
162
- Pass 1 drops optional nulls inside values of `properties`, `patternProperties`, and `additionalProperties`, while leaving pattern and additional keys themselves intact. Items past a draft-7 `items` array (`additionalItems`) are not coerced by any pass.
168
+ When passes 2 and 3 differ, pass 2 wins (for example, `null` for a required `string` becomes `"null"`, not `""`). Union branches evaluate in order and reuse recursive `$ref` conversions within a call; unconvertible values remain unchanged so validation reports them cleanly. Items beyond a draft-7 `items` tuple (`additionalItems`) are not coerced.
163
169
 
164
170
  ### Values
165
171
 
166
- - An optional property whose value is `undefined` counts as absent, matching TypeBox. A required property set to `undefined` counts as present. It is valid when its schema accepts `undefined` (`Type.Undefined()`, `Type.Unknown()`, or `Type.Any()`), and reported as missing otherwise.
167
- - `{ type: "bytes", minLength, maxLength }` matches a `Uint8Array` within those length bounds for binary values that do not pass through JSON.
168
- - `{ type: "bigint" }` matches a `bigint`. Number bounds (`minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf`) apply to both numbers and bigints with bounds of either kind.
172
+ - An optional property whose value is `undefined` counts as absent. A required property set to `undefined` counts as present—valid only if its schema accepts `undefined`, and reported as missing otherwise.
173
+ - `{ type: "bytes", minLength, maxLength }` matches a `Uint8Array` within those length bounds.
174
+ - `{ type: "bigint" }` matches a `bigint`; numeric bounds (`minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf`) work with both `number` and `bigint` bounds.
169
175
  - `{ type: "undefined" }` matches `undefined`.
170
- - `equal(a, b)` checks JSON value equality using the same rules as `const`, `enum`, and `uniqueItems`.
176
+ - `equal(a, b)` tests JSON value equality with the same rules as `const`, `enum`, and `uniqueItems`.
171
177
 
172
178
  ## Supported keywords
173
179
 
@@ -4,12 +4,12 @@ sidebarTitle: "@bastani/atomic-storage-postgres"
4
4
  description: "PostgreSQL storage adapter for Atomic sessions and Intercom multi-node routing, usable from the CLI or TypeScript SDK."
5
5
  ---
6
6
 
7
- `@bastani/atomic-storage-postgres` is Atomic's standalone [PostgreSQL](https://www.postgresql.org) storage adapter. It stores sessions and Intercom multi-node routing in one shared PostgreSQL database so multiple machines or SDK hosts can share state. Unlike the six core libraries in [Standalone libraries](/libraries), this package is not bundled inside `@bastani/atomic`; install it only when you use PostgreSQL.
7
+ `@bastani/atomic-storage-postgres` is Atomic's optional standalone [PostgreSQL](https://www.postgresql.org) storage adapter. It stores sessions and Intercom multi-node routing in one shared PostgreSQL database so multiple machines or SDK hosts can share state. Unlike the six core libraries in [Standalone libraries](/libraries), this package is not bundled inside `@bastani/atomic`; install it only when you use PostgreSQL.
8
8
 
9
9
  - **PostgreSQL version requirement:** Atomic needs **PostgreSQL 16 or newer**.
10
- - **Plain ESM with types:** Ships plain JavaScript ESM and TypeScript declarations (`postgres.d.ts`), requiring Node.js 24.20+ with no TypeScript loader.
10
+ - **Plain ESM with bundled types:** Ships plain JavaScript ESM with TypeScript declarations and requires Node.js 24.20+ with no TypeScript loader.
11
11
 
12
- For operator setup, role creation SQL, migrations, and troubleshooting, see [PostgreSQL setup](/storage/postgres). For all five SDK storage backends and `createAgentSessionRuntime()`, see [SDK storage backends](/sdk/storage).
12
+ For operator setup, role creation SQL, migrations, and troubleshooting, see [PostgreSQL setup](/storage/postgres). For all four SDK storage backends and `createAgentSessionRuntime()`, see [SDK storage backends](/sdk/storage).
13
13
 
14
14
  ## Installation
15
15
 
@@ -62,63 +62,77 @@ Pass the returned `SqliteDatabase` to `createAgentSession({ sessionStore: { kind
62
62
  | Option | Type | Default | Description |
63
63
  | --- | --- | --- | --- |
64
64
  | `url` | `string` *(required)* | — | A `postgres://` or `postgresql://` URL with a username and no embedded password. Any password in the URL or a `password=` query parameter is rejected with `credential-in-url`. |
65
- | `password` | `string \| (() => Promise<string>)` | — | Password string or async callback invoked for each new connection, and once when the database opens to tell its credential apart from other databases' in the shared pool. Omit when using cloud `auth`; combining cloud `auth` with `password` throws `conflicting-token`. |
65
+ | `password` | `string \| (() => Promise<string>)` | — | Password string or async callback invoked for each new connection, and once on open to distinguish its credential in the shared pool. Omit when using cloud `auth`; combining cloud `auth` with `password` throws `conflicting-token`. |
66
66
  | `auth` | `"password" \| "azure-entra" \| "aws-iam" \| "gcp-iam"` | `"password"` | Credential strategy. Cloud modes request short-lived tokens per new connection via the provider's SDK. |
67
- | `maxConnections` | `number` | `8` (`DEFAULT_MAX_CONNECTIONS`) | Most connections the process's main pool opens. A positive integer. Every database the process opens with the same `url`, role, password, `listenUrl`, `auth`, `schema`, `proxy`, `socket` and pool options shares one main pool, one reader pool and one listening connection, and the last one to close closes them. To size it, see [Tuning for many concurrent agents](/storage/postgres#tuning-for-many-concurrent-agents). |
68
- | `readerMaxConnections` | `number` | `2` (`DEFAULT_READER_MAX_CONNECTIONS`) | Most connections in the reader pool that every handle `openReader()` returns shares, capped at `maxConnections`. A non-negative integer. `0` leaves `openReader` undefined, so reads share the main pool. |
69
- | `statementTimeoutMs` | `number` | `30000` (`DEFAULT_STATEMENT_TIMEOUT_MS`) | How long one statement may run, in milliseconds, before the server cancels it. A positive integer. |
70
- | `connectTimeoutMs` | `number` | `10000` (`DEFAULT_CONNECT_TIMEOUT_MS`) | How long opening a connection, or waiting for a free pooled one, may take, in milliseconds. A positive integer. |
71
- | `idleTimeoutMs` | `number` | `300000` (`DEFAULT_IDLE_TIMEOUT_MS`) | How long a pool's last connection stays open after the pool's last call, in milliseconds. Connections opened for a burst close after `SURGE_IDLE_TIMEOUT_MS` (`10000`) idle, or after `idleTimeoutMs` when it is shorter. A positive integer. |
72
- | `keepAliveIdleMs` | `number` | `60000` (`DEFAULT_KEEPALIVE_IDLE_MS`) | How long a pooled connection sits unused, in milliseconds, before TCP keepalive probes start. A positive integer. |
73
- | `maxPreparedStatements` | `number` | `256` (`DEFAULT_MAX_PREPARED_STATEMENTS`); `0` when `listenUrl` is set or the URL's port is `6432` or `6543` | How many statements each pooled connection keeps prepared, so the server parses and plans each one once per connection. `0` turns them off, for example behind a pooler without prepared-statement support. |
67
+ | `maxConnections` | `number` | `8` (`DEFAULT_MAX_CONNECTIONS`) | Maximum connections in the process's main pool (positive integer). Databases opened in the same process with identical connection, auth, schema, transport, and pool options share one main pool, one reader pool, and one listening connection, closed when the last handle closes. See [Tuning for many concurrent agents](/storage/postgres#tuning-for-many-concurrent-agents). |
68
+ | `readerMaxConnections` | `number` | `2` (`DEFAULT_READER_MAX_CONNECTIONS`) | Maximum connections in the shared reader pool for `openReader()` handles, capped at `maxConnections`. `0` disables the separate reader pool so reads share the main pool. |
69
+ | `statementTimeoutMs` | `number` | `30000` (`DEFAULT_STATEMENT_TIMEOUT_MS`) | Maximum time one statement may run before the server cancels it, in milliseconds (positive integer). |
70
+ | `connectTimeoutMs` | `number` | `10000` (`DEFAULT_CONNECT_TIMEOUT_MS`) | Maximum time to open a connection or wait for a free pooled connection, in milliseconds (positive integer). |
71
+ | `idleTimeoutMs` | `number` | `300000` (`DEFAULT_IDLE_TIMEOUT_MS`) | How long a pool's last connection stays open while idle, in milliseconds. Burst connections close after `SURGE_IDLE_TIMEOUT_MS` (`10000`) idle, or `idleTimeoutMs` if shorter. |
72
+ | `keepAliveIdleMs` | `number` | `60000` (`DEFAULT_KEEPALIVE_IDLE_MS`) | Idle milliseconds before TCP keepalive probes start on pooled connections. |
73
+ | `maxPreparedStatements` | `number` | `256` (`DEFAULT_MAX_PREPARED_STATEMENTS`) on direct connections and PgBouncer 1.21+ with `max_prepared_statements > 0`; `0` behind other transaction poolers (auto-detected on the first connection) | Maximum statements each pooled connection keeps prepared so PostgreSQL parses and plans them once per connection. Pass `0` to force unnamed statements, or pass a positive integer to override auto-detection or change the cap. |
74
74
  | `listenUrl` | `string` | `url` | Direct session-mode endpoint for `LISTEN`/`NOTIFY` wake-ups when `url` goes through a transaction pooler. |
75
- | `schema` | `string` | `"atomic"` (`DEFAULT_SCHEMA`) | Lowercase schema holding Atomic's tables. Existing databases with tables in `public` and no `atomic` schema keep using `public` until `atomic storage migrate` moves them. Every transaction sets `SET LOCAL search_path`. |
75
+ | `schema` | `string` | `"atomic"` (`DEFAULT_SCHEMA`) | Lowercase schema holding Atomic's tables. Databases whose existing tables live in `public` without an `atomic` schema continue using `public` until `atomic storage migrate` moves them. Every transaction runs `SET LOCAL search_path`. |
76
76
  | `sdkSearchPaths` | `readonly string[]` | — | Extra npm prefix directories to search when loading a cloud IAM SDK not found beside the adapter. CLI adapter loading passes `<agentDir>/npm`. |
77
77
  | `proxy` | `string` | Environment proxy | An `http://` or `https://` proxy URL for `CONNECT` tunneling (credentials sent in `Proxy-Authorization` and redacted), or `"none"` to connect directly. Overrides environment proxy variables for TCP hosts. |
78
- | `socket` | `PostgresSocketFactory` | — | Custom transport callback `(target: ProxyTarget) => Duplex \| Promise<Duplex>` carrying the PostgreSQL protocol (`target` has `{ host, port }` from `url` or `PGHOST`/`PGPORT`). Atomic negotiates TLS over it as over a normal socket. Cannot be combined with `proxy` (`conflicting-transport`). Socket directories always connect directly. |
78
+ | `socket` | `PostgresSocketFactory` | — | Custom transport callback `(target: ProxyTarget) => Duplex \| Promise<Duplex>` carrying PostgreSQL wire traffic (`target` has `{ host, port }`). Atomic negotiates TLS over it as over a normal socket. Cannot be combined with `proxy` (`conflicting-transport`). Unix socket directories always connect directly. |
79
79
 
80
80
  ## Exported API
81
81
 
82
- - `openPostgresDatabase(options: PostgresDatabaseOptions): Promise<SqliteDatabase>` — opens a pooled PostgreSQL-backed `SqliteDatabase`.
83
- - `DEFAULT_MAX_CONNECTIONS` (`8`), `DEFAULT_READER_MAX_CONNECTIONS` (`2`), `DEFAULT_STATEMENT_TIMEOUT_MS` (`30000`), `DEFAULT_CONNECT_TIMEOUT_MS` (`10000`), `DEFAULT_IDLE_TIMEOUT_MS` (`300000`), `SURGE_IDLE_TIMEOUT_MS` (`10000`), `DEFAULT_KEEPALIVE_IDLE_MS` (`60000`), `DEFAULT_MAX_PREPARED_STATEMENTS` (`256`), `DEFAULT_SCHEMA` (`"atomic"`).
84
- - `numberPlaceholders(sql: string): string` — rewrites positional `?` parameters outside string literals, quoted identifiers, and comments to `$1`, `$2`, ....
85
- - `physicalIdentifiers(sql: string): string` — replaces unquoted identifiers longer than 63 bytes with their deterministic PostgreSQL physical identifier.
86
- - Types: `PostgresDatabaseOptions`, `PostgresSocketFactory`, `ProxyTarget`.
87
- - Default export: `StorageAdapterModule` (`{ atomicStorageAdapter: 1, liveSecrets, openDatabase }`) used by `atomic` CLI settings and `{ kind: "adapter" }` selections.
82
+ - **`openPostgresDatabase(options: PostgresDatabaseOptions): Promise<SqliteDatabase>`** — opens a pooled PostgreSQL-backed `SqliteDatabase`.
83
+ - **Default constants:** `DEFAULT_MAX_CONNECTIONS` (`8`), `DEFAULT_READER_MAX_CONNECTIONS` (`2`), `DEFAULT_STATEMENT_TIMEOUT_MS` (`30000`), `DEFAULT_CONNECT_TIMEOUT_MS` (`10000`), `DEFAULT_IDLE_TIMEOUT_MS` (`300000`), `SURGE_IDLE_TIMEOUT_MS` (`10000`), `DEFAULT_KEEPALIVE_IDLE_MS` (`60000`), `DEFAULT_MAX_PREPARED_STATEMENTS` (`256`), `DEFAULT_SCHEMA` (`"atomic"`).
84
+ - **Types:** `PostgresDatabaseOptions`, `PostgresSocketFactory`, `ProxyTarget`.
85
+ - **Default export:** `StorageAdapterModule` (`{ atomicStorageAdapter: 1, liveSecrets, openDatabase }`) used by Atomic CLI settings and `{ kind: "adapter" }` selections.
86
+
87
+ <Note>
88
+ **Low-level SQL translation helpers:** The package also exports `numberPlaceholders(sql)` (rewrites positional `?` parameters outside literals, quoted identifiers, and comments to `$1`, `$2`, ...) and `physicalIdentifiers(sql)` (replaces unquoted identifiers longer than 63 bytes with deterministic PostgreSQL physical names). Ordinary applications do not need to call these directly—they are provided for custom adapters or tooling translating Atomic SQLite queries to PostgreSQL.
89
+ </Note>
88
90
 
89
91
  ## Cloud IAM authentication
90
92
 
91
- On Azure, AWS, and Google Cloud, set `auth` and omit `password` / `secrets.password`. Only the selected provider's SDK is loaded on first connection. Tokens stay in memory, never appear in settings or errors, time out after 8 seconds, and clear and retry once on rejection (`28P01`, or Azure `28000`). Missing SDKs or token failures throw `StorageConfigError` (`reason: "auth-unavailable"`). Cloud tokens require TLS (`sslmode=verify-full` or `require`).
93
+ On Azure, AWS, and Google Cloud, set `auth` and omit `password` / `secrets.password`. Only the selected provider's SDK loads on first connection. Tokens stay in memory, never appear in settings or errors, time out after 8 seconds, and clear and retry once on rejection (`28P01`, or Azure `28000`). Missing SDKs or token failures throw `StorageConfigError` (`reason: "auth-unavailable"`). Cloud tokens require TLS (`sslmode=verify-full` or `require`).
92
94
 
93
95
  | `auth` | Optional peer SDK | CLI user-scope install | Credential source |
94
96
  | --- | --- | --- | --- |
95
- | `azure-entra` | `@azure/identity` | `atomic install npm:@azure/identity@4.14.1` | `DefaultAzureCredential` for `https://ossrdbms-aad.database.windows.net/.default` (reused until 5 minutes before expiry) |
96
- | `aws-iam` | `@aws-sdk/rds-signer` | `atomic install npm:@aws-sdk/rds-signer@3.1169.0` | RDS `Signer` using the AWS default credential chain (`AWS_*`, profiles, IRSA, instance profile) |
97
- | `gcp-iam` | `google-auth-library` | `atomic install npm:google-auth-library@11.3.4` | `GoogleAuth` for `https://www.googleapis.com/auth/sqlservice.login` (ADC, GKE/GCE/Cloud Run metadata) |
97
+ | `azure-entra` | `@azure/identity` | `atomic install npm:@azure/identity` | `DefaultAzureCredential` for `https://ossrdbms-aad.database.windows.net/.default` (reused until 5 minutes before expiry) |
98
+ | `aws-iam` | `@aws-sdk/rds-signer` | `atomic install npm:@aws-sdk/rds-signer` | RDS `Signer` using the AWS default credential chain (`AWS_*`, profiles, IRSA, instance profile) |
99
+ | `gcp-iam` | `google-auth-library` | `atomic install npm:google-auth-library` | `GoogleAuth` for `https://www.googleapis.com/auth/sqlservice.login` (ADC, GKE/GCE/Cloud Run metadata) |
98
100
 
99
- For Azure Database for PostgreSQL Flexible Server (PostgreSQL 16+), Azure HorizonDB (PostgreSQL 17, read/write endpoint), Amazon RDS/Aurora, and Google Cloud SQL role-grant SQL, see [PostgreSQL setup](/storage/postgres#azure) and [Cloud identities](/storage/postgres#cloud-identities).
101
+ For Azure Database for PostgreSQL Flexible Server (PostgreSQL 16+), Azure HorizonDB (PostgreSQL 17, read/write endpoint), Amazon RDS/Aurora, and Google Cloud SQL role-grant SQL, see [Cloud identities](/storage/postgres#cloud-identities).
100
102
 
101
103
  ## TLS, HTTP proxies, and connection poolers
102
104
 
103
105
  - **TLS defaults:** When `url` omits `sslmode`, Atomic applies `sslmode=verify-full` for remote hosts (checking `PGHOST` if omitted from the URL). Add `sslrootcert=/path/to/ca.pem` for private CAs. Without `sslrootcert`, `require` verifies both certificate and hostname like `verify-full` (stricter than libpq). TLS parameter names are case-sensitive; unknown `sslmode` values are rejected.
104
106
  - **HTTP `CONNECT` proxies:** Without `options.proxy`, remote TCP hosts check `HTTPS_PROXY` (`https_proxy`), then `ALL_PROXY` (when HTTP/HTTPS), then `HTTP_PROXY`, respecting `NO_PROXY`. Loopback hosts and Unix socket directories connect directly. Keep `sslmode=verify-full` (or `verify-ca` with a private CA) so TLS runs end to end through the tunnel.
105
- - **Connection poolers and wake-ups:** Works with transaction-mode poolers (PgBouncer, Azure port `6432`, Supabase Supavisor, Neon `-pooler`) with no session-level state. Prepared statements are off by default behind a pooler, when `listenUrl` is set or the port is `6432` or `6543`. On PgBouncer 1.21 and later with `max_prepared_statements` above `0`, the default from 1.24, set `maxPreparedStatements` to turn them on. A process that listens for wake-ups, as an Intercom broker does, opens one extra `LISTEN` connection outside its pools. When `url` uses a transaction pooler, set `listenUrl` to a direct endpoint, or Atomic falls back to polling. See the [PgBouncer guide](/storage/postgres/pgbouncer).
107
+ - **Connection poolers and wake-ups:** Works with transaction-mode poolers (PgBouncer, Azure port `6432`, Supabase Supavisor, Neon `-pooler`) with no session-level state. Atomic probes the first connection automatically: on PgBouncer 1.21+ with `max_prepared_statements > 0`, it keeps prepared statements enabled (up to `256`); behind transaction poolers that do not support prepared statements (on any port), it disables them automatically. Set `maxPreparedStatements` only to override auto-detection or change the per-connection cap. A process that listens for wake-ups (such as an Intercom broker) opens one extra `LISTEN` connection outside its pools; when `url` uses a transaction pooler, set `listenUrl` to a direct endpoint or Atomic falls back to polling. See the [PgBouncer guide](/storage/postgres/pgbouncer).
106
108
  - **Retries and errors:** Connection drops, lock conflicts (`40001`, `40P01`, `55P03`), and canceled statements (`57014`) throw `StorageTransientError` (read-only and unwritten calls retry automatically). Invalid credentials (`28P01`), missing databases (`3D000`), and certificate errors fail immediately. Missing privileges (`42501`) fail immediately with `StorageConfigError` (`reason: "missing-privilege"`) naming the exact `GRANT` or migration command.
107
109
 
108
110
  ## CLI configuration
109
111
 
110
- Join a machine with the CLI after installing in user scope and running `atomic storage migrate`:
111
-
112
- ```bash
113
- (umask 077; printf 'Runtime password: '; read -rs password; printf '\n'; printf '%s' "$password" > ~/atomic-db-password)
114
- atomic storage join 'postgresql://atomic_runtime@db.example.com:5432/atomic' --password-file ~/atomic-db-password
115
- rm ~/atomic-db-password # atomic storage join keeps its own copy
116
- atomic intercom restart
117
- atomic storage status
118
- ```
112
+ Join a machine with the CLI after installing the adapter in user scope and running `atomic storage migrate`:
113
+
114
+ <Steps>
115
+ <Step title="Write the runtime password to a mode-0600 file">
116
+ ```bash
117
+ (umask 077; printf 'Runtime password: '; read -rs password; printf '\n'; printf '%s' "$password" > ~/atomic-db-password)
118
+ ```
119
+ </Step>
120
+ <Step title="Join the shared database and remove the temporary file">
121
+ ```bash
122
+ atomic storage join 'postgresql://atomic_runtime@db.example.com:5432/atomic' --password-file ~/atomic-db-password
123
+ rm ~/atomic-db-password # atomic storage join keeps its own copy
124
+ ```
125
+ </Step>
126
+ <Step title="Restart Intercom and verify connectivity">
127
+ ```bash
128
+ atomic intercom restart
129
+ atomic storage status
130
+ ```
131
+ </Step>
132
+ </Steps>
119
133
 
120
134
  ## Related docs
121
135
 
122
- - [PostgreSQL operator guide](/storage/postgres): role creation SQL, migrations, Azure/RDS/Cloud SQL setup, and troubleshooting.
136
+ - [PostgreSQL operator guide](/storage/postgres): role creation SQL, migrations, cloud provider setup, and troubleshooting.
123
137
  - [SDK storage backends](/sdk/storage): complete `createAgentSession()`, `createAgentSessionRuntime()`, and error-handling recipes.
124
138
  - [Standalone libraries](/libraries): all published `@bastani/atomic-*` packages.