nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

Large pastes truncated in terminal input

Open JimStenstrom opened this issue 1 year ago • 5 comments

Large pastes truncated in terminal input

Description

When pasting large text (1000+ characters) via right-click in the terminal, the paste is often truncated. Only a portion of the pasted content is captured, resulting in incomplete prompts being sent to the LLM.

Environment

  • OS: Linux (WSL2 on Windows)
  • Terminal: Windows Terminal / WSL
  • Node.js version: 18+
  • Nanocoder version: 1.17.2

Steps to Reproduce

  1. Copy a large prompt (1000+ characters) to clipboard
  2. Right-click to paste into nanocoder input
  3. Observe the [Paste #1: XX chars] placeholder
  4. The character count is significantly less than expected

Example:

  • Copied text: ~1,400 characters
  • Captured: 48 characters
  • Display: [Paste #1: 48 chars]

Expected Behavior

The full pasted content should be captured regardless of size.

Actual Behavior

Only a portion of the paste is captured. The truncation point varies.

Root Cause Analysis

The issue is in source/hooks/useInputState.ts lines 33-36 and 65-113.

Nanocoder uses a chunked paste handling mechanism because terminals/CLIs don't receive native paste events. Instead, paste detection relies on heuristics:

const PASTE_CHUNK_WINDOW_MS = 200; // Time window to consider text as part of same paste

The problem:

  1. Large pastes are sent by the terminal in multiple chunks
  2. The 200ms window may not be sufficient for large pastes over slow connections or in WSL
  3. Chunks arriving after the window closes are either:
    • Treated as new input (creating duplicate placeholders)
    • Dropped entirely

Potential Solutions

Short-term: Increase the chunk window

const PASTE_CHUNK_WINDOW_MS = 500; // Increase from 200ms to 500ms

Medium-term: Dynamic window based on paste size

// Extend window proportionally to paste size
const dynamicWindow = Math.min(
  PASTE_CHUNK_WINDOW_MS + (placeholder.content.length / 10),
  2000 // Max 2 seconds
);

Long-term: Use terminal bracketed paste mode

Many modern terminals support bracketed paste mode which wraps pasted content in escape sequences:

  • \e[200~ ... pasted content ... \e[201~

This would allow reliable paste detection without heuristics.

Related Files

  • source/hooks/useInputState.ts - Main paste handling logic (lines 33-113)
  • source/utils/paste-detection.ts - Paste detection heuristics
  • source/utils/paste-utils.ts - Paste placeholder creation
  • source/components/user-input.tsx - Input component using useInputState

Workaround

For now, users can:

  1. Use smaller pastes and send in multiple messages
  2. Use a file: save the prompt to a file and reference it with @filename
  3. Type the prompt directly (for shorter prompts)

Labels

  • bug
  • input
  • wsl

JimStenstrom avatar Dec 01 '25 22:12 JimStenstrom

Hey @JimStenstrom - thanks for identifying this. Do you want to tackle a fix or shall we triage somewhere else? :)

will-lamerton avatar Dec 02 '25 13:12 will-lamerton

I can take a crack at it, have a few ideas on how. Wanted to put it in the bug tracker first and get feedback.

JimStenstrom avatar Dec 02 '25 15:12 JimStenstrom

@JimStenstrom - yeah, pasting in terminals is fun. We did a bit of work on this a month or so ago which made improvements to pasting.

const PASTE_CHUNK_WINDOW_MS = 500; // Increase from 200ms to 500ms

^ This is okay but affects other functionality and things being caught as "pastes".

Further work to improve pasting would definitely benefit!

will-lamerton avatar Dec 02 '25 15:12 will-lamerton

Hi! Since I see that no progress has been made, I want to work in it, can you assing it to me?

Alvaro842DEV avatar Dec 16 '25 22:12 Alvaro842DEV

Hi! Since I see that no progress has been made, I want to work in it, can you assing it to me?

Go for it :D

will-lamerton avatar Dec 16 '25 23:12 will-lamerton