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.
- package/Cargo.lock +572 -0
- package/Cargo.toml +41 -0
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/bin/dart-decimate-mcp.js +48 -0
- package/npm/bin/dart-decimate.js +48 -0
- package/npm/scripts/postinstall.js +46 -0
- package/npm/scripts/test-npx-local.js +54 -0
- package/npm/scripts/test-npx-mcp-local.js +56 -0
- package/package.json +45 -0
- package/src/baseline.rs +643 -0
- package/src/bin/dart-decimate-mcp.rs +11 -0
- package/src/boundaries/tests.rs +60 -0
- package/src/boundaries.rs +317 -0
- package/src/changed_scope.rs +117 -0
- package/src/ci_template.rs +399 -0
- package/src/cli/analyze.rs +462 -0
- package/src/cli/analyzer_options.rs +82 -0
- package/src/cli/audit_run.rs +327 -0
- package/src/cli/boundary_args.rs +44 -0
- package/src/cli/ci_template_run.rs +196 -0
- package/src/cli/command_name.rs +20 -0
- package/src/cli/common_args.rs +167 -0
- package/src/cli/config_run.rs +78 -0
- package/src/cli/coverage_run.rs +393 -0
- package/src/cli/decision_surface_run.rs +99 -0
- package/src/cli/default_command.rs +69 -0
- package/src/cli/dupes_args.rs +150 -0
- package/src/cli/entry_points.rs +121 -0
- package/src/cli/error.rs +149 -0
- package/src/cli/error_output.rs +68 -0
- package/src/cli/explain_run.rs +72 -0
- package/src/cli/fix_run.rs +162 -0
- package/src/cli/flags_args.rs +23 -0
- package/src/cli/health_args.rs +200 -0
- package/src/cli/hooks_run.rs +191 -0
- package/src/cli/impact_run.rs +95 -0
- package/src/cli/init_run.rs +49 -0
- package/src/cli/inspect_args.rs +20 -0
- package/src/cli/inspect_run.rs +66 -0
- package/src/cli/issue_filter_args.rs +240 -0
- package/src/cli/list_run.rs +311 -0
- package/src/cli/mode_args.rs +72 -0
- package/src/cli/output_format.rs +62 -0
- package/src/cli/regression_args.rs +156 -0
- package/src/cli/request_args.rs +175 -0
- package/src/cli/schema_commands.rs +72 -0
- package/src/cli/scope_args.rs +174 -0
- package/src/cli/security_args.rs +175 -0
- package/src/cli/security_gate_run.rs +66 -0
- package/src/cli/security_summary_run.rs +43 -0
- package/src/cli/summary_args.rs +12 -0
- package/src/cli/tests.rs +516 -0
- package/src/cli/trace_args.rs +67 -0
- package/src/cli/trace_run.rs +131 -0
- package/src/cli/trace_tests.rs +235 -0
- package/src/cli/unsupported_run.rs +116 -0
- package/src/cli/watch_run.rs +153 -0
- package/src/cli.rs +603 -0
- package/src/config/boundary_config.rs +235 -0
- package/src/config/cache.rs +25 -0
- package/src/config/dependencies.rs +114 -0
- package/src/config/health.rs +237 -0
- package/src/config/jsonc.rs +66 -0
- package/src/config/policy.rs +91 -0
- package/src/config/rule_aliases.rs +487 -0
- package/src/config/rules.rs +339 -0
- package/src/config.rs +635 -0
- package/src/coverage.rs +469 -0
- package/src/dart_parser.rs +673 -0
- package/src/decision_surface.rs +405 -0
- package/src/dependencies/analyze.rs +218 -0
- package/src/dependencies/codegen.rs +118 -0
- package/src/dependencies/discovery.rs +60 -0
- package/src/dependencies/overrides.rs +76 -0
- package/src/dependencies/private_src_imports.rs +32 -0
- package/src/dependencies/pubspec_document.rs +86 -0
- package/src/dependencies/pubspec_entry.rs +96 -0
- package/src/dependencies/tests.rs +544 -0
- package/src/dependencies/usage.rs +33 -0
- package/src/dependencies.rs +553 -0
- package/src/dependency_scripts.rs +91 -0
- package/src/dupes/lex.rs +236 -0
- package/src/dupes/tests.rs +119 -0
- package/src/dupes.rs +625 -0
- package/src/explain.rs +692 -0
- package/src/extract/directives.rs +252 -0
- package/src/extract/error_tests.rs +25 -0
- package/src/extract/members.rs +210 -0
- package/src/extract/primary_constructors.rs +421 -0
- package/src/extract/references.rs +151 -0
- package/src/extract/routes.rs +691 -0
- package/src/extract/signatures.rs +266 -0
- package/src/extract/string_tests.rs +18 -0
- package/src/extract/strings.rs +107 -0
- package/src/extract/tests.rs +697 -0
- package/src/extract.rs +680 -0
- package/src/feature_flags/tests.rs +76 -0
- package/src/feature_flags.rs +453 -0
- package/src/finding_identity.rs +60 -0
- package/src/fix.rs +551 -0
- package/src/generated.rs +53 -0
- package/src/graph/augment_tests.rs +212 -0
- package/src/graph/conditionals.rs +74 -0
- package/src/graph/package_config_tests.rs +100 -0
- package/src/graph/parts.rs +248 -0
- package/src/graph/pubspec_tests.rs +119 -0
- package/src/graph/tests.rs +837 -0
- package/src/graph/uri_tests.rs +102 -0
- package/src/graph.rs +644 -0
- package/src/health/coverage.rs +309 -0
- package/src/health/ownership.rs +175 -0
- package/src/health/runtime_coverage.rs +616 -0
- package/src/health/runtime_intelligence.rs +511 -0
- package/src/health/scores.rs +296 -0
- package/src/health/tests.rs +240 -0
- package/src/health/threshold_types.rs +163 -0
- package/src/health/thresholds.rs +229 -0
- package/src/health/types.rs +636 -0
- package/src/health.rs +597 -0
- package/src/hooks/agent_settings.rs +175 -0
- package/src/hooks/templates.rs +51 -0
- package/src/hooks.rs +569 -0
- package/src/impact.rs +287 -0
- package/src/init.rs +237 -0
- package/src/inspect.rs +142 -0
- package/src/intelligence/tests.rs +232 -0
- package/src/intelligence.rs +305 -0
- package/src/lib.rs +198 -0
- package/src/main.rs +5 -0
- package/src/manifest/mcp.rs +565 -0
- package/src/manifest.rs +552 -0
- package/src/mcp/cli_args/value_args.rs +175 -0
- package/src/mcp/cli_args.rs +658 -0
- package/src/mcp/cli_args_tests.rs +522 -0
- package/src/mcp/code_execute.rs +671 -0
- package/src/mcp/tools.rs +660 -0
- package/src/mcp.rs +325 -0
- package/src/output/audit_risk.rs +135 -0
- package/src/output/dependency_findings.rs +327 -0
- package/src/output/duplication_findings.rs +114 -0
- package/src/output/feature_flag_findings.rs +122 -0
- package/src/output/format.rs +31 -0
- package/src/output/graph_findings.rs +461 -0
- package/src/output/health_findings.rs +612 -0
- package/src/output/human.rs +27 -0
- package/src/output/next_steps.rs +92 -0
- package/src/output/route_findings.rs +76 -0
- package/src/output/runtime_coverage.rs +515 -0
- package/src/output/scope.rs +183 -0
- package/src/output/security_findings.rs +390 -0
- package/src/output/security_sarif.rs +150 -0
- package/src/output/suppressions.rs +323 -0
- package/src/output/symbol_findings.rs +257 -0
- package/src/output/tests.rs +114 -0
- package/src/output/types.rs +604 -0
- package/src/output/widget_findings.rs +213 -0
- package/src/output.rs +682 -0
- package/src/package_map.rs +495 -0
- package/src/policy/packs.rs +232 -0
- package/src/policy/tests.rs +134 -0
- package/src/policy.rs +640 -0
- package/src/project_list.rs +376 -0
- package/src/report_schema/inventory.rs +418 -0
- package/src/report_schema.rs +488 -0
- package/src/routes.rs +354 -0
- package/src/scan/tests.rs +250 -0
- package/src/scan.rs +275 -0
- package/src/security/detect.rs +639 -0
- package/src/security/tests.rs +178 -0
- package/src/security.rs +373 -0
- package/src/security_gate.rs +555 -0
- package/src/symbols/path_filters.rs +27 -0
- package/src/symbols/private_type_leaks.rs +125 -0
- package/src/symbols/riverpod.rs +113 -0
- package/src/symbols/tests.rs +692 -0
- package/src/symbols.rs +693 -0
- package/src/trace/tests.rs +225 -0
- package/src/trace.rs +690 -0
- package/src/unsupported.rs +47 -0
- package/src/widgets/lifecycle.rs +484 -0
- package/src/widgets/params.rs +236 -0
- package/src/widgets/tests.rs +430 -0
- package/src/widgets/top_level.rs +110 -0
- package/src/widgets/unrendered.rs +374 -0
- package/src/widgets.rs +590 -0
- package/src/workspace_scope.rs +358 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
use std::path::Path;
|
|
2
|
+
|
|
3
|
+
use serde_json::{Map, Value, json};
|
|
4
|
+
|
|
5
|
+
use super::{
|
|
6
|
+
AGENT_COMMAND, HookAction, HookFile, HooksError, claude_settings_path, missing_file, read_hook,
|
|
7
|
+
relative_path, write_text,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
pub(super) fn install_claude_settings(root: &Path, force: bool) -> Result<HookFile, HooksError> {
|
|
11
|
+
let path = claude_settings_path(root);
|
|
12
|
+
let (mut settings, action) = if path.exists() {
|
|
13
|
+
let source = read_hook(&path)?;
|
|
14
|
+
if settings_source_has_agent_command(&source) {
|
|
15
|
+
return claude_settings_status(root, HookAction::Unchanged);
|
|
16
|
+
}
|
|
17
|
+
match serde_json::from_str::<Value>(&source) {
|
|
18
|
+
Ok(value) if value.is_object() => (value, HookAction::Overwritten),
|
|
19
|
+
_ if force => (json!({}), HookAction::Overwritten),
|
|
20
|
+
_ => {
|
|
21
|
+
return Err(HooksError::UnmanagedHook { path: path.clone() });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
(json!({}), HookAction::Created)
|
|
26
|
+
};
|
|
27
|
+
add_agent_command_to_settings(&mut settings);
|
|
28
|
+
let source = serde_json::to_string_pretty(&settings).map_err(|source| HooksError::Write {
|
|
29
|
+
path: path.clone(),
|
|
30
|
+
source: std::io::Error::other(source),
|
|
31
|
+
})?;
|
|
32
|
+
write_text(&path, &format!("{source}\n"))?;
|
|
33
|
+
claude_settings_status(root, action)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
pub(super) fn uninstall_claude_settings(root: &Path, force: bool) -> Result<HookFile, HooksError> {
|
|
37
|
+
let path = claude_settings_path(root);
|
|
38
|
+
if !path.exists() {
|
|
39
|
+
return Ok(missing_file(root, &path));
|
|
40
|
+
}
|
|
41
|
+
let source = read_hook(&path)?;
|
|
42
|
+
if !settings_source_has_agent_command(&source) {
|
|
43
|
+
return claude_settings_status(root, HookAction::Unchanged);
|
|
44
|
+
}
|
|
45
|
+
let mut settings = match serde_json::from_str::<Value>(&source) {
|
|
46
|
+
Ok(value) => value,
|
|
47
|
+
Err(_) if force => json!({}),
|
|
48
|
+
Err(_) => {
|
|
49
|
+
return Err(HooksError::UnmanagedHook { path: path.clone() });
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
remove_agent_command_from_settings(&mut settings);
|
|
53
|
+
let source = serde_json::to_string_pretty(&settings).map_err(|source| HooksError::Write {
|
|
54
|
+
path: path.clone(),
|
|
55
|
+
source: std::io::Error::other(source),
|
|
56
|
+
})?;
|
|
57
|
+
write_text(&path, &format!("{source}\n"))?;
|
|
58
|
+
claude_settings_status(root, HookAction::Removed)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
pub(super) fn claude_settings_status(
|
|
62
|
+
root: &Path,
|
|
63
|
+
action: HookAction,
|
|
64
|
+
) -> Result<HookFile, HooksError> {
|
|
65
|
+
let path = claude_settings_path(root);
|
|
66
|
+
let installed = path.is_file();
|
|
67
|
+
let managed = installed && settings_source_has_agent_command(&read_hook(&path)?);
|
|
68
|
+
Ok(HookFile {
|
|
69
|
+
path: relative_path(root, &path),
|
|
70
|
+
installed,
|
|
71
|
+
managed,
|
|
72
|
+
action,
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
fn settings_source_has_agent_command(source: &str) -> bool {
|
|
77
|
+
serde_json::from_str::<Value>(source)
|
|
78
|
+
.ok()
|
|
79
|
+
.is_some_and(|value| value_has_agent_command(&value))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
fn value_has_agent_command(value: &Value) -> bool {
|
|
83
|
+
match value {
|
|
84
|
+
Value::Object(object) => {
|
|
85
|
+
object.get("command").and_then(Value::as_str) == Some(AGENT_COMMAND)
|
|
86
|
+
|| object.values().any(value_has_agent_command)
|
|
87
|
+
}
|
|
88
|
+
Value::Array(values) => values.iter().any(value_has_agent_command),
|
|
89
|
+
_ => false,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
fn add_agent_command_to_settings(settings: &mut Value) {
|
|
94
|
+
let Some(root) = settings.as_object_mut() else {
|
|
95
|
+
return;
|
|
96
|
+
};
|
|
97
|
+
ensure_object_field(root, "hooks");
|
|
98
|
+
let Some(hooks) = root.get_mut("hooks").and_then(Value::as_object_mut) else {
|
|
99
|
+
return;
|
|
100
|
+
};
|
|
101
|
+
ensure_array_field(hooks, "PreToolUse");
|
|
102
|
+
let Some(pre_tool_use) = hooks.get_mut("PreToolUse").and_then(Value::as_array_mut) else {
|
|
103
|
+
return;
|
|
104
|
+
};
|
|
105
|
+
if let Some(group) = pre_tool_use
|
|
106
|
+
.iter_mut()
|
|
107
|
+
.find(|group| group.get("matcher").and_then(Value::as_str) == Some("Bash"))
|
|
108
|
+
{
|
|
109
|
+
let Some(group) = group.as_object_mut() else {
|
|
110
|
+
return;
|
|
111
|
+
};
|
|
112
|
+
ensure_array_field(group, "hooks");
|
|
113
|
+
let Some(hooks) = group.get_mut("hooks").and_then(Value::as_array_mut) else {
|
|
114
|
+
return;
|
|
115
|
+
};
|
|
116
|
+
if !hooks.iter().any(is_agent_command_hook) {
|
|
117
|
+
hooks.push(agent_command_hook());
|
|
118
|
+
}
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
pre_tool_use.push(json!({
|
|
122
|
+
"matcher": "Bash",
|
|
123
|
+
"hooks": [agent_command_hook()]
|
|
124
|
+
}));
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fn remove_agent_command_from_settings(settings: &mut Value) {
|
|
128
|
+
let Some(root) = settings.as_object_mut() else {
|
|
129
|
+
return;
|
|
130
|
+
};
|
|
131
|
+
let Some(hooks) = root.get_mut("hooks").and_then(Value::as_object_mut) else {
|
|
132
|
+
return;
|
|
133
|
+
};
|
|
134
|
+
let Some(pre_tool_use) = hooks.get_mut("PreToolUse").and_then(Value::as_array_mut) else {
|
|
135
|
+
return;
|
|
136
|
+
};
|
|
137
|
+
for group in pre_tool_use.iter_mut() {
|
|
138
|
+
let Some(group) = group.as_object_mut() else {
|
|
139
|
+
continue;
|
|
140
|
+
};
|
|
141
|
+
let Some(hooks) = group.get_mut("hooks").and_then(Value::as_array_mut) else {
|
|
142
|
+
continue;
|
|
143
|
+
};
|
|
144
|
+
hooks.retain(|hook| !is_agent_command_hook(hook));
|
|
145
|
+
}
|
|
146
|
+
pre_tool_use.retain(|group| {
|
|
147
|
+
group
|
|
148
|
+
.get("hooks")
|
|
149
|
+
.and_then(Value::as_array)
|
|
150
|
+
.is_none_or(|hooks| !hooks.is_empty())
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
fn ensure_object_field(object: &mut Map<String, Value>, key: &str) {
|
|
155
|
+
if !object.get(key).is_some_and(Value::is_object) {
|
|
156
|
+
object.insert(key.to_owned(), json!({}));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
fn ensure_array_field(object: &mut Map<String, Value>, key: &str) {
|
|
161
|
+
if !object.get(key).is_some_and(Value::is_array) {
|
|
162
|
+
object.insert(key.to_owned(), json!([]));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
fn agent_command_hook() -> Value {
|
|
167
|
+
json!({
|
|
168
|
+
"type": "command",
|
|
169
|
+
"command": AGENT_COMMAND
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
fn is_agent_command_hook(hook: &Value) -> bool {
|
|
174
|
+
hook.get("command").and_then(Value::as_str) == Some(AGENT_COMMAND)
|
|
175
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
use super::{AGENTS_BLOCK_END, AGENTS_BLOCK_START, HOOK_MARKER};
|
|
2
|
+
|
|
3
|
+
pub(super) fn agent_hook_script(branch: &str) -> String {
|
|
4
|
+
format!(
|
|
5
|
+
r#"#!/bin/sh
|
|
6
|
+
# {HOOK_MARKER}
|
|
7
|
+
# Generated by dart-decimate setup-hooks.
|
|
8
|
+
set -eu
|
|
9
|
+
INPUT="$(cat || true)"
|
|
10
|
+
case "$INPUT" in
|
|
11
|
+
*"git commit"*|*"git push"*) ;;
|
|
12
|
+
*) exit 0 ;;
|
|
13
|
+
esac
|
|
14
|
+
if command -v dart-decimate >/dev/null 2>&1; then
|
|
15
|
+
DART_DECIMATE_BIN="dart-decimate"
|
|
16
|
+
elif command -v npx >/dev/null 2>&1; then
|
|
17
|
+
DART_DECIMATE_BIN="npx --no-install dart-decimate"
|
|
18
|
+
else
|
|
19
|
+
echo "dart-decimate-gate: dart-decimate binary not found; allowing command" >&2
|
|
20
|
+
exit 0
|
|
21
|
+
fi
|
|
22
|
+
BASE="${{DART_DECIMATE_BASE:-{branch}}}"
|
|
23
|
+
OUTPUT="$($DART_DECIMATE_BIN audit . --base "$BASE" --format json --summary 2>&1)" || {{
|
|
24
|
+
echo "dart-decimate-gate: dart-decimate audit failed open" >&2
|
|
25
|
+
printf '%s\n' "$OUTPUT" >&2
|
|
26
|
+
exit 0
|
|
27
|
+
}}
|
|
28
|
+
case "$OUTPUT" in
|
|
29
|
+
*'"error":true'*|*'"error": true'*)
|
|
30
|
+
echo "dart-decimate-gate: dart-decimate returned an error envelope; allowing command" >&2
|
|
31
|
+
exit 0
|
|
32
|
+
;;
|
|
33
|
+
*'"verdict":"fail"'*|*'"verdict": "fail"'*)
|
|
34
|
+
echo "dart-decimate-gate: blocked by dart-decimate" >&2
|
|
35
|
+
printf '%s\n' "$OUTPUT" >&2
|
|
36
|
+
exit 2
|
|
37
|
+
;;
|
|
38
|
+
*) exit 0 ;;
|
|
39
|
+
esac
|
|
40
|
+
"#
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
pub(super) fn agents_block(branch: &str) -> String {
|
|
45
|
+
format!(
|
|
46
|
+
r#"{AGENTS_BLOCK_START}
|
|
47
|
+
Before any `git commit` or `git push`, run `dart-decimate audit . --base {branch} --format json --summary`. If the verdict is `fail`, fix the reported findings before retrying. Treat JSON runtime errors like `{{ "error": true }}` as non-blocking.
|
|
48
|
+
{AGENTS_BLOCK_END}
|
|
49
|
+
"#
|
|
50
|
+
)
|
|
51
|
+
}
|