Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(mcp): keep an MCP output limit set in the turn's own folder
AdityaUmale83d238f9f16e
diff --git a/server/drivers/claude-bot-settings.ts b/server/drivers/claude-bot-settings.tsindex 0730ad0741..011e33e8ea 100644--- a/server/drivers/claude-bot-settings.ts+++ b/server/drivers/claude-bot-settings.ts@@ -31,8 +31,17 @@ function readBotSettings(file: string, cwd: string): unknown {try {if (realpathSync(join(cwd, ".claude", "settings.json")) === real) return null;} catch {}+ return readJson(real);+ } catch {+ return null;+ }+}++/** A regular settings file's JSON, never through a link, or null. */+function readJson(path: string): unknown {+ try {// O_NONBLOCK: a planted FIFO must not hang the open.- const fd = openSync(real, constants.O_RDONLY | (process.platform === "win32" ? 0 : constants.O_NOFOLLOW | constants.O_NONBLOCK));+ const fd = openSync(path, constants.O_RDONLY | (process.platform === "win32" ? 0 : constants.O_NOFOLLOW | constants.O_NONBLOCK));try {const stat = fstatSync(fd);return stat.isFile() && stat.size <= MAX_BYTES ? JSON.parse(readFileSync(fd, "utf8")) : null;@@ -44,6 +53,17 @@ function readBotSettings(file: string, cwd: string): unknown {}}+/** An env value the turn's own folder sets in the settings Claude Code reads there itself (project, then local), or undefined. */+export function folderSettingsEnv(cwd: string, name: string): string | undefined {+ let found: string | undefined;+ for (const file of ["settings.json", "settings.local.json"]) {+ const parsed = readJson(join(cwd, ".claude", file));+ const value = isObject(parsed) && isObject(parsed.env) ? parsed.env[name] : undefined;+ if (typeof value === "string") found = value;+ }+ return found;+}+/** What a turn takes from the bot's settings file: its hooks, plugins, permission rules and env. They ride in* OpenMausBot's own --settings file (Claude Code takes one), and Claude Code 2.1.312 drops a whole settings file when a* field it knows has the wrong type, so only these, each checked, come along. An env name the turn's process alreadydiff --git a/server/drivers/claude.test.ts b/server/drivers/claude.test.tsindex cf7effb222..06919c4067 100644--- a/server/drivers/claude.test.ts+++ b/server/drivers/claude.test.ts@@ -1708,6 +1708,17 @@ describe("ClaudeDriver turns (fake CLI)", () => {expect(seen.settings.env.MAX_MCP_OUTPUT_TOKENS).toBe("40000");});+ it("keeps an MCP output limit set in the turn's own folder, which Claude Code reads itself", async () => {+ const dump = join(scratch, "bot-settings-own-mcp-limit.json");+ process.env.FAKE_CLAUDE_DUMP = dump;+ await create();+ const { bot, file } = botFolders("own-mcp-limit", { env: { MAX_MCP_OUTPUT_TOKENS: "40000" } });+ await instance.adapter.sendTurn({ threadId: "t-bot-settings-own-mcp-limit", text: "hi", cwd: bot, botSettingsFile: file,+ integrations: { custom: { docs: { type: "http", url: "https://docs.example/mcp", headers: {} } } } });+ await recorder.until((e) => e.type === "turn.completed");+ expect(JSON.parse(readFileSync(dump, "utf8")).env.MAX_MCP_OUTPUT_TOKENS).toBeUndefined();+ });+it("is left to Claude Code when the turn runs in the folder that holds it", async () => {const dump = join(scratch, "bot-settings-own-folder.json");process.env.FAKE_CLAUDE_DUMP = dump;diff --git a/server/drivers/claude.ts b/server/drivers/claude.tsindex 6b478e6d2b..28a96455ca 100644--- a/server/drivers/claude.ts+++ b/server/drivers/claude.ts@@ -14,7 +14,7 @@ import { brokerSocketPath, describeSpawnFailure, execCli, killCliTree, spawnCliimport { 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";+import { botSettingsFor, folderSettingsEnv, withBotSettings } from "./claude-bot-settings.ts";import { claudeBilling, claudeCallUsage } from "./claude-billing.ts";import { claudeAuthFailure, claudeAuthRecovery, claudeOAuthExpired } from "./claude-auth-recovery.ts"; import { AWS_CREDENTIAL_ENV_KEYS, bedrockResultError, withBedrockCredentialError } from "./claude-bedrock-aws.ts";import { CLAUDE_MODEL_ID, STATIC_CLAUDE_MODELS, claudeModelExtras, currentEngineCatalog, endpointModelCatalog, withCliVersionGate } from "./claude-model-extras.ts";@@ -1184,7 +1184,7 @@ export const ClaudeDriver: ProviderDriver<ClaudeConfig> = {// Approvals and browser credentials expire at the turn boundary; native background workers must not outlive it.env.CLAUDE_CODE_DISABLE_BACKGROUND_TASKS = "1";// Never for a guest: --restricted leaves project settings out, and a hook is a command. The MCP output limit comes after, so one the bot set there is kept.- const botSettings = turn.guestConfined ? {} : botSettingsFor(turn.botSettingsFile, cwd, env); limitUngatedOutput(env, mcpServers, botOwned, turn.integrations?.customResultBudgets, (botSettings.env as Record<string, unknown> | undefined)?.MAX_MCP_OUTPUT_TOKENS);+ const botSettings = turn.guestConfined ? {} : botSettingsFor(turn.botSettingsFile, cwd, env); limitUngatedOutput(env, mcpServers, botOwned, turn.integrations?.customResultBudgets, (botSettings.env as Record<string, unknown> | undefined)?.MAX_MCP_OUTPUT_TOKENS ?? (turn.guestConfined ? undefined : folderSettingsEnv(cwd, "MAX_MCP_OUTPUT_TOKENS")));const settings = withBotSettings(botSettings, own);const authSettingsPath = mcpConfigPath && Object.keys(settings).length? join(dirname(mcpConfigPath), "auth-settings.json") : null;