Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Lent computer's menu keeps a bot named for its whole action, counts bots as bots
Bugfixer 2eb543f05a607
diff --git a/electron/computer-sharing.mjs b/electron/computer-sharing.mjsindex d21745a357..34c1629503 100644--- a/electron/computer-sharing.mjs+++ b/electron/computer-sharing.mjs@@ -257,15 +257,16 @@ export function createComputerSharing({ file, fetch: fetchImpl, environments, lo/** The Clouds whose device link is open now. */const linked = new Set();const inUse = new Map();- /** Each bot that acted here lately, by Cloud and bot name, until ACTING_MS after its last action. */+ /** Each bot that acted here lately, by Cloud and bot name, until ACTING_MS after its last action ends (`held` while it runs). */const acting = new Map();- const actedFor = (id, by) => {+ const actedFor = (id, by, held = false) => {const key = `${id}\n${by.name}`;clearTimeout(acting.get(key)?.timer);- const timer = setTimeout(() => { acting.delete(key); changed(); }, ACTING_MS);- timer.unref?.();+ const timer = held ? null : setTimeout(() => { acting.delete(key); changed(); }, ACTING_MS);+ timer?.unref?.();acting.set(key, { env: id, by, timer });};+ const forgetHeld = (id, by) => { const key = `${id}\n${by.name}`; if (acting.get(key)?.timer === null) acting.delete(key); };const forgetActing = id => { for (const [key, entry] of acting) if (id === undefined || entry.env === id) { clearTimeout(entry.timer); acting.delete(key); } };const actingOn = env => status.get(env.id)?.connected ? [...acting.values()].filter(entry => entry.env === env.id) : [];let closed = false;@@ -559,7 +560,7 @@ export function createComputerSharing({ file, fetch: fetchImpl, environments, loif (executing) { await call("result", { jobId: job.id, result: sharedComputerError(new Error("This computer is busy with another server")) }); continue; }const by = actingBot(job.by);executing = { env: env.id, action: job.operation.action };- if (by) actedFor(env.id, by);+ if (by) actedFor(env.id, by, true);changed();const jobAbort = new AbortController();const jobSignal = AbortSignal.any([signal, jobAbort.signal]);@@ -604,7 +605,8 @@ export function createComputerSharing({ file, fetch: fetchImpl, environments, loif (control) presence.acted(job.operation.tool_name, job.operation.arguments);await renewal?.catch(() => {});await control?.release().catch(() => {});- executing = null; if (by) actedFor(env.id, by); changed();+ // A stopped or replaced run must not name its bot again after stop() cleared it.+ executing = null; if (by) { if (!closed && !signal.aborted && running.get(env.id) === live) actedFor(env.id, by); else forgetHeld(env.id, by); } changed();}activity.record({env, action: job.operation.action, detail: describeSharedOperation(grant, job.operation), ok: result?.isError !== true,diff --git a/electron/lend-automatically.node-test.mjs b/electron/lend-automatically.node-test.mjsindex 6a8e46290a..c360c611a9 100644--- a/electron/lend-automatically.node-test.mjs+++ b/electron/lend-automatically.node-test.mjs@@ -533,7 +533,15 @@ test("the menu-bar item names the bot acting on this Mac, with its colour, and ktest("a bot's name from a Cloud is shown only as short plain text, and its colour only as a colour word", () => {assert.deepEqual(actingBot({ name: " Word\n assistant ", color: "purple" }), { name: "Word assistant", color: "purple" });assert.deepEqual(actingBot({ name: "Support", color: "#fff; rm" }), { name: "Support", color: null });- for (const by of [null, {}, { name: "" }, { name: 7 }, { name: "x".repeat(65) }, { name: "Bell\u0007" }, { name: "Support\u202Eevil" }, { name: "Zero\u200Bwidth" }]) assert.equal(actingBot(by), null, JSON.stringify(by));+ assert.equal(actingBot({ name: "x".repeat(80) })?.name, "x".repeat(80), "every name the server allows (80) is shown");+ for (const by of [null, {}, { name: "" }, { name: 7 }, { name: "x".repeat(81) }, { name: "Bell\u0007" }, { name: "Support\u202Eevil" }, { name: "Zero\u200Bwidth" }]) assert.equal(actingBot(by), null, JSON.stringify(by));+});++test("three or more names in the menu-bar title count bots as bots and Clouds as Clouds", () => {+ const bots = names => names.map(name => ({ name, color: null, cloud: "My Cloud" }));+ assert.equal(indicatorText({ clouds: ["My Cloud"], using: ["My Cloud"], bots: bots(["A", "B", "C"]) }, "Mac").title, "3 bots are using this Mac");+ assert.equal(indicatorText({ clouds: ["My Cloud", "Client A"], using: ["My Cloud", "Client A"], bots: bots(["A", "B"]) }, "Mac").title, "2 Clouds are using this Mac");+ assert.equal(indicatorText({ clouds: ["X", "Y", "Z"], using: ["X", "Y", "Z"] }, "Mac").title, "3 Clouds are using this Mac");});test("the menu names each bot using this Mac with its colour dot; See activity is one click from it", () => {diff --git a/electron/lending-indicator.mjs b/electron/lending-indicator.mjsindex 3f8655540f..9ada960f3c 100644--- a/electron/lending-indicator.mjs+++ b/electron/lending-indicator.mjs@@ -6,14 +6,15 @@ import { dotIcons } from "./color-dot.mjs";export const deviceWord = (platform = process.platform) => platform === "darwin" ? "Mac" : platform === "win32" ? "PC" : "computer";const listed = (names, t) => names.length < 3 ? names.join(t("native.lendTray.and")) : `${names.slice(0, -1).join(", ")}${t("native.lendTray.and")}${names.at(-1)}`;-const short = (names, t) => names.length < 3 ? listed(names, t) : t("native.lendTray.clouds", { count: names.length });+/** Three or more names shorten to a count of what they are: bots when every name is a bot, else the Clouds. */+const short = (names, t, { bots = false, clouds = names.length } = {}) => names.length < 3 ? listed(names, t) : t(bots ? "native.lendTray.bots" : "native.lendTray.clouds", { count: bots ? names.length : clouds });// oxlint-disable-next-line no-control-regexconst NOT_PRINTABLE = /[\x00-\x1f\x7f-\x9f\u200b-\u200f\u2028-\u202e\u2060-\u2069\ufeff]/;/** The bot a Cloud says an action is for: a short plain name and a colour word, or null. Older Clouds send none. */export function actingBot(by) {const name = typeof by?.name === "string" ? by.name.trim().replace(/\s+/g, " ") : "";- if (!name || [...name].length > 64 || NOT_PRINTABLE.test(name)) return null;+ if (!name || [...name].length > 80 || NOT_PRINTABLE.test(name)) return null;return { name, color: typeof by.color === "string" && /^[a-z]{1,16}$/.test(by.color) ? by.color : null };}@@ -36,7 +37,7 @@ export function indicatorText({ clouds, using, bots = [], paused, pauseError, scconst acting = bots.filter(bot => using.includes(bot.cloud));const rest = using.filter(name => !acting.some(bot => bot.cloud === name));const byBot = acting.length ? { acting: acting.map(bot => ({ label: t("native.lendTray.botUsing", { bot: bot.name, cloud: bot.cloud, device: named }), color: bot.color })) } : {};- return { line: rest.length ? say(rest, listed) : null, title: say([...acting.map(bot => bot.name), ...rest], short), screen: why, ...byBot, ...pending, ...wrong };+ return { line: rest.length ? say(rest, listed) : null, title: say([...acting.map(bot => bot.name), ...rest], (names, tt) => short(names, tt, { bots: !rest.length, clouds: using.length })), screen: why, ...byBot, ...pending, ...wrong };}const ready = clouds.filter(name => !waiting.includes(name));if (!ready.length) return { line: pending.pending ?? t("native.lendTray.canUse", { clouds: listed(clouds, t), device: named }), title: "", screen: why, ...wrong };diff --git a/src/locales/en.json b/src/locales/en.jsonindex d0846540e1..88bf51bcb8 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -9648,6 +9648,7 @@"activity.tool.team.reportBug": "Report bug","browser.control.held": "{name} is paused for you","native.lendTray.and": " and ",+ "native.lendTray.bots": "{count} bots","native.lendTray.clouds": "{count} Clouds","native.lendTray.pausedLine": "Paused: {clouds} can't use this {device}","native.lendTray.paused": "Paused",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex e6105cf4ab..e29126253f 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -9604,6 +9604,7 @@"activity.tool.team.reportBug": "Relatar um problema","browser.control.held": "O bot {name} está pausado para você","native.lendTray.and": " e ",+ "native.lendTray.bots": "Bots ({count})","native.lendTray.clouds": "Clouds ({count})","native.lendTray.pausedLine": "Pausado: {clouds} sem acesso a este {device}","native.lendTray.paused": "Pausado",