8900 commited on
Delete openclaw-diagnose.py
Browse files- openclaw-diagnose.py +0 -110
openclaw-diagnose.py
DELETED
|
@@ -1,110 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
# OpenClaw HF Spaces 终极万能诊断脚本 v3.0 (2026-04-10)
|
| 3 |
-
# 目标:真正“万能” —— 动态扫描任意日志 + 匹配所有已知错误 + 自动提取未知问题
|
| 4 |
-
|
| 5 |
-
import json
|
| 6 |
-
import os
|
| 7 |
-
import sys
|
| 8 |
-
import psutil
|
| 9 |
-
from datetime import datetime
|
| 10 |
-
from pathlib import Path
|
| 11 |
-
from collections import defaultdict
|
| 12 |
-
|
| 13 |
-
print("🚀 OpenClaw HF 无头容器 终极万能诊断脚本 v3.0")
|
| 14 |
-
print(f"时间: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
|
| 15 |
-
print("=" * 90)
|
| 16 |
-
|
| 17 |
-
# ==================== 1. 基础环境 ====================
|
| 18 |
-
data_dir = Path("/data")
|
| 19 |
-
print("\n📁 1. 持久存储")
|
| 20 |
-
if data_dir.exists() and os.access(data_dir, os.W_OK):
|
| 21 |
-
usage = psutil.disk_usage("/data")
|
| 22 |
-
print(f"✅ /data 可写 | 使用率 {usage.percent}%")
|
| 23 |
-
else:
|
| 24 |
-
print("❌ /data 不可写!必须开启 Persistent Storage")
|
| 25 |
-
|
| 26 |
-
# ==================== 2. 配置 JSON ====================
|
| 27 |
-
config_path = Path("/data/.openclaw/openclaw.json")
|
| 28 |
-
if not config_path.exists():
|
| 29 |
-
print("\n❌ 配置文件不存在!")
|
| 30 |
-
sys.exit(1)
|
| 31 |
-
try:
|
| 32 |
-
with open(config_path, encoding="utf-8") as f:
|
| 33 |
-
config = json.load(f)
|
| 34 |
-
print("\n✅ openclaw.json 语法合法")
|
| 35 |
-
except Exception as e:
|
| 36 |
-
print(f"\n❌ JSON 损坏: {e}")
|
| 37 |
-
sys.exit(1)
|
| 38 |
-
|
| 39 |
-
# ==================== 3. 动态日志扫描(核心万能部分) ====================
|
| 40 |
-
print("\n📜 3. 动态日志错误扫描(自动提取任意错误)")
|
| 41 |
-
log_contents = []
|
| 42 |
-
for pattern in ["*.log", "*error*", "*log*"]:
|
| 43 |
-
for log_file in list(Path("/data").rglob(pattern)) + list(Path("/tmp").rglob(pattern)):
|
| 44 |
-
try:
|
| 45 |
-
with open(log_file, "r", encoding="utf-8", errors="ignore") as f:
|
| 46 |
-
lines = f.readlines()[-200:] # 最近200行
|
| 47 |
-
log_contents.extend(lines)
|
| 48 |
-
except:
|
| 49 |
-
pass
|
| 50 |
-
|
| 51 |
-
# 提取所有可疑错误行
|
| 52 |
-
errors = [line.strip() for line in log_contents if any(k in line.lower() for k in
|
| 53 |
-
["error", "invalid", "failed", "exception", "pairing", "config", "untrusted", "required", "dmPolicy", "allowFrom"])]
|
| 54 |
-
|
| 55 |
-
unique_errors = list(dict.fromkeys(errors)) # 去重
|
| 56 |
-
print(f"检测到 {len(unique_errors)} 条可疑错误/警告")
|
| 57 |
-
|
| 58 |
-
# ==================== 4. 内置万能错误知识库 ====================
|
| 59 |
-
error_db = {
|
| 60 |
-
"dmPolicy.*allowlist.*allowFrom": "顶层 dmPolicy=allowlist 但缺少 allowFrom → 改顶层为 pairing,或每个 account 加 allowFrom",
|
| 61 |
-
"channels.telegram.allowFrom": "Telegram 配置校验失败 → 参考上面动态错误",
|
| 62 |
-
"pairing required": "需要配对 → 确认 dangerouslyDisableDeviceAuth=true + trustedProxies 包含 10.20.x.x",
|
| 63 |
-
"untrusted address": "HF 反向代理未信任 → 添加 OPENCLAW_GATEWAY_TRUSTED_PROXIES=10.20.x.x",
|
| 64 |
-
"Config invalid": "配置校验失败 → 查看上面动态错误详情",
|
| 65 |
-
"token": "Token 问题 → 长度至少32字符",
|
| 66 |
-
"workspace": "Workspace 路径问题 → 检查 agents.defaults.workspace",
|
| 67 |
-
"Supabase": "Supabase 未配置 → 添加对应环境变量",
|
| 68 |
-
"127.0.0.1": "不建议把 127.0.0.1 加入 trustedProxies(HF 环境)",
|
| 69 |
-
}
|
| 70 |
-
|
| 71 |
-
print("\n🔍 4. 错误自动匹配结果:")
|
| 72 |
-
for err in unique_errors[:15]: # 最多显示15条
|
| 73 |
-
matched = False
|
| 74 |
-
for key, fix in error_db.items():
|
| 75 |
-
if key.lower() in err.lower():
|
| 76 |
-
print(f"❌ {err}")
|
| 77 |
-
print(f" → 修复建议: {fix}")
|
| 78 |
-
matched = True
|
| 79 |
-
break
|
| 80 |
-
if not matched:
|
| 81 |
-
print(f"❓ 未知错误: {err}")
|
| 82 |
-
print(" → 请把这段完整错误复制发给 Grok,我会立刻给你定制修复方案")
|
| 83 |
-
|
| 84 |
-
# ==================== 5. Telegram 万能专项 ====================
|
| 85 |
-
print("\n📨 5. Telegram 多 bot 专项诊断")
|
| 86 |
-
tg = config.get("channels", {}).get("telegram", {})
|
| 87 |
-
if tg.get("enabled"):
|
| 88 |
-
top_dm = tg.get("dmPolicy")
|
| 89 |
-
if top_dm == "allowlist" and not tg.get("allowFrom"):
|
| 90 |
-
print("❌ 【致命】顶层 allowlist 但无 allowFrom")
|
| 91 |
-
for name, acc in tg.get("accounts", {}).items():
|
| 92 |
-
if acc.get("dmPolicy") == "allowlist" and not acc.get("allowFrom"):
|
| 93 |
-
print(f"❌ Account {name} 的 allowlist 缺少用户 ID")
|
| 94 |
-
|
| 95 |
-
# ==================== 6. 其他核心检查(保持完整) ====================
|
| 96 |
-
print("\n🔐 6. Gateway & 配对安全")
|
| 97 |
-
gw = config.get("gateway", {})
|
| 98 |
-
if len(gw.get("auth", {}).get("token", "")) < 20:
|
| 99 |
-
print("⚠️ Gateway Token 过短")
|
| 100 |
-
if not gw.get("controlUi", {}).get("dangerouslyDisableDeviceAuth"):
|
| 101 |
-
print("⚠️ dangerouslyDisableDeviceAuth 未开启(子代理易 pairing required)")
|
| 102 |
-
print(f"trustedProxies 数量: {len(gw.get('trustedProxies', []))}")
|
| 103 |
-
|
| 104 |
-
print("\n💻 7. 系统资源")
|
| 105 |
-
print(f"内存: {psutil.virtual_memory().percent}% | CPU: {psutil.cpu_percent()}%")
|
| 106 |
-
|
| 107 |
-
print("\n" + "=" * 90)
|
| 108 |
-
print("🎯 终极万能诊断完成!")
|
| 109 |
-
print("这个版本已经做到:在 HF 容器限制下能做到的最大“万能”程度。")
|
| 110 |
-
print("把 Logs 最顶部的**完整输出**复制给我,我立刻给你对应修复代码或自动修复脚本。")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|