| name | serena-safe-refactor |
| description | Safe refactoring workflow using Serena tools - analyzes impact, finds references, and performs safe code transformations |
| trigger | auto |
| domain | refactoring |
| tools | {"serena_find_symbol":true,"serena_find_referencing_symbols":true,"serena_replace_symbol_body":true,"serena_rename_symbol":true,"serena_replace_content":true} |
Serena Safe Refactor
Automated refactoring workflow that ensures safety by analyzing impact before making changes.
When to Apply
- Renaming functions or classes
- Changing function signatures
- Extracting or moving code
- Large-scale refactoring operations
Workflow
Phase 1: Impact Analysis
- Use
serena_find_symbol to locate the target
- Use
serena_find_referencing_symbols to find all usages
- Review impact scope
Phase 2: Preparation
- Check for tests covering the target code
- Identify potential breaking changes
- Plan migration strategy if needed
Phase 3: Execution
- Use
serena_rename_symbol for safe renaming
- Use
serena_replace_symbol_body for implementation changes
- Use
serena_replace_content for pattern-based changes
Phase 4: Verification
- Run tests to verify changes
- Check for compilation errors
- Review affected files
Best Practices
- Always find references before refactoring
- Make atomic changes - one symbol at a time
- Verify with tests after each change
- Use
rename_symbol instead of replace_content when possible
Safety Checklist
Example Usage
const workflow = [
'serena_find_symbol("oldFunctionName")',
'serena_find_referencing_symbols("oldFunctionName")',
'serena_rename_symbol("oldFunctionName", "newFunctionName")',
];
Context
- Learned from repeated refactoring patterns
- Emphasizes safety and impact analysis
- Confidence: High (based on 5+ observed usages)