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

This commit is contained in:
Teknium
2026-09-02 22:39:57 -07:00
parent 91d7b118b6
commit 711bec9219
3 changed files with 24 additions and 18 deletions
+23 -15
View File
@@ -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):
+1 -2
View File
@@ -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"
-1
View File
@@ -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)