fix(codex): model_catalog_json with correct Codex internal format
Previous attempt used OpenAI API format (bare array of {id, object}).
Codex expects ModelsResponse format: {"models": [{slug, display_name,
visibility, shell_type, supported_reasoning_levels, ...}]}.
Format reverse-engineered from codex-rs/core/models.json in official repo.
All 4 models (gpt-5.4, gpt-5.3-codex-spark, gpt-5.3-codex, gpt-5.2-codex)
now appear in interactive model picker.
Cleanup logic detects old bare-array format and replaces automatically.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -162,11 +162,7 @@ if (Test-Path $codexConfigFile) {
|
||||
$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
|
||||
}
|
||||
# Check 2: config will be regenerated anyway by patcher below
|
||||
|
||||
if ($needsCleanup) {
|
||||
Write-Host " Removing broken config.toml..." -ForegroundColor Yellow
|
||||
@@ -174,11 +170,14 @@ if (Test-Path $codexConfigFile) {
|
||||
}
|
||||
}
|
||||
|
||||
# Clean up stale model_catalog.json if it exists
|
||||
# Clean up old-format model_catalog.json (bare array instead of {models:[...]})
|
||||
$staleCatalog = "$codexConfigDir\model_catalog.json"
|
||||
if (Test-Path $staleCatalog) {
|
||||
Remove-Item $staleCatalog -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Removed stale model_catalog.json" -ForegroundColor Yellow
|
||||
$catContent = Get-Content $staleCatalog -Raw -ErrorAction SilentlyContinue
|
||||
if ($catContent -and $catContent.TrimStart().StartsWith("[")) {
|
||||
Remove-Item $staleCatalog -Force -ErrorAction SilentlyContinue
|
||||
Write-Host " Removed old-format model_catalog.json (wrong structure)" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
# ---- Apply patches ----
|
||||
@@ -235,10 +234,61 @@ if (-not $pyCmd) {
|
||||
Remove-Item $configToml -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# Generate model catalog (Codex internal format)
|
||||
$catalogFile = Join-Path $configDir "model_catalog.json"
|
||||
$catalogPath = $catalogFile -replace '\\', '/'
|
||||
|
||||
$modelTemplate = @{
|
||||
prefer_websockets = $false
|
||||
support_verbosity = $true
|
||||
default_verbosity = "low"
|
||||
apply_patch_tool_type = "freeform"
|
||||
input_modalities = @("text", "image")
|
||||
supports_image_detail_original = $true
|
||||
truncation_policy = @{ mode = "tokens"; limit = 10000 }
|
||||
supports_parallel_tool_calls = $true
|
||||
context_window = 272000
|
||||
default_reasoning_summary = "none"
|
||||
shell_type = "shell_command"
|
||||
visibility = "list"
|
||||
supported_in_api = $true
|
||||
availability_nux = $null
|
||||
upgrade = $null
|
||||
base_instructions = ""
|
||||
model_messages = $null
|
||||
experimental_supported_tools = @()
|
||||
supports_reasoning_summaries = $true
|
||||
supported_reasoning_levels = @(
|
||||
@{ effort = "low"; description = "Fast responses with lighter reasoning" }
|
||||
@{ effort = "medium"; description = "Balances speed and reasoning depth" }
|
||||
@{ effort = "high"; description = "Greater reasoning depth for complex problems" }
|
||||
@{ effort = "xhigh"; description = "Extra high reasoning depth" }
|
||||
)
|
||||
default_reasoning_level = "medium"
|
||||
}
|
||||
|
||||
$modelSlugs = @("gpt-5.4", "gpt-5.3-codex-spark", "gpt-5.3-codex", "gpt-5.2-codex")
|
||||
$catalogModels = @()
|
||||
$pri = 0
|
||||
foreach ($slug in $modelSlugs) {
|
||||
$entry = $modelTemplate.Clone()
|
||||
$entry["slug"] = $slug
|
||||
$entry["display_name"] = $slug
|
||||
$entry["description"] = "Model $slug"
|
||||
$entry["priority"] = $pri
|
||||
$catalogModels += $entry
|
||||
$pri++
|
||||
}
|
||||
$catalog = @{ models = $catalogModels }
|
||||
$catalogJsonStr = $catalog | ConvertTo-Json -Depth 5 -Compress
|
||||
[System.IO.File]::WriteAllText($catalogFile, $catalogJsonStr)
|
||||
Write-Host " model_catalog.json created ($($modelSlugs.Count) models)" -ForegroundColor Green
|
||||
|
||||
$tomlContent = @"
|
||||
model = "gpt-5.4"
|
||||
model_reasoning_effort = "high"
|
||||
model_provider = "custom"
|
||||
model_catalog_json = "$catalogPath"
|
||||
approval_policy = "never"
|
||||
sandbox_mode = "danger-full-access"
|
||||
check_for_update_on_startup = false
|
||||
|
||||
Reference in New Issue
Block a user