`learn` command to automatically create or improve Cursor rules
Implement learn Command for Automatic Cursor Rule Generation
Background
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
- Complete a development task using Cursor
- Manually review chat history for successful patterns
- Update relevant
.mdcfiles in.cursor/rules/ - Reference
cursor_rules.mdcfor proper formatting
Proposed Solution
Create a learn command that:
- Accesses Cursor's chat history from
~/Library/Application Support/Cursor/User/History - Analyzes the history for successful implementation patterns & diff's performed by the Cursor Agent
- Updates or creates rule files following the
cursor_rules.mdctemplate - 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
-
Chat History Analysis
- Read from
~/Library/Application Support/Cursor/User/History - Parse
entries.jsonand associated.jsfiles - Extract successful patterns and corrections
- Read from
-
Rule Management
- Use
cursor_rules.mdcas template - Validate rule file structure
- Handle rule categorization
- Manage rule updates
- Use
-
AI Integration
- Use
ai-services.jsfor Claude interaction - Build context-aware prompts
- Process AI responses into rule updates
- Use
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
- Successfully reads and parses Cursor chat history
- Correctly identifies and extracts successful patterns
- Generates/updates rules following
cursor_rules.mdcformat - Maintains existing rule quality while adding improvements
- Performs efficiently with large chat histories
- Handles errors gracefully
- 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
- Pattern confidence scoring
- Rule conflict resolution
- Rule effectiveness tracking
- 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
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 :)
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.
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.
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 ?
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?