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

@ -215,7 +215,6 @@ impl Mind {
config: SessionConfig,
turn_tx: mpsc::Sender<(Result<TurnResult>, StreamTarget)>,
) -> Self {
let shared_context = crate::agent::context::shared_context_state();
let shared_active_tools = crate::agent::tools::shared_active_tools();
let client = ApiClient::new(&config.api_base, &config.api_key, &config.model);
@ -230,7 +229,6 @@ impl Mind {
config.app.clone(),
config.prompt_file.clone(),
conversation_log,
shared_context,
shared_active_tools,
);
let agent = Arc::new(tokio::sync::Mutex::new(ag));
@ -278,7 +276,7 @@ impl Mind {
MindCommand::Compact => {
let threshold = compaction_threshold(&self.config.app) as usize;
let mut ag = self.agent.lock().await;
let sections = ag.shared_context.read().map(|s| s.clone()).unwrap_or_default();
let sections = ag.context_state_summary(None);
if crate::agent::context::sections_used(&sections) > threshold {
ag.compact();
ag.notify("compacted");
@ -312,13 +310,12 @@ impl Mind {
self.config.session_dir.join("conversation.jsonl"),
).ok();
let mut ag = self.agent.lock().await;
let shared_ctx = ag.shared_context.clone();
let shared_tools = ag.active_tools.clone();
*ag = Agent::new(
ApiClient::new(&self.config.api_base, &self.config.api_key, &self.config.model),
self.config.system_prompt.clone(), self.config.context_parts.clone(),
self.config.app.clone(), self.config.prompt_file.clone(),
new_log, shared_ctx, shared_tools,
new_log, shared_tools,
);
}
}
@ -366,11 +363,8 @@ impl Mind {
// Compact if over budget before sending
let threshold = compaction_threshold(&self.config.app) as usize;
ag.publish_context_state();
let used = {
let sections = ag.shared_context.read().map(|s| s.clone()).unwrap_or_default();
crate::agent::context::sections_used(&sections)
};
let used = crate::agent::context::sections_used(
&ag.context_state_summary(None));
if used > threshold {
ag.compact();
ag.notify("compacted");
@ -435,7 +429,6 @@ impl Mind {
{
let mut ag = self.agent.lock().await;
ag.age_out_images();
ag.publish_context_state();
}
cmds.push(MindCommand::Compact);