Skip to content

Commit 3327659

Browse files
terminal links
1 parent 6d6991b commit 3327659

5 files changed

Lines changed: 384 additions & 145 deletions

File tree

‎apps/server/src/codexTextGenerator.test.ts‎

Lines changed: 0 additions & 123 deletions
This file was deleted.

‎apps/server/src/codexTextGenerator.ts‎

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,16 @@ import type {
1010
PrContentGenerationResult,
1111
TextGenerationService,
1212
} from "./coreServices";
13-
import {
14-
type ProcessRunOptions,
15-
type ProcessRunResult,
16-
runProcess,
17-
} from "./processRunner";
13+
import { type ProcessRunOptions, type ProcessRunResult, runProcess } from "./processRunner";
1814

1915
type ProcessRunner = (
2016
command: string,
2117
args: readonly string[],
2218
options?: ProcessRunOptions,
2319
) => Promise<ProcessRunResult>;
2420

25-
const CODEX_MODEL = "gpt-5.3-codex-spark";
26-
const CODEX_REASONING_EFFORT = "medium";
21+
const CODEX_MODEL = "gpt-5.3-codex";
22+
const CODEX_REASONING_EFFORT = "low";
2723

2824
const COMMIT_OUTPUT_SCHEMA_JSON = {
2925
type: "object",
@@ -78,10 +74,7 @@ function limitSection(value: string, maxChars: number): string {
7874
}
7975

8076
async function writeTempFile(prefix: string, content: string): Promise<string> {
81-
const filePath = path.join(
82-
os.tmpdir(),
83-
`t3code-${prefix}-${process.pid}-${randomUUID()}.tmp`,
84-
);
77+
const filePath = path.join(os.tmpdir(), `t3code-${prefix}-${process.pid}-${randomUUID()}.tmp`);
8578
await fs.writeFile(filePath, content, "utf8");
8679
return filePath;
8780
}
@@ -128,10 +121,7 @@ async function runCodexJson<T>({
128121
parse: (raw: unknown) => T;
129122
run: ProcessRunner;
130123
}): Promise<T> {
131-
const schemaPath = await writeTempFile(
132-
"codex-schema",
133-
JSON.stringify(outputSchemaJson),
134-
);
124+
const schemaPath = await writeTempFile("codex-schema", JSON.stringify(outputSchemaJson));
135125
let outputPath: string | null = null;
136126

137127
try {
@@ -174,10 +164,7 @@ async function runCodexJson<T>({
174164

175165
return parse(parsedJson);
176166
} finally {
177-
await Promise.all([
178-
safeUnlink(schemaPath),
179-
...(outputPath ? [safeUnlink(outputPath)] : []),
180-
]);
167+
await Promise.all([safeUnlink(schemaPath), ...(outputPath ? [safeUnlink(outputPath)] : [])]);
181168
}
182169
}
183170

@@ -226,9 +213,7 @@ export class CodexTextGenerator implements TextGenerationService {
226213
};
227214
}
228215

229-
async generatePrContent(
230-
input: PrContentGenerationInput,
231-
): Promise<PrContentGenerationResult> {
216+
async generatePrContent(input: PrContentGenerationInput): Promise<PrContentGenerationResult> {
232217
const prompt = [
233218
"You write GitHub pull request content.",
234219
"Return a JSON object with keys: title, body.",

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ import {
88
useRef,
99
useState,
1010
} from "react";
11+
import {
12+
extractTerminalLinks,
13+
isTerminalLinkActivation,
14+
preferredTerminalEditor,
15+
resolvePathLinkTarget,
16+
} from "../terminal-links";
1117
import { isTerminalClearShortcut } from "../terminal-shortcuts";
1218
import { DEFAULT_THREAD_TERMINAL_HEIGHT } from "../types";
1319

@@ -298,6 +304,67 @@ export default function ThreadTerminalDrawer({
298304
return false;
299305
});
300306

307+
const terminalLinksDisposable = terminal.registerLinkProvider({
308+
provideLinks: (bufferLineNumber, callback) => {
309+
const activeTerminal = terminalRef.current;
310+
if (!activeTerminal) {
311+
callback(undefined);
312+
return;
313+
}
314+
315+
const line = activeTerminal.buffer.active.getLine(bufferLineNumber - 1);
316+
if (!line) {
317+
callback(undefined);
318+
return;
319+
}
320+
321+
const lineText = line.translateToString(true);
322+
const matches = extractTerminalLinks(lineText);
323+
if (matches.length === 0) {
324+
callback(undefined);
325+
return;
326+
}
327+
328+
callback(
329+
matches.map((match) => ({
330+
text: match.text,
331+
range: {
332+
start: { x: match.start + 1, y: bufferLineNumber },
333+
end: { x: match.end, y: bufferLineNumber },
334+
},
335+
activate: (event: MouseEvent) => {
336+
if (!isTerminalLinkActivation(event)) {
337+
return;
338+
}
339+
340+
const latestTerminal = terminalRef.current;
341+
if (!latestTerminal) {
342+
return;
343+
}
344+
345+
if (match.kind === "url") {
346+
void api.shell.openExternal(match.text).catch((error) => {
347+
writeSystemMessage(
348+
latestTerminal,
349+
error instanceof Error ? error.message : "Unable to open link",
350+
);
351+
});
352+
return;
353+
}
354+
355+
const target = resolvePathLinkTarget(match.text, cwd);
356+
void api.shell.openInEditor(target, preferredTerminalEditor()).catch((error) => {
357+
writeSystemMessage(
358+
latestTerminal,
359+
error instanceof Error ? error.message : "Unable to open path",
360+
);
361+
});
362+
},
363+
})),
364+
);
365+
},
366+
});
367+
301368
const inputDisposable = terminal.onData((data) => {
302369
void api.terminal
303370
.write({ threadId, data })
@@ -393,6 +460,7 @@ export default function ThreadTerminalDrawer({
393460
window.clearTimeout(fitTimer);
394461
unsubscribe();
395462
inputDisposable.dispose();
463+
terminalLinksDisposable.dispose();
396464
themeObserver.disconnect();
397465
terminalRef.current = null;
398466
fitAddonRef.current = null;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import {
4+
extractTerminalLinks,
5+
isTerminalLinkActivation,
6+
resolvePathLinkTarget,
7+
} from "./terminal-links";
8+
9+
describe("extractTerminalLinks", () => {
10+
it("finds http urls and path tokens", () => {
11+
const line =
12+
"failed at https://example.com/docs and src/components/ThreadTerminalDrawer.tsx:42";
13+
expect(extractTerminalLinks(line)).toEqual([
14+
{
15+
kind: "url",
16+
text: "https://example.com/docs",
17+
start: 10,
18+
end: 34,
19+
},
20+
{
21+
kind: "path",
22+
text: "src/components/ThreadTerminalDrawer.tsx:42",
23+
start: 39,
24+
end: 81,
25+
},
26+
]);
27+
});
28+
29+
it("trims trailing punctuation from links", () => {
30+
const line = "(https://example.com/docs), ./src/main.ts:12.";
31+
expect(extractTerminalLinks(line)).toEqual([
32+
{
33+
kind: "url",
34+
text: "https://example.com/docs",
35+
start: 1,
36+
end: 25,
37+
},
38+
{
39+
kind: "path",
40+
text: "./src/main.ts:12",
41+
start: 28,
42+
end: 44,
43+
},
44+
]);
45+
});
46+
});
47+
48+
describe("resolvePathLinkTarget", () => {
49+
it("resolves relative paths against cwd", () => {
50+
expect(
51+
resolvePathLinkTarget(
52+
"src/components/ThreadTerminalDrawer.tsx:42:7",
53+
"/Users/julius/project",
54+
),
55+
).toBe("/Users/julius/project/src/components/ThreadTerminalDrawer.tsx:42:7");
56+
});
57+
58+
it("keeps absolute paths unchanged", () => {
59+
expect(
60+
resolvePathLinkTarget(
61+
"/Users/julius/project/src/main.ts:12",
62+
"/Users/julius/project",
63+
),
64+
).toBe("/Users/julius/project/src/main.ts:12");
65+
});
66+
});
67+
68+
describe("isTerminalLinkActivation", () => {
69+
it("requires cmd on macOS", () => {
70+
expect(
71+
isTerminalLinkActivation(
72+
{
73+
metaKey: true,
74+
ctrlKey: false,
75+
},
76+
"MacIntel",
77+
),
78+
).toBe(true);
79+
expect(
80+
isTerminalLinkActivation(
81+
{
82+
metaKey: false,
83+
ctrlKey: true,
84+
},
85+
"MacIntel",
86+
),
87+
).toBe(false);
88+
});
89+
90+
it("requires ctrl on non-macOS", () => {
91+
expect(
92+
isTerminalLinkActivation(
93+
{
94+
metaKey: false,
95+
ctrlKey: true,
96+
},
97+
"Win32",
98+
),
99+
).toBe(true);
100+
expect(
101+
isTerminalLinkActivation(
102+
{
103+
metaKey: true,
104+
ctrlKey: false,
105+
},
106+
"Linux",
107+
),
108+
).toBe(false);
109+
});
110+
});

0 commit comments

Comments
 (0)