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:
- Did the agent change any contract or theorem statement, or did it only rewrite implementation code and proofs?
- If the agent swapped out an implementation, is there a machine-checked proof showing the new code satisfies the selected contracts?
- 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:
| Term | What it is | Mutable? |
|---|---|---|
| Workspace | Your 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) |
| Snapshot | A frozen selection of project bindings, authoring records, and locked manifest state sufficient to reconstruct the project cleanly. | Immutable |
| Revision | A history node recording its parent revisions, snapshot, commit message, cited evidence, and open or discharged obligations. | Immutable |
| Reference | A policy-governed publication branch such as main. Moving a reference publishes a revision. | Mutable (policy-gated) |
| Store actor | A registered human or agent identity whose token the store checks before governed operations (publishing, reviewing, waiving). | Governed |
| Activity | The 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:
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 addelaborates your modules against pinned scopes, records anyselect Contract(Impl)directives, and points your active workspace at a new snapshot without touching any other workspace’s names.lema statusandlema diffcompare your workspace snapshot semantically against the head ofmain.lema commitcomputes 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--evidenceor--evidence-file), writes the revision, and advancesmain(--no-publishkeeps 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:
- rename Alias only:
statement,template, andproofhashes unchanged 0 re-checks · 0 VM rebuilds - rebind Proof refactored: new
proofhash;statement&templateidentical Kernel receipt sufficient · 0 callers affected - substitute New algorithm: new
templatehash;statementunchanged Cleared by checked contract or Replaces proof - evolve Changed contract: exported
statementhash 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.
| Category | What changed | What a human reviewer needs to check |
|---|---|---|
rename | An exported name changed while keeping the exact same object ID and role. | Only the name choice; zero proofs need re-checking. |
exports | An export was added or removed. | Additions carry kernel receipts; removals create an explicit obligation to clear or waive. |
rebind | A 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. |
substitute | An implementation export moved to a new template ID (new executable code). | Check whether selected contracts are checked or backed by a Replaces equivalence theorem. |
evolve | A 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). |
policy | The reference’s governance policy changed. | Must be authorized under the currently active policy before adoption. |
material | Supporting 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
incarnationand monotonicgeneration. Concurrent edits that race on a stale generation fail cleanly instead of silently overwriting work. - Dedicated agent directories:
lema workspace create agent-1 --dir ../agent1links a separate checkout directory to its own store workspace,lema workspace syncrefreshes it, andlema workspace landfast-forwards or merges its commits ontomaincrash-safely. - Scoped search and live activity: Queries (
lema search,lema context,lema neighborhood) read only your active workspace’s snapshot closure, whilelema activitylets 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:
- Axiom ceilings and VM guarantees: Refusing revisions that exceed allowed axioms or lack required
ConstantTime/SecretFlowreceipts. - Interface boundary gates (Decision 0046): Walking the citation graph to confirm client theorems depend only on abstract interfaces rather than unfolding private implementation templates.
- 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