mind: unify MindCommand, add command queue pattern

MindCommand replaces both Action and MindMessage — one type for
everything: turns, compaction, scoring, hotkeys, new session.

State methods return MindCommand values. The run loop collects
commands into a Vec, then drains them through run_commands().
Compact and Score now flow through the same command path as
everything else.

Removes execute(), MindMessage from event_loop. Mind's run loop
is now: select! → collect commands → run_commands().

mind/mod.rs: 957 → 516 lines.

Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2026-04-05 03:34:43 -04:00
parent 07ca136c14
commit 01b07a7f28
2 changed files with 115 additions and 105 deletions

View file

@ -17,12 +17,7 @@ use crate::config::SessionConfig;
use crate::user::{self as tui, HotkeyAction};
use crate::user::ui_channel::{self, UiMessage};
/// Messages from the UI to the Mind.
pub enum MindMessage {
Hotkey(HotkeyAction),
NewSession,
Score,
}
pub use crate::mind::MindCommand;
fn send_help(ui_tx: &ui_channel::UiSender) {
let commands = &[
@ -189,7 +184,7 @@ pub async fn run(
shared_mind: crate::mind::SharedMindState,
turn_watch: tokio::sync::watch::Receiver<bool>,
mind_tx: tokio::sync::mpsc::UnboundedSender<MindMessage>,
mind_tx: tokio::sync::mpsc::UnboundedSender<MindCommand>,
ui_tx: ui_channel::UiSender,
mut ui_rx: ui_channel::UiReceiver,
mut observe_input_rx: tokio::sync::mpsc::UnboundedReceiver<String>,
@ -272,6 +267,18 @@ pub async fn run(
if cur.turn_active != prev_mind.turn_active {
dirty = true;
}
if cur.scoring_in_flight != prev_mind.scoring_in_flight {
if !cur.scoring_in_flight && prev_mind.scoring_in_flight {
let _ = ui_tx.send(UiMessage::Info("[scoring complete]".into()));
}
dirty = true;
}
if cur.compaction_in_flight != prev_mind.compaction_in_flight {
if !cur.compaction_in_flight && prev_mind.compaction_in_flight {
let _ = ui_tx.send(UiMessage::Info("[compacted]".into()));
}
dirty = true;
}
prev_mind = cur;
}
@ -319,7 +326,7 @@ pub async fn run(
let _ = ui_tx.send(UiMessage::Info("(busy)".into()));
}
}
"/new" | "/clear" => { let _ = mind_tx.send(MindMessage::NewSession); }
"/new" | "/clear" => { let _ = mind_tx.send(MindCommand::NewSession); }
"/dmn" => {
let s = shared_mind.lock().unwrap();
let _ = ui_tx.send(UiMessage::Info(format!("DMN: {:?} ({}/{})", s.dmn, s.dmn_turns, s.max_dmn_turns)));
@ -336,7 +343,7 @@ pub async fn run(
shared_mind.lock().unwrap().dmn_pause();
let _ = ui_tx.send(UiMessage::Info("DMN paused.".into()));
}
"/score" => { let _ = mind_tx.send(MindMessage::Score); }
"/score" => { let _ = mind_tx.send(MindCommand::Score); }
"/retry" => {
let agent = agent.clone();
let sm = shared_mind.clone();
@ -371,8 +378,8 @@ pub async fn run(
match action {
HotkeyAction::CycleReasoning => cmd_cycle_reasoning(&agent, &ui_tx),
HotkeyAction::KillProcess => cmd_kill_processes(&agent, &ui_tx).await,
HotkeyAction::Interrupt => { let _ = mind_tx.send(MindMessage::Hotkey(action)); }
HotkeyAction::CycleAutonomy => { let _ = mind_tx.send(MindMessage::Hotkey(action)); }
HotkeyAction::Interrupt => { let _ = mind_tx.send(MindCommand::Hotkey(action)); }
HotkeyAction::CycleAutonomy => { let _ = mind_tx.send(MindCommand::Hotkey(action)); }
HotkeyAction::AdjustSampling(param, delta) => cmd_adjust_sampling(&agent, param, delta),
}
}