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

240 lines 8.9 kB
"use strict"; /** * Prompt Improvement Workflow Management * * Contains core workflow management functionality extracted from optimizer.ts * This is a simplified module to maintain 500-line compliance. * The full implementation remains in optimizer.ts until further refactoring is needed. */ 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.PromptWorkflowManager = void 0; const fs = __importStar(require("fs")); const path = __importStar(require("path")); class PromptWorkflowManager { constructor(cognitiveCanvas, workspaceRoot, promptsDir, historyDir, backupDir) { this.cognitiveCanvas = cognitiveCanvas; this.workspaceRoot = workspaceRoot; this.promptsDir = promptsDir || path.join(workspaceRoot, 'prompts'); this.historyDir = historyDir || path.join(workspaceRoot, '.cortex', 'prompt-history'); this.backupDir = backupDir || path.join(workspaceRoot, '.cortex', 'prompt-backups'); this.versionsFile = path.join(this.historyDir, 'versions.json'); this.auditFile = path.join(this.historyDir, 'audit.json'); this.initializeDirectories(); } /** * Initialize required directories for prompt management */ initializeDirectories() { const dirs = [this.promptsDir, this.historyDir, this.backupDir]; for (const dir of dirs) { if (!fs.existsSync(dir)) { fs.mkdirSync(dir, { recursive: true }); } } // Initialize versions file if it doesn't exist if (!fs.existsSync(this.versionsFile)) { fs.writeFileSync(this.versionsFile, JSON.stringify([], null, 2)); } // Initialize audit file if it doesn't exist if (!fs.existsSync(this.auditFile)) { fs.writeFileSync(this.auditFile, JSON.stringify([], null, 2)); } } /** * Submit improvement proposal for approval */ async submitForApproval(proposal) { try { // Validate proposal const validation = this.validateProposal(proposal); if (!validation.isValid) { return { submitted: false, proposalId: proposal.id, error: `Validation failed: ${validation.errors.join(', ')}` }; } // Store proposal const versions = await this.getVersionHistory(); const version = { id: proposal.id, promptFile: proposal.promptFile, originalContent: proposal.originalContent, improvedContent: proposal.improvedContent, diff: proposal.diff, rationale: proposal.rationale, timestamp: proposal.submittedAt, status: 'pending' }; versions.push(version); await this.saveVersionHistory(versions); // Add audit entry await this.addAuditEntry({ id: `audit-${Date.now()}`, promptFile: proposal.promptFile, action: 'proposed', timestamp: new Date().toISOString(), performedBy: proposal.submittedBy, details: { proposalId: proposal.id, priority: proposal.priority } }); // Create pheromone for approval tracking const pheromone = { id: `proposal-${proposal.id}`, type: 'prompt_improvement_pending', strength: 0.8, context: 'approval_needed', metadata: { proposalId: proposal.id, promptFile: proposal.promptFile, priority: proposal.priority, submittedBy: proposal.submittedBy }, createdAt: new Date().toISOString(), expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString() // 7 days }; await this.cognitiveCanvas.createPheromone(pheromone); return { submitted: true, proposalId: proposal.id, pheromoneId: pheromone.id }; } catch (error) { return { submitted: false, proposalId: proposal.id, error: error.message }; } } /** * Validate improvement proposal */ validateProposal(proposal) { const errors = []; const warnings = []; // Check required fields if (!proposal.id) errors.push('Proposal ID is required'); if (!proposal.promptFile) errors.push('Prompt file is required'); if (!proposal.improvedContent) errors.push('Improved content is required'); if (!proposal.rationale) errors.push('Rationale is required'); // Check if prompt file exists const promptPath = path.join(this.promptsDir, proposal.promptFile); if (!fs.existsSync(promptPath)) { errors.push(`Prompt file does not exist: ${proposal.promptFile}`); } // Validate content differences if (proposal.originalContent === proposal.improvedContent) { warnings.push('No changes detected between original and improved content'); } return { isValid: errors.length === 0, errors, warnings }; } /** * Get version history */ async getVersionHistory() { try { const data = fs.readFileSync(this.versionsFile, 'utf-8'); return JSON.parse(data); } catch (error) { console.warn('Failed to load version history:', error.message); return []; } } /** * Save version history */ async saveVersionHistory(versions) { fs.writeFileSync(this.versionsFile, JSON.stringify(versions, null, 2)); } /** * Save single version to history */ async saveVersionToHistory(version) { try { const versions = await this.getVersionHistory(); versions.push(version); await this.saveVersionHistory(versions); } catch (error) { console.warn('Failed to save version to history:', error.message); } } /** * Add entry to audit trail */ async addAuditEntry(entry) { try { const auditEntries = await this.getAuditTrail(); auditEntries.push(entry); fs.writeFileSync(this.auditFile, JSON.stringify(auditEntries, null, 2)); } catch (error) { console.warn('Failed to add audit entry:', error.message); } } /** * Get audit trail for a specific prompt or all prompts */ async getAuditTrail(promptFile) { try { if (!fs.existsSync(this.auditFile)) { return []; } const data = fs.readFileSync(this.auditFile, 'utf-8'); const auditEntries = JSON.parse(data); if (promptFile) { return auditEntries.filter(entry => entry.promptFile === promptFile); } return auditEntries; } catch (error) { console.warn('Failed to load audit trail:', error.message); return []; } } } exports.PromptWorkflowManager = PromptWorkflowManager; //# sourceMappingURL=workflow.js.map