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
| Parameter | Value |
|---|---|
| Socket permissions | Created with umask 077 (mode 0600, accessible only to the owning OS user). |
| Framing | Single-line UTF-8 JSON request followed by \n; single-line UTF-8 JSON response followed by \n. |
| Maximum request size | 268,435,456 bytes (256 MiB). |
| Read / write timeout | 120 seconds per socket request/response frame. |
| Concurrency | Read-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
{"method": "info", "params": {}}Successful responses return "ok": true alongside method-specific fields:
{"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:
{"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.
| Field | Type | Meaning |
|---|---|---|
workspace | String | The store workspace the request is made in. |
actor | String | The actor the request claims to be for. Only a method that checks a token makes it the authenticated actor. |
correlation_id | String (1 to 64 printable ASCII bytes) | A client’s own tag, for example one agent task. The CLI sends LEMA_CORRELATION_ID. |
observer | Boolean | true 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.
{"method": "search", "params": {"query": "greet", "workspace": "agent-1"}, "observer": true}Common request parameters
Mutating methods support three cross-cutting parameters inside "params":
| Parameter | Type | Description |
|---|---|---|
expect | Object ({aliases?, refs?}) | Optimistic concurrency precondition checking that specific aliases or project references (generation) match expected values before committing. |
idempotency_key | String | Deduplicates retried publication requests under hash domain LEMA-PUBLICATION-v1\0. |
token | String | Actor 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
| Method | Mutates | Parameters and behavior |
|---|---|---|
info | No | {} -> Returns store schema version, object_count, configured axioms, and receipt counts. |
ids | No | {"kind"?: "<kind>"} -> Lists all 64-hex lema.core/v4 object IDs in the store, optionally filtered by kind. |
get | No | {"id": "<id>"} -> Returns the raw canonical lema.core/v4 JSON object for id. |
show | No | {"target": "<id-or-alias>", "syntax"?: "lean" | "lema"} -> Renders a human-readable view of an object, declaration, or contract alongside its verification status. |
find | No | {"name"?: "<prefix>", "kind"?: "<kind>"} -> Finds declarations or aliases matching the filter. |
deps | No | {"id": "<id>"} -> Returns direct referenced object IDs (refs) of id. |
dependents | No | {"id": "<id>"} -> Returns all objects in the store that directly reference id. |
closure | No | {"roots": ["<id>", ...]} -> Computes the topologically sorted transitive dependency closure of roots. |
receipts | No | {"id"?: "<id>"} -> Returns kernel replay verification receipts (axioms, kernel digest, call ID). |
alias | Yes | {"name": "<alias>", "id": "<id>"} -> Binds or updates a human-readable alias in aliases.json. |
submit / import | Yes | {"objects": [<core-v4>, ...], "aliases"?: {...}} -> Validates and replays pre-built lema.core/v4 objects through the Lean kernel and admits them into the store. |
export | No | {"roots": ["<id-or-alias>", ...]} -> Exports the self-contained lema.core/v4 object closure for roots. |
view | No | {"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). |
search | No | {"query": "<text>", "limit"?: <usize>} -> Searches aliases, namespaces, and rendered type signatures. |
context | No | {"target": "<id-or-alias>"} -> Returns the declaration’s type, axioms, realizations, and associated lema.contract/v1 selections. |
neighborhood | No | {"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
| Method | Mutates | Parameters and behavior |
|---|---|---|
elaborate | No | {"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. |
publish | Yes | Same 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. |
reverify | No | {"ids"?: ["<id>", ...]} -> Replays every specified object (or the entire store) from scratch in a fresh Lean 4.34.1 kernel process. |
replace | Yes | {"target": "<alias>", "replacement": "<id>", "proof": "<id>"} -> Replaces an implementation behind an alias after checking a Replaces / equality witness. |
refine | Yes | {"target": "<alias>", "refinement": "<id>", "proof": "<id>"} -> Updates an implementation or specification with a checked Refines / Implements witness. |
correct | Yes | {"target": "<alias>", "replacement": "<id>", "reason": "..."} -> Records an explicit specification correction when a prior statement had a bug. |
evolution | No | {"target": "<alias-or-id>"} -> Returns the chain of replace, refine, and correct steps for a declaration. |
rebind | Yes | {"authoring": "<id>", "bindings": "<binding-map-id>"} -> Re-elaborates or re-links an authoring bundle against updated dependency bindings and records a lema.derivation/v1. |
instantiate | Yes | {"template": "<id>", "fillings": [...], "proof": "<id>"} -> Instantiates a template object into a checked satisfaction and lema.derivation/v1. |
Contract selection methods (lema.contract/v1)
| Method | Mutates | Parameters and behavior |
|---|---|---|
contract.select | Yes | {"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.status | No | {"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.candidates | No | {"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
| Method | Mutates | Parameters and behavior |
|---|---|---|
bundle.create / get / list | Yes / No | Creates or queries lema.bundle/v1 export bundles. |
binding-map.create | Yes | {"bindings": [{"alias": "...", "bundle": "<id>"}]} -> Creates a lema.binding-map/v1 record. |
authoring.create | Yes | Stores a lema.authoring/v2 bundle and validates it (lema.validation/v1). |
snapshot.create | Yes | {"entries": {...}, "bindings": "<id>", "authoring"?: "<id>", "assets"?: [...]} -> Creates a lema.snapshot/v2 record (and any lema.asset/v1 records). |
snapshot.diff | No | {"left": "<snapshot-id>", "right": "<snapshot-id>"} -> Computes a lema.change-report/v1 between two snapshots. |
revision.create | Yes | {"parents": [...], "snapshot": "<id>", "intent": "...", "obligations"?: [...], "discharged"?: [...]} -> Creates an immutable lema.revision/v1 record. |
revision.show / revision.log | No | Inspects a single revision or walks the parent DAG from a starting revision ID. |
revision.report | No | {"from": "<rev-id>", "to": "<rev-id>"} -> Generates and stores a lema.change-report/v1 record between two revisions. |
policy.create | Yes | {"require": {...}, "protect"?: [...], "review"?: {...}} -> Creates an immutable lema.policy/v1 record. |
record.get / record.list | No | Retrieves 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.log | Yes / No | Creates or queries named project references in refs.json. |
ref.publish | Yes | {"name": "<ref>", "revision": "<rev-id>", "expected_generation"?: <u64>} -> Verifies revision against the reference’s active lema.policy/v1 and advances the reference. |
ref.adopt | Yes | {"name": "<ref>", "policy": "<policy-id>"} -> Adopts a new lema.policy/v1 on a reference after checking review thresholds. |
ref.report | No | Returns the current governance and obligation report for a reference. |
merge.create | Yes | {"base": "<rev>", "left": "<rev>", "right": "<rev>", "resolutions"?: [...]} -> Computes a three-way semantic merge (lema.merge/v1). |
review.create | Yes | {"target": "<id>", "decision": "approve" | "reject", "comment"?: "...", "display"?: {...}} -> Records a lema.review/v1 (and lema.review-display/v1 when display is included). |
view.mark / site.build | Yes / No | Records lema.view/v1 inspection markers or builds static HTML documentation pages. |
checkpoint.export / import / rebuild | No / Yes | Exports, 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.
| Method | Mutates | Parameters and behavior |
|---|---|---|
workspace.list | No | {} -> {workspaces: [{name, incarnation, generation, project, ref, head, pending_land, snapshot, modules, actor, description}]}, by name. |
workspace.get | No | {"name": "<name>"} -> The workspace whole: its snapshot, head, generation, reference, module paths, lock, project settings and any pending_land. |
workspace.set | Yes | {"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.commit | Yes | {"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.delete | Yes | {"name", "expect"} -> {deleted, incarnation, generation}. default is never deleted. |
commit.plan | No | {"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.list | No | {} -> [{id, operator}], never token digests. |
actor.add | Yes | {"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.rotate | Yes | {"id", "operator"?, "actor", "token"}, by an operator actor -> {id, operator, token}: a fresh token. |
activity.list | No | {"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_idyou were given andsince: next_cursor. Astream_idthat is not the server’s givesreset: trueand reads from the start (the server restarted);gap: truemeans events aftersincewere dropped before you read them. limitdefaults to 100 and is at most 500. A full page with more events after it hashas_more: trueandnext_cursorset to its last event’sseq; otherwisenext_cursorislatest_seq.actor: Amatches an event’sauthenticated_actoror itsclaimed_actor; withauthenticated_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:
{
"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
| Method | Mutates | Parameters and behavior |
|---|---|---|
exec.import / exec.show | Yes / No | Resolves a lema.exec-source/v2 manifest into a lema.exec/v2 record or retrieves an existing lema.exec/v2 record. |
entry.set / entry.list | Yes / No | Binds or lists named execution entrypoints in entries.json (LEMA-289). |
vm.guarantee | Yes | {"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.build | Yes | {"exec": "<exec-id>"} -> Checks all required guarantees, compiles the lema.vm-app/v1 artifact, and registers <output>/vm-workers/<sha256>.json. |
vm.test | No | {"exec": "<exec-id>"} -> Executes pure or vector test manifests in crates/lema-vm and returns pass/fail results and resource counters. |
run | No | {"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.create | Yes | {"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 / verify | No | Retrieves, lists, or re-verifies lema.release/v1 records and their artifact SHA-256 digests. |
release.select / withdraw / supersede / deployment | Yes / No | Manages active deployment state (LEMA-DEPLOYMENT-v1\0) for verified releases. |
job.submit / poll / cancel / list | Yes / No | Submits 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