#!/usr/bin/env python3
"""Quick check on ComfyUI status."""
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.178.150', username='fabian', key_filename=r'C:\Users\fabia\.ssh\id_ed25519')

def run(cmd, timeout=30):
    _, stdout, stderr = ssh.exec_command(cmd, timeout=timeout)
    return stdout.read().decode()

# Log tail
print("=== LOG (last 40 lines) ===")
print(run("tail -40 /home/fabian/comfyui.log 2>/dev/null"))

# Process status
print("=== PROCESS ===")
print(run("bash -c 'PID=$(pgrep -f \"python3 main.py\" | head -1); "
    "if [ -n \"$PID\" ]; then "
    "  ps -p $PID -o pid,%cpu,%mem,nlwp,stat --no-headers; "
    "  echo \"LOAD: $(cat /proc/loadavg)\"; "
    "else echo DEAD; fi'"))

# rocm-smi
print("=== GPU ===")
print(run("HSA_OVERRIDE_GFX_VERSION=10.1.0 rocm-smi 2>/dev/null || echo 'no rocm-smi'"))

# Queue
print("=== QUEUE ===")
print(run("curl -s http://localhost:8188/queue 2>/dev/null || echo 'no connection'"))

# History
print("=== HISTORY ===")
hist = run("curl -s http://localhost:8188/history 2>/dev/null || echo 'no connection'")
import json
try:
    h = json.loads(hist)
    for pid, info in h.items():
        print(f"  Prompt: {pid}")
        print(f"  Status: {info.get('status', {})}")
        outputs = info.get('outputs', {})
        if outputs:
            for nid, nout in outputs.items():
                if isinstance(nout, dict):
                    for key, val in nout.items():
                        print(f"  Output node {nid}/{key}: {str(val)[:200]}")
        else:
            print("  No outputs")
except:
    print(hist[:1000])

# Output directory
print("\n=== OUTPUT FILES ===")
print(run("ls -lah /home/fabian/ComfyUI/output/ 2>/dev/null"))

ssh.close()
