[{"data":1,"prerenderedAt":4},["ShallowReactive",2],{"hhK31AR0Yv":3},"# blueprint\n\nA blueprint records the informal mathematics of a formalisation project, the\nLean declarations that realise it, and the relations between the pieces, at\nwhatever levels of detail the project needs.  There is one sort of thing, the\n*object*: nodes, edges, hyperedges and edges between edges are all objects,\ntold apart only by their boundary.  Kinds are declared per project, so a\n`uses` edge can itself carry prose, be refined by lemmas, or sit inside a\n`commutes` hyperedge.  Any kind that is acyclic and collapsible can drive\nviews, which is how one blueprint reads at several levels of detail at once.\n`DESIGN.md` is the design; `docs/snapshot-format.md` is the contract between\nthe Lean core, the Lean extractor and the website under `web/`.\n\nThis repository is at phase 4: the model, the schema, the parser, `check`,\n`build`, the Lean extractor behind `extract` and `check --lean`, and the\nsemantic diff behind `diff`, `log`, `progress`, `history add`, `site` and\n`serve`, written in Lean 4 (toolchain `v4.33.1`, no dependencies beyond the\ntoolchain — TOML comes from `Lake.Toml` and JSON from `Lean.Data.Json`).\nAuthors write Markdown files with TOML front matter under `blueprint/`; the\ntool derives the edges the front matter implies, validates the whole thing,\nreads the Lean environment for proof status and actual dependencies, and\ncompiles `blueprint.json`.  The website under `web/` renders that snapshot;\nin-browser editing is the one phase still to come.\n\n## Running it\n\n```bash\nlake build                                  # builds .lake/build/bin/blueprint\nlake exe blueprint --help\n./test.sh                                   # acceptance tests over examples/\n```\n\nThree example blueprints ship with the tool:\n\n```bash\n# a small, correct blueprint: one section, four nodes, uses/refines sugar\nlake exe blueprint check --root examples/minimal\nlake exe blueprint view  --root examples/minimal --expand basics\n\n# DESIGN.md §3: an edge with its own prose that lemmas refine, an edge\n# between edges, a commutes hyperedge, an object with two parents\nlake exe blueprint check --root examples/induction --lean\nlake exe blueprint build --root examples/induction -o /tmp/induction.json\nlake exe blueprint view  --root examples/induction --expand induction\n\n# every error level check at once; exits 1\nlake exe blueprint check --root examples/broken --lean\n\n# the website, assembled into examples/induction/_site and served\nlake exe blueprint site  --root examples/induction\nlake exe blueprint serve --root examples/induction\n```\n\n`docs/cli.md` documents the commands, `blueprint.toml`, the authoring format\nand the default schema; `examples/broken/README.md` says which line of that\nexample triggers which check.\n\n## Lean integration\n\nNothing about the proof status of a declaration, and nothing about what it\nactually depends on, is written by hand: both are read out of the Lean\nenvironment.  A formalisation project wires itself up in four steps.\n\n**1. Require the package.**  In the project's `lakefile.toml`:\n\n```toml\n[[require]]\nname = \"blueprint\"\ngit  = \"https://github.com/…/blueprint\"\nrev  = \"main\"\n```\n\n**2. Tag declarations.**  `Blueprint.Attr` is the only module a project\nimports; it depends on nothing but Lean core.\n\n```lean\nimport Blueprint.Attr\n\n@[blueprint \"main-theorem\"]\ntheorem MyProject.mainTheorem (X : Space) : Decomposable X := …\n\n@[blueprint key-prop]              -- the bare form, same thing\ntheorem MyProject.keyProp : … := …\n```\n\nThe mapping may equally be stated from the text side, and the two merge:\n\n```markdown\n+++\nid   = \"main-theorem\"\nkind = \"theorem\"\nlean = [\"MyProject.mainTheorem\"]\n+++\n```\n\n**3. Extract.**  Name the modules to import, or put them in\n`blueprint.toml`:\n\n```toml\n[lean]\nmodules = [\"MyProject\"]\n```\n\n```bash\nlake exe blueprint extract                  # writes lean-facts.json\nlake exe blueprint extract MyProject.Basic MyProject.Main\n```\n\nThe tags survive `import`, so importing the project's root module finds\nevery tagged declaration below it.\n\n**4. Check and build.**\n\n```bash\nlake exe blueprint check --lean             # exits 1 on any error\nlake exe blueprint build                    # blueprint.json, facts merged in\n```\n\n`check --lean` reports a named constant that does not exist\n(`missing-lean`), a `uses` edge the Lean dependency graph does not show\n(`declared-not-actual`), and a Lean dependency no `uses` edge declares\n(`actual-not-declared`).  The derived status of an object is `proved`,\n`proved_with_axioms` when its proof rests on an axiom outside `propext`,\n`Classical.choice` and `Quot.sound`, `stated` when it rests on `sorry`, and\n`missing` when the constant is not there.\n\n`BlueprintExamples/` in this repository is a small worked example of all of\nthis: it is the Lean development that `examples/induction` and\n`examples/broken` describe.  Their `lean-facts.json` is generated from it —\n\n```bash\nlake exe blueprint extract --root examples/induction\nlake exe blueprint extract --root examples/broken\n```\n\n— and `./test.sh` fails if the committed files are not what those commands\nproduce.\n\n## Coming from a LaTeX blueprint\n\nA project that already has a `leanblueprint` LaTeX blueprint converts in one\ncommand:\n\n```bash\nlake exe blueprint import-latex blueprint/src/content.tex \\\n  --out blueprint --toml blueprint.toml --report import-report.txt\nlake exe blueprint check\n```\n\n`\\input` is followed, `\\chapter`/`\\section`/… become nested sections, the\ntheorem-like environments become objects with their `\\label` as id, `\\lean`\nand `\\uses` become the `lean` attribute and `uses` edges, a following\n`proof` becomes a `## Proof` in the same object, and every `\\newcommand` and\n`\\DeclareMathOperator` lands in `[katex.macros]` for the website to give to\nKaTeX.  Maths is copied out untouched; every command and environment the\nconverter did not understand is counted in the report, so the loss is\nvisible.  `examples/latex-import` is a worked example with its expected\noutput committed next to it, and `docs/cli.md` is the reference.\n\n## Editing the graph\n\nThe website has an opt-in *edit mode* for reorganising a blueprint's dependency\ngraph — typically one imported as it stands from a paper's LaTeX — and writing\nthe reorganised argument out as LaTeX again.  Open it with *Edit graph*\nbehind the graph's Filters on the site (or with `?edit=1`): delete a\nnode (reconnecting what used it to what it used), replace or edit it inline,\nadd nodes and dependencies (Shift+drag from one node to another), split a node\ninto smaller lemmas that other nodes can reuse, merge nodes — each step\nundoable.  The edits are a log kept in the browser and exported or imported as\nan edit file; the snapshot is never changed, and with edit mode off the site\nis exactly the reading site.  *Export TeX* writes the edited blueprint as a\n`leanblueprint` LaTeX document that `blueprint import-latex` reads back into\nthe edited graph.  `docs/graph-edit.md` is the reference.\n\n## History and the website\n\nThe compiled snapshot is the whole interchange format, so everything about\nchange is a comparison of two snapshots (`DESIGN.md` §7).\n\n```bash\n# what changed between two revisions, or between a revision and a file\nlake exe blueprint diff HEAD~10 HEAD --root examples/induction\nlake exe blueprint diff old.json blueprint.json --json\n\n# what every commit did to one object, across renames\nlake exe blueprint log main-theorem --root examples/induction\n\n# status counts by kind now, and the delta since a revision\nlake exe blueprint progress --root examples/induction --since HEAD~10\n```\n\n`diff` matches objects by id and then by the `aliases` a `blueprint rename`\nrecords, so a rename is a rename and not an addition plus a removal.  A\nderived status that falls from `proved` back to `stated`, `missing` or\n`absent` is the `status-regression` error of `docs/snapshot-format.md`:\n`diff` exits 1 on it unless `--no-fail` is given, which is what makes it\nuseful in CI.\n\nThe website is plain files under `web/` — no build step — and\n`blueprint site` puts them together with a freshly built snapshot:\n\n```bash\nlake exe blueprint site  --root examples/induction -o _site\nlake exe blueprint serve --root examples/induction            # site, then serve\n```\n\n`site` finds its copy of `web/` through `$BLUEPRINT_WEB_DIR`, then\n`\u003Croot>/web`, then the package the running executable belongs to — so a\nproject that consumes this tool through Lake gets the website out of\n`.lake/packages/blueprint/web` without copying anything.  `serve` runs\n`site` first and then hands the directory to `python3 -m http.server`, `npx\nserve`, `busybox httpd` or `nix-shell -p python3`, whichever is installed,\nand tells you what to run if none of them is.\n\nThe time slider on the progress page replays past snapshots out of\n`data/index.json`, which `blueprint history add` maintains:\n\n```bash\nlake exe blueprint build --root examples/induction -o snapshot.json\nlake exe blueprint history add snapshot.json --dir history   # sha, date from HEAD\nlake exe blueprint site --root examples/induction --history history -o _site\n```\n\n`.github/workflows/lean_action_ci.yml` does exactly that on every push to\nthe default branch: it extracts the Lean facts, builds the snapshot, files\nit in a `history/` directory restored from the `gh-pages` branch, assembles\n`_site`, deploys it to GitHub Pages, and pushes the grown history back to\n`gh-pages` under `data/` so that the next run finds it.\n\n## PDF export\n\nThe website's **Export PDF** button, and `blueprint export` on the command\nline, write the document — the whole blueprint, a chapter, a section, or a\nrefined statement with what is below it — as LaTeX and as a PDF, in the\nwebsite's reading order and with its numbers, proofs with their statements\nand a lemma shared with another section written out in full.  A static site\ncannot run TeX, so `blueprint site --pdf` (which CI runs) compiles every\nchoice the dialog offers in advance and files it under the snapshot it was\nmade from; `blueprint serve` also makes any other on demand.\n\n```bash\nlake exe blueprint export --root examples/paper                    # paper-whole.pdf\nlake exe blueprint export --root examples/paper --scope products   # one section\nlake exe blueprint site   --root examples/paper --pdf              # the site, PDFs included\n```\n\nIt needs node and TeX Live (pdfLaTeX); `docs/pdf-export.md` is the reference,\nand `examples/paper/export/` holds sample exports.\n\n## Layout\n\n```\nBlueprint/Model.lean     objects, boundaries, schema types\nBlueprint/Toml.lean      a thin wrapper around Lake.Toml\nBlueprint/Schema.lean    the default schema, blueprint.toml\nBlueprint/Parse.lean     front matter, sugar expansion, id derivation\nBlueprint/Check.lean     well-foundedness, constraints, references, lints\nBlueprint/View.lean      collapse orders, views, the display rule\nBlueprint/Status.lean    derived status, progress\nBlueprint/Json.lean      the snapshot, in and out\nBlueprint/Git.lean       running git: revisions, trees, commits\nBlueprint/Diff.lean      the semantic diff, and one file at a time for `log`\nBlueprint/Site.lean      site assembly, the snapshot history index\nBlueprint/Attr.lean      the @[blueprint] attribute (Lean core only)\nBlueprint/Extract.lean   environment walk, lean-facts.json\nBlueprint/Cli.lean       the commands\nMain.lean                the executable\nBlueprintExamples/       the Lean development examples/ talks about\nexamples/                the example blueprints\nweb/                     frontend (separate package)\n```\n",1795981085776]