Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(claude): scope an --autocompact refusal to the CLI version that launched the turn
AdityaUmaleb964c5f01531
diff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.tsindex e3748cfaa7..2d606631f5 100644--- a/server/drivers/claude.test.ts+++ b/server/drivers/claude.test.ts@@ -2000,6 +2000,33 @@ describe("ClaudeDriver turns (fake CLI)", () => {expect(readFileSync(refused, "utf8").trim().split("\n")).toHaveLength(1);});+ it("keeps --autocompact for a newer CLI when an older CLI's turn refuses it after the newer help probe", async () => {+ const dump = join(scratch, "newer-cli-autocompact.json");+ const refused = join(scratch, "older-cli-refused.jsonl");+ const gate = join(scratch, "older-cli-gate");+ const saved = { ...process.env };+ try {+ Object.assign(process.env, { FAKE_CLAUDE_REJECT_AUTOCOMPACT: refused, FAKE_CLAUDE_REJECT_GATE: gate, FAKE_CLAUDE_VERSION: "2.1.232" });+ await create(undefined, { FAKE_CLAUDE_DUMP: dump });+ await instance.snapshot();+ await instance.adapter.sendTurn({ threadId: "t-older-cli-refuses", text: "first" });+ await vi.waitFor(() => expect(existsSync(`${gate}.waiting`)).toBe(true), { timeout: 10_000 });+ // The CLI is swapped for a newer one that accepts the flag; its help probe lands before the old turn exits.+ delete process.env.FAKE_CLAUDE_REJECT_AUTOCOMPACT;+ process.env.FAKE_CLAUDE_VERSION = "2.1.240";+ await instance.snapshot();+ writeFileSync(gate, "");+ const done = await recorder.until((e) => e.type === "turn.completed" && e.threadId === "t-older-cli-refuses");+ expect(done).toMatchObject({ type: "turn.completed", ok: true });+ expect(readFileSync(refused, "utf8").trim().split("\n")).toHaveLength(1);+ expect(JSON.parse(readFileSync(dump, "utf8")).argv).toContain("--autocompact");+ } finally {+ for (const key of ["FAKE_CLAUDE_REJECT_AUTOCOMPACT", "FAKE_CLAUDE_REJECT_GATE", "FAKE_CLAUDE_VERSION"]) {+ if (saved[key] === undefined) delete process.env[key]; else process.env[key] = saved[key];+ }+ }+ });+it("keeps only the isolation flag a very old CLI accepts", async () => {// 1.0.100: --strict-mcp-config exists (1.0.60), --setting-sources not yet (1.0.122).const dump = join(scratch, "very-old-cli.json");diff --git a/server/drivers/claude.ts b/server/drivers/claude.tsindex 636299c06a..4c1e560c1e 100644--- a/server/drivers/claude.ts+++ b/server/drivers/claude.ts@@ -837,7 +837,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {elicit: ReturnType<typeof claudeElicitations>;mcpConfigPath: string | null;systemPromptPath: string | null;- argsKey: string;+ argsKey: string; /** the CLI version whose --help chose the args */ cliVersion: string | null;/** the volatile half the conversation holds; null once a compaction may have summarized it away */volatile: string | null;sessionId: string | null;@@ -1350,7 +1350,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {(event) => emit({ ...base(threadId, session.turn?.turnId ?? turnId), ...event })),mcpConfigPath,systemPromptPath,- argsKey,+ argsKey, cliVersion: cliHelpVersion,volatile: turn.systemVolatile ?? "",sessionId: sessionId ?? newSessionId,sawInit: false,@@ -1716,7 +1716,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {const { turnId, input: turn, retryAbort } = session.turn;// Commander prints this last before exiting; only a launch that passed the flag counts, so the flag-less relaunch can't loop.const refusedAutocompact = session.argsKey.includes('"--autocompact"') && /unknown option '--autocompact'/.test(session.stderr);- if (refusedAutocompact) [cliHasAutocompact, autocompactRefusedBy] = [false, cliHelpVersion];+ if (refusedAutocompact) [cliHasAutocompact, autocompactRefusedBy] = [session.cliVersion === cliHelpVersion ? false : cliHasAutocompact, session.cliVersion];const retry = retryState.get(threadId) ?? { attempt: 0, cancelled: false };const message = `claude exited ${code} before result${session.stderr ? `: ${session.stderr.trim().slice(-300)}` : ""}`;const verdict = classifyError({ exitCode: code, stderr: message });diff --git a/server/testing/fake-claude-cli.ts b/server/testing/fake-claude-cli.tsindex 042739400f..5ef9e25dcf 100755--- a/server/testing/fake-claude-cli.ts+++ b/server/testing/fake-claude-cli.ts@@ -52,6 +52,7 @@// processes; a compaction leaves FAKE_CLAUDE_COMPACTED_TOKENS (default 30000)// FAKE_CLAUDE_REJECT_AUTOCOMPACT a file: --help still lists --autocompact, but a turn given it appends its argv// there as a JSON line and exits 1 with "error: unknown option '--autocompact'" (a CLI that changed under a running app)+// FAKE_CLAUDE_REJECT_GATE path: that refusal first writes `<path>.waiting`, then waits until <path> exists// FAKE_CLAUDE_AUTOCOMPACT_AT tokens: a turn that starts at or above it compacts first, as Claude Code does at its threshold// (PreCompact, FAKE_CLAUDE_COMPACT_MS of nothing, compact_boundary, then SessionStart "compact")// FAKE_CLAUDE_COMPACT_MS how long a compaction takes: that one, or a one-shot `/compact` on a fork@@ -320,6 +321,9 @@ if (argv[0] === "--help") {}if (process.env.FAKE_CLAUDE_REJECT_AUTOCOMPACT && argv.includes("--autocompact")) {+ const gate = process.env.FAKE_CLAUDE_REJECT_GATE;+ if (gate) writeFileSync(`${gate}.waiting`, "");+ while (gate && !existsSync(gate)) await new Promise((resolve) => setTimeout(resolve, 20));appendFileSync(process.env.FAKE_CLAUDE_REJECT_AUTOCOMPACT, `${JSON.stringify(argv)}\n`);process.stderr.write("error: unknown option '--autocompact'\n");process.exit(1);