Kill publish_context_state() — screens lock the agent directly

F1 and F2 screens now call agent.context_state_summary() directly
via try_lock/lock instead of reading from a shared RwLock cache.
Removes SharedContextState, publish_context_state(), and
publish_context_state_with_scores().

Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
Kent Overstreet 2026-04-07 03:03:24 -04:00
parent 48c843234d
commit 04e260c081
6 changed files with 30 additions and 64 deletions

View file

@ -16,18 +16,22 @@ use super::{App, ScreenView, screen_legend};
use crate::agent::context::ContextSection;
pub(crate) struct ConsciousScreen {
agent: std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>,
scroll: u16,
selected: Option<usize>,
expanded: std::collections::HashSet<usize>,
}
impl ConsciousScreen {
pub fn new() -> Self {
Self { scroll: 0, selected: None, expanded: std::collections::HashSet::new() }
pub fn new(agent: std::sync::Arc<tokio::sync::Mutex<crate::agent::Agent>>) -> Self {
Self { agent, scroll: 0, selected: None, expanded: std::collections::HashSet::new() }
}
fn read_context_state(&self, app: &App) -> Vec<ContextSection> {
app.shared_context.read().map_or_else(|_| Vec::new(), |s| s.clone())
fn read_context_state(&self) -> Vec<ContextSection> {
match self.agent.try_lock() {
Ok(ag) => ag.context_state_summary(None),
Err(_) => Vec::new(),
}
}
fn item_count(&self, context_state: &[ContextSection]) -> usize {
@ -121,7 +125,7 @@ impl ScreenView for ConsciousScreen {
for event in events {
if let ratatui::crossterm::event::Event::Key(key) = event {
if key.kind != ratatui::crossterm::event::KeyEventKind::Press { continue; }
let context_state = self.read_context_state(app);
let context_state = self.read_context_state();
let item_count = self.item_count(&context_state);
match key.code {
@ -171,7 +175,7 @@ impl ScreenView for ConsciousScreen {
if !app.status.context_budget.is_empty() {
lines.push(Line::raw(format!(" Budget: {}", app.status.context_budget)));
}
let context_state = self.read_context_state(app);
let context_state = self.read_context_state();
if !context_state.is_empty() {
let total: usize = context_state.iter().map(|s| s.tokens).sum();
lines.push(Line::raw(""));