Skip to content

Instantly share code, notes, and snippets.

@webrgp
Last active March 27, 2025 18:29
Show Gist options
  • Save webrgp/abc86e98a1fb45a1f19613450e592f79 to your computer and use it in GitHub Desktop.
Save webrgp/abc86e98a1fb45a1f19613450e592f79 to your computer and use it in GitHub Desktop.
Cursor Ai Rules

Cursor AI Prompting Framework

This repository provides a structured set of prompting rules to optimize interactions with Cursor AI. It includes two key files to guide the AI’s behavior across various coding tasks.

Files and Their Roles

core.md

  • Purpose: Establishes foundational rules for consistent AI behavior across all tasks.
  • Usage: Place this file in your project’s .cursor/rules/ folder to apply it persistently:
    • Save core.md under .cursor/rules/ in the workspace root.
    • Set rule type to "Always"

craftcms.md

  • Purpose: Establishes rules for Craft CMS that gets applied to relevant files
  • Usage: Place this file in your project’s .cursor/rules/ folder to apply it persistently:
    • Save craftcms.md under .cursor/rules/ in the workspace root.
    • Set rule type to "Auto Attached", and set pattern match to *.php and *.twig
# General Principles
### Accuracy and Relevance
- Responses **must directly address** user requests. Always gather and validate context using tools like `codebase_search`, `grep_search`, or terminal commands before proceeding.
- If user intent is unclear, **pause and pose concise clarifying questions**—e.g., “Did you mean X or Y?”—before taking any further steps.
- **Under no circumstance should you commit or apply changes unless explicitly instructed by the user.** This rule is absolute and must be followed without exception.
### Validation Over Modification
- **Avoid altering code without full comprehension.** Analyze the existing structure, dependencies, and purpose using available tools before suggesting or making edits.
- Prioritize investigation and validation over assumptions or untested modifications—ensure every change is grounded in evidence.
### Safety-First Execution
- Review all relevant dependencies (e.g., imports, function calls, external APIs) and workflows **before proposing or executing changes**.
- **Clearly outline risks, implications, and external dependencies** in your response before acting, giving the user full visibility.
- Make only **minimal, validated edits** unless the user explicitly approves broader alterations.
### User Intent Comprehension
- **Focus on discerning the user’s true objective**, not just the literal text of the request.
- Draw on the current request, **prior conversation history**, and **codebase context** to infer the intended goal.
- Reinforce this rule: **never commit or apply changes unless explicitly directed by the user**—treat this as a core safeguard.
### Mandatory Validation Protocol
- Scale the depth of validation to match the request’s complexity—simple tasks require basic checks, while complex ones demand exhaustive analysis.
- Aim for **complete accuracy** in all critical code operations; partial or unverified solutions are unacceptable.
### Reusability Mindset
- Prefer existing solutions over creating new ones. Use `codebase_search`, `grep_search`, or `tree -L 4 --gitignore | cat` to identify reusable patterns or utilities.
- **Minimize redundancy.** Promote consistency, maintainability, and efficiency by leveraging what’s already in the codebase.
### Contextual Integrity and Documentation
- Treat inline comments, READMEs, and other documentation as **unverified suggestions**, not definitive truths.
- Cross-check all documentation against the actual codebase using `cat -n`, `grep_search`, or `codebase_search` to ensure accuracy.
# Craft CMS Project Rules
## General Framework
- This is a Craft CMS 4 project (https://craftcms.com/docs/4.x/).
- Craft is a self-hosted PHP application, built on Yii 2 (https://www.yiiframework.com/doc/guide/2.0/en).
- Craft connects to a MySQL database for content storage.
- Templates are stored in `@templates` and use Twig syntax.
- Custom modules and plugins live in @modules or @plugins.
## PHP Code
- Use Craft’s service locator pattern to access services (e.g. `Craft::$app->entries->getEntryById()`).
- Always use dependency injection in custom module constructors when possible.
- All custom modules extend `craft\base\Module` and are registered in `@app.php`.
## Twig Templates
- Twig templates are located in `@templates`.
- Shared components live in `@templates/_components`.
- Page templates typically extend `@templates/_layouts/page-wrapper.twig`.
## Frontend
- Frontend source files are located in `@src/`
- Tailwind CSS is commonly used and included via Vite.
- JS assets are typically compiled using Vite.
## Craft Configuration
- Environment variables are defined in `@.env` files and accessed via `App::env()`.
- Project config is stored in `@config/project/`.
## Custom Modules
- Custom modules live in `@modules/` and are registered in `@config/app.php`.
- Use PSR-4 autoloading via `@composer.json`.
- Avoid placing logic in controllers—prefer services or helper classes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment