//! MCP (Model Context Protocol) infrastructure for Wraith. //! //! Provides programmatic access to active sessions so AI tools running in the //! copilot panel can read terminal output, execute commands, and enumerate //! sessions. pub mod scrollback; pub mod server; pub mod error_watcher; use std::sync::Arc; use dashmap::DashMap; use crate::mcp::scrollback::ScrollbackBuffer; /// Registry of scrollback buffers keyed by session ID. /// Shared between SSH/PTY output loops (writers) and MCP tools (readers). #[derive(Clone)] pub struct ScrollbackRegistry { buffers: DashMap>, } impl ScrollbackRegistry { pub fn new() -> Self { Self { buffers: DashMap::new() } } /// Create and register a new scrollback buffer for a session. pub fn create(&self, session_id: &str) -> Arc { let buf = Arc::new(ScrollbackBuffer::new()); self.buffers.insert(session_id.to_string(), buf.clone()); buf } /// Get the scrollback buffer for a session. pub fn get(&self, session_id: &str) -> Option> { self.buffers.get(session_id).map(|entry| entry.clone()) } /// Remove a session's scrollback buffer. pub fn remove(&self, session_id: &str) { self.buffers.remove(session_id); } }