move hive-sh4re's harness_dir() into hive-agent-sock, drop the dev-fallback derivation

This commit is contained in:
damocles 2026-08-09 18:59:46 +02:00 committed by mara
commit 7ba492b965
6 changed files with 49 additions and 42 deletions

View file

@ -18,6 +18,8 @@ use serde::{Deserialize, Serialize};
use hive_sh4re::LooseEnd;
pub mod paths;
/// In-container path of the harness-served in-agent socket. The harness
/// binds it on boot; the in-container producers dial it for todo ops.
/// (Placeholder default — the harness + producers resolve the real path

View file

@ -0,0 +1,30 @@
//! In-container harness-directory resolution, shared by the harness
//! itself and every producer daemon that dials the in-agent socket
//! (`hive-bash-mcp`, and any future producer that writes artifacts
//! alongside the harness's own state).
use std::path::PathBuf;
/// Base harness directory for the current agent. Reads
/// `HYPERHIVE_HARNESS_DIR`, always injected by the meta flake's
/// `systemd.globalEnvironment` for every in-container service
/// (`nix/host-modules` — see `hive-c0re/src/meta.rs`'s per-agent
/// environment block). Every process this crate's wire types serve
/// (the harness, `hive-bash-daemon`, ...) runs under that same
/// environment, so there is no legitimate runtime path where it's
/// unset — a missing var means the container is misconfigured, not
/// that a fallback derivation should paper over it.
///
/// # Panics
///
/// Panics if `HYPERHIVE_HARNESS_DIR` is not set. Deliberate: a wrong
/// silently-derived path here means task files, sqlite stores, and the
/// in-agent socket itself could resolve to the wrong directory — a
/// loud crash at startup beats a quiet cross-agent path collision.
#[must_use]
pub fn harness_dir() -> PathBuf {
PathBuf::from(
std::env::var_os("HYPERHIVE_HARNESS_DIR")
.expect("HYPERHIVE_HARNESS_DIR must be set — the meta flake injects it for every in-container service; a missing value means the container's environment is misconfigured"),
)
}

View file

@ -31,13 +31,13 @@ pub fn state_dir() -> PathBuf {
/// (`hyperhive-events.sqlite`, `hyperhive-turn-stats.sqlite`,
/// `hyperhive-model`) so they do not appear inside the agent-visible
/// `/agents/{label}/state` tree. Delegates to the shared canonical
/// resolver in `hive_sh4re::paths` so the harness + every out-of-process
/// MCP daemon resolve this identically (reads `HYPERHIVE_HARNESS_DIR`,
/// then a `harness/` sibling of `HYPERHIVE_STATE_DIR`, then
/// `/agents/{HIVE_LABEL}/harness`).
/// resolver in `hive_agent_sock::paths` so the harness + every
/// out-of-process MCP daemon resolve this identically (reads
/// `HYPERHIVE_HARNESS_DIR`, always injected by the meta flake — panics
/// if it's unset rather than silently deriving a fallback path).
#[must_use]
pub fn harness_dir() -> PathBuf {
hive_sh4re::paths::harness_dir()
hive_agent_sock::paths::harness_dir()
}
/// Consolidated harness-local state db — todos + reminders + the questions

View file

@ -6,12 +6,12 @@
use std::path::PathBuf;
/// Base harness directory. Shared resolution lives in
/// `hive_sh4re::paths::harness_dir` so the harness + every MCP daemon
/// agree on the layout. Re-exported here as the base for the per-agent
/// artifact paths below.
/// `hive_agent_sock::paths::harness_dir` so the harness + every MCP
/// daemon agree on the layout. Re-exported here as the base for the
/// per-agent artifact paths below.
#[must_use]
pub fn harness_dir() -> PathBuf {
hive_sh4re::paths::harness_dir()
hive_agent_sock::paths::harness_dir()
}
/// Base directory for task files.

View file

@ -1,33 +1,8 @@
//! Shared in-container filesystem-path resolution.
//!
//! Every process that runs inside an agent container - the harness plus
//! the out-of-process MCP daemons (bash, matrix, ...) - must resolve the
//! harness directory layout identically. These helpers live here so the
//! resolution exists in exactly one place rather than being mirrored
//! across crates.
use std::path::PathBuf;
/// Base harness directory for the current agent. Uses `HYPERHIVE_HARNESS_DIR`
/// if set (injected by the hive-c0re meta flake after the harness/state
/// split). For pre-split / dev deployments where it isn't set, falls back to
/// a `harness/` sibling of `HYPERHIVE_STATE_DIR`, and finally to
/// `/agents/{HIVE_LABEL}/harness` when neither dir env var is present — the
/// shape the harness derives from its label alone.
#[must_use]
pub fn harness_dir() -> PathBuf {
if let Some(p) = std::env::var_os("HYPERHIVE_HARNESS_DIR") {
return PathBuf::from(p);
}
if let Some(state) = std::env::var_os("HYPERHIVE_STATE_DIR") {
let state_path = PathBuf::from(&state);
if let Some(parent) = state_path.parent() {
return parent.join("harness");
}
}
let label = std::env::var("HIVE_LABEL").unwrap_or_default();
PathBuf::from(format!("/agents/{label}/harness"))
}
//! Shared filename constants for in-container filesystem paths. Harness
//! *directory* resolution itself lives in `hive_agent_sock::paths`
//! (every in-container producer already depends on that crate for the
//! socket wire types) — this module only keeps the bits that also need
//! to be reachable from the host side (`hive-c0re`).
/// File name of the pause marker inside the harness dir. Re-exported from
/// `hive-priv-sock`, which owns the definition because hive-priv (root) is

View file

@ -261,9 +261,9 @@ in
# injected via systemd.globalEnvironment by the meta flake
# (set to /agents/<name>/harness and /agents/<name>/state
# respectively). The daemon uses these to derive its task +
# loose-ends dir paths; without them it falls back to deriving
# harness/ as a sibling of state/, which produces the same
# value but is less robust if the two vars ever diverge.
# loose-ends dir paths; `hive_agent_sock::paths::harness_dir`
# panics loudly if HYPERHIVE_HARNESS_DIR is unset rather than
# deriving a fallback, since every service here always gets it.
};
serviceConfig = {
ExecStart = "${config.hyperhive.packages.hive-bash-daemon}/bin/hive-bash-daemon --http 127.0.0.1:${toString config.hyperhive.mcp.bashHttpPort}";