UNPKG

@sethdouglasford/claude-flow

Version:

Claude Code Flow - Advanced AI-powered development workflows with SPARC methodology

266 lines (256 loc) 10.6 kB
import { logger } from "../../core/logger.js"; /** * Maintenance Strategy - System maintenance and updates with coordinated agents * Based on the Maintenance Swarm Pattern from swarm documentation * * Features: * - System health checks * - Update planning * - Implementation coordination * - Verification and rollback */ export class MaintenanceStrategy { async decomposeObjective(objective) { logger.info(`Decomposing maintenance objective: ${objective.description}`); const timestamp = Date.now(); const tasks = []; const dependencies = new Map(); // 1. System Health Assessment const healthCheckTaskId = `health-check-${timestamp}`; tasks.push({ id: { id: healthCheckTaskId, swarmId: objective.id, sequence: 1, priority: 1, }, name: "System Health Check", description: "Comprehensive system health assessment", status: "created", priority: "high", type: "monitoring", requirements: { capabilities: ["system_monitoring", "health_assessment", "diagnostics"], tools: ["memory", "monitoring_tools", "diagnostic_tools"], permissions: ["read", "execute"], }, constraints: { dependencies: [], dependents: [], conflicts: [], }, input: { objective: objective.description, phase: "health_check" }, instructions: ` Perform system health check for: ${objective.description} Tasks: 1. Check system vitals (CPU, memory, disk, network) 2. Verify service availability and response times 3. Check log files for errors and warnings 4. Store health report in Memory under 'system_health' 5. Create TodoWrite tasks for issue prioritization Coordination: - Establish baseline health metrics - Identify critical vs non-critical issues - Document current system state and vulnerabilities - Create health monitoring dashboard `, context: { strategy: "maintenance", coordination: "health_checker" }, createdAt: new Date(), updatedAt: new Date(), attempts: [], statusHistory: [], }); // 2. Update Planning (depends on health check) const updatePlanningTaskId = `update-planning-${timestamp}`; tasks.push({ id: { id: updatePlanningTaskId, swarmId: objective.id, sequence: 2, priority: 1, }, name: "Update Planning", description: "Plan maintenance updates and changes", status: "created", priority: "high", type: "coordination", requirements: { capabilities: ["update_planning", "risk_assessment", "change_management"], tools: ["memory", "planning_tools", "version_control"], permissions: ["read", "write"], }, constraints: { dependencies: [], dependents: [], conflicts: [], }, input: { objective: objective.description, phase: "update_planning" }, instructions: ` Plan updates for: ${objective.description} Tasks: 1. Retrieve system health data from Memory 'system_health' 2. Identify required updates (security, dependencies, features) 3. Assess update risks and create rollback plan 4. Store update plan in Memory under 'update_plan' 5. Create TodoWrite tasks for update implementation Coordination: - Prioritize security and critical updates - Plan maintenance windows and downtime - Create detailed rollback procedures - Coordinate with stakeholders for approval `, context: { strategy: "maintenance", coordination: "update_planner" }, createdAt: new Date(), updatedAt: new Date(), attempts: [], statusHistory: [], }); // 3. Backup and Preparation (parallel with update planning) const backupTaskId = `backup-preparation-${timestamp}`; tasks.push({ id: { id: backupTaskId, swarmId: objective.id, sequence: 2, priority: 2, }, name: "Backup and Preparation", description: "Create backups and prepare for maintenance", status: "created", priority: "normal", type: "maintenance", requirements: { capabilities: ["backup_management", "data_protection", "system_preparation"], tools: ["memory", "backup_tools", "file_operations"], permissions: ["read", "write", "backup"], }, constraints: { dependencies: [], dependents: [], conflicts: [], }, input: { objective: objective.description, phase: "backup_preparation" }, instructions: ` Prepare backups for: ${objective.description} Tasks: 1. Create full system and data backups 2. Verify backup integrity and restore procedures 3. Prepare maintenance environment and tools 4. Store backup information in Memory under 'backup_status' 5. Create TodoWrite tasks for maintenance verification Coordination: - Ensure all critical data is backed up - Test backup restoration procedures - Prepare rollback scripts and procedures - Coordinate with update implementation team `, context: { strategy: "maintenance", coordination: "backup_manager" }, createdAt: new Date(), updatedAt: new Date(), attempts: [], statusHistory: [], }); // 4. Update Implementation (depends on planning and backup) const implementationTaskId = `update-implementation-${timestamp}`; tasks.push({ id: { id: implementationTaskId, swarmId: objective.id, sequence: 3, priority: 1, }, name: "Update Implementation", description: "Execute planned maintenance updates", status: "created", priority: "high", type: "maintenance", requirements: { capabilities: ["update_implementation", "system_administration", "deployment"], tools: ["memory", "deployment_tools", "monitoring_tools"], permissions: ["read", "write", "execute", "admin"], }, constraints: { dependencies: [], dependents: [], conflicts: [], }, input: { objective: objective.description, phase: "implementation" }, instructions: ` Implement updates for: ${objective.description} Tasks: 1. Retrieve update plan from Memory 'update_plan' 2. Execute updates in planned sequence 3. Monitor system health during updates 4. Store implementation status in Memory under 'implementation_status' 5. Create TodoWrite tasks for verification Coordination: - Follow planned update sequence and timing - Monitor system health and performance during updates - Be prepared to rollback if issues arise - Coordinate with verification team for testing `, context: { strategy: "maintenance", coordination: "update_implementer" }, createdAt: new Date(), updatedAt: new Date(), attempts: [], statusHistory: [], }); // 5. Verification and Testing (depends on implementation) const verificationTaskId = `verification-testing-${timestamp}`; tasks.push({ id: { id: verificationTaskId, swarmId: objective.id, sequence: 4, priority: 1, }, name: "Verification and Testing", description: "Verify updates and test system functionality", status: "created", priority: "high", type: "testing", requirements: { capabilities: ["system_testing", "verification", "validation"], tools: ["memory", "testing_tools", "monitoring_tools"], permissions: ["read", "write", "execute"], }, constraints: { dependencies: [], dependents: [], conflicts: [], }, input: { objective: objective.description, phase: "verification" }, instructions: ` Verify updates for: ${objective.description} Tasks: 1. Retrieve implementation status from Memory 'implementation_status' 2. Run comprehensive system tests and health checks 3. Verify all services are functioning correctly 4. Store verification results in Memory under 'verification_results' 5. Create TodoWrite tasks for final reporting Coordination: - Test all critical system functions - Verify performance hasn't degraded - Check that all services are running correctly - Document any issues or recommendations `, context: { strategy: "maintenance", coordination: "verification_tester" }, createdAt: new Date(), updatedAt: new Date(), attempts: [], statusHistory: [], }); // Set up dependencies dependencies.set(updatePlanningTaskId, [healthCheckTaskId]); dependencies.set(backupTaskId, [healthCheckTaskId]); dependencies.set(implementationTaskId, [updatePlanningTaskId, backupTaskId]); dependencies.set(verificationTaskId, [implementationTaskId]); logger.info(`Created ${tasks.length} maintenance tasks with dependencies`); return { tasks, dependencies, estimatedDuration: 75, // 1.25 hours for typical maintenance task }; } } //# sourceMappingURL=maintenance.js.map