Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(claude): launch the CLI copy the turn checked, not one a newer PATH finds
AdityaUmalee01f37ef7b0b
diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.tsindex eb58556691..12f232b170 100644--- a/server/drivers/claude.test.ts+++ b/server/drivers/claude.test.ts@@ -2109,6 +2109,30 @@ describe("ClaudeDriver turns (fake CLI)", () => {resetPathCacheForTests();}});+ it.skipIf(process.platform === "win32")("launches the copy it checked when PATH finds another copy while the turn waits for that check", async () => {+ // The turn checks 2.1.321 and waits for its --version; PATH then finds 2.1.197 (refuses --system-prompt-snapshot).+ // The turn must launch the copy it checked, not the one a fresh PATH resolves at spawn time.+ const armed = join(scratch, "probe-path-armed"), asked = join(scratch, "probe-path-asked"), go = join(scratch, "probe-path-go"), olderRan = join(scratch, "probe-path-older-ran");+ const newer = join(scratch, "probe-path-newer"), older = join(scratch, "probe-path-older");+ mkdirSync(newer); mkdirSync(older);+ writeFileSync(join(newer, "claude"), `#!/bin/sh\nif [ "$1" = --version ] && [ -e "${armed}" ] && [ ! -e "${asked}" ]; then : > "${asked}"; while [ ! -e "${go}" ]; do sleep 0.05; done; fi\nFAKE_CLAUDE_VERSION=2.1.321 exec "${FAKE_CLI}" "$@"\n`, { mode: 0o755 });+ writeFileSync(join(older, "claude"), `#!/bin/sh\ncase "$1" in --version|--help) ;; *) : > "${olderRan}";; esac\nfor a in "$@"; do [ "$a" = --system-prompt-snapshot ] && { echo "error: unknown option '$a'" >&2; exit 1; }; done\nFAKE_CLAUDE_VERSION=2.1.197 exec "${FAKE_CLI}" "$@"\n`, { mode: 0o755 });+ try {+ resetPathCacheForTests();+ registerPathDir(newer);+ await create(undefined, {}, { cli: "claude" });+ writeFileSync(armed, "");+ const sent = instance.adapter.sendTurn({ threadId: "t-probe-path", text: "hi" });+ await vi.waitFor(() => expect(existsSync(asked)).toBe(true), { timeout: 5000 });+ registerPathDir(older);+ writeFileSync(go, "");+ await sent;+ expect(await recorder.until((e) => e.type === "turn.completed" && e.threadId === "t-probe-path")).toMatchObject({ ok: true });+ expect(existsSync(olderRan)).toBe(false);+ } finally {+ resetPathCacheForTests();+ }+ });it.skipIf(process.platform === "win32")("keeps the new copy's flags when the old copy's slower --help read finishes last", async () => {// snapshot() is still reading 2.1.321's help when PATH finds 2.1.197 (no --autocompact); that old read must not restore 2.1.321's flags.const refused = join(scratch, "stale-help-autocompact.jsonl"), helpStarted = join(scratch, "newer-help-started");diff --git a/server/drivers/claude.ts b/server/drivers/claude.tsindex 2eb648873b..87e1ce0f38 100644--- a/server/drivers/claude.ts+++ b/server/drivers/claude.ts@@ -1132,7 +1132,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {allowed.push("mcp__ogb", ...gateQueryTools(mcpServers));// A guest pre-allows only harness tools; anything else (the browser can open file:) asks.if (turn.guestConfined) allowed.splice(0, allowed.length, ...allowed.filter((name) => name === "mcp__ogb" || name === "mcp__agents"));- const env = withEndpointFolder(environment(config.endpointModels ? undefined : turnModel), config, () => retryState.delete(threadId));+ const env = withEndpointFolder(environment(config.endpointModels ? undefined : turnModel), config, () => retryState.delete(threadId)); env.PATH = turnEnvironment.PATH; // launch the copy this turn checked, not one a newer PATH finds// The MCP config carries credentials and argv is readable via `ps`: a 0600 file, removed at settle.let mcpConfigPath: string | null = null;if (Object.keys(mcpServers).length) {