1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![cfg_attr(coverage_nightly, coverage(off))]
use crate::models::proxy::{
ProxyMode, ProxyOperation, ProxyRequest, ProxyResponse, ProxyStatus, QualityConfig,
QualityMetrics, QualityReport, QualityViolation, ViolationSeverity, ViolationType,
};
use crate::services::ast_rust::analyze_rust_file_with_complexity;
use crate::services::complexity::aggregate_results_with_thresholds;
use crate::services::satd_detector::SATDDetector;
use anyhow::{Context, Result};
use std::collections::HashMap;
use std::path::Path;
use tracing::{debug, info, warn};
/// Service for proxying code changes through quality gates.
///
/// This service intercepts code operations from AI agents and ensures
/// they meet quality standards before being applied.
///
/// # Example
///
/// ```ignore
/// use pmat::services::quality_proxy::QualityProxyService;
/// use pmat::models::proxy::{ProxyRequest, ProxyOperation, ProxyMode};
///
/// # async fn example() -> anyhow::Result<()> {
/// let service = QualityProxyService::new();
/// let request = ProxyRequest {
/// operation: ProxyOperation::Write,
/// file_path: "test.rs".to_string(),
/// content: Some("fn main() { println!(\"Hello\"); }".to_string()),
/// old_content: None,
/// new_content: None,
/// mode: ProxyMode::Strict,
/// quality_config: Default::default(),
/// };
///
/// let response = service.proxy_operation(request).await?;
/// assert!(response.quality_report.passed);
/// # Ok(())
/// # }
/// ```ignore
pub struct QualityProxyService {
satd_detector: SATDDetector,
}
impl QualityProxyService {
/// Creates a new quality proxy service.
#[must_use]
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn new() -> Self {
Self {
satd_detector: SATDDetector::new(),
}
}
}
impl Default for QualityProxyService {
fn default() -> Self {
Self::new()
}
}
// Proxy operation orchestration and content extraction
include!("quality_proxy_operations.rs");
// Quality analysis: complexity, SATD, lint, documentation, formatting
include!("quality_proxy_analysis.rs");
// Auto-fix refactoring logic
include!("quality_proxy_autofix.rs");
// Unit tests and property tests
include!("quality_proxy_tests.rs");