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 21, 17:15 UTC
fix(web): terminal TypeScript links preserve error locations (#36174)
Simon Maggini committed
Nov 13, 2026 at 18:42 UTC
764c0475b5d98e60bdd01f5cd341c5cfbd55a2da
2 files changed
+27
-3
apps/web/src/terminal-links.test.ts
+21
@@ -299,6 +299,27 @@ describe("resolvePathLinkTarget", () => {
299
);
300
});
301
302
+ it.each([
303
+ ["src/main.ts", "/repo/src/main.ts"],
304
+ ["/repo/src/main.ts", "/repo/src/main.ts"],
305
+ [String.raw`C:\repo\src\main.ts`, String.raw`C:\repo\src\main.ts`],
306
+ ["app/(auth)/page.tsx", "/repo/app/(auth)/page.tsx"],
307
+ ])("preserves a TypeScript compiler location on %s", (path, target) => {
308
+ const text = `${path}(42,7)`;
309
+ const links = extractTerminalLinks(`${text}: error TS2322: Type mismatch`);
310
+ expect(links).toEqual([{ kind: "path", text: `${path}:42:7`, start: 0, end: text.length }]);
311
+ expect(resolveTerminalLinkTarget(links[0]?.text ?? "", "/repo")).toBe(`${target}:42:7`);
312
+ });
313
+
314
+ it.each([
315
+ [String.raw`PS C:\dev\folder (42,7)> `, String.raw`C:\dev\folder (42,7)`],
316
+ ["/tmp/report(42,7)", "/tmp/report(42,7)"],
317
+ ["src/Program.cs(3,10): error CS1002: x", "/repo/src/Program.cs"],
318
+ ])("preserves existing path targets in %s", (line, target) => {
319
+ const [link] = extractTerminalLinks(line);
320
+ expect(resolveTerminalLinkTarget(link?.text ?? "", "/repo")).toBe(target);
321
+ });
322
+
323
// regression: #36005 OSC 8 file URIs were joined onto the cwd as relative paths
324
it("does not resolve an OSC 8 file URI target against the cwd", () => {
325
expect(resolveTerminalLinkTarget("file:///var/tmp/report.txt", "/workspace/project")).toBe(
apps/web/src/terminal-links.ts
+6
-3
@@ -40,9 +40,9 @@ const POWERSHELL_PROMPT_PATH_PATTERN = /^PS ((?:[A-Za-z]:[\\/]|\\\\|\/)[^>\r\n]*
40
// Bare paths start only at a segment boundary: hover detection runs this on
41
// every frame, so separator-free output must not be rescanned at every suffix.
42
// For the same reason `]` needs its `[`: trimming a long run of `]` is quadratic.
43
-// Parentheses count only before a slash, so `src/foo.ts(3,10)` stays a compiler location.
43
+// Parenthesized path segments need a following slash to distinguish compiler locations.
44
const FILE_PATH_PATTERN =
45
- /(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|(?<![\p{L}\p{M}\p{N}._-])[\p{L}\p{M}\p{N}._-]+(?:[\\/](?:[\p{L}\p{M}\p{N}._$+@-]|\[{1,2}[\p{L}\p{M}\p{N}._-]+\]{1,2}|\([\p{L}\p{M}\p{N}._-]+\)(?=[\\/]))+)+(?::\d+){0,2}/gu;
45
+ /(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\)[^\s"'`<>]+|(?<![\p{L}\p{M}\p{N}._-])[\p{L}\p{M}\p{N}._-]+(?:[\\/](?:[\p{L}\p{M}\p{N}._$+@-]|\[{1,2}[\p{L}\p{M}\p{N}._-]+\]{1,2}|\([\p{L}\p{M}\p{N}._-]+\)(?=[\\/]))+)+(?:(?::\d+){1,2}|\(\d+,\d+\)(?=:\s+(?:error|warning) TS\d+:))?/gu;
46
const QUOTED_FILE_PATH_PATTERN =
47
/(["'`])(?<path>(?:~[\\/]|\.{1,2}[\\/]|\/|[A-Za-z]:[\\/]|\\\\|[\p{L}\p{M}\p{N}._ -]+[\\/])[^\r\n]*?|[\p{L}\p{M}\p{N}._ -]+\.[\p{L}\p{M}\p{N}_-]+(?::\d+){0,2})\1(?<position>(?::\d+){0,2})/gu;
48
const TRAILING_PUNCTUATION_PATTERN = /[.,;!?]+$/;
@@ -106,7 +106,10 @@ function collectMatches(
106
107
const candidate: TerminalLinkMatch = {
108
kind,
109
- text: trimmed,
109
+ text:
110
+ kind === "path" && /^:\s+(?:error|warning) TS\d+:/u.test(line.slice(start + trimmed.length))
111
+ ? trimmed.replace(/\((\d+),(\d+)\)$/, ":$1:$2")
112
+ : trimmed,
113
start,
114
// A position outside quotes spans the closing quote in the terminal buffer.
115
end: start + trimmed.length + (rawMatch.groups?.position ? 1 : 0),