1
0
mirror of https://github.com/tw93/Mole.git synced 2026-03-22 20:50:06 +00:00

clean orphaned Claude VM bundle

Fixes #537
This commit is contained in:
Tw93
2026-03-06 07:34:24 +08:00
parent 423c424f52
commit 7e69a4eb71
2 changed files with 133 additions and 1 deletions

View File

@@ -244,6 +244,44 @@ is_bundle_orphaned() {
# All checks passed - this is an orphan
return 0
}
is_claude_vm_bundle_orphaned() {
local vm_bundle_path="$1"
local installed_bundles="$2"
local claude_bundle_id="com.anthropic.claudefordesktop"
[[ -d "$vm_bundle_path" ]] || return 1
# Extra guard in case the running-app scan missed Claude Desktop.
if pgrep -x "Claude" > /dev/null 2>&1; then
return 1
fi
if grep -Fxq "$claude_bundle_id" "$installed_bundles" 2> /dev/null; then
return 1
fi
if [[ -z "$ORPHAN_MDFIND_CACHE_FILE" ]]; then
ORPHAN_MDFIND_CACHE_FILE=$(mktemp "${TMPDIR:-/tmp}/mole_mdfind_cache.XXXXXX")
register_temp_file "$ORPHAN_MDFIND_CACHE_FILE"
fi
if grep -Fxq "FOUND:$claude_bundle_id" "$ORPHAN_MDFIND_CACHE_FILE" 2> /dev/null; then
return 1
fi
if ! grep -Fxq "NOTFOUND:$claude_bundle_id" "$ORPHAN_MDFIND_CACHE_FILE" 2> /dev/null; then
local app_exists
app_exists=$(run_with_timeout 2 mdfind "kMDItemCFBundleIdentifier == '$claude_bundle_id'" 2> /dev/null | head -1 || echo "")
if [[ -n "$app_exists" ]]; then
echo "FOUND:$claude_bundle_id" >> "$ORPHAN_MDFIND_CACHE_FILE"
return 1
fi
echo "NOTFOUND:$claude_bundle_id" >> "$ORPHAN_MDFIND_CACHE_FILE"
fi
return 0
}
# Orphaned app data sweep.
clean_orphaned_app_data() {
if ! ls "$HOME/Library/Caches" > /dev/null 2>&1; then
@@ -260,6 +298,19 @@ clean_orphaned_app_data() {
local orphaned_count=0
local total_orphaned_kb=0
start_section_spinner "Scanning orphaned app resources..."
local claude_vm_bundle="$HOME/Library/Application Support/Claude/vm_bundles/claudevm.bundle"
if is_claude_vm_bundle_orphaned "$claude_vm_bundle" "$installed_bundles"; then
local claude_vm_size_kb
claude_vm_size_kb=$(get_path_size_kb "$claude_vm_bundle")
if [[ -n "$claude_vm_size_kb" && "$claude_vm_size_kb" != "0" ]]; then
if safe_clean "$claude_vm_bundle" "Orphaned Claude workspace VM"; then
orphaned_count=$((orphaned_count + 1))
total_orphaned_kb=$((total_orphaned_kb + claude_vm_size_kb))
fi
fi
fi
# CRITICAL: NEVER add LaunchAgents or LaunchDaemons (breaks login items/startup apps).
local -a resource_types=(
"$HOME/Library/Caches|Caches|com.*:org.*:net.*:io.*"
@@ -269,7 +320,6 @@ clean_orphaned_app_data() {
"$HOME/Library/HTTPStorages|HTTP|com.*:org.*:net.*:io.*"
"$HOME/Library/Cookies|Cookies|*.binarycookies"
)
orphaned_count=0
for resource_type in "${resource_types[@]}"; do
IFS='|' read -r base_path label patterns <<< "$resource_type"
if [[ ! -d "$base_path" ]]; then