Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(people): call people on self-hosted servers by name, not raw sign-in
TuftyBrunof6d99ab1926c
diff --git a/server/bot-visibility.e2e.test.ts b/server/bot-visibility.e2e.test.tsindex 1a1915c524..33e58aede4 100644--- a/server/bot-visibility.e2e.test.ts+++ b/server/bot-visibility.e2e.test.ts@@ -605,8 +605,8 @@ posixOnly("per-bot visibility on a shared workspace", () => {expect(bobKey).toMatch(/^p_[\w-]{22}$/);expect(adaKey).not.toBe(bobKey);expect(bob.body.message.reactions).toEqual([- { emoji: "π", by: adaKey, name: ADA, at: expect.any(Number) },- { emoji: "π", by: bobKey, name: BOB, at: expect.any(Number) },+ { emoji: "π", by: adaKey, name: "Ada", at: expect.any(Number) },+ { emoji: "π", by: bobKey, name: "Bob", at: expect.any(Number) },]);const changed = await react(ADA, "π");expect(changed.body.message.reactions.map((reaction: any) => [reaction.by, reaction.emoji])).toEqual([[bobKey, "π"], [adaKey, "π"]]);@@ -617,7 +617,7 @@ posixOnly("per-bot visibility on a shared workspace", () => {return !bot.busy && reactions.length === 3 ? reactions : null;});const thread = (await api("GET", `/api/threads/${ids.pubThread}/messages`, undefined, BOSS)).body.messages;- expect(lines?.map((line: any) => [line.reaction, line.sender?.name]), JSON.stringify(thread.map((m: any) => [m.role, m.kind, m.text?.slice(0, 60), m.reaction]))).toEqual([["π", ADA], ["π", BOB], ["π", ADA]]);+ expect(lines?.map((line: any) => [line.reaction, line.sender?.name]), JSON.stringify(thread.map((m: any) => [m.role, m.kind, m.text?.slice(0, 60), m.reaction]))).toEqual([["π", "Ada"], ["π", "Bob"], ["π", "Ada"]]);}, 90_000);it("keeps bots with different audiences from reaching each other", async () => {diff --git a/server/card-answerers.e2e.test.ts b/server/card-answerers.e2e.test.tsindex 990264f97a..66ca51218e 100644--- a/server/card-answerers.e2e.test.ts+++ b/server/card-answerers.e2e.test.ts@@ -154,7 +154,7 @@ posixOnly("who may answer a card on a shared workspace", () => {expect(answered.body.outcome).not.toBe("unavailable");const row = await decision(requestId, "user-approved");expect(row?.actor).toEqual({ kind: "session", sessionId: sessionIds[ADA], label: "ada's laptop", email: ADA });- expect((await settledCard(bot.threadId, requestId))?.card.answeredBy).toEqual({ kind: "session", name: ADA, person: expect.stringMatching(/^p_/u) });+ expect((await settledCard(bot.threadId, requestId))?.card.answeredBy).toEqual({ kind: "session", name: "Ada", person: expect.stringMatching(/^p_/u) });}, 90_000);it("lets a member answer any card on a thread they started", async () => {@@ -233,7 +233,7 @@ posixOnly("who may answer a card on a shared workspace", () => {const answered = await api("POST", `/api/threads/${threadId}/respond`, { requestId, behavior: "allow" }, BOB);expect(answered.status, JSON.stringify(answered.body)).toBe(200);expect((await decision(requestId, "user-approved"))?.actor).toMatchObject({ kind: "session", email: BOB });- expect((await settledCard(copy.automation.executionThreadId, requestId))?.card.answeredBy).toEqual({ kind: "session", name: BOB, person: expect.stringMatching(/^p_/u) });+ expect((await settledCard(copy.automation.executionThreadId, requestId))?.card.answeredBy).toEqual({ kind: "session", name: "Bob", person: expect.stringMatching(/^p_/u) });}, 90_000);it("lets any member answer a card that names nobody, as before", async () => {@@ -249,7 +249,7 @@ posixOnly("who may answer a card on a shared workspace", () => {const first = await cardFrom(bot, bot.threadId, ADA);expect((await api("POST", `/api/threads/${bot.threadId}/respond`, { requestId: first, behavior: "allow" }, BOSS)).status).toBe(200);expect((await decision(first, "user-approved"))?.actor).toMatchObject({ kind: "session", email: BOSS });- expect((await settledCard(bot.threadId, first))?.card.answeredBy).toEqual({ kind: "session", name: BOSS, person: expect.stringMatching(/^p_/u) });+ expect((await settledCard(bot.threadId, first))?.card.answeredBy).toEqual({ kind: "session", name: "Boss", person: expect.stringMatching(/^p_/u) });const second = await cardFrom(bot, bot.threadId, BOB);expect((await api("POST", `/api/threads/${bot.threadId}/respond`, { requestId: second, behavior: "deny" })).status).toBe(200);diff --git a/server/index.ts b/server/index.tsindex b62fd6f6c0..658c0f68ee 100644--- a/server/index.ts+++ b/server/index.ts@@ -21,7 +21,7 @@ import { RoomContextTracker, roomResetNote } from "./room-context.ts";import { createRoomTranscript, GROUP_CONTEXT_MESSAGES } from "./host/room-transcript.ts";import { createRoomSessions } from "./host/room-sessions.ts";import { LentComputers, provenRequestPerson, SharedComputers, sharedComputerOperation } from "./shared-computers.ts"; import { lentScreenResult } from "./lent-screen-guidance.ts"; import { DeviceLinks } from "./device-links.ts"; import { createLentMcp, isLentMcpPath } from "./lent-mcp.ts";-import { cloudHomeLendingRefusal, cloudHomeOwnTurnRefusal, createCloudRoutineAuthors, ownerOnlyConversation } from "./cloud-lending.ts"; import { createOwnHome } from "./own-home.ts"; import { createPlacesElsewhere } from "./places-elsewhere.ts"; import { createPlacesElsewhereRoutes } from "./routes/places-elsewhere.ts"; import { assertRoomFolder } from "./room-folder.ts"; import { cloudConnectedAppsBrokerUrl, startCloudHomeConnectedApps, stopCloudHomeConnectedApps } from "./cloud-connected-apps.ts"; import { createTeamConnectionsHost } from "./host/team-connections-host.ts"; import { createCloudLendingTurns } from "./host/cloud-lending-turns.ts"; import { createTeamConnectionRoutes } from "./routes/team-connections.ts";+import { cloudHomeLendingRefusal, cloudHomeOwnTurnRefusal, createCloudRoutineAuthors, ownerOnlyConversation } from "./cloud-lending.ts"; import { createOwnHome, selfHostedPersonName } from "./own-home.ts"; import { createPlacesElsewhere } from "./places-elsewhere.ts"; import { createPlacesElsewhereRoutes } from "./routes/places-elsewhere.ts"; import { assertRoomFolder } from "./room-folder.ts"; import { cloudConnectedAppsBrokerUrl, startCloudHomeConnectedApps, stopCloudHomeConnectedApps } from "./cloud-connected-apps.ts"; import { createTeamConnectionsHost } from "./host/team-connections-host.ts"; import { createCloudLendingTurns } from "./host/cloud-lending-turns.ts"; import { createTeamConnectionRoutes } from "./routes/team-connections.ts";import { botMemoryFiles, createLendingMemory } from "./lending-memory.ts";import { SharedComputerControl } from "./shared-computer-control.ts";import { STATUS_REPLY_TIMEOUT_MS } from "./runtime/status-reply.ts"; import { createCoordinator, type ComposedTurn, type CoordinateBotsCall, type Coordinator, type HandoffOpener, type HandoffOptions, type HandoffView, type HostTurnResult } from "./coordinator.ts";@@ -824,11 +824,10 @@ registerEnginesBinDir(); const engineUpdates = engineUpdatesFor({ drivers: BUILTconst turnTriggers = new Map<string, UsageTrigger>();const NOBODY_PROFILE: MemberProfile = { name: "", email: "", aboutMe: "" };-/** What a signed-in person is called on their lines, cards and reactions: their address or device label, and on a Team- * Cloud the name they chose first. */+/** What a signed-in person is called on their lines, cards and reactions: on a Team Cloud the name they chose first. */function sessionPersonName(session: SessionRecord): string {- const claimed = (session.email ?? session.label ?? "").trim();- return (CLOUD_TEAM ? teamHost.memberProfile(session).name : "") || claimed;+ if (CLOUD_TEAM) return teamHost.memberProfile(session).name || (session.email ?? session.label ?? "").trim();+ return selfHostedPersonName(session, signInAllowList().admins, cfg.profile);}function messageSender(auth: RequestAuth): ResolvedSender | undefined {diff --git a/server/own-home.test.ts b/server/own-home.test.tsindex 6424650eb5..e57ec96f54 100644--- a/server/own-home.test.ts+++ b/server/own-home.test.ts@@ -3,7 +3,7 @@ import { tmpdir } from "node:os";import { join } from "node:path";import { afterEach, describe, expect, it } from "vitest";-import { createOwnHome, oneOwner, ownServerOwner, type OwnServerFacts } from "./own-home.ts";+import { createOwnHome, oneOwner, ownServerOwner, selfHostedPersonName, type OwnServerFacts } from "./own-home.ts";import type { RequestAuth } from "./request-auth.ts";import type { SessionRecord } from "./sessions.ts";@@ -63,3 +63,32 @@ describe("a server of one person's own", () => {expect(home.ownServer()).toBeNull();});});++describe("what a self-hosted server calls someone on their lines", () => {+ const profile = { name: "Ada Lovelace", email: "[email protected]" };+ const signIn = (scopes: Array<"admin" | "client">, email?: string) => ({ label: "Chrome on Mac", scopes, ...(email ? { email } : {}) });++ it("is the profile's name for the profile's own address, and for the one admin by address or by their own device", () => {+ expect(selfHostedPersonName(signIn(["client"], "[email protected]"), [], profile)).toBe("Ada Lovelace");+ expect(selfHostedPersonName(signIn(["admin", "client"]), [], profile)).toBe("Ada Lovelace");+ expect(selfHostedPersonName(signIn(["admin", "client"], "[email protected]"), ["[email protected]"], profile)).toBe("Ada Lovelace");+ expect(selfHostedPersonName(signIn(["admin", "client"]), ["[email protected]"], profile)).toBe("Ada Lovelace");+ });++ it("is someone else's address as a name, never the profile's", () => {+ expect(selfHostedPersonName(signIn(["client"], "[email protected]"), [], profile)).toBe("Grace Hopper");+ expect(selfHostedPersonName(signIn(["admin", "client"], "[email protected]"), ["[email protected]"], profile)).toBe("Grace");+ });++ it("keeps a device's label when it may be someone else's: one that may only chat, or one paired while several can pair", () => {+ expect(selfHostedPersonName(signIn(["client"]), [], profile), "a device that may only chat").toBe("Chrome on Mac");+ expect(selfHostedPersonName(signIn(["admin", "client"]), ["[email protected]", "[email protected]"], profile)).toBe("Chrome on Mac");+ expect(selfHostedPersonName(signIn(["admin", "client"]), ["@example.test"], profile), "everyone at a domain").toBe("Chrome on Mac");+ expect(selfHostedPersonName({ label: "Nightly CI", scopes: ["admin", "client"], token: true }, [], profile), "a script token").toBe("Nightly CI");+ });++ it("falls back to the address or label while the profile has no name", () => {+ expect(selfHostedPersonName(signIn(["admin", "client"]), [], { name: " ", email: "" })).toBe("Chrome on Mac");+ expect(selfHostedPersonName(signIn(["client"], "[email protected]"), [], { email: "[email protected]" })).toBe("Ada");+ });+});diff --git a/server/own-home.ts b/server/own-home.tsindex 10c952bad2..f9341bd825 100644--- a/server/own-home.ts+++ b/server/own-home.ts@@ -1,9 +1,11 @@// A server of one person's own (`openmausbot serve` on their VPS or Mac mini) can be their home, as My Cloud is: its owner// moves a computer's bots into it, and that computer then works for it. Security: only where nobody else signs in, so no// one else's bots or turns ever reach a computer lent this way, and never a Cloud, a team's Cloud or a hosted workspace.+import { nameFromEmail } from "../shared/bot-owner.ts";import { movedFrom } from "./cloud-send-arrived.ts";import type { OwnServer } from "./person-key.ts";import type { RequestAuth } from "./request-auth.ts";+import type { SessionRecord } from "./sessions.ts";export interface OwnServerFacts {/** A Cloud home, a team's Cloud or a hosted workspace: MausBot or an organization runs it, never one person. */@@ -28,6 +30,15 @@ export function ownServerOwner(facts: OwnServerFacts, auth: RequestAuth): booleareturn !email || facts.admins.length === 0 || facts.admins[0] === email;}+/** A device without an address is the one admin's only with full access (only an admin pairs one); a device that may only+ * chat, or a script token, may be anyone's. */+export function selfHostedPersonName(session: Pick<SessionRecord, "email" | "label" | "scopes" | "token">, admins: readonly string[], profile?: { name?: string; email?: string }): string {+ const email = session.email?.trim().toLowerCase();+ const soleAdmin = oneOwner({ managed: false, shared: false, admins });+ const theirs = email ? email === profile?.email?.trim().toLowerCase() || (soleAdmin && admins[0] === email) : soleAdmin && !session.token && session.scopes.includes("admin");+ return (theirs && profile?.name?.trim()) || (email ? nameFromEmail(email) : session.label.trim());+}+/** `facts()` is read on every ask, so a sign-in list changed in Settings counts at once. `here()`: this server took a move* from its owner (cloud-send-arrived.ts keeps where from), so it is their home and their computers work for it. */export function createOwnHome({ facts, dataDir }: { facts(): OwnServerFacts; dataDir: string }) {