From a0c55ec0e08e9fdd12294f34c116948566ced6ba Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sat, 31 Oct 2026 23:45:01 -0400 Subject: [PATCH 01/14] fix(desktop): open WSL projects in VS Code --- .../src/electron/ElectronShell.test.ts | 37 +++++++- apps/desktop/src/electron/ElectronShell.ts | 22 ++++- apps/web/src/components/ChatMarkdown.tsx | 50 ++++++++-- .../chat/OpenInPicker.browser.test.tsx | 42 ++++++++- .../chat/OpenInPicker.logic.test.ts | 31 +++++++ apps/web/src/components/chat/OpenInPicker.tsx | 22 ++++- .../components/chat/OpenInPickerShortcut.ts | 30 +++++- apps/web/src/connection/desktopLocal.test.ts | 20 ++-- apps/web/src/connection/desktopLocal.ts | 53 +++++++---- .../connection/useDesktopLocalBootstraps.ts | 16 ++-- apps/web/src/markdownFileHostPath.test.ts | 15 +++ apps/web/src/markdownFileHostPath.ts | 19 ++++ apps/web/src/remoteOpen.test.ts | 92 ++++++++++++++++++- apps/web/src/remoteOpen.ts | 33 ++++++- apps/web/vite.config.ts | 8 +- packages/contracts/src/editor.ts | 30 ++++++ 16 files changed, 463 insertions(+), 57 deletions(-) create mode 100644 apps/web/src/components/chat/OpenInPicker.logic.test.ts create mode 100644 apps/web/src/markdownFileHostPath.test.ts diff --git a/apps/desktop/src/electron/ElectronShell.test.ts b/apps/desktop/src/electron/ElectronShell.test.ts index 0e72a46146e0a..35e4b62da4166 100644 --- a/apps/desktop/src/electron/ElectronShell.test.ts +++ b/apps/desktop/src/electron/ElectronShell.test.ts @@ -40,6 +40,25 @@ describe("ElectronShell", () => { }).pipe(Effect.provide(ElectronShell.layer)), ); + it.effect("opens VS Code Remote - WSL URLs", () => + Effect.gen(function* () { + openExternalMock.mockResolvedValue(undefined); + + const electronShell = yield* ElectronShell.ElectronShell; + const urls = [ + "vscode://vscode-remote/wsl+Ubuntu/home/user/My%20Project", + "vscode-insiders://vscode-remote/wsl+Debian/home/user/project", + ]; + const results = yield* Effect.forEach(urls, (url) => electronShell.openExternal(url)); + + assert.deepEqual(results, [true, true]); + assert.deepEqual( + openExternalMock.mock.calls, + urls.map((url) => [url]), + ); + }).pipe(Effect.provide(ElectronShell.layer)), + ); + it.effect("opens the JetBrains Toolbox ssh deep link", () => Effect.gen(function* () { openExternalMock.mockResolvedValue(undefined); @@ -62,12 +81,28 @@ describe("ElectronShell", () => { const results = yield* Effect.all([ electronShell.openExternal("zed://extension/attacker"), electronShell.openExternal("vscode://ssh/example.com/home/user/project"), + electronShell.openExternal("vscode://vscode-remote/wsl+bad!distro/home/user/project"), + electronShell.openExternal("cursor://vscode-remote/wsl+Ubuntu/home/user/project"), + electronShell.openExternal("vscode://vscode-remote/wsl+Ubuntu"), + electronShell.openExternal("vscode://vscode-remote/wsl+Ubuntu/home/%2Fetc"), + electronShell.openExternal("vscode://vscode-remote/wsl+Ubuntu/home/user/project?x=1"), electronShell.openExternal("jetbrains://idea/navigate/reference?project=x&path=y"), electronShell.openExternal("jetbrains://gateway/ssh/environment?launchIde=true"), electronShell.openExternal("jetbrains://gateway/com.example.provider/connect?h=x"), ]); - assert.deepEqual(results, [false, false, false, false, false]); + assert.deepEqual(results, [ + false, + false, + false, + false, + false, + false, + false, + 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.ts index e32dba36a6dfa..8870eee418843 100644 --- a/apps/desktop/src/electron/ElectronShell.ts +++ b/apps/desktop/src/electron/ElectronShell.ts @@ -23,6 +23,21 @@ const REMOTE_EDITOR_PROTOCOLS = new Set( // Zed embeds [user@]host in the path; reject passwords and ports there. const ZED_SSH_PATHNAME = /^\/(?:[^/@:]+@)?[^/@:]+\/.*$/; +function isValidWslRemotePath(pathname: string): boolean { + const match = /^\/wsl\+[A-Za-z0-9._-]+\/(.*)$/.exec(pathname); + if (!match || pathname.includes("\\") || /%(?:2f|5c)/i.test(pathname)) { + return false; + } + try { + return match[1]!.split("/").every((segment) => { + const decoded = decodeURIComponent(segment); + return decoded !== "." && decoded !== ".." && !/[\u0000-\u001f\u007f\\]/.test(decoded); + }); + } catch { + return false; + } +} + const isRemoteEditorUrl = (url: URL) => REMOTE_EDITOR_PROTOCOLS.has(url.protocol) && url.username.length === 0 && @@ -34,8 +49,11 @@ const isRemoteEditorUrl = (url: URL) => url.pathname === "/ssh/environment" && (url.searchParams.get("h") ?? "").length > 0 : url.host === "vscode-remote" && - url.pathname.startsWith("/ssh-remote+") && - url.pathname.length > "/ssh-remote+".length); + ((url.pathname.startsWith("/ssh-remote+") && url.pathname.length > "/ssh-remote+".length) || + ((url.protocol === "vscode:" || url.protocol === "vscode-insiders:") && + url.search.length === 0 && + url.hash.length === 0 && + isValidWslRemotePath(url.pathname)))); export function parseSafeExternalUrl(rawUrl: unknown): Option.Option { if (typeof rawUrl !== "string") { diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 9413b13a088cf..bfa20920631aa 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -142,6 +142,7 @@ import { } from "../markdown-links"; import { markdownFileCopyPaths, + buildWslMarkdownFileUrl, markdownFileEditorTarget, resolveMarkdownFileHostPath, } from "../markdownFileHostPath"; @@ -149,7 +150,13 @@ import { isMarkdownFileLinkLabel } from "@t3tools/shared/markdownLinks"; import { isElectron } from "../env"; import { readLocalApi } from "../localApi"; import { cn } from "../lib/utils"; -import { resolveRemoteOpenState, useRemoteOpenResolution } from "../remoteOpen"; +import { + openRemoteEditorUrl, + resolveRemoteOpenState, + useRemoteCapableEditors, + useRemoteOpenResolution, + wslCapableEditors, +} from "../remoteOpen"; import { useRightPanelStore } from "../rightPanelStore"; import { readThreadShell, useProjects } from "../state/entities"; import { serverEnvironment } from "../state/server"; @@ -630,6 +637,8 @@ function useChatMarkdownState({ markdownServerConfigFieldsAtom(environmentId), ); const projects = useProjects(); + const remoteEditors = useRemoteCapableEditors(); + const [wslEditor] = usePreferredEditor(wslCapableEditors(remoteEditors)); const [preferredEditor] = usePreferredEditor(availableEditors); const preferredEditorMenuLabel = openInEditorMenuLabel(preferredEditor); const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors); @@ -857,12 +866,33 @@ function useChatMarkdownState({ theme={resolvedTheme} threadRef={threadRef} onOpen={ - canUseShellActions - ? async () => - openInPreferredEditor( - markdownFileEditorTarget(fileLinkMeta, await resolveHostPath()), - ) - : undefined + remoteOpen.state.mode === "wsl-links" && canOperateHost && wslEditor + ? async () => { + if ( + environmentId === null || + !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope) + ) { + throw new Error("This connection cannot open an editor on this environment."); + } + const path = (await resolveHostPath()).absolutePath; + const url = buildWslMarkdownFileUrl({ + editor: wslEditor, + distro: remoteOpen.state.mode === "wsl-links" ? remoteOpen.state.distro : "", + path, + cwd, + line: fileLinkMeta.line, + column: fileLinkMeta.column, + }); + if (!url || !(await openRemoteEditorUrl(url))) + throw new Error("Could not open the file in VS Code."); + return AsyncResult.success(undefined); + } + : canUseShellActions + ? async () => + openInPreferredEditor( + markdownFileEditorTarget(fileLinkMeta, await resolveHostPath()), + ) + : undefined } resolveCopyPaths={async () => markdownFileCopyPaths(fileLinkMeta, await resolveHostPath(), cwd) @@ -873,7 +903,11 @@ function useChatMarkdownState({ ? () => openMarkdownMedia(mediaPath, fileLinkMeta.filePath) : undefined } - openInEditorMenuLabel={preferredEditorMenuLabel} + openInEditorMenuLabel={ + remoteOpen.state.mode === "wsl-links" + ? openInEditorMenuLabel(wslEditor) + : preferredEditorMenuLabel + } onReveal={ canUseShellActions && revealInFileManagerLabel !== undefined ? async () => revealFileInFileManager((await resolveHostPath()).absolutePath) diff --git a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx index 720ce4d6c443d..b9c24abb898a0 100644 --- a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx +++ b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx @@ -142,13 +142,13 @@ async function setup() { return event; } - function FavoriteEditorFallback() { + function FavoriteEditorFallback({ openInCwd = "/work/project" }: { openInCwd?: string }) { useOpenFavoriteEditorShortcut({ enabled: true, environmentId: selected, keybindings: DEFAULT_RESOLVED_KEYBINDINGS, availableEditors: editors, - openInCwd: "/work/project", + openInCwd, }); return null; } @@ -200,6 +200,44 @@ describe("remote editor links", () => { expect(state.openUrl).toHaveBeenCalledWith(expect.stringContaining("ssh-remote+sol")); expect(state.run).not.toHaveBeenCalled(); }); + + it("opens a WSL workspace through VS Code Remote - WSL and offers only VS Code variants", async () => { + await using fixture = await setup(); + const { renderPicker, byLabel, menuItems, click, primaryButton } = fixture; + state.remote = { mode: "wsl-links", distro: "Ubuntu" }; + state.clientEditors = ["cursor", "vscode-insiders", "vscode"]; + + await renderPicker(["vscode", "cursor"], false, { + openInCwd: "/home/theo/My Project", + }); + await click(byLabel("Choose editor")); + const labels = menuItems().map((item) => item.textContent); + expect(labels.some((label) => label?.startsWith("VS Code"))).toBe(true); + expect(labels).toContain("VS Code Insiders"); + expect(labels).not.toContain("Cursor"); + + await click(primaryButton()); + expect(state.openUrl).toHaveBeenCalledWith( + "vscode://vscode-remote/wsl+Ubuntu/home/theo/My%20Project", + ); + expect(state.run).not.toHaveBeenCalled(); + }); + + it("opens the WSL workspace from the favorite-editor shortcut", async () => { + await using fixture = await setup(); + const { screen, pressOpenFavorite, FavoriteEditorFallback } = fixture; + state.remote = { mode: "wsl-links", distro: "Debian" }; + state.clientEditors = ["vscode"]; + await act(async () => + screen.rerender(), + ); + + expect((await pressOpenFavorite()).defaultPrevented).toBe(true); + expect(state.openUrl).toHaveBeenCalledWith( + "vscode://vscode-remote/wsl+Debian/home/theo/workspace", + ); + expect(state.run).not.toHaveBeenCalled(); + }); }); describe("open in editor announcement", () => { diff --git a/apps/web/src/components/chat/OpenInPicker.logic.test.ts b/apps/web/src/components/chat/OpenInPicker.logic.test.ts new file mode 100644 index 0000000000000..640bfabeebdab --- /dev/null +++ b/apps/web/src/components/chat/OpenInPicker.logic.test.ts @@ -0,0 +1,31 @@ +import { EnvironmentId } from "@t3tools/contracts"; +import { describe, expect, it } from "vite-plus/test"; + +import { shouldShowOpenInPicker } from "./OpenInPicker.logic"; + +const primary = EnvironmentId.make("primary"); +const secondary = EnvironmentId.make("secondary"); + +describe("shouldShowOpenInPicker", () => { + it("shows the picker for a desktop-managed WSL environment", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: "project", + activeThreadEnvironmentId: secondary, + primaryEnvironmentId: primary, + remoteOpenMode: "wsl-links", + }), + ).toBe(true); + }); + + it("keeps other secondary local environments hidden", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: "project", + activeThreadEnvironmentId: secondary, + primaryEnvironmentId: primary, + remoteOpenMode: "local-exec", + }), + ).toBe(false); + }); +}); diff --git a/apps/web/src/components/chat/OpenInPicker.tsx b/apps/web/src/components/chat/OpenInPicker.tsx index a19491adcd15e..673d77ce5bfb2 100644 --- a/apps/web/src/components/chat/OpenInPicker.tsx +++ b/apps/web/src/components/chat/OpenInPicker.tsx @@ -2,6 +2,7 @@ import { ThreadDetailsControl } from "./ThreadDetailsControl"; import { AuthOrchestrationOperateScope, buildRemoteOpenUrl, + buildWslOpenUrl, EditorId, type EnvironmentId, type ResolvedKeybindingsConfig, @@ -15,6 +16,7 @@ import { editorLabelForPlatform } from "../../editorLabels"; import { openRemoteEditorUrl, useRemoteCapableEditors, + wslCapableEditors, useRemoteOpenHint, useRemoteOpenState, } from "../../remoteOpen"; @@ -239,7 +241,12 @@ export const OpenInPicker = memo(function OpenInPicker({ const [remoteHintSeen, markRemoteHintSeen] = useRemoteOpenHint(); const environmentLabel = useEnvironment(environmentId)?.label ?? "this machine"; // Remote editors run on the viewing machine; only desktop can probe that PATH. - const effectiveEditors = remote.mode === "local-exec" ? availableEditors : remoteCapableEditors; + const effectiveEditors = + remote.mode === "local-exec" + ? availableEditors + : remote.mode === "wsl-links" + ? wslCapableEditors(remoteCapableEditors) + : remoteCapableEditors; const [preferredEditor, setPreferredEditor] = usePreferredEditor(effectiveEditors); const openInEditor = async (editorId: EditorId | null): Promise => { @@ -247,6 +254,19 @@ export const OpenInPicker = memo(function OpenInPicker({ const editor = editorId ?? preferredEditor; if (!editor) return false; if (remote.mode === "remote-unavailable") return false; + if (remote.mode === "wsl-links") { + const url = buildWslOpenUrl({ + editor, + distro: remote.distro, + absolutePath: openInCwd, + isFile: openInCwdIsFile, + }); + if (url === undefined) return false; + const opened = await openRemoteEditorUrl(url); + if (!opened) return false; + setPreferredEditor(editor); + return true; + } if (remote.mode === "remote-links") { const url = buildRemoteOpenUrl({ editor, diff --git a/apps/web/src/components/chat/OpenInPickerShortcut.ts b/apps/web/src/components/chat/OpenInPickerShortcut.ts index 833c3f3784987..495b260ed6cb9 100644 --- a/apps/web/src/components/chat/OpenInPickerShortcut.ts +++ b/apps/web/src/components/chat/OpenInPickerShortcut.ts @@ -1,4 +1,5 @@ import { + buildWslOpenUrl, buildRemoteOpenUrl, type EditorId, type EnvironmentId, @@ -10,7 +11,12 @@ import { usePreferredEditor } from "../../editorPreferences"; import { editorLabelForPlatform } from "../../editorLabels"; import { isOpenFavoriteEditorShortcut } from "../../keybindings"; import { announce } from "../../lib/announce"; -import { openRemoteEditorUrl, useRemoteCapableEditors, useRemoteOpenState } from "../../remoteOpen"; +import { + openRemoteEditorUrl, + useRemoteCapableEditors, + useRemoteOpenState, + wslCapableEditors, +} from "../../remoteOpen"; import { registerCommands } from "../../shortcuts/dispatcher"; import { shellEnvironment } from "../../state/shell"; import { useAtomCommand } from "../../state/use-atom-command"; @@ -57,9 +63,13 @@ export function useOpenFavoriteEditorShortcut({ const remote = useRemoteOpenState(environmentId); const remoteCapableEditors = useRemoteCapableEditors(); // Matches the picker: remote editors run on the viewing machine. - const [preferredEditor] = usePreferredEditor( - remote.mode === "local-exec" ? availableEditors : remoteCapableEditors, - ); + const effectiveEditors = + remote.mode === "local-exec" + ? availableEditors + : remote.mode === "wsl-links" + ? wslCapableEditors(remoteCapableEditors) + : remoteCapableEditors; + const [preferredEditor] = usePreferredEditor(effectiveEditors); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enabled useEffect(() => { @@ -75,6 +85,18 @@ export function useOpenFavoriteEditorShortcut({ event.preventDefault(); const label = editorLabelForPlatform(preferredEditor, navigator.platform); + if (remote.mode === "wsl-links") { + const url = buildWslOpenUrl({ + editor: preferredEditor, + distro: remote.distro, + absolutePath: openInCwd, + }); + if (url === undefined) return; + void openRemoteEditorUrl(url).then((opened) => { + if (opened) announce(`Opened in ${label}`); + }); + return; + } if (remote.mode === "remote-links") { const url = buildRemoteOpenUrl({ editor: preferredEditor, diff --git a/apps/web/src/connection/desktopLocal.test.ts b/apps/web/src/connection/desktopLocal.test.ts index 2086e91853550..3911c884c5d97 100644 --- a/apps/web/src/connection/desktopLocal.test.ts +++ b/apps/web/src/connection/desktopLocal.test.ts @@ -63,19 +63,23 @@ describe("desktop local topology reads", () => { httpBaseUrl: "http://127.0.0.1:4000", wsBaseUrl: "ws://127.0.0.1:4000", }; + const primary = { + id: PRIMARY_LOCAL_ENVIRONMENT_ID, + label: "WSL (Ubuntu)", + runningDistro: "Ubuntu", + httpBaseUrl: "http://127.0.0.1:3000", + wsBaseUrl: "ws://127.0.0.1:3000", + }; const reader = createDesktopSecondaryBootstrapsReader(() => ({ - getLocalEnvironmentBootstraps: () => [ - { - ...secondary, - id: PRIMARY_LOCAL_ENVIRONMENT_ID, - label: "Windows", - }, - secondary, - ], + getLocalEnvironmentBootstraps: () => [primary, secondary], })); expect(reader.readResult()).toEqual({ _tag: "Success", bootstraps: [secondary] }); + expect(reader.readAllResult()).toEqual({ + _tag: "Success", + bootstraps: [primary, secondary], + }); }); it("retains the last successful snapshot only until another read succeeds", () => { diff --git a/apps/web/src/connection/desktopLocal.ts b/apps/web/src/connection/desktopLocal.ts index eb46a09ab3ac6..8ff2be07d217e 100644 --- a/apps/web/src/connection/desktopLocal.ts +++ b/apps/web/src/connection/desktopLocal.ts @@ -26,7 +26,7 @@ export function desktopLocalBackendId(target: ConnectionTarget): string | null { : null; } -export type DesktopSecondaryBootstrapsRead = +export type DesktopBootstrapsRead = | { readonly _tag: "Success"; readonly bootstraps: ReadonlyArray; @@ -36,9 +36,13 @@ export type DesktopSecondaryBootstrapsRead = readonly cause: unknown; }; +export type DesktopSecondaryBootstrapsRead = DesktopBootstrapsRead; + export interface DesktopSecondaryBootstrapsReader { readonly readResult: () => DesktopSecondaryBootstrapsRead; readonly readSnapshot: () => ReadonlyArray; + readonly readAllResult: () => DesktopBootstrapsRead; + readonly readAllSnapshot: () => ReadonlyArray; } /** Empty reads clear the snapshot; failed reads retain platform registrations. */ @@ -46,21 +50,21 @@ export function createDesktopSecondaryBootstrapsReader( resolveBridge: () => Pick | undefined, ): DesktopSecondaryBootstrapsReader { let snapshot: ReadonlyArray = []; + let allSnapshot: ReadonlyArray = []; - const readResult = (): DesktopSecondaryBootstrapsRead => { + const readAllResult = (): DesktopBootstrapsRead => { const bridge = resolveBridge(); if (bridge === undefined) { + if (allSnapshot.length > 0) allSnapshot = []; if (snapshot.length > 0) snapshot = []; - return { _tag: "Success", bootstraps: snapshot }; + return { _tag: "Success", bootstraps: allSnapshot }; } try { - const next = bridge - .getLocalEnvironmentBootstraps() - .filter((entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID); + const next = bridge.getLocalEnvironmentBootstraps(); if ( - next.length !== snapshot.length || + next.length !== allSnapshot.length || next.some((entry, index) => { - const previous = snapshot[index]; + const previous = allSnapshot[index]; return ( previous === undefined || entry.id !== previous.id || @@ -72,31 +76,48 @@ export function createDesktopSecondaryBootstrapsReader( ); }) ) { - snapshot = next; + allSnapshot = next; + } + const nextSecondary = allSnapshot.filter( + (entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID, + ); + if ( + nextSecondary.length !== snapshot.length || + nextSecondary.some((entry, index) => entry !== snapshot[index]) + ) { + snapshot = nextSecondary; } - return { _tag: "Success", bootstraps: snapshot }; + return { _tag: "Success", bootstraps: allSnapshot }; } catch (cause) { return { _tag: "Failure", cause }; } }; + const readResult = (): DesktopSecondaryBootstrapsRead => { + const result = readAllResult(); + return result._tag === "Success" ? { _tag: "Success", bootstraps: snapshot } : result; + }; + return { readResult, + readAllResult, readSnapshot: () => { const result = readResult(); return result._tag === "Success" ? result.bootstraps : snapshot; }, + readAllSnapshot: () => { + const result = readAllResult(); + return result._tag === "Success" ? result.bootstraps : allSnapshot; + }, }; } -const desktopSecondaryBootstrapsReader = createDesktopSecondaryBootstrapsReader( - () => window.desktopBridge, -); +const desktopBootstrapsReader = createDesktopSecondaryBootstrapsReader(() => window.desktopBridge); export function readDesktopSecondaryBootstrapsResult(): DesktopSecondaryBootstrapsRead { - return desktopSecondaryBootstrapsReader.readResult(); + return desktopBootstrapsReader.readResult(); } -export function readDesktopSecondaryBootstraps(): ReadonlyArray { - return desktopSecondaryBootstrapsReader.readSnapshot(); +export function readDesktopLocalBootstraps(): ReadonlyArray { + return desktopBootstrapsReader.readAllSnapshot(); } diff --git a/apps/web/src/connection/useDesktopLocalBootstraps.ts b/apps/web/src/connection/useDesktopLocalBootstraps.ts index 75c6904731ee6..8a700b30b0816 100644 --- a/apps/web/src/connection/useDesktopLocalBootstraps.ts +++ b/apps/web/src/connection/useDesktopLocalBootstraps.ts @@ -1,8 +1,8 @@ import { useAtomValue } from "@effect/atom-react"; -import type { DesktopEnvironmentBootstrap } from "@t3tools/contracts"; +import { PRIMARY_LOCAL_ENVIRONMENT_ID } from "@t3tools/contracts"; import { Atom } from "effect/reactivity"; -import { readDesktopSecondaryBootstraps } from "./desktopLocal"; +import { readDesktopLocalBootstraps } from "./desktopLocal"; const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000; @@ -12,15 +12,17 @@ const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000; * a successful empty read clears it. The reader returns the same array while * nothing changed, so an unchanged poll notifies no one. */ -const desktopLocalBootstrapsAtom = Atom.make((get) => { +export const desktopLocalBootstrapsAtom = Atom.make((get) => { const interval = setInterval( - () => get.setSelf(readDesktopSecondaryBootstraps()), + () => get.setSelf(readDesktopLocalBootstraps()), DESKTOP_LOCAL_BOOTSTRAP_POLL_MS, ); get.addFinalizer(() => clearInterval(interval)); - return readDesktopSecondaryBootstraps(); + return readDesktopLocalBootstraps(); }).pipe(Atom.withLabel("desktop-local-bootstraps")); -export function useDesktopLocalBootstraps(): ReadonlyArray { - return useAtomValue(desktopLocalBootstrapsAtom); +export function useDesktopLocalBootstraps() { + return useAtomValue(desktopLocalBootstrapsAtom).filter( + (entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID, + ); } diff --git a/apps/web/src/markdownFileHostPath.test.ts b/apps/web/src/markdownFileHostPath.test.ts new file mode 100644 index 0000000000000..4ab5d477c9b97 --- /dev/null +++ b/apps/web/src/markdownFileHostPath.test.ts @@ -0,0 +1,15 @@ +import { expect, it } from "vite-plus/test"; +import { buildWslMarkdownFileUrl } from "./markdownFileHostPath"; + +it("opens a relative WSL file at its specified position", () => { + expect( + buildWslMarkdownFileUrl({ + editor: "vscode", + distro: "Ubuntu", + path: "src/file.ts", + cwd: "/home/user/project", + line: 12, + column: 3, + }), + ).toBe("vscode://vscode-remote/wsl+Ubuntu/home/user/project/src/file.ts:12:3"); +}); diff --git a/apps/web/src/markdownFileHostPath.ts b/apps/web/src/markdownFileHostPath.ts index 26f3aaa348122..cf41287a0bac6 100644 --- a/apps/web/src/markdownFileHostPath.ts +++ b/apps/web/src/markdownFileHostPath.ts @@ -1,3 +1,4 @@ +import { buildWslOpenUrl, type EditorId } from "@t3tools/contracts"; import { formatFilePathPosition, resolvePathLinkTarget } from "@t3tools/shared/fileLinks"; import { workspaceRelativeFilePath } from "@t3tools/shared/path"; @@ -46,3 +47,21 @@ export function markdownFileCopyPaths( }), }; } + +export function buildWslMarkdownFileUrl(input: { + editor: EditorId; + distro: string; + path: string; + cwd: string | undefined; + line: number | undefined; + column: number | undefined; +}) { + return buildWslOpenUrl({ + editor: input.editor, + distro: input.distro, + absolutePath: input.cwd ? resolvePathLinkTarget(input.path, input.cwd) : input.path, + isFile: true, + ...(input.line !== undefined ? { line: input.line } : {}), + ...(input.column !== undefined ? { column: input.column } : {}), + }); +} diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.ts index 365ec4a3d50af..86d6d9c297c65 100644 --- a/apps/web/src/remoteOpen.test.ts +++ b/apps/web/src/remoteOpen.test.ts @@ -1,12 +1,13 @@ import { + BearerConnectionTarget, PrimaryConnectionTarget, RelayConnectionTarget, SshConnectionTarget, } from "@t3tools/client-runtime/connection"; -import { buildRemoteOpenUrl, EnvironmentId } from "@t3tools/contracts"; +import { buildRemoteOpenUrl, buildWslOpenUrl, EnvironmentId } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; -import { resolveRemoteOpenState } from "./remoteOpen"; +import { resolveRemoteOpenState, wslCapableEditors } from "./remoteOpen"; const environmentId = EnvironmentId.make("environment-1"); @@ -61,6 +62,32 @@ describe("resolveRemoteOpenState", () => { ).toEqual({ mode: "local-exec" }); }); + it("uses the resolved distro for desktop-managed WSL environments", () => { + expect( + resolveRemoteOpenState({ + target: primaryTarget("http://172.29.112.1:14369"), + sshTarget: null, + isDesktopRenderer: true, + remoteOpenTargets: undefined, + wslDistro: "Ubuntu", + }), + ).toEqual({ mode: "wsl-links", distro: "Ubuntu" }); + + expect( + resolveRemoteOpenState({ + target: new BearerConnectionTarget({ + environmentId, + label: "WSL (Debian)", + connectionId: "local:wsl:default", + }), + sshTarget: null, + isDesktopRenderer: true, + remoteOpenTargets: undefined, + wslDistro: "Debian", + }), + ).toEqual({ mode: "wsl-links", distro: "Debian" }); + }); + it("leaves a bare desktop SSH alias for the editor to resolve through SSH config", () => { const state = resolveRemoteOpenState({ target: new SshConnectionTarget({ environmentId, label: "sol", connectionId: "ssh-1" }), @@ -186,3 +213,64 @@ describe("buildRemoteOpenUrl", () => { } }); }); + +describe("buildWslOpenUrl", () => { + it("uses the Linux workspace path and VS Code's WSL remote authority", () => { + expect( + buildWslOpenUrl({ + editor: "vscode", + distro: "Ubuntu-22.04", + absolutePath: "/home/theo/My Project", + }), + ).toBe("vscode://vscode-remote/wsl+Ubuntu-22.04/home/theo/My%20Project"); + expect( + buildWslOpenUrl({ + editor: "vscode-insiders", + distro: "Ubuntu", + absolutePath: "/home/theo/file name.md", + isFile: true, + }), + ).toBe("vscode-insiders://vscode-remote/wsl+Ubuntu/home/theo/file%20name.md:1:1"); + expect( + buildWslOpenUrl({ + editor: "vscode", + distro: "Ubuntu", + absolutePath: "/work/file.ts", + isFile: true, + line: 12, + column: 3, + }), + ).toBe("vscode://vscode-remote/wsl+Ubuntu/work/file.ts:12:3"); + }); + + it("rejects unsupported editors, invalid distros, and Windows paths", () => { + expect( + buildWslOpenUrl({ + editor: "cursor", + distro: "Ubuntu", + absolutePath: "/home/theo/project", + }), + ).toBeUndefined(); + expect( + buildWslOpenUrl({ + editor: "vscode", + distro: "Ubuntu/..", + absolutePath: "/home/theo/project", + }), + ).toBeUndefined(); + expect( + buildWslOpenUrl({ + editor: "vscode", + distro: "Ubuntu", + absolutePath: "C:\\Users\\theo\\project", + }), + ).toBeUndefined(); + }); +}); + +describe("wslCapableEditors", () => { + it("retains the VS Code fallback when the probe only finds other editors", () => { + expect(wslCapableEditors(["cursor"])).toEqual(["vscode"]); + expect(wslCapableEditors(["cursor", "vscode-insiders"])).toEqual(["vscode-insiders"]); + }); +}); diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index 741f6f3c60cde..b665d5023407a 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -1,6 +1,8 @@ import type { ConnectionTarget } from "@t3tools/client-runtime/connection"; import { REMOTE_CAPABLE_EDITOR_IDS, + PRIMARY_LOCAL_ENVIRONMENT_ID, + WSL_REMOTE_EDITOR_IDS, type EditorId, type EnvironmentId, type RemoteOpenTarget, @@ -10,7 +12,8 @@ import * as Schema from "effect/Schema"; import { Atom } from "effect/reactivity"; import { useAtomValue } from "@effect/atom-react"; -import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal"; +import { desktopLocalBackendId, isDesktopLocalConnectionTarget } from "~/connection/desktopLocal"; +import { desktopLocalBootstrapsAtom } from "~/connection/useDesktopLocalBootstraps"; import { isLoopbackHostname } from "~/environments/primary/target"; import { useLocalStorage } from "~/hooks/useLocalStorage"; import { environmentPresentations } from "~/state/presentation"; @@ -24,6 +27,7 @@ export interface RemoteOpenHost { export type RemoteOpenState = | { readonly mode: "local-exec" } | { readonly mode: "remote-links"; readonly host: RemoteOpenHost } + | { readonly mode: "wsl-links"; readonly distro: string } | { readonly mode: "remote-unavailable" }; export type RemoteOpenMode = RemoteOpenState["mode"]; @@ -53,6 +57,7 @@ export function resolveRemoteOpenState(input: { readonly sshTarget: { readonly alias: string; readonly username: string | null } | null; readonly remoteOpenTargets: ReadonlyArray | undefined; readonly isDesktopRenderer: boolean; + readonly wslDistro?: string | null; }): RemoteOpenState { const { target } = input; if (target === null) { @@ -61,6 +66,7 @@ export function resolveRemoteOpenState(input: { if (target._tag === "PrimaryConnectionTarget") { // Desktop owns its primary even at a non-loopback WSL2 NAT address. if (input.isDesktopRenderer) { + if (input.wslDistro) return { mode: "wsl-links", distro: input.wslDistro }; return LOCAL_EXEC; } const hostname = parseHostname(target.httpBaseUrl); @@ -68,6 +74,9 @@ export function resolveRemoteOpenState(input: { return LOCAL_EXEC; } } else if (isDesktopLocalConnectionTarget(target)) { + if (desktopLocalBackendId(target)?.startsWith("wsl:") && input.wslDistro) { + return { mode: "wsl-links", distro: input.wslDistro }; + } return LOCAL_EXEC; } @@ -96,6 +105,9 @@ export function resolveRemoteOpenState(input: { function remoteOpenStatesEqual(previous: RemoteOpenState, next: RemoteOpenState): boolean { if (previous.mode !== next.mode) return false; + if (previous.mode === "wsl-links" && next.mode === "wsl-links") { + return previous.distro === next.distro; + } if (previous.mode !== "remote-links" || next.mode !== "remote-links") return true; return ( previous.host.kind === next.host.kind && @@ -113,13 +125,25 @@ const remoteOpenResolutionAtom = Atom.family((environmentId: EnvironmentId) => return UNRESOLVED_REMOTE_OPEN; } const profile = Option.getOrNull(entry.profile); + const isDesktopRenderer = window.desktopBridge !== undefined; + const backendId = + entry.target._tag === "PrimaryConnectionTarget" + ? PRIMARY_LOCAL_ENVIRONMENT_ID + : desktopLocalBackendId(entry.target); + const bootstraps = + isDesktopRenderer && backendId !== null ? get(desktopLocalBootstrapsAtom) : []; + const wslDistro = + backendId !== null + ? (bootstraps.find((bootstrap) => bootstrap.id === backendId)?.runningDistro ?? null) + : null; const next: RemoteOpenResolution = { state: resolveRemoteOpenState({ target: entry.target, sshTarget: profile !== null && profile._tag === "SshConnectionProfile" ? profile.target : null, remoteOpenTargets: presentation?.serverConfig?.remoteOpenTargets, - isDesktopRenderer: window.desktopBridge !== undefined, + isDesktopRenderer, + wslDistro, }), isResolved: true, }; @@ -159,6 +183,11 @@ const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray => { return REMOTE_FALLBACK_EDITORS; }).pipe(Atom.keepAlive, Atom.withLabel("remote-capable-editors")); +export function wslCapableEditors(editors: ReadonlyArray): ReadonlyArray { + const supported = editors.filter((editor) => WSL_REMOTE_EDITOR_IDS.some((id) => id === editor)); + return supported.length > 0 ? supported : REMOTE_FALLBACK_EDITORS; +} + export function useRemoteCapableEditors(): ReadonlyArray { return useAtomValue(remoteCapableEditorsAtom); } diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index da07814b29f6a..29f3b3025bab7 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -1,5 +1,6 @@ // @effect-diagnostics-next-line nodeBuiltinImport:off -- Vite config runs before any Effect runtime. import * as NodeFSP from "node:fs/promises"; +import * as NodeURL from "node:url"; import * as NodeZlib from "node:zlib"; import react from "@vitejs/plugin-react"; @@ -324,10 +325,9 @@ export default defineConfig(() => { resolve: { tsconfigPaths: true, alias: { - "@betteroffice/fonts-cjk": new URL( - "./src/components/files/office/fonts-cjk.ts", - import.meta.url, - ).pathname, + "@betteroffice/fonts-cjk": NodeURL.fileURLToPath( + new URL("./src/components/files/office/fonts-cjk.ts", import.meta.url), + ), }, dedupe: ["react", "react-dom"], }, diff --git a/packages/contracts/src/editor.ts b/packages/contracts/src/editor.ts index 9e0f3f8b82e72..8e2dd132f2f98 100644 --- a/packages/contracts/src/editor.ts +++ b/packages/contracts/src/editor.ts @@ -169,11 +169,41 @@ export const REMOTE_CAPABLE_EDITOR_IDS: ReadonlyArray = EDITORS.flatMa remoteSchemeOf(editor) !== undefined ? [editor.id] : [], ); +export const WSL_REMOTE_EDITOR_IDS = [ + "vscode", + "vscode-insiders", +] as const satisfies ReadonlyArray; + export const remoteSchemeForEditor = (id: EditorId): string | undefined => { const editor = EDITORS.find((candidate) => candidate.id === id); return editor === undefined ? undefined : remoteSchemeOf(editor); }; +export const buildWslOpenUrl = (input: { + readonly editor: EditorId; + readonly distro: string; + readonly absolutePath: string; + readonly isFile?: boolean; + readonly line?: number; + readonly column?: number; +}): string | undefined => { + if ( + !WSL_REMOTE_EDITOR_IDS.some((editor) => editor === input.editor) || + !/^[A-Za-z0-9._-]+$/.test(input.distro) || + !input.absolutePath.startsWith("/") || + input.absolutePath.includes("\\") || + input.absolutePath.split("/").some((segment) => segment === "." || segment === "..") + ) { + return undefined; + } + const scheme = remoteSchemeForEditor(input.editor); + if (scheme === undefined) { + return undefined; + } + const encodedPath = input.absolutePath.split("/").map(encodeURIComponent).join("/"); + return `${scheme}://vscode-remote/wsl+${input.distro}${encodedPath}${input.isFile ? `:${input.line ?? 1}:${input.column ?? 1}` : ""}`; +}; + export const buildRemoteOpenUrl = (input: { readonly editor: EditorId; readonly host: string; From ce6fbc111ffd5528ad0df9bfd6547ce42fb870ce Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sat, 31 Oct 2026 23:50:55 -0400 Subject: [PATCH 02/14] test(web): verify WSL editor labels precisely --- apps/web/src/components/chat/OpenInPicker.browser.test.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx index b9c24abb898a0..d250b5a20edbd 100644 --- a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx +++ b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx @@ -211,8 +211,10 @@ describe("remote editor links", () => { openInCwd: "/home/theo/My Project", }); await click(byLabel("Choose editor")); - const labels = menuItems().map((item) => item.textContent); - expect(labels.some((label) => label?.startsWith("VS Code"))).toBe(true); + const labels = menuItems().map( + (item) => item.querySelector('[data-slot="menu-item-label"]')?.textContent, + ); + expect(labels).toContain("VS Code"); expect(labels).toContain("VS Code Insiders"); expect(labels).not.toContain("Cursor"); From 9fe00f4b54481087e9cdc1bf8f3656b38122e41f Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sat, 31 Oct 2026 23:54:39 -0400 Subject: [PATCH 03/14] chore(web): keep WSL fix focused --- apps/web/vite.config.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 29f3b3025bab7..da07814b29f6a 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -1,6 +1,5 @@ // @effect-diagnostics-next-line nodeBuiltinImport:off -- Vite config runs before any Effect runtime. import * as NodeFSP from "node:fs/promises"; -import * as NodeURL from "node:url"; import * as NodeZlib from "node:zlib"; import react from "@vitejs/plugin-react"; @@ -325,9 +324,10 @@ export default defineConfig(() => { resolve: { tsconfigPaths: true, alias: { - "@betteroffice/fonts-cjk": NodeURL.fileURLToPath( - new URL("./src/components/files/office/fonts-cjk.ts", import.meta.url), - ), + "@betteroffice/fonts-cjk": new URL( + "./src/components/files/office/fonts-cjk.ts", + import.meta.url, + ).pathname, }, dedupe: ["react", "react-dom"], }, From 08b4fca59aa84daabdfc99a0ebd2db54be34335e Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 1 Nov 2026 00:03:20 -0400 Subject: [PATCH 04/14] fix(web): open dot-relative WSL file links --- apps/web/src/markdownFileHostPath.test.ts | 12 ++++++++++++ apps/web/src/markdownFileHostPath.ts | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/web/src/markdownFileHostPath.test.ts b/apps/web/src/markdownFileHostPath.test.ts index 4ab5d477c9b97..a0188d0c2cfe5 100644 --- a/apps/web/src/markdownFileHostPath.test.ts +++ b/apps/web/src/markdownFileHostPath.test.ts @@ -12,4 +12,16 @@ it("opens a relative WSL file at its specified position", () => { column: 3, }), ).toBe("vscode://vscode-remote/wsl+Ubuntu/home/user/project/src/file.ts:12:3"); + for (const path of ["./src/file.ts", "src/../src/file.ts", "/home/user/project/./src/file.ts"]) { + expect( + buildWslMarkdownFileUrl({ + editor: "vscode", + distro: "Ubuntu", + path, + cwd: "/home/user/project", + line: 12, + column: 3, + }), + ).toBe("vscode://vscode-remote/wsl+Ubuntu/home/user/project/src/file.ts:12:3"); + } }); diff --git a/apps/web/src/markdownFileHostPath.ts b/apps/web/src/markdownFileHostPath.ts index cf41287a0bac6..ee6f8a02b0ace 100644 --- a/apps/web/src/markdownFileHostPath.ts +++ b/apps/web/src/markdownFileHostPath.ts @@ -56,10 +56,18 @@ export function buildWslMarkdownFileUrl(input: { line: number | undefined; column: number | undefined; }) { + const path = input.cwd ? resolvePathLinkTarget(input.path, input.cwd) : input.path; + const segments: string[] = []; + if (path.startsWith("/") && !path.includes("\\")) { + for (const segment of path.split("/")) { + if (segment === "..") segments.pop(); + else if (segment !== "" && segment !== ".") segments.push(segment); + } + } return buildWslOpenUrl({ editor: input.editor, distro: input.distro, - absolutePath: input.cwd ? resolvePathLinkTarget(input.path, input.cwd) : input.path, + absolutePath: path.startsWith("/") && !path.includes("\\") ? `/${segments.join("/")}` : path, isFile: true, ...(input.line !== undefined ? { line: input.line } : {}), ...(input.column !== undefined ? { column: input.column } : {}), From 10d49ac37f49f0d26f85c31f623f7fe3d0ba17ca Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 1 Nov 2026 00:17:38 -0400 Subject: [PATCH 05/14] fix(web): resolve WSL links through symlinks --- .../src/workspace/WorkspaceFileSystem.test.ts | 19 ++++++++++++- .../src/workspace/WorkspaceFileSystem.ts | 27 +++++++++++++++---- apps/web/src/components/ChatMarkdown.tsx | 20 ++++++++++++-- apps/web/src/markdownFileHostPath.test.ts | 22 ++++++++++++++- apps/web/src/markdownFileHostPath.ts | 2 +- packages/contracts/src/filesystem.ts | 2 ++ 6 files changed, 82 insertions(+), 10 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index 0f252d600a5ba..137c8c061f170 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -106,6 +106,12 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i null, null, ]); + const unresolved = `${cwd}${path.sep}link${path.sep}..${path.sep}custom-name`; + const realpath = vi.mocked(NodeFSP.realpath).mockResolvedValueOnce(file); + expect( + (yield* service.getMetadata({ paths: [unresolved], resolveRealPath: true })).entries, + ).toEqual([{ kind: "file", byteLength: 5, realPath: file }]); + expect(realpath).toHaveBeenCalledWith(unresolved); }), ); @@ -155,7 +161,11 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i "//attacker.test/s/a.ts", "/\\attacker.test\\s", ]; - expect((yield* service.getMetadata({ paths })).entries).toEqual([null, null, null]); + expect((yield* service.getMetadata({ paths, resolveRealPath: true })).entries).toEqual([ + null, + null, + null, + ]); expect(statted).toEqual([]); }), ); @@ -313,6 +323,13 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i }); expect(result.contents).toBe("beside the target\n"); + const metadata = yield* workspaceFileSystem.getMetadata({ + paths: [`${root}/link/../parent.md`], + resolveRealPath: true, + }); + expect(metadata.entries[0]?.realPath).toBe( + yield* fs.realPath(path.join(root, "target", "parent.md")), + ); }), ); diff --git a/apps/server/src/workspace/WorkspaceFileSystem.ts b/apps/server/src/workspace/WorkspaceFileSystem.ts index e611d2bd71a3d..4ee2e88612438 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.ts @@ -18,6 +18,7 @@ import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; +import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; @@ -142,15 +143,26 @@ export const make = Effect.gen(function* () { const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; const isServerInternalPath = yield* makeIsServerInternalPath; - const metadataForPath = Effect.fnUntraced(function* (requestedPath: string) { + const metadataForPath = Effect.fnUntraced(function* ( + requestedPath: string, + resolveRealPath: boolean, + ) { const expandedPath = expandHomePath(requestedPath, yield* HostProcess.HomeDirectory); // Chips ask as soon as an agent's message renders, and touching a network // path makes Windows sign in to its host with the user's NTLM credentials. if (!path.isAbsolute(expandedPath) || isNetworkPath(expandedPath)) return null; - const stat = yield* fileSystem.stat(expandedPath).pipe(Effect.option); + const resolved = resolveRealPath + ? yield* Effect.tryPromise({ + try: () => NodeFSP.realpath(expandedPath), + catch: () => undefined, + }).pipe(Effect.option) + : Option.some(expandedPath); + if (Option.isNone(resolved)) return null; + const stat = yield* fileSystem.stat(resolved.value).pipe(Effect.option); if (stat._tag === "None") return null; - if (stat.value.type === "Directory") return { kind: "directory" } as const; - if (stat.value.type !== "File") return { kind: "other" } as const; + const realPath = resolveRealPath ? { realPath: resolved.value } : {}; + if (stat.value.type === "Directory") return { kind: "directory", ...realPath } as const; + if (stat.value.type !== "File") return { kind: "other", ...realPath } as const; let mimeType: string | undefined; if (path.extname(expandedPath) === "" && stat.value.size > 0) { mimeType = yield* Effect.tryPromise({ @@ -173,6 +185,7 @@ export const make = Effect.gen(function* () { } return { kind: "file", + ...realPath, byteLength: Number(stat.value.size), ...(mimeType === undefined ? {} : { mimeType }), } satisfies FilesystemEntryMetadata; @@ -182,7 +195,11 @@ export const make = Effect.gen(function* () { "WorkspaceFileSystem.getMetadata", )(function* (input) { const paths = [...new Set(input.paths)]; - const entries = yield* Effect.forEach(paths, metadataForPath, { concurrency: 8 }); + const entries = yield* Effect.forEach( + paths, + (entry) => metadataForPath(entry, input.resolveRealPath === true), + { concurrency: 8 }, + ); const byPath = new Map(paths.map((value, index) => [value, entries[index] ?? null])); return { entries: input.paths.map((value) => byPath.get(value) ?? null) }; }); diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index bfa20920631aa..27941da34522d 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -1,4 +1,8 @@ -import { buildFileLinkParentSuffixByPath, fileLinkLabel } from "@t3tools/shared/fileLinks"; +import { + buildFileLinkParentSuffixByPath, + fileLinkLabel, + resolvePathLinkTarget, +} from "@t3tools/shared/fileLinks"; import { isWindowsDrivePathHref, normalizeMarkdownLinkDestination, @@ -874,7 +878,19 @@ function useChatMarkdownState({ ) { throw new Error("This connection cannot open an editor on this environment."); } - const path = (await resolveHostPath()).absolutePath; + let path = (await resolveHostPath()).absolutePath; + const absolutePath = cwd ? resolvePathLinkTarget(path, cwd) : path; + if (absolutePath.split("/").includes("..")) { + const metadata = await getFilesystemMetadata({ + environmentId, + input: { paths: [absolutePath], resolveRealPath: true }, + }); + const realPath = + metadata._tag === "Success" ? metadata.value.entries[0]?.realPath : undefined; + if (!realPath) + throw new Error("Could not resolve the file path on the WSL environment."); + path = realPath; + } const url = buildWslMarkdownFileUrl({ editor: wslEditor, distro: remoteOpen.state.mode === "wsl-links" ? remoteOpen.state.distro : "", diff --git a/apps/web/src/markdownFileHostPath.test.ts b/apps/web/src/markdownFileHostPath.test.ts index a0188d0c2cfe5..bee4ac3252d9d 100644 --- a/apps/web/src/markdownFileHostPath.test.ts +++ b/apps/web/src/markdownFileHostPath.test.ts @@ -12,7 +12,7 @@ it("opens a relative WSL file at its specified position", () => { column: 3, }), ).toBe("vscode://vscode-remote/wsl+Ubuntu/home/user/project/src/file.ts:12:3"); - for (const path of ["./src/file.ts", "src/../src/file.ts", "/home/user/project/./src/file.ts"]) { + for (const path of ["./src/file.ts", "/home/user/project/./src/file.ts"]) { expect( buildWslMarkdownFileUrl({ editor: "vscode", @@ -24,4 +24,24 @@ it("opens a relative WSL file at its specified position", () => { }), ).toBe("vscode://vscode-remote/wsl+Ubuntu/home/user/project/src/file.ts:12:3"); } + expect( + buildWslMarkdownFileUrl({ + editor: "vscode", + distro: "Ubuntu", + path: "link/../file.ts", + cwd: "/home/user/project", + line: 12, + column: 3, + }), + ).toBeUndefined(); + expect( + buildWslMarkdownFileUrl({ + editor: "vscode", + distro: "Ubuntu", + path: "/opt/pkg/file.ts", + cwd: "/home/user/project", + line: 12, + column: 3, + }), + ).toBe("vscode://vscode-remote/wsl+Ubuntu/opt/pkg/file.ts:12:3"); }); diff --git a/apps/web/src/markdownFileHostPath.ts b/apps/web/src/markdownFileHostPath.ts index ee6f8a02b0ace..57f5c3d406a81 100644 --- a/apps/web/src/markdownFileHostPath.ts +++ b/apps/web/src/markdownFileHostPath.ts @@ -60,7 +60,7 @@ export function buildWslMarkdownFileUrl(input: { const segments: string[] = []; if (path.startsWith("/") && !path.includes("\\")) { for (const segment of path.split("/")) { - if (segment === "..") segments.pop(); + if (segment === "..") return undefined; else if (segment !== "" && segment !== ".") segments.push(segment); } } diff --git a/packages/contracts/src/filesystem.ts b/packages/contracts/src/filesystem.ts index 7270ba78c9acc..dbe1d2f71e01f 100644 --- a/packages/contracts/src/filesystem.ts +++ b/packages/contracts/src/filesystem.ts @@ -7,6 +7,7 @@ export const FILESYSTEM_METADATA_BATCH_LIMIT = 64; export const FilesystemGetMetadataInput = Schema.Struct({ // Absolute host paths, including ~/; clients must anchor relative paths. + resolveRealPath: Schema.optionalKey(Schema.Boolean), paths: Schema.Array( TrimmedNonEmptyString.check(Schema.isMaxLength(FILESYSTEM_PATH_MAX_LENGTH)), ).check(Schema.isMinLength(1), Schema.isMaxLength(FILESYSTEM_METADATA_BATCH_LIMIT)), @@ -15,6 +16,7 @@ export type FilesystemGetMetadataInput = typeof FilesystemGetMetadataInput.Type; export const FilesystemEntryMetadata = Schema.Struct({ kind: Schema.Literals(["file", "directory", "other"]), + realPath: Schema.optionalKey(TrimmedNonEmptyString), byteLength: Schema.optionalKey(NonNegativeInt), mimeType: Schema.optionalKey(TrimmedNonEmptyString), }); From 9bfe4e3faccb6984483a6fd6a062e0d943682b87 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 1 Nov 2026 21:18:13 -0500 Subject: [PATCH 06/14] test(server): check network paths skip realpath --- apps/server/src/workspace/WorkspaceFileSystem.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index 9311ff2dbd39f..c7471f51f584a 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -177,11 +177,13 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i "//attacker.test/s/a.ts", "/\\attacker.test\\s", ]; + const realpath = vi.mocked(NodeFSP.realpath).mockClear(); expect((yield* service.getMetadata({ paths, resolveRealPath: true })).entries).toEqual([ null, null, null, ]); + expect(realpath).not.toHaveBeenCalled(); expect(statted).toEqual([]); }), ); From 8be87f77ac2a6cd4ba23ff2ac26190f4d828be30 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Sun, 1 Nov 2026 21:39:50 -0500 Subject: [PATCH 07/14] fix(desktop): verify WSL editor handlers --- apps/desktop/src/ipc/methods/window.test.ts | 37 ++++++++++++++++++- apps/desktop/src/ipc/methods/window.ts | 22 +++++++++++ apps/web/src/components/ChatMarkdown.tsx | 7 ++-- .../chat/OpenInPicker.browser.test.tsx | 13 +++++++ apps/web/src/components/chat/OpenInPicker.tsx | 5 ++- .../components/chat/OpenInPickerShortcut.ts | 5 ++- apps/web/src/remoteOpen.test.ts | 4 +- apps/web/src/remoteOpen.ts | 16 +++++--- 8 files changed, 92 insertions(+), 17 deletions(-) diff --git a/apps/desktop/src/ipc/methods/window.test.ts b/apps/desktop/src/ipc/methods/window.test.ts index eacc92c94996d..ff068959abcdc 100644 --- a/apps/desktop/src/ipc/methods/window.test.ts +++ b/apps/desktop/src/ipc/methods/window.test.ts @@ -10,11 +10,13 @@ import * as Layer from "effect/Layer"; import * as Option from "effect/Option"; import { vi } from "vite-plus/test"; -const { focusedWebContents, ownerWindow } = vi.hoisted(() => ({ +const { focusedWebContents, ownerWindow, protocolHandler } = vi.hoisted(() => ({ focusedWebContents: vi.fn(), + protocolHandler: vi.fn<(url: string) => Promise<{ path: string }>>(), ownerWindow: vi.fn(), })); vi.mock("electron", () => ({ + app: { getApplicationInfoForProtocol: protocolHandler }, webContents: { getFocusedWebContents: focusedWebContents }, BrowserWindow: { fromWebContents: ownerWindow }, })); @@ -336,3 +338,36 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( assert.include(editors, "webstorm"); }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); + +it.effect("detects Windows VS Code URL handlers independently of PATH", () => + Effect.gen(function* () { + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-wsl-editors-" }); + const executable = path.join(root, "Code - Insiders.exe"); + yield* fs.writeFileString(executable, ""); + protocolHandler.mockReset().mockImplementation(async (url) => ({ + path: url === "vscode-insiders://" ? executable : path.join(root, "missing.exe"), + })); + const editors = yield* probeRemoteEditors + .handler(undefined) + .pipe( + Effect.provideService(HostProcess.Environment, { PATH: "" }), + Effect.provideService(HostProcess.Platform, "win32"), + ); + assert.notInclude(editors, "vscode"); + assert.include(editors, "vscode-insiders"); + protocolHandler.mockImplementation(async (url) => { + if (url === "vscode-insiders://") throw new Error("No handler"); + return { path: executable }; + }); + const stableOnly = yield* probeRemoteEditors + .handler(undefined) + .pipe( + Effect.provideService(HostProcess.Environment, { PATH: "" }), + Effect.provideService(HostProcess.Platform, "win32"), + ); + assert.include(stableOnly, "vscode"); + assert.notInclude(stableOnly, "vscode-insiders"); + }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), +); diff --git a/apps/desktop/src/ipc/methods/window.ts b/apps/desktop/src/ipc/methods/window.ts index 473d1874078be..df84d5b0df5f3 100644 --- a/apps/desktop/src/ipc/methods/window.ts +++ b/apps/desktop/src/ipc/methods/window.ts @@ -9,6 +9,8 @@ import { PickFolderOptionsSchema, PRIMARY_LOCAL_ENVIRONMENT_ID, REMOTE_CAPABLE_EDITOR_IDS, + WSL_REMOTE_EDITOR_IDS, + remoteSchemeForEditor, SystemSettingsPaneSchema, type DesktopEnvironmentBootstrap, type PickedThemeFile, @@ -337,7 +339,27 @@ export const probeRemoteEditors = DesktopIpc.makeIpcMethod({ handler: Effect.fn("desktop.ipc.window.probeRemoteEditors")(function* () { const available: Array = []; const env = yield* HostProcess.Environment; + const platform = yield* HostProcess.Platform; + const fs = yield* FileSystem.FileSystem; for (const editorId of REMOTE_CAPABLE_EDITOR_IDS) { + if (platform === "win32" && WSL_REMOTE_EDITOR_IDS.some((id) => id === editorId)) { + const scheme = remoteSchemeForEditor(editorId); + const handler = + scheme === undefined + ? Option.none() + : yield* Effect.tryPromise({ + try: async () => + (await Electron.app.getApplicationInfoForProtocol(`${scheme}://`)).path, + catch: () => undefined, + }).pipe(Effect.option); + if ( + Option.isSome(handler) && + (yield* fs.exists(handler.value).pipe(Effect.orElseSucceed(() => false))) + ) { + available.push(editorId); + } + continue; + } const editor = EDITORS.find((editor) => editor.id === editorId); if (editor && Option.isSome(yield* resolveEditorCommand(editor, env))) { available.push(editorId); diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 1d94c07a0bcd1..48d4e89492b1a 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -157,9 +157,8 @@ import { cn } from "../lib/utils"; import { openRemoteEditorUrl, resolveRemoteOpenState, - useRemoteCapableEditors, useRemoteOpenResolution, - wslCapableEditors, + useWslCapableEditors, } from "../remoteOpen"; import { useRightPanelStore } from "../rightPanelStore"; import { readThreadShell, useProjects } from "../state/entities"; @@ -641,8 +640,8 @@ function useChatMarkdownState({ markdownServerConfigFieldsAtom(environmentId), ); const projects = useProjects(); - const remoteEditors = useRemoteCapableEditors(); - const [wslEditor] = usePreferredEditor(wslCapableEditors(remoteEditors)); + const wslEditors = useWslCapableEditors(); + const [wslEditor] = usePreferredEditor(wslEditors); const [preferredEditor] = usePreferredEditor(availableEditors); const preferredEditorMenuLabel = openInEditorMenuLabel(preferredEditor); const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors); diff --git a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx index d250b5a20edbd..e3fe594430239 100644 --- a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx +++ b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx @@ -61,6 +61,8 @@ vi.mock(import("../../remoteOpen"), async (importOriginal) => ({ ...(await importOriginal()), useRemoteOpenState: () => state.remote, useRemoteCapableEditors: () => state.clientEditors, + useWslCapableEditors: () => + state.clientEditors.filter((id) => id === "vscode" || id === "vscode-insiders"), useRemoteOpenHint: () => [false, state.markHintSeen] as const, openRemoteEditorUrl: state.openUrl, })); @@ -225,6 +227,17 @@ describe("remote editor links", () => { expect(state.run).not.toHaveBeenCalled(); }); + it("disables WSL editor actions when no supported handler is detected", async () => { + await using fixture = await setup(); + const { renderPicker, primaryButton, pressOpenFavorite } = fixture; + state.remote = { mode: "wsl-links", distro: "Ubuntu" }; + state.clientEditors = ["cursor"]; + await renderPicker(); + expect(primaryButton().disabled).toBe(true); + expect((await pressOpenFavorite()).defaultPrevented).toBe(false); + expect(state.openUrl).not.toHaveBeenCalled(); + }); + it("opens the WSL workspace from the favorite-editor shortcut", async () => { await using fixture = await setup(); const { screen, pressOpenFavorite, FavoriteEditorFallback } = fixture; diff --git a/apps/web/src/components/chat/OpenInPicker.tsx b/apps/web/src/components/chat/OpenInPicker.tsx index 673d77ce5bfb2..9d33843392774 100644 --- a/apps/web/src/components/chat/OpenInPicker.tsx +++ b/apps/web/src/components/chat/OpenInPicker.tsx @@ -16,7 +16,7 @@ import { editorLabelForPlatform } from "../../editorLabels"; import { openRemoteEditorUrl, useRemoteCapableEditors, - wslCapableEditors, + useWslCapableEditors, useRemoteOpenHint, useRemoteOpenState, } from "../../remoteOpen"; @@ -238,6 +238,7 @@ export const OpenInPicker = memo(function OpenInPicker({ const canOpenEditor = remote.mode !== "remote-unavailable" && !isHostEditorDenied; const [menuOpen, setMenuOpen] = useComposerMenuState(isHostEditorDenied); const remoteCapableEditors = useRemoteCapableEditors(); + const wslEditors = useWslCapableEditors(); const [remoteHintSeen, markRemoteHintSeen] = useRemoteOpenHint(); const environmentLabel = useEnvironment(environmentId)?.label ?? "this machine"; // Remote editors run on the viewing machine; only desktop can probe that PATH. @@ -245,7 +246,7 @@ export const OpenInPicker = memo(function OpenInPicker({ remote.mode === "local-exec" ? availableEditors : remote.mode === "wsl-links" - ? wslCapableEditors(remoteCapableEditors) + ? wslEditors : remoteCapableEditors; const [preferredEditor, setPreferredEditor] = usePreferredEditor(effectiveEditors); diff --git a/apps/web/src/components/chat/OpenInPickerShortcut.ts b/apps/web/src/components/chat/OpenInPickerShortcut.ts index 495b260ed6cb9..23057688238b0 100644 --- a/apps/web/src/components/chat/OpenInPickerShortcut.ts +++ b/apps/web/src/components/chat/OpenInPickerShortcut.ts @@ -15,7 +15,7 @@ import { openRemoteEditorUrl, useRemoteCapableEditors, useRemoteOpenState, - wslCapableEditors, + useWslCapableEditors, } from "../../remoteOpen"; import { registerCommands } from "../../shortcuts/dispatcher"; import { shellEnvironment } from "../../state/shell"; @@ -62,12 +62,13 @@ export function useOpenFavoriteEditorShortcut({ const openInEditorMutation = useAtomCommand(shellEnvironment.openInEditor, "open in editor"); const remote = useRemoteOpenState(environmentId); const remoteCapableEditors = useRemoteCapableEditors(); + const wslEditors = useWslCapableEditors(); // Matches the picker: remote editors run on the viewing machine. const effectiveEditors = remote.mode === "local-exec" ? availableEditors : remote.mode === "wsl-links" - ? wslCapableEditors(remoteCapableEditors) + ? wslEditors : remoteCapableEditors; const [preferredEditor] = usePreferredEditor(effectiveEditors); diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.ts index 86d6d9c297c65..2f541d151d3bf 100644 --- a/apps/web/src/remoteOpen.test.ts +++ b/apps/web/src/remoteOpen.test.ts @@ -269,8 +269,8 @@ describe("buildWslOpenUrl", () => { }); describe("wslCapableEditors", () => { - it("retains the VS Code fallback when the probe only finds other editors", () => { - expect(wslCapableEditors(["cursor"])).toEqual(["vscode"]); + it("only offers detected WSL editors", () => { + expect(wslCapableEditors(["cursor"])).toEqual([]); expect(wslCapableEditors(["cursor", "vscode-insiders"])).toEqual(["vscode-insiders"]); }); }); diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index b665d5023407a..d082335741426 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -171,25 +171,29 @@ export function useRemoteOpenState(environmentId: EnvironmentId | null): RemoteO const REMOTE_FALLBACK_EDITORS: ReadonlyArray = ["vscode"]; // Probed once per page: installed editors rarely change, and the probe spawns processes. -const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray => { +const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray | null => { const probe = window.desktopBridge?.probeRemoteEditors; probe?.().then( (ids) => { const remoteCapable = ids.filter((id) => REMOTE_CAPABLE_EDITOR_IDS.includes(id)); - if (remoteCapable.length > 0) get.setSelf(remoteCapable); + get.setSelf(remoteCapable); }, () => undefined, ); - return REMOTE_FALLBACK_EDITORS; + return null; }).pipe(Atom.keepAlive, Atom.withLabel("remote-capable-editors")); export function wslCapableEditors(editors: ReadonlyArray): ReadonlyArray { - const supported = editors.filter((editor) => WSL_REMOTE_EDITOR_IDS.some((id) => id === editor)); - return supported.length > 0 ? supported : REMOTE_FALLBACK_EDITORS; + return editors.filter((editor) => WSL_REMOTE_EDITOR_IDS.some((id) => id === editor)); } export function useRemoteCapableEditors(): ReadonlyArray { - return useAtomValue(remoteCapableEditorsAtom); + const editors = useAtomValue(remoteCapableEditorsAtom); + return editors && editors.length > 0 ? editors : REMOTE_FALLBACK_EDITORS; +} + +export function useWslCapableEditors(): ReadonlyArray { + return wslCapableEditors(useAtomValue(remoteCapableEditorsAtom) ?? []); } /** Resolves false when the desktop refuses the URL, including unsupported editor schemes. */ From 82564076647e135de6823ea48864621daf0d2b24 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Tue, 10 Nov 2026 23:58:34 -0500 Subject: [PATCH 08/14] style(web): format markdown file actions --- apps/web/src/components/ChatMarkdown.tsx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 52e1771cfcb77..3ac3ce1c01aee 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -904,18 +904,18 @@ function useChatMarkdownState({ throw new Error("Could not open the file in VS Code."); return AsyncResult.success(undefined); } - : canOpenApp - ? async () => - openInEditor({ - environmentId, - input: { cwd: (await resolveHostPath()).absolutePath, editor: "file-manager" }, - }) - : canUseShellActions + : canOpenApp ? async () => - openInPreferredEditor( - markdownFileEditorTarget(fileLinkMeta, await resolveHostPath()), - ) - : undefined + openInEditor({ + environmentId, + input: { cwd: (await resolveHostPath()).absolutePath, editor: "file-manager" }, + }) + : canUseShellActions + ? async () => + openInPreferredEditor( + markdownFileEditorTarget(fileLinkMeta, await resolveHostPath()), + ) + : undefined } resolveCopyPaths={async () => markdownFileCopyPaths(fileLinkMeta, await resolveHostPath(), cwd) From eb3c64f4126c08539fb0c7d6c04a2ce7ee1c2680 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 Nov 2026 00:19:15 -0500 Subject: [PATCH 09/14] fix(web): clarify WSL editor errors --- apps/web/src/components/ChatMarkdown.tsx | 94 +++++++++++++----------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 3ac3ce1c01aee..196d62f5b88ce 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -835,6 +835,44 @@ function useChatMarkdownState({ isClientHost && canOperateHost && availableEditors.includes("file-manager"); + const wslDistro = remoteOpen.state.mode === "wsl-links" ? remoteOpen.state.distro : null; + const openInWslEditor = + wslDistro !== null && canOperateHost && wslEditor + ? async () => { + if ( + environmentId === null || + !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope) + ) { + throw new Error("This connection cannot open an editor on this environment."); + } + let path = (await resolveHostPath()).absolutePath; + const absolutePath = cwd ? resolvePathLinkTarget(path, cwd) : path; + if (absolutePath.split("/").includes("..")) { + const metadata = await getFilesystemMetadata({ + environmentId, + input: { paths: [absolutePath], resolveRealPath: true }, + }); + const realPath = + metadata._tag === "Success" ? metadata.value.entries[0]?.realPath : undefined; + if (!realPath) + throw new Error("Could not resolve the file path on the WSL environment."); + path = realPath; + } + const url = buildWslMarkdownFileUrl({ + editor: wslEditor, + distro: wslDistro, + path, + cwd, + line: fileLinkMeta.line, + column: fileLinkMeta.column, + }); + if (!url || !(await openRemoteEditorUrl(url))) + throw new Error( + `Could not open the file. ${openInEditorMenuLabel(wslEditor)} failed.`, + ); + return AsyncResult.success(undefined); + } + : undefined; const mediaPath = mediaSource ?? fileLinkMeta.filePath; const canPreviewMedia = mediaMimeTypeFromExtension( @@ -871,51 +909,19 @@ function useChatMarkdownState({ theme={resolvedTheme} threadRef={threadRef} onOpen={ - remoteOpen.state.mode === "wsl-links" && canOperateHost && wslEditor - ? async () => { - if ( - environmentId === null || - !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope) - ) { - throw new Error("This connection cannot open an editor on this environment."); - } - let path = (await resolveHostPath()).absolutePath; - const absolutePath = cwd ? resolvePathLinkTarget(path, cwd) : path; - if (absolutePath.split("/").includes("..")) { - const metadata = await getFilesystemMetadata({ - environmentId, - input: { paths: [absolutePath], resolveRealPath: true }, - }); - const realPath = - metadata._tag === "Success" ? metadata.value.entries[0]?.realPath : undefined; - if (!realPath) - throw new Error("Could not resolve the file path on the WSL environment."); - path = realPath; - } - const url = buildWslMarkdownFileUrl({ - editor: wslEditor, - distro: remoteOpen.state.mode === "wsl-links" ? remoteOpen.state.distro : "", - path, - cwd, - line: fileLinkMeta.line, - column: fileLinkMeta.column, - }); - if (!url || !(await openRemoteEditorUrl(url))) - throw new Error("Could not open the file in VS Code."); - return AsyncResult.success(undefined); - } - : canOpenApp + openInWslEditor ?? + (canOpenApp + ? async () => + openInEditor({ + environmentId, + input: { cwd: (await resolveHostPath()).absolutePath, editor: "file-manager" }, + }) + : canUseShellActions ? async () => - openInEditor({ - environmentId, - input: { cwd: (await resolveHostPath()).absolutePath, editor: "file-manager" }, - }) - : canUseShellActions - ? async () => - openInPreferredEditor( - markdownFileEditorTarget(fileLinkMeta, await resolveHostPath()), - ) - : undefined + openInPreferredEditor( + markdownFileEditorTarget(fileLinkMeta, await resolveHostPath()), + ) + : undefined) } resolveCopyPaths={async () => markdownFileCopyPaths(fileLinkMeta, await resolveHostPath(), cwd) From 61304780c105717abaae88d7c91d9ef3ce212d45 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 11 Nov 2026 22:42:37 -0500 Subject: [PATCH 10/14] fix(web): resolve WSL markdown folder and home links --- apps/web/src/components/ChatMarkdown.tsx | 11 +++++++++-- apps/web/src/markdown-links.test.ts | 6 ++++++ apps/web/src/markdown-links.ts | 2 ++ apps/web/src/markdownFileHostPath.test.ts | 11 +++++++++++ apps/web/src/markdownFileHostPath.ts | 3 ++- 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index a11159eafba85..8439a0e6202dd 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -859,10 +859,16 @@ function useChatMarkdownState({ } let path = (await resolveHostPath()).absolutePath; const absolutePath = cwd ? resolvePathLinkTarget(path, cwd) : path; - if (absolutePath.split("/").includes("..")) { + const homePath = fileLinkMeta.sourcePath?.startsWith("~/") + ? fileLinkMeta.sourcePath + : undefined; + if (homePath || absolutePath.split("/").includes("..")) { + if (!readEnvironmentScope(environmentId, AuthFilesystemReadScope)) { + throw new Error("This connection cannot read files on this environment."); + } const metadata = await getFilesystemMetadata({ environmentId, - input: { paths: [absolutePath], resolveRealPath: true }, + input: { paths: [homePath ?? absolutePath], resolveRealPath: true }, }); const realPath = metadata._tag === "Success" ? metadata.value.entries[0]?.realPath : undefined; @@ -877,6 +883,7 @@ function useChatMarkdownState({ cwd, line: fileLinkMeta.line, column: fileLinkMeta.column, + isDirectory: (fileLinkMeta.sourcePath ?? fileLinkMeta.filePath).endsWith("/"), }); if (!url || !(await openRemoteEditorUrl(url))) throw new Error( diff --git a/apps/web/src/markdown-links.test.ts b/apps/web/src/markdown-links.test.ts index 4b60a2cad3366..8ba175c8529f5 100644 --- a/apps/web/src/markdown-links.test.ts +++ b/apps/web/src/markdown-links.test.ts @@ -55,6 +55,12 @@ describe("rewriteMarkdownFileUriHref", () => { describe("relative links inside a rendered host file", () => { it("anchor to the file's directory while workspace membership follows cwd", () => { + expect(resolveMarkdownFileLinkMeta("~/notes.md", "/mnt/c/project")).toMatchObject({ + sourcePath: "~/notes.md", + }); + expect(resolveMarkdownFileLinkMeta("docs/", "/mnt/c/project")).toMatchObject({ + sourcePath: "docs/", + }); const meta = resolveMarkdownFileLinkMeta("appendix.md", "/repo", "/tmp/report"); expect(meta).toMatchObject({ filePath: "/tmp/report/appendix.md", diff --git a/apps/web/src/markdown-links.ts b/apps/web/src/markdown-links.ts index 330976746af6b..ae5123ae98a71 100644 --- a/apps/web/src/markdown-links.ts +++ b/apps/web/src/markdown-links.ts @@ -14,6 +14,7 @@ import { isTerminalLinkActivation } from "./terminal-links"; export interface MarkdownFileLinkMeta { filePath: string; + sourcePath?: string; workspaceLookupPath: string | null; targetPath: string; displayPath: string; @@ -85,6 +86,7 @@ export function resolveMarkdownFileLinkMeta( const source = href ? parseMarkdownFileLink(href) : null; return { ...buildFileLinkMetaFromTarget(targetPath, cwd), + ...(source ? { sourcePath: source.path } : {}), ...(source?.endLine !== undefined ? { endLine: source.endLine } : {}), workspaceLookupPath: source !== null && diff --git a/apps/web/src/markdownFileHostPath.test.ts b/apps/web/src/markdownFileHostPath.test.ts index bee4ac3252d9d..6db9c47b5230b 100644 --- a/apps/web/src/markdownFileHostPath.test.ts +++ b/apps/web/src/markdownFileHostPath.test.ts @@ -44,4 +44,15 @@ it("opens a relative WSL file at its specified position", () => { column: 3, }), ).toBe("vscode://vscode-remote/wsl+Ubuntu/opt/pkg/file.ts:12:3"); + expect( + buildWslMarkdownFileUrl({ + editor: "vscode", + distro: "Ubuntu", + path: "/mnt/c/project/docs/", + cwd: "/mnt/c/project", + line: undefined, + column: undefined, + isDirectory: true, + }), + ).toBe("vscode://vscode-remote/wsl+Ubuntu/mnt/c/project/docs"); }); diff --git a/apps/web/src/markdownFileHostPath.ts b/apps/web/src/markdownFileHostPath.ts index 57f5c3d406a81..477097da809e4 100644 --- a/apps/web/src/markdownFileHostPath.ts +++ b/apps/web/src/markdownFileHostPath.ts @@ -55,6 +55,7 @@ export function buildWslMarkdownFileUrl(input: { cwd: string | undefined; line: number | undefined; column: number | undefined; + isDirectory?: boolean; }) { const path = input.cwd ? resolvePathLinkTarget(input.path, input.cwd) : input.path; const segments: string[] = []; @@ -68,7 +69,7 @@ export function buildWslMarkdownFileUrl(input: { editor: input.editor, distro: input.distro, absolutePath: path.startsWith("/") && !path.includes("\\") ? `/${segments.join("/")}` : path, - isFile: true, + isFile: !input.isDirectory, ...(input.line !== undefined ? { line: input.line } : {}), ...(input.column !== undefined ? { column: input.column } : {}), }); From e2e3c50d32780a03fd566a9a50299758df2a32fb Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 20:50:20 +0000 Subject: [PATCH 11/14] refactor(web): keep WSL editor plumbing focused Derive secondary desktop bootstraps in an atom so CommandPalette keeps a stable array, drop the duplicate read type, and cut tests that only mirror assignments or repeat existing behavior. AI-assisted; verified with the tests and tools listed above. --- .../server/src/workspace/WorkspaceFileSystem.test.ts | 6 ------ .../components/chat/OpenInPicker.browser.test.tsx | 12 +----------- .../src/components/chat/OpenInPicker.logic.test.ts | 12 ------------ apps/web/src/connection/desktopLocal.ts | 8 +++----- apps/web/src/connection/platform.ts | 4 ++-- apps/web/src/connection/useDesktopLocalBootstraps.ts | 8 +++++--- apps/web/src/markdown-links.test.ts | 6 ------ apps/web/src/remoteOpen.test.ts | 9 +-------- apps/web/src/remoteOpen.ts | 7 ++----- 9 files changed, 14 insertions(+), 58 deletions(-) diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index 4c163533ad520..3816088d5ba10 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -123,12 +123,6 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i null, null, ]); - const unresolved = `${cwd}${path.sep}link${path.sep}..${path.sep}custom-name`; - const realpath = vi.mocked(NodeFSP.realpath).mockResolvedValueOnce(file); - expect( - (yield* service.getMetadata({ paths: [unresolved], resolveRealPath: true })).entries, - ).toEqual([{ kind: "file", byteLength: 5, realPath: file }]); - expect(realpath).toHaveBeenCalledWith(unresolved); }), ); diff --git a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx index 2cac389ea34cb..a6d9578906f01 100644 --- a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx +++ b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx @@ -229,17 +229,6 @@ describe("remote editor links", () => { expect(state.run).not.toHaveBeenCalled(); }); - it("disables WSL editor actions when no supported handler is detected", async () => { - await using fixture = await setup(); - const { renderPicker, primaryButton, pressOpenFavorite } = fixture; - state.remote = { mode: "wsl-links", distro: "Ubuntu" }; - state.clientEditors = ["cursor"]; - await renderPicker(); - expect(primaryButton().disabled).toBe(true); - expect((await pressOpenFavorite()).defaultPrevented).toBe(false); - expect(state.openUrl).not.toHaveBeenCalled(); - }); - it("opens the WSL workspace from the favorite-editor shortcut", async () => { await using fixture = await setup(); const { screen, pressOpenFavorite, FavoriteEditorFallback } = fixture; @@ -255,6 +244,7 @@ describe("remote editor links", () => { ); expect(state.run).not.toHaveBeenCalled(); }); + it("explains why a phone or tablet browser has no editor to open", async () => { await using fixture = await setup(); const { renderPicker, byLabel, primaryButton, menuItems, click, pressOpenFavorite } = fixture; diff --git a/apps/web/src/components/chat/OpenInPicker.logic.test.ts b/apps/web/src/components/chat/OpenInPicker.logic.test.ts index 9a9d0559edda5..371a8532901dc 100644 --- a/apps/web/src/components/chat/OpenInPicker.logic.test.ts +++ b/apps/web/src/components/chat/OpenInPicker.logic.test.ts @@ -19,18 +19,6 @@ describe("shouldShowOpenInPicker", () => { ).toBe(true); }); - it("keeps other secondary local environments hidden", () => { - expect( - shouldShowOpenInPicker({ - activeProjectName: "project", - activeThreadEnvironmentId: secondary, - primaryEnvironmentId: primary, - hostEnvironmentId: null, - remoteOpenMode: "local-exec", - }), - ).toBe(false); - }); - it("shows both local environments when the primary has a separate WSL home", () => { const primaryEnvironmentId = EnvironmentId.make("wsl"); const hostEnvironmentId = EnvironmentId.make("host"); diff --git a/apps/web/src/connection/desktopLocal.ts b/apps/web/src/connection/desktopLocal.ts index 8ff2be07d217e..335ea102cb170 100644 --- a/apps/web/src/connection/desktopLocal.ts +++ b/apps/web/src/connection/desktopLocal.ts @@ -36,10 +36,8 @@ export type DesktopBootstrapsRead = readonly cause: unknown; }; -export type DesktopSecondaryBootstrapsRead = DesktopBootstrapsRead; - export interface DesktopSecondaryBootstrapsReader { - readonly readResult: () => DesktopSecondaryBootstrapsRead; + readonly readResult: () => DesktopBootstrapsRead; readonly readSnapshot: () => ReadonlyArray; readonly readAllResult: () => DesktopBootstrapsRead; readonly readAllSnapshot: () => ReadonlyArray; @@ -93,7 +91,7 @@ export function createDesktopSecondaryBootstrapsReader( } }; - const readResult = (): DesktopSecondaryBootstrapsRead => { + const readResult = (): DesktopBootstrapsRead => { const result = readAllResult(); return result._tag === "Success" ? { _tag: "Success", bootstraps: snapshot } : result; }; @@ -114,7 +112,7 @@ export function createDesktopSecondaryBootstrapsReader( const desktopBootstrapsReader = createDesktopSecondaryBootstrapsReader(() => window.desktopBridge); -export function readDesktopSecondaryBootstrapsResult(): DesktopSecondaryBootstrapsRead { +export function readDesktopSecondaryBootstrapsResult(): DesktopBootstrapsRead { return desktopBootstrapsReader.readResult(); } diff --git a/apps/web/src/connection/platform.ts b/apps/web/src/connection/platform.ts index dcd50342f1c91..b87651fda0f53 100644 --- a/apps/web/src/connection/platform.ts +++ b/apps/web/src/connection/platform.ts @@ -58,7 +58,7 @@ import { acknowledgeRpcRequest, trackRpcRequestSent } from "../rpc/requestLatenc import { desktopLocalConnectionId, readDesktopSecondaryBootstrapsResult, - type DesktopSecondaryBootstrapsRead, + type DesktopBootstrapsRead, } from "./desktopLocal"; import * as ConnectionStorage from "./storage"; import { clientPresentationMetadata } from "./clientMetadata"; @@ -610,7 +610,7 @@ export function isRejectedBootstrapCredentialError(error: ConnectionAttemptError export function secondaryRegistrationsToRetainAfterTopologyRead( previous: ReadonlyMap, - topologyRead: DesktopSecondaryBootstrapsRead, + topologyRead: DesktopBootstrapsRead, nowEpochMs: number, ): ReadonlyMap { if (topologyRead._tag === "Success") { diff --git a/apps/web/src/connection/useDesktopLocalBootstraps.ts b/apps/web/src/connection/useDesktopLocalBootstraps.ts index 8a700b30b0816..aab3869551084 100644 --- a/apps/web/src/connection/useDesktopLocalBootstraps.ts +++ b/apps/web/src/connection/useDesktopLocalBootstraps.ts @@ -21,8 +21,10 @@ export const desktopLocalBootstrapsAtom = Atom.make((get) => { return readDesktopLocalBootstraps(); }).pipe(Atom.withLabel("desktop-local-bootstraps")); +const desktopSecondaryBootstrapsAtom = Atom.make((get) => + get(desktopLocalBootstrapsAtom).filter((entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID), +).pipe(Atom.withLabel("desktop-secondary-bootstraps")); + export function useDesktopLocalBootstraps() { - return useAtomValue(desktopLocalBootstrapsAtom).filter( - (entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID, - ); + return useAtomValue(desktopSecondaryBootstrapsAtom); } diff --git a/apps/web/src/markdown-links.test.ts b/apps/web/src/markdown-links.test.ts index 8ba175c8529f5..4b60a2cad3366 100644 --- a/apps/web/src/markdown-links.test.ts +++ b/apps/web/src/markdown-links.test.ts @@ -55,12 +55,6 @@ describe("rewriteMarkdownFileUriHref", () => { describe("relative links inside a rendered host file", () => { it("anchor to the file's directory while workspace membership follows cwd", () => { - expect(resolveMarkdownFileLinkMeta("~/notes.md", "/mnt/c/project")).toMatchObject({ - sourcePath: "~/notes.md", - }); - expect(resolveMarkdownFileLinkMeta("docs/", "/mnt/c/project")).toMatchObject({ - sourcePath: "docs/", - }); const meta = resolveMarkdownFileLinkMeta("appendix.md", "/repo", "/tmp/report"); expect(meta).toMatchObject({ filePath: "/tmp/report/appendix.md", diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.ts index 5e377cd920b35..ccf85c9b16456 100644 --- a/apps/web/src/remoteOpen.test.ts +++ b/apps/web/src/remoteOpen.test.ts @@ -7,7 +7,7 @@ import { import { buildRemoteOpenUrl, buildWslOpenUrl, EnvironmentId } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; -import { remoteFallbackEditors, resolveRemoteOpenState, wslCapableEditors } from "./remoteOpen"; +import { remoteFallbackEditors, resolveRemoteOpenState } from "./remoteOpen"; const environmentId = EnvironmentId.make("environment-1"); @@ -369,10 +369,3 @@ describe("buildWslOpenUrl", () => { ).toBeUndefined(); }); }); - -describe("wslCapableEditors", () => { - it("only offers detected WSL editors", () => { - expect(wslCapableEditors(["cursor"])).toEqual([]); - expect(wslCapableEditors(["cursor", "vscode-insiders"])).toEqual(["vscode-insiders"]); - }); -}); diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index 35a958c52b12c..1c482583899b0 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -193,17 +193,14 @@ const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray | null return null; }).pipe(Atom.keepAlive, Atom.withLabel("remote-capable-editors")); -export function wslCapableEditors(editors: ReadonlyArray): ReadonlyArray { - return editors.filter((editor) => WSL_REMOTE_EDITOR_IDS.some((id) => id === editor)); -} - export function useRemoteCapableEditors(): ReadonlyArray { const editors = useAtomValue(remoteCapableEditorsAtom); return editors && editors.length > 0 ? editors : remoteFallbackEditors(navigator); } export function useWslCapableEditors(): ReadonlyArray { - return wslCapableEditors(useAtomValue(remoteCapableEditorsAtom) ?? []); + const editors = useAtomValue(remoteCapableEditorsAtom) ?? []; + return editors.filter((editor) => WSL_REMOTE_EDITOR_IDS.some((id) => id === editor)); } /** Resolves false when the desktop refuses the URL, including unsupported editor schemes. */ From df3948583db1274e898950e8f3c45c921387b41c Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Thu, 12 Nov 2026 21:00:59 +0000 Subject: [PATCH 12/14] fix(web): open WSL backends through their own editors Drop the vscode-remote URL path: in WSL-only mode it replaced the primary's own editors with VS Code alone. Desktop-managed WSL backends already open editors locally through Windows interop, as the WSL-only primary does, so show their Open-in picker and shortcut instead. AI-assisted; verified with the tests and tools listed above. --- .../src/electron/ElectronShell.test.ts | 37 +------- apps/desktop/src/electron/ElectronShell.ts | 22 +---- apps/desktop/src/ipc/methods/window.test.ts | 37 +------- apps/desktop/src/ipc/methods/window.ts | 22 ----- .../src/workspace/WorkspaceFileSystem.test.ts | 15 +--- .../src/workspace/WorkspaceFileSystem.ts | 28 ++---- apps/web/src/components/ChatMarkdown.tsx | 74 ++-------------- .../web/src/components/ChatView.logic.test.ts | 1 + apps/web/src/components/ChatView.tsx | 4 + .../chat/OpenInPicker.browser.test.tsx | 46 +--------- .../chat/OpenInPicker.logic.test.ts | 29 +++---- .../src/components/chat/OpenInPicker.logic.ts | 3 + apps/web/src/components/chat/OpenInPicker.tsx | 23 +---- .../components/chat/OpenInPickerShortcut.ts | 31 +------ apps/web/src/connection/desktopLocal.test.ts | 20 ++--- apps/web/src/connection/desktopLocal.ts | 59 +++++-------- apps/web/src/connection/platform.ts | 4 +- .../connection/useDesktopLocalBootstraps.ts | 18 ++-- apps/web/src/markdown-links.ts | 2 - apps/web/src/markdownFileHostPath.test.ts | 58 ------------- apps/web/src/markdownFileHostPath.ts | 28 ------ apps/web/src/remoteOpen.test.ts | 85 +------------------ apps/web/src/remoteOpen.ts | 42 ++------- packages/contracts/src/editor.ts | 30 ------- packages/contracts/src/filesystem.ts | 2 - 25 files changed, 91 insertions(+), 629 deletions(-) delete mode 100644 apps/web/src/markdownFileHostPath.test.ts diff --git a/apps/desktop/src/electron/ElectronShell.test.ts b/apps/desktop/src/electron/ElectronShell.test.ts index 3c7bdcd47a928..e8618b4f5cc4d 100644 --- a/apps/desktop/src/electron/ElectronShell.test.ts +++ b/apps/desktop/src/electron/ElectronShell.test.ts @@ -40,25 +40,6 @@ describe("ElectronShell", () => { }).pipe(Effect.provide(ElectronShell.layer)), ); - it.effect("opens VS Code Remote - WSL URLs", () => - Effect.gen(function* () { - openExternalMock.mockResolvedValue(undefined); - - const electronShell = yield* ElectronShell.ElectronShell; - const urls = [ - "vscode://vscode-remote/wsl+Ubuntu/home/user/My%20Project", - "vscode-insiders://vscode-remote/wsl+Debian/home/user/project", - ]; - const results = yield* Effect.forEach(urls, (url) => electronShell.openExternal(url)); - - assert.deepEqual(results, [true, true]); - assert.deepEqual( - openExternalMock.mock.calls, - urls.map((url) => [url]), - ); - }).pipe(Effect.provide(ElectronShell.layer)), - ); - it.effect("opens the JetBrains Toolbox ssh deep link", () => Effect.gen(function* () { openExternalMock.mockResolvedValue(undefined); @@ -169,28 +150,12 @@ describe("ElectronShell", () => { const results = yield* Effect.all([ electronShell.openExternal("zed://extension/attacker"), electronShell.openExternal("vscode://ssh/example.com/home/user/project"), - electronShell.openExternal("vscode://vscode-remote/wsl+bad!distro/home/user/project"), - electronShell.openExternal("cursor://vscode-remote/wsl+Ubuntu/home/user/project"), - electronShell.openExternal("vscode://vscode-remote/wsl+Ubuntu"), - electronShell.openExternal("vscode://vscode-remote/wsl+Ubuntu/home/%2Fetc"), - electronShell.openExternal("vscode://vscode-remote/wsl+Ubuntu/home/user/project?x=1"), electronShell.openExternal("jetbrains://idea/navigate/reference?project=x&path=y"), electronShell.openExternal("jetbrains://gateway/ssh/environment?launchIde=true"), electronShell.openExternal("jetbrains://gateway/com.example.provider/connect?h=x"), ]); - assert.deepEqual(results, [ - false, - false, - false, - false, - false, - false, - false, - false, - false, - false, - ]); + assert.deepEqual(results, [false, false, 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.ts index 5aa67e13c3e15..d27c51d57c6eb 100644 --- a/apps/desktop/src/electron/ElectronShell.ts +++ b/apps/desktop/src/electron/ElectronShell.ts @@ -35,21 +35,6 @@ const isAppLaunchUrl = (url: URL) => // Zed embeds [user@]host in the path; reject passwords and ports there. const ZED_SSH_PATHNAME = /^\/(?:[^/@:]+@)?[^/@:]+\/.*$/; -function isValidWslRemotePath(pathname: string): boolean { - const match = /^\/wsl\+[A-Za-z0-9._-]+\/(.*)$/.exec(pathname); - if (!match || pathname.includes("\\") || /%(?:2f|5c)/i.test(pathname)) { - return false; - } - try { - return match[1]!.split("/").every((segment) => { - const decoded = decodeURIComponent(segment); - return decoded !== "." && decoded !== ".." && !/[\u0000-\u001f\u007f\\]/.test(decoded); - }); - } catch { - return false; - } -} - const isRemoteEditorUrl = (url: URL) => REMOTE_EDITOR_PROTOCOLS.has(url.protocol) && url.username.length === 0 && @@ -61,11 +46,8 @@ const isRemoteEditorUrl = (url: URL) => url.pathname === "/ssh/environment" && (url.searchParams.get("h") ?? "").length > 0 : url.host === "vscode-remote" && - ((url.pathname.startsWith("/ssh-remote+") && url.pathname.length > "/ssh-remote+".length) || - ((url.protocol === "vscode:" || url.protocol === "vscode-insiders:") && - url.search.length === 0 && - url.hash.length === 0 && - isValidWslRemotePath(url.pathname)))); + url.pathname.startsWith("/ssh-remote+") && + url.pathname.length > "/ssh-remote+".length); export function parseSafeExternalUrl(rawUrl: unknown): Option.Option { if (typeof rawUrl !== "string") { diff --git a/apps/desktop/src/ipc/methods/window.test.ts b/apps/desktop/src/ipc/methods/window.test.ts index 5a3fdc4ed6181..376f85d2baf9d 100644 --- a/apps/desktop/src/ipc/methods/window.test.ts +++ b/apps/desktop/src/ipc/methods/window.test.ts @@ -11,13 +11,11 @@ import * as Option from "effect/Option"; import { vi } from "vite-plus/test"; import type * as Electron from "electron"; -const { focusedWebContents, ownerWindow, protocolHandler } = vi.hoisted(() => ({ +const { focusedWebContents, ownerWindow } = vi.hoisted(() => ({ focusedWebContents: vi.fn(), - protocolHandler: vi.fn<(url: string) => Promise<{ path: string }>>(), ownerWindow: vi.fn(), })); vi.mock("electron", () => ({ - app: { getApplicationInfoForProtocol: protocolHandler }, webContents: { getFocusedWebContents: focusedWebContents }, BrowserWindow: { fromWebContents: ownerWindow }, })); @@ -476,36 +474,3 @@ it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")( assert.include(editors, "webstorm"); }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), ); - -it.effect("detects Windows VS Code URL handlers independently of PATH", () => - Effect.gen(function* () { - const fs = yield* FileSystem.FileSystem; - const path = yield* Path.Path; - const root = yield* fs.makeTempDirectoryScoped({ prefix: "t3-wsl-editors-" }); - const executable = path.join(root, "Code - Insiders.exe"); - yield* fs.writeFileString(executable, ""); - protocolHandler.mockReset().mockImplementation(async (url) => ({ - path: url === "vscode-insiders://" ? executable : path.join(root, "missing.exe"), - })); - const editors = yield* probeRemoteEditors - .handler(undefined) - .pipe( - Effect.provideService(HostProcess.Environment, { PATH: "" }), - Effect.provideService(HostProcess.Platform, "win32"), - ); - assert.notInclude(editors, "vscode"); - assert.include(editors, "vscode-insiders"); - protocolHandler.mockImplementation(async (url) => { - if (url === "vscode-insiders://") throw new Error("No handler"); - return { path: executable }; - }); - const stableOnly = yield* probeRemoteEditors - .handler(undefined) - .pipe( - Effect.provideService(HostProcess.Environment, { PATH: "" }), - Effect.provideService(HostProcess.Platform, "win32"), - ); - assert.include(stableOnly, "vscode"); - assert.notInclude(stableOnly, "vscode-insiders"); - }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)), -); diff --git a/apps/desktop/src/ipc/methods/window.ts b/apps/desktop/src/ipc/methods/window.ts index 5f53846b34d10..53a1138d71a99 100644 --- a/apps/desktop/src/ipc/methods/window.ts +++ b/apps/desktop/src/ipc/methods/window.ts @@ -10,8 +10,6 @@ import { PickFolderOptionsSchema, PRIMARY_LOCAL_ENVIRONMENT_ID, REMOTE_CAPABLE_EDITOR_IDS, - WSL_REMOTE_EDITOR_IDS, - remoteSchemeForEditor, SystemSettingsPaneSchema, type DesktopEnvironmentBootstrap, type PickedThemeFile, @@ -409,27 +407,7 @@ export const probeRemoteEditors = DesktopIpc.makeIpcMethod({ handler: Effect.fn("desktop.ipc.window.probeRemoteEditors")(function* () { const available: Array = []; const env = yield* HostProcess.Environment; - const platform = yield* HostProcess.Platform; - const fs = yield* FileSystem.FileSystem; for (const editorId of REMOTE_CAPABLE_EDITOR_IDS) { - if (platform === "win32" && WSL_REMOTE_EDITOR_IDS.some((id) => id === editorId)) { - const scheme = remoteSchemeForEditor(editorId); - const handler = - scheme === undefined - ? Option.none() - : yield* Effect.tryPromise({ - try: async () => - (await Electron.app.getApplicationInfoForProtocol(`${scheme}://`)).path, - catch: () => undefined, - }).pipe(Effect.option); - if ( - Option.isSome(handler) && - (yield* fs.exists(handler.value).pipe(Effect.orElseSucceed(() => false))) - ) { - available.push(editorId); - } - continue; - } const editor = EDITORS.find((editor) => editor.id === editorId); if (editor && Option.isSome(yield* resolveEditorCommand(editor, env))) { available.push(editorId); diff --git a/apps/server/src/workspace/WorkspaceFileSystem.test.ts b/apps/server/src/workspace/WorkspaceFileSystem.test.ts index 3816088d5ba10..26e444c1032d6 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.test.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.test.ts @@ -172,13 +172,7 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i "//attacker.test/s/a.ts", "/\\attacker.test\\s", ]; - const realpath = vi.mocked(NodeFSP.realpath).mockClear(); - expect((yield* service.getMetadata({ paths, resolveRealPath: true })).entries).toEqual([ - null, - null, - null, - ]); - expect(realpath).not.toHaveBeenCalled(); + expect((yield* service.getMetadata({ paths })).entries).toEqual([null, null, null]); expect(statted).toEqual([]); }), ); @@ -395,13 +389,6 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i }); expect(result.contents).toBe("beside the target\n"); - const metadata = yield* workspaceFileSystem.getMetadata({ - paths: [`${root}/link/../parent.md`], - resolveRealPath: true, - }); - expect(metadata.entries[0]?.realPath).toBe( - yield* fs.realPath(path.join(root, "target", "parent.md")), - ); }), ); diff --git a/apps/server/src/workspace/WorkspaceFileSystem.ts b/apps/server/src/workspace/WorkspaceFileSystem.ts index 02728b5b6c2e9..2f3823f97e477 100644 --- a/apps/server/src/workspace/WorkspaceFileSystem.ts +++ b/apps/server/src/workspace/WorkspaceFileSystem.ts @@ -18,7 +18,6 @@ import * as Context from "effect/Context"; import * as Effect from "effect/Effect"; import * as FileSystem from "effect/FileSystem"; import * as Layer from "effect/Layer"; -import * as Option from "effect/Option"; import * as Path from "effect/Path"; import * as Schema from "effect/Schema"; @@ -143,26 +142,16 @@ export const make = Effect.gen(function* () { const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries; const isServerInternalPath = yield* makeIsServerInternalPath; - const metadataForPath = Effect.fnUntraced(function* ( - requestedPath: string, - resolveRealPath: boolean, - ) { + const metadataForPath = Effect.fnUntraced(function* (requestedPath: string) { const expandedPath = expandHomePath(requestedPath, yield* HostProcess.HomeDirectory); // Chips ask as soon as an agent's message renders, and touching a network // path makes Windows sign in to its host with the user's NTLM credentials. if (!path.isAbsolute(expandedPath) || isNetworkPath(expandedPath)) return null; - const resolved = resolveRealPath - ? yield* Effect.tryPromise({ - try: () => NodeFSP.realpath(expandedPath), - catch: () => undefined, - }).pipe(Effect.option) - : Option.some(expandedPath); - if (Option.isNone(resolved)) return null; - const stat = yield* fileSystem.stat(resolved.value).pipe(Effect.option); + const stat = yield* fileSystem.stat(expandedPath).pipe(Effect.option); + // Server state files answer like missing paths, as readFile refuses them. if (stat._tag === "None" || (yield* isServerInternalPath(expandedPath))) return null; - const realPath = resolveRealPath ? { realPath: resolved.value } : {}; - if (stat.value.type === "Directory") return { kind: "directory", ...realPath } as const; - if (stat.value.type !== "File") return { kind: "other", ...realPath } as const; + if (stat.value.type === "Directory") return { kind: "directory" } as const; + if (stat.value.type !== "File") return { kind: "other" } as const; let mimeType: string | undefined; if (path.extname(expandedPath) === "" && stat.value.size > 0) { mimeType = yield* Effect.tryPromise({ @@ -185,7 +174,6 @@ export const make = Effect.gen(function* () { } return { kind: "file", - ...realPath, byteLength: Number(stat.value.size), ...(mimeType === undefined ? {} : { mimeType }), } satisfies FilesystemEntryMetadata; @@ -195,11 +183,7 @@ export const make = Effect.gen(function* () { "WorkspaceFileSystem.getMetadata", )(function* (input) { const paths = [...new Set(input.paths)]; - const entries = yield* Effect.forEach( - paths, - (entry) => metadataForPath(entry, input.resolveRealPath === true), - { concurrency: 8 }, - ); + const entries = yield* Effect.forEach(paths, metadataForPath, { concurrency: 8 }); const byPath = new Map(paths.map((value, index) => [value, entries[index] ?? null])); return { entries: input.paths.map((value) => byPath.get(value) ?? null) }; }); diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index b2397fa60cfb1..d2248c3af708e 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -1,9 +1,5 @@ -import { - buildFileLinkParentSuffixByPath, - fileLinkLabel, - resolvePathLinkTarget, -} from "@t3tools/shared/fileLinks"; import { clientHostEnvironmentAtom } from "../state/clientHostEnvironment"; +import { buildFileLinkParentSuffixByPath, fileLinkLabel } from "@t3tools/shared/fileLinks"; import { isWindowsDrivePathHref, normalizeMarkdownLinkDestination, @@ -150,7 +146,6 @@ import { } from "../markdown-links"; import { markdownFileCopyPaths, - buildWslMarkdownFileUrl, markdownFileEditorTarget, resolveMarkdownFileHostPath, } from "../markdownFileHostPath"; @@ -160,12 +155,7 @@ import { readLocalApi } from "../localApi"; import { appAtomRegistry } from "../rpc/atomRegistry"; import { hostEnvironmentIdAtom } from "../state/primaryEnvironment"; import { cn } from "../lib/utils"; -import { - openRemoteEditorUrl, - resolveRemoteOpenState, - useRemoteOpenResolution, - useWslCapableEditors, -} from "../remoteOpen"; +import { resolveRemoteOpenState, useRemoteOpenResolution } from "../remoteOpen"; import { useRightPanelStore } from "../rightPanelStore"; import { readThreadShell, useProjects } from "../state/entities"; import { serverEnvironment } from "../state/server"; @@ -655,8 +645,6 @@ function useChatMarkdownState({ markdownServerConfigFieldsAtom(environmentId), ); const projects = useProjects(); - const wslEditors = useWslCapableEditors(); - const [wslEditor] = usePreferredEditor(wslEditors); const [preferredEditor] = usePreferredEditor(availableEditors); const preferredEditorMenuLabel = openInEditorMenuLabel(preferredEditor); const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors); @@ -882,51 +870,6 @@ function useChatMarkdownState({ isClientHost && canOperateHost && availableEditors.includes("file-manager"); - const wslDistro = remoteOpen.state.mode === "wsl-links" ? remoteOpen.state.distro : null; - const openInWslEditor = - wslDistro !== null && canOperateHost && wslEditor - ? async () => { - if ( - environmentId === null || - !readEnvironmentScope(environmentId, AuthOrchestrationOperateScope) - ) { - throw new Error("This connection cannot open an editor on this environment."); - } - let path = (await resolveHostPath()).absolutePath; - const absolutePath = cwd ? resolvePathLinkTarget(path, cwd) : path; - const homePath = fileLinkMeta.sourcePath?.startsWith("~/") - ? fileLinkMeta.sourcePath - : undefined; - if (homePath || absolutePath.split("/").includes("..")) { - if (!readEnvironmentScope(environmentId, AuthFilesystemReadScope)) { - throw new Error("This connection cannot read files on this environment."); - } - const metadata = await getFilesystemMetadata({ - environmentId, - input: { paths: [homePath ?? absolutePath], resolveRealPath: true }, - }); - const realPath = - metadata._tag === "Success" ? metadata.value.entries[0]?.realPath : undefined; - if (!realPath) - throw new Error("Could not resolve the file path on the WSL environment."); - path = realPath; - } - const url = buildWslMarkdownFileUrl({ - editor: wslEditor, - distro: wslDistro, - path, - cwd, - line: fileLinkMeta.line, - column: fileLinkMeta.column, - isDirectory: (fileLinkMeta.sourcePath ?? fileLinkMeta.filePath).endsWith("/"), - }); - if (!url || !(await openRemoteEditorUrl(url))) - throw new Error( - `Could not open the file. ${openInEditorMenuLabel(wslEditor)} failed.`, - ); - return AsyncResult.success(undefined); - } - : undefined; const mediaPath = mediaSource ?? fileLinkMeta.filePath; const canPreviewMedia = mediaMimeTypeFromExtension( @@ -963,8 +906,7 @@ function useChatMarkdownState({ theme={resolvedTheme} threadRef={threadRef} onOpen={ - openInWslEditor ?? - (canOpenApp + canOpenApp ? async () => openInEditor({ environmentId, @@ -975,7 +917,7 @@ function useChatMarkdownState({ openInPreferredEditor( markdownFileEditorTarget(fileLinkMeta, await resolveHostPath()), ) - : undefined) + : undefined } resolveCopyPaths={async () => markdownFileCopyPaths(fileLinkMeta, await resolveHostPath(), cwd) @@ -986,13 +928,7 @@ function useChatMarkdownState({ ? () => openMarkdownMedia(mediaPath, fileLinkMeta.filePath) : undefined } - openInEditorMenuLabel={ - remoteOpen.state.mode === "wsl-links" - ? openInEditorMenuLabel(wslEditor) - : canOpenApp - ? "Open app" - : preferredEditorMenuLabel - } + openInEditorMenuLabel={canOpenApp ? "Open app" : preferredEditorMenuLabel} onReveal={ canUseShellActions && revealInFileManagerLabel !== undefined ? async () => revealFileInFileManager((await resolveHostPath()).absolutePath) diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts index 8223e03540405..7d8156ada3381 100644 --- a/apps/web/src/components/ChatView.logic.test.ts +++ b/apps/web/src/components/ChatView.logic.test.ts @@ -1388,6 +1388,7 @@ describe("Open in for the host environment", () => { primaryEnvironmentId, hostEnvironmentId, remoteOpenMode: "local-exec", + isDesktopWslBackend: false, }), ).toBe(visible); } diff --git a/apps/web/src/components/ChatView.tsx b/apps/web/src/components/ChatView.tsx index fdbb91d9073ff..56b731dfa1c4f 100644 --- a/apps/web/src/components/ChatView.tsx +++ b/apps/web/src/components/ChatView.tsx @@ -290,6 +290,8 @@ import { ChatHeader } from "./chat/ChatHeader"; import { useSideChat } from "./chat/useSideChat"; import { useRemoteOpenState } from "~/remoteOpen"; import { shouldShowOpenInPicker } from "./chat/OpenInPicker.logic"; +import { isDesktopWslTarget } from "../connection/desktopLocal"; +import { useEnvironmentPresentation } from "../state/presentation"; import { useOpenFavoriteEditorShortcut } from "./chat/OpenInPickerShortcut"; import { PanelLayoutControls, @@ -1652,12 +1654,14 @@ export default function ChatView(props: ChatViewProps) { useAtomValue(serverEnvironment.configValueAtom(openInEnvironmentId))?.availableEditors ?? []; const hostEnvironmentId = useAtomValue(hostEnvironmentIdAtom); const remoteOpenState = useRemoteOpenState(openInEnvironmentId); + const openInTarget = useEnvironmentPresentation(openInEnvironmentId).presentation?.entry.target; const showOpenInPicker = shouldShowOpenInPicker({ activeProjectName: activeProject?.title, activeThreadEnvironmentId: openInEnvironmentId, primaryEnvironmentId: primaryEnvironment?.environmentId ?? null, hostEnvironmentId, remoteOpenMode: remoteOpenState.mode, + isDesktopWslBackend: isDesktopWslTarget(openInTarget), }); useOpenFavoriteEditorShortcut({ enabled: showOpenInPicker && !backgroundThread, diff --git a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx index a6d9578906f01..da9d7d50a5396 100644 --- a/apps/web/src/components/chat/OpenInPicker.browser.test.tsx +++ b/apps/web/src/components/chat/OpenInPicker.browser.test.tsx @@ -61,8 +61,6 @@ vi.mock(import("../../remoteOpen"), async (importOriginal) => ({ ...(await importOriginal()), useRemoteOpenState: () => state.remote, useRemoteCapableEditors: () => state.clientEditors, - useWslCapableEditors: () => - state.clientEditors.filter((id) => id === "vscode" || id === "vscode-insiders"), useRemoteOpenHint: () => [false, state.markHintSeen] as const, openRemoteEditorUrl: state.openUrl, })); @@ -144,13 +142,13 @@ async function setup() { return event; } - function FavoriteEditorFallback({ openInCwd = "/work/project" }: { openInCwd?: string }) { + function FavoriteEditorFallback() { useOpenFavoriteEditorShortcut({ enabled: true, environmentId: selected, keybindings: DEFAULT_RESOLVED_KEYBINDINGS, availableEditors: editors, - openInCwd, + openInCwd: "/work/project", }); return null; } @@ -205,46 +203,6 @@ describe("remote editor links", () => { expect(state.run).not.toHaveBeenCalled(); }); - it("opens a WSL workspace through VS Code Remote - WSL and offers only VS Code variants", async () => { - await using fixture = await setup(); - const { renderPicker, byLabel, menuItems, click, primaryButton } = fixture; - state.remote = { mode: "wsl-links", distro: "Ubuntu" }; - state.clientEditors = ["cursor", "vscode-insiders", "vscode"]; - - await renderPicker(["vscode", "cursor"], false, { - openInCwd: "/home/theo/My Project", - }); - await click(byLabel("Choose editor")); - const labels = menuItems().map( - (item) => item.querySelector('[data-slot="menu-item-label"]')?.textContent, - ); - expect(labels).toContain("VS Code"); - expect(labels).toContain("VS Code Insiders"); - expect(labels).not.toContain("Cursor"); - - await click(primaryButton()); - expect(state.openUrl).toHaveBeenCalledWith( - "vscode://vscode-remote/wsl+Ubuntu/home/theo/My%20Project", - ); - expect(state.run).not.toHaveBeenCalled(); - }); - - it("opens the WSL workspace from the favorite-editor shortcut", async () => { - await using fixture = await setup(); - const { screen, pressOpenFavorite, FavoriteEditorFallback } = fixture; - state.remote = { mode: "wsl-links", distro: "Debian" }; - state.clientEditors = ["vscode"]; - await act(async () => - screen.rerender(), - ); - - expect((await pressOpenFavorite()).defaultPrevented).toBe(true); - expect(state.openUrl).toHaveBeenCalledWith( - "vscode://vscode-remote/wsl+Debian/home/theo/workspace", - ); - expect(state.run).not.toHaveBeenCalled(); - }); - it("explains why a phone or tablet browser has no editor to open", async () => { await using fixture = await setup(); const { renderPicker, byLabel, primaryButton, menuItems, click, pressOpenFavorite } = fixture; diff --git a/apps/web/src/components/chat/OpenInPicker.logic.test.ts b/apps/web/src/components/chat/OpenInPicker.logic.test.ts index 371a8532901dc..e69cbb1db2fd5 100644 --- a/apps/web/src/components/chat/OpenInPicker.logic.test.ts +++ b/apps/web/src/components/chat/OpenInPicker.logic.test.ts @@ -3,22 +3,7 @@ import { describe, expect, it } from "vite-plus/test"; import { shouldShowOpenInPicker } from "./OpenInPicker.logic"; -const primary = EnvironmentId.make("primary"); -const secondary = EnvironmentId.make("secondary"); - describe("shouldShowOpenInPicker", () => { - it("shows the picker for a desktop-managed WSL environment", () => { - expect( - shouldShowOpenInPicker({ - activeProjectName: "project", - activeThreadEnvironmentId: secondary, - primaryEnvironmentId: primary, - hostEnvironmentId: null, - remoteOpenMode: "wsl-links", - }), - ).toBe(true); - }); - it("shows both local environments when the primary has a separate WSL home", () => { const primaryEnvironmentId = EnvironmentId.make("wsl"); const hostEnvironmentId = EnvironmentId.make("host"); @@ -34,8 +19,22 @@ describe("shouldShowOpenInPicker", () => { primaryEnvironmentId, hostEnvironmentId, remoteOpenMode: "local-exec", + isDesktopWslBackend: false, }), ).toBe(visible); } }); + + it("shows a desktop-managed WSL backend that runs editors itself", () => { + expect( + shouldShowOpenInPicker({ + activeProjectName: "Project", + activeThreadEnvironmentId: EnvironmentId.make("wsl-secondary"), + primaryEnvironmentId: EnvironmentId.make("primary"), + hostEnvironmentId: null, + remoteOpenMode: "local-exec", + isDesktopWslBackend: true, + }), + ).toBe(true); + }); }); diff --git a/apps/web/src/components/chat/OpenInPicker.logic.ts b/apps/web/src/components/chat/OpenInPicker.logic.ts index 5978a5986030a..646ffa56976a1 100644 --- a/apps/web/src/components/chat/OpenInPicker.logic.ts +++ b/apps/web/src/components/chat/OpenInPicker.logic.ts @@ -8,6 +8,7 @@ export function shouldShowOpenInPicker(input: { readonly primaryEnvironmentId: EnvironmentId | null; readonly hostEnvironmentId: string | null; readonly remoteOpenMode: RemoteOpenMode; + readonly isDesktopWslBackend: boolean; }): boolean { if (!input.activeProjectName) return false; if ( @@ -16,5 +17,7 @@ export function shouldShowOpenInPicker(input: { ) { return true; } + // Desktop-managed WSL backends run on this machine and reach Windows editors through interop. + if (input.isDesktopWslBackend) return true; return input.remoteOpenMode !== "local-exec"; } diff --git a/apps/web/src/components/chat/OpenInPicker.tsx b/apps/web/src/components/chat/OpenInPicker.tsx index 697049663057b..d61a1a4a6063a 100644 --- a/apps/web/src/components/chat/OpenInPicker.tsx +++ b/apps/web/src/components/chat/OpenInPicker.tsx @@ -2,7 +2,6 @@ import { ThreadDetailsControl } from "./ThreadDetailsControl"; import { AuthOrchestrationOperateScope, buildRemoteOpenUrl, - buildWslOpenUrl, EditorId, type EnvironmentId, type ResolvedKeybindingsConfig, @@ -16,7 +15,6 @@ import { editorLabelForPlatform } from "../../editorLabels"; import { openRemoteEditorUrl, useRemoteCapableEditors, - useWslCapableEditors, useRemoteOpenHint, useRemoteOpenState, } from "../../remoteOpen"; @@ -239,16 +237,10 @@ export const OpenInPicker = memo(function OpenInPicker({ const canOpenEditor = remote.mode !== "remote-unavailable" && !isHostEditorDenied; const [menuOpen, setMenuOpen] = useComposerMenuState(isHostEditorDenied); const remoteCapableEditors = useRemoteCapableEditors(); - const wslEditors = useWslCapableEditors(); const [remoteHintSeen, markRemoteHintSeen] = useRemoteOpenHint(); const environmentLabel = useEnvironment(environmentId)?.label ?? "this machine"; // Remote editors run on the viewing machine; only desktop can probe that PATH. - const effectiveEditors = - remote.mode === "local-exec" - ? availableEditors - : remote.mode === "wsl-links" - ? wslEditors - : remoteCapableEditors; + const effectiveEditors = remote.mode === "local-exec" ? availableEditors : remoteCapableEditors; const [preferredEditor, setPreferredEditor] = usePreferredEditor(effectiveEditors); const openInEditor = async (editorId: EditorId | null): Promise => { @@ -256,19 +248,6 @@ export const OpenInPicker = memo(function OpenInPicker({ const editor = editorId ?? preferredEditor; if (!editor) return false; if (remote.mode === "remote-unavailable") return false; - if (remote.mode === "wsl-links") { - const url = buildWslOpenUrl({ - editor, - distro: remote.distro, - absolutePath: openInCwd, - isFile: openInCwdIsFile, - }); - if (url === undefined) return false; - const opened = await openRemoteEditorUrl(url); - if (!opened) return false; - setPreferredEditor(editor); - return true; - } if (remote.mode === "remote-links") { const url = buildRemoteOpenUrl({ editor, diff --git a/apps/web/src/components/chat/OpenInPickerShortcut.ts b/apps/web/src/components/chat/OpenInPickerShortcut.ts index 23057688238b0..833c3f3784987 100644 --- a/apps/web/src/components/chat/OpenInPickerShortcut.ts +++ b/apps/web/src/components/chat/OpenInPickerShortcut.ts @@ -1,5 +1,4 @@ import { - buildWslOpenUrl, buildRemoteOpenUrl, type EditorId, type EnvironmentId, @@ -11,12 +10,7 @@ import { usePreferredEditor } from "../../editorPreferences"; import { editorLabelForPlatform } from "../../editorLabels"; import { isOpenFavoriteEditorShortcut } from "../../keybindings"; import { announce } from "../../lib/announce"; -import { - openRemoteEditorUrl, - useRemoteCapableEditors, - useRemoteOpenState, - useWslCapableEditors, -} from "../../remoteOpen"; +import { openRemoteEditorUrl, useRemoteCapableEditors, useRemoteOpenState } from "../../remoteOpen"; import { registerCommands } from "../../shortcuts/dispatcher"; import { shellEnvironment } from "../../state/shell"; import { useAtomCommand } from "../../state/use-atom-command"; @@ -62,15 +56,10 @@ export function useOpenFavoriteEditorShortcut({ const openInEditorMutation = useAtomCommand(shellEnvironment.openInEditor, "open in editor"); const remote = useRemoteOpenState(environmentId); const remoteCapableEditors = useRemoteCapableEditors(); - const wslEditors = useWslCapableEditors(); // Matches the picker: remote editors run on the viewing machine. - const effectiveEditors = - remote.mode === "local-exec" - ? availableEditors - : remote.mode === "wsl-links" - ? wslEditors - : remoteCapableEditors; - const [preferredEditor] = usePreferredEditor(effectiveEditors); + const [preferredEditor] = usePreferredEditor( + remote.mode === "local-exec" ? availableEditors : remoteCapableEditors, + ); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- subscribes a window keydown listener for the open-in-editor shortcut while enabled useEffect(() => { @@ -86,18 +75,6 @@ export function useOpenFavoriteEditorShortcut({ event.preventDefault(); const label = editorLabelForPlatform(preferredEditor, navigator.platform); - if (remote.mode === "wsl-links") { - const url = buildWslOpenUrl({ - editor: preferredEditor, - distro: remote.distro, - absolutePath: openInCwd, - }); - if (url === undefined) return; - void openRemoteEditorUrl(url).then((opened) => { - if (opened) announce(`Opened in ${label}`); - }); - return; - } if (remote.mode === "remote-links") { const url = buildRemoteOpenUrl({ editor: preferredEditor, diff --git a/apps/web/src/connection/desktopLocal.test.ts b/apps/web/src/connection/desktopLocal.test.ts index 3911c884c5d97..2086e91853550 100644 --- a/apps/web/src/connection/desktopLocal.test.ts +++ b/apps/web/src/connection/desktopLocal.test.ts @@ -63,23 +63,19 @@ describe("desktop local topology reads", () => { httpBaseUrl: "http://127.0.0.1:4000", wsBaseUrl: "ws://127.0.0.1:4000", }; - const primary = { - id: PRIMARY_LOCAL_ENVIRONMENT_ID, - label: "WSL (Ubuntu)", - runningDistro: "Ubuntu", - httpBaseUrl: "http://127.0.0.1:3000", - wsBaseUrl: "ws://127.0.0.1:3000", - }; const reader = createDesktopSecondaryBootstrapsReader(() => ({ - getLocalEnvironmentBootstraps: () => [primary, secondary], + getLocalEnvironmentBootstraps: () => [ + { + ...secondary, + id: PRIMARY_LOCAL_ENVIRONMENT_ID, + label: "Windows", + }, + secondary, + ], })); expect(reader.readResult()).toEqual({ _tag: "Success", bootstraps: [secondary] }); - expect(reader.readAllResult()).toEqual({ - _tag: "Success", - bootstraps: [primary, secondary], - }); }); it("retains the last successful snapshot only until another read succeeds", () => { diff --git a/apps/web/src/connection/desktopLocal.ts b/apps/web/src/connection/desktopLocal.ts index 335ea102cb170..be420a0112b90 100644 --- a/apps/web/src/connection/desktopLocal.ts +++ b/apps/web/src/connection/desktopLocal.ts @@ -26,7 +26,11 @@ export function desktopLocalBackendId(target: ConnectionTarget): string | null { : null; } -export type DesktopBootstrapsRead = +export function isDesktopWslTarget(target: ConnectionTarget | undefined): boolean { + return target !== undefined && (desktopLocalBackendId(target)?.startsWith("wsl:") ?? false); +} + +export type DesktopSecondaryBootstrapsRead = | { readonly _tag: "Success"; readonly bootstraps: ReadonlyArray; @@ -37,10 +41,8 @@ export type DesktopBootstrapsRead = }; export interface DesktopSecondaryBootstrapsReader { - readonly readResult: () => DesktopBootstrapsRead; + readonly readResult: () => DesktopSecondaryBootstrapsRead; readonly readSnapshot: () => ReadonlyArray; - readonly readAllResult: () => DesktopBootstrapsRead; - readonly readAllSnapshot: () => ReadonlyArray; } /** Empty reads clear the snapshot; failed reads retain platform registrations. */ @@ -48,21 +50,21 @@ export function createDesktopSecondaryBootstrapsReader( resolveBridge: () => Pick | undefined, ): DesktopSecondaryBootstrapsReader { let snapshot: ReadonlyArray = []; - let allSnapshot: ReadonlyArray = []; - const readAllResult = (): DesktopBootstrapsRead => { + const readResult = (): DesktopSecondaryBootstrapsRead => { const bridge = resolveBridge(); if (bridge === undefined) { - if (allSnapshot.length > 0) allSnapshot = []; if (snapshot.length > 0) snapshot = []; - return { _tag: "Success", bootstraps: allSnapshot }; + return { _tag: "Success", bootstraps: snapshot }; } try { - const next = bridge.getLocalEnvironmentBootstraps(); + const next = bridge + .getLocalEnvironmentBootstraps() + .filter((entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID); if ( - next.length !== allSnapshot.length || + next.length !== snapshot.length || next.some((entry, index) => { - const previous = allSnapshot[index]; + const previous = snapshot[index]; return ( previous === undefined || entry.id !== previous.id || @@ -74,48 +76,31 @@ export function createDesktopSecondaryBootstrapsReader( ); }) ) { - allSnapshot = next; - } - const nextSecondary = allSnapshot.filter( - (entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID, - ); - if ( - nextSecondary.length !== snapshot.length || - nextSecondary.some((entry, index) => entry !== snapshot[index]) - ) { - snapshot = nextSecondary; + snapshot = next; } - return { _tag: "Success", bootstraps: allSnapshot }; + return { _tag: "Success", bootstraps: snapshot }; } catch (cause) { return { _tag: "Failure", cause }; } }; - const readResult = (): DesktopBootstrapsRead => { - const result = readAllResult(); - return result._tag === "Success" ? { _tag: "Success", bootstraps: snapshot } : result; - }; - return { readResult, - readAllResult, readSnapshot: () => { const result = readResult(); return result._tag === "Success" ? result.bootstraps : snapshot; }, - readAllSnapshot: () => { - const result = readAllResult(); - return result._tag === "Success" ? result.bootstraps : allSnapshot; - }, }; } -const desktopBootstrapsReader = createDesktopSecondaryBootstrapsReader(() => window.desktopBridge); +const desktopSecondaryBootstrapsReader = createDesktopSecondaryBootstrapsReader( + () => window.desktopBridge, +); -export function readDesktopSecondaryBootstrapsResult(): DesktopBootstrapsRead { - return desktopBootstrapsReader.readResult(); +export function readDesktopSecondaryBootstrapsResult(): DesktopSecondaryBootstrapsRead { + return desktopSecondaryBootstrapsReader.readResult(); } -export function readDesktopLocalBootstraps(): ReadonlyArray { - return desktopBootstrapsReader.readAllSnapshot(); +export function readDesktopSecondaryBootstraps(): ReadonlyArray { + return desktopSecondaryBootstrapsReader.readSnapshot(); } diff --git a/apps/web/src/connection/platform.ts b/apps/web/src/connection/platform.ts index b87651fda0f53..dcd50342f1c91 100644 --- a/apps/web/src/connection/platform.ts +++ b/apps/web/src/connection/platform.ts @@ -58,7 +58,7 @@ import { acknowledgeRpcRequest, trackRpcRequestSent } from "../rpc/requestLatenc import { desktopLocalConnectionId, readDesktopSecondaryBootstrapsResult, - type DesktopBootstrapsRead, + type DesktopSecondaryBootstrapsRead, } from "./desktopLocal"; import * as ConnectionStorage from "./storage"; import { clientPresentationMetadata } from "./clientMetadata"; @@ -610,7 +610,7 @@ export function isRejectedBootstrapCredentialError(error: ConnectionAttemptError export function secondaryRegistrationsToRetainAfterTopologyRead( previous: ReadonlyMap, - topologyRead: DesktopBootstrapsRead, + topologyRead: DesktopSecondaryBootstrapsRead, nowEpochMs: number, ): ReadonlyMap { if (topologyRead._tag === "Success") { diff --git a/apps/web/src/connection/useDesktopLocalBootstraps.ts b/apps/web/src/connection/useDesktopLocalBootstraps.ts index aab3869551084..75c6904731ee6 100644 --- a/apps/web/src/connection/useDesktopLocalBootstraps.ts +++ b/apps/web/src/connection/useDesktopLocalBootstraps.ts @@ -1,8 +1,8 @@ import { useAtomValue } from "@effect/atom-react"; -import { PRIMARY_LOCAL_ENVIRONMENT_ID } from "@t3tools/contracts"; +import type { DesktopEnvironmentBootstrap } from "@t3tools/contracts"; import { Atom } from "effect/reactivity"; -import { readDesktopLocalBootstraps } from "./desktopLocal"; +import { readDesktopSecondaryBootstraps } from "./desktopLocal"; const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000; @@ -12,19 +12,15 @@ const DESKTOP_LOCAL_BOOTSTRAP_POLL_MS = 2_000; * a successful empty read clears it. The reader returns the same array while * nothing changed, so an unchanged poll notifies no one. */ -export const desktopLocalBootstrapsAtom = Atom.make((get) => { +const desktopLocalBootstrapsAtom = Atom.make((get) => { const interval = setInterval( - () => get.setSelf(readDesktopLocalBootstraps()), + () => get.setSelf(readDesktopSecondaryBootstraps()), DESKTOP_LOCAL_BOOTSTRAP_POLL_MS, ); get.addFinalizer(() => clearInterval(interval)); - return readDesktopLocalBootstraps(); + return readDesktopSecondaryBootstraps(); }).pipe(Atom.withLabel("desktop-local-bootstraps")); -const desktopSecondaryBootstrapsAtom = Atom.make((get) => - get(desktopLocalBootstrapsAtom).filter((entry) => entry.id !== PRIMARY_LOCAL_ENVIRONMENT_ID), -).pipe(Atom.withLabel("desktop-secondary-bootstraps")); - -export function useDesktopLocalBootstraps() { - return useAtomValue(desktopSecondaryBootstrapsAtom); +export function useDesktopLocalBootstraps(): ReadonlyArray { + return useAtomValue(desktopLocalBootstrapsAtom); } diff --git a/apps/web/src/markdown-links.ts b/apps/web/src/markdown-links.ts index ae5123ae98a71..330976746af6b 100644 --- a/apps/web/src/markdown-links.ts +++ b/apps/web/src/markdown-links.ts @@ -14,7 +14,6 @@ import { isTerminalLinkActivation } from "./terminal-links"; export interface MarkdownFileLinkMeta { filePath: string; - sourcePath?: string; workspaceLookupPath: string | null; targetPath: string; displayPath: string; @@ -86,7 +85,6 @@ export function resolveMarkdownFileLinkMeta( const source = href ? parseMarkdownFileLink(href) : null; return { ...buildFileLinkMetaFromTarget(targetPath, cwd), - ...(source ? { sourcePath: source.path } : {}), ...(source?.endLine !== undefined ? { endLine: source.endLine } : {}), workspaceLookupPath: source !== null && diff --git a/apps/web/src/markdownFileHostPath.test.ts b/apps/web/src/markdownFileHostPath.test.ts deleted file mode 100644 index 6db9c47b5230b..0000000000000 --- a/apps/web/src/markdownFileHostPath.test.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { expect, it } from "vite-plus/test"; -import { buildWslMarkdownFileUrl } from "./markdownFileHostPath"; - -it("opens a relative WSL file at its specified position", () => { - expect( - buildWslMarkdownFileUrl({ - editor: "vscode", - distro: "Ubuntu", - path: "src/file.ts", - cwd: "/home/user/project", - line: 12, - column: 3, - }), - ).toBe("vscode://vscode-remote/wsl+Ubuntu/home/user/project/src/file.ts:12:3"); - for (const path of ["./src/file.ts", "/home/user/project/./src/file.ts"]) { - expect( - buildWslMarkdownFileUrl({ - editor: "vscode", - distro: "Ubuntu", - path, - cwd: "/home/user/project", - line: 12, - column: 3, - }), - ).toBe("vscode://vscode-remote/wsl+Ubuntu/home/user/project/src/file.ts:12:3"); - } - expect( - buildWslMarkdownFileUrl({ - editor: "vscode", - distro: "Ubuntu", - path: "link/../file.ts", - cwd: "/home/user/project", - line: 12, - column: 3, - }), - ).toBeUndefined(); - expect( - buildWslMarkdownFileUrl({ - editor: "vscode", - distro: "Ubuntu", - path: "/opt/pkg/file.ts", - cwd: "/home/user/project", - line: 12, - column: 3, - }), - ).toBe("vscode://vscode-remote/wsl+Ubuntu/opt/pkg/file.ts:12:3"); - expect( - buildWslMarkdownFileUrl({ - editor: "vscode", - distro: "Ubuntu", - path: "/mnt/c/project/docs/", - cwd: "/mnt/c/project", - line: undefined, - column: undefined, - isDirectory: true, - }), - ).toBe("vscode://vscode-remote/wsl+Ubuntu/mnt/c/project/docs"); -}); diff --git a/apps/web/src/markdownFileHostPath.ts b/apps/web/src/markdownFileHostPath.ts index 477097da809e4..26f3aaa348122 100644 --- a/apps/web/src/markdownFileHostPath.ts +++ b/apps/web/src/markdownFileHostPath.ts @@ -1,4 +1,3 @@ -import { buildWslOpenUrl, type EditorId } from "@t3tools/contracts"; import { formatFilePathPosition, resolvePathLinkTarget } from "@t3tools/shared/fileLinks"; import { workspaceRelativeFilePath } from "@t3tools/shared/path"; @@ -47,30 +46,3 @@ export function markdownFileCopyPaths( }), }; } - -export function buildWslMarkdownFileUrl(input: { - editor: EditorId; - distro: string; - path: string; - cwd: string | undefined; - line: number | undefined; - column: number | undefined; - isDirectory?: boolean; -}) { - const path = input.cwd ? resolvePathLinkTarget(input.path, input.cwd) : input.path; - const segments: string[] = []; - if (path.startsWith("/") && !path.includes("\\")) { - for (const segment of path.split("/")) { - if (segment === "..") return undefined; - else if (segment !== "" && segment !== ".") segments.push(segment); - } - } - return buildWslOpenUrl({ - editor: input.editor, - distro: input.distro, - absolutePath: path.startsWith("/") && !path.includes("\\") ? `/${segments.join("/")}` : path, - isFile: !input.isDirectory, - ...(input.line !== undefined ? { line: input.line } : {}), - ...(input.column !== undefined ? { column: input.column } : {}), - }); -} diff --git a/apps/web/src/remoteOpen.test.ts b/apps/web/src/remoteOpen.test.ts index ccf85c9b16456..12149f98af238 100644 --- a/apps/web/src/remoteOpen.test.ts +++ b/apps/web/src/remoteOpen.test.ts @@ -1,10 +1,9 @@ import { - BearerConnectionTarget, PrimaryConnectionTarget, RelayConnectionTarget, SshConnectionTarget, } from "@t3tools/client-runtime/connection"; -import { buildRemoteOpenUrl, buildWslOpenUrl, EnvironmentId } from "@t3tools/contracts"; +import { buildRemoteOpenUrl, EnvironmentId } from "@t3tools/contracts"; import { describe, expect, it } from "vite-plus/test"; import { remoteFallbackEditors, resolveRemoteOpenState } from "./remoteOpen"; @@ -65,34 +64,6 @@ describe("resolveRemoteOpenState", () => { ).toEqual({ mode: "local-exec" }); }); - it("uses the resolved distro for desktop-managed WSL environments", () => { - expect( - resolveRemoteOpenState({ - target: primaryTarget("http://172.29.112.1:14369"), - sshTarget: null, - isDesktopRenderer: true, - remoteOpenTargets: undefined, - wslDistro: "Ubuntu", - hostEnvironmentId: null, - }), - ).toEqual({ mode: "wsl-links", distro: "Ubuntu" }); - - expect( - resolveRemoteOpenState({ - target: new BearerConnectionTarget({ - environmentId, - label: "WSL (Debian)", - connectionId: "local:wsl:default", - }), - sshTarget: null, - isDesktopRenderer: true, - remoteOpenTargets: undefined, - wslDistro: "Debian", - hostEnvironmentId: null, - }), - ).toEqual({ mode: "wsl-links", distro: "Debian" }); - }); - it("keeps exec behavior for the environment that owns the desktop's T3 home", () => { // With Local environment off, a background service on this machine can own the // desktop's home and still be reached through T3 Connect. @@ -315,57 +286,3 @@ describe("buildRemoteOpenUrl", () => { } }); }); - -describe("buildWslOpenUrl", () => { - it("uses the Linux workspace path and VS Code's WSL remote authority", () => { - expect( - buildWslOpenUrl({ - editor: "vscode", - distro: "Ubuntu-22.04", - absolutePath: "/home/theo/My Project", - }), - ).toBe("vscode://vscode-remote/wsl+Ubuntu-22.04/home/theo/My%20Project"); - expect( - buildWslOpenUrl({ - editor: "vscode-insiders", - distro: "Ubuntu", - absolutePath: "/home/theo/file name.md", - isFile: true, - }), - ).toBe("vscode-insiders://vscode-remote/wsl+Ubuntu/home/theo/file%20name.md:1:1"); - expect( - buildWslOpenUrl({ - editor: "vscode", - distro: "Ubuntu", - absolutePath: "/work/file.ts", - isFile: true, - line: 12, - column: 3, - }), - ).toBe("vscode://vscode-remote/wsl+Ubuntu/work/file.ts:12:3"); - }); - - it("rejects unsupported editors, invalid distros, and Windows paths", () => { - expect( - buildWslOpenUrl({ - editor: "cursor", - distro: "Ubuntu", - absolutePath: "/home/theo/project", - }), - ).toBeUndefined(); - expect( - buildWslOpenUrl({ - editor: "vscode", - distro: "Ubuntu/..", - absolutePath: "/home/theo/project", - }), - ).toBeUndefined(); - expect( - buildWslOpenUrl({ - editor: "vscode", - distro: "Ubuntu", - absolutePath: "C:\\Users\\theo\\project", - }), - ).toBeUndefined(); - }); -}); diff --git a/apps/web/src/remoteOpen.ts b/apps/web/src/remoteOpen.ts index 1c482583899b0..a62b203663f07 100644 --- a/apps/web/src/remoteOpen.ts +++ b/apps/web/src/remoteOpen.ts @@ -1,8 +1,6 @@ import type { ConnectionTarget } from "@t3tools/client-runtime/connection"; import { REMOTE_CAPABLE_EDITOR_IDS, - PRIMARY_LOCAL_ENVIRONMENT_ID, - WSL_REMOTE_EDITOR_IDS, type EditorId, type EnvironmentId, type RemoteOpenTarget, @@ -13,8 +11,7 @@ import { Atom } from "effect/reactivity"; import { useAtomValue } from "@effect/atom-react"; import { browserClientOs, type BrowserIdentity } from "~/connection/clientMetadata"; -import { desktopLocalBackendId, isDesktopLocalConnectionTarget } from "~/connection/desktopLocal"; -import { desktopLocalBootstrapsAtom } from "~/connection/useDesktopLocalBootstraps"; +import { isDesktopLocalConnectionTarget } from "~/connection/desktopLocal"; import { isLoopbackHostname } from "~/environments/primary/target"; import { useLocalStorage } from "~/hooks/useLocalStorage"; import { environmentPresentations } from "~/state/presentation"; @@ -29,7 +26,6 @@ export interface RemoteOpenHost { export type RemoteOpenState = | { readonly mode: "local-exec" } | { readonly mode: "remote-links"; readonly host: RemoteOpenHost } - | { readonly mode: "wsl-links"; readonly distro: string } | { readonly mode: "remote-unavailable" }; export type RemoteOpenMode = RemoteOpenState["mode"]; @@ -59,7 +55,6 @@ export function resolveRemoteOpenState(input: { readonly sshTarget: { readonly alias: string; readonly username: string | null } | null; readonly remoteOpenTargets: ReadonlyArray | undefined; readonly isDesktopRenderer: boolean; - readonly wslDistro?: string | null; readonly hostEnvironmentId: string | null; }): RemoteOpenState { const { target } = input; @@ -69,7 +64,6 @@ export function resolveRemoteOpenState(input: { if (target._tag === "PrimaryConnectionTarget") { // Desktop owns its primary even at a non-loopback WSL2 NAT address. if (input.isDesktopRenderer) { - if (input.wslDistro) return { mode: "wsl-links", distro: input.wslDistro }; return LOCAL_EXEC; } const hostname = parseHostname(target.httpBaseUrl); @@ -77,9 +71,6 @@ export function resolveRemoteOpenState(input: { return LOCAL_EXEC; } } else if (isDesktopLocalConnectionTarget(target)) { - if (desktopLocalBackendId(target)?.startsWith("wsl:") && input.wslDistro) { - return { mode: "wsl-links", distro: input.wslDistro }; - } return LOCAL_EXEC; } @@ -108,9 +99,6 @@ export function resolveRemoteOpenState(input: { function remoteOpenStatesEqual(previous: RemoteOpenState, next: RemoteOpenState): boolean { if (previous.mode !== next.mode) return false; - if (previous.mode === "wsl-links" && next.mode === "wsl-links") { - return previous.distro === next.distro; - } if (previous.mode !== "remote-links" || next.mode !== "remote-links") return true; return ( previous.host.kind === next.host.kind && @@ -128,25 +116,13 @@ const remoteOpenResolutionAtom = Atom.family((environmentId: EnvironmentId) => return UNRESOLVED_REMOTE_OPEN; } const profile = Option.getOrNull(entry.profile); - const isDesktopRenderer = window.desktopBridge !== undefined; - const backendId = - entry.target._tag === "PrimaryConnectionTarget" - ? PRIMARY_LOCAL_ENVIRONMENT_ID - : desktopLocalBackendId(entry.target); - const bootstraps = - isDesktopRenderer && backendId !== null ? get(desktopLocalBootstrapsAtom) : []; - const wslDistro = - backendId !== null - ? (bootstraps.find((bootstrap) => bootstrap.id === backendId)?.runningDistro ?? null) - : null; const next: RemoteOpenResolution = { state: resolveRemoteOpenState({ target: entry.target, sshTarget: profile !== null && profile._tag === "SshConnectionProfile" ? profile.target : null, remoteOpenTargets: presentation?.serverConfig?.remoteOpenTargets, - isDesktopRenderer, - wslDistro, + isDesktopRenderer: window.desktopBridge !== undefined, hostEnvironmentId: get(hostEnvironmentIdAtom), }), isResolved: true, @@ -181,26 +157,20 @@ export function remoteFallbackEditors(identity: BrowserIdentity): ReadonlyArray< } // Probed once per page: installed editors rarely change, and the probe spawns processes. -const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray | null => { +const remoteCapableEditorsAtom = Atom.make((get): ReadonlyArray => { const probe = window.desktopBridge?.probeRemoteEditors; probe?.().then( (ids) => { const remoteCapable = ids.filter((id) => REMOTE_CAPABLE_EDITOR_IDS.includes(id)); - get.setSelf(remoteCapable); + if (remoteCapable.length > 0) get.setSelf(remoteCapable); }, () => undefined, ); - return null; + return remoteFallbackEditors(navigator); }).pipe(Atom.keepAlive, Atom.withLabel("remote-capable-editors")); export function useRemoteCapableEditors(): ReadonlyArray { - const editors = useAtomValue(remoteCapableEditorsAtom); - return editors && editors.length > 0 ? editors : remoteFallbackEditors(navigator); -} - -export function useWslCapableEditors(): ReadonlyArray { - const editors = useAtomValue(remoteCapableEditorsAtom) ?? []; - return editors.filter((editor) => WSL_REMOTE_EDITOR_IDS.some((id) => id === editor)); + return useAtomValue(remoteCapableEditorsAtom); } /** Resolves false when the desktop refuses the URL, including unsupported editor schemes. */ diff --git a/packages/contracts/src/editor.ts b/packages/contracts/src/editor.ts index 0b7d61ed65466..8732d7fe288e2 100644 --- a/packages/contracts/src/editor.ts +++ b/packages/contracts/src/editor.ts @@ -169,41 +169,11 @@ export const REMOTE_CAPABLE_EDITOR_IDS: ReadonlyArray = EDITORS.flatMa remoteSchemeOf(editor) !== undefined ? [editor.id] : [], ); -export const WSL_REMOTE_EDITOR_IDS = [ - "vscode", - "vscode-insiders", -] as const satisfies ReadonlyArray; - export const remoteSchemeForEditor = (id: EditorId): string | undefined => { const editor = EDITORS.find((candidate) => candidate.id === id); return editor === undefined ? undefined : remoteSchemeOf(editor); }; -export const buildWslOpenUrl = (input: { - readonly editor: EditorId; - readonly distro: string; - readonly absolutePath: string; - readonly isFile?: boolean; - readonly line?: number; - readonly column?: number; -}): string | undefined => { - if ( - !WSL_REMOTE_EDITOR_IDS.some((editor) => editor === input.editor) || - !/^[A-Za-z0-9._-]+$/.test(input.distro) || - !input.absolutePath.startsWith("/") || - input.absolutePath.includes("\\") || - input.absolutePath.split("/").some((segment) => segment === "." || segment === "..") - ) { - return undefined; - } - const scheme = remoteSchemeForEditor(input.editor); - if (scheme === undefined) { - return undefined; - } - const encodedPath = input.absolutePath.split("/").map(encodeURIComponent).join("/"); - return `${scheme}://vscode-remote/wsl+${input.distro}${encodedPath}${input.isFile ? `:${input.line ?? 1}:${input.column ?? 1}` : ""}`; -}; - // `goto` editors share VS Code's `file:line:col` addressing, so their remote schemes also open // a local file as `://file/[:line[:col]]`. Zed and JetBrains differ. export const LOCAL_FILE_LINK_SCHEMES: ReadonlyArray = EDITORS.flatMap((editor) => diff --git a/packages/contracts/src/filesystem.ts b/packages/contracts/src/filesystem.ts index b1622a88b59c3..a1f6c293e90b5 100644 --- a/packages/contracts/src/filesystem.ts +++ b/packages/contracts/src/filesystem.ts @@ -7,7 +7,6 @@ export const FILESYSTEM_METADATA_BATCH_LIMIT = 64; export const FilesystemGetMetadataInput = Schema.Struct({ // Absolute host paths, including ~/; clients must anchor relative paths. - resolveRealPath: Schema.optionalKey(Schema.Boolean), paths: Schema.Array( TrimmedNonEmptyString.check(Schema.isMaxLength(FILESYSTEM_PATH_MAX_LENGTH)), ).check(Schema.isMinLength(1), Schema.isMaxLength(FILESYSTEM_METADATA_BATCH_LIMIT)), @@ -16,7 +15,6 @@ export type FilesystemGetMetadataInput = typeof FilesystemGetMetadataInput.Type; export const FilesystemEntryMetadata = Schema.Struct({ kind: Schema.Literals(["file", "directory", "other"]), - realPath: Schema.optionalKey(TrimmedNonEmptyString), byteLength: Schema.optionalKey(NonNegativeInt), mimeType: Schema.optionalKey(TrimmedNonEmptyString), }); From 2d9a3353adbe3ee876b8e3a6245b6fcbadfdcdd3 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 18 Nov 2026 00:17:52 -0500 Subject: [PATCH 13/14] fix(web): import picker helper in chat view test --- apps/web/src/components/ChatView.logic.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts index 6e91b0ef81e78..4e4b98d81c93e 100644 --- a/apps/web/src/components/ChatView.logic.test.ts +++ b/apps/web/src/components/ChatView.logic.test.ts @@ -52,6 +52,7 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test"; import { AsyncResult, Atom } from "effect/reactivity"; import { appAtomRegistry } from "../rpc/atomRegistry"; import { environmentThreadDetails } from "../state/threads"; +import { shouldShowOpenInPicker } from "./chat/OpenInPicker.logic"; import type { Thread } from "../types"; import { DraftId, hydrateImagesFromPersisted, useComposerDraftStore } from "../composerDraftStore"; From 67ed35a16b4cf1616f5cd86dcfbca538960880e4 Mon Sep 17 00:00:00 2001 From: Matheson Steplock Date: Wed, 18 Nov 2026 00:21:03 -0500 Subject: [PATCH 14/14] test(web): remove duplicate picker coverage --- .../web/src/components/ChatView.logic.test.ts | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/apps/web/src/components/ChatView.logic.test.ts b/apps/web/src/components/ChatView.logic.test.ts index 4e4b98d81c93e..dbbb445a5ec95 100644 --- a/apps/web/src/components/ChatView.logic.test.ts +++ b/apps/web/src/components/ChatView.logic.test.ts @@ -52,7 +52,6 @@ import { afterEach, describe, expect, it, vi } from "vite-plus/test"; import { AsyncResult, Atom } from "effect/reactivity"; import { appAtomRegistry } from "../rpc/atomRegistry"; import { environmentThreadDetails } from "../state/threads"; -import { shouldShowOpenInPicker } from "./chat/OpenInPicker.logic"; import type { Thread } from "../types"; import { DraftId, hydrateImagesFromPersisted, useComposerDraftStore } from "../composerDraftStore"; @@ -1587,29 +1586,6 @@ describe("deriveThreadPendingBackgroundTasks", () => { }); }); -describe("Open in for the host environment", () => { - it("shows both local environments when the primary has a separate WSL home", () => { - const primaryEnvironmentId = EnvironmentId.make("wsl"); - const hostEnvironmentId = EnvironmentId.make("host"); - for (const [activeThreadEnvironmentId, visible] of [ - [primaryEnvironmentId, true], - [hostEnvironmentId, true], - [EnvironmentId.make("other"), false], - ] as const) { - expect( - shouldShowOpenInPicker({ - activeProjectName: "Project", - activeThreadEnvironmentId, - primaryEnvironmentId, - hostEnvironmentId, - remoteOpenMode: "local-exec", - isDesktopWslBackend: false, - }), - ).toBe(visible); - } - }); -}); - describe("prepareRevertedMessageAttachments", () => { it("suppresses a repeated image after restoring a rewound message", async () => { using _fetch = vi