Skip to the content.

← Command reference · CLI overview

lean-pkg-extract

Plan a standalone public Lean-verification repository from a mixed working repository, with exact provenance. Read-only; no registry, no network.

Usage

lean-pkg-extract COMMAND

Subcommands

More from –help

examples:
  lean-pkg-extract plan --repo . --commit HEAD --manifest extract.json
  lean-pkg-extract plan --repo ~/paper --commit 0123abc --manifest extract.json --json
  lean-pkg-extract plan --repo . --commit v1.0 --manifest extract.json --report ../extract-plan.json
  lean-pkg-extract ledger @ledger-args.txt
  lean-pkg-extract recheck --ledger ../newlib-ledger.json --repo . --target ../newlib
  lean-pkg-extract decls @decls-args.txt --output ../newlib --scaffold newlib --ledger ../newlib-ledger.json

Dry run only: `plan` reads git objects at COMMIT and writes nothing (--report PATH, outside SRC, is the
one exception). The file-level `write --output DIR` step comes next. `ledger` writes only its ledger,
outside SRC and the target; `recheck` writes nothing but its public summary on request (--public-summary);
`decls` writes the target modules into a new directory outside SRC (staged, scanned with public-safety,
moved into place) and its ledger.
exit codes: 0 plan clean, 1 refused (every reason listed), 2 usage.
docs: https://lean-pkg.github.io/lean-pkg/extract.html

Details

See also lean-pkg-extract plan --repo SRC --commit COMMIT --manifest PATH, a separate console script that plans a public Lean-verification repository from a mixed working repository, read-only and registry-free: Extracting a public Lean repository.

lean-pkg-extract ledger and lean-pkg-extract recheck record and re-verify a declaration-level extraction ledger (lean-pkg-extract-ledger/1) for a library ported by hand from private modules: Declaration-level extraction ledger. With --method types they compare the elaborated types too (types/1): --emit-script DIR writes two Lean programs to run in the source and target checkouts, and --from-output reads their outputs back (The comparison types/1). recheck --public-summary PATH also writes, when the recheck passes, a summary that may be published (lean-pkg-extract-ledger-summary/1: target names, verdicts, hashes and totals, no source path or name), scanned with public-safety first (A public summary of a ledger).

lean-pkg-extract decls writes the target modules from the same map into a new directory (with --scaffold NAME, a whole package: pins copied from the source commit, git init, nothing committed), staged beside it and scanned with public-safety before it is moved into place, and records the ledger of what it wrote: Writing the target modules.

lean-pkg-extract plan

dry run: classify, check and inventory what an extract at COMMIT would contain.

Usage

lean-pkg-extract plan --repo SRC --commit COMMIT --manifest PATH [--json]
                      [--report PATH]

Dry run: classify every file under the manifest’s roots at COMMIT (default deny), check paths, links, pins, dependencies, claims and imports, and print the inventory. Writes nothing.

Arguments and flags

Argument or flag Description
--repo SRC the source git repository (its top directory). Required.
--commit COMMIT the source commit; recorded as a full SHA. Required.
--manifest PATH the extract manifest, strict JSON, schema lean-pkg-extract/1. Required.
--json JSON on stdout (schema lean-pkg-extract-plan/1)
--report PATH also write the JSON plan (with the private excluded list) to PATH, outside SRC

Examples

Classify every file under the manifest’s roots at the commit (default deny), check pins, modules, claims and imports from git objects only, and print the inventory; writes nothing, exit 1 with every refusal listed.

lean-pkg-extract plan --repo . --commit HEAD --manifest extract.json

Sample output:

plan: REFUSED (1 refusal(s)): 16 file(s) included (25095 bytes), 0 excluded, 0 allowed private, 4 module(s), 0 claim(s), 0 weakening(s); source commit d3cb7c86cccc608017c2dc944db57931d6007409
refusals:
  - verify.sh: unclassified in a lean-package root (default deny); exclude it, move it, or put it in a root whose kind carries it
included (to <- from, size, sha256, blob, mode, class):
  ...
modules (module -> file, library):
  MyProof.Axioms -> MyProof/Axioms.lean  (MyProof)
  ...
plan: REFUSED (1 refusal(s)): 16 file(s) included (25095 bytes), 0 excluded, 0 allowed private, 4 module(s), 0 claim(s), 0 weakening(s); source commit d3cb7c86cccc608017c2dc944db57931d6007409

The same at a tag, also writing the JSON plan (with the private excluded list) to a path outside the source repository, its one write.

lean-pkg-extract plan --repo . --commit v1.0 --manifest extract.json --report ../extract-plan.json

lean-pkg-extract ledger

record an extraction ledger: a hand-ported target compared, declaration by declaration, with the source at COMMIT.

Usage

lean-pkg-extract ledger --repo SRC --commit COMMIT --target TDIR [--target-commit T]
                        --from-module SRC/Path.lean:New.Module
                        [--namespace OLD.Ns=NEW.Ns] [--rename OLD.qual=NEW.qual]
                        [--drop OLD.qual:REASON] [--new NEW.qual:REASON]
                        [--allow-differs OLD.qual:REASON] [--ledger PATH]
                        [--method {text,types}] [--emit-script DIR]
                        [--from-output OUT [OUT ...]] [--json]

Compare the target modules at TARGET_COMMIT with the source modules at COMMIT, declaration by declaration (method text/1: comments stripped, the namespace and rename maps applied, normalized text hashed), and, when nothing fails, write the ledger (lean-pkg-extract-ledger/1) to –ledger PATH, once. Reads git objects only; writes nothing else. –method types adds the elaborated types (types/1) in two steps, since lean-pkg runs no Lean: –emit-script writes two Lean programs, and –from-output reads what they printed.

Arguments and flags

Argument or flag Description
--repo SRC the source git repository (its top directory). Required.
--commit COMMIT the source commit; recorded as a full SHA. Required.
--target TDIR the target git repository (its top directory). Required.
--target-commit T the target commit (default: HEAD)
--from-module SRC/Path.lean:New.Module a source module and the target module it was ported to (repeatable, at least one). Required.
--namespace OLD.Ns=NEW.Ns a namespace prefix map (repeatable; the longest prefix wins)
--rename OLD.qual=NEW.qual a declaration renamed, fully qualified (repeatable; takes precedence over –namespace)
--drop OLD.qual:REASON a source declaration left out of the target on purpose, with a one-line reason
--new NEW.qual:REASON a target declaration with no source counterpart, declared, with a one-line reason
--allow-differs OLD.qual:REASON a disclosed difference, counted as weakened (context@<source module> for a module’s context rows)
--ledger PATH where to write the ledger: a new file outside SRC and outside the target (required, except with –emit-script)
--method {text,types} the comparison method: text (text/1, the default) or types (types/1: also the elaborated types, through –emit-script and –from-output). Choices: text, types.
--emit-script DIR method types/1, step 1: write the Lean programs DIR/source.lean and DIR/target.lean (DIR new, outside SRC and the target) and nothing else; run each in its checkout with lake env lean --run and keep its stdout (–ledger is not needed)
--from-output OUT [OUT ...] method types/1, step 2: the two programs’ outputs (source and target, any order), read strictly and bound to this ledger’s commits and programs
--json JSON on stdout: the ledger plus refusals, failures and written (and programs, with –emit-script)

More from –help

examples:
  lean-pkg-extract ledger --repo ~/paper --commit HEAD --target ~/newlib \
      --from-module Paper/Bounds.lean:NewLib.Bounds --namespace Paper.Bounds=NewLib.Bounds \
      --rename Paper.Bounds.main=NewLib.Bounds.main_bound --drop 'Paper.Bounds.scratch:exploration only' \
      --ledger ~/ledgers/newlib-1.json
  lean-pkg-extract ledger @ledger-args.txt --json
  lean-pkg-extract ledger @ledger-args.txt --method types --emit-script ~/ledgers/newlib-types
  lean-pkg-extract ledger @ledger-args.txt --method types --from-output source.out target.out

@ARGSFILE: one argument per line; a line `--flag value` is the flag and the rest of the line (so a reason
may hold spaces); blank lines and lines starting with # are skipped.
exit codes: 0 every declaration accounted for (ledger written; with --emit-script: the programs written),
1 refused or failing (nothing written), 2 usage.
docs: https://lean-pkg.github.io/lean-pkg/extract.html#declaration-level-extraction-ledger

Examples

Compare the hand-ported module New.A at the target’s HEAD with Src/A.lean at the source commit, declaration by declaration (method text/1), and write the private extraction ledger once, outside both repositories; exit 1 with nothing written when a declaration is MISSING, an undeclared NEW or a DIFFERS not allowed.

lean-pkg-extract ledger --repo ~/paper --commit HEAD --target ~/newlib --from-module Src/A.lean:New.A --namespace Old.A=New.A --rename Old.A.foo=New.A.bar --drop 'Old.A.aux:exploration only, never used' --ledger ~/ledgers/newlib-1.json

Sample output:

ledger: OK (text/1): 4 identical, 1 dropped, 0 differs, 0 new, 0 missing, 0 weakened; 1 context row(s) (0 differ); 0 warning(s); source 0034dfa7d81c09810ac5fce559088d62d0f84b3d, target 395069d8463ef9217daa068b9908d5972692afcc; written to ~/ledgers/newlib-1.json
entries (PRIVATE: source names and paths; keep this list out of anything published):
  IDENTICAL theorem   Old.A.foo -> New.A.bar
  DROPPED   lemma     Old.A.aux -> New.A.aux  (dropped: exploration only, never used)
  ...
ledger: OK (text/1): 4 identical, 1 dropped, 0 differs, 0 new, 0 missing, 0 weakened; 1 context row(s) (0 differ); 0 warning(s); source 0034dfa7d81c09810ac5fce559088d62d0f84b3d, target 395069d8463ef9217daa068b9908d5972692afcc; written to ~/ledgers/newlib-1.json

Method types/1, step 1 - write the two Lean programs (source.lean, target.lean) that print the elaborated types of the compared declarations; nothing else is written and lean-pkg runs no Lean. Run each in its checkout at the compared commit with lake env lean –run, after lake build.

lean-pkg-extract ledger --repo ~/paper --commit HEAD --target ~/newlib --from-module Src/A.lean:New.A --namespace Old.A=New.A --rename Old.A.foo=New.A.bar --drop 'Old.A.aux:exploration only, never used' --method types --emit-script ~/ledgers/newlib-types

Step 2 - read both outputs back (bound to the commits and the programs’ hashes) and write the ledger with method types/1; a text DIFFERS whose types are equal shows as DIFFERS (types equal) and no longer fails for a statement.

lean-pkg-extract ledger --repo ~/paper --commit HEAD --target ~/newlib --from-module Src/A.lean:New.A --namespace Old.A=New.A --rename Old.A.foo=New.A.bar --drop 'Old.A.aux:exploration only, never used' --method types --from-output source.out target.out --ledger ~/ledgers/newlib-2.json

lean-pkg-extract recheck

re-verify an extraction ledger against the source and the target.

Usage

lean-pkg-extract recheck --ledger PATH --repo SRC --target TDIR [--commit COMMIT]
                         [--target-commit T] [--emit-script DIR]
                         [--from-output OUT [OUT ...]] [--public-summary PATH]
                         [--include-source-commit] [--json]

Read a ledger strictly and recompute it from its own recorded map. At the recorded commits every field must match; at a newer –commit or –target-commit nothing may fail, and what changed is listed as drift. Writes nothing, except the public summary on request. A types/1 ledger needs –from-output (its programs’ outputs at the commits rechecked; –emit-script writes the programs).

Arguments and flags

Argument or flag Description
--ledger PATH the ledger (lean-pkg-extract-ledger/1). Required.
--repo SRC the source git repository (its top directory). Required.
--target TDIR the target git repository (its top directory). Required.
--commit COMMIT the source commit (default: the ledger’s source.commit)
--target-commit T the target commit (default: the ledger’s target.commit; required when it is null)
--emit-script DIR method types/1, step 1: write the Lean programs DIR/source.lean and DIR/target.lean (DIR new, outside SRC and the target) and nothing else; run each in its checkout with lake env lean --run and keep its stdout
--from-output OUT [OUT ...] method types/1, step 2: the two programs’ outputs (source and target, any order), read strictly and bound to this ledger’s commits and programs
--public-summary PATH when the recheck passes, also write its public summary (lean-pkg-extract-ledger-summary/1: target names, verdicts, hashes and totals, no source path or name) to PATH, a new file outside SRC (inside the target is allowed), after a public-safety scan
--include-source-commit with –public-summary: record the source commit in the summary (left out by default, since it may be private)
--json JSON on stdout: the recomputed ledger plus refusals, failures, drift and written (and public_summary, with –public-summary)

More from –help

examples:
  lean-pkg-extract recheck --ledger ~/ledgers/newlib-1.json --repo ~/paper --target ~/newlib
  lean-pkg-extract recheck --ledger ~/ledgers/newlib-1.json --repo ~/paper --target ~/newlib --commit main
  lean-pkg-extract recheck --ledger ~/ledgers/newlib-types.json --repo ~/paper --target ~/newlib \
      --from-output source.out target.out
  lean-pkg-extract recheck --ledger ~/ledgers/newlib-1.json --repo ~/paper --target ~/newlib \
      --public-summary ~/newlib/EXTRACTION.json

exit codes: 0 the ledger holds (at its commits: recomputed byte for byte; at other commits: nothing fails;
with --emit-script: the programs written; with --public-summary: the summary written), 1 refused or
failing (no summary written), 2 usage.
docs: https://lean-pkg.github.io/lean-pkg/extract.html#rechecking-a-ledger

Examples

Read the ledger strictly and recompute it from its own recorded map at its recorded commits; every field must match, so an edited hash or verdict is refused. Writes nothing.

lean-pkg-extract recheck --ledger ~/ledgers/newlib-1.json --repo ~/paper --target ~/newlib

Is the library still faithful to the source at the newer commits? Nothing may fail; what changed since the ledger is listed as drift.

lean-pkg-extract recheck --ledger ~/ledgers/newlib-1.json --repo ~/paper --target ~/newlib --commit main --target-commit main

Recheck a types/1 ledger with the outputs of its two programs, run again at the recorded commits; without –from-output a types/1 ledger is refused, since lean-pkg runs no Lean.

lean-pkg-extract recheck --ledger ~/ledgers/newlib-2.json --repo ~/paper --target ~/newlib --from-output source.out target.out

When the recheck passes, also write its public summary (lean-pkg-extract-ledger-summary/1) - target names, verdicts, hashes and totals, no source path, source name, reason or source commit - after a public-safety scan; inside the target is allowed, inside SRC and an existing file are refused.

lean-pkg-extract recheck --ledger ~/ledgers/newlib-1.json --repo ~/paper --target ~/newlib --public-summary ~/newlib/EXTRACTION.json

lean-pkg-extract decls

write the target modules of a declaration-level extraction (optionally a whole package) and record its extraction ledger.

Usage

lean-pkg-extract decls --repo SRC --commit COMMIT --output DIR
                       --from-module SRC/Path.lean:New.Module
                       [--namespace OLD.Ns=NEW.Ns] [--rename OLD.qual=NEW.qual]
                       [--drop OLD.qual:REASON] [--scaffold NAME] [--author TEXT]
                       [--license {Apache-2.0,MIT}] --ledger PATH [--dry-run] [--json]

Read the mapped source modules at COMMIT, write each as its target module (the namespace and rename maps applied, –drop declarations left out, imports of mapped modules rewritten, comments other than docstrings removed) into –output DIR, which must be absent or empty and outside SRC, and record the ledger (lean-pkg-extract-ledger/1, target.commit null) to –ledger PATH. The tree is compared with the source (text/1) before anything is written, staged beside DIR, scanned with public-safety and moved into place in one step. –scaffold NAME adds the package files and runs git init; nothing is committed.

Arguments and flags

Argument or flag Description
--repo SRC the source git repository (its top directory). Required.
--commit COMMIT the source commit; recorded as a full SHA. Required.
--output DIR where to write: a new or empty directory, outside SRC, not a symbolic link. Required.
--from-module SRC/Path.lean:New.Module a source module and the target module to write it as (repeatable, at least one). Required.
--namespace OLD.Ns=NEW.Ns a namespace prefix map (repeatable; the longest prefix wins)
--rename OLD.qual=NEW.qual a declaration renamed, fully qualified (repeatable; takes precedence over –namespace)
--drop OLD.qual:REASON a source declaration left out of the target, with a one-line reason
--scaffold NAME also write the package: lean-toolchain and lake-manifest.json copied from the source commit, lakefile.toml, README.md, CITATION.cff, LICENSE, REUSE.toml; then git init (nothing committed)
--author TEXT with –scaffold: the CITATION.cff author (default: git config user.name)
--license {Apache-2.0,MIT} with –scaffold: the LICENSE written (default Apache-2.0). Choices: Apache-2.0, MIT.
--ledger PATH where to write the ledger: a new file outside SRC and outside DIR. Required.
--dry-run read and compare, report what would be written, and write nothing (the public-safety scan of the staged tree runs only when writing)
--json JSON on stdout: the ledger plus refusals, failures, written, output and public_safety

More from –help

examples:
  lean-pkg-extract decls --repo ~/paper --commit HEAD --output ~/newlib \
      --from-module Paper/Bounds.lean:NewLib.Bounds --namespace Paper.Bounds=NewLib.Bounds \
      --rename Paper.Bounds.main=NewLib.Bounds.main_bound --drop 'Paper.Bounds.scratch:exploration only' \
      --scaffold newlib --author 'Ada Lovelace' --ledger ~/ledgers/newlib-1.json
  lean-pkg-extract decls @decls-args.txt --dry-run

@ARGSFILE: as for `ledger` (one argument per line; `--flag value` lines keep the rest of the line).
exit codes: 0 written (or, with --dry-run, writable) and every declaration IDENTICAL or dropped, 1 refused
(nothing written), 2 usage.
docs: https://lean-pkg.github.io/lean-pkg/extract.html#writing-the-target-modules-decls

Examples

Write New.A from Src/A.lean at the source commit with the maps applied and the dropped declaration left out, as a new package (pins copied from the source commit, git init, nothing committed), staged beside ~/newlib and scanned with public-safety before it is moved into place; the ledger of what was written goes outside both trees. Exit 1 with nothing written on any refusal.

lean-pkg-extract decls --repo ~/paper --commit HEAD --output ~/newlib --from-module Src/A.lean:New.A --namespace Old.A=New.A --rename Old.A.foo=New.A.bar --drop 'Old.A.aux:exploration only, never used' --scaffold newlib --author 'Ada Lovelace' --ledger ~/ledgers/newlib-1.json

The plainest map, reading and comparing only; nothing is written (the public-safety scan runs only when writing).

lean-pkg-extract decls --repo ~/paper --commit HEAD --output ~/newlib --from-module Src/A.lean:New.A --ledger ~/ledgers/newlib-1.json --dry-run