Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Keep the minute session read for any move under way, and spread the report's 6-hour off wait
milind-soni1285b539ee5d
diff --git a/electron/main.mjs b/electron/main.mjsindex 247e6a324c..f7efe5f980 100644--- a/electron/main.mjs+++ b/electron/main.mjs@@ -801,7 +801,7 @@ function ensureCloudAccount() {cloudAccount = createCloudAccountClient({store: cloudAccountStore(),platform: process.platform, deviceName: os.hostname().slice(0, 100) || "My computer", appVersion: app.getVersion(), origin: cloudTarget(process.env).origin,- openBrowser: url => shell.openExternal(url), awaitingWake: () => cloudPower.awaiting(), warn: slog, attended: () => { try { return BrowserWindow.getFocusedWindow() !== null || oneHome.holding() !== null; } catch { return true; } },+ openBrowser: url => shell.openExternal(url), awaitingWake: () => cloudPower.awaiting(), warn: slog, attended: () => { try { return BrowserWindow.getFocusedWindow() !== null || oneHome.underWay(); } catch { return true; } },onState: state => {cloudSync.accountChanged(state.account?.id ?? null); rememberCloudHome(state);rememberedHome = rememberedCloudHome(rememberedHome, state);diff --git a/electron/move-status.mjs b/electron/move-status.mjsindex 423c15b752..701d548b31 100644--- a/electron/move-status.mjs+++ b/electron/move-status.mjs@@ -24,7 +24,7 @@ export const MOVE_STATUS_IDLE_HEARTBEAT_MS = 6 * 3_600_000;export const MOVE_STATUS_SETTLE_MS = 5_000;/** At most one report a minute, whatever changes. */export const MOVE_STATUS_GAP_MS = 60_000;-/** An Admin that doesn't take reports yet (404) is asked again after this long. */+/** An Admin that doesn't take reports yet (404) is asked again after this long (spread ±20%). */export const MOVE_STATUS_OFF_MS = 6 * 3_600_000;const record = (value) => value !== null && typeof value === "object" && !Array.isArray(value);@@ -153,7 +153,7 @@ export function createMoveStatusReport({ status, send, signIn, now = Date.now, llet next = every;try {if (await send(body)) sent = { key, who, at, every };- else { offUntil = at + MOVE_STATUS_OFF_MS; next = MOVE_STATUS_OFF_MS; }+ else { next = jittered(MOVE_STATUS_OFF_MS, random); offUntil = at + next; }failing.ok();} catch (error) {next = failing.failed(error) - now();diff --git a/electron/move-status.node-test.mjs b/electron/move-status.node-test.mjsindex 9c06bc7c34..cbd736238d 100644--- a/electron/move-status.node-test.mjs+++ b/electron/move-status.node-test.mjs@@ -438,6 +438,15 @@ test("the move's own changes send the report by themselves, a moment later", asy} finally { f.main.close(); }});+test("a move under way keeps the session read every minute (underWay); none, a finished one, a paused one or one come back does not", async () => {+ const cases = [[null, false], [journalOf(), true], [journalOf({ phase: "wait" }), true], [journalOf({ phase: "keeping" }), true], [journalOf({ phase: "home-again" }), true],+ [journalOf({ paused: true }), false], [journalOf({ phase: "done" }), false], [journalOf({ phase: "back" }), false]];+ for (const [journal, under] of cases) {+ const f = installed({ state: signedIn(), journal });+ try { assert.equal(f.main.underWay(), under, JSON.stringify(journal?.phase ?? null)); } finally { f.main.close(); }+ }+});+test("reporting never touches the move: a send that fails or never answers changes nothing and holds nothing up", async () => {for (const reportMoveStatus of [async () => { throw new Error("Cloud request failed."); }, () => new Promise(() => {}), () => { throw new Error("sync"); }]) {const f = installed({ state: signedIn({ machine: { status: "ready", origin: CLOUD } }), reportMoveStatus });diff --git a/electron/one-home-main.d.mts b/electron/one-home-main.d.mtsindex c3fde29b32..8ffda38447 100644--- a/electron/one-home-main.d.mts+++ b/electron/one-home-main.d.mts@@ -49,6 +49,8 @@ export function installOneHome(deps: Omit<SendDeps, "local" | "move" | "moveSesskeep: { state(): KeepHereState; set(on: boolean): Promise<void> };/** Why the account signed in can't be left now, else null. */holding(): "moving" | null;+ /** A move to My Cloud, its way home, or a bot's move is under way: the session is read every minute for it. */+ underWay(): boolean;kick(): Promise<void>;away(): boolean;view(): OneHomeView | null;diff --git a/electron/one-home-main.mjs b/electron/one-home-main.mjsindex ac16c48290..5e4af46faa 100644--- a/electron/one-home-main.mjs+++ b/electron/one-home-main.mjs@@ -368,6 +368,10 @@ export function installOneHome({ localRequest: anyServer, clean = null, account,keep: { state: keepState, set: (on) => home.keep(on === true) },/** Why the account signed in can't be left now: its move, or a bot of its own moving into a team, is under way. */holding: () => { const bot = teamMove.view()?.phase; return home.moving() || (bot && !["done", "failed"].includes(bot)) || botMove.moving().length ? "moving" : null; },+ /** A move to My Cloud, its way home, or a bot's move is under way (any journal phase but done and back, unless paused): the+ * session is read every minute for it, as when the window is in front (cloud-account.mjs `attended`). */+ underWay: () => { const moving = parseJournal(journal.read()); const bot = teamMove.view()?.phase;+ return Boolean(moving && !moving.paused && !["done", "back"].includes(moving.phase)) || Boolean(bot && !["done", "failed"].includes(bot)) || botMove.moving().length > 0; },/** Goes on with the move, and with any bot moving into a team: at launch, and whenever the MausBot Cloud sign-in changes. */kick: () => {void teamMove.kick();