Skip to content

fix(terminal): resolve Markdown file destinations before bare paths - #32056

Merged
nwparker merged 2 commits into
mainfrom
nwparker/terminal-markdown-destinations
Oct 23, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/terminal-markdown-destinations

Conversation

@nwparker

@nwparker nwparker commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​133 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​133
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​176 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​169

ELI5

When an agent prints a Markdown link in the terminal, like [report](/tmp/folder%20with%20spaces/report.pdf), clicking it should open that file. Before this PR the terminal guessed wrong in two ways:

  • Label and target glued together. [/tmp/a/отчет.pdf](/tmp/a/отчет.pdf) became one path, /tmp/a/отчет.pdf](/tmp/a/отчет.pdf. That file doesn't exist, so nothing happened when you clicked.
  • %20 was not decoded. The terminal looked for a file literally named folder%20with%20spaces instead of folder with spaces.

Now the terminal reads the (...) part of a Markdown link first and links only that target. It decodes %20 the way the chat Markdown view already does. Plain paths outside Markdown links, including real filenames that contain %, work the same as before.

Related to #28598 (reported by @chilango74). This fixes the two extraction bugs from that issue that we reproduced. The original short-label failure on the reporter's Linux desktop is still unexplained, so this PR does not claim to fix it.

What changed

  • New terminal-markdown-file-links.ts: a bounded scanner for inline Markdown destinations. It handles <...> destinations, titles, balanced parens and escapes, and caps destinations at 2,048 characters. It reuses routeNativeChatHref (same href decoding as native chat) and the existing file:// / explicit-path parsers.
  • assembleFileLinks runs this pass first. It then blanks the label and syntax so the URI, path and bare-filename passes can't re-link them, and it keeps the original character offsets.
  • Review fix (f11542f): Markdown backslash unescaping is skipped for Windows-style destinations (drive, UNC, no /, or a backslash used as a separator). Without this, [cfg](C:\Users\me\.config\app.json) became C:\Users\me.config\app.json, which was a regression from main (flagged by CodeRabbit).

Verification

  • Ran main's terminal-links.ts and this branch side by side on the same inputs:
    • Cyrillic label+destination: main /tmp/p/Каталог/отчет.pdf](/tmp/p/Каталог/отчет.pdf -> PR /tmp/p/Каталог/отчет.pdf
    • %20 destination: main /tmp/p/folder%20with%20spaces/report.pdf -> PR /tmp/p/folder with spaces/report.pdf
    • [cfg](C:\Users\me\.config\app.json): before the review fix the PR returned C:\Users\me.config\app.json. Now it returns C:\Users\me\.config\app.json, same as main.
  • vitest --config config/vitest.config.ts on the terminal-links, terminal-link provider/handler, comment-markdown native-chat and href-routing suites: 32 files, 400 tests pass. The run includes real temp-file existence checks (both the encoded and decoded files exist, and the decoded one wins) and ReDoS guards for unclosed, nested and oversized Markdown.
  • Worst-case timing: a 260 KB line of [/tmp/a.pdf]( repeated took about 110 ms, and an 80 KB line of [a]( repeated took about 100 ms. Both are under the 500 ms ReDoS budget.
  • Earlier, a real hidden Electron app on macOS (temporary profile, folder workspace) printed raw Markdown through a shell PTY and clicked the links. The before/after screenshots below show the encoded-space click opening the literal-percent PDF on the old detector and the decoded PDF on the new one. Both files existed at the time.

(screenshot removed: contained real product data)

(screenshot removed: contained real product data)

Risks / tradeoffs

  • In a Markdown destination, %XX is now decoded. A file whose real name contains %20 can only be reached through a Markdown link if the link writes it as %2520. Bare paths keep the literal name.
  • Labels of Markdown links are no longer linked separately. For example, [README.md](https://…) no longer makes README.md clickable. That is intended, but it is a behavior change.
  • Windows/UNC destinations keep their backslashes literally, so a Markdown escape such as C:\a\(1\).txt is not unescaped. This is the same as bare-path behavior on main.
  • Not exercised on Windows/Linux desktops, mobile, or SSH remotes. The change is pure renderer string parsing with no IPC or schema changes, and host routing and existence checks are untouched.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

The terminal link code now detects file links in Markdown destinations and scans the remaining text for URIs, local paths, and bare filenames. The Markdown scanner supports escaped punctuation, balanced parentheses, angle-bracket destinations, and optional titles, with a 2048-character destination limit. Tests cover path decoding, Unicode paths, unsupported destinations, adjacent links, and oversized or malformed Markdown inputs.

Priority: ➖ Normal

Merge Risk: 🔵 Low · up to f1154

A narrow class of Markdown links to filenames with escaped punctuation may fail to open, but the impact is localized.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 5 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the primary change: resolving Markdown file destinations before bare path detection.
Description check Passed The description is detailed and on-topic. It covers the user impact, implementation, issue reference, visual proof, testing, risks, platform limitations, and compatibility considerations. It does not …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description is detailed and on-topic. It covers the user impact, implementation, issue reference, visual proof, testing, risks, platform limitations, and compatibility considerations. It does not reproduce every template heading or checklist item, but the required information is mostly present.

✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0502f668-1b78-482d-ae92-8a436ea910b5
📥 Commits

Reviewing files that changed from the base of the PR and between 6af2163 and 19e6d88.

📒 Files selected for processing: 5
  • src/renderer/src/components/terminal-pane/terminal-link-provider-markdown.test.ts
  • src/renderer/src/lib/terminal-links-redos.test.ts
  • src/renderer/src/lib/terminal-links.ts
  • src/renderer/src/lib/terminal-markdown-file-links.test.ts
  • src/renderer/src/lib/terminal-markdown-file-links.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Markdown unescaping turned C:\Users\me\.config\app.json into
C:\Users\me.config\app.json, a regression versus bare-path detection.

Co-Authored-By: Claude <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 832020ed-3261-4df4-86a1-87cbca0ed2a4
📥 Commits

Reviewing files that changed from the base of the PR and between 19e6d88 and f11542f.

📒 Files selected for processing: 2
  • src/renderer/src/lib/terminal-markdown-file-links.test.ts
  • src/renderer/src/lib/terminal-markdown-file-links.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

function unescapeMarkdownDestination(destination: string): string {
if (
isWindowsAbsolutePathLike(destination) ||
!destination.includes('/') ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '1,230p' src/renderer/src/lib/terminal-markdown-file-links.ts
printf '\n--- tests ---\n'
sed -n '1,180p' src/renderer/src/lib/terminal-markdown-file-links.test.ts
printf '\n--- integration ---\n'
rg -n 'detectTerminalMarkdownFileLinks|remainingText|extractTerminalFileLinks|extractTerminalFileLinkCandidates' src/renderer/src/lib/terminal-links.ts src/renderer/src/components/terminal-pane/terminal-link-provider-markdown.test.ts

Repository: stablyai/orca

Length of output: 10041


🏁 Script executed:

set -e
printf '%s\n' '--- bound symbols ---'
rg -n -F --glob '*.ts' -e 'export function routeNativeChatHref' -e 'function routeNativeChatHref' -e 'export function parseExplicitFileLinkTarget' -e 'function parseExplicitFileLinkTarget' src shared
printf '%s\n' '--- router references ---'
rg -n -F --glob '*.ts' -e 'routeNativeChatHref(' -e 'parseExplicitFileLinkTarget(' src/renderer/src shared
printf '%s\n' '--- implementations ---'
router=$(rg -l -F --glob '*.ts' 'export function routeNativeChatHref' src shared | head -n 1)
target=$(rg -l -F --glob '*.ts' 'export function parseExplicitFileLinkTarget' src shared | head -n 1)
printf 'router=%s\n' "$router"
sed -n '1,260p' "$router"
printf 'target=%s\n' "$target"
sed -n '1,300p' "$target"
printf '%s\n' '--- relevant tests ---'
rg -n -F --glob '*.{ts,tsx}' -e 'README\\(final\\).md' -e 'non-escape' -e 'backslash' -e 'allowRelativeDirectoryPath' -e 'routeNativeChatHref' -e 'parseExplicitFileLinkTarget' src/renderer/src shared

Repository: stablyai/orca

Length of output: 456


🏁 Script executed:

set -e
printf '%s\n' '--- native-chat-href-routing.ts ---'
sed -n '1,240p' src/shared/native-chat-href-routing.ts
printf '%s\n' '--- explicit-file-link-target.ts ---'
sed -n '1,240p' src/renderer/src/lib/explicit-file-link-target.ts
printf '%s\n' '--- focused backslash/path references ---'
rg -n -F --glob '*.{ts,tsx}' -e 'README\\(final\\).md' -e 'allowRelativeDirectoryPath' -e 'routeNativeChatHref' -e 'parseExplicitFileLinkTarget' src/renderer/src src/shared || test "$?" -eq 1

Repository: stablyai/orca

Length of output: 14991


🏁 Script executed:

set -e
printf '%s\n' '--- file-link-location ---'
rg -n -F --glob '*.ts' -e 'export function parseFileLinkLocation' -e 'function parseFileLinkLocation' src/shared
file_link=$(rg -l -F --glob '*.ts' 'export function parseFileLinkLocation' src/shared | head -n 1)
printf 'file_link=%s\n' "$file_link"
sed -n '1,260p' "$file_link"
printf '%s\n' '--- path normalization ---'
sed -n '1,280p' src/renderer/src/lib/terminal-path-normalization.ts

Repository: stablyai/orca

Length of output: 5140


Unescape relative Markdown filenames without directory separators.

When [doc](README\(final\).md) points to README(final).md, the no-/ guard keeps both backslashes. The resolver retains them and treats them as path separators during normalization, so it can target README/(final).md instead of README(final).md. The Markdown span is then masked in remainingText, so later detectors cannot recover the intended filename.

Keep the existing non-escape-backslash guard, but remove the broader no-/ guard:

🐛 Suggested fix
--- "a/src/renderer/src/lib/terminal-markdown-file-links.ts"
+++ "b/src/renderer/src/lib/terminal-markdown-file-links.ts"
@@ -78,11 +78,10 @@
 
 // Why: Windows destinations use backslash as a separator, so `C:\me\.config` is not an escape.
 function unescapeMarkdownDestination(destination: string): string {
   if (
     isWindowsAbsolutePathLike(destination) ||
-    !destination.includes('/') ||
     NON_ESCAPE_BACKSLASH.test(destination)
   ) {
     return destination
   }
   return destination.replace(MARKDOWN_ESCAPE, '$1')
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
!destination.includes('/') ||

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