Checks
A check is the part of a standard that a machine can run on your code. Each check names an evaluator and gives it options. This page covers every evaluator that ships with Groundrule, every option and default, where findings point, and how to test a check before you rely on it.
How checks work
Section titled “How checks work”A check is one entry in a standard’s spec.checks list:
spec: checks: - evaluator: regex # which evaluator pattern: 'console\.log\(' # options for that evaluator message: console.log in application code| Evaluator | What it checks | Source shown with findings | Confidence |
|---|---|---|---|
regex |
A pattern that must not, or must, appear in file contents. | deterministic | certain |
files |
Files that must or must not exist. | deterministic | certain |
dependencies |
Packages that must not be declared in manifests. | deterministic | certain |
imports |
Architecture rules over import statements: layers that must not import each other, modules reachable only through their public entry, packages only some code may use. | deterministic | certain |
layout |
Where files live and what they are called: a name pattern, the directories a kind of file may live under, a companion file that must exist for it. | deterministic | certain |
metrics |
Size and complexity limits: lines per file, lines per function, parameters, nesting depth. | deterministic | certain for file lines, high for functions |
change-set |
Files that must change together. | deterministic | certain |
semgrep |
Semgrep rules. Needs Semgrep installed. | static analysis | high |
llm |
A question about the change, answered by a model on Groundrule’s hosted checks. Advisory; never fails a change. Not run locally or in CI. | AI | from the model, filtered by minConfidence |
Every check also accepts minConfidence (see The rule format). Every other key is an option for the evaluator, and an unknown option is an error.
A standard can have several checks. Its findings are those of all its checks. A standard with no checks is guidance: it reaches agent files and is reported as ◇ guidance by check.
Which files a check reads
Section titled “Which files a check reads”- Groundrule lists the repository’s files: tracked files, plus untracked files that git doesn’t ignore. Outside a git repository, it walks the folder.
- It never reads its own files: the
.groundrule/folder, generated agent files, the managed block inAGENTS.md,CLAUDE.mdand Copilot instructions, and any YAML file that declaresapiVersion: groundrule.dev/…. - It keeps the files that match the standard’s
scope.pathsand not itsscope.exclude. - When checking a change (the default), content evaluators read only the changed files among those. With
check --all, they read all of them.
regex, dependencies, imports and semgrep read file contents. They skip files over 1,000,000 characters and binary files.
New and legacy findings
Section titled “New and legacy findings”When you check a change, every finding is marked new or legacy. Only new findings can fail check, unless the configuration sets legacy: enforce.
enforcement.scope |
A finding is new when |
|---|---|
changed-lines (default) |
Its lines overlap lines the change added or modified. |
changed-files |
Its file was added, modified or renamed in the change. |
all |
Always. check audits every file. |
A finding with no file location (for example “Required file is missing”) is always legacy in a change. It counts with check --all, or with legacy: enforce. See Configuration.
Errors in a check
Section titled “Errors in a check”The CLI validates each check’s options when it runs. A problem is reported against the file and the check’s position, and check exits with 2:
✕ Config error .groundrule/standards/ACME-006.yaml spec.checks[2].evaluator: Unknown evaluator "nope". Available: change-set, dependencies, files, imports, layout, llm, metrics, regex, semgrep.✕ Config error .groundrule/standards/ACME-006.yaml spec.checks[2].flags: Allowed flags: i, s, uA check that can’t run in this environment (Semgrep not installed, no change to compare) is not evaluated. It is listed with the reason, and never fails check:
– ACME-005 not evaluated: Needs a change to compare. Run in a pull request or with --base.Forbids, or requires, a regular expression in file contents.
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
pattern |
string | Yes | A JavaScript regular expression, without slashes. | |
flags |
string | No | "" |
Any of i (ignore case), s (. matches newlines) and u (Unicode). g and m are always on. |
mode |
forbid or require |
No | forbid |
forbid reports every match. require reports every file that has no match. |
message |
string | No | See below | The finding’s message. |
include |
list of globs | No | Only files matching these, within the standard’s scope. | |
exclude |
list of globs | No | Skip files matching these. | |
maxMatchesPerFile |
integer | No | 20 |
Stop after this many matches in one file. 1 to 1,000. |
Because m is always on, ^ and $ match at the start and end of every line.
Findings with mode: forbid: one per match.
- Location: the file and the line where the match starts (leading whitespace in the match is skipped). A match across lines also records the end line.
- Evidence: the line, for example
4: console.log("refunding", id, amount);. - Default message:
Matches forbidden pattern /<pattern>/<flags>.
Findings with mode: require: one per file in scope that doesn’t match.
- Location: line 1 of the file.
- Evidence:
<file> does not contain /<pattern>/. - Default message:
Required pattern /<pattern>/ not found.
With the default changed-lines scope, a require finding is new only when line 1 of the file changed, for example in a new file. Existing files show as legacy.
# Forbid: no direct Stripe imports outside the gatewaychecks: - evaluator: regex pattern: '\bfrom\s+["'']stripe["'']' message: Stripe imported outside the payments gateway
# Require: every workflow declares top-level permissionschecks: - evaluator: regex mode: require pattern: '^permissions[ \t]*:' include: [".github/workflows/*.yml", ".github/workflows/*.yaml"] message: Workflow does not declare top-level permissionsErrors: Enter a regular expression, pattern is not a valid regular expression, Allowed flags: i, s, u.
Quoting patterns in YAML
Section titled “Quoting patterns in YAML”Put patterns in single quotes. Inside single quotes, YAML keeps backslashes as they are, so '\bfoo\w+' reaches the evaluator unchanged. To include a single quote, write it twice: '["'']' is the character class ["'].
In double quotes, YAML reads backslashes as escapes. "\w" fails to load with Invalid escape sequence \w, and "\b" silently becomes a backspace character. If you must use double quotes, double every backslash: "\\bfoo\\w+".
Requires or forbids files by path.
| Option | Type | Required | Description |
|---|---|---|---|
require |
list of globs | One of the first three | Each glob must match at least one file. |
requireAny |
list of globs | One of the first three | At least one of the globs must match a file. |
forbid |
list of globs | One of the first three | No file may match these. |
allow |
list of globs | No | Files exempt from forbid, such as .env.example. |
message |
string | No | The finding’s message. |
At least one of require, requireAny or forbid is needed (Set at least one of require, requireAny, or forbid).
| Option | Files it looks at | Finding | Default message |
|---|---|---|---|
require |
Every file in the standard’s scope | One per glob with no match, with no file location. Evidence: No file matches <glob>. |
Required file is missing: <glob> |
requireAny |
Every file in the standard’s scope | One, when no glob matches, with no file location. | None of the required files exist: <globs> |
forbid |
Changed files in a change; every file with --all |
One per matching file, at line 1. | This file is not allowed in the repository: <file> |
Missing-file findings have no location, so they count in check --all and are legacy in a change.
# From SEC-002: no .env files, but examples are finechecks: - evaluator: files forbid: ["**/.env", "**/.env.*"] allow: ["**/.env.example", "**/.env.sample", "**/.env.template"]
# Commit a lockfilechecks: - evaluator: files requireAny: ["**/package-lock.json", "**/pnpm-lock.yaml", "**/yarn.lock"] message: No dependency lockfile is committeddependencies
Section titled “dependencies”Forbids dependencies in package manifests.
| Option | Type | Required | Description |
|---|---|---|---|
forbid |
list of strings | Yes | Dependency names or globs. At least one. |
ecosystems |
list | No | Limit to some of npm, maven, gradle, pip, go, cargo. Default: all six. |
allowInstead |
list of strings | No | Approved replacements. The fix reads Use <a> or <b> instead. |
message |
string | No | The finding’s message. Default: Forbidden dependency "<name>". |
How to write names in forbid:
| Ecosystem | Manifests read | Write names as |
|---|---|---|
npm |
package.json (dependencies, devDependencies, optionalDependencies, peerDependencies) |
axios, @aws-sdk/* |
maven |
pom.xml (<dependency> blocks) |
group:artifact, or artifact alone to match any group |
gradle |
build.gradle, build.gradle.kts (implementation, api, compileOnly, runtimeOnly, annotationProcessor, kapt, testImplementation, testRuntimeOnly, testCompileOnly) |
Same as Maven |
pip |
pyproject.toml (PEP 621 dependencies and optional dependencies, Poetry dependency tables), requirements*.txt |
The package name. Case and -, _, . don’t matter. |
go |
go.mod (require) |
The module path, for example github.com/dgrijalva/jwt-go |
cargo |
Cargo.toml (dependencies, dev-dependencies, build-dependencies, target-specific tables) |
The crate name |
Each finding points at the line that declares the dependency. Evidence reads, for example, package.json declares request (npm), which matches "request". Lockfiles and node_modules/ aren’t read.
In a change, only manifests that changed are read. With changed-lines, adding a forbidden package is new; one that was already there is legacy.
# From TS-002checks: - evaluator: dependencies ecosystems: [npm] forbid: [request, request-promise, request-promise-native, node-uuid] allowInstead: ["fetch", "crypto.randomUUID()"]imports
Section titled “imports”Architecture rules, checked deterministically on the import statements of the files under check (CLI 0.14.0, ADR 0009). TypeScript, JavaScript, Python, Java, Kotlin and Go (the last three from CLI 0.21.0, ADR 0011).
| Option | Type | Required | Description |
|---|---|---|---|
from |
list of globs | No | The files the rule applies to. Default: every file in the standard’s scope. May contain placeholders such as {feature}. |
forbid |
list of globs | For a layer rule | Repository paths the from files must not import. |
allow |
list of globs | No | Exceptions within forbid, e.g. a module’s index.*. |
package |
string or list | For a package gate | Package names or globs: stripe, @prisma/*, sqlalchemy. |
only |
list of globs | With package |
The only files allowed to import the package. |
message |
string | No | The finding’s message. Default names the file, the import and the rule. |
remediation |
string | No | The fix shown with each finding. |
A check is either a layer rule (forbid) or a package gate (package + only); a standard can have both as two checks.
How imports are resolved. Each import is turned into a repository path when it can be: relative paths (./x, ../y, with extensions and index files tried against the repository’s files); tsconfig.json or jsconfig.json baseUrl and paths aliases; npm workspaces, by the package name in each workspace’s package.json; Python packages, from the repository root, src/, and any top-level package, plus relative imports (., ..). Whatever doesn’t resolve to the repository is a package: a layer rule never fires on an import it didn’t understand, and a gate fires only on a package name that matches. That is what keeps these checks certain enough to reach Enforce.
For Java and Kotlin, an import resolves through the repository’s source roots (src/main/java, src/main/kotlin, their test siblings, then the repository root and src): com.acme.shop.infra.db.OrderRow becomes src/main/java/com/acme/shop/infra/db/OrderRow.java, a nested class resolves to its outer class’s file, and com.acme.shop.infra.* to the directory. For Go, an import resolves through every go.mod in the repository to the package’s directory: github.com/acme/shop/internal/infra/db becomes internal/infra/db. What does not resolve is a package named by the qualified name or the import path, so a gate reads package: "org.springframework.jdbc.*", "java.sql.*" or "github.com/stripe/**". Same-package references, which need no import statement in either language, are not seen.
Placeholders. {name} in a from pattern captures one path segment and is substituted into forbid and allow, so one rule covers every feature:
checks: - evaluator: imports from: ["src/features/{feature}/**"] forbid: ["src/features/!({feature})/**"] # other features allow: ["src/features/!({feature})/index.*"] # except their indexTwo more shapes:
# A layer rule (ARCH-001)checks: - evaluator: imports from: ["**/domain/**"] forbid: ["**/infra/**", "**/api/**"] remediation: Depend on an interface the domain owns; inject the implementation from outside.# A package gate (ARCH-007)checks: - evaluator: imports package: ["stripe", "@stripe/*", "com.stripe.*", "github.com/stripe/**"] only: ["**/payments/**"]# The same layer rule on a Spring service and a Go servicechecks: - evaluator: imports from: ["src/main/java/com/acme/shop/domain/**", "internal/domain/**"] forbid: ["src/main/java/com/acme/shop/infra/**", "internal/infra/**"]Each finding points at the import’s line, with evidence such as src/domain/order.ts:1 imports "../infra/db/client", which resolves to src/infra/db/client.ts. Comments are ignored; imports built from variables are invisible. In a change, only changed files are read, and an import that was already there is legacy.
The architecture pack ships eight such rules at Observe, with conventional directory names you adjust to your layout.
Preview in the editor. From CLI 0.22.0, groundrule scan --upload sends the repository’s resolved import graph (each import’s file, line, and the path or package it points at; never code; RFC 0015). While an admin edits an imports check in the dashboard, a line under the options says what it would report today: “Today, 3 imports in 2 files would violate this, across 4 scanned repositories”, with one example per repository. --no-import leaves the graph out.
layout
Section titled “layout”Where files live and what they are called (CLI 0.22.0, ADR 0012). Applies to every file in from and checks each one by its name only; nothing is read.
| Option | Type | Required | Description |
|---|---|---|---|
from |
list of globs | No | The files the rule applies to. Default: every file in the standard’s scope. |
exclude |
list of globs | No | Files in from to skip, such as the test files of a companion rule. |
name |
glob | One of the four | The file’s base name must match it: *.controller.ts. |
namePattern |
regular expression | One of the four | The base name must match it: ^[a-z0-9-]+\.ts$ for kebab-case. |
place |
list of globs | One of the four | Directories the file must live under; outside every one is a finding. |
companion |
list of patterns | One of the four | A file that must exist for it. {dir}, {base}, {name} and {ext} are the file’s directory, name without extension, full name and extension; at least one pattern must match a file in the standard’s scope. |
message |
string | No | The finding’s message. |
remediation |
string | No | The fix shown with each finding. |
# HTTP handlers live in the delivery layer (ARCH-010)checks: - evaluator: layout from: ["**/*.controller.ts", "**/*_handler.go"] place: ["**/api/**", "**/http/**", "**/transport/**"]# Every source file has a test file (ARCH-009)checks: - evaluator: layout from: ["src/**/*.ts"] exclude: ["**/*.test.ts", "**/index.ts"] companion: ["{dir}/{base}.test{ext}", "tests/**/{base}.test{ext}"]# File names are kebab-casechecks: - evaluator: layout from: ["src/**/*.ts"] namePattern: "^[a-z0-9.-]+\\.ts$" message: Use kebab-case file names.Each finding is on the file at line 1, with evidence that says which option failed and what was expected. Companions are looked up among the files in the standard’s scope, not only the files under check, so a changed source file finds its unchanged test; keep the test files in the scope and skip them with exclude.
metrics
Section titled “metrics”Size and complexity limits (CLI 0.23.0, ADR 0013), for TypeScript, JavaScript, Python, Java, Kotlin and Go. Set any of the four limits.
| Option | Type | Required | Description |
|---|---|---|---|
from |
list of globs | No | The files the rule applies to. Default: every file in the standard’s scope. |
exclude |
list of globs | No | Files to skip, such as generated code and migrations. |
maxFileLines |
number | One of the four | Lines in the file. |
maxFunctionLines |
number | One of the four | Lines from a function’s header to its closing brace, or to the end of its indented body in Python. |
maxParameters |
number | One of the four | Declared parameters; Python’s self and cls are not counted. |
maxNesting |
number | One of the four | Blocks nested inside the function’s body: one if holding one for is 2. |
message |
string | No | The finding’s message. |
remediation |
string | No | The fix shown with each finding. |
# Functions stay short and flat (ARCH-012)checks: - evaluator: metrics exclude: ["**/*.generated.*", "**/migrations/**"] maxFunctionLines: 60 maxParameters: 5 maxNesting: 4Functions are found with tolerant patterns, as imports are: declarations, methods and arrow functions assigned to a name in TypeScript and JavaScript, def in Python, methods and fun in Java and Kotlin, func in Go. Bodies are measured by brace matching with comments and strings blanked, or by indentation in Python. A file’s line count is reported as certain; function measurements as high, and each finding says what it measured: “placeOrder() in src/orders.ts is 84 lines, over the limit of 60”. Cyclomatic complexity is not measured; that needs a parser, which is a Semgrep rule or your linter.
change-set
Section titled “change-set”Rules about the shape of a change: when some files change, others must change too.
| Option | Type | Required | Description |
|---|---|---|---|
when |
object | Yes | The rule applies when the change touches files matching this. |
require |
object | Yes | Then the same change must also touch files matching this. |
message |
string | No | The finding’s message. Default: This change needs <what>, for example This change needs a new migrations/**. |
when and require each take:
| Field | Type | Matches |
|---|---|---|
changed |
list of globs | Files added, modified, renamed or deleted. |
added |
list of globs | Files newly added. |
Each needs at least one of the two (Set changed or added).
The finding points at the first file that triggered the rule, on its first changed line. The evidence lists Changed: <files> and Missing: <what>.
# From PROC-004: entity changes include a migrationchecks: - evaluator: change-set when: changed: ["src/main/**/entity/**/*.java"] require: added: ["src/main/resources/db/migration/V*__*.sql"]A change is needed to compare. Without --base, check compares your uncommitted work, including untracked files, with the last commit. With --base origin/main, it compares everything since the branch left origin/main. With check --all, there is no change, so the check is not evaluated.
semgrep
Section titled “semgrep”Runs Semgrep rules and reports their matches.
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
rules |
string | Yes | A Semgrep rules file, or a registry config such as p/owasp-top-ten (any p/, r/ or s/ config, or auto). |
|
timeoutSeconds |
integer | No | 300 |
Stop Semgrep after this long. 1 to 1,800. |
A relative rules path resolves against the folder of the standard’s file. Keep rules files outside the standards folder, for example in .groundrule/rules/. Every YAML file in .groundrule/standards/ is loaded as a standard, and a Semgrep rules file isn’t one.
checks: - evaluator: semgrep rules: ../rules/auth-017.yamlSemgrep must be installed where check runs. If it isn’t, the check is not evaluated, with the reason Semgrep is not installed. Install it with `brew install semgrep` or `pipx install semgrep`. groundrule doctor reports Evaluator semgrep is unavailable in that case. When Groundrule checks pull requests without CI, Semgrep is installed in the sandbox, but the sandbox has no internet: use a rule file from the repository there, since registry configs such as p/owasp-top-ten can’t be downloaded. See Check pull requests without CI.
Groundrule runs semgrep scan --json --quiet --metrics=off --disable-version-check on the files in scope, 400 files at a time. Each result becomes a finding:
- Location: the result’s file and lines.
- Message: the Semgrep rule’s message, or
Matched Semgrep rule <id>. - Evidence:
Semgrep rule <id>and the first line of the matched code. - Confidence:
high. SetminConfidence: certainon the check to report Semgrep results as concerns that never fail.
If the rules file doesn’t exist, the check is not evaluated, with semgrep failed: Semgrep rules not found at <path>. Registry configs need network access.
An AI check asks a model one question about a change, the question a reviewer would ask. It runs only on pull requests that Groundrule checks itself, and only when an admin has turned on AI checks on hosted pull requests in Settings → AI. Everywhere else (groundrule check on a laptop or in CI, the stop hook, the MCP check tool) the rule is reported as not evaluable with “AI checks run on Groundrule’s hosted checks; not here”, and its other checks still run. No laptop ever pays for tokens or sends code anywhere.
checks: - evaluator: llm question: > Does any new state-changing endpoint reach business logic without a server-side authorization check? include: ["src/api/**"] # optional; the standard's scope otherwise exclude: ["**/*.test.ts"] # optional minConfidence: high # medium (default) or high| Option | Required | What it does |
|---|---|---|
question |
Yes | One question about the change, 20 to 2,000 characters. The model answers it over the changed lines only. |
include, exclude |
No | Globs narrowing which changed files are reviewed, within the standard’s scope. |
minConfidence |
No | medium keeps findings the model is at least half sure of; high keeps only those it is sure of (0.8 and above). |
What the model sees. For each changed file the rule names: the changed lines with three lines of context on either side, numbered, with secrets redacted; the rule’s title, requirement and question. Never the whole file, never unchanged files. Per run at most 40 files, 400 lines per file and 200 KB in all; past that, the rule is reported as not evaluable for the rest.
What comes back. Findings with a line, a one-sentence message and the model’s confidence. They are labelled AI on the run page and on the pull request, with blocking: false: at 0.8 and above a finding is a violation, below it a concern, and either way the run’s pass or fail was decided before the model was asked and never changes. The rule’s outcome becomes warned when any finding stands.
Cost. One call per rule and file, cached for 30 days by content, at most $0.50 per run and within the workspace’s monthly AI budget; each call is in the AI ledger under checks.ai-review with tokens and cost, never with the code. See AI and your data.
Keeping false positives down
Section titled “Keeping false positives down”A check that flags correct code teaches people to ignore it. In order of preference:
- Narrow the standard’s scope.
scope.pathsandscope.excludeapply to every check and to agent files. For example,exclude: ["**/*.test.ts", "scripts/**"]. - Narrow one check.
regextakes its ownincludeandexclude. - Tighten the pattern. Anchor it (
^,\b), match the call and not the word, and test it on both examples (see below). - Record known false positives in
quality.knownFalsePositives, so people adopting the rule know what to expect.explainshows them. - Grant an exception for code that is right to break the rule, with a reason and an expiry. See Overrides and exceptions.
- Start the rule early. In a connected workspace, publish it at Observe or Advise, look at the evidence, and move it to Enforce when it is clean. See Rollout stages.
For pack rules, the catalog rates each rule’s noise (low, medium, high) and recommends a starting stage. See the Packs reference.
Test a check against its examples
Section titled “Test a check against its examples”There is no separate test command. Use check on a scratch file. Untracked files count as part of your change.
-
Write the forbidden example into a file the standard covers.
Terminal window printf 'import Stripe from "stripe";\n' > src/http/scratch.ts -
Run only that standard.
Terminal window npx @groundrule/cli check --only ACME-004You should see the finding, and an exit code of
1for a blocker:✕ ACME-004 Route all Stripe calls through the gatewayBLOCKER · deterministic (regex)src/http/scratch.ts:1Stripe imported outside the payments gateway1: import Stripe from "stripe"; -
Replace it with the approved example and run the check again.
Terminal window printf 'import { createPaymentIntent } from "../payments/gateway";\n' > src/http/scratch.tsnpx @groundrule/cli check --only ACME-004You should see
Passed. -
Run it on the whole repository to see what it flags in existing code.
Terminal window npx @groundrule/cli check --all --only ACME-004 -
Delete the scratch file.
Terminal window rm src/http/scratch.ts
If the forbidden example passes, check the file is inside scope.paths, the language matches scope.languages, and the pattern is in single quotes. npx @groundrule/cli explain ACME-004 shows the scope as the CLI read it.
In the dashboard, Describe a rule tests the check it writes against its examples before showing it to you. See Describe a rule.