somora 2026.1001.4 → 2026.1007.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -24
- package/config.example.yaml +37 -1
- package/docs/agents.md +714 -584
- package/docs/api.md +2327 -2546
- package/docs/browser.md +450 -265
- package/docs/builder.md +408 -282
- package/docs/cache-strategy.md +249 -301
- package/docs/compaction.md +378 -232
- package/docs/display.md +363 -130
- package/docs/dream-phases.md +598 -789
- package/docs/files.md +509 -333
- package/docs/imagegen.md +421 -302
- package/docs/images/somora-hero.png +0 -0
- package/docs/index.md +139 -174
- package/docs/lsp.md +142 -60
- package/docs/mcp.md +365 -273
- package/docs/memory.md +315 -356
- package/docs/mobile.md +283 -282
- package/docs/models.md +440 -197
- package/docs/projects.md +297 -316
- package/docs/realtime-voice.md +358 -234
- package/docs/resources.md +268 -176
- package/docs/sampling.md +141 -78
- package/docs/security.md +413 -169
- package/docs/sentinel.md +268 -208
- package/docs/setup.md +786 -1115
- package/docs/skills.md +415 -430
- package/docs/team.md +268 -143
- package/docs/thinking.md +415 -387
- package/docs/tmux.md +384 -334
- package/docs/tools.md +492 -109
- package/docs/videogen.md +319 -146
- package/docs/voice.md +335 -220
- package/docs/web.md +633 -835
- package/docs/wiki.md +442 -482
- package/package.json +2 -1
- package/src/attachments/store.ts +19 -1
- package/src/browser/session.ts +2 -2
- package/src/cli/auth.ts +22 -0
- package/src/cli/banner.ts +56 -0
- package/src/cli/claude-bin.ts +48 -0
- package/src/cli/config.ts +47 -0
- package/src/cli/server-call.ts +65 -0
- package/src/cli/setup.ts +26 -8
- package/src/cli/somora.ts +36 -4
- package/src/cli/team.ts +13 -6
- package/src/cli/tui/api.ts +44 -2
- package/src/cli/tui/app.tsx +77 -8
- package/src/cli/tui/commands.ts +111 -14
- package/src/cli/tui/header.tsx +20 -0
- package/src/cli/tui/stream.ts +3 -0
- package/src/cli/tui/turn-views.tsx +22 -0
- package/src/cli/tui/types.ts +14 -3
- package/src/compaction/summarize.ts +12 -3
- package/src/compaction/template.ts +15 -0
- package/src/compaction/types.ts +3 -0
- package/src/config/loader.ts +75 -10
- package/src/config/types.ts +59 -20
- package/src/dream/deep-llm.ts +83 -3
- package/src/dream/deep-runner.ts +8 -2
- package/src/dream/deep-worker.ts +1 -0
- package/src/dream/lucid-runner.ts +7 -3
- package/src/dream/lucid-types.ts +3 -0
- package/src/dream/rem-extract.ts +99 -69
- package/src/dream/worker-model.ts +31 -0
- package/src/engine/a2a.ts +1 -1
- package/src/engine/claude-cli.ts +136 -4
- package/src/engine/codex-cli.ts +74 -0
- package/src/engine/engine-meta-labels.ts +2 -0
- package/src/engine/openai-compatible.ts +142 -29
- package/src/engine/types.ts +7 -0
- package/src/imagegen/generate.ts +30 -5
- package/src/imagegen/types.ts +6 -0
- package/src/media/capabilities.ts +8 -0
- package/src/memory/inject.ts +66 -7
- package/src/multimodal/blocks.ts +14 -0
- package/src/multimodal/load.ts +21 -2
- package/src/multimodal/model-image.ts +127 -0
- package/src/persona/loader.ts +2 -2
- package/src/server/index.ts +275 -62
- package/src/server/restart-intent.ts +138 -0
- package/src/server/restart-reconcile.ts +6 -2
- package/src/server/run-turn.ts +66 -17
- package/src/server/session-compact.ts +138 -0
- package/src/server/thinking-resolve.ts +30 -0
- package/src/server/turn-origin-kind.ts +2 -2
- package/src/ssh/exec.ts +55 -22
- package/src/ssh/known-hosts.ts +17 -2
- package/src/ssh/pool.ts +7 -1
- package/src/storage/sessions.ts +40 -15
- package/src/tools/dream/tools.ts +2 -2
- package/src/tools/exec/tools.ts +19 -2
- package/src/tools/file/analyze.ts +46 -7
- package/src/tools/file/remote.ts +31 -10
- package/src/tools/file/tools.ts +86 -19
- package/src/tools/image/tools.ts +6 -0
- package/src/tools/registry.ts +14 -0
- package/src/types/events.ts +25 -4
- package/src/types/turn-origin.ts +6 -2
- package/web/dist/apple-touch-icon.png +0 -0
- package/web/dist/assets/{index-CrkkIfd9.js → index-40x__Izy.js} +168 -163
- package/web/dist/assets/index-40x__Izy.js.map +1 -0
- package/web/dist/assets/index-CZFgQRsq.css +32 -0
- package/web/dist/favicon-48.png +0 -0
- package/web/dist/favicon.ico +0 -0
- package/web/dist/favicon.svg +1 -8
- package/web/dist/index.html +6 -2
- package/web-mobile/dist/apple-touch-icon.png +0 -0
- package/web-mobile/dist/assets/index-CxILeHfe.js +88 -0
- package/web-mobile/dist/assets/index-CxILeHfe.js.map +1 -0
- package/web-mobile/dist/assets/index-Cyr13VGR.css +1 -0
- package/web-mobile/dist/favicon-48.png +0 -0
- package/web-mobile/dist/favicon.ico +0 -0
- package/web-mobile/dist/favicon.svg +1 -8
- package/web-mobile/dist/icon-192.png +0 -0
- package/web-mobile/dist/icon-512.png +0 -0
- package/web-mobile/dist/index.html +5 -3
- package/web-mobile/dist/manifest.webmanifest +2 -2
- package/web/dist/assets/index-BA5mmiV0.css +0 -32
- package/web/dist/assets/index-CrkkIfd9.js.map +0 -1
- package/web-mobile/dist/assets/index-BqKt7IMx.css +0 -1
- package/web-mobile/dist/assets/index-X_vRr6cd.js +0 -88
- package/web-mobile/dist/assets/index-X_vRr6cd.js.map +0 -1
package/docs/compaction.md
CHANGED
|
@@ -1,253 +1,399 @@
|
|
|
1
|
-
# Compaction
|
|
1
|
+
# Compaction
|
|
2
|
+
|
|
3
|
+
A session grows with every turn. Before it stops fitting into the
|
|
4
|
+
model's context window, somora folds the older part of the conversation
|
|
5
|
+
into a summary and sends only the recent exchanges word for word. This
|
|
6
|
+
is called compaction.
|
|
7
|
+
|
|
8
|
+
## What you get
|
|
9
|
+
|
|
10
|
+
- **Sessions that never run full.** A long conversation keeps going
|
|
11
|
+
instead of ending in a "prompt too long" error.
|
|
12
|
+
- **Nothing is lost on disk.** Compaction only changes what is sent to
|
|
13
|
+
the model. The session file stays the full record.
|
|
14
|
+
- **A summary that remembers the work.** It keeps goals, decisions, open
|
|
15
|
+
questions and which tools already ran on which files.
|
|
16
|
+
- **You choose who summarises.** Name the models that may write
|
|
17
|
+
summaries, in the order they are tried.
|
|
18
|
+
- **A backup when a model is down.** If one summariser refuses, the next
|
|
19
|
+
one is asked.
|
|
20
|
+
- **Compact by hand.** `/compact` shortens a session right away, with an
|
|
21
|
+
optional focus for the summary, and the conversation goes on.
|
|
22
|
+
|
|
23
|
+
## Set it up
|
|
24
|
+
|
|
25
|
+
Compaction works without any setting. Two things are worth doing:
|
|
26
|
+
|
|
27
|
+
1. Give every model the right `contextWindow`. See
|
|
28
|
+
[What contextWindow controls per engine](#what-contextwindow-controls-per-engine).
|
|
29
|
+
2. Name the models that may summarise. Without this list somora may pick
|
|
30
|
+
a subscription model, and the summary then counts against that
|
|
31
|
+
subscription.
|
|
2
32
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
model does the summarising, and — the part people trip over — what the
|
|
8
|
-
per-model `contextWindow` value actually controls on each engine.
|
|
9
|
-
|
|
10
|
-
Related: [setup.md → Tunables](setup.md#tunables) (the knobs),
|
|
11
|
-
[models.md](models.md) (recommended `contextWindow` per model),
|
|
12
|
-
[thinking.md](thinking.md), [cache-strategy.md](cache-strategy.md).
|
|
33
|
+
```yaml
|
|
34
|
+
compaction:
|
|
35
|
+
workers: [<small-local-alias>, <hosted-alias>]
|
|
36
|
+
```
|
|
13
37
|
|
|
14
38
|
## Two kinds of compaction
|
|
15
39
|
|
|
16
|
-
|
|
40
|
+
Who compacts depends on the engine of the model that answers.
|
|
41
|
+
|
|
42
|
+
| Engine | Who compacts | When | What you see |
|
|
17
43
|
|---|---|---|---|
|
|
18
|
-
| `openai-compatible` |
|
|
19
|
-
| `claude-cli`, `codex-cli`, `grok-cli` |
|
|
20
|
-
|
|
21
|
-
somora's history file (`sessions/<id>.jsonl`) is never shortened by
|
|
22
|
-
either. Compaction only changes what is *sent*; the JSONL stays the
|
|
23
|
-
full record, and REM reads it independently.
|
|
24
|
-
|
|
25
|
-
## The openai-compatible path in detail
|
|
26
|
-
|
|
27
|
-
1. **Measure.** The number that decides is the one the provider
|
|
28
|
-
reported for this session's last request (`usage.prompt_tokens`,
|
|
29
|
-
kept on the session as `contextTokens`). Only when there is none —
|
|
30
|
-
a new session, a model switch, a provider that omits usage — does
|
|
31
|
-
somora fall back to a character estimate: system prompt, latest
|
|
32
|
-
summary, every user/assistant message after it, and the tool traffic
|
|
33
|
-
(arguments in full, results capped the way the replay caps them), at
|
|
34
|
-
**4 characters per token**.
|
|
35
|
-
|
|
36
|
-
That estimate is corrected by what the last request actually cost
|
|
37
|
-
(`tokenRatio`, measured ÷ estimated). Prose runs near 4 characters
|
|
38
|
-
per token; code, JSON and markup near 2.5. Tool traffic is counted
|
|
39
|
-
on purpose: a session made of tool calls can carry twenty times more
|
|
40
|
-
tokens than its visible chat text, and an estimate that only counts
|
|
41
|
-
chat never triggers on such a session.
|
|
42
|
-
2. **Trigger.** `tokens >= triggerRatio × inputBudget`, where the input
|
|
43
|
-
budget is `contextWindow − maxTokens` of the **model that will answer
|
|
44
|
-
this turn**. The output reservation comes out of the same window, so
|
|
45
|
-
measuring against the full window would let a session walk into a
|
|
46
|
-
provider 400 while every check says it fits. Switching a long
|
|
47
|
-
session from a 1M-window model to a
|
|
48
|
-
131k one triggers a compaction on the next turn; the measured number
|
|
49
|
-
is dropped on a model switch because tokenizers differ.
|
|
50
|
-
3. **Range.** Everything after the previous summary up to, but not
|
|
51
|
-
including, the last `safetyCushionPairs` exchanges (default 4) is
|
|
52
|
-
summarised. Unanswered user messages are never folded in. The
|
|
53
|
-
previous summary is passed to the worker as *prior summary*, so the
|
|
54
|
-
result is a rolling summary, not a chain of summaries.
|
|
55
|
-
4. **Worker.** See below — a separate model call, one-shot, no tools.
|
|
56
|
-
When the cushion covers the whole session there is nothing to
|
|
57
|
-
summarise; somora then retries once keeping only the last exchange,
|
|
58
|
-
because an aggressive summary beats a turn that cannot run. After a
|
|
59
|
-
compaction the next real reading is checked against the trigger, and
|
|
60
|
-
a compaction that did not clear it is logged rather than assumed to
|
|
61
|
-
have worked.
|
|
62
|
-
5. **Persist.** The summary is stored with the timestamp it covers
|
|
63
|
-
(`throughTs`) in the session's meta; later turns replay
|
|
64
|
-
`[summary] + pairs after throughTs`. CLI engines use the same
|
|
65
|
-
record when they rebuild a session (a Codex thread that no longer
|
|
66
|
-
exists, an MCP server rename on claude-cli) — the replay is bounded
|
|
67
|
-
to the most recent 40 exchanges either way.
|
|
68
|
-
|
|
69
|
-
**Reactive path.** The estimate can be wrong (tool payloads, images, a
|
|
70
|
-
backend with a smaller real limit than configured). When a backend
|
|
71
|
-
rejects the prompt as too long — `400 "Prompt too long"`, `"maximum
|
|
72
|
-
context length"`, oMLX's prefill guard — the engine forces a compaction
|
|
73
|
-
down to the last exchange, retries the turn once, and leaves a
|
|
74
|
-
`context compacted` engine row. A second refusal surfaces as a
|
|
75
|
-
plain-language error (switch model, or `/reset`) instead of the raw
|
|
76
|
-
400. This path only runs before anything has streamed and before any
|
|
77
|
-
tool has run: retrying later would execute those tools a second time.
|
|
78
|
-
Mid-turn the same refusal ends the turn with an explanation, because the
|
|
79
|
-
work already done cannot be replayed.
|
|
80
|
-
|
|
81
|
-
**Either way the refusal is read.** It is the one moment a backend states
|
|
82
|
-
its own limits — the window it enforces and how many input tokens it
|
|
83
|
-
counted — and somora takes both: the count corrects this session's
|
|
84
|
-
estimate, and a reported window smaller than the configured one is logged
|
|
85
|
-
with the value to put in `config.yaml`.
|
|
44
|
+
| `openai-compatible` | somora | Before a turn, when the prompt reaches `triggerRatio` times the input budget | Usually nothing. A `context compacted` row when a compaction ran inside or in reaction to a turn |
|
|
45
|
+
| `claude-cli`, `codex-cli`, `grok-cli` | The CLI itself, inside its own session | At the CLI's own threshold | Nothing from somora |
|
|
86
46
|
|
|
87
|
-
|
|
47
|
+
The session file `sessions/<id>.jsonl` is never shortened by either
|
|
48
|
+
kind. REM reads it independently.
|
|
49
|
+
|
|
50
|
+
The rest of this page, up to [Which model summarises](#which-model-summarises),
|
|
51
|
+
describes the `openai-compatible` path.
|
|
52
|
+
|
|
53
|
+
## Compact by hand
|
|
54
|
+
|
|
55
|
+
`/compact` compacts the open session now, instead of waiting for the
|
|
56
|
+
automatic compaction. Use it when a long conversation should go on with
|
|
57
|
+
less weight, or before you change the subject within the same session.
|
|
58
|
+
A sentence after the command tells the summary what to keep:
|
|
59
|
+
|
|
60
|
+
```text
|
|
61
|
+
/compact
|
|
62
|
+
/compact keep every file path and the open questions
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
| Client | How |
|
|
66
|
+
|---|---|
|
|
67
|
+
| Web client | `/compact [what to keep]` in the chat, or **Compact now** in the `•••` session menu. |
|
|
68
|
+
| Mobile app | **Compact this conversation** in the session sheet. |
|
|
69
|
+
| TUI | `/compact [what to keep]`. |
|
|
70
|
+
| HTTP | `POST /agents/:agent/sessions/:session/compact`, see the [API](api.md#post-agentsagentsessionssessioncompact). |
|
|
71
|
+
|
|
72
|
+
What happens depends on the engine of the session's model:
|
|
73
|
+
|
|
74
|
+
| Engine | Who compacts | The focus sentence |
|
|
75
|
+
|---|---|---|
|
|
76
|
+
| `openai-compatible` | somora, with the same summary as the automatic compaction. The last exchanges (`safetyCushionPairs`) stay as they are. | Goes into the summary prompt. |
|
|
77
|
+
| `claude-cli` | Claude Code compacts its own session, as `/compact` does in Claude Code. | Passed to Claude as its instructions. |
|
|
78
|
+
| `codex-cli` | Codex compacts its own thread. | Not used: Codex takes no instructions for it. The reply says so. |
|
|
79
|
+
| `grok-cli` | Not available. | |
|
|
80
|
+
|
|
81
|
+
Good to know:
|
|
82
|
+
|
|
83
|
+
- **Not during a turn.** While a turn runs, the command is refused with
|
|
84
|
+
`This session is busy`. Compact once the turn has ended. A message
|
|
85
|
+
you send while a compaction runs waits until it is done.
|
|
86
|
+
- **The chat says what happened.** A row reads, for example,
|
|
87
|
+
`Compacted by hand: Claude compacted its session (17.2k → 1.5k
|
|
88
|
+
tokens).` It shows in every client, also with the tool rows hidden.
|
|
89
|
+
- **A short session stays as it is.** With too little conversation the
|
|
90
|
+
reply says so and nothing changes.
|
|
91
|
+
- **Nothing is lost on disk.** As with the automatic compaction, the
|
|
92
|
+
session file keeps every message and REM reads all of it.
|
|
93
|
+
|
|
94
|
+
## Before a turn
|
|
95
|
+
|
|
96
|
+
### Measuring the session
|
|
97
|
+
|
|
98
|
+
somora uses two numbers and takes the larger one:
|
|
88
99
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
100
|
+
- **The provider's count.** What the provider reported as prompt size
|
|
101
|
+
for the session's last request. It is dropped when the session
|
|
102
|
+
switches to another model, because tokenizers differ.
|
|
103
|
+
- **An estimate.** System prompt, latest summary, every message after
|
|
104
|
+
it, and the tool traffic, at 4 characters per token. Tool arguments
|
|
105
|
+
count in full, tool results up to 800 characters each, the same cap
|
|
106
|
+
the replay uses.
|
|
107
|
+
|
|
108
|
+
The estimate is corrected by what the last request really cost. Prose
|
|
109
|
+
runs near 4 characters per token, code and JSON near 2.5, so somora
|
|
110
|
+
keeps the factor "measured divided by estimated" per session and applies
|
|
111
|
+
it, limited to between 0.5 and 3.
|
|
112
|
+
|
|
113
|
+
### The trigger
|
|
114
|
+
|
|
115
|
+
A compaction runs when the size reaches `triggerRatio` times the input
|
|
116
|
+
budget. The input budget is `contextWindow` minus `maxTokens` of the
|
|
117
|
+
model that answers this turn. The answer needs room in the same window,
|
|
118
|
+
so measuring against the full window would let a session run into a
|
|
119
|
+
provider error while every check says it fits.
|
|
120
|
+
|
|
121
|
+
Switching a long session from a model with a large window to one with a
|
|
122
|
+
small window triggers a compaction on the next turn.
|
|
123
|
+
|
|
124
|
+
### What gets summarised
|
|
125
|
+
|
|
126
|
+
Everything after the previous summary, up to but not including the last
|
|
127
|
+
`safetyCushionPairs` exchanges (default 4). The newest message, the one
|
|
128
|
+
being answered, is never part of it. An older message that never got an
|
|
129
|
+
answer is included and marked as unanswered.
|
|
130
|
+
|
|
131
|
+
The previous summary is handed to the summariser, which carries its
|
|
132
|
+
points over. The result is one rolling summary, not a chain.
|
|
133
|
+
|
|
134
|
+
When the last exchanges cover the whole session there is nothing to
|
|
135
|
+
summarise. somora then tries once more and keeps only the last exchange.
|
|
124
136
|
|
|
125
137
|
### What a summary keeps
|
|
126
138
|
|
|
127
|
-
The summary
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
file it already wrote and which command already
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
The summary has seven fixed sections: Goal, Constraints, Decisions,
|
|
140
|
+
Recent Context, Open Questions, Work State and Relevant Files. It is
|
|
141
|
+
written in the language of the conversation and prefers direct quotes.
|
|
142
|
+
|
|
143
|
+
Tool calls are not flattened into prose. Each summarised exchange
|
|
144
|
+
carries its tool trail: the tool, its key argument such as a path or a
|
|
145
|
+
command, and whether it succeeded. A model that continues after the
|
|
146
|
+
compaction knows which file it already wrote and which command already
|
|
147
|
+
ran.
|
|
148
|
+
|
|
149
|
+
### Where the summary is stored
|
|
150
|
+
|
|
151
|
+
The summary is saved in the session's meta data together with the time
|
|
152
|
+
it covers. Later turns send the summary plus the exchanges after that
|
|
153
|
+
time.
|
|
154
|
+
|
|
155
|
+
`claude-cli` and `codex-cli` use the same record when they have to
|
|
156
|
+
rebuild a session, for example after a Codex thread is gone. That replay
|
|
157
|
+
is limited to the 40 most recent exchanges and 60,000 characters.
|
|
158
|
+
|
|
159
|
+
### When compaction fails
|
|
160
|
+
|
|
161
|
+
A failed compaction does not stop the turn. The turn runs on the
|
|
162
|
+
uncompacted history and the checks described below take over. After a
|
|
163
|
+
successful compaction the next real count is compared with the trigger.
|
|
164
|
+
If it is still above, a warning is logged.
|
|
165
|
+
|
|
166
|
+
## When the backend refuses the prompt
|
|
167
|
+
|
|
168
|
+
The estimate can be wrong, or the backend can have a smaller limit than
|
|
169
|
+
configured. When a backend rejects the prompt as too long, somora reacts:
|
|
170
|
+
|
|
171
|
+
| Situation | What happens |
|
|
172
|
+
|---|---|
|
|
173
|
+
| Nothing has streamed and no tool has run | somora compacts down to the last exchange, retries the turn once and leaves a `context compacted` row |
|
|
174
|
+
| The retry is refused too, or nothing could be compacted | The turn ends with a plain message: switch model with `/model` or start over with `/reset` |
|
|
175
|
+
| Tools have already run in this turn | The turn ends with an explanation. The work stays in the session and the next message compacts first |
|
|
176
|
+
|
|
177
|
+
A turn is not retried after tools have run, because that would run them
|
|
178
|
+
a second time.
|
|
179
|
+
|
|
180
|
+
The refusal is also read. Backends state the window they enforce and the
|
|
181
|
+
tokens they counted. The count corrects the session's estimate. A
|
|
182
|
+
reported window smaller than the configured one is logged with the value
|
|
183
|
+
to put into `config.yaml`.
|
|
184
|
+
|
|
185
|
+
## Inside a running turn
|
|
186
|
+
|
|
187
|
+
A turn with tools grows while it runs: every tool result, every image
|
|
188
|
+
and the tool definitions travel with each request. So before every
|
|
189
|
+
request of a turn, somora measures what it is about to send. Images
|
|
190
|
+
count as images, about 1,300 tokens each, not by their encoded length.
|
|
191
|
+
|
|
192
|
+
The limit is the window minus the model's `maxTokens` (4,096 if unset)
|
|
193
|
+
minus a 5% margin. The margin is 15% for a provider that never reports
|
|
194
|
+
token counts. If the request does not fit:
|
|
195
|
+
|
|
196
|
+
1. **The oldest tool results are shortened** to a one-line notice saying
|
|
197
|
+
the call already ran and must not be repeated. The four newest
|
|
198
|
+
results stay.
|
|
199
|
+
2. **More recent results follow**, except the newest. That is the one
|
|
200
|
+
the model is working with right now.
|
|
201
|
+
3. **The newest result is cut** as a last resort. Its beginning is kept
|
|
202
|
+
and the cut is labelled.
|
|
203
|
+
4. **The turn stops** only when nothing is left to shorten, with a
|
|
204
|
+
message that names the numbers. Tool results already produced stay in
|
|
205
|
+
the session.
|
|
206
|
+
|
|
207
|
+
No message is ever dropped, only shortened, so the model keeps its own
|
|
208
|
+
record of what it did. A trimmed turn leaves a `context trimmed` row.
|
|
209
|
+
|
|
210
|
+
### Builder turns
|
|
211
|
+
|
|
212
|
+
A [builder](builder.md#long-turns) turn takes one step before trimming.
|
|
213
|
+
When the next request no longer fits, the earlier rounds of the turn are
|
|
214
|
+
summarised into a work-state block: what was done, what is in progress,
|
|
215
|
+
what is blocked, the next move and the relevant files. The task list is
|
|
216
|
+
appended. The last six rounds stay word for word.
|
|
217
|
+
|
|
218
|
+
This leaves a `context compacted` row. It uses `workers` and
|
|
219
|
+
`preferSessionModel`, asks at most three models, and falls back to
|
|
220
|
+
trimming when none delivers.
|
|
144
221
|
|
|
145
222
|
## Which model summarises
|
|
146
223
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
224
|
+
A summary is a separate, single model call without tools. Three engines
|
|
225
|
+
can do it: `openai-compatible`, `claude-cli` and `codex-cli`. A
|
|
226
|
+
`grok-cli` model is never a summariser.
|
|
150
227
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
228
|
+
### With a workers list
|
|
229
|
+
|
|
230
|
+
`compaction.workers` is an ordered list. The first entry is asked first,
|
|
231
|
+
and a model that is not on the list never summarises. An entry is an
|
|
232
|
+
alias, a model id or `provider/modelId`.
|
|
233
|
+
|
|
234
|
+
Entries are used as written, without a window check: naming a model
|
|
235
|
+
means you meant it. An entry that matches no configured model is skipped
|
|
236
|
+
with a `compaction.workers_unresolved` warning. If no entry matches at
|
|
237
|
+
all, the compaction fails.
|
|
238
|
+
|
|
239
|
+
### Without a list
|
|
240
|
+
|
|
241
|
+
somora picks from every configured model on the three engines above:
|
|
242
|
+
each model whose `contextWindow` is at least 1.3 times the estimated
|
|
243
|
+
size of the summary request, smallest window first.
|
|
244
|
+
|
|
245
|
+
Three things follow from this:
|
|
246
|
+
|
|
247
|
+
- **A subscription model may be picked.** If the smallest fitting window
|
|
248
|
+
belongs to a Claude or Codex model, the summary runs through that CLI
|
|
249
|
+
and counts against that subscription. Nothing in the UI says so. Set
|
|
250
|
+
`workers` to keep summaries on local models.
|
|
251
|
+
- **A wrong `contextWindow` misleads the pick.** Too high makes a model
|
|
252
|
+
eligible for histories it cannot hold. Too low removes it from the
|
|
253
|
+
candidates.
|
|
254
|
+
- **A small model is often enough.** The summariser gets only the range
|
|
255
|
+
to summarise, not the whole session. A 32k local model works well for
|
|
256
|
+
a session that has been compacting all along.
|
|
257
|
+
|
|
258
|
+
### Session model first
|
|
259
|
+
|
|
260
|
+
`compaction.preferSessionModel: true` puts the model that is answering
|
|
261
|
+
the session in front of the list, session override included. It is used
|
|
262
|
+
only when its engine can summarise and its window is at least 1.3 times
|
|
263
|
+
the request. The list stays the order behind it.
|
|
264
|
+
|
|
265
|
+
It is off by default, because a session on a hosted subscription model
|
|
266
|
+
would start paying for its own summaries. Switch it on when sessions run
|
|
267
|
+
on models that are loaded and answering while the listed workers may not
|
|
268
|
+
be, for example on a GPU host that swaps models.
|
|
269
|
+
|
|
270
|
+
### Pinning one model
|
|
271
|
+
|
|
272
|
+
`compaction.modelOverride` names one model by alias, model id or
|
|
273
|
+
`provider/modelId`. It goes
|
|
274
|
+
to the front of whatever order is in play, ahead of the session model
|
|
275
|
+
and the list. A name that matches nothing is logged as
|
|
276
|
+
`compaction.override_unresolved` and the rest of the order is used.
|
|
277
|
+
|
|
278
|
+
### When a summariser fails
|
|
279
|
+
|
|
280
|
+
At most three models are asked per compaction. A refusal costs one
|
|
281
|
+
attempt, not the compaction: the next model is asked. Only when all of
|
|
282
|
+
them refuse does the compaction fail.
|
|
283
|
+
|
|
284
|
+
A model can fail for reasons that have nothing to do with the summary: a
|
|
285
|
+
busy host, a route being reloaded, a rate limit. A model that could not
|
|
286
|
+
be reached is remembered as unavailable for
|
|
287
|
+
`fallback.retryUnavailableMinutes` (default 60). A model that only
|
|
288
|
+
rejected the request is not.
|
|
289
|
+
|
|
290
|
+
Chat fallback, REM and compaction share this memory. Models marked
|
|
291
|
+
unavailable are left out before the three attempts are chosen, unless
|
|
292
|
+
that would leave nothing to try. A model that answers is cleared at
|
|
293
|
+
once. The memory is not kept across a restart.
|
|
155
294
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
Without the list, somora picks automatically **from every configured
|
|
173
|
-
model on every engine that has a one-shot path** (claude-cli,
|
|
174
|
-
codex-cli, openai-compatible), in this order:
|
|
175
|
-
|
|
176
|
-
> every model whose `contextWindow >= estimatedTokens × 1.3`,
|
|
177
|
-
> **smallest window first**
|
|
178
|
-
|
|
179
|
-
`compaction.modelOverride` still works and simply goes to the front of
|
|
180
|
-
whatever cascade is in play.
|
|
181
|
-
|
|
182
|
-
**A refusal costs one attempt, not the compaction.** At most
|
|
183
|
-
**three** workers are asked per compaction; each failure is logged as
|
|
184
|
-
`compaction.worker_failed` with the reason and the next candidate, and
|
|
185
|
-
only when all of them refuse does the compaction fail. This matters
|
|
186
|
-
because a worker can fail for reasons that have nothing to do with the
|
|
187
|
-
summary: a memory guard on a busy host, a route being reloaded, a rate
|
|
188
|
-
limit. somora cannot see which machine sits behind which route, so it
|
|
189
|
-
does not guess — it asks the next model.
|
|
190
|
-
|
|
191
|
-
Three consequences worth knowing:
|
|
192
|
-
|
|
193
|
-
- The worker may be a **subscription-backed CLI model**. If the
|
|
194
|
-
smallest fitting window belongs to a Claude or Codex model, the
|
|
195
|
-
summary is produced through that CLI and counts against that
|
|
196
|
-
subscription. Nothing in the UI says so. Set `workers` if you
|
|
197
|
-
want the summariser kept to local models.
|
|
198
|
-
- A `contextWindow` that is **too high** for what the engine can
|
|
199
|
-
really take makes that model eligible for histories it cannot
|
|
200
|
-
hold; the summarise call then fails or is compacted again by the
|
|
201
|
-
CLI. Too **low** just removes it from the candidate list.
|
|
202
|
-
- The history handed to the worker is the *range* above, not the
|
|
203
|
-
whole session, so a 32k local model is a perfectly good worker for a
|
|
204
|
-
session that has been compacting all along.
|
|
205
|
-
|
|
206
|
-
## What `contextWindow` really controls — per engine
|
|
207
|
-
|
|
208
|
-
The same per-model field does three different jobs:
|
|
209
|
-
|
|
210
|
-
| meaning | openai-compatible | claude-cli / codex-cli / grok-cli |
|
|
295
|
+
## What contextWindow controls per engine
|
|
296
|
+
|
|
297
|
+
The same per-model field does three jobs:
|
|
298
|
+
|
|
299
|
+
| Job | `openai-compatible` | `claude-cli`, `codex-cli`, `grok-cli` |
|
|
300
|
+
|---|---|---|
|
|
301
|
+
| Compaction trigger and in-turn limit | yes | no, the CLI compacts on its own threshold |
|
|
302
|
+
| Choice of summariser | yes | yes, except `grok-cli` |
|
|
303
|
+
| Usage display in the header | yes | yes |
|
|
304
|
+
|
|
305
|
+
On a CLI engine the value never prevents an overflow. It decides whether
|
|
306
|
+
the model is picked as a summariser for other sessions and whether the
|
|
307
|
+
percentage in the header is true. Set it to the limit the engine really
|
|
308
|
+
enforces:
|
|
309
|
+
|
|
310
|
+
| Engine | Set `contextWindow` to | Why |
|
|
211
311
|
|---|---|---|
|
|
212
|
-
|
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
312
|
+
| `codex-cli` | 258400 | Codex runs every session against its own window, which is smaller than the model's API window. |
|
|
313
|
+
| `claude-cli` | the model's real window | Claude Code sessions run against it: 1M for the Claude 5 family, 200k for Haiku 4.5. |
|
|
314
|
+
| `openai-compatible` | the server's limit | Use vLLM `--max-model-len`, SGLang `--context-length` or oMLX's configured length, not the number on the model card. |
|
|
315
|
+
|
|
316
|
+
> **Warning:** A value that is too high on `openai-compatible` means
|
|
317
|
+
> somora compacts too late. With 1000000 configured against a backend
|
|
318
|
+
> that takes 700k, compaction starts at about 800k and the backend
|
|
319
|
+
> refuses first.
|
|
320
|
+
|
|
321
|
+
Codex reports its window per thread as `modelContextWindow`. somora uses
|
|
322
|
+
that number for the header from the first turn on, so the configured
|
|
323
|
+
value matters before the first turn and for the choice of summariser. A
|
|
324
|
+
value copied from the model card makes the header show free space while
|
|
325
|
+
Codex is already compacting.
|
|
326
|
+
|
|
327
|
+
## Reading the numbers
|
|
328
|
+
|
|
329
|
+
The chat header shows two different things:
|
|
330
|
+
|
|
331
|
+
| Symbol | Meaning |
|
|
332
|
+
|---|---|
|
|
333
|
+
| `▣` | How full the window is: the prompt size of the turn's last request against the window. |
|
|
334
|
+
| `Σ↑` | How much was sent: the sum over every request the turn made. |
|
|
335
|
+
|
|
336
|
+
A turn with 21 tool rounds on a 524k window can read `▣ 62%` and
|
|
337
|
+
`Σ↑ 6.0M`. Both are correct, because the context travels with every
|
|
338
|
+
request. Only the first says how full the window is.
|
|
339
|
+
|
|
340
|
+
The percentage is counted the same way on every engine: the whole
|
|
341
|
+
prompt, cached part included. Codex reports `cachedInputTokens` as part
|
|
342
|
+
of its prompt size, so somora does not add it. Claude reports
|
|
343
|
+
`input_tokens` without the cached part, so somora adds the cache
|
|
344
|
+
numbers.
|
|
345
|
+
|
|
346
|
+
## Settings
|
|
347
|
+
|
|
348
|
+
All settings live in `config.yaml` and are optional.
|
|
243
349
|
|
|
244
350
|
```yaml
|
|
245
351
|
compaction:
|
|
246
|
-
triggerRatio: 0.8
|
|
247
|
-
safetyCushionPairs: 4
|
|
248
|
-
# workers: [<small-local-alias>, <hosted-alias>]
|
|
249
|
-
#
|
|
352
|
+
triggerRatio: 0.8
|
|
353
|
+
safetyCushionPairs: 4
|
|
354
|
+
# workers: [<small-local-alias>, <hosted-alias>]
|
|
355
|
+
# preferSessionModel: false
|
|
356
|
+
# modelOverride: <alias>
|
|
357
|
+
fallback:
|
|
358
|
+
retryUnavailableMinutes: 60
|
|
250
359
|
```
|
|
251
360
|
|
|
252
|
-
|
|
253
|
-
|
|
361
|
+
| Setting | Default | Meaning |
|
|
362
|
+
|---|---|---|
|
|
363
|
+
| `compaction.triggerRatio` | 0.8 | Share of the input budget at which a compaction runs. Above 0, at most 1. `openai-compatible` only. |
|
|
364
|
+
| `compaction.safetyCushionPairs` | 4 | The most recent exchanges that are never summarised. |
|
|
365
|
+
| `compaction.workers` | unset | Models that may summarise, in the order they are tried. Unset means automatic choice. |
|
|
366
|
+
| `compaction.preferSessionModel` | false | Ask the session's own model before the workers. |
|
|
367
|
+
| `compaction.modelOverride` | unset | One model that is always asked first. |
|
|
368
|
+
| `fallback.retryUnavailableMinutes` | 60 | How long an unreachable model is skipped by chat, REM and compaction. 1 to 1440. |
|
|
369
|
+
|
|
370
|
+
Environment variables override the file:
|
|
371
|
+
|
|
372
|
+
| Variable | Overrides |
|
|
373
|
+
|---|---|
|
|
374
|
+
| `SOMORA_COMPACTION_TRIGGER_RATIO` | `compaction.triggerRatio` |
|
|
375
|
+
| `SOMORA_COMPACTION_SAFETY_PAIRS` | `compaction.safetyCushionPairs` |
|
|
376
|
+
| `SOMORA_COMPACTION_WORKERS` | `compaction.workers`, comma separated |
|
|
377
|
+
| `SOMORA_COMPACTION_MODEL` | `compaction.modelOverride` |
|
|
378
|
+
|
|
379
|
+
## Troubleshooting
|
|
380
|
+
|
|
381
|
+
| Symptom | Look for | What to do |
|
|
382
|
+
|---|---|---|
|
|
383
|
+
| The backend still answers "prompt too long" | `engine.context_overflow` in the log, with a hint naming the window the backend enforces | Lower the model's `contextWindow` to that value. |
|
|
384
|
+
| Compaction runs every turn | `engine.compaction_ineffective` | The recent exchanges alone are too big. Lower `safetyCushionPairs` or use a model with a larger window. |
|
|
385
|
+
| Summaries cost subscription usage | `compaction.worker_chosen` shows a CLI model | Set `compaction.workers`. |
|
|
386
|
+
| Compaction fails | `compaction.worker_failed`, `compaction.all_workers_failed`, `compaction.no_model_fits`, `engine.compaction_fail` | Check that the workers are reachable and that one has a large enough window. |
|
|
387
|
+
| A listed worker is never asked | `compaction.workers_unresolved` or `model.unavailable` | Fix the name, or wait until the model is tried again. |
|
|
388
|
+
| `/compact` answers `This session is busy` | A turn or another compaction is running | Wait until it has ended, then run it again. |
|
|
389
|
+
| `/compact` changes nothing | `session.compacted_by_hand` with `status: nothing_to_compact` | The session is too short, or the engine has no conversation for it yet. |
|
|
390
|
+
|
|
391
|
+
## See also
|
|
392
|
+
|
|
393
|
+
- [Models](models.md): recommended `contextWindow` per model
|
|
394
|
+
- [Setup](setup.md#settings): server-level settings in one place
|
|
395
|
+
- [Builder](builder.md#long-turns): how long builder turns stay inside
|
|
396
|
+
the window
|
|
397
|
+
- [Cache strategy](cache-strategy.md): what is sent in which order and
|
|
398
|
+
why
|
|
399
|
+
- [Thinking](thinking.md): reasoning levels per engine
|