Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(surface): a self-hosted server's bots reach a lent computer through shared_computer
AdityaUmale669d48b8d392
diff --git a/server/index.ts b/server/index.tsindex 2785c558d7..124222eabc 100644--- a/server/index.ts+++ b/server/index.ts@@ -887,7 +887,7 @@ function sharedComputerPrincipal(capability: Pick<InternalCapability, "botId" |if (CLOUD_HOME) return cloudLendingRefusal(capability) === null ? CLOUD_HOME_LENDER : null;return lendingPerson(provenRequestPerson(directRequestOwners.get(capability.threadId), capability.generation,(messageId) => linePersonKey(store.messagesFor(capability.threadId).find((message) => message.id === messageId))), ownHome.ownServer(), () => sessions.list());-}+} /** On a self-hosted server, the computers lent to it by the person this turn provably acts for. */ function lentToServer(agents: unknown, turn: Pick<InternalCapability, "botId" | "threadId" | "generation">) { return CLOUD_HOME || CLOUD_TEAM || DESKTOP_MANAGED || !agents || !botLending() ? undefined : sharedComputers.known(sharedComputerPrincipal(turn)); }/** The only conversations that may feed a bot's memory, daily log, recall or brief; dropped whenever a session is revoked. */const ownerOnlyCache = new Map<string, { length: number; last?: string; owner: boolean }>();@@ -8276,7 +8276,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)) : "") + (computerSelectionTurns.get(threadId)?.handoff && !integrations.browser ? HANDOFF_BROWSER_NOTE : ""), canSelect: computerSelectionTurns.has(threadId) && !computerSelectionTurns.get(threadId)?.handoff, selectionRules: !selectionRulesStable, cloudHome: Boolean(CLOUD_HOME), botOpened: plan.botOpened, ownComputer: CLOUD_HOME && integrations.agents && lendingEnabled() ? sharedComputers.known(CLOUD_HOME_LENDER) : undefined, thisComputer: !CLOUD_HOME && bot.computer !== "off" && !inheritedTeamComputer(bot) && shouldMountLocalComputer({ requested: "local", providerSupportsLocal: instance.adapter.capabilities.localComputerMcp === true }) ? { bot: bot.name, botId: bot.id, platform: process.platform } : undefined }) }, { id: "computer-selection", label: "Choosing a computer", text: selectionRulesStable ? computerSelectionPrompt({ cloudHome: Boolean(CLOUD_HOME) }) : "" },+ { 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)) : "") + (computerSelectionTurns.get(threadId)?.handoff && !integrations.browser ? HANDOFF_BROWSER_NOTE : ""), canSelect: computerSelectionTurns.has(threadId) && !computerSelectionTurns.get(threadId)?.handoff, selectionRules: !selectionRulesStable, cloudHome: Boolean(CLOUD_HOME), botOpened: plan.botOpened, ownComputer: CLOUD_HOME && integrations.agents && lendingEnabled() ? sharedComputers.known(CLOUD_HOME_LENDER) : undefined, lentToServer: lentToServer(integrations.agents, { botId: bot.id, threadId, generation: dispatchClaimId }), thisComputer: !CLOUD_HOME && bot.computer !== "off" && !inheritedTeamComputer(bot) && shouldMountLocalComputer({ requested: "local", providerSupportsLocal: instance.adapter.capabilities.localComputerMcp === true }) ? { bot: bot.name, botId: bot.id, platform: process.platform } : undefined }) }, { id: "computer-selection", label: "Choosing a computer", text: selectionRulesStable ? computerSelectionPrompt({ cloudHome: Boolean(CLOUD_HOME) }) : "" },{ 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) : "" }, phoneLinkPart(),{ 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, lentMcp.lines(liveBot ?? bot, { botId: bot.id, threadId, generation: dispatchClaimId })) + teamConnections.prompt(threadId, dispatchClaimId, integrations) },@@ -10057,7 +10057,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), ownComputer: CLOUD_HOME && integrations.agents && lendingEnabled() ? sharedComputers.known(CLOUD_HOME_LENDER) : undefined }) },+ { 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, lentToServer: lentToServer(integrations.agents, { botId: bot.id, threadId, generation: internalGeneration }) }) },{ id: "cloud-home", label: "My Cloud", text: CLOUD_HOME ? cloudHomePrompt(Boolean(integrations.agents) && lendingEnabled(), syncedFolders(DATA_DIR), sharedComputers.known(CLOUD_HOME_LENDER), CLOUD_PERSONAL) : "" }, phoneLinkPart(),{ id: "browser", label: "Browser", text: integrations.browser ? browserPromptFor(bot, Boolean(integrations.agents)) : "" },{ id: "data", label: "Data", text: integrations.data ? dataPrompt(readyBot.id, threadId, `${roomContext}\n${latestUser?.text ?? ""}`) : "" },diff --git a/server/surface.test.ts b/server/surface.test.tsindex 01890c3394..2a57425cfe 100644--- a/server/surface.test.ts+++ b/server/surface.test.ts@@ -426,6 +426,21 @@ describe("surfacePrompt", () => {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");});++ // A self-hosted server with the person's Mac lent and a Local VM mounted: "open Terminal on my Mac" ran on the Local+ // VM, since only a Cloud home's paragraph said a lent computer is reached through shared_computer.+ it("tells a self-hosted server's bots a computer lent to it is reached through shared_computer", () => {+ const lent = [{ name: "Studio", platform: "darwin" as const }];+ const vm = surfacePrompt({ computer: "vm", browser: false }, { canSelect: true, lentToServer: lent });+ expect(vm).toContain("Their Mac (Studio) 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");+ expect(vm).toContain("say so in one sentence and don't do it on the Local VM instead unless they ask.");+ for (const { mounted, opts } of shapes) {+ expect(surfacePrompt(mounted, { ...opts, lentToServer: lent })).toContain("Their Mac (Studio) is reached only through shared_computer");+ // Nothing lent, or a Cloud home (which says it from ownComputer): no change.+ expect(surfacePrompt(mounted, { ...opts, lentToServer: [] })).toBe(surfacePrompt(mounted, opts));+ expect(surfacePrompt(mounted, { ...opts, cloudHome: true, lentToServer: lent })).toBe(surfacePrompt(mounted, { ...opts, cloudHome: true }));+ }+ });});describe("surface parsing", () => {diff --git a/server/surface.ts b/server/surface.tsindex 99f11fe1ac..5da857c59b 100644--- a/server/surface.ts+++ b/server/surface.ts@@ -290,11 +290,13 @@ export function computerSelectionPrompt(opts: { cloudHome?: boolean } = {}): str}/** 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. */+ * `ownComputer`: on a Cloud home, the person's lent computers (newest first) when this turn has the shared-computer tools.+ * `lentToServer`: the same on any other server, for a person who lends it a computer. */export function surfacePrompt(mounted: MountedSurfaces,opts: { pinned?: Surface | null; note?: string; canSelect?: boolean; selectionRules?: boolean; cloudHome?: boolean; botOpened?: boolean;ownComputer?: ReadonlyArray<{ name: string; platform: LentPlatform | null }>;+ lentToServer?: ReadonlyArray<{ name: string; platform: LentPlatform | null }>;/** This computer can be picked for this bot here: its name, and the platform this server runs on. */thisComputer?: { bot: string; botId?: string; platform: NodeJS.Platform } } = {},): string {@@ -336,6 +338,7 @@ export function surfacePrompt(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);}+ if (!opts.cloudHome && opts.lentToServer?.length) text += ownComputerSentence(opts.lentToServer, computer);if (opts.thisComputer && !opts.cloudHome && !reportBack && mounted.computer !== "local") {text += ownFilesSentence(opts.thisComputer, mounted.computer, Boolean(opts.canSelect));}