mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
- Reorganize v3/ into implementation/ subfolders: - planning/, architecture/, migration/, integration/ - security/, adrs/, research/, swarm-plans/ - Add 15-agent concurrent swarm implementation plans: - SWARM-OVERVIEW.md: Hierarchical mesh topology, 4 phases - AGENT-SPECIFICATIONS.md: 15 agent configs with capabilities - TDD-LONDON-SCHOOL-PLAN.md: Mock-first TDD methodology - BENCHMARK-OPTIMIZATION.md: Performance targets (2.49x-7.47x) - DEPLOYMENT-PLAN.md: Release strategy, CI/CD, rollback - GITHUB-ISSUE-TRACKING.md: Issue workflow with agent replies - Update .claude/settings.json with proper hooks format - Add bash aliases for claude --dangerously-skip-permissions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
254 lines
7.4 KiB
JavaScript
254 lines
7.4 KiB
JavaScript
/**
|
|
* Simple Swarm Executor - Provides basic swarm functionality without TypeScript dependencies
|
|
*/
|
|
|
|
import { promises as fs } from 'fs';
|
|
import path from 'path';
|
|
|
|
// Simple ID generator to avoid build dependencies
|
|
function generateId(prefix = 'id') {
|
|
const timestamp = Date.now().toString(36);
|
|
const random = Math.random().toString(36).substring(2, 9);
|
|
return `${prefix}_${timestamp}_${random}`;
|
|
}
|
|
|
|
// Simple SwarmCoordinator implementation
|
|
export class SwarmCoordinator {
|
|
constructor(config) {
|
|
this.config = config;
|
|
this.id = config.name || generateId('swarm');
|
|
this.agents = [];
|
|
this.tasks = [];
|
|
this.status = 'initializing';
|
|
this.startTime = Date.now();
|
|
}
|
|
|
|
async initialize() {
|
|
console.log(`\n🚀 Swarm initialized: ${this.id}`);
|
|
console.log(`📋 Description: ${this.config.description}`);
|
|
console.log(`🎯 Strategy: ${this.config.strategy}`);
|
|
console.log(`🏗️ Mode: ${this.config.mode}`);
|
|
console.log(`🤖 Max Agents: ${this.config.maxAgents}`);
|
|
|
|
this.status = 'active';
|
|
|
|
// Create swarm directory
|
|
const swarmDir = `./swarm-runs/${this.id}`;
|
|
await fs.mkdir(swarmDir, { recursive: true });
|
|
|
|
// Save configuration
|
|
await fs.writeFile(path.join(swarmDir, 'config.json'), JSON.stringify(this.config, null, 2));
|
|
|
|
return this;
|
|
}
|
|
|
|
async addAgent(type, name) {
|
|
const agent = {
|
|
id: generateId('agent'),
|
|
type,
|
|
name: name || `${type}-${this.agents.length + 1}`,
|
|
status: 'active',
|
|
tasks: [],
|
|
};
|
|
|
|
this.agents.push(agent);
|
|
console.log(` 🤖 Agent spawned: ${agent.name} (${agent.type})`);
|
|
|
|
return agent;
|
|
}
|
|
|
|
async executeTask(task) {
|
|
const taskObj = {
|
|
id: generateId('task'),
|
|
description: task,
|
|
status: 'in_progress',
|
|
startTime: Date.now(),
|
|
};
|
|
|
|
this.tasks.push(taskObj);
|
|
console.log(`\n📌 Executing task: ${task}`);
|
|
|
|
// Simulate task execution with progress
|
|
console.log(` ⏳ Processing...`);
|
|
|
|
// Simulate different types of tasks
|
|
if (task.toLowerCase().includes('api')) {
|
|
await this.createAPIProject();
|
|
} else if (task.toLowerCase().includes('test')) {
|
|
await this.runTests();
|
|
} else {
|
|
await this.genericTaskExecution(task);
|
|
}
|
|
|
|
taskObj.status = 'completed';
|
|
taskObj.endTime = Date.now();
|
|
|
|
console.log(` ✅ Task completed in ${(taskObj.endTime - taskObj.startTime) / 1000}s`);
|
|
|
|
return taskObj;
|
|
}
|
|
|
|
async createAPIProject() {
|
|
console.log(` 🏗️ Creating API project structure...`);
|
|
|
|
const projectDir = './api-project';
|
|
await fs.mkdir(projectDir, { recursive: true });
|
|
|
|
// Create basic Express server
|
|
const serverCode = `const express = require('express');
|
|
const app = express();
|
|
const port = process.env.PORT || 3000;
|
|
|
|
app.use(express.json());
|
|
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'healthy', swarm: '${this.id}' });
|
|
});
|
|
|
|
app.get('/api/items', (req, res) => {
|
|
res.json({ items: [], count: 0 });
|
|
});
|
|
|
|
app.listen(port, () => {
|
|
console.log(\`API server running on port \${port}\`);
|
|
});
|
|
|
|
module.exports = app;
|
|
`;
|
|
|
|
await fs.writeFile(path.join(projectDir, 'server.js'), serverCode);
|
|
|
|
// Create package.json
|
|
const packageJson = {
|
|
name: 'api-project',
|
|
version: '1.0.0',
|
|
description: 'API created by Claude Flow Swarm',
|
|
main: 'server.js',
|
|
scripts: {
|
|
start: 'node server.js',
|
|
dev: 'nodemon server.js',
|
|
},
|
|
dependencies: {
|
|
express: '^4.18.2',
|
|
},
|
|
devDependencies: {
|
|
nodemon: '^3.0.1',
|
|
},
|
|
};
|
|
|
|
await fs.writeFile(path.join(projectDir, 'package.json'), JSON.stringify(packageJson, null, 2));
|
|
|
|
console.log(` ✅ Created API project in ${projectDir}`);
|
|
}
|
|
|
|
async runTests() {
|
|
console.log(` 🧪 Running tests...`);
|
|
console.log(` ✅ All tests passed (0 tests)`);
|
|
}
|
|
|
|
async genericTaskExecution(task) {
|
|
console.log(` 🔄 Executing: ${task}`);
|
|
|
|
// Simulate work being done
|
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
|
|
console.log(` ✅ Generic task completed`);
|
|
}
|
|
|
|
async getStatus() {
|
|
return {
|
|
id: this.id,
|
|
status: this.status,
|
|
agents: this.agents.length,
|
|
tasks: {
|
|
total: this.tasks.length,
|
|
completed: this.tasks.filter((t) => t.status === 'completed').length,
|
|
in_progress: this.tasks.filter((t) => t.status === 'in_progress').length,
|
|
},
|
|
runtime: Math.floor((Date.now() - this.startTime) / 1000),
|
|
};
|
|
}
|
|
|
|
async complete() {
|
|
this.status = 'completed';
|
|
|
|
const summary = await this.getStatus();
|
|
console.log(`\n✅ Swarm completed successfully!`);
|
|
console.log(`📊 Summary:`);
|
|
console.log(` • Swarm ID: ${summary.id}`);
|
|
console.log(` • Total Agents: ${summary.agents}`);
|
|
console.log(` • Tasks Completed: ${summary.tasks.completed}`);
|
|
console.log(` • Runtime: ${summary.runtime}s`);
|
|
|
|
// Save summary
|
|
const swarmDir = `./swarm-runs/${this.id}`;
|
|
await fs.writeFile(path.join(swarmDir, 'summary.json'), JSON.stringify(summary, null, 2));
|
|
|
|
return summary;
|
|
}
|
|
}
|
|
|
|
// Main execution function
|
|
export async function executeSwarm(objective, flags = {}) {
|
|
try {
|
|
// Parse configuration from flags
|
|
const config = {
|
|
name: generateId('swarm'),
|
|
description: objective,
|
|
mode: flags.mode || 'centralized',
|
|
strategy: flags.strategy || 'auto',
|
|
maxAgents: parseInt(flags['max-agents']) || 5,
|
|
maxTasks: parseInt(flags['max-tasks']) || 100,
|
|
timeout: (parseInt(flags.timeout) || 60) * 60 * 1000,
|
|
taskTimeoutMinutes: parseInt(flags['task-timeout-minutes']) || 59,
|
|
qualityThreshold: parseFloat(flags['quality-threshold']) || 0.8,
|
|
reviewRequired: flags.review || false,
|
|
testingRequired: flags.testing || false,
|
|
monitoring: {
|
|
enabled: flags.monitor || false,
|
|
},
|
|
memory: {
|
|
namespace: flags['memory-namespace'] || 'swarm',
|
|
persistent: flags.persistence !== false,
|
|
},
|
|
security: {
|
|
encryptionEnabled: flags.encryption || false,
|
|
},
|
|
};
|
|
|
|
// Initialize swarm coordinator
|
|
const coordinator = new SwarmCoordinator(config);
|
|
await coordinator.initialize();
|
|
|
|
// Spawn agents based on strategy
|
|
if (config.strategy === 'development' || config.strategy === 'auto') {
|
|
await coordinator.addAgent('architect', 'System Architect');
|
|
await coordinator.addAgent('coder', 'Backend Developer');
|
|
await coordinator.addAgent('coder', 'Frontend Developer');
|
|
await coordinator.addAgent('tester', 'QA Engineer');
|
|
await coordinator.addAgent('reviewer', 'Code Reviewer');
|
|
} else if (config.strategy === 'research') {
|
|
await coordinator.addAgent('researcher', 'Lead Researcher');
|
|
await coordinator.addAgent('analyst', 'Data Analyst');
|
|
await coordinator.addAgent('researcher', 'Research Assistant');
|
|
} else if (config.strategy === 'testing') {
|
|
await coordinator.addAgent('tester', 'Test Lead');
|
|
await coordinator.addAgent('tester', 'Integration Tester');
|
|
await coordinator.addAgent('tester', 'Performance Tester');
|
|
}
|
|
|
|
// Execute the main objective
|
|
await coordinator.executeTask(objective);
|
|
|
|
// Complete and return summary
|
|
const summary = await coordinator.complete();
|
|
|
|
return { success: true, summary };
|
|
} catch (error) {
|
|
console.error(`❌ Swarm execution failed: ${error.message}`);
|
|
return { success: false, error: error.message };
|
|
}
|
|
}
|
|
|
|
// Exports are already declared inline above
|