# Private adapter only. Execute after root authorizes metadata/package work. #Requires -Version 7.0 $ErrorActionPreference = 'Stop' $prep = $PSScriptRoot $repo = Split-Path -Parent (Split-Path -Parent $prep) $source = Join-Path $prep 'source' $resultPath = Join-Path $prep 'package2-result.json' $logPath = Join-Path $prep 'package2.log' $metadataPath = Join-Path $prep 'metadata2-result.json' foreach ($path in @($resultPath, $logPath, $metadataPath)) { if (Test-Path -LiteralPath $path) { throw "Refusing existing evidence: $path" } } $prepared = Get-Content -LiteralPath (Join-Path $prep 'preparation.json') -Raw | ConvertFrom-Json $priorResult = Get-Content -LiteralPath (Join-Path $prep 'prepare-result.json') -Raw | ConvertFrom-Json if (-not $priorResult.success -or $prepared.base_commit -ne '33c6d83e9ba9a5b1310b1b627d7c40affcbcf15c' -or $prepared.version -ne '0.2.0-preview.navigation.20260911' -or $prepared.target -ne 'x86_64-pc-windows-gnullvm') { throw 'Missing successful designated navigation preparation.' } $head = (& git -C $source rev-parse HEAD).Trim() if ($LASTEXITCODE -ne 0 -or $head -ne $prepared.reconstruction_commit) { throw 'Reconstructed source HEAD changed.' } $dirty = & git -C $source status --porcelain if ($LASTEXITCODE -ne 0 -or $dirty) { throw 'Reconstructed source is not clean.' } foreach ($map in @($prepared.gui_inputs, $prepared.shared_non_cargo_inputs)) { foreach ($property in $map.PSObject.Properties) { if ((Get-FileHash -LiteralPath (Join-Path $source $property.Name)).Hash.ToLowerInvariant() -cne $property.Value) { throw "Frozen source changed: $($property.Name)" } } } foreach ($item in $prepared.artifacts) { if ((Get-FileHash -LiteralPath (Join-Path $prep $item.destination)).Hash.ToLowerInvariant() -cne $item.sha256) { throw "Frozen binary changed: $($item.destination)" } } . (Join-Path $repo '.local/toolchain/env.ps1') $env:CARGO_BUILD_JOBS = '1' $env:CARGO_NET_OFFLINE = 'true' # PS7 native stderr is diagnostic output; never reinterpret ordinary Cargo stderr # as a PowerShell terminating error. Native exit codes remain explicitly checked. $PSNativeCommandUseErrorActionPreference = $false $global:arcadiaNavigationMetadata = [pscustomobject]@{ Executable = (Get-Command cargo -CommandType Application).Source Calls = 0; Source = $source; ResultPath = $metadataPath } function cargo { $actual = @($args) $expected = @('metadata', '--locked', '--offline', '--manifest-path', (Join-Path $global:arcadiaNavigationMetadata.Source 'Cargo.toml'), '--filter-platform', 'x86_64-pc-windows-gnullvm', '--format-version', '1') if ($global:arcadiaNavigationMetadata.Calls -ne 0 -or ($actual -join "`n") -cne ($expected -join "`n")) { throw 'Only one exact locked offline metadata call is admitted.' } $global:arcadiaNavigationMetadata.Calls++ $receipt = [ordered]@{ executable = $global:arcadiaNavigationMetadata.Executable; arguments = $actual; started = [DateTime]::UtcNow.ToString('o') } try { & $global:arcadiaNavigationMetadata.Executable @actual $receipt.exitCode = $LASTEXITCODE } finally { $receipt.finished = [DateTime]::UtcNow.ToString('o') [IO.File]::WriteAllText($global:arcadiaNavigationMetadata.ResultPath, ($receipt | ConvertTo-Json -Depth 8) + "`n", [Text.UTF8Encoding]::new($false)) } $global:LASTEXITCODE = $receipt.exitCode if ($receipt.exitCode -ne 0) { throw "Offline metadata failed: $($receipt.exitCode)" } } $result = [ordered]@{ started = [DateTime]::UtcNow.ToString('o'); version = $prepared.version; source_commit = $head; native_acceptance = 'Pending' } try { & (Join-Path $source 'scripts/package-windows.ps1') ` -Target $prepared.target -Version $prepared.version ` -BinaryDirectory (Join-Path $prep 'bin') ` -LlvmMinGWRoot (Join-Path $repo '.local/toolchain/llvm-mingw-20260826-ucrt-x86_64') ` -BuildEvidence (Join-Path $prep 'build-evidence.json') ` -Python 'C:/Users/User/.cache/codex-runtimes/codex-primary-runtime/dependencies/python/python.exe' ` -OutputRoot (Join-Path $prep 'packages') *>&1 | Tee-Object -FilePath $logPath if ($global:arcadiaNavigationMetadata.Calls -ne 1) { throw 'Expected exactly one metadata call.' } $archive = Join-Path $prep "packages/ArcadiaStudio-$($prepared.version)-$($prepared.target).zip" $result.archive = $archive $result.archive_sha256 = (Get-FileHash -LiteralPath $archive).Hash.ToLowerInvariant() $result.archive_bytes = (Get-Item -LiteralPath $archive).Length $result.success = $true } catch { $result.success = $false $result.error = $_.ToString() $_ | Out-String | Add-Content -LiteralPath $logPath Write-Output $_ } finally { $result.finished = [DateTime]::UtcNow.ToString('o') $result.metadata_calls = $global:arcadiaNavigationMetadata.Calls [IO.File]::WriteAllText($resultPath, ($result | ConvertTo-Json -Depth 8) + "`n", [Text.UTF8Encoding]::new($false)) Remove-Item Function:\cargo Remove-Variable arcadiaNavigationMetadata -Scope Global } if (-not $result.success) { exit 1 }