Shift+Enter newline, OAuth URL truncation, and the auth bridge toggle
Three fixes that all land on the same journey: sign in, paste a prompt, and have the terminal behave the way every other Claude Code host does. Shift+Enter inserts a newline ----------------------------- xterm.js does not consult `shiftKey` for Enter (`Keyboard.ts`, case 13), so Shift+Enter was byte-identical to Enter and submitted the prompt. Both terminals now send `\x1b\r` (ESC+CR) instead, which Claude Code parses as return+meta — the same bytes its own `/terminal-setup` writes into the VS Code, Cursor, Alacritty and Zed keymaps, so this is in-band rather than a guess. Not `\n`: Claude Code accepts it, but a shell would run the line, so the two session types would diverge. Bound in Claude sessions only for that reason. `entrypoint.sh` sets `shiftEnterKeyBindingInstalled` in `~/.claude.json` so the CLI stops printing its "run /terminal-setup" tip. Purely cosmetic — the decoding is unconditional either way. Alt+Enter has always done the same thing (xterm ESC-prefixes on altKey) and was simply never documented. It is now, along with the rest. OAuth login URL truncation -------------------------- Two producers wrote one toast slot, last-writer-wins. The OSC 7777 relay delivers the URL base64-encoded and therefore exact; ~300 ms later the screen-scraper's debounce fired and overwrote it with a truncated guess at the same link — a URL that parses, points at the right host, and authorises nothing. The user is the one who has to notice. Why the scraper truncated: `ANSI_RE` strips OSC sequences wholesale, including the OSC 8 hyperlink whose parameter carries the complete URL. Claude Code slices the *visible* text of that hyperlink to the terminal width while every emission carries the whole URL in its parameter. The backend already knew this (`commands/auth_token_commands.rs`); the frontend did not. - `urlDetector` now reads OSC 8 targets out of the raw buffer before stripping, filtered by a port of `usable_sign_in_link`, and tags every candidate with its provenance. - The prompt slot gained `supersedes`: better provenance always wins, worse never does, and between equals only a candidate that *extends* what is showing may replace it. That last rule is `extendsUrl`, factored out of `pickSignInUrl` rather than copied — same rule, same reason, one implementation. - `flatten` splits on a bare `\r` as well as on `\r?\n`, so a `\r`-repainted TUI frame no longer inflates a line past the width and suppresses a join that should have happened; and the width is now sampled at `feed()` rather than read at `scan()`, so a resize inside the 300 ms debounce cannot reassemble 80-column text against a 120-column rule. Also corrects the comment claiming `acquire_claude_token` enables the auth bridge. It deliberately does not, and the module comment in `auth_token_commands.rs` explains at length why not. The auth bridge toggle ---------------------- `setAuthBridgeEnabled` and `getAuthBridgeStatus` had zero call sites: the Rust was complete, the IPC wrapper shipped, and there was nowhere to click — so the docs told users to "enable the Auth Bridge" for a switch that did not exist. `AuthBridgeRow` is that switch, in Config → Runtime. It deliberately does not go through the tab's stopped-only save: the dedicated command exists so the bridge can be flipped while a login is hanging in a running container, which is the only moment anyone reaches for it. It also subscribes to `auth-bridge-changed`, which the poller has been emitting to nobody — so a host port the bridge could not take was a completely silent failure, indistinguishable from a login that hung. `tunnel.rs` promotes the best-effort `::1` bind failure from debug to a warning recorded on the port. Half-bound is the failure mode that looks like success: the status says bridged, and a client that resolves `localhost` to `::1` without falling back is still refused. Finally, for a recognised Anthropic sign-in URL the toast now leads with "In container" and demotes the host "Open". The callback listener is inside the container, so the container-side browser closes the loop with no host round trip and no auth bridge; the host button stays as the fallback. Ordinary URLs are unchanged. Tests: 402 frontend (was 359), 285 Rust (unchanged). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GBq2rGum6GX7xXgsas1fDc
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
||||
import { UrlDetector, flatten } from "./urlDetector";
|
||||
import { UrlDetector, flatten, osc8Targets, usableLink } from "./urlDetector";
|
||||
import type { UrlSource } from "./urlDetector";
|
||||
|
||||
const COLS = 80;
|
||||
const enc = new TextEncoder();
|
||||
@@ -17,6 +18,34 @@ function ptyWrap(text: string, cols = COLS): string {
|
||||
return lines.join("\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* One OSC 8 hyperlink emission: the whole URL in the parameter, a slice of it
|
||||
* as visible text.
|
||||
*
|
||||
* This is what `claude setup-token` actually prints — measured against 2.1.226,
|
||||
* a 346-character URL arrives as five of these, each carrying the complete URL
|
||||
* and 80 characters of it on screen.
|
||||
*/
|
||||
function osc8(uri: string, visible: string): string {
|
||||
return `\x1b]8;;${uri}\x07${visible}\x1b]8;;\x07`;
|
||||
}
|
||||
|
||||
/** Slice `uri` into `width`-character visible pieces, each a full hyperlink. */
|
||||
function slicedHyperlink(uri: string, width = COLS): string {
|
||||
const parts: string[] = [];
|
||||
for (let i = 0; i < uri.length; i += width) {
|
||||
parts.push(osc8(uri, uri.slice(i, i + width)));
|
||||
}
|
||||
return parts.join("\r\n");
|
||||
}
|
||||
|
||||
/** The URL Claude Code prints, at the length it really is. */
|
||||
const SIGN_IN_URL =
|
||||
"https://claude.ai/oauth/authorize?code=true&client_id=9d1c250a-e61b-44d9-88ed-5944d1962f5e" +
|
||||
"&response_type=code&redirect_uri=https%3A%2F%2Fconsole.anthropic.com%2Foauth%2Fcode%2Fcallback" +
|
||||
"&scope=org%3Acreate_api_key+user%3Aprofile+user%3Ainference&code_challenge=" +
|
||||
"vJ8Kq2mN4pR7sT9wX1zA3bC5dE6fG8hJ0kL2mN4pQ6r&code_challenge_method=S256&state=aB3dE5gH7jK9";
|
||||
|
||||
beforeEach(() => vi.useFakeTimers());
|
||||
afterEach(() => vi.useRealTimers());
|
||||
|
||||
@@ -116,3 +145,166 @@ describe("UrlDetector", () => {
|
||||
expect(seen).toEqual([url]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("usableLink", () => {
|
||||
// Ports `usable_sign_in_link` from `commands/auth_token_commands.rs` — a junk
|
||||
// filter, not the security decision. `sanitizeRelayUrl` is still what stands
|
||||
// between any of this and `openUrl`.
|
||||
it("accepts an ordinary authorize URL", () => {
|
||||
expect(usableLink(SIGN_IN_URL)).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects a scheme that is not http(s)", () => {
|
||||
expect(usableLink("file:///etc/passwd")).toBe(false);
|
||||
expect(usableLink("javascript:alert(1)")).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects anything outside printable ASCII", () => {
|
||||
// A control character is how a URL is smuggled past a display, and
|
||||
// `new URL()` strips some of them silently.
|
||||
expect(usableLink("https://example.com/\u0000x")).toBe(false);
|
||||
expect(usableLink("https://exa\u200bmple.com/x")).toBe(false);
|
||||
expect(usableLink("https://example.com/a b")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("osc8Targets", () => {
|
||||
it("lifts the whole URL out of a sliced emission", () => {
|
||||
const raw = slicedHyperlink(SIGN_IN_URL);
|
||||
// Every piece carries the complete URL, however little of it is on screen.
|
||||
expect(new Set(osc8Targets(raw))).toEqual(new Set([SIGN_IN_URL]));
|
||||
});
|
||||
|
||||
it("ignores the closing half of a hyperlink", () => {
|
||||
expect(osc8Targets("\x1b]8;;\x07")).toEqual([]);
|
||||
});
|
||||
|
||||
it("ignores other OSCs, including the URL relay's own", () => {
|
||||
expect(osc8Targets("\x1b]0;a window title\x07")).toEqual([]);
|
||||
expect(osc8Targets("\x1b]7777;open;aHR0cHM6Ly9leGFtcGxlLmNvbQ==\x07")).toEqual([]);
|
||||
});
|
||||
|
||||
it("reads a hyperlink terminated by ST as well as by BEL", () => {
|
||||
expect(osc8Targets(`\x1b]8;id=1;${SIGN_IN_URL}\x1b\\text`)).toEqual([SIGN_IN_URL]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("UrlDetector — OSC 8", () => {
|
||||
it("recovers the complete URL from a sliced hyperlink", () => {
|
||||
// The bug this branch exists for. `ANSI_RE` strips OSC sequences wholesale,
|
||||
// so the scraper never saw the parameter and reassembled the *visible*
|
||||
// pieces instead — a URL that parses, points at claude.ai, and cannot
|
||||
// authorise anything.
|
||||
const seen: [string, UrlSource][] = [];
|
||||
const d = new UrlDetector((u, src) => seen.push([u, src]), () => COLS);
|
||||
|
||||
feed(d, "Open this link to sign in:\r\n" + slicedHyperlink(SIGN_IN_URL) + "\r\ndone\r\n");
|
||||
|
||||
expect(seen[0]).toEqual([SIGN_IN_URL, "osc8"]);
|
||||
});
|
||||
|
||||
it("does not emit the same hyperlink again when it is repainted", () => {
|
||||
const seen: [string, UrlSource][] = [];
|
||||
const d = new UrlDetector((u, s) => seen.push([u, s]), () => COLS);
|
||||
|
||||
feed(d, slicedHyperlink(SIGN_IN_URL) + "\r\n");
|
||||
feed(d, slicedHyperlink(SIGN_IN_URL) + "\r\n");
|
||||
|
||||
expect(seen.filter(([u]) => u === SIGN_IN_URL)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("marks a scraped candidate as a guess, so the slot can refuse it", () => {
|
||||
// Nothing here decides precedence — that is `supersedes` in TerminalView —
|
||||
// but it is what makes the decision possible.
|
||||
const seen: [string, UrlSource][] = [];
|
||||
const d = new UrlDetector((u, s) => seen.push([u, s]), () => COLS);
|
||||
const url = "https://example.com/" + "z".repeat(120);
|
||||
|
||||
feed(d, url + "\r\nnext\r\n");
|
||||
|
||||
expect(seen).toEqual([[url, "heuristic"]]);
|
||||
});
|
||||
|
||||
it("ignores a short hyperlink", () => {
|
||||
// `ls --hyperlink` decorates every filename; none of that is a prompt.
|
||||
const seen: string[] = [];
|
||||
const d = new UrlDetector((u) => seen.push(u), () => COLS);
|
||||
|
||||
feed(d, osc8("https://example.com/a", "a") + "\r\nnext\r\n");
|
||||
|
||||
expect(seen).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("UrlDetector — repaints and resizes", () => {
|
||||
it("treats a bare CR as a line break", () => {
|
||||
// A TUI repaints by returning to column 0 without a line feed. Splitting on
|
||||
// `\r?\n` alone leaves a whole frame on one "line", which is then longer
|
||||
// than the width — so the `===` test says "not wrapped" and a break the
|
||||
// terminal really did insert is never rejoined.
|
||||
const seen: string[] = [];
|
||||
const d = new UrlDetector((u) => seen.push(u), () => COLS);
|
||||
const url = "https://example.com/" + "q".repeat(100);
|
||||
|
||||
feed(d, "spinner frame one\rspinner frame two\r" + ptyWrap(url) + "\r\ndone\r\n");
|
||||
|
||||
expect(seen).toEqual([url]);
|
||||
});
|
||||
|
||||
it("does not glue two repainted frames into one token", () => {
|
||||
const seen: string[] = [];
|
||||
const d = new UrlDetector((u) => seen.push(u), () => COLS);
|
||||
|
||||
feed(
|
||||
d,
|
||||
"https://example.com/" + "a".repeat(90) + "\rhttps://evil.tld/" + "b".repeat(90) + "\r\n\r\ndone\r\n",
|
||||
);
|
||||
|
||||
for (const url of seen) expect(new URL(url).host).not.toBe("example.comhttps");
|
||||
});
|
||||
|
||||
it("reassembles with the width the bytes were printed at, not the current one", () => {
|
||||
// The scan runs 300 ms after the print. A resize inside that window used to
|
||||
// change every join decision retroactively: text wrapped at 80 columns,
|
||||
// rejoined against a width of 120, comes back as separate lines glued with
|
||||
// spaces — or, the other way round, as a URL nobody printed.
|
||||
const seen: string[] = [];
|
||||
let cols = COLS;
|
||||
const d = new UrlDetector((u) => seen.push(u), () => cols);
|
||||
const url =
|
||||
"https://accounts.example.com/o/oauth2/auth?client_id=1234567890-abcdefghijklmnop.apps.example.com&redirect_uri=http%3A%2F%2Flocalhost%3A45678";
|
||||
|
||||
d.feed(new TextEncoder().encode(ptyWrap(url) + "\r\nWaiting…\r\n"));
|
||||
cols = 120; // the user drags the window wider before the debounce fires
|
||||
vi.advanceTimersByTime(2000);
|
||||
|
||||
expect(seen).toEqual([url]);
|
||||
});
|
||||
|
||||
it("drops text buffered at a width that no longer applies", () => {
|
||||
// Half printed at 80, half at 120: no single width reassembles both, so the
|
||||
// older half goes rather than being joined by a rule that is wrong for it.
|
||||
const seen: string[] = [];
|
||||
let cols = COLS;
|
||||
const d = new UrlDetector((u) => seen.push(u), () => cols);
|
||||
const url = "https://example.com/" + "m".repeat(120);
|
||||
|
||||
d.feed(new TextEncoder().encode(ptyWrap(url.slice(0, 100))));
|
||||
cols = 120;
|
||||
feed(d, url.slice(100) + "\r\ndone\r\n");
|
||||
|
||||
// Whatever survives, it is never a URL that was not printed.
|
||||
for (const u of seen) expect(url.startsWith(u) || u.startsWith(url)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("flatten — bare CR", () => {
|
||||
it("splits on a lone CR as well as on LF", () => {
|
||||
expect(flatten("abcde\rfghij", 5)).toBe("abcdefghij");
|
||||
expect(flatten("abc\rdef", 5)).toBe("abc def");
|
||||
});
|
||||
|
||||
it("counts CRLF as one break, not two", () => {
|
||||
expect(flatten("abcde\r\nfghij", 5)).toBe("abcdefghij");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user