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

241 lines 11.2 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.AnalyticsOperations = void 0; const base_1 = require("./base"); const validators_1 = require("./validators"); const fs = __importStar(require("fs/promises")); const path = __importStar(require("path")); class AnalyticsOperations extends base_1.CognitiveCanvasBase { // Snapshot Management async saveSnapshot(filepath) { const snapshotDir = path.dirname(filepath); await fs.mkdir(snapshotDir, { recursive: true }); const nodesSession = this.driver.session(); let nodes = []; try { const nodesResult = await nodesSession.run('MATCH (n) RETURN n'); nodes = nodesResult.records.map(record => { const node = record.get('n'); return { id: node.identity.low ? node.identity.low.toString() : Math.random().toString(36).substring(7), labels: node.labels, properties: node.properties }; }); } finally { await nodesSession.close(); } const relsSession = this.driver.session(); let relationships = []; try { const relsResult = await relsSession.run('MATCH ()-[r]->() RETURN startNode(r) as start, endNode(r) as end, type(r) as type, properties(r) as props'); relationships = relsResult.records.map(record => { const startNode = record.get('start'); const endNode = record.get('end'); return { id: Math.random().toString(36).substring(7), startNode: startNode.identity.low ? startNode.identity.low.toString() : Math.random().toString(36).substring(7), endNode: endNode.identity.low ? endNode.identity.low.toString() : Math.random().toString(36).substring(7), type: record.get('type'), properties: record.get('props') }; }); } finally { await relsSession.close(); } const nodeTypes = {}; nodes.forEach(node => { node.labels.forEach((label) => { nodeTypes[label] = (nodeTypes[label] || 0) + 1; }); }); const snapshot = { version: '1.0.0', timestamp: new Date().toISOString(), metadata: { totalNodes: nodes.length, totalRelationships: relationships.length, nodeTypes }, nodes, relationships }; await fs.writeFile(filepath, JSON.stringify(snapshot, null, 2), 'utf8'); } async loadSnapshot(filepath) { const data = await fs.readFile(filepath, 'utf8'); const snapshot = JSON.parse(data); this.validateSnapshotFormat(snapshot); // Clear existing data const clearSession = this.driver.session(); try { await clearSession.run('MATCH (n) DETACH DELETE n'); } finally { await clearSession.close(); } // Batch create nodes const batchSize = 100; for (let i = 0; i < snapshot.nodes.length; i += batchSize) { const batch = snapshot.nodes.slice(i, i + batchSize); const nodeSession = this.driver.session(); try { for (const node of batch) { const labels = node.labels.join(':'); const query = `CREATE (n:${labels}) SET n = $properties`; await nodeSession.run(query, { properties: node.properties }); } } finally { await nodeSession.close(); } } // Create relationships using property matching for (const rel of snapshot.relationships) { const relSession = this.driver.session(); try { const startNodeProps = snapshot.nodes.find(n => n.id === rel.startNode)?.properties; const endNodeProps = snapshot.nodes.find(n => n.id === rel.endNode)?.properties; if (startNodeProps && endNodeProps && startNodeProps.id && endNodeProps.id) { const query = ` MATCH (start {id: $startId}), (end {id: $endId}) CREATE (start)-[r:${rel.type}]->(end) SET r = $props `; await relSession.run(query, { startId: startNodeProps.id, endId: endNodeProps.id, props: rel.properties || {} }); } } finally { await relSession.close(); } } } async createSnapshot() { const timestamp = new Date().toISOString().replace(/[:.]/g, '-'); const filename = `snapshot-${timestamp}.json`; const filepath = path.join(this.snapshotsDir, filename); await this.saveSnapshot(filepath); return filepath; } async listSnapshots() { try { const files = await fs.readdir(this.snapshotsDir); return files.filter(file => file.endsWith('.json')); } catch (error) { if (error.code === 'ENOENT') { return []; } throw error; } } async restoreFromSnapshot(filepath) { await this.loadSnapshot(filepath); await this.initializeSchema(); } // Failure and Diagnostic Management async storeFailure(failureData) { validators_1.CognitiveCanvasValidators.validateFailureData(failureData); const result = await this.executeQuery('CREATE (f:Failure {id: $id, message: $message, stack: $stack, stackTrace: $stackTrace, context: $context, severity: $severity, type: $type, agentId: $agentId, errorMessage: $errorMessage, timestamp: $timestamp, taskId: $taskId, projectId: $projectId, createdAt: $createdAt}) RETURN f', failureData, 'f'); if (!result) { throw new Error('Failed to store failure'); } return result; } async storeDiagnostic(diagnosticData) { validators_1.CognitiveCanvasValidators.validateDiagnosticData(diagnosticData); const result = await this.executeQuery('CREATE (d:Diagnostic {id: $id, rootCause: $rootCause, solution: $solution, confidence: $confidence, considerations: $considerations, failureId: $failureId, createdAt: $createdAt}) RETURN d', diagnosticData, 'd'); if (!result) { throw new Error('Failed to store diagnostic'); } return result; } async storePattern(patternData) { validators_1.CognitiveCanvasValidators.validatePatternData(patternData); const result = await this.executeQuery('CREATE (p:Pattern {id: $id, type: $type, pattern: $pattern, context: $context, frequency: $frequency, taskOutcome: $taskOutcome, projectId: $projectId, createdAt: $createdAt}) RETURN p', patternData, 'p'); if (!result) { throw new Error('Failed to store pattern'); } return result; } async storeArtifact(artifactData) { validators_1.CognitiveCanvasValidators.validateArtifactData(artifactData); const result = await this.executeQuery('CREATE (a:Artifact {id: $id, type: $type, name: $name, data: $data, content: $content, projectId: $projectId, createdAt: $createdAt}) RETURN a', artifactData, 'a'); if (!result) { throw new Error('Failed to store artifact'); } return result; } // Analytics queries async getKnowledgeGraph(projectId) { const project = await this.executeQuery('MATCH (p:Project {id: $id}) RETURN p', { id: projectId }, 'p'); const tasks = await this.executeQuery('MATCH (t:Task {projectId: $projectId}) RETURN t', { projectId }); const agents = await this.executeQuery('MATCH (a:Agent) RETURN a'); const pheromones = await this.executeQuery('MATCH (ph:Pheromone) RETURN ph'); const decisions = await this.executeQuery('MATCH (ad:ArchitecturalDecision {projectId: $projectId}) RETURN ad', { projectId }); const contracts = await this.executeQuery('MATCH (c:Contract {projectId: $projectId}) RETURN c', { projectId }); const codeModules = await this.executeQuery('MATCH (cm:CodeModule {projectId: $projectId}) RETURN cm', { projectId }); const tests = await this.executeQuery('MATCH (t:Test {projectId: $projectId}) RETURN t', { projectId }); return { project: project, tasks: tasks?.records?.map((r) => r.get('t').properties) || [], agents: agents?.records?.map((r) => r.get('a').properties) || [], pheromones: pheromones?.records?.map((r) => r.get('ph').properties) || [], decisions: decisions?.records?.map((r) => r.get('ad').properties) || [], contracts: contracts?.records?.map((r) => r.get('c').properties) || [], codeModules: codeModules?.records?.map((r) => r.get('cm').properties) || [], tests: tests?.records?.map((r) => r.get('t').properties) || [] }; } // Validation validateSnapshotFormat(snapshot) { const required = ['version', 'timestamp', 'metadata', 'nodes', 'relationships']; if (!required.every(field => snapshot[field] !== undefined)) { throw new Error('Invalid snapshot format: missing required fields'); } if (!Array.isArray(snapshot.nodes) || !Array.isArray(snapshot.relationships)) { throw new Error('Invalid snapshot format: nodes and relationships must be arrays'); } } } exports.AnalyticsOperations = AnalyticsOperations; //# sourceMappingURL=analytics-operations.js.map