# Ensure requirements.txt is UTF-8 (pip on Linux breaks on UTF-16 from Windows editors).
$path = Join-Path (Split-Path (Split-Path $PSScriptRoot -Parent) -Parent) "requirements.txt"
if (-not (Test-Path $path)) { return }
$bytes = [System.IO.File]::ReadAllBytes($path)
$isUtf16 = ($bytes.Length -ge 4 -and $bytes[1] -eq 0 -and $bytes[3] -eq 0)
if ($bytes.Length -ge 2 -and $bytes[0] -eq 0xFF -and $bytes[1] -eq 0xFE) { $isUtf16 = $true }
if (-not $isUtf16) { return }
$enc = New-Object System.Text.UnicodeEncoding $false, $false
$text = $enc.GetString($bytes)
$utf8 = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($path, $text, $utf8)
Write-Host "Converted requirements.txt from UTF-16 to UTF-8" -ForegroundColor Yellow
