Skip to main content

Module compaction

Module compaction 

Source
Expand description

Conversation compaction — turn a long message history into a structured summary.

Structs§

AppliedCompaction
What the engine applied. Pure data — the frontend adopts these fields; all persistence already happened (successor-first save ordering).
CompactionDisclosure
The pre-dispatch disclosure summary (spec §9.4): provider, model, and approximate disclosure every frontend surfaces BEFORE remote compaction.
CompactionOutcome
Typed result of a summarization call (spec §9.3): the summary text plus the provenance metadata the transition persists.
CompactionTransition
Frontend-supplied context for one transition.
DisclosurePolicy
Disclosure policy for one compaction (spec §9.4): where summarization runs and which content classes are withheld from the request.
RenderedCompactionInput
The policy-filtered summarization input, computable WITHOUT any network operation — this is what disclosure previews and the dispatch path share, so what the user inspects is exactly what would be sent.

Enums§

CompactionPolicy
How a successful compaction is applied to session state (spec §9.2).
TransitionFailpoint
Deterministic failure-injection points inside the linked-successor transition (I2, CP-12 review). The enum is always available so rollback code can name the steps; the injection machinery is test-gated.

Constants§

COMPACTION_SYSTEM_PROMPT
System prompt used for the compaction API call. Instructs the model to summarize, not continue the conversation.
LOCAL_SUMMARY_MODEL
Model label for the local extractive summarizer.

Functions§

apply_compaction
Task 30 (spec §9.2): the ONE engine operation applying a successful compaction for every frontend. Handles successor-vs-in-place policy, session id and chain advancement, accounting, typed provenance, pending events and queued messages, hooks, save ordering, and rollback: nothing is returned (and no caller state changes) unless the new state was persisted, so a failed save leaves the prior session intact.
compact_conversation
Serialize the in-memory API message history into a policy-filtered transcript and produce the typed CompactionOutcome. Remote mode asks the configured summarizer model; local-only mode (spec §9.4) derives the summary in-process and constructs NO network request. Called by /compact and every auto-compaction path.
preview_compaction_disclosure
Compute the disclosure summary for the next compaction WITHOUT any network operation. Uses the same rendering as the dispatch path, so the preview is exact for content classes and approximate only in bytes.
provider_label_for_model
Provider label for a model, derived from its resolved route (bare model names route to Anthropic). Unroutable models are labeled honestly.
render_compaction_input
Render the summarization request under a disclosure policy. Pure — no network, no provider dependence. Sentinel-tested per class: excluded classes must not appear in prompt_text.
transitions_applied
Read the process-wide applied-transition count (see [TRANSITIONS_APPLIED]). Test/diagnostic seam: harnesses assert the counter moves exactly once per transition and not at all for summarization without a transition.