<# .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 ""