Skip to content

Kerpeten in a pipeline

A pipeline can run kerpeten review for every pull request or merge request. The job prints the findings in its log and can keep them as a file. It can also write them to the pull request or merge request as comments.

Start from a ready example:

Other systems work the same way. This page lists what a job needs.

Status: Kerpeten writes comments to a GitHub pull request and to a GitLab merge request.

Need How
Kerpeten npm install -g kerpeten. Linux on x64 or arm64 with glibc, such as Debian or Ubuntu. There is no build for Alpine.
ripgrep rg on PATH, for example apt-get install -y ripgrep. The models search your code with it.
The configuration A .kerpeten.yml in the repository. Run kerpeten init once on your machine and commit the file. A review reads it from the base branch, so a pull request cannot change the settings of its own review.
A key The API key of your provider, as a secret variable of the pipeline: OPENROUTER_API_KEY, ANTHROPIC_API_KEY or OPENAI_API_KEY. A local model works on a runner of your own that runs the model server.
The history The last commit of the change and its base commit. A shallow clone does not have the base, so fetch the whole history.
A clean checkout The working copy at the last commit of the change, with no changed tracked files.
  • A ChatGPT plan does not work in a pipeline: its sign-in needs a browser on the same machine. Use a model with an API key.
  • Without a version after the name, npm installs the newest Kerpeten on every run. To install the same version on every run, name it: npm install -g kerpeten@0.7.1. Writing comments to a GitHub pull request needs 0.3.0 or later. Writing comments to a GitLab merge request, incremental reviews and the facts the judge marks need 0.4.0 or later.
--base --mr
What is reviewed The change between a base commit and the checked out commit The pull request or merge request, which Kerpeten reads itself
The job needs Only git gh on GitHub or glab on GitLab, and a token that can read the pull request or merge request. To write comments, the token must also be allowed to comment
The reviewer gets The commit messages The title and the description
Comment plan in the output No Yes
Comments on the pull request or merge request No Without --dry-run

With --base, give the base commit. Without it Kerpeten asks for the default branch of origin, which a pipeline checkout often does not set. A review with --base writes no comment and needs --dry-run.

kerpeten review --dry-run --base <base commit>

With --mr, give the number. This writes the comments to the pull request or merge request:

kerpeten review --mr <number>

With --dry-run it writes nothing and shows the comments it would write:

kerpeten review --dry-run --mr <number>

Reviewing lists what --mr reads, what it writes and the errors it can end with.

  • The findings go to standard output, as text, or as JSON with --json.
  • Messages about the run go to standard error. So standard output can be written to a file as it is.
  • Without --dry-run, the comments go to the pull request or merge request: the line comments, and one summary comment, which a later run updates.

The exit code tells whether the review ran and wrote its comments. Findings do not change it:

Exit code Meaning
0 The review ran. It may have findings or none. When it was to write comments, all of them are written.
1 The review could not finish: a model or the platform failed. Or a comment could not be written: the findings are still printed, and standard error says which comment and why.
2 Something you can put right: a missing key, a wrong flag, no .kerpeten.yml, a checkout at another commit, a review without --dry-run and without --mr, which has no pull request or merge request to write to.

A job that writes comments can end with exit code 1 after it printed the findings. Show the output before the job fails, as the GitHub Actions example does. Reviewing lists the messages.

A job with findings passes. To make it fail when a finding scores high enough for a comment on its line, check the JSON:

kerpeten review --dry-run --base <base commit> --json > review.json
jq -e '[.findings[] | select(.action == "inline")] | length == 0' review.json

jq -e ends with 1 when the answer is false. So the job fails when at least one finding has the action inline. The thresholds in .kerpeten.yml set the score a finding needs for that.

  • In each run the reviewer model goes through the change once, and the judge model is called once for every finding.
  • The limits in .kerpeten.yml set how long each may run and how many tool calls it may make.
  • A run that reviews an empty change calls no model.

The key is a secret. Most systems do not give secrets to a pipeline that runs for a pull request from a fork. Without the key Kerpeten stops with exit code 2 and says which variable is missing:

kerpeten review: the reviewer API key is missing; set OPENROUTER_API_KEY

The examples skip the job for forks.

  • The title, the description and the diff of a change are data for the models.
  • The models get tools that read and search the repository.
  • They cannot change a file, run a command or read the variables of the job.
  • They cannot write a comment. Kerpeten writes the comments itself, after both models ran.