# AI Terminal daemon installer (Windows PowerShell) # 用法: iwr ai-terminal.cn/i.ps1 | iex # 或: iwr ai-terminal.org/install.ps1 | iex # # Windows 原生支持: v1.3.2+ 通过 node-pty (ConPTY) 直接在 Windows 跑 PowerShell/cmd # 不再需要 WSL. 依赖: Node.js 18+, Windows 10 1809+ (Build 17763+, ConPTY 要求) $ErrorActionPreference = 'Stop' function Write-Info($msg) { Write-Host "→ $msg" -ForegroundColor Blue } function Write-Success($msg) { Write-Host "✓ $msg" -ForegroundColor Green } function Write-Warn($msg) { Write-Host "! $msg" -ForegroundColor Yellow } function Write-Err($msg) { Write-Host "✗ $msg" -ForegroundColor Red } Write-Host "╔══════════════════════════════════════╗" -ForegroundColor Blue Write-Host "║ AI Terminal Installer ║" -ForegroundColor Blue Write-Host "╚══════════════════════════════════════╝" -ForegroundColor Blue Write-Host "" # 1. 检测 WSL 环境 (用户在 WSL 里跑了 PowerShell 命令的反向场景) if (Test-Path "/proc/version") { Write-Warn "检测到你在 WSL 里运行 Windows 安装脚本" Write-Host " 建议: 用 Linux 命令: " -NoNewline Write-Host "curl -fL ai-terminal.cn/i | sh" -ForegroundColor Blue $confirm = Read-Host "继续装 Windows 版? (y/N)" if ($confirm -ne 'y') { exit 0 } } # 2. 检测 Windows 版本 (Windows 10 1809+ Build 17763 需要 ConPTY) $winVer = [System.Environment]::OSVersion.Version if ($winVer.Major -lt 10) { Write-Err "需要 Windows 10 或更高版本 (当前: $($winVer.ToString()))" exit 1 } if ($winVer.Build -lt 17763) { Write-Err "Windows 版本过低 (Build $($winVer.Build)), 需要 Build 17763+ (Windows 10 1809)" Write-Host " node-pty 依赖的 ConPTY API 需要此最低版本" exit 1 } Write-Success "Windows $($winVer.Major).$($winVer.Build)" # 3. 检测 PowerShell 版本 if ($PSVersionTable.PSVersion.Major -lt 5) { Write-Err "需要 PowerShell 5.1 或更高 (当前: $($PSVersionTable.PSVersion))" exit 1 } Write-Success "PowerShell $($PSVersionTable.PSVersion)" # 4. 检测 Node.js try { $nodeVer = (node -v 2>$null).Trim().TrimStart('v') $nodeMajor = [int]($nodeVer -split '\.')[0] if ($nodeMajor -lt 18) { Write-Err "Node.js 版本过低: v$nodeVer (需要 18+)" exit 1 } Write-Success "Node.js v$nodeVer" } catch { Write-Err "没有检测到 Node.js" Write-Host " 请先安装 Node.js 18+:" -ForegroundColor Yellow Write-Host " 方式 1: 访问 https://nodejs.org 下载 LTS 版" Write-Host " 方式 2 (winget): " -NoNewline Write-Host "winget install OpenJS.NodeJS.LTS" -ForegroundColor Blue Write-Host " 方式 3 (scoop): " -NoNewline Write-Host "scoop install nodejs-lts" -ForegroundColor Blue exit 1 } # 5. 从 npm 安装 termctl (会通过 optionalDependencies 自动装 node-pty 的 Windows prebuilt 二进制) Write-Info "正在从 npm 安装 termctl..." try { npm install -g termctl Write-Success "termctl 已安装" } catch { Write-Err "npm 安装失败: $_" Write-Host " 可能原因:" Write-Host " 1. 需要管理员 PowerShell (右键 '以管理员身份运行')" Write-Host " 2. node-pty native binding 下载失败 (检查网络)" exit 1 } # 6. 验证 node-pty 已安装 (Windows daemon 必需) Write-Info "验证 node-pty 二进制..." try { $nptyPath = (npm root -g).Trim() + "\termctl\node_modules\node-pty" if (Test-Path $nptyPath) { Write-Success "node-pty 已就绪" } else { Write-Warn "node-pty 未找到, daemon 可能无法启动 PowerShell" Write-Host " 手动安装: npm install -g node-pty" } } catch {} Write-Host "" Write-Info "启动 daemon..." Write-Warn "终端会显示二维码, 在手机 AI Terminal APP 上扫描即可配对" Write-Host "" & termctl