/** * Shared elapsed-time formatting for tool results, widgets, and status lines. * Leaf module: no imports from other subagent modules. */ /** Compact human elapsed time from a seconds count: "42s", "3m 7s". */ export function formatElapsed(seconds: number): string { if (seconds < 60) return `${seconds}s`; const m = Math.floor(seconds / 60); const s = seconds % 60; return `${m}m ${s}s`; } /** Coarse human elapsed time from a millisecond duration: "42s", "3m", "1h 12m". */ export function formatElapsedDuration(ms: number): string { const totalSeconds = Math.max(0, Math.floor(ms / 1000)); if (totalSeconds < 60) return `${totalSeconds}s`; const hours = Math.floor(totalSeconds / 3600); const minutes = Math.floor((totalSeconds % 3600) / 60); if (hours > 0) return `${hours}h ${minutes}m`; return `${minutes}m`; } /** Stopwatch-style elapsed time between two epoch millis: "03:07". */ export function formatElapsedMMSS(startTime: number, endTime = Date.now()): string { const seconds = Math.floor((endTime - startTime) / 1000); const m = Math.floor(seconds / 60); const s = seconds % 60; return `${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`; }