UNPKG

claude-buddy

Version:

Your friendly AI development companion for Claude Code - supercharge Claude Code with intelligent workflows and safety features

242 lines (241 loc) 9.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PersonaActivationEngine = exports.PersonaLearningEngine = exports.PersonaFlagParser = exports.PersonaManager = exports.personaSystem = exports.PersonaSystem = void 0; const persona_manager_js_1 = __importDefault(require("./persona-manager.js")); exports.PersonaManager = persona_manager_js_1.default; const flag_parser_js_1 = __importDefault(require("./flag-parser.js")); exports.PersonaFlagParser = flag_parser_js_1.default; const learning_engine_js_1 = __importDefault(require("./learning-engine.js")); exports.PersonaLearningEngine = learning_engine_js_1.default; const auto_activation_js_1 = require("./auto-activation.js"); Object.defineProperty(exports, "PersonaActivationEngine", { enumerable: true, get: function () { return auto_activation_js_1.PersonaActivationEngine; } }); class PersonaSystem { manager; flagParser; learningEngine; isInitialized = false; config = null; constructor(configDir) { this.manager = new persona_manager_js_1.default(configDir); this.flagParser = new flag_parser_js_1.default(); this.learningEngine = new learning_engine_js_1.default(); } async initialize() { try { await Promise.all([ this.manager.initialize(), this.learningEngine.initialize() ]); this.isInitialized = true; console.log('Persona system fully initialized'); return true; } catch (error) { console.error('Failed to initialize persona system:', error); return false; } } async processInput(userInput, context = {}) { if (!this.isInitialized) { await this.initialize(); } try { const flagResult = this.flagParser.parseInput(userInput); const validation = this.flagParser.validateFlags(flagResult); if (!validation.isValid) { return { success: false, context: context, prompt: this.createEmptyPrompt(), flags: flagResult, validation, error: 'Invalid flags detected' }; } const learningRecommendations = this.learningEngine.getActivationRecommendations(context); const enhancedContext = { cwd: context.cwd || process.cwd(), cleanedInput: flagResult.cleanedInput, flags: flagResult, learning: learningRecommendations, command: this.flagParser.extractCommand(userInput) || undefined, ...context }; let personaResult; if (flagResult.hasFlags) { personaResult = this.handleManualActivation(flagResult, enhancedContext); } else { personaResult = await this.handleAutoActivation(flagResult.cleanedInput, enhancedContext); } this.recordActivationForLearning(personaResult, enhancedContext); return { success: true, personas: personaResult, context: enhancedContext, prompt: this.generateEnhancedPrompt(personaResult, enhancedContext), flags: flagResult, validation: validation, learning: learningRecommendations }; } catch (error) { console.error('Error processing persona input:', error); return { success: false, context: context, prompt: this.createEmptyPrompt(), flags: this.createEmptyFlags(), validation: this.createEmptyValidation(), error: 'Failed to process persona activation', details: error instanceof Error ? error.message : String(error) }; } } handleManualActivation(flagResult, context) { const instructions = this.flagParser.generateActivationInstructions(flagResult, this.flagParser.validateFlags(flagResult)); const manualPersonas = [ ...instructions.personas.required, ...instructions.personas.preferred ]; return this.manager.activateManualPersonas(manualPersonas, context.cleanedInput, context); } async handleAutoActivation(cleanedInput, context) { return await this.manager.selectPersonas(cleanedInput, context); } recordActivationForLearning(personaResult, context) { const activationData = { userInput: context.cleanedInput, command: context.command, personas: personaResult.activePersonas?.map(p => p.name) || [], collaborationPattern: personaResult.collaboration?.strategy, confidence: personaResult.activePersonas?.map(p => p.confidence) || [], activationType: personaResult.manualMode ? 'manual' : 'automatic', projectType: context.projectType, filePatterns: context.files || [], learningRecommendations: context.learning }; this.learningEngine.recordActivation(activationData); } generateEnhancedPrompt(personaResult, context) { const basePrompt = this.manager.generatePersonaPrompt(personaResult.activePersonas, context.cleanedInput, context); let enhancedPrompt = basePrompt.systemPrompt; if (context.learning && context.learning.reasoning.length > 0) { enhancedPrompt += `\n\n**Learning Insights:**\n`; enhancedPrompt += context.learning.reasoning.map(reason => `- ${reason}`).join('\n'); } if (context.learning && context.learning.adaptations.length > 0) { enhancedPrompt += `\n\n**Recommended Adaptations:**\n`; enhancedPrompt += context.learning.adaptations.map(adaptation => `- ${adaptation.type}: ${adaptation.reason}`).join('\n'); } if (personaResult.manualMode && context.flags?.hasFlags) { enhancedPrompt += `\n\n**Manual Activation Context:**\n`; enhancedPrompt += `User explicitly requested persona activation with specific flags.\n`; if (context.flags.focusAreas.length > 0) { enhancedPrompt += `Focus areas: ${context.flags.focusAreas.join(', ')}\n`; } } return { ...basePrompt, systemPrompt: enhancedPrompt, learningIntegration: context.learning, flagIntegration: context.flags }; } provideFeedback(feedback) { this.learningEngine.recordFeedback(feedback); this.manager.provideFeedback(feedback); } getAnalytics() { return { personaManager: this.manager.getAnalytics(), learning: this.learningEngine.getAnalytics(), systemHealth: { initialized: this.isInitialized, availablePersonas: this.manager.personas?.size || 0, activePersonas: this.manager.activePersonas?.length || 0 } }; } getHelp() { return { flagHelp: this.flagParser.generateHelpText(), availablePersonas: Array.from(this.manager.personas?.keys() || []), commands: [ '/buddy:analyze - Multi-dimensional analysis with persona intelligence', '/buddy:improve - Systematic improvement with expert collaboration', '/buddy:architect - Architecture design with domain expertise', '/buddy:review - Comprehensive review with security, QA, and performance focus', '/buddy:commit - Professional commits with scribe and security personas' ], examples: [ '/buddy:analyze --persona-security --focus security,performance', '/buddy:improve --comprehensive --learn', '/buddy:architect --with-performance --with-security', '/buddy:review --persona-security --persona-qa' ] }; } async reset() { this.manager.reset(); await this.learningEngine.endSession(); } isReady() { return this.isInitialized && this.manager.personas && this.manager.personas.size > 0; } getActivePersonas() { return this.manager.getActivePersonas(); } isPersonaActive(personaName) { return this.manager.isPersonaActive(personaName); } getCommandRecommendations(command) { return this.flagParser.getCommandSuggestions(command); } createEmptyPrompt() { return { systemPrompt: '', personaContext: null, collaboration: null }; } createEmptyFlags() { return { originalInput: '', cleanedInput: '', hasFlags: false, personas: { manual: [], with: [], focus: [] }, modes: { comprehensive: false, singlePersona: false, noCollaboration: false, learn: null }, focusAreas: [], confidence: { override: null, threshold: null } }; } createEmptyValidation() { return { isValid: true, errors: [], warnings: [], suggestions: [] }; } } exports.PersonaSystem = PersonaSystem; exports.personaSystem = new PersonaSystem(); exports.default = PersonaSystem;