Skip to content

feat(tui): support drag-and-drop for .docx and .xlsx files#32104

Open
GP-commits wants to merge 3 commits into
anomalyco:devfrom
GP-commits:office-file-drop
Open

feat(tui): support drag-and-drop for .docx and .xlsx files#32104
GP-commits wants to merge 3 commits into
anomalyco:devfrom
GP-commits:office-file-drop

Conversation

@GP-commits

Copy link
Copy Markdown

Issue for this PR

Closes #27689

Type of change

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

What does this PR do?

The TUI had no way to attach .docx or .xlsx files — they were either rejected outright or fell through to the binary-file error in the read tool. This PR adds Office file support across three surfaces:

TUI drag-and-drop (packages/tui)
When a .docx or .xlsx is dropped into the prompt, a new office-converter.ts module converts it to Markdown text and inlines it into the prompt. For .docx, we use mammoth.convertToHtml() (the currently recommended API — convertToMarkdown is deprecated per the mammoth README) and then convert the HTML to GFM Markdown, preserving headings, tables, lists, bold/italic, and links. For .xlsx, we use SheetJS sheet_to_json({ header: 1 }) to render each sheet as a Markdown table.

Read tool (packages/opencode)
read.ts previously had .docx and .xlsx hardcoded in isBinaryFile() and would fail with "Cannot read binary file". Now, before that check, it detects Office extensions and runs the same converter, returning the Markdown inside <content> tags so the LLM can process it like any other file.

Desktop file picker (packages/app)
Added the two MIME types to ACCEPTED_FILE_TYPES and MIME_EXT so the Electron file picker dialog accepts .docx/.xlsx.

How did you verify your code works?

  • All 20 existing TUI prompt tests pass (bun test test/prompt/)
  • Added 3 new unit tests covering .docx conversion, .xlsx conversion (with Markdown table output), and graceful handling of empty/unreadable files
  • Ran a real .xlsx round-trip smoke test: built a workbook with SheetJS, converted it back, confirmed the Markdown table output including correct pipe-escaping in cells
  • bun typecheck passes clean in both packages/opencode and packages/tui

Screenshots / recordings

This is a TUI/backend change with no visual UI difference beyond the drag-and-drop accepting the new file types. The prompt behaviour after dropping a file is the same as pasting text — the file content appears inline with a [DOCX: filename] label.

Checklist

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]:Support drag-and-drop for Microsoft Office files (.docx, .xlsx)

1 participant