refactor: per-agent state paths (/agents/{label}/state), centralize in paths.rs
This commit is contained in:
parent
a82009cf8c
commit
a6d1464071
10 changed files with 86 additions and 56 deletions
39
hive-ag3nt/src/paths.rs
Normal file
39
hive-ag3nt/src/paths.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
//! 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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue