vibewatch 0.5.0

A file watcher utility with glob pattern support
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# VibeWatch

[![CI](https://github.com/rodrigogs/vibewatch/actions/workflows/ci.yml/badge.svg)](https://github.com/rodrigogs/vibewatch/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/rodrigogs/vibewatch/branch/master/graph/badge.svg)](https://codecov.io/gh/rodrigogs/vibewatch)
[![Crates.io](https://img.shields.io/crates/v/vibewatch.svg)](https://crates.io/crates/vibewatch)
[![Downloads](https://img.shields.io/crates/d/vibewatch.svg)](https://crates.io/crates/vibewatch)
[![License](https://img.shields.io/badge/license-BSD--3--Clause-blue.svg)](LICENSE)
[![Rust Version](https://img.shields.io/badge/rust-1.89.0+-orange.svg)](https://www.rust-lang.org)

A fast and extensible file watcher utility built in Rust with glob pattern support and cross-platform compatibility.

## Features

- **Custom command execution**: Run commands on file changes with event-specific triggers (`--on-create`, `--on-modify`, `--on-delete`, `--on-change`)
- **Template substitution**: Use `{file_path}`, `{relative_path}`, `{absolute_path}`, `{event_type}` in commands
- **Structured logging**: Objective, timestamp-based logs with exit codes for monitoring and automation
- **Cross-platform file watching**: Fully tested on Linux, macOS, and Windows with platform-specific event handling
- **Glob pattern support**: Include and exclude files using glob patterns like `*.rs`, `node_modules/**`
- **Extensible architecture**: Clean separation of concerns for easy feature additions
- **Fast performance**: Built in Rust for minimal resource usage
- **Flexible CLI**: Intuitive command-line interface with verbose logging and quiet mode
- **Comprehensive testing**: 90.95% code coverage with 187 tests covering unit, filesystem, and integration scenarios

## Installation

### From crates.io (Recommended)

```bash
cargo install vibewatch
```

### From Binary Releases (Recommended for Production)

Download pre-built binaries from the [latest release](https://github.com/rodrigogs/vibewatch/releases/latest).

**Available platforms:**
- **Linux**: x86_64, ARM64 (`.tar.gz`)
- **macOS**: Intel (x86_64), Apple Silicon (ARM64) (`.tar.gz`)
- **Windows**: x64 (`.zip`)

```bash
# Example: Linux x86_64
wget https://github.com/rodrigogs/vibewatch/releases/latest/download/vibewatch-x86_64-unknown-linux-gnu.tar.gz
tar -xzf vibewatch-x86_64-unknown-linux-gnu.tar.gz
sudo mv vibewatch /usr/local/bin/

# Example: macOS ARM (Apple Silicon)
wget https://github.com/rodrigogs/vibewatch/releases/latest/download/vibewatch-aarch64-apple-darwin.tar.gz
tar -xzf vibewatch-aarch64-apple-darwin.tar.gz
sudo mv vibewatch /usr/local/bin/
```

### From Source

Make sure you have Rust installed via `mise` or `rustup`:

```bash
# Clone and build
git clone https://github.com/rodrigogs/vibewatch.git
cd vibewatch
cargo build --release
```

## ⚡ Performance

vibewatch includes significant performance optimizations:

- **40-60% fewer memory allocations** through static strings and optimized path handling
- **15-30% faster event processing** via async channels (tokio)
- **80-95% fewer redundant commands** with intelligent event debouncing
- **Proper shell parsing** with quote support via shell-words crate
- **Fast binary builds** - Reliable cross-platform compilation (~4 minutes for 5 platforms)

### Benchmarks

Run comprehensive benchmarks yourself:

```bash
cargo bench                               # All benchmarks
cargo bench --bench template_substitution # Specific suite
```

The benchmark suite includes:
- **Template substitution** - Single-pass vs multi-pass string operations
- **Path normalization** - Platform-specific optimization validation  
- **Pattern matching** - Glob compilation and matching performance

## Usage

### Command Execution on File Changes

The primary use case is executing commands when files change:

```bash
# Run tests on any change
vibewatch . --on-change "npm test"

# Format Rust files when modified
vibewatch src --include "*.rs" --on-modify "rustfmt {file_path}"

# Run linter on TypeScript files (using brace expansion)
vibewatch . --include "*.{ts,tsx}" --exclude "node_modules/**" --on-modify "npx eslint {file_path} --fix"

# Different commands for different events
vibewatch src \
  --on-create "git add {file_path}" \
  --on-modify "cargo check" \
  --on-delete "echo Removed: {relative_path}"
```

**Available Templates:**
- `{file_path}` - Full path to the changed file
- `{relative_path}` - Path relative to watched directory
- `{absolute_path}` - Absolute path to the changed file
- `{event_type}` - Type of event (create, modify, delete)

**Brace Expansion:** You can use brace expansion syntax for convenience with both `--include` and `--exclude` patterns:
```bash
# Include patterns - these are equivalent:
vibewatch . --include "*.{ts,tsx}"
vibewatch . --include "*.ts" --include "*.tsx"

# Works with multiple extensions:
vibewatch . --include "*.{js,jsx,ts,tsx}"

# Works with paths:
vibewatch . --include "src/**/*.{rs,toml}"

# Exclude patterns - these are equivalent:
vibewatch . --exclude "{target,dist,node_modules}/**"
vibewatch . --exclude "target/**" --exclude "dist/**" --exclude "node_modules/**"

# Combined include and exclude with brace expansion:
vibewatch . --include "src/**/*.{rs,toml}" --exclude "{target,build}/**"
```

### Watch-Only Mode

Watch a directory and log all file changes (no commands):

```bash
vibewatch /path/to/directory
```

### Include Patterns

Watch only specific file types:

```bash
vibewatch /path/to/directory --include "*.rs" --include "*.ts"
```

### Exclude Patterns

Ignore common directories and files:

```bash
vibewatch /path/to/directory --exclude "node_modules/**" --exclude ".git/**" --exclude "target/**"
```

### Combined Patterns

Use both include and exclude patterns:

```bash
vibewatch . \
  --include "*.rs" \
  --include "*.ts" \
  --include "*.tsx" \
  --exclude "target/**" \
  --exclude "node_modules/**" \
  --verbose
```

### Options

**Directory:**
- `<DIRECTORY>`: Directory to watch (can be relative or absolute)

**Command Execution:**
- `--on-create <COMMAND>`: Run command when files are created
- `--on-modify <COMMAND>`: Run command when files are modified
- `--on-delete <COMMAND>`: Run command when files are deleted
- `--on-change <COMMAND>`: Run command on any file change (fallback)

**Filtering:**
- `-i, --include <PATTERN>`: Include patterns like `*.ts`, `*.rs` (use multiple times for multiple patterns)
- `-e, --exclude <PATTERN>`: Exclude patterns like `node_modules/**`, `.git/**`, `.next/**`

**General:**
- `-v, --verbose`: Enable verbose output with debug logging
- `-q, --quiet`: Suppress command output (only show file events and status)
- `-h, --help`: Show help message
- `-V, --version`: Show version information

### Structured Logging (v0.4.0+)

vibewatch provides objective, timestamp-based logs for monitoring and automation:

**File Events:**
```
[2025-10-06T14:23:15] [CREATED] src/main.rs
[2025-10-06T14:23:16] [MODIFIED] src/watcher.rs
[2025-10-06T14:23:17] [DELETED] tmp/test.txt
```

**Command Execution:**
```
[2025-10-06T14:23:15] Executing command: cargo build
<command output appears here>
[2025-10-06T14:23:18] Command succeeded (exit code: 0)
```

**Command Failure:**
```
[2025-10-06T14:23:19] Executing command: cargo check
<error output appears here>
[2025-10-06T14:23:20] Command failed (exit code: 1)
```

**Features:**
- ISO 8601 timestamps for sortable, parseable logs
- Uppercase event types (CREATED, MODIFIED, DELETED, CHANGED)
- Exit codes shown for all command executions
- Grep-friendly format (all lines start with `[YYYY-MM-DD`)
- Use `--quiet` to suppress command output, keeping only events and status

## Examples

### Auto-format TypeScript on save

```bash
vibewatch src \
  --include "*.{ts,tsx}" \
  --exclude "node_modules/**" --exclude "dist/**" \
  --on-modify "npx prettier --write {file_path}"
```

### Run Rust tests on file changes

```bash
vibewatch . \
  --include "*.rs" --include "Cargo.toml" \
  --exclude "target/**" \
  --on-change "cargo test"
```

### Rebuild documentation on changes

```bash
vibewatch docs \
  --include "*.md" --include "*.rst" \
  --exclude "_build/**" \
  --on-change "mdbook build"
```

### Watch and restart development server

```bash
vibewatch src \
  --include "*.js" --include "*.json" \
  --exclude "node_modules/**" \
  --on-change "pkill -f 'node server.js' && node server.js &"
```

### Auto-commit on file creation

```bash
vibewatch src \
  --on-create "git add {file_path} && git commit -m 'Add {relative_path}'"
```

## Architecture

The application is structured for extensibility:

- **`main.rs`**: CLI argument parsing and application entry point
- **`watcher.rs`**: Core file watching logic using the `notify` crate
- **`filter.rs`**: Glob pattern matching for include/exclude functionality

## Common Glob Patterns

### Exclude Patterns
- `node_modules/**` - Node.js dependencies
- `.git/**` - Git repository files
- `.next/**` - Next.js build files
- `target/**` - Rust build directory
- `dist/**` - Build output directory
- `{target,dist,build}/**` - Multiple build directories (brace expansion)
- `*.tmp` - Temporary files
- `*.swp` - Vim swap files
- `*.{tmp,swp,bak}` - Multiple temporary file types (brace expansion)

### Include Patterns
- `*.rs` - Rust source files
- `*.{ts,tsx}` - TypeScript files (brace expansion supported)
- `*.{js,jsx}` - JavaScript files (brace expansion supported)
- `*.py` - Python files
- `*.go` - Go files
- `*.{cpp,c,h}` - C/C++ files (brace expansion supported)
- `*.md` - Markdown files

**Note:** Brace expansion like `*.{ext1,ext2}` or `{dir1,dir2}/**` works with both `--include` and `--exclude` patterns. The syntax is automatically expanded to multiple patterns before glob compilation. You can also use multiple flags if you prefer explicit patterns.

## Future Enhancements

The following features are planned for future releases:

- **Configuration file support**: Store watch patterns and commands in `.vibewatch.toml`
- **Ignore file support**: Respect `.gitignore`, `.watchignore` patterns

## Requirements

- Rust 1.70+ (managed via `mise`)
- Unix-like system (macOS, Linux) or Windows

## Development

### Quick Start with Just

The project uses [`just`](https://github.com/casey/just) for task automation:

```bash
# Install just (if not already installed)
cargo install just
# or: brew install just

# List all available tasks
just --list

# Common tasks
just test              # Run all tests
just coverage          # Generate coverage report
just lint              # Run linter
just check             # Run all checks (fmt, lint, test)
just demo              # Run vibewatch on src/ directory
```

### Running Tests

```bash
# Run all tests (187 total: 140 unit + 21 filesystem + 26 integration)
cargo test
# or: just test

# Run tests with output
cargo test -- --nocapture
# or: just test-verbose

# Run specific test suite
cargo test --test it  # Integration tests only
# or: just test-integration test_name
```

### Code Coverage

The project maintains **90.95% code coverage** (1096/1205 lines):

```bash
# Generate coverage report
cargo llvm-cov --all-features --workspace --html

# View report
open target/llvm-cov/html/index.html
```

**Coverage by file:**
- `filter.rs`: 100.00% (177/177) ✅
- `main.rs`: 97.67% (252/258) ✅
- `watcher.rs`: 86.62% (667/770) ✅

> **Note:** The watcher.rs coverage is lower due to command execution happening in spawned async tasks that are harder to test in unit tests. All command execution logic is thoroughly tested through our comprehensive integration test suite.

### Development Commands

```bash
# Run with debug logging
RUST_LOG=debug cargo run -- /path/to/directory --verbose

# Build for release
cargo build --release

# Run linter
cargo clippy

# Format code
cargo fmt
```

## Contributing

### Commit Message Convention

This project uses [Conventional Commits](https://www.conventionalcommits.org/) for automated versioning and changelog generation.

**Format**: `<type>(<optional scope>): <description>`

**Types:**
- `feat:` - New feature (triggers minor version bump)
- `fix:` - Bug fix (triggers patch version bump)
- `docs:` - Documentation changes
- `chore:` - Maintenance tasks
- `refactor:` - Code refactoring
- `test:` - Adding or updating tests
- `feat!:` or `fix!:` - Breaking changes (triggers major version bump)

**Examples:**
```bash
feat: add support for symlink watching
fix: resolve race condition in file detection
docs: update README with new examples
feat!: change CLI argument structure (breaking change)
```

### Release Process

Releases are fully automated via [Release Please](https://github.com/googleapis/release-please):

1. **Commit using conventional commits** - Each commit to `master` is analyzed
2. **Release PR is created** - Release Please opens a PR with updated version and CHANGELOG
3. **Merge the Release PR** - This triggers:
   - GitHub Release creation with release notes
   - **Binary builds for 5 platforms** (parallel execution, ~4 minutes):
     * Linux x86_64 and ARM64
     * macOS Intel and Apple Silicon
     * Windows x64
   - Publish to crates.io (requires `CARGO_TOKEN` secret)

**Current version**: v0.4.0 (October 2025)

**Binary build tool**: Uses `taiki-e/upload-rust-binary-action` for reliable cross-compilation
- Automatic cross-compilation for Linux ARM64
- No timeout issues (resolved in v0.3.0)
- Battle-tested by tokio-console and cargo-hack

### CI/CD

**Branch Protection**: Enabled on `master` with 6 required status checks

All PRs and pushes to `master` run:
- ✅ Tests (187 tests on Linux, macOS, Windows)
- ✅ Formatting check (`cargo fmt --check`)
- ✅ Linting (`cargo clippy -D warnings`)
- ✅ Coverage report (uploaded to Codecov)

**On release** (after merging Release PR):
- ✅ Build binaries for 5 platforms (parallel)
- ✅ Create GitHub Release with all binaries
- ✅ Publish to crates.io

**Release Process**:
- Uses Release Please with Personal Access Token (`RELEASE_PLEASE_TOKEN`)
- PAT required to trigger CI workflows on Release Please PRs
- Ensures all tests pass before releases are created

See [`docs/CI_CD.md`](docs/CI_CD.md) for complete CI/CD architecture documentation.

## Documentation

For comprehensive technical documentation:
- **CI/CD Architecture**: [`docs/CI_CD.md`]docs/CI_CD.md - Complete CI/CD pipeline, release process, branch protection (v2.0)
- **Testing Guide**: [`docs/TESTING.md`]docs/TESTING.md - Test organization, best practices, and quick reference
- **Coverage Analysis**: [`docs/COVERAGE.md`]docs/COVERAGE.md - Detailed coverage metrics and industry benchmarks
- **Integration Tests**: [`docs/INTEGRATION_TEST.md`]docs/INTEGRATION_TEST.md - Testing research, rationale, and best practices
- **Justfile Guide**: [`docs/JUSTFILE_IMPLEMENTATION.md`]docs/JUSTFILE_IMPLEMENTATION.md - Task runner implementation and benefits