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.
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:
W3C audit trail — who said what, when
Software Bill of Materials
License & compliance metadata
Runnable state machine class
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 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
Classic distributed transaction coordinator. Voting phase, commit phase, abort path — fully specified with guard conditions.
Flagship example: leader election, log replication, and safety properties verified with Z3 SMT. Don't replace Kafka. Prove it.
Consensus for unreliable networks. Prepare, promise, accept, commit — with "only one value chosen" invariant.
Leader election, log replication, safety. The largest SpeckDL spec — demonstrates composition at scale.
Real-world state machine: create → assign → review → merge → close. 5 temporal verification conditions.
Role-based access with role addition, removal, and permission checks. One of 5 examples with zero TypeScript errors.
--target=z3 emits SMT-LIB2 that Z3 acceptsexamples/OAuth2AuthorizationCode.speckdlThe WAT/WASM generator was removed in favor of a proper IR → Rust → wasm-pack pipeline. No hand-rolled WASM text format; no magic.
# 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
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.
18 checks, one page. Free, pay what you want. The checklist is free under CC BY 4.0. Share and adapt it, with credit.