Skip to content

an open-source alternative to the dots, bots and muses of the world, run an office of claude code/codex like agents on your laptop, sandboxes or anywhere, uses your existing subscriptions

feat(7B): live fleet grid + per-agent tool-span waterfall

Chaitanya Giriada467067c2a
diff --git a/src/renderer/src/components/AgentDetailPanel.tsx b/src/renderer/src/components/AgentDetailPanel.tsx
index 9041f5d8..4de150ab 100644
--- a/src/renderer/src/components/AgentDetailPanel.tsx
+++ b/src/renderer/src/components/AgentDetailPanel.tsx
@@ -11,6 +11,7 @@ import { disposeTerminal } from './terminalPool';
import { SidebarTabs } from './SidebarTabs';
import { FilesTab } from './FilesTab';
import { ThreadsPanel } from './ThreadsPanel';
+import { ToolWaterfall } from './ToolWaterfall';
import { Icon } from './Icon';
import { useStore, type Agent } from '@/store/store';
import { usePtyParser } from '@/hooks/usePtyParser';
@@ -178,6 +179,10 @@ export function AgentDetailPanel({ agent }: AgentDetailPanelProps) {
{sidebarTab === 'messages' && (
<ThreadsPanel agentId={agent.id} />
)}
+
+ {sidebarTab === 'traces' && (
+ <ToolWaterfall agentId={agent.id} />
+ )}
</div>
</PixelPanel>
);
diff --git a/src/renderer/src/components/CommandCenterPanel.tsx b/src/renderer/src/components/CommandCenterPanel.tsx
index b73d115f..7a3ecd66 100644
--- a/src/renderer/src/components/CommandCenterPanel.tsx
+++ b/src/renderer/src/components/CommandCenterPanel.tsx
@@ -9,6 +9,7 @@ import { TasksKanban } from './TasksKanban';
import { disposeTerminal } from './terminalPool';
import { Icon } from './Icon';
import { MemoryGraphPanel } from './MemoryGraphPanel';
+import { FleetGrid } from './FleetGrid';
import { useStore, type Agent } from '@/store/store';
import { usePtyParser } from '@/hooks/usePtyParser';
import { buildSpawnCommand, AGENT_MODELS } from '@/store/config';
@@ -18,7 +19,7 @@ import { buildSpawnCommand, AGENT_MODELS } from '@/store/config';
* per-agent model + dispatch + assistant access), a memory view, and a live
* activity feed / board / usage meter. */
-type CCTab = 'terminal' | 'floor' | 'tasks' | 'memory' | 'graph' | 'activity' | 'handbook';
+type CCTab = 'terminal' | 'floor' | 'fleet' | 'tasks' | 'memory' | 'graph' | 'activity' | 'handbook';
/** A recurring auto-dispatched mission (mirrors the main-process config type). */
interface ScheduledMission {
@@ -61,6 +62,7 @@ interface CIRun {
const TABS: { key: CCTab; label: string; icon: Parameters<typeof Icon>[0]['name'] }[] = [
{ key: 'terminal', label: 'terminal', icon: 'terminal' },
{ key: 'floor', label: 'floor', icon: 'mcp' },
+ { key: 'fleet', label: 'fleet', icon: 'gear' },
{ key: 'tasks', label: 'tasks', icon: 'check' },
{ key: 'memory', label: 'memory', icon: 'sparkle' },
{ key: 'graph', label: 'graph', icon: 'web' },
@@ -162,6 +164,7 @@ export function CommandCenterPanel({ agent }: { agent: Agent }) {
)
)}
{tab === 'floor' && <FloorTab seed={dispatchSeed} />}
+ {tab === 'fleet' && <FleetTab />}
{tab === 'tasks' && (
<TasksKanban
onAssign={(prefill) => {
@@ -668,6 +671,21 @@ function MemoryTab({ godId, who: controlledWho, onWho }: { godId: string; who?:
);
}
+// ─── Fleet tab — the live control-room overview (#7B.1) ──────────────────────
+
+function FleetTab() {
+ return (
+ <Scroll>
+ <Section title="FLEET (live telemetry)">
+ <FleetGrid />
+ <div style={{ marginTop: 6 }}>
+ <Muted>live from each agent&apos;s OpenTelemetry · cost is Claude&apos;s own per-model figure</Muted>
+ </div>
+ </Section>
+ </Scroll>
+ );
+}
+
// ─── Activity tab — log feed + board + usage ─────────────────────────────────
interface LogEntry { ts?: number; kind?: string; [k: string]: unknown }
diff --git a/src/renderer/src/components/FleetGrid.tsx b/src/renderer/src/components/FleetGrid.tsx
new file mode 100644
index 00000000..55aef847
--- /dev/null
+++ b/src/renderer/src/components/FleetGrid.tsx
@@ -0,0 +1,146 @@
+import { useStore } from '@/store/store';
+import { SpritePortrait } from './SpritePortrait';
+import { PixelBadge } from './PixelBadge';
+import {
+ useFleetTelemetry,
+ type AgentUsageSample, type BreakerState
+} from '@/hooks/useTelemetry';
+
+/**
+ * FLEET — the control-room overview (#7B.1). One cell per live agent: sprite,
+ * status, live cost, a tokens-burned sparkline, the last tool, and a budget
+ * meter normalized to the priciest agent and colored by headroom. A circuit
+ * breaker (Lane A #6) flips the row to a coral ⚠ state. All styling derives from
+ * the design tokens — no new palette.
+ */
+export function FleetGrid() {
+ const agents = useStore((s) => s.agents);
+ const live = agents.filter((a) => a.ptyId);
+ const { samples, spark, rate, lastTool, breakers } = useFleetTelemetry();
+
+ const maxCost = Math.max(0.0001, ...live.map((a) => samples[a.id]?.usd ?? 0));
+
+ // Fleet totals.
+ let sumCost = 0;
+ let sumInput = 0;
+ let sumCacheRead = 0;
+ let sumRate = 0;
+ for (const a of live) {
+ const s = samples[a.id];
+ if (s) { sumCost += s.usd; sumInput += s.input + s.cacheRead + s.cacheCreation; sumCacheRead += s.cacheRead; }
+ sumRate += rate[a.id] ?? 0;
+ }
+ const fleetCachePct = sumInput > 0 ? Math.round((sumCacheRead / sumInput) * 100) : 0;
+
+ if (live.length === 0) {
+ return (
+ <div style={{ fontSize: 12, color: 'var(--cth-ink-500)', padding: 8 }}>
+ No live agents. Spawn one and its telemetry appears here in real time.
+ </div>
+ );
+ }
+
+ return (
+ <div>
+ <div style={{
+ display: 'grid', gridTemplateColumns: '24px 1fr auto', gap: 0,
+ boxShadow: 'inset 0 0 0 1px var(--cth-ink-300)', background: 'var(--cth-paper-100)'
+ }}>
+ {live.map((a) => (
+ <FleetCell
+ key={a.id}
+ name={a.name}
+ character={a.character}
+ status={a.status}
+ sample={samples[a.id]}
+ maxCost={maxCost}
+ spark={spark[a.id] ?? []}
+ tool={lastTool[a.id]}
+ breaker={breakers[a.id]}
+ />
+ ))}
+ </div>
+ {/* Fleet summary band */}
+ <div style={{
+ display: 'flex', gap: 14, marginTop: 8, padding: '6px 8px',
+ background: 'var(--cth-cream-200)', boxShadow: 'inset 0 0 0 1px var(--cth-ink-700)',
+ fontFamily: 'var(--cth-font-mono)', fontSize: 11, color: 'var(--cth-ink-900)', flexWrap: 'wrap'
+ }}>
+ <span>Σ <strong>${sumCost.toFixed(2)}</strong></span>
+ <span style={{ color: 'var(--cth-ink-700)' }}>inputs {fmtTokens(sumInput)} (cache {fleetCachePct}%)</span>
+ <span style={{ color: 'var(--cth-ink-700)' }}>{Math.round(sumRate).toLocaleString()} tok/min</span>
+ </div>
+ </div>
+ );
+}
+
+function FleetCell({ name, character, status, sample, maxCost, spark, tool, breaker }: {
+ name: string;
+ character: Parameters<typeof SpritePortrait>[0]['character'];
+ status: Parameters<typeof PixelBadge>[0]['status'];
+ sample?: AgentUsageSample;
+ maxCost: number;
+ spark: number[];
+ tool?: string;
+ breaker?: BreakerState;
+}) {
+ const cost = sample?.usd ?? 0;
+ const pct = Math.min(100, Math.round((cost / maxCost) * 100));
+ const armed = breaker && (breaker.level === 'constrained' || breaker.level === 'stopped');
+ const meterColor = armed
+ ? 'var(--cth-coral)'
+ : pct >= 90 ? 'var(--cth-coral)' : pct >= 60 ? 'var(--cth-lemon)' : 'var(--cth-mint)';
+
+ const cellBg = armed ? 'var(--cth-coral-light)' : 'transparent';
+ const rowBorder = 'inset 0 -1px 0 var(--cth-ink-300)';
+
+ return (
+ <>
+ {/* sprite */}
+ <div style={{ boxShadow: rowBorder, background: cellBg, display: 'flex', alignItems: 'center', justifyContent: 'center', height: 30, overflow: 'hidden' }}>
+ <SpritePortrait character={character} scale={1} />
+ </div>
+ {/* name + status + sparkline + tool */}
+ <div style={{ boxShadow: rowBorder, background: cellBg, display: 'flex', alignItems: 'center', gap: 6, padding: '0 8px', minWidth: 0 }}>
+ <span style={{ fontSize: 12, color: 'var(--cth-ink-900)', width: 64, whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{name}</span>
+ <PixelBadge status={armed ? 'looping' : status} />
+ <Sparkline series={spark} />
+ {tool && (
+ <span style={{
+ fontSize: 10, lineHeight: '14px', padding: '0 5px', flexShrink: 0,
+ background: 'var(--cth-paper-200)', boxShadow: 'inset 0 0 0 1px var(--cth-ink-300)', color: 'var(--cth-ink-700)'
+ }}>{tool}</span>
+ )}
+ {armed && <span title={breaker?.reason} style={{ color: 'var(--cth-coral)', fontSize: 12 }}>⚠</span>}
+ </div>
+ {/* cost + budget meter */}
+ <div style={{ boxShadow: rowBorder, background: cellBg, display: 'flex', alignItems: 'center', gap: 6, padding: '0 8px' }}>
+ <span style={{ fontFamily: 'var(--cth-font-mono)', fontSize: 11, color: 'var(--cth-ink-900)', width: 52, textAlign: 'right' }}>${cost.toFixed(2)}</span>
+ <div style={{ width: 70, height: 8, background: 'var(--cth-cream-200)', boxShadow: 'inset 0 0 0 1px var(--cth-ink-300)' }}>
+ <div style={{ width: `${pct}%`, height: '100%', background: meterColor }} />
+ </div>
+ <span style={{ fontSize: 10, color: 'var(--cth-ink-500)', width: 28, textAlign: 'right' }}>{pct}%</span>
+ </div>
+ </>
+ );
+}
+
+/** Block-character sparkline — matches the neo-brutalist mono aesthetic. */
+function Sparkline({ series }: { series: number[] }) {
+ const blocks = '▁▂▃▄▅▆▇█';
+ const max = Math.max(1, ...series);
+ const text = series.length
+ ? series.map((v) => blocks[Math.min(blocks.length - 1, Math.round((v / max) * (blocks.length - 1)))]).join('')
+ : '▁▁▁▁▁▁';
+ return (
+ <span style={{ flex: 1, fontFamily: 'var(--cth-font-mono)', fontSize: 12, lineHeight: '12px', color: 'var(--cth-sky)', whiteSpace: 'nowrap', overflow: 'hidden', minWidth: 0 }}>
+ {text}
+ </span>
+ );
+}
+
+function fmtTokens(n: number): string {
+ if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
+ if (n >= 1_000) return `${(n / 1_000).toFixed(0)}K`;
+ return String(n);
+}
diff --git a/src/renderer/src/components/PixelBadge.tsx b/src/renderer/src/components/PixelBadge.tsx
index 64056854..f04d4acb 100644
--- a/src/renderer/src/components/PixelBadge.tsx
+++ b/src/renderer/src/components/PixelBadge.tsx
@@ -1,7 +1,10 @@
import { CSSProperties } from 'react';
export type StatusKind =
- | 'idle' | 'thinking' | 'working' | 'waiting' | 'blocked' | 'success' | 'ghost';
+ | 'idle' | 'thinking' | 'working' | 'waiting' | 'blocked' | 'success' | 'ghost'
+ // #5C — richer states driven by real events: PreCompact/PostCompact hooks and
+ // the Lane A circuit breaker (#6) respectively.
+ | 'compacting' | 'looping';
export interface PixelBadgeProps {
status: StatusKind;
@@ -16,7 +19,9 @@ const colorByStatus: Record<StatusKind, string> = {
waiting: 'var(--cth-status-waiting)',
blocked: 'var(--cth-status-blocked)',
success: 'var(--cth-status-success)',
- ghost: 'var(--cth-status-ghost)'
+ ghost: 'var(--cth-status-ghost)',
+ compacting: 'var(--cth-status-compacting)',
+ looping: 'var(--cth-status-looping)'
};
// Human-readable labels. "blocked" is reserved for the god agent waiting on YOU,
@@ -29,7 +34,9 @@ const labelByStatus: Record<StatusKind, string> = {
waiting: 'waiting',
blocked: 'needs you',
success: 'done',
- ghost: 'gone'
+ ghost: 'gone',
+ compacting: 'compacting',
+ looping: 'looping'
};
export function PixelBadge({ status, label, style }: PixelBadgeProps) {
diff --git a/src/renderer/src/components/SidebarTabs.tsx b/src/renderer/src/components/SidebarTabs.tsx
index b68dd910..c465592f 100644
--- a/src/renderer/src/components/SidebarTabs.tsx
+++ b/src/renderer/src/components/SidebarTabs.tsx
@@ -5,7 +5,8 @@ import { Icon, type IconName } from './Icon';
const TABS: { key: SidebarTab; label: string; icon: IconName }[] = [
{ key: 'terminal', label: 'terminal', icon: 'terminal' },
{ key: 'files', label: 'files', icon: 'folder' },
- { key: 'messages', label: 'messages', icon: 'bell' }
+ { key: 'messages', label: 'messages', icon: 'bell' },
+ { key: 'traces', label: 'traces', icon: 'web' }
];
export interface SidebarTabsProps {
diff --git a/src/renderer/src/components/ToolWaterfall.tsx b/src/renderer/src/components/ToolWaterfall.tsx
new file mode 100644
index 00000000..6c586008
--- /dev/null
+++ b/src/renderer/src/components/ToolWaterfall.tsx
@@ -0,0 +1,87 @@
+import { useAgentSpans, useFleetTelemetry, totalTokens, cacheFraction } from '@/hooks/useTelemetry';
+
+/**
+ * Per-agent tool-call timeline (#7B.2) — a horizontal waterfall of tool spans
+ * from live `tool_result` telemetry. Each bar is one tool call, width ∝ its
+ * duration, mint=success / coral=failure. A header band shows cumulative cost
+ * with the cache-vs-fresh split made visible (fixes cost bug #1.1.3). This is
+ * the headline upgrade over the old bare tool-count proxy.
+ */
+export function ToolWaterfall({ agentId }: { agentId: string }) {
+ const spans = useAgentSpans(agentId);
+ const { samples } = useFleetTelemetry();
+ const sample = samples[agentId];
+
+ const maxDur = Math.max(1, ...spans.map((s) => s.durationMs));
+ const recent = spans.slice(-60); // keep the view legible
+
+ return (
+ <div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column', background: 'var(--cth-paper-200)', overflow: 'hidden' }}>
+ {/* Header band: cumulative cost + cache-vs-fresh split */}
+ <div style={{
+ flexShrink: 0, padding: '8px 10px', background: 'var(--cth-cream-200)',
+ boxShadow: 'inset 0 -2px 0 var(--cth-ink-900)',
+ fontFamily: 'var(--cth-font-mono)', fontSize: 12, color: 'var(--cth-ink-900)',
+ display: 'flex', gap: 14, flexWrap: 'wrap', alignItems: 'baseline'
+ }}>
+ {sample ? (
+ <>
+ <span><strong>${sample.usd.toFixed(2)}</strong></span>
+ <span style={{ color: 'var(--cth-ink-700)' }}>
+ fresh {fmtTokens(sample.input + sample.cacheCreation)}t
+ </span>
+ <span style={{ color: 'var(--cth-sky)' }}>
+ cache {fmtTokens(sample.cacheRead)}t ({Math.round(cacheFraction(sample) * 100)}%)
+ </span>
+ {sample.model && <span style={{ color: 'var(--cth-ink-500)' }}>{sample.model}</span>}
+ <span style={{ color: 'var(--cth-ink-500)' }}>{fmtTokens(totalTokens(sample))}t total</span>
+ </>
+ ) : (
+ <span style={{ color: 'var(--cth-ink-500)' }}>no live telemetry yet — spawn / respawn this agent to instrument it</span>
+ )}
+ </div>
+
+ {/* Waterfall */}
+ <div style={{ flex: 1, minHeight: 0, overflowY: 'auto', padding: 10 }}>
+ {recent.length === 0 && (
+ <div style={{ fontSize: 12, color: 'var(--cth-ink-500)' }}>
+ No tool calls captured yet. Each tool the agent runs appears here with its real duration.
+ </div>
+ )}
+ {recent.map((s, i) => {
+ const pct = Math.max(2, Math.round((s.durationMs / maxDur) * 100));
+ const ok = s.success && s.tool !== 'api_error';
+ return (
+ <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 3 }}>
+ <span style={{ width: 88, fontSize: 11, color: 'var(--cth-ink-700)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }} title={s.error ?? s.tool}>
+ {s.tool}
+ </span>
+ <div style={{ flex: 1, height: 12, background: 'var(--cth-paper-100)', boxShadow: 'inset 0 0 0 1px var(--cth-ink-300)' }}>
+ <div
+ title={s.error ? `${s.tool}: ${s.error}` : `${s.tool} · ${s.durationMs}ms · ${ok ? 'ok' : 'failed'}`}
+ style={{ width: `${pct}%`, height: '100%', background: ok ? 'var(--cth-mint)' : 'var(--cth-coral)' }}
+ />
+ </div>
+ <span style={{ width: 54, textAlign: 'right', fontFamily: 'var(--cth-font-mono)', fontSize: 11, color: 'var(--cth-ink-500)' }}>
+ {fmtDur(s.durationMs)}
+ </span>
+ <span style={{ width: 12, textAlign: 'center', fontSize: 11, color: ok ? 'var(--cth-mint)' : 'var(--cth-coral)' }}>
+ {ok ? '✓' : '✗'}
+ </span>
+ </div>
+ );
+ })}
+ </div>
+ </div>
+ );
+}
+
+function fmtDur(ms: number): string {
+ if (ms >= 1000) return `${(ms / 1000).toFixed(1)}s`;
+ return `${Math.round(ms)}ms`;
+}
+function fmtTokens(n: number): string {
+ if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;
+ if (n >= 1_000) return `${(n / 1_000).toFixed(0)}K`;
+ return String(n);
+}
diff --git a/src/renderer/src/design/tokens.css b/src/renderer/src/design/tokens.css
index f729e68d..eb33f3e8 100644
--- a/src/renderer/src/design/tokens.css
+++ b/src/renderer/src/design/tokens.css
@@ -31,6 +31,8 @@
--cth-status-blocked: #FF6B6B;
--cth-status-success: #6BCF7F;
--cth-status-ghost: #D9CFE0;
+ --cth-status-compacting: #9B7EDE; /* #5C — mid-/compact, "boxing up context" */
+ --cth-status-looping: #FF9F43; /* #5C — circuit-breaker armed (runaway) */
/* Spacing */
--cth-space-0: 0px;
diff --git a/src/renderer/src/hooks/useTelemetry.ts b/src/renderer/src/hooks/useTelemetry.ts
new file mode 100644
index 00000000..9ebed968
--- /dev/null
+++ b/src/renderer/src/hooks/useTelemetry.ts
@@ -0,0 +1,172 @@
+import { useEffect, useRef, useState } from 'react';
+
+/**
+ * Renderer-side consumers of the live telemetry stream (#7B).
+ *
+ * The main-process collector (telemetry.ts) pushes normalized, PII-free events
+ * on `telemetry:event` and breaker state on `control:breakerState`. These hooks
+ * subscribe + backfill from the cold-start snapshot, and shape the data for the
+ * fleet grid (`useFleetTelemetry`) and the per-agent span waterfall
+ * (`useAgentSpans`).
+ *
+ * Types mirror the LOCKED contract in src/main/telemetry.ts + src/preload (kept
+ * in sync by hand, matching the codebase's local-redeclare pattern).
+ */
+
+export interface AgentUsageSample {
+ agentId: string;
+ sessionId: string;
+ ts: number;
+ input: number;
+ output: number;
+ cacheRead: number;
+ cacheCreation: number;
+ model: string;
+ usd: number;
+}
+
+export interface ToolSpan {
+ agentId: string;
+ sessionId: string;
+ ts: number;
+ tool: string;
+ success: boolean;
+ durationMs: number;
+ decision?: 'accept' | 'reject';
+ error?: string;
+}
+
+export interface BreakerState {
+ agentId: string;
+ level: 'healthy' | 'steering' | 'constrained' | 'stopped';
+ reason: string;
+ ts: number;
+}
+
+type TelemetryEvent =
+ | { kind: 'usage'; sample: AgentUsageSample }
+ | { kind: 'tool_result'; span: ToolSpan }
+ | { kind: 'api_error'; agentId: string; sessionId: string; ts: number; error: string };
+
+/** Total tokens across all kinds — the sparkline/velocity basis. */
+export function totalTokens(s: AgentUsageSample): number {
+ return s.input + s.output + s.cacheRead + s.cacheCreation;
+}
+
+/** How many tokens were fresh vs served from cache, as a 0–1 cache fraction. */
+export function cacheFraction(s: AgentUsageSample): number {
+ const total = totalTokens(s);
+ return total > 0 ? s.cacheRead / total : 0;
+}
+
+/** Per-agent rolling token deltas (for the sparkline) plus a simple tokens/min. */
+interface Rate {
+ deltas: number[]; // most recent first-N token deltas between pushes
+ firstTs: number;
+ firstTotal: number;
+ lastTs: number;
+ lastTotal: number;
+}
+
+const SPARK_LEN = 14;
+
+export interface FleetTelemetry {
+ samples: Record<string, AgentUsageSample>;
+ /** sparkline series (token deltas between pushes), oldest→newest, per agent */
+ spark: Record<string, number[]>;
+ /** tokens/min, derived per agent */
+ rate: Record<string, number>;
+ /** last tool name seen per agent */
+ lastTool: Record<string, string>;
+ /** latest breaker state per agent (drives the cost-meter color + ⚠) */
+ breakers: Record<string, BreakerState>;
+}
+
+/**
+ * Subscribe to the whole fleet's live telemetry. One instance (the fleet grid).
+ * Backfills from the snapshot on mount, then folds in live pushes.
+ */
+export function useFleetTelemetry(): FleetTelemetry {
+ const [samples, setSamples] = useState<Record<string, AgentUsageSample>>({});
+ const [spark, setSpark] = useState<Record<string, number[]>>({});
+ const [rate, setRate] = useState<Record<string, number>>({});
+ const [lastTool, setLastTool] = useState<Record<string, string>>({});
+ const [breakers, setBreakers] = useState<Record<string, BreakerState>>({});
+ const rates = useRef<Record<string, Rate>>({});
+
+ useEffect(() => {
+ let alive = true;
+
+ const foldUsage = (s: AgentUsageSample): void => {
+ setSamples((prev) => ({ ...prev, [s.agentId]: s }));
+ const total = totalTokens(s);
+ const r = rates.current[s.agentId];
+ if (!r) {
+ rates.current[s.agentId] = { deltas: [], firstTs: s.ts, firstTotal: total, lastTs: s.ts, lastTotal: total };
+ } else {
+ const delta = Math.max(0, total - r.lastTotal);
+ r.deltas = [...r.deltas, delta].slice(-SPARK_LEN);
+ r.lastTs = s.ts;
+ r.lastTotal = total;
+ const minutes = Math.max(1 / 60, (r.lastTs - r.firstTs) / 60000);
+ const perMin = (r.lastTotal - r.firstTotal) / minutes;
+ setSpark((prev) => ({ ...prev, [s.agentId]: r.deltas }));
+ setRate((prev) => ({ ...prev, [s.agentId]: perMin }));
+ }
+ };
+
+ // Backfill from the snapshot (we missed the pushes before mount).
+ window.cth.telemetrySnapshot?.().then((snap) => {
+ if (!alive || !snap) return;
+ for (const s of snap.usage ?? []) foldUsage(s as AgentUsageSample);
+ const tools: Record<string, string> = {};
+ for (const [id, spans] of Object.entries(snap.spans ?? {})) {
+ const arr = spans as ToolSpan[];
+ if (arr.length) tools[id] = arr[arr.length - 1].tool;
+ }
+ setLastTool((prev) => ({ ...tools, ...prev }));
+ }).catch(() => { /* collector not up — empty grid */ });
+
+ const offEvent = window.cth.onTelemetryEvent?.((e: TelemetryEvent) => {
+ if (e.kind === 'usage') foldUsage(e.sample);
+ else if (e.kind === 'tool_result') setLastTool((prev) => ({ ...prev, [e.span.agentId]: e.span.tool }));
+ });
+ const offBreaker = window.cth.onBreakerState?.((s: BreakerState) => {
+ setBreakers((prev) => ({ ...prev, [s.agentId]: s }));
+ });
+
+ return () => { alive = false; offEvent?.(); offBreaker?.(); };
+ }, []);
+
+ return { samples, spark, rate, lastTool, breakers };
+}
+
+/**
+ * Subscribe to ONE agent's tool spans for the waterfall. Backfills from the
+ * collector on mount/agent-change, then appends live `tool_result` pushes.
+ */
+export function useAgentSpans(agentId: string): ToolSpan[] {
+ const [spans, setSpans] = useState<ToolSpan[]>([]);
+
+ useEffect(() => {
+ let alive = true;
+ setSpans([]);
+ window.cth.telemetrySpans?.(agentId).then((s) => {
+ if (alive && Array.isArray(s)) setSpans(s as ToolSpan[]);
+ }).catch(() => { /* none yet */ });
+
+ const off = window.cth.onTelemetryEvent?.((e: TelemetryEvent) => {
+ if (e.kind === 'tool_result' && e.span.agentId === agentId) {
+ setSpans((prev) => [...prev, e.span].slice(-200));
+ } else if (e.kind === 'api_error' && e.agentId === agentId) {
+ setSpans((prev) => [...prev, {
+ agentId, sessionId: e.sessionId, ts: e.ts, tool: 'api_error',
+ success: false, durationMs: 0, error: e.error
+ }].slice(-200));
+ }
+ });
+ return () => { alive = false; off?.(); };
+ }, [agentId]);
+
+ return spans;
+}
diff --git a/src/renderer/src/store/store.ts b/src/renderer/src/store/store.ts
index 4c14f9ff..c63c84bd 100644
--- a/src/renderer/src/store/store.ts
+++ b/src/renderer/src/store/store.ts
@@ -87,7 +87,7 @@ export interface QueuedMessage {
ts: number;
}
-export type SidebarTab = 'terminal' | 'files' | 'messages';
+export type SidebarTab = 'terminal' | 'files' | 'messages' | 'traces';
/** Lifecycle of the god agent ("Michael") bootstrap on launch.
* 'booting' until his PTY is confirmed live, then 'ready' (or 'failed' if the
@@ -270,7 +270,7 @@ const initialSidebarWidth = (() => {
const initialSidebarTab: SidebarTab = (() => {
try {
const v = window.localStorage.getItem(LS_SIDEBAR_TAB);
- if (v === 'files' || v === 'terminal' || v === 'messages') return v;
+ if (v === 'files' || v === 'terminal' || v === 'messages' || v === 'traces') return v;
} catch { /* noop */ }
return 'terminal';
})();