UNPKG

github-mcp-auto-git

Version:

GitHub MCP Auto Git v3.0 - メモリ効率化・統合MCP・モジュール化完了の完全自動Git操作システム

244 lines 9.32 kB
/** * GitAutoMCP Core Class - Refactored for Modularity * Main orchestration class following Constitutional AI principles */ import { GitOperations } from './git-operations.js'; import { FileWatchManager } from './file-watch-manager.js'; import { InteractiveConfigManager } from './interactive-config-manager.js'; import { SystemStatusManager } from './system-status-manager.js'; import { SubAgentManager } from './subagent-manager.js'; export class GitAutoMCP { constructor(configPath) { this.config = {}; // Temporary initialization this.configPath = configPath; } /** * Initialize the GitAutoMCP system * Fail Fast: Comprehensive validation and early error detection * Be Lazy: Efficient module initialization with dependency injection * TypeScript First: Complete type safety throughout initialization */ async initialize() { console.log('🚀 GitHub MCP Auto Git System を初期化しています...'); try { // Load configuration this.config = await this.loadConfig(this.configPath); // Initialize core components this.gitOps = new GitOperations(this.config); await this.gitOps.initialize(); // Initialize managers this.fileWatchManager = new FileWatchManager(this.config, this.gitOps); this.configManager = new InteractiveConfigManager(this.config); this.statusManager = new SystemStatusManager(this.config); this.subAgentManager = new SubAgentManager('./src/agents', process.cwd()); // Validate GitHub token if (!this.config.github.token) { console.warn('⚠️ GITHUB_TOKEN が設定されていません。PR機能は無効になります。'); } // Start health monitoring this.statusManager.startHealthMonitoring(); // Setup PID file management const pidManager = await this.statusManager.managePIDFile(); await pidManager.create(); console.log('✅ 初期化完了'); console.log('📁 監視パターン:', this.config.paths.join(', ')); console.log('🤖 有効なサブエージェント:', this.getEnabledAgents().join(', ')); } catch (error) { console.error('❌ 初期化に失敗しました:', error); throw new Error(`Initialization failed: ${error}`); } } /** * Start file watching with interactive configuration * Be Lazy: Reuse existing configuration when possible */ async startWatching() { if (!this.config.enabled) { throw new Error('System is disabled in configuration'); } try { // Interactive watch pattern configuration const configResult = await this.configManager.configureWatchPatterns(); if (configResult.success && configResult.config) { this.config = configResult.config; // Reinitialize file watch manager with new config this.fileWatchManager = new FileWatchManager(this.config, this.gitOps); } // Start file watching await this.fileWatchManager.startWatching(); // Start health monitoring this.statusManager.startHealthMonitoring(); } catch (error) { console.error('❌ ファイル監視の開始に失敗しました:', error); throw error; } } /** * Process changes manually (one-time execution) * TypeScript First: Strongly typed change processing */ async runOnce(files) { await this.ensureInitialized(); const startTime = Date.now(); const result = await this.fileWatchManager.processChanges(files); const processingTime = Date.now() - startTime; // Record metrics this.statusManager.recordProcessingMetrics(result.success, processingTime, files?.length || 1); return result; } /** * Stop all operations and cleanup * Fail Fast: Comprehensive cleanup with error handling */ async stop() { try { // Stop file watching if (this.fileWatchManager) { await this.fileWatchManager.stopWatching(); } // Cleanup Git operations and MCP resources if (this.gitOps) { await this.gitOps.cleanup(); } // Cleanup SubAgent Manager and memory executor if (this.subAgentManager) { await this.subAgentManager.cleanup(); } // Stop health monitoring if (this.statusManager) { this.statusManager.stopHealthMonitoring(); // Remove PID file const pidManager = await this.statusManager.managePIDFile(); await pidManager.remove(); } console.log('✅ システムを正常に停止しました'); } catch (error) { console.error('⚠️ 停止処理中にエラーが発生しました:', error); throw error; } } /** * Get comprehensive system status * Be Lazy: Cached status with efficient updates */ async getStatus() { await this.ensureInitialized(); return await this.statusManager.getSystemStatus(); } /** * Configure system interactively * TypeScript First: Complete configuration type safety */ async configureInteractively() { await this.ensureInitialized(); try { // Configure subagents const subagentResult = await this.configManager.configureSubagents(); if (!subagentResult.success) { return subagentResult; } // Configure notifications const notificationResult = await this.configManager.configureNotifications(); if (!notificationResult.success) { return notificationResult; } // Update configuration if (subagentResult.config) { this.config = subagentResult.config; } console.log('✅ 対話的設定が完了しました'); return { success: true, config: this.config }; } catch (error) { console.error('❌ 対話的設定に失敗しました:', error); return { success: false, message: `Interactive configuration failed: ${error}` }; } } /** * Display system health report * Be Lazy: Efficient health reporting with visual formatting */ async displayHealthReport() { const status = await this.getStatus(); this.statusManager.displaySystemStatus(status.health); } /** * Load configuration with defaults and validation * Fail Fast: Immediate configuration validation */ async loadConfig(configPath) { const defaultConfig = { enabled: true, triggers: ['save', 'auto'], paths: ['src/**/*', '!node_modules/**'], subAgents: { gitSafetyAnalyzer: { enabled: true, safetyThreshold: 0.85 }, commitMessageGenerator: { enabled: true, language: 'ja', style: 'friendly' }, prManagementAgent: { enabled: true, autoMergeThreshold: 0.85 } }, notifications: { success: true, warnings: true, detailed: false }, github: { owner: process.env.GITHUB_OWNER || '', repo: process.env.GITHUB_REPO || '', token: process.env.GITHUB_TOKEN || '' } }; if (configPath) { try { const { default: userConfig } = await import(configPath); return { ...defaultConfig, ...userConfig }; } catch (error) { console.warn(`設定ファイルの読み込みに失敗しました: ${error}`); } } return defaultConfig; } /** * Get list of enabled agents * TypeScript First: Type-safe agent enumeration */ getEnabledAgents() { const agents = []; if (this.config.subAgents.gitSafetyAnalyzer.enabled) agents.push('Git Safety Analyzer'); if (this.config.subAgents.commitMessageGenerator.enabled) agents.push('Commit Message Generator'); if (this.config.subAgents.prManagementAgent.enabled) agents.push('PR Management Agent'); return agents; } /** * Ensure system is properly initialized * Fail Fast: Prevent operations on uninitialized system */ async ensureInitialized() { if (!this.gitOps || !this.fileWatchManager || !this.statusManager) { await this.initialize(); } } } //# sourceMappingURL=git-auto-mcp.js.map