# Claude Code 架构图（中文版）

---

## 1. 系统全景架构图

```mermaid
graph TB
    subgraph UserInterface["🖥️ 用户界面层 (React + Ink)"]
        CLI["CLI 入口<br/>main.tsx<br/>Commander.js"]
        REPL["REPL 交互界面<br/>screens/REPL.tsx"]
        Doctor["诊断界面<br/>screens/Doctor.tsx"]
        Resume["会话恢复<br/>screens/ResumeConversation.tsx"]
        Components["UI 组件 (~144个)<br/>components/"]
        VimMode["Vim 模式<br/>vim/"]
        VoiceInput["语音输入<br/>voice/"]
    end

    subgraph CoreEngine["⚡ 核心引擎层"]
        QE["QueryEngine<br/>LLM API 调用核心<br/>流式响应 / 工具调用循环<br/>思考模式 / 重试逻辑"]
        QueryPipeline["查询管线<br/>query/"]
        Context["上下文管理<br/>context.ts<br/>系统提示词 / 用户上下文"]
        CostTracker["成本追踪<br/>cost-tracker.ts"]
        State["全局状态管理<br/>state/AppStateStore.ts<br/>不可变状态 + Store"]
    end

    subgraph ToolSystem["🔧 工具系统 (43+ 工具)"]
        FileTools["文件工具<br/>FileRead / FileWrite / FileEdit<br/>Glob / Grep"]
        ExecTools["执行工具<br/>Bash / PowerShell"]
        NetTools["网络工具<br/>WebFetch / WebSearch"]
        AgentTool["智能体工具<br/>Agent / Team<br/>SendMessage"]
        TaskTools["任务工具<br/>TaskCreate / Update / Stop<br/>TodoWrite"]
        ModeTools["模式工具<br/>PlanMode / Worktree"]
        ProtoTools["协议工具<br/>MCPTool / LSPTool"]
        OtherTools["其他工具<br/>Skill / Notebook<br/>Sleep / Cron / ToolSearch"]
    end

    subgraph CommandSystem["📋 命令系统 (101+ 命令)"]
        GitCmds["Git 命令<br/>/commit /review /diff<br/>/branch /pr_comments"]
        CtxCmds["上下文命令<br/>/compact /context /memory<br/>/resume /share"]
        ConfigCmds["配置命令<br/>/config /doctor /mcp<br/>/permissions /theme"]
        AuthCmds["认证命令<br/>/login /logout<br/>/oauth-refresh"]
        ExtCmds["扩展命令<br/>/skills /plugin /agents<br/>/vim /voice"]
        PlanCmds["计划命令<br/>/plan /ultraplan"]
        CostCmds["成本命令<br/>/cost /usage"]
    end

    subgraph ServiceLayer["🌐 服务层"]
        APIClient["Anthropic API 客户端<br/>services/api/"]
        MCPService["MCP 服务<br/>Model Context Protocol<br/>服务器连接与管理"]
        LSPService["LSP 服务<br/>Language Server Protocol<br/>代码智能"]
        OAuth["OAuth 2.0 认证<br/>services/oauth/"]
        Analytics["数据分析<br/>GrowthBook + OpenTelemetry"]
        Compact["上下文压缩<br/>services/compact/"]
        Memory["记忆管理<br/>extractMemories /<br/>teamMemorySync"]
        Plugins["插件系统<br/>services/plugins/"]
    end

    subgraph BridgeSystem["🌉 桥接系统 (IDE 集成)"]
        BridgeMain["桥接主循环<br/>bridgeMain.ts"]
        BridgeMsg["消息协议<br/>bridgeMessaging.ts"]
        ReplBridge["REPL 桥接<br/>replBridge.ts"]
        JWTAuth["JWT 认证<br/>jwtUtils.ts"]
        SessionRunner["会话运行器<br/>sessionRunner.ts"]
    end

    subgraph MultiAgent["🤖 多智能体系统"]
        Coordinator["协调器<br/>coordinator/"]
        AgentSpawn["子智能体生成<br/>AgentTool/runAgent.ts<br/>forkSubagent.ts"]
        TeamMgmt["团队管理<br/>TeamCreate / TeamDelete"]
        MsgPass["消息传递<br/>SendMessageTool"]
        TaskMgr["任务管理<br/>tasks/ (6种类型)"]
    end

    subgraph Infrastructure["🏗️ 基础设施"]
        Bootstrap["启动引导<br/>bootstrap/state.ts"]
        Permissions["权限系统<br/>hooks/toolPermission/"]
        Migrations["配置迁移<br/>migrations/"]
        Schemas["Schema 校验<br/>schemas/ (Zod)"]
        Keybindings["快捷键<br/>keybindings/"]
        MemDir["持久记忆<br/>memdir/"]
        Remote["远程会话<br/>remote/"]
        Server["服务器模式<br/>server/"]
        FeatureFlags["特性标志<br/>bun:bundle feature()"]
    end

    CLI --> REPL
    CLI --> Doctor
    CLI --> Resume
    REPL --> QE
    REPL --> Components
    REPL --> State
    Components --> VimMode
    Components --> VoiceInput

    QE --> ToolSystem
    QE --> Context
    QE --> CostTracker
    QE --> QueryPipeline
    QE --> APIClient
    QE --> State

    ToolSystem --> Permissions
    CommandSystem --> CoreEngine

    ServiceLayer --> CoreEngine
    BridgeSystem --> CoreEngine
    BridgeSystem -.->|"双向通信"| IDE["VS Code / JetBrains"]

    MultiAgent --> QE
    AgentSpawn --> QE

    REPL --> CommandSystem
    Infrastructure --> CoreEngine
    Infrastructure --> UserInterface

    style UserInterface fill:#4A90D9,color:#fff
    style CoreEngine fill:#E74C3C,color:#fff
    style ToolSystem fill:#2ECC71,color:#fff
    style CommandSystem fill:#F39C12,color:#fff
    style ServiceLayer fill:#9B59B6,color:#fff
    style BridgeSystem fill:#1ABC9C,color:#fff
    style MultiAgent fill:#E67E22,color:#fff
    style Infrastructure fill:#95A5A6,color:#fff
```

---

## 2. 核心数据流 — Agent 循环

```mermaid
sequenceDiagram
    participant U as 用户
    participant REPL as REPL 界面
    participant QE as QueryEngine
    participant CTX as Context 上下文
    participant API as Anthropic API
    participant PERM as 权限系统
    participant TOOL as 工具执行
    participant MCP as MCP 服务器
    participant LSP as LSP 服务
    participant STATE as AppState

    U->>REPL: 输入消息
    REPL->>QE: submitMessage(prompt)
    
    QE->>CTX: fetchSystemPromptParts()
    CTX-->>QE: SystemPrompt + UserContext
    
    QE->>API: query(messages, tools, systemPrompt)
    
    loop 工具调用循环 (Agentic Loop)
        API-->>QE: 流式响应 (text + tool_use)
        QE->>REPL: yield SDKMessage (实时流)
        
        alt 响应包含 tool_use
            QE->>PERM: canUseTool(tool, input)
            
            alt 权限允许
                PERM-->>QE: allowed
                QE->>TOOL: execute(tool, input)
                
                alt MCP 工具
                    TOOL->>MCP: 调用 MCP 服务器
                    MCP-->>TOOL: 结果
                end
                
                alt LSP 工具
                    TOOL->>LSP: 请求语言服务
                    LSP-->>TOOL: 诊断/定义/引用
                end
                
                TOOL-->>QE: 工具执行结果
                QE->>API: 继续 (追加工具结果)
            else 权限拒绝
                PERM-->>QE: denied
                QE->>API: 继续 (报告拒绝)
            end
        else 纯文本响应
            QE-->>REPL: 最终响应
        end
    end
    
    QE->>STATE: 更新 usage / cost
    QE-->>REPL: 生成器结束
    REPL-->>U: 显示完整响应
```

---

## 3. 工具系统架构

```mermaid
graph TB
    subgraph ToolRegistry["工具注册表 (tools.ts)"]
        GetAll["getAllBaseTools()"]
        GetFiltered["getTools(permissionContext)"]
        FilterDeny["filterToolsByDenyRules()"]
    end

    subgraph BaseTools["基础工具 (始终可用)"]
        BT_Bash["BashTool<br/>Shell 命令执行"]
        BT_Read["FileReadTool<br/>文件读取 (含图片/PDF)"]
        BT_Write["FileWriteTool<br/>文件创建/覆写"]
        BT_Edit["FileEditTool<br/>局部字符串替换"]
        BT_Glob["GlobTool<br/>文件模式匹配"]
        BT_Grep["GrepTool<br/>ripgrep 内容搜索"]
        BT_Agent["AgentTool<br/>子智能体生成"]
        BT_Skill["SkillTool<br/>技能执行"]
        BT_WebF["WebFetchTool<br/>URL 抓取"]
        BT_WebS["WebSearchTool<br/>网页搜索"]
        BT_Todo["TodoWriteTool<br/>Todo 管理"]
        BT_Ask["AskUserQuestionTool<br/>用户交互"]
        BT_Brief["BriefTool<br/>摘要"]
    end

    subgraph CondTools["条件工具 (Feature Gated)"]
        CT_Team["TeamCreate/Delete<br/>需 AGENT_SWARMS"]
        CT_Sleep["SleepTool<br/>需 PROACTIVE/KAIROS"]
        CT_Cron["CronCreate/Delete/List<br/>需 AGENT_TRIGGERS"]
        CT_Remote["RemoteTriggerTool<br/>需 AGENT_TRIGGERS_REMOTE"]
        CT_Monitor["MonitorTool<br/>需 MONITOR_TOOL"]
        CT_WebB["WebBrowserTool<br/>需 WEB_BROWSER_TOOL"]
        CT_LSP["LSPTool<br/>需 ENABLE_LSP_TOOL"]
        CT_Worktree["Enter/ExitWorktree<br/>需 WORKTREE 模式"]
        CT_Workflow["WorkflowTool<br/>需 WORKFLOW_SCRIPTS"]
        CT_Snip["SnipTool<br/>需 HISTORY_SNIP"]
    end

    subgraph TaskTools2["任务工具"]
        TT_Create["TaskCreateTool"]
        TT_Get["TaskGetTool"]
        TT_Update["TaskUpdateTool"]
        TT_List["TaskListTool"]
        TT_Stop["TaskStopTool"]
        TT_Output["TaskOutputTool"]
    end

    subgraph ModeTools2["模式切换工具"]
        MT_Plan["EnterPlanModeTool<br/>ExitPlanModeV2Tool"]
        MT_Worktree["EnterWorktreeTool<br/>ExitWorktreeTool"]
    end

    subgraph ProtoTools2["协议工具"]
        PT_MCP["MCPTool<br/>MCP 服务器调用"]
        PT_LSP["LSPTool<br/>语言服务器"]
        PT_ListRes["ListMcpResourcesTool"]
        PT_ReadRes["ReadMcpResourceTool"]
    end

    subgraph MCPDynamic["MCP 动态工具"]
        MCPConn["MCPConnectionManager"]
        MCPServer["MCP 服务器<br/>(外部进程)"]
    end

    subgraph PluginDynamic["插件动态工具"]
        PluginLoader["Plugin Loader"]
        PluginCmd["插件提供的<br/>命令和工具"]
    end

    GetAll --> BaseTools
    GetAll --> CondTools
    GetFiltered --> GetAll
    GetFiltered --> FilterDeny

    PT_MCP --> MCPConn
    MCPConn --> MCPServer

    PluginLoader --> PluginCmd
    PluginCmd -.->|"注册到"| ToolRegistry

    style ToolRegistry fill:#E74C3C,color:#fff
    style BaseTools fill:#2ECC71,color:#fff
    style CondTools fill:#F39C12,color:#fff
    style MCPDynamic fill:#9B59B6,color:#fff
    style PluginDynamic fill:#1ABC9C,color:#fff
```

---

## 4. 多智能体系统架构

```mermaid
graph TB
    subgraph Leader["主智能体 (Leader)"]
        MainLoop["主循环<br/>QueryEngine.submitMessage()"]
        AppState["AppState<br/>全局状态管理"]
    end

    subgraph AgentTool2["AgentTool (子智能体生成)"]
        Fork["forkSubagent()<br/>创建子进程"]
        RunAgent["runAgent()<br/>运行智能体"]
        ResumeAgent["resumeAgent()<br/>恢复智能体"]
        LoadAgents["loadAgentsDir()<br/>加载自定义智能体定义"]
        BuiltIn["builtInAgents<br/>内置智能体定义"]
        ColorMgr["agentColorManager<br/>颜色分配"]
        AgentMemory["agentMemory<br/>智能体记忆"]
    end

    subgraph TaskTypes["任务类型 (Task.ts)"]
        LocalBash["local_bash<br/>本地 Shell 任务<br/>LocalShellTask"]
        LocalAgent["local_agent<br/>本地 Agent 任务<br/>LocalAgentTask"]
        RemoteAgent["remote_agent<br/>远程 Agent 任务<br/>RemoteAgentTask"]
        Teammate["in_process_teammate<br/>进程内 Teammate<br/>InProcessTeammateTask"]
        Workflow["local_workflow<br/>工作流任务"]
        MonitorMCP["monitor_mcp<br/>MCP 监控任务"]
        Dream["dream<br/>后台思考任务<br/>DreamTask"]
    end

    subgraph TeamSystem["团队系统 (Agent Swarms)"]
        TeamCreate["TeamCreateTool<br/>创建团队"]
        TeamDelete["TeamDeleteTool<br/>删除团队"]
        SendMsg["SendMessageTool<br/>智能体间消息"]
        Coordinator["Coordinator<br/>多智能体编排"]
        NameReg["agentNameRegistry<br/>名称→ID 注册表"]
    end

    subgraph Worktree["Worktree 隔离"]
        EnterWT["EnterWorktreeTool<br/>进入独立 worktree"]
        ExitWT["ExitWorktreeTool<br/>退出 worktree"]
        GitWT["Git Worktree<br/>文件系统隔离"]
    end

    MainLoop -->|"生成子智能体"| AgentTool2
    AgentTool2 --> Fork
    AgentTool2 --> RunAgent
    AgentTool2 --> ResumeAgent
    Fork --> TaskTypes
    RunAgent --> TaskTypes

    MainLoop -->|"团队协作"| TeamSystem
    TeamCreate --> Coordinator
    SendMsg --> NameReg
    
    MainLoop -->|"隔离执行"| Worktree
    EnterWT --> GitWT

    AppState --> NameReg
    AppState --> TaskTypes

    style Leader fill:#E74C3C,color:#fff
    style AgentTool2 fill:#2ECC71,color:#fff
    style TaskTypes fill:#F39C12,color:#fff
    style TeamSystem fill:#9B59B6,color:#fff
    style Worktree fill:#1ABC9C,color:#fff
```

---

## 5. 启动流程

```mermaid
flowchart TD
    Start(["bun run main.tsx"]) --> Prefetch

    subgraph Prefetch["并行预取 (启动优化)"]
        direction LR
        P1["profileCheckpoint()"]
        P2["startMdmRawRead()"]
        P3["startKeychainPrefetch()"]
    end

    Prefetch --> Parse["Commander.js 解析 CLI 参数"]
    Parse --> Init["init() 初始化"]
    
    Init --> InitParallel

    subgraph InitParallel["并行初始化"]
        direction TB
        I1["initializeGrowthBook()<br/>特性标志"]
        I2["fetchBootstrapData()<br/>引导数据"]
        I3["loadPolicyLimits()<br/>策略限制"]
        I4["loadRemoteManagedSettings()<br/>远程托管设置"]
        I5["initBuiltinPlugins()<br/>内置插件"]
        I6["initBundledSkills()<br/>内置技能"]
        I7["initializeLspServerManager()<br/>LSP 管理器"]
    end

    InitParallel --> Migrations["运行配置迁移"]
    Migrations --> CheckMode{运行模式?}

    CheckMode -->|"交互模式"| Interactive
    CheckMode -->|"Headless -p"| Headless
    CheckMode -->|"SDK"| SDK
    CheckMode -->|"Bridge"| Bridge
    CheckMode -->|"KAIROS 助手"| Assistant

    subgraph Interactive["交互模式启动"]
        direction TB
        Auth["认证检查<br/>OAuth / API Key"]
        LoadTools["加载工具<br/>getTools()"]
        LoadCmds["加载命令<br/>getCommands()"]
        LoadMCP["加载 MCP<br/>getMcpToolsCommandsAndResources()"]
        LoadAgents2["加载智能体<br/>getAgentDefinitionsWithOverrides()"]
        Render["React/Ink 渲染<br/>launchRepl()"]
        REPLStart["REPL 主循环<br/>screens/REPL.tsx"]
    end

    subgraph Headless["Headless 模式"]
        H_QE["创建 QueryEngine"]
        H_Submit["submitMessage(prompt)"]
        H_Exit["输出结果并退出"]
    end

    subgraph SDK["SDK 模式"]
        S_Entry["cli.tsx → SDK 入口"]
        S_QE["创建 QueryEngine"]
        S_Stream["流式返回消息"]
    end

    subgraph Bridge["Bridge 模式"]
        B_Init["initReplBridge()"]
        B_Connect["连接 IDE"]
        B_Loop["bridgeMain() 消息循环"]
    end

    subgraph Assistant["KAIROS 助手模式"]
        A_Gate["gate.js 权限检查"]
        A_Start["assistant/index.js 启动"]
        A_Daemon["守护进程模式"]
    end

    Interactive --> Running["运行中"]
    Headless --> Running
    SDK --> Running
    Bridge --> Running
    Assistant --> Running

    style Prefetch fill:#E74C3C,color:#fff
    style InitParallel fill:#2ECC71,color:#fff
    style Interactive fill:#4A90D9,color:#fff
    style Headless fill:#F39C12,color:#fff
    style SDK fill:#9B59B6,color:#fff
    style Bridge fill:#1ABC9C,color:#fff
    style Assistant fill:#E67E22,color:#fff
```

---

## 6. 权限系统

```mermaid
graph LR
    subgraph PermissionFlow["权限检查流程"]
        ToolCall["工具调用请求"] --> PermMode{权限模式?}
        
        PermMode -->|"bypassPermissions"| AutoAllow["自动允许"]
        PermMode -->|"auto"| AutoCheck["自动检查<br/>(基于规则)"]
        PermMode -->|"default"| UserPrompt["提示用户<br/>允许/拒绝/总是允许"]
        PermMode -->|"plan"| PlanMode["计划模式<br/>(只读允许)"]
    end

    subgraph PermissionContext["权限上下文 (ToolPermissionContext)"]
        AllowedPaths["允许的文件路径"]
        DeniedPaths["拒绝的文件路径"]
        AllowedTools["允许的工具列表"]
        DeniedTools["拒绝的工具列表"]
        AdditionalDirs["额外工作目录"]
        MCPAllowlist["MCP 通道白名单"]
    end

    AutoCheck --> RuleMatch{规则匹配?}
    RuleMatch -->|"匹配允许规则"| Allow["✅ 允许"]
    RuleMatch -->|"匹配拒绝规则"| Deny["❌ 拒绝"]
    RuleMatch -->|"无匹配规则"| UserPrompt
    UserPrompt -->|"允许一次"| Allow
    UserPrompt -->|"总是允许"| AllowAndSave["允许 + 保存规则"]
    UserPrompt -->|"拒绝"| Deny

    style PermissionFlow fill:#E74C3C,color:#fff
    style PermissionContext fill:#2ECC71,color:#fff
```

---

## 7. 桥接系统 — IDE 集成

```mermaid
graph LR
    subgraph IDE["IDE 扩展"]
        VSCode["VS Code 扩展"]
        JetBrains["JetBrains 插件"]
    end

    subgraph BridgeLayer["桥接层"]
        BMain["bridgeMain.ts<br/>主循环"]
        BMsg["bridgeMessaging.ts<br/>消息协议"]
        BPerm["bridgePermissionCallbacks<br/>权限回调"]
        BRepl["replBridge.ts<br/>REPL 桥接"]
        BJWT["jwtUtils.ts<br/>JWT 认证"]
        BSession["sessionRunner.ts<br/>会话管理"]
        BTransport["replBridgeTransport<br/>传输层"]
        BDebug["bridgeDebug.ts<br/>调试工具"]
    end

    subgraph Core["Claude Code 核心"]
        QE2["QueryEngine"]
        REPL2["REPL"]
        State2["AppState"]
    end

    IDE <-->|"WebSocket<br/>JWT 认证"| BTransport
    BTransport --> BMain
    BMain --> BMsg
    BMain --> BPerm
    BMain --> BRepl
    BRepl --> BSession
    BSession --> Core

    BPerm -->|"权限请求"| IDE
    IDE -->|"用户决策"| BPerm

    QE2 -->|"事件流"| BMain
    BMain -->|"命令/提示"| QE2
    State2 -->|"状态同步"| BMain

    style IDE fill:#4A90D9,color:#fff
    style BridgeLayer fill:#1ABC9C,color:#fff
    style Core fill:#E74C3C,color:#fff
```

---

## 8. MCP (Model Context Protocol) 集成

```mermaid
graph TB
    subgraph ClaudeCore["Claude Code"]
        MCPTool2["MCPTool<br/>工具调用入口"]
        ListRes["ListMcpResourcesTool<br/>资源列表"]
        ReadRes["ReadMcpResourceTool<br/>资源读取"]
    end

    subgraph MCPManager["MCP 管理层"]
        ConnMgr["MCPConnectionManager<br/>连接管理器"]
        Config["MCP Config<br/>配置解析"]
        Auth["MCP Auth<br/>认证处理"]
        Elicitation["elicitationHandler<br/>URL 认证流"]
        ChannelPerm["channelPermissions<br/>通道权限"]
        Official["officialRegistry<br/>官方 MCP 注册表"]
    end

    subgraph MCPServers["MCP 服务器 (外部进程)"]
        ServerA["MCP Server A<br/>例: 文件系统"]
        ServerB["MCP Server B<br/>例: 数据库"]
        ServerC["MCP Server C<br/>例: GitHub"]
        ServerN["自定义 MCP 服务器..."]
    end

    subgraph Transport["传输层"]
        InProcess["InProcessTransport<br/>进程内通信"]
        SDKControl["SdkControlTransport<br/>SDK 控制"]
        Stdio["stdio 传输"]
        SSE["SSE 传输"]
    end

    MCPTool2 --> ConnMgr
    ListRes --> ConnMgr
    ReadRes --> ConnMgr
    ConnMgr --> Config
    ConnMgr --> Auth
    ConnMgr --> Elicitation
    ConnMgr --> ChannelPerm

    ConnMgr --> Transport
    Transport --> MCPServers

    Official -->|"注册表"| Config

    style ClaudeCore fill:#E74C3C,color:#fff
    style MCPManager fill:#9B59B6,color:#fff
    style MCPServers fill:#2ECC71,color:#fff
    style Transport fill:#F39C12,color:#fff
```

---

## 9. 状态管理架构

```mermaid
graph TB
    subgraph AppState2["AppState (不可变全局状态)"]
        Settings["settings: SettingsJson"]
        Model["mainLoopModel: ModelSetting"]
        Messages2["messages: Message[]"]
        ToolPermCtx["toolPermissionContext"]
        Tasks2["tasks: TaskState[]"]
        MCP2["mcp: clients/tools/commands/resources"]
        Plugins2["plugins: enabled/disabled/commands"]
        Agents2["agentDefinitions"]
        Todos2["todos: TodoList[]"]
        FileHist["fileHistory"]
        Bridge2["replBridge 状态"]
        Tungsten["tungsten 终端面板"]
        Memory2["companionReaction"]
    end

    subgraph StoreLayer["Store 层"]
        Store2["createStore()<br/>不可变状态更新"]
        Selector["selectors.ts<br/>状态选择器"]
        OnChange["onChangeAppState<br/>状态变更监听"]
    end

    subgraph Consumers["消费者"]
        REPLComp["REPL 组件"]
        ToolsComp["工具执行"]
        QECmp["QueryEngine"]
        BridgeComp["桥接系统"]
        HooksComp["React Hooks"]
    end

    Store2 --> AppState2
    Selector --> Store2
    OnChange --> Store2

    REPLComp -->|"读取"| Store2
    ToolsComp -->|"更新"| Store2
    QECmp -->|"读取+更新"| Store2
    BridgeComp -->|"读取+更新"| Store2
    HooksComp -->|"useSettings 等"| Store2

    style AppState2 fill:#E74C3C,color:#fff
    style StoreLayer fill:#2ECC71,color:#fff
    style Consumers fill:#4A90D9,color:#fff
```

---

## 10. 技术栈全景

```mermaid
graph LR
    subgraph Runtime["运行时"]
        Bun["Bun Runtime"]
        TS["TypeScript (strict)"]
    end

    subgraph UI["终端 UI"]
        React["React"]
        Ink["Ink (CLI React)"]
    end

    subgraph CLI["CLI"]
        Commander["Commander.js"]
    end

    subgraph Validation["校验"]
        Zod["Zod v4"]
    end

    subgraph Protocols["协议"]
        MCPSDK["MCP SDK"]
        LSP["LSP Client"]
    end

    subgraph API["API"]
        Anthropic["Anthropic SDK"]
    end

    subgraph Search["搜索"]
        Ripgrep["ripgrep"]
    end

    subgraph Observability["可观测性"]
        OTel["OpenTelemetry"]
        gRPC["gRPC"]
        GrowthBook["GrowthBook"]
    end

    subgraph Auth["认证"]
        OAuth["OAuth 2.0"]
        JWT["JWT"]
        Keychain["macOS Keychain"]
    end

    Runtime --> UI --> CLI
    API --> Protocols
    Observability --> Runtime
    Auth --> API
