Skip to content

fix(cli): ignore terminal focus reports (salvage #16780) - #34429

Merged
teknium1 merged 2 commits into
mainfrom
salvage/16780-focus-reports
May 29, 2026
Merged

teknium1 merged 2 commits into
mainfrom
salvage/16780-focus-reports

Conversation

@teknium1

Copy link
Copy Markdown
Collaborator

Salvage of #16780 by @blackpilledsoftware-prog onto current main (PR branch was 3500+ commits behind).

Ghostty / macOS window or tab navigation (Cmd+Shift+[ / ], Alt+Tab) 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 both sequences as Keys.Ignore in ANSI_SEQUENCES at the VT100 parser level, plus a no-op kb.add(Keys.Ignore) handler so the default self-insert path never fires on the consumed bytes.

This is parser-level — strictly cleaner than the post-hoc regex stripping in _strip_leaked_terminal_responses_with_meta because the bytes never reach the buffer.

Salvage notes

The original PR placed the helper as a top-level function in cli.py. Salvaged into hermes_cli/pt_input_extras.py alongside install_shift_enter_alias and install_ctrl_enter_alias to match the established pattern for ANSI_SEQUENCES augmentation (which post-dated this PR). Registration uses if seq not in ANSI_SEQUENCES (setdefault behavior) so any prior user or downstream registration wins.

Test rehomed to import from pt_input_extras and gained one additional case that verifies idempotency of repeat installs.

Files

File Change
hermes_cli/pt_input_extras.py New install_ignored_terminal_sequences() function
cli.py Call new installer alongside the existing two; add kb.add(Keys.Ignore) no-op handler
tests/cli/test_cli_terminal_shortcuts.py Regression coverage (3 tests)

Validation

Test Result
tests/cli/test_cli_terminal_shortcuts.py 3/3 pass
tests/cli/test_cli_init.py 36/36 pass
tests/cli/test_ctrl_enter_newline.py 15/15 pass
tests/cli/test_cli_terminal_response_sanitizer.py 16/16 pass
Total 67/67 pass, no regressions

Attribution

@blackpilledsoftware-prog's design intent (parser-level Keys.Ignore + no-op handler) preserved. Authorship retained on the substantive commit via explicit --author=. AUTHOR_MAP entries added in follow-up commit.

Closes #16780

Infographic

focus-reports-silenced

blackpilledsoftware-prog and others added 2 commits May 28, 2026 23:41
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
Required by CI author validation after salvaging PR #16780.
@github-actions

Copy link
Copy Markdown
Contributor

🔎 Lint report: salvage/16780-focus-reports vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 9428 on HEAD, 9423 on base (🆕 +5)

🆕 New issues (2):

Rule Count
unresolved-import 2
First entries
tests/cli/test_cli_terminal_shortcuts.py:9: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.keys`
tests/cli/test_cli_terminal_shortcuts.py:8: [unresolved-import] unresolved-import: Cannot resolve imported module `prompt_toolkit.input.vt100_parser`

✅ Fixed issues: none

Unchanged: 4891 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added P3 Low — cosmetic, nice to have type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard labels May 29, 2026
@teknium1
teknium1 merged commit 0384398 into main May 29, 2026
25 checks passed
@teknium1
teknium1 deleted the salvage/16780-focus-reports branch May 29, 2026 07:31
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 P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants