Automatic compaction fires mid-conversation, right after the loop warmed the provider's KV cache with the last routed request. The default summarizer then issued a separate request whose prefix shared nothing with that warm request — a bespoke summarizer system prompt followed by the older history flattened to one rendered transcript string — so a differing first token invalidated the entire cached prefix and every compaction re-processed the whole replayed history twice. Move the compaction directive from the FRONT (a fresh system prompt) to the END (a trailing user message), and replay the last routed request's own system prompt, tools, message prefix, and shadowed-region messages verbatim via session.requestHeader() + deriveEventMessage. The auxiliary call is now a genuine prefix-extension of the warm request, so the provider reuses the cached tokens up to the trailing instruction. SummarizationInput carries the replayed prefix instead of a flat string; the now-unused renderTranscript/renderContentBlocks path is removed with its spec. Cache reuse is best-effort (head compaction guarantees a hit; a mid-range compaction or a differently-routed summarizer forgoes it), correctness is not.
compact/ — compaction capability family
A compaction capability family (see capability seams): an abstract interface, a summarizing backend, a model-free tool-result pruning companion, and a deferred model-facing consumer. All product packages.
| Package | Role | ctx key |
|---|---|---|
compact/ |
Abstract compaction seam (interface + compact/* events + CompactionResult) |
ctx.compact |
compact-basic/ |
A backend: ctx.tokenMeter pressure + token-budget retention + llm.stream() summarization |
(registers ctx.compact) |
compact-tool-result-prune/ |
Optional model-free head/middle/tail rewriting before summary compaction | ctx.toolResultPrune |
tool-compact/ (deferred) |
Model-facing /compact tool over ctx.compact |
(registers on ctx.tools) |
The interface lives at compact/compact/, the backend at compact/compact-basic/, and deterministic pruning at compact/compact-tool-result-prune/. Unlike the bash seam, the interface depends on dsh-session and dsh-llm because its verbs are defined over a Session and its output uses ContentBlock. That deviation is recorded in the compaction capability-seam Agent Note. Token measurement remains a reusable LLM-family service; a template- or model-backed compactor can replace compact-basic without changing the meter, pruner, or callers.