dart-decimate 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/Cargo.lock +572 -0
  2. package/Cargo.toml +41 -0
  3. package/LICENSE +21 -0
  4. package/README.md +617 -0
  5. package/assets/dart-decimate-banner.png +0 -0
  6. package/npm/bin/dart-decimate-mcp.js +48 -0
  7. package/npm/bin/dart-decimate.js +48 -0
  8. package/npm/scripts/postinstall.js +46 -0
  9. package/npm/scripts/test-npx-local.js +54 -0
  10. package/npm/scripts/test-npx-mcp-local.js +56 -0
  11. package/package.json +45 -0
  12. package/src/baseline.rs +643 -0
  13. package/src/bin/dart-decimate-mcp.rs +11 -0
  14. package/src/boundaries/tests.rs +60 -0
  15. package/src/boundaries.rs +317 -0
  16. package/src/changed_scope.rs +117 -0
  17. package/src/ci_template.rs +399 -0
  18. package/src/cli/analyze.rs +462 -0
  19. package/src/cli/analyzer_options.rs +82 -0
  20. package/src/cli/audit_run.rs +327 -0
  21. package/src/cli/boundary_args.rs +44 -0
  22. package/src/cli/ci_template_run.rs +196 -0
  23. package/src/cli/command_name.rs +20 -0
  24. package/src/cli/common_args.rs +167 -0
  25. package/src/cli/config_run.rs +78 -0
  26. package/src/cli/coverage_run.rs +393 -0
  27. package/src/cli/decision_surface_run.rs +99 -0
  28. package/src/cli/default_command.rs +69 -0
  29. package/src/cli/dupes_args.rs +150 -0
  30. package/src/cli/entry_points.rs +121 -0
  31. package/src/cli/error.rs +149 -0
  32. package/src/cli/error_output.rs +68 -0
  33. package/src/cli/explain_run.rs +72 -0
  34. package/src/cli/fix_run.rs +162 -0
  35. package/src/cli/flags_args.rs +23 -0
  36. package/src/cli/health_args.rs +200 -0
  37. package/src/cli/hooks_run.rs +191 -0
  38. package/src/cli/impact_run.rs +95 -0
  39. package/src/cli/init_run.rs +49 -0
  40. package/src/cli/inspect_args.rs +20 -0
  41. package/src/cli/inspect_run.rs +66 -0
  42. package/src/cli/issue_filter_args.rs +240 -0
  43. package/src/cli/list_run.rs +311 -0
  44. package/src/cli/mode_args.rs +72 -0
  45. package/src/cli/output_format.rs +62 -0
  46. package/src/cli/regression_args.rs +156 -0
  47. package/src/cli/request_args.rs +175 -0
  48. package/src/cli/schema_commands.rs +72 -0
  49. package/src/cli/scope_args.rs +174 -0
  50. package/src/cli/security_args.rs +175 -0
  51. package/src/cli/security_gate_run.rs +66 -0
  52. package/src/cli/security_summary_run.rs +43 -0
  53. package/src/cli/summary_args.rs +12 -0
  54. package/src/cli/tests.rs +516 -0
  55. package/src/cli/trace_args.rs +67 -0
  56. package/src/cli/trace_run.rs +131 -0
  57. package/src/cli/trace_tests.rs +235 -0
  58. package/src/cli/unsupported_run.rs +116 -0
  59. package/src/cli/watch_run.rs +153 -0
  60. package/src/cli.rs +603 -0
  61. package/src/config/boundary_config.rs +235 -0
  62. package/src/config/cache.rs +25 -0
  63. package/src/config/dependencies.rs +114 -0
  64. package/src/config/health.rs +237 -0
  65. package/src/config/jsonc.rs +66 -0
  66. package/src/config/policy.rs +91 -0
  67. package/src/config/rule_aliases.rs +487 -0
  68. package/src/config/rules.rs +339 -0
  69. package/src/config.rs +635 -0
  70. package/src/coverage.rs +469 -0
  71. package/src/dart_parser.rs +673 -0
  72. package/src/decision_surface.rs +405 -0
  73. package/src/dependencies/analyze.rs +218 -0
  74. package/src/dependencies/codegen.rs +118 -0
  75. package/src/dependencies/discovery.rs +60 -0
  76. package/src/dependencies/overrides.rs +76 -0
  77. package/src/dependencies/private_src_imports.rs +32 -0
  78. package/src/dependencies/pubspec_document.rs +86 -0
  79. package/src/dependencies/pubspec_entry.rs +96 -0
  80. package/src/dependencies/tests.rs +544 -0
  81. package/src/dependencies/usage.rs +33 -0
  82. package/src/dependencies.rs +553 -0
  83. package/src/dependency_scripts.rs +91 -0
  84. package/src/dupes/lex.rs +236 -0
  85. package/src/dupes/tests.rs +119 -0
  86. package/src/dupes.rs +625 -0
  87. package/src/explain.rs +692 -0
  88. package/src/extract/directives.rs +252 -0
  89. package/src/extract/error_tests.rs +25 -0
  90. package/src/extract/members.rs +210 -0
  91. package/src/extract/primary_constructors.rs +421 -0
  92. package/src/extract/references.rs +151 -0
  93. package/src/extract/routes.rs +691 -0
  94. package/src/extract/signatures.rs +266 -0
  95. package/src/extract/string_tests.rs +18 -0
  96. package/src/extract/strings.rs +107 -0
  97. package/src/extract/tests.rs +697 -0
  98. package/src/extract.rs +680 -0
  99. package/src/feature_flags/tests.rs +76 -0
  100. package/src/feature_flags.rs +453 -0
  101. package/src/finding_identity.rs +60 -0
  102. package/src/fix.rs +551 -0
  103. package/src/generated.rs +53 -0
  104. package/src/graph/augment_tests.rs +212 -0
  105. package/src/graph/conditionals.rs +74 -0
  106. package/src/graph/package_config_tests.rs +100 -0
  107. package/src/graph/parts.rs +248 -0
  108. package/src/graph/pubspec_tests.rs +119 -0
  109. package/src/graph/tests.rs +837 -0
  110. package/src/graph/uri_tests.rs +102 -0
  111. package/src/graph.rs +644 -0
  112. package/src/health/coverage.rs +309 -0
  113. package/src/health/ownership.rs +175 -0
  114. package/src/health/runtime_coverage.rs +616 -0
  115. package/src/health/runtime_intelligence.rs +511 -0
  116. package/src/health/scores.rs +296 -0
  117. package/src/health/tests.rs +240 -0
  118. package/src/health/threshold_types.rs +163 -0
  119. package/src/health/thresholds.rs +229 -0
  120. package/src/health/types.rs +636 -0
  121. package/src/health.rs +597 -0
  122. package/src/hooks/agent_settings.rs +175 -0
  123. package/src/hooks/templates.rs +51 -0
  124. package/src/hooks.rs +569 -0
  125. package/src/impact.rs +287 -0
  126. package/src/init.rs +237 -0
  127. package/src/inspect.rs +142 -0
  128. package/src/intelligence/tests.rs +232 -0
  129. package/src/intelligence.rs +305 -0
  130. package/src/lib.rs +198 -0
  131. package/src/main.rs +5 -0
  132. package/src/manifest/mcp.rs +565 -0
  133. package/src/manifest.rs +552 -0
  134. package/src/mcp/cli_args/value_args.rs +175 -0
  135. package/src/mcp/cli_args.rs +658 -0
  136. package/src/mcp/cli_args_tests.rs +522 -0
  137. package/src/mcp/code_execute.rs +671 -0
  138. package/src/mcp/tools.rs +660 -0
  139. package/src/mcp.rs +325 -0
  140. package/src/output/audit_risk.rs +135 -0
  141. package/src/output/dependency_findings.rs +327 -0
  142. package/src/output/duplication_findings.rs +114 -0
  143. package/src/output/feature_flag_findings.rs +122 -0
  144. package/src/output/format.rs +31 -0
  145. package/src/output/graph_findings.rs +461 -0
  146. package/src/output/health_findings.rs +612 -0
  147. package/src/output/human.rs +27 -0
  148. package/src/output/next_steps.rs +92 -0
  149. package/src/output/route_findings.rs +76 -0
  150. package/src/output/runtime_coverage.rs +515 -0
  151. package/src/output/scope.rs +183 -0
  152. package/src/output/security_findings.rs +390 -0
  153. package/src/output/security_sarif.rs +150 -0
  154. package/src/output/suppressions.rs +323 -0
  155. package/src/output/symbol_findings.rs +257 -0
  156. package/src/output/tests.rs +114 -0
  157. package/src/output/types.rs +604 -0
  158. package/src/output/widget_findings.rs +213 -0
  159. package/src/output.rs +682 -0
  160. package/src/package_map.rs +495 -0
  161. package/src/policy/packs.rs +232 -0
  162. package/src/policy/tests.rs +134 -0
  163. package/src/policy.rs +640 -0
  164. package/src/project_list.rs +376 -0
  165. package/src/report_schema/inventory.rs +418 -0
  166. package/src/report_schema.rs +488 -0
  167. package/src/routes.rs +354 -0
  168. package/src/scan/tests.rs +250 -0
  169. package/src/scan.rs +275 -0
  170. package/src/security/detect.rs +639 -0
  171. package/src/security/tests.rs +178 -0
  172. package/src/security.rs +373 -0
  173. package/src/security_gate.rs +555 -0
  174. package/src/symbols/path_filters.rs +27 -0
  175. package/src/symbols/private_type_leaks.rs +125 -0
  176. package/src/symbols/riverpod.rs +113 -0
  177. package/src/symbols/tests.rs +692 -0
  178. package/src/symbols.rs +693 -0
  179. package/src/trace/tests.rs +225 -0
  180. package/src/trace.rs +690 -0
  181. package/src/unsupported.rs +47 -0
  182. package/src/widgets/lifecycle.rs +484 -0
  183. package/src/widgets/params.rs +236 -0
  184. package/src/widgets/tests.rs +430 -0
  185. package/src/widgets/top_level.rs +110 -0
  186. package/src/widgets/unrendered.rs +374 -0
  187. package/src/widgets.rs +590 -0
  188. package/src/workspace_scope.rs +358 -0
@@ -0,0 +1,511 @@
1
+ use std::collections::{BTreeMap, BTreeSet};
2
+ use std::path::{Path, PathBuf};
3
+
4
+ use serde::{Deserialize, Serialize};
5
+
6
+ use crate::graph::normalize_against;
7
+ use crate::{LowTrafficThreshold, ScannedProject};
8
+
9
+ use super::runtime_coverage::{RuntimeCoverageAccumulator, RuntimeFunctionCoverage};
10
+ use super::{
11
+ FunctionMetrics, HealthOptions, RuntimeCoverageConfidence, RuntimeCoverageFinding,
12
+ RuntimeCoverageFindingKind, RuntimeHotPath,
13
+ };
14
+
15
+ const FNV_OFFSET: u64 = 0xcbf2_9ce4_8422_2325;
16
+ const FNV_PRIME: u64 = 0x0000_0100_0000_01b3;
17
+
18
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
19
+ pub struct RuntimeCoverageIntelligence {
20
+ pub id: String,
21
+ pub stable_id: String,
22
+ pub kind: RuntimeCoverageIntelligenceKind,
23
+ pub path: PathBuf,
24
+ pub line: Option<usize>,
25
+ pub symbol: Option<String>,
26
+ pub action: RuntimeCoverageAction,
27
+ pub priority: usize,
28
+ pub confidence: RuntimeCoverageConfidence,
29
+ pub reason: String,
30
+ pub signals: Vec<String>,
31
+ }
32
+
33
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
34
+ #[serde(rename_all = "kebab-case")]
35
+ pub enum RuntimeCoverageIntelligenceKind {
36
+ HotPathTouched,
37
+ LowTraffic,
38
+ CoverageUnavailable,
39
+ }
40
+
41
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
42
+ #[serde(rename_all = "kebab-case")]
43
+ pub enum RuntimeCoverageAction {
44
+ ReviewRuntime,
45
+ DeleteColdCode,
46
+ }
47
+
48
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
49
+ pub struct RuntimeBlastRadius {
50
+ pub id: String,
51
+ pub stable_id: String,
52
+ pub path: PathBuf,
53
+ pub line: Option<usize>,
54
+ pub symbol: Option<String>,
55
+ pub caller_count: usize,
56
+ pub callers: Vec<PathBuf>,
57
+ pub traffic_weighted_caller_reach: LowTrafficThreshold,
58
+ pub risk: RuntimeBlastRisk,
59
+ }
60
+
61
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
62
+ #[serde(rename_all = "kebab-case")]
63
+ pub enum RuntimeBlastRisk {
64
+ Low,
65
+ Medium,
66
+ High,
67
+ }
68
+
69
+ #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
70
+ pub struct RuntimeImportance {
71
+ pub id: String,
72
+ pub stable_id: String,
73
+ pub path: PathBuf,
74
+ pub line: Option<usize>,
75
+ pub symbol: Option<String>,
76
+ pub invocations: usize,
77
+ pub traffic_fraction: LowTrafficThreshold,
78
+ pub cyclomatic_complexity: usize,
79
+ pub caller_count: usize,
80
+ pub score: usize,
81
+ pub reason: String,
82
+ }
83
+
84
+ #[derive(Debug, Clone, PartialEq, Eq)]
85
+ pub(super) struct RuntimeIntelligenceBundle {
86
+ pub(super) coverage_intelligence: Vec<RuntimeCoverageIntelligence>,
87
+ pub(super) blast_radius: Vec<RuntimeBlastRadius>,
88
+ pub(super) importance: Vec<RuntimeImportance>,
89
+ }
90
+
91
+ pub(super) fn runtime_intelligence(
92
+ project: &ScannedProject,
93
+ options: &HealthOptions,
94
+ functions: &[FunctionMetrics],
95
+ accumulator: &RuntimeCoverageAccumulator,
96
+ total_invocations: usize,
97
+ hot_paths: &[RuntimeHotPath],
98
+ findings: &[RuntimeCoverageFinding],
99
+ ) -> RuntimeIntelligenceBundle {
100
+ let callers = callers_by_target(project);
101
+ let observations = runtime_observations(accumulator);
102
+ let importance = runtime_importance(
103
+ options,
104
+ functions,
105
+ &observations,
106
+ &callers,
107
+ total_invocations,
108
+ );
109
+ let blast_radius = runtime_blast_radius(
110
+ options,
111
+ &observations,
112
+ hot_paths,
113
+ &callers,
114
+ total_invocations,
115
+ );
116
+ let coverage_intelligence =
117
+ coverage_intelligence(project, options, hot_paths, findings, total_invocations);
118
+ RuntimeIntelligenceBundle {
119
+ coverage_intelligence,
120
+ blast_radius,
121
+ importance,
122
+ }
123
+ }
124
+
125
+ fn runtime_observations(accumulator: &RuntimeCoverageAccumulator) -> Vec<RuntimeObservation> {
126
+ let mut observations = BTreeMap::<(PathBuf, Option<usize>, Option<String>), usize>::new();
127
+ for (path, file) in &accumulator.files {
128
+ if file.functions.is_empty() {
129
+ observations.insert((path.clone(), None, None), file.invocations);
130
+ continue;
131
+ }
132
+ for function in &file.functions {
133
+ add_observation(&mut observations, path, function);
134
+ }
135
+ }
136
+ observations
137
+ .into_iter()
138
+ .map(|((path, line, symbol), invocations)| RuntimeObservation {
139
+ path,
140
+ line,
141
+ symbol,
142
+ invocations,
143
+ })
144
+ .collect()
145
+ }
146
+
147
+ fn add_observation(
148
+ observations: &mut BTreeMap<(PathBuf, Option<usize>, Option<String>), usize>,
149
+ path: &Path,
150
+ function: &RuntimeFunctionCoverage,
151
+ ) {
152
+ *observations
153
+ .entry((path.to_path_buf(), function.line, function.symbol.clone()))
154
+ .or_default() += function.invocations;
155
+ }
156
+
157
+ fn runtime_importance(
158
+ options: &HealthOptions,
159
+ functions: &[FunctionMetrics],
160
+ observations: &[RuntimeObservation],
161
+ callers: &BTreeMap<PathBuf, Vec<PathBuf>>,
162
+ total_invocations: usize,
163
+ ) -> Vec<RuntimeImportance> {
164
+ let mut importance = observations
165
+ .iter()
166
+ .map(|observation| {
167
+ let complexity = matched_complexity(functions, observation);
168
+ let caller_count = callers.get(&observation.path).map_or(0, std::vec::Vec::len);
169
+ let traffic =
170
+ LowTrafficThreshold::from_fraction(observation.invocations, total_invocations);
171
+ let score = importance_score(observation, complexity, caller_count, total_invocations);
172
+ RuntimeImportance {
173
+ id: stable_prefixed("dart-decimate:importance", observation),
174
+ stable_id: stable_prefixed("dart-decimate:fn", observation),
175
+ path: observation.path.clone(),
176
+ line: observation.line,
177
+ symbol: observation.symbol.clone(),
178
+ invocations: observation.invocations,
179
+ traffic_fraction: traffic,
180
+ cyclomatic_complexity: complexity,
181
+ caller_count,
182
+ score,
183
+ reason: importance_reason(observation, complexity, caller_count, options),
184
+ }
185
+ })
186
+ .collect::<Vec<_>>();
187
+ importance.sort_by(|left, right| {
188
+ right
189
+ .score
190
+ .cmp(&left.score)
191
+ .then_with(|| right.invocations.cmp(&left.invocations))
192
+ .then_with(|| left.path.cmp(&right.path))
193
+ .then_with(|| left.line.cmp(&right.line))
194
+ });
195
+ importance
196
+ }
197
+
198
+ fn runtime_blast_radius(
199
+ options: &HealthOptions,
200
+ observations: &[RuntimeObservation],
201
+ hot_paths: &[RuntimeHotPath],
202
+ callers: &BTreeMap<PathBuf, Vec<PathBuf>>,
203
+ total_invocations: usize,
204
+ ) -> Vec<RuntimeBlastRadius> {
205
+ let invocation_by_path = invocations_by_path(observations);
206
+ let mut rows = hot_paths
207
+ .iter()
208
+ .map(|hot_path| {
209
+ let observation = RuntimeObservation {
210
+ path: hot_path.path.clone(),
211
+ line: hot_path.line,
212
+ symbol: hot_path.symbol.clone(),
213
+ invocations: hot_path.invocations,
214
+ };
215
+ let callers = callers.get(&hot_path.path).cloned().unwrap_or_default();
216
+ let caller_reach = caller_reach(&callers, &invocation_by_path, total_invocations);
217
+ let risk = blast_risk(hot_path.invocations, callers.len(), options);
218
+ RuntimeBlastRadius {
219
+ id: stable_prefixed("dart-decimate:blast", &observation),
220
+ stable_id: stable_prefixed("dart-decimate:fn", &observation),
221
+ path: hot_path.path.clone(),
222
+ line: hot_path.line,
223
+ symbol: hot_path.symbol.clone(),
224
+ caller_count: callers.len(),
225
+ callers,
226
+ traffic_weighted_caller_reach: caller_reach,
227
+ risk,
228
+ }
229
+ })
230
+ .collect::<Vec<_>>();
231
+ rows.sort_by(|left, right| {
232
+ risk_rank(right.risk)
233
+ .cmp(&risk_rank(left.risk))
234
+ .then_with(|| right.caller_count.cmp(&left.caller_count))
235
+ .then_with(|| left.path.cmp(&right.path))
236
+ });
237
+ rows
238
+ }
239
+
240
+ fn coverage_intelligence(
241
+ project: &ScannedProject,
242
+ options: &HealthOptions,
243
+ hot_paths: &[RuntimeHotPath],
244
+ findings: &[RuntimeCoverageFinding],
245
+ total_invocations: usize,
246
+ ) -> Vec<RuntimeCoverageIntelligence> {
247
+ let mut rows = hot_paths
248
+ .iter()
249
+ .map(|hot_path| hot_path_intelligence(hot_path, options, total_invocations))
250
+ .collect::<Vec<_>>();
251
+ rows.extend(
252
+ findings
253
+ .iter()
254
+ .map(|finding| finding_intelligence(project, finding, total_invocations, options)),
255
+ );
256
+ rows.sort_by(|left, right| {
257
+ right
258
+ .priority
259
+ .cmp(&left.priority)
260
+ .then_with(|| left.path.cmp(&right.path))
261
+ .then_with(|| left.line.cmp(&right.line))
262
+ });
263
+ rows
264
+ }
265
+
266
+ fn callers_by_target(project: &ScannedProject) -> BTreeMap<PathBuf, Vec<PathBuf>> {
267
+ let mut callers = BTreeMap::<PathBuf, BTreeSet<PathBuf>>::new();
268
+ for dependency in project.graph.dependencies() {
269
+ callers
270
+ .entry(normalize_against(&project.root, &dependency.to_path))
271
+ .or_default()
272
+ .insert(normalize_against(&project.root, &dependency.from_path));
273
+ }
274
+ callers
275
+ .into_iter()
276
+ .map(|(target, sources)| (target, sources.into_iter().collect()))
277
+ .collect()
278
+ }
279
+
280
+ fn invocations_by_path(observations: &[RuntimeObservation]) -> BTreeMap<PathBuf, usize> {
281
+ let mut by_path = BTreeMap::new();
282
+ for observation in observations {
283
+ *by_path.entry(observation.path.clone()).or_default() += observation.invocations;
284
+ }
285
+ by_path
286
+ }
287
+
288
+ fn caller_reach(
289
+ callers: &[PathBuf],
290
+ invocation_by_path: &BTreeMap<PathBuf, usize>,
291
+ total_invocations: usize,
292
+ ) -> LowTrafficThreshold {
293
+ let invocations = callers
294
+ .iter()
295
+ .filter_map(|caller| invocation_by_path.get(caller))
296
+ .sum::<usize>();
297
+ LowTrafficThreshold::from_fraction(invocations, total_invocations)
298
+ }
299
+
300
+ fn matched_complexity(functions: &[FunctionMetrics], observation: &RuntimeObservation) -> usize {
301
+ functions
302
+ .iter()
303
+ .find(|function| function_matches(function, observation))
304
+ .map_or(0, |function| function.cyclomatic)
305
+ }
306
+
307
+ fn function_matches(function: &FunctionMetrics, observation: &RuntimeObservation) -> bool {
308
+ function.path == observation.path
309
+ && observation
310
+ .symbol
311
+ .as_ref()
312
+ .is_none_or(|symbol| symbol == &function.symbol)
313
+ && observation
314
+ .line
315
+ .is_none_or(|line| function.location.line <= line && line <= function.end_line)
316
+ }
317
+
318
+ fn importance_score(
319
+ observation: &RuntimeObservation,
320
+ complexity: usize,
321
+ caller_count: usize,
322
+ total_invocations: usize,
323
+ ) -> usize {
324
+ let traffic = observation
325
+ .invocations
326
+ .saturating_mul(70)
327
+ .checked_div(total_invocations)
328
+ .unwrap_or_default();
329
+ traffic
330
+ .saturating_add(complexity.min(20))
331
+ .saturating_add((caller_count * 5).min(10))
332
+ .min(100)
333
+ }
334
+
335
+ fn importance_reason(
336
+ observation: &RuntimeObservation,
337
+ complexity: usize,
338
+ caller_count: usize,
339
+ options: &HealthOptions,
340
+ ) -> String {
341
+ if observation.invocations >= options.min_invocations_hot {
342
+ return format!(
343
+ "{} runtime invocations on a hot path with cyclomatic complexity {complexity} and {caller_count} callers",
344
+ observation.invocations
345
+ );
346
+ }
347
+ format!(
348
+ "{} runtime invocations with cyclomatic complexity {complexity} and {caller_count} callers",
349
+ observation.invocations
350
+ )
351
+ }
352
+
353
+ fn hot_path_intelligence(
354
+ hot_path: &RuntimeHotPath,
355
+ options: &HealthOptions,
356
+ total_invocations: usize,
357
+ ) -> RuntimeCoverageIntelligence {
358
+ let observation = RuntimeObservation::from_hot_path(hot_path);
359
+ RuntimeCoverageIntelligence {
360
+ id: stable_prefixed("dart-decimate:coverage-intel", &observation),
361
+ stable_id: stable_prefixed("dart-decimate:fn", &observation),
362
+ kind: RuntimeCoverageIntelligenceKind::HotPathTouched,
363
+ path: hot_path.path.clone(),
364
+ line: hot_path.line,
365
+ symbol: hot_path.symbol.clone(),
366
+ action: RuntimeCoverageAction::ReviewRuntime,
367
+ priority: 100,
368
+ confidence: observation_confidence(total_invocations, options),
369
+ reason: "runtime coverage marks this function as a production hot path".to_owned(),
370
+ signals: vec!["hot-path".to_owned(), "review-runtime".to_owned()],
371
+ }
372
+ }
373
+
374
+ fn finding_intelligence(
375
+ project: &ScannedProject,
376
+ finding: &RuntimeCoverageFinding,
377
+ total_invocations: usize,
378
+ options: &HealthOptions,
379
+ ) -> RuntimeCoverageIntelligence {
380
+ let observation = RuntimeObservation {
381
+ path: finding.path.clone(),
382
+ line: Some(finding.line),
383
+ symbol: None,
384
+ invocations: finding.invocations,
385
+ };
386
+ let (kind, priority, signals) = finding_intelligence_parts(finding.kind);
387
+ RuntimeCoverageIntelligence {
388
+ id: stable_prefixed("dart-decimate:coverage-intel", &observation),
389
+ stable_id: stable_prefixed("dart-decimate:fn", &observation),
390
+ kind,
391
+ path: finding.path.clone(),
392
+ line: Some(finding.line),
393
+ symbol: None,
394
+ action: if finding.safe_to_delete {
395
+ RuntimeCoverageAction::DeleteColdCode
396
+ } else {
397
+ RuntimeCoverageAction::ReviewRuntime
398
+ },
399
+ priority,
400
+ confidence: observation_confidence(total_invocations, options),
401
+ reason: runtime_reason(project, finding),
402
+ signals,
403
+ }
404
+ }
405
+
406
+ fn finding_intelligence_parts(
407
+ kind: RuntimeCoverageFindingKind,
408
+ ) -> (RuntimeCoverageIntelligenceKind, usize, Vec<String>) {
409
+ match kind {
410
+ RuntimeCoverageFindingKind::LowTraffic => (
411
+ RuntimeCoverageIntelligenceKind::LowTraffic,
412
+ 70,
413
+ vec!["low-traffic".to_owned(), "review-runtime".to_owned()],
414
+ ),
415
+ RuntimeCoverageFindingKind::CoverageUnavailable => (
416
+ RuntimeCoverageIntelligenceKind::CoverageUnavailable,
417
+ 40,
418
+ vec![
419
+ "coverage-unavailable".to_owned(),
420
+ "review-runtime".to_owned(),
421
+ ],
422
+ ),
423
+ }
424
+ }
425
+
426
+ fn runtime_reason(project: &ScannedProject, finding: &RuntimeCoverageFinding) -> String {
427
+ let path = finding
428
+ .path
429
+ .strip_prefix(&project.root)
430
+ .unwrap_or(&finding.path)
431
+ .display();
432
+ match finding.kind {
433
+ RuntimeCoverageFindingKind::LowTraffic => {
434
+ format!("{path} ran below the configured low-traffic threshold")
435
+ }
436
+ RuntimeCoverageFindingKind::CoverageUnavailable => {
437
+ format!("{path} was scanned but absent from runtime coverage")
438
+ }
439
+ }
440
+ }
441
+
442
+ fn observation_confidence(
443
+ total_invocations: usize,
444
+ options: &HealthOptions,
445
+ ) -> RuntimeCoverageConfidence {
446
+ if total_invocations == 0 {
447
+ RuntimeCoverageConfidence::Low
448
+ } else if total_invocations >= options.min_observation_volume {
449
+ RuntimeCoverageConfidence::High
450
+ } else {
451
+ RuntimeCoverageConfidence::Medium
452
+ }
453
+ }
454
+
455
+ fn blast_risk(
456
+ invocations: usize,
457
+ caller_count: usize,
458
+ options: &HealthOptions,
459
+ ) -> RuntimeBlastRisk {
460
+ if caller_count >= 5 || invocations >= options.min_invocations_hot.saturating_mul(10) {
461
+ RuntimeBlastRisk::High
462
+ } else if caller_count >= 2 || invocations >= options.min_invocations_hot {
463
+ RuntimeBlastRisk::Medium
464
+ } else {
465
+ RuntimeBlastRisk::Low
466
+ }
467
+ }
468
+
469
+ const fn risk_rank(risk: RuntimeBlastRisk) -> usize {
470
+ match risk {
471
+ RuntimeBlastRisk::Low => 0,
472
+ RuntimeBlastRisk::Medium => 1,
473
+ RuntimeBlastRisk::High => 2,
474
+ }
475
+ }
476
+
477
+ fn stable_prefixed(prefix: &str, observation: &RuntimeObservation) -> String {
478
+ let mut hash = FNV_OFFSET;
479
+ update_hash(&mut hash, observation.path.to_string_lossy().as_bytes());
480
+ update_hash(&mut hash, &observation.line.unwrap_or(0).to_le_bytes());
481
+ if let Some(symbol) = &observation.symbol {
482
+ update_hash(&mut hash, symbol.as_bytes());
483
+ }
484
+ format!("{prefix}:{hash:016x}")
485
+ }
486
+
487
+ fn update_hash(hash: &mut u64, bytes: &[u8]) {
488
+ for byte in bytes {
489
+ *hash ^= u64::from(*byte);
490
+ *hash = hash.wrapping_mul(FNV_PRIME);
491
+ }
492
+ }
493
+
494
+ #[derive(Debug, Clone, PartialEq, Eq)]
495
+ struct RuntimeObservation {
496
+ path: PathBuf,
497
+ line: Option<usize>,
498
+ symbol: Option<String>,
499
+ invocations: usize,
500
+ }
501
+
502
+ impl RuntimeObservation {
503
+ fn from_hot_path(hot_path: &RuntimeHotPath) -> Self {
504
+ Self {
505
+ path: hot_path.path.clone(),
506
+ line: hot_path.line,
507
+ symbol: hot_path.symbol.clone(),
508
+ invocations: hot_path.invocations,
509
+ }
510
+ }
511
+ }