Appearance
A slow check
A check in a git hook runs on each commit. In CI, it runs on each pull request. A check that takes two minutes costs two minutes every time. These steps find the slow part. Reviewer calls are the one part of a run that can cost money. You limit them in Bound the reviewer.
The outputs below come from a repository that joins two other guides. It has the script rule no-console of Bring a law into an existing repository. It has the reviewer rule clear-errors and the Ollama reviewer of Write a reviewer rule. Its law:
yaml
lawcheck: 0.1.0
rules:
no-console:
why: Only the command layer writes to the terminal.
clear-errors:
why: An error a caller sees says what happened and what to do next.
types:
library:
about: Code the commands call.
paths: ["src/core/**"]
rules: [no-console, clear-errors]
may_use: [library]
command:
about: The command layer.
paths: ["src/cli/**"]A branch made from main changes src/core/price.ts and src/core/tax.ts. The file src/core/tax.ts imports src/core/price.ts. Put time before a command to see how long it takes. The shell prints its timing lines after the output of Lawcheck.
1. See what the run judges
text
$ lawcheck check --base mainoutput
lawcheck: FAIL 2 errors in 2 changed files (against main)
src/core/price.ts error[not-reviewed] clear-errors has no verdict for this content
why: a reviewer rule says nothing about content it has not judged
src/core/tax.ts error[not-reviewed] clear-errors has no verdict for this content
next: lawcheck check --review --base main (2 reviewer calls)A plain check judges the files of the change against a base. The first line names that base. When the first line ends in (no base: every file counts as changed), the run judges every file (Give the check its base). With --full, a check judges every file that has a type. A check without --review calls no reviewer. Its next: line counts the calls that a review would make.
2. Check one file
text
$ lawcheck check src/core/tax.tsoutput
lawcheck: PASS 1 warning in 1 named file
src/core/tax.ts warning[not-reviewed] clear-errors has no verdict for this content
why: a reviewer rule says nothing about content it has not judgedA check of named files judges those files alone, with no base and no reviewer call. Compare its time with the time of the run in See what the run judges. Then name a folder or a pattern, to find the folder whose files take the time.
3. Run each script rule alone
text
$ lawcheck try no-consoleoutput
lawcheck: try no-console (script rule, enforced) nothing found in 2 fileslawcheck try with no file runs one script rule alone, on every file whose type, or a type above it, lists the rule. Run lawcheck try for each script rule of the law, and compare the times.
4. See which files are read for uses
text
$ lawcheck doctor --base mainFind its readers line:
output
ok readers uses are read in 2 files: typescript 2; the 13 grammars loadA use is an import, or another reference from one file to another. The line counts the files whose uses Lawcheck reads, by language. Lawcheck reads the uses of a file whose type, or a type above it, has may_use (Forbid one layer to use another). A plain check reads the uses of the changed files among them. With --full, it reads the uses of all of them. A large count may come from generated code, or from code copied in from another project. To leave that code out, narrow the paths of the type.
5. Bound the reviewer
Set the limits in .lawcheck/config.yaml:
yaml
reviewer:
provider: ollama
model: your-model-id
max_calls: 20
parallel: 2
timeout: 120The three keys set these limits:
max_calls: 20: a run that needs more than 20 calls sends none. A call that Lawcheck sends again, after a failure or after an answer with no verdict, counts as one more;parallel: 2: Lawcheck sends at most two calls at once;timeout: 120: one call has two minutes.
Without these keys, Lawcheck takes the defaults:
- a run sends at most 100 calls, 4 at a time;
- a call has 60 seconds, or 300 seconds with
ollama; - with
claude-code,codex,gemini-cliorcopilot-cli, a call has 300 seconds. Lawcheck makes one call at a time to these programs.
--max-calls <n> replaces max_calls for one run. This change needs 2 calls, so --max-calls 1 shows the refusal:
text
$ lawcheck check --review --max-calls 1 --base mainoutput
lawcheck: ERROR 1 error
error[too-many-reviews] this run needs 2 reviewer calls and may send 1
why: reviewer.max_calls bounds what one run spends
next: 2 reviewer calls are needed and the limit is 1; raising reviewer.max_calls or --max-calls is the user's decisionThe run stops with too-many-reviews and sends nothing. To count the calls before you spend any, run lawcheck try <rule> <file> --dry-run. It prints the calls and the size of each prompt, and makes no call (Write a reviewer rule).
6. Give the check its base
A plain check takes its base from --base, then from LAWCHECK_BASE, then from origin/HEAD. With none of the three, a check on a machine counts every file as changed. It runs every rule on every file that has a type. With --review, it then asks for a review of each such file. This repository has no remote and no origin/HEAD:
text
$ lawcheck checkoutput
lawcheck: FAIL 2 errors in 9 files (no base: every file counts as changed)
src/core/price.ts error[not-reviewed] clear-errors has no verdict for this content
why: a reviewer rule says nothing about content it has not judged
src/core/tax.ts error[not-reviewed] clear-errors has no verdict for this content
next: lawcheck check --review (2 reviewer calls)The run counts all 9 files that git lists as changed. The run in See what the run judges counted 2. lawcheck doctor without --base prints a note in its base line:
text
$ lawcheck doctoroutput
note base no base: no --base, LAWCHECK_BASE or origin/HEAD, so a plain check counts every file as changed
next: pass --base <branch>, or set LAWCHECK_BASEPass --base with the branch you started from, as the steps above do, or set LAWCHECK_BASE.
The limits of a run
A run that goes over one of the limits below stops with exit 2. A file over 512 KiB is the one exception. It gets the finding uses-not-read, and the run goes on. The table gives the code that the run prints for each limit:
| Limit | Code |
|---|---|
| a script rule: 30 seconds to load, and 30 seconds for each call | rule-crashed |
| all script rules of a run: 600 seconds together | rules-too-slow |
| one step of a run, such as typing one file: 30 seconds | step-too-slow |
a reviewer call: its timeout | reviewer-unreachable |
| a file over 512 KiB, for its uses | uses-not-read |
| one run: 1536 MiB of memory, or 85 percent of the machine's memory where that is less | memory-too-large |
If it goes wrong
- When
step-too-slowcomes while Lawcheck gives a file its type, acontentexpression of the law takes too long on that file. In^(a|a)+$, eachacan match either branch. On a line of 80aand a!, the expression tries every way to match, and the run goes over the limit. Write^a+$instead: it matches the same lines, with one way to match eacha. - The
next:line ofmemory-too-largenames the step that went past the limit. The fix depends on that step:- for a file whose uses Lawcheck reads, leave the file out of the types whose
may_useis in force; - for a file that Lawcheck reads only for the names it declares, keep it out of the files git lists: run
git rm --cachedon it, and add a line to.gitignore; - for a whole run, narrow those types, or run Lawcheck on a machine with more memory.
- for a file whose uses Lawcheck reads, leave the file out of the types whose
internalis a fault of Lawcheck. Run the command again, and report the error if it comes back.
Next: The commands