# Copyright 2026 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. [CmdletBinding()] param( [int]$Port = 8000, [switch]$NoOpen = $false, [switch]$SetupOnly = $false, [switch]$SkipUpdate = $false, [switch]$SkipMcpSync = $false, [ValidateSet('Official', 'China')][string]$Mirror ) $ErrorActionPreference = "Continue" [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 function Get-LaunchText { param([string]$English, [string]$Chinese) if ($env:ARTEMIS_LAUNCH_LANG -eq 'zh-CN') { return $Chinese } return $English } # Ensure modern TLS protocols are enabled for downloads (GitHub releases, nodejs.org, Google repositories) try { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor [System.Net.SecurityProtocolType]::Tls12 } catch {} $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition $RootDir = Split-Path -Parent $ScriptDir Set-Location $RootDir # Existing installations check source BEFORE importing bootstrap helpers. $existingPython = Join-Path $RootDir '.venv\Scripts\python.exe' if ((-not $SkipUpdate) -and (Test-Path -LiteralPath $existingPython)) { & $existingPython (Join-Path $ScriptDir 'update_installation.py') source --port $Port $updateExit = $LASTEXITCODE if ($updateExit -eq 20) { exit 1 } if ($updateExit -eq 10) { # Reparse the freshly updated launcher; do not continue running stale functions. $reloadArgs = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', (Join-Path $ScriptDir 'start.ps1'), '-Port', $Port, '-SkipUpdate') if ($NoOpen) { $reloadArgs += '-NoOpen' } if ($SetupOnly) { $reloadArgs += '-SetupOnly' } if ($SkipMcpSync) { $reloadArgs += '-SkipMcpSync' } if ($Mirror) { $reloadArgs += @('-Mirror', $Mirror) } & powershell.exe @reloadArgs exit $LASTEXITCODE } if ($updateExit -ne 0) { Write-Host (Get-LaunchText ' [ERROR] Source update check failed. Resolve the error above, or use -SkipUpdate for local startup.' ' [错误] 源码更新检查失败。请处理上方错误;要运行当前源码可传入 -SkipUpdate。') -ForegroundColor Red exit 1 } } . (Join-Path $ScriptDir 'download_config.ps1') try { Initialize-ArtemisDownloads -ProjectRoot $RootDir -Mode $Mirror } catch { Write-Host (Get-LaunchText " [ERROR] Invalid download settings: $_" " [错误] 下载配置无效:$_") -ForegroundColor Red exit 1 } Write-Host "======================================================" -ForegroundColor Cyan Write-Host (Get-LaunchText " Artemis Autonomous Mobile Agent UI " " ARTEMIS 手机自动化测试平台") -ForegroundColor Cyan Write-Host "======================================================" -ForegroundColor Cyan Write-Host "" function Update-EnvironmentPath { $standardDirs = @( "$env:LOCALAPPDATA\Microsoft\WinGet\Links", "$env:LOCALAPPDATA\Programs\node", "$env:USERPROFILE\.local\share\node", "$env:LOCALAPPDATA\Programs\scrcpy", "$env:USERPROFILE\.local\share\scrcpy", "$env:LOCALAPPDATA\Programs\platform-tools", "$env:USERPROFILE\.local\share\platform-tools", "$env:LOCALAPPDATA\Programs\uv", "$env:LOCALAPPDATA\uv", "$env:APPDATA\uv", "$env:USERPROFILE\.cargo\bin", "$env:USERPROFILE\.local\bin", "$env:USERPROFILE\scoop\shims", "C:\ProgramData\chocolatey\bin", "$env:LOCALAPPDATA\Android\Sdk\platform-tools", "$env:LOCALAPPDATA\Android\android-sdk\platform-tools", "$env:ProgramFiles\Android\platform-tools", "${env:ProgramFiles(x86)}\Android\android-sdk\platform-tools", "$env:ProgramFiles\nodejs", "${env:ProgramFiles(x86)}\nodejs", "$env:APPDATA\npm" ) if ($env:CARGO_HOME) { $standardDirs = @("$env:CARGO_HOME\bin") + $standardDirs } if ($env:ANDROID_HOME) { $standardDirs += "$env:ANDROID_HOME\platform-tools" } if ($env:ANDROID_SDK_ROOT) { $standardDirs += "$env:ANDROID_SDK_ROOT\platform-tools" } if ($env:NVM_SYMLINK) { $standardDirs = @($env:NVM_SYMLINK) + $standardDirs } if ($env:NVM_HOME) { $standardDirs = @($env:NVM_HOME) + $standardDirs } $regPath = [Environment]::GetEnvironmentVariable("Path", "User") + ";" + [Environment]::GetEnvironmentVariable("Path", "Machine") $currentPaths = ($env:PATH -split ";") + ($regPath -split ";") + $standardDirs | Where-Object { [string]::IsNullOrWhiteSpace($_) -eq $false -and (Test-Path $_) } | Select-Object -Unique $env:PATH = $currentPaths -join ";" # Ensure user-space portable tools take absolute priority over system-level outdated versions $portableNode = "$env:LOCALAPPDATA\Programs\node" if (Test-Path "$portableNode\node.exe") { $env:PATH = "$portableNode;$env:PATH" } $portableScrcpy = "$env:LOCALAPPDATA\Programs\scrcpy" if (Test-Path "$portableScrcpy\scrcpy.exe") { $env:PATH = "$portableScrcpy;$env:PATH" } $portablePt = "$env:LOCALAPPDATA\Programs\platform-tools" if (Test-Path "$portablePt\adb.exe") { $env:PATH = "$portablePt;$env:PATH" } } function Start-LocalAdbServer { if (Test-CommandExists "adb") { try { $origSocket = $env:ADB_SERVER_SOCKET Remove-Item Env:\ADB_SERVER_SOCKET -ErrorAction SilentlyContinue & adb start-server 2>$null | Out-Null if ($origSocket) { $env:ADB_SERVER_SOCKET = $origSocket } } catch {} } } function Test-CommandExists { param([string]$Command) $res = Get-Command $Command -ErrorAction SilentlyContinue return ($null -ne $res) } function Invoke-DownloadFile { param( [Parameter(Mandatory=$true)][string]$Uri, [Parameter(Mandatory=$true)][string]$OutFile, [int]$TimeoutSec = $ArtemisDownloads.timeout_seconds ) if (Test-Path $OutFile) { Remove-Item -Path $OutFile -Force -ErrorAction SilentlyContinue } # 1. Try Windows built-in curl.exe first (available in Win 10 1803+ and Win 11) if (Test-CommandExists "curl.exe") { try { & curl.exe -f -sSL --connect-timeout 5 --max-time $TimeoutSec "$Uri" -o "$OutFile" 2>$null if ($LASTEXITCODE -eq 0 -and (Test-Path $OutFile) -and ((Get-Item $OutFile).Length -gt 0)) { return $true } } catch {} if (Test-Path $OutFile) { Remove-Item -Path $OutFile -Force -ErrorAction SilentlyContinue } } # 2. Fallback to Invoke-WebRequest (suppressing progress bar to eliminate PowerShell buffer hangs) try { $prevProgress = $ProgressPreference $ProgressPreference = 'SilentlyContinue' Invoke-WebRequest -Uri $Uri -OutFile $OutFile -TimeoutSec $TimeoutSec -UseBasicParsing -ErrorAction Stop $ProgressPreference = $prevProgress if ((Test-Path $OutFile) -and ((Get-Item $OutFile).Length -gt 0)) { return $true } } catch { $ProgressPreference = $prevProgress } if (Test-Path $OutFile) { Remove-Item -Path $OutFile -Force -ErrorAction SilentlyContinue } return $false } function Install-PortablePlatformTools { $ptDir = "$env:LOCALAPPDATA\Programs\platform-tools" if (Test-Path "$ptDir\adb.exe") { $env:PATH = "$ptDir;$env:PATH" return $true } Write-Host (Get-LaunchText " [INFO] Installing Android platform-tools (adb) in user space..." " [安装] 正在安装 Android 调试工具 adb(当前用户)...") -ForegroundColor Cyan try { $zipPath = "$env:TEMP\platform-tools-windows.zip" if (Invoke-DownloadFile -Uri $ArtemisDownloads.adb_url -OutFile $zipPath) { New-Item -ItemType Directory -Path "$env:LOCALAPPDATA\Programs" -Force | Out-Null Expand-Archive -Path $zipPath -DestinationPath "$env:LOCALAPPDATA\Programs" -Force Remove-Item $zipPath -Force -ErrorAction SilentlyContinue if (Test-Path "$ptDir\adb.exe") { $env:PATH = "$ptDir;$env:PATH" Write-Host (Get-LaunchText " [OK] adb installed in user space." " [完成] adb 已安装。") -ForegroundColor Green return $true } } } catch { Write-Host (Get-LaunchText " [WARN] Failed to install portable platform-tools: $_" " [提示] adb 安装失败:$_") -ForegroundColor DarkYellow } return $false } function Install-PortableScrcpy { $scrcpyDir = "$env:LOCALAPPDATA\Programs\scrcpy" if (Test-Path "$scrcpyDir\scrcpy.exe") { $env:PATH = "$scrcpyDir;$env:PATH" return $true } # Check if nested from an earlier run and heal $nested = Get-ChildItem -Path $scrcpyDir -Directory -Filter "scrcpy*" -ErrorAction SilentlyContinue | Select-Object -First 1 if ($nested -and (Test-Path "$($nested.FullName)\scrcpy.exe")) { Copy-Item -Path "$($nested.FullName)\*" -Destination $scrcpyDir -Recurse -Force Remove-Item -Path $nested.FullName -Recurse -Force -ErrorAction SilentlyContinue if (Test-Path "$scrcpyDir\scrcpy.exe") { $env:PATH = "$scrcpyDir;$env:PATH" return $true } } Write-Host (Get-LaunchText " [INFO] Installing portable scrcpy in user space..." " [安装] 正在安装 scrcpy(当前用户)...") -ForegroundColor Cyan if ($ArtemisDownloads.mode -eq 'China' -and $ArtemisDownloads.scrcpy_url.StartsWith('https://github.com/')) { Write-Host (Get-LaunchText ' [WARN] China mode has no non-GitHub scrcpy source. Configure overrides.scrcpy_url or install scrcpy manually.' ' [提示] 国内镜像中没有可用的 scrcpy 下载地址;请设置 config/downloads.json 的 overrides.scrcpy_url,或自行安装。') -ForegroundColor Yellow return $false } try { $zipPath = "$env:TEMP\scrcpy-win64.zip" if (Invoke-DownloadFile -Uri $ArtemisDownloads.scrcpy_url -OutFile $zipPath) { $actualHash = (Get-FileHash -LiteralPath $zipPath -Algorithm SHA256).Hash.ToLowerInvariant() if ($actualHash -ne $ArtemisDownloads.scrcpy_sha256) { throw 'Downloaded scrcpy ZIP failed official SHA256 verification.' } $extractDir = "$env:TEMP\scrcpy_extract" if (Test-Path $extractDir) { Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue } New-Item -ItemType Directory -Path $extractDir -Force | Out-Null Expand-Archive -Path $zipPath -DestinationPath $extractDir -Force $extractedFolder = Get-ChildItem -Path $extractDir -Directory | Select-Object -First 1 if ($extractedFolder) { if (-not (Test-Path $scrcpyDir)) { New-Item -ItemType Directory -Path $scrcpyDir -Force | Out-Null } Copy-Item -Path "$($extractedFolder.FullName)\*" -Destination $scrcpyDir -Recurse -Force } Remove-Item $zipPath -Force -ErrorAction SilentlyContinue Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue if (Test-Path "$scrcpyDir\scrcpy.exe") { $env:PATH = "$scrcpyDir;$env:PATH" Write-Host (Get-LaunchText " [OK] Portable scrcpy installed in user space." " [完成] scrcpy 已安装。") -ForegroundColor Green return $true } } } catch { Write-Host (Get-LaunchText " [WARN] Failed to install portable scrcpy: $_" " [提示] scrcpy 安装失败:$_") -ForegroundColor DarkYellow } return $false } function Test-NodeCompatible { if (-not (Test-CommandExists "node") -or (-not (Test-CommandExists "npm") -and -not (Test-CommandExists "npm.cmd"))) { return $false } try { $verRaw = (& node -v 2>$null) if (-not $verRaw) { return $false } $verStr = $verRaw.ToString().Trim().TrimStart('v') $parts = $verStr.Split('.') if ($parts.Count -ge 2) { $major = [int]$parts[0] $minor = [int]$parts[1] if ($major -ge 26) { return $true } if ($major -eq 24 -and $minor -ge 15) { return $true } if ($major -eq 22 -and $minor -ge 22) { return $true } } } catch { return $false } return $false } function Install-PortableNode { $nodeDir = "$env:LOCALAPPDATA\Programs\node" if (Test-Path "$nodeDir\node.exe") { $env:PATH = "$nodeDir;$env:PATH" if (Test-NodeCompatible) { return $true } } # Check if nested from an earlier run and heal $nested = Get-ChildItem -Path $nodeDir -Directory -Filter "node-*" -ErrorAction SilentlyContinue | Select-Object -First 1 if ($nested -and (Test-Path "$($nested.FullName)\node.exe")) { Copy-Item -Path "$($nested.FullName)\*" -Destination $nodeDir -Recurse -Force Remove-Item -Path $nested.FullName -Recurse -Force -ErrorAction SilentlyContinue if (Test-Path "$nodeDir\node.exe") { $env:PATH = "$nodeDir;$env:PATH" if (Test-NodeCompatible) { return $true } } } Write-Host (Get-LaunchText " [INFO] Installing portable Node.js LTS (v22.23.2) in user space..." " [安装] 正在安装 Node.js LTS v22.23.2(当前用户)...") -ForegroundColor Cyan try { $nodeVer = "v22.23.2" $arch = if ([System.Environment]::Is64BitOperatingSystem) { if ($env:PROCESSOR_ARCHITECTURE -match "ARM64") { "arm64" } else { "x64" } } else { "x64" } $zipPath = "$env:TEMP\node-$nodeVer-win-$arch.zip" $nodeBase = $ArtemisDownloads.node_mirror.TrimEnd('/') if (Invoke-DownloadFile -Uri "$nodeBase/$nodeVer/node-$nodeVer-win-$arch.zip" -OutFile $zipPath) { $extractDir = "$env:TEMP\node_extract" if (Test-Path $extractDir) { Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue } New-Item -ItemType Directory -Path $extractDir -Force | Out-Null Expand-Archive -Path $zipPath -DestinationPath $extractDir -Force $extractedFolder = Get-ChildItem -Path $extractDir -Directory | Select-Object -First 1 if ($extractedFolder) { if (-not (Test-Path $nodeDir)) { New-Item -ItemType Directory -Path $nodeDir -Force | Out-Null } Copy-Item -Path "$($extractedFolder.FullName)\*" -Destination $nodeDir -Recurse -Force } Remove-Item $zipPath -Force -ErrorAction SilentlyContinue Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue if (Test-Path "$nodeDir\node.exe") { $env:PATH = "$nodeDir;$env:PATH" Write-Host (Get-LaunchText " [OK] Portable Node.js $nodeVer installed in user space." " [完成] Node.js $nodeVer 已安装。") -ForegroundColor Green return $true } } } catch { Write-Host (Get-LaunchText " [WARN] Failed to install portable Node.js: $_" " [提示] Node.js 安装失败:$_") -ForegroundColor DarkYellow } return $false } # 1. Refresh PATH with standard toolchain paths Update-EnvironmentPath # 2. Prepare the project Python environment before optional device/UI setup. . (Join-Path $ScriptDir 'bootstrap_python.ps1') try { $ArtemisPython = Initialize-ArtemisPython -ProjectRoot $RootDir } catch { Write-Host " [ERROR] $_" -ForegroundColor Red exit 1 } if (-not (Test-Path -LiteralPath (Join-Path $RootDir '.env'))) { if (Test-Path -LiteralPath (Join-Path $RootDir '.env.example')) { Copy-Item -LiteralPath (Join-Path $RootDir '.env.example') -Destination (Join-Path $RootDir '.env') -ErrorAction Stop Write-Host (Get-LaunchText ' [OK] Created .env from .env.example. Configure your model in the web UI.' ' [完成] 已按模板创建 .env;请在网页中配置模型。') -ForegroundColor Green } } if (-not $SkipMcpSync) { Write-Host (Get-LaunchText ' [CHECK] Installing/updating MCP for detected AI clients...' ' [检查] 正在为检测到的 AI 客户端安装或更新 MCP...') -ForegroundColor Cyan & $ArtemisPython (Join-Path $ScriptDir 'update_installation.py') mcp if ($LASTEXITCODE -ne 0) { Write-Host (Get-LaunchText ' [ERROR] MCP synchronization failed. Fix the configuration above, or use -SkipMcpSync to run the web UI without MCP.' ' [错误] MCP 同步失败。请修复上方配置;仅需启动网页时可使用 -SkipMcpSync。') -ForegroundColor Red exit 1 } } else { Write-Host (Get-LaunchText ' [SKIP] MCP synchronization was skipped.' ' [跳过] 已跳过 MCP 同步。') -ForegroundColor Yellow } if ($SetupOnly) { Write-Host (Get-LaunchText ' [OK] Setup complete. Run start.bat to launch Artemis.' ' [完成] 环境已准备好。运行 start-cn.bat 启动 ARTEMIS。') -ForegroundColor Green exit 0 } # 3. Check and try installing missing system toolchains (ADB, FFmpeg, scrcpy) $missingCore = @() if (-not (Test-CommandExists "adb")) { $missingCore += "adb" } # imageio-ffmpeg ships a working executable in its wheel, including mirror installs. if (-not (Test-CommandExists "ffmpeg")) { & $ArtemisPython -c 'import imageio_ffmpeg; imageio_ffmpeg.get_ffmpeg_exe()' 2>$null | Out-Null if ($LASTEXITCODE -ne 0) { $missingCore += "ffmpeg" } } if (-not (Test-CommandExists "scrcpy")) { $missingCore += "scrcpy" } if ($missingCore.Count -gt 0) { $useWinGet = $false if ($ArtemisDownloads.mode -ne 'China' -and (Test-CommandExists "winget")) { if ([Console]::IsInputRedirected -eq $false) { Write-Host (Get-LaunchText " [INFO] Missing components detected: $($missingCore -join ', ')." " [检查] 缺少组件:$($missingCore -join ', ')。") -ForegroundColor Cyan $ans = Read-Host (Get-LaunchText " Install system packages via WinGet? [Y/n]" " 通过 WinGet 安装?[Y/n]") if ($ans -eq "" -or $ans -match "^[Yy]") { $useWinGet = $true } } else { $useWinGet = $true } } if ($useWinGet) { Write-Host (Get-LaunchText " [INFO] Auto-installing missing components ($($missingCore -join ', '))..." " [安装] 正在安装缺少的组件:$($missingCore -join ', ')...") -ForegroundColor DarkYellow if ($missingCore -contains "adb") { winget install --id Google.PlatformTools -e --accept-source-agreements --accept-package-agreements --silent 2>$null | Out-Null } if ($missingCore -contains "ffmpeg") { winget install --id Gyan.FFmpeg -e --accept-source-agreements --accept-package-agreements --silent 2>$null | Out-Null } if ($missingCore -contains "scrcpy") { winget install --id Genymobile.scrcpy -e --accept-source-agreements --accept-package-agreements --silent 2>$null | Out-Null } Update-EnvironmentPath } # Zero-admin user-space fallback for adb and scrcpy if still missing if (-not (Test-CommandExists "adb")) { Install-PortablePlatformTools } if (-not (Test-CommandExists "scrcpy")) { if (-not (Install-PortableScrcpy)) { Write-Host (Get-LaunchText ' [WARN] scrcpy download failed. Set overrides.scrcpy_url in config/downloads.json to a reachable release ZIP, then retry.' ' [提示] scrcpy 下载失败。请在 config/downloads.json 中设置可访问的 overrides.scrcpy_url,然后重试。') -ForegroundColor Yellow } } } # Ensure local ADB daemon is warm & listening so probes do not hit 'Connection refused' Start-LocalAdbServer # 6. Check and build Showcase UI if not already compiled $ShowcaseIndex = "$RootDir\apps\showcase_ui\dist\frontend\browser\index.html" $ShowcaseIndexAlt1 = "$RootDir\apps\showcase_ui\dist\browser\index.html" $ShowcaseIndexAlt2 = "$RootDir\apps\showcase_ui\dist\index.html" & $ArtemisPython (Join-Path $ScriptDir 'update_installation.py') frontend-check $frontendChanged = $LASTEXITCODE -eq 10 if ($LASTEXITCODE -notin @(0, 10)) { Write-Host (Get-LaunchText ' [ERROR] Could not check frontend sources.' ' [错误] 无法检查前端源码。') -ForegroundColor Red; exit 1 } if ($frontendChanged -or ((-not (Test-Path $ShowcaseIndex)) -and (-not (Test-Path $ShowcaseIndexAlt1)) -and (-not (Test-Path $ShowcaseIndexAlt2)))) { if (-not (Test-NodeCompatible)) { if (Test-CommandExists "node") { $curVer = (& node -v 2>$null) Write-Host (Get-LaunchText " [INFO] Detected Node.js $curVer, but Angular CLI requires Node.js >= v22.22.0." " [检查] 检测到 Node.js $curVer;前端需要 v22.22.0 或更新版本。") -ForegroundColor Yellow } else { Write-Host (Get-LaunchText " [INFO] Node.js/npm not found (required for Showcase UI)." " [检查] 未找到 Node.js/npm,网页构建需要安装。") -ForegroundColor Cyan } # 1. Try nvm if available on Windows if ($ArtemisDownloads.mode -ne 'China' -and (Test-CommandExists "nvm")) { Write-Host (Get-LaunchText " [INFO] Installing Node.js 22 LTS via nvm..." " [安装] 正在通过 nvm 安装 Node.js 22 LTS...") -ForegroundColor Cyan & nvm install 22.23.2 | Out-Null & nvm use 22.23.2 | Out-Null Update-EnvironmentPath } # 2. Try WinGet if (-not (Test-NodeCompatible)) { $useWinGetNode = $false if ($ArtemisDownloads.mode -ne 'China' -and (Test-CommandExists "winget")) { if ([Console]::IsInputRedirected -eq $false) { Write-Host (Get-LaunchText " [INFO] Node.js >= v22.22.0 required for Showcase UI." " [检查] 网页需要 Node.js v22.22.0 或更新版本。") -ForegroundColor Cyan $ans = Read-Host (Get-LaunchText " Install/Upgrade Node.js via WinGet (may require Administrator)? [Y/n]" " 通过 WinGet 安装/升级 Node.js(可能需要管理员权限)?[Y/n]") if ($ans -eq "" -or $ans -match "^[Yy]") { $useWinGetNode = $true } } else { $useWinGetNode = $true } } if ($useWinGetNode) { Write-Host (Get-LaunchText " [INFO] Installing/Upgrading Node.js LTS via WinGet..." " [安装] 正在通过 WinGet 安装/升级 Node.js LTS...") -ForegroundColor Yellow winget install --id OpenJS.NodeJS.LTS -e --accept-source-agreements --accept-package-agreements --silent 2>$null | Out-Null Update-EnvironmentPath } } # 3. Zero-admin user-space fallback for Node.js if still not compatible if (-not (Test-NodeCompatible)) { Install-PortableNode } } if (Test-NodeCompatible) { $nodeVer = (& node -v 2>$null) Write-Host (Get-LaunchText " [OK] Node.js $nodeVer is ready." " [完成] Node.js $nodeVer 已就绪。") -ForegroundColor Green Write-Host (Get-LaunchText " [INFO] Showcase UI sources/dependencies changed or build missing. Compiling..." " [构建] 前端源码/依赖有变化或缺少构建结果,准备重新构建...") -ForegroundColor Yellow Push-Location "$RootDir\apps\showcase_ui" try { $npmExec = if (Test-CommandExists "npm.cmd") { "npm.cmd" } else { "npm" } Write-Host (Get-LaunchText " [INFO] Installing frontend npm dependencies..." " [安装] 正在安装前端 npm 依赖...") -ForegroundColor Cyan & $npmExec ci --no-audit --no-fund --loglevel=error if ($LASTEXITCODE -ne 0) { throw "npm ci failed (exit $LASTEXITCODE). Check the network and retry." } Write-Host (Get-LaunchText " [INFO] Building Angular frontend application..." " [构建] 正在构建 Angular 网页...") -ForegroundColor Cyan & $npmExec run build if ($LASTEXITCODE -ne 0) { throw "Frontend build failed (exit $LASTEXITCODE)." } if (Test-Path $ShowcaseIndex) { Write-Host (Get-LaunchText " [OK] Showcase UI compiled successfully." " [完成] 网页构建成功。") -ForegroundColor Green } elseif ((Test-Path $ShowcaseIndexAlt1) -or (Test-Path $ShowcaseIndexAlt2)) { Write-Host (Get-LaunchText " [OK] Showcase UI compiled successfully." " [完成] 网页构建成功。") -ForegroundColor Green } else { throw 'Frontend build did not produce index.html.' } & $ArtemisPython (Join-Path $ScriptDir 'update_installation.py') frontend-mark if ($LASTEXITCODE -ne 0) { throw 'Could not save frontend build fingerprint.' } } catch { Write-Host (Get-LaunchText " [ERROR] Failed to build Showcase UI: $_" " [错误] 网页构建失败:$_") -ForegroundColor Red exit 1 } finally { Pop-Location } } else { Write-Host (Get-LaunchText " [ERROR] A compatible Node.js/npm could not be installed. Install Node.js LTS and retry." " [错误] 无法安装兼容的 Node.js/npm。请安装 Node.js LTS 后重试。") -ForegroundColor Red exit 1 } } # MCP clients were refreshed after Python dependency sync above. # 8. Launch unified Showcase UI & open browser # Ensure local ADB daemon is warm & listening Start-LocalAdbServer # Launch via `python -m artemis` (not the `artemis.exe` console-script shim) so the # long-running server never locks .venv\Scripts\artemis.exe against `uv sync` reinstalls. Write-Host (Get-LaunchText " [INFO] Launching Artemis Showcase UI & Admin Console..." " [启动] 正在启动 ARTEMIS 网页与管理服务...") -ForegroundColor Green if ($NoOpen) { & $ArtemisPython -m artemis ui --port $Port --no-open } else { & $ArtemisPython -m artemis ui --port $Port --open } if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }