import type { Theme } from "@earendil-works/pi-coding-agent"; import { truncateToWidth } from "@earendil-works/pi-tui"; import { formatDuration } from "./duration.ts"; import { clusterUsage, formatCacheHitRate, formatTokenCount } from "./usage.ts"; import { isActiveClusterStatus, type ClusterState } from "./types.ts"; function statusLabel(state: ClusterState): string { return state.status === "paused" ? "已暂停" : "运行中"; } export function renderStatusPanel(state: ClusterState | undefined, theme: Theme, width: number, focused: boolean): string[] { if (!state || !isActiveClusterStatus(state.status)) return []; const completed = state.tasks.filter((task) => task.status === "completed").length; const usage = clusterUsage(state.tasks); const hint = focused ? "Enter 查看 · Esc 返回" : "↓ 选择 · Enter 查看"; const text = `${focused ? "▶" : "↓"} 集群 ${statusLabel(state)} · ${completed}/${state.tasks.length} 完成 · ${formatTokenCount(usage.totalTokens)} tokens · 命中率 ${formatCacheHitRate(usage)} · 运行时长 ${formatDuration(state.startedAt, state.finishedAt, state.pausePeriods)} ${hint}`; const colored = focused ? theme.bg("selectedBg", theme.fg("accent", text)) : theme.bg("customMessageBg", theme.fg("muted", text)); return [truncateToWidth(colored, Math.max(1, width), "", true)]; }