CLI
Reference for the lema command-line interface, project workflow commands, semantic version control, and operator subcommands.
The lema binary (crates/lema-cli) is the unified command-line tool for creating projects, authoring .lema and .lean files, running tests and applications in the register VM, managing semantic revisions and merges, and administering Lema stores and releases.
Path resolution and environment variables
Every lema command resolves its project root, store directory, daemon socket, and runtime configuration in a fixed priority order:
| Resource | Resolution order (first match wins) |
|---|---|
| Project root | Nearest ancestor directory containing lema.json, else current working directory. |
| Store directory | 1. --store <DIR> flag -> 2. LEMA_STORE env var -> 3. <project_root>/.lema/store -> 4. ./.lema/store. |
| Daemon socket | 1. --socket <PATH> flag -> 2. LEMA_SOCKET env var -> 3. <project_root>/.lema/lema.sock -> 4. ./.lema/lema.sock. |
| Runtime config | 1. --runtime <FILE> flag -> 2. LEMA_RUNTIME env var -> 3. ~/.lema/runtime.json. |
| Actor bearer token | 1. --token <TOKEN> flag -> 2. LEMA_ACTOR_TOKEN env var -> 3. ~/.lema/credentials.json (0600). |
Unix domain socket path-length fallback
Operating systems cap sockaddr_un.sun_path at 103 usable bytes on macOS (104 including NUL) and 107 usable bytes on Linux (108 including NUL). When <project_root>/.lema/lema.sock exceeds the platform’s sun_path limit, lema deterministically places the socket at:
$XDG_RUNTIME_DIR/lema/<sha256(canonical_project_root)[:16]>.sockwhenXDG_RUNTIME_DIRis set and mode0700.~/.lema/run/<sha256(canonical_project_root)[:16]>.sock(directory created with mode0700) otherwise.
Output modes and exit codes
Every subcommand supports human-readable terminal output by default and canonical JSON output when passed --json.
When --json is passed on an elaboration or contract error, lema emits structured source diagnostics so editors and CI scripts can jump straight to the failing location:
{
"errors": [
{
"column": 5,
"file": "src/Counter.lema",
"line": 14,
"message": "unknown identifier 'advance_typo'"
}
],
"ok": false
}| Exit code | Meaning |
|---|---|
0 | Command succeeded ("ok": true). |
1 | Verification failure, contract obligation error, policy rejection, or invalid arguments. |
75 | (EX_TEMPFAIL) Transient runtime exhaustion or sandbox pre-call refusal (for example insufficient MemAvailable or active HALTED latch). |
Project configuration (lema.json)
Running lema new <name> creates a project directory with a lema.json manifest ("schema": "lema.project/v1"):
{
"axioms": [
"propext",
"Quot.sound",
"Classical.choice"
],
"capabilities": "lema-cap.json",
"entries": {
"default": {
"families": [
"block",
"serve"
],
"guarantees": [
"NoCopySliceCall",
"ConstantTime",
"SecretFlow.SigV4VerifyServer"
],
"limits": {
"allocation_bytes": 67108864,
"bigint_bits": 4096,
"call_depth": 1024,
"steps": 100000000
},
"root": "App.main",
"seconds": 60
}
},
"name": "my-service",
"prefix": "App",
"schema": "lema.project/v1",
"sources": [
"src/Spec.lema",
"src/Main.lean"
],
"tests": [
"App.test_roundtrip"
]
}Project lifecycle and authoring commands
lema new <NAME>
Creates a new Lema project directory <NAME>/ containing lema.json, src/, .gitignore (ignoring .lema/), and initializes the local store at <NAME>/.lema/store.
lema start, lema stop, lema status
Manages the background lema serve daemon for the current project:
lema start: Starts the project store server in the background if not already running and writes.lema/server.pid.lema stop: Gracefully stops the background server and removes the socket.lema status: Reports store health, daemon PID, active reference (main), open vs checkedlema.contract/v1counts, and runtime latch status. Note thatlema add,lema test,lema run,lema commit, andlema releaseauto-start the project daemon on demand if it is not yet running.
lema add <FILE>...
Elaborates and publishes one or more .lema or .lean files into the project store in topological dependency order.
- Automatically infers
syntax: "lema"for.lemafiles andsyntax: "lean"for.leanfiles. - Registers any
selectdeclarations in.lemafiles aslema.contract/v1records and attempts to discharge open selections against newly published theorems. - Updates the project’s working snapshot.
lema dev
Watches all files listed in lema.json sources (plus lema.json itself) and automatically re-runs lema add and lema test whenever a file is saved.
Testing, running, and releasing
lema test [FILTER]
Compiles and executes all test roots listed in lema.json tests (or matching FILTER) inside crates/lema-vm via vm.test, reporting pass/fail status, instruction step counts, and heap allocation totals.
lema run [ENTRY] [-- <ARGS>...]
Resolves ENTRY (defaulting to entries.default in lema.json), imports its lema.exec/v2 manifest, checks its static VM guarantees, compiles the LemaIR closure, and executes the application in lema-vm-runner using the project’s capabilities configuration (lema-cap.json).
- Passing
lema run --releaseexecutes the most recently sealed release artifact recorded in.lema/last-releasewithout recompiling.
lema release [ENTRY] [--target vm]
Builds, verifies, and seals an immutable lema.release/v1 record and lema.vm-app/v1 artifact for ENTRY (Target::Vm "vm"):
- Checks that the active project reference (
main) satisfies itslema.policy/v1(includingno_obligationsand any requiredreviewthreshold). - Verifies all static VM
guarantees(ConstantTime,SecretFlow.*,NoBigIntPrimitives, and others). - Emits the compiled
lema.vm-app/v1bundle and writes its release ID to.lema/last-release.
Semantic version control commands
lema commit -m <INTENT> [--ref <NAME>] [--waive <KEY>=<REASON>...] [--evidence-file <FILE>] [--plan] [--no-publish]
In a project, commits the active store workspace’s snapshot: plans the revision (commit.plan: the change report, the obligations it discharges or carries, and the current guarantee records rooted at the snapshot’s members as evidence), stores it and advances the workspace (workspace.commit), then lands it on --ref (default the workspace’s reference, main) if the reference’s lema.policy/v1 permits.
--waive KEY=REASONrecords{obligation, waiver}in the revision’sdischargedarray; publishing it needs an actor listed under the policy’swaive.--evidence-file FILEadds evidence to cite: a JSON list of{kind, id}.--planprints the plan and changes nothing.--no-publishstops after the local commit; land it later withlema workspace land.--actor IDand--token-file FILE(orLEMA_ACTOR_TOKEN) name the publishing actor; in a project they default todevand.lema/token.--assetsand--asset-idsare refused in a project, which always commits its workspace’s snapshot; uselema snapshotandlema revision createfor an explicit selection.
lema diff [REV_A [REV_B]] [--ref <NAME>] [--json]
Computes a semantic lema.change-report/v1 between two revisions or snapshots (REV_A and REV_B, each a reference name, a revision ID, a snapshot ID or workspace:NAME; by default the head of main vs the active workspace’s snapshot). Prints changes grouped by semantic category (rename, exports, rebind, substitute, evolve, policy, material) alongside contract selection status transitions (open -> checked, open -> waived).
lema merge <PARENT_REV> [--into <REF>] [--resolve <FILE>] [-m <INTENT>]
Performs a three-way semantic merge (lema.merge/v1) between the head of --into (default "main") and <PARENT_REV> using their nearest common ancestor:
- Automatically reuses valid proofs (
reuse) when statements are unchanged. - If structural conflicts (
collision,delete-update,update-update,rename-rename,bundle) exist and--resolveis omitted, exits with code1and prints the structured conflict list.
lema export <FILE> [--ref <NAME>...] and lema import <FILE> [DIR]
lema export app.lemabundle: Exports a self-containedlema.checkpoint/v1archive containing all objects, aliases, bundles, snapshots, revisions, policies, contracts, guarantees, and execution entries reachable from the selected references.lema import app.lemabundle [DIR]: Imports a.lemabundlearchive into a store, replaying everylema.core/v4object through the Lean4.34.1kernel before admitting the records.
lema checkout <REV> [--force] [--workspace <NAME>] [--json]
Makes the active workspace and its directory REV’s state (a reference name, a revision ID, a snapshot ID or workspace:NAME): the project, modules and lock come from REV’s .lema/manifest.json, the workspace is set to it, and the files follow. A file you edited that REV changes refuses the checkout unless --force.
Store workspaces, actors, and activity
A store workspace is a durable, mutable working state inside the store (workspaces.json). Project commands act in the active workspace: --workspace NAME if given, else LEMA_WORKSPACE, else the workspace the directory is linked to (.lema/workspace.json), else default. Each request a project command sends names that workspace, so lema activity --workspace NAME shows its jobs and reads.
lema workspace
| Command | Behavior |
|---|---|
lema workspace list | Lists the store’s workspaces (name, snapshot, head, generation, actor, reference) and which one is active here. |
lema workspace show [NAME] | Shows one workspace with its modules and lock. |
lema workspace create NAME [--from REF|REV|SNAPSHOT] [--actor ID] [--description TEXT] [--ref NAME] [--dir DIR] | Creates a workspace, by default from the project’s reference. --dir DIR (missing or empty) writes its files to a directory of its own and links it. |
lema workspace set [NAME] [--actor ID | --no-actor] [--description TEXT | --no-description] [--ref NAME] | Changes a workspace’s attribution, description or reference. |
lema workspace sync [--force] | Brings a linked directory up to its workspace after another client changed it. A file edited here that the workspace changes refuses it unless --force. |
lema workspace land [--ref NAME] [--resolve FILE] [-m TEXT] [--actor ID] [--token-file FILE] | Lands the workspace’s local commits on its reference: a fast-forward, or a merge with the reference’s head first. Each step is recorded in the workspace’s pending_land, so an interrupted landing resumes. |
lema workspace delete NAME | Deletes a workspace. default, the project’s own, is never deleted. |
Scoped queries
lema search, lema context and lema neighborhood read one snapshot. In a project that is the active workspace’s; elsewhere, with no flag, they read the store’s aliases.
| Flag | Reads |
|---|---|
--workspace NAME | That workspace’s current snapshot. |
--snapshot ID | That snapshot. |
--revision ID | That revision’s snapshot. |
--all-store | With one of the above (or the active workspace), the whole store’s objects under the snapshot’s names; search and neighborhood only. |
Names are exactly the snapshot’s exports, and the objects considered are its closure; a scoped reply carries a scope block saying which snapshot it read.
lema actor add | rotate | list
Manages the store’s registered actors (actors.json). Through a running server, add and rotate authenticate an operator actor (--actor ID, default dev, with --token-file FILE or LEMA_ACTOR_TOKEN, default the project’s .lema/token); with no server holding the store they act on it directly (--store DIR).
| Command | Behavior |
|---|---|
lema actor add --id ID [--operator] [--write-token FILE [--force]] [--idempotency-key KEY] | Registers an actor and prints its new token once, or writes it to FILE (mode 0600, never over an existing file unless --force). The store keeps only the token’s SHA-256. |
lema actor rotate --id ID [--operator | --no-operator] [--write-token FILE] | Issues a fresh token for an actor (the old one stops working), optionally changing whether it is an operator. |
lema actor list | Lists the actors and whether each is an operator, never their token digests. |
lema activity
lema activity [--workspace NAME] [--actor ID] [--authenticated-only] [--kind read|write|job] [--since SEQ] [--limit N] [--follow | -f] [--json] reads the project server’s activity stream once, or with --follow prints each new event as it arrives until interrupted.
--actor IDmatches an event’s authenticated actor or the actor it claims;--authenticated-onlymatches only actors whose token the server checked.--since SEQstarts after eventSEQ;--limit N(1 to 500, default 100) caps one page.- With
--follow, a restarted server and events dropped before they were read are reported on standard error. LEMA_CORRELATION_ID, when set, tags every request a command sends, so one agent’s task can be picked out of the stream.
Lema Cloud pilot commands
These commands share a project through a hosted Lema Cloud project at https://api.cloud.lema-lang.org. Develop a library on the private Cloud pilot walks through them in order, and Lema Cloud and LemaHub explains what the service checks.
Accounts: lema cloud
| Command | Behavior |
|---|---|
lema cloud signup --id ID (--invite-file FILE | --invite-stdin) | Consumes an invitation and writes the account’s credential to ~/.config/lema/credentials.json (mode 0600, in a 0700 directory). The handle is permanent. |
lema cloud whoami | Shows the current hosted account. |
lema cloud project create --name NAME | Creates a hosted project owned by the account. Run inside a local project of the same name (and namespace) to bind it for the first push; a lost reply can be retried with the same command. |
lema cloud rotate-token | Replaces the account’s credential. |
lema cloud logout | Revokes the credential. A network error keeps the local credential until the service confirms the revocation. |
lema cloud login --token-file FILE | Installs a reissued credential, after checking it with the service. |
lema cloud app create --project NAME --app APP_ID | Registers a hosted app in a project. |
A credential is bound to the exact API address. The client refuses redirects, refuses to send a credential to Hub or application hosts, and refuses raw secrets on the command line. After a network error, repeat the same command: a pending signup, rotation or logout resumes from credentials.pending.json.
Transfer: lema clone, lema fetch, lema push
| Command | Behavior |
|---|---|
lema clone HTTPS_URL [DIR] [--ref REF] | Imports a project’s published revision and history, checks every object locally, re-elaborates its authoring records and binds the workspace head to that revision. --ref PROJECT/BRANCH selects a project branch. Reader, writer and owner roles may clone; deployer alone may not. |
lema fetch | Brings the tracked reference up to date, importing history without changing local files or the workspace head. |
lema fetch --revision REV | Imports one revision you may read in the project (from a reference’s history, a workspace or a held candidate) and its history, checking its checkpoint digest and project. Changes no files, workspace or tracking. |
lema push [--evidence-file FILE] [--reviews-file FILE] [--workspace NAME] | Uploads the active workspace head with its whole closure, at most 64 MiB, and asks the service to publish it against the last fetched revision, generation and policy version. The evidence and review files are JSON lists of at most 256 IDs. |
lema merge | After a fetch, merges the fetched head (first parent) with your commits (second parent), the order hosted publication requires. |
lema clone, lema fetch and lema push also take --allow-origin HTTPS_ORIGIN and --ca-file PEM for an explicitly configured alternative API; the credential must be bound to that origin. .lema/remote.json records the URL, project, reference and the last fetched revision, generation and policy version. Credentials are never stored in it.
A push reply carries an outcome and a durability:
| Outcome | Meaning |
|---|---|
| published | The reference moved to your revision. |
409 ref_conflict | The reference moved since your last fetch. The service keeps your admitted candidate: run lema fetch, lema merge, then lema push. |
422 review_required | The policy does not let your account publish. The service keeps the admitted revision as a held candidate for an account that may. |
422 admission_failed | The service could not check the revision. Nothing is held. |
403 with a reason | The upload or its history names objects or snapshots outside the project. Nothing is installed. |
413 | The push exceeds one of the pilot’s per-push limits. Nothing was started. |
durability.status is remote_committed (HTTP 200) once the change is stored durably, or pending_remote (HTTP 202) before that; it is independent of the outcome. After a lost reply, a 504 or a bare 503, the push may still have been queued: run lema fetch before pushing again. A queued push waits up to 15 minutes for an outcome; if none arrives, it says the push may have committed.
Review a held candidate
| Command | Behavior |
|---|---|
lema revision show REV --cloud | Shows a revision held or published in the hosted project. |
lema diff --cloud --before SNAPSHOT --after SNAPSHOT | Compares two snapshots inside the project’s authorized scope. |
lema review --cloud --revision REV --decision approve|reject --nonce 32_HEX | Records a review, by a reviewer the reference’s policy lists who has writer authority. Reuse the same nonce to retry an interrupted request; the next push can cite the review’s ID with --reviews-file. |
To publish another account’s held candidate, an account the policy lets publish runs lema fetch, lema fetch --revision REV, lema checkout REV and lema push. The revision’s first parent must be the reference’s current revision.
Activity and deployment
| Command | Behavior |
|---|---|
lema activity --remote HTTPS_ORIGIN --project NAME --token-file FILE [--ca-file PEM] [--follow] | Reads a project-filtered snapshot of the hosted service’s activity over TLS 1.3; --follow keeps reading in bounded batches. The token file must be owner-only. A 401, 403 or 503 stops following. |
lema cloud deploy https://HOST/PROJECT APP_ID --deployment ID --manifest FILE ... | Deploys an app from a reference’s published revision as a hosted VM app. Hosted deployment is not open to pilot accounts yet. |
Toolchain, runtime, and operator subcommands
Installation and build diagnostics
| Command | Behavior |
|---|---|
lema --version [--json] | Reports the explicit release or development version and build identity. |
lema build-info [--json] [--check-worker] | Reports the source revision, target and worker pin; --check-worker checks the selected VM and prints its path and digest. |
lema setup [--runtime CONFIG] [--pack-archive FILE | --no-pack] | Preserves and checks the selected configuration, installs the matching library pack, and succeeds only when the requested setup is complete. --no-pack explicitly chooses slower local library checking. |
lema self versions [--dir DIR] | Lists current and retained direct-install versions with their CLI paths. |
lema self uninstall [--dir DIR] | Removes direct-install command links while preserving versions, projects and runtime data. Use Homebrew to uninstall a Homebrew package. |
See machine setup and update or uninstall for installation paths, PATH selection and active-server restarts.
lema toolchain install and lema verify-distribution
lema toolchain install: Downloads and verifies the pinned Lean4.34.1distribution for the current supported platform.lema setupcombines toolchain installation with runtime configuration and library-pack setup.lema verify-distribution <DIR>: Verifies every file in an extracted Lean distribution against the compiled-inDISTRIBUTION_SHAmanifest.
check-runtime
lema check-runtime [--runtime <FILE>] validates a lema.runtime-linux/v2 configuration before starting a server or running sandboxed calls:
- Validates the selected platform distribution and host supervision controls. Linux records the root-owned host tools, loader and resolved libraries and checks that they remain unchanged; reviewed-pin drift is reported.
- Checks that neither
<output>/HALTEDnor<shared_lock>.HALTEDis latched. - Runs a small native kernel check under the selected systemd, container or macOS Seatbelt profile. The separate KVM result is optional for VM applications.
Store, governance, and inspection commands
| Command | Description |
|---|---|
lema init <DIR> [--axioms <LIST>] | Initializes an empty store directory with the specified axiom policy. |
lema serve [--store <DIR>] [--socket <PATH>] | Runs the store Unix domain socket daemon in the foreground. |
lema call <METHOD> [<JSON_PARAMS>] | Sends a raw JSON-RPC request to the store socket (see Server API). |
lema publish <FILE> --prefix <NS> --roots <NAMES> | Low-level single-file publication into the store. |
lema info | Prints store object counts, axiom policy, and receipt summary. |
lema search <QUERY> | Searches names, namespaces, and declaration types, in one snapshot when scoped (see Scoped queries). |
lema context <TARGET> / lema neighborhood <TARGET> | Inspects the upstream dependencies and downstream dependents of an object or name, in one snapshot when scoped. |
lema reverify | Replays every lema.core/v4 object in the store from scratch through the Lean 4.34.1 kernel. |
lema actor add / rotate / list | Registers actors and issues bearer tokens for authenticated governance operations (see Store workspaces, actors, and activity). |
lema snapshot, lema revision, lema policy, lema ref | Low-level creation and inspection of snapshots, revisions, policies, and project references. |
lema publish-revision / lema adopt-policy | Advances a project reference to a new revision or adopts a new lema.policy/v1 record. |
lema review <TARGET> --decision approve|reject | Records a signed lema.review/v1 (and optional lema.review-display/v1) record. |
lema log [--ref <NAME>] / lema report <REV_A> <REV_B> | Prints revision history or generates a lema.change-report/v1. |
lema exec import <FILE> / exec show / exec entries | Imports and inspects lema.exec-source/v2 and lema.exec/v2 records and entries.json. |
lema build <EXEC_ID_OR_ENTRY> | Compiles a lema.exec/v2 record to a lema.vm-app/v1 artifact and checks VM guarantees. |
lema release create|verify|select|withdraw|supersede|deployment | Full lifecycle management for lema.release/v1 records and active deployments. |
lema secret bundle --spec <FILE> --out <DIR> | Packages secret files and TLS trust anchors into a versioned secret-<N>.bundle (lema.secret-bundle/v1). |
lema site build --out <DIR> | Generates static HTML inspection pages for a store’s revisions, contracts, and guarantees. |
lema audit render | Renders the store-first standard library (audit/inputs/) into audit/view/{core,data,std,cap}/. |
Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility