Repository navigation
fix(terminal): resolve Markdown file destinations before bare paths - #32056
Conversation
📝 Walkthrough
Priority: ➖ Normal Merge Risk: 🔵 Low · up to
|
There was a problem hiding this comment.
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
📒 Files selected for processing: 5
src/renderer/src/components/terminal-pane/terminal-link-provider-markdown.test.tssrc/renderer/src/lib/terminal-links-redos.test.tssrc/renderer/src/lib/terminal-links.tssrc/renderer/src/lib/terminal-markdown-file-links.test.tssrc/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>
There was a problem hiding this comment.
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
📒 Files selected for processing: 2
src/renderer/src/lib/terminal-markdown-file-links.test.tssrc/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('/') || |
There was a problem hiding this comment.
🎯 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.tsRepository: 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 sharedRepository: 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 1Repository: 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.tsRepository: 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.
| !destination.includes('/') || |
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:[/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.%20was not decoded. The terminal looked for a file literally namedfolder%20with%20spacesinstead offolder with spaces.Now the terminal reads the
(...)part of a Markdown link first and links only that target. It decodes%20the 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
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 reusesrouteNativeChatHref(same href decoding as native chat) and the existingfile:/// explicit-path parsers.assembleFileLinksruns 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./, or a backslash used as a separator). Without this,[cfg](C:\Users\me\.config\app.json)becameC:\Users\me.config\app.json, which was a regression from main (flagged by CodeRabbit).Verification
terminal-links.tsand this branch side by side on the same inputs:/tmp/p/Каталог/отчет.pdf](/tmp/p/Каталог/отчет.pdf-> PR/tmp/p/Каталог/отчет.pdf%20destination: 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 returnedC:\Users\me.config\app.json. Now it returnsC:\Users\me\.config\app.json, same as main.vitest --config config/vitest.config.tson 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.[/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.(screenshot removed: contained real product data)
(screenshot removed: contained real product data)
Risks / tradeoffs
%XXis now decoded. A file whose real name contains%20can only be reached through a Markdown link if the link writes it as%2520. Bare paths keep the literal name.[README.md](https://…)no longer makesREADME.mdclickable. That is intended, but it is a behavior change.C:\a\(1\).txtis not unescaped. This is the same as bare-path behavior on main.