Skip to content

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

The clean workspace, after its first real-app run: rail, sign in, popup and top-up

milind-sonief7a95f98c1a
diff --git a/electron/chrome-rail.mjs b/electron/chrome-rail.mjs
index 2700a0e0cb..02ef3716ec 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() } });
@@ -104,8 +107,9 @@ export function createChromeRail({ createView, preload, args, url, wanted, prefs
contents.on("will-navigate", stay);
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}`));
+ contents.on("did-finish-load", () => { unloaded = false; contents.send("rail:framed", framed); });
+ contents.on("did-fail-load", (_event, code, _description, _url, mainFrame) => { if (mainFrame && code !== ABORTED) unloaded = true; });
+ load(contents);
return view;
};
const rail = {
@@ -138,6 +142,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..f6e2bcd5ef 100644
--- a/electron/chrome-rail.node-test.mjs
+++ b/electron/chrome-rail.node-test.mjs
@@ -355,3 +355,28 @@ 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(), 2, "a page that did load afterwards 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..62d7d7f3c8 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) => {
+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() });
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 42c6f31517..338dd50a41 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 }); }
}