Skip to content

Instantly share code, notes, and snippets.

@codekiln
Last active March 6, 2025 10:17
Show Gist options
  • Save codekiln/242b572c64c1097277fd4c831db91c10 to your computer and use it in GitHub Desktop.
Save codekiln/242b572c64c1097277fd4c831db91c10 to your computer and use it in GitHub Desktop.
Cursor Rules for Editing Cursor Rules

Cursor Project Rule Editor Rule

Quick Install/Update (macOS)

Run this one-liner in your project root to install or update the rule:

curl -s https://gist.githubusercontent.com/codekiln/242b572c64c1097277fd4c831db91c10/raw/update.sh | bash

This will:

  • Install the rule if it doesn't exist
  • Update it if a newer version is available
  • Let you know if you're already on the latest version

Notes

  • This script is designed for macOS. Linux users will need to modify the awk commands in the script.
  • The script requires:
    • curl for downloading files
    • GitHub CLI (gh) for version checking
    • jq for parsing JSON responses
    • awk for text processing

Manual Installation

If you prefer to install manually or need to modify for Linux, you can:

  1. First, get the latest gist version:
VERSION=$(gh api /gists/242b572c64c1097277fd4c831db91c10/commits | jq -r ".[0].version" | cut -c1-8)
  1. Download and prepare the file:
# Create directory if needed
mkdir -p .cursor/rules

# Download the file
curl -o .cursor/rules/cursor-project-rule-editor.mdc "https://gist.githubusercontent.com/codekiln/242b572c64c1097277fd4c831db91c10/raw/cursor-project-rule-editor.mdc"

# Add version number (macOS syntax)
awk -v ver="$VERSION" 'BEGIN {p=1} /^---/ && p==1 {print; print "versionNum:", ver; p++; next} {print}' \
    .cursor/rules/cursor-project-rule-editor.mdc > .cursor/rules/cursor-project-rule-editor.mdc.tmp && \
    mv .cursor/rules/cursor-project-rule-editor.mdc.tmp .cursor/rules/cursor-project-rule-editor.mdc

Source Files

---
description: Editing Cursor Project Rules
globs: *.mdc
source: https://gist.github.com/codekiln/242b572c64c1097277fd4c831db91c10
---
# Cursor Project Rule Editor
This rule defines the workflow for editing Cursor project rules, ensuring they are properly placed and formatted.
<rule>
name: cursor_project_rule_editor
description: Standards for editing Cursor project rules
filters:
- type: file_extension
pattern: "\\.mdc$"
- type: content
pattern: "(?s)<rule>.*?</rule>"
actions:
- type: suggest
message: |
When editing Cursor project rules:
1. **Create Draft**:
- Create a draft in `ai-coding/cursor-project-rule/draft/`:
```bash
mkdir -p ai-coding/cursor-project-rule/draft
```
- Draft should follow the same naming as the target rule
- Draft should include proper frontmatter and formatting
2. **Request Approval**:
- Present the draft to the user for review
- Wait for explicit approval before proceeding
- If changes are requested, update the draft
3. **Apply Changes**:
- Upon approval, copy the draft to `.cursor/rules/` (forcing update if exists):
```bash
cp -f ai-coding/cursor-project-rule/draft/rule-name.mdc .cursor/rules/
```
- Remove the draft:
```bash
rm ai-coding/cursor-project-rule/draft/rule-name.mdc
```
4. **File Organization**:
```
PROJECT_ROOT/
├── .cursor/
│ └── rules/
│ └── rule-name.mdc # Final rule
└── ai-coding/
└── cursor-project-rule/
└── draft/
└── rule-name.mdc # Draft (temporary)
```
examples:
- input: |
# Draft Rule
```
---
description: "Example rule"
globs: "*.mdc"
---
# Example Rule
This is a draft rule.
```
output: "Correctly formatted draft rule"
metadata:
priority: high
version: 1.0
</rule>
#!/bin/bash
# Constants
GIST_ID="242b572c64c1097277fd4c831db91c10"
FILE_PATH=".cursor/rules/cursor-project-rule-editor.mdc"
TMP_FILE="${FILE_PATH}.tmp"
# Ensure .cursor/rules directory exists
mkdir -p .cursor/rules
# Get latest version from gist
LATEST_VERSION=$(gh api /gists/${GIST_ID}/commits | jq -r ".[0].version" | cut -c1-8)
# Check if file exists and get current version if it does
if [ -f "$FILE_PATH" ]; then
CURRENT_VERSION=$(awk "/^versionNum:/ {print \$2}" "$FILE_PATH")
if [ "$CURRENT_VERSION" = "$LATEST_VERSION" ]; then
echo "✓ cursor-project-rule-editor.mdc is already at the latest version ($LATEST_VERSION)"
exit 0
else
echo "⟳ Updating cursor-project-rule-editor.mdc from version $CURRENT_VERSION to $LATEST_VERSION"
fi
else
echo "+ Installing cursor-project-rule-editor.mdc version $LATEST_VERSION"
fi
# Download the latest version
curl -s -o "$TMP_FILE" "https://gist.githubusercontent.com/codekiln/${GIST_ID}/raw/cursor-project-rule-editor.mdc"
# Add version number to the frontmatter (macOS compatible)
awk -v ver="$LATEST_VERSION" '
BEGIN {p=1}
/^---/ && p==1 {print; print "versionNum:", ver; p++; next}
{print}
' "$TMP_FILE" > "${TMP_FILE}.new" && mv "${TMP_FILE}.new" "$TMP_FILE"
# Move the temporary file to replace the existing one
mv "$TMP_FILE" "$FILE_PATH"
echo "✓ Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment