[{"data":1,"prerenderedAt":1230},["ShallowReactive",2],{"navigation_docs":3,"blog-post-when-code-clones-matter":249,"blog-views-when-code-clones-matter":1226},[4,29,104,124,194],{"title":5,"icon":6,"path":7,"stem":8,"children":9},"Start",false,"\u002Fstart","1.start",[10,14,19,24],{"title":11,"path":7,"stem":12,"icon":13},"What jscpd finds","1.start\u002Findex","i-lucide-house",{"title":15,"path":16,"stem":17,"icon":18},"Installation","\u002Fstart\u002Finstallation","1.start\u002F2.installation","i-lucide-download",{"title":20,"path":21,"stem":22,"icon":23},"Quickstart","\u002Fstart\u002Fquickstart","1.start\u002F3.quickstart","i-lucide-rocket",{"title":25,"path":26,"stem":27,"icon":28},"Configuration basics","\u002Fstart\u002Fconfiguration","1.start\u002F4.configuration","i-lucide-settings-2",{"title":30,"icon":6,"path":31,"stem":32,"children":33,"page":6},"Guides","\u002Fguides","2.guides",[34,39,44,49,54,59,64,69,74,79,84,89,94,99],{"title":35,"path":36,"stem":37,"icon":38},"Use jscpd in CI","\u002Fguides\u002Fci","2.guides\u002F01.ci","i-lucide-github",{"title":40,"path":41,"stem":42,"icon":43},"Pre-commit hooks","\u002Fguides\u002Fpre-commit","2.guides\u002F02.pre-commit","i-lucide-git-commit",{"title":45,"path":46,"stem":47,"icon":48},"Fail only on new duplication","\u002Fguides\u002Fbaseline","2.guides\u002F03.baseline","i-lucide-git-compare",{"title":50,"path":51,"stem":52,"icon":53},"Monorepos","\u002Fguides\u002Fmonorepos","2.guides\u002F04.monorepos","i-lucide-folder-tree",{"title":55,"path":56,"stem":57,"icon":58},"Cross-format detection","\u002Fguides\u002Fcross-format","2.guides\u002F05.cross-format","i-lucide-layers",{"title":60,"path":61,"stem":62,"icon":63},"Agents","\u002Fguides\u002Fagents","2.guides\u002F06.agents","i-lucide-cpu",{"title":65,"path":66,"stem":67,"icon":68},"Editors","\u002Fguides\u002Feditors","2.guides\u002F07.editors","i-lucide-code",{"title":70,"path":71,"stem":72,"icon":73},"Duplication over git history","\u002Fguides\u002Fhistory","2.guides\u002F08.history","i-lucide-chart-no-axes-combined",{"title":75,"path":76,"stem":77,"icon":78},"Dashboard and health score","\u002Fguides\u002Fdashboard","2.guides\u002F09.dashboard","i-lucide-layout-dashboard",{"title":80,"path":81,"stem":82,"icon":83},"Dead code","\u002Fguides\u002Fdead-code","2.guides\u002F10.dead-code","i-lucide-ghost",{"title":85,"path":86,"stem":87,"icon":88},"Comparing two codebases","\u002Fguides\u002Fcompare","2.guides\u002F11.compare","i-lucide-git-compare-arrows",{"title":90,"path":91,"stem":92,"icon":93},"Semantic clones","\u002Fguides\u002Fsemantic-clones","2.guides\u002F12.semantic-clones","i-lucide-brain-circuit",{"title":95,"path":96,"stem":97,"icon":98},"Similar functions","\u002Fguides\u002Fsimilarity","2.guides\u002F13.similarity","i-lucide-list-tree",{"title":100,"path":101,"stem":102,"icon":103},"Boundaries","\u002Fguides\u002Fboundaries","2.guides\u002F14.boundaries","i-lucide-fence",{"title":105,"icon":6,"path":106,"stem":107,"children":108,"page":6},"Concepts","\u002Fconcepts","3.concepts",[109,114,119],{"title":110,"path":111,"stem":112,"icon":113},"Types of code clones","\u002Fconcepts\u002Fclone-types","3.concepts\u002F1.clone-types","i-lucide-copy",{"title":115,"path":116,"stem":117,"icon":118},"How detection works","\u002Fconcepts\u002Fhow-detection-works","3.concepts\u002F2.how-detection-works","i-lucide-scan-search",{"title":120,"path":121,"stem":122,"icon":123},"The health score","\u002Fconcepts\u002Fhealth-score","3.concepts\u002F3.health-score","i-lucide-heart-pulse",{"title":125,"icon":6,"path":126,"stem":127,"children":128,"page":6},"Reference","\u002Freference","4.reference",[129,134,139,144,181,186,190],{"title":130,"path":131,"stem":132,"icon":133},"CLI options","\u002Freference\u002Fcli","4.reference\u002F1.cli","i-lucide-terminal",{"title":135,"path":136,"stem":137,"icon":138},"The config file","\u002Freference\u002Fconfig-file","4.reference\u002F2.config-file","i-lucide-settings",{"title":140,"path":141,"stem":142,"icon":143},"Exit codes","\u002Freference\u002Fexit-codes","4.reference\u002F3.exit-codes","i-lucide-log-out",{"title":145,"icon":6,"path":146,"stem":147,"children":148},"Reporters","\u002Freference\u002Freporters","4.reference\u002F4.reporters\u002Findex",[149,151,156,161,166,171,176],{"title":145,"path":146,"stem":147,"icon":150},"i-lucide-file-chart-column",{"title":152,"path":153,"stem":154,"icon":155},"HTML reporter","\u002Freference\u002Freporters\u002Fhtml","4.reference\u002F4.reporters\u002F2.html","i-lucide-file-code",{"title":157,"path":158,"stem":159,"icon":160},"JSON reporter","\u002Freference\u002Freporters\u002Fjson","4.reference\u002F4.reporters\u002F3.json","i-lucide-braces",{"title":162,"path":163,"stem":164,"icon":165},"Badge reporter","\u002Freference\u002Freporters\u002Fbadge","4.reference\u002F4.reporters\u002F4.badge","i-lucide-award",{"title":167,"path":168,"stem":169,"icon":170},"SARIF reporter","\u002Freference\u002Freporters\u002Fsarif","4.reference\u002F4.reporters\u002F5.sarif","i-lucide-shield-check",{"title":172,"path":173,"stem":174,"icon":175},"CodeClimate reporter","\u002Freference\u002Freporters\u002Fcodeclimate","4.reference\u002F4.reporters\u002F6.codeclimate","i-lucide-flag-triangle-right",{"title":177,"path":178,"stem":179,"icon":180},"OpenMetrics reporter","\u002Freference\u002Freporters\u002Fopenmetrics","4.reference\u002F4.reporters\u002F7.openmetrics","i-lucide-activity",{"title":182,"path":183,"stem":184,"icon":185},"Supported formats","\u002Freference\u002Fsupported-formats","4.reference\u002F5.supported-formats","i-lucide-languages",{"title":187,"path":188,"stem":189,"icon":38},"GitHub Action","\u002Freference\u002Fgithub-action","4.reference\u002F6.github-action",{"title":191,"path":192,"stem":193,"icon":68},"Rust crates","\u002Freference\u002Frust-crates","4.reference\u002F7.rust-crates",{"title":195,"icon":6,"path":196,"stem":197,"children":198,"page":6},"Project","\u002Fproject","5.project",[199,204,209,214,239,244],{"title":200,"path":201,"stem":202,"icon":203},"Changelog","\u002Fproject\u002Fchangelog","5.project\u002F1.changelog","i-lucide-scroll-text",{"title":205,"path":206,"stem":207,"icon":208},"Migrating from v4 to v5","\u002Fproject\u002Fmigration","5.project\u002F2.migration","i-lucide-arrow-right-left",{"title":210,"path":211,"stem":212,"icon":213},"jscpd v4 (TypeScript)","\u002Fproject\u002Fv4","5.project\u002F3.v4","i-simple-icons-typescript",{"title":215,"icon":6,"path":216,"stem":217,"children":218},"Benchmarks","\u002Fproject\u002Fbenchmarks","5.project\u002F4.benchmarks\u002Findex",[219,221,226,230,235],{"title":215,"path":216,"stem":217,"icon":220},"i-lucide-gauge",{"title":222,"path":223,"stem":224,"icon":225},"Detection Speed","\u002Fproject\u002Fbenchmarks\u002Fdetection-speed","5.project\u002F4.benchmarks\u002F2.detection-speed","i-lucide-zap",{"title":227,"path":228,"stem":229,"icon":58},"Multi-Format Detection","\u002Fproject\u002Fbenchmarks\u002Fcross-format","5.project\u002F4.benchmarks\u002F3.cross-format",{"title":231,"path":232,"stem":233,"icon":234},"AI Token Efficiency","\u002Fproject\u002Fbenchmarks\u002Fai-token-efficiency","5.project\u002F4.benchmarks\u002F4.ai-token-efficiency","i-lucide-sparkles",{"title":236,"path":237,"stem":238,"icon":93},"Embedding Models","\u002Fproject\u002Fbenchmarks\u002Fembedding-models","5.project\u002F4.benchmarks\u002F5.embedding-models",{"title":240,"path":241,"stem":242,"icon":243},"Research","\u002Fproject\u002Fresearch","5.project\u002F5.research","i-lucide-graduation-cap",{"title":245,"path":246,"stem":247,"icon":248},"Articles","\u002Fproject\u002Farticles","5.project\u002F6.articles","i-lucide-newspaper",{"id":250,"title":251,"authors":252,"body":254,"date":1214,"description":1215,"extension":1216,"meta":1217,"navigation":6,"path":1218,"publishedAt":1219,"seo":1220,"stem":1221,"tags":1222,"__hash__":1225},"blog\u002Fblog\u002Fwhen-code-clones-matter.md","How to let a coding agent port your code and know what it ported",[253],"kucherenko",{"type":255,"value":256,"toc":1203},"minimark",[257,275,278,286,297,304,310,313,316,321,349,355,360,363,369,427,430,496,500,503,570,584,588,594,617,634,637,641,650,674,677,698,701,704,708,711,726,729,736,739,743,746,754,769,779,782,788,799,807,810,813,880,886,891,902,905,911,916,928,932,935,992,998,1020,1023,1045,1049,1118,1121,1124,1128,1146,1193,1199],[258,259,260,261,268,269,274],"p",{},"Agent-made ports are already shipping. Jarred Sumner ",[262,263,267],"a",{"href":264,"rel":265},"https:\u002F\u002Fbun.com\u002Fblog\u002Fbun-in-rust",[266],"nofollow","took Bun",", 535,496 lines of Zig without comments, to Rust in 11 days with Claude Code. Stephen Toub ",[262,270,273],{"href":271,"rel":272},"https:\u002F\u002Fgithub.blog\u002Fai-and-ml\u002Fgenerative-ai\u002Fmigrating-the-github-copilot-runtime-to-rust-using-copilot\u002F",[266],"ported the GitHub Copilot runtime",", about 430,000 lines of production TypeScript, to Rust with Copilot itself. Both write-ups record the agents cutting corners. In the Bun port, Claude read \"let's get all the crates to compile\" as \"stub out the functions with compilation errors\". The Copilot write-up mentions a port that \"omitted SDK callbacks and deleted their end-to-end test\". Toub tracks the port's progress with charts of the production TypeScript left and of the temporary N-API layer between the two languages, which peaked at 2,019 internal exports. The question every such write-up has to answer is how much has really moved, and tests answer a different one. Tests check behavior, and copied code behaves exactly like the code it was copied from, so the shortest path to a green suite is to keep the source.",[258,276,277],{},"What I wanted during a port was an answer to the question the tests leave open: how much of the source has really made it into the target, and in what form. The method in this post gives that answer, and it rests on two things, a measurement and a loop.",[258,279,280,281,285],{},"The measurement comes from ",[282,283,284],"code",{},"jscpd --compare",", a feature added in the latest release of the copy-paste detector I maintain. Given two folders, the source and the target, it follows every function of the source into the target and reports where its counterpart turned up, in which file and in which language, and how closely the two match. A counterpart in the target language means the function has been ported; a counterpart in the source language, with the same code, means it has been copied; no counterpart at all means it is still waiting its turn. The tests get the same treatment, so a test that was dropped on the way shows up as a test without a counterpart.",[258,287,288,289,292,293,296],{},"The loop is the ",[282,290,291],{},"code-migration"," skill for coding agents, which turns that report into the agent's way of working. The tests go across first. Then the code, one function at a time, beginning with the functions whose dependencies are already in place, and after every step the agent runs ",[282,294,295],{},"--compare"," again to see the new function recognized as a port rather than a copy.",[258,298,299],{},[300,301],"img",{"alt":302,"src":303},"The migration loop","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002F1-migration-loop.svg",[258,305,306],{},[307,308,309],"em",{},"The migration loop: the report tells the agent what to port next, and every ported function is measured before the next one.",[258,311,312],{},"Neither part cares which languages are involved. jscpd parses 19 of them and pairs functions across any two, and within one language as well, so the same loop serves a move between frameworks. Nor does the direction matter. The source doesn't have to be the old implementation. It can stay in production and keep changing, the target can already hold features the source lacks, and when both stay alive, an iOS and an Android app, say, or a Python library and its TypeScript rewrite, the same report shows their parity.",[258,314,315],{},"To see what the loop changes, I gave the same task to the same agent twice, with the skill and without it. The task was to port fs-extra, the Node.js file system library, to Rust. Both ports pass 488 of the 491 tests from fs-extra's own suite and export all 149 names of its API, with the right types. One of them ported 50 of fs-extra's 51 functions, 34 into Rust and 16 into thin JavaScript wrappers over a Rust core. The other copied 32 of them, unchanged, into its own JavaScript layer and wrapped a little Rust around the rest. The tests can't tell these two ports apart. The measurement can, and the second half of this post shows what it found.",[317,318,320],"h2",{"id":319},"the-measurement-where-did-each-function-go","The measurement: where did each function go",[258,322,323,324,327,328,331,332,335,336,339,340,331,342,344,345,348],{},"Most of the time a clone detector looks for copy-paste so you can fold it into one function. A migration flips that. The source is supposed to reappear in the target, only in another language, so duplication, usually something you clean up, becomes the most honest progress report you have. If ",[282,325,326],{},"move()"," from ",[282,329,330],{},"move.js"," shows up as ",[282,333,334],{},"move_impl"," in ",[282,337,338],{},"move.rs",", that is progress. If ",[282,341,326],{},[282,343,326],{}," in the target's ",[282,346,347],{},"lib\u002Fmove\u002Fmove.js",", nothing moved.",[258,350,351],{},[300,352],{"alt":353,"src":354},"Where did each function go","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002F2-where-did-each-function-go.svg",[258,356,357],{},[307,358,359],{},"Three things the counterpart column can say about one source function. A port and a copy pass the same tests.",[258,361,362],{},"A classic token-based detector, which is what jscpd has always been, only sees the second kind, because a JavaScript function and its Rust port share almost no tokens. To see both kinds, you have to compare what functions do rather than how they are spelled.",[258,364,365,366,368],{},"I looked for something that does this before building it. Cross-language clone detection has been a research field since C2D2 in 2008, with CLCDSA, C4 and SimCL after it, and it produced models and papers rather than a tool you run on two folders. Modernization agents report progress as tasks ticked off a plan they wrote themselves. The closest tool I found keeps a translation ledger the agent fills in. None of them reads two codebases and says, per function and per test, where its counterpart lives. ",[282,367,295],{}," does it in five steps.",[370,371,376],"pre",{"className":372,"code":373,"language":374,"meta":375,"style":375},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","npx jscpd --semantic-download   # once: the CodeRankEmbed model, 548 MB\nnpx jscpd --compare path\u002Fto\u002Fsource path\u002Fto\u002Ftarget --ignore \"**\u002Ftarget\u002F**,**\u002Fnode_modules\u002F**\"\n","bash","",[282,377,378,398],{"__ignoreMap":375},[379,380,383,387,391,394],"span",{"class":381,"line":382},"line",1,[379,384,386],{"class":385},"sBMFI","npx",[379,388,390],{"class":389},"sfazB"," jscpd",[379,392,393],{"class":389}," --semantic-download",[379,395,397],{"class":396},"sHwdD","   # once: the CodeRankEmbed model, 548 MB\n",[379,399,401,403,405,408,411,414,417,421,424],{"class":381,"line":400},2,[379,402,386],{"class":385},[379,404,390],{"class":389},[379,406,407],{"class":389}," --compare",[379,409,410],{"class":389}," path\u002Fto\u002Fsource",[379,412,413],{"class":389}," path\u002Fto\u002Ftarget",[379,415,416],{"class":389}," --ignore",[379,418,420],{"class":419},"sMK4o"," \"",[379,422,423],{"class":389},"**\u002Ftarget\u002F**,**\u002Fnode_modules\u002F**",[379,425,426],{"class":419},"\"\n",[258,428,429],{},"The source goes first and the target second. Then:",[431,432,433,441,447,453,474],"ol",{},[434,435,436,440],"li",{},[437,438,439],"strong",{},"Find functions."," jscpd parses both folders and extracts every function from 19 languages, Rust and JavaScript among them. Functions under 30 tokens or 5 lines don't count toward the totals, because short functions resemble too many others.",[434,442,443,446],{},[437,444,445],{},"Embed them."," Each function becomes a vector from CodeRankEmbed, a code embedding model that runs locally inside jscpd. Two functions that do the same job point in the same direction even when language, names and structure differ. The vectors are cached, so the next run only embeds what changed and takes seconds.",[434,448,449,452],{},[437,450,451],{},"Pair by code."," Two functions pair when each is the other's closest match in the other folder, their cosine similarity clears the model's threshold (0.4125 across languages, 0.6375 within one language), and the match stands out from the runner-up.",[434,454,455,458,459,462,463,466,467,470,471,473],{},[437,456,457],{},"Pair by name."," A function left over can pair with one of the same name, ignoring case and underscores (",[282,460,461],{},"moveSync"," and ",[282,464,465],{},"move_sync","), if the similarity reaches 0.5625 and both live in modules the first step already linked. This catches short ports without pairing every ",[282,468,469],{},"init"," with every other ",[282,472,469],{},".",[434,475,476,479,480,483,484,487,488,491,492,495],{},[437,477,478],{},"Report."," Each pair gets a level, ",[282,481,482],{},"high",", ",[282,485,486],{},"medium"," or ",[282,489,490],{},"low",", and the report lists what pairs with what, what is left only in the source, and what exists only in the target. Tests are measured separately and only pair with tests. The JSON report also has ",[282,493,494],{},"readyToPort",", the unported functions whose callees are all ported already, in the order to take them.",[317,497,499],{"id":498},"reading-the-report","Reading the report",[258,501,502],{},"The report has one number at the top, the share of source functions with a counterpart, and a table underneath with the counterpart for each file. Read the table before the number. In a port to another language, a pair whose target is in the source's language with a similarity near 1.00 is a copy, and the headline number counts it as a counterpart. The JSON report has everything needed to count the copies:",[370,504,506],{"className":372,"code":505,"language":374,"meta":375,"style":375},"npx jscpd --compare path\u002Fto\u002Fsource path\u002Fto\u002Ftarget -r json -o report --silent\nnode -e '\nconst r = require(\".\u002Freport\u002Fjscpd-compare.json\")\nconst copies = r.code.pairs.filter(p => !p.b.file.endsWith(\".rs\") && p.similarity >= 0.97)\nconsole.log(new Set(copies.map(p => p.a.file + \":\" + p.a.name)).size, \"functions paired with an unchanged copy\")\n'\n",[282,507,508,535,546,552,558,564],{"__ignoreMap":375},[379,509,510,512,514,516,518,520,523,526,529,532],{"class":381,"line":382},[379,511,386],{"class":385},[379,513,390],{"class":389},[379,515,407],{"class":389},[379,517,410],{"class":389},[379,519,413],{"class":389},[379,521,522],{"class":389}," -r",[379,524,525],{"class":389}," json",[379,527,528],{"class":389}," -o",[379,530,531],{"class":389}," report",[379,533,534],{"class":389}," --silent\n",[379,536,537,540,543],{"class":381,"line":400},[379,538,539],{"class":385},"node",[379,541,542],{"class":389}," -e",[379,544,545],{"class":419}," '\n",[379,547,549],{"class":381,"line":548},3,[379,550,551],{"class":389},"const r = require(\".\u002Freport\u002Fjscpd-compare.json\")\n",[379,553,555],{"class":381,"line":554},4,[379,556,557],{"class":389},"const copies = r.code.pairs.filter(p => !p.b.file.endsWith(\".rs\") && p.similarity >= 0.97)\n",[379,559,561],{"class":381,"line":560},5,[379,562,563],{"class":389},"console.log(new Set(copies.map(p => p.a.file + \":\" + p.a.name)).size, \"functions paired with an unchanged copy\")\n",[379,565,567],{"class":381,"line":566},6,[379,568,569],{"class":419},"'\n",[258,571,572,573,576,577,580,581,583],{},"Change ",[282,574,575],{},".rs"," to the extension of your target language. jscpd doesn't flag these pairs on its own yet, and ",[282,578,579],{},"--semantic-scope cross",", which keeps only the pairs across languages, doesn't change what ",[282,582,295],{}," counts. It would help if it did.",[317,585,587],{"id":586},"the-loop-how-the-skill-drives-a-port","The loop: how the skill drives a port",[258,589,590,591,593],{},"The report on its own is a measurement. The ",[282,592,291],{}," skill makes it the loop the agent works in:",[431,595,596,602,605,608],{},[434,597,598,599,601],{},"Run ",[282,600,295],{}," on the source and an empty target to list every function to port.",[434,603,604],{},"Collect test coverage of the source and map each test to the functions it runs, so every function is ported together with the tests that check it.",[434,606,607],{},"Port the tests first, keeping inputs and expected values as they are. No stubs to make them compile, because a stub with the source's name can pair by name and count as done.",[434,609,610,611,613,614,616],{},"Port the code one function at a time, starting from ",[282,612,494],{},", and rerun ",[282,615,295],{}," after each step to see the function leave the unmatched list and pair with the right thing.",[258,618,619,620,622,623,626,627,630,631,633],{},"One rule in the skill comes from its first run. The agent vendored its Rust dependencies into the target folder, about two thousand files of tokio, libc and syn, then ran ",[282,621,295],{}," without ",[282,624,625],{},"--ignore",". jscpd dutifully embedded every function of every crate, and the agent spent 36 minutes waiting on it. The skill now tells the agent to keep vendored code and build output out of both paths, through a ",[282,628,629],{},".gitignore"," (which jscpd reads only inside a git repository) or through ",[282,632,625],{},". The ban on stubs in step 3 was there from the start, for a similar reason. A stub carries the source's name, pairs by name, and raises the number without moving anything.",[258,635,636],{},"Nothing in the four steps names a language. The rest of this post is one project the agent ran them on.",[317,638,640],{"id":639},"the-case-fs-extra-to-rust-twice","The case: fs-extra to Rust, twice",[258,642,643,644,649],{},"The agent was ",[262,645,648],{"href":646,"rel":647},"https:\u002F\u002Fgithub.com\u002Fearendil-works\u002Fpi",[266],"pi"," 0.99.1 running GLM-5.3-flash through ollama. The task, word for word in both runs, was to port fs-extra 11.4.1 to Rust as a native addon built with napi-rs, as a drop-in replacement with the same API, behavior and errors. fs-extra's test suite had to pass against the port, the port had to be faster, and the agent had to work without asking questions.",[258,651,652,653,656,657,483,660,462,663,666,667,670,671,673],{},"The two numbers at the top count different things. Of the 149 names fs-extra exports, 104 are Node's own ",[282,654,655],{},"fs"," methods passed through, and 45 are fs-extra's own API, which is 27 functions under several names (",[282,658,659],{},"mkdirs",[282,661,662],{},"mkdirp",[282,664,665],{},"ensureDir"," are one function). The 51 are the functions in fs-extra's ",[282,668,669],{},"lib\u002F"," folder, internal helpers included, that reach the minimum ",[282,672,295],{}," counts, 30 tokens and 5 lines. The folder has 72 in all.",[258,675,676],{},"I'll call the two runs by the names their code now has on GitHub:",[678,679,680,692],"ul",{},[434,681,682,685,686,462,688,691],{},[437,683,684],{},"fs-extra-rs"," got two skills from the jscpd repository, ",[282,687,291],{},[282,689,690],{},"compare-codebases",", and one extra line in the prompt: \"Use the code-migration skill for this port.\"",[434,693,694,697],{},[437,695,696],{},"fs-extra-rs-plain"," got nothing extra.",[258,699,700],{},"Both ran at the same time on one M1 laptop. This was the second round of the experiment. The first round ended the same way, and I'll come back to it.",[258,702,703],{},"fs-extra-rs was done in 123 minutes. fs-extra-rs-plain had its tests green after about an hour and then spent most of the next two running its own benchmark, until it hit the three-hour limit I had set per session.",[317,705,707],{"id":706},"what-the-tests-said","What the tests said",[258,709,710],{},"A port that keeps the source's JavaScript is guaranteed to pass the source's tests. It is the one thing about it you can count on.",[258,712,713,714,717,718,721,722,725],{},"fs-extra's suite even rewards copying. Six of its test files replace parts of fs-extra's internals with stubs, through proxyquire or a mocked ",[282,715,716],{},"fs.rename",", and those tests only work if the JavaScript internals exist. The agent behind fs-extra-rs-plain kept the internals, changed no test, and got 745 passing tests. fs-extra-rs has no JavaScript internals to stub, so its agent rewrote five of those files to cause real failures instead, an ",[282,719,720],{},"EACCES"," from a directory with mode ",[282,723,724],{},"000"," and real moves between two file systems where the originals mocked one. fs-extra-rs ended with 734 passing and 11 skipped.",[258,727,728],{},"Those numbers are each agent's own run of fs-extra's whole suite, 753 tests in 80 files before the agents touched them. Seventeen of those files load fs-extra's private modules directly or through proxyquire, so with the entry point swapped they would still test the original JavaScript. The comparison below counts the other 63 files, 491 tests.",[258,730,731,732,735],{},"To take the agents' own test changes out of the picture, I also ran fs-extra's unmodified tests against both ports, swapping fs-extra's entry point for the port. Both ports gave the same result, 488 of 491 passing and 2 skipped, and the same single test failed in both, because both export ",[282,733,734],{},"fs.realpath.native"," and fs-extra doesn't.",[258,737,738],{},"So \"all tests green\" was true for both, and it said nothing about how much porting had happened.",[317,740,742],{"id":741},"what-the-reports-said","What the reports said",[258,744,745],{},"Here is part of the report for fs-extra-rs-plain, the port made without the skill:",[370,747,752],{"className":748,"code":750,"language":751,"meta":375},[749],"language-text"," 80% 41 of 51 functions in fs-extra\u002Flib have a counterpart in fs-extra-rs-plain\n\n  file                     paired  similarity   counterpart\n  ensure\u002Flink.js           2 \u002F 2   1.00         lib\u002Fensure\u002Flink.js\n  ensure\u002Fsymlink-paths.js  2 \u002F 2   1.00         lib\u002Fensure\u002Fsymlink-paths.js\n  move\u002Fmove.js             3 \u002F 3   1.00         lib\u002Fmove\u002Fmove.js\n  move\u002Fmove-sync.js        5 \u002F 5   0.94         lib\u002Fmove\u002Fmove-sync.js\n  util\u002Fstat.js             7 \u002F 7   0.90         lib\u002Futil\u002Fstat.js\n","text",[282,753,750],{"__ignoreMap":375},[258,755,756,757,759,760,762,763,768],{},"Look at the counterpart column. ",[282,758,330],{}," pairs with ",[282,761,347],{}," in the port at a similarity of 1.00, the same function in the same language. That is not a port. It is the original. The ",[262,764,767],{"href":765,"target":766},"\u002Fexamples\u002Fcompare-fs-extra-rs-plain.html","_blank","HTML report for fs-extra-rs-plain"," marks these pairs as ported too, and only the file in the counterpart column gives them away.",[770,771],"report-screenshot",{":height":772,":width":773,"alt":774,"caption":775,"dark":776,"href":765,"light":777,"link-text":778},"1302","1560","The migration map of jscpd --compare for fs-extra-rs-plain, one mark per folder: fs-extra's folders on the left, code as circles and tests as squares, bridged to folders of the same names under lib\u002F in the port on the right; 80% of functions and 428 of 428 tests have a counterpart.","fs-extra-rs-plain, one mark per folder. Circles are code and squares are tests. Most of the code bridges to folders of the same names under lib\u002F, still in JavaScript.","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002Fmap-fs-extra-rs-plain-dark.webp","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002Fmap-fs-extra-rs-plain-light.webp","Open the report for fs-extra-rs-plain",[258,780,781],{},"And part of the report for fs-extra-rs:",[370,783,786],{"className":784,"code":785,"language":751,"meta":375},[749]," 98% 50 of 51 functions in fs-extra\u002Flib have a counterpart in fs-extra-rs\n\n  file                     paired   similarity  counterpart\n  copy\u002Fcopy-sync.js        10 \u002F 10  0.83        src\u002Fcopy_sync.rs\n  move\u002Fmove.js             3 \u002F 3    0.85        src\u002Fmove_mod.rs\n  move\u002Fmove-sync.js        5 \u002F 5    0.85        src\u002Fmove_sync.rs\n  util\u002Fstat.js             7 \u002F 7    0.81        src\u002Futil_stat.rs\n",[282,787,785],{"__ignoreMap":375},[258,789,790,791,793,794,798],{},"Same files, counterparts in ",[282,792,575],{},", similarities around 0.8, which is what a faithful port into another language looks like. Here is ",[262,795,797],{"href":796,"target":766},"\u002Fexamples\u002Fcompare-fs-extra-rs.html","the HTML report for fs-extra-rs",", the port published as @jscpd\u002Ffs-extra.",[770,800],{":height":801,":width":773,"alt":802,"caption":803,"dark":804,"href":796,"light":805,"link-text":806},"1290","The migration map of jscpd --compare for fs-extra-rs, one mark per folder: fs-extra's code folders bridge to src, the Rust core, and to thin wrappers under lib\u002F, and its test folders bridge to test folders of the same names; 98% of functions and 417 of 428 tests have a counterpart.","fs-extra-rs, one mark per folder. The code bridges to src, the Rust core, and to thin wrappers under lib\u002F.","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002Fmap-fs-extra-rs-dark.webp","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002Fmap-fs-extra-rs-light.webp","Open the report for fs-extra-rs",[258,808,809],{},"Both reports come from jscpd 5.4.1 and measure the tests as well as the code. They leave out the ports' benchmarks and build output, and with them the unchanged copy of fs-extra that fs-extra-rs-plain keeps in its benchmark folder.",[258,811,812],{},"Sorting all 51 functions by where their counterpart lives:",[814,815,816,832],"table",{},[817,818,819],"thead",{},[820,821,822,826,829],"tr",{},[823,824,825],"th",{},"fs-extra's 51 functions",[823,827,828],{},"fs-extra-rs (with the skill)",[823,830,831],{},"fs-extra-rs-plain (without)",[833,834,835,847,858,869],"tbody",{},[820,836,837,841,844],{},[838,839,840],"td",{},"Counterpart in Rust",[838,842,843],{},"34",[838,845,846],{},"4",[820,848,849,852,855],{},[838,850,851],{},"Copied unchanged into the port's JavaScript",[838,853,854],{},"0",[838,856,857],{},"32",[820,859,860,863,866],{},[838,861,862],{},"Counterpart is a JavaScript wrapper that calls Rust",[838,864,865],{},"16",[838,867,868],{},"5",[820,870,871,874,877],{},[838,872,873],{},"No counterpart",[838,875,876],{},"1",[838,878,879],{},"10",[258,881,882],{},[300,883],{"alt":884,"src":885},"fs-extra's 51 functions by where their counterpart lives","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002F3-51-functions-by-counterpart.svg",[258,887,888],{},[307,889,890],{},"fs-extra's 51 functions by where their counterpart lives. The magenta block is code that never left JavaScript.",[258,892,893,894,897,898,901],{},"The 16 JavaScript pairs in fs-extra-rs are thin files that keep fs-extra's module layout. Each function calls the native core and turns its error into Node's format. Their similarity sits between 0.69 and 0.91, never near 1.00. Its one unpaired function, ",[282,895,896],{},"asyncIteratorConcurrentProcess",", has nothing to do in the port, because the Rust ",[282,899,900],{},"copy"," walks directories on its own threads. The agent noted that decision rather than writing a stub to raise the number.",[258,903,904],{},"In this round the headline numbers point the right way, 98% for fs-extra-rs and 80% for fs-extra-rs-plain. In the first round they didn't. The run without the skill scored 84% and the run with it scored 73%, because the headline number counts a copy as a counterpart, and the copy-heavy port had more counterparts. That run had copied 37 functions. Its own summary called the result \"a drop-in Rust port of fs-extra 11.4.1\" with \"~2,600 lines of Rust\". The copy-counting script above prints 0 and 3 for the runs with the skill, 32 and 37 for the runs without.",[258,906,907],{},[300,908],{"alt":909,"src":910},"Headline percentage against the number of copies","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002F5-headline-vs-copies.svg",[258,912,913],{},[307,914,915],{},"The headline number counts a copy as a counterpart. Count the copies before you trust the percentage.",[258,917,918,919,921,922,924,925,927],{},"The agent behind fs-extra-rs followed the loop almost to the letter. It ran ",[282,920,295],{}," 11 times, and all 11 runs together took under two minutes thanks to the vector cache. It also wrote the ",[282,923,629],{}," the skill suggests and never waited on vendored crates. The agent behind fs-extra-rs-plain never ran ",[282,926,295],{},", and never had a reason to look at what it had kept.",[317,929,931],{"id":930},"what-the-benchmark-said","What the benchmark said",[258,933,934],{},"I benchmarked both ports against the original fs-extra on the same laptop: 30 scenarios, each library in its own process, three rounds with the order rotated, medians with bootstrap confidence intervals.",[814,936,937,948],{},[817,938,939],{},[820,940,941,944,946],{},[823,942,943],{},"30 scenarios",[823,945,828],{},[823,947,831],{},[833,949,950,961,971,981],{},[820,951,952,955,958],{},[838,953,954],{},"Faster than fs-extra",[838,956,957],{},"17",[838,959,960],{},"12",[820,962,963,966,969],{},[838,964,965],{},"Same speed (the confidence interval includes ×1.00)",[838,967,968],{},"6",[838,970,960],{},[820,972,973,976,979],{},[838,974,975],{},"Slower than fs-extra",[838,977,978],{},"7",[838,980,968],{},[820,982,983,986,989],{},[838,984,985],{},"Geometric mean speedup, without whole-file copies",[838,987,988],{},"×1.12",[838,990,991],{},"×0.98",[258,993,994],{},[300,995],{"alt":996,"src":997},"30 benchmark scenarios","\u002Fimages\u002Fblog\u002Fwhen-code-clones-matter\u002F4-benchmark-30-scenarios.svg",[258,999,1000],{},[307,1001,1002,1003,483,1006,483,1008,483,1011,483,1014,462,1017,473],{},"30 scenarios against the original fs-extra. Six of the twelve ties in the plain port are scenarios that run its copied functions directly: ",[282,1004,1005],{},"move",[282,1007,461],{},[282,1009,1010],{},"ensureFile",[282,1012,1013],{},"ensureFileSync",[282,1015,1016],{},"ensureSymlinkSync",[282,1018,1019],{},"ensureLinkSync",[258,1021,1022],{},"I leave whole-file copies out of the mean because on macOS both ports hand them to the file system's clone call, and a \"speedup\" of 5 to 260 times is a fact about APFS. The three whole-file copy scenarios are among the faster ones in both columns.",[258,1024,1025,1026,1028,1029,1031,1032,1034,1035,1038,1039,1041,1042,1044],{},"Where fs-extra-rs-plain kept fs-extra's JavaScript, it runs at fs-extra's speed, as the same code should. ",[282,1027,1005],{}," comes out at ×1.00 against ×1.65 in fs-extra-rs, async ",[282,1030,1010],{}," at ×0.99 against ×1.29, ",[282,1033,1016],{}," at ×1.00 against ×1.07. fs-extra-rs isn't faster everywhere, though. Its async ",[282,1036,1037],{},"remove"," is ×0.74 and its async ",[282,1040,900],{}," of 2,000 small files ×0.87, so a real native port can still lose to Node's own thread pool. The benchmark measures the port; ",[282,1043,295],{}," tells you whether there is one.",[317,1046,1048],{"id":1047},"what-it-cost","What it cost",[814,1050,1051,1061],{},[817,1052,1053],{},[820,1054,1055,1057,1059],{},[823,1056],{},[823,1058,828],{},[823,1060,831],{},[833,1062,1063,1074,1085,1096,1107],{},[820,1064,1065,1068,1071],{},[838,1066,1067],{},"Time",[838,1069,1070],{},"123 min",[838,1072,1073],{},"180 min, stopped by the time limit",[820,1075,1076,1079,1082],{},[838,1077,1078],{},"Model calls",[838,1080,1081],{},"503",[838,1083,1084],{},"342",[820,1086,1087,1090,1093],{},[838,1088,1089],{},"Input tokens, not cached",[838,1091,1092],{},"952 thousand",[838,1094,1095],{},"2.6 million",[820,1097,1098,1101,1104],{},[838,1099,1100],{},"Output tokens",[838,1102,1103],{},"348 thousand",[838,1105,1106],{},"350 thousand",[820,1108,1109,1112,1115],{},[838,1110,1111],{},"Input tokens read from cache",[838,1113,1114],{},"141 million",[838,1116,1117],{},"111 million",[258,1119,1120],{},"I wouldn't read a verdict into these numbers. The run without the skill in the first round took 76 minutes; this one took 180, almost all of the difference in its own benchmark, which ran three times for over 20 minutes each. Each of those pauses outlived the prompt cache, so the next model call read the whole context, about half a million tokens, uncached. That alone accounts for most of fs-extra-rs-plain's uncached input. Between two runs of the same agent with the same prompt, the spread in time was bigger than any effect of the skill.",[258,1122,1123],{},"What the skill reliably changed was the result. In both rounds, the run with it produced a port, and the run without it produced fs-extra with a native addon attached.",[317,1125,1127],{"id":1126},"try-it","Try it",[370,1129,1131],{"className":372,"code":1130,"language":374,"meta":375,"style":375},"npx jscpd --compare path\u002Fto\u002Fsource path\u002Fto\u002Ftarget\n",[282,1132,1133],{"__ignoreMap":375},[379,1134,1135,1137,1139,1141,1143],{"class":381,"line":382},[379,1136,386],{"class":385},[379,1138,390],{"class":389},[379,1140,407],{"class":389},[379,1142,410],{"class":389},[379,1144,1145],{"class":389}," path\u002Fto\u002Ftarget\n",[678,1147,1148,1170,1185],{},[434,1149,1150,1151,1154,1155,1160,1161,1166,1167,1169],{},"The skill installs into any agent that reads skills with one command, ",[282,1152,1153],{},"npx skills add https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd --skill code-migration",", and its full text is on ",[262,1156,1159],{"href":1157,"rel":1158},"https:\u002F\u002Fwww.skills.sh\u002Fkucherenko\u002Fjscpd\u002Fcode-migration",[266],"skills.sh"," and in the ",[262,1162,1165],{"href":1163,"rel":1164},"https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\u002Ftree\u002Fmaster\u002Fskills",[266],"jscpd repository"," next to ",[282,1168,690],{},". Then give the agent the single prompt line \"Use the code-migration skill for this port.\"",[434,1171,1172,1173,1178,1179,1184],{},"The port made with the skill is on npm as ",[262,1174,1177],{"href":1175,"rel":1176},"https:\u002F\u002Fwww.npmjs.com\u002Fpackage\u002F@jscpd\u002Ffs-extra",[266],"@jscpd\u002Ffs-extra",", with the code at ",[262,1180,1183],{"href":1181,"rel":1182},"https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Ffs-extra-rs",[266],"kucherenko\u002Ffs-extra-rs",". It is experimental, and only checked as described here.",[434,1186,1187,1188,473],{},"The port made without the skill is kept for comparison at ",[262,1189,1192],{"href":1190,"rel":1191},"https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Ffs-extra-rs-plain",[266],"kucherenko\u002Ffs-extra-rs-plain",[258,1194,1195,1196,1198],{},"If you run an agent on a migration, have it run ",[282,1197,295],{}," after every green test run, and read the counterpart column yourself before you believe the summary. The loop is the same whatever the source and the target are. fs-extra is only the project this agent ran it on.",[1200,1201,1202],"style",{},"html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":375,"searchDepth":400,"depth":400,"links":1204},[1205,1206,1207,1208,1209,1210,1211,1212,1213],{"id":319,"depth":400,"text":320},{"id":498,"depth":400,"text":499},{"id":586,"depth":400,"text":587},{"id":639,"depth":400,"text":640},{"id":706,"depth":400,"text":707},{"id":741,"depth":400,"text":742},{"id":930,"depth":400,"text":931},{"id":1047,"depth":400,"text":1048},{"id":1126,"depth":400,"text":1127},"2026-10-12","A method for letting a coding agent port code to another language and checking what it really ported. jscpd --compare follows every source function into the target, the code-migration skill turns the report into a loop, and an fs-extra to Rust experiment shows what the tests miss.","md",{},"\u002Fblog\u002Fwhen-code-clones-matter","2026-10-12T13:30:00Z",{"title":251,"description":1215},"blog\u002Fwhen-code-clones-matter",[1223,1224],"migration","compare","49Kie_CDZ8diQwaPPsUqwbz-kGcPsBEKXUVJTuaDw_s",{"\u002Fblog\u002Fwhen-code-clones-matter":1227},{"views":1228,"visits":1229},522,128,1795510274106]