# Task ID: 85 **Title:** Implement Hot-Reload for Stages **Status:** done **Dependencies:** 79 ✓ **Priority:** medium **Description:** Add file watching for ~/.mcpctl/stages/ to automatically reload custom stages when they change without restarting mcplocal. **Details:** Modify `src/mcplocal/src/proxymodel/stage-registry.ts`: ```typescript import { watch, FSWatcher } from 'fs'; import { join, basename } from 'path'; let watcher: FSWatcher | null = null; const stageFileHashes: Map = new Map(); export function startStageWatcher(): void { if (watcher) return; try { watcher = watch(STAGES_DIR, async (eventType, filename) => { if (!filename || (!filename.endsWith('.ts') && !filename.endsWith('.js'))) return; const name = filename.replace(/\.(ts|js)$/, ''); const fullPath = join(STAGES_DIR, filename); if (eventType === 'rename') { // File added or removed await loadCustomStages(); console.info(`[proxymodel] Stages reloaded due to ${filename} change`); } else if (eventType === 'change') { // File modified - invalidate module cache and reload delete require.cache[require.resolve(fullPath)]; try { const module = await import(fullPath + '?t=' + Date.now()); customStages.set(name, module.default); console.info(`[proxymodel] Stage '${name}' hot-reloaded`); } catch (err) { console.error(`[proxymodel] Failed to reload stage '${name}':`, err); } } }); } catch { // Directory doesn't exist - no watching needed } } export function stopStageWatcher(): void { watcher?.close(); watcher = null; } ``` Call startStageWatcher() during mcplocal initialization. **Test Strategy:** Integration tests: modify a stage file and verify the new version is loaded without restart, add a new stage file and verify it becomes available, remove a stage file and verify it's no longer available, syntax errors in stage file don't crash the watcher.