[CmdletBinding()] param( [string]$OfficialModel = 'gpt-5.5', [string]$CodexHome = (Join-Path $env:USERPROFILE '.codex'), [string]$TestRoot, [switch]$DryRun ) $ErrorActionPreference = 'Stop' $scriptUrl = 'https://gitlab.com/comluojian/agent-tools/-/raw/main/codex/windows/desktop/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 was not found.' } $arguments = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $scriptPath, '-OfficialModel', $OfficialModel, '-CodexHome', $CodexHome) if (-not [string]::IsNullOrWhiteSpace($TestRoot)) { $arguments += @('-TestRoot', $TestRoot) } if ($DryRun) { $arguments += '-DryRun' } & $powershellCommand.Source @arguments if ($LASTEXITCODE -ne 0) { throw "Official model restore failed, exit code: $LASTEXITCODE" } } finally { if (Test-Path -LiteralPath $scriptPath -PathType Leaf) { Remove-Item -LiteralPath $scriptPath -Force -ErrorAction SilentlyContinue } }