zai-mcp-server
Version:
🚀 REVOLUTIONARY AI-to-AI Collaboration Platform v6.1! NEW: Advanced Debugging Tools with Screenshot Analysis, Console Error Parsing, Automated Fix Generation, 5 Specialized Debugging Agents, Visual UI Analysis, JavaScript Error Intelligence, CSS/HTML Fix
358 lines (309 loc) • 12.6 kB
JavaScript
/**
* Strict Progress Validator for ZAI MCP Server
* Enforces mandatory feature usage and validates AI agent compliance
*/
export class StrictProgressValidator {
constructor() {
this.mandatoryFeatures = new Map();
this.agentCompliance = new Map();
this.progressRequirements = new Map();
this.violationHistory = [];
this.strictMode = true;
this.complianceThreshold = 85; // 85% compliance required
this.initializeMandatoryFeatures();
this.initializeProgressRequirements();
}
/**
* Initialize mandatory features for different contexts
*/
initializeMandatoryFeatures() {
// Core AI-to-AI Loop Features (MANDATORY)
this.mandatoryFeatures.set('ai_collaboration', [
'ai_voting_request',
'acknowledge_agent_response',
'get_ai_prompts',
'analyze_task_breakdown'
]);
// Development Workflow Features (MANDATORY)
this.mandatoryFeatures.set('development', [
'execute_ai_swarm',
'generate_code',
'analyze_task_breakdown',
'deep_think_implementation',
'parallel_execute_tasks'
]);
// Debugging Features (MANDATORY)
this.mandatoryFeatures.set('debugging', [
'quantum_debug',
'universal_platform_debug',
'analyze_screenshot',
'predictive_bug_analysis'
]);
// Performance Features (MANDATORY)
this.mandatoryFeatures.set('performance', [
'initialize_wasm_engine',
'process_batch_wasm',
'initialize_gpu_engine',
'process_ai_gpu',
'get_revolutionary_stats'
]);
// Analytics Features (MANDATORY)
this.mandatoryFeatures.set('analytics', [
'get_model_analytics',
'get_cost_analysis',
'get_cache_analytics',
'get_performance_trends'
]);
// Memory & Context Features (MANDATORY)
this.mandatoryFeatures.set('memory', [
'create_project',
'get_project_memory',
'set_user_preference',
'get_memory_analytics'
]);
}
/**
* Initialize progress requirements
*/
initializeProgressRequirements() {
this.progressRequirements.set('feature_usage_rate', 0.75); // 75% of mandatory features must be used
this.progressRequirements.set('quality_threshold', 0.80); // 80% quality score required
this.progressRequirements.set('response_time_limit', 5000); // 5 second response time limit
this.progressRequirements.set('error_rate_limit', 0.15); // Max 15% error rate
this.progressRequirements.set('compliance_score', 0.85); // 85% compliance required
}
/**
* Validate AI agent strict progress
*/
validateAgentProgress(agentId, context, usedFeatures, metrics) {
const validation = {
agentId,
timestamp: new Date().toISOString(),
context,
compliance: {
featureUsage: this.validateFeatureUsage(context, usedFeatures),
qualityScore: this.validateQualityScore(metrics),
responseTime: this.validateResponseTime(metrics),
errorRate: this.validateErrorRate(metrics),
overallCompliance: 0
},
violations: [],
mandatoryActions: [],
status: 'PENDING'
};
// Calculate overall compliance
const complianceScores = Object.values(validation.compliance).filter(score => typeof score === 'number');
validation.compliance.overallCompliance = complianceScores.reduce((sum, score) => sum + score, 0) / complianceScores.length;
// Determine status
if (validation.compliance.overallCompliance >= this.complianceThreshold / 100) {
validation.status = 'COMPLIANT';
} else if (validation.compliance.overallCompliance >= 0.60) {
validation.status = 'WARNING';
validation.mandatoryActions = this.generateMandatoryActions(validation.compliance, context);
} else {
validation.status = 'NON_COMPLIANT';
validation.violations = this.generateViolations(validation.compliance, context);
validation.mandatoryActions = this.generateMandatoryActions(validation.compliance, context);
}
// Record compliance history
this.agentCompliance.set(agentId, validation);
// Record violations if any
if (validation.violations.length > 0) {
this.violationHistory.push({
agentId,
timestamp: validation.timestamp,
violations: validation.violations,
context
});
}
return validation;
}
/**
* Validate feature usage compliance
*/
validateFeatureUsage(context, usedFeatures) {
const requiredFeatures = this.getMandatoryFeaturesForContext(context);
const usedCount = usedFeatures.filter(feature => requiredFeatures.includes(feature)).length;
const usageRate = usedCount / requiredFeatures.length;
return Math.min(100, usageRate * 100);
}
/**
* Validate quality score
*/
validateQualityScore(metrics) {
const qualityScore = metrics.qualityScore || 0;
const threshold = this.progressRequirements.get('quality_threshold');
return qualityScore >= threshold ? 100 : (qualityScore / threshold) * 100;
}
/**
* Validate response time
*/
validateResponseTime(metrics) {
const responseTime = metrics.responseTime || 0;
const limit = this.progressRequirements.get('response_time_limit');
return responseTime <= limit ? 100 : Math.max(0, 100 - ((responseTime - limit) / limit) * 100);
}
/**
* Validate error rate
*/
validateErrorRate(metrics) {
const errorRate = metrics.errorRate || 0;
const limit = this.progressRequirements.get('error_rate_limit');
return errorRate <= limit ? 100 : Math.max(0, 100 - ((errorRate - limit) / limit) * 100);
}
/**
* Get mandatory features for context
*/
getMandatoryFeaturesForContext(context) {
const contextType = this.determineContextType(context);
return this.mandatoryFeatures.get(contextType) || [];
}
/**
* Determine context type
*/
determineContextType(context) {
const contextLower = context.toLowerCase();
if (contextLower.includes('debug')) return 'debugging';
if (contextLower.includes('code') || contextLower.includes('develop')) return 'development';
if (contextLower.includes('performance') || contextLower.includes('speed')) return 'performance';
if (contextLower.includes('analytics') || contextLower.includes('metrics')) return 'analytics';
if (contextLower.includes('memory') || contextLower.includes('context')) return 'memory';
return 'ai_collaboration'; // Default to AI collaboration
}
/**
* Generate violations list
*/
generateViolations(compliance, context) {
const violations = [];
if (compliance.featureUsage < 75) {
violations.push({
type: 'INSUFFICIENT_FEATURE_USAGE',
severity: 'HIGH',
description: `Only ${compliance.featureUsage.toFixed(1)}% of mandatory features used (75% required)`,
mandatoryAction: 'Must use all mandatory features for context'
});
}
if (compliance.qualityScore < 80) {
violations.push({
type: 'LOW_QUALITY_SCORE',
severity: 'HIGH',
description: `Quality score ${compliance.qualityScore.toFixed(1)}% below 80% threshold`,
mandatoryAction: 'Improve response quality and accuracy'
});
}
if (compliance.responseTime < 70) {
violations.push({
type: 'SLOW_RESPONSE_TIME',
severity: 'MEDIUM',
description: 'Response time exceeds acceptable limits',
mandatoryAction: 'Optimize processing speed'
});
}
if (compliance.errorRate < 85) {
violations.push({
type: 'HIGH_ERROR_RATE',
severity: 'HIGH',
description: 'Error rate exceeds 15% limit',
mandatoryAction: 'Reduce errors and improve reliability'
});
}
return violations;
}
/**
* Generate mandatory actions
*/
generateMandatoryActions(compliance, context) {
const actions = [];
const requiredFeatures = this.getMandatoryFeaturesForContext(context);
// Feature usage actions
if (compliance.featureUsage < 75) {
actions.push({
priority: 'HIGH',
action: 'USE_MANDATORY_FEATURES',
description: `Must use these mandatory features: ${requiredFeatures.join(', ')}`,
deadline: new Date(Date.now() + 300000).toISOString() // 5 minutes
});
}
// Quality improvement actions
if (compliance.qualityScore < 80) {
actions.push({
priority: 'HIGH',
action: 'IMPROVE_QUALITY',
description: 'Enhance response quality through better AI model usage and validation',
deadline: new Date(Date.now() + 600000).toISOString() // 10 minutes
});
}
// Performance optimization actions
if (compliance.responseTime < 70) {
actions.push({
priority: 'MEDIUM',
action: 'OPTIMIZE_PERFORMANCE',
description: 'Use WASM and GPU acceleration features to improve speed',
deadline: new Date(Date.now() + 900000).toISOString() // 15 minutes
});
}
return actions;
}
/**
* Get compliance report
*/
getComplianceReport() {
const totalAgents = this.agentCompliance.size;
const compliantAgents = Array.from(this.agentCompliance.values())
.filter(validation => validation.status === 'COMPLIANT').length;
const overallComplianceRate = totalAgents > 0 ? (compliantAgents / totalAgents) * 100 : 0;
return {
timestamp: new Date().toISOString(),
totalAgents,
compliantAgents,
overallComplianceRate,
strictMode: this.strictMode,
complianceThreshold: this.complianceThreshold,
recentViolations: this.violationHistory.slice(-10),
mandatoryFeatures: Object.fromEntries(this.mandatoryFeatures),
progressRequirements: Object.fromEntries(this.progressRequirements)
};
}
/**
* Enforce strict compliance
*/
enforceStrictCompliance(agentId) {
const validation = this.agentCompliance.get(agentId);
if (!validation) {
return {
action: 'BLOCK',
reason: 'No compliance validation found',
mandatoryActions: ['Complete initial validation']
};
}
if (validation.status === 'NON_COMPLIANT') {
return {
action: 'BLOCK',
reason: 'Non-compliant agent blocked from further operations',
mandatoryActions: validation.mandatoryActions,
violations: validation.violations
};
}
if (validation.status === 'WARNING') {
return {
action: 'WARN',
reason: 'Agent compliance below optimal level',
mandatoryActions: validation.mandatoryActions
};
}
return {
action: 'ALLOW',
reason: 'Agent is compliant',
complianceScore: validation.compliance.overallCompliance
};
}
/**
* Reset compliance data
*/
resetCompliance() {
this.agentCompliance.clear();
this.violationHistory = [];
console.log('🔄 Strict compliance data reset');
}
}
export default StrictProgressValidator;