v2.0.3 · python + R · invariants · 194 tests · field-tested on Windows & live MCP

SIGIL

A contract-first, content-addressed language and toolchain for human ↔ AI coding. Intent is code. Effects are visible. Edits are patches. And nothing is called done until verification says so.

2 languages — Python & R
6.0× measured context reduction (requests 2.34.2)
~0.15ms cached verify (78× vs cold)
191 tests · 0 effect under-reports

How it works — in 75 seconds

The explainer below runs live in your browser (same scenes as the Remotion clip in video/). Once you render the MP4 (cd video && npm i && npm run render) this player upgrades to the video automatically.

SIGIL
Code an AI can't quietly get wrong.
contract-first · content-addressed · effect-typed · verified
the problem
"Fetch the prices and cache them."
…has hundreds of valid implementations — and no way to check which one the AI gave you.
Natural language
optimized for ambiguity
Mainstream code
throws the intent away
AI review
hopes someone notices
Sigil's bet: make intent, effects and verification part of the language.
step 1 · lift what you already have
Any Python repo → a one-page digest sheet
def fetch_user(user_id):
  cached = read_cache(…)
  if cached: return cached
  r = requests.get(f"{API}/users/…")
  write_cache(…)
  return r.json()

# …14 more functions…
sigil lift ⟶
#705b get_config(key) !env
#d939 read_cache(name, ttl) !clock !fs
#d4b8 fetch_user(user_id) !clock !fs !net
#9b4e order_totals(orders) pure?
#f574 jitter_sleep(attempt) !clock !rand
#e70b dispatch(event) !unsafe?
; '?' = static guess — never silenced
tok measured on requests 2.34.2 — 6.0× smaller, hashes instead of bodies
step 2 · write the contract, not the code
A goal is the entire human contribution
goal fetch_prices {
  intent: "Daily OHLCV for the given tickers"
  in: tickers [Str], start Str, end Str
  out: Map
  fx: !net(api.example.com)
  verify:
    out.keys.set == tickers.set
}
intent — for humans, kept with the code
effect BUDGET — the impl may use at most this
verify — the acceptance test, written before any code
An implementation is only accepted if these clauses pass. The goal doesn't move.
step 3 · the budget is enforced, statically
An AI sneaks in a cache write. The build says no.
-- impl calls save_cache() → open() — but fx: !net only
sigil build: rejected.
effect budget exceeded for goal 'fetch_prices':
fetch_prices → save_cache: open requires !fs; budget allows !net(api.example.com)
Remedy: remove the call, or extend the goal's fx: budget if intended.
No runtime sandbox needed — it's a call-graph check at build time. Hidden I/O, eliminated structurally.
step 4 · how an agent works on it (MCP harness)
sheet → expand → patch → verify
sheet()
digests, not files
expand(#6e01)
only what you change
patch(…)
ops, not files
verify ✓
checked before "done"
verify: fail — out == n * 3 with out=8, n=4
expand #6e01: fn triple(n Int) { ret n * 2 }
⇒ #a4c2 · verify: pass · goal triple: verified
R1 context only grows R2 expand beats regenerating R3 failures return patch targets, never "try again"
measured, not estimated
v2.0.3 — every number is from the actual build
tests green · 92% core coverage
×
measured context reduction
effect under-reports / 35 fixtures
~0.15ms
cached verify hit (78× vs cold)
Honest where it matters: the spec guessed 10×+ — measurement said 6.0× at first contact; the bigger wins compound per-iteration.
SIGIL
Nothing is called done until verification says so.
pip install -e ".[dev,harness]"
sigil lift your/code · sigil serve --root .
see the quick guide tab ↑
0:00 / 1:15

New in v2 — from tool to substrate

v1 made Python code verifiable. v2 makes the model language-neutral and the contracts richer. Every line below ships in v2.0.1 — see the Changelog.

⌘Language-neutral IR + R

Lifted code now hashes to a neutral IR, not Python AST tuples — so a second frontend could land without touching the store. The first one did: sigil lift script.R, plus sigil check-r reproducibility contracts (analyze(seed=42) ≡ #hash), the scientific wedge pytest can't reach.

⟲Multi-fn invariants

invariant round_trip { over: enc, dec verify: dec(enc(x)) == x } — a property across two functions. Patch either one and the invariant re-verifies automatically. One broken edit can't slip through.

!Effect modes & module budgets

!fs.read vs !fs.write, first-class !db, and a whole-module fx: budget every function must satisfy. "This module reads config, never writes, never hits the network" is now a checkable contract.

@@sigil.bind — write plain Python

Decorate an ordinary function; Sigil lifts it on import, checks its declared budget statically, and verifies through the same runner. The .sg language stays for advanced cases — it's no longer the price of entry.

✓CI gate + always-on watch

sigil check --against origin/main fails the build if a bound contract regressed or silently vanished — one line in Actions. sigil watch re-verifies on every save. The seatbelt is always on.

∴Tier-3 propose / validate

Your agent propose_contracts verify clauses; Sigil validates them against independently generated inputs (not the agent's own example) and binds only on zero counterexamples over many cases — guesses can't launder into specs. sigil from-pytest turns parametrize tables into reviewable goal drafts.

Three guarantees, enforced — not reviewed

Mainstream languages throw away intent; prompts can't be verified. Sigil makes the contract the source of truth and the toolchain its enforcer.

#Content-addressed identity

Every definition is named by the sha256 of its canonical AST. Reformatting, comments, docstrings — hash unchanged (proven by property tests, 200 random mutations a run); but they aren't discarded — the original source is kept verbatim and returned by expand, so an agent reads the author's actual docstring, not a re-print (v2.0.3). Any semantic change — hash moves. "Did the AI change the logic?" is a string compare.

!Effects are typed

Every function carries its effect row: !net !fs !rand !clock !env… A goal's budget is checked statically; a sneaked-in write fails the build naming the exact call chain. When analysis can't see through dynamic code it says !unsafe? — uncertainty is never silenced.

∴Verify before display

Goals declare executable verify: clauses. Implementations run them subprocess-isolated with timeouts; a pass binds goal↔impl in the store, anything else stays provisional. Patches are auto-verified before success is ever shown.

What a digest sheet looks like

Real output — sigil lift examples/lift-legacy/webapp.py, a deliberately effect-rich legacy module. One line per definition; the AI reads this, not your files.

sigil lift — Tier 1+2 mechanical, never executes your code
#705b get_config(key, default) !env
#d939 read_cache(name, ttl_seconds) !clock !fs
#d4b8 fetch_user(user_id) !clock !fs !net
#9b4e order_totals(orders) pure?
#f574 jitter_sleep(attempt) !clock !rand
#e70b dispatch(event) !unsafe?   ← dynamic dispatch: flagged, not guessed
; '?' marks static guesses — Tier 2 over-approximates, never trusts.

The agent loop: sheet → expand → patch → verify

From the scripted agent-session transcript (examples/agent-session/): a seeded bug fixed with zero file reads, zero file writes, one patch.

MCP harness · sigil serve · rules R1–R3 enforced
-- verify reports the failure, with values:
verify triple: fail — out == n * 3 with out=8 inputs={'n': 4}

-- the agent expands only the 11-token implementation, not the file:
fn triple(n Int) -> Int { ret n * 2 }

-- one 18-token patch op, auto-verified before display (R3):
patch #6e01 { body.stmts.0.value.right.val := "3" }
⇒ #a4c2 · verify: pass · goal triple: verified

-- the sheet only ever grew (R1, property-tested):
#6e01 -> #a4c2 triple

R1Append-only context

The digest sheet never rewrites history — your cached prompt prefix stays byte-stable. Proven with a hypothesis property over arbitrary op sequences.

R2Expand, don't regenerate

expand(#hash) is byte-identical forever. Re-reading code is cheap cached input; re-emitting it from memory is expensive output.

R3Verify before display

Failures return the failing clause, observed values, and the subtree hash to patch — never “try again from scratch”. The retry term is the one that dominates cost.

Measured results — benchmarked on v2.0.3

Real production BPE tokenizer, real artifacts, reproducible via scripts/benchmark.py (full report in docs/benchmarks.md). Where measurement contradicted the spec's estimates, the measured number won.

sourcefull sourcedigest sheetreduction
demo_module.py (4 fns)319 tok133 tok2.4×
lift-legacy webapp.py (15 fns)768 tok306 tok2.5×
requests 2.34.2 — 6,385 lines, 302 definitions52,464 tok8,812 tok6.0×

Honest note: the spec guessed "10×+ at first contact" — measurement says 6.0× on a real repo (the neutral IR is marginally tighter than v1). The bigger win is per iteration: that 8.8k-token sheet is cache-eligible (R1), an edit expands ~19 tokens and a patch costs ~29 output tokens — versus re-reading 52k fresh tokens.

Verify cache

~0.15 ms
median cached hit on unchanged code — 78× faster than a ~12 ms cold run. Content-addressed: a file read + parse. Timeouts/errors never cached.

Effect inference

0
under-reports across 39 labeled functions (35 fixtures), 2.4% over-report. The security-critical metric — a missed effect is a bug, an extra one is noise.

Lift throughput

~3,800
definitions/sec (~79k lines/s) — all of requests lifts in under 0.1 s. Parse + hash only; no code runs.

Iteration turn

29 tok
to emit a verified patch — sheet 19 (cached) + expand 19 + patch 29 out, vs 60 to re-read even a tiny module. Output scales with the change.

IR round-trip

100%
of the 19 requests modules are hash-stable through lower → render → re-lower — the property that lets patches and expand ride on the neutral IR.

Build quality

191
tests green · 92% coverage on core/lift/transpile · ruff clean · property-tested hashing, round-trips, patch≡re-lift, R1 · CI on Linux 3.11–3.13 + Windows.

Benchmarks, visualized

The same v2.0.1 numbers as plots, each with what it measures and how it moved across versions. Reproduce any of them with python3 scripts/benchmark.py.

Context reduction — sheet vs full source

How much smaller the digest sheet an agent reads is than the raw file. Bar = the sheet as a fraction of the full source; shorter is better.

What it means: the agent references hashes, not bodies — a 10k-line repo becomes a one-page sheet. v1 5.9× → v2.0.1 6.0× on requests (the neutral IR sheets are marginally tighter).

Tokens an agent spends per edit turn

The actual cost of one fix: read the sheet, expand only the target, emit a patch — versus re-reading the whole module. Output (the expensive side) scales with the change.

What it means: R1 keeps the sheet cache-eligible, R2 expands on demand, R3 emits a patch not a file. At repo scale that's an 8.8k cached-token sheet vs 52k fresh per turn — where the >10× compounding lives.

Verify latency — cold vs cached

A goal's contracts run subprocess-isolated once (cold); an unchanged re-verify is a content-addressed cache hit. Log scale — the cached bar is genuinely that small.

What it means: re-checking unchanged code is effectively free, so the loop stays fast. v1 gate was <50 ms → v2.0.1 measures ~0.15 ms (78× vs cold).

Effect inference accuracy, by version

The security metric. A missed effect is a bug; an over-reported one is acceptable noise. Bars = hand-labeled fixtures; the line that matters is flat at zero.

What it means: 0 under-reports, every version, even as fixtures grew 30→35 (read/write modes + !db added in v1.1). Over-report 2.6% → 2.4%.

Test suite growth, every release green

Each release shipped with the full suite passing and tagged. Each exit gate was written as a failing test before the feature it gates.

What it means: coverage of behavior grew with capability, never traded away. 130 → 191 tests across seven releases; + R, invariants, IR round-trip property tests in v2.

Tier-3 validation — agent can't grade its own homework (v2.0.2)

A proposed rule is checked against independently generated inputs, not the witness the agent chose. Measured on the report's clamp exploit.

What it means: the false rule out == x that earned a lucky verified before is now refuted by a generated counterexample and stays provisional; a genuinely true rule still verifies over 40 cases. Hardened in v2.0.2.

What v2 added on top of v1

v1 was a Python verifier; v2 made the model language-neutral and the contracts richer. New capabilities, measured where measurable.

What it means: a second language (R) lands without touching the store; lifted modules round-trip the neutral IR at 100%; lift runs at ~3,800 defs/s. All new in v2.

Six phases, six gates, all green

Every phase exit gate was written as a failing test before its implementation.

Phase 0Core AST + canonical hashing — formatting never moves a hash, semantics always do✓ gate
Phase 1Lifter Tiers 1–2 — requests 2.34.2 lifted; zero under-reports on the labeled set✓ gate
Phase 2Language + transpiler — LL(1) grammar, lossless round-trip, over-budget effects rejected with the call chain✓ gate
Phase 3Verify runner + store — subprocess isolation, (goal, impl) verdict cache, binding only on pass✓ gate
Phase 4MCP harness — lift / sheet / expand / patch / verify under R1–R3; scripted agent session✓ gate
Phase 5Hardening + release — measured cost model, docs, examples, clean-venv install, v1.0.0 (v1.0.1 after field testing)✓ gate

Then a real first user filed a report (a true bug, fixed) and a roadmap. Three more releases shipped — depth, then width — same discipline: failing test first, suite green at every commit.

v1.1.0Effect modes + module budgets · @sigil.bind · patch-by-snippet · unbind/diff✓ shipped
v1.2.0Recorded inputs · sigil check CI gate · sigil watch · property generation✓ shipped
v2.0.0Language-neutral IR (+migrate) · R frontend (+check-r) · multi-fn invariants · Tier-3 propose/validate✓ shipped
v2.0.1Second field report — Windows/UTF-8 crash fixed · invariant binding persisted after patch · Windows + 3.13 CI lanes✓ shipped

Honest limits (docs/limitations.md): effect scopes are recorded but not enforced (modes now are); heavily dynamic Python and R earn !unsafe? rather than answers; R Tier-1 is token-canonical, not a full parser; lifting is one-directional; verify network-blocking is best-effort; JVM/JS frontends are v3. CI runs on Linux 3.11–3.13 + Windows.

Get started: pip install -e ".[dev,harness]" → sigil lift your/code → sigil serve --root . · docs/quickstart.md · Sigil v2.0.3, 2026