Table of Contents
Code Refinement Workflow
Analyze and improve living code quality across six dimensions.
Quick Start
/refine-code
/refine-code --level 2 --focus duplication
/refine-code --level 3 --report refinement-plan.md
When To Use
- After rapid AI-assisted development sprints
- Before major releases (quality gate)
- When code "works but smells"
- Refactoring existing modules for clarity
- Reducing technical debt in living code
When NOT To Use
- Removing
dead/unused code (use conserve:bloat-detector)
- Removing
dead/unused code (use conserve:bloat-detector)
Analysis Dimensions
| # |
Dimension |
Module |
What It Catches |
| 1 |
Duplication & Redundancy |
duplication-analysis |
Near-identical blocks, similar functions, copy-paste |
| 2 |
Algorithmic Efficiency |
algorithm-efficiency |
O(n^2) where O(n) works, unnecessary iterations |
| 3 |
Clean Code Violations |
clean-code-checks |
Long methods, deep nesting, poor naming, magic values |
| 4 |
Architectural Fit |
architectural-fit |
Paradigm mismatches, coupling violations, leaky abstractions |
| 5 |
Anti-Slop Patterns |
clean-code-checks |
Premature abstraction, enterprise cosplay, hollow patterns |
| 6 |
Error Handling |
clean-code-checks |
Bare excepts, swallowed errors, happy-path-only |
Progressive Loading
Load modules based on refinement focus:
modules/duplication-analysis.md (~400 tokens): Duplication detection and consolidation
modules/algorithm-efficiency.md (~400 tokens): Complexity analysis and optimization
modules/clean-code-checks.md (~450 tokens): Clean code, anti-slop, error handling
modules/architectural-fit.md (~400 tokens): Paradigm alignment and coupling
Load all for comprehensive refinement. For focused work, load only relevant modules.
Required TodoWrite Items
refine:context-established — Scope, language, framework detection
refine:scan-complete — Findings across all dimensions
refine:prioritized — Findings ranked by impact and effort
refine:plan-generated — Concrete refactoring plan with before/after
refine:evidence-captured — Evidence appendix per imbue:proof-of-work
Workflow
Step 1: Establish Context (refine:context-established)
Detect project characteristics:
# Language detection
find . -name "*.py" -o -name "*.ts" -o -name "*.rs" -o -name "*.go" | head -20
# Framework detection
ls package.json pyproject.toml Cargo.toml go.mod 2>/dev/null
# Size assessment
find . -name "*.py" -o -name "*.ts" -o -name "*.rs" | xargs wc -l 2>/dev/null | tail -1
Step 2: Dimensional Scan (refine:scan-complete)
Load relevant modules and execute analysis per tier level.
Step 3: Prioritize (refine:prioritized)
Rank findings by:
- Impact: How much quality improves (HIGH/MEDIUM/LOW)
- Effort: Lines changed, files touched (SMALL/MEDIUM/LARGE)
- Risk: Likelihood of introducing bugs (LOW/MEDIUM/HIGH)
Priority = HIGH impact + SMALL effort + LOW risk first.
Step 4: Generate Plan (refine:plan-generated)
For each finding, produce:
- File path and line range
- Current code snippet
- Proposed improvement
- Rationale (which principle/dimension)
- Estimated effort
Step 5: Evidence Capture (refine:evidence-captured)
Document with imbue:proof-of-work (if available):
[E1], [E2] references for each finding
- Metrics before/after where measurable
- Principle violations cited
Fallback: If imbue is not installed, capture evidence inline in the report using the same [E1] reference format without TodoWrite integration.
Tiered Analysis
| Tier |
Time |
Scope |
| 1: Quick (default) |
2-5 min |
Complexity hotspots, obvious duplication, naming, magic values |
| 2: Targeted |
10-20 min |
Algorithm analysis, full duplication scan, architectural alignment |
| 3: Deep |
30-60 min |
All above + cross-module coupling, paradigm fitness, comprehensive plan |
Cross-Plugin Dependencies
| Dependency |
Required? |
Fallback |
pensive:shared |
Yes |
Core review patterns |
imbue:proof-of-work |
Optional |
Inline evidence in report |
conserve:code-quality-principles |
Optional |
Built-in KISS/YAGNI/SOLID checks |
archetypes:architecture-paradigms |
Optional |
Principle-based checks only (no paradigm detection) |
Supporting Modules
- Code quality analysis - duplication detection commands and consolidation strategies
When optional plugins are not installed, the skill degrades gracefully:
- Without
imbue: Evidence captured inline, no TodoWrite proof-of-work
- Without
conserve: Uses built-in clean code checks (subset)
- Without
archetypes: Skips paradigm-specific alignment, uses coupling/cohesion principles only
1---2name: code-refinement3description: Analyze and improve living code quality: duplication, algorithmic efficiency, clean code principles, architectural fit, anti-slop patterns, and error handling robustness. Use when improving code quality, reducing AI slop, refactoring for clarity, optimizing algorithms, applying clean code principles. Do not use when removing dead/unused code (use conserve:bloat-detector). reviewing for bugs (use pensive:bug-review). selecting architecture paradigms (use archetypes skills). This skill actively improves living code, complementing bloat detection (dead code removal) with quality refinement (living code improvement).4---5## Table of Contents67- [Quick Start](#quick-start)8- [When to Use](#when-to-use)9- [Analysis Dimensions](#analysis-dimensions)10- [Progressive Loading](#progressive-loading)11- [Required TodoWrite Items](#required-todowrite-items)12- [Workflow](#workflow)13- [Tiered Analysis](#tiered-analysis)14- [Cross-Plugin Dependencies](#cross-plugin-dependencies)1516# Code Refinement Workflow1718Analyze and improve living code quality across six dimensions.1920## Quick Start2122```bash23/refine-code24/refine-code --level 2 --focus duplication25/refine-code --level 3 --report refinement-plan.md26```2728## When To Use2930- After rapid AI-assisted development sprints31- Before major releases (quality gate)32- When code "works but smells"33- Refactoring existing modules for clarity34- Reducing technical debt in living code3536## When NOT To Use3738- Removing39 dead/unused code (use conserve:bloat-detector)40- Removing41 dead/unused code (use conserve:bloat-detector)4243## Analysis Dimensions4445| # | Dimension | Module | What It Catches |46|---|-----------|--------|----------------|47| 1 | Duplication & Redundancy | `duplication-analysis` | Near-identical blocks, similar functions, copy-paste |48| 2 | Algorithmic Efficiency | `algorithm-efficiency` | O(n^2) where O(n) works, unnecessary iterations |49| 3 | Clean Code Violations | `clean-code-checks` | Long methods, deep nesting, poor naming, magic values |50| 4 | Architectural Fit | `architectural-fit` | Paradigm mismatches, coupling violations, leaky abstractions |51| 5 | Anti-Slop Patterns | `clean-code-checks` | Premature abstraction, enterprise cosplay, hollow patterns |52| 6 | Error Handling | `clean-code-checks` | Bare excepts, swallowed errors, happy-path-only |5354## Progressive Loading5556Load modules based on refinement focus:5758- **`modules/duplication-analysis.md`** (~400 tokens): Duplication detection and consolidation59- **`modules/algorithm-efficiency.md`** (~400 tokens): Complexity analysis and optimization60- **`modules/clean-code-checks.md`** (~450 tokens): Clean code, anti-slop, error handling61- **`modules/architectural-fit.md`** (~400 tokens): Paradigm alignment and coupling6263Load all for comprehensive refinement. For focused work, load only relevant modules.6465## Required TodoWrite Items66671. `refine:context-established` — Scope, language, framework detection682. `refine:scan-complete` — Findings across all dimensions693. `refine:prioritized` — Findings ranked by impact and effort704. `refine:plan-generated` — Concrete refactoring plan with before/after715. `refine:evidence-captured` — Evidence appendix per `imbue:proof-of-work`7273## Workflow7475### Step 1: Establish Context (`refine:context-established`)7677Detect project characteristics:78```bash79# Language detection80find . -name "*.py" -o -name "*.ts" -o -name "*.rs" -o -name "*.go" | head -208182# Framework detection83ls package.json pyproject.toml Cargo.toml go.mod 2>/dev/null8485# Size assessment86find . -name "*.py" -o -name "*.ts" -o -name "*.rs" | xargs wc -l 2>/dev/null | tail -187```8889### Step 2: Dimensional Scan (`refine:scan-complete`)9091Load relevant modules and execute analysis per tier level.9293### Step 3: Prioritize (`refine:prioritized`)9495Rank findings by:96- **Impact**: How much quality improves (HIGH/MEDIUM/LOW)97- **Effort**: Lines changed, files touched (SMALL/MEDIUM/LARGE)98- **Risk**: Likelihood of introducing bugs (LOW/MEDIUM/HIGH)99100Priority = HIGH impact + SMALL effort + LOW risk first.101102### Step 4: Generate Plan (`refine:plan-generated`)103104For each finding, produce:105- File path and line range106- Current code snippet107- Proposed improvement108- Rationale (which principle/dimension)109- Estimated effort110111### Step 5: Evidence Capture (`refine:evidence-captured`)112113Document with `imbue:proof-of-work` (if available):114- `[E1]`, `[E2]` references for each finding115- Metrics before/after where measurable116- Principle violations cited117118**Fallback**: If `imbue` is not installed, capture evidence inline in the report using the same `[E1]` reference format without TodoWrite integration.119120## Tiered Analysis121122| Tier | Time | Scope |123|------|------|-------|124| **1: Quick** (default) | 2-5 min | Complexity hotspots, obvious duplication, naming, magic values |125| **2: Targeted** | 10-20 min | Algorithm analysis, full duplication scan, architectural alignment |126| **3: Deep** | 30-60 min | All above + cross-module coupling, paradigm fitness, comprehensive plan |127128## Cross-Plugin Dependencies129130| Dependency | Required? | Fallback |131|------------|-----------|----------|132| `pensive:shared` | Yes | Core review patterns |133| `imbue:proof-of-work` | Optional | Inline evidence in report |134| `conserve:code-quality-principles` | Optional | Built-in KISS/YAGNI/SOLID checks |135| `archetypes:architecture-paradigms` | Optional | Principle-based checks only (no paradigm detection) |136137## Supporting Modules138139- [Code quality analysis](modules/code-quality-analysis.md) - duplication detection commands and consolidation strategies140141When optional plugins are not installed, the skill degrades gracefully:142- Without `imbue`: Evidence captured inline, no TodoWrite proof-of-work143- Without `conserve`: Uses built-in clean code checks (subset)144- Without `archetypes`: Skips paradigm-specific alignment, uses coupling/cohesion principles only