/** * Compact statusline text for the goal harness footer chip. */ import type { GoalOrchestration } from "../types.ts"; /** Short display id for statusline (alphanumeric prefix, max 8). */ export function shortAgentId(id: string | undefined | null): string | undefined { if (!id?.trim()) return undefined; const cleaned = id.replace(/[^a-zA-Z0-9]/g, ""); const short = (cleaned || id.trim()).slice(0, 8); return short || undefined; } /** * Format a statusline fragment for the active goal. * Returns `undefined` when there is no goal (clears the status key). */ export function formatStatusline(o: GoalOrchestration | null): string | undefined { if (!o) return undefined; const status = String(o.status ?? ""); const phase = String(o.phase ?? ""); const attempts = typeof o.verifyAttempts === "number" ? o.verifyAttempts : 0; const max = typeof o.verifyMax === "number" ? o.verifyMax : 0; if (status === "complete") return "✓ done"; if (status === "blocked") return "⛔ blocked"; if ( status === "user_paused" || status === "back_off_paused" || status === "no_progress_paused" || status === "infra_paused" || status === "budget_limited" ) { return "⏸ pause"; } if (phase === "planning" || status === "planning") { const short = shortAgentId(o.plannerAgentId); return short ? `◎ plan ${short}` : "◎ plan"; } if (phase === "verifying") { if (max > 0) return `🔬 verify ${attempts}/${max}`; return "🔬 verify"; } // active / executing if (attempts > 0 && max > 0) { return `● active ${attempts}/${max}`; } return "● active"; }