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/// Name of the workspace-local ignore file that mirrors `.gitignore` semantics
7/// but only affects VT Code's own file operations.
8///
9/// Registered as a custom ignore filename on every traversal walker so the
10/// same patterns prune the file picker, grep/list tools, and the indexer.
11pub const VTCODE_IGNORE_FILE: &str = ".vtcodegitignore";
12
13/// Directories skipped by default during workspace traversal.
14///
15/// This covers build artifacts, dependency stores, VCS metadata, and IDE
16/// configuration directories that are almost never relevant to code search
17/// or analysis.
18pub const DEFAULT_EXCLUDED_DIRS: &[&str] = &[
19    ".git",
20    "node_modules",
21    "target",
22    "dist",
23    ".next",
24    "vendor",
25    ".cursor",
26    ".vtcode",
27    ".vscode",
28    ".idea",
29];
30
31/// Sensitive files that must never be exposed in listings, search results,
32/// or the TUI file palette.  These contain secrets, credentials, or
33/// environment-specific configuration.
34pub const SENSITIVE_FILES: &[&str] = &[
35    ".env",
36    ".env.local",
37    ".env.production",
38    ".env.development",
39    ".env.test",
40    ".DS_Store",
41    ".git-credentials",
42    ".netrc",
43    ".npmrc",
44    ".pypirc",
45    "credentials",
46    "credentials.json",
47    "id_dsa",
48    "id_ecdsa",
49    "id_ecdsa_sk",
50    "id_ed25519",
51    "id_ed25519_sk",
52    "id_mldsa44_ed25519",
53    "id_rsa",
54];
55
56/// Glob patterns passed to ripgrep (or other search back-ends) to exclude
57/// noisy vendor/build directories from results.
58pub const DEFAULT_IGNORE_GLOBS: &[&str] = &[
59    "**/.git/**",
60    "**/node_modules/**",
61    "**/target/**",
62    "**/.cursor/**",
63    "**/dist/**",
64    "**/.next/**",
65    "**/vendor/**",
66    "**/.vtcode/**",
67    "**/.vscode/**",
68    "**/.idea/**",
69];
70
71/// Returns `true` if `name` matches any entry in [`SENSITIVE_FILES`] or
72/// starts with `.env.` (catches all dotenv variants). Matching is
73/// case-insensitive because macOS and Windows commonly use case-insensitive
74/// filesystems.
75pub fn is_sensitive_file(name: &str) -> bool {
76    SENSITIVE_FILES.iter().any(|sensitive| name.eq_ignore_ascii_case(sensitive))
77        || name.get(..5).is_some_and(|prefix| prefix.eq_ignore_ascii_case(".env."))
78}
79
80#[cfg(test)]
81mod tests {
82    use super::is_sensitive_file;
83
84    #[test]
85    fn sensitive_file_matching_is_case_insensitive() {
86        assert!(is_sensitive_file(".ENV"));
87        assert!(is_sensitive_file(".Env.Local"));
88        assert!(is_sensitive_file(".NPMRC"));
89        assert!(!is_sensitive_file(".environment"));
90    }
91
92    #[test]
93    fn ssh_private_key_basenames_are_sensitive() {
94        assert!(is_sensitive_file("id_dsa"));
95        assert!(is_sensitive_file("id_ecdsa"));
96        assert!(is_sensitive_file("ID_ECDSA"));
97        assert!(!is_sensitive_file("id_ecdsa.pub"));
98    }
99
100    #[test]
101    fn post_quantum_and_fido_ssh_private_keys_are_sensitive() {
102        assert!(is_sensitive_file("id_mldsa44_ed25519"));
103        assert!(is_sensitive_file("ID_MLDSA44_ED25519"));
104        assert!(is_sensitive_file("id_ecdsa_sk"));
105        assert!(is_sensitive_file("id_ed25519_sk"));
106        assert!(!is_sensitive_file("id_mldsa44_ed25519.pub"));
107    }
108}