# Hold agents to a quality bar

An agent that says it is done has not proved anything yet. Two things let the board check it
for you: verification checks you agree with the agent for one ticket, and code quality rules
that hold every agent on the board to the same bar. With both on, a ticket only reaches In
Review once its checks pass.

## Before you begin

- A ticket that runs in a git repo. Scratch tickets have no code to check and skip the quality gate.
- The **Developer** profile turns the code quality rules and the
  pre-merge gate on, with **warn** enforcement. **Explorer** leaves them off. See
  [Choose a profile](pick-a-profile.md).

## Verification checks

![Verification checks with two test checks, one failing with its output, and a goal check](img/checks.png)

A verification check is one thing that must be true for the ticket to be done, in plain words,
usually with a command that proves it.

| Kind | Has a command | What it does |
| --- | --- | --- |
| **Test** | yes | Binding: the board runs the command in the ticket's worktree, and it passes when the command exits 0. |
| **Goal** | no | Advisory, for your review. It is never run. |

Where they come from:

1. On a plan ticket, the agent proposes its checks with the plan. They show in the plan card,
   under **Verification checks**. Read them before you click **Accept plan**: accepting locks
   them, so the agent can add stricter checks but cannot weaken or remove one without asking
   you first.
2. On an Auto ticket, the agent declares its checks when it finishes. If it has commits but no
   checks, the board reminds it once.
3. With the pre-merge gate on, the board adds its own check, **Board gate**, to every ticket
   ([below](#the-pre-merge-gate-and-the-ratchet)). Agents cannot edit or drop it.

When they run: after the agent finishes, before the ticket rests in In Review. Test checks run
one at a time, each for at most 10 minutes, and a commit that already passed is not checked
again. The card on the board says **Running checks** while they run.

What a failure does:

- **The first two failures** send the ticket back to To Do with the failing output, and the
  agent fixes it (attempt 1 of 3, 2 of 3).
- **The third failure**, or the same commit failing twice, parks the ticket in Your turn
  for you: fix the work, agree different checks with the agent, or override the quality gate.
- **A check that never finished** (a timeout, a command that could not start) parks the ticket
  without counting an attempt: the code was never judged, so it is not a failure.

**Result:** a ticket in In Review shows **passed** on its **Verification checks**, or the
reason it stopped. You can still merge while a check fails: checks hold the agent, not you.

## Turn on the code quality rules

1. Open **Settings > Code & repositories** and scroll to **Enforcement**.
2. Turn on **Enforce code quality**.
3. Pick an **Enforcement mode**:

   | Mode | What the agent gets |
   | --- | --- |
   | **advise (prompt only)** | The rules, in its instructions. Nothing checks them as it writes. |
   | **warn (post-write feedback)** | After every file it writes, the violations in that file, which it then fixes. |
   | **block (deny the write until clean)** | The same check, returned as a refusal it must clear before it goes on. The file is already on disk: block makes the agent deal with it, it does not undo the write. |

4. Under **Scope & thresholds**, pick the **Scope**: **changed files only (ratchet)** holds
   agents to the bar on the files they touch, **whole project** everywhere. **Global coverage
   minimum** is the coverage floor any language without its own inherits.
5. Click **Save changes**.

**Result:** every agent on the board is held to the rules. The save-time check covers file
length for every language, and for Python ruff plus the complexity rule; for TypeScript and
JavaScript it runs eslint. The repo's own ruff and eslint configuration applies.

## Set the rules per language

![Settings, Code & repositories, Per-language rules: the Python, TypeScript and JavaScript cards with their limits](img/settings-quality.png)

1. In **Settings > Code & repositories > Per-language rules**, edit the card of each language.
   A card has a field for each limit the board checks in that language, so a limit with no
   field is not checked there. A blank field saves the default its hint names.
2. Click **Save changes**.

| Language | Maximum file length | Maximum complexity per function | Minimum coverage, percent | Maximum risk score |
| --- | --- | --- | --- | --- |
| Python | 800 | 10 | 80 | 30 |
| TypeScript | 600 | | 70 | |
| JavaScript | 600 | | | |
| Shell | 200 | | | |
| CSS | 600 | | | |

When each is checked:

- **Maximum file length**: whenever a file is saved.
- **Maximum complexity per function** (Python, cyclomatic complexity): when a file is saved, and
  at the quality gate for a function the change pushes over it.
- **Minimum coverage, percent** (Python and TypeScript): at the quality gate, over the files the
  change adds.
- **Maximum risk score** (Python, the CRAP score of complexity against coverage): at the
  quality gate only.

A limit of 0 turns that check off, both when files are saved and at the pre-merge gate, and
agents are not told about it. A **Global coverage minimum** of 0 does the same for every
language without its own coverage limit.

**Result:** agents are told these limits in their instructions, and the quality gate grades against
them.

## The pre-merge gate and the ratchet

The pre-merge gate is a verification check the board adds to every ticket, so a ticket cannot
reach In Review while the rules are red.

1. In **Settings > Code & repositories > Pre-merge gate**, turn on **Pre-merge gate** (it needs **Enforce
   code quality** on).
2. Leave **Quality gate judging mode** on **ratchet** unless you want every function graded.
3. Click **Save changes**.

**Result:** from the next implementation run, each ticket carries a **Board gate** check. It
runs with the other checks and fails the same way, sending the agent back to fix what it made
worse. Plan runs, Loops, chats and scratch tickets do not get it.

How the quality gate judges a change:

- **ratchet** (the default) charges only what the change makes worse: a function the diff
  touches that is new, or more complex than on the base branch. A function that was already
  over the limit before stays grandfathered, so an edit to a legacy file can still land.
  Coverage is measured over the files the change adds, not the whole project, and test files
  are never graded.
- **absolute** grades every function in every file in scope against the raw limit.

A collector that runs out of time (7 minutes) is a warning, not a failure, and **Quality gate test
workers** sets how many parallel test workers its coverage run uses.

To run the same quality gate yourself, from the repo:

```bash
rev0 quality-gate
```

It prints **Code Quality gate passed: no violations.** or **Code Quality gate FAILED** with
one line per violation, and exits 1 on a violation. It reads the board's global settings, not
a board's overrides.

## Override the quality gate on one ticket

When the quality gate is wrong for one ticket (a generated file, a vendored module):

1. In the ticket's **Verification checks**, click **Override quality gate**.
2. Confirm **Override quality gate**.

**Result:** the board gate stops running on that ticket and the button reads **Quality gate
overridden, turn back on** until you click it. It is recorded as an override, not as a pass,
and the ticket's own checks still run, so an override never clears one of them. A check in
progress can also be stopped with **Stop check...**.

To change the bar for one board, open its **Board settings** and, under **Per-board
overrides**, **Add an override...** for **Enforce code quality**, **Enforcement mode**,
**Pre-merge gate**, **Scope** or **Global coverage minimum**. The per-language rules apply to
every board.

## If something goes wrong

### Verification still failing after 3 attempts

The agent could not make a test check pass. Read the output under the failing check, then reply
with a hint (**Reply**, then **Send**) or ask the agent to change the checks (it needs your
approval to weaken one). The card offers **Override quality gate** only when the quality gate
is one of the checks that failed. When only the ticket's own checks failed, it names them, and
you can accept the ticket as it is: move it back to In Review and click **Merge**, or move it to
Done when nothing needs to land. The failed checks stay on its record.

### The verification checks did not finish

A check timed out or could not start, so the code was never judged. Often the command needs a
tool the worktree lacks. Fix the command or the environment and move the ticket back to To Do.

### Quality gate reports 0% coverage

The quality gate measures coverage with the board's own test runner. In a repo with its own virtual
environment, the tests may fail to import. See [python coverage 0.0% is below the 80% floor](troubleshooting.md#python-coverage-00-is-below-the-80-floor).

## Related

- [Review and merge an agent's work](review-and-merge.md), for what you do once the checks pass.
- [Review and annotate a plan](review-a-plan.md), where you agree the checks.
- [Settings](../reference/settings.md), for every quality setting and its default.
