Skip to content

The agent that grows with you

fix(cli): backslash continuation runs before the paste-timing guard

teknium11de9963ce761
diff --git a/hermes_cli/cli_tui_mixin.py b/hermes_cli/cli_tui_mixin.py
index 10c65202a09..cc3c6b4cbd5 100644
--- a/hermes_cli/cli_tui_mixin.py
+++ b/hermes_cli/cli_tui_mixin.py
@@ -1351,14 +1351,9 @@ class CLITuiMixin:
if self._tui_enter_overlay(event):
return
buf = 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")
- return
raw_text = buf.text
+ # Explicit `\` + Enter continuation runs first so its backslash is consumed identically
+ # whether the Enter was typed or arrived inside a paste.
if (
self._tui_multiline_shortcuts
and buf.cursor_position == len(raw_text)
@@ -1368,6 +1363,13 @@ class CLITuiMixin:
buf.cursor_position = len(continued)
event.app.invalidate()
return
+ # 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 (#10994).
+ if time.monotonic() - getattr(self, "_tui_last_text_change", 0.0) < _RAPID_INPUT_ENTER_WINDOW_S:
+ buf.insert_text("\n")
+ return
text = raw_text.strip()
has_images = bool(self._attached_images)
if not (text or has_images):
diff --git a/tests/cli/test_tui_rapid_enter_paste.py b/tests/cli/test_tui_rapid_enter_paste.py
index 00be39fda16..fe848ae7287 100644
--- a/tests/cli/test_tui_rapid_enter_paste.py
+++ b/tests/cli/test_tui_rapid_enter_paste.py
@@ -49,3 +49,16 @@ def test_enter_right_after_text_arrives_is_a_newline_not_a_steer():
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"
+
+
+def test_fast_backslash_continuation_still_consumes_the_backslash():
+ """`\\` + Enter inside a paste (multiline shortcuts on) behaves like a typed one: the
+ backslash is removed and a newline inserted, never a literal backslash left in the text."""
+ shell = _shell()
+ shell._tui_multiline_shortcuts = True
+ buf = Buffer()
+ buf.on_text_changed += shell._tui_on_text_changed
+ buf.insert_text("alpha \\")
+ shell._tui_handle_enter(_event(buf)) # < 50 ms after the text change
+ assert buf.text == "alpha \n"
+ shell._tui_enter_while_busy.assert_not_called()