Skip to main content

weavatrix_scan/config/
mod.rs

1use crate::control::CancellationToken;
2use crate::file_types::{FileTypeMatch, NamedFileTypes};
3use crate::walk_types::WalkOptions;
4use std::collections::BTreeSet;
5use std::ffi::OsStr;
6use std::path::Path;
7use std::time::Duration;
8
9mod builder;
10mod ignore_policy;
11mod limits;
12mod runtime;
13mod walk;
14
15pub use ignore_policy::IgnorePolicy;
16pub use limits::ScanLimits;
17
18const DEFAULT_MAX_FILE_BYTES: u64 = 1_500_000;
19const DEFAULT_IGNORE_FILES: &[&str] = &[".gitignore", ".ignore", ".weavatrixignore"];
20const DEFAULT_SKIP_DIRECTORIES: &[&str] = &[
21    ".git",
22    ".hg",
23    ".svn",
24    ".venv",
25    "__pycache__",
26    "build",
27    "coverage",
28    "dist",
29    "node_modules",
30    "target",
31    "vendor",
32];
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum StandardSkips {
36    Enabled,
37    Disabled,
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum EvidenceMode {
42    Complete,
43    SelectedFiles,
44}
45
46/// Controls how persistent content hashes are validated before reuse.
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
48pub enum CacheValidationPolicy {
49    /// Trust stable size, timestamp and available native identity evidence.
50    Fast,
51    /// Read a whole-file 128-bit fingerprint before reusing the prior SHA-256.
52    Strict,
53}
54
55/// Controls post-read snapshot verification for newly opened content.
56#[derive(Debug, Clone, Copy, PartialEq, Eq)]
57pub enum ContentValidationPolicy {
58    /// Verify the opened handle against discovery evidence before reading.
59    /// This is appropriate for latency-sensitive local search.
60    Fast,
61    /// Also re-check native file evidence after reading to reject concurrent
62    /// same-size modifications.
63    Strict,
64}
65
66/// Controls how content candidates are discovered before bounded file reads.
67#[derive(Debug, Clone, Copy, PartialEq, Eq)]
68pub enum ContentDiscoveryMode {
69    /// Discover candidates serially and overlap discovery with content reads.
70    ///
71    /// This keeps memory bounded independently of the number of files.
72    Streaming,
73    /// Discover candidates with the parallel walker, retain their compact path
74    /// evidence, then dispatch bounded content reads.
75    ///
76    /// This minimizes latency on large, warm repositories at the cost of
77    /// memory proportional to the number of selected files.
78    BufferedParallel,
79}
80
81#[derive(Debug, Clone)]
82#[allow(clippy::struct_excessive_bools)]
83pub struct ScanOptions {
84    pub max_file_bytes: u64,
85    pub extensions: BTreeSet<String>,
86    /// Reusable named file-pattern groups, combined with `extensions`.
87    pub file_types: NamedFileTypes,
88    pub ignore_files: Vec<String>,
89    /// High-precedence include/exclude globs using `ignore::Override` syntax.
90    pub override_rules: Vec<String>,
91    /// Controls parent, repository-exclude and global Git ignore sources.
92    pub ignore_policy: IgnorePolicy,
93    /// Match ignore patterns without ASCII case sensitivity.
94    pub ignore_case_insensitive: bool,
95    /// Skip dot-prefixed and native Windows-hidden entries unless included.
96    pub skip_hidden: bool,
97    pub standard_skips: StandardSkips,
98    pub hash_file_contents: bool,
99    pub detect_binary_files: bool,
100    /// Record typed evidence for entries excluded by policy.
101    pub evidence: EvidenceMode,
102    /// Traversal and content-inspection workers. Zero selects available
103    /// parallelism. Retained as the shared backward-compatible default.
104    pub parallelism: usize,
105    /// Optional traversal-only worker override. `Some(0)` selects available
106    /// parallelism independently of content inspection.
107    pub traversal_parallelism: Option<usize>,
108    /// Optional content-inspection worker override. `Some(0)` selects
109    /// available parallelism independently of traversal.
110    pub content_parallelism: Option<usize>,
111    /// Whole-scan resource bounds. All limits are disabled by default.
112    pub limits: ScanLimits,
113    /// Optional cooperative cancellation signal.
114    pub cancellation: Option<CancellationToken>,
115    /// Persistent hash validation policy.
116    pub cache_validation: CacheValidationPolicy,
117    /// New content-read validation policy.
118    pub content_validation: ContentValidationPolicy,
119    /// Candidate-discovery policy for content visits.
120    pub content_discovery: ContentDiscoveryMode,
121    /// Low-level traversal policy.
122    pub walk: WalkOptions,
123}
124
125impl Default for ScanOptions {
126    fn default() -> Self {
127        Self {
128            max_file_bytes: DEFAULT_MAX_FILE_BYTES,
129            extensions: BTreeSet::new(),
130            file_types: NamedFileTypes::default(),
131            ignore_files: DEFAULT_IGNORE_FILES
132                .iter()
133                .map(ToString::to_string)
134                .collect(),
135            override_rules: Vec::new(),
136            ignore_policy: IgnorePolicy::default(),
137            ignore_case_insensitive: false,
138            skip_hidden: false,
139            standard_skips: StandardSkips::Enabled,
140            hash_file_contents: true,
141            detect_binary_files: true,
142            evidence: EvidenceMode::Complete,
143            parallelism: 0,
144            traversal_parallelism: None,
145            content_parallelism: None,
146            limits: ScanLimits::default(),
147            cancellation: None,
148            cache_validation: CacheValidationPolicy::Fast,
149            content_validation: ContentValidationPolicy::Strict,
150            content_discovery: ContentDiscoveryMode::Streaming,
151            walk: WalkOptions::default().with_metadata(true),
152        }
153    }
154}