Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(tui): keep connection sign-in links clickable when they wrap (#4422)

Rui7f559acda730
diff --git a/.changeset/tui-auth-url-hyperlink.md b/.changeset/tui-auth-url-hyperlink.md
new file mode 100644
index 000000000..9c10f12b2
--- /dev/null
+++ b/.changeset/tui-auth-url-hyperlink.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+The TUI now prints a connection sign-in URL on its own line and makes every wrapped row an OSC 8 hyperlink to the full URL, so Cmd-clicking the link opens the whole URL in a narrow terminal.
diff --git a/packages/eve/src/cli/dev/tui/blocks.test.ts b/packages/eve/src/cli/dev/tui/blocks.test.ts
index ab6fa3b11..4fa5ed2a5 100644
--- a/packages/eve/src/cli/dev/tui/blocks.test.ts
+++ b/packages/eve/src/cli/dev/tui/blocks.test.ts
@@ -13,6 +13,29 @@ function render(block: DisplayBlock, width = 60): string[] {
}
describe("renderBlockLines", () => {
+ it("links every wrapped row of a connection-auth URL to the full URL", () => {
+ const url = `https://auth.example.com/authorize?client_id=abc&redirect_uri=${"x".repeat(160)}`;
+ const raw = renderBlockLines(
+ {
+ kind: "connection-auth",
+ title: "Catalog · authorization · required",
+ body: `Sign in to Catalog\nOpen to authorize:\n${url}`,
+ link: url,
+ preformatted: true,
+ },
+ 100,
+ theme,
+ ctx,
+ );
+ const urlRows = raw.filter((row) => row.includes("\x1b]8;;"));
+ expect(urlRows.length).toBeGreaterThan(1);
+ for (const row of urlRows) {
+ expect(row).toContain(`\x1b]8;;${url}\x1b\\`);
+ expect(visibleLength(row)).toBeLessThanOrEqual(100);
+ }
+ expect(urlRows.map((row) => stripAnsi(row).trim()).join("")).toBe(url);
+ expect(raw.map(stripAnsi)).toContain(" Open to authorize:");
+ });
it("colors only classified failures red, warnings yellow, and raw stderr neutral", () => {
const colored = createTheme({ color: true, unicode: true });
const body = (logLevel?: "error" | "warn") =>
diff --git a/packages/eve/src/cli/dev/tui/blocks.ts b/packages/eve/src/cli/dev/tui/blocks.ts
index 54a564230..7c772bce2 100644
--- a/packages/eve/src/cli/dev/tui/blocks.ts
+++ b/packages/eve/src/cli/dev/tui/blocks.ts
@@ -10,7 +10,7 @@
* given width, so the live region can place rows verbatim.
*/
-import { renderMarkdown } from "./markdown.js";
+import { renderMarkdown, renderHyperlink } from "./markdown.js";
import type { ToolDetailLine } from "./line-diff.js";
import type { TaskKind } from "./task-activity.js";
import type { Theme } from "./theme.js";
@@ -91,6 +91,12 @@ export interface Block {
* (stopped) mark it ending.
*/
status?: ToolStatus;
+ /**
+ * Connection-auth only: the sign-in URL. Its body row is hard-wrapped like
+ * any other, but every wrapped row is an OSC 8 hyperlink to this full URL,
+ * so Cmd-click opens the whole link whatever the terminal width.
+ */
+ link?: string;
/** When true, treat `body` as pre-styled and only wrap + indent it. */
preformatted?: boolean;
/** Reasoning only: collapse the trace to a single "thinking" line. */
@@ -474,8 +480,9 @@ function renderPreformatted(block: Block, width: number, theme: Theme): string[]
index === 0 ? `${glyph} ${theme.colors.bold(line)}` : ` ${theme.colors.bold(line)}`,
);
for (const raw of (block.body ?? "").split("\n")) {
+ const isLink = block.link !== undefined && raw === block.link;
for (const line of wrapVisibleLine(raw, Math.max(1, width - bodyIndent.length))) {
- rows.push(`${bodyIndent}${line}`);
+ rows.push(`${bodyIndent}${isLink ? renderHyperlink(line, raw) : line}`);
}
}
return rows;
diff --git a/packages/eve/src/cli/dev/tui/markdown.ts b/packages/eve/src/cli/dev/tui/markdown.ts
index 888e2fe51..f9c7edc2e 100644
--- a/packages/eve/src/cli/dev/tui/markdown.ts
+++ b/packages/eve/src/cli/dev/tui/markdown.ts
@@ -255,6 +255,14 @@ function renderInlineToken(token: Token, options: InlineOptions): string {
}
}
+/**
+ * Wraps `label` in an OSC 8 hyperlink to `href`, underlined. Terminals
+ * without OSC 8 show the plain label. Unsafe hrefs return the label as-is.
+ */
+export function renderHyperlink(label: string, href: string): string {
+ return renderLink(label, href);
+}
+
function renderLink(label: string, href: string, restoreUnderline = false): string {
if (!isSafeLinkUrl(href)) return label;
const restore = restoreUnderline ? ansi.underline : "";
diff --git a/packages/eve/src/cli/dev/tui/transcript-parts.ts b/packages/eve/src/cli/dev/tui/transcript-parts.ts
index f63861c92..ed51f935f 100644
--- a/packages/eve/src/cli/dev/tui/transcript-parts.ts
+++ b/packages/eve/src/cli/dev/tui/transcript-parts.ts
@@ -410,15 +410,21 @@ export function authorizationTerminalMessage(state: string): string | undefined
export function formatAuthorization(
part: EveAuthorizationPart,
terminalMessage: string | undefined,
-): string {
+): { body: string; link?: string } {
const lines: string[] = [];
+ let link: string | undefined;
if (terminalMessage !== undefined) {
lines.push(terminalMessage);
} else {
const description = stripTerminalControls(part.description);
if (description.length > 0) lines.push(description);
const challenge = part.authorization;
- if (challenge?.url) lines.push(`URL: ${stripTerminalControls(challenge.url)}`);
+ // The URL gets a row of its own; returning it as `link` (the block's
+ // `Block.link`) lets the renderer hyperlink every wrapped row to it.
+ if (challenge?.url) {
+ link = stripTerminalControls(challenge.url);
+ lines.push("Open to authorize:", link);
+ }
if (challenge?.userCode) lines.push(`Code: ${stripTerminalControls(challenge.userCode)}`);
if (challenge?.expiresAt) lines.push(`Expires: ${stripTerminalControls(challenge.expiresAt)}`);
if (challenge?.instructions) lines.push(stripTerminalControls(challenge.instructions));
@@ -427,7 +433,8 @@ export function formatAuthorization(
const reason = stripTerminalControls(part.reason);
if (reason.length > 0) lines.push(`Reason: ${reason}`);
}
- return lines.join("\n");
+ const body = lines.join("\n");
+ return link === undefined ? { body } : { body, link };
}
/** Reads the shared write-file result's `existed` flag, whatever the tool. */
diff --git a/packages/eve/src/cli/dev/tui/transcript.test.ts b/packages/eve/src/cli/dev/tui/transcript.test.ts
index 089951955..e338e7611 100644
--- a/packages/eve/src/cli/dev/tui/transcript.test.ts
+++ b/packages/eve/src/cli/dev/tui/transcript.test.ts
@@ -27,7 +27,8 @@ import {
type MessageStreamEvent,
type UnstampedMessageStreamEvent,
} from "#protocol/message.js";
-import type { Block } from "./blocks.js";
+import { type Block, renderBlockLines } from "./blocks.js";
+import { createTheme } from "./theme.js";
import { tuiSessionReducer, type AgentTUIConversationView } from "./conversation-view.js";
import { ConversationTranscript, turnActivity, type TranscriptOptions } from "./transcript.js";
@@ -757,6 +758,31 @@ describe("ConversationTranscript", () => {
]);
});
+ it("hyperlinks every wrapped row of a pending authorization URL to the full URL", () => {
+ const url = `https://idp.example.com/authorize?redirect_uri=${"x".repeat(160)}`;
+ const state = conversation([
+ turn,
+ event(
+ createAuthorizationRequiredEvent({
+ attemptId: "attempt_1",
+ authorization: { displayName: "Linear", url },
+ description: "Connect Linear",
+ name: "linear",
+ sequence: 1,
+ stepIndex: 0,
+ turnId: "turn_1",
+ webhookUrl: "https://agent.example.com/callback",
+ }),
+ ),
+ ]);
+ const [block] = new ConversationTranscript().project(view(state, true), options);
+ expect(block).toEqual(expect.objectContaining({ kind: "connection-auth", link: url }));
+ const theme = createTheme({ color: false, unicode: true });
+ const rows = renderBlockLines(block!, 100, theme, { activityPulse: "▪" });
+ const linked = rows.filter((row) => row.includes(`\x1b]8;;${url}\x1b\\`));
+ expect(linked.length).toBeGreaterThan(1);
+ });
+
it("keeps an optimistic message's block when the server confirms it", () => {
const transcript = new ConversationTranscript();
const optimistic = conversation([
diff --git a/packages/eve/src/cli/dev/tui/transcript.ts b/packages/eve/src/cli/dev/tui/transcript.ts
index 3e8f135f9..1674241cf 100644
--- a/packages/eve/src/cli/dev/tui/transcript.ts
+++ b/packages/eve/src/cli/dev/tui/transcript.ts
@@ -551,7 +551,7 @@ export class ConversationTranscript {
return {
kind: "connection-auth",
title: `${stripTerminalControls(part.displayName)} · authorization · ${state}`,
- body: formatAuthorization(part, terminalMessage),
+ ...formatAuthorization(part, terminalMessage),
preformatted: true,
live: terminalMessage === undefined,
};
diff --git a/packages/eve/test/tui-client/tui-connection-auth-states.ts b/packages/eve/test/tui-client/tui-connection-auth-states.ts
index 2ecfb04b0..bcb87df5f 100644
--- a/packages/eve/test/tui-client/tui-connection-auth-states.ts
+++ b/packages/eve/test/tui-client/tui-connection-auth-states.ts
@@ -181,7 +181,7 @@ void (async () => {
() => {
const snap = screen.snapshot();
return (
- snap.includes("URL: https://example.com/authorize/stub-mcp") &&
+ snap.includes("https://example.com/authorize/stub-mcp") &&
snap.includes("Code: STUB-1234") &&
snap.includes("Visit the URL above")
);
@@ -210,7 +210,7 @@ void (async () => {
return (
snap.includes("Authorization complete") &&
!snap.includes("Authorization required for stub-mcp") &&
- !snap.includes("URL: https://example.com/authorize/stub-mcp") &&
+ !snap.includes("https://example.com/authorize/stub-mcp") &&
!snap.includes("Code: STUB-1234") &&
!snap.includes("Visit the URL above")
);