diff --git a/codex/codex_patcher.py b/codex/codex_patcher.py index 57a65bb..4bcc8f4 100755 --- a/codex/codex_patcher.py +++ b/codex/codex_patcher.py @@ -458,9 +458,20 @@ def apply_all_patches(config, home_dir=None): print(f" Proxy: {config['base_url']}") print() + # Clean up stale model_catalog.json from previous broken installs + stale_catalog = os.path.join(codex_dir, "model_catalog.json") + if os.path.isfile(stale_catalog): + os.remove(stale_catalog) + print(f" {YELLOW}Removed stale model_catalog.json{RESET}") + # Read existing config existing = read_toml(config_path) + # Remove model_catalog_json if present (wrong format crashes Codex) + if "model_catalog_json" in existing: + del existing["model_catalog_json"] + print(f" {YELLOW}Removed model_catalog_json from config (unsupported format){RESET}") + # Backup before any changes backup_file(config_path) diff --git a/codex/ucodex_install.ps1 b/codex/ucodex_install.ps1 index 066e0ad..03445f1 100644 --- a/codex/ucodex_install.ps1 +++ b/codex/ucodex_install.ps1 @@ -153,14 +153,34 @@ if ($currentVersion -eq $latestVersion) { $codexConfigDir = "$env:USERPROFILE\.codex" $codexConfigFile = "$codexConfigDir\config.toml" if (Test-Path $codexConfigFile) { - # Check if existing config is broken (Codex writes bad TOML with dotted model keys) $existingContent = Get-Content $codexConfigFile -Raw -ErrorAction SilentlyContinue + $needsCleanup = $false + + # Check 1: broken TOML with dotted model keys (gpt-5.4 parsed as gpt-5 -> 4) if ($existingContent -match "gpt-5\s*=" -and $existingContent -match "\{.*:") { + Write-Host " Detected broken TOML (dotted key bug)" -ForegroundColor Yellow + $needsCleanup = $true + } + + # Check 2: model_catalog_json with wrong format (crashes Codex on startup) + if ($existingContent -match "model_catalog_json") { + Write-Host " Detected model_catalog_json (unsupported, removing)" -ForegroundColor Yellow + $needsCleanup = $true + } + + if ($needsCleanup) { Write-Host " Removing broken config.toml..." -ForegroundColor Yellow Remove-Item $codexConfigFile -Force -ErrorAction SilentlyContinue } } +# Clean up stale model_catalog.json if it exists +$staleCatalog = "$codexConfigDir\model_catalog.json" +if (Test-Path $staleCatalog) { + Remove-Item $staleCatalog -Force -ErrorAction SilentlyContinue + Write-Host " Removed stale model_catalog.json" -ForegroundColor Yellow +} + # ---- Apply patches ---- if ($pyCmd) { diff --git a/codex/ucodex_update.ps1 b/codex/ucodex_update.ps1 index cde2e07..cec93ce 100644 --- a/codex/ucodex_update.ps1 +++ b/codex/ucodex_update.ps1 @@ -93,6 +93,39 @@ if ($oldVer -eq $latestVer) { Write-Host " Updated: $oldVer -> $newVer" -ForegroundColor Green } +# ---- Clean up broken config from previous runs ---- + +$codexConfigDir = "$env:USERPROFILE\.codex" +$codexConfigFile = "$codexConfigDir\config.toml" +if (Test-Path $codexConfigFile) { + $existingContent = Get-Content $codexConfigFile -Raw -ErrorAction SilentlyContinue + $needsCleanup = $false + + # Check 1: broken TOML with dotted model keys + if ($existingContent -match "gpt-5\s*=" -and $existingContent -match "\{.*:") { + Write-Host " Detected broken TOML (dotted key bug)" -ForegroundColor Yellow + $needsCleanup = $true + } + + # Check 2: model_catalog_json with wrong format (crashes Codex) + if ($existingContent -match "model_catalog_json") { + Write-Host " Detected model_catalog_json (unsupported, removing)" -ForegroundColor Yellow + $needsCleanup = $true + } + + if ($needsCleanup) { + Write-Host " Removing broken config.toml..." -ForegroundColor Yellow + Remove-Item $codexConfigFile -Force -ErrorAction SilentlyContinue + } +} + +# Clean up stale model_catalog.json +$staleCatalog = "$codexConfigDir\model_catalog.json" +if (Test-Path $staleCatalog) { + Remove-Item $staleCatalog -Force -ErrorAction SilentlyContinue + Write-Host " Removed stale model_catalog.json" -ForegroundColor Yellow +} + # ---- Download and apply patches ---- $pyCmd = $null