Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/remote/labelFormatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* VS Code labels with the longest matching authority glob, and Cursor's Remote-SSH
* registers `<authority>*`, 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, "[$&]")}}`;
}
5 changes: 2 additions & 3 deletions src/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
SESSION_TYPE_ENV,
SSH_PROXY_SETTINGS,
} from "./environment";
import { labelFormatterAuthority } from "./labelFormatter";
import { migrateAuthToSecretsStorage } from "./migration";
import {
getGitForWindowsSshConfigPath,
Expand Down Expand Up @@ -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: "/",
Expand Down
43 changes: 22 additions & 21 deletions src/remote/sshProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,19 @@ async function findSshLogInDir(dirPath: string): Promise<string | undefined> {
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 <port> ->` or `between local port <port>`
// `codeium.windsurf-remote-openssh`, `jeanp413.open-remote-ssh`, `google.antigravity-remote-openssh`: `=> <port>(socks) =>`
// `anysphere.remote-ssh`: `Socks port: <port>`
const RemoteSSHLogPortRegex =
/(?:-> socksPort (\d+) ->|between local port (\d+)|=> (\d+)\(socks\) =>|Socks port: (\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 (?<port>\d+) ->/g,
/between local port (?<port>\d+)/g,
// codeium.windsurf-remote-openssh, jeanp413.open-remote-ssh, google.antigravity-remote-openssh
/=> (?<port>\d+)\(socks\) =>/g,
// anysphere.remote-ssh before 1.1.5
/Socks port: (?<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:)(?<port>\d+)/g,
];

/**
* Given the contents of a Remote - SSH log file, find the most recent port
Expand All @@ -561,20 +568,14 @@ 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;
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 Number.parseInt(portStr);
return latest?.port ?? null;
}
27 changes: 27 additions & 0 deletions test/unit/remote/labelFormatter.test.ts
Original file line number Diff line number Diff line change
@@ -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<AuthorityCase>([
{
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);
});
});
97 changes: 59 additions & 38 deletions test/unit/remote/sshProcess.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,44 +1080,65 @@ function waitForEvent<T>(
}

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<PortCase>([
{ 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);
});
});
Loading