Replace stale host agent on boot and document one-click Startup install.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-09-15 18:15:19 -05:00
co-authored by Cursor
parent 840440d7ef
commit df885d5732
5 changed files with 112 additions and 51 deletions
+29 -7
View File
@@ -1,26 +1,48 @@
# Installs Desktop + Start Menu shortcuts that start the Comfy host agent
# without Cursor. The scheduled task still starts the agent at logon.
# Installs Desktop, Start Menu, and Windows Startup shortcuts that start THIS
# clone's Comfy host agent (YuE2) and replace any stale process on 8199.
$ErrorActionPreference = 'Stop'
$root = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
$vbs = Join-Path $root 'scripts\launch-comfy-host-agent.vbs'
$startPs1 = Join-Path $root 'scripts\start-comfy-host-agent.ps1'
if (-not (Test-Path $vbs)) { throw "Missing $vbs" }
if (-not (Test-Path $startPs1)) { throw "Missing $startPs1" }
$shell = New-Object -ComObject WScript.Shell
$desktop = [Environment]::GetFolderPath('Desktop')
$programs = Join-Path ([Environment]::GetFolderPath('StartMenu')) 'Programs\AIGen'
$startup = [Environment]::GetFolderPath('Startup')
New-Item -ItemType Directory -Force -Path $programs | Out-Null
function Save-Shortcut([string]$dir) {
$path = Join-Path $dir 'Start Comfy Host Agent.lnk'
function Save-Shortcut([string]$dir, [string]$name = 'Start Comfy Host Agent.lnk') {
$path = Join-Path $dir $name
$lnk = $shell.CreateShortcut($path)
$lnk.TargetPath = (Join-Path $env:SystemRoot 'System32\wscript.exe')
$lnk.Arguments = "//B `"$vbs`""
$lnk.WorkingDirectory = $root
$lnk.WindowStyle = 7
$lnk.Description = 'Start the AIGen Comfy host agent in the background'
$lnk.Description = 'Start THIS AIGen Comfy host agent (YuE2) and replace any stale agent on 8199'
$lnk.Save()
$path
}
Save-Shortcut $desktop
Save-Shortcut $programs
$saved = @(
(Save-Shortcut $desktop),
(Save-Shortcut $programs),
(Save-Shortcut $startup 'AIGen Comfy Host Agent.lnk')
)
# Point the scheduled task at this clone when it already exists.
$taskName = 'AIGen Comfy Host Agent'
$existing = schtasks /Query /TN $taskName 2>$null
if ($LASTEXITCODE -eq 0) {
$hidden = Join-Path $root 'scripts\start-comfy-host-agent-hidden.vbs'
$tr = "wscript.exe //B `"$hidden`""
schtasks /Change /TN $taskName /TR $tr | Out-Null
Write-Host "Updated scheduled task '$taskName' -> $hidden"
}
Write-Host "Installed launchers for $root"
$saved | ForEach-Object { Write-Host " $_" }
Write-Host ''
Write-Host 'One click: double-click Desktop "Start Comfy Host Agent", or log off/on so Startup runs it.'
Write-Host 'That replaces any old node on 8199 with this clone (YuE2 /yue2/status).'
+7 -28
View File
@@ -1,35 +1,14 @@
' Start the Comfy host agent with no window. Safe to run when Cursor is closed.
' Uses the "AIGen Comfy Host Agent" scheduled task when it exists.
' Start THIS clone's Comfy host agent (YuE2). Replaces any stale agent on 8199.
' Safe to run at logon / from Startup / Desktop shortcut when Cursor is closed.
Option Explicit
Dim sh, fso, root, node, agent, rc
Dim sh, fso, root, ps1
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If AgentRunning() Then WScript.Quit 0
On Error Resume Next
rc = sh.Run("schtasks /run /tn ""AIGen Comfy Host Agent""", 0, True)
On Error GoTo 0
WScript.Sleep 1200
If AgentRunning() Then WScript.Quit 0
root = fso.GetParentFolderName(WScript.ScriptFullName)
root = fso.GetParentFolderName(root)
node = """C:\Program Files\nodejs\node.exe"""
agent = """" & root & "\scripts\comfy-host-agent.mjs"""
If Not fso.FileExists(Replace(node, """", "")) Then WScript.Quit 1
sh.CurrentDirectory = root
sh.Run node & " " & agent, 0, False
ps1 = root & "\scripts\start-comfy-host-agent.ps1"
If Not fso.FileExists(ps1) Then WScript.Quit 1
Function AgentRunning()
Dim svc, query, item
AgentRunning = False
Set svc = GetObject("winmgmts:\\.\root\cimv2")
Set query = svc.ExecQuery("SELECT CommandLine FROM Win32_Process WHERE Name='node.exe'")
For Each item In query
If InStr(LCase("" & item.CommandLine), "comfy-host-agent") > 0 Then
AgentRunning = True
Exit Function
End If
Next
End Function
sh.CurrentDirectory = root
sh.Run "powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File """ & ps1 & """", 0, False
+12 -8
View File
@@ -1,11 +1,15 @@
' Launch the Comfy host agent with no console window.
' Window style 0 = hidden. Wait = True so Task Scheduler keeps the task marked Running.
' Launch the Comfy host agent with no console window (Task Scheduler wait mode).
' Replaces any stale agent on 8199, then runs THIS clone's agent until it exits.
Option Explicit
Dim sh, root, node, agent
Dim sh, fso, root, ps1
Set sh = CreateObject("WScript.Shell")
root = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
root = CreateObject("Scripting.FileSystemObject").GetParentFolderName(root)
node = """C:\Program Files\nodejs\node.exe"""
agent = """" & root & "\scripts\comfy-host-agent.mjs"""
Set fso = CreateObject("Scripting.FileSystemObject")
root = fso.GetParentFolderName(WScript.ScriptFullName)
root = fso.GetParentFolderName(root)
ps1 = root & "\scripts\start-comfy-host-agent.ps1"
If Not fso.FileExists(ps1) Then WScript.Quit 1
sh.CurrentDirectory = root
sh.Run node & " " & agent, 0, True
' Wait=True so Task Scheduler keeps the task marked Running while the agent lives.
sh.Run "powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File """ & ps1 & """ -Wait", 0, True
+34
View File
@@ -0,0 +1,34 @@
# 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
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
[void][System.Diagnostics.Process]::Start($psi)