Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge #4478 at 15242586e
milind-sonic996925c1b80
diff --cc electron/one-home.mjsindex 33119044ba,a89a2dcb52..a301ff3898--- a/electron/one-home.mjs+++ b/electron/one-home.mjs@@@ -357,11 -376,9 +376,11 @@@ export function createOneHome(deps)} finally { await session?.close().catch(() => {}); }const sent = deps.send.snapshot?.();const held = (sent?.whole?.result?.notes ?? []).filter((note) => note?.kind === "held" && typeof note.connection === "string").map((note) => note.connection);- const left = notCarried(sent, true);+ const left = [...notCarried(sent, true), ...(Array.isArray(journal.stuck) ? journal.stuck : [])];- const done = write({ ...journal, phase: "done", switched, doneAt: now(), version: deps.version ?? null, phone: deps.phone?.paired() === true, held, ...(left.length ? { left } : {}),+ const stayed = (sent?.whole?.result?.notes ?? []).filter((note) => note?.kind === "stayed" && typeof note.connection === "string").slice(0, NAMED_MAX)+ .map((note) => ({ name: note.connection, ...(typeof note.needs === "string" ? { needs: note.needs } : {}) }));+ const done = write({ ...journal, phase: "done", switched, doneAt: now(), version: deps.version ?? null, phone: deps.phone?.paired() === true, held, ...(left.length ? { left } : {}), ...(stayed.length ? { stayed } : {}),- error: undefined, failingSince: undefined, retryAt: undefined, tries: undefined, failure: undefined });+ error: undefined, failingSince: undefined, retryAt: undefined, tries: undefined, failure: undefined, frozenTries: undefined, gapKey: undefined, gaps: undefined, stuck: undefined });await settle(done);deps.openHome?.();return null;diff --cc electron/one-home.node-test.mjsindex 6bfbbed1db,bc785ee7f4..d43f60ab0d--- a/electron/one-home.node-test.mjs+++ b/electron/one-home.node-test.mjs@@@ -42,9 -42,10 +42,10 @@@ function world({ cloud = {}, switchesconst failure = moves.shift();if (failure) throw failure;},- async check() { w.checked++; return { ok: checks.shift() ?? true }; },+ // A check answers `true`/`false`, or a whole report (cloud-send.mjs `check`).+ async check() { w.checked++; const next = checks.shift(); return next && typeof next === "object" ? next : { ok: next ?? true }; },switches: () => switches,- snapshot: () => ({ running: w.running ?? null, whole: { result: { notes: [{ kind: "held", connection: "OpenRouter" }], failed: w.failed ?? [] } } }),+ snapshot: () => ({ running: w.running ?? null, whole: { result: { notes: w.notes ?? [{ kind: "held", connection: "OpenRouter" }], failed: w.failed ?? [] } } }),},local: {async freeze() {@@@ -203,17 -204,80 +204,91 @@@ test("a check that still finds things m{ label: "Reply to email", error: "This app automation stays on the computer it came from." }] } });});+test("a move done while a connector stayed on this computer names it on the done line, with what it needs", async () => {+ const w = world();+ w.notes = [{ kind: "stayed", connection: "fetch", needs: "uvx" }, { kind: "stayed", connection: "easy" }, { kind: "held", connection: "OpenRouter" }];+ await w.home.kick();+ assert.equal(w.journal.phase, "done");+ assert.deepEqual(w.home.view().stayed, [{ name: "fetch", needs: "uvx" }, { name: "easy" }]);+ assert.deepEqual(w.home.view().held, ["OpenRouter"]);+ w.notes = [];+ assert.deepEqual(w.home.view().stayed, [{ name: "fetch", needs: "uvx" }, { name: "easy" }], "kept with the move, not read again");+});++ /** A check that finds the same things missing on every pass: one attachment and one bot's memory note that sending again+ * never carries (a file gone from this computer, a note My Cloud can't keep). */+ const stuckReport = (extra = {}) => ({ ok: false, gaps: { items: [], memory: [{ bot: "b1", path: "memory/notes.md" }], conversations: [] },+ chats: [{ threadId: "t1", missing: 2, unstamped: 0, path: "equal" }], attachments: ["a1.mp3"], secrets: { equal: [], differs: [], missing: [] },+ names: { b1: "Scout" }, owners: { t1: "b1" }, ...extra });++ test("what sending again never carries stays on this computer once two tries ended the same way, and the rest moves", async () => {+ // Seen on a customer's PC (0.1.140): the check found the same things missing on every pass, so the move failed 94 times+ // in a week, freezing the computer each hour, and the line only said "Some of this computer's things did not reach My Cloud".+ const w = world({ checks: [stuckReport(), stuckReport(), stuckReport(), stuckReport(), stuckReport(), stuckReport()] });+ await w.home.kick();+ assert.equal(w.journal.phase, "copy", "the first try that ends this way still goes again: My Cloud may have been busy");+ assert.equal(w.journal.failure.code, "incomplete");+ assert.equal(w.journal.gaps, "1 memory, 1 chats (2 rows), 1 attachments");+ assert.equal(w.home.view().failing.error, INCOMPLETE, "the line says what happens next, not only that it failed");+ assert.equal(w.server.frozen, false);++ w.advance(FROZEN_RETRY_MS);+ await w.tick();+ assert.equal(w.journal.phase, "done", "the next try ending the same way moves the rest");+ assert.equal(w.server.frozen, true);+ assert.deepEqual(w.journal.left, [+ { label: "Scout", error: "One of its memory notes didn't reach My Cloud." },+ { label: "Scout", error: "Part of one chat didn't reach My Cloud." },+ { label: "An attachment", error: "It didn't reach My Cloud." },+ ]);+ assert.deepEqual(w.home.view().left, w.journal.left, "the done line says what stayed here");+ for (const key of ["gapKey", "gaps", "stuck", "frozenTries", "failure"]) assert.equal(w.journal[key], undefined, `${key} is cleared once done`);+ });++ test("a move keeps trying while sending again carries something, or something new goes missing", async () => {+ // Pass by pass the gaps shrink: sending again is working, so this is no reason to leave anything behind.+ const shrinking = world({ checks: [stuckReport(), stuckReport({ attachments: [] }), stuckReport({ attachments: [] }),+ stuckReport(), stuckReport({ attachments: [] }), stuckReport({ attachments: [] })] });+ shrinking.journal = { v: 1, phase: "copy", cloud: { origin: CLOUD, account: "acct-1", machine: CLOUD }, failure: { phase: "check", code: "incomplete", count: 3, since: 1, at: 1 } };+ await shrinking.relaunch().kick();+ assert.equal(shrinking.journal.phase, "copy");+ assert.equal(shrinking.journal.failure.code, "incomplete");++ // The try before found other things missing than this one: both go again.+ const other = world({ checks: [stuckReport(), stuckReport(), stuckReport()] });+ other.journal = { v: 1, phase: "copy", cloud: { origin: CLOUD, account: "acct-1", machine: CLOUD }, failure: { phase: "check", code: "incomplete", count: 1, since: 1, at: 1 }, gapKey: "not-these" };+ await other.relaunch().kick();+ assert.equal(other.journal.phase, "copy");+ assert.notEqual(other.journal.gapKey, "not-these");++ // A journal an older app wrote, failing this way with no gaps kept: the first try that ends the same way moves the rest.+ const older = world({ checks: [stuckReport(), stuckReport(), stuckReport()] });+ older.journal = { v: 1, phase: "copy", cloud: { origin: CLOUD, account: "acct-1", machine: CLOUD }, failure: { phase: "check", code: "incomplete", count: 94, since: 1, at: 1 }, tries: 94 };+ await older.relaunch().kick();+ assert.equal(older.journal.phase, "done");+ assert.equal(older.journal.left.length, 3);+ });++ test("a move that keeps failing frozen waits twice as long each time, up to half a day, so this computer is not stopped every hour", async () => {+ const w = world({ moves: Array.from({ length: 12 }, (_, at) => (at % 2 ? new Error("My Cloud could not add the chats.") : undefined)) });+ const waits = [];+ for (let attempt = 0; attempt < 6; attempt++) {+ await w.tick();+ waits.push((w.journal.retryAt - w.now()) / FROZEN_RETRY_MS);+ w.advance(w.journal.retryAt - w.now());+ }+ assert.deepEqual(waits, [1, 2, 4, 8, 12, 12]);+ assert.equal(FROZEN_RETRY_MAX_MS, 12 * FROZEN_RETRY_MS);+ assert.equal(w.server.freezes, 6, "one freeze a try, never more");+ await w.home.retry();+ assert.equal(w.server.freezes, 7, "Try again still goes at once");++ const unnamed = world({ checks: [false, false, false, false, false, false] });+ unnamed.journal = { v: 1, phase: "copy", cloud: { origin: CLOUD, account: "acct-1", machine: CLOUD }, failure: { phase: "check", code: "incomplete", count: 2, since: 1, at: 1 } };+ await unnamed.relaunch().kick();+ assert.equal(unnamed.journal.phase, "copy", "a check that can't say what it misses never leaves anything behind");+ });+test("a move done without what My Cloud refused for good names it on the done line", async () => {const w = world();w.failed = [{ key: "app-event:e1", kind: "app-event", label: "Reply to email", error: "This app automation stays on the computer it came from.", final: true }];