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 22, 08:15 UTC
fix(web): terminal URLs like redis:// no longer become broken file links (#28189)
Co-authored-by: MarcoDotIO <20867620+MarcoDotIO@users.noreply.github.com>
tiliakoos committed
Oct 31, 2026 at 22:47 UTC
f513369612a5bc5bc3de2bdfe78307f2705118ed
2 files changed
+27
-5
apps/web/src/terminal-links.test.ts
+19
@@ -187,6 +187,25 @@ describe("extractTerminalLinks", () => {
187
]);
188
});
189
190
+ it.each([
191
+ "connected to redis://127.0.0.1:6379/0",
192
+ "connected to postgres://localhost:5432/app",
193
+ "uploaded s3://bucket/reports/today.csv",
194
+ " at main (file:///Users/jane/app/src/index.mjs:3:7)",
195
+ "+redis://localhost:6379/0",
196
+ "-redis://localhost:6379/0",
197
+ ])("does not turn part of a non-web URL into an editor link: %s", (line) => {
198
+ expect(extractTerminalLinks(line)).toEqual([]);
199
+ });
200
+
201
+ it("keeps file links beside a non-web URL", () => {
202
+ const line = "src/db.ts:4 redis://localhost:6379/0 C:/app/src/db.ts:9";
203
+ expect(extractTerminalLinks(line)).toEqual([
204
+ { kind: "path", text: "src/db.ts:4", start: 0, end: 11 },
205
+ { kind: "path", text: "C:/app/src/db.ts:9", start: 37, end: 55 },
206
+ ]);
207
+ });
208
+
209
it("keeps a question mark inside a filesystem path", () => {
210
const path = "/tmp/report?draft";
211
expect(extractTerminalLinks(`wrote ${path}`)).toEqual([
apps/web/src/terminal-links.ts
+8
-5
@@ -41,6 +41,9 @@ const TRAILING_PATH_PUNCTUATION_PATTERN = /[.,;:!?]+$/;
41
// A question mark is legal in filenames; only exclude query-bearing request targets.
42
const REQUEST_ROUTE_PATTERN =
43
/(?:^|[\s"'`])(?:GET|HEAD|POST|PUT|PATCH|DELETE|OPTIONS|CONNECT|TRACE|proxying)\s+["'`]?(?:\/|[A-Za-z0-9_-]+\/)[^\s?]*\?\S*/g;
44
+// The tail of `redis://host/0` or `file:///a.mjs` is not a path. One-letter schemes stay drives,
45
+// a diff's `+` or `-` may lead, and the lookbehind keeps runs from being rescanned at every suffix.
46
+const SCHEME_URL_PATTERN = /(?<![A-Za-z\d+.-])[+-]?[A-Za-z][A-Za-z\d+.-]+:\/\/[^\s"'`<>]+/gu;
47
48
function trimClosingDelimiters(value: string, kind: TerminalLinkKind): string {
49
let output = value.replace(
@@ -110,10 +113,10 @@ export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
113
const promptMatches: TerminalLinkMatch[] = promptPath
114
? [{ kind: "path", text: promptPath, start: 3, end: 3 + promptPath.length }]
115
: [];
113
- const requestRoutes = Array.from(line.matchAll(REQUEST_ROUTE_PATTERN), (match) => ({
114
- start: match.index,
115
- end: match.index + match[0].length,
116
- }));
116
+ const nonPathRanges = Array.from(
117
+ [...line.matchAll(REQUEST_ROUTE_PATTERN), ...line.matchAll(SCHEME_URL_PATTERN)],
118
+ (match) => ({ start: match.index, end: match.index + match[0].length }),
119
+ );
120
const urlMatches = collectMatches(line, "url", URL_PATTERN, promptMatches);
121
const quotedMatches = collectMatches(line, "path", QUOTED_FILE_PATH_PATTERN, [
122
...promptMatches,
@@ -126,7 +129,7 @@ export function extractTerminalLinks(line: string): TerminalLinkMatch[] {
129
]);
130
return [...promptMatches, ...urlMatches, ...quotedMatches, ...pathMatches]
131
.filter(
129
- (match) => match.kind === "url" || !requestRoutes.some((route) => overlaps(match, route)),
132
+ (match) => match.kind === "url" || !nonPathRanges.some((range) => overlaps(match, range)),
133
)
134
.toSorted((a, b) => a.start - b.start);
135
}