code2logic 1.0.13__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 (57) hide show
  1. code2logic-1.0.13/LICENSE +201 -0
  2. code2logic-1.0.13/PKG-INFO +470 -0
  3. code2logic-1.0.13/README.md +419 -0
  4. code2logic-1.0.13/code2logic/__init__.py +354 -0
  5. code2logic-1.0.13/code2logic/__main__.py +15 -0
  6. code2logic-1.0.13/code2logic/adaptive.py +620 -0
  7. code2logic-1.0.13/code2logic/analyzer.py +300 -0
  8. code2logic-1.0.13/code2logic/base.py +69 -0
  9. code2logic-1.0.13/code2logic/benchmark.py +449 -0
  10. code2logic-1.0.13/code2logic/benchmarks/__init__.py +19 -0
  11. code2logic-1.0.13/code2logic/benchmarks/common.py +258 -0
  12. code2logic-1.0.13/code2logic/benchmarks/results.py +229 -0
  13. code2logic-1.0.13/code2logic/benchmarks/runner.py +824 -0
  14. code2logic-1.0.13/code2logic/chunked_reproduction.py +479 -0
  15. code2logic-1.0.13/code2logic/cli.py +959 -0
  16. code2logic-1.0.13/code2logic/code_review.py +272 -0
  17. code2logic-1.0.13/code2logic/config.py +240 -0
  18. code2logic-1.0.13/code2logic/core/__init__.py +22 -0
  19. code2logic-1.0.13/code2logic/dependency.py +246 -0
  20. code2logic-1.0.13/code2logic/errors.py +437 -0
  21. code2logic-1.0.13/code2logic/file_formats.py +352 -0
  22. code2logic-1.0.13/code2logic/formats/__init__.py +35 -0
  23. code2logic-1.0.13/code2logic/function_logic.py +267 -0
  24. code2logic-1.0.13/code2logic/generators.py +2077 -0
  25. code2logic-1.0.13/code2logic/gherkin.py +980 -0
  26. code2logic-1.0.13/code2logic/integrations/__init__.py +7 -0
  27. code2logic-1.0.13/code2logic/intent.py +561 -0
  28. code2logic-1.0.13/code2logic/llm/__init__.py +15 -0
  29. code2logic-1.0.13/code2logic/llm.py +478 -0
  30. code2logic-1.0.13/code2logic/llm_clients.py +526 -0
  31. code2logic-1.0.13/code2logic/llm_profiler.py +650 -0
  32. code2logic-1.0.13/code2logic/logicml.py +370 -0
  33. code2logic-1.0.13/code2logic/markdown_format.py +365 -0
  34. code2logic-1.0.13/code2logic/mcp_server.py +356 -0
  35. code2logic-1.0.13/code2logic/metrics.py +597 -0
  36. code2logic-1.0.13/code2logic/models.py +338 -0
  37. code2logic-1.0.13/code2logic/parsers.py +1765 -0
  38. code2logic-1.0.13/code2logic/project_reproducer.py +401 -0
  39. code2logic-1.0.13/code2logic/prompts.py +156 -0
  40. code2logic-1.0.13/code2logic/py.typed +2 -0
  41. code2logic-1.0.13/code2logic/quality.py +264 -0
  42. code2logic-1.0.13/code2logic/refactor.py +388 -0
  43. code2logic-1.0.13/code2logic/reproducer.py +705 -0
  44. code2logic-1.0.13/code2logic/reproduction.py +440 -0
  45. code2logic-1.0.13/code2logic/schemas/__init__.py +29 -0
  46. code2logic-1.0.13/code2logic/schemas/json_schema.py +257 -0
  47. code2logic-1.0.13/code2logic/schemas/logicml_schema.py +250 -0
  48. code2logic-1.0.13/code2logic/schemas/markdown_schema.py +174 -0
  49. code2logic-1.0.13/code2logic/schemas/yaml_schema.py +214 -0
  50. code2logic-1.0.13/code2logic/shared_utils.py +414 -0
  51. code2logic-1.0.13/code2logic/similarity.py +238 -0
  52. code2logic-1.0.13/code2logic/terminal.py +669 -0
  53. code2logic-1.0.13/code2logic/tools/__init__.py +23 -0
  54. code2logic-1.0.13/code2logic/toon_format.py +710 -0
  55. code2logic-1.0.13/code2logic/universal.py +1074 -0
  56. code2logic-1.0.13/code2logic/utils.py +24 -0
  57. code2logic-1.0.13/pyproject.toml +192 -0
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
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 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 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 those 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
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,470 @@
1
+ Metadata-Version: 2.3
2
+ Name: code2logic
3
+ Version: 1.0.13
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"
35
+ Requires-Dist: litellm (>=1.0.0) ; extra == "llm"
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
+ [![PyPI version](https://badge.fury.io/py/code2logic.svg)](https://badge.fury.io/py/code2logic)
54
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
55
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-yellow.svg)](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
+