code2logic 1.0.1__tar.gz → 1.0.3__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 (87) hide show
  1. {code2logic-1.0.1 → code2logic-1.0.3}/CHANGELOG.md +11 -0
  2. {code2logic-1.0.1 → code2logic-1.0.3}/PKG-INFO +82 -4
  3. {code2logic-1.0.1 → code2logic-1.0.3}/README.md +80 -3
  4. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/__init__.py +73 -1
  5. code2logic-1.0.3/code2logic/benchmarks/__init__.py +19 -0
  6. code2logic-1.0.3/code2logic/benchmarks/common.py +258 -0
  7. code2logic-1.0.3/code2logic/benchmarks/results.py +230 -0
  8. code2logic-1.0.3/code2logic/benchmarks/runner.py +790 -0
  9. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/chunked_reproduction.py +40 -5
  10. code2logic-1.0.3/code2logic/cli.py +805 -0
  11. code2logic-1.0.3/code2logic/core/__init__.py +22 -0
  12. code2logic-1.0.3/code2logic/errors.py +437 -0
  13. code2logic-1.0.3/code2logic/formats/__init__.py +35 -0
  14. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/generators.py +50 -5
  15. code2logic-1.0.3/code2logic/integrations/__init__.py +7 -0
  16. code2logic-1.0.3/code2logic/llm/__init__.py +15 -0
  17. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/llm.py +39 -10
  18. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/llm_clients.py +264 -10
  19. code2logic-1.0.3/code2logic/llm_profiler.py +650 -0
  20. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/logicml.py +23 -5
  21. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/parsers.py +34 -12
  22. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/prompts.py +16 -10
  23. code2logic-1.0.3/code2logic/quality.py +264 -0
  24. code2logic-1.0.3/code2logic/reproducer.py +705 -0
  25. code2logic-1.0.3/code2logic/schemas/__init__.py +29 -0
  26. code2logic-1.0.3/code2logic/schemas/json_schema.py +257 -0
  27. code2logic-1.0.3/code2logic/schemas/logicml_schema.py +250 -0
  28. code2logic-1.0.3/code2logic/schemas/markdown_schema.py +174 -0
  29. code2logic-1.0.3/code2logic/schemas/yaml_schema.py +179 -0
  30. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/similarity.py +73 -0
  31. code2logic-1.0.3/code2logic/terminal.py +669 -0
  32. code2logic-1.0.3/code2logic/tools/__init__.py +23 -0
  33. code2logic-1.0.3/code2logic/toon_format.py +396 -0
  34. code2logic-1.0.3/code2logic/utils.py +24 -0
  35. {code2logic-1.0.1 → code2logic-1.0.3}/pyproject.toml +16 -2
  36. code2logic-1.0.3/tests/samples/sample_enum.py +95 -0
  37. code2logic-1.0.3/tests/samples/sample_pydantic.py +78 -0
  38. code2logic-1.0.3/tests/samples/sample_reexport/__init__.py +21 -0
  39. code2logic-1.0.3/tests/samples/sample_reexport/exceptions.py +11 -0
  40. code2logic-1.0.3/tests/samples/sample_reexport/models.py +28 -0
  41. code2logic-1.0.3/tests/samples/sample_reexport/utils.py +13 -0
  42. code2logic-1.0.3/tests/test_error_handling.py +489 -0
  43. code2logic-1.0.3/tests/test_formats.py +486 -0
  44. code2logic-1.0.3/tests/test_llm_priority.py +68 -0
  45. code2logic-1.0.3/tests/test_llm_profiler.py +555 -0
  46. code2logic-1.0.1/code2logic/cli.py +0 -363
  47. code2logic-1.0.1/tests/test_format_specifics.py +0 -260
  48. {code2logic-1.0.1 → code2logic-1.0.3}/.gitignore +0 -0
  49. {code2logic-1.0.1 → code2logic-1.0.3}/LICENSE +0 -0
  50. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/__main__.py +0 -0
  51. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/adaptive.py +0 -0
  52. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/analyzer.py +0 -0
  53. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/base.py +0 -0
  54. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/benchmark.py +0 -0
  55. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/code_review.py +0 -0
  56. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/config.py +0 -0
  57. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/dependency.py +0 -0
  58. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/file_formats.py +0 -0
  59. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/gherkin.py +0 -0
  60. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/intent.py +0 -0
  61. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/markdown_format.py +0 -0
  62. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/mcp_server.py +0 -0
  63. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/metrics.py +0 -0
  64. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/models.py +0 -0
  65. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/project_reproducer.py +0 -0
  66. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/py.typed +0 -0
  67. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/refactor.py +0 -0
  68. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/reproduction.py +0 -0
  69. {code2logic-1.0.1 → code2logic-1.0.3}/code2logic/universal.py +0 -0
  70. {code2logic-1.0.1 → code2logic-1.0.3}/tests/__init__.py +0 -0
  71. {code2logic-1.0.1 → code2logic-1.0.3}/tests/conftest.py +0 -0
  72. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_algorithms.py +0 -0
  73. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_api.py +0 -0
  74. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_async.py +0 -0
  75. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_class.py +0 -0
  76. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_dataclasses.py +0 -0
  77. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_functions.py +0 -0
  78. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_go.go +0 -0
  79. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_javascript.js +0 -0
  80. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_rust.rs +0 -0
  81. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_sql.sql +0 -0
  82. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_sql_dsl.py +0 -0
  83. {code2logic-1.0.1 → code2logic-1.0.3}/tests/samples/sample_typescript.ts +0 -0
  84. {code2logic-1.0.1 → code2logic-1.0.3}/tests/test_analyzer.py +0 -0
  85. {code2logic-1.0.1 → code2logic-1.0.3}/tests/test_generators.py +0 -0
  86. {code2logic-1.0.1 → code2logic-1.0.3}/tests/test_intent.py +0 -0
  87. {code2logic-1.0.1 → code2logic-1.0.3}/tests/test_reproduction.py +0 -0
@@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ### Added
11
+ - `code2logic llm ...` command group for managing LLM provider configuration.
12
+ - `code2logic llm set-provider auto` for automatic provider fallback.
13
+ - Provider and model priority management:
14
+ - provider priorities (stored in `~/.code2logic/llm_config.json`)
15
+ - model priorities by exact model string and prefix (family)
16
+ - priority modes: `provider-first`, `model-first`, `mixed`
17
+
18
+ ### Changed
19
+ - Provider auto-selection order now follows configured priorities.
20
+
10
21
  ## [1.0.1] - 2026-01-03
11
22
 
12
23
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: code2logic
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: Convert source code to logical representation for LLM analysis
5
5
  Project-URL: Homepage, https://github.com/softreck/code2logic
6
6
  Project-URL: Documentation, https://code2logic.readthedocs.io
@@ -31,6 +31,7 @@ Requires-Python: >=3.9
31
31
  Provides-Extra: dev
32
32
  Requires-Dist: black>=23.0; extra == 'dev'
33
33
  Requires-Dist: build>=1.0.0; extra == 'dev'
34
+ Requires-Dist: bumpver>=2023.1129; extra == 'dev'
34
35
  Requires-Dist: mypy>=1.0; extra == 'dev'
35
36
  Requires-Dist: pre-commit>=3.0; extra == 'dev'
36
37
  Requires-Dist: pytest-cov>=4.0; extra == 'dev'
@@ -74,7 +75,8 @@ Description-Content-Type: text/markdown
74
75
 
75
76
  **Convert source code to logical representation for LLM analysis.**
76
77
 
77
- Code2Logic analyzes codebases and generates compact, LLM-friendly representations with semantic understanding. Perfect for feeding project context to AI assistants, building code documentation, or analyzing code structure.
78
+ Code2Logic analyzes codebases and generates compact, LLM-friendly representations with semantic understanding.
79
+ Perfect for feeding project context to AI assistants, building code documentation, or analyzing code structure.
78
80
 
79
81
  ## ✨ Features
80
82
 
@@ -146,6 +148,25 @@ hubs = [p for p, n in project.dependency_metrics.items() if n.is_hub]
146
148
  print(f"Key modules: {hubs}")
147
149
  ```
148
150
 
151
+ ### Organized Imports
152
+
153
+ ```python
154
+ # Core analysis
155
+ from code2logic.core import ProjectInfo, ProjectAnalyzer, analyze_project
156
+
157
+ # Format generators
158
+ from code2logic.formats import (
159
+ YAMLGenerator, JSONGenerator, TOONGenerator,
160
+ LogicMLGenerator, GherkinGenerator
161
+ )
162
+
163
+ # LLM clients
164
+ from code2logic.llm import get_client, BaseLLMClient
165
+
166
+ # Development tools
167
+ from code2logic.tools import run_benchmark, CodeReviewer
168
+ ```
169
+
149
170
  ## 📋 Output Formats
150
171
 
151
172
  ### Markdown (default)
@@ -187,6 +208,48 @@ Library Status:
187
208
  rapidfuzz: ✓
188
209
  nltk: ✗
189
210
  spacy: ✗
211
+
212
+ ### LLM Configuration
213
+
214
+ Manage LLM providers, models, API keys, and routing priorities:
215
+
216
+ ```bash
217
+ code2logic llm status
218
+ code2logic llm set-provider auto
219
+ code2logic llm set-model openrouter nvidia/nemotron-3-nano-30b-a3b:free
220
+ code2logic llm key set openrouter <OPENROUTER_API_KEY>
221
+ code2logic llm priority set-provider openrouter 10
222
+ code2logic llm priority set-mode provider-first
223
+ code2logic llm priority set-llm-model nvidia/nemotron-3-nano-30b-a3b:free 5
224
+ code2logic llm priority set-llm-family nvidia/ 5
225
+ code2logic llm config list
226
+ ```
227
+
228
+ Notes:
229
+
230
+ - `code2logic llm set-provider auto` enables automatic fallback selection: providers are tried in priority order.
231
+ - API keys should be stored in `.env` (or environment variables), not in `litellm_config.yaml`.
232
+
233
+ #### Priority modes
234
+
235
+ You can choose how automatic fallback ordering is computed:
236
+
237
+ - `provider-first`
238
+ providers are ordered by provider priority (defaults + overrides)
239
+ - `model-first`
240
+ providers are ordered by priority rules for the provider's configured model (exact/prefix)
241
+ - `mixed`
242
+ providers are ordered by the best (lowest) priority from either provider priority or model rules
243
+
244
+ Configure the mode:
245
+
246
+ ```bash
247
+ code2logic llm priority set-mode provider-first
248
+ code2logic llm priority set-mode model-first
249
+ code2logic llm priority set-mode mixed
250
+ ```
251
+
252
+ Model priority rules are stored in `~/.code2logic/llm_config.json`.
190
253
  ```
191
254
 
192
255
  ### Python API
@@ -339,6 +402,8 @@ python examples/09_async_benchmark.py --folder tests/samples/
339
402
 
340
403
  # Function-level reproduction
341
404
  python examples/10_function_reproduction.py --multi-lang
405
+
406
+ python examples/15_unified_benchmark.py --folder tests/samples/
342
407
  ```
343
408
 
344
409
  ## 🤝 Contributing
@@ -351,8 +416,21 @@ MIT License - see [LICENSE](LICENSE) for details.
351
416
 
352
417
  ## 📚 Documentation
353
418
 
354
- - [API Documentation](DOCS.md) - Complete API reference
355
- - [Refactoring Plan](TODO.md) - Development roadmap
419
+ - [00 - Docs Index](docs/00-index.md) - Documentation home (start here)
420
+ - [01 - Getting Started](docs/01-getting-started.md) - Install and first steps
421
+ - [02 - Configuration](docs/02-configuration.md) - API keys, environment setup
422
+ - [03 - CLI Reference](docs/03-cli-reference.md) - Command-line usage
423
+ - [04 - Python API](docs/04-python-api.md) - Programmatic usage
424
+ - [05 - Output Formats](docs/05-output-formats.md) - Format comparison and usage
425
+ - [06 - Format Specifications](docs/06-format-specifications.md) - Detailed format specs
426
+ - [07 - TOON Format](docs/07-toon.md) - Token-Oriented Object Notation
427
+ - [08 - LLM Integration](docs/08-llm-integration.md) - OpenRouter/Ollama/LiteLLM
428
+ - [09 - LLM Comparison](docs/09-llm-comparison-report.md) - Provider/model comparison
429
+ - [10 - Benchmarking](docs/10-benchmark.md) - Benchmark methodology and results
430
+ - [11 - Repeatability](docs/11-repeatability.md) - Repeatability testing
431
+ - [12 - Examples](docs/12-examples.md) - Usage workflows and examples
432
+ - [13 - Architecture](docs/13-architecture.md) - System design and components
433
+ - [14 - Format Analysis](docs/14-format-analysis.md) - Deeper format evaluation
356
434
 
357
435
  ## 🔗 Links
358
436
 
@@ -6,7 +6,8 @@
6
6
 
7
7
  **Convert source code to logical representation for LLM analysis.**
8
8
 
9
- Code2Logic analyzes codebases and generates compact, LLM-friendly representations with semantic understanding. Perfect for feeding project context to AI assistants, building code documentation, or analyzing code structure.
9
+ Code2Logic analyzes codebases and generates compact, LLM-friendly representations with semantic understanding.
10
+ Perfect for feeding project context to AI assistants, building code documentation, or analyzing code structure.
10
11
 
11
12
  ## ✨ Features
12
13
 
@@ -78,6 +79,25 @@ hubs = [p for p, n in project.dependency_metrics.items() if n.is_hub]
78
79
  print(f"Key modules: {hubs}")
79
80
  ```
80
81
 
82
+ ### Organized Imports
83
+
84
+ ```python
85
+ # Core analysis
86
+ from code2logic.core import ProjectInfo, ProjectAnalyzer, analyze_project
87
+
88
+ # Format generators
89
+ from code2logic.formats import (
90
+ YAMLGenerator, JSONGenerator, TOONGenerator,
91
+ LogicMLGenerator, GherkinGenerator
92
+ )
93
+
94
+ # LLM clients
95
+ from code2logic.llm import get_client, BaseLLMClient
96
+
97
+ # Development tools
98
+ from code2logic.tools import run_benchmark, CodeReviewer
99
+ ```
100
+
81
101
  ## 📋 Output Formats
82
102
 
83
103
  ### Markdown (default)
@@ -119,6 +139,48 @@ Library Status:
119
139
  rapidfuzz: ✓
120
140
  nltk: ✗
121
141
  spacy: ✗
142
+
143
+ ### LLM Configuration
144
+
145
+ Manage LLM providers, models, API keys, and routing priorities:
146
+
147
+ ```bash
148
+ code2logic llm status
149
+ code2logic llm set-provider auto
150
+ code2logic llm set-model openrouter nvidia/nemotron-3-nano-30b-a3b:free
151
+ code2logic llm key set openrouter <OPENROUTER_API_KEY>
152
+ code2logic llm priority set-provider openrouter 10
153
+ code2logic llm priority set-mode provider-first
154
+ code2logic llm priority set-llm-model nvidia/nemotron-3-nano-30b-a3b:free 5
155
+ code2logic llm priority set-llm-family nvidia/ 5
156
+ code2logic llm config list
157
+ ```
158
+
159
+ Notes:
160
+
161
+ - `code2logic llm set-provider auto` enables automatic fallback selection: providers are tried in priority order.
162
+ - API keys should be stored in `.env` (or environment variables), not in `litellm_config.yaml`.
163
+
164
+ #### Priority modes
165
+
166
+ You can choose how automatic fallback ordering is computed:
167
+
168
+ - `provider-first`
169
+ providers are ordered by provider priority (defaults + overrides)
170
+ - `model-first`
171
+ providers are ordered by priority rules for the provider's configured model (exact/prefix)
172
+ - `mixed`
173
+ providers are ordered by the best (lowest) priority from either provider priority or model rules
174
+
175
+ Configure the mode:
176
+
177
+ ```bash
178
+ code2logic llm priority set-mode provider-first
179
+ code2logic llm priority set-mode model-first
180
+ code2logic llm priority set-mode mixed
181
+ ```
182
+
183
+ Model priority rules are stored in `~/.code2logic/llm_config.json`.
122
184
  ```
123
185
 
124
186
  ### Python API
@@ -271,6 +333,8 @@ python examples/09_async_benchmark.py --folder tests/samples/
271
333
 
272
334
  # Function-level reproduction
273
335
  python examples/10_function_reproduction.py --multi-lang
336
+
337
+ python examples/15_unified_benchmark.py --folder tests/samples/
274
338
  ```
275
339
 
276
340
  ## 🤝 Contributing
@@ -283,8 +347,21 @@ MIT License - see [LICENSE](LICENSE) for details.
283
347
 
284
348
  ## 📚 Documentation
285
349
 
286
- - [API Documentation](DOCS.md) - Complete API reference
287
- - [Refactoring Plan](TODO.md) - Development roadmap
350
+ - [00 - Docs Index](docs/00-index.md) - Documentation home (start here)
351
+ - [01 - Getting Started](docs/01-getting-started.md) - Install and first steps
352
+ - [02 - Configuration](docs/02-configuration.md) - API keys, environment setup
353
+ - [03 - CLI Reference](docs/03-cli-reference.md) - Command-line usage
354
+ - [04 - Python API](docs/04-python-api.md) - Programmatic usage
355
+ - [05 - Output Formats](docs/05-output-formats.md) - Format comparison and usage
356
+ - [06 - Format Specifications](docs/06-format-specifications.md) - Detailed format specs
357
+ - [07 - TOON Format](docs/07-toon.md) - Token-Oriented Object Notation
358
+ - [08 - LLM Integration](docs/08-llm-integration.md) - OpenRouter/Ollama/LiteLLM
359
+ - [09 - LLM Comparison](docs/09-llm-comparison-report.md) - Provider/model comparison
360
+ - [10 - Benchmarking](docs/10-benchmark.md) - Benchmark methodology and results
361
+ - [11 - Repeatability](docs/11-repeatability.md) - Repeatability testing
362
+ - [12 - Examples](docs/12-examples.md) - Usage workflows and examples
363
+ - [13 - Architecture](docs/13-architecture.md) - System design and components
364
+ - [14 - Format Analysis](docs/14-format-analysis.md) - Deeper format evaluation
288
365
 
289
366
  ## 🔗 Links
290
367
 
@@ -18,7 +18,7 @@ Example:
18
18
  >>> print(output)
19
19
  """
20
20
 
21
- __version__ = "1.0.1"
21
+ __version__ = "1.0.3"
22
22
  __author__ = "Softreck"
23
23
  __email__ = "info@softreck.dev"
24
24
  __license__ = "MIT"
@@ -146,6 +146,46 @@ from .prompts import (
146
146
  get_review_prompt,
147
147
  get_fix_prompt,
148
148
  )
149
+ from .schemas import (
150
+ validate_yaml,
151
+ validate_logicml,
152
+ validate_markdown,
153
+ validate_json,
154
+ YAMLSchema,
155
+ LogicMLSchema,
156
+ MarkdownSchema,
157
+ JSONSchema,
158
+ )
159
+ from .quality import (
160
+ QualityAnalyzer,
161
+ QualityReport,
162
+ QualityIssue,
163
+ analyze_quality,
164
+ get_quality_summary,
165
+ )
166
+ from .similarity import get_refactoring_suggestions
167
+ from .errors import (
168
+ ErrorHandler,
169
+ ErrorType,
170
+ ErrorSeverity,
171
+ AnalysisError,
172
+ AnalysisResult,
173
+ create_error_handler,
174
+ )
175
+ from .reproducer import (
176
+ SpecReproducer,
177
+ SpecValidator,
178
+ ReproductionResult,
179
+ FileValidation,
180
+ reproduce_project,
181
+ validate_files,
182
+ )
183
+ from .toon_format import (
184
+ TOONGenerator,
185
+ TOONParser,
186
+ generate_toon,
187
+ parse_toon,
188
+ )
149
189
  from .chunked_reproduction import (
150
190
  ChunkedReproducer,
151
191
  ChunkedResult,
@@ -155,6 +195,23 @@ from .chunked_reproduction import (
155
195
  auto_chunk_reproduce,
156
196
  get_llm_limit,
157
197
  )
198
+ from .llm_profiler import (
199
+ LLMProfiler,
200
+ LLMProfile,
201
+ AdaptiveChunker,
202
+ profile_llm,
203
+ get_profile,
204
+ get_or_create_profile,
205
+ get_adaptive_chunker,
206
+ load_profiles,
207
+ save_profile,
208
+ )
209
+ from .terminal import (
210
+ ShellRenderer,
211
+ render,
212
+ get_renderer,
213
+ set_renderer,
214
+ )
158
215
 
159
216
  __all__ = [
160
217
  # Version
@@ -262,4 +319,19 @@ __all__ = [
262
319
  "MarkdownSpec",
263
320
  "generate_markdown_hybrid",
264
321
  "generate_file_markdown",
322
+ # LLM Profiler
323
+ "LLMProfiler",
324
+ "LLMProfile",
325
+ "AdaptiveChunker",
326
+ "profile_llm",
327
+ "get_profile",
328
+ "get_or_create_profile",
329
+ "get_adaptive_chunker",
330
+ "load_profiles",
331
+ "save_profile",
332
+ # Terminal Rendering
333
+ "ShellRenderer",
334
+ "render",
335
+ "get_renderer",
336
+ "set_renderer",
265
337
  ]
@@ -0,0 +1,19 @@
1
+ from .common import (
2
+ create_single_project,
3
+ generate_spec,
4
+ generate_spec_token,
5
+ get_async_reproduction_prompt,
6
+ get_token_reproduction_prompt,
7
+ get_simple_reproduction_prompt,
8
+ )
9
+ from .results import (
10
+ BenchmarkResult,
11
+ BenchmarkConfig,
12
+ FileResult,
13
+ FunctionResult,
14
+ FormatResult,
15
+ )
16
+ from .runner import (
17
+ BenchmarkRunner,
18
+ run_benchmark,
19
+ )
@@ -0,0 +1,258 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import datetime
4
+ from pathlib import Path
5
+ import json
6
+
7
+ from ..gherkin import GherkinGenerator
8
+ from ..generators import JSONGenerator, YAMLGenerator
9
+ from ..logicml import LogicMLGenerator
10
+ from ..markdown_format import MarkdownHybridGenerator
11
+ from ..toon_format import TOONGenerator
12
+ from ..models import ProjectInfo
13
+
14
+
15
+ def create_single_project(module_info, file_path: Path) -> ProjectInfo:
16
+ return ProjectInfo(
17
+ name=file_path.name,
18
+ root_path=str(file_path.parent),
19
+ languages={"python": 1},
20
+ modules=[module_info],
21
+ dependency_graph={},
22
+ dependency_metrics={},
23
+ entrypoints=[],
24
+ similar_functions={},
25
+ total_files=1,
26
+ total_lines=module_info.lines_total,
27
+ generated_at=datetime.now().isoformat(),
28
+ )
29
+
30
+
31
+ def generate_spec(project: ProjectInfo, fmt: str) -> str:
32
+ if fmt == "gherkin":
33
+ gen = GherkinGenerator()
34
+ return gen.generate(project)
35
+ if fmt == "yaml":
36
+ gen = YAMLGenerator()
37
+ return gen.generate(project, detail="full")
38
+ if fmt == "markdown":
39
+ gen = MarkdownHybridGenerator()
40
+ spec = gen.generate(project)
41
+ return spec.content
42
+ if fmt == "json":
43
+ gen = JSONGenerator()
44
+ return gen.generate(project, detail="full")
45
+ if fmt == "logicml":
46
+ gen = LogicMLGenerator()
47
+ spec = gen.generate(project)
48
+ return spec.content
49
+ if fmt == "toon":
50
+ gen = TOONGenerator()
51
+ return gen.generate(project, detail="full")
52
+ return ""
53
+
54
+
55
+ def _generate_token_json(project: ProjectInfo) -> str:
56
+ """Generate compact, token-friendly JSON spec (used by examples/11_token_benchmark.py)."""
57
+ data = {
58
+ "project": project.name,
59
+ "files": project.total_files,
60
+ "lines": project.total_lines,
61
+ "modules": [],
62
+ }
63
+
64
+ for m in project.modules:
65
+ module: dict = {
66
+ "path": m.path,
67
+ "language": m.language,
68
+ "imports": m.imports[:10],
69
+ "exports": m.exports[:10],
70
+ }
71
+
72
+ if m.classes:
73
+ module["classes"] = []
74
+ for c in m.classes[:20]:
75
+ cls = {
76
+ "name": c.name,
77
+ "bases": c.bases,
78
+ "doc": (c.docstring[:80] if c.docstring else ""),
79
+ "properties": c.properties[:15],
80
+ "methods": [
81
+ {
82
+ "name": method.name,
83
+ "params": method.params[:5],
84
+ "returns": method.return_type or "None",
85
+ "doc": (method.intent[:50] if method.intent else ""),
86
+ "async": method.is_async,
87
+ }
88
+ for method in c.methods[:15]
89
+ ],
90
+ }
91
+ module["classes"].append(cls)
92
+
93
+ if m.functions:
94
+ module["functions"] = [
95
+ {
96
+ "name": f.name,
97
+ "params": f.params[:6],
98
+ "returns": f.return_type or "None",
99
+ "doc": (f.intent[:60] if f.intent else ""),
100
+ "async": f.is_async,
101
+ "lines": f.lines,
102
+ }
103
+ for f in m.functions[:20]
104
+ ]
105
+
106
+ data["modules"].append(module)
107
+
108
+ return json.dumps(data, indent=2)
109
+
110
+
111
+ def _generate_token_json_compact(project: ProjectInfo) -> str:
112
+ data = json.loads(_generate_token_json(project))
113
+ return json.dumps(data, separators=(",", ":"))
114
+
115
+
116
+ def generate_spec_token(project: ProjectInfo, fmt: str) -> str:
117
+ """Generate spec optimized for token benchmark (keeps historical behavior).
118
+
119
+ Notes:
120
+ - json/json_compact use the token-friendly JSON representation.
121
+ - other formats delegate to generate_spec.
122
+ """
123
+ if fmt == "json":
124
+ return _generate_token_json(project)
125
+ if fmt == "json_compact":
126
+ return _generate_token_json_compact(project)
127
+ return generate_spec(project, fmt)
128
+
129
+
130
+ def get_async_reproduction_prompt(spec: str, fmt: str, file_name: str, with_tests: bool = False) -> str:
131
+ base_prompts = {
132
+ "gherkin": f"""Generate Python code from this Gherkin/BDD specification.
133
+ Implement all scenarios as working, production-ready code.
134
+
135
+ {spec[:6000]}
136
+
137
+ Requirements:
138
+ - Generate complete, working Python code for {file_name}
139
+ - Include all imports
140
+ - Use type hints
141
+ - Add docstrings""",
142
+ "yaml": f"""Generate Python code from this YAML specification.
143
+ Match the structure exactly with all classes and functions.
144
+
145
+ {spec[:6000]}
146
+
147
+ Requirements:
148
+ - Generate complete, working Python code for {file_name}
149
+ - Include all imports
150
+ - Use type hints
151
+ - Implement all methods with actual logic""",
152
+ "markdown": f"""Generate Python code from this Markdown specification.
153
+ It contains embedded Gherkin (behaviors) and YAML (structures).
154
+
155
+ {spec[:6000]}
156
+
157
+ Requirements:
158
+ - Generate complete, working Python code for {file_name}
159
+ - Include all imports
160
+ - Implement all classes and functions
161
+ - Use type hints throughout""",
162
+ }
163
+
164
+ prompt = base_prompts.get(fmt, base_prompts["yaml"])
165
+
166
+ if with_tests:
167
+ prompt += """
168
+
169
+ IMPORTANT: Also generate a unittest test class at the end of the file.
170
+ Include tests for each function/method with at least 2 test cases each.
171
+ Use unittest.TestCase as base class.
172
+ Name the test class Test<ClassName> or TestFunctions."""
173
+
174
+ return prompt
175
+
176
+
177
+ def get_token_reproduction_prompt(spec: str, fmt: str, file_name: str) -> str:
178
+ format_hints = {
179
+ "json": "Parse the JSON structure and implement all classes and functions.",
180
+ "json_compact": "Parse the compact JSON and implement all elements.",
181
+ "yaml": "Parse the YAML structure and implement all classes and functions with exact signatures.",
182
+ "gherkin": "Implement scenarios as SIMPLE, MINIMAL Python code. NO extra error classes, NO over-engineering. Keep code short and direct.",
183
+ "markdown": "Parse embedded Gherkin (behaviors) and YAML (structures).",
184
+ "logicml": """Parse LogicML and generate VALID Python code:
185
+ - 'sig: (params) -> Type' = def func(params) -> Type
186
+ - 'sig: async (params)' = async def func(params)
187
+ - 'sig: @property (self)' = @property decorator
188
+ - 'bases: [BaseModel]' = class X(BaseModel) with Field()
189
+ - 'type: re-export' = from .module import X
190
+ CRITICAL: Ensure valid syntax - balanced brackets, proper indentation, no undefined variables.""",
191
+ "toon": """Parse TOON (Token-Oriented Object Notation) format carefully:
192
+
193
+ STRUCTURE:
194
+ - 'imports[N]: mod1,mod2' = import statements to include
195
+ - 'classes[N]{name,bases,decorators,props,methods}:' = class definitions
196
+ - 'functions[N]{name,sig,decorators,async,category,lines}:' = function definitions
197
+ - 'function_docs:' section = docstrings/intent for each function
198
+
199
+ SIGNATURE FORMAT '(params)->ReturnType':
200
+ - 'sig: (self;x: int;y: str)->bool' = def func(self, x: int, y: str) -> bool
201
+ - 'sig: (self)->None' = def func(self) -> None
202
+ - Semicolons separate params, '->' indicates return type
203
+
204
+ DECORATORS:
205
+ - 'decorators: @property' = add @property decorator
206
+ - 'decorators: @staticmethod|@cache' = multiple decorators
207
+
208
+ CRITICAL: Use imports[], function_docs, and exact signatures to reproduce code accurately.""",
209
+ }
210
+
211
+ max_spec = 5000
212
+ spec_truncated = spec[:max_spec] if len(spec) > max_spec else spec
213
+
214
+ prompt = f"""Generate Python code from this {fmt.upper()} specification.
215
+ {format_hints.get(fmt, '')}
216
+
217
+ {spec_truncated}
218
+
219
+ Requirements:
220
+ - Complete, working Python code for {file_name}
221
+ - Include imports and type hints
222
+ - Implement all functions with actual logic
223
+
224
+ ```python
225
+ """
226
+ return prompt
227
+
228
+
229
+ def get_simple_reproduction_prompt(spec: str, fmt: str, file_name: str) -> str:
230
+ prompts = {
231
+ "gherkin": f"""Generate Python code from this Gherkin/BDD specification.
232
+ Implement all scenarios as working code.
233
+
234
+ {spec[:5000]}
235
+
236
+ Generate complete Python code for {file_name}:""",
237
+ "yaml": f"""Generate Python code from this YAML specification.
238
+ Match the structure exactly.
239
+
240
+ {spec[:5000]}
241
+
242
+ Generate complete Python code for {file_name}:""",
243
+ "markdown": f"""Generate Python code from this Markdown specification.
244
+ It contains embedded Gherkin and YAML sections.
245
+
246
+ {spec[:5000]}
247
+
248
+ Generate complete Python code for {file_name}:""",
249
+ "logicml": f"""Generate Python code from this LogicML specification.
250
+ 'sig:' = EXACT function signature, 'does:' = docstring, 'attrs:' = class attributes.
251
+ Match signatures EXACTLY.
252
+
253
+ {spec[:5000]}
254
+
255
+ Generate complete Python code for {file_name}:""",
256
+ }
257
+
258
+ return prompts.get(fmt, prompts["yaml"])