From 096c0ca73f7ae560d5694352df85ef455da65f52 Mon Sep 17 00:00:00 2001 From: biplavbarua Date: Sat, 10 Jan 2026 01:22:43 +0530 Subject: [PATCH 1/2] feat: add cleanup support for Elixir, Haskell, OCaml, and Editors --- lib/clean/dev.sh | 25 +++++++++++++ tests/dev_extended.bats | 77 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 tests/dev_extended.bats diff --git a/lib/clean/dev.sh b/lib/clean/dev.sh index bb519e7..3b54bf0 100644 --- a/lib/clean/dev.sh +++ b/lib/clean/dev.sh @@ -255,6 +255,27 @@ clean_dev_network() { clean_sqlite_temp_files() { return 0 } +# Elixir/Erlang ecosystem. +clean_dev_elixir() { + safe_clean ~/.mix/archives/* "Mix cache" + safe_clean ~/.hex/cache/* "Hex cache" +} +# Haskell ecosystem. +clean_dev_haskell() { + safe_clean ~/.cabal/packages/* "Cabal install cache" + safe_clean ~/.stack/programs/* "Stack cache" +} +# OCaml ecosystem. +clean_dev_ocaml() { + safe_clean ~/.opam/download-cache/* "Opam cache" +} +# Editor caches. +clean_dev_editors() { + safe_clean ~/Library/Caches/com.microsoft.VSCode/Cache/* "VS Code cached data" + safe_clean ~/Library/Application\ Support/Code/CachedData/* "VS Code cached data" + safe_clean ~/Library/Application\ Support/Code/User/workspaceStorage/* "VS Code workspace storage" + safe_clean ~/Library/Caches/Zed/* "Zed cache" +} # Main developer tools cleanup sequence. clean_developer_tools() { stop_section_spinner @@ -277,6 +298,10 @@ clean_developer_tools() { clean_dev_api_tools clean_dev_network clean_dev_misc + clean_dev_elixir + clean_dev_haskell + clean_dev_ocaml + clean_dev_editors safe_clean ~/Library/Caches/Homebrew/* "Homebrew cache" # Clean Homebrew locks without repeated sudo prompts. local brew_lock_dirs=( diff --git a/tests/dev_extended.bats b/tests/dev_extended.bats new file mode 100644 index 0000000..67b854d --- /dev/null +++ b/tests/dev_extended.bats @@ -0,0 +1,77 @@ +#!/usr/bin/env bats + +setup_file() { + PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)" + export PROJECT_ROOT + + ORIGINAL_HOME="${HOME:-}" + export ORIGINAL_HOME + + HOME="$(mktemp -d "${BATS_TEST_DIRNAME}/tmp-dev-extended.XXXXXX")" + export HOME + + mkdir -p "$HOME" +} + +teardown_file() { + rm -rf "$HOME" + if [[ -n "${ORIGINAL_HOME:-}" ]]; then + export HOME="$ORIGINAL_HOME" + fi +} + +@test "clean_dev_elixir cleans mix and hex caches" { + run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' +set -euo pipefail +source "$PROJECT_ROOT/lib/core/common.sh" +source "$PROJECT_ROOT/lib/clean/dev.sh" +safe_clean() { echo "$2"; } +clean_dev_elixir +EOF + + [ "$status" -eq 0 ] + [[ "$output" == *"Mix cache"* ]] + [[ "$output" == *"Hex cache"* ]] +} + +@test "clean_dev_haskell cleans cabal install and stack caches" { + run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' +set -euo pipefail +source "$PROJECT_ROOT/lib/core/common.sh" +source "$PROJECT_ROOT/lib/clean/dev.sh" +safe_clean() { echo "$2"; } +clean_dev_haskell +EOF + + [ "$status" -eq 0 ] + [[ "$output" == *"Cabal install cache"* ]] + [[ "$output" == *"Stack cache"* ]] +} + +@test "clean_dev_ocaml cleans opam cache" { + run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' +set -euo pipefail +source "$PROJECT_ROOT/lib/core/common.sh" +source "$PROJECT_ROOT/lib/clean/dev.sh" +safe_clean() { echo "$2"; } +clean_dev_ocaml +EOF + + [ "$status" -eq 0 ] + [[ "$output" == *"Opam cache"* ]] +} + +@test "clean_dev_editors cleans VS Code and Zed caches" { + run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' +set -euo pipefail +source "$PROJECT_ROOT/lib/core/common.sh" +source "$PROJECT_ROOT/lib/clean/dev.sh" +safe_clean() { echo "$2"; } +clean_dev_editors +EOF + + [ "$status" -eq 0 ] + [[ "$output" == *"VS Code cached data"* ]] + [[ "$output" == *"VS Code workspace storage"* ]] + [[ "$output" == *"Zed cache"* ]] +} From 413b2c8f98e3541f7a553200a6f980a4ddf297cf Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sun, 11 Jan 2026 09:26:04 +0800 Subject: [PATCH 2/2] fix: disable aggressive cleanup and optimize directory checks --- SECURITY_AUDIT.md | 8 ++++++++ lib/clean/dev.sh | 28 +++++++++++++++++++--------- tests/dev_extended.bats | 10 +++++++--- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/SECURITY_AUDIT.md b/SECURITY_AUDIT.md index 2fc4a61..ee00b91 100644 --- a/SECURITY_AUDIT.md +++ b/SECURITY_AUDIT.md @@ -163,6 +163,14 @@ The analyzer (`mo analyze`) uses a different security model: **Code:** `lib/clean/apps.sh:orphan_detection()` +#### New Language Ecosystem Support (v1.19.1+) + +Added support for Elixir, Haskell, OCaml, and Editors (VS Code, Zed) with strict safety checks: + +- **Existence Checks:** Cleanup logic only runs if the tool is installed (directory exists). +- **Safe Targets:** Only volatile caches are cleaned (e.g., `~/.hex/cache`). +- **Protected Paths:** Critical directories like `~/.mix/archives` (installed tools) and `~/.stack/programs` (installed compilers) are explicitly **excluded**. + #### Active Uninstallation Heuristics For user-selected app removal: diff --git a/lib/clean/dev.sh b/lib/clean/dev.sh index 3b54bf0..fb703a9 100644 --- a/lib/clean/dev.sh +++ b/lib/clean/dev.sh @@ -257,24 +257,34 @@ clean_sqlite_temp_files() { } # Elixir/Erlang ecosystem. clean_dev_elixir() { - safe_clean ~/.mix/archives/* "Mix cache" - safe_clean ~/.hex/cache/* "Hex cache" + if [[ -d ~/.mix ]] || [[ -d ~/.hex ]]; then + # safe_clean ~/.mix/archives/* "Mix cache" + safe_clean ~/.hex/cache/* "Hex cache" + fi } # Haskell ecosystem. clean_dev_haskell() { - safe_clean ~/.cabal/packages/* "Cabal install cache" - safe_clean ~/.stack/programs/* "Stack cache" + if [[ -d ~/.cabal ]] || [[ -d ~/.stack ]]; then + safe_clean ~/.cabal/packages/* "Cabal install cache" + # safe_clean ~/.stack/programs/* "Stack cache" + fi } # OCaml ecosystem. clean_dev_ocaml() { - safe_clean ~/.opam/download-cache/* "Opam cache" + if [[ -d ~/.opam ]]; then + safe_clean ~/.opam/download-cache/* "Opam cache" + fi } # Editor caches. clean_dev_editors() { - safe_clean ~/Library/Caches/com.microsoft.VSCode/Cache/* "VS Code cached data" - safe_clean ~/Library/Application\ Support/Code/CachedData/* "VS Code cached data" - safe_clean ~/Library/Application\ Support/Code/User/workspaceStorage/* "VS Code workspace storage" - safe_clean ~/Library/Caches/Zed/* "Zed cache" + if [[ -d ~/Library/Caches/com.microsoft.VSCode ]] || [[ -d ~/Library/Application\ Support/Code ]]; then + safe_clean ~/Library/Caches/com.microsoft.VSCode/Cache/* "VS Code cached data" + safe_clean ~/Library/Application\ Support/Code/CachedData/* "VS Code cached data" + # safe_clean ~/Library/Application\ Support/Code/User/workspaceStorage/* "VS Code workspace storage" + fi + if [[ -d ~/Library/Caches/Zed ]]; then + safe_clean ~/Library/Caches/Zed/* "Zed cache" + fi } # Main developer tools cleanup sequence. clean_developer_tools() { diff --git a/tests/dev_extended.bats b/tests/dev_extended.bats index 67b854d..abf87c0 100644 --- a/tests/dev_extended.bats +++ b/tests/dev_extended.bats @@ -21,6 +21,7 @@ teardown_file() { } @test "clean_dev_elixir cleans mix and hex caches" { + mkdir -p "$HOME/.mix" "$HOME/.hex" run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' set -euo pipefail source "$PROJECT_ROOT/lib/core/common.sh" @@ -30,11 +31,12 @@ clean_dev_elixir EOF [ "$status" -eq 0 ] - [[ "$output" == *"Mix cache"* ]] + [[ "$output" == *"Hex cache"* ]] } @test "clean_dev_haskell cleans cabal install and stack caches" { + mkdir -p "$HOME/.cabal" "$HOME/.stack" run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' set -euo pipefail source "$PROJECT_ROOT/lib/core/common.sh" @@ -45,10 +47,11 @@ EOF [ "$status" -eq 0 ] [[ "$output" == *"Cabal install cache"* ]] - [[ "$output" == *"Stack cache"* ]] + } @test "clean_dev_ocaml cleans opam cache" { + mkdir -p "$HOME/.opam" run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' set -euo pipefail source "$PROJECT_ROOT/lib/core/common.sh" @@ -62,6 +65,7 @@ EOF } @test "clean_dev_editors cleans VS Code and Zed caches" { + mkdir -p "$HOME/Library/Caches/com.microsoft.VSCode" "$HOME/Library/Application Support/Code" "$HOME/Library/Caches/Zed" run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF' set -euo pipefail source "$PROJECT_ROOT/lib/core/common.sh" @@ -72,6 +76,6 @@ EOF [ "$status" -eq 0 ] [[ "$output" == *"VS Code cached data"* ]] - [[ "$output" == *"VS Code workspace storage"* ]] + [[ "$output" == *"Zed cache"* ]] }