learn command to automatically create or improve Cursor rules #1113

Open
opened 2025-10-14 16:53:44 -06:00 by navan · 0 comments
Owner

Originally created by @eyaltoledano on 3/26/2025

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
  • 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
*Originally created by @eyaltoledano on 3/26/2025* # Implement `learn` Command for Automatic Cursor Rule Generation ## Background [Inspired by this tweet](https://x.com/eyaltoledano/status/1904971536668237902?s=61&t=eg2S6tM6zg--91fHqauJxw) 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 ```bash # Automatically triggered after task completion task-master set-status --status=complete --id=<task-id> # Will trigger learn if enabled ``` ### Manual Mode ```bash # Manual trigger task-master learn ``` ### Configuration -- just an example, not literal ```javascript // 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](https://x.com/eyaltoledano/status/1904971536668237902) - 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
navan added the
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
labels 2025-10-14 16:53:51 -06:00
Sign in to join this conversation.
No labels
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:ai-models
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:cli
area:installation
area:installation
area:installation
area:installation
area:installation
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:mcp
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:task-management
area:vscode-extension
area:vscode-extension
area:vscode-extension
area:vscode-extension
area:vscode-extension
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
bug
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
documentation
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
duplicate
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
feedback
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
good first issue
help wanted
help wanted
help wanted
help wanted
help wanted
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
high-priority
integration request
integration request
integration request
integration request
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
invalid
low-priority
low-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
medium-priority
provider:anthropic
provider:anthropic
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:claude-code
provider:gemini-cli
provider:openai
provider:perplexity
question
question
question
question
question
question
question
question
question
question
question
question
question
question
refactor
refactor
wontfix
wontfix
wontfix
wontfix
wontfix
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github/claude-task-master#1113
No description provided.