codewrench 0.1.0__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.
- codewrench-0.1.0/PKG-INFO +187 -0
- codewrench-0.1.0/README.md +160 -0
- codewrench-0.1.0/codewrench.egg-info/PKG-INFO +187 -0
- codewrench-0.1.0/codewrench.egg-info/SOURCES.txt +30 -0
- codewrench-0.1.0/codewrench.egg-info/dependency_links.txt +1 -0
- codewrench-0.1.0/codewrench.egg-info/entry_points.txt +2 -0
- codewrench-0.1.0/codewrench.egg-info/requires.txt +10 -0
- codewrench-0.1.0/codewrench.egg-info/top_level.txt +2 -0
- codewrench-0.1.0/pyproject.toml +44 -0
- codewrench-0.1.0/setup.cfg +4 -0
- codewrench-0.1.0/wrench/ai_engine.py +94 -0
- codewrench-0.1.0/wrench/code.py +67 -0
- codewrench-0.1.0/wrench/detectors/__init__.py +0 -0
- codewrench-0.1.0/wrench/detectors/base.py +35 -0
- codewrench-0.1.0/wrench/detectors/high.py +78 -0
- codewrench-0.1.0/wrench/detectors/medium.py +90 -0
- codewrench-0.1.0/wrench/errors.py +16 -0
- codewrench-0.1.0/wrench/ir.py +11 -0
- codewrench-0.1.0/wrench/ir_translator.py +104 -0
- codewrench-0.1.0/wrench/languages/__init__.py +0 -0
- codewrench-0.1.0/wrench/languages/c_rules.py +10 -0
- codewrench-0.1.0/wrench/languages/cpp_rules.py +10 -0
- codewrench-0.1.0/wrench/languages/go_rules.py +10 -0
- codewrench-0.1.0/wrench/languages/javascript_rules.py +11 -0
- codewrench-0.1.0/wrench/languages/python_rules.py +11 -0
- codewrench-0.1.0/wrench/languages/typescript_rules.py +11 -0
- codewrench-0.1.0/wrench/main.py +216 -0
- codewrench-0.1.0/wrench/parser_engine.py +34 -0
- codewrench-0.1.0/wrench/profilers/__init__.py +0 -0
- codewrench-0.1.0/wrench/profilers/profiler.py +44 -0
- codewrench-0.1.0/wrench/reports.py +72 -0
- codewrench-0.1.0/wrench/wrenchignore.py +25 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codewrench
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A multi-language code performance analyser with static analysis and AI-powered fix generation.
|
|
5
|
+
Author-email: Vishad Jain <vishadjain2304@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/vishaddjain/wrench
|
|
8
|
+
Project-URL: Issues, https://github.com/vishaddjain/wrench/issues
|
|
9
|
+
Keywords: performance,static-analysis,code-analysis,AI,developer-tools
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: groq>=1.1.1
|
|
18
|
+
Requires-Dist: python-dotenv>=1.2.2
|
|
19
|
+
Requires-Dist: requests>=2.32.5
|
|
20
|
+
Requires-Dist: tree-sitter>=0.25.2
|
|
21
|
+
Requires-Dist: tree-sitter-python>=0.25.0
|
|
22
|
+
Requires-Dist: tree-sitter-javascript>=0.25.0
|
|
23
|
+
Requires-Dist: tree-sitter-typescript>=0.23.2
|
|
24
|
+
Requires-Dist: tree-sitter-go>=0.25.0
|
|
25
|
+
Requires-Dist: tree-sitter-c>=0.24.1
|
|
26
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4
|
|
27
|
+
|
|
28
|
+
# š§ wrench
|
|
29
|
+
|
|
30
|
+
> Point it at your code. Get back what's slow and how to fix it.
|
|
31
|
+
|
|
32
|
+
Wrench is a multi-language performance analyser that combines static analysis with AI-powered explanations. It finds real performance issues in your code ā nested loops, inefficient patterns, bad practices ā then explains exactly why they're a problem and shows you the fix.
|
|
33
|
+
|
|
34
|
+
No cloud, no setup hell, no enterprise pricing. Just run it on a file.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## What it catches
|
|
39
|
+
|
|
40
|
+
**High priority**
|
|
41
|
+
- Nested loops (O(n²) and worse)
|
|
42
|
+
- Expensive function calls inside loops
|
|
43
|
+
- Repeated attribute access that should be cached
|
|
44
|
+
- String concatenation with `+` in loops
|
|
45
|
+
|
|
46
|
+
**Medium priority**
|
|
47
|
+
- List appends inside nested loops
|
|
48
|
+
- Unnecessary `list(range(n))` creation
|
|
49
|
+
- Bare `except:` and overly broad `except Exception`
|
|
50
|
+
- Global variable access inside loops
|
|
51
|
+
- Mutable default arguments
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Supported languages
|
|
56
|
+
|
|
57
|
+
| Language | Extension |
|
|
58
|
+
|----------|-----------|
|
|
59
|
+
| Python | `.py` |
|
|
60
|
+
| JavaScript | `.js` |
|
|
61
|
+
| TypeScript | `.ts` |
|
|
62
|
+
| Go | `.go` |
|
|
63
|
+
| C | `.c` |
|
|
64
|
+
| C++ | `.cpp`, `.cc` |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
git clone https://github.com/yourusername/wrench.git
|
|
72
|
+
cd wrench
|
|
73
|
+
python -m venv venv
|
|
74
|
+
source venv/bin/activate # Mac/Linux
|
|
75
|
+
venv\Scripts\activate # Windows
|
|
76
|
+
pip install -r requirements.txt
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Create a `.env` file in the project root:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
GROQ_API_KEY=your_key_here
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Get a free Groq API key at [console.groq.com](https://console.groq.com)
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
python main.py yourfile.py
|
|
93
|
+
python main.py app.js
|
|
94
|
+
python main.py main.go
|
|
95
|
+
python main.py server.cpp
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
That's it. Wrench detects the language from the file extension automatically.
|
|
99
|
+
|
|
100
|
+
### Example output
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
Nested loop at line 19 ā potential O(n²)
|
|
104
|
+
String concatenation at line 22 ā use ''.join() instead
|
|
105
|
+
Function call 'expensive_function' inside loop at line 25 ā consider moving it out
|
|
106
|
+
Bare except at line 40 ā catches everything including system exceptions, be specific
|
|
107
|
+
|
|
108
|
+
--- AI Analysis ---
|
|
109
|
+
|
|
110
|
+
1. Nested loop at line 19
|
|
111
|
+
Problem: Two nested loops over the same data gives you O(n²) time complexity.
|
|
112
|
+
For 1000 items that's 1,000,000 iterations instead of 1,000.
|
|
113
|
+
|
|
114
|
+
Fix:
|
|
115
|
+
# before
|
|
116
|
+
for i in items:
|
|
117
|
+
for j in items:
|
|
118
|
+
process(i, j)
|
|
119
|
+
|
|
120
|
+
# after ā use itertools or restructure with a dict lookup
|
|
121
|
+
lookup = {item: process(item) for item in items}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## How it works
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
your file
|
|
130
|
+
ā
|
|
131
|
+
Tree-sitter parses it into a syntax tree
|
|
132
|
+
ā
|
|
133
|
+
IR translator converts to language-agnostic representation
|
|
134
|
+
ā
|
|
135
|
+
Detectors run static analysis on the IR
|
|
136
|
+
ā
|
|
137
|
+
Findings sent to Groq (Llama 3.3 70B)
|
|
138
|
+
ā
|
|
139
|
+
Plain English explanation + fix
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The static analysis layer is deterministic ā it either finds a nested loop or it doesn't. No hallucination. The AI layer explains what the detectors already confirmed exists.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Roadmap
|
|
147
|
+
|
|
148
|
+
- [x] Static analysis (Python, JS, TS, Go, C, C++)
|
|
149
|
+
- [x] AI-powered explanations and fixes
|
|
150
|
+
- [x] Multi-language IR architecture
|
|
151
|
+
- [ ] Runtime profiling (Layer 3)
|
|
152
|
+
- [ ] More detectors
|
|
153
|
+
- [ ] `pip install wrench` support
|
|
154
|
+
- [ ] Web UI
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Project structure
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
wrench/
|
|
162
|
+
āāā detectors/
|
|
163
|
+
ā āāā base.py ā depth tracking, core visitor
|
|
164
|
+
ā āāā high.py ā high priority detectors
|
|
165
|
+
ā āāā medium.py ā medium priority detectors
|
|
166
|
+
āāā languages/
|
|
167
|
+
ā āāā python_rules.py ā Tree-sitter node mappings per language
|
|
168
|
+
ā āāā js_rules.py
|
|
169
|
+
ā āāā ...
|
|
170
|
+
āāā ir.py ā language-agnostic IR node
|
|
171
|
+
āāā ir_translator.py ā Tree-sitter ā IR translation
|
|
172
|
+
āāā parser_engine.py ā language detection + parser setup
|
|
173
|
+
āāā ai_engine.py ā Groq integration
|
|
174
|
+
āāā main.py ā entry point
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Contributing
|
|
180
|
+
|
|
181
|
+
Pull requests welcome. If you want to add a new language, add a rules file in `languages/` mapping Tree-sitter node types to the generic IR types. That's it ā the detectors work on all languages automatically.
|
|
182
|
+
|
|
183
|
+
Open an issue first for anything major.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
Built by [@vishaddjain]
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# š§ wrench
|
|
2
|
+
|
|
3
|
+
> Point it at your code. Get back what's slow and how to fix it.
|
|
4
|
+
|
|
5
|
+
Wrench is a multi-language performance analyser that combines static analysis with AI-powered explanations. It finds real performance issues in your code ā nested loops, inefficient patterns, bad practices ā then explains exactly why they're a problem and shows you the fix.
|
|
6
|
+
|
|
7
|
+
No cloud, no setup hell, no enterprise pricing. Just run it on a file.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## What it catches
|
|
12
|
+
|
|
13
|
+
**High priority**
|
|
14
|
+
- Nested loops (O(n²) and worse)
|
|
15
|
+
- Expensive function calls inside loops
|
|
16
|
+
- Repeated attribute access that should be cached
|
|
17
|
+
- String concatenation with `+` in loops
|
|
18
|
+
|
|
19
|
+
**Medium priority**
|
|
20
|
+
- List appends inside nested loops
|
|
21
|
+
- Unnecessary `list(range(n))` creation
|
|
22
|
+
- Bare `except:` and overly broad `except Exception`
|
|
23
|
+
- Global variable access inside loops
|
|
24
|
+
- Mutable default arguments
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## Supported languages
|
|
29
|
+
|
|
30
|
+
| Language | Extension |
|
|
31
|
+
|----------|-----------|
|
|
32
|
+
| Python | `.py` |
|
|
33
|
+
| JavaScript | `.js` |
|
|
34
|
+
| TypeScript | `.ts` |
|
|
35
|
+
| Go | `.go` |
|
|
36
|
+
| C | `.c` |
|
|
37
|
+
| C++ | `.cpp`, `.cc` |
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/yourusername/wrench.git
|
|
45
|
+
cd wrench
|
|
46
|
+
python -m venv venv
|
|
47
|
+
source venv/bin/activate # Mac/Linux
|
|
48
|
+
venv\Scripts\activate # Windows
|
|
49
|
+
pip install -r requirements.txt
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Create a `.env` file in the project root:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
GROQ_API_KEY=your_key_here
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Get a free Groq API key at [console.groq.com](https://console.groq.com)
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Usage
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
python main.py yourfile.py
|
|
66
|
+
python main.py app.js
|
|
67
|
+
python main.py main.go
|
|
68
|
+
python main.py server.cpp
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
That's it. Wrench detects the language from the file extension automatically.
|
|
72
|
+
|
|
73
|
+
### Example output
|
|
74
|
+
|
|
75
|
+
```
|
|
76
|
+
Nested loop at line 19 ā potential O(n²)
|
|
77
|
+
String concatenation at line 22 ā use ''.join() instead
|
|
78
|
+
Function call 'expensive_function' inside loop at line 25 ā consider moving it out
|
|
79
|
+
Bare except at line 40 ā catches everything including system exceptions, be specific
|
|
80
|
+
|
|
81
|
+
--- AI Analysis ---
|
|
82
|
+
|
|
83
|
+
1. Nested loop at line 19
|
|
84
|
+
Problem: Two nested loops over the same data gives you O(n²) time complexity.
|
|
85
|
+
For 1000 items that's 1,000,000 iterations instead of 1,000.
|
|
86
|
+
|
|
87
|
+
Fix:
|
|
88
|
+
# before
|
|
89
|
+
for i in items:
|
|
90
|
+
for j in items:
|
|
91
|
+
process(i, j)
|
|
92
|
+
|
|
93
|
+
# after ā use itertools or restructure with a dict lookup
|
|
94
|
+
lookup = {item: process(item) for item in items}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## How it works
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
your file
|
|
103
|
+
ā
|
|
104
|
+
Tree-sitter parses it into a syntax tree
|
|
105
|
+
ā
|
|
106
|
+
IR translator converts to language-agnostic representation
|
|
107
|
+
ā
|
|
108
|
+
Detectors run static analysis on the IR
|
|
109
|
+
ā
|
|
110
|
+
Findings sent to Groq (Llama 3.3 70B)
|
|
111
|
+
ā
|
|
112
|
+
Plain English explanation + fix
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The static analysis layer is deterministic ā it either finds a nested loop or it doesn't. No hallucination. The AI layer explains what the detectors already confirmed exists.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Roadmap
|
|
120
|
+
|
|
121
|
+
- [x] Static analysis (Python, JS, TS, Go, C, C++)
|
|
122
|
+
- [x] AI-powered explanations and fixes
|
|
123
|
+
- [x] Multi-language IR architecture
|
|
124
|
+
- [ ] Runtime profiling (Layer 3)
|
|
125
|
+
- [ ] More detectors
|
|
126
|
+
- [ ] `pip install wrench` support
|
|
127
|
+
- [ ] Web UI
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## Project structure
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
wrench/
|
|
135
|
+
āāā detectors/
|
|
136
|
+
ā āāā base.py ā depth tracking, core visitor
|
|
137
|
+
ā āāā high.py ā high priority detectors
|
|
138
|
+
ā āāā medium.py ā medium priority detectors
|
|
139
|
+
āāā languages/
|
|
140
|
+
ā āāā python_rules.py ā Tree-sitter node mappings per language
|
|
141
|
+
ā āāā js_rules.py
|
|
142
|
+
ā āāā ...
|
|
143
|
+
āāā ir.py ā language-agnostic IR node
|
|
144
|
+
āāā ir_translator.py ā Tree-sitter ā IR translation
|
|
145
|
+
āāā parser_engine.py ā language detection + parser setup
|
|
146
|
+
āāā ai_engine.py ā Groq integration
|
|
147
|
+
āāā main.py ā entry point
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## Contributing
|
|
153
|
+
|
|
154
|
+
Pull requests welcome. If you want to add a new language, add a rules file in `languages/` mapping Tree-sitter node types to the generic IR types. That's it ā the detectors work on all languages automatically.
|
|
155
|
+
|
|
156
|
+
Open an issue first for anything major.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
Built by [@vishaddjain]
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: codewrench
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A multi-language code performance analyser with static analysis and AI-powered fix generation.
|
|
5
|
+
Author-email: Vishad Jain <vishadjain2304@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/vishaddjain/wrench
|
|
8
|
+
Project-URL: Issues, https://github.com/vishaddjain/wrench/issues
|
|
9
|
+
Keywords: performance,static-analysis,code-analysis,AI,developer-tools
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
14
|
+
Classifier: Topic :: Software Development :: Testing
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
Requires-Dist: groq>=1.1.1
|
|
18
|
+
Requires-Dist: python-dotenv>=1.2.2
|
|
19
|
+
Requires-Dist: requests>=2.32.5
|
|
20
|
+
Requires-Dist: tree-sitter>=0.25.2
|
|
21
|
+
Requires-Dist: tree-sitter-python>=0.25.0
|
|
22
|
+
Requires-Dist: tree-sitter-javascript>=0.25.0
|
|
23
|
+
Requires-Dist: tree-sitter-typescript>=0.23.2
|
|
24
|
+
Requires-Dist: tree-sitter-go>=0.25.0
|
|
25
|
+
Requires-Dist: tree-sitter-c>=0.24.1
|
|
26
|
+
Requires-Dist: tree-sitter-cpp>=0.23.4
|
|
27
|
+
|
|
28
|
+
# š§ wrench
|
|
29
|
+
|
|
30
|
+
> Point it at your code. Get back what's slow and how to fix it.
|
|
31
|
+
|
|
32
|
+
Wrench is a multi-language performance analyser that combines static analysis with AI-powered explanations. It finds real performance issues in your code ā nested loops, inefficient patterns, bad practices ā then explains exactly why they're a problem and shows you the fix.
|
|
33
|
+
|
|
34
|
+
No cloud, no setup hell, no enterprise pricing. Just run it on a file.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## What it catches
|
|
39
|
+
|
|
40
|
+
**High priority**
|
|
41
|
+
- Nested loops (O(n²) and worse)
|
|
42
|
+
- Expensive function calls inside loops
|
|
43
|
+
- Repeated attribute access that should be cached
|
|
44
|
+
- String concatenation with `+` in loops
|
|
45
|
+
|
|
46
|
+
**Medium priority**
|
|
47
|
+
- List appends inside nested loops
|
|
48
|
+
- Unnecessary `list(range(n))` creation
|
|
49
|
+
- Bare `except:` and overly broad `except Exception`
|
|
50
|
+
- Global variable access inside loops
|
|
51
|
+
- Mutable default arguments
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Supported languages
|
|
56
|
+
|
|
57
|
+
| Language | Extension |
|
|
58
|
+
|----------|-----------|
|
|
59
|
+
| Python | `.py` |
|
|
60
|
+
| JavaScript | `.js` |
|
|
61
|
+
| TypeScript | `.ts` |
|
|
62
|
+
| Go | `.go` |
|
|
63
|
+
| C | `.c` |
|
|
64
|
+
| C++ | `.cpp`, `.cc` |
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
git clone https://github.com/yourusername/wrench.git
|
|
72
|
+
cd wrench
|
|
73
|
+
python -m venv venv
|
|
74
|
+
source venv/bin/activate # Mac/Linux
|
|
75
|
+
venv\Scripts\activate # Windows
|
|
76
|
+
pip install -r requirements.txt
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Create a `.env` file in the project root:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
GROQ_API_KEY=your_key_here
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Get a free Groq API key at [console.groq.com](https://console.groq.com)
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
## Usage
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
python main.py yourfile.py
|
|
93
|
+
python main.py app.js
|
|
94
|
+
python main.py main.go
|
|
95
|
+
python main.py server.cpp
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
That's it. Wrench detects the language from the file extension automatically.
|
|
99
|
+
|
|
100
|
+
### Example output
|
|
101
|
+
|
|
102
|
+
```
|
|
103
|
+
Nested loop at line 19 ā potential O(n²)
|
|
104
|
+
String concatenation at line 22 ā use ''.join() instead
|
|
105
|
+
Function call 'expensive_function' inside loop at line 25 ā consider moving it out
|
|
106
|
+
Bare except at line 40 ā catches everything including system exceptions, be specific
|
|
107
|
+
|
|
108
|
+
--- AI Analysis ---
|
|
109
|
+
|
|
110
|
+
1. Nested loop at line 19
|
|
111
|
+
Problem: Two nested loops over the same data gives you O(n²) time complexity.
|
|
112
|
+
For 1000 items that's 1,000,000 iterations instead of 1,000.
|
|
113
|
+
|
|
114
|
+
Fix:
|
|
115
|
+
# before
|
|
116
|
+
for i in items:
|
|
117
|
+
for j in items:
|
|
118
|
+
process(i, j)
|
|
119
|
+
|
|
120
|
+
# after ā use itertools or restructure with a dict lookup
|
|
121
|
+
lookup = {item: process(item) for item in items}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## How it works
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
your file
|
|
130
|
+
ā
|
|
131
|
+
Tree-sitter parses it into a syntax tree
|
|
132
|
+
ā
|
|
133
|
+
IR translator converts to language-agnostic representation
|
|
134
|
+
ā
|
|
135
|
+
Detectors run static analysis on the IR
|
|
136
|
+
ā
|
|
137
|
+
Findings sent to Groq (Llama 3.3 70B)
|
|
138
|
+
ā
|
|
139
|
+
Plain English explanation + fix
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The static analysis layer is deterministic ā it either finds a nested loop or it doesn't. No hallucination. The AI layer explains what the detectors already confirmed exists.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Roadmap
|
|
147
|
+
|
|
148
|
+
- [x] Static analysis (Python, JS, TS, Go, C, C++)
|
|
149
|
+
- [x] AI-powered explanations and fixes
|
|
150
|
+
- [x] Multi-language IR architecture
|
|
151
|
+
- [ ] Runtime profiling (Layer 3)
|
|
152
|
+
- [ ] More detectors
|
|
153
|
+
- [ ] `pip install wrench` support
|
|
154
|
+
- [ ] Web UI
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Project structure
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
wrench/
|
|
162
|
+
āāā detectors/
|
|
163
|
+
ā āāā base.py ā depth tracking, core visitor
|
|
164
|
+
ā āāā high.py ā high priority detectors
|
|
165
|
+
ā āāā medium.py ā medium priority detectors
|
|
166
|
+
āāā languages/
|
|
167
|
+
ā āāā python_rules.py ā Tree-sitter node mappings per language
|
|
168
|
+
ā āāā js_rules.py
|
|
169
|
+
ā āāā ...
|
|
170
|
+
āāā ir.py ā language-agnostic IR node
|
|
171
|
+
āāā ir_translator.py ā Tree-sitter ā IR translation
|
|
172
|
+
āāā parser_engine.py ā language detection + parser setup
|
|
173
|
+
āāā ai_engine.py ā Groq integration
|
|
174
|
+
āāā main.py ā entry point
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Contributing
|
|
180
|
+
|
|
181
|
+
Pull requests welcome. If you want to add a new language, add a rules file in `languages/` mapping Tree-sitter node types to the generic IR types. That's it ā the detectors work on all languages automatically.
|
|
182
|
+
|
|
183
|
+
Open an issue first for anything major.
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
Built by [@vishaddjain]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
codewrench.egg-info/PKG-INFO
|
|
4
|
+
codewrench.egg-info/SOURCES.txt
|
|
5
|
+
codewrench.egg-info/dependency_links.txt
|
|
6
|
+
codewrench.egg-info/entry_points.txt
|
|
7
|
+
codewrench.egg-info/requires.txt
|
|
8
|
+
codewrench.egg-info/top_level.txt
|
|
9
|
+
wrench/ai_engine.py
|
|
10
|
+
wrench/code.py
|
|
11
|
+
wrench/errors.py
|
|
12
|
+
wrench/ir.py
|
|
13
|
+
wrench/ir_translator.py
|
|
14
|
+
wrench/main.py
|
|
15
|
+
wrench/parser_engine.py
|
|
16
|
+
wrench/reports.py
|
|
17
|
+
wrench/wrenchignore.py
|
|
18
|
+
wrench/detectors/__init__.py
|
|
19
|
+
wrench/detectors/base.py
|
|
20
|
+
wrench/detectors/high.py
|
|
21
|
+
wrench/detectors/medium.py
|
|
22
|
+
wrench/languages/__init__.py
|
|
23
|
+
wrench/languages/c_rules.py
|
|
24
|
+
wrench/languages/cpp_rules.py
|
|
25
|
+
wrench/languages/go_rules.py
|
|
26
|
+
wrench/languages/javascript_rules.py
|
|
27
|
+
wrench/languages/python_rules.py
|
|
28
|
+
wrench/languages/typescript_rules.py
|
|
29
|
+
wrench/profilers/__init__.py
|
|
30
|
+
wrench/profilers/profiler.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "codewrench"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A multi-language code performance analyser with static analysis and AI-powered fix generation."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "Vishad Jain", email = "vishadjain2304@gmail.com" }
|
|
13
|
+
]
|
|
14
|
+
requires-python = ">=3.10"
|
|
15
|
+
keywords = ["performance", "static-analysis", "code-analysis", "AI", "developer-tools"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Topic :: Software Development :: Quality Assurance",
|
|
21
|
+
"Topic :: Software Development :: Testing",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"groq>=1.1.1",
|
|
25
|
+
"python-dotenv>=1.2.2",
|
|
26
|
+
"requests>=2.32.5",
|
|
27
|
+
"tree-sitter>=0.25.2",
|
|
28
|
+
"tree-sitter-python>=0.25.0",
|
|
29
|
+
"tree-sitter-javascript>=0.25.0",
|
|
30
|
+
"tree-sitter-typescript>=0.23.2",
|
|
31
|
+
"tree-sitter-go>=0.25.0",
|
|
32
|
+
"tree-sitter-c>=0.24.1",
|
|
33
|
+
"tree-sitter-cpp>=0.23.4",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
codewrench = "main:main"
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://github.com/vishaddjain/wrench"
|
|
41
|
+
Issues = "https://github.com/vishaddjain/wrench/issues"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["."]
|