A hierarchical finite state machine (HSM) and workflow execution engine for MoonBit
| Package | Path | Purpose |
|---|---|---|
| Core | core/ | Transition engine, guards, and lifecycle hooks |
| HSM | hsm/ | Hierarchical states, event bubbling, and LCA resolution |
| Workflow | workflow/ | Sequential pipelines with retry policies |
| Timer | timer/ | Deterministic scheduler and timeout simulation |
| Export | export/ | Mermaid and PlantUML generator |
| Diagnostics | diagnostics/ | FSM/HSM/Workflow configuration checks |
| Trace | trace/ | Execution records and replay inspection |
| Benchmarks | benchmarks/ | Reproducible workload and release evidence |
| Examples | examples/ | Agent workflow and game state demos |
moon add Lyl66655/moonbit-workflow-engine@0.1.2enum State { Locked; Unlocked } derive(Eq, Debug)
enum Event { Coin; Push } derive(Eq, Debug)
struct Context { mut coins : Int } derive(Eq, Debug)
let ctx = { coins: 0 }
let fsm = @core.Machine::new(State::Locked, ctx)
fsm.add_transition(
State::Locked,
Event::Coin,
State::Unlocked,
cond=fn(c, _e) { c.coins < 5 },
action=fn(c, _e) { c.coins = c.coins + 1 },
)
fsm.add_transition(State::Unlocked, Event::Push, State::Locked)
let transitioned = fsm.send(Event::Coin)moon run examples/ai_agent_workflow/main[Agent] Task initialized.
[Agent] Planning steps...
[Agent] Step 1 executed.
[Agent] Workflow completed successfully.moon run examples/game_fsm/main[Game] Spawned boss at 100% health
[Game] Player attacking... boss health at 80%
[Game] Boss phase changed to Enragedmoon check
moon build
moon testmoon fmt --check
moon info
moon check --deny-warn
moon test --deny-warnA hierarchical finite state machine (HSM) and workflow execution engine for MoonBit