Skip to content

codebase_search tool doesn't handle "." path correctly for current directory searches #6514

@hannesrudolph

Description

@hannesrudolph

Description

When using the codebase_search tool with path parameter "." (meaning current directory), the search returns no results. This is because the path filtering logic creates an incorrect filter looking for files with pathSegments.0 = ".", but indexed files don't have "." in their path segments.

Steps to Reproduce

  1. Use the codebase_search tool with path parameter set to "."
  2. Example: <codebase_search><query>any search query</query><path>.</path></codebase_search>
  3. The search returns no results even though there are matching files in the workspace

Expected Behavior

When path is "." (or "./" or other current directory representations), the search should return results from the entire workspace without any path filtering.

Actual Behavior

The search returns no results because it creates a filter looking for pathSegments.0 = "." which doesn't match any indexed files.

🔍 Comprehensive Issue Scoping

Root Cause

The issue occurs in src/services/code-index/vector-store/qdrant-client.ts (lines 377-386) where the path is split into segments. When path is ".", it results in ["."] after splitting, creating an invalid filter.

Affected Components

  • Primary File:
    • src/services/code-index/vector-store/qdrant-client.ts (lines 377-386): The search method that creates path filters

Proposed Implementation

In the search method of qdrant-client.ts, add a check for current directory representations:

if (directoryPrefix) {
    // Check if the path represents current directory
    const normalizedPrefix = directoryPrefix.replace(/\\/g, '/');
    if (normalizedPrefix === '.' || normalizedPrefix === './' || normalizedPrefix === '') {
        // Don't create a filter - search entire workspace
        filter = undefined;
    } else {
        const segments = directoryPrefix.split(path.sep).filter(Boolean);
        if (segments.length > 0) {
            filter = {
                must: segments.map((segment, index) => ({
                    key: `pathSegments.${index}`,
                    match: { value: segment },
                })),
            };
        }
    }
}

Testing Requirements

  • Unit Tests:
    • Test that path "." returns results from entire workspace
    • Test that path "./" returns results from entire workspace
    • Test that path ".\" works on Windows
    • Test that path "./src" correctly filters to src directory
    • Test that existing path filtering still works correctly

Technical Considerations

  • Cross-platform compatibility (Windows backslashes)
  • No breaking changes to existing functionality
  • Minimal performance impact (just a string comparison)

Metadata

Metadata

Assignees

Labels

Issue - In ProgressSomeone is actively working on this. Should link to a PR soon.bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions