UNPKG

claude-flow

Version:

Enterprise-grade AI agent orchestration with ruv-swarm integration (Alpha Release)

547 lines (476 loc) โ€ข 17 kB
// SPARC Command Variations // Specialized SPARC commands for different development scenarios import { SparcMethodology } from './index.js'; /** * SPARC Development Command * Full-stack development workflow with TDD */ export async function sparcDev(taskDescription, options = {}) { console.log('๐Ÿš€ SPARC Development Workflow'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-dev', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, autoRemediation: true, mode: 'development', focus: ['specification', 'architecture', 'refinement'], qualityGates: { testCoverage: 85, codeQuality: 80, performance: 200 // ms }, tddCycles: true, continuousIntegration: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC Development completed'); console.log(`๐Ÿ“Š Test Coverage: ${result.refinement?.testResults?.coverage?.toFixed(1)}%`); console.log(`๐ŸŽฏ Code Quality: ${result.refinement?.codeQuality?.overall?.toFixed(1)}/100`); console.log(`โšก Performance: ${result.refinement?.performance?.responseTime?.average}ms`); return result; } catch (error) { console.error('โŒ SPARC Development failed:', error.message); throw error; } } /** * SPARC API Command * API-focused development with OpenAPI specs */ export async function sparcApi(taskDescription, options = {}) { console.log('๐Ÿ”Œ SPARC API Development'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-api', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'api', focus: ['specification', 'architecture', 'refinement'], specializations: { specification: 'api_requirements', architecture: 'api_design', refinement: 'api_testing' }, qualityGates: { apiCoverage: 100, responseTime: 100, // ms securityScore: 90 }, generateOpenAPI: true, includeAuthentication: true, includeValidation: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC API Development completed'); console.log(`๐Ÿ”Œ API Endpoints: ${result.architecture?.apiDesign?.endpoints?.length || 0}`); console.log(`๐Ÿ”’ Security Score: ${result.refinement?.security?.score || 0}/100`); console.log(`๐Ÿ“‹ OpenAPI Spec: Generated`); return result; } catch (error) { console.error('โŒ SPARC API Development failed:', error.message); throw error; } } /** * SPARC UI Command * Frontend/UI development with component architecture */ export async function sparcUi(taskDescription, options = {}) { console.log('๐ŸŽจ SPARC UI Development'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-ui', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'ui', focus: ['specification', 'pseudocode', 'architecture', 'refinement'], specializations: { specification: 'ux_requirements', pseudocode: 'ui_flows', architecture: 'component_design', refinement: 'ui_testing' }, qualityGates: { accessibility: 95, performance: 3000, // ms load time responsiveness: 100 }, includeAccessibility: true, includeResponsiveDesign: true, includeComponentLibrary: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC UI Development completed'); console.log(`๐ŸŽจ Components: ${result.architecture?.components?.length || 0}`); console.log(`โ™ฟ Accessibility: ${result.refinement?.validation?.usability?.accessibility?.score || 0}%`); console.log(`๐Ÿ“ฑ Responsive: ${result.refinement?.validation?.compatibility?.devices?.score || 0}%`); return result; } catch (error) { console.error('โŒ SPARC UI Development failed:', error.message); throw error; } } /** * SPARC Test Command * Test-driven development with comprehensive testing */ export async function sparcTest(taskDescription, options = {}) { console.log('๐Ÿงช SPARC Test-Driven Development'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-test', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'testing', focus: ['specification', 'refinement'], specializations: { specification: 'test_requirements', refinement: 'comprehensive_testing' }, qualityGates: { testCoverage: 95, mutationScore: 80, performanceTests: 100 }, tddCycles: true, includeUnitTests: true, includeIntegrationTests: true, includeE2ETests: true, includePerformanceTests: true, includeMutationTesting: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC Test Development completed'); console.log(`๐Ÿงช Test Coverage: ${result.refinement?.testResults?.coverage?.toFixed(1)}%`); console.log(`๐Ÿ”ฌ Test Types: Unit, Integration, E2E, Performance`); console.log(`โšก TDD Cycles: ${result.refinement?.tddCycles?.length || 0}`); return result; } catch (error) { console.error('โŒ SPARC Test Development failed:', error.message); throw error; } } /** * SPARC Refactor Command * Code refactoring and optimization */ export async function sparcRefactor(taskDescription, options = {}) { console.log('๐Ÿ”„ SPARC Refactoring'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-refactor', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'refactoring', focus: ['architecture', 'refinement'], specializations: { architecture: 'refactoring_design', refinement: 'code_optimization' }, qualityGates: { codeQuality: 90, performance: 150, // ms improvement maintainability: 85 }, preserveFunctionality: true, incremental: true, safetyFirst: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC Refactoring completed'); console.log(`๐Ÿ“ˆ Quality Improvement: +${result.refinement?.refactoring?.after?.overall - result.refinement?.refactoring?.before?.overall || 0} points`); console.log(`โšก Performance Gain: ${result.refinement?.optimizations?.length || 0} optimizations applied`); console.log(`๐Ÿ”ง Refactoring Techniques: ${result.refinement?.refactoring?.techniques?.length || 0}`); return result; } catch (error) { console.error('โŒ SPARC Refactoring failed:', error.message); throw error; } } /** * SPARC Research Command * Research and analysis workflow */ export async function sparcResearch(taskDescription, options = {}) { console.log('๐Ÿ” SPARC Research & Analysis'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-research', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'research', focus: ['specification', 'pseudocode'], specializations: { specification: 'research_requirements', pseudocode: 'analysis_workflow' }, qualityGates: { comprehensiveness: 90, accuracy: 95, relevance: 85 }, includeWebSearch: true, includeDataAnalysis: true, includeLiteratureReview: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC Research completed'); console.log(`๐Ÿ“š Sources Analyzed: ${result.specification?.userStories?.length || 0}`); console.log(`๐Ÿ“Š Analysis Workflows: ${result.pseudocode?.algorithms?.length || 0}`); console.log(`๐ŸŽฏ Research Quality: ${result.specification?.requirements?.filter(r => r.fulfilled)?.length || 0} requirements validated`); return result; } catch (error) { console.error('โŒ SPARC Research failed:', error.message); throw error; } } /** * SPARC Data Command * Data engineering and analytics workflow */ export async function sparcData(taskDescription, options = {}) { console.log('๐Ÿ“Š SPARC Data Engineering'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-data', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'data', focus: ['specification', 'architecture', 'refinement'], specializations: { specification: 'data_requirements', architecture: 'data_architecture', refinement: 'data_validation' }, qualityGates: { dataQuality: 95, performance: 1000, // ms query time accuracy: 99 }, includeDataModeling: true, includeETL: true, includeValidation: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC Data Engineering completed'); console.log(`๐Ÿ“Š Data Models: ${result.architecture?.dataModel?.entities?.length || 0}`); console.log(`๐Ÿ”„ ETL Pipelines: ${result.architecture?.integrationPoints?.length || 0}`); console.log(`โœ… Data Quality: ${result.refinement?.validation?.score || 0}/100`); return result; } catch (error) { console.error('โŒ SPARC Data Engineering failed:', error.message); throw error; } } /** * SPARC Security Command * Security-focused development and auditing */ export async function sparcSecurity(taskDescription, options = {}) { console.log('๐Ÿ”’ SPARC Security Development'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-security', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'security', focus: ['specification', 'architecture', 'refinement'], specializations: { specification: 'security_requirements', architecture: 'security_architecture', refinement: 'security_testing' }, qualityGates: { securityScore: 95, vulnerabilities: 0, compliance: 100 }, includeSecurityReview: true, includePenetrationTesting: true, includeComplianceCheck: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC Security Development completed'); console.log(`๐Ÿ”’ Security Score: ${result.refinement?.security?.score || 0}/100`); console.log(`๐Ÿ›ก๏ธ Vulnerabilities: ${result.refinement?.security?.vulnerabilities?.length || 0}`); console.log(`๐Ÿ“‹ Compliance: ${Object.values(result.refinement?.security?.compliance || {}).filter(c => c).length}/3 standards`); return result; } catch (error) { console.error('โŒ SPARC Security Development failed:', error.message); throw error; } } /** * SPARC DevOps Command * DevOps and deployment workflow */ export async function sparcDevOps(taskDescription, options = {}) { console.log('โš™๏ธ SPARC DevOps Workflow'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-devops', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'devops', focus: ['architecture', 'completion'], specializations: { architecture: 'deployment_architecture', completion: 'devops_deployment' }, qualityGates: { deployment: 100, monitoring: 100, automation: 90 }, includeCI: true, includeCD: true, includeMonitoring: true, includeInfrastructureAsCode: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC DevOps completed'); console.log(`๐Ÿš€ Deployments: ${result.completion?.deployment?.environments?.length || 0} environments`); console.log(`๐Ÿ“Š Monitoring: ${result.completion?.monitoring?.alerts?.length || 0} alerts configured`); console.log(`๐Ÿค– Automation: ${result.completion?.deployment?.successful ? 'Successful' : 'Pending'}`); return result; } catch (error) { console.error('โŒ SPARC DevOps failed:', error.message); throw error; } } /** * SPARC Performance Command * Performance optimization and monitoring */ export async function sparcPerformance(taskDescription, options = {}) { console.log('โšก SPARC Performance Optimization'); const sparcOptions = { ...options, namespace: options.namespace || 'sparc-performance', swarmEnabled: options.swarm || false, neuralLearning: options.learning !== false, mode: 'performance', focus: ['architecture', 'refinement'], specializations: { architecture: 'performance_architecture', refinement: 'performance_optimization' }, qualityGates: { responseTime: 100, // ms throughput: 1000, // req/s resourceUsage: 70 // % }, includeLoadTesting: true, includeProfiler: true, includeCaching: true, includeOptimization: true }; const sparc = new SparcMethodology(taskDescription, sparcOptions); try { const result = await sparc.execute(); console.log('\nโœ… SPARC Performance Optimization completed'); console.log(`โšก Response Time: ${result.refinement?.performance?.responseTime?.average || 0}ms`); console.log(`๐Ÿš€ Throughput: ${result.refinement?.performance?.throughput?.requestsPerSecond || 0} req/s`); console.log(`๐Ÿ“ˆ Optimizations: ${result.refinement?.optimizations?.length || 0} applied`); return result; } catch (error) { console.error('โŒ SPARC Performance Optimization failed:', error.message); throw error; } } /** * Command factory for creating SPARC command variations */ export const sparcCommands = { dev: sparcDev, api: sparcApi, ui: sparcUi, test: sparcTest, refactor: sparcRefactor, research: sparcResearch, data: sparcData, security: sparcSecurity, devops: sparcDevOps, performance: sparcPerformance }; /** * Get available SPARC command variations */ export function getSparcCommands() { return Object.keys(sparcCommands); } /** * Execute a SPARC command variation */ export async function executeSparcCommand(command, taskDescription, options = {}) { if (!sparcCommands[command]) { throw new Error(`Unknown SPARC command: ${command}. Available commands: ${getSparcCommands().join(', ')}`); } return await sparcCommands[command](taskDescription, options); } /** * Get help for SPARC command variations */ export function getSparcCommandHelp(command) { const helpTexts = { dev: 'Full-stack development workflow with TDD and quality gates', api: 'API-focused development with OpenAPI specifications and security', ui: 'Frontend/UI development with component architecture and accessibility', test: 'Test-driven development with comprehensive testing strategies', refactor: 'Code refactoring and optimization while preserving functionality', research: 'Research and analysis workflow with data gathering', data: 'Data engineering and analytics with quality validation', security: 'Security-focused development with auditing and compliance', devops: 'DevOps workflow with CI/CD and infrastructure automation', performance: 'Performance optimization with load testing and monitoring' }; return helpTexts[command] || 'Unknown command'; } /** * Show help for all SPARC command variations */ export function showSparcCommandsHelp() { console.log('๐ŸŽฏ SPARC Command Variations:'); console.log(); for (const [command, helpText] of Object.entries(getSparcCommands().reduce((acc, cmd) => { acc[cmd] = getSparcCommandHelp(cmd); return acc; }, {}))) { console.log(` sparc-${command.padEnd(12)} ${helpText}`); } console.log(); console.log('Usage:'); console.log(' claude-flow sparc-<command> "<task-description>" [options]'); console.log(); console.log('Examples:'); console.log(' claude-flow sparc-dev "build user authentication system"'); console.log(' claude-flow sparc-api "create REST API for e-commerce" --swarm'); console.log(' claude-flow sparc-test "comprehensive testing for payment module"'); console.log(' claude-flow sparc-security "security audit for web application"'); } export default { sparcCommands, getSparcCommands, executeSparcCommand, getSparcCommandHelp, showSparcCommandsHelp };