UNPKG

arela

Version:

AI-powered CTO with multi-agent orchestration, code summarization, visual testing (web + mobile) for blazing fast development.

117 lines â€ĸ 4.19 kB
import { watch } from 'chokidar'; import { existsSync } from 'fs'; export class MemoryAutoUpdater { watcher = null; updateQueue = new Map(); debounceTimer = null; isProcessing = false; start(options) { const { projectPath, ignored, debounceMs = 500 } = options; if (!existsSync(projectPath)) { throw new Error(`Project path does not exist: ${projectPath}`); } console.log('🔄 Starting memory auto-updater...'); this.watcher = watch(projectPath, { ignored: ignored || [ /(node_modules|\.git|dist|build|\.arela|\.next|\.turbo|coverage)/, /\.(log|lock|map)$/, /package-lock\.json$/, ], persistent: true, ignoreInitial: true, awaitWriteFinish: { stabilityThreshold: 100, pollInterval: 50, }, }); // Queue changes for batch processing this.watcher.on('all', (event, path) => { if (event === 'add' || event === 'change' || event === 'unlink') { this.updateQueue.set(path, event); this.scheduleUpdate(debounceMs); } }); this.watcher.on('error', (error) => { console.error('❌ File watcher error:', error); }); console.log('✅ Memory auto-updater started'); console.log(` Watching: ${projectPath}`); console.log(` Debounce: ${debounceMs}ms`); } stop() { if (this.watcher) { this.watcher.close(); this.watcher = null; console.log('âšī¸ Memory auto-updater stopped'); } if (this.debounceTimer) { clearTimeout(this.debounceTimer); this.debounceTimer = null; } } isRunning() { return this.watcher !== null; } scheduleUpdate(debounceMs) { if (this.debounceTimer) { clearTimeout(this.debounceTimer); } this.debounceTimer = setTimeout(() => { this.processQueue(); }, debounceMs); } async processQueue() { if (this.updateQueue.size === 0 || this.isProcessing) { return; } this.isProcessing = true; const updates = Array.from(this.updateQueue.entries()); this.updateQueue.clear(); const start = Date.now(); console.log(`📝 Processing ${updates.length} file change(s)...`); let successCount = 0; let errorCount = 0; for (const [path, event] of updates) { try { if (event === 'unlink') { await this.removeFile(path); } else { await this.updateFile(path); } successCount++; } catch (error) { console.error(`❌ Failed to process ${path}:`, error instanceof Error ? error.message : error); errorCount++; // Continue with other files } } const duration = Date.now() - start; console.log(`✅ Processed ${successCount} file(s) in ${duration}ms`); if (errorCount > 0) { console.log(`âš ī¸ ${errorCount} file(s) failed`); } this.isProcessing = false; } async updateFile(path) { // TODO: Integrate with actual memory systems when they exist // For now, just log the update // Future integration: // await graphMemory.updateFile(path); // await vectorMemory.reindexFile(path); // await sessionMemory?.markFileChanged(path); console.log(` ✓ Updated: ${path}`); } async removeFile(path) { // TODO: Integrate with actual memory systems when they exist // For now, just log the removal // Future integration: // await graphMemory.removeFile(path); // await vectorMemory.removeFile(path); console.log(` đŸ—‘ī¸ Removed: ${path}`); } } // Singleton instance export const memoryAutoUpdater = new MemoryAutoUpdater(); //# sourceMappingURL=auto-update.js.map