Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

The clean workspace: the rail loads after a restart, a Sign in row, no popup over it (#4335)

Milind Soni85d7a42e54b0
diff --git a/electron/chrome-rail.mjs b/electron/chrome-rail.mjs
index 2700a0e0cb..0a68f7b0dc 100644
--- a/electron/chrome-rail.mjs
+++ b/electron/chrome-rail.mjs
@@ -42,6 +42,8 @@ const ABORTED = -3;
*/
export function createChromeRail({ createView, preload, args, url, wanted, prefs = () => null, changed = () => {}, log = () => {} }) {
let view = null, win = null, shown = false, expanded = false, held = false;
+ // The rail's page didn't load (this app's server was restarting): it loads again at the next refresh, or it stays a blank strip.
+ let unloaded = false;
// Whether the page beside draws the frame; the window opens as if it does (windowChromeOptions).
let framed = true, frameGrace = null;
// The document beside the rail offered its button; a new one may still (`grace`); the page stopped responding.
@@ -94,6 +96,7 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefs
};
/** The page beside the rail asks: the window's own page, in its main frame (never a frame inside it). */
const pageBeside = (event) => Boolean(page() && event?.sender === win.webContents && event.senderFrame === win.webContents.mainFrame);
+ const load = (contents) => { void contents.loadURL(url()).catch((error) => log(`chrome rail: ${error?.message ?? error}`)); };
const ensureView = () => {
if (view) return view;
view = createView({ webPreferences: { contextIsolation: true, sandbox: true, nodeIntegration: false, preload, additionalArguments: args() } });
@@ -105,7 +108,9 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefs
contents.on("will-redirect", stay);
contents.on("render-process-gone", () => { log("chrome rail: its page went away; loading it again"); void contents.loadURL(url()).catch(() => {}); });
contents.on("did-finish-load", () => contents.send("rail:framed", framed));
- void contents.loadURL(url()).catch((error) => log(`chrome rail: ${error?.message ?? error}`));
+ // Only a load's failing says so: the error page that replaces it finishes loading too.
+ contents.on("did-fail-load", (_event, code, _description, _url, mainFrame) => { if (mainFrame && code !== ABORTED) unloaded = true; });
+ load(contents);
return view;
};
const rail = {
@@ -138,6 +143,7 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefs
* whole window otherwise. */
refresh() {
const on = alive() && ((wanted() && !hidden()) || held);
+ if (view && unloaded && on) { unloaded = false; load(view.webContents); }
if (on === shown) layout();
else {
shown = on;
diff --git a/electron/chrome-rail.node-test.mjs b/electron/chrome-rail.node-test.mjs
index 0c7683f049..20f47445e0 100644
--- a/electron/chrome-rail.node-test.mjs
+++ b/electron/chrome-rail.node-test.mjs
@@ -355,3 +355,31 @@ test("the accounts sheet holds the rail's page up, even for someone who hid the
w.rail.holdOpen(true); w.rail.holdOpen(false);
assert.equal(w.rail.shown(), true, "a rail that was there stays");
});
+
+test("the rail's page that couldn't load (this app's server was restarting) loads again at the next refresh, so it isn't left a blank strip", () => {
+ const w = world();
+ w.rail.attach(w.win);
+ const contents = w.made[0].webContents, loads = () => contents.loaded.length;
+ assert.equal(loads(), 1);
+ w.rail.refresh();
+ assert.equal(loads(), 1, "loaded or on its way: not loaded again");
+ contents.emit("did-fail-load", {}, -102, "ERR_CONNECTION_REFUSED", "http://127.0.0.1:8799/rail", true);
+ assert.equal(loads(), 1, "nothing retries until the server says it is ready");
+ w.rail.refresh();
+ assert.equal(loads(), 2, "the next refresh loads it");
+ w.rail.refresh();
+ assert.equal(loads(), 2, "once");
+ contents.emit("did-fail-load", {}, -3, "ERR_ABORTED", "http://127.0.0.1:8799/rail", true);
+ w.rail.refresh();
+ assert.equal(loads(), 2, "a load cut short by another isn't a failure");
+ contents.emit("did-fail-load", {}, -105, "ERR_NAME_NOT_RESOLVED", "https://cdn.example.test/", false);
+ w.rail.refresh();
+ assert.equal(loads(), 2, "nor a frame inside it");
+ contents.emit("did-fail-load", {}, -102, "ERR_CONNECTION_REFUSED", "http://127.0.0.1:8799/rail", true);
+ contents.emit("did-finish-load");
+ w.rail.refresh();
+ assert.equal(loads(), 3, "the error page that replaced it finishing loading isn't the rail's page loading (seen in the real app)");
+ contents.emit("did-finish-load");
+ w.rail.refresh();
+ assert.equal(loads(), 3, "and the load that worked stays");
+});
diff --git a/electron/clean-workspace.d.mts b/electron/clean-workspace.d.mts
index 88f141d15f..1c20bc4810 100644
--- a/electron/clean-workspace.d.mts
+++ b/electron/clean-workspace.d.mts
@@ -2,6 +2,7 @@ export function cleanWorkspaceDir(dataDir: string): string;
export function cleanWorkspaceConfig(language?: string | null, now?: Date): { language?: string; onboarding: { completedAt: string; version: number; hintsSeen: string[] } };
export interface CleanWorkspace {
active(): boolean;
+ ownCopy(): boolean;
marker(): { frozen: boolean; cloud?: string; place?: string };
enter(): Promise<boolean>;
leave(): Promise<boolean>;
diff --git a/electron/clean-workspace.mjs b/electron/clean-workspace.mjs
index 1294750997..c91ef46ba7 100644
--- a/electron/clean-workspace.mjs
+++ b/electron/clean-workspace.mjs
@@ -18,6 +18,8 @@ import { WELCOME_VERSION } from "./onboarding-record.mjs";
/** This first conversation stays quiet: no corner notices until a reply, no spotlights (src/lib/onboarding.ts MET_CHIEF_HINT). */
const QUIET_HINT = "met-chief-v1";
+/** The popup that offers to bring bots here (src/lib/notices.ts GROK_MOVE_NOTICE) would read badly beside a line saying they're safe in the Cloud. */
+const NO_MOVE_POPUP = "grok-move-2026-11";
const CLEAN = "clean-workspace";
export const cleanWorkspaceDir = (dataDir) => `${dataDir}-clean`;
@@ -25,7 +27,7 @@ export const cleanWorkspaceDir = (dataDir) => `${dataDir}-clean`;
/** A clean workspace's first config: never the new-user setup, which would read as the person's bots being gone. Connecting
* an AI isn't part of this: the page's line offers it while none works (HomeLine). */
export function cleanWorkspaceConfig(language = null, now = new Date()) {
- return { ...(typeof language === "string" && language ? { language } : {}), onboarding: { completedAt: now.toISOString(), version: WELCOME_VERSION, hintsSeen: [QUIET_HINT] } };
+ return { ...(typeof language === "string" && language ? { language } : {}), onboarding: { completedAt: now.toISOString(), version: WELCOME_VERSION, hintsSeen: [QUIET_HINT, NO_MOVE_POPUP] } };
}
/**
@@ -44,7 +46,9 @@ export function cleanWorkspaceConfig(language = null, now = new Date()) {
export function createCleanWorkspace({ dataDir, running, swap, allowed = () => true, changed = () => {}, log = () => {}, fs = nodeFs }) {
const folder = () => cleanWorkspaceDir(dataDir());
const active = () => running() === folder();
- let held = 0;
+ let held = 0, swapping = false;
+ /** This computer's own copy is the server that answers now: not the clean workspace, and not on its way between them. */
+ const ownCopy = () => !active() && !swapping;
let queue = Promise.resolve();
/** One swap at a time: a second would stop the server the first just started. */
const inTurn = (work) => {
@@ -62,7 +66,8 @@ export function createCleanWorkspace({ dataDir, running, swap, allowed = () => t
catch (error) { if (error?.code !== "EEXIST") throw error; }
}
async function swapTo(dir) {
- const done = await swap(dir).catch((error) => ({ ok: false, error }));
+ swapping = true;
+ const done = await swap(dir).catch((error) => ({ ok: false, error })).finally(() => { swapping = false; });
if (done?.ok !== true) { log(`clean workspace: could not start on ${dir} (${done?.error?.message ?? done?.error ?? "no answer"})`); return false; }
changed();
return true;
@@ -80,6 +85,7 @@ export function createCleanWorkspace({ dataDir, running, swap, allowed = () => t
return {
active,
+ ownCopy,
marker,
/** Opens the clean workspace; true once it runs. False when it can't, and the window says why as before. A named local
* environment the person chose is no frozen copy, so it stays. */
@@ -103,7 +109,7 @@ export function createCleanWorkspace({ dataDir, running, swap, allowed = () => t
* files say, and everything else refused. */
realCopy(request) {
return async (route, init) => {
- if (!active()) return request(route, init);
+ if (ownCopy()) return request(route, init);
if ((init?.method ?? "GET").toUpperCase() === "GET") {
if (route === "/api/move/freeze") return Response.json(marker());
if (route === "/.well-known/openmausbot/environment") {
diff --git a/electron/clean-workspace.node-test.mjs b/electron/clean-workspace.node-test.mjs
index 7c69e0016c..f54bebc973 100644
--- a/electron/clean-workspace.node-test.mjs
+++ b/electron/clean-workspace.node-test.mjs
@@ -170,20 +170,36 @@ const ready = (extra = {}) => ({ status: "connected", account: owner, deviceId:
const done = (extra = {}) => ({ v: 1, phase: "done", cloud: { origin: CLOUD, account: owner.id, machine: CLOUD }, startedAt: 1, doneAt: 2, frozenAt: 2, version: "0.1.140", reported: "d1", lent: true, phoneStopped: true, ...extra });
const onClean = (w) => w.requests.filter(([folder]) => folder === w.cleanDir);
-test("a top-up can't read the clean workspace: it waits, and nothing of it reaches the person's Cloud", async (t) => {
- const w = moved(t, { state: ready(), journal: done() });
+test("a top-up can't read the clean workspace: it waits, with no hour's penalty, and goes once this computer's own copy answers", async (t) => {
+ const w = moved(t, { state: ready(), journal: done({ doneAt: Date.now() }) });
await w.clean.enter();
await w.main.kick();
assert.deepEqual(onClean(w), []);
assert.equal(w.journal.version, "0.1.140", "the top-up didn't count as made");
- assert.ok(w.journal.retryAt, "and goes again later");
+ assert.equal(w.journal.retryAt, undefined, "and isn't put off");
await w.clean.leave();
w.requests.length = 0;
- w.journal = done();
await w.main.kick();
assert.deepEqual(w.requests[0], [w.dataDir, "GET", "/api/cloud-send?move=1"], "its own copy running, the same top-up does read this computer's server");
});
+test("while the server is on its way between the two, nothing reaches it, and a top-up waits for it", async (t) => {
+ const w = moved(t, { state: ready(), journal: done() });
+ let finish;
+ const started = new Promise((resolve) => { finish = resolve; });
+ const clean = createCleanWorkspace({ dataDir: () => w.dataDir, running: () => w.running, swap: async (dir) => { await started; w.running = dir; return { ok: true }; } });
+ const entering = clean.enter();
+ await new Promise((resolve) => setImmediate(resolve));
+ assert.equal(clean.ownCopy(), false, "its server is stopped, or starting");
+ await assert.rejects(clean.realCopy(w.request)("/api/bots?messages=0"), { code: "clean-workspace" });
+ assert.deepEqual(w.requests, []);
+ finish();
+ await entering;
+ assert.equal(clean.ownCopy(), false, "the clean workspace runs");
+ await clean.leave();
+ assert.equal(clean.ownCopy(), true);
+});
+
test("settling can't record this computer as lent from the clean workspace's empty bot list", async (t) => {
const w = moved(t, { state: { status: "signed-out" }, journal: done({ lent: undefined }) });
await w.clean.enter();
@@ -248,6 +264,13 @@ test("a clean workspace's first config carries the language and that the setup w
assert.equal(cleanWorkspaceConfig().language, undefined);
});
+test("nothing pops up to bring bots here beside a line saying they're safe in the Cloud: the hint is the one that popup looks for", () => {
+ const notices = readFileSync(new URL("../src/lib/notices.ts", import.meta.url), "utf8");
+ const popup = /GROK_MOVE_NOTICE = "([^"]+)"/u.exec(notices)?.[1];
+ assert.ok(popup);
+ assert.equal(cleanWorkspaceConfig().onboarding.hintsSeen.includes(popup), true);
+});
+
test("no lending from the clean workspace: nothing is lent or asked while it runs, and a grant only pauses, so it goes on after", async (t) => {
const w = computer(t);
const env = { id: "c", origin: CLOUD, cloud: { id: "c" } };
diff --git a/electron/main.mjs b/electron/main.mjs
index a3369f3856..182e4e4a5f 100644
--- a/electron/main.mjs
+++ b/electron/main.mjs
@@ -1468,7 +1468,7 @@ function sharingController() {
return computerSharing;
}
-const cleanWorkspace = createCleanWorkspace({ dataDir: desktopDataDir, running: () => runningDataDir, swap: dir => switchLocalEnvironmentTo(dir, LOCAL_ID, true), allowed: () => app.isPackaged && !desktopRemoteAccess, changed: () => computerSharing?.cloudChanged(), log: slog }); const lendingTarget = createLendingTarget({ account: () => (cleanWorkspace.active() ? null : cloudAccount), environments: () => environmentsState.environments, ownHome: () => ownHome?.home() ?? null });
+const cleanWorkspace = createCleanWorkspace({ dataDir: desktopDataDir, running: () => runningDataDir, swap: dir => switchLocalEnvironmentTo(dir, LOCAL_ID, true), allowed: () => app.isPackaged && !desktopRemoteAccess, changed: () => { computerSharing?.cloudChanged(); void oneHome.kick(); }, log: slog }); const lendingTarget = createLendingTarget({ account: () => (cleanWorkspace.active() ? null : cloudAccount), environments: () => environmentsState.environments, ownHome: () => ownHome?.home() ?? null });
const screenControl = createScreenControl({ connection: () => cuaReady, remote: () => Boolean(desktopRemoteAccess), request: requestComputerUse, log: slog });
let screenAskedAt = -Infinity;
/** Computer control starts again, as Settings' Retry does, which asks macOS for what it never asked; at most every 10 minutes. */
diff --git a/electron/one-home-main.mjs b/electron/one-home-main.mjs
index 9222c6c93f..7f0a626e48 100644
--- a/electron/one-home-main.mjs
+++ b/electron/one-home-main.mjs
@@ -256,6 +256,7 @@ export function installOneHome({ localRequest: anyServer, clean = null, account,
return Boolean(client?.reportKept && mine && await client.reportKept({ installation: mine }));
},
lastInput: typed,
+ ownCopy: () => clean?.ownCopy() ?? true,
onChange: () => { send.publish(); report.changed(); },
});
diff --git a/electron/one-home.mjs b/electron/one-home.mjs
index 4a5159fc39..f5964da5b2 100644
--- a/electron/one-home.mjs
+++ b/electron/one-home.mjs
@@ -381,7 +381,8 @@ export function createOneHome(deps) {
async function steady(journal, cloud, waiting) {
let next = await settle(journal, cloud);
if (cloud?.ended) return ended(next, cloud);
- if (!waiting && !next.forgot && deps.version && next.version !== deps.version && cloud?.ready) {
+ // Not while this computer's own copy isn't the server answering: it goes as soon as it is, rather than an hour later.
+ if (!waiting && !next.forgot && deps.version && next.version !== deps.version && cloud?.ready && deps.ownCopy?.() !== false) {
try { await deps.send.move({ final: true }); next = write({ ...next, version: deps.version, retryAt: undefined }); }
catch (error) { log(`one home: the top-up waits (${error?.message ?? error})`); next = write({ ...next, retryAt: now() + HOUR }); }
}
diff --git a/src/components/AccountMenu.test.ts b/src/components/AccountMenu.test.ts
index 073b6b1bb4..44deaf9766 100644
--- a/src/components/AccountMenu.test.ts
+++ b/src/components/AccountMenu.test.ts
@@ -1,5 +1,5 @@
import { afterEach, expect, it, vi } from "vitest";
-import { accountMenuItems } from "./AccountMenu";
+import { accountMenuItems, cloudRowLabel } from "./AccountMenu";
afterEach(() => vi.unstubAllGlobals());
const signOut = vi.fn();
@@ -24,3 +24,9 @@ it("another place's page shows no address, only the row that asks main for the s
items[0].onSelect();
expect(openSheet).toHaveBeenCalled();
});
+
+it("the MausBot Cloud row says Sign in while nobody is signed in here; any other page keeps its name", () => {
+ expect(cloudRowLabel({ active: null, others: [] })).toBe("Sign in");
+ expect(cloudRowLabel({ active: { id: "b", email: "[email protected]" }, others: [] })).toBe("MausBot Cloud");
+ expect(cloudRowLabel(null)).toBe("MausBot Cloud");
+});
diff --git a/src/components/AccountMenu.tsx b/src/components/AccountMenu.tsx
index b126a82dfd..d37a16e12a 100644
--- a/src/components/AccountMenu.tsx
+++ b/src/components/AccountMenu.tsx
@@ -40,6 +40,12 @@ export function useAccounts(): AccountsAccess {
};
}
+/** The You menu's row for the MausBot Cloud page, on this app's own page: Sign in while nobody is signed in here, so whoever was
+ * told to sign in finds the words. Any other page knows nothing of who is signed in. */
+export function cloudRowLabel(view: AccountsView | null): string {
+ return t(view && !view.active ? "accounts.signIn" : "settings.section.cloudAccount");
+}
+
/** The You menu's last rows. On another page, one row that opens the sheet. Signed out: nothing, as Settings has the sign-in. */
export function accountMenuItems({ view, openSheet, signOut }: AccountsAccess): SidebarMenuItem[] {
if (openSheet) return [{ key: "accounts-sheet", label: t("accounts.manage"), icon: <UserRound size={18} />, onSelect: openSheet }];
diff --git a/src/components/HomeLine.test.ts b/src/components/HomeLine.test.ts
index 72c4a1d795..2e59ac8648 100644
--- a/src/components/HomeLine.test.ts
+++ b/src/components/HomeLine.test.ts
@@ -63,9 +63,9 @@ it("the clean workspace's line says the bots are safe in their Cloud, on every l
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."));
+ await vi.waitFor(() => expect(host.querySelector("[data-home-line='clean']")?.textContent).toBe("Your bots are in the 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" })).toBe("Your bots are in the Cloud. Sign in to get them.");
});
it("with the new-user setup skipped, the clean workspace still offers connecting an AI while none is ready", async () => {
diff --git a/src/components/SidebarProfileMenu.tsx b/src/components/SidebarProfileMenu.tsx
index 9b6622abc3..2289034b70 100644
--- a/src/components/SidebarProfileMenu.tsx
+++ b/src/components/SidebarProfileMenu.tsx
@@ -23,7 +23,7 @@ import {
Zap,
} from "lucide-react";
-import { accountMenuItems, useAccounts } from "./AccountMenu";
+import { accountMenuItems, cloudRowLabel, useAccounts } from "./AccountMenu";
import { AccountMoveStatus, useAccountMove, type AccountMoveKind } from "./AccountMove";
import { InitialsAvatar } from "./Avatar";
import { DiscordIcon } from "./DiscordIcon";
@@ -603,7 +603,7 @@ export function SidebarProfileMenu({ iconOnly = false, rail = false, circle = fa
update: update?.item ?? null,
updateTop: simple ? simpleUpdateTop(update) : null,
move: move.items,
- account: cloudAccount ? t("settings.section.cloudAccount") : null,
+ account: cloudAccount ? cloudRowLabel(accounts.view) : null,
accounts: accountMenuItems(accounts),
...(account ? { simple: {
tools: toolMenuItems({
diff --git a/src/locales/en.json b/src/locales/en.json
index 2dc463d346..b5c9b371b1 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -7056,7 +7056,7 @@
"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.clean": "Your bots are in the Cloud. Sign in 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.",