add: wechat-hermes-gateway skill
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
---
|
||||
name: wechat-hermes-gateway
|
||||
description: 微信机器人运维技能。管理 WeChat 3.9.10.19 + wxhelper DLL + wechat_agent.py + Hermes API 双向通信链路的启动、维护和故障恢复。当用户提到"启动微信agent"、"维护微信机器人"、"微信运维"、"wechat agent"、"莫荷"、"小小莫通信"时触发此技能。
|
||||
---
|
||||
|
||||
# WeChat Hermes Gateway 运维技能
|
||||
|
||||
## 🚨 环境配置
|
||||
|
||||
### 关键路径
|
||||
|
||||
| 项目 | 路径 |
|
||||
|------|------|
|
||||
| 项目根目录 | `D:\F\NewI\opencode\daily-workspace\projects\wechat-hermes-gateway\` |
|
||||
| wechat_agent.py | `...\scripts\wechat_agent.py` |
|
||||
| DLL 注入器 | `...\tools\ConsoleApplication.exe` |
|
||||
| wxhelper DLL | `...\tools\wxhelper_391019.dll` |
|
||||
| 日志文件 | `...\logs\wechat_agent.log` |
|
||||
| Python | `C:\Users\hmo\AppData\Local\Programs\Python\Python310\python.exe` |
|
||||
| serve 启动脚本 | `D:\F\NewI\opencode\daily-workspace\start-opencode-serve.bat` |
|
||||
| serve 守护 | `D:\F\NewI\opencode\daily-workspace\opencode-serve-daemon.ps1` |
|
||||
|
||||
### 关键端口
|
||||
|
||||
| 端口 | 用途 | 所在 |
|
||||
|------|------|------|
|
||||
| 4096 | opencode serve (莫荷 attach 用) | Windows |
|
||||
| 5801 | wechat_agent HTTP API (收消息 + 历史查询) | Windows |
|
||||
| 19088 | wxhelper HTTP API (收发微信) | Windows |
|
||||
| 19099 | wxhelper TCP 事件推送 | Windows |
|
||||
| 8642 | Hermes API (OpenAI 兼容) | Linux 192.168.0.103 |
|
||||
| 15000 | 网络代理 (统一端口) | Windows |
|
||||
|
||||
### 联系人
|
||||
|
||||
| 角色 | 微信名 | wxid |
|
||||
|------|--------|------|
|
||||
| 老莫 (用户) | 莫语不语 | `wxid_c0a6izmwd78y22` |
|
||||
| 莫荷 (Hermes AI) | modachenchen | `wxid_7onnerpx2s2l22` |
|
||||
|
||||
### Hermes API
|
||||
|
||||
| 项目 | 值 |
|
||||
|------|-----|
|
||||
| API 地址 | `http://192.168.0.103:8642/v1/chat/completions` |
|
||||
| Auth | `Bearer hermes123` |
|
||||
| Session | `sisyphus` (永久固定) |
|
||||
| 代理 | Linux 自动检测 192.168.0.111:15000 |
|
||||
|
||||
---
|
||||
|
||||
## 一句话启动:"启动微信agent"
|
||||
|
||||
当用户说"启动微信agent"时,执行以下流程:
|
||||
|
||||
### 第一步:启动 serve + 守护
|
||||
|
||||
serve 已由 `start-opencode-serve.bat` 管理,双击即可。
|
||||
内置 daemon 每 5分钟检查 CloseWait,≥10 自动重启。
|
||||
|
||||
### 第二步:告知用户手动操作
|
||||
|
||||
向用户说明:
|
||||
1. **打开桌面微信 3.9.10.19**(机器人号 modachenchen)
|
||||
2. **扫码登录**
|
||||
3. 登录后 agent 自动注入 DLL → 开始工作
|
||||
|
||||
### 第三步:验证
|
||||
|
||||
执行 `scripts/verify-status.ps1` 检查所有服务。
|
||||
或给 modachenchen 发条消息,看是否回复。
|
||||
|
||||
---
|
||||
|
||||
## 常用操作
|
||||
|
||||
### 发微信消息(小小莫 → 老莫)
|
||||
|
||||
```powershell
|
||||
$body = '{"to":"wxid_c0a6izmwd78y22","message":"[xxm] 内容"}'
|
||||
Invoke-WebRequest -Uri 'http://192.168.0.111:5801' -Method POST -Body $body -ContentType 'application/json; charset=utf-8' -UseBasicParsing
|
||||
```
|
||||
|
||||
**⚠️ 必须加 `charset=utf-8`**,否则 GBK 编码变乱码。
|
||||
|
||||
### 注入莫荷记忆(小小莫 → 莫荷)
|
||||
|
||||
```powershell
|
||||
$body = '{"model":"hermes-agent","messages":[{"role":"system","content":"你是莫荷。"},{"role":"user","content":"消息"}]}'
|
||||
Invoke-WebRequest -Uri 'http://192.168.0.103:8642/v1/chat/completions' -Method POST -Body $body -ContentType 'application/json; charset=utf-8' -Headers @{'Authorization'='Bearer hermes123'; 'X-Hermes-Session-Id'='sisyphus'} -UseBasicParsing
|
||||
```
|
||||
|
||||
### 查询聊天记录(本地)
|
||||
|
||||
```powershell
|
||||
Invoke-WebRequest -Uri 'http://192.168.0.111:5801/api/chatHistory' -Method POST -Body '{"wxid":"wxid_c0a6izmwd78y22","count":20}' -ContentType 'application/json; charset=utf-8' -UseBasicParsing
|
||||
```
|
||||
|
||||
### 莫荷自己拉取历史(Linux)
|
||||
|
||||
```bash
|
||||
curl -X POST http://192.168.0.111:5801/api/chatHistory \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"wxid":"wxid_c0a6izmwd78y22","count":20}'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 三向通信
|
||||
|
||||
```
|
||||
莫荷 (Hermes AI)
|
||||
/ \
|
||||
serve :4096 :8642→wechat_agent→微信
|
||||
/ \
|
||||
小小莫 ─── :5801 ───→ 老莫 (微信)
|
||||
```
|
||||
|
||||
| 方向 | 通道 | 发起方 |
|
||||
|------|------|--------|
|
||||
| 小小莫 → 老莫 | POST :5801 (charset=utf-8) | 小小莫 ✅ |
|
||||
| 小小莫 → 莫荷 | POST :8642 sisyphus session | 小小莫 ✅ |
|
||||
| 莫荷 → 小小莫 | run --attach 写 serve session | 莫荷 |
|
||||
| 莫荷 ↔ 老莫 | 微信 (wxhelper → Hermes) | 双方 ✅ |
|
||||
| 老莫 → 小小莫 | ❌ 需莫荷转述 | — |
|
||||
|
||||
前缀:`[mohe]` = 莫荷,`[xxm]` = 小小莫
|
||||
|
||||
---
|
||||
|
||||
## 历史查询
|
||||
|
||||
**数据库**:MSG0.db(优先)> MicroMsg.db(废弃,无 MSG 表)
|
||||
`get_db_handle()` 已修复:按 `MSG*.db` 模式匹配再按 MSG 表名回退。
|
||||
|
||||
**不推荐** `[HISTORY:wxid:count]` 标签(转发原始记录)
|
||||
**推荐** 莫荷自己 curl JSON 分析
|
||||
|
||||
---
|
||||
|
||||
## 速查命令
|
||||
|
||||
```powershell
|
||||
# 启动 agent
|
||||
$env:PYTHONHOME=''
|
||||
& "C:\Users\hmo\AppData\Local\Programs\Python\Python310\python.exe" "D:\F\NewI\opencode\daily-workspace\projects\wechat-hermes-gateway\scripts\wechat_agent.py"
|
||||
|
||||
# 查日志
|
||||
Get-Content -Path "D:\F\NewI\opencode\daily-workspace\projects\wechat-hermes-gateway\logs\wechat_agent.log" -Tail 20 -Encoding UTF8
|
||||
|
||||
# 检查 wxhelper
|
||||
Invoke-WebRequest -Uri 'http://127.0.0.1:19088/api/checkLogin' -Method POST -Body '{}' -ContentType 'application/json' -UseBasicParsing
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 已知问题
|
||||
|
||||
| 问题 | 说明 |
|
||||
|------|------|
|
||||
| 编码乱码 | PowerShell 发微信必须加 `charset=utf-8` |
|
||||
| 群成员列表为空 | wxhelper API 限制 |
|
||||
| 语音转文字 | wxhelper 不支持提取语音 |
|
||||
| serve 僵尸连接 | 守护进程自动处理 |
|
||||
|
||||
---
|
||||
|
||||
## Scripts
|
||||
|
||||
- `scripts/verify-status.ps1` — 验证所有服务状态
|
||||
@@ -0,0 +1,93 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
验证 WeChat Hermes Gateway 所有服务状态
|
||||
.DESCRIPTION
|
||||
检查 wxhelper、wechat_agent、serve、Hermes API 是否正常运行
|
||||
#>
|
||||
|
||||
$PROJECT = "D:\F\NewI\opencode\daily-workspace\projects\wechat-hermes-gateway"
|
||||
$LOG = Join-Path $PROJECT "logs\wechat_agent.log"
|
||||
$PASS = 0
|
||||
$FAIL = 0
|
||||
|
||||
function Test-Ok {
|
||||
$script:PASS++
|
||||
Write-Host " ✅ $($args)" -ForegroundColor Green
|
||||
}
|
||||
|
||||
function Test-Fail {
|
||||
$script:FAIL++
|
||||
Write-Host " ❌ $($args)" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host "`n🔍 WeChat Hermes Gateway 状态检查`n" -ForegroundColor Cyan
|
||||
|
||||
# 1. 检查 wechat_agent 进程
|
||||
Write-Host "--- 进程检查 ---" -ForegroundColor Yellow
|
||||
$agent = Get-CimInstance Win32_Process -Filter "Name='python.exe'" | Where-Object { $_.CommandLine -match 'wechat_agent' }
|
||||
if ($agent) {
|
||||
Test-Ok "wechat_agent.py 运行中 (PID $($agent.ProcessId))"
|
||||
} else {
|
||||
Test-Fail "wechat_agent.py 未运行"
|
||||
}
|
||||
|
||||
# 2. 检查 opencode serve
|
||||
$serve = Get-Process opencode -ErrorAction SilentlyContinue
|
||||
if ($serve) {
|
||||
Test-Ok "opencode serve 运行中 (PID $($serve.Id))"
|
||||
} else {
|
||||
Test-Fail "opencode serve 未运行"
|
||||
}
|
||||
|
||||
# 3. 检查端口
|
||||
Write-Host "`n--- 端口检查 ---" -ForegroundColor Yellow
|
||||
$ports = @{19088="wxhelper HTTP"; 19099="wxhelper TCP"; 5801="agent HTTP"; 4096="opencode serve"}
|
||||
foreach ($p in $ports.Keys) {
|
||||
$conn = netstat -ano | Select-String ":$p\s" | Select-String "LISTENING"
|
||||
if ($conn) {
|
||||
Test-Ok "端口 $p ($($ports[$p])) 监听中"
|
||||
} else {
|
||||
Test-Fail "端口 $p ($($ports[$p])) 未监听"
|
||||
}
|
||||
}
|
||||
|
||||
# 4. 检查 wxhelper
|
||||
Write-Host "`n--- wxhelper 状态 ---" -ForegroundColor Yellow
|
||||
try {
|
||||
$r = Invoke-WebRequest -Uri 'http://127.0.0.1:19088/api/checkLogin' -Method POST -Body '{}' -ContentType 'application/json' -UseBasicParsing -ErrorAction Stop
|
||||
$d = $r.Content | ConvertFrom-Json
|
||||
if ($d.code -eq 1) {
|
||||
Test-Ok "wxhelper 已注入,微信已登录"
|
||||
} else {
|
||||
Test-Fail "wxhelper 状态异常: $($d.msg)"
|
||||
}
|
||||
} catch {
|
||||
Test-Fail "wxhelper 不可达: $_"
|
||||
}
|
||||
|
||||
# 5. 检查 Hermes API
|
||||
Write-Host "`n--- Hermes API 检查 ---" -ForegroundColor Yellow
|
||||
try {
|
||||
$r = Invoke-WebRequest -Uri 'http://192.168.0.103:8642/v1/models' -Headers @{'Authorization'='Bearer hermes123'} -UseBasicParsing -ErrorAction Stop
|
||||
Test-Ok "Hermes API (:8642) 可达"
|
||||
} catch {
|
||||
Test-Fail "Hermes API 不可达: $_"
|
||||
}
|
||||
|
||||
# 6. 查看最新日志
|
||||
Write-Host "`n--- 最近日志 (5行) ---" -ForegroundColor Yellow
|
||||
if (Test-Path $LOG) {
|
||||
Get-Content $LOG -Tail 5 -Encoding UTF8 | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
|
||||
} else {
|
||||
Write-Host " (日志文件不存在)" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
# 7. 汇总
|
||||
Write-Host "`n--- 汇总 ---" -ForegroundColor Cyan
|
||||
Write-Host " 通过: $PASS | 失败: $FAIL"
|
||||
if ($FAIL -eq 0) {
|
||||
Write-Host " ✅ 所有服务正常!" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host " ⚠️ 有 $FAIL 项异常,需排查" -ForegroundColor Yellow
|
||||
}
|
||||
Write-Host ""
|
||||
Reference in New Issue
Block a user