# Quick verification script for training package # Usage: .\scripts\quick-verify-training-package.ps1 D:\qiwei-training param( [Parameter(Mandatory=$true)] [string]$TrainingDir, [int]$TimeoutSeconds = 15 ) $ErrorActionPreference = "Stop" Write-Host "`n=== Training Package Quick Verification ===" -ForegroundColor Cyan Write-Host "Target directory: $TrainingDir`n" # Step 1: Check directory structure Write-Host "[1/7] Checking directory structure..." -ForegroundColor Yellow $requiredFiles = @( "qiwei-workbench.exe", "web\index.html", "web\app.js", "knowledge\rules.md", ".env.local", ".mcp.json", "README.md" ) $missing = @() foreach ($file in $requiredFiles) { $path = Join-Path $TrainingDir $file if (-not (Test-Path $path)) { $missing += $file } } if ($missing.Count -gt 0) { Write-Host "[X] Missing files:" -ForegroundColor Red $missing | ForEach-Object { Write-Host " - $_" -ForegroundColor Red } exit 1 } Write-Host "[OK] Directory structure complete`n" -ForegroundColor Green # Step 1b: Check portable MCP registration before starting the dashboard. Write-Host "[1b/7] Checking MCP registration and tool discovery..." -ForegroundColor Yellow $mcpConfig = Get-Content (Join-Path $TrainingDir ".mcp.json") -Raw | ConvertFrom-Json $mcpEntry = $mcpConfig.mcpServers.'qiwei-assistant' if (-not $mcpEntry) { Write-Host "[X] .mcp.json does not register qiwei-assistant" -ForegroundColor Red exit 1 } if (-not ($mcpEntry.args -contains "mcp")) { Write-Host "[X] qiwei-assistant is missing the mcp subcommand" -ForegroundColor Red exit 1 } $mcpVerifier = Join-Path $PSScriptRoot "verify-training-package-mcp.js" if (Get-Command node -ErrorAction SilentlyContinue) { $mcpResult = & node $mcpVerifier $TrainingDir 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host "[X] MCP handshake failed: $mcpResult" -ForegroundColor Red exit 1 } Write-Host "[OK] MCP registered and tools discovered: $mcpResult`n" -ForegroundColor Green } else { Write-Host "[WARN] Node.js not found; registration structure checked, handshake deferred" -ForegroundColor Yellow } # Step 2: Check port availability Write-Host "[2/7] Checking port availability..." -ForegroundColor Yellow $ports = @(4320, 4310) $occupied = @() foreach ($port in $ports) { $conn = Get-NetTCPConnection -LocalPort $port -State Listen -ErrorAction SilentlyContinue if ($conn) { $occupied += $port } } if ($occupied.Count -gt 0) { Write-Host "[X] Ports occupied: $($occupied -join ', ')" -ForegroundColor Red Write-Host " Please stop processes or use different ports" -ForegroundColor Yellow exit 1 } Write-Host "[OK] Ports available`n" -ForegroundColor Green # Step 3: Start workbench Write-Host "[3/7] Starting workbench..." -ForegroundColor Yellow $exePath = Join-Path $TrainingDir "qiwei-workbench.exe" $process = Start-Process -FilePath $exePath -ArgumentList "--no-open" -WorkingDirectory $TrainingDir -PassThru -WindowStyle Hidden Start-Sleep -Seconds 5 if ($process.HasExited) { Write-Host "[X] Workbench exited immediately" -ForegroundColor Red exit 1 } Write-Host "[OK] Workbench started (PID: $($process.Id))`n" -ForegroundColor Green # Step 4: Check Dashboard response Write-Host "[4/7] Checking Dashboard response..." -ForegroundColor Yellow $maxRetries = 5 $retryCount = 0 $dashboardOk = $false while ($retryCount -lt $maxRetries) { try { $response = Invoke-WebRequest -Uri "http://127.0.0.1:4320/api/status" -Method GET -UseBasicParsing -TimeoutSec 3 if ($response.StatusCode -eq 200) { $dashboardOk = $true break } } catch { $retryCount++ Start-Sleep -Seconds 2 } } if (-not $dashboardOk) { Write-Host "[X] Dashboard not responding" -ForegroundColor Red Stop-Process -Id $process.Id -Force exit 1 } $status = $response.Content | ConvertFrom-Json Write-Host "[OK] Dashboard responding`n" -ForegroundColor Green # Step 5: Verify status data Write-Host "[5/7] Verifying status data..." -ForegroundColor Yellow $authStatus = if ($status.summary.authConfigured) { "[OK]" } else { "[NO]" } $subStatus = if ($status.summary.subscribed) { "[OK]" } else { "[NO]" } $onlineStatus = if ($status.summary.online) { "[OK]" } else { "[NO]" } Write-Host " Token configured: $authStatus" Write-Host " Subscription: $subStatus" Write-Host " Account online: $onlineStatus" if (-not $status.summary.authConfigured) { Write-Host "`n NOTE: Token not detected, need manual input" -ForegroundColor Cyan } if (-not $status.summary.subscribed) { Write-Host " NOTE: Need subscription at http://127.0.0.1:4310" -ForegroundColor Cyan } if (-not $status.summary.online) { Write-Host " NOTE: Need WeChat Work QR code login" -ForegroundColor Cyan } Write-Host "" # Step 6: Check Runtime Write-Host "[6/7] Checking Runtime..." -ForegroundColor Yellow $runtimeStatePath = Join-Path $TrainingDir "outputs\runtime\qiwei-runtime.json" if (Test-Path $runtimeStatePath) { $runtimeState = Get-Content $runtimeStatePath -Raw | ConvertFrom-Json Write-Host "[OK] Runtime running" -ForegroundColor Green Write-Host " PID: $($runtimeState.pid)" -ForegroundColor Gray Write-Host " Mode: $($runtimeState.mode)" -ForegroundColor Gray Write-Host " Status: $($runtimeState.status)" -ForegroundColor Gray } else { Write-Host "[WARN] Runtime state file not found" -ForegroundColor Yellow } Write-Host "" # Step 7: Check knowledge base Write-Host "[7/7] Checking knowledge base..." -ForegroundColor Yellow try { $configResponse = Invoke-WebRequest -Uri "http://127.0.0.1:4320/api/agent/config" -UseBasicParsing -TimeoutSec 3 $config = $configResponse.Content | ConvertFrom-Json $knowledgeCount = if ($config.knowledge.chunks) { $config.knowledge.chunks.Count } else { 0 } Write-Host "[OK] Knowledge base loaded ($knowledgeCount chunks)" -ForegroundColor Green Write-Host " Conversation mode: $($config.conversationMode)" -ForegroundColor Gray Write-Host " Provider: $($config.provider)" -ForegroundColor Gray } catch { Write-Host "[WARN] Knowledge API not responding" -ForegroundColor Yellow } Write-Host "" # Summary Write-Host "=== Verification Complete ===" -ForegroundColor Cyan Write-Host "`nWorkbench URL: http://127.0.0.1:4320/#status" -ForegroundColor Cyan Write-Host "Press Ctrl+C to stop...`n" # Wait for interruption try { while ($true) { Start-Sleep -Seconds 1 if ($process.HasExited) { Write-Host "Workbench process exited" -ForegroundColor Yellow break } } } finally { Write-Host "`nStopping workbench..." -ForegroundColor Yellow if (-not $process.HasExited) { Stop-Process -Id $process.Id -Force } Write-Host "[OK] Stopped`n" -ForegroundColor Green }