Files
zclaw_openfang/start.ps1
iven 0d4fa96b82
Some checks failed
CI / Lint & TypeCheck (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Build Frontend (push) Has been cancelled
CI / Rust Check (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
refactor: 统一项目名称从OpenFang到ZCLAW
重构所有代码和文档中的项目名称,将OpenFang统一更新为ZCLAW。包括:
- 配置文件中的项目名称
- 代码注释和文档引用
- 环境变量和路径
- 类型定义和接口名称
- 测试用例和模拟数据

同时优化部分代码结构,移除未使用的模块,并更新相关依赖项。
2026-03-27 07:36:03 +08:00

184 lines
5.8 KiB
PowerShell

# ZCLAW Unified Start Script for Windows
# Usage: .\start.ps1 [-NoBrowser] [-NoGateway] [-Dev]
param(
[switch]$NoBrowser, # Skip ChromeDriver
[switch]$NoGateway, # Skip ZCLAW gateway
[switch]$Dev, # Start in development mode (with hot reload)
[switch]$Help
)
$ErrorActionPreference = "Continue"
# Colors for output
function Write-Info { param($msg) Write-Host "[INFO] $msg" -ForegroundColor Cyan }
function Write-Success { param($msg) Write-Host "[OK] $msg" -ForegroundColor Green }
function Write-Warn { param($msg) Write-Host "[WARN] $msg" -ForegroundColor Yellow }
function Write-Err { param($msg) Write-Host "[ERROR] $msg" -ForegroundColor Red }
if ($Help) {
Write-Host @"
ZCLAW Unified Start Script
Usage: .\start.ps1 [options]
Options:
-NoBrowser Skip starting ChromeDriver
-NoGateway Skip starting ZCLAW gateway
-Dev Start in development mode with hot reload
-Help Show this help message
Examples:
.\start.ps1 # Start all services
.\start.ps1 -NoBrowser # Start without ChromeDriver
.\start.ps1 -Dev # Start in dev mode
"@
exit 0
}
Write-Host ""
Write-Host "═══════════════════════════════════════════" -ForegroundColor Magenta
Write-Host " 🦞 ZCLAW - AI Agent Desktop Client" -ForegroundColor Magenta
Write-Host "═══════════════════════════════════════════" -ForegroundColor Magenta
Write-Host ""
# Track started processes for cleanup
$startedProcesses = @()
# Cleanup function
function Cleanup {
Write-Info "Cleaning up..."
foreach ($proc in $startedProcesses) {
if ($proc -and !$proc.HasExited) {
Write-Info "Stopping process $($proc.ProcessName) (PID: $($proc.Id))"
try {
$proc.Kill()
} catch {
# Ignore errors
}
}
}
}
# Register cleanup
trap { Cleanup; break }
Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action { Cleanup }
# 1. Check ChromeDriver
if (-not $NoBrowser) {
Write-Info "Checking ChromeDriver..."
$chromedriver = Get-Command chromedriver -ErrorAction SilentlyContinue
if ($chromedriver) {
Write-Success "ChromeDriver found: $($chromedriver.Source)"
# Start ChromeDriver
Write-Info "Starting ChromeDriver on port 4444..."
$chromedriverProc = Start-Process -FilePath "chromedriver" -ArgumentList "--port=4444" -PassThru -WindowStyle Hidden
$startedProcesses += $chromedriverProc
Start-Sleep -Milliseconds 500
if ($chromedriverProc.HasExited) {
Write-Warn "ChromeDriver exited immediately. It may already be running."
} else {
Write-Success "ChromeDriver started (PID: $($chromedriverProc.Id))"
}
} else {
Write-Warn "ChromeDriver not found. Browser automation will not work."
Write-Info "Install ChromeDriver: https://chromedriver.chromium.org/downloads"
}
} else {
Write-Info "Skipping ChromeDriver (-NoBrowser)"
}
Write-Host ""
# 2. Check/ZCLAW Gateway
if (-not $NoGateway) {
Write-Info "Checking ZCLAW Gateway..."
# Check if already running
$gatewayRunning = $false
try {
$response = Invoke-WebRequest -Uri "http://127.0.0.1:4200/health" -TimeoutSec 2 -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
$gatewayRunning = $true
Write-Success "ZCLAW Gateway already running on port 4200"
}
} catch {
# Not running
}
if (-not $gatewayRunning) {
# Try to start ZCLAW
$zclaw = Get-Command zclaw -ErrorAction SilentlyContinue
if ($zclaw) {
Write-Info "Starting ZCLAW Gateway..."
$gatewayProc = Start-Process -FilePath "zclaw" -ArgumentList "gateway", "start" -PassThru
$startedProcesses += $gatewayProc
# Wait for gateway to start
Write-Info "Waiting for gateway to be ready..."
$maxWait = 30
$waited = 0
while ($waited -lt $maxWait) {
try {
$response = Invoke-WebRequest -Uri "http://127.0.0.1:4200/health" -TimeoutSec 1 -ErrorAction SilentlyContinue
if ($response.StatusCode -eq 200) {
Write-Success "ZCLAW Gateway started on port 4200"
break
}
} catch {}
Start-Sleep -Seconds 1
$waited++
Write-Host -NoNewline "."
}
Write-Host ""
if ($waited -ge $maxWait) {
Write-Warn "Gateway did not respond within ${maxWait}s. Check logs."
}
} else {
Write-Warn "ZCLAW CLI not found. Gateway not started."
Write-Info "Install ZCLAW: https://github.com/RightNow-AI/zclaw"
}
}
} else {
Write-Info "Skipping ZCLAW Gateway (-NoGateway)"
}
Write-Host ""
# 3. Start Tauri Desktop App
Write-Info "Starting ZCLAW Desktop..."
Set-Location desktop
if ($Dev) {
Write-Info "Starting in development mode..."
pnpm tauri dev
} else {
# Check if built version exists
$exePath = "src-tauri\target\release\ZClaw.exe"
if (Test-Path $exePath) {
Write-Info "Starting built application..."
Start-Process $exePath
Write-Success "ZCLAW Desktop started"
} else {
Write-Info "Built application not found, starting in dev mode..."
pnpm tauri dev
}
}
# Keep script running if in dev mode
if ($Dev) {
Write-Host ""
Write-Info "Press Ctrl+C to stop all services..."
try {
while ($true) {
Start-Sleep -Seconds 1
}
} finally {
Cleanup
}
}