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,658 @@
1
+ use serde_json::{Map, Value};
2
+
3
+ mod value_args;
4
+
5
+ use value_args::{
6
+ array_strings, bool_arg, issue_filter_flag, push_bool_flag, push_bool_mode, push_float_flag,
7
+ push_noop_bool, push_number_flag, push_required_string, push_string_flag, push_string_flags,
8
+ string_arg,
9
+ };
10
+
11
+ const GLOBAL_KEYS: &[&str] = &["root", "config"];
12
+ const REPORT_SCOPE_KEYS: &[&str] = &[
13
+ "entry",
14
+ "dart_platform",
15
+ "file",
16
+ "workspace",
17
+ "changed_workspaces",
18
+ "changed_since",
19
+ "production",
20
+ ];
21
+ const LIST_SCOPE_KEYS: &[&str] = &[
22
+ "entry",
23
+ "dart_platform",
24
+ "file",
25
+ "workspace",
26
+ "changed_workspaces",
27
+ "production",
28
+ ];
29
+ const BASELINE_KEYS: &[&str] = &[
30
+ "baseline",
31
+ "regression_baseline",
32
+ "fail_on_regression",
33
+ "tolerance",
34
+ ];
35
+ const SYMBOL_KEYS: &[&str] = &["include_entry_exports", "private_type_leaks"];
36
+ const BOUNDARY_KEYS: &[&str] = &[
37
+ "boundary",
38
+ "boundary_coverage",
39
+ "boundary_call",
40
+ "policy_pack",
41
+ "policy_violations",
42
+ ];
43
+ const DUPLICATE_KEYS: &[&str] = &[
44
+ "mode",
45
+ "min_tokens",
46
+ "min_lines",
47
+ "min_occurrences",
48
+ "top",
49
+ "threshold",
50
+ "cross_language",
51
+ "skip_local",
52
+ "ignore_imports",
53
+ "no_ignore_imports",
54
+ ];
55
+ const HEALTH_KEYS: &[&str] = &[
56
+ "max_cyclomatic",
57
+ "max_cognitive",
58
+ "max_crap",
59
+ "coverage",
60
+ "runtime_coverage",
61
+ "min_invocations_hot",
62
+ "min_observation_volume",
63
+ "low_traffic_threshold",
64
+ "coverage_gaps",
65
+ "file_scores",
66
+ "hotspots",
67
+ "targets",
68
+ "ownership",
69
+ "complexity_breakdown",
70
+ "min_score",
71
+ "top",
72
+ ];
73
+ const FIX_KEYS: &[&str] = &["action", "no_create_config"];
74
+
75
+ pub(super) fn cli_args_for_tool(
76
+ name: &str,
77
+ args: &Map<String, Value>,
78
+ ) -> Result<Vec<String>, String> {
79
+ reject_unknown_args(name, args)?;
80
+ match name {
81
+ "analyze" => report_args("check", args, analyze_args),
82
+ "check_changed" => report_args("check", args, check_changed_args),
83
+ "project_info" => report_args("list", args, project_info_args),
84
+ "list_boundaries" => report_args("list", args, list_boundaries_args),
85
+ "inspect_target" => report_args("inspect", args, inspect_args),
86
+ "trace_file" => report_args("trace-file", args, trace_file_args),
87
+ "trace_export" => report_args("trace-symbol", args, trace_export_args),
88
+ "trace_dependency" => report_args("trace-dependency", args, trace_dependency_args),
89
+ "trace_clone" => report_args("trace-clone", args, trace_clone_args),
90
+ "find_dupes" => report_args("dupes", args, dupes_args),
91
+ "check_health" => report_args("health", args, health_args),
92
+ "check_runtime_coverage"
93
+ | "get_hot_paths"
94
+ | "get_blast_radius"
95
+ | "get_importance"
96
+ | "get_cleanup_candidates" => coverage_analyze_args(args),
97
+ "security_candidates" => report_args("security", args, security_args),
98
+ "feature_flags" => report_args("flags", args, flags_args),
99
+ "impact" => impact_args(args),
100
+ "impact_all" => impact_all_args(args),
101
+ "fix_preview" => fix_preview_args(args),
102
+ "fix_apply" => fix_apply_args(args),
103
+ "audit" => report_args("audit", args, audit_args),
104
+ "decision_surface" => report_args("decision-surface", args, decision_surface_args),
105
+ "dart_decimate_explain" | "fallow_explain" => explain_args(name, args),
106
+ _ => Err(format!("unknown tool {name}")),
107
+ }
108
+ }
109
+
110
+ fn reject_unknown_args(name: &str, args: &Map<String, Value>) -> Result<(), String> {
111
+ let allowed = allowed_args(name)?;
112
+ for key in args.keys() {
113
+ if !allowed.contains(&key.as_str()) {
114
+ return Err(format!("{name} does not accept argument {key}"));
115
+ }
116
+ }
117
+ Ok(())
118
+ }
119
+
120
+ fn allowed_args(name: &str) -> Result<Vec<&'static str>, String> {
121
+ let mut allowed = GLOBAL_KEYS.to_vec();
122
+ match name {
123
+ "analyze" => extend_analyze_allowed(&mut allowed),
124
+ "check_changed" => extend_check_changed_allowed(&mut allowed),
125
+ "project_info" => extend_project_info_allowed(&mut allowed),
126
+ "list_boundaries" => allowed.extend(LIST_SCOPE_KEYS),
127
+ "inspect_target" => allowed.extend(["target", "file", "symbol", "production"]),
128
+ "trace_file" => allowed.extend(["file"]),
129
+ "trace_export" => allowed.extend(["file", "symbol", "export_name"]),
130
+ "trace_dependency" => allowed.extend(["dependency", "package_name"]),
131
+ "trace_clone" => extend_trace_clone_allowed(&mut allowed),
132
+ "find_dupes" => extend_dupes_allowed(&mut allowed),
133
+ "check_health" => extend_health_allowed(&mut allowed),
134
+ "check_runtime_coverage"
135
+ | "get_hot_paths"
136
+ | "get_blast_radius"
137
+ | "get_importance"
138
+ | "get_cleanup_candidates" => extend_runtime_allowed(&mut allowed),
139
+ "security_candidates" => extend_security_allowed(&mut allowed),
140
+ "feature_flags" => extend_flags_allowed(&mut allowed),
141
+ "impact" => return Ok(vec!["root"]),
142
+ "impact_all" => return Ok(vec!["sort", "limit"]),
143
+ "fix_preview" => extend_fix_allowed(&mut allowed),
144
+ "fix_apply" => extend_fix_apply_allowed(&mut allowed),
145
+ "audit" => extend_audit_allowed(&mut allowed),
146
+ "decision_surface" => allowed.extend(["base", "max_decisions"]),
147
+ "dart_decimate_explain" | "fallow_explain" => return Ok(vec!["issue_type", "rule_id"]),
148
+ _ => return Err(format!("unknown tool {name}")),
149
+ }
150
+ allowed.sort_unstable();
151
+ allowed.dedup();
152
+ Ok(allowed)
153
+ }
154
+
155
+ fn extend_analyze_allowed(allowed: &mut Vec<&'static str>) {
156
+ allowed.extend(["issue_types"]);
157
+ allowed.extend(REPORT_SCOPE_KEYS);
158
+ allowed.extend(BASELINE_KEYS);
159
+ allowed.extend(SYMBOL_KEYS);
160
+ allowed.extend(BOUNDARY_KEYS);
161
+ allowed.extend(DUPLICATE_KEYS);
162
+ allowed.extend(HEALTH_KEYS);
163
+ }
164
+
165
+ fn extend_check_changed_allowed(allowed: &mut Vec<&'static str>) {
166
+ allowed.extend(["since", "changed_since"]);
167
+ allowed.extend(BASELINE_KEYS);
168
+ allowed.extend(["dart_platform", "production"]);
169
+ }
170
+
171
+ fn extend_project_info_allowed(allowed: &mut Vec<&'static str>) {
172
+ allowed.extend([
173
+ "files",
174
+ "entry_points",
175
+ "plugins",
176
+ "boundaries",
177
+ "workspaces",
178
+ ]);
179
+ allowed.extend(LIST_SCOPE_KEYS);
180
+ }
181
+
182
+ fn extend_dupes_allowed(allowed: &mut Vec<&'static str>) {
183
+ allowed.extend(REPORT_SCOPE_KEYS);
184
+ allowed.extend(BASELINE_KEYS);
185
+ allowed.extend(DUPLICATE_KEYS);
186
+ }
187
+
188
+ fn extend_trace_clone_allowed(allowed: &mut Vec<&'static str>) {
189
+ allowed.extend(["fingerprint", "file", "line"]);
190
+ allowed.extend(DUPLICATE_KEYS);
191
+ }
192
+
193
+ fn extend_health_allowed(allowed: &mut Vec<&'static str>) {
194
+ allowed.extend(REPORT_SCOPE_KEYS);
195
+ allowed.extend(BASELINE_KEYS);
196
+ allowed.extend(HEALTH_KEYS);
197
+ }
198
+
199
+ fn extend_runtime_allowed(allowed: &mut Vec<&'static str>) {
200
+ allowed.extend([
201
+ "coverage",
202
+ "min_invocations_hot",
203
+ "min_observation_volume",
204
+ "low_traffic_threshold",
205
+ "top",
206
+ "repo",
207
+ ]);
208
+ }
209
+
210
+ fn extend_security_allowed(allowed: &mut Vec<&'static str>) {
211
+ allowed.extend(REPORT_SCOPE_KEYS);
212
+ allowed.extend(BASELINE_KEYS);
213
+ allowed.extend([
214
+ "top",
215
+ "surface",
216
+ "gate",
217
+ "paths",
218
+ "diff_file",
219
+ "ci",
220
+ "fail_on_issues",
221
+ "summary",
222
+ ]);
223
+ }
224
+
225
+ fn extend_flags_allowed(allowed: &mut Vec<&'static str>) {
226
+ allowed.extend(REPORT_SCOPE_KEYS);
227
+ allowed.extend(BASELINE_KEYS);
228
+ allowed.extend(["top"]);
229
+ }
230
+
231
+ fn extend_fix_allowed(allowed: &mut Vec<&'static str>) {
232
+ allowed.extend(REPORT_SCOPE_KEYS);
233
+ allowed.extend(FIX_KEYS);
234
+ }
235
+
236
+ fn extend_fix_apply_allowed(allowed: &mut Vec<&'static str>) {
237
+ extend_fix_allowed(allowed);
238
+ allowed.extend(["yes"]);
239
+ }
240
+
241
+ fn extend_audit_allowed(allowed: &mut Vec<&'static str>) {
242
+ allowed.extend(REPORT_SCOPE_KEYS);
243
+ allowed.extend(SYMBOL_KEYS);
244
+ allowed.extend(BOUNDARY_KEYS);
245
+ allowed.extend(DUPLICATE_KEYS);
246
+ allowed.extend(HEALTH_KEYS);
247
+ allowed.extend([
248
+ "base",
249
+ "gate",
250
+ "brief",
251
+ "dead_code_baseline",
252
+ "health_baseline",
253
+ "dupes_baseline",
254
+ "max_decisions",
255
+ ]);
256
+ }
257
+
258
+ fn report_args<F>(
259
+ command: &str,
260
+ args: &Map<String, Value>,
261
+ append: F,
262
+ ) -> Result<Vec<String>, String>
263
+ where
264
+ F: FnOnce(&mut Vec<String>, &Map<String, Value>) -> Result<(), String>,
265
+ {
266
+ let mut cli = json_command_args(&[command]);
267
+ push_string_flag(&mut cli, args, "root", "--root")?;
268
+ push_string_flag(&mut cli, args, "config", "--config")?;
269
+ append(&mut cli, args)?;
270
+ Ok(cli)
271
+ }
272
+
273
+ fn json_command_args(command: &[&str]) -> Vec<String> {
274
+ let mut cli = vec!["dart-decimate".to_owned()];
275
+ cli.extend(command.iter().map(|part| (*part).to_owned()));
276
+ cli.extend(["--format".to_owned(), "json".to_owned()]);
277
+ cli
278
+ }
279
+
280
+ fn analyze_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
281
+ push_report_scope_args(cli, args)?;
282
+ push_baseline_args(cli, args)?;
283
+ push_symbol_args(cli, args)?;
284
+ push_boundary_args(cli, args)?;
285
+ push_duplicate_args(cli, args)?;
286
+ push_health_args(cli, args)?;
287
+ if let Some(issue_types) = args.get("issue_types") {
288
+ for issue_type in array_strings(issue_types, "issue_types")? {
289
+ cli.push(issue_filter_flag(issue_type)?);
290
+ }
291
+ }
292
+ Ok(())
293
+ }
294
+
295
+ fn check_changed_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
296
+ let since = string_arg(args, "since")?
297
+ .or(string_arg(args, "changed_since")?)
298
+ .ok_or_else(|| "check_changed requires since".to_owned())?;
299
+ cli.extend(["--changed-since".to_owned(), since]);
300
+ push_baseline_args(cli, args)?;
301
+ push_string_flag(cli, args, "dart_platform", "--dart-platform")?;
302
+ push_bool_mode(cli, args, "production", "--production", "--no-production")
303
+ }
304
+
305
+ fn project_info_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
306
+ push_string_flags(cli, args, "entry", "--entry")?;
307
+ push_string_flag(cli, args, "dart_platform", "--dart-platform")?;
308
+ push_string_flags(cli, args, "file", "--file")?;
309
+ push_string_flags(cli, args, "workspace", "--workspace")?;
310
+ push_string_flag(cli, args, "changed_workspaces", "--changed-workspaces")?;
311
+ push_bool_mode(cli, args, "production", "--production", "--no-production")?;
312
+ for (key, flag) in [
313
+ ("files", "--files"),
314
+ ("entry_points", "--entry-points"),
315
+ ("plugins", "--plugins"),
316
+ ("boundaries", "--boundaries"),
317
+ ("workspaces", "--workspaces"),
318
+ ] {
319
+ push_bool_flag(cli, args, key, flag)?;
320
+ }
321
+ Ok(())
322
+ }
323
+
324
+ fn list_boundaries_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
325
+ push_string_flags(cli, args, "entry", "--entry")?;
326
+ push_string_flag(cli, args, "dart_platform", "--dart-platform")?;
327
+ push_string_flags(cli, args, "file", "--file")?;
328
+ push_string_flags(cli, args, "workspace", "--workspace")?;
329
+ push_string_flag(cli, args, "changed_workspaces", "--changed-workspaces")?;
330
+ push_bool_mode(cli, args, "production", "--production", "--no-production")?;
331
+ cli.push("--boundaries".to_owned());
332
+ Ok(())
333
+ }
334
+
335
+ fn inspect_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
336
+ if let Some(target) = args.get("target") {
337
+ let target = target
338
+ .as_object()
339
+ .ok_or_else(|| "target must be an object".to_owned())?;
340
+ match target.get("type").and_then(Value::as_str) {
341
+ Some("file") => {
342
+ reject_nested_unknown(target, &["type", "file"])?;
343
+ push_required_string(cli, target, "file", "--file")
344
+ }
345
+ Some("symbol") => push_symbol_target(cli, target),
346
+ _ => Err("target.type must be file or symbol".to_owned()),
347
+ }?;
348
+ } else if args.contains_key("file") {
349
+ push_required_string(cli, args, "file", "--file")?;
350
+ } else if args.contains_key("symbol") {
351
+ push_required_string(cli, args, "symbol", "--symbol")?;
352
+ } else {
353
+ return Err("inspect_target requires target, file, or symbol".to_owned());
354
+ }
355
+ push_bool_mode(cli, args, "production", "--production", "--no-production")
356
+ }
357
+
358
+ fn trace_file_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
359
+ push_required_string(cli, args, "file", "--file")
360
+ }
361
+
362
+ fn trace_export_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
363
+ push_required_string(cli, args, "file", "--file")?;
364
+ if let Some(export_name) = string_arg(args, "export_name")? {
365
+ cli.extend(["--symbol".to_owned(), export_name]);
366
+ return Ok(());
367
+ }
368
+ push_required_string(cli, args, "symbol", "--symbol")
369
+ }
370
+
371
+ fn trace_dependency_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
372
+ if let Some(package) = string_arg(args, "package_name")? {
373
+ cli.extend(["--dependency".to_owned(), package]);
374
+ return Ok(());
375
+ }
376
+ push_required_string(cli, args, "dependency", "--dependency")
377
+ }
378
+
379
+ fn trace_clone_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
380
+ if args.contains_key("fingerprint") && (args.contains_key("file") || args.contains_key("line"))
381
+ {
382
+ return Err("trace_clone accepts either fingerprint or file and line".to_owned());
383
+ }
384
+ if let Some(fingerprint) = string_arg(args, "fingerprint")? {
385
+ cli.extend(["--fingerprint".to_owned(), fingerprint]);
386
+ } else {
387
+ let file = string_arg(args, "file")?
388
+ .ok_or_else(|| "trace_clone requires fingerprint or file and line".to_owned())?;
389
+ let line = args
390
+ .get("line")
391
+ .and_then(Value::as_u64)
392
+ .ok_or_else(|| "trace_clone line must be a positive integer".to_owned())?;
393
+ if line == 0 {
394
+ return Err("trace_clone line must be a positive integer".to_owned());
395
+ }
396
+ cli.extend(["--fingerprint".to_owned(), format!("{file}:{line}")]);
397
+ }
398
+ push_duplicate_args(cli, args)
399
+ }
400
+
401
+ fn dupes_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
402
+ push_report_scope_args(cli, args)?;
403
+ push_baseline_args(cli, args)?;
404
+ push_duplicate_args(cli, args)
405
+ }
406
+
407
+ fn push_duplicate_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
408
+ push_string_flag(cli, args, "mode", "--mode")?;
409
+ push_number_flag(cli, args, "min_tokens", "--min-tokens")?;
410
+ push_number_flag(cli, args, "min_lines", "--min-lines")?;
411
+ push_number_flag(cli, args, "min_occurrences", "--min-occurrences")?;
412
+ push_number_flag(cli, args, "top", "--top")?;
413
+ push_float_flag(cli, args, "threshold", "--threshold")?;
414
+ if bool_arg(args, "cross_language")?.unwrap_or_default() {
415
+ return Err("cross_language is not supported for Dart-only analysis".to_owned());
416
+ }
417
+ for (key, flag) in [
418
+ ("skip_local", "--skip-local"),
419
+ ("ignore_imports", "--ignore-imports"),
420
+ ("no_ignore_imports", "--no-ignore-imports"),
421
+ ] {
422
+ push_bool_flag(cli, args, key, flag)?;
423
+ }
424
+ Ok(())
425
+ }
426
+
427
+ fn health_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
428
+ push_report_scope_args(cli, args)?;
429
+ push_baseline_args(cli, args)?;
430
+ push_health_args(cli, args)
431
+ }
432
+
433
+ fn coverage_analyze_args(args: &Map<String, Value>) -> Result<Vec<String>, String> {
434
+ let mut cli = json_command_args(&["coverage", "analyze"]);
435
+ push_string_flag(&mut cli, args, "root", "--root")?;
436
+ push_string_flag(&mut cli, args, "config", "--config")?;
437
+ push_required_string(&mut cli, args, "coverage", "--runtime-coverage")?;
438
+ push_number_flag(
439
+ &mut cli,
440
+ args,
441
+ "min_invocations_hot",
442
+ "--min-invocations-hot",
443
+ )?;
444
+ push_number_flag(
445
+ &mut cli,
446
+ args,
447
+ "min_observation_volume",
448
+ "--min-observation-volume",
449
+ )?;
450
+ push_float_flag(
451
+ &mut cli,
452
+ args,
453
+ "low_traffic_threshold",
454
+ "--low-traffic-threshold",
455
+ )?;
456
+ push_number_flag(&mut cli, args, "top", "--top")?;
457
+ push_string_flag(&mut cli, args, "repo", "--repo")?;
458
+ Ok(cli)
459
+ }
460
+
461
+ fn push_health_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
462
+ push_number_flag(cli, args, "max_cyclomatic", "--max-cyclomatic")?;
463
+ push_number_flag(cli, args, "max_cognitive", "--max-cognitive")?;
464
+ push_number_flag(cli, args, "max_crap", "--max-crap")?;
465
+ push_string_flag(cli, args, "coverage", "--coverage")?;
466
+ push_string_flag(cli, args, "runtime_coverage", "--runtime-coverage")?;
467
+ push_number_flag(cli, args, "min_invocations_hot", "--min-invocations-hot")?;
468
+ push_number_flag(
469
+ cli,
470
+ args,
471
+ "min_observation_volume",
472
+ "--min-observation-volume",
473
+ )?;
474
+ push_float_flag(
475
+ cli,
476
+ args,
477
+ "low_traffic_threshold",
478
+ "--low-traffic-threshold",
479
+ )?;
480
+ for (key, flag) in [
481
+ ("coverage_gaps", "--coverage-gaps"),
482
+ ("file_scores", "--file-scores"),
483
+ ("hotspots", "--hotspots"),
484
+ ("targets", "--targets"),
485
+ ("ownership", "--ownership"),
486
+ ("complexity_breakdown", "--complexity-breakdown"),
487
+ ] {
488
+ push_bool_flag(cli, args, key, flag)?;
489
+ }
490
+ push_number_flag(cli, args, "min_score", "--min-score")?;
491
+ push_number_flag(cli, args, "top", "--top")?;
492
+ Ok(())
493
+ }
494
+
495
+ fn security_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
496
+ push_report_scope_args(cli, args)?;
497
+ push_baseline_args(cli, args)?;
498
+ push_number_flag(cli, args, "top", "--top")?;
499
+ push_bool_flag(cli, args, "surface", "--surface")?;
500
+ push_string_flag(cli, args, "gate", "--gate")?;
501
+ push_string_flags(cli, args, "paths", "--file")?;
502
+ push_string_flag(cli, args, "diff_file", "--diff-file")?;
503
+ for (key, flag) in [
504
+ ("ci", "--ci"),
505
+ ("fail_on_issues", "--fail-on-issues"),
506
+ ("summary", "--summary"),
507
+ ] {
508
+ push_bool_flag(cli, args, key, flag)?;
509
+ }
510
+ Ok(())
511
+ }
512
+
513
+ fn flags_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
514
+ push_report_scope_args(cli, args)?;
515
+ push_baseline_args(cli, args)?;
516
+ push_number_flag(cli, args, "top", "--top")?;
517
+ Ok(())
518
+ }
519
+
520
+ fn impact_args(args: &Map<String, Value>) -> Result<Vec<String>, String> {
521
+ let mut cli = json_command_args(&["impact"]);
522
+ cli.push("--quiet".to_owned());
523
+ push_string_flag(&mut cli, args, "root", "--root")?;
524
+ Ok(cli)
525
+ }
526
+
527
+ fn impact_all_args(args: &Map<String, Value>) -> Result<Vec<String>, String> {
528
+ let mut cli = json_command_args(&["impact"]);
529
+ cli.extend(["--quiet".to_owned(), "--all".to_owned()]);
530
+ push_string_flag(&mut cli, args, "sort", "--sort")?;
531
+ push_number_flag(&mut cli, args, "limit", "--limit")?;
532
+ Ok(cli)
533
+ }
534
+
535
+ fn fix_preview_args(args: &Map<String, Value>) -> Result<Vec<String>, String> {
536
+ let mut cli = json_command_args(&["fix"]);
537
+ push_string_flag(&mut cli, args, "root", "--root")?;
538
+ push_string_flag(&mut cli, args, "config", "--config")?;
539
+ push_report_scope_args(&mut cli, args)?;
540
+ push_string_flags(&mut cli, args, "action", "--action")?;
541
+ push_noop_bool(args, "no_create_config")?;
542
+ cli.push("--dry-run".to_owned());
543
+ Ok(cli)
544
+ }
545
+
546
+ fn fix_apply_args(args: &Map<String, Value>) -> Result<Vec<String>, String> {
547
+ if bool_arg(args, "yes")? != Some(true) {
548
+ return Err("fix_apply requires yes: true".to_owned());
549
+ }
550
+ let mut cli = json_command_args(&["fix"]);
551
+ push_string_flag(&mut cli, args, "root", "--root")?;
552
+ push_string_flag(&mut cli, args, "config", "--config")?;
553
+ push_report_scope_args(&mut cli, args)?;
554
+ push_string_flags(&mut cli, args, "action", "--action")?;
555
+ push_noop_bool(args, "no_create_config")?;
556
+ cli.push("--yes".to_owned());
557
+ Ok(cli)
558
+ }
559
+
560
+ fn audit_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
561
+ push_required_string(cli, args, "base", "--base")?;
562
+ push_string_flag(cli, args, "gate", "--gate")?;
563
+ push_report_scope_args(cli, args)?;
564
+ push_symbol_args(cli, args)?;
565
+ push_boundary_args(cli, args)?;
566
+ push_duplicate_args(cli, args)?;
567
+ push_health_args(cli, args)?;
568
+ for (key, flag) in [
569
+ ("dead_code_baseline", "--dead-code-baseline"),
570
+ ("health_baseline", "--health-baseline"),
571
+ ("dupes_baseline", "--dupes-baseline"),
572
+ ] {
573
+ push_string_flag(cli, args, key, flag)?;
574
+ }
575
+ push_number_flag(cli, args, "max_decisions", "--max-decisions")?;
576
+ push_bool_flag(cli, args, "brief", "--brief")?;
577
+ Ok(())
578
+ }
579
+
580
+ fn decision_surface_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
581
+ push_required_string(cli, args, "base", "--base")?;
582
+ push_number_flag(cli, args, "max_decisions", "--max-decisions")?;
583
+ Ok(())
584
+ }
585
+
586
+ fn explain_args(name: &str, args: &Map<String, Value>) -> Result<Vec<String>, String> {
587
+ let issue_type = string_arg(args, "issue_type")?
588
+ .or(string_arg(args, "rule_id")?)
589
+ .ok_or_else(|| format!("{name} requires issue_type"))?;
590
+ Ok(vec![
591
+ "dart-decimate".to_owned(),
592
+ "explain".to_owned(),
593
+ issue_type,
594
+ "--format".to_owned(),
595
+ "json".to_owned(),
596
+ ])
597
+ }
598
+
599
+ fn push_report_scope_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
600
+ push_string_flags(cli, args, "entry", "--entry")?;
601
+ push_string_flag(cli, args, "dart_platform", "--dart-platform")?;
602
+ push_string_flags(cli, args, "file", "--file")?;
603
+ push_string_flags(cli, args, "workspace", "--workspace")?;
604
+ push_string_flag(cli, args, "changed_workspaces", "--changed-workspaces")?;
605
+ push_string_flag(cli, args, "changed_since", "--changed-since")?;
606
+ push_bool_mode(cli, args, "production", "--production", "--no-production")?;
607
+ Ok(())
608
+ }
609
+
610
+ fn push_baseline_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
611
+ push_string_flag(cli, args, "baseline", "--baseline")?;
612
+ push_string_flag(cli, args, "regression_baseline", "--regression-baseline")?;
613
+ push_bool_flag(cli, args, "fail_on_regression", "--fail-on-regression")?;
614
+ push_string_flag(cli, args, "tolerance", "--tolerance")?;
615
+ Ok(())
616
+ }
617
+
618
+ fn push_symbol_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
619
+ push_bool_flag(
620
+ cli,
621
+ args,
622
+ "include_entry_exports",
623
+ "--include-entry-exports",
624
+ )?;
625
+ push_bool_flag(cli, args, "private_type_leaks", "--private-type-leaks")
626
+ }
627
+
628
+ fn push_boundary_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
629
+ push_string_flags(cli, args, "boundary", "--boundary")?;
630
+ push_bool_flag(cli, args, "boundary_coverage", "--boundary-coverage")?;
631
+ push_string_flags(cli, args, "boundary_call", "--boundary-call")?;
632
+ push_string_flags(cli, args, "policy_pack", "--policy-pack")?;
633
+ push_bool_flag(cli, args, "policy_violations", "--policy-violations")
634
+ }
635
+
636
+ fn push_symbol_target(cli: &mut Vec<String>, target: &Map<String, Value>) -> Result<(), String> {
637
+ reject_nested_unknown(target, &["type", "file", "symbol", "export_name"])?;
638
+ let file = target
639
+ .get("file")
640
+ .and_then(Value::as_str)
641
+ .ok_or_else(|| "symbol target requires file".to_owned())?;
642
+ let symbol = target
643
+ .get("export_name")
644
+ .or_else(|| target.get("symbol"))
645
+ .and_then(Value::as_str)
646
+ .ok_or_else(|| "symbol target requires export_name or symbol".to_owned())?;
647
+ cli.extend(["--symbol".to_owned(), format!("{file}:{symbol}")]);
648
+ Ok(())
649
+ }
650
+
651
+ fn reject_nested_unknown(value: &Map<String, Value>, allowed: &[&str]) -> Result<(), String> {
652
+ for key in value.keys() {
653
+ if !allowed.contains(&key.as_str()) {
654
+ return Err(format!("target does not accept argument {key}"));
655
+ }
656
+ }
657
+ Ok(())
658
+ }