From 70cf3763c7a9df9512ed8793544d3cbcad95ea9e Mon Sep 17 00:00:00 2001 From: Ehab Younes Date: Thu, 3 Dec 2026 15:19:28 +0000 Subject: [PATCH 1/2] fix(remote): support Cursor's Remote-SSH port and label Find the SSH port in anysphere.remote-ssh 1.1.5+ logs, ignoring its connection report, and register the label formatter authority as a one-choice brace group so it outranks Cursor's longer pattern. --- CHANGELOG.md | 5 ++ src/remote/labelFormatter.ts | 11 +++ src/remote/remote.ts | 5 +- src/remote/sshProcess.ts | 24 ++---- test/unit/remote/labelFormatter.test.ts | 27 +++++++ test/unit/remote/sshProcess.test.ts | 97 +++++++++++++++---------- 6 files changed, 110 insertions(+), 59 deletions(-) create mode 100644 src/remote/labelFormatter.ts create mode 100644 test/unit/remote/labelFormatter.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index cca6458598..d7401f6eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,11 @@ into Windows Server 2019, when `HOME` points somewhere other than your user profile, and with every Windows OpenSSH version when `HOME` contains non-ASCII characters. +- In Cursor with its Remote-SSH extension 1.1.5 or later, the status bar shows the + workspace connection's latency. +- In Cursor, and for deployments at an IPv6 address in every editor, the window + title and recent folders label Coder workspaces as `Coder: owner∕workspace` + instead of Remote-SSH's `SSH` label. ## [v1.18.3](https://github.com/coder/vscode-coder/releases/tag/v1.18.3) 2026-11-25 diff --git a/src/remote/labelFormatter.ts b/src/remote/labelFormatter.ts new file mode 100644 index 0000000000..bc31a6050f --- /dev/null +++ b/src/remote/labelFormatter.ts @@ -0,0 +1,11 @@ +/** + * VS Code labels with the longest matching authority glob, and Cursor's Remote-SSH + * registers `*`, so SSH windows get a longer brace glob. Nested (dev + * container) windows keep the exact authority so their labels don't change. + */ +export function labelFormatterAuthority(remoteAuthority: string): string { + if (!remoteAuthority.startsWith("ssh-remote+")) { + return remoteAuthority; + } + return `{${remoteAuthority.replace(/[[\]*?]/g, "[$&]")}}`; +} diff --git a/src/remote/remote.ts b/src/remote/remote.ts index 5b6fcafddd..685684f905 100644 --- a/src/remote/remote.ts +++ b/src/remote/remote.ts @@ -64,6 +64,7 @@ import { SESSION_TYPE_ENV, SSH_PROXY_SETTINGS, } from "./environment"; +import { labelFormatterAuthority } from "./labelFormatter"; import { migrateAuthToSecretsStorage } from "./migration"; import { getGitForWindowsSshConfigPath, @@ -1180,9 +1181,7 @@ export class Remote { // under the key "memento/cachedResourceLabelFormatters2". return vscodeProposed.workspace.registerResourceLabelFormatter({ scheme: "vscode-remote", - // authority is optional but VS Code prefers formatters that most - // accurately match the requested authority, so we include it. - authority: remoteAuthority, + authority: labelFormatterAuthority(remoteAuthority), formatting: { label: "${path}", separator: "/", diff --git a/src/remote/sshProcess.ts b/src/remote/sshProcess.ts index 879840f073..95080ad689 100644 --- a/src/remote/sshProcess.ts +++ b/src/remote/sshProcess.ts @@ -549,9 +549,10 @@ async function findSshLogInDir(dirPath: string): Promise { // Regex patterns to find the SSH port from Remote SSH extension logs. // `ms-vscode-remote.remote-ssh`: `-> socksPort ->` or `between local port ` // `codeium.windsurf-remote-openssh`, `jeanp413.open-remote-ssh`, `google.antigravity-remote-openssh`: `=> (socks) =>` -// `anysphere.remote-ssh`: `Socks port: ` +// `anysphere.remote-ssh`: `Socks port: `, or in 1.1+ the `-D`/`-L` port of the logged ssh command +// that pipes in `cursor_remote_install_*`, which the connection report's command does not const RemoteSSHLogPortRegex = - /(?:-> socksPort (\d+) ->|between local port (\d+)|=> (\d+)\(socks\) =>|Socks port: (\d+))/g; + /(?:-> socksPort (\d+) ->|between local port (\d+)|=> (\d+)\(socks\) =>|Socks port: (\d+)|Launching SSH server via shell with command: [^\n]*?cursor_remote_install_[^\n]*? -(?:D (\d+)|L "127\.0\.0\.1:(\d+):))/g; /** * Given the contents of a Remote - SSH log file, find the most recent port @@ -561,20 +562,7 @@ const RemoteSSHLogPortRegex = * Returns null if no port is found. */ export function findPort(text: string): number | null { - const allMatches = [...text.matchAll(RemoteSSHLogPortRegex)]; - if (allMatches.length === 0) { - return null; - } - - // Get the last match, which is the most recent port. - const lastMatch = allMatches[allMatches.length - 1]; - // Each capture group corresponds to a different Remote SSH extension log format: - // [0] full match, [1] and [2] ms-vscode-remote.remote-ssh, - // [3] devin/windsurf/open-remote-ssh/antigravity, [4] anysphere.remote-ssh - const portStr = lastMatch[1] || lastMatch[2] || lastMatch[3] || lastMatch[4]; - if (!portStr) { - return null; - } - - return Number.parseInt(portStr); + const lastMatch = [...text.matchAll(RemoteSSHLogPortRegex)].at(-1); + const port = lastMatch?.slice(1).find((group) => group !== undefined); + return port ? Number.parseInt(port) : null; } diff --git a/test/unit/remote/labelFormatter.test.ts b/test/unit/remote/labelFormatter.test.ts new file mode 100644 index 0000000000..c003ab6579 --- /dev/null +++ b/test/unit/remote/labelFormatter.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from "vitest"; + +import { labelFormatterAuthority } from "@/remote/labelFormatter"; + +describe("labelFormatterAuthority", () => { + interface AuthorityCase { + name: string; + authority: string; + expected: string; + } + it.each([ + { + name: "brackets an IPv6 SSH host inside braces", + authority: "ssh-remote+coder-vscode.https_[::1]_8080--foo--bar", + expected: "{ssh-remote+coder-vscode.https_[[]::1[]]_8080--foo--bar}", + }, + { + name: "keeps a nested dev container authority", + authority: + "dev-container+7b7d@ssh-remote+coder-vscode.dev.coder.com--foo--bar", + expected: + "dev-container+7b7d@ssh-remote+coder-vscode.dev.coder.com--foo--bar", + }, + ])("$name", ({ authority, expected }) => { + expect(labelFormatterAuthority(authority)).toBe(expected); + }); +}); diff --git a/test/unit/remote/sshProcess.test.ts b/test/unit/remote/sshProcess.test.ts index 490adf6972..e41e6c4e84 100644 --- a/test/unit/remote/sshProcess.test.ts +++ b/test/unit/remote/sshProcess.test.ts @@ -1080,44 +1080,65 @@ function waitForEvent( } describe("findPort", () => { - it.each([[""], ["some random log text without ports"]])( - "returns null for <%s>", - (input) => { - expect(findPort(input)).toBe(null); + const host = "coder-vscode.example.com--alice--dev"; + const cursorReport = `2026-12-03 10:40:00.000 [info] Launching SSH server via shell with command: cat "/home/alice/.cursor/extensions/anysphere.remote-ssh-1.1.19/dist/scripts/connectionReport.sh" | ssh -T -D 50999 ${host} bash --login -c bash`; + const windsurfLaunch = `[info] Launching SSH server with command: ssh -v -T -D 50999 ${host} bash -s`; + + interface PortCase { + name: string; + log: string; + port: number | null; + } + // Multi-line logs hold a connection and a reconnect; the reconnect's port wins. + it.each([ + { name: "an empty log", log: "", port: null }, + { name: "Cursor's connection report", log: cursorReport, port: null }, + { name: "a Windsurf launch command", log: windsurfLaunch, port: null }, + { + name: "ms-vscode-remote.remote-ssh 0.129", + log: `[10:30:41.200] Starting forwarding server. local port 50001 -> socksPort 50000 -> remotePort 40000 +[10:35:00.000] Spawned SSH tunnel between local port 50100 and remote target socket /run/user/1000/code.sock`, + port: 50100, }, - ); - - it.each([ - [ - "ms-vscode-remote.remote-ssh", - "[10:30:45] SSH established -> socksPort 12345 -> ready", - 12345, - ], - [ - "ms-vscode-remote.remote-ssh[2]", - "Forwarding between local port 54321 and remote", - 54321, - ], - [ - "devin/open-remote-ssh/antigravity", - "[INFO] Connection => 9999(socks) => target", - 9999, - ], - [ - "anysphere.remote-ssh", - "[DEBUG] Initialized Socks port: 8888 proxy", - 8888, - ], - ])("finds port from %s log format", (_name, input, expected) => { - expect(findPort(input)).toBe(expected); - }); - - it("returns most recent port when multiple matches exist", () => { - const log = ` -[10:30:00] Starting connection -> socksPort 1111 -> initialized -[10:30:05] Reconnecting => 2222(socks) => retry -[10:30:10] Final connection Socks port: 3333 established - `; - expect(findPort(log)).toBe(3333); + { + name: "jeanp413.open-remote-ssh", + log: `[Trace - 10:30:41.200] Creating forwarding server 50001(local) => 50000(socks) => 40000(remote) +[Trace - 10:35:00.000] Creating forwarding server 50101(local) => 50100(socks) => 40000(remote)`, + port: 50100, + }, + { + name: "windsurf-remote-openssh and antigravity-remote-openssh", + log: `[info] Launching SSH server with command: ssh -v -T -D 50000 ${host} bash -s +[info] SSH askpass server listening on local port: 50002 +[info] Creating forwarding server 50001(local) => 50000(socks) => 40000(remote) +[info] Launching SSH server with command: ssh -v -T -D 50100 ${host} bash -s +[info] Creating forwarding server 50101(local) => 50100(socks) => 40000(remote)`, + port: 50100, + }, + { + name: "anysphere.remote-ssh 1.0.32", + log: `2026-12-03 10:30:40.000 [info] Launching SSH server via shell with command: cat "/tmp/cursor_remote_install_0b1c.sh" | ssh -T -D 50000 ${host} bash --login -c bash +2026-12-03 10:30:41.000 [info] [remote-ssh] Resolved exec server. Socks port: 50000 +2026-12-03 10:35:00.000 [info] Launching SSH server via shell with command: cat "/tmp/cursor_remote_install_0b1c.sh" | ssh -T -D 50100 ${host} bash --login -c bash +2026-12-03 10:35:01.000 [info] [remote-ssh] Resolved authority: {"host":"127.0.0.1","port":50101}. Socks port: 50100 +${cursorReport}`, + port: 50100, + }, + { + name: "anysphere.remote-ssh 1.1.19 SOCKS transport", + log: `2026-12-03 10:30:40.000 [info] Launching SSH server via shell with command: cat "/tmp/cursor_remote_install_0b1c.sh" | ssh -T -F "/home/alice/.ssh/config" -D 50000 ${host} bash --login -c bash +2026-12-03 10:30:40.001 [info] Establishing SSH connection: cat "/tmp/cursor_remote_install_0b1c.sh" | ssh -T -F "/home/alice/.ssh/config" -D 50000 ${host} bash --login -c bash +2026-12-03 10:35:00.000 [info] Launching SSH server via shell with command: cat "/tmp/cursor_remote_install_0b1c.sh" | ssh -T -F "/home/alice/.ssh/config" -D 50100 ${host} bash --login -c bash +${cursorReport}`, + port: 50100, + }, + { + name: "anysphere.remote-ssh 1.1.19 socket transport on Windows", + log: `2026-12-03 10:30:40.000 [info] Launching SSH server via shell with command: type "C:\\Users\\alice\\AppData\\Local\\Temp\\cursor_remote_install_0b1c.sh" | ssh -T -o ExitOnForwardFailure=yes -L "127.0.0.1:50000:/run/user/1000/code.sock" -L "127.0.0.1:50001:/run/user/1000/mux.sock" ${host} bash --login -c bash +2026-12-03 10:35:00.000 [info] Launching SSH server via shell with command: type "C:\\Users\\alice\\AppData\\Local\\Temp\\cursor_remote_install_0b1c.sh" | ssh -T -o ExitOnForwardFailure=yes -L "127.0.0.1:50100:/run/user/1000/code.sock" -L "127.0.0.1:50101:/run/user/1000/mux.sock" ${host} bash --login -c bash`, + port: 50100, + }, + ])("finds port $port in $name", ({ log, port }) => { + expect(findPort(log)).toBe(port); }); }); From 7b960631968ba391ae0a462ddcd87f7ecd7de28b Mon Sep 17 00:00:00 2001 From: Ehab Younes Date: Thu, 3 Dec 2026 15:19:28 +0000 Subject: [PATCH 2/2] refactor(remote): split the SSH port regex into one pattern per log line --- src/remote/sshProcess.ts | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/remote/sshProcess.ts b/src/remote/sshProcess.ts index 95080ad689..f145cf3008 100644 --- a/src/remote/sshProcess.ts +++ b/src/remote/sshProcess.ts @@ -546,13 +546,19 @@ async function findSshLogInDir(dirPath: string): Promise { return remoteSshLog ? path.join(dirPath, remoteSshLog) : undefined; } -// Regex patterns to find the SSH port from Remote SSH extension logs. -// `ms-vscode-remote.remote-ssh`: `-> socksPort ->` or `between local port ` -// `codeium.windsurf-remote-openssh`, `jeanp413.open-remote-ssh`, `google.antigravity-remote-openssh`: `=> (socks) =>` -// `anysphere.remote-ssh`: `Socks port: `, or in 1.1+ the `-D`/`-L` port of the logged ssh command -// that pipes in `cursor_remote_install_*`, which the connection report's command does not -const RemoteSSHLogPortRegex = - /(?:-> socksPort (\d+) ->|between local port (\d+)|=> (\d+)\(socks\) =>|Socks port: (\d+)|Launching SSH server via shell with command: [^\n]*?cursor_remote_install_[^\n]*? -(?:D (\d+)|L "127\.0\.0\.1:(\d+):))/g; +/** Lines each Remote-SSH extension logs with the SSH process's local port. */ +const REMOTE_SSH_PORT_PATTERNS: readonly RegExp[] = [ + // ms-vscode-remote.remote-ssh + /-> socksPort (?\d+) ->/g, + /between local port (?\d+)/g, + // codeium.windsurf-remote-openssh, jeanp413.open-remote-ssh, google.antigravity-remote-openssh + /=> (?\d+)\(socks\) =>/g, + // anysphere.remote-ssh before 1.1.5 + /Socks port: (?\d+)/g, + // anysphere.remote-ssh 1.1.5+: the connection's ssh command, which pipes in + // the install script (its connection report command does not) + /Launching SSH server via shell with command: [^\n]*?cursor_remote_install_[^\n]*? -(?:D |L "127\.0\.0\.1:)(?\d+)/g, +]; /** * Given the contents of a Remote - SSH log file, find the most recent port @@ -562,7 +568,14 @@ const RemoteSSHLogPortRegex = * Returns null if no port is found. */ export function findPort(text: string): number | null { - const lastMatch = [...text.matchAll(RemoteSSHLogPortRegex)].at(-1); - const port = lastMatch?.slice(1).find((group) => group !== undefined); - return port ? Number.parseInt(port) : null; + let latest: { index: number; port: number } | undefined; + for (const pattern of REMOTE_SSH_PORT_PATTERNS) { + for (const match of text.matchAll(pattern)) { + const port = match.groups?.port; + if (port && (latest === undefined || match.index > latest.index)) { + latest = { index: match.index, port: Number.parseInt(port) }; + } + } + } + return latest?.port ?? null; }