Skip to content

Commit f8f0e77

Browse files
refactoring
1 parent 675f7db commit f8f0e77

5 files changed

Lines changed: 55 additions & 27 deletions

File tree

README.md

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,19 @@ from code2logic.llm import get_client, BaseLLMClient
101101
from code2logic.tools import run_benchmark, CodeReviewer
102102
```
103103

104-
## Output Formats
104+
## 📋 Output Formats
105105

106106
### Markdown (default)
107+
107108
Human-readable documentation with:
109+
108110
- Project structure tree with hub markers (★)
109111
- Dependency graphs with PageRank scores
110112
- Classes with methods and intents
111113
- Functions with signatures and descriptions
112114

113115
### Compact
116+
114117
Ultra-compact format optimized for LLM context:
115118

116119
```text
@@ -124,12 +127,14 @@ HUBS: evolution-manager llm-orchestrator
124127
```
125128

126129
### JSON
130+
127131
Machine-readable format for:
132+
128133
- RAG (Retrieval-Augmented Generation)
129134
- Database storage
130135
- Further analysis
131136

132-
## Configuration
137+
## 🔧 Configuration
133138

134139
### Library Status
135140
Check which features are available:
@@ -198,15 +203,17 @@ status = get_library_status()
198203
# {'tree_sitter': True, 'networkx': True, ...}
199204
```
200205

201-
## Analysis Features
206+
## 📊 Analysis Features
202207

203208
### Dependency Analysis
209+
204210
- **PageRank** - Identifies most important modules
205211
- **Hub detection** - Central modules marked with ★
206212
- **Cycle detection** - Find circular dependencies
207213
- **Clustering** - Group related modules
208214

209215
### Intent Generation
216+
210217
Functions get human-readable descriptions:
211218

212219
```yaml
@@ -217,6 +224,7 @@ methods:
217224
```
218225
219226
### Similarity Detection
227+
220228
Find duplicate and similar functions:
221229
222230
```yaml
@@ -226,7 +234,7 @@ Similar Functions:
226234
- services/jwt.ts::verifyToken (85%)
227235
```
228236
229-
## Architecture
237+
## 🏗️ Architecture
230238
231239
```text
232240
code2logic/
@@ -240,7 +248,7 @@ code2logic/
240248
└── cli.py # Command-line interface
241249
```
242250

243-
## Integration Examples
251+
## 🔌 Integration Examples
244252

245253
### With Claude/ChatGPT
246254

@@ -276,7 +284,7 @@ for module in data['modules']:
276284
)
277285
```
278286

279-
## Development
287+
## 🧪 Development
280288

281289
### Setup
282290

@@ -307,28 +315,28 @@ ruff check code2logic
307315
black code2logic
308316
```
309317

310-
## Performance
318+
## 📈 Performance
311319

312-
| Codebase Size | Files | Lines | Time | Output Size |
313-
| --- | --- | --- | --- | --- |
314-
| Small | 10 | 1K | <1s | ~5KB |
315-
| Medium | 100 | 30K | ~2s | ~50KB |
316-
| Large | 500 | 150K | ~10s | ~200KB |
320+
|Codebase Size|Files|Lines|Time|Output Size|
321+
|---|---|---|---|---|
322+
|Small|10|1K|<1s|~5KB|
323+
|Medium|100|30K|~2s|~50KB|
324+
|Large|500|150K|~10s|~200KB|
317325

318326
Compact format is ~10-15x smaller than Markdown.
319327

320-
## Code Reproduction Benchmarks
328+
## 🔬 Code Reproduction Benchmarks
321329

322330
Code2Logic can reproduce code from specifications using LLMs. Benchmark results:
323331

324332
### Format Comparison (Token Efficiency)
325333

326-
| Format | Score | Token Efficiency | Spec Tokens | Runs OK |
327-
| --- | --- | --- | --- | --- |
328-
| **YAML** | **71.1%** | 42.1 | **366** | 66.7% |
329-
| **Markdown** | 65.6% | **48.7** | 385 | **100%** |
330-
| JSON | 61.9% | 23.7 | 605 | 66.7% |
331-
| Gherkin | 51.3% | 19.1 | 411 | 66.7% |
334+
|Format|Score|Token Efficiency|Spec Tokens|Runs OK|
335+
|---|---|---|---|---|
336+
|**YAML**|**71.1%**|42.1|**366**|66.7%|
337+
|**Markdown**|65.6%|**48.7**|385|**100%**|
338+
|JSON|61.9%|23.7|605|66.7%|
339+
|Gherkin|51.3%|19.1|411|66.7%|
332340

333341
### Key Findings
334342

code2logic/benchmarks/runner.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,12 @@ def run_file_benchmark(
374374

375375
client: Optional[BaseLLMClient]
376376
if self._should_use_llm():
377-
client = self._get_client()
377+
try:
378+
client = self._get_client()
379+
except Exception as e:
380+
client = None
381+
if verbose:
382+
render.warning(f"LLM not available ({str(e)[:80]}). Falling back to template mode.")
378383
else:
379384
client = None
380385

@@ -471,7 +476,12 @@ def run_function_benchmark(
471476

472477
client: Optional[BaseLLMClient]
473478
if self._should_use_llm():
474-
client = self._get_client()
479+
try:
480+
client = self._get_client()
481+
except Exception as e:
482+
client = None
483+
if verbose:
484+
render.warning(f"LLM not available ({str(e)[:80]}). Falling back to template mode.")
475485
else:
476486
client = None
477487

code2logic/universal.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,9 +903,15 @@ class UniversalReproducer:
903903

904904
def __init__(self, client: BaseLLMClient = None):
905905
"""Initialize reproducer."""
906-
self.client = client or get_client()
906+
self.client = client
907907
self.parser = UniversalParser()
908908
self.generator = CodeGenerator()
909+
910+
def _get_client(self) -> BaseLLMClient:
911+
"""Get or create LLM client."""
912+
if self.client is None:
913+
self.client = get_client()
914+
return self.client
909915

910916
def extract_logic(self, file_path: str) -> CodeLogic:
911917
"""Extract code logic from file."""
@@ -978,6 +984,7 @@ def reproduce(
978984

979985
def _generate_with_llm(self, logic: CodeLogic, target: Language) -> str:
980986
"""Generate code using LLM."""
987+
client = self._get_client()
981988
compact = logic.to_compact()
982989

983990
lang_names = {
@@ -1007,7 +1014,7 @@ def _generate_with_llm(self, logic: CodeLogic, target: Language) -> str:
10071014
10081015
Generate complete, working {target_name} code that implements all elements."""
10091016

1010-
response = self.client.generate(prompt, system=system, max_tokens=8000)
1017+
response = client.generate(prompt, system=system, max_tokens=8000)
10111018
return extract_code_block(response, target.value)
10121019

10131020
def _save_result(

examples/15_unified_benchmark.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
functionality from examples 10-13 into a simple, reusable interface.
77
88
Usage:
9-
python examples/14_unified_benchmark.py
10-
python examples/14_unified_benchmark.py --type format --folder tests/samples/
11-
python examples/14_unified_benchmark.py --type function --file tests/samples/sample_functions.py
12-
python examples/14_unified_benchmark.py --type project --folder tests/samples/ --limit 3
9+
python examples/15_unified_benchmark.py
10+
python examples/15_unified_benchmark.py --type format --folder tests/samples/
11+
python examples/15_unified_benchmark.py --type function --file tests/samples/sample_functions.py
12+
python examples/15_unified_benchmark.py --type project --folder tests/samples/ --limit 3
1313
"""
1414

1515
import argparse
@@ -102,13 +102,15 @@ def main():
102102
parser.add_argument('--limit', '-l', type=int, default=3)
103103
parser.add_argument('--output', '-o', default='examples/output/unified_benchmark.json')
104104
parser.add_argument('--verbose', '-v', action='store_true')
105+
parser.add_argument('--no-llm', action='store_true', help='Run without LLM (template fallback)')
105106
args = parser.parse_args()
106107

107108
# Configure
108109
config = BenchmarkConfig(
109110
formats=args.formats,
110111
max_files=args.limit,
111112
verbose=args.verbose,
113+
use_llm=not args.no_llm,
112114
)
113115

114116
runner = BenchmarkRunner(config=config)

examples/16_terminal_demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def demo_log_highlighting():
182182
def main():
183183
parser = argparse.ArgumentParser(description='Terminal Rendering Demo')
184184
parser.add_argument('--no-color', action='store_true', help='Disable colors')
185+
parser.add_argument('--folder', '-f', default=None, help='Ignored (kept for CLI compatibility)')
185186
args = parser.parse_args()
186187

187188
if args.no_color:

0 commit comments

Comments
 (0)