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