Skip to content

Conversation

@marius-kilocode
Copy link
Contributor

@marius-kilocode marius-kilocode commented Dec 5, 2025

This PR adds image support to the CLI.

  • Allow Ctrl+V in the CLI to paste clipboard images, attach them as [Image #N], and send them with messages (macOS only, with status feedback and cleanup).
  • Add image mention parsing (@path and [Image #N]) so pasted or referenced images are included when sending messages.
  • Split media code into a dedicated module with platform-specific clipboard handlers and image utilities; keep behavior consistent and logged.
  • Document the CLI test naming exception (.test.ts[x]) and add covering tests for media parsing/clipboard/image loading.
  • Windows and Linux are currently not supported (Linux is currently blocked by this kitty on linux doesn't correctly parse ctrl+c #3495 )
image image

@changeset-bot
Copy link

changeset-bot bot commented Dec 5, 2025

🦋 Changeset detected

Latest commit: 62e7917

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Patch

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

Copy link
Contributor

Copilot AI left a 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)

Copy link
Contributor

@kiloconnect kiloconnect bot left a 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 parsing
  • cli/src/media/clipboard-linux.ts - Clean Linux clipboard implementation
  • cli/src/media/clipboard-macos.ts - Proper macOS clipboard with path escaping
  • cli/src/media/clipboard-shared.ts - Good shared utilities
  • cli/src/media/clipboard.ts - Clean main clipboard module
  • cli/src/media/images.ts - Solid image utilities with size limits
  • cli/src/media/processMessageImages.ts - Good message processing logic
  • cli/src/state/atoms/keyboard.ts - Proper Ctrl+V handling with error catching
  • cli/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)

Copy link
Contributor

@kiloconnect kiloconnect bot left a 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 handling
  • cli/src/media/clipboard-linux.ts - Clean Linux clipboard implementation with xclip
  • cli/src/media/clipboard-macos.ts - Proper macOS clipboard with AppleScript path escaping
  • cli/src/media/clipboard-shared.ts - Good shared utilities and type definitions
  • cli/src/media/clipboard.ts - Clean main clipboard module with platform routing
  • cli/src/media/images.ts - Solid image utilities with appropriate size limits (8MB)
  • cli/src/media/processMessageImages.ts - Good message processing logic
  • cli/src/state/atoms/keyboard.ts - Proper Ctrl+V handling with error catching
  • cli/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 handleClipboardImagePaste without .catch() - Fixed
  • path.join instead of string concatenation - Fixed
  • ✅ Comprehensive test coverage - Added

Copy link
Contributor

@kiloconnect kiloconnect bot left a 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 handling
  • cli/src/media/clipboard-linux.ts - Clean Linux clipboard implementation with xclip
  • cli/src/media/clipboard-macos.ts - Proper macOS clipboard with AppleScript path escaping
  • cli/src/media/clipboard-shared.ts - Good shared utilities and type definitions
  • cli/src/media/clipboard.ts - Clean main clipboard module with platform routing
  • cli/src/media/images.ts - Solid image utilities with appropriate size limits (8MB)
  • cli/src/media/processMessageImages.ts - Good message processing logic
  • cli/src/state/atoms/keyboard.ts - Proper Ctrl+V handling with error catching
  • cli/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

Copy link
Contributor

@kiloconnect kiloconnect bot left a 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 handling
  • cli/src/media/clipboard-linux.ts - Clean Linux clipboard implementation with xclip
  • cli/src/media/clipboard-macos.ts - Proper macOS clipboard with AppleScript path escaping
  • cli/src/media/clipboard-shared.ts - Good shared utilities and type definitions
  • cli/src/media/clipboard.ts - Clean main clipboard module with platform routing
  • cli/src/media/images.ts - Solid image utilities with appropriate size limits (8MB)
  • cli/src/media/processMessageImages.ts - Good message processing logic
  • cli/src/state/atoms/keyboard.ts - Proper Ctrl+V handling with error catching
  • cli/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:

  • ciMode in useMessageHandler.ts dependency array (line 140) is not used in the callback - this is a very minor code quality issue that doesn't affect functionality.

Copy link
Contributor

@kiloconnect kiloconnect bot left a 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 handling
  • cli/src/media/clipboard-linux.ts - Clean Linux clipboard implementation with xclip
  • cli/src/media/clipboard-macos.ts - Proper macOS clipboard with AppleScript path escaping
  • cli/src/media/clipboard-shared.ts - Good shared utilities and type definitions
  • cli/src/media/clipboard.ts - Clean main clipboard module with platform routing
  • cli/src/media/images.ts - Solid image utilities with appropriate size limits (8MB)
  • cli/src/media/processMessageImages.ts - Good message processing logic with proper regex handling
  • cli/src/state/atoms/keyboard.ts - Proper Ctrl+V handling with error catching
  • cli/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):

  • ciMode in useMessageHandler.ts dependency array (line 140) is not used in the callback - this is a very minor code quality issue that doesn't affect functionality.

Copy link
Contributor

@kiloconnect kiloconnect bot left a 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):

  • ciMode in useMessageHandler.ts dependency array (line 140) is not used in the callback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants