Private/Get-GuidelineSummaries.ps1

function Get-GuidelineSummaries {
    <#
    .SYNOPSIS
    Extracts and summarizes coding guidelines using AI
     
    .DESCRIPTION
    Reads the company rules markdown file and asks the AI to provide
    a concise one-line summary for each main guideline.
     
    .PARAMETER RulesPath
    Path to the rules markdown file
     
    .PARAMETER Provider
    AI provider to use for summarization
     
    .EXAMPLE
    Get-GuidelineSummaries -RulesPath "./rules/ifacto-company-rules.md" -Provider "azure"
    #>

    
    [CmdletBinding()]
    param(
        [Parameter(Mandatory)]
        [string]$RulesPath,
        
        [Parameter(Mandatory)]
        [ValidateSet('github', 'azure', 'openai', 'anthropic')]
        [string]$Provider
    )
    
    if (-not (Test-Path $RulesPath)) {
        Write-Host "##[warning]Rules file not found: $RulesPath"
        return @()
    }
    
    try {
        $rulesContent = Get-Content $RulesPath -Raw -Encoding UTF8
        
        $prompt = @"
Read the following coding guidelines document and extract ONLY the main guideline names (the ## level headers in ALL CAPS).
For each guideline, provide a concise one-line description (10-15 words max).
 
Return ONLY a JSON array of objects with "name" and "description" fields. No other text.
 
Example format:
[
  {"name": "SINGLE OBJECT PER FILE", "description": "Each .al file must contain exactly one AL object or extension"},
  {"name": "TEST COVERAGE", "description": "Business logic changes in codeunits require corresponding test updates"}
]
 
Guidelines document:
 
$rulesContent
 
Return ONLY the JSON array, no other text or formatting.
"@


        Write-Verbose "Calling AI to summarize guidelines..."
        
        # Call the appropriate AI provider
        $response = switch ($Provider) {
            'azure' { 
                Invoke-AzureAIReview -Prompt $prompt -SystemPrompt "You are a helpful assistant that extracts and summarizes coding guidelines. Return only valid JSON." 
            }
            'github' { 
                Invoke-GitHubModelsReview -Prompt $prompt -SystemPrompt "You are a helpful assistant that extracts and summarizes coding guidelines. Return only valid JSON."
            }
            'openai' { 
                Invoke-OpenAIReview -Prompt $prompt -SystemPrompt "You are a helpful assistant that extracts and summarizes coding guidelines. Return only valid JSON."
            }
            'anthropic' { 
                Invoke-AnthropicReview -Prompt $prompt -SystemPrompt "You are a helpful assistant that extracts and summarizes coding guidelines. Return only valid JSON."
            }
        }
        
        if (-not $response) {
            Write-Verbose "No response from AI provider"
            return @()
        }
        
        # Extract JSON from response (in case there's markdown formatting)
        $jsonMatch = [regex]::Match($response, '(?s)\[.*\]')
        if ($jsonMatch.Success) {
            $jsonText = $jsonMatch.Value
        } else {
            $jsonText = $response
        }
        
        # Parse and validate JSON
        $guidelines = $jsonText | ConvertFrom-Json
        
        if ($guidelines -is [array] -and $guidelines.Count -gt 0) {
            Write-Verbose "Successfully extracted $($guidelines.Count) guidelines"
            return $guidelines
        } else {
            Write-Verbose "Invalid guideline format returned"
            return @()
        }
    }
    catch {
        Write-Verbose "Error summarizing guidelines: $_"
        return @()
    }
}