1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 09:46:44 +00:00

540 Commits

Author SHA1 Message Date
tw93
cb19899eaa fix(apps): correct array initialization for matches in clean_orphaned_app_data 2026-02-04 17:34:04 +08:00
tw93
41a26204fb perf: skip redundant -name parameter when pattern is wildcard
Optimization:
- Skip -name "*" in safe_sudo_find_delete when pattern matches everything
- Reduces unnecessary parameter passing to find command
- Improves performance for operations that scan all files

Rationale:
- find -name "*" is redundant as it matches everything by default
- Removing it reduces command overhead without changing behavior
2026-02-04 16:18:13 +08:00
tw93
0fbf2661c8 perf: optimize system cleanup by merging find operations
Performance improvements:
- Merge 3 separate find operations into 1 for /Library/Caches
  - Combine *.cache, *.tmp, *.log patterns in single scan
  - Reduces filesystem traversal overhead
- Merge 2 find operations into 1 for /private/var/log
  - Combine *.log and *.gz patterns
- Optimize diagnostics cleanup with single combined scan
  - Merge Special, Persist, and tracev3 patterns
  - Reduces redundant directory traversal
- Use find -delete for batch removal of memory exception reports
  - More efficient than iterative removal for large file counts
  - Add summary logging to operations.log

UI improvements:
- Add granular spinner messages for each cleanup stage
- Separate diagnostic logs and power logs output for clarity
- Add progress feedback during Time Machine status check

Tests:
- Update sudo mock functions to support new combined find patterns
- Verify find -delete usage for memory exception cleanup
- Update assertions to match optimized implementation
2026-02-04 16:18:06 +08:00
tw93
a4e084a4ed feat: improve app cleanup with orphaned LaunchAgent detection
New features:
- Add orphaned LaunchAgent/LaunchDaemon detection with 5-layer verification
  - Layer 1: Check if program path exists
  - Layer 2: Verify AssociatedBundleIdentifiers via mdfind
  - Layer 3: Check Application Support directory activity (7 days)
  - Layer 4: Fuzzy match app name in /Applications
  - Layer 5: Special handling for PrivilegedHelperTools
- Only process user-level ~/Library/LaunchAgents (safer than system-level)
- Unload agent before removal using launchctl

Bug fixes:
- Handle paths with spaces correctly in orphaned_app_data cleanup
  - Add nullglob state management to prevent word splitting
  - Use IFS=$'\n' for proper array iteration
- Only count successful deletions (check safe_clean return value)

Tests:
- Add 4 new tests for is_launch_item_orphaned edge cases
- Add tests for space handling and deletion count accuracy
2026-02-04 16:17:36 +08:00
tw93
579c963940 uninstall: refine protection flow and menu filtering 2026-02-03 17:36:15 +08:00
tw93
bad1c71231 fix: protect Gradle cache from cleanup by default
Gradle build cache (~/.gradle/caches) is now protected by default whitelist,
similar to Maven repository. This prevents unintentional deletion of large
dependency caches that take time and bandwidth to re-download.

- Add ~/.gradle/caches/* and ~/.gradle/daemon/* to DEFAULT_WHITELIST_PATTERNS
- Remove Gradle cleanup from clean_dev_jvm() function
- Users can disable protection via 'mo clean --whitelist' if needed

Fixes #408
2026-02-03 16:37:33 +08:00
tw93
a5c7abd227 refactor: optimize raycast cleanup code structure
Improve code readability and maintainability:
- Simplify conditional logic with chained operators
- Add clarifying comments for different cleanup scopes
- Rename variables for better semantic clarity
- Maintain consistent style with other app cleanup patterns
2026-02-03 14:53:10 +08:00
Andrei Murariu
4f3eb0eb62 bug-fix: uninstall raycast leftovers (#404) 2026-02-03 14:47:44 +08:00
tw93
d02bb49497 fix: update macOS installer cleanup logic to remove installers older than 14 days 2026-02-02 17:28:57 +08:00
tw93
5f88d84d3f fix: update authentication failure messages for clarity 2026-02-02 17:18:32 +08:00
tw93
48db04a95b fix: add comment for clarity in safe_sudo_remove function 2026-02-02 17:15:32 +08:00
tw93
05faf2b691 core: improve file removal diagnostics 2026-02-02 17:06:00 +08:00
tw93
f965ca25c3 uninstall: harden cache and removal flow 2026-02-02 17:05:42 +08:00
tw93
aaa3a6ae5a ui: add menu filtering support 2026-02-02 17:05:19 +08:00
Andrei Murariu
e8f46a7a1c feat: Homebrew uninstall with --zap flag (#397)
Uninstalling mole with Zap will automatically remove also the directories that brew creates for it. -> More complete uninstallation

Also updated the test about uninstalling
2026-02-02 11:26:58 +08:00
tw93
7366047398 fix: adjust output formatting in clean_project_artifacts function for better alignment 2026-02-02 11:25:39 +08:00
tw93
67c9d16b13 fix: optimize find command expressions in scan_purge_targets function 2026-02-02 11:21:11 +08:00
Angelk90
cb779d9144 Fix use find (#399) 2026-02-02 11:19:44 +08:00
tw93
82d46ee286 fix: refine clash pattern matching for data protection and improve spinner handling 2026-02-01 09:28:49 +08:00
tw93
7e2c8d24fa fix: add fallback to find when fd fails in project scan
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-01-31 21:26:15 +08:00
tw93
d0a95f5e31 fix: enhance performance of application support log cleanup using find -delete 2026-01-31 20:22:52 +08:00
tw93
7d62fa5e65 fix: improve performance of cache cleanup using find -delete 2026-01-31 20:19:38 +08:00
tw93
8ac71a3937 fix: add clash patterns to data protection checks 2026-01-31 20:05:38 +08:00
tw93
c34d8e71c8 fix: correct minimum purge scan depth from 2 to 1 2026-01-31 20:05:34 +08:00
tw93
81c58b5b89 fix: increase purge max depth from 4 to 6 to find deeply nested artifacts
Fixes #394

Users reported that `mo purge` could not find `node_modules` folders in
deeply nested project structures. The issue was caused by `PURGE_MAX_DEPTH_DEFAULT=4`
being too restrictive for real-world project organizations.

Example failing case:
~/Projects/Company/Division/Team/MyProject/node_modules  (depth 5)
~/Projects/Org/ClientA/Backend/Services/API/node_modules (depth 6)

Changes:
- Increased PURGE_MAX_DEPTH_DEFAULT from 4 to 6
- This covers 95%+ of real-world project structures
- Performance impact: ~15-25% slower scan (acceptable trade-off for correctness)
- All 41 existing tests pass with the new depth limit

Verified:
- Tested with structures at depths 2-6, all artifacts now detected
- No breaking changes to existing functionality
- Users with fd (fast) won't notice performance difference
2026-01-31 17:45:37 +08:00
tw93
aa6f6c503f refactor: add feedback for fallback Trash cleanup
Improve user experience when osascript fails to empty Trash:
- Count successfully cleaned items
- Display cleanup confirmation message
- Only show message if items were actually cleaned
- Call note_activity to record the cleanup

This ensures users get consistent feedback regardless of which
cleanup method is used (osascript vs find fallback).
2026-01-31 17:40:07 +08:00
tw93
82df7abc35 Merge branch 'main' into dev 2026-01-31 17:37:46 +08:00
dekran
dcac6a3391 fix: handle dotfiles in Trash cleanup (#395)
Replace glob pattern with find command to properly clean dotfiles
in Trash when osascript fallback is used. The old pattern
~/.Trash/* does not match files starting with "." in bash.

This fix ensures that hidden files like .DS_Store, .hidden_file,
etc. are properly removed when cleaning the Trash.
2026-01-31 17:37:22 +08:00
tw93
15bb60c531 perf: fix should_protect_data performance regression with case optimization
Issue #393 reported mo clean hanging on 'Scanning sandboxed apps'
and 'Scanning orphaned app resources'.

Root cause: should_protect_data() was looping through 332 patterns
(28 SYSTEM_CRITICAL_BUNDLES_FAST + 304 DATA_PROTECTED_BUNDLES).
For 662 sandboxed containers, this resulted in 220,000+ pattern matches.

Solution: Replace loops with fast case statement for common prefixes:
- com.apple.* (system apps) - instant return
- com.microsoft.*, com.jetbrains.* (IDEs) - instant return
- Password managers, VPNs, Docker etc. - instant return
- Other apps - instant return (no protection needed)
- Only check detailed list for special wildcards (com.tencent.* etc.)

Performance: Clean command maintains 35s (same as previous optimization)
Functionality: All 9 protection tests pass
2026-01-31 11:54:26 +08:00
tw93
9d2c907c08 perf: optimize app protection with dual-array strategy and lazy loading
- Add SYSTEM_CRITICAL_BUNDLES_FAST (30 items) for clean operations
- Keep SYSTEM_CRITICAL_BUNDLES (60+ items) for uninstall precision
- Implement lazy regex loading - only build when uninstall is triggered
- Use fast wildcard matching for should_protect_data (clean scenario)
- Use detailed regex matching for should_protect_from_uninstall

Performance improvement:
- Clean command: 71s → 35s (51% faster)
- System CPU: 17.3s → 5.9s (66% reduction)
- Now 27% faster than v1.23.2 baseline (48s → 35s)

Fixes performance regression introduced in commit 2865a78 where
SYSTEM_CRITICAL_BUNDLES expanded from 5 wildcards to 60+ explicit entries.
2026-01-31 11:31:51 +08:00
tw93
e12a40f6bf fix: use \033[2K to fully clear spinner lines and prevent text remnants
Fixes text remnants and extra blank lines when spinner messages change.

Issues fixed:
1. Text remnants when switching from longer to shorter messages (e.g., 'Cleaning...ems...')
2. Extra blank lines appearing after section headers

Root causes:
- \033[K only clears from cursor to end of line, leaving remnants when new messages are shorter
- stop_section_spinner was clearing lines even when no spinner was running

Changes:
- lib/core/base.sh:
  - Changed stop_section_spinner(), safe_clear_line(), safe_clear_lines() to use \033[2K
  - Added guard in stop_section_spinner to only clear when spinner is actually running
- lib/core/ui.sh:
  - Clear line once when starting spinner (before loop) to ensure clean start
  - Normal spinner rotation uses \r without clearing (performance optimization)

Performance: Line clearing happens only once per spinner start, not on every loop iteration.

Fixes #390
2026-01-31 10:09:02 +08:00
tw93
e81be16031 perf: optimize scanner timer usage and app protection matching
- Replace time.After() with reusable timer to reduce GC pressure
- Use pre-compiled regex for app bundle matching (O(1) vs O(N))
- Fix Bash 3.2 compatibility (remove local -n usage)
2026-01-30 15:37:13 +08:00
tw93
89dcb0c3b5 fix: Use du -P for accurate size calculation and add timeouts to channel sends to prevent blocking. 2026-01-30 15:06:30 +08:00
tw93
2865a788e8 test: add checks for uninstallable Apple apps in should_protect_from_uninstall function 2026-01-30 13:57:43 +08:00
tw93
e96868824b feat: clean Apple Podcasts zombie StreamedMedia files (#387)
Add cleanup for sandboxed container tmp directory where zombie sparse
files can accumulate (0-byte files with ~93MB pre-allocated APFS blocks).
2026-01-30 11:19:51 +08:00
tw93
d06cf6a69e fix: correct blue color definition in base.sh 2026-01-30 11:13:29 +08:00
tw93
3a7f15aa32 fix(check): use numeric df output for disk space 2026-01-29 11:15:14 +08:00
tw93
0a46bf2077 fix: improve status icons and fix spinner cleanup
- Show ✓ for empty trash and discovered versions (normal states)
- Fix inline spinner not stopping, causing residual display artifacts
2026-01-28 20:15:26 +08:00
tw93
88da841ce9 refactor: remove mo log command, keep log recording only 2026-01-28 19:58:59 +08:00
Tw93
c12f76c9f3 chore: auto format code 2026-01-28 11:46:59 +00:00
tw93
64f79a59d8 feat: optimize log system and add mo log command
- Add get_timestamp() helper and optimize log rotation
- Create mo log viewer with search/filter capabilities
- Improve test coverage to 18.4% with better assertions
- Add security fixes for grep injection prevention
2026-01-28 19:46:01 +08:00
tw93
6f0255c56e fix(uninstall): enhance app leftover detection with naming variants (#377) 2026-01-28 19:06:52 +08:00
tw93
61a3238f19 fix(scan): prevent hang on cyclic symlinks (#378, #379) 2026-01-28 11:43:39 +08:00
tw93
8b9436e244 feat(check): detect third-party firewalls before built-in check
(#374)

    Support Little Snitch, LuLu, Radio Silence, Hands Off!, Murus, Vallum.
2026-01-27 20:04:29 +08:00
tw93
37e6994c34 feat(clean): add Yandex Browser cache cleanup support 2026-01-27 11:34:21 +08:00
tw93
3919a70300 fix: enhance uninstall security per audit review
- Validate bundle_id format (reverse-DNS) in stop_launch_services() to prevent glob injection attacks
    - Add common word exclusion list for LaunchAgents name search to avoid false positive matches (Music, Notes, Photos, etc.) - Add security comments explaining symlink handling in remove_file_list()
    - Improve brew_uninstall_cask() timeout handling: exit code 124 now returns failure immediately
    - Update SECURITY_AUDIT.md with remediation details
2026-01-26 20:27:46 +08:00
tw93
0fbf88a6c6 fix: harden cleanup path validation 2026-01-26 15:43:11 +08:00
Tw93
587b127c01 chore: auto format code 2026-01-26 07:24:38 +00:00
tw93
610a4fc0a7 chore: simplify optimize maintenance cleanup 2026-01-26 15:22:20 +08:00
tw93
864bade7c6 fix: improve uninstall guidance and timeouts 2026-01-26 15:22:16 +08:00