[CmdletBinding()] param( [string]$OfficialModel = 'gpt-5.5', [string]$CodexHome = (Join-Path $env:USERPROFILE '.codex'), [switch]$DryRun ) $ErrorActionPreference = 'Stop' $scriptUrl = 'https://gitlab.com/comluojian/agent-tools/-/raw/main/codex/windows/cli/latest/Run-CodexOfficialRestore.ps1' $scriptPath = Join-Path ([System.IO.Path]::GetTempPath()) ('CodexOfficialRestore-' + [guid]::NewGuid().ToString('N') + '.ps1') try { Invoke-WebRequest -UseBasicParsing -Uri $scriptUrl -OutFile $scriptPath $powershellCommand = Get-Command powershell.exe -ErrorAction SilentlyContinue if (-not $powershellCommand) { $powershellCommand = Get-Command pwsh.exe -ErrorAction SilentlyContinue } if (-not $powershellCommand) { throw '没有找到 PowerShell。' } $arguments = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $scriptPath, '-OfficialModel', $OfficialModel, '-CodexHome', $CodexHome) if ($DryRun) { $arguments += '-DryRun' } & $powershellCommand.Source @arguments if ($LASTEXITCODE -ne 0) { throw "官方模型恢复失败,退出码:$LASTEXITCODE" } } finally { if (Test-Path -LiteralPath $scriptPath -PathType Leaf) { Remove-Item -LiteralPath $scriptPath -Force -ErrorAction SilentlyContinue } }