Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(claude): on Windows launch the checked CLI copy by its path
AdityaUmale006f84802ae1
diff --git a/server/cli-version-probe.test.ts b/server/cli-version-probe.test.tsindex 9025263928..bfe90fd291 100644--- a/server/cli-version-probe.test.ts+++ b/server/cli-version-probe.test.ts@@ -2,7 +2,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { delimiter, join } from "node:path";import { afterEach, expect, it, vi } from "vitest";-import { cliVersionProbe } from "./cli-version-probe.ts";+import { cliToLaunch, cliVersionProbe } from "./cli-version-probe.ts";import { cliVersionReader, type execCli } from "./procs.ts";afterEach(() => vi.useRealTimers());@@ -111,3 +111,10 @@ it("does not report one copy's version for another copy that PATH now finds firsrmSync(root, { recursive: true, force: true });}});++it("launches the checked copy by its path on Windows, where spawn resolves the app's PATH rather than the turn's", () => {+ const checked = join("C:", "Users", "me", "AppData", "Roaming", "npm", "claude.cmd");+ expect(cliToLaunch("claude", checked, "win32")).toBe(checked);+ expect(cliToLaunch("claude", undefined, "win32")).toBe("claude"); // nothing found on the turn's PATH: unchanged+ for (const platform of ["darwin", "linux"] as const) expect(cliToLaunch("claude", "/opt/homebrew/bin/claude", platform)).toBe("claude"); // POSIX spawn already uses the turn's PATH+});diff --git a/server/cli-version-probe.ts b/server/cli-version-probe.tsindex 8f1483b4b0..5067fc4f7b 100644--- a/server/cli-version-probe.ts+++ b/server/cli-version-probe.ts@@ -1,6 +1,11 @@import { findCliCandidates } from "./env-path.ts";import { CLI_VERSION_TIMEOUT_MS, cliVersionReader, execCli } from "./procs.ts";+/** What to launch: on Windows the checked copy's own path, since spawn-time resolution reads the app's PATH, not the turn's (POSIX spawn already looks up the turn's PATH). */+export function cliToLaunch(cli: string, checked: string | undefined, platform: NodeJS.Platform = process.platform): string {+ return platform === "win32" && checked ? checked : cli;+}+// Shares version checks and retries empty responses. A failed check falls back to the last version only while PATH// still finds the same copy of the CLI, so a newly found copy is never reported with another copy's version.export function cliVersionProbe(cli: string, run: typeof execCli = execCli) {diff --git a/server/drivers/claude.ts b/server/drivers/claude.tsindex 87e1ce0f38..042b02bd68 100644--- a/server/drivers/claude.ts+++ b/server/drivers/claude.ts@@ -11,7 +11,7 @@ import { openStartupModelCatalog, unconfirmedModelCatalog, writeStartupModelCachimport { writeFileAtomicIfChanged } from "../atomic.ts";import { augmentedPath, findCliCandidates } from "../env-path.ts";import { brokerSocketPath, describeSpawnFailure, execCli, killCliTree, spawnCli } from "../procs.ts";-import { cliVersionProbe } from "../cli-version-probe.ts";+import { cliToLaunch, cliVersionProbe } from "../cli-version-probe.ts";import { claudeAuthStatus } from "./claude-auth-status.ts";import { projectMcpServers } from "./claude-project-mcp.ts";import { botSettingsFor, withBotSettings } from "./claude-bot-settings.ts";@@ -1323,7 +1323,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {let child: ReturnType<typeof spawnCli>;try {- child = spawnCli(config.cli, args, { cwd, env, stdio: ["pipe", "pipe", "pipe"], box: { ...(broker ? { rw: [broker.socketPath] } : {}), ...(hookTokenPath ? { ro: [dirname(hookTokenPath)] } : {}) } }, "bot");+ child = spawnCli(cliToLaunch(config.cli, launchCli), args, { cwd, env, stdio: ["pipe", "pipe", "pipe"], box: { ...(broker ? { rw: [broker.socketPath] } : {}), ...(hookTokenPath ? { ro: [dirname(hookTokenPath)] } : {}) } }, "bot");} catch (error) {cleanupUnownedLaunch();throw error;