refactor-extract
refactor-extract
Disciplined extraction of duplicated logic into a shared module. Stack-agnostic — applies to monorepos (packages/*), single-repo shared dirs (src/lib/, internal/pkg/), or language-level shared packages.
Step 1 — Confirm it's worth extracting
Before moving anything, sanity-check three things. If any answer is "no", abort and tell the user why.
≥ 2 callers (or imminent ≥ 2)
If only one caller exists today, leave the code there. Premature shared modules are worse than duplication — you're paying the abstraction cost without anyone using it. Three or more callers is the comfortable trigger; two is borderline (extract only if the surface is stable).
Rule of thumb: 3 near-identical lines is not duplication worth abstracting. 3 identical 30-line functions is.
Stable surface
If the function shape is still churning across callers (different signatures, different return types, frequent refactors), wait. The shared API will churn just as much, and every callsite will pay the migration cost twice.