|
| 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 | +} |
0 commit comments