Skip to content

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

Rust

fix(tui): open bare URLs in fullscreen mode (#1299)

Seth Karten0987c1ba7637
diff --git a/packages/coding-agent/src/core/settings-manager.ts b/packages/coding-agent/src/core/settings-manager.ts
index ab42f5e93f..9e64ca4cf3 100644
--- a/packages/coding-agent/src/core/settings-manager.ts
+++ b/packages/coding-agent/src/core/settings-manager.ts
@@ -45,7 +45,7 @@ export interface TerminalSettings {
clearOnShrink?: boolean; // default: false (clear empty rows when content shrinks)
showTerminalProgress?: boolean; // default: false (OSC 9;4 terminal progress indicators)
fullscreen?: boolean; // default: true (alternate-screen rendering with scrollable transcript)
- fullscreenMouse?: boolean; // default: true (wheel scrolling in fullscreen; disable if it breaks selection)
+ fullscreenMouse?: boolean; // default: true, except false in Ghostty to preserve native Cmd-click links
}
export interface ImageSettings {
@@ -1154,7 +1154,19 @@ export class SettingsManager {
}
getFullscreenMouse(): boolean {
- return this.settings.terminal?.fullscreenMouse ?? true;
+ const configured = this.settings.terminal?.fullscreenMouse;
+ if (typeof configured === "boolean") return configured;
+ // Ghostty's native Cmd-click URL handling is suppressed while an
+ // application enables mouse reporting, and SGR cannot encode Command for
+ // the application to reproduce that gesture. Preserve native link clicks
+ // by default; users can explicitly enable fullscreen mouse capture.
+ const termProgram = process.env.TERM_PROGRAM?.toLowerCase();
+ const term = process.env.TERM?.toLowerCase();
+ const isGhostty =
+ termProgram === "ghostty" ||
+ term?.includes("ghostty") === true ||
+ (termProgram === undefined && !!process.env.GHOSTTY_RESOURCES_DIR);
+ return !isGhostty;
}
setFullscreenMouse(enabled: boolean): void {
diff --git a/packages/coding-agent/test/fullscreen-mode.test.ts b/packages/coding-agent/test/fullscreen-mode.test.ts
index 7a38ec6895..d360218843 100644
--- a/packages/coding-agent/test/fullscreen-mode.test.ts
+++ b/packages/coding-agent/test/fullscreen-mode.test.ts
@@ -1,4 +1,4 @@
-import { existsSync, mkdirSync, readFileSync, rmSync } from "fs";
+import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
import { join } from "path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { SettingsManager } from "../src/core/settings-manager.js";
@@ -9,6 +9,9 @@ describe("fullscreen mode settings", () => {
const agentDir = join(testDir, "agent");
const projectDir = join(testDir, "project");
let savedEnv: string | undefined;
+ let savedTermProgram: string | undefined;
+ let savedTerm: string | undefined;
+ let savedGhosttyResourcesDir: string | undefined;
beforeEach(() => {
if (existsSync(testDir)) {
@@ -17,7 +20,13 @@ describe("fullscreen mode settings", () => {
mkdirSync(agentDir, { recursive: true });
mkdirSync(join(projectDir, ".prime", "agent"), { recursive: true });
savedEnv = process.env.PI_FULLSCREEN;
+ savedTermProgram = process.env.TERM_PROGRAM;
+ savedTerm = process.env.TERM;
+ savedGhosttyResourcesDir = process.env.GHOSTTY_RESOURCES_DIR;
delete process.env.PI_FULLSCREEN;
+ delete process.env.TERM_PROGRAM;
+ delete process.env.TERM;
+ delete process.env.GHOSTTY_RESOURCES_DIR;
});
afterEach(() => {
@@ -29,6 +38,12 @@ describe("fullscreen mode settings", () => {
} else {
process.env.PI_FULLSCREEN = savedEnv;
}
+ if (savedTermProgram === undefined) delete process.env.TERM_PROGRAM;
+ else process.env.TERM_PROGRAM = savedTermProgram;
+ if (savedTerm === undefined) delete process.env.TERM;
+ else process.env.TERM = savedTerm;
+ if (savedGhosttyResourcesDir === undefined) delete process.env.GHOSTTY_RESOURCES_DIR;
+ else process.env.GHOSTTY_RESOURCES_DIR = savedGhosttyResourcesDir;
});
it("defaults to on with mouse enabled", () => {
@@ -37,6 +52,47 @@ describe("fullscreen mode settings", () => {
expect(manager.getFullscreenMouse()).toBe(true);
});
+ it("preserves native Ghostty link clicks by disabling mouse capture by default", () => {
+ process.env.TERM_PROGRAM = "ghostty";
+ const manager = SettingsManager.create(projectDir, agentDir);
+ expect(manager.getFullscreenMouse()).toBe(false);
+ });
+
+ it("detects Ghostty through TERM in SSH sessions", () => {
+ process.env.TERM = "xterm-ghostty";
+ const manager = SettingsManager.create(projectDir, agentDir);
+ expect(manager.getFullscreenMouse()).toBe(false);
+ });
+
+ it("honors explicit mouse capture when TERM identifies Ghostty", () => {
+ process.env.TERM = "xterm-ghostty";
+ const manager = SettingsManager.create(projectDir, agentDir);
+ manager.setFullscreenMouse(true);
+ expect(manager.getFullscreenMouse()).toBe(true);
+ });
+
+ it("does not mistake an integrated terminal inheriting Ghostty variables for Ghostty", () => {
+ process.env.TERM_PROGRAM = "vscode";
+ process.env.GHOSTTY_RESOURCES_DIR = "/Applications/Ghostty.app/Contents/Resources/ghostty";
+ const manager = SettingsManager.create(projectDir, agentDir);
+ expect(manager.getFullscreenMouse()).toBe(true);
+ });
+
+ it("honors an explicit fullscreen mouse setting in Ghostty", () => {
+ process.env.GHOSTTY_RESOURCES_DIR = "/Applications/Ghostty.app/Contents/Resources/ghostty";
+ const manager = SettingsManager.create(projectDir, agentDir);
+ manager.setFullscreenMouse(true);
+ expect(manager.getFullscreenMouse()).toBe(true);
+ });
+
+ it("ignores a malformed null fullscreen mouse setting", () => {
+ process.env.TERM_PROGRAM = "xterm";
+ const settingsPath = join(agentDir, "settings.json");
+ writeFileSync(settingsPath, JSON.stringify({ terminal: { fullscreenMouse: null } }));
+ const manager = SettingsManager.create(projectDir, agentDir);
+ expect(manager.getFullscreenMouse()).toBe(true);
+ });
+
it("persists the fullscreen off toggle", async () => {
const manager = SettingsManager.create(projectDir, agentDir);
manager.setFullscreen(false);
diff --git a/packages/tui/src/fullscreen.ts b/packages/tui/src/fullscreen.ts
index c56c196034..7c21e55caa 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 { hyperlinkAtColumn, sliceByColumn, stripAnsi, visibleWidth } from "./utils.js";
+import { sliceByColumn, stripAnsi, urlAtColumn, visibleWidth } from "./utils.js";
export const FULLSCREEN_MIN_TRANSCRIPT_ROWS = 3;
@@ -635,7 +635,7 @@ export class FullscreenViewport {
if (screenRow >= this.lastFrameVisibleHeight) return null;
const line = this.lastFrame[this.lastFrameVisibleStart + screenRow];
if (line === undefined || isImageLine(line)) return null;
- return hyperlinkAtColumn(line, screenCol);
+ return urlAtColumn(line, screenCol);
}
/** Row-diff a composed frame against the previous one with absolute addressing. */
diff --git a/packages/tui/src/tui.ts b/packages/tui/src/tui.ts
index fcf37e8427..318513c824 100644
--- a/packages/tui/src/tui.ts
+++ b/packages/tui/src/tui.ts
@@ -330,6 +330,7 @@ export class TUI extends Container {
private preserveViewportOnNextRender = false; // One-shot: repaint visible viewport in place instead of replaying scrollback
private stopped = false;
private fullscreenLeftMouseDragged = false;
+ private fullscreenPressedHyperlink: string | null = null;
private overlaySelectionRegions: FrameSelectionRegion[] = [];
// While set, doRender paints fixed frames via the viewport; the inline
@@ -553,6 +554,8 @@ export class TUI extends Container {
const enabled = this.shouldEnableFullscreenMouseTracking();
if (!enabled) {
this.stopSelectionAutoScroll();
+ this.fullscreenLeftMouseDragged = false;
+ this.fullscreenPressedHyperlink = null;
this.fullscreen?.viewport.clearSelection();
} else if (this.isFullscreenOverlayFocused()) {
this.stopSelectionAutoScroll();
@@ -677,6 +680,8 @@ export class TUI extends Container {
*/
enterFullscreen(options: FullscreenOptions): void {
if (this.fullscreen) return;
+ this.fullscreenLeftMouseDragged = false;
+ this.fullscreenPressedHyperlink = null;
this.fullscreen = {
viewport: new FullscreenViewport(),
scroll: options.scroll,
@@ -930,6 +935,9 @@ export class TUI extends Container {
event?.button === MOUSE_BUTTON_LEFT && !event.press ? this.fullscreenLeftMouseDragged : false;
if (event?.button === MOUSE_BUTTON_LEFT && event.press) {
this.fullscreenLeftMouseDragged = event.motion;
+ if (!event.motion) {
+ this.fullscreenPressedHyperlink = fullscreen.viewport.hyperlinkAt(event.y - 1, event.x - 1);
+ }
}
if (event && !overlayFocused) {
const viewport = fullscreen.viewport;
@@ -958,7 +966,7 @@ export class TUI extends Container {
this.stopSelectionAutoScroll();
viewport.clearSelection();
if (event.button === MOUSE_BUTTON_LEFT && !event.motion && !leftReleaseWasDrag) {
- const url = viewport.hyperlinkAt(event.y - 1, event.x - 1);
+ const url = this.fullscreenPressedHyperlink ?? viewport.hyperlinkAt(event.y - 1, event.x - 1);
if (url) this.openHyperlink(url);
}
}
@@ -980,13 +988,14 @@ export class TUI extends Container {
} 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);
+ const url = this.fullscreenPressedHyperlink ?? viewport.hyperlinkAt(event.y - 1, event.x - 1);
if (url) this.openHyperlink(url);
}
}
}
if (event?.button === MOUSE_BUTTON_LEFT && !event.press) {
this.fullscreenLeftMouseDragged = false;
+ this.fullscreenPressedHyperlink = null;
}
return true;
}
diff --git a/packages/tui/src/utils.ts b/packages/tui/src/utils.ts
index a7655521e8..f26f5ea0a1 100644
--- a/packages/tui/src/utils.ts
+++ b/packages/tui/src/utils.ts
@@ -1269,6 +1269,36 @@ export function hyperlinkAtColumn(line: string, column: number): string | null {
return null;
}
+/**
+ * Return an explicit OSC 8 URL or terminal-style bare HTTP(S) URL covering a
+ * visible column. OSC 8 remains authoritative when its label resembles a URL.
+ */
+export function urlAtColumn(line: string, column: number): string | null {
+ const explicitUrl = hyperlinkAtColumn(line, column);
+ if (explicitUrl || column < 0) return explicitUrl;
+
+ // Fullscreen normalizes tabs before painting, and strips ANSI without
+ // changing visible columns. Mirror that representation for bare URL spans.
+ const plainText = stripAnsi(line).replace(/\t/g, " ");
+ const urlPattern = /https?:\/\/[^\s<>"'`]+/giu;
+ for (const match of plainText.matchAll(urlPattern)) {
+ let url = match[0].replace(/[.,;:!?]+$/u, "");
+ for (const [open, close] of [
+ ["(", ")"],
+ ["[", "]"],
+ ["{", "}"],
+ ] as const) {
+ while (url.endsWith(close) && url.split(close).length > url.split(open).length) {
+ url = url.slice(0, -1);
+ }
+ }
+ const start = visibleWidth(plainText.slice(0, match.index));
+ const end = start + visibleWidth(url);
+ if (column >= start && column < end) return url;
+ }
+ 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 2a6352b5bd..5dd22d3491 100644
--- a/packages/tui/test/fullscreen.test.ts
+++ b/packages/tui/test/fullscreen.test.ts
@@ -961,6 +961,45 @@ describe("TUI fullscreen mode", () => {
tui.stop();
});
+ it("clicking a bare URL opens it when OSC 8 metadata is absent", async () => {
+ const transcript = lines(20);
+ transcript[12] = "see https://example.com/docs 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();
+
+ terminal.sendInput("\x1b[<0;6;1M");
+ // The target can repaint between physical press and release while output streams.
+ transcript[12] = "updated without the URL";
+ tui.requestRender();
+ await terminal.waitForRender();
+ terminal.sendInput("\x1b[<0;6;1m");
+ await terminal.waitForRender();
+ assert.deepStrictEqual(opened, ["https://example.com/docs"]);
+
+ tui.stop();
+ });
+
+ it("clicking a hyperlink after a tab opens the painted target", async () => {
+ const transcript = lines(20);
+ transcript[12] = "\t\x1b]8;;https://example.com/docs\x1b\\docs\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();
+
+ // The tab is painted as three spaces, so the link starts at column 4.
+ terminal.sendInput("\x1b[<0;4;1M");
+ terminal.sendInput("\x1b[<0;4;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";
diff --git a/packages/tui/test/hyperlink-at-column.test.ts b/packages/tui/test/hyperlink-at-column.test.ts
index 73e1b3e636..09e747708e 100644
--- a/packages/tui/test/hyperlink-at-column.test.ts
+++ b/packages/tui/test/hyperlink-at-column.test.ts
@@ -1,6 +1,6 @@
import assert from "node:assert";
import { describe, it } from "node:test";
-import { hyperlinkAtColumn } from "../src/utils.js";
+import { hyperlinkAtColumn, urlAtColumn } from "../src/utils.js";
const ST = "\x1b\\";
@@ -32,6 +32,31 @@ describe("hyperlinkAtColumn", () => {
assert.strictEqual(hyperlinkAtColumn(line, 3), "https://b.example");
});
+ it("detects bare http URLs when OSC 8 metadata is absent", () => {
+ const line = "visit https://example.com/docs, then continue";
+ assert.strictEqual(urlAtColumn(line, 6), "https://example.com/docs");
+ assert.strictEqual(urlAtColumn(line, 29), "https://example.com/docs");
+ assert.strictEqual(urlAtColumn(line, 30), null);
+ });
+
+ it("does not include trailing prose punctuation in bare URLs", () => {
+ const line = "open (https://example.com/path).";
+ assert.strictEqual(urlAtColumn(line, 7), "https://example.com/path");
+ assert.strictEqual(urlAtColumn(line, 30), null);
+ });
+
+ it("prefers an OSC 8 target over a URL-like label", () => {
+ const line = link("https://target.example", "https://label.example");
+ assert.strictEqual(urlAtColumn(line, 10), "https://target.example");
+ });
+
+ it("resolves a link after its painted tab expansion", () => {
+ const line = ` ${link("https://example.com", "docs")}`;
+ assert.strictEqual(hyperlinkAtColumn(line, 2), null);
+ assert.strictEqual(hyperlinkAtColumn(line, 3), "https://example.com");
+ assert.strictEqual(hyperlinkAtColumn(line, 6), "https://example.com");
+ });
+
it("counts wide graphemes as two columns", () => {
const line = `\u4f60\u597d ${link("https://example.com", "docs")}`;
assert.strictEqual(hyperlinkAtColumn(line, 4), null);