78 Commits

Author SHA1 Message Date
oudecheng
fc3a95b152 feat: 异步子代理 v8 实现与 /stop 取消流程修复
后端核心实现:
- 新增 wait_coordinator:释放/重获取 serial_lock 的 in-tool waiting 模式,替代旧的 break-exit 方案
- 新增 wait_for_subagents 工具:select! 等待子代理完成/用户消息/超时,支持 try_drain 批量消费
- task 工具异步 spawn 路径:CancellationToken 注册表 + RAII guard + Semaphore 并发限流
- process exit 安全检查:pending 子代理存在时抑制 ExecutionCompleted
- 崩溃恢复:启动时标记 running->interrupted,history 加载时对账占位

/stop 取消流程修复:
- wait_coordinator select! 添加 cancel 分支,完整清理状态
- ToolContext 注入 cancel_rx(watch::Receiver clone)
- agent_loop 工具执行 select! 对 wait 工具跳过竞速,防止 drop coordinator 清理逻辑
- 子代理完成状态通过 execution_completed metadata 传播

存储层:
- pending_subagents 表 + 条件 UPDATE
- mark_all_running_as_interrupted 崩溃恢复
2026-08-13 22:12:20 +08:00
oudecheng
29060315a3 feat(observability): 端到端可观测性整改,修复 trace_id 断链与指标配对
- 传播 trace_id:BusToolCallEmitter/SubAgentEmitter/processor 全链路设置

- AgentEnd 配对:补发 5 个 cancel/defensive 路径,闭合 AgentStart 指标

- LLM 计时修正:attempt_start 移入 retry 循环,排除退避等待时间

- /metrics auth:非 loopback 部署时纳入 Bearer token 校验

- recorder 复用:OnceLock 缓存 PrometheusHandle,热重启后不再返回 503

- 结构化日志:新增 tracing_ctx + JSON 日志格式支持
2026-08-12 08:26:42 +08:00
oudecheng
3e97ed903c feat(mcp): 为 MCP 工具调用增加超时保护,默认 5 分钟
在 McpToolWrapper 适配层用 tokio::time::timeout 包裹 call_tool,防止外部 MCP server 挂起导致 agent loop 无限阻塞。超时时间通过 config.mcp_tool_timeout_secs 配置(默认 300 秒,0=不超时),前端 McpTab 设置页提供输入框。
2026-08-11 21:53:07 +08:00
oudecheng
f26ec49182 chore: 修复 release 构建的编译器警告
- 为 regex::Captures 补全显式生命周期标注
- 将仅用于 debug 日志的局部变量 (media_count/len/total) 用 cfg(debug_assertions) 条件化
- 为仅 debug 读取的 AnthropicProvider::llm_timeout_secs 字段添加 cfg_attr allow(dead_code)
2026-08-07 14:36:27 +08:00
oudecheng
79d099a3bc chore(compaction): 调整压缩阈值默认值
工程化压缩阈值 threshold_ratio: 0.7 → 0.5(50%)
LLM 压缩阈值 llm_compaction_threshold_ratio: 0.5 → 0.3(30%)

降低触发门槛使压缩更积极介入,减少上下文溢出风险。
同步更新相关注释、日志信息和前端 hint 文案。
2026-08-07 11:53:54 +08:00
oudecheng
510520e08e refactor: 提取公共工具函数,修复飞书正则重复编译和网关路由DRY问题,添加CI安全审计 2026-08-07 08:33:15 +08:00
oudecheng
7b459b8ca1 feat(config): 压缩算法关键参数暴露到设置页面
将 4 个压缩参数(threshold_ratio、llm_compaction_threshold_ratio、
truncate_max_tokens、preserve_count)从硬编码提取到 config.json 顶层
compaction 节,前端新增 CompactionTab 供用户调整。

后端:
- config: 新增 CompactionConfig 结构体,Config 新增 compaction 字段
- context_compressor: 4 个参数内聚到 ContextCompressor 实例字段;
  新增 with_compaction_config() 构造函数和 truncate_tool_results() 方法;
  对用户配置做防御性 clamp(ratio ∈ [0.1,1.0],整数 ≥ 1)
- agent_loop: 调用 compressor.truncate_tool_results() 实现零参数耦合
- agent_factory: 新增 build_compressor() 方法,in-loop 与 sync 兜底
  两条压缩路径共用同一套用户配置
- session: with_factories 改用 agent_factory.build_compressor(),修复
  sync 压缩路径忽略用户配置的 P0 问题

前端:
- types: 新增 CompactionConfig 接口,TabId 新增 'compaction'
- 新建 CompactionTab.tsx,4 个 number input 分两组 SectionCard
- constants + ConfigPage: 注册"上下文压缩" Tab(Archive 图标)

清理:删除无调用方的 from_provider_config/from_runtime_config/with_config
方法及 DEFAULT_THRESHOLD_RATIO/LLM_COMPACTION_THRESHOLD_RATIO 常量。

测试:context_compressor 18 + session 31 + agent_loop 42 全通过。
2026-08-06 11:03:56 +08:00
oudecheng
fa420b713f feat(gateway): 添加 HTTP API 认证与 CORS 防护,修复密钥泄露风险
- 新增 auth_token 配置项:非 loopback 绑定强制认证,loopback 可选加固
- 新增 auth.rs:loopback 判定(IpAddr 解析)、常量时间 token 比较、RFC 6750 Bearer 解析
- 新增 Bearer token 中间件(/api/*)与 WebSocket ?token= 校验
- 新增 CORS layer:loopback 镜像 Origin 防 DNS rebinding,非 loopback permissive
- 修复 .gitignore 遗漏 tests/test.env,补充通用 *.env 规则
- 修复前端 experts/skills/subagents.ts 直接 fetch 不带 token(13 处),统一走 authedFetch
- config.json host 从 0.0.0.0 改回 127.0.0.1
- mask_config/save_config 处理 auth_token 掩码与保留
- ConnectionTab/GatewayTab 增加认证 token 配置入口
2026-08-05 22:41:00 +08:00
oudecheng
457f6b2408 feat(retry): 为 LLM 主调用添加可配置重试机制,默认 3 次
- config: ProviderConfig 增加 max_retries 字段(serde default=3,向后兼容)
- config: LLMProviderConfig 透传 max_retries,不进 ProviderRuntimeConfig(保持 provider 构造包纯净)
- agent: AgentRuntimeConfig 增加 max_retries,归属 agent 行为层
- agent_loop: 流式 + summary 两个调用点实现重试循环
  - 指数退避 1s/2s/4s,仅对 429/502/503/504/timeout/connection reset 重试
  - 流式仅在未 emit delta 时重试(AtomicBool 跟踪),避免重复输出
  - 退避 sleep 期间响应 cancel_signal,取消优先
- 前端: ProviderConfig 类型和表单增加 max_retries 字段
- 测试: 7 个单元测试(3 判定 + 4 行为),540 个 lib 测试全绿
2026-08-04 12:53:33 +08:00
oudecheng
cda14360af chore: 建立工程化基线(rustfmt + clippy + CI + eslint + prettier)
配置:
- rustfmt.toml: 固化 max_width=100 / 4 空格缩进,cargo fmt 全量格式化
- Cargo.toml: 配置 [lints.rust] 与 [lints.clippy] 渐进式规则
- .github/workflows/ci.yml: Rust(fmt+clippy+test) + 前端(eslint+tsc+test) 双平台 CI
- Makefile: 新增 check/fmt/fix 目标,clippy 对齐 --all-targets --all-features
- web: eslint flat config + prettier 配置 + package.json 脚本与依赖
- src/main.rs: loop→while 修复 clippy::never_loop

对抗性审查发现并修复:
- eslint 缺 caughtErrorsIgnorePattern 导致 catch(_) 误报为 error
- 前端 lint 未接入 CI,现已补上 Lint 步骤
- Makefile 与 CI 的 clippy flags 不一致,已对齐
2026-08-03 23:24:02 +08:00
oudecheng
389e222b11 feat: 默认 max_tool_iterations 调整为 1000 2026-08-03 14:46:49 +08:00
oudecheng
dc9211548a feat(model): 专家和子代理支持独立配置 provider/model
- 新增 ModelResolver 解析器,按 frontmatter 中的 provider/model 名覆盖基础 LLMProviderConfig

- Expert/SubagentDef 数据结构新增 provider/model 字段,frontmatter 解析与渲染支持往返

- AgentFactory 和 DefaultSubAgentRuntime 持有 ModelResolver,在创建 agent 时解析模型覆盖

- HTTP API 新增 /api/model-options 端点,ExpertResponse/Create/Update 和 SubagentUpdateRequest 支持 provider/model

- update_expert/update_subagent 支持 provider/model 字段写回 frontmatter

- 保持架构解耦:ModelResolver 位于 config 底层,不引入新的跨模块依赖
2026-07-30 22:44:10 +08:00
oudecheng
cea4bd3cfb feat: 子代理支持数据驱动的工具过滤(白名单+黑名单),删除内置 explore
SUBAGENT.md frontmatter 新增 denied_tools 黑名单字段,启用已有的 allowed_tools 白名单;新增 ToolRegistry::only 白名单方法;抽取 build_subagent_tools_registry(白名单→黑名单→depth 兜底);安全修复:resume 在 def 失踪时拒绝恢复而非降级为完整工具集(避免权限提升);depth 阈值改为引用 max_nesting_depth 配置;SubagentWithStatus 暴露工具字段供前端只读展示;删除内置 explore 子代理及专属 explore_max_execution_secs 配置(全栈清理);新增 23 个测试覆盖过滤矩阵、frontmatter 解析、状态投影
2026-07-09 14:42:38 +08:00
oudecheng
46a1ca6853 refactor: 修复 3 项 P1 技术债(硬编码 URL / any 类型 / dead_code)
P1-1: 硬编码 wechat URL 抽常量统一两处
  - config/mod.rs: 定义 pub const WECHAT_DEFAULT_BASE_URL
  - cli/init.rs: import 并引用常量,消除字面量重复
  - 消除两处不一致风险(default_wechat_base_url 与 init 向导)

P1-2: ConfigPage any 类型定义具体类型(8 处)
  - types.ts: 新增 FeishuChannelConfig/WechatChannelConfig/ChannelConfig/
    SchedulerJobConfig 类型;jobs?: any[] → SchedulerJobConfig[];
    channels: Record<string, any> → Record<string, ChannelConfig>
  - api/config.ts: 新增 RestartResponse 类型,data: any → RestartResponse
  - ConfigPage.tsx: catch (e: any) ×2 → catch (e: unknown) + 类型守卫;
    as any → as SchedulerConfig['misfire_policy'];
    Record<string, any> → Partial<ChannelConfig>;(ch: any) → (ch: ChannelConfig)

P1-3: dead_code 18 处逐一审查清理
  - 删除 10 处未使用函数/struct(YAGNI 原则):
    context_compressor.rs (into_messages, is_tool_round)
    agent_loop.rs (EmptySkillProvider struct + impl)
    memory_maintenance.rs (run_for_scope)
    session.rs (try_start/finish_background_compaction)
    session_history.rs (try_start/finish_background_compaction)
    tool_registry_factory.rs (shell_session_manager)
    task/runtime.rs (effective_allowed_tools)
  - 保留 8 处 serde 反序列化字段(删除会破坏 JSON 反序列化):
    feishu.rs/openai.rs/anthropic.rs/skills/mod.rs/task/runtime.rs
2026-07-08 14:51:42 +08:00
oudecheng
9d7c1f2e52 feat: 集成专家提示词到网关配置、依赖注入与HTTP API
- config: 新增 ExpertsConfig,默认 sources=[user,project], enabled=true

- AgentFactory: 新增 experts 字段,providers 顺序为 Agent→Skill→Expert→Subagent→Todo

- GatewayState: 持有 Arc<ExpertRuntime>,from_config 中初始化

- runtime: build_session_manager_with_sender 接收 experts 参数

- 路由: 注册 7 个专家 API (list/toggle/create/update/delete/selected/select)

- http: 实现 7 个处理器,支持专家 CRUD 与 session 级选择

- session/cli: 测试便利构造器与 empty_config/build_config 补齐 experts 字段
2026-07-06 18:07:33 +08:00
oudecheng
81c88257c8 feat: 更新模型配置,调整温度和上下文窗口令牌数量;添加启动和停止网关的批处理脚本 2026-07-01 15:11:28 +08:00
oudecheng
f8e7bfcd54 feat: 更新默认提供者配置,修改基础URL和模型ID 2026-07-01 09:29:34 +08:00
oudecheng
4fabbe47e9 feat: 增强MCP集成,支持配置路径和连接重试机制 2026-06-30 10:46:33 +08:00
oudecheng
7d11ab8067 feat: 添加默认配置文件创建功能,确保首次启动时可用 2026-06-29 15:27:22 +08:00
oudecheng
879f5f243a feat(task): 增加子代理最大嵌套深度支持,更新相关文档和提示 2026-06-17 17:55:22 +08:00
oudecheng
631c61fea2 feat(agent): 支持子代理最大嵌套深度控制
- 在配置结构体中新增 max_nesting_depth 字段,设置子代理最大嵌套深度
- 在 AgentFactory、todo_read、todo_write 等处初始化 nesting_depth 字段为 0
- 允许 Task 工具注册,使用 max_nesting_depth 控制子代理嵌套层数
- SubAgentRuntimeConfig 新增 max_nesting_depth 配置项,默认值为 1
- TaskTool 新增 max_nesting_depth 字段和带深度限制的构造函数
- 任务执行时增加嵌套深度校验,超过最大深度返回错误提示,防止无限递归创建子代理
2026-06-17 14:43:55 +08:00
oudecheng
66e40fc714 feat(config): 增加 Feishu 渠道支持及 MCP 服务器管理界面
- 为配置中的 Channel 添加对 Feishu 配置的可变访问接口
- 在 HTTP 掩码和恢复中支持 Feishu 的 app_secret 字段处理
- 在前端配置页面新增 MCP 服务器配置面板,支持多类型参数编辑
- 在前端配置页面新增渠道管理面板,支持 Feishu 和 Wechat 渠道的增删改查
- 优化配置保存后的提示与刷新,提示需要重启服务生效
- 更新模型配置字段提示,使说明更加友好和明确
- 增加界面图标及样式调整,提升用户操作体验
2026-06-16 14:57:22 +08:00
oudecheng
37f417007e feat(gateway): 添加配置管理功能支持敏感信息脱敏
- 实现 API 端点 /api/config 用于获取和保存配置
- 添加配置信息脱敏功能,保护 API 密钥等敏感数据
- 集成配置验证逻辑,确保时区等参数有效性
- 在前端添加完整的配置管理页面界面
- 实现配置项的动态编辑和保存功能
- 添加连接设置功能用于 WebSocket 连接配置
- 提供多标签页界面分别管理不同配置模块
- 实现配置变更后的实时预览和保存确认
2026-06-15 17:22:32 +08:00
99b6f54f67 feat: 更新网关配置,将主机地址从 "0.0.0.0" 修改为 "127.0.0.1" 2026-06-06 16:00:34 +08:00
oudecheng
d1d4998a26 feat: 增加工具结果字符限制,提升处理能力至 100,000 字符 2026-06-04 17:33:01 +08:00
oudecheng
861aa04690 feat: 将 TaskConfig 默认超时时间统一改为60分钟
- default_task_max_execution_secs: 1200 -> 3600 (20分钟 -> 60分钟)
- default_task_explore_max_execution_secs: 600 -> 3600 (10分钟 -> 60分钟)

确保配置层默认值与代码层一致。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-26 08:52:30 +08:00
9ae2813c20 feat: 添加子代理配置,支持自定义子代理定义和运行时管理 2026-05-24 21:35:36 +08:00
b571d7b7b3 feat: 添加图片上下文限制配置,支持最大图片数量和消息轮次限制 2026-05-24 18:06:22 +08:00
4605c2dad3 feat: 重构 MCP 配置,支持 mcpServers 字段,优化工具注册和连接管理 2026-05-24 10:00:25 +08:00
5e04832f20 feat: 更新 MCP 配置和工具适配器,支持 Claude Desktop 格式,优化服务器连接管理 2026-05-23 23:37:45 +08:00
cbb384a4e6 feat: 添加 MCP (Model Context Protocol) 支持,包含客户端管理器和工具适配器 2026-05-23 22:52:36 +08:00
b6f2de053d refactor: 移除会话重置逻辑中的 reset_cutoff_seq 字段,优化会话管理和历史压缩逻辑 2026-05-23 18:38:34 +08:00
b4ef56803f feat: 添加内存维护配置,优化记忆整理逻辑和限制 2026-05-23 16:05:11 +08:00
oudecheng
8f82009c32 feat: 重命名工具名称,简化工具调用接口 2026-05-19 15:18:04 +08:00
6b5d45e3a5 feat: 添加探索类型最大执行时间配置,优化子代理任务执行逻辑 2026-05-16 17:05:03 +08:00
bee1a39a06 feat: add task management tool with subagent support
- Introduced `TaskConfig` struct to manage task-related configurations.
- Implemented `TaskTool` for creating and managing subagents for complex tasks.
- Added `TaskSession` and `TaskRepository` for handling task sessions and persistence.
- Created `DefaultSubAgentRuntime` to execute tasks with timeout and history support.
- Enhanced `ToolContext` to include `subagent_description` for better context tracking.
- Implemented error handling for task execution and session management.
- Updated `ToolRegistryFactory` to register task tools conditionally based on configuration.
- Added prompt builders for subagent tasks to improve interaction clarity.
2026-05-16 16:12:28 +08:00
9bf57c1132 feat: 移除任务管理相关功能,简化工具配置和依赖 2026-05-16 09:08:40 +08:00
020b7aa77a feat: 添加任务管理功能,支持创建和恢复子代理任务,优化任务执行和状态管理 2026-05-16 08:50:15 +08:00
b77fc93d71 Refactor command handling and input adapters
- Removed the `format_session_list` function and related session handling from the client module.
- Simplified command output in the client by removing session-related commands.
- Introduced `ChannelInputAdapter` for parsing channel commands like `/new` and `/save`.
- Updated WebSocket handling to process commands via the new command system.
- Removed deprecated in-chat command handling from the gateway.
- Adjusted tests to reflect changes in command serialization and session handling.
- Enhanced session cleanup and job scheduling in the configuration module.
2026-05-14 22:23:02 +08:00
oudecheng
86ba3b447e feat: 添加会话管理功能,支持会话过期清理;引入 session_ttl_hours 配置项以控制会话存活时间 2026-05-14 15:29:37 +08:00
d4c15e0478 feat: 添加 max_concurrent_requests 配置项,优化并发请求控制;更新 InboundProcessor 以支持信号量控制并发 2026-05-13 21:56:01 +08:00
9d9fa1dc4b feat: 添加 memory_maintenance_timeout_secs 配置,优化内存维护超时设置 2026-05-12 22:11:34 +08:00
daec690f59 feat: 更新会话配置,重命名 session_ttl_hours 为 chat_history_ttl_hours,并调整相关逻辑以支持聊天历史过期管理 2026-05-10 19:29:55 +08:00
33e6b78267 feat: 添加工具配置示例,支持工具启用/禁用功能;更新调度器管理工具描述以支持标准 cron 语法 2026-05-10 13:57:47 +08:00
oudecheng
f4758f8513 feat: 添加平台抽象层,支持跨平台兼容性;更新多个模块以使用临时目录和平台特定路径 2026-05-09 16:59:58 +08:00
oudecheng
e0a7f67dab feat: 添加对 user_openclaw 技能源的支持,更新相关描述和逻辑 2026-05-09 14:38:06 +08:00
oudecheng
ba0e1c2473 feat: 添加对 project_openclaw 技能源的支持,更新相关描述和逻辑 2026-05-09 14:31:38 +08:00
597881f72e feat: Implement WeChatBot SDK with error handling and message protocol
- Add WeChatBotError enum for error handling with various error types.
- Create a Result type alias for easier error management.
- Implement ILinkClient for low-level API interactions including QR code generation, message sending, and updates retrieval.
- Define message types and structures for handling incoming messages and media content.
- Add tests for error handling and message parsing to ensure reliability.

Co-authored-by: Copilot <copilot@github.com>
2026-05-06 14:18:47 +08:00
fa3354db9c feat: add context_window_tokens to model configuration and update related logic
- Introduced context_window_tokens in ModelConfig and LLMProviderConfig structs.
- Updated context window estimation logic in ContextCompressor to use context_window_tokens.
- Modified tests to accommodate new context_window_tokens field.
- Refactored memory maintenance logic into a new memory_maintenance.rs file for better organization.
- Ensured backward compatibility by providing default values where necessary.

Co-authored-by: Copilot <copilot@github.com>
2026-04-28 11:29:06 +08:00
73dab09bfe Refactor code for improved readability and consistency
- Adjusted formatting and indentation in various files for better clarity.
- Consolidated multi-line statements into single lines where appropriate.
- Enhanced error handling messages for better debugging.
- Added a new InboundProcessor struct to handle inbound messages more effectively.
- Updated test cases to ensure they align with the new code structure.
2026-04-28 10:33:31 +08:00