sourcebot/packages/web/src/features/agents/review-agent/nodes/generateDiffReviewPrompt.ts
Michael Sukkarieh e64f37178a
Review Agent (#298)
* push review agent implementation

* feedback

* wip integrating review agent into monorepo

* move review agent to web

* feedback

* feedback

* add rate limit throttling to octokit

* configure agent ui in app

* docs

* add review command logic and add logging for review agent to data cache dir

* fix bug with llm returning multiple reviews in single invocation

* fix doc link bug

* feedback and improved docs for review agent

* review agent doc nits

* mcp doc nit
2025-05-12 12:10:01 -07:00

44 lines
No EOL
1.7 KiB
TypeScript

import { sourcebot_diff, sourcebot_context, sourcebot_file_diff_review_schema } from "@/features/agents/review-agent/types";
import { zodToJsonSchema } from "zod-to-json-schema";
export const generateDiffReviewPrompt = async (diff: sourcebot_diff, context: sourcebot_context[], rules: string[]) => {
console.log("Executing generate_diff_review_prompt");
const prompt = `
You are an expert software engineer that excells at reviewing code changes. Given the input, additional context, and rules defined below, review the code changes and provide a detailed review. The review you provide
must conform to all of the rules defined below. The output format of your review must conform to the output format defined below.
# Input
The input is the old and new code snippets, which represent a single hunk from a git diff. The old code snippet is the code before the changes were made, and the new code snippet is the code after the changes were made. Each code snippet
is a sequence of lines each with a line number.
## Old Code Snippet
\`\`\`
${diff.oldSnippet}
\`\`\`
## New Code Snippet
\`\`\`
${diff.newSnippet}
\`\`\`
# Additional Context
${context.map(c => `${c.type}: ${c.description}\n\n${c.context}`).join("\n\n----------------------\n\n")}
# Rules
- ${rules.join("\n- ")}
# Output Format (JSON Schema)
The output must be a valid JSON object that conforms to the following JSON schema. Do NOT respond with anything other than the JSON object. Do NOT respond with
the JSON object in a markdown code block.
${JSON.stringify(zodToJsonSchema(sourcebot_file_diff_review_schema), null, 2)}
`;
console.log("Completed generate_diff_review_prompt");
return prompt;
}