Skip to content

feat: add exclude_paths to file index configuration#33

Merged
SUSTAPLE117 merged 2 commits intomainfrom
feat-file-index-exclude-paths
Mar 26, 2026
Merged

feat: add exclude_paths to file index configuration#33
SUSTAPLE117 merged 2 commits intomainfrom
feat-file-index-exclude-paths

Conversation

@tveronezi
Copy link
Copy Markdown
Contributor

Summary

Adds file_index.exclude_paths to bagel.yaml so users can opt entire directory trees out of the file index walk:

file_index:
  exclude_paths:
    - ~/projects
    - ~/.cache

This is useful on machines with large project trees (e.g. many node_modules copies or git worktrees) where the default unlimited walk produces millions of files and makes the index build slow.

Changes

  • pkg/models/config.go — add ExcludePaths []string to FileIndexConfig
  • pkg/fileindex/fileindex.go — expand/normalize exclude paths at build time; walkDirectory() returns early when currentDir matches an excluded path (exact match or child prefix); empty/whitespace entries are ignored; paths normalized with filepath.Clean/filepath.FromSlash
  • pkg/collector/collector.go — pass ExcludePaths from config into BuildIndexInput, cache.LoadInput, and cache.SaveInput
  • pkg/cache/cache.go — include ExcludePaths in cache key and Metadata so changing the list invalidates stale cache entries; SchemaVersion bumped to 4

Tests

TestBuildIndex_WithExcludePaths — verifies that files inside an excluded directory are not indexed while files in a sibling directory still are.

Introduces file_index.exclude_paths in bagel.yaml so users can opt
entire directory trees out of the file index walk:

  file_index:
    exclude_paths:
      - ~/projects
      - ~/.cache

- ~ / $HOME / %USERPROFILE% are expanded (same logic as base_dirs)
- Paths are normalized with filepath.Clean/filepath.FromSlash so
  trailing separators and Windows paths work correctly
- Empty/whitespace entries in the list are silently ignored
- walkDirectory() returns early when currentDir matches an excluded path
  (exact match or child prefix)
- ExcludePaths is threaded through cache.LoadInput, cache.SaveInput,
  cacheKeyInput, and cache.Metadata so that changing the list correctly
  invalidates stale cache entries; cache SchemaVersion bumped to 4

Adds TestBuildIndex_WithExcludePaths to verify excluded directories are
not indexed while sibling directories still are.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds support for excluding entire directory trees from the file index walk via file_index.exclude_paths in bagel.yaml, and ensures cache entries are invalidated when the exclusion list changes.

Changes:

  • Add ExcludePaths to file index configuration and plumb it through collector → fileindex build and cache load/save.
  • Implement directory-skip logic during the walk based on exact/prefix matches of excluded paths (with expansion/normalization).
  • Extend cache metadata/keying to incorporate ExcludePaths, and add a test covering excluded directories.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
pkg/models/config.go Adds exclude_paths to FileIndexConfig YAML/mapstructure model.
pkg/fileindex/fileindex.go Normalizes excludes and skips excluded directories during traversal.
pkg/fileindex/fileindex_test.go Adds test verifying excluded directories are not indexed.
pkg/collector/collector.go Passes config ExcludePaths into index build and cache operations.
pkg/cache/cache.go Includes ExcludePaths in cache schema/metadata and cache-key computation.
CLA_SIGNATURES.md Adds a CLA signature entry and fixes formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- TrimSpace before expandHomeDir so entries like ' ~/repos ' expand
  the ~ prefix correctly instead of being passed through unexpanded
- Replace HasPrefix child-path check with filepath.Rel so that
  excluding a root or volume-root path (e.g. '/') correctly excludes
  all descendants without the '//'-prefix false-negative
- Add normalizeExcludePaths helper to cache package (TrimSpace, skip
  empty, expandPath, filepath.Clean/FromSlash) and use it in Load,
  Save, and computeCacheKey so cache keys and metadata are stable and
  consistent with BuildIndex normalization
@tveronezi tveronezi marked this pull request as ready for review March 23, 2026 22:21
@SUSTAPLE117 SUSTAPLE117 merged commit 3342321 into main Mar 26, 2026
6 checks passed
@SUSTAPLE117 SUSTAPLE117 deleted the feat-file-index-exclude-paths branch March 26, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants