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
JavaScript
/**
* 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