diff --git a/src/commands/sandbox-formatters.ts b/src/commands/sandbox-formatters.ts new file mode 100644 index 000000000..cc3eef865 --- /dev/null +++ b/src/commands/sandbox-formatters.ts @@ -0,0 +1,49 @@ +/** + * Formatting utilities for sandbox CLI output + */ + +export function formatStatus(running: boolean): string { + return running ? "🟢 running" : "⚫ stopped"; +} + +export function formatSimpleStatus(running: boolean): string { + return running ? "running" : "stopped"; +} + +export function formatImageMatch(matches: boolean): string { + return matches ? "✓" : "⚠️ mismatch"; +} + +export function formatAge(ms: number): string { + const seconds = Math.floor(ms / 1000); + const minutes = Math.floor(seconds / 60); + const hours = Math.floor(minutes / 60); + const days = Math.floor(hours / 24); + + if (days > 0) return `${days}d ${hours % 24}h`; + if (hours > 0) return `${hours}h ${minutes % 60}m`; + if (minutes > 0) return `${minutes}m`; + return `${seconds}s`; +} + +/** + * Type guard and counter utilities + */ + +export type ContainerItem = { + running: boolean; + imageMatch: boolean; + containerName: string; + sessionKey: string; + image: string; + createdAtMs: number; + lastUsedAtMs: number; +}; + +export function countRunning(items: T[]): number { + return items.filter((item) => item.running).length; +} + +export function countMismatches(items: T[]): number { + return items.filter((item) => !item.imageMatch).length; +}