UNPKG

adpa-enterprise-framework-automation

Version:

Modular, standards-compliant Node.js/TypeScript automation framework for enterprise requirements, project, and data management. Provides CLI and API for BABOK v3, PMBOK 7th Edition, and DMBOK 2.0 (in progress). Production-ready Express.js API with TypeSpe

156 lines โ€ข 7.55 kB
/** * Direct Context Injection Example * Demonstrates the new Enhanced Context Manager capabilities * for automatically discovering and injecting high-relevance markdown files */ import { ContextManager } from '../modules/contextManager.js'; import { getReadmeContent } from '../modules/projectAnalyzer.js'; import * as path from 'path'; /** * Example: Using Direct Context Injection with Enhanced Context Manager */ export async function demonstrateDirectContextInjection(projectPath) { console.log('๐Ÿš€ Direct Context Injection Demo'); console.log('====================================='); try { // 1. Initialize Enhanced Context Manager const contextManager = new ContextManager(); console.log('โœ… Enhanced Context Manager initialized'); // 2. Create core context from README const readmeContent = await getReadmeContent(projectPath); if (readmeContent) { await contextManager.createCoreContext(readmeContent); console.log('โœ… Core context created from README'); } else { console.log('โš ๏ธ No README.md found, using minimal core context'); await contextManager.createCoreContext('Project analysis in progress...'); } // 3. Inject high-relevance markdown files automatically console.log('\n๐Ÿ“„ Discovering and injecting high-relevance markdown files...'); const injectedCount = await contextManager.injectHighRelevanceMarkdownFiles(projectPath, 75, // Minimum relevance score 8 // Maximum files to inject ); // 4. Get injection statistics const stats = contextManager.getInjectionStatistics(); console.log('\n๐Ÿ“Š Injection Statistics:'); console.log(` โ€ข Files injected: ${stats.totalInjected}`); console.log(` โ€ข Tokens used: ${stats.totalTokensInjected.toLocaleString()}`); console.log(` โ€ข Remaining budget: ${stats.remainingTokenBudget.toLocaleString()}`); // 5. Show injected context keys if (stats.injectedKeys.length > 0) { console.log('\n๐Ÿ”‘ Injected Context Keys:'); stats.injectedKeys.forEach(key => console.log(` โ€ข ${key}`)); } // 6. Generate context utilization report console.log('\n๐Ÿ“ˆ Context Utilization Report:'); const report = contextManager.getContextUtilizationReport(); console.log(report); // 7. Test context building for different document types console.log('\n๐Ÿงช Testing Context Building:'); const testDocuments = ['project-charter', 'user-stories', 'tech-stack-analysis']; for (const docType of testDocuments) { const context = contextManager.buildContextForDocument(docType); const contextTokens = Math.ceil(context.length / 3.5); console.log(` โ€ข ${docType}: ${contextTokens.toLocaleString()} tokens`); } // 8. Analyze document-specific context console.log('\n๐Ÿ” Document Context Analysis:'); const analysis = contextManager.analyzeDocumentContext('project-charter'); console.log(` โ€ข Total tokens: ${analysis.totalTokens.toLocaleString()}`); console.log(` โ€ข Utilization: ${analysis.utilizationPercentage.toFixed(1)}%`); console.log(` โ€ข Included contexts: ${analysis.includedContexts.length}`); console.log(` โ€ข Potential contexts: ${analysis.potentialContexts.length}`); if (analysis.recommendations.length > 0) { console.log(' โ€ข Recommendations:'); analysis.recommendations.forEach(rec => console.log(` - ${rec}`)); } console.log('\nโœ… Direct Context Injection demonstration completed!'); } catch (error) { console.error('โŒ Error during demonstration:', error); } } /** * Example: Using specific file injection */ export async function demonstrateSpecificFileInjection(projectPath, filePaths) { console.log('\n๐ŸŽฏ Specific File Injection Demo'); console.log('====================================='); try { const contextManager = new ContextManager(); // Initialize with minimal context await contextManager.createCoreContext('Project with specific file injection...'); // Inject specific files const injectedCount = await contextManager.injectSpecificMarkdownFiles(filePaths, projectPath); console.log(`โœ… Injected ${injectedCount} specific files`); // Show results const stats = contextManager.getInjectionStatistics(); console.log(`๐Ÿ“Š Token usage: ${stats.totalTokensInjected.toLocaleString()}`); } catch (error) { console.error('โŒ Error during specific file injection:', error); } } /** * Example: Context cleanup and management */ export async function demonstrateContextManagement(projectPath) { console.log('\n๐Ÿงน Context Management Demo'); console.log('====================================='); try { const contextManager = new ContextManager(); // Initialize and inject content await contextManager.createCoreContext('Test context for cleanup demo...'); await contextManager.injectHighRelevanceMarkdownFiles(projectPath, 70, 5); const beforeStats = contextManager.getInjectionStatistics(); console.log(`๐Ÿ“Š Before cleanup: ${beforeStats.totalInjected} injected contexts`); // Clear injected context contextManager.clearInjectedContext(); const afterStats = contextManager.getInjectionStatistics(); console.log(`โœ… After cleanup: ${afterStats.totalInjected} injected contexts`); // Show general metrics const metrics = contextManager.getMetrics(); console.log('\n๐Ÿ“ˆ Context Manager Metrics:'); console.log(` โ€ข Core context tokens: ${metrics.coreContextTokens.toLocaleString()}`); console.log(` โ€ข Enriched context count: ${metrics.enrichedContextCount}`); console.log(` โ€ข Cache size: ${metrics.cacheSize}`); console.log(` โ€ข Max tokens: ${metrics.maxTokens.toLocaleString()}`); } catch (error) { console.error('โŒ Error during context management demo:', error); } } /** * Run all demonstrations */ export async function runAllDirectContextInjectionExamples(projectPath) { console.log('๐ŸŒŸ DIRECT CONTEXT INJECTION - FULL DEMONSTRATION'); console.log('================================================'); // Main demonstration await demonstrateDirectContextInjection(projectPath); // Example specific files (if they exist) const exampleFiles = [ path.join(projectPath, 'docs', 'architecture.md'), path.join(projectPath, 'docs', 'requirements.md'), path.join(projectPath, 'CONTRIBUTING.md') ].filter(filePath => { // In a real implementation, you'd check if files exist return true; // For demo purposes }); if (exampleFiles.length > 0) { await demonstrateSpecificFileInjection(projectPath, exampleFiles); } // Context management await demonstrateContextManagement(projectPath); console.log('\n๐ŸŽ‰ All Direct Context Injection examples completed!'); } // Usage example (commented out for library use) /* // To run the demo: (async () => { const projectPath = 'c:/Users/menno/Source/Repos/requirements-gathering-agent'; await runAllDirectContextInjectionExamples(projectPath); })(); */ //# sourceMappingURL=directContextInjectionExample.js.map