UNPKG

cortexweaver

Version:

CortexWeaver is a command-line interface (CLI) tool that orchestrates a swarm of specialized AI agents, powered by Claude Code and Gemini CLI, to assist in software development. It transforms a high-level project plan (plan.md) into a series of coordinate

210 lines 10.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoreOperations = void 0; class CoreOperations { constructor(driver) { this.driver = driver; } async executeQuery(query, params = {}, returnKey) { const session = this.driver.session(); try { const result = await session.run(query, params); if (!returnKey) return result; if (result.records.length === 0) return null; return result.records[0].get(returnKey).properties; } finally { await session.close(); } } // Project Operations async createProject(projectData) { this.validateProjectData(projectData); const result = await this.executeQuery('CREATE (p:Project {id: $id, name: $name, description: $description, status: $status, createdAt: $createdAt}) RETURN p', projectData, 'p'); if (!result) { throw new Error('Failed to create project'); } return result; } async getProject(id) { return this.executeQuery('MATCH (p:Project {id: $id}) RETURN p', { id }, 'p'); } async updateProjectStatus(id, status) { const result = await this.executeQuery('MATCH (p:Project {id: $id}) SET p.status = $status, p.updatedAt = $updatedAt RETURN p', { id, status, updatedAt: new Date().toISOString() }, 'p'); if (!result) { throw new Error(`Project with id ${id} not found`); } return result; } // Task Operations async createTask(taskData) { this.validateTaskData(taskData); const result = await this.executeQuery('CREATE (t:Task {id: $id, title: $title, description: $description, status: $status, priority: $priority, projectId: $projectId, createdAt: $createdAt}) RETURN t', taskData, 't'); if (!result) { throw new Error('Failed to create task'); } return result; } async updateTaskStatus(taskId, status) { const result = await this.executeQuery('MATCH (t:Task {id: $id}) SET t.status = $status, t.updatedAt = $updatedAt RETURN t', { id: taskId, status, updatedAt: new Date().toISOString() }, 't'); if (!result) { throw new Error(`Task with id ${taskId} not found`); } return result; } async createTaskDependency(fromTaskId, toTaskId) { await this.executeQuery('MATCH (t1:Task {id: $fromTaskId}), (t2:Task {id: $toTaskId}) CREATE (t1)-[r:DEPENDS_ON]->(t2) RETURN r', { fromTaskId, toTaskId }); } // Agent Operations async createAgent(agentData) { this.validateAgentData(agentData); const result = await this.executeQuery('CREATE (a:Agent {id: $id, name: $name, role: $role, capabilities: $capabilities, status: $status, createdAt: $createdAt}) RETURN a', agentData, 'a'); if (!result) { throw new Error('Failed to create agent'); } return result; } async assignAgentToTask(agentId, taskId) { await this.executeQuery('MATCH (a:Agent {id: $agentId}), (t:Task {id: $taskId}) CREATE (t)-[r:ASSIGNED_TO {assignedAt: $assignedAt}]->(a) RETURN r', { agentId, taskId, assignedAt: new Date().toISOString() }); } // Architectural Decisions async storeArchitecturalDecision(decisionData) { this.validateArchitecturalDecisionData(decisionData); const result = await this.executeQuery('CREATE (ad:ArchitecturalDecision {id: $id, title: $title, description: $description, rationale: $rationale, status: $status, projectId: $projectId, createdAt: $createdAt}) RETURN ad', decisionData, 'ad'); if (!result) { throw new Error('Failed to store architectural decision'); } return result; } // Contract Management async createContract(contractData) { this.validateContractData(contractData); const result = await this.executeQuery('CREATE (c:Contract {id: $id, name: $name, type: $type, version: $version, specification: $specification, description: $description, projectId: $projectId, createdAt: $createdAt}) RETURN c', contractData, 'c'); if (!result) { throw new Error('Failed to create contract'); } return result; } async getContract(id) { return this.executeQuery('MATCH (c:Contract {id: $id}) RETURN c', { id }, 'c'); } async updateContract(id, updates) { const updateData = { ...updates, id, updatedAt: new Date().toISOString() }; const result = await this.executeQuery('MATCH (c:Contract {id: $id}) SET c += $updates RETURN c', { id, updates: updateData }, 'c'); if (!result) { throw new Error(`Contract with id ${id} not found`); } return result; } // Code Module Management async createCodeModule(moduleData) { this.validateCodeModuleData(moduleData); const result = await this.executeQuery('CREATE (cm:CodeModule {id: $id, name: $name, filePath: $filePath, type: $type, language: $language, projectId: $projectId, createdAt: $createdAt}) RETURN cm', moduleData, 'cm'); if (!result) { throw new Error('Failed to create code module'); } return result; } async getCodeModule(id) { return this.executeQuery('MATCH (cm:CodeModule {id: $id}) RETURN cm', { id }, 'cm'); } async updateCodeModule(id, updates) { const updateData = { ...updates, id, updatedAt: new Date().toISOString() }; const result = await this.executeQuery('MATCH (cm:CodeModule {id: $id}) SET cm += $updates RETURN cm', { id, updates: updateData }, 'cm'); if (!result) { throw new Error(`Code module with id ${id} not found`); } return result; } // Test Management async createTest(testData) { this.validateTestData(testData); const result = await this.executeQuery('CREATE (t:Test {id: $id, name: $name, filePath: $filePath, type: $type, framework: $framework, projectId: $projectId, createdAt: $createdAt}) RETURN t', testData, 't'); if (!result) { throw new Error('Failed to create test'); } return result; } async getTest(id) { return this.executeQuery('MATCH (t:Test {id: $id}) RETURN t', { id }, 't'); } async updateTest(id, updates) { const updateData = { ...updates, id, updatedAt: new Date().toISOString() }; const result = await this.executeQuery('MATCH (t:Test {id: $id}) SET t += $updates RETURN t', { id, updates: updateData }, 't'); if (!result) { throw new Error(`Test with id ${id} not found`); } return result; } // Prototype Management async createPrototypeNode(prototypeData) { const id = `prototype-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`; const createdAt = new Date().toISOString(); const result = await this.executeQuery('CREATE (p:Prototype {id: $id, contractId: $contractId, pseudocode: $pseudocode, flowDiagram: $flowDiagram, outputPath: $outputPath, createdAt: $createdAt}) RETURN p', { id, contractId: prototypeData.contractId, pseudocode: prototypeData.pseudocode, flowDiagram: prototypeData.flowDiagram, outputPath: prototypeData.outputPath, createdAt }, 'p'); if (!result) { throw new Error('Failed to create prototype node'); } return id; } async linkPrototypeToContract(prototypeId, contractId) { await this.executeQuery('MATCH (p:Prototype {id: $prototypeId}), (c:Contract {id: $contractId}) CREATE (p)-[r:PROTOTYPES {linkedAt: $linkedAt}]->(c) RETURN r', { prototypeId, contractId, linkedAt: new Date().toISOString() }); } // Validation methods validateRequiredFields(data, fields, type) { if (!fields.every(field => data[field] !== undefined && data[field] !== null)) { throw new Error(`Missing required ${type} fields: ${fields.join(', ')}`); } } validateProjectData(data) { this.validateRequiredFields(data, ['id', 'name', 'description', 'status', 'createdAt'], 'project'); } validateTaskData(data) { this.validateRequiredFields(data, ['id', 'title', 'description', 'status', 'priority', 'projectId', 'createdAt'], 'task'); } validateAgentData(data) { this.validateRequiredFields(data, ['id', 'name', 'role', 'capabilities', 'status', 'createdAt'], 'agent'); } validateArchitecturalDecisionData(data) { this.validateRequiredFields(data, ['id', 'title', 'description', 'rationale', 'status', 'projectId', 'createdAt'], 'architectural decision'); } validateContractData(data) { this.validateRequiredFields(data, ['id', 'name', 'type', 'version', 'specification', 'projectId', 'createdAt'], 'contract'); const validTypes = ['openapi', 'json-schema', 'property-definition']; if (!validTypes.includes(data.type)) { throw new Error(`Invalid contract type: ${data.type}. Must be one of: ${validTypes.join(', ')}`); } } validateCodeModuleData(data) { this.validateRequiredFields(data, ['id', 'name', 'filePath', 'type', 'language', 'projectId', 'createdAt'], 'code module'); const validTypes = ['function', 'class', 'module', 'component']; if (!validTypes.includes(data.type)) { throw new Error(`Invalid code module type: ${data.type}. Must be one of: ${validTypes.join(', ')}`); } } validateTestData(data) { this.validateRequiredFields(data, ['id', 'name', 'filePath', 'type', 'framework', 'projectId', 'createdAt'], 'test'); const validTypes = ['unit', 'integration', 'e2e', 'contract']; if (!validTypes.includes(data.type)) { throw new Error(`Invalid test type: ${data.type}. Must be one of: ${validTypes.join(', ')}`); } } } exports.CoreOperations = CoreOperations; //# sourceMappingURL=core-operations.js.map