$ show guard/listen
Listen is a Ruby gem that provides file system change detection capabilities. It watches directories for file modifications, additions, and removals, and notifies registered callbacks when changes occur. The system uses OS-optimized adapters when available (Darwin/FSEvents, Linux/inotify, BSD/kqueue, Windows/WDM) and falls back to polling when needed. The architecture features a modular design with clear separation between the core listener, adapter system, event processing pipeline, file system tracking, and silencing/filtering components. Key entry points include the Listen.to() method and the bin/listen executable.
The LLM identified 5 files worth highlighting for reuse:
A clean implementation of a Finite State Machine with state transition validation, callback support, and thread safety. The module is isolated with minimal dependencies, making it easily extractable for use in other projects needing state management.
A small but robust abstraction over different clock sources (CLOCK_MONOTONIC, CLOCK_MONOTONIC_RAW, Time.now) with automatic fallback. Provides reliable monotonic time measurement across different Ruby platforms and versions.
Thread utility that creates threads with proper exception handling and logging. Captures full backtrace including causal chains when exceptions occur, making debugging multi-threaded issues significantly easier.
Comprehensive file path filtering system with sensible defaults for ignoring common temporary and version control files. Supports flexible configuration through ignore, ignore!, and only patterns, making it reusable for any path-based filtering needs.
Sophisticated event deduplication and optimization logic that handles complex file system event patterns like editor temp files, rename operations, and related changes. Reduces noise in file system event processing while preserving meaningful change notifications.