UNPKG

agent-rules-generator

Version:

Interactive CLI tool to generate .agent.md and .windsurfrules files for AI-assisted development

639 lines (508 loc) โ€ข 24.7 kB
โ˜• Support This Work Found value in these resources? ๐Ÿ‘‰ Buy me a coffee: https://www.buymeacoffee.com/ubuntupunk If you find value in this project, please consider buying me a coffee to support my work. That will help me maintain and improve the resources available for free # Agent Rules Generator An interactive CLI tool to generate `.agent.md`, `.windsurfrules`, and modern `.cursor/rules/` (MDC) files for AI-assisted development with Cursor AI, Windsurf, and Gemini CLI. ## ๐Ÿค Contributing We welcome contributions! Here's how you can help: - ๐Ÿ› **Report bugs** via [GitHub Issues](https://github.com/ubuntupunk/agent-rules-generator/issues) - ๐Ÿ’ก **Suggest features** or improvements - ๐Ÿ“ **Improve documentation** (README, guides, examples) - ๐Ÿงช **Add tests** for new functionality - ๐Ÿ”ง **Submit pull requests** with bug fixes or features - ๐Ÿณ **Create new recipes** for different tech stacks - ๐Ÿ“‹ **Add project types** for better inclusivity **Quick Start for Contributors:** ```bash git clone https://github.com/ubuntupunk/agent-rules-generator.git cd agent-rules-generator bun install bun test # Ensure all tests pass ``` See our [Testing Guide](docs/testing.md) and [Deployment Guide](docs/deployment.md) for detailed contribution guidelines. ## ๐Ÿš€ Features - **๐Ÿ†• Modern Cursor MDC Support**: Generate modular `.cursor/rules/*.mdc` files for enhanced AI performance - **Interactive CLI**: Guided setup process for creating AI assistant configuration files - **Multiple AI Platforms**: Support for Cursor AI (`.agent.md` + `.cursor/rules/`), Windsurf (`.windsurfrules`), and Gemini CLI configuration - **Modular Rule Generation**: Choose from 5 specialized rule modules (coding, architecture, testing, deployment, security) - **Path-Scoped Rules**: Context-aware rules that apply to specific file patterns and directories - **Project Type Inclusivity**: Supports 6 project types with tailored question flows - **Recipe System**: Pre-built templates for common project types and technology stacks - **Conditional Tech Stack**: Only asks relevant questions based on your project type - **Enhanced Technology Support**: 20+ technology-specific guidelines and best practices - **Project Structure Analysis**: Automatically detects and configures based on your project setup - **Customizable Rules**: Define coding standards, workflow guidelines, and project-specific instructions - **Interactive Recipe Creator**: Create new recipes with guided prompts and auto-validation - **Recipe Validation**: Comprehensive validation system with auto-fix capabilities - **Gemini CLI Integration**: Configure Gemini CLI to use `.agent.md` as context file (local or global) - **Backward Compatibility**: Seamlessly supports both legacy and modern Cursor formats ## ๐Ÿค– Supported AI Platforms | Platform | Icon | File Type | Configuration | |----------|------|-----------|---------------| | **Cursor AI** | ๐Ÿ”ต | `.agent.md` | Comprehensive markdown rules file | | **Cursor AI (Modern)** | ๐Ÿ”ต | `.cursor/rules/*.mdc` | **NEW!** Modular Multi-Document Context files | | **Windsurf** | ๐ŸŒŠ | `.windsurfrules` | IDE-specific configuration file | | **Gemini CLI** | ๐Ÿ’Ž | `.gemini/settings.json` | Context file configuration | ### Platform-Specific Features - **Cursor AI (Legacy)**: Full project context, coding standards, and AI assistant instructions - **Cursor AI (Modern MDC)**: ๐Ÿ†• **Modular rules system** with specialized files: - `coding-standards.mdc` - Language & formatting rules with path scoping - `architecture.mdc` - Project structure & design patterns - `testing.mdc` - Testing guidelines & framework-specific rules - `deployment.mdc` - CI/CD & deployment best practices - `security.mdc` - Security guidelines & language-specific practices - **Windsurf**: IDE integration with project-specific rules and guidelines - **Gemini CLI**: Automatic configuration to use `.agent.md` as context file ## ๐Ÿ†• Modern Cursor MDC Format The **Multi-Document Context (MDC)** format represents the latest evolution in AI assistant configuration, offering superior performance and organization compared to traditional single-file approaches. ### **Why MDC is Better** - **๐ŸŽฏ Enhanced AI Performance**: Modular context provides better understanding - **๐Ÿ“ Organized Structure**: Separate concerns into focused rule files - **๐Ÿ” Path-Scoped Rules**: Apply rules only where relevant - **โšก Faster Processing**: AI can load only relevant context - **๐Ÿ”ง Easier Maintenance**: Update specific areas without affecting others ### **Generated Structure** ``` .cursor/ โ””โ”€โ”€ rules/ โ”œโ”€โ”€ coding-standards.mdc # Language & formatting rules โ”œโ”€โ”€ architecture.mdc # Project structure & patterns โ”œโ”€โ”€ testing.mdc # Testing guidelines โ”œโ”€โ”€ deployment.mdc # CI/CD & deployment (optional) โ””โ”€โ”€ security.mdc # Security practices (optional) ``` ### **Interactive Module Selection** When choosing the MDC format, you can select which modules to generate: - โœ… **Coding Standards** (recommended) - โœ… **Architecture Guidelines** (recommended) - โœ… **Testing Rules** (recommended) - โฌœ **Deployment & CI/CD** (optional) - โฌœ **Security Guidelines** (optional) ### **Path Scoping Example** ```markdown # coding-standards.mdc ## Language: TypeScript ### Path Scope Apply to: `src/**/*`, `lib/**/*` ### Formatting Rules - Use 2 spaces for indentation - Single quotes for strings - Semicolons required ``` ## ๐Ÿณ Recipe Creation & Validation ### **Interactive Recipe Creator** Create high-quality recipes with guided assistance: ```bash # Start the CLI and select "Create new recipe" agent-rules-generator # Or use validation commands npm run validate:remote # Validate remote recipes npm run validate:sample # Generate sample recipe node scripts/validate_recipes.js --help # See all options ``` #### **Creation Flow:** 1. **Basic Information** - Name, description, category with validation 2. **Technology Stack** - Guided setup, manual entry, or package.json import 3. **Optional Fields** - Author, version, tags with smart defaults 4. **Rules Generation** - Auto-generated templates or custom rules 5. **Validation & Review** - Real-time validation with auto-fixes 6. **Save & Integration** - Flexible saving with git integration #### **Smart Features:** - **Category-based suggestions** for languages and frameworks - **Package.json detection** for existing projects - **Template generation** based on technology stack - **Real-time validation** with 15+ quality checks - **Auto-fix functionality** for common issues - **Git integration** for automatic recipe tracking #### **Recipe Validation:** ```bash # Validate specific recipe file (JSON or YAML) node scripts/validate_recipes.js --file recipe.json node scripts/validate_recipes.js --file recipe.yaml # Validate with auto-fix node scripts/validate_recipes.js --file recipe.json --fix node scripts/validate_recipes.js --file recipe.yaml --fix # Validate all recipes in directory (supports mixed formats) node scripts/validate_recipes.js --dir ./recipes # Generate sample recipe templates node scripts/validate_recipes.js --sample > new_recipe.json node scripts/validate_recipes.js --sample | yaml-convert > new_recipe.yaml ``` #### **Supported File Formats:** - **JSON** (`.json`) - Traditional JSON format - **YAML** (`.yaml`, `.yml`) - Human-readable YAML format - **Mixed directories** - Validate both formats together - **Format conversion** - Built-in conversion between formats ## ๐Ÿ—๏ธ Architecture The Agent Rules Generator features a **modular architecture** designed for maintainability and extensibility: ### **Core Components** ``` agent-rules-generator/ โ”œโ”€โ”€ index.js # Main entry point โ”œโ”€โ”€ agent_rules_cli.js # Core CLI orchestrator โ”œโ”€โ”€ package.json # Project configuration โ”œโ”€โ”€ DEPLOY.md # Deployment instructions โ”œโ”€โ”€ CHANGELOG.md # Version history โ”œโ”€โ”€ lib/ # 13 specialized modules โ”‚ โ”œโ”€โ”€ cache_manager.js # Cache management operations โ”‚ โ”œโ”€โ”€ cleanup_utils.js # Cleanup and maintenance utilities โ”‚ โ”œโ”€โ”€ file_format_handler.js # JSON/YAML format processing โ”‚ โ”œโ”€โ”€ generator_lib.js # Template system and file generation โ”‚ โ”œโ”€โ”€ project_configurator.js # Project configuration collection โ”‚ โ”œโ”€โ”€ project_types.js # Project type logic and questions โ”‚ โ”œโ”€โ”€ recipe_creator.js # Recipe creation and validation โ”‚ โ”œโ”€โ”€ recipe_manager.js # Recipe selection and application โ”‚ โ”œโ”€โ”€ recipes_lib.js # Recipe system with GitHub integration โ”‚ โ”œโ”€โ”€ repository_manager.js # Repository settings and testing โ”‚ โ”œโ”€โ”€ tech_stack_collector.js # Technology stack collection โ”‚ โ”œโ”€โ”€ windsurf_manager.js # Windsurf integration and menu handling โ”‚ โ””โ”€โ”€ windsurf_scraper.js # Windsurf recipe scraping and caching โ”œโ”€โ”€ test/ # 13 test files (181 tests total) โ”‚ โ”œโ”€โ”€ deployment.test.js # Deployment workflow tests โ”‚ โ”œโ”€โ”€ file_format_handler.test.js # Format handling tests โ”‚ โ”œโ”€โ”€ project_types.test.js # Project type tests โ”‚ โ”œโ”€โ”€ recipe_creator.test.js # Recipe creation tests โ”‚ โ”œโ”€โ”€ recipe_download.test.js # Recipe download tests โ”‚ โ”œโ”€โ”€ recipe_validation.test.js # Recipe validation tests โ”‚ โ”œโ”€โ”€ scraper_integrate_test.js # Scraper integration tests โ”‚ โ”œโ”€โ”€ template_system.test.js # Template system tests โ”‚ โ”œโ”€โ”€ windsurf_customization_flow.test.js # Windsurf flow tests โ”‚ โ””โ”€โ”€ [4 additional test files] # Other specialized tests โ”œโ”€โ”€ docs/ # 13 documentation files โ”‚ โ”œโ”€โ”€ NOTIFICATIONS.md # Discord/Telegram setup guide โ”‚ โ”œโ”€โ”€ testing.md # Testing strategy and procedures โ”‚ โ”œโ”€โ”€ deployment.md # Deployment and CI/CD processes โ”‚ โ””โ”€โ”€ [10 additional docs] # Analysis and guides โ”œโ”€โ”€ scripts/ # 4 utility scripts โ”‚ โ”œโ”€โ”€ investigate_windsurf.js # Windsurf investigation tools โ”‚ โ”œโ”€โ”€ scrape_windsurf_rules.js # Windsurf scraping utilities โ”‚ โ”œโ”€โ”€ simple_windsurf_scraper.js # Simple scraper implementation โ”‚ โ””โ”€โ”€ validate_recipes.js # Recipe validation script โ”œโ”€โ”€ templates/ # Template files for generation โ”‚ โ””โ”€โ”€ agent-template.md # Base agent template โ”œโ”€โ”€ examples/ # Example files โ”‚ โ”œโ”€โ”€ sample_recipe.yaml # Sample recipe format โ”‚ โ””โ”€โ”€ sample_recipe_generated.yaml # Generated recipe example โ”œโ”€โ”€ windsurf_recipes/ # Cached Windsurf recipes โ”‚ โ””โ”€โ”€ recipes.json # Recipe cache file โ””โ”€โ”€ .github/ # GitHub Actions workflows โ””โ”€โ”€ workflows/ โ””โ”€โ”€ deploy.yml # Automated deployment pipeline ``` ### **Key Design Principles** - **Separation of Concerns**: Each module handles a specific functionality - **Dependency Injection**: Modules receive shared dependencies (inquirer, chalk, config) - **Clean Interfaces**: Consistent method signatures across modules - **Testability**: 99 tests with 100% pass rate - **Maintainability**: No module exceeds 300 lines ### **Refactoring Achievement** - โœ… **45% code reduction**: Main CLI reduced from 779 โ†’ 424 lines - โœ… **13 specialized modules** with clean separation of concerns - โœ… **100% functionality preserved** including the awesome startup screen - โœ… **All 181 tests passing** with comprehensive coverage - โœ… **Bug fixes completed**: Windsurf recipe customization flow fully functional ## ๐Ÿ“‹ Prerequisites ### For Normal Use - **Node.js** >= 14.0.0 ### For Development - **Node.js** >= 14.0.0 - **Bun** >= 1.0.0 (recommended for development) - **Git** (for contributing) ## ๐Ÿ› ๏ธ Installation ### For Normal Use (Recommended) Install globally to use the CLI commands anywhere: ```bash # Using npm (recommended) npm install -g agent-rules-generator # Using Bun (fast alternative) bun add -g agent-rules-generator # Using Yarn yarn global add agent-rules-generator # Using pnpm pnpm add -g agent-rules-generator ``` ### For Development/Contributing If you want to contribute to the project or run from source: ```bash # Clone the repository git clone https://github.com/ubuntupunk/agent-rules-generator.git cd agent-rules-generator # Install dependencies bun install # or npm install # Run from source node index.js # Run tests bun test # or npm test ``` ## ๐Ÿ‘จโ€๐Ÿ’ป Development Guide ### **Working with the Modular Architecture** The codebase is organized into specialized modules for easy development and maintenance: #### **Adding New Features** 1. **Identify the appropriate module** or create a new one if needed 2. **Follow the module pattern**: ```javascript class ModuleName { constructor(config) { this.config = config; } async methodName() { // Implementation } } module.exports = { ModuleName }; ``` 3. **Update the main CLI** to use your new module 4. **Add comprehensive tests** for your functionality #### **Module Responsibilities** - **recipe_manager.js**: Recipe selection, browsing, and application - **windsurf_manager.js**: Windsurf-specific functionality and menus - **tech_stack_collector.js**: Technology stack collection and customization - **project_configurator.js**: Project information and configuration collection - **cache_manager.js**: Cache operations and management - **repository_manager.js**: Remote repository configuration and testing #### **Testing Guidelines** ```bash # Run all tests (181 tests across 13 test files) bun test # Run specific test suite bun test test/template_system.test.js # Run recipe creation tests (34 tests) bun test test/recipe_creator.test.js # Run recipe validation tests (15 tests) bun test test/recipe_validation.test.js # Run Windsurf customization flow tests (9 tests) bun test test/windsurf_customization_flow.test.js # Test with verbose output bun test --verbose ``` #### **Test Coverage:** - **Recipe Creator**: 34 tests covering suggestions, detection, templates, validation - **Recipe Validation**: 15 tests covering validation rules, auto-fixes, edge cases - **Windsurf Integration**: 9 tests covering customization flow and bug fixes - **Template System**: 18 tests covering file generation and technology detection - **Deployment**: 33 tests covering package config and CI/CD validation #### **Recipe Management Scripts** ```bash # Validate recipes (supports JSON and YAML) npm run validate # Validate local/remote recipes npm run validate:remote # Validate remote GitHub recipes npm run validate:fix # Validate with auto-fix enabled npm run validate:sample # Generate sample recipe template # Format-specific validation examples node scripts/validate_recipes.js --file recipe.json node scripts/validate_recipes.js --file recipe.yaml node scripts/validate_recipes.js --dir ./recipes # Mixed formats ``` #### **Code Quality Standards** - **Keep modules under 300 lines** for maintainability - **Use dependency injection** for shared resources - **Follow consistent naming conventions** (camelCase for methods, PascalCase for classes) - **Add JSDoc comments** for public methods - **Include error handling** with user-friendly messages using chalk ## ๐Ÿš€ Quick Start 1. **Install globally**: ```bash npm install -g agent-rules-generator ``` 2. **Run the generator**: ```bash agent-rules-generator ``` or ```bash generate-agent-rules ``` 3. **Follow the interactive prompts** to configure your project 4. **Choose your output format**: - `.agent.md` for Cursor AI (Legacy) ๐Ÿ”ต - **๐Ÿ†• `.cursor/rules/` for Modern Cursor MDC** ๐Ÿ”ต - `.windsurfrules` for Windsurf ๐ŸŒŠ - Configure Gemini CLI ๐Ÿ’Ž The tool will create a comprehensive configuration file tailored to your project type and technology stack. ## ๐ŸŽฏ What It Does The Agent Rules Generator creates comprehensive configuration files that help AI assistants understand your project better. These files include: - **Project Overview**: Name, description, version, and type - **Technology Stack**: Conditional questions based on project type (no more irrelevant questions!) - **Coding Standards**: Style guides, linting rules, and conventions - **Project Structure**: Directory organization and file patterns - **Development Workflow**: Git workflow, branching strategy, and CI/CD processes - **Project Management**: Methodology, issue tracking, and documentation practices ## ๐Ÿ—๏ธ Supported Project Types The tool now supports **6 different project types** with tailored question flows: ### ๐ŸŒ **Web Applications** - Frontend frameworks (React, Vue, Angular, Svelte) - Backend frameworks (Express, FastAPI, Django, Spring Boot) - Databases (PostgreSQL, MongoDB, MySQL, SQLite) - Deployment platforms (Vercel, Netlify, AWS) ### โšก **CLI Tools** - CLI frameworks (Commander.js, Yargs, Inquirer.js) - Configuration formats (JSON, YAML, TOML) - Package managers (npm, yarn, pnpm, bun) - No irrelevant frontend/backend questions ### ๐Ÿ“š **Libraries/Packages** - Target environments (Node.js, Browser, Both) - Build systems (TypeScript, Rollup, Webpack) - Distribution formats (CommonJS, ESM, UMD) - Testing frameworks (Jest, Vitest, Mocha) ### ๐Ÿ“ฑ **Mobile Applications** - Platforms (iOS, Android, Cross-platform) - Frameworks (React Native, Flutter, Native) - State management (Redux, Zustand, Context API) - App store distribution ### ๐Ÿ–ฅ๏ธ **Desktop Applications** - Frameworks (Electron, Tauri, Native) - UI libraries (React, Vue, Svelte) - Platform targets (Windows, macOS, Linux) - Distribution methods ### ๐Ÿ”Œ **API/Backend Services** - Backend frameworks (Express, FastAPI, Django) - Databases and data storage - API documentation tools - Authentication methods ## ๐Ÿณ Recipes & Templates ### Recipe System The tool includes a sophisticated recipe system that fetches pre-built configurations from a remote GitHub repository. This allows for: - **Easy Updates**: Recipes are updated automatically - **Community Contributions**: Anyone can contribute new recipes - **Technology Coverage**: Recipes for all major tech stacks - **Project Type Specific**: Recipes tailored to each project type ### Available Recipes - React + TypeScript + Vite - Vue 3 + TypeScript + Vite - Node.js + Express + PostgreSQL - CLI Tool with Commander.js - React Native + Expo - Electron + React - And many more... ### Creating Custom Recipes You can contribute new recipes by: 1. Forking the [recipe repository](https://github.com/ubuntupunk/agent-rules-recipes) 2. Adding your recipe YAML file 3. Submitting a pull request ## ๐Ÿงช Development & Testing ### For Contributors ```bash # Clone and setup git clone https://github.com/ubuntupunk/agent-rules-generator.git cd agent-rules-generator bun install # Run tests bun test # All tests (90 tests) bun test test/recipe_download.test.js # Recipe system (17 tests) bun test test/template_system.test.js # Template system (18 tests) bun test test/deployment.test.js # Deployment (33 tests) bun test test/project_types.test.js # Project types (22 tests) # Run from source node index.js # Test deployment npm pack --dry-run ``` ### Project Structure ``` agent-rules-generator/ โ”œโ”€โ”€ index.js # Main CLI entry point โ”œโ”€โ”€ agent_rules_cli.js # Core CLI application โ”œโ”€โ”€ lib/ # Library modules โ”‚ โ”œโ”€โ”€ generator_lib.js # File generation logic โ”‚ โ”œโ”€โ”€ recipes_lib.js # Recipe management โ”‚ โ””โ”€โ”€ project_types.js # Project type logic โ”œโ”€โ”€ templates/ # Template files โ”œโ”€โ”€ test/ # Test suites (90 tests) โ”œโ”€โ”€ docs/ # Documentation โ”œโ”€โ”€ CHANGELOG.md # Version history โ””โ”€โ”€ README.md # This file ``` ## ๐Ÿ“š Documentation ### **Core Documentation** - **[DEPLOY.md](DEPLOY.md)** - Quick deployment instructions - **[NOTIFICATIONS.md](docs/NOTIFICATIONS.md)** - Discord/Telegram setup guide - **[Testing Guide](docs/testing.md)** - Comprehensive testing information (181 tests) - **[Deployment Guide](docs/deployment.md)** - CI/CD pipeline documentation - **[CHANGELOG.md](CHANGELOG.md)** - Version history and release notes ### **Additional Resources** (13 docs total) - Analysis documents for project types, recipes, and templates - Deployment analysis and strategy guides - Technical notes and implementation details ## ๐Ÿ”ง Configuration The CLI will guide you through configuring: ### Project Overview - Project name and description - Project type selection - Version and metadata ### Technology Stack (Conditional) - **Web Apps**: Frontend, backend, database - **CLI Tools**: CLI framework, config format - **Libraries**: Target environment, build system - **Mobile Apps**: Platform, framework, state management - **Desktop Apps**: Framework, UI library, platforms - **API/Backend**: Backend framework, database ### Coding Standards - Code style preferences - Naming conventions - Linting and formatting tools - Documentation requirements ### Project Structure - Directory organization - File naming patterns - Module structure ### Workflow Guidelines - Git workflow and branching - CI/CD processes - Deployment procedures - Code review practices ## ๐Ÿ“ Generated Files ### `.agent.md` (Cursor AI - Legacy) A comprehensive markdown file containing: - Project context and overview - Technology-specific guidelines - Coding standards and conventions - Development workflow rules - AI assistant instructions ### ๐Ÿ†• `.cursor/rules/*.mdc` (Modern Cursor MDC) **Multi-Document Context files** for enhanced AI performance: - **`coding-standards.mdc`** - Language & formatting rules with path scoping - **`architecture.mdc`** - Project structure & design patterns - **`testing.mdc`** - Testing guidelines & framework-specific rules - **`deployment.mdc`** - CI/CD & deployment best practices (optional) - **`security.mdc`** - Security guidelines & language-specific practices (optional) **Benefits over legacy format:** - ๐ŸŽฏ **Better AI understanding** through modular context - ๐Ÿ“ **Organized structure** with separated concerns - ๐Ÿ” **Path-scoped rules** that apply only where relevant - โšก **Faster processing** by loading only relevant context ### `.windsurfrules` (Windsurf) A configuration file for Windsurf AI development environment with: - Project-specific rules - Technology guidelines - Code generation preferences - Quality standards ### `.gemini/settings.json` (Gemini CLI) Configuration for Gemini CLI to use `.agent.md` as context file: - Local project configuration (`.gemini/settings.json`) - Global user configuration (`~/.gemini/settings.json`) - Automatic context file detection - Seamless integration with existing `.agent.md` files ## ๐ŸŽฏ Benefits ### Before v1.1.0 (React-Biased) - โŒ Always assumed web applications - โŒ Asked irrelevant frontend/backend questions for CLI tools - โŒ Limited to 6 technology guidelines - โŒ One-size-fits-all approach ### After v1.1.0 (Inclusive) - โœ… **6 project types** supported with specific workflows - โœ… **Conditional questions** - only relevant ones asked - โœ… **20+ technologies** with specific guidelines - โœ… **Context-aware** messaging and defaults - โœ… **Backward compatible** - existing users unaffected ## ๐Ÿ“Š Version History See [CHANGELOG.md](CHANGELOG.md) for detailed version history and release notes. ## ๐Ÿ“„ License This project is licensed under the GPL-3.0 License - see the [LICENSE](LICENSE) file for details. ## ๐Ÿ™ Acknowledgments - Thanks to all contributors who help improve this tool - Special thanks to the AI development community for feedback and suggestions - Built with โค๏ธ for developers working with AI assistants --- **Made with โค๏ธ by [ubuntupunk](https://github.com/ubuntupunk)**