Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 16, 2025

This PR addresses Issue #4263 where list_files would return only directories when targeting paths inside ignored ancestors like node_modules/@types/stream-json.

Problem

When list_files targets a path that lives under a directory in DIRS_TO_IGNORE (e.g., node_modules), ripgrep exclusions were applied globally, causing ripgrep to return no files. The fallback scanner only added directories, leading to "only directories" in results.

Solution

The fix treats paths "inside an ignored ancestor" the same as explicitly targeting that ignored directory:

  1. Added checkPathForIgnoredSegments() helper - Detects if any segment in the path is in DIRS_TO_IGNORE
  2. Modified buildRecursiveArgs() - Checks for ignored segments in the entire path (not just basename), skips exclusion patterns for directories that are part of the target path, and applies --no-ignore-vcs and --no-ignore flags when inside ignored paths
  3. Modified buildNonRecursiveArgs() - Applies the same logic for non-recursive operations
  4. Added comprehensive test coverage - Tests for various scenarios including paths inside node_modules, nested paths inside ignored directories, and paths with multiple ignored segments

Testing

  • All existing tests pass ✅
  • Added 5 new test cases specifically for node_modules/@types scenarios ✅
  • Verified the fix handles edge cases like deeply nested ignored paths ✅

References

This is my attempt to address the issue based on the detailed analysis provided. Feedback and guidance are welcome!


Important

Fixes list_files to handle paths inside ignored directories by adjusting ripgrep arguments and adding tests.

  • Behavior:
    • Fixes list_files to return files inside ignored directories by modifying buildRecursiveArgs() and buildNonRecursiveArgs() to skip exclusion patterns for directories in the target path.
    • Adds checkPathForIgnoredSegments() to detect ignored segments in paths.
  • Testing:
    • Adds tests for paths inside node_modules, nested ignored directories, and paths with multiple ignored segments in list-files.spec.ts.
  • Misc:
    • Updates list-files.ts to apply --no-ignore-vcs and --no-ignore flags when inside ignored paths.

This description was created by Ellipsis for f3cf443. You can customize this summary. It will automatically update as commits are pushed.

- Add checkPathForIgnoredSegments helper to detect if a path contains any ignored directory segments
- Modify buildRecursiveArgs to treat paths inside ignored directories (e.g., node_modules/@types/) the same as explicitly targeting those directories
- Apply same logic to buildNonRecursiveArgs for consistency
- Add comprehensive tests for node_modules/@types scenarios

This fixes the issue where list_files would return only directories when targeting paths inside ignored ancestors like node_modules/@types/stream-json.

Fixes #4263
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 16, 2025 23:52
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Sep 16, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing my own code is like grading my own homework - suspiciously generous but still finding issues.

const normalizedPath = path.normalize(dirPath)
// Split by separator and filter out empty parts
// This handles cases like trailing slashes, multiple separators, etc.
const pathParts = normalizedPath.split(path.sep).filter((part) => part.length > 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this handling Windows paths correctly? The use of path.sep should work cross-platform, but paths like C:\projects\node_modules\@types might benefit from additional testing. Consider adding a Windows-specific test case to ensure the normalization handles backslashes properly.

* @param dirPath - The directory path to check
* @returns Object with flags indicating if path contains ignored segments
*/
function checkPathForIgnoredSegments(dirPath: string): {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance consideration: For deeply nested paths, this function could be called multiple times during a single operation. Would it be worth memoizing the result for the same path during a single listFiles call?

const { hasHiddenSegment, ignoredSegment } = checkPathForIgnoredSegments(dirPath)

// If path contains ignored segments, use special handling
if (hasHiddenSegment || ignoredSegment) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we extract this condition to a variable for better readability, similar to how it's done in buildRecursiveArgs()? For example:

Suggested change
if (hasHiddenSegment || ignoredSegment) {
const shouldApplySpecialHandling = hasHiddenSegment || ignoredSegment;
if (shouldApplySpecialHandling) {
args.push("--no-ignore-vcs")
args.push("--no-ignore")
}

}
}),
kill: vi.fn(),
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be valuable to add a test case for paths containing multiple different ignored directories? For example, node_modules/package/dist/bundle to ensure the logic correctly handles the first ignored segment and doesn't get confused by subsequent ones.

.filter((f) => f.endsWith("/"))
.map((f) => {
const parts = f.split("/")
return parts[parts.length - 2] + "/"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test name could be more specific. Consider: "should not apply node_modules exclusion when path contains node_modules as a segment" to better describe what's being tested.

}

/**
* Check if a path contains any ignored directory segment
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation enhancement: This helper function could benefit from an example in its JSDoc comment showing what it returns for a path like node_modules/@types/node.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 17, 2025
@daniel-lxs
Copy link
Member

Closing this PR as the issue it addresses doesn't actually exist. Testing confirms that list_files works correctly in non-git workspaces, returning both files and directories as expected.

The issue title 'Bug: list_files tool only shows top-level empty directories in non-git workspaces' is incorrect. The actual behavior described in the issue (problems with paths inside node_modules/@types/) is a different concern related to ignored directory patterns, not git initialization status.

Since the reported bug doesn't exist and the PR addresses a non-existent problem based on a misunderstanding of the issue, this PR should be closed.

@daniel-lxs daniel-lxs closed this Sep 18, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 18, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Bug: list_files tool only shows top-level empty directories in non-git workspaces

4 participants