mind: move CycleAutonomy to event_loop, simplify MindCommand
CycleAutonomy just flips DMN state — handled directly in event_loop by locking shared MindState. MindCommand::Hotkey replaced with MindCommand::Interrupt — the only command that needs Mind's async context (abort handles, kill processes). Remove dmn_interval() wrapper — inline self.dmn.interval(). MindCommand is now: Turn, Compact, Score, Interrupt, NewSession, None. Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
402bae4178
commit
2d6a17e773
2 changed files with 10 additions and 15 deletions
|
|
@ -66,8 +66,8 @@ pub enum MindCommand {
|
||||||
Compact,
|
Compact,
|
||||||
/// Run memory scoring
|
/// Run memory scoring
|
||||||
Score,
|
Score,
|
||||||
/// Hotkey action
|
/// Abort current turn, kill processes
|
||||||
Hotkey(crate::user::HotkeyAction),
|
Interrupt,
|
||||||
/// Reset session
|
/// Reset session
|
||||||
NewSession,
|
NewSession,
|
||||||
/// Nothing to do
|
/// Nothing to do
|
||||||
|
|
@ -91,11 +91,7 @@ impl MindState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dmn_interval(&self) -> Duration {
|
/// Consume pending input, return a Turn command if ready.
|
||||||
self.dmn.interval()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Consume pending input, return a Turn action if ready.
|
|
||||||
pub fn take_pending_input(&mut self) -> MindCommand {
|
pub fn take_pending_input(&mut self) -> MindCommand {
|
||||||
if self.turn_active || self.input.is_empty() {
|
if self.turn_active || self.input.is_empty() {
|
||||||
return MindCommand::None;
|
return MindCommand::None;
|
||||||
|
|
@ -252,7 +248,7 @@ impl Mind {
|
||||||
self.start_memory_scoring();
|
self.start_memory_scoring();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MindCommand::Hotkey(crate::user::HotkeyAction::Interrupt) => {
|
MindCommand::Interrupt => {
|
||||||
self.shared.lock().unwrap().interrupt();
|
self.shared.lock().unwrap().interrupt();
|
||||||
let ag = self.agent.lock().await;
|
let ag = self.agent.lock().await;
|
||||||
let mut tools = ag.active_tools.lock().unwrap();
|
let mut tools = ag.active_tools.lock().unwrap();
|
||||||
|
|
@ -262,10 +258,6 @@ impl Mind {
|
||||||
self.shared.lock().unwrap().turn_active = false;
|
self.shared.lock().unwrap().turn_active = false;
|
||||||
let _ = self.turn_watch.send(false);
|
let _ = self.turn_watch.send(false);
|
||||||
}
|
}
|
||||||
MindCommand::Hotkey(crate::user::HotkeyAction::CycleAutonomy) => {
|
|
||||||
self.shared.lock().unwrap().cycle_autonomy();
|
|
||||||
}
|
|
||||||
MindCommand::Hotkey(_) => {}
|
|
||||||
MindCommand::NewSession => {
|
MindCommand::NewSession => {
|
||||||
self.shared.lock().unwrap().dmn_sleep();
|
self.shared.lock().unwrap().dmn_sleep();
|
||||||
let new_log = log::ConversationLog::new(
|
let new_log = log::ConversationLog::new(
|
||||||
|
|
@ -351,7 +343,7 @@ impl Mind {
|
||||||
mut turn_rx: mpsc::Receiver<(Result<TurnResult>, StreamTarget)>,
|
mut turn_rx: mpsc::Receiver<(Result<TurnResult>, StreamTarget)>,
|
||||||
) {
|
) {
|
||||||
loop {
|
loop {
|
||||||
let timeout = self.shared.lock().unwrap().dmn_interval();
|
let timeout = self.shared.lock().unwrap().dmn.interval();
|
||||||
let turn_active = self.shared.lock().unwrap().turn_active;
|
let turn_active = self.shared.lock().unwrap().turn_active;
|
||||||
|
|
||||||
let mut cmds = Vec::new();
|
let mut cmds = Vec::new();
|
||||||
|
|
|
||||||
|
|
@ -377,8 +377,11 @@ pub async fn run(
|
||||||
match action {
|
match action {
|
||||||
HotkeyAction::CycleReasoning => cmd_cycle_reasoning(&agent, &ui_tx),
|
HotkeyAction::CycleReasoning => cmd_cycle_reasoning(&agent, &ui_tx),
|
||||||
HotkeyAction::KillProcess => cmd_kill_processes(&agent, &ui_tx).await,
|
HotkeyAction::KillProcess => cmd_kill_processes(&agent, &ui_tx).await,
|
||||||
HotkeyAction::Interrupt => { let _ = mind_tx.send(MindCommand::Hotkey(action)); }
|
HotkeyAction::Interrupt => { let _ = mind_tx.send(MindCommand::Interrupt); }
|
||||||
HotkeyAction::CycleAutonomy => { let _ = mind_tx.send(MindCommand::Hotkey(action)); }
|
HotkeyAction::CycleAutonomy => {
|
||||||
|
let label = shared_mind.lock().unwrap().cycle_autonomy();
|
||||||
|
let _ = ui_tx.send(UiMessage::Info(format!("DMN → {} (Ctrl+P to cycle)", label)));
|
||||||
|
}
|
||||||
HotkeyAction::AdjustSampling(param, delta) => cmd_adjust_sampling(&agent, param, delta),
|
HotkeyAction::AdjustSampling(param, delta) => cmd_adjust_sampling(&agent, param, delta),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue