hive-c0re: admin socket server + client (stub dispatch)

This commit is contained in:
müde 2026-05-14 20:49:11 +02:00
parent bb2770856d
commit 0ec54ecf89
5 changed files with 177 additions and 26 deletions

View file

@ -2,10 +2,18 @@ use std::path::PathBuf;
use anyhow::{Result, bail};
use clap::{Parser, Subcommand};
use hive_sh4re::{HostRequest, HostResponse};
mod client;
mod server;
#[derive(Parser)]
#[command(name = "hive-c0re", about = "hyperhive coordinator daemon and CLI")]
struct Cli {
/// Path to the host admin socket.
#[arg(long, global = true, default_value = "/run/hyperhive/host.sock")]
socket: PathBuf,
#[command(subcommand)]
cmd: Cmd,
}
@ -17,11 +25,8 @@ enum Cmd {
/// Flake reference for the agent base template.
#[arg(long, default_value = "/etc/hyperhive#agent-base")]
agent_flake: String,
/// Path to the host admin socket.
#[arg(long, default_value = "/run/hyperhive/host.sock")]
socket: PathBuf,
},
/// Spawn a new agent container (creates `hive-agent-<name>`).
/// Spawn a new agent container (`hive-agent-<name>`).
Spawn { name: String },
/// Stop a managed container (graceful).
Kill { name: String },
@ -31,7 +36,8 @@ enum Cmd {
List,
}
fn main() -> Result<()> {
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
@ -41,28 +47,20 @@ fn main() -> Result<()> {
let cli = Cli::parse();
match cli.cmd {
Cmd::Serve {
agent_flake,
socket,
} => {
tracing::info!(?socket, %agent_flake, "serve: not yet implemented");
bail!("serve not yet implemented");
}
Cmd::Spawn { name } => {
tracing::info!(%name, "spawn: not yet implemented");
bail!("spawn not yet implemented");
}
Cmd::Kill { name } => {
tracing::info!(%name, "kill: not yet implemented");
bail!("kill not yet implemented");
}
Cmd::Serve { agent_flake } => server::serve(&cli.socket, &agent_flake).await,
Cmd::Spawn { name } => render(client::request(&cli.socket, HostRequest::Spawn { name }).await?),
Cmd::Kill { name } => render(client::request(&cli.socket, HostRequest::Kill { name }).await?),
Cmd::Rebuild { name } => {
tracing::info!(%name, "rebuild: not yet implemented");
bail!("rebuild not yet implemented");
}
Cmd::List => {
tracing::info!("list: not yet implemented");
bail!("list not yet implemented");
render(client::request(&cli.socket, HostRequest::Rebuild { name }).await?)
}
Cmd::List => render(client::request(&cli.socket, HostRequest::List).await?),
}
}
fn render(resp: HostResponse) -> Result<()> {
println!("{}", serde_json::to_string_pretty(&resp)?);
if !resp.ok {
bail!(resp.error.unwrap_or_else(|| "request failed".to_owned()));
}
Ok(())
}