
const REVIEW_PROMPT = "You are reviewing a code diff for correctness only. You were not involved in writing it and have no other context. Look only at the diff below. Flag genuine bugs, not style preferences. If it looks correct, say so in one short line.";
/**
* Deliberately NOT full agents: no tools, no codebase access, no fresh
* research. Each configured reviewer makes one call passing the diff summary,
* so it stays cheap and doesn't reintroduce coordination overhead. Reviewers
* run in parallel; any 'issues' verdict wins and flagged notes are kept
* separate. Returns null when config.review is unset or empty — review is
* optional by design, not a required pipeline stage.
*/
async function runOptionalReview(diffSummary, config, token) {
	const reviewers = config.review ?? [];
	if (reviewers.length === 0) return null;
	const calls = reviewers.map(async (ref) => {
		const model = await pickModel(ref);
		const messages = [vscode.LanguageModelChatMessage.User(REVIEW_PROMPT), vscode.LanguageModelChatMessage.User(diffSummary)];
		const response = await model.sendRequest(messages, {}, token);
		let text = "";
		for await (const chunk of response.text) text += chunk;
		return {
			verdict: /no issues|looks correct|correct/i.test(text) ? "ok" : "issues",
			notes: text
		};
	});
	const results = await Promise.all(calls);
	const flagged = results.filter((r) => r.verdict === "issues");
	if (flagged.length === 0) return {
		verdict: "ok",
		notes: results.map((r) => r.notes).join("\n")
	};
	return {
		verdict: "issues",
		notes: flagged.map((r, i) => `Reviewer ${i + 1}: ${r.notes}`).join("\n\n")
	};
}
