mind: double-buffer MindState for UI diffing

UI event loop clones MindState on each render tick, diffs against
the previous copy, and generates status updates from changes. Mind
no longer sends UiMessage::StatusUpdate — state changes are detected
automatically by the UI.

Removes update_status from both Mind and event_loop. DMN state
changes, turn tracking, scoring status all flow through the diff.

Zero UiMessage sends from Mind's run loop for state changes.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-05 03:24:08 -04:00
parent 54cd3783eb
commit 07ca136c14
3 changed files with 24 additions and 33 deletions

View file

@ -130,18 +130,6 @@ fn cmd_adjust_sampling(agent: &Arc<Mutex<Agent>>, param: usize, delta: f32) {
}
}
pub fn update_status(shared: &crate::mind::SharedMindState, ui_tx: &ui_channel::UiSender) {
let s = shared.lock().unwrap();
let _ = ui_tx.send(UiMessage::StatusUpdate(ui_channel::StatusInfo {
dmn_state: s.dmn.label().to_string(),
dmn_turns: s.dmn_turns,
dmn_max_turns: s.max_dmn_turns,
prompt_tokens: 0, completion_tokens: 0,
model: String::new(), turn_tools: 0,
context_budget: String::new(),
}));
}
pub fn send_context_info(config: &crate::config::SessionConfig, ui_tx: &ui_channel::UiSender) {
let context_groups = crate::config::get().context_groups.clone();
let (instruction_files, memory_files) = crate::mind::identity::context_file_info(
@ -216,6 +204,7 @@ pub async fn run(
let mut render_interval = tokio::time::interval(Duration::from_millis(50));
render_interval.set_missed_tick_behavior(tokio::time::MissedTickBehavior::Skip);
let mut dirty = true;
let mut prev_mind = shared_mind.lock().unwrap().clone();
terminal.hide_cursor()?;
@ -266,6 +255,26 @@ pub async fn run(
idle_state.decay_ewma();
app.update_idle(&idle_state);
// Diff MindState — generate UI messages from changes
{
let cur = shared_mind.lock().unwrap().clone();
if cur.dmn.label() != prev_mind.dmn.label() || cur.dmn_turns != prev_mind.dmn_turns {
let _ = ui_tx.send(UiMessage::StatusUpdate(ui_channel::StatusInfo {
dmn_state: cur.dmn.label().to_string(),
dmn_turns: cur.dmn_turns,
dmn_max_turns: cur.max_dmn_turns,
prompt_tokens: 0, completion_tokens: 0,
model: String::new(), turn_tools: 0,
context_budget: String::new(),
}));
dirty = true;
}
if cur.turn_active != prev_mind.turn_active {
dirty = true;
}
prev_mind = cur;
}
while let Ok(notif) = notify_rx.try_recv() {
let tx = channel_tx.clone();
tokio::spawn(async move {