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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions apps/server/src/process/externalLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,80 @@ const layerTest = (input: {
);
};

it.effect.skipIf(windowsHost)("discovers and launches Windows Zed in the selected WSL distro", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-wsl-zed-" });
const executable = path.join(binDir, "zed.exe");
yield* fs.writeFileString(executable, "#!/bin/sh\n");
yield* fs.chmod(executable, 0o755);
let spawned: ChildProcess.StandardCommand | undefined;
yield* Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
assert.include(yield* launcher.resolveAvailableEditors(), "zed");
yield* launcher.launchEditor({
editor: "zed",
cwd: "/home/tobi/projects/linux-server@blain",
});
}).pipe(
Effect.provide(
layerTest({
platform: "linux",
env: { PATH: binDir, WSL_DISTRO_NAME: "Ubuntu", USER: "tobi" },
onSpawn: (command) => {
spawned = command;
},
}),
),
);
assert.ok(spawned);
assert.equal(spawned.command, "zed.exe");
assert.deepEqual(spawned.args, [
"--wsl",
"tobi@Ubuntu",
"/home/tobi/projects/linux-server@blain",
]);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect.skipIf(windowsHost)("keeps native Linux and SSH Zed launches unchanged", () =>
Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fs.makeTempDirectoryScoped({ prefix: "t3-native-zed-" });
for (const name of ["zed", "zed.exe"]) {
const executable = path.join(binDir, name);
yield* fs.writeFileString(executable, "#!/bin/sh\n");
yield* fs.chmod(executable, 0o755);
}
const cases: ReadonlyArray<Record<string, string>> = [
{},
{ WSL_DISTRO_NAME: "Ubuntu", SSH_CONNECTION: "client server" },
];
for (const extraEnv of cases) {
let spawned: ChildProcess.StandardCommand | undefined;
yield* Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
yield* launcher.launchEditor({ editor: "zed", cwd: "/workspace/project" });
}).pipe(
Effect.provide(
layerTest({
platform: "linux",
env: { PATH: binDir, ...extraEnv },
onSpawn: (command) => {
spawned = command;
},
}),
),
);
assert.ok(spawned);
assert.equal(spawned.command, "zed");
assert.deepEqual(spawned.args, ["/workspace/project"]);
}
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);

it.effect.skipIf(windowsHost)(
"launched browsers and editors do not inherit ELECTRON_RUN_AS_NODE",
() =>
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/process/externalLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ const CommandLookupEnvConfig = Config.all({
path: Config.String("path").pipe(Config.option),
PATHEXT: Config.String("PATHEXT").pipe(Config.option),
HOME: Config.String("HOME").pipe(Config.option),
USER: Config.String("USER").pipe(Config.option),
LOCALAPPDATA: Config.String("LOCALAPPDATA").pipe(Config.option),
ProgramFiles: Config.String("ProgramFiles").pipe(Config.option),
ProgramW6432: Config.String("ProgramW6432").pipe(Config.option),
Expand Down
6 changes: 4 additions & 2 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,6 @@ import { useEnvironmentQuery } from "../state/query";
import { useEnvironmentScope } from "~/state/session";
import {
environmentServerConfigsAtom,
primaryServerAvailableEditorsAtom,
primaryServerKeybindingsAtom,
serverEnvironment,
} from "../state/server";
Expand Down Expand Up @@ -587,6 +586,7 @@ import { recallableComposerPrompt } from "./chat/composerPromptHistory";
import { observeResize } from "~/lib/observeResize";

const EMPTY_PROVIDERS: ServerProvider[] = [];
const EMPTY_AVAILABLE_EDITORS: readonly never[] = [];
const EMPTY_PROVIDER_MODELS: ServerProvider["models"] = [];
const EMPTY_USAGE_LIMIT_SOURCES: UsageLimitSourceSnapshots = [];
import type { CodexArtifactTemplate } from "@t3tools/shared/codexArtifactTemplates";
Expand Down Expand Up @@ -3088,7 +3088,9 @@ export default function ChatView(props: ChatViewProps) {
const scriptKeybindings =
useAtomValue(serverEnvironment.configValueAtom(environmentId))?.keybindings ??
DEFAULT_RESOLVED_KEYBINDINGS;
const availableEditors = useAtomValue(primaryServerAvailableEditorsAtom);
const availableEditors =
useAtomValue(serverEnvironment.configValueAtom(activeThread?.environmentId ?? environmentId))
?.availableEditors ?? EMPTY_AVAILABLE_EDITORS;
const remoteOpenState = useRemoteOpenState(activeThread?.environmentId ?? environmentId);
const showOpenInPicker = shouldShowOpenInPicker({
activeProjectName: activeProject?.title,
Expand Down
10 changes: 3 additions & 7 deletions apps/web/src/components/chat/OpenInPicker.logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ export function shouldShowOpenInPicker(input: {
readonly remoteOpenMode: RemoteOpenMode;
}): boolean {
if (!input.activeProjectName) return false;
if (
input.primaryEnvironmentId !== null &&
input.activeThreadEnvironmentId === input.primaryEnvironmentId
) {
return true;
}
return input.remoteOpenMode !== "local-exec";
// Local execution targets the selected environment, including secondary WSL
// backends. The picker handles missing editors and unavailable SSH routes.
return true;
}
63 changes: 63 additions & 0 deletions apps/web/src/components/chat/OpenInPicker.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { EnvironmentId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { shouldShowOpenInPicker } from "./OpenInPicker.logic";

describe("shouldShowOpenInPicker", () => {
const primaryEnvironmentId = EnvironmentId.make("environment-primary");

it("shows the picker for projects in the primary environment", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: primaryEnvironmentId,
primaryEnvironmentId,
remoteOpenMode: "local-exec",
}),
).toBe(true);
});

it("shows the picker for remote environments in deep-link mode", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
primaryEnvironmentId,
remoteOpenMode: "remote-links",
}),
).toBe(true);
});

it("shows the picker's unavailable state for remote environments without an SSH route", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
primaryEnvironmentId: null,
remoteOpenMode: "remote-unavailable",
}),
).toBe(true);
});

it("shows the picker for non-primary local backends such as WSL", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
primaryEnvironmentId,
remoteOpenMode: "local-exec",
}),
).toBe(true);
});

it("hides the picker when there is no active project", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: undefined,
activeThreadEnvironmentId: primaryEnvironmentId,
primaryEnvironmentId,
remoteOpenMode: "remote-links",
}),
).toBe(false);
});
});
15 changes: 15 additions & 0 deletions packages/shared/src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ export const resolveEditorCommand = Effect.fn("editor.resolveEditorCommand")(fun
if (editor.commands === null) return Option.none();
const baseArgs = "baseArgs" in editor ? editor.baseArgs : [];
const platform = yield* HostProcess.Platform;
// The Windows CLI needs an explicit distro when invoked without Zed's
// bundled WSL shell wrapper. Prefer it over a Linux `zed` (possibly ZFS).
if (
platform === "linux" &&
editor.id === "zed" &&
env.WSL_DISTRO_NAME?.trim() &&
env.SSH_CONNECTION === undefined &&
env.SSH_TTY === undefined &&
env.container === undefined &&
(yield* isCommandAvailable("zed.exe", { env }))
) {
const distro = env.USER ? `${env.USER}@${env.WSL_DISTRO_NAME}` : env.WSL_DISTRO_NAME;
const wslArgs: ReadonlyArray<string> = ["--wsl", distro];
return Option.some({ command: "zed.exe", baseArgs: wslArgs });
}
// OpenZFS also installs a `zed` executable. Prefer the macOS editor bundle
// so a PATH entry for the ZFS Event Daemon cannot take over editor opens.
const preferBundle = platform === "darwin" && editor.id === "zed";
Expand Down
Loading