@devries-cameron20 / t3code Mirror · read-only / commits / 7a1c8f47e4
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 23, 03:00 UTC

fix(web): recognize Windows terminal file links (#21199)

Utkarsh Patil committed Oct 19, 2026 at 01:32 UTC 7a1c8f47e4aff9d42d9448e6a1662f577cff9ea3
5 files changed +125 -8
apps/web/src/terminal-links.test.ts
+63
@@ -17,6 +17,62 @@ function createBufferLine(text: string, isWrapped = false): TerminalBufferLineLi
17 }
18
19 describe("extractTerminalLinks", () => {
20 + it.each([
21 + String.raw`src\index.ts:12`,
22 + String.raw`.\src\index.ts:12:7`,
23 + String.raw`..\src\index.ts:12`,
24 + String.raw`C:\Users\Jane\project\index.ts:12`,
25 + String.raw`\\server\share\index.ts:12`,
26 + ])("finds Windows path %s", (text) => {
27 + const line = `error at ${text}: failed`;
28 + expect(extractTerminalLinks(line)).toEqual([
29 + { kind: "path", text, start: 9, end: 9 + text.length },
30 + ]);
31 + });
32 +
33 + it.each(['"', "'", "`"])("finds paths containing spaces enclosed in %s", (quote) => {
34 + const text = String.raw`C:\Users\Jane Doe\project\index.ts:12:7`;
35 + expect(extractTerminalLinks(`see ${quote}${text}${quote}.`)).toEqual([
36 + { kind: "path", text, start: 5, end: 5 + text.length },
37 + ]);
38 + });
39 +
40 + it.each([
41 + String.raw`src\my folder\index.ts`,
42 + "./my folder/index.ts",
43 + "/home/Jane Doe/index.ts",
44 + "/home/Jane Doe/file)",
45 + String.raw`\\server\my share\index.ts`,
46 + ])("keeps positions outside quotes on %s", (path) => {
47 + expect(extractTerminalLinks(`"${path}":12:7: error`)).toEqual([
48 + { kind: "path", text: `${path}:12:7`, start: 1, end: path.length + 7 },
49 + ]);
50 + });
51 +
52 + it("does not treat quoted prose as a path", () => {
53 + expect(extractTerminalLinks('error: "something went wrong"')).toEqual([]);
54 + expect(extractTerminalLinks('error: "something went wrong."')).toEqual([]);
55 + });
56 +
57 + it.each([
58 + ['"my file.ts":12:7', "my file.ts:12:7", 17],
59 + ["'my file.ts:12:7'", "my file.ts:12:7", 16],
60 + ["`my file.ts`", "my file.ts", 11],
61 + ])("finds a quoted basename in %s", (line, text, end) => {
62 + expect(extractTerminalLinks(line)).toEqual([{ kind: "path", text, start: 1, end }]);
63 + });
64 +
65 + it("keeps quoted paths and URLs separate without duplicate partial paths", () => {
66 + const path = String.raw`C:\Jane Doe\index.ts:12`;
67 + const url = "https://example.com/docs";
68 + const line = `"${path}" ${url} src/index.ts`;
69 + expect(extractTerminalLinks(line)).toEqual([
70 + { kind: "path", text: path, start: 1, end: 1 + path.length },
71 + { kind: "url", text: url, start: path.length + 3, end: path.length + 3 + url.length },
72 + { kind: "path", text: "src/index.ts", start: line.length - 12, end: line.length },
73 + ]);
74 + });
75 +
76 it("finds http urls and path tokens", () => {
77 const line =
78 "failed at https://example.com/docs and src/components/ThreadTerminalDrawer.tsx:42";
@@ -171,6 +227,13 @@ describe("collectWrappedTerminalLinkLine", () => {
227 });
228
229 describe("resolvePathLinkTarget", () => {
230 + it("resolves a quoted terminal link against a Windows environment", () => {
231 + const [link] = extractTerminalLinks(String.raw`error at "src\my folder\index.ts":12:7`);
232 + expect(resolvePathLinkTarget(link?.text ?? "", String.raw`C:\Users\Jane Doe\project`)).toBe(
233 + String.raw`C:\Users\Jane Doe\project\src\my folder\index.ts:12:7`,
234 + );
235 + });
236 +
237 it("resolves relative paths against cwd", () => {
238 expect(
239 resolvePathLinkTarget(
apps/web/src/terminal-links.ts
+16 -7
@@ -28,7 +28,9 @@ export interface WrappedTerminalLinkLine {
28
29 const URL_PATTERN = /https?:\/\/[^\s"'`<>]+/giu;
30 const FILE_PATH_PATTERN =
31 - /(?:~\/|\.{1,2}\/|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|[A-Za-z0-9._-]+(?:\/[A-Za-z0-9._-]+)+(?::\d+){0,2}/g;
31 + /(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|[A-Za-z0-9._-]+(?:[\\/][A-Za-z0-9._-]+)+(?::\d+){0,2}/g;
32 +const QUOTED_FILE_PATH_PATTERN =
33 + /(["'`])(?<path>(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\|[A-Za-z0-9._ -]+[\\/])[^\r\n]*?|[A-Za-z0-9._ -]+\.[A-Za-z0-9_-]+(?::\d+){0,2})\1(?<position>(?::\d+){0,2})/g;
34 const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;
35 // Paths also drop a trailing colon: compilers end `file:line:col:` with one.
36 const TRAILING_PATH_PUNCTUATION_PATTERN = /[.,;:!?]+$/;
@@ -69,11 +71,13 @@ function collectMatches(
71 pattern.lastIndex = 0;
72
73 for (const rawMatch of line.matchAll(pattern)) {
72 - const raw = rawMatch[0];
73 - const start = rawMatch.index ?? -1;
74 + const quotedPath = rawMatch.groups?.path;
75 + const raw =
76 + quotedPath === undefined ? rawMatch[0] : quotedPath + (rawMatch.groups?.position ?? "");
77 + const start = rawMatch.index + (quotedPath === undefined ? 0 : 1);
78 if (start < 0 || raw.length === 0) continue;
79
76 - const trimmed = trimClosingDelimiters(raw, kind);
80 + const trimmed = quotedPath === undefined ? trimClosingDelimiters(raw, kind) : raw;
81 if (trimmed.length === 0) continue;
82 if (kind === "path" && isTerminalUrl(trimmed)) continue;
83
@@ -81,7 +85,8 @@ function collectMatches(
85 kind,
86 text: trimmed,
87 start,
84 - end: start + trimmed.length,
88 + // A position outside quotes spans the closing quote in the terminal buffer.
89 + end: start + trimmed.length + (rawMatch.groups?.position ? 1 : 0),
90 };
91
92 const collides = [...existing, ...matches].some((other) => overlaps(candidate, other));
@@ -95,8 +100,12 @@ function collectMatches(
100
101 export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
102 const urlMatches = collectMatches(line, "url", URL_PATTERN, []);
98 - const pathMatches = collectMatches(line, "path", FILE_PATH_PATTERN, urlMatches);
99 - return [...urlMatches, ...pathMatches].toSorted((a, b) => a.start - b.start);
103 + const quotedMatches = collectMatches(line, "path", QUOTED_FILE_PATH_PATTERN, urlMatches);
104 + const pathMatches = collectMatches(line, "path", FILE_PATH_PATTERN, [
105 + ...urlMatches,
106 + ...quotedMatches,
107 + ]);
108 + return [...urlMatches, ...quotedMatches, ...pathMatches].toSorted((a, b) => a.start - b.start);
109 }
110
111 export function isTerminalUrl(value: string): boolean {
apps/web/src/terminal/ghostty/surface.test.ts
+19
@@ -1004,6 +1004,25 @@ describe("shouldBlinkTerminalCursor", () => {
1004 });
1005
1006 describe("terminalLinkAtPositionWithRange", () => {
1007 + it("activates a wrapped quoted Windows path from its spaces and position suffix", () => {
1008 + const row = (text: string, isWrapContinuation: boolean): GhosttyRow => ({
1009 + cells: Array.from(text, (character) => cell(character)),
1010 + text,
1011 + isWrapContinuation,
1012 + wrapsToNext: false,
1013 + });
1014 + const first = String.raw`"C:\Users\Jane `;
1015 + const second = String.raw`Doe\index.ts":12:7`;
1016 + const rows = [row(first, false), row(second, true)];
1017 + const expected = {
1018 + text: String.raw`C:\Users\Jane Doe\index.ts:12:7`,
1019 + range: { start: { x: 1, y: 0 }, end: { x: second.length - 1, y: 1 } },
1020 + };
1021 + expect(terminalLinkAtPositionWithRange(rows, 0, first.length - 1)).toEqual(expected);
1022 + expect(terminalLinkAtPositionWithRange(rows, 1, second.length - 1)).toEqual(expected);
1023 + expect(terminalLinkAtPositionWithRange(rows, 0, 0)).toBeNull();
1024 + });
1025 +
1026 it("maps terminal cells to UTF-16 offsets after a wide emoji", () => {
1027 const cells = [
1028 cell("🙂"),
packages/shared/src/fileLinks.test.ts
+26
@@ -42,6 +42,32 @@ describe("splitFilePathPosition", () => {
42 });
43
44 describe("resolvePathLinkTarget", () => {
45 + it.each([
46 + [
47 + String.raw`src\index.ts:12:7`,
48 + String.raw`C:\Users\Jane Doe\project`,
49 + String.raw`C:\Users\Jane Doe\project\src\index.ts:12:7`,
50 + ],
51 + [
52 + "src/index.ts:12:7",
53 + "C:/Users/Jane Doe/project",
54 + String.raw`C:/Users/Jane Doe/project\src\index.ts:12:7`,
55 + ],
56 + [
57 + String.raw`.\src\index.ts:12`,
58 + String.raw`\\server\share\project`,
59 + String.raw`\\server\share\project\.\src\index.ts:12`,
60 + ],
61 + [
62 + String.raw`~\index.ts:12`,
63 + String.raw`C:\Users\Jane Doe\project`,
64 + String.raw`C:\Users\Jane Doe\index.ts:12`,
65 + ],
66 + ["src/index.ts:12", "/home/jane/project", "/home/jane/project/src/index.ts:12"],
67 + ])("resolves %s using the connected environment cwd %s", (path, cwd, expected) => {
68 + expect(resolvePathLinkTarget(path, cwd)).toBe(expected);
69 + });
70 +
71 it("resolves relative paths against cwd", () => {
72 expect(
73 resolvePathLinkTarget(
packages/shared/src/fileLinks.ts
+1 -1
@@ -93,7 +93,7 @@ export function resolvePathLinkTarget(rawPath: string, cwd: string): string {
93 const { path } = position;
94
95 let resolvedPath = path;
96 - if (path.startsWith("~/")) {
96 + if (path.startsWith("~/") || (isWindowsPathStyle(cwd) && path.startsWith("~\\"))) {
97 const home = inferHomeFromCwd(cwd);
98 if (home) {
99 const separator: "/" | "\\" = isWindowsPathStyle(home) ? "\\" : "/";