"""Quick status: is ComfyUI still running and what's the log say?"""
import paramiko

k = paramiko.Ed25519Key.from_private_key_file(r'C:\Users\fabia\.ssh\id_ed25519')
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect('192.168.178.150', username='fabian', pkey=k, timeout=10)

sftp = c.open_sftp()

# Read full log
with sftp.open('/tmp/comfyui.log', 'r') as f:
    log = f.read().decode(errors='replace')

sftp.close()

lines = log.split('\n')
print(f"Total lines: {len(lines)}")
print()

# Show only meaningful lines
for line in lines:
    s = line.strip()
    if not s:
        continue
    if 'FETCH ComfyRegistry' in s or 'All startup tasks' in s or 'FETCH DATA' in s:
        continue
    print(s)

# Check process + GPU
chan = c.get_transport().open_session()
chan.settimeout(10)
chan.exec_command('/bin/bash -c "echo; echo === PROCESS ===; ps aux | grep python3 | grep -v grep; echo; echo === GPU ===; rocm-smi 2>/dev/null | head -12; echo; echo === OUTPUT ===; ls -la ~/ComfyUI/output/ 2>/dev/null; echo; echo === QUEUE ===; curl -s http://127.0.0.1:8188/queue 2>/dev/null"')
out = b""
while True:
    try:
        chunk = chan.recv(65536)
        if not chunk: break
        out += chunk
    except: break
chan.close()
print(out.decode(errors='replace'))

c.close()
