Repository navigation
feat(agent): preview what a compression would keep, without calling a model - #312
Merged
Merged
Conversation
… model B5's S3. `/compress` was all-or-nothing and silent until it ran: a user had no way to see which turns would be kept, which would be folded into a summary, and what the summary would replace. The partition now exists on its own: `planCompression` computes head, middle, pinned groups, tail, the token estimate and the threshold, and `compressHistory` executes that plan instead of re-deriving it. `/compress preview` reads the same plan and prints it — each kept region with its first lines and size, the middle by token count, and whether automatic compression would fire. Because there is one plan, the preview cannot disagree with the thing it previews; the test asserts the compression's output is the plan's head, summary, pinned and tail in that order. The preview makes no provider call, which is the acceptance that matters most: a preview that asks a model is a compression. It is still refused while a run is active — reading a slice the run goroutine appends to is a data race even when nothing is written. Verified: go test ./... -count=1, 16 packages ok; go vet and gofmt clean; both load-bearing assertions mutation-checked — adding a provider call to the preview fails "the preview called the provider 1 times", and swapping pinned and tail in the compression fails "pinned message 0 differs". Refs #306, #168
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 changed
agent/compression.go: the partition is now a value —compressionPlan(head, middle, pinned, tail,tokens, threshold) produced by
planCompression, with the reason it cannot be built when it cannot.compressHistoryexecutes the plan instead of re-deriving the same boundaries.agent/compression_preview.go(new):CompressionPreview()renders the plan — whether automaticcompression would fire, each kept region's messages (role + first line, capped at 12) and token count,
and the middle's token count. No provider call.
tui/update.go:/compress previewprints it; still refused while a run is active (reading a slice therun appends to is a data race even though nothing is written).
CODEBASE.md(the plan and the preview), roadmap B5 (S1–S3 landed, S4 open), test count1277 → 1285.
Why
A compression is destructive and was opaque until it ran. "What would be kept" is a question with a cheap
answer — the partition — and the preview is that answer. Making the compression execute the same plan is
what keeps the answer true: a second implementation of the boundaries would drift, and the drift would
only be visible after a summary had already replaced the turns.
Verification
go test ./... -count=1→ 16 packagesok;go vetandgofmt -lclean.TestCompressionPreviewCallsNoModelfails withthe preview called the provider 1 times;TestCompressionPreviewMatchesTheCompressionfails withpinned message 0 differs.says why nothing can be compressed (fewer than four turns, disabled, all-pinned middle); the plan and
the compression agree message for message; the over/under-threshold wording;
firstLineclipping; andthe TUI command, including the run guard.
git log --format='%h %G? %s'→G.Honest scope
between the preview and the command (another turn, or a run), the partition changes with it; there is no
reservation.
has no plan at all — compression would do nothing — so the preview reports the reason instead of empty
sections.
/compress previewprints,/compressstill compresses without asking.Follow-ups
Refs #306, #168