@devries-cameron20 / t3code-1 / commits / ea9fbc1a07
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(desktop): open cursor:// and vscode:// file links from chat (#23486)

fixfon committed Nov 9, 2026 at 00:23 UTC ea9fbc1a076e1544ba397731c2d2365d90f5c365
9 files changed +227 -2
apps/desktop/src/electron/ElectronShell.test.ts
+61
@@ -54,6 +54,67 @@ describe("ElectronShell", () => {
54 }).pipe(Effect.provide(ElectronShell.layer)),
55 );
56
57 + it.effect("opens local editor file deep links", () =>
58 + Effect.gen(function* () {
59 + openExternalMock.mockResolvedValue(undefined);
60 +
61 + const urls = [
62 + "cursor://file/Users/me/repo/file.md:186",
63 + "vscode://file/Users/me/repo/file.md:3:7",
64 + "vscode-insiders://file/Users/me/repo/file.md",
65 + "vscodium://file/C:/Users/me/repo/file.md:3",
66 + ];
67 + const electronShell = yield* ElectronShell.ElectronShell;
68 + const results = yield* Effect.forEach(urls, (url) => electronShell.openExternal(url));
69 +
70 + assert.deepEqual(results, [true, true, true, true]);
71 + assert.deepEqual(
72 + openExternalMock.mock.calls,
73 + urls.map((url) => [url]),
74 + );
75 + }).pipe(Effect.provide(ElectronShell.layer)),
76 + );
77 +
78 + it.effect("normalizes the scheme case of local editor file deep links", () =>
79 + Effect.gen(function* () {
80 + openExternalMock.mockResolvedValue(undefined);
81 +
82 + const electronShell = yield* ElectronShell.ElectronShell;
83 + const result = yield* electronShell.openExternal("VSCode://file/Users/me/repo/file.md:3");
84 +
85 + assert.equal(result, true);
86 + assert.deepEqual(openExternalMock.mock.calls, [["vscode://file/Users/me/repo/file.md:3"]]);
87 + }).pipe(Effect.provide(ElectronShell.layer)),
88 + );
89 +
90 + it.effect("does not open editor URLs that are not absolute local file links", () =>
91 + Effect.gen(function* () {
92 + openExternalMock.mockResolvedValue(undefined);
93 +
94 + const electronShell = yield* ElectronShell.ElectronShell;
95 + const results = yield* Effect.forEach(
96 + [
97 + "cursor://user@file/Users/me/repo/file.md",
98 + "cursor://:secret@file/Users/me/repo/file.md",
99 + "cursor://file:8080/Users/me/repo/file.md",
100 + "cursor://anysphere.cursor-deeplink/prompt?text=hi",
101 + "vscode://vscode.git/clone?url=https%3A%2F%2Fexample.com%2Frepo.git",
102 + "cursor://file",
103 + "cursor://file/",
104 + "cursor:file/Users/me/repo/file.md",
105 + "foo://file/Users/me/repo/file.md",
106 + "zed://file/Users/me/repo/file.md",
107 + "jetbrains://file/Users/me/repo/file.md",
108 + "javascript:alert(1)",
109 + ],
110 + (url) => electronShell.openExternal(url),
111 + );
112 +
113 + assert.deepEqual(results, Array(12).fill(false));
114 + assert.equal(openExternalMock.mock.calls.length, 0);
115 + }).pipe(Effect.provide(ElectronShell.layer)),
116 + );
117 +
118 it.effect("does not open editor URLs that mix up link shapes", () =>
119 Effect.gen(function* () {
120 openExternalMock.mockResolvedValue(undefined);
apps/desktop/src/electron/ElectronShell.ts
+5 -2
@@ -1,5 +1,6 @@
1 import { MAC_PERMISSION_SETTINGS_URLS } from "../permissions/MacPermission.ts";
2 import {
3 + isLocalEditorFileUrl,
4 REMOTE_CAPABLE_EDITOR_IDS,
5 remoteSchemeForEditor,
6 type SystemSettingsPane,
@@ -11,7 +12,7 @@ import * as Option from "effect/Option";
12
13 import * as Electron from "electron";
14
14 -// Remote editor deep links must reach the OS handler.
15 +// Remote editor deep links and local editor file links must reach the OS handler.
16 const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
17 const REMOTE_EDITOR_PROTOCOLS = new Set(
18 REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
@@ -44,7 +45,9 @@ export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
45
46 try {
47 const url = new URL(rawUrl);
47 - return SAFE_WEB_PROTOCOLS.has(url.protocol) || isRemoteEditorUrl(url)
48 + return SAFE_WEB_PROTOCOLS.has(url.protocol) ||
49 + isRemoteEditorUrl(url) ||
50 + isLocalEditorFileUrl(url)
51 ? Option.some(url.href)
52 : Option.none();
53 } catch {
apps/web/src/components/ChatMarkdown.browser.test.tsx
+25
@@ -433,6 +433,31 @@ describe("ChatMarkdown inline code selection", () => {
433 });
434 });
435
436 +describe("ChatMarkdown editor deep links", () => {
437 + const hrefs = (container: HTMLElement) =>
438 + [...container.querySelectorAll("a")].map((link) => link.getAttribute("href"));
439 +
440 + it("keeps local editor file links", async () => {
441 + setup();
442 + await using screen = await renderText(
443 + "[file.md line 3](cursor://file/Users/me/repo/file.md:3) and [same](vscode://file/Users/me/repo/file.md:3:7)",
444 + );
445 + expect(hrefs(screen.container)).toEqual([
446 + "cursor://file/Users/me/repo/file.md:3",
447 + "vscode://file/Users/me/repo/file.md:3:7",
448 + ]);
449 + });
450 +
451 + it("still drops other editor links and unknown schemes", async () => {
452 + setup();
453 + await using screen = await renderText(
454 + "[prompt](cursor://anysphere.cursor-deeplink/prompt?text=hi) [user](cursor://me@file/Users/me/file.md) [unknown](foo://file/Users/me/file.md)",
455 + );
456 + expect(screen.container.innerHTML).not.toContain("://");
457 + expect(hrefs(screen.container).filter(Boolean)).toEqual([]);
458 + });
459 +});
460 +
461 describe("ChatMarkdown Windows file links", () => {
462 const environmentId = EnvironmentId.make("env-windows");
463 const renderWindows = (text: string, parseRawHtml: boolean) =>
apps/web/src/components/ChatMarkdown.tsx
+2
@@ -136,6 +136,7 @@ import { useRenderedAppearance } from "../hooks/useTheme";
136 import { useClientSettings } from "../hooks/useSettings";
137 import { chatMarkdownClipboardPayload } from "../markdown-clipboard";
138 import {
139 + isLocalEditorFileHref,
140 resolveInlineCodeFileLinkMeta,
141 resolveMarkdownFileLinkMeta,
142 rewriteMarkdownFileUriHref,
@@ -399,6 +400,7 @@ function markdownUrlTransform(href: string) {
400 if (parseComposerContextHref(href)) return href;
401 if (parseThreadLinkHref(href)) return href;
402 if (isWindowsDrivePathHref(href)) return href;
403 + if (isLocalEditorFileHref(href)) return href;
404 return rewriteMarkdownFileUriHref(href) ?? defaultUrlTransform(href);
405 }
406
apps/web/src/markdown-links.test.ts
+32
@@ -1,6 +1,7 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 import {
4 + isLocalEditorFileHref,
5 resolveInlineCodeFileLinkMeta,
6 resolveMarkdownFileLinkMeta,
7 rewriteMarkdownFileUriHref,
@@ -11,6 +12,37 @@ import {
12 resolveMarkdownFileHostPath,
13 } from "./markdownFileHostPath";
14
15 +describe("isLocalEditorFileHref", () => {
16 + it("accepts absolute file deep links of known editors", () => {
17 + for (const href of [
18 + "cursor://file/Users/me/repo/file.md:186",
19 + "vscode://file/Users/me/repo/file.md:3:7",
20 + "vscode-insiders://file/Users/me/repo/file.md",
21 + "VSCODE://file/C:/Users/me/repo/file.md:3",
22 + ]) {
23 + expect(isLocalEditorFileHref(href), href).toBe(true);
24 + }
25 + });
26 +
27 + it("rejects other hosts, userinfo, relative paths, and unknown schemes", () => {
28 + for (const href of [
29 + "cursor://anysphere.cursor-deeplink/prompt?text=hi",
30 + "vscode://user@file/Users/me/repo/file.md",
31 + "vscode://file:8080/Users/me/repo/file.md",
32 + "vscode://vscode-remote/ssh-remote+example.com/home/user/project",
33 + "cursor://file",
34 + "cursor:file/Users/me/repo/file.md",
35 + "foo://file/Users/me/repo/file.md",
36 + "zed://file/Users/me/repo/file.md",
37 + "javascript:alert(1)",
38 + "./file.md",
39 + "",
40 + ]) {
41 + expect(isLocalEditorFileHref(href), href).toBe(false);
42 + }
43 + });
44 +});
45 +
46 describe("rewriteMarkdownFileUriHref", () => {
47 it("preserves encoded octets so file paths are decoded only once later", () => {
48 expect(rewriteMarkdownFileUriHref("file:///Users/julius/project/file%2520name.md")).toBe(
apps/web/src/markdown-links.ts
+9
@@ -1,3 +1,4 @@
1 +import { isLocalEditorFileUrl } from "@t3tools/contracts";
2 import { fileBasename, isAbsolutePath, workspaceRelativeFilePath } from "@t3tools/shared/path";
3 import {
4 inlineCodeFilePathCandidate,
@@ -39,6 +40,14 @@ export function rewriteMarkdownFileUriHref(href: string | undefined): string | n
40 return target ? `${target.path}${target.hash}` : null;
41 }
42
43 +export function isLocalEditorFileHref(href: string): boolean {
44 + try {
45 + return isLocalEditorFileUrl(new URL(href));
46 + } catch {
47 + return false;
48 + }
49 +}
50 +
51 export function resolveInlineCodeFileLinkMeta(
52 codeText: string,
53 cwd?: string,
packages/contracts/src/editor.ts
+13
@@ -174,6 +174,19 @@ export const remoteSchemeForEditor = (id: EditorId): string | undefined => {
174 return editor === undefined ? undefined : remoteSchemeOf(editor);
175 };
176
177 +// `goto` editors share VS Code's `file:line:col` addressing, so their remote schemes also open
178 +// a local file as `<scheme>://file/<absolute path>[:line[:col]]`. Zed and JetBrains differ.
179 +export const LOCAL_FILE_LINK_SCHEMES: ReadonlyArray<string> = EDITORS.flatMap((editor) =>
180 + editor.launchStyle === "goto" && "remoteScheme" in editor ? [editor.remoteScheme] : [],
181 +);
182 +
183 +export const isLocalEditorFileUrl = (url: URL): boolean =>
184 + LOCAL_FILE_LINK_SCHEMES.includes(url.protocol.slice(0, -1)) &&
185 + url.host === "file" &&
186 + url.username.length === 0 &&
187 + url.password.length === 0 &&
188 + url.pathname.length > 1;
189 +
190 export const buildRemoteOpenUrl = (input: {
191 readonly editor: EditorId;
192 readonly host: string;
packages/shared/src/markdownPipeline.test.ts
+56
@@ -204,6 +204,62 @@ it("builds the tree rehype-raw builds for markdown without HTML", () => {
204 }
205 });
206
207 +it("keeps local editor file links but not other schemes through the shared Markdown sanitizer", () => {
208 + const processor = unified()
209 + .use(remarkParse)
210 + .use(CHAT_MARKDOWN_REMARK_PLUGINS)
211 + .use(remarkRehype, { allowDangerousHtml: true })
212 + .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
213 + const tree = processor.runSync(
214 + processor.parse(
215 + [
216 + "[cursor](cursor://file/Users/me/repo/file.md:3)",
217 + "[code](vscode://file/Users/me/repo/file.md:3:7)",
218 + "[insiders](vscode-insiders://file/Users/me/repo/file.md)",
219 + "[unknown](foo://file/Users/me/repo/file.md)",
220 + "[zed](zed://file/Users/me/repo/file.md)",
221 + ].join(" "),
222 + ),
223 + );
224 + type Node = { tagName?: string; properties?: { href?: string }; children?: Node[] };
225 + const hrefs = ((tree.children[0] as Node).children ?? [])
226 + .filter((node) => node.tagName === "a")
227 + .map((node) => node.properties?.href);
228 + expect(hrefs).toEqual([
229 + "cursor://file/Users/me/repo/file.md:3",
230 + "vscode://file/Users/me/repo/file.md:3:7",
231 + "vscode-insiders://file/Users/me/repo/file.md",
232 + undefined,
233 + undefined,
234 + ]);
235 +});
236 +
237 +it("keeps mixed-case local editor file links by lowercasing the scheme before sanitizing", () => {
238 + const processor = unified()
239 + .use(remarkParse)
240 + .use(CHAT_MARKDOWN_REMARK_PLUGINS)
241 + .use(remarkRehype, { allowDangerousHtml: true })
242 + .use(CHAT_MARKDOWN_REHYPE_PLUGINS);
243 + const tree = processor.runSync(
244 + processor.parse(
245 + [
246 + "[upper](VSCODE://file/Users/me/repo/file.md:3:7)",
247 + "[mixed](Cursor://file/Users/me/repo/file.md:3)",
248 + "[other](FOO://file/Users/me/repo/file.md)",
249 + ].join(" "),
250 + ),
251 + );
252 + type Node = { tagName?: string; properties?: { href?: string }; children?: Node[] };
253 + const hrefs = ((tree.children[0] as Node).children ?? [])
254 + .filter((node) => node.tagName === "a")
255 + .map((node) => node.properties?.href);
256 + expect(hrefs).toEqual([
257 + "vscode://file/Users/me/repo/file.md:3:7",
258 + "cursor://file/Users/me/repo/file.md:3",
259 + undefined,
260 + ]);
261 +});
262 +
263 it("keeps backslashes that CommonMark would read as escapes in prose Windows paths", () => {
264 const processor = unified()
265 .use(remarkParse)
packages/shared/src/markdownPipeline.ts
+24
@@ -1,3 +1,4 @@
1 +import { isLocalEditorFileUrl, LOCAL_FILE_LINK_SCHEMES } from "@t3tools/contracts";
2 import type { Paragraph, PhrasingContent, Root, RootContent } from "mdast";
3 import { remarkKeepWindowsPaths } from "./markdownWindowsPaths.ts";
4 import { type PluggableList, type Processor, type Transformer, unified } from "unified";
@@ -164,6 +165,26 @@ function rehypePreserveImageSourceMeta() {
165
166 const IMAGE_SRC_PROTOCOLS = [...(defaultSchema.protocols?.src ?? []), "file", "t3-context"];
167
168 +// The sanitizer compares schemes case-sensitively, so lowercase accepted editor links first.
169 +function rehypeNormalizeLocalEditorLinks() {
170 + return (tree: MarkdownImageHastNode) => {
171 + const visit = (node: MarkdownImageHastNode) => {
172 + const href = node.properties?.href;
173 + if (node.type === "element" && node.tagName === "a" && typeof href === "string") {
174 + try {
175 + const url = new URL(href);
176 + if (isLocalEditorFileUrl(url)) node.properties = { ...node.properties, href: url.href };
177 + } catch {
178 + // Not an absolute URL; the sanitizer decides.
179 + }
180 + }
181 + node.children?.forEach(visit);
182 + };
183 +
184 + visit(tree);
185 + };
186 +}
187 +
188 const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
189 ...defaultSchema,
190 attributes: {
@@ -195,6 +216,8 @@ const CHAT_MARKDOWN_SANITIZE_SCHEMA = {
216 "t3-citation",
217 "t3-context",
218 THREAD_LINK_PROTOCOL,
219 + // Scheme only: the renderer's URL transform checks the rest of the link shape.
220 + ...LOCAL_FILE_LINK_SCHEMES,
221 ],
222 src: IMAGE_SRC_PROTOCOLS,
223 dataDarkSrc: IMAGE_SRC_PROTOCOLS,
@@ -301,6 +324,7 @@ export const CHAT_MARKDOWN_REHYPE_PLUGINS: PluggableList = [
324 rehypePreserveBareAnchorPlaceholders,
325 rehypeRawWhenPresent,
326 rehypePreserveImageSourceMeta,
327 + rehypeNormalizeLocalEditorLinks,
328 [rehypeSanitize, CHAT_MARKDOWN_SANITIZE_SCHEMA],
329 ];
330