|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +`ph` (Process Hunter) is a parental control tool that monitors OS processes and terminates those that exceed specified time limits or run during downtime periods. It's designed to limit game time for children by monitoring processes and enforcing daily time budgets and blackout periods. |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +The codebase is structured into several key packages: |
| 12 | + |
| 13 | +- **`engine/`** - Core process monitoring and killing logic |
| 14 | + - `ProcessHunter` struct manages configuration, time balance tracking, and process termination |
| 15 | + - Supports day-specific time limits and downtime periods via JSON configuration |
| 16 | + - Uses goroutines with context cancellation for graceful shutdown |
| 17 | + - Checks running processes every 3 minutes (hardcoded) |
| 18 | + |
| 19 | +- **`server/`** - HTTP web interface and API |
| 20 | + - Serves static web UI at localhost:8080 |
| 21 | + - Provides REST endpoints for configuration and process balance data |
| 22 | + - Basic auth protection for PUT operations (username: "time", password: "k33p3rs") |
| 23 | + - Uses embedded files for web assets |
| 24 | + |
| 25 | +- **`cmd/cli/`** - Main CLI application entry point |
| 26 | +- **`cmd/winsvc/`** - Windows service wrapper |
| 27 | + |
| 28 | +## Development Commands |
| 29 | + |
| 30 | +### Building |
| 31 | +```bash |
| 32 | +make build # Build CLI and Windows service binaries |
| 33 | +make build_test # Build with test processes |
| 34 | +make clean # Clean build artifacts |
| 35 | +``` |
| 36 | + |
| 37 | +### Testing |
| 38 | +```bash |
| 39 | +make test # Run tests with coverage |
| 40 | +make cover # Generate HTML coverage report |
| 41 | +``` |
| 42 | + |
| 43 | +### Running |
| 44 | +```bash |
| 45 | +make run # Build and run with test processes |
| 46 | +# OR run directly: |
| 47 | +cd bin && ./ph # On Unix |
| 48 | +cd bin && ph.exe # On Windows |
| 49 | +``` |
| 50 | + |
| 51 | +For Windows service development: |
| 52 | +```bash |
| 53 | +phsvc debug # Run as CLI tool (not as service) |
| 54 | +phsvc install # Install as Windows service |
| 55 | +phsvc start # Start service |
| 56 | +phsvc stop # Stop service |
| 57 | +phsvc remove # Uninstall service |
| 58 | +``` |
| 59 | + |
| 60 | +## Configuration |
| 61 | + |
| 62 | +The application uses `cfg.json` for process limits and downtime configuration. The configuration format supports: |
| 63 | +- Process groups with shared time budgets |
| 64 | +- Day-specific limits (weekdays, dates, wildcards) |
| 65 | +- Downtime periods in HH:MM..HH:MM format |
| 66 | +- Priority-based rule matching (specific dates > day lists > individual days > wildcards) |
| 67 | + |
| 68 | +## Key Files |
| 69 | + |
| 70 | +- `engine/ph.go` - Main ProcessHunter implementation with time tracking and process killing logic |
| 71 | +- `server/server.go` - Web server with API endpoints and basic auth |
| 72 | +- `cmd/cli/main.go` - CLI entry point with graceful shutdown handling |
| 73 | +- `Makefile` - Cross-platform build system |
| 74 | +- `testdata/cfg.json` - Example configuration file |
| 75 | + |
| 76 | +## Testing Notes |
| 77 | + |
| 78 | +The project includes test processes (`test_process/`) that can be built and run to simulate monitored applications during development and testing. |
| 79 | + |
| 80 | +## Web Interface |
| 81 | + |
| 82 | +The web UI is available at http://localhost:8080 and provides: |
| 83 | +- Real-time process balance monitoring |
| 84 | +- Configuration editing (with basic auth) |
| 85 | +- Process group status display |
0 commit comments