param([string]$Root='C:\ProgramData\VibeCodingRemoteCompilation',[string]$EnvironmentFile=(Join-Path $PSScriptRoot 'build-environment.json'),[switch]$GrantCacheAccess) $ErrorActionPreference='Stop' $markers=@(Get-ChildItem -LiteralPath "$Root\data\projects" -Directory -ErrorAction SilentlyContinue | ForEach-Object {Get-Item -LiteralPath (Join-Path $_.FullName 'active-build') -ErrorAction SilentlyContinue}) if($markers.Count){Write-Output 'Active build IDs (not stopped):';$markers | ForEach-Object{Get-Content -LiteralPath $_.FullName};throw 'Wait for active builds; this upgrade never cancels them automatically.'} $configPath="$Root\bin\RemoteCompileService.xml" [xml]$config=Get-Content -LiteralPath $configPath -Raw $next=Join-Path $PSScriptRoot 'remotecompile-windows-amd64.exe' if(-not(Test-Path -LiteralPath $next)){throw 'New binary missing'} if(-not(Test-Path -LiteralPath $EnvironmentFile)){throw 'Capture build-environment.json from the intended developer account first'} $environment=Get-Content -LiteralPath $EnvironmentFile -Raw | ConvertFrom-Json if(-not $environment.gradleUserHome){throw 'Gradle cache path required'} New-Item -ItemType Directory -Force -Path $environment.gradleUserHome | Out-Null # Traverse parent directories, grant writes only to the explicitly selected Gradle cache. if($GrantCacheAccess){ $parent=Split-Path $environment.gradleUserHome while($parent -and $parent -ne [IO.Path]::GetPathRoot($parent)){ & icacls.exe $parent /grant '*S-1-5-19:(X)' | Out-Null if($LASTEXITCODE -ne 0){throw "Cannot grant cache path traversal: $parent"} $parent=Split-Path $parent } & icacls.exe $environment.gradleUserHome /grant '*S-1-5-19:(OI)(CI)M' | Out-Null if($LASTEXITCODE -ne 0){throw 'Cannot grant selected Gradle cache permission'} } Stop-Service RemoteCompile (Get-Service RemoteCompile).WaitForStatus('Stopped',[TimeSpan]::FromSeconds(45)) Copy-Item -LiteralPath "$Root\bin\remotecompile.exe" -Destination "$Root\bin\remotecompile.before-0.2.0.exe" -Force Copy-Item -LiteralPath $configPath -Destination "$configPath.before-0.2.0.xml" -Force Copy-Item -LiteralPath $next -Destination "$Root\bin\remotecompile.exe" -Force $destination="$Root\build-environment.json" Copy-Item -LiteralPath $EnvironmentFile -Destination $destination -Force $config.service.arguments=([string]$config.service.arguments -replace '\s+-environment-file\s+"[^"]*"','')+" -environment-file `"$destination`"" [IO.File]::WriteAllText($configPath,$config.OuterXml,(New-Object Text.UTF8Encoding($false))) Start-Service RemoteCompile Get-Service RemoteCompile | Select-Object Name,Status Write-Output 'Updated service. Verify HTTPS health and /api/v1/environment with the existing token and certificate.'