planning-refactor
Skill5 starsChanged 17 days agoMITView on GitHub
Planning skill for refactoring - improves existing code following best practices, reduces duplication, improves readability and testability
In this repository50 other files it gives its agents.
- analyze-pr-commentsSkill
- architecture-analyzeSkill
- architecture-tradeoffSkill
- askSkill
- code-smellsSkill
- debugging-rocprof-sysSkill
- exploration-explore-codeSkill
- git-commitSkill
- git-gh-clientSkill
- git-prepare-pull-requestSkill
- git-pull-request-statusSkill
- gitSkill
- grill-meSkill
- library-amd-smiSkill
- notify-meSkill
- planning-architectureSkill
- planning-baseSkill
- planning-bugfixSkill
- planning-docsSkill
- planning-featureSkill
- programming-cmake-best-practicesSkill
- programming-cpp-constexprSkill
- programming-cpp-design-patternsSkill
- programming-cpp-naming-rulesSkill
- programming-cpp-policy-based-diSkill
- programming-cppSkill
- programming-cpp-stl-algorithmsSkill
- programming-pythonSkill
- pr-review-interactiveSkill
- pr-reviewSkill
- radisha-create-skillSkill
- radisha-helpSkill
- radisha-improve-skillSkill
- radisha-skillsSkill
- radisha-updateSkill
- refactoring-techniquesSkill
- review-architectureSkill
- rocprofsys-buildSkill
- rocprofsys-configureSkill
- rocprofsysSkill
- static-analysisSkill
- testing-gtest-gmockSkill
- testing-pytestSkill
- testing-testplanSkill
- therock-build-to-commitSkill
- therock-commit-in-buildSkill
- therock-first-build-with-commitSkill
- update-pr-descriptionSkill
- verify-pmc-metricsSkill
- watchSkill
The file
We split this skill into the rules it gives an agent
12 rules. About 0 are common, 11 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 8
Use this skill when improving EXISTING code without changing its external behavior.
- Distinctive: line 13
Follow all base planning rules, plus the refactoring-specific rules below.
- Distinctive: line 26
Every refactoring should aim for one or more of these:
- Distinctive: line 67
Check if any design pattern fits:
- Distinctive: line 85
After analysis, ASK the user:
- Distinctive: line 217
After COMPLETING the refactoring:
- Distinctive: line 221
Document verification that behavior is unchanged
- Distinctive: line 234
Follow the test planning process from that skill
- Distinctive: line 235
Write tests ONE BY ONE, waiting for user approval after each test
- Distinctive: line 236
Update test plan file with test status
- Distinctive: line 240
After tests (if any), ASK the user:
- Very specific: line 244
If yes, invoke git-create-pull-request skill and create PR with:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Refactoring Planning
Use this skill when improving EXISTING code without changing its external behavior.
<IMPORTANT>
**Prerequisites:** Invoke `planning-base` skill first if not already loaded. It provides the core planning phases (0-5).Follow all base planning rules, plus the refactoring-specific rules below.
Mandatory: Invoke and apply ALL relevant skills during refactoring:
code-smells- Identify WHAT to fix (smell detection)refactoring-techniques- HOW to fix it (60+ techniques with examples)programming-cpp- C++ best practices, performance, testabilityprogramming-cpp-design-patterns- Suggest applicable patternsprogramming-cpp-stl-algorithms- Replace loops with STL algorithmsprogramming-cmake-best-practices- Modern CMake practices</IMPORTANT>
Refactoring Goals
Every refactoring should aim for one or more of these:
| Goal | Description |
| Best Practices | Apply C++ Core Guidelines, modern C++17 features |
| Reduce Duplication | Extract common code, apply DRY principle |
| Improve Readability | Better naming, smaller functions, clearer intent |
| Testability | Dependency injection, policy-based design, pure functions |
| Performance | Compile-time computation, cache-friendly, zero-cost abstractions |
Refactoring-Specific Analysis
Code Smell Detection
During analysis, actively look for these code smells:
Duplication:
- Copy-pasted code blocks
- Similar functions with minor differences
- Repeated patterns that could be templates
Complexity:
- Long functions (> 30 lines)
- Deep nesting (> 3 levels)
- God classes (too many responsibilities)
- Long parameter lists
Poor Abstractions:
- Raw loops instead of STL algorithms
- Manual memory management instead of RAII
- Inheritance where composition fits better
- Missing interfaces for testability
C++ Specific:
- Missing
const,constexpr,noexcept - Unnecessary copies (missing move semantics)
- Raw pointers for ownership
- C-style casts
Design Pattern Opportunities
Check if any design pattern fits:
- Strategy - Multiple algorithms/behaviors
- Factory - Complex object creation
- Adapter - Interface mismatch
- Decorator - Adding behavior dynamically
- Template Method - Algorithm skeleton with variable steps
STL Algorithm Opportunities
Replace manual loops with:
std::find,std::find_if- searchingstd::transform- mappingstd::accumulate- reducingstd::copy_if- filteringstd::any_of,std::all_of- predicates
Changelog Consideration
After analysis, ASK the user:
"Should this refactoring be added to the changelog?
- Yes: If it's a significant improvement users should know about
- No: If it's internal cleanup with no user impact
Add to changelog? (yes/no)"
If yes:
## Changelog Entry
### Changed
- <Brief description of what was refactored and why>Plan File Format
Save to planning/refactor-<name>.md:
# Refactor: <Component/Area Name>
## Goal
<What is being refactored and why>
## Code Smells Identified
- [ ] <Smell 1>: <Location and description>
- [ ] <Smell 2>: <Location and description>
## Refactoring Strategy
### Best Practices to Apply
- <Guideline 1>
- <Guideline 2>
### Design Patterns to Use
- <Pattern>: <Where and why>
(or "No patterns needed")
### STL Algorithms to Apply
- Replace <loop description> with <algorithm>
(or "No algorithm replacements")
## Tasks
- [ ] Task 1
- [ ] Task 2
- [ ] Verify behavior unchanged (tests pass)
- [ ] Verify no new warnings/errors
## Testability Improvements
- <How code will be more testable>
(or "Already testable")
## Changelog
<Entry if requested, or "Not added to changelog">
## Notes
<Any additional context or decisions>Example
User request: "Refactor the parser module - it's hard to test and has lots of duplication"
Planning output:
# Refactor: Parser Module
## Goal
Improve testability and reduce code duplication in the parser module
## Code Smells Identified
- [ ] Duplication: `parse_int()` and `parse_float()` share 80% of code
- [ ] Untestable: `parser` class creates its own `file_reader` internally
- [ ] Long function: `parse_expression()` is 150 lines with deep nesting
- [ ] Raw loops: Manual iteration in `parse_tokens()` instead of STL
## Refactoring Strategy
### Best Practices to Apply
- F.2: Functions should perform single logical operation
- I.1: Make interfaces explicit (inject dependencies)
- Use `std::string_view` for read-only string params
- Add `[[nodiscard]]` to parsing functions
### Design Patterns to Use
- **Strategy**: Extract number parsing into policy template
- **Dependency Injection**: Inject `i_reader` interface for testability
### STL Algorithms to Apply
- Replace token search loop with `std::find_if`
- Replace validation loop with `std::all_of`
## Tasks
- [ ] Extract `i_reader` interface from `file_reader`
- [ ] Inject reader dependency into `parser` constructor
- [ ] Create `parse_number<T>` template to unify int/float parsing
- [ ] Split `parse_expression()` into smaller functions
- [ ] Replace manual loops with STL algorithms
- [ ] Add `const`, `noexcept`, `[[nodiscard]]` where appropriate
- [ ] Verify all existing tests still pass
## Testability Improvements
- Parser can now be tested with mock reader
- Smaller functions are easier to unit test
- Pure parsing functions can be tested in isolation
## Changelog
### Changed
- Refactored parser module for improved testability and maintainability
## Notes
- Keep public API unchanged
- Existing tests must pass without modificationSafety Rules
<IMPORTANT>
Refactoring MUST NOT change external behavior:- Run tests before AND after each refactoring step
- Small incremental changes - one smell at a time
- Commit frequently - easy to rollback if something breaks
- If tests fail - revert and analyze before proceeding
</IMPORTANT>
Test Plan
After COMPLETING the refactoring:
- Create test plan file:
planning/testplan-<refactor-name>.md - Invoke
testing-testplanskill for the template - Document verification that behavior is unchanged
- Include regression checks for all affected functionality
Test Consideration
Then ASK the user:
"Refactoring is complete. Would you like to add/improve unit tests?
- The code is now easier to test due to dependency injection
- Are there functions not covered by tests?"
If user agrees:
- Invoke the testing skill:
testing-gtest-gmock(C++) ortesting-pytest(Python) - Follow the test planning process from that skill
- Write tests ONE BY ONE, waiting for user approval after each test
- Update test plan file with test status
Pull Request
After tests (if any), ASK the user:
"Ready to create a Pull Request. Should I proceed?"
If yes, invoke git-create-pull-request skill and create PR with:
- Motivation - Why refactoring was needed (code smells, testability, etc.)
- Technical Details - What was changed and design decisions
- Test Plan - Verification that behavior is unchanged
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

