watch
Command
The watch
command is the core monitoring functionality of kasl. It tracks user activity to automatically detect work sessions, breaks, and workday boundaries. The command can run in background daemon mode for daily use or in foreground mode for debugging and development.
Usage
kasl watch [OPTIONS]
Options
-
--foreground
: Run the watcher in the foreground for debugging- Provides real-time feedback about detected activity
- Shows pause events and workday state changes
- Useful for testing configuration changes and troubleshooting
-
--stop
,-s
: Stop any running background watcher process- Terminates the background daemon if it's currently running
- Safely closes database connections and cleans up system resources
- Useful before system shutdown or when restarting with new configuration
Operating Modes
Background Daemon Mode (Default)
kasl watch
Runs silently in the background, perfect for daily use:
- Automatically starts monitoring when you begin working
- Detects work vs. break periods based on configurable thresholds
- Records workday start/end times and pause periods
- Maintains activity state across application restarts
Foreground Debug Mode
kasl watch --foreground
Runs in the terminal with detailed logging:
- Real-time activity detection feedback
- Pause event notifications
- Workday state change logging
- Configuration testing and validation
Stop Mode
kasl watch --stop
Terminates background monitoring:
- Stops any running daemon process
- Properly closes database connections
- Cleans up system resources
How It Works
Activity Detection
The monitor tracks these input events:
- Keyboard presses and releases
- Mouse button clicks
- Mouse movement
- Mouse wheel scrolling
Work Session Detection
- Input Detection: Monitors keyboard and mouse activity using system APIs
- Activity Analysis: Determines work vs. break periods based on configurable thresholds
- Database Recording: Automatically records workday start/end times and pause periods
- State Management: Maintains activity state across application restarts
Configuration Settings
The monitor behavior is controlled by configuration settings:
pause_threshold
: Seconds of inactivity before recording a pausepoll_interval
: Milliseconds between activity checksactivity_threshold
: Seconds of activity needed to start a workdaymin_pause_duration
: Minimum pause length to record (filters noise)
Examples
Daily Usage
# Start background monitoring (recommended for daily use)
kasl watch
# Check if monitoring is running
ps aux | grep kasl
Debugging and Development
# Run in foreground to see activity detection in real-time
kasl watch --foreground
# Test configuration changes
kasl watch --foreground
# Press Ctrl+C to stop
System Management
# Stop monitoring before system shutdown
kasl watch --stop
# Restart with new configuration
kasl watch --stop
kasl watch
Database Operations
During monitoring, the system automatically:
- Creates workday records when sustained activity is detected
- Records pause start times when inactivity threshold is exceeded
- Records pause end times when activity resumes
- Updates workday end times when monitoring stops
Signal Handling
The daemon process responds to these signals:
- SIGTERM: Graceful shutdown (Unix)
- SIGINT: Interrupt signal (Unix)
- Ctrl+C: Console interrupt (Windows)
Troubleshooting
Common Issues
Daemon already running
# Check if daemon is running
ps aux | grep kasl
# Stop existing daemon
kasl watch --stop
# Start new daemon
kasl watch
Permission issues
# Run with elevated permissions if needed
sudo kasl watch --foreground
Configuration errors
# Test configuration in foreground mode
kasl watch --foreground
Debug Mode
Enable debug logging for troubleshooting:
RUST_LOG=kasl=debug kasl watch --foreground
Process Management
# Check daemon status
ps aux | grep kasl
# View daemon logs (if configured)
tail -f ~/.local/share/lacodda/kasl/kasl.log
# Force stop daemon (if needed)
pkill -f kasl
Integration with Other Commands
The watch
command works with other kasl commands:
task
: Create and manage tasks while monitoringreport
: Generate reports based on monitored dataadjust
: Manually adjust times recorded by monitoringpauses
: View recorded breaks and pauses
Best Practices
Daily Workflow
- Start monitoring at the beginning of your workday
- Let it run in the background during work
- Stop monitoring before system shutdown
- Review data using
report
andpauses
commands
Configuration
- Adjust thresholds based on your work patterns
- Test settings using foreground mode
- Monitor performance and adjust as needed
- Backup configuration regularly
Troubleshooting
- Use foreground mode for debugging
- Check system permissions for input device access
- Verify database connectivity
- Review logs for error messages