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
Markdown
โ 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)**