ruv-swarm
Version:
High-performance neural network swarm orchestration in WebAssembly
209 lines (182 loc) โข 6.81 kB
JavaScript
/**
* Main Claude Code integration orchestrator
* Coordinates all integration modules for modular, remote-capable setup
*/
import { ClaudeIntegrationCore } from './core.js';
import { ClaudeDocsGenerator } from './docs.js';
import { RemoteWrapperGenerator } from './remote.js';
class ClaudeIntegrationOrchestrator {
constructor(options = {}) {
this.options = {
autoSetup: options.autoSetup || false,
forceSetup: options.forceSetup || false,
mergeSetup: options.mergeSetup || false,
backupSetup: options.backupSetup || false,
noBackup: options.noBackup || false,
interactive: options.interactive !== false, // Default to true
workingDir: options.workingDir || process.cwd(),
packageName: options.packageName || 'ruv-swarm',
...options,
};
// Initialize modules
this.core = new ClaudeIntegrationCore(this.options);
this.docs = new ClaudeDocsGenerator(this.options);
this.remote = new RemoteWrapperGenerator(this.options);
}
/**
* Setup complete Claude Code integration
*/
async setupIntegration() {
console.log('๐ Setting up modular Claude Code integration...');
console.log(' Working directory:', this.options.workingDir);
console.log(' Force setup:', this.options.forceSetup);
console.log(' Backup setup:', this.options.backupSetup);
console.log(' Merge setup:', this.options.mergeSetup);
console.log(' Auto setup MCP:', this.options.autoSetup);
try {
const results = {
timestamp: new Date().toISOString(),
workingDir: this.options.workingDir,
success: true,
modules: {},
};
// Step 1: Generate documentation
console.log('\n๐ Step 1: Documentation Generation');
results.modules.docs = await this.docs.generateAll({
force: this.options.forceSetup,
merge: this.options.mergeSetup,
backup: this.options.backupSetup,
noBackup: this.options.noBackup,
interactive: this.options.interactive,
});
// Step 2: Setup remote capabilities
console.log('\n๐ Step 2: Remote Execution Setup');
results.modules.remote = await this.remote.createAll();
// Step 3: Initialize core integration (if auto setup enabled)
if (this.options.autoSetup) {
console.log('\n๐ง Step 3: Core Integration Setup');
try {
results.modules.core = await this.core.initialize();
} catch (error) {
console.log('โ ๏ธ Core integration setup failed (manual setup required)');
console.log(' Error:', error.message);
results.modules.core = {
success: false,
error: error.message,
manualSetup: true,
};
}
} else {
console.log('\n๐ก Step 3: Manual Core Setup Required');
results.modules.core = {
success: true,
manualSetup: true,
instructions: [
'Run: claude mcp add ruv-swarm npx ruv-swarm mcp start',
'Test with: mcp__ruv-swarm__agent_spawn',
],
};
}
// Summary
console.log('\nโ
Modular Claude Code integration setup complete!');
console.log('\n๐ What was created:');
console.log(' ๐ claude.md - Main configuration guide');
console.log(' ๐ .claude/commands/ - Command documentation');
console.log(' ๐ง Cross-platform wrapper scripts');
console.log(' ๐ค Claude helper scripts');
console.log(' ๐ Remote execution support');
console.log('\n๐ Next steps:');
if (results.modules.core.manualSetup) {
console.log(' 1. claude mcp add ruv-swarm npx ruv-swarm mcp start');
console.log(' 2. Test with MCP tools: mcp__ruv-swarm__agent_spawn');
} else {
console.log(' 1. Test with MCP tools: mcp__ruv-swarm__agent_spawn');
}
console.log(' 3. Check .claude/commands/ for detailed usage guides');
console.log(' 4. Use wrapper scripts for remote execution');
return results;
} catch (error) {
console.error('โ Integration setup failed:', error.message);
throw error;
}
}
/**
* Invoke Claude with a prompt using the core module
*/
async invokeClaudeWithPrompt(prompt) {
return await this.core.invokeClaudeWithPrompt(prompt);
}
/**
* Check integration status
*/
async checkStatus() {
console.log('๐ Checking Claude Code integration status...');
try {
const status = {
claudeAvailable: await this.core.isClaudeAvailable(),
filesExist: await this.core.checkExistingFiles(),
workingDir: this.options.workingDir,
timestamp: new Date().toISOString(),
};
console.log('Claude CLI available:', status.claudeAvailable ? 'โ
' : 'โ');
console.log('Integration files exist:', status.filesExist ? 'โ
' : 'โ');
return status;
} catch (error) {
console.error('โ Status check failed:', error.message);
throw error;
}
}
/**
* Clean up integration files
*/
async cleanup() {
console.log('๐งน Cleaning up Claude Code integration files...');
const fs = require('fs').promises;
const path = require('path');
try {
const filesToRemove = [
'claude.md',
'.claude',
this.options.packageName,
`${this.options.packageName }.bat`,
`${this.options.packageName }.ps1`,
'claude-swarm.sh',
'claude-swarm.bat',
];
const removedFiles = [];
for (const file of filesToRemove) {
try {
const filePath = path.join(this.options.workingDir, file);
await fs.rm(filePath, { recursive: true, force: true });
removedFiles.push(file);
} catch {
// File doesn't exist, continue
}
}
console.log('โ
Cleanup complete. Removed:', removedFiles.join(', '));
return { success: true, removedFiles };
} catch (error) {
console.error('โ Cleanup failed:', error.message);
throw error;
}
}
}
// Convenience function for simple setup
async function setupClaudeIntegration(options = {}) {
const orchestrator = new ClaudeIntegrationOrchestrator(options);
return await orchestrator.setupIntegration();
}
// Convenience function for Claude invocation
async function invokeClaudeWithSwarm(prompt, options = {}) {
const orchestrator = new ClaudeIntegrationOrchestrator(options);
return await orchestrator.invokeClaudeWithPrompt(prompt);
}
export {
ClaudeIntegrationOrchestrator,
setupClaudeIntegration,
invokeClaudeWithSwarm,
// Export individual modules for advanced usage
ClaudeIntegrationCore,
ClaudeDocsGenerator,
RemoteWrapperGenerator,
};