Repository navigation
feat(desktop): make file paths in chat messages clickable #9677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 9 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
8ba692c
feat(desktop): make file paths in chat messages clickable
bb0a32e
feat(desktop): linkify file paths in chat messages
e310220
fix(desktop): address review feedback for clickable file paths
8ed41e8
fix(desktop): support file paths with spaces in linkifier
692f479
fix(desktop): exclude trailing prose from spaced path segments
18923ab
fix(desktop): make path linkifier linear and skip nested traversal
dd6b368
fix(desktop): address Codex review and CI typecheck failure
fc5c4d0
fix(desktop): support Unicode paths and keyboard file links
435732b
fix(desktop): handle numeric path suffixes and link references
f7ccad0
fix(desktop): skip link subtrees and parenthesized filenames
d75a60f
fix(desktop): include commas in filename path segments
6a20648
fix(desktop): preserve closing parens in path suffixes
4fc7728
fix(desktop): reject partial paths and untrusted open-file links
6f5003b
fix(desktop): require longer spaced path segments
98cd9d6
fix(desktop): support word parentheticals and apostrophes in paths
28c1b4d
fix(desktop): support colons in timestamped filenames
89e4145
fix(desktop): support alphanumeric parenthetical filename suffixes
8ffb75e
fix(desktop): stop prose after parenthesized path suffixes
79526c8
fix(desktop): link paths wrapped in parentheses or brackets
0c1eec5
fix(desktop): allow brackets and question marks in path filenames
a84c9f5
fix(desktop): reject numeric counts after path segments
b940ba7
fix(desktop): reject capitalized prose after path segments
ca461aa
fix(desktop): include balanced bracket suffixes in path segments
2c56380
fix(desktop): include bracket suffixes in spaced path segments
4d8de80
fix(desktop): link long lowercase spaced filename segments
93fafd0
fix(desktop): strip line suffixes and link multiword filenames
ebf26e8
fix(desktop): refine line suffix stripping and tab terminators
194d051
fix(desktop): preserve bracket suffixes and reject prose parentheticals
c05a4b3
fix(desktop): broaden line suffix stripping and reject bracket tags
e3d6839
fix(desktop): reject short counts after capitalized path segments
c78b04f
fix(desktop): strip punctuation in extension lookahead words
3a727e5
fix(desktop): link top-level absolute directories
64c45b6
fix(desktop): link paths in questions and Windows drive dirs
7fbd240
fix(desktop): require drive separator for Windows paths
10a76ba
fix(desktop): accept assignment prefixes and newline terminators
65d41d2
fix(desktop): tighten capitalized and parenthetical continuations
8d5f57b
fix(desktop): reject prose before slashes and after short basenames
60e6e8e
fix(desktop): preserve spaced directory names before separators
f31ed2a
fix(desktop): ignore equals in URL query parameters
b3a3484
fix(desktop): preserve parenthesized filename suffixes with spaces
f71168a
fix(desktop): tighten spaced path continuation heuristics
d69f581
fix(ui): linkify inline parenthesized filename suffixes
2c7ac42
fix(desktop): allow dots and underscores in parenthesized filename su…
032955f
fix(ui): tighten path linkification for diagnostics and parentheticals
a321ea3
fix(ui): reject URL fragment/path params and strip lowercase diagnost…
bc1dd15
fix(ui): linkify paths with parenthesized directory segments
c9823ef
fix(ui): reject bracketed URL query keys and uppercase extension look…
ad9db5a
fix(ui): allow titlecase basename extension lookahead
d5619de
fix(ui): include hyphen in URL query param key scan
a53493d
fix(ui): allow apostrophe and Unicode in parenthesized filename suffixes
7aad701
fix(ui): resolve ESLint escape and support Unicode parenthesized paths
535be07
fix(ui): stop two-char basename paths from absorbing prose
cc8048e
fix(ui): reject URL path assignments and hyphenated spaced filenames
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,201 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import type { Root } from 'mdast'; | ||
| import { findPaths, OPEN_FILE_PROTOCOL, remarkLinkifyPaths } from './linkifyPaths'; | ||
|
|
||
| describe('path linkification', () => { | ||
| describe('Unix absolute paths', () => { | ||
| it('detects Unix absolute paths', () => { | ||
| const matches = findPaths('Created file at /home/user/project/src/main.rs'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/home/user/project/src/main.rs'); | ||
| }); | ||
|
|
||
| it('does not match single-segment paths', () => { | ||
| const matches = findPaths('Go to / for root'); | ||
| expect(matches).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('detects multiple paths in one line', () => { | ||
| const matches = findPaths('Compare /etc/hosts and /etc/resolv.conf'); | ||
| expect(matches).toHaveLength(2); | ||
| expect(matches[0][1]).toBe('/etc/hosts'); | ||
| expect(matches[1][1]).toBe('/etc/resolv.conf'); | ||
| }); | ||
|
|
||
| it('detects paths with spaces in segment names', () => { | ||
| const matches = findPaths('Saved /Users/me/My Project/result.txt for review'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/Users/me/My Project/result.txt'); | ||
| }); | ||
|
|
||
| it('detects lowercase folder names with spaces at end of path', () => { | ||
| const matches = findPaths('Output in /home/user/my documents'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/home/user/my documents'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Tilde paths', () => { | ||
| it('detects tilde paths', () => { | ||
| const matches = findPaths('Config at ~/.config/app/settings.json'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('~/.config/app/settings.json'); | ||
| }); | ||
|
|
||
| it('does not match bare tilde', () => { | ||
| const matches = findPaths('Go to ~ for home'); | ||
| expect(matches).toHaveLength(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Windows paths', () => { | ||
| it('detects Windows paths', () => { | ||
| const matches = findPaths('File at C:\\Users\\dev\\project\\index.ts'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('C:\\Users\\dev\\project\\index.ts'); | ||
| }); | ||
|
|
||
| it('detects Windows paths with spaces in segment names', () => { | ||
| const matches = findPaths('File at C:\\Users\\dev\\My Project\\index.ts'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('C:\\Users\\dev\\My Project\\index.ts'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Edge cases', () => { | ||
| it('detects paths after punctuation', () => { | ||
| const matches = findPaths('Saved to "/var/log/app.log"'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/var/log/app.log'); | ||
| }); | ||
|
|
||
| it('detects paths with dots and underscores', () => { | ||
| const matches = findPaths('Read /home/user/.env.local'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/home/user/.env.local'); | ||
| }); | ||
|
|
||
| it('strips trailing sentence punctuation', () => { | ||
| const matches = findPaths('Created /tmp/result.txt.'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/tmp/result.txt'); | ||
| }); | ||
|
|
||
| it('does not include trailing prose before sentence punctuation', () => { | ||
| const matches = findPaths('Created /tmp/result successfully.'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/tmp/result'); | ||
| }); | ||
|
|
||
| it('does not extend short single-char basenames with prose', () => { | ||
| const matches = findPaths('Created /tmp/a successfully.'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/tmp/a'); | ||
| }); | ||
|
|
||
| it('includes spaced folder names before sentence punctuation', () => { | ||
| const matches = findPaths('Saved to /home/user/my documents.'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/home/user/my documents'); | ||
| }); | ||
|
|
||
| it('does not match URLs', () => { | ||
| const matches = findPaths('Visit https://example.com/page for info'); | ||
| expect(matches).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('generates correct open-file URLs', () => { | ||
| const path = '/home/user/project/src/main.rs'; | ||
| expect(OPEN_FILE_PROTOCOL + encodeURI(path)).toBe( | ||
| 'open-file:///home/user/project/src/main.rs' | ||
| ); | ||
| }); | ||
|
|
||
| it('encodes spaces in open-file URLs', () => { | ||
| const path = '/Users/me/My Project/result.txt'; | ||
| expect(OPEN_FILE_PROTOCOL + encodeURI(path)).toBe( | ||
| 'open-file:///Users/me/My%20Project/result.txt' | ||
| ); | ||
| }); | ||
|
|
||
| it('handles paths with hyphens', () => { | ||
| const matches = findPaths('Check /usr/local/lib/my-app/config.yaml'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/usr/local/lib/my-app/config.yaml'); | ||
| }); | ||
|
|
||
| it('does not match content inside code blocks', () => { | ||
| const matches = findPaths('Use `Array<T>` for generics'); | ||
| expect(matches).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('matches paths inside inline code markers', () => { | ||
| const matches = findPaths('`/usr/local/bin/node`'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/usr/local/bin/node'); | ||
| }); | ||
|
|
||
| it('detects paths with numeric suffixes in segment names', () => { | ||
| const matches = findPaths('Saved /Users/me/Project 2026.'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/Users/me/Project 2026'); | ||
| }); | ||
|
|
||
| it('detects paths with Unicode segment names', () => { | ||
| const matches = findPaths('Saved /Users/me/デスクトップ/out.txt'); | ||
| expect(matches).toHaveLength(1); | ||
| expect(matches[0][1]).toBe('/Users/me/デスクトップ/out.txt'); | ||
| }); | ||
|
|
||
| it('does not linkify partial paths before unsupported characters', () => { | ||
| const matches = findPaths('See /Users/me/🎉/out.txt'); | ||
| expect(matches).toHaveLength(0); | ||
| }); | ||
|
|
||
| it('returns no matches for long prose without paths', () => { | ||
| const prose = 'word '.repeat(10_000); | ||
| const start = Date.now(); | ||
| const matches = findPaths(prose); | ||
| const elapsed = Date.now() - start; | ||
|
|
||
| expect(matches).toHaveLength(0); | ||
| expect(elapsed).toBeLessThan(500); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('remarkLinkifyPaths', () => { | ||
| it('does not linkify paths inside link references', () => { | ||
| const tree: Root = { | ||
| type: 'root', | ||
| children: [ | ||
| { | ||
| type: 'paragraph', | ||
| children: [ | ||
| { | ||
| type: 'linkReference', | ||
| identifier: 'log', | ||
| label: 'log', | ||
| referenceType: 'full', | ||
| children: [{ type: 'text', value: 'log /tmp/out' }], | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const transform = (remarkLinkifyPaths as unknown as () => (tree: Root) => void)(); | ||
| transform(tree); | ||
|
|
||
| const paragraph = tree.children[0]; | ||
| expect(paragraph.type).toBe('paragraph'); | ||
| if (paragraph.type !== 'paragraph') return; | ||
|
|
||
| const linkRef = paragraph.children[0]; | ||
| expect(linkRef.type).toBe('linkReference'); | ||
| if (linkRef.type !== 'linkReference') return; | ||
|
|
||
| expect(linkRef.children).toHaveLength(1); | ||
| expect(linkRef.children[0]).toEqual({ type: 'text', value: 'log /tmp/out' }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When markdown content already contains an
open-file://href, this treats it exactly like a generated path link, but authored link text can be arbitrary. For example,[release notes](open-file:///Users/me/Secrets)bypasses the existing external-link confirmation UI and opens the local file manager even though the visible label is not the path; only trust generated file links or verify the label matches the decoded path before using this direct-open path.Useful? React with 👍 / 👎.