The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): cite xterm's key table for the Shift+symbol mapping; trim tests
teknium1df97ee795635
diff --git a/hermes_cli/pt_input_extras.py b/hermes_cli/pt_input_extras.pyindex 6e113f9e3d3..489a843aa37 100644--- a/hermes_cli/pt_input_extras.py+++ b/hermes_cli/pt_input_extras.py@@ -175,7 +175,9 @@ def install_modify_other_keys_aliases() -> int:``_`` `` `` ``@``): same formats → the same ``Keys`` value the raw control byte maps to. ***Alt+letter** (a–z, A–Z): ``ESC[27;3;<codepoint>~`` and ``ESC[<codepoint>;3u`` → ``(Keys.Escape,<letter>)`` — matching how prompt_toolkit handles a bare ``ESC`` followed by a character. *- **Shift+letter** (a–z): → the uppercase character. * **Multi-modifier letters** (Shift+Alt=4,+ **Shift+letter** (a–z): → the uppercase character. * **Shift+symbol** (tilde form only): ``ESC[27;2;<cp>~``+ → ``chr(cp)`` for printable ASCII — xterm and Ghostty put the produced character in that codepoint (#114242).+ * **Multi-modifier letters** (Shift+Alt=4,Ctrl+Shift=6, Ctrl+Alt=7, Ctrl+Alt+Shift=8): normalized onto the same targets — Ctrl-bearing combosbehave as the Ctrl key (Alt adds an ``Escape`` prefix), matching how dte/kakoune normalize theseprotocols. * **Lock-bit variants**: every CSI-u mapping above is also installed with the CapsLock (64)@@ -225,9 +227,10 @@ def _modify_other_keys_aliases(ANSI_SEQUENCES: dict, Keys) -> dict[str, object]:_install_paired(5, ctrl_key_map)# Letter combos. Alt+a -> (Escape, 'a') like bare Alt. Shift+a -> 'A' (safe on every Latin- # layout; Shift+digit symbols are layout-specific and deliberately NOT mapped — leaking beats- # wrong input). Kitty reports the UNSHIFTED codepoint, some modifyOtherKeys emitters the shifted- # one — map both. Ctrl-bearing combos normalize onto the Ctrl key (Alt adds an Escape prefix),+ # layout). Kitty CSI-u reports the UNSHIFTED codepoint, modifyOtherKeys emitters the shifted+ # one — map both. Shift+symbol is mapped only in the tilde form below: the CSI-u codepoint is+ # unshifted (ESC[47;2u is Shift+/ on US, '?' — layout-specific), so there leaking beats wrong+ # input. Ctrl-bearing combos normalize onto the Ctrl key (Alt adds an Escape prefix),# Shift+Alt onto (Escape, UPPER) — the same normalization dte/kakoune apply.for ch in letters:upper_char = chr(ch - 32)@@ -241,12 +244,12 @@ def _modify_other_keys_aliases(ANSI_SEQUENCES: dict, Keys) -> dict[str, object]:for modifier in (7, 8): # Ctrl+Alt and Ctrl+Alt+Shift — same normalization_install_paired(modifier, {cp: (Keys.Escape, ctrl_key)})- # Shift+printable ASCII under modifyOtherKeys (tilde form):- # Under modifyOtherKeys=2, terminals (xterm, Ghostty) encode any modified key that produces- # a character (e.g. Shift+- -> '_', Shift+= -> '+', Shift+[ -> '{') as ESC[27;2;<produced_cp>~.- # Unlike Kitty CSI-u (which sends the unshifted key), the tilde-form codepoint is already the- # layout-resolved produced character, so mapping ESC[27;2;<cp>~ -> chr(cp) is layout-safe.- # Existing entries (e.g. Shift+Enter \x1b[27;2;13~, Shift+Tab) are preserved via setdefault.+ # Shift+printable ASCII under modifyOtherKeys (tilde form only, never CSI-u): xterm's own key+ # table sends Shift+[ as ESC[27;2;123~ — the codepoint is the PRODUCED character '{', already+ # resolved through the user's keymap — and Ghostty follows that spec (#114242, #102683). So+ # ESC[27;2;<cp>~ -> chr(cp) is layout-safe on every tilde-form emitter; the+ # unshifted-codepoint concern belongs to Kitty CSI-u, which never uses this spelling.+ # Existing entries (Shift+Enter \x1b[27;2;13~, Shift+Tab, Shift+Space) win via setdefault.for cp in range(33, 127):_put(f"\x1b[27;2;{cp}~", chr(cp))diff --git a/tests/hermes_cli/test_modify_other_keys_aliases.py b/tests/hermes_cli/test_modify_other_keys_aliases.pyindex 87dcac9b368..c304f0730c2 100644--- a/tests/hermes_cli/test_modify_other_keys_aliases.py+++ b/tests/hermes_cli/test_modify_other_keys_aliases.py@@ -269,31 +269,22 @@ def test_modify_other_keys_shift_letter_produces_uppercase(letter):# ---------------------------------------------------------------------------@pytest.mark.parametrize("cp", [- 33, # '!'- 34, # '"'- 35, # '#'- 36, # '$'- 43, # '+'58, # ':'- 60, # '<'- 62, # '>'- 63, # '?'- 64, # '@'95, # '_' (Shift+Minus)123, # '{'- 124, # '|'125, # '}'- 126, # '~'])def test_modify_other_keys_shift_symbol_produces_char(cp):- """Under modifyOtherKeys=2, Shift+symbol (e.g. Shift+- -> '_') emits- ESC[27;2;<produced_cp>~. It must parse to the produced character,- not leak literal escape text."""+ """Under modifyOtherKeys=2, Shift+symbol (e.g. Shift+[ -> '{') arrives as+ ESC[27;2;<produced_cp>~ (xterm's own key table; Ghostty follows it). It must parse+ to the produced character, not leak literal escape text. The kitty CSI-u spelling+ carries the UNSHIFTED codepoint and must stay unmapped (layout-specific)."""ch = chr(cp)mok_seq = f"\x1b[27;2;{cp}~"assert _parse(mok_seq) == [ch], (f"modifyOtherKeys Shift+symbol ({mok_seq!r}) should produce {ch!r}")+ assert ANSI_SEQUENCES.get(f"\x1b[{cp};2u") is Nonedef test_shift_symbol_data_normalized_in_buffer():