fix(cli): handle multi-line paste on Windows & fix command approval chaining #4915
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two separate issues:
Fix #4773: Multi-line Paste on Windows
Root Cause
On Windows terminals (especially those without proper bracketed paste mode support), pasting multi-line text causes each line to be submitted immediately because newlines are sent as Enter key presses.
Changes
keyboard.ts: Added paste detection system with atoms:
lastCharTimestampAtom: Tracks when last character was receivedcharCountInWindowAtom: Counts characters in rapid input windowhasSuppressedEnterAtom: Tracks if we've suppressed an Enter (active paste mode)resetPasteDetectionAtom: Resets paste detection statecheckPasteDetectionAtom: Checks if we should suppress EnterupdatePasteDetectionAtom: Updates paste detection on character inputschedulePasteSubmitAtom: Schedules auto-submit after paste timeoutEnter handling: Modified to detect paste by:
hasSuppressedEnterAtom)Testing
Fix #4812: Command Approval Chaining Bypass (Security)
Problem
The
matchesCommandPatternfunction usedstartsWithwith word boundary checking, but didn't account for command chaining operators. This allowed commands likegit status; rm -rf /tmpto match the patterngit statusbecause the semicolon was treated as a word boundary.Solution
parseCommandfrom shared utilitiesTesting
Added comprehensive tests for:
;)&&)||)|)&)All existing tests continue to pass.
@kilocode/cli