Commit cd79f2a
fix(prompt): scale bracketed-paste delay by line count to prevent stuck initial prompts (#107)
* fix(prompt): scale bracketed-paste delay by line count to prevent stuck initial prompts
When an agent enables bracketed paste mode (CSI ? 2004 h), synthetic prompt
sends wrap the text in \x1b[200~...\x1b[201~ to avoid Codex's paste-burst
guard. However, TUI agents like Claude Code process the paste asynchronously —
if \r arrives while the paste is still being consumed, it is absorbed into the
input buffer as a newline rather than submitting the prompt.
The previous fixed 50ms delay was sufficient for short prompts but too short
for large ones (e.g. a 31-line initial task prompt). The symptom is the agent
sitting in INSERT mode with "[Pasted text #1 +N lines]" in its input, never
sending.
Fix:
- Track bracketed paste mode (CSI ? 2004 h/l) in AgentTrackingState via
updateBracketedPasteMode(), called on each PTY data chunk in markAgentOutput()
- Export isAgentBracketedPasteEnabled() so sendPrompt can conditionally wrap
- Scale the pre-Enter delay: max(50ms, lines * 15ms), capped at 500ms —
a 31-line prompt now waits ~465ms instead of 50ms
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* test(prompt): add pasteDelayMs regression tests; export fn; fix duplicate constants
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent 0c93d63 commit cd79f2a
2 files changed
Lines changed: 31 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
63 | 74 | | |
64 | 75 | | |
65 | 76 | | |
| |||
496 | 507 | | |
497 | 508 | | |
498 | 509 | | |
| 510 | + | |
499 | 511 | | |
500 | 512 | | |
501 | | - | |
502 | | - | |
503 | | - | |
| 513 | + | |
504 | 514 | | |
505 | | - | |
| 515 | + | |
506 | 516 | | |
507 | 517 | | |
508 | 518 | | |
| |||
0 commit comments