Skip to content

Commit 3c5cd90

Browse files
maria-rcksclaude
andcommitted
refactor(editors): shrink the Zed remote link change
Drop the link-style helper and the desktop scheme map: a `remoteScheme` entry plus one `editor === "zed"` branch in the link builder and one `zed:` branch in the shell allowlist cover the same behavior. The Zed branch bans userinfo in the host path segment, matching the rule the vscode-remote branch already applies. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
1 parent d3efb43 commit 3c5cd90

4 files changed

Lines changed: 32 additions & 61 deletions

File tree

‎apps/desktop/src/electron/ElectronShell.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ describe("ElectronShell", () => {
127127
electronShell.openExternal(
128128
"vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",
129129
),
130+
electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),
130131
]);
131132

132-
assert.deepEqual(results, [false, false]);
133+
assert.deepEqual(results, [false, false, false]);
133134
assert.equal(openExternalMock.mock.calls.length, 0);
134135
}).pipe(Effect.provide(ElectronShell.layer)),
135136
);

‎apps/desktop/src/electron/ElectronShell.ts‎

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {
22
REMOTE_CAPABLE_EDITOR_IDS,
3-
remoteLinkStyleForEditor,
43
remoteSchemeForEditor,
5-
type EditorRemoteLinkStyle,
64
type SystemSettingsPane,
75
} from "@t3tools/contracts";
86
import * as Context from "effect/Context";
@@ -26,38 +24,29 @@ const SYSTEM_SETTINGS_URLS: Record<SystemSettingsPane, string> = {
2624
"x-apple.systempreferences:com.apple.settings.PrivacySecurity.extension?Privacy_AllFiles",
2725
};
2826

29-
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…` and
27+
// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`,
3028
// `zed://ssh/<host>/<path>`) must reach the OS handler; every other non-web
31-
// scheme stays blocked. Each scheme only unlocks its own editor's link shape,
32-
// so a Zed link cannot ride in on a VS Code scheme or the reverse.
29+
// scheme stays blocked.
3330
const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);
34-
const REMOTE_EDITOR_PROTOCOLS = new Map<string, EditorRemoteLinkStyle>(
31+
const REMOTE_EDITOR_PROTOCOLS = new Set(
3532
REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {
3633
const scheme = remoteSchemeForEditor(id);
37-
const style = remoteLinkStyleForEditor(id);
38-
return scheme === undefined || style === undefined
39-
? []
40-
: [[`${scheme}:`, style] as [string, EditorRemoteLinkStyle]];
34+
return scheme === undefined ? [] : [`${scheme}:`];
4135
}),
4236
);
4337

44-
// `zed://ssh/<host>/<path>`: a host segment plus a non-empty path.
45-
const ZED_SSH_PATHNAME = /^\/[^/]+\/.+$/;
38+
// Zed's host sits in the first path segment, so it needs its own userinfo ban.
39+
const ZED_SSH_PATHNAME = /^\/[^/@:]+\/.+$/;
4640

47-
const isRemoteEditorUrl = (url: URL) => {
48-
const style = REMOTE_EDITOR_PROTOCOLS.get(url.protocol);
49-
if (style === undefined || url.username.length > 0 || url.password.length > 0) {
50-
return false;
51-
}
52-
if (style === "zed-ssh") {
53-
return url.host === "ssh" && ZED_SSH_PATHNAME.test(url.pathname);
54-
}
55-
return (
56-
url.host === "vscode-remote" &&
57-
url.pathname.startsWith("/ssh-remote+") &&
58-
url.pathname.length > "/ssh-remote+".length
59-
);
60-
};
41+
const isRemoteEditorUrl = (url: URL) =>
42+
REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&
43+
url.username.length === 0 &&
44+
url.password.length === 0 &&
45+
(url.protocol === "zed:"
46+
? url.host === "ssh" && ZED_SSH_PATHNAME.test(url.pathname)
47+
: url.host === "vscode-remote" &&
48+
url.pathname.startsWith("/ssh-remote+") &&
49+
url.pathname.length > "/ssh-remote+".length);
6150

6251
export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {
6352
if (typeof rawUrl !== "string") {

‎apps/web/src/remoteOpen.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* Remote open-in-editor: when this client is not on the environment's
3-
* machine, "Open" must hand the OS an editor deep link
4-
* (`vscode://vscode-remote/ssh-remote+…`, `zed://ssh/…`) so the local editor
5-
* connects over SSH instead of exec'ing an editor on the environment host.
3+
* machine, "Open" must hand the OS a `vscode://vscode-remote/ssh-remote+…`
4+
* deep link (local editor connects over SSH) instead of exec'ing an editor
5+
* on the environment host.
66
*
77
* Host precedence: a desktop-SSH environment's real `~/.ssh/config` alias
88
* beats server-advertised names; among advertised names the tailnet MagicDNS

‎packages/contracts/src/editor.ts‎

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,19 @@ import { TrimmedNonEmptyString } from "./baseSchemas.ts";
44
export const EditorLaunchStyle = Schema.Literals(["direct-path", "goto", "line-column"]);
55
export type EditorLaunchStyle = typeof EditorLaunchStyle.Type;
66

7-
/** Deep-link shapes editors use to open a remote workspace over SSH. */
8-
export type EditorRemoteLinkStyle = "vscode-remote" | "zed-ssh";
9-
107
type EditorDefinition = {
118
readonly id: string;
129
readonly label: string;
1310
readonly commands: readonly [string, ...string[]] | null;
1411
readonly baseArgs?: readonly string[];
1512
readonly launchStyle: EditorLaunchStyle;
1613
/**
17-
* URL scheme for editors that can open a remote workspace over SSH. Only set
18-
* for editors that ship the remote machinery; see `remoteLinkStyle` for the
19-
* shape of the link the scheme expects.
14+
* URL scheme for editors that support VS Code's remote deep links
15+
* (`<scheme>://vscode-remote/ssh-remote+<host><path>`). Only set for VS Code
16+
* and forks that ship the Remote-SSH machinery, plus Zed, which uses its own
17+
* `zed://ssh/<host><path>` shape.
2018
*/
2119
readonly remoteScheme?: string;
22-
/**
23-
* Shape of `remoteScheme`'s deep link. Defaults to VS Code's
24-
* `<scheme>://vscode-remote/ssh-remote+<host><path>`, which its forks share.
25-
*/
26-
readonly remoteLinkStyle?: EditorRemoteLinkStyle;
2720
};
2821

2922
export const EDITORS = [
@@ -63,7 +56,6 @@ export const EDITORS = [
6356
commands: ["zed", "zeditor"],
6457
launchStyle: "direct-path",
6558
remoteScheme: "zed",
66-
remoteLinkStyle: "zed-ssh",
6759
},
6860
{ id: "antigravity", label: "Antigravity", commands: ["agy"], launchStyle: "goto" },
6961
{ id: "idea", label: "IntelliJ IDEA", commands: ["idea"], launchStyle: "line-column" },
@@ -99,10 +91,7 @@ export type LaunchEditorInput = typeof LaunchEditorInput.Type;
9991

10092
const remoteSchemeOf = (editor: EditorDefinition): string | undefined => editor.remoteScheme;
10193

102-
const remoteLinkStyleOf = (editor: EditorDefinition): EditorRemoteLinkStyle | undefined =>
103-
editor.remoteScheme === undefined ? undefined : (editor.remoteLinkStyle ?? "vscode-remote");
104-
105-
/** Editors that can open a remote workspace via an SSH deep link. */
94+
/** Editors that can open a remote workspace via `vscode-remote` deep links. */
10695
export const REMOTE_CAPABLE_EDITOR_IDS: ReadonlyArray<EditorId> = EDITORS.flatMap((editor) =>
10796
remoteSchemeOf(editor) !== undefined ? [editor.id] : [],
10897
);
@@ -112,35 +101,27 @@ export const remoteSchemeForEditor = (id: EditorId): string | undefined => {
112101
return editor === undefined ? undefined : remoteSchemeOf(editor);
113102
};
114103

115-
/** Link shape `remoteSchemeForEditor` returns a scheme for, if any. */
116-
export const remoteLinkStyleForEditor = (id: EditorId): EditorRemoteLinkStyle | undefined => {
117-
const editor = EDITORS.find((candidate) => candidate.id === id);
118-
return editor === undefined ? undefined : remoteLinkStyleOf(editor);
119-
};
120-
121104
/**
122-
* Builds the deep link that opens `absolutePath` on `host` in the local editor
123-
* over SSH: `<scheme>://vscode-remote/ssh-remote+<host><path>` for VS Code and
124-
* its forks, `zed://ssh/<host><path>` for Zed. Returns undefined for editors
125-
* without remote deep-link support.
105+
* Builds a `<scheme>://vscode-remote/ssh-remote+<host><path>` deep link (Zed
106+
* takes `zed://ssh/<host><path>`) that opens `absolutePath` on `host` in the
107+
* local editor over SSH. Returns undefined for editors without remote
108+
* deep-link support.
126109
*/
127110
export const buildRemoteOpenUrl = (input: {
128111
readonly editor: EditorId;
129112
readonly host: string;
130113
readonly absolutePath: string;
131114
}): string | undefined => {
132115
const scheme = remoteSchemeForEditor(input.editor);
133-
const style = remoteLinkStyleForEditor(input.editor);
134-
if (scheme === undefined || style === undefined) {
116+
if (scheme === undefined) {
135117
return undefined;
136118
}
137-
// Windows server paths (`C:\...`) appear as `/C:/...` in the remote URI, and
138-
// percent-encoding keeps the drive colon out of Zed's SCP-style host split.
119+
// Windows server paths (`C:\...`) appear as `/C:/...` in vscode-remote URIs.
139120
const posixPath = input.absolutePath.replaceAll("\\", "/");
140121
const rootedPath = posixPath.startsWith("/") ? posixPath : `/${posixPath}`;
141122
const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");
142123
const encodedHost = encodeURIComponent(input.host);
143-
return style === "zed-ssh"
124+
return input.editor === "zed"
144125
? `${scheme}://ssh/${encodedHost}${encodedPath}`
145126
: `${scheme}://vscode-remote/ssh-remote+${encodedHost}${encodedPath}`;
146127
};

0 commit comments

Comments
 (0)