use crate::params::{ImpactAllParams, ImpactClosureParams, ImpactParams};
use rmcp::ErrorData as McpError;
use rmcp::model::CallToolResult;
use super::{
push_global, push_remote_extends, push_scope, push_str_flag, run_tool, validation_error_body,
};
pub async fn run_impact(binary: &str, params: ImpactParams) -> Result<CallToolResult, McpError> {
let args = build_impact_args(¶ms);
run_tool(binary, "impact", &args).await
}
pub async fn run_impact_all(
binary: &str,
params: ImpactAllParams,
) -> Result<CallToolResult, McpError> {
let args = build_impact_all_args(¶ms);
run_tool(binary, "impact_all", &args).await
}
pub async fn run_impact_closure(
binary: &str,
params: ImpactClosureParams,
) -> Result<CallToolResult, McpError> {
let args = match build_impact_closure_args(¶ms) {
Ok(args) => args,
Err(msg) => {
return Ok(CallToolResult::error(vec![
rmcp::model::ContentBlock::text(msg),
]));
}
};
run_tool(binary, "impact_closure", &args).await
}
pub fn build_impact_args(params: &ImpactParams) -> Vec<String> {
let mut args = vec![
"impact".to_string(),
"--format".to_string(),
"json".to_string(),
"--quiet".to_string(),
];
push_str_flag(&mut args, "--root", params.root.as_deref());
args
}
pub fn build_impact_all_args(params: &ImpactAllParams) -> Vec<String> {
let mut args = vec![
"impact".to_string(),
"--all".to_string(),
"--format".to_string(),
"json".to_string(),
"--quiet".to_string(),
];
push_str_flag(&mut args, "--sort", params.sort.as_deref());
if let Some(limit) = params.limit {
args.push("--limit".to_string());
args.push(limit.to_string());
}
args
}
pub fn build_impact_closure_args(params: &ImpactClosureParams) -> Result<Vec<String>, String> {
if params.path.trim().is_empty() {
return Err(validation_error_body("path must not be empty"));
}
let mut args = vec![
"dead-code".to_string(),
"--format".to_string(),
"json".to_string(),
"--quiet".to_string(),
];
push_global(
&mut args,
params.root.as_deref(),
params.config.as_deref(),
params.no_cache,
params.threads,
);
push_remote_extends(&mut args, params.allow_remote_extends);
push_scope(&mut args, params.production, params.workspace.as_deref());
args.extend(["--impact-closure".to_string(), params.path.clone()]);
Ok(args)
}