Insert non-image file references on drop/paste#2091
Insert non-image file references on drop/paste#2091itsklimov wants to merge 3 commits intopingdotgg:mainfrom
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6e1a6be281
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6e1a6be. Configure here.
ApprovabilityVerdict: Needs human review This PR introduces a new feature that changes how non-image files are handled during drop/paste operations - instead of being ignored, they now insert file path references as text into the composer. This adds new user-facing behavior, new IPC contracts, and runtime behavior changes that warrant human review. You can customize Macroscope's approvability policy. Learn more. |

Summary
This changes composer file ingestion so that dropping or pasting non-image files inserts file references into the prompt instead of rejecting them.
Images keep the existing attachment flow.
Non-image files now resolve to local file references:
Related issues
Prior art / related PRs
#885 is directionally the same user-facing fix, but it targets the older composer structure. The current implementation path now runs through
ChatComposer, the currentLocalApisurface, and the currentComposerPromptEditorhandle rather than the olderChatView-centric flow.This PR keeps the same product intent, but re-implements it against the current architecture so it is actually mergeable on top of today's code.
#2108 expands the drag/drop surface for URL-backed image drags from other browser tabs. This PR covers the
File-backed non-image path and paste/drop insertion of local file references. They touch adjacent composer code, but solve different cases.Before / After
Before
Dropping a non-image file into the composer is rejected with:
After: non-image file drop
Dropping a non-image file inserts its local file reference into the composer.
After: mixed drop
Mixed drops keep image attachments and insert non-image file references into the prompt.
Problem
Today the composer only accepts
image/*files.If a user drops or pastes a
.json,.csv,.txt, or other non-image file into the chat box, the action is rejected with:That is a poor fit for the actual developer workflow here.
In practice, users often want to reference a local file in their prompt rather than upload it as binary message content.
Examples:
look at /Users/alice/project/output.jsoncompare this against ./fixtures/request.txtinspect the CSV I just droppedWhy this approach
I intentionally did not implement arbitrary non-image attachments.
That would expand the product contract significantly:
For this UX, that is unnecessary.
The cleaner behavior is:
image/*as true attachmentsThis matches how coding-agent users actually work and keeps the existing send contract unchanged.
What changed
Desktop bridge support
Added
getPathForFile(file)to the desktop bridge contract and preload layer.On Electron desktop this uses
webUtils.getPathForFile(file), which is the supported replacement for the removed nonstandardFile.pathbehavior.App-level local API
Exposed file path resolution through
LocalApi.shell.getPathForFile(...)so the composer does not need to talk towindow.desktopBridgedirectly.This keeps the platform-specific behavior behind the same local-shell abstraction already used for other desktop/browser capabilities.
Composer ingestion behavior
Unified paste/drop handling so both paths now:
Mixed drops work as expected:
Editor insertion behavior
Added an editor handle method for text insertion at the active composer cursor so file references are inserted into the real prompt state rather than reconstructed from a stale plain-text snapshot.
Reference formatting
Added a small formatter for prompt-safe file references:
User impact
This removes a frustrating dead end in the composer.
After this change:
file.name)Validation
Ran:
bun fmtbun lintbun typecheckbun run test src/localApi.test.ts src/composer-logic.test.tsinapps/webAlso manually validated the desktop behavior:
Note
Medium Risk
Changes input handling in the composer (drop/paste) and exposes a new desktop bridge method that resolves local filesystem paths, which could affect UX and path/quoting edge cases across platforms.
Overview
Enables drag-and-drop/paste of non-image files into the chat composer by inserting formatted file references into the prompt, while keeping existing image attachment behavior.
Adds
shell.getPathForFile(file)toLocalApi/DesktopBridge(wired through Electron preload viawebUtils.getPathForFile) so desktop builds can resolve real filesystem paths and web builds fall back to filenames, and introducesformatComposerFileReferenceplus a newComposerPromptEditorimperative method (insertTextAndFocus) to insert references at the current cursor.Reviewed by Cursor Bugbot for commit 1495e0b. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Insert non-image file references into the composer on drop or paste
formatComposerFileReferencein composer-logic.ts to quote paths with whitespace or special characters.shell.getPathForFileto theLocalApiandDesktopBridgeinterfaces, delegating to Electron'swebUtils.getPathForFileon desktop to resolveFileobjects to filesystem paths.insertTextAndFocusto theComposerPromptEditorHandleimperative ref to support programmatic text insertion at the current cursor.Macroscope summarized 1495e0b.