Skip to content

Insert non-image file references on drop/paste#2091

Open
itsklimov wants to merge 3 commits intopingdotgg:mainfrom
itsklimov:feat/non-image-file-references
Open

Insert non-image file references on drop/paste#2091
itsklimov wants to merge 3 commits intopingdotgg:mainfrom
itsklimov:feat/non-image-file-references

Conversation

@itsklimov
Copy link
Copy Markdown

@itsklimov itsklimov commented Apr 16, 2026

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:

  • on desktop, the composer inserts the native file system path
  • outside the desktop shell, it falls back to the file name

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 current LocalApi surface, and the current ComposerPromptEditor handle rather than the older ChatView-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:

Please attach image files only.

image

After: non-image file drop

Dropping a non-image file inserts its local file reference into the composer.

image

After: mixed drop

Mixed drops keep image attachments and insert non-image file references into the prompt.

image

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:

Please attach image files only.

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.json
  • compare this against ./fixtures/request.txt
  • inspect the CSV I just dropped

Why this approach

I intentionally did not implement arbitrary non-image attachments.

That would expand the product contract significantly:

  • new attachment semantics for non-image files
  • persistence and preview rules
  • payload size and MIME policy questions
  • provider/runtime expectations for how local files should be interpreted

For this UX, that is unnecessary.
The cleaner behavior is:

  • keep image/* as true attachments
  • treat non-image files as prompt references

This 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 nonstandard File.path behavior.

App-level local API

Exposed file path resolution through LocalApi.shell.getPathForFile(...) so the composer does not need to talk to window.desktopBridge directly.

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:

  • keep images on the current attachment flow
  • resolve non-image files into prompt text references
  • insert those references at the current cursor position in the prompt editor

Mixed drops work as expected:

  • images are attached
  • non-image file references are inserted into the prompt

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:

  • plain paths are inserted as-is
  • paths with spaces are quoted
  • paths containing quotes fall back to the next-safe quoting form

User impact

This removes a frustrating dead end in the composer.

After this change:

  • dropping a config/data/text file into the composer is useful instead of rejected
  • desktop users get the real native path
  • browser users still get a reasonable fallback (file.name)
  • image attachments continue to work exactly as before

Validation

Ran:

  • bun fmt
  • bun lint
  • bun typecheck
  • bun run test src/localApi.test.ts src/composer-logic.test.ts in apps/web

Also manually validated the desktop behavior:

  • dropping non-image files inserts file references into the prompt
  • mixed image + non-image drops keep image attachments and insert file references
  • pasting non-image files uses the same path insertion 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) to LocalApi/DesktopBridge (wired through Electron preload via webUtils.getPathForFile) so desktop builds can resolve real filesystem paths and web builds fall back to filenames, and introduces formatComposerFileReference plus a new ComposerPromptEditor imperative 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

  • Dropping or pasting non-image files now inserts formatted file path references into the chat composer, while images continue to be handled as attachments.
  • Adds formatComposerFileReference in composer-logic.ts to quote paths with whitespace or special characters.
  • Adds shell.getPathForFile to the LocalApi and DesktopBridge interfaces, delegating to Electron's webUtils.getPathForFile on desktop to resolve File objects to filesystem paths.
  • Adds insertTextAndFocus to the ComposerPromptEditorHandle imperative ref to support programmatic text insertion at the current cursor.

Macroscope summarized 1495e0b.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3ce52c9d-439d-4020-8e0f-3814575d0105

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 16, 2026
@itsklimov itsklimov changed the title [codex] Insert non-image file references on drop/paste Insert non-image file references on drop/paste Apr 16, 2026
@itsklimov itsklimov marked this pull request as ready for review April 16, 2026 23:00
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread apps/web/src/components/chat/ChatComposer.tsx
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread apps/web/src/components/chat/ChatComposer.tsx Outdated
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 16, 2026

Approvability

Verdict: 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.

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

Labels

size:L 100-499 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Allow drag and drop text files into the prompt builder as context Restricted to only attach image files?

1 participant