thanks a million - i did some research with perplexity deep research asking it to provide suggestions as to how i can get cursor to be as efficient and optimized as cline roo which seems to just work in develop applications but it is cost prohibitive i received the following suggestion perhaps you can assist and make cursor as efficient as cline roo Below is a complete, beginner-friendly stepābyāstep guide covering all the rules you provided. Each rule is listed exactly as written, with instructions on how to set it up in Cursor. For any rule that requires extra files or steps, those are explained; otherwise, you simply add the rule.
1. Context Retention Rule
Rule: .cursor/rules/context-retention.mdc
# .cursor/rules/context-retention.mdc
- Maintain vector index of all modified files via @contextprotocol/vector-db
- Weight context by:
- File modification frequency (0.7x)
- Test coverage density (1.2x)
- Architectural significance from .cursor/architecture.md
- Preserve session state across restarts using LocalForage snapshots
Purpose:
Ensures that Cursor tracks changes in your files, prioritizes important files based on modification frequency, test coverage, and architectural importance, and remembers your session state even after restarting.
Setup Instructions:
- Create the File:
- In your global rules directory (e.g.,
~/.cursor/rules/
), create a file named context-retention.mdc
.
- Paste the Content:
- Copy the exact content above into the file.
- Additional File Required:
- @architecture-rules.md:
- Purpose: This file defines your projectās architectural guidelines (key modules, design patterns, etc.).
- Setup: Create a file named
.cursor/architecture.md
(or @architecture-rules.md
per your convention) in the same folder. Add your architectural guidelines there.
- Finish:
- Restart Cursor to load the new rule.
Global Rules Inheritance
Rule: Global JSON Configuration
{
"rules.globalRulesPath": "~/.cursor/rules/enterprise-standards",
"rules.mergeStrategy": "override",
"rules.autoApplyPatterns": ["**/*.tsx", "**/api/*.ts"]
}
Purpose:
Directs Cursor to use enterprise-wide rules stored in a specific folder, ensures global rules override project-specific ones, and automatically applies these rules to specific file patterns.
Setup Instructions:
- Add the Rule:
- Insert this JSON snippet into your global Cursor configuration file (e.g.,
settings.json
).
- Ensure the Folder Exists:
- Confirm that the folder
~/.cursor/rules/enterprise-standards
exists and contains your standard rule templates.
- Finish:
- No additional steps are neededāsimply add the rule.
2. Debug Workflows and Error Handling
Rule: .cursor/rules/debug-workflows.mdc
# .cursor/rules/debug-workflows.mdc
- Create pre-commit checkpoints via @cline/checkpoint-engine
- Diff current state against last stable checkpoint
- Auto-suggest rollbacks when test coverage drops below 85%
Purpose:
Automates the creation of checkpoints before commits, compares current code with the last known good state, and suggests rollbacks if test coverage falls too low.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named debug-workflows.mdc
.
- Paste the Content:
- Copy and paste the rule exactly.
- Finish:
Note: This rule appears multiple times in your list; add it once.
Rule: .cursor/rules/error-handler.ts
// .cursor/rules/error-handler.ts
export const recoveryFlow = (error: Error) => {
if (error.message.includes("Cannot read property")) {
return {
action: "INJECT_NULL_CHECK",
contextFiles: ["@utils/safe-access.ts"]
};
}
// 28 additional error signatures
};
Purpose:
Defines how Cursor automatically handles common errors by suggesting fixesāsuch as injecting null checks when a āCannot read propertyā error is encountered.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named error-handler.ts
.
- Paste the Content:
- Copy and paste the exact code.
- Additional File Required:
- @utils/safe-access.ts:
- Purpose: Contains functions to safely access object properties (implementing null checks).
- Setup: Create this file in your projectās utilities folder and add the necessary code.
- Finish:
- Add the rule along with the extra file.
Note: This error-handler rule is repeated; add it only once.
3. Architectural Guardrails (MCP Server Configuration)
Rule: MCP Server JSON Configuration
{
"mcp.servers": [
{
"name": "ArchGuard",
"url": "http://localhost:3001",
"timeout": 150,
"rules": "@architecture-rules.md"
}
]
}
Purpose:
Sets up an MCP server named āArchGuardā that enforces architectural rules defined in an external file.
Setup Instructions:
- Add the Rule:
- Insert this JSON snippet into your global configuration (or dedicated MCP server settings file).
- Additional File Required:
- @architecture-rules.md:
- Purpose: Contains the architectural guidelines for your project.
- Setup: As described in Rule 1, create and populate this file in
~/.cursor/rules/
.
- Run the MCP Server:
- Finish:
- Add the rule and verify that the MCP server is active.
4. Security Rule
Rule: .cursor/rules/security.mdc
# ~/.cursor/rules/security.mdc
- Scan all terminal commands through @security-sentinel
- Risk levels:
- HIGH: rm -rf, .env modifications
- MEDIUM: file system writes
- LOW: read-only operations
- Require manual approval for HIGH-risk actions
Purpose:
Ensures that every terminal command executed via Cursor is checked for security risks and requires manual approval for high-risk actions.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named security.mdc
.
- Paste the Content:
- Copy and paste the exact content.
- Finish:
5. Update and Validation Script
Rule: update-rules.sh
#!/bin/bash
# update-rules.sh
curl https://rules.cursor.directory/latest.tar.gz | tar xz -C ~/.cursor/rules
npx @cursorlint/cli validate --strict
Purpose:
Automates downloading the latest rule templates and validating your Cursor configuration to ensure all rules are applied correctly.
Setup Instructions:
- Create the Script File:
- Create a file named
update-rules.sh
in your preferred scripts directory (e.g., in your home directory or /usr/local/bin/
).
- Paste the Script Content:
- Copy and paste the above script.
- Make It Executable:
- Run in your terminal:
chmod +x update-rules.sh
- Optional ā Schedule via Cron:
- To automate updates, place the script in
/etc/cron.daily/
or create a cron job.
- Finish:
6. Next.js Specific Rule
Rule: .cursor/rules/nextjs.mdc
# .cursor/rules/nextjs.mdc
- Use App Router for all routing
- Server Components:
- No useEffect/useState
- Fetch directly in component
- Streaming responses
- Client Components:
- 'use client' directive
- Hydration-safe patterns
- Cache Config:
- revalidate: 3600
- tags: @/data-fetching
- Metadata:
- generateMetadata for dynamic SEO [1][9]
Purpose:
Optimizes Cursorās handling of Next.js projects by setting best practices for routing, component usage, caching, and SEO.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named nextjs.mdc
.
- Paste the Content:
- Copy and paste the rule exactly.
- Finish:
7. React Component Governance Rule
Rule: React Governance JSON
{
"react.rules": {
"naming": "PascalCase",
"props": {
"typeSafety": "TypeScript interfaces",
"defaults": "Required unless optional",
"destructuring": "Enforced"
},
"hooks": {
"dependencies": "Exhaustive deps",
"ordering": "Same-order principle"
}
}
}
Purpose:
Enforces best practices in React componentsāensuring proper naming, type safety, and correct hook usage.
Setup Instructions:
- Add the Rule:
- Insert this JSON snippet into your global configuration file (e.g.,
settings.json
) or into your dedicated React rules configuration file.
- Finish:
8. Performance Guardrails Rule
Rule: .cursor/rules/performance.yml
# .cursor/rules/performance.yml
react:
memoization:
threshold: 3_props_changes
exclude: ["context_consumers"]
nextjs:
image_optimization:
format: webp
quality: 75
remote_patterns:
- hostname: '**.cdn.com'
bundling:
chunk_strategy: route_based
preload: critical_assets [6][10]
Purpose:
Sets performance guidelines for React and Next.js projects, including memoization, image optimization, and bundling strategies.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named performance.yml
.
- Paste the Content:
- Copy and paste the rule exactly.
- Finish:
9. Adaptive Token Allocation (Context Pruning) Rule
Rule: .cursor/rules/context-pruning.mdc
# .cursor/rules/context-pruning.mdc
- Implement vector-aware pruning using @contextprotocol/dynamic-pruner
- Priority tiers:
- Active development files: 45% token allocation
- Recently modified utils: 25%
- Architectural docs: 15%
- node_modules: 0% (auto-excluded)
- Prune non-essential tokens using CDIT framework thresholds [18][5]
Purpose:
Optimizes the context window by allocating tokens (the unit of context) preferentially to important files while pruning less essential information.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named context-pruning.mdc
.
- Paste the Content:
- Copy and paste the rule exactly.
- Finish:
10. Hierarchical Indexing Rule
Rule: .cursor/rules/index-layers.yml
# .cursor/rules/index-layers.yml
index_layers:
- Type: File Relationships
Weight: 0.7
Source: import/export statements
- Type: API Surface
Weight: 0.9
Source: OpenAPI specs
- Type: Data Flow
Weight: 1.2
Source: PropTypes/TypeScript interfaces
Purpose:
Builds multiple layers of indexing so that Cursor can better understand relationships within your code, such as how files import/export each other, the structure of your APIs, and the data flow through your application.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named index-layers.yml
.
- Paste the Content:
- Copy and paste the rule exactly.
- Finish:
11. Multi-Model Routing Protocol Rule
Rule: .cursor/rules/model-router.ts
// .cursor/rules/model-router.ts
export const routeRequest = (task: DevTask) => {
switch(task.type) {
case 'REFACTOR':
return {
model: 'claude-3-opus',
temperature: 0.3,
maxTokens: 4096
};
case 'DEBUG':
return {
model: 'roo-code-v3',
temperature: 0.1,
contextStrategy: 'Temporal'
};
case 'GENERATE':
return {
model: 'gpt-4-turbo',
temperature: 0.7,
streaming: true
};
}
};
Purpose:
Routes different types of development tasks (refactoring, debugging, generating new code) to the most suitable AI model.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named model-router.ts
.
- Paste the Content:
- Copy and paste the code exactly.
- Finish:
12. Cost-Aware Execution Rule
Rule: Cost-Aware Execution JSON
{
"ai.budgetRules": {
"maxDailyCost": "$15",
"fallbackModel": "claude-3-sonnet",
"alertThresholds": {
"75%": "WARN",
"90%": "BLOCK"
}
}
}
Purpose:
Manages your daily API spending by setting a maximum cost, specifying a fallback model if needed, and defining alert thresholds.
Setup Instructions:
- Add the Rule:
- Insert this JSON snippet into your global Cursor configuration file (e.g.,
settings.json
).
- Finish:
13. Automated Checkpointing Rule
Rule: .cursor/rules/checkpoints.mdc
# .cursor/rules/checkpoints.mdc
- Create pre-commit snapshots via @cline/checkpoint-engine
- Diff analysis parameters:
- Line similarity: 85%
- Semantic equivalence: 92%
- Test coverage delta: Ā±5%
- Auto-rollback triggers:
- Test pass rate 3
- Lint warnings increase
Purpose:
Automatically creates snapshots of your code before commits and compares them with the current state to suggest rollbacks if necessary, reducing debugging iterations.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named checkpoints.mdc
.
- Paste the Content:
- Copy and paste the rule exactly.
- Finish:
14. Security Enforcement (Workflow) Rule
Rule: .cursor/rules/security-gates.yml
# .cursor/rules/security-gates.yml
command_risk:
HIGH:
- "rm -rf"
- ".env modification"
- "sudo"
MEDIUM:
- "fs.write"
- "process.kill"
validation:
- Manual approval for HIGH
- Code review for MEDIUM+
Purpose:
Ensures that commands with high risk (like deletion or modifying critical files) require manual approval or extra review, helping prevent catastrophic errors.
Setup Instructions:
- Create the File:
- In
~/.cursor/rules/
, create a file named security-gates.yml
.
- Paste the Content:
- Copy and paste the rule exactly.
- Finish:
15. Maintenance Protocol (Benchmark and Optimization Script)
Rule: Maintenance Script
#!/bin/bash
# /etc/cron.hourly/cursor-optimize
find ~/.cursor/rules -name "*.mdc" -exec sed -i 's/temperature: 0.7/temperature: 0.5/g' {} \;
systemctl reload cursor-engine
Purpose:
Automates the tuning of specific parameters (e.g., adjusting temperature values) across all rule files and reloads the Cursor engine, ensuring optimal performance.
Setup Instructions:
- Create the Script File:
- Create a file named
cursor-optimize
in your cron directory (e.g., /etc/cron.hourly/
).
- Paste the Content:
- Copy and paste the script exactly.
- Make It Executable:
- Finish:
- Add the script and schedule it via cron.
16. Global Coding Standards for Cursor AI
Rule: Global Rules for Cursor AI
## General Coding Standards
1. Code Quality:
- Follow SOLID principles
- Implement DRY (Don't Repeat Yourself)
- Use clear, semantic naming
- Include proper error handling
- Add comprehensive documentation
2. Security Practices:
- Validate all inputs
- Sanitize data outputs
- Use prepared statements for queries
- Implement proper authentication
- Follow OWASP guidelines
3. Performance Optimization:
- Optimize database queries
- Implement caching where appropriate
- Use lazy loading for resources
- Minimize HTTP requests
- Optimize asset delivery
## Architecture Patterns
1. Backend Development:
- RESTful API design
- Microservices architecture
- Event-driven patterns
- Repository pattern
- Service layer abstraction
2. Frontend Development:
- Component-based architecture
- State management patterns
- Progressive enhancement
- Responsive design
- Accessibility standards
## Testing Standards
1. Test Coverage:
- Unit testing
- Integration testing
- End-to-end testing
- Performance testing
- Security testing
2. Documentation Requirements:
- API documentation
- Code comments
- README files
- Changelog maintenance
- Setup instructions
## Development Workflow
1. Version Control:
- Git flow branching
- Meaningful commit messages
- Pull request templates
- Code review guidelines
- Branch naming conventions
2. CI/CD Practices:
- Automated testing
- Continuous integration
- Deployment automation
- Environment management
- Monitoring and logging
## Code Review Guidelines
1. Review Focus:
- Code functionality
- Security implications
- Performance impact
- Documentation completeness
- Test coverage
2. Quality Checks:
- Linting standards
- Code formatting
- Type checking
- Dependency management
- Security scanning
Purpose:
These guidelines establish best practices for coding, security, performance, architecture, testing, workflow, and code review. They serve as a foundation for maintaining enterprise-grade standards.
Setup Instructions:
- Document the Guidelines:
- Create a file (e.g.,
enterprise-standards.md
) in your global rules folder (e.g., ~/.cursor/rules/enterprise-standards/
).
- Paste the Content:
- Copy and paste the exact content above into that file.
- Reference in Global Config:
- Make sure your global configuration (see Rule 2) points to this folder.
- Finish:
Final Summary
For each rule:
- If a file needs to be created:
Create the file in the appropriate folder (usually ~/.cursor/rules/
) and paste the exact content.
- If additional files are mentioned:
Create those as well (e.g., @architecture-rules.md
, @utils/safe-access.ts
).
- If the rule is a JSON snippet:
Add it to your global configuration file (e.g., settings.json
).
- For scripts:
Create the script file, paste the code, and make it executable.
- If no extra steps are needed:
Simply add the rule.
By following this complete guide, you will have set up all the provided Cursor global rules, ensuring your development environment is optimized for enterprise-grade web development.