hyperhive/hive-forge-notify/src/main.rs
atlas 246c9471b1 refactor(hive-agent): split the forge notification poller into its own crate
The poller was a `tokio::spawn` inside the `hive-agent` serve loop. It
never needed anything from that loop except a socket path, so being
in-process bought nothing and cost two things: a harness restart took
forge notifications down with it, and the whole forge/HTTP dependency
tree was linked into the serve-loop binary.

It is now `hive-forge-notify`, a per-agent daemon with its own systemd
unit, a sibling of `hive-bash-daemon` and `hive-matrix-daemon`. Same
contract as those two: it reaches the harness only by upserting todos on
the in-agent socket, and nowhere else.

The module moves verbatim (`notify.rs`) — the formatters, the activation
gates, the dedupe map and all 33 tests are unchanged. Only the socket
call sites are rewritten, onto a small local `todo_client` rather than
the harness's. That mirrors what both sibling daemons already do, and
the etiquette differs on purpose: the harness's client carries a 60s
backoff schedule sized to ride out a hive-c0re restart, which its
callers need because they have no retry of their own. This poller's two
call sites both sit inside the 30s poll loop and both treat a failure as
"leave the thread unread, try next tick", so the poll interval already
is the retry; a second backoff would only stack sleeps and delay the
rest of the batch.

The unit is `Restart=on-failure`, not `always`. An agent with no forge
account is a supported configuration and the poller reports it by
logging why and exiting 0 — under `always` that clean exit would be a
restart loop on every forge-less agent.

`forgejo-api`, `url` and `time` drop out of `hive-agent`'s dependencies
with the module.

Also corrects docs that outlived the code they described: the persisted
`forge_cursor` field is long gone (forge's own read-state is the durable
record of what has been delivered), but `docs/persistence.md` and the
`harness_state` module docs still documented it as live.
2026-07-26 21:30:29 +02:00

38 lines
1.6 KiB
Rust

//! `hive-forge-notify` binary — long-running per-agent Forgejo
//! notification poller. Polls the agent's unread notification list,
//! formats each thread into a short summary, and pushes it as a todo
//! (loose-ends v2) on the harness's in-agent socket so claude drives a
//! turn to handle it.
//!
//! Takes no arguments: everything comes from the environment the
//! per-agent systemd unit provides — `HIVE_FORGE_URL` (forwarded into
//! every container by the meta flake), `HYPERHIVE_STATE_DIR` (where the
//! agent's `forge-token` lives) and `HIVE_AGENT_SOCKET` (the harness's
//! todo socket). When the forge is not configured for this agent the
//! poller logs why and exits 0 — the unit is `Restart=on-failure`, so a
//! forge-less agent settles instead of restart-looping.
mod notify;
mod todo_client;
#[tokio::main]
async fn main() {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_env("RUST_LOG")
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.init();
let socket = std::env::var_os("HIVE_AGENT_SOCKET").map_or_else(
|| std::path::PathBuf::from(hive_agent_sock::DEFAULT_AGENT_SOCKET),
std::path::PathBuf::from,
);
tracing::info!(socket = %socket.display(), "hive-forge-notify starting");
// Returns only when the forge is not configured (or the token never
// arrives); otherwise loops forever. Either way there is nothing left
// for this process to do, so fall off the end and exit 0.
notify::run(socket).await;
}