mirror of
https://github.com/SuperClaude-Org/SuperClaude_Framework.git
synced 2025-12-29 16:16:08 +00:00
Remove profile system and make custom two-stage selection default
- Remove profiles/ directory with all profile JSON files - Update install.py to remove profile CLI options and simplify flow - Make interactive two-stage selection (MCP → Components) the default - Remove ConfigManager.load_profile() method - Update documentation to reflect simplified installation process - Add CLAUDEMdManager for intelligent CLAUDE.md import management - Components now install to root directory with organized @imports - Preserve user customizations while managing framework imports This simplifies the installation experience while providing users direct control over what gets installed through the intuitive two-stage selection process. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -12,7 +12,6 @@ from pathlib import Path
|
||||
SETUP_DIR = Path(__file__).parent
|
||||
PROJECT_ROOT = SETUP_DIR.parent
|
||||
CONFIG_DIR = PROJECT_ROOT / "config"
|
||||
PROFILES_DIR = PROJECT_ROOT / "profiles"
|
||||
|
||||
# Installation target
|
||||
DEFAULT_INSTALL_DIR = Path.home() / ".claude"
|
||||
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
import shutil
|
||||
|
||||
from ..base.component import Component
|
||||
from ..managers.claude_md_manager import CLAUDEMdManager
|
||||
|
||||
class CoreComponent(Component):
|
||||
"""Core SuperClaude framework files component"""
|
||||
@@ -77,6 +78,15 @@ class CoreComponent(Component):
|
||||
dir_path = self.install_dir / dirname
|
||||
if not self.file_manager.ensure_directory(dir_path):
|
||||
self.logger.warning(f"Could not create directory: {dir_path}")
|
||||
|
||||
# Update CLAUDE.md with core framework imports
|
||||
try:
|
||||
manager = CLAUDEMdManager(self.install_dir)
|
||||
manager.add_imports(self.component_files, category="Core Framework")
|
||||
self.logger.info("Updated CLAUDE.md with core framework imports")
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to update CLAUDE.md with core framework imports: {e}")
|
||||
# Don't fail the whole installation for this
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import Dict, List, Tuple, Optional, Any
|
||||
from pathlib import Path
|
||||
|
||||
from ..base.component import Component
|
||||
from ..managers.claude_md_manager import CLAUDEMdManager
|
||||
|
||||
|
||||
class MCPDocsComponent(Component):
|
||||
@@ -13,7 +14,7 @@ class MCPDocsComponent(Component):
|
||||
|
||||
def __init__(self, install_dir: Optional[Path] = None):
|
||||
"""Initialize MCP docs component"""
|
||||
super().__init__(install_dir, Path("mcp"))
|
||||
super().__init__(install_dir, Path(""))
|
||||
|
||||
# Map server names to documentation files
|
||||
self.server_docs_map = {
|
||||
@@ -57,7 +58,7 @@ class MCPDocsComponent(Component):
|
||||
if server_name in self.server_docs_map:
|
||||
doc_file = self.server_docs_map[server_name]
|
||||
source = source_dir / doc_file
|
||||
target = self.install_component_subdir / doc_file
|
||||
target = self.install_dir / doc_file
|
||||
if source.exists():
|
||||
files.append((source, target))
|
||||
self.logger.debug(f"Will install documentation for {server_name}: {doc_file}")
|
||||
@@ -143,6 +144,15 @@ class MCPDocsComponent(Component):
|
||||
self.settings_manager.update_metadata(metadata_mods)
|
||||
self.logger.info("Updated metadata with MCP docs component registration")
|
||||
|
||||
# Update CLAUDE.md with MCP documentation imports
|
||||
try:
|
||||
manager = CLAUDEMdManager(self.install_dir)
|
||||
manager.add_imports(self.component_files, category="MCP Documentation")
|
||||
self.logger.info("Updated CLAUDE.md with MCP documentation imports")
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to update CLAUDE.md with MCP documentation imports: {e}")
|
||||
# Don't fail the whole installation for this
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to update metadata: {e}")
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import Dict, List, Tuple, Optional, Any
|
||||
from pathlib import Path
|
||||
|
||||
from ..base.component import Component
|
||||
from ..managers.claude_md_manager import CLAUDEMdManager
|
||||
|
||||
|
||||
class ModesComponent(Component):
|
||||
@@ -13,7 +14,7 @@ class ModesComponent(Component):
|
||||
|
||||
def __init__(self, install_dir: Optional[Path] = None):
|
||||
"""Initialize modes component"""
|
||||
super().__init__(install_dir, Path("modes"))
|
||||
super().__init__(install_dir, Path(""))
|
||||
|
||||
def get_metadata(self) -> Dict[str, str]:
|
||||
"""Get component metadata"""
|
||||
@@ -77,6 +78,15 @@ class ModesComponent(Component):
|
||||
self.settings_manager.update_metadata(metadata_mods)
|
||||
self.logger.info("Updated metadata with modes component registration")
|
||||
|
||||
# Update CLAUDE.md with mode imports
|
||||
try:
|
||||
manager = CLAUDEMdManager(self.install_dir)
|
||||
manager.add_imports(self.component_files, category="Behavioral Modes")
|
||||
self.logger.info("Updated CLAUDE.md with mode imports")
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Failed to update CLAUDE.md with mode imports: {e}")
|
||||
# Don't fail the whole installation for this
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to update metadata: {e}")
|
||||
|
||||
316
setup/managers/claude_md_manager.py
Normal file
316
setup/managers/claude_md_manager.py
Normal file
@@ -0,0 +1,316 @@
|
||||
"""
|
||||
CLAUDE.md Manager for preserving user customizations while managing framework imports
|
||||
"""
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
from typing import List, Set, Dict, Optional
|
||||
from ..utils.logger import get_logger
|
||||
|
||||
|
||||
class CLAUDEMdManager:
|
||||
"""Manages CLAUDE.md file updates while preserving user customizations"""
|
||||
|
||||
def __init__(self, install_dir: Path):
|
||||
"""
|
||||
Initialize CLAUDEMdManager
|
||||
|
||||
Args:
|
||||
install_dir: Installation directory (typically ~/.claude)
|
||||
"""
|
||||
self.install_dir = install_dir
|
||||
self.claude_md_path = install_dir / "CLAUDE.md"
|
||||
self.logger = get_logger()
|
||||
|
||||
def read_existing_imports(self) -> Set[str]:
|
||||
"""
|
||||
Parse CLAUDE.md for existing @import statements
|
||||
|
||||
Returns:
|
||||
Set of already imported filenames (without @)
|
||||
"""
|
||||
existing_imports = set()
|
||||
|
||||
if not self.claude_md_path.exists():
|
||||
return existing_imports
|
||||
|
||||
try:
|
||||
with open(self.claude_md_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# Find all @import statements using regex
|
||||
import_pattern = r'^@([^\s\n]+\.md)\s*$'
|
||||
matches = re.findall(import_pattern, content, re.MULTILINE)
|
||||
existing_imports.update(matches)
|
||||
|
||||
self.logger.debug(f"Found existing imports: {existing_imports}")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Could not read existing CLAUDE.md imports: {e}")
|
||||
|
||||
return existing_imports
|
||||
|
||||
def read_existing_content(self) -> str:
|
||||
"""
|
||||
Read existing CLAUDE.md content
|
||||
|
||||
Returns:
|
||||
Existing content or empty string if file doesn't exist
|
||||
"""
|
||||
if not self.claude_md_path.exists():
|
||||
return ""
|
||||
|
||||
try:
|
||||
with open(self.claude_md_path, 'r', encoding='utf-8') as f:
|
||||
return f.read()
|
||||
except Exception as e:
|
||||
self.logger.warning(f"Could not read existing CLAUDE.md: {e}")
|
||||
return ""
|
||||
|
||||
def extract_user_content(self, content: str) -> str:
|
||||
"""
|
||||
Extract user content (everything before framework imports section)
|
||||
|
||||
Args:
|
||||
content: Full CLAUDE.md content
|
||||
|
||||
Returns:
|
||||
User content without framework imports
|
||||
"""
|
||||
# Look for framework imports section marker
|
||||
framework_marker = "# ═══════════════════════════════════════════════════\n# SuperClaude Framework Components"
|
||||
|
||||
if framework_marker in content:
|
||||
user_content = content.split(framework_marker)[0].rstrip()
|
||||
else:
|
||||
# If no framework section exists, preserve all content
|
||||
user_content = content.rstrip()
|
||||
|
||||
return user_content
|
||||
|
||||
def organize_imports_by_category(self, files_by_category: Dict[str, List[str]]) -> str:
|
||||
"""
|
||||
Organize imports into categorized sections
|
||||
|
||||
Args:
|
||||
files_by_category: Dict mapping category names to lists of files
|
||||
|
||||
Returns:
|
||||
Formatted import sections
|
||||
"""
|
||||
if not files_by_category:
|
||||
return ""
|
||||
|
||||
sections = []
|
||||
|
||||
# Framework imports section header
|
||||
sections.append("# ═══════════════════════════════════════════════════")
|
||||
sections.append("# SuperClaude Framework Components")
|
||||
sections.append("# ═══════════════════════════════════════════════════")
|
||||
sections.append("")
|
||||
|
||||
# Add each category
|
||||
for category, files in files_by_category.items():
|
||||
if files:
|
||||
sections.append(f"# {category}")
|
||||
for file in sorted(files):
|
||||
sections.append(f"@{file}")
|
||||
sections.append("")
|
||||
|
||||
return "\n".join(sections)
|
||||
|
||||
def add_imports(self, files: List[str], category: str = "Framework") -> bool:
|
||||
"""
|
||||
Add new imports with duplicate checking and user content preservation
|
||||
|
||||
Args:
|
||||
files: List of filenames to import
|
||||
category: Category name for organizing imports
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
# Ensure CLAUDE.md exists
|
||||
self.ensure_claude_md_exists()
|
||||
|
||||
# Read existing content and imports
|
||||
existing_content = self.read_existing_content()
|
||||
existing_imports = self.read_existing_imports()
|
||||
|
||||
# Filter out files already imported
|
||||
new_files = [f for f in files if f not in existing_imports]
|
||||
|
||||
if not new_files:
|
||||
self.logger.info("All files already imported, no changes needed")
|
||||
return True
|
||||
|
||||
self.logger.info(f"Adding {len(new_files)} new imports to category '{category}': {new_files}")
|
||||
|
||||
# Extract user content (preserve everything before framework section)
|
||||
user_content = self.extract_user_content(existing_content)
|
||||
|
||||
# Parse existing framework imports by category
|
||||
existing_framework_imports = self._parse_existing_framework_imports(existing_content)
|
||||
|
||||
# Add new files to the specified category
|
||||
if category not in existing_framework_imports:
|
||||
existing_framework_imports[category] = []
|
||||
existing_framework_imports[category].extend(new_files)
|
||||
|
||||
# Build new content
|
||||
new_content_parts = []
|
||||
|
||||
# Add user content
|
||||
if user_content.strip():
|
||||
new_content_parts.append(user_content)
|
||||
new_content_parts.append("") # Add blank line before framework section
|
||||
|
||||
# Add organized framework imports
|
||||
framework_section = self.organize_imports_by_category(existing_framework_imports)
|
||||
if framework_section:
|
||||
new_content_parts.append(framework_section)
|
||||
|
||||
# Write updated content
|
||||
new_content = "\n".join(new_content_parts)
|
||||
|
||||
with open(self.claude_md_path, 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
|
||||
self.logger.success(f"Updated CLAUDE.md with {len(new_files)} new imports")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to update CLAUDE.md: {e}")
|
||||
return False
|
||||
|
||||
def _parse_existing_framework_imports(self, content: str) -> Dict[str, List[str]]:
|
||||
"""
|
||||
Parse existing framework imports organized by category
|
||||
|
||||
Args:
|
||||
content: Full CLAUDE.md content
|
||||
|
||||
Returns:
|
||||
Dict mapping category names to lists of imported files
|
||||
"""
|
||||
imports_by_category = {}
|
||||
|
||||
# Look for framework imports section
|
||||
framework_marker = "# ═══════════════════════════════════════════════════\n# SuperClaude Framework Components"
|
||||
|
||||
if framework_marker not in content:
|
||||
return imports_by_category
|
||||
|
||||
# Extract framework section
|
||||
framework_section = content.split(framework_marker)[1] if framework_marker in content else ""
|
||||
|
||||
# Parse categories and imports
|
||||
lines = framework_section.split('\n')
|
||||
current_category = None
|
||||
|
||||
for line in lines:
|
||||
line = line.strip()
|
||||
|
||||
# Skip section header lines and empty lines
|
||||
if line.startswith('# ═══') or not line:
|
||||
continue
|
||||
|
||||
# Category header (starts with # but not the section divider)
|
||||
if line.startswith('# ') and not line.startswith('# ═══'):
|
||||
current_category = line[2:].strip() # Remove "# "
|
||||
if current_category not in imports_by_category:
|
||||
imports_by_category[current_category] = []
|
||||
|
||||
# Import line (starts with @)
|
||||
elif line.startswith('@') and current_category:
|
||||
import_file = line[1:].strip() # Remove "@"
|
||||
if import_file not in imports_by_category[current_category]:
|
||||
imports_by_category[current_category].append(import_file)
|
||||
|
||||
return imports_by_category
|
||||
|
||||
def ensure_claude_md_exists(self) -> None:
|
||||
"""
|
||||
Create CLAUDE.md with default content if it doesn't exist
|
||||
"""
|
||||
if self.claude_md_path.exists():
|
||||
return
|
||||
|
||||
try:
|
||||
# Create directory if it doesn't exist
|
||||
self.claude_md_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Default CLAUDE.md content
|
||||
default_content = """# SuperClaude Entry Point
|
||||
|
||||
This file serves as the entry point for the SuperClaude framework.
|
||||
You can add your own custom instructions and configurations here.
|
||||
|
||||
The SuperClaude framework components will be automatically imported below.
|
||||
"""
|
||||
|
||||
with open(self.claude_md_path, 'w', encoding='utf-8') as f:
|
||||
f.write(default_content)
|
||||
|
||||
self.logger.info("Created CLAUDE.md with default content")
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to create CLAUDE.md: {e}")
|
||||
raise
|
||||
|
||||
def remove_imports(self, files: List[str]) -> bool:
|
||||
"""
|
||||
Remove specific imports from CLAUDE.md
|
||||
|
||||
Args:
|
||||
files: List of filenames to remove from imports
|
||||
|
||||
Returns:
|
||||
True if successful, False otherwise
|
||||
"""
|
||||
try:
|
||||
if not self.claude_md_path.exists():
|
||||
return True # Nothing to remove
|
||||
|
||||
existing_content = self.read_existing_content()
|
||||
user_content = self.extract_user_content(existing_content)
|
||||
existing_framework_imports = self._parse_existing_framework_imports(existing_content)
|
||||
|
||||
# Remove files from all categories
|
||||
removed_any = False
|
||||
for category, category_files in existing_framework_imports.items():
|
||||
for file in files:
|
||||
if file in category_files:
|
||||
category_files.remove(file)
|
||||
removed_any = True
|
||||
|
||||
# Remove empty categories
|
||||
existing_framework_imports = {k: v for k, v in existing_framework_imports.items() if v}
|
||||
|
||||
if not removed_any:
|
||||
return True # Nothing was removed
|
||||
|
||||
# Rebuild content
|
||||
new_content_parts = []
|
||||
|
||||
if user_content.strip():
|
||||
new_content_parts.append(user_content)
|
||||
new_content_parts.append("")
|
||||
|
||||
framework_section = self.organize_imports_by_category(existing_framework_imports)
|
||||
if framework_section:
|
||||
new_content_parts.append(framework_section)
|
||||
|
||||
# Write updated content
|
||||
new_content = "\n".join(new_content_parts)
|
||||
|
||||
with open(self.claude_md_path, 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
|
||||
self.logger.info(f"Removed {len(files)} imports from CLAUDE.md")
|
||||
return True
|
||||
|
||||
except Exception as e:
|
||||
self.logger.error(f"Failed to remove imports from CLAUDE.md: {e}")
|
||||
return False
|
||||
@@ -278,47 +278,6 @@ class ConfigManager:
|
||||
return component_info.get("dependencies", [])
|
||||
return []
|
||||
|
||||
def load_profile(self, profile_path: Path) -> Dict[str, Any]:
|
||||
"""
|
||||
Load installation profile
|
||||
|
||||
Args:
|
||||
profile_path: Path to profile JSON file
|
||||
|
||||
Returns:
|
||||
Profile configuration dict
|
||||
|
||||
Raises:
|
||||
FileNotFoundError: If profile not found
|
||||
ValidationError: If profile is invalid
|
||||
"""
|
||||
if not profile_path.exists():
|
||||
raise FileNotFoundError(f"Profile not found: {profile_path}")
|
||||
|
||||
try:
|
||||
with open(profile_path, 'r') as f:
|
||||
profile = json.load(f)
|
||||
|
||||
# Basic validation
|
||||
if "components" not in profile:
|
||||
raise ValidationError("Profile must contain 'components' field")
|
||||
|
||||
if not isinstance(profile["components"], list):
|
||||
raise ValidationError("Profile 'components' must be a list")
|
||||
|
||||
# Validate that all components exist
|
||||
features = self.load_features()
|
||||
available_components = set(features.get("components", {}).keys())
|
||||
|
||||
for component in profile["components"]:
|
||||
if component not in available_components:
|
||||
raise ValidationError(f"Unknown component in profile: {component}")
|
||||
|
||||
return profile
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
raise ValidationError(f"Invalid JSON in {profile_path}: {e}")
|
||||
|
||||
def get_system_requirements(self) -> Dict[str, Any]:
|
||||
"""
|
||||
Get system requirements
|
||||
|
||||
@@ -40,8 +40,7 @@ def register_parser(subparsers, global_parser=None) -> argparse.ArgumentParser:
|
||||
epilog="""
|
||||
Examples:
|
||||
SuperClaude install # Interactive installation
|
||||
SuperClaude install --quick --dry-run # Quick installation (dry-run)
|
||||
SuperClaude install --profile developer # Developer profile
|
||||
SuperClaude install --dry-run # Dry-run mode
|
||||
SuperClaude install --components core mcp # Specific components
|
||||
SuperClaude install --verbose --force # Verbose with force mode
|
||||
""",
|
||||
@@ -50,23 +49,6 @@ Examples:
|
||||
)
|
||||
|
||||
# Installation mode options
|
||||
parser.add_argument(
|
||||
"--quick",
|
||||
action="store_true",
|
||||
help="Quick installation with pre-selected components"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--minimal",
|
||||
action="store_true",
|
||||
help="Minimal installation (core only)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--profile",
|
||||
type=str,
|
||||
help="Installation profile (quick, minimal, developer, etc.)"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"--components",
|
||||
@@ -141,31 +123,7 @@ def get_components_to_install(args: argparse.Namespace, registry: ComponentRegis
|
||||
return ["core", "commands", "agents", "modes", "mcp", "mcp_docs"]
|
||||
return args.components
|
||||
|
||||
# Profile-based selection
|
||||
if args.profile:
|
||||
try:
|
||||
profile_path = PROJECT_ROOT / "profiles" / f"{args.profile}.json"
|
||||
profile = config_manager.load_profile(profile_path)
|
||||
return profile["components"]
|
||||
except Exception as e:
|
||||
logger.error(f"Could not load profile '{args.profile}': {e}")
|
||||
return None
|
||||
|
||||
# Quick installation
|
||||
if args.quick:
|
||||
try:
|
||||
profile_path = PROJECT_ROOT / "profiles" / "quick.json"
|
||||
profile = config_manager.load_profile(profile_path)
|
||||
return profile["components"]
|
||||
except Exception as e:
|
||||
logger.warning(f"Could not load quick profile: {e}")
|
||||
return ["core"] # Fallback to core only
|
||||
|
||||
# Minimal installation
|
||||
if args.minimal:
|
||||
return ["core"]
|
||||
|
||||
# Interactive selection
|
||||
# Interactive two-stage selection
|
||||
return interactive_component_selection(registry, config_manager)
|
||||
|
||||
|
||||
@@ -299,43 +257,21 @@ def interactive_component_selection(registry: ComponentRegistry, config_manager:
|
||||
logger = get_logger()
|
||||
|
||||
try:
|
||||
# Add preset options first
|
||||
preset_options = [
|
||||
"Quick Installation (recommended components)",
|
||||
"Minimal Installation (core only)",
|
||||
"Custom Two-Stage Selection"
|
||||
]
|
||||
print(f"\n{Colors.CYAN}SuperClaude Interactive Installation{Colors.RESET}")
|
||||
print(f"{Colors.BLUE}Select components to install using the two-stage process:{Colors.RESET}")
|
||||
|
||||
print(f"\n{Colors.CYAN}SuperClaude Installation Options:{Colors.RESET}")
|
||||
menu = Menu("Select installation type:", preset_options)
|
||||
choice = menu.display()
|
||||
# Stage 1: MCP Server Selection
|
||||
selected_mcp_servers = select_mcp_servers(registry)
|
||||
|
||||
if choice == -1: # Cancelled
|
||||
return None
|
||||
elif choice == 0: # Quick
|
||||
try:
|
||||
profile_path = PROJECT_ROOT / "profiles" / "quick.json"
|
||||
profile = config_manager.load_profile(profile_path)
|
||||
return profile["components"]
|
||||
except Exception:
|
||||
return ["core"]
|
||||
elif choice == 1: # Minimal
|
||||
return ["core"]
|
||||
elif choice == 2: # Custom Two-Stage
|
||||
# Stage 1: MCP Server Selection
|
||||
selected_mcp_servers = select_mcp_servers(registry)
|
||||
|
||||
# Stage 2: Framework Component Selection
|
||||
selected_components = select_framework_components(registry, config_manager, selected_mcp_servers)
|
||||
|
||||
# Store selected MCP servers for components to use
|
||||
if not hasattr(config_manager, '_installation_context'):
|
||||
config_manager._installation_context = {}
|
||||
config_manager._installation_context["selected_mcp_servers"] = selected_mcp_servers
|
||||
|
||||
return selected_components
|
||||
# Stage 2: Framework Component Selection
|
||||
selected_components = select_framework_components(registry, config_manager, selected_mcp_servers)
|
||||
|
||||
return None
|
||||
# Store selected MCP servers for components to use
|
||||
if not hasattr(config_manager, '_installation_context'):
|
||||
config_manager._installation_context = {}
|
||||
config_manager._installation_context["selected_mcp_servers"] = selected_mcp_servers
|
||||
|
||||
return selected_components
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in component selection: {e}")
|
||||
|
||||
Reference in New Issue
Block a user