Skip to content

Guard command

Muhammet Şafak edited this page Jun 20, 2026 · 1 revision

guard — declarative policy gate

commitbrief guard evaluates a review's actionable findings against a declarative policy (.commitbrief/policy.yml) and exits non-zero when the policy is breached. It is a richer alternative to the single --fail-on=<severity> threshold — a per-severity budget — and is aimed at gating high-volume, often AI-authored pull requests at scale. It pairs with the MCP server: an agent self-reviews via the review tool, and guard enforces the bar in CI.

Introduced in v1.10.0 (ADR-0029). Opt-in and additive — it changes nothing about the existing commands or --fail-on.

The policy file

.commitbrief/policy.yml — the gate is opt-in: with no file, guard errors (it never silently passes). Unknown keys are rejected so a typo can't disable the gate.

version: 1
thresholds:        # maximum findings allowed per severity
  critical: 0
  high: 0
  medium: 5
  low: ~           # ~ (or omitted) = unlimited
total: 20          # optional overall cap on actionable findings

Severities are the canonical five (critical, high, medium, low, info). A severity that is absent — or set to ~ — is unlimited.

Two modes

Run-mode (default) reviews the diff and evaluates the result. It reuses the exact review pipeline (runReview) — diff acquisition, filtering, the pre-send guard + secret scan, cost preflight, cache, the flaky pre-pass, and signal control — with no --fail-on set, because the policy decides the verdict.

commitbrief guard                  # staged diff (default)
commitbrief guard --unstaged       # working tree
commitbrief guard --diff main...HEAD

Provider/model/flaky knobs come from the persistent flags (--provider, --model, --no-flaky).

Consume-mode (--from-json) evaluates a review you already produced — no provider call. Ideal for gating an agent's self-review (the MCP review tool's JSON) cheaply in CI:

commitbrief --json --staged > review.json
commitbrief guard --from-json review.json
commitbrief guard --from-json -        # read the JSON from stdin

What it counts

guard evaluates the findings that survive baseline + inline suppression (signal control) — exactly the set that commitbrief --json emits and that a human reviewer sees. Baselined and suppressed findings do not count toward the gate.

Output & exit codes

Exit Meaning
0 pass — every threshold (and the total cap) is within budget
non-zero blocked — a threshold was exceeded, or the policy/review could not be loaded or parsed

A load/parse failure blocks deliberately: a merge gate must not pass when it cannot prove the change is within policy.

By default guard prints a human summary (the verdict, each breached severity, and the per-severity counts). With --json it emits a machine verdict:

{
  "passed": false,
  "counts": { "critical": 1, "high": 0, "medium": 8, "low": 3, "info": 0 },
  "total": 12,
  "violations": [
    { "severity": "critical", "allowed": 0, "actual": 1 },
    { "severity": "medium", "allowed": 5, "actual": 8 }
  ]
}

guard vs --fail-on

--fail-on=<severity> is a single all-or-nothing threshold (fail if any finding meets or exceeds one level). guard is a declarative, version-controlled, per-severity budget that can also consume a prior review's JSON. They are independent — use either or both.

Flags

Flag Default Meaning
--policy <path> .commitbrief/policy.yml policy file (resolved relative to the repo root)
--from-json <file|-> consume-mode: evaluate a prior schema-v1 review instead of running one
--unstaged false run-mode: review the working tree instead of the staged index
--diff <range> run-mode: review an arbitrary git diff range (repeatable)

Limits

Rule-id-scoped allow/deny lists are not supported: findings carry no stable rule identifier (they are free-form model output), so a name-based list would be unreliable. That awaits a finding rule-id field.

See also

Clone this wiki locally