task-master-neo-sdlc
Version:
Enhanced task management system with Neo SDLC agents and MCP tools for comprehensive, AI-driven software development lifecycle management.
83 lines (73 loc) • 4 kB
JavaScript
import { KnowledgeGraph } from '../knowledge-graph';
import { AgentWorkflowSystem } from '../agent-workflow';
// Assume requirements might be stored in KG nodes with type 'requirement'
// or fetched from external sources.
export class RequirementsValidatorAgent {
constructor(knowledgeGraph, workflow) {
this.knowledgeGraph = knowledgeGraph;
this.workflow = workflow;
}
/**
* Validates a target entity (e.g., component, feature, API) against associated requirements.
* @param {string} targetEntityId - The ID of the entity to validate (e.g., 'component:button').
* @param {string[]} [requirementIds] - Optional list of specific requirement IDs to validate against. If null, finds associated requirements via KG.
* @returns {Promise<object>} A validation report object.
*/
async validateAgainstRequirements(targetEntityId, requirementIds = null) {
console.log(`Validating ${targetEntityId} against requirements:`, requirementIds || 'Associated');
const targetNode = await this.knowledgeGraph.findNodes({ id: targetEntityId }).then(n => n[0]);
if (!targetNode) {
throw new Error(`Target entity ${targetEntityId} not found for validation.`);
}
let requirementsToValidate = [];
if (requirementIds) {
// Fetch specific requirements by ID
const reqNodes = await this.knowledgeGraph.findNodes({ ids: requirementIds, type: 'requirement' });
requirementsToValidate = reqNodes.map(n => n.data);
} else {
// Find requirements linked to the target entity in the KG
const edges = await this.knowledgeGraph.findEdges({ target: targetEntityId, relationship: 'implements' }); // Assuming 'implements' relationship
const sourceReqIds = edges.map(e => e.source);
const reqNodes = await this.knowledgeGraph.findNodes({ ids: sourceReqIds, type: 'requirement' });
requirementsToValidate = reqNodes.map(n => n.data);
requirementIds = reqNodes.map(n => n.id); // Store the IDs found
}
if (requirementsToValidate.length === 0) {
console.log(`No requirements found for ${targetEntityId}. Skipping validation.`);
return { id: `reqVal_${Date.now()}`, target: targetEntityId, requirementsChecked: [], violations: [], status: 'skipped' };
}
const violations = [];
// Placeholder validation logic:
// In a real scenario, this would involve checking the targetNode's data (properties, implementation, tests)
// against the criteria defined in each requirementToValidate.
for (const req of requirementsToValidate) {
console.log(` - Checking requirement: ${req.id} - ${req.summary || 'No summary'}`);
// Example: Check if a required property exists on the target
if (req.criteria?.requiredProperty && !targetNode.data?.[req.criteria.requiredProperty]) {
violations.push({ requirementId: req.id, details: `Missing required property: ${req.criteria.requiredProperty}` });
}
// Example: Check if implementation details match requirement keywords
if (req.criteria?.keyword && !JSON.stringify(targetNode.data).includes(req.criteria.keyword)) {
violations.push({ requirementId: req.id, details: `Implementation may not meet criteria keyword: ${req.criteria.keyword}` });
}
}
const reportId = `reqValidation_${Date.now()}`;
const report = {
id: reportId,
timestamp: Date.now(),
target: targetEntityId,
requirementsChecked: requirementIds || [], // IDs of requirements checked
violations: violations,
status: violations.length === 0 ? 'compliant' : 'non-compliant'
};
// Add report to knowledge graph
await this.knowledgeGraph.addNode({
id: `requirementsValidation:${reportId}`,
type: 'requirements_validation_report',
data: report,
edges: [{ target: targetEntityId, relationship: 'validates' }]
});
console.log(`Requirements validation ${reportId} completed. Status: ${report.status}`);
return report;
}
}