Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge the clean workspace into the rail
milind-soni305786eeb841
diff --cc electron/fixtures/home-window-world.mjsindex b20496d1d3,26fd30a4ac..45f8472c16--- a/electron/fixtures/home-window-world.mjs+++ b/electron/fixtures/home-window-world.mjs@@@ -18,7 -18,7 +18,7 @@@ export const json = (body, status = 200* sign-in (its power word, wake, pairing code), My Cloud's answers (`cloud`), the window (where it went), the startup* screen and a manual clock.*/- export function world({ journal = done(), marker = null, state = connected(), power = null, cloud = {}, team = {}, client = {}, splash = true, url = "", remembered = null, ownMove = null, deps = {} } = {}) {-export function world({ clean = null, journal = done(), marker = null, state = connected(), power = null, cloud = {}, team = {}, client = {}, splash = true, url = "", remembered = null, ownMove = null } = {}) {++export function world({ clean = null, journal = done(), marker = null, state = connected(), power = null, cloud = {}, team = {}, client = {}, splash = true, url = "", remembered = null, ownMove = null, deps = {} } = {}) {const w = {journal, marker, state, power, ownMove, clock: 1_000_000, typed: 0, now: () => w.clock,cloud: { down: false, signedIn: true, version: "0.1.130", health: 200, wakes: true, ...cloud },diff --cc electron/main.mjsindex e7714045b3,a3369f3856..5188267904--- a/electron/main.mjs+++ b/electron/main.mjs@@@ -2657,10 -2657,10 +2657,10 @@@ const cloudLook = createCloudLook({ stoconst cloudBuy = installCloudBuy({ ipcMain, guard: localWorkspaceOnly, client: ensureCloudAccount, offersReady: cloudOffersReady, clipboard, look: cloudLook });const localServerRequest = (route, init = {}) => (serverProc && serverReady ? fetch(`http://127.0.0.1:${SERVER_PORT}${route}`, { ...init, redirect: "error", credentials: "omit", headers: { ...init.headers, [DESKTOP_MUTATION_HEADER]: desktopMutationToken } }) : Promise.reject(new Error("not running")));const teamProfileSeeds = createTeamProfileSeeds({ teamFetch: (...args) => session.defaultSession.fetch(...args), localRequest: localServerRequest, log: slog });- const oneHome = installOneHome({ ipcMain, cloudPage: cloudPageAsking, server: () => serverProc, cookieFetch: (...args) => session.defaultSession.fetch(...args), home: () => (myCloud() && cloudAccount ? { origin: myCloud(), grant: () => cloudAccount.pairHome() } : null), power: cloudPower, file: () => path.join(app.getPath("userData"), "cloud-send.json"), localRequest: localServerRequest, space: { disk: () => cloudPlanDisk(ensureCloudAccount().state()), grow: sizeGb => ensureCloudAccount().growDisk(sizeGb) }, reconnect: origin => signInCloudSession({ origin, mine: myCloud(), pair: () => ensureCloudAccount().pairHome(), fetch: (...args) => session.defaultSession.fetch(...args) }), window: () => (desktopRemoteAccess ? null : mainWindow), localOrigin: rendererOrigin, account: () => cloudAccount, journalFile: () => path.join(app.getPath("userData"), "one-home.json"), tempRoot: () => path.join(app.getPath("temp"), "openmaus-one-home"), lend: projects => sharingController().lendProjects(projects), phone: { paired: () => companionEnabledAtRest(), stop: () => stopDesktopCompanion({ remember: false }).then(() => {}), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: () => void showHome({ place: "cloud" }), openTeam: team => void showHome({ place: { team: team.id, name: team.name } }), openLocal: () => void showHome(), restart: () => relaunchAfterDesktopRemoteChange(), version: app.getVersion(), log: slog, other: () => ownHome, accountsHere: () => accountRing()?.count() ?? 1 }); ownHome = installOwnHome({ localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, handoff: what => oneHome.handoff(what), cloudJournal: () => oneHome.journal(), journal: jsonFile(path.join(app.getPath("userData"), "own-home.json")), choice: jsonFile(path.join(app.getPath("userData"), "own-home-choice.json")), sendState: jsonFile(path.join(app.getPath("userData"), "own-home-send.json")), lend: (projects, place) => sharingController().lendProjects(projects, place), phone: { paired: () => companionEnabledAtRest(), stop: () => stopDesktopCompanion({ remember: false }).then(() => {}), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: place => void workspaceMenuAction(() => switchEnvironment(place.id)), lastInput: oneHome.lastInput, version: app.getVersion(), log: slog, onChange: () => { oneHome.publish(); computerSharing?.cloudChanged(); railChanged(); } }); twoPlaces = installTwoPlacesMain({ ipcMain, guard: localWorkspaceOnly, localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, cloud: () => ({ origin: myCloud(), asleep: cloudPower.asleep() }), oneHome, ownHome, dismissed: jsonFile(path.join(app.getPath("userData"), "two-places.json")), account: () => cloudAccount, teamsRemembered: jsonFile(path.join(app.getPath("userData"), "team-places.json")), log: slog, tell: () => { if (mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })) mainWindow.webContents.send("two-places:changed"); } });-const oneHome = installOneHome({ ipcMain, clean: cleanWorkspace, cloudPage: cloudPageAsking, server: () => serverProc, cookieFetch: (...args) => session.defaultSession.fetch(...args), home: () => (myCloud() && cloudAccount ? { origin: myCloud(), grant: () => cloudAccount.pairHome() } : null), power: cloudPower, file: () => path.join(app.getPath("userData"), "cloud-send.json"), localRequest: localServerRequest, space: { disk: () => cloudPlanDisk(ensureCloudAccount().state()), grow: sizeGb => ensureCloudAccount().growDisk(sizeGb) }, reconnect: origin => signInCloudSession({ origin, mine: myCloud(), pair: () => ensureCloudAccount().pairHome(), fetch: (...args) => session.defaultSession.fetch(...args) }), window: () => (desktopRemoteAccess ? null : mainWindow), localOrigin: rendererOrigin, account: () => cloudAccount, journalFile: () => path.join(app.getPath("userData"), "one-home.json"), tempRoot: () => path.join(app.getPath("temp"), "openmaus-one-home"), lend: projects => sharingController().lendProjects(projects), phone: { paired: () => companionEnabledAtRest(), stop: () => stopDesktopCompanion({ remember: false }).then(() => {}), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: () => void showHome({ place: "cloud" }), openTeam: team => void showHome({ place: { team: team.id, name: team.name } }), openLocal: () => void showHome(), restart: () => relaunchAfterDesktopRemoteChange(), version: app.getVersion(), log: slog, other: () => ownHome }); ownHome = installOwnHome({ localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, handoff: what => oneHome.handoff(what), cloudJournal: () => oneHome.journal(), journal: jsonFile(path.join(app.getPath("userData"), "own-home.json")), choice: jsonFile(path.join(app.getPath("userData"), "own-home-choice.json")), sendState: jsonFile(path.join(app.getPath("userData"), "own-home-send.json")), lend: (projects, place) => sharingController().lendProjects(projects, place), phone: { paired: () => companionEnabledAtRest(), stop: () => stopDesktopCompanion({ remember: false }).then(() => {}), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: place => void workspaceMenuAction(() => switchEnvironment(place.id)), lastInput: oneHome.lastInput, version: app.getVersion(), log: slog, onChange: () => { oneHome.publish(); computerSharing?.cloudChanged(); railChanged(); } }); twoPlaces = installTwoPlacesMain({ ipcMain, guard: localWorkspaceOnly, localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, cloud: () => ({ origin: myCloud(), asleep: cloudPower.asleep() }), oneHome, ownHome, dismissed: jsonFile(path.join(app.getPath("userData"), "two-places.json")), account: () => cloudAccount, teamsRemembered: jsonFile(path.join(app.getPath("userData"), "team-places.json")), log: slog, tell: () => { if (mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })) mainWindow.webContents.send("two-places:changed"); } });++const oneHome = installOneHome({ ipcMain, clean: cleanWorkspace, cloudPage: cloudPageAsking, server: () => serverProc, cookieFetch: (...args) => session.defaultSession.fetch(...args), home: () => (myCloud() && cloudAccount ? { origin: myCloud(), grant: () => cloudAccount.pairHome() } : null), power: cloudPower, file: () => path.join(app.getPath("userData"), "cloud-send.json"), localRequest: localServerRequest, space: { disk: () => cloudPlanDisk(ensureCloudAccount().state()), grow: sizeGb => ensureCloudAccount().growDisk(sizeGb) }, reconnect: origin => signInCloudSession({ origin, mine: myCloud(), pair: () => ensureCloudAccount().pairHome(), fetch: (...args) => session.defaultSession.fetch(...args) }), window: () => (desktopRemoteAccess ? null : mainWindow), localOrigin: rendererOrigin, account: () => cloudAccount, journalFile: () => path.join(app.getPath("userData"), "one-home.json"), tempRoot: () => path.join(app.getPath("temp"), "openmaus-one-home"), lend: projects => sharingController().lendProjects(projects), phone: { paired: () => companionEnabledAtRest(), stop: () => stopDesktopCompanion({ remember: false }).then(() => {}), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: () => void showHome({ place: "cloud" }), openTeam: team => void showHome({ place: { team: team.id, name: team.name } }), openLocal: () => void showHome(), restart: () => relaunchAfterDesktopRemoteChange(), version: app.getVersion(), log: slog, other: () => ownHome, accountsHere: () => accountRing()?.count() ?? 1 }); ownHome = installOwnHome({ localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, handoff: what => oneHome.handoff(what), cloudJournal: () => oneHome.journal(), journal: jsonFile(path.join(app.getPath("userData"), "own-home.json")), choice: jsonFile(path.join(app.getPath("userData"), "own-home-choice.json")), sendState: jsonFile(path.join(app.getPath("userData"), "own-home-send.json")), lend: (projects, place) => sharingController().lendProjects(projects, place), phone: { paired: () => companionEnabledAtRest(), stop: () => stopDesktopCompanion({ remember: false }).then(() => {}), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }).then(() => {}) }, openHome: place => void workspaceMenuAction(() => switchEnvironment(place.id)), lastInput: oneHome.lastInput, version: app.getVersion(), log: slog, onChange: () => { oneHome.publish(); computerSharing?.cloudChanged(); railChanged(); } }); twoPlaces = installTwoPlacesMain({ ipcMain, guard: localWorkspaceOnly, localRequest: localServerRequest, fetch: (...args) => session.defaultSession.fetch(...args), environments: () => environmentsState.environments, cloud: () => ({ origin: myCloud(), asleep: cloudPower.asleep() }), oneHome, ownHome, dismissed: jsonFile(path.join(app.getPath("userData"), "two-places.json")), account: () => cloudAccount, teamsRemembered: jsonFile(path.join(app.getPath("userData"), "team-places.json")), log: slog, tell: () => { if (mainWindow && !mainWindow.isDestroyed() && senderIsLocal({ sender: mainWindow.webContents })) mainWindow.webContents.send("two-places:changed"); } });// Teams from the verified session as places this window shows (home-places.mjs): the one to open next time, and its lines.const homePlaces = createHomePlaces({ store: jsonFile(path.join(app.getPath("userData"), "home-place.json")), environments: () => environmentsState, persist: persistEnvironments, makeId: randomUUID, homeOrigin: myCloud, log: slog });- const homeWindow = createHomeWindow({ journal: oneHome.journal, frozen: oneHome.marker, account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), restored: cloudAccountRestored,+ const homeWindow = createHomeWindow({ clean: cleanWorkspace, journal: oneHome.journal, frozen: oneHome.marker, account: () => (app.isPackaged && !desktopRemoteAccess ? cloudAccount : null), restored: cloudAccountRestored,window: () => (mainWindow && !mainWindow.isDestroyed() ? mainWindow : null), ensureWindow: () => { if (!mainWindow || mainWindow.isDestroyed()) createWindow({ deferNavigation: true }); },localOrigin: rendererOrigin, cookieFetch: (...args) => session.defaultSession.fetch(...args), power: cloudPower, splash: () => startupScreen, lastInput: oneHome.lastInput, rehomed: () => talk.homeChanged(), log: slog,hosts: () => session.defaultSession, readyStore: jsonFile(path.join(app.getPath("userData"), "cloud-ready.json")), ownMove: () => ownHome?.underWay() ?? null,@@@ -2778,7 -2778,7 +2778,7 @@@ ipcMain.handle("environments:forget", l// Once My Cloud is home the switcher lists only whole places, and shows only when there is more than My Cloud.const homeAlone = () => Boolean(homeWindow.cloudOrigin()) && !otherPlaces(environmentsState, homeWindow.cloudOrigin());ipcMain.handle("workspaces:state", workspaceOnly(event => ({ ...workspaceSummary(environmentsState), ...(homeAlone() && homeWindow.homePage(event) ? { home: true } : {}) })));- ipcMain.handle("workspaces:line", workspaceOnly(() => homePlaces.line()));-ipcMain.handle("workspaces:line", workspaceOnly(event => (cleanWorkspace.active() && senderIsLocal(event) ? { kind: "clean" } : homePlaces.line())));++ipcMain.handle("workspaces:line", workspaceOnly(event => (cleanWorkspace.active() && senderIsLocal(event) ? { kind: "clean", ...(accountRing.waiting().some(row => row.id === oneHome.journal()?.cloud?.account) ? { saved: true } : {}) } : homePlaces.line())));let workspaceMenuOpen = false;ipcMain.handle("workspaces:menu", workspaceOnly(async (_event, from) => {if (workspaceMenuOpen || homeAlone()) return;@@@ -3103,10 -3103,10 +3103,10 @@@ app.whenReady().then(async () =>// Fresh local use never makes a Cloud request; start only restores an existing grant.if (app.isPackaged && !desktopRemoteAccess) {cloudAccountRestoring = true;- cloudAccountStarted = ensureCloudAccount().start().catch(() => {}).finally(() => { cloudAccountRestoring = false; });+ cloudAccountStarted = ensureCloudAccount().start().catch(() => {}).then(() => accountRing()?.start()).finally(() => { cloudAccountRestoring = false; });}void cloudAccountStarted.then(() => { cloudSignInRestored = true; void oneHome.kick(); void homeWindow.refresh(); }); void ownHome?.kick();- if (!desktopRemoteAccess && serverReady && companionEnabledAtRest() && !oneHome.away() && !ownHome?.away()) {+ if (!desktopRemoteAccess && serverReady && companionEnabledAtRest() && !oneHome.away() && !ownHome?.away() && !cleanWorkspace.marker().frozen) {// Retries stop once the person turns the phone off, starts it by hand or quits.const wanted = () => !desktopShutdownStarted && companionEnabledAtRest() && !companionRunning() && !oneHome.away() && !ownHome?.away();void autoStartCompanion({ restored: managedDesktop?.whenRestored(), start: () => startDesktopCompanion({ waitForHosted: false, remember: false }), wanted, log: slog });diff --cc electron/one-home-main.mjsindex 65af2ef967,9222c6c93f..73e749efac--- a/electron/one-home-main.mjs+++ b/electron/one-home-main.mjs@@@ -117,9 -117,9 +117,11 @@@ async function answer(response)* keep?: { read(): unknown, write(value: unknown): void },* reportTimers?: { set(work: () => void, ms: number): unknown, clear(timer: unknown): void },* other?(): null | { view(): unknown, seen(): unknown, retry(): Promise<unknown>, active(): boolean },+ * accountsHere?(): number,+ * clean?: import("./clean-workspace.mjs").CleanWorkspace | null,- * }} deps `localRequest`: this computer's server, as its owner (main adds the owner's header), and only its own copy while `clean`+ * }} deps `accountsHere`: how many accounts are signed in on this device: with more than one, which Cloud this computer's bots- * belong in is the person's to say, so no first move starts by itself. `localRequest`: this computer's server, as its owner (main adds the owner's header). `account`: the MausBot++ * belong in is the person's to say, so no first move starts by itself. `localRequest`: this computer's server, as its owner (main adds the owner's header), and only its own copy while `clean`+ * (the clean workspace) runs. `account`: the MausBot* Cloud sign-in (cloud-account.mjs). `journal`: where the move's journal is kept, journalFile by default; `keep`: the* person's choice to keep this computer's bots here, one-home-keep.json beside it by default. `openTeam`:* shows a team's page, where a bot moved into it from My Cloud now lives (team-move-main.mjs, whose journal is@@@ -128,9 -128,11 +130,11 @@@* while it is chosen no move to My Cloud starts, and its line is the one this computer's page shows. The rest are* installCloudSend's.*/- export function installOneHome({ localRequest, account, journalFile, tempRoot, lend, phone, openHome, openLocal, restart, version, log = () => {}, journal: kept, keep: keptChoice, openTeam, teamJournal,+ export function installOneHome({ localRequest: anyServer, clean = null, account, journalFile, tempRoot, lend, phone, openHome, openLocal, restart, version, log = () => {}, journal: kept, keep: keptChoice, openTeam, teamJournal,- reportTimers, other = () => null, ...sendDeps }) {+ reportTimers, other = () => null, accountsHere = () => 1, ...sendDeps }) {const fetchImpl = sendDeps.fetch ?? globalThis.fetch;+ const localRequest = clean ? clean.realCopy(anyServer) : anyServer;+ const onOwnCopy = (work) => (clean ? clean.holding(work) : work());let home = null;let lastInput = 0;const watched = new WeakSet();diff --cc src/components/HomeLine.test.tsindex 0fb2e1f63e,72c4a1d795..7eefd42530--- a/src/components/HomeLine.test.ts+++ b/src/components/HomeLine.test.ts@@@ -54,3 -58,28 +58,29 @@@ it("a team's page names its notificatioawait mount(vi.fn().mockResolvedValue(null));await vi.waitFor(() => expect(place.set).toEqual(["Acme", null]));});++ it("the clean workspace's line says the bots are safe in their Cloud, on every load, with no Sign in button: that stays in the You menu", async () => {+ ais.instances = [{ ready: true, instanceId: "claude", driver: "claudeCode" }];+ const line = vi.fn().mockResolvedValue({ kind: "clean" });+ await mount(line);+ await vi.waitFor(() => expect(host.querySelector("[data-home-line='clean']")?.textContent).toBe("Your bots are in your Cloud. Sign in to get them."));+ expect(host.querySelector("button")).toBeNull();+ expect(homeLineText({ kind: "clean" })).toBe("Your bots are in your Cloud. Sign in to get them.");++ expect(homeLineText({ kind: "clean", saved: true })).toBe("Your bots are in your other account's Cloud. Click its icon at the side to get them.");+ });++ it("with the new-user setup skipped, the clean workspace still offers connecting an AI while none is ready", async () => {+ ais.instances = [{ ready: false, instanceId: "claude", driver: "claudeCode" }];+ await mount(vi.fn().mockResolvedValue({ kind: "clean" }));+ await vi.waitFor(() => expect(host.querySelector("[data-home-line-ai]")?.textContent).toBe("Connect an AI"));+ expect(host.querySelector("[data-connect-ai]")).toBeNull();+ flushSync(() => (host.querySelector("[data-home-line-ai]") as HTMLButtonElement).click());+ expect(host.querySelector("[data-connect-ai]")).not.toBeNull();+ });++ it("a team's line never offers it", async () => {+ ais.instances = [];+ await mount(vi.fn().mockResolvedValue({ kind: "left", name: "Acme" }));+ await vi.waitFor(() => expect(host.querySelector("[data-home-line='left']")).not.toBeNull());+ expect(host.querySelector("[data-home-line-ai]")).toBeNull();+ });diff --cc src/components/HomeLine.tsxindex ad2e4e6d54,f0d4feedac..dfd91ee056--- a/src/components/HomeLine.tsx+++ b/src/components/HomeLine.tsx@@@ -1,18 -1,35 +1,36 @@@import { useEffect, useState } from "react";- import { Users } from "lucide-react";+ import { Cloud, Users } from "lucide-react";+ import { freeFallback } from "../../shared/ai-ranking";+ import { engineReady } from "@/components/EngineLibrary";+ import { ConnectAiDialog } from "@/components/onboarding/ConnectAi";import { t } from "@/lib/i18n";import { setNotificationPlace } from "@/lib/notify";+ import { useStore } from "@/state/store";- type Line = { kind: "left"; name: string };-type Line = { kind: "left"; name: string } | { kind: "clean" };++type Line = { kind: "left"; name: string } | { kind: "clean"; saved?: boolean };- /** The words for main's one line: a team this person is no longer in. */-/** The words for main's one line: a team this person is no longer in, or that the clean workspace isn't where their bots went. */++/** The words for main's one line: a team this person is no longer in, or that the clean workspace isn't where their bots went (`saved`: the account they moved with is signed in here too, one click away on the rail). */export function homeLineText(line: Line): string {- return line.kind === "clean" ? t("homeLine.clean") : t("homeLine.left", { name: line.name });++ if (line.kind === "clean") return t(line.saved ? "homeLine.cleanSaved" : "homeLine.clean");+ return t("homeLine.left", { name: line.name });}+ /** The clean workspace skips the new-user setup, so connecting an AI is offered here while none is ready. Nothing is sent to+ * test one: nothing starts by itself in this workspace. */+ function ConnectAiLink() {+ const { state } = useStore();+ const [open, setOpen] = useState(false);+ if (state.instances.some((instance) => engineReady(instance) && !freeFallback(instance))) return null;+ return <>+ <button type="button" data-home-line-ai className="underline underline-offset-2 hover:text-ink" onClick={() => setOpen(true)}>{t("onboarding.meet.connectAi")}</button>+ {open && <ConnectAiDialog tested={null} onClose={() => setOpen(false)} />}+ </>;+ }+/** In the desktop app, never in a browser: one plain line main has for the next page, served once (home-places.mjs):* after a team dropped this person, that they are no longer in it. Nothing to press; it goes with the page. (Who can- * see a team's private chats is said in the chat itself, by the team's own page.) */+ * see a team's private chats is said in the chat itself, by the team's own page.) Or, for as long as the clean workspace+ * runs (clean-workspace.mjs), that the person's bots are safe in their Cloud; Sign in stays in the You menu. */export function HomeLine() {const bridge = !window.ogb?.remoteClient?.active ? window.ogb?.workspaces : undefined;const [line, setLine] = useState<Line | null>(null);diff --cc src/locales/en.jsonindex b03800dbc7,d1cd03ba70..b7663e6cde--- a/src/locales/en.json+++ b/src/locales/en.json@@@ -7102,6 -7092,7 +7102,8 @@@"homeScreen.planNamed": "{name} isn't running","homeScreen.setupNamed": "Setting up {name}…","homeLine.left": "You're no longer in {name}.",+ "homeLine.clean": "Your bots are in your Cloud. Sign in to get them.",++ "homeLine.cleanSaved": "Your bots are in your other account's Cloud. Click its icon at the side to get them.","teamMove.menu": "Move to {team}","teamMove.title": "Move {bot} to {team}?","teamMove.everyone": "Everyone in {team} can use {bot}. Only {team}'s admins can change it.",