//! Per-agent path resolution for state and credential directories. //! //! 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`, //! `HYPERHIVE_CLAUDE_DIR`) for dev / test scenarios. use std::path::PathBuf; /// 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. #[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")) } /// Claude credentials directory for the current agent. Always `/root/.claude` /// because the `claude` CLI reads `$HOME/.claude` (uid 0 → `/root`), and /// hive-c0re binds the per-agent credentials dir there for every container. /// Overridable via `HYPERHIVE_CLAUDE_DIR` for dev / test scenarios. #[must_use] pub fn claude_dir() -> PathBuf { std::env::var_os("HYPERHIVE_CLAUDE_DIR") .map_or_else(|| PathBuf::from("/root/.claude"), PathBuf::from) }