Skip to main content

matrixcode_core/command/handlers/
new.rs

1//! /new 命令实现
2//!
3//! 开始新会话。
4
5use super::super::backend_context::BackendContext;
6use super::super::command_trait::Command;
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>(
24        &'a self,
25        ctx: &'a mut BackendContext<'_>,
26    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = bool> + Send + 'a>> {
27        Box::pin(async move {
28            if let Some(mgr) = ctx.session_mgr {
29                // Start new session with None project path
30                if let Err(e) = mgr.start_new(None) {
31                    let _ = ctx
32                        .event_tx
33                        .send(crate::AgentEvent::error(
34                            format!("Failed to start new session: {}", e),
35                            None,
36                            None,
37                        ))
38                        .await;
39                }
40            }
41            ctx.agent.clear_history();
42
43            let _ = ctx
44                .event_tx
45                .send(crate::AgentEvent::progress("✓ New session started", None))
46                .await;
47
48            false // 不转发给 agent
49        })
50    }
51}