{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/watchdog/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAA2B,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEzD,KAAK,aAAa,GAAG;IACpB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;CAC7B,CAAC;AAmBF,wBAAgB,+BAA+B,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CAkBvF;AAED,wBAAgB,qBAAqB,CACpC,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,EAC9B,KAAK,EAAE,aAAa,GAClB,SAAS,CAcX","sourcesContent":["import { type Component, Container, Spacer, Text } from \"@lpb-work/pi-tui\";\nimport type { WatchdogWarningDetails } from \"./types.ts\";\n\ntype WatchdogTheme = {\n\tfg(name: string, value: string): string;\n\tbold?(value: string): string;\n};\n\nfunction titleCase(value: string): string {\n\treturn value\n\t\t.split(\"-\")\n\t\t.map((part) => (part ? `${part[0]?.toUpperCase()}${part.slice(1)}` : part))\n\t\t.join(\" \");\n}\n\nfunction stateLabels(warning: WatchdogWarningDetails): string[] {\n\tconst labels: string[] = [];\n\tif (warning.state === \"displayed\") labels.push(\"displayed\");\n\tif (warning.stale || warning.state === \"stale\") labels.push(\"stale · no auto-follow\");\n\tif (warning.state === \"failed\") labels.push(\"failed review\");\n\tif (warning.state === \"stalemate\") labels.push(\"stalemate · auto-follow stopped\");\n\tif (warning.autoFollowAttempt !== undefined) labels.push(`auto-follow attempt ${warning.autoFollowAttempt}`);\n\treturn labels;\n}\n\nexport function formatWatchdogWarningRenderText(warning: WatchdogWarningDetails): string {\n\tconst labels = stateLabels(warning);\n\tconst subject = warning.severity === \"blocker\" ? \"Blocker\" : \"Concern\";\n\tconst lines = [\n\t\t`Subagent watchdog ${subject}${labels.length ? ` (${labels.join(\", \")})` : \"\"}: ${warning.summary}`,\n\t\t`Evidence: ${warning.evidence}`,\n\t\t`Recommended action: ${warning.recommendedAction}`,\n\t\t`Category: ${titleCase(warning.category)} · Source: ${warning.source}${warning.agent ? ` · Agent: ${warning.agent}` : \"\"}${warning.runId ? ` · Run: ${warning.runId}` : \"\"}`,\n\t];\n\tif (warning.state === \"failed\" && warning.error) lines.push(`Failure: ${warning.error}`);\n\tif (warning.state === \"stalemate\" && warning.stalemateRepeats !== undefined) {\n\t\tlines.push(\n\t\t\t`Auto-follow stopped after ${warning.stalemateRepeats} repeated blocker warning${warning.stalemateRepeats === 1 ? \"\" : \"s\"}.`,\n\t\t);\n\t}\n\tif (warning.stale || warning.state === \"stale\")\n\t\tlines.push(\"This warning arrived after the watchdog catch-up timeout and must not auto-follow.\");\n\treturn lines.join(\"\\n\");\n}\n\nexport function renderWatchdogWarning(\n\twarning: WatchdogWarningDetails,\n\toptions: { expanded: boolean },\n\ttheme: WatchdogTheme,\n): Component {\n\tconst text = formatWatchdogWarningRenderText(warning);\n\tconst lines = text.split(\"\\n\");\n\tconst container = new Container();\n\tconst color = warning.severity === \"blocker\" ? \"error\" : \"warning\";\n\tconst bold = theme.bold ?? ((value: string) => value);\n\tcontainer.addChild(new Text(theme.fg(color, bold(lines[0] ?? \"Subagent watchdog warning\")), 0, 0));\n\tif (options.expanded) {\n\t\tcontainer.addChild(new Spacer(1));\n\t\tfor (const line of lines.slice(1)) container.addChild(new Text(theme.fg(\"dim\", line), 0, 0));\n\t} else if (lines[1]) {\n\t\tcontainer.addChild(new Text(theme.fg(\"dim\", `  ⎿  ${lines[1]}`), 0, 0));\n\t}\n\treturn container;\n}\n"]}