Skip to content

Commit 11cd5f0

Browse files
authored
feat(M1.3.2): Task 1 - Create state_machine module stub with MimiState enum and StateManager (#209)
1 parent a0d0ee2 commit 11cd5f0

4 files changed

Lines changed: 3166 additions & 0 deletions

File tree

crates/mimi-core/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ pub mod error;
88
pub mod message;
99
pub mod routing;
1010
pub mod serialization;
11+
pub mod state_machine;
1112

1213
pub use error::{Error, Result};
1314
pub use routing::{MessageRouter, RoutingError, Topic, TopicPattern};
1415
pub use serialization::{MessageSerializer, SerializationError};
16+
pub use state_machine::{MimiState, StateManager};
1517

1618
/// Core version
1719
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//! Mimi State Machine FSM
2+
//!
3+
//! Implements the 10-state finite state machine for Mimi orchestrator core lifecycle.
4+
//! Provides async execution, guard conditions, error recovery, and message bus integration.
5+
6+
use std::sync::{Arc, Mutex};
7+
8+
/// Mimi system states
9+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10+
pub enum MimiState {
11+
/// System idle, waiting for input
12+
Idle,
13+
/// Listening for user commands via Zenoh
14+
Listening,
15+
/// Processing intent classification
16+
Processing,
17+
/// Executing task via workers
18+
Executing,
19+
/// Generating response via Liliana
20+
Responding,
21+
/// Degraded mode (partial functionality)
22+
Degraded,
23+
/// Recovering from failure
24+
Recovering,
25+
/// Component failure detected
26+
FailedComponent,
27+
/// Critical error requiring intervention
28+
CriticalError,
29+
/// System shutdown in progress
30+
Shutdown,
31+
}
32+
33+
/// State manager with thread-safe access
34+
pub struct StateManager {
35+
state: Arc<Mutex<MimiState>>,
36+
}
37+
38+
impl StateManager {
39+
/// Create new state manager starting in Idle state
40+
pub fn new() -> Self {
41+
Self {
42+
state: Arc::new(Mutex::new(MimiState::Idle)),
43+
}
44+
}
45+
46+
/// Get current state
47+
pub fn current_state(&self) -> MimiState {
48+
*self.state.lock().unwrap()
49+
}
50+
}
51+
52+
impl Default for StateManager {
53+
fn default() -> Self {
54+
Self::new()
55+
}
56+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//! State Machine Unit Tests
2+
3+
use mimi_core::state_machine::{MimiState, StateManager};
4+
5+
#[test]
6+
fn test_initial_state_is_idle() {
7+
// This will fail because StateManager doesn't exist yet
8+
let manager = StateManager::new();
9+
assert_eq!(manager.current_state(), MimiState::Idle);
10+
}

0 commit comments

Comments
 (0)