maple_runtime/lib.rs
1//! # MAPLE Resonance Runtime
2//!
3//! The foundational AI framework for Mapleverse, Finalverse, and iBank.
4//!
5//! ## Overview
6//!
7//! MAPLE (Multi-Agent Platform for Learning and Evolution) is a world-class
8//! multi-agent AI framework built entirely on **Resonance Architecture** principles.
9//!
10//! Unlike traditional agent frameworks (Google A2A, Anthropic MCP) that treat
11//! agents as isolated processes communicating via messages, MAPLE treats every
12//! entity as a **Resonator** participating in continuous, stateful **resonance**.
13//!
14//! ## Key Features
15//!
16//! - **Resonance-Native**: Built from the ground up on presence → coupling → meaning → intent → commitment → consequence
17//! - **8 Architectural Invariants**: Compile-time and runtime enforced safety guarantees
18//! - **Attention Economics**: Prevents runaway resource consumption and coercive patterns
19//! - **Commitment Accountability**: Every consequential action is attributable and auditable
20//! - **Human Agency Protection**: Architectural, not policy-based, safeguards
21//!
22//! ## Architecture
23//!
24//! ```text
25//! Traditional: Agent A --[message]--> Agent B --[message]--> Agent C
26//!
27//! MAPLE: Resonator A <==[coupling]==> Resonator B <==[coupling]==> Resonator C
28//! ↑ ↑ ↑
29//! [presence] [presence] [presence]
30//! ↓ ↓ ↓
31//! [meaning] -----------------> [meaning] -----------------> [meaning]
32//! ↓ ↓ ↓
33//! [intent] ------------------> [commitment] --------------> [consequence]
34//! ```
35//!
36//! ## Quick Start
37//!
38//! ```no_run
39//! use maple_runtime::{MapleRuntime, config::RuntimeConfig, ResonatorSpec};
40//!
41//! #[tokio::main]
42//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
43//! // Bootstrap runtime
44//! let config = RuntimeConfig::default();
45//! let runtime = MapleRuntime::bootstrap(config).await?;
46//!
47//! // Register a Resonator
48//! let spec = ResonatorSpec::default();
49//! let resonator = runtime.register_resonator(spec).await?;
50//!
51//! // Resonator is now active and can participate in resonance
52//!
53//! // Shutdown gracefully
54//! runtime.shutdown().await?;
55//! Ok(())
56//! }
57//! ```
58//!
59//! ## Platform-Specific Configurations
60//!
61//! ### Mapleverse (Pure AI Agents)
62//!
63//! ```no_run
64//! use maple_runtime::{MapleRuntime, config::mapleverse_runtime_config};
65//!
66//! # #[tokio::main]
67//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
68//! let config = mapleverse_runtime_config();
69//! let runtime = MapleRuntime::bootstrap(config).await?;
70//! # Ok(())
71//! # }
72//! ```
73//!
74//! ### Finalverse (Human-AI Coexistence)
75//!
76//! ```no_run
77//! use maple_runtime::{MapleRuntime, config::finalverse_runtime_config};
78//!
79//! # #[tokio::main]
80//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
81//! let config = finalverse_runtime_config();
82//! let runtime = MapleRuntime::bootstrap(config).await?;
83//! # Ok(())
84//! # }
85//! ```
86//!
87//! ### iBank (Autonomous Finance)
88//!
89//! ```no_run
90//! use maple_runtime::{MapleRuntime, config::ibank_runtime_config};
91//!
92//! # #[tokio::main]
93//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
94//! let config = ibank_runtime_config();
95//! let runtime = MapleRuntime::bootstrap(config).await?;
96//! # Ok(())
97//! # }
98//! ```
99//!
100//! ## The 8 Canonical Invariants
101//!
102//! These invariants are **enforced at runtime** and violations are treated as system errors:
103//!
104//! 1. **Presence precedes meaning**: A Resonator must be present before it can form or receive meaning
105//! 2. **Meaning precedes intent**: Intent cannot be formed without sufficient meaning
106//! 3. **Intent precedes commitment**: Commitments cannot be created without stabilized intent
107//! 4. **Commitment precedes consequence**: No consequence may occur without an explicit commitment
108//! 5. **Coupling is bounded by attention**: Coupling strength cannot exceed available attention
109//! 6. **Safety overrides optimization**: Safety constraints take precedence over performance
110//! 7. **Human agency cannot be bypassed**: Human Resonators must always be able to disengage
111//! 8. **Failure must be explicit**: All failures must be surfaced, never hidden
112
113#![warn(missing_docs)]
114#![warn(clippy::all)]
115
116// Core modules
117pub mod types;
118pub mod runtime_core;
119pub mod fabrics;
120pub mod allocator;
121pub mod invariants;
122pub mod temporal;
123pub mod scheduler;
124pub mod config;
125pub mod telemetry;
126
127// Re-exports for convenience
128pub use runtime_core::{
129 MapleRuntime, ResonatorHandle, CouplingHandle, ScheduleHandle,
130 ResonatorSpec, ResonatorIdentitySpec, ContinuityProof,
131};
132
133pub use types::{
134 ResonatorId, ResonatorProfile, PresenceState, PresenceConfig,
135 Coupling, CouplingParams, CouplingScope, CouplingPersistence, SymmetryType,
136 AttentionBudget, AttentionBudgetSpec, AttentionClass,
137 Commitment, CommitmentContent, CommitmentStatus,
138 TemporalAnchor, LocalTimestamp,
139};
140
141pub use invariants::{ArchitecturalInvariant, InvariantViolation};
142
143// Error types
144pub use types::{
145 BootstrapError, ShutdownError, RegistrationError, ResumeError,
146 PresenceError, CouplingError, AttentionError, CommitmentError,
147 SchedulingError, TemporalError,
148};
149
150#[cfg(test)]
151mod tests {
152 use super::*;
153
154 #[tokio::test]
155 async fn test_runtime_bootstrap() {
156 let config = config::RuntimeConfig::default();
157 let runtime = MapleRuntime::bootstrap(config).await;
158 assert!(runtime.is_ok());
159 }
160
161 #[tokio::test]
162 async fn test_resonator_registration() {
163 let config = config::RuntimeConfig::default();
164 let runtime = MapleRuntime::bootstrap(config).await.unwrap();
165
166 let spec = ResonatorSpec::default();
167 let result = runtime.register_resonator(spec).await;
168 assert!(result.is_ok());
169 }
170
171 #[tokio::test]
172 async fn test_mapleverse_config() {
173 let config = config::mapleverse_runtime_config();
174 let runtime = MapleRuntime::bootstrap(config).await;
175 assert!(runtime.is_ok());
176 }
177
178 #[tokio::test]
179 async fn test_finalverse_config() {
180 let config = config::finalverse_runtime_config();
181 let runtime = MapleRuntime::bootstrap(config).await;
182 assert!(runtime.is_ok());
183 }
184
185 #[tokio::test]
186 async fn test_ibank_config() {
187 let config = config::ibank_runtime_config();
188 let runtime = MapleRuntime::bootstrap(config).await;
189 assert!(runtime.is_ok());
190 }
191
192 #[tokio::test]
193 async fn test_presence_signaling() {
194 let config = config::RuntimeConfig::default();
195 let runtime = MapleRuntime::bootstrap(config).await.unwrap();
196
197 let spec = ResonatorSpec::default();
198 let resonator = runtime.register_resonator(spec).await.unwrap();
199
200 // Wait a bit to avoid rate limiting from initialization
201 tokio::time::sleep(tokio::time::Duration::from_millis(1100)).await;
202
203 let presence = PresenceState::new();
204 let result = resonator.signal_presence(presence).await;
205 assert!(result.is_ok(), "Presence signaling failed: {:?}", result);
206 }
207
208 #[tokio::test]
209 async fn test_shutdown() {
210 let config = config::RuntimeConfig::default();
211 let runtime = MapleRuntime::bootstrap(config).await.unwrap();
212
213 let result = runtime.shutdown().await;
214 assert!(result.is_ok());
215 }
216}