Class SkillWatcher
Monitors skill directories for changes and automatically reloads modified skills.
Provides hot-reload functionality for development scenarios where skills are frequently edited and should be reloaded without restarting the application.
public sealed class SkillWatcher : IDisposable
- Inheritance
-
SkillWatcher
- Implements
- Inherited Members
Examples
Basic usage:
var registry = new SkillRegistry();
registry.LoadFromDirectory("./skills");
using (var watcher = new SkillWatcher(registry, "./skills"))
{
watcher.SkillReloaded += (s, e) =>
Console.WriteLine($"Reloaded: {e.Skill.Name}");
watcher.Start();
// Skills are now automatically reloaded when modified
Console.ReadLine();
}
Remarks
Monitored Events
- SKILL.md file changes trigger skill reload
- New skill directories are automatically registered
- Deleted skill directories are automatically unregistered
- Resource file changes trigger skill reload
Debouncing
File system events are debounced to avoid multiple reloads when a file is saved
(which can trigger multiple events). Default debounce delay is 500ms.
Thread Safety
This class is thread-safe. Events are raised on a background thread.
Constructors
- SkillWatcher(SkillRegistry, IEnumerable<string>, TimeSpan?)
Initializes a new instance of the SkillWatcher class.
- SkillWatcher(SkillRegistry, string, TimeSpan?)
Initializes a new instance of the SkillWatcher class for a single directory.
Fields
- DefaultDebounceDelay
Gets the default debounce delay (500ms).
Properties
- IsRunning
Gets whether the watcher is currently monitoring for changes.
- WatchedDirectories
Gets the directories being watched.
Methods
- ReloadSkill(string)
Manually triggers a reload of a specific skill.
- Start()
Starts monitoring for file changes.
- Stop()
Stops monitoring for file changes.
Events
- Error
Occurs when an error happens during reload.
- SkillDiscovered
Occurs when a new skill is discovered and added.
- SkillReloaded
Occurs when a skill is reloaded due to file changes.
- SkillRemoved
Occurs when a skill directory is deleted and the skill is removed.