Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(editors): open remote projects in Zed (#221)
Leo8066239f4038
diff --git a/apps/desktop/src/electron/ElectronShell.test.ts b/apps/desktop/src/electron/ElectronShell.test.tsindex 9ae6f502b..a7b9d23cb 100644--- a/apps/desktop/src/electron/ElectronShell.test.ts+++ b/apps/desktop/src/electron/ElectronShell.test.ts@@ -52,6 +52,54 @@ describe("ElectronShell", () => {}).pipe(Effect.provide(ElectronShell.layer)),);+ it.effect("opens Zed's ssh deep link", () =>+ Effect.gen(function* () {+ openExternalMock.mockResolvedValue(undefined);++ const electronShell = yield* ElectronShell.ElectronShell;+ const result = yield* electronShell.openExternal("zed://ssh/example.com/home/user/project");++ assert.equal(result, true);+ assert.deepEqual(openExternalMock.mock.calls, [["zed://ssh/example.com/home/user/project"]]);+ }).pipe(Effect.provide(ElectronShell.layer)),+ );++ it.effect("does not open editor URLs that mix up link shapes", () =>+ Effect.gen(function* () {+ openExternalMock.mockResolvedValue(undefined);++ const electronShell = yield* ElectronShell.ElectronShell;+ const results = yield* Effect.all([+ electronShell.openExternal("zed://extension/attacker"),+ electronShell.openExternal("vscode://ssh/example.com/home/user/project"),+ ]);++ assert.deepEqual(results, [false, false]);+ assert.equal(openExternalMock.mock.calls.length, 0);+ }).pipe(Effect.provide(ElectronShell.layer)),+ );++ it.effect("does not open Zed ssh links with encoded host delimiters", () =>+ Effect.gen(function* () {+ openExternalMock.mockResolvedValue(undefined);++ const electronShell = yield* ElectronShell.ElectronShell;+ const results = yield* Effect.all([+ electronShell.openExternal("zed://ssh/user%40host/workspace"),+ electronShell.openExternal("zed://ssh/host%3A22/workspace"),+ electronShell.openExternal("zed://ssh/host%2Fevil/workspace"),+ electronShell.openExternal("zed://ssh/host%2fevil/workspace"),+ electronShell.openExternal("zed://ssh/host%3a22/workspace"),+ electronShell.openExternal("zed://ssh/user%2540host/workspace"),+ electronShell.openExternal("zed://ssh/host%252Fevil/workspace"),+ electronShell.openExternal("zed://ssh/host%253A22/workspace"),+ ]);++ assert.deepEqual(results, [false, false, false, false, false, false, false, false]);+ assert.equal(openExternalMock.mock.calls.length, 0);+ }).pipe(Effect.provide(ElectronShell.layer)),+ );+it.effect("does not open remote editor URLs with userinfo", () =>Effect.gen(function* () {openExternalMock.mockResolvedValue(undefined);@@ -64,9 +112,10 @@ describe("ElectronShell", () => {electronShell.openExternal("vscode://:secret@vscode-remote/ssh-remote+example.com/home/user/project",),+ electronShell.openExternal("zed://ssh/[email protected]/home/user/project"),]);- assert.deepEqual(results, [false, false]);+ assert.deepEqual(results, [false, false, false]);assert.equal(openExternalMock.mock.calls.length, 0);}).pipe(Effect.provide(ElectronShell.layer)),);diff --git a/apps/desktop/src/electron/ElectronShell.ts b/apps/desktop/src/electron/ElectronShell.tsindex 2ed13bfeb..be874ce02 100644--- a/apps/desktop/src/electron/ElectronShell.ts+++ b/apps/desktop/src/electron/ElectronShell.ts@@ -6,8 +6,9 @@ import * as Option from "effect/Option";import * as Electron from "electron";-// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`)-// must reach the OS handler; every other non-web scheme stays blocked.+// Remote open-in-editor deep links (`vscode://vscode-remote/ssh-remote+…`,+// `zed://ssh/<host>/<path>`) must reach the OS handler; every other non-web+// scheme stays blocked.const SAFE_WEB_PROTOCOLS = new Set(["http:", "https:"]);const REMOTE_EDITOR_PROTOCOLS = new Set(REMOTE_CAPABLE_EDITOR_IDS.flatMap((id) => {@@ -16,13 +17,37 @@ const REMOTE_EDITOR_PROTOCOLS = new Set(}),);+// Zed's host sits in the first path segment, so it needs its own userinfo ban.+// A decoded host cannot contain `%`; rejecting it also blocks nested encoding+// such as `%2540`, which another URL parser could decode into a delimiter.+const ZED_SSH_HOST = /^[^/@:%]+$/;++function isZedSshUrl(url: URL): boolean {+ if (url.host !== "ssh") {+ return false;+ }+ const encodedHost = url.pathname.split("/")[1];+ if (!encodedHost) {+ return false;+ }+ let host: string;+ try {+ host = decodeURIComponent(encodedHost);+ } catch {+ return false;+ }+ return ZED_SSH_HOST.test(host) && url.pathname.length > encodedHost.length + 1;+}+const isRemoteEditorUrl = (url: URL) =>REMOTE_EDITOR_PROTOCOLS.has(url.protocol) &&url.username.length === 0 &&url.password.length === 0 &&- url.host === "vscode-remote" &&- url.pathname.startsWith("/ssh-remote+") &&- url.pathname.length > "/ssh-remote+".length;+ (url.protocol === "zed:"+ ? isZedSshUrl(url)+ : url.host === "vscode-remote" &&+ url.pathname.startsWith("/ssh-remote+") &&+ url.pathname.length > "/ssh-remote+".length);export function parseSafeExternalUrl(rawUrl: unknown): Option.Option<string> {if (typeof rawUrl !== "string") {diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.tsindex eb18aece4..2d3de1c7e 100644--- a/apps/web/src/remoteOpen.test.ts+++ b/apps/web/src/remoteOpen.test.ts@@ -144,8 +144,18 @@ describe("buildRemoteOpenUrl", () => {).toBe("vscode://vscode-remote/ssh-remote+sol/C%3A/Users/theo");});+ it("builds Zed's ssh deep link", () => {+ expect(+ buildRemoteOpenUrl({+ editor: "zed",+ host: "sol.tail1234.ts.net",+ absolutePath: "/home/theo/code/my repo",+ }),+ ).toBe("zed://ssh/sol.tail1234.ts.net/home/theo/code/my%20repo");+ });+it("returns undefined for editors without remote support", () => {- expect(buildRemoteOpenUrl({ editor: "zed", host: "sol", absolutePath: "/tmp/x" })).toBe(+ expect(buildRemoteOpenUrl({ editor: "idea", host: "sol", absolutePath: "/tmp/x" })).toBe(undefined,);});diff --git a/packages/contracts/src/editor.ts b/packages/contracts/src/editor.tsindex b7a7dd7c7..530785db4 100644--- a/packages/contracts/src/editor.ts+++ b/packages/contracts/src/editor.ts@@ -13,7 +13,8 @@ type EditorDefinition = {/*** URL scheme for editors that support VS Code's remote deep links* (`<scheme>://vscode-remote/ssh-remote+<host><path>`). Only set for VS Code- * and forks that ship the Remote-SSH machinery.+ * and forks that ship the Remote-SSH machinery, plus Zed, which uses its own+ * `zed://ssh/<host><path>` shape.*/readonly remoteScheme?: string;};@@ -49,7 +50,13 @@ export const EDITORS = [launchStyle: "goto",remoteScheme: "vscodium",},- { id: "zed", label: "Zed", commands: ["zed", "zeditor"], launchStyle: "direct-path" },+ {+ id: "zed",+ label: "Zed",+ commands: ["zed", "zeditor"],+ launchStyle: "direct-path",+ remoteScheme: "zed",+ },{ id: "antigravity", label: "Antigravity", commands: ["agy"], launchStyle: "goto" },{ id: "idea", label: "IntelliJ IDEA", commands: ["idea"], launchStyle: "line-column" },{ id: "aqua", label: "Aqua", commands: ["aqua"], launchStyle: "line-column" },@@ -95,9 +102,10 @@ export const remoteSchemeForEditor = (id: EditorId): string | undefined => {};/**- * Builds a `<scheme>://vscode-remote/ssh-remote+<host><path>` deep link that- * opens `absolutePath` on `host` in the local editor over SSH. Returns- * undefined for editors without remote deep-link support.+ * Builds a `<scheme>://vscode-remote/ssh-remote+<host><path>` deep link (Zed+ * takes `zed://ssh/<host><path>`) that opens `absolutePath` on `host` in the+ * local editor over SSH. Returns undefined for editors without remote+ * deep-link support.*/export const buildRemoteOpenUrl = (input: {readonly editor: EditorId;@@ -112,7 +120,10 @@ export const buildRemoteOpenUrl = (input: {const posixPath = input.absolutePath.replaceAll("\\", "/");const rootedPath = posixPath.startsWith("/") ? posixPath : `/${posixPath}`;const encodedPath = rootedPath.split("/").map(encodeURIComponent).join("/");- return `${scheme}://vscode-remote/ssh-remote+${encodeURIComponent(input.host)}${encodedPath}`;+ const encodedHost = encodeURIComponent(input.host);+ return input.editor === "zed"+ ? `${scheme}://ssh/${encodedHost}${encodedPath}`+ : `${scheme}://vscode-remote/ssh-remote+${encodedHost}${encodedPath}`;};/**