@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.
- package/CHANGELOG.md +29 -0
- package/dist/_shared/dist-KOELCESV.js +2 -2
- package/dist/_shared/fork-row-index-UAUAQRD5.js +2 -2
- package/dist/_shared/lib-4PES5P4V.js +2 -2
- package/dist/_shared/mode-interactive-sdk-7KXUFI2F.js +3 -3
- package/dist/_shared/mode-rpc-sdk-IOPGDYR4.js +3 -3
- package/dist/_shared/mode-shared-2QJSCUM6.js +3 -3
- package/dist/_shared/p1a-prewarm-XIU57JHF.js +3 -3
- package/dist/_shared/runtime-O4KCSG4C.js +2 -2
- package/dist/_shared/{sdk-B5LEWGGI.js → sdk-OHKMDJ74.js} +27 -5
- package/dist/_shared/{sdk-B5LEWGGI.js.map → sdk-OHKMDJ74.js.map} +1 -1
- package/dist/_shared/session-data-AHTU7IS6.js +2 -2
- package/dist/_shared/startup-0-0-Q3MWKUK4.js +2 -2
- package/dist/_shared/startup-0-1-M6OWAYHH.js +2 -2
- package/dist/_shared/{startup-0-2-5QHPCEON.js → startup-0-2-2HUMCPKX.js} +14 -16
- package/dist/_shared/startup-0-2-2HUMCPKX.js.map +1 -0
- package/dist/_shared/startup-0-3-4ZYBYQNM.js +3 -3
- package/dist/_shared/startup-0-4-ZMJV547D.js +3 -3
- package/dist/_shared/startup-0-5-YDW47QX6.js +3 -3
- package/dist/_shared/startup-10-0-TDQNBDDL.js +3 -3
- package/dist/_shared/startup-14-0-MLX36RBG.js +1 -1
- package/dist/_shared/startup-15-0-YUKGAC63.js +1 -1
- package/dist/_shared/startup-15-1-4S7FLMNG.js +6 -30
- package/dist/_shared/startup-15-1-4S7FLMNG.js.map +1 -1
- package/dist/_shared/startup-8-0-34CBHPZH.js +3 -3
- package/dist/_shared/startup-8-1-LZFXSD3Z.js +3 -3
- package/dist/_shared/storage-command-7MGXLJGZ.js +2 -2
- package/dist/_shared/storage-status-K7PX2RXA.js +3 -3
- package/dist/_shared/task-unsaved-answer-VJ2KTB4V.js +2 -2
- package/dist/_shared/tree-outline-MUEPK5B7.js +2 -2
- package/dist/builtin/intercom/index.bundle.mjs +1 -1
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/index.bundle.mjs +1 -1
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/subagents/src/extension/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/index.bundle.mjs +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/cli/auth-cli.code.js +1 -1
- package/dist/cli/auth-cli.impl.js +3 -3
- package/dist/cli/auth-cli.js +3 -3
- package/dist/cli/blueprint-command.impl.js +3 -3
- package/dist/cli/blueprint-command.js +3 -3
- package/dist/cli/intercom-command.code.js +3 -3
- package/dist/cli/intercom-command.impl.js +3 -3
- package/dist/cli/intercom-command.js +3 -3
- package/dist/cli/list-models.impl.js +3 -3
- package/dist/cli/list-models.js +3 -3
- package/dist/cli/session-picker.code.js +1 -1
- package/dist/cli/session-picker.impl.js +3 -3
- package/dist/cli/session-picker.js +3 -3
- package/dist/cli/startup-ui.code.js +1 -1
- package/dist/cli/startup-ui.impl.js +3 -3
- package/dist/cli/startup-ui.js +3 -3
- package/dist/cli/storage-command.impl.js +3 -3
- package/dist/cli/storage-command.js +3 -3
- package/dist/cli/storage-search-session.code.js +1 -1
- package/dist/cli/storage-search-session.impl.js +3 -3
- package/dist/cli/storage-search-session.js +3 -3
- package/dist/cli/team-command.code.js +1 -1
- package/dist/cli/team-command.impl.js +3 -3
- package/dist/cli/team-command.js +3 -3
- package/dist/cli.js +2 -2
- package/dist/core/compaction/compactor.d.ts +0 -8
- package/dist/core/debug.impl.js +3 -3
- package/dist/core/debug.js +3 -3
- package/dist/core/export-html/card-projection.impl.js +3 -3
- package/dist/core/export-html/card-projection.js +3 -3
- package/dist/core/export-html/index.code.js +2 -2
- package/dist/core/export-html/index.impl.js +3 -3
- package/dist/core/export-html/index.js +3 -3
- package/dist/core/export-html/json-spans.impl.js +3 -3
- package/dist/core/export-html/json-spans.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.impl.js +3 -3
- package/dist/core/export-html/oversized-render-inputs.js +3 -3
- package/dist/core/export-html/tool-renderer.impl.js +3 -3
- package/dist/core/export-html/tool-renderer.js +3 -3
- package/dist/core/extensions/jiti-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-loader.js +3 -3
- package/dist/core/extensions/jiti-static-loader.impl.js +3 -3
- package/dist/core/extensions/jiti-static-loader.js +3 -3
- package/dist/core/extensions/loader-host-modules.impl.js +3 -3
- package/dist/core/extensions/loader-host-modules.js +3 -3
- package/dist/core/intercom-broker-control-host.code.js +1 -1
- package/dist/core/intercom-broker-control-host.impl.js +3 -3
- package/dist/core/intercom-broker-control-host.js +3 -3
- package/dist/core/intercom-broker-control.code.js +2 -2
- package/dist/core/intercom-broker-control.impl.js +3 -3
- package/dist/core/intercom-broker-control.js +3 -3
- package/dist/core/package-manager-storage-adapters.impl.js +3 -3
- package/dist/core/package-manager-storage-adapters.js +3 -3
- package/dist/core/sdk.code.js +1 -1
- package/dist/core/sdk.impl.js +3 -3
- package/dist/core/sdk.js +3 -3
- package/dist/core/session-manager-core.js +3 -3
- package/dist/core/session-manager-list.impl.js +3 -3
- package/dist/core/session-manager-list.js +3 -3
- package/dist/core/session-manager.impl.js +3 -3
- package/dist/core/session-manager.js +3 -3
- package/dist/core/session-storage.impl.js +3 -3
- package/dist/core/session-storage.js +3 -3
- package/dist/core/storage/index.js +2 -2
- package/dist/core/storage/node-sqlite-thread.js +2 -2
- package/dist/core/storage/node-sqlite.js +2 -2
- package/dist/core/storage/offline-snapshot-file.impl.js +3 -3
- package/dist/core/storage/offline-snapshot-file.js +3 -3
- package/dist/core/storage/provider.js +2 -2
- package/dist/core/storage/selection.js +2 -2
- package/dist/core/storage/session/branch-fork-source.code.js +2 -2
- package/dist/core/storage/session/branch-fork-source.impl.js +3 -3
- package/dist/core/storage/session/branch-fork-source.js +3 -3
- package/dist/core/storage/session/card-view.impl.js +3 -3
- package/dist/core/storage/session/card-view.js +3 -3
- package/dist/core/storage/session/child-reader.code.js +2 -2
- package/dist/core/storage/session/child-reader.impl.js +3 -3
- package/dist/core/storage/session/child-reader.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.impl.js +3 -3
- package/dist/core/storage/session/chunked-resume-projection.js +3 -3
- package/dist/core/storage/session/expanded-child-details.code.js +2 -2
- package/dist/core/storage/session/expanded-child-details.impl.js +3 -3
- package/dist/core/storage/session/expanded-child-details.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.impl.js +3 -3
- package/dist/core/storage/session/fork-row-bytes.js +3 -3
- package/dist/core/storage/session/fork-row-index.impl.js +3 -3
- package/dist/core/storage/session/fork-row-index.js +3 -3
- package/dist/core/storage/session/fork-staging.code.js +1 -1
- package/dist/core/storage/session/fork-staging.impl.js +3 -3
- package/dist/core/storage/session/fork-staging.js +3 -3
- package/dist/core/storage/session/fork-window.code.js +2 -2
- package/dist/core/storage/session/fork-window.impl.js +3 -3
- package/dist/core/storage/session/fork-window.js +3 -3
- package/dist/core/storage/session/history-pages.impl.js +3 -3
- package/dist/core/storage/session/history-pages.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.impl.js +3 -3
- package/dist/core/storage/session/jsonl-entry-projection.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.impl.js +3 -3
- package/dist/core/storage/session/jsonl-session-store.js +3 -3
- package/dist/core/storage/session/memory-session-store.impl.js +3 -3
- package/dist/core/storage/session/memory-session-store.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.code.js +2 -2
- package/dist/core/storage/session/pinned-branch-resume.impl.js +3 -3
- package/dist/core/storage/session/pinned-branch-resume.js +3 -3
- package/dist/core/storage/session/released-history-files.code.js +1 -1
- package/dist/core/storage/session/released-history-files.impl.js +3 -3
- package/dist/core/storage/session/released-history-files.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.impl.js +3 -3
- package/dist/core/storage/session/resident-fork-rows.js +3 -3
- package/dist/core/storage/session/session-resume.impl.js +3 -3
- package/dist/core/storage/session/session-resume.js +3 -3
- package/dist/core/storage/session/snapshot-cut.impl.js +3 -3
- package/dist/core/storage/session/snapshot-cut.js +3 -3
- package/dist/core/storage/session/snapshot-history.code.js +2 -2
- package/dist/core/storage/session/snapshot-history.impl.js +3 -3
- package/dist/core/storage/session/snapshot-history.js +3 -3
- package/dist/core/storage/session/sql-session-store.code.js +1 -1
- package/dist/core/storage/session/sql-session-store.impl.js +3 -3
- package/dist/core/storage/session/sql-session-store.js +3 -3
- package/dist/core/storage/session/tree-outline.impl.js +3 -3
- package/dist/core/storage/session/tree-outline.js +3 -3
- package/dist/core/storage/session/tree-presentation.impl.js +3 -3
- package/dist/core/storage/session/tree-presentation.js +3 -3
- package/dist/core/storage/storage-status.impl.js +3 -3
- package/dist/core/storage/storage-status.js +3 -3
- package/dist/core/storage/team.impl.js +3 -3
- package/dist/core/storage/team.js +3 -3
- package/dist/core/structured-output/index.code.js +1 -1
- package/dist/core/structured-output/index.impl.js +3 -3
- package/dist/core/structured-output/index.js +3 -3
- package/dist/core/tasks/task-completion-entry.impl.js +3 -3
- package/dist/core/tasks/task-completion-entry.js +3 -3
- package/dist/core/tasks/task-file-history.code.js +2 -2
- package/dist/core/tasks/task-file-history.impl.js +3 -3
- package/dist/core/tasks/task-file-history.js +3 -3
- package/dist/core/tasks/task-reference-archive.code.js +2 -2
- package/dist/core/tasks/task-reference-archive.js +3 -3
- package/dist/core/tasks/task-reference-identity.js +3 -3
- package/dist/core/tasks/task-reference-stream.impl.js +3 -3
- package/dist/core/tasks/task-reference-stream.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.impl.js +3 -3
- package/dist/core/tasks/task-unsaved-answer.js +3 -3
- package/dist/core/tasks/task-view-source.impl.js +3 -3
- package/dist/core/tasks/task-view-source.js +3 -3
- package/dist/core/tools/read-url.impl.js +3 -3
- package/dist/core/tools/read-url.js +3 -3
- package/dist/core/worktree-snapshot/blob-store.js +2 -2
- package/dist/core/worktree-snapshot/errors.code.js +1 -1
- package/dist/core/worktree-snapshot/errors.impl.js +3 -3
- package/dist/core/worktree-snapshot/errors.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.impl.js +3 -3
- package/dist/core/worktree-snapshot/session-index-reset.js +3 -3
- package/dist/extensions/codemode/execute.impl.js +3 -3
- package/dist/extensions/codemode/execute.js +3 -3
- package/dist/extensions/codemode/renderer.impl.js +3 -3
- package/dist/extensions/codemode/renderer.js +3 -3
- package/dist/extensions/mcp/cli.code.js +1 -1
- package/dist/extensions/mcp/cli.impl.js +3 -3
- package/dist/extensions/mcp/cli.js +3 -3
- package/dist/extensions/mcp/cli.lazy.code.js +2 -2
- package/dist/extensions/mcp/cli.lazy.impl.js +3 -3
- package/dist/extensions/mcp/cli.lazy.js +3 -3
- package/dist/extensions/mcp/runtime.code.js +1 -1
- package/dist/extensions/mcp/runtime.impl.js +3 -3
- package/dist/extensions/mcp/runtime.js +3 -3
- package/dist/index.d.ts +21 -1
- package/dist/index.js +2 -2
- package/dist/main-first-time-setup.code.js +1 -1
- package/dist/main-first-time-setup.impl.js +3 -3
- package/dist/main-first-time-setup.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.code.js +2 -2
- package/dist/modes/interactive/components/stored-tree-view.impl.js +3 -3
- package/dist/modes/interactive/components/stored-tree-view.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.impl.js +3 -3
- package/dist/modes/interactive/components/user-message-selector-archive.js +3 -3
- package/dist/modes/print-mode.js +1 -1
- package/dist/package-manager-cli.code.js +2 -2
- package/dist/package-manager-cli.impl.js +3 -3
- package/dist/package-manager-cli.js +3 -3
- package/dist/startup-files.json +1 -1
- package/dist/startup-stages/6.js +1 -1
- package/dist/utils/startup-database-spare.code.js +1 -1
- package/dist/utils/startup-database-spare.impl.js +3 -3
- package/dist/utils/startup-database-spare.js +3 -3
- package/dist/utils/tools-manager.impl.js +3 -3
- package/dist/utils/tools-manager.js +3 -3
- package/docs/background-tasks/reference.md +182 -0
- package/docs/background-tasks.md +98 -405
- package/docs/build.md +67 -27
- package/docs/changelog.mdx +9 -0
- package/docs/codemode.md +108 -39
- package/docs/compaction/branch-summaries.md +54 -0
- package/docs/compaction/custom-compactors.md +161 -0
- package/docs/compaction/memory-compaction.md +77 -0
- package/docs/compaction/reference.md +86 -38
- package/docs/compaction.md +51 -252
- package/docs/computer-use.md +169 -321
- package/docs/containerization.md +71 -57
- package/docs/custom-provider/api-reference.md +119 -25
- package/docs/custom-provider/oauth.md +114 -132
- package/docs/custom-provider/override.md +37 -27
- package/docs/custom-provider/registration.md +107 -83
- package/docs/custom-provider/streaming.md +85 -71
- package/docs/custom-provider.md +85 -52
- package/docs/development.md +39 -29
- package/docs/docs.json +76 -63
- package/docs/environment-variables.md +94 -44
- package/docs/extensions/api-reference.md +86 -43
- package/docs/extensions/authoring.md +162 -154
- package/docs/extensions/events.md +80 -25
- package/docs/extensions/examples.md +90 -85
- package/docs/extensions/ui.md +206 -82
- package/docs/extensions.md +79 -108
- package/docs/getting-started/authentication.md +67 -36
- package/docs/getting-started/first-session.md +53 -43
- package/docs/getting-started/installation.md +116 -89
- package/docs/getting-started/project-instructions.md +48 -34
- package/docs/guides/configuration.md +82 -20
- package/docs/guides/non-interactive.md +66 -24
- package/docs/guides/resume-on-any-machine.md +135 -82
- package/docs/guides/team-setup.md +114 -105
- package/docs/guides.md +76 -32
- package/docs/herdr.md +15 -16
- package/docs/how-atomic-works.md +140 -0
- package/docs/index.md +58 -44
- package/docs/intercom/operations.md +141 -151
- package/docs/intercom/reference.md +85 -108
- package/docs/intercom.md +84 -145
- package/docs/json.md +120 -67
- package/docs/keybindings.md +85 -49
- package/docs/libraries/agent-core.md +137 -275
- package/docs/libraries/ai.md +100 -84
- package/docs/libraries/codemode.md +210 -300
- package/docs/libraries/schema.md +59 -53
- package/docs/libraries/storage-postgres.md +49 -35
- package/docs/libraries/telemetry.md +153 -354
- package/docs/libraries/tui.md +265 -393
- package/docs/libraries.md +42 -26
- package/docs/llama-cpp.md +171 -161
- package/docs/mcp-servers.md +90 -51
- package/docs/models/choose-a-model.md +188 -0
- package/docs/models/reference.md +74 -30
- package/docs/models.md +153 -88
- package/docs/orchestration/migrating-workflows.md +23 -16
- package/docs/orchestration/patterns.md +39 -44
- package/docs/orchestration.md +65 -26
- package/docs/packages/authoring.md +51 -29
- package/docs/packages/reference.md +42 -21
- package/docs/packages.md +69 -58
- package/docs/programmatic.md +118 -24
- package/docs/prompt-templates.md +84 -83
- package/docs/providers/reference.md +43 -48
- package/docs/providers.md +219 -451
- package/docs/quickstart.md +140 -120
- package/docs/reference/cli.md +135 -97
- package/docs/reference.md +20 -18
- package/docs/rpc/examples.md +76 -20
- package/docs/rpc/extension-ui.md +64 -38
- package/docs/rpc/protocol.md +361 -110
- package/docs/rpc.md +57 -17
- package/docs/sdk/reference.md +409 -534
- package/docs/sdk/storage.md +53 -13
- package/docs/sdk/structured-decisions.md +82 -56
- package/docs/sdk/web-server.md +57 -43
- package/docs/sdk.md +106 -84
- package/docs/security.md +42 -64
- package/docs/session-format.md +62 -38
- package/docs/sessions.md +99 -214
- package/docs/settings.md +165 -195
- package/docs/shell-aliases.md +9 -6
- package/docs/skills/authoring.md +69 -48
- package/docs/skills/reference.md +51 -20
- package/docs/skills.md +99 -148
- package/docs/slash-commands.md +129 -0
- package/docs/storage/custom-adapters.md +160 -85
- package/docs/storage/jsonl.md +81 -66
- package/docs/storage/postgres/pgbouncer.md +120 -126
- package/docs/storage/postgres/tuning.md +120 -143
- package/docs/storage/postgres.md +314 -330
- package/docs/storage/sqlite.md +71 -42
- package/docs/storage.md +298 -302
- package/docs/subagents/authoring.md +55 -38
- package/docs/subagents/reference.md +73 -33
- package/docs/subagents.md +119 -187
- package/docs/terminal-setup.md +50 -38
- package/docs/termux.md +67 -41
- package/docs/themes/reference.md +23 -19
- package/docs/themes.md +142 -127
- package/docs/tmux.md +47 -55
- package/docs/tools.md +147 -109
- package/docs/tui/reference.md +166 -214
- package/docs/tui.md +196 -341
- package/docs/usage.md +118 -138
- package/docs/verification.md +79 -51
- package/docs/web-access.md +121 -101
- package/docs/windows.md +26 -27
- package/docs/worktree-snapshots/reference.md +245 -0
- package/docs/worktree-snapshots.md +71 -259
- package/package.json +8 -8
- package/dist/_shared/startup-0-2-5QHPCEON.js.map +0 -1
- package/docs/guides/intercom.md +0 -32
- package/docs/guides/orchestration.md +0 -28
- 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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
29
|
+
Atomic `POST`s JSON to `<baseUrl><endpointPath>` (`endpointPath` defaults to `"/compact"`; `""` `POST`s directly to `baseUrl`):
|
|
32
30
|
|
|
33
|
-
- **
|
|
34
|
-
- **
|
|
35
|
-
- **
|
|
36
|
-
- **
|
|
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
|
-
|
|
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
|
-
##
|
|
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` |
|
|
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`)
|
|
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.
|
|
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.
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
|
158
|
-
|
|
|
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
|
|
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
|
-
| `
|
|
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 `
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
###
|
|
303
|
+
### Extension hooks for branch summarization {#extension-hooks-for-branch-summarization}
|
|
258
304
|
|
|
259
|
-
|
|
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 [
|
|
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
|
-
|
|
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
|
|