Commit 919ce97
committed
feat: Enhanced CLI Watcher with automatic terminal process monitoring
CLI Watcher now automatically detects and tracks terminal-based development
activity, distinguishing between interactive CLIs (vim, REPLs) and work
processes (builds, deploys) without manual configuration.
Key Features:
- Fully automatic: Only requires 'enabled: true' - auto-detects ALL terminal processes
- Smart defaults: Adapts activityWindow and gracePeriod to workspace idle timeout
- Automatic classification: Interactive (vim, python REPL) vs work (builds, deploys)
- Backward compatible: Old configs continue working with deprecation warnings
- Safety mechanisms: Grace period (5min), max age limit (6h), activity monitoring
- Flexible duration parsing: Accepts 6h, 25m, 60 (seconds), or duration strings
Configuration:
- Minimal: enabled: true (that's it!)
- Smart defaults: Auto-calculated from workspace idle timeout
- Time settings: checkPeriod, activityWindow, gracePeriod, maxProcessAge
- Override options: watchedCommands (fix misclassification), ignoredCommands (skip entirely)
Technical Implementation:
- User process filtering: Parent TTY chain analysis (filters shells, system processes)
- Interactive detection: Foreground process group + TTY read analysis
- Activity tracking: TTY access time (Atime) monitoring for user input
- Multicall binary support: Uses /proc/comm for proper command detection
- Self-skip: che-machine-exec doesn't watch itself
- Config validation: Warns about misconfigurations without breaking
- Platform portability: Detects clock ticks from /proc/self/auxv with platform-specific fallbacks
- Performance: Boot time and clock ticks cached at startup (not per process)
- Robustness: Infinite loop protection, cycle detection, error checking on all parsing
Code Quality Improvements:
- Added comprehensive unit tests (79 test cases covering pure functions and concurrency)
- Tests cover: duration parsing, YAML unmarshaling, defaults, validation, platform detection, applyPolicy, race conditions
- Merged duplicate policy logic into single unified function
- Added error checking to all fmt.Sscanf calls for consistency
- Fixed comment-code mismatches for clarity
- Warning on breaking changes (globally-excluded commands)
Test Coverage:
- Added concurrent Start/Stop tests (catches race conditions)
- Added clock skew tests (documents negative age handling)
- Enhanced /proc parsing integration tests
- All 79 tests pass with -race flag
- No data races detected
All issues verified with test-driven approach: wrote tests first to
detect bugs, then fixed implementation. Thread-safety verified with
Go race detector (-race flag).
Documentation:
- timeout/CLI-WATCHER.md - Comprehensive guide with testing scenarios
- timeout/.noidle.minimal - Minimal config example
- timeout/.noidle.example - Full config with all options
- Added auto-detection test scenario for manual testing
- Added comprehensive upgrade guide for breaking behavioral changes
- Developer testing section added
Issue: https://redhat.atlassian.net/browse/CRW-11505
Assisted-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>1 parent d54935d commit 919ce97
8 files changed
Lines changed: 2549 additions & 61 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments