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
/// into the hyperhive broker.
Mcp,
/// Agent-only: inject a wake-up event into this agent's inbox so
/// the next turn fires with the given body. Intended for extra MCP
/// servers / helpers (matrix bridge, scraper, webhook listener)
/// that need to nudge claude on external events. Refused when
/// `HIVE_ROLE=manager` — the manager surface has no `Wake`
/// equivalent.
/// Inject a wake-up event into this harness's inbox so the next
/// turn fires with the given body. Intended for extra MCP servers
/// / helpers (matrix bridge, scraper, webhook listener, etc.) that
/// need to nudge claude on external events. Available on both
/// agent and manager roles — closes #693, mirrors the
/// `AgentRequest::Wake` / `ManagerRequest::Wake` pair already on
/// the wire.
Wake {
#[arg(long)]
from: String,
@ -102,8 +103,8 @@ async fn main() -> Result<()> {
(Role::Agent, Cmd::Mcp) => mcp::serve_agent_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::Manager, Cmd::Wake { .. }) => {
bail!("wake is agent-only — manager has no equivalent surface")
(Role::Manager, Cmd::Wake { from, body }) => {
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)
}
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:?}"),
}
}