Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(claude): drop the old copy's flags when a newly found copy's version check fails
AdityaUmale2fb0c3fc6907
diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.tsindex 02650d1222..4e19ec3b86 100644--- a/server/drivers/claude.test.ts+++ b/server/drivers/claude.test.ts@@ -1997,6 +1997,29 @@ describe("ClaudeDriver turns (fake CLI)", () => {resetPathCacheForTests();}});+ it.skipIf(process.platform === "win32")("passes none of the old copy's flags when the newly found copy's version check fails, and checks it again next turn", async () => {+ const dump = join(scratch, "path-swap-fail.json"), failedOnce = join(scratch, "older-version-failed");+ const newer = join(scratch, "newer-f"), older = join(scratch, "older-f");+ mkdirSync(newer); mkdirSync(older);+ writeFileSync(join(newer, "claude"), `#!/bin/sh\nFAKE_CLAUDE_VERSION=2.1.321 exec "${FAKE_CLI}" "$@"\n`, { mode: 0o755 });+ // The older copy: its first --version fails, and it refuses --system-prompt-snapshot like 2.1.197 does.+ writeFileSync(join(older, "claude"), `#!/bin/sh\n[ "$1" = --version ] && [ ! -e "${failedOnce}" ] && { : > "${failedOnce}"; exit 1; }\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, { FAKE_CLAUDE_DUMP: dump }, { cli: "claude" });+ expect(await instance.snapshot()).toMatchObject({ version: "2.1.321 (Claude Code)" });+ registerPathDir(older);+ for (const threadId of ["t-swap-fail-1", "t-swap-fail-2"]) {+ await instance.adapter.sendTurn({ threadId, text: "hi" });+ expect(await recorder.until((e) => e.type === "turn.completed" && e.threadId === threadId)).toMatchObject({ ok: true });+ expect(JSON.parse(readFileSync(dump, "utf8")).argv).not.toContain("--system-prompt-snapshot");+ }+ expect(existsSync(failedOnce)).toBe(true);+ } finally {+ resetPathCacheForTests();+ }+ });it("withholds --autocompact from a CLI above the floor whose --help does not list it", async () => {// 2.1.129 clears the 2.1.122 floor yet rejects the flag ("unknown option")const dump = join(scratch, "no-autocompact-cli.json");diff --git a/server/drivers/claude.ts b/server/drivers/claude.tsindex a8fc1bfa9b..2de4e0512c 100644--- a/server/drivers/claude.ts+++ b/server/drivers/claude.ts@@ -805,11 +805,11 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {let [cliHasAutocompact, cliHelpVersion]: [boolean | null, string | null] = [null, null], autocompactRefusedBy = new Set<string>(), cliProbedAt: string | undefined;const readCliVersion = cliVersionProbe(config.cli);const ensureCliVersion = async (env: NodeJS.ProcessEnv): Promise<void> => { // and again once PATH finds another copy (an nvm one ahead of Homebrew's)- const at = findCliCandidates(config.cli, env.PATH ?? "")[0], reprobed = cliVersionChecked;+ const at = findCliCandidates(config.cli, env.PATH ?? "")[0], reprobed = cliVersionChecked, seen = cliProbedAt !== undefined;if (reprobed && at === cliProbedAt) { await helpRead?.done; return; } // a help read for this copy may still be runningconst probe = await readCliVersion(env);- if ("version" in probe) [cliVersion, cliVersionChecked, cliProbedAt] = [parseClaudeCliVersion(probe.version), true, at];- if (reprobed && "version" in probe && probe.version !== cliHelpVersion) await readCliHelp(probe.version, env);+ if ("version" in probe) [cliVersion, cliVersionChecked, cliProbedAt] = [parseClaudeCliVersion(probe.version), true, at]; else if (reprobed) [cliVersion, cliVersionChecked, cliHasAutocompact, cliHelpVersion] = [null, false, null, null]; // another copy that could not be checked: none of the old copy's flags, check again next turn+ if (seen && "version" in probe && probe.version !== cliHelpVersion) await readCliHelp(probe.version, env);};let helpRead: { version: string; done: Promise<void> } | null = null;const readCliHelp = (version: string, env: NodeJS.ProcessEnv): Promise<void> => {