Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(threads): teach the coordinate_bots call that carries on a closed thread
luishron1233bbef66ef853
diff --git a/server/host/work-thread.test.ts b/server/host/work-thread.test.tsindex 44df8d0204..d2b01cf50b 100644--- a/server/host/work-thread.test.ts+++ b/server/host/work-thread.test.ts@@ -70,8 +70,8 @@ describe("workThreadFor", () => {const post = (thread: string, more: Partial<TaskRecord> = {}) => workThreadFor({ ...store, taskByThread: () => task(thread, undefined, more) },{ botId: "bugfixer", botName: "Bugfixer", fromBotId: "liaison", fromThreadId: "liaison-chat", thread, notice: true, answering: undefined, also: () => true, reach: () => true, any: true });expect(post("run-0")?.threadId).toBe("run-0");- expect(() => post("closed", { closedBy: {} as TaskRecord["closedBy"] })).toThrow(/is not an open thread of Bugfixer/);- expect(() => post("archived", { archivedAt: 1 })).toThrow(/is not an open thread of Bugfixer/);+ expect(() => post("closed", { closedBy: {} as TaskRecord["closedBy"] })).toThrow(/^"closed" is not an open thread of Bugfixer, and post_to_thread reaches only open threads\. To carry on its subject, send it with coordinate_bots, e\.g\. \{"bot_ids": \["Bugfixer"\], "thread": "standing", "message": "<the subject and what to do>"\}/);+ expect(() => post("archived", { archivedAt: 1 })).toThrow(/^"archived" is not an open thread of Bugfixer, and post_to_thread reaches only open threads\. To carry on its subject, send it with coordinate_bots/);expect(() => workThreadFor({ ...store, taskByThread: () => undefined }, { botId: "bugfixer", botName: "Bugfixer", fromBotId: "liaison", fromThreadId: "liaison-chat",thread: "nope", notice: true, answering: undefined, also: () => true, reach: () => true, any: true })).toThrow(/is not an open thread of Bugfixer/);expect(() => workThreadFor({ ...store, taskByThread: () => task("x") }, { botId: "bugfixer", botName: "Bugfixer", fromBotId: "liaison", fromThreadId: "liaison-chat",@@ -79,6 +79,26 @@ describe("workThreadFor", () => {});});+describe("a closed thread the sender opened", () => {+ const closedAt = { botId: "bugfixer", name: "Bugfixer", at: 5 };+ const closed = (oneShot: boolean) => ({ ...store, taskByThread: () => task("audit", { ...by("liaison", "Liaison", "liaison-chat")!, ...(oneShot ? { oneShot: true as const } : {}) },+ { closedBy: closedAt, ...(oneShot ? { archivedAt: 5, closedBy: { ...closedAt, botId: "liaison" } } : {}) }) });+ const send = (oneShot: boolean, any: boolean) => workThreadFor(closed(oneShot), { botId: "bugfixer", botName: "Bugfixer", fromBotId: "liaison", fromThreadId: "liaison-chat",+ thread: "audit", notice: false, answering: undefined, also: () => true, reach: () => true, ...(any ? { any } : {}) });++ it("carries on with coordinate_bots and that thread id, closed or archived by its own result", () => {+ expect(send(false, false)?.threadId).toBe("audit");+ expect(send(true, false)?.threadId).toBe("audit");+ });++ it("is refused by post_to_thread with the coordinate_bots call that carries it on", () => {+ for (const oneShot of [false, true]) {+ expect(() => send(oneShot, true)).toThrow('"audit" is closed, and post_to_thread reaches only open threads. To carry on its subject with Bugfixer, send it there with ' ++ 'coordinate_bots, e.g. {"bot_ids": ["Bugfixer"], "thread": "audit", "message": "<what to carry on>"}: the thread opens again with its history');+ }+ });+});+describe("besideBusy", () => {// Liaison's chat "liaison-chat" opened two work threads on Bugfixer earlier: "standing" and "spare".const opened = [task("standing", by("liaison", "Liaison", "liaison-chat")), task("spare", by("liaison", "Liaison", "liaison-chat"))];diff --git a/server/host/work-thread.ts b/server/host/work-thread.tsindex 7a24b637a4..e09840bf9f 100644--- a/server/host/work-thread.ts+++ b/server/host/work-thread.ts@@ -22,11 +22,15 @@ export function workThreadFor(store: Pick<Store, "workThread" | "taskByThread">,const allowed = task !== undefined && also(task);const usable = allowed && task.archivedAt === undefined;const reusable = usable || (allowed && archivedOnResult(task));+ const yours = reusable && task.openedBy?.botId === input.fromBotId && !task.openedBy.roomLane;if (input.any) {if (usable && !task.closedBy) return task;+ const send = (to: string, what: string) => `coordinate_bots, e.g. {"bot_ids": [${JSON.stringify(input.botName)}], "thread": ${JSON.stringify(to)}, "message": "${what}"}`;+ if (yours) throw new Error(`"${thread}" is closed, and post_to_thread reaches only open threads. To carry on its subject with ${input.botName}, send it there with ${send(thread, "<what to carry on>")}: the thread opens again with its history`);+ if (task && allowed) throw new Error(`"${thread}" is not an open thread of ${input.botName}, and post_to_thread reaches only open threads. To carry on its subject, send it with ${send("standing", "<the subject and what to do>")}, or use a threadId list_threads shows open on them`);throw new Error(`"${thread}" is not an open thread of ${input.botName}: use a threadId list_threads shows on them`);}- if (reusable && task.openedBy?.botId === input.fromBotId && !task.openedBy.roomLane) return task;+ if (yours) return task;const handedWork = usable && input.answering?.botId === botId && input.answering.threadId === thread;if (handedWork && input.notice) return task;if (handedWork) throw new Error(`"${thread}" handed you work: answer it there with reply "none", a one-way notice; it cannot be given new work`);