cli_info_lines.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """The classic CLI's `/toolsets` and `/platforms` reports as plain lines.
  2. Shared by the classic CLI (`CLIInfoMixin.show_toolsets` / `_show_gateway_status`) and the shared
  3. gateway, which runs the same report for a local session's `slash.exec` (gateway/session_info_reads.py):
  4. one text on every surface, read where the state lives (the session's toolsets, the gateway's
  5. platform config).
  6. """
  7. from __future__ import annotations
  8. from agent.i18n import t
  9. def _box(title: str, width: int) -> list[str]:
  10. pad = width - len(title)
  11. return ["+" + "-" * width + "+", "|" + " " * (pad // 2) + title + " " * (pad - pad // 2) + "|",
  12. "+" + "-" * width + "+"]
  13. def toolsets_lines(enabled) -> list[str]:
  14. """``/toolsets``: every toolset, ``(*)`` on the ones *enabled* names."""
  15. from toolsets import get_all_toolsets, get_toolset_info
  16. out = ["", *_box(t("cli.toolsets.header"), 58), ""]
  17. for name in sorted(get_all_toolsets()):
  18. info = get_toolset_info(name)
  19. if info:
  20. marker = "(*)" if enabled and name in enabled else " "
  21. out.append(f" {marker} {name:<18} [{info['tool_count']:>2} tools] - {info['description']}")
  22. return [*out, "", f" {t('cli.toolsets.currently_enabled_legend')}", "",
  23. f" {t('cli.toolsets.tip_enable_all')}", f" {t('cli.toolsets.example')}", ""]
  24. def platforms_lines() -> list[str]:
  25. """``/platforms``: the messaging platforms the profile's gateway config enables."""
  26. from hermes_constants import display_hermes_home
  27. from gateway.config import load_gateway_config, Platform
  28. out = ["", *_box(t("cli.gateway_status.header"), 60), ""]
  29. config_file = f"{display_hermes_home()}/config.yaml"
  30. try:
  31. config = load_gateway_config()
  32. out += [f" {t('cli.gateway_status.platform_config_header')}", " " + "-" * 55]
  33. platform_status = {
  34. Platform.TELEGRAM: ("Telegram", "TELEGRAM_BOT_TOKEN"),
  35. Platform.DISCORD: ("Discord", "DISCORD_BOT_TOKEN"),
  36. Platform.SLACK: ("Slack", "SLACK_BOT_TOKEN"),
  37. Platform.WHATSAPP: ("WhatsApp", "WHATSAPP_ENABLED")}
  38. for platform, (name, env_var) in platform_status.items():
  39. pconfig = config.platforms.get(platform)
  40. if pconfig and pconfig.enabled:
  41. home = config.get_home_channel(platform)
  42. home_str = f" → {home.name}" if home else ""
  43. out.append(f" ✓ {name:<12} {t('cli.gateway_status.enabled')}{home_str}")
  44. else:
  45. out.append(f" ○ {name:<12} {t('cli.gateway_status.not_configured', env_var=env_var)}")
  46. return [*out, "", f" {t('cli.gateway_status.conversations_persist')}", "",
  47. f" {t('cli.gateway_status.to_start')}", " python cli.py --gateway", "",
  48. f" {t('cli.gateway_status.config_file', path=config_file)}", ""]
  49. except Exception as e: # health: allow BLE001 -- moved unchanged from CLIInfoMixin._show_gateway_status (main): any config load failure prints the setup steps
  50. return [*out, f" {t('cli.gateway_status.load_error', error=str(e))}", "",
  51. f" {t('cli.gateway_status.to_configure')}", f" {t('cli.gateway_status.step_env_vars')}",
  52. " TELEGRAM_BOT_TOKEN=your_token", " DISCORD_BOT_TOKEN=your_token",
  53. f" {t('cli.gateway_status.step_config', path=config_file)}", ""]