Interactive rule generation with dependency and conflict resolution
Demo Rules Repository • Features • Installation • Configuration • Usage • Rule Schema • Output Structure • Development • Architecture • Error Handling
AI Rules CLI is a command-line tool for managing and composing rule sets defined in ai-rules. It provides an interactive wizard, schema validation, dependency resolution, and conflict detection — all fully typed with TypeScript.
- Interactive Wizard: Step-by-step rule selection with visual feedback
- Dependency Resolution: Automatically resolves rule dependencies
- Conflict Detection: Identifies and helps resolve rule conflicts
- Schema Validation: Validates rules against the MDC schema
- Multiple Commands: List, validate, check, and generate rules
- TypeScript: Fully typed with strict mode
npm install -g ai-rules-clinpx ai-rules-cli initgit clone https://github.com/rerades/ai-rules-cli.git
cd ai-rules-cli
npm install
npm run build
npm linkNote: This CLI does not include any predefined rules. To use your own rules, you must specify where the CLI can find them. By default, the CLI will look for rules in your user directory at ~/ai-rules (you can change this path using environment variables).
Any new rule that you define must follow the predefined schema created in this repository.
For a quick rules setup, I also maintain a repository with example rules that you can fork to create your own rule sets.
You can copy the rules to the default repository path ~/ai-rules to get started quickly.
The CLI uses the following default configuration:
- Repository Path:
~/ai-rules- This is where your rules are saved - Rules Directory:
rules - Schema File:
mdc.schema.json - Output Directory:
.cursor/rules
You can override these settings using environment variables:
| Variable | Default | Description |
|---|---|---|
AI_RULES_REPO_PATH |
~/ai-rules |
Repository where rules are stored |
AI_RULES_OUTPUT_PATH |
.cursor/rules |
Output folder |
AI_RULES_VERBOSE |
false |
Enable verbose logging |
export AI_RULES_REPO_PATH="/path/to/your/rules/repo"
export AI_RULES_OUTPUT_PATH="/path/to/output"
export AI_RULES_VERBOSE=trueai-rules initThis will launch the interactive wizard to:
- Select rule categories
- Choose specific rules
- Configure output directory
- Resolve dependencies and conflicts
- Generate rule files
ai-rules listOptions:
-c, --category <category>- Filter by category-s, --search <query>- Search rules by title or summary-v, --verbose- Show detailed information
ai-rules validateOptions:
-v, --verbose- Show detailed validation results
ai-rules check <rule-ids...>Options:
-v, --verbose- Show detailed information
ai-rules generate <rule-ids...> -o <output-path>Options:
-o, --output <path>- Output directory path--dry-run- Simulate without creating files-m, --minify-frontmatter- Emit minimal frontmatter (required fields only)--keep <fields>- Comma-separated optional fields to retain with minify (e.g.,description,scope,enforcement)-v, --verbose- Enable verbose output
- Minimal (with
-m):
---
id: foundation.response-deliverables.structure
version: 1.0.0
title: "Response Deliverables — Structure"
category: foundation
---- Extended (default or allowlisted via
--keep):
---
id: foundation.response-deliverables.structure
version: 1.0.0
title: "Response Deliverables — Structure"
category: foundation
description: "Rules for structuring responses with status, edits, and impact summary."
scope: ["global"]
language: "none"
enforcement: { lint: "warn", ci: "allow", scaffold: "none" }
---Rules must follow the MDC (Markdown with frontmatter) schema defined in mdc.schema.json. Each rule file should have:
- Frontmatter: YAML metadata with rule information
- Content: Markdown content with the actual rule
Example rule structure:
---
id: "foundation.code-guidelines"
version: "1.0.0"
title: "Code Guidelines"
summary: "Basic coding standards and best practices"
category: "foundation"
scope: ["global"]
language: "ts"
lifecycle: "recommended"
maturity: "stable"
order: 10
---
# 📝 Code Guidelines
This rule defines basic coding standards...The CLI generates the following structure:
.cursor/
└── rules/
├── index.md
├── foundation.code-guidelines.mdc
├── typescript.conventions.mdc
└── ...
Additionally, the CLI generates a claude.md file in the output directory root (alongside .cursor/rules/) for Claude AI integration.
The index.md file contains:
- Overview of all rules
- Categorization
- Rule metadata
- Usage instructions
The claude.md file is automatically generated to help Claude AI integrate with your rules:
- Provides structured guidelines for Claude AI to reference the
.cursor/rulesdirectory - Explains how Claude can benefit from your rules and maintain consistency with Cursor IDE
- Includes usage examples and best practices for working with rules in Claude
- Documents available rules and categories for easy reference
- Generated automatically when running
initorgeneratecommands
Each rule file (.mdc) contains:
- YAML frontmatter with metadata
- Markdown content with the actual rule
- Node.js 18+
- TypeScript 5+
- npm or yarn
git clone <repository-url>
cd ai-rules-cli
npm installnpm run buildnpm run devnpm testnpm run lint
npm run lint:fixThe CLI is built with a modular architecture:
src/
├── core/ # Core business logic
│ ├── config.ts # Configuration management
│ ├── rule-loader.ts # Rule loading and parsing
│ ├── rule-validator.ts # Schema validation
│ └── dependency-resolver.ts # Dependency resolution
├── ui/ # User interface
│ ├── wizard.ts # Interactive wizard
│ ├── prompts.ts # Inquirer prompts
│ ├── formatters.ts # Visual formatting
│ └── spinner.ts # Loading indicators
├── generators/ # File generation
│ ├── output-generator.ts # Rule file generation
│ └── index-generator.ts # Index file generation
├── utils/ # Utilities
│ ├── logger.ts # Logging
│ └── file-utils.ts # File operations
├── types/ # TypeScript types
│ ├── rule.types.ts
│ ├── config.types.ts
│ └── wizard.types.ts
└── index.ts # CLI entry point
The CLI provides comprehensive error handling:
- Validation Errors: Clear messages for schema violations
- Dependency Errors: Missing dependencies are reported
- Conflict Errors: Rule conflicts are identified and resolved
- File Errors: File system operations are handled gracefully
- User Errors: Invalid inputs are caught and reported
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details.
For issues and questions:
- Create an issue on GitHub
- Check the documentation
- Review the examples
MIT © Rodrigo Erades
