"""Reports hive registry (swarm address book) reachability into LLM context.
Silent while the registry is reachable (token economy); when it is down the
agent is told explicitly — this system is supposed to be able to fix its own
network, so it must notice a fallen registry instead of silently ignoring it.
"""
from navi.config import settings
name = "hive_status"
description = "Injects hive registry reachability (swarm address book) status."
global_provider = True
async def get_context() -> str | None:
if not settings.hive_url:
return None # standalone navi — no registry, nothing to report
from navi.swarm import get_announcer
announcer = get_announcer()
if announcer is None:
return None # HIVE_URL set but key missing — announce disabled; already warned in logs
status = announcer.get_status()
if status.get("reachable") is True:
return None # healthy: stay out of the context
if status.get("reachable") is None:
return None # hasn't ticked yet (startup moment); not a failure
return (
f"[System] Hive registry ({status['url']}) is unreachable "
f"since {status['down_since']}: {status['last_error']}. "
"Other navi agents cannot discover this machine while the registry is down. "
"If the current task depends on the swarm, investigate the registry host."
)