The landing
The prover session left its work uncommitted and handed back a report; the report is a claim about the tree, and the landing reads the tree: the declaration manifest’s diff, a cold read-back of every landed statement, the binders and the guards.
Then the document’s rows are written from the landed proof, the summary sites swept, the records closed (where the research plugin is set up) and the commit made with named paths.
The tool is scripts/formal.py of the land skill (/formal:land in Claude Code), the one CLI of the formal plugin: the handback diff, the read-back packet, the check, the three gates over the documents and what ships, the hypotheses ratchet and the witnesses report, beside formal probe, formal init and formal handoffcheck, which The formal setup and The handoff use.
This page is the tool — its commands, the generator and the manifest it reads, its checks and its words — and the skill is the procedure of a landing.
What it does
formal handbackfirst, and the whole diff is read, not the names the report lists: everything the report names must be there, and everything the diff shows that the report omits is the surplus that makes a document boundary stale; each absent commissioned declaration is named in the log entry. It reads no proof: asorry, anadmit, anative_decideor a newaxiomis the build’s warnings and the project’s#print axiomsguards to catch.- A read-back before anything is read at the binders:
formal readbackbuilds the packet, one fresh subagent given the packet and nothing else writes out what each declaration literally asserts, and that prose is compared to the document’s statement quantifier by quantifier; a mismatch changes the row or sends the statement back, never reads the document into the Lean. - Every commissioned declaration is opened at its binders in the source, and every binder is tiered VERBATIM, ADAPTER, IMPLIED or UNANCHORED against the document’s statement; guards commissioned together are read one by one.
formal check, then the three gates over what the landing touched, and the project’s own figure check where it states tree-derived figures, the new total written and never a delta.- The result is registered by the project’s rule, else the
methodskill’s register test, and the rows and the boundary paragraph are written from the landed proof, each ADAPTER binder named as such and each UNANCHORED one with its reason. - The summary sites are swept — the status label, the abstract, the contributions, the settled-and-open lists, an earlier row’s boundary, every negative-coverage sentence about the result’s kind — found by the claims’ own words.
- Where the research plugin is set up, the flow closes the prover’s task with
flow make, then each finding is minted from the landed proof withflow finding … --evidence … --ref TASK, the declaration among its evidence asformal:Path.lean#decl, the path relative to the workspace, not to the project’s root, the one that settles the question with--answers Q; a failed handoff isflow abort, its refuting finding minted after it, taggedrefuted; and the commit names its paths.
The commands
| Command | What it does |
|---|---|
formal handback [--base REV] [--handoff DRAFT] |
the manifest diff against HEAD: the new public and private declarations, the removals, the visibility flips, the field changes and the per-module counts; the instantiations of an existing generic; the joint-satisfiability witnesses owed; the guards added and removed in the workspace diff with the live total after the change; every document site citing a declaration of a touched module; and the commission, every name of the handoff’s Commissioned: line sorted into four classes, landed, private (in the tree, not citable), already at base and absent; a cited name removed from the manifests that is in [documents] upstream moved upstream and is listed in a block of its own, MOVED UPSTREAM, one line a site, with no failure; exit 1 on a document citing a name now private or removed and not so listed |
formal readback NAME… [-o FILE] [--depth N] |
the packet a cold reader writes each landed statement out from: the statement with its modifiers and scope lines (cut where the proof starts: the first := outside brackets that no let or have of the statement is still waiting for, so a local definition the statement binds is read whole), every project-local definition its elaborated statement refers to, to depth two (a definition’s value too), read from the manifests’ uses rows, so a projection, an inherited field, dot notation and an instance are Lean’s and not guessed from the text, docstrings and comments stripped; a manifest without the uses section is refused with the command that regenerates it, exit 2 |
formal rows [--json] |
every row of the manifests with its kind and fields, as {"schema": 1, "rows": […]} under --json, else each manifest’s count per kind: the one read of the manifests outside the plugin; exit 1 where a row matches no kind |
formal resolve [--public] [--json] [--protocol] TARGET… |
whether each target (Path.lean#name, Path.lean, or a name; - reads them from the standard input) is a declaration or a module of the manifests, a line and the count for each that is not; --public also fails a private one; --json prints each target with every declaration its name could mean; --protocol is the research flow’s call; exit 1 where one does not resolve, 2 where it could not run |
formal check |
the manifests parse and are the tree’s, each read its named conditions under the project’s own roots, the umbrellas import their modules, the packages import in order, the bindings resolve |
formal cite, formal anchors, formal register |
the three gates over the documents and what ships, each a pre-commit hook |
formal hypotheses [--base REV | --baseline FILE [--update]] |
no public theorem shipped at the base gained a named condition |
formal witnesses [--base REV] |
the public theorems with two or more named conditions and no _nonvacuous witness, by module; a report |
Every command reads formal.toml at the project root (--root DIR for another, before the command or after it); formal --help prints every command and the manifest’s row grammar, and needs no bindings file.
The skill names every flag, and the kit’s tests hold it to the script.
The manifest
scripts/DeclManifest.lean beside the CLI generates a Lean package’s declaration manifest after a genuine build: from the workspace, lake env lean --run DeclManifest.lean --roots Root1,Root2 --out ../scripts/decls.txt, with --own naming the roots whose Prop-valued definitions count as named conditions, by default every root built in the workspace’s own packages; the roots taken are printed and written as the manifest’s second line, # own roots: A,B, which formal check holds against [packages], so a generate command passes --own only where the default is not the project’s.
The setup copies the file into the workspace once and binds one command per package in formal.toml’s [manifest] generate; the prover session regenerates the manifests after the last declaration change, and the flow asks formal resolve about declaration evidence and reads none of them.
A manifest is a text file in a row grammar any prover’s declaration list may follow, seven row kinds:
module <module> <count> a module and how many declarations it counts
<module> <name> a public declaration
private <module> <name> a private one (counted, not citable from outside)
field <module> <name> a structure projection (citable, not counted)
hypothesis <module> <theorem> <cond> a public theorem's named condition
instance <module> <theorem> <class> a class one of its instance binders carries
uses <module> <decl> <const> a project declaration the decl's elaborated statement refers to
The generator walks the compiled environment, so it needs the build current, and its counting rule is stated in its own header; another prover writes the same seven row kinds with its own tool.
The uses rows are the elaborated environment’s answer to what a statement refers to: for each counted declaration, the project declarations its type uses and, for a definition, its value too, a structure projection mapped to its structure through the environment’s projection info and a constructor, recursor or generated helper to the declaration it belongs to, an upstream name dropped; the header line # uses rows: N says the section was written, so formal readback, the one command that reads them, refuses a manifest of an older generator and says to copy the generator over and regenerate.
The checks
The formal plugin’s checks report in words rather than codes.
Each exits 0 when clean, 1 when it found problems, each printed with its place, and 2 when it could not run, so a hook or a CI job never reads “did not run” as “clean”; each ends with a coverage line saying what it looked at.
formal rows and formal resolve
formal rows --json prints {"schema": 1, "rows": [{"kind": "decl", "file": "scripts/decls.txt", "line": 12, "module": "Lib.Foo", "name": "lemma_L"}, …]}: every row in the manifests’ order with kind, file, line and module, and the kind’s own fields under the names the grammar gives them — count for module; name for decl, private and field; theorem and condition for hypothesis; theorem and class for instance; decl and const for uses.
A project’s own script reads the manifests through it and filters the rows by the kinds it knows: a new kind is a new value of kind under the same schema number, which moves only when a kind’s fields change, so an old reader ignores it.
A row matching no kind exits 1 with its file and line and prints no JSON, since a row is never absorbed into another kind; formal check stays the strict validator of a manifest.
formal resolve answers for a list of names of the project’s own and for the research flow’s formal evidence.
A target is Path.lean#name, Path.lean (a module) or a name with no path, the module scope left out.
The module is the path without .lean, / read as ., and its file under the package directory [packages] binds for its root must exist; a module resolves where a module row names it, and a name where a decl, private or field row’s name is it or ends in . and it, among the rows of the module where a module row names it, or where it is Module.name, a declaration with the base name in a module that Module ends on a component boundary.
It prints one line for each target that does not resolve, with why, then the count, and exits 0 where all resolve, 1 where one does not, and 2 where it could not run: no formal.toml, a manifest missing, or a row matching no kind.
--public also fails a target whose every reading is a private declaration; without it a private one resolves, which is the flow’s claim, existence.
--json prints one JSON document in the lines’ place, {"schema": 1, "targets": [{"target": "Host.lemma", "readings": ["Root.Host.lemma"], "ok": true}, …], "ok": true}, an object for each target in the order given.
Its readings are every declaration the name could mean, public and private and in no module’s scope, so a project’s own tool that counts every reading of a name, a visibility closure for one, reads them and keeps no copy of the rule that can drift from the gate’s; a module has none, and a target that does not resolve carries its why.
The text’s lines and exit code stay as they are.
--protocol is the flow’s call: one JSON request on the standard input, {"protocol": 1, "form": "formal", "items": […]}, one JSON answer on the standard output, {"protocol": 1, "items": {TARGET: {"ok": true} | {"ok": false, "why": "…"} | {"unchecked": "…"}}}, with exit 0 whenever it answered; a manifest that is missing leaves every item unchecked, with the command that regenerates it, and the protocol is described on the flow’s page.
formal check
formal check reads formal.toml and reports:
- a workspace that is not a directory, or the prover session’s instructions file missing;
- a package root with neither
<Root>.leannor<Root>/under its package directory; - a declaration manifest missing, with the command that regenerates it, or a row outside the grammar
formal --helpprints; - with
[packages]bound: the manifests’ modules not the tree’s (the files on disk under each root, those git ignores left out), the missing and the extra named with the command that regenerates them, and a module counted under a root[packages]does not bind; - with
[packages]bound, each manifest’s# own roots:line, the roots whose Prop-valued definitions the generator read as named conditions, against[packages]: a manifest without the line (an older generator’s, to copy over and regenerate), a root[packages]does not bind (a library required by path from outside the project), and a bound root the package’s modules import, directly or through another module, left out (a package required by git, under.lake/packages/, or an explicit--ownthat misses it); - a root’s umbrella
<Root>.leannot importing a module under<Root>/, or importing one not in the tree (umbrellas = falseturns this off; a module the package’s lakefile declares as a library root of its own stands outside the umbrella); - a module importing a module of a later package of
[workspace] package_order.
Its coverage line names the manifests with their row counts by kind, the packages bound and the documents scanned, and says the prover tree itself is not built.
formal cite, formal anchors, formal register
Three gates over the documents and what ships, each bound in formal.toml, each exiting 1 with every site named and 2 when it could not run:
formal cite: no document matching[documents] scan; a declaration name a document cites that resolves nowhere, resolves only to private declarations, or is a dotted name scoped by a namespace or a module of the manifests and names no declaration; a citedX.leanthat is not a module; an API-docs link to a module not in the tree; a name bound as retired that the manifests still hold. A dotted name is read where its first component is a namespace segment at any depth of a declaration’s name or a module’s last component: it resolves to every declaration it ends on a component boundary (Host.lemmaforRoot.Host.lemma), to a declaration of a module byModule.name(Code.thingfor a declaration with the basethinginRoot.Code, the formformal resolvereads too), or to a module by the path written from below a root (Code.BitGatesforRoot.Code.BitGates), and is drift where it is none of these. The allowlists and[documents] ambiguous_namespacesare read first, and a dotted name whose first component is none of these, no module’s last component and no base name of the manifests is an upstream name and stays unread. A name an upstream library shares with a module’s last component (Basic,Matrix) or with a namespace segment goes inambiguous_namespaces, which leaves the names under it unread. A name under such a namespace that is also a declaration’s base name is still read as a declaration-scoped name. Its coverage lines count the resolutions by kind and the allowlisted names by list, andformal cite --jsonprints in their place one JSON document listing each citation that resolved (document, line, token, kind and the sorted declarations it resolved to), the allowlisted tokens by list,unread(each dotted token left unread because its first component is inambiguous_namespacesand would otherwise be read: document, line, token and that namespace), the drift andok, with the text’s exit code, so a tool that needs the cited declarations reads them rather than copying the rule;formal anchors: no file matching[anchors] scan; a[Key] §N,[Key] Theorem N.Mor[Key] Appendix Xnaming no heading, statement of that kind or appendix of the key’s document, or a statement riding a section it is not in; the bare keys and the § lines with no key are counted, not checked;formal register: a line of a shipped file matching a bound pattern class after the sanctioned expressions are cut; a.leanfile name a shipped file in a file class’s scope mentions that is no module of the class’s packages and that noallowexpression matches as written (a bare-name expression lets no path-qualified mention through); a class reaching no file, a file class naming a package with no tracked.leanfile, or an empty scope. A package directory outside the repository, a library required by path, is listed by what its own repository tracks, or by its.leanfiles on disk where it is in none, a build’s.lake/left out. Its coverage line counts the files each class reads, and the modules of each package where a file class is bound.
formal hypotheses exits 1 where a public theorem shipped at the base, or listed in a baseline, gained a named condition, and says INERT, exiting 0, where the manifests carry no hypothesis row; formal witnesses is a report and exits 0.
Words
- guard, guard family — a checked expectation beside a theorem (
#guard_msgsover#print axiomsin Lean) that a declaration’s axioms, or a named instance’s value, are as stated; a family is the set of instances that pin a theorem’s hypotheses as load-bearing. - instantiation of an existing generic — a landed declaration that is an existing generic theorem at one instance (
mul_comm_intundermul_comm), the shape a report compresses into a clause. - drift, drift list — the document sites a landing makes false or stale — figures, boundaries, citations — reported verbatim by the prover session and swept by the root session.
- read-back packet — a landed statement with the project-local definitions it names, docstrings and comments stripped, for a reader who has not seen the document.
- binder tiers — VERBATIM, ADAPTER, IMPLIED, UNANCHORED: what each binder of a landed declaration is against the document’s statement.
- umbrella — a library root’s file
<Root>.lean, importing every module under<Root>/;formal checkreads it. - named condition — a binder of a public theorem whose type is one of the workspace’s own Prop-valued definitions, applied in full; the manifest’s
hypothesisrows, whichformal hypothesesratchets. - internal register — the words of the project’s own process (record ids, stage labels, private paths), which a docstring never carries since it renders into the public API docs;
formal registerreads what ships for them.