Large pastes truncated in terminal input
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
- Copy a large prompt (1000+ characters) to clipboard
- Right-click to paste into nanocoder input
- Observe the
[Paste #1: XX chars]placeholder - 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:
- Large pastes are sent by the terminal in multiple chunks
- The 200ms window may not be sufficient for large pastes over slow connections or in WSL
- 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 heuristicssource/utils/paste-utils.ts- Paste placeholder creationsource/components/user-input.tsx- Input component using useInputState
Workaround
For now, users can:
- Use smaller pastes and send in multiple messages
- Use a file: save the prompt to a file and reference it with
@filename - Type the prompt directly (for shorter prompts)
Labels
buginputwsl
Hey @JimStenstrom - thanks for identifying this. Do you want to tackle a fix or shall we triage somewhere else? :)
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 - 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!
Hi! Since I see that no progress has been made, I want to work in it, can you assing it to me?
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