Expand description
Operations over the generic property-graph model defined in
code-ranker-plugin-api: cycle detection, Henry-Kafura coupling, aggregate
stats, id relativization, and the serializable Snapshot artifact.
Everything here is language-agnostic. Plugins emit a pure
api::Graph (structure only); this crate
and the orchestrator enrich it (writing computed values into node attrs
by id) and assemble the snapshot. Which edge kinds count as information
flow is read from the level’s edge_kinds (EdgeKindSpec.flow), passed in
as a flow_kinds set — there is no hardcoded uses/contains knowledge.
Re-exports§
pub use attrs::num_attr;pub use attrs::round_sig3;pub use cycles::annotate_cycles;pub use finalize::finalize_graph;pub use hk::annotate_hk;pub use level_graph::CycleGroup;pub use level_graph::LevelGraph;pub use level_graph::LevelUi;pub use metrics::FileMetrics;pub use metrics::metric_specs;pub use metrics::write_metrics;pub use relativize::relativize_graph;pub use relativize::relativize_level;pub use serialize::to_canonical_string;pub use serialize::to_canonical_string_pretty;pub use snapshot::GitInfo;pub use snapshot::Snapshot;pub use snapshot::StageTime;pub use stats::compute_stats;
Modules§
- attrs
- Shared attribute helpers used by every enrichment pass: numeric rounding,
the
f64 → AttrValuebridge, typed attribute reads, and the external-node predicate. This is a leaf module — it depends only on the plugin API, never on the crate root, so the enrichment passes can pull helpers from here without creating asubmodule → crate-rootback-edge. - cycles
- Cycle detection over information-flow edges (Kosaraju SCC). Edges count iff
their kind is in
flow_kinds(derived fromEdgeKindSpec.flow); structural kinds likecontainsare excluded, so amod foo;parent/child pair is not flagged as a false cycle. - finalize
- Canonicalize a freshly-parsed structural graph: drop self-loops, deduplicate
edges on
(source, target, kind), and prune external nodes that nothing references. Structural edges (e.g.contains) are preserved — they carry no flow but are kept for display and ownership. - hk
- Henry-Kafura coupling over flow edges. For each internal (non-external) node
we count unique flow partners (
fan_in/fan_out), track outgoing edges to external libraries separately (fan_out_external), and computehk = sloc · (fan_in · fan_out)². Results are written into nodeattrsas flat keys; zero values are omitted. - level_
graph - Per-level payload types:
LevelGraph(one analysis level’s structural graph + semantics dictionaries + computed cycles/stats/UI),LevelUi(computed UI hints), andCycleGroup(one classified SCC). These are the widely-imported model types; keeping them in their own module spreads their fan-in off the crate’ssnapshotartifact. - metrics
- Language-neutral complexity-metric scaffolding: the computed-value carrier
FileMetrics, the writerwrite_metrics(omit-at + LOC/Halstead gating), the no-signal values [metric_omit_at], and the metric attribute catalogmetric_specs. The siblingcoupling_specslives alongside it; both are merged into the snapshot’s node-attribute dictionary. - relativize
- Id relativization: rewrite absolute file-path node ids to portable
{target}/rel/{root}/reltokens (and follow them through edges, parents, cycle node lists, and externalpathattributes), so a snapshot is machine-independent. - serialize
- Canonical (deterministic) JSON serialization. Object keys come out
alphabetically (
serde_json::Valueis backed by aBTreeMap) and thenodes/edgesarrays are sorted by a stable key, so unchanged input is byte-identical across runs. Generic over anySerialize— depends on nothing else in the crate. - snapshot
- The serializable analysis artifact (
Snapshot) and its header types (GitInfo,StageTime). - stats
- Per-graph aggregate stats: the mean of each tracked numeric metric across the project’s file nodes. Zero/missing values are excluded from a metric’s average (matching the historical behavior); a metric is emitted only when its average is positive.
Functions§
- coupling_
specs - The coupling/cycle attribute dictionary produced by
annotate_hk/annotate_cycles, plus thecouplinggroup. The orchestrator merges these into each level’snode_attributes/attribute_groups.