1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 21:55:08 +00:00
Commit Graph

81 Commits

Author SHA1 Message Date
Tw93
c5d6cdc2f9 perf(purge/uninstall): eliminate per-item subprocess forks in scan phase
purge:
- is_safe_project_artifact: replace echo|tr|wc depth calc with pure bash
  string arithmetic (2 forks → 0 per item)
- process_scan_results: replace dirname subprocess with ${item%/*}
- is_recently_modified: accept pre-computed epoch to avoid redundant
  get_epoch_seconds call (N date forks → 1 before loop)
- fd pattern construction: replace 45 per-target sed forks with single
  printf|sed pass (45 forks → 2)
- pre-compute _cached_project_paths alongside existing name/basename
  cache so display loop avoids get_project_path subshell per item

uninstall/app-selector:
- default size display: N/A → -- for apps without cached size data
  (cleaner UX on first scan; real sizes populate from background refresh)
- Pass 1 scan: replace basename/dirname subshells with parameter expansion
2026-03-21 15:33:57 +08:00
Tw93
4f07a5aa0a perf(clean): speed up scan phase across all modules
- Parallelize project cache indicator checks and root scans in caches.sh
  (sequential find per $HOME/* dir → throttled background jobs)
- Pre-compute project name cache before purge display loop, eliminating
  O(N²) filesystem traversals in get_artifact_display_name
- Replace basename/dirname subshells with parameter expansion in
  get_project_name/get_project_path hot loops; depth counter via
  bash string arithmetic instead of echo|tr|wc|tr pipeline
- Eliminate mktemp/awk/rm per call in app_support_item_size_bytes,
  use command substitution to capture du output directly
- Defer tr lowercase in clean_application_support_logs to only when
  first 3 protection checks fail; replace basename with ${var##*/}
- Optimize trash item counting: find -print0|tr -dc '\0'|wc -c
  avoids per-file fork from -exec printf
- Add -maxdepth 5 to /private/var/folders find (X dir is always at
  depth 3, code_sign_clone at depth 5 max; verified on real machine)
2026-03-21 15:19:32 +08:00
Tw93
694c191c6f fix: correct glob expansion in downloads cleanup, add purge index bounds guard, update security audit
- lib/clean/user.sh: quote glob patterns in _clean_incomplete_downloads so
  they are not expanded at array assignment time; filenames with spaces would
  previously be word-split before reaching safe_clean, causing silent failures
- lib/clean/project.sh: replace silent array fallback with explicit bounds
  check before reading PURGE_CATEGORY_FULL_PATHS_ARRAY, guarding against
  future index drift if menu filtering is added
- SECURITY_AUDIT.md: document double validatePath in analyze delete, native
  PAM passthrough for sudo prompts, dry-run dedup by filesystem identity,
  atomic purge config write, pre-commit hook mirroring CI, and new test suites
2026-03-21 14:17:52 +08:00
Tw93
d6b9d9f3f3 Fix cleanup regressions and analyze navigation
Refs #605 #607 #608 #609 #610
2026-03-21 13:05:21 +08:00
Tw93
25892594b0 fix: show full purge paths during confirmation
Fixes #576
2026-03-17 19:20:32 +08:00
Tw93
ea37d3e356 fix(purge): remove 60-char hard cap on path display width (issue #564)
The path column in 'mo purge' selection was capped at 60 characters
regardless of terminal width. On wide terminals (120+ cols) this caused
long project paths like ~/GitHub/Ulama/transformer-project to be
truncated unnecessarily to ~17 visible characters.

Remove the hard 60-char cap and let the available terminal space be the
only upper bound, which is already computed as:
  available_for_path = terminal_width - fixed_overhead

Paths now use as much space as the terminal allows while still keeping
the size and artifact-type columns readable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-14 07:46:44 +08:00
Tw93
97d35c03d6 fix(purge): parallelize size calculations to prevent hang (issue #560)
Sequential du calls with 15s timeout each meant N artifacts × 15s of potential
wait when paths are on slow storage (network mounts, Syncthing, large dirs).
Now all du processes are launched concurrently; total time is bounded by the
single longest call (≤ 15s) rather than N × 15s.

fix(protection): protect CoreAudio paths in should_protect_path (issue #553)

Add com.apple.coreaudio*, com.apple.audio.*, and coreaudiod* to the protected
path patterns so deep-clean cannot touch audio subsystem caches, reducing risk
of audio output loss on Intel Macs running macOS Sequoia.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-03-14 00:00:08 +08:00
Onur Taşhan
dfedc029d1 fix: handle empty menu_options in mo purge to prevent unbound variable error (#547)
When no artifacts are found during scanning, `menu_options` remains an
empty array. With `set -euo pipefail` active, expanding `${menu_options[@]}`
on an empty array causes a fatal "unbound variable" error (line 1325).

Add an early-return guard after the spinner stops: if no items were found,
print a friendly "No artifacts found to purge" message and exit cleanly.

Fixes #546
2026-03-07 20:33:47 +08:00
tw93
241e6a7a34 fix(purge): avoid counting failed dry-run removals 2026-03-01 20:35:49 +08:00
陳德生
05446e0847 Add dry-run support across destructive commands (#516)
* chore: update contributors [skip ci]

* Add dry-run support across destructive commands

Implement dry-run for uninstall, purge, installer, touchid, completion, and remove flows.\nGuard side effects in uninstall path (launchctl, defaults writes, kill/brew actions), update help/README, and add coverage in CLI/Bats tests.\n\nValidation: ./scripts/check.sh and ./scripts/test.sh (452 tests, 0 failures, 8 skipped).

* test(purge): keep dev-compatible purge coverage

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tw93 <hitw93@gmail.com>
2026-03-01 20:03:22 +08:00
tw93
c19a0276b8 refactor: Update shell arithmetic increment syntax from ((var++)) || true to var=$((var + 1)) across various scripts. 2026-02-28 11:10:18 +08:00
tw93
7d70889ad4 chore: auto format code 2026-02-28 11:03:16 +08:00
tw93
a9433e4acd fix: preserve interrupt semantics and restore purge traps 2026-02-27 11:18:53 +08:00
tw93
d13c0927a6 feat(purge): add confirm dialog, two-pass column alignment, adaptive footer
- Add confirm_purge_cleanup() to show item count + size and require
  explicit Enter/y confirmation before any deletion
- Two-pass layout in clean_project_artifacts: pass 1 collects data,
  pre-scan finds max path and artifact widths, pass 2 formats with
  consistent column alignment across all rows
- Adaptive footer hints in select_purge_categories degrade gracefully
  on narrow terminals (full → reduced → minimal)
- Use printf '\033[J' to clear stale content when list height shrinks
- Guard empty-array expansions with ${arr[*]-} for set -u safety
- Add BATS tests for confirm_purge_cleanup (Enter confirm, ESC cancel)
2026-02-26 19:42:42 +08:00
tw93
8bd257a9c2 refactor(purge): reuse shared size formatter in header 2026-02-24 14:20:25 +08:00
Angelk90
ae5e81722b Fix (#486) 2026-02-24 14:17:20 +08:00
tw93
ff00e9ba9c refactor(clean): extract shared purge hint helpers 2026-02-23 13:39:22 +08:00
tw93
1169cbf198 fix(purge): avoid command find in fallback scan (#478) 2026-02-23 08:15:47 +08:00
tw93
8f5b70457e fix(purge): normalize search roots for scan filtering (#478) 2026-02-22 22:06:19 +08:00
tw93
894c81bb9a fix(purge): detect artifacts when search path is project root 2026-02-22 10:08:20 +08:00
tw93
0597021fd4 fix(purge): save and restore caller traps to prevent state leak
- Save caller's INT/TERM traps before installing local cleanup trap
- Restore original traps after clean_project_artifacts completes
- Add test to verify trap restoration behavior

Fixes P3 issue: project.sh (line 825, 870)
2026-02-21 20:21:54 +08:00
tw93
7c974bf351 fix(purge): prevent hangs during size calculation 2026-02-19 22:52:27 +08:00
tw93
a29cadbfd0 fix(purge): resolve trap conflict between purge.sh and project.sh
- Add guard flag in cleanup_monitor to prevent duplicate execution
- Check for existing trap in project.sh before setting new one
- Prevents crash when user presses Ctrl-C or scan process fails
2026-02-16 15:54:16 +08:00
tw93
685aa8b970 refactor(purge): improve React Native targets safety and clarity
- Clarify .cxx comment to indicate React Native NDK build cache
- Add protection for Xcode global DerivedData in ~/Library/Developer/Xcode/
  to prevent accidental deletion of shared build artifacts

Refs: #461
2026-02-16 15:39:00 +08:00
Dimitar Nestorov
a7c9b8d6ec feat(purge): add common React Native targets (#461) 2026-02-16 15:37:07 +08:00
tw93
7d193526c3 fix(purge): support vim j/k navigation in selector 2026-02-15 07:48:35 +08:00
tw93
f8ff6d54cd fix(purge): dynamically limit path display width to 70% of terminal, fixing issue #433 2026-02-09 19:34:15 +08:00
tw93
7f787b5c04 fix: implement MO_USE_FIND and improve fd fallback logic
Fixes the issue reported in PR #410 where mo purge fails to find
artifacts when fd returns empty results.

Changes:
- Implement MO_USE_FIND environment variable to force using find
- Improve fd fallback: check if fd output is empty (-s test)
- Add debug logging to show which tool is being used
- If fd returns no results, fallback to find automatically

This fixes the root cause where fd successfully runs (exit 0) but
finds nothing, preventing the find fallback from being triggered.
2026-02-04 20:05:09 +08:00
tw93
d8b396533d fix: implement MO_USE_FIND and improve fd fallback logic
Fixes the issue reported in PR #410 where `mo purge` fails to find
artifacts when `fd` returns empty results.

Changes:
- Implement MO_USE_FIND environment variable to force using find
- Improve fd fallback: check if fd output is empty (-s test)
- Add debug logging to show which tool is being used
- If fd returns no results, fallback to find automatically

This fixes the root cause where fd successfully runs (exit 0) but
finds nothing, preventing the find fallback from being triggered.
2026-02-04 19:57:44 +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
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
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
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
e966838c82 style: standardize punctuation across codebase
- Replace parentheses with commas for supplementary info
- Use commas instead of em-dashes for separators
- Update bullet points from - to * in some contexts
- Improve version extraction regex with fallback logic
2026-01-26 14:36:06 +08:00
Tw93
83dc59bb54 feat: improve purge display with full paths and size sorting (#311)
- Show full project paths (~/www/project) instead of just project names
  - Sort artifacts by size descending (largest first)
  - Increase path display width for better readability
  - Support CMD+Click to open folders in terminal
2026-01-14 10:15:58 +08:00
Tw93
8ec7663a70 Fixed the ShellCheck warning 2026-01-13 16:54:10 +08:00
Tw93
5b51007c3f Fix mo purge UI glitch by correctly clearing the scanning progress line without overwriting the title. 2026-01-13 14:16:41 +08:00
Tw93
5d77001a72 Optimize the effect and speed of scanning 2026-01-12 17:49:51 +08:00
Biplav Barua
3507870275 feat: add Angular, SvelteKit, Astro, and coverage to purge targets (#286) 2026-01-10 00:05:38 +08:00
Tw93
fc4d94f7c7 Merge pull request #247 from JackPhallen/feat/more-purge-support
feat(purge): C# bin purge support
2026-01-04 16:16:59 +08:00
Jack Phallen
aabee42344 feat(purge): C# bin purge support 2026-01-03 23:24:25 -08:00
Jack Phallen
2045917c23 feat(purge): Additional python purge targets 2026-01-03 22:54:37 -08:00
Tw93
6dfd675417 refactor: standardize epoch time retrieval with get_epoch_seconds and ensure locale-independent string transformations. 2026-01-03 18:07:47 +08:00
Tw93
f98aab6840 refactor: simplify configuration by removing unused environment variables 2026-01-03 13:34:19 +08:00
Tw93
910e79df4e feat: Improve clean command's regex handling and pnpm cache cleaning, enhance test output, update completion descriptions, and clarify installation instructions. 2026-01-02 18:50:42 +08:00
Jack Phallen
5e7f276722 fix(purge): use regex OR pattern instead of multiple -g flags for fd 2026-01-01 22:45:30 -08:00
Tw93
23ffafc415 feat: add Microsoft Edge old version cleanup and improve vendor directory protection logic. 2026-01-02 00:29:58 +08:00