跳到正文
Skillpedia
通用编程6.5k · #14189

compare-codebases

它能做什么

它说明如何将两个代码库中的函数配对,并报告每一方有而另一方缺少的内容。适用于检查两个项目之间的关系,或移植进展程度的开发者。

适用场景

  • ✓当团队想知道某个版本的应用有哪些函数是另一个版本所缺少的时。
  • ✓当开发者想检查应用的 iOS 版和 Android 版是否一致时。
  • ✓当开发者需要找出一个文件夹中的哪个函数对应另一个文件夹中的某个函数时。

技能链接

https://github.com/kucherenko/jscpd/blob/master/skills/compare-codebases/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/kucherenko/jscpd/blob/master/skills/compare-codebases/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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:

  1. 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.
  2. 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 title rounds cents and rounds_cents), when their similarity reaches the medium level (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 every load and init of 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 (notification in android/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. So checkPermissions of 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.swift or *_spec.rb;
  • a test folder such as tests/, __tests__/, spec/, src/test/ (where Java, Kotlin and Scala keep their tests), MyAppTests/ or MyApp.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,

常见问题

它需要相同的语言吗?

不需要。两个文件夹可以使用不同的语言,例如 Python 和 TypeScript。

它是按名称匹配函数的吗?

不是。它依据函数的作用进行匹配,使用的是代码嵌入模型。

它能比较同一个文件夹内的函数吗?

不能。它只比较两个文件夹之间的函数。

详情

作者的原始描述

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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能