diff --git a/windows/src/App.tsx b/windows/src/App.tsx index 77281597..6b71b558 100644 --- a/windows/src/App.tsx +++ b/windows/src/App.tsx @@ -9,7 +9,7 @@ import { PayloadCache } from './lib/cache' import { relativePast } from './lib/dates' import { applyTheme, currentTheme, readSetting, writeSetting } from './lib/settings' import { TRAY_BADGE_SUPPORTED } from './lib/platform' -import { AgentTabStrip, detectedProviders } from './components/AgentTabStrip' +import { AgentTabStrip, ALL_PROVIDER, providerLabel, providerTabs } from './components/AgentTabStrip' import type { Provider } from './components/AgentTabStrip' import { ModelsSection } from './components/ModelsSection' import { InsightPills, INSIGHT_ORDER, isInsightMode, type InsightMode } from './components/InsightPills' @@ -51,7 +51,7 @@ type FetchOptions = { export function App() { const [period, setPeriod] = useState('today') - const [provider, setProvider] = useState('all') + const [provider, setProvider] = useState(ALL_PROVIDER) const [payload, setPayload] = useState(null) const [todayPayload, setTodayPayload] = useState(null) const [currency, setCurrency] = useState(USD) @@ -258,8 +258,10 @@ export function App() { writeSetting('insight', mode) } - const providers = detectedProviders(todayPayload) - const planVisible = provider === 'claude' || (provider === 'all' && providers.length === 1 && providers[0] === 'claude') + const tabs = providerTabs(todayPayload) + const detected = tabs.filter(t => t.id !== ALL_PROVIDER && t.detected) + const planVisible = provider === 'claude' + || (provider === ALL_PROVIDER && detected.length === 1 && detected[0].id === 'claude') const visibleModes = useMemo( () => INSIGHT_ORDER.filter(m => m !== 'plan' || planVisible), [planVisible], @@ -269,9 +271,9 @@ export function App() { const cliBlocked = cliStatus !== null && (!cliStatus.found || !cliStatus.compatible) // The version gate above is what keeps these fields present; the optional reads are the // backstop that turns a surprising payload into an empty state rather than a blank window. - const isFilteredEmpty = payload !== null && provider !== 'all' + const isFilteredEmpty = payload !== null && provider !== ALL_PROVIDER && (payload.current?.cost ?? 0) <= 0 && (payload.current?.calls ?? 0) === 0 - const neverAnyData = payload !== null && provider === 'all' + const neverAnyData = payload !== null && provider === ALL_PROVIDER && (payload.current?.calls ?? 0) === 0 && (payload.current?.sessions ?? 0) === 0 && (payload.history?.daily?.length ?? 0) === 0 @@ -317,7 +319,7 @@ export function App() { {isFilteredEmpty ? ( - + ) : neverAnyData ? ( refreshAll({ includeOptimize: true, showOverlay: true })} /> ) : ( diff --git a/windows/src/components/AgentTabStrip.tsx b/windows/src/components/AgentTabStrip.tsx index 2845037f..5730e323 100644 --- a/windows/src/components/AgentTabStrip.tsx +++ b/windows/src/components/AgentTabStrip.tsx @@ -1,14 +1,30 @@ -import { useRef, useState, type WheelEvent } from 'react' +import { useCallback, useEffect, useLayoutEffect, useRef, useState, type WheelEvent } from 'react' import type { MenubarPayload } from '../lib/payload' import type { CurrencyState } from '../lib/currency' import { formatCompactCurrency, formatCurrency, plural } from '../lib/currency' import { homePath } from '../lib/platform' +import { ChevronRight } from './Icons' -export type Provider = 'all' | 'claude' | 'codex' | 'cursor' | 'copilot' | 'opencode' | 'pi' +/// Any provider id the CLI reports, plus `all`. The CLI's own ids are what `--provider` +/// accepts, so a tab built from the payload is directly usable as a filter argument. +export type Provider = string -/// Same order as the macOS ProviderFilter.allCases. -export const ALL_PROVIDERS: Array<{ id: Provider; label: string; source: string }> = [ - { id: 'all', label: 'All', source: 'every detected tool' }, +export const ALL_PROVIDER: Provider = 'all' + +export type ProviderTab = { + id: Provider + label: string + cost: number + /// False only for a known tool the payload never mentioned: it stays visible, dimmed, + /// so a first-time reader can see what CodeBurn watches for. + detected: boolean + /// Where CodeBurn would find this tool, shown in the hover preview when it is missing. + source: string | null +} + +/// The tools the app can describe without any help from the payload. Used only when the CLI +/// reports no provider with activity, which is the first-run case the copy is written for. +const KNOWN_TOOLS: Array<{ id: Provider; label: string; source: string }> = [ { id: 'claude', label: 'Claude', source: `Claude Code sessions in ${homePath('.claude', 'projects')}` }, { id: 'codex', label: 'Codex', source: `Codex CLI sessions in ${homePath('.codex', 'sessions')}` }, { id: 'cursor', label: 'Cursor', source: 'the Cursor IDE local database' }, @@ -17,15 +33,76 @@ export const ALL_PROVIDERS: Array<{ id: Provider; label: string; source: string { id: 'pi', label: 'Pi', source: 'Pi session logs' }, ] -export const PROVIDER_LABELS: Record = Object.fromEntries( - ALL_PROVIDERS.map(p => [p.id, p.label]), -) as Record +/// Provider marks from mac/Sources/CodeBurnMenubar/Views/AgentTabStrip.swift (ProviderFilter +/// .color), keyed by the CLI provider id rather than the Swift case name. +const PROVIDER_COLORS: Record = { + all: '#C9521D', + claude: '#C9521D', + cline: '#238A7E', + codewhale: '#38BDF8', + codex: '#4A7D5C', + cursor: '#3F6B8C', + 'cursor-agent': '#4EC9B0', + copilot: '#6D8FA6', + devin: '#25A08D', + droid: '#7C3AED', + gemini: '#4485F4', + 'ibm-bob': '#0F62FE', + 'kilo-code': '#009688', + kiro: '#4A9EC4', + kimi: '#A4C639', + kimicode: '#A3E635', + 'lingtai-tui': '#22A7A0', + openclaw: '#DA7056', + openclaude: '#C2416B', + opencode: '#5B835B', + pi: '#B26B3D', + qwen: '#615EEB', + omp: '#8B5CB0', + 'roo-code': '#4CAF50', + crush: '#E06C9F', + antigravity: '#FF7A45', + goose: '#B78D52', + grok: '#8E8E93', + hermes: '#C7523E', + zcode: '#526ED6', +} -/// Providers the CLI detected on this machine (installed, even with zero spend today). -export function detectedProviders(payload: MenubarPayload | null): Provider[] { - if (!payload) return [] - const detected = payload.current.providers - return ALL_PROVIDERS.map(p => p.id).filter(id => id !== 'all' && id in detected) +export function providerColor(id: Provider): string { + return PROVIDER_COLORS[id] ?? 'var(--label-3)' +} + +/// The tabs for a payload: All first, then every provider the CLI saw activity for, dearest +/// first. Falls back to the known-tool list only when the payload names nobody, so a fresh +/// machine still shows what is being watched. +export function providerTabs(payload: MenubarPayload | null): ProviderTab[] { + const details = payload?.current.providerDetails ?? [] + const active = details.filter(d => d.hasUsage ?? (d.cost > 0 || (d.calls ?? 0) > 0)) + if (active.length > 0) { + const sorted = [...active].sort((a, b) => (b.cost - a.cost) || a.label.localeCompare(b.label)) + const total = sorted.reduce((sum, d) => sum + d.cost, 0) + return [ + { id: ALL_PROVIDER, label: 'All', cost: total, detected: true, source: 'every detected tool' }, + ...sorted.map(d => ({ id: d.id, label: d.label, cost: d.cost, detected: true, source: null })), + ] + } + const legacy = payload?.current.providers ?? {} + const known = KNOWN_TOOLS.map(t => ({ + id: t.id, + label: t.label, + cost: legacy[t.id] ?? 0, + detected: t.id in legacy, + source: t.source, + })) + const total = known.reduce((sum, t) => sum + t.cost, 0) + return [ + { id: ALL_PROVIDER, label: 'All', cost: total, detected: known.some(t => t.detected), source: 'every detected tool' }, + ...known, + ] +} + +export function providerLabel(tabs: ProviderTab[], id: Provider): string { + return tabs.find(t => t.id === id)?.label ?? id } type Props = { @@ -35,15 +112,13 @@ type Props = { currency: CurrencyState } -/// Every supported tool is listed so the reader can see at a glance which ones CodeBurn -/// is watching. Tools that are not installed are dimmed and explain themselves on hover; -/// detected tools show today's spend and a hover preview with their share. export function AgentTabStrip({ selected, onSelect, payload, currency }: Props) { const [hovered, setHovered] = useState(null) + const [overflowing, setOverflowing] = useState(false) + const row = useRef(null) const scroller = useRef(null) - const providers = detectedProviders(payload) - const costs = payload?.current.providers ?? {} - const total = providers.reduce((s, id) => s + (costs[id] ?? 0), 0) + const content = useRef(null) + const tabs = providerTabs(payload) const onWheel = (e: WheelEvent) => { if (scroller.current && e.deltaY !== 0 && e.deltaX === 0) { @@ -51,34 +126,90 @@ export function AgentTabStrip({ selected, onSelect, payload, currency }: Props) } } - const preview = hovered ? previewFor(hovered, providers, costs, total, currency) : null + /// The mac calls the strip overflowing 30pt before the content actually clips, so the + /// chevrons appear while there is still room for them. Both measurements are of elements + /// the chevrons do not resize, so showing them cannot feed back into the decision. + const measure = useCallback(() => { + if (row.current && content.current) { + setOverflowing(content.current.scrollWidth > row.current.clientWidth - 30) + } + }, []) + + useLayoutEffect(measure) + useEffect(() => { + const el = row.current + if (!el || typeof ResizeObserver === 'undefined') return + const observer = new ResizeObserver(measure) + observer.observe(el) + return () => observer.disconnect() + }, [measure]) + + // Keep the active tab in view, the way the mac scrolls it to centre on every change. + useEffect(() => { + scroller.current?.querySelector('[data-active="true"]') + ?.scrollIntoView({ behavior: 'smooth', block: 'nearest', inline: 'center' }) + }, [selected, tabs.length]) + + const index = Math.max(0, tabs.findIndex(t => t.id === selected)) + const step = (direction: -1 | 1) => { + const target = tabs[Math.min(Math.max(index + direction, 0), tabs.length - 1)] + if (target && target.detected) onSelect(target.id) + } + + const preview = hovered ? previewFor(hovered, tabs, currency) : null return (
setHovered(null)}> - +
+ {overflowing && ( + + )} + + {overflowing && ( + + )} +
{preview && (
{preview.title}
@@ -89,28 +220,24 @@ export function AgentTabStrip({ selected, onSelect, payload, currency }: Props) ) } -function previewFor( - id: Provider, - providers: Provider[], - costs: Record, - total: number, - currency: CurrencyState, -): { title: string; body: string } { - const meta = ALL_PROVIDERS.find(p => p.id === id)! - if (id === 'all') { - if (providers.length === 0) return { title: 'No tools detected yet', body: 'Run one of the supported tools once, then refresh.' } +function previewFor(id: Provider, tabs: ProviderTab[], currency: CurrencyState): { title: string; body: string } | null { + const tab = tabs.find(t => t.id === id) + if (!tab) return null + const others = tabs.filter(t => t.id !== ALL_PROVIDER && t.detected) + const total = tabs.find(t => t.id === ALL_PROVIDER)?.cost ?? 0 + if (id === ALL_PROVIDER) { + if (others.length === 0) return { title: 'No tools detected yet', body: 'Run one of the supported tools once, then refresh.' } return { - title: `${formatCurrency(total, currency)} today across ${plural(providers.length, 'tool')}`, - body: providers.map(p => `${PROVIDER_LABELS[p]} ${formatCompactCurrency(costs[p] ?? 0, currency)}`).join(' · '), + title: `${formatCurrency(total, currency)} today across ${plural(others.length, 'tool')}`, + body: others.map(t => `${t.label} ${formatCompactCurrency(t.cost, currency)}`).join(' · '), } } - if (!providers.includes(id)) { - return { title: `${meta.label} not detected on this machine`, body: `CodeBurn watches ${meta.source}.` } + if (!tab.detected) { + return { title: `${tab.label} not detected on this machine`, body: `CodeBurn watches ${tab.source ?? 'this tool'}.` } } - const cost = costs[id] ?? 0 - const share = total > 0 ? Math.round((cost / total) * 100) : 0 + const share = total > 0 ? Math.round((tab.cost / total) * 100) : 0 return { - title: `${meta.label} · ${formatCurrency(cost, currency)} today`, - body: cost > 0 ? `${share}% of today's spend · click to filter every view` : 'No spend yet today · click to filter every view', + title: `${tab.label} · ${formatCurrency(tab.cost, currency)} today`, + body: tab.cost > 0 ? `${share}% of today's spend · click to filter every view` : 'No spend yet today · click to filter every view', } } diff --git a/windows/src/components/EmptyProviderState.tsx b/windows/src/components/EmptyProviderState.tsx index e0843807..7babe5b0 100644 --- a/windows/src/components/EmptyProviderState.tsx +++ b/windows/src/components/EmptyProviderState.tsx @@ -1,19 +1,17 @@ -import type { Provider } from './AgentTabStrip' -import { PROVIDER_LABELS } from './AgentTabStrip' import type { Period } from './PeriodTabs' import { PERIOD_PHRASES } from './PeriodTabs' import { TrayIcon } from './Icons' type Props = { - provider: Provider + label: string period: Period } -export function EmptyProviderState({ provider, period }: Props) { +export function EmptyProviderState({ label, period }: Props) { return (
-
No {PROVIDER_LABELS[provider]} data for {PERIOD_PHRASES[period]}
+
No {label} data for {PERIOD_PHRASES[period]}
) } diff --git a/windows/src/styles.css b/windows/src/styles.css index 31f3fe00..450f8646 100644 --- a/windows/src/styles.css +++ b/windows/src/styles.css @@ -194,16 +194,44 @@ code { font-family: var(--font-mono); } z-index: 40; border-bottom: 1px solid var(--separator); } -.agent-tabs { +.agent-tabs-row { display: flex; - gap: 5px; + align-items: center; +} +.agent-tabs { + flex: 1 1 auto; + min-width: 0; padding: 8px 12px; overflow-x: auto; scrollbar-width: none; mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent); -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 18px), transparent); } +.agent-tabs-content { + display: flex; + gap: 5px; + width: max-content; +} .agent-tabs::-webkit-scrollbar { display: none; } +/* Overflow arrows, as on the mac: they select the neighbouring tab rather than scrolling + blindly, so the strip and the active filter never disagree about what is in view. */ +.tab-chevron { + flex: 0 0 auto; + display: inline-flex; + align-items: center; + justify-content: center; + width: 18px; + height: 18px; + border: 0; + border-radius: var(--radius-pill); + background: transparent; + color: var(--label); +} +.tab-chevron:hover:not(:disabled) { background: var(--fill-08); } +.tab-chevron:disabled { color: var(--label-3); } +.agent-tabs-row > .tab-chevron:first-child { margin-left: 6px; } +.agent-tabs-row > .tab-chevron:last-child { margin-right: 6px; } +.agent-tabs-row > .tab-chevron:first-child + .agent-tabs { padding-left: 6px; } .tab-muted, .tab-muted:hover { background: transparent; color: var(--label-3); box-shadow: inset 0 0 0 1px var(--fill-08); } .tab-preview { position: absolute; @@ -238,6 +266,16 @@ code { font-family: var(--font-mono); } } .tab:hover { background: var(--fill-12); } .tab-active, .tab-active:hover { background: var(--brand-accent); color: #fff; } +/* The provider's brand mark, from ProviderFilter.color on the mac. */ +.tab-dot { + align-self: center; + flex: 0 0 auto; + width: 5px; + height: 5px; + border-radius: 50%; +} +.tab-active .tab-dot { background: rgba(255, 255, 255, 0.85); } +.tab-muted .tab-dot { opacity: 0.4; } .tab-cost { font-family: var(--font-mono); font-size: 10.5px;