Repository navigation
feat: /compact summarizes earlier messages so long conversations keep fitting the context - #144
Merged
Merged
Conversation
…ps fitting the model's context; the reader still sees every message, with a divider that opens the summary
This was referenced Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
A long conversation used to send every message to the model on every request; nothing ever made it smaller.
/compactnow summarizes the earlier part of a conversation so it keeps fitting the model's context. The reader still sees every message, with a divider that opens the summary.The algorithm is ported from pi's coding agent (
packages/coding-agent/src/core/compaction):compactionmessage is appended to the conversation (aCustomAgentMessagesentry), recording the summary andfirstKept, the stored position of the first message kept as is. Nothing is rewritten, and the IndexedDB schema is unchanged.transformContextsends[system messages…, <summary>, messages from firstKept…]. Every system message is kept, because pi-agent-core declares tool changes with system messages in the middle of the transcript. Memory's transform runs after the projection.<previous-summary>. A reply that stops forlength, an error, or a tool call fails the compaction and records nothing.Automatic compaction and overflow recovery come next, as a separate change.
Files
core/agent/compaction.ts: message type, projection, cut point, serialization. All pure functions, with tests.features/assistant/compaction.ts: prompts, pluscompactConversation, which calls the model.create-reader-agent.ts,use-conversation.ts,conversation-panel.tsx,conversation-messages.tsx,token-usage.ts,styles.css: wiring, the/compactcommand, thecompactingphase and the divider.Testing
pnpm checkpasses.brennock-light.mdwith one key fact per chapter:/compactbrought it to 19.6K. The cut fell inside the first turn (firstKept=16), so only a turn-prefix summary was made, with the fileId, chapter line ranges, ranges read and key records preserved./compactupdated the previous summary (firstKept=18), giving 19.9K./compacton a two-message conversation shows "Nothing to compact yet".