Expand description
Context selection policy: build candidate ledger items and select the working set for a turn.
This is a pure policy layer. It consumes already-loaded candidate sources
(harness fragments, instruction selections, pins, compaction
summaries, transcript entries, skills) and produces a ContextLedger
whose items carry a ContextVisibility and a human-readable reason
for every inclusion or omission decision. Side effects belong to the caller.
§Selection order
- Always-loaded harness context (visible, never evicted by budget).
- Current user turn (visible, outside ordinary budget eviction).
- Active pins (pinned, before ordinary transcript items).
- Applicable closest
AGENTS.mdbefore broader guidance (visible). - Active skill instructions then discovered skill metadata (visible).
- Latest compaction summary (visible) when older transcript turns are omitted; older summaries stay archived.
- Recent transcript entries (visible) within budget, oldest evicted first under pressure.
UI-only and live-only transcript entries are never selected. Items whose
token estimate alone would exceed the available input budget are marked
ContextVisibility::Blocked instead of being silently truncated.
Structs§
- Compaction
Summary Candidate - A compaction summary considered for selection.
- Harness
Candidate - A harness context fragment considered for selection.
- Instruction
Candidate - An instruction source considered for selection.
- Pinned
Candidate - A pinned working-set item considered for selection.
- Selection
Input - All candidate sources for a turn, ready for selection.
- Skill
Candidate - A loaded skill considered for selection.
- Transcript
Candidate - A transcript entry considered for selection.
- User
Turn Candidate - The current user turn, kept outside ordinary budget eviction.
Functions§
- select_
context - Select the context working set for a turn.