gateway_status_notes.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. """Notes `hermes gateway status` prints beside the running/not-running verdict."""
  2. from __future__ import annotations
  3. from hermes_cli.config import get_hermes_home
  4. def _incompatible_owner_verdict() -> str | None:
  5. """``incompatible: <reason>`` when the gateway answering for this home is one this Hermes's clients
  6. (TUI, Desktop, chat) refuse, e.g. an older Hermes's daemon left running across an upgrade."""
  7. from hermes_cli.gateway_runtime import discover_gateway_endpoint
  8. try:
  9. observed = discover_gateway_endpoint(get_hermes_home(), timeout=1.5)
  10. except (OSError, ValueError): # discovery reports peers as verdicts; only a bad home lands here
  11. return None
  12. if observed.state != "incompatible":
  13. return None
  14. return f"incompatible: {observed.reason_code or 'unknown'}"
  15. def report_incompatible_owner(pids) -> bool:
  16. """Print ✗ (with the fix) when the running gateway cannot serve this Hermes; True if printed.
  17. ``pids`` names the scanned processes for the manual-run line; empty for a service-managed one."""
  18. stale = _incompatible_owner_verdict()
  19. if not stale:
  20. return False
  21. running = f"Gateway is running (PID: {', '.join(map(str, pids))})" if pids else "The running gateway"
  22. print(f"✗ {running} but cannot serve this Hermes ({stale})")
  23. print(" It was started by another Hermes version; TUI, Desktop and chat cannot attach to it.")
  24. print(" Replace it with this version:")
  25. print(" hermes gateway restart")
  26. return True
  27. def print_standalone_by_config() -> None:
  28. """Default-profile status: name the profiles that opted out of the host multiplexer by config,
  29. so the served set the host gateway reports is not mistaken for the installed roster."""
  30. from hermes_cli.profiles import get_active_profile_name, profiles_to_serve
  31. if (get_active_profile_name() or "default") != "default":
  32. return
  33. roster = {name for name, _home in profiles_to_serve(True, include_standalone=True)}
  34. served = {name for name, _home in profiles_to_serve(True)}
  35. names = sorted(roster - served - {"default"})
  36. if names:
  37. print(f"standalone by config (temporary compatibility shim): {', '.join(names)}")