# Undo/Redo System **Status**: ✅ Complete **Phase**: Phase 6 **Last Updated**: December 6, 2025 --- ## Overview The Undo/Redo System provides comprehensive operation history management, enabling you to navigate through your work history, undo/redo changes, create snapshots, and branch from any point in history. **Key Benefit**: Experiment confidently knowing you can always undo changes. --- ## Key Features - **Complete History**: Full history of all operations - **Undo/Redo**: Navigate forward and backward through history - **Branching**: Create branches from any point in history - **Snapshots**: Save and restore project snapshots - **Conflict Resolution**: Handle conflicts when undoing/redoing - **History Visualization**: View operation history graphically - **Selective Undo**: Undo specific operations without affecting others --- ## Quick Start ### Basic Undo/Redo ```bash # Perform operations ricecoder generate --domain frontend ricecoder refactor --pattern hooks # Undo last operation ricecoder undo # Redo last undone operation ricecoder redo # Undo multiple operations ricecoder undo --count 3 # Redo multiple operations ricecoder redo --count 2 ``` ### View History ```bash # Show operation history ricecoder history show # Show history with details ricecoder history show --verbose # Show history for specific domain ricecoder history show --domain frontend # Export history ricecoder history export --format json > history.json ``` ### Create Snapshots ```bash # Create snapshot ricecoder snapshot create --name "Before refactoring" # List snapshots ricecoder snapshot list # Restore snapshot ricecoder snapshot restore # Delete snapshot ricecoder snapshot delete ``` --- ## Operation History ### Viewing History ```bash # Show all operations ricecoder history show # Output: # 1. generate --domain frontend (2025-12-06 10:30:00) # 2. refactor --pattern hooks (2025-12-06 10:35:00) # 3. test --domain frontend (2025-12-06 10:40:00) ``` ### History Details ```bash # Show detailed history ricecoder history show --verbose # Output: # Operation 1: generate # Domain: frontend # Template: react-component # Duration: 2.5s # Status: success # Files Changed: 5 # Lines Added: 150 # Lines Removed: 0 ``` ### Filtering History ```bash # History for specific domain ricecoder history show --domain frontend # History for specific action ricecoder history show --action generate # History for time period ricecoder history show --since 2025-12-01 # History for last N operations ricecoder history show --last 10 ``` --- ## Undo/Redo Operations ### Undoing Changes ```bash # Undo last operation ricecoder undo # Undo last 3 operations ricecoder undo --count 3 # Undo to specific point ricecoder undo --to # Undo specific operation ricecoder undo --operation ``` ### Redoing Changes ```bash # Redo last undone operation ricecoder redo # Redo last 3 undone operations ricecoder redo --count 3 # Redo to specific point ricecoder redo --to ``` ### Selective Undo ```bash # Undo specific operation without affecting others ricecoder undo --operation --selective # Undo operations matching pattern ricecoder undo --pattern "refactor" --selective # Undo operations for specific domain ricecoder undo --domain frontend --selective ``` --- ## Snapshots ### Creating Snapshots ```bash # Create snapshot with description ricecoder snapshot create --name "Before refactoring" \ --description "Snapshot before major refactoring" # Create snapshot with tags ricecoder snapshot create --name "v1.0" --tags "release,stable" # Create snapshot automatically ricecoder snapshot create --auto --interval 1h ``` ### Managing Snapshots ```bash # List all snapshots ricecoder snapshot list # Show snapshot details ricecoder snapshot show # Compare snapshots ricecoder snapshot compare # Rename snapshot ricecoder snapshot rename --name "New name" # Add tags to snapshot ricecoder snapshot tag --add "tag1,tag2" # Delete snapshot ricecoder snapshot delete # Delete old snapshots ricecoder snapshot delete --older-than 30d ``` ### Restoring Snapshots ```bash # Restore snapshot ricecoder snapshot restore # Restore snapshot to specific location ricecoder snapshot restore --to ./backup # Preview snapshot before restoring ricecoder snapshot restore --dry-run # Restore with conflict resolution ricecoder snapshot restore --on-conflict merge ``` --- ## Branching ### Creating Branches ```bash # Create branch from current point ricecoder history branch --name "experimental" # Create branch from specific operation ricecoder history branch --from --name "feature-x" # List branches ricecoder history branches # Switch branch ricecoder history switch-branch ``` ### Managing Branches ```bash # Show current branch ricecoder history current-branch # Show branch history ricecoder history show --branch # Merge branches ricecoder history merge # Delete branch ricecoder history delete-branch ``` --- ## Conflict Resolution ### Detecting Conflicts ```bash # Check for conflicts ricecoder history check-conflicts # Show conflicts ricecoder history show-conflicts # Resolve conflicts ricecoder history resolve-conflicts ``` ### Resolving Conflicts ```bash # Resolve conflict interactively ricecoder history resolve-conflicts --interactive # Resolve conflict with strategy ricecoder history resolve-conflicts --strategy merge # Resolve specific conflict ricecoder history resolve-conflict --with ``` --- ## Configuration ### Undo/Redo Configuration Add to `.ricecoder/config.yaml`: ```yaml undo_redo: # Enable undo/redo system enabled: true # Maximum history size (operations) max_history: 1000 # History retention period (days) retention_days: 90 # Auto-create snapshots auto_snapshot: true auto_snapshot_interval: 3600 # seconds # Conflict resolution strategy conflict_strategy: "merge" # merge, ours, theirs # Enable branching branching_enabled: true ``` ### Snapshot Configuration ```yaml snapshots: # Snapshot storage location storage_path: ".ricecoder/snapshots" # Maximum snapshots to keep max_snapshots: 50 # Snapshot retention period (days) retention_days: 365 # Compress snapshots compress: true # Encryption encrypt: false ``` --- ## Common Workflows ### Workflow 1: Safe Experimentation ```bash # Create snapshot before experimenting ricecoder snapshot create --name "Before experiment" # Perform experimental changes ricecoder generate --domain frontend --experimental ricecoder refactor --pattern experimental # If experiment fails, restore snapshot ricecoder snapshot restore # If experiment succeeds, keep changes ricecoder snapshot delete ``` ### Workflow 2: Feature Development ```bash # Create branch for feature ricecoder history branch --name "feature-x" # Develop feature ricecoder generate --domain frontend ricecoder refactor --pattern hooks ricecoder test --domain frontend # Switch back to main ricecoder history switch-branch main # Merge feature branch ricecoder history merge feature-x ``` ### Workflow 3: Rollback on Error ```bash # Perform operations ricecoder generate --domain frontend ricecoder refactor --pattern microservices # Error detected, undo last operation ricecoder undo # Undo more if needed ricecoder undo --count 2 # Or restore to snapshot ricecoder snapshot restore ``` --- ## Best Practices ### For Undo/Redo 1. **Create Snapshots**: Create snapshots before major changes 2. **Use Descriptive Names**: Use descriptive snapshot names 3. **Review History**: Periodically review operation history 4. **Clean Up**: Delete old snapshots to save space ### For Branching 1. **Use Branches for Experiments**: Create branches for experimental work 2. **Merge Carefully**: Review changes before merging 3. **Delete Old Branches**: Delete branches after merging 4. **Document Branches**: Document branch purpose ### For Conflict Resolution 1. **Understand Conflicts**: Understand what caused conflicts 2. **Review Changes**: Review changes before resolving 3. **Test After Resolution**: Test after resolving conflicts 4. **Document Resolution**: Document how conflicts were resolved --- ## Troubleshooting ### Undo Not Working **Problem**: Undo command doesn't work **Solutions**: - Check if undo/redo is enabled: `ricecoder config get undo_redo.enabled` - Check history: `ricecoder history show` - Check for conflicts: `ricecoder history check-conflicts` ### Snapshot Restore Failed **Problem**: Snapshot restore fails **Solutions**: - Check snapshot exists: `ricecoder snapshot list` - Check snapshot integrity: `ricecoder snapshot verify ` - Try restore with conflict resolution: `ricecoder snapshot restore --on-conflict merge` ### Merge Conflicts **Problem**: Merge conflicts when merging branches **Solutions**: - Resolve conflicts interactively: `ricecoder history resolve-conflicts --interactive` - Use merge strategy: `ricecoder history merge --strategy merge` - Abort merge: `ricecoder history merge --abort` --- ## Advanced Topics ### Custom Conflict Resolution Define custom conflict resolution strategies: ```yaml # In .ricecoder/conflict-strategies.yaml strategies: - name: "custom-merge" rules: - pattern: "*.json" strategy: "merge" - pattern: "*.yaml" strategy: "ours" - pattern: "*.md" strategy: "theirs" ``` ### History Visualization Visualize operation history: ```bash # Show history graph ricecoder history graph # Export history graph ricecoder history graph --export dot > history.dot # Visualize with graphviz dot -Tpng history.dot -o history.png ``` ### Integration with CI/CD Use undo/redo in CI/CD: ```yaml # GitHub Actions example - name: Create snapshot before deployment run: ricecoder snapshot create --name "pre-deployment" - name: Deploy run: ./deploy.sh - name: Rollback on failure if: failure() run: ricecoder snapshot restore pre-deployment ``` --- ## See Also - [Orchestration](./Orchestration.md) - Multi-project management - [Learning System](./Learning-System.md) - System learns from your usage - [Architecture Overview](./Architecture-Overview.md) - System architecture - [Configuration Guide](./Configuration.md) - Configuration reference - [CLI Commands](./CLI-Commands.md) - Command reference --- *Last updated: December 6, 2025*