harness: enable hive wake on manager role (#693)

This commit is contained in:
damocles 2026-05-31 10:15:54 +02:00 committed by Mara
commit a4cd0518a0

View file

@ -55,12 +55,13 @@ enum Cmd {
/// `--mcp-config`; tools dispatch through `/run/hive/mcp.sock` back /// `--mcp-config`; tools dispatch through `/run/hive/mcp.sock` back
/// into the hyperhive broker. /// into the hyperhive broker.
Mcp, Mcp,
/// Agent-only: inject a wake-up event into this agent's inbox so /// Inject a wake-up event into this harness's inbox so the next
/// the next turn fires with the given body. Intended for extra MCP /// turn fires with the given body. Intended for extra MCP servers
/// servers / helpers (matrix bridge, scraper, webhook listener) /// / helpers (matrix bridge, scraper, webhook listener, etc.) that
/// that need to nudge claude on external events. Refused when /// need to nudge claude on external events. Available on both
/// `HIVE_ROLE=manager` — the manager surface has no `Wake` /// agent and manager roles — closes #693, mirrors the
/// equivalent. /// `AgentRequest::Wake` / `ManagerRequest::Wake` pair already on
/// the wire.
Wake { Wake {
#[arg(long)] #[arg(long)]
from: String, from: String,
@ -102,8 +103,8 @@ async fn main() -> Result<()> {
(Role::Agent, Cmd::Mcp) => mcp::serve_agent_stdio(cli.socket).await, (Role::Agent, Cmd::Mcp) => mcp::serve_agent_stdio(cli.socket).await,
(Role::Manager, Cmd::Mcp) => mcp::serve_manager_stdio(cli.socket).await, (Role::Manager, Cmd::Mcp) => mcp::serve_manager_stdio(cli.socket).await,
(Role::Agent, Cmd::Wake { from, body }) => agent_wake(&cli.socket, from, body).await, (Role::Agent, Cmd::Wake { from, body }) => agent_wake(&cli.socket, from, body).await,
(Role::Manager, Cmd::Wake { .. }) => { (Role::Manager, Cmd::Wake { from, body }) => {
bail!("wake is agent-only — manager has no equivalent surface") manager_wake(&cli.socket, from, body).await
} }
} }
} }
@ -702,3 +703,20 @@ async fn manager_post_turn_counts(socket: &Path) -> (Option<u64>, Option<u64>) {
}; };
(threads, reminders) (threads, reminders)
} }
async fn manager_wake(socket: &Path, from: String, body: String) -> Result<()> {
let body = if body == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)?;
buf
} else {
body
};
let resp: ManagerResponse =
client::request(socket, &ManagerRequest::Wake { from, body }).await?;
match resp {
ManagerResponse::Ok => Ok(()),
ManagerResponse::Err { message } => anyhow::bail!("wake: {message}"),
other => anyhow::bail!("wake: unexpected response {other:?}"),
}
}