@bastani/atomic 0.8.26-alpha.7 → 0.8.26-alpha.9
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 +18 -0
- package/README.md +5 -8
- package/dist/builtin/intercom/CHANGELOG.md +12 -0
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +12 -0
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +12 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/CHANGELOG.md +12 -0
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +12 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/wiring.ts +13 -1
- package/dist/builtin/workflows/src/runs/foreground/executor.ts +12 -6
- package/dist/builtin/workflows/src/runs/foreground/stage-runner.ts +2 -2
- package/dist/builtin/workflows/src/shared/authoring-contract.d.ts +2 -2
- package/dist/builtin/workflows/src/shared/types.ts +3 -3
- package/dist/builtin/workflows/src/tui/stage-chat-view.ts +1 -9
- package/dist/core/agent-session.d.ts +5 -5
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +64 -173
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/atomic-guide-command.d.ts.map +1 -1
- package/dist/core/atomic-guide-command.js +1 -1
- package/dist/core/atomic-guide-command.js.map +1 -1
- package/dist/core/extensions/types.d.ts +3 -2
- package/dist/core/extensions/types.d.ts.map +1 -1
- package/dist/core/extensions/types.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +1 -1
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +1 -2
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.d.ts.map +1 -1
- package/dist/modes/interactive/components/chat-session-host.js +1 -1
- package/dist/modes/interactive/components/chat-session-host.js.map +1 -1
- package/dist/modes/interactive/components/context-compaction-summary-message.d.ts +17 -0
- package/dist/modes/interactive/components/context-compaction-summary-message.d.ts.map +1 -0
- package/dist/modes/interactive/components/context-compaction-summary-message.js +83 -0
- package/dist/modes/interactive/components/context-compaction-summary-message.js.map +1 -0
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +28 -38
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts +3 -3
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +1 -1
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/modes/rpc/rpc-types.d.ts +2 -2
- package/dist/modes/rpc/rpc-types.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-types.js.map +1 -1
- package/docs/compaction.md +71 -38
- package/docs/extensions.md +9 -5
- package/docs/index.md +17 -3
- package/docs/json.md +2 -2
- package/docs/quickstart.md +18 -4
- package/docs/rpc.md +19 -40
- package/docs/sdk.md +18 -4
- package/docs/session-format.md +3 -3
- package/docs/sessions.md +2 -3
- package/docs/settings.md +2 -2
- package/docs/termux.md +1 -1
- package/docs/usage.md +2 -4
- package/package.json +1 -1
package/docs/compaction.md
CHANGED
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
# Compaction & Branch Summarization
|
|
2
2
|
|
|
3
|
-
LLMs have limited context windows. When conversations grow too long, Atomic uses
|
|
3
|
+
LLMs have limited context windows. When conversations grow too long, Atomic uses a deletion-only form of Context Compaction called **Verbatim Compaction**: it deletes safe older transcript objects while preserving every retained object byte-for-byte. This page covers auto-compaction, manual compaction, and branch summarization.
|
|
4
|
+
|
|
5
|
+
Atomic's default compaction design and terminology are informed by Morph's Context Compaction work: [Morph's Context Compaction](https://www.morphllm.com/context-compaction). In particular, Atomic follows the same core idea that coding agents benefit from deleting low-signal context instead of rewriting high-signal details like file paths, line numbers, and error strings into a lossy summary.
|
|
4
6
|
|
|
5
7
|
**Source files** ([atomic](https://github.com/bastani-inc/atomic)):
|
|
6
8
|
- [`packages/coding-agent/src/core/compaction/compaction.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) - Summary compaction logic
|
|
7
|
-
- [`packages/coding-agent/src/core/compaction/context-compaction.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/compaction/context-compaction.ts) -
|
|
9
|
+
- [`packages/coding-agent/src/core/compaction/context-compaction.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/compaction/context-compaction.ts) - Verbatim context compaction
|
|
8
10
|
- [`packages/coding-agent/src/core/compaction/branch-summarization.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/compaction/branch-summarization.ts) - Branch summarization
|
|
9
11
|
- [`packages/coding-agent/src/core/compaction/utils.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/compaction/utils.ts) - Shared utilities (file tracking, serialization)
|
|
10
|
-
- [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`CompactionEntry`, `BranchSummaryEntry`)
|
|
12
|
+
- [`packages/coding-agent/src/core/session-manager.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/session-manager.ts) - Entry types (`ContextCompactionEntry`, `CompactionEntry`, `BranchSummaryEntry`)
|
|
11
13
|
- [`packages/coding-agent/src/core/extensions/types.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/extensions/types.ts) - Extension event types
|
|
12
14
|
|
|
13
15
|
For TypeScript definitions in your project, inspect `node_modules/@bastani/atomic/dist/`.
|
|
14
16
|
|
|
15
17
|
## Overview
|
|
16
18
|
|
|
17
|
-
Atomic has
|
|
19
|
+
Atomic has three compaction/summarization mechanisms:
|
|
18
20
|
|
|
19
21
|
| Mechanism | Trigger | Purpose |
|
|
20
22
|
|-----------|---------|---------|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
+
| Default context compaction (Verbatim Compaction) | Context exceeds threshold, context overflow, or `/compact` | Delete safe old transcript objects while retaining surviving content verbatim |
|
|
24
|
+
| Summary compaction internals | Core APIs and legacy extension hooks | Summarize old messages into replacement context |
|
|
23
25
|
| Branch summarization | `/tree` navigation | Preserve context when switching branches |
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
`/compact` has no user-facing arguments. It uses a fixed internal prompt, validates model-proposed deletion targets locally, and stores logical deletions in a `context_compaction` entry. Auto-compaction uses the same deletion-only path.
|
|
26
28
|
|
|
27
|
-
## Compaction
|
|
29
|
+
## Default Context Compaction (Verbatim Compaction)
|
|
28
30
|
|
|
29
31
|
### When It Triggers
|
|
30
32
|
|
|
@@ -36,18 +38,66 @@ contextTokens > contextWindow - reserveTokens
|
|
|
36
38
|
|
|
37
39
|
By default, `reserveTokens` is 16384 tokens. Configure it in `~/.atomic/agent/settings.json` or `<project-dir>/.atomic/settings.json`; legacy `.pi` paths are also supported. This leaves room for the LLM's response.
|
|
38
40
|
|
|
39
|
-
You can also trigger manually with `/compact
|
|
41
|
+
You can also trigger manually with `/compact`. Custom summary instructions are no longer accepted because retained transcript content stays verbatim.
|
|
40
42
|
|
|
41
43
|
### How It Works
|
|
42
44
|
|
|
43
|
-
1.
|
|
44
|
-
2.
|
|
45
|
-
3.
|
|
46
|
-
4.
|
|
47
|
-
5.
|
|
45
|
+
1. Build a compactable transcript for the active branch with stable entry IDs and content-block indexes.
|
|
46
|
+
2. Ask the selected model, with a fixed internal prompt, for JSON deletion targets only.
|
|
47
|
+
3. Validate the plan locally: unknown IDs, protected user messages, recent operations, unresolved errors, and tool-call/tool-result orphaning fail closed.
|
|
48
|
+
4. Write a backup snapshot for persisted sessions.
|
|
49
|
+
5. Append a `context_compaction` entry containing validated logical deletion targets and stats.
|
|
50
|
+
6. Rebuild active LLM context by filtering those targets. Retained entries/content blocks are reused unchanged.
|
|
51
|
+
|
|
52
|
+
Tradeoff: compaction performs logical deletion during session rebuild instead of physically rewriting JSONL. The full raw history remains in the session file and backup, while the active LLM context is reduced.
|
|
53
|
+
|
|
54
|
+
### Verbatim Compaction Diagram
|
|
55
|
+
|
|
56
|
+
Unlike legacy summary compaction, Verbatim Compaction does not add a generated summary or rewrite retained messages. It appends a `context_compaction` entry that records exactly which older transcript objects should be hidden from future active context rebuilds.
|
|
48
57
|
|
|
49
58
|
```
|
|
50
|
-
Before compaction:
|
|
59
|
+
Before verbatim compaction:
|
|
60
|
+
|
|
61
|
+
entry: 0 1 2 3 4 5 6 7
|
|
62
|
+
┌─────┬─────┬─────┬──────┬─────┬──────┬──────┬─────┐
|
|
63
|
+
│ hdr │ usr │ ass │ tool │ usr │ ass │ tool │ ass │
|
|
64
|
+
└─────┴─────┴─────┴──────┴─────┴──────┴──────┴─────┘
|
|
65
|
+
│ │ │ │
|
|
66
|
+
└──────┴────────────┴──────┘
|
|
67
|
+
planner may mark low-signal old objects
|
|
68
|
+
|
|
69
|
+
Validated deletion plan:
|
|
70
|
+
|
|
71
|
+
delete entry 2 (older assistant text)
|
|
72
|
+
delete entry 3 (superseded tool output)
|
|
73
|
+
keep entries 0,1,4,5,6,7 unchanged
|
|
74
|
+
|
|
75
|
+
After compaction (new entry appended; JSONL remains append-only):
|
|
76
|
+
|
|
77
|
+
entry: 0 1 2 3 4 5 6 7 8
|
|
78
|
+
┌─────┬─────┬─────┬──────┬─────┬──────┬──────┬─────┬─────┐
|
|
79
|
+
│ hdr │ usr │ ass │ tool │ usr │ ass │ tool │ ass │ ctx │
|
|
80
|
+
└─────┴─────┴─────┴──────┴─────┴──────┴──────┴─────┴─────┘
|
|
81
|
+
╳ ╳ ↑
|
|
82
|
+
logical deletions context_compaction entry
|
|
83
|
+
|
|
84
|
+
What the LLM sees after rebuild:
|
|
85
|
+
|
|
86
|
+
┌────────┬─────┬─────┬──────┬──────┬─────┐
|
|
87
|
+
│ system │ usr │ usr │ ass │ tool │ ass │
|
|
88
|
+
└────────┴─────┴─────┴──────┴──────┴─────┘
|
|
89
|
+
entry 1 entry 4 entry 5 entry 6 entry 7
|
|
90
|
+
|
|
91
|
+
No generated summary is inserted. Every surviving entry/content block is reused
|
|
92
|
+
verbatim; deleted objects are simply omitted from the active LLM context.
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Summary Compaction Internals
|
|
96
|
+
|
|
97
|
+
The older summarization pipeline still exists in the core compaction module and for legacy extension hook types, but `/compact` and auto-compaction no longer use it by default.
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Before summary compaction:
|
|
51
101
|
|
|
52
102
|
entry: 0 1 2 3 4 5 6 7 8 9
|
|
53
103
|
┌─────┬─────┬─────┬─────┬──────┬─────┬─────┬──────┬──────┬─────┐
|
|
@@ -80,23 +130,6 @@ What the LLM sees:
|
|
|
80
130
|
|
|
81
131
|
On repeated compactions, the summarized span starts at the previous compaction's kept boundary (`firstKeptEntryId`), not at the compaction entry itself, falling back to the entry after the previous compaction if that kept entry cannot be found in the path. This preserves messages that survived the earlier compaction by including them in the next summarization pass as well. Atomic also recalculates `tokensBefore` from the rebuilt session context before writing the new `CompactionEntry`, so the token count reflects the actual pre-compaction context being replaced.
|
|
82
132
|
|
|
83
|
-
## Context Compaction (`/context-compact`)
|
|
84
|
-
|
|
85
|
-
`/context-compact` is a fixed no-argument command for deletion-only compaction. Unlike `/compact [prompt]`, it never accepts custom instructions and never asks the model to write replacement context.
|
|
86
|
-
|
|
87
|
-
How it works in this first iteration:
|
|
88
|
-
|
|
89
|
-
1. Build a compactable transcript for the active branch with stable entry IDs and content-block indexes.
|
|
90
|
-
2. Ask the selected model, with a fixed internal prompt, for JSON deletion targets only.
|
|
91
|
-
3. Validate the plan locally: unknown IDs, protected user messages, recent operations, unresolved errors, and tool-call/tool-result orphaning fail closed.
|
|
92
|
-
4. Write a backup snapshot for persisted sessions.
|
|
93
|
-
5. Append a `context_compaction` entry containing validated logical deletion targets and stats.
|
|
94
|
-
6. Rebuild active LLM context by filtering those targets. Retained entries/content blocks are reused unchanged.
|
|
95
|
-
|
|
96
|
-
`/context-compact anything` is invalid in the main interactive UI and trailing text is not treated as a prompt. Workflow-stage chat consumes extra text without invoking compaction so it is not sent to the model.
|
|
97
|
-
|
|
98
|
-
Tradeoff: this iteration performs logical deletion during session rebuild instead of physically rewriting JSONL. The full raw history remains in the session file and backup, while the active LLM context is reduced.
|
|
99
|
-
|
|
100
133
|
### Split Turns
|
|
101
134
|
|
|
102
135
|
A "turn" starts with a user message and includes all assistant responses and tool calls until the next user message. Normally, compaction cuts at turn boundaries.
|
|
@@ -152,14 +185,14 @@ interface CompactionEntry<T = unknown> {
|
|
|
152
185
|
details?: T; // implementation-specific data
|
|
153
186
|
}
|
|
154
187
|
|
|
155
|
-
//
|
|
188
|
+
// Legacy summary compaction uses this for details (from compaction.ts):
|
|
156
189
|
interface CompactionDetails {
|
|
157
190
|
readFiles: string[];
|
|
158
191
|
modifiedFiles: string[];
|
|
159
192
|
}
|
|
160
193
|
```
|
|
161
194
|
|
|
162
|
-
Extensions can store any JSON-serializable data in `details`. The
|
|
195
|
+
Extensions can store any JSON-serializable data in `details`. The legacy summary compaction pipeline tracks file operations, but custom extension implementations can use their own structure.
|
|
163
196
|
|
|
164
197
|
See [`prepareCompaction()`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) and [`compact()`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/compaction/compaction.ts) for the implementation.
|
|
165
198
|
|
|
@@ -287,11 +320,11 @@ Tool results are truncated to 2000 characters during serialization. Content beyo
|
|
|
287
320
|
|
|
288
321
|
## Custom Summarization via Extensions
|
|
289
322
|
|
|
290
|
-
Extensions can
|
|
323
|
+
Extensions can still customize the legacy summary compaction pipeline and branch summarization. Default `/compact` and auto-compaction use deletion-only context compaction and do not call summary customization hooks. See [`extensions/types.ts`](https://github.com/bastani-inc/atomic/blob/main/packages/coding-agent/src/core/extensions/types.ts) for event type definitions.
|
|
291
324
|
|
|
292
325
|
### session_before_compact
|
|
293
326
|
|
|
294
|
-
Fired before
|
|
327
|
+
Fired before legacy summary compaction. Can cancel or provide custom summary. See `SessionBeforeCompactEvent` and `CompactionPreparation` in the types file.
|
|
295
328
|
|
|
296
329
|
```typescript
|
|
297
330
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
@@ -406,8 +439,8 @@ Configure compaction in `~/.atomic/agent/settings.json` or `<project-dir>/.atomi
|
|
|
406
439
|
|
|
407
440
|
| Setting | Default | Description |
|
|
408
441
|
|---------|---------|-------------|
|
|
409
|
-
| `enabled` | `true` | Enable
|
|
442
|
+
| `enabled` | `true` | Enable automatic Verbatim Compaction |
|
|
410
443
|
| `reserveTokens` | `16384` | Tokens to reserve for LLM response |
|
|
411
|
-
| `keepRecentTokens` | `20000` | Recent tokens to
|
|
444
|
+
| `keepRecentTokens` | `20000` | Recent tokens to protect from deletion |
|
|
412
445
|
|
|
413
446
|
Disable auto-compaction with `"enabled": false`. You can still compact manually with `/compact`.
|
package/docs/extensions.md
CHANGED
|
@@ -322,6 +322,9 @@ user sends another prompt ◄─────────────────
|
|
|
322
322
|
└─► resources_discover { reason: "startup" }
|
|
323
323
|
|
|
324
324
|
/compact or auto-compaction
|
|
325
|
+
└─► compaction_start / compaction_end (deletion-only context compaction)
|
|
326
|
+
|
|
327
|
+
legacy summary compaction APIs
|
|
325
328
|
├─► session_before_compact (can cancel or customize)
|
|
326
329
|
└─► session_compact
|
|
327
330
|
|
|
@@ -413,7 +416,7 @@ Do cleanup work in `session_shutdown`, then reestablish any in-memory state in `
|
|
|
413
416
|
|
|
414
417
|
#### session_before_compact / session_compact
|
|
415
418
|
|
|
416
|
-
Fired on compaction. See [Compaction](/compaction) for details.
|
|
419
|
+
Fired by the legacy summary compaction pipeline. `/compact` and auto-compaction now use deletion-only context compaction by default, so extensions should not rely on these events for default compaction. See [Compaction](/compaction) for details.
|
|
417
420
|
|
|
418
421
|
```typescript
|
|
419
422
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
@@ -947,13 +950,12 @@ if (usage && usage.tokens > 100_000) {
|
|
|
947
950
|
|
|
948
951
|
### ctx.compact()
|
|
949
952
|
|
|
950
|
-
Trigger
|
|
953
|
+
Trigger Atomic's default Verbatim Compaction without awaiting completion. This is deletion-only Context Compaction: retained transcript content stays unchanged, and older low-signal objects are omitted by validated logical deletion. The approach is informed by Morph's Context Compaction write-up: [Morph's Context Compaction](https://www.morphllm.com/context-compaction). Use `onComplete` and `onError` for follow-up actions.
|
|
951
954
|
|
|
952
955
|
```typescript
|
|
953
956
|
ctx.compact({
|
|
954
|
-
customInstructions: "Focus on recent changes",
|
|
955
957
|
onComplete: (result) => {
|
|
956
|
-
ctx.ui.notify(
|
|
958
|
+
ctx.ui.notify(`Compaction deleted ${result.stats.objectsDeleted} objects`, "info");
|
|
957
959
|
},
|
|
958
960
|
onError: (error) => {
|
|
959
961
|
ctx.ui.notify(`Compaction failed: ${error.message}`, "error");
|
|
@@ -961,6 +963,8 @@ ctx.compact({
|
|
|
961
963
|
});
|
|
962
964
|
```
|
|
963
965
|
|
|
966
|
+
`customInstructions` is deprecated and ignored for default compaction because Verbatim Compaction never asks the model to write a custom summary.
|
|
967
|
+
|
|
964
968
|
### ctx.getSystemPrompt()
|
|
965
969
|
|
|
966
970
|
Returns Atomic's current system prompt string.
|
|
@@ -2568,7 +2572,7 @@ All examples in [examples/extensions/](https://github.com/bastani-inc/atomic/tre
|
|
|
2568
2572
|
| `prompt-customizer.ts` | Add context-aware tool guidance using `systemPromptOptions` | `on("before_agent_start")`, `BuildSystemPromptOptions` |
|
|
2569
2573
|
| `file-trigger.ts` | File watcher triggers messages | `sendMessage` |
|
|
2570
2574
|
| **Compaction & Sessions** |||
|
|
2571
|
-
| `custom-compaction.ts` |
|
|
2575
|
+
| `custom-compaction.ts` | Legacy custom compaction summary | `on("session_before_compact")` |
|
|
2572
2576
|
| `trigger-compact.ts` | Trigger compaction manually | `compact()` |
|
|
2573
2577
|
| `git-checkpoint.ts` | Git stash on turns | `on("turn_start")`, `on("session_before_fork")`, `exec` |
|
|
2574
2578
|
| `auto-commit-on-exit.ts` | Commit on shutdown | `on("session_shutdown")`, `exec` |
|
package/docs/index.md
CHANGED
|
@@ -9,10 +9,24 @@ Atomic is a minimal terminal coding harness. It is designed to stay small at the
|
|
|
9
9
|
|
|
10
10
|
## Quick start
|
|
11
11
|
|
|
12
|
-
Install Atomic with Bun:
|
|
12
|
+
Install Atomic globally with npm, pnpm, or Bun:
|
|
13
|
+
|
|
14
|
+
With npm:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @bastani/atomic
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
With pnpm:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pnpm add -g @bastani/atomic
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
With Bun:
|
|
13
27
|
|
|
14
28
|
```bash
|
|
15
|
-
bun
|
|
29
|
+
bun add -g @bastani/atomic
|
|
16
30
|
```
|
|
17
31
|
|
|
18
32
|
Atomic does not require package install scripts. If you want to disable dependency lifecycle scripts during the Atomic install, you can add `--ignore-scripts` to the install command.
|
|
@@ -37,7 +51,7 @@ For the full first-run flow, see [Quickstart](/quickstart).
|
|
|
37
51
|
- [Settings](/settings) - global and project settings.
|
|
38
52
|
- [Keybindings](/keybindings) - default shortcuts and custom keybindings.
|
|
39
53
|
- [Sessions](/sessions) - session management, branching, and tree navigation.
|
|
40
|
-
- [Compaction](/compaction) - context
|
|
54
|
+
- [Compaction](/compaction) - Verbatim Compaction, context management, and branch summarization.
|
|
41
55
|
|
|
42
56
|
## Customization
|
|
43
57
|
|
package/docs/json.md
CHANGED
|
@@ -18,12 +18,12 @@ type AgentSessionEvent =
|
|
|
18
18
|
| { type: "session_info_changed"; name: string | undefined }
|
|
19
19
|
| { type: "model_changed"; model: Model<Api>; previousModel: Model<Api> | undefined; source: "set" | "cycle" | "restore" }
|
|
20
20
|
| { type: "thinking_level_changed"; level: ThinkingLevel }
|
|
21
|
-
| { type: "compaction_end"; reason: "manual" | "threshold" | "overflow"; result:
|
|
21
|
+
| { type: "compaction_end"; reason: "manual" | "threshold" | "overflow"; result: ContextCompactionResult | undefined; aborted: boolean; willRetry: boolean; errorMessage?: string }
|
|
22
22
|
| { type: "auto_retry_start"; attempt: number; maxAttempts: number; delayMs: number; errorMessage: string }
|
|
23
23
|
| { type: "auto_retry_end"; success: boolean; attempt: number; finalError?: string };
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
`queue_update` emits the full pending steering and follow-up queues whenever they change. `session_info_changed`, `model_changed`, and `thinking_level_changed` report interactive session metadata changes. `compaction_start` and `compaction_end` cover both manual and automatic compaction.
|
|
26
|
+
`queue_update` emits the full pending steering and follow-up queues whenever they change. `session_info_changed`, `model_changed`, and `thinking_level_changed` report interactive session metadata changes. `compaction_start` and `compaction_end` cover both manual and automatic Verbatim Compaction, Atomic's deletion-only Context Compaction approach inspired by [Morph's Context Compaction](https://www.morphllm.com/context-compaction).
|
|
27
27
|
|
|
28
28
|
Base events come from `AgentEvent` in `@earendil-works/pi-agent-core` (installed as an Atomic dependency):
|
|
29
29
|
|
package/docs/quickstart.md
CHANGED
|
@@ -4,16 +4,30 @@ This page gets you from install to a useful first Atomic session.
|
|
|
4
4
|
|
|
5
5
|
## Prerequisites
|
|
6
6
|
|
|
7
|
-
- **Node.js
|
|
8
|
-
- **
|
|
7
|
+
- **Node.js 24 LTS or newer** — Atomic requires the latest Node LTS runtime. Check with `node --version`.
|
|
8
|
+
- **A package manager** — use npm (included with Node), pnpm, Yarn, or Bun. Use Bun 1.3.14+ for Bun installs or workflow-authoring examples.
|
|
9
9
|
- **Model-provider access** — Use `/login` after startup. Supports provider subscriptions and APIs.
|
|
10
10
|
|
|
11
11
|
## Install
|
|
12
12
|
|
|
13
|
-
Install the published package with Bun:
|
|
13
|
+
Install the published package globally with npm, pnpm, or Bun:
|
|
14
|
+
|
|
15
|
+
With npm:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g @bastani/atomic
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
With pnpm:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add -g @bastani/atomic
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
With Bun:
|
|
14
28
|
|
|
15
29
|
```bash
|
|
16
|
-
bun
|
|
30
|
+
bun add -g @bastani/atomic
|
|
17
31
|
```
|
|
18
32
|
|
|
19
33
|
Atomic does not require package install scripts. If you want to disable dependency lifecycle scripts during the Atomic install, you can add `--ignore-scripts` to the install command.
|
package/docs/rpc.md
CHANGED
|
@@ -352,46 +352,18 @@ Response:
|
|
|
352
352
|
|
|
353
353
|
#### compact
|
|
354
354
|
|
|
355
|
-
|
|
355
|
+
Run Atomic's default Verbatim Compaction to reduce token usage. This command has no prompt/config fields; send no custom instructions. Atomic asks the selected model for deletion targets using a fixed internal prompt, validates them, appends a `context_compaction` entry, and rebuilds active context with surviving entries/content blocks reused verbatim. This deletion-only Context Compaction approach is informed by Morph's article: [Morph's Context Compaction](https://www.morphllm.com/context-compaction).
|
|
356
356
|
|
|
357
357
|
```json
|
|
358
358
|
{"type": "compact"}
|
|
359
359
|
```
|
|
360
360
|
|
|
361
|
-
With custom instructions:
|
|
362
|
-
```json
|
|
363
|
-
{"type": "compact", "customInstructions": "Focus on code changes"}
|
|
364
|
-
```
|
|
365
|
-
|
|
366
361
|
Response:
|
|
367
362
|
```json
|
|
368
363
|
{
|
|
369
364
|
"type": "response",
|
|
370
365
|
"command": "compact",
|
|
371
366
|
"success": true,
|
|
372
|
-
"data": {
|
|
373
|
-
"summary": "Summary of conversation...",
|
|
374
|
-
"firstKeptEntryId": "abc123",
|
|
375
|
-
"tokensBefore": 150000,
|
|
376
|
-
"details": {}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
```
|
|
380
|
-
|
|
381
|
-
#### context_compact
|
|
382
|
-
|
|
383
|
-
Run deletion-only context compaction. This command has no prompt/config fields; send no custom instructions. Atomic asks the selected model for deletion targets using a fixed internal prompt, validates them, appends a `context_compaction` entry, and rebuilds active context.
|
|
384
|
-
|
|
385
|
-
```json
|
|
386
|
-
{"type": "context_compact"}
|
|
387
|
-
```
|
|
388
|
-
|
|
389
|
-
Response:
|
|
390
|
-
```json
|
|
391
|
-
{
|
|
392
|
-
"type": "response",
|
|
393
|
-
"command": "context_compact",
|
|
394
|
-
"success": true,
|
|
395
367
|
"data": {
|
|
396
368
|
"promptVersion": 1,
|
|
397
369
|
"deletedTargets": [{ "kind": "entry", "entryId": "abc123" }],
|
|
@@ -404,7 +376,7 @@ Response:
|
|
|
404
376
|
"tokensAfter": 120000,
|
|
405
377
|
"percentReduction": 20
|
|
406
378
|
},
|
|
407
|
-
"backupPath": "/path/to/session.jsonl.2026-06-06T00-00-00-000Z.
|
|
379
|
+
"backupPath": "/path/to/session.jsonl.2026-06-06T00-00-00-000Z.compact.bak"
|
|
408
380
|
}
|
|
409
381
|
}
|
|
410
382
|
```
|
|
@@ -787,10 +759,10 @@ Events are streamed to stdout as JSON lines during agent operation. Events do NO
|
|
|
787
759
|
| `tool_execution_update` | Tool execution progress (streaming output) |
|
|
788
760
|
| `tool_execution_end` | Tool completes |
|
|
789
761
|
| `queue_update` | Pending steering/follow-up queue changed |
|
|
790
|
-
| `compaction_start` |
|
|
791
|
-
| `compaction_end` |
|
|
792
|
-
| `context_compaction_start` |
|
|
793
|
-
| `context_compaction_end` |
|
|
762
|
+
| `compaction_start` | Default Verbatim Compaction begins |
|
|
763
|
+
| `compaction_end` | Default Verbatim Compaction completes |
|
|
764
|
+
| `context_compaction_start` | Legacy context-compaction RPC begins |
|
|
765
|
+
| `context_compaction_end` | Legacy context-compaction RPC completes |
|
|
794
766
|
| `auto_retry_start` | Auto-retry begins (after transient error) |
|
|
795
767
|
| `auto_retry_end` | Auto-retry completes (success or final failure) |
|
|
796
768
|
| `extension_error` | Extension threw an error |
|
|
@@ -940,7 +912,7 @@ Emitted whenever the pending steering or follow-up queue changes.
|
|
|
940
912
|
|
|
941
913
|
### compaction_start / compaction_end
|
|
942
914
|
|
|
943
|
-
Emitted when
|
|
915
|
+
Emitted when default Verbatim Compaction runs, whether manual or automatic. The result records deletion targets and stats rather than a generated summary.
|
|
944
916
|
|
|
945
917
|
```json
|
|
946
918
|
{"type": "compaction_start", "reason": "threshold"}
|
|
@@ -953,10 +925,17 @@ The `reason` field is `"manual"`, `"threshold"`, or `"overflow"`.
|
|
|
953
925
|
"type": "compaction_end",
|
|
954
926
|
"reason": "threshold",
|
|
955
927
|
"result": {
|
|
956
|
-
"
|
|
957
|
-
"
|
|
958
|
-
"
|
|
959
|
-
"
|
|
928
|
+
"promptVersion": 1,
|
|
929
|
+
"deletedTargets": [{ "kind": "entry", "entryId": "abc123" }],
|
|
930
|
+
"protectedEntryIds": ["user-task-entry"],
|
|
931
|
+
"stats": {
|
|
932
|
+
"objectsBefore": 20,
|
|
933
|
+
"objectsAfter": 19,
|
|
934
|
+
"objectsDeleted": 1,
|
|
935
|
+
"tokensBefore": 150000,
|
|
936
|
+
"tokensAfter": 120000,
|
|
937
|
+
"percentReduction": 20
|
|
938
|
+
}
|
|
960
939
|
},
|
|
961
940
|
"aborted": false,
|
|
962
941
|
"willRetry": false
|
|
@@ -971,7 +950,7 @@ If compaction failed (e.g., API quota exceeded), `result` is `null`, `aborted` i
|
|
|
971
950
|
|
|
972
951
|
### context_compaction_start / context_compaction_end
|
|
973
952
|
|
|
974
|
-
|
|
953
|
+
Legacy RPC `context_compact` emits these events. The result contains `deletedTargets`, `protectedEntryIds`, `stats`, `promptVersion`, and optional `backupPath`.
|
|
975
954
|
|
|
976
955
|
### auto_retry_start / auto_retry_end
|
|
977
956
|
|
package/docs/sdk.md
CHANGED
|
@@ -39,7 +39,21 @@ await session.prompt("What files are in the current directory?");
|
|
|
39
39
|
|
|
40
40
|
## Installation
|
|
41
41
|
|
|
42
|
-
Install
|
|
42
|
+
Install `@bastani/atomic` as a project dependency with npm, pnpm, or Bun:
|
|
43
|
+
|
|
44
|
+
With npm:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install @bastani/atomic
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
With pnpm:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm add @bastani/atomic
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
With Bun:
|
|
43
57
|
|
|
44
58
|
```bash
|
|
45
59
|
bun add @bastani/atomic
|
|
@@ -47,7 +61,7 @@ bun add @bastani/atomic
|
|
|
47
61
|
|
|
48
62
|
Atomic does not require package install scripts. If you want to disable dependency lifecycle scripts during the Atomic install, you can add `--ignore-scripts` to the install command.
|
|
49
63
|
|
|
50
|
-
The SDK is included in the main package. No separate
|
|
64
|
+
The SDK is included in the main package. No separate SDK package is needed.
|
|
51
65
|
|
|
52
66
|
## Core Concepts
|
|
53
67
|
|
|
@@ -109,8 +123,8 @@ interface AgentSession {
|
|
|
109
123
|
// In-place tree navigation within the current session file
|
|
110
124
|
navigateTree(targetId: string, options?: { summarize?: boolean; customInstructions?: string; replaceInstructions?: boolean; label?: string }): Promise<{ editorText?: string; cancelled: boolean }>;
|
|
111
125
|
|
|
112
|
-
// Compaction
|
|
113
|
-
compact(
|
|
126
|
+
// Verbatim Compaction (deletion-only Context Compaction)
|
|
127
|
+
compact(): Promise<ContextCompactionResult>;
|
|
114
128
|
abortCompaction(): void;
|
|
115
129
|
|
|
116
130
|
// Abort current operation
|
package/docs/session-format.md
CHANGED
|
@@ -223,7 +223,7 @@ Emitted when the user changes the thinking/reasoning level.
|
|
|
223
223
|
|
|
224
224
|
### CompactionEntry
|
|
225
225
|
|
|
226
|
-
|
|
226
|
+
Legacy summary-compaction entry. Stores a generated summary of earlier messages for older APIs and extension hooks. Default `/compact` and auto-compaction now create `ContextCompactionEntry` records instead.
|
|
227
227
|
|
|
228
228
|
```json
|
|
229
229
|
{"type":"compaction","id":"f6g7h8i9","parentId":"e5f6g7h8","timestamp":"2024-12-03T14:10:00.000Z","summary":"User discussed X, Y, Z...","firstKeptEntryId":"c3d4e5f6","tokensBefore":50000}
|
|
@@ -235,10 +235,10 @@ Optional fields:
|
|
|
235
235
|
|
|
236
236
|
### ContextCompactionEntry
|
|
237
237
|
|
|
238
|
-
Created by `/
|
|
238
|
+
Created by `/compact` and auto-compaction. Stores Atomic's default **Verbatim Compaction** data: validated logical deletion targets, not replacement text. During `buildSessionContext()`, matching entries/content blocks are filtered from active LLM context while retained content remains verbatim. This deletion-only Context Compaction approach is informed by Morph's write-up at [Morph's Context Compaction](https://www.morphllm.com/context-compaction).
|
|
239
239
|
|
|
240
240
|
```json
|
|
241
|
-
{"type":"context_compaction","id":"ctx12345","parentId":"f6g7h8i9","timestamp":"2024-12-03T14:12:00.000Z","promptVersion":1,"deletedTargets":[{"kind":"entry","entryId":"b2c3d4e5"}],"protectedEntryIds":["a1b2c3d4"],"stats":{"objectsBefore":20,"objectsAfter":19,"objectsDeleted":1,"tokensBefore":50000,"tokensAfter":43000,"percentReduction":14},"backupPath":"/path/session.jsonl.2024-12-03T14-12-00-000Z.
|
|
241
|
+
{"type":"context_compaction","id":"ctx12345","parentId":"f6g7h8i9","timestamp":"2024-12-03T14:12:00.000Z","promptVersion":1,"deletedTargets":[{"kind":"entry","entryId":"b2c3d4e5"}],"protectedEntryIds":["a1b2c3d4"],"stats":{"objectsBefore":20,"objectsAfter":19,"objectsDeleted":1,"tokensBefore":50000,"tokensAfter":43000,"percentReduction":14},"backupPath":"/path/session.jsonl.2024-12-03T14-12-00-000Z.compact.bak"}
|
|
242
242
|
```
|
|
243
243
|
|
|
244
244
|
`deletedTargets` entries are either whole entries (`{ kind: "entry", entryId }`) or content blocks (`{ kind: "content_block", entryId, blockIndex }`). The JSONL file remains append-only; this is logical deletion for active context rebuild.
|
package/docs/sessions.md
CHANGED
|
@@ -29,8 +29,7 @@ For the JSONL file format and SessionManager API, see [Session Format](/session-
|
|
|
29
29
|
| `/tree` | Navigate the current session tree |
|
|
30
30
|
| `/fork` | Create a new session from a previous user message |
|
|
31
31
|
| `/clone` | Duplicate the current active branch into a new session |
|
|
32
|
-
| `/compact
|
|
33
|
-
| `/context-compact` | Apply validated deletion-only logical compaction; no arguments |
|
|
32
|
+
| `/compact` | Apply Verbatim Compaction with validated logical deletions; see [Compaction](/compaction) |
|
|
34
33
|
| `/export [file]` | Export session to HTML |
|
|
35
34
|
| `/share` | Upload as private GitHub gist with shareable HTML link |
|
|
36
35
|
|
|
@@ -129,7 +128,7 @@ When prompted, choose one of:
|
|
|
129
128
|
2. summarize with the default prompt
|
|
130
129
|
3. summarize with custom focus instructions
|
|
131
130
|
|
|
132
|
-
See [Compaction](/compaction) for branch summarization internals and extension hooks.
|
|
131
|
+
See [Compaction](/compaction) for Verbatim Compaction, branch summarization internals, and extension hooks.
|
|
133
132
|
|
|
134
133
|
## Session Format
|
|
135
134
|
|
package/docs/settings.md
CHANGED
|
@@ -90,9 +90,9 @@ Set `ATOMIC_SKIP_VERSION_CHECK=1` to disable the Atomic version update check. Us
|
|
|
90
90
|
|
|
91
91
|
| Setting | Type | Default | Description |
|
|
92
92
|
|---------|------|---------|-------------|
|
|
93
|
-
| `compaction.enabled` | boolean | `true` | Enable
|
|
93
|
+
| `compaction.enabled` | boolean | `true` | Enable automatic Verbatim Compaction |
|
|
94
94
|
| `compaction.reserveTokens` | number | `16384` | Tokens reserved for LLM response |
|
|
95
|
-
| `compaction.keepRecentTokens` | number | `20000` | Recent tokens to
|
|
95
|
+
| `compaction.keepRecentTokens` | number | `20000` | Recent tokens to protect from deletion |
|
|
96
96
|
|
|
97
97
|
```json
|
|
98
98
|
{
|
package/docs/termux.md
CHANGED
|
@@ -20,7 +20,7 @@ pkg install nodejs termux-api git
|
|
|
20
20
|
npm install -g @bastani/atomic
|
|
21
21
|
|
|
22
22
|
# If you have installed Bun separately in Termux, you can use Bun instead:
|
|
23
|
-
# bun
|
|
23
|
+
# bun add -g @bastani/atomic
|
|
24
24
|
|
|
25
25
|
# Create config directory
|
|
26
26
|
mkdir -p ~/.atomic/agent
|
package/docs/usage.md
CHANGED
|
@@ -48,8 +48,7 @@ Type `/` in the editor to open command completion. Extensions can register custo
|
|
|
48
48
|
| `/tree` | Jump to any point in the session and continue from there |
|
|
49
49
|
| `/fork` | Create a new session from a previous user message |
|
|
50
50
|
| `/clone` | Duplicate the current active branch into a new session |
|
|
51
|
-
| `/compact
|
|
52
|
-
| `/context-compact` | Delete safe older transcript objects verbatim; no arguments |
|
|
51
|
+
| `/compact` | Run Verbatim Compaction by deleting safe older transcript objects |
|
|
53
52
|
| `/copy` | Copy last assistant message to clipboard |
|
|
54
53
|
| `/export [file]` | Export session to HTML |
|
|
55
54
|
| `/share` | Upload as private GitHub gist with shareable HTML link |
|
|
@@ -90,8 +89,7 @@ Useful session commands:
|
|
|
90
89
|
- `/tree` navigates the in-file session tree and can summarize abandoned branches.
|
|
91
90
|
- `/fork` creates a new session from an earlier user message.
|
|
92
91
|
- `/clone` duplicates the current active branch into a new session file.
|
|
93
|
-
- `/compact`
|
|
94
|
-
- `/context-compact` uses a fixed no-argument deletion-only planner and applies only validated logical deletions; trailing text is not used as a prompt.
|
|
92
|
+
- `/compact` uses Verbatim Compaction: a fixed no-argument deletion-only planner applies only validated logical deletions; retained transcript content stays verbatim. Atomic's approach is informed by Morph's Context Compaction article: [Morph's Context Compaction](https://www.morphllm.com/context-compaction).
|
|
95
93
|
|
|
96
94
|
See [Sessions](/sessions) and [Compaction](/compaction) for details.
|
|
97
95
|
|