Compare commits

..

No commits in common. "d0b65b1f4768ac110b73903b3c9dbd0a2de72f98" and "9cbb05bb862aa4fa60b488c6638455c0849a7887" have entirely different histories.

3 changed files with 13 additions and 20 deletions

View file

@ -1383,20 +1383,13 @@ pub fn render_claude_config(agent_binary: &str, socket: &std::path::Path) -> Str
"env": {} "env": {}
}), }),
); );
// Auto-inject HYPERHIVE_STATE_DIR so extra MCP servers can resolve the for (name, spec) in load_extra_mcp() {
// agent's durable state dir without the agent author hard-coding it.
// User-supplied env takes precedence — we only fill in the missing key.
let state_dir = crate::paths::state_dir();
for (name, mut spec) in load_extra_mcp() {
if name == SERVER_NAME { if name == SERVER_NAME {
tracing::warn!( tracing::warn!(
"extra MCP server name `{SERVER_NAME}` collides with the built-in surface; ignoring", "extra MCP server name `{SERVER_NAME}` collides with the built-in surface; ignoring",
); );
continue; continue;
} }
spec.env
.entry("HYPERHIVE_STATE_DIR".to_owned())
.or_insert_with(|| state_dir.display().to_string());
servers.insert( servers.insert(
name, name,
serde_json::json!({ serde_json::json!({

View file

@ -1,6 +1,6 @@
//! Per-agent path resolution for state and credential directories. //! Per-agent path resolution for state and credential directories.
//! //!
//! All agents (including the manager "hm1nd") use `/agents/{label}/state`. //! Manager ("hm1nd") keeps `/state`; sub-agents use `/agents/{label}/state`.
//! Claude credentials are always at `/root/.claude` for all agents. //! Claude credentials are always at `/root/.claude` for all agents.
//! //!
//! Both paths can be overridden via env vars (`HYPERHIVE_STATE_DIR`, //! Both paths can be overridden via env vars (`HYPERHIVE_STATE_DIR`,
@ -8,17 +8,24 @@
use std::path::PathBuf; use std::path::PathBuf;
/// Container label of the manager. Sub-agents get `/agents/{label}/state`;
/// the manager keeps `/state`. Must match `hive-c0re::lifecycle::MANAGER_NAME`.
pub const MANAGER_NAME: &str = "hm1nd";
/// Durable state directory for the current agent. Reads `HYPERHIVE_STATE_DIR` /// Durable state directory for the current agent. Reads `HYPERHIVE_STATE_DIR`
/// first (always set by the meta flake to `/agents/{label}/state`); falls back /// first; falls back to `/agents/{label}/state` for sub-agents or `/state` for
/// to the same pattern derived from `HIVE_LABEL` for dev/test environments /// the manager / any unrecognised label.
/// where the env var may not be set.
#[must_use] #[must_use]
pub fn state_dir() -> PathBuf { pub fn state_dir() -> PathBuf {
if let Some(p) = std::env::var_os("HYPERHIVE_STATE_DIR") { if let Some(p) = std::env::var_os("HYPERHIVE_STATE_DIR") {
return PathBuf::from(p); return PathBuf::from(p);
} }
let label = std::env::var("HIVE_LABEL").unwrap_or_default(); let label = std::env::var("HIVE_LABEL").unwrap_or_default();
if label == MANAGER_NAME || label.is_empty() {
PathBuf::from("/state")
} else {
PathBuf::from(format!("/agents/{label}/state")) PathBuf::from(format!("/agents/{label}/state"))
}
} }
/// Claude credentials directory for the current agent. Always `/root/.claude` /// Claude credentials directory for the current agent. Always `/root/.claude`

View file

@ -273,18 +273,11 @@ fn render_flake(
name = name; name = name;
email = "${name}@hyperhive"; email = "${name}@hyperhive";
}; };
# Container-wide env: every service + co-process daemon can
# resolve the agent's durable state dir without hard-coding it.
environment.variables = {
HIVE_LABEL = name;
HYPERHIVE_STATE_DIR = "/agents/${name}/state";
};
systemd.services.${service}.environment = { systemd.services.${service}.environment = {
HIVE_PORT = toString port; HIVE_PORT = toString port;
HIVE_LABEL = name; HIVE_LABEL = name;
HIVE_DASHBOARD_PORT = toString dashboardPort; HIVE_DASHBOARD_PORT = toString dashboardPort;
HIVE_OPERATOR_PRONOUNS = operatorPronouns; HIVE_OPERATOR_PRONOUNS = operatorPronouns;
HYPERHIVE_STATE_DIR = "/agents/${name}/state";
}; };
} }
]; ];