원클릭으로
refactor-consolidate
Systematically refactor, tighten, and deduplicate implementation while preserving complete functionality
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Systematically refactor, tighten, and deduplicate implementation while preserving complete functionality
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | refactor-consolidate |
| description | Systematically refactor, tighten, and deduplicate implementation while preserving complete functionality |
| license | MIT |
| compatibility | opencode |
Use this skill when:
Phase 1: IDENTIFY Phase 2: DELEGATE Phase 3: CONSOLIDATE
┌─────────────────────┐ ┌─────────────────────┐ ┌─────────────────────┐
│ Scan for: │ │ Delegate each │ │ Workers report │
│ - Duplication │ │ cleanup area with │ │ additional │
│ - Boilerplate │-> │ clear acceptance │-> │ refinement │
│ - Redundancy │ │ criteria │ │ opportunities │
│ - Structural issues │ │ │ │ │
└─────────────────────┘ └─────────────────────┘ └─────────────────────┘
Phase 4: EXECUTE Phase 5: REPORT
┌─────────────────────┐ ┌─────────────────────┐
│ Workers implement │ │ Supervisory agent │
│ approved cleanups │ │ assembles findings │
│ │ │ into final report │
└─────────────────────┘ └─────────────────────┘
| Subagent | Use for | Why |
|---|---|---|
explore | Scanning, analysis, finding opportunities | Fast, read-only — cannot modify files |
worker | Implementation (cleanups, deduplication) | Constrained executor — no scope expansion, single response |
Strategy: Determine the scope of investigation based on recent work.
The skill adapts its investigation strategy based on available context:
If you've recently delegated work, you already know which files were modified:
# Check recent git history for files you touched
git diff --name-only HEAD~5
Action: Focus scanning on:
If supervisor context is lost, extract it from recent git activity:
# Recently modified files (last N commits)
git diff --name-only HEAD~10
# Files changed in the last day
git log --since="1 day ago" --name-only --pretty=format:
# Unique, sorted
git log --since="1 day ago" --name-only --pretty=format: | sort -u
Action: Compile a list of recently touched files and focus scanning there.
If no recent work context exists, perform a systematic codebase scan:
# Identify major source directories
glob "**/*.rs" # or *.py, *.ts, etc.
Action: Scan the entire codebase or major modules systematically.
Choose your Phase 1 approach based on context availability:
| Context Available | Approach | Focus Area |
|---|---|---|
| Recent delegation history | Targeted | Recently modified files |
| Git history | Targeted | Files from recent commits |
| Neither | Broad | Entire codebase or major modules |
When to use Targeted Scanning (Phase 0A/0B):
When to use Broad Scanning (Phase 0C):
Hybrid Approach:
# 1. Start with targeted scan of recent work
# 2. Workers report "similar patterns found in [other files]"
# 3. Broaden scan to those additional files
# 4. Consolidate findings across all areas
Strategy: Scan codebase systematically for refactorable patterns.
Scope Selection:
Progress Tracking: Use todowrite to track scan progress across categories.
todowrite todos='[
{"content": "Scan for code duplication", "status": "in_progress", "priority": "high"},
{"content": "Scan for test redundancy", "status": "pending", "priority": "high"},
{"content": "Scan for boilerplate & ceremony", "status": "pending", "priority": "medium"},
{"content": "Scan for structural issues", "status": "pending", "priority": "medium"},
{"content": "Consolidate findings and prioritize", "status": "pending", "priority": "high"}
]
1. Code Duplication
2. Test Duplication
3. Boilerplate & Ceremony
4. Structural Issues
For each category, delegate focused scans:
task subagent_type=explore description="Scan for [CATEGORY]" prompt="
**SCAN FOR**: [duplication | test redundancy | boilerplate | structural issues]
**READ IMPLEMENTATION:**
- [list files/modules to scan]
**DO NOT MODIFY ANYTHING - JUST ANALYZE**
**Your Task:**
Find all instances of [CATEGORY]. For each:
1. Location: file path and line numbers
2. Current: code snippet showing the issue
3. Impact: brief assessment of cleanup benefit
4. Risk: low | medium | high (chance of breaking something)
**Categorize by Cleanup Type:**
- Mechanical: safe to automate (renames, moves, deduplication)
- Structural: needs design decision (extract module, change API)
- Tests: duplicate assertions, redundant setup
**Output Format:**
## [Category] Findings
### Finding 1
- **Location**: `path/to/file.ext:45-67`
- **Current**: [code snippet]
- **Issue**: [description]
- **Suggested**: [brief cleanup approach]
- **Risk**: low | medium | high
### Finding 2
...
**At the end of your analysis, suggest 2-3 additional areas** that might benefit from cleanup but weren't in the original scope.
"
With Recent Context (Phase 0A or 0B):
# Files identified from recent work:
# - src/auth.rs (recently modified)
# - src/auth_test.rs (recently modified)
# - src/middleware.rs (uses auth)
# Delegate targeted scans
task subagent_type=explore description="Scan auth module for duplication" prompt="
**FOCUS FILES** (recently modified):
- src/auth.rs
- src/auth_test.rs
- src/middleware.rs
**SCAN FOR**: code duplication, test redundancy, boilerplate
...
"
Without Context (Phase 0C):
# One scan per category across entire codebase
task subagent_type=explore description="Scan for code duplication"
task subagent_type=explore description="Scan for test redundancy"
task subagent_type=explore description="Scan for boilerplate"
task subagent_type=explore description="Scan for structural issues"
# Step 1: Get recently changed files
git log --since="1 day ago" --name-only --pretty=format: | sort -u
# Step 2: See what changed in each file
git log --oneline -10 -- src/auth.rs
# Step 3: See the actual diff for context
git diff HEAD~5 -- src/auth.rs
# Step 4: Compile affected files list and their dependents
# - src/parser.rs
# - src/validator.rs
# - Any files importing these (grep for use/import statements)
Strategy: Convert findings into actionable tasks with strict acceptance criteria.
Progress Tracking: Update todowrite with specific cleanup tasks from findings.
todowrite todos='[
{"content": "Scan for code duplication", "status": "completed", "priority": "high"},
{"content": "Scan for test redundancy", "status": "completed", "priority": "high"},
{"content": "Deduplicate process_x/process_y in file_a/file_b", "status": "in_progress", "priority": "high"},
{"content": "Consolidate test setup in test_a/test_b", "status": "pending", "priority": "medium"},
{"content": "Remove unused imports in module_c", "status": "pending", "priority": "low"}
]
Each cleanup task must include:
**CLEANUP TASK**: [Brief description]
**Scope**: Mechanical | Structural | Test
**Current State**:
[code snippet showing duplication/boilerplate]
**Target State**:
[what it should look like after cleanup]
**Acceptance Criteria** (MUST be verifiable):
1. [Specific criterion - e.g., "Function extracted to shared module"]
2. [Specific criterion - e.g., "All existing tests still pass"]
3. [Specific criterion - e.g., "No references to old duplicated code"]
**Verification Steps**:
1. Run test suite: [command]
2. Verify no regressions: [how to check]
3. Review changed files: [what to look for]
**Preservation Requirements**:
- All test assertions must be preserved (may be reorganized)
- Public API behavior unchanged
- Error messages maintain same meaning
- Performance not degraded
**Additional Refinement Suggestions** (fill in during/after work):
[Worker notes additional opportunities discovered]
Implementation tasks use subagent_type=worker (constrained executor,
no scope expansion). Scanning and analysis tasks use
subagent_type=explore (read-only, cannot modify files).
task subagent_type=worker description="[Cleanup description]" prompt="
**CLEANUP TASK**: [Description from findings]
**Current**:
[code]
**Target**: [description]
**Acceptance Criteria**:
1. [Criterion 1]
2. [Criterion 2]
3. All tests pass
**Steps**:
1. Make the changes
2. Run tests to verify
3. Report any additional refinement opportunities you discover
**Report Format**:
- What was done
- Test results
- Additional refinement suggestions (if any)
- Any issues or blockers
"
Order of operations:
Mechanical first (safest, establishes patterns)
Test consolidation (establishes safety net)
Structural last (builds on clean foundation)
Strategy: Implement cleanups, gather refinement suggestions.
Workers must:
Progress Tracking: Mark each cleanup task in todowrite as completed or in_progress as work proceeds.
todowrite todos='[
{"content": "Deduplicate process_x/process_y", "status": "completed", "priority": "high"},
{"content": "Consolidate test setup", "status": "in_progress", "priority": "medium"},
{"content": "Remove unused imports in module_c", "status": "pending", "priority": "low"}
]
Workers should categorize suggestions:
**Additional Refinement Opportunities Discovered**:
**Mechanical** (can be delegated immediately):
- Finding 1: [description and location]
- Finding 2: [description and location]
**Design** (needs supervisory decision):
- Finding 3: [description - involves API change or architectural decision]
- Finding 4: [description - trade-offs to consider]
**Out of Scope** (noted for future):
- Finding 5: [would change behavior or too large for current scope]
Strategy: Assemble all worker reports into actionable summary.
## Refactoring Report: [Project/Module Name]
### Completed Cleanups
| Task | Status | Test Results | Notes |
|------|--------|--------------|-------|
| [Description] | Complete | All pass | - |
| [Description] | Partial | 1 failure | See Finding X |
### Additional Mechanical Cleanups Identified
These can be safely delegated:
1. **[Description]**
- **Location**: `path:lines`
- **Issue**: [brief]
- **Suggested Approach**: [how to fix]
- **Estimated Effort**: small | medium | large
### Design-Level Refinements Identified
These need architectural decisions:
1. **[Description]**
- **Context**: [what worker discovered]
- **Trade-offs**: [pros/cons]
- **Recommendation**: [supervisory agent assessment]
- **Next Step**: [delegate for design | discuss with team | defer]
### Deferred Items
Noted but out of current scope:
1. **[Description]**
- **Reason**: [why deferred]
- **Future Trigger**: [when to revisit]
### Metrics
- **Duplicated code removed**: [N] lines
- **Tests consolidated**: [N] removed, [N] assertions preserved
- **Boilerplate reduced**: [N] lines
- **Test pass rate**: [X]% before, [Y]% after
### Recommendations
1. **Immediate**: [next mechanical cleanups to tackle]
2. **Short-term**: [design refinements worth exploring]
3. **Long-term**: [architectural improvements to consider]
todowrite: Mark all completed, add any follow-up items discoveredGolden Rule: If it changes behavior, it's not a cleanup - it's a feature change.
Mechanical = structural moves with no logic changes:
These can be delegated with confidence.
Test Assertions = Feature specification
Test Functions = Implementation detail
Workers identify opportunities; supervisory agent:
**Current**:
// file_a.ext
fn process_x() { steps 1-2-3 }
// file_b.ext
fn process_y() { steps 1-2-3 }
**Target**:
// shared.ext
pub fn common_process() { steps 1-2-3 }
// file_a.ext
fn process_x() { common_process() }
// file_b.ext
fn process_y() { common_process() }
**Acceptance Criteria**:
1. Common function extracted to shared location
2. Original functions call common function
3. All tests pass
4. No behavior change
**Current**:
// test_a.rs
fn setup() { /* 20 lines */ }
// test_b.rs
fn setup() { /* same 20 lines */ }
**Target**:
// test_utils.rs
pub fn common_setup() { /* 20 lines */ }
// test_a.rs
use test_utils::common_setup;
// test_b.rs
use test_utils::common_setup;
**Acceptance Criteria**:
1. Setup extracted to shared module
2. Both test files use shared setup
3. All test assertions preserved
4. All tests pass
**Current**:
#[test]
fn test_foo_basic() {
let result = foo(5);
assert_eq!(result, 10);
}
#[test]
fn test_foo_again() {
let result = foo(5);
assert_eq!(result, 10);
}
**Target**:
#[test]
fn test_foo_basic() {
let result = foo(5);
assert_eq!(result, 10);
}
**Acceptance Criteria**:
1. Identical test removed
2. Remaining test still passes
3. No unique assertions lost
4. Test coverage unchanged
Before declaring cleanup complete:
Test Suite Passes
[run test command]
# Must be 100% or clearly documented why not
No Deleted Assertions
Compare before/after test counts:
- Before: [N] assertions
- After: [N] assertions (or more)
Public API Unchanged
- All public functions still exist
- Signatures unchanged (or equivalent)
- Return values semantically identical
Behavioral Equivalence
- Edge cases handled same way
- Error conditions trigger same paths
- Performance not worse (or documented)
# 1. Establish context
git diff --name-only HEAD~10
# 2. Set up tracking
todowrite todos='[
{"content": "Scan for code duplication", "status": "in_progress", "priority": "high"},
{"content": "Scan for test redundancy", "status": "pending", "priority": "high"},
{"content": "Scan for boilerplate", "status": "pending", "priority": "medium"},
{"content": "Scan for structural issues", "status": "pending", "priority": "medium"}
]
# 3. Delegate scans
task subagent_type=explore description="Scan for duplication"
task subagent_type=explore description="Scan for test redundancy"
# 4. Create cleanup tasks with acceptance criteria
# (based on scan findings)
# 5. Delegate cleanups (worker subagent for constrained execution)
task subagent_type=worker description="Deduplicate X" prompt="..."
task subagent_type=worker description="Consolidate Y" prompt="..."
# 6. Gather reports, assemble final report
# (supervisory agent synthesizes)
# 7. (Optional) Delegate mechanical follow-ups identified
You've done this well when:
Don't let cleanups turn into feature work. If you find bugs or missing features:
Don't introduce complex abstractions to remove simple duplication:
Never remove tests without verifying assertions are preserved elsewhere:
If cleanup requires API changes:
Incrementally extract stable code units from exploratory work. Use when the user wants to carve a stable unit out of a messy WIP branch, promote a coherent piece to a clean branch, run an extract/reconcile loop, manage PROTO/MERGE/RECONCILE branches, or avoid post-hoc commit reconstruction. Triggers on "extract stable unit", "promote to merge", "reconcile proto onto merge", "incremental extraction", "carve out stable code", "extract-reconcile workflow".
Detect drift between documented invariants/interface and actual implementation. Multi-phase: explore docs, build code hierarchy (parallel subagents), then analyze each module for invariant-linked vs unexplained code. Outputs drift metrics per module and aggregate across the project.
Enforces disciplined HTMX + TypeScript server-driven UI development. Focuses on HTMX lifecycle correctness, DOM mutation semantics, runtime observability, browser-debugging methodology, and preventing architectural drift toward imperative SPA patterns. Optimized for workflows using browser automation/debugging agents and server-rendered HTML fragments.
MANDATORY skill for spawning and killing processes
Audit Rust changes for bugs the compiler and Clippy do not catch (TOCTOU, panic surfaces, UTF-8 issues, error suppression, and trust-boundary mistakes) before finalizing work
Reconcile lat.md spec against implementation and tests, find contradictions, remove trash, and produce a verified truth table