Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(check-backs): a bot woken by its own check-back can hand work to teammates
AdityaUmale3ffcd56ebe5c
diff --git a/server/check-backs.e2e.test.ts b/server/check-backs.e2e.test.tsindex 081f1fea87..94e239f1bb 100644--- a/server/check-backs.e2e.test.ts+++ b/server/check-backs.e2e.test.ts@@ -1,7 +1,7 @@// A bot checks back later by itself: the fake engine's turn sets a check-back through the real internal route, nobody// presses anything, and at its time the same bot takes a turn in the same conversation with the note. The line in the-// chat moves from pending to started; Cancel on another one stops it. It proves timing, place and provenance, not a-// model's judgement.+// chat moves from pending to started; Cancel on another one stops it. It proves timing, place, provenance and that the+// woken turn may hand work on, not a model's judgement.import { mkdtempSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";@@ -76,6 +76,9 @@ it("wakes the same bot in the same conversation at its time with no human actionconst rows = await transcript();expect(rows.filter((m) => m.card && !m.card.answered && !m.card.dismissed)).toEqual([]);expect(rows.filter((m) => m.role === "user" && String(m.text ?? "").includes("[Check back:"))).toEqual([]);+ const mira = (await api("POST", "/api/bots", { name: "Mira" }, 201)).bot;+ const handed = await api("POST", "/api/internal/coordinate-bots", { botIds: [mira.id], message: "Tell me when CI is green.", reply: "none" }, 200, woken);+ expect(handed.receipts).toMatchObject([{ botId: mira.id, outcome: "queued" }]);const again = await api("POST", "/api/internal/check-backs", { when: "in 5 minutes", note: "look at CI once more" }, 201, woken);expect(again.text).toContain("You will be woken here");diff --git a/server/index.ts b/server/index.tsindex e8b24b6a66..044fc72b63 100644--- a/server/index.ts+++ b/server/index.ts@@ -7427,8 +7427,8 @@ async function beginTurn(onTurnSettled?: () => void;/** The turn's outcome, for a caller that runs it outside any coordinated work. */onSettled?: (outcome: HostTurnResult) => void;- /** A one-on-one goal step: a card continuation that is still its own turn, as a room goal step is. */- goalRunId?: string;+ /** A one-on-one goal step (goalRunId) or a bot's own check-back (ownRoot): a card continuation that is still its own turn, as a room goal step is. */+ goalRunId?: string; ownRoot?: boolean;coordination?: { id: string; resumed: boolean; settle: (outcome: HostTurnResult) => void };/** Carries on a run already started (a hand-off's result, an answered card, a restart): usage caps never refuse it (usage-caps.ts). */ continuesRun?: boolean;/** A person's own send: it may run beside a room turn on another thread. */ allowRoomTurnElsewhere?: boolean;@@ -7629,7 +7629,7 @@ async function beginTurn(directTurnDispatchClaims.set(threadId, { id: dispatchClaimId, botId, threadId, phase: "setup" }); liveTurns.dispatchStarted(threadId);directTurnBots.set(threadId, bot);beginInternalCapabilityGeneration(threadId, dispatchClaimId);- if (!opts?.coordination && !opts?.compactOnly && (!opts?.cardContinuation || opts.goalRunId)) {+ if (!opts?.coordination && !opts?.compactOnly && (!opts?.cardContinuation || opts.goalRunId || opts.ownRoot)) {const opener = handoffOpener({ botId: bot.id, threadId }, threadId);coordinator.beginTurn({ id: dispatchClaimId, address: { botId: bot.id, threadId }, brief: resolvedImages.text,level: approvalModeForTurn(bot, commsDepth > 0, threadId), ...(opener ? { opener } : {}), origin: requestOrigin,@@ -8808,7 +8808,7 @@ ROUTES.push(createCalendarCallRoutes({roomView: (auth, group) => personRooms.groupForAuth(auth, publicGroupState(group)),messages: (threadId) => store.messagesFor(threadId),}));-const checkBacks = createCheckBacks({ dataDir: DATA_DIR, alive: (botId, threadId) => directChatOf(botId, threadId), busy: (botId, threadId) => threadBusy(botId, threadId), line: (record, line, messageId) => writeCheckBackLine(store, record, line, messageId, threadLanguage(record.threadId)), start: async (record, prompt) => { await startTurn(record.botId, prompt, { threadId: record.threadId, cardContinuation: true, origin: record.origin }); }, paused: (error) => [BOT_HELD_CODE, BOT_PAUSED_CODE].includes(String((error as { code?: unknown } | null)?.code)) }); const botWaits = new WaitManager(createWaitHost({ store, directChat: directChatOf, threadBusy, wrote: markTaskContextExternallyUpdated, notify, enqueue: (input) => routines!.enqueueWebhook(input), cloudHome: Boolean(CLOUD_HOME) })); store.onChange((change) => { if (change.type === "bot" && store.bot(change.botId)?.busy) botWaits.noteBotBusy(change.botId); });+const checkBacks = createCheckBacks({ dataDir: DATA_DIR, alive: (botId, threadId) => directChatOf(botId, threadId), busy: (botId, threadId) => threadBusy(botId, threadId), line: (record, line, messageId) => writeCheckBackLine(store, record, line, messageId, threadLanguage(record.threadId)), start: async (record, prompt) => { await startTurn(record.botId, prompt, { threadId: record.threadId, cardContinuation: true, ownRoot: true, origin: record.origin }); }, paused: (error) => [BOT_HELD_CODE, BOT_PAUSED_CODE].includes(String((error as { code?: unknown } | null)?.code)) }); const botWaits = new WaitManager(createWaitHost({ store, directChat: directChatOf, threadBusy, wrote: markTaskContextExternallyUpdated, notify, enqueue: (input) => routines!.enqueueWebhook(input), cloudHome: Boolean(CLOUD_HOME) })); store.onChange((change) => { if (change.type === "bot" && store.bot(change.botId)?.busy) botWaits.noteBotBusy(change.botId); });const recoveryOwners = routines.routineRequestReceiptOwners();if (recoveryOwners.length > 0) {const recoveryThreads = [...new Set(recoveryOwners.map((owner) => owner.threadId))];