import paramiko

client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('152.136.232.83', port=22, username='root', password='Jianhua105', timeout=10)

def run(cmd):
    print(f"\n>>> {cmd[:120]}")
    stdin, stdout, stderr = client.exec_command(cmd, timeout=20)
    out = stdout.read().decode('utf-8', errors='replace').strip()
    err = stderr.read().decode('utf-8', errors='replace').strip()
    if out: print(out[-800:])
    if err: print(f"ERR: {err[-200:]}")
    return out

# Full error log
run("tail -50 /root/.pm2/logs/ai-video-error.log")

# Also check out log
run("tail -30 /root/.pm2/logs/ai-video-out.log")

# Check if index.js has syntax errors by parsing it
run("node --check /www/wwwroot/zhinengtiapp/index.js 2>&1")

client.close()
