How tw93/mole works
1. Overall shape
Mole is a macOS-focused maintenance toolkit delivered as a single CLI entrypoint, mo, with a mixed implementation split between Go and shell scripts. The repository is organized around user-facing commands such as clean, uninstall, optimize, analyze, status, purge, installer, update, and remove.
2. Primary execution boundary
The top-level bin/*.sh scripts are the main user entrypoints and wrappers. They expose the CLI commands, handle shell integration, and delegate into the shared shell libraries under lib/, or into the Go-built subcommands where appropriate. This makes the repo feel like one product, but with multiple implementation layers behind it.
3. Go-based subsystems
cmd/analyze and cmd/status are the main Go subsystems. They appear to own the more interactive and structured features:
- analyze handles disk exploration, JSON output, live scanning, view formatting, deletion/update flows, and caching.
- status gathers machine health and runtime metrics, diagnoses conditions, and renders the live dashboard.
These commands are likely the most data-rich parts of the application and also the ones that support machine-readable output.
4. Shell-based maintenance engine
Most destructive or system-touching maintenance work lives in shell libraries under lib/. These are grouped by domain:
- lib/clean for cache and artifact cleanup
- lib/uninstall for app removal
- lib/optimize for system refresh and maintenance tasks
- lib/manage for whitelist and purge-path management
- lib/ui for interactive menu components
- lib/core for shared plumbing
This is the core operational backend for cleanup, uninstall, optimize, purge, and related actions.
5. Common infrastructure layer
lib/core is the shared foundation used by the shell subsystems. It centralizes things like command wiring, common helpers, logging, file operations, timeouts, sudo handling, help text, and bundle/app resolution. Architecturally, this is the low-level boundary that keeps each maintenance command from reimplementing the same safety and runtime logic.
6. Safety and destructive-operation controls
Safety is a first-class boundary across the repo. The README and tree show dedicated safety docs, review agents, and tests for dangerous paths. In practice, the destructive commands rely on:
- path validation and protected-directory rules
- dry-run behavior
- whitelists / protected lists
- logging of file operations
- confirmation gates for high-risk actions
This means the architecture is intentionally conservative: commands prefer refusing or skipping over broad deletion.
7. Data flow for cleanup and uninstall
For clean and uninstall, the flow is roughly: user selection or scan discovery → classification of targets → safety filtering → deletion or trash/removal actions → summary of freed space. The repo also distinguishes between removing apps that are still installed versus cleaning leftovers for already-removed apps. That split is reflected in separate cleanup and uninstall domains.
8. Data flow for analysis
analyze operates as a disk traversal and inspection pipeline. It scans a target path, aggregates directory and file sizes, identifies large files, formats the results for interactive browsing, and can emit JSON for scripting. The README indicates a key behavioral boundary: deletion from analyze goes through Trash/Finder rather than direct removal, making it safer for ad hoc cleanup.
9. Data flow for live status
status is a read-only telemetry pipeline. It collects system state across CPU, memory, disk, network, battery/power, hardware, and process metrics, then computes a health score and renders a live dashboard. It also supports JSON output and auto-switches to JSON when piped, which makes it suitable for automation without changing the command path.
10. Interactive UI layer
The repo has a dedicated terminal UI layer in lib/ui and corresponding view logic in the Go commands. This supports menu navigation, paginated selection, and keyboard-driven interaction for actions like choosing apps, selecting files, or reviewing cleanup candidates. The UI is not just presentation; it directly gates destructive operations by forcing user review.
11. Support tooling and install/update path
The scripts/ and install.sh files support installation, release automation, quick-launcher setup, and repository maintenance tasks. This sits outside the core command runtime but is important architecturally because it defines how the CLI is distributed, updated, and integrated into shell environments.
12. Testing and validation boundaries
The repo uses a strong split between:
- Go tests under cmd/analyze, cmd/status, and internal/
- BATS integration tests under tests/ for shell commands and system behavior
- CI workflows under .github/workflows/
This testing structure mirrors the implementation split: Go logic is unit-tested, while system-affecting shell behavior is validated with higher-level integration tests.
13. Security and operational governance
Security-related files and workflows are prominent: SECURITY.md, SECURITY_AUDIT.md, gitleaks, CodeQL, and dedicated safety review agents. That indicates the project treats local-destructive operations, path handling, and shell execution as architectural risk areas, not just implementation details.
14. How to diagram it
The clean architecture view is: **user/terminal → mo entry scripts → command-specific engine (cmd/* or lib/*) → filesystem/system APIs → output/logging/trash. Around that core, add side boundaries for interactive UI, safety validation, metrics collection, installation/release tooling, and testing/CI**.
Main entry points: mo mo · analyze Analyze · core Core · status Status
Components 25
CLI entrypoints
User-facing shell wrappers and command dispatch.
- mo · Primary CLI launcher for the toolkit.
mo - clean · Shell entrypoint for cache and artifact cleanup.
bin/clean.sh - uninstall · Shell entrypoint for app removal flows.
bin/uninstall.sh - optimize · Shell entrypoint for maintenance and refresh tasks.
bin/optimize.sh - analyze · Wrapper that dispatches into the Go analyzer.
bin/analyze.sh - status · Wrapper that dispatches into the Go status monitor.
bin/status.sh - purge · Shell entrypoint for purge and whitelist-driven removal.
bin/purge.sh - installer · Shell entrypoint for install and setup actions.
bin/installer.sh
Go commands
Structured analysis and telemetry subsystems.
- Analyze · Disk exploration, formatting, JSON output, and delete/update flows.
cmd/analyze - Status · System health telemetry, diagnosis, and live dashboard rendering.
cmd/status - Scanner · Traverses paths and builds size/classification results.
cmd/analyze/scanner.go - Live view · Live scanning and interactive browsing of analysis results.
cmd/analyze/live_scan.go - JSON out · Structured export for scripting and automation.
cmd/analyze/json.go - Metrics · Collects CPU, memory, disk, network, battery, GPU, hardware, and process data.
cmd/status/metrics.go - Diagnosis · Computes health signals and system diagnosis.
cmd/status/diagnosis.go - Dashboard · Renders the live status interface.
cmd/status/view.go
Shell maintenance
Core operational libraries for destructive and system-touching tasks.
- Core · Shared command wiring, logging, timeouts, help, sudo, and file operations.
lib/core - Clean · Cleanup routines for caches, app leftovers, and system artifacts.
lib/clean - Uninstall · Application removal flows and batch uninstall support.
lib/uninstall - Optimize · Maintenance and system refresh tasks.
lib/optimize - Manage · Whitelist and purge-path management for controlled deletion.
lib/manage - UI · Interactive menus, selection, and pagination for user review.
lib/ui
Support tooling
Install, release, security, and test boundaries.
Connections 34
- mo → clean: dispatches to · Primary CLI exposes cleanup command.
- mo → uninstall: dispatches to · Primary CLI exposes uninstall command.
- mo → optimize: dispatches to · Primary CLI exposes optimize command.
- mo → analyze: dispatches to · Primary CLI exposes analysis command.
- mo → status: dispatches to · Primary CLI exposes status command.
- mo → purge: dispatches to · Primary CLI exposes purge command.
- mo → installer: dispatches to · Primary CLI exposes installer command.
- clean → Clean: uses · Cleanup wrapper delegates into shell domain.
- uninstall → Uninstall: uses · Uninstall wrapper delegates into shell domain.
- optimize → Optimize: uses · Optimize wrapper delegates into shell domain.
- purge → Manage: uses · Purge wrapper uses policy and whitelist logic.
- analyze → Analyze: invokes · Wrapper launches Go analyzer.
- status → Status: invokes · Wrapper launches Go status command.
- installer → Install: uses · Installer wrapper routes to setup tooling.
- Analyze → Scanner: scans · Core analyzer traverses filesystem and aggregates sizes.
- Analyze → Live view: renders · Interactive analysis views and live browsing.
- Analyze → JSON out: exports · Machine-readable output path for scripts.
- Analyze → UI: uses · Interactive selection and review UI.
- Analyze → Core: uses · Shared shell plumbing and safety helpers.
- Status → Metrics: collects · Telemetry collection across system subsystems.
- Status → Diagnosis: evaluates · Transforms metrics into health assessment.
- Status → Dashboard: renders · Live dashboard output.
- Status → Core: uses · Shared process and runtime helpers.
- Clean → Core: uses · Cleanup routines rely on shared safety and file ops.
- Uninstall → Core: uses · Removal flows depend on shared shell foundation.
- Optimize → Core: uses · Maintenance tasks reuse common execution plumbing.
- Manage → Core: uses · Whitelist and purge-path logic uses common helpers.
- UI → Core: uses · Terminal UI builds on shared shell utilities.
- Tests → Core: validates · Integration and fuzz tests cover common shell behavior.
- Tests → Clean: validates · Cleanup behavior is heavily tested.
- Tests → Uninstall: validates · Uninstall safety and behavior are tested.
- Tests → Analyze: validates · Go analyzer behavior is unit tested.
- Tests → Status: validates · Status command behavior is unit tested.
- Scripts → Install: supports · Repository scripts support installation and release flows.