Skip to content

fix(cli): defer Enter during rapid text input to prevent multiline paste splitting - #19494

Closed
Ralojeil1 wants to merge 1 commit into
NousResearch:mainfrom
Ralojeil1:fix/cli-defer-enter-on-rapid-paste
Closed

fix(cli): defer Enter during rapid text input to prevent multiline paste splitting#19494
Ralojeil1 wants to merge 1 commit into
NousResearch:mainfrom
Ralojeil1:fix/cli-defer-enter-on-rapid-paste

Conversation

@Ralojeil1

Copy link
Copy Markdown

Problem

When pasting multiline text into the Hermes CLI prompt without bracketed paste support (Windows Terminal, tmux, some terminals), newlines arrive as individual Enter key events. Each line gets submitted as a separate steering message instead of one complete message.

This is a major UX issue — pasting a 20-line context block floods the agent with 20 fragmented steering messages.

Root Cause

Without bracketed paste, pasted newlines are indistinguishable from manual Enter presses. The @kb.add('enter') handler fires for each newline, routing each line to the steering queue independently.

Fix: 50ms Timing Guard

Three changes in cli.py (9 lines total):

  1. Tracker variable_last_text_change = [None]
  2. Timestamp update_last_text_change[0] = time.monotonic() in _on_text_changed
  3. Defer guard in handle_enter before normal input routing:
    if _last_text_change[0] and (time.monotonic() - _last_text_change[0]) < 0.05:
        return

The 50ms threshold cleanly separates:

Scenario Time between chars
Paste (no bracketed paste) < 1ms
Fast human typing ~80-100ms
Normal typing > 50ms

Tested

  • ✅ Windows Terminal (no bracketed paste) — multiline pastes buffer correctly
  • ✅ Large pastes (731+ lines) accumulate fully, only submit on physical Enter
  • ✅ No impact on normal or fast manual typing
  • ✅ Functions across tmux, Windows Terminal, and any terminal without bracketed paste

Notes

Adapted from @iRonin's approach in PR #10997. This version updates the fix for the current codebase which has newer _on_text_changed logic (bracketed-paste leak stripping) not present in the original PR's base.

Closes #10994

…ste splitting

When pasting multiline text without bracketed paste support (Windows Terminal,
tmux, some terminals), newlines arrive as individual Enter key events, causing
the CLI to submit each line as a separate steering message.

Add a 50ms timing guard: track _last_text_change timestamp on every buffer
modification, and defer submission in handle_enter if text changed <50ms ago.
This catches paste-speed input (<1ms between chars) while leaving normal typing
(>50ms) unaffected.

Tested on:
- Windows Terminal (no bracketed paste) — works correctly
- Large multi-line pastes buffer fully, only submit on manual Enter
- No impact on normal or fast typing

Adapted from @iRonin's approach in PR NousResearch#10997, updated for current codebase
with bracketed-paste leak stripping in _on_text_changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(cli): multiline paste splits into separate steering messages when agent is running

1 participant