Serializable behavior-tree assets, deterministic execution, and regression analysis for MoonBit.
文本 DSL / Builder
↓
解析、重复 ID 检查、缺失引用检查、环检测、lint
↓
显式 BehaviorTree 数据模型与确定性 tick
↓
trace digest / timeline / coverage / matrix / profile / audit
↓
asset diff / baseline / catalog / canonical fingerprint
↓
Graphviz DOT / Mermaid / Markdown 验收报告| 对比维度 | MoonBTKit | mhh12345678/behavior_tree 公开定位 |
|---|---|---|
| 核心用户 | 维护行为树文本资产、测试基线和验收报告的工具开发者 | 在宿主程序中直接组装并调度行为节点的应用开发者 |
| 建模核心 | 可序列化 DSL、显式节点数据模型、Builder | 闭包节点与 Builder |
| 主要处理链 | 解析、静态校验、确定性执行、回归分析、报告导出 | 运行时执行、事件路由、多树和预算调度 |
| 回归证据 | 固定 fixture、trace digest、coverage、输入 matrix、profile、综合 audit | 场景运行、metrics、trace、benchmark |
| 交付物 | 可版本比较的 DSL、DOT、Mermaid、Markdown 报告 | 可嵌入宿主应用的运行时对象和调度结果 |
| 明确不做 | EventBus、EventRouter、多 NPC Scheduler、宿主闭包脚本 | 不以 MoonBTKit 的 DSL roundtrip 和多格式报告链为核心 |
| 项目 | 状态 |
|---|---|
| 包名 | liu666789987/moonbtkit |
| 版本 | 0.1.6 |
| MoonBit 实现 | 核心功能均由 MoonBit 实现 |
| 代码规模 | 7,700 余行有效 MoonBit 代码 |
| 测试 | 164 个测试,覆盖核心执行、严格 DSL、类型无损 roundtrip、错误与边界、资产差异、回归基线、目录审计、规范指纹、fixture、可视化和白盒 helper |
| 示例 | cmd/main、examples/basic、examples/export 均可运行 |
| CI | GitHub Actions 覆盖格式、零警告检查、构建、测试、JS 目标、示例和包清单 |
| 许可证 | Apache-2.0 |
moon add liu666789987/moonbtkitimport {
"liu666789987/moonbtkit",
}let source =
"root root\n" +
"blackboard enemy_visible true\n" +
"blackboard ammo 2\n" +
"selector root engage patrol\n" +
"sequence engage see_enemy has_ammo aim fire\n" +
"condition see_enemy enemy_visible eq true\n" +
"condition has_ammo ammo gt 0\n" +
"action aim aim_weapon running,success mode=aiming\n" +
"action fire fire_weapon success ammo=1 result=hit\n" +
"action patrol patrol_area success mode=patrol\n"
match @moonbtkit.parse_dsl(source) {
Ok(doc) => {
let engine = @moonbtkit.new_engine(doc.tree, blackboard=doc.blackboard)
match engine.run_until_done(max_ticks=6) {
Ok(result) => println(result.summary())
Err(err) => println(err.message())
}
}
Err(err) => println(err.message())
}moon run cmd/main
moon run examples/basic
moon run examples/export| 分类 | API |
|---|---|
| 黑板 | new_blackboard, blackboard_from_pairs, Blackboard::set, Blackboard::get_* |
| 节点 | node, sequence, selector, condition, set_value, wait, action_success |
| 树 | new_tree, tree_from_nodes, BehaviorTree::add, BehaviorTree::validate |
| 引擎 | new_engine, BtEngine::tick, BtEngine::run_until_done, BtEngine::trace_digest |
| DSL | parse_dsl, parse_tree_dsl, serialize_tree, parse_blackboard_dsl |
| 分析 | analyze_tree, lint_tree, tree_markdown_report, smoke_run |
| 测试 | run_case, run_cases, fixture_cases, recipe_cases, assert_* |
| 示例 | fixture_catalog, run_fixture, recipe_catalog, run_recipe_catalog |
| Timeline | timeline_from_trace, timeline_text, summarize_trace, compact_trace |
| Visualization | tree_to_dot, tree_to_mermaid, trace_to_mermaid_sequence, visualization_bundle |
| Coverage | coverage_from_trace, fixture_coverage, fixture_catalog_coverage |
| Matrix | run_matrix, boolean_matrix, int_sweep_matrix, fixture_matrix_report |
| Profile | profile_trace, profile_fixture, fixture_profile_report, profile_markdown |
| Audit | audit_fixture, audit_fixture_catalog, audit_catalog_markdown |
| Asset Diff | diff_trees, diff_dsl, TreeDiff::compatibility, TreeDiff::markdown |
| Baseline | capture_baseline, verify_baseline, regression_baseline, BaselineReport::markdown |
| Asset Catalog | asset_spec, audit_asset, audit_asset_catalog, AssetCatalogReport::markdown |
| Asset Identity | canonicalize_dsl, asset_fingerprint, inspect_asset, AssetIdentity::markdown |
moon fmt --check
moon check
moon build
moon test
moon check --deny-warn
moon test --deny-warn
moon check --target js
moon build --target js
moon test --target js
moon run cmd/main
moon run examples/basic
moon run examples/export
moon info
moon package --listpub(all) struct AssetCatalogReport {
name : String
assets : Array[AssetReport]
duplicate_names : Array[String]
} derive(Eq, Debug)pub(all) struct AuditReport {
name : String
run : RunSummary
coverage : TraceCoverage
profile : ProfileReport
lint : LintReport
visual_assets : Int
} derive(Eq, Debug)pub(all) struct BaselineReport {
name : String
expected_status : BtStatus
actual_status : BtStatus
expected_digest : String
actual_digest : String
expected_ticks : Int
actual_ticks : Int
minimum_coverage : Int
actual_coverage : Int
status_matches : Bool
digest_matches : Bool
ticks_match : Bool
coverage_meets : Bool
} derive(Eq, Debug)pub(all) struct BtEngine {
tree : BehaviorTree
blackboard : Blackboard
config : TickConfig
tick_count : Int
memory : Array[NodeMemory]
trace : Array[TickEvent]
} derive(Eq, Debug)pub(all) struct CaseReport {
name : String
parsed : Bool
run : RunSummary
assertions : AssertionReport
} derive(Eq, Debug)pub(all) struct CaseSpec {
name : String
dsl : String
expectation : CaseExpectation
} derive(Eq, Debug)pub(all) struct DslDocument {
tree : BehaviorTree
blackboard : Blackboard
warnings : Array[String]
} derive(Eq, Debug)pub(all) struct ProfileReport {
name : String
profiles : Array[NodeProfile]
total_events : Int
total_ticks : Int
} derive(Eq, Debug)pub(all) struct RecipeBundle {
name : String
description : String
tree : BehaviorTree
blackboard : Blackboard
expected : BtStatus
max_ticks : Int
} derive(Eq, Debug)fn TreeBuilder::action(self : TreeBuilder, id : String, name : String, statuses : Array[BtStatus], writes? : Array[(String, BtValue)]) -> Result[TreeBuilder, BtError]fn TreeBuilder::condition(self : TreeBuilder, id : String, key : String, op : CompareOp, expected : BtValue) -> Result[TreeBuilder, BtError]fn TreeBuilder::decorator(self : TreeBuilder, id : String, kind : NodeKind, child : String) -> Result[TreeBuilder, BtError]fn TreeBuilder::emit(self : TreeBuilder, id : String, label : String) -> Result[TreeBuilder, BtError]fn TreeBuilder::parallel_all(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::parallel_any(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::selector(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::sequence(self : TreeBuilder, id : String, children : Array[String]) -> Result[TreeBuilder, BtError]fn TreeBuilder::set(self : TreeBuilder, id : String, key : String, value : BtValue) -> Result[TreeBuilder, BtError]fn assert_board_value(board : Array[(String, BtValue)], key : String, value : BtValue) -> BtAssertionfn boolean_matrix(name : String, source : String, key : String, true_expected : BtStatus, false_expected : BtStatus, max_ticks? : Int) -> MatrixReportfn capture_baseline(name : String, source : String, max_ticks? : Int) -> Result[RegressionBaseline, BtError]fn int_sweep_matrix(name : String, source : String, key : String, values : Array[Int], expected : BtStatus, max_ticks? : Int) -> MatrixReportfn regression_baseline(name : String, expected_status : BtStatus, expected_digest : String, expected_ticks : Int, minimum_coverage : Int, max_ticks? : Int) -> RegressionBaselinefn smoke_run(name : String, tree : BehaviorTree, board : Blackboard, expected : BtStatus, max_ticks? : Int) -> RunSummaryfn variant(name : String, overrides : Array[(String, BtValue)], expected? : BtStatus, max_ticks? : Int) -> VariantSpecfn verify_baseline(source : String, baseline : RegressionBaseline) -> Result[BaselineReport, BtError]Serializable behavior-tree assets, deterministic execution, and regression analysis for MoonBit.