()
| 83 | * Initialize file watching for skill directories |
| 84 | */ |
| 85 | export async function initialize(): Promise<void> { |
| 86 | if (initialized || disposed) return |
| 87 | initialized = true |
| 88 | |
| 89 | // Register callback for when dynamic skills are loaded (only once) |
| 90 | if (!dynamicSkillsCallbackRegistered) { |
| 91 | dynamicSkillsCallbackRegistered = true |
| 92 | onDynamicSkillsLoaded(() => { |
| 93 | // Clear memoization caches so new skills are picked up |
| 94 | // Note: we use clearCommandMemoizationCaches (not clearCommandsCache) |
| 95 | // because clearCommandsCache would call clearSkillCaches which |
| 96 | // wipes out the dynamic skills we just loaded |
| 97 | clearCommandMemoizationCaches() |
| 98 | // Notify listeners that skills changed |
| 99 | skillsChanged.emit() |
| 100 | }) |
| 101 | } |
| 102 | |
| 103 | const paths = await getWatchablePaths() |
| 104 | if (paths.length === 0) return |
| 105 | |
| 106 | logForDebugging( |
| 107 | `Watching for changes in skill/command directories: ${paths.join(', ')}...`, |
| 108 | ) |
| 109 | |
| 110 | watcher = chokidar.watch(paths, { |
| 111 | persistent: true, |
| 112 | ignoreInitial: true, |
| 113 | depth: 2, // Skills use skill-name/SKILL.md format |
| 114 | awaitWriteFinish: { |
| 115 | stabilityThreshold: |
| 116 | testOverrides?.stabilityThreshold ?? FILE_STABILITY_THRESHOLD_MS, |
| 117 | pollInterval: |
| 118 | testOverrides?.pollInterval ?? FILE_STABILITY_POLL_INTERVAL_MS, |
| 119 | }, |
| 120 | // Ignore special file types (sockets, FIFOs, devices) - they cannot be watched |
| 121 | // and will error with EOPNOTSUPP on macOS. Only allow regular files and directories. |
| 122 | ignored: (path, stats) => { |
| 123 | if (stats && !stats.isFile() && !stats.isDirectory()) return true |
| 124 | // Ignore .git directories |
| 125 | return path.split(platformPath.sep).some(dir => dir === '.git') |
| 126 | }, |
| 127 | ignorePermissionErrors: true, |
| 128 | usePolling: USE_POLLING, |
| 129 | interval: testOverrides?.chokidarInterval ?? POLLING_INTERVAL_MS, |
| 130 | atomic: true, |
| 131 | }) |
| 132 | |
| 133 | watcher.on('add', handleChange) |
| 134 | watcher.on('change', handleChange) |
| 135 | watcher.on('unlink', handleChange) |
| 136 | |
| 137 | // Register cleanup to properly dispose of the file watcher during graceful shutdown |
| 138 | unregisterCleanup = registerCleanup(async () => { |
| 139 | await dispose() |
| 140 | }) |
| 141 | } |
| 142 |
nothing calls this directly
no test coverage detected