附录 · Daemon API 逆向工程命令索引
本文档收集第三章(Daemon API)所有报告中使用的逆向工程命令与样本输出 日期: 2026-06-29
1. API 端点发现
bash
# 从二进制提取所有 API 路由
strings atomcode.bin.bak | grep -E "^/[a-z]" | sort -u
# 输出包含:
# /auth/login
# /auth/logout
# /auth/status
# /auth/refresh
# /chat
# /chat/permission
# /config
# /config/reload
# /health
# /live
# /live/message
# /live/provider
# /live/permission
# /live/reasoning_effort
# /models
# /projects
# /project
# /providers
# /sessions
# /skills
# /fs/list
# /fs/mkdir
# /cd
# /tunnel/status
# 提取指定长度以上的(避免短噪声)
strings -n 10 atomcode.bin.bak | grep -E "^/[a-z]" | sort -u2. 健康检查运行时验证
bash
# 健康检查
curl -s http://localhost:13456/health | jq .
# 输出示例:
{
"status": "ok",
"version": "4.25.5",
"service": "atomcode-daemon",
"binary_hash": "aabede8376de761431c049c12a31c1c2ff6f2b44c72b5a302904a5e4de21f9d8"
}
# 带 token 的健康检查
TOKEN=$(python3 -c "
import tomllib
with open('$HOME/.atomcode/auth.toml','rb') as f:
print(tomllib.load(f)['access_token'])
")
curl -s -H "Authorization: Bearer $TOKEN" http://localhost:13456/health | jq .3. SSE 流抓取(完整协议验证)
bash
# 捕获完整 SSE 流
curl -N -X POST http://localhost:13456/chat \
-H "Authorization: Bearer $(cat ~/.atomcode/auth.toml | grep access_token | cut -d'"' -f2)" \
-H "Content-Type: application/json" \
-d '{"session_id":"capture-001","message":"写一个hello world"}' \
-o /tmp/sse_capture.txt 2>&1
# 分析 SSE 事件类型分布
grep '"type"' /tmp/sse_capture.txt | grep -oP '"type":"[^"]*"' | sort | uniq -c | sort -rn
# 输出示例:
# 5 "type":"reasoning"
# 2 "type":"tokens"
# 1 "type":"text"
# 1 "type":"tool_start"
# 1 "type":"tool_result"
# 1 "type":"done"
# 查看 tool_start 参数格式
python3 -c "
import json
with open('/tmp/sse_capture.txt') as f:
for line in f:
if line.startswith('data: '):
d = json.loads(line[6:])
if d.get('type') == 'tool_start':
print(json.dumps(d, indent=2))
"4. SSE 事件格式提取
bash
# 提取 SSE 事件类型枚举
strings atomcode.bin.bak | grep -E "\"type\":\"[a-z_]+\"" | sed 's/.*"type":"\([^"]*\)".*/\1/' | sort -u
# 输出:
# done
# error
# permission_request
# provider
# reasoning
# snapshot
# state
# stopped
# text
# tokens
# tool_output
# tool_result
# tool_start
# user5. 所有 API 处理模块路径
bash
strings atomcode.bin.bak | grep "^crates/atomcode-daemon/src/" | sort -u
# 输出:
# crates/atomcode-daemon/src/api_auth.rs
# crates/atomcode-daemon/src/api_codingplan.rs
# crates/atomcode-daemon/src/api_config.rs
# crates/atomcode-daemon/src/api_provider.rs
# crates/atomcode-daemon/src/auth_token.rs
# crates/atomcode-daemon/src/lib.rs
# crates/atomcode-daemon/src/live_api.rs
# crates/atomcode-daemon/src/permission_bridge.rs
# crates/atomcode-daemon/src/telemetry_scope.rs
# crates/atomcode-daemon/src/webui.rs6. 请求/响应结构体提取
bash
# 提取所有 Chat/API 相关结构体
strings atomcode.bin.bak | grep -E "struct Chat|struct Live[A-Z]|struct [A-Za-z]*Req|struct [A-Za-z]*Resp|struct [A-Za-z]*Request" | sort -u
# 输出:
# struct ChatChunk with 2 elements
# struct ChatCompletionResponse with 2 elements
# struct ChatRequest with 5 elements
# struct LiveMessageReq with 4 elements
# struct LivePermissionReq with 2 elements
# struct LiveProviderReq with 1 element
# struct StopChatRequest with 1 element
# struct RenameRequest with 1 element
# struct ChangeDirRequest with 2 elements
# struct FsMkdirRequest with 1 element
# struct CreateProviderRequest with 16 elements
# struct PatchProviderRequest with 19 elements
# struct PatchThinkingRequest with 6 elements
# struct CodingPlanSetupRequest with 1 element7. daemon 启动参数提取
bash
# 提取 daemon 子命令参数
strings atomcode.bin.bak | grep -E "daemon|Daemon|port.*listen|ATOMCODE_DAEMON" | grep -v "https\?://\|struct\|crates/" | sort -u | head -20
# 输出:
# daemon
# Port to listen on (default: 13456)
# Start the HTTP daemon for IDE integration
# Daemon
# --port 13456📅 生成: 2026-06-29