Skip to main content

Module compaction

Module compaction 

Source
Expand description

Compaction: summarize older context when the window fills, keeping a recent tail. Also branch summarization support for /tree navigation.

Structs§

CompactionPlan
Cut-point decision for a compaction pass.
SummaryOutcome

Constants§

SUMMARY_FORMAT

Functions§

estimate_context_tokens
Estimated context size: prefer the last assistant usage (input+output+ cache) and add estimates for everything after it.
estimate_message_tokens
estimate_tokens_text
chars/4 heuristic, matching pi’s estimator for messages without usage.
extract_file_ops
Extract read/modified file paths from tool calls in the messages.
file_ops_details
Details payload stored on compaction/branch-summary entries.
generate_summary
Generate a structured summary with the LLM. One-off prompt: fresh session id and no cache writes wanted, so it’s a plain request.
plan_compaction
Choose the cut point: walk back from the newest message accumulating estimates until keep_recent_tokens, then snap to a turn boundary.
serialize_agent_messages
Serialize agent messages for summarization (convert then serialize).
serialize_conversation
Serialize a conversation to labeled text for the summary prompt. Tool results are capped so summarization stays cheap.
should_compact
Whether auto-compaction should trigger.