# Replace any stale Comfy host agent, then start THIS clone's agent on 8199. # Called by launch-comfy-host-agent.vbs (Startup / Desktop / Start Menu). # -Wait: run in-foreground for Task Scheduler (keeps task marked Running). param([switch]$Wait) $ErrorActionPreference = 'SilentlyContinue' $root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path $node = 'C:\Program Files\nodejs\node.exe' $agent = Join-Path $root 'scripts\comfy-host-agent.mjs' if (-not (Test-Path $node)) { throw "Missing $node" } if (-not (Test-Path $agent)) { throw "Missing $agent" } Get-CimInstance Win32_Process -Filter "Name='node.exe'" | Where-Object { $_.CommandLine -match 'comfy-host-agent' } | ForEach-Object { Stop-Process -Id $_.ProcessId -Force } Get-NetTCPConnection -LocalPort 8199 -State Listen -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force } Start-Sleep -Milliseconds 400 # Caption VLM — point at existing host GGUFs (no download). $captionModels = Join-Path $env:LOCALAPPDATA 'Comfy-Desktop\ComfyUI-Shared\models\caption\qwen25vl-7b-nsfw-v4' $llamaServer = Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Packages\ggml.llamacpp_Microsoft.Winget.Source_8wekyb3d8bbwe\llama-server.exe' if (Test-Path $captionModels) { $env:CAPTION_MODELS = $captionModels } if (Test-Path $llamaServer) { $env:CAPTION_LLAMA_SERVER = $llamaServer } if ($Wait) { Set-Location $root & $node $agent exit $LASTEXITCODE } $psi = New-Object System.Diagnostics.ProcessStartInfo $psi.FileName = $node $psi.Arguments = "`"$agent`"" $psi.WorkingDirectory = $root $psi.UseShellExecute = $false $psi.CreateNoWindow = $true $psi.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden # CAPTION_* already set on this process; child inherits when UseShellExecute is false [void][System.Diagnostics.Process]::Start($psi)