Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

fix(tui): open OSC 8 hyperlinks on click in fullscreen mode (#1270)

Mika Senghaas965941c750ff
diff --git a/packages/coding-agent/CHANGELOG.md b/packages/coding-agent/CHANGELOG.md
index 1677ecf9b3..bfd4abb604 100644
--- a/packages/coding-agent/CHANGELOG.md
+++ b/packages/coding-agent/CHANGELOG.md
@@ -2,6 +2,8 @@
## [Unreleased]
+- Fixed URLs not opening on click in fullscreen mode on terminals such as Ghostty; clicking a link in the transcript, dock, or overlays now opens it in the browser.
+
## [0.7.2] - 2026-08-11
- Fixed Down Arrow focusing the Agents View entry before moving a nonempty prompt cursor to the end ([ENG-5147](https://linear.app/primeintellect/issue/ENG-5147/keep-down-arrow-in-the-prompt-until-the-cursor-reaches-the-end)).
diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
index b0585156ff..3092fc376e 100644
--- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts
+++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts
@@ -9803,6 +9803,7 @@ ${interrupt ? `| \`${interrupt}\` | Interrupt current operation |\n` : ""}${shor
| \`${viewportFollow}\` | Scroll to bottom and follow output |
| mouse wheel | Scroll transcript |
| mouse drag | Select and copy text |
+| mouse click on link | Open link in browser |
`;
const shortcuts = this.bindLocalSessionExtensions
diff --git a/packages/tui/CHANGELOG.md b/packages/tui/CHANGELOG.md
index bb824bb29c..c72398df4e 100644
--- a/packages/tui/CHANGELOG.md
+++ b/packages/tui/CHANGELOG.md
@@ -2,6 +2,8 @@
## [Unreleased]
+- Fixed hyperlinks not being clickable in fullscreen mode on terminals that gate native link handling while mouse reporting is active (e.g. Ghostty); left-clicking a link now opens it directly.
+
## [0.7.2] - 2026-08-11
## [0.7.1] - 2026-08-07
diff --git a/packages/tui/src/fullscreen.ts b/packages/tui/src/fullscreen.ts
index b11e9a9963..c56c196034 100644
--- a/packages/tui/src/fullscreen.ts
+++ b/packages/tui/src/fullscreen.ts
@@ -7,7 +7,7 @@
import type { TableCellSelectionRegion } from "./selection-metadata.js";
import { isImageLine } from "./terminal-image.js";
-import { sliceByColumn, stripAnsi, visibleWidth } from "./utils.js";
+import { hyperlinkAtColumn, sliceByColumn, stripAnsi, visibleWidth } from "./utils.js";
export const FULLSCREEN_MIN_TRANSCRIPT_ROWS = 3;
@@ -625,6 +625,19 @@ export class FullscreenViewport {
return this.orderedSelection() !== null;
}
+ /**
+ * OSC 8 hyperlink URL at a screen position in the last painted frame, or
+ * null when the position is not over a hyperlink. Covers the transcript
+ * window, the dock, and composited overlays.
+ */
+ hyperlinkAt(screenRow: number, screenCol: number): string | null {
+ if (screenRow < 0 || screenCol < 0 || this.lastFrameVisibleHeight === 0) return null;
+ if (screenRow >= this.lastFrameVisibleHeight) return null;
+ const line = this.lastFrame[this.lastFrameVisibleStart + screenRow];
+ if (line === undefined || isImageLine(line)) return null;
+ return hyperlinkAtColumn(line, screenCol);
+ }
+
/** Row-diff a composed frame against the previous one with absolute addressing. */
paint(
write: (data: string) => void,
diff --git a/packages/tui/src/tui.ts b/packages/tui/src/tui.ts
index 32655a68bc..fcf37e8427 100644
--- a/packages/tui/src/tui.ts
+++ b/packages/tui/src/tui.ts
@@ -2,6 +2,7 @@
* Minimal TUI implementation with differential rendering
*/
+import { execFile } from "node:child_process";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
@@ -313,6 +314,8 @@ export class TUI extends Container {
public onDebug?: () => void;
/** Copies fullscreen mouse selections; when unset, OSC 52 is written directly. */
public onCopy?: (text: string) => void;
+ /** Opens hyperlinks clicked in the fullscreen viewport; when unset, the platform opener is used. */
+ public onOpenUrl?: (url: string) => void;
private renderRequested = false;
private renderTimer: NodeJS.Timeout | undefined;
private lastRenderAt = 0;
@@ -326,6 +329,7 @@ export class TUI extends Container {
private fullRedrawCount = 0;
private preserveViewportOnNextRender = false; // One-shot: repaint visible viewport in place instead of replaying scrollback
private stopped = false;
+ private fullscreenLeftMouseDragged = false;
private overlaySelectionRegions: FrameSelectionRegion[] = [];
// While set, doRender paints fixed frames via the viewport; the inline
@@ -751,6 +755,36 @@ export class TUI extends Container {
return this.fullscreen?.viewport.scrollInfo() ?? null;
}
+ // Terminals gate their native link handling while mouse reporting is active
+ // (Ghostty only refreshes link hover when reporting is off or shift is held),
+ // so clicks the TUI consumes must open OSC 8 hyperlinks itself.
+ private openHyperlink(url: string): void {
+ if (/\p{Cc}/u.test(url)) return;
+ let href: string;
+ try {
+ const parsed = new URL(url);
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return;
+ href = parsed.href;
+ } catch {
+ return;
+ }
+ if (this.onOpenUrl) {
+ this.onOpenUrl(href);
+ return;
+ }
+ const [command, ...args] =
+ process.platform === "darwin"
+ ? ["open", href]
+ : process.platform === "win32"
+ ? [
+ path.win32.join(process.env.SystemRoot ?? "C:\\Windows", "System32", "rundll32.exe"),
+ "url.dll,FileProtocolHandler",
+ href,
+ ]
+ : ["xdg-open", href];
+ execFile(command, args, () => {});
+ }
+
private copySelection(text: string): void {
if (this.onCopy) {
this.onCopy(text);
@@ -892,6 +926,11 @@ export class TUI extends Container {
if (isMouseSequence(data)) {
// consumed even when disabled — mouse reports are garbage downstream
const event = this.terminal.mouseTrackingActive ? parseSgrMouseEvent(data) : null;
+ const leftReleaseWasDrag =
+ event?.button === MOUSE_BUTTON_LEFT && !event.press ? this.fullscreenLeftMouseDragged : false;
+ if (event?.button === MOUSE_BUTTON_LEFT && event.press) {
+ this.fullscreenLeftMouseDragged = event.motion;
+ }
if (event && !overlayFocused) {
const viewport = fullscreen.viewport;
if (isWheelUp(event)) {
@@ -918,6 +957,10 @@ export class TUI extends Container {
} else if (!event.press) {
this.stopSelectionAutoScroll();
viewport.clearSelection();
+ if (event.button === MOUSE_BUTTON_LEFT && !event.motion && !leftReleaseWasDrag) {
+ const url = viewport.hyperlinkAt(event.y - 1, event.x - 1);
+ if (url) this.openHyperlink(url);
+ }
}
} else if (event && overlayFocused) {
this.stopSelectionAutoScroll();
@@ -936,8 +979,15 @@ export class TUI extends Container {
this.requestRender();
} else if (!event.press) {
viewport.clearSelection();
+ if (event.button === MOUSE_BUTTON_LEFT && !event.motion && !leftReleaseWasDrag) {
+ const url = viewport.hyperlinkAt(event.y - 1, event.x - 1);
+ if (url) this.openHyperlink(url);
+ }
}
}
+ if (event?.button === MOUSE_BUTTON_LEFT && !event.press) {
+ this.fullscreenLeftMouseDragged = false;
+ }
return true;
}
this.stopSelectionAutoScroll();
diff --git a/packages/tui/src/utils.ts b/packages/tui/src/utils.ts
index ba02305e05..a7655521e8 100644
--- a/packages/tui/src/utils.ts
+++ b/packages/tui/src/utils.ts
@@ -1239,6 +1239,36 @@ export function sliceWithWidth(
return { text: result, width: resultWidth };
}
+/**
+ * Return the OSC 8 hyperlink URL covering the given visible column, or null
+ * when the column is not inside a hyperlink (or is past the end of the line).
+ */
+export function hyperlinkAtColumn(line: string, column: number): string | null {
+ if (column < 0) return null;
+ const extractAnsi = createAnsiCodeExtractor(line);
+ let currentCol = 0;
+ let activeUrl: string | null = null;
+ let i = 0;
+ while (i < line.length) {
+ const ansi = extractAnsi(i);
+ if (ansi) {
+ const hyperlink = parseOsc8Hyperlink(ansi.code);
+ if (hyperlink !== undefined) activeUrl = hyperlink?.url ?? null;
+ i += ansi.length;
+ continue;
+ }
+ let textEnd = i;
+ while (textEnd < line.length && !extractAnsi(textEnd)) textEnd++;
+ for (const { segment } of segmenter.segment(line.slice(i, textEnd))) {
+ const w = graphemeWidth(segment);
+ if (column < currentCol + w) return activeUrl;
+ currentCol += w;
+ }
+ i = textEnd;
+ }
+ return null;
+}
+
// Pooled tracker instance for extractSegments (avoids allocation per call)
const pooledStyleTracker = new AnsiCodeTracker();
diff --git a/packages/tui/test/fullscreen.test.ts b/packages/tui/test/fullscreen.test.ts
index 6b738cbd9b..2a6352b5bd 100644
--- a/packages/tui/test/fullscreen.test.ts
+++ b/packages/tui/test/fullscreen.test.ts
@@ -936,6 +936,166 @@ describe("TUI fullscreen mode", () => {
tui.stop();
});
+ it("clicking an OSC 8 hyperlink opens it through the URL handler", async () => {
+ const transcript = lines(20);
+ // window height is 8 (rows=10, dock=2), following shows lines 12..19
+ transcript[12] = "see \x1b]8;;https://example.com/docs\x1b\\\x1b[36mdocs\x1b[39m\x1b]8;;\x1b\\ here";
+ const { terminal, tui, chat, dock } = setup(transcript);
+ const opened: string[] = [];
+ tui.onOpenUrl = (url) => opened.push(url);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ // "docs" occupies columns 5-8 on screen row 1
+ terminal.sendInput("\x1b[<0;6;1M");
+ terminal.sendInput("\x1b[<0;6;1m");
+ await terminal.waitForRender();
+ assert.deepStrictEqual(opened, ["https://example.com/docs"]);
+
+ // clicking outside the link opens nothing
+ terminal.sendInput("\x1b[<0;2;1M");
+ terminal.sendInput("\x1b[<0;2;1m");
+ await terminal.waitForRender();
+ assert.deepStrictEqual(opened, ["https://example.com/docs"]);
+
+ tui.stop();
+ });
+
+ it("drag-selecting over a hyperlink copies text without opening it", async () => {
+ const transcript = lines(20);
+ transcript[12] = "see \x1b]8;;https://example.com/docs\x1b\\docs\x1b]8;;\x1b\\ here";
+ const { terminal, tui, chat, dock } = setup(transcript);
+ const opened: string[] = [];
+ const copies: string[] = [];
+ tui.onOpenUrl = (url) => opened.push(url);
+ tui.onCopy = (text) => copies.push(text);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput("\x1b[<0;5;1M");
+ terminal.sendInput("\x1b[<32;9;1M");
+ terminal.sendInput("\x1b[<0;9;1m");
+ await terminal.waitForRender();
+
+ assert.deepStrictEqual(copies, ["docs"]);
+ assert.deepStrictEqual(opened, []);
+
+ tui.stop();
+ });
+
+ it("does not open a link when a drag returns to its press cell", async () => {
+ const transcript = lines(20);
+ transcript[12] = "see \x1b]8;;https://example.com/docs\x1b\\docs\x1b]8;;\x1b\\ here";
+ const { terminal, tui, chat, dock } = setup(transcript);
+ const opened: string[] = [];
+ const copies: string[] = [];
+ tui.onOpenUrl = (url) => opened.push(url);
+ tui.onCopy = (text) => copies.push(text);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput("\x1b[<0;5;1M");
+ terminal.sendInput("\x1b[<32;9;1M");
+ terminal.sendInput("\x1b[<32;5;1M");
+ terminal.sendInput("\x1b[<0;5;1m");
+ await terminal.waitForRender();
+
+ assert.deepStrictEqual(copies, []);
+ assert.deepStrictEqual(opened, []);
+
+ tui.stop();
+ });
+
+ it("does not open a link when a focused-overlay drag returns to its press cell", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20), 80, 10);
+ const opened: string[] = [];
+ const copies: string[] = [];
+ tui.onOpenUrl = (url) => opened.push(url);
+ tui.onCopy = (text) => copies.push(text);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ const overlay = new InputComponent();
+ overlay.lines = ["\x1b]8;;https://example.com/docs\x1b\\docs\x1b]8;;\x1b\\"];
+ tui.showOverlay(overlay, { anchor: "center", width: 20 });
+ await terminal.waitForRender();
+
+ const viewport = terminal.getViewport();
+ const row = viewport.findIndex((line) => line.includes("docs"));
+ assert.notStrictEqual(row, -1);
+ const x = viewport[row]!.indexOf("docs") + 1;
+ const y = row + 1;
+ terminal.sendInput(`\x1b[<0;${x};${y}M`);
+ terminal.sendInput(`\x1b[<32;${x + 4};${y}M`);
+ terminal.sendInput(`\x1b[<32;${x};${y}M`);
+ terminal.sendInput(`\x1b[<0;${x};${y}m`);
+ await terminal.waitForRender();
+
+ assert.deepStrictEqual(copies, []);
+ assert.deepStrictEqual(opened, []);
+ assert.deepStrictEqual(overlay.inputs, []);
+
+ tui.stop();
+ });
+
+ it("ignores clicked hyperlinks with non-http schemes", async () => {
+ const transcript = lines(20);
+ transcript[12] = "\x1b]8;;file:///etc/passwd\x1b\\secrets\x1b]8;;\x1b\\";
+ const { terminal, tui, chat, dock } = setup(transcript);
+ const opened: string[] = [];
+ tui.onOpenUrl = (url) => opened.push(url);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput("\x1b[<0;3;1M");
+ terminal.sendInput("\x1b[<0;3;1m");
+ await terminal.waitForRender();
+ assert.deepStrictEqual(opened, []);
+
+ tui.stop();
+ });
+
+ it("rejects malformed or control-character hyperlink URLs", async () => {
+ const transcript = lines(20);
+ transcript[12] =
+ "\x1b]8;;https://example.com/\x00bad\x1b\\nul\x1b]8;;\x1b\\ " +
+ "\x1b]8;;https://[invalid\x1b\\malformed\x1b]8;;\x1b\\ " +
+ "\x1b]8;;https://example.com/\u0085bad\x1b\\c1\x1b]8;;\x1b\\";
+ const { terminal, tui, chat, dock } = setup(transcript);
+ const opened: string[] = [];
+ tui.onOpenUrl = (url) => opened.push(url);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ terminal.sendInput("\x1b[<0;1;1M");
+ terminal.sendInput("\x1b[<0;1;1m");
+ terminal.sendInput("\x1b[<0;6;1M");
+ terminal.sendInput("\x1b[<0;6;1m");
+ terminal.sendInput("\x1b[<0;15;1M");
+ terminal.sendInput("\x1b[<0;15;1m");
+ await terminal.waitForRender();
+ assert.deepStrictEqual(opened, []);
+
+ tui.stop();
+ });
+
+ it("clicking a hyperlink in the dock opens it", async () => {
+ const { terminal, tui, chat, dock } = setup(lines(20));
+ dock.lines = ["\x1b]8;;https://example.com/login\x07sign in\x1b]8;;\x07", "footer"];
+ const opened: string[] = [];
+ tui.onOpenUrl = (url) => opened.push(url);
+ tui.enterFullscreen({ scroll: [chat], dock });
+ await terminal.waitForRender();
+
+ // rows=10, dock=2 → dock starts at screen row 9
+ terminal.sendInput("\x1b[<0;3;9M");
+ terminal.sendInput("\x1b[<0;3;9m");
+ await terminal.waitForRender();
+ assert.deepStrictEqual(opened, ["https://example.com/login"]);
+
+ tui.stop();
+ });
+
it("a plain click copies nothing and clears any selection", async () => {
const { terminal, tui, chat, dock } = setup(lines(20));
const copies: string[] = [];
diff --git a/packages/tui/test/hyperlink-at-column.test.ts b/packages/tui/test/hyperlink-at-column.test.ts
new file mode 100644
index 0000000000..73e1b3e636
--- /dev/null
+++ b/packages/tui/test/hyperlink-at-column.test.ts
@@ -0,0 +1,52 @@
+import assert from "node:assert";
+import { describe, it } from "node:test";
+import { hyperlinkAtColumn } from "../src/utils.js";
+
+const ST = "\x1b\\";
+
+function link(url: string, text: string, terminator = ST): string {
+ return `\x1b]8;;${url}${terminator}${text}\x1b]8;;${terminator}`;
+}
+
+describe("hyperlinkAtColumn", () => {
+ it("returns the URL for columns inside the link and null outside", () => {
+ const line = `see ${link("https://example.com/docs", "docs")} here`;
+ assert.strictEqual(hyperlinkAtColumn(line, 0), null);
+ assert.strictEqual(hyperlinkAtColumn(line, 3), null);
+ assert.strictEqual(hyperlinkAtColumn(line, 4), "https://example.com/docs");
+ assert.strictEqual(hyperlinkAtColumn(line, 7), "https://example.com/docs");
+ assert.strictEqual(hyperlinkAtColumn(line, 8), null);
+ });
+
+ it("supports BEL-terminated links", () => {
+ const line = link("https://example.com/login", "https://example.com/login", "\x07");
+ assert.strictEqual(hyperlinkAtColumn(line, 0), "https://example.com/login");
+ assert.strictEqual(hyperlinkAtColumn(line, 24), "https://example.com/login");
+ assert.strictEqual(hyperlinkAtColumn(line, 25), null);
+ });
+
+ it("tracks multiple links on one line", () => {
+ const line = `${link("https://a.example", "aa")} ${link("https://b.example", "bb")}`;
+ assert.strictEqual(hyperlinkAtColumn(line, 1), "https://a.example");
+ assert.strictEqual(hyperlinkAtColumn(line, 2), null);
+ assert.strictEqual(hyperlinkAtColumn(line, 3), "https://b.example");
+ });
+
+ it("counts wide graphemes as two columns", () => {
+ const line = `\u4f60\u597d ${link("https://example.com", "docs")}`;
+ assert.strictEqual(hyperlinkAtColumn(line, 4), null);
+ assert.strictEqual(hyperlinkAtColumn(line, 5), "https://example.com");
+ });
+
+ it("ignores SGR styling inside the link", () => {
+ const line = `x ${link("https://example.com", "\x1b[36mdocs\x1b[39m")}`;
+ assert.strictEqual(hyperlinkAtColumn(line, 3), "https://example.com");
+ });
+
+ it("returns null past the end of the line and for negative columns", () => {
+ const line = link("https://example.com", "docs");
+ assert.strictEqual(hyperlinkAtColumn(line, 4), null);
+ assert.strictEqual(hyperlinkAtColumn(line, 100), null);
+ assert.strictEqual(hyperlinkAtColumn(line, -1), null);
+ });
+});