oudecheng 4ce89f8d82 feat(tools): 新增持久 PTY 会话工具替代管道式交互式 shell
- 新增 PtyTool:spawn/write/read/kill/list 五操作管理真实伪终端会话(portable-pty)

- PtySessionManager:活动续期 TTL 惰性回收、ANSI 剥离、增量读取游标

- kill 走完整 Child::kill() 语义(Unix SIGHUP→宽限→SIGKILL),spawn_blocking 执行

- 修复:write_input 不再持管理器锁跨阻塞 IO;kill 前 drain 管道尾部输出;watcher 改 try_lock

- 移除 shell_session.rs 管道式实现;前端 Tools/Subagents 页补充 PTY 条目
2026-08-21 08:30:44 +08:00

113 lines
4.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pub mod adapter;
pub mod adapters;
pub mod context;
pub mod handler;
pub mod handlers;
pub mod response;
use serde::{Deserialize, Serialize};
/// 统一命令枚举 - 与渠道无关
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum Command {
/// 创建新话题(在同一个 Session 内)
CreateSession { title: Option<String> },
/// 保存当前话题内容到 Markdown 文件
SaveTopic {
filepath: Option<String>,
include_subagents: bool,
},
/// 保存会话内容到 Markdown 文件
SaveSession {
filepath: Option<String>,
include_all: bool,
include_subagents: bool,
},
/// 列出当前 Session 的所有话题
ListSessions { include_archived: bool },
/// 加载指定话题
LoadTopic { topic_id: String },
/// 切换到指定话题(清理当前历史并加载新话题)
SwitchTopic { topic_id: String },
/// 获取当前话题信息
GetCurrentSession,
/// 显示所有支持的命令
Help,
/// 列出所有可用通道
ListChannels,
/// 列出指定通道的所有会话
ListSessionsByChannel {
channel_name: String,
include_archived: bool,
},
/// 列出 Session 的所有 Topics
ListTopics { session_id: String },
/// 加载子智能体任务的消息历史
LoadTaskMessages { task_id: String },
/// 列出所有定时任务
ListSchedulerJobs,
/// 加载指定 channel + chat_id 的对话消息
LoadChatMessages { channel: String, chat_id: String },
/// 分页加载话题更早的历史消息(用户向上滚动触发)
LoadOlderMessages { topic_id: String, before_seq: i64 },
/// 删除指定话题
DeleteTopic { topic_id: String },
/// 重命名指定话题
RenameTopic { topic_id: String, title: String },
/// 停止当前正在执行的 Agent
StopExecution,
/// 列出所有记忆
ListMemories,
/// 创建新记忆
CreateMemory {
namespace: String,
key: String,
content: String,
},
/// 更新已有记忆
UpdateMemory { id: String, content: String },
/// 删除记忆
DeleteMemory { id: String },
/// 列出所有技能
ListSkills,
/// 列出当前 Todo 列表
ListTodos {
/// 子代理的 task_id进入子代理视图时传入
#[serde(default)]
task_id: Option<String>,
},
}
impl Command {
/// 获取命令名称(用于日志和调试)
pub fn name(&self) -> &'static str {
match self {
Command::CreateSession { .. } => "create_session",
Command::SaveTopic { .. } => "save_topic",
Command::SaveSession { .. } => "save_session",
Command::ListSessions { .. } => "list_sessions",
Command::LoadTopic { .. } => "load_topic",
Command::SwitchTopic { .. } => "switch_topic",
Command::GetCurrentSession => "get_current_session",
Command::Help => "help",
Command::ListChannels => "list_channels",
Command::ListSessionsByChannel { .. } => "list_sessions_by_channel",
Command::ListTopics { .. } => "list_topics",
Command::LoadTaskMessages { .. } => "load_task_messages",
Command::ListSchedulerJobs => "list_scheduler_jobs",
Command::LoadChatMessages { .. } => "load_chat_messages",
Command::LoadOlderMessages { .. } => "load_older_messages",
Command::DeleteTopic { .. } => "delete_topic",
Command::RenameTopic { .. } => "rename_topic",
Command::StopExecution => "stop_execution",
Command::ListMemories => "list_memories",
Command::CreateMemory { .. } => "create_memory",
Command::UpdateMemory { .. } => "update_memory",
Command::DeleteMemory { .. } => "delete_memory",
Command::ListSkills => "list_skills",
Command::ListTodos { .. } => "list_todos",
}
}
}