feat(tui,app): insert absolute path when dragging unsupported file#34306
feat(tui,app): insert absolute path when dragging unsupported file#34306Su-Qingmu wants to merge 1 commit into
Conversation
Three small, complementary fixes that share a theme: when the user pastes or drops something the native pipeline can't handle natively, give them (or the agent) a path they can act on, instead of a silent failure. ## Web — packages/app/src/components/prompt-input/attachments.ts Dragging a file with an unsupported MIME/extension (e.g. .docx, .pptx) into the web prompt input used to reject it with a warn toast and silently drop the file reference. The agent had no way to know the file even existed. When running under Electron, input.getPathForFile(file) exposes the absolute path. Use it to insert a file part whose content starts with '@' so the agent can read the file on demand via its existing tools. Pure-browser deployments (where getPathForFile is undefined) fall back to the original warn-toast behavior. ## TUI — packages/tui/src/component/prompt/index.tsx ### Drag-and-drop (pasteInputText) When the user pastes a filepath that readLocalAttachment returns undefined for (i.e. not SVG, image, or PDF), the existing flow falls through to a [Pasted ~N lines] summary for long content. A typical Windows path like 'C:\Users\me\Documents\project-notes.docx' can be long enough to trigger that summary, hiding the actual path. Add an early-exit branch: if attachment === undefined but existsSync(filepath) is true, insertText(filepath) and bail out, bypassing the paste-summary fold. The agent still sees the path, just not wrapped in a placeholder. ### Ctrl+V (prompt.paste handler) When clipboard.read() returned undefined (e.g. Get-Clipboard / clipboardy failing silently on Windows hosts), all the ?.-checks short-circuited and the function returned silently. Users had no way to tell whether the keystroke was received, the clipboard was empty, or the OS-side reader was broken. Replace the implicit fallthrough with an explicit error toast. The subsequent branches drop the now-redundant ?. since content is proven non-null. ## Compatibility - Web: guarded by if (absolutePath); browser-only behavior unchanged. - TUI drag-drop: only activates when pastedContent parses as a non-URL local path AND existsSync returns true. URL paste and plain-text paste flows are untouched. - TUI Ctrl+V: additive; only adds user feedback on the failure path. Happy-path text/image paste unchanged. Refs: anomalyco#13800, anomalyco#12595, anomalyco#18104, anomalyco#26283, anomalyco#32851, anomalyco#18771 (Windows paste cluster), anomalyco#31470 (CJK mojibake through ConPTY — orthogonal, not addressed here). Tested: portable Windows desktop build (Win11, Windows Terminal + cmd.exe). - Dragging a .docx into web prompt → inserts '@C:\path\file.docx' as a file part. - Pasting a long Windows path into TUI → inserts the path verbatim, no [Pasted ~N lines] summary. - Ctrl+V with empty/broken clipboard → red toast explaining the failure. - Happy-path image drag, text paste, and URL paste unchanged.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Hey! Your PR title Please update it to start with one of:
Where See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: I found one potentially related PR that should be reviewed for overlap: #34234 —
The search also returned:
These are all related to the attachment and paste functionality being modified, but #34234 appears to be the most directly relevant for potential duplication. |
Three small, complementary fixes that share a theme: when the user pastes or drops something the native pipeline can't handle natively, give them (or the agent) a path they can act on, instead of a silent failure.
Web — packages/app/src/components/prompt-input/attachments.ts
Dragging a file with an unsupported MIME/extension (e.g. .docx, .pptx) into the web prompt input used to reject it with a warn toast and silently drop the file reference. The agent had no way to know the file even existed.
When running under Electron, input.getPathForFile(file) exposes the absolute path. Use it to insert a file part whose content starts with '@' so the agent can read the file on demand via its existing tools. Pure-browser deployments (where getPathForFile is undefined) fall back to the original warn-toast behavior.
TUI — packages/tui/src/component/prompt/index.tsx
Drag-and-drop (pasteInputText)
When the user pastes a filepath that readLocalAttachment returns undefined for (i.e. not SVG, image, or PDF), the existing flow falls through to a [Pasted ~N lines] summary for long content. A typical Windows path like 'C:\Users\me\Documents\project-notes.docx' can be long enough to trigger that summary, hiding the actual path.
Add an early-exit branch: if attachment === undefined but existsSync(filepath) is true, insertText(filepath) and bail out, bypassing the paste-summary fold. The agent still sees the path, just not wrapped in a placeholder.
Ctrl+V (prompt.paste handler)
When clipboard.read() returned undefined (e.g. Get-Clipboard / clipboardy failing silently on Windows hosts), all the ?.-checks short-circuited and the function returned silently. Users had no way to tell whether the keystroke was received, the clipboard was empty, or the OS-side reader was broken.
Replace the implicit fallthrough with an explicit error toast. The subsequent branches drop the now-redundant ?. since content is proven non-null.
Compatibility
Refs: #13800, #12595, #18104, #26283, #32851, #18771 (Windows paste cluster), #31470 (CJK mojibake through ConPTY — orthogonal, not addressed here).
Tested: portable Windows desktop build (Win11, Windows Terminal + cmd.exe).
Issue for this PR
Closes #
Type of change
What does this PR do?
Please provide a description of the issue, the changes you made to fix it, and why they work. It is expected that you understand why your changes work and if you do not understand why at least say as much so a maintainer knows how much to value the PR.
If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!
How did you verify your code works?
Screenshots / recordings
If this is a UI change, please include a screenshot or recording.
Checklist
If you do not follow this template your PR will be automatically rejected.