graph LR
  User(["👤 用户操作"])

  subgraph BROWSER["🌐 浏览器侧 (P4+P2)"]
    direction TB
    SidePanel("UI: AI 面板 (Vue)")
    ProcessHost("Host: 进程守护")
    PipeListener("IPC: Pipe 监听")
    Cmd["Action: CDP 操纵指令"]

    SidePanel <-->|"Window IPC"| ProcessHost
    ProcessHost --> PipeListener
    PipeListener -.->|"复用"| Cmd
  end

  subgraph SGCLAW["⚙️ sgClaw AI 引擎进程 (P1a+P1b)"]
    direction TB
    PipeRW("Core: Pipe 双向读写")
    BrowserTool("Tool: Action 封装")
    Runtime("Brain: ReAct 核心循环")
    Memory[("Mem: 记忆层 (SQLite)")]
    SkillLoader("Sandbox: 沙箱加载验签")

    PipeRW <--> BrowserTool
    BrowserTool <--> Runtime
    Runtime --> Memory
    Runtime --> SkillLoader
  end

  subgraph EXT["☁️ 远端服务与库 (P3)"]
    direction TB
    LLM1("LLM: Minimax-M2.5 API")
    SkillDB[/"Skill: 黄金/泛化技能库"/]
  end

  User --> SidePanel
  PipeListener == "⚡ 高风险卡点 (STDIO 双工流)" === PipeRW
  Runtime <-->|"提示词组装"| LLM1
  SkillLoader -->|"签名挂载调用"| SkillDB
  BrowserTool -.->|"执行结果回调"| PipeListener

  classDef p1 fill:#fff7ed,stroke:#ea580c,stroke-width:2px
  classDef p2 fill:#eff6ff,stroke:#2563eb,stroke-width:2px
  classDef p3 fill:#f0fdf4,stroke:#16a34a,stroke-width:2px

  class PipeRW,BrowserTool,Runtime,Memory,SkillLoader p1
  class SidePanel,ProcessHost,PipeListener,Cmd p2
  class LLM1,SkillDB p3
