fix: 执行器结果通过zhiwei的XMPP发给Dad

- 新增 send_xmpp() 用hermes send经zhiwei发XMPP给hmo
- 每条TODO完成/失败/升级都调用send_xmpp
- Dad通过XMPP收到所有TODO流转结果
This commit is contained in:
知微
2026-06-24 21:50:15 +08:00
parent 0a7ad20f54
commit 7a6fb103cb
+15
View File
@@ -15,6 +15,17 @@ GATEWAY_URL = "http://localhost:8643/v1/chat/completions"
GATEWAY_KEY = "hermes123" GATEWAY_KEY = "hermes123"
def send_xmpp(msg):
"""通过zhiwei发XMPP消息给Dad"""
try:
subprocess.run(
["hermes", "send", "--to", "xmpp:hmo@yoin.fun", msg],
capture_output=True, text=True, timeout=15
)
except:
pass
def main(): def main():
start = time.time() start = time.time()
conn = sqlite3.connect(str(DB_PATH)) conn = sqlite3.connect(str(DB_PATH))
@@ -43,6 +54,7 @@ def main():
if not fix: if not fix:
# 无修复方案 → 带完整描述调gateway # 无修复方案 → 带完整描述调gateway
context = f"[自愈执行器] 系统体检发现以下问题,无自动修复方案,需分析处理。\n\n问题: {title}\n\n详情:\n{desc}".strip() context = f"[自愈执行器] 系统体检发现以下问题,无自动修复方案,需分析处理。\n\n问题: {title}\n\n详情:\n{desc}".strip()
send_xmpp(f"📋 TODO已创建(无自动修复): {title[:80]}")
else: else:
# 执行修复命令 # 执行修复命令
try: try:
@@ -51,6 +63,7 @@ def main():
conn.execute("UPDATE todos SET status='completed', note=? WHERE id=?", conn.execute("UPDATE todos SET status='completed', note=? WHERE id=?",
(f"已修复: {r.stdout.strip()[:200]}", tid)) (f"已修复: {r.stdout.strip()[:200]}", tid))
conn.commit() conn.commit()
send_xmpp(f"✅ TODO修复成功: {title[:80]}")
print(f"{title}: 已修复") print(f"{title}: 已修复")
continue continue
output = r.stderr.strip()[:500] or r.stdout.strip()[:500] output = r.stderr.strip()[:500] or r.stdout.strip()[:500]
@@ -83,11 +96,13 @@ def main():
result = reply["choices"][0]["message"]["content"][:500] result = reply["choices"][0]["message"]["content"][:500]
conn.execute("UPDATE todos SET status='completed', note=? WHERE id=?", conn.execute("UPDATE todos SET status='completed', note=? WHERE id=?",
(f"知微已处理: {result[:200]}", tid)) (f"知微已处理: {result[:200]}", tid))
send_xmpp(f"🔶 TODO需知微处理: {title[:60]}\n{result[:200]}")
print(f" 🔶 {title}") print(f" 🔶 {title}")
print(f" {result[:300]}") print(f" {result[:300]}")
except Exception as e: except Exception as e:
conn.execute("UPDATE todos SET status='pending', note=? WHERE id=?", conn.execute("UPDATE todos SET status='pending', note=? WHERE id=?",
(f"调用知微失败: {str(e)[:100]},下次再试", tid)) (f"调用知微失败: {str(e)[:100]},下次再试", tid))
send_xmpp(f"⚠️ TODO处理失败(将重试): {title[:60]}\n{str(e)[:100]}")
print(f" ⚠️ {title}: gateway API调用失败,下次再试") print(f" ⚠️ {title}: gateway API调用失败,下次再试")
conn.commit() conn.commit()