UNPKG

mcp-adr-analysis-server

Version:

MCP server for analyzing Architectural Decision Records and project architecture

284 lines 8.94 kB
/** * MCP Tool for Bootstrap Validation Loop with ADR Learning * * Implements a self-learning architecture validation system: * 1. Generate bootstrap scripts from ADRs * 2. Execute scripts in real environment with monitoring * 3. Capture learnings and failures * 4. Mask sensitive information * 5. Update ADRs with deployment experience * 6. Re-generate improved scripts * 7. Validate until success * * This creates a bidirectional feedback loop where ADRs evolve * based on real-world deployment experience. */ import { EnhancedLogger } from '../utils/enhanced-logging.js'; import { ResearchOrchestrator } from '../utils/research-orchestrator.js'; import { MemoryEntityManager } from '../utils/memory-entity-manager.js'; import { DynamicDeploymentPlan } from '../utils/dynamic-deployment-intelligence.js'; import { PlatformDetectionResult } from '../utils/platform-detector.js'; import { DAGExecutionResult } from '../utils/dag-executor.js'; /** * Bootstrap execution result with environment context */ export interface BootstrapExecutionResult { executionId: string; timestamp: string; success: boolean; duration: number; exitCode: number; stdout: string; stderr: string; environmentSnapshot: { docker?: any; kubernetes?: any; openshift?: any; ansible?: any; systemInfo?: any; }; validationResults?: ValidationResult[]; learnings: BootstrapLearning[]; } /** * Validation result for a specific check */ export interface ValidationResult { checkId: string; adrId: string; requirement: string; passed: boolean; actualState: string; expectedState: string; confidence: number; evidence: string[]; } /** * Learning captured from bootstrap execution */ export interface BootstrapLearning { type: 'success' | 'failure' | 'unexpected' | 'performance' | 'prerequisite'; category: 'infrastructure' | 'configuration' | 'dependency' | 'security' | 'performance'; description: string; adrReference?: string; severity: 'info' | 'warning' | 'error' | 'critical'; recommendation: string; evidence: string[]; environmentSpecific: boolean; timestamp: string; } /** * ADR update proposal based on learnings */ export interface AdrUpdateProposal { adrPath: string; adrTitle: string; updateType: 'append' | 'modify' | 'note'; sectionToUpdate: string; proposedContent: string; learnings: BootstrapLearning[]; confidence: number; requiresReview: boolean; } /** * Missing file detection result */ export interface MissingFileInfo { filePath: string; fileType: 'config' | 'env' | 'build' | 'secret' | 'dependency' | 'unknown'; isIgnored: boolean; requiredBy: string[]; severity: 'critical' | 'error' | 'warning' | 'info'; canCreateTemplate: boolean; templateContent: string | undefined; recommendation: string; } /** * Dependencies for BootstrapValidationLoop (enables DI and mocking) * Uses concrete types for full compatibility with existing implementations * @see Issue #310 - Dependency injection for improved testability */ export interface BootstrapValidationLoopDeps { logger?: EnhancedLogger; researchOrchestrator?: ResearchOrchestrator; memoryManager?: MemoryEntityManager; } /** * Bootstrap Validation Loop orchestrator * Supports dependency injection for improved testability * @see Issue #310 - Dependency injection for improved testability */ export declare class BootstrapValidationLoop { private logger; private projectPath; private adrDirectory; private researchOrchestrator; private memoryManager; private deploymentIntelligence; private executionHistory; private maxIterations; private currentIteration; private deploymentPlan; private platformDetection; private validatedPattern; private patternResearchReport; private contextManager; private dagExecutor; private patternLoader; private patternConverter; private contributionHelper; private systemCardManager; /** * Constructor with optional dependency injection * @param projectPath - Path to the project * @param adrDirectory - Path to ADR directory * @param maxIterations - Maximum validation iterations * @param deps - Optional dependencies for testing (defaults create real instances) */ constructor(projectPath: string, adrDirectory: string, maxIterations?: number, deps?: BootstrapValidationLoopDeps); /** * Initialize the validation loop */ initialize(): Promise<void>; /** * Execute the complete validation loop */ executeLoop(args: { targetEnvironment: string; autoFix: boolean; validateAfterFix: boolean; captureEnvironmentSnapshot: boolean; updateAdrsWithLearnings: boolean; }): Promise<{ success: boolean; iterations: number; finalResult: BootstrapExecutionResult; adrUpdates: AdrUpdateProposal[]; executionHistory: BootstrapExecutionResult[]; deploymentPlan?: DynamicDeploymentPlan; bootstrapAdrPath?: string; contextDocumentPath?: string; requiresHumanApproval: boolean; }>; /** * Create Bootstrap ADR with deployment plan and architecture diagrams */ private createBootstrapAdr; /** * Save bootstrap context document for future sessions */ private saveBootstrapContext; /** * Generate bootstrap scripts from validated pattern (NEW) */ private generateBootstrapScriptsFromPattern; /** * Generate bootstrap scripts from current ADRs (FALLBACK) */ private generateBootstrapScripts; /** * Execute bootstrap.sh with environment monitoring */ private executeBootstrapWithMonitoring; /** * Execute validate_bootstrap.sh and analyze results */ private executeValidationScript; /** * Extract learnings from execution results */ private extractLearnings; /** * Generate recommendation for a failed validation */ private generateRecommendation; /** * Update bootstrap scripts based on learnings */ private updateBootstrapScriptsFromLearnings; /** * Generate ADR update proposals based on learnings */ private generateAdrUpdates; /** * Generate deployment experience section content */ private generateDeploymentExperienceSection; /** * Detect missing files that might break bootstrap */ private detectMissingFiles; /** * Parse .gitignore file patterns */ private parseGitignore; /** * Check if a file path matches gitignore patterns */ private isFileIgnored; /** * Extract file references from ADR content */ private extractFileReferencesFromAdrs; /** * Analyze a missing file and provide recommendations */ private analyzeMissingFile; /** * Generate template content for missing files */ private generateTemplateContent; /** * Generate recommendation for missing file */ private generateMissingFileRecommendation; /** * Handle missing files - create templates or add to bootstrap prerequisites */ private handleMissingFiles; /** * Capture environment snapshot */ private captureEnvironmentSnapshot; /** * Store execution result in memory system */ private storeExecutionInMemory; /** * Compute SHA-256 hash of validated pattern for change detection * @param pattern - Validated pattern to hash * @returns Hex-encoded SHA-256 hash */ /** * Execute Infrastructure Layer using DAG with validated pattern * * This method: * 1. Attempts to load validated pattern from YAML * 2. If pattern exists: Auto-generates DAG tasks from pattern definition * 3. If pattern doesn't exist: Works with user to create GitHub issue * 4. Executes infrastructure DAG with parallel execution where possible */ executeInfrastructureDAG(platformDetection: PlatformDetectionResult): Promise<DAGExecutionResult>; /** * Generate fallback pattern using AI when validated pattern doesn't exist */ private generateFallbackPattern; private computePatternHash; } /** * Main tool function for bootstrap validation loop */ export declare function bootstrapValidationLoop(args: { projectPath?: string; adrDirectory?: string; targetEnvironment?: string; maxIterations?: number; autoFix?: boolean; updateAdrsWithLearnings?: boolean; currentIteration?: number; previousExecutionOutput?: string; previousExecutionSuccess?: boolean; deploymentCleanupRequested?: boolean; }): Promise<any>; export default bootstrapValidationLoop; //# sourceMappingURL=bootstrap-validation-loop-tool.d.ts.map