Skip to main content

matrixcode_core/command/handlers/
new.rs

1//! /new 命令实现
2//!
3//! 开始新会话。
4
5use super::super::command_trait::Command;
6use super::super::backend_context::BackendContext;
7
8/// New 命令
9///
10/// 用法:
11/// - /new - 开始新会话
12pub struct New;
13
14impl Command for New {
15    fn name(&self) -> &'static str {
16        "new"
17    }
18
19    fn help(&self) -> Option<&'static str> {
20        Some("开始新会话。用法: /new")
21    }
22
23    fn execute<'a>(&'a self, ctx: &'a mut BackendContext<'_>) 
24        -> std::pin::Pin<Box<dyn std::future::Future<Output = bool> + Send + 'a>> 
25    {
26        Box::pin(async move {
27            if let Some(mgr) = ctx.session_mgr {
28                // Start new session with None project path
29                if let Err(e) = mgr.start_new(None) {
30                    let _ = ctx.event_tx.send(crate::AgentEvent::error(
31                        format!("Failed to start new session: {}", e), None, None
32                    )).await;
33                }
34            }
35            ctx.agent.clear_history();
36            
37            let _ = ctx.event_tx.send(crate::AgentEvent::progress(
38                "✓ New session started", None
39            )).await;
40
41            false // 不转发给 agent
42        })
43    }
44}