Skip to content

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

Cloud bots are told the person's lent computer is reached through shared_computer, whatever place is mounted

milind-soni23dd70fb37c7
diff --git a/server/cloud-lent-screen.e2e.test.ts b/server/cloud-lent-screen.e2e.test.ts
new file mode 100644
index 0000000000..28ae43d9b0
--- /dev/null
+++ b/server/cloud-lent-screen.e2e.test.ts
@@ -0,0 +1,204 @@
+// The real Cloud home server with a synthetic engine and a synthetic lent PC (Windows, apps and screen and Chrome lent,
+// no terminal). A conversation on Auto that an earlier turn pinned to the cloud computer: its turn is told the PC is
+// reached through shared_computer, never that everything on screen happens on the cloud computer, and the PC's apps and
+// screen answer it. A conversation the lending rules refuse is told why by list_shared_computers, never the PC's tools.
+import { randomBytes, randomUUID } from "node:crypto";
+import { spawn, type ChildProcess } from "node:child_process";
+import { createInterface } from "node:readline";
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { dirname, join } from "node:path";
+import { fileURLToPath, pathToFileURL } from "node:url";
+import { afterAll, beforeAll, expect, it } from "vitest";
+import { spawnWithSecrets } from "./cloud-home-start.ts";
+import { cloudPairingSignature } from "./cloud-home.ts";
+import { removeTempDir, waitForExit } from "./testing/cleanup.ts";
+import { markLeftBehind } from "./testing/cloud-left-behind.ts";
+import { hostTimeout } from "./testing/host-timeout.ts";
+import { freePortBlock } from "./testing/ports.ts";
+
+const SERVER_DIR = dirname(fileURLToPath(import.meta.url));
+const HOST = "omb-t-0123456789ab.fly.dev";
+const secret = randomBytes(32).toString("base64url");
+const PC = { id: randomUUID(), secret: randomBytes(32).toString("hex") };
+let home = "";
+let dataDir = "";
+let base = "";
+let child: ChildProcess;
+let log = "";
+let owner = "";
+let boot: () => Promise<void> = async () => {};
+let lending = true;
+const proxies: ChildProcess[] = [];
+const answered: string[] = [];
+
+async function api(method: string, path: string, options: { body?: unknown; token?: string; headers?: Record<string, string> } = {}) {
+ const response = await fetch(`${base}${path}`, {
+ method,
+ headers: {
+ host: HOST, "x-forwarded-for": "203.0.113.9", "x-forwarded-proto": "https", origin: `https://${HOST}`,
+ ...(options.token ? { authorization: `Bearer ${options.token}` } : {}),
+ ...(options.body === undefined ? {} : { "content-type": "application/json" }),
+ ...options.headers,
+ },
+ body: options.body === undefined ? undefined : JSON.stringify(options.body),
+ });
+ return { status: response.status, body: await response.json().catch(() => null) as any };
+}
+
+async function adminPairing(): Promise<string> {
+ const body = JSON.stringify({ label: "OpenMausBot app (Cloud)", ttlSeconds: 300 });
+ const timestamp = String(Math.floor(Date.now() / 1000)), nonce = randomBytes(16).toString("base64url");
+ const response = await fetch(`${base}/api/cloud/pairing`, { method: "POST", headers: {
+ host: HOST, "x-forwarded-for": "203.0.113.9", "x-forwarded-proto": "https", "content-type": "application/json",
+ "x-omb-cloud-timestamp": timestamp, "x-omb-cloud-nonce": nonce, "x-omb-cloud-signature": `v1=${cloudPairingSignature(secret, timestamp, nonce, body)}`,
+ }, body });
+ const granted = await response.json() as { code: string };
+ return (await api("POST", "/api/auth/pair", { body: { code: granted.code } })).body.token;
+}
+
+/** The person's Windows PC, lending its apps and screen and its Chrome but no terminal and no folder, as the desktop app
+ * registers it; it answers computer_tools with its own tool list, as cua-driver there would. */
+async function lendPc(): Promise<void> {
+ const environmentId = (await api("GET", "/.well-known/openmausbot/environment")).body.environmentId as string;
+ const headers = { "x-omb-computer-secret": PC.secret };
+ const connected = await api("POST", "/api/shared-computers/connect", { token: owner, headers, body: {
+ id: PC.id, name: "OFFICE-PC", environmentId, folders: [], terminal: false, computer: true, platform: "win32", chrome: true,
+ commandTimeouts: true, longCommands: true, fileEdits: true,
+ } });
+ expect(connected.status, JSON.stringify(connected.body)).toBe(200);
+ void (async () => {
+ while (lending) {
+ const polled = await api("POST", `/api/shared-computers/${PC.id}/poll`, { token: owner, headers, body: {} }).catch(() => null);
+ const job = polled?.body?.job as { id: string; operation: { action: string } } | null | undefined;
+ if (!job) { if (!polled || polled.status !== 200) await new Promise((resolve) => setTimeout(resolve, 200)); continue; }
+ answered.push(job.operation.action);
+ await api("POST", `/api/shared-computers/${PC.id}/result`, { token: owner, headers, body: { jobId: job.id,
+ result: { ok: true, value: { tools: [{ name: "launch_app" }, { name: "click" }, { name: "type_text" }, { name: "get_window_state" }] } } } });
+ }
+ })();
+}
+
+beforeAll(async () => {
+ home = mkdtempSync(join(tmpdir(), "omb-cloud-lent-screen-"));
+ dataDir = join(home, ".openmausbot");
+ mkdirSync(dataDir, { recursive: true });
+ const claude = join(home, "claude-cli.mjs");
+ writeFileSync(claude, `#!/usr/bin/env node
+if (process.argv[2] === "auth") { console.log(JSON.stringify({ loggedIn: true, email: "[email protected]" })); process.exit(0); }
+process.env.FAKE_CLAUDE_VERSION = "2.1.284";
+if (process.argv[2] !== "--version") { process.env.FAKE_CLAUDE_DUMP = ${JSON.stringify(join(home, "claude.json"))}; process.env.FAKE_CLAUDE_MODE = "hang"; process.env.FAKE_CLAUDE_RELEASE = ${JSON.stringify(join(home, "release"))}; }
+await import(${JSON.stringify(pathToFileURL(join(SERVER_DIR, "testing", "fake-claude-cli.ts")).href)});
+`, { mode: 0o755 });
+ writeFileSync(join(dataDir, "config.json"), JSON.stringify({ instances: {
+ ...Object.fromEntries(["codex", "cursor", "githubCopilot", "openaiCompat", "qwen", "hermes", "pi"].map((id) => [id, { driver: "not-a-real-driver" }])),
+ claude: { driver: "claudeAgent", displayName: "Claude", config: { cli: claude } },
+ } }));
+ const port = await freePortBlock([0, 1]);
+ base = `http://127.0.0.1:${port}`;
+ const offline = `data:text/javascript,${encodeURIComponent('const real = globalThis.fetch; globalThis.fetch = async (url, init) => String(url).startsWith("http://127.0.0.1:") ? real(url, init) : new Response("offline fixture", { status: 503 });')}`;
+ boot = async () => {
+ child = spawnWithSecrets(process.execPath, ["--import", offline, join(SERVER_DIR, "index.ts")], {
+ PATH: process.env.PATH, ...(process.env.SystemRoot ? { SystemRoot: process.env.SystemRoot } : {}),
+ HOME: home, USERPROFILE: home, OMB_DATA_DIR: dataDir, OMB_PORT: String(port), OMB_WEBHOOK_PORT: String(port + 1),
+ OMB_CLOUD_ROLE: "home", OMB_CLOUD_MACHINE_ID: "3f9c2a4e-8b1d-4c6e-9a7f-2d5e8c1b0a93", OMB_CLOUD_ADMIN_URL: "https://cloud.example.test",
+ OMB_PUBLIC_URL: `https://${HOST}`, OMB_CLOUD_BOAT_URL: "https://cloud.example.test/api/cloud/services/boat/api/box/v1",
+ OMB_CLOUD_SECRETS_FD: "3",
+ }, { OMB_CLOUD_BOOTSTRAP_SECRET: secret, OMB_CLOUD_BOAT_TOKEN: `box_omb_${randomBytes(32).toString("base64url")}` }, undefined, true);
+ for (const stream of [child.stdout, child.stderr]) stream?.on("data", (chunk) => { log += chunk; });
+ const deadline = Date.now() + 20_000;
+ for (;;) {
+ if (child.exitCode !== null) throw new Error(`the Cloud home exited:\n${log}`);
+ try { if ((await fetch(`${base}/api/health`)).ok) break; } catch {}
+ if (Date.now() > deadline) throw new Error(`the Cloud home did not start:\n${log}`);
+ await new Promise((resolve) => setTimeout(resolve, 100));
+ }
+ };
+ await boot();
+ owner = await adminPairing();
+}, hostTimeout(40_000));
+
+afterAll(async () => {
+ lending = false;
+ for (const proxy of proxies) proxy.kill();
+ if (child) await waitForExit(child, { signal: "SIGTERM" });
+ if (home) await removeTempDir(home);
+});
+
+const dump = () => join(home, "claude.json");
+type Turn = { systemPrompt?: string; mcpConfig: { mcpServers: { agents: { command: string; args: string[]; env: Record<string, string> } } } };
+
+async function ownerAsks(botId: string, threadId: string, text: string): Promise<Turn> {
+ rmSync(dump(), { force: true });
+ const sent = await api("POST", `/api/bots/${botId}/messages`, { token: owner, body: { text, threadId } });
+ expect(sent.status, JSON.stringify(sent.body)).toBe(202);
+ await expect.poll(() => existsSync(dump()), { timeout: hostTimeout(15_000) }).toBe(true);
+ return JSON.parse(readFileSync(dump(), "utf8")) as Turn;
+}
+
+async function agentTools(turn: Turn) {
+ const agents = turn.mcpConfig.mcpServers.agents;
+ const proxy = spawn(agents.command, agents.args, { env: { PATH: process.env.PATH, HOME: home, ...agents.env }, stdio: ["pipe", "pipe", "pipe"] });
+ proxies.push(proxy);
+ const replies = new Map<number, (value: any) => void>();
+ createInterface({ input: proxy.stdout! }).on("line", (line) => { const msg = JSON.parse(line); replies.get(msg.id)?.(msg.result ?? msg); replies.delete(msg.id); });
+ let next = 0;
+ const request = (method: string, params: unknown): Promise<any> => new Promise((resolve) => {
+ const id = ++next; replies.set(id, resolve);
+ proxy.stdin!.write(`${JSON.stringify({ jsonrpc: "2.0", id, method, params })}\n`);
+ });
+ await request("initialize", { protocolVersion: "2024-11-05" });
+ return (name: string, args: unknown = {}) => request("tools/call", { name, arguments: args }) as Promise<{ isError?: boolean; content: Array<{ text: string }> }>;
+}
+
+it("lets an Auto conversation pinned to the cloud computer use the person's lent PC, and says how", async () => {
+ const created = (await api("POST", "/api/bots", { token: owner, body: { name: "Office", modelSelection: { instanceId: "claude", model: "claude-sonnet-5" } } })).body.bot as { id: string; threadId: string };
+ const guestThread = (await api("POST", `/api/bots/${created.id}/tasks`, { token: owner, body: { title: "Guest's" } })).body.task.threadId as string;
+ // Stopped: an earlier Auto turn selected the cloud computer in this conversation (the pin a turn makes on its own), and
+ // a guest opened the other one before the Cloud was personal.
+ await waitForExit(child, { signal: "SIGTERM" });
+ const bots = JSON.parse(readFileSync(join(dataDir, "bots.json"), "utf8"));
+ const record = (bots.bots ?? bots).find((bot: any) => bot.id === created.id);
+ expect(record.computer).toBeUndefined();
+ const task = record.tasks.find((candidate: any) => candidate.threadId === created.threadId);
+ Object.assign(task, { surface: "cloud", surfaceSource: "auto" });
+ writeFileSync(join(dataDir, "bots.json"), JSON.stringify(bots), { mode: 0o600 });
+ markLeftBehind(dataDir, { threadIds: [guestThread] });
+ await boot();
+ await lendPc();
+
+ const turn = await ownerAsks(created.id, created.threadId, "Open Notepad on my PC.");
+ const prompt = turn.systemPrompt ?? "";
+ // The cloud computer is what this turn mounts, as the pin says…
+ expect(prompt).toContain("This conversation is pinned to the cloud computer");
+ expect(prompt).toContain("The screen tools mounted this turn work on the cloud computer, web pages included");
+ // …and the person's PC is still theirs to ask for, through shared_computer.
+ expect(prompt).not.toContain("Everything you do on screen happens on the cloud computer");
+ expect(prompt).not.toContain("the user's own computer cannot be reached from here");
+ expect(prompt).toContain("Their PC (OFFICE-PC) is reached only through shared_computer, never select_computer");
+ expect(prompt).toContain("whatever this conversation is pinned to");
+
+ const call = await agentTools(turn);
+ const listed = JSON.parse((await call("list_shared_computers")).content[0]!.text);
+ expect(listed.computers).toEqual([expect.objectContaining({ id: PC.id, name: "OFFICE-PC", device: "PC", computer: true, terminal: false, chrome: true })]);
+ expect(listed.unavailable).toBeUndefined();
+ const tools = await call("shared_computer", { computer_id: PC.id, action: "computer_tools" });
+ expect(tools.isError, JSON.stringify(tools)).not.toBe(true);
+ expect(tools.content[0]!.text).toContain("launch_app");
+ expect(answered).toEqual(["computer_tools"]);
+ writeFileSync(join(home, "release"), "");
+ await expect.poll(async () => (await api("GET", "/api/bots", { token: owner })).body.bots.find((bot: any) => bot.id === created.id)?.busy,
+ { timeout: hostTimeout(15_000) }).toBe(false);
+ rmSync(join(home, "release"), { force: true });
+
+ // A conversation a guest left behind: the same paragraph points to list_shared_computers, which says why it can't.
+ const guest = await ownerAsks(created.id, guestThread, "Open Notepad on my PC.");
+ expect(guest.systemPrompt).toContain("If list_shared_computers says this conversation can't use it");
+ const refused = await agentTools(guest);
+ const listing = JSON.parse((await refused("list_shared_computers")).content[0]!.text);
+ expect(listing.computers).toEqual([]);
+ expect(listing.say).toEqual(expect.any(String));
+ expect((await refused("shared_computer", { computer_id: PC.id, action: "computer_tools" })).isError).toBe(true);
+ expect(answered).toEqual(["computer_tools"]);
+ writeFileSync(join(home, "release"), "");
+}, hostTimeout(120_000));
diff --git a/server/index.ts b/server/index.ts
index 8d66da0e6f..f87ba8e1b4 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -3027,7 +3027,7 @@ function previewSystemPrompt(bot: BotRecord) {
{ id: "plan", label: "Surface", text: previewPlan.computer === undefined ? "" : surfacePrompt({
computer: previewPlan.computer && previewPlan.computer !== "off" && computerPromptKind ? previewPlan.computer : null,
browser: previewPlan.computer === undefined ? false : previewPlan.browser,
- }, { note: previewPlan.note, cloudHome: Boolean(CLOUD_HOME) }) },
+ }, { note: previewPlan.note, cloudHome: Boolean(CLOUD_HOME), ownComputer: CLOUD_HOME && agentsMounted && lendingEnabled() ? sharedComputers.known(CLOUD_HOME_LENDER) : undefined }) },
{ id: "cloud-home", label: "My Cloud", text: CLOUD_HOME ? cloudHomePrompt(agentsMounted && lendingEnabled(), syncedFolders(DATA_DIR), sharedComputers.known(CLOUD_HOME_LENDER), CLOUD_PERSONAL) + firstHourHooks.prompt(bot.id, bot.threadId) : "" },
{ id: "composio", label: "Connected apps", text: caps?.composioMcp && bot.composio !== false && composio.configured(cfg) ? composioSystemPrompt(bot.connectorTools) + describeConnectorScopes(bot.connectorScopes) : "" },
{ id: "highlevel", label: "HighLevel", text: caps?.highlevelMcp === true && highlevelHost.mounts(bot) ? highlevelHost.prompt(bot) : "" },
@@ -8482,7 +8482,7 @@ async function beginTurn(
{ id: "shell", label: "Long-running commands", text: worksInWorkspace ? longCommandsPrompt(computerPromptKind) : "" },
{ id: "computer", label: "Computer", text: computerPrompt(computerPromptKind) },
{ id: "team-computer", label: "Team computer", text: teamComputerPrompt(teamComputer) },
- { id: "plan", label: "Surface", text: surfacePrompt({ computer: mountedComputer, browser: Boolean(integrations.browser) }, { pinned: plan.pinned, note: plan.note + vpsUnavailableNote + vmUpdateNote + (computerSkipped && plan.computer !== "off" ? computerSkippedNote(redactSecretsInText(computerSkipped)) : ""), canSelect: computerSelectionTurns.has(threadId), cloudHome: Boolean(CLOUD_HOME), botOpened: plan.botOpened }) },
+ { id: "plan", label: "Surface", text: surfacePrompt({ computer: mountedComputer, browser: Boolean(integrations.browser) }, { pinned: plan.pinned, note: plan.note + vpsUnavailableNote + vmUpdateNote + (computerSkipped && plan.computer !== "off" ? computerSkippedNote(redactSecretsInText(computerSkipped)) : ""), canSelect: computerSelectionTurns.has(threadId), cloudHome: Boolean(CLOUD_HOME), botOpened: plan.botOpened, ownComputer: CLOUD_HOME && integrations.agents && lendingEnabled() ? sharedComputers.known(CLOUD_HOME_LENDER) : undefined }) },
{ id: "cloud-home", label: "My Cloud", text: CLOUD_HOME ? cloudHomePrompt(Boolean(integrations.agents) && lendingEnabled(), syncedFolders(DATA_DIR), sharedComputers.known(CLOUD_HOME_LENDER), CLOUD_PERSONAL) + firstHourHooks.prompt(bot.id, threadId) : "" },
{ id: "composio", label: "Connected apps", text: integrations.composio ? composioSystemPrompt(liveBot?.connectorTools ?? bot.connectorTools) + describeConnectorScopes((liveBot ?? bot).connectorScopes) : "" },
{ id: "mcp", label: "MCP servers", text: customMcpPrompt(Object.keys(integrations.custom ?? {}), mcpServersHost.off(bot)) }, { id: "to-connect", label: "Connections to make", text: cloudConnections.prompt(liveBot ?? bot) + teamConnections.prompt(threadId, dispatchClaimId, integrations) },
@@ -10303,7 +10303,7 @@ async function runClaimedGroupMemberTurn(
{ id: "mcp", label: "MCP servers", text: customMcpPrompt(Object.keys(integrations.custom ?? {}), mcpServersHost.off(bot)) + teamConnections.prompt(threadId, internalGeneration, integrations) },
{ id: "computer", label: "Computer", text: computerPrompt(roomComputerPromptKind) },
{ id: "team-computer", label: "Team computer", text: teamComputerPrompt(roomTeamComputer) },
- { id: "plan", label: "Surface", text: surfacePrompt({ computer: roomTeamComputer ? "cloud" : roomVmTarget ? "vm" : surfaceOfComputerKind(roomComputerKind), browser: Boolean(integrations.browser) }, { note: roomPlan.note, cloudHome: Boolean(CLOUD_HOME) }) },
+ { id: "plan", label: "Surface", text: surfacePrompt({ computer: roomTeamComputer ? "cloud" : roomVmTarget ? "vm" : surfaceOfComputerKind(roomComputerKind), browser: Boolean(integrations.browser) }, { note: roomPlan.note, cloudHome: Boolean(CLOUD_HOME), ownComputer: CLOUD_HOME && integrations.agents && lendingEnabled() ? sharedComputers.known(CLOUD_HOME_LENDER) : undefined }) },
{ id: "cloud-home", label: "My Cloud", text: CLOUD_HOME ? cloudHomePrompt(Boolean(integrations.agents) && lendingEnabled(), syncedFolders(DATA_DIR), sharedComputers.known(CLOUD_HOME_LENDER), CLOUD_PERSONAL) : "" },
{ id: "browser", label: "Browser", text: integrations.browser ? browserPromptFor(bot, Boolean(integrations.agents)) : "" },
{ id: "data", label: "Data", text: integrations.data ? BUILT_IN_DATA_SYSTEM_PROMPT : "" },
diff --git a/server/lent-computers.ts b/server/lent-computers.ts
index 602b37187a..34a7c48f43 100644
--- a/server/lent-computers.ts
+++ b/server/lent-computers.ts
@@ -26,6 +26,16 @@ export function deviceWord(platform: LentPlatform | null | undefined): "PC" | "M
return platform === "win32" ? "PC" : platform === "darwin" ? "Mac" : "computer";
}
+/** Their computer as they know it: "their PC (MILIND-PC)" on Windows, "their Mac (…)" only on a Mac, else "their own computer". */
+export function theirComputer(lent: ReadonlyArray<{ name: string; platform: LentPlatform | null }>): { theirs: string; device: "PC" | "Mac" | "computer" } {
+ const latest = lent[0];
+ if (!latest) return { theirs: "their own computer", device: "computer" };
+ const device = deviceWord(latest.platform);
+ // eslint-disable-next-line no-control-regex
+ const name = latest.name.replace(/[\u0000-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, " ").slice(0, 80);
+ return { theirs: `their ${device} (${name})`, device };
+}
+
export class LentComputers {
private readonly file: string;
private readonly now: () => number;
diff --git a/server/surface.test.ts b/server/surface.test.ts
index cebe16cd2d..92463ae2d4 100644
--- a/server/surface.test.ts
+++ b/server/surface.test.ts
@@ -312,9 +312,42 @@ describe("surfacePrompt", () => {
}
});
+ // A Cloud conversation on Auto, pinned to the cloud computer by an earlier turn, with the person's PC lent with its
+ // screen and Chrome: the paragraph said everything on screen happens on the cloud computer and that their own computer
+ // could not be reached, so the bot told them it couldn't use their PC.
+ it("tells a Cloud home's bots their lent computer is reached through shared_computer, whatever place is mounted", () => {
+ const lent = [{ name: "OFFICE-PC", platform: "win32" as const }];
+ for (const { mounted, opts } of shapes) {
+ const text = surfacePrompt(mounted, { ...opts, cloudHome: true, ownComputer: lent });
+ const where = JSON.stringify({ mounted, opts });
+ expect(text, where).not.toContain("cannot be reached from here");
+ expect(text, where).not.toContain("Everything you do on screen happens");
+ expect(text, where).not.toContain("You cannot open apps, click, or inspect a screen");
+ expect(text, where).toContain("Their PC (OFFICE-PC) is reached only through shared_computer, never select_computer: when they ask for something on it, check list_shared_computers, then use shared_computer on it (computer_tools, then computer_call, for its apps and screen), whatever this conversation is pinned to.");
+ expect(text, where).toContain("If list_shared_computers says this conversation can't use it, or that it doesn't lend what you need, say so in one sentence");
+ if (mounted.computer || mounted.browser) expect(text, where).toContain("and their PC (OFFICE-PC) is not one of these places");
+ }
+ const pinned = surfacePrompt({ computer: "cloud", browser: false }, { pinned: "cloud", canSelect: true, cloudHome: true, ownComputer: lent });
+ expect(pinned).toContain(" The screen tools mounted this turn work on the cloud computer, web pages included, through its own browser");
+ expect(pinned).toContain("say so in one sentence and don't do it on the cloud computer instead unless they ask.");
+ expect(surfacePrompt({ computer: null, browser: true }, { cloudHome: true, ownComputer: lent })).toContain("no desktop computer is mounted this turn");
+ // Never lent yet: still their own computer, reached the same way once it is.
+ expect(surfacePrompt({ computer: "cloud", browser: false }, { cloudHome: true, ownComputer: [] })).toContain("Their own computer is reached only through shared_computer");
+ });
+
+ it("still says the person's computer can't be reached when the turn has no shared-computer tools", () => {
+ for (const { mounted, opts } of shapes.filter(({ mounted }) => mounted.computer || mounted.browser)) {
+ const text = surfacePrompt(mounted, { ...opts, cloudHome: true });
+ expect(text).toContain("the user's own computer cannot be reached from here");
+ expect(text).not.toContain("shared_computer");
+ }
+ });
+
it("leaves every other server's paragraph exactly as it was", () => {
for (const { mounted, opts } of shapes) {
expect(surfacePrompt(mounted, { ...opts, cloudHome: false })).toBe(surfacePrompt(mounted, opts));
+ // Lending to a desktop server names no Cloud: its own computer is "this computer".
+ expect(surfacePrompt(mounted, { ...opts, ownComputer: [{ name: "OFFICE-PC", platform: "win32" }] })).toBe(surfacePrompt(mounted, opts));
}
expect(surfacePrompt({ computer: "cloud", browser: true }, { canSelect: true }))
.toContain("this computer is the user's host, Local VM is an isolated desktop, the cloud computer is remote");
diff --git a/server/surface.ts b/server/surface.ts
index 5ce007afd1..ef3ac25c0d 100644
--- a/server/surface.ts
+++ b/server/surface.ts
@@ -3,6 +3,7 @@ import { canWorkOnCloud, type CloudEngine } from "../shared/cloud-computer.ts";
import { canUseMcpServer } from "../shared/tool-scope.ts";
import { placeRowText, type PlaceRow, type PlaceSource } from "../shared/place-view.ts";
import { PLAIN_WORDS } from "./local-computer-guidance.ts";
+import { theirComputer, type LentPlatform } from "./lent-computers.ts";
export type { Surface, PlaceSource };
/** The bot's "Works on" setting; undefined = Auto. */
@@ -183,19 +184,38 @@ const REPORT_BACK = "tell the bot that gave you this job which place you need an
const SURFACE_AUTHORITY =
` For browser and computer tasks, use OpenMausBot's mounted browser/computer tools first: inspect the target, perform the action, and verify its result before claiming success. Discover deferred tools by their server/name when needed. Do not substitute the provider's own desktop, a shell-launched browser, or another automation path for the selected OpenMausBot surface. Ordinary code and file tasks may still use their normal tools. Announcing an action is not performing it. A request naming another place does not move these tools: this computer is the user's host, Local VM is an isolated desktop, the cloud computer is remote, and the built-in browser is a separate browser. If the requested place differs from the mounted one, ${ASK_TO_SWITCH}; never act on a different computer or describe a host window as a VM.`;
+/** A Cloud home without the shared-computer tools cannot reach the person's own computer at all. */
+const UNREACHABLE_OWN = "the user's own computer cannot be reached from here";
+
+/** With the shared-computer tools, what the wording above says of every screen holds only for this turn's places. */
+const OWN_COMPUTER_WORDING: ReadonlyArray<readonly [RegExp | string, string]> = [
+ [/ Everything you do on screen happens (on|in) /, " The screen tools mounted this turn work $1 "],
+ ["there is no desktop computer this turn", "no desktop computer is mounted this turn"],
+ ["You cannot open apps, click, or inspect a screen through OpenMausBot.", "No place's tools can open apps, click, or inspect a screen this turn."],
+];
+
/** A Cloud home has neither this computer nor a Local VM; each pair rewrites one phrase of the wording above. */
const CLOUD_HOME_WORDING: ReadonlyArray<readonly [string, string]> = [
["this computer is the user's host, Local VM is an isolated desktop, the cloud computer is remote, and the built-in browser is a separate browser",
- "the cloud computer is remote, the built-in browser is a separate browser, and the user's own computer cannot be reached from here"],
+ `the cloud computer is remote, the built-in browser is a separate browser, and ${UNREACHABLE_OWN}`],
[" or describe a host window as a VM", ""],
["select an available Local VM without asking", "select an available cloud computer without asking"],
[" Never silently replace an explicitly requested VM with the host desktop.", ""],
];
-/** Built from what was actually mounted, never from the setting, so the model is only told about tools it can call. */
+/** On a Cloud home the person's own computer is never one of the places above: shared_computer reaches it, whatever
+ * place the conversation has. Saying it can't be reached there turned a bot away from a PC lent with its screen. */
+function ownComputerSentence(lent: ReadonlyArray<{ name: string; platform: LentPlatform | null }>, place: string | null): string {
+ const { theirs } = theirComputer(lent);
+ return ` ${theirs[0]!.toUpperCase()}${theirs.slice(1)} is reached only through shared_computer, never select_computer: when they ask for something on it, check list_shared_computers, then use shared_computer on it (computer_tools, then computer_call, for its apps and screen), whatever this conversation is pinned to. If list_shared_computers says this conversation can't use it, or that it doesn't lend what you need, say so in one sentence${place ? ` and don't do it on ${place} instead unless they ask` : ""}.`;
+}
+
+/** Built from what was actually mounted, never from the setting, so the model is only told about tools it can call.
+ * `ownComputer`: on a Cloud home, the person's lent computers (newest first) when this turn has the shared-computer tools. */
export function surfacePrompt(
mounted: MountedSurfaces,
- opts: { pinned?: Surface | null; note?: string; canSelect?: boolean; cloudHome?: boolean; botOpened?: boolean } = {},
+ opts: { pinned?: Surface | null; note?: string; canSelect?: boolean; cloudHome?: boolean; botOpened?: boolean;
+ ownComputer?: ReadonlyArray<{ name: string; platform: LentPlatform | null }> } = {},
): string {
const reportBack = opts.botOpened && !opts.canSelect;
const computer = mounted.computer ? surfaceLabel(mounted.computer) : null;
@@ -229,5 +249,10 @@ export function surfacePrompt(
if (computer || mounted.browser) text += CONNECTED_APP_FIRST;
if (computer || mounted.browser) text += " For online research, use the selected OpenMausBot browser when a search service is unavailable. A failed tool proves only that this attempt failed, not that every browser is unavailable. Inspect the current page after navigation; report a sign-in page, redirect or error as such. A completed model turn is not proof that the user's task succeeded.";
if (opts.cloudHome) for (const [desktop, cloudHome] of CLOUD_HOME_WORDING) text = text.replace(desktop, cloudHome);
+ if (opts.cloudHome && opts.ownComputer) {
+ // What this turn's places reach, never every screen: their own computer is reachable too, through shared_computer.
+ for (const [nowhere, places] of OWN_COMPUTER_WORDING) text = text.replace(nowhere, places);
+ text = text.replace(UNREACHABLE_OWN, `${theirComputer(opts.ownComputer).theirs} is not one of these places`) + ownComputerSentence(opts.ownComputer, computer);
+ }
return text + (opts.note ?? "");
}
diff --git a/server/system-prompt.ts b/server/system-prompt.ts
index 7ed2cb8a14..d88cccdb23 100644
--- a/server/system-prompt.ts
+++ b/server/system-prompt.ts
@@ -1,6 +1,6 @@
// One builder for every turn's system prompt, so what a bot receives and the "what the model sees" preview are the same bytes.
import { soulSystemPrompt } from "./bot-folder.ts";
-import { deviceWord } from "./lent-computers.ts";
+import { theirComputer } from "./lent-computers.ts";
import { agentsToolBridged } from "./drivers/agents-bridge.ts";
import { teammateAvailabilityPrompt, type RosterMember } from "./peer-roster.ts";
import type { ConnectorToolGrant } from "../shared/wire.ts";
@@ -137,16 +137,6 @@ export const CLOUD_HOME_PLACE = "the user's My Cloud, their always-on OpenMausBo
// The Cloud prompt names the synced folders; index.ts reads the registry through here.
export { syncedFolders } from "./cloud-sync-store.ts";
-/** Their computer as they know it: "their PC MILIND-PC" on Windows, "their Mac" only on a Mac, else "their own computer". */
-function theirComputer(lent: ReadonlyArray<{ name: string; platform: "darwin" | "win32" | "linux" | null }>): { theirs: string; device: "PC" | "Mac" | "computer" } {
- const latest = lent[0];
- if (!latest) return { theirs: "their own computer", device: "computer" };
- const device = deviceWord(latest.platform);
- // eslint-disable-next-line no-control-regex
- const name = latest.name.replace(/[\u0000-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, " ").slice(0, 80);
- return { theirs: `their ${device} (${name})`, device };
-}
-
/** `asks`: the person's own Cloud, whose bots ask them to turn on what their computer doesn't give now (ask_for_computer). */
export function cloudHomePrompt(sharedComputerTools: boolean, synced: ReadonlyArray<{ computerName: string; pcPath: string; cloudPath: string }> = [],
lent: ReadonlyArray<{ name: string; platform: "darwin" | "win32" | "linux" | null }> = [], asks = false): string {