一键导入
planning-refactor
Planning skill for refactoring - improves existing code following best practices, reduces duplication, improves readability and testability
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Planning skill for refactoring - improves existing code following best practices, reduces duplication, improves readability and testability
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Given a TheRock nightly build (URL or run-id), return the rocm-systems pin_sha used in that build
Check whether a given rocm-systems commit is included in a specific TheRock nightly build
Find the first TheRock nightly build that includes a given rocm-systems commit
Reviews Pull Requests or local diffs with an 8-agent fan-out covering static analysis, dead code, code smells + quality (naming, complexity, single-responsibility, magic numbers), language rules (C++/Python/CMake), architecture, simplification, performance (hot-path classification, allocations, locks, I/O), and undefined behaviour (signed overflow, lifetime, strict aliasing, data races, sanitizer coverage; C/C++/unsafe-Rust only). Use when the user asks to "review this PR", "review the diff", "audit this branch", "/pr-review", or when staging changes before push.
Walk through a PR review interactively, one finding at a time. Generate review via pr-review, then for each issue present analysis + proposed inline comment, let user accept/edit/skip, accumulate into a PENDING GitHub review, submit at end.
Use when user wants to list, analyze, review, or summarize GitHub PR comments on a pull request number or URL
| name | planning-refactor |
| description | Planning skill for refactoring - improves existing code following best practices, reduces duplication, improves readability and testability |
Use this skill when improving EXISTING code without changing its external behavior.
**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
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 |
During analysis, actively look for these code smells:
Duplication:
Complexity:
Poor Abstractions:
C++ Specific:
const, constexpr, noexceptCheck if any design pattern fits:
Replace manual loops with:
std::find, std::find_if - searchingstd::transform - mappingstd::accumulate - reducingstd::copy_if - filteringstd::any_of, std::all_of - predicatesAfter 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>
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>
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 modification
After COMPLETING the refactoring:
planning/testplan-<refactor-name>.mdtesting-testplan skill for the templateThen 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:
testing-gtest-gmock (C++) or testing-pytest (Python)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: