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.
Files changed (123) hide show
  1. package/README.md +31 -24
  2. package/config.example.yaml +37 -1
  3. package/docs/agents.md +714 -584
  4. package/docs/api.md +2327 -2546
  5. package/docs/browser.md +450 -265
  6. package/docs/builder.md +408 -282
  7. package/docs/cache-strategy.md +249 -301
  8. package/docs/compaction.md +378 -232
  9. package/docs/display.md +363 -130
  10. package/docs/dream-phases.md +598 -789
  11. package/docs/files.md +509 -333
  12. package/docs/imagegen.md +421 -302
  13. package/docs/images/somora-hero.png +0 -0
  14. package/docs/index.md +139 -174
  15. package/docs/lsp.md +142 -60
  16. package/docs/mcp.md +365 -273
  17. package/docs/memory.md +315 -356
  18. package/docs/mobile.md +283 -282
  19. package/docs/models.md +440 -197
  20. package/docs/projects.md +297 -316
  21. package/docs/realtime-voice.md +358 -234
  22. package/docs/resources.md +268 -176
  23. package/docs/sampling.md +141 -78
  24. package/docs/security.md +413 -169
  25. package/docs/sentinel.md +268 -208
  26. package/docs/setup.md +786 -1115
  27. package/docs/skills.md +415 -430
  28. package/docs/team.md +268 -143
  29. package/docs/thinking.md +415 -387
  30. package/docs/tmux.md +384 -334
  31. package/docs/tools.md +492 -109
  32. package/docs/videogen.md +319 -146
  33. package/docs/voice.md +335 -220
  34. package/docs/web.md +633 -835
  35. package/docs/wiki.md +442 -482
  36. package/package.json +2 -1
  37. package/src/attachments/store.ts +19 -1
  38. package/src/browser/session.ts +2 -2
  39. package/src/cli/auth.ts +22 -0
  40. package/src/cli/banner.ts +56 -0
  41. package/src/cli/claude-bin.ts +48 -0
  42. package/src/cli/config.ts +47 -0
  43. package/src/cli/server-call.ts +65 -0
  44. package/src/cli/setup.ts +26 -8
  45. package/src/cli/somora.ts +36 -4
  46. package/src/cli/team.ts +13 -6
  47. package/src/cli/tui/api.ts +44 -2
  48. package/src/cli/tui/app.tsx +77 -8
  49. package/src/cli/tui/commands.ts +111 -14
  50. package/src/cli/tui/header.tsx +20 -0
  51. package/src/cli/tui/stream.ts +3 -0
  52. package/src/cli/tui/turn-views.tsx +22 -0
  53. package/src/cli/tui/types.ts +14 -3
  54. package/src/compaction/summarize.ts +12 -3
  55. package/src/compaction/template.ts +15 -0
  56. package/src/compaction/types.ts +3 -0
  57. package/src/config/loader.ts +75 -10
  58. package/src/config/types.ts +59 -20
  59. package/src/dream/deep-llm.ts +83 -3
  60. package/src/dream/deep-runner.ts +8 -2
  61. package/src/dream/deep-worker.ts +1 -0
  62. package/src/dream/lucid-runner.ts +7 -3
  63. package/src/dream/lucid-types.ts +3 -0
  64. package/src/dream/rem-extract.ts +99 -69
  65. package/src/dream/worker-model.ts +31 -0
  66. package/src/engine/a2a.ts +1 -1
  67. package/src/engine/claude-cli.ts +136 -4
  68. package/src/engine/codex-cli.ts +74 -0
  69. package/src/engine/engine-meta-labels.ts +2 -0
  70. package/src/engine/openai-compatible.ts +142 -29
  71. package/src/engine/types.ts +7 -0
  72. package/src/imagegen/generate.ts +30 -5
  73. package/src/imagegen/types.ts +6 -0
  74. package/src/media/capabilities.ts +8 -0
  75. package/src/memory/inject.ts +66 -7
  76. package/src/multimodal/blocks.ts +14 -0
  77. package/src/multimodal/load.ts +21 -2
  78. package/src/multimodal/model-image.ts +127 -0
  79. package/src/persona/loader.ts +2 -2
  80. package/src/server/index.ts +275 -62
  81. package/src/server/restart-intent.ts +138 -0
  82. package/src/server/restart-reconcile.ts +6 -2
  83. package/src/server/run-turn.ts +66 -17
  84. package/src/server/session-compact.ts +138 -0
  85. package/src/server/thinking-resolve.ts +30 -0
  86. package/src/server/turn-origin-kind.ts +2 -2
  87. package/src/ssh/exec.ts +55 -22
  88. package/src/ssh/known-hosts.ts +17 -2
  89. package/src/ssh/pool.ts +7 -1
  90. package/src/storage/sessions.ts +40 -15
  91. package/src/tools/dream/tools.ts +2 -2
  92. package/src/tools/exec/tools.ts +19 -2
  93. package/src/tools/file/analyze.ts +46 -7
  94. package/src/tools/file/remote.ts +31 -10
  95. package/src/tools/file/tools.ts +86 -19
  96. package/src/tools/image/tools.ts +6 -0
  97. package/src/tools/registry.ts +14 -0
  98. package/src/types/events.ts +25 -4
  99. package/src/types/turn-origin.ts +6 -2
  100. package/web/dist/apple-touch-icon.png +0 -0
  101. package/web/dist/assets/{index-CrkkIfd9.js → index-40x__Izy.js} +168 -163
  102. package/web/dist/assets/index-40x__Izy.js.map +1 -0
  103. package/web/dist/assets/index-CZFgQRsq.css +32 -0
  104. package/web/dist/favicon-48.png +0 -0
  105. package/web/dist/favicon.ico +0 -0
  106. package/web/dist/favicon.svg +1 -8
  107. package/web/dist/index.html +6 -2
  108. package/web-mobile/dist/apple-touch-icon.png +0 -0
  109. package/web-mobile/dist/assets/index-CxILeHfe.js +88 -0
  110. package/web-mobile/dist/assets/index-CxILeHfe.js.map +1 -0
  111. package/web-mobile/dist/assets/index-Cyr13VGR.css +1 -0
  112. package/web-mobile/dist/favicon-48.png +0 -0
  113. package/web-mobile/dist/favicon.ico +0 -0
  114. package/web-mobile/dist/favicon.svg +1 -8
  115. package/web-mobile/dist/icon-192.png +0 -0
  116. package/web-mobile/dist/icon-512.png +0 -0
  117. package/web-mobile/dist/index.html +5 -3
  118. package/web-mobile/dist/manifest.webmanifest +2 -2
  119. package/web/dist/assets/index-BA5mmiV0.css +0 -32
  120. package/web/dist/assets/index-CrkkIfd9.js.map +0 -1
  121. package/web-mobile/dist/assets/index-BqKt7IMx.css +0 -1
  122. package/web-mobile/dist/assets/index-X_vRr6cd.js +0 -88
  123. package/web-mobile/dist/assets/index-X_vRr6cd.js.map +0 -1
@@ -1,253 +1,399 @@
1
- # Compaction — how somora keeps a session inside the context window
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
- A session grows with every turn. Somewhere before it stops fitting into
4
- the model's context window, the older part of the conversation is
5
- folded into a summary and only the recent exchanges travel to the model
6
- verbatim. This page describes when that happens, who does it, which
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
- | | who compacts | when | what you see |
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` | **somora** | before a turn, when the prompt reaches `triggerRatio × inputBudget` (default 0.8; the budget is the window minus the answer, and the number is the one the provider measured last) | a `context compacted` row when the reactive path ran; otherwise nothing — the summary is invisible, the recent pairs are verbatim |
19
- | `claude-cli`, `codex-cli`, `grok-cli` | **the CLI itself**, inside its own session/thread | at the CLI's own threshold (codex: its server-delivered session cap) | nothing from somora; the engine's own compaction is opaque to it. The `▣` percentage still tells the truth: codex reports its own `modelContextWindow` per thread, and the prompt size it reports is the prompt, cached part included, so somora does not add `cachedInputTokens` on top (that would count the cached part twice and drive the badge past 100 % on long threads). Anthropic counts the other way round, `input_tokens` EXCLUDES the cached part, so claude-cli sums. |
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
- ## Inside a running turn
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
- Steps 1 to 5 size the conversation *before* the turn. A turn with tools
90
- grows while it runs — every result, every image, and the tool schemas
91
- that travel with each request. Sized once, a turn estimated at a few
92
- tens of thousands of tokens can reach the backend at ten times that,
93
- die on a raw 400, and lose its work.
94
-
95
- So before **every** request of a turn, somora measures what it is about
96
- to send: all messages, images counted as images rather than as their
97
- base64 length, plus the tool schemas. It compares that against the
98
- window minus the model's output reserve minus a 5% margin. If it does
99
- not fit:
100
-
101
- 1. **The oldest tool results are shortened** to a one-line notice that
102
- says the call already ran and must not be repeated. Nothing is
103
- dropped: an assistant message with `tool_calls` and no matching
104
- reply is rejected by every OpenAI-compatible backend, and the
105
- model's own record of what it did is what stops it repeating work.
106
- 2. If that is not enough, more recent results follow, **except the
107
- newest**, which is what the model is reasoning about right now.
108
- 3. As a last resort the newest result is **cut**, keeping its beginning
109
- and labelling the cut.
110
- 4. Only when there is nothing left to shorten does the turn stop, with
111
- an explanation naming the numbers instead of a raw backend error.
112
- The tool results already produced stay in the session, so nothing
113
- has to be redone.
114
-
115
- A trimmed turn leaves a `context trimmed` engine row, so it is visible
116
- that the model saw less than the full results.
117
-
118
- A **builder** turn ([builder.md](builder.md#long-turns)) goes one step
119
- further before trimming: when the turn's own traffic passes the trigger
120
- mid-way, the rounds so far are summarised into a work-state block (what
121
- was done, what the files look like now, what is left) and the last six
122
- rounds stay verbatim, then the turn continues on the smaller context.
123
- Chat agents keep the trimming above; nothing changes for them.
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 a compaction writes follows a fixed template — the goal,
128
- what was done, decisions and their reasons, the work state, the
129
- relevant files, open points, and the tone of the conversation — and
130
- the pairs after it stay verbatim. Tool calls are not flattened into
131
- prose: each summarised pair carries its **tool trail** (the tool, the
132
- essential argument such as a path or a command, and whether it
133
- succeeded), so a model that continues after the compaction knows which
134
- file it already wrote and which command already ran, instead of
135
- repeating them.
136
-
137
- **Reading the numbers.** The chat header shows two different things.
138
- `▣` is occupancy: the prompt size of the turn's **last** request against
139
- the window. `Σ↑` is spend, and the Σ is the point — it sums every
140
- request the turn made. Example: 21 tool rounds on a 524k window read
141
- `▣ 62%` (about 323k tokens in the last request) and `Σ↑ 6.0M` (sent in
142
- total, because the context travels with every request). Both are
143
- correct; only the first one says how full it is.
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
- `compaction.workers` is an **ordered list** of the models allowed to
148
- summarise, and that order is the cascade — the first entry is asked
149
- first, and a model that is not on the list is never a worker:
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
- ```yaml
152
- compaction:
153
- workers: [<small-local-alias>, <hosted-alias>]
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
- Listed entries are honoured as written, including their window: naming
157
- a model means you meant it. An entry that matches no configured alias
158
- or `provider/modelId` is skipped with a `compaction.workers_unresolved`
159
- warning.
160
-
161
- Workers that are currently marked unreachable (see `fallback.retryUnavailableMinutes` in [setup.md](setup.md#tunables) — the note the chat fallback and REM share) are left out of the cascade, unless that would leave nothing to try.
162
-
163
- `compaction.preferSessionModel: true` puts the session's own model —
164
- the one answering right now, session override included — in front of
165
- the list, provided its engine can summarise and its window fits the
166
- summary with headroom; the list stays the cascade behind it. Off by
167
- default: a session on a hosted subscription model would otherwise start
168
- paying for its own summaries. Use it when sessions run on models that
169
- are loaded and answering while the listed workers may not be (a GPU
170
- profile that swaps models).
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
- | **Compaction trigger** (`triggerRatio ×`) | yes — this is the wall somora compacts against | **no** — the CLI compacts on its own threshold |
213
- | **Worker selection** (smallest fitting window, engine-agnostic) | yes | yes |
214
- | **Usage display** (`X / contextWindow` in TUI header and `agent` SSE end event) | yes | yes |
215
-
216
- So on a CLI engine the value never prevents an overflow — it decides
217
- whether that model is picked as a summariser for *other* sessions and
218
- whether the percentage in the header tells the truth. Which is exactly
219
- why it must be the **effective session limit of the CLI**, not the
220
- native API window of the model:
221
-
222
- - **codex-cli**: Codex runs a session against a window it delivers
223
- itself and reports per thread as `modelContextWindow` — **258,400**
224
- for the GPT-5.6 and GPT-6 models, although the model's API window
225
- is 1.05M. somora uses that reported number for the header
226
- as soon as the first turn reports it, so the configured value matters
227
- before the first turn and for the compaction-worker choice: configure
228
- `contextWindow: 258400`. A value of 400000 or 1000000 — the obvious
229
- thing to copy from the model card — makes the header claim "68 %
230
- free" while codex is already compacting internally, and lets the
231
- model be picked as a summariser for histories it will refuse.
232
- - **claude-cli**: Claude Code sessions run against the model's real
233
- window (1M for the Claude 5 family, 200k for Haiku 4.5), so the
234
- native value is correct here.
235
- - **openai-compatible**: use the **server's** limit, not the model
236
- card's — vLLM `--max-model-len`, SGLang `--context-length`, oMLX's
237
- configured length. With 1000000 configured against a 700k backend
238
- somora only compacts at 800k and the backend answers 400 first.
239
-
240
- [models.md](models.md) lists the recommended values per model.
241
-
242
- ## Knobs
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 # fraction of the input budget (openai-compatible only)
247
- safetyCushionPairs: 4 # most-recent exchanges never summarised
248
- # workers: [<small-local-alias>, <hosted-alias>] # who may summarise, in the order they are tried
249
- # modelOverride: <alias> # pin the summariser (any engine with a one-shot path)
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
- Environment overrides `SOMORA_COMPACTION_*` are listed in
253
- [setup.md → Environment overrides](setup.md#environment-overrides).
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