// engine/drift-watcher/file-watcher.ts — SPEC-388: FSEvents wrapper using node:fs watch
import { watch } from 'node:fs';
/**
 * Watch a directory recursively for file changes.
 * Calls onChange with the relative filename whenever a file changes.
 * Silently skips directories that don't exist or can't be watched.
 * Closes the watcher when the provided AbortSignal is aborted.
 */
export function watchDirectory(dirPath, onChange, signal) {
    try {
        const watcher = watch(dirPath, { recursive: true }, (_event, filename) => {
            if (filename) {
                onChange(filename);
            }
        });
        signal.addEventListener('abort', () => {
            watcher.close();
        }, { once: true });
    }
    catch {
        // Directory doesn't exist or not watchable — silently skip
    }
}
//# sourceMappingURL=file-watcher.js.map