feat(composer): drop non-image files as filesystem paths #7749
Closednioasoft(GitHub profile, opens in a new tab)wants to merge 4 commits into
main fromrefs/pull/7749/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/web/src/components/chat/droppedFilePaths.ts lines 34 to 36Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +9,21 @@9+ */10+11+/**12+ * Quote a path for the prompt when whitespace would make where it ends13+ * ambiguous. This is prompt text, not a shell command — the goal is a clear14+ * boundary for the reader, not shell-injection safety.15+ */16+export function quoteDroppedFilePath(path: string): string {17+ return /\s/.test(path) ? `"${path}"` : path;18+}19+20+/**21+ * The text inserted into the composer for a set of dropped paths. Empty and22+ * whitespace-only paths are dropped (a bridge that can't resolve a file23+ * returns null, which the caller filters, but be defensive about "" too).24+ */25+export function formatDroppedFilePaths(paths: ReadonlyArray<string>): string {26+ return paths27+ .map((path) => path.trim())28+ .filter((path) => path.length > 0)29+ .map(quoteDroppedFilePath)apps/web/src/components/chat/droppedFilePaths.ts lines 17 to 17OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,17 @@1+/**2+ * Files dropped from the OS that aren't images are handed to the agent by3+ * *path*, not by content: it can open the file itself, so a 40MB recording or4+ * a PDF never has to cross the wire as an attachment. This mirrors dropping a5+ * file into a terminal, where the shell receives the path.6+ *7+ * Paths are only available in the desktop app (Electron's `webUtils`); in a8+ * browser tab the File object carries no filesystem path at all.9+ */10+11+/**12+ * Quote a path for the prompt when whitespace would make where it ends13+ * ambiguous. This is prompt text, not a shell command — the goal is a clear14+ * boundary for the reader, not shell-injection safety.15+ */16+export function quoteDroppedFilePath(path: string): string {17+ return /\s/.test(path) ? `"${path}"` : path;
- @@ -2565,0 +2568,21 @@2568+ * Insert dropped non-image files as filesystem paths. Only the desktop app2569+ * can resolve a path from a dropped File, so in a browser tab this reports2570+ * why nothing was inserted instead of silently swallowing the drop.2571+ */2572+ const insertDroppedFilePaths = (files: File[]) => {2573+ const resolvePath = window.desktopBridge?.getPathForFile;2574+ if (!resolvePath) {2575+ setThreadError(2576+ activeThreadId,2577+ "Attaching files by path needs the desktop app. Paste an image, or type the path.",2578+ );2579+ return;2580+ }2581+ const paths = files2582+ .map((file) => resolvePath(file))2583+ .filter((path): path is string => path !== null);2584+ const text = formatDroppedFilePaths(paths);2585+ if (text.length === 0) {2586+ setThreadError(activeThreadId, "Could not read the location of the dropped file(s).");2587+ return;2588+ }@@ -2686,4 +2718,20 @@26862718 composerEditorRef.current?.focusAt(cursor);26872719 },26882720 addDroppedFiles: (files: File[]) => {2689- void addComposerImages(files);2721+ // Images become attachments; everything else (audio, PDF, video, …) is2722+ // handed over as a path so the agent opens it from disk itself.2723+ const images = files.filter((file) => file.type.startsWith("image/"));2724+ const nonImages = files.filter((file) => !file.type.startsWith("image/"));2725+ if (images.length > 0) {2726+ void addComposerImages(images);2727+ }2728+ if (nonImages.length > 0) {2729+ // Deliberately no focusComposer() on this path. `applyPromptReplacement`2730+ // focuses on the next frame, once Lexical has reconciled; focusing2731+ // synchronously here makes the not-yet-reconciled editor sync its stale2732+ // empty state back over the text we just inserted, so the drop looks2733+ // like it silently did nothing. Same footgun the file-tree mention drop2734+ // documents in makeComposerMentionDragHandlers.2735+ insertDroppedFilePaths(nonImages);2736+ return;2737+ }@@ -2686,4 +2718,20 @@26862718 composerEditorRef.current?.focusAt(cursor);26872719 },26882720 addDroppedFiles: (files: File[]) => {2689- void addComposerImages(files);2721+ // Images become attachments; everything else (audio, PDF, video, …) is2722+ // handed over as a path so the agent opens it from disk itself.2723+ const images = files.filter((file) => file.type.startsWith("image/"));2724+ const nonImages = files.filter((file) => !file.type.startsWith("image/"));2725+ if (images.length > 0) {2726+ void addComposerImages(images);2727+ }2728+ if (nonImages.length > 0) {2729+ // Deliberately no focusComposer() on this path. `applyPromptReplacement`2730+ // focuses on the next frame, once Lexical has reconciled; focusing2731+ // synchronously here makes the not-yet-reconciled editor sync its stale2732+ // empty state back over the text we just inserted, so the drop looks2733+ // like it silently did nothing. Same footgun the file-tree mention drop2734+ // documents in makeComposerMentionDragHandlers.2735+ insertDroppedFilePaths(nonImages);2736+ return;2737+ }
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/chat/ChatComposer.tsx line 2603Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2565,0 +2579,21 @@2579+ const resolvePath = window.desktopBridge?.getPathForFile;2580+ if (!resolvePath) {2581+ reportFailure(2582+ "Attaching files by path needs the desktop app. Paste an image, or type the path.",2583+ );2584+ return false;2585+ }2586+ const paths = files2587+ .map((file) => resolvePath(file))2588+ .filter((path): path is string => path !== null);2589+ const text = formatDroppedFilePaths(paths);2590+ if (text.length === 0) {2591+ reportFailure("Could not read the location of the dropped file(s).");2592+ return false;2593+ }2594+ if (!insertComposerTextAtEnd(text, { ensureLeadingBoundary: true })) {2595+ // This refusal comes from the same composer state that already rejected2596+ // the images, so one drop never says it twice.2597+ if (!hadImages) {2598+ reportFailure("The composer is busy; try again once it is ready.");2599+ }
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.




Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
49c1b54e-39f0-4495-9e99-0cb8fbcadfe4You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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