🧹 Optimize Codebase (The Mechanic)
Context
Entropy increases over time. This skill proactively fights it.
1. Complexity Scan (Cyclomatic Complexity)
- •Tool:
ruff(mccabe plugin) or mental check. - •Rule: If
if/else/fornesting is > 3 levels, Refactor. - •Action: Extract method.
2. Dead Code Removal
- •Unused Imports: Run
uv run ruff check --select F401 --fix. - •Unused Variables: Rename to
_or remove. - •Commented Out Code: DELETE IT. Git history remembers.
3. Type Health
- •Any: Search for
Any. Can we make it aTypedDictorProtocol? - •Optional: specific types
str | Noneare better than implicit None.
4. Optimization Routine (Run this)
powershell
# 1. Sort Imports uv run ruff check --select I --fix . # 2. Fix Formatting uv run ruff format . # 3. Check for specific complexity (C901) uv run ruff check --select C901 .