Skip to main content

matrixcode_core/command/
backend_context.rs

1//! 后端命令执行上下文
2//!
3//! 包含命令执行所需的共享依赖。
4
5use std::sync::{Arc, Mutex};
6
7use crate::{AgentEvent, Config, SessionManager, agent::Agent, providers::Provider, skills::Skill};
8
9/// 后端命令执行上下文
10///
11/// 包含命令执行所需的所有共享依赖。
12/// 使用生命周期避免不必要的克隆。
13pub struct BackendContext<'a> {
14    /// 原始消息内容
15    pub message: &'a str,
16    /// 事件发送通道
17    pub event_tx: &'a tokio::sync::mpsc::Sender<AgentEvent>,
18    /// 项目路径
19    pub project_path: Option<&'a std::path::PathBuf>,
20    /// 可用技能列表
21    pub skills: &'a [Skill],
22    /// 配置
23    pub config: &'a Config,
24    /// 当前模型
25    pub model: &'a str,
26    /// 会话管理器
27    pub session_mgr: &'a mut Option<SessionManager>,
28    /// 记忆存储
29    pub memory_storage: &'a mut Option<crate::memory::MemoryStorage>,
30    /// Agent 实例
31    pub agent: &'a mut Agent,
32    /// Provider 实例
33    pub provider: &'a dyn Provider,
34    /// 文件监控句柄(可选)
35    pub watcher_handle: Option<&'a Arc<Mutex<Option<tokio::task::JoinHandle<()>>>>>,
36    /// 取消令牌(可选)
37    pub cancel_token: Option<&'a crate::cancel::CancellationToken>,
38}