param( [string]$Root = 'C:\ProgramData\VibeCodingRemoteCompilation', [Parameter(Mandatory=$true)][string]$JavaHome, [string]$AndroidHome = 'D:\AndroidSdk\Windows' ) $ErrorActionPreference = 'Stop' if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { throw 'Administrator required' } if (-not (Test-Path -LiteralPath "$JavaHome\bin\java.exe")) { throw 'Invalid JavaHome' } if (-not (Test-Path -LiteralPath "$AndroidHome\platforms")) { throw 'Invalid AndroidHome' } foreach ($name in @('remotecompile-windows-amd64.exe','WinSW-x64-v2.12.0.exe')) { if (-not (Test-Path -LiteralPath (Join-Path $PSScriptRoot $name))) { throw "Missing $name" } } if (Get-Service RemoteCompile -ErrorAction SilentlyContinue) { Stop-Service RemoteCompile (Get-Service RemoteCompile).WaitForStatus('Stopped',[TimeSpan]::FromSeconds(45)) } New-Item -ItemType Directory -Force -Path $Root | Out-Null & icacls.exe $Root /inheritance:r /grant:r '*S-1-5-18:(OI)(CI)F' '*S-1-5-32-544:(OI)(CI)F' '*S-1-5-19:(OI)(CI)RX' | Out-Null if ($LASTEXITCODE -ne 0) { throw 'Root ACL failed' } foreach ($dir in @('bin','logs','data','home','temp')) { New-Item -ItemType Directory -Force -Path (Join-Path $Root $dir) | Out-Null } foreach ($dir in @('logs','data','home','temp')) { & icacls.exe (Join-Path $Root $dir) /grant:r '*S-1-5-19:(OI)(CI)M' | Out-Null if ($LASTEXITCODE -ne 0) { throw 'Data ACL failed' } } $config = Join-Path $Root 'bin\RemoteCompileService.xml' if (Test-Path -LiteralPath $config) { [xml]$old = Get-Content -LiteralPath $config -Raw $token = ($old.service.env | Where-Object name -eq 'REMOTE_BUILD_TOKEN').value } else { $bytes = New-Object byte[] 32 $rng = [Security.Cryptography.RandomNumberGenerator]::Create() try { $rng.GetBytes($bytes) } finally { $rng.Dispose() } $token = ([BitConverter]::ToString($bytes)).Replace('-','').ToLowerInvariant() } if ($token.Length -lt 24) { throw 'Invalid token' } Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'remotecompile-windows-amd64.exe') -Destination "$Root\bin\remotecompile.exe" -Force Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'WinSW-x64-v2.12.0.exe') -Destination "$Root\bin\RemoteCompileService.exe" -Force function XmlEscape([string]$value) { [Security.SecurityElement]::Escape($value) } $safeRoot = XmlEscape $Root $safeJava = XmlEscape $JavaHome $safeSdk = XmlEscape $AndroidHome $xml = @" RemoteCompile VibeCoding Remote Compilation Android remote build service, loopback only. $safeRoot\bin\remotecompile.exe -listen 127.0.0.1:8765 -data "$safeRoot\data" -tasks :app:assembleDebug $safeRoot Automatic true 40 sec $safeRoot\logs 102404 NT AUTHORITYLocalService "@ [IO.File]::WriteAllText($config,$xml,(New-Object Text.UTF8Encoding($false))) if (-not (Get-Service RemoteCompile -ErrorAction SilentlyContinue)) { & "$Root\bin\RemoteCompileService.exe" install if ($LASTEXITCODE -ne 0) { throw 'Service installation failed' } } Start-Service RemoteCompile $headers = @{Authorization="Bearer $token"} $healthy = $false for ($i=0;$i -lt 30;$i++) { try { $result = Invoke-RestMethod -Uri 'http://127.0.0.1:8765/api/v1/health' -Headers $headers -TimeoutSec 2 Write-Output ('Health: ' + ($result | ConvertTo-Json -Compress)); $healthy=$true; break } catch { Start-Sleep -Seconds 1 } } if (-not $healthy) { throw "Service health failed. Check $Root\logs" } $tokenPath = Join-Path $env:USERPROFILE '.remotecompile-service-token.txt' [IO.File]::WriteAllText($tokenPath,$token,(New-Object Text.UTF8Encoding($false))) $sid = [Security.Principal.WindowsIdentity]::GetCurrent().User.Value & icacls.exe $tokenPath /inheritance:r /grant:r "*$($sid):R" '*S-1-5-18:F' '*S-1-5-32-544:F' | Out-Null if ($LASTEXITCODE -ne 0) { throw 'Token ACL failed' } Get-CimInstance Win32_Service -Filter "Name='RemoteCompile'" | Select-Object Name,State,StartMode,StartName Write-Output 'Client token exported privately; contents hidden.'