@vooodooo/magic
Version:
Vooodooo - AI orchestration platform
179 lines • 6.45 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AgentManager = void 0;
exports.createAgentManager = createAgentManager;
/**
* AI Agent Manager for Vooodooo
*
* This module manages AI agent personas that provide specialized assistance
* for different phases of the development lifecycle.
*/
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
// Agent manager class
class AgentManager {
constructor(options) {
this.agentsCache = [];
this.activeAgent = null;
// Default to current working directory if not specified
const rootDir = process.cwd();
this.agentsDir = options?.agentsDir || path_1.default.resolve(rootDir, 'agents');
this.cursorRulesDir = options?.cursorRulesDir || path_1.default.resolve(rootDir, '.cursor/rules');
this.loadAgents();
}
/**
* Load all available agent personas
*/
loadAgents() {
try {
// Check if agents directory exists
if (!fs_1.default.existsSync(this.agentsDir)) {
console.warn(`Agents directory not found: ${this.agentsDir}`);
return;
}
const files = fs_1.default.readdirSync(this.agentsDir);
this.agentsCache = files
.filter((file) => file.endsWith('.mdc'))
.map((file) => {
const filePath = path_1.default.join(this.agentsDir, file);
const content = fs_1.default.readFileSync(filePath, 'utf8');
// Extract front matter
const frontMatterMatch = content.match(/^---\n([\s\S]*?)\n---\n/);
if (!frontMatterMatch || !frontMatterMatch[1]) {
console.warn(`Agent file ${file} does not contain valid front matter`);
return null;
}
try {
// Simple YAML parser without external dependencies
const frontMatter = parseFrontMatter(frontMatterMatch[1]);
if (!frontMatter) {
console.warn(`Invalid front matter in ${file}`);
return null;
}
return {
name: frontMatter.name || 'Unnamed Agent',
description: frontMatter.description || '',
role: frontMatter.role || '',
phase: frontMatter.phase || '',
content: content,
filePath,
};
}
catch (error) {
console.error(`Error parsing front matter in ${file}:`, error);
return null;
}
})
.filter((agent) => agent !== null);
console.log(`Loaded ${this.agentsCache.length} agent personas`);
}
catch (error) {
console.error('Error loading agent personas:', error);
}
}
/**
* Get list of available agents
*/
listAgents() {
return this.agentsCache;
}
/**
* Get agent details by name (case insensitive partial match)
*/
getAgent(nameOrPhase) {
const searchTerm = nameOrPhase.toLowerCase();
// Try direct match first
const agent = this.agentsCache.find((a) => a.name.toLowerCase() === searchTerm ||
a.phase.toLowerCase() === searchTerm);
if (agent)
return agent;
// Try partial match
return (this.agentsCache.find((a) => a.name.toLowerCase().includes(searchTerm) ||
a.phase.toLowerCase().includes(searchTerm)) || null);
}
/**
* Activate an agent for use in Cursor
*/
activateAgent(nameOrPhase) {
const agent = this.getAgent(nameOrPhase);
if (!agent) {
console.error(`Agent "${nameOrPhase}" not found`);
return false;
}
try {
// Ensure cursor rules directory exists
if (!fs_1.default.existsSync(this.cursorRulesDir)) {
fs_1.default.mkdirSync(this.cursorRulesDir, { recursive: true });
}
// Create the active-agent.mdc file in Cursor rules
const targetPath = path_1.default.join(this.cursorRulesDir, 'active-agent.mdc');
const content = agent.content;
fs_1.default.writeFileSync(targetPath, content, 'utf8');
this.activeAgent = agent;
console.log(`Activated agent: ${agent.name}`);
return true;
}
catch (error) {
console.error('Error activating agent:', error);
return false;
}
}
/**
* Deactivate the current agent
*/
deactivateAgent() {
try {
const targetPath = path_1.default.join(this.cursorRulesDir, 'active-agent.mdc');
if (fs_1.default.existsSync(targetPath)) {
fs_1.default.unlinkSync(targetPath);
}
this.activeAgent = null;
console.log('Agent deactivated');
return true;
}
catch (error) {
console.error('Error deactivating agent:', error);
return false;
}
}
/**
* Get the currently active agent
*/
getActiveAgent() {
return this.activeAgent;
}
}
exports.AgentManager = AgentManager;
/**
* Simple YAML front matter parser
*/
function parseFrontMatter(frontMatter) {
try {
const result = {};
const lines = frontMatter.split('\n');
for (const line of lines) {
// Skip empty lines
if (!line.trim())
continue;
// Parse key-value pairs
const match = line.match(/^(.+?):\s*(.*)$/);
if (match && match.length === 3) {
const key = match[1].trim();
const value = match[2].trim();
result[key] = value;
}
}
return result;
}
catch (error) {
console.error('Error parsing front matter:', error);
return null;
}
}
function createAgentManager(options) {
return new AgentManager(options);
}
//# sourceMappingURL=agent-manager.js.map