Skip to content

Server API

Reference for the Lema Unix domain socket JSON protocol, concurrency model, and all method groups.

The lema serve daemon (crates/lema-http) exposes a line-delimited JSON protocol over a local Unix domain socket. Every lema CLI command communicates with the store through this protocol, and external tools can call it directly via lema call <METHOD> '<JSON>' or by connecting to the socket.


Transport and concurrency model

ParameterValue
Socket permissionsCreated with umask 077 (mode 0600, accessible only to the owning OS user).
FramingSingle-line UTF-8 JSON request followed by \n; single-line UTF-8 JSON response followed by \n.
Maximum request size268,435,456 bytes (256 MiB).
Read / write timeout120 seconds per socket request/response frame.
ConcurrencyRead-only methods execute concurrently against an immutable in-memory store snapshot. Mutating methods acquire an exclusive commit lock when persisting objects or updating indices. Long-running elaboration, reverification, and VM compilation tasks can also run asynchronously via the background job queue (jobs.rs).

Request and response envelope

JSON
{"method": "info", "params": {}}

Successful responses return "ok": true alongside method-specific fields:

JSON
{"ok": true, "object_count": 412, "axioms": ["propext", "Quot.sound", "Classical.choice"]}

Failed requests return "ok": false with an "error" message and optional structured "errors" array:

JSON
{"ok": false, "error": "object not found: 3f9a...c102"}

Attribution fields

Beside method and params, a request may carry four optional fields that say who it is for. They feed the activity stream (activity.list) and change nothing else.

FieldTypeMeaning
workspaceStringThe store workspace the request is made in.
actorStringThe actor the request claims to be for. Only a method that checks a token makes it the authenticated actor.
correlation_idString (1 to 64 printable ASCII bytes)A client’s own tag, for example one agent task. The CLI sends LEMA_CORRELATION_ID.
observerBooleantrue on a read records no activity event, so a client that only watches never feeds the stream it watches. Refused on a write or a job method.

A workspace or actor given both here and in params must be byte for byte the same (a workspace method’s params.name is its workspace), or the request is refused before it runs.

JSON
{"method": "search", "params": {"query": "greet", "workspace": "agent-1"}, "observer": true}

Common request parameters

Mutating methods support three cross-cutting parameters inside "params":

ParameterTypeDescription
expectObject ({aliases?, refs?})Optimistic concurrency precondition checking that specific aliases or project references (generation) match expected values before committing.
idempotency_keyStringDeduplicates retried publication requests under hash domain LEMA-PUBLICATION-v1\0.
tokenStringActor bearer token (hashed with SHA-256 and verified against actors.json) required for governance actions (review.create, ref.publish, ref.adopt, release.*).

Objects, aliases, and discovery methods

MethodMutatesParameters and behavior
infoNo{} -> Returns store schema version, object_count, configured axioms, and receipt counts.
idsNo{"kind"?: "<kind>"} -> Lists all 64-hex lema.core/v4 object IDs in the store, optionally filtered by kind.
getNo{"id": "<id>"} -> Returns the raw canonical lema.core/v4 JSON object for id.
showNo{"target": "<id-or-alias>", "syntax"?: "lean" | "lema"} -> Renders a human-readable view of an object, declaration, or contract alongside its verification status.
findNo{"name"?: "<prefix>", "kind"?: "<kind>"} -> Finds declarations or aliases matching the filter.
depsNo{"id": "<id>"} -> Returns direct referenced object IDs (refs) of id.
dependentsNo{"id": "<id>"} -> Returns all objects in the store that directly reference id.
closureNo{"roots": ["<id>", ...]} -> Computes the topologically sorted transitive dependency closure of roots.
receiptsNo{"id"?: "<id>"} -> Returns kernel replay verification receipts (axioms, kernel digest, call ID).
aliasYes{"name": "<alias>", "id": "<id>"} -> Binds or updates a human-readable alias in aliases.json.
submit / importYes{"objects": [<core-v4>, ...], "aliases"?: {...}} -> Validates and replays pre-built lema.core/v4 objects through the Lean kernel and admits them into the store.
exportNo{"roots": ["<id-or-alias>", ...]} -> Exports the self-contained lema.core/v4 object closure for roots.
viewNo{"id": "<id>", "syntax": "lema" | "lean", "rederive"?: true} -> Renders a contract or statement via crates/lema-core/src/view.rs (render_declaration and optional zero-Lean rederive).
searchNo{"query": "<text>", "limit"?: <usize>} -> Searches aliases, namespaces, and rendered type signatures.
contextNo{"target": "<id-or-alias>"} -> Returns the declaration’s type, axioms, realizations, and associated lema.contract/v1 selections.
neighborhoodNo{"target": "<id-or-alias>", "depth"?: <usize>} -> Returns the bounded upstream and downstream dependency graph around target.

Scoped reads

search, context, neighborhood, show, view and find take a scope: at most one of "workspace": "<name>" (its current snapshot), "snapshot": "<id>" or "revision": "<id>" (its snapshot). Scoped, a read’s names are exactly that snapshot’s exports and its objects are the snapshot’s dependency closure; search and neighborhood also take "all_store": true to consider the whole store’s objects under the snapshot’s names. The reply carries a scope block: {kind, workspace?, incarnation?, generation?, revision?, snapshot, all_store?}. Without a scope, reads use the store’s aliases as before.


Authoring, checking, and evolution methods

MethodMutatesParameters and behavior
elaborateNo{"source": "...", "syntax"?: "lean" | "lema", "prefix": "...", "roots": [...]} -> Runs the sandboxed elaboration and kernel replay pipeline and returns the resulting lema.core/v4 objects without committing them to the store.
publishYesSame parameters as elaborate plus optional aliases and idempotency_key -> Elaborates, replays in the kernel, commits all objects and lema.contract/v1 selections to the store, and updates aliases.
reverifyNo{"ids"?: ["<id>", ...]} -> Replays every specified object (or the entire store) from scratch in a fresh Lean 4.34.1 kernel process.
replaceYes{"target": "<alias>", "replacement": "<id>", "proof": "<id>"} -> Replaces an implementation behind an alias after checking a Replaces / equality witness.
refineYes{"target": "<alias>", "refinement": "<id>", "proof": "<id>"} -> Updates an implementation or specification with a checked Refines / Implements witness.
correctYes{"target": "<alias>", "replacement": "<id>", "reason": "..."} -> Records an explicit specification correction when a prior statement had a bug.
evolutionNo{"target": "<alias-or-id>"} -> Returns the chain of replace, refine, and correct steps for a declaration.
rebindYes{"authoring": "<id>", "bindings": "<binding-map-id>"} -> Re-elaborates or re-links an authoring bundle against updated dependency bindings and records a lema.derivation/v1.
instantiateYes{"template": "<id>", "fillings": [...], "proof": "<id>"} -> Instantiates a template object into a checked satisfaction and lema.derivation/v1.

Contract selection methods (lema.contract/v1)

MethodMutatesParameters and behavior
contract.selectYes{"contract_or_claim": "<id-or-alias>", "arguments": [...], "scope"?: {...}, "by"?: "<witness-id>", "laws"?: [...], "waive"?: "<reason>"} -> Synthesizes the instantiated target statement and per-law targets, runs Store::check_witness if a witness is provided, and stores an immutable lema.contract/v1 record (status: "open" | "checked" | "waived").
contract.statusNo{"snapshot"?: "<id>", "status"?: "open" | "checked" | "waived"} -> Lists lema.contract/v1 records and their per-law discharge status, plus each law’s structural Rederived::hidden count.
contract.candidatesNo{"contract": "<contract-id>"} -> Scans the store for accepted proof and satisfaction objects whose targets match the open selection or its individual laws.

Bundles, snapshots, revisions, policies, and reviews

MethodMutatesParameters and behavior
bundle.create / get / listYes / NoCreates or queries lema.bundle/v1 export bundles.
binding-map.createYes{"bindings": [{"alias": "...", "bundle": "<id>"}]} -> Creates a lema.binding-map/v1 record.
authoring.createYesStores a lema.authoring/v2 bundle and validates it (lema.validation/v1).
snapshot.createYes{"entries": {...}, "bindings": "<id>", "authoring"?: "<id>", "assets"?: [...]} -> Creates a lema.snapshot/v2 record (and any lema.asset/v1 records).
snapshot.diffNo{"left": "<snapshot-id>", "right": "<snapshot-id>"} -> Computes a lema.change-report/v1 between two snapshots.
revision.createYes{"parents": [...], "snapshot": "<id>", "intent": "...", "obligations"?: [...], "discharged"?: [...]} -> Creates an immutable lema.revision/v1 record.
revision.show / revision.logNoInspects a single revision or walks the parent DAG from a starting revision ID.
revision.reportNo{"from": "<rev-id>", "to": "<rev-id>"} -> Generates and stores a lema.change-report/v1 record between two revisions.
policy.createYes{"require": {...}, "protect"?: [...], "review"?: {...}} -> Creates an immutable lema.policy/v1 record.
record.get / record.listNoRetrieves any store record by ID or lists record IDs by schema (lema.snapshot/v2, lema.contract/v1, lema.revision/v1, lema.policy/v1, lema.release/v1, and others).
ref.create / ref.list / ref.logYes / NoCreates or queries named project references in refs.json.
ref.publishYes{"name": "<ref>", "revision": "<rev-id>", "expected_generation"?: <u64>} -> Verifies revision against the reference’s active lema.policy/v1 and advances the reference.
ref.adoptYes{"name": "<ref>", "policy": "<policy-id>"} -> Adopts a new lema.policy/v1 on a reference after checking review thresholds.
ref.reportNoReturns the current governance and obligation report for a reference.
merge.createYes{"base": "<rev>", "left": "<rev>", "right": "<rev>", "resolutions"?: [...]} -> Computes a three-way semantic merge (lema.merge/v1).
review.createYes{"target": "<id>", "decision": "approve" | "reject", "comment"?: "...", "display"?: {...}} -> Records a lema.review/v1 (and lema.review-display/v1 when display is included).
view.mark / site.buildYes / NoRecords lema.view/v1 inspection markers or builds static HTML documentation pages.
checkpoint.export / import / rebuildNo / YesExports, imports, or kernel-rebuilds a lema.checkpoint/v1 (.lemabundle) closure.

Store workspaces, actors, and activity

A workspace’s every change names the {incarnation, generation} it expects (expect; null to create), and the store refuses the change if either moved. Mutating workspace and actor methods take an optional idempotency_key: a retry gets the first reply back with replayed: true instead of changing anything twice.

MethodMutatesParameters and behavior
workspace.listNo{} -> {workspaces: [{name, incarnation, generation, project, ref, head, pending_land, snapshot, modules, actor, description}]}, by name.
workspace.getNo{"name": "<name>"} -> The workspace whole: its snapshot, head, generation, reference, module paths, lock, project settings and any pending_land.
workspace.setYes{"name", "expect", "snapshot"? | "project"? + "modules"? + "lock"?, "ref"?, "head"?, "pending_land"?, "actor"?, "description"?} -> {workspace, created}. Given a project, modules and lock, the store makes the snapshot (with its .lema/manifest.json) itself.
workspace.commitYes{"name", "expect", "mode": "local" | "merge_candidate", "revision": {after, intent, parents?, base?, evidence?, obligations?, discharged?}, "pending_land"?} -> {name, revision, created, before, incarnation, generation, workspace}. Stores the revision and advances the workspace in one crash-safe step.
workspace.deleteYes{"name", "expect"} -> {deleted, incarnation, generation}. default is never deleted.
commit.planNo{"ref", "after", "parent"?, "obligations"?, "waive"?, "witnesses"?} -> The revision lema commit would write: {ref, parent, expect, before, after, report, obligations, discharged, evidence, intent, ...}. parent names the revision the new one follows (a workspace’s head, or null for a first revision); without it, the reference’s head.
actor.listNo{} -> [{id, operator}], never token digests.
actor.addYes{"id", "operator"?, "actor", "token"}, by an operator actor -> {id, operator, token, already_applied}; the new token is shown once. A retry after success gets token: null and already_applied: true: recover a lost token with actor.rotate.
actor.rotateYes{"id", "operator"?, "actor", "token"}, by an operator actor -> {id, operator, token}: a fresh token.
activity.listNo{"stream_id"?, "since"?, "limit"?, "workspace"?, "actor"?, "authenticated_only"?, "kind"?: "read" | "write" | "job"} -> {stream_id, reset, oldest_seq, latest_seq, next_cursor, gap, has_more, events} (below).

The activity stream

Each server boots with a random 16-hex stream_id and numbers its events seq 1, 2, and so on. It keeps the newest 4,096 events (at most 8 MiB, each event at most 4 KiB), never on disk. Polling and metadata reads (activity.list, job.list, job.poll, ref.list, workspace.list, actor.list) and reads marked observer are never recorded.

  • Pass back the stream_id you were given and since: next_cursor. A stream_id that is not the server’s gives reset: true and reads from the start (the server restarted); gap: true means events after since were dropped before you read them.
  • limit defaults to 100 and is at most 500. A full page with more events after it has has_more: true and next_cursor set to its last event’s seq; otherwise next_cursor is latest_seq.
  • actor: A matches an event’s authenticated_actor or its claimed_actor; with authenticated_only: true, only the former.

An event (lema.activity-event/v1) is built from bounded fields only, never a request’s raw parameters, a result, a token, source text or error text:

JSON
{
  "schema": "lema.activity-event/v1",
  "seq": 32, "at_ms": 1793511300000, "request_id": 87,
  "kind": "write", "method": "ref.publish", "ok": true,
  "workspace": "default", "claimed_actor": "dev", "authenticated_actor": "dev",
  "correlation_id": null,
  "snapshot": {"id": "4a9a...0640", "seq": 9},
  "nav": {"kind": "revision", "id": "89d0...3f4c", "ref": "main"}
}

A job’s events carry job and phase (queued, running, then committed, failed or cancelled), and share the request_id of the request that submitted it. A scoped read’s event carries scope ({kind, workspace?, snapshot}). nav says where a request went: object {id}, neighborhood {id, direction, depth, limit, kinds, include_hubs, all_store}, search {query, zoom, limit, kinds?, marks?, first_id?, all_store}, revision {id, ref?}, or diff {before?, after}.


VM execution, releases, and background jobs

MethodMutatesParameters and behavior
exec.import / exec.showYes / NoResolves a lema.exec-source/v2 manifest into a lema.exec/v2 record or retrieves an existing lema.exec/v2 record.
entry.set / entry.listYes / NoBinds or lists named execution entrypoints in entries.json (LEMA-289).
vm.guaranteeYes{"exec": "<exec-id>", "profiles": [...]} -> Compiles the LemaIR closure, runs the static guarantee analysers (ConstantTime, SecretFlow.*, NoBigIntPrimitives, and others), and stores a lema.vm-guarantee/v1 receipt.
build / vm.buildYes{"exec": "<exec-id>"} -> Checks all required guarantees, compiles the lema.vm-app/v1 artifact, and registers <output>/vm-workers/<sha256>.json.
vm.testNo{"exec": "<exec-id>"} -> Executes pure or vector test manifests in crates/lema-vm and returns pass/fail results and resource counters.
runNo{"exec": "<exec-id>", "fuel"?: <u64>, "input"?: "<hex>", "cap_config"?: {...}} -> Runs a compiled lema.vm-app/v1 worker inside lema-vm-runner with the supplied capability configuration.
release.createYes{"ref": "<ref>", "entry": "<entry>", "target": "vm"} -> Verifies policy compliance, guarantee receipts, and review thresholds, then writes an immutable lema.release/v1 record.
release.get / list / verifyNoRetrieves, lists, or re-verifies lema.release/v1 records and their artifact SHA-256 digests.
release.select / withdraw / supersede / deploymentYes / NoManages active deployment state (LEMA-DEPLOYMENT-v1\0) for verified releases.
job.submit / poll / cancel / listYes / NoSubmits long-running API requests (elaborate, publish, reverify, vm.build) to the asynchronous job queue (jobs.rs) and polls or cancels them by job_id.

Lema v0.3.2 · Updated 29 October 2026 · Version and compatibility