"""Slash-command catalog for the app's "/" drawer. Derived from hermes' central ``COMMAND_REGISTRY`` (``hermes_cli/commands.py``) — the same source the gateway help text and the Telegram command menu use — restricted to commands available on gateway surfaces, plus plugin-registered commands. Never raises: any import/attribute problem (code skew between the plugin and the hermes checkout) degrades to an empty catalog, so the app's drawer simply stays closed. """ import logging from typing import Any logger = logging.getLogger(__name__) def _slash_command_catalog() -> list[dict[str, Any]]: try: from hermes_cli import commands as hermes_commands except Exception: logger.warning( "iris: slash catalog unavailable (hermes_cli.commands import failed)", exc_info=True, ) return [] def _entry( name: str, description: str, args_hint: str, category: str, aliases: list[str] ) -> dict[str, Any]: return { "name": f"/{name}", "description": description, "args_hint": args_hint or "", "category": category, "aliases": [f"/{a}" for a in aliases], } entries: list[dict[str, Any]] = [] try: overrides = hermes_commands._resolve_config_gates() for cmd in hermes_commands.COMMAND_REGISTRY: if not hermes_commands._is_gateway_available(cmd, overrides): continue entries.append( _entry(cmd.name, cmd.description, cmd.args_hint, cmd.category, list(cmd.aliases)) ) except Exception: # Code skew: the private helpers moved. Fall back to the plain # cli_only filter (config-gated commands are dropped, acceptable). logger.warning("iris: slash catalog fell back to cli_only filter", exc_info=True) entries = [ _entry(cmd.name, cmd.description, cmd.args_hint, cmd.category, list(cmd.aliases)) for cmd in hermes_commands.COMMAND_REGISTRY if not cmd.cli_only ] try: for name, description, args_hint in hermes_commands._iter_plugin_command_entries(): entries.append(_entry(name, description, args_hint, "Plugin", [])) except Exception: # Best-effort: a broken plugin-command registry should not break the # built-in catalog, so the failure is intentionally swallowed. logger.debug("iris: plugin command enumeration failed", exc_info=True) return entries