param( [string]$Root = 'C:\ProgramData\VibeCodingRemoteCompilation', [string]$OutputPath = (Join-Path $env:TEMP ('RemoteCompile-diagnostics-' + (Get-Date -Format 'yyyyMMdd-HHmmss') + '.txt')) ) $ErrorActionPreference = 'Stop' $lines = New-Object 'System.Collections.Generic.List[string]' $token = '' $configPath = Join-Path $Root 'bin\RemoteCompileService.xml' if (Test-Path -LiteralPath $configPath) { [xml]$config = Get-Content -LiteralPath $configPath -Raw $token = [string](($config.service.env | Where-Object name -eq 'REMOTE_BUILD_TOKEN').value) } function Add-Section([string]$name, [scriptblock]$collect) { $lines.Add("`r`n## $name") try { $value = (& $collect 2>&1 | Out-String -Width 220) if ($token) { $value = $value.Replace($token, '[REDACTED]') } $value = $value -replace '(?i)Bearer\s+[A-Za-z0-9._~+/-]+', 'Bearer [REDACTED]' $value = $value -replace '(?i)((?:password|passwd|secret|access_token)\s*[=:]\s*)[^\s,;]+', '$1[REDACTED]' $lines.Add($value) } catch { $lines.Add('Collection failed: ' + $_.Exception.Message) } } Add-Section 'System and service' { Get-Date -Format o Get-CimInstance Win32_OperatingSystem | Select-Object Caption,Version,LastBootUpTime Get-CimInstance Win32_Service -Filter "Name='RemoteCompile' OR Name='sshd'" | Select-Object Name,State,StartMode,StartName,ProcessId } Add-Section 'Listening ports' { Get-NetTCPConnection -State Listen | Where-Object LocalPort -in @(22,8765) | Select-Object LocalAddress,LocalPort,OwningProcess } Add-Section 'Toolchain configuration (token omitted)' { if ($config) { $config.service.env | Where-Object name -in @('JAVA_HOME','ANDROID_HOME','ANDROID_SDK_ROOT','GRADLE_USER_HOME','HOME','USERPROFILE') | Select-Object name,value } } Add-Section 'Authenticated local health check' { if (-not $token) { throw 'Service config/token unavailable; run as administrator.' } Invoke-RestMethod -Uri 'http://127.0.0.1:8765/api/v1/health' -Headers @{Authorization="Bearer $token"} -TimeoutSec 5 | ConvertTo-Json -Compress } Add-Section 'Service wrapper and application logs' { Get-ChildItem -LiteralPath (Join-Path $Root 'logs') -File | Where-Object Extension -eq '.log' | ForEach-Object { 'FILE: ' + $_.Name Get-Content -LiteralPath $_.FullName -Tail 120 } } Add-Section 'Recent build results' { Get-ChildItem -LiteralPath (Join-Path $Root 'data\artifacts') -Filter build.json -Recurse -File -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending | Select-Object -First 5 | ForEach-Object { $build = Get-Content -LiteralPath $_.FullName -Raw | ConvertFrom-Json $build | Select-Object id,project,revision,task,status | ConvertTo-Json -Compress $build.logs | Select-Object -Last 120 } } Add-Section 'Active build markers' { Get-ChildItem -LiteralPath (Join-Path $Root 'data\projects') -Filter active-build -Recurse -File -ErrorAction SilentlyContinue | ForEach-Object { $_.FullName Get-Content -LiteralPath $_.FullName } } Add-Section 'Related service control events (48 hours)' { Get-WinEvent -FilterHashtable @{LogName='System';ProviderName='Service Control Manager';StartTime=(Get-Date).AddDays(-2)} -MaxEvents 300 | Where-Object Message -match 'RemoteCompile|VibeCoding|sshd|OpenSSH' | Select-Object TimeCreated,Id,LevelDisplayName,Message | Format-List } [IO.File]::WriteAllText($OutputPath,($lines -join "`r`n"),(New-Object Text.UTF8Encoding($false))) Write-Output "Diagnostics saved: $OutputPath" Write-Output 'The service token is redacted. Review build output for project-specific secrets before sharing.'