$ show tw93/Mole
Mole is a macOS system maintenance CLI tool that provides a unified interface for cleaning caches, uninstalling applications, analyzing disk usage, monitoring system health, and optimizing performance. It combines two Go binaries (cmd/analyze for disk exploration with a Bubble Tea TUI, cmd/status for real-time system metrics) with an extensive shell script library for orchestration and system-level operations. The `mo` command dispatches to subcommands like `clean`, `uninstall`, `analyze`, `status`, `optimize`, `purge`, and `installer`. The architecture is hybrid: Go handles performance-critical tasks (concurrent directory scanning with semaphore-based concurrency, hardlink deduplication, gob-based caching, and interactive TUI rendering) while Bash scripts manage cleanup logic, safety guards (path identity snapshots, whitelists, process guards), Homebrew integration, and sudo session management. Key data flows include disk scanning with progress events and cache invalidation, system metrics collection via gopsutil and macOS commands (system_profiler, ioreg, pmset), and cleanup operations with dry-run previews and bounded timeouts. External dependencies include Homebrew (for cask detection and uninstall), macOS system commands (tmutil, plutil, diskutil, osascript), and Go modules (charmbracelet/bubbletea, lipgloss, gopsutil). The codebase emphasizes safety with fail-closed policies, identity re-verification before deletion, and extensive timeout handling. It supports both interactive TUI and non-interactive JSON output for scripting.
The LLM identified 6 files worth highlighting for reuse:
Provides human-readable byte formatting with SI (1000-based) for disk sizes and binary (1024-based) for memory sizes. Self-contained package with no internal dependencies, easily extractable into any Go project needing size formatting.
Implements min-heaps for dirEntry and fileEntry to efficiently track top-N largest items during disk scanning. The heap pattern is generic and could be extracted for any top-N problem, demonstrating non-obvious data structure usage in a CLI tool.
Detects cache directories by reading CACHEDIR.TAG file signatures. Self-contained function that can be reused in any file system cleanup tool to identify cache directories without external dependencies.
Implements a ring buffer for network history rate smoothing, used to calculate smoothed network speeds. The ring buffer pattern is generic and reusable for any sliding window data collection in monitoring tools.
Centralized timeout constants and run_with_timeout function with fallback mechanisms (gtimeout, perl, shell). Reusable pattern for any shell script needing bounded execution, demonstrating robust cross-platform timeout handling.
Manages sudo sessions with background keepalive, Touch ID support, and re-authentication fallback. Reusable pattern for any macOS CLI tool requiring elevated privileges, with careful handling of session expiration and concurrent access.