diff --git a/install-claude-code.sh b/install-claude-code.sh index 39df500..f330663 100755 --- a/install-claude-code.sh +++ b/install-claude-code.sh @@ -482,172 +482,36 @@ EOF fi } -check_coding_helper_installed() { - if command -v chelper &> /dev/null || npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then - return 0 - else - return 1 - fi -} - -# Detect coding-helper components and their installation status -detect_coding_helper_components() { - local status_json="{" - - # 1. Core coding-helper installation - if command -v chelper &> /dev/null || npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then - status_json+='"core":true,' - else - status_json+='"core":false,' - fi - - # 2. Interactive wizard (part of core, but check if wizard can run) - if command -v chelper &> /dev/null || npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then - status_json+='"wizard":true,' - else - status_json+='"wizard":false,' - fi - - # 3. Multi-tool management (check for chelper config) - if [ -f "$HOME/.chelper/config.json" ] || [ -d "$HOME/.chelper" ]; then - status_json+='"multi_tool":true,' - else - status_json+='"multi_tool":false,' - fi - - # 4. MCP service configuration (check for MCP configs in Claude settings) - if [ -f "$CLAUDE_DIR/settings.json" ]; then - if grep -q "mcpServers" "$CLAUDE_DIR/settings.json" 2>/dev/null || \ - grep -q "mcp.*servers" "$CLAUDE_DIR/settings.json" 2>/dev/null; then - status_json+='"mcp_config":true,' - else - status_json+='"mcp_config":false,' - fi - else - status_json+='"mcp_config":false,' - fi - - # 5. API key management (check for Z.AI API keys in settings) - if [ -f "$CLAUDE_DIR/settings.json" ]; then - if grep -q "dashscope-intl.aliyuncs.com" "$CLAUDE_DIR/settings.json" 2>/dev/null; then - status_json+='"api_management":true,' - else - status_json+='"api_management":false,' - fi - else - status_json+='"api_management":false,' - fi - - # 6. Bilingual interface (inherent to coding-helper) - if command -v chelper &> /dev/null || npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then - status_json+='"bilingual":true,' - else - status_json+='"bilingual":false,' - fi - - # 7. MCP servers integration (check for installed MCP servers) - local mcp_count=0 - if [ -d "$CLAUDE_DIR/plugins" ]; then - mcp_count=$(find "$CLAUDE_DIR/plugins" -name "*mcp*" -o -name "*zai*" 2>/dev/null | wc -l) - fi - if [ "$mcp_count" -gt 0 ]; then - status_json+='"mcp_servers":true,' - else - status_json+='"mcp_servers":false,' - fi - - # 8. Plugin marketplace (check for marketplace config) - if [ -f "$CLAUDE_DIR/config.json" ] && grep -q "marketplace" "$CLAUDE_DIR/config.json" 2>/dev/null; then - status_json+='"marketplace":true,' - else - status_json+='"marketplace":false,' - fi - - # 9. Tool detection (check for tool-discovery-agent skill) - if [ -f "$CLAUDE_DIR/skills/tool-discovery-agent/SKILL.md" ]; then - status_json+='"tool_detection":true,' - else - status_json+='"tool_detection":false,' - fi - - # 10. Configuration backup/sync (check for sync scripts) - if [ -f "$CLAUDE_DIR/scripts/sync-agents.sh" ] || [ -f "$CLAUDE_DIR/agents/export-claude-customizations.sh" ]; then - status_json+='"backup_sync":true' - else - status_json+='"backup_sync":false' - fi - - status_json+="}" - echo "$status_json" -} - -# Display component status with colored indicators -display_component_status() { - local component_name="$1" - local is_installed="$2" - local indent="${3:- }" - - if [ "$is_installed" = "true" ]; then - echo -e "${indent}${GREEN}✓${NC} ${component_name} ${GREEN}[Installed]${NC}" - else - echo -e "${indent}${RED}✗${NC} ${component_name} ${YELLOW}[Not installed]${NC}" - fi -} - offer_coding_helper_addons() { log_step "Z.AI Coding-Helper Addons" echo "" - - # Detect installed components - local status_json=$(detect_coding_helper_components) - - # Parse JSON using simple string matching (bash compatible) - local core=$(echo "$status_json" | grep -o '"core":[^,}]*' | cut -d: -f2) - local wizard=$(echo "$status_json" | grep -o '"wizard":[^,}]*' | cut -d: -f2) - local multi_tool=$(echo "$status_json" | grep -o '"multi_tool":[^,}]*' | cut -d: -f2) - local mcp_config=$(echo "$status_json" | grep -o '"mcp_config":[^,}]*' | cut -d: -f2) - local api_management=$(echo "$status_json" | grep -o '"api_management":[^,}]*' | cut -d: -f2) - local bilingual=$(echo "$status_json" | grep -o '"bilingual":[^,}]*' | cut -d: -f2) - local mcp_servers=$(echo "$status_json" | grep -o '"mcp_servers":[^,}]*' | cut -d: -f2) - local marketplace=$(echo "$status_json" | grep -o '"marketplace":[^,}]*' | cut -d: -f2) - local tool_detection=$(echo "$status_json" | grep -o '"tool_detection":[^,}]*' | cut -d: -f2) - local backup_sync=$(echo "$status_json" | grep -o '"backup_sync":[^,}]*' | cut -d: -f2) - echo -e "${CYAN}Z.AI's coding-helper (chelper) provides additional features:${NC}" echo "" - display_component_status "Interactive wizard for easy setup" "$wizard" - display_component_status "Multi-tool management (Claude Code, OpenCode, etc.)" "$multi_tool" - display_component_status "MCP service configuration" "$mcp_config" - display_component_status "API key management for both Global and China plans" "$api_management" - display_component_status "Bilingual interface (English/Chinese)" "$bilingual" + echo " • Interactive wizard for easy setup" + echo " • Multi-tool management (Claude Code, OpenCode, etc.)" + echo " • MCP service configuration" + echo " • API key management for both Global and China plans" + echo " • Bilingual interface (English/Chinese)" echo "" echo -e "${YELLOW}Available addons/features:${NC}" - display_component_status "MCP servers integration (Blender, filesystem, etc.)" "$mcp_servers" - display_component_status "Plugin marketplace access" "$marketplace" - display_component_status "Automatic tool detection and installation" "$tool_detection" - display_component_status "Configuration backup and sync" "$backup_sync" + echo " • MCP servers integration (Blender, filesystem, etc.)" + echo " • Plugin marketplace access" + echo " • Automatic tool detection and installation" + echo " • Configuration backup and sync" echo "" - # Calculate overall status - local total=10 - local installed=0 - [ "$core" = "true" ] && ((installed++)) - [ "$wizard" = "true" ] && ((installed++)) - [ "$multi_tool" = "true" ] && ((installed++)) - [ "$mcp_config" = "true" ] && ((installed++)) - [ "$api_management" = "true" ] && ((installed++)) - [ "$bilingual" = "true" ] && ((installed++)) - [ "$mcp_servers" = "true" ] && ((installed++)) - [ "$marketplace" = "true" ] && ((installed++)) - [ "$tool_detection" = "true" ] && ((installed++)) - [ "$backup_sync" = "true" ] && ((installed++)) + # Check if chelper command exists or npm package is installed + local is_installed=false + if command -v chelper &> /dev/null; then + is_installed=true + elif npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then + is_installed=true + fi - echo -e "${CYAN}Installation Status:${NC} ${GREEN}${installed}${NC}/${total} components installed" - echo "" - - # If everything is installed, offer to launch wizard or skip - if [ "$installed" -eq "$total" ]; then - log_success "All coding-helper components are already installed!" + if [ "$is_installed" = true ]; then + log_success "coding-helper is installed!" + echo "" + echo -e "${CYAN}You can run it anytime with:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}" echo "" echo -e "${CYAN}Launch coding-helper wizard now?${NC} ${GREEN}[Y/n]${NC}" >&2 echo -en "\033[0;36m> \033[0m" @@ -656,66 +520,39 @@ offer_coding_helper_addons() { set -e echo "" if [[ $launch_helper =~ ^[Yy]$ ]]; then - launch_coding_helper + npx @z_ai/coding-helper fi return fi - # If core is installed but some components missing, ask to install - if [ "$core" = "true" ]; then - log_info "coding-helper is installed, but some components may be missing" - echo "" - echo -e "${CYAN}Launch coding-helper wizard to configure missing components?${NC} ${GREEN}[Y/n]${NC}" - >&2 echo -en "\033[0;36m> \033[0m" - set +e - read -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="N" - set -e - echo "" - if [[ $launch_helper =~ ^[Yy]$ ]]; then - launch_coding_helper - fi - return - fi - - # Core not installed, offer installation + # Not installed - offer installation echo "" echo -e "${BOLD}${MAGENTA}═══════════════════════════════════════════════════════════${NC}" echo -e "${BOLD}${MAGENTA} Install Z.AI coding-helper now?${NC} ${GREEN}[Y/n]${NC}" echo -e "${BOLD}${MAGENTA}═══════════════════════════════════════════════════════════${NC}" - read -p " " -n 1 -r install_helper < /dev/tty + set +e + read -n 1 -r install_helper < /dev/tty 2>/dev/null || install_helper="Y" + set -e echo "" - # Default to Yes if user just presses Enter + # Default to Yes if user just presses Enter or enters Y/y if [[ -z "$install_helper" ]] || [[ $install_helper =~ ^[Yy]$ ]]; then - install_coding_helper + install_coding_helper_simple else log_info "Skipping coding-helper installation" - return + echo "" + echo -e "${CYAN}You can install it later with:${NC}" + echo -e " ${YELLOW}npm install -g @z_ai/coding-helper${NC}" + echo " ${YELLOW}npx @z_ai/coding-helper${NC}" fi } -install_coding_helper() { +# Simplified installation function +install_coding_helper_simple() { log_info "Installing @z_ai/coding-helper..." echo "" - if check_coding_helper_installed; then - log_info "coding-helper already installed" - echo "" - # Show prompt explicitly (read -p doesn't work with curl | bash) - echo -e "${CYAN}Launch coding-helper wizard now?${NC} ${GREEN}[Y/n]${NC}" - >&2 echo -en "\033[0;36m> \033[0m" - # Temporarily disable set -e for read command - set +e - read -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="N" - set -e - echo "" - if [[ $launch_helper =~ ^[Yy]$ ]]; then - launch_coding_helper - fi - return - fi - - # Install the helper (temporarily disable set -e to capture errors) + # Try regular install first set +e local install_output install_output=$(npm install -g @z_ai/coding-helper 2>&1) @@ -725,123 +562,86 @@ install_coding_helper() { if [ $install_exit_code -eq 0 ]; then # Verify installation if npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then - log_success "coding-helper installed and verified!" + log_success "coding-helper installed!" echo "" echo -e "${CYAN}You can now run:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}" echo "" - echo -e "${CYAN}Launch coding-helper wizard now?${NC} ${GREEN}[Y/n]${NC}" - >&2 echo -en "\033[0;36m> \033[0m" + echo -e "${CYAN}Launch the wizard now?${NC} ${GREEN}[Y/n]${NC}" set +e - read -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="N" + read -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="Y" set -e echo "" - if [[ $launch_helper =~ ^[Yy]$ ]]; then - launch_coding_helper + if [[ -z "$launch_helper" ]] || [[ $launch_helper =~ ^[Yy]$ ]]; then + npx @z_ai/coding-helper fi else log_warn "Installation appeared to succeed but verification failed" echo "" - echo -e "${YELLOW}Installation output:${NC}" - echo "$install_output" - echo "" - echo -e "${CYAN}You can try running manually:${NC}" - echo -e " ${YELLOW}npx @z_ai/coding-helper${NC}" + echo -e "${CYAN}You can still run it with:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}" fi - else - # Check if it's a permission error (EACCES) - if echo "$install_output" | grep -q "EACCES\|permission denied"; then - log_error "Installation failed due to permissions!" + return + fi + + # Check if permission error + if echo "$install_output" | grep -q "EACCES\|permission denied"; then + log_error "Installation failed due to permissions!" + echo "" + echo -e "${YELLOW}The installation requires write permissions to:${NC}" + echo -e " ${CYAN}/usr/local/lib/node_modules/@z_ai${NC}" + echo "" + echo -e "${BOLD}You have several options:${NC}" + echo "" + echo -e "${GREEN}Option 1: Use sudo (recommended)${NC}" + echo -e " Run: ${YELLOW}sudo npm install -g @z_ai/coding-helper${NC}" + echo "" + echo -e "${GREEN}Option 2: Run without installation (works immediately)${NC}" + echo -e " Just use: ${YELLOW}npx @z_ai/coding-helper${NC}" + echo "" + echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}" + echo -e "${BOLD} Try installing with sudo now?${NC} ${GREEN}[Y/n]${NC} ${BOLD}(recommended)${NC}" + echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}" + set +e + read -n 1 -r use_sudo < /dev/tty 2>/dev/null || use_sudo="Y" + set -e + echo "" + + if [[ -z "$use_sudo" ]] || [[ $use_sudo =~ ^[Yy]$ ]]; then echo "" - echo -e "${YELLOW}The installation requires write permissions to:${NC}" - echo -e " ${CYAN}/usr/local/lib/node_modules/@z_ai${NC}" - echo "" - echo -e "${BOLD}You have several options:${NC}" - echo "" - echo -e "${GREEN}Option 1: Use sudo (recommended)${NC}" - echo -e " Run: ${YELLOW}sudo npm install -g @z_ai/coding-helper${NC}" - echo "" - echo -e "${GREEN}Option 2: Fix npm permissions permanently${NC}" - echo -e " Run: ${YELLOW}sudo chown -R \$(whoami) /usr/local/lib/node_modules${NC}" - echo -e " ${YELLOW}sudo chown -R \$(whoami) /usr/local/bin${NC}" - echo -e " Then: ${YELLOW}npm install -g @z_ai/coding-helper${NC}" - echo "" - echo -e "${GREEN}Option 3: Run without installation (works immediately)${NC}" - echo -e " Just use: ${YELLOW}npx @z_ai/coding-helper${NC}" - echo "" - echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}" - echo -e "${BOLD} Try installing with sudo now?${NC} ${GREEN}[Y/n]${NC} ${BOLD}(recommended)${NC}" - echo -e "${BOLD}${YELLOW}═══════════════════════════════════════════════════════════${NC}" - # Temporarily disable set -e for read command + log_info "Installing with sudo..." set +e - read -p " " -n 1 -r use_sudo < /dev/tty 2>/dev/null || use_sudo="Y" - set -e - echo "" - # Default to Yes if user just presses Enter - if [[ -z "$use_sudo" ]] || [[ $use_sudo =~ ^[Yy]$ ]]; then - echo "" - log_info "Installing with sudo..." - if sudo npm install -g @z_ai/coding-helper 2>&1; then - if npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then - log_success "coding-helper installed and verified with sudo!" - echo "" - # Show prompt explicitly (read -p doesn't work with curl | bash) - echo -e "${CYAN}Launch coding-helper wizard now?${NC} ${GREEN}[Y/n]${NC}" - echo -e "${CYAN}(Press Enter for Yes, or 'n' to skip)${NC}" - # Flush output to ensure prompt displays - >&2 echo -en "\033[0;36m> \033[0m" - set +e - read -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="Y" - set -e - echo "" - echo "" - if [[ -z "$launch_helper" ]] || [[ $launch_helper =~ ^[Yy]$ ]]; then - launch_coding_helper - fi - fi - else - log_warn "Sudo installation also failed" + if sudo npm install -g @z_ai/coding-helper 2>&1; then + set -e + if npm list -g @z_ai/coding-helper &> /dev/null 2>&1; then + log_success "coding-helper installed!" echo "" - echo -e "${CYAN}You can still run it without installation:${NC}" - echo -e " ${YELLOW}npx @z_ai/coding-helper${NC}" + echo -e "${CYAN}Launch the wizard now?${NC} ${GREEN}[Y/n]${NC}" + set +e + read -n 1 -r launch_helper < /dev/tty 2>/dev/null || launch_helper="Y" + set -e + echo "" + if [[ -z "$launch_helper" ]] || [[ $launch_helper =~ ^[Yy]$ ]]; then + npx @z_ai/coding-helper + fi fi else + set -e + log_warn "Sudo installation also failed" echo "" - echo -e "${CYAN}No problem! You can run it anytime with:${NC}" - echo -e " ${YELLOW}npx @z_ai/coding-helper${NC}" + echo -e "${CYAN}You can still run it with:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}" fi else - # Non-permission error - log_error "Installation failed!" echo "" - echo -e "${YELLOW}Error output:${NC}" - echo "$install_output" - echo "" - echo -e "${CYAN}You can try installing manually:${NC}" - echo -e " ${YELLOW}npm install -g @z_ai/coding-helper${NC}" - echo -e " ${YELLOW}sudo npm install -g @z_ai/coding-helper${NC}" - echo "" - echo -e "${CYAN}Or run without installation:${NC}" + echo -e "${CYAN}No problem! You can run it anytime with:${NC}" echo -e " ${YELLOW}npx @z_ai/coding-helper${NC}" fi - fi -} - -launch_coding_helper() { - log_info "Launching Z.AI coding-helper wizard..." - echo "" - echo -e "${CYAN}The wizard will guide you through:${NC}" - echo " 1. Selecting UI language" - echo " 2. Choosing coding plan (Global/China)" - echo " 3. Entering API key" - echo " 4. Selecting tools to manage" - echo " 5. Installing and configuring tools" - echo " 6. Managing MCP services" - echo "" - - if command -v chelper &> /dev/null; then - chelper else - npx @z_ai/coding-helper + # Other error + log_error "Installation failed!" + echo "" + echo -e "${YELLOW}Error output:${NC}" + echo "$install_output" + echo "" + echo -e "${CYAN}You can still run it with:${NC} ${YELLOW}npx @z_ai/coding-helper${NC}" fi }