scripts-activate-project-components
#!/usr/bin/env python3 """
title: "Get script directory for path resolution (works from any cwd)" component_type: script version: "1.0.0" audience: contributor status: stable summary: "Activate Project-Specific Components" keywords: ['activate', 'api', 'backend', 'components', 'database'] tokens: ~500 created: 2025-12-22 updated: 2025-12-22 script_name: "activate-project-components.py" language: python executable: true usage: "python3 scripts/activate-project-components.py [options]" python_version: "3.10+" dependencies: [] modifies_files: false network_access: false requires_auth: false
Activate Project-Specific Components
Intelligently activates components based on detected project type. Enables context-aware component activation for multi-session workflows.
Part of Phase 5.2: Session Initialization Created: 2025-11-29 """
import argparse import json from pathlib import Path from typing import Dict, List, Set, Any
Get script directory for path resolution (works from any cwd)
SCRIPT_DIR = Path(file).resolve().parent CORE_ROOT = SCRIPT_DIR.parent
Project type detection patterns
PROJECT_PATTERNS = { 'web_frontend': { 'indicators': ['package.json', 'src/App.tsx', 'src/App.jsx', 'vite.config.ts'], 'components': { 'agent': ['frontend-react-typescript-expert', 'generative-ui-architect'], 'command': ['ui', 'motion'], 'skill': [] } }, 'backend_api': { 'indicators': ['Cargo.toml', 'src/main.rs', 'actix-web', 'api/', 'backend/'], 'components': { 'agent': ['rust-expert-developer', 'actix-web-specialist', 'database-architect'], 'command': [], 'skill': ['rust-backend-patterns'] } }, 'documentation': { 'indicators': ['docs/', 'README.md', 'CLAUDE.md', 'ADR-', '.md'], 'components': { 'agent': ['codi-documentation-writer', 'documentation-librarian'], 'command': ['document'], 'skill': ['documentation-librarian'] } }, 'infrastructure': { 'indicators': ['Dockerfile', 'kubernetes/', 'terraform/', '.github/workflows'], 'components': { 'agent': ['devops-engineer', 'cloud-architect', 'k8s-statefulset-specialist'], 'command': [], 'skill': [] } }, 'framework_development': { 'indicators': ['.coditect/', 'agents/', 'skills/', 'commands/'], 'components': { 'agent': ['orchestrator', 'codebase-analyzer', 'documentation-librarian'], 'command': [], 'skill': ['framework-patterns'] } } }
def detect_project_type() -> Set[str]: """ Detect project type(s) based on filesystem indicators
Returns:
Set of detected project types
"""
detected_types = set()
cwd = Path.cwd()
for project_type, config in PROJECT_PATTERNS.items():
indicators = config['indicators']
# Check if any indicator patterns match
for indicator in indicators:
# Direct file check
if Path(indicator).exists():
detected_types.add(project_type)
break
# Pattern check (for directories)
if '/' in indicator:
dir_name = indicator.rstrip('/')
if Path(dir_name).is_dir():
detected_types.add(project_type)
break
# Glob pattern check (for file extensions)
if indicator.startswith('.'):
if list(cwd.rglob(f"*{indicator}")):
detected_types.add(project_type)
break
# Default to framework_development if in CODITECT structure
if not detected_types and (Path('.coditect').exists() or Path('.claude').exists()):
detected_types.add('framework_development')
return detected_types
def get_components_for_project_types(project_types: Set[str]) -> Dict[str, Set[str]]: """ Get all components needed for detected project types
Returns:
Dict of component_type -> set of component names
"""
components_needed = {
'agent': set(),
'command': set(),
'skill': set()
}
for project_type in project_types:
if project_type in PROJECT_PATTERNS:
config = PROJECT_PATTERNS[project_type]
for comp_type, comp_names in config['components'].items():
components_needed[comp_type].update(comp_names)
return components_needed
def load_activation_status() -> Dict[str, Any]: """Load current activation status""" status_file = CORE_ROOT / '.coditect' / 'component-activation-status.json'
if not status_file.exists():
print("❌ Error: component-activation-status.json not found")
print(" Run: python3 scripts/generate-activation-status.py")
return {}
with open(status_file, 'r') as f:
return json.load(f)
def is_component_activated(component_type: str, component_name: str, status: Dict[str, Any]) -> bool: """Check if component is already activated""" for component in status.get('components', []): if (component.get('type') == component_type and component.get('name') == component_name): return component.get('activated', False)
return False
def parse_args(): """Parse command line arguments""" parser = argparse.ArgumentParser( description='Detect project type and recommend/activate relevant CODITECT components.', formatter_class=argparse.RawDescriptionHelpFormatter, epilog=''' Examples: %(prog)s # Detect project type and show recommendations %(prog)s --auto-activate # Automatically activate recommended components %(prog)s --list-types # List all supported project types %(prog)s --type backend_api # Force specific project type
Supported project types:
- web_frontend : React/Vue/Angular frontend projects
- backend_api : Rust/Python API backends
- documentation : Documentation-focused projects
- infrastructure : Docker/Kubernetes/Terraform projects
- framework_development : CODITECT framework development
Part of CODITECT Phase 5.2: Session Initialization ''' ) parser.add_argument('--auto-activate', action='store_true', help='Automatically activate recommended components') parser.add_argument('--list-types', action='store_true', help='List all supported project types and their components') parser.add_argument('--type', type=str, choices=list(PROJECT_PATTERNS.keys()), help='Force specific project type instead of auto-detection') parser.add_argument('--json', action='store_true', help='Output results as JSON') return parser.parse_args()
def main(): """Main entry point""" args = parse_args()
# Handle --list-types
if args.list_types:
print("Supported Project Types:\n")
for ptype, config in PROJECT_PATTERNS.items():
print(f" {ptype}:")
print(f" Indicators: {', '.join(config['indicators'][:3])}")
print(f" Agents: {', '.join(config['components']['agent'][:3])}")
print()
return
# Detect project types
project_types = {args.type} if args.type else detect_project_type()
if not project_types:
print("📊 Project type: Unknown (no specific components activated)")
return
print(f"📊 Detected project type(s): {', '.join(sorted(project_types))}")
# Get components needed
components_needed = get_components_for_project_types(project_types)
# Load current activation status
status = load_activation_status()
if not status:
return
# Check which components need activation
to_activate = []
already_activated = []
for comp_type, comp_names in components_needed.items():
for comp_name in comp_names:
if is_component_activated(comp_type, comp_name, status):
already_activated.append(f"{comp_type}/{comp_name}")
else:
to_activate.append(f"{comp_type}/{comp_name}")
# Report activation status
if already_activated:
print(f"✅ Already activated: {len(already_activated)} components")
if to_activate:
print(f"💡 Recommended for activation: {len(to_activate)} components")
print()
print(" To activate, run:")
for component_ref in to_activate[:5]: # Show first 5
comp_type, comp_name = component_ref.split('/')
print(f" python3 scripts/update-component-activation.py activate {comp_type} {comp_name}")
if len(to_activate) > 5:
print(f" ... and {len(to_activate) - 5} more")
else:
print(f"✅ All project-specific components activated")
if name == 'main': main()