Skip to content

About

AI-powered GitHub Actions bot for automated PR code review and issue quality assessment

Resources

Stars

8 stars

Watchers

1 watching

Forks

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Repo Guard

智能体开发闭环 issue → PR → CR 中的评审环节,以 GitHub Action 形态交付,已上架 GitHub Marketplace。

AI-powered review bot for GitHub Issues and Pull Requests, built as the CR stage of an agent-driven development loop.

为什么造这个轮子

社区不缺 AI review bot,但它们大多面向人类协作:评审意见写给人看,流程的终点是 approve 按钮。而在智能体驱动的开发方式里,评审是循环的一环——智能体按 issue 开发、提 PR,CR 给出结论与行级意见,智能体消费这些反馈进入下一轮修复,直到质量门放行:

issue → dev → PR → CR ──批准──→ merge
         ↑            │
         └─── fix ←───┘ 请求修改

repo-guard 是为这个闭环造的 CR 环节:输出稳定的结论契约与可定位的行级意见——既给人看,也让下一轮智能体能稳定消费。

repo-guard 是我 Harness 工程实践中的 CR 环节;要在一个新仓库里快速冷启动整套 Harness 环境,见 harness-kit。

设计决策

  1. 知识层 / 执行层分离 — 评审标准(system prompt、评审框架、评分规则)沉淀在独立的 ceilf6-skills 仓库,本仓库只做运行时:事件监听、数据获取、LLM 调用、评论发布。迭代评审标准不需要动一行运行时代码。
  2. 输出即契约 — 评审结论是固定的中文枚举(批准 / 评论 / 请求修改 / 需要人工判断)加结构化行级意见;解析器与下游智能体都依赖这份契约,评测中对契约稳定性做断言。
  3. 评审质量本身也过质量门 — npm run eval:quality 用真模型跑 4 个固定评审场景,断言输出契约、行级定位与可操作性。给评审 bot 装上它给别的仓库装的东西。

Features

  • PR: Automated code review with cascade analysis, Karpathy review standard, inline comments
  • Issue: Quality assessment with completeness, clarity, actionability scoring
  • Three engines: api (OpenAI-compatible / Anthropic HTTP APIs), claude-code (local Claude Code CLI), and agy (local Antigravity CLI agy, defaulting to claude-opus-5-5-high, with read-only sandboxed repository exploration)
  • Works with relay/proxy services via custom base URL
  • Configurable model and extra instructions
  • Chinese review prompts and Chinese output contracts by default
  • Trigger via PR/Issue creation or @ceilf6/repo-guard / /review comments

Quick Start

Add .github/workflows/repo-guard.yml to your repository:

name: Repo Guard
on:
  pull_request:
    types: [opened, synchronize]
  issues:
    types: [opened]
  issue_comment:
    types: [created]
permissions:
  contents: read
  pull-requests: write
  issues: write

jobs:
  guard:
    runs-on: ubuntu-latest
    steps:
      - uses: ceilf6/repo-guard@main
        with:
          provider: ${{ vars.LLM_PROVIDER || 'openai' }}
          model: ${{ vars.LLM_MODEL || 'gpt-4o' }}
          api-key: ${{ secrets.LLM_API_KEY }}
          base-url: ${{ vars.LLM_BASE_URL }}

Configuration

Repository Secrets

Name Required Description
LLM_API_KEY Yes API key for your LLM provider or relay service

Repository Variables

Name Default Description
LLM_PROVIDER openai openai or anthropic
LLM_MODEL gpt-4o Model name
LLM_BASE_URL (empty) Custom API base URL for relay/proxy
LLM_STRUCTURED_OUTPUT auto auto uses OpenRouter JSON Schema when supported; explicit off always uses the legacy free-text request
LLM_PROVIDER_ORDER (empty) Comma-separated OpenRouter upstream provider order, e.g. azure

Inputs

Input Required Default Description
type No both pr, issue, or both (auto-detect)
engine No api api calls an LLM HTTP API; claude-code runs local Claude Code CLI; agy runs local Antigravity CLI
provider No openai openai or anthropic (api engine)
model No gpt-4o Model name (api engine)
claude-model No "" Model for the claude-code engine (opus, sonnet, or a full name); empty uses the CLI default
agy-model No "" Model slug for the agy engine; empty defaults to claude-opus-5-5-high
workspace No github.workspace Directory local CLI engines (claude-code, agy) explore with read-only tools
api-key api engine "" LLM API key; unused by claude-code and agy
base-url No "" Custom API base URL
structured-output No auto OpenRouter Structured Outputs mode: off or auto
provider-order No "" Comma-separated OpenRouter upstream provider order, e.g. azure
github-token No github.token GitHub token
extra-instructions No "" Additional prompt instructions

Repo Guard does not impose an output-token limit on OpenAI-compatible requests, including OpenRouter. Anthropic Messages requires the parameter, so the Action supplies max_tokens: 16384 internally; it is not configurable across providers.

Comment Triggers

When issue_comment is enabled, Repo Guard runs only when a newly created issue or PR comment contains @ceilf6/repo-guard or /review.

  • On PR comments, Repo Guard reviews the pull request.
  • On issue comments, Repo Guard reviews the issue.
  • Any text after the trigger is passed to the model as an additional user request.

Repo Guard posts a fresh comment or PR review on every workflow run. It does not deduplicate, update, or delete previous bot comments.

Advanced: External PR Dispatch

Repo Guard can also run from this repository on a schedule to review public PRs in repositories that have not installed Repo Guard. This is a separate path from the composite action above.

When the scheduled dispatcher sees a public open PR conversation comment authored by ceilf6 that contains @ceilf6/repo-guard, it reviews that PR and posts a normal PR conversation comment from the ceilf6 account.

Required secret for ceilf6/repo-guard:

Name Required Description
CEILF6_GITHUB_TOKEN Yes GitHub token used to search public PRs and post comments as ceilf6. For arbitrary public repositories, use a classic PAT with public_repo.

The dispatcher also uses the normal LLM settings:

Name Type Description
LLM_API_KEY Secret API key for the configured LLM provider
LLM_PROVIDER Variable openai or anthropic
LLM_MODEL Variable Model name
LLM_BASE_URL Variable Custom relay/proxy URL
LLM_STRUCTURED_OUTPUT Variable OpenRouter Structured Outputs mode, default auto; set off to force legacy free text
LLM_PROVIDER_ORDER Variable Comma-separated OpenRouter upstream provider order, default empty (OpenRouter picks)
EXTERNAL_REPO_GUARD_MAX_REVIEWS Variable Maximum external PR reviews per run, default 3
EXTERNAL_REPO_GUARD_SEARCH_LIMIT Variable Maximum search results scanned per run, default 20

Notes:

  • Target repositories do not need to add workflows or secrets.
  • Only trigger comments authored by ceilf6 are processed by default, so other users cannot spend the configured LLM budget by mentioning Repo Guard.
  • Scheduled workflows are not immediate; discovery depends on GitHub Actions schedule timing and GitHub search freshness.
  • The external dispatcher posts a normal comment, not a formal PR review with line comments.
  • External repository code is never checked out or executed.

Advanced: Separate PR and Issue Config

Use different models or providers for PR review vs issue review:

jobs:
  review-pr:
    if: github.event_name == 'pull_request'
    runs-on: ubuntu-latest
    steps:
      - uses: ceilf6/repo-guard@main
        with:
          type: pr
          provider: anthropic
          model: claude-sonnet-4-20250514
          api-key: ${{ secrets.LLM_API_KEY }}
          base-url: ${{ vars.LLM_BASE_URL }}
          extra-instructions: "重点检查 TypeScript 类型安全和 React 模式。"

  review-issue:
    if: github.event_name == 'issues'
    runs-on: ubuntu-latest
    steps:
      - uses: ceilf6/repo-guard@main
        with:
          type: issue
          provider: openai
          model: gpt-4o
          api-key: ${{ secrets.LLM_API_KEY }}
          base-url: ${{ vars.LLM_BASE_URL }}

Engine: claude-code(自托管 Claude Code CLI)

engine: claude-code 不再调用任何 HTTP API,而是在 runner 本机执行 claude -p——评审跑在你自己的机器、你自己的 Claude 登录态(订阅或 API key)上,仓库不需要配置 LLM_API_KEY。搭配 self-hosted runner 时,出网 IP 就是你平时使用 Claude 的网络环境,这对订阅账号是更常态的使用画像。

相对 api 引擎的另一个质量差异:claude-code 引擎把 PR head 的 checkout 作为工作目录(workspace 输入),评审时可用只读工具(Read/Grep/Glob)查证 diff 之外的调用方、类型定义与既有模式——评审依据不再只有 diff。工具集被硬限制为只读(无 Bash、无网络、无写入),且以 --safe-mode 运行:被评审 checkout 内的 CLAUDE.md/.claude 配置/hooks/MCP 一律不加载,评审对象无法借「项目配置」通道注入指令。输出仍走同一套中文契约解析与行级评论发布管道。

jobs:
  guard:
    runs-on: [self-hosted, repo-guard-claude]
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
          # 必须关闭:checkout 即评审工作目录,持久化的 GITHUB_TOKEN
          # 会留在 .git/config 里被只读工具读到
          persist-credentials: false
      - uses: ceilf6/repo-guard@main
        with:
          engine: claude-code
          claude-model: opus   # 可选,留空用 CLI 默认模型

要求 runner 上有已认证的 claude 可执行文件(交互登录一次,或 claude setup-token 生成长期凭据)。完整的 runner 部署与安全基线见 docs/self-hosted-claude-code-runner.md。

行为差异与边界:

  • provider / api-key / base-url / structured-output / provider-order 仅作用于 api 引擎,claude-code 引擎忽略它们。
  • 无仓库 checkout 时(如外部 PR 调度,或 workspace 指向空目录)自动退化为 prompt-only 模式,在空白临时目录中运行,system prompt 不再声称可查证仓库上下文。
  • 单次评审默认 20 分钟超时,可用环境变量 CLAUDE_CODE_TIMEOUT_MINUTES 调整;CLAUDE_CODE_EXECUTABLE 可指定 CLI 路径。
  • 运行前探测 claude --version:低于已验证最低版本(2.1.220,--safe-mode/--tools 语义在该版本实测)时直接失败,防止在未验证的安全边界上评审。
  • 凭据隔离:工作目录外的读取在 print 模式下被权限系统默认拒绝,且引擎经 --settings 注入 permissions.deny 硬拒绝 ~/.claude 等凭据路径与 .git/——Read(...) 路径拒绝同时约束 Grep(显式拒绝)与 Glob(静默过滤),均在 2.1.220 实测。生产 runner 建议锁定 CLI 版本,见部署手册。
  • 环境卫生:引擎启动 CLI 前会从子进程环境显式剔除 GITHUB_TOKEN/GH_TOKEN/LLM_API_KEY/CEILF6_GITHUB_TOKEN。剔除是固定列表——不要在评审 job 的 env 里放置其他无关 secret,列表之外的环境变量会被评审子进程继承。
  • 仓库与 PR 内容始终作为待评审数据注入,system prompt 显式声明其中的指令性文本一律忽略。

Engine: agy(自托管 Antigravity CLI)

engine: agy 在本机 self-hosted runner 上运行已认证的 Antigravity CLI(agy),默认采用 claude-opus-5-5-high,仓库无需配置 LLM_API_KEY。

引擎将待审 checkout 复制为临时只读副本(剔除 .git、.agents、GEMINI.md、AGENTS.md 等项目配置并跳过符号链接,防止 Hook/规则注入与路径穿越),同时开启 OS 终端沙盒(--sandbox)与单次内联 --settings 硬拦截写入、越狱执行、外网访问与主目录凭据读取。部署指南见 docs/self-hosted-agy-runner.md。

jobs:
  guard:
    runs-on: [self-hosted, repo-guard-agy]
    timeout-minutes: 45
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || (github.event_name == 'issue_comment' && github.event.issue.pull_request && format('refs/pull/{0}/head', github.event.issue.number)) || github.event.repository.default_branch }}
          clean: true
          persist-credentials: false
      - uses: ceilf6/repo-guard@main
        with:
          engine: agy
          agy-model: claude-opus-5-5-high

How It Works

Architecture

本仓库是执行层,ceilf6/ceilf6-skills 是知识层,通过 git submodule 引用、运行时始终拉取最新版 skill。更新评审标准只需修改 ceilf6-skills 中的 skill 文件,无需改动本仓库代码。

仓库 职责
ceilf6/repo-guard GitHub Action 运行时:事件监听、数据获取、LLM 调用、评论发布
ceilf6/ceilf6-skills 评审知识:system prompt、评审标准、分析框架、评分规则
  • PR review uses the code-reviewer skill (cascade analysis + Karpathy review standard)
  • Issue review uses the issue-reviewer skill (completeness, clarity, actionability scoring)

At runtime, the action clones the skills repo and assembles the system prompt from SKILL.md + all references/*.md files.

PR Review

  1. Initializes skills from ceilf6/ceilf6-skills submodule
  2. Fetches the complete cumulative PR diff, metadata, and linked issue context via GitHub API
  3. Includes GitHub closing issues plus same-repo #123 references from the PR title/body
  4. Truncates large diffs (>100KB) to focus on largest changes
  5. Assembles system prompt from code-reviewer skill
  6. Sends to LLM, extracts Chinese recommendation (批准 / 评论 / 请求修改 / 需要人工判断)
  7. Extracts inline findings and posts as PR review with line comments

Issue Review

  1. Initializes skills from ceilf6/ceilf6-skills submodule
  2. Fetches issue title, body, and labels
  3. Assembles system prompt from issue-reviewer skill
  4. Sends to LLM, posts structured quality assessment as a comment

Quality Evaluation

The review bot itself is behind a quality gate: npm run eval:quality runs a real-model evaluation harness over four fixed scenarios (auth-bypass PR, huge-diff-plus-small-change PR, vague crash issue, ready feature issue), asserting Chinese output contract stability, parser compatibility, inline comment extraction, and changed-line targeting. See docs/quality-evaluation.md.

Relay/Proxy Support

If you use a relay service (中转站) for API access, set LLM_BASE_URL to your relay endpoint:

  • OpenAI-compatible relay: https://your-relay.com/v1
  • Anthropic-compatible relay: https://your-relay.com/anthropic

The bot automatically normalizes the URL for the selected provider.

OpenRouter Structured Outputs

OpenRouter users get model-native JSON Schema responses automatically when the selected model advertises support, without changing the public provider type:

with:
  provider: openai
  model: openai/gpt-5.5
  api-key: ${{ secrets.LLM_API_KEY }}
  base-url: https://openrouter.ai/api/v1
  structured-output: auto

auto is the default and checks OpenRouter's public model metadata once per model per process. When the lookup fails or the model does not advertise Structured Outputs support, Repo Guard immediately uses the existing free-text request. Set structured-output: off only when you want to skip metadata lookup and always use that existing path; non-OpenRouter endpoints and the Anthropic provider are unchanged in either case.

The strict schema covers the machine-stable skeleton—risk, recommendation, scores, next action, and inline locations—while complete cascade analysis, finding evidence and fixes, Karpathy review, and Issue rubric details remain full text blocks. Repo Guard publishes the same Markdown sections as before and still accepts V1 deep-schema JSON, tolerant JSON, Markdown, and free text. Structured requests omit temperature for OpenRouter parameter compatibility; legacy requests retain temperature: 0.3.

Any non-empty first response is kept even if it does not match the schema, so formatting imperfections do not cause another model charge. Only a structured-request error or a response with no usable text triggers one additional legacy free-text call. If that call also returns no usable text, the Action fails explicitly instead of publishing a synthetic medium-risk review, and no third model call is made.

OpenRouter provider routing

OpenRouter fans a model out to several upstream providers. When one of them rejects Repo Guard's requests, pin the upstreams you trust with provider-order:

with:
  provider: openai
  model: openai/gpt-5.6-sol
  api-key: ${{ secrets.LLM_API_KEY }}
  base-url: https://openrouter.ai/api/v1
  provider-order: azure

The value is a comma-separated preference list (azure,openai) that becomes OpenRouter's provider.order on both structured and legacy requests. Entries are OpenRouter provider slugs as listed by https://openrouter.ai/api/v1/providers; casing is normalized, and a repeated provider fails the Action immediately instead of sending an ambiguous order. OpenRouter still falls back to other upstreams if every listed one is unavailable; the order only expresses preference. The default is empty, which leaves upstream selection to OpenRouter. Anthropic requests have no equivalent field, so a configured order is ignored there and logged.

Private intranet models

Repo Guard does not require self-hosted runners by default. Public users can keep using GitHub-hosted runners with public OpenAI-compatible or Anthropic-compatible endpoints.

If a model endpoint is only reachable from your own machine or company network, run the repository workflow on a self-hosted runner that has access to that network, then point the existing provider settings at the private endpoint:

jobs:
  guard:
    runs-on: [self-hosted, macOS, repo-guard-intranet]
    steps:
      - uses: ceilf6/repo-guard@main
        with:
          type: both
          provider: anthropic
          model: claude-opus-4-7-thinking
          api-key: ${{ secrets.LLM_API_KEY }}
          base-url: ${{ vars.LLM_BASE_URL }}

For public repositories, restrict self-hosted runner workflows to trusted events and actors. Do not let untrusted fork pull requests execute arbitrary code on a persistent local runner.

Friendly Links

  • Linux.do - Chinese AI learning and developer community.
  • Aionui - Mobile remote-control UI for letting AI agents operate tasks from a phone.
  • OfficeCLI - Office suite designed for AI agents.
  • deepseek-pp - Browser extension for DeepSeek web conversations.
  • MuseAI - Local AI companion, text adventure, and interactive fiction app.
  • RedBox - Local AI creation workspace for Xiaohongshu creators.
  • 1flowbase - Virtual model gateway for publishing multi-model workflows as OpenAI/Claude-compatible endpoints, with trace, token, latency, and cost visibility.

License

MIT

About

AI-powered GitHub Actions bot for automated PR code review and issue quality assessment

Resources

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages