From fef9c537d7f096a9b7b6fa7dfbb8d4fca704aaf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Valero?= Date: Wed, 29 Jul 2026 19:18:12 +0200 Subject: [PATCH] fix(cli): convert Alt key shortcuts to sequence tuple for prompt_toolkit (#74169) --- cli.py | 3 ++- hermes_cli/voice.py | 11 +++++++++++ tests/hermes_cli/test_voice_wrapper.py | 7 +++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cli.py b/cli.py index 01ed9a87a2..38fa410060 100644 --- a/cli.py +++ b/cli.py @@ -17420,6 +17420,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): from hermes_cli.config import load_config from hermes_cli.voice import ( normalize_voice_record_key_for_prompt_toolkit, + pt_key_to_sequence, voice_record_key_from_config, ) _raw_key = voice_record_key_from_config(load_config()) @@ -17445,7 +17446,7 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin): # voice.record_key mid-session (Copilot round-13 on #19835). self.set_voice_record_key_cache(_raw_key) - @kb.add(_voice_key) + @kb.add(*pt_key_to_sequence(_voice_key)) def handle_voice_record(event): """Toggle voice recording when voice mode is active. diff --git a/hermes_cli/voice.py b/hermes_cli/voice.py index 5cde3604f4..3c4cddbb08 100644 --- a/hermes_cli/voice.py +++ b/hermes_cli/voice.py @@ -183,6 +183,17 @@ def normalize_voice_record_key_for_prompt_toolkit(raw: Any) -> str: return f"{normalized_mod}{named}" +def pt_key_to_sequence(pt_key: str) -> tuple[str, ...]: + """Convert a prompt_toolkit key specifier (e.g. 'c-b' or 'a-v') to a sequence tuple. + + prompt_toolkit's ``@kb.add`` rejects 'a-x' strings directly (raises ValueError), + expecting ('escape', 'x') instead for Alt-modifier shortcuts. + """ + if isinstance(pt_key, str) and pt_key.startswith("a-"): + return ("escape", pt_key[2:]) + return (pt_key,) + + def format_voice_record_key_for_status(raw: Any) -> str: """Render ``voice.record_key`` for ``/voice status`` in CLI-friendly form. diff --git a/tests/hermes_cli/test_voice_wrapper.py b/tests/hermes_cli/test_voice_wrapper.py index fdfa9c1ab6..c30637cc4b 100644 --- a/tests/hermes_cli/test_voice_wrapper.py +++ b/tests/hermes_cli/test_voice_wrapper.py @@ -73,6 +73,13 @@ class TestNormalizeVoiceRecordKeyForPromptToolkit: # configs like ``option+c`` don't bind Alt+C in the CLI while the # TUI falls back to Ctrl+B. + def test_pt_key_to_sequence(self): + from hermes_cli.voice import pt_key_to_sequence + + assert pt_key_to_sequence("c-b") == ("c-b",) + assert pt_key_to_sequence("a-v") == ("escape", "v") + assert pt_key_to_sequence("a-space") == ("escape", "space") + class TestVoiceRecordKeyFromConfig: """Round-11 Copilot review regression on #19835.