Dry Refactoringのロゴ

Dry Refactoring

コミュニティ
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.

Add to TypingMind

概要

公開者tuanductran
リポジトリhr-skills
スキル名dry-refactoring
スター
78
フォーク
20
同梱ファイル
指示のみ
ライセンスMIT
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 指示だけで完結

    モデルに必要なものはすべて指示に含まれているため、別途同期するファイルはありません。

  • オープンソース

    tuanductranがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Dry Refactoring」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/tuanductran/hr-skills/tree/main/.agents/skills/dry-refactoring
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでDry Refactoringを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にDry Refactoringを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Dry Refactoringは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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.

よくある質問

AIスキル「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.

TypingMindでDry Refactoringを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Dry Refactoringはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにDry Refactoringをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/tuanductran/hr-skills/tree/main/.agents/skills/dry-refactoringを貼り付けてください。TypingMindがSKILL.mdを読み込み、チャットごとに有効にできるスキルとしてインストールします。

Dry Refactoringを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Dry Refactoringで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもDry Refactoringを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Dry Refactoring」は無料ですか?

はい。tuanductranがMITライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇