feat: harden loose-offline sync for user JWT, schema, and console ops

Enable Binding-scoped agent push/pull, empty-table schema ensure, SyncPage inspect/drop-table, default module import, and agent-bound publish docs from the 宇恒联调意见.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-08-05 09:47:35 +08:00
parent 76cdcd760e
commit b04b180d30
59 changed files with 4762 additions and 308 deletions

View File

@@ -55,20 +55,46 @@ function Kill-Port([int]$Port) {
}
function Kill-ByCommand([string]$ProcessName, [string]$Pattern) {
Get-CimInstance Win32_Process -Filter ("Name='{0}'" -f $ProcessName) -ErrorAction SilentlyContinue | Where-Object {
$_.CommandLine -and ($_.CommandLine -match $Pattern)
} | ForEach-Object {
Write-Info (" kill {0} pid={1}" -f $ProcessName, $_.ProcessId)
Kill-Tree ([int]$_.ProcessId)
# WMI/CIM 在 Docker 半挂或本机负载高时会卡死;用限时 Job超时则跳过
$job = Start-Job -ScriptBlock {
param($ProcessName, $Pattern)
Get-CimInstance Win32_Process -Filter ("Name='{0}'" -f $ProcessName) -ErrorAction SilentlyContinue | Where-Object {
$_.CommandLine -and ($_.CommandLine -match $Pattern)
} | ForEach-Object { [int]$_.ProcessId }
} -ArgumentList $ProcessName, $Pattern
if (-not (Wait-Job $job -Timeout 5)) {
Stop-Job $job -ErrorAction SilentlyContinue
Remove-Job $job -Force -ErrorAction SilentlyContinue
return
}
$ids = @(Receive-Job $job -ErrorAction SilentlyContinue)
Remove-Job $job -Force -ErrorAction SilentlyContinue
foreach ($procId in $ids) {
if ($procId -gt 0) {
Write-Info (" kill {0} pid={1}" -f $ProcessName, $procId)
Kill-Tree $procId
}
}
}
# ----- 1) Docker first (do NOT return; native may still be running) -----
# Docker Desktop 半挂时 `docker info` 会无限阻塞,必须限时。
$dockerOk = $false
try {
$null = & docker info 2>&1
if ($LASTEXITCODE -eq 0) { $dockerOk = $true }
} catch { }
$outFile = Join-Path $env:TEMP "aijz-docker-info.out"
$errFile = Join-Path $env:TEMP "aijz-docker-info.err"
$p = Start-Process -FilePath "docker" -ArgumentList @("info") -NoNewWindow -PassThru `
-RedirectStandardOutput $outFile -RedirectStandardError $errFile
if (-not $p.WaitForExit(8000)) {
try { Stop-Process -Id $p.Id -Force -ErrorAction SilentlyContinue } catch {}
Write-Info " docker info timeout (8s); skip compose down"
$dockerOk = $false
} else {
$dockerOk = ($p.ExitCode -eq 0)
}
} catch {
$dockerOk = $false
}
if ($dockerOk) {
Write-Info "==> docker compose down --remove-orphans"
@@ -127,15 +153,9 @@ Kill-ByCommand "node.exe" "vite"
Kill-ByCommand "node.exe" "esbuild"
Kill-ByCommand "cmd.exe" "npm.*vite|vite\.js"
# Playwright Chromium leftovers from fidelity shots
# Playwright Chromium leftovers from fidelity shots(限时,避免 CIM 卡死)
Kill-ByCommand "chrome.exe" "ms-playwright|playwright"
Kill-ByCommand "chromium.exe" "ms-playwright|playwright"
Get-CimInstance Win32_Process -ErrorAction SilentlyContinue | Where-Object {
$_.Name -match '^(chrome|chromium)\.exe$' -and $_.CommandLine -match 'ms-playwright|playwright_chromium'
} | ForEach-Object {
Write-Info (" kill playwright browser pid={0}" -f $_.ProcessId)
Kill-Tree ([int]$_.ProcessId)
}
# ----- 5) Ports (authoritative) -----
foreach ($port in 8888, 8001, 8180, 5173) {
@@ -171,3 +191,4 @@ if ($still.Count -gt 0) {
Write-Info "OK stopped (docker + native; ports 8888/8001/8180/5173 free)"
exit 0