if have_cmd npx; then echo"✅ npx: $(npx -v)" else echo"⚠️ 警告:npx 不在 PATH,后续使用 npx 相关命令可能失败。" fi
echo"🛠 配置 npm 全局目录为 /usr/local..." mkdir -p /usr/local/lib/node_modules /usr/local/bin npm config set prefix /usr/local npm config set audit false npm config set fund false
echo"💾 安装 AI CLI(检测已安装则跳过)..."
# 1. Claude Code (@anthropic-ai/claude-code) if have_cmd claude || have_global_npm_pkg "@anthropic-ai/claude-code"; then echo" → Claude Code 已安装,跳过 (@anthropic-ai/claude-code)" else echo" → 安装 Claude Code (@anthropic-ai/claude-code)" if ! npm install -g @anthropic-ai/claude-code@latest; then echo"⚠️ Claude Code 安装失败,请稍后重试。" fi fi
# 2. Gemini CLI (@google/gemini-cli) if have_cmd gemini || have_global_npm_pkg "@google/gemini-cli"; then echo" → Gemini CLI 已安装,跳过 (@google/gemini-cli)" else echo" → 安装 Gemini CLI (@google/gemini-cli)" if ! npm install -g @google/gemini-cli@latest; then echo"⚠️ Gemini CLI 安装失败,请检查网络或包名。" fi fi
# 3. OpenAI Codex (@openai/codex) if have_cmd codex || have_global_npm_pkg "@openai/codex"; then echo" → OpenAI Codex 已安装,跳过 (@openai/codex)" else echo" → 安装 OpenAI Codex (@openai/codex)" if ! npm install -g @openai/codex@latest; then echo"⚠️ Codex 安装失败,请检查网络或包名。" fi fi
# 4. OpenCode (opencode-ai) - 修正包名为 opencode-ai(无 @) if have_cmd opencode || have_global_npm_pkg "opencode-ai"; then echo" → OpenCode 已安装,跳过 (opencode-ai)" else echo" → 安装 OpenCode CLI (opencode-ai)" if npm install -g opencode-ai@latest; then echo" → OpenCode npm 安装成功" else echo" → npm 安装失败,尝试官方一键脚本..." curl -fsSL https://opencode.ai/install | bash || echo"⚠️ OpenCode 一键安装也失败,请手动检查网络/权限" fi fi
# 5. iFlow CLI (@iflow-ai/iflow-cli) if have_cmd iflow || have_global_npm_pkg "@iflow-ai/iflow-cli"; then echo" → iFlow CLI 已安装,跳过 (@iflow-ai/iflow-cli)" else echo" → 安装 iFlow CLI (@iflow-ai/iflow-cli)" if ! npm install -g @iflow-ai/iflow-cli@latest; then echo"⚠️ iFlow 安装失败,请检查网络或包名。" fi fi
# 6. Qwen Code (@qwen-code/qwen-code) if have_cmd qwen-code || have_global_npm_pkg "@qwen-code/qwen-code"; then echo" → Qwen Code 已安装,跳过 (@qwen-code/qwen-code)" else echo" → 安装 Qwen Code (@qwen-code/qwen-code)" if ! npm install -g @qwen-code/qwen-code@latest; then echo"⚠️ Qwen Code 安装失败,请检查网络或包名。" fi fi
echo"💾 安装 HAPI(全局)..." # 7. HAPI (@twsxtd/hapi) - 你已经验证这条命令可用 if have_cmd hapi || have_global_npm_pkg "@twsxtd/hapi"; then echo" → HAPI 已安装,跳过 (@twsxtd/hapi)" else echo" → 安装 HAPI (@twsxtd/hapi)" if ! npm install -g @twsxtd/hapi@latest; then echo"⚠️ HAPI 安装失败,请检查网络或包名。" fi fi