AtomCode Daemon API 处理模块(未覆盖部分)
持续深度分析 — Daemon 内部 API handler 模块、loop_guard、json_repair 2026-06-23
1. Daemon API 处理模块
以下 Daemon crate 的 API handler 模块在之前报告中没有被明确覆盖:
crates/atomcode-daemon/src/
├── api_auth.rs # /auth/* 路由处理
├── api_codingplan.rs # /codingplan/* 路由处理
├── api_config.rs # /config/* 路由处理
├── api_provider.rs # /providers/* 路由处理
├── live_api.rs # /live/* SSE 流路由处理
├── permission_bridge.rs # 权限桥接(TUI ↔ WebUI)
└── telemetry_scope.rs # 遥测作用域管理1.1 api_auth.rs — 认证路由
处理端点:
GET /auth/status → OAuth 登录状态
POST /auth/login/start → 发起 OAuth 登录
POST /auth/login/:id/poll → 轮询登录结果
POST /auth/logout → 登出
功能:
- OAuth 授权码流程
- 登录会话管理(login_id + 过期时间)
- Token 存储(-> ~/.atomcode/auth.json)
- Token 刷新(refresh_token)1.2 api_codingplan.rs — CodingPlan 路由
处理端点:
POST /codingplan/setup → 设置 CodingPlan
功能:
- CodingPlan 计划申领
- 提供商自动配置
- 同步标记管理1.3 api_config.rs — 配置路由
处理端点:
GET /config → 获取配置
POST /config/reload → 从磁盘重载
响应结构体:
ConfigResponse {
default_workdir: String?,
// ...
}1.4 api_provider.rs — 提供商管理路由
处理端点:
GET /providers → 列出所有提供商
POST /providers → 创建提供商 (CreateProviderRequest)
PATCH /providers/:name → 更新提供商 (PatchProviderRequest)
DELETE /providers/:name → 删除提供商
POST /providers/:name/default → 设为默认
功能:
- 提供商 CRUD 操作
- 提供商缓存管理
- 默认提供商设置1.5 live_api.rs — LiveWire SSE 路由
处理端点:
GET /live → SSE 连接(建立长连接)
POST /live/message → 发送消息
POST /live/provider → 切换提供商
POST /live/permission → 响应权限请求
POST /live/reasoning_effort → 设置推理努力级别
功能:
- SSE 事件流管理
- 多会话支持(?session_id=xxx)
- 事件广播1.6 permission_bridge.rs — 权限桥接
功能:
- 在 TUI 和 WebUI 之间桥接权限请求
- 当 WebUI 用户需要审批工具调用时通知 TUI
- 当 TUI 用户审批时同步到 WebUI
流:
WebUI: POST /live/permission { session_id, decision, tool_name }
→ permission_bridge → TUI 同步
TUI: 用户确认 → permission_bridge → WebUI 同步1.7 telemetry_scope.rs — 遥测作用域
功能:
- 管理 daemon 会话的遥测作用域
- 与 crates/atomcode-telemetry/ 交互
- 追踪 daemon 启动/停止事件
事件:
- daemon 启动 → 创建遥测 session
- daemon 停止 → 刷新遥测队列
- 错误 → 标记遥测错误事件2. 回合系统模块
2.1 loop_guard.rs — 循环守卫
crates/atomcode-core/src/turn/loop_guard.rs
功能:
检测并阻止 LLM 的无限循环调用
检测模式:
"[Loop guard] This exact tool call (...)"
分析:
- 相同工具 + 相同参数重复 N 次
- 工具调用无结果变化(read-only loop)
- incrementing/decrementing call ID patterns
响应:
- 触发 loop_detected 信号
- 中断当前回合
- 提示用户或自动纠正2.2 json_repair.rs — JSON 修复
crates/atomcode-core/src/turn/json_repair.rs
功能:
修复 LLM 输出的损坏 JSON
使用场景:
- LLM 返回截断的 JSON
- LLM 返回格式错误的 JSON(多余逗号、缺失引号)
- LLM 返回嵌套过深的 JSON
策略:
- 尝试标准 JSON.parse
- 失败 → 尝试修复(补齐括号、清理尾随逗号)
- 失败 → 提取 JSON 片段3. version_check.rs — 版本检查
crates/atomcode-core/src/version_check.rs
功能:
检查 AtomCode 版本兼容性
检查:
- 当前版本 vs CodingPlan 所需最低版本
- 下载 latest.json 从 AtomGit
- 版本号比较
消息:
"AtomCode is out of date and no longer compatible with CodingPlan"
"An upgrade is required to continue using CodingPlan"
"This feature requires the official AtomCode build"
"#fetching latest.json returned HTTP ..."
端点:
https://atomgit.com/atomgit_atomcode/atomcode/releases
https://raw.atomgit.com/atomgit_atomcode/atomcode/raw/main/latest.json4. 插件系统模块
4.1 bootstrap.rs — 插件引导
crates/atomcode-core/src/plugin/bootstrap.rs
功能:
- 启动时加载已安装插件
- 执行插件注册
- 初始化本地插件目录4.2 installer.rs — 插件安装器
crates/atomcode-core/src/plugin/installer.rs
功能:
- 从 marketplace 下载插件
- 验证插件签名
- 解压到 plugins/ 目录
- 更新 installed_plugins.json4.3 self_update.rs — 自升级
crates/atomcode-core/src/self_update.rs
功能:
- 下载新版本二进制到 staged/
- 验证 staged 二进制 (SHA256 + 大小)
- 原子替换: rename → mv
- 备份旧版本到 atomcode.bak
- 失败回滚
原子写:
atomic_write: NamedTempFile::new_in(...)5. setup 子系统
5.1 setup/scan.rs — 项目扫描
crates/atomcode-core/src/setup/scan.rs
功能:
- 扫描项目目录
- 检测语言/框架(Cargo.toml, package.json, go.mod 等)
- 生成安装建议
- 返回扫描结果给 setup skill6. uninstall/actions.rs — 卸载动作
crates/atomcode-core/src/uninstall/actions.rs
卸载模式:
normal — 保留数据
purge — 清除 ~/.atomcode/
keep-data — 仅删除二进制 + PATH 编辑
dry-run — 仅打印计划
执行:
- 移除二进制文件
- 从 shell rc 移除 PATH 编辑
- 可选: 删除 ~/.atomcode/7. 新覆盖的盲区
| # | 之前未覆盖的领域 | 状态 | 发现 |
逆向命令索引
bash
# 提取所有 daemon 源文件
strings atomcode.bin.bak | grep "^crates/atomcode-daemon/src/" | sort -u
# 输出: 10 个文件
# 提取处理函数路由
strings atomcode.bin.bak | grep -E "axum|Router|route" | grep -v "https\?://\|crates/" | sort -u | head -10
# 提取 axum 框架错误信息
strings atomcode.bin.bak | grep -iE "Cannot merge.*Router|Adding a route_layer|no route for" | sort -u
# 输出:
# Cannot merge two `Router`s that both have a fallback
# Adding a route_layer before any routes is a no-op
# no route for id. This is a bug in axum.|---|-----------------|------|------| | 1 | Daemon API 7 处理模块 | ✅ | api_auth/api_codingplan/api_config/api_provider/live_api/permission_bridge/telemetry_scope | | 2 | loop_guard 循环守卫 | ✅ | 检测重复工具调用模式 | | 3 | json_repair JSON 修复 | ✅ | 修复截断/格式错误的 LLM JSON | | 4 | version_check 版本检查 | ✅ | CodingPlan 兼容性检查 | | 5 | plugin/bootstrap + installer | ✅ | 插件加载与安装 | | 6 | setup/scan 项目扫描 | ✅ | 语言/框架自动检测 | | 7 | uninstall/actions 卸载 | ✅ | 4 种模式 + 完整动作 |
本报告由持续分析循环生成 — 覆盖剩余的 crate 路径盲区