Skip to content

fix(native-chat): stop linkifying slash commands and routes as files - #26586

Closed
AmoabaKelvin wants to merge 2 commits into
stablyai:mainfrom
AmoabaKelvin:tighten-chat-path-linkification
Closed

AmoabaKelvin wants to merge 2 commits into
stablyai:mainfrom
AmoabaKelvin:tighten-chat-path-linkification

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 8, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​72 $\color{#cf222e}{\Huge{\mathbf{−}}}$​35 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​37
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​174 $\color{#cf222e}{\Huge{\mathbf{−}}}$​33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​141

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/v1 prefix", chat underlines it like a file and clicking it says the file was not found. Same for things like HTTP/1.1 and git 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.

In a chat message Before After
Type /orca-native-chat:orca-chat-visuals linked /orca-native-chat (half the name) plain text
Run /code-review linked /code-review plain text
Strip the `/api/v1` prefix linked /api/v1 plain text
Use /clear and /compact when needed linked /clear and /compact when needed plain text
Try HTTP/1.1 instead linked HTTP/1.1 plain text
We use z-ai/glm-5.3 linked z-ai/glm-5.3 plain text
Run `git log origin/main..HEAD` linked the whole command plain text
See example.com/docs/guide.html linked it as a relative path plain text
The log is in /tmp linked /tmp plain text

Paths 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:

  • An absolute candidate needs a known filesystem root (/Users/, /tmp/, /etc/, /workspace/…), a :line suffix, or a basename that names a file. A lone root segment (/code-review) is never a file.
  • A suffix of digits either side of a dot is a version, not an extension, so HTTP/1.1 and glm-5.3 are prose while ls.1, libfoo.so.1 and docs/archive.7z stay files.
  • A candidate with a space in it must be anchored at a root. C:\Program Files\App\config.ini still links; git log origin/main..HEAD does not.
  • A candidate whose first segment is a hostname is a URL someone dropped the scheme from.
  • A 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) and hostname-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 isLinkifiableFile rather 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:
CleanShot 2026-10-08 at 2 28 30 PM@2x

After:
CleanShot 2026-10-08 at 2 29 35 PM@2x

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. Only src/foo.ts and /tmp/report.html should underline.

  • pnpm test src/renderer/src/components/sidebar src/renderer/src/components/native-chat src/renderer/src/lib — 1341 files, 13051 tests passing

  • pnpm lint and pnpm tc clean on a fresh rebase onto main

  • Four 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Chat underlined anything starting with `/`, so `/code-review` and `/api/v1`
opened a "file not found" toast.
@AmoabaKelvin
AmoabaKelvin marked this pull request as ready for review October 8, 2026 13:57
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough

Walkthrough

File-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 b65b2

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)

Check name Status Explanation Resolution
Description check ⚠️ Warning 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 t… Link an actual issue in the Linked Issue section, for example by replacing “Internal report, no issue opened” with “Fixes #”. Also report pnpm build results or state that CI will cover the build.
Docstring Coverage ⚠️ Warning Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing native chat from linkifying slash commands and routes as files.
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 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.

  • Fix all pre-merge checks with AI
  • Autopilot · 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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c47789dc-915f-4072-9980-184c1a7fc9a2
📥 Commits

Reviewing files that changed from the base of the PR and between 89ba968 and adb493f.

📒 Files selected for processing (6)
  • src/renderer/src/components/native-chat/use-native-chat-file-link-click.test.tsx
  • src/renderer/src/components/sidebar/CommentMarkdown.link-click.test.tsx
  • src/renderer/src/components/sidebar/comment-markdown-native-chat-file-links.ts
  • src/renderer/src/lib/extensionless-filenames.ts
  • src/renderer/src/lib/hostname-shaped-segment.ts
  • src/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.

@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
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fe54fb70-1e33-4da8-9039-a8735de05c8e
📥 Commits

Reviewing files that changed from the base of the PR and between adb493f and b65b258.

📒 Files selected for processing (2)
  • src/renderer/src/components/sidebar/comment-markdown-native-chat-file-links.ts
  • src/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))) {

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:

#!/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 1

Repository: 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 1

Repository: 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*' -print

Repository: 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.

@brennanb2025

Copy link
Copy Markdown
Contributor

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: /code-review, /api/v1, HTTP/1.1 and example.com/docs stay plain because no such file exists. Your cases are carried over as regression tests in #26819 (with you as co-author), along with a table of which rules were kept and why. The extensionless-filename list is left for the follow-up that adds bare file names, since each extra name costs an existence check on every terminal hover, including over SSH. Closing this in favour of those two.

brennanb2025 added a commit that referenced this pull request Oct 11, 2026
…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]>
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.

2 participants