Skip to content

fix(cli): ignore terminal focus reports#16780

Closed
blackpilledsoftware-prog wants to merge 1 commit into
NousResearch:mainfrom
blackpilledsoftware-prog:fix/ignore-terminal-focus-reports
Closed

fix(cli): ignore terminal focus reports#16780
blackpilledsoftware-prog wants to merge 1 commit into
NousResearch:mainfrom
blackpilledsoftware-prog:fix/ignore-terminal-focus-reports

Conversation

@blackpilledsoftware-prog

Copy link
Copy Markdown
Contributor

Summary

  • Register terminal focus reports (CSI I / CSI O) as prompt_toolkit parser-level ignored sequences
  • Add an explicit Keys.Ignore binding so the default self-insert path never inserts focus-report bytes into the prompt
  • Add regression coverage that parses Ghostty/macOS focus navigation sequences before typed text reaches the buffer

Test Plan

  • python -m pytest tests/cli/test_cli_terminal_shortcuts.py tests/cli/test_cli_terminal_response_sanitizer.py -q -o 'addopts='
  • python -m py_compile cli.py tests/cli/test_cli_terminal_shortcuts.py

Notes

This fixes prompt corruption seen in Ghostty on macOS when navigating terminal tabs/windows (for example Cmd+Shift+[ / ] or Alt+Tab).

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 28, 2026
teknium1 pushed a commit that referenced this pull request May 29, 2026
Ghostty/macOS window or tab navigation (Cmd+Shift+[ / ], Alt+Tab,
etc.) can deliver terminal focus reports (CSI I / CSI O) to the
running TUI. prompt_toolkit does not map those sequences by default,
so its parser falls back to literal key presses (ESC, [, I/O) and
inserts `[I` / `[O` into the prompt buffer after the ESC byte is
handled.

Fix: register the two sequences as Keys.Ignore in ANSI_SEQUENCES at
parser level, plus a no-op kb.add(Keys.Ignore) handler so the
default self-insert path never inserts focus-report bytes.

Salvage notes: original PR put the helper in cli.py. Salvaged into
hermes_cli/pt_input_extras.py alongside install_shift_enter_alias /
install_ctrl_enter_alias to match the established pattern for
ANSI_SEQUENCES augmentation. setdefault → in-check so any prior user
registration wins.

Closes #16780
teknium1 added a commit that referenced this pull request May 29, 2026
Required by CI author validation after salvaging PR #16780.
KKT-OPT pushed a commit to KKT-OPT/hermes-agent that referenced this pull request May 31, 2026
Ghostty/macOS window or tab navigation (Cmd+Shift+[ / ], Alt+Tab,
etc.) can deliver terminal focus reports (CSI I / CSI O) to the
running TUI. prompt_toolkit does not map those sequences by default,
so its parser falls back to literal key presses (ESC, [, I/O) and
inserts `[I` / `[O` into the prompt buffer after the ESC byte is
handled.

Fix: register the two sequences as Keys.Ignore in ANSI_SEQUENCES at
parser level, plus a no-op kb.add(Keys.Ignore) handler so the
default self-insert path never inserts focus-report bytes.

Salvage notes: original PR put the helper in cli.py. Salvaged into
hermes_cli/pt_input_extras.py alongside install_shift_enter_alias /
install_ctrl_enter_alias to match the established pattern for
ANSI_SEQUENCES augmentation. setdefault → in-check so any prior user
registration wins.

Closes NousResearch#16780
KKT-OPT pushed a commit to KKT-OPT/hermes-agent that referenced this pull request May 31, 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 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