بنقرة واحدة
refactor
Safe refactoring with comprehensive test coverage
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Safe refactoring with comprehensive test coverage
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
Build the project (auto-detects build system)
Find and remove dead code, unused imports, and technical debt
Create git commits in logical groups for all current changes
Create a git commit with conventional commit message
Pick up unfinished work from where the last session left off
Debug and fix failing tests or errors
استنادا إلى تصنيف SOC المهني
| name | refactor |
| description | Safe refactoring with comprehensive test coverage |
| argument-hint | <what-to-refactor> |
Refactor code safely with tests as a safety net.
RULE: All tests must pass before AND after. No behavior changes.
$ARGUMENTS - What to refactor (file, module, pattern, etc.)Launch three agents in parallel to gather all baseline information simultaneously:
Agent A: Coverage Report
Task: Generate the test coverage report for the affected area.
Run `./gradlew koverReport` and read the coverage output.
Report the coverage percentage for every file in the refactoring scope.
Flag any file below 80% coverage.
Agent B: Baseline Tests
Task: Run the full test suite and report results.
Run `./gradlew test`.
Report pass/fail counts and list any failures with their full stack traces.
Agent C: Scope Analysis
Task: Analyze the refactoring scope for `$ARGUMENTS`.
Determine what is being refactored: single file, multiple related files, entire module, or cross-cutting pattern.
Identify and list:
- Every public API surface (public functions, classes, interfaces, data classes)
- Expected inputs and outputs for each public entry point
- Edge cases and error paths
- Integration points with other modules
- All direct dependents (files that import or reference the target)
Write findings to `.claude/plans/PLAN-refactor-scope.md`.
Wait for all three agents to complete before continuing.
Review the outputs from all three agents:
Launch parallel agents per dimension to identify every untested path. Create one agent per category:
Agent: Branch Coverage
Task: Analyze the coverage report and source code for `$ARGUMENTS`.
List every uncovered branch (if/else, when, try/catch) with file path and line numbers.
For each uncovered branch, write a one-line description of what condition triggers it.
Agent: Edge Cases
Task: Analyze the source code for `$ARGUMENTS`.
List every edge case that lacks a test: null inputs, empty collections, boundary values,
overflow conditions, concurrent access, and type coercion scenarios.
For each, specify the function and the exact edge condition.
Agent: Error Paths
Task: Analyze the source code for `$ARGUMENTS`.
List every error/exception path that lacks a test: thrown exceptions, error returns,
fallback branches, retry logic, timeout handling, and resource cleanup paths.
For each, specify the function, the error condition, and expected behavior.
Wait for all agents to complete. Merge their findings into a single prioritized list.
Tests that capture CURRENT behavior (even if it seems wrong):
# Verify new tests pass
./gradlew test
STOP IF TESTS FAIL. Fix tests until green.
Launch a planner agent (subagent_type: "planner") with the scope analysis from Phase 0 and the refactoring request. The planner will:
Then launch a verifier agent (subagent_type: "verifier") to validate the plan. Iterate until APPROVED.
Independent steps (touching different files with no dependency): launch ALL simultaneously as worktree-isolated architect agents, then merge via the consolidator.
Sequential steps (each depends on the previous): execute one at a time:
For each step:
Single, focused change:
./gradlew test
STOP IF TESTS FAIL. Fix or revert before continuing.
Delegate to the skills:commit command:
Skill(skill="skills:commit", args="(refactor): [specific change made]")
Continue with next step until refactoring complete.
Launch a reviewer agent (subagent_type: "reviewer") to review the full diff (git diff main...HEAD). Focus: behavior preservation, no accidental API changes, code quality improvement. Fix any critical/major issues found.
Launch a verifier agent (subagent_type: "verifier") in post-verification mode. It confirms: tests pass (count not decreased from baseline), lint clean, build succeeds, no behavior changes, all public APIs preserved.
// Before
fun process() {
// 20 lines of validation
// 20 lines of processing
}
// After
fun process() {
validate()
doProcessing()
}
When a class has too many responsibilities.
When names don't reflect purpose.
Extract shared logic to helper/utility.
Replace complex if/else with when, early returns, or polymorphism.
Extract constants with meaningful names.