redup 0.1.1__tar.gz

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 (34) hide show
  1. redup-0.1.1/LICENSE +190 -0
  2. redup-0.1.1/PKG-INFO +254 -0
  3. redup-0.1.1/README.md +208 -0
  4. redup-0.1.1/pyproject.toml +78 -0
  5. redup-0.1.1/setup.cfg +4 -0
  6. redup-0.1.1/src/redup/__init__.py +25 -0
  7. redup-0.1.1/src/redup/__main__.py +5 -0
  8. redup-0.1.1/src/redup/cli_app/__init__.py +1 -0
  9. redup-0.1.1/src/redup/cli_app/main.py +161 -0
  10. redup-0.1.1/src/redup/core/__init__.py +1 -0
  11. redup-0.1.1/src/redup/core/hasher.py +199 -0
  12. redup-0.1.1/src/redup/core/matcher.py +91 -0
  13. redup-0.1.1/src/redup/core/models.py +153 -0
  14. redup-0.1.1/src/redup/core/pipeline.py +185 -0
  15. redup-0.1.1/src/redup/core/planner.py +118 -0
  16. redup-0.1.1/src/redup/core/scanner.py +193 -0
  17. redup-0.1.1/src/redup/reporters/__init__.py +1 -0
  18. redup-0.1.1/src/redup/reporters/json_reporter.py +66 -0
  19. redup-0.1.1/src/redup/reporters/toon_reporter.py +75 -0
  20. redup-0.1.1/src/redup/reporters/yaml_reporter.py +34 -0
  21. redup-0.1.1/src/redup.egg-info/PKG-INFO +254 -0
  22. redup-0.1.1/src/redup.egg-info/SOURCES.txt +32 -0
  23. redup-0.1.1/src/redup.egg-info/dependency_links.txt +1 -0
  24. redup-0.1.1/src/redup.egg-info/entry_points.txt +2 -0
  25. redup-0.1.1/src/redup.egg-info/requires.txt +25 -0
  26. redup-0.1.1/src/redup.egg-info/top_level.txt +1 -0
  27. redup-0.1.1/tests/test_e2e.py +447 -0
  28. redup-0.1.1/tests/test_hasher.py +64 -0
  29. redup-0.1.1/tests/test_matcher.py +65 -0
  30. redup-0.1.1/tests/test_models.py +104 -0
  31. redup-0.1.1/tests/test_pipeline.py +128 -0
  32. redup-0.1.1/tests/test_planner.py +96 -0
  33. redup-0.1.1/tests/test_reporters.py +100 -0
  34. redup-0.1.1/tests/test_scanner.py +73 -0
redup-0.1.1/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work.
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by the Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding any notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Tom Sapletta
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
redup-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,254 @@
1
+ Metadata-Version: 2.4
2
+ Name: redup
3
+ Version: 0.1.1
4
+ Summary: Code duplication analyzer and refactoring planner for LLMs
5
+ Author-email: Tom Sapletta <tom@sapletta.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/semcod/redup
8
+ Project-URL: Repository, https://github.com/semcod/redup
9
+ Project-URL: Issues, https://github.com/semcod/redup/issues
10
+ Project-URL: Documentation, https://github.com/semcod/redup#readme
11
+ Keywords: duplication,refactoring,code-analysis,LLM,AST,static-analysis
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Software Development :: Quality Assurance
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: typer>=0.9.0
27
+ Requires-Dist: rich>=13.0
28
+ Requires-Dist: pydantic>=2.0
29
+ Provides-Extra: all
30
+ Requires-Dist: redup[fuzzy]; extra == "all"
31
+ Requires-Dist: redup[ast]; extra == "all"
32
+ Requires-Dist: redup[lsh]; extra == "all"
33
+ Provides-Extra: fuzzy
34
+ Requires-Dist: rapidfuzz>=3.0; extra == "fuzzy"
35
+ Provides-Extra: ast
36
+ Requires-Dist: tree-sitter>=0.21; extra == "ast"
37
+ Requires-Dist: tree-sitter-language-pack>=0.1; extra == "ast"
38
+ Provides-Extra: lsh
39
+ Requires-Dist: datasketch>=1.6; extra == "lsh"
40
+ Provides-Extra: dev
41
+ Requires-Dist: pytest>=7.0; extra == "dev"
42
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
43
+ Requires-Dist: ruff>=0.4; extra == "dev"
44
+ Requires-Dist: mypy>=1.8; extra == "dev"
45
+ Dynamic: license-file
46
+
47
+ # reDUP
48
+
49
+ **Code duplication analyzer and refactoring planner for LLMs.**
50
+
51
+ [![PyPI](https://img.shields.io/pypi/v/redup)](https://pypi.org/project/redup/)
52
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
53
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://python.org)
54
+
55
+ reDUP scans codebases for duplicated functions, blocks, and structural patterns — then builds a prioritized refactoring map that LLMs can consume to eliminate redundancy systematically.
56
+
57
+ ## Features
58
+
59
+ - **Exact duplicate detection** via SHA-256 block hashing
60
+ - **Structural clone detection** — same AST shape, different variable names
61
+ - **Fuzzy near-duplicate matching** via SequenceMatcher / rapidfuzz
62
+ - **Function-level analysis** using Python AST extraction
63
+ - **Impact scoring** — prioritizes duplicates by `saved_lines × similarity`
64
+ - **Refactoring planner** — generates concrete extract/inline suggestions
65
+ - **Three output formats**: JSON (tooling), YAML (humans), TOON (LLMs)
66
+ - **CLI** with `typer` + `rich` for interactive use
67
+
68
+ ## Installation
69
+
70
+ ```bash
71
+ pip install redup
72
+ ```
73
+
74
+ With optional dependencies:
75
+
76
+ ```bash
77
+ pip install redup[all] # Everything
78
+ pip install redup[fuzzy] # rapidfuzz for better similarity matching
79
+ pip install redup[ast] # tree-sitter for multi-language AST
80
+ pip install redup[lsh] # datasketch for LSH near-duplicate detection
81
+ ```
82
+
83
+ ## Quick Start
84
+
85
+ ### CLI
86
+
87
+ ```bash
88
+ # Scan current directory, output TOON to stdout
89
+ redup scan .
90
+
91
+ # Scan with JSON output saved to file
92
+ redup scan ./src --format json --output ./reports/
93
+
94
+ # Scan with all formats
95
+ redup scan . --format all --output ./redup_output/
96
+
97
+ # Only function-level duplicates (faster)
98
+ redup scan . --functions-only
99
+
100
+ # Custom thresholds
101
+ redup scan . --min-lines 5 --min-sim 0.9
102
+
103
+ # Show installed optional dependencies
104
+ redup info
105
+ ```
106
+
107
+ ### Python API
108
+
109
+ ```python
110
+ from pathlib import Path
111
+ from redup import ScanConfig, analyze
112
+ from redup.reporters.toon_reporter import to_toon
113
+ from redup.reporters.json_reporter import to_json
114
+
115
+ config = ScanConfig(
116
+ root=Path("./my_project"),
117
+ extensions=[".py"],
118
+ min_block_lines=3,
119
+ min_similarity=0.85,
120
+ )
121
+
122
+ result = analyze(config=config, function_level_only=True)
123
+
124
+ print(f"Found {result.total_groups} duplicate groups")
125
+ print(f"Lines recoverable: {result.total_saved_lines}")
126
+
127
+ # For LLM consumption
128
+ print(to_toon(result))
129
+
130
+ # For tooling / CI
131
+ Path("duplication.json").write_text(to_json(result))
132
+ ```
133
+
134
+ ## Output Formats
135
+
136
+ ### TOON (LLM-optimized)
137
+
138
+ ```
139
+ # redup/duplication | 3 groups | 12f 4200L | 2026-03-22
140
+
141
+ SUMMARY:
142
+ files_scanned: 12
143
+ total_lines: 4200
144
+ dup_groups: 3
145
+ saved_lines: 84
146
+
147
+ DUPLICATES[3] (ranked by impact):
148
+ [E0001] !! EXAC calculate_tax L=8 N=3 saved=16 sim=1.00
149
+ billing.py:1-8 (calculate_tax)
150
+ shipping.py:1-8 (calculate_tax)
151
+ returns.py:1-8 (calculate_tax)
152
+
153
+ REFACTOR[1] (ranked by priority):
154
+ [1] ○ extract_function → utils/calculate_tax.py
155
+ WHY: 3 occurrences of 8-line block across 3 files — saves 16 lines
156
+ FILES: billing.py, shipping.py, returns.py
157
+ ```
158
+
159
+ ### JSON (machine-readable)
160
+
161
+ ```json
162
+ {
163
+ "summary": {
164
+ "total_groups": 3,
165
+ "total_saved_lines": 84
166
+ },
167
+ "groups": [
168
+ {
169
+ "id": "E0001",
170
+ "type": "exact",
171
+ "normalized_name": "calculate_tax",
172
+ "fragments": [
173
+ {"file": "billing.py", "line_start": 1, "line_end": 8},
174
+ {"file": "shipping.py", "line_start": 1, "line_end": 8}
175
+ ],
176
+ "saved_lines_potential": 16
177
+ }
178
+ ],
179
+ "refactor_suggestions": [
180
+ {
181
+ "priority": 1,
182
+ "action": "extract_function",
183
+ "new_module": "utils/calculate_tax.py",
184
+ "risk_level": "low"
185
+ }
186
+ ]
187
+ }
188
+ ```
189
+
190
+ ## Architecture
191
+
192
+ ```
193
+ src/redup/
194
+ ├── __init__.py # Public API
195
+ ├── __main__.py # python -m redup
196
+ ├── core/
197
+ │ ├── models.py # Pydantic data models
198
+ │ ├── scanner.py # File discovery + block extraction
199
+ │ ├── hasher.py # SHA-256 / structural fingerprinting
200
+ │ ├── matcher.py # Fuzzy similarity comparison
201
+ │ ├── planner.py # Refactoring suggestion generator
202
+ │ └── pipeline.py # Orchestrator: scan → hash → match → plan
203
+ ├── reporters/
204
+ │ ├── json_reporter.py # JSON output
205
+ │ ├── yaml_reporter.py # YAML output
206
+ │ └── toon_reporter.py # TOON output (LLM-optimized)
207
+ └── cli_app/
208
+ └── main.py # Typer CLI
209
+ ```
210
+
211
+ ## Analysis Pipeline
212
+
213
+ ```
214
+ 1. SCAN Walk project, read files, extract function-level + sliding-window blocks
215
+ 2. HASH Generate exact (SHA-256) and structural (normalized AST) fingerprints
216
+ 3. GROUP Bucket by hash, keep only groups with 2+ blocks from different locations
217
+ 4. MATCH Verify candidates with fuzzy similarity (SequenceMatcher / rapidfuzz)
218
+ 5. DEDUP Remove overlapping groups (keep highest-impact)
219
+ 6. PLAN Generate prioritized refactoring suggestions with risk assessment
220
+ 7. REPORT Export to JSON / YAML / TOON
221
+ ```
222
+
223
+ ## Integration with wronai Toolchain
224
+
225
+ reDUP is part of the [wronai](https://github.com/wronai) developer toolchain:
226
+
227
+ - **[code2llm](https://github.com/wronai/code2llm)** — static analysis engine (health diagnostics, complexity)
228
+ - **reDUP** — deep duplication analysis and refactoring planning
229
+ - **[code2docs](https://github.com/wronai/code2docs)** — automatic documentation generation
230
+ - **[vallm](https://github.com/semcod/vallm)** — validation of LLM-generated code proposals
231
+
232
+ Typical workflow:
233
+
234
+ 1. `code2llm` analyzes the project → `.toon` diagnostics
235
+ 2. `redup` finds duplicates → `duplication.toon`
236
+ 3. Feed both to an LLM for targeted refactoring
237
+ 4. `vallm` validates the LLM's proposals before merging
238
+
239
+ ## Development
240
+
241
+ ```bash
242
+ git clone https://github.com/semcod/redup.git
243
+ cd redup
244
+ pip install -e ".[dev]"
245
+ pytest
246
+ ```
247
+
248
+ ## License
249
+
250
+ Apache License 2.0 - see [LICENSE](LICENSE) for details.
251
+
252
+ ## Author
253
+
254
+ Created by **Tom Sapletta** - [tom@sapletta.com](mailto:tom@sapletta.com)
redup-0.1.1/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # reDUP
2
+
3
+ **Code duplication analyzer and refactoring planner for LLMs.**
4
+
5
+ [![PyPI](https://img.shields.io/pypi/v/redup)](https://pypi.org/project/redup/)
6
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
7
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://python.org)
8
+
9
+ reDUP scans codebases for duplicated functions, blocks, and structural patterns — then builds a prioritized refactoring map that LLMs can consume to eliminate redundancy systematically.
10
+
11
+ ## Features
12
+
13
+ - **Exact duplicate detection** via SHA-256 block hashing
14
+ - **Structural clone detection** — same AST shape, different variable names
15
+ - **Fuzzy near-duplicate matching** via SequenceMatcher / rapidfuzz
16
+ - **Function-level analysis** using Python AST extraction
17
+ - **Impact scoring** — prioritizes duplicates by `saved_lines × similarity`
18
+ - **Refactoring planner** — generates concrete extract/inline suggestions
19
+ - **Three output formats**: JSON (tooling), YAML (humans), TOON (LLMs)
20
+ - **CLI** with `typer` + `rich` for interactive use
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ pip install redup
26
+ ```
27
+
28
+ With optional dependencies:
29
+
30
+ ```bash
31
+ pip install redup[all] # Everything
32
+ pip install redup[fuzzy] # rapidfuzz for better similarity matching
33
+ pip install redup[ast] # tree-sitter for multi-language AST
34
+ pip install redup[lsh] # datasketch for LSH near-duplicate detection
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ### CLI
40
+
41
+ ```bash
42
+ # Scan current directory, output TOON to stdout
43
+ redup scan .
44
+
45
+ # Scan with JSON output saved to file
46
+ redup scan ./src --format json --output ./reports/
47
+
48
+ # Scan with all formats
49
+ redup scan . --format all --output ./redup_output/
50
+
51
+ # Only function-level duplicates (faster)
52
+ redup scan . --functions-only
53
+
54
+ # Custom thresholds
55
+ redup scan . --min-lines 5 --min-sim 0.9
56
+
57
+ # Show installed optional dependencies
58
+ redup info
59
+ ```
60
+
61
+ ### Python API
62
+
63
+ ```python
64
+ from pathlib import Path
65
+ from redup import ScanConfig, analyze
66
+ from redup.reporters.toon_reporter import to_toon
67
+ from redup.reporters.json_reporter import to_json
68
+
69
+ config = ScanConfig(
70
+ root=Path("./my_project"),
71
+ extensions=[".py"],
72
+ min_block_lines=3,
73
+ min_similarity=0.85,
74
+ )
75
+
76
+ result = analyze(config=config, function_level_only=True)
77
+
78
+ print(f"Found {result.total_groups} duplicate groups")
79
+ print(f"Lines recoverable: {result.total_saved_lines}")
80
+
81
+ # For LLM consumption
82
+ print(to_toon(result))
83
+
84
+ # For tooling / CI
85
+ Path("duplication.json").write_text(to_json(result))
86
+ ```
87
+
88
+ ## Output Formats
89
+
90
+ ### TOON (LLM-optimized)
91
+
92
+ ```
93
+ # redup/duplication | 3 groups | 12f 4200L | 2026-03-22
94
+
95
+ SUMMARY:
96
+ files_scanned: 12
97
+ total_lines: 4200
98
+ dup_groups: 3
99
+ saved_lines: 84
100
+
101
+ DUPLICATES[3] (ranked by impact):
102
+ [E0001] !! EXAC calculate_tax L=8 N=3 saved=16 sim=1.00
103
+ billing.py:1-8 (calculate_tax)
104
+ shipping.py:1-8 (calculate_tax)
105
+ returns.py:1-8 (calculate_tax)
106
+
107
+ REFACTOR[1] (ranked by priority):
108
+ [1] ○ extract_function → utils/calculate_tax.py
109
+ WHY: 3 occurrences of 8-line block across 3 files — saves 16 lines
110
+ FILES: billing.py, shipping.py, returns.py
111
+ ```
112
+
113
+ ### JSON (machine-readable)
114
+
115
+ ```json
116
+ {
117
+ "summary": {
118
+ "total_groups": 3,
119
+ "total_saved_lines": 84
120
+ },
121
+ "groups": [
122
+ {
123
+ "id": "E0001",
124
+ "type": "exact",
125
+ "normalized_name": "calculate_tax",
126
+ "fragments": [
127
+ {"file": "billing.py", "line_start": 1, "line_end": 8},
128
+ {"file": "shipping.py", "line_start": 1, "line_end": 8}
129
+ ],
130
+ "saved_lines_potential": 16
131
+ }
132
+ ],
133
+ "refactor_suggestions": [
134
+ {
135
+ "priority": 1,
136
+ "action": "extract_function",
137
+ "new_module": "utils/calculate_tax.py",
138
+ "risk_level": "low"
139
+ }
140
+ ]
141
+ }
142
+ ```
143
+
144
+ ## Architecture
145
+
146
+ ```
147
+ src/redup/
148
+ ├── __init__.py # Public API
149
+ ├── __main__.py # python -m redup
150
+ ├── core/
151
+ │ ├── models.py # Pydantic data models
152
+ │ ├── scanner.py # File discovery + block extraction
153
+ │ ├── hasher.py # SHA-256 / structural fingerprinting
154
+ │ ├── matcher.py # Fuzzy similarity comparison
155
+ │ ├── planner.py # Refactoring suggestion generator
156
+ │ └── pipeline.py # Orchestrator: scan → hash → match → plan
157
+ ├── reporters/
158
+ │ ├── json_reporter.py # JSON output
159
+ │ ├── yaml_reporter.py # YAML output
160
+ │ └── toon_reporter.py # TOON output (LLM-optimized)
161
+ └── cli_app/
162
+ └── main.py # Typer CLI
163
+ ```
164
+
165
+ ## Analysis Pipeline
166
+
167
+ ```
168
+ 1. SCAN Walk project, read files, extract function-level + sliding-window blocks
169
+ 2. HASH Generate exact (SHA-256) and structural (normalized AST) fingerprints
170
+ 3. GROUP Bucket by hash, keep only groups with 2+ blocks from different locations
171
+ 4. MATCH Verify candidates with fuzzy similarity (SequenceMatcher / rapidfuzz)
172
+ 5. DEDUP Remove overlapping groups (keep highest-impact)
173
+ 6. PLAN Generate prioritized refactoring suggestions with risk assessment
174
+ 7. REPORT Export to JSON / YAML / TOON
175
+ ```
176
+
177
+ ## Integration with wronai Toolchain
178
+
179
+ reDUP is part of the [wronai](https://github.com/wronai) developer toolchain:
180
+
181
+ - **[code2llm](https://github.com/wronai/code2llm)** — static analysis engine (health diagnostics, complexity)
182
+ - **reDUP** — deep duplication analysis and refactoring planning
183
+ - **[code2docs](https://github.com/wronai/code2docs)** — automatic documentation generation
184
+ - **[vallm](https://github.com/semcod/vallm)** — validation of LLM-generated code proposals
185
+
186
+ Typical workflow:
187
+
188
+ 1. `code2llm` analyzes the project → `.toon` diagnostics
189
+ 2. `redup` finds duplicates → `duplication.toon`
190
+ 3. Feed both to an LLM for targeted refactoring
191
+ 4. `vallm` validates the LLM's proposals before merging
192
+
193
+ ## Development
194
+
195
+ ```bash
196
+ git clone https://github.com/semcod/redup.git
197
+ cd redup
198
+ pip install -e ".[dev]"
199
+ pytest
200
+ ```
201
+
202
+ ## License
203
+
204
+ Apache License 2.0 - see [LICENSE](LICENSE) for details.
205
+
206
+ ## Author
207
+
208
+ Created by **Tom Sapletta** - [tom@sapletta.com](mailto:tom@sapletta.com)