config_show.py 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. """``hermes config`` / ``hermes config show``: the read-only configuration summary.
  2. Split out of ``hermes_cli.config``; config names are read through the module at call time
  3. (``_cfg.<name>``) so ``hermes_cli.config.<name>`` patch seams hold.
  4. """
  5. from typing import Any, Dict
  6. from hermes_cli import config as _cfg
  7. from hermes_cli import managed_scope
  8. from hermes_cli.colors import Colors, color
  9. def _section(title: str) -> None:
  10. print()
  11. print(color(f"◆ {title}", Colors.CYAN, Colors.BOLD))
  12. def _show_managed_banner() -> None:
  13. """Surface administrator-pinned settings so the user knows why a config.yaml value may not
  14. be the effective one."""
  15. managed_keys = managed_scope.managed_config_keys()
  16. managed_env = managed_scope.load_managed_env()
  17. if not managed_keys and not managed_env:
  18. return
  19. print()
  20. print(color(
  21. f" ⚷ Some settings are managed by your administrator ({managed_scope.get_managed_dir()}) "
  22. f"and cannot be changed", Colors.YELLOW, Colors.BOLD))
  23. for label, keys in (("config", managed_keys), ("env", managed_env)):
  24. if keys:
  25. print(color(f" Managed {label} keys: {', '.join(sorted(keys))}", Colors.YELLOW))
  26. _SHOW_CONFIG_API_KEYS = (
  27. ("OPENROUTER_API_KEY", "OpenRouter"),
  28. ("VOICE_TOOLS_OPENAI_KEY", "OpenAI (STT/TTS)"),
  29. ("EXA_API_KEY", "Exa"),
  30. ("PARALLEL_API_KEY", "Parallel"),
  31. ("FIRECRAWL_API_KEY", "Firecrawl"),
  32. ("TAVILY_API_KEY", "Tavily"),
  33. ("PERPLEXITY_API_KEY", "Perplexity"),
  34. ("BROWSERBASE_API_KEY", "Browserbase"),
  35. ("BROWSER_USE_API_KEY", "Browser Use"),
  36. ("FAL_KEY", "FAL"))
  37. def _show_model_section(config: dict[str, Any]) -> None:
  38. _section("Model")
  39. print(f" Model: {_cfg.redact_config_value(config.get('model', 'not set'))}")
  40. cfg_max_turns = config.get('agent', {}).get('max_turns', _cfg.DEFAULT_CONFIG['agent']['max_turns'])
  41. print(f" Max turns: {cfg_max_turns}")
  42. # Read the .env FILE directly so a stale HERMES_MAX_ITERATIONS ghost is caught even when the
  43. # gateway bridge already overrode os.environ.
  44. try:
  45. env_ghost = _cfg.load_env().get("HERMES_MAX_ITERATIONS")
  46. except Exception:
  47. env_ghost = None
  48. if env_ghost is not None and str(env_ghost).strip() != str(cfg_max_turns).strip():
  49. print(color(f" ⚠ .env has stale HERMES_MAX_ITERATIONS={env_ghost} "
  50. f"(run 'hermes doctor --fix' to remove)", Colors.YELLOW))
  51. def _show_display_section(config: dict[str, Any]) -> None:
  52. _section("Display")
  53. display = config.get('display', {})
  54. try:
  55. from hermes_cli.personality import active_personality_name
  56. active_personality = active_personality_name(config) or 'none'
  57. except Exception:
  58. active_personality = display.get('personality') or 'none'
  59. on_off = lambda flag: 'on' if flag else 'off'
  60. print(f" Personality: {active_personality}")
  61. print(f" Reasoning: {on_off(display.get('show_reasoning', True))}")
  62. print(
  63. f" Bell: complete={on_off(display.get('bell_on_complete', False))}, "
  64. f"prompt={on_off(display.get('bell_on_prompt', False))}")
  65. ump = display.get('user_message_preview', {})
  66. ump = ump if isinstance(ump, dict) else {}
  67. print(f" User preview: first {ump.get('first_lines', 2)} line(s), last {ump.get('last_lines', 2)} line(s)")
  68. def _show_terminal_section(config: dict[str, Any]) -> None:
  69. _section("Terminal")
  70. terminal = config.get('terminal', {})
  71. print(f" Backend: {terminal.get('backend', 'local')}")
  72. print(f" Working dir: {terminal.get('cwd', '.')}")
  73. print(f" Timeout: {terminal.get('timeout', 60)}s")
  74. configured = lambda *names: 'configured' if all(_cfg.get_env_value(n) for n in names) else '(not set)'
  75. from hermes_cli.config_defaults import DEFAULT_SANDBOX_IMAGE as default_img, DEFAULT_VERCEL_IMAGE as _DEFAULT_VERCEL_IMAGE
  76. backend_lines = {
  77. 'docker': lambda: [f" Docker image: {terminal.get('docker_image', default_img)}"],
  78. 'modal': lambda: [
  79. f" Modal image: {terminal.get('modal_image', default_img)}",
  80. f" Modal token: {configured('MODAL_TOKEN_ID')}"],
  81. 'daytona': lambda: [
  82. f" Daytona image: {terminal.get('daytona_image', default_img)}",
  83. f" API key: {configured('DAYTONA_API_KEY')}"],
  84. 'vercel_sandbox': lambda: [
  85. f" Vercel image: {terminal.get('vercel_runtime') or terminal.get('vercel_image') or _DEFAULT_VERCEL_IMAGE}",
  86. f" Vercel auth: {'configured' if _cfg.get_env_value('VERCEL_OIDC_TOKEN') or (_cfg.get_env_value('VERCEL_TOKEN') and _cfg.get_env_value('VERCEL_PROJECT_ID') and _cfg.get_env_value('VERCEL_TEAM_ID')) else '(not set)'}",
  87. ],
  88. 'ssh': lambda: [
  89. f" SSH host: {_cfg.get_env_value('TERMINAL_SSH_HOST') or '(not set)'}",
  90. f" SSH user: {_cfg.get_env_value('TERMINAL_SSH_USER') or '(not set)'}"]}
  91. for line in backend_lines.get(terminal.get('backend'), list)():
  92. print(line)
  93. def _show_compression_section(config: dict[str, Any]) -> None:
  94. _section("Context Compression")
  95. compression = config.get('compression', {})
  96. enabled = compression.get('enabled', True)
  97. print(f" Enabled: {'yes' if enabled else 'no'}")
  98. if not enabled:
  99. return
  100. print(f" Threshold: {compression.get('threshold', 0.50) * 100:.0f}%")
  101. tt = compression.get('threshold_tokens')
  102. try:
  103. if tt is not None and int(tt) > 0:
  104. print(f" Token cap: {int(tt):,} tokens (takes lower of ratio vs absolute)")
  105. except (TypeError, ValueError):
  106. pass
  107. print(f" Target ratio: {compression.get('target_ratio', 0.20) * 100:.0f}% of threshold preserved")
  108. print(f" Protect last: {compression.get('protect_last_n', 20)} messages")
  109. print(f" Protect first: {compression.get('protect_first_n', 3)} non-system head messages")
  110. aux_comp = config.get('auxiliary', {}).get('compression', {})
  111. print(f" Model: {aux_comp.get('model', '') or '(auto)'}")
  112. comp_provider = aux_comp.get('provider', 'auto')
  113. if comp_provider and comp_provider != 'auto':
  114. print(f" Provider: {comp_provider}")
  115. def _show_aux_overrides(config: dict[str, Any]) -> None:
  116. aux_tasks = {"Vision": config.get('auxiliary', {}).get('vision', {})}
  117. overrides = {
  118. label: (t.get('provider', 'auto'), t.get('model', ''))
  119. for label, t in aux_tasks.items()
  120. if t.get('provider', 'auto') != 'auto' or t.get('model', '')}
  121. if not overrides:
  122. return
  123. _section("Auxiliary Models (overrides)")
  124. for label, (prov, mdl) in overrides.items():
  125. parts = [f"provider={prov}"] + ([f"model={mdl}"] if mdl else [])
  126. print(f" {label:12s} {', '.join(parts)}")
  127. def _show_skill_settings() -> None:
  128. try:
  129. from agent.skill_utils import discover_all_skill_config_vars, resolve_skill_config_values
  130. skill_vars = discover_all_skill_config_vars()
  131. if not skill_vars:
  132. return
  133. resolved = resolve_skill_config_values(skill_vars)
  134. _section("Skill Settings")
  135. for var in skill_vars:
  136. value = resolved.get(var["key"], "")
  137. display_val = str(value) if value else color("(not set)", Colors.DIM)
  138. skill_tag = color(f"[{var.get('skill', '')}]", Colors.DIM)
  139. print(f" {var['key']:<20s} {display_val} {skill_tag}")
  140. except Exception:
  141. pass
  142. def show_config():
  143. """Display current configuration."""
  144. config = _cfg.load_config()
  145. print()
  146. print(color("┌─────────────────────────────────────────────────────────┐", Colors.CYAN))
  147. print(color("│ ☤ Hermes Configuration │", Colors.CYAN))
  148. print(color("└─────────────────────────────────────────────────────────┘", Colors.CYAN))
  149. _show_managed_banner()
  150. _section("Paths")
  151. print(f" Config: {_cfg.get_config_path()}")
  152. print(f" Secrets: {_cfg.get_env_path()}")
  153. print(f" Install: {_cfg.get_project_root()}")
  154. _section("API Keys")
  155. for env_key, name in _SHOW_CONFIG_API_KEYS:
  156. print(f" {name:<14} {_cfg.redact_key(_cfg.get_env_value(env_key))}")
  157. from hermes_cli.auth import get_anthropic_key
  158. print(f" {'Anthropic':<14} {_cfg.redact_key(get_anthropic_key())}")
  159. _show_model_section(config)
  160. _show_display_section(config)
  161. _show_terminal_section(config)
  162. _section("Timezone")
  163. tz = config.get('timezone', '')
  164. print(f" Timezone: {tz or color('(server-local)', Colors.DIM)}")
  165. _show_compression_section(config)
  166. _show_aux_overrides(config)
  167. _section("Messaging Platforms")
  168. for label, env_key in (("Telegram", "TELEGRAM_BOT_TOKEN"), ("Discord", "DISCORD_BOT_TOKEN")):
  169. state = 'configured' if _cfg.get_env_value(env_key) else color('not configured', Colors.DIM)
  170. print(f" {label + ':':<13} {state}")
  171. _show_skill_settings()
  172. print()
  173. print(color("─" * 60, Colors.DIM))
  174. print(color(" hermes config edit # Edit config file", Colors.DIM))
  175. print(color(" hermes config set <key> <value>", Colors.DIM))
  176. print(color(" hermes setup # Run setup wizard", Colors.DIM))
  177. print()