matrixcode_core/command/handlers/
new.rs1use super::super::command_trait::Command;
6use super::super::backend_context::BackendContext;
7
8pub 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 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 })
43 }
44}