{"version":3,"file":"critic.d.ts","sourceRoot":"","sources":["../../src/reflect/critic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AAK9D,MAAM,WAAW,gBAAgB;IAChC,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,0BAA0B,CAAC;IACpC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,kBAAkB;IAClC,QAAQ,EAAE,QAAQ,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,GAAG,EAAE,cAAc,CAAC;CACpB;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAuCtF","sourcesContent":["import { readFile } from \"node:fs/promises\";\nimport type { ThinkingLevel } from \"@ch1nyzzz/pi-agent-core\";\nimport type { EvoPaths } from \"../paths.ts\";\nimport { attachProposalArtifact, proposalApproval } from \"../proposal.ts\";\nimport type { Proposal } from \"../types.ts\";\nimport type { EvidenceCorpus } from \"./evidence.ts\";\nimport type { ModelRunner, ModelRunResult } from \"./model-runner.ts\";\nimport type { CounterfactualReplayResult } from \"./replay.ts\";\nimport { recordModelUsage } from \"./usage.ts\";\n\nconst CRITIC_PROMPT_URL = new URL(\"../prompts/critic.md\", import.meta.url);\n\nexport interface RunCriticOptions {\n\tpaths: EvoPaths;\n\trunner: ModelRunner;\n\tproposal: Proposal;\n\tcorpus: EvidenceCorpus;\n\treplay?: CounterfactualReplayResult;\n\tcwd?: string;\n\tagentDir?: string;\n\tmodel?: string;\n\tthinkingLevel?: ThinkingLevel;\n\tsignal?: AbortSignal;\n}\n\nexport interface CriticReviewResult {\n\tproposal: Proposal;\n\treviewMarkdown: string;\n\trun: ModelRunResult;\n}\n\nexport async function runCritic(options: RunCriticOptions): Promise<CriticReviewResult> {\n\tconst prompt = [\n\t\t\"Review this proposal against the supplied primary evidence.\",\n\t\t...(options.replay?.mode === \"code-patch-hypothesis\"\n\t\t\t? [\n\t\t\t\t\t\"\",\n\t\t\t\t\t\"The code replay candidate is a hypothetical model prediction conditioned on the patch. No candidate code, runtime, or tool was loaded or executed; do not report it as observed patched-agent behavior.\",\n\t\t\t\t]\n\t\t\t: []),\n\t\t\"\",\n\t\t\"<proposal>\",\n\t\tJSON.stringify(options.proposal, undefined, \"\\t\"),\n\t\t\"</proposal>\",\n\t\t\"\",\n\t\t`<evidence_corpus truncated=\"${String(options.corpus.truncated)}\">`,\n\t\toptions.corpus.text,\n\t\t\"</evidence_corpus>\",\n\t\t...(options.replay ? [\"\", \"<counterfactual_replay>\", options.replay.markdown, \"</counterfactual_replay>\"] : []),\n\t].join(\"\\n\");\n\tconst run = await options.runner.run({\n\t\tcwd: options.cwd ?? process.cwd(),\n\t\t...(options.agentDir ? { agentDir: options.agentDir } : {}),\n\t\tsystemPrompt: await readFile(CRITIC_PROMPT_URL, \"utf8\"),\n\t\tprompt,\n\t\t...(options.model ? { model: options.model } : {}),\n\t\tthinkingLevel: options.thinkingLevel ?? \"low\",\n\t\t...(options.signal ? { signal: options.signal } : {}),\n\t});\n\tawait recordModelUsage(options.paths, \"critic\", run);\n\tconst reviewMarkdown = `${run.text.trim()}\\n`;\n\tconst proposal = await attachProposalArtifact({\n\t\tpaths: options.paths,\n\t\tproposalId: options.proposal.id,\n\t\texpected: proposalApproval(options.proposal),\n\t\tkind: \"review\",\n\t\tcontent: reviewMarkdown,\n\t\tallowedStatuses: [\"pending\", \"deferred\"],\n\t});\n\treturn { proposal, reviewMarkdown, run };\n}\n"]}