Files
hermes-agent/hermes_cli/cli_unknown_command.py
Teknium 1986a7b8d5 fix: slash commands are offered and described only where they work
- /discard: drop gateway_only; the CLI's /discard <admission_id> runs, so CLI /help lists it.
- CLI: a messaging-only command typed in full says it runs in messaging chats instead of a
  near-miss for a different command (/pause -> "Did you mean /paste?").
- Shared gateway: an unsupported_command refusal for a messaging-only command carries a
  detail naming where it runs (Ink prints it under the refusal).
- TUI: commands.catalog marks each registry command with slash_exec (the owner's verdict); Ink
  completion and /help offer a registry command only when Ink runs it itself or the owner
  does, and an exact registry name is never prefix-expanded into another command.
- Desktop: /prompt /battery /focus /tools get desktop="terminal", /subscription "settings",
  the messaging-only /start /topic /pause /mute /sethome /restart "messaging".
- /stop description and docs say what it does per surface (messaging keeps processes from
  earlier turns running); /platform docs say pause/resume act only on a failing adapter.
2026-11-28 19:42:51 -08:00

29 lines
1.3 KiB
Python

"""Copy for a slash command the CLI cannot run: says nothing was sent and why, or suggests a near-miss."""
from __future__ import annotations
import difflib
from collections.abc import Iterable
from agent.i18n import t
def unknown_command_lines(typed: str, known: Iterable[str]) -> tuple[str, str]:
"""(lead line, pointer line) for a slash token with no handler.
``known`` holds names WITH the leading slash (``hermes_cli.commands.COMMANDS`` keys plus skill
commands). A close match (typo) becomes ``Did you mean /model?``; prefix expansion already ran
before this, so only fuzzy matches are considered here.
"""
base = typed.split()[0] if typed.split() else typed
close = difflib.get_close_matches(base, list(known), n=1, cutoff=0.6)
hint = " " + t("cli.command.did_you_mean_one", suggestion=close[0]) if close else ""
return (t("cli.command.unknown_nothing_sent", command=base, hint=hint), t("cli.command.type_help"))
def messaging_only_line(name: str) -> str:
"""A registry command whose only handler is the messaging gateway's (``gateway_only``): it is a
real command, so name where it runs instead of fuzzy-suggesting a different one (``/pause`` was
answered "Did you mean /paste?") or prefix-expanding into one (``/platform`` ran ``/platforms``)."""
return t("cli.command.messaging_only", command=f"/{name}")