Speckl

A compiler for state machine specifications by Scott Scoble

Your specification is the source of truth. Speckl ensures what gets built — by humans or AI — stays faithful to what you specified. Compile state machine specs into auditable code with embedded provenance.

What Speckl Does

Speckl is a compiler for state machine specifications. You write what your system should do in SpeckDL — a typed specification language with states, actions, invariants, and guard conditions. The compiler produces five auditable artifacts from a single spec:

📜

PROV-O

W3C audit trail — who said what, when

📦

CycloneDX

Software Bill of Materials

📋

SPDX

License & compliance metadata

⚡

TypeScript

Runnable state machine class

🔍

Z3 Verification

SMT-LIB2 output from --target=z3

No LLMs in the compiler. Same spec, same output, every time. Every compilation embeds provenance — PROV-O traces, CycloneDX and SPDX SBOMs — so auditors can trace any generated code back to its specification.

SpeckDL by Example

SpeckDL is a typed specification language for state machines. Define your states, actions, preconditions, and mutations — the compiler handles the rest.

// A simple toggle switch — compiles to TypeScript + 3 provenance artifacts
spec ToggleSwitch {
  type Status = enum { On, Off }

  state {
    status: Status = Status.Off
  }

  init Start() {
    set status = Status.On
  }

  action Flip() {
    require status == Status.On
    set status = Status.Off
    emit "TurnedOff"
  }

  action FlipBack() {
    require status == Status.Off
    set status = Status.On
    emit "TurnedOn"
  }

  invariant "At most one pending action" {
    !(status == Status.Flip && !(status == Status.FlipBack))
  }
}

Type system: Int · Float · Bool · String · Enum · Struct · List<T> · Set<T> · Map<K,V>  |  Keywords: spec · type · state · init · action · require · set · emit · invariant

Real Examples

Two-Phase Commit

45 lines · 5 actions

Classic distributed transaction coordinator. Voting phase, commit phase, abort path — fully specified with guard conditions.

Kafka KRaft

141 lines · 6 safety invariants · BMC verify blocks

Flagship example: leader election, log replication, and safety properties verified with Z3 SMT. Don't replace Kafka. Prove it.

Paxos

120 lines · 3 safety invariants

Consensus for unreliable networks. Prepare, promise, accept, commit — with "only one value chosen" invariant.

Raft

230 lines · 8 actions · 3 invariants

Leader election, log replication, safety. The largest SpeckDL spec — demonstrates composition at scale.

Issue Workflow

9 actions · 8 guard conditions

Real-world state machine: create → assign → review → merge → close. 5 temporal verification conditions.

Access Control

RBAC system · clean TS output

Role-based access with role addition, removal, and permission checks. One of 5 examples with zero TypeScript errors.

+ 8 more

OAuth2AuthorizationCode · DrugDosageCalculator · PaymentService · RetryHandler · TemperatureMonitor · AccountLedger · TigerBeetle · PreconditionTest

Browse all 14 examples →

Status & Roadmap

The WAT/WASM generator was removed in favor of a proper IR → Rust → wasm-pack pipeline. No hand-rolled WASM text format; no magic.

Try It

# Clone the repo
git clone https://github.com/wscoble/speckl.git
cd speckl/compiler

# Build and run tests (41 tests, ~2s)
npm install
npm test

# Compile a spec to TypeScript + provenance artifacts
node dist/index.js ../examples/TwoPhaseCommit.speckdl -o out/twophase

# Compile to Z3 SMT-LIB2 for verification
node dist/index.js ../examples/KafkaKRaft.speckdl --target=z3 -o out/kraft

# Check TypeScript validity
npx tsc --noEmit -p out/twophase

Shipping Code an Agent Wrote?

Speckl makes the spec checkable. The release still needs a gate. I keep the checks I run before code goes to production on one page, for code written by people or by coding agents.

AI Code Release Checklist

  • Every acceptance criterion names how it gets checked
  • A named human owns the release
  • No test loosened or skipped to get green
  • Rollback rehearsed, with the time written down

18 checks, one page. Free, pay what you want. The checklist is free under CC BY 4.0. Share and adapt it, with credit.

Take the 10-question readiness self-check