arela
Version:
AI-powered CTO with multi-agent orchestration, code summarization, visual testing (web + mobile) for blazing fast development.
117 lines âĸ 4.19 kB
JavaScript
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