export const RUN_ENTRY_TYPE = "ultrapi-run"; /** Just enough of Pi's theme to colour a line, without depending on the TUI package. */ export type Paint = (color: string, text: string) => string; const PLAIN: Paint = (_color, text) => text; function text(value: unknown): string | undefined { return typeof value === "string" && value.trim() ? value : undefined; } /** * One line for a dispatch that has already been appended to the session. * * These entries have been recorded at every dispatch since the beginning and rendered as nothing at * all, because no renderer was registered for the type. The transcript therefore showed a tool call * and then a silence where the run began. */ export function runEntryLine(data: unknown, paint: Paint = PLAIN): string | undefined { if (!data || typeof data !== "object") return undefined; const entry = data as Record; const runId = text(entry.runId); if (!runId) return undefined; const status = text(entry.status); const colour = status === "blocked" ? "error" : status === "direct" ? "accent" : "success"; const recovered = text(entry.recoveredFromRunId); const parts = [ paint("muted", "UltraPi"), paint(colour, `${text(entry.topology) ?? "run"}${status ? `/${status}` : ""}`), paint("muted", runId.slice(0, 8)), ...(recovered ? [paint("muted", `recovered from ${recovered.slice(0, 8)}`)] : []), ...(text(entry.piAgentsRunId) ? [paint("muted", "delegated")] : []), ]; return parts.join(" ยท "); }