{"version":3,"file":"warning-format.d.ts","sourceRoot":"","sources":["../../../src/watchdog/warning-format.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,sBAAsB,EAC3B,MAAM,YAAY,CAAC;AAepB,wBAAgB,+BAA+B,CAC9C,OAAO,EAAE,eAAe,EACxB,MAAM,GAAE,OAAO,CAAC,sBAAsB,CAAM,GAC1C,sBAAsB,CAOxB;AAED,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CA6B7E;AAED,wBAAgB,4BAA4B,CAC3C,OAAO,EAAE,eAAe,EACxB,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC,sBAAsB,CAAC,CAAA;CAAO,GAC5E,sBAAsB,CAQxB","sourcesContent":["import {\n\tSUBAGENT_WATCHDOG_WARNING_TYPE,\n\ttype WatchdogWarning,\n\ttype WatchdogWarningDetails,\n\ttype WatchdogWarningMessage,\n} from \"./types.ts\";\n\nfunction escapeXmlText(value: string): string {\n\treturn value.replace(/&/g, \"&amp;\").replace(/</g, \"&lt;\").replace(/>/g, \"&gt;\");\n}\n\nfunction escapeXmlAttribute(value: string): string {\n\treturn escapeXmlText(value).replace(/\"/g, \"&quot;\");\n}\n\nfunction tag(name: string, value: string | number | boolean | undefined): string | undefined {\n\tif (value === undefined) return undefined;\n\treturn `<${name}>${escapeXmlText(String(value))}</${name}>`;\n}\n\nexport function normalizeWatchdogWarningDetails(\n\twarning: WatchdogWarning,\n\textras: Partial<WatchdogWarningDetails> = {},\n): WatchdogWarningDetails {\n\treturn {\n\t\t...warning,\n\t\tcategory: warning.category ?? extras.category ?? \"other\",\n\t\tsource: warning.source ?? extras.source ?? \"main\",\n\t\t...extras,\n\t};\n}\n\nexport function formatWatchdogWarningContent(warning: WatchdogWarning): string {\n\tconst details = normalizeWatchdogWarningDetails(warning);\n\tconst attrs = [\n\t\t`severity=\"${escapeXmlAttribute(details.severity)}\"`,\n\t\t`category=\"${escapeXmlAttribute(details.category)}\"`,\n\t\t`source=\"${escapeXmlAttribute(details.source)}\"`,\n\t\t`guidance=\"weigh, don't blindly obey\"`,\n\t];\n\tconst optionalTags = [\n\t\ttag(\"confidence\", details.confidence),\n\t\ttag(\"agent\", details.agent),\n\t\ttag(\"run_id\", details.runId),\n\t\ttag(\"state\", details.state),\n\t\ttag(\"stale\", details.stale),\n\t\ttag(\"auto_follow_attempt\", details.autoFollowAttempt),\n\t];\n\treturn [\n\t\t`<subagent_watchdog ${attrs.join(\" \")}>`,\n\t\t`<summary>${escapeXmlText(details.summary)}</summary>`,\n\t\t`<evidence>${escapeXmlText(details.evidence)}</evidence>`,\n\t\t`<recommended_action>${escapeXmlText(details.recommendedAction)}</recommended_action>`,\n\t\t...optionalTags.filter((line): line is string => Boolean(line)),\n\t\tdetails.severity === \"blocker\"\n\t\t\t? \"<blocker_guidance>If this warning changes the outcome, produce a new self-contained final answer after addressing it.</blocker_guidance>\"\n\t\t\t: undefined,\n\t\t\"</subagent_watchdog>\",\n\t]\n\t\t.filter((line): line is string => Boolean(line))\n\t\t.join(\"\\n\");\n}\n\nexport function createWatchdogWarningMessage(\n\twarning: WatchdogWarning,\n\toptions: { display?: boolean; details?: Partial<WatchdogWarningDetails> } = {},\n): WatchdogWarningMessage {\n\tconst details = normalizeWatchdogWarningDetails(warning, options.details);\n\treturn {\n\t\tcustomType: SUBAGENT_WATCHDOG_WARNING_TYPE,\n\t\tcontent: formatWatchdogWarningContent(details),\n\t\tdisplay: options.display ?? true,\n\t\tdetails,\n\t};\n}\n"]}