claude-task-master icon indicating copy to clipboard operation
claude-task-master copied to clipboard

`learn` command to automatically create or improve Cursor rules

Open eyaltoledano opened this issue 9 months ago • 5 comments

Implement learn Command for Automatic Cursor Rule Generation

Background

Inspired by this tweet

We currently maintain a few Taskmaster-specific Cursor rules in .cursor/rules/*.mdc files that guide Cursor's task management. There are no other rules for actual code implementation. These rules are manually added and updated by the user after successful implementations. We want to automate this process by creating a learn command that analyzes Cursor's chat history and automatically updates or creates rules based on successful patterns.

I think we can do this using the user's local Cursor client history and getting the latest edits that led to a successful implementation, as well as the full chat history for context. Then we can call this learn command every time a task is marked as completed to capture any new learnings and ensure things are done properly and using that new stuff.

Current Process

  1. Complete a development task using Cursor
  2. Manually review chat history for successful patterns
  3. Update relevant .mdc files in .cursor/rules/
  4. Reference cursor_rules.mdc for proper formatting

Proposed Solution

Create a learn command that:

  1. Accesses Cursor's chat history from ~/Library/Application Support/Cursor/User/History
  2. Analyzes the history for successful implementation patterns & diff's performed by the Cursor Agent
  3. Updates or creates rule files following the cursor_rules.mdc template
  4. Can be triggered automatically after task completion or manually via CLI

Technical Details

Key Files

  • commands/learn.js: Main command implementation
  • rules/cursor-rules-manager.js: Rule file management
  • utils/chat-history-analyzer.js: Chat history analysis
  • utils/cursor-path-helper.js: Path management utilities

Core Components

  1. Chat History Analysis

    • Read from ~/Library/Application Support/Cursor/User/History
    • Parse entries.json and associated .js files
    • Extract successful patterns and corrections
  2. Rule Management

    • Use cursor_rules.mdc as template
    • Validate rule file structure
    • Handle rule categorization
    • Manage rule updates
  3. AI Integration

    • Use ai-services.js for Claude interaction
    • Build context-aware prompts
    • Process AI responses into rule updates

Implementation Plan

[Detailed subtasks in tasks/task_032.txt]

Usage

Automatic Mode

# Automatically triggered after task completion
task-master set-status --status=complete --id=<task-id>  # Will trigger learn if enabled

Manual Mode

# Manual trigger
task-master learn

Configuration -- just an example, not literal

// either in the .env file or we should start having a .taskmasterconfig file somewhere
{
  "autoLearnOnComplete": true,  // Enable automatic learning
  "learnConfig": {
    "ruleTemplate": "cursor_rules.mdc",
    "minHistoryAge": "1h",      // Minimum history to consider
    "categories": ["testing", "components", "api"]
  }
}

Success Criteria

  1. Successfully reads and parses Cursor chat history
  2. Correctly identifies and extracts successful patterns
  3. Generates/updates rules following cursor_rules.mdc format
  4. Maintains existing rule quality while adding improvements
  5. Performs efficiently with large chat histories
  6. Handles errors gracefully
  7. Provides clear feedback on changes made

Security Considerations

  • Safe file system operations
  • Proper error handling for inaccessible files
  • Validation of generated rules
  • Backup of existing rules before updates

Performance Requirements

  • Handle large chat histories efficiently
  • Complete analysis within reasonable time
  • Minimize memory usage
  • Implement caching where appropriate

Future Enhancements

  1. Pattern confidence scoring
  2. Rule conflict resolution
  3. Rule effectiveness tracking
  4. Integration with other Cursor features

Related

  • Original tweet: Link
  • Task Master documentation
  • Cursor rules documentation

Notes

  • Access to Cursor's chat history is crucial for this feature
  • The command should work both automatically and manually
  • Rule updates should be non-destructive
  • Clear logging of changes is essential

eyaltoledano avatar Mar 26 '25 19:03 eyaltoledano

Was suggested to incorporate some if these concepts as well https://github.com/bmadcode/cursor-custom-agents-rules-generator

We should invite @bmadcode to come build Taskmaster with us :)

eyaltoledano avatar Apr 04 '25 16:04 eyaltoledano

It may be good to offer an input flag to let it learn off of a PRD. This would be good for an initial phase before task begin to get worked on if the PRD includes code samples and patterns.

joedanz avatar Apr 08 '25 16:04 joedanz

Needs to be rethought now that Cursor has the ability to generate cursor rules. Not sure if we can hook into that in any way.

eyaltoledano avatar Apr 16 '25 21:04 eyaltoledano

Needs to be rethought now that Cursor has the ability to generate cursor rules. Not sure if we can hook into that in any way.

Maybe through sampling ?

Maybe instead of using "learn" as a tool, we could introduce sampling in our MCP server and have it generate a PRD through that ?

Crunchyman-ralph avatar Apr 16 '25 21:04 Crunchyman-ralph

Can this also soak in "best practices" from other places, and log them in a way that is organized, such that these meta-prompts can be project-independent?

BradKML avatar May 15 '25 05:05 BradKML