UNPKG

task-master-neo-sdlc

Version:

Enhanced task management system with Neo SDLC agents and MCP tools for comprehensive, AI-driven software development lifecycle management.

185 lines (158 loc) 4.49 kB
/** * Base Agent for Neo System * * Provides common functionality for all agent types. */ import { log } from '../../../utils/logging.js'; export class BaseAgent { constructor(id, options = {}) { this.id = id; this.capabilities = options.capabilities || []; this.knowledgeDomains = options.knowledgeDomains || []; this.role = options.role || 'general'; this.status = 'available'; this.metrics = { tasksCompleted: 0, successRate: 1.0, avgCompletionTime: 0, qualityScore: 1.0 }; this.currentTask = null; this.history = []; log.info(`BaseAgent ${this.id} initialized with role ${this.role}`); } /** * Update agent metrics * @param {Object} metrics - Metrics to update */ updateMetrics(metrics) { this.metrics = { ...this.metrics, ...metrics }; log.info(`Updated metrics for agent ${this.id}`); } /** * Add task to agent history * @param {Object} task - Task to add to history */ addToHistory(task) { this.history.push({ ...task, timestamp: Date.now() }); // Limit history size if (this.history.length > 100) { this.history = this.history.slice(-100); } } /** * Check if agent has required capabilities * @param {Array<string>} requiredCapabilities - Required capabilities * @returns {boolean} Whether agent has required capabilities */ hasCapabilities(requiredCapabilities) { return requiredCapabilities.every(cap => this.capabilities.includes(cap)); } /** * Check if agent has knowledge in required domains * @param {Array<string>} requiredDomains - Required knowledge domains * @returns {boolean} Whether agent has required knowledge */ hasKnowledge(requiredDomains) { return requiredDomains.every(domain => this.knowledgeDomains.includes(domain)); } /** * Set agent status * @param {string} status - New status */ setStatus(status) { this.status = status; log.info(`Agent ${this.id} status set to ${status}`); } /** * Assign task to agent * @param {Object} task - Task to assign */ assignTask(task) { this.currentTask = task; this.setStatus('busy'); log.info(`Task assigned to agent ${this.id}: ${JSON.stringify(task)}`); } /** * Complete current task * @param {Object} result - Task result * @param {number} quality - Task quality (0-1) */ completeTask(result, quality = 0.8) { if (!this.currentTask) { log.warn(`Agent ${this.id} has no current task to complete`); return; } const task = this.currentTask; const completionTime = Date.now() - task.assignedAt; // Update metrics this.metrics.tasksCompleted++; this.metrics.avgCompletionTime = ( (this.metrics.avgCompletionTime * (this.metrics.tasksCompleted - 1) + completionTime) / this.metrics.tasksCompleted ); this.metrics.qualityScore = ( (this.metrics.qualityScore * (this.metrics.tasksCompleted - 1) + quality) / this.metrics.tasksCompleted ); // Add to history this.addToHistory({ ...task, result, quality, completedAt: Date.now(), completionTime }); // Reset current task this.currentTask = null; this.setStatus('available'); log.info(`Task completed by agent ${this.id} with quality ${quality}`); return { task, result, quality, metrics: this.metrics }; } /** * Fail current task * @param {Error} error - Error that caused the failure */ failTask(error) { if (!this.currentTask) { log.warn(`Agent ${this.id} has no current task to fail`); return; } const task = this.currentTask; // Update metrics this.metrics.successRate = ( (this.metrics.tasksCompleted * this.metrics.successRate) / (this.metrics.tasksCompleted + 1) ); // Add to history this.addToHistory({ ...task, error: error.message, failedAt: Date.now() }); // Reset current task this.currentTask = null; this.setStatus('available'); log.error(`Task failed by agent ${this.id}: ${error.message}`); return { task, error, metrics: this.metrics }; } } // Export a factory function to create base agents export function createBaseAgent(id, options = {}) { return new BaseAgent(id, options); }