本项目是基于 MoonBit 语言纯原生研发的高性能、零依赖 分层有限状态机(HSM)与工作流编排引擎。项目重点解决复杂系统状态管理的无序性与脆性问题,核心包含四大模块:支持父子继承、事件冒泡及 LCA(最近公共祖先)生命周期精确执行的 分层状态图引擎;支持任务分步重试与异常捕获的 顺序工作流管道;消除多线程竞态与测试不确定性的 虚拟时钟调度器;以及一键导出 Mermaid/PlantUML 可视
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
MoonBit StateMachine & Workflow Engine
An open-source MoonBit library for building hierarchical state machines, deterministic workflow pipelines, and event schedulers.
The project is organized around nine practical building blocks:
core/for the base state transition enginehsm/for hierarchical state machines with event bubbling and LCA-based lifecycle handlingworkflow/for sequential pipelines with retry and failure handlingtimer/for deterministic timeout and interval simulationexport/for Mermaid and PlantUML diagram exportdiagnostics/for configuration validation and actionable CI diagnosticstrace/for bounded execution traces, checkpoints, filtering, and replay cursorsbenchmarks/for deterministic logical-workload evidence without wall-clock noiseexamples/for executable demos and reference usageWhat it does
Repository Layout
core/hsm/workflow/timer/export/diagnostics/trace/benchmarks/examples/Quick Start
Installation
To add this package to your project, run:
Basic Usage
Running Examples
You can execute the provided demos directly from the command line:
Expected Output:
(Output may vary slightly based on the specific demo logic)
Expected Output:
For more details, see:
Quality Checks
To verify the repository locally, you can run the following standard MoonBit checks:
For stricter formatting, warnings, and public API checks:
To validate every supported compiler backend locally:
The benchmark package reports logical operations, successes, failures, and Markdown release evidence without wall-clock assertions. Use
@benchmarks.run_suite(100)and@benchmarks.summarize(results)in a MoonBit package to reproduce the release evidence.For production configuration checks, use
@diagnostics.validate_hsmto catch missing parents, parent cycles, inconsistent initial children, and initial-child cycles. For schedulers that accept user-provided intervals, preferschedule_periodic_checked; it returnsNoneand registers no timer when the interval is zero or negative. The legacyschedule_periodicmethod remains safe and treats such input as a one-shot event.On the current local toolchain, the standard and all-backend checks pass. Repository CI runs the standard workflow on Ubuntu, Windows, and macOS with MoonBit
0.10.7+bc794d341.Competition Notes
This repository is prepared for the OSC 2026 MoonBit track:
masterCurrent Status
.mbtifiles)The repository includes production-oriented engines, diagnostics, deterministic benchmark scenarios, executable examples, and boundary tests. The OSC guide uses 4k–10k effective MoonBit lines as a project-scale reference; this checkout has crossed the requested 3,000-line milestone and should continue toward the larger project-scale range before final acceptance.
License
Apache-2.0. See LICENSE.