feat(#2): split harness-internal state from agent-visible state
This commit is contained in:
parent
ce875646a5
commit
ae6d23594d
9 changed files with 113 additions and 23 deletions
|
|
@ -21,19 +21,19 @@ const CHANNEL_CAPACITY: usize = 256;
|
|||
/// sqlite. Older rows are vacuumed on a periodic sweep.
|
||||
const HISTORY_CAPACITY: usize = 2000;
|
||||
/// Path to the persisted event db. Overridable via `HYPERHIVE_EVENTS_DB`
|
||||
/// for dev / tests; otherwise derived from the agent's state dir.
|
||||
/// for dev / tests; otherwise derived from the agent's harness dir.
|
||||
fn events_db_path() -> PathBuf {
|
||||
std::env::var_os("HYPERHIVE_EVENTS_DB").map_or_else(
|
||||
|| crate::paths::state_dir().join("hyperhive-events.sqlite"),
|
||||
|| crate::paths::harness_dir().join("hyperhive-events.sqlite"),
|
||||
PathBuf::from,
|
||||
)
|
||||
}
|
||||
|
||||
/// Path to the persisted model file. Overridable via `HYPERHIVE_MODEL_FILE`
|
||||
/// for dev / tests; otherwise derived from the agent's state dir.
|
||||
/// for dev / tests; otherwise derived from the agent's harness dir.
|
||||
fn model_file_path() -> PathBuf {
|
||||
std::env::var_os("HYPERHIVE_MODEL_FILE").map_or_else(
|
||||
|| crate::paths::state_dir().join("hyperhive-model"),
|
||||
|| crate::paths::harness_dir().join("hyperhive-model"),
|
||||
PathBuf::from,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,16 @@
|
|||
//! Per-agent path resolution for state and credential directories.
|
||||
//! Per-agent path resolution for state, harness, and credential directories.
|
||||
//!
|
||||
//! All agents (including the manager `hm1nd`) use `/agents/{label}/state`.
|
||||
//! All agents (including the manager `hm1nd`) use `/agents/{label}/state`
|
||||
//! for agent-owned durable notes, and `/agents/{label}/harness` for
|
||||
//! harness-internal files (`hyperhive-events.sqlite`, `hyperhive-model`, etc.)
|
||||
//! that should not clutter what claude sees as "my notes dir".
|
||||
//! Claude credentials live at `$HOME/.claude` (resolves to
|
||||
//! `/home/<agent-name>/.claude` because the harness service runs as a
|
||||
//! non-root unix user matching the agent label — see
|
||||
//! `docs/persistence.md::First-boot agent-user migration`).
|
||||
//!
|
||||
//! Both paths can be overridden via env vars (`HYPERHIVE_STATE_DIR`,
|
||||
//! `HYPERHIVE_CLAUDE_DIR`) for dev / test scenarios.
|
||||
//! All three paths can be overridden via env vars (`HYPERHIVE_STATE_DIR`,
|
||||
//! `HYPERHIVE_HARNESS_DIR`, `HYPERHIVE_CLAUDE_DIR`) for dev / test scenarios.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
@ -24,6 +27,20 @@ pub fn state_dir() -> PathBuf {
|
|||
PathBuf::from(format!("/agents/{label}/state"))
|
||||
}
|
||||
|
||||
/// Harness-internal state directory. Holds files the harness owns
|
||||
/// (`hyperhive-events.sqlite`, `hyperhive-turn-stats.sqlite`,
|
||||
/// `hyperhive-model`) so they do not appear inside the agent-visible
|
||||
/// `/agents/{label}/state` tree. Reads `HYPERHIVE_HARNESS_DIR` first;
|
||||
/// falls back to `/agents/{label}/harness` derived from `HIVE_LABEL`.
|
||||
#[must_use]
|
||||
pub fn harness_dir() -> PathBuf {
|
||||
if let Some(p) = std::env::var_os("HYPERHIVE_HARNESS_DIR") {
|
||||
return PathBuf::from(p);
|
||||
}
|
||||
let label = std::env::var("HIVE_LABEL").unwrap_or_default();
|
||||
PathBuf::from(format!("/agents/{label}/harness"))
|
||||
}
|
||||
|
||||
/// Per-turn config dir for the regenerated claude-{mcp-config,settings,
|
||||
/// system-prompt} files the harness drops before each turn. Set by
|
||||
/// systemd via `RuntimeDirectory = "hive-config"`: a per-service runtime
|
||||
|
|
|
|||
|
|
@ -262,5 +262,5 @@ impl TurnStats {
|
|||
}
|
||||
|
||||
fn default_path() -> PathBuf {
|
||||
crate::paths::state_dir().join("hyperhive-turn-stats.sqlite")
|
||||
crate::paths::harness_dir().join("hyperhive-turn-stats.sqlite")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue