%%{init: {"theme": "base", "themeVariables": {"background": "transparent", "primaryColor": "#f2ede3", "primaryTextColor": "#253047", "primaryBorderColor": "#64748b", "lineColor": "#6b7280", "secondaryColor": "#e6edf5", "tertiaryColor": "#f7f4ed", "fontFamily": "Inter, PingFang SC, sans-serif"}, "flowchart": {"curve": "basis", "nodeSpacing": 32, "rankSpacing": 55}}}%%
flowchart TB
  subgraph R1[" "]
    direction LR
    U["Issue / PR / 定时事件<br/>可能含不可信文本"] --> R["只读上下文<br/>代码、规则、历史"]
    R --> A["Agent 沙箱<br/>有限文件、网络、工具和预算"]
    A --> O["候选输出<br/>补丁、报告或结构化请求"]
  end
  subgraph R2[" "]
    direction LR
    V{"确定性验证<br/>Schema、允许目标、数量、补丁大小、威胁检测"} -->|"通过"| W["独立写入任务<br/>短期、最小权限凭据"]
    W --> P["分支 / Draft PR / Issue 评论"]
    P --> C["CI + Code Owner + 人工批准"]
    C -->|"批准"| M["合并或发布"]
  end
  O --> V
  V -->|"拒绝"| X["停止并保留证据"]
  C -->|"不批准"| Y["返回审查意见"]

  style R1 fill:transparent,stroke:transparent
  style R2 fill:transparent,stroke:transparent

  classDef untrusted fill:#f9e8e5,stroke:#a14f45,color:#35231f,stroke-width:1.5px;
  classDef sandbox fill:#e6edf5,stroke:#486581,color:#1f2937,stroke-width:1.5px;
  classDef gate fill:#f4edcf,stroke:#8a6d1f,color:#2f291a,stroke-width:1.5px;
  classDef trusted fill:#e6f0e7,stroke:#4b7352,color:#1f2937,stroke-width:1.5px;
  class U untrusted;
  class R,A,O sandbox;
  class V,X,Y,C gate;
  class W,P,M trusted;
