From 17a5e31ab2f9c560f56b46d774230ddb91484864 Mon Sep 17 00:00:00 2001 From: "Anaz S. Aji" <12648688+ajianaz@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:14:36 +0000 Subject: [PATCH 1/2] refactor: remove the unused file bundling engine Closes #792. --- CHANGELOG.md | 1 + docs/configuration.md | 2 +- docs/roadmap.md | 2 +- src/engine/bundling/grouping.rs | 625 -------------------------------- src/engine/bundling/mod.rs | 36 +- src/engine/bundling/types.rs | 343 +----------------- src/engine/context/types.rs | 6 +- src/engine/diff_parser.rs | 45 --- src/index/ast.rs | 2 +- 9 files changed, 17 insertions(+), 1045 deletions(-) delete mode 100644 src/engine/bundling/grouping.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f2b9b76..eb9535fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - **The build without Tree-sitter compiles again, and CI keeps it that way (#793).** `cargo build --no-default-features` (regex extraction only, documented in the README) failed because the edge types lived in the Tree-sitter module; they are shared now. Running its tests showed that the regex extractor skipped `pub(crate)`, `pub(super)` and `pub(in ..)` items and read `const fn name` as a constant called `fn`; both are fixed. CI lints and tests this configuration in the `Check` job. +- **The unused file bundling engine is removed (#792).** About 1,100 lines of directory and language grouping for LLM batches were never called by `cora review` or `cora scan`, although the roadmap called the feature done and `.cora.yaml` has a `bundling:` section. The engine, `extract_added_lines` and the data types only it used are gone; the `bundling:` keys are still accepted (they never had an effect) so an existing config keeps loading, and the docs and the roadmap say so. Large diffs are split by `review.max_chunk_chars`. - **`cora dead-code`, `callers` and `impact` see functions passed as values and functions named in serde attributes (#802).** The Rust extractor recorded a call only for a `call_expression` and inside macros, so `.map(helper)`, `.and_then(Type::make)` and `#[serde(default = "default_true")]` made the function look unused. On this repository `cora dead-code` went from 43 findings, none of them dead code, to the 5 that are (the unwired bundling engine of #792), and `callers` now lists the function that passes another one as a value. A variable that merely has the name of a function (a parameter, a `let`, a pattern binding) is not recorded. The first `cora index` after the upgrade re-extracts every file once (#803). diff --git a/docs/configuration.md b/docs/configuration.md index 57e98054..84342ce1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -730,7 +730,7 @@ review: ## Bundling -> **Deprecation notice:** as of the current release, `cora scan` does **not** read this section — batch sizing is governed by `--batch-files` (default 20) and an internal ~60,000-character batch budget. These keys are parsed but have no effect on `cora scan`. They are kept for backward compatibility; do not rely on them. +> **Deprecated, no effect:** the file grouping engine these keys configured was never called by `cora review` or `cora scan` and has been removed (#792). The keys are still accepted so an existing `.cora.yaml` keeps loading. Large diffs are split by a character budget (`review.max_chunk_chars`, see [Large Diffs](#large-diffs)); `cora scan` batches by `--batch-files` (default 20) and an internal ~60,000-character budget. ```yaml bundling: diff --git a/docs/roadmap.md b/docs/roadmap.md index ea60ce83..03990011 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -44,7 +44,7 @@ Demand-gated — we build what people actually need. Track progress on [GitHub I ## v0.4 — Deterministic Engine Pipeline - [#116](https://github.com/codecoradev/cora-code/issues/116) Deterministic rule engine — 12 built-in rules — ✓ Done -- [#115](https://github.com/codecoradev/cora-code/issues/115) File bundling — parallel per-bundle review — ✓ Done +- [#115](https://github.com/codecoradev/cora-code/issues/115) File bundling — the grouping engine was written but never wired into review; removed in #792 (large diffs are chunked by a character budget instead, #733) — ✗ Removed - [#114](https://github.com/codecoradev/cora-code/issues/114) AST-based cross-file dependency extraction — ✓ Done - [#159](https://github.com/codecoradev/cora-code/issues/159) Hunk header regex panic fix + 5MB diff support — ✓ Done diff --git a/src/engine/bundling/grouping.rs b/src/engine/bundling/grouping.rs deleted file mode 100644 index 52aaa606..00000000 --- a/src/engine/bundling/grouping.rs +++ /dev/null @@ -1,625 +0,0 @@ -/// Grouping strategies for bundling files into LLM-friendly groups. -use std::collections::HashMap; - -use tracing::debug; - -use crate::engine::scanner::FileEntry; - -use super::types::{BundlingConfig, FileGroup, GroupingKey, GroupingStrategy, LanguageFamily}; - -/// Group files into `FileGroup`s based on the configuration. -/// -/// This is the main entry point for the bundling engine. It dispatches to -/// the appropriate strategy and returns a vector of groups. -pub fn group_files(files: &[FileEntry], config: &BundlingConfig) -> Vec { - if files.is_empty() { - return Vec::new(); - } - - match config.strategy { - GroupingStrategy::Smart => group_smart(files, config), - GroupingStrategy::Flat => group_flat(files, config), - } -} - -/// Smart grouping: coalesce by directory and language within character limits. -/// -/// Algorithm: -/// 1. Compute a `GroupingKey` (directory × language_family) for each file. -/// 2. Sort files by key so related files are adjacent. -/// 3. Greedily pack files into groups, preferring to keep the same key together. -/// 4. When a group is full (char or file limit), start a new one. -fn group_smart(files: &[FileEntry], config: &BundlingConfig) -> Vec { - debug!(total_files = files.len(), "smart grouping files"); - - let max_chars = config.max_chars_per_group; - let max_files = config.max_files_per_group; - - // Build grouping keys for each file - let mut keyed: Vec<(GroupingKey, &FileEntry)> = files - .iter() - .map(|f| { - let ext = f - .path - .rsplit_once('.') - .map(|(_, e)| e) - .filter(|e| !e.contains('/')); - let key = if config.coalesce_by_directory || config.coalesce_by_language { - GroupingKey::from_file(&f.path, ext) - } else { - GroupingKey { - directory: String::new(), - language: LanguageFamily::Other, - } - }; - (key, f) - }) - .collect(); - - // Sort by key to cluster related files - keyed.sort_by(|a, b| { - if config.coalesce_by_directory && config.coalesce_by_language { - a.0.directory - .cmp(&b.0.directory) - .then_with(|| a.0.language.cmp(&b.0.language)) - .then_with(|| a.1.path.cmp(&b.1.path)) - } else if config.coalesce_by_directory { - a.0.directory - .cmp(&b.0.directory) - .then_with(|| a.1.path.cmp(&b.1.path)) - } else if config.coalesce_by_language { - a.0.language - .cmp(&b.0.language) - .then_with(|| a.1.path.cmp(&b.1.path)) - } else { - a.1.path.cmp(&b.1.path) - } - }); - - // Greedy packing with coalescing preference - let mut groups: Vec = Vec::new(); - let mut current_group = FileGroup::new(); - let mut current_key: Option = None; - - for (key, file) in keyed { - let fits = current_group.would_fit(file, max_chars, max_files); - - // If file doesn't fit or we're switching to a very different key, consider - // starting a new group. But only split if we have enough files in the current - // group to justify it (avoid trivial groups). - let should_split = !fits - || (current_key.is_some() - && current_key.as_ref() != Some(&key) - && current_group.len() >= 2 - && would_exceed_threshold(¤t_group, file, max_chars)); - - if should_split && !current_group.is_empty() { - groups.push(std::mem::replace(&mut current_group, FileGroup::new())); - let _ = current_key.take(); - } - - current_group.push(file.clone()); - current_key = Some(key); - } - - if !current_group.is_empty() { - groups.push(current_group); - } - - debug!(groups = groups.len(), "smart grouping complete"); - - groups -} - -/// Check if adding a file would push the group past a "comfort threshold" -/// (75% of max_chars), suggesting it's a good split point. -fn would_exceed_threshold(group: &FileGroup, file: &FileEntry, max_chars: usize) -> bool { - let threshold = (max_chars as f64 * 0.75) as usize; - let cost = FileGroup::file_cost(file); - group.total_chars + cost > threshold -} - -/// Flat grouping: simple first-fit batching by character count. -/// -/// This is the legacy behavior — equivalent to the old `batch_files` function -/// in scanner.rs. Files are processed in order, packed greedily until limits -/// are hit, then a new group starts. -fn group_flat(files: &[FileEntry], config: &BundlingConfig) -> Vec { - debug!(total_files = files.len(), "flat grouping files"); - - let max_chars = config.max_chars_per_group; - let max_files = config.max_files_per_group; - - let mut groups: Vec = Vec::new(); - let mut current_group = FileGroup::new(); - - for file in files { - if !current_group.would_fit(file, max_chars, max_files) && !current_group.is_empty() { - groups.push(std::mem::replace(&mut current_group, FileGroup::new())); - } - current_group.push(file.clone()); - } - - if !current_group.is_empty() { - groups.push(current_group); - } - - debug!(groups = groups.len(), "flat grouping complete"); - - groups -} - -/// Group files by a specific key dimension (directory or language only). -/// -/// This is a helper for more fine-grained grouping when the user only wants -/// one dimension of coalescing. -pub fn group_by_dimension( - files: &[FileEntry], - config: &BundlingConfig, - dimension: GroupingDimension, -) -> Vec { - let max_chars = config.max_chars_per_group; - let max_files = config.max_files_per_group; - - // Bucket files by the chosen dimension - let mut buckets: HashMap> = HashMap::new(); - - for file in files { - let bucket_key = match dimension { - GroupingDimension::Directory => file - .path - .rsplit_once('/') - .or_else(|| file.path.rsplit_once('\\')) - .map(|(dir, _)| dir.to_string()) - .unwrap_or_else(|| ".".to_string()), - GroupingDimension::Language => file - .path - .rsplit_once('.') - .map(|(_, ext)| LanguageFamily::from_extension(ext).to_string()) - .unwrap_or_else(|| "other".to_string()), - }; - buckets.entry(bucket_key).or_default().push(file); - } - - // Sort bucket keys for deterministic output - let mut bucket_keys: Vec = buckets.keys().cloned().collect(); - bucket_keys.sort(); - - // Pack each bucket into groups respecting limits - let mut groups: Vec = Vec::new(); - - for key in bucket_keys { - let bucket_files = &buckets[&key]; - let mut current_group = FileGroup::new(); - - for file in bucket_files { - if !current_group.would_fit(file, max_chars, max_files) && !current_group.is_empty() { - groups.push(std::mem::replace(&mut current_group, FileGroup::new())); - } - current_group.push((*file).clone()); - } - - if !current_group.is_empty() { - groups.push(current_group); - } - } - - groups -} - -/// Dimension to group files by. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum GroupingDimension { - /// Group by parent directory. - Directory, - /// Group by language family. - Language, -} - -/// Merge small groups that could fit together. -/// -/// After initial grouping, some groups may be very small (1-2 files). -/// This post-processing step merges adjacent small groups if their -/// combined size stays within limits. -pub fn merge_small_groups( - mut groups: Vec, - config: &BundlingConfig, - min_group_size: usize, -) -> Vec { - if groups.len() <= 1 { - return groups; - } - - let max_chars = config.max_chars_per_group; - let max_files = config.max_files_per_group; - - let mut merged: Vec = Vec::new(); - let mut accumulator = groups.remove(0); - - for group in groups { - // Merge if both groups are small and combined fits - if accumulator.len() < min_group_size - && group.len() < min_group_size - && accumulator.len() + group.len() <= max_files - && accumulator.total_chars + group.total_chars <= max_chars - { - for file in group.files { - accumulator.push(file); - } - } else { - merged.push(std::mem::replace(&mut accumulator, group)); - } - } - - if !accumulator.is_empty() { - merged.push(accumulator); - } - - merged -} - -/// Collect statistics about the grouping result. -#[derive(Debug, Clone)] -pub struct GroupingStats { - /// Total number of groups. - pub group_count: usize, - /// Total number of files across all groups. - pub total_files: usize, - /// Total characters across all groups. - pub total_chars: usize, - /// Average files per group. - pub avg_files_per_group: f64, - /// Average characters per group. - pub avg_chars_per_group: f64, - /// Number of groups with only 1 file. - pub single_file_groups: usize, -} - -impl GroupingStats { - /// Compute stats from a list of groups. - pub fn from_groups(groups: &[FileGroup]) -> Self { - let group_count = groups.len(); - let total_files: usize = groups.iter().map(|g| g.len()).sum(); - let total_chars: usize = groups.iter().map(|g| g.total_chars).sum(); - let single_file_groups = groups.iter().filter(|g| g.len() == 1).count(); - - Self { - group_count, - total_files, - total_chars, - avg_files_per_group: if group_count > 0 { - total_files as f64 / group_count as f64 - } else { - 0.0 - }, - avg_chars_per_group: if group_count > 0 { - total_chars as f64 / group_count as f64 - } else { - 0.0 - }, - single_file_groups, - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - fn make_file(path: &str, content_len: usize) -> FileEntry { - FileEntry { - path: path.to_string(), - content: "x".repeat(content_len), - lines: content_len, - } - } - - fn default_config() -> BundlingConfig { - BundlingConfig::default() - } - - // ─── group_files dispatch ─── - - #[test] - fn group_files_empty() { - let groups = group_files(&[], &default_config()); - assert!(groups.is_empty()); - } - - // ─── Flat grouping ─── - - #[test] - fn flat_grouping_basic() { - let files = vec![ - make_file("a.rs", 100), - make_file("b.rs", 100), - make_file("c.rs", 100), - ]; - let config = BundlingConfig { - max_chars_per_group: 250, // fits ~2 files per group - max_files_per_group: 100, - strategy: GroupingStrategy::Flat, - ..Default::default() - }; - - let groups = group_files(&files, &config); - assert!(groups.len() >= 2, "should split into at least 2 groups"); - assert_eq!( - groups.iter().map(|g| g.len()).sum::(), - 3, - "all files should be assigned" - ); - } - - #[test] - fn flat_grouping_all_fit() { - let files = vec![make_file("a.rs", 10), make_file("b.rs", 10)]; - let config = BundlingConfig { - strategy: GroupingStrategy::Flat, - ..Default::default() - }; - - let groups = group_files(&files, &config); - assert_eq!(groups.len(), 1); - assert_eq!(groups[0].len(), 2); - } - - #[test] - fn flat_grouping_preserves_order() { - let files = vec![ - make_file("a.rs", 10), - make_file("b.rs", 10), - make_file("c.rs", 10), - ]; - let config = BundlingConfig { - strategy: GroupingStrategy::Flat, - ..Default::default() - }; - - let groups = group_files(&files, &config); - assert_eq!(groups.len(), 1); - assert_eq!(groups[0].files[0].path, "a.rs"); - assert_eq!(groups[0].files[1].path, "b.rs"); - assert_eq!(groups[0].files[2].path, "c.rs"); - } - - #[test] - fn flat_grouping_max_files_limit() { - let files = vec![ - make_file("a.rs", 10), - make_file("b.rs", 10), - make_file("c.rs", 10), - make_file("d.rs", 10), - ]; - let config = BundlingConfig { - strategy: GroupingStrategy::Flat, - max_files_per_group: 2, - max_chars_per_group: 1_000_000, - ..Default::default() - }; - - let groups = group_files(&files, &config); - assert_eq!(groups.len(), 2); - assert_eq!(groups[0].len(), 2); - assert_eq!(groups[1].len(), 2); - } - - // ─── Smart grouping ─── - - #[test] - fn smart_grouping_clusters_same_directory() { - let files = vec![ - make_file("src/engine/mod.rs", 100), - make_file("src/engine/types.rs", 100), - make_file("src/config/mod.rs", 100), - make_file("tests/integration.rs", 100), - ]; - let config = BundlingConfig { - strategy: GroupingStrategy::Smart, - coalesce_by_directory: true, - coalesce_by_language: false, - ..Default::default() - }; - - let groups = group_files(&files, &config); - // Should cluster src/engine files together and src/config + tests may be separate - assert_eq!( - groups.iter().map(|g| g.len()).sum::(), - 4, - "all files assigned" - ); - } - - #[test] - fn smart_grouping_clusters_same_language() { - let files = vec![ - make_file("src/main.rs", 100), - make_file("lib/api.py", 100), - make_file("src/lib.rs", 100), - make_file("scripts/deploy.py", 100), - ]; - let config = BundlingConfig { - strategy: GroupingStrategy::Smart, - coalesce_by_directory: false, - coalesce_by_language: true, - ..Default::default() - }; - - let groups = group_files(&files, &config); - // Rust files should cluster together, Python files together - assert_eq!( - groups.iter().map(|g| g.len()).sum::(), - 4, - "all files assigned" - ); - } - - #[test] - fn smart_grouping_respects_char_limit() { - let files = vec![ - make_file("src/a.rs", 10_000), - make_file("src/b.rs", 10_000), - make_file("src/c.rs", 10_000), - ]; - let config = BundlingConfig { - strategy: GroupingStrategy::Smart, - max_chars_per_group: 15_000, - max_files_per_group: 100, - ..Default::default() - }; - - let groups = group_files(&files, &config); - assert!(groups.len() >= 2, "should split into at least 2 groups"); - } - - // ─── merge_small_groups ─── - - #[test] - fn merge_small_groups_basic() { - let g1 = { - let mut g = FileGroup::new(); - g.push(make_file("a.rs", 10)); - g - }; - let g2 = { - let mut g = FileGroup::new(); - g.push(make_file("b.rs", 10)); - g - }; - let g3 = { - let mut g = FileGroup::new(); - g.push(make_file("c.rs", 10)); - g - }; - - let merged = merge_small_groups(vec![g1, g2, g3], &default_config(), 2); - // All groups have 1 file (< min_group_size=2), so they should be merged - assert!(merged.len() <= 2, "should merge small groups"); - assert_eq!( - merged.iter().map(|g| g.len()).sum::(), - 3, - "no files lost" - ); - } - - #[test] - fn merge_small_groups_respects_limits() { - let g1 = { - let mut g = FileGroup::new(); - g.push(make_file("a.rs", 30_000)); - g - }; - let g2 = { - let mut g = FileGroup::new(); - g.push(make_file("b.rs", 30_000)); - g - }; - - let config = BundlingConfig { - max_chars_per_group: 50_000, - ..Default::default() - }; - let merged = merge_small_groups(vec![g1, g2], &config, 2); - // 30k + 30k = 60k > 50k, should not merge - assert_eq!(merged.len(), 2); - } - - // ─── group_by_dimension ─── - - #[test] - fn group_by_directory() { - let files = vec![ - make_file("src/engine/mod.rs", 10), - make_file("src/engine/types.rs", 10), - make_file("src/config/mod.rs", 10), - ]; - let groups = group_by_dimension(&files, &default_config(), GroupingDimension::Directory); - // Should have at least 2 groups: src/engine and src/config - assert!(groups.len() >= 2); - } - - #[test] - fn group_by_language() { - let files = vec![ - make_file("src/main.rs", 10), - make_file("src/app.py", 10), - make_file("src/lib.rs", 10), - ]; - let groups = group_by_dimension(&files, &default_config(), GroupingDimension::Language); - // Should have at least 2 groups: Rust and Python - assert!(groups.len() >= 2); - } - - // ─── GroupingStats ─── - - #[test] - fn grouping_stats_empty() { - let stats = GroupingStats::from_groups(&[]); - assert_eq!(stats.group_count, 0); - assert_eq!(stats.total_files, 0); - assert_eq!(stats.total_chars, 0); - assert_eq!(stats.single_file_groups, 0); - } - - #[test] - fn grouping_stats_computed() { - let g1 = { - let mut g = FileGroup::new(); - g.push(make_file("a.rs", 100)); - g.push(make_file("b.rs", 100)); - g - }; - let g2 = { - let mut g = FileGroup::new(); - g.push(make_file("c.rs", 50)); - g - }; - - let stats = GroupingStats::from_groups(&[g1, g2]); - assert_eq!(stats.group_count, 2); - assert_eq!(stats.total_files, 3); - assert_eq!(stats.single_file_groups, 1); - assert!((stats.avg_files_per_group - 1.5).abs() < 0.01); - } - - // ─── Smart grouping with both coalesce off ─── - - #[test] - fn smart_grouping_no_coalesce_is_like_flat() { - let files = vec![ - make_file("z.rs", 10), - make_file("a.rs", 10), - make_file("m.rs", 10), - ]; - let config = BundlingConfig { - strategy: GroupingStrategy::Smart, - coalesce_by_directory: false, - coalesce_by_language: false, - ..Default::default() - }; - - let groups = group_files(&files, &config); - assert_eq!(groups.len(), 1); - // Without coalescing, files are sorted by path - assert_eq!(groups[0].files[0].path, "a.rs"); - assert_eq!(groups[0].files[1].path, "m.rs"); - assert_eq!(groups[0].files[2].path, "z.rs"); - } - - // ─── Single large file ─── - - #[test] - fn single_large_file_gets_own_group() { - let files = vec![make_file("huge.rs", 200_000)]; - let config = BundlingConfig { - strategy: GroupingStrategy::Smart, - max_chars_per_group: 50_000, - max_files_per_group: 10, - ..Default::default() - }; - - let groups = group_files(&files, &config); - assert_eq!(groups.len(), 1); - assert_eq!(groups[0].len(), 1); - } -} diff --git a/src/engine/bundling/mod.rs b/src/engine/bundling/mod.rs index 419b93ea..d69e7a63 100644 --- a/src/engine/bundling/mod.rs +++ b/src/engine/bundling/mod.rs @@ -1,34 +1,8 @@ -/// File bundling engine — groups files into cohesive units for LLM review. -/// -/// Instead of arbitrary batching by character count alone, the bundling engine -/// groups related files together (by directory, language, or both) to provide -/// better review context to the LLM. -/// -/// # Configuration -/// -/// Controlled via `BundlingConfig` (on `Config`): -/// - `strategy`: `"smart"` (coalesce by directory/language) or `"flat"` (legacy) -/// - `max_chars_per_group`: character budget per group -/// - `max_files_per_group`: file count limit per group -/// - `coalesce_by_directory`: prefer keeping same-directory files together -/// - `coalesce_by_language`: prefer keeping same-language files together -/// -/// # Usage -/// -/// ```ignore -/// use crate::engine::bundling::{group_files, types::BundlingConfig}; -/// -/// let config = BundlingConfig::default(); -/// let groups = group_files(&files, &config); -/// for group in groups { -/// let content = crate::engine::scanner::format_batch_for_prompt(&group.files); -/// // send content to LLM -/// } -/// ``` -// The grouping engine is not called by review yet (#792). -#[allow(dead_code)] -pub mod grouping; -#[allow(dead_code)] +//! Deprecated `bundling:` configuration (no effect, kept so existing configs load). +//! +//! The file grouping engine that used it was removed in #792: review splits a large +//! diff by a character budget (`review.max_chunk_chars`), not by directory or language. + pub mod types; pub use types::GroupingStrategy; diff --git a/src/engine/bundling/types.rs b/src/engine/bundling/types.rs index a0d7a2fb..cfc71a37 100644 --- a/src/engine/bundling/types.rs +++ b/src/engine/bundling/types.rs @@ -1,4 +1,8 @@ -/// Bundling types — configuration and data structures for file grouping. +//! The `bundling:` section of `.cora.yaml`. +//! +//! The grouping engine these keys once configured was never called by review or +//! scan and is gone (#792); the keys are still parsed so an existing `.cora.yaml` +//! keeps loading, and they have no effect. use serde::{Deserialize, Serialize}; /// Runtime configuration for the file bundling engine (lives on `Config`). @@ -72,175 +76,10 @@ impl std::fmt::Display for GroupingStrategy { } } -/// A group of files to be reviewed together in a single LLM call. -/// -/// Each group is a coherent unit — ideally files that are related by -/// directory, language, or feature area — kept within character and file -/// count limits. -#[derive(Debug, Clone)] -pub struct FileGroup { - /// Files in this group. - pub files: Vec, - /// Total character count (content + path headers + line numbers). - pub total_chars: usize, -} - -impl FileGroup { - /// Create a new empty group. - pub fn new() -> Self { - Self { - files: Vec::new(), - total_chars: 0, - } - } - - /// Estimated character size for a single file entry (content + header overhead). - pub fn file_cost(file: &crate::engine::scanner::FileEntry) -> usize { - file.content.len() + file.path.len() + 20 // header overhead - } - - /// Check if adding a file would exceed the limits. - pub fn would_fit( - &self, - file: &crate::engine::scanner::FileEntry, - max_chars: usize, - max_files: usize, - ) -> bool { - if self.files.len() >= max_files { - return false; - } - let cost = Self::file_cost(file); - // Allow first file even if it exceeds max_chars (single large file) - if self.files.is_empty() { - return true; - } - self.total_chars + cost <= max_chars - } - - /// Add a file to the group. - pub fn push(&mut self, file: crate::engine::scanner::FileEntry) { - self.total_chars += Self::file_cost(&file); - self.files.push(file); - } - - /// Number of files in the group. - pub fn len(&self) -> usize { - self.files.len() - } - - /// Whether the group is empty. - pub fn is_empty(&self) -> bool { - self.files.is_empty() - } -} - -/// Language family classification for grouping. -/// -/// Files with extensions in the same family are preferred to be grouped together, -/// as they often belong to the same project layer. -#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] -pub enum LanguageFamily { - /// Rust (rs) - Rust, - /// JavaScript/TypeScript (js, ts, tsx, jsx, mjs, cjs) - JavaScript, - /// Python (py, pyi) - Python, - /// Go (go, mod, sum) - Go, - /// Java/JVM (java, kt, scala, gradle) - Jvm, - /// Web (html, css, scss, less, vue, svelte) - Web, - /// C/C++ (c, cpp, h, hpp, cc, cxx) - CFamily, - /// Shell (sh, bash, zsh, ps1) - Shell, - /// Config (yaml, yml, json, toml, ini) - Config, - /// Documentation (md, rst, txt, adoc) - Documentation, - /// Database (sql, graphql, proto) - Database, - /// Other / unclassified - Other, -} - -impl LanguageFamily { - /// Classify a file extension into a language family. - pub fn from_extension(ext: &str) -> Self { - match ext.to_lowercase().as_str() { - "rs" => LanguageFamily::Rust, - "js" | "ts" | "tsx" | "jsx" | "mjs" | "cjs" => LanguageFamily::JavaScript, - "py" | "pyi" => LanguageFamily::Python, - "go" | "mod" | "sum" => LanguageFamily::Go, - "java" | "kt" | "scala" | "gradle" => LanguageFamily::Jvm, - "html" | "css" | "scss" | "less" | "vue" | "svelte" => LanguageFamily::Web, - "c" | "cpp" | "h" | "hpp" | "cc" | "cxx" => LanguageFamily::CFamily, - "sh" | "bash" | "zsh" | "ps1" => LanguageFamily::Shell, - "yaml" | "yml" | "json" | "toml" | "ini" => LanguageFamily::Config, - "md" | "rst" | "txt" | "adoc" => LanguageFamily::Documentation, - "sql" | "graphql" | "proto" => LanguageFamily::Database, - _ => LanguageFamily::Other, - } - } -} - -impl std::fmt::Display for LanguageFamily { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - LanguageFamily::Rust => write!(f, "rust"), - LanguageFamily::JavaScript => write!(f, "javascript"), - LanguageFamily::Python => write!(f, "python"), - LanguageFamily::Go => write!(f, "go"), - LanguageFamily::Jvm => write!(f, "jvm"), - LanguageFamily::Web => write!(f, "web"), - LanguageFamily::CFamily => write!(f, "c_family"), - LanguageFamily::Shell => write!(f, "shell"), - LanguageFamily::Config => write!(f, "config"), - LanguageFamily::Documentation => write!(f, "documentation"), - LanguageFamily::Database => write!(f, "database"), - LanguageFamily::Other => write!(f, "other"), - } - } -} - -/// Key used for grouping files together. -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct GroupingKey { - /// The parent directory of the file (relative to project root). - pub directory: String, - /// The language family of the file. - pub language: LanguageFamily, -} - -impl GroupingKey { - /// Create a grouping key from a file path and extension. - pub fn from_file(path: &str, extension: Option<&str>) -> Self { - let directory = path - .rsplit_once('/') - .or_else(|| path.rsplit_once('\\')) - .map(|(dir, _)| dir.to_string()) - .unwrap_or_else(|| ".".to_string()); - - let language = extension - .map(LanguageFamily::from_extension) - .unwrap_or(LanguageFamily::Other); - - Self { - directory, - language, - } - } -} - #[cfg(test)] mod tests { use super::*; - // ─── BundlingConfig defaults ─── - #[test] fn bundling_config_default() { let cfg = BundlingConfig::default(); @@ -251,184 +90,12 @@ mod tests { assert!(cfg.coalesce_by_language); } - // ─── GroupingStrategy display ─── - #[test] fn grouping_strategy_display() { assert_eq!(format!("{}", GroupingStrategy::Smart), "smart"); assert_eq!(format!("{}", GroupingStrategy::Flat), "flat"); } - // ─── LanguageFamily classification ─── - - #[test] - fn language_family_rust() { - assert_eq!(LanguageFamily::from_extension("rs"), LanguageFamily::Rust); - assert_eq!( - LanguageFamily::from_extension("toml"), - LanguageFamily::Config - ); - } - - #[test] - fn language_family_javascript() { - assert_eq!( - LanguageFamily::from_extension("js"), - LanguageFamily::JavaScript - ); - assert_eq!( - LanguageFamily::from_extension("ts"), - LanguageFamily::JavaScript - ); - assert_eq!( - LanguageFamily::from_extension("tsx"), - LanguageFamily::JavaScript - ); - assert_eq!( - LanguageFamily::from_extension("jsx"), - LanguageFamily::JavaScript - ); - } - - #[test] - fn language_family_python() { - assert_eq!(LanguageFamily::from_extension("py"), LanguageFamily::Python); - } - - #[test] - fn language_family_other() { - assert_eq!(LanguageFamily::from_extension("xyz"), LanguageFamily::Other); - } - - #[test] - fn language_family_case_insensitive() { - assert_eq!(LanguageFamily::from_extension("RS"), LanguageFamily::Rust); - assert_eq!(LanguageFamily::from_extension("Py"), LanguageFamily::Python); - } - - // ─── GroupingKey ─── - - #[test] - fn grouping_key_from_file() { - let key = GroupingKey::from_file("src/engine/mod.rs", Some("rs")); - assert_eq!(key.directory, "src/engine"); - assert_eq!(key.language, LanguageFamily::Rust); - } - - #[test] - fn grouping_key_root_file() { - let key = GroupingKey::from_file("main.rs", Some("rs")); - assert_eq!(key.directory, "."); - assert_eq!(key.language, LanguageFamily::Rust); - } - - #[test] - fn grouping_key_no_extension() { - let key = GroupingKey::from_file("Makefile", None); - assert_eq!(key.directory, "."); - assert_eq!(key.language, LanguageFamily::Other); - } - - // ─── FileGroup ─── - - #[test] - fn file_group_new() { - let group = FileGroup::new(); - assert!(group.is_empty()); - assert_eq!(group.len(), 0); - assert_eq!(group.total_chars, 0); - } - - #[test] - fn file_group_push_and_fit() { - let mut group = FileGroup::new(); - let file = crate::engine::scanner::FileEntry { - path: "test.rs".to_string(), - content: "fn main() {}".to_string(), - lines: 1, - }; - - assert!(group.would_fit(&file, 1000, 10)); - group.push(file); - assert_eq!(group.len(), 1); - assert!(!group.is_empty()); - } - - #[test] - fn file_group_max_files_limit() { - let mut group = FileGroup::new(); - for i in 0..3 { - group.push(crate::engine::scanner::FileEntry { - path: format!("file_{i}.rs"), - content: "x".to_string(), - lines: 1, - }); - } - // 3 files already, max 3 - let new_file = crate::engine::scanner::FileEntry { - path: "file_4.rs".to_string(), - content: "x".to_string(), - lines: 1, - }; - assert!(!group.would_fit(&new_file, 1_000_000, 3)); - } - - #[test] - fn file_group_max_chars_limit() { - let mut group = FileGroup::new(); - group.push(crate::engine::scanner::FileEntry { - path: "big.rs".to_string(), - content: "x".repeat(500), - lines: 1, - }); - let new_file = crate::engine::scanner::FileEntry { - path: "small.rs".to_string(), - content: "x".repeat(500), - lines: 1, - }; - // First file always fits, second should not if we set tight limit - // Total would be ~500 + path + 20 + 500 + path + 20 ≈ 1060 - assert!(!group.would_fit(&new_file, 800, 100)); - } - - #[test] - fn file_group_first_file_always_fits() { - let group = FileGroup::new(); - let huge_file = crate::engine::scanner::FileEntry { - path: "huge.rs".to_string(), - content: "x".repeat(1_000_000), - lines: 1000, - }; - // Even with tiny char limit, first file should fit - assert!(group.would_fit(&huge_file, 100, 10)); - } - - #[test] - fn file_cost_calculation() { - let file = crate::engine::scanner::FileEntry { - path: "test.rs".to_string(), - content: "hello world".to_string(), - lines: 1, - }; - let cost = FileGroup::file_cost(&file); - // "hello world".len() = 11 + "test.rs".len() = 7 + 20 overhead = 38 - assert_eq!(cost, 38); - } - - // ─── GroupingKey equality ─── - - #[test] - fn grouping_key_equality() { - let k1 = GroupingKey::from_file("src/main.rs", Some("rs")); - let k2 = GroupingKey::from_file("src/lib.rs", Some("rs")); - let k3 = GroupingKey::from_file("src/main.rs", Some("py")); - - assert_eq!(k1, k2); // same directory + language - assert_ne!(k1, k3); // same directory, different language - } - - // ─── BundlingConfig serde round-trip ─── - #[test] fn bundling_config_serde_roundtrip() { let cfg = BundlingConfig { diff --git a/src/engine/context/types.rs b/src/engine/context/types.rs index 7eb5a459..f81997d6 100644 --- a/src/engine/context/types.rs +++ b/src/engine/context/types.rs @@ -137,10 +137,10 @@ pub struct ExtractedSymbol { /// The file path where the symbol was found. pub file: String, /// Line number in the file (1-indexed). - #[allow(dead_code)] // set, never read until bundling is wired (#792) + #[allow(dead_code)] // debugging information, not read yet pub line: u32, /// The raw text that matched (for debugging). - #[allow(dead_code)] // same (#792) + #[allow(dead_code)] // debugging information, not read yet pub raw: String, } @@ -215,7 +215,7 @@ pub struct ContextChain { /// Formatted text to inject into the prompt. pub text: String, /// Build statistics. - #[allow(dead_code)] // set, never read until bundling is wired (#792) + #[allow(dead_code)] // build statistics for debugging, not read yet pub stats: ContextStats, } diff --git a/src/engine/diff_parser.rs b/src/engine/diff_parser.rs index b00ea070..11bd074e 100644 --- a/src/engine/diff_parser.rs +++ b/src/engine/diff_parser.rs @@ -299,33 +299,6 @@ pub fn detect_language(path: &str) -> &'static str { } } -/// Extract all added lines from parsed file chunks. -/// -/// Returns `(file_path, line_number, content)` triples. -#[allow(dead_code)] // for the bundling engine, not wired yet (#792) -pub fn extract_added_lines(chunks: &[FileChunk]) -> Vec<(String, u32, String)> { - let mut result = Vec::new(); - - for file in chunks { - let path = file - .new_path - .as_deref() - .or(file.old_path.as_deref()) - .unwrap_or("unknown"); - for hunk in &file.chunks { - for line in &hunk.lines { - if line.line_type == DiffLineType::Add { - if let Some(ln) = line.new_line_no { - result.push((path.to_string(), ln, line.content.clone())); - } - } - } - } - } - - result -} - // ─── Internal builder for assembling FileChunk ─── struct FileChunkBuilder { @@ -586,24 +559,6 @@ diff --git a/src/foo.rs b/src/foo.rs assert_eq!(add2.new_line_no, Some(7)); } - #[test] - fn extract_added_lines_works() { - let diff = r#"diff --git a/app.js b/app.js ---- a/app.js -+++ b/app.js -@@ -1,1 +1,3 @@ - console.log('a'); -+console.log('b'); -+console.log('c'); -"#; - let files = parse_diff(diff); - let added = extract_added_lines(&files); - assert_eq!(added.len(), 2); - assert_eq!(added[0].0, "app.js"); - assert_eq!(added[0].1, 2); - assert_eq!(added[1].1, 3); - } - #[test] fn detect_language_various() { assert_eq!(detect_language("src/main.rs"), "rs"); diff --git a/src/index/ast.rs b/src/index/ast.rs index 38792c87..142c6ee3 100644 --- a/src/index/ast.rs +++ b/src/index/ast.rs @@ -24,7 +24,7 @@ pub struct AstNode { /// Full signature text. pub signature: String, /// Parent scope name (struct/class for methods). - #[allow(dead_code)] // computed at every site, never read (#792) + #[allow(dead_code)] // computed at every site, never read; stored or removed in #807 pub parent: Option, } From e4ebe7229e4713dd0936a1019c77e1e1ffab3586 Mon Sep 17 00:00:00 2001 From: "Anaz S. Aji" <12648688+ajianaz@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:17:05 +0000 Subject: [PATCH 2/2] docs(changelog): uniform spacing under Unreleased Refs #792. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb9535fc..60a8c3ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - **The build without Tree-sitter compiles again, and CI keeps it that way (#793).** `cargo build --no-default-features` (regex extraction only, documented in the README) failed because the edge types lived in the Tree-sitter module; they are shared now. Running its tests showed that the regex extractor skipped `pub(crate)`, `pub(super)` and `pub(in ..)` items and read `const fn name` as a constant called `fn`; both are fixed. CI lints and tests this configuration in the `Check` job. + - **The unused file bundling engine is removed (#792).** About 1,100 lines of directory and language grouping for LLM batches were never called by `cora review` or `cora scan`, although the roadmap called the feature done and `.cora.yaml` has a `bundling:` section. The engine, `extract_added_lines` and the data types only it used are gone; the `bundling:` keys are still accepted (they never had an effect) so an existing config keeps loading, and the docs and the roadmap say so. Large diffs are split by `review.max_chunk_chars`. - **`cora dead-code`, `callers` and `impact` see functions passed as values and functions named in serde attributes (#802).** The Rust extractor recorded a call only for a `call_expression` and inside macros, so `.map(helper)`, `.and_then(Type::make)` and `#[serde(default = "default_true")]` made the function look unused. On this repository `cora dead-code` went from 43 findings, none of them dead code, to the 5 that are (the unwired bundling engine of #792), and `callers` now lists the function that passes another one as a value. A variable that merely has the name of a function (a parameter, a `let`, a pattern binding) is not recorded. The first `cora index` after the upgrade re-extracts every file once (#803).