diff --git a/src/agent/mod.rs b/src/agent/mod.rs index ea3f614..f620af8 100644 --- a/src/agent/mod.rs +++ b/src/agent/mod.rs @@ -851,10 +851,6 @@ impl Agent { } /// Called after any change to context state (working stack, etc). - fn refresh_context_state(&mut self) { - self.publish_context_state(); - } - /// Load working stack from disk. fn load_working_stack(&mut self) { if let Ok(data) = std::fs::read_to_string(working_stack::file_path()) { @@ -886,7 +882,7 @@ impl Agent { /// Replace base64 image data in older messages with text placeholders. /// Keeps the 2 most recent images live (enough for motion/comparison). /// The tool result message before each image records what was loaded. - fn age_out_images(&mut self) { + pub fn age_out_images(&mut self) { // Find image entries newest-first, skip 1 (caller is about to add another) let to_age: Vec = self.context.entries.iter().enumerate() .rev() diff --git a/src/mind/mod.rs b/src/mind/mod.rs index 47c7161..3f3a158 100644 --- a/src/mind/mod.rs +++ b/src/mind/mod.rs @@ -24,10 +24,9 @@ use tokio::sync::{mpsc, Mutex}; use crate::agent::{Agent, TurnResult}; use crate::agent::api::ApiClient; -use crate::agent::api::types as api_types; use crate::config::{self, AppConfig, SessionConfig}; use crate::user::{self as tui}; -use crate::user::ui_channel::{self, ContextInfo, StatusInfo, StreamTarget, UiMessage}; +use crate::user::ui_channel::{self, StatusInfo, StreamTarget, UiMessage}; use crate::subconscious::learn; /// Compaction threshold — context is rebuilt when prompt tokens exceed this. @@ -373,6 +372,13 @@ impl Mind { crate::user::event_loop::cmd_switch_model(&self.agent, &name, &self.ui_tx).await; } + // Post-turn maintenance + { + let mut ag = self.agent.lock().await; + ag.age_out_images(); + ag.publish_context_state(); + } + cmds.push(MindCommand::Compact); if !self.config.no_agents { cmds.push(MindCommand::Score); diff --git a/src/user/event_loop.rs b/src/user/event_loop.rs index dae2c3a..fc1ddf3 100644 --- a/src/user/event_loop.rs +++ b/src/user/event_loop.rs @@ -13,7 +13,6 @@ use tokio::sync::Mutex; use crate::agent::Agent; use crate::agent::api::ApiClient; -use crate::config::SessionConfig; use crate::user::{self as tui, HotkeyAction}; use crate::user::ui_channel::{self, UiMessage};