Skip to content
Merged
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 Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/tracedecay-application/src/git_intelligence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ use tracedecay_query::native_git::NativeHistoricalBlobReaderV1;
use tracedecay_runtime_core::cancellation::CancellationToken;
use tracedecay_runtime_core::git_repository::GitRepositoryError;

/// Git churn reads for structural-health and test-risk analysis.
pub mod churn;
mod topology;

/// Read subcommands the adapter is allowed to run. Anything outside this
Expand Down
69 changes: 0 additions & 69 deletions crates/tracedecay-application/src/git_intelligence/churn.rs

This file was deleted.

71 changes: 4 additions & 67 deletions crates/tracedecay-application/src/semantic_runtime/redundancy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,74 +18,11 @@ use super::{
project_semantic_production_runtime,
};

const SEMANTIC_DISTANCE_SCALE: f64 = 1_000_000_000.0;
const MAX_COSINE_DISTANCE_MICROS: i64 = 2_000_000_000;

#[derive(Clone, Debug, PartialEq)]
pub struct SemanticRedundancyVectorV1 {
pub file_path: String,
pub qualified_name: String,
pub values: Vec<f32>,
}

#[derive(Clone, Debug, PartialEq)]
pub struct SemanticRedundancyGenerationV1 {
pub vector_generation: String,
pub source_generation: String,
pub projection_key: String,
pub profile: SemanticRedundancyProfileV1,
pub vectors: Vec<SemanticRedundancyVectorV1>,
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SemanticRedundancyProfileV1 {
pub scope_digest: String,
pub accepted_profile_digest: String,
pub calibration_profile_id: String,
pub calibration_digest: String,
pub redundancy_profile_digest: String,
pub maximum_distance_micros: i64,
}

impl SemanticRedundancyProfileV1 {
pub(crate) fn distance_micros(&self, cosine: f64) -> Option<i64> {
if !cosine.is_finite() || !(-1.0..=1.0).contains(&cosine) {
return None;
}
let scaled = ((1.0 - cosine) * SEMANTIC_DISTANCE_SCALE).round();
(scaled >= 0.0 && scaled <= MAX_COSINE_DISTANCE_MICROS as f64).then_some(scaled as i64)
}

pub fn accepts(&self, cosine: f64) -> Option<i64> {
let distance = self.distance_micros(cosine)?;
(distance <= self.maximum_distance_micros).then_some(distance)
}
pub use tracedecay_graph_query::redundancy_scan::{
SemanticRedundancyGenerationV1, SemanticRedundancyProfileV1, SemanticRedundancyVectorV1,
};

/// Half-width, in normalized-vector coordinate units, of the smallest
/// window that still contains every pair this profile could accept.
///
/// For unit vectors `u`, `v` we have `‖u − v‖² = 2(1 − cos)`, and every
/// single coordinate obeys `|u_k − v_k| ≤ ‖u − v‖`. A pair is accepted only
/// when `round((1 − cos)·SCALE) ≤ maximum_distance_micros`, which requires
/// `(1 − cos) ≤ (maximum_distance_micros + 0.5)/SCALE` (the `+0.5` bounds
/// the rounding). Substituting yields a per-coordinate bound of
/// `sqrt(2·(maximum_distance_micros + 0.5)/SCALE)`.
///
/// Sorting normalized vectors by any one coordinate and comparing only
/// entries within this half-width therefore excludes **no** acceptable pair
/// (perfect recall): the returned window is a necessary condition on every
/// accepted pair, never a sufficient one, so callers must still re-check
/// [`accepts`] on each surviving candidate. A tiny epsilon is added for
/// floating-point slack; the value saturates at `2.0` (a window that spans
/// the whole normalized range, i.e. no pruning) for permissive profiles.
pub fn cosine_projection_window(&self) -> f64 {
let allowed = (self.maximum_distance_micros as f64 + 0.5) / SEMANTIC_DISTANCE_SCALE;
if allowed <= 0.0 {
return 0.0;
}
((2.0 * allowed).sqrt() + 1e-9).min(2.0)
}
}
const MAX_COSINE_DISTANCE_MICROS: i64 = 2_000_000_000;

#[derive(Clone, Debug, PartialEq, Eq)]
struct SemanticRedundancyAuthorityV1 {
Expand Down
11 changes: 10 additions & 1 deletion crates/tracedecay-graph-query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ include = ["/src/**"]

[dependencies]
hotpath.workspace = true
serde = { version = "1", features = ["derive"] }
serde_json = "1"
thiserror = "2"
tokio = { version = "1", features = ["rt", "process"] }
tracedecay-contracts = { path = "../tracedecay-contracts", version = "0.1.0" }
# Grammar-free entry only: `markdown_structure` compiles with no language
# feature enabled, so section structure reaches retrieval without linking a
# tree-sitter bundle into this crate.
# tree-sitter bundle into this crate. Isolated redundancy tests opt into
# `lite` via dev-dependencies; production callers already unify a grammar
# tier through the composition root.
tracedecay-code-extraction = { path = "../tracedecay-code-extraction", version = "0.1.0", default-features = false }
tracedecay-code-index = { path = "../tracedecay-code-index", version = "0.1.0", default-features = false }
tracedecay-domain = { path = "../tracedecay-domain", version = "0.1.0" }
tracedecay-graph-db = { path = "../tracedecay-graph-db", version = "0.1.0" }
tracedecay-privacy = { path = "../tracedecay-privacy", version = "0.1.0" }
tracedecay-runtime-core = { path = "../tracedecay-runtime-core", version = "0.1.0" }
tracedecay-session-memory = { path = "../tracedecay-session-memory", version = "0.1.0" }

Expand All @@ -32,6 +37,10 @@ test-helpers = []
[dev-dependencies]
tempfile = "3"
tokio = { version = "1", features = ["full"] }
# Isolated crate tests need a grammar bundle so the patched Rust grammar
# registers (`ts_provider` only serves Rust alongside a bundle). Production
# callers already unify `lite`/`full` through the composition root.
tracedecay-code-extraction = { path = "../tracedecay-code-extraction", version = "0.1.0", default-features = false, features = ["lite"] }
tracedecay-code-index = { path = "../tracedecay-code-index", version = "0.1.0", default-features = false, features = ["test-helpers"] }
tracedecay-global-db = { path = "../tracedecay-global-db", version = "0.1.0", features = ["test-helpers"] }
tracedecay-runtime-core = { path = "../tracedecay-runtime-core", version = "0.1.0", features = ["test-helpers"] }
Expand Down
5 changes: 4 additions & 1 deletion crates/tracedecay-graph-query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
//! (`tracedecay-code-index`, `tracedecay-graph-db`,
//! `tracedecay-runtime-core`). It owns the [`VerifiedGraphQuery`] authority:
//! admission, source binding, and every analytical read run through the one
//! generation-pinned reader opened by [`open_verified_graph_query`].
//! generation-pinned reader opened by [`open_verified_graph_query`], including
//! the redundancy and test-risk scans that consume that admitted handle.

use std::path::{Path, PathBuf};

Expand All @@ -18,8 +19,10 @@ pub mod context;
pub mod health;
mod projection;
pub mod queries;
pub mod redundancy_scan;
pub mod scc;
mod source_authority;
pub mod test_risk;
mod verified_query;

pub use tracedecay_code_index::chunks::CodeIndexImportEvidenceV1;
Expand Down
Loading
Loading