Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Merge the move check's review fixes into the bot picker
Milind Soni776e750fdafa
diff --cc electron/cloud-send-main.d.mtsindex 5a3455412e,85cfb85b95..d184208969--- a/electron/cloud-send-main.d.mts+++ b/electron/cloud-send-main.d.mts@@@ -29,8 -28,8 +29,8 @@@ export function installCloudSend(deps:receive(proc: unknown, message: unknown): boolean;/** This computer's server's private port, asked as a send asks it: another move's sends share it. */handoff(what: { kind: string; [key: string]: unknown }): Promise<any>;- move(options?: { final?: boolean }): Promise<CloudSendOutcome>;- check(options?: { stopped?(): boolean }): Promise<CloudMoveCheck>;+ move(options?: { final?: boolean; scope?: string }): Promise<CloudSendOutcome>;- check(options?: { scope?: string }): Promise<CloudMoveCheck>;++ check(options?: { scope?: string; stopped?(): boolean }): Promise<CloudMoveCheck>;switches(): Record<string, boolean>;snapshot(): CloudSendSnapshot;publish(): void;diff --cc electron/cloud-send.d.mtsindex 7c6d98698c,9ccc31fbbb..771f78fb2e--- a/electron/cloud-send.d.mts+++ b/electron/cloud-send.d.mts@@@ -229,7 -212,8 +229,8 @@@ export function createCloudSend(deps:/** `reason: "move"`: everything this computer has, apps and keys first; `final`: the pass after this computer stopped,* which carries the sign-ins that refresh themselves and lets go of this computer's copies. */send(options?: { keys?: string[] | null; force?: string[]; reason?: string; final?: boolean }): Promise<CloudSendOutcome>;- check(options?: { scope?: string }): Promise<CloudMoveCheck>;- /** `stopped`: the person stopped the move, so a check waiting for My Cloud ends now. */- check(options?: { stopped?(): boolean }): Promise<CloudMoveCheck>;++ /** `scope`: only the bots a move of some of them carries. `stopped`: the person stopped the move, so a check waiting for My Cloud ends now. */++ check(options?: { scope?: string; stopped?(): boolean }): Promise<CloudMoveCheck>;/** Each automation a move carried ("routine:<id>", "call:<id>", "webhook:<id>", "app-event:<id>") and whether it was* on here when it went. */switches(): Record<string, boolean>;diff --cc electron/cloud-send.mjsindex 90efe23eab,afc106a338..aa3f3e3c44--- a/electron/cloud-send.mjs+++ b/electron/cloud-send.mjs@@@ -897,15 -893,13 +898,15 @@@ export function createCloudSend({ local/** What did not arrive of what a move carried (cloud-send-check.mjs `moveCheck`), over one owner session that counts* as someone using My Cloud; `snapshot().checking` says how far it is. A check that stood still too long fails as- * unanswered, saying whether it got anywhere (`progressed`). */- async function check({ stopped } = {}) {+ * unanswered, saying whether it got anywhere (`progressed`). `scope`: only the bots a move of some of them carries; its+ * credentials are copies this computer goes on using, and are not checked. */- async function check({ scope = null } = {}) {++ async function check({ scope = null, stopped } = {}) {const origin = cloud.origin();if (!origin) throw new CloudSendError("no_cloud", "This computer has no My Cloud yet.");const session = await cloud.open({ move: true }).catch((error) => { throw new CloudSendError("session", sentence(error?.message) ?? "This app could not sign in to My Cloud. Try again.", { cause: error }); });+ localScope = scope;try {- return await moveCheck({ session, kept: entry(origin), persist, localJson, handoff: team || scope ? null : handoff, scoped, now, sleep, patience, takesMove: () => assertTakesMove(session),- return await moveCheck({ session, kept: entry(origin), persist, localJson, handoff: team ? null : handoff, scoped, now, sleep, patience, stopped, takesMove: () => assertTakesMove(session),++ return await moveCheck({ session, kept: entry(origin), persist, localJson, handoff: team || scope ? null : handoff, scoped, now, sleep, patience, stopped, takesMove: () => assertTakesMove(session),refuse: (answer, message) => refusedError("unreachable", answer, message), onStep: (value) => { checking = value; publish(); } });} catch (error) {if (error?.code === "slow") throw Object.assign(new CloudSendError("unreachable", sentence(error.message) ?? "My Cloud did not answer.", { cause: error.cause }), { progressed: error.progressed === true });diff --cc electron/one-home-check.node-test.mjsindex 96c15b09ff,bcd9dd211c..77141138ef--- a/electron/one-home-check.node-test.mjs+++ b/electron/one-home-check.node-test.mjs@@@ -177,21 -177,15 +178,34 @@@ test("a move that waits for another comassert.deepEqual(nuc.timers.map((timer) => timer.ms), [QUEUE_POLL_MS]);});+test("no first move starts while the person is asked which bots go, and it goes on by itself once they say", async () => {+ const clock = newClock();+ let asking = true;+ const c = computer({ clock, choosing: async () => asking });+ await c.home.kick();+ assert.equal(c.journal, null, "nothing has started");+ assert.deepEqual(c.passes, []);+ assert.equal(c.server.freezes, 0);+ assert.deepEqual(c.home.view(), { phase: "choose" });+ asking = false;+ await c.home.kick();+ assert.equal(c.journal.phase, "done");+ assert.deepEqual(c.passes, ["copy", "final"]);++ const failing = computer({ clock, choosing: async () => { throw new Error("this computer's server did not answer"); } });+ await failing.home.kick();+ assert.equal(failing.journal.phase, "done", "a question that can't be asked never holds a move back");+});+++ test("a check is told when the person stops the move, and a failed one lifts the freeze before it lets go of My Cloud", async () => {+ const clock = newClock();+ const order = [];+ const lease = cloudLease(() => clock.now);+ const answer = lease.answer;+ lease.answer = (body) => { if (body.release) order.push(c.server.frozen ? "released frozen" : "released thawed"); return answer(body); };+ const c = computer({ clock, lease, checks: [Object.assign(new Error("My Cloud did not answer."), { cause: timeout() })] });+ await c.home.kick();+ assert.equal(typeof c.checkOptions.stopped, "function");+ assert.equal(c.checkOptions.stopped(), false);+ assert.ok(order.includes("released thawed") && !order.includes("released frozen"), order.join());+ });diff --cc server/cloud-send-manifest.tsindex 57bf8d3391,b861a9be0e..70fa60300d--- a/server/cloud-send-manifest.ts+++ b/server/cloud-send-manifest.ts@@@ -4,8 -4,7 +4,8 @@@import type { ChatStore } from "./cloud-chat-merge.ts";import { listBotFiles, type BotFile } from "./cloud-send-files.ts";import { chatHeads, conversationSettings } from "./cloud-send-chats.ts";- import { attachmentNamesOf } from "./cloud-send-rows.ts";+ import { activeLeaves, attachmentNamesOf } from "./cloud-send-rows.ts";+import { roomGoes } from "./cloud-send-scope.ts";import { automationSwitches, routineRunIds, type MoveKindsDeps } from "./cloud-send-kinds.ts";import { journalIds, memoryFiles, memoryLines, teamsHere } from "./cloud-send-memory.ts";import type { CloudSendSummary } from "./cloud-send.ts";@@@ -71,11 -68,11 +71,12 @@@ export async function cloudSendManifestconst { store } = sources;const sent = [...new Set(summary.items.filter((item) => item.kind === "bot" && item.id).map((item) => item.id!))];const only = sources.bot;- const rooms = only === undefined ? store.groups.filter((room) => !room.dm) : [];+ const chosen = sources.scope;+ const rooms = only === undefined ? store.groups.filter((room) => !room.dm && (!chosen || roomGoes(room, chosen, (id) => store.bot(id)))) : [];const counts = sources.heads();+ const leaves = activeLeaves();- const conversations: ManifestConversation[] = chatHeads(only === undefined ? store.bots : store.bots.filter((bot) => bot.id === only), rooms).map((head) => ({+ const conversations: ManifestConversation[] = chatHeads(only !== undefined ? store.bots.filter((bot) => bot.id === only) : chosen ? store.bots.filter((bot) => chosen.has(bot.id)) : store.bots, rooms).map((head) => ({- threadId: head.threadId, ...(head.bot ? { bot: head.bot } : { room: head.room }), rows: counts.get(head.threadId)?.rows ?? 0, newest: head.lastId,+ threadId: head.threadId, ...(head.bot ? { bot: head.bot } : { room: head.room }), rows: counts.get(head.threadId)?.rows ?? 0, newest: head.lastId, leaf: leaves.get(head.threadId) ?? head.lastId,settings: conversationSettings(store, head),}));const attachments = sources.attachments === false ? {} : { attachments: [...attachmentNamesOf(new Set(conversations.map((head) => head.threadId)), sources.dataDir)].sort() };