Skip to content

Semantic version control

Why Lema versions semantic declarations and evidence directly inside the store instead of text diffs, how the 7 change categories guide code review, and how multi-agent workspaces collaborate safely.

Git was built for human programmers editing text files line by line. When an AI coding agent generates a 3,000-line change that optimizes an engine, renames private helpers, and rewrites twelve proof scripts, a line-based git diff shows you which characters moved while hiding the three questions a human reviewer actually cares about:

  1. Did the agent change any contract or theorem statement, or did it only rewrite implementation code and proofs?
  2. If the agent swapped out an implementation, is there a machine-checked proof showing the new code satisfies the selected contracts?
  3. Are all previously proved guarantees intact, or did an open obligation get dropped along the way?

To answer those questions directly, Lema includes Store-Native Semantic Version Control (SVC) independent of Git. Instead of diffing mutable text files, SVC versions immutable content-addressed declarations, contract selections, proof evidence, and branch policies directly inside the Lema store. (You can still back up authoring directories in Git if you like, while the store remains the authority on semantic history and evidence.)

Six core terms

Everything in SVC revolves around six store concepts:

TermWhat it isMutable?
WorkspaceYour isolated working state inside the store: added modules, current snapshot, and last committed revision. default is the project’s own; each coding agent can have another.Mutable (compare-and-set)
SnapshotA frozen selection of project bindings, authoring records, and locked manifest state sufficient to reconstruct the project cleanly.Immutable
RevisionA history node recording its parent revisions, snapshot, commit message, cited evidence, and open or discharged obligations.Immutable
ReferenceA policy-governed publication branch such as main. Moving a reference publishes a revision.Mutable (policy-gated)
Store actorA registered human or agent identity whose token the store checks before governed operations (publishing, reviewing, waiving).Governed
ActivityThe running server’s live event stream (lema activity) attributing reads, writes, and background jobs to workspaces and actors.Ephemeral

The daily loop (lema new, add, diff, commit, merge)

In a local project, the CLI feels familiar while operating on typed store objects underneath:

Shell
lema new escrow
cd escrow
lema add src/Storage.lema src/MemoryStorage.lean
lema status
lema diff
lema commit -m "Add EscrowStorage contract and in-memory implementation"
  • lema add elaborates your modules against pinned scopes, records any select Contract(Impl) directives, and points your active workspace at a new snapshot without touching any other workspace’s names.
  • lema status and lema diff compare your workspace snapshot semantically against the head of main.
  • lema commit computes the semantic change report, matches accepted theorems in your snapshot against open contract selections (Contracts, selections and proofs), attaches static VM guarantee receipts (plus any extra evidence passed via --evidence or --evidence-file), writes the revision, and advances main (--no-publish keeps a commit local to your workspace).

The 7 semantic change categories (lema diff)

Because the store knows the exact structural role (statement, template, proof, satisfaction) of every SHA-256 hash (Code stored by identity), lema diff classifies every change between two snapshots into seven semantic categories:

Semantic diff routing How lema diff classifies edits by structural hash role
Store-native SVC
  1. rename Alias only: statement, template, and proof hashes unchanged 0 re-checks · 0 VM rebuilds
  2. rebind Proof refactored: new proof hash; statement & template identical Kernel receipt sufficient · 0 callers affected
  3. substitute New algorithm: new template hash; statement unchanged Cleared by checked contract or Replaces proof
  4. evolve Changed contract: exported statement hash moved ⚠ Display-bound human review (or Refines proof)

Instead of scanning thousands of changed text lines, reviewers focus attention where statement hashes change or contract obligations remain open.

CategoryWhat changedWhat a human reviewer needs to check
renameAn exported name changed while keeping the exact same object ID and role.Only the name choice; zero proofs need re-checking.
exportsAn export was added or removed.Additions carry kernel receipts; removals create an explicit obligation to clear or waive.
rebindA theorem or definition got a new proof while keeping the exact same statement and template IDs.Nothing in executable code or specifications changed; the kernel receipt already verified the new proof.
substituteAn implementation export moved to a new template ID (new executable code).Check whether selected contracts are checked or backed by a Replaces equivalence theorem.
evolveA contract or theorem export moved to a new statement ID (the specification itself changed).Requires human review of the rendered contract diff (or a checked Refines theorem).
policyThe reference’s governance policy changed.Must be authorized under the currently active policy before adoption.
materialSupporting authoring files, notes, or assets changed without altering code binding hashes.Tracked by digest inside the snapshot.

When an AI coding agent spends twenty minutes optimizing a module, lema diff separates signal from noise immediately: if the report shows only rebind and substitute entries with passing contract proofs and zero evolve entries, you know mathematically that no specification was weakened.

Three-way semantic merges (lema merge)

When two workspaces or branches diverge from a common ancestor, lema merge performs a three-way semantic merge over their binding maps and manifests rather than matching adjacent lines of text:

  • Non-overlapping updates, new modules, and proved witnesses carry forward cleanly.
  • Incompatible edits to the same symbol produce structured semantic conflicts (update-update, delete-update, rename-rename, collision) resolved explicitly via --resolve.
  • Open obligations from both parents are preserved in the merge revision until discharged by a theorem (or explicitly waived by an authorized actor, which is recorded as a workflow decision and never counted as proof evidence).

Workspaces: several agents on one store

When two coding agents (or an agent and a human) share a single working directory, one lema add clobbers the other’s bindings. Store workspaces give each worker an isolated state inside the same store served by one lema serve:

  • Compare-and-set updates: Each workspace tracks an incarnation and monotonic generation. Concurrent edits that race on a stale generation fail cleanly instead of silently overwriting work.
  • Dedicated agent directories: lema workspace create agent-1 --dir ../agent1 links a separate checkout directory to its own store workspace, lema workspace sync refreshes it, and lema workspace land fast-forwards or merges its commits onto main crash-safely.
  • Scoped search and live activity: Queries (lema search, lema context, lema neighborhood) read only your active workspace’s snapshot closure, while lema activity lets you watch authenticated agent jobs progress in real time.

Protected branch policies and display-bound reviews

A reference such as main can enforce a governance policy requiring:

  1. Axiom ceilings and VM guarantees: Refusing revisions that exceed allowed axioms or lack required ConstantTime / SecretFlow receipts.
  2. Interface boundary gates (Decision 0046): Walking the citation graph to confirm client theorems depend only on abstract interfaces rather than unfolding private implementation templates.
  3. Display-bound human reviews: When a specification change (evolve) requires human sign-off, the review signature binds both the rendered Pythonic Lema contract digest and the cryptographic digest of the renderer itself, ensuring what the human approved on screen matches the stored kernel object byte for byte.

See Review and merge semantic changes and Tutorial 7: Work alongside an agent in store workspaces for hands-on workflows.

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