Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/mimi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ pub mod error;
pub mod message;
pub mod routing;
pub mod serialization;
pub mod state_machine;

pub use error::{Error, Result};
pub use routing::{MessageRouter, RoutingError, Topic, TopicPattern};
pub use serialization::{MessageSerializer, SerializationError};
pub use state_machine::{MimiState, StateManager};

/// Core version
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
56 changes: 56 additions & 0 deletions crates/mimi-core/src/state_machine.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//! Mimi State Machine FSM
//!
//! Implements the 10-state finite state machine for Mimi orchestrator core lifecycle.
//! Provides async execution, guard conditions, error recovery, and message bus integration.

use std::sync::{Arc, Mutex};

/// Mimi system states
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MimiState {
/// System idle, waiting for input
Idle,
/// Listening for user commands via Zenoh
Listening,
/// Processing intent classification
Processing,
/// Executing task via workers
Executing,
/// Generating response via Liliana
Responding,
/// Degraded mode (partial functionality)
Degraded,
/// Recovering from failure
Recovering,
/// Component failure detected
FailedComponent,
/// Critical error requiring intervention
CriticalError,
/// System shutdown in progress
Shutdown,
}

/// State manager with thread-safe access
pub struct StateManager {
state: Arc<Mutex<MimiState>>,
}

impl StateManager {
/// Create new state manager starting in Idle state
pub fn new() -> Self {
Self {
state: Arc::new(Mutex::new(MimiState::Idle)),
}
}

/// Get current state
pub fn current_state(&self) -> MimiState {
*self.state.lock().unwrap()
}
}

impl Default for StateManager {
fn default() -> Self {
Self::new()
}
}
10 changes: 10 additions & 0 deletions crates/mimi-core/tests/state_machine_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! State Machine Unit Tests

use mimi_core::state_machine::{MimiState, StateManager};

#[test]
fn test_initial_state_is_idle() {
// This will fail because StateManager doesn't exist yet
let manager = StateManager::new();
assert_eq!(manager.current_state(), MimiState::Idle);
}
Loading
Loading