Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Work from outside keeps to the same rule in what landed since
milind-soni2af7d9fcca58
diff --git a/docs/team-cloud.md b/docs/team-cloud.mdindex 5a59499da9..ed49ea056e 100644--- a/docs/team-cloud.md+++ b/docs/team-cloud.md@@ -131,7 +131,7 @@ language new bots start in); a value that isn't a locale is ignored, never refusWhat came in from outside (a webhook, an app's event) is confined, and the conversation it reached stays that way for good: a run or a hand-off ends, its words stay in the thread. The record is on the conversation (`outside`, `server/host/outside-lineage.ts`), and every turn is judged from it, at any level and after a restart.- **What it starts stays outside.** A thread it hands work to, a one-way notice still queued when the run ends, a retry, a wake and a routine it makes or changes all run confined. A routine it made runs without full access until someone opens it and saves it once. An event's own results chat counts too.-- **It reaches nothing else.** A confined turn can't open a thread, hand work to, post to or retry into a conversation or room that isn't already outside, can't answer a question in a person's work or be folded into a turn running there, and can't change, start, pause, resume or delete a person's routine. It hears why in plain words and finishes where it is. Of the server's own routes it reaches only those `server/host/outside-fence.ts` lists; anything else is refused, whether or not its engine pre-allows the tool.+- **It reaches nothing else.** A confined turn can't open a thread, hand work to, post to or retry into a conversation or room that isn't already outside, can't answer a question in a person's work or be folded into a turn running there, and can't change, start, pause, resume or delete a person's routine. A skill its words name stays plain text, and a page it shows keeps its frame. It hears why in plain words and finishes where it is. Of the server's own routes it reaches only those `server/host/outside-fence.ts` lists; anything else is refused, whether or not its engine pre-allows the tool.- **What it writes for later turns waits on a card.** A room's bulletin and a bot's memory load into later turns as instructions, so an admin sees a card and nothing is saved until they say yes (`server/host/outside-writes.ts`). A memory log line and a preference are refused, and nothing such a conversation says reaches memory or the daily log on its own.- **Its problems reach a person.** A confined run that fails or needs someone notifies a person; it starts no turn on a Chief at the Chief's own level. None of what it says lands in a person's inbox thread, by naming them or as a copy of its question or report: the person gets the notification and opens the conversation.- **A person's own line there runs confined too.** The engine reads the outside words as context, whoever typed last, so the bot works without its shell and says so once. A new conversation with the same bot runs at the bot's own level; it doesn't read that conversation on its own (recall and the recent-work brief leave it out), and a person can paste what they want into it.diff --git a/server/host-lazy-claim.e2e.test.ts b/server/host-lazy-claim.e2e.test.tsindex 0da08a35b9..e89d1600c2 100644--- a/server/host-lazy-claim.e2e.test.ts+++ b/server/host-lazy-claim.e2e.test.ts@@ -315,6 +315,25 @@ describe("lazy host claim and pin on use (issue #1650)", () => {await idle(bot.id, task.threadId);}, 60_000);+ itAutoHost("still asks at Full access when the work came in from outside: a webhook's words don't carry the person's grant", async () => {+ await start();+ const { bot } = await apiOk("POST", "/api/bots", { name: "Host Webhook Bot" });+ expect(bot.approvalMode ?? "full").toBe("full");+ const hook = await apiOk("POST", "/api/webhooks", { name: "Host hook", prompt: "Handle the event.", botId: bot.id });+ resetTurn();+ const delivered = await fetch(`http://127.0.0.1:${Number(new URL(base).port) + 1}/hooks/${hook.webhook.endpointId}/${encodeURIComponent(hook.credential.secret)}`, {+ method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ text: "Look at my calendar." }) });+ expect(delivered.status).toBe(202);+ const computer = mountedComputer(await dumpFor(bot.id));+ const client = createControlClient({ url: computer.env.OMB_CONTROL_URL, token: computer.env.OMB_CONTROL_TOKEN });+ const thread = (await apiOk("GET", "/api/routines")).runs.find((run: any) => run.webhookId === hook.webhook.id).threadId as string;+ expect(await withAnswer(base, thread, client.state(true, { app: "Chrome", site: "calendar.google.com" }))).toEqual({ held: false, helpOpen: false });+ const cards = (await apiOk("GET", `/api/threads/${thread}/messages?limit=200`)).messages.filter((message: any) => message.card?.tool === "use_your_computer");+ expect(cards.map((message: any) => message.card.answered)).toEqual(["allow"]);+ writeFileSync(finishFile, "finish");+ await idle(bot.id, thread);+ }, 60_000);+itAutoHost("asks once before the first screen call below Full access, in plain words naming the app and the site", async () => {await start();const { bot } = await apiOk("POST", "/api/bots", { name: "Host Asking Bot", settings: { approvalMode: ASKS } });diff --git a/server/index.ts b/server/index.tsindex b21080cb75..ed66b76228 100644--- a/server/index.ts+++ b/server/index.ts@@ -3148,6 +3148,8 @@ function peerReviewRequired(bot: BotRecord, threadId: string): boolean {const delegatedLevel = createDelegatedLevel({ store, node: id => coordinator.node(id), sourceLevel: sourceApprovalMode, turnLevel: approvalModeForTurn,driverKind: bot => registry.cliTarget(bot.modelSelection.instanceId)?.driverKind, guestDriven: cloudGuestDriven, handsNoLevel: outsideLineage.handsNoLevel });const liveApprovalMode = createLiveApprovalMode({ store, turnLevel: approvalModeForTurn });+/** Full access is the person's grant to use their screen without asking; words from outside never carry it. */+const asksBeforeYourComputer = (bot: BotRecord, threadId: string, peerInitiated: boolean) => liveApprovalMode(bot, threadId, peerInitiated) !== "full" || outsideLineage.handsNoLevel(threadId);function roomTurnApprovalMode(bot: BotRecord, threadId: string, orchestration?: GroupTurnOrchestration): ApprovalMode {const handoff = orchestration?.roomHandoffId ? coordinator.node(orchestration.roomHandoffId) : undefined;@@ -7945,9 +7947,8 @@ async function beginTurn(createHash("sha256").update(JSON.stringify([...persistentConfig, soul])).digest("hex").slice(0, 16);const plannedConfig = sessionConfig(bot.soul);const skillAuthoring = skillAuthoringEnabled(cfg) && agentsMounted;- const skillCommandText = supportsWorkspaceFiles(instance.driverKind)- ? skillsHost.expandSkillCommand(bot, threadId, providerText, instance)- : providerText;+ const namesSkills = !commsDepth && !opts?.coordination && !opts?.peerAsk && !userMessage.peerAsk && !guestConfined && !outsideLineage.handsNoLevel(threadId);+ const skillCommandText = namesSkills && supportsWorkspaceFiles(instance.driverKind) ? skillsHost.expandSkillCommand(bot, threadId, providerText, instance) : providerText;const setupText = agentsMounted ? expandSetupTurnText(skillCommandText) : skillCommandText;const userTurnText = (opts?.app?.context ?? "") + (opts?.cardContinuation ? "" : routineRunNote(threadId, opts?.automationSource)) + labelledLine(personLine && !opts?.excludeMessageIds ? userMessage : {}, withReactionNotes(promptWithReply(skillAuthoring ? expandLearnTurnText(setupText) : setupText,@@ -8266,7 +8267,7 @@ async function beginTurn(if (wants === "vm") {if (await attachLocalVm(true)) computerKind = "vm";} else if (wants === "local") {- integrations.localComputer = await mountHostComputer(resourceOwner, bot.id, mountsLocalComputer, surfaceLazyClaimRejection("this computer"), () => placeSource === "auto-pin" && liveApprovalMode(bot, threadId, commsDepth > 0) !== "full", savedSteps.journals(directRequestOwners.get(threadId)));+ integrations.localComputer = await mountHostComputer(resourceOwner, bot.id, mountsLocalComputer, surfaceLazyClaimRejection("this computer"), () => placeSource === "auto-pin" && asksBeforeYourComputer(bot, threadId, commsDepth > 0), savedSteps.journals(directRequestOwners.get(threadId)));computerKind = "local";}@@ -8344,7 +8345,7 @@ async function beginTurn(label: "this computer",onRejected: surfaceLazyClaimRejection("this computer"),claim: async (call) => {- await claimWithYourComputerConsent(() => liveApprovalMode(bot, threadId, commsDepth > 0) !== "full", () => askToUseYourComputer(approvalBus, bot, resourceOwner, call), () => bindTurnComputer(resourceOwner, "computer:host", true));+ await claimWithYourComputerConsent(() => asksBeforeYourComputer(bot, threadId, commsDepth > 0), () => askToUseYourComputer(approvalBus, bot, resourceOwner, call), () => bindTurnComputer(resourceOwner, "computer:host", true));pinAutoSurface("local"); recordTurnPlace(bot.id, threadId, "local");},});@@ -13213,7 +13214,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {store,bot: internalSender, apps: chatApps, folders: async () => ({ roots: messageFileRootsForThread(internalSender.id, internalCapability.threadId).filter((root) => root !== ATTACHMENTS_DIR), vmWorkspace: (await attachmentVmForTurn(internalCapability))?.workspaceDir ?? null }),threadId: internalCapability.threadId,- input: body, authored: (id) => handoffs.authored(internalCapability.threadId, internalCapability.generation, id),+ input: body?.frameless && cloudGuestDriven(internalCapability.threadId) ? { ...body, frameless: false } : body, authored: (id) => handoffs.authored(internalCapability.threadId, internalCapability.generation, id),});return result.ok? json(res, 201, { messageId: result.messageId, ...("masked" in result && result.masked ? { masked: true } : {}) })diff --git a/server/outside-lineage.e2e.test.ts b/server/outside-lineage.e2e.test.tsindex 1e15126e48..cbd4265c8e 100644--- a/server/outside-lineage.e2e.test.ts+++ b/server/outside-lineage.e2e.test.ts@@ -31,6 +31,7 @@ async function until<V>(what: string, fn: () => Promise<V> | V, ms = hostTimeoutconst said = (marker: string, where: "prompt" | "systemPrompt" = "prompt") => { const turn = read(); return turn && JSON.stringify(turn[where] ?? "").includes(marker) ? turn : null; };const turnWith = (marker: string, where: "prompt" | "systemPrompt" = "prompt") => until(`a turn with ${marker}`, () => said(marker, where));const confined = (turn: { argv: string[] }) => turn.argv.includes("--restricted");+const skillNamed = (name: string) => ({ name, description: "Write the digest.", source: "local:test", enabled: true, text: `---\nname: ${name}\ndescription: Write the digest.\n---\n\nWrite the digest.\n` });const atFull = (turn: { argv: string[] }) => turn.argv[turn.argv.indexOf("--permission-mode") + 1] === "bypassPermissions";let fx: CloudSendFixture, team: CloudTeamFixture, ada: string;@@ -335,6 +336,61 @@ describe("a Team Cloud", () => {rmSync(notes, { force: true });}, hostTimeout(120_000));+ it("runs no skill named in outside words or a bot's message, where a person's own line runs it", async () => {+ const RAN = "The user ran your weekly-digest skill";+ const scout = await newBot("Skill scout");+ const mate = await newBot("Skill mate");+ for (const bot of [scout, mate]) expect((await team.as(ada, "POST", `/api/bots/${bot.id}/skill-template`, skillNamed("weekly-digest"))).status).toBe(201);+ const { turn } = await webhookTurn(scout.id, "Skill hook", "marker-skill please run /weekly-digest now");+ expect(JSON.stringify(turn.prompt)).not.toContain(RAN);+ await finish(scout.id);+ const person = (await team.as(ada, "POST", `/api/bots/${scout.id}/tasks`, { title: "Mine" })).body.task.threadId as string;+ expect((await team.as(ada, "POST", `/api/bots/${scout.id}/messages`, { text: "person-skill please run /weekly-digest now", threadId: person })).status).toBe(202);+ expect(JSON.stringify((await turnWith("person-skill")).prompt)).toContain(RAN);+ expect((await internal(scout.id, person, "/api/internal/coordinate-bots", { botIds: [mate.id], message: "brief-skill please run /weekly-digest now", reply: "none" })).status).toBe(200);+ expect(JSON.stringify((await turnWith("brief-skill")).prompt)).not.toContain(RAN);+ await finish(scout.id, mate.id);+ }, hostTimeout(120_000));++ it("keeps the frame on a page outside work shows, where a person's own conversation may drop it", async () => {+ const scout = await newBot("Page bot");+ const page = { tool: "show_html", html: "<p>A page</p>", title: "A page", frameless: true };+ const { thread } = await webhookTurn(scout.id, "Page hook", "marker-page");+ const shown = await internal(scout.id, thread, "/api/internal/options-card", page);+ expect(shown.status).toBe(201);+ expect((await linesOf(thread)).find((line) => line.id === shown.body.messageId).app.border).toBe(true);+ await finish(scout.id);+ const person = (await team.as(ada, "POST", `/api/bots/${scout.id}/tasks`, { title: "Mine" })).body.task.threadId as string;+ expect((await team.as(ada, "POST", `/api/bots/${scout.id}/messages`, { text: "person-page", threadId: person })).status).toBe(202);+ await turnWith("person-page");+ const own = await internal(scout.id, person, "/api/internal/options-card", page);+ expect(own.status).toBe(201);+ expect((await linesOf(person)).find((line) => line.id === own.body.messageId).app.border).toBe(false);+ await finish(scout.id);+ }, hostTimeout(120_000));++ it("keeps a goal step in a conversation holding outside work confined, with what it hands on", async () => {+ const scout = await newChief("Goal bot");+ const mate = await newBot("Goal mate");+ expect((await team.as(ada, "POST", `/api/bots/${mate.id}/messages`, { text: "person-line-goal", threadId: mate.threadId })).status).toBe(202);+ await turnWith("person-line-goal");+ await finish(mate.id);+ const { thread } = await webhookTurn(scout.id, "Goal hook", "marker-goal");+ await finish(scout.id);+ expect((await team.as(ada, "POST", `/api/bots/${scout.id}/messages`, { text: "goal-in-this-thread: finish it", mode: "goal", threadId: thread })).status).toBe(202);+ expect(confined(await turnWith("goal-in-this-thread"))).toBe(true);+ const capability = await team.capability(scout.id, thread);+ const handed = await internal(scout.id, thread, "/api/internal/coordinate-bots", { botIds: [mate.id], message: "brief-from-goal", reply: "none" }, capability);+ expect(handed.status).toBe(200);+ expect(confined(await turnWith("brief-from-goal"))).toBe(true);+ expect(await internal(scout.id, thread, "/api/internal/retry-thread", { toBotId: mate.id, toThreadId: mate.threadId, note: "note-from-goal" }, capability)).toMatchObject({ status: 403, body: { error: OUTSIDE_STAYS_HERE } });+ expect((await team.as(ada, "POST", `/api/bots/${scout.id}/interrupt`, { threadId: thread })).status).toBe(200);+ await finish(scout.id, mate.id);+ expect((await team.as(ada, "POST", `/api/bots/${mate.id}/messages`, { text: "person-after-goal", threadId: handed.body.receipts[0].threadId })).status).toBe(202);+ expect(confined(await turnWith("person-after-goal"))).toBe(true);+ await finish(mate.id);+ }, hostTimeout(120_000));+it("judges work again after a restart as it stood before", async () => {const scout = await newBot("Restart bot");const mate = await newBot("Restart mate");@@ -487,6 +543,21 @@ describe("a personal Cloud someone else has used", () => {});describe("a desktop", () => {+ it("runs no skill named in a webhook's words, though the turn keeps the bot's level", async () => {+ const local = fx.local;+ const bot = (await local("POST", "/api/bots", { name: "Desk skills" })).body.bot;+ expect((await local("POST", `/api/bots/${bot.id}/skill-template`, skillNamed("desk-digest"))).status).toBe(201);+ const hook = (await local("POST", "/api/webhooks", { name: "Desk skill hook", prompt: "Handle the event.", botId: bot.id })).body;+ const port = Number(new URL(fx.desktopBase).port) + 1;+ expect((await fetch(`http://127.0.0.1:${port}/hooks/${hook.webhook.endpointId}/${encodeURIComponent(hook.credential.secret)}`, { method: "POST", headers: { "content-type": "application/json", "idempotency-key": randomBytes(6).toString("hex") }, body: JSON.stringify({ text: "marker-desk-skill please run /desk-digest now" }) })).status).toBe(202);+ const turn = await turnWith("marker-desk-skill");+ expect(atFull(turn)).toBe(true);+ expect(JSON.stringify(turn.prompt)).not.toContain("The user ran your desk-digest skill");+ writeFileSync(release, "");+ await sleep(1_500);+ for (const file of [release, dump]) rmSync(file, { force: true });+ }, hostTimeout(120_000));+it("brings no level down from a webhook's Chief: the teammate keeps its own", async () => {const local = fx.local;const chief = (await local("POST", "/api/bots", { name: "Desk chief" })).body.bot;