Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Give each model in the usage breakdown a provider shade

BunBnnuy0f5ac6f5fd70
diff --git a/src/components/UsageSection.model-colors.test.ts b/src/components/UsageSection.model-colors.test.ts
new file mode 100644
index 0000000000..03be249426
--- /dev/null
+++ b/src/components/UsageSection.model-colors.test.ts
@@ -0,0 +1,37 @@
+import { createElement } from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { describe, expect, it, vi } from "vitest";
+import { modelColor } from "@/lib/model-color";
+
+vi.mock("@/state/store", async (original) => {
+ const actual = await original<typeof import("@/state/store")>();
+ return { ...actual, useStore: () => ({ state: actual.initialState, dispatch: vi.fn() }) };
+});
+
+const { GroupBars } = await import("./UsageSection");
+
+const group = (key: string, label: string, input: number) => ({
+ key, label, turns: 1, input, output: 0, cachedInput: 0, costUsd: null,
+});
+
+describe("model colours in the usage breakdown", () => {
+ it("paints each model's dot and bar with the tone its provider keeps", () => {
+ const models = [
+ group("model:codex/gpt-6.1-sol", "gpt-6.1-sol", 1_000),
+ group("model:codex/gpt-6-luna", "gpt-6-luna", 800),
+ group("model:opencodeGo/opencode-go/deepseek-v4.1-flash", "deepseek-v4.1-flash", 600),
+ ];
+ const html = renderToStaticMarkup(createElement(GroupBars, { groupBy: "model", groups: models }));
+ const painted = [...html.matchAll(/data-model-color="(#[0-9a-f]{6})"/gi)].map((match) => match[1]!);
+ expect(painted).toHaveLength(6);
+ const unique = [...new Set(painted)];
+ expect(unique).toHaveLength(3);
+ for (const model of models) expect(unique).toContain(modelColor(model.key));
+ });
+
+ it("leaves the other groupings on the app's accent colour", () => {
+ const html = renderToStaticMarkup(createElement(GroupBars, { groupBy: "bot", groups: [group("bot:b1", "Scout", 1_000)] }));
+ expect(html).not.toContain("data-model-color");
+ expect(html).toContain("bg-accent/70");
+ });
+});
diff --git a/src/components/UsageSection.tsx b/src/components/UsageSection.tsx
index 38e3d14943..02487d84b2 100644
--- a/src/components/UsageSection.tsx
+++ b/src/components/UsageSection.tsx
@@ -3,6 +3,7 @@ import { ArrowLeft, ChevronRight, Download, Loader2 } from "lucide-react";
import { cn } from "@/lib/cn";
import { activeLocale, documentLanguage, t } from "@/lib/i18n";
import { listenLiveFrames } from "@/lib/live-events";
+import { modelColor, modelFamily } from "@/lib/model-color";
import { formatTokens, hasFiniteCost, headlineTokens } from "@/lib/usage";
import { fetchTraces, formatCost, formatDuration, USAGE_PERIODS, usageExportHref, usagePeriodRange, type UsagePeriod } from "@/lib/usage-trace";
import { api, useStore } from "@/state/store";
@@ -87,14 +88,17 @@ export function GroupBars({ groupBy, groups }: { groupBy: UsageGroupBy; groups:
<ul className="flex flex-col gap-2.5">
{top.map((group) => {
const bot = groupBy === "bot" ? state.bots.find((item) => `bot:${item.id}` === group.key) : undefined;
+ const family = groupBy === "model" ? modelFamily(group.key) : undefined;
+ const color = family ? modelColor(group.key) : undefined;
return (
<li key={group.key} className="grid grid-cols-[minmax(0,9rem)_1fr_auto] items-center gap-3 text-[13px]" title={t("usage.page.turns", { count: String(group.turns) })}>
<span className="flex min-w-0 items-center gap-2 text-ink">
{bot && <BotAvatar bot={bot} state="idle" size={18} animated={false} />}
+ {family && <span aria-hidden="true" title={family.label} data-model-color={color} className="size-2 shrink-0 rounded-full" style={{ backgroundColor: color }} />}
<span className="truncate">{groupBy === "model" ? modelName(group.label, state.instances) : usageGroupLabel(groupBy, group)}</span>
</span>
<span className="h-2 overflow-hidden rounded-full bg-raised">
- <span className="block h-full rounded-full bg-accent/70" style={{ width: `${Math.max(2, (headlineTokens(group) / max) * 100)}%` }} />
+ <span data-model-color={color} className={cn("block h-full rounded-full", !color && "bg-accent/70")} style={{ width: `${Math.max(2, (headlineTokens(group) / max) * 100)}%`, backgroundColor: color }} />
</span>
<span className="min-w-[4.5rem] text-right tabular-nums text-ink-secondary">
{formatTokens(headlineTokens(group))}
diff --git a/src/lib/model-color.test.ts b/src/lib/model-color.test.ts
new file mode 100644
index 0000000000..45a2521251
--- /dev/null
+++ b/src/lib/model-color.test.ts
@@ -0,0 +1,96 @@
+import { describe, expect, it } from "vitest";
+import { contrastRatio, toOklch } from "./color-contrast";
+import { MODEL_PALETTE, modelColor, modelFamily, modelIdOf } from "./model-color";
+
+const HEX = /^#[0-9a-f]{6}$/i;
+const SURFACES = ["#ffffff", "#3a322d"] as const;
+const hueGap = (a: number, b: number): number => Math.abs((((a - b) % 360) + 540) % 360 - 180);
+
+function rgb(hex: string): [number, number, number] {
+ return [1, 3, 5].map((offset) => Number.parseInt(hex.slice(offset, offset + 2), 16)) as [number, number, number];
+}
+
+function distance(a: string, b: string): number {
+ const left = rgb(a);
+ const right = rgb(b);
+ return Math.hypot(left[0] - right[0], left[1] - right[1], left[2] - right[2]);
+}
+
+describe("model colours", () => {
+ it("strips the driver from a group key, including a model id that carries a slash of its own", () => {
+ expect(modelIdOf("model:codex/gpt-6.1-sol")).toBe("gpt-6.1-sol");
+ expect(modelIdOf("model:opencodeGo/opencode-go/deepseek-v4.1-flash")).toBe("opencode-go/deepseek-v4.1-flash");
+ expect(modelIdOf("model:claude-no-driver")).toBe("claude-no-driver");
+ expect(modelIdOf("bot:b1")).toBe("bot:b1");
+ });
+
+ it("keeps the same colour for a model on every driver and period", () => {
+ expect(modelColor("model:codex/gpt-6.1-sol")).toBe(modelColor("model:openai/gpt-6.1-sol"));
+ expect(modelColor("model:opencodeGo/opencode-go/deepseek-v4.1-flash")).toBe(modelColor("model:deepseek/deepseek-v4.1-flash"));
+ expect(modelColor("model:opencode/beam-free")).toBe(modelColor("model:opencode/beam"));
+ });
+
+ it("names the provider of the models seen in the ledger", () => {
+ expect(modelFamily("model:opencodeGo/opencode-go/deepseek-v4.1-flash").id).toBe("deepseek");
+ expect(modelFamily("model:codex/gpt-6.1-sol").id).toBe("openai");
+ expect(modelFamily("model:opencodeGo/opencode/crouton-alpha-free").id).toBe("opencode");
+ expect(modelFamily("model:grok/grok-4").id).toBe("xai");
+ expect(modelFamily("model:claude/claude-sonnet-5").id).toBe("anthropic");
+ expect(modelFamily("model:test/aya").id).toBe("cohere");
+ expect(modelFamily("model:test/playa").id).toBe("unknown");
+ expect(modelFamily("model:test/mystery-model").id).toBe("unknown");
+ });
+
+ it("gives each provider family its own colour", () => {
+ const colors = [
+ "model:claude/claude-sonnet-5",
+ "model:codex/gpt-6.1-sol",
+ "model:grok/grok-4",
+ "model:opencode-go/deepseek-v4.1-flash",
+ "model:opencode-go/glm-5.3-flash",
+ ].map(modelColor);
+ expect(new Set(colors).size).toBe(colors.length);
+ });
+
+ it("shades models from one provider close together but apart", () => {
+ const pairs = [
+ ["model:codex/gpt-6.1-sol", "model:codex/gpt-6-luna"],
+ ["model:claude/claude-sonnet-5", "model:claude/claude-opus-5-5"],
+ ["model:opencode/beam", "model:opencode/big-pickle"],
+ ];
+ for (const [left, right] of pairs) {
+ const a = modelColor(left!);
+ const b = modelColor(right!);
+ expect(a, `${left} and ${right} should not share a tone`).not.toBe(b);
+ const oa = toOklch(a);
+ const ob = toOklch(b);
+ expect(Math.abs(oa.l - ob.l), `${left} and ${right} should stay in one family`).toBeLessThan(0.09);
+ expect(hueGap(oa.h, ob.h), `${left} and ${right} should stay in one family`).toBeLessThan(15);
+ expect(distance(a, b), `${left} and ${right} should be visible side by side`).toBeGreaterThan(20);
+ }
+ });
+
+ it("falls back to a stable tone for an unknown model", () => {
+ const color = modelColor("model:acme/mystery-model");
+ expect(color).toMatch(HEX);
+ expect(modelColor("model:acme/mystery-model")).toBe(color);
+ expect(modelColor("model:acme/Mystery-Model")).toBe(color);
+ });
+
+ it("keeps every family colour and every shade readable on the light and the dark ground", () => {
+ for (const base of MODEL_PALETTE) {
+ expect(base).toMatch(HEX);
+ for (const surface of SURFACES) expect(contrastRatio(base, surface)).toBeGreaterThanOrEqual(3);
+ }
+ const models = [
+ "claude-sonnet-5", "claude-opus-5-5", "gpt-6.1-sol", "gpt-6-luna", "grok-4", "deepseek-v4.1-flash",
+ "gemini-3.8-pro", "qwen3", "mistral-large", "llama-4", "kimi-k2", "glm-5.3-flash", "minimax-m2",
+ "command-r", "sonar-pro", "nova-pro", "phi-5", "nemotron", "crouton-alpha", "beam", "big-pickle", "mystery-model",
+ ];
+ for (const model of models) {
+ const color = modelColor(`model:test/${model}`);
+ expect(color, model).toMatch(HEX);
+ for (const surface of SURFACES) expect(contrastRatio(color, surface), `${model} on ${surface}`).toBeGreaterThanOrEqual(3);
+ }
+ });
+});
diff --git a/src/lib/model-color.ts b/src/lib/model-color.ts
new file mode 100644
index 0000000000..0178677468
--- /dev/null
+++ b/src/lib/model-color.ts
@@ -0,0 +1,159 @@
+import { contrastRatio, fromOklch, toOklch } from "./color-contrast";
+
+/**
+ * The colour a model keeps in the usage breakdown: a shade of the predominant
+ * colour of its provider. Models from one provider stay in the same family of
+ * hues and differ only in a small, deterministic step of hue, lightness and
+ * chroma, so the list reads as one provider with distinct members instead of a
+ * rainbow of unrelated colours.
+ */
+export interface ModelFamily {
+ id: string;
+ label: string;
+ color: string;
+}
+
+interface FamilyRule extends ModelFamily {
+ pattern: RegExp;
+}
+
+const FAMILIES: readonly FamilyRule[] = [
+ { id: "anthropic", label: "Anthropic", color: "#D97757", pattern: /claude|anthropic|sonnet|opus|haiku/i },
+ { id: "openai", label: "OpenAI", color: "#0C9A76", pattern: /gpt|openai|chatgpt|codex|^o[134](?:-|$)/i },
+ { id: "xai", label: "xAI", color: "#7D8794", pattern: /grok|xai/i },
+ { id: "deepseek", label: "DeepSeek", color: "#4C7DFF", pattern: /deepseek/i },
+ { id: "google", label: "Google", color: "#9A6BE0", pattern: /gemini|google|gemma/i },
+ { id: "qwen", label: "Qwen", color: "#D0634A", pattern: /qwen|tongyi|qwq/i },
+ { id: "mistral", label: "Mistral", color: "#B88A12", pattern: /mistral|codestral|devstral|magistral|pixtral/i },
+ { id: "meta", label: "Meta", color: "#D8578F", pattern: /llama|meta-|^meta$/i },
+ { id: "kimi", label: "Kimi", color: "#1E93AA", pattern: /kimi|moonshot/i },
+ { id: "zai", label: "Z.ai", color: "#7274F2", pattern: /glm|zhipu|z-ai|chatglm/i },
+ { id: "minimax", label: "MiniMax", color: "#E05C7A", pattern: /minimax/i },
+ { id: "cohere", label: "Cohere", color: "#B563D0", pattern: /command-r|cohere|(?:^|[-/])aya(?:[-/]|$)/i },
+ { id: "perplexity", label: "Perplexity", color: "#2F97A6", pattern: /sonar|perplexity/i },
+ { id: "amazon", label: "Amazon", color: "#C77C02", pattern: /nova|amazon|titan/i },
+ { id: "microsoft", label: "Microsoft", color: "#2C90DE", pattern: /(?:^|[-/])phi|microsoft/i },
+ { id: "nvidia", label: "NVIDIA", color: "#5E8C00", pattern: /nemotron|nvidia/i },
+ { id: "opencode", label: "OpenCode", color: "#6F8B9A", pattern: /opencode|big-pickle|crouton|beam/i },
+ { id: "nous", label: "Nous Research", color: "#8A6FD1", pattern: /hermes/i },
+ { id: "cursor", label: "Cursor", color: "#74818C", pattern: /cursor|composer/i },
+ { id: "factory", label: "Factory", color: "#7B8794", pattern: /droid/i },
+ { id: "greenference", label: "Greenference", color: "#3F8F5F", pattern: /greenference/i },
+ { id: "unknown", label: "Other", color: "#76828F", pattern: /$^/ },
+];
+
+/** Every family's base tone, for the contrast guard in the tests. */
+export const MODEL_PALETTE: readonly string[] = FAMILIES.map((family) => family.color);
+
+const DRIVER_FAMILIES: ReadonlyArray<readonly [RegExp, string]> = [
+ [/claude|anthropic/i, "anthropic"],
+ [/codex|openai/i, "openai"],
+ [/grok|xai/i, "xai"],
+ [/opencode/i, "opencode"],
+ [/gemini|antigravity/i, "google"],
+ [/qwen/i, "qwen"],
+ [/kimi/i, "kimi"],
+ [/mistral/i, "mistral"],
+ [/deepseek/i, "deepseek"],
+ [/copilot/i, "microsoft"],
+ [/cursor/i, "cursor"],
+ [/command/i, "cohere"],
+ [/droid/i, "factory"],
+ [/hermes/i, "nous"],
+ [/greenference/i, "greenference"],
+];
+
+const GATEWAY = /^(?:opencode-go|opencode|zen|openrouter|vercel|groq|fireworks(?:-ai)?|together(?:_ai)?|deepinfra|cerebras|togetherai|ollama|lmstudio|local)\//;
+
+/** The model id inside a usage group key (`model:<driver>/<model>`), or the key itself. */
+export function modelIdOf(groupKey: string): string {
+ if (!groupKey.startsWith("model:")) return groupKey;
+ const rest = groupKey.slice("model:".length);
+ const slash = rest.indexOf("/");
+ return slash === -1 ? rest : rest.slice(slash + 1);
+}
+
+function driverOf(groupKey: string): string | undefined {
+ if (!groupKey.startsWith("model:")) return undefined;
+ const rest = groupKey.slice("model:".length);
+ const slash = rest.indexOf("/");
+ return slash === -1 ? undefined : rest.slice(0, slash);
+}
+
+/** The model name without the gateway prefix or the free/beta marker, so the same model keeps one tone on every engine. */
+function coreModelId(model: string): string {
+ let id = model.trim().toLowerCase();
+ if (GATEWAY.test(id)) id = id.replace(GATEWAY, "");
+ return id.replace(/(?::|-)(?:free|beta|preview|latest)$/, "");
+}
+
+export function modelFamily(groupKey: string): ModelFamily {
+ const model = coreModelId(modelIdOf(groupKey));
+ const known = FAMILIES.find((family) => family.pattern.test(model));
+ if (known) return known;
+ const driver = driverOf(groupKey);
+ const fallback = driver && DRIVER_FAMILIES.find(([pattern]) => pattern.test(driver))?.[1];
+ return FAMILIES.find((family) => family.id === fallback) ?? FAMILIES.find((family) => family.id === "unknown")!;
+}
+
+/** Murmur3's mixing over the model name: a small change in the name moves the tone to an unrelated step. */
+function hash32(text: string): number {
+ let hash = 2166136261;
+ for (let index = 0; index < text.length; index += 1) {
+ let chunk = text.charCodeAt(index);
+ chunk = Math.imul(chunk, 0xcc9e2d51);
+ chunk = (chunk << 15) | (chunk >>> 17);
+ chunk = Math.imul(chunk, 0x1b873593);
+ hash ^= chunk;
+ hash = (hash << 13) | (hash >>> 19);
+ hash = (Math.imul(hash, 5) + 0xe6546b64) >>> 0;
+ }
+ hash ^= text.length;
+ hash ^= hash >>> 16;
+ hash = Math.imul(hash, 0x85ebca6b);
+ hash ^= hash >>> 13;
+ hash = Math.imul(hash, 0xc2b2ae35);
+ hash ^= hash >>> 16;
+ return hash >>> 0;
+}
+
+const SHADE_SALT = "shade428:";
+const HUE_STEPS = [-7, -4.7, -2.3, 0, 2.3, 4.7, 7] as const;
+const LIGHT_STEPS = [-0.045, -0.03, -0.015, 0, 0.015, 0.03, 0.045] as const;
+const CHROMA_STEPS = [0.93, 1, 1.07] as const;
+const SURFACES = ["#ffffff", "#3a322d"] as const;
+const MIN_CONTRAST = 3.05;
+
+function readsOnBoth(hex: string): boolean {
+ return SURFACES.every((surface) => contrastRatio(hex, surface) >= MIN_CONTRAST);
+}
+
+/** Keeps a tone legible on the light and the dark grounds, moving lightness only as much as it has to. */
+function readableTone(hex: string, fallback: string): string {
+ if (readsOnBoth(hex)) return hex;
+ const base = toOklch(hex);
+ for (let step = 0; step <= 140; step += 1) {
+ for (const direction of [-1, 1] as const) {
+ const lightness = base.l + direction * step * 0.002;
+ if (lightness < 0.2 || lightness > 0.95) continue;
+ const candidate = fromOklch({ ...base, l: lightness });
+ if (readsOnBoth(candidate)) return candidate;
+ }
+ }
+ return fallback;
+}
+
+function shadeOf(model: string, family: ModelFamily): string {
+ const base = toOklch(family.color);
+ const index = hash32(`${SHADE_SALT}${model}`) % (HUE_STEPS.length * LIGHT_STEPS.length * CHROMA_STEPS.length);
+ const hue = base.h + HUE_STEPS[index % HUE_STEPS.length]!;
+ const lightness = base.l + LIGHT_STEPS[Math.floor(index / HUE_STEPS.length) % LIGHT_STEPS.length]!;
+ const chroma = base.c * CHROMA_STEPS[Math.floor(index / (HUE_STEPS.length * LIGHT_STEPS.length)) % CHROMA_STEPS.length]!;
+ return readableTone(fromOklch({ l: lightness, c: chroma, h: hue }), family.color);
+}
+
+/** The colour of a model, stable across drivers, periods and the other models in the list. */
+export function modelColor(groupKey: string): string {
+ const family = modelFamily(groupKey);
+ return shadeOf(coreModelId(modelIdOf(groupKey)) || groupKey.toLowerCase(), family);
+}