Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Tell bots the status of every computer they could use
milind-soni4793a909e08c
diff --git a/server/lent-computers.test.ts b/server/lent-computers.test.tsindex eb033595b0..15b027186f 100644--- a/server/lent-computers.test.ts+++ b/server/lent-computers.test.ts@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";import { join } from "node:path";import { afterEach, describe, expect, it, vi } from "vitest";-import { awayNotice, deviceWord, LentComputers } from "./lent-computers.ts";+import { awayNotice, deviceWord, lentComputersLine, LentComputers } from "./lent-computers.ts";import { SharedComputers, sharedComputerRegistration } from "./shared-computers.ts";const dirs: string[] = [];@@ -40,6 +40,17 @@ describe("what a server remembers about computers lent to it", () => {expect(readFileSync(path, "utf8")).not.toMatch(/Plans|secret/u);});+ it("lists every computer's status for this turn's prompt, by name, and only when it knows them", () => {+ const at = Date.UTC(2026, 9, 7, 14, 2);+ expect(lentComputersLine([])).toBe("");+ expect(lentComputersLine([{ name: "ASH-PC", platform: "win32" }])).toBe("");+ expect(lentComputersLine([+ { name: "ASH-MBP", platform: "darwin", online: true, lent: true, lastSeenAt: at },+ { name: "evil\u202eNAME\nnext", platform: "win32", online: false, lent: true, lastSeenAt: at },+ { name: "OLD-BOX", platform: null, online: false, lent: false, lastSeenAt: at },+ ])).toBe(" Their computers right now: ASH-MBP (Mac): online; evil NAME next (PC): offline since 2026-10-07 14:02 UTC; OLD-BOX (computer): no longer lent.");+ });+it("says PC on Windows, Mac only on a Mac, and computer otherwise", () => {expect([deviceWord("win32"), deviceWord("darwin"), deviceWord("linux"), deviceWord(null)]).toEqual(["PC", "Mac", "computer", "computer"]);const at = Date.UTC(2026, 9, 7, 14, 2);@@ -52,6 +63,9 @@ describe("what a server remembers about computers lent to it", () => {expect(awayNotice([{ ...record, platform: "darwin", stoppedAt: at }], new Set()).say).toContain("choose Resume from OpenMausBot's icon in the menu bar on that Mac");expect(awayNotice([{ ...record, platform: "darwin" }], new Set()).say).toMatch(/^Their Mac ASH-PC is shared with the Cloud/u);expect(awayNotice([record], new Set([record.id]))).toEqual({});+ // One of two away: the bot is told about it, without the sentence meant for a person with nothing online.+ const other = { ...record, id: randomUUID(), name: "ASH-MBP", platform: "darwin" as const };+ expect(awayNotice([record, other], new Set([other.id]))).toEqual({ offline: [{ name: "ASH-PC", device: "PC", lastOnline: "2026-10-07 14:02 UTC", lent: true }] });for (const sentence of [awayNotice([record], new Set()).say!, awayNotice([{ ...record, stoppedAt: at }], new Set()).say!]) expect(sentence).not.toMatch(/this Mac|OMB Cloud|OpenMausBot Cloud/u);});});diff --git a/server/lent-computers.ts b/server/lent-computers.tsindex 82d1c475e7..18d4e81d3a 100644--- a/server/lent-computers.ts+++ b/server/lent-computers.ts@@ -125,14 +125,28 @@ export const lendScreenSteps = (device: "PC" | "Mac" | "computer") => device ===const dateText = (at: number) => new Date(at).toISOString().slice(0, 16).replace("T", " ") + " UTC";+/** Every computer the person lent, as this turn's prompt tells it: names are theirs and may hold anything, so controls go. */+export function lentComputersLine(known: ReadonlyArray<{ name: string; platform: LentPlatform | null; online?: boolean; lent?: boolean; lastSeenAt?: number }>): string {+ const statuses = known.flatMap((computer) => {+ if (computer.online === undefined) return [];+ // eslint-disable-next-line no-control-regex+ const name = computer.name.replace(/[\u0000-\u001f\u007f\u202a-\u202e\u2066-\u2069]/g, " ").slice(0, 80);+ const state = computer.online ? "online" : computer.lent === false ? "no longer lent" : `offline since ${dateText(computer.lastSeenAt ?? 0)}`;+ return [`${name} (${deviceWord(computer.platform)}): ${state}`];+ });+ return statuses.length ? ` Their computers right now: ${statuses.join("; ")}.` : "";+}+/*** What list_shared_computers adds for a bot when a computer it knows is not online: the computer by name and kind, since* when, and the one sentence to say. Nothing when every known computer is online.*/export function awayNotice(known: LentComputer[], online: ReadonlySet<string>, askTool: string | null = null): { offline?: Array<{ name: string; device: string; lastOnline: string; lent: boolean }>; say?: string } {const away = known.filter((computer) => !online.has(computer.id));- if (!away.length || known.some((computer) => online.has(computer.id))) return {};+ if (!away.length) return {};const offline = away.slice(0, 3).map((computer) => ({ name: computer.name, device: deviceWord(computer.platform), lastOnline: dateText(computer.lastSeenAt), lent: computer.stoppedAt === null }));+ // The sentence to say is for a person whose every computer is away: with one online, the bot uses that one.+ if (known.some((computer) => online.has(computer.id))) return { offline };const latest = away[0]!;const device = deviceWord(latest.platform);const ask = askTool ? ` If the request needs it, call ${askTool}: it asks them with a one-tap Turn on, and you carry on once it's on. Don't explain the fix in chat.` : null;diff --git a/server/system-prompt.test.ts b/server/system-prompt.test.tsindex 7921fcdecc..8950e53886 100644--- a/server/system-prompt.test.ts+++ b/server/system-prompt.test.ts@@ -375,6 +375,11 @@ describe("composioSystemPrompt", () => {});describe("cloudHomePrompt", () => {+ it("names every computer's status with the tools on, and says nothing about them without", () => {+ const known = [{ name: "ASH-MBP", platform: "darwin" as const, online: true, lent: true, lastSeenAt: 1 }, { name: "OFFICE-PC", platform: "win32" as const, online: false, lent: true, lastSeenAt: Date.UTC(2026, 9, 1, 8, 0) }];+ expect(cloudHomePrompt(true, [], known)).toContain("Their computers right now: ASH-MBP (Mac): online; OFFICE-PC (PC): offline since 2026-10-01 08:00 UTC.");+ expect(cloudHomePrompt(false, [], known)).not.toContain("Their computers right now");+ });it("says the bot runs in the cloud, offers what works there, and never asks for a place that cannot exist", () => {for (const tools of [true, false]) {const text = cloudHomePrompt(tools);diff --git a/server/system-prompt.ts b/server/system-prompt.tsindex 41b5b509c4..954e4afd19 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 { theirComputer } from "./lent-computers.ts";+import { lentComputersLine, 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";@@ -179,13 +179,13 @@ export const CLOUD_ENGINES_HERE = " The AIs bots run on (Claude, Codex, Cursor a/** `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 {+ lent: ReadonlyArray<{ name: string; platform: "darwin" | "win32" | "linux" | null; online?: boolean; lent?: boolean; lastSeenAt?: number }> = [], asks = false): string {const { theirs, device } = theirComputer(lent);const unavailable = asks? ` If it isn't online, or doesn't lend what you need (its apps and screen, its files, running commands), call ask_for_computer with what you want to do and why: it shows them one card with a one-tap Turn on, and you carry on once it's on. Don't explain the fix yourself, and never do it on their cloud computer or in the built-in browser instead unless they ask you to.`: ` If none is online, say so in one sentence: use its say field when it has one (it names the computer and when it was last online), otherwise ask them to open OpenMausBot on that ${device}, signed in to MausBot Cloud: it shares that ${device} with you by itself.`;return ` You run on ${CLOUD_HOME_PLACE}.` + (sharedComputerTools- ? ` If they ask for something on ${theirs}, check list_shared_computers: a computer they share with the Cloud is reachable through shared_computer, within the folders and apps it allows.${unavailable}${device === "computer" ? " Call it their computer: never assume it is a Mac." : ` It is a ${device}: call it that, never a Mac unless it is one.`}`+ ? ` If they ask for something on ${theirs}, check list_shared_computers: a computer they share with the Cloud is reachable through shared_computer, within the folders and apps it allows.${lentComputersLine(lent)}${unavailable}${device === "computer" ? " Call it their computer: never assume it is a Mac." : ` It is a ${device}: call it that, never a Mac unless it is one.`}`+ ` While that ${device} is away, each folder it lends that the Cloud keeps a copy of still works from that copy: list_shared_computers lists them under away_computers (copy null means a folder only on the ${device}), every read says how fresh the copy is, and a write to a folder lent with editing is saved here and reaches the ${device} when it's on (tell them so in a few words). A file or folder that isn't in the copy is only on the ${device}: say you'll get it when it's on.`: ` You cannot see or use ${theirs}, its screen or its files from here. If they ask for something on it, say so in one sentence.`)+ (asks ? " For work that doesn't need their own computer, use what works here:" : " Offer what works here:")