oclaw/runtime/operations/scripts/weixin_status.ps1
oliver 31e3962c74 Harden attachment access controls and stabilize the Weixin bridge.
This persists referenced media safely, adds explicit attachment ACL/backfill flows, and fixes the Weixin sidecar so official login state can bridge reliably into oclaw without duplicate replays or dropped replies.

Made-with: Cursor
2026-04-28 15:38:55 +08:00

83 lines
2.3 KiB
PowerShell

param(
[string]$ChannelId = "oclaw-weixin"
)
$ErrorActionPreference = "Stop"
function Resolve-RepoRoot {
$here = Split-Path -Parent $PSCommandPath
# runtime/operations/scripts -> repo root
return (Resolve-Path (Join-Path $here "..\\..\\..")).Path
}
$oclawRoot = Resolve-RepoRoot
$sidecarRoot = Join-Path $oclawRoot "data\\channel_sidecar\\$ChannelId"
$pidFile = Join-Path $sidecarRoot "pid.txt"
$systemNodeDir = "C:\\Program Files\\nodejs"
if (Test-Path (Join-Path $systemNodeDir "node.exe")) {
$env:PATH = "$systemNodeDir;$env:PATH"
}
function Get-SidecarProcesses {
$escapedSidecarRoot = $sidecarRoot.Replace("\", "\\")
$patterns = @(
"*$ChannelId*",
"*runner.ts*",
"*$escapedSidecarRoot*"
)
Get-CimInstance Win32_Process | Where-Object {
$cmd = [string]($_.CommandLine)
if (-not $cmd) { return $false }
foreach ($pattern in $patterns) {
if ($cmd -like $pattern) { return $true }
}
return $false
}
}
if (-not (Test-Path $pidFile)) {
$sidecarProcs = @(Get-SidecarProcesses)
if ($sidecarProcs.Count -gt 0) {
$pids = ($sidecarProcs | Select-Object -ExpandProperty ProcessId) -join ","
Write-Host "status=orphaned count=$($sidecarProcs.Count) pids=$pids"
exit 0
}
Write-Host "status=stopped"
exit 0
}
$procId = (Get-Content -Path $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
if (-not $procId) {
Write-Host "status=stopped"
exit 0
}
$exists = $false
try {
Get-Process -Id $procId -ErrorAction Stop | Out-Null
$exists = $true
} catch {}
if ($exists) {
$sidecarProcs = @(Get-SidecarProcesses)
Write-Host "status=running pid=$procId matches=$($sidecarProcs.Count)"
} else {
$sidecarProcs = @(Get-SidecarProcesses)
if ($sidecarProcs.Count -gt 0) {
$pids = ($sidecarProcs | Select-Object -ExpandProperty ProcessId) -join ","
Write-Host "status=orphaned stale_pid=$procId count=$($sidecarProcs.Count) pids=$pids"
exit 0
}
$openclawCmd = Get-Command openclaw -ErrorAction SilentlyContinue
if ($openclawCmd) {
try {
$txt = (& openclaw channels status --probe) -join "`n"
if ($txt -match "openclaw-weixin .*running") {
Write-Host "status=running mode=official"
exit 0
}
} catch {}
}
Write-Host "status=stale_pid pid=$procId"
}