mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 18:34:46 +00:00
4.8 KiB
4.8 KiB
Mole AI Agent Documentation
READ THIS FIRST: This file serves as the single source of truth for any AI agent trying to work on the Mole repository. It aggregates architectural context, development workflows, and behavioral guidelines.
1. Philosophy & Guidelines
Core Philosophy
- Safety First: Never risk user data. Always use
safe_*wrappers. When in doubt, ask. - Incremental Progress: Break complex tasks into manageable stages.
- Clear Intent: Prioritize readability and maintainability over clever hacks.
- Native Performance: Use Go for heavy lifting (scanning), Bash for system glue.
Eight Honors and Eight Shames
- Shame in guessing APIs, Honor in careful research.
- Shame in vague execution, Honor in seeking confirmation.
- Shame in assuming business logic, Honor in human verification.
- Shame in creating interfaces, Honor in reusing existing ones.
- Shame in skipping validation, Honor in proactive testing.
- Shame in breaking architecture, Honor in following specifications.
- Shame in pretending to understand, Honor in honest ignorance.
- Shame in blind modification, Honor in careful refactoring.
Quality Standards
- English Only: Comments and code must be in English.
- No Unnecessary Comments: Code should be self-explanatory.
- Pure Shell Style: Use
[[ ]]over[ ], avoidlocal varassignments on definition line if exit code matters. - Go Formatting: Always run
gofmt(or let the build script do it).
2. Project Identity
- Name: Mole
- Purpose: A lightweight, robust macOS cleanup and system analysis tool.
- Core Value: Native, fast, safe, and dependency-free (pure Bash + static Go binary).
- Mechanism:
- Cleaning: Pure Bash scripts for transparency and safety.
- Analysis: High-concurrency Go TUI (Bubble Tea) for disk scanning.
- Monitoring: Real-time Go TUI for system status.
3. Technology Stack
- Shell: Bash 3.2+ (macOS default compatible).
- Go: Latest Stable (Bubble Tea framework).
- Testing:
- Shell:
bats-core,shellcheck. - Go: Native
testingpackage.
- Shell:
4. Repository Architecture
Directory Structure
bin/: Standalone entry points.mole: Main CLI wrapper.clean.sh,uninstall.sh: Logic wrappers callinglib/.
cmd/: Go applications.analyze/: Disk space analyzer (concurrent, TUI).status/: System monitor (TUI).
lib/: Core Shell Logic.core/: Low-level utilities (logging,safe_remove, sudo helpers).clean/: Domain-specific cleanup tasks (brew,caches,system).ui/: Reusable TUI components (menu_paginated.sh).
scripts/: Development tools (run-tests.sh,build-analyze.sh).tests/: BATS integration tests.
5. Key Workflows
Development
- Understand: Read
lib/core/to know what tools are available. - Implement:
- For Shell: Add functions to
lib/, source them inbin/. - For Go: Edit
cmd/app/*.go.
- For Shell: Add functions to
- Verify: Use dry-run modes first.
Commands:
./scripts/run-tests.sh: Run EVERYTHING (Lint, Syntax, Unit, Go)../bin/clean.sh --dry-run: Test cleanup logic safely.go run ./cmd/analyze: Run analyzer in dev mode.
Building
./scripts/build-analyze.sh: Compilesanalyze-gobinary (Universal)../scripts/build-status.sh: Compilesstatus-gobinary.
Release
- Versions managed via git tags.
- Build scripts embed version info into binaries.
6. Implementation Details
Safety System (lib/core/file_ops.sh)
- Crucial: Never use
rm -rfdirectly. - Use:
safe_remove "/path"safe_find_delete "/path" "*.log" 7 "f"
- Protection:
validate_path_for_deletionprevents root/system deletion.checksensure path is absolute and safe.
Go Concurrency (cmd/analyze)
- Worker Pool: Tuned dynamically (16-64 workers) to respect system load.
- Throttling: UI updates throttled (every 100 items) to keep TUI responsive (80ms tick).
- Memory: Uses Heaps for top-file tracking to minimize RAM usage.
TUI Unification
- Keybindings:
j/k(Nav),space(Select),enter(Action),R(Refresh). - Style: Compact footers
|and standard colors defined inlib/core/base.shor Go constants.
7. Common AI Tasks
- Adding a Cleanup Task:
- Create/Edit
lib/clean/topic.sh. - Define
clean_topic(). - Register in
lib/optimize/tasks.shorbin/clean.sh. - MUST use
safe_*functions.
- Create/Edit
- Modifying Go UI:
- Update
modelstruct inmain.go. - Update
View()inview.go. - Run
./scripts/build-analyze.shto test.
- Update
- Fixing a Bug:
- Reproduce with a new BATS test in
tests/. - Fix logic.
- Verify with
./scripts/run-tests.sh.
- Reproduce with a new BATS test in