Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,12 +926,12 @@ async def code_graph_ingest_repo(
if ctx:
await ctx.info("Using incremental mode - detecting changed files")

changed_files = git_utils.get_changed_files(
changed_files_result = git_utils.get_changed_files(
repo_path,
since_commit=since_commit,
include_untracked=True
)
changed_files_count = len(changed_files)
changed_files_count = changed_files_result.get("count", 0)

if changed_files_count == 0:
return {
Expand All @@ -945,7 +945,7 @@ async def code_graph_ingest_repo(
}

# Filter changed files by globs
files_to_process = [f["path"] for f in changed_files if f["action"] != "deleted"]
files_to_process = [f["path"] for f in changed_files_result.get("changed_files", []) if f["action"] != "deleted"]

if ctx:
await ctx.info(f"Found {changed_files_count} changed files")
Expand Down Expand Up @@ -1277,6 +1277,8 @@ async def context_pack(
context_result = pack_builder.build_context_pack(
nodes=all_nodes,
budget=budget,
stage=stage,
repo_id=repo_id,
file_limit=8,
symbol_limit=12,
enable_deduplication=True
Expand All @@ -1286,13 +1288,13 @@ async def context_pack(
items = []
for item in context_result.get("items", []):
items.append({
"kind": item.get("type", "file"),
"title": item.get("path", "Unknown"),
"kind": item.get("kind", "file"),
"title": item.get("title", "Unknown"),
"summary": item.get("summary", ""),
"ref": item.get("ref", ""),
"extra": {
"lang": item.get("lang"),
"score": item.get("score", 0.0)
"lang": item.get("extra", {}).get("lang"),
"score": item.get("extra", {}).get("score", 0.0)
}
})

Expand Down
3 changes: 2 additions & 1 deletion services/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import time
from functools import wraps
from loguru import logger
from config import settings

# Create a custom registry to avoid conflicts
registry = CollectorRegistry()
Expand Down Expand Up @@ -259,7 +260,7 @@ async def update_neo4j_metrics(self, graph_service):
return

# Get node counts
with graph_service.driver.session(database=graph_service.neo4j_database) as session:
with graph_service.driver.session(database=settings.neo4j_database) as session:
# Count File nodes
result = session.run("MATCH (n:File) RETURN count(n) as count")
file_count = result.single()["count"]
Expand Down
45 changes: 37 additions & 8 deletions tests/test_context_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,46 @@ def test_pack_focus_paths_priority(self):
assert "important" in first_item["ref"]

@pytest.mark.unit
def test_extract_title(self):
"""Test title extraction from path"""
def test_title_extraction_via_build_context_pack(self):
"""Test that titles are properly extracted from paths via build_context_pack"""
pack_builder = PackBuilder()

# Test with multi-level path
title = pack_builder._extract_title("src/auth/token.py")
assert title == "auth/token.py"
nodes = [
{
"type": "file",
"path": "src/auth/token.py",
"lang": "python",
"score": 0.9,
"summary": "Test file",
"ref": "ref://file/src/auth/token.py"
},
{
"type": "file",
"path": "main.py",
"lang": "python",
"score": 0.8,
"summary": "Test file",
"ref": "ref://file/main.py"
}
]

pack = pack_builder.build_context_pack(
nodes=nodes,
budget=1500,
stage="plan",
repo_id="test-repo"
)

# Test with single level
title = pack_builder._extract_title("main.py")
assert title == "main.py"
# Verify titles are extracted correctly (last 2 path segments)
assert len(pack["items"]) == 2

# Multi-level path should show last 2 segments
multi_level_item = next(item for item in pack["items"] if "auth" in item["ref"])
assert multi_level_item["title"] == "auth/token.py"

# Single level path should show as-is
single_level_item = next(item for item in pack["items"] if item["ref"] == "ref://file/main.py")
assert single_level_item["title"] == "main.py"


class TestContextPackAPI:
Expand Down