Skip to content
Open
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
9 changes: 6 additions & 3 deletions fastcode/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
is_supported_file,
should_ignore_path,
get_repo_name_from_url,
get_repo_name_from_path,
normalize_path,
ensure_dir,
)
Expand Down Expand Up @@ -135,9 +136,12 @@ def load_from_path(self, path: str, target_dir: Optional[str] = None) -> str:
if not os.path.isdir(path):
raise ValueError(f"Path is not a directory: {path}")

source_path = os.path.abspath(path)
self.repo_name = os.path.basename(source_path)
destination_root = os.path.abspath(target_dir) if target_dir else self.safe_repo_root
source_path = os.path.abspath(path)
self.repo_name = get_repo_name_from_path(
source_path,
workspace_root=destination_root,
)
destination_path = os.path.join(destination_root, self.repo_name)

# If source is already in workspace destination, use it directly.
Expand Down Expand Up @@ -381,4 +385,3 @@ def cleanup(self):
def __del__(self):
"""Cleanup on deletion"""
self.cleanup()

261 changes: 207 additions & 54 deletions fastcode/main.py

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions fastcode/query_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def _enhance_with_llm(self, query: str, intent: str,
else:
return {}

print(f"LLM response of _enhance_with_llm: {response}")
self.logger.debug("LLM enhancement response received")

# Parse LLM response
enhancements = self._parse_llm_response(response, intent)
Expand Down Expand Up @@ -825,4 +825,3 @@ def _parse_rewritten_query(self, response: str) -> Optional[str]:
rewritten = rewritten[1:-1]

return rewritten if rewritten else None

7 changes: 4 additions & 3 deletions fastcode/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def _select_relevant_repositories(self, query: Union[str, List[str]], keywords:
# 2. get top k
for repo_name, scores in sorted_repos[:top_k]:
selected_repos.append(repo_name)
print(
self.logger.info(
f"Selected repo: {repo_name} "
f"(semantic: {scores['semantic_score']:.3f}, "
f"bm25: {scores['bm25_score']:.3f}, "
Expand All @@ -510,7 +510,9 @@ def _select_relevant_repositories(self, query: Union[str, List[str]], keywords:

# 3. no repo selected
if not selected_repos:
print(f"No repositories met the minimum score threshold of {MIN_SCORE_THRESHOLD}")
self.logger.info(
f"No repositories met the minimum score threshold of {MIN_SCORE_THRESHOLD}"
)

return selected_repos

Expand Down Expand Up @@ -1440,4 +1442,3 @@ def _apply_agency_mode(self, query: str, results: List[Dict[str, Any]],
self.logger.error(traceback.format_exc())
# Fallback to original results
return results

22 changes: 21 additions & 1 deletion fastcode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,27 @@ def get_repo_name_from_url(url: str) -> str:
return parts[-1] if parts else "unknown_repo"


def get_repo_name_from_path(path: str, workspace_root: Optional[str] = None) -> str:
"""Derive a stable local repository identifier from its absolute path."""
normalized = normalize_path(os.path.abspath(path or ""))
base_name = os.path.basename(normalized.rstrip("/")) or "local_repo"

if workspace_root:
normalized_root = normalize_path(os.path.abspath(workspace_root))
parent_dir = normalize_path(os.path.dirname(normalized.rstrip("/")))
suffix = base_name.rsplit("-", 1)
if (
parent_dir == normalized_root
and len(suffix) == 2
and len(suffix[1]) == 8
and all(ch in "0123456789abcdef" for ch in suffix[1].lower())
):
return base_name

digest = hashlib.md5(normalized.encode("utf-8")).hexdigest()[:8]
return f"{base_name}-{digest}"


def clean_docstring(docstring: str) -> str:
"""Clean and format docstring"""
if not docstring:
Expand All @@ -335,4 +356,3 @@ def clean_docstring(docstring: str) -> str:
for line in lines]

return "\n".join(lines).strip()

5 changes: 3 additions & 2 deletions fastcode/vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,9 @@ def search_repository_overviews(self, query_vector: np.ndarray, k: int = 5,
distance = float(np.linalg.norm(query_vector - embedding))
similarity = 1.0 / (1.0 + distance)

print(f"similarity: {similarity}, repo_name: {repo_name}")
self.logger.debug(
f"Repository overview similarity for {repo_name}: {similarity:.4f}"
)

# Apply minimum score filter
if min_score is not None and similarity < min_score:
Expand Down Expand Up @@ -752,4 +754,3 @@ def invalidate_scan_cache(self):
"""Invalidate the scan cache (call this when indexes change)"""
self._index_scan_cache = None
self.logger.debug("Invalidated index scan cache")

Loading
Loading