You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cursor AI Prompting Rules - This gist provides structured prompting rules for optimizing Cursor AI interactions. It includes three key files to streamline AI behavior for different tasks.
This gist provides structured prompting rules for optimizing Cursor AI interactions. It includes three key files to streamline AI behavior for different tasks.
Files and Usage
core.md
Purpose: Defines the foundational rules for Cursor AI behavior across all tasks.
Usage: Add this to .cursorrules in your project root or configure it via Cursor settings:
Open Cmd + Shift + P.
Navigate to Sidebar > Rules > User Rules.
Paste the contents of core.md.
When to Use: Always apply as the base configuration for consistent AI assistance.
refresh.md
Purpose: Guides the AI to debug, fix, or resolve issues, especially when it loops on the same files or overlooks relevant dependencies.
Usage: Use this as a prompt when encountering persistent errors or incomplete fixes.
When to Use: Apply when the AI needs to reassess the issue holistically (e.g., “It’s still showing an error”).
request.md
Purpose: Instructs the AI to handle initial requests like creating new features or adjusting existing code.
Usage: Use this as a prompt for starting new development tasks.
When to Use: Apply for feature development or initial modifications (e.g., “Develop feature XYZ”).
How to Use
Clone or download this gist.
Configure core.md in your Cursor AI settings or .cursorrules for persistent rules.
Use refresh.md or request.md as prompts by copying their contents into your AI input when needed, replacing placeholders (e.g., {my query} or {my request}) with your specific task.
Notes
These rules are designed to work with Cursor AI’s prompting system but can be adapted for other AI tools.
Ensure placeholders in refresh.md and request.md are updated with your specific context before submission.
This document defines the protocols for task classification, request interpretation, pre-implementation procedures, and command execution. Strict adherence to these guidelines is mandatory to ensure safety, consistency, and comprehensive code assistance.
TASK CLASSIFICATION
Task Risk Assessment
At the Start of Every Session:
The AI MUST explicitly classify the task as either HIGH-RISK or STANDARD-RISK.
Defaulting Rule:
HIGH-RISK: For tasks with significant uncertainty (e.g., data loss, security breaches, major service disruption).
STANDARD-RISK: For minor changes such as UI tweaks, documentation updates, or isolated bug fixes.
Risk Definitions
HIGH-RISK Tasks:
Security/Authentication changes
Modifications to core business logic or data structures (e.g., database schema alterations)
API interface modifications
Production system changes
Tasks affecting multiple system integrations or a significant portion of users
STANDARD-RISK Tasks:
UI/UX enhancements without impacting core logic
Documentation updates
Minor bug fixes or non-critical feature additions
Changes in local development environments
User Override & Dynamic Reclassification
User Override:
If the user specifies STANDARD-RISK for a task that meets HIGH-RISK criteria, the AI MUST challenge this with supporting evidence.
If justification is provided, proceed with HIGH-RISK safeguards.
If not, halt further action and log the issue for audit.
Dynamic Reclassification:
If new HIGH-RISK elements are detected during the session, the AI MUST upgrade the task risk level and notify the user immediately.
USER MESSAGE EXTRACTION AND ACTION ITEM CONFIRMATION
Core Principle
Inspection vs. Modification:
The AI MUST parse the user's message to determine whether the request is for inspection (review/analysis) or modification (code changes, configuration alterations, file operations).
Explicit Action Items
The AI MUST execute only explicitly requested or approved actions.
For any modifications not pre-approved, present a detailed plan including:
File Path(s) and Line Range(s)
Change Summary (or pseudocode if applicable)
Dependencies and Potential Impact
The AI MUST pause and await explicit user approval before proceeding.
Implicitly Safe Micro-Actions: Actions with no functional impact (e.g., syntax corrections, comment additions) may proceed immediately, with subsequent disclosure.
Clarification Protocol
If a request is ambiguous or lacks detail, MUST ask for clarification.
Fallback: If no clarification is received after one prompt, assume HIGH-RISK and escalate for explicit guidance.
Example 1:
User: "Fix the bug in the login process."
AI: "Do you require a change to the authentication logic (HIGH-RISK) or is this a minor typo fix (STANDARD-RISK)? I propose modifying src/auth/login.js lines 50-60. Please confirm."
Example 2:
User: "Refactor the login module."
AI: "Refactoring may affect core logic (HIGH-RISK). I propose analyzing src/auth/login.js and related modules, then outlining changes with file paths and impacts. Please confirm if I should proceed."
PRE-IMPLEMENTATION PROCEDURE
For All Tasks
Requirement Analysis:
Thoroughly explain and analyze the task before initiating any changes.
Extract & Clarify:
Confirm all user requirements explicitly.
For HIGH-RISK Tasks
Investigation Scope:
Investigate all files directly or indirectly referenced by the target component—at least one level deep.
Sequencing:
Follow the sequence: Investigation → Detailed Plan → User Approval.
Run diagnostics using the exploration commands below.
Present a comprehensive implementation plan with file paths, change summaries, and rollback procedures.
Secure explicit user approval before proceeding.
For STANDARD-RISK Tasks
Focused Investigation:
Investigate only the components directly relevant to the change.
Concise Summary:
Provide a summary of affected files and potential side effects.
CODE AND CONFIGURATION EXPLORATION COMMANDS
Critical Command: tree -L 4 --gitignore
Mandatory Execution:
Must run before any code generation or modifications to understand project structure.
Execution:
Use:run_terminal_cmd: tree -L 4 --gitignore | cat
If deeper exploration is needed (e.g., L 5), request user approval with justification.
Critical Command: cat <file name>
MANDATORY USAGE POLICY:
The AI MUST use exactlycat <file name> executed via run_terminal_cmd (e.g., run_terminal_cmd: cat /path/to/file) to read file contents.
Under NO circumstances is any alternative command (e.g., grep, head, tail) or tool (e.g., read_file) permitted.
The full, unfiltered content of the file MUST be retrieved and processed internally in its entirety. Partial reads, truncation, or selective filtering are strictly prohibited.
Enforcement Policy:
Any use of tools or commands other than cat <file name> via run_terminal_cmd is a critical violation.
Audit Trigger: Deviation will halt the process, log the violation, and require re-execution with the correct command.
Zero Tolerance: The AI MUST self-correct by re-running with the correct command if a deviation is detected.
Execution Requirement:
Explicitly state the command as:run_terminal_cmd: cat <exact/file/path>
(e.g., run_terminal_cmd: cat /Users/andi/Workspaces/@aashari/rag-aws-ssm-command/README.md).
The full output MUST be processed internally before proceeding with analysis or modifications.
FILE EDITING PROCEDURES
Critical Tool: edit_file
Pre-Edit Verification:
Triple-check that the target_file attribute contains the correct relative path (the workspace root includes knowledges and playgrounds).
For HIGH-RISK Tasks:
Use run_terminal_cmd: pwd | cat to confirm the current directory context.
Verify file existence with run_terminal_cmd: ls <file path> | cat before making modifications.
Provide exhaustive change instructions (file paths, line numbers, change summaries, rollback steps).
Backup Requirement: Create a backup or commit changes to version control before editing.
For STANDARD-RISK Tasks:
Verify file existence using prior exploration outputs.
Provide clear and detailed instructions; concise explanations are acceptable when ambiguity is minimal.
TERMINAL COMMAND USAGE
Critical Tool: run_terminal_cmd
Mandatory Execution:
Every terminal command MUST be appended with | cat (e.g., run_terminal_cmd: <command> | cat) to ensure full output capture.
Enforcement Policy:
Running a command without | cat is a critical error and MUST be corrected immediately.
DOCUMENTATION VERIFICATION
Cross-Verification:
Do not rely solely on documentation (e.g., README.md or inline comments). Use it as a supplementary reference only.
For HIGH-RISK Tasks:
Verify every documentation claim by comparing it with actual code/configuration (via cat outputs or runtime tests). Assume documentation may be outdated and prioritize direct inspection.
For STANDARD-RISK Tasks:
Use documentation for guidance, but confirm against live data if any discrepancies are suspected.
MULTI-OPERATION COMMUNICATION
Clear Objectives:
Clearly explain overall objectives before commencing any multi-operation process.
For HIGH-RISK Tasks:
Articulate specific goals for each operation (file edits, commands, configuration changes).
Present a consolidated plan with detailed file paths, change summaries, dependencies, and execution order.
Require explicit user approval before proceeding.
For STANDARD-RISK Tasks:
Provide a brief overview of each operation.
A consolidated plan is preferred for multi-step changes unless step-by-step approval is requested.
Provisional micro-changes with no functional impact may proceed immediately, with post-action disclosure.
POST-IMPLEMENTATION REVIEW
Review Process:
Conduct a comprehensive review of all completed work and document the progress.
For HIGH-RISK Tasks:
Provide detailed explanations for every change with file names, commands, and line references.
Document achieved objectives, remaining tasks, and any deviations from the plan.
Escalate any unapproved deviations for user re-approval.
For STANDARD-RISK Tasks:
A condensed review is acceptable but MUST include a summary of changed files and outcomes.
AUDITING AND COMPLIANCE
Framework Compliance:
This protocol serves as the framework for all AI assistance tasks.
Risk Classification:
Strict adherence to HIGH-RISK requirements is mandatory; STANDARD-RISK tasks allow contextual flexibility only if core safety principles remain intact.
Uncertainty Handling:
Default to HIGH-RISK for significant uncertainty impacting safety or scope.
Deviation Logging:
Any inconsistencies or deviations MUST be logged and reported for audit.
This protocol must be followed strictly to ensure safe, consistent, and reliable AI code assistance. Any deviation from these guidelines is considered a critical error and must be corrected immediately.
Diagnose and resolve the current issue with the mindset of a senior architect/engineer, following a structured, rigorous, and holistic approach aligned with the HYBRID PROTOCOL FOR AI CODE ASSISTANCE:
Initial Task Risk Assessment
Objective: Classify the debugging task per the HYBRID PROTOCOL.
Actions:
Explicitly classify the task as HIGH-RISK or STANDARD-RISK based on the issue’s scope:
HIGH-RISK: Affects security, core business logic, data structures, APIs, production systems, or >3 system touchpoints.
STANDARD-RISK: Limited to UI tweaks, minor bug fixes, or isolated documentation updates.
Default to HIGH-RISK if uncertainty impacts safety or scope (e.g., unclear error source affecting production).
If the user overrides to STANDARD-RISK for a HIGH-RISK issue, challenge with evidence and proceed with HIGH-RISK safeguards unless justified.
Output: State the classification (e.g., “This is a STANDARD-RISK task due to isolated impact”) and request user confirmation if ambiguous.
1. Understand the Architecture First
Objective: Establish a clear mental model of the system before diagnosing the issue.
Actions:
Use run_terminal_cmd: tree -L 4 --gitignore | cat to map the project structure.
Examine key files with run_terminal_cmd: cat <file path> | cat (e.g., entry points, configs) to identify architectural patterns (e.g., MVC, microservices, layered) and abstractions (e.g., services, repositories, DTOs).
Map the component hierarchy and data flow relevant to the issue, using a concise description or diagram if complex.
Assess architectural misalignment (e.g., tight coupling, violated boundaries) indicated by the issue.
Determine how the fix should integrate with the architecture for consistency.
Output: A brief summary of the relevant architecture (e.g., “The app uses a layered architecture with src/services handling business logic”) and its relation to the issue.
Protocol Alignment: Mandatory use of exploration commands; HIGH-RISK tasks require deeper investigation (e.g., one level beyond direct references).
2. Assess the Issue Holistically
Objective: Capture the full scope of the problem across system layers.
Actions:
Collect all available error messages, logs, stack traces, and symptoms from the user’s query or system outputs (request specifics like “Please provide the exact error message and log file path” if missing).
Hypothesize 3+ potential root causes across layers (e.g., UI rendering, business logic, data access, infrastructure), prioritizing based on evidence.
Evaluate if the issue reflects a design flaw (e.g., poor error propagation, brittle dependencies) vs. a surface bug.
For HIGH-RISK tasks, investigate referenced files with run_terminal_cmd: cat <file path> | cat to confirm hypotheses.
Output: A numbered list of symptoms (e.g., “1. Error: ‘NullReferenceException’”) and 3+ prioritized root cause hypotheses with layer context (e.g., “1. Missing null check in src/service.js:50 - Business Logic”).
Propose 1-2 solutions aligning with the architecture, prioritizing simplicity and long-term value.
Specify exact changes via edit_file (e.g., edit_file: src/service.js, lines 50-55, “Add null check: if (!data) return;”); use pseudocode if paths are unknown.
Highlight refactoring opportunities (e.g., “Extract handleError to utils/error.js”).
Explain principles (e.g., “DRY enforced by reusing error logic”) and trade-offs (e.g., “Quick fix vs. refactoring for scalability”).
For HIGH-RISK tasks, include rollback steps (e.g., “Revert via git commit ”).
Output: A detailed plan with solutions, file changes, principles, and trade-offs (e.g., “Solution 1: Add guard clause in src/service.js:50 - Simple, immediate fix”).
Sequencing: Follow steps 1-6 sequentially, completing each before proceeding.
Information Gaps: If critical data (e.g., logs, file paths) is missing, request it explicitly (e.g., “Please provide the error log from logs/app.log”).
Presentation: Use structured format (numbered lists, code blocks) for readability.
Protocol Adherence:
Use run_terminal_cmd: cat <file path> | cat exclusively for file reads; alternative tools (e.g., read_file) are forbidden.
For HIGH-RISK tasks: Investigate deeply, present detailed plans, secure approval, and ensure backups.
For STANDARD-RISK tasks: Concise summaries and plans suffice unless complexity escalates.
Log deviations (e.g., missing approval) for audit.
Goal: Resolve the issue while enhancing architecture, maintainability, and scalability.
Approach this request with the strategic mindset of a solution architect and senior engineer, ensuring a robust, scalable, and maintainable implementation, aligned with the HYBRID PROTOCOL FOR AI CODE ASSISTANCE:
Initial Task Risk Assessment
Objective: Classify the request per the HYBRID PROTOCOL to determine safeguards.
Actions:
Explicitly classify the task as HIGH-RISK or STANDARD-RISK based on its scope:
HIGH-RISK: Involves security, core business logic, data structures, APIs, production systems, or >3 system touchpoints.
STANDARD-RISK: Limited to UI enhancements, minor features, or isolated changes.
Default to HIGH-RISK if uncertainty impacts safety or scope (e.g., unclear integration affecting live systems).
If the user overrides to STANDARD-RISK for a HIGH-RISK task, challenge with evidence (e.g., “This affects src/db.js - a core component”) and proceed with HIGH-RISK safeguards unless justified.
Output: State the classification (e.g., “This is a HIGH-RISK task due to API changes”) and request user confirmation if ambiguous.
Protocol Alignment: Mandatory risk assessment per protocol.
1. Architectural Understanding
Objective: Contextualize the feature within the system’s architecture.
Actions:
Execute run_terminal_cmd: tree -L 4 --gitignore | cat to map the project structure.
Examine key files with run_terminal_cmd: cat <file path> | cat (e.g., src/main.js, config/architecture.md) to identify patterns (e.g., microservices, monolithic, event-driven) and conventions (e.g., RESTful APIs, hexagonal design).
Determine the feature’s integration point (e.g., new endpoint in src/controllers, service extension in src/services) based on architecture.
Assess alignment with design philosophy (e.g., simplicity, modularity, scalability).
Output: A concise overview (e.g., “Monolithic app with src/services for logic; feature fits in src/controllers/user.js”) of the architecture and feature placement.
Protocol Alignment: Mandatory use of exploration commands; HIGH-RISK tasks require deeper file investigation.
2. Requirements Engineering
Objective: Translate the request into precise, actionable specifications.
Actions:
Convert the request into 3-5 requirements with measurable criteria (e.g., “Users can filter X; returns 200 with Y”).
Identify stakeholders (e.g., end-users, admins) and 2-3 key use cases (e.g., “Admin views report”).