code_ranker_plugin_api/metrics.rs
1//! The plugin↔orchestrator **metric contract**: the raw tier-1 counts a language
2//! plugin measures for one unit ([`MetricInputs`]) and a sub-file unit carrying
3//! them ([`FunctionUnit`]).
4//!
5//! These are pure data. A plugin's metric engine *produces* them; the
6//! orchestrator (`code-ranker-graph`) *consumes* them — running the tier-2 CEL
7//! registry from `metrics/builtin.toml` and writing every metric onto the node.
8//! They live here in the foundation crate so a plugin depends only on this API,
9//! never on the heavier graph/enrichment crate, to hand back its measurements.
10
11/// Raw tier-1 counts a per-language engine measures for one unit (a file or, for
12/// the `functions` level, a function). Every tier-2 metric is a pure function of
13/// these, evaluated by the orchestrator's built-in registry — see
14/// `code-ranker-graph`'s `metrics/builtin.toml`.
15#[derive(Debug, Clone, Default, PartialEq)]
16pub struct MetricInputs {
17 /// Halstead base counts (η₁/η₂/N₁/N₂), as floats (counts are small integers).
18 pub eta1: f64,
19 pub eta2: f64,
20 pub n1: f64,
21 pub n2: f64,
22 /// Structural counts.
23 pub spaces: f64,
24 pub branches: f64,
25 pub cognitive: f64,
26 pub exits: f64,
27 pub args: f64,
28 pub closures: f64,
29 /// LOC breakdown.
30 pub sloc: f64,
31 pub lloc: f64,
32 pub cloc: f64,
33 pub blank: f64,
34 pub tloc: f64,
35 /// Unit span sloc (`end_row − start_row`) — an MI input, not emitted itself.
36 pub span_sloc: f64,
37}
38
39/// One sub-file unit (a function / method / closure) with its tier-1 counts.
40/// Produced by a language engine's `compute_functions` for the optional
41/// `functions` level. `kind` is a free-form, per-language string
42/// (`fn` / `method` / `closure` / `lambda` / …).
43#[derive(Debug, Clone, PartialEq)]
44pub struct FunctionUnit {
45 pub kind: String,
46 pub name: String,
47 /// 1-based inclusive line span.
48 pub start_line: u32,
49 pub end_line: u32,
50 pub inputs: MetricInputs,
51}