@bastani/atomic 0.10.14-alpha.1 → 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 +29 -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 +9 -0
  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
@@ -0,0 +1,161 @@
1
+ ---
2
+ title: "Use custom compaction models"
3
+ sidebarTitle: "Custom compaction models"
4
+ description: "Use built-in Morph or configure your own remote HTTP compactor model with custom parameters and automatic fallback to memory compaction."
5
+ ---
6
+
7
+ **Custom compaction models** are Atomic's second form of compaction. Instead of clearing the context window outright, Atomic sends the active context once to a dedicated remote compactor endpoint—either built-in `morph/morph-compactor` or a custom compactor you define in `models.json` or an extension—and places its response inside a `<compacted-context>` block.
8
+
9
+ Your full conversation still stays verbatim in session history, and the boundary includes the same history recovery instructions as [memory compaction](/compaction/memory-compaction) so the agent can pull back anything the compactor omitted.
10
+
11
+ <Warning>
12
+ A remote compactor receives your in-context conversation and uses its own provider credentials. Enable a remote compactor only if your policy permits sending session content to that provider.
13
+ </Warning>
14
+
15
+ ## Quick start: use built-in Morph
16
+
17
+ <Steps>
18
+ <Step title="Authenticate Morph">
19
+ Run `/login morph` inside Atomic, or export `MORPH_API_KEY` in your shell.
20
+ </Step>
21
+ <Step title="Select the compaction model">
22
+ Open `/settings`, select **Compaction model**, and pick `morph/morph-compactor`. The change applies immediately with no `/reload` or restart.
23
+ </Step>
24
+ </Steps>
25
+
26
+ ## How custom compactors work
27
+
28
+ When `compactionModel` names a registered compactor model, Atomic frames the current context window (previous compacted text first, followed by role-labelled user messages, assistant text, tool calls with arguments, tool results, shell commands with exit codes, and extension messages) and sends one HTTP `POST` request to that model's endpoint:
29
+
30
+ - **No forced request defaults.** Atomic sends `{ messages, query, model }` plus any optional keys you put in `compactionParams`. When `compactionParams` is omitted, Atomic adds no provider-specific fields so the remote API applies its own defaults.
31
+ - **No built-in output size limit.** Whatever the endpoint returns is kept as-is, however long it is. To ask the endpoint for shorter output, set its own parameter in `compactionParams` (for Morph, `compression_ratio`). To reject long output locally, set `maxTokens` on the compactor model: output exceeding that token estimate falls back to memory compaction. `maxTokens` has no default.
32
+ - **Oversized output does not loop.** If a compactor returns output that remains above the automatic threshold, nothing is rejected and Atomic does not re-compact before every tool call of the same turn. The next user turn compacts again before its first request. If the provider reports a context overflow, Atomic compacts and retries once; if the retry still overflows, the provider's error is shown.
33
+ - **Content filtering and redaction.** Images become omission markers, thinking blocks are omitted, role headers are wrapped in `<keepContext>` tags, and messages excluded from model context (such as `!!` shell commands and display-only extension messages) are not sent. If an endpoint echoes your API key or a sensitive auth header, Atomic replaces it with `[redacted]` before storing or displaying the output.
34
+
35
+ ## Select a compaction model {#select-a-compaction-model}
36
+
37
+ Open `/settings` and choose **Compaction model** to switch between **Automatic** ([memory compaction](/compaction/memory-compaction)) and any registered compactor model immediately, without `/reload` or restarting.
38
+
39
+ Both built-in `morph/morph-compactor` and custom remote compactors defined in `~/.atomic/agent/models.json` or an extension appear in this searchable picker automatically (authenticated models first; unauthenticated ones show `requires /login <provider>`). The selector updates project settings when a project override already exists, and global settings otherwise.
40
+
41
+ You can also set `compactionModel` directly in `~/.atomic/agent/settings.json` or a trusted project's `.atomic/settings.json`:
42
+
43
+ ```json
44
+ {
45
+ "compactionModel": "morph/morph-compactor"
46
+ }
47
+ ```
48
+
49
+ - `"auto"` (lowercase) or `""` selects [memory compaction](/compaction/memory-compaction).
50
+ - A registered compactor ID must match `provider/model` **case-sensitively** (leading and trailing whitespace is trimmed).
51
+ - Compactor models never appear in `/model` and never run as chat models. Changing `compactionModel` does not affect [branch summaries](/compaction/branch-summaries).
52
+
53
+ Compaction never calls chat models or classifiers. On startup, once extensions finish loading, and when you trust a project, Atomic resets any saved chat or classifier `compactionModel` to `"auto"`. Compactor IDs and unknown IDs remain untouched; an unknown ID falls back to memory compaction with a notice.
54
+
55
+ For programmatic per-run overrides, live SDK/RPC switching, and registering compactors from extensions, see [Compaction reference](/compaction/reference), [Compaction and tree navigation](/sdk#compaction-and-tree-navigation), and [Custom providers](/custom-provider/api-reference).
56
+
57
+ ## Configure Morph or add a custom compactor {#configure-morph-or-add-a-custom-compactor}
58
+
59
+ Keep `settings.json` free of endpoint knobs and configure API-specific parameters directly on the compactor model in `~/.atomic/agent/models.json` (see [Remote compaction models](/models#remote-compaction-models)).
60
+
61
+ ### Override built-in Morph parameters
62
+
63
+ ```json
64
+ {
65
+ "providers": {
66
+ "morph": {
67
+ "modelOverrides": {
68
+ "morph-compactor": {
69
+ "compactionParams": {
70
+ "compression_ratio": 0.35,
71
+ "preserve_recent": 2
72
+ },
73
+ "timeoutMs": 180000
74
+ }
75
+ }
76
+ }
77
+ }
78
+ }
79
+ ```
80
+
81
+ ### Add a custom remote compactor
82
+
83
+ ```json
84
+ {
85
+ "providers": {
86
+ "my-compactor": {
87
+ "baseUrl": "https://compact.example.com/v1",
88
+ "apiKey": "$MY_COMPACTOR_API_KEY",
89
+ "headers": {
90
+ "X-Team": "platform"
91
+ },
92
+ "models": [
93
+ {
94
+ "id": "compact-v2",
95
+ "name": "Internal Compactor v2",
96
+ "type": "compactor",
97
+ "api": "custom-compact",
98
+ "endpointPath": "/compress",
99
+ "compactionParams": {
100
+ "target_ratio": 0.4,
101
+ "preserve_recent": 2
102
+ },
103
+ "timeoutMs": 180000
104
+ }
105
+ ]
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ Key configuration fields:
112
+
113
+ - **`type: "compactor"`** registers the model as a compactor so it appears in `/settings` under **Compaction model** instead of `/model`.
114
+ - **`api`** is required on the provider or model for custom compactors (built-in Morph defines `"api": "morph-compact"`). Overriding an existing compactor under `modelOverrides` inherits its provider's `api` and `baseUrl`.
115
+ - **`compactionParams`** merges arbitrary API-specific keys into the JSON request body alongside `{ messages, query, model }`. Omit it to let the remote API apply its own server defaults.
116
+ - **`endpointPath`** appends to `baseUrl` and defaults to `"/compact"`. Set `"endpointPath": ""` to `POST` directly to `baseUrl`.
117
+ - **`timeoutMs`** overrides the default 120-second request timeout.
118
+ - **`maxTokens`** sets an optional estimated-token cap on the compactor's response (no default; longer output falls back to memory compaction).
119
+ - **`headers`** supports `$ENV`, `${ENV}`, and `!command` for custom auth headers (such as `"X-API-Key": "$MY_KEY"`). Sensitive auth headers are redacted automatically from errors and compacted output.
120
+
121
+ For the exact HTTP payload, header, token estimator, and response contract, see [Compactor request contract](/compaction/reference#compactor-request-contract).
122
+
123
+ ## Automatic fallback to memory compaction
124
+
125
+ Every compactor failure falls back automatically to **Automatic** ([memory compaction](/compaction/memory-compaction)) so a broken, unauthenticated, or slow remote endpoint never blocks a session:
126
+
127
+ ```text
128
+ Compaction starts
129
+ ├─ Cancelled by user or extension -> Cancelled (context unchanged)
130
+ ├─ Extension supplies replacement text -> Context compacted (extension)
131
+ ├─ Compaction model is "" / "auto" -> Memory compaction (Context cleared)
132
+ ├─ Compaction model is unknown / chat / classifier -> Automatic fallback (Context cleared)
133
+ └─ Compaction model is a registered compactor
134
+ ├─ success (within maxTokens, if you set one) -> Context compacted (compactor)
135
+ └─ missing auth / HTTP or network error / timeout / Esc /
136
+ malformed or empty output / longer than a maxTokens you set -> Automatic fallback (Context cleared)
137
+ ```
138
+
139
+ Atomic prints a one-line notice (`Compaction model not used (<reason>); context cleared instead`) without exposing your API key or sensitive headers. Pressing `Escape` while a compactor request is in flight also falls back to memory compaction with reason `request aborted`. Taking over with `/compact`, closing the session, or an extension cancelling compaction stops compaction completely.
140
+
141
+ ### Troubleshooting network and DNS errors
142
+
143
+ If Atomic cannot reach the compactor's server, the fallback notice names the underlying connection failure while falling back to memory compaction so your session keeps moving.
144
+
145
+ <Accordion title="Host name cannot be resolved (ENOTFOUND)">
146
+ ```text
147
+ Compaction model not used (morph/morph-compactor failed: fetch failed: getaddrinfo ENOTFOUND api.morphllm.com); context cleared instead
148
+ ```
149
+
150
+ Check your network connection, proxy or VPN settings, and the compactor's `baseUrl`.
151
+ </Accordion>
152
+
153
+ <Accordion title="Blocked by a DNS filter (0.0.0.0 or ::)">
154
+ A DNS filter such as NextDNS, Pi-hole, or AdGuard can block the compactor by resolving its domain to `0.0.0.0` or `::`. When the host resolves only to those addresses, Atomic names the domain to allow:
155
+
156
+ ```text
157
+ Compaction model not used (morph/morph-compactor failed: fetch failed: ERR_SSL_TLSV1_ALERT_INTERNAL_ERROR: tlsv1 alert internal error (api.morphllm.com resolves to 0.0.0.0, the address DNS filters such as NextDNS, Pi-hole or AdGuard return for blocked domains; allow api.morphllm.com in the resolver)); context cleared instead
158
+ ```
159
+
160
+ Add that domain to your DNS filter's allowlist. Until then, compaction continues working through memory compaction.
161
+ </Accordion>
@@ -0,0 +1,77 @@
1
+ ---
2
+ title: "Use memory compaction"
3
+ sidebarTitle: "Memory compaction"
4
+ description: "Atomic's default compaction form: clear the context window with no model call and let the agent recall verbatim details from session history."
5
+ ---
6
+
7
+ **Memory compaction** is Atomic's default form of compaction (active whenever `compactionModel` is unset, `""`, or `"auto"`). It requires no configuration, sends no extra model request, and needs no compaction parameters.
8
+
9
+ Instead of asking a model to write a lossy summary, Atomic clears the active context window and replaces it with a `Context cleared` boundary pointing to this session's verbatim history (`history://sessions/<session id>`). On the next turn, the agent searches and reads exact prior entries on demand using its own tools.
10
+
11
+ ## How it works
12
+
13
+ <Steps>
14
+ <Step title="Clear the active context window">
15
+ Atomic writes a `Context cleared` compaction boundary. Nothing is lost: every earlier user message, assistant reply, tool call, and tool result stays verbatim in the session store.
16
+ </Step>
17
+ <Step title="Hand the agent an exact history pointer">
18
+ After the boundary, the model sees only the system prompt and one `Context cleared` message naming:
19
+ - how many tokens the earlier conversation held;
20
+ - the exact `history://sessions/<session id>` URL for this session;
21
+ - which saved entries hold the earlier conversation, the boundary's entry position, and the total entry count;
22
+ - any `/compact` focus instructions you passed.
23
+ </Step>
24
+ <Step title="Recover exact details on demand">
25
+ In its next turn, the agent searches the exact session URL first (a plain `history://sessions` search skips the current session), then reads narrow ranges of about 200 saved entries with `read history://sessions/<id>:N-M`. It follows continuation URLs when reads stop early and opens saved full tool-output links (`tool-output://` or `artifact://`) when it needs untruncated command or tool output.
26
+ </Step>
27
+ </Steps>
28
+
29
+ ### Example boundary message
30
+
31
+ ```text
32
+ Context cleared. Your earlier conversation (182,340 tokens) is no longer in your context window. It is stored verbatim in this session's history at history://sessions/019f6a2e-...: entries 1-4210 hold the earlier conversation, this boundary is entry 4211, and the history has 4211 entries now. Before you continue, recover what the task needs from there.
33
+
34
+ Recover what you need, in this order:
35
+ 1. Every <keepContext> span, verbatim and whole: search history://sessions/019f6a2e-... for "keepContext". ...
36
+ 2. The user's objectives and latest requests; constraints and prohibitions ...
37
+
38
+ How to recover:
39
+ - Search first ...
40
+
41
+ Then continue the task.
42
+ ```
43
+
44
+ See [Recalling earlier work](/sessions#recalling-earlier-work) for how `history://` URLs read and search saved entries.
45
+
46
+ ### Recovery priority
47
+
48
+ The boundary directs the agent to recover information in order:
49
+
50
+ 1. Every `<keepContext>` span verbatim and whole by searching the session URL for `keepContext`.
51
+ 2. The user's objectives and latest requests, constraints and prohibitions, decisions and their rationale, key identifiers (branches, worktrees, pull requests, run IDs, file paths, commands), open work, and needed tool results, preferring the most recent records.
52
+
53
+ ## `keepContext` tags
54
+
55
+ Wrap constraints or facts the agent must not lose in `<keepContext>` and `</keepContext>`:
56
+
57
+ ```text
58
+ <keepContext>
59
+ You are researching only. Do not implement code changes.
60
+ </keepContext>
61
+ ```
62
+
63
+ The tags do not pin text in the context window automatically. Instead, the boundary recovery instructions tell the agent to search session history for every tagged span and recover each one verbatim before anything else. Custom compaction models may also honor the tags.
64
+
65
+ <Tip>
66
+ Put each opening and closing tag on its own line. Tag constraints, prohibitions, acceptance criteria, and key identifiers, and keep spans short so recovery stays fast.
67
+ </Tip>
68
+
69
+ ## Agents without `read` or `search` {#agents-without-read-or-search}
70
+
71
+ Agents whose tool allowlist omits `read` or `search` (such as restricted subagents) automatically receive one read-only tool named `session_history` after their first context clear, or on resume whenever `read` or `search` is absent.
72
+
73
+ `session_history` lets the agent search and read narrow entry ranges from its own session history without accessing any other session, file, or project, leaving all other tool restrictions intact. For exact `session_history` parameters, entry clamps, and output limits, see [The `session_history` tool](/compaction/reference#the-session_history-tool).
74
+
75
+ <Note>
76
+ Memory compaction also serves as the automatic fallback whenever a [custom compaction model](/compaction/custom-compactors) is unauthenticated, unreachable, times out, or returns unusable output.
77
+ </Note>
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  title: "Compaction reference"
3
3
  sidebarTitle: "Compaction"
4
- description: "Reference for compaction parameters, saved boundary fields, extension hooks, SDK concurrency, exports, branch summary format, and settings."
4
+ description: "Reference for compaction parameters, HTTP compactor contract, saved boundary fields, session_history tool, extension hooks, SDK concurrency, error classes, exports, branch summaries, and settings."
5
5
  ---
6
6
 
7
7
  ## Parameters
@@ -14,30 +14,52 @@ Extension events and compaction results carry one parameter:
14
14
 
15
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.
16
16
 
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.
17
+ Endpoint-specific knobs live 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`), never as top-level `session.compact()` or `settings.json` compaction options (see [Settings](#settings)). When `compactionParams` is omitted, Atomic does not inject provider-specific body fields so the remote API applies its own defaults.
18
18
 
19
- Safety bounds are exported from `@bastani/atomic`. A compactor model's output has no built-in size limit: only a `maxTokens` you set on the compactor model limits it, and it has no default.
19
+ Compacted text from a compactor model or a `session_before_compact` extension hook has no built-in size limit: only a `maxTokens` you set on a compactor model limits its output (using `estimateTextTokens()` at 4 ASCII characters or 1 non-ASCII character per token), and it has no default. The default request timeout is exported from `@bastani/atomic`:
20
20
 
21
21
  | Default | Export | Model override field | Meaning |
22
22
  | --- | --- | --- | --- |
23
23
  | `120000` | `COMPACTOR_REQUEST_TIMEOUT_MS` | `timeoutMs` | Wall-clock limit on one compactor request, in milliseconds |
24
- | `32000` | `COMPACTED_OUTPUT_MAX_TOKENS` | None | Largest compacted text an extension's `session_before_compact` hook may return, in estimated tokens (also capped at `COMPACTED_OUTPUT_MAX_TRIGGER_SHARE` = 50% of the automatic trigger budget). Does not apply to compactor models |
25
- | `2000` | `COMPACTOR_LINE_WIDTH` | None | Character width at which long lines wrap before framing |
26
24
 
27
- ### Compactor request contract
25
+ ### Compactor request contract {#compactor-request-contract}
28
26
 
29
27
  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
28
 
31
- Atomic POSTs JSON to `<baseUrl><endpointPath>` (`endpointPath` defaults to `"/compact"`; `""` POSTs directly to `baseUrl`):
29
+ Atomic `POST`s JSON to `<baseUrl><endpointPath>` (`endpointPath` defaults to `"/compact"`; `""` `POST`s directly to `baseUrl`):
32
30
 
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.
31
+ - **Message framing (`messages`).** An array of `{ role: "user" | "assistant", content: string }` items produced by `buildCompactorMessages()`. Prior compaction boundaries are hoisted first (labelled `[Previously compacted history]`), followed by remaining LLM-visible messages in order. Each item's `content` begins with a `<keepContext>\n<label>\n</keepContext>` header (`[User]`, `[Assistant]`, `[Tool result: <name>]` or `[Tool result: <name> (error)]`, `[Shell execution]`, `[Extension context: <customType>]`, or `[Previous branch summary]`). Lines longer than 2,000 characters are wrapped (`wrapLongLines()`), images become `[Image omitted from text compaction (<mimeType>)]`, thinking blocks are omitted, and `excludeFromContext` messages are skipped.
32
+ - **Payload precedence.** Atomic copies any defined keys from `compactionParams` first, then writes `messages`, `query`, and `model` last—so core fields cannot be overridden by `compactionParams`.
33
+ - **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. Either `apiKey` or at least one custom header in `headers` satisfies the credential check (`missing-credentials` is thrown only when both are absent). The API key and sensitive auth headers (`Authorization`, `Proxy-Authorization`, `X-API-Key`, `API-Key`) are redacted from HTTP error excerpts and compacted output.
34
+ - **Error body truncation.** On non-2xx HTTP responses, Atomic reads at most **8 KiB** of the response body, redacts secrets, normalizes control characters and whitespace, and truncates the excerpt to **500 characters**.
35
+ - **Response parsing.** Reads joined non-empty `messages[].content` strings when present, otherwise `output`. Optional `usage` is recorded only when **both** `usage.input_tokens` and `usage.output_tokens` are numbers.
36
+ - **Automatic fallback.** Any failure (missing `baseUrl`, missing credentials, network/HTTP error, timeout, malformed/empty output, output exceeding a configured `maxTokens`, or pressing `Escape` / `abortCompaction()`) falls back automatically to memory compaction (`form: "cleared"`) with `fallbackReason` set.
37
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.
38
+ 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.
39
39
 
40
- ## Persistence and resume
40
+ ## Automatic trigger and continuation limits {#automatic-trigger-and-continuation-limits}
41
+
42
+ - **Automatic skip condition.** Automatic compaction skips when the system prompt and clear boundary together would already reach or exceed the automatic trigger (`systemPrompt + boundary >= trigger`), letting [`fallbackModels`](/settings#fallbackmodels) handle provider overflow.
43
+ - **Completed answer preservation.** An assistant answer that finishes over the automatic threshold remains as the session's last answer so `prompt()`, RPC `get_last_assistant_text`, and `/copy` can read it; Atomic compacts immediately before the next request.
44
+ - **Overflow recovery.** On a provider context-overflow error, Atomic compacts and retries the interrupted turn at most once per turn.
45
+ - **Truncated responses (`stopReason: "length"`).**
46
+ - Stopped with `length` before the requested output cap: 1 compact-and-retry, or at most 1 direct continuation if nothing can be compacted.
47
+ - Hit the requested output cap: up to **3** direct continuations.
48
+ - Output-budget error: at most **1** direct continuation.
49
+
50
+ ## The `session_history` tool {#the-session_history-tool}
51
+
52
+ When an agent's tool allowlist omits `read` or `search` (such as a restricted subagent), Atomic registers one read-only tool named `session_history` (`SESSION_HISTORY_TOOL_NAME`) after its first context clear, or on resume whenever `read` or `search` is absent.
53
+
54
+ | Parameter | Type | Behavior |
55
+ | --- | --- | --- |
56
+ | `pattern` | `string` (optional) | Case-sensitive regular expression search over this session's history with 0 surrounding context lines. Combine with `lines` to restrict the search to an entry range or `?cursor=` continuation URL. |
57
+ | `lines` | `string` (optional) | 1-based saved-entry range (`"100-300"` or `"120"`) or a `?cursor=` continuation URL from an earlier truncated call. |
58
+
59
+ - **Limits.** Reads clamp to at most **400 entries** per call (`MAX_READ_ENTRIES`), and output truncates at **50,000 characters** (`MAX_OUTPUT_CHARS`).
60
+ - **Isolation.** `session_history` can reach only `history://sessions/<own session id>` and rejects URLs targeting any other session, file, or project, leaving the agent's other tools unchanged.
61
+
62
+ ## Persistence and resume {#persistence-and-resume}
41
63
 
42
64
  A successful compaction appends a `type: "compaction"` entry (see [`CompactionEntry`](/session-format#compactionentry)):
43
65
 
@@ -61,12 +83,16 @@ A successful compaction appends a `type: "compaction"` entry (see [`CompactionEn
61
83
  }
62
84
  ```
63
85
 
86
+ <Note>
87
+ **Schema compatibility fields.** `"strategy": "verbatim-lines"`, `promptVersion: 7`, and `stats.rangeCount: 0` are retained from earlier line-based compaction versions as stable schema discriminators so active boundaries stay distinguishable from retired summary-compaction entries—even on a zero-line clear (`form: "cleared"`).
88
+ </Note>
89
+
64
90
  | Field | Meaning |
65
91
  | --- | --- |
66
92
  | `summary` | Full boundary message shown to the model: `Context cleared` or `Context compacted` text, any compacted text, recovery instructions, and any `/compact` instructions |
67
93
  | `firstKeptEntryId` | Always `null` on new boundaries because no earlier message stays in context |
68
94
  | `tokensBefore` | Provider-aware whole-context token count before the boundary, used for budgeting and the chat boundary line |
69
- | `coveredThroughEntryId` | Written only by earlier versions while a tool call waited for its result; new boundaries are never written while a call waits |
95
+ | `coveredThroughEntryId` | Actively written during resume-budget compaction on Claude models with fixed thinking budgets so newly added resume context (changed instructions, blueprint context, or recovery notices) replays after the boundary; also present on boundaries written by earlier versions while a tool call waited for its result (current Atomic never writes a boundary while a tool call waits) |
70
96
  | `usage` | Compactor endpoint usage when reported |
71
97
  | `fromHook` | `true` when an extension supplied compacted text from `session_before_compact` |
72
98
  | `systemMessage` | Optional replayed system prompt and tool state checkpoint at this boundary |
@@ -83,6 +109,8 @@ Only `compaction` entries with `details.strategy: "verbatim-lines"` affect activ
83
109
 
84
110
  ## Extension hooks
85
111
 
112
+ Atomic exposes three compaction hooks below plus `session_before_tree` for branch navigation (see [Extension hooks for branch summarization](#extension-hooks-for-branch-summarization)).
113
+
86
114
  ### `session_before_compact`
87
115
 
88
116
  Extensions can cancel compaction or provide custom replacement text before any compactor call runs:
@@ -100,11 +128,16 @@ atomic.on("session_before_compact", async (event) => {
100
128
  });
101
129
  ```
102
130
 
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.
131
+ `preparation` (`VerbatimCompactionPreparation`) is a deep-frozen clone (attempting to mutate it throws a `TypeError`):
132
+
133
+ - `preparation.region` (`NumberedRegion`): the entire active context since the last boundary serialized for hooks—`lines` holds one line per element with role prefixes (`[User]: `, `[Assistant]: `, `[Assistant tool calls]: `, `[Tool result]: `), starting with any prior boundary text; optional `messageSpans` gives `{ role, start, end, previousSummary? }` 1-based line ranges per serialized message; `tokenEstimate` gives its estimated token count.
134
+ - `preparation.regionEntryIds`: array of session entry IDs covered by `preparation.region`.
135
+ - `preparation.parameters.query`: `/compact` instructions or the latest user request.
136
+ - `preparation.firstKeptEntryId` (`null`) and `preparation.keptTailMessageCount` (`0`): fixed compatibility fields kept because current boundaries replace the entire active window.
104
137
 
105
138
  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.
106
139
 
107
- Empty or whitespace-only text counts as no replacement, so the configured compaction form runs normally. If `compactedText` exceeds `COMPACTED_OUTPUT_MAX_TOKENS` (32,000 estimated tokens, or half of the automatic trigger on a small context window) 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`. These limits apply only to an extension's text; a compactor model's output has none.
140
+ Empty or whitespace-only text counts as no replacement, so the configured compaction form runs normally. Extension-supplied `compactedText` has no built-in size limit.
108
141
 
109
142
  ### `session_compact`
110
143
 
@@ -135,7 +168,7 @@ atomic.on("session_compact_failed", async (event) => {
135
168
 
136
169
  `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`.
137
170
 
138
- ## SDK concurrency and message queuing
171
+ ## SDK concurrency and message queuing {#sdk-concurrency-and-message-queuing}
139
172
 
140
173
  For `session.compact()` usage and return types, see [Compaction and tree navigation](/sdk#compaction-and-tree-navigation).
141
174
 
@@ -146,39 +179,48 @@ For `session.compact()` usage and return types, see [Compaction and tree navigat
146
179
  - **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
180
  - **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
181
 
149
- ## Compaction errors
182
+ ## Compaction errors {#compaction-errors}
150
183
 
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`.
184
+ `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.
152
185
 
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) |
186
+ <Note>
187
+ Reading an invalid `compactionModel` or `compaction.reserveTokens` value from `settings.json` throws a plain `Error` rather than `CompactionConfigError`.
188
+ </Note>
189
+
190
+ | Class | `code` | `retryable` | Subclass fields | When |
191
+ | --- | --- | --- | --- | --- |
192
+ | `CompactionConfigError` | `invalid-setting` | `false` | `source`, `field`, `scope?` | `setCompactionModel()` receives a non-string or whitespace-padded `model`; RPC `set_compaction_model` additionally validates `scope` (`"global" \| "project"`) and `persist` (`boolean`) at runtime |
193
+ | `CompactionCancelledError` | `cancelled` | `false` | `reason?` | Compaction is cancelled via abort signal or `session_before_compact` returning `{ cancel: true }` |
194
+ | `CompactionStateError` | `nothing-to-compact`, `pending-tool-call`, `no-model-selected`, `snapshot-failed`, `boundary-not-built` | `false` | `detail?` | `session.compact()` cannot proceed in the current session state |
195
+ | `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 | `status?`, `timeoutMs?`, `model?` | Direct `requestCompactorOutput()` fails (during `session.compact()`, Atomic catches `CompactorFailure` and falls back to clearing context) |
159
196
 
160
197
  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
198
 
162
199
  ## Package exports
163
200
 
164
- `@bastani/atomic` exports these compaction helpers, errors, and types:
201
+ `@bastani/atomic` exports these compaction and branch-summarization helpers, errors, and types:
165
202
 
166
203
  | Export | Use |
167
204
  | --- | --- |
168
- | `CompactionError`, `CompactionConfigError`, `CompactionCancelledError`, `CompactionStateError`, `CompactorFailure` | Typed compaction error family, matching the SDK error convention (`code`, `hint`, `retryable`, `fields()`) |
205
+ | `CompactionError`, `CompactionConfigError`, `CompactionCancelledError`, `CompactionStateError`, `CompactorFailure` | Typed compaction error family (`code`, `hint`, `retryable`, `fields()`) |
169
206
  | `isCompactionError`, `isCompactionConfigError`, `isCompactionCancelledError`, `isCompactionStateError`, `isCompactorFailure`, `findCompactionError`, `isRetryableCompactionError` | Type guards and cause-chain helpers for compaction errors |
170
207
  | `serializeCompactionError`, `parseSerializedCompactionError`, `rehydrateCompactionError` | Cross-process serialization and rehydration for `CompactionError` |
171
208
  | `buildBoundaryText(input, totalEntries)` | Build the boundary message for a session, history location, and optional instructions or compacted text |
172
- | `buildCompactorMessages(messages, isBoundary)` | Frame active context messages in the format sent to a compactor |
209
+ | `buildCompactorMessages(messages, isBoundary)` | Frame active context messages in the wire format sent to a compactor |
173
210
  | `requestCompactorOutput(request)` | Send one `CompactorRequest` to a compactor endpoint; resolves `{ text, usage? }` or throws `CompactorFailure` / `CompactionCancelledError` |
174
211
  | `resolveCompactionModel(configured, models)` | Resolve `compactionModel` to a `CompactionModelSelection` (`auto` with any fallback reason, or a compactor) |
175
212
  | `classifyCompactionModel(configured, models)` | Classify a `compactionModel` string as `"auto"`, `"compactor"`, `"chat"`, `"classifier"`, or `"unknown"` |
176
- | `compactedOutputTokenCap(triggerTokens, maxOutputTokens?)` | Compute the largest compacted text an extension hook may return, in estimated tokens |
213
+ | `prepareCompactionBoundary`, `shouldCompact`, `calculateContextTokens`, `getLastAssistantUsage`, `DEFAULT_COMPACTION_SETTINGS` | Compaction threshold checks, token counting, boundary preparation, and default compaction settings |
214
+ | `estimateTokens`, `estimateTextTokens`, `wrapLongLines`, `serializeConversation`, `serializeConversationForCompaction` | Token estimation, 2,000-char line wrapping, and conversation serializers |
215
+ | `collectEntriesForBranchSummary`, `prepareBranchEntries`, `generateBranchSummary` | Branch-entry collection, budget trimming, and branch summary generation |
216
+ | `COMPACTOR_REQUEST_TIMEOUT_MS` | Default wall-clock request timeout in milliseconds (`120000`) when a compactor model omits `timeoutMs` |
177
217
  | `SESSION_HISTORY_TOOL_NAME` | `"session_history"`, the read-only history tool granted after clearing when `read` or `search` is absent |
178
218
 
179
- The types `CompactorModel`, `CompactorApi`, `ProviderCompactorModelConfig`, `CompactionForm`, `CompactionBackend`, `CompactionHistoryLocation`, `CompactionModelKind`, `CompactionModelSelection`, `CompactorMessage`, `CompactorRequest`, `CompactionErrorCode`, `SerializedCompactionError`, and `BranchSummaryEntry` are exported alongside them.
219
+ The types `CompactorModel`, `CompactorApi`, `ProviderCompactorModelConfig`, `CompactionForm`, `CompactionBackend`, `CompactionHistoryLocation`, `CompactionModelKind`, `CompactionModelSelection`, `CompactorMessage`, `CompactorRequest`, `CompactionErrorCode`, `SerializedCompactionError`, `BranchSummaryEntry`, `BranchPreparation`, `BranchSummaryResult`, `CollectEntriesResult`, `FileOperations`, `GenerateBranchSummaryOptions`, `LineRange`, `VerbatimCompactionDetails`, `VerbatimCompactionParameters`, `VerbatimCompactionPreparation`, and `VerbatimCompactionResult` are exported alongside them.
220
+
221
+ ## Branch summaries {#branch-summaries}
180
222
 
181
- ## Branch summary format
223
+ ### Branch summary format {#branch-summary-format}
182
224
 
183
225
  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:
184
226
 
@@ -239,7 +281,7 @@ interface BranchSummaryDetails {
239
281
  }
240
282
  ```
241
283
 
242
- ### Message serialization for branch summaries
284
+ ### Message serialization and edge cases
243
285
 
244
286
  Branch-summary prompts serialize conversation messages with role labels so the model summarizes rather than continuing the conversation:
245
287
 
@@ -252,11 +294,15 @@ Branch-summary prompts serialize conversation messages with role labels so the m
252
294
 
253
295
  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.
254
296
 
255
- ## Extension hooks for branch summarization
297
+ Key edge cases in `generateBranchSummary()`:
298
+
299
+ - **Empty branch.** When no summarizable messages exist in the abandoned segment, `generateBranchSummary()` returns `{ summary: "No content to summarize" }` without calling the model.
300
+ - **Nested branch summaries near the budget.** When walking newest-to-oldest reaches `tokenBudget`, an earlier `branch_summary` entry is still included if `totalTokens < tokenBudget * 0.9` so nested branch context is preserved when almost enough room remains.
301
+ - **Replacing the default prompt.** Setting `replaceInstructions: true` alongside `customInstructions` on `GenerateBranchSummaryOptions` replaces the built-in structured summary prompt instead of appending `Additional focus: ...`.
256
302
 
257
- ### `session_before_tree`
303
+ ### Extension hooks for branch summarization {#extension-hooks-for-branch-summarization}
258
304
 
259
- Fired before `/tree` navigation regardless of whether the user requested a summary. Handlers can cancel navigation or supply a custom summary:
305
+ `session_before_tree` fires before `/tree` navigation regardless of whether the user requested a summary. Handlers can cancel navigation or supply a custom summary:
260
306
 
261
307
  ```typescript
262
308
  atomic.on("session_before_tree", async (event, ctx) => {
@@ -285,7 +331,7 @@ atomic.on("session_before_tree", async (event, ctx) => {
285
331
 
286
332
  `SessionBeforeTreeEvent` and `SessionBeforeTreeResult` are exported from `@bastani/atomic`.
287
333
 
288
- ## Settings
334
+ ## Settings {#settings}
289
335
 
290
336
  Configure compaction in `~/.atomic/agent/settings.json` or `<project-dir>/.atomic/settings.json` (legacy `.pi` paths are also supported):
291
337
 
@@ -299,9 +345,11 @@ Configure compaction in `~/.atomic/agent/settings.json` or `<project-dir>/.atomi
299
345
  }
300
346
  ```
301
347
 
302
- See [Compaction settings](/settings#compaction) for the complete `compaction` and `branchSummary` settings table, and [Compaction model](/compaction#compaction-model) for selecting `auto` or a registered compactor. Setting `"compaction": { "enabled": false }` turns off automatic compaction while keeping manual `/compact` available.
348
+ See [Compaction settings](/settings#compaction) for the complete `compaction` and `branchSummary` settings table, and [Select a compaction model](/compaction/custom-compactors#select-a-compaction-model) for choosing memory compaction (`auto`) or a registered compactor. Setting `"compaction": { "enabled": false }` turns off automatic compaction while keeping manual `/compact` available.
303
349
 
304
- These removed compaction settings are ignored without error if still present in `settings.json`: `compaction.compression_ratio`, `compaction.preserve_recent`, `compaction.keepContextShare`, `compaction.query`, `compaction.planningTimeoutMs`, `compaction.modelOverrides`, `compaction.background`, `compaction.backgroundThresholdPercent`, and `compaction.historyRecall`.
350
+ <Note>
351
+ **Removed settings.** These legacy compaction settings are ignored without error if still present in `settings.json` (or passed to `session.compact()`): `compaction.compression_ratio`, `compaction.preserve_recent`, `compaction.keepContextShare`, `compaction.query`, `compaction.planningTimeoutMs`, `compaction.modelOverrides`, `compaction.background`, `compaction.backgroundThresholdPercent`, and `compaction.historyRecall`. Configure endpoint-specific parameters like `compression_ratio` or `preserve_recent` under `compactionParams` in `models.json` instead.
352
+ </Note>
305
353
 
306
354
  ## Historical formats
307
355