Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(engines): say clearly when an engine's command runs it inside WSL (#4188)
Aditya Umaleefc8b350a027
diff --git a/server/harness/registry.test.ts b/server/harness/registry.test.tsindex 45346dfa12..7a03e48ccb 100644--- a/server/harness/registry.test.ts+++ b/server/harness/registry.test.ts@@ -190,6 +190,23 @@ describe("ProviderRegistry", () => {expect(registry.get("b")?.displayName).toBe("Rebuilt");});+ it("warns on Windows when an engine's custom command starts it inside WSL", async () => {+ const platform = Object.getOwnPropertyDescriptor(process, "platform")!;+ const registry = new ProviderRegistry([makeFakeDriver().driver]);+ Object.defineProperty(process, "platform", { ...platform, value: "win32" });+ try {+ await registry.load({+ wsl: { driver: "fake", config: { cli: "wsl.exe -d Ubuntu -- hermes" } },+ native: { driver: "fake", config: { cli: "C:\\Users\\me\\hermes.exe" } },+ });+ const described = Object.fromEntries((await registry.describe()).map((d) => [d.instanceId, d]));+ expect(described.wsl.snapshot).toMatchObject({ state: "available", warning: { title: "This engine runs inside WSL" } });+ expect(described.native.snapshot).not.toHaveProperty("warning");+ } finally {+ Object.defineProperty(process, "platform", platform);+ }+ });+it("describe() reports a snapshot() failure as unavailable rather than throwing", async () => {const fake = makeFakeDriver({ failSnapshot: "provider probe exploded" });const registry = new ProviderRegistry([fake.driver]);diff --git a/server/harness/registry.ts b/server/harness/registry.tsindex ddcfdcecd0..98474baa3d 100644--- a/server/harness/registry.ts+++ b/server/harness/registry.ts@@ -7,6 +7,7 @@ import { withEngineHomes } from "../engine-homes/engine-homes.ts";import { withLocalContext } from "../drivers/local-inject.ts";import { engineStatusFile, snapshotFrom } from "./engine-status-file.ts";import { withUnaskedStops } from "./unasked-stop.ts";+import { withWslNotice } from "./wsl-launch.ts";export { engineMemory } from "../engine-memory.ts";import { clientInstall } from "../contracts.ts";import type {@@ -472,7 +473,8 @@ export class ProviderRegistry {};}const inst = entry.live;- const snapshot = await statusOf(inst);+ const cli = this.cliByInstance.get(inst.instanceId);+ const snapshot = withWslNotice(await statusOf(inst), cli);return {instanceId: inst.instanceId,driverKind: inst.driverKind,@@ -497,7 +499,7 @@ export class ProviderRegistry {backgroundText: inst.generateText !== undefined || inst.generateMemoryText !== undefined,},access: driver?.metadata.access ?? "subscription",- install: withServerInstall(driver?.install, npmPresent, this.appStandaloneCopy(driver, this.cliByInstance.get(inst.instanceId) ?? cliDefaultOf(driver))),+ install: withServerInstall(driver?.install, npmPresent, this.appStandaloneCopy(driver, cli ?? cliDefaultOf(driver))),authentication: inst.startAuthentication? {method: inst.authenticationMethod ?? (inst.getAuthentication && inst.completeAuthentication@@ -508,7 +510,7 @@ export class ProviderRegistry {signOut: inst.signOut !== undefined,}: undefined,- cli: this.cliByInstance.get(inst.instanceId),+ cli,cliDefault: cliDefaultOf(driver),cliCandidates: candidatesFor(driver),};diff --git a/server/harness/wsl-launch.test.ts b/server/harness/wsl-launch.test.tsnew file mode 100644index 0000000000..4b577fdedd--- /dev/null+++ b/server/harness/wsl-launch.test.ts@@ -0,0 +1,54 @@+import { describe, expect, it } from "vitest";+import { launchesThroughWsl, withWslNotice, WSL_ENGINE_WARNING } from "./wsl-launch.ts";++describe("launchesThroughWsl", () => {+ it.each([+ "wsl hermes",+ "wsl.exe -d Ubuntu -- hermes",+ "WSL.EXE hermes",+ "C:\\Windows\\System32\\wsl.exe hermes",+ "\"C:\\Windows\\System32\\wsl.exe\" -e hermes",+ "C:/Windows/System32/wsl.exe hermes",+ "C:\\Windows\\System32\\bash.exe -c hermes",+ "C:\\Windows\\Sysnative\\bash.exe -c hermes",+ ])("counts %s on Windows", (cli) => {+ expect(launchesThroughWsl(cli, "win32")).toBe(true);+ });++ it.each([+ undefined,+ "",+ "hermes",+ "C:\\Users\\me\\AppData\\Local\\hermes\\hermes.exe",+ "\"C:\\Program Files\\Git\\bin\\bash.exe\" -c hermes",+ "bash -c hermes",+ "C:\\tools\\wslhermes.exe",+ "hermes --profile wsl",+ ])("does not count %s on Windows", (cli) => {+ expect(launchesThroughWsl(cli, "win32")).toBe(false);+ });++ it.each(["linux", "darwin"] as const)("never counts anything on %s", (platform) => {+ expect(launchesThroughWsl("wsl hermes", platform)).toBe(false);+ expect(launchesThroughWsl("/usr/bin/wsl", platform)).toBe(false);+ });+});++describe("withWslNotice", () => {+ const wsl = "wsl.exe -d Ubuntu -- hermes";++ it("adds the WSL notice on Windows and keeps the rest of the status", () => {+ const platform = Object.getOwnPropertyDescriptor(process, "platform")!;+ Object.defineProperty(process, "platform", { ...platform, value: "win32" });+ try {+ expect(withWslNotice({ state: "available", authenticated: true, version: "1.2.3" }, wsl))+ .toEqual({ state: "available", authenticated: true, version: "1.2.3", warning: WSL_ENGINE_WARNING });+ const own = { title: "Check ChatGPT connection", message: "plan" };+ expect(withWslNotice({ state: "available", warning: own }, wsl).warning).toEqual(own);+ expect(withWslNotice({ state: "available" }, "hermes")).toEqual({ state: "available" });+ expect(withWslNotice({ state: "unavailable", reason: "no distro" }, wsl)).not.toHaveProperty("warning");+ } finally {+ Object.defineProperty(process, "platform", platform);+ }+ });+});diff --git a/server/harness/wsl-launch.ts b/server/harness/wsl-launch.tsnew file mode 100644index 0000000000..5a0295e46d--- /dev/null+++ b/server/harness/wsl-launch.ts@@ -0,0 +1,27 @@+import { win32 } from "node:path";+import { splitCliString } from "../env-path.ts";+import type { ProviderSnapshot } from "../contracts.ts";++/** Shown on an engine whose custom command starts it inside WSL: it chats, but OpenMausBot's tool servers are Windows+ * programs on Windows' loopback, which the engine inside WSL can neither start nor reach. */+export const WSL_ENGINE_WARNING = {+ title: "This engine runs inside WSL",+ message: "Its command starts it inside WSL, so it can chat but can't use OpenMausBot's tools (team, browser, computer, data and the rest). Install the engine on Windows itself and set its CLI path to that install to get them.",+} as const;++/** Whether a custom CLI command starts the engine through WSL on Windows: wsl.exe, or the bash.exe in System32 that+ * forwards to WSL (Git Bash's bash.exe is a native Windows program and is not counted). Never true off Windows. */+export function launchesThroughWsl(cli: string | undefined, platform: NodeJS.Platform = process.platform): boolean {+ if (platform !== "win32" || !cli) return false;+ const head = (splitCliString(cli)[0] ?? "").toLowerCase();+ const name = win32.basename(head);+ if (name === "wsl" || name === "wsl.exe") return true;+ return /[\\/]windows[\\/](system32|sysnative)[\\/]bash(\.exe)?$/.test(head);+}++/** The status of an available engine with the WSL notice added when its command goes through WSL, unless the engine+ * reports a warning of its own. An unavailable engine keeps just its reason: it can't chat either. */+export function withWslNotice(snapshot: ProviderSnapshot, cli: string | undefined): ProviderSnapshot {+ const notice = snapshot.state === "available" && !snapshot.warning && launchesThroughWsl(cli);+ return notice ? { ...snapshot, warning: WSL_ENGINE_WARNING } : snapshot;+}