Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
0.9.8: seven small budget and badge fixes (pixel-fixes-098) (#582)
Oleksandr Ivanchenkobcfe681083e6
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 906dd1b9..616f5aab 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -159,7 +159,7 @@ import { isNotificationOpen, placeOfNotification, showDeviceNotification } fromimport { requestSpendStopFocus } from './spendStop';import { SpendStopNeedsYou } from './components/SpendStop';import { BudgetNeedsYou } from './components/BotBudget';-import { budgetStore, isBudgetMessage, requestBudgetFocus } from './botBudget';+import { budgetStore, isBudgetMessage, requestBudgetFocus, sendWaitsForBudget } from './botBudget';import { EMPTY_PILL, NUDGES_SETTING_EVENT, browserIconDoc, createArrivals, createNudgeIcon, nudgesEnabled, pillAdd, pillPrune, setAppBadgeCount, shouldPill, type Nudge, type PillState } from './attention';import { NeedsYouPill } from './components/NeedsYouPill';import { DevModeError, devApi, devStore, devTeamRefs } from './devMode';@@ -1855,13 +1855,18 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({setDiscussionState({ inProgress: false });setRoutingState(null);}- streamingContextIdRef.current = targetId;- if (!(targetId in liveRef.current)) {- streamsRef.current[targetId] = { text: '', thinking: '' };- setStreamingText('');- setStreamingThinking('');+ // A bot paused at its monthly budget: the message is saved and waits, and nothing starts (QA F1), so+ // no "getting started", timer or Stop. Continue starts the turn, and its events show it working.+ const budgetWait = (): boolean => !threadId && !isTargetChannel && sendWaitsForBudget(budgetStore.get().byBot, targetId);+ if (!budgetWait()) {+ streamingContextIdRef.current = targetId;+ if (!(targetId in liveRef.current)) {+ streamsRef.current[targetId] = { text: '', thinking: '' };+ setStreamingText('');+ setStreamingThinking('');+ }+ markLive(targetId, speakerName);}- markLive(targetId, speakerName);// Optimistically add user messageconst tempId = `temp-${Date.now()}`;@@ -1911,6 +1916,11 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({throw new Error(message);}const reply = await res.json().catch(() => null);+ // Paused while this was on its way (the list caught up since): drop the working state it started+ if (budgetWait() && turnsIn(turnsRef.current, targetId).length === 0) {+ clearLive(targetId);+ if (streamingContextIdRef.current === targetId) streamingContextIdRef.current = null;+ }const held = heldFromReply(reply, tempId);if (held) {// H3: saved, but no turn starts yet, so no "thinking" for it; the line under the message says why.diff --git a/frontend/src/botBudget.ts b/frontend/src/botBudget.tsindex 2adb0c3f..14835477 100644--- a/frontend/src/botBudget.ts+++ b/frontend/src/botBudget.ts@@ -292,6 +292,15 @@ export function budgetsNeedingYou(list: readonly BotBudget[]): BotBudget[] {return list.filter((b) => b.state === 'paused' || b.state === 'warn').sort((a, b) => (a.state === b.state ? b.percent - a.percent : a.state === 'paused' ? -1 : 1));}+/**+ * A message to this bot waits for its budget: the server saves and parks it, and no turn starts until+ * Continue, a raise or next month (0.9.5 QA F1). The chat shows no working state for it (no timer, no+ * Stop); the pause bar is what's on screen. A channel or team message isn't one bot's, so never.+ */+export function sendWaitsForBudget(byBot: Readonly<Record<string, BotBudget>>, kwantId: string | null | undefined): boolean {+ return !!kwantId && isPaused(byBot[kwantId]);+}+// ---------------------------------------------------------------- chat linesexport const BUDGET_KINDS = ['bot_budget_stopped', 'bot_budget_warn', 'bot_budget_resumed', 'bot_budget_continued'] as const;@@ -304,8 +313,12 @@ export interface BudgetNoticeMeta {month: string;percent: number;detail: string;+ /** The counts when the line was posted (the server's meta), so the 80% line keeps "3k of 3.8k" after more turns. */+ at: UsedAt | null;}+export type UsedAt = Pick<BotBudget, 'over' | 'used_tokens' | 'budget_tokens' | 'used_usd' | 'budget_usd' | 'month' | 'estimated'>;+function metaObject(meta: unknown): Record<string, unknown> | null {if (!meta) return null;if (typeof meta === 'object') return meta as Record<string, unknown>;@@ -322,7 +335,19 @@ function metaObject(meta: unknown): Record<string, unknown> | null {export function parseBudgetNotice(meta: unknown): BudgetNoticeMeta | null {const o = metaObject(meta);if (!o || !BUDGET_KINDS.includes(o.kind as BudgetKind) || typeof o.kwant_id !== 'string') return null;- return { kind: o.kind as BudgetKind, kwant_id: o.kwant_id, kwant_name: str(o.kwant_name), month: str(o.month), percent: num(o.percent), detail: str(o.detail) };+ const at: UsedAt | null =+ typeof o.used_tokens === 'number' || typeof o.used_usd === 'number'+ ? {+ over: o.over === 'tokens' || o.over === 'usd' ? o.over : null,+ used_tokens: num(o.used_tokens),+ budget_tokens: num(o.budget_tokens),+ used_usd: num(o.used_usd),+ budget_usd: num(o.budget_usd),+ month: str(o.month),+ estimated: o.estimated === true,+ }+ : null;+ return { kind: o.kind as BudgetKind, kwant_id: o.kwant_id, kwant_name: str(o.kwant_name), month: str(o.month), percent: num(o.percent), detail: str(o.detail), at };}/** True for any message that changes a bot's budget state, so the shared list is re-read. */diff --git a/frontend/src/components/BotBudget.tsx b/frontend/src/components/BotBudget.tsxindex 81a33b21..6db4a608 100644--- a/frontend/src/components/BotBudget.tsx+++ b/frontend/src/components/BotBudget.tsx@@ -145,6 +145,7 @@ export const PausedActions: React.FC<{const focusComposer = () => document.querySelector<HTMLTextAreaElement>('[data-composer-form] textarea')?.focus();/** Above the composer in a paused bot's chat: why nothing new starts, and the way on. */+// The second line is balanced so "again." never sits alone on a line at 1280 (Mira, 0.9.5 follow-up 4)export const BudgetPausedBanner: React.FC<{ budget: BotBudget; onRaise?: (kwantId: string) => void; send?: typeof fetch }> = ({ budget, onRaise, send }) => {const id = `budget-banner-${budget.kwant_id}`;return (@@ -158,7 +159,7 @@ export const BudgetPausedBanner: React.FC<{ budget: BotBudget; onRaise?: (kwantI<PauseCircle size={14} className="shrink-0 text-amber-400" aria-hidden="true" />{PAUSED_LINE}</p>- <p className="mt-0.5 pl-[22px] text-[11px] text-amber-200/70">{usedLine(budget)}. Your message waits and goes through once it can start again.</p>+ <p className="mt-0.5 pl-[22px] text-[11px] text-amber-200/70 text-balance" data-budget-banner-detail>{usedLine(budget)}. Your message waits and goes through once it can start again.</p></div><PausedActions budget={budget} onRaise={onRaise} onContinued={focusComposer} describedBy={id} send={send} /></section>@@ -181,6 +182,9 @@ export const BudgetNotice: React.FC<{// Only this month's line still has a way on; an older one stays as a recordconst current = !!live && live.month === meta.month;const stopped = meta.kind === 'bot_budget_stopped';+ // The 80% line is a record of the crossing: its numbers are the ones it was posted with, never the live count+ // (0.9.5 QA F2). The stop notice keeps the live count while it still has Continue on it.+ const usage = !stopped ? (meta.at ? usedLine(meta.at) : meta.detail) : current ? usedLine(live) : meta.detail;return (<sectiondata-message-id={messageId}@@ -198,7 +202,7 @@ export const BudgetNotice: React.FC<{)}<span className="min-w-0">{text}</span></p>- {(current || meta.detail) && <p className="mt-1 pl-[23px] text-[11px] text-amber-200/60 font-mono">{current ? usedLine(live) : meta.detail}</p>}+ {usage && <p className="mt-1 pl-[23px] text-[11px] text-amber-200/60 font-mono">{usage}</p>}</div>{canAct && current && stopped && (live.state === 'paused' || live.state === 'continued') && (<PausedActions budget={live} onRaise={onRaise} describedBy={headingId} send={send} />@@ -242,7 +246,11 @@ export const BudgetNeedsYou: React.FC<{ onRaise?: (kwantId: string) => void; senconst done = continued.has(b.kwant_id);const live = list?.bots.find((x) => x.kwant_id === b.kwant_id) ?? b;return (- <li key={b.kwant_id} data-needs-budget-item={done ? 'continued' : b.state} className="rounded-xl border border-amber-500/30 bg-amber-950/20 px-3.5 py-2.5 sm:px-4">+ <li+ key={b.kwant_id}+ data-needs-budget-item={done ? 'continued' : b.state}+ className={`rounded-xl border px-3.5 py-2.5 sm:px-4 ${done ? 'border-zinc-800 bg-zinc-900/40' : 'border-amber-500/30 bg-amber-950/20'}`}+ ><div className="flex flex-wrap items-center gap-x-3 gap-y-2"><div className="min-w-0 flex-1 basis-56">{done ? (@@ -262,9 +270,10 @@ export const BudgetNeedsYou: React.FC<{ onRaise?: (kwantId: string) => void; sen</span></p>)}+ {/* Done after Continue: no amber and no meter, just what was used (Mira, 0.9.5 follow-up 1) */}<div className="mt-1.5 pl-[23px] flex flex-wrap items-center gap-x-2 gap-y-1">- <BudgetMeter budget={b} className="max-w-[160px]" />- <span className="min-w-0 break-words text-[11px] text-amber-200/60 font-mono">{usedLine(b)}</span>+ {!done && <BudgetMeter budget={b} className="max-w-[160px]" />}+ <span className={`min-w-0 break-words text-[11px] font-mono ${done ? 'text-zinc-500' : 'text-amber-200/60'}`}>{usedLine(b)}</span></div></div>{paused ? (@@ -519,12 +528,13 @@ export const BotBudgetSection: React.FC<{ kwantId: string; kwantName: string; se// ---------------------------------------------------------------- Settings › Usage-const STATE_CHIP: Record<BotBudget['state'], { text: string; tone: string }> = {- off: { text: 'No budget', tone: 'text-zinc-500 border-zinc-800' },- under: { text: 'On track', tone: 'text-zinc-300 border-zinc-700' },- warn: { text: '% used', tone: 'text-amber-200 border-amber-500/40 bg-amber-500/10' },- paused: { text: 'Paused', tone: 'text-amber-100 border-amber-500/60 bg-amber-500/20' },- continued: { text: 'Continued', tone: 'text-zinc-300 border-zinc-700' },+/** The chip on each bot's row: its words follow the budget (the 80% one says how much is used). */+const STATE_CHIP: Record<BotBudget['state'], { text: (b: BotBudget) => string; tone: string }> = {+ off: { text: () => 'No budget', tone: 'text-zinc-500 border-zinc-800' },+ under: { text: () => 'On track', tone: 'text-zinc-300 border-zinc-700' },+ warn: { text: (b) => `${meterPercent(b)}% used`, tone: 'text-amber-200 border-amber-500/40 bg-amber-500/10' },+ paused: { text: () => 'Paused', tone: 'text-amber-100 border-amber-500/60 bg-amber-500/20' },+ continued: { text: () => 'Continued', tone: 'text-zinc-300 border-zinc-700' },};/** Every bot in this space with its budget and this month's use. */@@ -564,7 +574,7 @@ export const BudgetOverview: React.FC<{ open: boolean; onOpenBot?: (kwantId: strreturn (<li key={b.kwant_id} className="flex flex-wrap lg:flex-nowrap items-center gap-x-3 gap-y-1 px-3 py-2" data-budget-row={b.state}><span className="min-w-0 flex-1 basis-32 truncate text-[11px] font-medium text-zinc-200">{b.kwant_name || 'Unnamed bot'}</span>- <span className={`shrink-0 rounded-full border px-1.5 py-px text-[10px] ${chip.tone}`}>{b.state === 'warn' ? `${meterPercent(b)}% used` : chip.text}</span>+ <span className={`shrink-0 rounded-full border px-1.5 py-px text-[10px] ${chip.tone}`}>{chip.text(b)}</span><span className="basis-full sm:order-last lg:order-none lg:basis-auto lg:w-80 flex items-center gap-2 min-w-0">{hasBudget(b) && <BudgetMeter budget={b} className="max-w-[72px]" />}<span className="min-w-0 break-words font-mono text-[11px] tabular-nums text-zinc-400">diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsxindex 46628992..05b3cdb8 100644--- a/frontend/src/components/Sidebar.tsx+++ b/frontend/src/components/Sidebar.tsx@@ -3,7 +3,7 @@ import { Hash, Plus, CheckCircle2, ShieldCheck, KeyRound, Loader2, Users, Chevroimport { ModernAvatar, useModelBadge } from './ModernAvatar';import { playSfx } from '../audio/chiptune';import { badgeText } from '../away';-import { canRunNow, engineTip, isUsable, type RunsOn } from '../engines';+import { canRunNow, engineTip, isUsable, pinnedCantRun, type RunsOn } from '../engines';import { statusOf, statusText, type BotStatus } from '../botStatus';import { EnginesApi, useEngines } from '../useEngines';import { claudeNeedsSignIn } from '../claudeLogin';@@ -572,7 +572,9 @@ export const Sidebar: React.FC<SidebarProps> = ({const attLine = att && (att.rank === 2 || att.rank === 3 || att.rank === 4 || (att.rank === 1 && att.review)) ? att.line : undefined;const attTone = !att ? '' : att.rank === 1 ? 'text-warn' : att.rank === 2 ? 'text-rose-300' : att.rank === 3 ? 'text-[#7dd3fc]' : 'text-zinc-200';const attDot = !att ? '' : att.rank === 1 ? 'kw-status-warn' : att.rank === 2 ? 'bg-rose-400' : att.rank === 3 ? 'bg-[#38bdf8]' : 'bg-teal-400';- const status = asked ? 'needs_you' : statusOf(k.id, botStatus, canRun);+ // Pinned to an engine that can't run, with failover off: its turn would fail, so no green dot+ const pinnedTip = pinnedCantRun(k, engines.engines);+ const status = asked ? 'needs_you' : statusOf(k.id, botStatus, pinnedTip ? false : canRun);const isLead = !!team && k.id === team.lead_kwant_id;const canRemove = !!team && !isLead && !!onUpdateTeamMembers;const hasRowActions = !!onEditKwant || canRemove;@@ -626,7 +628,7 @@ export const Sidebar: React.FC<SidebarProps> = ({active ? 'bg-accent-soft text-zinc-50 shadow-card border border-sky-300/25' : 'text-zinc-300 hover:text-zinc-50 hover:bg-white/[0.05] border border-transparent'}`}>- <span className="shrink-0" title={status === 'cant_run' ? "Can't run yet: no account works here" : statusText(k.name, status)}>+ <span className="shrink-0" title={status === 'cant_run' ? pinnedTip ?? "Can't run yet: no account works here" : statusText(k.name, status)}><ModernAvatar role={k.avatar_sprite} name={k.name} size={chat ? 32 : 28} status={status} kwantId={k.id} /></span><div className="flex-1 min-w-0">diff --git a/frontend/src/engines.ts b/frontend/src/engines.tsindex 3822fd67..6e047ede 100644--- a/frontend/src/engines.ts+++ b/frontend/src/engines.ts@@ -488,6 +488,20 @@ export function modelBadgeFor(};}+/**+ * Why a bot pinned to one engine can't run now, or null when it can (or it isn't pinned). Only with failover+ * off: with failover on, a signed-out engine's turn moves on and really runs, so the dot stays green.+ * The words are the badge's own tip, "Runs on Grok · signed out" (0.9.7 model-badge QA).+ */+export function pinnedCantRun(+ kwant: { preferred_model?: string | null; profile_failover?: boolean } | null | undefined,+ engines: EngineInfo[] | null | undefined,+): string | null {+ if (!kwant || kwant.profile_failover !== false) return null;+ const badge = modelBadgeFor({ preferred_model: kwant.preferred_model }, null, engines ?? null);+ return badge && !badge.auto && badge.cantRun ? badge.label : null;+}+/** The badge's diameter for an avatar of `size` px: none under 24, 14 at 28–34, larger on big avatars. */export function modelBadgeSize(size: number): number | null {if (size < 24) return null;diff --git a/frontend/tests/botBudget.test.mjs b/frontend/tests/botBudget.test.mjsindex 13df883e..82abf4c6 100644--- a/frontend/tests/botBudget.test.mjs+++ b/frontend/tests/botBudget.test.mjs@@ -463,3 +463,89 @@ test('F3 and F6 overview: 44 px phone targets, "N% used" chip, readable no-budgeassert.equal(src2.match(/min-h-\[44px\] sm:min-h-0 px-2 -mx-2/g)?.length, 2, 'both Retry buttons');assert.match(src2, /text-\[11px\] text-zinc-400" data-budget-none/);});++// ---------------------------------------------------------------- 0.9.8 follow-ups (pixel-fixes-098)++test('0.9.8 #1: a send to a paused bot shows no working state; the app checks before it marks the chat live', async () => {+ const { send } = fake({ 'GET /api/usage/budgets': [200, LIST([PAUSED, B({ kwant_id: 'k3', kwant_name: 'Vega', percent: 86 }), OFF])] });+ m.budgetStore.reset(send);+ await m.budgetStore.refresh();+ const { byBot } = m.budgetStore.get();+ assert.equal(m.sendWaitsForBudget(byBot, 'k1'), true, 'paused: the message waits, nothing starts');+ assert.equal(m.sendWaitsForBudget(byBot, 'k3'), false, '80% still runs');+ assert.equal(m.sendWaitsForBudget(byBot, 'k2'), false, 'no budget');+ assert.equal(m.sendWaitsForBudget(byBot, 'nobody'), false);+ assert.equal(m.sendWaitsForBudget(byBot, null), false);+ m.budgetStore.put(m.parseBudget({ ...PAUSED, state: 'continued' }));+ assert.equal(m.sendWaitsForBudget(m.budgetStore.get().byBot, 'k1'), false, 'after Continue it starts as before');+ // Wiring: in handleSendMessage the check guards markLive (no "getting started", timer or Stop) and runs+ // again on the reply, so a pause that the list learnt of meanwhile clears the working state it started.+ const app = src('App.tsx');+ const sendFn = app.slice(app.indexOf('const handleSendMessage = async'), app.indexOf('const handleChangeDecision'));+ const guard = sendFn.indexOf('if (!budgetWait()) {');+ assert.ok(guard > 0 && guard < sendFn.indexOf('markLive(targetId, speakerName)'), 'markLive sits inside the budget check');+ assert.match(sendFn, /!threadId && !isTargetChannel && sendWaitsForBudget\(budgetStore\.get\(\)\.byBot, targetId\)/);+ assert.match(sendFn, /if \(budgetWait\(\) && turnsIn\(turnsRef\.current, targetId\)\.length === 0\) \{\n\s+clearLive\(targetId\);/);+});++test('0.9.8 #2: the 80% line keeps the numbers it was posted with, not the live count', async () => {+ // The bot crossed 80% at 3k of 3.8k; it has since used 6k (paused, then continued)+ const live = B({ used_tokens: 6000, budget_tokens: 3800, percent: 158, over: 'tokens', state: 'continued' });+ const { send } = fake({ 'GET /api/usage/budgets': [200, LIST([live])] });+ m.budgetStore.reset(send);+ await m.budgetStore.refresh();+ const meta = m.parseBudgetNotice(+ JSON.stringify({ kind: 'bot_budget_warn', kwant_id: 'k1', kwant_name: 'Juno', month: '2026-11', percent: 80, over: null, used_tokens: 3000, budget_tokens: 3800, used_usd: 0, budget_usd: 0, estimated: false, detail: '3k of 3.8k fresh tokens in November' }),+ );+ assert.deepEqual(meta.at, { over: null, used_tokens: 3000, budget_tokens: 3800, used_usd: 0, budget_usd: 0, month: '2026-11', estimated: false });+ const older = m.parseBudgetNotice({ kind: 'bot_budget_warn', kwant_id: 'k1', kwant_name: 'Juno', month: '2026-11', percent: 80, detail: 'about 3k of 3.8k fresh tokens in November' });+ assert.equal(older.at, null, 'a line from before the counts were in meta');+ const { host, unmount } = await mount(+ h('div', null, h(m.BudgetNotice, { messageId: 'w', text: 'Juno has used 80% of its monthly budget.', meta, onRaise: () => {} }), h(m.BudgetNotice, { messageId: 'o', text: 'older', meta: older })),+ );+ const [line, old] = host.querySelectorAll('[data-budget-notice]');+ assert.match(line.textContent, /3k of 3\.8k fresh tokens in November/);+ assert.doesNotMatch(line.textContent, /6k of/);+ assert.match(old.textContent, /about 3k of 3\.8k/, 'falls back to the server’s words');+ m.budgetStore.put(m.parseBudget({ ...live, used_tokens: 9000 }));+ await settle();+ assert.match(line.textContent, /3k of 3\.8k/, 'more turns: still the crossing');+ unmount();+});++test('0.9.8 #3: the Inbox done row after Continue drops the amber and the meter', async () => {+ const { send } = fake({+ 'GET /api/usage/budgets': [200, LIST([PAUSED])],+ 'POST /api/kwants/k1/budget/continue': [200, { ...PAUSED, state: 'continued', continued_month: '2026-11' }],+ });+ m.budgetStore.reset(send);+ await m.budgetStore.refresh();+ const { host, unmount } = await mount(h(m.BudgetNeedsYou, { onRaise: () => {}, send }));+ let row = host.querySelector('[data-needs-budget-item]');+ assert.match(row.className, /border-amber-500\/30 bg-amber-950\/20/, 'paused: amber');+ assert.ok(row.querySelector('[role=meter]'));+ await click(host.querySelector('[data-budget-continue]'));+ row = host.querySelector('[data-needs-budget-item]');+ assert.equal(row.dataset.needsBudgetItem, 'continued');+ assert.match(row.className, /border-zinc-800 bg-zinc-900\/40/);+ assert.doesNotMatch(row.className, /amber/);+ assert.equal(row.querySelector('[role=meter]'), null, 'no meter');+ assert.match(row.querySelector('.font-mono').className, /text-zinc-500/);+ assert.doesNotMatch(row.querySelector('.font-mono').className, /amber/);+ unmount();+});++test('0.9.8 #4 and #6: the chip words follow the budget; the bar’s second line is balanced', async () => {+ const s = src('components/BotBudget.tsx');+ assert.doesNotMatch(s, /text: '% used'/, 'no dead chip value');+ const { send } = fake({ 'GET /api/usage/budgets': [200, LIST([B({ percent: 86 }), PAUSED, OFF])] });+ m.budgetStore.reset(send);+ const { host, unmount } = await mount(h(m.BudgetOverview, { open: true }));+ await settle();+ const chips = [...host.querySelectorAll('[data-budget-row] .rounded-full.border')].map((c) => c.textContent);+ assert.deepEqual(chips, ['86% used', 'Paused', 'No budget']);+ unmount();+ const bar = await mount(h(m.BudgetPausedBanner, { budget: m.parseBudget(PAUSED), send }));+ assert.match(bar.host.querySelector('[data-budget-banner-detail]').className, /\btext-balance\b/);+ bar.unmount();+});diff --git a/frontend/tests/modelBadge.test.mjs b/frontend/tests/modelBadge.test.mjsindex 83b65b0c..f79d42ee 100644--- a/frontend/tests/modelBadge.test.mjs+++ b/frontend/tests/modelBadge.test.mjs@@ -295,3 +295,18 @@ test('turn_runs_on for a turn whose start went unseen still lets go when it endsassert.equal(m.liveRunOf('k9'), undefined);assert.equal(m.lastRunOf('k9').model, 'haiku');});++test('0.9.8 #7: a bot pinned to a signed-out engine with failover off gets no green dot; failover on keeps it', () => {+ const gout = ENGINES.map((e) => (e.id === 'grok' ? { ...e, status: 'signed_out', ready: false } : e));+ const grokBot = { preferred_model: 'grok/grok-4' };+ assert.equal(m.pinnedCantRun({ ...grokBot, profile_failover: false }, gout), 'Runs on Grok · Grok 4 · signed out', 'the badge’s own tip');+ assert.equal(m.pinnedCantRun({ ...grokBot, profile_failover: true }, gout), null, 'failover on: its turn moves on and runs');+ assert.equal(m.pinnedCantRun(grokBot, gout), null, 'unknown failover is the server default (on)');+ assert.equal(m.pinnedCantRun({ ...grokBot, profile_failover: false }, ENGINES), null, 'Grok signed in');+ assert.equal(m.pinnedCantRun({ preferred_model: 'auto', profile_failover: false }, gout), null, 'Laya picks: never pinned');+ assert.equal(m.pinnedCantRun({ ...grokBot, profile_failover: false }, null), null, 'engines not loaded yet: no claim');+ // The sidebar row passes it to the dot: can't run (grey) with the badge's tip instead of the green Available+ const side = readFileSync(new URL('../src/components/Sidebar.tsx', import.meta.url), 'utf8');+ assert.match(side, /const pinnedTip = pinnedCantRun\(k, engines\.engines\);\n\s+const status = asked \? 'needs_you' : statusOf\(k\.id, botStatus, pinnedTip \? false : canRun\);/);+ assert.match(side, /title=\{status === 'cant_run' \? pinnedTip \?\? "Can't run yet: no account works here"/);+});diff --git a/src/server/bot_budget.rs b/src/server/bot_budget.rsindex 06b367c3..bae1a2d5 100644--- a/src/server/bot_budget.rs+++ b/src/server/bot_budget.rs@@ -158,7 +158,7 @@ pub async fn status(state: &AppState, kwant: &Kwant) -> Budget {}}-/// Short token counts: 950, 1.5k, 61k, 2.04M. One decimal below 100k, like the app's `compactTokens`,+/// Short token counts: 950, 1.5k, 61k, 2M, 2.5M. One decimal below 100k, like the app's `compactTokens`,/// so 1,500 of 1,800 reads "1.5k of 1.8k", not "1k of 1k".fn short(n: u64) -> String {match n {@@ -169,7 +169,7 @@ fn short(n: u64) -> String {}100_000..=999_999 => format!("{}k", (n as f64 / 1_000.0).round() as u64),_ => {- let m = format!("{:.2}", n as f64 / 1_000_000.0);+ let m = format!("{:.1}", n as f64 / 1_000_000.0);format!("{}M", m.trim_end_matches('0').trim_end_matches('.'))}}@@ -179,7 +179,7 @@ fn month_name(month: &str) -> String {NaiveDate::parse_from_str(&format!("{month}-01"), "%Y-%m-%d").map(|d| d.format("%B").to_string()).unwrap_or_else(|_| month.to_string())}-/// "2.04M of 2M fresh tokens in November" / "$20.40 of $20.00 in November", for the limit hit+/// "2M of 2M fresh tokens in November" / "$20.40 of $20.00 in November", for the limit hit/// (or the one with the higher percentage).pub fn used_of(b: &Budget) -> String {let pt = if b.budget_tokens > 0 { b.used_tokens as f64 / b.budget_tokens as f64 } else { -1.0 };@@ -678,8 +678,11 @@ mod tests {#[test]fn short_counts() {- assert_eq!(short(2_040_000), "2.04M");+ // One decimal for millions, ".0" trimmed, like the app's compactTokens (Mira, 0.9.5 follow-up 3)+ assert_eq!(short(2_040_000), "2M");assert_eq!(short(2_000_000), "2M");+ assert_eq!(short(2_450_000), "2.5M");+ assert_eq!(short(12_340_000), "12.3M");assert_eq!(short(61_000), "61k");}