Skip to content

fix(cli): auto-disable mouse reporting on leaky terminals (Konsole/Plasma Wayland) - #48701

Closed
mjwicker wants to merge 1 commit into
NousResearch:mainfrom
mjwicker:fix/terminal-mouse-reporting-leak
Closed

fix(cli): auto-disable mouse reporting on leaky terminals (Konsole/Plasma Wayland)#48701
mjwicker wants to merge 1 commit into
NousResearch:mainfrom
mjwicker:fix/terminal-mouse-reporting-leak

Conversation

@mjwicker

Copy link
Copy Markdown

Summary

Level-1 mitigation for the long-standing "spam letters/symbols on mouse movement or keypress" bug that occurs in Konsole + Plasma (especially on Wayland/Pop!_OS).

The Bug

Certain terminals (notably Konsole) enable bracketed mouse reporting for the entire terminal emulator. Hermes (which uses prompt_toolkit) receives the raw escape sequences (\e[?1000h, \e[<83;30M, etc.) as input, causing garbage spam every time the mouse moves or a button is pressed.

Users have to manually run:

printf '\e[?1000l\e[?1002l\e[?1006l\e[?1005l'

or disable mouse input in the Konsole profile.

The Fix (Level 1)

  • Early detection of known-leaky environments
  • Automatically emit the disable sequences before prompt_toolkit takes over the tty
  • Never re-enable reporting on exit (preserves mouse behavior in other TUIs)

Detection Logic

  • KONSOLE_VERSION env var (strongest signal)
  • TERM containing konsole
  • XDG_SESSION_TYPE=wayland + Plasma/KDE desktop
  • XDG_CURRENT_DESKTOP containing plasma/kde

Scope

  • Only disables on detected vulnerable terminals
  • Safe no-op on Kitty, Alacritty, Foot, WezTerm, GNOME Terminal, etc.
  • No change to mouse support behavior inside Hermes (future Level-2 work)

This matches the existing workaround documented in the hermes-agent skill under "Troubleshooting → Input Glitches (Mouse Reporting ANSI Codes)".

Refs: multiple user reports of ;83;30M / random symbol spam during interactive sessions.

…asma Wayland)

Adds Level-1 mitigation for the long-reported "spam letters on mouse/keyboard"
bug caused by raw bracketed mouse sequences leaking into stdin.

Detection:
- KONSOLE_VERSION env var (strongest signal)
- TERM containing "konsole"
- XDG_SESSION_TYPE=wayland + Plasma/KDE desktop
- XDG_CURRENT_DESKTOP containing plasma/kde

Actions:
- Emits \e[?1000l etc. to disable before prompt_toolkit grabs the tty
- Never re-enables (preserves mouse for other TUIs)
- Completely silent on well-behaved terminals (Kitty, Alacritty, etc.)

This matches the existing workaround documented in the hermes-agent skill
under "Input Glitches (Mouse Reporting ANSI Codes)".

Refs: user reports of ;83;30M spam and similar garbage on mouse movement.
@alt-glitch alt-glitch added type/bug Something isn't working comp/cli CLI entry point, hermes_cli/, setup wizard comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have labels Jun 18, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related: this is part of the SGR mouse-tracking leak chain (#18658 core issue; #42527, #31213, #17701 prior fixes). Those address the leak reactively — stripping leaked sequences from the input buffer and resetting terminal mode on teardown/startup. This PR adds a distinct, proactive mechanism: env-based detection of known-leaky terminals (KONSOLE_VERSION / Plasma / Wayland) and emitting the disable sequences before prompt_toolkit takes over. Complementary, not a duplicate.

@teknium1

Copy link
Copy Markdown
Contributor

Thanks for the targeted mitigation. The mouse-reporting startup leak is already addressed on current main with a broader proactive reset, so this PR is now redundant.

  • Automated hermes-sweeper review verified hermes_cli/main.py:185-207: _suppress_mouse_residue_early() runs before the TUI launcher’s later imports and disables SGR/X10 mouse modes without relying on terminal-specific environment detection.
  • ui-tui/src/entry.tsx:22-24 resets terminal modes again at TUI startup; ui-tui/src/lib/terminalModes.ts:3-22 includes 1006/1005/1003/1002/1001/1000/9 disables.
  • Regression coverage is present in tests/hermes_cli/test_tui_mouse_residue_suppression.py:29-92.
  • The implementation shipped in 912e6e2274e171d33b698fb8287571c6358fe2d7 (v2026.5.29).

@teknium1 teknium1 closed this Jul 14, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jul 14, 2026
zipzob added a commit to zipzob/hermes-agent that referenced this pull request Aug 6, 2026
Force a full Ink redraw after coalesced terminal resize events and on terminal focus regain, and reassert bracketed paste when focus returns. This hardens the Alacritty/terminal-stale-frame class without rewriting input handling.

Refs upstream TUI redraw/input issues:
- NousResearch#54284
- NousResearch#25337
- NousResearch#35530
- NousResearch#48701
- NousResearch#30092
- NousResearch#55415

(cherry picked from commit 61d9540565c62a7434e35b0ec774988f18967deb)
(cherry picked from commit a8385de07f84e0e4baa2f3959973328f1b609651)
zipzob added a commit to zipzob/hermes-agent that referenced this pull request Aug 13, 2026
Force a full Ink redraw after coalesced terminal resize events and on terminal focus regain, and reassert bracketed paste when focus returns. This hardens the Alacritty/terminal-stale-frame class without rewriting input handling.

Refs upstream TUI redraw/input issues:
- NousResearch#54284
- NousResearch#25337
- NousResearch#35530
- NousResearch#48701
- NousResearch#30092
- NousResearch#55415

(cherry picked from commit 61d9540565c62a7434e35b0ec774988f18967deb)
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 comp/tui Terminal UI (ui-tui/ + tui_gateway/) P3 Low — cosmetic, nice to have sweeper:implemented-on-main Sweeper: behavior already present on current main type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants