Split context_state_summary: ContextBudget for compaction, UI-only for display

context_state_summary() was used for both compaction decisions (just
needs token counts) and debug screen display (needs full tree with
labels). Split into:

- Agent::context_budget() -> ContextBudget: cheap token counting by
  category, used by compact(), restore_from_log(), mind event loop
- ContextBudget::format(): replaces sections_budget_string() which
  fragily pattern-matched on section name strings
- context_state_summary(): now UI-only, formatting code stays here

Also extracted entry_sections() as shared helper with include_memories
param — false for context_state_summary (memories have own section),
true for conversation_sections_from() (subconscious screen shows all).

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-07 19:02:58 -04:00
parent 9e49398689
commit cf1c64f936
4 changed files with 130 additions and 86 deletions

View file

@ -863,8 +863,7 @@ impl ScreenView for InteractScreen {
agent.expire_activities();
app.status.prompt_tokens = agent.last_prompt_tokens();
app.status.model = agent.model().to_string();
let sections = agent.context_state_summary();
app.status.context_budget = crate::agent::context::sections_budget_string(&sections);
app.status.context_budget = agent.context_budget().format();
app.activity = agent.activities.last()
.map(|a| a.label.clone())
.unwrap_or_default();