dry-refactoring
Skill58 starsChanged 2 months agoMITView on GitHub
Guided workflow to eliminate copy-paste duplication in packages/hr-skills-build and packages/hr-skills-ref, detected by jscpd. Extract shared functions, constants, and types into their own files instead of growing an existing one.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- kucherenko/jscpdtheir own version, first seen Sep 2, 2026
- YYH211/Claude-meta-skilltheir own version, first seen Oct 31, 2025
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- kucherenko/jscpd★ 6.6ksame name
- YYH211/Claude-meta-skill★ 274same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- biomeSkill
- bunSkill
- changesetSkill
- clackSkill
- github-awesome-copilot-git-commitSkill
- hr-root-router-maintainingSkill
- hr-skills-maintainingSkill
- humanizerSkill
- jscpdSkill
- markdownSkill
- pdfSkill
- skill-vetterSkill
- turboSkill
- typescriptSkill
- valibotSkill
- hr-skillsSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 2 are distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Run jscpd first — see jscpd for the exact command this repo uses:
- Very specific: line 23
Run jscpd, scoped to packages/ only (never skills/, see the jscpd skill for why).
- Distinctive: line 25
Read both code fragments and understand what they do — don't refactor blind.
- Very specific: line 28
Run bun run typecheck and bun run test (repo-wide or --filter to the affected package — see turbo).
- Very specific: line 51
Before extracting, grep -rn "export (const|function|type|interface) <name>" packages for the name you're about to reuse.
- Very specific: line 53
Prefer a more specific name over a generic one (e.g.
- Distinctive: line 54
If both are genuinely the same concept split across two files, that's itself a duplication signal — consolidate into one export instead of …
- Very specific: line 66
Avoid the template/base class strategy in this codebase unless a real inheritance hierarchy already exists — this repo favors small …
- Very specific: line 70
All call sites updated, not just the two jscpd reported — grep for other near-identical blocks jscpd's thresholds may have missed.
- Very specific: line 73
If the duplication is between packages/hr-skills-build and packages/hr-skills-ref, check whether a changeset is needed — see changeset.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
dry-refactoring
Guided workflow to eliminate copy-paste duplication in packages/* TypeScript source. Use after jscpd has produced a clone list.
Prerequisites
Run jscpd first — see jscpd for the exact command this repo uses:
bunx jscpd@5 packages --reporters ai --format typescriptWorkflow
- Run jscpd, scoped to
packages/only (neverskills/, see thejscpdskill for why). - Parse each clone line to identify the two duplicated locations (file + line range).
- Read both code fragments and understand what they do — don't refactor blind.
- Decide the refactor target using the placement rules below.
- Extract the shared logic; update all call sites, not just the two jscpd reported.
- Run
bun run typecheckandbun run test(repo-wide or--filterto the affected package — seeturbo). - Re-run jscpd to confirm the clone is gone.
- Repeat, highest-impact cluster first (most repeated pattern, not just the first line in the report).
Where extracted code goes in this repo
This repo separates code by surface and domain under
packages/hr-skills/src/cli/, packages/hr-skills-build/src/client/,
packages/hr-skills-build/src/server/, packages/hr-skills-ref/src/client/,
and packages/hr-skills-ref/src/server/. Follow that structure — don't dump
extracted helpers into whichever file happens to be open:
- Duplicated logic used by 2+ files in the same domain folder (e.g. two files under
src/server/validation/) → new file in that same folder, e.g.src/server/validation/security-helpers.ts, imported by both. - Duplicated logic used across domain folders (e.g.
src/server/build/*andsrc/server/evaluation/*) →src/server/shared/, alongside the existingshared/constants.ts,shared/helpers.ts,shared/schema.ts,shared/types.ts. - Duplicated logic across packages (
hr-skills-buildandhr-skills-refboth define it) → do not create a third copy in either package. Prefer keeping a single canonical definition in the package it conceptually belongs to (hr-skills-reffor skill-file parsing primitives,hr-skills-buildfor build/registry/CLI concerns) and importing it from the other, or promote it to a small shared internal package if both genuinely need to own it independently. Never resolve this by copy-pasting into a third location. - Intentional client/server duplication → each public surface must remain self-contained. If sharing a module would create a client/server import edge, keep separate surface-local implementations and test both surfaces instead.
- Constants → their own
constants.tsin the relevant folder; don't fold them into a file that already holds functions or types. - Types/interfaces → their own
types.ts(or*.types.tsiftypes.tsalready exists and would grow unrelated concerns) in the relevant folder — never appended to a functions file "for now."
Naming collisions
Before extracting, grep -rn "export (const|function|type|interface) <name>" packages for the name you're about to reuse. If a same-named export already exists elsewhere in the monorepo:
- Prefer a more specific name over a generic one (e.g.
parseSkillFrontmatteroverparse) rather than renaming the existing export and risking unrelated churn. - If both are genuinely the same concept split across two files, that's itself a duplication signal — consolidate into one export instead of two similarly-named ones.
Refactoring strategies
Extract function — duplicate is a block of logic → shared function, called from both places.
Extract module — duplicate spans multiple files in the same or related domains → shared file per the placement rules above, imported by all call sites.
Extract constant — duplicate is repeated literal data or config → named constant in the domain's constants.ts.
Extract type/interface — duplicate or near-duplicate shape appears in two files → single definition in the domain's types.ts, both files import it.
Avoid the template/base class strategy in this codebase unless a real inheritance hierarchy already exists — this repo favors small composable functions and Valibot schemas (see valibot) over class hierarchies.
Tips
- All call sites updated, not just the two jscpd reported —
grepfor other near-identical blocks jscpd's thresholds may have missed. - Tests still pass after refactoring (
bun run test), andbun run typecheckis clean. - The extracted abstraction has a clear, descriptive name — see naming collisions above.
- If the duplication is between
packages/hr-skills-buildandpackages/hr-skills-ref, check whether a changeset is needed — seechangeset. - Format with Biome after refactoring (
bun run formator letlefthookcatch it on commit) — seebiome.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

