use crate::params::{CheckRuntimeCoverageParams, GetTokenBlastRadiusParams};
use rmcp::ErrorData as McpError;
use rmcp::model::CallToolResult;
use super::{push_global, push_scope, run_tool, run_tool_with_top_level_warnings};
pub async fn run_check_runtime_coverage(
binary: &str,
params: CheckRuntimeCoverageParams,
) -> Result<CallToolResult, McpError> {
let args = build_check_runtime_coverage_args(¶ms);
run_tool(binary, "check_runtime_coverage", &args).await
}
pub async fn run_get_hot_paths(
binary: &str,
params: CheckRuntimeCoverageParams,
) -> Result<CallToolResult, McpError> {
let args = build_get_hot_paths_args(¶ms);
run_tool_with_top_level_warnings(binary, "get_hot_paths", &args).await
}
pub async fn run_get_blast_radius(
binary: &str,
params: CheckRuntimeCoverageParams,
) -> Result<CallToolResult, McpError> {
let args = build_get_blast_radius_args(¶ms);
run_tool_with_top_level_warnings(binary, "get_blast_radius", &args).await
}
pub async fn run_get_importance(
binary: &str,
params: CheckRuntimeCoverageParams,
) -> Result<CallToolResult, McpError> {
let args = build_get_importance_args(¶ms);
run_tool_with_top_level_warnings(binary, "get_importance", &args).await
}
pub async fn run_get_cleanup_candidates(
binary: &str,
params: CheckRuntimeCoverageParams,
) -> Result<CallToolResult, McpError> {
let args = build_get_cleanup_candidates_args(¶ms);
run_tool_with_top_level_warnings(binary, "get_cleanup_candidates", &args).await
}
pub async fn run_get_token_blast_radius(
binary: &str,
params: GetTokenBlastRadiusParams,
) -> Result<CallToolResult, McpError> {
let args = build_get_token_blast_radius_args(¶ms);
run_tool_with_top_level_warnings(binary, "get_token_blast_radius", &args).await
}
pub fn build_check_runtime_coverage_args(params: &CheckRuntimeCoverageParams) -> Vec<String> {
let mut args = vec![
"health".to_string(),
"--format".to_string(),
"json".to_string(),
"--quiet".to_string(),
"--explain".to_string(),
"--runtime-coverage".to_string(),
params.coverage.clone(),
];
push_global(
&mut args,
params.root.as_deref(),
params.config.as_deref(),
params.no_cache,
params.threads,
);
push_scope(&mut args, params.production, params.workspace.as_deref());
if let Some(min_invocations_hot) = params.min_invocations_hot {
args.extend([
"--min-invocations-hot".to_string(),
min_invocations_hot.to_string(),
]);
}
if let Some(min_observation_volume) = params.min_observation_volume {
args.extend([
"--min-observation-volume".to_string(),
min_observation_volume.to_string(),
]);
}
if let Some(low_traffic_threshold) = params.low_traffic_threshold {
args.extend([
"--low-traffic-threshold".to_string(),
format!("{low_traffic_threshold}"),
]);
}
if let Some(max_crap) = params.max_crap {
args.extend(["--max-crap".to_string(), format!("{max_crap}")]);
}
if let Some(top) = params.top {
args.extend(["--top".to_string(), top.to_string()]);
}
if let Some(ref gb) = params.group_by {
args.extend(["--group-by".to_string(), gb.clone()]);
}
args
}
pub fn build_get_hot_paths_args(params: &CheckRuntimeCoverageParams) -> Vec<String> {
build_check_runtime_coverage_args(params)
}
pub fn build_get_blast_radius_args(params: &CheckRuntimeCoverageParams) -> Vec<String> {
build_check_runtime_coverage_args(params)
}
pub fn build_get_importance_args(params: &CheckRuntimeCoverageParams) -> Vec<String> {
build_check_runtime_coverage_args(params)
}
pub fn build_get_cleanup_candidates_args(params: &CheckRuntimeCoverageParams) -> Vec<String> {
build_check_runtime_coverage_args(params)
}
pub fn build_get_token_blast_radius_args(params: &GetTokenBlastRadiusParams) -> Vec<String> {
let mut args = vec![
"health".to_string(),
"--css".to_string(),
"--format".to_string(),
"json".to_string(),
];
push_global(
&mut args,
params.root.as_deref(),
params.config.as_deref(),
params.no_cache,
params.threads,
);
args
}