Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ jobs:

- name: Run benchmarks
run: |
git branch ${{ github.head_ref }} || true
git fetch origin ${{ github.base_ref }}
git checkout ${{ github.base_ref }}
cargo bench --bench serialization --no-run
Expand Down Expand Up @@ -261,6 +262,7 @@ jobs:
- name: Fetch and check out base branch
if: github.event_name == 'pull_request'
run: |
git branch ${{ github.head_ref }} || true
git fetch origin ${{ github.base_ref }}
git checkout ${{ github.base_ref }}

Expand Down
31 changes: 31 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ pub struct YekConfig {
#[config_arg(accept_from = "config_only")]
pub git_boost_max: Option<i32>,

/// Enable dependency centrality ranking (fixes #255)
#[config_arg(accept_from = "config_only")]
pub centrality: Option<bool>,

/// Weight for dependency centrality ranking (0.0..1.0, default 0.6)
#[config_arg(accept_from = "config_only")]
pub centrality_weight: Option<f64>,

/// Weight for Git recency ranking (0.0..1.0, default 0.4)
#[config_arg(accept_from = "config_only")]
pub recency_weight: Option<f64>,

/// Category-based priority weights
#[config_arg(accept_from = "config_only")]
pub category_weights: Option<crate::category::CategoryWeights>,
Expand Down Expand Up @@ -135,6 +147,9 @@ impl Default for YekConfig {
.map(|s| s.to_string())
.collect(),
git_boost_max: Some(100),
centrality: Some(true),
centrality_weight: Some(0.6),
recency_weight: Some(0.4),
category_weights: None,

// computed fields
Expand Down Expand Up @@ -324,6 +339,10 @@ impl YekConfig {
self.line_numbers |= config_bool(&settings, "line_numbers", "line-numbers");
self.tree_header |= config_bool(&settings, "tree_header", "tree-header");
self.tree_only |= config_bool(&settings, "tree_only", "tree-only");

if let Ok(val) = settings.get_bool("centrality") {
self.centrality = Some(val);
}
}

/// Compute a quick checksum for the input paths (files and directories).
Expand Down Expand Up @@ -455,6 +474,18 @@ impl YekConfig {
})?;
}

// Validate centrality weights
if let Some(w) = self.centrality_weight {
if !(0.0..=1.0).contains(&w) {
return Err(anyhow!("centrality_weight: must be between 0.0 and 1.0"));
}
}
if let Some(w) = self.recency_weight {
if !(0.0..=1.0).contains(&w) {
return Err(anyhow!("recency_weight: must be between 0.0 and 1.0"));
}
}

// Validate tree options are mutually exclusive
if self.tree_header && self.tree_only {
return Err(anyhow!("tree_header and tree_only cannot both be enabled"));
Expand Down
35 changes: 35 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,41 @@ pub fn serialize_repo(config: &YekConfig) -> Result<(String, Vec<ProcessedFile>)

let mut files = merged_files;

// Apply hybrid priority boost (combining Git recency + Dependency Centrality, fixes #255)
let enable_centrality = config.centrality.unwrap_or(true);
let max_boost = config.git_boost_max.unwrap_or(100);
let r_weight = config.recency_weight.unwrap_or(0.4);
let c_weight = config.centrality_weight.unwrap_or(0.6);

let file_inputs: Vec<(String, String)> = files
.iter()
.map(|f| (f.rel_path.clone(), f.content.clone()))
.collect();

let centrality_scores = if enable_centrality {
Some(priority::compute_dependency_centrality(&file_inputs))
} else {
None
};

let hybrid_boosts = priority::compute_hybrid_priority_boost(
if combined_commit_times.is_empty() {
None
} else {
Some(&combined_commit_times)
},
centrality_scores.as_ref(),
max_boost,
r_weight,
c_weight,
);

for file in &mut files {
if let Some(boost) = hybrid_boosts.get(&file.rel_path) {
file.priority += *boost;
}
}

// Sort final (priority asc, then file_index asc)
files.par_sort_by(|a, b| {
a.priority
Expand Down
9 changes: 9 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ pub struct ProcessingConfig {
pub memory_limit_mb: Option<usize>,
/// Batch size for processing
pub batch_size: usize,
/// Whether to enable dependency centrality ranking
pub centrality: Option<bool>,
/// Weight for dependency centrality ranking (0.0..1.0)
pub centrality_weight: Option<f64>,
/// Weight for Git recency ranking (0.0..1.0)
pub recency_weight: Option<f64>,
}

impl Default for ProcessingConfig {
Expand All @@ -312,6 +318,9 @@ impl Default for ProcessingConfig {
max_threads: None,
memory_limit_mb: None,
batch_size: 1000,
centrality: Some(true),
centrality_weight: Some(0.6),
recency_weight: Some(0.4),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ pub fn process_files_parallel(
max_threads: None,
memory_limit_mb: None,
batch_size: 1000,
centrality: config.centrality,
centrality_weight: config.centrality_weight,
recency_weight: config.recency_weight,
},
crate::models::RepositoryInfo::new(base_path.to_path_buf(), false), // TODO: Proper repo info
Arc::new(crate::repository::RealFileSystem),
Expand Down
48 changes: 43 additions & 5 deletions src/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,11 +532,14 @@ impl FileDiscoveryStage {
}
}

// Apply git boost if available
if let Some(commit_time) = repo_info.commit_times.get(rel_path) {
let max_boost = context.input_config.git_boost_max.unwrap_or(100);
let boost = self.calculate_git_boost(*commit_time, &repo_info.commit_times, max_boost);
priority += boost;
// Apply git boost if available and centrality is disabled (otherwise hybrid boost is applied at pipeline completion)
if !context.processing_config.centrality.unwrap_or(true) {
if let Some(commit_time) = repo_info.commit_times.get(rel_path) {
let max_boost = context.input_config.git_boost_max.unwrap_or(100);
let boost =
self.calculate_git_boost(*commit_time, &repo_info.commit_times, max_boost);
priority += boost;
}
}

priority
Expand Down Expand Up @@ -760,6 +763,41 @@ impl ProcessingPipeline {
files = stage.process(files, &self.context)?;
}

// Apply hybrid boost (dependency centrality + Git recency, fixes #255)
let enable_centrality = self.context.processing_config.centrality.unwrap_or(true);
if enable_centrality {
let file_inputs: Vec<(String, String)> = files
.iter()
.map(|f| (f.rel_path.clone(), f.content.clone()))
.collect();
let centralities = crate::priority::compute_dependency_centrality(&file_inputs);
let max_boost = self.context.input_config.git_boost_max.unwrap_or(100);
let c_weight = self
.context
.processing_config
.centrality_weight
.unwrap_or(0.6);
let r_weight = self.context.processing_config.recency_weight.unwrap_or(0.4);

let commit_times = &self.context.repository_info.commit_times;
let hybrid_boosts = crate::priority::compute_hybrid_priority_boost(
if commit_times.is_empty() {
None
} else {
Some(commit_times)
},
Some(&centralities),
max_boost,
r_weight,
c_weight,
);
for f in &mut files {
if let Some(boost) = hybrid_boosts.get(&f.rel_path) {
f.priority += *boost;
}
}
}

// Final sorting by priority and file_index
files.sort_by(|a, b| {
a.priority
Expand Down
Loading
Loading