task-master-neo-sdlc
Version:
Enhanced task management system with Neo SDLC agents and MCP tools for comprehensive, AI-driven software development lifecycle management.
139 lines (119 loc) • 5.38 kB
JavaScript
import { KnowledgeGraph } from '../knowledge-graph';
import { AgentWorkflowSystem } from '../agent-workflow';
export class KnowledgeBaseManagerAgent {
constructor(knowledgeGraph, workflow) {
this.knowledgeGraph = knowledgeGraph;
this.workflow = workflow;
}
/**
* Creates a new knowledge base article.
* @param {string} title - Article title.
* @param {string} content - Article content (e.g., Markdown).
* @param {string[]} [tags=[]] - Keywords or tags for the article.
* @param {string[]} [relatedEntities=[]] - IDs of related KG nodes (e.g., components, features, errors).
* @returns {Promise<object>} The created knowledge base article node data.
*/
async createArticle(title, content, tags = [], relatedEntities = []) {
console.log(`Creating knowledge base article: ${title}`);
const articleId = `kb_article:${title.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '')}_${Date.now()}`;
const articleData = {
id: articleId,
title,
content,
tags,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
version: 1
// Add author, status etc. if needed
};
const edges = relatedEntities.map(targetId => ({
target: targetId,
relationship: 'documents' // Or 'related_to', 'explains' etc.
}));
// Add article to knowledge graph with edges
await this.knowledgeGraph.addNode({
id: articleId,
type: 'kb_article',
data: articleData,
edges: edges
});
console.log(`Knowledge base article ${articleId} created.`);
return articleData;
}
/**
* Updates an existing knowledge base article.
* @param {string} articleId - The ID of the article node in KG.
* @param {object} updates - Fields to update (e.g., { content, tags }).
* @returns {Promise<object>} The updated knowledge base article node data.
*/
async updateArticle(articleId, updates) {
console.log(`Updating knowledge base article: ${articleId}`);
const articleNode = await this.knowledgeGraph.findNodes({ id: articleId, type: 'kb_article' }).then(n => n[0]);
if (!articleNode) {
throw new Error(`Knowledge base article ${articleId} not found.`);
}
// Merge updates, update timestamp, increment version
const updatedData = {
...articleNode.data,
...updates,
updatedAt: new Date().toISOString(),
version: (articleNode.data.version || 0) + 1
};
await this.knowledgeGraph.updateContext({ id: articleId, data: updatedData });
console.log(`Knowledge base article ${articleId} updated.`);
return updatedData;
}
/**
* Searches knowledge base articles based on keywords or tags.
* @param {string} query - Search query string.
* @param {object} [options={}] - Search options (e.g., { limit: 10, tags: ['api'] }).
* @returns {Promise<Array<object>>} A list of matching article node data.
*/
async searchArticles(query, options = {}) {
console.log(`Searching KB for: "${query}"`, options);
// In a real scenario, this would use more sophisticated search (e.g., full-text search on content,
// semantic search, filtering by tags/metadata stored in KG).
// Placeholder: Simple search on title and tags.
const allArticles = await this.knowledgeGraph.findNodes({ type: 'kb_article' });
const queryLower = query.toLowerCase();
const results = allArticles
.map(node => node.data)
.filter(article => {
const titleMatch = article.title.toLowerCase().includes(queryLower);
const tagMatch = Array.isArray(article.tags) && article.tags.some(tag => tag.toLowerCase().includes(queryLower));
const contentMatch = article.content.toLowerCase().includes(queryLower); // Simple content check
let optionsMatch = true;
if (options.tags && Array.isArray(options.tags)) {
optionsMatch = options.tags.every(reqTag => article.tags?.includes(reqTag));
}
return (titleMatch || tagMatch || contentMatch) && optionsMatch;
})
.slice(0, options.limit || 10); // Apply limit
console.log(`Found ${results.length} KB articles matching query.`);
return results;
}
/**
* Links two knowledge base articles together.
* @param {string} sourceArticleId - ID of the source article.
* @param {string} targetArticleId - ID of the target article.
* @param {string} [relationship='related_to'] - Type of relationship.
* @returns {Promise<void>}
*/
async linkArticles(sourceArticleId, targetArticleId, relationship = 'related_to') {
console.log(`Linking KB articles: ${sourceArticleId} -> ${targetArticleId} (${relationship})`);
// Ensure both articles exist (optional, addEdge might handle implicitly)
const [sourceNode, targetNode] = await Promise.all([
this.knowledgeGraph.findNodes({ id: sourceArticleId, type: 'kb_article' }).then(n => n[0]),
this.knowledgeGraph.findNodes({ id: targetArticleId, type: 'kb_article' }).then(n => n[0])
]);
if (!sourceNode || !targetNode) {
throw new Error(`One or both articles not found for linking: ${sourceArticleId}, ${targetArticleId}`);
}
await this.knowledgeGraph.addEdge({
source: sourceArticleId,
target: targetArticleId,
relationship
});
console.log('Articles linked successfully.');
}
}