|
| 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 | +ShellTime CLI is a Go-based command-line tool for tracking DevOps work. It consists of two main binaries: |
| 8 | +- `shelltime`: The main CLI tool for command tracking and management |
| 9 | +- `shelltime-daemon`: A background service for asynchronous command tracking and synchronization |
| 10 | + |
| 11 | +## Development Commands |
| 12 | + |
| 13 | +### Building |
| 14 | +```bash |
| 15 | +# Build the CLI binary |
| 16 | +go build -o shelltime ./cmd/cli/main.go |
| 17 | + |
| 18 | +# Build the daemon binary |
| 19 | +go build -o shelltime-daemon ./cmd/daemon/main.go |
| 20 | + |
| 21 | +# Build with version information |
| 22 | +go build -ldflags "-X main.version=v0.1.0 -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%d)" -o shelltime ./cmd/cli/main.go |
| 23 | +``` |
| 24 | + |
| 25 | +### Testing |
| 26 | +```bash |
| 27 | +# Run all tests with coverage |
| 28 | +go test -timeout 3m -coverprofile=coverage.txt -covermode=atomic ./... |
| 29 | + |
| 30 | +# Run tests for a specific package |
| 31 | +go test ./commands/... |
| 32 | +go test ./daemon/... |
| 33 | +go test ./model/... |
| 34 | + |
| 35 | +# Run a single test |
| 36 | +go test -run TestHandlerName ./daemon/ |
| 37 | +``` |
| 38 | + |
| 39 | +### Code Generation |
| 40 | +```bash |
| 41 | +# Install mockery if not already installed |
| 42 | +go install github.com/vektra/mockery/v2@v2.42.0 |
| 43 | + |
| 44 | +# Generate mocks |
| 45 | +go generate ./... |
| 46 | +``` |
| 47 | + |
| 48 | +### Linting |
| 49 | +```bash |
| 50 | +# Run go vet |
| 51 | +go vet ./... |
| 52 | + |
| 53 | +# Format code |
| 54 | +go fmt ./... |
| 55 | +``` |
| 56 | + |
| 57 | +## Architecture |
| 58 | + |
| 59 | +### Package Structure |
| 60 | +- **cmd/**: Entry points for the binaries |
| 61 | + - `cli/`: Main CLI application entry point |
| 62 | + - `daemon/`: Daemon service entry point |
| 63 | + |
| 64 | +- **commands/**: CLI command implementations (auth, track, sync, gc, daemon management, hooks) |
| 65 | + - Each command is self-contained in its own file |
| 66 | + - `base.go` provides shared functionality across commands |
| 67 | + - Hook management for shell integrations (bash, zsh, fish) |
| 68 | + |
| 69 | +- **daemon/**: Daemon service implementation |
| 70 | + - Socket-based IPC communication with CLI |
| 71 | + - Async command processing and batch synchronization |
| 72 | + - Channel-based architecture for concurrent operations |
| 73 | + |
| 74 | +- **model/**: Core business logic and data models |
| 75 | + - API client implementations with encryption support |
| 76 | + - Database operations (local SQLite storage) |
| 77 | + - Shell-specific hook implementations |
| 78 | + - System service installers (systemd/launchctl) |
| 79 | + |
| 80 | +### Key Architectural Patterns |
| 81 | + |
| 82 | +1. **Command Pattern**: Each CLI command implements the `urfave/cli/v2` command interface |
| 83 | +2. **Service Pattern**: ConfigService interface for configuration management |
| 84 | +3. **IPC Communication**: Unix domain sockets for CLI-daemon communication |
| 85 | +4. **Batch Processing**: Commands are buffered locally and synced in batches |
| 86 | +5. **Encryption**: Hybrid RSA/AES-GCM encryption for secure command transmission |
| 87 | + |
| 88 | +### Data Flow |
| 89 | +1. Shell hooks capture commands → |
| 90 | +2. CLI stores commands locally (SQLite) → |
| 91 | +3. Daemon (if installed) processes commands asynchronously → |
| 92 | +4. Batch sync to shelltime.xyz API |
| 93 | + |
| 94 | +### Configuration |
| 95 | +- Config file location: `$HOME/.shelltime/config.toml` |
| 96 | +- Database location: `$HOME/.shelltime/shelltime.db` |
| 97 | +- Daemon socket: `/tmp/shelltime-daemon.sock` (Unix) or named pipe (Windows) |
| 98 | + |
| 99 | +## Important Notes |
| 100 | + |
| 101 | +- The daemon is optional but recommended for better performance |
| 102 | +- Encryption requires daemon mode and a special token |
| 103 | +- All local storage uses SQLite for reliability |
| 104 | +- The project uses OpenTelemetry for observability (when enabled) |
| 105 | +- Shell hooks are platform-specific and require careful testing |
0 commit comments