matrixcode_core/command/handlers/
mode.rs1use crate::ApproveMode;
6
7use super::super::command_trait::Command;
8use super::super::backend_context::BackendContext;
9
10pub struct Mode;
17
18impl Command for Mode {
19 fn name(&self) -> &'static str {
20 "mode"
21 }
22
23 fn help(&self) -> Option<&'static str> {
24 Some("设置审批模式。用法: /mode:<ask|auto|strict>")
25 }
26
27 fn matches(&self, msg: &str) -> bool {
29 msg.starts_with("/mode:")
30 }
31
32 fn execute<'a>(&'a self, ctx: &'a mut BackendContext<'_>)
33 -> std::pin::Pin<Box<dyn std::future::Future<Output = bool> + Send + 'a>>
34 {
35 Box::pin(async move {
36 let mode_str = ctx.message.strip_prefix("/mode:").unwrap_or("");
37
38 let mode = match mode_str.to_lowercase().as_str() {
39 "ask" | "a" => ApproveMode::Ask,
40 "auto" => ApproveMode::Auto,
41 "strict" => ApproveMode::Strict,
42 _ => {
43 let _ = ctx.event_tx.send(crate::AgentEvent::error(
44 format!("Unknown mode: {}. Use ask/auto/strict", mode_str),
45 None,
46 None,
47 )).await;
48 return false;
49 }
50 };
51
52 ctx.agent.set_approve_mode(mode);
53
54 let mode_name = match mode {
55 ApproveMode::Ask => "ask (default)",
56 ApproveMode::Auto => "auto (no confirmation)",
57 ApproveMode::Strict => "strict (confirm all)",
58 };
59
60 let _ = ctx.event_tx.send(crate::AgentEvent::progress(
61 format!("✓ Mode set to: {}", mode_name),
62 None,
63 )).await;
64
65 false })
67 }
68}