refactor(#2569): rename hive-agent-sock to hive-core-agent-sock

This commit is contained in:
damocles 2026-07-20 21:58:28 +02:00
commit 795dd882bb
26 changed files with 184 additions and 161 deletions

View file

@ -9,7 +9,7 @@
use std::sync::Arc;
use hive_agent_sock::Response;
use hive_core_agent_sock::Response;
use super::require_new_child;
use crate::coordinator::Coordinator;

View file

@ -5,7 +5,7 @@
use std::sync::Arc;
use hive_agent_sock::Response;
use hive_core_agent_sock::Response;
use super::require_descendant;
use crate::coordinator::Coordinator;

View file

@ -13,7 +13,7 @@ use std::path::{Path, PathBuf};
use std::sync::Arc;
use anyhow::{Context, Result};
use hive_agent_sock::{Request, Response};
use hive_core_agent_sock::{Request, Response};
use hive_sh4re::{MANAGER_AGENT, Message};
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
use tokio::net::{UnixListener, UnixStream};
@ -190,24 +190,26 @@ pub(crate) fn recv_timeout(wait_seconds: Option<u64>) -> std::time::Duration {
/// The unified `dispatch` calls this first; the remaining arms (which gate
/// on topology / capabilities / tool-groups) are handled there.
pub(crate) async fn dispatch_shared(
req: &hive_agent_sock::Request,
req: &hive_core_agent_sock::Request,
agent: &str,
coord: &Arc<Coordinator>,
) -> Option<hive_agent_sock::Response> {
) -> Option<hive_core_agent_sock::Response> {
Some(match req {
hive_agent_sock::Request::Send {
hive_core_agent_sock::Request::Send {
to,
body,
in_reply_to,
} => handle_send(coord, agent, to, body, *in_reply_to),
hive_agent_sock::Request::Recv { wait_seconds, max } => {
hive_core_agent_sock::Request::Recv { wait_seconds, max } => {
handle_recv(coord, agent, *wait_seconds, *max).await
}
hive_agent_sock::Request::Status => handle_status(coord, agent),
hive_agent_sock::Request::OperatorMsg { body } => handle_operator_msg(coord, agent, body),
hive_agent_sock::Request::Wake { from, body } => handle_wake(coord, agent, from, body),
hive_agent_sock::Request::Recent { limit } => handle_recent(coord, agent, *limit),
hive_agent_sock::Request::Ask {
hive_core_agent_sock::Request::Status => handle_status(coord, agent),
hive_core_agent_sock::Request::OperatorMsg { body } => {
handle_operator_msg(coord, agent, body)
}
hive_core_agent_sock::Request::Wake { from, body } => handle_wake(coord, agent, from, body),
hive_core_agent_sock::Request::Recent { limit } => handle_recent(coord, agent, *limit),
hive_core_agent_sock::Request::Ask {
question,
options,
multi,
@ -223,42 +225,42 @@ pub(crate) async fn dispatch_shared(
to.as_deref(),
)
.map_or_else(
|message| hive_agent_sock::Response::Err { message },
|id| hive_agent_sock::Response::QuestionQueued { id },
|message| hive_core_agent_sock::Response::Err { message },
|id| hive_core_agent_sock::Response::QuestionQueued { id },
),
hive_agent_sock::Request::Answer { id, answer } => {
hive_core_agent_sock::Request::Answer { id, answer } => {
crate::questions::handle_answer(coord, agent, *id, answer).map_or_else(
|message| hive_agent_sock::Response::Err { message },
|()| hive_agent_sock::Response::Ok,
|message| hive_core_agent_sock::Response::Err { message },
|()| hive_core_agent_sock::Response::Ok,
)
}
hive_agent_sock::Request::Remind {
hive_core_agent_sock::Request::Remind {
message,
timing,
file_path,
} => handle_remind(coord, agent, message, timing, file_path.as_deref()),
hive_agent_sock::Request::SetStatus { text } => handle_set_status(coord, text),
hive_agent_sock::Request::GetAgentMeta { name } => {
hive_core_agent_sock::Request::SetStatus { text } => handle_set_status(coord, text),
hive_core_agent_sock::Request::GetAgentMeta { name } => {
handle_get_agent_meta(coord, agent, name.as_deref()).await
}
hive_agent_sock::Request::CancelLooseEnd { kind, id } => {
hive_core_agent_sock::Request::CancelLooseEnd { kind, id } => {
crate::questions::handle_cancel_loose_end(coord, agent, *kind, *id).map_or_else(
|message| hive_agent_sock::Response::Err { message },
|()| hive_agent_sock::Response::Ok,
|message| hive_core_agent_sock::Response::Err { message },
|()| hive_core_agent_sock::Response::Ok,
)
}
hive_agent_sock::Request::CreateRepo { repo } => handle_create_repo(agent, repo).await,
hive_agent_sock::Request::AckTurn => handle_ack_turn(coord, agent),
hive_agent_sock::Request::AckUntil { up_to } => handle_ack_until(coord, agent, *up_to),
hive_agent_sock::Request::RequeueInflight => handle_requeue_inflight(coord, agent),
hive_agent_sock::Request::GracefulStopComplete => {
hive_core_agent_sock::Request::CreateRepo { repo } => handle_create_repo(agent, repo).await,
hive_core_agent_sock::Request::AckTurn => handle_ack_turn(coord, agent),
hive_core_agent_sock::Request::AckUntil { up_to } => handle_ack_until(coord, agent, *up_to),
hive_core_agent_sock::Request::RequeueInflight => handle_requeue_inflight(coord, agent),
hive_core_agent_sock::Request::GracefulStopComplete => {
// Harness drained + is exiting: clear the fence so the
// `GracefulStop` orchestration (which polls this flag) proceeds
// to stop the container without waiting out its timeout.
coord.clear_graceful_stop(agent);
hive_agent_sock::Response::Ok
hive_core_agent_sock::Response::Ok
}
hive_agent_sock::Request::GetHostJournal {
hive_core_agent_sock::Request::GetHostJournal {
unit,
container,
lines,
@ -293,7 +295,7 @@ async fn handle_recv(
agent: &str,
wait_seconds: Option<u64>,
max: Option<u32>,
) -> hive_agent_sock::Response {
) -> hive_core_agent_sock::Response {
// Graceful-stop fence: while a graceful stop is pending for this agent,
// return `GracefulStop` instead of polling the broker. The harness runs
// one stop-checkpoint turn then exits; new sends keep queueing in the
@ -301,7 +303,7 @@ async fn handle_recv(
// so a flag set between polls is seen on the next Recv — the orchestration
// also fires a transient wake to break an in-flight long-poll.
if coord.is_graceful_stop_pending(agent) {
return hive_agent_sock::Response::GracefulStop;
return hive_core_agent_sock::Response::GracefulStop;
}
let cap = max.unwrap_or(1).min(RECV_BATCH_MAX) as usize;
match coord
@ -315,7 +317,7 @@ async fn handle_recv(
// exactly how many still-pending messages remain to drain. A count
// error is non-fatal — fall back to 0 rather than fail the recv.
let remaining = coord.broker.count_pending(agent).unwrap_or(0);
hive_agent_sock::Response::Messages {
hive_core_agent_sock::Response::Messages {
messages: deliveries
.into_iter()
.map(|d| hive_sh4re::DeliveredMessage {
@ -329,7 +331,7 @@ async fn handle_recv(
remaining,
}
}
Err(e) => hive_agent_sock::Response::Err {
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}
@ -343,15 +345,15 @@ fn handle_wake(
agent: &str,
from: &str,
body: &str,
) -> hive_agent_sock::Response {
) -> hive_core_agent_sock::Response {
match coord.broker.send(&Message {
from: from.to_owned(),
to: agent.to_owned(),
body: body.to_owned(),
in_reply_to: None,
}) {
Ok(()) => hive_agent_sock::Response::Ok,
Err(e) => hive_agent_sock::Response::Err {
Ok(()) => hive_core_agent_sock::Response::Ok,
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}
@ -361,13 +363,13 @@ fn handle_wake(
/// rescan. The harness has already written the status file to its own
/// `state/` dir (it runs as the agent user), so this only refreshes the
/// dashboard's view.
fn handle_set_status(coord: &Arc<Coordinator>, text: &str) -> hive_agent_sock::Response {
fn handle_set_status(coord: &Arc<Coordinator>, text: &str) -> hive_core_agent_sock::Response {
if let Err(message) = crate::limits::check_status_text(text) {
return hive_agent_sock::Response::Err { message };
return hive_core_agent_sock::Response::Err { message };
}
let coord2 = Arc::clone(coord);
tokio::spawn(async move { coord2.rescan_containers_and_emit().await });
hive_agent_sock::Response::Ok
hive_core_agent_sock::Response::Ok
}
/// Validate an agent-supplied repo name: a single safe slug segment, no
@ -385,9 +387,9 @@ fn valid_repo_name(name: &str) -> bool {
/// `CreateRepo` — create a repo for `agent` *through hive-c0re* in the
/// c0re-owned `agents` org with operator-team branch protection.
/// The sanctioned create path now that agents can't create repos directly.
async fn handle_create_repo(agent: &str, repo: &str) -> hive_agent_sock::Response {
async fn handle_create_repo(agent: &str, repo: &str) -> hive_core_agent_sock::Response {
if !valid_repo_name(repo) {
return hive_agent_sock::Response::Err {
return hive_core_agent_sock::Response::Err {
message: format!(
"invalid repo name {repo:?} — single segment of letters, digits, '-', '_', '.' \
(no leading '-'/'.', max 100 chars)"
@ -395,16 +397,16 @@ async fn handle_create_repo(agent: &str, repo: &str) -> hive_agent_sock::Respons
};
}
let Some(core_token) = crate::forge::core_token() else {
return hive_agent_sock::Response::Err {
return hive_core_agent_sock::Response::Err {
message: "forge unavailable (no core token) — cannot create repo".to_owned(),
};
};
match crate::forge::create_agent_repo(agent, repo, &core_token).await {
Ok(full_name) => hive_agent_sock::Response::RepoCreated {
Ok(full_name) => hive_core_agent_sock::Response::RepoCreated {
clone_url: format!("{}/{full_name}.git", crate::forge::forge_http_base()),
full_name,
},
Err(e) => hive_agent_sock::Response::Err {
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("create repo {repo:?} failed: {e:#}"),
},
}
@ -417,7 +419,7 @@ async fn handle_get_agent_meta(
coord: &Arc<Coordinator>,
agent: &str,
name: Option<&str>,
) -> hive_agent_sock::Response {
) -> hive_core_agent_sock::Response {
let target = name.unwrap_or(agent);
// `name` is agent-supplied and flows into filesystem reads below
// (`read_agent_status_live`, `read_agent_matrix_identities` →
@ -428,7 +430,7 @@ async fn handle_get_agent_meta(
let target_id = match hive_types::Ident::parse(target) {
Ok(id) => id,
Err(reason) => {
return hive_agent_sock::Response::Err {
return hive_core_agent_sock::Response::Err {
message: format!("get_agent_meta: invalid agent name {target:?}: {reason}"),
};
}
@ -436,7 +438,7 @@ async fn handle_get_agent_meta(
let (status_text, status_set_at, running) =
crate::container_view::read_agent_status_live(&target_id).await;
let (hive_name, swarm_name) = crate::container_view::hive_swarm_names();
hive_agent_sock::Response::AgentMeta {
hive_core_agent_sock::Response::AgentMeta {
name: target.to_owned(),
running,
hyperhive_rev: crate::auto_update::current_flake_rev(&coord.hyperhive_flake),
@ -470,10 +472,10 @@ fn read_agent_matrix_identities(agent: &hive_types::Ident) -> Vec<hive_sh4re::Ma
}
/// `Status` — count of pending (unread) inbox messages for `agent`.
fn handle_status(coord: &Arc<Coordinator>, agent: &str) -> hive_agent_sock::Response {
fn handle_status(coord: &Arc<Coordinator>, agent: &str) -> hive_core_agent_sock::Response {
match coord.broker.count_pending(agent) {
Ok(unread) => hive_agent_sock::Response::Status { unread },
Err(e) => hive_agent_sock::Response::Err {
Ok(unread) => hive_core_agent_sock::Response::Status { unread },
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}
@ -485,15 +487,15 @@ fn handle_operator_msg(
coord: &Arc<Coordinator>,
agent: &str,
body: &str,
) -> hive_agent_sock::Response {
) -> hive_core_agent_sock::Response {
match coord.broker.send(&Message {
from: hive_sh4re::OPERATOR_RECIPIENT.to_owned(),
to: agent.to_owned(),
body: body.to_owned(),
in_reply_to: None,
}) {
Ok(()) => hive_agent_sock::Response::Ok,
Err(e) => hive_agent_sock::Response::Err {
Ok(()) => hive_core_agent_sock::Response::Ok,
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}
@ -501,10 +503,14 @@ fn handle_operator_msg(
/// `Recent` — the last `limit` inbox rows for `agent` (read-only,
/// doesn't consume).
fn handle_recent(coord: &Arc<Coordinator>, agent: &str, limit: u64) -> hive_agent_sock::Response {
fn handle_recent(
coord: &Arc<Coordinator>,
agent: &str,
limit: u64,
) -> hive_core_agent_sock::Response {
match coord.broker.recent_for(agent, limit) {
Ok(rows) => hive_agent_sock::Response::Recent { rows },
Err(e) => hive_agent_sock::Response::Err {
Ok(rows) => hive_core_agent_sock::Response::Recent { rows },
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}
@ -512,10 +518,10 @@ fn handle_recent(coord: &Arc<Coordinator>, agent: &str, limit: u64) -> hive_agen
/// `AckTurn` — mark `agent`'s in-flight delivered messages acked so
/// they don't redeliver on the next turn.
fn handle_ack_turn(coord: &Arc<Coordinator>, agent: &str) -> hive_agent_sock::Response {
fn handle_ack_turn(coord: &Arc<Coordinator>, agent: &str) -> hive_core_agent_sock::Response {
match coord.broker.ack_turn(agent) {
Ok(_n) => hive_agent_sock::Response::Ok,
Err(e) => hive_agent_sock::Response::Err {
Ok(_n) => hive_core_agent_sock::Response::Ok,
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}
@ -527,10 +533,10 @@ fn handle_ack_until(
coord: &Arc<Coordinator>,
agent: &str,
up_to: i64,
) -> hive_agent_sock::Response {
) -> hive_core_agent_sock::Response {
match coord.broker.ack_until(agent, up_to) {
Ok(count) => hive_agent_sock::Response::Acked { count },
Err(e) => hive_agent_sock::Response::Err {
Ok(count) => hive_core_agent_sock::Response::Acked { count },
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}
@ -538,15 +544,18 @@ fn handle_ack_until(
/// `RequeueInflight` — resurface `agent`'s unacked in-flight messages
/// (crash recovery on harness boot).
fn handle_requeue_inflight(coord: &Arc<Coordinator>, agent: &str) -> hive_agent_sock::Response {
fn handle_requeue_inflight(
coord: &Arc<Coordinator>,
agent: &str,
) -> hive_core_agent_sock::Response {
match coord.broker.requeue_inflight(agent) {
Ok(n) => {
if n > 0 {
tracing::info!(%agent, requeued = %n, "requeued in-flight messages");
}
hive_agent_sock::Response::Ok
hive_core_agent_sock::Response::Ok
}
Err(e) => hive_agent_sock::Response::Err {
Err(e) => hive_core_agent_sock::Response::Err {
message: format!("{e:#}"),
},
}

View file

@ -5,7 +5,7 @@
use std::sync::Arc;
use hive_agent_sock::Response;
use hive_core_agent_sock::Response;
use crate::coordinator::Coordinator;

View file

@ -6,7 +6,7 @@
use std::sync::Arc;
use hive_agent_sock::Response;
use hive_core_agent_sock::Response;
use crate::coordinator::Coordinator;