import asyncio
import json
import loregrep
async def main():
print("🌳 Repository Tree Example")
print("=" * 30)
try:
lg = loregrep.LoreGrep.builder().with_rust_analyzer().with_python_analyzer().build()
print("✅ LoreGrep instance created")
print("\n📁 Scanning repository...")
scan_result = await lg.scan(".")
print(f"✅ Scanned {scan_result.files_scanned} files")
print("\n🌳 Getting repository structure...")
try:
print("\n1. Basic tree structure:")
basic_result = await lg.execute_tool("get_repository_tree", {
"max_depth": 3,
"include_file_details": False
})
print(f" ✅ Basic structure: {len(basic_result.content)} characters")
print("\n2. Detailed tree with file information:")
detailed_result = await lg.execute_tool("get_repository_tree", {
"max_depth": 2,
"include_file_details": True
})
print(f" ✅ Detailed structure: {len(detailed_result.content)} characters")
try:
data = json.loads(detailed_result.content)
if "stats" in data:
stats = data["stats"]
print(f"\n📊 Repository Statistics:")
print(f" 📁 Total files: {stats.get('total_files', '?')}")
print(f" 🔧 Total functions: {stats.get('total_functions', '?')}")
print(f" 📦 Total structs: {stats.get('total_structs', '?')}")
print(f" 📏 Total lines: {stats.get('total_lines', '?')}")
if "structure" in data:
print(f"\n🏗️ Structure data available for further processing")
except json.JSONDecodeError:
print(f" 📄 Raw tree data available")
print("\n3. Shallow overview (depth 1):")
shallow_result = await lg.execute_tool("get_repository_tree", {
"max_depth": 1,
"include_file_details": False
})
print(f" ✅ Shallow overview: {len(shallow_result.content)} characters")
except Exception as e:
print(f"❌ Tree generation failed: {e}")
print(f"\n💡 Repository tree helps understand project structure and organization")
except ImportError:
print("❌ LoreGrep not installed. Run: maturin develop --features python")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
asyncio.run(main())