opengrep 1.1.0

Advanced AST-aware code search tool with tree-sitter parsing and AI integration capabilities
Documentation
//! AI-powered code analysis types and structures

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Result of AI analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct AnalysisResult {
    /// Summary of the analysis
    pub summary: String,
    /// Key insights discovered
    pub insights: Vec<String>,
    /// Recommendations for improvement
    pub recommendations: Vec<String>,
    /// Common patterns identified
    pub patterns: Vec<String>,
    /// Confidence score (0.0 to 1.0)
    pub confidence: f32,
}

/// Code quality metrics from AI analysis
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct QualityMetrics {
    /// Overall quality score (0.0 to 1.0)
    pub score: f32,
    /// Complexity score (0.0 to 1.0, higher = more complex)
    pub complexity: f32,
    /// Maintainability score (0.0 to 1.0, higher = more maintainable)
    pub maintainability: f32,
    /// Test coverage estimate (0.0 to 1.0)
    pub test_coverage: f32,
    /// Documentation quality (0.0 to 1.0)
    pub documentation: f32,
}

/// Security analysis result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityAnalysis {
    /// Potential security issues found
    pub issues: Vec<SecurityIssue>,
    /// Overall security score (0.0 to 1.0, higher = more secure)
    pub score: f32,
    /// Recommendations for security improvements
    pub recommendations: Vec<String>,
}

/// Individual security issue
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SecurityIssue {
    /// Type of security issue
    pub issue_type: String,
    /// Severity level (Low, Medium, High, Critical)
    pub severity: String,
    /// Description of the issue
    pub description: String,
    /// File path where issue was found
    pub file_path: String,
    /// Line number (if applicable)
    pub line_number: Option<usize>,
    /// Recommendation for fixing
    pub recommendation: String,
}

/// Performance analysis result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PerformanceAnalysis {
    /// Potential performance bottlenecks
    pub bottlenecks: Vec<PerformanceIssue>,
    /// Overall performance score (0.0 to 1.0)
    pub score: f32,
    /// Optimization suggestions
    pub optimizations: Vec<String>,
}

/// Individual performance issue
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PerformanceIssue {
    /// Type of performance issue
    pub issue_type: String,
    /// Impact level (Low, Medium, High)
    pub impact: String,
    /// Description of the issue
    pub description: String,
    /// File path where issue was found
    pub file_path: String,
    /// Line number (if applicable)
    pub line_number: Option<usize>,
    /// Suggestion for optimization
    pub optimization: String,
}

/// Comprehensive code analysis combining all aspects
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComprehensiveAnalysis {
    /// Basic analysis result
    pub analysis: AnalysisResult,
    /// Quality metrics
    pub quality: QualityMetrics,
    /// Security analysis
    pub security: SecurityAnalysis,
    /// Performance analysis
    pub performance: PerformanceAnalysis,
    /// Technology stack detected
    pub tech_stack: Vec<String>,
    /// Dependencies analysis
    pub dependencies: DependencyAnalysis,
}

/// Dependency analysis result
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DependencyAnalysis {
    /// Direct dependencies
    pub direct: Vec<Dependency>,
    /// Transitive dependencies (flattened)
    pub transitive: Vec<Dependency>,
    /// Outdated dependencies
    pub outdated: Vec<Dependency>,
    /// Vulnerable dependencies
    pub vulnerable: Vec<VulnerableDependency>,
    /// License compatibility issues
    pub license_issues: Vec<String>,
}

/// Dependency information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Dependency {
    /// Name of the dependency
    pub name: String,
    /// Current version
    pub version: String,
    /// Latest available version
    pub latest_version: Option<String>,
    /// License information
    pub license: Option<String>,
    /// Description
    pub description: Option<String>,
}

/// Vulnerable dependency information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct VulnerableDependency {
    /// Dependency information
    pub dependency: Dependency,
    /// Vulnerability details
    pub vulnerabilities: Vec<Vulnerability>,
}

/// Vulnerability information
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Vulnerability {
    /// CVE identifier (if available)
    pub cve_id: Option<String>,
    /// Severity score (CVSS)
    pub severity_score: Option<f32>,
    /// Severity level
    pub severity_level: String,
    /// Title/summary
    pub title: String,
    /// Detailed description
    pub description: String,
    /// Affected versions
    pub affected_versions: Vec<String>,
    /// Fixed versions
    pub fixed_versions: Vec<String>,
}

impl Default for QualityMetrics {
    fn default() -> Self {
        Self {
            score: 0.5,
            complexity: 0.5,
            maintainability: 0.5,
            test_coverage: 0.0,
            documentation: 0.5,
        }
    }
}

impl Default for SecurityAnalysis {
    fn default() -> Self {
        Self {
            issues: vec![],
            score: 0.5,
            recommendations: vec![],
        }
    }
}

impl Default for PerformanceAnalysis {
    fn default() -> Self {
        Self {
            bottlenecks: vec![],
            score: 0.5,
            optimizations: vec![],
        }
    }
}