This commit is contained in:
2025-11-14 00:45:18 +00:00
parent 2bbc408cd2
commit 904ea52a97
+13 -11
View File
@@ -3043,8 +3043,8 @@ Example - health_check() → { "status":"ready","total_chunks":11234,"graph_node
except: except:
repo_info = "Git repository (no branch info)" repo_info = "Git repository (no branch info)"
# Load graph to check if it exists # Load graph to check if it exists - FIX: Convert Path to string
graph = LocalGraph(str(CODEBASE_PATH)) graph = LocalGraph(root_path=str(CODEBASE_PATH)) # Convert Path to str
graph_loaded = graph.load() graph_loaded = graph.load()
status = { status = {
@@ -3080,7 +3080,7 @@ Example - health_check() → { "status":"ready","total_chunks":11234,"graph_node
"index_age_hours": round((time.time() - index_build_time) / 3600, 1) if index_build_time > 0 else None "index_age_hours": round((time.time() - index_build_time) / 3600, 1) if index_build_time > 0 else None
} }
# Add graph statistics # Add graph statistics - FIX: Use graph.graph.nodes instead of graph.nodes
if graph_loaded: if graph_loaded:
graph_stats = _calculate_graph_stats(graph) graph_stats = _calculate_graph_stats(graph)
status["graph"] = graph_stats status["graph"] = graph_stats
@@ -3098,6 +3098,7 @@ Example - health_check() → { "status":"ready","total_chunks":11234,"graph_node
def _calculate_graph_stats(graph: LocalGraph) -> dict: def _calculate_graph_stats(graph: LocalGraph) -> dict:
"""Calculate comprehensive graph statistics.""" """Calculate comprehensive graph statistics."""
# FIX: Use graph.graph.nodes and graph.graph.edges instead of graph.nodes/graph.edges
if graph.graph.number_of_nodes() == 0: if graph.graph.number_of_nodes() == 0:
return {"status": "empty", "nodes": 0, "edges": 0} return {"status": "empty", "nodes": 0, "edges": 0}
@@ -3107,34 +3108,34 @@ def _calculate_graph_stats(graph: LocalGraph) -> dict:
# Count by node type # Count by node type
node_types = {} node_types = {}
for _, data in graph.graph.nodes(data=True): for _, data in graph.graph.nodes(data=True): # FIX: graph.graph.nodes
node_type = data.get('type', 'unknown') node_type = data.get('type', 'unknown')
node_types[node_type] = node_types.get(node_type, 0) + 1 node_types[node_type] = node_types.get(node_type, 0) + 1
# Count by edge type # Count by edge type
edge_types = {} edge_types = {}
for _, _, data in graph.graph.edges(data=True): for _, _, data in graph.graph.edges(data=True): # FIX: graph.graph.edges
edge_type = data.get('type', 'unknown') edge_type = data.get('type', 'unknown')
edge_types[edge_type] = edge_types.get(edge_type, 0) + 1 edge_types[edge_type] = edge_types.get(edge_type, 0) + 1
# Language distribution # Language distribution
languages = {} languages = {}
for _, data in graph.graph.nodes(data=True): for _, data in graph.graph.nodes(data=True): # FIX: graph.graph.nodes
lang = data.get('language', 'unknown') lang = data.get('lang', 'unknown') # Changed from 'language' to 'lang' to match our new attribute
languages[lang] = languages.get(lang, 0) + 1 languages[lang] = languages.get(lang, 0) + 1
# File statistics # File statistics
files = [n for n, d in graph.graph.nodes(data=True) if d.get('type') == 'File'] files = [n for n, d in graph.graph.nodes(data=True) if d.get('type') == 'File'] # FIX: graph.graph.nodes
# Relationship density # Relationship density
avg_edges_per_node = edges / nodes if nodes > 0 else 0 avg_edges_per_node = edges / nodes if nodes > 0 else 0
# Most connected nodes (hubs) # Most connected nodes (hubs)
degree_centrality = dict(graph.graph.degree()) degree_centrality = dict(graph.graph.degree()) # FIX: graph.graph.degree()
top_hubs = sorted(degree_centrality.items(), key=lambda x: x[1], reverse=True)[:5] top_hubs = sorted(degree_centrality.items(), key=lambda x: x[1], reverse=True)[:5]
top_hubs_info = [] top_hubs_info = []
for node_id, degree in top_hubs: for node_id, degree in top_hubs:
node_data = graph.graph.nodes[node_id] node_data = graph.graph.nodes[node_id] # FIX: graph.graph.nodes
top_hubs_info.append({ top_hubs_info.append({
"name": node_data.get('name', node_id), "name": node_data.get('name', node_id),
"type": node_data.get('type', 'unknown'), "type": node_data.get('type', 'unknown'),
@@ -3170,7 +3171,8 @@ Example: search_codebase("user authentication", 5, True) → 5 results with code
if vectorstore is None or bm25_corpus is None: if vectorstore is None or bm25_corpus is None:
return "❌ Index not built. Please call init_repo() or rebuild_index() first." return "❌ Index not built. Please call init_repo() or rebuild_index() first."
graph = LocalGraph(CODEBASE_PATH) # FIX: Convert Path to string
graph = LocalGraph(root_path=str(CODEBASE_PATH))
graph_loaded = graph.load() graph_loaded = graph.load()
if not graph_loaded: if not graph_loaded: