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

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

fix(web): keep PowerShell prompt paths with spaces in one link (#23527)

Utkarsh Patil committed Oct 30, 2026 at 18:11 UTC d1f1650f09bc51bad3146b572e0ec72730741c61
3 files changed +51 -3
apps/web/src/terminal-links.test.ts
+30
@@ -16,6 +16,36 @@ function createBufferLine(text: string, isWrapped = false): TerminalBufferLineLi
16 }
17
18 describe("extractTerminalLinks", () => {
19 + it.each([
20 + String.raw`C:\dev\ai-test\dir 1`,
21 + String.raw`C:\dev\ai-test\dir 1\test`,
22 + "C:\\",
23 + String.raw`\\server\my share\dir 1`,
24 + "/home/Jane Doe/project",
25 + String.raw`C:\dev\folder (draft)\name!`,
26 + ])("keeps the full PowerShell prompt path %s in one link", (path) => {
27 + expect(extractTerminalLinks(`PS ${path}> `)).toEqual([
28 + { kind: "path", text: path, start: 3, end: 3 + path.length },
29 + ]);
30 + });
31 +
32 + it("keeps links in a command separate from the PowerShell prompt path", () => {
33 + const path = String.raw`C:\dev\dir 1\test`;
34 + const prompt = `PS ${path}> `;
35 + const url = "https://example.com";
36 + expect(extractTerminalLinks(`${prompt}echo ${url}`)).toEqual([
37 + { kind: "path", text: path, start: 3, end: 3 + path.length },
38 + { kind: "url", text: url, start: prompt.length + 5, end: prompt.length + 5 + url.length },
39 + ]);
40 + });
41 +
42 + it("does not extend ordinary output paths through trailing prose", () => {
43 + const path = String.raw`C:\dev\project`;
44 + expect(extractTerminalLinks(`see ${path} for details`)).toEqual([
45 + { kind: "path", text: path, start: 4, end: 4 + path.length },
46 + ]);
47 + });
48 +
49 it.each([
50 String.raw`src\index.ts:12`,
51 String.raw`.\src\index.ts:12:7`,
apps/web/src/terminal-links.ts
+13 -3
@@ -27,6 +27,8 @@ export interface WrappedTerminalLinkLine {
27 }
28
29 const URL_PATTERN = /https?:\/\/[^\s"'`<>]+/giu;
30 +// The default PowerShell prompt delimits its unquoted path with `PS ` and `>`.
31 +const POWERSHELL_PROMPT_PATH_PATTERN = /^PS ((?:[A-Za-z]:[\\/]|\\\\|\/)[^>\r\n]*)>/u;
32 // Bare paths start only at a segment boundary: hover detection runs this on
33 // every frame, so separator-free output must not be rescanned at every suffix.
34 const FILE_PATH_PATTERN =
@@ -104,17 +106,25 @@ function collectMatches(
106 }
107
108 export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
109 + const promptPath = POWERSHELL_PROMPT_PATH_PATTERN.exec(line)?.[1];
110 + const promptMatches: TerminalLinkMatch[] = promptPath
111 + ? [{ kind: "path", text: promptPath, start: 3, end: 3 + promptPath.length }]
112 + : [];
113 const requestRoutes = Array.from(line.matchAll(REQUEST_ROUTE_PATTERN), (match) => ({
114 start: match.index,
115 end: match.index + match[0].length,
116 }));
111 - const urlMatches = collectMatches(line, "url", URL_PATTERN, []);
112 - const quotedMatches = collectMatches(line, "path", QUOTED_FILE_PATH_PATTERN, urlMatches);
117 + const urlMatches = collectMatches(line, "url", URL_PATTERN, promptMatches);
118 + const quotedMatches = collectMatches(line, "path", QUOTED_FILE_PATH_PATTERN, [
119 + ...promptMatches,
120 + ...urlMatches,
121 + ]);
122 const pathMatches = collectMatches(line, "path", FILE_PATH_PATTERN, [
123 + ...promptMatches,
124 ...urlMatches,
125 ...quotedMatches,
126 ]);
117 - return [...urlMatches, ...quotedMatches, ...pathMatches]
127 + return [...promptMatches, ...urlMatches, ...quotedMatches, ...pathMatches]
128 .filter(
129 (match) => match.kind === "url" || !requestRoutes.some((route) => overlaps(match, route)),
130 )
apps/web/src/terminal/ghostty/surface.test.ts
+8
@@ -606,12 +606,20 @@ describe("terminalLinkAtPositionWithRange", () => {
606 row("com/reference", true),
607 row("~/project/file", false),
608 row("C:\\repo\\file.ts", false),
609 + row("PS C:\\repo\\dir 1", false, true),
610 + row("\\test> ", true),
611 ];
612
613 expect(terminalLinkAtPositionWithRange(rows, 0, 8)?.text).toBe("https://example.com/reference");
614 expect(terminalLinkAtPositionWithRange(rows, 1, 4)?.text).toBe("https://example.com/reference");
615 expect(terminalLinkAtPositionWithRange(rows, 2, 2)?.text).toBe("~/project/file");
616 expect(terminalLinkAtPositionWithRange(rows, 3, 4)?.text).toBe("C:\\repo\\file.ts");
617 + expect(terminalLinkAtPositionWithRange(rows, 4, 13)).toEqual({
618 + text: "C:\\repo\\dir 1\\test",
619 + range: { start: { x: 3, y: 4 }, end: { x: 4, y: 5 } },
620 + });
621 + expect(terminalLinkAtPositionWithRange(rows, 5, 2)?.text).toBe("C:\\repo\\dir 1\\test");
622 + expect(terminalLinkAtPositionWithRange(rows, 5, 5)).toBeNull();
623 expect(terminalLinkAtPositionWithRange(rows, 1, 4)).toEqual({
624 text: "https://example.com/reference",
625 range: {