Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(computer): start Local VM and VPS bridge children without a console window
AdityaUmale3cf0f003a2fe
diff --git a/server/container-mcp.ts b/server/container-mcp.tsindex 7c6e9d2812..964690d920 100644--- a/server/container-mcp.ts+++ b/server/container-mcp.ts@@ -21,6 +21,7 @@ runMcpBridge({command: runtime,args: cuaExecArgs(["mcp", "--socket", socket], { container, interactive: true }),label: "Cua Driver",+ consoleChild: true,// No liveness watchdog: the runtime CLI talks to a local daemon and fails fast on its own....(controlUrl && controlToken ? { gate: { url: controlUrl, token: controlToken } } : {}),});diff --git a/server/mcp-bridge.spawn.test.ts b/server/mcp-bridge.spawn.test.tsnew file mode 100644index 0000000000..4c292f1cca--- /dev/null+++ b/server/mcp-bridge.spawn.test.ts@@ -0,0 +1,44 @@+import { EventEmitter } from "node:events";+import { PassThrough } from "node:stream";+import { afterEach, describe, expect, it, vi } from "vitest";++const spawned: Array<{ command: string; options: Record<string, unknown> }> = [];++vi.mock("node:child_process", async (importOriginal) => {+ const actual = await importOriginal<typeof import("node:child_process")>();+ return {+ ...actual,+ spawn: (command: string, _args: string[], options: Record<string, unknown>) => {+ spawned.push({ command, options });+ const child = Object.assign(new EventEmitter(), {+ stdin: new PassThrough(),+ stdout: new PassThrough(),+ stderr: new PassThrough(),+ kill: () => true,+ });+ queueMicrotask(() => child.emit("close", 0));+ return child;+ },+ };+});++const { runLivenessProbe, spawnBridgeChild } = await import("./mcp-bridge.ts");++afterEach(() => { spawned.length = 0; });++describe("bridge child processes", () => {+ it("starts a console child (docker, podman) without a terminal window on Windows", () => {+ spawnBridgeChild("docker", ["exec", "-i", "omb-vm"], { PATH: "" }, true);+ expect(spawned).toEqual([{ command: "docker", options: expect.objectContaining({ shell: false, windowsHide: true }) }]);+ });++ it("leaves other children (the local desktop driver) as they start today", () => {+ spawnBridgeChild("cua-driver", ["mcp"], { PATH: "" }, false);+ expect(spawned).toEqual([{ command: "cua-driver", options: expect.objectContaining({ windowsHide: false }) }]);+ });++ it("starts the liveness probe without a console window", async () => {+ await expect(runLivenessProbe({ command: "docker", args: ["exec", "omb-vm", "true"] }, 1_000, { PATH: "" })).resolves.toBe(true);+ expect(spawned).toEqual([{ command: "docker", options: expect.objectContaining({ shell: false, windowsHide: true }) }]);+ });+});diff --git a/server/mcp-bridge.ts b/server/mcp-bridge.tsindex ef360f94d0..9ad355f9a1 100644--- a/server/mcp-bridge.ts+++ b/server/mcp-bridge.ts@@ -1,4 +1,4 @@-import { spawn } from "node:child_process";+import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";import { StringDecoder } from "node:string_decoder";import { CONTROL_ACT_WITHIN_MS, CONTROL_UNCONFIRMED, CONTROL_WAITED, controlRefusal, createControlClient, type ControlState } from "./control-client.ts";@@ -20,6 +20,7 @@ export function runLivenessProbe(probe: BridgeLiveness, timeoutMs = PROBE_TIMEOUreturn new Promise((resolve) => {const child = spawn(probe.command, probe.args, {shell: false,+ windowsHide: true,env: env ?? { ...process.env, PATH: augmentedPath() },stdio: ["ignore", "ignore", "ignore"],});@@ -111,6 +112,8 @@ export interface BridgeOptions {label: string;/** docker's ssh connection helper takes no ConnectTimeout/ServerAlive options, so a dropped VPS wedges silently without this. */liveness?: BridgeLiveness;+ /** The child is a console program (docker, podman, ssh): start it hidden, or Windows opens a terminal window for it. */+ consoleChild?: boolean;/** `describe`: what a tools/call would open, passed to the gate so the person can be asked in plain words. */gate?: { url: string; token: string; describe?: (frame: unknown) => Record<string, string> };journal?: { url: string; token: string };@@ -326,21 +329,24 @@ export function createChildCalls(write: (line: string) => void, closedText = "Coconst RESPAWN_WAITS_MS = [0, 500, 1_500, 3_000];const RESPAWN_INITIALIZE_MS = 5_000;+export function spawnBridgeChild(+ command: string,+ args: string[],+ env: NodeJS.ProcessEnv,+ windowsHide: boolean,+): ChildProcessWithoutNullStreams {+ const proc = spawn(command, args, { shell: false, windowsHide, env, stdio: ["pipe", "pipe", "pipe"] });+ // docker may exit before it drains stdin; pipe() leaves this error unhandled.+ proc.stdin.on("error", () => {});+ proc.stderr.pipe(process.stderr, { end: false });+ return proc;+}+export function runMcpBridge(options: BridgeOptions): void {const env = options.env ?? { ...process.env, PATH: augmentedPath() };const { command, args } = resolveCliSpawn(options.command, options.args, env);const respawn = options.respawn;- const spawnChild = () => {- const proc = spawn(command, args, {- shell: false,- env,- stdio: ["pipe", "pipe", "pipe"],- });- // docker may exit before it drains stdin; pipe() leaves this error unhandled.- proc.stdin.on("error", () => {});- proc.stderr.pipe(process.stderr, { end: false });- return proc;- };+ const spawnChild = () => spawnBridgeChild(command, args, env, options.consoleChild === true);let child = spawnChild();const client = options.gatediff --git a/server/vps-container-mcp.ts b/server/vps-container-mcp.tsindex f3512bbf75..e69ba555b9 100644--- a/server/vps-container-mcp.ts+++ b/server/vps-container-mcp.ts@@ -31,6 +31,7 @@ runMcpBridge({args,env: { ...process.env, PATH: ssh.path },label: "VPS Cua Driver",+ consoleChild: true,// Probe the transport, not the driver: a busy desktop mid-tool-call must never look dead.liveness: { command: "docker", args: vpsDockerArgs(sshAlias, ["version", "--format", "{{.Server.Version}}"]) },...(controlUrl && controlToken ? { gate: { url: controlUrl, token: controlToken } } : {}),