|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Build & Test |
| 4 | + |
| 5 | +- **Build:** `go build -o drift ./cmd/drift` |
| 6 | +- **Test:** `go test ./...` or `go test ./compare -run TestName` |
| 7 | +- **Vet:** `go vet ./...` |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +`drift` is a two-layer tool: a comparison engine and an interactive TUI. |
| 12 | + |
| 13 | +### Compare engine (`compare/`) |
| 14 | + |
| 15 | +Pure-Go diffing logic. `Compare(pathA, pathB, mode)` returns a `*Result` with a tree of `Node`s representing the comparison. `Detail(result, node)` produces the detailed diff for a single node. |
| 16 | + |
| 17 | +Supported modes: tree (directories/archives), binary (Mach-O), plist, text. Mode is auto-detected from inputs. |
| 18 | + |
| 19 | +Key files: |
| 20 | +- `compare.go` - entry point, mode detection, tree comparison |
| 21 | +- `directory.go` - directory walking and tree building |
| 22 | +- `archive.go` - archive extraction (zip, tar, tar.gz, tar.bz2) |
| 23 | +- `binary.go` - Mach-O analysis via nm/size/otool |
| 24 | +- `plist.go` - plist conversion via plutil |
| 25 | +- `text.go` - line-by-line unified diff |
| 26 | +- `types.go` - `Result`, `Node`, `DetailResult` types |
| 27 | +- `hash.go` - content hashing for change detection |
| 28 | + |
| 29 | +### TUI (`tui/`) |
| 30 | + |
| 31 | +Bubbletea-based interactive terminal UI. Three-tier component model: |
| 32 | + |
| 33 | +1. **App** (`app.go`) - root model, layout, keyboard dispatch |
| 34 | +2. **Components** (`tree.go`, `detail.go`, `search.go`, `overlay.go`, `alert.go`) - stateful sub-models |
| 35 | +3. **Views** (`view_*.go`, `summary.go`, `render.go`) - pure render functions, no state |
| 36 | + |
| 37 | +- `styles.go` - all lipgloss styles |
| 38 | +- `help.go` - keybinding definitions |
| 39 | +- `components.go` - detail content builder |
| 40 | + |
| 41 | +### Entry point |
| 42 | + |
| 43 | +- `cmd/drift/main.go` - CLI struct, kong parser, `run()` method |
| 44 | + |
| 45 | +## Code style |
| 46 | + |
| 47 | +- Views are pure functions: `func renderX(width int, data T) string` |
| 48 | +- Components own state and implement `Update`/`View` |
| 49 | +- Use lipgloss for all styling - no raw ANSI |
0 commit comments