Skip to main content

mecha10_behavior_runtime/
lib.rs

1//! Mecha10 Behavior Runtime
2//!
3//! This crate provides a unified behavior composition system for robotics and AI.
4//! All behaviors implement the `BehaviorNode` trait with a simple tick-based interface.
5//!
6//! # Philosophy
7//!
8//! - **Behavior Logic** = Rust code (complex logic, high performance)
9//! - **Behavior Composition** = JSON config (simple orchestration, hot-reloadable)
10//! - **Configuration** = JSON with validation (parameters only)
11//!
12//! # Example
13//!
14//! ```rust
15//! use mecha10_behavior_runtime::{BehaviorNode, NodeStatus, Context};
16//! use async_trait::async_trait;
17//!
18//! #[derive(Debug)]
19//! struct MyBehavior;
20//!
21//! #[async_trait]
22//! impl BehaviorNode for MyBehavior {
23//!     async fn tick(&mut self, ctx: &Context) -> anyhow::Result<NodeStatus> {
24//!         // Your behavior logic here
25//!         Ok(NodeStatus::Success)
26//!     }
27//! }
28//! ```
29
30pub mod actions;
31mod behavior;
32mod composition;
33pub mod config;
34mod execution;
35mod loader;
36mod registry;
37mod status;
38
39// Re-export core types
40pub use actions::{register_builtin_actions, MoveNode, SensorCheckNode, TimerNode, WanderNode};
41pub use behavior::{BehaviorNode, BehaviorNodeExt, BoxedBehavior};
42pub use composition::{ParallelNode, ParallelPolicy, SelectOrNode, SequenceNode};
43pub use config::{
44    detect_project_root, get_current_environment, load_behavior_config, resolve_behavior_config_path,
45    validate_behavior_composition_json, validate_behavior_config, BehaviorConfig, CompositionConfig, NodeConfig,
46    NodeReference, ParallelPolicyConfig, ValidationResult,
47};
48pub use execution::{BehaviorExecutor, ExecutionContext, ExecutionStats};
49pub use loader::BehaviorLoader;
50pub use registry::NodeRegistry;
51pub use status::NodeStatus;
52
53// Re-export hot-reload module as public
54pub mod hot_reload;
55
56// Re-export mecha10-core Context
57pub use mecha10_core::Context;
58
59/// Prelude module for convenient imports
60pub mod prelude {
61    pub use crate::actions::{MoveNode, SensorCheckNode, TimerNode, WanderNode};
62    pub use crate::behavior::{BehaviorNode, BehaviorNodeExt, BoxedBehavior};
63    pub use crate::composition::{ParallelNode, ParallelPolicy, SelectOrNode, SequenceNode};
64    pub use crate::config::{BehaviorConfig, CompositionConfig, NodeConfig, NodeReference, ParallelPolicyConfig};
65    pub use crate::execution::{BehaviorExecutor, ExecutionContext, ExecutionStats};
66    pub use crate::loader::BehaviorLoader;
67    pub use crate::registry::NodeRegistry;
68    pub use crate::status::NodeStatus;
69    pub use async_trait::async_trait;
70    pub use mecha10_core::Context;
71}