MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / analyze_snapshot

Function analyze_snapshot

libatomic/src/review/analysis.rs:152–231  ·  view source on GitHub ↗

Inspect each supplied live path once, using the exact named-view renderer.

(
    repo: &Repository,
    view: &str,
    reference: &str,
    paths: &[String],
)

Source from the content-addressed store, hash-verified

150
151/// Inspect each supplied live path once, using the exact named-view renderer.
152pub(super) fn analyze_snapshot(
153 repo: &Repository,
154 view: &str,
155 reference: &str,
156 paths: &[String],
157) -> Result<(AnalysisReport, BTreeMap<String, String>), atomic_repository::RepositoryError> {
158 let mut report = empty_report();
159 let mut registry = ParserRegistry::new();
160 let mut files = Vec::new();
161 let mut eligible = Vec::new();
162 // Whole-view mode must not inherit the per-change 128-file/8-MiB limits.
163 // Cross-file clone work and all other limits remain explicit and bounded.
164 let config = ExtractionConfig {
165 max_files: paths.len(),
166 max_total_bytes: 128 * 1024 * 1024,
167 max_total_tokens: 2_000_000,
168 max_total_subjects: 65_536,
169 max_clone_pairs: 2_000_000,
170 ..Default::default()
171 };
172 let mut remaining = config.max_total_bytes;
173 let mut content_hashes = BTreeMap::new();
174 for path in paths {
175 if atomic_repository::is_vault_path(path) {
176 report.excluded_metadata_paths.push(path.clone());
177 } else if Language::detect(path).is_none() {
178 let reason = "Unsupported language; no structural or anti-slop rules executed";
179 checks(&mut report, reference, path, CheckStatus::Skipped, reason);
180 files.push(FileChange {
181 path: path.clone(),
182 before: Source::Unavailable(SNAPSHOT_BASELINE.into()),
183 after: Source::Unavailable(reason.into()),
184 });
185 } else {
186 eligible.push(path.clone());
187 }
188 }
189 repo.for_each_file_content_and_kind_on_view(&eligible, view, |path, bytes, kind| {
190 let bytes = bytes.ok_or_else(|| atomic_repository::RepositoryError::Output(format!("Recorded view source disappeared while inspecting '{path}'")))?;
191 let reason = if kind != Some(atomic_core::change::InodeKind::Regular) {
192 Some("Recorded symlink/non-regular source is not followed or audited as code")
193 } else if bytes.len() > atomic_semantic::MAX_SOURCE_BYTES || bytes.len() > remaining {
194 Some("View snapshot source budget exceeded (1 MiB per file, 128 MiB total); source not silently truncated")
195 } else { None };
196 let after = if let Some(reason) = reason {
197 checks(&mut report, reference, path, CheckStatus::Skipped, reason);
198 Source::Unavailable(reason.into())
199 } else {
200 remaining -= bytes.len();
201 content_hashes.insert(path.to_string(), Hash::of(&bytes).to_base32());
202 match parse(&mut registry, path, &bytes) {
203 Ok(parsed) => inspect_parsed(&mut report, reference, path, parsed, Err(SNAPSHOT_BASELINE.into()), true),
204 Err(reason) => checks(&mut report, reference, path, CheckStatus::Skipped, &reason),
205 }
206 Source::from_bytes(bytes)
207 };
208 // Treat every current token as in scope for the whole-view clone scan.
209 // Restore the unavailable historical baseline below; no change delta is

Callers 1

collectFunction · 0.85

Calls 14

empty_reportFunction · 0.85
checksFunction · 0.85
inspect_parsedFunction · 0.85
extract_changesFunction · 0.85
is_noneMethod · 0.80
parseFunction · 0.70
is_vault_pathFunction · 0.50
lenMethod · 0.45
pushMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected