Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Rooms: a first answer that can't write skills still holds the claim, so no later top-level answer hands shares
AdityaUmale1129e6e3e893
diff --git a/server/agents-turn.test.ts b/server/agents-turn.test.tsindex 0dfdcec085..746ecde2b2 100644--- a/server/agents-turn.test.ts+++ b/server/agents-turn.test.ts@@ -187,13 +187,25 @@ describe("what a turn that may not use a listed tool is told", () => {it("lets the first answer hand shares to the bots it @mentions even when its own engine can't write skills", () => {const claim: RoomSkillsClaim = { claimed: false };- expect(roomSkillsTurn(claim, 0, "writer", { allowed: true, canWrite: false })).toEqual({ writes: false, hands: true });- expect(roomSkillsTurn(claim, 0, "writer", { allowed: true, canWrite: true })).toEqual({ writes: true, hands: true });- expect(roomSkillsTurn(claim, 0, "writer", { allowed: false, canWrite: true })).toEqual({ writes: false, hands: false });+ expect(roomSkillsTurn(claim, 0, "writer", { allowed: true, canWrite: false })).toEqual({ writes: false, hands: true, claims: true });+ expect(roomSkillsTurn(claim, 0, "writer", { allowed: true, canWrite: true })).toEqual({ writes: true, hands: true, claims: true });+ expect(roomSkillsTurn(claim, 0, "writer", { allowed: false, canWrite: true })).toEqual({ writes: false, hands: false, claims: false });handRoomSkills(claim, ["video"]);- expect(roomSkillsTurn(claim, 1, "video", { allowed: true, canWrite: true })).toEqual({ writes: true, hands: false });+ expect(roomSkillsTurn(claim, 1, "video", { allowed: true, canWrite: true })).toEqual({ writes: true, hands: false, claims: true });takeRoomSkills(claim, 0, "editor", true);- expect(roomSkillsTurn(claim, 0, "other", { allowed: true, canWrite: true })).toEqual({ writes: false, hands: false });+ expect(roomSkillsTurn(claim, 0, "other", { allowed: true, canWrite: true })).toEqual({ writes: false, hands: false, claims: false });+ });++ it("keeps the claim with a first answer that can't write skills, so a later top-level answer hands no shares", () => {+ const claim: RoomSkillsClaim = { claimed: false };+ const first = roomSkillsTurn(claim, 0, "writer", { allowed: true, canWrite: false });+ expect(first.claims).toBe(true);+ takeRoomSkills(claim, 0, "writer", true);+ handRoomSkills(claim, ["video"])();+ expect(roomSkillsTurn(claim, 0, "editor", { allowed: true, canWrite: true })).toEqual({ writes: false, hands: false, claims: false });+ takeRoomSkills(claim, 0, "writer", false);+ expect(roomSkillsTurn(claim, 0, "editor", { allowed: true, canWrite: true }).hands).toBe(true);+ expect(roomSkillsTurn(claim, 1, "video", { allowed: true, canWrite: true }).claims).toBe(false);});it("gives the share back to a turn that never ran", () => {diff --git a/server/agents-turn.ts b/server/agents-turn.tsindex 49509db6f2..6e49fda84f 100644--- a/server/agents-turn.ts+++ b/server/agents-turn.ts@@ -111,11 +111,13 @@ export function roomTurnMayWriteSkills(claim: RoomSkillsClaim, hop: number, botIreturn hop === 0 ? !claim.claimed : claim.mentioned?.has(botId) === true;}-/** What one room turn may do with skills: `writes` its own (it may, and its engine can), and `hands` a share to each bot it- * @mentions (the first answer, even when its own engine can't write skills). */-export function roomSkillsTurn(claim: RoomSkillsClaim, hop: number, botId: string, { allowed, canWrite }: { allowed: boolean; canWrite: boolean }): { writes: boolean; hands: boolean } {+/** What one room turn may do with skills: `writes` its own (it may, and its engine can), `hands` a share to each bot it+ * @mentions (the first answer, even when its own engine can't write skills), and `claims` its turn: it takes the claim once+ * set up, and gives it back if it never ran, whenever it writes or hands, so no later first answer can hand shares again. */+export function roomSkillsTurn(claim: RoomSkillsClaim, hop: number, botId: string, { allowed, canWrite }: { allowed: boolean; canWrite: boolean }): { writes: boolean; hands: boolean; claims: boolean } {const may = allowed && roomTurnMayWriteSkills(claim, hop, botId);- return { writes: may && canWrite, hands: may && hop === 0 };+ const writes = may && canWrite, hands = may && hop === 0;+ return { writes, hands, claims: writes || hands };}/** The first answer, holding the claim, @mentions `botIds`: each may change its own skills once on this message. Returns whatdiff --git a/server/index.ts b/server/index.tsindex 4eeb8bb62f..162b5f763e 100644--- a/server/index.ts+++ b/server/index.ts@@ -10035,7 +10035,7 @@ async function runClaimedGroupMemberTurn(], integrations.agents, { rules: cfg.everyBotRules, pagesOff: (store.bot(bot.id) ?? bot).toolsOff?.includes("pages") });// Claim /learn only after setup succeeded, so a failed first responder does not consume it.- if (skillAuthoring) takeRoomSkills(skillAuthoringClaim, hop, bot.id, true);+ if (roomSkills.claims) takeRoomSkills(skillAuthoringClaim, hop, bot.id, true);// Never launch a replacement into a stopped handshake's pre-id window.await pendingCancelledProviderHandshakes.waitForClear(threadId);const heldBeforeDispatch = roomHeld(store.group(group.id), bot.id);@@ -10285,7 +10285,7 @@ async function runClaimedGroupMemberTurn(store.setActivity(bot.id, "idle");}if (outcome === "dispatch_failed") {- if (skillAuthoring) takeRoomSkills(skillAuthoringClaim, hop, bot.id, false);+ if (roomSkills.claims) takeRoomSkills(skillAuthoringClaim, hop, bot.id, false);// No turn.completed follows a rejected room dispatch: retry what queued meanwhile.drainQueuedSends();}@@ -10297,7 +10297,7 @@ async function runClaimedGroupMemberTurn(return true;}if (outcome === "provider_failed" || outcome === "parked") {- if (skillAuthoring) takeRoomSkills(skillAuthoringClaim, hop, bot.id, false);+ if (roomSkills.claims) takeRoomSkills(skillAuthoringClaim, hop, bot.id, false);return false;}const resent = orchestration || cardContinuation || oneTimeInputTaken || outcome !== "settled" || isCancelled?.() ? undefined : await roomLimits.resendOnce(threadId, bot, preparedApprovalMode, turnCompleted, roomSpeaker?.since ?? 0,