refactor(#2581): carve per-agent mcp.sock protocol into hive-agent-sock crate

This commit is contained in:
damocles 2026-07-19 14:22:37 +02:00 committed by mara
commit d0beec8a40
26 changed files with 603 additions and 542 deletions

View file

@ -19,6 +19,7 @@ time.workspace = true
futures-util = "0.3"
clap.workspace = true
hive-claude.workspace = true
hive-agent-sock.workspace = true
hive-sh4re.workspace = true
rmcp.workspace = true
rusqlite.workspace = true

View file

@ -1083,11 +1083,11 @@ async fn poll_once(
continue;
};
let req = hive_sh4re::Request::Wake {
let req = hive_agent_sock::Request::Wake {
from: "forge".to_owned(),
body,
};
let deliver_result = crate::client::request::<_, hive_sh4re::Response>(socket, &req)
let deliver_result = crate::client::request::<_, hive_agent_sock::Response>(socket, &req)
.await
.map(|_| ());
match deliver_result {

View file

@ -42,7 +42,8 @@ use crate::login::LoginState;
use crate::turn_stats::TurnStats;
use anyhow::Result;
use clap::Parser;
use hive_sh4re::{AgentRequest, AgentResponse, HelperEvent, SYSTEM_SENDER};
use hive_agent_sock::{AgentRequest, AgentResponse};
use hive_sh4re::{HelperEvent, SYSTEM_SENDER};
#[derive(Parser)]
#[command(name = "hive-agent", about = "hyperhive harness serve loop")]

View file

@ -23,15 +23,20 @@ pub(super) async fn post_send(
if body.is_empty() {
return error_response(StatusCode::BAD_REQUEST, "send: `body` required");
}
match super::broker_request(&state.socket, &hive_sh4re::Request::OperatorMsg { body }).await {
match super::broker_request(
&state.socket,
&hive_agent_sock::Request::OperatorMsg { body },
)
.await
{
// 200 instead of 303 → the client doesn't refetch /api/state.
// The operator message becomes a broker `Sent` (already shown
// server-side in the dashboard); on the agent side, the
// resulting `TurnStart` SSE event drives the terminal + the
// inbox row gets consumed by the time `TurnEnd` fires the
// existing turn-end refresh.
Ok(hive_sh4re::Response::Ok) => (axum::http::StatusCode::OK, "ok").into_response(),
Ok(hive_sh4re::Response::Err { message }) => error_response(
Ok(hive_agent_sock::Response::Ok) => (axum::http::StatusCode::OK, "ok").into_response(),
Ok(hive_agent_sock::Response::Err { message }) => error_response(
StatusCode::INTERNAL_SERVER_ERROR,
&format!("send failed: {message}"),
),

View file

@ -302,11 +302,11 @@ enum BrokerError {
/// web-UI handler that talks to the broker goes through it.
async fn broker_request(
socket: &Path,
req: &hive_sh4re::Request,
) -> std::result::Result<hive_sh4re::Response, BrokerError> {
req: &hive_agent_sock::Request,
) -> std::result::Result<hive_agent_sock::Response, BrokerError> {
match tokio::time::timeout(
SOCKET_FETCH_TIMEOUT,
crate::client::request::<_, hive_sh4re::Response>(socket, req),
crate::client::request::<_, hive_agent_sock::Response>(socket, req),
)
.await
{

View file

@ -366,8 +366,8 @@ async fn recent_inbox(socket: &std::path::Path) -> Vec<hive_sh4re::InboxRow> {
const LIMIT: u64 = 30;
// Deadline-bounded (via `broker_request`): `/api/state` must render even
// when hive-c0re is busy — an empty inbox section beats a hung snapshot.
match super::broker_request(socket, &hive_sh4re::Request::Recent { limit: LIMIT }).await {
Ok(hive_sh4re::Response::Recent { rows }) => rows,
match super::broker_request(socket, &hive_agent_sock::Request::Recent { limit: LIMIT }).await {
Ok(hive_agent_sock::Response::Recent { rows }) => rows,
_ => Vec::new(),
}
}

View file

@ -35,14 +35,14 @@ async fn fetch_reminder_stats(
) -> Option<hive_sh4re::ReminderStats> {
match super::broker_request(
socket,
&hive_sh4re::Request::ReminderRollup {
&hive_agent_sock::Request::ReminderRollup {
since_secs: window_secs,
agent: None,
},
)
.await
{
Ok(hive_sh4re::Response::ReminderRollup(stats)) => Some(stats),
Ok(hive_agent_sock::Response::ReminderRollup(stats)) => Some(stats),
_ => None,
}
}
@ -57,14 +57,14 @@ async fn fetch_reminder_stats(
pub(super) async fn api_loose_ends(State(state): State<AppState>) -> Response {
match super::broker_request(
&state.socket,
&hive_sh4re::Request::GetLooseEnds { agent: None },
&hive_agent_sock::Request::GetLooseEnds { agent: None },
)
.await
{
Ok(hive_sh4re::Response::LooseEnds { loose_ends }) => {
Ok(hive_agent_sock::Response::LooseEnds { loose_ends }) => {
axum::Json(serde_json::json!({ "loose_ends": loose_ends })).into_response()
}
Ok(hive_sh4re::Response::Err { message }) => error_response(
Ok(hive_agent_sock::Response::Err { message }) => error_response(
StatusCode::INTERNAL_SERVER_ERROR,
&format!("get_loose_ends: {message}"),
),