Private/Build-ReviewPrompt.ps1
|
function Build-ReviewPrompt { <# .SYNOPSIS Build system and user prompts for AI code review .DESCRIPTION Constructs structured prompts for AI providers with review rules and code context. .PARAMETER Rules Markdown content containing review rules .PARAMETER ReviewContext Array of file diffs with context .EXAMPLE $prompts = Build-ReviewPrompt -Rules $rules -ReviewContext $context .OUTPUTS System.Object - Hashtable with SystemPrompt and UserPrompt .NOTES Author: waldo Version: 1.0.0 #> [CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Rules, [Parameter(Mandatory = $true)] [array]$ReviewContext ) begin { Write-Verbose "Starting $($MyInvocation.MyCommand.Name)" } process { try { # Build system prompt with rules and output schema $systemPrompt = @" You are an expert AL (Application Language) code reviewer for Microsoft Dynamics 365 Business Central. Your task is to review changed code in a Pull Request and identify violations of coding standards, best practices, and potential bugs. ## Review Rules $Rules ## Output Requirements Provide your review as a JSON array with the following schema: [ { "file": "path/to/file.al", "line": 45, "severity": "error|warning|info", "message": "Clear description of the issue", "suggestion": "Optional: Suggested code fix" } ] **Severity Guidelines:** - error: Bugs, security issues, breaking changes, violations of critical standards - warning: Code smells, performance concerns, maintainability issues - info: Suggestions for improvement, style preferences **Important:** 1. Only review the CHANGED lines (marked with + in diffs) 2. Do not report on pre-existing code unless directly related to changes 3. Be specific: reference exact line numbers and code snippets 4. Provide actionable feedback with clear explanations Return ONLY the JSON array, no additional text or markdown formatting. "@ # Build user prompt with code diffs $userPrompt = "Review the following code changes:`n`n" foreach ($context in $ReviewContext) { $userPrompt += "## File: $($context.FilePath)`n`n" $userPrompt += "diff`n" $userPrompt += $context.FullDiff $userPrompt += "`n" $userPrompt += "`n`n" } $userPrompt += "Provide violations as JSON array." return @{ SystemPrompt = $systemPrompt UserPrompt = $userPrompt } } catch { Write-Error "Error in $($MyInvocation.MyCommand.Name): $_" throw } } end { Write-Verbose "Completed $($MyInvocation.MyCommand.Name)" } } |