Public/Repair-CCRepo.ps1

function Repair-CCRepo {
    [CmdletBinding(SupportsShouldProcess)]
    param(
        [string]$Path = '.',
        [ValidateSet('core','active','minimal')][string]$Standard = 'core',
        [string]$Config,
        [switch]$Force
    )

    $Path = (Resolve-Path $Path -ErrorAction Stop).Path

    # Run checks to find failures
    $splat = @{ Path = $Path; Standard = $Standard; Config = $Config }
    $results = @()
    $results += Test-CCFilePresence @splat
    $results += Test-CCFolderStructure @splat

    $fixable = $results | Where-Object { $_.Status -in 'Fail','Warning' -and $_.FixAvailable }
    $fixed = 0

    foreach ($issue in $fixable) {
        switch -Regex ($issue.CheckId) {
            '^FILE-' {
                $filePath = Join-Path $Path $issue.Item
                if ($PSCmdlet.ShouldProcess($filePath, "Create file")) {
                    $dir = Split-Path $filePath -Parent
                    if ($dir -and -not (Test-Path $dir)) {
                        New-Item -ItemType Directory -Path $dir -Force | Out-Null
                    }

                    $content = switch ($issue.Item) {
                        'README.md' {
                            $repoName = Split-Path $Path -Leaf
                            "# $repoName`n`n## Overview`n`nTODO: Add overview`n`n## Installation`n`nTODO: Add installation steps`n`n## Usage`n`nTODO: Add usage examples`n"
                        }
                        '.gitignore' {
                            "# OS`n.DS_Store`nThumbs.db`n`n# IDE`n.vscode/`n.idea/`n`n# Secrets`n*.pem`n*.key`n*.pfx`n"
                        }
                        'LICENSE' {
                            $year = (Get-Date).Year
                            "MIT License`n`nCopyright (c) $year`n`nPermission is hereby granted, free of charge, to any person obtaining a copy of this software...`n"
                        }
                        'CHANGELOG.md' {
                            "# Changelog`n`nAll notable changes to this project will be documented in this file.`n`n## [Unreleased]`n`n### Added`n`n- Initial release`n"
                        }
                        '.editorconfig' {
                            "root = true`n`n[*]`nindent_style = space`nindent_size = 4`nend_of_line = lf`ncharset = utf-8`ntrim_trailing_whitespace = true`ninsert_final_newline = true`n"
                        }
                        'CODEOWNERS' {
                            "# Code owners for this repository`n* @owner`n"
                        }
                        default { "# $($issue.Item)`n" }
                    }

                    Set-Content -Path $filePath -Value $content -NoNewline
                    Write-Host " [FIXED] Created $($issue.Item)" -ForegroundColor Green
                    $fixed++
                }
            }
            '^STRUCT-' {
                $folderPath = Join-Path $Path $issue.Item
                if ($PSCmdlet.ShouldProcess($folderPath, "Create folder")) {
                    New-Item -ItemType Directory -Path $folderPath -Force | Out-Null
                    # Add .gitkeep so git tracks the empty folder
                    Set-Content -Path (Join-Path $folderPath '.gitkeep') -Value '' -NoNewline
                    Write-Host " [FIXED] Created folder $($issue.Item)" -ForegroundColor Green
                    $fixed++
                }
            }
        }
    }

    Write-Host "`n Repair complete: $fixed fix(es) applied out of $($fixable.Count) fixable issue(s)`n"
}