// Tool-specific prompt builder for review_code. import { buildBasePrompt } from "./base.js"; /** * Build a tool-specific prompt for the review_code MCP tool. * * @param {{ question: string, context?: string, constraints?: string[], expectedOutput?: string, projectSummary?: string, taskSummary?: string, relevantFiles?: Array<{path: string, content: string, language?: string}> }} input * @returns {string} A two-part prompt: base system message + review_code user message. */ export function buildReviewCodePrompt(input) { if (!input || typeof input.question !== "string" || input.question.length === 0) { const err = new TypeError("review_code requires a non-empty 'question' field."); err.kind = "ValidationError"; throw err; } const base = buildBasePrompt(); const lines = [ "", "---", "", "You are acting as a code reviewer for Claude Code. Claude Code will implement your suggestions — you do not implement anything yourself.", "", "Your task: review the supplied code only and provide a focused, actionable assessment.", "", "Review across these dimensions:", "- Correctness — bugs, logic errors, off-by-one, type coercion issues.", "- Edge cases — boundary values, empty/null inputs, unexpected states.", "- Security — injection, auth bypass, data exposure, unsafe patterns.", "- Maintainability — readability, naming, cohesion, testability.", "- Unnecessary complexity — over-engineering, nested conditionals, abstractions that add no value.", "- Performance — obvious inefficiencies when relevant (N+1, unnecessary allocations, blocking ops).", "- Missing validation or error handling — unchecked inputs, swallowed errors, missing catch blocks.", "- Simpler approaches — more concise or idiomatic alternatives.", "", "Important rules:", "- Claude Code remains the implementation agent. You are acting only as a reviewer.", "- Review only the supplied files and snippets. Do not assume access to the full repository.", "- Do not make assumptions about files, configuration, or architecture that you have not been given.", "- Use only the context provided — call out uncertainty clearly — do not guess about unprovided information.", "", "Respond in this exact structure:", "- Summary: Brief overall assessment of the code quality.", "- Issues by Severity: Grouped into High, Medium, and Low.", "- Suggested Fixes: Small, reviewable changes with brief rationale.", "- Test Suggestions: Specific test cases that should be added or updated.", "", ]; lines.push(`Question: ${input.question}`); if (input.context) { lines.push(""); lines.push(`Context: ${input.context}`); } if (input.constraints && input.constraints.length > 0) { lines.push(""); lines.push("Constraints:"); for (const c of input.constraints) { lines.push(`- ${c}`); } } if (input.expectedOutput) { lines.push(""); lines.push(`Expected output: ${input.expectedOutput}`); } if (input.projectSummary) { lines.push(""); lines.push(`Project summary: ${input.projectSummary}`); } if (input.taskSummary) { lines.push(""); lines.push(`Task summary: ${input.taskSummary}`); } if (input.relevantFiles && input.relevantFiles.length > 0) { lines.push(""); lines.push("Relevant files:"); for (const file of input.relevantFiles) { lines.push(""); lines.push(`File: ${file.path}`); if (file.language) { lines.push(`Language: ${file.language}`); } lines.push(file.content); } } return base + "\n" + lines.join("\n"); }