fix(approval): disable mouse tracking to prevent micro-movement false denies

- Add _suppress_mouse_tracking_cli() in cli.py called at classic CLI startup
- Add mouse suppression in prompt_dangerous_approval() for legacy input() path
- Enhance _suppress_mouse_residue_early() in hermes_cli/main.py with focus tracking disable
- Disables all 10 mouse tracking modes (SGR 1006, X10 1000, focus 1004, kitty 2029, etc.)
- Fixes #78587: mouse jiggle falsely interpreted as deny in approval prompts
This commit is contained in:
GauravPatil2515 2026-08-08 13:44:29 +05:30
parent e6977f41bc
commit a37166efa5
3 changed files with 46 additions and 2 deletions

29
cli.py
View File

@ -1008,6 +1008,30 @@ def _mark_tui_input_modes_active() -> None:
_tui_input_modes_active = True
def _suppress_mouse_tracking_cli() -> None:
"""Disable terminal mouse tracking for the classic CLI to prevent
mouse micro-movements from generating escape sequences that could
be misinterpreted as key presses (e.g. triggering 'deny' in approval prompts).
This is similar to _suppress_mouse_residue_early() for the TUI but runs
at the start of the classic CLI run() method.
"""
try:
if not os.isatty(1):
return
# Disable all mouse tracking variants: SGR (1006), X10 (1000), button-event (1002),
# any-event (1003), focus (1004), and alternate scroll (1005/1015/1016)
# Also disable vt200 mouse (1001) and kitty mouse (2029)
os.write(
1,
b"\x1b[?1006l\x1b[?1005l\x1b[?1015l\x1b[?1016l"
b"\x1b[?1003l\x1b[?1002l\x1b[?1001l\x1b[?1000l"
b"\x1b[?1004l\x1b[?2029l",
)
except OSError:
pass
def _prepare_deferred_agent_startup() -> None:
"""Run Termux-deferred agent discovery before the first real agent turn."""
global _deferred_agent_startup_done
@ -14958,6 +14982,11 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
_welcome_color = "#FFF8DC"
self._console_print(f"[{_welcome_color}]{_welcome_text}[/]")
# Disable terminal mouse tracking to prevent mouse micro-movements
# from generating escape sequences that could interfere with
# approval prompts and other modal dialogs.
_suppress_mouse_tracking_cli()
# Warm the /model picker's provider-models cache off-thread during this
# idle window (banner shown, user about to type). The no-args picker
# otherwise blocks ~1-2s on serial /v1/models fetches the first time

View File

@ -361,8 +361,9 @@ def _suppress_mouse_residue_early() -> None:
# safe to send even when no tracking is currently asserted.
os.write(
1,
b"\x1b[?1003l\x1b[?1002l\x1b[?1001l\x1b[?1000l\x1b[?9l"
b"\x1b[?1006l\x1b[?1005l\x1b[?1015l\x1b[?1016l\x1b[?2029l",
b"\x1b[?1006l\x1b[?1005l\x1b[?1015l\x1b[?1016l"
b"\x1b[?1003l\x1b[?1002l\x1b[?1001l\x1b[?1000l"
b"\x1b[?1004l\x1b[?2029l",
)
except OSError:
pass

View File

@ -2634,6 +2634,20 @@ def prompt_dangerous_approval(command: str, description: str,
os.environ["HERMES_SPINNER_PAUSE"] = "1"
try:
# Disable mouse tracking to prevent mouse micro-movements from
# generating escape sequences that could be captured by input()
# and misinterpreted as user input.
try:
if os.isatty(1):
os.write(
1,
b"\x1b[?1006l\x1b[?1005l\x1b[?1015l\x1b[?1016l"
b"\x1b[?1003l\x1b[?1002l\x1b[?1001l\x1b[?1000l"
b"\x1b[?1004l\x1b[?2029l",
)
except OSError:
pass
# Resolve the active UI language once per prompt so we don't re-read
# config/YAML inside the retry loop below.
from agent.i18n import t