hyperhive/hive-ag3nt/src/paths.rs

39 lines
1.6 KiB
Rust

//! Per-agent path resolution for state and credential directories.
//!
//! 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`,
//! `HYPERHIVE_CLAUDE_DIR`) for dev / test scenarios.
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.
#[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"))
}
}
/// 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)
}