Repo Guardian — Dual-Model PR Review & Issue Triage
Automated repository maintenance with cross-model review consensus.
Scope & Boundaries
Repo Guardian handles PR review governance and repo maintenance automation:
reviewing PRs, enforcing quality via dual-model consensus, auto-merging when
approved, and triaging repository state.
It is not the issue-to-fix implementation pipeline. If the job is to fetch
issues, spawn coding agents, implement fixes, open PRs, and monitor review
feedback, use gh-issues instead.
It is also not a general-purpose GitHub CLI toolkit. For direct gh CLI
operations such as listing PRs, commenting, checking CI, or making ad hoc API
queries, use the github skill.
NOT For
- - Implementing issue fixes end-to-end — fetching issues, spawning coding agents, writing code, and opening PRs belongs to the gh-issues skill
- General GitHub CLI operations — listing PRs, commenting, checking CI, or ad-hoc
gh queries belong to the github skill - Code authoring or refactoring — Repo Guardian reviews and gates merges; it does not write new code
What It Does
Every 6 hours (configurable), Repo Guardian:
- 1. Checks for open PRs on the target repo
- Reviews each PR with two independent models (Opus + GPT-5.4)
- Merges if both models approve
- Requests changes if either model finds issues
- Optionally prepares follow-up remediation for review-discovered issues
- Checks for open issues and triages them for the appropriate next step
Cron Setup
CODEBLOCK0
Or run manually:
CODEBLOCK1
Review Process
PR Review (Dual-Model Consensus)
CODEBLOCK2
Issue Triage
CODEBLOCK3
Review Criteria
Each model evaluates independently against:
- 1. Correctness — Does the code do what the PR claims?
- Security — Any vulnerabilities, secret exposure, injection risks?
- Tests — Are changes tested? Do existing tests still pass?
- Scope — Does the PR stay within its stated purpose?
- Quality — Code style, error handling, edge cases, naming
Each model returns a structured verdict:
CODEBLOCK4
Configuration
Environment variables (set in shell or .env):
- -
GH_TOKEN — GitHub token with repo access (required) - INLINECODE4 — OpenClaw agent name for Reviewer A (default:
$OPENCLAW_AGENT or default) - INLINECODE7 — OpenClaw agent name for Reviewer B (default: same as
GUARDIAN_AGENT; set to a different agent for true cross-model review) - INLINECODE9 — Default repo (e.g.,
your-org/your-repo) - INLINECODE11 — Enable auto-merge on consensus (
true/false, default: true) - INLINECODE15 — Enable auto-fix for issues (
true/false, default: false) - INLINECODE19 — Max PRs to review per run (default:
5) - INLINECODE21 — Max issues to process per run (default:
3)
Data Flow & Privacy
Repo Guardian sends PR diffs and file listings to the configured OpenClaw agent models for review. This means:
- - Repository code from open PRs is transmitted to your configured AI model providers (e.g., Anthropic, OpenAI) via the OpenClaw agent interface
- No data is sent to any third-party endpoint beyond your configured model providers
- Large diffs are truncated to 500 lines before transmission to limit exposure
- The
GH_TOKEN is used only for GitHub API calls and is never passed to AI model prompts - All JSON payloads to the GitHub API are constructed via Python
json.dumps() to prevent injection
Recommended GH_TOKEN scopes: repo (read) for review-only mode; add repo (write) only if auto-merge is enabled. Use a fine-grained token scoped to the specific repository when possible.
Safety
- - Never force-pushes or modifies protected branches
- Squash merges only — clean history
- Labels PRs with review status for audit trail
- Posts review comments with model attribution (which model said what)
- Requires dual consensus — single model cannot merge alone
- Skips PRs by org members marked with
skip-guardian label - Dry-run mode available (
--dry-run flag) - Credentials (GHTOKEN) are user-configured via environment variables; Repo Guardian never stores, bundles, or transmits tokens
- Auto-merge requires explicit opt-in (GUARDIANAUTO_MERGE=true); disabled by default
- All review actions are logged with model attribution for full audit trail
- The skill operates only on the repository specified by the user; it does not discover or access other repos
Run Trace Logging
Each Repo Guardian run emits a structured trace for audit and performance tracking. After completing all PR reviews and issue triages, write a trace entry:
CODEBLOCK5
Write traces to memory/performance/skill-runs.md (following the standard skill execution logging protocol). The model agreement rate is a key health metric — if it drops below 70% over 5+ runs, the review criteria may need recalibration.
Models Used
| Role | Primary | Fallback |
|---|
| Reviewer A | anthropic/claude-opus-4-6 | anthropic/claude-sonnet-4-6 |
| Reviewer B |
anthropic/claude-sonnet-4-6 | anthropic/claude-haiku-4-5 |
| Issue triage | anthropic/claude-sonnet-4-6 | anthropic/claude-haiku-4-5 |
Note: GPT-5.4 (openai-codex/gpt-5.4) can be used as Reviewer B if the OpenAI Codex agent is configured and available in your deployment. When using GPT, set Reviewer B primary to openai-codex/gpt-5.4 with fallback anthropic/claude-sonnet-4-6.
Requirements
Required environment variables:
- -
GH_TOKEN — A GitHub Personal Access Token. Must be set explicitly (the script will not fall back to gh auth token to avoid inadvertent scope leakage). Use a fine-grained PAT scoped to the specific target repository with read/write permissions for pull requests and issues.
Required binaries (must be on PATH):
- -
openclaw — OpenClaw CLI (dispatches review prompts to configured model agents) - INLINECODE37 — JSON construction and data parsing
- INLINECODE38 — GitHub API calls
Required OpenClaw configuration:
- - At least one agent configured with access to Opus-tier and Sonnet/GPT-tier models for dual-model review
Repo Guardian — 双模型PR审查与问题分类
通过跨模型审查共识实现自动化仓库维护。
范围与边界
Repo Guardian 负责 PR审查治理和仓库维护自动化:审查PR、通过双模型共识强制执行质量标准、在批准时自动合并,以及分类仓库状态。
它不是问题修复实施流水线。如果任务是获取问题、生成编码代理、实施修复、打开PR并监控审查反馈,请使用 gh-issues。
它也不是通用GitHub CLI工具包。对于直接的 gh CLI操作,如列出PR、评论、检查CI或进行临时API查询,请使用 github 技能。
不适用于
- - 端到端实施问题修复 — 获取问题、生成编码代理、编写代码和打开PR属于 gh-issues 技能
- 通用GitHub CLI操作 — 列出PR、评论、检查CI或临时 gh 查询属于 github 技能
- 代码编写或重构 — Repo Guardian负责审查和把关合并;它不编写新代码
功能说明
每6小时(可配置),Repo Guardian:
- 1. 检查目标仓库的开放PR
- 使用两个独立模型(Opus + GPT-5.4)审查每个PR
- 如果两个模型都批准则合并
- 如果任一模型发现问题则请求修改
- 可选地为审查发现的问题准备后续修复
- 检查开放问题并进行分类以确定下一步操作
Cron设置
bash
通过OpenClaw cron运行守护脚本
添加到 ~/.openclaw/cron/jobs.json:
{
repo-guardian: {
schedule: 0
/6 ,
agent: <你的代理名称>,
message: 为你的组织/你的仓库运行repo-guardian,
skill: repo-guardian
}
}
或手动运行:
bash
bash /scripts/guardian.sh 你的组织/你的仓库
审查流程
PR审查(双模型共识)
检测到开放PR
│
├─→ Opus审查(安全性、架构、正确性)
├─→ Sonnet审查(代码质量、边界情况、测试)
│ (回退:如果Sonnet不可用则使用Haiku)
│
├─ 两者均批准 → 自动合并(压缩合并)
├─ 一个批准,一个请求修改 → 发布审查评论,不合并
├─ 两者均请求修改 → 发布审查评论,不合并
└─ 任一发现严重问题 → 发布评论 + 标记需要修复
问题分类
检测到开放问题
│
├─ 评估复杂性和路由(适合自动化 vs 需要人工处理)
├─ 适合实施:移交给问题修复流水线(gh-issues)
└─ 复杂或不明确:添加标签需要人工处理,发布分析评论
审查标准
每个模型独立评估以下方面:
- 1. 正确性 — 代码是否实现了PR声称的功能?
- 安全性 — 是否存在漏洞、密钥泄露、注入风险?
- 测试 — 变更是否经过测试?现有测试是否仍然通过?
- 范围 — PR是否在其声明的目的范围内?
- 质量 — 代码风格、错误处理、边界情况、命名
每个模型返回结构化裁决:
json
{
verdict: 批准|请求修改|严重,
summary: 一行摘要,
findings: [
{severity: 严重|主要|次要, file: ..., line: 0, issue: ..., fix: ...}
],
confidence: 高|中|低
}
配置
环境变量(在shell或 .env 中设置):
- - GHTOKEN — 具有仓库访问权限的GitHub令牌(必需)
- GUARDIANAGENT — 审查者A的OpenClaw代理名称(默认:$OPENCLAWAGENT 或 default)
- GUARDIANREVIEWERBAGENT — 审查者B的OpenClaw代理名称(默认:与 GUARDIANAGENT 相同;设置为不同代理以实现真正的跨模型审查)
- GUARDIANREPO — 默认仓库(例如 你的组织/你的仓库)
- GUARDIANAUTOMERGE — 启用共识自动合并(true/false,默认:true)
- GUARDIANAUTOFIX — 启用问题自动修复(true/false,默认:false)
- GUARDIANMAXPRS — 每次运行审查的最大PR数(默认:5)
- GUARDIANMAXISSUES — 每次运行处理的最大问题数(默认:3)
数据流与隐私
Repo Guardian将PR差异和文件列表发送到配置的OpenClaw代理模型进行审查。这意味着:
- - 来自开放PR的仓库代码通过OpenClaw代理接口传输到您配置的AI模型提供商(例如Anthropic、OpenAI)
- 除您配置的模型提供商外,不会向任何第三方端点发送数据
- 大型差异在传输前会被截断为500行以限制暴露
- GH_TOKEN 仅用于GitHub API调用,绝不会传递给AI模型提示
- 所有发送到GitHub API的JSON负载均通过Python json.dumps() 构建以防止注入
推荐的 GH_TOKEN 范围: 仅审查模式使用 repo(读取);仅在启用自动合并时添加 repo(写入)。尽可能使用限定到特定仓库的细粒度令牌。
安全性
- - 绝不强制推送或修改受保护分支
- 仅压缩合并 — 保持历史记录整洁
- 标记PR 审查状态以便审计追踪
- 发布审查评论 并注明模型归属(哪个模型说了什么)
- 需要双重共识 — 单个模型不能单独合并
- 跳过标记有 skip-guardian 标签的组织成员PR
- 提供干运行模式(--dry-run 标志)
- 凭据(GHTOKEN)由用户通过环境变量配置;Repo Guardian从不存储、捆绑或传输令牌
- 自动合并需要明确选择加入(GUARDIANAUTO_MERGE=true);默认禁用
- 所有审查操作均记录模型归属以提供完整审计追踪
- 该技能仅操作用户指定的仓库;不会发现或访问其他仓库
运行追踪日志
每次Repo Guardian运行都会生成结构化追踪记录,用于审计和性能跟踪。完成所有PR审查和问题分类后,写入一条追踪条目:
markdown
[YYYY-MM-DD HH:MM] repo-guardian 运行
- - 仓库: [所有者/仓库]
- 审查的PR: [数量](已合并:N,已请求修改:N,严重:N)
- 分类的问题: [数量](路由到gh-issues:N,标记需要人工处理:N)
- 模型一致率: [两个模型达成相同裁决的PR百分比]
- 持续时间: [大约时间]
- 异常: [任何意外行为、超时、值得注意的模型分歧]
将追踪记录写入 memory/performance/skill-runs.md(遵循标准技能执行日志记录协议)。模型一致率是关键健康指标——如果在5次以上运行中低于70%,可能需要重新校准审查标准。
使用的模型
| 角色 | 主要模型 | 回退模型 |
|---|
| 审查者A | anthropic/claude-opus-4-6 | anthropic/claude-sonnet-4-6 |
| 审查者B |
anthropic/claude-sonnet-4-6 | anthropic/claude-haiku-4-5 |
| 问题分类 | anthropic/claude-sonnet-4-6 | anthropic/claude-haiku-4-5 |
注意: 如果OpenAI Codex代理已在您的部署中配置并可用,则GPT-5.4(openai-codex/gpt-5.4)可用作审查者B。使用GPT时,将审查者B的主要模型设置为 openai-codex/gpt-5.4,回退模型为 anthropic/claude-sonnet-4-6。
要求
必需的环境变量:
- - GH_TOKEN — GitHub个人访问令牌。必须显式设置(脚本不会回退到 gh auth token,以避免意外范围泄露)。使用限定到特定目标仓库的细粒度PAT,具有拉取请求和问题的读写权限。
必需的二进制文件(必须在PATH中):
- - openclaw — OpenClaw CLI(将审查提示分派到配置的模型代理)
- python3 — JSON构建和数据解析
- curl — GitHub API调用
必需的