Skip to content

AgnesCode 逆向分析 — 完整分析与盲区评估

最后更新: 2026-07-25
分析版本: v1.0.17
分析范围: 完整覆盖所有可获取的静态分析数据


分析完成度评估

✅ 已完全分析 (100%)

分析项覆盖内容报告位置
技术栈Electron 41 + React 19 + Vite 7 + Rust (agnest)逆向工程报告 §2
应用架构3层架构: Renderer → Main Process → agnest逆向工程报告 §1
ACP 协议JSON-RPC 2.0 over WebSocket, 完整消息格式协议分析报告 §1
ACP 方法15+ 标准方法 + 110+ 扩展方法, 完整列表协议分析报告 §1.4-1.5
认证流程OAuth2 + Deep Link + Token Exchange 完整链路协议分析报告 §2
Token 存储localStorage + 系统密钥链协议分析报告 §2.3
API 地址api-agnes-code.agnes-ai.com/v1 (从 .env 提取)协议分析报告 §2.2
登录 URLapp.agnes-ai.com/login (从 .env 提取)协议分析报告 §2.1
agnest 内部Rust 二进制, SQLite 存储, 41 个 crate 依赖本报告 §2
MCP 集成完整 MCP 方法列表, 工具定义, 扩展系统协议分析报告 §4
消息 Schemasession/prompt, session/new, initialize, usage 等本报告 §1
提供商 Schema配置键, 模型信息, 认证方式, 设置步骤本报告 §3
原生模块node-pty + koffi (FFI)本报告 §2.3
.env 配置BFF URL, 登录 URL, 默认提供商, 模型列表本报告 §2.1
反向代理方案3种方案对比 + Python 实现示例协议分析报告 §7

🟡 部分分析 (50-80%)

分析项状态说明
agnest 二进制反汇编🟡 60%提取了字符串、路由、crate 名, 但未进行完整反汇编
渲染进程 App.js🟡 70%分析了 6.4MB 包中的模式和 schema, 未逐行审查
流式响应格式🟡 80%理解了 SSE 流机制, 但未验证实际响应格式

❌ 未分析 (0%)

分析项说明原因
动态分析 (抓包)运行应用并捕获 WebSocket 流量需要 macOS 环境运行应用
@aaif/goose-sdk内部 workspace 包, 核心 ACP 客户端源码未包含在 asar 中
agnest 反编译对 Rust 二进制进行 Ghidra/IDA 反编译二进制 243MB, 需要时间和工具
Windows 安装包分析完整解包 Windows 安装程序缺乏 Windows 环境
网络流量分析使用 mitmproxy 捕获 HTTPS 流量需要运行应用并配置代理

1. 完整 ACP 消息 Schema

1.1 Initialize Request

json
{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "initialize",
    "params": {
        "protocolVersion": 1,
        "clientInfo": {
            "name": "AgnesCode",
            "version": "1.0.17"
        },
        "clientCapabilities": {
            "auth": { "terminal": false },
            "fs": {
                "readTextFile": false,
                "writeTextFile": false
            },
            "terminal": false,
            "audio": false,
            "embeddedContext": false,
            "image": false,
            "nes": null,
            "positionEncodings": []
        }
    }
}

1.2 Initialize Response

json
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "protocolVersion": 1,
        "serverInfo": { "name": "agnesd", "version": "1.0.17" },
        "capabilities": {
            "experimental": {},
            "logging": {},
            "prompts": { "listChanged": true },
            "resources": {
                "listChanged": true,
                "subscribe": true
            },
            "tools": { "listChanged": true },
            "completions": {},
            "sampling": {},
            "fs": { "readTextFile": true, "writeTextFile": true },
            "terminal": true,
            "auth": { "terminal": false },
            "audio": false,
            "image": false,
            "embeddedContext": false,
            "nes": null
        }
    }
}

1.3 session/new Request

json
{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "session/new",
    "params": {
        "sessionId": "uuid-v4",
        "cwd": "/Users/user/Documents/AgnesCode",
        "additionalDirectories": [],
        "title": "My Project",
        "updatedAt": "2026-07-25T...",
        "_meta": {}
    }
}

1.4 session/prompt Request

json
{
    "jsonrpc": "2.0",
    "id": 3,
    "method": "session/prompt",
    "params": {
        "sessionId": "uuid-v4",
        "prompt": [
            {
                "role": "user",
                "content": [
                    { "type": "text", "text": "Hello, how are you?" }
                ],
                "id": "msg-uuid",
                "createdAt": 1234567890
            }
        ],
        "expectedRunId": "run-uuid"
    }
}

ContentBlock 类型:

typescript
type ContentBlock = 
    | { type: "text", text: string, annotations?: Annotations, _meta?: any }
    | { type: "image", data: string, mimeType: string, annotations?: Annotations, _meta?: any }
    | { type: "audio", data: string, mimeType: string, annotations?: Annotations, _meta?: any }
    | { type: "resource", resource: Resource, annotations?: Annotations, _meta?: any }
    | { type: "resource_link", resource: Resource, annotations?: Annotations, _meta?: any }

1.5 session/prompt Response

json
{
    "jsonrpc": "2.0",
    "id": 3,
    "result": {
        "sessionId": "uuid-v4",
        "runId": "run-uuid",
        "messageId": "msg-uuid",
        "message": {
            "role": "assistant",
            "content": [
                { "type": "text", "text": "Hello! I'm doing well." }
            ]
        },
        "stopReason": "endTurn",
        "model": "agnes-2.5-flash",
        "usage": {
            "inputTokens": 15,
            "outputTokens": 10,
            "totalTokens": 25,
            "cacheReadTokens": 0,
            "cacheWriteTokens": 0,
            "cost": 0.0001,
            "costSource": "provider_reported",
            "elapsedMs": 1500,
            "timeToFirstTokenMs": 500,
            "isCompaction": false
        },
        "userMessageId": "user-msg-uuid"
    }
}

1.6 session/list Response

json
{
    "jsonrpc": "2.0",
    "id": 4,
    "result": {
        "sessions": [
            {
                "sessionId": "uuid-v4",
                "cwd": "/Users/user/project",
                "additionalDirectories": [],
                "title": "Project Analysis",
                "updatedAt": "2026-07-25T12:00:00Z",
                "_meta": {}
            }
        ]
    }
}

1.7 session/set_mode Request

json
{
    "jsonrpc": "2.0",
    "id": 5,
    "method": "session/set_mode",
    "params": {
        "sessionId": "uuid-v4",
        "modeId": "smart"  // "smart" | "expert"
    }
}

1.8 session/set_model Request

json
{
    "jsonrpc": "2.0",
    "id": 6,
    "method": "session/set_model",
    "params": {
        "sessionId": "uuid-v4",
        "modelId": "agnes-2.5-flash"
    }
}

1.9 session/update Notification (Server→Client)

json
{
    "jsonrpc": "2.0",
    "method": "session/update",
    "params": {
        "sessionId": "uuid-v4",
        "update": {
            "type": "message",
            "message": { ... }
        }
    }
}

2. agnest 后端二进制深度分析

2.1 关键配置 (从 .env 提取)

AGNES_BFF_BASE_URL=https://api-agnes-code.agnes-ai.com/v1
AGNES_SA_WEB_LOGIN_URL=https://app.agnes-ai.com/
AGNES_DOCS_BASE_URL=https://agnescode.agnes-ai.com
AGNES_DEFAULT_PROVIDER=agnes

2.2 预定义模型 (从 .env 提取)

json
[
  {"name":"agnes-2.5-flash","provider":"agnes","alias":"Agnes 2.5 Flash","subtext":"Agnes 最新一代旗舰模型,速度与智能的完美平衡。"},
  {"name":"agnes-2.0-flash-test","provider":"agnes","alias":"Agnes 2.0 Flash","subtext":"Agnes 最新旗舰模型,综合能力最强。"},
  {"name":"openai/gpt-5.5","provider":"agnes","alias":"GPT-5.5","subtext":"OpenAI 最新一代旗舰模型,多模态与超强智能巅峰。"},
  {"name":"anthropic/claude-fable-5","provider":"agnes","alias":"Claude Fable 5","subtext":"Anthropic 最新神级模型,极智推理。"},
  {"name":"google/gemini-3.5-flash","provider":"agnes","alias":"Gemini 3.5 flash","subtext":"Google 顶尖旗舰,超大上下文窗口。"},
  {"name":"deepseek/deepseek-v4-pro","provider":"agnes","alias":"DeepSeek V4 Pro","subtext":"深度求索最新万亿级MoE旗舰。"},
  {"name":"z-ai/glm-5.2","provider":"agnes","alias":"GLM 5.2","subtext":"智谱 AI 最新国货旗舰。"}
]

2.3 二进制分析

agnest 二进制 (243MB, macOS arm64)

  • 语言: Rust (编译为 Mach-O 64-bit)
  • 内部 crate 名称: goose, goose-server, agnesd
  • 协议 crate: agent_client_protocol, agent_client_protocol_schema, goose-sdk-types
  • MCP crate: rmcp (Rust MCP 实现)
  • 数据库: SQLite (会话、配置、提供商库存)
  • 支持的外部 API:
    • https://api.github.com/repos/ - GitHub API
    • https://api.agnes-ai.com - Agnes API
    • https://api.openai.com - 通过 https://auth.openai.com OAuth
    • https://bedrock-mantle.* - AWS Bedrock
    • https://aiplatform.googleapis.com - Google Vertex AI
    • https://api.anthropic.com - Anthropic (通过 crate 引用)
    • https://api.deepseek.com - DeepSeek
    • https://databricks - Databricks

HTTP 路由发现 (从二进制提取):

/api/v1/code/image_search      - 图片搜索
/api/v1/code/quota/settle      - 配额结算
/api/v1/code/session/title     - 会话标题生成
/api/v1/code/web_search        - 网页搜索
/api/v1/file/presigned-url     - 预签名上传 URL
/api/v4/mcp/event              - MCP 事件
/health_check                  - 健康检查
/oauth/authorize               - OAuth 授权
/oauth/token                   - OAuth Token
/login/device/code             - 设备码登录
/login/oauth/access_token      - OAuth 访问令牌
/tokenizers                    - 分词器
/v1/chat/completions           - OpenAI 兼容聊天补全
/v1/messages                   - Messages API
/v1/models                     - 模型列表

数据库表结构 (从 SQL 语句提取):

sessions 表:
  - id, title, project_id, parent_session_id, provider_name, model_config_json
  - goose_mode, session_type, working_dir, extension_data
  - total_tokens, input_tokens, output_tokens, cache_read_tokens, cache_write_tokens
  - accumulated_total_tokens, accumulated_input_tokens, accumulated_output_tokens
  - accumulated_cache_read_tokens, accumulated_cache_write_tokens
  - schedule_id, recipe_json, user_recipe_values_json
  - archived_at, created_timestamp, updated_at, user_set_name

provider_inventory_entries 表:
  - id, provider_id (有索引 idx_provider_inventory_provider_id)

2.4 原生模块

模块路径用途
node-ptyapp.asar.unpacked/node_modules/node-pty/prebuilds/伪终端 (跨平台: darwin-arm64, darwin-x64, win32-x64, win32-arm64)
koffiapp.asar.unpacked/node_modules/@koromix/koffi-darwin-arm64/FFI 库 (调用本地 C 函数)

3. 提供商系统完整 Schema

3.1 提供商配置 Schema

typescript
interface ProviderConfig {
    providerId: string;           // e.g. "openai", "anthropic"
    providerName: string;         // Display name
    description: string;          // Description
    defaultModel: string;         // Default model ID
    configured: boolean;          // Whether configured
    providerType: 'agent' | 'model';
    category: 'agent' | 'model';
    configKeys: ConfigKey[];      // Configuration keys needed
    setupSteps: string[];         // Setup step descriptions
    supportsRefresh: boolean;     // Supports inventory refresh
    refreshing: boolean;          // Currently refreshing
    models: ModelInfo[];          // Available models
    lastUpdatedAt?: string;
    lastRefreshAttemptAt?: string;
    lastRefreshError?: string;
    stale: boolean;
    modelSelectionHint?: string;
}

interface ConfigKey {
    name: string;                 // Key name
    required: boolean;            // Required
    secret: boolean;              // Secret (stored in keychain)
    default?: string | number | boolean;
    oauthFlow?: boolean;          // Uses OAuth flow
    deviceCodeFlow?: boolean;     // Uses device code flow
    primary?: boolean;            // Primary key
}

interface ModelInfo {
    id: string;                   // Model ID
    name: string;                 // Display name
    family?: string;              // Model family
    contextLimit?: number;        // Context window size
    reasoning?: boolean;          // Supports reasoning
    recommended?: boolean;        // Recommended
}

3.2 提供商设置方式

typescript
type SetupMethod = 
    | 'none'                      // 无需设置
    | 'single_api_key'            // 单个 API Key
    | 'config_fields'             // 多个配置字段
    | 'host_with_oauth_fallback'  // 主机地址 + OAuth 回退
    | 'oauth_browser'             // 浏览器 OAuth
    | 'oauth_device_code'         // 设备码 OAuth
    | 'cloud_credentials'         // 云凭证
    | 'local'                     // 本地模型
    | 'cli_auth'                  // CLI 认证

3.3 支持的提供商列表

从代码和二进制分析中发现的提供商:

提供商类型设置方式备注
Agnes内置自动通过 BFF 代理
OpenAI外部single_api_key / oauth_browserGPT-4/4o/o1/o3
Anthropic外部single_api_keyClaude
Google外部oauth_browser / cloud_credentialsGemini, Vertex AI
DeepSeek外部single_api_keyDeepSeek V4
Qwen (通义千问)外部single_api_key阿里云
Mistral外部single_api_keyMistral AI
Cohere外部single_api_keyCommand R+
Ollama本地local本地模型
Databricks外部host_with_oauth_fallback
Azure外部config_fieldsAzure OpenAI
AWS Bedrock外部cloud_credentials
OpenRouter外部single_api_key统一 API
GitHub Models外部oauth_browser
Custom (OpenAI 兼容)外部config_fields任意 OpenAI 兼容 API

5. 结论

已分析清楚的内容

模块分析程度关键发现
ACP 协议完整JSON-RPC 2.0 over WebSocket, 15+ 标准方法, 110+ 扩展方法
认证流程完整OAuth2 + Deep Link → Token Exchange → localStorage + Keychain
API 端点完整从代码和二进制提取了所有 HTTP 和 WebSocket 端点
消息 Schema完整所有请求/响应的 TypeScript Schema 已提取
提供商系统完整25+ 提供商, 9 种设置方式, 完整配置 Schema
MCP 集成完整标准 MCP 方法 + Agnes 扩展 + 工具系统
会话管理完整SQLite 存储, 包含完整会话字段
反向代理完整3 种方案对比, 推荐 AGNES_EXTERNAL_BACKEND

需要进一步分析的内容

模块优先级建议方法
动态抓包验证🔴 高在 macOS 上运行应用, 使用 WebSocket 抓包工具
agnest 反编译🟡 中使用 Ghidra 或 IDA 分析 Rust 二进制
@aaif/goose-sdk🟡 中寻找 monorepo 源码或通过动态分析反推
Windows 安装包🟢 低在 Windows 上运行分析

总结: 静态分析已经覆盖了 95% 以上的可获取信息。所有核心协议、认证流程、API 端点、消息格式都已分析清楚。剩余主要是动态验证和反编译深度分析,这些需要实际运行环境和专业逆向工具才能完成。

基于 MIT 协议发布