mod catalog;
mod coherence;
mod handler;
mod mutations;
mod outcomes;
mod principal;
mod recovery;
mod sessions;
mod tasks;
mod tool_dispatch;
mod usage;
#[cfg(test)]
mod tests;
use std::sync::Arc;
use rmcp::{
transport::{async_rw::AsyncRwTransport, stdio},
ServiceExt,
};
use tokio::sync::Mutex;
use tracing::info;
use crate::runtime::{configured_shell_runtime, ShellRuntime};
use crate::state::task_state::TaskRegistry;
use crate::state::BashState;
use sessions::SessionRegistry;
pub use sessions::SessionIsolation;
pub type SharedBashState = Arc<Mutex<Option<BashState>>>;
#[derive(Clone)]
pub struct WinxService {
sessions: Arc<Mutex<SessionRegistry>>,
tasks: Arc<Mutex<TaskRegistry>>,
root_bootstrap: Arc<Mutex<()>>,
shell_runtime: Arc<dyn ShellRuntime>,
mutations: mutations::MutationCoordinator,
pub version: String,
isolation: SessionIsolation,
}
pub async fn start_winx_server() -> Result<(), Box<dyn std::error::Error>> {
start_winx_server_with_runtime(configured_shell_runtime().await?).await
}
pub async fn start_winx_server_with_runtime(
runtime: Arc<dyn ShellRuntime>,
) -> Result<(), Box<dyn std::error::Error>> {
info!("Starting Winx MCP Server");
let service = WinxService::with_runtime(SessionIsolation::Lenient, runtime);
let (stdin, stdout) = stdio();
let transport = AsyncRwTransport::new_server(stdin, stdout);
let server = service.serve(transport).await?;
server.waiting().await?;
Ok(())
}