@versatil/sdlc-framework
Version:
🚀 AI-Native SDLC framework with 11-MCP ecosystem, RAG memory, OPERA orchestration, and 6 specialized agents achieving ZERO CONTEXT LOSS. Features complete CI/CD pipeline with 7 GitHub workflows (MCP testing, security scanning, performance benchmarking),
1,098 lines • 45.7 kB
JavaScript
/**
* VERSATIL SDLC Framework - Enhanced OPERA Agent Configuration
* Implements integration with the three new rules:
* 1. Parallel task execution with collision detection
* 2. Automated stress test generation
* 3. Daily audit and health check system
*
* Features:
* - Enhanced agent capabilities
* - Rule-based automation triggers
* - Cross-agent collaboration protocols
* - Performance optimization
* - Quality assurance integration
*/
import { EventEmitter } from 'events';
import { ParallelTaskManager, Priority } from '../orchestration/parallel-task-manager.js';
import { AutomatedStressTestGenerator, StressTestType, TargetType } from '../testing/automated-stress-test-generator.js';
import { DailyAuditSystem, AuditType, CheckCategory } from '../audit/daily-audit-system.js';
export var OptimizationLevel;
(function (OptimizationLevel) {
OptimizationLevel["BASIC"] = "basic";
OptimizationLevel["STANDARD"] = "standard";
OptimizationLevel["AGGRESSIVE"] = "aggressive";
OptimizationLevel["EXPERIMENTAL"] = "experimental";
})(OptimizationLevel || (OptimizationLevel = {}));
export var ConflictStrategy;
(function (ConflictStrategy) {
ConflictStrategy["PRIORITY_BASED"] = "priority_based";
ConflictStrategy["ROUND_ROBIN"] = "round_robin";
ConflictStrategy["LOAD_BALANCED"] = "load_balanced";
ConflictStrategy["EXPERTISE_BASED"] = "expertise_based";
})(ConflictStrategy || (ConflictStrategy = {}));
export class EnhancedOPERAConfigManager extends EventEmitter {
constructor() {
super();
this.agentConfigs = new Map();
this.activeAgents = new Set();
this.taskManager = new ParallelTaskManager();
this.stressTestGenerator = new AutomatedStressTestGenerator();
this.auditSystem = new DailyAuditSystem();
this.initializeEnhancedConfigs();
this.setupRuleIntegration();
this.startConfigMonitoring();
}
/**
* Initialize enhanced OPERA agent configurations
*/
initializeEnhancedConfigs() {
// Enhanced Maria-QA Configuration
const mariaConfig = {
id: 'maria-qa',
name: 'Enhanced Maria-QA',
role: 'Quality Assurance Lead & Testing Orchestrator',
description: 'Advanced QA with parallel testing, stress testing, and health monitoring',
version: '2.0.0',
enabled: true,
auto_activate: true,
patterns: [
'*.test.js', '*.test.ts', '*.test.jsx', '*.test.tsx',
'*.spec.js', '*.spec.ts', '*.spec.jsx', '*.spec.tsx',
'__tests__/**', 'cypress/**', 'e2e/**',
'playwright.config.*', 'jest.config.*'
],
keywords: [
'test', 'spec', 'describe', 'it(', 'expect', 'coverage',
'stress', 'load', 'performance', 'audit', 'health',
'quality', 'validation', 'regression'
],
tools: [
'jest', 'playwright', 'cypress', 'vitest', 'testing-library',
'supertest', 'chai', 'mocha', 'jasmine', 'puppeteer',
'lighthouse', 'axe-core', 'storybook'
],
capabilities: {
parallel_execution: true,
stress_testing: true,
health_monitoring: true,
quality_gates: true,
security_scanning: true,
performance_optimization: true,
automated_testing: true,
continuous_integration: true,
documentation_generation: true,
code_analysis: true
},
rules: {
rule1_parallel_tasks: {
enabled: true,
max_parallel_tasks: 8,
collision_detection: true,
resource_management: true,
priority_handling: true,
auto_scaling: true,
triggers: [
{
pattern: 'test/**',
action: 'parallel_test_execution',
condition: 'file_count > 5',
parallelism_level: 4
},
{
pattern: '*.spec.*',
action: 'parallel_spec_validation',
condition: 'changed_files > 3',
parallelism_level: 6
}
]
},
rule2_stress_testing: {
enabled: true,
auto_generate_tests: true,
test_types: [
StressTestType.LOAD_TEST,
StressTestType.STRESS_TEST,
StressTestType.SPIKE_TEST,
StressTestType.ENDURANCE_TEST
],
coverage_threshold: 80,
performance_baseline: true,
chaos_engineering: true,
triggers: [
{
event: 'code_change',
test_type: StressTestType.LOAD_TEST,
target_type: TargetType.API_ENDPOINT,
condition: 'api_endpoint_modified',
priority: Priority.HIGH
},
{
event: 'deployment',
test_type: StressTestType.STRESS_TEST,
target_type: TargetType.END_TO_END,
condition: 'production_deployment',
priority: Priority.CRITICAL
}
]
},
rule3_daily_audit: {
enabled: true,
audit_frequency: 'daily',
health_check_interval: 300000, // 5 minutes
alert_thresholds: {
cpu_usage: 80,
memory_usage: 85,
disk_usage: 90,
response_time: 2000,
error_rate: 5,
test_coverage: 80
},
compliance_checks: true,
performance_monitoring: true,
security_scanning: true,
triggers: [
{
schedule: '0 2 * * *', // 2 AM daily
audit_type: AuditType.COMPREHENSIVE,
check_categories: [
CheckCategory.SYSTEM,
CheckCategory.APPLICATION,
CheckCategory.SECURITY,
CheckCategory.PERFORMANCE,
CheckCategory.QUALITY
],
notification_level: 'critical'
}
]
},
custom_rules: [
{
id: 'auto_regression_test',
name: 'Auto Regression Testing',
description: 'Automatically run regression tests on critical path changes',
condition: 'critical_path_modified && coverage < 90',
action: 'execute_regression_suite',
priority: Priority.HIGH,
enabled: true
}
]
},
integration: {
task_manager: true,
stress_tester: true,
audit_system: true,
environment_manager: true,
monitoring_dashboard: true,
notification_system: true,
ci_cd_pipeline: true,
version_control: true
},
performance: {
max_concurrent_tasks: 8,
memory_limit: 4096,
cpu_limit: 80,
timeout_duration: 300000,
retry_attempts: 3,
cache_enabled: true,
optimization_level: OptimizationLevel.AGGRESSIVE
},
collaboration: {
handoff_protocols: [
{
from_agent: 'james-frontend',
to_agent: 'maria-qa',
trigger_condition: 'component_ready_for_testing',
context_data: ['component_spec', 'test_requirements', 'acceptance_criteria'],
validation_required: true
},
{
from_agent: 'marcus-backend',
to_agent: 'maria-qa',
trigger_condition: 'api_ready_for_testing',
context_data: ['api_spec', 'endpoint_definitions', 'security_requirements'],
validation_required: true
}
],
context_preservation: true,
knowledge_sharing: true,
conflict_resolution: {
strategy: ConflictStrategy.PRIORITY_BASED,
escalation_path: ['sarah-pm'],
timeout_duration: 30000,
fallback_agent: 'sarah-pm'
},
communication_channels: ['websocket', 'event_bus', 'shared_memory']
},
configured_at: new Date().toISOString()
};
// Enhanced James-Frontend Configuration
const jamesConfig = {
id: 'james-frontend',
name: 'Enhanced James-Frontend',
role: 'Frontend Specialist & Performance Optimizer',
description: 'Advanced frontend development with parallel component building and automated testing',
version: '2.0.0',
enabled: true,
auto_activate: true,
patterns: [
'*.jsx', '*.tsx', '*.vue', '*.svelte',
'components/**', 'ui/**', 'pages/**', 'views/**',
'*.css', '*.scss', '*.sass', '*.less', '*.styled.*',
'package.json', 'webpack.config.*', 'vite.config.*'
],
keywords: [
'react', 'vue', 'svelte', 'component', 'ui', 'frontend',
'responsive', 'accessibility', 'performance', 'css',
'styling', 'animation', 'interaction'
],
tools: [
'react', 'vue', 'svelte', 'next.js', 'nuxt.js', 'gatsby',
'webpack', 'vite', 'rollup', 'parcel', 'esbuild',
'tailwind', 'styled-components', 'emotion', 'sass'
],
capabilities: {
parallel_execution: true,
stress_testing: true,
health_monitoring: true,
quality_gates: true,
security_scanning: false,
performance_optimization: true,
automated_testing: true,
continuous_integration: true,
documentation_generation: true,
code_analysis: true
},
rules: {
rule1_parallel_tasks: {
enabled: true,
max_parallel_tasks: 6,
collision_detection: true,
resource_management: true,
priority_handling: true,
auto_scaling: false,
triggers: [
{
pattern: 'components/**',
action: 'parallel_component_build',
condition: 'component_count > 3',
parallelism_level: 4
},
{
pattern: '*.css',
action: 'parallel_style_compilation',
condition: 'style_files > 5',
parallelism_level: 3
}
]
},
rule2_stress_testing: {
enabled: true,
auto_generate_tests: true,
test_types: [StressTestType.LOAD_TEST, StressTestType.VOLUME_TEST],
coverage_threshold: 75,
performance_baseline: true,
chaos_engineering: false,
triggers: [
{
event: 'component_change',
test_type: StressTestType.LOAD_TEST,
target_type: TargetType.UI_COMPONENT,
condition: 'ui_component_modified',
priority: Priority.MEDIUM
}
]
},
rule3_daily_audit: {
enabled: true,
audit_frequency: 'daily',
health_check_interval: 600000, // 10 minutes
alert_thresholds: {
cpu_usage: 70,
memory_usage: 75,
disk_usage: 80,
response_time: 1500,
error_rate: 3,
test_coverage: 75
},
compliance_checks: true,
performance_monitoring: true,
security_scanning: false,
triggers: [
{
schedule: '0 3 * * *', // 3 AM daily
audit_type: AuditType.PERFORMANCE,
check_categories: [CheckCategory.PERFORMANCE, CheckCategory.QUALITY],
notification_level: 'warning'
}
]
},
custom_rules: [
{
id: 'accessibility_check',
name: 'Accessibility Validation',
description: 'Automatically validate accessibility on UI changes',
condition: 'ui_component_changed',
action: 'run_accessibility_audit',
priority: Priority.MEDIUM,
enabled: true
}
]
},
integration: {
task_manager: true,
stress_tester: true,
audit_system: true,
environment_manager: true,
monitoring_dashboard: true,
notification_system: false,
ci_cd_pipeline: true,
version_control: true
},
performance: {
max_concurrent_tasks: 6,
memory_limit: 2048,
cpu_limit: 70,
timeout_duration: 180000,
retry_attempts: 2,
cache_enabled: true,
optimization_level: OptimizationLevel.STANDARD
},
collaboration: {
handoff_protocols: [
{
from_agent: 'james-frontend',
to_agent: 'maria-qa',
trigger_condition: 'component_development_complete',
context_data: ['component_props', 'styling_guide', 'interaction_specs'],
validation_required: true
},
{
from_agent: 'alex-ba',
to_agent: 'james-frontend',
trigger_condition: 'ui_requirements_defined',
context_data: ['user_stories', 'wireframes', 'design_system'],
validation_required: false
}
],
context_preservation: true,
knowledge_sharing: true,
conflict_resolution: {
strategy: ConflictStrategy.EXPERTISE_BASED,
escalation_path: ['maria-qa', 'sarah-pm'],
timeout_duration: 45000,
fallback_agent: 'maria-qa'
},
communication_channels: ['event_bus', 'shared_memory']
},
configured_at: new Date().toISOString()
};
// Enhanced Marcus-Backend Configuration
const marcusConfig = {
id: 'marcus-backend',
name: 'Enhanced Marcus-Backend',
role: 'Backend Expert & System Architect',
description: 'Advanced backend development with parallel processing and comprehensive monitoring',
version: '2.0.0',
enabled: true,
auto_activate: true,
patterns: [
'*.api.js', '*.api.ts', 'server/**', 'backend/**',
'controllers/**', 'models/**', 'routes/**', 'middleware/**',
'database/**', 'migrations/**', 'seeds/**',
'docker-compose.*', 'Dockerfile*', '.env*'
],
keywords: [
'server', 'api', 'database', 'security', 'backend',
'authentication', 'authorization', 'middleware', 'docker',
'microservices', 'database', 'migration', 'cache'
],
tools: [
'express', 'fastify', 'koa', 'nestjs', 'prisma',
'sequelize', 'mongoose', 'typeorm', 'redis',
'postgresql', 'mongodb', 'docker', 'kubernetes'
],
capabilities: {
parallel_execution: true,
stress_testing: true,
health_monitoring: true,
quality_gates: true,
security_scanning: true,
performance_optimization: true,
automated_testing: true,
continuous_integration: true,
documentation_generation: true,
code_analysis: true
},
rules: {
rule1_parallel_tasks: {
enabled: true,
max_parallel_tasks: 10,
collision_detection: true,
resource_management: true,
priority_handling: true,
auto_scaling: true,
triggers: [
{
pattern: 'controllers/**',
action: 'parallel_controller_testing',
condition: 'controller_count > 5',
parallelism_level: 5
},
{
pattern: 'migrations/**',
action: 'parallel_migration_validation',
condition: 'migration_files > 3',
parallelism_level: 3
}
]
},
rule2_stress_testing: {
enabled: true,
auto_generate_tests: true,
test_types: [
StressTestType.LOAD_TEST,
StressTestType.STRESS_TEST,
StressTestType.SECURITY_STRESS,
StressTestType.INTEGRATION_STRESS
],
coverage_threshold: 85,
performance_baseline: true,
chaos_engineering: true,
triggers: [
{
event: 'api_change',
test_type: StressTestType.LOAD_TEST,
target_type: TargetType.API_ENDPOINT,
condition: 'api_endpoint_modified',
priority: Priority.HIGH
},
{
event: 'database_change',
test_type: StressTestType.VOLUME_TEST,
target_type: TargetType.DATABASE,
condition: 'database_schema_modified',
priority: Priority.MEDIUM
}
]
},
rule3_daily_audit: {
enabled: true,
audit_frequency: 'daily',
health_check_interval: 180000, // 3 minutes
alert_thresholds: {
cpu_usage: 85,
memory_usage: 90,
disk_usage: 85,
response_time: 500,
error_rate: 2,
test_coverage: 85
},
compliance_checks: true,
performance_monitoring: true,
security_scanning: true,
triggers: [
{
schedule: '0 1 * * *', // 1 AM daily
audit_type: AuditType.COMPREHENSIVE,
check_categories: [
CheckCategory.SYSTEM,
CheckCategory.SECURITY,
CheckCategory.PERFORMANCE,
CheckCategory.INFRASTRUCTURE
],
notification_level: 'critical'
}
]
},
custom_rules: [
{
id: 'security_scan',
name: 'Automated Security Scan',
description: 'Run security scans on API changes',
condition: 'api_endpoint_added || security_config_changed',
action: 'execute_security_scan',
priority: Priority.CRITICAL,
enabled: true
},
{
id: 'performance_benchmark',
name: 'API Performance Benchmark',
description: 'Benchmark API performance on changes',
condition: 'api_performance_critical_path_changed',
action: 'run_performance_benchmark',
priority: Priority.HIGH,
enabled: true
}
]
},
integration: {
task_manager: true,
stress_tester: true,
audit_system: true,
environment_manager: true,
monitoring_dashboard: true,
notification_system: true,
ci_cd_pipeline: true,
version_control: true
},
performance: {
max_concurrent_tasks: 10,
memory_limit: 8192,
cpu_limit: 85,
timeout_duration: 600000,
retry_attempts: 3,
cache_enabled: true,
optimization_level: OptimizationLevel.AGGRESSIVE
},
collaboration: {
handoff_protocols: [
{
from_agent: 'marcus-backend',
to_agent: 'maria-qa',
trigger_condition: 'api_development_complete',
context_data: ['api_documentation', 'test_data', 'security_requirements'],
validation_required: true
},
{
from_agent: 'marcus-backend',
to_agent: 'james-frontend',
trigger_condition: 'api_ready_for_integration',
context_data: ['api_endpoints', 'response_schemas', 'authentication_flow'],
validation_required: false
}
],
context_preservation: true,
knowledge_sharing: true,
conflict_resolution: {
strategy: ConflictStrategy.PRIORITY_BASED,
escalation_path: ['maria-qa', 'sarah-pm'],
timeout_duration: 60000,
fallback_agent: 'maria-qa'
},
communication_channels: ['websocket', 'event_bus', 'shared_memory', 'message_queue']
},
configured_at: new Date().toISOString()
};
// Enhanced Sarah-PM Configuration
const sarahConfig = {
id: 'sarah-pm',
name: 'Enhanced Sarah-PM',
role: 'Project Manager & Process Orchestrator',
description: 'Advanced project management with automated coordination and comprehensive reporting',
version: '2.0.0',
enabled: true,
auto_activate: true,
patterns: [
'README.md', '*.md', 'docs/**', 'documentation/**',
'.github/**', 'CONTRIBUTING.md', 'CHANGELOG.md',
'package.json', 'package-lock.json', 'yarn.lock',
'.gitignore', '.env.example', 'docker-compose.*'
],
keywords: [
'project', 'plan', 'milestone', 'documentation', 'setup',
'coordination', 'process', 'workflow', 'management',
'reporting', 'metrics', 'status', 'timeline'
],
tools: [
'github', 'jira', 'confluence', 'slack', 'teams',
'prometheus', 'grafana', 'datadog', 'newrelic',
'jenkins', 'circleci', 'github-actions'
],
capabilities: {
parallel_execution: true,
stress_testing: false,
health_monitoring: true,
quality_gates: true,
security_scanning: false,
performance_optimization: true,
automated_testing: false,
continuous_integration: true,
documentation_generation: true,
code_analysis: false
},
rules: {
rule1_parallel_tasks: {
enabled: true,
max_parallel_tasks: 5,
collision_detection: true,
resource_management: true,
priority_handling: true,
auto_scaling: false,
triggers: [
{
pattern: 'docs/**',
action: 'parallel_documentation_generation',
condition: 'documentation_files > 10',
parallelism_level: 3
}
]
},
rule2_stress_testing: {
enabled: false,
auto_generate_tests: false,
test_types: [],
coverage_threshold: 0,
performance_baseline: false,
chaos_engineering: false,
triggers: []
},
rule3_daily_audit: {
enabled: true,
audit_frequency: 'daily',
health_check_interval: 900000, // 15 minutes
alert_thresholds: {
cpu_usage: 60,
memory_usage: 70,
disk_usage: 75,
response_time: 3000,
error_rate: 10,
test_coverage: 70
},
compliance_checks: true,
performance_monitoring: true,
security_scanning: false,
triggers: [
{
schedule: '0 6 * * *', // 6 AM daily
audit_type: AuditType.COMPLIANCE,
check_categories: [CheckCategory.QUALITY, CheckCategory.COMPLIANCE],
notification_level: 'info'
}
]
},
custom_rules: [
{
id: 'milestone_tracking',
name: 'Automated Milestone Tracking',
description: 'Track and report on project milestones',
condition: 'milestone_deadline_approaching',
action: 'generate_milestone_report',
priority: Priority.MEDIUM,
enabled: true
},
{
id: 'team_performance_review',
name: 'Team Performance Review',
description: 'Generate team performance metrics',
condition: 'sprint_completed || week_ended',
action: 'compile_performance_metrics',
priority: Priority.LOW,
enabled: true
}
]
},
integration: {
task_manager: true,
stress_tester: false,
audit_system: true,
environment_manager: true,
monitoring_dashboard: true,
notification_system: true,
ci_cd_pipeline: true,
version_control: true
},
performance: {
max_concurrent_tasks: 5,
memory_limit: 1024,
cpu_limit: 50,
timeout_duration: 120000,
retry_attempts: 2,
cache_enabled: true,
optimization_level: OptimizationLevel.BASIC
},
collaboration: {
handoff_protocols: [
{
from_agent: '*',
to_agent: 'sarah-pm',
trigger_condition: 'escalation_required || conflict_detected',
context_data: ['issue_details', 'stakeholders', 'priority_level'],
validation_required: false
}
],
context_preservation: true,
knowledge_sharing: true,
conflict_resolution: {
strategy: ConflictStrategy.ROUND_ROBIN,
escalation_path: ['external_stakeholder'],
timeout_duration: 120000,
fallback_agent: 'external_stakeholder'
},
communication_channels: ['email', 'slack', 'webhook', 'dashboard']
},
configured_at: new Date().toISOString()
};
// Store configurations
this.agentConfigs.set('maria-qa', mariaConfig);
this.agentConfigs.set('james-frontend', jamesConfig);
this.agentConfigs.set('marcus-backend', marcusConfig);
this.agentConfigs.set('sarah-pm', sarahConfig);
this.emit('configs:initialized', {
agents: Array.from(this.agentConfigs.keys()),
count: this.agentConfigs.size
});
}
/**
* Setup integration between rules and agent systems
*/
setupRuleIntegration() {
// Rule 1: Parallel Task Execution Integration
this.taskManager.on('task:added', (event) => {
this.handleRule1Trigger(event);
});
// Rule 2: Stress Testing Integration
this.stressTestGenerator.on('generation:completed', (event) => {
this.handleRule2Trigger(event);
});
// Rule 3: Daily Audit Integration
this.auditSystem.on('audit:completed', (event) => {
this.handleRule3Trigger(event);
});
this.emit('rule_integration:setup_complete');
}
/**
* Handle Rule 1 triggers (Parallel Task Execution)
*/
handleRule1Trigger(event) {
for (const [agentId, config] of this.agentConfigs) {
if (!config.rules.rule1_parallel_tasks.enabled)
continue;
for (const trigger of config.rules.rule1_parallel_tasks.triggers) {
if (this.matchesTriggerPattern(event, trigger.pattern, trigger.condition)) {
this.executeRule1Action(agentId, trigger, event);
}
}
}
}
/**
* Handle Rule 2 triggers (Stress Testing)
*/
handleRule2Trigger(event) {
for (const [agentId, config] of this.agentConfigs) {
if (!config.rules.rule2_stress_testing.enabled)
continue;
for (const trigger of config.rules.rule2_stress_testing.triggers) {
if (this.matchesStressTestTrigger(event, trigger)) {
this.executeRule2Action(agentId, trigger, event);
}
}
}
}
/**
* Handle Rule 3 triggers (Daily Audit)
*/
handleRule3Trigger(event) {
for (const [agentId, config] of this.agentConfigs) {
if (!config.rules.rule3_daily_audit.enabled)
continue;
this.processAuditResults(agentId, config, event);
}
}
/**
* Execute Rule 1 action (Parallel Tasks)
*/
async executeRule1Action(agentId, trigger, event) {
this.emit('rule1:action_triggered', { agentId, trigger, event });
const config = this.agentConfigs.get(agentId);
if (!config)
return;
try {
switch (trigger.action) {
case 'parallel_test_execution':
await this.executeParallelTests(agentId, trigger.parallelism_level, event);
break;
case 'parallel_component_build':
await this.executeParallelComponentBuild(agentId, trigger.parallelism_level, event);
break;
case 'parallel_controller_testing':
await this.executeParallelControllerTests(agentId, trigger.parallelism_level, event);
break;
case 'parallel_documentation_generation':
await this.executeParallelDocumentation(agentId, trigger.parallelism_level, event);
break;
default:
this.emit('rule1:unknown_action', { action: trigger.action, agentId });
}
}
catch (error) {
this.emit('rule1:action_failed', { agentId, trigger, error });
}
}
/**
* Execute Rule 2 action (Stress Testing)
*/
async executeRule2Action(agentId, trigger, event) {
this.emit('rule2:action_triggered', { agentId, trigger, event });
try {
const target = {
type: trigger.target_type,
component: event.component,
endpoint: event.endpoint
};
const tests = await this.stressTestGenerator.generateStressTests(target);
const testIds = tests.map(test => test.id);
await this.stressTestGenerator.executeStressTests(testIds);
this.emit('rule2:stress_tests_completed', { agentId, testIds, results: testIds.length });
}
catch (error) {
this.emit('rule2:action_failed', { agentId, trigger, error });
}
}
/**
* Process audit results for Rule 3
*/
processAuditResults(agentId, config, event) {
const auditResult = event.result;
const thresholds = config.rules.rule3_daily_audit.alert_thresholds;
// Check for threshold violations
const violations = this.checkThresholdViolations(auditResult, thresholds);
if (violations.length > 0) {
this.emit('rule3:threshold_violations', {
agentId,
violations,
auditResult: auditResult.id
});
// Take corrective actions
this.executeCorrectiveActions(agentId, violations);
}
this.emit('rule3:audit_processed', {
agentId,
auditId: auditResult.id,
violations: violations.length
});
}
/**
* Check for threshold violations in audit results
*/
checkThresholdViolations(auditResult, thresholds) {
const violations = [];
// Check system metrics
if (auditResult.metrics) {
if (auditResult.metrics.cpu > thresholds.cpu_usage) {
violations.push({
type: 'cpu_usage',
actual: auditResult.metrics.cpu,
threshold: thresholds.cpu_usage
});
}
if (auditResult.metrics.memory > thresholds.memory_usage) {
violations.push({
type: 'memory_usage',
actual: auditResult.metrics.memory,
threshold: thresholds.memory_usage
});
}
if (auditResult.metrics.responseTime > thresholds.response_time) {
violations.push({
type: 'response_time',
actual: auditResult.metrics.responseTime,
threshold: thresholds.response_time
});
}
}
return violations;
}
/**
* Execute corrective actions for violations
*/
async executeCorrectiveActions(agentId, violations) {
for (const violation of violations) {
switch (violation.type) {
case 'cpu_usage':
await this.optimizeCpuUsage(agentId);
break;
case 'memory_usage':
await this.optimizeMemoryUsage(agentId);
break;
case 'response_time':
await this.optimizeResponseTime(agentId);
break;
default:
this.emit('rule3:unknown_violation', { violation, agentId });
}
}
}
// Helper methods for parallel execution
async executeParallelTests(agentId, parallelism, event) {
// Implementation for parallel test execution
this.emit('parallel_tests:executed', { agentId, parallelism, event });
}
async executeParallelComponentBuild(agentId, parallelism, event) {
// Implementation for parallel component building
this.emit('parallel_build:executed', { agentId, parallelism, event });
}
async executeParallelControllerTests(agentId, parallelism, event) {
// Implementation for parallel controller testing
this.emit('parallel_controllers:executed', { agentId, parallelism, event });
}
async executeParallelDocumentation(agentId, parallelism, event) {
// Implementation for parallel documentation generation
this.emit('parallel_docs:executed', { agentId, parallelism, event });
}
// Helper methods for optimization
async optimizeCpuUsage(agentId) {
const config = this.agentConfigs.get(agentId);
if (config) {
// Reduce concurrent tasks
config.performance.max_concurrent_tasks = Math.max(1, config.performance.max_concurrent_tasks - 1);
this.emit('optimization:cpu_usage', { agentId, newLimit: config.performance.max_concurrent_tasks });
}
}
async optimizeMemoryUsage(agentId) {
const config = this.agentConfigs.get(agentId);
if (config) {
// Enable aggressive caching and reduce memory limit
config.performance.cache_enabled = true;
config.performance.memory_limit = Math.max(512, config.performance.memory_limit * 0.8);
this.emit('optimization:memory_usage', { agentId, newLimit: config.performance.memory_limit });
}
}
async optimizeResponseTime(agentId) {
const config = this.agentConfigs.get(agentId);
if (config) {
// Increase optimization level
if (config.performance.optimization_level === OptimizationLevel.BASIC) {
config.performance.optimization_level = OptimizationLevel.STANDARD;
}
else if (config.performance.optimization_level === OptimizationLevel.STANDARD) {
config.performance.optimization_level = OptimizationLevel.AGGRESSIVE;
}
this.emit('optimization:response_time', { agentId, newLevel: config.performance.optimization_level });
}
}
// Pattern matching helpers
matchesTriggerPattern(event, pattern, condition) {
// Simple pattern matching implementation
// In real implementation, use more sophisticated pattern matching
return true;
}
matchesStressTestTrigger(event, trigger) {
// Match stress test trigger conditions
return event.type === trigger.event;
}
/**
* Start configuration monitoring
*/
startConfigMonitoring() {
setInterval(() => {
this.monitorAgentPerformance();
}, 60000); // Monitor every minute
this.emit('monitoring:started');
}
/**
* Monitor agent performance and adjust configurations
*/
monitorAgentPerformance() {
for (const [agentId, config] of this.agentConfigs) {
if (!config.enabled)
continue;
// Monitor performance metrics and adjust configurations
this.adjustAgentConfiguration(agentId, config);
}
}
/**
* Adjust agent configuration based on performance
*/
adjustAgentConfiguration(agentId, config) {
// Get current performance metrics (would come from monitoring system)
const metrics = this.getCurrentMetrics(agentId);
// Adjust configuration based on metrics
if (metrics.cpu > 90) {
config.performance.max_concurrent_tasks = Math.max(1, config.performance.max_concurrent_tasks - 1);
}
else if (metrics.cpu < 50 && config.performance.max_concurrent_tasks < 10) {
config.performance.max_concurrent_tasks += 1;
}
this.emit('config:adjusted', { agentId, metrics, config: config.performance });
}
/**
* Get current performance metrics for an agent
*/
getCurrentMetrics(agentId) {
// In real implementation, this would fetch actual metrics
return {
cpu: Math.random() * 100,
memory: Math.random() * 100,
tasks: Math.floor(Math.random() * 10),
responseTime: Math.random() * 1000
};
}
// Public API methods
getAgentConfig(agentId) {
return this.agentConfigs.get(agentId);
}
getAllConfigs() {
return new Map(this.agentConfigs);
}
updateAgentConfig(agentId, updates) {
const config = this.agentConfigs.get(agentId);
if (config) {
Object.assign(config, updates);
config.configured_at = new Date().toISOString();
this.emit('config:updated', { agentId, updates });
}
}
enableAgent(agentId) {
const config = this.agentConfigs.get(agentId);
if (config) {
config.enabled = true;
this.activeAgents.add(agentId);
this.emit('agent:enabled', { agentId });
}
}
disableAgent(agentId) {
const config = this.agentConfigs.get(agentId);
if (config) {
config.enabled = false;
this.activeAgents.delete(agentId);
this.emit('agent:disabled', { agentId });
}
}
getActiveAgents() {
return Array.from(this.activeAgents);
}
getAgentCapabilities(agentId) {
const config = this.agentConfigs.get(agentId);
return config?.capabilities;
}
getAgentRules(agentId) {
const config = this.agentConfigs.get(agentId);
return config?.rules;
}
enableRule(agentId, ruleType) {
const config = this.agentConfigs.get(agentId);
if (config) {
switch (ruleType) {
case 'rule1':
config.rules.rule1_parallel_tasks.enabled = true;
break;
case 'rule2':
config.rules.rule2_stress_testing.enabled = true;
break;
case 'rule3':
config.rules.rule3_daily_audit.enabled = true;
break;
}
this.emit('rule:enabled', { agentId, ruleType });
}
}
disableRule(agentId, ruleType) {
const config = this.agentConfigs.get(agentId);
if (config) {
switch (ruleType) {
case 'rule1':
config.rules.rule1_parallel_tasks.enabled = false;
break;
case 'rule2':
config.rules.rule2_stress_testing.enabled = false;
break;
case 'rule3':
config.rules.rule3_daily_audit.enabled = false;
break;
}
this.emit('rule:disabled', { agentId, ruleType });
}
}
}
export default EnhancedOPERAConfigManager;
//# sourceMappingURL=enhanced-bmad-config.js.map