# Rule: quality gates

Three tiers. Each is scoped so that **many agents committing in parallel
worktrees stay fast** — the whole point is that a gate you are tempted to skip
is not a gate.

| Tier | Hook | Scope | Budget | Runs |
| --- | --- | --- | --- | --- |
| 1 | `pre-commit` | **staged files only** (lint-staged) | < 3s | every commit |
| 2 | `pre-push` | whole project: build + verify + audit | < 90s | every push |
| 3 | CI (Gitea Actions) | tier 2 + visual regression | minutes | every push to `main` |

Tier 1 must stay under a few seconds. If it creeps, move the check to tier 2.
An agent that waits 40s per commit will start passing `--no-verify`, and then
you have no gate at all.

## Tier 1 — pre-commit (lint-staged)

Formats and lints **only what you staged**. Scoped by construction, so ten
parallel worktrees do ten small jobs, not ten full-project sweeps.

- Prettier + ESLint on `*.{js,mjs,ts,astro}`
- Prettier + Stylelint on `*.css`
- `check-tokens.mjs` on changed `.astro`/`.css` — catches raw hex before it lands
- Prettier on `*.{json,md}`

## Tier 2 — pre-push

The real gate:

```
astro check        types
astro build        it compiles
verify.mjs         42 content assertions — count must not fall
audit-ui.mjs       no external runtime dependencies
check-tokens.mjs   full sweep
```

## Tier 3 — CI

Tier 2 plus screenshot comparison against `.agents/snapshots/`. Only CI has the
budget for it.

## Bypassing

`--no-verify` is allowed exactly once: a work-in-progress commit **on your own
task branch that you will rebase away**. It is never allowed on a commit you
intend to merge, and the pre-push gate has no bypass.

If a gate is wrong, fix the gate in its own commit. Do not route around it.

## Parallelism

- Hooks are **per-worktree**. Git's `index.lock` is per-worktree, so parallel
  commits do not contend.
- The heavy tier-2 gate takes a **lock** (`.git/af-gate.lock`, shared across
  worktrees) so ten agents pushing at once do not run ten concurrent builds and
  thrash the machine. Waiters queue; they do not fail.
- `npm ci` in a fresh worktree should use `--prefer-offline` to avoid registry
  contention when several spin up at once.

## The silent-failure mode you must know about

Husky sets `core.hooksPath` to `.husky/_`, and **`.husky/_` is generated by
`npm install`, not committed**. A fresh `git worktree add` therefore has hooks
configured but the directory missing — so **hooks silently do not run**. Every
commit passes. Nothing is checked.

`.agents/scripts/worktree.sh start` runs the install and then verifies. Check
manually any time you did not use it:

```bash
.agents/scripts/verify-hooks.sh
```

Run this first in any worktree you did not create with the script.
