fix(cli): convert Alt key shortcuts to sequence tuple for prompt_toolkit (#74169)

This commit is contained in:
Moisés Valero
2026-07-29 19:18:12 +02:00
committed by Teknium
parent b3447c2129
commit fef9c537d7
3 changed files with 20 additions and 1 deletions
+2 -1
View File
@@ -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.
+11
View File
@@ -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.
+7
View File
@@ -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.