Dry Refactoring logo

Dry Refactoring

Community
tuanductran
dry-refactoring

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.

Overview

Publishertuanductran
Repositoryhr-skills
Skill namedry-refactoring
Stars
78
Forks
20
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by tuanductran on GitHub. Read the source before you install it.

Installation

Install the Dry Refactoring AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/tuanductran/hr-skills/tree/main/.agents/skills/dry-refactoring
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/tuanductran/hr-skills.git /tmp/hr-skills
mkdir -p .claude/skills
cp -r /tmp/hr-skills/.agents/skills/dry-refactoring .claude/skills/dry-refactoring
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Dry Refactoring in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Dry Refactoring on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Dry Refactoring is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

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:

bash
bunx jscpd@5 packages --reporters ai --format typescript

Workflow

  1. Run jscpd, scoped to packages/ only (never skills/, see the jscpd skill for why).
  2. Parse each clone line to identify the two duplicated locations (file + line range).
  3. Read both code fragments and understand what they do — don't refactor blind.
  4. Decide the refactor target using the placement rules below.
  5. Extract the shared logic; update all call sites, not just the two jscpd reported.
  6. Run bun run typecheck and bun run test (repo-wide or --filter to the affected package — see turbo).
  7. Re-run jscpd to confirm the clone is gone.
  8. 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/* and src/server/evaluation/*) → src/server/shared/, alongside the existing shared/constants.ts, shared/helpers.ts, shared/schema.ts, shared/types.ts.
  • Duplicated logic across packages (hr-skills-build and hr-skills-ref both 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-ref for skill-file parsing primitives, hr-skills-build for 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.ts in the relevant folder; don't fold them into a file that already holds functions or types.
  • Types/interfaces → their own types.ts (or *.types.ts if types.ts already 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. parseSkillFrontmatter over parse) 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 — grep for other near-identical blocks jscpd's thresholds may have missed.
  • Tests still pass after refactoring (bun run test), and bun run typecheck is clean.
  • The extracted abstraction has a clear, descriptive name — see naming collisions above.
  • If the duplication is between packages/hr-skills-build and packages/hr-skills-ref, check whether a changeset is needed — see changeset.
  • Format with Biome after refactoring (bun run format or let lefthook catch it on commit) — see biome.

Frequently asked questions

What does the Dry Refactoring AI skill do?

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.

Why use Dry Refactoring on TypingMind?

Because you install it once and use it with any model. Dry Refactoring is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Dry Refactoring in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/tuanductran/hr-skills/tree/main/.agents/skills/dry-refactoring. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Dry Refactoring?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Dry Refactoring?

As many as you like. As long as a model supports skills, you can use Dry Refactoring with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Dry Refactoring AI skill free?

Yes. It is published on GitHub by tuanductran under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇