-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add image paste support to CLI #4244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 62e7917 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds comprehensive image support to the CLI, enabling users to paste images directly with Ctrl+V and reference images via @path mentions. The implementation introduces a new media module with platform-specific clipboard handlers for macOS and Linux, while Windows support is deferred.
Key changes:
- Clipboard image paste with Ctrl+V creates temporary files and inserts [Image #N] references
- @path mention parsing extracts and loads images from file paths
- Message processing combines both clipboard-pasted and @path-referenced images before sending
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| cli/src/state/hooks/useMessageHandler.ts | Integrates image processing into message sending flow, handling both @path mentions and [Image #N] references with error display |
| cli/src/state/atoms/keyboard.ts | Adds Ctrl+V handler for clipboard paste, image reference tracking atoms, and status feedback for clipboard operations |
| cli/src/state/atoms/tests/shell.test.ts | Adds execFile mock to prevent clipboard code from executing during shell tests |
| cli/src/media/processMessageImages.ts | Processes messages to extract and load images from both [Image #N] references and @path mentions |
| cli/src/media/images.ts | Provides image utilities for validation, size checking, MIME type detection, and data URL conversion |
| cli/src/media/clipboard.ts | Main clipboard module that delegates to platform-specific implementations |
| cli/src/media/clipboard-shared.ts | Shared clipboard utilities including format detection, path helpers, and result types |
| cli/src/media/clipboard-macos.ts | macOS clipboard implementation using osascript to read/write images via AppleScript |
| cli/src/media/clipboard-linux.ts | Linux clipboard implementation using xclip to access clipboard images |
| cli/src/media/atMentionParser.ts | Parses @path mentions with support for quoted paths, escaped characters, and automatic image detection |
| cli/src/media/tests/processMessageImages.test.ts | Tests for image reference removal (minimal coverage) |
| cli/src/media/tests/images.test.ts | Comprehensive tests for image path validation, MIME types, data URL conversion, and size limits |
| cli/src/media/tests/clipboard.test.ts | Tests for clipboard parsing logic, format detection, and platform support |
| cli/src/media/tests/atMentionParser.test.ts | Comprehensive tests for @path mention parsing with various edge cases |
| .kilocode/rules/rules.md | Documents CLI test file naming exception (.test.ts instead of .spec.ts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ No New Issues Found
16 files reviewed | Confidence: 90% | Recommendation: Merge
Previous Review Issues - Status
All significant issues from the previous Copilot review have been addressed:
| Issue | Status |
|---|---|
Async handleClipboardImagePaste without .catch() |
✅ Fixed - now has proper error handlers |
| AppleScript path escaping vulnerability | ✅ Fixed - proper escaping added |
path.join instead of string concatenation |
✅ Fixed - now uses path.join |
Redundant hasAnyImages variable |
✅ Fixed - uses processed.hasImages directly |
| Minimal test coverage | ✅ Fixed - comprehensive tests added |
Global regex lastIndex issue |
⚪ False positive - String.replace() doesn't have this issue |
clipboardStatusTimer race condition |
⚪ Low severity - acceptable for this use case |
| Debug logging condition too broad | ⚪ Intentional for debugging purposes |
Review Details
Files Reviewed:
cli/src/media/atMentionParser.ts- Well-structured @path mention parsingcli/src/media/clipboard-linux.ts- Clean Linux clipboard implementationcli/src/media/clipboard-macos.ts- Proper macOS clipboard with path escapingcli/src/media/clipboard-shared.ts- Good shared utilitiescli/src/media/clipboard.ts- Clean main clipboard modulecli/src/media/images.ts- Solid image utilities with size limitscli/src/media/processMessageImages.ts- Good message processing logiccli/src/state/atoms/keyboard.ts- Proper Ctrl+V handling with error catchingcli/src/state/hooks/useMessageHandler.ts- Clean integration- Test files with comprehensive coverage
Checked: Security (path escaping, command injection), bugs, error handling, performance
Highlights:
- Good separation of platform-specific code
- Proper error handling and user feedback
- Comprehensive test coverage
- Clean TypeScript types
- Appropriate size limits (8MB for images, 50MB buffer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ No Issues Found
16 files reviewed | Confidence: 92% | Recommendation: Merge
Review Details
Files Reviewed:
cli/src/media/atMentionParser.ts- Well-structured @path mention parsing with proper escape handlingcli/src/media/clipboard-linux.ts- Clean Linux clipboard implementation with xclipcli/src/media/clipboard-macos.ts- Proper macOS clipboard with AppleScript path escapingcli/src/media/clipboard-shared.ts- Good shared utilities and type definitionscli/src/media/clipboard.ts- Clean main clipboard module with platform routingcli/src/media/images.ts- Solid image utilities with appropriate size limits (8MB)cli/src/media/processMessageImages.ts- Good message processing logiccli/src/state/atoms/keyboard.ts- Proper Ctrl+V handling with error catchingcli/src/state/hooks/useMessageHandler.ts- Clean integration with image processing- Test files with comprehensive coverage
Checked: Security (path escaping, command injection), bugs, error handling, performance
Highlights:
- Good separation of platform-specific code (macOS/Linux)
- Proper error handling with user feedback
- Comprehensive test coverage for parsing and clipboard utilities
- Clean TypeScript types throughout
- Appropriate size limits (8MB for images, 50MB buffer)
- AppleScript path escaping properly handles special characters
Previous Review Issues - All Addressed:
- ✅ AppleScript path escaping vulnerability - Fixed
- ✅ Async
handleClipboardImagePastewithout.catch()- Fixed - ✅
path.joininstead of string concatenation - Fixed - ✅ Comprehensive test coverage - Added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ No New Issues Found
16 files reviewed | Confidence: 92% | Recommendation: Merge
Reviewed after merge from main (877e1a4). The image paste support implementation remains solid.
Review Details
Files Reviewed:
cli/src/media/atMentionParser.ts- Well-structured @path mention parsing with proper escape handlingcli/src/media/clipboard-linux.ts- Clean Linux clipboard implementation with xclipcli/src/media/clipboard-macos.ts- Proper macOS clipboard with AppleScript path escapingcli/src/media/clipboard-shared.ts- Good shared utilities and type definitionscli/src/media/clipboard.ts- Clean main clipboard module with platform routingcli/src/media/images.ts- Solid image utilities with appropriate size limits (8MB)cli/src/media/processMessageImages.ts- Good message processing logiccli/src/state/atoms/keyboard.ts- Proper Ctrl+V handling with error catchingcli/src/state/hooks/useMessageHandler.ts- Clean integration with image processing- Test files with comprehensive coverage
Checked: Security (path escaping, command injection), bugs, error handling, performance
Highlights:
- Good separation of platform-specific code (macOS/Linux)
- Proper error handling with user feedback
- Comprehensive test coverage for parsing and clipboard utilities
- Clean TypeScript types throughout
- Appropriate size limits (8MB for images, 50MB buffer)
- AppleScript path escaping properly handles special characters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ No New Issues Found
16 files reviewed | Confidence: 92% | Recommendation: Merge
This PR adds comprehensive image paste support to the CLI with a well-structured implementation.
Review Details
Files Reviewed:
cli/src/media/atMentionParser.ts- Well-structured @path mention parsing with proper escape handlingcli/src/media/clipboard-linux.ts- Clean Linux clipboard implementation with xclipcli/src/media/clipboard-macos.ts- Proper macOS clipboard with AppleScript path escapingcli/src/media/clipboard-shared.ts- Good shared utilities and type definitionscli/src/media/clipboard.ts- Clean main clipboard module with platform routingcli/src/media/images.ts- Solid image utilities with appropriate size limits (8MB)cli/src/media/processMessageImages.ts- Good message processing logiccli/src/state/atoms/keyboard.ts- Proper Ctrl+V handling with error catchingcli/src/state/hooks/useMessageHandler.ts- Clean integration with image processing- Test files with comprehensive coverage
Checked: Security (path escaping, command injection), bugs, error handling, performance
Highlights:
- Good separation of platform-specific code (macOS/Linux)
- Proper error handling with user feedback
- Comprehensive test coverage for parsing and clipboard utilities
- Clean TypeScript types throughout
- Appropriate size limits (8MB for images, 50MB buffer)
- AppleScript path escaping properly handles special characters
Minor Observation:
ciModeinuseMessageHandler.tsdependency array (line 140) is not used in the callback - this is a very minor code quality issue that doesn't affect functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ No New Issues Found
16 files reviewed | Confidence: 92% | Recommendation: Merge
Reviewed after merge from main (0bc71ad). No new code changes since last review - only merge commit.
Review Details
Files Reviewed:
cli/src/media/atMentionParser.ts- Well-structured @path mention parsing with proper escape handlingcli/src/media/clipboard-linux.ts- Clean Linux clipboard implementation with xclipcli/src/media/clipboard-macos.ts- Proper macOS clipboard with AppleScript path escapingcli/src/media/clipboard-shared.ts- Good shared utilities and type definitionscli/src/media/clipboard.ts- Clean main clipboard module with platform routingcli/src/media/images.ts- Solid image utilities with appropriate size limits (8MB)cli/src/media/processMessageImages.ts- Good message processing logic with proper regex handlingcli/src/state/atoms/keyboard.ts- Proper Ctrl+V handling with error catchingcli/src/state/hooks/useMessageHandler.ts- Clean integration with image processing- Test files with comprehensive coverage
Checked: Security (path escaping, command injection), bugs, error handling, performance
Highlights:
- Good separation of platform-specific code (macOS/Linux)
- Proper error handling with user feedback
- Comprehensive test coverage for parsing and clipboard utilities
- Clean TypeScript types throughout
- Appropriate size limits (8MB for images, 50MB buffer)
- AppleScript path escaping properly handles special characters
Minor Observation (non-blocking):
ciModeinuseMessageHandler.tsdependency array (line 140) is not used in the callback - this is a very minor code quality issue that doesn't affect functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅ No New Issues Found
5 files reviewed (incremental) | Confidence: 92% | Recommendation: Merge
Reviewed the latest commit (62e7917) which removes Linux clipboard support, simplifying to macOS-only.
Review Details
Changes in Latest Commit:
- Removed
cli/src/media/clipboard-linux.ts(116 lines deleted) - Updated
.changeset/cli-image-paste-support.md- "macOS only" description - Simplified
cli/src/media/clipboard.ts- removed Linux imports/code paths - Simplified
cli/src/media/clipboard-shared.ts- removed Linux utilities - Updated
cli/src/media/__tests__/clipboard.test.ts- removed Linux tests
Verified:
- ✅ No dead code - all Linux-related imports properly removed
- ✅ Tests updated - Linux-specific tests removed
- ✅ Documentation updated - changeset reflects "macOS only"
- ✅ Error messages correct -
getUnsupportedClipboardPlatformMessage()states "macOS only" - ✅ Platform checks consistent - all checks now only check for
darwin
Minor Observation (non-blocking, previously noted):
ciModeinuseMessageHandler.tsdependency array (line 140) is not used in the callback
This PR adds image support to the CLI.