The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): Enter arriving mid-paste is a newline, not a per-line steer
teknium140f123ceab41
diff --git a/hermes_cli/cli_tui_mixin.py b/hermes_cli/cli_tui_mixin.pyindex dd57ed572f5..10c65202a09 100644--- a/hermes_cli/cli_tui_mixin.py+++ b/hermes_cli/cli_tui_mixin.py@@ -41,6 +41,8 @@ from typing import Optional# Rows below an overlay panel taken by spinner/tool-progress, status bar, input, separators and# prompt symbol (measured ~6 during live PTY approval prompts) — shared by every panel budget._PANEL_RESERVED_BELOW = 6+# Enter within this many seconds of the last buffer change is a pasted/dictated newline, not a submit.+_RAPID_INPUT_ENTER_WINDOW_S = 0.05_TYPING_CHARS = string.digits + string.ascii_letters + "-_.:/ "_APPROVAL_CHOICE_LABELS = {@@ -1349,6 +1351,13 @@ class CLITuiMixin:if self._tui_enter_overlay(event):returnbuf = event.app.current_buffer+ # Paste without bracketed-paste (tmux strips it) and IME/voice dictation deliver each+ # newline as its own Enter key event; the buffer collapse in _tui_on_text_changed only+ # sees whole-chunk pastes. Text still arriving (<50 ms since the last change) means this+ # Enter is a line break inside one message, not a submit — humans type >50 ms apart (#10994).+ if time.monotonic() - getattr(self, "_tui_last_text_change", 0.0) < _RAPID_INPUT_ENTER_WINDOW_S:+ buf.insert_text("\n")+ returnraw_text = buf.textif (self._tui_multiline_shortcuts@@ -1676,6 +1685,7 @@ class CLITuiMixin:tick), or the newline count jumped by 4+ (terminals that feed characters individuallybut batch newlines; Alt+Enter adds 1 newline per event so never trips it)."""+ self._tui_last_text_change = time.monotonic()from cli import _strip_leaked_bracketed_paste_wrappers, _strip_leaked_terminal_responses_with_metatext = _strip_leaked_bracketed_paste_wrappers(buf.text)text, _had_mouse_reports = _strip_leaked_terminal_responses_with_meta(text)diff --git a/tests/cli/test_tui_rapid_enter_paste.py b/tests/cli/test_tui_rapid_enter_paste.pynew file mode 100644index 00000000000..00be39fda16--- /dev/null+++ b/tests/cli/test_tui_rapid_enter_paste.py@@ -0,0 +1,51 @@+"""Enter arriving mid-paste (no bracketed paste; each newline is its own key event) must not+submit / steer the partial line (#10994). Only the Enter-vs-recent-text-change timing is exercised;+the real prompt_toolkit Buffer carries the text so the newline lands where the user's did."""+from __future__ import annotations++import time+from types import SimpleNamespace+from unittest.mock import MagicMock++from prompt_toolkit.buffer import Buffer++from hermes_cli.cli_tui_mixin import _RAPID_INPUT_ENTER_WINDOW_S+++def _shell():+ from cli import HermesCLI+ shell = object.__new__(HermesCLI)+ shell._tui_enter_overlay = lambda event: False+ shell._tui_multiline_shortcuts = False+ shell._attached_images = []+ shell._agent_running = True+ shell._tui_enter_while_busy = MagicMock()+ shell._tui_enter_inline_command = lambda *a, **k: False+ shell._inline_pastes = lambda buf: None+ shell._tui_paste_counter = 0+ shell.config = {}+ shell._tui_prev_text_len = shell._tui_prev_newline_count = 0+ shell._tui_paste_just_collapsed = shell._skip_paste_collapse = False+ return shell+++def _event(buf: Buffer):+ return SimpleNamespace(app=SimpleNamespace(current_buffer=buf, invalidate=lambda: None, is_running=False))+++def test_enter_right_after_text_arrives_is_a_newline_not_a_steer():+ """Line 1 of a paste followed by Enter within the window stays in the buffer; the same Enter+ after a human-scale pause submits the accumulated multi-line message once."""+ shell = _shell()+ buf = Buffer()+ buf.on_text_changed += shell._tui_on_text_changed+ buf.insert_text("line one")+ shell._tui_handle_enter(_event(buf)) # < 50 ms after the text change+ assert buf.text == "line one\n"+ shell._tui_enter_while_busy.assert_not_called()++ buf.insert_text("line two")+ time.sleep(_RAPID_INPUT_ENTER_WINDOW_S * 3) # the paste has finished; a human presses Enter+ shell._tui_handle_enter(_event(buf))+ shell._tui_enter_while_busy.assert_called_once()+ assert shell._tui_enter_while_busy.call_args.args[0] == "line one\nline two"