From f21ae1ff98ae2b1c0f36f9b85365ea5bf19f5616 Mon Sep 17 00:00:00 2001 From: damocles Date: Wed, 20 May 2026 12:46:41 +0200 Subject: [PATCH 1/2] inject HYPERHIVE_STATE_DIR into container env + extra MCP server envs --- hive-ag3nt/src/mcp.rs | 9 ++++++++- hive-c0re/src/meta.rs | 11 +++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/hive-ag3nt/src/mcp.rs b/hive-ag3nt/src/mcp.rs index 2df48a2..bced8cc 100644 --- a/hive-ag3nt/src/mcp.rs +++ b/hive-ag3nt/src/mcp.rs @@ -1383,13 +1383,20 @@ pub fn render_claude_config(agent_binary: &str, socket: &std::path::Path) -> Str "env": {} }), ); - for (name, spec) in load_extra_mcp() { + // 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() { 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-c0re/src/meta.rs b/hive-c0re/src/meta.rs index 6774e66..c2d67fa 100644 --- a/hive-c0re/src/meta.rs +++ b/hive-c0re/src/meta.rs @@ -273,11 +273,22 @@ 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 = + if isManager then "/state" + else "/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 = + if isManager then "/state" + else "/agents/${name}/state"; }; } ]; From d0b65b1f4768ac110b73903b3c9dbd0a2de72f98 Mon Sep 17 00:00:00 2001 From: damocles Date: Wed, 20 May 2026 13:24:18 +0200 Subject: [PATCH 2/2] fix: manager uses /agents/hm1nd/state, not /state, for HYPERHIVE_STATE_DIR --- hive-ag3nt/src/paths.rs | 17 +++++------------ hive-c0re/src/meta.rs | 8 ++------ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/hive-ag3nt/src/paths.rs b/hive-ag3nt/src/paths.rs index 0774f75..7564ebf 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. //! -//! Manager ("hm1nd") keeps `/state`; sub-agents use `/agents/{label}/state`. +//! All agents (including the manager "hm1nd") 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,24 +8,17 @@ 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; falls back to `/agents/{label}/state` for sub-agents or `/state` for -/// the manager / any unrecognised label. +/// 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. #[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(); - 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` diff --git a/hive-c0re/src/meta.rs b/hive-c0re/src/meta.rs index c2d67fa..48f4fde 100644 --- a/hive-c0re/src/meta.rs +++ b/hive-c0re/src/meta.rs @@ -277,18 +277,14 @@ fn render_flake( # resolve the agent's durable state dir without hard-coding it. environment.variables = { HIVE_LABEL = name; - HYPERHIVE_STATE_DIR = - if isManager then "/state" - else "/agents/${name}/state"; + 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 = - if isManager then "/state" - else "/agents/${name}/state"; + HYPERHIVE_STATE_DIR = "/agents/${name}/state"; }; } ];