matrixcode_core/command/handlers/
new.rs1use super::super::backend_context::BackendContext;
6use super::super::command_trait::Command;
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>(
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 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 })
50 }
51}