561 lines
21 KiB
Markdown
561 lines
21 KiB
Markdown
# BMAD Boot Loader
|
|
|
|
## Intelligent System Initialization for Claude Code
|
|
|
|
The BMAD Boot Loader provides intelligent initialization of the BMAD system within Claude Code, automatically analyzing project context and configuring optimal personas and workflows.
|
|
|
|
### Boot Sequence for Claude Code Integration
|
|
|
|
#### Intelligent Boot Process
|
|
```yaml
|
|
boot_sequence:
|
|
1_environment_detection:
|
|
claude_code_integration:
|
|
- detect_claude_code_session: "Identify active Claude Code environment"
|
|
- assess_tool_availability: "Check available tools and capabilities"
|
|
- load_compatibility_layer: "Initialize Claude Code tool adapters"
|
|
- establish_session_context: "Set up session tracking"
|
|
|
|
project_analysis:
|
|
- scan_project_structure: "Use LS and Glob to understand project layout"
|
|
- identify_tech_stack: "Detect technologies via file patterns and configs"
|
|
- detect_project_type: "Classify as web-app, api, mobile, library, etc."
|
|
- assess_complexity: "Evaluate project size and complexity factors"
|
|
|
|
2_context_restoration:
|
|
memory_integration:
|
|
- load_project_memory: "Restore previous session memory"
|
|
- restore_last_session: "Continue where last session ended"
|
|
- reconstruct_context: "Rebuild project state from memory"
|
|
- sync_with_git_state: "Align memory with current git status"
|
|
|
|
3_persona_initialization:
|
|
intelligent_selection:
|
|
- determine_required_personas: "Select optimal personas for project type"
|
|
- load_persona_definitions: "Load persona files and configurations"
|
|
- apply_customizations: "Apply project-specific persona adjustments"
|
|
- establish_communication: "Set up inter-persona messaging"
|
|
|
|
4_rule_loading:
|
|
dynamic_rule_system:
|
|
- load_core_rules: "Load universal BMAD rules"
|
|
- load_context_rules: "Load technology and domain-specific rules"
|
|
- load_project_rules: "Load custom project-generated rules"
|
|
- validate_rule_compatibility: "Ensure rules work together"
|
|
|
|
5_tool_integration:
|
|
claude_code_optimization:
|
|
- configure_tool_preferences: "Set optimal tool usage patterns"
|
|
- establish_tool_monitoring: "Set up tool usage tracking"
|
|
- create_workflow_shortcuts: "Define efficient tool sequences"
|
|
- initialize_error_prevention: "Activate error prevention monitoring"
|
|
|
|
6_system_validation:
|
|
comprehensive_checks:
|
|
- verify_all_components: "Ensure all systems operational"
|
|
- test_communication: "Validate inter-persona messaging"
|
|
- confirm_memory_access: "Verify memory system functionality"
|
|
- report_boot_status: "Provide detailed boot completion report"
|
|
```
|
|
|
|
### Boot Configuration and Intelligence
|
|
|
|
#### Smart Project Detection
|
|
```python
|
|
async def intelligent_project_analysis():
|
|
"""
|
|
Analyze project using Claude Code tools to determine optimal configuration
|
|
"""
|
|
project_analysis = {
|
|
'structure': {},
|
|
'technology': {},
|
|
'complexity': {},
|
|
'recommendations': {}
|
|
}
|
|
|
|
# Use LS to analyze project structure
|
|
root_files = await claude_code_ls("/")
|
|
project_analysis['structure'] = {
|
|
'root_files': root_files,
|
|
'has_src_dir': 'src' in [f.name for f in root_files.files],
|
|
'has_docs_dir': 'docs' in [f.name for f in root_files.files],
|
|
'has_tests_dir': any('test' in f.name.lower() for f in root_files.files)
|
|
}
|
|
|
|
# Use Glob to detect technology indicators
|
|
tech_indicators = await detect_technology_stack()
|
|
project_analysis['technology'] = tech_indicators
|
|
|
|
# Use Read to analyze key configuration files
|
|
config_analysis = await analyze_configuration_files(tech_indicators)
|
|
project_analysis['configuration'] = config_analysis
|
|
|
|
# Assess project complexity
|
|
complexity_metrics = await assess_project_complexity(
|
|
project_analysis['structure'],
|
|
tech_indicators
|
|
)
|
|
project_analysis['complexity'] = complexity_metrics
|
|
|
|
# Generate boot recommendations
|
|
boot_recommendations = generate_boot_recommendations(project_analysis)
|
|
project_analysis['recommendations'] = boot_recommendations
|
|
|
|
return project_analysis
|
|
|
|
async def detect_technology_stack():
|
|
"""
|
|
Detect technology stack using Claude Code tools
|
|
"""
|
|
tech_stack = {
|
|
'primary_language': None,
|
|
'frameworks': [],
|
|
'tools': [],
|
|
'databases': [],
|
|
'deployment': []
|
|
}
|
|
|
|
# Language detection through file patterns
|
|
language_patterns = {
|
|
'javascript': await claude_code_glob("**/*.{js,jsx,mjs}"),
|
|
'typescript': await claude_code_glob("**/*.{ts,tsx}"),
|
|
'python': await claude_code_glob("**/*.py"),
|
|
'java': await claude_code_glob("**/*.java"),
|
|
'go': await claude_code_glob("**/*.go"),
|
|
'rust': await claude_code_glob("**/*.rs"),
|
|
'ruby': await claude_code_glob("**/*.rb")
|
|
}
|
|
|
|
# Determine primary language
|
|
language_counts = {lang: len(files) for lang, files in language_patterns.items()}
|
|
tech_stack['primary_language'] = max(language_counts, key=language_counts.get)
|
|
|
|
# Framework detection through package files
|
|
if tech_stack['primary_language'] in ['javascript', 'typescript']:
|
|
package_json = await try_read_file('package.json')
|
|
if package_json:
|
|
frameworks = detect_js_frameworks(package_json)
|
|
tech_stack['frameworks'].extend(frameworks)
|
|
|
|
elif tech_stack['primary_language'] == 'python':
|
|
requirements = await try_read_file('requirements.txt')
|
|
pyproject = await try_read_file('pyproject.toml')
|
|
if requirements or pyproject:
|
|
frameworks = detect_python_frameworks(requirements, pyproject)
|
|
tech_stack['frameworks'].extend(frameworks)
|
|
|
|
# Infrastructure detection
|
|
infra_indicators = {
|
|
'docker': await file_exists('Dockerfile'),
|
|
'kubernetes': await claude_code_glob("**/*.{yaml,yml}") and await claude_code_grep("apiVersion"),
|
|
'terraform': await claude_code_glob("**/*.tf"),
|
|
'github_actions': await file_exists('.github/workflows'),
|
|
'jenkins': await file_exists('Jenkinsfile')
|
|
}
|
|
|
|
tech_stack['deployment'] = [tool for tool, exists in infra_indicators.items() if exists]
|
|
|
|
return tech_stack
|
|
|
|
async def generate_boot_recommendations(project_analysis):
|
|
"""
|
|
Generate intelligent boot recommendations based on project analysis
|
|
"""
|
|
recommendations = {
|
|
'personas': [],
|
|
'workflows': [],
|
|
'tools': [],
|
|
'priorities': []
|
|
}
|
|
|
|
# Persona recommendations based on project type
|
|
if project_analysis['technology']['primary_language'] in ['javascript', 'typescript']:
|
|
if 'react' in project_analysis['technology']['frameworks']:
|
|
recommendations['personas'].extend(['design-architect', 'frontend-dev'])
|
|
if 'express' in project_analysis['technology']['frameworks']:
|
|
recommendations['personas'].extend(['architect', 'security'])
|
|
|
|
# Always recommend core personas
|
|
recommendations['personas'].extend(['analyst', 'pm', 'qa'])
|
|
|
|
# Infrastructure personas based on deployment indicators
|
|
if project_analysis['technology']['deployment']:
|
|
recommendations['personas'].append('platform-engineer')
|
|
|
|
# Workflow recommendations based on project phase
|
|
if project_analysis['structure']['has_tests_dir']:
|
|
recommendations['workflows'].append('test-driven-development')
|
|
if '.github' in project_analysis['structure']['root_files']:
|
|
recommendations['workflows'].append('ci-cd-integration')
|
|
|
|
# Tool preferences based on complexity
|
|
if project_analysis['complexity']['level'] == 'high':
|
|
recommendations['tools'].extend(['pattern-intelligence', 'error-prevention'])
|
|
|
|
# Priority recommendations
|
|
if project_analysis['complexity']['security_sensitive']:
|
|
recommendations['priorities'].append('security-first')
|
|
if project_analysis['complexity']['performance_critical']:
|
|
recommendations['priorities'].append('performance-optimization')
|
|
|
|
return recommendations
|
|
```
|
|
|
|
#### Context-Aware Boot Configuration
|
|
```yaml
|
|
boot_config:
|
|
auto_detect_scenarios:
|
|
new_project_setup:
|
|
indicators:
|
|
- empty_or_minimal_directory: true
|
|
- no_git_history: true
|
|
- basic_file_structure: true
|
|
boot_mode: "project_initialization"
|
|
recommended_personas: ["analyst", "pm", "architect"]
|
|
initial_workflow: "discovery_and_planning"
|
|
|
|
existing_project_continuation:
|
|
indicators:
|
|
- established_codebase: true
|
|
- git_history_present: true
|
|
- previous_bmad_memory: true
|
|
boot_mode: "session_restoration"
|
|
recommended_personas: "based_on_memory"
|
|
initial_workflow: "continue_previous_session"
|
|
|
|
legacy_project_adoption:
|
|
indicators:
|
|
- large_existing_codebase: true
|
|
- no_previous_bmad_memory: true
|
|
- complex_structure: true
|
|
boot_mode: "legacy_analysis"
|
|
recommended_personas: ["analyst", "architect", "qa"]
|
|
initial_workflow: "comprehensive_analysis"
|
|
|
|
emergency_debugging:
|
|
indicators:
|
|
- error_logs_present: true
|
|
- failing_tests: true
|
|
- recent_deployment_issues: true
|
|
boot_mode: "emergency_response"
|
|
recommended_personas: ["architect", "security", "qa", "platform-engineer"]
|
|
initial_workflow: "incident_response"
|
|
|
|
initialization_options:
|
|
minimal_boot:
|
|
description: "Essential functionality only"
|
|
personas: ["core_orchestrator"]
|
|
memory: "session_only"
|
|
rules: "core_rules_only"
|
|
tools: "basic_claude_code_tools"
|
|
use_case: "Quick tasks or limited scope work"
|
|
|
|
standard_boot:
|
|
description: "Recommended default configuration"
|
|
personas: "auto_detected_based_on_project"
|
|
memory: "full_project_memory"
|
|
rules: "context_appropriate_rules"
|
|
tools: "full_claude_code_integration"
|
|
use_case: "Normal development work"
|
|
|
|
full_boot:
|
|
description: "Maximum capabilities enabled"
|
|
personas: "all_available_personas"
|
|
memory: "full_memory_with_cross_project_learning"
|
|
rules: "all_rule_sets_with_learning"
|
|
tools: "advanced_claude_code_features"
|
|
use_case: "Complex projects or learning mode"
|
|
|
|
custom_boot:
|
|
description: "User-defined configuration"
|
|
personas: "user_specified_list"
|
|
memory: "configurable_scope"
|
|
rules: "selected_rule_sets"
|
|
tools: "custom_tool_preferences"
|
|
use_case: "Specialized workflows or team preferences"
|
|
```
|
|
|
|
### Boot Process Implementation
|
|
|
|
#### Intelligent Boot Execution
|
|
```python
|
|
async def execute_intelligent_boot(boot_mode='auto'):
|
|
"""
|
|
Execute intelligent boot process with Claude Code integration
|
|
"""
|
|
boot_session = {
|
|
'session_id': generate_uuid(),
|
|
'start_time': datetime.utcnow(),
|
|
'boot_mode': boot_mode,
|
|
'steps_completed': [],
|
|
'errors': [],
|
|
'warnings': []
|
|
}
|
|
|
|
try:
|
|
# Step 1: Environment Detection
|
|
boot_session['steps_completed'].append('environment_detection')
|
|
environment_context = await detect_claude_code_environment()
|
|
|
|
# Step 2: Project Analysis
|
|
boot_session['steps_completed'].append('project_analysis')
|
|
project_analysis = await intelligent_project_analysis()
|
|
|
|
# Step 3: Boot Mode Determination
|
|
if boot_mode == 'auto':
|
|
boot_mode = determine_optimal_boot_mode(
|
|
environment_context,
|
|
project_analysis
|
|
)
|
|
|
|
boot_session['determined_boot_mode'] = boot_mode
|
|
|
|
# Step 4: Memory Restoration
|
|
boot_session['steps_completed'].append('memory_restoration')
|
|
memory_context = await restore_project_memory(project_analysis)
|
|
|
|
# Step 5: Persona Initialization
|
|
boot_session['steps_completed'].append('persona_initialization')
|
|
persona_config = await initialize_optimal_personas(
|
|
project_analysis,
|
|
memory_context,
|
|
boot_mode
|
|
)
|
|
|
|
# Step 6: Rule System Loading
|
|
boot_session['steps_completed'].append('rule_loading')
|
|
rule_system = await load_dynamic_rule_system(
|
|
project_analysis,
|
|
persona_config,
|
|
memory_context
|
|
)
|
|
|
|
# Step 7: Claude Code Integration
|
|
boot_session['steps_completed'].append('claude_code_integration')
|
|
tool_integration = await setup_claude_code_integration(
|
|
environment_context,
|
|
persona_config,
|
|
rule_system
|
|
)
|
|
|
|
# Step 8: System Validation
|
|
boot_session['steps_completed'].append('system_validation')
|
|
validation_results = await validate_boot_completion(
|
|
environment_context,
|
|
project_analysis,
|
|
persona_config,
|
|
rule_system,
|
|
tool_integration
|
|
)
|
|
|
|
boot_duration = (datetime.utcnow() - boot_session['start_time']).total_seconds()
|
|
|
|
boot_completion_report = {
|
|
'status': 'success',
|
|
'boot_session': boot_session,
|
|
'boot_duration': boot_duration,
|
|
'environment_context': environment_context,
|
|
'project_analysis': project_analysis,
|
|
'active_personas': persona_config['active_personas'],
|
|
'loaded_rules': rule_system['active_rules'],
|
|
'claude_code_integration': tool_integration,
|
|
'validation_results': validation_results,
|
|
'recommendations': generate_post_boot_recommendations(
|
|
project_analysis,
|
|
persona_config,
|
|
validation_results
|
|
)
|
|
}
|
|
|
|
# Store boot session for future reference
|
|
await store_boot_session(boot_completion_report)
|
|
|
|
return boot_completion_report
|
|
|
|
except Exception as e:
|
|
boot_session['errors'].append({
|
|
'error': str(e),
|
|
'step': boot_session['steps_completed'][-1] if boot_session['steps_completed'] else 'initialization',
|
|
'timestamp': datetime.utcnow()
|
|
})
|
|
|
|
# Attempt graceful degradation
|
|
degraded_boot = await attempt_graceful_degradation(boot_session, str(e))
|
|
|
|
return {
|
|
'status': 'degraded',
|
|
'boot_session': boot_session,
|
|
'degraded_configuration': degraded_boot,
|
|
'error_details': str(e)
|
|
}
|
|
|
|
async def initialize_optimal_personas(project_analysis, memory_context, boot_mode):
|
|
"""
|
|
Initialize the optimal set of personas based on project context
|
|
"""
|
|
persona_config = {
|
|
'active_personas': [],
|
|
'persona_customizations': {},
|
|
'communication_channels': {},
|
|
'collaboration_patterns': {}
|
|
}
|
|
|
|
# Get base persona recommendations
|
|
base_personas = project_analysis['recommendations']['personas']
|
|
|
|
# Enhance with memory-based insights
|
|
if memory_context.has_previous_sessions:
|
|
memory_personas = extract_successful_personas_from_memory(memory_context)
|
|
base_personas.extend(memory_personas)
|
|
|
|
# Remove duplicates and prioritize
|
|
prioritized_personas = prioritize_personas(base_personas, project_analysis, boot_mode)
|
|
|
|
# Initialize each persona
|
|
for persona_name in prioritized_personas:
|
|
try:
|
|
# Load persona definition
|
|
persona_definition = await load_persona_definition(persona_name)
|
|
|
|
# Apply project-specific customizations
|
|
customized_persona = await customize_persona_for_project(
|
|
persona_definition,
|
|
project_analysis,
|
|
memory_context
|
|
)
|
|
|
|
# Initialize persona with Claude Code context
|
|
initialized_persona = await initialize_persona_with_claude_context(
|
|
customized_persona,
|
|
project_analysis['technology']
|
|
)
|
|
|
|
persona_config['active_personas'].append(initialized_persona)
|
|
persona_config['persona_customizations'][persona_name] = customized_persona
|
|
|
|
except Exception as e:
|
|
# Log persona initialization failure but continue
|
|
persona_config['failed_personas'] = persona_config.get('failed_personas', [])
|
|
persona_config['failed_personas'].append({
|
|
'persona': persona_name,
|
|
'error': str(e)
|
|
})
|
|
|
|
# Establish inter-persona communication
|
|
persona_config['communication_channels'] = await setup_persona_communication(
|
|
persona_config['active_personas']
|
|
)
|
|
|
|
# Define collaboration patterns
|
|
persona_config['collaboration_patterns'] = await define_collaboration_patterns(
|
|
persona_config['active_personas'],
|
|
project_analysis
|
|
)
|
|
|
|
return persona_config
|
|
```
|
|
|
|
### Boot Optimization and Learning
|
|
|
|
#### Adaptive Boot Configuration
|
|
```python
|
|
async def learn_from_boot_outcomes():
|
|
"""
|
|
Learn from boot session outcomes to improve future boot processes
|
|
"""
|
|
# Analyze recent boot sessions
|
|
recent_boots = await get_recent_boot_sessions(limit=10)
|
|
|
|
boot_analysis = {
|
|
'success_patterns': [],
|
|
'failure_patterns': [],
|
|
'optimization_opportunities': [],
|
|
'configuration_improvements': []
|
|
}
|
|
|
|
for boot_session in recent_boots:
|
|
if boot_session['status'] == 'success':
|
|
success_pattern = extract_success_pattern(boot_session)
|
|
boot_analysis['success_patterns'].append(success_pattern)
|
|
else:
|
|
failure_pattern = extract_failure_pattern(boot_session)
|
|
boot_analysis['failure_patterns'].append(failure_pattern)
|
|
|
|
# Identify optimization opportunities
|
|
optimization_opportunities = identify_boot_optimizations(
|
|
boot_analysis['success_patterns'],
|
|
boot_analysis['failure_patterns']
|
|
)
|
|
boot_analysis['optimization_opportunities'] = optimization_opportunities
|
|
|
|
# Generate configuration improvements
|
|
config_improvements = generate_boot_config_improvements(boot_analysis)
|
|
boot_analysis['configuration_improvements'] = config_improvements
|
|
|
|
# Apply learnings to boot system
|
|
await apply_boot_learnings(boot_analysis)
|
|
|
|
return boot_analysis
|
|
|
|
async def optimize_boot_performance():
|
|
"""
|
|
Optimize boot performance based on usage patterns
|
|
"""
|
|
performance_analysis = await analyze_boot_performance()
|
|
|
|
optimizations = {
|
|
'caching_strategies': [],
|
|
'parallel_loading': [],
|
|
'lazy_initialization': [],
|
|
'preloading_opportunities': []
|
|
}
|
|
|
|
# Identify caching opportunities
|
|
if performance_analysis.persona_loading_time > 2.0: # seconds
|
|
optimizations['caching_strategies'].append({
|
|
'target': 'persona_definitions',
|
|
'strategy': 'in_memory_cache',
|
|
'expected_improvement': '60% faster persona loading'
|
|
})
|
|
|
|
# Identify parallel loading opportunities
|
|
if performance_analysis.sequential_operations > 3:
|
|
optimizations['parallel_loading'].append({
|
|
'target': 'independent_operations',
|
|
'strategy': 'asyncio_gather',
|
|
'expected_improvement': '40% faster overall boot'
|
|
})
|
|
|
|
# Implement optimizations
|
|
for optimization_category, optimizations_list in optimizations.items():
|
|
for optimization in optimizations_list:
|
|
await implement_boot_optimization(optimization)
|
|
|
|
return optimizations
|
|
```
|
|
|
|
### Claude Code Integration Commands
|
|
|
|
```bash
|
|
# Boot system commands
|
|
bmad boot --auto --analyze-project
|
|
bmad boot --mode "standard" --personas "architect,security,qa"
|
|
bmad boot --minimal --quick-start
|
|
|
|
# Boot configuration and customization
|
|
bmad boot config --show-current
|
|
bmad boot config --set-default "personas=architect,dev,qa"
|
|
bmad boot config --optimize-for "performance"
|
|
|
|
# Boot analysis and optimization
|
|
bmad boot analyze --performance --show-bottlenecks
|
|
bmad boot optimize --based-on-usage --last-30-days
|
|
bmad boot learn --from-recent-sessions --improve-recommendations
|
|
|
|
# Boot status and diagnostics
|
|
bmad boot status --detailed --show-active-personas
|
|
bmad boot validate --check-all-components
|
|
bmad boot report --session-summary --with-recommendations
|
|
```
|
|
|
|
This BMAD Boot Loader transforms Claude Code startup into an intelligent initialization process that automatically configures optimal development environments based on project characteristics, previous experience, and current context, ensuring users get the most relevant AI assistance from the moment they start working. |