This example demonstrates integrating vallm with code2llm for comprehensive code analysis and validation.
- code2llm: Analyzes code structure, extracts insights, generates TOON format reports
- vallm: Validates code quality through the 4-tier pipeline
- Combined: Full project analysis with quality gates
pip install code2llm vallm- Project Structure Analysis — code2llm analyzes file structure and language distribution
- Quality Validation — vallm validates each file through syntax, imports, complexity checks
- Combined Reporting — unified report with both structural and quality metrics
- Batch Processing — process entire project directories
cd examples/08_code2llm_integration
python main.py🚀 code2llm + vallm Integration Example
============================================================
📁 Creating sample project...
Created at: sample_project
============================================================
Analyzing with code2llm...
============================================================
Analyzing project structure...
Found 3 Python files
============================================================
Validating with vallm...
============================================================
✓ math_utils.py: pass (score: 1.00)
✓ string_utils.py: pass (score: 1.00)
✓ main.py: pass (score: 1.00)
📊 Report saved to .vallm/code2llm_integration_report.json
============================================================
INTEGRATION SUMMARY
============================================================
Total files analyzed: 3
Passed: 3
Failed: 0
🎉 All files passed quality checks!
SAMPLE_PROJECT = {
"math_utils.py": '''...''',
"string_utils.py": '''...''',
"main.py": '''...''',
}from code2llm import analyze_directory
# Get project structure
result = analyze_directory(project_path)
print(f"Found {len(result['files'])} files")from vallm import Proposal, validate
# Validate each file
for file_path in project_path.rglob("*.py"):
code = file_path.read_text()
proposal = Proposal(code=code, language="python")
result = validate(proposal)
print(f"{file_path}: {result.verdict.value}"){
"analysis_tools": {
"code2llm": true,
"vallm": true
},
"project_structure": {
"files": 3,
"languages": {"Python": 3}
},
"quality_validation": {
"files": [
{"file": "math_utils.py", "verdict": "pass", "score": 1.0}
]
},
"summary": {
"total_files": 3,
"passed": 3,
"failed": 0
}
}# Analyze and validate entire codebase
python -m vallm batch src/ --recursive --format json > validation.json
code2llm analyze ./ --format toon > analysis.toon
# Combine reports
python combine_reports.py#!/usr/bin/env python
"""Pre-commit hook using code2llm + vallm."""
import subprocess
import sys
# Analyze staged files
result = subprocess.run(
["code2llm", "analyze", "--staged"],
capture_output=True
)
# Validate staged files
result = subprocess.run(
["vallm", "batch", "--staged", "--fail-fast"],
capture_output=True
)
if result.returncode != 0:
print("❌ Validation failed")
sys.exit(1)# VS Code extension using both tools
from code2llm import get_file_info
from vallm import validate_file
def on_file_save(file_path):
# Get structural info
info = get_file_info(file_path)
# Validate quality
result = validate_file(file_path)
# Show inline diagnostics
show_diagnostics(file_path, result.issues)analyze_directory(path)— Analyze entire directoryanalyze_file(path)— Analyze single fileTOONFormat.parse(path)— Parse TOON format output
from vallm import Proposal, validate, VallmSettings
from vallm.core.languages import detect_language
# Auto-detect language
lang = detect_language(file_path)
# Create proposal with detected language
proposal = Proposal(
code=code,
language=lang.tree_sitter_id if lang else "python"
)
# Validate
result = validate(proposal)pip install code2llm# Ensure both packages are in same environment
pip install code2llm vallm