UNPKG

claude-flow

Version:

Enterprise-grade AI agent orchestration with WASM-powered ReasoningBank memory and AgentDB vector database (always uses latest agentic-flow)

254 lines (219 loc) 8.37 kB
/** * SparcInit - SPARC methodology initialization mode * Sets up Test-Driven Development with SPARC workflow */ import { IInitMode, InitConfig, InitResult } from '../types/interfaces.js'; export class SparcInit implements IInitMode { getDescription(): string { return 'SPARC (Specification, Pseudocode, Architecture, Refinement, Completion) initialization with TDD workflow'; } getRequiredComponents(): string[] { return ['ConfigManager', 'DatabaseManager', 'TopologyManager', 'AgentRegistry', 'MCPIntegrator']; } validate(): boolean { return true; // SPARC mode is always valid } async initialize(config: InitConfig): Promise<InitResult> { const components: string[] = []; try { // Basic initialization if (config.configManager) { components.push('ConfigManager'); } if (config.databaseManager) { await config.databaseManager.initialize(); components.push('DatabaseManager'); } // Use hierarchical topology for SPARC workflow stages if (config.topologyManager) { await config.topologyManager.configure('hierarchical', []); components.push('TopologyManager'); } if (config.agentRegistry) { await config.agentRegistry.initialize(); components.push('AgentRegistry'); } // Spawn SPARC-specific agents if (config.agentRegistry) { // SPARC Coordinator (orchestrates the entire SPARC workflow) await config.agentRegistry.spawn('coordinator', { capabilities: ['sparc-coordination', 'workflow-management', 'tdd-orchestration'], metadata: { role: 'sparc-coordinator', phase: 'all', authority: 'high' } }); // Specification Agent await config.agentRegistry.spawn('analyst', { capabilities: ['requirement-analysis', 'specification-writing', 'user-story-creation'], metadata: { role: 'specification-agent', phase: 'specification', workflow: 'sparc' } }); // Pseudocode Agent await config.agentRegistry.spawn('researcher', { capabilities: ['algorithm-design', 'pseudocode-creation', 'logic-planning'], metadata: { role: 'pseudocode-agent', phase: 'pseudocode', workflow: 'sparc' } }); // Architecture Agent await config.agentRegistry.spawn('reviewer', { capabilities: ['system-architecture', 'design-patterns', 'component-design'], metadata: { role: 'architecture-agent', phase: 'architecture', workflow: 'sparc' } }); // Refinement Agent (TDD focus) await config.agentRegistry.spawn('coder', { capabilities: ['test-driven-development', 'unit-testing', 'refactoring', 'implementation'], metadata: { role: 'refinement-agent', phase: 'refinement', workflow: 'sparc' } }); // Completion Agent await config.agentRegistry.spawn('tester', { capabilities: ['integration-testing', 'validation', 'quality-assurance', 'documentation'], metadata: { role: 'completion-agent', phase: 'completion', workflow: 'sparc' } }); components.push('SparcAgents'); } // Initialize SPARC MCP integration if (config.mcpIntegrator) { await config.mcpIntegrator.initialize(); // Test SPARC-related MCP functions const sparcStatus = await config.mcpIntegrator.executeCommand({ tool: 'claude-flow', function: 'sparc_mode', parameters: { mode: 'dev', task_description: 'Initialize SPARC workflow' } }); if (sparcStatus.success) { components.push('SparcMCP'); } } // Set up SPARC workflow memory structures if (config.databaseManager) { await config.databaseManager.store('sparc-config', { initialized: true, mode: 'sparc', phases: ['specification', 'pseudocode', 'architecture', 'refinement', 'completion'], tddEnabled: true, workflowActive: false, currentPhase: null, timestamp: new Date().toISOString() }, 'sparc'); // Initialize phase tracking const phases = ['specification', 'pseudocode', 'architecture', 'refinement', 'completion']; for (const phase of phases) { await config.databaseManager.store(`phase-${phase}`, { name: phase, status: 'pending', agent: null, artifacts: [], dependencies: this.getPhaseDependencies(phase) }, 'sparc'); } // Initialize TDD tracking await config.databaseManager.store('tdd-status', { testSuites: [], coverage: 0, redGreenRefactor: { red: [], green: [], refactor: [] } }, 'sparc'); components.push('SparcMemory'); } // Set up SPARC workflow templates if (config.databaseManager) { await config.databaseManager.store('workflow-templates', { 'feature-development': { phases: phases.map(phase => ({ name: phase, description: this.getPhaseDescription(phase), estimatedDuration: this.getPhaseEstimatedDuration(phase), deliverables: this.getPhaseDeliverables(phase) })) } }, 'sparc'); components.push('SparcTemplates'); } return { success: true, mode: 'sparc', components, topology: 'hierarchical', message: 'SPARC workflow initialization completed successfully - TDD methodology active', metadata: { sparcPhases: 5, tddEnabled: true, agentSpecialization: true, workflowOrchestration: true, testDrivenDevelopment: true } }; } catch (error) { return { success: false, mode: 'sparc', components, error: error instanceof Error ? error.message : String(error), message: 'SPARC initialization failed' }; } } private getPhaseDependencies(phase: string): string[] { const dependencies: Record<string, string[]> = { 'specification': [], 'pseudocode': ['specification'], 'architecture': ['specification', 'pseudocode'], 'refinement': ['specification', 'pseudocode', 'architecture'], 'completion': ['specification', 'pseudocode', 'architecture', 'refinement'] }; return dependencies[phase] || []; } private getPhaseDescription(phase: string): string { const descriptions: Record<string, string> = { 'specification': 'Analyze requirements and create detailed specifications', 'pseudocode': 'Design algorithms and create pseudocode representations', 'architecture': 'Design system architecture and component structure', 'refinement': 'Implement code using Test-Driven Development methodology', 'completion': 'Integration testing, validation, and documentation' }; return descriptions[phase] || 'Unknown phase'; } private getPhaseEstimatedDuration(phase: string): number { const durations: Record<string, number> = { 'specification': 1800, // 30 minutes 'pseudocode': 1200, // 20 minutes 'architecture': 2400, // 40 minutes 'refinement': 3600, // 60 minutes (main implementation) 'completion': 1800 // 30 minutes }; return durations[phase] || 1800; } private getPhaseDeliverables(phase: string): string[] { const deliverables: Record<string, string[]> = { 'specification': ['Requirements document', 'User stories', 'Acceptance criteria'], 'pseudocode': ['Algorithm pseudocode', 'Logic flow diagrams', 'Data structures'], 'architecture': ['System architecture', 'Component diagrams', 'API specifications'], 'refinement': ['Test suites', 'Implementation code', 'Refactored code'], 'completion': ['Integration tests', 'Documentation', 'Deployment artifacts'] }; return deliverables[phase] || []; } }