Writing ·

A shepherd for your agent PRs: review profiles on GitHub, step by step

TL;DR · A shep­herd for your agent PRs

  • review-shep­herd takes every PR from draft to merge on GitHub, and asks a per­son only where a bug would be expen­sive. It is open source, and the quick­est set­up is to point your cod­ing agent at it.
  • A PR whose author is new to the code gets a review­er who knows it. If the author has no com­mit in the changed fold­ers in the last 12 months, a pro­file can require approvals from peo­ple who do, as a Microsoft study recommends.
  • Rules look at what a change does, not only where it is. A pro­file match­es on paths, or on yes/no ques­tions an AI answers, such as “Does this change who can move funds?”.
  • Review­ers 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 shep­herd 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 pro­files by what a bug would cost, and send only the strict ones to an engi­neer who knows the code. This post builds that on GitHub with­out stalling your team. At its core is a pro­gram I call the shep­herd. It moves each PR from draft to merge, stage by stage: it match­es the PR to pro­files, then enforces what they require. The code is in a com­pan­ion repos­i­to­ry, review-shep­herd. The quick­est set­up is to point your cod­ing agent at the repos­i­to­ry, which has instruc­tions for agents.

  1. Draft PRThe devel­op­er opens the PR as a draft.
  2. MatchThe shep­herd match­es the PR to pro­files by its changed files and the clas­si­fier’s answers.
  3. TestsCI runs the suites from the match­ing profiles.
  4. AI reviewAn AI review (CodeR­ab­bit or chief) flags what should stop the merge. Option­al­ly, this can be run in par­al­lel with the test suite.Block­ing find­ingThe PR stays a draft until the author fix­es it. Three rounds in a row at most.
  5. PRIf both tests and the AI review pass, the PR is pro­mot­ed from draft.
  6. Human reviewIf required by the pro­file, a devel­op­er that knows the code reviews the PR. In case of request­ed changes, the PR goes back to draft.QAA pro­file can also ask a tester to try the change and approve it.
  7. MergeWhen the shep­herd’s check is green.
Fig­ure 1. The stages the shep­herd moves a PR through.

What you’ll build. A few files in your repos­i­to­ry and two set­tings on GitHub. You write the pro­files; the rest you copy from the review-shep­herd 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 itCode language: plaintext (plaintext)

Togeth­er, the shep­herd’s code and the two work­flows are the shepherd.

On GitHub you’ll need to set up:

  • A GitHub App, a bot account, review-shepherd[bot], which the shep­herd posts its check as.
  • A rule­set, GitHub’s merge rules for a branch. It refus­es the merge until the review-shepherd/decision check is green, and accepts it only from the App, so a PR can’t post its own green one. That one check stands for every­thing a pro­file requires, approvals includ­ed: GitHub can’t count approvals per pro­file, so the shep­herd does.

Step 1. Write your profiles

Pro­files are defined in .github/review-profiles.yml. Each one has two parts: which PRs it match­es, and what those PRs need before they merge.

Which PRs a pro­file match­es. There are two kinds of con­di­tion, and either one is enough (under match — see the exam­ple at the end of this section):

  • Paths: any_file_in match­es when at least one changed file is under these paths, and every_file_in when every changed file is.
  • Yes/no ques­tions (ask_classifier) for what paths can’t tell, such as “Does this change who can move funds?”. A clas­si­fi­er answers them, a sep­a­rate AI step from the AI review (Step 4 says which). All the ques­tions still open go in one call, and a yes makes that pro­file match too. An answer can add a pro­file to a PR, nev­er remove one. Write each ques­tion so that a yes means the pro­file applies, and ask about one thing per question.

What those PRs need before they merge. This is what the shep­herd enforces. There are three kinds of require­ment (under the require key):

  • Test suites (checks).
  • An AI review (ai_review).
  • Approvals (approvals): how many peo­ple from which GitHub team, option­al­ly only peo­ple who have com­mit­ted to the changed files’ fold­ers in the last 12 months (knows_the_code). If nobody has, any mem­ber of the team counts. The teams are your orga­ni­za­tion’s teams on GitHub, which the shep­herd reads through GitHub’s API.

A pro­file can also ask for addi­tion­al require­ments when the author is new to the code (if_author_is_new), i.e., when the author has no com­mit in the changed files’ fold­ers in the last 12 months. This fol­lows a Microsoft study, which found more fail­ures in com­po­nents with more minor con­trib­u­tors and rec­om­mend­ed that “changes made by minor con­trib­u­tors should be reviewed with more scruti­ny” (Bird et al., FSE 2011). In the exam­ple below, a new­com­er’s change to critical code needs its two approvals from peo­ple who know that code.

A PR gets the require­ments of every pro­file it match­es, and a label for each, so the order you write them in does­n’t matter.

Each pro­file can also car­ry three option­al prose fields: description (what it is), bug_cost (what a bug costs) and blocks_merge (what should stop the merge). They are con­text, not con­di­tions: the AI review reads all three, and the clas­si­fi­er reads the description.

Pro­fileMatch­es a PR whenTestsWho approves
crit­i­cal Con­tracts, con­sen­sus, sign­ing, migra­tions, CI con­fig, or the clas­si­fi­er says it changes who can move funds or sign Unit, invari­ant, fuzz; muta­tion on the diff 2 from protocol; if the author is new here, both must know the code
user-fac­ing Web app or wal­let UI, or the clas­si­fi­er says it changes what a user sees or signs Unit, end-to-end 1 engi­neer, 1 from qa
stan­dard Noth­ing above Unit, types, linters Nobody; if the author is new here, 1 who knows the code
docs Only docs and Mark­down files Link check Nobody; no AI review
Fig­ure 2. Exam­ple pro­files for a blockchain com­pa­ny. Every pro­file but docs gets an AI review.

In the exam­ple below, a pro­file I call critical match­es the PRs that change code where a bug could lose funds. Its last two paths are the shep­herd’s own files and CodeR­ab­bit’s set­tings, so chang­ing either needs two peo­ple from the protocol team. From the repos­i­to­ry’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}Code language: YAML (yaml)

Step 2. Create the GitHub App

The shep­herd needs an account of its own, to label PRs, take them out of draft, ask review­ers 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, Com­mit sta­tus­es and Con­tents (required for pro­mot­ing a draft), and read on orga­ni­za­tion Members.

Install it on this repos­i­to­ry only. Keep its pri­vate key in a GitHub envi­ron­ment, a named set of secrets with rules about which branch­es may use them. Allow only main, so only a work­flow run­ning from main can read the key. Keep in mind that on a pri­vate repos­i­to­ry, envi­ron­ments and rule­sets need a paid plan, and team approvals need an orga­ni­za­tion (require­ments). The full set­up is in the repos­i­to­ry’s set­up guide.

Step 3. Add the two workflows

We want to min­i­mize human review time which is a scarce resource, so agents open every PR as a draft, and the shep­herd ensures that it stays so until all the defined checks and AI reviews pass. In this way, human review­ers can safe­ly ignore all PRs that are drafts. If, once they review it, they request changes, it again gets demot­ed as draft and the cycle restarts.

On every push, the shepherd:

  1. ensures it is a draft;
  2. match­es the PR against the profiles;
  3. runs the clas­si­fi­er on the ask_classifier ques­tions, poten­tial­ly adding match­ing profiles;
  4. runs the test suites from checks;
  5. starts the AI review, chief or CodeR­ab­bit (see Step 4), option­al­ly in par­al­lel to the test runs (by set­ting ai_review_after_tests: false);
  6. labels the PR and posts its ver­dict as the review-shepherd/decision check: red if the tests or the AI review failed, yel­low while an approval is miss­ing, green when noth­ing is. If the tests and the AI review passed, it also pro­motes the PR and noti­fies a review­er when a pro­file asks for one.

All this is imple­ment­ed in two workflows:

  1. review-check.yml runs steps 2 to 5. It’s exe­cut­ed from its copy on the PR branch.
  2. review-decide.yml runs the first and the last step. It holds the App’s key, is always exe­cut­ed from its copy on main and reads the pro­files from main too.

This sep­a­ra­tion lets the shep­herd treat every­thing the first work­flow pro­duces as untrust­ed 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 mod­el, each with two inter­change­able options, set in the pro­files file. The set­up guide has the set­tings. Since both read text any­one can write, such as the PR descrip­tion, the tem­plate lim­its what a prompt injec­tion could do: the jobs that run them have read-only per­mis­sions and only their own key, and Claude Code runs in its sand­box.

The AI review

The AI review flags what should stop the merge. ai_reviewer picks who:

  • coderabbit runs on CodeR­ab­bit’s servers and fetch­es the code itself. The deci­sion work­flow starts it by adding a label to the PR. A label car­ries no text, so CodeR­ab­bit reads its con­text from its con­fig­u­ra­tion file on main: for each path, what the pro­files cov­er­ing it are about. It knows noth­ing about this par­tic­u­lar PR, such as a pro­file the clas­si­fi­er added. It needs a plan with auto­mat­ic approvals, so that it requests changes or approves, and its con­fig­u­ra­tion source set to main, so a PR can’t loosen its own review.
  • chief, my Ralph Wig­gum imple­men­ta­tion con­fig­ured for review, steers a cod­ing agent in your CI on the PR’s code. It gets the full con­text: the matched pro­files and why each matched, whether the author is new to the code, the tests that passed and who reviews after it. The trade­off is it can be cost­ly (paid via API usage); by default it stops after five pass­es at most.

Either way, block­ing find­ings keep the PR a draft and noti­fy the author. After three blocks in a row the PR is pro­mot­ed and a human review­er takes over.

Man­u­al over­ride: Com­ment­ing /skip-ai-review on the PR waives the AI review gate for the cur­rent com­mit (the next push resets this — AI review will run again). Any­one with a role on the repos­i­to­ry can do it. With CodeR­ab­bit, click­ing “Resolve” on its com­ment has the same effect.

The classifier

The clas­si­fi­er answers the yes/no ques­tions in ask_classifier. These are meant for more nuanced cri­te­ria in pro­file match­ing that can­not be achieved by a regex on paths alone. Review-shep­herd sup­ports two options for classifier:

  • jev is Type­Safe’s “Sys­tem One” deci­sion mod­el (Type­Safe). One request returns the prob­a­bil­i­ty of yes for every open ques­tion. It needs a Type­Safe key.
  • claude makes a Claude Code call instead. It needs an Anthrop­ic key.

With jev, each answer is the prob­a­bil­i­ty of a yes, from 0% to 100%. The shep­herd is con­ser­v­a­tive by default: only an answer below 30% counts as a no, so an unsure answer adds the pro­file too. The set­ting is classifier_threshold.

Step 5. Turn it on

After Steps 1 to 4 the shep­herd is installed, but any­one can still merge what­ev­er its check says. Three things are left.

  1. Merge the set­up into main and open a test PR. The deci­sion work­flow only runs from main. In the exam­ple, if you open a draft PR that changes a file under contracts/, it should get the profile:critical label and a com­ment list­ing what it still needs.
  2. Make GitHub require the shep­herd’s check. Add a rule­set on main that requires review-shepherd/decision and accepts it only from your GitHub App. From then on noth­ing merges before the shep­herd says so, and no per­son or agent can post that check in its place. The exact set­tings are in the set­up guide.
  3. Start strict, then loosen. With everyone_needs_a_person: true (a top-lev­el set­ting in the pro­files file), every PR needs a human review, what­ev­er its pro­files require. If that is already your rule today, start with it on: your process stays the same, but review­ers now only see PRs whose tests and AI review passed. After a month, set it to false, so that only pro­files with their own approvals need a per­son. If reverts or inci­dents rise, set it back.

Want a dry run first? Set dry_run: true in the pro­files file before you merge: the shep­herd then only labels each PR and com­ments what it would have required. This can be a use­ful way to test the sys­tem with your team with­out cre­at­ing exces­sive fric­tion: run it for a week and com­pare its calls with your reviewers’.

20-minute call · with Renato

Your first fix, in writing.

Tell me how your team ships agent-written code. Within two business days you get one written page. No charge.

Not for you if your team is still choosing a coding agent or running a pilot: this is for teams already shipping with one.

Book a 20-minute call I work with 3 teams at a time.

Prefer to write? Send me a message.

  • Your top riskThe gap most likely to hurt you, judged against the five failure modes.
  • Your first fixA concrete step your team can take this week.
  • Do you need help?Which paid option fits, or why you don't need one.