Cross-language code duplication scanner + classifier + fix-suggester. Tree-sitter based. nWave plugin.
Project description
nwave-dedup
Cross-language code duplication scanner + classifier + fix-suggester. Tree-sitter based. Part of the nWave ecosystem.
What it does
Finds duplicate logic across your codebase — not just byte-identical copies but structurally similar functions. Then classifies what's safe to refactor and suggests how:
| Class | Meaning | Action |
|---|---|---|
MIGRATABLE |
Production code, no special context | Extract to shared helper |
STRUCTURAL |
Required by tooling (e.g. pytest-bdd in path-with-hyphen dirs) |
Document, don't refactor |
ADAPTER_PATTERN |
Intentional polymorphism (_uv vs _pipx, v1 vs v2) |
Document as design choice |
TEST_FIXTURE |
Test helpers duplicated across conftest layers | Consolidate via conftest |
UNVERIFIABLE |
Generic name (__init__, setUp) — accidental shape match |
Human review required |
Why it exists
Manual code review misses duplicate logic across modules. AST-based scanners typically support only one language. nwave-dedup uses tree-sitter to parse 50+ languages from a single Python CLI, classifies findings honestly (no false-positive dump), and suggests concrete refactor paths.
The honesty bar is the differentiator: a duplicate that looks like a refactor candidate but is actually an intentional adapter pattern is worse than no flag at all — it trains developers to ignore the tool. Every classification carries a one-line reason a human can override.
Install
pip install git+https://github.com/nWave-ai/nwave-dedup.git
Usage
# Scan your project, get markdown report (default top 20 groups)
nwave-dedup scan src/ tests/
# JSON output (CI-friendly)
nwave-dedup scan src/ --format json --output report.json
# Tune sensitivity: only flag functions ≥10 statements
nwave-dedup scan src/ --min-statements 10
# Show all groups (not just top 20)
nwave-dedup scan src/ --top 1000
Sample output
# Duplicate-shape scan
**Total groups**: 4 | **Showing top**: 4
**Classification summary** (heuristic — every verdict needs human confirm):
| Class | Count |
|-----------------|-------|
| MIGRATABLE | 1 |
| ADAPTER_PATTERN | 2 |
| TEST_FIXTURE | 0 |
| STRUCTURAL | 1 |
| UNVERIFIABLE | 0 |
## Group 1 [MIGRATABLE] — 2 clones, ~12 stmts each
_2 clones × ~12 stmts in production code; no structural / adapter / fixture
markers detected — extract to shared helper_
- `src/uninstall.py:42` `def remove_agents()` (python)
- `src/uninstall.py:71` `def remove_commands()` (python)
Status
Pre-alpha (v0.1.0.dev0). Currently shipped:
- Multi-language scanner: Python, JavaScript, TypeScript, Rust, Go, Ruby, OCaml
- Classifier with 5 heuristic classes (see table above)
- Markdown + JSON output formats
Planned for v0.2:
nwave-dedup baseline— snapshot current count, fail CI if it increasesnwave-dedup fix --interactive— refactor wizard forMIGRATABLEgroups- Expanded language support (more grammars from tree-sitter-language-pack)
- Performance: incremental scan via mtime cache
Honest limitations
- Classifier is heuristic, not proof. False positives exist; every verdict carries a reason string a human can override. Earned Trust applies.
- AST-shape only. Two functions with identical structure but different semantics (e.g. one increments, one decrements) hash to the same group.
- Per-grammar cost. Each language adds ~1-3 MB to the wheel via
tree-sitter-language-pack. The current pin (0.7.0) bundles all 50+ languages by default — future versions may split this.
License
MIT — see LICENSE.
Related
- nWave — parent methodology framework
- tree-sitter — the multi-language parser engine
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nwave_dedup-0.1.0.dev0.tar.gz.
File metadata
- Download URL: nwave_dedup-0.1.0.dev0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1861ec417b4e3a7b42a514cb3bdfbf1651993cb3f3153c386a49d461dcaf325
|
|
| MD5 |
13efad7d05e8fb14be1e69c12b79d119
|
|
| BLAKE2b-256 |
011745429f7f11efb3f1e45b44ce3dab8bd46a450ecf7f21404d7eb9d1a7c19f
|
Provenance
The following attestation bundles were made for nwave_dedup-0.1.0.dev0.tar.gz:
Publisher:
release.yml on nWave-ai/nwave-dedup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nwave_dedup-0.1.0.dev0.tar.gz -
Subject digest:
e1861ec417b4e3a7b42a514cb3bdfbf1651993cb3f3153c386a49d461dcaf325 - Sigstore transparency entry: 1436108215
- Sigstore integration time:
-
Permalink:
nWave-ai/nwave-dedup@08f7cd2f092789f5c8fad3169f7b1f7179d2afb2 -
Branch / Tag:
refs/tags/v0.1.0.dev0 - Owner: https://github.com/nWave-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@08f7cd2f092789f5c8fad3169f7b1f7179d2afb2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nwave_dedup-0.1.0.dev0-py3-none-any.whl.
File metadata
- Download URL: nwave_dedup-0.1.0.dev0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc90978083e3b15440e4b1b022da81f55d1d97376c08c638024a8fa662015b90
|
|
| MD5 |
99703b4ef63d7cb8bbac5db543df4e9e
|
|
| BLAKE2b-256 |
ec141c3664d06123cea245c8d0bb4714a5a800349eed0da08ac65fe850cde698
|
Provenance
The following attestation bundles were made for nwave_dedup-0.1.0.dev0-py3-none-any.whl:
Publisher:
release.yml on nWave-ai/nwave-dedup
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nwave_dedup-0.1.0.dev0-py3-none-any.whl -
Subject digest:
dc90978083e3b15440e4b1b022da81f55d1d97376c08c638024a8fa662015b90 - Sigstore transparency entry: 1436108218
- Sigstore integration time:
-
Permalink:
nWave-ai/nwave-dedup@08f7cd2f092789f5c8fad3169f7b1f7179d2afb2 -
Branch / Tag:
refs/tags/v0.1.0.dev0 - Owner: https://github.com/nWave-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@08f7cd2f092789f5c8fad3169f7b1f7179d2afb2 -
Trigger Event:
push
-
Statement type: