The statute command
Part of the Rule system, whose status and terms apply here.
Compilation and the site
Locally, the compiler takes the constitution (the version for agents) and a rule set with its lock file, and writes:
- an
AGENTS.md, which holds the constitution’s version for agents and then the enabled rules under a heading for each domain, each rule an item of its reference and its statement and nothing more (below). The file is not split for now. Once the compiled file of a repository using it has been measured withcount-tokens, a length threshold is set from that measurement, and a file over it is split along domains; - the skill directories the enabled rules need;
- the version of the check binary to install, and the external commands of the enabled rules.
The AGENTS.md holds only the enabled rules whose uses has
instructions (Where a rule is used);
once parameters are built, each placeholder is replaced by its value
(Parameters).
statute compile writes the AGENTS.md next to statute.toml, or to
another file with --output, and the skills next to it (below),
and only when the lock file is what statute lock would write now, the
version of statute it records included; when only that version differs,
the error names both
(Rule sets and the lock file). The
AGENTS.md holds, in
this order: a comment that the file is generated, which compile reads to
tell its own file from one written by hand; the constitution’s version
for agents in the rule set’s language, the file
constitution/<edition>/generated/constitution.<lang>.agent.md that the
constitution’s build writes, unchanged, when the rule set rests on a
constitution (Rule sets and the lock file);
and a heading “Rules” with the
enabled rules. The edition, revision and source the file rests on are in
statute.lock, not in the file.
AGENTS.md is for agents, as is the private full text,
.statute/AGENTS.full.md, built the same way. Below the heading
“Rules”, each domain with an enabled rule in the file is a heading of
its title, in the rule set’s language when it has a translation into it
and in its original otherwise, its placeholders filled as in a
statement. Each enabled
rule is one item, - <reference> <statement>, such as
- R22 Keep a credential out of every message.: the rule’s reference
as statute shows it (R42, L12, P7, team:7), a space, and its
statement, a line after the first indented by two spaces to continue
the item. Nothing else goes in: no title, reason or verification of a
rule, nothing of a one-of, nothing of a domain but its title, neither
its applicability nor an anchor or link. The headings take few lines
and let an agent, or a person reading the file, see where each group of
rules starts. The relations and settings
between the nodes, requires, conflicts, one-ofs, overrides, the
defaults, uses and parent, are metadata: statute checks them when it
locks and compiles, and once the rule set compiles they have done their
work and stay out of the file. The titles of rules, reasons,
verifications and the domains’ applicability are for people, on the site (below); the
reviewer gets a rule’s reason and verification from statute check.
The references stay, at the start of each item, so that a review’s
findings and a citation can name the rule.
The headings and items follow the tree, a node before its children, so that related
rules stay together: the first-party source’s domains first, then those
of the other sources by the sources’ names, then the repository’s own;
below a node, the first-party source’s children first, then those of
the other sources by name, then the repository’s own, each source’s by
ID; below a domain, its rules and one-ofs first, and its subdomains
after them, each part in that order, so that a domain’s own rules stay
together. The sites order a domain’s children the same way, under one
heading for each domain
(The local site, Static site).
“Rules” is a heading of level one; a domain at the top is a heading of
level two, and each domain below it one level below the nearest domain
above it, down to level six, the last Markdown has, which also holds
every domain deeper than that. A domain hung under a domain of another
source takes its level from its place in the tree. A one-of has no
heading and takes no level: it contributes its enabled option, an item
when the option is a rule and, when it is a domain, the domain with its
heading, one level below the domain the one-of is in. A subtree with no
enabled rule contributes nothing, not even a heading. A blank line
comes before and after each heading, and the file ends with one
newline. An overriding rule
(Overrides) stands at the place of the rule
it overrides, which is not in the file. A rule uses its translation
into the language when it has one, and its original otherwise. The
citations in a statement are rendered (IDs):
{@rule:<id>} as the cited rule’s reference, R42, whether the rule is
in the file or not, and as the rule in its place when it is overridden,
unless that rule is the one citing it, which names it as itself; and {@constitution:<id>} as the provision’s label in the language, in
plain text as in the version for agents, such as Art. IV §1(2). A
citation whose text is half-width at one end, as R42 is, is set off
by a space from a Han character next to that end (摘下 R42 的), as
Chinese typography asks, and so it is on the sites. The labels
come from the edition’s sources, the numbers of the articles’ and
sections’ names and the items’ number, by the same rules as in the
constitution’s build (Compilation); unlike that build,
citations in a row are not shortened (Art. IV §1, Art. IV §2). A
citation of a node or provision that does not exist fails the command,
naming the rule and the part. The rules’ files and their hashes in the
lock file are unchanged.
In the directory of the AGENTS.md, statute compile also writes:
- each skill an enabled rule needs (Rules and skills),
copied whole from
skills/<name>/of the rule’s source (for the repository’s own rules, theskills/at the top of the repository, unless a source is that directory, as withR = { path = "." }: those skills are then the source’s, and the repository’s own rules have none) to.agents/skills/<name>/(two needed skills of one name, from two sources, fail the command), with a file.statute-generatedadded, and a link to that copy,.claude/skills/<name>, whose target is the relative path../../.agents/skills/<name>. Each skill has a link of its own, never one for the whole directory nor one forSKILL.mdalone; Claude Code reads a repository’s skills only from.claude/skills/(read 2026-10-14). Links are made only on a Unix system: elsewhere, a rule set that needs a skill fails the command. A skill may hold only directories and regular files.
The version of statute and the commands of the checks, which CI reads,
are in the lock file (Rule sets and the lock file).
statute before 0.1.18 wrote them to a file of their own,
statute-checks.toml, next to the AGENTS.md; statute compile deletes
that file when it starts with statute’s comment, and leaves one without
it alone.
The AGENTS.md starts with a comment that statute wrote it
(<!-- ... -->). Before writing
anything, the command checks every place it would write, and when one holds
something it did not write (a file without that first line, a skill
directory without .statute-generated, a .claude/skills/<name> that
is not its link), it writes nothing at all and fails. When a skill is to
be written, .agents/skills and .claude/skills must be plain
directories, or absent: a repository that links the whole of
.claude/skills to ../.agents/skills fails the command, which names
the link, since statute writes a link per skill. A skill directory
with .statute-generated that the rule set no longer needs is removed,
with its link; nothing else in .agents/skills/ or .claude/skills/ is
touched. The same input compiles to the same bytes, links included.
The files are not written all at once: an error midway, such as a full
disk, can leave part of the output, and running the command again
finishes it. The order makes that work: a skill’s
.statute-generated is written before its files, a link is removed
before its directory, and the AGENTS.md is written last.
statute compile --check writes nothing. It compiles the public layer
and fails, naming each place, wherever statute compile would change
something: an AGENTS.md that differs or is missing, a
statute-checks.toml it would delete, a file of a skill’s copy that differs from the source, is
missing or is not in the source, a copy or a link that is not statute’s,
and a skill directory with .statute-generated that the rule set no
longer needs. The private output, which git ignores, is neither compiled
nor compared, so a private layer that does not load does not fail it.
Like compile, it fails when statute.lock is not what statute lock
would write now. This repo runs it as a commit hook, which CI runs too.
A CLAUDE.md next to the AGENTS.md written (the top of the
repository, unless --output names another place), a file or a link to
AGENTS.md, draws a warning on every statute compile, with or without
a private layer. The warning asks whether to delete it, and says why in
a few short sentences: Claude Code reads AGENTS.md itself when there
is no CLAUDE.md
(Rule sets and the lock file,
Monorepos), so a CLAUDE.md is not needed to point to it; with the
private output, where CLAUDE.local.md gives Claude Code the full text
in place of AGENTS.md, Claude Code reads a CLAUDE.md as well, so its
content comes on top of the rules, the public rules twice for a link to
AGENTS.md (Private rules in a public repository),
a sentence the warning leaves out without a private layer; and the
migration (statute-migrate,
step e) renames a CLAUDE.md that is a file to a legacy copy, and
asks the user whether to delete one that is a link to AGENTS.md.
statute neither deletes nor renames it. Not built yet: the warning
still says that a migration renames either kind.
Compiling, checking and upgrading a rule set are one command
(The command and the first version).
The same command builds the constitution, statute constitution build.
The public site lists every rule, so that people can choose from
the full list, with a filter that leaves superseded and repealed rules
out by default; a superseded rule keeps its page, so links to it keep
working. A rule of this repo is shown as R42 there too. What the list
and the rule pages show is in Static site.
The command and the first version
The command. The rule system’s command is written in Rust (see
Why Rust) and grows in the crate crates/statute
(File structure). The first version is that one
crate. Its name is statute: on crates.io, 0.0.1 is a placeholder that
held the name, and the command starts with 0.1.0
(Releases and versions).
The rule set is statute.toml, the lock file
statute.lock, and the commands are:
init: write a new rule set; with--global, the global configuration (Global configuration and git sources);source add: name a source in the rule set, its private layer or the global configuration (Adding a source);addandremove: enable a rule or take it out of the rule set, and update the lock file; with--private, of the private rule set (Private rules in a public repository);lock: resolve the rule set into the lock file;compile: write the compiled output (Compilation and the site); with--private-only, only the private output, for a git hook in a new worktree, without the network, and failing when it does not write a private output it should (Private rules in a public repository, A new worktree); with--check, nothing, failing when the committed output differs from a fresh compile;hooks install: write thepost-checkoutandpost-mergehooks that runcompile --private-only, leaving a hook it did not write as it is (Private rules in a public repository, A new worktree);check: list the enabled rules for review by domain, with the outcome of those a script checks (Checks);upgrade: move the sources and the constitution to newer versions (Rule sets and the lock file);explain: say why a rule is enabled and which rules require it;site: write a local site of the rules the rule set can draw on (The local site);export: print the constitution and the rules of a directory as JSON, for a program that reads them (Export);constitution build: build the constitution of the repository it runs in from its sources, or check it (below);validate <dir>: check a directory of rule files on its own, as one source, without a rule set (below).
The first version builds the repository level only. The user level
is planned, not built; retiring the hand-written guide that the private
overlay installs in the user’s home directory today does not wait for it
(Cutover from the hand-written guide). The rules of this repo have moved to
the new format, each keeping its earlier word ID as its slug. Among the first
rules written in the new format are those for writing a design document,
which try the whole process on real work.
Built so far: the commands init, lock, explain, add,
remove, upgrade, compile and check
(built-in checks for rules 43, 46, 50, 58, 61 and 71, and for 3 and 7,
which 43 and 46 supersede), site, constitution build and
validate, for sources on disk and git
sources, as many as
[sources] names, and export. The repository’s own rules, L12, are read from
.statute/rules/, or the directory local-rules names
(The directory of local rules);
when that is a source’s rules directory, as with local-rules = "rules"
and R = { path = "." }, they are that source’s, and a local reference
fails with a note to write R12. A rule names a rule of another source in
requires, conflicts and {@rule:...} as R12, P7 or team:7, with
the names of the rule set’s [sources]: a source’s own [sources]
table (Sources and references)
is not read yet. Of Rule sources, public is built,
with which rules may cite which in requires, conflicts,
overrides, parent and {@rule:...}, and the check of public against GitHub
(Checks). Loading a rule set, as every command
that reads one does, checks that each authority entry and each
{@constitution:...} citation of the repository’s own nodes not
repealed, and of the enabled rules of the other sources, names a
provision of the edition that exists and is not repealed, as validate
does beside the constitution; each finding names the rule and its line,
rules/7.toml:12. Overrides are built, with scope
and the ranks, and so are subdomains, a rule’s or a domain’s parent
in another source, and the private layer with its lock file in git’s
directory, its output, .statute/.gitignore,
compile --private-only and hooks install.
The global configuration, init --global, git sources and source add
are built (Global configuration and git sources),
except that upgrade does not show the text of a changed rule yet.
Of Rule configuration, the rule files’ default,
uses and check = "none" are read and checked, with the tree of
No rule under a rule, and
uses decides what compile writes and check lists, and the
default switches of a rule set are built, with domains, exclude,
local-rules and a source entry’s defaults, and what add,
remove, explain (--defaults included) and the lock file do with
them; default is required where the rule files need it, and
check = "review" fails; parameters are built, with their values in
the lock file, upgrade, explain <name> and both outputs; the marks
of both sites, the public site’s pages of parameters, the one-of’s place
in the compiled AGENTS.md and the one-of as a box on the sites are
built.
Inherited rule sets and path segments are not built.
init writes statute.toml in the current directory: the
constitution’s source and edition, public = true or public = false,
an empty rules, and, with --source, one source on disk, the
first-party source R.
public is what --public or --private says (one of them at most),
or else what gh
shows for the repository, as in
Public or not. --source <dir> gives the source’s directory, relative
to the current one. Without it, init writes no [sources],
and R is the global configuration’s or the built-in default
(Which source a name means),
read at the head of the branch it follows. --edition names the edition;
without it, init takes the one directory under the source’s
constitution/ that holds an index.toml, and fails when there is none
or more than one, naming those it found. It resolves the rule set before
writing it and writes nothing when that fails. It does not write
statute.lock: with no rule enabled there is nothing to pin, and the
first add writes it, replacing a statute.lock already there. An
existing statute.toml is left as it is, and init exits with status 1.
upgrade compares the resolution with statute.lock, prints what
changed (Rule sets and the lock file),
or that the lock file is up to date, and writes the lock file as lock
does. Without a statute.lock there is nothing to compare with, and it
exits with status 1. With --replace-superseded it first replaces, in
rules and packs, each superseded rule with its successor, following
the chain to its end, and keeps the rest of the file as written; when
the successor is listed already, the old entry is only taken out. Where
the chain reaches a rule with more than one successor, the entry is left
as it is and the successors are listed, for the user to choose with
add and remove. A repealed rule is left for the user to take out. When the changed rule
set does not resolve, neither file is changed. With --private, which
--replace-superseded excludes, it moves only the private layer’s own
sources and writes only the worktree’s private.lock
(Private rules in a public repository);
outside a git repository it fails.
validate <dir> reads the rule files of one directory as the
first-party source, with its parameters in params.toml, and runs
every check that needs no rule set (Checkers):
the format of each node and parameter, the tree, the targets of its
references, the translations, citations and placeholders, and the
defaults; and, of this one source alone, that no node in force names a
superseded or repealed node of it, which a rule set reading a source
does not check. Each finding goes to standard error on a
line of its own; an error makes it exit with status 1, and a clean run
prints one line to standard output with the number of nodes. When
<dir> has a constitution/ beside it, it also reads that constitution
and checks what the constitution decides of the rules: each node’s
status against index.toml’s, each {@constitution:...} citation and
each authority entry, with the warning on an authority that names a
provision and one above it; a constitution that does not load is one
error, and its own errors are left to constitution build. Without
one, when statute.toml in the directory it runs in has no
constitution, the rule set there rests on none, and a rule may leave
out authority and constitution, and a {@constitution:...}
citation is an error, as when that rule set reads it
(Rule file format); with no
statute.toml there, or one that names a constitution, both are
required. With
--base <git-ref> it also runs the rules part of check 7: when the
numbering is compared, every node of the base still exists, a rule of
the older format as the node whose slug is its name, and what was
repealed or superseded still is, and a node changed beyond its
translations has a higher revision than at the base; it skips the comparison, with the
note, where check 7 does, and without a constitution/ beside <dir>
it fails. These findings are rules/7.toml:12: error: <message>.
This repo runs statute validate rules as a commit hook, and CI runs
it with --base too. --base <git-ref> compares with the tip of
<git-ref>, not with the point where the branch left it, so a branch
behind it shows the nodes changed there as its own changes; merge the
base into the branch before running it locally. On a pull request, CI
compares the merge commit with its first parent, which this does not
affect, and on a push to main, the commit before the push.
constitution build checks the sources of the one edition under
constitution/ and writes the full version and the version for agents
in each language to its generated/, whose first line names the
command that wrote them, cargo run -p statute -- constitution build;
with --check it writes nothing and fails when a committed file
differs from a fresh build; with --check --base <git-ref> it also
compares the numbering and the revision with that commit; and `–root
Moving over. Repositories move onto statute one at a time: in a
repository whose root has a statute.toml, the repository’s compiled
output governs and the user-level instruction files of the private
overlay are set aside, as those files themselves say; everywhere else
they still govern. How a repository switches and when the user-level
files are retired is
Cutover from the hand-written guide.
The local site
statute site writes a site of the rules a rule set can draw on into
.statute/site/ next to statute.toml, to be opened in a browser from
disk; it is never published, and it is not
the public site. It reads statute.toml and, when it
is there, the private rule set, both layers resolved in memory, with
each git source at the commit the lock file records
(Git sources); it writes no lock
file. It prints the path of index.html.
- Files. Plain HTML with one inline style sheet, which follows
Frontend with the public site’s tokens, and its icons
inlined; the index also inlines one short script, which the page
works without (Frontend). No Hugo, and no
dependency beyond those statute has. Each run builds the site
anew: it removes the old
.statute/site/first, but only when that directory holds statute’s.gitignore(below), and otherwise writes nothing and fails. Nothing is written outside.statute/site/but.statute/.gitignore. - Ignored by git. statute writes
.statute/site/.gitignoreholding*, so git ignores every file there, that one included, and it marks the directory as statute’s. It also writes.statute/.gitignore, which lists/site/, as every command that writes a generated file into.statute/does (Private rules in a public repository). Before anything, in a git repository, it asksgit ls-filesabout.statute/site/, and when git tracks a file there it writes nothing and fails, naming the file and the way out,git rm -r --cached .statute/site. When git cannot answer, because it does not start or fails, statute writes nothing either and fails with git’s error. Outside a git repository there is nothing to commit and nothing to ask. - The index has the four kinds of source
(Four kinds of source) as
sections: global public, global private, local public and local
private. Each lists its sources, and each source its rules, enabled or
not, a domain’s rules and one-ofs before its subdomains
(Compilation and the site), in a table
of rules (Frontend): a row
per rule, its reference, title, marks and whether this rule set
enables it, overrides it or leaves it out, with both layers: a rule
only the private rule set enables is marked enabled, and one its
excludeturns off is marked left out, under a group row that names its source and domains; a one-of is a box that holds its options, the default marked. All of them are on the one page. A rule’s row also holds its statement, in the page’s language or, marked as not translated, in the rule’s own, its placeholders filled as for nodes’ pages (below). A switch beside the filter shows the title, by default, or the statement in the title’s place; radio buttons and the style sheet do it. The script writes the choice into the address asview=titleorview=statement, and nothing for the default, so that back and forward return to it, and keeps it for the next index opened. The address decides the view, and one withoutviewshows the default; only when the index opens at such an address does it show the view kept, and write it into that address. An index opened at an address with an unknownviewshows the default and leaves the view out of the address. The filter has a menu of check boxes per field: the status, superseded and repealed left out by default; the defaults; the use; the domain; the kind of source; and whether this rule set enables the rule. The style sheet applies the boxes at once, so the filter works without the script, a domain’s box then holding only the rules right in that domain; the script checks or clears the domains under a domain with it, writes the filter into the address and adds All and None, a search of the rows’ text, Clear filters and the number of rules shown. The legend above it folds, and stays as the reader left it. - The kind of a source follows its two properties: local for the
repository’s own rules (
L) and a source withscope = "local", global for any other, the global configuration’s included; public as the source declares it, and forLas the rule set does. A source at., asR = { path = "." }in this repo, is first-party and so global public. Whenlocal-rulesnames its rules directory, its rules are the repository’s own as well: it is listed once, as global public, and the local public section says so and links there; otherwise the repository’s own rules are listed in the local section of their kind. Not built yet: the site still treats a source at.as the repository’s own rules whateverlocal-rulesnames. Every node, in the index and on its page, is marked with the kind of its source: its name, in the language of the pages, on one of four background colors. On the node’s page the mark also names the source, as inGlobal private · me. - One page per node,
<source>/<id>.html: the statement, reason, verification and applicability;requires,conflicts,overridesand the successors; the path of parents and the children. A link to a node whose title a node under another parent has adds its parent’s title, as does the index’s menu of domains (Frontend). A domain’s page is the list of its nodes. A citation of a rule is a link to its page, and one of the constitution the provision’s label, as in the compiledAGENTS.md. A status is shown as the rule file writes it,draftortrial. - Two languages. The pages are written in English and in Chinese:
at the top of
.statute/site/in the language of[compile] lang, since the site is the repository’s and not the reader’s, and inzh/, oren/when that language is Chinese, in the other, with the same paths below it. Each page links to itself in the other language (Frontend, the language switch). The words statute adds, the kind of each node and of its source included, are in the page’s language. A node’s title and texts are in the page’s language where the rule file has them, and otherwise in the node’s own, marked with that language’slang; its page then carries a tag that says it is not translated. Such a text cites the constitution with the labels of its own language and names the rules it cites in that language too. - The marks of Rule configuration. Every domain
and rule, in the index and on its page, says whether it is on or off
by default, and an option of a one-of whether it is the one-of’s
default. A rule’s page says where it is used,
AGENTS.md, review or both, and two filters of the index hide the rules for either. A placeholder shows the value this rule set gives the parameter, the person’s own where there is one, marked as the public site marks it (Frontend), with a tip that names the parameter and a link to the page of its source’s parameters,<source>/parameters.html. That page lists each parameter’s title, name, type, scope and default, its value and where the value comes from, and the enabled rules that use it.
Export
statute export [<dir>] prints the constitution and the rules of a
directory, . by default, as one JSON value, for a program that reads
them; this repo’s site does
(Static site, Rules). It resolves no rule set: the
directory is a source, holding constitution/, rules/ or both. Only
when the directory has no constitution/ does it read one key of
statute.toml in the directory it runs in, constitution; when that
file has none, a rule may leave out authority and constitution, and a
{@constitution:...} citation is an error, as validate reads the rules
(above).
constitution:nullwithoutconstitution/; otherwise theedition,revision,statusandlanguagesof theindex.tomlof its one edition (with none or more than one, the export fails), and itsprovisionsin the order of the text: each article, section and item with itsidas a citation names it, itsparent(nullfor an article) and itslabelsby language, as the compiledAGENTS.mdwrites them.nodes: each node ofrules/in order of ID, with itsfileand itsfieldsas the file writes them, texts included. A program gets each value as written and a field statute learns later without a change to the export; it applies its own defaults. One value is statute’s own reckoning, so that no program repeats it:on-by-default, whether the source’s defaults enable the node (Default switches), never for a superseded or repealed rule, andnullwhen that depends on a node of another source.params: the parameters ofrules/params.toml(Parameters) in the order of the file, each with itsname,type,values(achoice’s, elsenull),scope,defaultandtitleby language, andshown: the default as the outputs write it, by each language a title of the source is written in (a language by its name, “Chinese”, 「中文」); empty without that file.
Before it prints anything, statute checks the rules as it checks any source (Dependencies, one-ofs and packs); when a check fails, it prints the errors alone and exits with status 1. A translation that follows an older original fails that check, so every translation a node lists follows its current original. JSON is the one format, so the command has no option to choose one.
Why Rust
Speed is not the main reason. A few hundred file checks and regular expressions take a second or two in Python as well; what costs time and money is the reviewer’s model calls. Rust is chosen because:
- the checks ship as one binary, which needs no Python or other runtime, so a downstream repository in any language can use them;
- running the checks in parallel is easier to get right;
- limae, a Rust linter shipped as a Python wheel and run from pre-commit, already reaches downstream repositories this way, so the distribution path has been tried.