-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Problem (one or two sentences)
When opening a chat message in VS Code's Markdown Preview via the "Open in preview" button, all relative file links (e.g., helper) are broken because they resolve against /tmp instead of the workspace directory.
Context (who is affected and when)
Affects all users who click the "Open in preview" (expand) button on AI responses that contain relative file path links. The links appear correct in the webview chat but break when opened in VS Code's native Markdown Preview.
Reproduction steps
- OS: macOS (also affects Linux). Extension version: latest.
- Start a conversation that produces a response with relative file links, e.g., ask the AI to explain a file, and it responds with markdown like helper.
- Click the "Open in preview" button (SquareArrowOutUpRight icon) on the AI's response message.
- In the opened Markdown Preview, hover over or click any relative file link.
- Observe that the link resolves to /tmp/src/utils/helper.ts:42 instead of /src/utils/helper.ts:42.
Expected result
Relative file links in the Markdown Preview should resolve against the workspace root, making them clickable and functional.
Actual result
All relative file links are prefixed with /tmp (the OS temp directory) because the temp markdown file is written to os.tmpdir() in webviewMessageHandler.ts (openMarkdownPreview case, line ~3451).
Variations tried (optional)
Root cause identified in src/core/webview/webviewMessageHandler.ts, the "openMarkdownPreview" case:
const tmpDir = os.tmpdir() // <-- This is the problem
const tempFilePath = path.join(tmpDir, tempFileName)
VS Code's Markdown Preview resolves relative links relative to the document's directory. Since the file is in /tmp, all relative links resolve against /tmp.
Suggested fix: Write the temp file to the workspace directory (using getCurrentCwd() already available in the handler) instead of os.tmpdir(). Use a dot-prefixed filename (.roo-preview-.md) to minimize workspace pollution.
App Version
Latest (bug exists since PR #10773)
API Provider (optional)
None
Model Used (optional)
No response
Roo Code Task Links (optional)
No response
Relevant logs or errors (optional)
No errors in logs — the file is written and preview opens successfully.
The issue is that VS Code's markdown preview resolves relative paths
relative to the temp file location (/tmp/) instead of the workspace.
Affected code: src/core/webview/webviewMessageHandler.ts lines 3448-3466
Introduced by: PR #10773 (feat: add button to open markdown in VSCode preview)