Feedback on rule to avoid cursor deleting random lines from files

I’ve been working on a rule to try and catch when cursor removes lines from a file that are unrelated to the edit that it’s making. I’ve seen it catch a few instances, so I thought it might be worth sharing to a wider audience for testing and feedback. I have cursor flag rules as probationary, it’s not required, but won’t impact anything. All my rules attempt to find the latest date. It isn’t consistent. If anyone has tips, I’d love to hear them.

First the description:

Timestamp System Documentation

Overview

The timestamp system is an integral part of the codebase’s safety and tracking mechanisms, implemented through two main components:

1. Timestamp Files

Two files are maintained in the .cursor directory:

  • .cursor/current_timestamp - Human readable format
  • .cursor/current_timestamp_iso - Machine readable ISO format

2. Rule Implementation

Timestamp Execution Rule

name: timestamp_execution
description: Execute timestamp script at the start of new sessions and chats

Triggers:
- Session start
- Chat start

Actions:
- Executes timestamp generation
- Updates timestamp files
- Provides utility access methods

Edit Safety Checks Rule

name: edit_safety_checks
status: probationary (v0.1-beta)
description: Enforces strict safety checks for file modifications

Dependencies:
- timestamp-execution rule
- Requires valid timestamp files

Usage Methods

1. Direct File Access

# Human readable timestamp
with open('.cursor/current_timestamp') as f:
    timestamp = f.read().strip()

# ISO format timestamp
with open('.cursor/current_timestamp_iso') as f:
    iso_timestamp = f.read().strip()

2. Utility Class Method

from src.agents.utils.date_utils import DateManager

# Get current UTC time
now = DateManager.get_current_utc()

# Format for display
timestamp = DateManager.format_for_display(now)

Integration Points

1. Code Editing

Required metadata format for edits:

EDIT METADATA
Timestamp: {from .cursor/current_timestamp}
ISO: {from .cursor/current_timestamp_iso}
File: {file_path}
Location: {class/method name}
Type: {addition|modification|deletion}
Risk: {LOW|MEDIUM|HIGH}
Size: +{x}/-{y} lines

2. Safety Checks

  • Verifies timestamp presence
  • Validates timestamp currency
  • Ensures timestamp consistency
  • Requires metadata inclusion

Implementation Notes

  • The actual timestamp generation script (scripts/get_timestamp.sh) appears to be handled internally by Cursor
  • The system is designed to maintain a consistent audit trail of code modifications
  • Timestamps are used to enforce edit safety and maintain modification history

Last Updated

{from .cursor/current_timestamp}

For me this lives in, .cursor/rules/edit_safety_checks.mdc

PROBATIONARY RULE v0.1-beta

This rule is under evaluation for effectiveness and may be modified based on results.

name: edit_safety_checks
description: Enforces strict safety checks for file modifications

filters:

  • type: event
    pattern: “(file_edit|file_create|file_delete)”
  • type: content
    pattern: “(class|def|async def|#|""")”

actions:

  • type: verify
    conditions:

    • pattern: “.cursor/current_timestamp”
      action: “read”
      message: “Cannot proceed without valid timestamp”
    • pattern: “.cursor/current_timestamp_iso”
      action: “read”
      message: “Cannot proceed without valid ISO timestamp”
  • type: suggest
    message: |
    Required Edit Format:

    EDIT METADATA
    Timestamp: {from .cursor/current_timestamp}
    ISO: {from .cursor/current_timestamp_iso}
    File: {file_path}
    Location: {class/method name}
    Type: {addition|modification|deletion}
    Risk: {LOW|MEDIUM|HIGH}
    Size: +{x}/-{y} lines
    
  • type: validate
    on_events: [“file_edit”]
    steps:

    • read_timestamp: “.cursor/current_timestamp”
    • read_iso: “.cursor/current_timestamp_iso”
    • verify_timestamps_match: true
    • verify_timestamps_current: true
    • require_metadata: true
  • type: reject
    conditions:

    • pattern: “(?<!// \.\.\.\s)existing code(?!\s\.\.\.)”
      message: “Must use proper ‘// … existing code …’ markers”
    • pattern: “.{30,}”
      message: “Edit too large - requires explicit confirmation”
    • pattern: “^(?!Timestamp: )”
      message: “Edit must start with current timestamp”

examples:

  • input: |
    EDIT METADATA
    Timestamp: 2024-03-21 15:30:45 EDT
    ISO: 2024-03-21T19:30:45Z
    File: src/utils/logger.py
    Location: Logger.log_error
    Type: modification
    Risk: LOW
    Size: +2/-0 lines

    // … existing code …
    def log_error(self, message: str) → None:
    logger.debug(“Processing error message”)
    logger.error(f"Error: {message}")
    // … existing code …
    output: “Valid edit with proper timestamp integration”

metadata:
priority: high
version: “0.1-beta”
status: “probationary”

For completeness, the timestamp script:
#!/bin/bash

Script: get_timestamp.sh

Description: Generates and updates timestamp files for the project

This script creates/updates two timestamp files:

- .cursor/current_timestamp (human readable)

- .cursor/current_timestamp_iso (machine readable ISO format)

Ensure .cursor directory exists

mkdir -p .cursor

Get current timestamp in different formats

HUMAN_READABLE=$(date ‘+%Y-%m-%d %H:%M:%S %Z’)
ISO_FORMAT=$(date -u ‘+%Y-%m-%dT%H:%M:%SZ’)

Update the timestamp files

echo “$HUMAN_READABLE” > .cursor/current_timestamp
echo “$ISO_FORMAT” > .cursor/current_timestamp_iso

Make the files read-only to prevent accidental modifications

chmod 444 .cursor/current_timestamp
chmod 444 .cursor/current_timestamp_iso

Output the current timestamps

echo “Timestamps updated:”
echo “Human readable: $HUMAN_READABLE”
echo “ISO format : $ISO_FORMAT”

Verify files were created

if [ -f .cursor/current_timestamp ] && [ -f .cursor/current_timestamp_iso ]; then
echo “:white_check_mark: Timestamp files successfully updated”
exit 0
else
echo “:x: Error: Failed to update timestamp files”
exit 1
fi