diff --git a/install.ps1 b/install.ps1 index b41dc87..7623efc 100644 --- a/install.ps1 +++ b/install.ps1 @@ -363,12 +363,149 @@ if ($nodeCheck -eq $ClaudeTarget) { Write-Host " [WARN] Node.js 环境变量传递异常,hooks 可能无法正确解析路径" -ForegroundColor Yellow } -# 步骤 6: 启动 Claude Code -Write-Host "`n[7/7] 启动 Claude Code..." -ForegroundColor White +# 步骤 6: Bookworm 完整性验证 + MCP 检查 +Write-Host "`n[7/8] Bookworm 系统验证..." -ForegroundColor White + +# --- Bookworm vs 原生 Claude Code 检测 --- +$bwChecks = @() +$claudeMd = Join-Path $ClaudeTarget "CLAUDE.md" +$skillsDir = Join-Path $ClaudeTarget "skills" +$hooksDir = Join-Path $ClaudeTarget "hooks" +$settingsF = Join-Path $ClaudeTarget "settings.json" + +# 检查 CLAUDE.md +if (Test-Path $claudeMd) { + $content = Get-Content $claudeMd -Raw -ErrorAction SilentlyContinue + if ($content -match "Bookworm") { + $bwChecks += @{ Name = "CLAUDE.md (Bookworm 指令)"; OK = $true } + } else { + $bwChecks += @{ Name = "CLAUDE.md (缺少 Bookworm 指令)"; OK = $false } + } +} else { + $bwChecks += @{ Name = "CLAUDE.md (文件不存在!)"; OK = $false } +} + +# 检查 Skills +$skillCount = 0 +if (Test-Path $skillsDir) { + $skillCount = (Get-ChildItem $skillsDir -Directory -ErrorAction SilentlyContinue).Count +} +$bwChecks += @{ Name = "Skills ($skillCount 个)"; OK = ($skillCount -gt 50) } + +# 检查 Hooks +$hookCount = 0 +if (Test-Path $hooksDir) { + $hookCount = (Get-ChildItem $hooksDir -Filter "*.js" -File -ErrorAction SilentlyContinue).Count +} +$bwChecks += @{ Name = "Hooks ($hookCount 个)"; OK = ($hookCount -gt 10) } + +# 检查 settings.json hooks 配置 +$hasHooks = $false +if (Test-Path $settingsF) { + $sContent = Get-Content $settingsF -Raw -ErrorAction SilentlyContinue + if ($sContent -match '"hooks"') { $hasHooks = $true } +} +$bwChecks += @{ Name = "Settings hooks 配置"; OK = $hasHooks } + +# 输出验证结果 +$allOK = $true +foreach ($c in $bwChecks) { + $icon = if ($c.OK) { "[OK]" } else { "[!!]" } + $color = if ($c.OK) { "Green" } else { "Red" } + Write-Host " $icon $($c.Name)" -ForegroundColor $color + if (-not $c.OK) { $allOK = $false } +} + +if (-not $allOK) { + Write-Host "" + Write-Host " ╔══════════════════════════════════════════════════════╗" -ForegroundColor Yellow + Write-Host " ║ [!] 警告: Bookworm 系统不完整 ║" -ForegroundColor Yellow + Write-Host " ║ Claude Code 将以原生模式启动 (无 Skills/Hooks) ║" -ForegroundColor Yellow + Write-Host " ║ 建议: 不加 -StartOnly 重新运行 install.ps1 同步 ║" -ForegroundColor Yellow + Write-Host " ╚══════════════════════════════════════════════════════╝" -ForegroundColor Yellow +} else { + Write-Host " [OK] Bookworm 系统完整 ($skillCount Skills / $hookCount Hooks)" -ForegroundColor Green +} + +# --- MCP 依赖检查 (中文提醒) --- Write-Host "" -Write-Host " ╔══════════════════════════════════════════╗" -ForegroundColor Green -Write-Host " ║ Bookworm 就绪! 正在启动 Claude Code... ║" -ForegroundColor Green -Write-Host " ╚══════════════════════════════════════════╝" -ForegroundColor Green +Write-Host " MCP 服务检查:" -ForegroundColor Gray +$mcpWarnings = @() + +# Python (askui/pywinauto/com-server 需要) +$hasPython = [bool](Get-Command python -ErrorAction SilentlyContinue) +if (-not $hasPython) { + $mcpWarnings += " [!] Python 未安装 - askui/pywinauto/com-server MCP 不可用" + $mcpWarnings += " 安装: https://www.python.org/downloads/ 或 winget install Python.Python.3.12" +} + +# Playwright (浏览器自动化 MCP) +$hasPlaywright = $false +try { $null = npx --yes @playwright/mcp --help 2>$null; $hasPlaywright = $true } catch {} +if (-not $hasPlaywright) { + $mcpWarnings += " [!] Playwright MCP 未安装 - 浏览器自动化功能不可用" + $mcpWarnings += " 安装: npx playwright install" +} + +# 检查关键 API Key 环境变量 +$apiChecks = @( + @{ Key = "ANTHROPIC_API_KEY"; Name = "Claude API (中转站)" } + @{ Key = "ANTHROPIC_BASE_URL"; Name = "API 中转站地址" } +) +foreach ($ak in $apiChecks) { + $val = [System.Environment]::GetEnvironmentVariable($ak.Key, "Process") + if (-not $val) { + $mcpWarnings += " [!] $($ak.Key) 未设置 - $($ak.Name)不可用" + $mcpWarnings += " 需要管理员重新加密凭证并更新 secrets.enc" + } +} + +# 可选 MCP API Key 检查 +$optionalApis = @( + @{ Key = "GITHUB_PERSONAL_ACCESS_TOKEN"; Name = "GitHub MCP"; Cmd = "仓库管理/代码搜索" } + @{ Key = "SLACK_BOT_TOKEN"; Name = "Slack MCP"; Cmd = "消息发送/频道管理" } + @{ Key = "BROWSERBASE_API_KEY"; Name = "Browserbase MCP"; Cmd = "云端浏览器" } + @{ Key = "FIRECRAWL_API_KEY"; Name = "Firecrawl MCP"; Cmd = "网页抓取/搜索" } +) +$missingOptional = @() +foreach ($api in $optionalApis) { + $val = [System.Environment]::GetEnvironmentVariable($api.Key, "Process") + if (-not $val) { + $missingOptional += $api + } +} + +if ($mcpWarnings.Count -gt 0) { + foreach ($w in $mcpWarnings) { + Write-Host $w -ForegroundColor Yellow + } +} + +if ($missingOptional.Count -gt 0) { + Write-Host "" + Write-Host " 可选 MCP 服务 (未配置, 不影响核心功能):" -ForegroundColor Gray + foreach ($m in $missingOptional) { + Write-Host " [-] $($m.Name) ($($m.Cmd))" -ForegroundColor DarkGray + } + Write-Host " 如需使用, 请联系管理员将 API Key 加入 secrets.enc" -ForegroundColor DarkGray +} + +if ($mcpWarnings.Count -eq 0) { + Write-Host " [OK] 核心 API 已配置" -ForegroundColor Green +} + +# 步骤 7: 启动 Claude Code +Write-Host "`n[8/8] 启动 Claude Code..." -ForegroundColor White +Write-Host "" +if ($allOK) { + Write-Host " ╔══════════════════════════════════════════╗" -ForegroundColor Green + Write-Host " ║ Bookworm 就绪! 正在启动 Claude Code... ║" -ForegroundColor Green + Write-Host " ╚══════════════════════════════════════════╝" -ForegroundColor Green +} else { + Write-Host " ╔══════════════════════════════════════════╗" -ForegroundColor Yellow + Write-Host " ║ 原生模式启动 (Bookworm 不完整) ║" -ForegroundColor Yellow + Write-Host " ╚══════════════════════════════════════════╝" -ForegroundColor Yellow +} Write-Host "" & claude