Skip to content

fix(cli): insert mapped character instead of raw modifyOtherKeys sequence - #91539

Closed
ceotind wants to merge 1 commit into
NousResearch:mainfrom
ceotind:fix/shift-letter-modifyotherkeys-leak
Closed

ceotind wants to merge 1 commit into
NousResearch:mainfrom
ceotind:fix/shift-letter-modifyotherkeys-leak

Conversation

@ceotind

@ceotind ceotind commented Aug 21, 2026

Copy link
Copy Markdown

Summary

Typing Shift+letters in the Hermes CLI prompt on Ghostty (xterm modifyOtherKeys mode, which Hermes enables for Ghostty terminals via _is_ghostty_terminal) inserts literal escape text like [27;2;70~ instead of the character. Same root cause kills Alt+letter combos (dead keys, empty data) and Shift+Space.

Root cause: install_modify_other_keys_aliases() maps ESC[27;2;<cp>~ to single-character string keys ('F', ' '), but prompt_toolkit's Vt100Parser._call_handler attaches the raw matched sequence as the KeyPress.data, and the self-insert binding inserts event.data — so the escape text lands in the buffer.

Fix: new install_vt100_single_char_data_fix() (hermes_cli/pt_input_extras.py) rewrites data to the mapped character for single-char string keys, called from the cli.py startup block. Fixes Shift+letter, Shift+Space, and dead Alt+letter at the source. Normal typing (key == data already) and enum keys (Ctrl+C) are untouched.

Test Plan

  • New tests/cli/test_cli_shift_letter_data_fix.py: 6 tests — Shift+F → ('F','F'), Shift+Space → (' ',' '), Alt+a → Escape + ('a','a'), plain F unchanged, Ctrl+C → Keys.ControlC, idempotency.
  • pytest tests/cli/test_cli_shift_letter_data_fix.py tests/cli/test_cli_shift_enter_newline.py tests/cli/test_cli_cmd_backspace.py → 22 passed.
  • Verified live in the CLI before this PR (real Ghostty session): Shift+letters type clean.

…ence

Ghostty in xterm modifyOtherKeys mode (enabled by Hermes for Ghostty
terminals) encodes Shift+letters as ESC[27;2;<cp>~. install_modify_other_keys_aliases()
maps these to single-character string keys, but prompt_toolkit's
Vt100Parser._call_handler attaches the raw matched sequence as the
KeyPress data, and the self-insert binding inserts event.data — so
Shift+F typed literal '[27;2;70~' into the prompt buffer.

install_vt100_single_char_data_fix() rewrites data to the mapped
character for single-char string keys, fixing Shift+letter, Shift+Space,
and dead Alt+letter combos at the source. Normal typing and enum keys
(Ctrl+C etc.) are unaffected.

Adds regression tests covering Shift+F, Shift+Space, Alt+a, plain
letters, Ctrl+C, and idempotency.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard P2 Medium — degraded but workaround exists duplicate This issue or pull request already exists labels Aug 21, 2026
@alt-glitch

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

Duplicate of #88097: both PRs normalize mapped single-character KeyPress data at the prompt_toolkit parser boundary; #88097 has broader terminal-protocol coverage.

@ceotind

ceotind commented Aug 21, 2026

Copy link
Copy Markdown
Author

Fair enough. #88097 covers this and then some — no point in two PRs fixing the same thing. Closing mine in favour of theirs.

@ceotind ceotind closed this Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants