Skip to content

feat(tui,app): insert absolute path when dragging unsupported file#34306

Closed
Su-Qingmu wants to merge 1 commit into
anomalyco:devfrom
Su-Qingmu:fix/paste-and-drop-combine
Closed

feat(tui,app): insert absolute path when dragging unsupported file#34306
Su-Qingmu wants to merge 1 commit into
anomalyco:devfrom
Su-Qingmu:fix/paste-and-drop-combine

Conversation

@Su-Qingmu

Copy link
Copy Markdown

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: #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).

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

Issue for this PR

Closes #

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

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.
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No issue referenced. Please add Closes #<number> linking to the relevant issue.
  • "How did you verify your code works?" section is empty. Please explain how you tested.
  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

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.

@github-actions

Copy link
Copy Markdown
Contributor

Hey! Your PR title feat(tui,app): insert absolute path when dragging unsupported file doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

I found one potentially related PR that should be reviewed for overlap:

#34234fix: preserve attachment file paths

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.

@Su-Qingmu Su-Qingmu closed this Jun 28, 2026
@Su-Qingmu Su-Qingmu deleted the fix/paste-and-drop-combine branch June 28, 2026 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs:compliance This means the issue will auto-close after 2 hours. needs:title

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant