compare-codebases
できること
このスキルは、2つのコードベースの関数を組み合わせ、一方にあって他方にないものを報告する方法を説明します。2つのプロジェクトの関係や、移植がどこまで進んだかを確認する開発者向けです。
使う場面
- ✓チームが、アプリのあるバージョンに、もう一方にはない関数があるかを知りたいとき。
- ✓開発者が、アプリのiOS版とAndroid版が一致しているかを確認したいとき。
- ✓開発者が、あるフォルダの関数が、別のフォルダのどの関数に対応するかを見つける必要があるとき。
スキルのリンク
https://github.com/kucherenko/jscpd/blob/master/skills/compare-codebases/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私たちのiOSとAndroidのコードフォルダを比べて、Androidアプリに欠けている関数を教えてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
このスキルは、名前ではなく機能によって関数を対応づける比較を実行します。その後、対応したものと対応しなかったものを平易な言葉で説明します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
compare-codebases
jscpd --compare A B pairs every function of folder A with the function of folder B that does the same job, and lists the functions of each folder that have no counterpart. The two folders may be in one language or in two (Python and TypeScript, Kotlin and Swift, Java and Rust). This skill explains how the comparison works and how to run one well. For porting code with the comparison as the progress measure, use the code-migration skill; for the rest of jscpd, the jscpd skill.
How the comparison works
jscpd finds the functions of JavaScript, TypeScript, JSX, TSX, Vue, Svelte, Astro, Python, Rust, Go, Java, Kotlin, C#, C, C++, PHP, Ruby, Scala and Swift files in both folders. It turns the code of each function into a vector with a code embedding model that runs inside jscpd (CodeRankEmbed by default), so two functions that do the same job point the same way even when their languages, names and structure differ. Functions of one folder are never compared with each other.
Functions pair in two steps:
- By code. Two functions pair when each is the other's closest match in the other folder, their cosine similarity reaches the model's threshold (0.4125 across languages and 0.6375 within one language, with CodeRankEmbed), and the similarity stands out from the function's other matches. A function close to the best one also pairs when it reaches a higher bar, so a feature written twice on one side gets two pairs. A pair stays only when it is the best match of at least one of its two functions, so a lookalike from another class does not join a function and its counterpart; a tie goes to the file of the same name. Functions shorter than
--min-tokens(30 with--compare) or--min-lines(5) stay out of this step, because a short function resembles too many others. - By name. A function left over pairs with a function of the other folder under the same name, once case, underscores, spaces and punctuation are ignored (
encodeBinary,encode_binary,_encode_binary; the test titlerounds centsandrounds_cents), when their similarity reaches themediumlevel (0.5625 across languages with CodeRankEmbed). A name pair skips the closest-match and stand-out checks of the first step, so it needs more than that step's threshold; otherwise everyloadandinitof two codebases would pair. Size does not matter here, so a short port is found. A name pair has to stay within modules the first step linked. A module is the folder right under the deepest folder all files of a side share (notificationinandroid/notification/…), and a file that sits higher than the rest, such as a build script, does not move that folder up. Two modules link when one holds the most of the other's pairs, counted for code and for tests separately. SocheckPermissionsof one plugin does not pair with its namesake in another.
Each pair gets a level on the scale of the model, because a cosine that is high for one model is low for another:
| Level | With CodeRankEmbed, across languages | Meaning |
|---|---|---|
high |
0.7125 and up | almost always the same function |
medium |
0.5625 to 0.7125 | usually the same function, restructured |
low |
0.4125 to 0.5625 | read both: related code pairs here too |
jscpd measures tests and code apart, in two blocks of the report, and pairs a test only with a test. It tells a test by the conventions of its language:
- a test file such as
*_test.go,test_*.py,*.test.ts,*.spec.js,*Tests.swiftor*_spec.rb; - a test folder such as
tests/,__tests__/,spec/,src/test/(where Java, Kotlin and Scala keep their tests),MyAppTests/orMyApp.Tests.Integration/, the compared folder's own name included; - a Rust function in a
#[cfg(test)]module or under#[test]; - a JavaScript or TypeScript test case such as
it('rounds cents', () => …).
When neither side has a test that counts (see below), the report has one block and no headings.
Totals count the functions of at least --min-tokens tokens and --min-lines lines; smaller ones appear only as partners. Declarations without a body (TypeScript overloads, the functions of a .d.ts file, interface and abstract methods) take no part. Anonymous functions (callbacks, closures) take no part either, except JavaScript and TypeScript test cases. A test case such as it('rounds cents', () => …) goes by its title, and so do those written with test,
よくある質問
同じ言語である必要がありますか?
いいえ。2つのフォルダはPythonとTypeScriptなど、異なる言語でも構いません。
関数を名前で対応づけますか?
いいえ。コードの埋め込みモデルを使い、機能によって関数を対応づけます。
1つのフォルダの中の関数を比べますか?
いいえ。2つのフォルダをまたいで関数を比べるだけです。
詳細
作者による元の説明
Compare two folders function by function with jscpd --compare, in the same language or across languages, and explain the result. Use when asked how two codebases relate, which functions one implementation has and the other lacks, how far a port has come, whether the iOS and Android versions of an app match, or which function in one folder corresponds to a function in the other.
repo: kucherenko/jscpd
人気
- GitHubのスター
- 6.5k
- ランキング
- #14189
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
code-migration
6.5kエージェントが、テストを先に書き、元のコードに対する進捗を測りながら、1度に1つの関数ずつ、ある言語やフレームワークから別のものへコードを移植できるよう支援します。
codebase-refactoring
6.5kエージェントが、重複したコードを直し、使われていないコードを削除し、最も複雑なファイルを簡素化することで、コードベースの健全性を改善できるよう支援します。その順序で進めます。
dry-refactoring
6.5kエージェントが、最も大きな重複から始めて、繰り返されるブロックを共有の関数にまとめ、プロジェクトからコピー&ペーストされたコードを取り除けるよう支援します。
jscpd
6.5kエージェントが、完全一致、名前を変えた一致、近いコピーの形で、プロジェクト内のコピー&ペーストされたコードを見つけ、どれだけのコードが重複しているかを測れるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。