pub mod lifecycle;
pub mod schema;
pub mod store;
pub mod walker;
pub use lifecycle::{init_coupling_store, refresh_on_reconcile_tick};
pub use store::{CouplingRow, CouplingStore};
pub use walker::{DeltaOutcome, WalkerConfig, WalkerStats, apply_head_delta, cold_build};
pub(crate) fn decay_factor(delta_secs: i64, half_life_secs: i64) -> f64 {
if half_life_secs <= 0 || delta_secs <= 0 {
return 1.0;
}
(-(delta_secs as f64) * std::f64::consts::LN_2 / half_life_secs as f64).exp()
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Granularity {
File,
Symbol,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AnchorKey(String);
impl AnchorKey {
pub fn file(rel_path: &str) -> Self {
Self(format!("file:{}", normalize_path(rel_path)))
}
pub fn symbol(rel_path: &str, name: &str, kind: &str) -> Self {
Self(format!(
"symbol:{}#{}#{}",
normalize_path(rel_path),
name,
kind
))
}
pub(crate) fn from_raw(raw: String) -> Self {
Self(raw)
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn granularity(&self) -> Granularity {
if self.0.starts_with("symbol:") {
Granularity::Symbol
} else {
Granularity::File
}
}
}
fn normalize_path(s: &str) -> String {
s.replace('\\', "/")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn file_anchor_is_prefixed_and_slash_normalized() {
let a = AnchorKey::file("src\\live_index\\query.rs");
assert_eq!(a.as_str(), "file:src/live_index/query.rs");
assert_eq!(a.granularity(), Granularity::File);
}
#[test]
fn symbol_anchor_embeds_name_and_kind() {
let a = AnchorKey::symbol("src/live_index/query.rs", "capture_search_files_view", "fn");
assert_eq!(
a.as_str(),
"symbol:src/live_index/query.rs#capture_search_files_view#fn"
);
assert_eq!(a.granularity(), Granularity::Symbol);
}
#[test]
fn from_raw_preserves_unknown_prefix_as_file_granularity() {
let a = AnchorKey::from_raw("weird:whatever".to_string());
assert_eq!(a.as_str(), "weird:whatever");
assert_eq!(a.granularity(), Granularity::File);
}
}