Files
ruflo/examples/parallel-2/reviewer-agent-test.ts
T
rUvandClaude 8cbc07a6f4 fix: Implement critical swarm fixes and add v1.0.50 changelog
## 🔧 Critical Swarm System Fixes

### Fixed Task File Naming Bug
- Tasks were being saved as '[object Object].json' due to TaskId object structure
- Now properly extracts task ID string for file naming
- Files save correctly as 'task_<id>.json'

### Added Task Timeout Protection
- Implemented automatic timeout detection in task execution loop
- Tasks that exceed timeout (default 5 minutes) are marked as failed
- Prevents swarms from hanging indefinitely on stuck tasks
- Agent state properly cleaned up on timeout

### Fixed Target Directory Propagation
- Testing tasks were receiving null targetDir, preventing file access
- Target directory now extracted from objective description
- All tasks inherit targetDir through context
- Enhanced extractTargetDirectory to check multiple sources

### Improved Task Dependencies
- Fixed taskDependenciesMet to handle both string and TaskId objects
- Added convertDependenciesToTaskDependencies for Map structure
- Dependencies now properly resolve for sequential task execution

### Auto Strategy Integration
- Added missing autoStrategy property and initialization
- Proper AutoStrategy instantiation in coordinator constructor
- Enables intelligent task decomposition for 'auto' strategy

## 📊 Added Comprehensive Benchmarks

### Benchmark Suite Integration
- Added complete Python-based benchmarking tool
- Tests 7 strategies across 5 coordination modes
- 100% success rate across all test scenarios
- Performance metrics: 0.10s - 0.20s execution times

### Real-World Performance Data
- Calculator example: 4m 20s total (3 tasks)
- Task breakdown: Analysis 29%, Implementation 22%, Testing 48%
- Successfully created 6 files with proper directory structure

## 📝 Documentation Updates

### Updated README.md
- Added v1.0.50 changelog with critical fixes
- Integrated benchmark performance results table
- Added real-world timing example
- Removed old update notes for clarity
- Added dedicated Benchmarks & Performance section

## 🧪 Test Results
- Swarm now completes successfully with proper task coordination
- All fixes validated in production environment
- Task files save with correct names
- Testing tasks find implementation files
- Swarms exit cleanly after completion

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-14 22:48:11 +00:00

184 lines
5.3 KiB
TypeScript

#!/usr/bin/env ts-node
/**
* Reviewer Agent Test - Designed for parallel execution
* This agent reviews and validates work
*/
export class ReviewerAgent {
private agentId: string;
private startTime: number;
constructor(id: string = 'reviewer-001') {
this.agentId = id;
this.startTime = Date.now();
}
async performCodeReview(pullRequest: any): Promise<any> {
console.log(`[${this.agentId}] Reviewing PR: ${pullRequest.title}`);
await this.simulateWork(1500);
const review = {
overallRating: 'Approved with suggestions',
score: 7.5,
issues: [
{ severity: 'high', file: pullRequest.files[0], line: 45, issue: 'Potential SQL injection' },
{ severity: 'medium', file: pullRequest.files[1], line: 23, issue: 'Missing error handling' },
{ severity: 'low', file: pullRequest.files[2], line: 67, issue: 'Unused variable' }
],
suggestions: [
'Add input validation for user data',
'Implement proper logging for debugging',
'Consider using prepared statements',
'Add more comprehensive test cases'
],
positives: [
'Good code organization',
'Clear variable naming',
'Comprehensive documentation'
],
testCoverage: '82%',
complexityScore: 'Medium'
};
console.log(`[${this.agentId}] Code review completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
pullRequest: pullRequest.title,
review
};
}
async reviewDocumentation(docPath: string): Promise<any> {
console.log(`[${this.agentId}] Reviewing documentation: ${docPath}`);
await this.simulateWork(800);
const docReview = {
completeness: 85,
clarity: 90,
accuracy: 95,
issues: [
'Missing examples for edge cases',
'Some API parameters not documented',
'Installation steps need more detail'
],
suggestions: [
'Add troubleshooting section',
'Include more code examples',
'Add links to related documentation',
'Include performance considerations'
],
sections: {
introduction: 'Excellent',
apiReference: 'Good',
examples: 'Needs improvement',
troubleshooting: 'Missing'
}
};
console.log(`[${this.agentId}] Documentation review completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
document: docPath,
review: docReview
};
}
async validateQualityStandards(component: string): Promise<any> {
console.log(`[${this.agentId}] Validating quality standards for: ${component}`);
await this.simulateWork(1000);
const validation = {
passedStandards: [
'Code formatting guidelines',
'Naming conventions',
'Security best practices',
'Performance benchmarks',
'Accessibility standards'
],
failedStandards: [
'Test coverage minimum (requires 90%, has 82%)',
'Documentation completeness'
],
warnings: [
'Approaching complexity threshold',
'Some dependencies are outdated'
],
overallCompliance: '87%',
recommendation: 'Address failed standards before production release'
};
console.log(`[${this.agentId}] Quality validation completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
component,
validation
};
}
async reviewArchitecture(design: string): Promise<any> {
console.log(`[${this.agentId}] Reviewing architecture design: ${design}`);
await this.simulateWork(1200);
const architectureReview = {
scalability: 'Good',
maintainability: 'Excellent',
security: 'Good',
performance: 'Very Good',
concerns: [
'Single point of failure in auth service',
'Database might become bottleneck at scale',
'Consider caching strategy for frequently accessed data'
],
strengths: [
'Clear separation of concerns',
'Good use of microservices pattern',
'Proper API gateway implementation'
],
recommendations: [
'Implement circuit breakers',
'Add service mesh for better observability',
'Consider event-driven architecture for some components'
],
score: 8.2
};
console.log(`[${this.agentId}] Architecture review completed`);
return {
agentId: this.agentId,
duration: Date.now() - this.startTime,
design,
review: architectureReview
};
}
private async simulateWork(ms: number): Promise<void> {
await new Promise(resolve => setTimeout(resolve, ms));
}
}
// Allow direct execution
if (require.main === module) {
const reviewer = new ReviewerAgent();
const samplePR = {
title: 'Feature: Add user authentication',
author: 'developer123',
files: ['src/auth/login.ts', 'src/auth/logout.ts', 'tests/auth.test.ts']
};
Promise.all([
reviewer.performCodeReview(samplePR),
reviewer.reviewDocumentation('/docs/api-reference.md'),
reviewer.validateQualityStandards('AuthenticationModule'),
reviewer.reviewArchitecture('Microservices Design v2.0')
]).then(results => {
console.log('\nReviewer Agent Results:', JSON.stringify(results, null, 2));
});
}