Skip to main content

vtcode_commons/
exclusions.rs

1//! Centralized exclusion constants and helpers for file traversal.
2//!
3//! All directory walkers, grep invocations, and file-operation tools should
4//! reference these constants instead of maintaining their own skip lists.
5
6/// Directories skipped by default during workspace traversal.
7///
8/// This covers build artifacts, dependency stores, VCS metadata, and IDE
9/// configuration directories that are almost never relevant to code search
10/// or analysis.
11pub const DEFAULT_EXCLUDED_DIRS: &[&str] = &[
12    ".git",
13    "node_modules",
14    "target",
15    "dist",
16    ".next",
17    "vendor",
18    ".cursor",
19    ".vtcode",
20    ".vscode",
21    ".idea",
22];
23
24/// Sensitive files that must never be exposed in listings, search results,
25/// or the TUI file palette.  These contain secrets, credentials, or
26/// environment-specific configuration.
27pub const SENSITIVE_FILES: &[&str] = &[
28    ".env",
29    ".env.local",
30    ".env.production",
31    ".env.development",
32    ".env.test",
33    ".DS_Store",
34    ".git-credentials",
35    ".netrc",
36    ".npmrc",
37    ".pypirc",
38    "credentials",
39    "credentials.json",
40    "id_dsa",
41    "id_ecdsa",
42    "id_ed25519",
43    "id_rsa",
44];
45
46/// Glob patterns passed to ripgrep (or other search back-ends) to exclude
47/// noisy vendor/build directories from results.
48pub const DEFAULT_IGNORE_GLOBS: &[&str] = &[
49    "**/.git/**",
50    "**/node_modules/**",
51    "**/target/**",
52    "**/.cursor/**",
53    "**/dist/**",
54    "**/.next/**",
55    "**/vendor/**",
56    "**/.vtcode/**",
57    "**/.vscode/**",
58    "**/.idea/**",
59];
60
61/// Returns `true` if `name` matches any entry in [`SENSITIVE_FILES`] or
62/// starts with `.env.` (catches all dotenv variants). Matching is
63/// case-insensitive because macOS and Windows commonly use case-insensitive
64/// filesystems.
65pub fn is_sensitive_file(name: &str) -> bool {
66    SENSITIVE_FILES.iter().any(|sensitive| name.eq_ignore_ascii_case(sensitive))
67        || name.get(..5).is_some_and(|prefix| prefix.eq_ignore_ascii_case(".env."))
68}
69
70#[cfg(test)]
71mod tests {
72    use super::is_sensitive_file;
73
74    #[test]
75    fn sensitive_file_matching_is_case_insensitive() {
76        assert!(is_sensitive_file(".ENV"));
77        assert!(is_sensitive_file(".Env.Local"));
78        assert!(is_sensitive_file(".NPMRC"));
79        assert!(!is_sensitive_file(".environment"));
80    }
81
82    #[test]
83    fn ssh_private_key_basenames_are_sensitive() {
84        assert!(is_sensitive_file("id_dsa"));
85        assert!(is_sensitive_file("id_ecdsa"));
86        assert!(is_sensitive_file("ID_ECDSA"));
87        assert!(!is_sensitive_file("id_ecdsa.pub"));
88    }
89}