Skip to content

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

Merge main into feat/computer-exec-background: keep background exec and the file copy tools (13 tools)

milind-soni03c855b48f4d
diff --cc server/cloud-computer-tools.test.ts
index 576d8215f4,a3acf39c42..7dc522ddb6
--- a/server/cloud-computer-tools.test.ts
+++ b/server/cloud-computer-tools.test.ts
@@@ -47,10 -47,11 +47,11 @@@ const rpc = (request: unknown, gate: {
};
describe("cloud computer tools", () => {
- it("lists the same eleven tools for every engine", async () => {
- it("lists the same twelve tools for every engine", async () => {
++ it("lists the same thirteen tools for every engine", async () => {
const listed = await rpc({ method: "tools/list", params: {} }).done as { tools: Array<{ name: string }> };
expect(listed.tools.map(tool => tool.name)).toEqual([
- "screenshot", "get_screen_size", "click", "move", "drag", "type_text", "key_press", "scroll", "open_url", "exec",
+ "screenshot", "get_screen_size", "click", "move", "drag", "type_text", "key_press", "scroll", "open_url", "exec", "exec_status",
+ "copy_from_computer", "copy_to_computer",
]);
expect(calls).toEqual([]);
});
diff --cc server/cloud-computer-tools.ts
index 93a2a9508b,f944f04539..2dddd6060e
--- a/server/cloud-computer-tools.ts
+++ b/server/cloud-computer-tools.ts
@@@ -2,12 -2,10 +2,13 @@@
import type { ValidateFunction } from "ajv";
import { isolatedRemoteCommand, runCommand, screenshotBoat } from "./boat.ts";
import { isRedditAddress, REDDIT_REFUSAL } from "./browser/egress/reddit.ts";
+import {
+ backgroundStatus, commandLateText, EXEC_LATE, PROCESS_ID_PATTERN, startInBackground, STATUS_WAIT_MAX_SECONDS, STDERR_TAIL_CHARS, STDOUT_TAIL_CHARS,
+} from "./cloud-computer-background.ts";
+ import { copyFromComputer, copyToComputer } from "./cloud-computer-files.ts";
import type { AppConfig } from "./config.ts";
import { controlRefusal, type ControlState } from "./control-client.ts";
- import { HARNESS_CALL_BUDGET_MS } from "./harness-budget.ts";
+ import { COMPUTER_COPY_BUDGET_MS, HARNESS_CALL_BUDGET_MS } from "./harness-budget.ts";
import { compileToolSchema } from "./mcp-schema-validator.ts";
const coordinate = { type: "integer", minimum: 0, maximum: 32767 };
@@@ -23,14 -21,15 +24,22 @@@ export const CLOUD_COMPUTER_TOOLS =
tool("key_press", "Press an X11 key or shortcut.", { key: { type: "string", pattern: "^[A-Za-z0-9_+]+$", minLength: 1, maxLength: 100 } }, ["key"]),
tool("scroll", "Scroll at a point on the cloud desktop.", { x: coordinate, y: coordinate, direction: { type: "string", enum: ["up", "down", "left", "right"] }, amount: { type: "integer", minimum: 1, maximum: 30 } }, ["x", "y", "direction"]),
tool("open_url", "Request opening an HTTP or HTTPS URL in the cloud desktop browser; inspect the screen to confirm it loaded.", { url: { type: "string", pattern: "^https?://", maxLength: 2000 } }, ["url"]),
- tool("exec", "Run a shell command on the assigned cloud computer.", { command: { type: "string", minLength: 1, maxLength: 4000 } }, ["command"]),
+ tool("exec", "Run a shell command on the assigned cloud computer and wait for its result. For a command that may run long (downloads, installs, builds, data jobs), set background: true: it starts the command and answers at once with a process_id to follow with exec_status, and the computer stays on for it for up to two hours.", {
+ command: { type: "string", minLength: 1, maxLength: 4000 },
+ background: { type: "boolean", description: "Start the command and answer at once with a process_id, instead of waiting for it to finish." },
+ }, ["command"]),
+ tool("exec_status", `Check a command started with exec and background: true: running or finished, its exit code, and the end of its stdout and stderr (the last ${STDOUT_TAIL_CHARS.toLocaleString("en-US")} and ${STDERR_TAIL_CHARS.toLocaleString("en-US")} characters).`, {
+ process_id: { type: "string", pattern: PROCESS_ID_PATTERN },
+ wait_seconds: { type: "integer", minimum: 0, maximum: STATUS_WAIT_MAX_SECONDS, description: "Wait up to this many seconds for the command to finish before answering." },
+ }, ["process_id"]),
+ tool("copy_from_computer", "Copy one file of up to 2 GiB from the cloud computer into your working folder, for example to load it with data_load or use it in a page. A file already there is replaced.", {
+ path: { type: "string", minLength: 1, maxLength: 4096, description: "The file on the cloud computer, under /home/user or /tmp." },
+ to: { type: "string", minLength: 1, maxLength: 1000, description: "Where it goes, relative to your working folder. Default: the file's own name." },
+ }, ["path"]),
+ tool("copy_to_computer", "Copy one file of up to 2 GiB from your working folder to the cloud computer. A file already there is replaced.", {
+ from: { type: "string", minLength: 1, maxLength: 1000, description: "The file, relative to your working folder." },
+ path: { type: "string", minLength: 1, maxLength: 4096, description: "Where it goes on the cloud computer, under /home/user or /tmp." },
+ }, ["from", "path"]),
];
/** A call the gate let through while no Boat had landed for the turn. */
export const CLOUD_COMPUTER_NOT_READY = "The cloud computer is not ready. This call was not performed. Take a fresh screenshot in a moment.";
@@@ -131,10 -144,10 +156,10 @@@ export async function cloudComputerRpc
const late = AbortSignal.timeout(Math.max(1, deadline - Date.now()));
let result: CloudComputerResult;
try {
- result = await runCloudComputerTool(deps.cfg, boxId, params.name as string, args as Record<string, unknown>, AbortSignal.any([deps.signal, late]));
+ result = await runCloudComputerTool(deps.cfg, boxId, params.name as string, args as Record<string, unknown>, AbortSignal.any([deps.signal, late]), deps.folder?.());
} catch (error) {
if (!late.aborted || deps.signal.aborted) throw error;
- return { isError: true, content: [{ type: "text", text: commandLateText(params.name, args) ?? CLOUD_COMPUTER_LATE }] };
- return { isError: true, content: [{ type: "text", text: copy ? CLOUD_COMPUTER_COPY_LATE : CLOUD_COMPUTER_LATE }] };
++ return { isError: true, content: [{ type: "text", text: commandLateText(params.name, args) ?? (copy ? CLOUD_COMPUTER_COPY_LATE : CLOUD_COMPUTER_LATE) }] };
}
deps.assertActive();
return result;
diff --cc server/hosted-desktop.e2e.test.ts
index a9e0fd50ce,52adb666e6..79f8d75e37
--- a/server/hosted-desktop.e2e.test.ts
+++ b/server/hosted-desktop.e2e.test.ts
@@@ -139,7 -139,7 +139,7 @@@ it("keeps the bot's own engine on the c
const client = mcpClient(computer);
try {
expect((await client.request("initialize", { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: { name: "fixture", version: "1" } })).result.serverInfo.name).toBe("openmausbot-computer");
- expect((await client.request("tools/list")).result.tools).toHaveLength(11);
- expect((await client.request("tools/list")).result.tools).toHaveLength(12);
++ expect((await client.request("tools/list")).result.tools).toHaveLength(13);
const shot = await client.request("tools/call", { name: "screenshot", arguments: {} });
expect(shot.result.content[0]).toMatchObject({ type: "image", mimeType: "image/jpeg" });
const exec = await client.request("tools/call", { name: "exec", arguments: { command: "printf hosted-desktop" } });