Files
zclaw_openfang/start.ps1
iven d890fa1858 feat(scripts): add unified startup scripts for full stack development
Add comprehensive startup scripts for managing all ZCLAW services:

Windows (PowerShell):
- start.ps1 / start-all.ps1 - Unified service launcher
- Supports -NoBrowser, -NoGateway, -Dev, -Stop flags

Unix (Bash):
- start.sh - Cross-platform launcher for macOS/Linux

Makefile:
- make start / make start-unix
- make desktop / make desktop-build
- make setup / make test / make clean

pnpm commands:
- pnpm start - Start all services
- pnpm start:dev - Development mode with hot reload
- pnpm start:no-browser - Skip ChromeDriver
- pnpm start:no-gateway - Skip OpenFang gateway
- pnpm desktop - Start Tauri only
- pnpm chromedriver - Start ChromeDriver only

Services managed:
1. ChromeDriver (port 4444) - Browser automation
2. OpenFang Gateway (port 4200) - AI Agent runtime
3. Tauri Desktop - React + Rust frontend

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-17 09:23:44 +08:00

184 lines
5.9 KiB
PowerShell

# ZCLAW Unified Start Script for Windows
# Usage: .\start.ps1 [-NoBrowser] [-NoGateway] [-Dev]
param(
[switch]$NoBrowser, # Skip ChromeDriver
[switch]$NoGateway, # Skip OpenFang 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 OpenFang 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 - OpenFang 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/OpenFang Gateway
if (-not $NoGateway) {
Write-Info "Checking OpenFang 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 "OpenFang Gateway already running on port 4200"
}
} catch {
# Not running
}
if (-not $gatewayRunning) {
# Try to start OpenFang
$openfang = Get-Command openfang -ErrorAction SilentlyContinue
if ($openfang) {
Write-Info "Starting OpenFang Gateway..."
$gatewayProc = Start-Process -FilePath "openfang" -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 "OpenFang 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 "OpenFang CLI not found. Gateway not started."
Write-Info "Install OpenFang: https://github.com/openfang/openfang"
}
}
} else {
Write-Info "Skipping OpenFang 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
}
}