Phase 4: manager socket + manager_server with privileged tool surface

This commit is contained in:
müde 2026-05-14 22:35:08 +02:00
parent 4f191b2e43
commit aa67e5a481
6 changed files with 188 additions and 15 deletions

View file

@ -1,5 +1,6 @@
//! Runtime state shared between the host admin socket and the per-agent
//! sockets: the broker plus a map of `name -> AgentSocket`.
//! Runtime state + config shared between the host admin socket, the manager
//! socket, and the per-agent sockets: the broker, configured `agent_flake`,
//! and the map of registered agent sockets.
use std::collections::HashMap;
use std::path::{Path, PathBuf};
@ -11,17 +12,20 @@ use crate::agent_server::{self, AgentSocket};
use crate::broker::Broker;
const AGENT_RUNTIME_ROOT: &str = "/run/hyperhive/agents";
const MANAGER_RUNTIME_ROOT: &str = "/run/hyperhive/manager";
pub struct Coordinator {
pub broker: Arc<Broker>,
pub agent_flake: String,
agents: Mutex<HashMap<String, AgentSocket>>,
}
impl Coordinator {
pub fn open(db_path: &Path) -> Result<Self> {
pub fn open(db_path: &Path, agent_flake: String) -> Result<Self> {
let broker = Broker::open(db_path).context("open broker")?;
Ok(Self {
broker: Arc::new(broker),
agent_flake,
agents: Mutex::new(HashMap::new()),
})
}
@ -34,7 +38,8 @@ impl Coordinator {
std::fs::create_dir_all(&agent_dir)
.with_context(|| format!("create agent dir {}", agent_dir.display()))?;
let socket_path = Self::socket_path(name);
let socket = agent_server::start(name.to_owned(), socket_path, self.broker.clone()).await?;
let socket =
agent_server::start(name.to_owned(), socket_path, self.broker.clone()).await?;
self.agents.lock().unwrap().insert(name.to_owned(), socket);
Ok(agent_dir)
}
@ -53,4 +58,12 @@ impl Coordinator {
pub fn socket_path(name: &str) -> PathBuf {
Self::agent_dir(name).join("mcp.sock")
}
pub fn manager_dir() -> PathBuf {
PathBuf::from(MANAGER_RUNTIME_ROOT)
}
pub fn manager_socket_path() -> PathBuf {
Self::manager_dir().join("mcp.sock")
}
}