Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(shared-computers): handed-on work keeps the lent Mac only when nobody else joined the own-window turn
AdityaUmale416199b8f71c
diff --git a/server/host/acting-person.test.ts b/server/host/acting-person.test.tsindex 7066991cd8..75058116bf 100644--- a/server/host/acting-person.test.ts+++ b/server/host/acting-person.test.ts@@ -240,6 +240,18 @@ describe("handing on for the desktop app's own window", () => {expect(people.handedOrigin(userOrigin(), "lends")).toMatchObject({ person: ADA, lends: true });});+ it("records nobody when another person's words joined the turn, or its line was steered in", () => {+ const joined = world({ threads: { own: [{ id: "m1", at: 1, role: "user" }, said("m2", 2, BEN)] }, direct: { own: request("g1", { messageId: "m1" }) } });+ joined.people.handOn({ threadId: "own", generation: "g1" }, { id: "n", rootId: "r" }, true, ADA);+ expect(joined.handed.get("n")).toBeUndefined();+ const named = world({ threads: { ada: [said("m1", 1, ADA), said("m2", 2, BEN)] }, direct: { ada: request("g1", { messageId: "m1" }) } });+ named.people.handOn({ threadId: "ada", generation: "g1" }, { id: "n", rootId: "r" }, true, ADA);+ expect(named.handed.get("n")).toBeUndefined();+ const steered = world({ threads: { own: [{ id: "m1", at: 1, role: "user", steered: true }] }, direct: { own: request("g1", { messageId: "m1" }) } });+ steered.people.handOn({ threadId: "own", generation: "g1" }, { id: "n", rootId: "r" }, true, ADA);+ expect(steered.handed.get("n")).toBeUndefined();+ });+it("keeps the person whose own line started the turn over the lender", () => {const { people, handed } = world({ threads: { ada: [said("m1", 1, ADA)] }, direct: { ada: request("g1", { messageId: "m1" }) } });people.handOn({ threadId: "ada", generation: "g1" }, { id: "n", rootId: "r" }, true, BEN);diff --git a/server/host/acting-person.ts b/server/host/acting-person.tsindex b74ffe361a..daeec30545 100644--- a/server/host/acting-person.ts+++ b/server/host/acting-person.ts@@ -137,14 +137,23 @@ export function createActingPeople(deps: ActingPeopleDeps) {const handed = request.origin?.kind === "user" ? request.origin.person : undefined;return handed && onlyTheirs(thread, handed, 0) ? handed : null;};+ /** This one-on-one turn began with a line that names no sender (the desktop app's own window), and nobody's words+ * joined it since: no named person's line, no line sent in by someone the server can't name, no card answer. */+ const unnamedAlone = (threadId: string, generation: string): boolean => {+ const request = deps.direct(threadId);+ if (deps.store.groupByThread(threadId) || !request?.messageId || request.stopped || !request.generations.has(generation) || request.automation !== undefined) return false;+ const thread = deps.store.messagesFor(threadId);+ const line = thread.find((message) => message.id === request.messageId);+ return Boolean(line && line.role === "user" && !line.peerAsk && !line.sender?.id && !line.steered && !line.relayed && onlyTheirs(thread, "", line.at));+ };return {requester,/** Work this turn hands on now acts for whoever this turn acts for; the first hand-on of a turn that started its* work is kept for that turn too, so it still acts for them if a restart runs it again. `lends`: this turn could use- * the person's lent computer (cloud-lending-turns handsOnLending). `lender`: whom work that `lends` acts for when no- * person's own line names one (the desktop app's own window on a server of one person's own). */+ * the person's lent computer (cloud-lending-turns handsOnLending). `lender`: whom work that `lends` acts for when the+ * turn began with an unnamed line (the desktop app's own window on a server of one person's own) nobody else joined. */handOn(turn: { threadId: string; generation: string }, work: { id: string; rootId: string }, lends = false, lender?: string): void {- const person = requester(turn.threadId, turn.generation) ?? (lends ? lender ?? null : null);+ const person = requester(turn.threadId, turn.generation) ?? (lends && lender && unnamedAlone(turn.threadId, turn.generation) ? lender : null);deps.handed.record(work.id, person, lends);if (work.rootId === turn.generation) deps.handed.record(work.rootId, person, lends);},