Lean plugin
Use Lean to keep a proof next to the product: a rule of a pricing engine, a
property of a parser, a lemma an agent proved for you. Lean 4 checks every step
of a proof; the plugin makes the result a step of a flow, so a change that breaks
the proof, leaves a sorry behind or quietly weakens the theorem fails the run.
It checks a model, not the code. A Lean definition is someone’s reading of the code and keeps passing when the code changes. Pair it with a journey flow that exercises the same rule. Lean says nothing about what a user sees, and it replaces no journey test.
Install
Section titled “Install”Lean is an optional plugin. It carries its own Lean 4.36.0 (the lean checker,
Lean’s Init and Std libraries and the SAT solver bv_decide uses), so it is not
inside the CLI download. reflow init downloads it once for your platform from
the release your CLI was installed from (about 270 MB), checks it against that
release’s manifest and installs it. Plan and apply never download, and a check
needs no network.
reflow init --upgrade Lean --collection <collection-id>The other selected plugins stay exactly as locked. A teammate’s device, or CI,
installs it with plain reflow init, because the application’s lock names it. No
Lean needs to be installed, and none on the machine (elan, a lean on PATH) is
used.
Connect
Section titled “Connect”The binding takes no configuration:
{ "lean": {"provider": "Lean", "configuration": {}}}chmod 600 /absolute/path/to/bindings.jsonreflow target --group proofs --scope device --collection <collection-id> --bindings /absolute/path/to/bindings.jsonThe flow carries the proof
Section titled “The flow carries the proof”A Lean step reads only files its flow carries. Put each Lean file in the flow as a
fenced block whose info string is lean file="NAME", and name the theorems the
step proves:
---name: Discount rule proofsproviders: lean: Lean---
### The discount rule keeps its promises```rfllean.check file="Discount.lean" theorems="Discount.total_le Discount.total_eq_zero"```
```lean file="Discount.lean"namespace Discountdef total (price discount : Nat) : Nat := price - min discount pricetheorem total_le (price discount : Nat) : total price discount ≤ price := Nat.sub_le price _theorem total_eq_zero (price discount : Nat) : total price discount = 0 ↔ price ≤ discount := by unfold total omegaend Discount```Each .lean file is a module named by its path: Pricing/Rules.lean is
Pricing.Rules, and the flow’s files import each other by those names. Only
Lean’s Init and Std and the flow’s own files can be imported: Mathlib, Batteries,
import Lean and other Lake packages are not available. A small dependency can be
carried as flow files. A flow carries at most 8 files, 64 KiB each and 192 KiB in
all. A carried lean-toolchain must name leanprover/lean4:v4.36.0, and a
lakefile that requires a package is refused; Lake itself never runs.
Check a proof
Section titled “Check a proof”| Argument | Meaning |
|---|---|
theorems | Full names of the theorems the step proves, separated by spaces. |
statements | A json( block: theorem names and the types they must prove. Its names count as theorems. |
file | The .lean file to check, with what it imports. Default: every Lean file of the flow. |
memoryMb | Lean’s memory limit in MiB, 256 to 65536. Default 4096. |
Name at least one theorem: a check that names none would pass a file that only states axioms. The step passes when:
- no checked file has an error, and no declaration in them uses
sorry; - each named theorem is declared in the checked files and its proof uses only
Lean’s standard axioms,
propext,Classical.choiceandQuot.sound; - each type in
statementsis proved by its theorem.
| Outcome | Meaning |
|---|---|
| checked | All of the above holds. |
| errors | Lean reports an error. The message leads with the place, for example Discount.lean:7:2. |
| incomplete | A declaration uses sorry. |
| missing | A named theorem cannot be named from another module: it is private, or a plain theorem in a file that starts with module (write public theorem). |
| statement differs | A theorem does not prove the type statements gives it. |
| unexpected axioms | A named theorem uses another axiom: sorryAx, an axiom of the file, or native_decide, which Lean 4.36 records as an axiom of its own. |
| refused | Not run: a name that is not a Lean file of the flow, an import the plugin does not carry, or a command it refuses (below). |
| no verdict | Lean did not finish: it ran out of memory or was killed. The message says what to change. |
A plugin call gets 30 seconds unless the statement has timeout=, for example
timeout=5m. While Lean runs, the step shows which file it is checking.
State what is proved
Section titled “State what is proved”theorems keeps a proof honest, but not its statement: an edit that changes
total_le to prove something weaker still passes. statements fixes the
statement in the flow:
lean.check ( file="Discount.lean" statements=json( {"Discount.total_le": "∀ (price discount : Nat), price - min discount price ≤ price"} ))Each stated type is read in a module that imports only Init and Std, never the
flow’s files, so a file cannot redefine + or a notation to make it mean
something else. The kernel then checks that the named theorem proves it,
unfolding definitions where it needs to: above, total unfolds to the stated
price - min discount price. A stated type can therefore use only what Lean and
Std define.
Read a failure
Section titled “Read a failure”A step whose proof was left unfinished fails like this:
incomplete: Discount.lean:6:8 declaration uses 'sorry' (1 in all). Finish the proof.and one whose theorem was weakened like this:
statement differs: theorem Discount.total_le does not prove the stated type "∀ (price discount : Nat), price - min discount price ≤ price" (type mismatch …).The step’s tile lists each named theorem and its result. Its file
lean-output.txt holds every Lean message as File.lean:line:column: severity: text, and the axioms each named theorem uses.
Security
Section titled “Security”A flow, and so the Lean it carries, may come from a pull request, and Lean runs
code while it checks. Before Lean starts, the plugin refuses, also inside
comments: prelude (a file without Lean’s Init could declare its own standard
axioms), #eval and run_cmd (they run programs), initialize,
implemented_by, extern and unsafe (compiled code that could reach the
machine), include_str (reads a file), #guard_msgs and warn. options (could
hide a sorry), debug. options such as debug.skipKernelTC, the sat.solver
option, and syntax built by hand or macro attributes (they could spell a
refused command). Lean runs in a private directory holding
copies of the flow’s Lean files, with a fixed environment and a memory limit.
Lean still runs as you, with no operating-system sandbox: a file written to get round these rules could run code. The verdict does not rest on them: the kernel checks the compiled modules again, and the axioms of each named theorem are read from the compiled modules with Lean’s own exporter, never from Lean’s messages, which a file’s macros can change. Check Lean files from authors you would let run a LocalBash step. Lean’s messages are evidence your team can read.