Compare commits
2 commits
9cbb05bb86
...
d0b65b1f47
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0b65b1f47 | ||
|
|
f21ae1ff98 |
3 changed files with 20 additions and 13 deletions
|
|
@ -1383,13 +1383,20 @@ pub fn render_claude_config(agent_binary: &str, socket: &std::path::Path) -> Str
|
||||||
"env": {}
|
"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 {
|
if name == SERVER_NAME {
|
||||||
tracing::warn!(
|
tracing::warn!(
|
||||||
"extra MCP server name `{SERVER_NAME}` collides with the built-in surface; ignoring",
|
"extra MCP server name `{SERVER_NAME}` collides with the built-in surface; ignoring",
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
spec.env
|
||||||
|
.entry("HYPERHIVE_STATE_DIR".to_owned())
|
||||||
|
.or_insert_with(|| state_dir.display().to_string());
|
||||||
servers.insert(
|
servers.insert(
|
||||||
name,
|
name,
|
||||||
serde_json::json!({
|
serde_json::json!({
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
//! Per-agent path resolution for state and credential directories.
|
//! 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.
|
//! Claude credentials are always at `/root/.claude` for all agents.
|
||||||
//!
|
//!
|
||||||
//! Both paths can be overridden via env vars (`HYPERHIVE_STATE_DIR`,
|
//! Both paths can be overridden via env vars (`HYPERHIVE_STATE_DIR`,
|
||||||
|
|
@ -8,24 +8,17 @@
|
||||||
|
|
||||||
use std::path::PathBuf;
|
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`
|
/// Durable state directory for the current agent. Reads `HYPERHIVE_STATE_DIR`
|
||||||
/// first; falls back to `/agents/{label}/state` for sub-agents or `/state` for
|
/// first (always set by the meta flake to `/agents/{label}/state`); falls back
|
||||||
/// the manager / any unrecognised label.
|
/// to the same pattern derived from `HIVE_LABEL` for dev/test environments
|
||||||
|
/// where the env var may not be set.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn state_dir() -> PathBuf {
|
pub fn state_dir() -> PathBuf {
|
||||||
if let Some(p) = std::env::var_os("HYPERHIVE_STATE_DIR") {
|
if let Some(p) = std::env::var_os("HYPERHIVE_STATE_DIR") {
|
||||||
return PathBuf::from(p);
|
return PathBuf::from(p);
|
||||||
}
|
}
|
||||||
let label = std::env::var("HIVE_LABEL").unwrap_or_default();
|
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`
|
/// Claude credentials directory for the current agent. Always `/root/.claude`
|
||||||
|
|
|
||||||
|
|
@ -273,11 +273,18 @@ fn render_flake(
|
||||||
name = name;
|
name = name;
|
||||||
email = "${name}@hyperhive";
|
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 = "/agents/${name}/state";
|
||||||
|
};
|
||||||
systemd.services.${service}.environment = {
|
systemd.services.${service}.environment = {
|
||||||
HIVE_PORT = toString port;
|
HIVE_PORT = toString port;
|
||||||
HIVE_LABEL = name;
|
HIVE_LABEL = name;
|
||||||
HIVE_DASHBOARD_PORT = toString dashboardPort;
|
HIVE_DASHBOARD_PORT = toString dashboardPort;
|
||||||
HIVE_OPERATOR_PRONOUNS = operatorPronouns;
|
HIVE_OPERATOR_PRONOUNS = operatorPronouns;
|
||||||
|
HYPERHIVE_STATE_DIR = "/agents/${name}/state";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue