-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
148 lines (114 loc) · 3.95 KB
/
main.py
File metadata and controls
148 lines (114 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
"""
CodeMind - AI-powered codebase intelligence platform
Usage:
python main.py <command> [options]
Commands:
index <repo_path> - Index a repository
review <diff_file> - Review a diff file using existing index
health - Check database health
"""
import os
import sys
import asyncio
# Suppress tokenizers parallelism warning
os.environ["TOKENIZERS_PARALLELISM"] = "false"
from config import Config
from services.codebase_service import CodebaseService
from services.code_review_service import CodeReviewService
from storage.database import CodeMindDatabase
from utils.logging import setup_logging, get_logger
async def index_repository(repo_path: str):
"""Index a repository for code review."""
config = Config.load()
logger = get_logger()
# Initialize database
db = CodeMindDatabase()
# Check database health
health = db.health_check()
if not all(health.values()):
logger.error(f"Database health check failed: {health}")
logger.error("Make sure to start databases with: docker-compose up -d")
sys.exit(1)
logger.info("Database health check passed")
# Initialize service with database
service = CodebaseService(config, logger, db)
result = await service.index_repository(repo_path)
if not result.success:
logger.error(f"Failed to index repository: {result.message}")
sys.exit(1)
logger.info(
f"Successfully indexed {result.chunks_indexed} chunks in {result.duration:.2f}s"
)
# Show stats
repositories = db.list_repositories()
logger.info(f"Indexing complete. Total repositories: {len(repositories)}")
async def review_diff(diff_file: str):
"""Review a diff file."""
config = Config.load()
logger = get_logger()
# Initialize database
db = CodeMindDatabase()
# Check database health
health = db.health_check()
if not all(health.values()):
logger.error(f"Database health check failed: {health}")
logger.error("Make sure to start databases with: docker-compose up -d")
sys.exit(1)
# Initialize service with database
service = CodeReviewService(config, logger)
# Read diff content from file
with open(diff_file, "r") as f:
diff_content = f.read()
result = await service.review_diff(diff_content)
if result:
logger.info(
f"""
================================
CODE REVIEW
================================
{result.review_content}
================================
"""
)
else:
logger.error("Failed to review diff")
sys.exit(1)
async def health_check():
"""Check database health."""
logger = get_logger()
try:
db = CodeMindDatabase()
health = db.health_check()
repositories = db.list_repositories()
logger.info("=== Database Health Check ===")
logger.info(f"Vector DB (Qdrant): {'✅' if health['vector_db'] else '❌'}")
logger.info(f"Graph DB (Neo4j): {'✅' if health['graph_db'] else '❌'}")
logger.info(f"Total repositories: {len(repositories)}")
if all(health.values()):
logger.info("All databases are healthy! 🎉")
else:
logger.error("Some databases are unhealthy. Run: docker-compose up -d")
sys.exit(1)
except Exception as e:
logger.error(f"Health check failed: {e}")
sys.exit(1)
def main():
"""Main entry point."""
config = Config.load()
setup_logging(level=config.log_level)
logger = get_logger()
if len(sys.argv) < 2:
logger.info(__doc__)
sys.exit(1)
command = sys.argv[1]
if command == "index" and len(sys.argv) > 2:
asyncio.run(index_repository(sys.argv[2]))
elif command == "review" and len(sys.argv) > 2:
asyncio.run(review_diff(sys.argv[2]))
elif command == "health":
asyncio.run(health_check())
else:
logger.info(__doc__)
sys.exit(1)
if __name__ == "__main__":
main()