code-gauge 4.5.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +39 -6
  2. package/THIRD-PARTY-NOTICES.txt +8911 -0
  3. package/dist/cliConfig.cjs +1 -1
  4. package/dist/cliConfig.cjs.map +1 -1
  5. package/dist/cliConfig.js +1 -1
  6. package/dist/crossFileDuplication.cjs +1 -1
  7. package/dist/crossFileDuplication.cjs.map +1 -1
  8. package/dist/crossFileDuplication.d.ts +2 -2
  9. package/dist/crossFileDuplication.js +1 -1
  10. package/dist/crossFileDuplication.js.map +1 -1
  11. package/dist/crossFileNearMiss.cjs +1 -1
  12. package/dist/crossFileNearMiss.cjs.map +1 -1
  13. package/dist/crossFileNearMiss.d.ts +18 -12
  14. package/dist/crossFileNearMiss.js +1 -1
  15. package/dist/crossFileNearMiss.js.map +1 -1
  16. package/dist/diffCommand.cjs +1 -1
  17. package/dist/diffCommand.cjs.map +1 -1
  18. package/dist/diffCommand.js +1 -1
  19. package/dist/languages.cjs +1 -1
  20. package/dist/languages.cjs.map +1 -1
  21. package/dist/languages.js +1 -1
  22. package/dist/languages.js.map +1 -1
  23. package/dist/nativeMetrics.cjs +3 -3
  24. package/dist/nativeMetrics.cjs.map +1 -1
  25. package/dist/nativeMetrics.d.ts +14 -0
  26. package/dist/nativeMetrics.js +3 -3
  27. package/dist/nativeMetrics.js.map +1 -1
  28. package/dist/scan.cjs +1 -1
  29. package/dist/scan.js +1 -1
  30. package/dist/types.d.ts +3 -1
  31. package/dist/wasmBinding.cjs +2 -0
  32. package/dist/wasmBinding.cjs.map +1 -0
  33. package/dist/wasmBinding.d.ts +9 -0
  34. package/dist/wasmBinding.js +2 -0
  35. package/dist/wasmBinding.js.map +1 -0
  36. package/dist/worker.cjs +2 -0
  37. package/dist/worker.cjs.map +1 -0
  38. package/dist/worker.d.ts +1 -0
  39. package/dist/worker.js +2 -0
  40. package/dist/worker.js.map +1 -0
  41. package/native/Cargo.toml +5 -2
  42. package/native/build.rs +4 -1
  43. package/native/code-gauge.wasm +0 -0
  44. package/native/src/duplication.rs +332 -234
  45. package/native/src/lib.rs +32 -37
  46. package/native/src/napi.rs +45 -0
  47. package/native/src/near_miss.rs +455 -0
  48. package/native/src/wasm.rs +128 -0
  49. package/package.json +18 -13
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Test](https://github.com/WillBooster/code-gauge/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/code-gauge/actions/workflows/test.yml)
6
6
  [![Test rust](https://github.com/WillBooster/code-gauge/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/code-gauge/actions/workflows/test-rust.yml)
7
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
8
- [![wbfy](https://img.shields.io/badge/wbfy-20.19.0-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.20.2-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
9
9
 
10
10
  A command-line tool that ranks the files of a project by refactoring priority and gates changes
11
11
  against metric regressions, built for AI-agent workflows: an agent asked to "refactor this
@@ -157,10 +157,17 @@ The `duplication` section tunes how clones are detected:
157
157
  - `minSimilarityPercent` (default 70): blocks the exact pipeline misses are additionally compared by
158
158
  similarity (n-gram filtration, then token-level longest-common-subsequence verification, following
159
159
  NIL and NiCad), so a near-miss (Type-3) clone with scattered small edits is still reported when
160
- both blocks are at least this similar and share more than half of their content-bearing tokens.
161
- `100` disables near-miss detection. Applies to within-file detection and to cross-file matching
162
- alike; across files, n-grams shared by more than 1000 blocks (syntax boilerplate) are left out of
163
- the filtration index so boilerplate cannot make candidate counting quadratic in the block count.
160
+ both blocks are at least this similar and share more than half of their content-bearing tokens
161
+ (names and literal values, weighted by rarity so ubiquitous names count less, after ECScan). Two
162
+ refinements apply the same threshold: blocks whose top-level statements were reordered are also
163
+ compared in a canonical statement order, and a copy embedded in added code (on one side or both)
164
+ is matched on its cores, provided the two blocks are within 3 times each other's length (a
165
+ threshold below 34% widens this to whatever the threshold allows): the chain of n-grams unique to
166
+ both blocks (only those continuing a diagonal run) is split at gaps of more than 30 tokens, each
167
+ segment must pass the same threshold on its own, and the verified cores, not the whole blocks,
168
+ are reported. `100` disables near-miss detection. Applies to within-file detection and to cross-file matching alike; across files,
169
+ n-grams shared by more than 1000 blocks (syntax boilerplate) are left out of the filtration index
170
+ so boilerplate cannot make candidate counting quadratic in the block count.
164
171
 
165
172
  ## Metrics
166
173
 
@@ -184,7 +191,8 @@ The `duplication` section tunes how clones are detected:
184
191
  - Within-file duplication: copy-pasted blocks matched on normalized tokens (identifiers anonymized
185
192
  consistently, literals by kind, and literal-dense data tables excluded unless their values also
186
193
  match), with adjacent matches around a small edit merged into gapped (Type-3) clone groups and
187
- near-miss (Type-3) clones matched by token-LCS similarity, plus duplicated line count and ratio
194
+ near-miss (Type-3) clones matched by token-LCS similarity (tolerating reordered statements and
195
+ copies embedded in added code), plus duplicated line count and ratio
188
196
  - Cross-file duplication (via `measureCrossFileDuplication`): copy-pasted blocks shared between
189
197
  files, matched with the same normalization (exact, gapped, and near-miss clones) and reported as
190
198
  groups with their file locations
@@ -249,3 +257,28 @@ console.log(metrics.maxCognitiveComplexity);
249
257
  `detectLanguage(filePath)` maps a file extension to a supported language (or `undefined`) with the
250
258
  same table as the CLI, so `measureCode` can be fed arbitrary source files. Unlike the CLI scan, it
251
259
  does not skip generated files (e.g. `.d.ts`, `.min.js`) or test files.
260
+
261
+ ### Cloudflare Workers
262
+
263
+ Workers cannot load native addons, so the package's `workerd` export runs the same API on a
264
+ WebAssembly build of the Rust engine (about 2.3 MB gzipped). Wrangler resolves that export
265
+ automatically, and no `nodejs_compat` flag is needed:
266
+
267
+ ```ts
268
+ import { measureCode } from 'code-gauge';
269
+
270
+ export default {
271
+ async fetch(request: Request): Promise<Response> {
272
+ const code = await request.text();
273
+ return Response.json(measureCode(code, { language: 'typescript' }));
274
+ },
275
+ };
276
+ ```
277
+
278
+ Only the programmatic API is available; the CLI needs a file system and `git`. The Workers
279
+ runtime's stack limits nesting to a few thousand syntax-tree levels (the native addon allows
280
+ 5,000); deeper sources fail with an error instead of being measured.
281
+
282
+ In this repository, build the WebAssembly module with `bun run build-wasm`. It downloads a
283
+ [wasi-sdk](https://github.com/WebAssembly/wasi-sdk) release for the grammars' C sources unless
284
+ `WASI_SDK_PATH` points to an installation of the same release.