diff --git a/cli.py b/cli.py index aed3992922b4a..b4b4dab48a9d8 100644 --- a/cli.py +++ b/cli.py @@ -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 diff --git a/hermes_cli/main.py b/hermes_cli/main.py index 624d0f10109f7..a1c707461449c 100644 --- a/hermes_cli/main.py +++ b/hermes_cli/main.py @@ -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 diff --git a/tools/approval.py b/tools/approval.py index 151e534065539..6cdf59e6fc825 100644 --- a/tools/approval.py +++ b/tools/approval.py @@ -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