-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: add file attachment support to chat interface #5570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
MuriloFP
wants to merge
19
commits into
RooCodeInc:main
from
MuriloFP:feat/issue-5532-file-attachments
Closed
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
efaaed9
feat: add Issue Fixer Orchestrator mode
MuriloFP 57d3fbe
Merge branch 'RooCodeInc:main' into main
MuriloFP ef61905
Merge branch 'RooCodeInc:main' into main
MuriloFP f5a51c4
Merge branch 'RooCodeInc:main' into main
MuriloFP bcbf329
Merge branch 'RooCodeInc:main' into main
MuriloFP 80413c0
Merge branch 'RooCodeInc:main' into main
MuriloFP ab10140
Merge branch 'RooCodeInc:main' into main
MuriloFP 39c5cf7
Merge branch 'RooCodeInc:main' into main
MuriloFP 00a0b63
Merge branch 'RooCodeInc:main' into main
MuriloFP 080b61b
Merge branch 'RooCodeInc:main' into main
MuriloFP 7a5ad14
Merge branch 'RooCodeInc:main' into main
MuriloFP 2c73ff2
Merge branch 'RooCodeInc:main' into main
MuriloFP 05ccf57
Merge branch 'RooCodeInc:main' into main
MuriloFP 7797a90
feat: Replace image-only attachment with general file attachment supp…
MuriloFP 0c9522f
corrected the file filter for all supported files
MuriloFP b547330
feat: change file attachment to use binary exclusion list instead of …
MuriloFP 90cc2e0
fix: resolve CI failures - remove unused file, add missing translatio…
MuriloFP 43b5a23
fix(file-attachments): address critical review feedback
MuriloFP 8f35f19
fix(ui): implement UI/UX improvements for file attachments
MuriloFP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest" | ||
| import * as vscode from "vscode" | ||
| import fs from "fs/promises" | ||
| import * as path from "path" | ||
| import { selectFiles, selectImages } from "../process-files" | ||
|
|
||
| // Mock vscode | ||
| vi.mock("vscode", () => ({ | ||
| window: { | ||
| showOpenDialog: vi.fn(), | ||
| showWarningMessage: vi.fn(), | ||
| }, | ||
| Uri: { | ||
| file: (path: string) => ({ fsPath: path }), | ||
| }, | ||
| })) | ||
|
|
||
| // Mock fs | ||
| vi.mock("fs/promises", () => ({ | ||
| default: { | ||
| readFile: vi.fn(), | ||
| stat: vi.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| describe("process-files", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| }) | ||
|
|
||
| describe("selectFiles", () => { | ||
| it("should return empty arrays when no files are selected", async () => { | ||
| vi.mocked(vscode.window.showOpenDialog).mockResolvedValue(undefined) | ||
|
|
||
| const result = await selectFiles() | ||
|
|
||
| expect(result).toEqual({ images: [], files: [] }) | ||
| }) | ||
|
|
||
| it("should process image files correctly", async () => { | ||
| const mockUri = { fsPath: "/test/image.png" } | ||
| vi.mocked(vscode.window.showOpenDialog).mockResolvedValue([mockUri] as any) | ||
| vi.mocked(fs.stat).mockResolvedValue({ size: 1000 } as any) | ||
| vi.mocked(fs.readFile).mockResolvedValue(Buffer.from("fake-image-data")) | ||
|
|
||
| const result = await selectFiles() | ||
|
|
||
| expect(result.images).toHaveLength(1) | ||
| expect(result.images[0]).toMatch(/^data:image\/png;base64,/) | ||
| expect(result.files).toHaveLength(0) | ||
| }) | ||
|
|
||
| it("should process text files correctly", async () => { | ||
| const mockUri = { fsPath: "/test/data.json" } | ||
| vi.mocked(vscode.window.showOpenDialog).mockResolvedValue([mockUri] as any) | ||
| vi.mocked(fs.stat).mockResolvedValue({ size: 1000 } as any) | ||
| vi.mocked(fs.readFile).mockResolvedValue('{"test": "data"}') | ||
|
|
||
| const result = await selectFiles() | ||
|
|
||
| expect(result.files).toHaveLength(1) | ||
| expect(result.files[0]).toEqual({ | ||
| path: "data.json", | ||
| content: '{"test": "data"}', | ||
| type: "json", | ||
| }) | ||
| expect(result.images).toHaveLength(0) | ||
| }) | ||
|
|
||
| it("should handle multiple files of different types", async () => { | ||
| const mockUris = [ | ||
| { fsPath: "/test/image.jpg" }, | ||
| { fsPath: "/test/config.xml" }, | ||
| { fsPath: "/test/readme.md" }, | ||
| ] | ||
| vi.mocked(vscode.window.showOpenDialog).mockResolvedValue(mockUris as any) | ||
| vi.mocked(fs.stat).mockResolvedValue({ size: 1000 } as any) | ||
| vi.mocked(fs.readFile) | ||
| .mockResolvedValueOnce(Buffer.from("fake-image")) | ||
| .mockResolvedValueOnce("<config>test</config>") | ||
| .mockResolvedValueOnce("# README") | ||
|
|
||
| const result = await selectFiles() | ||
|
|
||
| expect(result.images).toHaveLength(1) | ||
| expect(result.files).toHaveLength(2) | ||
| expect(result.files[0].type).toBe("xml") | ||
| expect(result.files[1].type).toBe("md") | ||
| }) | ||
|
|
||
| it("should reject files that are too large", async () => { | ||
| const mockUri = { fsPath: "/test/large.txt" } | ||
| vi.mocked(vscode.window.showOpenDialog).mockResolvedValue([mockUri] as any) | ||
| vi.mocked(fs.stat).mockResolvedValue({ size: 25 * 1024 * 1024 } as any) // 25MB | ||
|
|
||
| const result = await selectFiles() | ||
|
|
||
| expect(vscode.window.showWarningMessage).toHaveBeenCalledWith("File too large: large.txt (max 20MB)") | ||
| expect(result).toEqual({ images: [], files: [] }) | ||
| }) | ||
|
|
||
| it("should handle binary files gracefully", async () => { | ||
| const mockUri = { fsPath: "/test/binary.exe" } | ||
| vi.mocked(vscode.window.showOpenDialog).mockResolvedValue([mockUri] as any) | ||
| vi.mocked(fs.stat).mockResolvedValue({ size: 1000 } as any) | ||
| vi.mocked(fs.readFile).mockRejectedValue(new Error("Invalid UTF-8")) | ||
|
|
||
| const result = await selectFiles() | ||
|
|
||
| expect(vscode.window.showWarningMessage).toHaveBeenCalledWith("Cannot attach binary file: binary.exe") | ||
| expect(result).toEqual({ images: [], files: [] }) | ||
| }) | ||
| }) | ||
|
|
||
| describe("selectImages", () => { | ||
| it("should only return images from selectFiles", async () => { | ||
| const mockUris = [{ fsPath: "/test/image.png" }, { fsPath: "/test/data.json" }] | ||
| vi.mocked(vscode.window.showOpenDialog).mockResolvedValue(mockUris as any) | ||
| vi.mocked(fs.stat).mockResolvedValue({ size: 1000 } as any) | ||
| vi.mocked(fs.readFile) | ||
| .mockResolvedValueOnce(Buffer.from("fake-image")) | ||
| .mockResolvedValueOnce('{"test": "data"}') | ||
|
|
||
| const result = await selectImages() | ||
|
|
||
| expect(result).toHaveLength(1) | ||
| expect(result[0]).toMatch(/^data:image\/png;base64,/) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| import * as vscode from "vscode" | ||
| import fs from "fs/promises" | ||
| import * as path from "path" | ||
|
|
||
| const IMAGE_EXTENSIONS = ["png", "jpg", "jpeg", "webp", "gif", "bmp", "svg", "ico"] | ||
| const MAX_FILE_SIZE = 20 * 1024 * 1024 // 20MB | ||
|
|
||
| // Known binary file extensions to skip upfront | ||
| const BINARY_EXTENSIONS = [ | ||
| // Executables & Libraries | ||
| "exe", | ||
| "dll", | ||
| "so", | ||
| "dylib", | ||
| "app", | ||
| "deb", | ||
| "rpm", | ||
| "dmg", | ||
| "pkg", | ||
| "msi", | ||
| // Archives | ||
| "zip", | ||
| "tar", | ||
| "gz", | ||
| "bz2", | ||
| "7z", | ||
| "rar", | ||
| "jar", | ||
| "war", | ||
| "ear", | ||
| // Media | ||
| "mp3", | ||
| "mp4", | ||
| "avi", | ||
| "mov", | ||
| "wmv", | ||
| "flv", | ||
| "mkv", | ||
| "webm", | ||
| "ogg", | ||
| "wav", | ||
| "flac", | ||
| // Documents (binary formats) | ||
| "pdf", | ||
| "doc", | ||
| "docx", | ||
| "xls", | ||
| "xlsx", | ||
| "ppt", | ||
| "pptx", | ||
| "odt", | ||
| "ods", | ||
| "odp", | ||
| // Databases | ||
| "db", | ||
| "sqlite", | ||
| "mdb", | ||
| // Other binary formats | ||
| "pyc", | ||
| "pyo", | ||
| "class", | ||
| "o", | ||
| "a", | ||
| "lib", | ||
| "node", | ||
| "wasm", | ||
| ] | ||
|
|
||
| export async function selectFiles(): Promise<{ | ||
| images: string[] | ||
| files: Array<{ path: string; content: string; type: string }> | ||
| }> { | ||
| const options: vscode.OpenDialogOptions = { | ||
| canSelectMany: true, | ||
| openLabel: "Select", | ||
| filters: { | ||
| "All Files": ["*"], | ||
| Images: IMAGE_EXTENSIONS, | ||
| }, | ||
| } | ||
|
|
||
| const fileUris = await vscode.window.showOpenDialog(options) | ||
|
|
||
| if (!fileUris || fileUris.length === 0) { | ||
| return { images: [], files: [] } | ||
| } | ||
|
|
||
| const images: string[] = [] | ||
| const files: Array<{ path: string; content: string; type: string }> = [] | ||
|
|
||
| await Promise.all( | ||
| fileUris.map(async (uri) => { | ||
| const filePath = uri.fsPath | ||
| const ext = path.extname(filePath).toLowerCase().substring(1) | ||
| const fileName = path.basename(filePath) | ||
|
|
||
| // Check file size | ||
| const stats = await fs.stat(filePath) | ||
| if (stats.size > MAX_FILE_SIZE) { | ||
| vscode.window.showWarningMessage(`File too large: ${fileName} (max 20MB)`) | ||
| return | ||
| } | ||
|
|
||
| if (IMAGE_EXTENSIONS.includes(ext)) { | ||
| // Process as image | ||
| const buffer = await fs.readFile(filePath) | ||
| const base64 = buffer.toString("base64") | ||
| const mimeType = getMimeType(filePath) | ||
| const dataUrl = `data:${mimeType};base64,${base64}` | ||
| images.push(dataUrl) | ||
| } else if (BINARY_EXTENSIONS.includes(ext)) { | ||
| // Skip known binary files | ||
| vscode.window.showWarningMessage(`Cannot attach binary file: ${fileName}`) | ||
| } else { | ||
| // Try to read as text file | ||
| try { | ||
| const content = await fs.readFile(filePath, "utf-8") | ||
| // Additional check: if the content has null bytes, it's likely binary | ||
| if (content.includes("\0")) { | ||
| vscode.window.showWarningMessage(`File appears to be binary: ${fileName}`) | ||
| } else { | ||
| files.push({ | ||
| path: fileName, | ||
| content: content, | ||
| type: ext || "txt", // Default to 'txt' if no extension | ||
| }) | ||
| } | ||
| } catch (error) { | ||
| // File couldn't be read as UTF-8, likely binary | ||
| vscode.window.showWarningMessage(`Cannot read file as text: ${fileName}`) | ||
| } | ||
| } | ||
| }), | ||
| ) | ||
|
|
||
| return { images, files } | ||
| } | ||
|
|
||
| // Keep the original selectImages function for backward compatibility | ||
| export async function selectImages(): Promise<string[]> { | ||
| const result = await selectFiles() | ||
| return result.images | ||
| } | ||
|
|
||
| function getMimeType(filePath: string): string { | ||
| const ext = path.extname(filePath).toLowerCase() | ||
| switch (ext) { | ||
| case ".png": | ||
| return "image/png" | ||
| case ".jpeg": | ||
| case ".jpg": | ||
| return "image/jpeg" | ||
| case ".webp": | ||
| return "image/webp" | ||
| default: | ||
| throw new Error(`Unsupported image type: ${ext}`) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IMAGE_EXTENSIONS array (line 5) includes extensions like gif, bmp, svg and ico, but the getMimeType function (lines 145–157) only supports PNG, JPEG, JPG and WEBP. Consider adding cases for the additional image types to prevent runtime errors when a supported extension is selected.