|
| 1 | +--- |
| 2 | +description: This rule is essential for maintaining consistency and quality in rule creation across the codebase. It must be followed whenever: (1) A user requests a new rule to be created, (2) An existing rule needs modification, (3) The user asks to remember certain behaviors or patterns, or (4) Future behavior changes are requested. This rule ensures proper organization, clear documentation, and effective rule application by defining standard formats, naming conventions, and content requirements. It's particularly crucial for maintaining the rule hierarchy, ensuring rules are discoverable by the AI, and preserving the effectiveness of the rule-based system. The rule system is fundamental to project consistency, code quality, and automated assistance effectiveness. |
| 3 | +globs: |
| 4 | +alwaysApply: true |
| 5 | +--- |
| 6 | +# Cursor Rules Format |
| 7 | + |
| 8 | +## Template Structure for Rules Files |
| 9 | + |
| 10 | +```mdc |
| 11 | +--- |
| 12 | +description: `Comprehensive description that provides full context and clearly indicates when this rule should be applied. Include key scenarios, impacted areas, and why following this rule is important. While being thorough, remain focused and relevant. The description should be detailed enough that the agent can confidently determine whether to apply the rule in any given situation.` |
| 13 | +globs: .cursor/rules/**/*.mdc OR blank |
| 14 | +alwaysApply: {true or false} |
| 15 | +--- |
| 16 | + |
| 17 | +# Rule Title |
| 18 | + |
| 19 | +## Critical Rules |
| 20 | + |
| 21 | +- Concise, bulleted list of actionable rules the agent MUST follow |
| 22 | + |
| 23 | +## Examples |
| 24 | + |
| 25 | +<example> |
| 26 | +{valid rule application} |
| 27 | +</example> |
| 28 | + |
| 29 | +<example type="invalid"> |
| 30 | +{invalid rule application} |
| 31 | +</example> |
| 32 | +``` |
| 33 | + |
| 34 | +### Organizational Folders (Create if non existent) |
| 35 | +All rules files will be under an organizational folder: |
| 36 | +- .cursor/rules/core-rules - rules related to cursor agent behavior or rule generation specifically |
| 37 | +- .cursor/rules/my-rules - gitignore in a shared repo, rules specifically for ME only |
| 38 | +- .cursor/rules/global-rules - these will be rules that are ALWAYS applied to every chat and cmd/ctrl-k context |
| 39 | +- .cursor/rules/testing-rules - rules about testing |
| 40 | +- .cursor/rules/tool-rules - rules specific to different tools, such as git, linux commands, direction of usage of MCP tools |
| 41 | +- .cursor/rules/ts-rules - typescript language specific rules |
| 42 | +- .cursor/rules/py-rules - python specific rules |
| 43 | +- .cursor/rules/ui-rules - rules about html, css, react |
| 44 | +* create new folders under .cursor/rules/ as needed following similar grouping conventions, |
| 45 | + - for example `.cursor/rules/cs-rules` if we started using c# in a project |
| 46 | + |
| 47 | +## Glob Pattern Examples |
| 48 | +Common glob patterns for different rule types: |
| 49 | +- Core standards: .cursor/rules/*.mdc |
| 50 | +- Language rules: *.cs, *.cpp |
| 51 | +- Testing standards: *.test.ts, *.test.js |
| 52 | +- React components: src/components/**/*.tsx |
| 53 | +- Documentation: docs/**/*.md, *.md |
| 54 | +- Configuration files: *.config.js |
| 55 | +- Build artifacts: dist/**/* |
| 56 | +- Multiple extensions: *.js, *.ts, *.tsx |
| 57 | +- Multiple patterns: dist/**/*.*, docs/**/*.md, *test*.* |
| 58 | + |
| 59 | +## Critical Rules |
| 60 | + - Rule files will be located and named ALWAYS as: `.cursor/rules/{organizational-folder}/rule-name-{auto|agent|manual|always}.mdc` |
| 61 | + - Rules will NEVER be created anywhere other than .cursor/rules/** |
| 62 | + - You will always check to see if there is an existing rule to update under all .cursor/rules sub-folders |
| 63 | + - FrontMatter Rules Types: |
| 64 | + - The front matter section must always start the file and include all 3 fields, even if the field value will be blank - the types are: |
| 65 | + - Manual Rule: IF a Manual rule is requested - description and globs MUST be blank and alwaysApply: false and filename ends with -manual.mdc. |
| 66 | + - Auto Rule: IF a rule is requested that should apply always to certain glob patterns (example all typescript files or all markdown files) - description must be blank, and alwaysApply: false and filename ends with -auto.mdc. |
| 67 | + - Always Rule: Global Rule applies to every chat and cmd/ctrl-k - description and globs blank, and alwaysApply: true and filename ends with -always.mdc. |
| 68 | + - Agent Select Rule: The rule does not need to be loaded into every chat thread, it serves a specific purpose. The description MUST provide comprehensive context about when to apply the rule, including scenarios like code changes, architecture decisions, bug fixes, or new file creation. Globs blank, and alwaysApply:false and filename ends with -agent.mdc |
| 69 | + - For Rule Content - focus on actionable, clear directives without unnecessary explanation |
| 70 | + - When a rule will only be used sometimes (alwaysApply: false) the description MUST provide enough context for the AI to confidently determine when to load and apply the rule |
| 71 | + - Use Concise Markdown Tailored to Agent Context Window usage |
| 72 | + - Always indent content within XML Example section with 2 spaces |
| 73 | + - Emojis and Mermaid diagrams are allowed and encouraged if it is not redundant and better explains the rule for the AI comprehension |
| 74 | + - While there is no strict line limit, be judicious with content length as it impacts performance. Focus on essential information that helps the agent make decisions |
| 75 | + - Always include a valid and invalid example |
| 76 | + - NEVER use quotes around glob patterns, NEVER group glob extensions with `{}` |
| 77 | + - If the request for a rule or a future behavior change includes context of a mistake is made, this would be great to use in the example for the rule |
| 78 | + - After rule is created or updated, Respond with the following: |
| 79 | + - AutoRuleGen Success: path/rule-name.mdc |
| 80 | + - Rule Type: {Rule Type} |
| 81 | + - Rule Description: {The exact content of the description field} |
0 commit comments