{"id":37074660,"url":"https://github.com/wronai/code2logic","last_synced_at":"2026-01-14T08:47:24.194Z","repository":{"id":332046595,"uuid":"1127162527","full_name":"wronai/code2logic","owner":"wronai","description":"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.","archived":false,"fork":false,"pushed_at":"2026-01-12T14:04:15.000Z","size":2254,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-12T16:13:13.290Z","etag":null,"topics":["code2logic","compactness","framework","library","litellm","llm","ollama","python","refactoring"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wronai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-03T10:07:28.000Z","updated_at":"2026-01-12T14:04:19.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/wronai/code2logic","commit_stats":null,"previous_names":["wronai/code2logic"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/wronai/code2logic","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wronai%2Fcode2logic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wronai%2Fcode2logic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wronai%2Fcode2logic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wronai%2Fcode2logic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wronai","download_url":"https://codeload.github.com/wronai/code2logic/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wronai%2Fcode2logic/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28414693,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code2logic","compactness","framework","library","litellm","llm","ollama","python","refactoring"],"created_at":"2026-01-14T08:47:21.836Z","updated_at":"2026-01-14T08:47:24.178Z","avatar_url":"https://github.com/wronai.png","language":"Python","readme":"# Code2Logic\n\n \n![alt text](image.png)\n\n \n[![PyPI version](https://badge.fury.io/py/code2logic.svg)](https://badge.fury.io/py/code2logic)\n[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)\n[![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-yellow.svg)](https://www.apache.org/licenses/LICENSE-2.0)\n\n \n**Convert source code to logical representation for LLM analysis.**\n\nCode2Logic analyzes codebases and generates compact, LLM-friendly representations with semantic understanding.\nPerfect for feeding project context to AI assistants, building code documentation, or analyzing code structure.\n\n## ✨ Features\n\n- 🌳 **Multi-language support** - Python, JavaScript, TypeScript, Java, Go, Rust, and more\n- 🎯 **Tree-sitter AST parsing** - 99% accuracy with graceful fallback\n- 📊 **NetworkX dependency graphs** - PageRank, hub detection, cycle analysis\n- 🔍 **Rapidfuzz similarity** - Find duplicate and similar functions\n- 🧠 **NLP intent extraction** - Human-readable function descriptions\n- 📦 **Zero dependencies** - Core works without any external libs\n\n## 🚀 Installation\n\n### Basic (no dependencies)\n\n```bash\npip install code2logic\n```\n\n### Full (all features)\n\n```bash\npip install code2logic[full]\n```\n\n### Selective features\n\n```bash\npip install code2logic[treesitter]  # High-accuracy AST parsing\npip install code2logic[graph]       # Dependency analysis\npip install code2logic[similarity]  # Similar function detection\npip install code2logic[nlp]         # Enhanced intents\n```\n\n## 📖 Quick Start\n```bash\ncode2logic ./ -f yaml --compact --function-logic --with-schema -o project.yaml\ncode2logic ./ -f toon --ultra-compact --function-logic --with-schema -o project.toon\n```\n    \n### Command Line\n\n```bash\n# Standard Markdown output\ncode2logic /path/to/project\n\n# If the `code2logic` entrypoint is not available (e.g. running from source without install):\npython -m code2logic /path/to/project\n\n# Compact YAML (14% smaller, meta.legend transparency)\ncode2logic /path/to/project -f yaml --compact -o analysis-compact.yaml\n\n# Ultra-compact TOON (71% smaller, single-letter keys)\ncode2logic /path/to/project -f toon --ultra-compact -o analysis-ultra.toon\n\n\n# Generate schema alongside output\ncode2logic /path/to/project -f yaml --compact --with-schema\n\n# With detailed analysis\ncode2logic /path/to/project -d detailed\n```\n\n![alt text](image-1.png)\n\n### Python API\n\n```python\nfrom code2logic import analyze_project, MarkdownGenerator\n\n# Analyze a project\nproject = analyze_project(\"/path/to/project\")\n\n# Generate output\ngenerator = MarkdownGenerator()\noutput = generator.generate(project, detail_level='standard')\nprint(output)\n\n# Access analysis results\nprint(f\"Files: {project.total_files}\")\nprint(f\"Lines: {project.total_lines}\")\nprint(f\"Languages: {project.languages}\")\n\n# Get hub modules (most important)\nhubs = [p for p, n in project.dependency_metrics.items() if n.is_hub]\nprint(f\"Key modules: {hubs}\")\n```\n\n### Organized Imports\n\n```python\n# Core analysis\nfrom code2logic import ProjectInfo, ProjectAnalyzer, analyze_project\n\n# Format generators\nfrom code2logic import (\n    YAMLGenerator,\n    JSONGenerator,\n    TOONGenerator,\n    LogicMLGenerator,\n    GherkinGenerator,\n)\n\n# LLM clients\nfrom code2logic import get_client, BaseLLMClient\n\n# Development tools\nfrom code2logic import run_benchmark, CodeReviewer\n```\n\n## 📋 Output Formats\n\n### Markdown (default)\n\nHuman-readable documentation with:\n\n- Project structure tree with hub markers (★)\n- Dependency graphs with PageRank scores\n- Classes with methods and intents\n- Functions with signatures and descriptions\n\n### Compact\n\nUltra-compact format optimized for LLM context:\n\n```text\n# myproject | 102f 31875L | typescript:79/python:23\nENTRY: index.ts main.py\nHUBS: evolution-manager llm-orchestrator\n\n[core/evolution]\n  evolution-manager.ts (3719L) C:EvolutionManager | F:createEvolutionManager\n  task-queue.ts (139L) C:TaskQueue,Task\n```\n\n### JSON\n\nMachine-readable format for:\n\n- RAG (Retrieval-Augmented Generation)\n- Database storage\n- Further analysis\n\n## 🔧 Configuration\n\n### Library Status\n\nCheck which features are available:\n\n```bash\ncode2logic --status\n```\n\n```text\nLibrary Status:\n  tree_sitter: ✓\n  networkx: ✓\n  rapidfuzz: ✓\n  nltk: ✗\n  spacy: ✗\n```\n\n### LLM Configuration\n\nManage LLM providers, models, API keys, and routing priorities:\n\n```bash\ncode2logic llm status\ncode2logic llm set-provider auto\ncode2logic llm set-model openrouter nvidia/nemotron-3-nano-30b-a3b:free\ncode2logic llm key set openrouter \u003cOPENROUTER_API_KEY\u003e\ncode2logic llm priority set-provider openrouter 10\ncode2logic llm priority set-mode provider-first\ncode2logic llm priority set-llm-model nvidia/nemotron-3-nano-30b-a3b:free 5\ncode2logic llm priority set-llm-family nvidia/ 5\ncode2logic llm config list\n```\n\nNotes:\n\n- `code2logic llm set-provider auto` enables automatic fallback selection: providers are tried in priority order.\n- API keys should be stored in `.env` (or environment variables), not in `litellm_config.yaml`.\n- These commands write configuration files:\n  - `.env` in the current working directory\n  - `litellm_config.yaml` in the current working directory\n  - `~/.code2logic/llm_config.json` in your home directory\n\n#### Priority modes\n\nYou can choose how automatic fallback ordering is computed:\n\n- `provider-first`\n  providers are ordered by provider priority (defaults + overrides)\n- `model-first`\n  providers are ordered by priority rules for the provider's configured model (exact/prefix)\n- `mixed`\n  providers are ordered by the best (lowest) priority from either provider priority or model rules\n\nConfigure the mode:\n\n```bash\ncode2logic llm priority set-mode provider-first\ncode2logic llm priority set-mode model-first\ncode2logic llm priority set-mode mixed\n```\n\nModel priority rules are stored in `~/.code2logic/llm_config.json`.\n\n### Python API (Library Status)\n\n```python\nfrom code2logic import get_library_status\n\nstatus = get_library_status()\n# {'tree_sitter': True, 'networkx': True, ...}\n```\n\n## 📊 Analysis Features\n\n### Dependency Analysis\n\n- **PageRank** - Identifies most important modules\n- **Hub detection** - Central modules marked with ★\n- **Cycle detection** - Find circular dependencies\n- **Clustering** - Group related modules\n\n### Intent Generation\n\nFunctions get human-readable descriptions:\n\n```yaml\nmethods:\n  async findById(id:string) -\u003e Promise\u003cUser\u003e  # retrieves user by id\n  async createUser(data:UserDTO) -\u003e Promise\u003cUser\u003e  # creates user\n  validateEmail(email:string) -\u003e boolean  # validates email\n```\n\n### Similarity Detection\n\nFind duplicate and similar functions:\n\n```yaml\nSimilar Functions:\n  core/auth.ts::validateToken:\n    - python/auth.py::validate_token (92%)\n    - services/jwt.ts::verifyToken (85%)\n```\n\n## 🏗️ Architecture\n\n```text\ncode2logic/\n├── analyzer.py      # Main orchestrator\n├── parsers.py       # Tree-sitter + fallback parser\n├── dependency.py    # NetworkX dependency analysis\n├── similarity.py    # Rapidfuzz similar detection\n├── intent.py        # NLP intent generation\n├── generators.py    # Output generators (MD/Compact/JSON)\n├── models.py        # Data structures\n└── cli.py           # Command-line interface\n```\n\n## 🔌 Integration Examples\n\n### With Claude/ChatGPT\n\n```python\nfrom code2logic import analyze_project, CompactGenerator\n\nproject = analyze_project(\"./my-project\")\ncontext = CompactGenerator().generate(project)\n\n# Use in your LLM prompt\nprompt = f\"\"\"\nAnalyze this codebase and suggest improvements:\n\n{context}\n\"\"\"\n```\n\n### With RAG Systems\n\n```python\nimport json\nfrom code2logic import analyze_project, JSONGenerator\n\nproject = analyze_project(\"./my-project\")\ndata = json.loads(JSONGenerator().generate(project))\n\n# Index in vector DB\nfor module in data['modules']:\n    for func in module['functions']:\n        embed_and_store(\n            text=f\"{func['name']}: {func['intent']}\",\n            metadata={'path': module['path'], 'type': 'function'}\n        )\n```\n\n## 🧪 Development\n\n### Setup\n\n```bash\ngit clone https://github.com/wronai/code2logic\ncd code2logic\npoetry install --with dev -E full\npoetry run pre-commit install\n\n# Alternatively, you can use Makefile targets (prefer Poetry if available)\nmake install-full\n```\n\n### Tests\n\n```bash\nmake test\nmake test-cov\n\n# Or directly:\npoetry run pytest\npoetry run pytest --cov=code2logic --cov-report=html\n```\n\n### Type Checking\n\n```bash\nmake typecheck\n\n# Or directly:\npoetry run mypy code2logic\n```\n\n### Linting\n\n```bash\nmake lint\nmake format\n\n# Or directly:\npoetry run ruff check code2logic\npoetry run black code2logic\n```\n\n## 📈 Performance\n\n| Codebase Size | Files | Lines | Time | Output Size |\n| --- | --- | --- | --- | --- |\n| Small | 10 | 1K | \u003c1s | ~5KB |\n| Medium | 100 | 30K | ~2s | ~50KB |\n| Large | 500 | 150K | ~10s | ~200KB |\n\nCompact format is ~10-15x smaller than Markdown.\n\n## 🔬 Code Reproduction Benchmarks\n\nCode2Logic can reproduce code from specifications using LLMs. Benchmark results:\n\n### Format Comparison (Token Efficiency)\n\n| Format | Score | Token Efficiency | Spec Tokens | Runs OK |\n| --- | --- | --- | --- | --- |\n| **YAML** | **71.1%** | 42.1 | **366** | 66.7% |\n| **Markdown** | 65.6% | **48.7** | 385 | **100%** |\n| JSON | 61.9% | 23.7 | 605 | 66.7% |\n| Gherkin | 51.3% | 19.1 | 411 | 66.7% |\n\n### Key Findings\n\n- **YAML is best for score** - 71.1% reproduction accuracy\n- **Markdown is best for token efficiency** - 48.7 score/1000 tokens\n- **YAML uses 39.6% fewer tokens than JSON** with 9.2% higher score\n- **Markdown has 100% runs OK** - generated code always executes\n\n### Run Benchmarks\n\n```bash\n# Token-aware benchmark\npython examples/11_token_benchmark.py --folder tests/samples/ --no-llm\n\n# Async multi-format benchmark\npython examples/09_async_benchmark.py --folder tests/samples/ --no-llm\n\n# Function-level reproduction\npython examples/10_function_reproduction.py --file tests/samples/sample_functions.py --no-llm\n\npython examples/15_unified_benchmark.py --folder tests/samples/ --no-llm\n\n# Terminal markdown rendering demo\npython examples/16_terminal_demo.py --folder tests/samples/\n```\n\n## 🤝 Contributing\n\nContributions welcome! Please read our [Contributing Guide](CONTRIBUTING.md).\n\n## 📄 License\n\nApache 2 License - see [LICENSE](LICENSE) for details.\n\n## 🔄 Companion Packages\n\n### logic2test - Generate Tests from Logic\n\nGenerate test scaffolds from Code2Logic output:\n\n```bash\n# Show what can be generated\npython -m logic2test out/code2logic/project.c2l.yaml --summary\n\n# Generate unit tests\npython -m logic2test out/code2logic/project.c2l.yaml -o out/logic2test/tests/\n\n# Generate all test types (unit, integration, property)\npython -m logic2test out/code2logic/project.c2l.yaml -o out/logic2test/tests/ --type all\n```\n\n```python\nfrom logic2test import TestGenerator\n\ngenerator = TestGenerator('out/code2logic/project.c2l.yaml')\nresult = generator.generate_unit_tests('out/logic2test/tests/')\nprint(f\"Generated {result.tests_generated} tests\")\n```\n\n### logic2code - Generate Code from Logic\n\nGenerate source code from Code2Logic output:\n\n```bash\n# Show what can be generated\npython -m logic2code out/code2logic/project.c2l.yaml --summary\n\n# Generate Python code\npython -m logic2code out/code2logic/project.c2l.yaml -o out/logic2code/generated_code/\n\n# Generate stubs only\npython -m logic2code out/code2logic/project.c2l.yaml -o out/logic2code/generated_code/ --stubs-only\n```\n\n```python\nfrom logic2code import CodeGenerator\n\ngenerator = CodeGenerator('out/code2logic/project.c2l.yaml')\nresult = generator.generate('out/logic2code/generated_code/')\nprint(f\"Generated {result.files_generated} files\")\n```\n\n### Full Workflow: Code → Logic → Tests/Code\n\n```bash\n# 1. Analyze existing codebase\ncode2logic src/ -f yaml -o out/code2logic/project.c2l.yaml\n\n# 2. Generate tests for the codebase\npython -m logic2test out/code2logic/project.c2l.yaml -o out/logic2test/tests/ --type all\n\n# 3. Generate code scaffolds (for refactoring)\npython -m logic2code out/code2logic/project.c2l.yaml -o out/logic2code/generated_code/ --stubs-only\n```\n\n## 📚 Documentation\n\n- [00 - Docs Index](docs/00-index.md) - Documentation home (start here)\n- [01 - Getting Started](docs/01-getting-started.md) - Install and first steps\n- [02 - Configuration](docs/02-configuration.md) - API keys, environment setup\n- [03 - CLI Reference](docs/03-cli-reference.md) - Command-line usage\n- [04 - Python API](docs/04-python-api.md) - Programmatic usage\n- [05 - Output Formats](docs/05-output-formats.md) - Format comparison and usage\n- [06 - Format Specifications](docs/06-format-specifications.md) - Detailed format specs\n- [07 - TOON Format](docs/07-toon.md) - Token-Oriented Object Notation\n- [08 - LLM Integration](docs/08-llm-integration.md) - OpenRouter/Ollama/LiteLLM\n- [09 - LLM Comparison](docs/09-llm-comparison-report.md) - Provider/model comparison\n- [10 - Benchmarking](docs/10-benchmark.md) - Benchmark methodology and results\n- [11 - Repeatability](docs/11-repeatability.md) - Repeatability testing\n- [12 - Examples](docs/12-examples.md) - Usage workflows and examples\n- [13 - Architecture](docs/13-architecture.md) - System design and components\n- [14 - Format Analysis](docs/14-format-analysis.md) - Deeper format evaluation\n- [15 - Logic2Test](docs/15-logic2test.md) - Test generation from logic files\n- [16 - Logic2Code](docs/16-logic2code.md) - Code generation from logic files\n- [17 - LOLM](docs/17-lolm.md) - LLM provider management\n- [18 - Reproduction Testing](docs/18-reproduction-testing.md) - Format validation and code regeneration\n- [19 - Monorepo Workflow](docs/19-monorepo-workflow.md) - Managing all packages from repo root\n\n## 🧩 Examples\n\n- [examples/](examples/) - All runnable examples\n- [examples/run_examples.sh](examples/run_examples.sh) - Example runner script (multi-command workflows)\n- [examples/code2logic/](examples/code2logic/) - Minimal project + docker example for code2logic\n- [examples/logic2test/](examples/logic2test/) - Minimal project + docker example for logic2test\n- [examples/logic2code/](examples/logic2code/) - Minimal project + docker example for logic2code\n\n## 🔗 Links\n\n- [Documentation](https://code2logic.readthedocs.io)\n- [PyPI](https://pypi.org/project/code2logic/)\n- [GitHub](https://github.com/wronai/code2logic)\n- [Issues](https://github.com/wronai/code2logic/issues)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwronai%2Fcode2logic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwronai%2Fcode2logic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwronai%2Fcode2logic/lists"}