From 397c9aeb905f7a4a020873a582860a5254a380b6 Mon Sep 17 00:00:00 2001 From: ztimson Date: Tue, 30 Dec 2025 14:53:35 -0500 Subject: [PATCH] Dont make re-recommendations --- src/review.mjs | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/review.mjs b/src/review.mjs index 502a94f..87de01c 100644 --- a/src/review.mjs +++ b/src/review.mjs @@ -30,6 +30,26 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false}); const commit = await $`cd ${root} && git log -1 --pretty=format:%H`; const gitDiff = await $`cd ${root} && git diff ${branch}`; + if(!gitDiff) { + console.warn('No diff found'); + return process.exit(); + } + + let existingComments = ''; + if(git && pr) { + const res = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews`, { + headers: {'Authorization': `token ${auth}`} + }); + if(res.ok) { + const reviews = await res.json(); + const allComments = reviews.flatMap(r => r.comments || []); + if(allComments.length) { + existingComments = '\n\nExisting review comments (DO NOT repeat these):\n' + + allComments.map(c => `- ${c.path}:${c.line || c.position}: ${c.body}`).join('\n'); + } + } + } + let options = {ollama: {model, host}}; if(host === 'anthropic') options = {anthropic: {model, token}}; else if(host === 'openai') options = {openAi: {model, token}}; @@ -37,7 +57,7 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false}); ...options, model: [host, model], path: process.env['path'] || os.tmpdir(), - system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity directly related to changes. Ignore formatting recommendations. After making all recommendations, provide one brief bullet-point summary.`, + system: `You are a code reviewer. Analyze the git diff and use the \`recommend\` tool for EACH issue you find. You must call \`recommend\` exactly once for every bug or improvement opportunity directly related to changes. Ignore formatting recommendations. After making all recommendations, provide some concluding remarks about the overall state of the changes.${existingComments}`, tools: [{ name: 'read_file', description: 'Read contents of a file', @@ -71,11 +91,6 @@ dotenv.config({path: '.env.local', override: true, quiet: true, debug: false}); }] }); - if(!gitDiff) { - console.warn('No diff found'); - return process.exit(); - } - const messages = await ai.language.ask(gitDiff); const summary = messages.pop().content; if(git) {