code2logic 1.0.7__tar.gz → 1.0.9__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.
- code2logic-1.0.9/PKG-INFO +470 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/README.md +21 -7
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/__init__.py +1 -1
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/generators.py +6 -10
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/toon_format.py +48 -2
- {code2logic-1.0.7 → code2logic-1.0.9}/pyproject.toml +67 -94
- code2logic-1.0.7/.gitignore +0 -211
- code2logic-1.0.7/CHANGELOG.md +0 -220
- code2logic-1.0.7/PKG-INFO +0 -674
- code2logic-1.0.7/tests/__init__.py +0 -3
- code2logic-1.0.7/tests/conftest.py +0 -367
- code2logic-1.0.7/tests/samples/sample_algorithms.py +0 -251
- code2logic-1.0.7/tests/samples/sample_api.py +0 -138
- code2logic-1.0.7/tests/samples/sample_async.py +0 -210
- code2logic-1.0.7/tests/samples/sample_class.py +0 -96
- code2logic-1.0.7/tests/samples/sample_dataclasses.py +0 -82
- code2logic-1.0.7/tests/samples/sample_enum.py +0 -95
- code2logic-1.0.7/tests/samples/sample_functions.py +0 -123
- code2logic-1.0.7/tests/samples/sample_go.go +0 -119
- code2logic-1.0.7/tests/samples/sample_javascript.js +0 -167
- code2logic-1.0.7/tests/samples/sample_pydantic.py +0 -78
- code2logic-1.0.7/tests/samples/sample_reexport/__init__.py +0 -21
- code2logic-1.0.7/tests/samples/sample_reexport/exceptions.py +0 -11
- code2logic-1.0.7/tests/samples/sample_reexport/models.py +0 -28
- code2logic-1.0.7/tests/samples/sample_reexport/utils.py +0 -13
- code2logic-1.0.7/tests/samples/sample_rust.rs +0 -209
- code2logic-1.0.7/tests/samples/sample_sql.sql +0 -93
- code2logic-1.0.7/tests/samples/sample_sql_dsl.py +0 -231
- code2logic-1.0.7/tests/samples/sample_typescript.ts +0 -141
- code2logic-1.0.7/tests/test_analyzer.py +0 -246
- code2logic-1.0.7/tests/test_error_handling.py +0 -489
- code2logic-1.0.7/tests/test_formats.py +0 -486
- code2logic-1.0.7/tests/test_generators.py +0 -260
- code2logic-1.0.7/tests/test_intent.py +0 -503
- code2logic-1.0.7/tests/test_llm_priority.py +0 -68
- code2logic-1.0.7/tests/test_llm_profiler.py +0 -555
- code2logic-1.0.7/tests/test_parser_integrity.py +0 -307
- code2logic-1.0.7/tests/test_reproduction.py +0 -288
- code2logic-1.0.7/tests/test_shared_utils.py +0 -325
- code2logic-1.0.7/tests/test_yaml_compact.py +0 -240
- {code2logic-1.0.7 → code2logic-1.0.9}/LICENSE +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/__main__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/adaptive.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/analyzer.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/base.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/benchmark.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/benchmarks/__init__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/benchmarks/common.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/benchmarks/results.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/benchmarks/runner.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/chunked_reproduction.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/cli.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/code_review.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/config.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/core/__init__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/dependency.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/errors.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/file_formats.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/formats/__init__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/gherkin.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/integrations/__init__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/intent.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/llm/__init__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/llm.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/llm_clients.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/llm_profiler.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/logicml.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/markdown_format.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/mcp_server.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/metrics.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/models.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/parsers.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/project_reproducer.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/prompts.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/py.typed +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/quality.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/refactor.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/reproducer.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/reproduction.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/schemas/__init__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/schemas/json_schema.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/schemas/logicml_schema.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/schemas/markdown_schema.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/schemas/yaml_schema.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/shared_utils.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/similarity.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/terminal.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/tools/__init__.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/universal.py +0 -0
- {code2logic-1.0.7 → code2logic-1.0.9}/code2logic/utils.py +0 -0
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: code2logic
|
|
3
|
+
Version: 1.0.9
|
|
4
|
+
Summary: Convert source code to logical representation for LLM analysis
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Keywords: code-analysis,llm,ast,static-analysis,tree-sitter,code-understanding,documentation,dependency-graph,nlp
|
|
7
|
+
Author: Softreck
|
|
8
|
+
Author-email: info@softreck.dev
|
|
9
|
+
Maintainer: Softreck
|
|
10
|
+
Maintainer-email: info@softreck.dev
|
|
11
|
+
Requires-Python: >=3.9,<4.0
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
+
Classifier: Topic :: Software Development :: Documentation
|
|
24
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
25
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
26
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Provides-Extra: full
|
|
29
|
+
Provides-Extra: graph
|
|
30
|
+
Provides-Extra: llm
|
|
31
|
+
Provides-Extra: nlp
|
|
32
|
+
Provides-Extra: similarity
|
|
33
|
+
Provides-Extra: treesitter
|
|
34
|
+
Requires-Dist: httpx (>=0.25.0) ; extra == "llm" or extra == "full"
|
|
35
|
+
Requires-Dist: litellm (>=1.0.0) ; extra == "llm" or extra == "full"
|
|
36
|
+
Requires-Dist: networkx (>=3.0) ; extra == "graph" or extra == "full"
|
|
37
|
+
Requires-Dist: nltk (>=3.8) ; extra == "nlp" or extra == "full"
|
|
38
|
+
Requires-Dist: pyyaml (>=6.0) ; extra == "full"
|
|
39
|
+
Requires-Dist: rapidfuzz (>=3.0) ; extra == "similarity" or extra == "full"
|
|
40
|
+
Requires-Dist: tree-sitter (>=0.21.0) ; extra == "treesitter" or extra == "full"
|
|
41
|
+
Requires-Dist: tree-sitter-javascript (>=0.21.0) ; extra == "treesitter" or extra == "full"
|
|
42
|
+
Requires-Dist: tree-sitter-python (>=0.21.0) ; extra == "treesitter" or extra == "full"
|
|
43
|
+
Requires-Dist: tree-sitter-typescript (>=0.21.0) ; extra == "treesitter" or extra == "full"
|
|
44
|
+
Project-URL: Changelog, https://github.com/wronai/code2logic/blob/main/CHANGELOG.md
|
|
45
|
+
Project-URL: Documentation, https://code2logic.readthedocs.io
|
|
46
|
+
Project-URL: Homepage, https://github.com/wronai/code2logic
|
|
47
|
+
Project-URL: Issues, https://github.com/wronai/code2logic/issues
|
|
48
|
+
Project-URL: Repository, https://github.com/wronai/code2logic.git
|
|
49
|
+
Description-Content-Type: text/markdown
|
|
50
|
+
|
|
51
|
+
# Code2Logic
|
|
52
|
+
|
|
53
|
+
[](https://badge.fury.io/py/code2logic)
|
|
54
|
+
[](https://www.python.org/downloads/)
|
|
55
|
+
[](https://www.apache.org/licenses/LICENSE-2.0)
|
|
56
|
+
|
|
57
|
+
**Convert source code to logical representation for LLM analysis.**
|
|
58
|
+
|
|
59
|
+
Code2Logic analyzes codebases and generates compact, LLM-friendly representations with semantic understanding.
|
|
60
|
+
Perfect for feeding project context to AI assistants, building code documentation, or analyzing code structure.
|
|
61
|
+
|
|
62
|
+
## ✨ Features
|
|
63
|
+
|
|
64
|
+
- 🌳 **Multi-language support** - Python, JavaScript, TypeScript, Java, Go, Rust, and more
|
|
65
|
+
- 🎯 **Tree-sitter AST parsing** - 99% accuracy with graceful fallback
|
|
66
|
+
- 📊 **NetworkX dependency graphs** - PageRank, hub detection, cycle analysis
|
|
67
|
+
- 🔍 **Rapidfuzz similarity** - Find duplicate and similar functions
|
|
68
|
+
- 🧠 **NLP intent extraction** - Human-readable function descriptions
|
|
69
|
+
- 📦 **Zero dependencies** - Core works without any external libs
|
|
70
|
+
|
|
71
|
+
## 🚀 Installation
|
|
72
|
+
|
|
73
|
+
### Basic (no dependencies)
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install code2logic
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Full (all features)
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
pip install code2logic[full]
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Selective features
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install code2logic[treesitter] # High-accuracy AST parsing
|
|
89
|
+
pip install code2logic[graph] # Dependency analysis
|
|
90
|
+
pip install code2logic[similarity] # Similar function detection
|
|
91
|
+
pip install code2logic[nlp] # Enhanced intents
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 📖 Quick Start
|
|
95
|
+
|
|
96
|
+
### Command Line
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Standard Markdown output
|
|
100
|
+
code2logic /path/to/project
|
|
101
|
+
|
|
102
|
+
# Compact YAML (14% smaller, meta.legend transparency)
|
|
103
|
+
code2logic /path/to/project -f yaml --compact -o analysis-compact.yaml
|
|
104
|
+
|
|
105
|
+
# Ultra-compact TOON (71% smaller, single-letter keys)
|
|
106
|
+
code2logic /path/to/project -f toon --ultra-compact -o analysis-ultra.toon
|
|
107
|
+
|
|
108
|
+
# Generate schema alongside output
|
|
109
|
+
code2logic /path/to/project -f yaml --compact --with-schema
|
|
110
|
+
|
|
111
|
+
# With detailed analysis
|
|
112
|
+
code2logic /path/to/project -d detailed
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Python API
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from code2logic import analyze_project, MarkdownGenerator
|
|
119
|
+
|
|
120
|
+
# Analyze a project
|
|
121
|
+
project = analyze_project("/path/to/project")
|
|
122
|
+
|
|
123
|
+
# Generate output
|
|
124
|
+
generator = MarkdownGenerator()
|
|
125
|
+
output = generator.generate(project, detail_level='standard')
|
|
126
|
+
print(output)
|
|
127
|
+
|
|
128
|
+
# Access analysis results
|
|
129
|
+
print(f"Files: {project.total_files}")
|
|
130
|
+
print(f"Lines: {project.total_lines}")
|
|
131
|
+
print(f"Languages: {project.languages}")
|
|
132
|
+
|
|
133
|
+
# Get hub modules (most important)
|
|
134
|
+
hubs = [p for p, n in project.dependency_metrics.items() if n.is_hub]
|
|
135
|
+
print(f"Key modules: {hubs}")
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Organized Imports
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
# Core analysis
|
|
142
|
+
from code2logic.core import ProjectInfo, ProjectAnalyzer, analyze_project
|
|
143
|
+
|
|
144
|
+
# Format generators
|
|
145
|
+
from code2logic.formats import (
|
|
146
|
+
YAMLGenerator, JSONGenerator, TOONGenerator,
|
|
147
|
+
LogicMLGenerator, GherkinGenerator
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
# LLM clients
|
|
151
|
+
from code2logic.llm import get_client, BaseLLMClient
|
|
152
|
+
|
|
153
|
+
# Development tools
|
|
154
|
+
from code2logic.tools import run_benchmark, CodeReviewer
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## 📋 Output Formats
|
|
158
|
+
|
|
159
|
+
### Markdown (default)
|
|
160
|
+
|
|
161
|
+
Human-readable documentation with:
|
|
162
|
+
|
|
163
|
+
- Project structure tree with hub markers (★)
|
|
164
|
+
- Dependency graphs with PageRank scores
|
|
165
|
+
- Classes with methods and intents
|
|
166
|
+
- Functions with signatures and descriptions
|
|
167
|
+
|
|
168
|
+
### Compact
|
|
169
|
+
|
|
170
|
+
Ultra-compact format optimized for LLM context:
|
|
171
|
+
|
|
172
|
+
```text
|
|
173
|
+
# myproject | 102f 31875L | typescript:79/python:23
|
|
174
|
+
ENTRY: index.ts main.py
|
|
175
|
+
HUBS: evolution-manager llm-orchestrator
|
|
176
|
+
|
|
177
|
+
[core/evolution]
|
|
178
|
+
evolution-manager.ts (3719L) C:EvolutionManager | F:createEvolutionManager
|
|
179
|
+
task-queue.ts (139L) C:TaskQueue,Task
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### JSON
|
|
183
|
+
|
|
184
|
+
Machine-readable format for:
|
|
185
|
+
|
|
186
|
+
- RAG (Retrieval-Augmented Generation)
|
|
187
|
+
- Database storage
|
|
188
|
+
- Further analysis
|
|
189
|
+
|
|
190
|
+
## 🔧 Configuration
|
|
191
|
+
|
|
192
|
+
### Library Status
|
|
193
|
+
|
|
194
|
+
Check which features are available:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
code2logic --status
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```text
|
|
201
|
+
Library Status:
|
|
202
|
+
tree_sitter: ✓
|
|
203
|
+
networkx: ✓
|
|
204
|
+
rapidfuzz: ✓
|
|
205
|
+
nltk: ✗
|
|
206
|
+
spacy: ✗
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### LLM Configuration
|
|
210
|
+
|
|
211
|
+
Manage LLM providers, models, API keys, and routing priorities:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
code2logic llm status
|
|
215
|
+
code2logic llm set-provider auto
|
|
216
|
+
code2logic llm set-model openrouter nvidia/nemotron-3-nano-30b-a3b:free
|
|
217
|
+
code2logic llm key set openrouter <OPENROUTER_API_KEY>
|
|
218
|
+
code2logic llm priority set-provider openrouter 10
|
|
219
|
+
code2logic llm priority set-mode provider-first
|
|
220
|
+
code2logic llm priority set-llm-model nvidia/nemotron-3-nano-30b-a3b:free 5
|
|
221
|
+
code2logic llm priority set-llm-family nvidia/ 5
|
|
222
|
+
code2logic llm config list
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Notes:
|
|
226
|
+
|
|
227
|
+
- `code2logic llm set-provider auto` enables automatic fallback selection: providers are tried in priority order.
|
|
228
|
+
- API keys should be stored in `.env` (or environment variables), not in `litellm_config.yaml`.
|
|
229
|
+
- These commands write configuration files:
|
|
230
|
+
- `.env` in the current working directory
|
|
231
|
+
- `litellm_config.yaml` in the current working directory
|
|
232
|
+
- `~/.code2logic/llm_config.json` in your home directory
|
|
233
|
+
|
|
234
|
+
#### Priority modes
|
|
235
|
+
|
|
236
|
+
You can choose how automatic fallback ordering is computed:
|
|
237
|
+
|
|
238
|
+
- `provider-first`
|
|
239
|
+
providers are ordered by provider priority (defaults + overrides)
|
|
240
|
+
- `model-first`
|
|
241
|
+
providers are ordered by priority rules for the provider's configured model (exact/prefix)
|
|
242
|
+
- `mixed`
|
|
243
|
+
providers are ordered by the best (lowest) priority from either provider priority or model rules
|
|
244
|
+
|
|
245
|
+
Configure the mode:
|
|
246
|
+
|
|
247
|
+
```bash
|
|
248
|
+
code2logic llm priority set-mode provider-first
|
|
249
|
+
code2logic llm priority set-mode model-first
|
|
250
|
+
code2logic llm priority set-mode mixed
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Model priority rules are stored in `~/.code2logic/llm_config.json`.
|
|
254
|
+
|
|
255
|
+
### Python API (Library Status)
|
|
256
|
+
|
|
257
|
+
```python
|
|
258
|
+
from code2logic import get_library_status
|
|
259
|
+
|
|
260
|
+
status = get_library_status()
|
|
261
|
+
# {'tree_sitter': True, 'networkx': True, ...}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## 📊 Analysis Features
|
|
265
|
+
|
|
266
|
+
### Dependency Analysis
|
|
267
|
+
|
|
268
|
+
- **PageRank** - Identifies most important modules
|
|
269
|
+
- **Hub detection** - Central modules marked with ★
|
|
270
|
+
- **Cycle detection** - Find circular dependencies
|
|
271
|
+
- **Clustering** - Group related modules
|
|
272
|
+
|
|
273
|
+
### Intent Generation
|
|
274
|
+
|
|
275
|
+
Functions get human-readable descriptions:
|
|
276
|
+
|
|
277
|
+
```yaml
|
|
278
|
+
methods:
|
|
279
|
+
async findById(id:string) -> Promise<User> # retrieves user by id
|
|
280
|
+
async createUser(data:UserDTO) -> Promise<User> # creates user
|
|
281
|
+
validateEmail(email:string) -> boolean # validates email
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
### Similarity Detection
|
|
285
|
+
|
|
286
|
+
Find duplicate and similar functions:
|
|
287
|
+
|
|
288
|
+
```yaml
|
|
289
|
+
Similar Functions:
|
|
290
|
+
core/auth.ts::validateToken:
|
|
291
|
+
- python/auth.py::validate_token (92%)
|
|
292
|
+
- services/jwt.ts::verifyToken (85%)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## 🏗️ Architecture
|
|
296
|
+
|
|
297
|
+
```text
|
|
298
|
+
code2logic/
|
|
299
|
+
├── analyzer.py # Main orchestrator
|
|
300
|
+
├── parsers.py # Tree-sitter + fallback parser
|
|
301
|
+
├── dependency.py # NetworkX dependency analysis
|
|
302
|
+
├── similarity.py # Rapidfuzz similar detection
|
|
303
|
+
├── intent.py # NLP intent generation
|
|
304
|
+
├── generators.py # Output generators (MD/Compact/JSON)
|
|
305
|
+
├── models.py # Data structures
|
|
306
|
+
└── cli.py # Command-line interface
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## 🔌 Integration Examples
|
|
310
|
+
|
|
311
|
+
### With Claude/ChatGPT
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
from code2logic import analyze_project, CompactGenerator
|
|
315
|
+
|
|
316
|
+
project = analyze_project("./my-project")
|
|
317
|
+
context = CompactGenerator().generate(project)
|
|
318
|
+
|
|
319
|
+
# Use in your LLM prompt
|
|
320
|
+
prompt = f"""
|
|
321
|
+
Analyze this codebase and suggest improvements:
|
|
322
|
+
|
|
323
|
+
{context}
|
|
324
|
+
"""
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### With RAG Systems
|
|
328
|
+
|
|
329
|
+
```python
|
|
330
|
+
import json
|
|
331
|
+
from code2logic import analyze_project, JSONGenerator
|
|
332
|
+
|
|
333
|
+
project = analyze_project("./my-project")
|
|
334
|
+
data = json.loads(JSONGenerator().generate(project))
|
|
335
|
+
|
|
336
|
+
# Index in vector DB
|
|
337
|
+
for module in data['modules']:
|
|
338
|
+
for func in module['functions']:
|
|
339
|
+
embed_and_store(
|
|
340
|
+
text=f"{func['name']}: {func['intent']}",
|
|
341
|
+
metadata={'path': module['path'], 'type': 'function'}
|
|
342
|
+
)
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## 🧪 Development
|
|
346
|
+
|
|
347
|
+
### Setup
|
|
348
|
+
|
|
349
|
+
```bash
|
|
350
|
+
git clone https://github.com/wronai/code2logic
|
|
351
|
+
cd code2logic
|
|
352
|
+
poetry install --with dev -E full
|
|
353
|
+
poetry run pre-commit install
|
|
354
|
+
|
|
355
|
+
# Alternatively, you can use Makefile targets (prefer Poetry if available)
|
|
356
|
+
make install-full
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
### Tests
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
make test
|
|
363
|
+
make test-cov
|
|
364
|
+
|
|
365
|
+
# Or directly:
|
|
366
|
+
poetry run pytest
|
|
367
|
+
poetry run pytest --cov=code2logic --cov-report=html
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
### Type Checking
|
|
371
|
+
|
|
372
|
+
```bash
|
|
373
|
+
make typecheck
|
|
374
|
+
|
|
375
|
+
# Or directly:
|
|
376
|
+
poetry run mypy code2logic
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Linting
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
make lint
|
|
383
|
+
make format
|
|
384
|
+
|
|
385
|
+
# Or directly:
|
|
386
|
+
poetry run ruff check code2logic
|
|
387
|
+
poetry run black code2logic
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## 📈 Performance
|
|
391
|
+
|
|
392
|
+
| Codebase Size | Files | Lines | Time | Output Size |
|
|
393
|
+
| --- | --- | --- | --- | --- |
|
|
394
|
+
| Small | 10 | 1K | <1s | ~5KB |
|
|
395
|
+
| Medium | 100 | 30K | ~2s | ~50KB |
|
|
396
|
+
| Large | 500 | 150K | ~10s | ~200KB |
|
|
397
|
+
|
|
398
|
+
Compact format is ~10-15x smaller than Markdown.
|
|
399
|
+
|
|
400
|
+
## 🔬 Code Reproduction Benchmarks
|
|
401
|
+
|
|
402
|
+
Code2Logic can reproduce code from specifications using LLMs. Benchmark results:
|
|
403
|
+
|
|
404
|
+
### Format Comparison (Token Efficiency)
|
|
405
|
+
|
|
406
|
+
| Format | Score | Token Efficiency | Spec Tokens | Runs OK |
|
|
407
|
+
| --- | --- | --- | --- | --- |
|
|
408
|
+
| **YAML** | **71.1%** | 42.1 | **366** | 66.7% |
|
|
409
|
+
| **Markdown** | 65.6% | **48.7** | 385 | **100%** |
|
|
410
|
+
| JSON | 61.9% | 23.7 | 605 | 66.7% |
|
|
411
|
+
| Gherkin | 51.3% | 19.1 | 411 | 66.7% |
|
|
412
|
+
|
|
413
|
+
### Key Findings
|
|
414
|
+
|
|
415
|
+
- **YAML is best for score** - 71.1% reproduction accuracy
|
|
416
|
+
- **Markdown is best for token efficiency** - 48.7 score/1000 tokens
|
|
417
|
+
- **YAML uses 39.6% fewer tokens than JSON** with 9.2% higher score
|
|
418
|
+
- **Markdown has 100% runs OK** - generated code always executes
|
|
419
|
+
|
|
420
|
+
### Run Benchmarks
|
|
421
|
+
|
|
422
|
+
```bash
|
|
423
|
+
# Token-aware benchmark
|
|
424
|
+
python examples/11_token_benchmark.py --folder tests/samples/ --no-llm
|
|
425
|
+
|
|
426
|
+
# Async multi-format benchmark
|
|
427
|
+
python examples/09_async_benchmark.py --folder tests/samples/ --no-llm
|
|
428
|
+
|
|
429
|
+
# Function-level reproduction
|
|
430
|
+
python examples/10_function_reproduction.py --file tests/samples/sample_functions.py --no-llm
|
|
431
|
+
|
|
432
|
+
python examples/15_unified_benchmark.py --folder tests/samples/ --no-llm
|
|
433
|
+
|
|
434
|
+
# Terminal markdown rendering demo
|
|
435
|
+
python examples/16_terminal_demo.py --folder tests/samples/
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
## 🤝 Contributing
|
|
439
|
+
|
|
440
|
+
Contributions welcome! Please read our [Contributing Guide](CONTRIBUTING.md).
|
|
441
|
+
|
|
442
|
+
## 📄 License
|
|
443
|
+
|
|
444
|
+
Apache 2 License - see [LICENSE](LICENSE) for details.
|
|
445
|
+
|
|
446
|
+
## 📚 Documentation
|
|
447
|
+
|
|
448
|
+
- [00 - Docs Index](docs/00-index.md) - Documentation home (start here)
|
|
449
|
+
- [01 - Getting Started](docs/01-getting-started.md) - Install and first steps
|
|
450
|
+
- [02 - Configuration](docs/02-configuration.md) - API keys, environment setup
|
|
451
|
+
- [03 - CLI Reference](docs/03-cli-reference.md) - Command-line usage
|
|
452
|
+
- [04 - Python API](docs/04-python-api.md) - Programmatic usage
|
|
453
|
+
- [05 - Output Formats](docs/05-output-formats.md) - Format comparison and usage
|
|
454
|
+
- [06 - Format Specifications](docs/06-format-specifications.md) - Detailed format specs
|
|
455
|
+
- [07 - TOON Format](docs/07-toon.md) - Token-Oriented Object Notation
|
|
456
|
+
- [08 - LLM Integration](docs/08-llm-integration.md) - OpenRouter/Ollama/LiteLLM
|
|
457
|
+
- [09 - LLM Comparison](docs/09-llm-comparison-report.md) - Provider/model comparison
|
|
458
|
+
- [10 - Benchmarking](docs/10-benchmark.md) - Benchmark methodology and results
|
|
459
|
+
- [11 - Repeatability](docs/11-repeatability.md) - Repeatability testing
|
|
460
|
+
- [12 - Examples](docs/12-examples.md) - Usage workflows and examples
|
|
461
|
+
- [13 - Architecture](docs/13-architecture.md) - System design and components
|
|
462
|
+
- [14 - Format Analysis](docs/14-format-analysis.md) - Deeper format evaluation
|
|
463
|
+
|
|
464
|
+
## 🔗 Links
|
|
465
|
+
|
|
466
|
+
- [Documentation](https://code2logic.readthedocs.io)
|
|
467
|
+
- [PyPI](https://pypi.org/project/code2logic/)
|
|
468
|
+
- [GitHub](https://github.com/wronai/code2logic)
|
|
469
|
+
- [Issues](https://github.com/wronai/code2logic/issues)
|
|
470
|
+
|
|
@@ -299,28 +299,42 @@ for module in data['modules']:
|
|
|
299
299
|
```bash
|
|
300
300
|
git clone https://github.com/wronai/code2logic
|
|
301
301
|
cd code2logic
|
|
302
|
-
|
|
303
|
-
pre-commit install
|
|
302
|
+
poetry install --with dev -E full
|
|
303
|
+
poetry run pre-commit install
|
|
304
|
+
|
|
305
|
+
# Alternatively, you can use Makefile targets (prefer Poetry if available)
|
|
306
|
+
make install-full
|
|
304
307
|
```
|
|
305
308
|
|
|
306
309
|
### Tests
|
|
307
310
|
|
|
308
311
|
```bash
|
|
309
|
-
|
|
310
|
-
|
|
312
|
+
make test
|
|
313
|
+
make test-cov
|
|
314
|
+
|
|
315
|
+
# Or directly:
|
|
316
|
+
poetry run pytest
|
|
317
|
+
poetry run pytest --cov=code2logic --cov-report=html
|
|
311
318
|
```
|
|
312
319
|
|
|
313
320
|
### Type Checking
|
|
314
321
|
|
|
315
322
|
```bash
|
|
316
|
-
|
|
323
|
+
make typecheck
|
|
324
|
+
|
|
325
|
+
# Or directly:
|
|
326
|
+
poetry run mypy code2logic
|
|
317
327
|
```
|
|
318
328
|
|
|
319
329
|
### Linting
|
|
320
330
|
|
|
321
331
|
```bash
|
|
322
|
-
|
|
323
|
-
|
|
332
|
+
make lint
|
|
333
|
+
make format
|
|
334
|
+
|
|
335
|
+
# Or directly:
|
|
336
|
+
poetry run ruff check code2logic
|
|
337
|
+
poetry run black code2logic
|
|
324
338
|
```
|
|
325
339
|
|
|
326
340
|
## 📈 Performance
|
|
@@ -1004,6 +1004,7 @@ class YAMLGenerator:
|
|
|
1004
1004
|
# Build detailed module data with enhanced information
|
|
1005
1005
|
detailed_modules = []
|
|
1006
1006
|
for m in project.modules:
|
|
1007
|
+
file_kb = bytes_to_kb(getattr(m, 'file_bytes', 0))
|
|
1007
1008
|
mod_data = {
|
|
1008
1009
|
'p': m.path, # path
|
|
1009
1010
|
}
|
|
@@ -1033,17 +1034,10 @@ class YAMLGenerator:
|
|
|
1033
1034
|
for const in m.constants:
|
|
1034
1035
|
if isinstance(const, str):
|
|
1035
1036
|
# Handle string constants (from UniversalParser)
|
|
1036
|
-
|
|
1037
|
+
const_data.append({'n': const})
|
|
1037
1038
|
else:
|
|
1038
1039
|
# Handle ConstantInfo objects (from TreeSitter parser)
|
|
1039
|
-
|
|
1040
|
-
if const.type_annotation:
|
|
1041
|
-
const_dict['t'] = const.type_annotation
|
|
1042
|
-
if const.value_keys: # For dicts, show keys
|
|
1043
|
-
const_dict['keys'] = const.value_keys[:10]
|
|
1044
|
-
elif const.value and len(const.value) <= 100: # For small values
|
|
1045
|
-
const_dict['v'] = const.value
|
|
1046
|
-
const_data.append(const_dict)
|
|
1040
|
+
const_data.append(self._constant_to_dict(const))
|
|
1047
1041
|
if const_data:
|
|
1048
1042
|
mod_data['const'] = const_data
|
|
1049
1043
|
|
|
@@ -1776,7 +1770,9 @@ class YAMLGenerator:
|
|
|
1776
1770
|
if len(f.params) > 6:
|
|
1777
1771
|
params += f', ...+{len(f.params)-6}'
|
|
1778
1772
|
|
|
1779
|
-
|
|
1773
|
+
if params:
|
|
1774
|
+
return f"({params})"
|
|
1775
|
+
return "()"
|
|
1780
1776
|
|
|
1781
1777
|
def _constants_for_module(self, module: ModuleInfo, limit: int = 10) -> list:
|
|
1782
1778
|
"""Convert module constants into compact dictionaries."""
|
|
@@ -85,10 +85,11 @@ class TOONGenerator:
|
|
|
85
85
|
lines = []
|
|
86
86
|
|
|
87
87
|
# Module summary as tabular array
|
|
88
|
-
lines.append(f"modules[{len(modules)}]{{path{self.delim_marker}lang{self.delim_marker}lines}}:")
|
|
88
|
+
lines.append(f"modules[{len(modules)}]{{path{self.delim_marker}lang{self.delim_marker}lines{self.delim_marker}kb}}:")
|
|
89
89
|
for m in modules:
|
|
90
90
|
path = self._quote(m.path)
|
|
91
|
-
|
|
91
|
+
kb = round((getattr(m, 'file_bytes', 0) or 0) / 1024, 1)
|
|
92
|
+
lines.append(f" {path}{self.delimiter}{m.language}{self.delimiter}{m.lines_code}{self.delimiter}{kb}")
|
|
92
93
|
|
|
93
94
|
# Detailed module info
|
|
94
95
|
if detail in ('standard', 'full'):
|
|
@@ -107,6 +108,38 @@ class TOONGenerator:
|
|
|
107
108
|
if m.exports:
|
|
108
109
|
exports_str = self.delimiter.join(self._quote(x) for x in m.exports[:10])
|
|
109
110
|
lines.append(f" exports[{len(m.exports)}]: {exports_str}")
|
|
111
|
+
|
|
112
|
+
# ENHANCED: Add constants with values/keys (critical for reproduction)
|
|
113
|
+
constants_attr = getattr(m, 'constants', []) or []
|
|
114
|
+
const_rows = []
|
|
115
|
+
for c in constants_attr:
|
|
116
|
+
if isinstance(c, str):
|
|
117
|
+
if c.startswith('conditional:'):
|
|
118
|
+
continue
|
|
119
|
+
const_rows.append({'n': c, 't': '-', 'v': '-', 'keys': '-'})
|
|
120
|
+
else:
|
|
121
|
+
keys = getattr(c, 'value_keys', None) or []
|
|
122
|
+
v = getattr(c, 'value', None)
|
|
123
|
+
t = getattr(c, 'type_annotation', '') or '-'
|
|
124
|
+
if keys:
|
|
125
|
+
const_rows.append({'n': c.name, 't': t, 'v': '-', 'keys': '|'.join(keys[:10])})
|
|
126
|
+
elif v:
|
|
127
|
+
v_snip = v.replace('\n', ' ').strip()
|
|
128
|
+
if len(v_snip) > 120:
|
|
129
|
+
v_snip = v_snip[:117] + '...'
|
|
130
|
+
const_rows.append({'n': c.name, 't': t, 'v': v_snip, 'keys': '-'})
|
|
131
|
+
else:
|
|
132
|
+
const_rows.append({'n': c.name, 't': t, 'v': '-', 'keys': '-'})
|
|
133
|
+
if len(const_rows) >= 8:
|
|
134
|
+
break
|
|
135
|
+
|
|
136
|
+
if const_rows:
|
|
137
|
+
header = f"n{self.delim_marker}t{self.delim_marker}v{self.delim_marker}keys"
|
|
138
|
+
lines.append(f" const[{len(const_rows)}]{{{header}}}:")
|
|
139
|
+
for r in const_rows:
|
|
140
|
+
lines.append(
|
|
141
|
+
f" {self._quote(r['n'])}{self.delimiter}{self._quote(r['t'])}{self.delimiter}{self._quote(r['v'])}{self.delimiter}{self._quote(r['keys'])}"
|
|
142
|
+
)
|
|
110
143
|
|
|
111
144
|
# Classes
|
|
112
145
|
if m.classes:
|
|
@@ -152,6 +185,19 @@ class TOONGenerator:
|
|
|
152
185
|
if c.properties:
|
|
153
186
|
props_str = self.delimiter.join(self._quote(x) for x in c.properties[:10])
|
|
154
187
|
lines.append(f"{ind} properties[{len(c.properties)}]: {props_str}")
|
|
188
|
+
|
|
189
|
+
# ENHANCED: Dataclass fields
|
|
190
|
+
if getattr(c, 'is_dataclass', False) and getattr(c, 'fields', None):
|
|
191
|
+
fields = c.fields[:20]
|
|
192
|
+
header = f"n{self.delim_marker}t{self.delim_marker}default{self.delim_marker}factory"
|
|
193
|
+
lines.append(f"{ind} fields[{len(fields)}]{{{header}}}:")
|
|
194
|
+
for f in fields:
|
|
195
|
+
t = getattr(f, 'type_annotation', '') or '-'
|
|
196
|
+
dflt = getattr(f, 'default', None) or '-'
|
|
197
|
+
fac = getattr(f, 'default_factory', None) or '-'
|
|
198
|
+
lines.append(
|
|
199
|
+
f"{ind} {self._quote(f.name)}{self.delimiter}{self._quote(t)}{self.delimiter}{self._quote(dflt)}{self.delimiter}{self._quote(fac)}"
|
|
200
|
+
)
|
|
155
201
|
|
|
156
202
|
# Methods with full details
|
|
157
203
|
if c.methods:
|