diff --git a/install-claude-code.sh b/install-claude-code.sh index 74318df..b868b20 100755 --- a/install-claude-code.sh +++ b/install-claude-code.sh @@ -490,23 +490,186 @@ check_coding_helper_installed() { 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; 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; 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 "" - echo -e " ${GREEN}✓${NC} Interactive wizard for easy setup" - echo -e " ${GREEN}✓${NC} Multi-tool management (Claude Code, OpenCode, etc.)" - echo -e " ${GREEN}✓${NC} MCP service configuration" - echo -e " ${GREEN}✓${NC} API key management for both Global and China plans" - echo -e " ${GREEN}✓${NC} Bilingual interface (English/Chinese)" + 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 "" echo -e "${YELLOW}Available addons/features:${NC}" - echo " • MCP servers integration (Blender, filesystem, etc.)" - echo " • Plugin marketplace access" - echo " • Automatic tool detection and installation" - echo " • Configuration backup and sync" + 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 "" + + # 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++)) + + 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!" + 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 + 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 "" + read -p "Launch coding-helper wizard to configure missing components? [y/N] " -n 1 -r launch_helper < /dev/tty + echo "" + if [[ $launch_helper =~ ^[Yy]$ ]]; then + launch_coding_helper + fi + return + fi + + # Core not installed, offer installation read -p "Install Z.AI coding-helper? [y/N] " -n 1 -r install_helper < /dev/tty echo ""