--- 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` — 验证所有服务状态