Watch
0
0
Fork
You've already forked hyperhive
0

Compare commits

..
34 changed files with 135 additions and 243 deletions

27
Cargo.lock generated
View file

@ -1767,6 +1767,7 @@ dependencies = [
"serde",
"serde_json",
"sha2 0.11.0",
"strum",
"swarm-queue-client",
"swarm-secret-client",
"tempfile",
@ -1814,6 +1815,7 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"strum",
"time",
"url",
]
@ -1965,6 +1967,7 @@ dependencies = [
"schemars",
"serde",
"serde_json",
"strum",
]
[[package]]
@ -4662,6 +4665,27 @@ version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "strum"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9628de9b8791db39ceda2b119bbe13134770b56c138ec1d3af810d045c04f9bd"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.119",
]
[[package]]
name = "subtle"
version = "2.6.1"
@ -4721,6 +4745,7 @@ dependencies = [
"serde",
"serde_json",
"sha2 0.11.0",
"strum",
"swarm-authelia-bridge-sock",
"swarm-queue-client",
"swarm-secret-client",
@ -4761,6 +4786,7 @@ dependencies = [
"reqwest",
"serde",
"serde_json",
"strum",
"thiserror 2.0.18",
"tokio",
"tracing",
@ -4775,6 +4801,7 @@ dependencies = [
"rustify_derive",
"serde",
"serde_json",
"strum",
"thiserror 2.0.18",
"vaultrs",
]

View file

@ -113,6 +113,10 @@ schemars = "1.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
similar = "2"
# `derive`-only: `Kind`'s segment strings via `#[strum(serialize = "...")]`
# instead of a hand-written match, so the derive macro is the single source
# of truth (see `swarm-secret-client::path::Kind`).
strum = { version = "0.28.0", features = ["derive"] }
tokio = { version = "1", features = [
"fs",
"io-util",

View file

@ -848,7 +848,7 @@ progresses (a rebuild reads `stop_for_update`, then `swap`, then
life). Two consequences for anything rendering it:
- The label vocabulary is **open** — it's the node's own wire tag
(`NodeKind::as_str`, the same strings the graph wire's node
(`NodeKind`'s `&str` conversion, the same strings the graph wire's node
labels carry), not a fixed set. Treat it as an opaque display
string; don't switch on specific values. `restarting` in
particular no longer exists, because no node kind is unique to a

View file

@ -50,6 +50,7 @@ sha2.workspace = true
rusqlite.workspace = true
serde.workspace = true
serde_json.workspace = true
strum.workspace = true
# Offering this hive's status to the swarm (`swarm_status`). The same crate
# the swarm controller reads it with, and `kv` for the same reason: the
# bucket's name and creation config belong to neither end of it alone.

View file

@ -712,7 +712,7 @@ async fn finish_approval(
// snapshot refetch. `approved` rows that succeed get the
// approval's logged resolved_at indirectly via `Utc::now()`;
// failures already wrote it via mark_failed above.
let approval_kind = approval.kind.as_str();
let approval_kind = <&str>::from(approval.kind);
let sha_short = approval
.fetched_sha
.as_deref()
@ -921,7 +921,7 @@ pub fn deny(coord: &Coordinator, id: i64, note: Option<&str>) -> Result<()> {
tracing::info!(%id, note, "approval denied");
if let Some(a) = approval {
let sha = a.fetched_sha.clone();
let approval_kind = a.kind.as_str();
let approval_kind = <&str>::from(a.kind);
let sha_short = sha.as_deref().map(|s| s[..s.len().min(12)].to_owned());
let description = a.description.clone();
let agent_owned = a.agent.clone();

View file

@ -55,7 +55,7 @@ pub fn caps_for(name: &str) -> Vec<String> {
pub fn has_cap(name: &str, cap: hive_sh4re::permissions::Capability) -> bool {
caps_for(name)
.iter()
.any(|s| s.eq_ignore_ascii_case(cap.as_str()))
.any(|s| s.eq_ignore_ascii_case(<&str>::from(cap)))
}
/// Persist the full capability map. Sorted JSON output keeps diffs

View file

@ -72,7 +72,7 @@ fn write(map: &BTreeMap<String, Vec<String>>) -> std::io::Result<()> {
pub fn validate_groups(groups: &[String]) -> anyhow::Result<()> {
let valid: std::collections::BTreeSet<&str> = hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect();
let unknown: Vec<&str> = groups
.iter()
@ -87,7 +87,7 @@ pub fn validate_groups(groups: &[String]) -> anyhow::Result<()> {
unknown.join(", "),
hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect::<Vec<_>>()
.join(", ")
)

View file

@ -638,10 +638,10 @@ impl Coordinator {
/// commits the JSON file, so the P3RM1SS10NS tab updates live.
pub fn emit_capabilities_snapshot(self: &Arc<Self>) {
use hive_sh4re::permissions::Capability;
let caps = Capability::ALL.iter().map(|c| c.as_str()).collect();
let caps = Capability::ALL.iter().map(|c| <&str>::from(*c)).collect();
let descriptions = Capability::ALL
.iter()
.map(|c| (c.as_str(), c.description()))
.map(|c| (<&str>::from(*c), c.description()))
.collect();
let assignments = crate::capabilities::read();
// Best-effort roster (sync path); on a contended cache miss we
@ -665,10 +665,10 @@ impl Coordinator {
/// commits the JSON file, so the P3RM1SS10NS tab updates live.
pub fn emit_tool_groups_snapshot(self: &Arc<Self>) {
use hive_sh4re::permissions::ToolGroup;
let groups = ToolGroup::ALL.iter().map(|g| g.as_str()).collect();
let groups = ToolGroup::ALL.iter().map(|g| <&str>::from(*g)).collect();
let descriptions = ToolGroup::ALL
.iter()
.map(|g| (g.as_str(), g.description()))
.map(|g| (<&str>::from(*g), g.description()))
.collect();
let assignments = crate::tool_groups::read();
let roster = self.live_container_names_blocking().unwrap_or_default();

View file

@ -105,7 +105,7 @@ pub(super) fn gc_orphans(coord: &Coordinator, approvals: Vec<Approval>) -> Vec<A
coord.emit_approval_resolved(crate::coordinator::ApprovalResolved {
id: a.id,
agent: a.agent.as_str(),
approval_kind: a.kind.as_str(),
approval_kind: <&str>::from(a.kind),
sha_short,
status: "failed",
note: Some(note.to_owned()),

View file

@ -50,11 +50,11 @@ pub(super) async fn get_tool_groups(
) -> axum::Json<ToolGroupsSnapshot> {
let groups = hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect();
let descriptions = hive_sh4re::permissions::ToolGroup::ALL
.iter()
.map(|g| (g.as_str(), g.description()))
.map(|g| (<&str>::from(*g), g.description()))
.collect();
let assignments = crate::tool_groups::read();
let roster = state
@ -82,7 +82,7 @@ pub(super) async fn get_tool_groups(
pub(crate) fn tool_group_default_names() -> Vec<&'static str> {
hive_sh4re::permissions::ToolGroup::AGENT_DEFAULT
.iter()
.map(|g| g.as_str())
.map(|g| <&str>::from(*g))
.collect()
}
@ -205,10 +205,10 @@ pub(super) async fn get_capabilities(
State(state): State<AppState>,
) -> axum::Json<CapabilitiesSnapshot> {
use hive_sh4re::permissions::Capability;
let caps = Capability::ALL.iter().map(|c| c.as_str()).collect();
let caps = Capability::ALL.iter().map(|c| <&str>::from(*c)).collect();
let descriptions = Capability::ALL
.iter()
.map(|c| (c.as_str(), c.description()))
.map(|c| (<&str>::from(*c), c.description()))
.collect();
let assignments = crate::capabilities::read();
let roster = state
@ -258,7 +258,7 @@ pub(super) async fn post_capabilities(
}
let known: Vec<&str> = hive_sh4re::permissions::Capability::ALL
.iter()
.map(|c| c.as_str())
.map(|c| <&str>::from(*c))
.collect();
for cap in &body.caps {
if !known.contains(&cap.as_str()) {
@ -336,7 +336,7 @@ pub(super) async fn post_permissions(
) -> Result<Response, ProblemDetails> {
let known_caps: Vec<&str> = hive_sh4re::permissions::Capability::ALL
.iter()
.map(|c| c.as_str())
.map(|c| <&str>::from(*c))
.collect();
// Phase 1 — validate everything before touching any file or the
// queue, so a bad entry fails the whole POST with zero side effects.

View file

@ -423,7 +423,7 @@ fn history_view(a: Approval) -> ApprovalHistoryView {
// Pending shouldn't appear in recent_resolved, but be defensive.
hive_sh4re::approvals::ApprovalStatus::Pending => "pending",
};
let kind = a.kind.as_str();
let kind = <&str>::from(a.kind);
ApprovalHistoryView {
id: a.id,
agent: a.agent.to_string(),

View file

@ -385,7 +385,7 @@ fn run_set_wanted(coord: &Arc<Coordinator>, agent: &str, up: bool) -> Result<()>
coord
.power
.set(agent, wanted)
.with_context(|| format!("set wanted={} for agent {agent}", wanted.as_str()))?;
.with_context(|| format!("set wanted={} for agent {agent}", <&str>::from(wanted)))?;
Ok(())
}
@ -579,7 +579,7 @@ async fn run_reconcile(coord: &Arc<Coordinator>, name: &str) -> Result<Option<No
agent: name.to_owned(),
}),
ReconcileAction::Noop => {
tracing::debug!(%name, wanted = wanted.as_str(), running, "reconcile: noop");
tracing::debug!(%name, wanted = <&str>::from(wanted), running, "reconcile: noop");
None
}
})

View file

@ -281,7 +281,7 @@ impl JobQueue {
/// so both are running and both name `a`. Anything keying this set by agent
/// alone will silently drop one — see [`scheduler`].
///
/// `label` is the node's own wire tag ([`NodeKind::as_str`]), the same
/// `label` is the node's own wire tag (`NodeKind`'s `&str` conversion), the same
/// vocabulary the graph wire ships as a node's label, so a pill and a
/// graph node name an operation identically. `takes_container_down` is the
/// crash watcher's
@ -313,7 +313,7 @@ impl JobQueue {
}
Some(RunningTransient {
agent: agent.to_owned(),
label: n.payload.as_str().to_owned(),
label: <&str>::from(&n.payload).to_owned(),
takes_container_down: n.payload.takes_container_down(),
// `started_at` is set when a node enters `Running`, and this
// only sees `Running` nodes — the fallback is unreachable in

View file

@ -31,8 +31,9 @@ use hive_jobq::TerminalState;
/// compose into live in the node-inventory table and surrounding sections
/// of `docs/scheduler/coordinator.md` — this enum is deliberately not a
/// second copy of that; each variant below gets a one-line pointer.
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, strum::IntoStaticStr)]
#[serde(tag = "kind", rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum NodeKind {
/// The rebuild's meta-repo preamble. `relock = false` only for
/// meta-update cascade rebuilds (re-locking would revert the bump the
@ -169,7 +170,7 @@ pub enum NodeKind {
/// renders it without knowing what any of it means.
impl hive_jobq_wire::WireNode for NodeKind {
fn label(&self) -> String {
self.as_str().to_owned()
<&str>::from(self).to_owned()
}
fn data(&self, id: hive_jobq_wire::WireId) -> serde_json::Value {
@ -200,48 +201,6 @@ impl hive_jobq_wire::WireNode for NodeKind {
}
impl NodeKind {
/// Wire string for the node's label on the graph wire
/// ([`hive_jobq_wire::WireNode::label`]).
pub fn as_str(&self) -> &'static str {
match self {
NodeKind::MetaSync { .. } => "meta_sync",
NodeKind::Prebuild { .. } => "prebuild",
NodeKind::Swap { .. } => "swap",
NodeKind::RebuildBookkeeping { .. } => "rebuild_bookkeeping",
NodeKind::Provision { .. } => "provision",
NodeKind::Create { .. } => "create",
NodeKind::DestroyContainer { .. } => "destroy_container",
NodeKind::PurgeState { .. } => "purge_state",
NodeKind::DestroyBookkeeping { .. } => "destroy_bookkeeping",
NodeKind::MetaLock { .. } => "meta_lock",
NodeKind::Reconcile { .. } => "reconcile",
NodeKind::Start { .. } => "start",
NodeKind::Stop { .. } => "stop",
NodeKind::StopForUpdate { .. } => "stop_for_update",
NodeKind::Signal { .. } => "signal",
NodeKind::Drain { .. } => "drain",
NodeKind::PauseSignal { .. } => "pause_signal",
NodeKind::PauseDrain { .. } => "pause_drain",
NodeKind::WriteDropin { .. } => "write_dropin",
NodeKind::WritePermFile { .. } => "write_perm_file",
NodeKind::Reparent { .. } => "reparent",
NodeKind::DeployWindow { .. } => "deploy_window",
NodeKind::AgentWindow { .. } => "agent_window",
NodeKind::MergeVerify { .. } => "merge_verify",
NodeKind::DeployApply { .. } => "deploy_apply",
NodeKind::FinalizeDeploy { .. } => "finalize_deploy",
NodeKind::DeployTail { .. } => "deploy_tail",
NodeKind::ResolveApproval { .. } => "resolve_approval",
NodeKind::EmitRebuilt { .. } => "emit_rebuilt",
NodeKind::SetWanted { .. } => "set_wanted",
NodeKind::ForgeSweep => "forge_sweep",
NodeKind::MatrixSweep => "matrix_sweep",
NodeKind::WebhookRegister => "webhook_register",
NodeKind::KnowledgePull => "knowledge_pull",
NodeKind::WantedPull => "wanted_pull",
}
}
/// The agent this node targets, or `""` for agentless kinds
/// ([`NodeKind::MetaLock`] on the `hyperhive` pseudo-agent,
/// [`NodeKind::Reparent`] which can span multiple agents, and

View file

@ -92,10 +92,11 @@ pub async fn run_worker(coord: Arc<Coordinator>) {
hive_jobq::scheduler::Scheduler::claim_next(&sched, move |id, kind, builder| {
let coord = node_coord;
async move {
let kind_str = <&str>::from(&kind);
tracing::info!(
dag = coord.job_queue.root_of(id).unwrap_or_default(),
node = id.get(),
kind = kind.as_str(),
kind = kind_str,
agent = %kind.agent(),
"job_queue: node running"
);
@ -104,7 +105,7 @@ pub async fn run_worker(coord: Arc<Coordinator>) {
Ok(()) => tracing::info!(node = id.get(), "job_queue: node done"),
Err(e) => tracing::warn!(
node = id.get(),
kind = kind.as_str(),
kind = kind_str,
agent = %kind.agent(),
error = %format!("{e:#}"),
grown_nodes = !grown.is_empty(),

View file

@ -146,12 +146,12 @@ fn declared_shape(q: &JobQueue) -> Vec<Declared> {
fn declared_shape_filtered(q: &JobQueue, keep: &dyn Fn(&NodeKind) -> bool) -> Vec<Declared> {
let sched = q.sched().lock().expect("job_queue mutex poisoned");
let graph = sched.graph();
let kind_of = |id: NodeId| graph.node(id).map(|n| n.payload.as_str());
let kind_of = |id: NodeId| graph.node(id).map(|n| <&str>::from(&n.payload));
graph
.nodes()
.filter(|n| keep(&n.payload))
.map(|n| Declared {
kind: n.payload.as_str(),
kind: <&str>::from(&n.payload),
parent: n.parent.and_then(kind_of),
after: n
.deps
@ -175,7 +175,7 @@ fn node_of(q: &JobQueue, kind: &str) -> hive_jobq::NodeId {
let graph = sched.graph();
let mut found: Vec<_> = graph
.nodes()
.filter(|n| n.payload.as_str() == kind)
.filter(|n| <&str>::from(&n.payload) == kind)
.map(|n| n.id)
.collect();
assert_eq!(
@ -225,7 +225,7 @@ fn pending_kinds_filtered(q: &JobQueue, keep: &dyn Fn(&NodeKind) -> bool) -> Vec
graph
.nodes()
.filter(|n| n.state == State::Pending && keep(&n.payload))
.map(|n| n.payload.as_str())
.map(|n| <&str>::from(&n.payload))
.collect()
}
@ -275,7 +275,7 @@ fn declared_resources_of_kind(q: &JobQueue, kind: &str) -> Vec<Vec<Resource>> {
let graph = sched.graph();
let mut rows: Vec<Vec<Resource>> = graph
.nodes()
.filter(|n| n.payload.as_str() == kind)
.filter(|n| <&str>::from(&n.payload) == kind)
.map(|n| {
n.deps
.iter()
@ -862,7 +862,7 @@ fn rebuild_chain_nodes_suppress_crash_watch() {
kind.takes_container_down(),
"{} must suppress crash-watch — a rebuild takes the container down \
on purpose",
kind.as_str()
<&str>::from(&kind)
);
}
// The counter-case, and the reason this can't be "any node in a rebuild":

View file

@ -823,7 +823,7 @@ fn handle_cancel_loose_end(
coord.emit_approval_resolved(crate::coordinator::ApprovalResolved {
id: approval.id,
agent: approval.agent.as_str(),
approval_kind: approval.kind.as_str(),
approval_kind: <&str>::from(approval.kind),
sha_short,
status: "cancelled",
note: approval.note,

View file

@ -93,7 +93,7 @@ impl Approvals {
VALUES (?1, ?2, ?3, ?4, 'pending', ?5, ?6, ?7)",
params![
agent,
kind.as_str(),
<&str>::from(kind),
commit_ref,
Utc::now().timestamp(),
description,

View file

@ -90,8 +90,9 @@ const MIGRATIONS: &[Migration] = &[Migration {
/// Status of a finished build attempt. Stored as the literal string in
/// the `status` column; `NULL` while the attempt is still in progress.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, strum::IntoStaticStr)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum BuildStatus {
/// Child exited with success.
Ok,
@ -99,15 +100,6 @@ pub enum BuildStatus {
Fail,
}
impl BuildStatus {
fn as_str(self) -> &'static str {
match self {
Self::Ok => "ok",
Self::Fail => "fail",
}
}
}
/// Header-only row returned by `list_recent_for_agent`. Carries the
/// metadata the dashboard's agent-card chip needs (status + age +
/// id-to-open) without the multi-MB stdout/stderr payload.
@ -280,7 +272,7 @@ impl BuildLogs {
let conn = self.conn.lock().unwrap();
if let Err(e) = conn.execute(
"UPDATE build_logs SET finished_at = ?1, status = ?2 WHERE id = ?3",
params![now, status.as_str(), id],
params![now, <&str>::from(status), id],
) {
tracing::warn!(
build_log_id = id,

View file

@ -30,28 +30,14 @@ CREATE TABLE IF NOT EXISTS agent_power (
";
/// Per-agent power intent.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, strum::IntoStaticStr, strum::EnumString)]
#[strum(serialize_all = "snake_case")]
pub enum Wanted {
Up,
Offline,
}
impl Wanted {
pub fn as_str(self) -> &'static str {
match self {
Wanted::Up => "up",
Wanted::Offline => "offline",
}
}
fn parse(s: &str) -> Option<Self> {
match s {
"up" => Some(Wanted::Up),
"offline" => Some(Wanted::Offline),
_ => None,
}
}
/// Seed value from an observed running state (first boot after
/// this store lands, or an agent spawned outside the normal path).
pub fn from_running(running: bool) -> Self {
@ -128,7 +114,7 @@ impl PowerStore {
.context("select agent_power")?;
match row {
None => Ok(None),
Some(stored) => Wanted::parse(&stored).map(Some).with_context(|| {
Some(stored) => stored.parse::<Wanted>().ok().map(Some).with_context(|| {
format!("agent_power row for {agent} holds an unknown intent {stored:?}")
}),
}
@ -141,7 +127,7 @@ impl PowerStore {
conn.execute(
"INSERT INTO agent_power (agent, wanted, updated_at) VALUES (?1, ?2, ?3)
ON CONFLICT(agent) DO UPDATE SET wanted = ?2, updated_at = ?3",
params![agent, wanted.as_str(), Utc::now().timestamp()],
params![agent, <&str>::from(wanted), Utc::now().timestamp()],
)
.context("upsert agent_power")?;
Ok(())
@ -157,7 +143,7 @@ impl PowerStore {
}
let seeded = Wanted::from_running(running);
self.set(agent, seeded)?;
tracing::info!(%agent, wanted = seeded.as_str(), "agent_power: seeded from observed state");
tracing::info!(%agent, wanted = <&str>::from(seeded), "agent_power: seeded from observed state");
Ok(seeded)
}

Some files were not shown because too many files have changed in this diff Show more