ProofStruct extracts structured proof blueprints from Lean 4 files and displays them in the Lean Infoview. It is designed for users who want to inspect both the high-level proof plan and the fine-grained proof evidence of Lean proofs.
Chinese documentation is available in README.zh.md.
ProofStruct is developed as a subproject of ProofAtlas. This standalone repository packages the usable ProofStruct components as a local Lake dependency so that Lean users can test the tool in their own projects.
- Linux environment.
- Lean via
elan. - Lean toolchain:
leanprover/lean4:v4.30.0-rc2. - Python
>=3.12,<3.13.
The Lean configuration is pinned in lean-toolchain and lakefile.toml. If you use ProofStruct inside another Lean project, first make sure the target project can build with a compatible Lean setup.
Clone the repository:
git clone https://github.com/longdie/ProofStruct.git
cd ProofStructCreate the Python environment:
conda env create -f environment.yml
conda activate proofstructAlternatively:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtBuild the Lean package:
lake update
lake build ProofStructGenerate formal blueprint JSON files for the example file:
conda run --no-capture-output -n proofstruct python scripts/ProofStruct/batch_extract.py \
--project-root . \
--file examples/example.leanThen open examples/example.lean in VS Code with the Lean extension. The example contains a lemma, two theorems, and the Infoview command:
#proof_blueprint demo_fermatPut the cursor on the command to view the proof blueprint in the Infoview.
The default workflow is to generate JSON from the terminal, then let Infoview read the generated files:
conda run --no-capture-output -n proofstruct python scripts/ProofStruct/batch_extract.py \
--project-root . \
--file examples/example.leanThis is the recommended mode for normal use because it does not run extraction inside the VS Code Lean server.
To process a single declaration:
conda run --no-capture-output -n proofstruct python scripts/ProofStruct/batch_extract.py \
--project-root . \
--file examples/example.lean \
--theorem demo_fermatProofStruct also provides explicit bang commands:
#proof_blueprint! demo_fermat
#proof_blueprint_english! demo_fermatThese commands call the Python batch script from Lean with safety checks enabled. They are useful when you want to generate a small missing blueprint without leaving the editor.
Instant generation blocks the Lean command elaboration while it runs. For Mathlib projects, a machine with more than 24GB of memory is recommended. Avoid running multiple blueprint extraction jobs in parallel.
For instant commands, configure the Python executable either through PROOFSTRUCT_PYTHON or through
a local proofstruct_config.toml:
[python]
executable = "/absolute/path/to/python"proofstruct_config.toml is local configuration and should not be committed.
#proof_blueprint theorem_nameReads existing JSON and displays the blueprint. It never generates missing JSON.
#proof_blueprint! theorem_nameGenerates the formal blueprint if the current source hash is missing, then displays it.
#proof_blueprint_english! theorem_nameEnsures the formal blueprint exists, generates the English blueprint if needed, then displays Formal/English views.
English blueprints require an OpenAI-compatible LLM endpoint.
Create a local configuration file:
cp proofstruct_config.example.toml proofstruct_config.tomlSet your API key through the environment variable configured in proofstruct_config.toml, for
example:
export PROOFSTRUCT_LLM_API_KEY=<your-api-key>Generate formal and English blueprints from the terminal:
conda run --no-capture-output -n proofstruct python scripts/ProofStruct/batch_extract.py \
--project-root . \
--file examples/example.lean \
--englishCommon options:
--file <path>: Lean file to process.--project-root <path>: Lake project root.--theorem <name>: process one declaration; can be repeated.--output-root <path>: output root, defaulting to<project-root>/output.--dataset <name>: output dataset name, defaulting to the Lean file stem.--english: generateenglish.layered.json.--english-only: generate English from existing formal JSON.--safe: enable lock, memory/process checks, timeout, and logs.
Safety overrides:
--safe-max-lean-processes <n>--safe-min-available-memory-gb <gb>--safe-timeout-seconds <seconds>--safe-lock-wait-seconds <seconds>
English options:
--english-config <path>--english-evidence-mode none|objects|all--english-plan-batch-size <n>--english-evidence-batch-size <n>--english-require-llm
Generated files are written under the target project:
output/<file-stem>/<declaration-name>/manifest.json
output/<file-stem>/<declaration-name>/<source-hash>/formal.evidence.json
output/<file-stem>/<declaration-name>/<source-hash>/formal.layered.json
output/<file-stem>/<declaration-name>/<source-hash>/english.layered.json
<source-hash> is the first 16 hex characters of the SHA-256 hash of the normalized declaration
source block. If the declaration statement or proof changes, the hash changes as well. This
prevents #proof_blueprint from showing stale data for a theorem whose name stayed the same.
To use ProofStruct in an existing Lean project, add it as a local dependency in the target
project's lakefile.toml:
[[require]]
name = "ProofStruct"
path = "../ProofStruct"Then run:
lake update
lake build ProofStructIn your Lean file:
import ProofStruct
theorem example_theorem : True := by
trivial
#proof_blueprint example_theoremGenerate JSON from the target project root:
conda run --no-capture-output -n proofstruct python /absolute/path/to/ProofStruct/scripts/ProofStruct/batch_extract.py \
--project-root . \
--file MyProject/MyFile.lean- If
#proof_blueprintreports that JSON is missing, runbatch_extract.pyfirst or use#proof_blueprint!. - If the current source does not match the manifest, rerun extraction after editing the theorem.
- If instant generation cannot find Python, set
PROOFSTRUCT_PYTHONor configure[python].executableinproofstruct_config.toml. - If the Infoview still shows an old widget, restart the Lean server or reload VS Code.
- Blueprint extraction can use substantial memory. Do not run multiple extraction jobs in parallel.
For questions, feedback, or collaboration, please contact:
stju_dzn@sjtu.edu.cn
This project is released under the terms of the LICENSE file.