Skip to content

Open Windows file links in rendered Markdown - #4665

Merged
SawyerHood merged 2 commits into
mainfrom
bb/windows-file-links-thr_jensq3v9th
Oct 2, 2026
Merged

SawyerHood merged 2 commits into
mainfrom
bb/windows-file-links-thr_jensq3v9th

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

File links that an agent prints with a Windows path did not work in rendered Markdown:

  • [readme](C:\src\repo\README.md) and [readme](C:/src/repo/README.md:12) rendered as plain text. The link parser tested the href against a URI-scheme pattern first, so C: was read as a scheme, the href was not recognised as a local file, and the default URL transform dropped it.
  • Markdown treats a backslash before punctuation as an escape, so a destination such as C:\src\repo\.config\app.json lost its \. before the parser saw it.
  • file:///C:/src/repo/README.md parsed to the POSIX-looking path /C:/src/repo/README.md and rendered as an external link.

Part of #1206. Stacked on #4659, which adds the Windows-aware path helpers this uses for containment.

What changed

  • apps/app/src/components/ui/markdown-local-file-link.ts: a drive-letter path (C:\… or C:/…) is a local file path, not a URL. file: and editor URLs whose pathname is /C:/… yield C:/…. Validation rejects drive roots and directory paths the same way it rejects / and trailing-slash POSIX paths. buildLocalFileAnchorHref renders a Windows link as file:///C:/… with each segment percent-encoded.
  • markdown-local-file-link-normalize.ts: before Markdown parsing, an inline link destination that is a Windows drive path is rewritten to forward slashes inside angle brackets, so no backslash is consumed as an escape and spaces survive. While finding where such a destination ends, a backslash is read as a path separator, not an escape, so [draft](C:\docs\(draft).md) keeps its parentheses and becomes <C:/docs/(draft).md>.

POSIX link handling is unchanged; the existing tests pass unmodified.

How you verified

  • Windows 11 Enterprise VM (build 26300), installed desktop build containing this change and the other open Windows changes, driven through its web UI: a message containing [readme](C:\src\testrepo\README.md), [fwd](C:/src/testrepo/README.md:1), and [uri](file:///C:/src/testrepo/README.md) rendered three anchors with hrefs file:///C:/src/testrepo/README.md, …README.md#L1, and …README.md. Clicking fwd opened the file preview panel titled C:\src\testrepo\README.md showing the file's contents. Before the change the first two were plain text and the third was an external link.
  • Linux: turbo run lint typecheck test --filter=@bb/app passes (6 of 6 tasks). New tests cover drive paths with line suffixes, file:///C:/… URLs, rejected roots and directories, case-insensitive containment in a Windows workspace root, the rendered anchor href, relative links under a Windows root, and the normalization of backslash and space-containing destinations and of a file name in parentheses after a separator. The two link test files also pass on the VM (41 of 41).

Not verified: bare Windows paths that are not Markdown links are still plain text (the same is true of bare POSIX paths); editor-scheme URLs (vscode://file/C:/…) are covered only by the shared parsing path, not by a click on Windows.

🤖 Generated with Claude Code

AGENT GENERATED

@SawyerHood
SawyerHood added this pull request to stack #4666 October 2, 2026 00:17
@SawyerHood
SawyerHood marked this pull request as ready for review October 2, 2026 01:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-02T01:44:19.616669Z 05df29d Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 05df29d53e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +404 to +405
if (isWindowsDriveLocalFilePath(payload.destination)) {
const windowsDestination = payload.destination.replaceAll("\\", "/");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve opening parentheses after Windows separators

Handle a backslash before ( as a Windows path separator while locating the destination end. For a valid path such as [draft](C:\docs\(draft).md), findInlineLinkDestinationEnd treats \( as a Markdown escape, skips the opening parenthesis, and mistakes the filename's ) for the link terminator. Consequently this branch receives a truncated destination and the link remains broken or, when the truncated prefix contains a dot, is rewritten to the wrong file.

Useful? React with 👍 / 👎.

@SawyerHood
SawyerHood force-pushed the bb/windows-file-links-thr_jensq3v9th branch from 05df29d to 656b43f Compare October 2, 2026 02:49
Base automatically changed from bb/windows-host-paths-thr_jensq3v9th to main October 2, 2026 03:22
SawyerHood and others added 2 commits October 1, 2026 20:22
A link to `C:\src\repo\file.ts` rendered as plain text: the drive letter was
read as a URL scheme and dropped, and Markdown ate backslashes that precede
punctuation. `file:///C:/…` links rendered as external links.

- Treat a drive-letter path as a local file path, not a URL, and accept
  `file:///C:/…` and editor URLs that carry one.
- Rewrite Windows link destinations to forward slashes before Markdown
  parses them.
- Render the anchor as a `file:///C:/…` URL.

Co-Authored-By: Claude Code <[email protected]>
The destination scanner treated every backslash as a Markdown escape, so
'C:\docs\(draft).md' lost its opening parenthesis and ended at the
filename's closing one. A destination that starts with a drive path now
reads backslashes as separators.

Co-Authored-By: Claude Code <[email protected]>
@SawyerHood
SawyerHood force-pushed the bb/windows-file-links-thr_jensq3v9th branch from 656b43f to 8c29f9b Compare October 2, 2026 03:22
@SawyerHood
SawyerHood merged commit 2ac0747 into main Oct 2, 2026
22 checks passed
@SawyerHood
SawyerHood deleted the bb/windows-file-links-thr_jensq3v9th branch October 2, 2026 03:27
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.

1 participant