diff --git a/install-claude-code.sh b/install-claude-code.sh index 98cfcfd..0de0def 100755 --- a/install-claude-code.sh +++ b/install-claude-code.sh @@ -723,16 +723,67 @@ install_coding_helper() { echo -e " ${YELLOW}npx @z_ai/coding-helper${NC}" fi else - 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 "" - echo -e "${CYAN}Or run without installation:${NC}" - echo -e " ${YELLOW}npx @z_ai/coding-helper${NC}" + # 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!" + 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 "${CYAN}Want to try with sudo now? [y/N]${NC}" + read -p " " -n 1 -r use_sudo < /dev/tty + echo "" + if [[ $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 "" + read -p "Launch coding-helper wizard now? [y/N] " -n 1 -r launch_helper < /dev/tty + echo "" + if [[ $launch_helper =~ ^[Yy]$ ]]; then + launch_coding_helper + fi + fi + else + log_warn "Sudo installation also failed" + echo "" + echo -e "${CYAN}You can still run it without installation:${NC}" + echo -e " ${YELLOW}npx @z_ai/coding-helper${NC}" + fi + else + echo "" + echo -e "${CYAN}No problem! You can run it anytime with:${NC}" + echo -e " ${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 " ${YELLOW}npx @z_ai/coding-helper${NC}" + fi fi }