Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Pass the deferral switch into the bot box; bridge e2e reads the deferred catalog

milind-soni90fcbd807074
diff --git a/server/agents-bridge.e2e.test.ts b/server/agents-bridge.e2e.test.ts
index 3aa6e52632..b0ca286e95 100644
--- a/server/agents-bridge.e2e.test.ts
+++ b/server/agents-bridge.e2e.test.ts
@@ -16,6 +16,7 @@ import { expect, it } from "vitest";
import { launchVerificationServer, runControlOmb } from "../scripts/control-omb.ts";
import type { WireMessage } from "../shared/wire.ts";
import { createToolBridge, type BridgeTool } from "./drivers/agents-bridge.ts";
+import { ALWAYS_LOAD_META, DEFER_TOOLS_ENV } from "./drivers/agents-claude-defer.ts";
import { gateServer } from "./mcp-gate-config.ts";
import { AGENTS_TOOL_BRIDGE_PROMPT } from "./system-prompt.ts";
import { turnEvidence } from "./turn-outcome.ts";
@@ -113,10 +114,14 @@ it("keeps a turn on the whole catalog until the switch is on, then mounts the br
const before = await launched();
const unbridged = before.mcpConfig.mcpServers.agents!;
expect(unbridged.env.OMB_AGENTS_TOOL_BRIDGE).toBe("0");
+ // A Claude turn marks all but a few tools deferred (agents-claude-defer.ts); the bridge, once on, lists none so marked.
+ expect(unbridged.env[DEFER_TOOLS_ENV]).toBe("1");
expect(before.systemPrompt).not.toContain("find_tool");
let whole: BridgeTool[] = [];
await withServer(unbridged, async (ask) => {
- whole = (await ask("tools/list")).result!.tools!;
+ const listed = (await ask("tools/list")).result!.tools! as Array<BridgeTool & { _meta?: Record<string, unknown> }>;
+ expect(listed.some((tool) => tool._meta?.[ALWAYS_LOAD_META] === false)).toBe(true);
+ whole = listed.map(({ _meta: _marks, ...tool }) => tool);
expect(whole.map((tool) => tool.name)).toEqual(expect.arrayContaining(["coordinate_bots", "trigger", "trigger_info", "session_search"]));
expect(whole.map((tool) => tool.name)).not.toEqual(expect.arrayContaining(["find_tool"]));
expect(whole.length).toBeGreaterThan(25);
diff --git a/server/bot-box/env.ts b/server/bot-box/env.ts
index 52c55adff9..ccb7261c2d 100644
--- a/server/bot-box/env.ts
+++ b/server/bot-box/env.ts
@@ -20,7 +20,7 @@ export const BOX_ENV_OMB_NAMES: ReadonlySet<string> = new Set([
"OMB_HARNESS_URL", "OMB_BOT_ID", "OMB_THREAD_ID", "OMB_COMMS_TOKEN", "OMB_TURN_DEPTH", "OMB_EXTERNAL_RUNTIME",
"OMB_CHIEF_OF_STAFF", "OMB_MAUSBOT", "OMB_SKILL_AUTHORING_ENABLED", "OMB_MEMORY_ENABLED", "OMB_SHARED_COMPUTERS_ENABLED",
"OMB_VOICE_NOTES", "OMB_X_RESEARCH", "OMB_RESEARCH", "OMB_TEAM_PEOPLE", "OMB_COMPUTER_SELECTION", "OMB_ROOM",
- "OMB_IMAGE_GENERATION", "OMB_MEETINGS", "OMB_APP_HOSTING", "OMB_AGENTS_TOOL_BRIDGE", "OMB_TOOL_LIMIT", "OMB_TOOL_SCHEMA_PROFILE",
+ "OMB_IMAGE_GENERATION", "OMB_MEETINGS", "OMB_APP_HOSTING", "OMB_AGENTS_TOOL_BRIDGE", "OMB_AGENTS_DEFER_TOOLS", "OMB_TOOL_LIMIT", "OMB_TOOL_SCHEMA_PROFILE",
"OMB_MCP_CONFIG", "OMB_MCP_RESTART", "OMB_MCP_RESULT_BUDGET",
"OMB_HOOK_URL", "OMB_HOOK_TOKEN_FILE", "OMB_HOOK_TIMEOUT_MS", "OMB_PERMISSION_TOOL_SCOPE",
"OMB_CONNECTOR_UPSTREAM_URL", "OMB_CONNECTOR_UPSTREAM_HEADERS", "OMB_CONNECTOR_TOKEN", "OMB_CONNECTOR_ALLOWED_TOOLS",
diff --git a/server/drivers/claude-box.test.ts b/server/drivers/claude-box.test.ts
index e641f96fb2..9ba74ffdc8 100644
--- a/server/drivers/claude-box.test.ts
+++ b/server/drivers/claude-box.test.ts
@@ -11,11 +11,13 @@ import { fileURLToPath } from "node:url";
import { afterEach, describe, expect, it, vi } from "vitest";
import { botBox, type WrappedSpawn } from "../bot-box/box.ts";
+import { boxEnvironment } from "../bot-box/env.ts";
import { visibleInBox } from "../bot-box/plan.ts";
import { DATA_DIR, ensureDirs } from "../config.ts";
import type { ProviderInstance } from "../contracts.ts";
import { removeTempDir } from "../testing/cleanup.ts";
import { recordEvents } from "../testing/events.ts";
+import { DEFER_TOOLS_ENV } from "./agents-claude-defer.ts";
import { ClaudeDriver, hookTokenFile } from "./claude.ts";
const FAKE_CLI = join(dirname(fileURLToPath(import.meta.url)), "..", "testing", "fake-claude-cli.ts");
@@ -199,4 +201,37 @@ describe("a Claude turn in the bot box", () => {
expect(boxed!.plan.mounts, "the endpoint folder is bound on its own line").toContainEqual(expect.objectContaining({ source: configDir, target: configDir }));
expect(visibleInBox(boxed!.plan, configDir)).toBe("rw");
}, 60_000);
+
+ it.skipIf(process.platform === "win32")("defers the agents tools in the box as outside it", async () => {
+ ensureDirs();
+ chmodSync(FAKE_CLI, 0o755);
+ const scratch = mkdtempSync(join(tmpdir(), "omb-claude-box-defer-"));
+ dirs.push(scratch);
+ const fakeBwrap = join(scratch, "fake-bwrap.sh");
+ writeFileSync(fakeBwrap, `#!/bin/sh\nwhile [ "$1" != "--" ]; do shift; done; shift\nexec "$@"\n`);
+ chmodSync(fakeBwrap, 0o755);
+ await botBox.start({
+ dataDir: DATA_DIR, home: homedir(), port: 8799, denyEnv: new Set(), env: {}, log: () => {},
+ detect: () => ({ box: "bwrap", reason: null, tools: { bwrap: fakeBwrap, socat: "/usr/bin/true" } }),
+ });
+ const wrap = vi.spyOn(botBox, "wrap");
+ delete process.env.TMPDIR;
+ const dump = join(scratch, "dump.json");
+ process.env.FAKE_CLAUDE_DUMP = dump;
+ instance = await ClaudeDriver.create({ instanceId: "claude-box", displayName: "Claude", environment: {}, enabled: true, config: { cli: FAKE_CLI, permissionMode: "acceptEdits" } });
+ const recorder = recordEvents(instance.adapter);
+ const cwd = join(DATA_DIR, "task-workspaces", "bot-a", "t-boxed-defer");
+ mkdirSync(cwd, { recursive: true });
+
+ await instance.adapter.sendTurn({
+ threadId: "t-boxed-defer", botId: "bot-a", text: "hi", approvalMode: "full", cwd,
+ integrations: { agents: { command: process.execPath, args: ["/fake/agents-proxy.js"], env: { OMB_BOT_ID: "bot-a" } } },
+ });
+ await recorder.until((event) => event.type === "turn.completed", 30_000);
+
+ expect(wrap.mock.results.some((result) => (result.value as WrappedSpawn | null)?.plan.botId === "bot-a"), "the engine ran in the box").toBe(true);
+ const agents = JSON.parse(readFileSync(dump, "utf8")).mcpConfig.mcpServers.agents as { alwaysLoad?: boolean; env: Record<string, string> };
+ expect(agents).toMatchObject({ alwaysLoad: true, env: { [DEFER_TOOLS_ENV]: "1" } });
+ expect(boxEnvironment(agents.env)[DEFER_TOOLS_ENV], "the box passes the switch to the proxy").toBe("1");
+ }, 60_000);
});