Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Board: let a bot withdraw its own question
erywim8b5e98b60d62
diff --git a/docs/team-board.md b/docs/team-board.mdindex 8844ffba0f..855b952558 100644--- a/docs/team-board.md+++ b/docs/team-board.md@@ -68,10 +68,11 @@ A room holds at most 200 items that are not settled.last need is done; a failed or cancelled need readies nothing.- `ready` → `working`: the server gives it to a bot (see Dispatch).- `working` → `done`, `failed`, `needs_person` (the bot asked someone) or back to `ready` (released, or the turn ended- without settling it). `needs_person` → `working` when the person replies, `ready` when a person releases it, or- `cancelled`.+ without settling it). `needs_person` → `working` when the person replies or the bot picks its question back up+ (`resume`), `ready` when a person or the bot releases it, or `cancelled`.- A person may cancel any open item, mark any open item done, release one waiting on a person, and reopen a settled- one (its tries start again from 0, and it waits again if a need is not done). A bot may cancel an open item it made.+ one (its tries start again from 0, and it waits again if a need is not done). A bot may cancel an open item it made,+ and withdraw its own question (`resume` or `release`).- An item that is removed, or whose thread or room is deleted, stops being needed: what waited only on it is ready.Every other move is refused with 409 `board_bad_move`. The rules are `server/board/state.ts`.@@ -121,8 +122,9 @@ cannot reach them.- `board_update` `{ item?, move?, text?, person?, minutes?, labels? }`: the item of this thread unless `item` is given.`done` and `failed` take `text` as the result; `ask` posts `text` as the bot's line in the thread and puts it in theinbox of `person` (a teammate's name or email), else of the person who made the item, and keeps their name on the item; `later` takes `minutes` (1 to- 1,440) and `text` as the note; `release` hands it back to ready. `labels` replaces them. Only the bot holding an item- may settle, ask about or set it aside.+ 1,440) and `text` as the note; `release` hands it back to ready, and `resume` takes the bot's own question back to+ working; both let the holder withdraw a question it no longer needs. `labels` replaces them. Only the bot holding an+ item may settle, ask about, set it aside or withdraw its question.## Routesdiff --git a/server/board/state.test.ts b/server/board/state.test.tsindex bae2175147..01de3f4d9f 100644--- a/server/board/state.test.ts+++ b/server/board/state.test.ts@@ -36,7 +36,8 @@ const ALLOWED: Record<string, Array<[BoardItemState, BoardMove["move"], BoardAct["ready", "take", DISPATCHER], ["working", "done", DISPATCHER], ["working", "failed", DISPATCHER], ["working", "release", DISPATCHER],["needs_person", "resume", DISPATCHER], ["needs_person", "release", DISPATCHER],],- holder: [["working", "done", HOLDER], ["working", "failed", HOLDER], ["working", "ask", HOLDER], ["working", "release", HOLDER], ["working", "later", HOLDER]],+ holder: [["working", "done", HOLDER], ["working", "failed", HOLDER], ["working", "ask", HOLDER], ["working", "release", HOLDER], ["working", "later", HOLDER],+ ["needs_person", "resume", HOLDER], ["needs_person", "release", HOLDER]],person: [["waiting", "done", PERSON], ["ready", "done", PERSON], ["working", "done", PERSON], ["needs_person", "done", PERSON],["needs_person", "release", PERSON],@@ -93,6 +94,20 @@ describe("moves", () => {expect(released.question).toBeUndefined();});+ it("the holder withdraws its own question: resume puts it back to work, release frees it", () => {+ const asked = inState("needs_person");+ const resumed = applyMove(asked, { move: "resume" }, HOLDER, [], T + 2);+ expect(resumed).toMatchObject({ state: "working", holder: { botId: "scout", since: T + 2 } });+ expect(resumed.question).toBeUndefined();+ const released = applyMove(asked, { move: "release" }, HOLDER, [], T + 3);+ expect(released.state).toBe("ready");+ expect(released.holder).toBeUndefined();+ expect(released.question).toBeUndefined();+ for (const move of [{ move: "resume" }, { move: "release" }] as BoardMove[]) {+ expect(() => applyMove(asked, move, OTHER_BOT, [], T + 4)).toThrow(expect.objectContaining({ code: "board_bad_move" }));+ }+ });+it("reopen resets the tries and the result, and waits again when a need is not done", () => {const failed = item({ state: "failed", attempts: 3, result: "Stopped after 3 tries" });const reopened = applyMove(failed, { move: "reopen" }, PERSON, [failed], T + 1);diff --git a/server/board/state.ts b/server/board/state.tsindex 9e43dbaf56..a037e635fa 100644--- a/server/board/state.ts+++ b/server/board/state.ts@@ -123,8 +123,8 @@ function allowed(item: BoardItem, move: BoardMove["move"], actor: BoardActor): bcase "ask": return state === "working" && holds(item, actor);case "later": return state === "working" && holds(item, actor);case "wake": return state === "working" && dispatcher && item.later !== undefined;- case "resume": return state === "needs_person" && dispatcher;- case "release": return state === "working" ? dispatcher || holds(item, actor) : state === "needs_person" && (person || dispatcher);+ case "resume": return state === "needs_person" && (dispatcher || holds(item, actor));+ case "release": return state === "working" ? dispatcher || holds(item, actor) : state === "needs_person" && (person || dispatcher || holds(item, actor));case "cancel": return isOpen(state) && (person || madeIt(item, actor));case "reopen": return !isOpen(state) && person;}diff --git a/server/drivers/agents-board-tools.ts b/server/drivers/agents-board-tools.tsindex 77306e3509..499e6f59de 100644--- a/server/drivers/agents-board-tools.ts+++ b/server/drivers/agents-board-tools.ts@@ -58,13 +58,13 @@ export const BOARD_TOOL_DEFINITIONS = [},{name: "board_update",- description: "Settle the item you hold (default: this thread's): done or failed (text = result), ask a person (text = question), later (minutes; text = note) or release.",+ description: "Settle the item you hold (default: this thread's): done or failed (text = result), ask a person (text = question), later (minutes; text = note), resume a question you no longer need, or release.",inputSchema: {type: "object",additionalProperties: false,properties: {item: { type: "string", description: "Item id from board_list." },- move: { type: "string", enum: ["done", "failed", "ask", "later", "release"] },+ move: { type: "string", enum: ["done", "failed", "ask", "later", "resume", "release"] },text: { type: "string", maxLength: 2000 },person: { type: "string", description: "ask: who; default: who made the item." },minutes: { type: "integer", minimum: 1, maximum: 1440 },diff --git a/server/drivers/agents-catalog-goldens/profiles.json b/server/drivers/agents-catalog-goldens/profiles.jsonindex 7106824ab3..2e88983283 100644--- a/server/drivers/agents-catalog-goldens/profiles.json+++ b/server/drivers/agents-catalog-goldens/profiles.json@@ -1878,8 +1878,8 @@]},"skills+shared+voice+x+team+board": {- "bytes": 74360,- "sha256": "1f24142f877a55e71e5cdd277819e1ed24352b3fcbe0fe295c79b625785ea1b8",+ "bytes": 74408,+ "sha256": "9c6f6d026b895e31180508cb7cc90d49298da59cd24eebbe96e9d5bab00be8d9","tools": ["tool_result_read","list_shared_computers",@@ -1952,8 +1952,8 @@]},"default+room+board": {- "bytes": 59460,- "sha256": "9b58f188e1680fba0cc2f582dcfea7fb087fe9db8f4ed089caf1449d638d9437",+ "bytes": 59508,+ "sha256": "9981d3457e65b15e403d43b84043aa9c06c921c436498db7d2135aaf2d6865d7","tools": ["tool_result_read","list_room_targets",diff --git a/server/routes/board-tools.ts b/server/routes/board-tools.tsindex 871a3025bf..8f752db42d 100644--- a/server/routes/board-tools.ts+++ b/server/routes/board-tools.ts@@ -3,9 +3,9 @@// anywhere else they answer 404 like an unknown path.// POST /api/internal/board/add new room threads, each an item, needs given by keys of the same call// POST /api/internal/board/list the items of the rooms the bot is in-// POST /api/internal/board/update the bot settles, asks about, sets aside, hands back or labels an item+// POST /api/internal/board/update the bot settles, asks about, sets aside, withdraws, hands back or labels an item// Security: a bot sees and adds items only in rooms it is a member of; which moves it may make is the state machine's-// (server/board/state.ts): only the bot holding an item may settle, ask about or set it aside.+// (server/board/state.ts): only the bot holding an item may settle, ask about, set it aside or withdraw its question.import { z } from "zod";import { BOARD_LIMITS, type BoardItem, type BoardItemState } from "../../shared/board.ts";@@ -195,7 +195,7 @@ export function createBoardToolRoutes(deps: BoardToolDeps): RouteHandler {}const move = body.move?.trim().toLowerCase();const text = body.text?.trim() ?? "";- if (move === undefined && body.labels === undefined) return { status: 400, text: `Say a move (done, failed, ask, later or release) or labels. ${UPDATE_EXAMPLE}` };+ if (move === undefined && body.labels === undefined) return { status: 400, text: `Say a move (done, failed, ask, later, resume or release) or labels. ${UPDATE_EXAMPLE}` };const actor = { kind: "bot" as const, botId };if (move === "ask") {if (!text) return { status: 400, text: 'ask needs text: the question. Example: {"move":"ask","text":"Which client is this for?","person":"Mira"}' };@@ -220,13 +220,15 @@ export function createBoardToolRoutes(deps: BoardToolDeps): RouteHandler {const moves: Record<string, () => Parameters<Board["patch"]>[1]["move"]> = {done: () => ({ move: "done", ...(text ? { result: text } : {}) }),failed: () => ({ move: "failed", ...(text ? { result: text } : {}) }),+ resume: () => ({ move: "resume" }),release: () => ({ move: "release" }),};- if (move !== undefined && !Object.hasOwn(moves, move)) return { status: 400, text: `move is one of done, failed, ask, later or release. ${UPDATE_EXAMPLE}` };+ if (move !== undefined && !Object.hasOwn(moves, move)) return { status: 400, text: `move is one of done, failed, ask, later, resume or release. ${UPDATE_EXAMPLE}` };const changed = deps.board.patch(item.threadId, { ...(move ? { move: moves[move]!() } : {}), ...(body.labels !== undefined ? { labels: body.labels } : {}) }, actor);const after: Record<string, string> = {done: "Marked done; items waiting on it are ready now. End your turn with a short summary.",failed: "Marked failed. End your turn with one line on why.",+ resume: "Your question is withdrawn and the item is yours again. Carry on and settle it.",release: "Handed back; another free bot of the room may take it. End your turn.",};return { status: 200, text: move ? after[move]! : `Labels set: ${Object.entries(changed.labels).map(([key, value]) => `${key}=${value}`).join(", ") || "none"}.` };