Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Show AI quota rings in the Advanced chat header
skygunner9ec74287068c
diff --git a/screenshots/issue-5889/after-1440-daylight-focus.png b/screenshots/issue-5889/after-1440-daylight-focus.pngnew file mode 100644index 0000000000..0e7bbc4046Binary files /dev/null and b/screenshots/issue-5889/after-1440-daylight-focus.png differdiff --git a/screenshots/issue-5889/after-1440-daylight.png b/screenshots/issue-5889/after-1440-daylight.pngnew file mode 100644index 0000000000..4e840fc194Binary files /dev/null and b/screenshots/issue-5889/after-1440-daylight.png differdiff --git a/screenshots/issue-5889/after-1440-midnight.png b/screenshots/issue-5889/after-1440-midnight.pngnew file mode 100644index 0000000000..b7e9b63caeBinary files /dev/null and b/screenshots/issue-5889/after-1440-midnight.png differdiff --git a/screenshots/issue-5889/after-390-daylight.png b/screenshots/issue-5889/after-390-daylight.pngnew file mode 100644index 0000000000..aee0e7dcb3Binary files /dev/null and b/screenshots/issue-5889/after-390-daylight.png differdiff --git a/screenshots/issue-5889/before-1440-daylight.png b/screenshots/issue-5889/before-1440-daylight.pngnew file mode 100644index 0000000000..ee69397db6Binary files /dev/null and b/screenshots/issue-5889/before-1440-daylight.png differdiff --git a/screenshots/issue-5889/before-1440-midnight.png b/screenshots/issue-5889/before-1440-midnight.pngnew file mode 100644index 0000000000..23a5f6fb45Binary files /dev/null and b/screenshots/issue-5889/before-1440-midnight.png differdiff --git a/screenshots/issue-5889/before-390-daylight.png b/screenshots/issue-5889/before-390-daylight.pngnew file mode 100644index 0000000000..15d0a4e95cBinary files /dev/null and b/screenshots/issue-5889/before-390-daylight.png differdiff --git a/src/components/BotRole.tsx b/src/components/BotRole.tsxindex 675dcf0b0b..a3bf69d7f4 100644--- a/src/components/BotRole.tsx+++ b/src/components/BotRole.tsx@@ -12,22 +12,12 @@ export function SidebarBotRole({ role }: { role: string }) {);}-export function ChatHeadRole({ bot }: { bot: Pick<Bot, "title" | "chiefOfStaff"> }) {- const role = bot.title.trim();- const repeatsChiefBadge = bot.chiefOfStaff && role.toLocaleLowerCase() === t("chat.chiefOfStaff").toLocaleLowerCase();- if (!role || repeatsChiefBadge) return null;- return (- <span data-chathead-role className="flex min-w-0 max-w-fit grow basis-0">- <span title={role} className="max-w-[16rem] truncate text-[13px] text-ink-secondary">{role}</span>- </span>- );-}-export function chiefOfStaffBadge(bot: Bot) {if (!bot.chiefOfStaff) return null;+ const label = t("chat.chiefOfStaff");return (- <span title={t("chat.chiefOfStaff")} className="flex shrink-0 items-center gap-1 whitespace-nowrap rounded-full bg-accent/12 px-2 py-0.5 text-[11px] font-medium text-accent @max-4xl/chathead:px-1.5">- <Crown size={11} aria-hidden="true" /> <span className="@max-4xl/chathead:sr-only">{t("chat.chiefOfStaff")}</span>+ <span role="img" aria-label={label} title={label} className="flex shrink-0 items-center rounded-full bg-accent/12 p-1.5 text-accent">+ <Crown size={11} aria-hidden="true" /></span>);}diff --git a/src/components/ChatActivity.tsx b/src/components/ChatActivity.tsxindex d9e0a3d666..ea109b82d8 100644--- a/src/components/ChatActivity.tsx+++ b/src/components/ChatActivity.tsx@@ -1,6 +1,7 @@import { useMemo, useState, type CSSProperties } from "react";import { List } from "lucide-react";import { Switch } from "./SettingsPrimitives";+import { ChatHeaderUsage } from "./EngineUsage";import { t } from "@/lib/i18n";import type { Message } from "@/state/store";import { useStoreDispatch } from "@/state/store-select";@@ -50,7 +51,7 @@ export function chatActivityMessages(messages: Message[], advanced: boolean, act}/** The chat header's Chat activity button and, once opened, its two switches and the way to the bot's run history. */-export function ChatActivityControls({ activity, botId, style }: { activity: ChatActivity; botId: string; style?: CSSProperties }) {+export function ChatActivityControls({ activity, botId, style, showUsage }: { activity: ChatActivity; botId: string; style?: CSSProperties; showUsage: boolean }) {const dispatch = useStoreDispatch();const [open, setOpen] = useState(false);return (@@ -61,6 +62,7 @@ export function ChatActivityControls({ activity, botId, style }: { activity: ChaonClick={() => setOpen((was) => !was)}className="ui-pill shrink-0"><List size={14} aria-hidden="true" />{t("chat.automation.activity")}</button>+ {showUsage && <ChatHeaderUsage />}{open && (<section className="chat-run-log-actions flex min-w-0 flex-wrap items-center gap-1.5"><label className="ui-pill shrink-0">diff --git a/src/components/ChatView.controls.test.ts b/src/components/ChatView.controls.test.tsindex 4ceaafd152..43db7c04b6 100644--- a/src/components/ChatView.controls.test.ts+++ b/src/components/ChatView.controls.test.ts@@ -179,7 +179,7 @@ describe("the Simple header", () => {expect(advanced).not.toContain("data-chathead-elsewhere");expect(advanced).toContain("data-background-activity");expect(advanced).toContain("data-chathead-back");- expect(advanced).toContain("data-chathead-role");+ expect(advanced).toContain('aria-description="Research"');fixture.showThreads = true;});@@ -217,28 +217,15 @@ describe("header name", () => {expect(pill).toContain("Rename Pepper");});- it("shows the bot's role beside the pill in Advanced mode, taking only the room the name leaves, and leaves it to the bot panel in Simple", () => {- fixture.advanced = false;- expect(renderToStaticMarkup(createElement(ChatView, { bot: { ...bot, title: " Research " } }))).not.toContain("data-chathead-role");- for (const advanced of [true]) {- fixture.advanced = advanced;- const markup = renderToStaticMarkup(createElement(ChatView, { bot: { ...bot, title: " Research " } }));- const identity = markup.slice(markup.indexOf("data-chathead-identity"), markup.indexOf("data-chathead-controls"));- const role = identity.match(/<span data-chathead-role="true" class="([^"]*)"><span title="Research" class="([^"]*)">Research<\/span><\/span>/);- expect(role, `advanced ${advanced}`).toBeTruthy();- expect(role![1].split(" ")).toEqual(expect.arrayContaining(["min-w-0", "max-w-fit", "grow", "basis-0"]));- expect(role![2].split(" ")).toEqual(expect.arrayContaining(["truncate", "text-[13px]", "text-ink-secondary"]));- expect(identity.indexOf("data-chathead-role")).toBeGreaterThan(identity.indexOf("Rename Pepper"));- expect(renderToStaticMarkup(createElement(ChatView, { bot }))).not.toContain("data-chathead-role");- }- fixture.advanced = true;- });-- it("leaves a Chief's role out of the header when it only repeats the Chief of Staff badge", () => {- const header = (title: string) => renderToStaticMarkup(createElement(ChatView, { bot: { ...bot, chiefOfStaff: true, title } }));- expect(header("chief of staff ")).not.toContain("data-chathead-role");- expect(header("Operations lead")).toContain('<span title="Operations lead"');- expect(renderToStaticMarkup(createElement(ChatView, { bot: { ...bot, title: "Chief of Staff" } }))).toContain("data-chathead-role");+ it("keeps the role on the profile control and shows an icon-only Chief of Staff badge", () => {+ const markup = renderToStaticMarkup(createElement(ChatView, { bot: { ...bot, chiefOfStaff: true, title: " Research " } }));+ const identity = markup.slice(markup.indexOf("data-chathead-identity"), markup.indexOf("data-chathead-controls"));+ expect(identity).toContain('title="Research"');+ expect(identity).toContain('aria-description="Research"');+ expect(identity).toContain('role="img" aria-label="Chief of Staff"');+ expect(identity).not.toContain(">Research<");+ expect(identity).not.toContain(">Chief of Staff<");+ expect(identity).toContain("Rename Pepper");});it("draws no working dots in the header pill, keeping one width, while a status still tells a screen reader", () => {@@ -650,9 +637,9 @@ describe("thread control placement", () => {it("keeps the Chief of Staff badge on one line instead of stacking a word per line", () => {const markup = renderToStaticMarkup(createElement(ChatView, { bot: { ...bot, busy: false, chiefOfStaff: true } }));- const badge = /<span title="Chief of Staff" class="([^"]*)"><svg[^>]*lucide-crown[^]*?<\/svg> <span class="([^"]*)">Chief of Staff<\/span>/.exec(markup)!;- expect(badge[1].split(" ")).toEqual(expect.arrayContaining(["shrink-0", "whitespace-nowrap"]));- expect(badge[2].split(" ")).toContain("@max-4xl/chathead:sr-only");+ const badge = /<span role="img" aria-label="Chief of Staff" title="Chief of Staff" class="([^"]*)"><svg[^>]*lucide-crown[^]*?<\/svg><\/span>/.exec(markup)!;+ expect(badge[1].split(" ")).toEqual(expect.arrayContaining(["shrink-0", "items-center", "rounded-full"]));+ expect(badge[0]).not.toContain("whitespace-nowrap");});it("shows the selected thread's model and its level under the composer's field in Advanced", () => {diff --git a/src/components/ChatView.tsx b/src/components/ChatView.tsxindex e65ab65517..6cb9be4388 100644--- a/src/components/ChatView.tsx+++ b/src/components/ChatView.tsx@@ -87,7 +87,7 @@ import { CallRecordRow } from "./CallRecordRow";import { AttachmentGallery, collectMessageFiles, replyAttachmentGroup, splitMessageAttachments } from "./AttachmentGallery";import { ScreenFrame } from "./ScreenFrame";import { CompactionChip, DigestChip } from "./DigestChip";-import { RenameTitle } from "./RenameTitle"; import { ChatHeadRole, chiefOfStaffBadge } from "./BotRole";+import { RenameTitle } from "./RenameTitle"; import { chiefOfStaffBadge } from "./BotRole";import { BotActivityPicker } from "./TaskPicker"; import { ChatHeadPill } from "./ChatHeadPill"; import { HeaderShare } from "./bot-access/HeaderShare"; import { isPlaceId } from "@/lib/place-chat"; import { PlacedModelPill } from "./PlacedBotMenu"; import { ThreadPresenceFaces } from "./TeamPresence"; import { useStoreRef } from "@/state/store-ref"; import { sameFields, useStoreDispatch, useStoreSelector } from "@/state/store-select"; import { sameDrawnBots } from "@/lib/drawn-bots"; import { ChatActivityControls, chatActivityMessages, useChatActivity } from "./ChatActivity";import { ELEVATED_FLOAT, ELEVATED_HOVER } from "./elevated"; import { NewThreadHeaderButton } from "./NewThreadHeaderButton"; import { HeaderThreadTabs, useThreadTabsShown } from "./HeaderThreadTabs";import { ModelPicker } from "./ModelPicker"; import { useFailedTurnFix } from "./FailedTurnFix";@@ -912,7 +912,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = falsimpleHead ? "px-5 pt-2.5 pb-2.5 max-md:pl-14 max-md:pr-3" : "px-5 py-3 pl-11 md:pl-5 max-md:pl-14 max-md:pr-3",)}>- <div data-chathead-row className={cn("flex items-center justify-between", phone ? "gap-2" : "@max-[30rem]/chathead:flex-wrap @max-[30rem]/chathead:gap-y-1 @min-[30rem]/chathead:grid @min-[30rem]/chathead:grid-cols-[minmax(0,1fr)_minmax(0,auto)_minmax(max-content,1fr)]")}>{advanced && !inForkPanel && <ChatActivityControls key={bot.threadId} activity={activity} botId={bot.id} style={headerNoDragStyle} />}+ <div data-chathead-row className={cn("flex items-center justify-between", phone ? "gap-2" : "@max-[30rem]/chathead:flex-wrap @max-[30rem]/chathead:gap-y-1 @min-[30rem]/chathead:grid @min-[30rem]/chathead:grid-cols-[minmax(0,1fr)_minmax(0,auto)_minmax(max-content,1fr)]")}>{advanced && !inForkPanel && <ChatActivityControls key={bot.threadId} activity={activity} botId={bot.id} style={headerNoDragStyle} showUsage={!phone && !remoteClient} />}<div data-chathead-identity className={cn("flex min-w-0 items-center gap-2", phone ? "flex-1" : "@max-[30rem]/chathead:basis-full @min-[30rem]/chathead:col-start-2 @min-[30rem]/chathead:justify-self-center", simpleHead && phone && "justify-center")} style={headerNoDragStyle}>{headTabs && <HeaderThreadTabs bot={bot} />}{simpleHead ? (<ChatHeadPill@@ -927,7 +927,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = faltype="button"onClick={() => dispatch({ type: "toggleSettings", open: true })}className="flex shrink-0 items-center justify-center rounded-full"- title={t("chat.openProfile")}+ title={bot.title.trim() || t("chat.openProfile")} aria-description={bot.title.trim() || undefined}aria-label={t("chat.openProfileAria", { name: bot.name })}><BotAvatar@@ -963,7 +963,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = faltype="button"data-chathead-pill data-tour="bot-pill"onClick={() => dispatch({ type: "toggleSettings", open: true })}- title={t("chat.openProfile")}+ title={bot.title.trim() || t("chat.openProfile")} aria-description={bot.title.trim() || undefined}aria-label={t("chat.openProfileAria", { name: bot.name })}className={cn("group flex h-9 min-w-0 items-center gap-2.5 rounded-full py-0.5 pl-2 pr-3.5 text-ink", ELEVATED_FLOAT, ELEVATED_HOVER)}>@@ -974,7 +974,7 @@ export const ChatView = memo(function ChatView({ bot: profile, inForkPanel = fal<ChevronRight size={14} aria-hidden="true" className="-ml-2.5 w-0 shrink-0 text-ink-secondary opacity-0 transition-[width,margin,opacity] duration-150 group-hover:ml-0 group-hover:w-3.5 group-hover:opacity-100 group-focus-visible:ml-0 group-focus-visible:w-3.5 group-focus-visible:opacity-100" /></button>)}- {!phone && !simpleHead && <ChatHeadRole bot={bot} />}<span role="status" className="sr-only" data-chathead-status>{bot.busy ? t("sidebar.preview.working") : ""}</span>{!simpleHead && privateChat && <TeamPrivateHeader />}{!simpleHead && ownHelper && <TeamOwnHelperHeader />}{!simpleHead && sharedChat && team && <TeamSharedHeader team={team} onlyPeopleAdded={bot.onlyPeopleAdded} sharedWith={currentTask?.sharedWith?.name} />}+ <span role="status" className="sr-only" data-chathead-status>{bot.busy ? t("sidebar.preview.working") : ""}</span>{!simpleHead && privateChat && <TeamPrivateHeader />}{!simpleHead && ownHelper && <TeamOwnHelperHeader />}{!simpleHead && sharedChat && team && <TeamSharedHeader team={team} onlyPeopleAdded={bot.onlyPeopleAdded} sharedWith={currentTask?.sharedWith?.name} />}{!simpleHead && !bot.busy && bot.waitingForTeammates && <span className="truncate text-[12px] text-ink-secondary" role="status">{t("chat.teammatesWorking")}</span>}{(advanced || remoteClient) && awayFromMainThread(profile, showThreads) && (<buttondiff --git a/src/components/EngineUsage.tsx b/src/components/EngineUsage.tsxindex e139b6e1e9..c900bd7e42 100644--- a/src/components/EngineUsage.tsx+++ b/src/components/EngineUsage.tsx@@ -3,6 +3,8 @@ import { createPortal } from "react-dom";import { cn } from "@/lib/cn";import { t } from "@/lib/i18n";+import { useOwnerOrAdmin } from "@/lib/use-owner-or-admin";+import { sameItems, useStoreDispatch, useStoreSelector } from "@/state/store-select";import {limitLine, limitsCheckedAt, loadLimits, releaseLimit, reportsUsage, resetTime, usageBars, usageRows, usageTone, useEngineLimits, USAGE_BARS, windowLabel,type EngineLimit, type UsageTone,@@ -107,13 +109,13 @@ const RING_LENGTH = 2 * Math.PI * RING_RADIUS;const RING_INK: Record<UsageTone, string> = { fine: "text-success", near: "text-warning", out: "text-danger" };/** A ring drawn clockwise from the top for the usage left; at the limit it is empty and struck through. */-export function UsageRing({ limit, className }: { limit: EngineLimit; className?: string }) {- const tone = usageTone(limit);- const left = tone === "out" ? 0 : Math.max(0, 100 - (limit.usedPercent ?? 0));+export function UsageRing({ limit, className }: { limit?: EngineLimit; className?: string }) {+ const tone = reportsUsage(limit) ? usageTone(limit) : null;+ const left = !tone || tone === "out" ? 0 : Math.max(0, 100 - (limit?.usedPercent ?? 0));const middle = RING / 2;return (- <svg aria-hidden="true" data-usage-ring={tone} width={RING} height={RING} viewBox={`0 0 ${RING} ${RING}`} className={cn("shrink-0", RING_INK[tone], className)}>- <circle cx={middle} cy={middle} r={RING_RADIUS} fill="none" stroke="currentColor" strokeWidth={RING_STROKE} opacity={0.3} />+ <svg aria-hidden="true" data-usage-ring={tone ?? "unknown"} width={RING} height={RING} viewBox={`0 0 ${RING} ${RING}`} className={cn("shrink-0", tone ? RING_INK[tone] : "text-ink-secondary", className)}>+ <circle cx={middle} cy={middle} r={RING_RADIUS} fill="none" stroke="currentColor" strokeWidth={RING_STROKE} strokeDasharray={tone ? undefined : "2 2"} opacity={tone ? 0.3 : 0.65} />{left > 0 && <circle cx={middle} cy={middle} r={RING_RADIUS} fill="none" stroke="currentColor" strokeWidth={RING_STROKE} strokeLinecap="round"strokeDasharray={`${(RING_LENGTH * left) / 100} ${RING_LENGTH}`} transform={`rotate(-90 ${middle} ${middle})`} />}{tone === "out" && <path d={`M3 ${RING - 3}L${RING - 3} 3`} stroke="currentColor" strokeWidth={1.5} strokeLinecap="round" />}@@ -121,6 +123,51 @@ export function UsageRing({ limit, className }: { limit: EngineLimit; className?);}+const QUOTA_DRIVERS = new Set(["claudeAgent", "codex", "grokAgent", "opencodeGo", "antigravityAgent"]);++export function ChatHeaderUsage() {+ const team = useStoreSelector((state) => Boolean(state.config?.team));+ const admin = useOwnerOrAdmin();+ return !team || admin ? <ChatHeaderUsageRings /> : null;+}++function ChatHeaderUsageRings() {+ const limits = useEngineLimits();+ const dispatch = useStoreDispatch();+ const instances = useStoreSelector((state) => state.instances.filter((instance) =>+ QUOTA_DRIVERS.has(instance.driverKind) && instance.snapshot?.billing === "subscription" && instance.snapshot.authenticated === true), sameItems);+ const accounts = new Map<string, { name: string; limit?: EngineLimit }>(limits.map((limit) =>+ [limit.engine, { name: limit.name, limit }]));+ for (const instance of instances) {+ if (!accounts.has(instance.instanceId)) accounts.set(instance.instanceId, { name: instance.displayName });+ }+ if (!accounts.size) return null;+ const now = Date.now();+ return (+ <div data-chathead-usage role="group" aria-label={t("limits.title")} className="hidden min-w-0 flex-wrap items-center gap-0.5 @min-[48rem]/chathead:flex">+ {[...accounts].map(([engine, { name, limit }]) => {+ const windows = limit ? usageRows(limit) : [];+ const details = windows.length ? windows.map((row) => [+ windowLabel(row.window, limit?.meter),+ t("planUsage.left", { remaining: row.left }),+ row.resetsAt !== null && row.resetsAt > now ? t("limits.resets", { time: resetTime(row.resetsAt, now) }) : null,+ ].filter(Boolean).join(" · ")) : [t("planUsage.notReported")];+ return (+ <button key={engine} type="button" data-usage-engine={engine} aria-label={[name, ...details].join(", ")}+ onClick={() => dispatch({ type: "toggleAppSettings", open: true, section: "usage" })}+ className="group/quota relative flex size-6 shrink-0 items-center justify-center rounded-full hover:bg-ink/[0.06] focus-visible:bg-ink/[0.06]">+ <UsageRing limit={limit} className="size-5" />+ <span aria-hidden="true" className="menu-surface pointer-events-none absolute start-0 top-full z-50 mt-1 hidden w-max max-w-64 px-2.5 py-1.5 text-start text-[12px] text-ink group-hover/quota:block group-focus-visible/quota:block">+ <span className="block font-medium">{name}</span>+ {details.map((text) => <span key={text} className="block text-ink-secondary">{text}</span>)}+ </span>+ </button>+ );+ })}+ </div>+ );+}+/** When the usage was last read, each window's share left with its reset and a track filled by use; at the limit, how it* clears and a fresh check. */export function UsageRows({ limit }: { limit: EngineLimit }) {diff --git a/src/components/limit-resets.test.ts b/src/components/limit-resets.test.tsindex c00ae51a2d..fcfca7ab3c 100644--- a/src/components/limit-resets.test.ts+++ b/src/components/limit-resets.test.ts@@ -33,7 +33,7 @@ const { setLocale } = await import("@/lib/i18n");const limits = await import("@/lib/limit-resets");const { automationSentence, isDone, statusLine } = await import("@/lib/automations");const { LimitWarnings } = await import("./automations/LimitWarnings");-const { UsageAlert, UsageBars, UsageRows } = await import("./EngineUsage");+const { ChatHeaderUsage, UsageAlert, UsageBars, UsageRows } = await import("./EngineUsage");const { FailedTurnRow } = await import("./ChatView");const { CalendarGrid } = await import("./RoutineCalendarPage");@@ -155,6 +155,22 @@ describe("the bars", () => {windows: [{ window: "5-hour", usedPercent: fiveHour, resetsAt: RESET }, { window: "weekly", usedPercent: weekly, resetsAt: MONDAY }], ...extra,});+ it("shows known and unknown quotas in the header, with window details and a Spending shortcut", () => {+ serve([windows(35, 82)]);+ fixture.state.instances = [{ instanceId: "gemini", driverKind: "antigravityAgent", displayName: "Gemini", models: { default: "gemini", options: [] },+ snapshot: { state: "available", authenticated: true, billing: "subscription" } } satisfies InstanceInfo];+ const header = mount(createElement(ChatHeaderUsage));+ const known = header.querySelector<HTMLButtonElement>('[data-usage-engine="claude"]')!;+ const unknown = header.querySelector<HTMLButtonElement>('[data-usage-engine="gemini"]')!;+ expect(known.getAttribute("aria-label")).toContain("5-hour · 65% left · resets 3:40 PM");+ expect(known.getAttribute("aria-label")).toContain("Weekly · 18% left");+ expect(known.querySelector('[aria-hidden="true"].menu-surface')?.className).toContain("group-focus-visible/quota:block");+ expect(unknown.getAttribute("aria-label")).toBe("Gemini, Not reported by this plan");+ expect(unknown.querySelector('[data-usage-ring="unknown"] circle')?.getAttribute("stroke-dasharray")).toBe("2 2");+ known.click();+ expect(fixture.dispatch).toHaveBeenCalledWith({ type: "toggleAppSettings", open: true, section: "usage" });+ });+it("fill for the usage left, with one bar exactly while near the limit and none at it", () => {const bars = (used: number, blocked = false) => limits.usageBars({ usedPercent: used, blocked });expect([0, 29, 30, 31, 59, 60, 61, 89, 89.9, 90, 99, 100].map((used) => bars(used))).toEqual([4, 4, 3, 3, 3, 2, 2, 2, 2, 1, 1, 0]);