Metakit / Verify a state machine
Prove only what changed since the last run
Proving every transition on every CI run spends solver time on transitions nobody touched. Provide an Artifact.EvidenceStore and Prove.machine and Prove.fn keep each proof under a key made from the transition's or function's contract hash (its body, its ensures, the Schemas it assumes and the hashes of what it calls), the solver's name, encoding and version, MetaKit's version and timeoutMs. A later run with the same key takes the proof from the store and marks the entry reused; a transition whose key changed, because it or something it calls changed, is proved again. EvidenceStore.layerFileSystem(directory) keeps one file per proof and reads files through Effect's FileSystem, which @effect/platform-node provides:
import { Layer } from 'effect'
import { NodeServices } from '@effect/platform-node'
import * as Artifact from '@doeixd/metakit/artifact'
const store = Artifact.EvidenceStore.layerFileSystem('.metakit/evidence').pipe(
Layer.provide(NodeServices.layer),
)
const kept = await Effect.runPromise(Prove.machine(AccountMachine).pipe(Effect.provide(store)))
// kept.entries[i].reused: true for a proof the store already heldOnly a proof is kept. A transition left undecided (a timeout included) or refuted is asked again on every run, so a stored answer never stands in for a pass. A solver backend that sets no version keeps nothing. EvidenceStore.layerMemory keeps proofs for one process; EvidenceStore.layer takes any Effect KeyValueStore, so the directory can be one your CI caches between runs. On this repository's examples/metakit, proving its nine machines and one function took 1.7–1.9 s cold and 0.27–0.30 s warm, Z3 asked 10 times and then 3 (the arms left undecided).