Maintained procedure · manual/workflows/getting-started.mdMarkdown source at d23f2aea9f24
On this page

Get oriented and build

Start with the kind of claim you want Lean to check. A running Lean function, an equality of probability distributions, and a polynomial-time certificate answer different questions. cslib-frontier connects these layers through explicit theorems. Open a client that proves the kind of statement you need, then follow its imports and encodings.

Prerequisites and the checkout's version#

Use Git, Bash, Python 3.11+, Lean's elan/lake tools and a Lean-capable editor, or a text editor with command-line checks. An agent, MCP server or account with an AI provider is not required. Install Lean using its official setup instructions. The checked-out lean-toolchain selects the Lean release. The lakefile.toml declares the dependencies and lake-manifest.json records their exact revisions.

Start: a shell with Git and elan available, outside an existing checkout. Run:

git clone https://github.com/cslib-community/cslib-frontier.git
cd cslib-frontier
scripts/build.sh --wfail --iofail

Expected result: the requested library build exits zero under strict warning and I/O-error settings. It is one build, not the full integration gate. The wrapper tries cache restoration before Lake; a cache miss may cause compilation. If it fails, keep the first error and use build troubleshooting. The cache guide explains missing artifacts and retries.

Before opening a cold checkout in a Lean editor, run:

scripts/cache/ensure.sh

Bare lake does not run this helper. A recent stamp records an attempted restore, not proof that every artifact was found. MCP is an optional editor-assistance interface. Its commands do not invoke the bootstrap; run the helper before using MCP in a cold checkout.

For ordinary edits, use editor/MCP diagnostics or build the affected modules and a representative client with scripts/build.sh <targets> --wfail --iofail. At a local checkpoint, use scripts/check.sh --quick --no-full-fallback. If it exits with status 3, quick mode cannot plan the change; run focused checks for the changed files and let hosted CI supply full validation. This avoids an automatic full local check. The default scripts/check.sh still runs the full suite: use it only when explicitly requested or hosted coverage is unavailable. Successful CI covering the final revision supplies full validation without repeating it locally.

The check helpers also recover diagnostics lost by local artifact reuse. That audit may re-elaborate restored sources; it is not part of an ordinary targeted build.

Read the directory names correctly#

The package is cslib-frontier; imports start with CslibFrontier.. Most declarations live in Cslib namespaces; the Turing-machine API uses Turing. A module path and its declarations' namespace therefore need not have the same first component.

PlaceUse it for
CslibFrontier/Definitions, semantics, resource predicates and theorems
CslibFrontierTests/Small clients, edge cases, failure guards and regressions
guide/Explanatory chapters with Lean examples
results/ and CslibFrontierResults/Checked inventory of named results and their sources, linked to the API documentation
ROADMAP.mdOutstanding directions and incomplete endpoints
-- upstream: markers and CONTRIBUTING.md (Upstreaming)Local-copy status and live CSLib/Mathlib coordination

Import a topic module or tactic module first. import CslibFrontier imports the entire library and is usually unnecessary for a small client. The architecture reference explains the layers.

A first worked example#

Start: the repository is available, you have read the current contribution policy, and no other task owns the fresh branch and directory names below. From the primary checkout:

scripts/worktree.sh create docs/manual-first-client manual-first-client HEAD
cd .worktrees/manual-first-client
scripts/build.sh CslibFrontierTests.NPCompleteness CslibFrontierTests.PolyTimePlainDriver --wfail --iofail

The helper prepares an isolated working directory and mutable build outputs. HEAD is interpreted relative to the primary checkout; use an explicit revision if you need a different base. Pick different branch and directory names if these are already in use. For a source-only checkout or dependency changes, read the helper's isolation modes.

Read the complete client: open CslibFrontierTests/NPCompleteness.lean. It imports CslibFrontier.Computability.Complexity.Problems.Clique and CslibFrontier.Tactic.PolyTime, enters CslibFrontierTests.NPCompleteness, and opens Cslib.Complexity Turing.MultiTapeTM. Keep that context. Follow startsTrue_mem_P: its three fields give a Boolean decider, its polynomial-time certificate and its membership equivalence. Then follow complementInstance_polyTime, independentSet_to_clique and clique_npComplete. The reduction's direction, encoded inputs and correctness equivalence are explained in the deterministic workflow.

Expected result: both complete test modules elaborate. The first reuses existing membership, reduction and hardness theorems and checks boundary graphs; the second tests plain certificate automation. This does not establish a new completeness result or run all integration gates. The client bodies are canonical source, not copied tutorial files. The editorial check described here does not itself claim a fresh Lean build.

Finish: from that worktree run git diff --check and git status --short. After restoring the experiment, the test file should have no diff. For a real change, include its complete client and the actual validation result in the review handoff. Never report the intentional failing build as a successful check.

To remove only this disposable exercise worktree after it is clean and no work needs preserving, return to the primary checkout and use Git's guarded removal:

cd ../..
git worktree remove .worktrees/manual-first-client

The branch is retained. If Git refuses because files are modified, inspect and preserve them before retrying; do not force removal. This command is not a cleanup procedure for another contributor's worktree.

The Verso guide provides further checked tutorials: first steps, NP-completeness, streaming, and first-order operators. Use those source files for their example bodies. The workflow chapters' quoted Lean blocks remain contextual excerpts: open each linked full client for its complete imports and assumptions. Their identity is checked against current source by the manual checker; that check is not standalone elaboration. Historical hosted validation has its own dated scope and cannot validate later changes.

Use cslib-frontier from your own project#

Choose a full commit SHA from the commit history. Copy that revision's lean-toolchain into your project. In your lakefile.toml, add the following entry with the SHA you chose.

[[require]]
name = "cslib-frontier"
git = "https://github.com/cslib-community/cslib-frontier"
rev = "<the-full-commit-SHA-you-selected>"

CSLib and Mathlib are transitive dependencies. If your project also requires either directly, align its revision with cslib-frontier's lake-manifest.json at the commit you chose. From your project directory, run lake update cslib-frontier, then lake build. Include any direct dependencies whose pins you changed in the update command. For example, use lake update cslib-frontier cslib mathlib when changing both.

Commit the resulting lake-manifest.json, Lake configuration and lean-toolchain together. The library map links to complete Lean examples whose imports you can reuse.