cli_unknown_command.py 944 B

123456789101112131415161718192021
  1. """Copy for an unknown slash command: says nothing was sent and suggests a near-miss."""
  2. from __future__ import annotations
  3. import difflib
  4. from collections.abc import Iterable
  5. from agent.i18n import t
  6. def unknown_command_lines(typed: str, known: Iterable[str]) -> tuple[str, str]:
  7. """(lead line, pointer line) for a slash token with no handler.
  8. ``known`` holds names WITH the leading slash (``hermes_cli.commands.COMMANDS`` keys plus skill
  9. commands). A close match (typo) becomes ``Did you mean /model?``; prefix expansion already ran
  10. before this, so only fuzzy matches are considered here.
  11. """
  12. base = typed.split()[0] if typed.split() else typed
  13. close = difflib.get_close_matches(base, list(known), n=1, cutoff=0.6)
  14. hint = " " + t("cli.command.did_you_mean_one", suggestion=close[0]) if close else ""
  15. return (t("cli.command.unknown_nothing_sent", command=base, hint=hint), t("cli.command.type_help"))