manager: receive forge notifications (ManagerRequest::Wake)

This commit is contained in:
damocles 2026-05-21 18:33:39 +02:00 committed by Mara
parent d5009cd175
commit 3b44410427
4 changed files with 46 additions and 11 deletions

View file

@ -82,6 +82,7 @@ async fn main() -> Result<()> {
files.clone(),
turn_lock.clone(),
));
tokio::spawn(hive_ag3nt::forge_notify::run(cli.socket.clone(), true));
match initial {
LoginState::Online => {
serve(

View file

@ -27,10 +27,15 @@ const HTTP_TIMEOUT_SECS: u64 = 10;
/// Maximum characters of a body/comment to include in the wake message.
const BODY_TRUNCATE: usize = 500;
/// Spawn point: called once from `hive-ag3nt serve`. Returns immediately if
/// the forge is not configured for this agent. Otherwise loops forever,
/// polling every `POLL_INTERVAL_SECS` seconds. Errors are never fatal.
pub async fn run(socket: PathBuf) {
/// Spawn point: called once from `hive-ag3nt serve` (agent) or
/// `hive-m1nd serve` (manager). Returns immediately if the forge is not
/// configured. Otherwise loops forever, polling every
/// `POLL_INTERVAL_SECS` seconds. Errors are never fatal.
///
/// `is_manager`: when true, wakes the inbox via `ManagerRequest::Wake`
/// instead of `AgentRequest::Wake` (the manager socket rejects the agent
/// request type).
pub async fn run(socket: PathBuf, is_manager: bool) {
let forge_url = match std::env::var("HIVE_FORGE_URL") {
Ok(u) if !u.is_empty() => u,
_ => {
@ -77,7 +82,7 @@ pub async fn run(socket: PathBuf) {
loop {
interval.tick().await;
poll_once(&client, &forge_url, &token, &socket).await;
poll_once(&client, &forge_url, &token, &socket, is_manager).await;
}
}
@ -208,7 +213,7 @@ async fn format_notification(
}
}
async fn poll_once(client: &reqwest::Client, forge_url: &str, token: &str, socket: &Path) {
async fn poll_once(client: &reqwest::Client, forge_url: &str, token: &str, socket: &Path, is_manager: bool) {
let url = format!("{forge_url}/api/v1/notifications?all=false&limit=50");
let resp = match client
.get(&url)
@ -250,12 +255,25 @@ async fn poll_once(client: &reqwest::Client, forge_url: &str, token: &str, socke
let body = format_notification(client, token, notif).await;
let req = hive_sh4re::AgentRequest::Wake {
from: "forge".to_owned(),
body,
let delivered = if is_manager {
let req = hive_sh4re::ManagerRequest::Wake {
from: "forge".to_owned(),
body,
};
crate::client::request::<_, hive_sh4re::ManagerResponse>(socket, &req)
.await
.map(|_| ())
} else {
let req = hive_sh4re::AgentRequest::Wake {
from: "forge".to_owned(),
body,
};
crate::client::request::<_, hive_sh4re::AgentResponse>(socket, &req)
.await
.map(|_| ())
};
match crate::client::request::<_, hive_sh4re::AgentResponse>(socket, &req).await {
Ok(_) => {
match delivered {
Ok(()) => {
debug!(%id, "forge_notify: delivered");
}
Err(e) => {