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:
@@ -25,7 +25,7 @@ function Refresh-Path {
|
||||
|
||||
# ---- Check prerequisites ----
|
||||
|
||||
# Python 3.11+ (for tomllib)
|
||||
# Python 3.11+ (for tomllib) — optional, fallback to PowerShell patching
|
||||
$pyCmd = $null
|
||||
foreach ($candidate in @("python3", "python")) {
|
||||
if (Test-Command $candidate) {
|
||||
@@ -41,20 +41,8 @@ foreach ($candidate in @("python3", "python")) {
|
||||
}
|
||||
|
||||
if (-not $pyCmd) {
|
||||
Write-Host " Python 3.11+ not found. Installing..." -ForegroundColor Yellow
|
||||
if (Test-Command "winget") {
|
||||
winget install --id Python.Python.3.12 --accept-package-agreements --accept-source-agreements -e 2>$null
|
||||
Refresh-Path
|
||||
foreach ($candidate in @("python3", "python")) {
|
||||
if (Test-Command $candidate) { $pyCmd = $candidate; break }
|
||||
}
|
||||
}
|
||||
if (-not $pyCmd) {
|
||||
Write-Host " Install Python 3.11+ manually: https://www.python.org/downloads/" -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
Write-Host " Python 3.11+ not found, will use PowerShell fallback for patching" -ForegroundColor Yellow
|
||||
}
|
||||
Write-Host " Python OK ($pyCmd)" -ForegroundColor Green
|
||||
|
||||
# curl (usually built into Windows 10+)
|
||||
if (-not (Test-Command "curl.exe") -and -not (Test-Command "curl")) {
|
||||
@@ -160,42 +148,86 @@ if ($currentVersion -eq $latestVersion) {
|
||||
}
|
||||
}
|
||||
|
||||
# ---- Download and apply patcher ----
|
||||
# ---- Apply patches ----
|
||||
|
||||
Write-Host " Downloading patcher..." -ForegroundColor Cyan
|
||||
$patchDir = Join-Path $env:TEMP "codex-patcher-$(Get-Random)"
|
||||
New-Item -ItemType Directory -Force -Path $patchDir | Out-Null
|
||||
if ($pyCmd) {
|
||||
# Python available — use full patcher
|
||||
Write-Host " Downloading patcher..." -ForegroundColor Cyan
|
||||
$patchDir = Join-Path $env:TEMP "codex-patcher-$(Get-Random)"
|
||||
New-Item -ItemType Directory -Force -Path $patchDir | Out-Null
|
||||
|
||||
$repoRaw = "https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/codex"
|
||||
$token = "cadffcb0a6a3be728ac1ff619bb40c86588f6837"
|
||||
$headers = @{ "Authorization" = "token $token" }
|
||||
$repoRaw = "https://git.sensey24.ru/aibot777/unlimitedcoding/raw/branch/master/codex"
|
||||
$token = "cadffcb0a6a3be728ac1ff619bb40c86588f6837"
|
||||
$headers = @{ "Authorization" = "token $token" }
|
||||
|
||||
try {
|
||||
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 " Patcher downloaded" -ForegroundColor Green
|
||||
} catch {
|
||||
# Try without auth
|
||||
} catch {
|
||||
try {
|
||||
Invoke-WebRequest -Uri "$repoRaw/codex_patcher.py" -OutFile "$patchDir\codex_patcher.py" -UseBasicParsing
|
||||
Invoke-WebRequest -Uri "$repoRaw/codex_config.json" -OutFile "$patchDir\codex_config.json" -UseBasicParsing
|
||||
Write-Host " Patcher downloaded (no auth)" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " Download failed: $_" -ForegroundColor Red
|
||||
Write-Host " Clone repo manually: git clone https://git.sensey24.ru/aibot777/unlimitedcoding.git" -ForegroundColor Yellow
|
||||
Remove-Item -Recurse -Force $patchDir -ErrorAction SilentlyContinue
|
||||
exit 1
|
||||
Write-Host " Patcher download failed, using PowerShell fallback" -ForegroundColor Yellow
|
||||
$pyCmd = $null
|
||||
}
|
||||
}
|
||||
|
||||
if ($pyCmd) {
|
||||
Write-Host " Applying patches..." -ForegroundColor Cyan
|
||||
& $pyCmd "$patchDir\codex_patcher.py" --apply --config "$patchDir\codex_config.json"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host " Patcher returned exit code $LASTEXITCODE, using PowerShell fallback" -ForegroundColor Yellow
|
||||
$pyCmd = $null
|
||||
} else {
|
||||
Write-Host " Patches applied" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
Remove-Item -Recurse -Force $patchDir -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
Write-Host " Applying patches..." -ForegroundColor Cyan
|
||||
& $pyCmd "$patchDir\codex_patcher.py" --apply --config "$patchDir\codex_config.json"
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host " Patching returned exit code $LASTEXITCODE" -ForegroundColor Yellow
|
||||
}
|
||||
Write-Host " Patches applied" -ForegroundColor Green
|
||||
if (-not $pyCmd) {
|
||||
# PowerShell fallback — generate config.toml directly
|
||||
Write-Host " Applying patches (PowerShell)..." -ForegroundColor Cyan
|
||||
|
||||
Remove-Item -Recurse -Force $patchDir -ErrorAction SilentlyContinue
|
||||
$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)
|
||||
Write-Host " config.toml created: $configToml" -ForegroundColor Green
|
||||
|
||||
# Create auth token
|
||||
$authDir = "$env:APPDATA\codex"
|
||||
$authFile = Join-Path $authDir ".codex_api_key"
|
||||
[System.IO.File]::WriteAllText($authFile, "ClauderAPI")
|
||||
Write-Host " Auth token set" -ForegroundColor Green
|
||||
|
||||
# Set env vars via setx
|
||||
& 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
|
||||
Write-Host " Env vars set via setx" -ForegroundColor Green
|
||||
}
|
||||
|
||||
# ---- Configure environment variables ----
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user