Repository navigation
fix(native-chat): stop linkifying slash commands and routes as files - #26586
AmoabaKelvin wants to merge 2 commits into
Conversation
Chat underlined anything starting with `/`, so `/code-review` and `/api/v1` opened a "file not found" toast.
📝 WalkthroughWalkthroughFile-link recognition now uses a shared set of extensionless filenames and a hostname detector. Candidate parsing applies unified recognition to prose-joined, exact, and spaced candidates. Rejected spaced quoted text remains plain text. Tests cover accepted file paths and excluded text, including commands, app routes, URLs, and version-like strings. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to Some scheme-less URLs may appear as local-file links in native chat, so clicking them can lead to the wrong destination. This is a localized rendering issue; overall merge risk is low. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description is detailed and covers the change, rationale, visual proof, testing, compatibility, and checklist. However, the required Linked Issue section states that no issue was opened, and the template requires an actual issue link. The description also does not report a successful build or CI coverage for the build.
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
c47789dc-915f-4072-9980-184c1a7fc9a2
📒 Files selected for processing (6)
src/renderer/src/components/native-chat/use-native-chat-file-link-click.test.tsxsrc/renderer/src/components/sidebar/CommentMarkdown.link-click.test.tsxsrc/renderer/src/components/sidebar/comment-markdown-native-chat-file-links.tssrc/renderer/src/lib/extensionless-filenames.tssrc/renderer/src/lib/hostname-shaped-segment.tssrc/renderer/src/lib/terminal-bare-file-link-detection.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fe54fb70-1e33-4da8-9039-a8735de05c8e
📒 Files selected for processing (2)
src/renderer/src/components/sidebar/comment-markdown-native-chat-file-links.tssrc/renderer/src/lib/hostname-segment.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
| const [firstSegment = ''] = link.pathText.split(/[\\/]/, 1) | ||
| // Why: unrooted, a space reads as a command (`git log origin/main`) and a leading host as a | ||
| // URL missing its scheme. Rooted keeps both: `C:\Program Files\...` is a real path. | ||
| if (!isRooted && (/\s/.test(link.pathText) || looksLikeHostname(firstSegment))) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect candidate extraction, routing, and relevant tests.
rg -n -C 5 'routeNativeChatHref|extractTerminalFileLinks|example\.photography' src/renderer/src
rg -n -C 3 'looksLikeHostname|example\.photography|routeNativeChatHref' src/renderer/src --glob '*test*'Repository: stablyai/orca
Length of output: 41679
🏁 Script executed:
set -euo pipefail
printf '%s\n' '--- hostname and classifier ---'
rg -n -C 12 -F -- 'looksLikeHostname' src/renderer/src/components/sidebar src/renderer/src/lib shared
printf '%s\n' '--- classifier block ---'
sed -n '1,115p' src/renderer/src/components/sidebar/comment-markdown-native-chat-file-links.ts
printf '%s\n' '--- terminal extraction and parsing ---'
sed -n '1,340p' src/renderer/src/lib/terminal-links.ts
printf '%s\n' '--- native chat route implementation ---'
rg -n -C 20 -F -- 'export function routeNativeChatHref' shared src/renderer/src
printf '%s\n' '--- focused native-chat tests ---'
rg -n -C 8 -F -- 'photography' src/renderer/src shared || test "$?" -eq 1
rg -n -C 8 -F -- 'unsupported' src/renderer/src/components/sidebar src/renderer/src/lib shared || test "$?" -eq 1Repository: stablyai/orca
Length of output: 7642
🏁 Script executed:
set -euo pipefail
printf '%s\n' '--- hostname helper ---'
nl -ba src/renderer/src/lib/hostname-segment.ts | sed -n '1,55p'
printf '%s\n' '--- terminal extractor declarations ---'
rg -n -C 8 -F -- 'function assembleFileLinks' src/renderer/src/lib/terminal-links.ts
rg -n -C 8 -F -- 'function parse' src/renderer/src/lib/terminal-links.ts
nl -ba src/renderer/src/lib/terminal-links.ts | sed -n '180,330p'
printf '%s\n' '--- route parser ---'
rg -n -C 24 -F -- 'export function routeNativeChatHref' src/shared src/renderer/src
printf '%s\n' '--- route module ---'
nl -ba src/shared/native-chat-href-routing.ts | sed -n '1,240p'
printf '%s\n' '--- focused tests ---'
rg -n -C 10 -F -- 'photography' src/renderer/src src/shared || test "$?" -eq 1Repository: stablyai/orca
Length of output: 2537
🏁 Script executed:
set -u
printf '%s\n' '--- terminal links source ---'
nl -ba src/renderer/src/lib/terminal-links.ts | sed -n '1,305p'
printf '%s\n' '--- route symbol locations ---'
rg -n -C 20 -F -- 'routeNativeChatHref' src/shared src/renderer/src || test "$?" -eq 1
printf '%s\n' '--- route module files ---'
find src -maxdepth 3 -type f -iname '*native*chat*href*' -printRepository: stablyai/orca
Length of output: 41931
🏁 Script executed:
set -euo pipefail
printf '%s\n' '--- basename classifier ---'
rg -n -C 18 -F -- 'function namesFileBasename' src/renderer/src/components/sidebar/comment-markdown-native-chat-file-links.ts
printf '%s\n' '--- route implementation ---'
nl -ba src/shared/native-chat-href-routing.ts | sed -n '1,145p'
printf '%s\n' '--- relevant tests ---'
nl -ba src/renderer/src/components/sidebar/CommentMarkdown.link-click.test.tsx | sed -n '348,376p'Repository: stablyai/orca
Length of output: 7301
Keep unsupported-TLD scheme-less URLs as plain text.
example.photography/docs/guide.html is extracted as a path. photography is not in the hostname allowlist, so it passes the guard. guide.html then passes the file-name check, and routeNativeChatHref classifies the candidate as a file. Reject scheme-less URL-shaped candidates before the file-name and route checks, while preserving valid dotted directories such as conf.d/nginx.conf. Add a regression test for this URL.
|
Thanks Kelvin, this found real cases. #26675 (now merged) changed chat to underline a path only once the workspace confirms the file exists, using the terminal's own check, so most of the shape rules here aren't needed anymore: |
…26819) Command-, route-, version- and host-shaped text stays plain unless the host confirms the path, in chat and terminal alike, since #26675. Co-authored-by: Kelvin Amoaba <[email protected]>
ELI5
Chat treats anything that starts with a slash as a file on your computer. So when a message says "run
/code-review" or "strip the/api/v1prefix", chat underlines it like a file and clicking it says the file was not found. Same for things likeHTTP/1.1andgit log origin/main..HEAD.This teaches chat the difference between a real path and text that only looks like one.
What Changed
Before and after, as the message renders in chat. "Linked" means underlined and clickable; every one of these opened a "file not found" toast.
Type /orca-native-chat:orca-chat-visuals/orca-native-chat(half the name)Run /code-review/code-reviewStrip the `/api/v1` prefix/api/v1Use /clear and /compact when needed/clear and /compact when neededTry HTTP/1.1 insteadHTTP/1.1We use z-ai/glm-5.3z-ai/glm-5.3Run `git log origin/main..HEAD`See example.com/docs/guide.htmlThe log is in /tmp/tmpPaths that already worked still work:
/etc/hosts,/usr/local/bin,/tmp/report.html,/data/out.json,/mnt/c/Users/me/notes.md,src/foo.ts,docs/review.docx,~/Downloads/report.pdf,./scripts/release,C:\Reports\final.pages,/Users/me/project/src/main.ts:12, and spaced paths anchored at a root such as~/Library/Application Support/orca/log.json.Two things now link that never did: extensionless project files (
docs/Makefile,.github/CODEOWNERS) and absolute paths under roots we do not recognise but whose basename names a file (/data/out.json).The mechanism. One function,
isLinkifiableFile, decides whether a token in chat prose deserves an underline. Its rule was "starts with/means absolute path", which is also the shape of every slash command and every app route. It now asks for evidence instead:/Users/,/tmp/,/etc/,/workspace/…), a:linesuffix, or a basename that names a file. A lone root segment (/code-review) is never a file.HTTP/1.1andglm-5.3are prose whilels.1,libfoo.so.1anddocs/archive.7zstay files.C:\Program Files\App\config.inistill links;git log origin/main..HEADdoes not.file://URI skips all of it, because the author said outright that it is a file.Two small modules came out of this:
extensionless-filenames.ts(which the terminal's bare-word detector already had a private copy of, now shared) andhostname-shaped-segment.ts.Why
Chat linkification is purely syntactic — unlike terminal links, which confirm the path exists before underlining it. That is why the terminal never had this bug and chat did. Making chat check the filesystem would mean async work inside a synchronous render and a round trip per candidate on SSH hosts, so the fix stays syntactic and just demands better evidence.
Fixing it at
isLinkifiableFilerather than in the shared path detector keeps the blast radius in chat: the detector is shared with terminal links, where the current behaviour is correct.Two cases stay deliberately unfixed because they cannot be told apart by syntax: a scheme-less URL on a TLD outside the allowlist, and an extensionless path under an unrecognised root (
/data/raw). Both fail to a plain-text render rather than a broken link.Linked Issue
Internal report, no issue opened.
Visual Proof
Before:

After:

Testing
Reviewer steps: open a chat, paste
Run /code-review on src/foo.ts, strip the /api/v1 prefix, try HTTP/1.1, then open /tmp/report.html.Onlysrc/foo.tsand/tmp/report.htmlshould underline.pnpm test src/renderer/src/components/sidebar src/renderer/src/components/native-chat src/renderer/src/lib— 1341 files, 13051 tests passingpnpm lintandpnpm tcclean on a fresh rebase ontomainFour new tests, each confirmed failing on the pre-change source. Three existing tests changed deliberately: spaced paths that are not anchored at a root (
My Folder/notes.md,"Brennan's Folder/notes.md") no longer link, because they are indistinguishable from a shell command with a path argument.Platforms: logic is platform-independent and covered by tests for POSIX, Windows drive and WSL (
/mnt/c/...) shapes. Exercised manually on macOS only.I manually tested these changes locally
Automated tests added/updated, or explained why not below
Review
Agent skill upstream boundary
Notes
SSH and remote: the root allowlist includes the Linux, container and WSL roots a remote workspace uses, and nothing here reaches the execution host. Mobile: unaffected, it does not use this linkifier. Backwards compatibility: render-only, no wire or persisted format touched. Performance: the added work is a set lookup and two regex tests per candidate, on a path that already ran several.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)