@bastani/atomic 0.10.9 → 0.10.10-alpha.2

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 (406) hide show
  1. package/CHANGELOG.md +83 -0
  2. package/README.md +226 -163
  3. package/dist/_shared/dist-KOELCESV.js +2 -2
  4. package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
  5. package/dist/_shared/lib-4PES5P4V.js +2 -2
  6. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +27 -12
  7. package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js.map +1 -1
  8. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +47 -7
  9. package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js.map +1 -1
  10. package/dist/_shared/mode-shared-2QJSCUM6.js +48 -19
  11. package/dist/_shared/mode-shared-2QJSCUM6.js.map +1 -1
  12. package/dist/_shared/{p1a-prewarm-UQY3X2UK.js → p1a-prewarm-XIU57JHF.js} +5 -5
  13. package/dist/_shared/{p1a-prewarm-UQY3X2UK.js.map → p1a-prewarm-XIU57JHF.js.map} +1 -1
  14. package/dist/_shared/p2-shell-main-B2WIALFD.js +30 -25
  15. package/dist/_shared/p2-shell-main-B2WIALFD.js.map +1 -1
  16. package/dist/_shared/runtime-O4KCSG4C.js +5 -5
  17. package/dist/_shared/{sdk-OSBEPR3Q.js → sdk-RRLVN7ER.js} +15 -9
  18. package/dist/_shared/sdk-RRLVN7ER.js.map +1 -0
  19. package/dist/_shared/session-data-AHTU7IS6.js +2 -2
  20. package/dist/_shared/session-manager-list-2BLEEZVG.js +1 -1
  21. package/dist/_shared/settings-startup-8-DNZ2RIHM.js +4 -1
  22. package/dist/_shared/settings-startup-8-DNZ2RIHM.js.map +1 -1
  23. package/dist/_shared/{startup-0-0-TYUFUOJZ.js → startup-0-0-4VG2G44V.js} +427 -33
  24. package/dist/_shared/startup-0-0-4VG2G44V.js.map +1 -0
  25. package/dist/_shared/{startup-0-1-W2G2UY7R.js → startup-0-1-XTIL65D4.js} +18 -11
  26. package/dist/_shared/startup-0-1-XTIL65D4.js.map +1 -0
  27. package/dist/_shared/{startup-0-2-UXBUEOXW.js → startup-0-2-27OWFHV6.js} +150 -62
  28. package/dist/_shared/startup-0-2-27OWFHV6.js.map +1 -0
  29. package/dist/_shared/startup-0-3-T4DVFYWX.js +15 -25
  30. package/dist/_shared/startup-0-3-T4DVFYWX.js.map +1 -1
  31. package/dist/_shared/{startup-0-4-HN5EB4K7.js → startup-0-4-ZMJV547D.js} +81 -12
  32. package/dist/_shared/startup-0-4-ZMJV547D.js.map +1 -0
  33. package/dist/_shared/startup-0-5-FD2P735I.js +90 -50
  34. package/dist/_shared/startup-0-5-FD2P735I.js.map +1 -1
  35. package/dist/_shared/startup-10-0-TDQNBDDL.js +5 -5
  36. package/dist/_shared/startup-12-0-55AAXBJZ.js +13 -7
  37. package/dist/_shared/startup-12-0-55AAXBJZ.js.map +1 -1
  38. package/dist/_shared/startup-14-0-MLX36RBG.js +4 -4
  39. package/dist/_shared/startup-15-0-YUKGAC63.js +4 -4
  40. package/dist/_shared/startup-15-1-4S7FLMNG.js +88 -28
  41. package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
  42. package/dist/_shared/startup-8-0-34CBHPZH.js +5 -5
  43. package/dist/_shared/startup-8-1-4KANEHRA.js +61 -17
  44. package/dist/_shared/startup-8-1-4KANEHRA.js.map +1 -1
  45. package/dist/_shared/storage-command-7MGXLJGZ.js +4 -4
  46. package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
  47. package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
  48. package/dist/builtin/intercom/CHANGELOG.md +6 -0
  49. package/dist/builtin/intercom/README.md +87 -116
  50. package/dist/builtin/intercom/broker/broker.bundle.mjs +3 -3
  51. package/dist/builtin/intercom/broker/presence-handler.ts +1 -1
  52. package/dist/builtin/intercom/group.ts +7 -3
  53. package/dist/builtin/intercom/index.bundle.mjs +1 -1
  54. package/dist/builtin/intercom/package.json +1 -1
  55. package/dist/builtin/mcp/README.md +61 -27
  56. package/dist/builtin/mcp/index.bundle.mjs +1 -1
  57. package/dist/builtin/mcp/package.json +1 -1
  58. package/dist/builtin/subagents/CHANGELOG.md +8 -0
  59. package/dist/builtin/subagents/README.md +74 -141
  60. package/dist/builtin/subagents/package.json +1 -1
  61. package/dist/builtin/subagents/src/extension/index.bundle.mjs +213 -74
  62. package/dist/builtin/web-access/CHANGELOG.md +9 -0
  63. package/dist/builtin/web-access/README.md +61 -88
  64. package/dist/builtin/web-access/index.bundle.mjs +387 -351
  65. package/dist/builtin/web-access/package.json +1 -1
  66. package/dist/cli/args.js +2 -2
  67. package/dist/cli/auth-cli.code.js +4 -4
  68. package/dist/cli/auth-cli.impl.js +3 -3
  69. package/dist/cli/auth-cli.js +3 -3
  70. package/dist/cli/blueprint-command.code.js +2 -2
  71. package/dist/cli/blueprint-command.impl.js +3 -3
  72. package/dist/cli/blueprint-command.js +3 -3
  73. package/dist/cli/intercom-command.code.js +3 -3
  74. package/dist/cli/intercom-command.impl.js +3 -3
  75. package/dist/cli/intercom-command.js +3 -3
  76. package/dist/cli/list-models.code.js +3 -3
  77. package/dist/cli/list-models.impl.js +3 -3
  78. package/dist/cli/list-models.js +3 -3
  79. package/dist/cli/session-picker.code.js +2 -2
  80. package/dist/cli/session-picker.impl.js +3 -3
  81. package/dist/cli/session-picker.js +3 -3
  82. package/dist/cli/startup-ui.code.js +2 -2
  83. package/dist/cli/startup-ui.impl.js +3 -3
  84. package/dist/cli/startup-ui.js +3 -3
  85. package/dist/cli/storage-command.impl.js +3 -3
  86. package/dist/cli/storage-command.js +3 -3
  87. package/dist/cli/storage-search-session.code.js +2 -2
  88. package/dist/cli/storage-search-session.impl.js +3 -3
  89. package/dist/cli/storage-search-session.js +3 -3
  90. package/dist/cli/team-command.code.js +2 -2
  91. package/dist/cli/team-command.impl.js +3 -3
  92. package/dist/cli/team-command.js +3 -3
  93. package/dist/cli.js +2 -2
  94. package/dist/core/agent-session-methods.d.ts +4 -1
  95. package/dist/core/agent-session-methods.js.map +1 -1
  96. package/dist/core/agent-session.d.ts +3 -0
  97. package/dist/core/compaction/compactor.d.ts +20 -14
  98. package/dist/core/compaction/errors.d.ts +120 -0
  99. package/dist/core/compaction/index.d.ts +1 -0
  100. package/dist/core/compaction/model-resolver.d.ts +2 -2
  101. package/dist/core/debug.impl.js +3 -3
  102. package/dist/core/debug.js +3 -3
  103. package/dist/core/export-html/card-projection.impl.js +3 -3
  104. package/dist/core/export-html/card-projection.js +3 -3
  105. package/dist/core/export-html/index.code.js +2 -2
  106. package/dist/core/export-html/index.impl.js +3 -3
  107. package/dist/core/export-html/index.js +3 -3
  108. package/dist/core/export-html/json-spans.impl.js +3 -3
  109. package/dist/core/export-html/json-spans.js +3 -3
  110. package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
  111. package/dist/core/export-html/oversized-render-inputs.js +3 -3
  112. package/dist/core/export-html/tool-renderer.code.js +1 -1
  113. package/dist/core/export-html/tool-renderer.impl.js +3 -3
  114. package/dist/core/export-html/tool-renderer.js +3 -3
  115. package/dist/core/extensions/api-types.d.ts +1 -1
  116. package/dist/core/extensions/api-types.js.map +1 -1
  117. package/dist/core/extensions/index.d.ts +1 -1
  118. package/dist/core/extensions/jiti-loader.impl.js +3 -3
  119. package/dist/core/extensions/jiti-loader.js +3 -3
  120. package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
  121. package/dist/core/extensions/jiti-static-loader.js +3 -3
  122. package/dist/core/extensions/loader-host-modules.code.js +1 -1
  123. package/dist/core/extensions/loader-host-modules.impl.js +3 -3
  124. package/dist/core/extensions/loader-host-modules.js +3 -3
  125. package/dist/core/extensions/loader-virtual-modules.js +1 -1
  126. package/dist/core/extensions/provider-types.d.ts +18 -6
  127. package/dist/core/extensions/provider-types.js.map +1 -1
  128. package/dist/core/extensions/runner-context.js +1 -1
  129. package/dist/core/intercom-broker-control-host.code.js +1 -1
  130. package/dist/core/intercom-broker-control-host.impl.js +3 -3
  131. package/dist/core/intercom-broker-control-host.js +3 -3
  132. package/dist/core/intercom-broker-control.code.js +3 -3
  133. package/dist/core/intercom-broker-control.impl.js +3 -3
  134. package/dist/core/intercom-broker-control.js +3 -3
  135. package/dist/core/model-config.d.ts +40 -0
  136. package/dist/core/model-registry.js +1 -1
  137. package/dist/core/model-resolver-scope.d.ts +4 -4
  138. package/dist/core/model-runtime.d.ts +1 -1
  139. package/dist/core/package-manager-storage-adapters.impl.js +3 -3
  140. package/dist/core/package-manager-storage-adapters.js +3 -3
  141. package/dist/core/provider-composer-internal.d.ts +11 -2
  142. package/dist/core/sdk.code.js +3 -3
  143. package/dist/core/sdk.impl.js +3 -3
  144. package/dist/core/sdk.js +3 -3
  145. package/dist/core/session-manager-core.js +5 -5
  146. package/dist/core/session-manager-list.impl.js +3 -3
  147. package/dist/core/session-manager-list.js +3 -3
  148. package/dist/core/session-manager.code.js +1 -1
  149. package/dist/core/session-manager.impl.js +3 -3
  150. package/dist/core/session-manager.js +3 -3
  151. package/dist/core/session-storage.impl.js +3 -3
  152. package/dist/core/session-storage.js +3 -3
  153. package/dist/core/settings-manager-basic-accessors.d.ts +6 -2
  154. package/dist/core/storage/index.js +2 -2
  155. package/dist/core/storage/node-sqlite-thread.js +2 -2
  156. package/dist/core/storage/node-sqlite.js +2 -2
  157. package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
  158. package/dist/core/storage/offline-snapshot-file.js +3 -3
  159. package/dist/core/storage/provider.js +2 -2
  160. package/dist/core/storage/selection.js +2 -2
  161. package/dist/core/storage/session/branch-fork-source.code.js +2 -2
  162. package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
  163. package/dist/core/storage/session/branch-fork-source.js +3 -3
  164. package/dist/core/storage/session/card-view.impl.js +3 -3
  165. package/dist/core/storage/session/card-view.js +3 -3
  166. package/dist/core/storage/session/child-reader.code.js +3 -3
  167. package/dist/core/storage/session/child-reader.impl.js +3 -3
  168. package/dist/core/storage/session/child-reader.js +3 -3
  169. package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
  170. package/dist/core/storage/session/chunked-resume-projection.js +3 -3
  171. package/dist/core/storage/session/expanded-child-details.code.js +2 -2
  172. package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
  173. package/dist/core/storage/session/expanded-child-details.js +3 -3
  174. package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
  175. package/dist/core/storage/session/fork-row-bytes.js +3 -3
  176. package/dist/core/storage/session/fork-row-index.impl.js +3 -3
  177. package/dist/core/storage/session/fork-row-index.js +3 -3
  178. package/dist/core/storage/session/fork-staging.code.js +2 -2
  179. package/dist/core/storage/session/fork-staging.impl.js +3 -3
  180. package/dist/core/storage/session/fork-staging.js +3 -3
  181. package/dist/core/storage/session/fork-window.code.js +3 -3
  182. package/dist/core/storage/session/fork-window.impl.js +3 -3
  183. package/dist/core/storage/session/fork-window.js +3 -3
  184. package/dist/core/storage/session/history-pages.impl.js +3 -3
  185. package/dist/core/storage/session/history-pages.js +3 -3
  186. package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
  187. package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
  188. package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
  189. package/dist/core/storage/session/jsonl-session-store.js +3 -3
  190. package/dist/core/storage/session/memory-session-store.impl.js +3 -3
  191. package/dist/core/storage/session/memory-session-store.js +3 -3
  192. package/dist/core/storage/session/pinned-branch-resume.code.js +3 -3
  193. package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
  194. package/dist/core/storage/session/pinned-branch-resume.js +3 -3
  195. package/dist/core/storage/session/released-history-files.code.js +3 -3
  196. package/dist/core/storage/session/released-history-files.impl.js +3 -3
  197. package/dist/core/storage/session/released-history-files.js +3 -3
  198. package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
  199. package/dist/core/storage/session/resident-fork-rows.js +3 -3
  200. package/dist/core/storage/session/session-resume.impl.js +3 -3
  201. package/dist/core/storage/session/session-resume.js +3 -3
  202. package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
  203. package/dist/core/storage/session/snapshot-cut.js +3 -3
  204. package/dist/core/storage/session/snapshot-history.code.js +3 -3
  205. package/dist/core/storage/session/snapshot-history.impl.js +3 -3
  206. package/dist/core/storage/session/snapshot-history.js +3 -3
  207. package/dist/core/storage/session/sql-session-store.code.js +1 -1
  208. package/dist/core/storage/session/sql-session-store.impl.js +3 -3
  209. package/dist/core/storage/session/sql-session-store.js +3 -3
  210. package/dist/core/storage/session/tree-outline.impl.js +3 -3
  211. package/dist/core/storage/session/tree-outline.js +3 -3
  212. package/dist/core/storage/session/tree-presentation.impl.js +3 -3
  213. package/dist/core/storage/session/tree-presentation.js +3 -3
  214. package/dist/core/storage/storage-status.impl.js +3 -3
  215. package/dist/core/storage/storage-status.js +3 -3
  216. package/dist/core/storage/team.impl.js +3 -3
  217. package/dist/core/storage/team.js +3 -3
  218. package/dist/core/structured-output/index.code.js +1 -1
  219. package/dist/core/structured-output/index.impl.js +3 -3
  220. package/dist/core/structured-output/index.js +3 -3
  221. package/dist/core/tasks/task-completion-entry.impl.js +3 -3
  222. package/dist/core/tasks/task-completion-entry.js +3 -3
  223. package/dist/core/tasks/task-file-history.code.js +3 -3
  224. package/dist/core/tasks/task-file-history.impl.js +3 -3
  225. package/dist/core/tasks/task-file-history.js +3 -3
  226. package/dist/core/tasks/task-reference-archive.code.js +4 -4
  227. package/dist/core/tasks/task-reference-archive.js +3 -3
  228. package/dist/core/tasks/task-reference-identity.code.js +1 -1
  229. package/dist/core/tasks/task-reference-identity.js +3 -3
  230. package/dist/core/tasks/task-reference-stream.impl.js +3 -3
  231. package/dist/core/tasks/task-reference-stream.js +3 -3
  232. package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
  233. package/dist/core/tasks/task-unsaved-answer.js +3 -3
  234. package/dist/core/tasks/task-view-source.impl.js +3 -3
  235. package/dist/core/tasks/task-view-source.js +3 -3
  236. package/dist/core/tools/read-url.code.js +2 -2
  237. package/dist/core/tools/read-url.impl.js +3 -3
  238. package/dist/core/tools/read-url.js +3 -3
  239. package/dist/core/worktree-snapshot/blob-store.js +2 -2
  240. package/dist/core/worktree-snapshot/errors.code.js +3 -3
  241. package/dist/core/worktree-snapshot/errors.impl.js +3 -3
  242. package/dist/core/worktree-snapshot/errors.js +3 -3
  243. package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
  244. package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
  245. package/dist/extensions/codemode/execute.code.js +1 -1
  246. package/dist/extensions/codemode/execute.impl.js +3 -3
  247. package/dist/extensions/codemode/execute.js +3 -3
  248. package/dist/extensions/codemode/renderer.code.js +2 -2
  249. package/dist/extensions/codemode/renderer.impl.js +3 -3
  250. package/dist/extensions/codemode/renderer.js +3 -3
  251. package/dist/extensions/mcp/cli.code.js +2 -2
  252. package/dist/extensions/mcp/cli.impl.js +3 -3
  253. package/dist/extensions/mcp/cli.js +3 -3
  254. package/dist/extensions/mcp/cli.lazy.code.js +2 -2
  255. package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
  256. package/dist/extensions/mcp/cli.lazy.js +3 -3
  257. package/dist/extensions/mcp/runtime.code.js +1 -1
  258. package/dist/extensions/mcp/runtime.impl.js +3 -3
  259. package/dist/extensions/mcp/runtime.js +3 -3
  260. package/dist/index-extensions.d.ts +1 -1
  261. package/dist/index.d.ts +8 -1
  262. package/dist/index.js +7 -7
  263. package/dist/main-first-time-setup.code.js +2 -2
  264. package/dist/main-first-time-setup.impl.js +3 -3
  265. package/dist/main-first-time-setup.js +3 -3
  266. package/dist/modes/interactive/components/settings-selector-types.d.ts +1 -0
  267. package/dist/modes/interactive/components/settings-selector-types.js.map +1 -1
  268. package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
  269. package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
  270. package/dist/modes/interactive/components/stored-tree-view.js +3 -3
  271. package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
  272. package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
  273. package/dist/modes/interactive/theme/color-utils.d.ts +5 -5
  274. package/dist/modes/interactive/theme/theme-loading.d.ts +1 -0
  275. package/dist/modes/interactive-engine/engine-prewarm.js +1 -1
  276. package/dist/modes/interactive-engine/remote-model-catalog.d.ts +1 -0
  277. package/dist/modes/print-mode.js +1 -1
  278. package/dist/modes/rpc/rpc-client-api.d.ts +6 -0
  279. package/dist/modes/rpc/rpc-types.d.ts +29 -2
  280. package/dist/package-manager-cli.code.js +5 -5
  281. package/dist/package-manager-cli.impl.js +3 -3
  282. package/dist/package-manager-cli.js +3 -3
  283. package/dist/rpc-entry.js +1 -1
  284. package/dist/startup-files.json +1 -1
  285. package/dist/startup-stages/5.js +1 -1
  286. package/dist/startup-stages/7.js +1 -1
  287. package/dist/startup-stages/8.js +1 -2
  288. package/dist/startup-stages/9.js +2 -1
  289. package/dist/utils/native-module.d.ts +44 -0
  290. package/dist/utils/startup-database-spare.code.js +3 -3
  291. package/dist/utils/startup-database-spare.impl.js +3 -3
  292. package/dist/utils/startup-database-spare.js +3 -3
  293. package/dist/utils/tools-manager.code.js +1 -1
  294. package/dist/utils/tools-manager.impl.js +3 -3
  295. package/dist/utils/tools-manager.js +3 -3
  296. package/docs/background-tasks.md +238 -243
  297. package/docs/build.md +21 -15
  298. package/docs/changelog.mdx +1 -1
  299. package/docs/codemode.md +68 -51
  300. package/docs/compaction/reference.md +65 -26
  301. package/docs/compaction.md +118 -66
  302. package/docs/computer-use.md +179 -146
  303. package/docs/containerization.md +87 -33
  304. package/docs/custom-provider/api-reference.md +152 -13
  305. package/docs/custom-provider/oauth.md +45 -28
  306. package/docs/custom-provider/override.md +14 -7
  307. package/docs/custom-provider/registration.md +77 -67
  308. package/docs/custom-provider/streaming.md +42 -19
  309. package/docs/custom-provider.md +26 -62
  310. package/docs/development.md +81 -42
  311. package/docs/docs.json +54 -38
  312. package/docs/environment-variables.md +92 -64
  313. package/docs/extensions/api-reference.md +326 -735
  314. package/docs/extensions/authoring.md +186 -269
  315. package/docs/extensions/events.md +308 -375
  316. package/docs/extensions/examples.md +122 -74
  317. package/docs/extensions/ui.md +217 -197
  318. package/docs/extensions.md +189 -259
  319. package/docs/getting-started/authentication.md +27 -14
  320. package/docs/getting-started/first-session.md +25 -26
  321. package/docs/getting-started/installation.md +62 -84
  322. package/docs/getting-started/project-instructions.md +39 -14
  323. package/docs/guides/configuration.md +62 -20
  324. package/docs/guides/intercom.md +20 -12
  325. package/docs/guides/non-interactive.md +31 -16
  326. package/docs/guides/orchestration.md +17 -9
  327. package/docs/guides/resume-on-any-machine.md +63 -52
  328. package/docs/guides/subagents.md +26 -14
  329. package/docs/guides/team-setup.md +49 -27
  330. package/docs/guides.md +30 -23
  331. package/docs/herdr.md +22 -17
  332. package/docs/index.md +24 -17
  333. package/docs/intercom/operations.md +90 -66
  334. package/docs/intercom/reference.md +219 -192
  335. package/docs/intercom.md +111 -92
  336. package/docs/json.md +73 -71
  337. package/docs/keybindings.md +74 -48
  338. package/docs/libraries/agent-core.md +52 -9
  339. package/docs/libraries/ai.md +90 -63
  340. package/docs/libraries/codemode.md +31 -8
  341. package/docs/libraries/schema.md +12 -9
  342. package/docs/libraries/storage-libsql.md +92 -0
  343. package/docs/libraries/storage-postgres.md +119 -0
  344. package/docs/libraries/telemetry.md +42 -9
  345. package/docs/libraries/tui.md +74 -94
  346. package/docs/libraries.md +25 -8
  347. package/docs/llama-cpp.md +38 -33
  348. package/docs/mcp-servers.md +140 -88
  349. package/docs/models/reference.md +53 -36
  350. package/docs/models-configuration.md +19 -13
  351. package/docs/models.md +102 -87
  352. package/docs/orchestration/migrating-workflows.md +22 -20
  353. package/docs/orchestration/patterns.md +36 -21
  354. package/docs/orchestration.md +24 -21
  355. package/docs/packages/authoring.md +29 -18
  356. package/docs/packages/reference.md +77 -16
  357. package/docs/packages.md +34 -34
  358. package/docs/programmatic.md +28 -21
  359. package/docs/prompt-templates.md +65 -41
  360. package/docs/providers/reference.md +36 -20
  361. package/docs/providers.md +78 -76
  362. package/docs/quickstart.md +42 -54
  363. package/docs/reference/cli.md +256 -254
  364. package/docs/reference.md +30 -23
  365. package/docs/rpc/examples.md +121 -17
  366. package/docs/rpc/extension-ui.md +86 -63
  367. package/docs/rpc/protocol.md +817 -358
  368. package/docs/rpc.md +78 -152
  369. package/docs/sdk/reference.md +309 -73
  370. package/docs/sdk/storage.md +614 -0
  371. package/docs/sdk/structured-decisions.md +168 -65
  372. package/docs/sdk/web-server.md +80 -46
  373. package/docs/sdk.md +168 -215
  374. package/docs/security.md +117 -44
  375. package/docs/session-format.md +127 -76
  376. package/docs/sessions.md +155 -113
  377. package/docs/settings.md +293 -205
  378. package/docs/shell-aliases.md +15 -6
  379. package/docs/skills/authoring.md +17 -9
  380. package/docs/skills/reference.md +23 -21
  381. package/docs/skills.md +148 -97
  382. package/docs/storage.md +172 -260
  383. package/docs/subagents/authoring.md +148 -15
  384. package/docs/subagents/reference.md +105 -29
  385. package/docs/subagents.md +247 -250
  386. package/docs/terminal-setup.md +97 -69
  387. package/docs/termux.md +51 -85
  388. package/docs/themes/reference.md +51 -37
  389. package/docs/themes.md +52 -55
  390. package/docs/tmux.md +38 -21
  391. package/docs/tools.md +209 -147
  392. package/docs/tui/reference.md +64 -32
  393. package/docs/tui.md +38 -66
  394. package/docs/usage.md +94 -86
  395. package/docs/verification.md +25 -25
  396. package/docs/web-access.md +106 -54
  397. package/docs/windows.md +55 -57
  398. package/docs/worktree-snapshots.md +82 -74
  399. package/examples/sdk/11-sessions.ts +4 -4
  400. package/package.json +8 -8
  401. package/schemas/models.schema.json +58 -7
  402. package/dist/_shared/sdk-OSBEPR3Q.js.map +0 -1
  403. package/dist/_shared/startup-0-0-TYUFUOJZ.js.map +0 -1
  404. package/dist/_shared/startup-0-1-W2G2UY7R.js.map +0 -1
  405. package/dist/_shared/startup-0-2-UXBUEOXW.js.map +0 -1
  406. package/dist/_shared/startup-0-4-HN5EB4K7.js.map +0 -1
package/docs/build.md CHANGED
@@ -1,10 +1,9 @@
1
1
  ---
2
- title: Build with Atomic
3
- description: Extend Atomic with skills, subagents, Intercom, codemode, extensions, prompt templates, themes, packages, custom models and providers, and programmatic integrations.
2
+ title: "Build with Atomic"
3
+ sidebarTitle: "Overview"
4
+ description: "Choose how to customize an Atomic session, extend it with TypeScript or MCP, or embed it in your own software."
4
5
  ---
5
6
 
6
- # Build with Atomic
7
-
8
7
  Customize an Atomic session or embed it in your own software. Choose a starting point below.
9
8
 
10
9
  New to Atomic? Start with the [Quickstart](/quickstart). To look up an exact contract, use the [Reference index](/reference).
@@ -15,27 +14,34 @@ Work down this list and stop at the first mechanism that solves your problem.
15
14
 
16
15
  1. [Prompt templates](/prompt-templates). Expand reusable Markdown prompts from a slash command without writing code.
17
16
  2. [Skills](/skills). Provide on-demand instructions and optional scripts that the agent loads when a task matches.
18
- 3. [Subagents](/subagents). Delegate a focused, bounded task to a child agent.
19
- 4. [Intercom](/intercom). Coordinate sessions on the same machine or across machines sharing a database.
20
- 5. [Orchestration](/orchestration). Use codemode to launch children, check results, and pick up after an interruption.
21
- 6. [Extensions](/extensions). Write TypeScript that adds tools, commands, events, and custom UI when nothing lighter fits.
22
- 7. [Atomic packages](/packages). Bundle and distribute your extensions, skills, prompt templates, themes, subagents, MCP servers, or storage adapters.
17
+ 3. [MCP servers](/mcp-servers). Connect external tools and data sources over Model Context Protocol without writing an extension.
18
+ 4. [Subagents](/subagents). Delegate a focused, bounded task to a child agent.
19
+ 5. [Intercom](/intercom). Coordinate sessions on the same machine or across machines sharing a database.
20
+ 6. [Orchestration](/orchestration). Use codemode to launch children, check results, and pick up after an interruption.
21
+ 7. [Environment blueprints](/guides/resume-on-any-machine#set-the-environment-up-with-a-blueprint). Define `.atomic/blueprint.yaml` so restored worktrees rebuild dependencies and caches automatically on any machine or CI runner.
22
+ 8. [Extensions](/extensions). Write TypeScript that adds tools, commands, events, and custom UI when nothing lighter fits.
23
+ 9. [Atomic packages](/packages). Bundle and distribute your extensions, skills, prompt templates, themes, subagents, MCP servers, or [storage adapters](/storage#adapters-from-atomic-packages).
23
24
 
24
25
  ## Change the model layer
25
26
 
26
27
  - [Custom models](/models). Add model entries for a supported provider API.
27
- - [Custom providers](/custom-provider). Implement a provider API or OAuth flow that Atomic does not ship.
28
+ - [Remote compaction models](/models#remote-compaction-models). Configure custom `type: "compactor"` endpoints or override `morph/morph-compactor` parameters (see [Compaction](/compaction#customize-morph-or-add-a-remote-compactor)).
29
+ - [Custom providers](/custom-provider). Implement a provider API, classifier, remote compactor, or OAuth flow that Atomic does not ship.
28
30
 
29
- ## Customization
31
+ ## Customize appearance and controls
30
32
 
31
- Use [Themes](/themes) to restyle the terminal with a built-in or custom theme.
33
+ - [Themes](/themes). Restyle the terminal with a built-in or custom JSON theme.
34
+ - [Keybindings](/keybindings). Rebind interactive shortcuts and navigation keys.
32
35
 
33
36
  ## Embed Atomic in your own software
34
37
 
35
- [Programmatic use](/programmatic) compares JSON mode, RPC, and the SDK, and links each one to its protocol or API reference.
38
+ [Programmatic modes](/programmatic) compares JSON mode, RPC, and the SDK, and links each one to its protocol or API reference.
36
39
 
37
- - [SDK](/sdk). Embed Atomic in Node.js applications.
40
+ - [TypeScript SDK](/sdk). Embed Atomic in Node.js applications.
41
+ - [SDK storage backends](/sdk/storage). Wire local SQLite, JSONL, in-memory, libSQL/Turso, or PostgreSQL into `createAgentSession()` and `createAgentSessionRuntime()`.
42
+ - [Structured decisions](/sdk/structured-decisions). Run typed classifier or chat decisions with `decide()` and `generateStructuredOutput()`.
43
+ - [Web server guide](/sdk/web-server). Stream agent runs from an HTTP server or Next.js App Router endpoint.
38
44
  - [RPC mode](/rpc). Integrate over stdin and stdout JSONL.
39
45
  - [JSON event stream mode](/json). Run print mode with structured events.
40
46
  - [TUI components](/tui). Build custom terminal UI for extensions.
41
- - [Libraries](/libraries). Use Atomic's AI, TUI, agent core, codemode, schema, and telemetry packages directly.
47
+ - [Standalone libraries](/libraries). Use Atomic's six core packages (`ai`, `tui`, `agent-core`, `codemode`, `schema`, `telemetry`) and optional storage adapters ([`@bastani/atomic-storage-postgres`](/libraries/storage-postgres) and [`@bastani/atomic-storage-libsql`](/libraries/storage-libsql)) directly.
@@ -8,7 +8,7 @@ description: "What's new in Atomic"
8
8
  ## Pi 0.83.0 parity
9
9
 
10
10
  - **One door prints a stored credential.** `atomic auth print-api-key --model <model>` and `atomic auth print-bearer-token --model <model>` hand a configured credential to an external client. The credential is all that reaches stdout — warnings, provider selection, refresh notices, and help go to stderr — `--model` is required, and each failure has its own exit code, with stdout empty on every non-zero exit. `--min-expiry` accepts `ms`, `s`, `m`, or `h`, defaults to `30m`, and is a usage error on `print-api-key`, which has no expiry to wait for. See [Usage](/reference/cli#credential-commands) and [Security](/security#credential-export).
11
- - **Extensions can read the session's model scope.** `ctx.scopedModels` reports the models scoped to the current session — the set `/scoped-models` shows — resolved at access time and correct under the isolated engine. It reports the scope and cannot widen it: the accessor is read-only, and every read hands back a frozen copy of the array, its entries, and their models, so neither pushing an entry nor swapping one in place reaches the session. `ScopedModel` and `ExtensionScopedModels` are exported so an extension can name what it read. See [Extensions](/extensions/api-reference#ctx-modelregistry-/-ctx-model-/-ctx-scopedmodels).
11
+ - **Extensions can read the session's model scope.** `ctx.scopedModels` reports the models scoped to the current session — the set `/scoped-models` shows — resolved at access time and correct under the isolated engine. It reports the scope and cannot widen it: the accessor is read-only, and every read hands back a frozen copy of the array, its entries, and their models, so neither pushing an entry nor swapping one in place reaches the session. `ScopedModel` and `ExtensionScopedModels` are exported so an extension can name what it read. See [Extensions](/extensions/api-reference#ctx-modelregistry-ctx-model-ctx-scopedmodels).
12
12
  - **An unrecognised stop reason is now an error.** A provider that ends a turn with a terminal reason the mapping does not know surfaces a provider error naming the raw value instead of an ordinary successful stop, so a new truncation or safety signal is visible rather than silent. Streaming partials carry the new `pending` reason until the terminal event replaces it; a stream that ends still `pending` is an error. See [Providers](/providers/reference#stop-reasons) and [Custom Providers](/custom-provider/streaming#stop-reasons).
13
13
  - **OAuth tokens refresh before they expire.** A stored token with under five minutes of validity left is refreshed rather than used, so a long turn does not start on a credential that dies mid-request. The refresh runs under the `auth.json` lock and re-checks expiry inside it, so concurrent sessions sharing one credential file refresh it once between them. See [Providers](/providers#token-refresh).
14
14
  - **Remote OpenRouter logins have a way through.** When the browser cannot reach the loopback callback — over SSH, or on a headless host — the OpenRouter login accepts the final redirect URL, or the authorization code alone, pasted into the prompt. See [Providers](/providers#subscriptions).
package/docs/codemode.md CHANGED
@@ -1,84 +1,95 @@
1
1
  ---
2
- title: "Codemode"
3
- description: "The codemode script reference: globals, tool calls, stored values, classifier and image models, and limits."
2
+ title: "Codemode reference"
3
+ sidebarTitle: "Codemode"
4
+ description: "Write JavaScript scripts inside Atomic's sandbox to compose tool calls, persist state across turns, and call classifier or image models."
4
5
  ---
5
6
 
6
- # Codemode
7
-
8
- `codemode` lets the model run a JavaScript script that calls Atomic tools and non-LLM models (classifiers and image generators) and returns only the filtered result. It is enabled by default; see [`codemode` in Built-in tools](/tools#codemode) to toggle it. To embed the sandbox in your own app, see [`@bastani/atomic-codemode`](/libraries/codemode).
7
+ `codemode` lets the model run a JavaScript script that calls Atomic tools and non-LLM models (classifiers and image generators) and returns only the filtered result. It is enabled by default. Toggle it from the CLI or settings ([`codemode` in Built-in tools](/tools#codemode)), or from the SDK with `tools: ["-codemode"]`, `noTools: "builtin"`, or `DefaultResourceLoader({ disabledBuiltinExtensions: ["codemode"] })` ([SDK extensions](/sdk/reference#extensions)). For multi-step subagent workflows in codemode, see [Orchestrate with codemode and subagents](/orchestration). To embed the sandbox in your own application, see [`@bastani/atomic-codemode`](/libraries/codemode).
9
8
 
10
9
  ## Scripts
11
10
 
12
- Pass raw JavaScript source (no JSON wrapper or markdown code fences). Code runs as an async function body inside a QuickJS sandbox, so top-level `await` and `return` work. The sandbox has no Node APIs, filesystem, network, or timers; external access goes exclusively through `tools` and `models`.
11
+ Pass raw JavaScript source with no JSON wrapper or markdown code fences. Code runs as an async function body inside a sandboxed JavaScript runtime, so top-level `await` and `return` work. The sandbox has no Node or Bun APIs, filesystem, network, or timers; all external access goes through `tools` and `models`.
12
+
13
+ ```javascript
14
+ const [readme, pkg] = await Promise.all([
15
+ tools.read({ path: "README.md:1-40" }),
16
+ tools.read({ path: "package.json" }),
17
+ ]);
18
+ return { name: JSON.parse(pkg).name, excerpt: readme.slice(0, 400) };
19
+ ```
13
20
 
14
- Optional first-line directives configure output budget and timeout (must be line 1 or the call fails):
21
+ An optional first-line directive sets the output budget and timeout. It must be line 1 followed by JavaScript code; unknown keys or a script with no code after the directive fail immediately:
15
22
 
16
- ```js
23
+ ```javascript
17
24
  // @options: {"max_output_tokens": 2000, "timeout_ms": 60000}
18
25
  ```
19
26
 
20
- - **`max_output_tokens` (default `10000`).** Caps returned text. Overflow keeps the start and end and writes full output to a temp file whose path is included.
21
- - **`timeout_ms` (unset by default).** Hard deadline for the whole script, including waiting for a worker slot. Avoid short deadlines when generating images, which can take minutes.
27
+ - **`max_output_tokens` (default `10000`).** Non-negative safe integer (`0` is accepted; budget is `max_output_tokens * 4` characters). Overflow keeps the start and end and writes full output to a temp file whose path is included in the result.
28
+ - **`timeout_ms` (unset by default).** Hard deadline in milliseconds for the whole script, including waiting for a worker slot. Must be a positive integer up to `2147483647` (about 24.8 days); `0`, negative numbers, decimals, or larger values fail before running. Avoid short deadlines when generating images, which can take minutes.
22
29
 
23
30
  **Result format.** Starts with `Script completed` or `Script failed` plus wall time, followed by text and image items in order. Multiple text items (from `text()` or `return`) are separated by `==> text N/M <==`. `console.*` output follows in one `<console_output>` block. On failure, partial output is kept before `Script error:`. Side effects from completed tool calls are **not** rolled back; still-running calls are cancelled and unawaited promises are dropped when the script exits.
24
31
 
25
32
  ## Globals
26
33
 
27
- | Global | Purpose |
28
- | --- | --- |
29
- | `tools.<name>(args)` | Call a permitted tool. See [Call tools](#call-tools). |
30
- | `text(value)` | Emit a text item (strings verbatim, other values as JSON). |
31
- | `image(value)` | Emit an image from a base64 `data:` URL, `{ image_url }`, or `{ type: "image", data, mimeType }` (PNG, JPEG, GIF, WebP; no remote URLs or SVG; see [Generate images](#generate-images)). Also saves to a temp file and prints its path. |
32
- | `console.log(...)` | Append a space-joined line to `<console_output>` (`info`, `warn`, `error`, and `debug` behave identically). |
33
- | `return value` | Top-level `return` emits `value` like `text()`. |
34
- | `exit()` | End the script immediately with success. |
35
- | `store(key, value)` / `load(key)` | Persist small JSON values across `codemode` calls on this branch. See [Store values](#store-values). |
36
- | `ALL_TOOLS` | Array of `{ name, description }` for every script-callable tool (excludes [model-only tools](#model-only-tools)). |
37
- | `searchTools(query, { limit?, namespace? })` | BM25 search over script-callable tools (default `limit: 8`). Exact tool names or suffixes after `__` (such as `thread_read` for `mcp__app__thread_read`) rank first. An exact active model-only tool name returns a hint to call it directly. |
38
- | `describeTool(name)` | Returns a script-callable tool's description and TypeScript declaration, a direct-call hint for an active model-only tool, or `undefined`. |
39
- | `describeNamespace(name)` | Returns `{ name, description?, instructions?, tools }` for a namespace (such as an MCP server), or `undefined`. |
40
- | `models` | Inspect and invoke classifier and image models. See [Models](#models). |
34
+ Use `await` with every async global (`tools.*`, `searchTools()`, `describeTool()`, `describeNamespace()`, and `models.*`). Output, store, and exit helpers are synchronous.
35
+
36
+ | Global | Sync / Async | Purpose |
37
+ | --- | --- | --- |
38
+ | `tools.<name>(args)` | Async (`await`) | Call a permitted tool. See [Call tools](#call-tools). |
39
+ | `text(value)` | Sync | Emit a text item (strings verbatim, other values as JSON). |
40
+ | `image(value)` | Sync | Emit an image from a base64 `data:` URL, `{ image_url }`, or `{ type: "image", data, mimeType }` (PNG, JPEG except JPEG-LS, GIF, or WebP; no remote URLs or SVG; see [Generate images](#generate-images)). Inspects base64 magic bytes instead of trusting the declared MIME type, strips whitespace and newlines, throws `TypeError` on invalid or mismatched base64, saves a temp file, and prints its path. |
41
+ | `console.log(...)` | Sync | Append a space-joined line to `<console_output>` (`info`, `warn`, `error`, and `debug` behave identically). |
42
+ | `return value` | Sync | Top-level `return` emits `value` like `text()`. |
43
+ | `exit()` | Sync | End the script immediately with success. Persists prior `store()` writes, takes no argument (call `text()` first to emit output), and ignores further `text()` or `image()` calls inside `finally` blocks. |
44
+ | `store(key, value)` / `load(key)` | Sync | Persist small JSON values across `codemode` calls on this branch. See [Store values](#store-values). |
45
+ | `ALL_TOOLS` | Value | Array of `{ name, description }` for every script-callable tool (excludes [model-only tools](#model-only-tools)). |
46
+ | `searchTools(query, { limit?, namespace? })` | Async (`await`) | BM25 search over script-callable tools (`limit` must be a positive integer, default `8`). Exact tool names or suffixes after `__` (such as `thread_read` for `mcp__app__thread_read`) rank first. Querying an exact active model-only tool name returns a hint to call it directly unless `namespace` is passed. |
47
+ | `describeTool(name)` | Async (`await`) | Returns a script-callable tool's description and TypeScript declaration, a direct-call hint for an active model-only tool, or `undefined`. Accepts exact names, JS identifiers, `mcp.<server>.<tool>`, `mcp__<raw-server>__<tool>`, `<server>__<tool>`, or `<tool>` suffixes, and throws an ambiguity error if a shorthand matches multiple tools. |
48
+ | `describeNamespace(name)` | Async (`await`) | Returns `{ name, description?, instructions?, tools }` for a namespace (such as an MCP server), or `undefined`. |
49
+ | `models` | Async methods (`await`) | Inspect and invoke classifier and image models. See [Models](#models). Not exposed in routing-only subagents. |
41
50
 
42
51
  ## Call tools
43
52
 
44
- Every script-callable tool is exposed on `tools` with non-identifier characters converted to `_` (for example `mcp__dev-docs__search` becomes `tools.mcp__dev_docs__search`). Each method accepts one argument object.
53
+ Every script-callable tool is exposed on `tools` under both its normalized JavaScript identifier (non-identifier characters replaced with `_`, such as `tools.mcp__dev_docs__search`) and its raw tool name (`tools["mcp__dev-docs__search"]`). If two tool names normalize to the same identifier, the first registered tool keeps the normalized key. Each method accepts one argument object.
45
54
 
46
55
  **Return values:**
47
- - **Tools with `outputSchema`.** Resolve to their structured object (including structured failures). `bash` resolves to `{ output, truncated, full_output_path?, exit_code, wall_time_seconds }` even for nonzero exit codes; `output` keeps up to 1 MiB (first and last 512 KiB around an omission marker if truncated, with full text in `full_output_path`).
48
- - **MCP tools.** Resolve to `CallToolResult` (`content`, `isError`, and typed `structuredContent`).
49
- - **`read`.** Resolves to text (including path headers and line numbers unless `:raw`), or for images to `{ type: "image", data, mimeType, note }` usable directly with `image()`.
56
+ - **Tools with `outputSchema`.** Resolve to their structured object (including structured failures). `bash` resolves to `{ output, truncated, full_output_path?, exit_code, wall_time_seconds }` even for nonzero exit codes; `output` keeps up to 1 MiB (the first and last 512 KiB around an omission marker if truncated, with full text in `full_output_path`).
57
+ - **MCP tools.** Resolve to `CallToolResult` (`content`, `isError`, and typed `structuredContent`, with `_meta` stripped).
58
+ - **`read`.** Resolves to plain LF text with `[Lines S-E of N]` range headers on partial reads (no per-line numbers or local path headers; URL reads include `URL:`, `Status:`, and `Content-Type:` headers; append `:raw` for exact bytes). For images, resolves to `{ type: "image", data, mimeType, note }` usable directly with `image()`.
50
59
  - **Other tools (`edit`, `write`, and similar).** Resolve to text.
51
60
 
52
61
  **Errors and discovery:**
53
62
  - Failed, blocked, or invalid calls reject with `Error` (except schema-backed tools that return a structured error value; check `exit_code` or `isError`). Use `Promise.allSettled()` for independent calls.
54
63
  - Accessing an unknown tool throws with close-match suggestions (for example `tools.Bash` suggests `tools.bash`). Check availability with `"name" in tools`.
55
- - Inline tool declarations share a `3000`-token budget (`codemode.inlineBudget` in [settings](/settings#tools)); deferred tools stay unlisted and are found via `searchTools()`, `describeTool()`, `describeNamespace()`, or `ALL_TOOLS`.
64
+ - Inline tool declarations share a `3000`-token budget (`codemode.inlineBudget` in [settings](/settings#tools)); deferred tools stay unlisted and are found via `await searchTools()`, `await describeTool()`, `await describeNamespace()`, or `ALL_TOOLS`.
56
65
  - `codemode.mode` in [settings](/settings#tools) controls tool visibility: `"on"` (default) keeps direct tools declared alongside codemode; `"only"` hides ordinary direct tools so the model calls them through codemode while keeping active model-only tools (like `ask_user_question`) top-level. Declarations in `codemode`, `describeTool()`, and `ALL_TOOLS` carry each tool's prompt guidelines.
57
66
 
58
67
  ### Model-only tools
59
68
 
60
- Tools without script access (such as `ask_user_question`) are absent from `tools`, `ALL_TOOLS`, and `searchTools()` rankings. Call them as top-level tools instead. Querying their exact name with `searchTools()` or `describeTool()` returns a hint to call them directly without making them script-callable.
69
+ Tools without script access (such as `ask_user_question` and `tool_search`) are absent from `tools`, `ALL_TOOLS`, and `searchTools()` rankings. Call them as top-level tools instead. Querying their exact name with `await searchTools()` or `await describeTool()` returns a hint to call them directly without making them script-callable.
61
70
 
62
71
  Two tools expose a script-safe subset:
63
- - **`tools.subagent`.** Launches children (`{ agent, task }` or `{ tasks }`) and returns task IDs at admission; also supports `status`, bounded `wait`, `pause`, `quit`, `resume`, and agent and model inspection. A script timeout cancels `wait`, not the child; admitted children continue after a script returns or throws. See [Subagents from codemode scripts](/subagents#from-codemode-scripts).
72
+ - **`tools.subagent`.** Launches subagents (`{ agent, task }` or `{ tasks }`) and returns task IDs at admission; also supports `status`, bounded `wait`, `pause`, `quit`, `resume`, and agent and model inspection. A script timeout cancels `wait`, not the subagent; admitted subagents continue after a script returns or throws. See [Subagents from codemode scripts](/subagents#from-codemode-scripts).
64
73
  - **`tools.intercom`.** Supports `list`, `status`, `pending`, and `send` to an exact target (returning structured results). Other actions and glob or `subagents:` targets must be called directly. See [Intercom from codemode scripts](/intercom/reference#from-codemode-scripts).
65
74
 
66
75
  ## Store values
67
76
 
68
- `store(key, value)` saves a JSON value for subsequent `codemode` calls; `store(key, undefined)` deletes it; `load(key)` reads it back (or `undefined`).
77
+ `store(key, value)` synchronously saves a JSON value for subsequent `codemode` calls; `store(key, undefined)` deletes it; `load(key)` synchronously reads it back (or returns `undefined`).
69
78
 
70
- - Persists only when the script succeeds by appending a `codemode-store` session entry, so values survive resume and stay isolated per session branch.
71
- - Size caps: 262,144 JSON characters per value, 1,048,576 characters total across all keys. Do not store images; emit them with `image()`, which writes a temp file automatically.
79
+ - Writes become visible to `load()` immediately inside the same script. They persist to the session history only when the script succeeds (including via `exit()`), so values survive resume and stay isolated per session branch. Failed scripts discard uncommitted writes.
80
+ - Keys must be strings. Non-JSON-serializable values (functions, BigInt, circular references) throw `TypeError`.
81
+ - Size caps are 262,144 JSON characters per value (`json.length`) and 1,048,576 characters total across all stored entries (`key.length + json.length`). Do not store images; emit them with `image()`, which writes a temp file automatically.
72
82
 
73
83
  ## Models
74
84
 
75
- `models` accesses the model catalog and calls non-LLM models using the session's credentials:
85
+ `models` accesses the model catalog and calls non-LLM models using the session's credentials. Routing-only subagents do not expose `models`.
86
+
76
87
  - **Classifiers.** Answer typed questions about JSON state (and images when supported). Examples: [TypeSafe Jev](/providers#typesafe-jev), [OpenAI GPT-6 Luna](/models#use-classifier-models), and [local llama.cpp models](/llama-cpp).
77
88
  - **Image models.** Generate or edit images. Examples: OpenRouter (`provider: "openrouter"`, IDs such as `google/gemini-2.5-flash-image` and `black-forest-labs/flux.2-pro`, reusing your OpenRouter credential) and OpenAI (`provider: "openai-images"`, such as `gpt-image-2.6-flare`, reusing your [OpenAI API key](/providers#subscription-and-api-key-at-the-same-time)).
78
89
 
79
- Chat models are listed in the catalog but cannot be called from scripts. Neither classifiers nor image models appear in `/model`.
90
+ Chat models are listed in the catalog (with active service-tier pricing) but cannot be called from scripts. Neither classifiers nor image models appear in `/model`.
80
91
 
81
- ```ts
92
+ ```typescript
82
93
  type ModelType = "chat" | "image" | "classifier";
83
94
 
84
95
  interface ModelInfo {
@@ -88,7 +99,10 @@ interface ModelInfo {
88
99
  name: string;
89
100
  api: string;
90
101
  input: ("text" | "image")[];
102
+ reasoning?: boolean;
91
103
  contextWindow?: number;
104
+ maxTokens?: number;
105
+ cost?: { input: number; output: number; cacheRead: number; cacheWrite: number };
92
106
  [key: string]: unknown;
93
107
  }
94
108
 
@@ -107,7 +121,7 @@ declare const models: {
107
121
 
108
122
  ### Classify
109
123
 
110
- ```ts
124
+ ```typescript
111
125
  interface ClassifierContext {
112
126
  state: Record<string, unknown>;
113
127
  images?: { type: "image"; data: string; mimeType: string }[];
@@ -138,7 +152,7 @@ type ModelUsage = { input: number; output: number; totalTokens: number; cost: {
138
152
 
139
153
  Classify multiple items in parallel:
140
154
 
141
- ```js
155
+ ```javascript
142
156
  const jev = await models.getModelOfType("classifier", "typesafe", "jev-latest");
143
157
  const results = await Promise.all(
144
158
  messages.map((message) =>
@@ -166,9 +180,9 @@ return results.map((result, i) =>
166
180
  );
167
181
  ```
168
182
 
169
- When a classifier's `input` includes `"image"`, pass image blocks (such as those returned by `tools.read()`) in `images` (text-only models return an error result for non-empty `images`):
183
+ When a classifier's `input` includes `"image"`, pass image blocks (such as those returned by `tools.read()`) in `images`. Text-only models return an error result for non-empty `images`:
170
184
 
171
- ```js
185
+ ```javascript
172
186
  const luna = await models.getModelOfType("classifier", "openai-decisions", "gpt-6-luna");
173
187
  const photo = await tools.read({ path: "screenshot.png" });
174
188
  const result = await models.classify(luna, {
@@ -187,7 +201,7 @@ return result.stopReason === "stop" ? result.answers : result.errorMessage;
187
201
 
188
202
  ### Generate images
189
203
 
190
- ```ts
204
+ ```typescript
191
205
  interface ImagesContext {
192
206
  input: (TextBlock | ImageBlock)[];
193
207
  }
@@ -203,7 +217,7 @@ interface ImagesOptions {
203
217
  frameCount?: number;
204
218
  frameDurationMs?: number;
205
219
  complexity?: "low" | "medium" | "high";
206
- svg?: { model: string; reasoning?: { effort?: string } };
220
+ svg?: { model: string; reasoning?: { effort?: "none" | "minimal" | "low" | "medium" | "high" | "xhigh" | "max" } };
207
221
  moderation?: "auto" | "low";
208
222
  safetyIdentifier?: string;
209
223
  }
@@ -223,13 +237,14 @@ type TextBlock = { type: "text"; text: string };
223
237
  type ImageBlock = { type: "image"; data: string; mimeType: string; role?: "markup" | "mask" };
224
238
  ```
225
239
 
226
- - **Provider options.** `ImagesOptions` targets OpenAI's `openai-images` models (OpenRouter models ignore them). The first untagged image is the base image to edit; additional untagged images are references. `role: "markup"` is a same-size transparent PNG overlay; `role: "mask"` is an alpha mask (mutually exclusive).
227
- - **GIF and SVG.** `outputFormat: "gif"` (`frameCount` `2` to `16`, `frameDurationMs` `20` to `2000`) and `"svg"` require a GPT Image 2.6 model with text-only input.
240
+ - **Provider options.** `ImagesOptions` targets OpenAI's `openai-images` models (OpenRouter models ignore them). The first untagged image is the base image to edit; additional untagged images are references. `role: "markup"` (a same-size transparent PNG overlay) and `role: "mask"` (an alpha mask) are mutually exclusive and require an untagged base image earlier in `input`.
241
+ - **OpenAI option validation.** `outputCompression` accepts integers `0` to `100` and is valid only with `outputFormat: "jpeg"` or `"webp"`. `background: "transparent"` is valid only with `"png"`, `"webp"`, or the default format. `safetyIdentifier` has a 128-character limit. `complexity` (`"low"`, `"medium"`, or `"high"`, API default `"high"`) applies to GPT Image 2.6 only.
242
+ - **GIF and SVG.** `outputFormat: "gif"` and `"svg"` require a GPT Image 2.6 model with text-only input. For GIF, `frameCount` (`2` to `16`, API default `9`) and `frameDurationMs` (`20` to `2000`, API default `200`, rounded to 10 ms) are rejected unless `outputFormat` is `"gif"`. For SVG, `n` must be `1` or omitted, and the `svg` option is rejected unless `outputFormat` is `"svg"`.
228
243
  - **SVG authoring model.** `{ outputFormat: "svg" }` works without extra options. If an account requires `svg.model` and you omitted `svg`, Atomic retries once with `gpt-6.1-sol` (reported in `result.svgModel`), and retries once without `svg` if rejected as unsupported. An explicit `svg: { model, reasoning }` is sent verbatim without automatic fallback. Allow at least `timeout_ms: 180000` for SVG requests (Atomic's own request timeout is at least 10 minutes).
229
- - **Structured errors.** Invalid options fail locally with `stopReason: "error"`, `error.code: "invalid-option"`, and `error.fields.field` (plus `error.fields.reason`: `required-by-api`, `rejected-by-api`, or `unsupported-by-api` for SVG). Other codes: `moderation-blocked`, `user-error`, `quota-exceeded`, `rate-limited`, `server-error`, `timeout`, `api-error`. Branch on `error.code` and `error.retryable` (see [Image generation](/extensions/api-reference#ctx-modelregistry-/-ctx-model-/-ctx-scopedmodels)).
244
+ - **Structured errors.** Invalid options fail locally with `stopReason: "error"`, `error.code: "invalid-option"`, and `error.fields.field` (plus `error.fields.reason`: `required-by-api`, `rejected-by-api`, or `unsupported-by-api` for SVG). Other codes are `moderation-blocked`, `user-error`, `quota-exceeded`, `rate-limited`, `server-error`, `timeout`, and `api-error`. Branch on `error.code` and `error.retryable` (see [Image generation](/libraries/ai#image-generation)).
230
245
  - **Displaying and saving output.** Call `image(block)` for PNG, JPEG, GIF, and WebP (never print base64 `data` via `text()` or `return`; scripts that generate images without showing any receive a note). `image()` also saves each image to a private temp file and prints its path. For SVG (`image/svg+xml`), Atomic automatically saves a private temp `.svg` file (`[SVG saved to <path> (image/svg+xml, <size>)]`), and scripts can inspect XML text via `atob(block.data)`.
231
246
 
232
- ```js
247
+ ```javascript
233
248
  // @options: {"timeout_ms": 300000}
234
249
  const painter = await models.getModelOfType("image", "openrouter", "google/gemini-2.5-flash-image");
235
250
  const result = await models.generateImages(painter, {
@@ -244,7 +259,7 @@ for (const block of result.output) {
244
259
 
245
260
  SVG and animated GIF with GPT Image 2.6:
246
261
 
247
- ```js
262
+ ```javascript
248
263
  // @options: {"timeout_ms": 180000}
249
264
  const flare = await models.getModelOfType("image", "openai-images", "gpt-image-2.6-flare");
250
265
  const logo = await models.generateImages(flare, {
@@ -264,7 +279,9 @@ Extensions can call `ctx.modelRegistry.classify()` and `ctx.modelRegistry.genera
264
279
 
265
280
  ## Limits
266
281
 
267
- - **Memory.** 256 MiB per script VM (`InternalError: out of memory`); filter or aggregate data instead of buffering everything.
268
- - **Cancellation.** Stopping a script or hitting `timeout_ms` cancels the call promptly. In the standalone Bun binary, non-interruptible native built-ins (such as a long regex or string search) finish before the worker exits.
269
- - **Worker concurrency.** Default max `2` live workers per Atomic process (override with `ATOMIC_CODEMODE_MAX_WORKERS`). Cancelled workers occupy a slot until exit. Additional scripts queue in FIFO order and fail if no slot opens within 60 seconds (or `timeout_ms`).
282
+ - **Memory.** 256 MiB per script sandbox (`InternalError: out of memory`); filter or aggregate data instead of buffering everything in memory.
283
+ - **Hard output caps.** Across `text()`, `image()`, and `console.*`, a script can emit at most 16 MiB (`16,777,216` characters) total and `100,000` items. Exceeding either cap stops the script immediately with an uncatchable `RangeError`.
284
+ - **Frozen built-in prototypes.** Standard JavaScript globals and built-in prototypes are frozen before your script starts. Monkey-patching built-in prototypes throws `TypeError`; normal own properties on your own objects (`name`, `message`, `toString`, `toJSON`, and custom keys) work normally.
285
+ - **Cancellation.** Stopping a script or hitting `timeout_ms` cancels execution promptly. In the standalone binary release, a single long-running native built-in operation (such as a catastrophic regex) finishes before the worker exits.
286
+ - **Worker concurrency.** Default limit is `2` concurrent script workers per Atomic process (override with `ATOMIC_CODEMODE_MAX_WORKERS` or legacy `PI_CODEMODE_MAX_WORKERS`). Cancelled workers occupy a slot until they exit. Additional scripts queue in FIFO order and fail if no slot opens within 60 seconds (or `timeout_ms`).
270
287
  - **Deadlocks and nesting.** Waiting on a promise with no pending tool call fails immediately because there are no timers. Scripts cannot invoke `codemode` recursively.
@@ -1,34 +1,45 @@
1
1
  ---
2
- title: Compaction reference
3
- sidebarTitle: "Compaction internals"
4
- description: Compaction parameters, saved boundaries, extension hooks, exports, formats, and settings.
2
+ title: "Compaction reference"
3
+ sidebarTitle: "Compaction"
4
+ description: "Reference for compaction parameters, saved boundary fields, extension hooks, SDK concurrency, exports, branch summary format, and settings."
5
5
  ---
6
6
 
7
- # Compaction reference
8
-
9
7
  ## Parameters
10
8
 
11
9
  Extension events and compaction results carry one parameter:
12
10
 
13
11
  | Parameter | Default | Meaning |
14
12
  | --- | --- | --- |
15
- | `query` | Latest user request | Your `/compact` instructions when provided, otherwise the text of the latest user request. A compactor model receives it as its query. |
13
+ | `query` | Latest user request | Your `/compact` instructions when provided, otherwise the text of the latest user request (or `"the latest user request"` when no user message exists on the active branch). A compactor model receives it as its query. |
16
14
 
17
15
  Instructions passed to `/compact`, `session.compact({ query })`, `ctx.compact({ query })`, or RPC `compact` are also appended to the boundary message after the recovery steps. Automatic compaction passes no custom instructions.
18
16
 
19
- `compression_ratio` and `preserve_recent` are no longer compaction options and are ignored if supplied. The compactor ratio, request timeout, and output cap are fixed constants exported from `@bastani/atomic`:
17
+ `compression_ratio` and `preserve_recent` are not top-level `session.compact()` or `settings.json` compaction options and are ignored if supplied there, keeping default context-clearing compaction free of endpoint knobs. Configure API-specific parameters directly on each compactor model in [`models.json`](/models#remote-compaction-models) (`compactionParams`, `endpointPath`, `timeoutMs`, `maxTokens`, `headers`) or via [`atomic.registerProvider()`](/custom-provider/api-reference) (`ProviderCompactorModelConfig`). When `compactionParams` is omitted, Atomic does not inject provider-specific body fields so the remote API applies its own defaults.
20
18
 
21
- | Value | Export | Meaning |
22
- | --- | --- | --- |
23
- | `0.5` | `COMPACTOR_COMPRESSION_RATIO` | Share of the conversation the compactor is asked to keep |
24
- | `120000` | `COMPACTOR_REQUEST_TIMEOUT_MS` | Wall-clock limit on one compactor request, in milliseconds |
25
- | `32000` | `COMPACTED_OUTPUT_MAX_TOKENS` | Largest allowed compacted text in estimated tokens (or half of the automatic trigger budget on small context windows) |
19
+ Safety bounds used when a compactor model omits an override are exported from `@bastani/atomic`:
20
+
21
+ | Default | Export | Model override field | Meaning |
22
+ | --- | --- | --- | --- |
23
+ | `120000` | `COMPACTOR_REQUEST_TIMEOUT_MS` | `timeoutMs` | Wall-clock limit on one compactor request, in milliseconds |
24
+ | `32000` | `COMPACTED_OUTPUT_MAX_TOKENS` | `maxTokens` | Largest allowed compacted text in estimated tokens (always also capped at `COMPACTED_OUTPUT_MAX_TRIGGER_SHARE` = 50% of the automatic trigger budget) |
25
+ | `2000` | `COMPACTOR_LINE_WIDTH` | None | Character width at which long lines wrap before framing |
26
+
27
+ ### Compactor request contract
26
28
 
27
- Compaction resets Claude's signed reasoning chain, so `thinking` and `redacted_thinking` blocks do not survive a boundary. See [Preserved thinking and model switches](/models/reference#preserved-thinking-and-model-switches) for behavior between boundaries.
29
+ Each compactor provider defines its own `api` identifier and `baseUrl` (for example, built-in `morph/morph-compactor` defines `api: "morph-compact"` and `baseUrl: "https://api.morphllm.com/v1"`). Custom compactors in `models.json` or `atomic.registerProvider()` must declare `api` at the provider or model level unless overriding an existing compactor model.
30
+
31
+ Atomic POSTs JSON to `<baseUrl><endpointPath>` (`endpointPath` defaults to `"/compact"`; `""` POSTs directly to `baseUrl`):
32
+
33
+ - **Payload:** sends `{ ...compactionParams, messages, query, model }`. Atomic never injects hard-coded Morph parameters; any API-specific options come solely from the model's `compactionParams`.
34
+ - **Headers and authentication:** sends `Content-Type: application/json`, merges resolved provider and model `headers`, and adds `Authorization: Bearer <apiKey>` when `apiKey` is present and no explicit `Authorization` header was set. The API key and sensitive auth headers (`Authorization`, `Proxy-Authorization`, `X-API-Key`, `API-Key`) are redacted from HTTP error excerpts and compacted output.
35
+ - **Response parsing:** reads joined non-empty `messages[].content` entries when present, otherwise `output`, plus optional `usage.input_tokens` and `usage.output_tokens`.
36
+ - **Automatic fallback:** any failure (missing `baseUrl`, missing credentials, network/HTTP error, timeout, malformed/empty output, output exceeding `maxTokens` or 50% of the automatic trigger, boundary overflowing the trigger, or pressing `Escape` / `abortCompaction()`) falls back automatically to clearing the context (`form: "cleared"`) with `fallbackReason` set.
37
+
38
+ Long lines sent to a compactor wrap at 2,000 characters. Compaction resets Claude's signed reasoning chain, so `thinking` and `redacted_thinking` blocks do not survive a boundary. See [Preserved thinking and model switches](/models/reference#preserved-thinking-and-model-switches) for behavior between boundaries.
28
39
 
29
40
  ## Persistence and resume
30
41
 
31
- A successful compaction appends a `type: "compaction"` entry:
42
+ A successful compaction appends a `type: "compaction"` entry (see [`CompactionEntry`](/session-format#compactionentry)):
32
43
 
33
44
  ```json
34
45
  {
@@ -57,6 +68,8 @@ A successful compaction appends a `type: "compaction"` entry:
57
68
  | `tokensBefore` | Provider-aware whole-context token count before the boundary, used for budgeting and the chat boundary line |
58
69
  | `coveredThroughEntryId` | Written only by earlier versions while a tool call waited for its result; new boundaries are never written while a call waits |
59
70
  | `usage` | Compactor endpoint usage when reported |
71
+ | `fromHook` | `true` when an extension supplied compacted text from `session_before_compact` |
72
+ | `systemMessage` | Optional replayed system prompt and tool state checkpoint at this boundary |
60
73
  | `details.form` | `"cleared"` (no model call) or `"compacted"` (compactor or extension supplied replacement text) |
61
74
  | `details.backend` | `"compactor"` or `"extension"`, present only on `"compacted"` boundaries |
62
75
  | `details.model` | Compactor ID as `provider/model` when a compactor produced the text |
@@ -64,7 +77,7 @@ A successful compaction appends a `type: "compaction"` entry:
64
77
  | `details.history` | Boundary location in `history://sessions/<sessionId>`: `rangeUnit: "entries"`, `entriesBefore`, `boundaryEntry`, and `totalEntries` |
65
78
  | `details.historyAccess` | `"read-search"` or `"session-history-tool"`. Resumed sessions receive `session_history` whenever `read` or `search` is absent from resumed tools |
66
79
  | `details.stats` | Heuristic estimates: `tokensAfter` counts the system prompt and boundary message, `linesBefore` counts replaced context lines, `linesKept` counts compacted lines (`0` on a clear), and `rangeCount` is `0` |
67
- | `details.backupPath` | Path to the pre-compaction backup when written |
80
+ | `details.backupPath` | Path to the pre-compaction backup (`<sessionFile>.<timestamp>.<label>.bak`, never auto-deleted). Populated only for JSONL stores, never SQLite, libSQL, PostgreSQL, or memory stores (see [Storage backends](/storage)). |
68
81
 
69
82
  Only `compaction` entries with `details.strategy: "verbatim-lines"` affect active context. Resuming uses the saved boundary text directly without another model request, and messages appended after the boundary stay ordinary messages. Inactive legacy formats do not reapply historical omissions, so content they previously hid may reappear on resume.
70
83
 
@@ -87,11 +100,11 @@ atomic.on("session_before_compact", async (event) => {
87
100
  });
88
101
  ```
89
102
 
90
- `preparation` is a deep-frozen clone. `preparation.region.lines` holds the entire active context since the last boundary serialized as role-tagged lines (`[User]: `, `[Assistant]: `, `[Assistant tool calls]: `, `[Tool result]: `), starting with any previous boundary text. `firstKeptEntryId` is `null`, `keptTailMessageCount` is `0`, and `parameters.query` holds the `/compact` instructions or latest user request.
103
+ `preparation` is a deep-frozen clone (attempting to mutate it throws a `TypeError`). `preparation.region.lines` holds the entire active context since the last boundary serialized as role-tagged lines (`[User]: `, `[Assistant]: `, `[Assistant tool calls]: `, `[Tool result]: `), starting with any previous boundary text. `firstKeptEntryId` is `null`, `keptTailMessageCount` is `0`, and `parameters.query` holds the `/compact` instructions or latest user request.
91
104
 
92
105
  Return `{ cancel: true }` to cancel compaction. Return `{ compactedText }` to write a `Context compacted` boundary offline without provider credentials; the model sees your text in a `<compacted-context>` block followed by recovery instructions.
93
106
 
94
- Empty or whitespace-only text counts as no replacement, so the configured compaction form runs normally. Replacement text exceeding the compactor output cap or automatic trigger budget is rejected and falls back to context clearing with fallback reason `extension failed: output too long (...)`.
107
+ Empty or whitespace-only text counts as no replacement, so the configured compaction form runs normally. If `compactedText` exceeds the compactor output cap or makes `systemPrompt + boundary >= trigger`, Atomic rejects it, falls back to clearing the context with `fallbackReason` starting with `extension failed: output too long`, and emits `session_compact` with `fromExtension: false`.
95
108
 
96
109
  ### `session_compact`
97
110
 
@@ -122,23 +135,52 @@ atomic.on("session_compact_failed", async (event) => {
122
135
 
123
136
  `errorMessage` is absent when cancelled. `fromExtension` marks failures after a `session_before_compact` handler supplied replacement text, and no boundary is saved. A compactor failure is not a compaction failure because Atomic falls back to clearing context and reports `fallbackReason` on `session_compact`.
124
137
 
138
+ ## SDK concurrency and message queuing
139
+
140
+ For `session.compact()` usage and return types, see [Compaction and tree navigation](/sdk#compaction-and-tree-navigation).
141
+
142
+ - **Shared manual runs.** Concurrent manual SDK `session.compact()` calls share one run and resolve to the same result. Calling `abortCompaction()` cancels the run for all waiters, or falls back to clearing context if a compactor request is already in flight.
143
+ - **Manual takeover.** A manual compaction request arriving during automatic compaction cancels the automatic work and its continuation, then runs once the active work settles (or follows the automatic boundary if it already committed).
144
+ - **Automatic continuations.** Automatic continuations, including output-cap continuations, belong to the original prompt. Both the `prompt()` promise and `agent_settled` finish only after the full continuation chain completes.
145
+ - **Waiting messages.** User messages arriving during compaction (from typed input, prompt templates, skills, SDK `prompt()`, RPC `prompt`, or extension `sendUserMessage()`) wait in arrival order until compaction ends, then run once. If an earlier waiting message has already started a turn, later messages without `streamingBehavior` or `deliverAs` queue behind it as steering.
146
+ - **Inspecting and clearing queued input.** Waiting messages appear in `getSteeringMessages()`, `getFollowUpMessages()`, and `queue_update` events, and `clearQueue()` returns them without sending them. Before the TUI runs an extension command during compaction, it hands already-typed messages to the session so messages sent by the command run after them.
147
+ - **Turn hooks.** SDK `prepareNextTurn` and `prepareNextTurnWithContext` callbacks receive the rebuilt context after mid-turn compaction. Returning `{ action: "end" }` from `finishTurn` keeps queued input pending until an explicit prompt or continuation, while mid-turn compaction resumes streaming automatically.
148
+
149
+ ## Compaction errors
150
+
151
+ `setCompactionModel()`, RPC `set_compaction_model`, session compaction calls, and direct `requestCompactorOutput()` calls throw subclasses of `CompactionError`. Branch on the class or `error.code`, not on the message string. Reading an invalid `compactionModel` or `compaction.reserveTokens` value from `settings.json` throws a plain `Error` instead of `CompactionConfigError`.
152
+
153
+ | Class | `code` | `retryable` | When |
154
+ | --- | --- | --- | --- |
155
+ | `CompactionConfigError` | `invalid-setting` | `false` | `setCompactionModel()` or RPC `set_compaction_model` receives a non-string, whitespace-padded string, or invalid `scope`/`persist` |
156
+ | `CompactionCancelledError` | `cancelled` | `false` | Compaction is cancelled via abort signal or `session_before_compact` returning `{ cancel: true }` |
157
+ | `CompactionStateError` | `nothing-to-compact`, `pending-tool-call`, `no-model-selected`, `snapshot-failed`, `boundary-not-built` | `false` | `session.compact()` cannot proceed in the current session state |
158
+ | `CompactorFailure` | `missing-base-url`, `missing-credentials`, `request-aborted`, `timeout`, `http-error`, `network-error`, `malformed-response`, `empty-output`, `compactor-failed` | `true` for `timeout`, `network-error`, and HTTP `408`/`429`/`5xx`; `false` otherwise | Direct `requestCompactorOutput()` fails (during `session.compact()`, Atomic catches `CompactorFailure` and falls back to clearing context) |
159
+
160
+ Every `CompactionError` carries `code`, `hint`, `retryable`, and `fields()`. Use `isCompactionError`, `isCompactionConfigError`, `isCompactionCancelledError`, `isCompactionStateError`, `isCompactorFailure`, `findCompactionError`, and `isRetryableCompactionError` to match errors across realms or cause chains. Use `serializeCompactionError`, `parseSerializedCompactionError`, and `rehydrateCompactionError` to preserve the typed class across worker or RPC boundaries (the RPC client rehydrates `compaction_error` responses automatically).
161
+
125
162
  ## Package exports
126
163
 
127
- `@bastani/atomic` exports these compaction helpers and types:
164
+ `@bastani/atomic` exports these compaction helpers, errors, and types:
128
165
 
129
166
  | Export | Use |
130
167
  | --- | --- |
168
+ | `CompactionError`, `CompactionConfigError`, `CompactionCancelledError`, `CompactionStateError`, `CompactorFailure` | Typed compaction error family, matching the SDK error convention (`code`, `hint`, `retryable`, `fields()`) |
169
+ | `isCompactionError`, `isCompactionConfigError`, `isCompactionCancelledError`, `isCompactionStateError`, `isCompactorFailure`, `findCompactionError`, `isRetryableCompactionError` | Type guards and cause-chain helpers for compaction errors |
170
+ | `serializeCompactionError`, `parseSerializedCompactionError`, `rehydrateCompactionError` | Cross-process serialization and rehydration for `CompactionError` |
131
171
  | `buildBoundaryText(input, totalEntries)` | Build the boundary message for a session, history location, and optional instructions or compacted text |
132
172
  | `buildCompactorMessages(messages, isBoundary)` | Frame active context messages in the format sent to a compactor |
133
- | `requestCompactorOutput(request)` | Send one `CompactorRequest` to a compactor endpoint; resolves `{ text, usage? }` or throws `CompactorFailure` |
173
+ | `requestCompactorOutput(request)` | Send one `CompactorRequest` to a compactor endpoint; resolves `{ text, usage? }` or throws `CompactorFailure` / `CompactionCancelledError` |
134
174
  | `resolveCompactionModel(configured, models)` | Resolve `compactionModel` to a `CompactionModelSelection` (`auto` with any fallback reason, or a compactor) |
175
+ | `classifyCompactionModel(configured, models)` | Classify a `compactionModel` string as `"auto"`, `"compactor"`, `"chat"`, `"classifier"`, or `"unknown"` |
176
+ | `compactedOutputTokenCap(triggerTokens, maxOutputTokens?)` | Compute the effective compacted output cap in estimated tokens |
135
177
  | `SESSION_HISTORY_TOOL_NAME` | `"session_history"`, the read-only history tool granted after clearing when `read` or `search` is absent |
136
178
 
137
- The types `CompactionForm`, `CompactionBackend`, `CompactionHistoryLocation`, `CompactionModelSelection`, `CompactorMessage`, `CompactorRequest`, and `BranchSummaryEntry` are exported alongside them.
179
+ The types `CompactorModel`, `CompactorApi`, `ProviderCompactorModelConfig`, `CompactionForm`, `CompactionBackend`, `CompactionHistoryLocation`, `CompactionModelKind`, `CompactionModelSelection`, `CompactorMessage`, `CompactorRequest`, `CompactionErrorCode`, `SerializedCompactionError`, and `BranchSummaryEntry` are exported alongside them.
138
180
 
139
181
  ## Branch summary format
140
182
 
141
- Branch summarization writes structured Markdown:
183
+ Built-in branch summarization prepends the preamble `"The user explored a different conversation branch before returning here.\nSummary of that exploration:\n\n"` and writes structured Markdown with these sections:
142
184
 
143
185
  ```markdown
144
186
  ## Goal
@@ -163,9 +205,6 @@ Branch summarization writes structured Markdown:
163
205
  ## Next Steps
164
206
  1. [What should happen next]
165
207
 
166
- ## Critical Context
167
- - [Data needed to continue]
168
-
169
208
  <read-files>
170
209
  path/to/file1.ts
171
210
  path/to/file2.ts
@@ -178,7 +217,7 @@ path/to/changed.ts
178
217
 
179
218
  ### `BranchSummaryEntry` structure
180
219
 
181
- `BranchSummaryEntry` is exported from `@bastani/atomic`. Default branch summarization stores cumulative file lists in `details`, while extensions can store custom metadata:
220
+ `BranchSummaryEntry` is exported from `@bastani/atomic` (see [`BranchSummaryEntry`](/session-format#branchsummaryentry)). Default branch summarization stores cumulative file lists in `details`, while extensions can store custom metadata:
182
221
 
183
222
  ```typescript
184
223
  interface BranchSummaryEntry<T = unknown> {
@@ -211,7 +250,7 @@ Branch-summary prompts serialize conversation messages with role labels so the m
211
250
  [Tool result]: Output from tool
212
251
  ```
213
252
 
214
- Thinking blocks are omitted. Tool results longer than 2,000 characters are truncated with a marker stating how many characters were removed.
253
+ Thinking blocks are omitted. Built-in branch summarization truncates every tool result to **500 characters** before serialization (with a marker stating how many characters were removed). Calling `serializeConversation()` directly on unshortened messages truncates tool results at 2,000 characters.
215
254
 
216
255
  ## Extension hooks for branch summarization
217
256