#[derive(Debug, Deserialize)]
struct LintHotspotArgs {
paths: Vec<String>,
#[serde(default)]
top_files: Option<usize>,
}
pub struct LintHotspotTool;
impl LintHotspotTool {
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self
}
}
impl Default for LintHotspotTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for LintHotspotTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze.lint-hotspot with args: {}", args);
let params: LintHotspotArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_lint_hotspots(&paths, params.top_files)
.await
.map_err(|e| Error::internal(format!("Lint hotspot analysis failed: {e}")))?;
Ok(results)
}
fn metadata(&self) -> Option<ToolInfo> {
let extra = json!({
"top_files": { "type": "integer", "description": "Return only the top N files with the most lint violations" }
});
Some(build_tool_info(
"analyze_dag",
"Generate a dependency graph (DAG) / lint hotspot report highlighting files with the most violations.",
paths_object_schema(extra, vec!["paths"]),
))
}
}
#[derive(Debug, Deserialize)]
struct ChurnArgs {
paths: Vec<String>,
#[serde(default)]
days: Option<u32>,
#[serde(default)]
top_files: Option<usize>,
}
pub struct ChurnTool;
impl ChurnTool {
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self
}
}
impl Default for ChurnTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for ChurnTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze.churn with args: {}", args);
let params: ChurnArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_churn(&paths, params.days, params.top_files)
.await
.map_err(|e| Error::internal(format!("Churn analysis failed: {e}")))?;
Ok(results)
}
fn metadata(&self) -> Option<ToolInfo> {
let extra = json!({
"days": { "type": "integer", "description": "Git history window in days (default: 90)" },
"top_files": { "type": "integer", "description": "Return only the top N files by churn" }
});
Some(build_tool_info(
"analyze_deep_context",
"Comprehensive code analysis combining git churn history with code metrics.",
paths_object_schema(extra, vec!["paths"]),
))
}
}
#[derive(Debug, Deserialize)]
struct CouplingArgs {
paths: Vec<String>,
#[serde(default)]
threshold: Option<f64>,
}
pub struct CouplingTool;
impl CouplingTool {
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self
}
}
impl Default for CouplingTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for CouplingTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze.coupling with args: {}", args);
let params: CouplingArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_coupling(&paths, params.threshold)
.await
.map_err(|e| Error::internal(format!("Coupling analysis failed: {e}")))?;
Ok(results)
}
fn metadata(&self) -> Option<ToolInfo> {
let extra = json!({
"threshold": { "type": "number", "description": "Minimum similarity threshold for reporting coupled modules (0.0-1.0)" }
});
Some(build_tool_info(
"analyze_big_o",
"Big-O complexity / module coupling analysis.",
paths_object_schema(extra, vec!["paths"]),
))
}
}
#[derive(Debug, Deserialize)]
struct AnalyzeDagArgs {
paths: Vec<String>,
#[serde(default)]
dag_type: Option<String>,
}
pub struct AnalyzeDagTool;
impl AnalyzeDagTool {
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self
}
}
impl Default for AnalyzeDagTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for AnalyzeDagTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze_dag with args: {}", args);
let params: AnalyzeDagArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_dag(&paths, params.dag_type)
.await
.map_err(|e| Error::internal(format!("DAG analysis failed: {e}")))?;
Ok(results)
}
}
#[derive(Debug, Deserialize)]
struct AnalyzeBigOArgs {
paths: Vec<String>,
#[serde(default)]
top_files: Option<usize>,
}
pub struct AnalyzeBigOTool;
impl AnalyzeBigOTool {
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self
}
}
impl Default for AnalyzeBigOTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for AnalyzeBigOTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze_big_o with args: {}", args);
let params: AnalyzeBigOArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_big_o(&paths, params.top_files)
.await
.map_err(|e| Error::internal(format!("Big-O analysis failed: {e}")))?;
Ok(results)
}
}
#[derive(Debug, Deserialize)]
struct AnalyzeDeepContextArgs {
paths: Vec<String>,
#[serde(default)]
include_patterns: Option<Vec<String>>,
}
pub struct AnalyzeDeepContextTool;
impl AnalyzeDeepContextTool {
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self
}
}
impl Default for AnalyzeDeepContextTool {
fn default() -> Self {
Self::new()
}
}
#[async_trait]
impl ToolHandler for AnalyzeDeepContextTool {
async fn handle(&self, args: Value, _extra: RequestHandlerExtra) -> Result<Value> {
debug!("Handling analyze_deep_context with args: {}", args);
let params: AnalyzeDeepContextArgs = serde_json::from_value(args)
.map_err(|e| Error::validation(format!("Invalid arguments: {e}")))?;
let paths: Vec<PathBuf> = params.paths.into_iter().map(PathBuf::from).collect();
let results = tool_functions::analyze_deep_context(&paths, params.include_patterns)
.await
.map_err(|e| Error::internal(format!("Deep context analysis failed: {e}")))?;
Ok(results)
}
}