#!/usr/bin/env python3
"""Get detailed node info from ComfyUI on BC-250."""
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')

# Create a Python script on the remote to query node info
query_script = '''#!/usr/bin/env python3
import json, urllib.request

data = json.loads(urllib.request.urlopen("http://localhost:8188/object_info").read())

# Find all Z-Image and GGUF related nodes
targets = [k for k in data if any(t in k.lower() for t in ["zi_", "zimage", "z_image", "gguf", "zi ", "zsampler", "emptyz", "textencodez"])]

# Also check for standard nodes we need
standard = ["UNETLoader", "VAELoader", "VAEDecode", "SaveImage", "EmptyLatentImage", "CLIPTextEncode", "KSampler"]
for s in standard:
    if s in data and s not in targets:
        targets.append(s)

for name in sorted(targets):
    info = data[name]
    print(f"\\n=== {name} ===")
    inp = info.get("input", {}).get("required", {})
    if inp:
        print("  Required:")
        for k, v in inp.items():
            print(f"    {k}: {v}")
    opt = info.get("input", {}).get("optional", {})
    if opt:
        print("  Optional:")
        for k, v in opt.items():
            print(f"    {k}: {v}")
    out = info.get("output", [])
    out_names = info.get("output_name", [])
    print(f"  Outputs: {list(zip(out, out_names)) if out_names else out}")

# Also list ALL nodes with "empty" and "latent" in the name
print("\\n\\n=== Nodes with 'empty' or 'z' in name ===")
for k in sorted(data.keys()):
    if "empty" in k.lower() or ("z" in k.lower() and "image" in k.lower()):
        print(f"  {k}")
'''

sftp = ssh.open_sftp()
with sftp.open('/tmp/query_nodes.py', 'w') as f:
    f.write(query_script)
sftp.close()

_, stdout, stderr = ssh.exec_command("python3 /tmp/query_nodes.py", timeout=30)
out = stdout.read().decode()
err = stderr.read().decode()
print(out)
if err.strip():
    print(f"STDERR: {err.strip()}")

ssh.close()
