refactor(#1202): introduce HiveEnv + AgentPaths to reduce arg repetition
This commit is contained in:
parent
e7785b4948
commit
29c7f64bd3
8 changed files with 131 additions and 235 deletions
|
|
@ -143,6 +143,44 @@ pub struct Coordinator {
|
|||
shutdown_tx: watch::Sender<bool>,
|
||||
}
|
||||
|
||||
/// Hive-wide configuration that lifecycle and meta operations need.
|
||||
/// Extracted from `Coordinator` so callers can pass a single struct
|
||||
/// instead of repeating the same 6 arguments everywhere.
|
||||
///
|
||||
/// Cloned from `Coordinator` via [`Coordinator::hive_env`]. All fields
|
||||
/// are cheap to clone (small strings + small map); lifecycle ops are
|
||||
/// infrequent enough that the copy cost is irrelevant.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct HiveEnv {
|
||||
pub hyperhive_flake: String,
|
||||
pub nixpkgs_flake: String,
|
||||
pub nixpkgs_unstable_flake: String,
|
||||
pub dashboard_port: u16,
|
||||
pub operator_pronouns: String,
|
||||
pub context_window_tokens: std::collections::HashMap<String, u64>,
|
||||
/// Per-agent systemd `CPUQuota=` value (e.g. `"200%"`).
|
||||
pub agent_cpu_quota: String,
|
||||
/// Per-agent systemd `MemoryMax=` value (e.g. `"4G"`).
|
||||
pub agent_memory_max: String,
|
||||
}
|
||||
|
||||
/// Per-agent filesystem paths that lifecycle operations write to.
|
||||
/// Assembled from `Coordinator`'s static path helpers so callers
|
||||
/// don't repeat the same `Coordinator::agent_*_dir(name)` calls.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AgentPaths {
|
||||
/// Runtime socket dir (tmpfs, recreated per boot).
|
||||
pub agent_dir: PathBuf,
|
||||
/// Manager-editable proposed config repo.
|
||||
pub proposed_dir: PathBuf,
|
||||
/// Hive-c0re-authoritative applied config repo.
|
||||
pub applied_dir: PathBuf,
|
||||
/// Claude OAuth credentials (survives purge boundary).
|
||||
pub claude_dir: PathBuf,
|
||||
/// Agent durable notes + forge token (survives purge boundary).
|
||||
pub notes_dir: PathBuf,
|
||||
}
|
||||
|
||||
/// Per-agent in-progress state that the dashboard surfaces between approve
|
||||
/// click and container ready.
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -282,6 +320,42 @@ impl Coordinator {
|
|||
})
|
||||
}
|
||||
|
||||
/// Snapshot the hive-wide configuration fields as a [`HiveEnv`].
|
||||
/// Pass the result to `lifecycle::spawn` / `rebuild` / `meta::sync_agents`
|
||||
/// instead of threading the individual fields separately.
|
||||
#[must_use]
|
||||
pub fn hive_env(&self) -> HiveEnv {
|
||||
HiveEnv {
|
||||
hyperhive_flake: self.hyperhive_flake.clone(),
|
||||
nixpkgs_flake: self.nixpkgs_flake.clone(),
|
||||
nixpkgs_unstable_flake: self.nixpkgs_unstable_flake.clone(),
|
||||
dashboard_port: self.dashboard_port,
|
||||
operator_pronouns: self.operator_pronouns.clone(),
|
||||
context_window_tokens: self.context_window_tokens.clone(),
|
||||
agent_cpu_quota: self.agent_cpu_quota.clone(),
|
||||
agent_memory_max: self.agent_memory_max.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Assemble the per-agent filesystem paths for `name`. The caller
|
||||
/// must supply `agent_dir` (from `ensure_runtime`) since that
|
||||
/// creates the tmpfs entry on first call. All other paths are
|
||||
/// derived statically from `name`.
|
||||
///
|
||||
/// ```no_run
|
||||
/// let paths = Coordinator::agent_paths(name, coord.ensure_runtime(name)?);
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn agent_paths(name: &str, agent_dir: PathBuf) -> AgentPaths {
|
||||
AgentPaths {
|
||||
agent_dir,
|
||||
proposed_dir: Self::agent_proposed_dir(name),
|
||||
applied_dir: Self::agent_applied_dir(name),
|
||||
claude_dir: Self::agent_claude_dir(name),
|
||||
notes_dir: Self::agent_notes_dir(name),
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit a `RebuildQueueChanged` snapshot event. Called from the
|
||||
/// queue mutation helpers (`enqueue` / `finish` / `cancel`-adjacent
|
||||
/// wrappers below) and the worker so every state transition
|
||||
|
|
|
|||
Loading…
Reference in a new issue