Cannot add custom cursor rules

cursor is trying to add a cursor rule and it it fails time and time again
it cannot

  • The file is being created but the content is not being saved correctly
  • We’ve tried multiple approaches:
  • Basic PowerShell commands
  • System.IO methods
  • edit_file tool
  • Here-strings
  • Explicit encoding

Changelog

[1.0.0] - 2024-02-23

Initial Setup

  1. Created .cursor/rules directory structure:
New-Item -Path ".cursor/rules" -ItemType Directory -Force

File Creation Attempts

  1. First attempt - Basic file creation:
Set-Content -Path ".cursor/rules/tremor-rules.mdc" -Value "---\ndescription: Tremor component standards..."
  1. Second attempt - Using PowerShell here-string:
$content = @'
---
description: Tremor component standards...
'@ | Out-File -FilePath ".cursor/rules/tremor-rules.mdc" -Encoding utf8
  1. Third attempt - Using System.IO:
[System.IO.File]::WriteAllText((Join-Path (Get-Location) ".cursor/rules/tremor-rules.mdc"), "---\r\ndescription...")
  1. Fourth attempt - Comprehensive PowerShell script with verification:
# 1. First ensure we're in the right directory and create the structure
$ruleDir = ".cursor/rules"
New-Item -Path $ruleDir -ItemType Directory -Force

# 2. Create the content with proper formatting
$content = @'
---
description: "Tremor component standards and best practices"
version: "1.0.0"
author: "Supermaven"
enforcement: "error"
globs:
  - "**/*.tsx"
  - "**/*.ts"
metadata:
  category: "components"
  framework: "tremor"
  integration: "react"
---
'@

# 3. Write the file with explicit encoding and line endings
$filePath = Join-Path $ruleDir "tremor-rules.mdc"
[System.IO.File]::WriteAllText(
    [System.IO.Path]::GetFullPath($filePath),
    $content.Replace("`r`n", "`n"),
    [System.Text.UTF8Encoding]::new($false) # $false ensures no BOM
)

# 4. Verify the file was created correctly
$verification = Get-Content -Path $filePath -Raw
if ($verification -match '^---\r?\ndescription:') {
    Write-Host "File created successfully with proper frontmatter"
} else {
    throw "File verification failed"
}
  1. Final successful attempt - Using edit_file tool with proper formatting and content

Validation Script Development

  1. Created initial validation script:
// .cursor/rules/validate-tremor.ts
import { readFileSync } from 'fs';
import { resolve } from 'path';
import * as yaml from 'yaml';
  1. Added TypeScript interfaces:
interface TremorRule {
  enforcement: 'error' | 'warning' | 'off';
  description: string;
  rules: string[];
}

interface TremorRules {
  description: string;
  version: string;
  author: string;
  enforcement: string;
  globs: string[];
  metadata: {
    category: string;
    framework: string;
    integration: string;
  };
}
  1. Implemented validation checks for:
    • Frontmatter validation
    • Required sections check
    • Enforcement levels validation
    • Code examples verification
    • Schema validation

Package.json Updates

  1. Added validation script:
{
  "scripts": {
    "validate:tremor": "ts-node .cursor/rules/validate-tremor.ts"
  }
}
  1. Added required dependencies:
npm install --save-dev yaml ts-node

Debugging and Fixes

  1. Fixed file encoding issues:

    • Removed BOM markers
    • Standardized line endings to LF
    • Fixed YAML frontmatter formatting
  2. Fixed content structure:

    • Removed duplicate frontmatter
    • Added proper spacing between sections
    • Fixed code block formatting
  3. Enhanced validation script:

    • Added debug logging
    • Improved error handling
    • Added detailed error messages

Final Structure

  • .cursor/rules/
    • tremor-rules.mdc - Main rules file with 11 sections
    • validate-tremor.ts - Validation script
    • CHANGELOG.md - This changelog file

Current Status

  • :white_check_mark: Directory creation successful
  • :white_check_mark: File creation successful
  • :white_check_mark: Content addition successful
  • :white_check_mark: YAML package installed
  • :white_check_mark: Package.json script added
  • :white_check_mark: Validation script created
  • :x: Validation script still showing frontmatter parsing issues (under investigation)

Issues Encountered

  1. File encoding issues with PowerShell commands
  2. Duplicate frontmatter creation
  3. YAML parsing errors
  4. Line ending inconsistencies
  5. Content persistence issues

Next Steps

  1. Debug YAML frontmatter parsing in validate-tremor.ts
  2. Add more comprehensive error reporting
  3. Consider adding unit tests for validation script
  4. Add automated file encoding checks
  5. Implement backup/restore functionality