matrix: hive-matrix-mcp crate (daemon+stdio bridge) + harness wiring (#548 phase 3)
This commit is contained in:
parent
23ed124881
commit
e6c53045ad
16 changed files with 3310 additions and 35 deletions
65
hive-matrix-mcp/src/paths.rs
Normal file
65
hive-matrix-mcp/src/paths.rs
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
//! Per-agent filesystem paths used by both `hive-matrix-daemon` and the
|
||||
//! stdio MCP bridge.
|
||||
//!
|
||||
//! All paths are overridable via env vars for dev / test scenarios and
|
||||
//! to let the harness point the daemon at non-default locations when
|
||||
//! the operator overrides `hyperhive.matrix.*` options.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Default homeserver URL when `HIVE_MATRIX_URL` isn't set. Tuwunel
|
||||
/// (the local hive-matrix container) listens on `localhost:8008` by
|
||||
/// default; shared host netns means every agent container resolves
|
||||
/// `localhost` to the same machine.
|
||||
pub const DEFAULT_HOMESERVER: &str = "http://localhost:8008";
|
||||
|
||||
/// Default unix socket path the daemon listens on inside the agent
|
||||
/// container. The stdio MCP bridge `connect()`s here on every tool call.
|
||||
/// `/run/hive-matrix.sock` is a tmpfs path that disappears on container
|
||||
/// restart — fine, because the daemon recreates the socket on its own
|
||||
/// boot.
|
||||
pub const DEFAULT_DAEMON_SOCKET: &str = "/run/hive-matrix.sock";
|
||||
|
||||
/// Resolve the matrix access-token file path. Override via
|
||||
/// `HIVE_MATRIX_TOKEN_FILE`; default is `<HYPERHIVE_STATE_DIR>/matrix-token`,
|
||||
/// the path `hive-c0re::matrix::ensure_user_for` writes to on agent
|
||||
/// account provisioning.
|
||||
#[must_use]
|
||||
pub fn token_file() -> PathBuf {
|
||||
if let Some(p) = std::env::var_os("HIVE_MATRIX_TOKEN_FILE") {
|
||||
return PathBuf::from(p);
|
||||
}
|
||||
let state_dir = std::env::var("HYPERHIVE_STATE_DIR").unwrap_or_default();
|
||||
PathBuf::from(format!("{state_dir}/matrix-token"))
|
||||
}
|
||||
|
||||
/// Resolve the homeserver URL. Override via `HIVE_MATRIX_URL`; default
|
||||
/// is the in-container `localhost:8008` tuwunel.
|
||||
#[must_use]
|
||||
pub fn homeserver_url() -> String {
|
||||
std::env::var("HIVE_MATRIX_URL").unwrap_or_else(|_| DEFAULT_HOMESERVER.to_owned())
|
||||
}
|
||||
|
||||
/// Resolve the daemon's unix socket path. Override via
|
||||
/// `HIVE_MATRIX_SOCKET`; default is `/run/hive-matrix.sock`.
|
||||
#[must_use]
|
||||
pub fn daemon_socket() -> PathBuf {
|
||||
std::env::var_os("HIVE_MATRIX_SOCKET").map_or_else(|| PathBuf::from(DEFAULT_DAEMON_SOCKET), PathBuf::from)
|
||||
}
|
||||
|
||||
/// Persistent sqlite store directory for matrix-sdk's state (event
|
||||
/// cache, devices, etc.). Lives under the per-agent state dir so it
|
||||
/// survives container restart but gets wiped on `destroy --purge`.
|
||||
#[must_use]
|
||||
pub fn matrix_state_dir() -> PathBuf {
|
||||
let state_dir = std::env::var("HYPERHIVE_STATE_DIR").unwrap_or_default();
|
||||
PathBuf::from(format!("{state_dir}/matrix-sdk-state"))
|
||||
}
|
||||
|
||||
/// Hyperhive control socket — the daemon writes wake signals here so
|
||||
/// the harness drives a new claude turn on incoming matrix events.
|
||||
/// Mirrors the path `forge_notify` writes to.
|
||||
#[must_use]
|
||||
pub fn hyperhive_socket() -> PathBuf {
|
||||
std::env::var_os("HIVE_CONTROL_SOCKET").map_or_else(|| PathBuf::from("/run/hive/mcp.sock"), PathBuf::from)
|
||||
}
|
||||
Loading…
Reference in a new issue