Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(agents): do not offer the Local VM tools on a server that cannot give a Local VM
David Neyra1e9137b87d69
diff --git a/server/agents-bridge-names.ts b/server/agents-bridge-names.tsindex 83e565d688..6e793f7bc6 100644--- a/server/agents-bridge-names.ts+++ b/server/agents-bridge-names.ts@@ -8,7 +8,7 @@ import { availableTools } from "./drivers/agents-catalog.ts";/** Every catalog tool's name, whoever may call it, and every alias a call may still use. */export const CATALOG_TOOL_NAMES: ReadonlySet<string> = new Set([...availableTools({skillAuthoring: true, sharedComputers: true, voiceNotes: true, xResearch: true, research: true, team: true,- computerSelection: true, cloudHome: false, chief: true, mausbot: true, botId: WATCHER_OPTIONS_CARD_BOT_ID,+ computerSelection: true, cloudHome: false, localVm: true, chief: true, mausbot: true, botId: WATCHER_OPTIONS_CARD_BOT_ID,}).map((tool) => tool.name), ...Object.keys(AGENTS_TOOL_ALIASES)]);/** A call's name with a bridged call read as the tool it ran. With `serverNamed`, only a title that namesdiff --git a/server/agents-turn.test.ts b/server/agents-turn.test.tsindex 08314e6621..3181530350 100644--- a/server/agents-turn.test.ts+++ b/server/agents-turn.test.ts@@ -6,7 +6,7 @@ import { TOOL_BRIDGE_ENV } from "./drivers/agents-bridge.ts";import { agentsMcp } from "./drivers/agents-mcp.ts";import { agentsServerEnv, botDrivenConversation, COMPUTER_OFF_REFUSAL, computerPickRefusal, directTurnKind, roomSkillsRefusal, type AgentsConversation, type AgentsTurn } from "./agents-turn.ts";-const HOST: AgentsConversation["host"] = { skillAuthoring: true, sharedComputers: true, cloudHome: false, team: false, voiceNotes: true, x: true, research: true, imageGeneration: false };+const HOST: AgentsConversation["host"] = { skillAuthoring: true, sharedComputers: true, cloudHome: false, team: false, voiceNotes: true, x: true, research: true, imageGeneration: false, localVm: true };const CHAT: AgentsConversation = { threadId: "thread-1", bot: { id: "bot-1", chiefOfStaff: true }, room: false, teamComputer: false, host: HOST };const ROOM: AgentsConversation = { ...CHAT, threadId: "room-1", room: true };diff --git a/server/agents-turn.ts b/server/agents-turn.tsindex 67b1c1f992..df02729a98 100644--- a/server/agents-turn.ts+++ b/server/agents-turn.ts@@ -18,7 +18,7 @@ export interface AgentsConversation {botDriven?: boolean;/** `x`: a research credential is held (a treg key or a plan's); `research`: research works for it too; `appHosting`:* the plan's included app hosting reaches this server. */- host: { skillAuthoring: boolean; sharedComputers: boolean; cloudHome: boolean; team: boolean; voiceNotes: boolean; x: boolean; research: boolean; imageGeneration: boolean; meetings?: boolean; appHosting?: boolean };+ host: { skillAuthoring: boolean; sharedComputers: boolean; cloudHome: boolean; team: boolean; voiceNotes: boolean; x: boolean; research: boolean; imageGeneration: boolean; meetings?: boolean; appHosting?: boolean; localVm: boolean };}/** What one turn may do. Its bearer carries this to the harness, which checks it on every call. */@@ -53,6 +53,7 @@ export function agentsServerEnv(conversation: AgentsConversation, turn: AgentsTuOMB_MEETINGS: flag(host.meetings === true && !conversation.room),OMB_APP_HOSTING: flag(host.appHosting === true),OMB_COMPUTER_SELECTION: flag(!conversation.room && bot.computer !== "off" && !conversation.teamComputer && !conversation.botDriven),+ OMB_LOCAL_VM: flag(host.localVm),[TOOLS_OFF_ENV]: (bot.toolsOff ?? []).join(","),};}diff --git a/server/bot-box/env.ts b/server/bot-box/env.tsindex b415cce99b..a384d2ddd7 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_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_TOOLS_OFF", "OMB_AGENTS_TOOL_BRIDGE", "OMB_AGENTS_DEFER_TOOLS", "OMB_TOOL_LIMIT", "OMB_TOOL_SCHEMA_PROFILE",+ "OMB_IMAGE_GENERATION", "OMB_MEETINGS", "OMB_APP_HOSTING", "OMB_TOOLS_OFF", "OMB_LOCAL_VM", "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/agents-catalog-local-vm.test.ts b/server/drivers/agents-catalog-local-vm.test.tsnew file mode 100644index 0000000000..496fea9b24--- /dev/null+++ b/server/drivers/agents-catalog-local-vm.test.ts@@ -0,0 +1,21 @@+import { describe, expect, it } from "vitest";++import { availableTools, type CatalogProfile } from "./agents-catalog.ts";++const PROFILE: CatalogProfile = {+ skillAuthoring: false, sharedComputers: false, voiceNotes: false, cloudHome: false, chief: false, botId: "bot-scout",+};++describe("the Local VM's tools", () => {+ it("are not listed on a server that cannot give a bot a Local VM", () => {+ expect(availableTools({ ...PROFILE, localVm: false }).map((tool) => tool.name)).not.toContain("vm_exec");+ });++ it("are listed when it can", () => {+ expect(availableTools({ ...PROFILE, localVm: true }).map((tool) => tool.name)).toContain("vm_exec");+ });++ it("are listed when the server does not say", () => {+ expect(availableTools(PROFILE).map((tool) => tool.name)).toContain("vm_exec");+ });+});diff --git a/server/drivers/agents-catalog-profile.ts b/server/drivers/agents-catalog-profile.tsindex e2d7ea62dd..c442eaaff7 100644--- a/server/drivers/agents-catalog-profile.ts+++ b/server/drivers/agents-catalog-profile.ts@@ -27,6 +27,9 @@ export interface CatalogProfile {/** A direct chat whose bot may pick where it works (Works on is not Off and no team computer is its own): select_computer* is mounted, and the harness refuses a pick on any turn but a person's own message. */computerSelection?: boolean;+ /** This server can give a bot a Local VM: a supported container runtime is installed on the host.+ * Absent means it can. */+ localVm?: boolean;/** A room's thread: the wait tools are not mounted, since a room holds no wait. */room?: boolean;imageGeneration?: boolean;@@ -53,6 +56,7 @@ export function catalogProfileFromEnv(env: NodeJS.ProcessEnv): CatalogProfile {team: env.OMB_TEAM_PEOPLE === "1",mausbot: env.OMB_MAUSBOT === "1",computerSelection: env.OMB_COMPUTER_SELECTION === "1",+ localVm: env.OMB_LOCAL_VM !== "0",room: env.OMB_ROOM === "1",imageGeneration: env.OMB_IMAGE_GENERATION === "1",meetings: env.OMB_MEETINGS === "1",diff --git a/server/drivers/agents-catalog.ts b/server/drivers/agents-catalog.tsindex 9bfb205b9b..3dd7e5f0ab 100644--- a/server/drivers/agents-catalog.ts+++ b/server/drivers/agents-catalog.ts@@ -817,7 +817,11 @@ export function availableTools(profile: CatalogProfile) {? tools.filter(tool => !LOCAL_VM_TOOL_NAMES.has(tool.name)).map(tool => tool.name === "select_computer"? { ...tool, inputSchema: { ...tool.inputSchema, properties: { surface: CLOUD_HOME_SURFACE } } }: tool)- : tools;+ // A model shown a tool it cannot use spends turns finding out: with no container runtime there is+ // no Local VM to run a command in.+ : profile.localVm === false+ ? tools.filter(tool => !LOCAL_VM_TOOL_NAMES.has(tool.name))+ : tools;return placed.map((tool) => ({ ...tool, inputSchema: advertisedSchema(tool.inputSchema, tool.description) }));}diff --git a/server/drivers/agents-mcp-env.ts b/server/drivers/agents-mcp-env.tsindex 80ad7dbdab..b6c1852444 100644--- a/server/drivers/agents-mcp-env.ts+++ b/server/drivers/agents-mcp-env.ts@@ -5,6 +5,6 @@ import { DEFER_TOOLS_ENV } from "./agents-claude-defer.ts";/** The settings the harness gives the agents MCP server, and the only ones a request may carry over HTTP. */export const AGENTS_MCP_ENV = ["OMB_BOT_ID", "OMB_THREAD_ID", "OMB_EXTERNAL_RUNTIME", "OMB_CHIEF_OF_STAFF","OMB_SKILL_AUTHORING_ENABLED", "OMB_MEMORY_ENABLED", "OMB_SHARED_COMPUTERS_ENABLED", "OMB_CLOUD_HOME", "OMB_VOICE_NOTES",- "OMB_X_RESEARCH", "OMB_RESEARCH", "OMB_TEAM_PEOPLE", "OMB_MAUSBOT", "OMB_COMPUTER_SELECTION", "OMB_ROOM", "OMB_IMAGE_GENERATION", "OMB_MEETINGS", "OMB_APP_HOSTING", "OMB_TOOLS_OFF", TOOL_BRIDGE_ENV, TOOL_LIMIT_ENV,+ "OMB_X_RESEARCH", "OMB_RESEARCH", "OMB_TEAM_PEOPLE", "OMB_MAUSBOT", "OMB_COMPUTER_SELECTION", "OMB_ROOM", "OMB_IMAGE_GENERATION", "OMB_MEETINGS", "OMB_APP_HOSTING", "OMB_TOOLS_OFF", "OMB_LOCAL_VM", TOOL_BRIDGE_ENV, TOOL_LIMIT_ENV,// Claude's deferred catalog: the URL form carries it as the stdio proxy's environment does.DEFER_TOOLS_ENV] as const;diff --git a/server/harness-capabilities.ts b/server/harness-capabilities.tsindex 5e8784e585..c8fab9fc89 100644--- a/server/harness-capabilities.ts+++ b/server/harness-capabilities.ts@@ -13,6 +13,7 @@ const ENVELOPE: CatalogProfile = {voiceNotes: true,computerSelection: true,cloudHome: false,+ localVm: true,chief: true,botId: "",};diff --git a/server/index.ts b/server/index.tsindex 26e1af6878..d056ab75b1 100644--- a/server/index.ts+++ b/server/index.ts@@ -281,7 +281,7 @@ import { lentCopies, noteSyncBotTurn } from "./routes/cloud-sync.ts"; import { mimport { type CloudOwnership } from "./cloud-owner.ts"; import { memberLoginRefusal, personalMoveRefusal } from "./cloud-team.ts"; import { createCloudTeamHost, type MemberProfile } from "./host/cloud-team-host.ts"; import { engineHomes } from "./engine-homes/engine-homes.ts"; import { audienceMember, layerId, memberAudience } from "./audience.ts"; import { createPersonRooms, createRoomReads, type OwnGroupFrames } from "./host/room-reads.ts"; import { createPersonBotOrder } from "./host/person-bot-order.ts"; import { createMeRoutes } from "./routes/me.ts"; import { createTeamPhoneRoutes } from "./routes/team-phone.ts"; import { settleCloudHome } from "./cloud-home-settle.ts"; import { CLOUD_NOBODY_KEY, CLOUD_OUTSIDE_KEY } from "./cloud-sharing.ts"; import { createTeamSlackHost } from "./host/team-slack-host.ts"; import { createTeamSlackMessages } from "./team-slack.ts"; import { createTeamSlackRoutes } from "./routes/team-slack.ts";import { createCloudMoveRoutes } from "./cloud-move-http.ts";import { RESTART_EXIT_CODE } from "./restart.ts"; import { installCrashGuard, SERVER_ERROR_CAUSE } from "./crash-guard.ts"; import { markRequestArrival } from "./perf/loop-stalls.ts"; import { createThreadMaps, keepThreadEntry } from "./host/thread-maps.ts"; import { botLimitRefusal } from "./bot-limit.ts";-import { applyIncludedXMessage, holdIncludedServices, hostingCredential, researchCredential, trialCreditCredential, xCredential, xResearchStatus } from "./included-services.ts"; import { applyPhoneLinkMessage, phoneLinkPart } from "./phone-link.ts"; import { createResearchAvailability } from "./research.ts";+import { applyIncludedXMessage, holdIncludedServices, hostingCredential, researchCredential, trialCreditCredential, xCredential, xResearchStatus } from "./included-services.ts"; import { applyPhoneLinkMessage, phoneLinkPart } from "./phone-link.ts"; import { createLocalVmAvailability } from "./local-vm-availability.ts"; import { createResearchAvailability } from "./research.ts";import { CloudCreditProvider } from "./cloud-credit-provider.ts";import { createCreditMoves } from "./cloud-credit-moves.ts"; import { createRoutineHoldsHost } from "./host/routine-holds-host.ts"; import { tellTurnedBackOn } from "./host/routines-turned-back-on.ts";import { TRIAL_CREDIT_OWN_AI, TRIAL_KEY_HELD } from "./trial-credit.ts"; import { createHeldKeys } from "./cloud-held-keys.ts";@@ -1812,6 +1812,7 @@ const MAX_WORKSPACE_BOTS = 100;const phoneProxyPath = SPAWNED_PROXIES.phone;const researchAvailability = createResearchAvailability({ credential: () => researchCredential(cfg.treg?.key) }); researchAvailability.available();+const localVmAvailability = createLocalVmAvailability(() => containerRuntimeStatus());function agentsIntegration(botId: string,threadId: string,@@ -1824,7 +1825,7 @@ function agentsIntegration(const bot = store.bot(botId), speaking = botForThread(botId, threadId) ?? bot;// Only advertises the tools; the routes behind them refuse regardless.const host = { skillAuthoring: skillAuthoringEnabled(cfg), sharedComputers: botLending(), cloudHome: Boolean(CLOUD_HOME), team: Boolean(CLOUD_TEAM),- voiceNotes: tts.voiceReady(cfg, speaking?.voice) && speaking?.voiceNotes !== false, x: Boolean(researchCredential(cfg.treg?.key)), research: researchAvailability.available(), imageGeneration: imageGenerationReady(cfg), meetings: boat.boatConfigured(cfg), appHosting: hostingCredential() !== null };+ voiceNotes: tts.voiceReady(cfg, speaking?.voice) && speaking?.voiceNotes !== false, x: Boolean(researchCredential(cfg.treg?.key)), research: researchAvailability.available(), imageGeneration: imageGenerationReady(cfg), meetings: boat.boatConfigured(cfg), appHosting: hostingCredential() !== null, localVm: localVmAvailability.available() };return { ...agentsProxyLaunch(), env: agentsServerEnv({ threadId, bot: bot ?? { id: botId }, room: Boolean(store.groupByThread(threadId)), teamComputer: Boolean(bot && inheritedTeamComputer(bot)), botDriven: automated || botDrivenConversation(store.taskByThread(botId, threadId)), host },{ generation, depth, skillAuthoring, roomHandoffId, ...(hostFiles && !CLOUD_HOME && !HOSTED_WORKSPACE ? { deliversSavedFiles: true } : {}) },(turn) => mintInternalCapability({ botId, threadId, kind: "agents", createdBots: 0, openedThreads: 0, ...turn }), `http://127.0.0.1:${PORT}`) };diff --git a/server/local-vm-availability.test.ts b/server/local-vm-availability.test.tsnew file mode 100644index 0000000000..015178177c--- /dev/null+++ b/server/local-vm-availability.test.ts@@ -0,0 +1,38 @@+import { describe, expect, it } from "vitest";++import { createLocalVmAvailability } from "./local-vm-availability.ts";++const flush = () => new Promise((resolve) => setImmediate(resolve));++describe("whether this server can give a bot a Local VM", () => {+ it("says no when the host has no container runtime to run one", async () => {+ const availability = createLocalVmAvailability(async () => ({ available: [] }));+ expect(availability.available()).toBe(true);+ await flush();+ expect(availability.available()).toBe(false);+ });++ it("says no when the runtime is installed but its daemon is down", async () => {+ const availability = createLocalVmAvailability(async () => ({ available: ["docker"], daemonUp: false }));+ await flush();+ expect(availability.available()).toBe(false);+ });++ it("says yes when a runtime is installed and its daemon answers", async () => {+ const availability = createLocalVmAvailability(async () => ({ available: ["docker"], daemonUp: true }));+ await flush();+ expect(availability.available()).toBe(true);+ });++ it("keeps the tool listed when the probe fails", async () => {+ const availability = createLocalVmAvailability(async () => { throw new Error("no runtime"); });+ await flush();+ expect(availability.available()).toBe(true);+ });++ it("keeps the tool listed when the probe answers without a runtime list", async () => {+ const availability = createLocalVmAvailability(async () => ({ daemonUp: true }));+ await flush();+ expect(availability.available()).toBe(true);+ });+});diff --git a/server/local-vm-availability.ts b/server/local-vm-availability.tsnew file mode 100644index 0000000000..86f82b8640--- /dev/null+++ b/server/local-vm-availability.ts@@ -0,0 +1,18 @@+// Whether this server can give a bot a Local VM: a supported container runtime is installed on the host+// and its daemon answers. The answer is read once and kept, so the tools a conversation is listed do+// not change from turn to turn.+export interface LocalVmRuntimeStatus {+ available?: readonly string[];+ daemonUp?: boolean;+}++export function createLocalVmAvailability(probe: () => Promise<LocalVmRuntimeStatus>) {+ let usable = true;+ void probe()+ .then((status) => {+ const available = Array.isArray(status?.available) ? status.available : null;+ if (available) usable = available.length > 0 && status.daemonUp === true;+ })+ .catch(() => {});+ return { available: () => usable };+}