Job 1788372148257

Command: python -c "from pathlib import Path;p=Path(r'C:\Users\ash\Documents\Codex\2026-08-26\worked-for-1m-5s-inference-ya\bootstrap_zero_dashboard.ps1');s=p.read_text(encoding='utf-8',errors='replace');print('\n'.join(s.splitlines()[:90]))"
Directory: projects
Status: SUCCESS
Exit code: 0

Cancel Job Rerun Command Refresh

# bootstrap_zero_dashboard.ps1
# Idempotent logon bootstrap: bridge -> wait health -> supervisor (-> quick tunnel).
# Safe to run repeatedly. Does NOT touch existing named tunnel.
# Designed for Task Scheduler ONLOGON (current user, no admin).

$ErrorActionPreference = "Stop"
$root = $PSScriptRoot
$bridgeScript = Join-Path $root "bridge.py"
$supervisorScript = Join-Path $root "quick_tunnel_supervisor.py"
$stateDir = Join-Path $root "bridge-data\quick-tunnel"
$bridgePidFile = Join-Path $root "bridge-data\bridge.pid"
$supervisorPidFile = Join-Path $stateDir "supervisor.pid"
$bridgeBase = "http://127.0.0.1:8765"

function Test-PidAlive([int]$pidToCheck) {
    try { $null = Get-Process -Id $pidToCheck -ErrorAction Stop; return $true }
    catch { return $false }
}

function Test-SupervisorPid([int]$pidToCheck) {
    try {
        $process = Get-CimInstance Win32_Process -Filter "ProcessId=$pidToCheck" -ErrorAction Stop
        return $null -ne $process -and $process.CommandLine -match 'quick_tunnel_supervisor\.py'
    } catch {
        return $false
    }
}

function Get-PythonExe {
    $p = Get-Command python -ErrorAction SilentlyContinue
    if ($p) { return $p.Source }
    $fallback = "C:\Users\ash\AppData\Local\Programs\Python\Python312\python.exe"
    if (Test-Path $fallback) { return $fallback }
    return $null
}

# Prepend Codex node bin to PATH so wrangler/npx resolve inside supervisor
$nodeBase = "C:\Users\ash\AppData\Local\OpenAI\Codex\runtimes\cua_node"
if (Test-Path $nodeBase) {
    $child = Get-ChildItem $nodeBase -Directory | Sort-Object Name -Descending | Select-Object -First 1
    if ($child) {
        $bin = Join-Path $child.FullName "bin"
        if (Test-Path $bin) { $env:PATH = "$bin;$env:PATH" }
    }
}

# Wait for networking (after reboot, DNS may take a few seconds)
$netDeadline = (Get-Date).AddSeconds(30)
while ((Get-Date) -lt $netDeadline) {
    try { $null = [System.Net.Dns]::GetHostAddresses("api.cloudflare.com"); break } catch { Start-Sleep -Seconds 2 }
}

# 1. Start bridge if not running (check via health endpoint, not PID file)
$bridgeRunning = $false
try {
    $r = Invoke-WebRequest -Uri "$bridgeBase/health" -UseBasicParsing -TimeoutSec 3 -ErrorAction Stop
    if ($r.StatusCode -eq 200) { $bridgeRunning = $true }
} catch { }
if ($bridgeRunning) {
    # refresh PID file if missing (informational only)
    if (-not (Test-Path $bridgePidFile)) {
        try {
            $conn = Get-NetTCPConnection -LocalPort 8765 -State Listen -ErrorAction Stop | Select-Object -First 1
            if ($conn) { Set-Content -Path $bridgePidFile -Value $conn.OwningProcess }
        } catch { }
    }
}
if (-not $bridgeRunning) {
    $py = Get-PythonExe
    if ($py) {
        Start-Process -FilePath $py -ArgumentList "`"$bridgeScript`"" -WorkingDirectory $root -WindowStyle Hidden
        Start-Sleep -Seconds 3
    }
}

# 2. Wait for bridge health (up to 60s)
$healthDeadline = (Get-Date).AddSeconds(60)
$bridgeOk = $false
while ((Get-Date) -lt $healthDeadline) {
    try {
        $r = Invoke-WebRequest -Uri "$bridgeBase/health" -UseBasicParsing -TimeoutSec 5 -ErrorAction Stop
        if ($r.StatusCode -eq 200) { $bridgeOk = $true; break }
    } catch { Start-Sleep -Seconds 2 }
}
if (-not $bridgeOk) { exit 1 }

# 3. Start supervisor if not running
if (-not (Test-Path $stateDir)) { New-Item -ItemType Directory -Force -Path $stateDir | Out-Null }
$supRunning = $false
if (Test-Path $supervisorPidFile) {