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

167 lines 7.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PrototyperAgent = void 0; const agent_1 = require("../agent"); class PrototyperAgent extends agent_1.Agent { constructor(mcpClient) { super(); this.mcpClient = mcpClient; } get role() { return this.config?.role || 'Prototyper'; } get capabilities() { return this.config?.capabilities || ['pseudocode-generation', 'logic-flow-design', 'mermaid-diagrams']; } async initialize(config) { config.role = 'Prototyper'; config.capabilities = ['pseudocode-generation', 'logic-flow-design', 'mermaid-diagrams']; await super.initialize(config); } getPromptTemplate() { return `You are a senior implementation planner. Generate detailed pseudocode and logic flows before implementation.`; } async executeTask() { if (!this.currentTask) { throw new Error('No task assigned'); } return { success: true, result: 'Prototyper task completed', metadata: { agent: 'Prototyper' } }; } async processContract(contractId) { try { if (!this.cognitiveCanvas) { throw new Error('Agent not initialized. Call initialize(config) first.'); } // Get contract details from Cognitive Canvas const contractData = await this.cognitiveCanvas.getContract(contractId); if (!contractData) { return { success: false, error: 'Contract not found' }; } // Get guide pheromones for patterns const pheromones = await this.cognitiveCanvas.getPheromonesByType('guide'); // Generate pseudocode and collect token usage const pseudocodeResponse = await this.generatePseudocodeWithUsage(contractData, pheromones); const pseudocode = pseudocodeResponse.content; // Generate flow diagram and collect token usage const flowDiagramResponse = await this.generateFlowDiagramWithUsage(pseudocode); const flowDiagram = flowDiagramResponse.content; // Aggregate token usage const totalTokenUsage = { input_tokens: pseudocodeResponse.tokenUsage.inputTokens + flowDiagramResponse.tokenUsage.inputTokens, output_tokens: pseudocodeResponse.tokenUsage.outputTokens + flowDiagramResponse.tokenUsage.outputTokens, total_tokens: pseudocodeResponse.tokenUsage.totalTokens + flowDiagramResponse.tokenUsage.totalTokens }; // Save to /prototypes directory const outputPath = `/prototypes/${contractData.name || contractId}_prototype.md`; const prototypeContent = `# ${contractData.name || contractId} Prototype\n\n## Pseudocode\n${pseudocode}\n\n## Flow Diagram\n${flowDiagram}`; if (this.mcpClient) { await this.mcpClient.writeFileToWorktree(outputPath, contractData.name || contractId, prototypeContent); } // Create prototype node in Cognitive Canvas const prototypeNodeId = await this.cognitiveCanvas.createPrototypeNode({ contractId, pseudocode, flowDiagram, outputPath }); // Link to contract await this.cognitiveCanvas.linkPrototypeToContract(prototypeNodeId, contractId); return { success: true, pseudocode, flowDiagram, outputPath, architectureReady: true, implementationNotes: `Prototype contains detailed pseudocode ready for implementation`, metadata: { contractId, complexity: 'medium', dependencies: [] }, tokenUsage: totalTokenUsage }; } catch (error) { return { success: false, error: `Failed to process contract: ${error instanceof Error ? error.message : 'Unknown error'}` }; } } async generatePseudocode(contract, pheromones = []) { try { if (!this.claudeClient) { throw new Error('Agent not initialized. Call initialize(config) first.'); } const prompt = this.buildPseudocodePrompt(contract, pheromones); const response = await this.claudeClient.sendMessage(prompt); return response.content; } catch (error) { throw new Error(`Failed to generate pseudocode: ${error instanceof Error ? error.message : 'Unknown error'}`); } } async generatePseudocodeWithUsage(contract, pheromones = []) { try { if (!this.claudeClient) { throw new Error('Agent not initialized. Call initialize(config) first.'); } const prompt = this.buildPseudocodePrompt(contract, pheromones); return await this.claudeClient.sendMessage(prompt); } catch (error) { throw new Error(`Failed to generate pseudocode: ${error instanceof Error ? error.message : 'Unknown error'}`); } } async generateFlowDiagram(pseudocode) { try { if (!this.claudeClient) { throw new Error('Agent not initialized. Call initialize(config) first.'); } const prompt = `Convert the following pseudocode into a Mermaid flowchart diagram:\n\n${pseudocode}`; const response = await this.claudeClient.sendMessage(prompt); return response.content; } catch (error) { throw new Error(`Failed to generate flow diagram: ${error instanceof Error ? error.message : 'Unknown error'}`); } } async generateFlowDiagramWithUsage(pseudocode) { try { if (!this.claudeClient) { throw new Error('Agent not initialized. Call initialize(config) first.'); } const prompt = `Convert the following pseudocode into a Mermaid flowchart diagram:\n\n${pseudocode}`; return await this.claudeClient.sendMessage(prompt); } catch (error) { throw new Error(`Failed to generate flow diagram: ${error instanceof Error ? error.message : 'Unknown error'}`); } } buildPseudocodePrompt(contract, pheromones) { let prompt = `Generate detailed pseudocode for the following contract:\n\n`; prompt += `Contract: ${JSON.stringify(contract, null, 2)}\n\n`; if (pheromones.length > 0) { prompt += `Apply these successful patterns (guide pheromones):\n`; pheromones.forEach(p => { prompt += `- ${p.context} (strength: ${p.strength})\n`; }); prompt += '\n'; } prompt += `Please provide:\n`; prompt += `1. Detailed pseudocode for each endpoint\n`; prompt += `2. Error handling paths\n`; prompt += `3. Input validation logic\n`; prompt += `4. Return value specifications\n`; return prompt; } } exports.PrototyperAgent = PrototyperAgent; //# sourceMappingURL=prototyper.js.map