command_manifest.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """Gateway-declared Discord slash-command manifest for the relay lane (Phase 4).
  2. The CONNECTOR holds the Discord token, so the gateway declares its command set on
  3. the ``hello`` frame and the connector reconciles Discord's registration (idempotent,
  4. best-effort). MIRRORS the native tree (plugins/platforms/discord/adapter.py
  5. ``_register_slash_commands``) — same names, same descriptions; interactions return
  6. via the passthrough plane as ordinary "/name args" COMMAND events, so a new entry
  7. needs NO new handler. Wire shape per entry: {name, description, options?} with
  8. Discord option objects verbatim; names must match ``[a-z0-9_-]{1,32}`` (the
  9. connector drops invalid entries, never the whole manifest).
  10. """
  11. from __future__ import annotations
  12. from typing import Any, Dict, List
  13. # Discord option type 3 = STRING.
  14. _STR = 3
  15. def _opt(name: str, description: str, *, choices: list[str] | None = None) -> dict[str, Any]:
  16. row: dict[str, Any] = {
  17. "type": _STR,
  18. "name": name,
  19. "description": description,
  20. "required": False,
  21. }
  22. if choices:
  23. row["choices"] = [{"name": c, "value": c} for c in choices]
  24. return row
  25. def _cmd(name: str, description: str, *options: dict[str, Any]) -> dict[str, Any]:
  26. row: dict[str, Any] = {"name": name, "description": description}
  27. if options:
  28. row["options"] = list(options)
  29. return row
  30. _REASONING_CHOICES = [
  31. "none", "minimal", "low", "medium", "high", "xhigh", "max", "ultra",
  32. "reset", "show", "hide",
  33. ]
  34. def build_relay_command_manifest() -> list[dict[str, Any]]:
  35. """The relay lane's Discord slash-command manifest (native-tree mirror)."""
  36. return [
  37. _cmd("new", "Start a new conversation"),
  38. _cmd("reset", "Reset your Hermes session"),
  39. _cmd("model", "Show or change the model",
  40. _opt("name", "Model name. Leave empty to see current.")),
  41. _cmd("reasoning", "Show/change reasoning effort, or toggle showing it",
  42. _opt("effort", "Level, reset, or show/hide. Leave empty to see current.",
  43. choices=_REASONING_CHOICES)),
  44. _cmd("personality", "Set a personality",
  45. _opt("name", "Personality name. Leave empty to list.")),
  46. _cmd("retry", "Retry your last message"),
  47. _cmd("undo", "Remove the last exchange"),
  48. _cmd("status", "Show Hermes session status"),
  49. _cmd("sethome", "Set this chat as the home channel"),
  50. _cmd("stop", "Stop the running Hermes agent"),
  51. _cmd("steer", "Inject a message after the next tool call (no interrupt)",
  52. _opt("text", "What to tell the agent")),
  53. _cmd("compress", "Compress conversation context"),
  54. _cmd("title", "Set or show the session title",
  55. _opt("text", "New title. Leave empty to show.")),
  56. _cmd("resume", "Resume a previously-named session",
  57. _opt("name", "Session title or id")),
  58. _cmd("usage", "Show token usage for this session"),
  59. _cmd("help", "Show available commands"),
  60. _cmd("insights", "Show usage insights and analytics"),
  61. _cmd("reload-mcp", "Reload MCP servers from config"),
  62. _cmd("reload-skills", "Re-scan skills for new or removed entries"),
  63. _cmd("voice", "Toggle voice reply mode"),
  64. _cmd("update", "Update Hermes Agent to the latest version"),
  65. _cmd("restart", "Gracefully restart the Hermes gateway"),
  66. _cmd("approve", "Approve a pending dangerous command",
  67. _opt("scope", "Approval scope", choices=["once", "session", "always", "all"])),
  68. _cmd("deny", "Deny a pending dangerous command",
  69. _opt("reason", "Why (relayed to the agent)")),
  70. _cmd("thread", "Create a new thread and start a Hermes session in it",
  71. _opt("name", "Thread name")),
  72. _cmd("queue", "Queue a prompt for the next turn (doesn't interrupt)",
  73. _opt("text", "The prompt to queue")),
  74. _cmd("bg", "Run a prompt in a separate background session",
  75. _opt("text", "The prompt to run")),
  76. _cmd("btw", "Ask a side question about the current conversation",
  77. _opt("text", "The question to answer")),
  78. ]