diff --git a/hive-ag3nt/src/mcp.rs b/hive-ag3nt/src/mcp.rs index bced8cc..2df48a2 100644 --- a/hive-ag3nt/src/mcp.rs +++ b/hive-ag3nt/src/mcp.rs @@ -1383,20 +1383,13 @@ pub fn render_claude_config(agent_binary: &str, socket: &std::path::Path) -> Str "env": {} }), ); - // Auto-inject HYPERHIVE_STATE_DIR so extra MCP servers can resolve the - // 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() { + for (name, spec) in load_extra_mcp() { if name == SERVER_NAME { tracing::warn!( "extra MCP server name `{SERVER_NAME}` collides with the built-in surface; ignoring", ); continue; } - spec.env - .entry("HYPERHIVE_STATE_DIR".to_owned()) - .or_insert_with(|| state_dir.display().to_string()); servers.insert( name, serde_json::json!({ diff --git a/hive-ag3nt/src/paths.rs b/hive-ag3nt/src/paths.rs index 7564ebf..0774f75 100644 --- a/hive-ag3nt/src/paths.rs +++ b/hive-ag3nt/src/paths.rs @@ -1,6 +1,6 @@ //! 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. //! //! Both paths can be overridden via env vars (`HYPERHIVE_STATE_DIR`, @@ -8,17 +8,24 @@ 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` -/// first (always set by the meta flake to `/agents/{label}/state`); falls back -/// to the same pattern derived from `HIVE_LABEL` for dev/test environments -/// where the env var may not be set. +/// first; falls back to `/agents/{label}/state` for sub-agents or `/state` for +/// the manager / any unrecognised label. #[must_use] pub fn state_dir() -> PathBuf { if let Some(p) = std::env::var_os("HYPERHIVE_STATE_DIR") { return PathBuf::from(p); } let label = std::env::var("HIVE_LABEL").unwrap_or_default(); - PathBuf::from(format!("/agents/{label}/state")) + if label == MANAGER_NAME || label.is_empty() { + PathBuf::from("/state") + } else { + PathBuf::from(format!("/agents/{label}/state")) + } } /// Claude credentials directory for the current agent. Always `/root/.claude` diff --git a/hive-c0re/src/meta.rs b/hive-c0re/src/meta.rs index 48f4fde..6774e66 100644 --- a/hive-c0re/src/meta.rs +++ b/hive-c0re/src/meta.rs @@ -273,18 +273,11 @@ fn render_flake( name = name; 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 = { HIVE_PORT = toString port; HIVE_LABEL = name; HIVE_DASHBOARD_PORT = toString dashboardPort; HIVE_OPERATOR_PRONOUNS = operatorPronouns; - HYPERHIVE_STATE_DIR = "/agents/${name}/state"; }; } ];