From 6c6d21400c4634dbc0db0eb9673c1b6d9e78cd28 Mon Sep 17 00:00:00 2001 From: iven Date: Tue, 17 Mar 2026 09:40:16 +0800 Subject: [PATCH] fix(scripts): use powershell instead of pwsh and add DesktopOnly mode - Replace pwsh with powershell for Windows compatibility - Add -DesktopOnly flag to skip all external services - Add automatic port 1420 cleanup before starting - Improve stop command to kill all related processes - Update package.json scripts for easier access Co-Authored-By: Claude Opus 4.6 --- package.json | 9 ++++---- start-all.ps1 | 64 ++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index e25c765..1b03fe5 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,10 @@ "gateway:start": "openfang gateway start", "gateway:status": "openfang gateway status", "gateway:doctor": "openfang doctor", - "start": "pwsh -File ./start-all.ps1", - "start:dev": "pwsh -File ./start-all.ps1 -Dev", - "start:no-browser": "pwsh -File ./start-all.ps1 -NoBrowser", - "start:no-gateway": "pwsh -File ./start-all.ps1 -NoGateway", - "start:stop": "pwsh -File ./start-all.ps1 -Stop", + "start": "powershell -ExecutionPolicy Bypass -File ./start-all.ps1", + "start:dev": "powershell -ExecutionPolicy Bypass -File ./start-all.ps1 -Dev", + "start:desktop": "powershell -ExecutionPolicy Bypass -File ./start-all.ps1 -DesktopOnly", + "start:stop": "powershell -ExecutionPolicy Bypass -File ./start-all.ps1 -Stop", "desktop": "cd desktop && pnpm tauri dev", "desktop:build": "cd desktop && pnpm tauri build", "chromedriver": "chromedriver --port=4444" diff --git a/start-all.ps1 b/start-all.ps1 index 65506e3..cecd2a5 100644 --- a/start-all.ps1 +++ b/start-all.ps1 @@ -1,12 +1,13 @@ # ZCLAW Full Stack Start Script -# Starts: ChromeDriver -> OpenFang Gateway -> Tauri Desktop +# Starts: ChromeDriver (optional) -> OpenFang Gateway (optional) -> Tauri Desktop param( [switch]$NoBrowser, [switch]$NoGateway, [switch]$Dev, [switch]$Help, - [switch]$Stop + [switch]$Stop, + [switch]$DesktopOnly ) $ErrorActionPreference = "Continue" @@ -27,17 +28,16 @@ ZCLAW Full Stack Start Script Usage: .\start-all.ps1 [options] Options: - -NoBrowser Skip ChromeDriver - -NoGateway Skip OpenFang Gateway - -Dev Development mode (hot reload) - -Stop Stop all services - -Help Show this help + -DesktopOnly Start desktop only (skip all external services) + -NoBrowser Skip ChromeDriver + -NoGateway Skip OpenFang Gateway + -Dev Development mode (hot reload) + -Stop Stop all services + -Help Show this help Quick Commands: pnpm start # Start all services - pnpm start:dev # Start in dev mode pnpm desktop # Start desktop only - pnpm chromedriver # Start ChromeDriver only "@ exit 0 @@ -59,16 +59,27 @@ if ($Stop) { # Stop Tauri/ZClaw Get-Process -Name "ZClaw" -ErrorAction SilentlyContinue | Stop-Process -Force + Get-Process -Name "desktop" -ErrorAction SilentlyContinue | Stop-Process -Force ok "ZCLAW Desktop stopped" + # Kill any process on port 1420 + $port1420 = netstat -ano | Select-String ":1420.*LISTENING" + if ($port1420) { + $pid1420 = ($port1420 -split '\s+')[-1] + if ($pid1420 -match '^\d+$') { + Stop-Process -Id $pid1420 -Force -ErrorAction SilentlyContinue + ok "Killed process on port 1420 (PID: $pid1420)" + } + } + ok "All services stopped" exit 0 } Write-Host "" -Write-Host "═══════════════════════════════════════════════════════════" -ForegroundColor Magenta -Write-Host " 🦞 ZCLAW - OpenFang Desktop Client" -ForegroundColor Magenta -Write-Host "═══════════════════════════════════════════════════════════" -ForegroundColor Magenta +Write-Host "===============================================" -ForegroundColor Magenta +Write-Host " ZCLAW - OpenFang Desktop Client" -ForegroundColor Magenta +Write-Host "===============================================" -ForegroundColor Magenta Write-Host "" # Track processes for cleanup @@ -87,7 +98,13 @@ function Cleanup { trap { Cleanup; break } Register-EngineEvent -SourceIdentifier PowerShell.Exiting -Action { Cleanup } | Out-Null -# 1. ChromeDriver +# Skip external services if DesktopOnly +if ($DesktopOnly) { + $NoBrowser = $true + $NoGateway = $true +} + +# 1. ChromeDriver (optional) if (-not $NoBrowser) { info "Checking ChromeDriver..." @@ -114,11 +131,13 @@ if (-not $NoBrowser) { info "Download: https://chromedriver.chromium.org/downloads" } } +} else { + info "Skipping ChromeDriver" } Write-Host "" -# 2. OpenFang Gateway +# 2. OpenFang Gateway (optional) if (-not $NoGateway) { info "Checking OpenFang Gateway..." @@ -156,10 +175,12 @@ if (-not $NoGateway) { warn "Gateway did not respond within 30s" } } else { - warn "OpenFang CLI not found" - info "Install: https://github.com/openfang/openfang" + warn "OpenFang CLI not found. Gateway not started." + info "The app will run in standalone mode." } } +} else { + info "Skipping OpenFang Gateway" } Write-Host "" @@ -168,6 +189,17 @@ Write-Host "" info "Starting ZCLAW Desktop..." Set-Location "$ScriptDir/desktop" +# Check if port 1420 is in use +$port1420 = netstat -ano | Select-String ":1420.*LISTENING" +if ($port1420) { + $pid1420 = ($port1420 -split '\s+')[-1] + if ($pid1420 -match '^\d+$') { + warn "Port 1420 is in use by PID $pid1420. Killing..." + Stop-Process -Id $pid1420 -Force -ErrorAction SilentlyContinue + Start-Sleep -Seconds 1 + } +} + if ($Dev) { info "Development mode enabled" pnpm tauri dev