code2llm 0.3.7__py3-none-any.whl
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.
- code2flow/__init__.py +47 -0
- code2flow/__main__.py +6 -0
- code2flow/analysis/__init__.py +23 -0
- code2flow/analysis/call_graph.py +210 -0
- code2flow/analysis/cfg.py +293 -0
- code2flow/analysis/coupling.py +77 -0
- code2flow/analysis/data_analysis.py +249 -0
- code2flow/analysis/dfg.py +224 -0
- code2flow/analysis/pipeline_detector.py +445 -0
- code2flow/analysis/side_effects.py +313 -0
- code2flow/analysis/smells.py +192 -0
- code2flow/analysis/type_inference.py +306 -0
- code2flow/cli.py +493 -0
- code2flow/core/__init__.py +36 -0
- code2flow/core/analyzer.py +765 -0
- code2flow/core/config.py +177 -0
- code2flow/core/models.py +194 -0
- code2flow/core/streaming_analyzer.py +666 -0
- code2flow/exporters/__init__.py +35 -0
- code2flow/exporters/base.py +13 -0
- code2flow/exporters/context_exporter.py +207 -0
- code2flow/exporters/flow_exporter.py +570 -0
- code2flow/exporters/json_exporter.py +17 -0
- code2flow/exporters/llm_exporter.py +12 -0
- code2flow/exporters/map_exporter.py +218 -0
- code2flow/exporters/mermaid_exporter.py +67 -0
- code2flow/exporters/toon.py +982 -0
- code2flow/exporters/yaml_exporter.py +108 -0
- code2flow/llm_flow_generator.py +451 -0
- code2flow/llm_task_generator.py +263 -0
- code2flow/mermaid_generator.py +481 -0
- code2flow/nlp/__init__.py +23 -0
- code2flow/nlp/config.py +174 -0
- code2flow/nlp/entity_resolution.py +326 -0
- code2flow/nlp/intent_matching.py +297 -0
- code2flow/nlp/normalization.py +122 -0
- code2flow/nlp/pipeline.py +388 -0
- code2flow/patterns/__init__.py +0 -0
- code2flow/patterns/detector.py +168 -0
- code2flow/refactor/__init__.py +0 -0
- code2flow/refactor/prompt_engine.py +150 -0
- code2flow/visualizers/__init__.py +0 -0
- code2flow/visualizers/graph.py +196 -0
- code2llm-0.3.7.dist-info/METADATA +604 -0
- code2llm-0.3.7.dist-info/RECORD +49 -0
- code2llm-0.3.7.dist-info/WHEEL +5 -0
- code2llm-0.3.7.dist-info/entry_points.txt +2 -0
- code2llm-0.3.7.dist-info/licenses/LICENSE +201 -0
- code2llm-0.3.7.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: code2llm
|
|
3
|
+
Version: 0.3.7
|
|
4
|
+
Summary: High-performance Python code flow analysis with optimized TOON format - CFG, DFG, call graphs, and intelligent code queries
|
|
5
|
+
Home-page: https://github.com/wronai/stts
|
|
6
|
+
Author: STTS Project
|
|
7
|
+
Author-email: Tom Sapletta <tom@sapletta.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Project-URL: Homepage, https://github.com/wronai/stts
|
|
10
|
+
Project-URL: Repository, https://github.com/wronai/stts
|
|
11
|
+
Project-URL: Issues, https://github.com/wronai/stts/issues
|
|
12
|
+
Keywords: static-analysis,control-flow,data-flow,call-graph,reverse-engineering,toon-format,code-analysis,ast,optimization,complexity-analysis
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
24
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
25
|
+
Requires-Python: >=3.8
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
Requires-Dist: networkx>=2.6
|
|
29
|
+
Requires-Dist: matplotlib>=3.4
|
|
30
|
+
Requires-Dist: pyyaml>=5.4
|
|
31
|
+
Requires-Dist: numpy>=1.20
|
|
32
|
+
Requires-Dist: jinja2>=3.0
|
|
33
|
+
Requires-Dist: radon>=5.1
|
|
34
|
+
Requires-Dist: astroid>=3.0
|
|
35
|
+
Requires-Dist: vulture>=2.10
|
|
36
|
+
Requires-Dist: tiktoken>=0.5
|
|
37
|
+
Requires-Dist: tree-sitter>=0.21
|
|
38
|
+
Requires-Dist: tree-sitter-python>=0.21
|
|
39
|
+
Provides-Extra: dev
|
|
40
|
+
Requires-Dist: pytest>=6.2; extra == "dev"
|
|
41
|
+
Requires-Dist: pytest-cov>=2.12; extra == "dev"
|
|
42
|
+
Requires-Dist: black>=21.0; extra == "dev"
|
|
43
|
+
Requires-Dist: flake8>=3.9; extra == "dev"
|
|
44
|
+
Requires-Dist: mypy>=0.910; extra == "dev"
|
|
45
|
+
Dynamic: author
|
|
46
|
+
Dynamic: home-page
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
Dynamic: requires-python
|
|
49
|
+
|
|
50
|
+
# code2flow
|
|
51
|
+
|
|
52
|
+
**Python Code Flow Analysis Tool** - Static analysis for control flow graphs (CFG), data flow graphs (DFG), and call graph extraction with optimized TOON format.
|
|
53
|
+
|
|
54
|
+

|
|
55
|
+
|
|
56
|
+
## 🚀 New: TOON Format v2
|
|
57
|
+
|
|
58
|
+
**TOON v2** is the default output format - scannable, severity-sorted, prompt-ready:
|
|
59
|
+
|
|
60
|
+
- **🎯 Health-first design** - issues sorted by severity (🔴/🟡)
|
|
61
|
+
- **📊 Coupling matrix** - fan-in/fan-out analysis
|
|
62
|
+
- **🔍 Duplicate detection** - find identical classes
|
|
63
|
+
- **📈 Layered architecture** - package-level metrics
|
|
64
|
+
- **⚡ Inline markers** - `!!` (CC≥15), `!` (CC≥10), `×DUP`
|
|
65
|
+
- **🚫 Smart filtering** - excludes venv, site-packages
|
|
66
|
+
- **📋 Actionable REFACTOR** - concrete steps, not just problems
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Default: TOON format only
|
|
70
|
+
code2flow /path/to/project
|
|
71
|
+
|
|
72
|
+
# Generate all formats
|
|
73
|
+
code2flow /path/to/project -f all
|
|
74
|
+
|
|
75
|
+
# TOON + YAML (for comparison)
|
|
76
|
+
code2flow /path/to/project -f toon,yaml
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Performance Optimization
|
|
80
|
+
|
|
81
|
+
For large projects (>1000 functions), use **Fast Mode**:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Ultra-fast analysis (5-10x faster)
|
|
85
|
+
code2flow /path/to/project --fast
|
|
86
|
+
|
|
87
|
+
# Custom performance settings
|
|
88
|
+
code2flow /path/to/project \
|
|
89
|
+
--parallel-workers 8 \
|
|
90
|
+
--max-depth 3 \
|
|
91
|
+
--skip-data-flow \
|
|
92
|
+
--cache-dir ./.cache
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Performance Tips
|
|
96
|
+
|
|
97
|
+
| Technique | Speedup | Use Case |
|
|
98
|
+
|-----------|---------|----------|
|
|
99
|
+
| `--fast` mode | 5-10x | Initial exploration |
|
|
100
|
+
| Parallel workers | 2-4x | Multi-core machines |
|
|
101
|
+
| Caching | 3-5x | Repeated analysis |
|
|
102
|
+
| Depth limiting | 2-3x | Large codebases |
|
|
103
|
+
| Skip private methods | 1.5-2x | Public API analysis |
|
|
104
|
+
|
|
105
|
+
### Benchmarks
|
|
106
|
+
|
|
107
|
+
| Project Size | Functions | Time (fast) | Time (full) |
|
|
108
|
+
|--------------|-----------|-------------|-------------|
|
|
109
|
+
| Small (<100) | ~50 | 0.5s | 2s |
|
|
110
|
+
| Medium (1K) | ~500 | 3s | 15s |
|
|
111
|
+
| Large (10K) | ~2000 | 15s | 120s |
|
|
112
|
+
|
|
113
|
+
## Features
|
|
114
|
+
|
|
115
|
+
- **🎯 TOON Format**: Optimized compact output (default)
|
|
116
|
+
- **Control Flow Graph (CFG)**: Extract execution paths from Python AST
|
|
117
|
+
- **Data Flow Graph (DFG)**: Track variable definitions and dependencies
|
|
118
|
+
- **Call Graph Analysis**: Map function calls and dependencies
|
|
119
|
+
- **Pattern Detection**: Identify design patterns and code smells
|
|
120
|
+
- **Multiple Output Formats**: TOON, YAML, JSON, Mermaid diagrams, PNG visualizations
|
|
121
|
+
- **LLM-Ready Output**: Generate prompts for reverse engineering
|
|
122
|
+
- **Smart Validation**: Built-in format validation and testing
|
|
123
|
+
|
|
124
|
+
## Installation
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Install from source
|
|
128
|
+
pip install -e .
|
|
129
|
+
|
|
130
|
+
# Or with development dependencies
|
|
131
|
+
pip install -e ".[dev]"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Quick Start
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Analyze a Python project (default: TOON format)
|
|
138
|
+
code2flow /path/to/project
|
|
139
|
+
|
|
140
|
+
# With verbose output
|
|
141
|
+
code2flow /path/to/project -v
|
|
142
|
+
|
|
143
|
+
# Generate all formats
|
|
144
|
+
code2flow /path/to/project -f all
|
|
145
|
+
|
|
146
|
+
# Use different analysis modes
|
|
147
|
+
code2flow /path/to/project -m static # Fast static analysis only
|
|
148
|
+
code2flow /path/to/project -m hybrid # Combined analysis (default)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Usage
|
|
152
|
+
|
|
153
|
+
### Output Formats
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# Default: TOON format only
|
|
157
|
+
code2flow /path/to/project
|
|
158
|
+
|
|
159
|
+
# All formats (toon,yaml,json,mermaid,png)
|
|
160
|
+
code2flow /path/to/project -f all
|
|
161
|
+
|
|
162
|
+
# Custom combinations
|
|
163
|
+
code2flow /path/to/project -f toon,yaml
|
|
164
|
+
code2flow /path/to/project -f json,png
|
|
165
|
+
code2flow /path/to/project -f mermaid,png
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Analysis Modes
|
|
169
|
+
|
|
170
|
+
```bash
|
|
171
|
+
# Static analysis only (fastest)
|
|
172
|
+
code2flow /path/to/project -m static
|
|
173
|
+
|
|
174
|
+
# Dynamic analysis with tracing
|
|
175
|
+
code2flow /path/to/project -m dynamic
|
|
176
|
+
|
|
177
|
+
# Hybrid analysis (recommended)
|
|
178
|
+
code2flow /path/to/project -m hybrid
|
|
179
|
+
|
|
180
|
+
# Behavioral pattern focus
|
|
181
|
+
code2flow /path/to/project -m behavioral
|
|
182
|
+
|
|
183
|
+
# Reverse engineering ready
|
|
184
|
+
code2flow /path/to/project -m reverse
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Custom Output
|
|
188
|
+
|
|
189
|
+
```bash
|
|
190
|
+
code2flow /path/to/project -o my_analysis
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Output Files
|
|
194
|
+
|
|
195
|
+
| File | Description | Size |
|
|
196
|
+
|------|-------------|------|
|
|
197
|
+
| `analysis.toon` | **🎯 Optimized TOON format** (default) | ~200KB |
|
|
198
|
+
| `analysis.yaml` | Complete structured analysis data | ~2.5MB |
|
|
199
|
+
| `analysis.json` | JSON format for programmatic use | ~2.6MB |
|
|
200
|
+
| `flow.mmd` | Full Mermaid flowchart (all nodes) | ~9KB |
|
|
201
|
+
| `compact_flow.mmd` | Compact flowchart - deduplicated nodes | ~9KB |
|
|
202
|
+
| `calls.mmd` | Function call graph | ~9KB |
|
|
203
|
+
| `cfg.png` | Control flow visualization | ~7MB |
|
|
204
|
+
| `call_graph.png` | Call graph visualization | ~3.7MB |
|
|
205
|
+
| `llm_prompt.md` | LLM-ready analysis summary | ~35KB |
|
|
206
|
+
|
|
207
|
+
## 🎯 TOON v2 Format Structure
|
|
208
|
+
|
|
209
|
+
The TOON v2 format is designed for rapid scanning and actionable insights:
|
|
210
|
+
|
|
211
|
+
```
|
|
212
|
+
# code2flow | 43f 10693L | py:43 | 2026-02-28
|
|
213
|
+
# CC̄=4.6 | critical:39/406 | dups:0 | cycles:0
|
|
214
|
+
|
|
215
|
+
HEALTH[20]:
|
|
216
|
+
🔴 GOD code2flow/core/analyzer.py = 765L, 4 classes, 30m, max CC=20
|
|
217
|
+
🟡 CC validate_mermaid_file CC=42 (limit:15)
|
|
218
|
+
|
|
219
|
+
REFACTOR[4]:
|
|
220
|
+
1. split code2flow/core/analyzer.py (god module)
|
|
221
|
+
2. split 17 high-CC methods (CC>15)
|
|
222
|
+
|
|
223
|
+
COUPLING:
|
|
224
|
+
┌─────────────┬──────────────────────────────────────┐
|
|
225
|
+
│ Package │ fan-in fan-out status │
|
|
226
|
+
├─────────────┼──────────────────────────────────────┤
|
|
227
|
+
│ core │ 12 45 !! split needed │
|
|
228
|
+
│ exporters │ 5 28 hub │
|
|
229
|
+
└─────────────┴──────────────────────────────────────┘
|
|
230
|
+
|
|
231
|
+
LAYERS:
|
|
232
|
+
code2flow/ CC̄=5.0 ←in:0 →out:0
|
|
233
|
+
│ !! toon 982L 1C 29m CC=31
|
|
234
|
+
│ !! analyzer 765L 4C 30m CC=20
|
|
235
|
+
|
|
236
|
+
FUNCTIONS (CC≥10, 39 of 406):
|
|
237
|
+
56.0 main 19n 4exit cond+ret !! split
|
|
238
|
+
42.0 validate_mermaid_file 6n 3exit cond+ret !! split
|
|
239
|
+
|
|
240
|
+
HOTSPOTS:
|
|
241
|
+
#1 main fan=45 "calls 45 functions"
|
|
242
|
+
#2 analyze_project fan=18 "analysis pipeline, 18 stages"
|
|
243
|
+
|
|
244
|
+
CLASSES:
|
|
245
|
+
ToonExporter ████████████████████████ 29m CC̄=9.5 max=31 !!
|
|
246
|
+
DataAnalyzer ██████████ 13m CC̄=9.9 max=17 !!
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
### Complexity Tiers
|
|
250
|
+
|
|
251
|
+
- **🔴 Critical** (≥5.0): Immediate refactoring needed
|
|
252
|
+
- **🟠 High** (≥3.0): Consider refactoring
|
|
253
|
+
- **🟡 Medium** (≥1.5): Monitor complexity
|
|
254
|
+
- **🟢 Low** (>0): Acceptable complexity
|
|
255
|
+
- **⚪ Basic** (0): Simple functions
|
|
256
|
+
|
|
257
|
+
## Validation & Testing
|
|
258
|
+
|
|
259
|
+
Built-in validation ensures output quality:
|
|
260
|
+
|
|
261
|
+
```bash
|
|
262
|
+
# Validate TOON format
|
|
263
|
+
python validate_toon.py analysis.toon
|
|
264
|
+
|
|
265
|
+
# Compare TOON vs YAML
|
|
266
|
+
python validate_toon.py analysis.yaml analysis.toon
|
|
267
|
+
|
|
268
|
+
# Run comprehensive tests
|
|
269
|
+
bash project.sh
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Test Results
|
|
273
|
+
|
|
274
|
+
- **✅ Functions**: 100% data consistency (443/443)
|
|
275
|
+
- **✅ Statistics**: Perfect correlation
|
|
276
|
+
- **✅ Structure**: All required sections present
|
|
277
|
+
- **✅ Insights**: Actionable recommendations generated
|
|
278
|
+
|
|
279
|
+
## Understanding the Output
|
|
280
|
+
|
|
281
|
+
### LLM Prompt Structure
|
|
282
|
+
The generated prompt includes:
|
|
283
|
+
- System overview with metrics
|
|
284
|
+
- Call graph structure
|
|
285
|
+
- Behavioral patterns with confidence scores
|
|
286
|
+
- Data flow insights
|
|
287
|
+
- State machine definitions
|
|
288
|
+
- Reverse engineering guidelines
|
|
289
|
+
|
|
290
|
+
### Behavioral Patterns
|
|
291
|
+
Each pattern includes:
|
|
292
|
+
- **Name**: Descriptive identifier
|
|
293
|
+
- **Type**: sequential, conditional, iterative, recursive, state_machine
|
|
294
|
+
- **Entry/Exit points**: Key functions
|
|
295
|
+
- **Decision points**: Conditional logic locations
|
|
296
|
+
- **Data transformations**: Variable dependencies
|
|
297
|
+
- **Confidence**: Pattern detection certainty
|
|
298
|
+
|
|
299
|
+
### Reverse Engineering Guidelines
|
|
300
|
+
The analysis provides specific guidance for:
|
|
301
|
+
1. Preserving call graph structure
|
|
302
|
+
2. Implementing identified patterns
|
|
303
|
+
3. Maintaining data dependencies
|
|
304
|
+
4. Recreating state machines
|
|
305
|
+
5. Preserving decision logic
|
|
306
|
+
|
|
307
|
+
## Advanced Features
|
|
308
|
+
|
|
309
|
+
### State Machine Detection
|
|
310
|
+
Automatically identifies:
|
|
311
|
+
- State variables
|
|
312
|
+
- Transition methods
|
|
313
|
+
- Source and destination states
|
|
314
|
+
- State machine hierarchy
|
|
315
|
+
|
|
316
|
+
### Data Flow Tracking
|
|
317
|
+
Maps:
|
|
318
|
+
- Variable dependencies
|
|
319
|
+
- Data transformations
|
|
320
|
+
- Information flow paths
|
|
321
|
+
- Side effects
|
|
322
|
+
|
|
323
|
+
### Dynamic Tracing
|
|
324
|
+
When using dynamic mode:
|
|
325
|
+
- Function entry/exit timing
|
|
326
|
+
- Call stack reconstruction
|
|
327
|
+
- Exception tracking
|
|
328
|
+
- Performance profiling
|
|
329
|
+
|
|
330
|
+
## Integration with LLMs
|
|
331
|
+
|
|
332
|
+
The generated `llm_prompt.md` is designed to be:
|
|
333
|
+
- **Comprehensive**: Contains all necessary system information
|
|
334
|
+
- **Structured**: Organized for easy parsing
|
|
335
|
+
- **Actionable**: Includes specific implementation guidance
|
|
336
|
+
- **Language-agnostic**: Describes behavior, not implementation
|
|
337
|
+
|
|
338
|
+
Example usage with an LLM:
|
|
339
|
+
```
|
|
340
|
+
"Based on the TOON analysis provided, implement this system in Go,
|
|
341
|
+
preserving all behavioral patterns and data flow characteristics."
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
## Format Comparison
|
|
345
|
+
|
|
346
|
+
| Feature | TOON | YAML | JSON |
|
|
347
|
+
|---------|------|------|------|
|
|
348
|
+
| **Size** | 🎯 200KB | 2.5MB | 2.6MB |
|
|
349
|
+
| **Readability** | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐ |
|
|
350
|
+
| **Processing Speed** | ⚡ Fast | 🐌 Slow | 🐌 Slow |
|
|
351
|
+
| **Human-Friendly** | ✅ Yes | ❌ No | ❌ No |
|
|
352
|
+
| **Machine-Readable** | ✅ Yes | ✅ Yes | ✅ Yes |
|
|
353
|
+
| **Insights** | ✅ Built-in | ❌ No | ❌ No |
|
|
354
|
+
|
|
355
|
+
## Limitations
|
|
356
|
+
|
|
357
|
+
- Dynamic analysis requires test files
|
|
358
|
+
- Complex inheritance hierarchies may need manual review
|
|
359
|
+
- External library calls are treated as black boxes
|
|
360
|
+
- Runtime reflection and metaprogramming not fully captured
|
|
361
|
+
|
|
362
|
+
## Contributing
|
|
363
|
+
|
|
364
|
+
The analyzer is designed to be extensible. Key areas for enhancement:
|
|
365
|
+
- Additional pattern types
|
|
366
|
+
- Language-specific optimizations
|
|
367
|
+
- Improved visualization
|
|
368
|
+
- Real-time analysis mode
|
|
369
|
+
- TOON format enhancements
|
|
370
|
+
|
|
371
|
+
## 🎯 Quick Reference
|
|
372
|
+
|
|
373
|
+
| Command | Output | Use Case |
|
|
374
|
+
|---------|--------|----------|
|
|
375
|
+
| `code2flow ./project` | `analysis.toon` | Quick analysis (default) |
|
|
376
|
+
| `code2flow ./project -f all` | All formats | Complete analysis |
|
|
377
|
+
| `code2flow ./project -f toon,yaml` | TOON + YAML | Comparison |
|
|
378
|
+
| `code2flow ./project -m hybrid -v` | TOON + verbose | Detailed analysis |
|
|
379
|
+
| `python validate_toon.py analysis.toon` | Validation | Quality check |
|
|
380
|
+
|
|
381
|
+
## 🔧 Advanced Usage
|
|
382
|
+
|
|
383
|
+
### Custom Analysis Configuration
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
# Deep analysis with all insights
|
|
387
|
+
code2flow ./project \
|
|
388
|
+
-m hybrid \
|
|
389
|
+
-f toon \
|
|
390
|
+
--max-depth 15 \
|
|
391
|
+
--full \
|
|
392
|
+
-v
|
|
393
|
+
|
|
394
|
+
# Performance-optimized for large projects
|
|
395
|
+
code2flow ./project \
|
|
396
|
+
-m static \
|
|
397
|
+
-f toon \
|
|
398
|
+
--strategy quick \
|
|
399
|
+
--max-memory 500
|
|
400
|
+
|
|
401
|
+
# Refactoring-focused analysis
|
|
402
|
+
code2flow ./project \
|
|
403
|
+
-m behavioral \
|
|
404
|
+
-f toon \
|
|
405
|
+
--refactor \
|
|
406
|
+
--smell god_function
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
### Integration Examples
|
|
410
|
+
|
|
411
|
+
#### CI/CD Pipeline
|
|
412
|
+
```bash
|
|
413
|
+
#!/bin/bash
|
|
414
|
+
# Analyze code quality in CI
|
|
415
|
+
code2flow ./src -f toon -o ./analysis
|
|
416
|
+
python validate_toon.py ./analysis/analysis.toon
|
|
417
|
+
if [ $? -eq 0 ]; then
|
|
418
|
+
echo "✅ Code analysis passed"
|
|
419
|
+
else
|
|
420
|
+
echo "❌ Code analysis failed"
|
|
421
|
+
exit 1
|
|
422
|
+
fi
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
#### Pre-commit Hook
|
|
426
|
+
```bash
|
|
427
|
+
#!/bin/sh
|
|
428
|
+
# .git/hooks/pre-commit
|
|
429
|
+
code2flow ./ -f toon -o ./temp_analysis
|
|
430
|
+
python validate_toon.py ./temp_analysis/analysis.toon
|
|
431
|
+
rm -rf ./temp_analysis
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## 📊 Real-World Examples
|
|
435
|
+
|
|
436
|
+
### Microservice Analysis
|
|
437
|
+
```bash
|
|
438
|
+
# Analyze microservice complexity
|
|
439
|
+
code2flow ./microservice -f toon -o ./service_analysis
|
|
440
|
+
# Results: 15 critical functions, 3 modules need refactoring
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### Legacy Code Migration
|
|
444
|
+
```bash
|
|
445
|
+
# Prepare for legacy system migration
|
|
446
|
+
code2flow ./legacy -f toon,yaml -o ./migration_analysis
|
|
447
|
+
# Use TOON for quick overview, YAML for detailed migration planning
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Code Review Enhancement
|
|
451
|
+
```bash
|
|
452
|
+
# Generate insights for code review
|
|
453
|
+
code2flow ./feature-branch -f toon --refactor -o ./review
|
|
454
|
+
# Focus on critical functions and code smells
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
## 🚀 Migration Guide
|
|
458
|
+
|
|
459
|
+
### From YAML to TOON
|
|
460
|
+
|
|
461
|
+
**Before:**
|
|
462
|
+
```bash
|
|
463
|
+
code2flow ./project -f yaml -o ./analysis
|
|
464
|
+
# Output: analysis.yaml (2.5MB)
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
**After:**
|
|
468
|
+
```bash
|
|
469
|
+
code2flow ./project -f toon -o ./analysis
|
|
470
|
+
# Output: analysis.toon (204KB)
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
**Benefits:**
|
|
474
|
+
- 10x smaller files
|
|
475
|
+
- Faster processing
|
|
476
|
+
- Built-in insights
|
|
477
|
+
- Automatic recommendations
|
|
478
|
+
|
|
479
|
+
### Backward Compatibility
|
|
480
|
+
|
|
481
|
+
```bash
|
|
482
|
+
# Still generate YAML if needed
|
|
483
|
+
code2flow ./project -f toon,yaml
|
|
484
|
+
# Both formats available for comparison
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
## 📋 TOON Format Specification
|
|
488
|
+
|
|
489
|
+
### File Structure
|
|
490
|
+
```
|
|
491
|
+
analysis.toon
|
|
492
|
+
├── meta # Metadata (project, mode, timestamp)
|
|
493
|
+
├── stats # Analysis statistics
|
|
494
|
+
├── functions # Function analysis with complexity
|
|
495
|
+
├── classes # Class information from function grouping
|
|
496
|
+
├── modules # Module-level statistics
|
|
497
|
+
├── patterns # Detected design patterns
|
|
498
|
+
├── call_graph # Top 50 most important functions
|
|
499
|
+
└── insights # Recommendations and summaries
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
### Complexity Scoring
|
|
503
|
+
|
|
504
|
+
| Factor | Weight | Example |
|
|
505
|
+
|--------|--------|---------|
|
|
506
|
+
| Loops (FOR/WHILE) | 2.0 | `for i in range(10):` |
|
|
507
|
+
| Conditions (IF) | 1.0 | `if condition:` |
|
|
508
|
+
| Method calls | 1.0 | `obj.method()` |
|
|
509
|
+
| Size (>10 nodes) | 1.0 | Large functions |
|
|
510
|
+
| Returns/Assignments | 0.5 | `return value`, `x = 1` |
|
|
511
|
+
|
|
512
|
+
### Tier Classification
|
|
513
|
+
|
|
514
|
+
- **Critical (≥5.0)**: Immediate refactoring required
|
|
515
|
+
- **High (3.0-4.9)**: Consider refactoring
|
|
516
|
+
- **Medium (1.5-2.9)**: Monitor complexity
|
|
517
|
+
- **Low (0.1-1.4)**: Acceptable
|
|
518
|
+
- **Basic (0.0)**: Simple functions
|
|
519
|
+
|
|
520
|
+
## 🔍 Troubleshooting
|
|
521
|
+
|
|
522
|
+
### Common Issues
|
|
523
|
+
|
|
524
|
+
**Issue:** `analysis.toon not found`
|
|
525
|
+
```bash
|
|
526
|
+
# Solution: Check output directory
|
|
527
|
+
ls -la ./output/
|
|
528
|
+
# Should contain analysis.toon file
|
|
529
|
+
```
|
|
530
|
+
|
|
531
|
+
**Issue:** Validation fails
|
|
532
|
+
```bash
|
|
533
|
+
# Solution: Run with verbose output
|
|
534
|
+
code2flow ./project -f toon -v
|
|
535
|
+
# Check for any errors during analysis
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
**Issue:** Large file sizes
|
|
539
|
+
```bash
|
|
540
|
+
# Solution: Use TOON format instead of YAML
|
|
541
|
+
code2flow ./project -f toon # 200KB vs 2.5MB
|
|
542
|
+
```
|
|
543
|
+
|
|
544
|
+
### Performance Issues
|
|
545
|
+
|
|
546
|
+
**Memory Usage:**
|
|
547
|
+
```bash
|
|
548
|
+
# Limit memory for large projects
|
|
549
|
+
code2flow ./large-project --max-memory 500 -f toon
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
**Slow Analysis:**
|
|
553
|
+
```bash
|
|
554
|
+
# Use fast mode for initial exploration
|
|
555
|
+
code2flow ./project -m static -f toon --strategy quick
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
## 🤝 Contributing to TOON Format
|
|
559
|
+
|
|
560
|
+
The TOON format is designed to be extensible. Areas for contribution:
|
|
561
|
+
|
|
562
|
+
- **New complexity metrics**
|
|
563
|
+
- **Additional pattern detection**
|
|
564
|
+
- **Enhanced recommendations**
|
|
565
|
+
- **Visualization improvements**
|
|
566
|
+
- **Integration with other tools**
|
|
567
|
+
|
|
568
|
+
### Development Setup
|
|
569
|
+
|
|
570
|
+
```bash
|
|
571
|
+
# Clone and setup development environment
|
|
572
|
+
git clone https://github.com/tom-sapletta/code2flow.git
|
|
573
|
+
cd code2flow
|
|
574
|
+
pip install -e ".[dev]"
|
|
575
|
+
|
|
576
|
+
# Run tests
|
|
577
|
+
bash project.sh
|
|
578
|
+
|
|
579
|
+
# Validate TOON format
|
|
580
|
+
python validate_toon.py output/analysis.toon
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
## 📚 Additional Resources
|
|
584
|
+
|
|
585
|
+
- [TOON Format Validation](validate_toon.py) - Built-in validation tool
|
|
586
|
+
- [Project Testing Script](project.sh) - Comprehensive test suite
|
|
587
|
+
- [CLI Reference](code2flow/cli.py) - Complete command-line interface
|
|
588
|
+
- [Exporter Implementation](code2flow/exporters/base.py) - TOON format implementation
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
**Ready to analyze your code?** Start with the optimized TOON format:
|
|
593
|
+
|
|
594
|
+
```bash
|
|
595
|
+
code2flow ./your-project -f toon
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
## License
|
|
599
|
+
|
|
600
|
+
Apache License 2.0 - see [LICENSE](LICENSE) for details.
|
|
601
|
+
|
|
602
|
+
## Author
|
|
603
|
+
|
|
604
|
+
Created by **Tom Sapletta** - [tom@sapletta.com](mailto:tom@sapletta.com)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
code2flow/__init__.py,sha256=G4QqchxKBOqnUh-n7sIc9-XviORWlu7l0AUlM7LQrqs,1068
|
|
2
|
+
code2flow/__main__.py,sha256=uhNwQhN-MYxasOaS-ETTFjd45y50DFwTEN6qW_x3Pjw,115
|
|
3
|
+
code2flow/cli.py,sha256=iZMtvGbzx8U-wKORLELVBR57sbG-jQhywfkK2aIMygo,17648
|
|
4
|
+
code2flow/llm_flow_generator.py,sha256=EfrIFgEWvoQ4D3pgmmlgbFbsjgrXzr3rGRQ-9hnUODI,13177
|
|
5
|
+
code2flow/llm_task_generator.py,sha256=47wc-PO_ZrMhXQj2o5DKDK3IwOEeX2CzpnSdpUbgl6k,8471
|
|
6
|
+
code2flow/mermaid_generator.py,sha256=LBHnHAgA8vSrLEKcKD5PAZ1YcchGWM9x343AhsyYKvA,18354
|
|
7
|
+
code2flow/analysis/__init__.py,sha256=E5QI45uGUDtCZyDyp_IUF2aPpH2KzZm4wTvW9q9KIqI,619
|
|
8
|
+
code2flow/analysis/call_graph.py,sha256=dTVe8HefxvJIVarYUwgKNkr6I0EqmRlKKY0qhE9BE4w,7605
|
|
9
|
+
code2flow/analysis/cfg.py,sha256=Kx12QLP4R5pVWrFQbLIl-pxK1u6TDOt8iI9ZEa3VhZo,10716
|
|
10
|
+
code2flow/analysis/coupling.py,sha256=68uDclqSR78KwkHt_U-rRHPfC9DdAZ028NQSNh3D8j4,3319
|
|
11
|
+
code2flow/analysis/data_analysis.py,sha256=FqQjB5UkaeF_EhGLgCy4f1fl9kADcSmfiw0mecURVQQ,14433
|
|
12
|
+
code2flow/analysis/dfg.py,sha256=fKLT0mF1xU3FT7Kf3I1QZupSUSnzjb03BhPxc2TAOYc,8487
|
|
13
|
+
code2flow/analysis/pipeline_detector.py,sha256=eehY30wP4vD1MSy6nLRBkbplIWRZP4-waJYqGMktzs4,15841
|
|
14
|
+
code2flow/analysis/side_effects.py,sha256=UbC5Mi02nMFf-q3l2KSXVr6qPxx8V4TWZy7T2nBgGN0,12004
|
|
15
|
+
code2flow/analysis/smells.py,sha256=VBinDPkX6NlJlo_0XRAmhSUp5rFIs-DTiezwkdmXqi0,9193
|
|
16
|
+
code2flow/analysis/type_inference.py,sha256=F8O8m-49mf_eRpcXE4xXKJruZU7Ozsv-L3P0memfDkM,10976
|
|
17
|
+
code2flow/core/__init__.py,sha256=vj840f-QrXBcUl0FroOe9C1p59FXHtzl_1xnE3_NEXI,835
|
|
18
|
+
code2flow/core/analyzer.py,sha256=8yEsK-7qtCDMkR5ob8Pp7VfciLMd6yjw2-iKAUIGbIY,31060
|
|
19
|
+
code2flow/core/config.py,sha256=GmqPJuT9w3U_bJQFC6G5TBKzFANvv21-cSDYG9ze09E,4679
|
|
20
|
+
code2flow/core/models.py,sha256=2yMXguavdeEgu6JGc3Dk9onl7nG5-90t2hgc0Wk3q8c,6106
|
|
21
|
+
code2flow/core/streaming_analyzer.py,sha256=vHsb8akdfe6kVPnxkbpbXjvzP_W8WpddLcpUi3sWwDQ,23253
|
|
22
|
+
code2flow/exporters/__init__.py,sha256=qHYX9kXWwYBkoCRzOYemyuh0J5PpsgdQB7wPuNnXLio,1065
|
|
23
|
+
code2flow/exporters/base.py,sha256=_Mx1lePMSglPhZzhP6xw5GTf0PVibaw4U8Z1J5cEJXE,371
|
|
24
|
+
code2flow/exporters/context_exporter.py,sha256=QAPQsigKmXJU0K9Yu6ARO1q8rjfmdh4i4A5lTe9q8Pg,10063
|
|
25
|
+
code2flow/exporters/flow_exporter.py,sha256=xu6BZm6A4JlqQFqL0TIUSnqizlG8wqQes1_HA-cj3JM,21767
|
|
26
|
+
code2flow/exporters/json_exporter.py,sha256=lBhcfQ8XR7s9yEqut52bLSlbLl065JnMSqnHgLb3DrA,658
|
|
27
|
+
code2flow/exporters/llm_exporter.py,sha256=Vp4P1ca-kbnWH81eTXCBhaWyEtbyacV5DE1DgJU9SBE,360
|
|
28
|
+
code2flow/exporters/map_exporter.py,sha256=4KmYUxDnjoHvuK3Jd8bTg5qv3CUuAyltfcHuGBn7g20,8237
|
|
29
|
+
code2flow/exporters/mermaid_exporter.py,sha256=ZOnpSGufDeqfATratKejF4jLC8MW_yB_i382o--JyAM,2623
|
|
30
|
+
code2flow/exporters/toon.py,sha256=dJLl-gMaYrVXJFFSQDhfgUqacgyFHEzKq6HCo6jIP-A,39808
|
|
31
|
+
code2flow/exporters/yaml_exporter.py,sha256=SDFSlTKFxmrNeg7ke5JAfR9viWJ2_1Q2dyAFYrTFg_M,5455
|
|
32
|
+
code2flow/nlp/__init__.py,sha256=-rVTfSRRsiqu3_nrCq1rtytTgqFvp__p2I9zAAw05fk,586
|
|
33
|
+
code2flow/nlp/config.py,sha256=ZL_5yiW0UpD-S8axCiH-iCD5F1rYQ02KkTEY_c4Rzhw,6189
|
|
34
|
+
code2flow/nlp/entity_resolution.py,sha256=7R0LUMTFvWMZqp4vjyzxDqoqhdVdQa3EUIHDIg1gwNM,12034
|
|
35
|
+
code2flow/nlp/intent_matching.py,sha256=O721054NpUZ8AawHSW7_-pxktJFENWgUouNqbja42C0,10894
|
|
36
|
+
code2flow/nlp/normalization.py,sha256=Qy2Nd4EG7FVEm0EIU45qlNhSlnhucEzfR2hdtpeI6eg,4350
|
|
37
|
+
code2flow/nlp/pipeline.py,sha256=cWQdZMvmdbz9gOLk5t8MGH4a_BJ9_FbtZFMro-kQUsw,13931
|
|
38
|
+
code2flow/patterns/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
39
|
+
code2flow/patterns/detector.py,sha256=dytO145ULT0zn-nPIgLAK1NO1GfqqODRJvCuEviQMSA,6751
|
|
40
|
+
code2flow/refactor/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
41
|
+
code2flow/refactor/prompt_engine.py,sha256=wCZYSloiPrnQE-GJEad1VpJZigDQYgL57AOs4hfx8K0,7738
|
|
42
|
+
code2flow/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
43
|
+
code2flow/visualizers/graph.py,sha256=uk6pjR4Qf3QUAqmNJteexkAhMULZTA5ZO5N53SUdFE8,6415
|
|
44
|
+
code2llm-0.3.7.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
45
|
+
code2llm-0.3.7.dist-info/METADATA,sha256=b6AWeAAfr8yXlz-NmtatvqPQJXjRMXihQIwsOKDlzws,17060
|
|
46
|
+
code2llm-0.3.7.dist-info/WHEEL,sha256=YCfwYGOYMi5Jhw2fU4yNgwErybb2IX5PEwBKV4ZbdBo,91
|
|
47
|
+
code2llm-0.3.7.dist-info/entry_points.txt,sha256=ZeUga-oQQIRw1EpzqvNodYnyPWbmoeVlZj8W1xddGVs,49
|
|
48
|
+
code2llm-0.3.7.dist-info/top_level.txt,sha256=e-l_BvGCgzuB4vVmCMbArcK8Qk_GpQMYNEdEIsboIGE,10
|
|
49
|
+
code2llm-0.3.7.dist-info/RECORD,,
|