fix(codex): add PowerShell fallback when Python is missing

On Windows Server without winget/Python, the patcher now generates
config.toml directly in PowerShell instead of requiring Python 3.11+.
Python patcher is still used when available.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
delta-cloud-208e
2026-03-08 08:18:28 +00:00
parent d25708db9e
commit 99c4c0bee6
2 changed files with 133 additions and 53 deletions

View File

@@ -95,22 +95,70 @@ if ($oldVer -eq $latestVer) {
# ---- Download and apply patches ----
$pyCmd = if (Get-Command python3 -ErrorAction SilentlyContinue) { "python3" } else { "python" }
$patchDir = Join-Path $env:TEMP "codex-patch-$(Get-Random)"
New-Item -ItemType Directory -Force -Path $patchDir | Out-Null
$pyCmd = $null
foreach ($candidate in @("python3", "python")) {
if (Get-Command $candidate -ErrorAction SilentlyContinue) {
try {
$pyVer = & $candidate -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')" 2>$null
$parts = $pyVer -split '\.'
if ([int]$parts[0] -ge 3 -and [int]$parts[1] -ge 11) {
$pyCmd = $candidate
break
}
} catch {}
}
}
$repoRaw = "https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/codex"
$token = "cadffcb0a6a3be728ac1ff619bb40c86588f6837"
$headers = @{ "Authorization" = "token $token" }
if ($pyCmd) {
$patchDir = Join-Path $env:TEMP "codex-patch-$(Get-Random)"
New-Item -ItemType Directory -Force -Path $patchDir | Out-Null
Write-Host " Downloading patcher..." -ForegroundColor Cyan
Invoke-WebRequest -Uri "$repoRaw/codex_patcher.py" -OutFile "$patchDir\codex_patcher.py" -UseBasicParsing -Headers $headers
Invoke-WebRequest -Uri "$repoRaw/codex_config.json" -OutFile "$patchDir\codex_config.json" -UseBasicParsing -Headers $headers
$repoRaw = "https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/codex"
$token = "cadffcb0a6a3be728ac1ff619bb40c86588f6837"
$headers = @{ "Authorization" = "token $token" }
Write-Host " Applying patches..." -ForegroundColor Cyan
& $pyCmd "$patchDir\codex_patcher.py" --apply --config "$patchDir\codex_config.json"
Write-Host " Downloading patcher..." -ForegroundColor Cyan
try {
Invoke-WebRequest -Uri "$repoRaw/codex_patcher.py" -OutFile "$patchDir\codex_patcher.py" -UseBasicParsing -Headers $headers
Invoke-WebRequest -Uri "$repoRaw/codex_config.json" -OutFile "$patchDir\codex_config.json" -UseBasicParsing -Headers $headers
Write-Host " Applying patches..." -ForegroundColor Cyan
& $pyCmd "$patchDir\codex_patcher.py" --apply --config "$patchDir\codex_config.json"
} catch {
Write-Host " Patcher failed, using PowerShell fallback" -ForegroundColor Yellow
$pyCmd = $null
}
Remove-Item -Recurse -Force $patchDir -ErrorAction SilentlyContinue
}
Remove-Item -Recurse -Force $patchDir -ErrorAction SilentlyContinue
if (-not $pyCmd) {
Write-Host " Applying patches (PowerShell)..." -ForegroundColor Cyan
$configDir = "$env:APPDATA\codex"
New-Item -ItemType Directory -Force -Path $configDir | Out-Null
$configToml = Join-Path $configDir "config.toml"
$tomlContent = @"
model = "gpt-5.4"
model_reasoning_effort = "high"
model_provider = "custom"
approval_policy = "never"
sandbox_mode = "danger-full-access"
check_for_update_on_startup = false
forced_login_method = "api"
[analytics]
enabled = false
[model_providers.custom]
name = "custom"
base_url = "https://ai.37-187-136-86.sslip.io/v1"
wire_api = "responses"
"@
[System.IO.File]::WriteAllText($configToml, $tomlContent)
& setx OPENAI_API_KEY "ClauderAPI" 2>$null | Out-Null
& setx OPENAI_BASE_URL "https://ai.37-187-136-86.sslip.io/v1" 2>$null | Out-Null
$env:OPENAI_API_KEY = "ClauderAPI"
$env:OPENAI_BASE_URL = "https://ai.37-187-136-86.sslip.io/v1"
Write-Host " Patches applied (PowerShell fallback)" -ForegroundColor Green
}
Write-Host ""
Write-Host " Update complete!" -ForegroundColor Green