Skip to content

The agent that grows with you

refactor(hermes_cli): commands_completion — _quiet generator decorator; completion — single profile-action source

Teknium711bec92198a
diff --git a/hermes_cli/commands_completion.py b/hermes_cli/commands_completion.py
index 9352bf0ee29..55420dceffe 100644
--- a/hermes_cli/commands_completion.py
+++ b/hermes_cli/commands_completion.py
@@ -6,6 +6,7 @@ stays prompt_toolkit-free for the gateway.
from __future__ import annotations
+import functools
import os
import shutil
import subprocess
@@ -91,27 +92,34 @@ def _split_args(sub_text: str) -> tuple[list[str], str]:
# Dynamic argument completers: (sub_text, sub_lower) -> Completion iterator
+def _quiet(gen_fn):
+ """Generator decorator: any exception while producing completions just ends the stream."""
+ @functools.wraps(gen_fn)
+ def wrapper(*args):
+ try:
+ yield from gen_fn(*args)
+ except Exception:
+ return
+ return wrapper
+
+
+@_quiet
def _skin_completions(sub_text: str, sub_lower: str):
"""/skin — available skins."""
- try:
- from hermes_cli.skin_engine import list_skins
- rows = ((s["name"], s.get("description", "") or s.get("source", "")) for s in list_skins())
- yield from _prefix_completions(rows, sub_text)
- except Exception:
- pass
+ from hermes_cli.skin_engine import list_skins
+ rows = ((s["name"], s.get("description", "") or s.get("source", "")) for s in list_skins())
+ yield from _prefix_completions(rows, sub_text)
+@_quiet
def _personality_completions(sub_text: str, sub_lower: str):
"""/personality — ``none`` plus configured personalities."""
- try:
- from hermes_cli.personality import describe_personality
- personalities = _personalities_from_cli_config()
- rows = chain(
- [("none", "clear personality overlay")],
- ((name, describe_personality(prompt)) for name, prompt in personalities.items()))
- yield from _prefix_completions(rows, sub_text)
- except Exception:
- pass
+ from hermes_cli.personality import describe_personality
+ personalities = _personalities_from_cli_config()
+ rows = chain(
+ [("none", "clear personality overlay")],
+ ((name, describe_personality(prompt)) for name, prompt in personalities.items()))
+ yield from _prefix_completions(rows, sub_text)
def _tools_completions(sub_text: str, sub_lower: str):
diff --git a/hermes_cli/completion.py b/hermes_cli/completion.py
index 280d7cd3fd8..a1d09213de4 100644
--- a/hermes_cli/completion.py
+++ b/hermes_cli/completion.py
@@ -50,7 +50,6 @@ def generate_bash(parser: argparse.ArgumentParser) -> str:
if cmd == "profile" and info["subcommands"]:
# Complete actions, then profile names for actions that accept a profile argument.
subcmds = " ".join(sorted(info["subcommands"]))
- profile_actions = " ".join(_PROFILE_NAME_ACTIONS)
cases.append(
f" profile)\n"
f" case \"$prev\" in\n"
@@ -58,7 +57,7 @@ def generate_bash(parser: argparse.ArgumentParser) -> str:
f" COMPREPLY=($(compgen -W \"{subcmds}\" -- \"$cur\"))\n"
f" return\n"
f" ;;\n"
- f" {profile_actions.replace(' ', '|')})\n"
+ f" {'|'.join(_PROFILE_NAME_ACTIONS)})\n"
f" COMPREPLY=($(compgen -W \"$(_hermes_profiles)\" -- \"$cur\"))\n"
f" return\n"
f" ;;\n"
diff --git a/hermes_cli/curses_ui.py b/hermes_cli/curses_ui.py
index 3ce99260ad0..928aa958d86 100644
--- a/hermes_cli/curses_ui.py
+++ b/hermes_cli/curses_ui.py
@@ -715,7 +715,6 @@ def _search_hint(search, searchable: bool, confirm: str, cancel: str, back_enabl
def _simple_header(title: str, confirm: str, cancel: str, searchable: bool):
"""``draw_header`` callback: title on row 0, key hint on row 1, items start on row 3."""
-
def _draw_header(stdscr, max_y, max_x, search=None, back_enabled=False):
hint = _search_hint(search, searchable, confirm, cancel, back_enabled)
_draw_title_and_hint(stdscr, title, hint, max_x)