// Always use try/catch for async operationsasync function processComponent(name) { try { const component = await fetchComponent(name); const result = await installComponent(component); return result; } catch (error) { // Log with context console.error(`Failed to process component ${name}:`, error); // Provide helpful error message throw new Error(`Component installation failed: ${error.message}`); }}// Validate input parametersfunction installAgent(name) { if (!name || typeof name !== 'string') { throw new TypeError('Agent name must be a non-empty string'); } if (name.includes('/')) { throw new Error('Agent name cannot contain slashes'); } // Proceed with installation}// Use fallback mechanismsfunction getConfig() { try { return JSON.parse(fs.readFileSync('config.json', 'utf8')); } catch (error) { console.warn('Config file not found, using defaults'); return DEFAULT_CONFIG; }}
# Use type hintsdef process_component(name: str, category: str) -> dict: """Process a component and return metadata.""" return {'name': name, 'category': category}# Use f-strings for formattingmessage = f"Processing {component_name} in {category}"path = f"{base_dir}/{file_name}"# Use list comprehensionsnames = [agent['name'] for agent in agents]active_users = [u for u in users if u.is_active]# Use context managerswith open('file.txt', 'r') as f: content = f.read()# Use pathlib for pathsfrom pathlib import Pathbase_dir = Path('cli-tool/components')agent_file = base_dir / 'agents' / 'development-team' / 'frontend-developer.md'
# Use specific exception typestry: component = load_component(name)except FileNotFoundError: print(f"Component {name} not found") return Noneexcept json.JSONDecodeError as e: print(f"Invalid JSON in component: {e}") return Noneexcept Exception as e: print(f"Unexpected error: {e}") raise# Provide context in error messagesif not component_name: raise ValueError("Component name cannot be empty")if '/' in component_name: raise ValueError(f"Invalid component name: {component_name}")
/** * Install a component to the user's project. * * @param {string} componentType - Type of component (agent, command, hook, etc.) * @param {string} componentName - Name of the component to install * @param {Object} options - Installation options * @param {boolean} options.dryRun - If true, don't actually install * @param {boolean} options.force - If true, overwrite existing files * @returns {Promise<Object>} Installation result with status and files created * @throws {Error} If component not found or installation fails */async function installComponent(componentType, componentName, options = {}) { // Implementation}
def generate_component_catalog(component_dir: str, output_file: str) -> dict: """ Generate a JSON catalog of all components. Scans the component directory for agents, commands, hooks, etc. and generates a comprehensive JSON catalog with metadata and content. Args: component_dir: Path to the cli-tool/components directory output_file: Path where the catalog JSON should be written Returns: Dictionary with component counts by type Raises: FileNotFoundError: If component directory doesn't exist ValueError: If output path is invalid """ # Implementation
# Use conventional commits formatfeat: Add new security-auditor agentfix: Correct path handling in Windowsdocs: Update contributing guidelineschore: Bump version to 1.28.17refactor: Simplify hook installation logictest: Add tests for component validation# Provide context in commit bodygit commit -m "feat: Add PostgreSQL MCP integration" -m "Adds Model Context Protocol server for PostgreSQL database access. Includes connection pooling and query execution support."