| 854 | } |
| 855 | |
| 856 | fn project_metrics( |
| 857 | out: &mut Projection, |
| 858 | reference: &str, |
| 859 | analysis: &AnalysisReport, |
| 860 | project: &atomic_core::kg::project_id::ProjectId, |
| 861 | view_mode: Option<&str>, |
| 862 | ) { |
| 863 | use atomic_audit::Metric; |
| 864 | if analysis.metrics.is_empty() { |
| 865 | return; |
| 866 | } |
| 867 | let scope = local_id("metric-scope", &reference); |
| 868 | out.node(&scope, "metric_comparison_scope", if view_mode.is_some() { "Recorded view corpus (see view/comparison root; language/subject/resource limits apply)" } else { "Recorded supplied paths only (not a repository-wide clone scan)" }, json!({ |
| 869 | "change": reference, "paths": analysis.metric_comparison_scope, "diagnostics": analysis.metric_diagnostics, |
| 870 | })); |
| 871 | for record in &analysis.metrics { |
| 872 | let metric = record.observation.metric; |
| 873 | let pass = if matches!(metric, Metric::DependencyFanOut | Metric::PublicSurface) { |
| 874 | ReviewPass::BlastRadiusRisk |
| 875 | } else { |
| 876 | ReviewPass::AntiSlop |
| 877 | }; |
| 878 | let id = local_id("metric", &(&reference, metric, &record.observation.subject)); |
| 879 | let delta = record |
| 880 | .delta |
| 881 | .map(|delta| format!(" (delta {delta:+})")) |
| 882 | .unwrap_or_default(); |
| 883 | let label = if view_mode == Some("view_snapshot") { |
| 884 | format!( |
| 885 | "{} {}: {} (recorded view snapshot)", |
| 886 | metric.id(), |
| 887 | record.observation.subject, |
| 888 | measurement_label(&record.observation.after) |
| 889 | ) |
| 890 | } else { |
| 891 | format!( |
| 892 | "{} {}: {} → {}{delta}", |
| 893 | metric.id(), |
| 894 | record.observation.subject, |
| 895 | measurement_label(&record.observation.before), |
| 896 | measurement_label(&record.observation.after) |
| 897 | ) |
| 898 | }; |
| 899 | let mut properties = encode(record); |
| 900 | properties["change"] = json!(reference); |
| 901 | if let Some(kind) = view_mode { |
| 902 | properties["scope_kind"] = json!(kind); |
| 903 | } |
| 904 | out.node(&id, "metric", &label, properties); |
| 905 | out.edge(pass.id(), "measures", &id); |
| 906 | out.edge(&id, "within_comparison_scope", &scope); |
| 907 | let card = atomic_audit::METRIC_CARDS |
| 908 | .iter() |
| 909 | .find(|card| card.metric == metric) |
| 910 | .expect("metric card"); |
| 911 | let card_id = format!("metric-card:{}", metric.id()); |
| 912 | out.node(&card_id, "metric_card", card.title, encode(card)); |
| 913 | out.edge(&id, "defined_by", &card_id); |