Skip to main content
Glama
file-hygiene-agent.js8.24 kB
/** * FILE HYGIENE AGENT - MCP VERSION * Full agent accessible through MCP */ const FileHygieneTools = require('../tools/file-hygiene-tools'); const fs = require('fs').promises; const path = require('path'); class FileHygieneAgent { constructor() { this.name = 'FileHygieneAgent'; this.role = 'File system health monitoring and maintenance'; this.capabilities = [ 'health_check', 'continuous_monitoring', 'dependency_analysis', 'reorganization_planning', 'inventory_management', 'alert_generation' ]; this.tools = new FileHygieneTools(); this.status = 'ready'; this.monitoringActive = false; } /** * Initialize agent */ async initialize() { console.log(`[${this.name}] Initializing...`); // Check if required files exist const requiredFiles = [ 'C:/tools/folder_hygiene_agent.py', 'C:/tools/build_inventory.py', 'C:/tools/map_dependencies.py', 'C:/tools/safe_reorganize.py' ]; for (const file of requiredFiles) { try { await fs.access(file); } catch { console.error(`[${this.name}] Missing required file: ${file}`); this.status = 'error'; return false; } } this.status = 'ready'; console.log(`[${this.name}] Ready`); return true; } /** * MCP Agent Method: Perform health check */ async performHealthCheck() { console.log(`[${this.name}] Performing health check...`); try { const health = await this.tools.checkHealth(); const brokenDeps = await this.tools.getBrokenDependencies(); const inventory = await this.tools.getInventorySummary(); const report = { agent: this.name, timestamp: new Date().toISOString(), status: health.status, summary: { totalFiles: inventory.totalFiles, brokenDependencies: brokenDeps.total, categories: inventory.categories }, critical: health.status === 'CRITICAL', actions: [] }; // Add recommended actions if (brokenDeps.total > 1000) { report.actions.push('URGENT: Review and fix broken dependencies'); } if (brokenDeps.total > 0) { report.actions.push('Run safe reorganization to fix structure'); } return report; } catch (error) { console.error(`[${this.name}] Health check failed:`, error); return { agent: this.name, status: 'error', error: error.message }; } } /** * MCP Agent Method: Start monitoring */ async startMonitoring(interval = 60) { if (this.monitoringActive) { return { agent: this.name, status: 'already_running', message: 'Monitoring is already active' }; } console.log(`[${this.name}] Starting continuous monitoring...`); try { const result = await this.tools.startMonitoring(interval); this.monitoringActive = true; return { agent: this.name, status: 'monitoring_started', pid: result.pid, interval: interval, message: `Monitoring every ${interval} minutes` }; } catch (error) { return { agent: this.name, status: 'error', error: error.message }; } } /** * MCP Agent Method: Analyze reorganization */ async analyzeReorganization() { console.log(`[${this.name}] Analyzing reorganization options...`); try { const analysis = await this.tools.testReorganization(); return { agent: this.name, analysis: { safeToMove: analysis.safeToMove, riskyFiles: analysis.riskyFiles, unmovable: analysis.unmovable, recommendation: analysis.safeToMove > 100 ? 'Safe to reorganize' : 'Manual review recommended' }, timestamp: new Date().toISOString() }; } catch (error) { return { agent: this.name, status: 'error', error: error.message }; } } /** * MCP Agent Method: Rebuild system */ async rebuildSystem() { console.log(`[${this.name}] Rebuilding system inventory and dependencies...`); try { // Rebuild inventory const inventory = await this.tools.rebuildInventory(); // Remap dependencies const dependencies = await this.tools.remapDependencies(); // Run health check const health = await this.performHealthCheck(); return { agent: this.name, rebuilt: { inventory: inventory.status, dependencies: dependencies.status }, health: health, timestamp: new Date().toISOString() }; } catch (error) { return { agent: this.name, status: 'error', error: error.message }; } } /** * MCP Agent Method: Get status */ async getStatus() { return { agent: this.name, role: this.role, status: this.status, monitoringActive: this.monitoringActive, capabilities: this.capabilities, files: { inventory: 'C:/tools/agent-agency-file-inventory.json', dependencies: 'C:/tools/agent-agency-dependency-map.json', healthReport: 'C:/tools/health_report_*.json', alerts: 'C:/tools/ALERT_BROKEN_DEPENDENCIES.txt' } }; } /** * MCP Agent Method: Execute command */ async execute(command, params = {}) { console.log(`[${this.name}] Executing: ${command}`); switch(command) { case 'health_check': return await this.performHealthCheck(); case 'start_monitoring': return await this.startMonitoring(params.interval || 60); case 'analyze_reorganization': return await this.analyzeReorganization(); case 'rebuild_system': return await this.rebuildSystem(); case 'get_broken_dependencies': return await this.tools.getBrokenDependencies(); case 'get_inventory_summary': return await this.tools.getInventorySummary(); case 'status': return await this.getStatus(); default: return { agent: this.name, error: `Unknown command: ${command}`, availableCommands: [ 'health_check', 'start_monitoring', 'analyze_reorganization', 'rebuild_system', 'get_broken_dependencies', 'get_inventory_summary', 'status' ] }; } } } // Export for MCP module.exports = FileHygieneAgent;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bermingham85/mcp-puppet-pipeline'

If you have feedback or need assistance with the MCP directory API, please join our Discord server