TL;DR · A shepherd for your agent PRs
- review-shepherd takes every PR from draft to merge on GitHub, and asks a person only where a bug would be expensive. It is open source, and the quickest setup is to point your coding agent at it.
- A PR whose author is new to the code gets a reviewer who knows it. If the author has no commit in the changed folders in the last 12 months, a profile can require approvals from people who do, as a Microsoft study recommends.
- Rules look at what a change does, not only where it is. A profile matches on paths, or on yes/no questions an AI answers, such as “Does this change who can move funds?”.
- Reviewers only see PRs that are ready. Every PR stays a draft until its tests and an AI review pass.
- A PR can’t loosen its own rules. The shepherd reads them from
main, and only its GitHub App can post the check that allows a merge.
Last week I argued that not every agent PR needs a human: sort PRs into review profiles by what a bug would cost, and send only the strict ones to an engineer who knows the code. This post builds that on GitHub without stalling your team. At its core is a program I call the shepherd. It moves each PR from draft to merge, stage by stage: it matches the PR to profiles, then enforces what they require. The code is in a companion repository, review-shepherd. The quickest setup is to point your coding agent at the repository, which has instructions for agents.
What you’ll build. A few files in your repository and two settings on GitHub. You write the profiles; the rest you copy from the review-shepherd repository:
.github/
├── review-profiles.yml # the profiles, in a custom format that defines the rules the shepherd applies
├── review-shepherd/ # the shepherd's code: copy it as is
├── pull_request_template.md # the PR template your agents open drafts with
└── workflows/
├── review-check.yml # the check workflow: matches the profiles, runs the classifier and the tests
└── review-decide.yml # the decision workflow: labels, moves the PR between draft and ready, posts the check
.coderabbit.yaml # CodeRabbit's settings, if you use it
Together, the shepherd’s code and the two workflows are the shepherd.
On GitHub you’ll need to set up:
- A GitHub App, a bot account,
review-shepherd[bot], which the shepherd posts its check as. - A ruleset, GitHub’s merge rules for a branch. It refuses the merge until the
review-shepherd/decisioncheck is green, and accepts it only from the App, so a PR can’t post its own green one. That one check stands for everything a profile requires, approvals included: GitHub can’t count approvals per profile, so the shepherd does.
Step 1. Write your profiles
Profiles are defined in .github/review-profiles.yml. Each one has two parts: which PRs it matches, and what those PRs need before they merge.
Which PRs a profile matches. There are two kinds of condition, and either one is enough (under match — see the example at the end of this section):
- Paths:
any_file_inmatches when at least one changed file is under these paths, andevery_file_inwhen every changed file is. - Yes/no questions (
ask_classifier) for what paths can’t tell, such as “Does this change who can move funds?”. A classifier answers them, a separate AI step from the AI review (Step 4 says which). All the questions still open go in one call, and a yes makes that profile match too. An answer can add a profile to a PR, never remove one. Write each question so that a yes means the profile applies, and ask about one thing per question.
What those PRs need before they merge. This is what the shepherd enforces. There are three kinds of requirement (under the require key):
- Test suites (
checks). - An AI review (
ai_review). - Approvals (
approvals): how many people from which GitHub team, optionally only people who have committed to the changed files’ folders in the last 12 months (knows_the_code). If nobody has, any member of the team counts. The teams are your organization’s teams on GitHub, which the shepherd reads through GitHub’s API.
A profile can also ask for additional requirements when the author is new to the code (if_author_is_new), i.e., when the author has no commit in the changed files’ folders in the last 12 months. This follows a Microsoft study, which found more failures in components with more minor contributors and recommended that “changes made by minor contributors should be reviewed with more scrutiny” (Bird et al., FSE 2011). In the example below, a newcomer’s change to critical code needs its two approvals from people who know that code.
A PR gets the requirements of every profile it matches, and a label for each, so the order you write them in doesn’t matter.
Each profile can also carry three optional prose fields: description (what it is), bug_cost (what a bug costs) and blocks_merge (what should stop the merge). They are context, not conditions: the AI review reads all three, and the classifier reads the description.
| Profile | Matches a PR when | Tests | Who approves | |---|---|---|---| | critical | Contracts, consensus, signing, migrations, CI config, or the classifier says it changes who can move funds or sign | Unit, invariant, fuzz; mutation on the diff | 2 from protocol ; if the author is new here, both must know the code | | user-facing | Web app or wallet UI, or the classifier says it changes what a user sees or signs | Unit, end-to-end | 1 engineer, 1 from qa | | standard | Nothing above | Unit, types, linters | Nobody; if the author is new here, 1 who knows the code | | docs | Only docs and Markdown files | Link check | Nobody; no AI review |
In the example below, a profile I call critical matches the PRs that change code where a bug could lose funds. Its last two paths are the shepherd’s own files and CodeRabbit’s settings, so changing either needs two people from the protocol team. From the repository’s file:
profiles:
critical:
description: "Who can move funds or sign transactions: contracts, consensus, the signer and migrations."
bug_cost: "Funds can be lost or stolen, and a signed transaction cannot be undone; a bug here reaches every user at once."
blocks_merge: "Anything that changes who can move funds, what gets signed, or an invariant the chain relies on."
match:
any_file_in:
- contracts/**
- consensus/**
- signer/**
- db/migrations/**
- .github/**
- .coderabbit.yaml
ask_classifier:
- Does this change who can move funds?
- Does this change who can sign transactions?
require:
checks: [unit, invariants, fuzz, mutation-on-diff]
ai_review: true
approvals: {team: protocol, count: 2}
if_author_is_new:
approvals: {team: protocol, count: 1, knows_the_code: true}
Step 2. Create the GitHub App
The shepherd needs an account of its own, to label PRs, take them out of draft, ask reviewers and post the check. On GitHub that account is a GitHub App, here review-shepherd[bot]. Give it read and write on Pull requests, Issues, Commit statuses and Contents (required for promoting a draft), and read on organization Members.
Install it on this repository only. Keep its private key in a GitHub environment, a named set of secrets with rules about which branches may use them. Allow only main, so only a workflow running from main can read the key. Keep in mind that on a private repository, environments and rulesets need a paid plan, and team approvals need an organization (requirements). The full setup is in the repository’s setup guide.
Step 3. Add the two workflows
We want to minimize human review time which is a scarce resource, so agents open every PR as a draft, and the shepherd ensures that it stays so until all the defined checks and AI reviews pass. In this way, human reviewers can safely ignore all PRs that are drafts. If, once they review it, they request changes, it again gets demoted as draft and the cycle restarts.
On every push, the shepherd:
- ensures it is a draft;
- matches the PR against the profiles;
- runs the classifier on the
ask_classifierquestions, potentially adding matching profiles; - runs the test suites from
checks; - starts the AI review, chief or CodeRabbit (see Step 4), optionally in parallel to the test runs (by setting
ai_review_after_tests: false); - labels the PR and posts its verdict as the
review-shepherd/decisioncheck: red if the tests or the AI review failed, yellow while an approval is missing, green when nothing is. If the tests and the AI review passed, it also promotes the PR and notifies a reviewer when a profile asks for one.
All this is implemented in two workflows:
review-check.ymlruns steps 2 to 5. It’s executed from its copy on the PR branch.review-decide.ymlruns the first and the last step. It holds the App’s key, is always executed from its copy onmainand reads the profiles frommaintoo.
This separation lets the shepherd treat everything the first workflow produces as untrusted data, so an agent can’t change the approval rules in its own PR.
Step 4. Choose the AI review and the classifier
Two stages call a model, each with two interchangeable options, set in the profiles file. The setup guide has the settings. Since both read text anyone can write, such as the PR description, the template limits what a prompt injection could do: the jobs that run them have read-only permissions and only their own key, and Claude Code runs in its sandbox.
The AI review
The AI review flags what should stop the merge. ai_reviewer picks who:
coderabbitruns on CodeRabbit’s servers and fetches the code itself. The decision workflow starts it by adding a label to the PR. A label carries no text, so CodeRabbit reads its context from its configuration file onmain: for each path, what the profiles covering it are about. It knows nothing about this particular PR, such as a profile the classifier added. It needs a plan with automatic approvals, so that it requests changes or approves, and its configuration source set tomain, so a PR can’t loosen its own review.chief, myRalph Wiggum implementation configured for review, steers a coding agent in your CI on the PR’s code. It gets the full context: the matched profiles and why each matched, whether the author is new to the code, the tests that passed and who reviews after it. The tradeoff is it can be costly (paid via API usage); by default it stops after five passes at most.
Either way, blocking findings keep the PR a draft and notify the author. After three blocks in a row the PR is promoted and a human reviewer takes over.
Manual override: Commenting /skip-ai-review on the PR waives the AI review gate for the current commit (the next push resets this — AI review will run again). Anyone with a role on the repository can do it. With CodeRabbit, clicking “Resolve” on its comment has the same effect.
The classifier
The classifier answers the yes/no questions in ask_classifier. These are meant for more nuanced criteria in profile matching that cannot be achieved by a regex on paths alone. Review-shepherd supports two options for classifier:
jevis TypeSafe’s “System One” decision model (TypeSafe ). One request returns the probability of yes for every open question. It needs a TypeSafe key.claudemakes a Claude Code call instead. It needs an Anthropic key.
With jev, each answer is the probability of a yes, from 0% to 100%. The shepherd is conservative by default: only an answer below 30% counts as a no, so an unsure answer adds the profile too. The setting is classifier_threshold.
Step 5. Turn it on
After Steps 1 to 4 the shepherd is installed, but anyone can still merge whatever its check says. Three things are left.
- Merge the setup into
mainand open a test PR. The decision workflow only runs frommain. In the example, if you open a draft PR that changes a file undercontracts/, it should get theprofile:criticallabel and a comment listing what it still needs. - Make GitHub require the shepherd’s check. Add a ruleset on
mainthat requiresreview-shepherd/decisionand accepts it only from your GitHub App. From then on nothing merges before the shepherd says so, and no person or agent can post that check in its place. The exact settings are inthe setup guide . - Start strict, then loosen. With
everyone_needs_a_person: true(a top-level setting in the profiles file), every PR needs a human review, whatever its profiles require. If that is already your rule today, start with it on: your process stays the same, but reviewers now only see PRs whose tests and AI review passed. After a month, set it tofalse, so that only profiles with their ownapprovalsneed a person. If reverts or incidents rise, set it back.
Want a dry run first? Set dry_run: true in the profiles file before you merge: the shepherd then only labels each PR and comments what it would have required. This can be a useful way to test the system with your team without creating excessive friction: run it for a week and compare its calls with your reviewers’.
原文来源:renatobudinich.com