drop the hyperhive send/recv/ack_until tools: agents message over matrix
This commit is contained in:
parent
ccac95fcf4
commit
bffb2c07a8
1 changed files with 52 additions and 397 deletions
|
|
@ -24,10 +24,9 @@ mod args;
|
|||
mod render;
|
||||
|
||||
pub use args::{
|
||||
AckUntilArgs, CancelLooseEndArgs, CompactArgs, GetAgentMetaArgs, MarkTodosDoneArgs, RecvArgs,
|
||||
RemindArgs, SendArgs, SetStatusArgs,
|
||||
CancelLooseEndArgs, CompactArgs, GetAgentMetaArgs, MarkTodosDoneArgs, RemindArgs, SetStatusArgs,
|
||||
};
|
||||
pub use render::{annotate_retries, format_ack, format_agent_meta, format_recv};
|
||||
pub use render::{annotate_retries, format_ack, format_agent_meta};
|
||||
|
||||
use render::{
|
||||
dial_agent_socket, format_matrix_summary, local_reminders, local_todos, mark_local_todo_done,
|
||||
|
|
@ -140,92 +139,6 @@ impl AgentServer {
|
|||
// non-interactive `--print` mode with "permissions not granted yet".
|
||||
#[tool_router]
|
||||
impl AgentServer {
|
||||
#[tool(
|
||||
description = "Send a message through the hive-local broker to another hyperhive \
|
||||
agent on this hive. To talk to a peer agent, prefer matrix (a DM to the peer's \
|
||||
`user_id` from `get_agent_meta`) when you have the matrix MCP tools; use this \
|
||||
when you have none or the peer has no matrix account. Not for the operator: reach \
|
||||
them over matrix if you have the matrix MCP tools."
|
||||
)]
|
||||
async fn send(&self, Parameters(args): Parameters<SendArgs>) -> String {
|
||||
let log = format!("{args:?}");
|
||||
let to = args.to.clone();
|
||||
run_tool_envelope("send", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_core_agent_sock::Request::Send {
|
||||
to: args.to,
|
||||
body: args.body,
|
||||
in_reply_to: args.in_reply_to,
|
||||
})
|
||||
.await;
|
||||
annotate_retries(format_ack(resp, "send", format!("sent to {to}")), retries)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Pop messages from this agent's inbox. Returns one or more messages, or \
|
||||
an empty marker if nothing is waiting. Always an immediate 'anything pending?' peek \
|
||||
— never blocks. \n\n\
|
||||
**Single-message default**: with no args (or `max: 1`) you get the next message — \
|
||||
same behaviour the harness uses to drive a turn. \n\n\
|
||||
**When idle, prefer ending the turn over polling here.** Ending the turn is the \
|
||||
ONLY path that observes an in-container todo wake (bash-task completions, matrix \
|
||||
unread, forge activity) — that signal reaches the harness loop between turns, never \
|
||||
a live `recv` call, so looping on `recv` while idle means sitting blind until \
|
||||
something else wakes you. Ending the turn also checkpoints your session, and costs \
|
||||
no latency vs. polling for a real inbox message either way — the broker wakes the \
|
||||
next turn just as fast. \n\n\
|
||||
**Batch drain**: pass `max: N` (capped at 5) to drain up to N messages in one \
|
||||
round-trip. Use this when the wake prompt told you the inbox has more queued, or \
|
||||
any time you expect a burst — one tool call beats N consecutive single recvs. Empty \
|
||||
result reported the same way regardless of `max`. \n\n\
|
||||
After popping, the result appends a `(N more message(s) pending …)` line whenever the \
|
||||
inbox still has queued messages — so you know whether to drain again (or `ack_until`) \
|
||||
without a separate status check. No line means the inbox is empty."
|
||||
)]
|
||||
async fn recv(&self, Parameters(args): Parameters<RecvArgs>) -> String {
|
||||
let log = format!("{args:?}");
|
||||
run_tool_envelope("recv", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_core_agent_sock::Request::Recv {
|
||||
wait_seconds: None,
|
||||
max: args.max,
|
||||
})
|
||||
.await;
|
||||
annotate_retries(format_recv(resp), retries)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "Bulk-mark inbox messages handled: every message with broker id \
|
||||
<= `up_to` (ids show as `[msg #<id>]` in recv output and wake prompts) is \
|
||||
acked in one call — pending and already-delivered rows alike. Use this to \
|
||||
clear a backlog you've already triaged (e.g. a redelivered flood after a \
|
||||
container restart, or a pile of stale notifications) instead of draining it \
|
||||
one recv at a time: note the highest `[msg #N]` you've seen, then \
|
||||
`ack_until(up_to: N)`. Acked messages never redeliver. Only affects YOUR \
|
||||
inbox rows; messages newer than `up_to` stay queued. Returns how many rows \
|
||||
were newly acked."
|
||||
)]
|
||||
async fn ack_until(&self, Parameters(args): Parameters<AckUntilArgs>) -> String {
|
||||
let log = format!("{args:?}");
|
||||
run_tool_envelope("ack_until", log, async move {
|
||||
let (resp, retries) = self
|
||||
.dispatch(hive_core_agent_sock::Request::AckUntil { up_to: args.up_to })
|
||||
.await;
|
||||
let rendered = match resp {
|
||||
Ok(hive_core_agent_sock::Response::Acked { count }) => {
|
||||
format!("acked {count} message(s) up to id {}", args.up_to)
|
||||
}
|
||||
other => reply_err(other, "ack_until"),
|
||||
};
|
||||
annotate_retries(rendered, retries)
|
||||
})
|
||||
.await
|
||||
}
|
||||
|
||||
#[tool(
|
||||
description = "List loose ends pending against this agent: pending reminders \
|
||||
you scheduled. Also lists active \
|
||||
|
|
|
|||
Loading…
Reference in a new issue