/** Format a millisecond duration the same way Pi's own status widgets do. */ export function formatDuration(ms: number): string { if (ms < 1000) return `${ms}ms`; if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`; return `${Math.floor(ms / 60000)}m${Math.floor((ms % 60000) / 1000)}s`; } /** Shorten large counts (tokens, tools) so the status line stays narrow. */ export function formatCompactMetric(value: number): string { if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(1)}M`; if (value >= 1_000) return `${(value / 1_000).toFixed(1)}k`; return String(value); }