Commit 70d2f8c
Ryan Wyler
feat: collapse/float compaction modes and knowledge pack support
Collapse compaction mode:
- Selectively compresses oldest 65% of tokens instead of entire conversation
- Merges historical summaries for continuity (configurable: previousSummaries)
- Places summary at correct breakpoint position in timeline
- TUI toggle cycles standard -> collapse -> float via command palette
- insertTriggers=false prevents timestamp collision infinite loops
- Preserves real user messages; only deletes synthetic trigger messages
Float compaction mode:
- Sub-collapses oldest conversation chains before overflow evaluation
- Chain detection requires 2+ assistant messages (skips simple Q&A pairs)
- bookend algorithm by default; configurable per chainThreshold
- Soft-deletes sub-collapsed messages with flux=compacted (not hard-delete)
- summary:true flag on sub-collapse result prevents re-trigger loops
- detectChains skips already-processed messages (summary:true or flux set)
to prevent infinite sub-collapse loop
- Token adjustment accounts for sub-collapse savings to prevent re-trigger
- Reloads TUI messages after sub-collapse via session.compacted event
- Re-parents orphaned chain messages after mid-chain split
- splitChainMinThreshold gate prevents processing chains too small for benefit
- minFloat threshold: skip sub-collapse until total tokens reach configurable limit
- Float pre-check also fires on stop finish (not just before LLM calls)
Knowledge pack support:
- New KnowledgePack module for injecting knowledge pack messages into sessions
- Knowledge pack messages sit at time_created=1,2,... (before compaction breakpoints)
and are prepended explicitly at prompt build time (filterCompacted never sees them)
- Propagates manually-enabled knowledge packs from parent to subagent sessions
- Knowledge pack agent prompt overrides: KP can declare agent.<name>.prompt to
replace a built-in agent system prompt for the session (global registry not mutated)
- Plugin transform hook receives knowledge pack messages via toModelMessages injection
- TUI sidebar: add/remove knowledge packs, mirror to project config on change
- Server routes: /knowledge-pack list/add/remove/enable/disable endpoints
- Sidebar click race condition fix: refetchActive deferred after server response
- Sidebar prompt refocus: restores focus after KP interactions only
- Global knowledge packs mirrored to project config on sidebar add/remove
- Project config written to .opencode/opencode.json (not config.json)
Upstream overflow (413) integration:
- Collapse/float modes propagate overflow=true through to the continuation message:
when a 413 triggers compaction in collapse or float mode, an overflow explanation
message is injected after the collapse completes so the user understands their
media attachments were too large
- filterCompacted: errored summary messages no longer treated as valid compaction
breakpoints (upstream guard: !msg.info.error)
- filterCompacted: breakpoint detection no longer requires finish flag on assistant
summary (collapse compaction may complete without setting finish)
Implementation details:
- compaction-extension.ts: self-contained for easy rebasing; all debug logging
uses COLLAPSE tag (grep: tail -f ~/.local/share/opencode/log/dev.log | grep COLLAPSE)
- detectChains: handles mid-run user interjections in full chain detection
- copyUserMessage: inserts duplicate chain anchor when mid-chain compaction splits
leave orphaned assistant messages
- Identifier.insertCopy / Identifier.insert: generate IDs that sort between
existing messages without timestamp collisions
- isOverflow routes to CompactionExtension for collapse/float modes (configurable trigger)
- Config schema: compaction.method, extractRatio, recentRatio, summaryMaxTokens,
previousSummaries, splitChain, splitChainMinThreshold, minFloat, insertTriggers
- knowledge.enabled, knowledge.paths, knowledge.packs config fields1 parent b976f33 commit 70d2f8c
15 files changed
Lines changed: 4134 additions & 29 deletions
File tree
- packages
- opencode/src
- cli/cmd/tui
- context
- routes/session
- config
- id
- server/routes
- session
- sdk
- js/src/v2/gen
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
| 198 | + | |
197 | 199 | | |
198 | 200 | | |
199 | 201 | | |
| |||
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
| 211 | + | |
209 | 212 | | |
210 | 213 | | |
211 | 214 | | |
| |||
225 | 228 | | |
226 | 229 | | |
227 | 230 | | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
228 | 248 | | |
229 | 249 | | |
230 | 250 | | |
| |||
266 | 286 | | |
267 | 287 | | |
268 | 288 | | |
| 289 | + | |
269 | 290 | | |
270 | 291 | | |
271 | 292 | | |
| |||
319 | 340 | | |
320 | 341 | | |
321 | 342 | | |
| 343 | + | |
322 | 344 | | |
323 | 345 | | |
324 | 346 | | |
| |||
431 | 453 | | |
432 | 454 | | |
433 | 455 | | |
434 | | - | |
435 | 456 | | |
436 | 457 | | |
437 | 458 | | |
| |||
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
162 | 166 | | |
163 | 167 | | |
164 | 168 | | |
| |||
465 | 469 | | |
466 | 470 | | |
467 | 471 | | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
468 | 485 | | |
469 | 486 | | |
470 | 487 | | |
| |||
Lines changed: 145 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
16 | 18 | | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 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 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
63 | 137 | | |
64 | 138 | | |
65 | 139 | | |
| |||
102 | 176 | | |
103 | 177 | | |
104 | 178 | | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
105 | 186 | | |
106 | 187 | | |
107 | 188 | | |
| |||
111 | 192 | | |
112 | 193 | | |
113 | 194 | | |
114 | | - | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
115 | 199 | | |
116 | 200 | | |
117 | 201 | | |
| |||
167 | 251 | | |
168 | 252 | | |
169 | 253 | | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
170 | 294 | | |
171 | 295 | | |
172 | 296 | | |
173 | 297 | | |
174 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
175 | 302 | | |
176 | 303 | | |
177 | 304 | | |
| |||
215 | 342 | | |
216 | 343 | | |
217 | 344 | | |
218 | | - | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
219 | 349 | | |
220 | 350 | | |
221 | 351 | | |
| |||
234 | 364 | | |
235 | 365 | | |
236 | 366 | | |
237 | | - | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
238 | 371 | | |
239 | 372 | | |
240 | 373 | | |
| |||
288 | 421 | | |
289 | 422 | | |
290 | 423 | | |
291 | | - | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
292 | 431 | | |
293 | 432 | | |
294 | 433 | | |
| |||
0 commit comments