Skip to content

Foundry vocabulary

crucible/state names its lifecycle after a foundry: you Forge a definition, Quench it solid, Cast instances, and Fire events at them. The metaphor is load-bearing: each verb marks a real boundary between mutable authoring, an immutable definition, and a running instance.

VerbSignature (shape)What it doesWhen to call it
ForgeForge[S,E,C]("name") *BuilderOpens a mutable builder. Declare states, transitions, and register named behavior (.Guard, .Action, .Reducer, .Service, .Actor). For the common string-keyed case, ForgeFor[C]("name") fixes S and E to string so you spell only the context type.Once, at the start of defining a machine.
Temperb.Temper() []DiagnosticOptional, non-failing lint/diagnostics pass over the builder. Returns findings; never panics, never freezes.Before Quench, when you want to surface reachability or wiring warnings.
Quenchb.Quench() *MachineFreezes the builder into an immutable *Machine. Panics on misconfiguration (unknown states, dangling refs).Once, when the definition is complete. The *Machine is safe to share across goroutines.
Castm.Cast(entity, opts...) *InstanceCreates a running *Instance seeded with your context entity (by value).Per entity you want to track. Cheap; cast freely.
Fireinst.Fire(ctx, event, opts...) FireResultAdvances the instance. Returns FireResult{NewState, Effects, Trace, Err}. Performs no IO; effects are data.Every time an event arrives.

Not everything earns a metaphor. These read literally:

VerbSignature (shape)What it does
Verifym.Verify(state, entity, opts...) errorChecks that an externally-built entity is legally in a given state, running the relevant requirements. Fail-fast by default; Aggregate() collects all violations.
PlanPathm.PlanPath(from, to, entity, opts...) ([]E, error)Computes a sequence of events that would drive an entity from one state to another.
Trace(field on FireResult)The ordered record of what happened during a Fire: transitions, guards, regions.
ToJSON / LoadFromJSONm.ToJSON() / LoadFromJSON[S,E,C](b)Round-trip the canonical IR losslessly to and from JSON.
ToMermaid / ToDOTm.ToMermaid() / m.ToDOT()Render the machine as a diagram for docs or inspection.

A typical session uses Forge → (Temper) → Quench once, then Cast and Fire many times, with Verify at the edges where entities cross trust boundaries.