feat: Collapse Compaction maintains agent intelligence beyond compaction by preserving recent interactions and curating knowledge collapsing the older stale messages #6374
+759
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.






Summary
Adds a new "collapse" compaction mode that preserves recent context while summarizing older messages.
The problem: Standard compaction compresses the entire conversation into a tiny summary, causing massive context loss (100% -> 3%). The AI forgets everything.
The solution: Collapse only compresses the OLD, stale parts while keeping current work pristine:
Changes
packages/opencode/src/session/compaction.ts- Main collapse logic withprocessCollapse(), token estimation, and markdown conversionpackages/opencode/src/id/id.ts- AddcreateLike()for inserting messages at past timestamps,detectFormat()for backward compatibilitypackages/opencode/src/session/message-v2.ts- UpdatefilterCompacted()for breakpoint detectionpackages/opencode/src/config/config.ts- New config options (method, trigger, extractRatio, recentRatio)packages/opencode/src/cli/cmd/tui/routes/session/- TUI toggle and sidebar displaypackages/opencode/src/server/server.ts- Unified flow for both modespackages/opencode/src/cli/cmd/tui/ui/link.tsx- Fix underline prop error from fix(tui): make auth URLs clickable regardless of line wrapping #6317Configuration
{ "compaction": { "method": "collapse", "trigger": 0.85, "extractRatio": 0.65, "recentRatio": 0.15 } }Default remains "standard" - users can opt-in to collapse via config or TUI toggle (Ctrl+P -> "Use collapse compaction").
Testing
compaction.methodto"collapse"in config or toggle via TUI