$ErrorActionPreference = 'Stop' $milestoneRoot = $PSScriptRoot $repositoryRoot = Split-Path -Parent (Split-Path -Parent $milestoneRoot) $source = Join-Path $milestoneRoot 'source' $resultPath = Join-Path $milestoneRoot 'package2-result.json' $logPath = Join-Path $milestoneRoot 'package2.log' $metadataPath = Join-Path $milestoneRoot 'metadata2-result.json' foreach ($path in @($resultPath, $logPath, $metadataPath)) { if (Test-Path -LiteralPath $path) { throw "Refusing existing execution evidence: $path" } } $preparation = Get-Content -LiteralPath (Join-Path $milestoneRoot 'preparation.json') -Raw | ConvertFrom-Json if ($preparation.reconstruction_commit -ne 'd5650309a93f3d590a41f8a8f0322c6500568f69') { throw 'Unexpected reconstruction commit.' } . (Join-Path $repositoryRoot '.local/toolchain/env.ps1') $env:CARGO_BUILD_JOBS = '1' $env:CARGO_NET_OFFLINE = 'true' $global:arcadiaContextualMetadataState = [pscustomobject]@{ Executable = (Get-Command cargo -CommandType Application).Source; Calls = 0; Source = $source; ResultPath = $metadataPath } # Transparent timing/admission wrapper: only the unchanged packager's one exact # offline metadata command is allowed; stdout remains its original JSON stream. function cargo { $metadataArguments = @($args) $expectedArguments = @('metadata', '--locked', '--offline', '--manifest-path', (Join-Path $global:arcadiaContextualMetadataState.Source 'Cargo.toml'), '--filter-platform', 'x86_64-pc-windows-gnullvm', '--format-version', '1') if ($global:arcadiaContextualMetadataState.Calls -ne 0 -or ($metadataArguments -join "`n") -cne ($expectedArguments -join "`n")) { throw 'Only one admitted locked offline metadata operation is authorized.' } $global:arcadiaContextualMetadataState.Calls++ $metadataResult = [ordered]@{ executable = $global:arcadiaContextualMetadataState.Executable; arguments = $metadataArguments; started = [DateTime]::UtcNow.ToString('o') } try { & $global:arcadiaContextualMetadataState.Executable @metadataArguments $metadataResult.exitCode = $LASTEXITCODE } finally { $metadataResult.finished = [DateTime]::UtcNow.ToString('o') [IO.File]::WriteAllText($global:arcadiaContextualMetadataState.ResultPath, ($metadataResult | ConvertTo-Json -Depth 8) + "`n", [Text.UTF8Encoding]::new($false)) } $global:LASTEXITCODE = $metadataResult.exitCode } $started = [DateTime]::UtcNow $result = [ordered]@{ started = $started.ToString('o'); source_commit = $preparation.reconstruction_commit; version = $preparation.version } try { & (Join-Path $source 'scripts/package-windows.ps1') ` -Target x86_64-pc-windows-gnullvm ` -Version '0.2.0-preview.contextual.20260911' ` -BinaryDirectory (Join-Path $milestoneRoot 'bin') ` -LlvmMinGWRoot (Join-Path $repositoryRoot '.local/toolchain/llvm-mingw-20260826-ucrt-x86_64') ` -BuildEvidence (Join-Path $milestoneRoot 'build-evidence.json') ` -Python 'C:\Users\User\.cache\codex-runtimes\codex-primary-runtime\dependencies\python\python.exe' ` -OutputRoot (Join-Path $milestoneRoot 'packages') *>&1 | Tee-Object -FilePath $logPath if ($global:arcadiaContextualMetadataState.Calls -ne 1) { throw 'Expected exactly one metadata call.' } $result.success = $true } catch { $result.success = $false $result.error = $_.ToString() $_ | Out-String | Add-Content -LiteralPath $logPath Write-Output $_ } finally { $result.metadata_calls = $global:arcadiaContextualMetadataState.Calls $result.finished = [DateTime]::UtcNow.ToString('o') $result.elapsed_seconds = ([DateTime]::UtcNow - $started).TotalSeconds [IO.File]::WriteAllText($resultPath, ($result | ConvertTo-Json -Depth 8) + "`n", [Text.UTF8Encoding]::new($false)) } if (-not $result.success) { exit 1 }