🧹 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/for nesting 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 a TypedDict or Protocol?
- Optional: specific types
str | None are better than implicit None.
4. Optimization Routine (Run this)
# 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 .