Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Select nothing on Developer, Build Artifacts, and Space until you do

Țugui Dragoșe81f0dbb3c2d
diff --git a/GUIDE.md b/GUIDE.md
index 3daa7971..4df8d70e 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -52,10 +52,11 @@ and how to get it, [SAFETY.md](SAFETY.md) what it protects, [PRIVACY.md](PRIVACY
Space shows what fills your disk, area by area, and what each area is.
- **Orphaned Files:** files left behind by apps you already removed.
-- **Developer:** caches of developer tools, editors, browsers, and AI models. What you may want again is listed but
- never selected for you, and toolchains or anything holding an account are never listed.
+- **Developer:** caches of developer tools, editors, browsers, and AI models. Nothing is selected for you, and Select
+ Recommended passes by what you may want again; toolchains or anything holding an account are never listed.
- **Build Artifacts:** what builds left in your projects, like `node_modules`, `DerivedData`, or `target`, each only
- when its tool's own file proves it. A project changed in the last 7 days is never selected for you.
+ when its tool's own file proves it. Nothing is selected for you, and Select Recommended passes by a project
+ changed in the last 7 days.
- **Duplicates:** files and whole folders with identical contents, compared with SHA-256. One copy is always kept.
Files under 100 KB, and folders holding less, are left out unless you choose a smaller size, in the app and in
`peel duplicates` alike.
@@ -83,15 +84,15 @@ on Electron, such as Slack or Discord (never what a browser or an app keeps for
Playwright run left in the temporary folder when it ended early, never one a browser still has open. Xcode's
archives and the symbols it copied from your devices, model weights, installed packages, what a tool keeps for you
to install again (Vagrant boxes, Asset Store packages, Godot's export templates), an editor's saved state for each
-project it opened, and a cache with a wallet, a signing key, or a password database inside are listed but never
-selected for you, and toolchains or anything holding an account are never listed.
+project it opened, and a cache with a wallet, a signing key, or a password database inside are listed, and Select
+Recommended passes them by; toolchains or anything holding an account are never listed. Nothing is selected for you.
**Build Artifacts:** what builds left in the folders you choose, like `node_modules`, `DerivedData`, `target`,
`.nuxt`, `__pycache__`, Unity's `Library`, and any folder its tool tagged as a cache (`CACHEDIR.TAG`), each only
-when a file of the tool that makes it proves it. A project changed in the last 7 days is never selected for you, and
-neither are installed packages (a Python environment, `vendor`, Terraform's `.terraform`) or a folder like `target`
-whose name says nothing on its own. Until you choose a folder, Peel offers `~/Developer`, `~/Projects`, `~/Code`,
-or `~/src` when you have one, and adds it only when you say so.
+when a file of the tool that makes it proves it. Nothing is selected for you, and Select Recommended passes by a
+project changed in the last 7 days, installed packages (a Python environment, `vendor`, Terraform's `.terraform`),
+and a folder like `target` whose name says nothing on its own. Until you choose a folder, Peel offers `~/Developer`,
+`~/Projects`, `~/Code`, or `~/src` when you have one, and adds it only when you say so.
**Space:** what's taking up room, and which app it belongs to. What an app manages itself, such as Xcode's
simulators, Docker's disk, Rust's toolchains, or Android's NDK versions, Space measures and leaves to that tool,
@@ -99,7 +100,8 @@ with the command that frees it, when there is one, for you to copy into Terminal
deletes for good. The caches and logs apps keep for every account, and the crash reports macOS keeps, in the
Library at the top of the disk, go through Peel's helper when an administrator owns them, and what macOS keeps
there for its own services is never listed. Peel can also warn you, with a notification that opens Space, when
-less than a tenth of your disk is available: turn it on in Settings > General.
+less than a tenth of your disk is available: turn it on in Settings > General. Nothing is selected for you: Select
+Recommended takes what Peel could measure in an area and nothing holds back.
</details>
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index 75927d4d..af3310bd 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -79,8 +79,8 @@ public struct DeveloperEnvironment: Sendable, Hashable, Identifiable {
size == nil || !isTheTools || workspace?.mayStillBeInUse == true || heldBack != nil || kind == .archives
}
- /// Whether Peel selects this location for the user: only content that tools make or fetch again, or
- /// logs, and only once measured. Nothing is selected for the user without showing its size.
+ /// Whether Peel recommends this location, which Select Recommended selects and `peel caches --remove` moves:
+ /// only content that tools make or fetch again, or logs, and only once measured.
public var isRecommended: Bool {
guard isTheTools, workspace?.mayStillBeInUse != true, heldBack == nil else { return false }
return switch kind {
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift b/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift
index 6e53763a..30271713 100644
--- a/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Removal/CarriedSelection.swift
@@ -1,9 +1,8 @@
public import Foundation
/// What is selected on the pages of the storage tools, and what of it moves when Move to Trash is pressed on any
-/// of them: each page the person has seen, one part to a page. A tool can select for the person on pages they
-/// never opened (Developer selects the caches it recommends in every tool it lists), and what was never seen must
-/// never be moved from another page, so a page counts only once it has been on screen.
+/// of them: each page the person has seen, one part to a page. What was never seen must never be moved from
+/// another page, so a page counts only once it has been on screen.
public struct CarriedSelection: Sendable {
/// One page of a tool: `tool` names the tool, and `scope` the page within it, such as a developer tool, a
/// project, or a kind of installer. It is empty for a tool that is one page.
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
index 6d49b62f..21b8d6f0 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceRemoval.swift
@@ -31,7 +31,8 @@ public enum SpaceRemoval {
Set(inUse.map(\.name)).sorted()
}
- /// What Peel selects of this plan for the person: every item it could measure that nothing holds back.
+ /// What Peel recommends of this plan, which Select Recommended selects: every item it could measure that
+ /// nothing holds back.
public var suggested: Set<URL> {
Set(sizes.keys).subtracting(heldBack.keys)
}
@@ -41,15 +42,10 @@ public enum SpaceRemoval {
needsTheHelper.contains(url) && heldBack[url]?.cannotBeMoved != true && !canUseHelper
}
- /// What stays selected in the area as the plan is made again or the helper comes or goes: a child that waits
- /// for the helper is offered and suggested only while the helper can act.
- public func selection(
- keeping selected: Set<URL>,
- in choices: inout KeptSelection,
- canUseHelper: Bool
- ) -> Set<URL> {
- let rows = selectableRows(canUseHelper: canUseHelper)
- return choices.update(selected, selectable: Set(rows.selectable), suggested: Set(rows.recommended))
+ /// What stays selected in the area as the plan is made again or the helper comes or goes: what the person
+ /// chose that can still be selected. Nothing is selected for them.
+ public func selection(keeping selected: Set<URL>, canUseHelper: Bool) -> Set<URL> {
+ selected.intersection(selectableRows(canUseHelper: canUseHelper).selectable)
}
public func selectableRows(canUseHelper: Bool) -> SelectableRows<URL> {
diff --git a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
index d7645331..0428a83a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Space/SpaceReport.swift
@@ -26,7 +26,7 @@ public struct SpaceItem: Sendable, Hashable, Identifiable {
/// Nil when measuring one of its folders ran out of time or was refused. Unknown is not the same as empty.
public let size: Int64?
public let handling: Handling
- /// Why nothing in this area is selected for the person, whatever each item holds.
+ /// Why nothing in this area is recommended, whatever each item holds.
public var heldBack: HoldBack?
/// True when what macOS keeps in its folders for its own services is neither measured nor offered: there they run
/// as other accounts, whose open files Peel cannot see, or keep caches not even Full Disk Access can read.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
index f478cc1f..a4b301be 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/SpaceRemovalTests.swift
@@ -251,11 +251,12 @@ struct SpaceRemovalTests {
let plan = await SpaceRemoval.plan(for: shared, environment: environment(directory), running: [:])
let updater = try #require(plan.removable.first)
- var choices = KeptSelection()
#expect(plan.needsTheHelper == [updater])
- #expect(plan.selection(keeping: [], in: &choices, canUseHelper: false).isEmpty)
- #expect(plan.selection(keeping: [], in: &choices, canUseHelper: true) == [updater])
+ #expect(plan.selection(keeping: [updater], canUseHelper: false).isEmpty)
+ #expect(plan.selection(keeping: [updater], canUseHelper: true) == [updater])
+ #expect(plan.selectableRows(canUseHelper: false).recommended.isEmpty)
+ #expect(plan.selectableRows(canUseHelper: true).recommended == [updater])
}
@Test func emptiesAContainersCachesUnlessItsAppIsOpenOrApples() async throws {
@@ -579,10 +580,8 @@ struct SpaceRemovalTests {
#expect(running.withLock { $0.most } == LeftoverScanner.concurrentMeasurements)
}
- /// An area's plan is made again when the disk changes, and what the person chose in it stays chosen: a child
- /// that was already there keeps its checkbox as it was, one new to the area is selected when its size is
- /// known, as every child is in the area's first plan, and one that went is no longer selected. A child Peel
- /// selected whose size can no longer be measured is no longer selected either.
+ /// An area's plan is made again when the disk changes: what the person chose stays chosen while it is still
+ /// there, and nothing is selected for them, in the first plan or among the children new to the area.
@Test func aPlanMadeAgainKeepsWhatThePersonChose() {
let caches = URL(filePath: "/Users/x/Library/Caches", directoryHint: .isDirectory)
let (kept, deselected, chosenByHand, unmeasured, new, gone, noLongerMeasured) = (
@@ -596,12 +595,7 @@ struct SpaceRemovalTests {
leftToDeveloper: [],
sizes: [kept: 1, deselected: 2, gone: 5, noLongerMeasured: 7]
)
- var choices = KeptSelection()
- #expect(
- first.selection(keeping: [], in: &choices, canUseHelper: true) == [
- kept, deselected, gone, noLongerMeasured,
- ]
- )
+ #expect(first.selection(keeping: [], canUseHelper: true).isEmpty)
let again = SpaceRemoval.Plan(
removable: [kept, deselected, chosenByHand, unmeasured, new, noLongerMeasured],
@@ -610,14 +604,21 @@ struct SpaceRemovalTests {
sizes: [kept: 1, deselected: 2, chosenByHand: 3, unmeasured: 4, new: 6]
)
let selected: Set = [kept, chosenByHand, gone, noLongerMeasured]
- #expect(
- again.selection(keeping: selected, in: &choices, canUseHelper: true) == [
- kept, chosenByHand, new,
- ]
+ #expect(again.selection(keeping: selected, canUseHelper: true) == [kept, chosenByHand, noLongerMeasured])
+ }
+
+ @Test func anAreaSelectsNothingUntilThePersonDoes() {
+ let caches = URL(filePath: "/Users/x/Library/Caches", directoryHint: .isDirectory)
+ let (measured, chosen) = (caches.appending(path: "com.a"), caches.appending(path: "com.b"))
+ let plan = SpaceRemoval.Plan(
+ removable: [measured, chosen], inUse: [], leftToDeveloper: [], sizes: [measured: 1, chosen: 2]
)
+ #expect(plan.selection(keeping: [], canUseHelper: true).isEmpty)
+ #expect(plan.selection(keeping: [chosen], canUseHelper: true) == [chosen])
+ #expect(Set(plan.selectableRows(canUseHelper: true).recommended) == [measured, chosen])
}
- @Test func aChildThatWaitsForTheHelperIsSelectedOnlyOnceTheHelperCanAct() {
+ @Test func aChildThatWaitsForTheHelperCanBeSelectedOnlyOnceTheHelperCanAct() {
let caches = URL(filePath: "/Library/Caches", directoryHint: .isDirectory)
let vendor = caches.appending(path: "org.example.Vendor")
let system = caches.appending(path: "org.example.System")
@@ -625,9 +626,7 @@ struct SpaceRemovalTests {
removable: [vendor, system], inUse: [], leftToDeveloper: [], sizes: [vendor: 1, system: 2],
needsTheHelper: [system]
)
- var choices = KeptSelection()
-
- #expect(plan.selection(keeping: [], in: &choices, canUseHelper: false) == [vendor])
- #expect(plan.selection(keeping: [vendor], in: &choices, canUseHelper: true) == [vendor, system])
+ #expect(plan.selection(keeping: [vendor, system], canUseHelper: false) == [vendor])
+ #expect(plan.selection(keeping: [vendor, system], canUseHelper: true) == [vendor, system])
}
}
diff --git a/Peel/Model/DeveloperLibrary.swift b/Peel/Model/DeveloperLibrary.swift
index 12dee553..686a02d1 100644
--- a/Peel/Model/DeveloperLibrary.swift
+++ b/Peel/Model/DeveloperLibrary.swift
@@ -11,7 +11,6 @@ final class DeveloperLibrary {
private(set) var isRemoving = false
var selection: DeveloperEnvironment.ID?
var selectedURLs: Set<URL> = []
- private var choices = KeptSelection()
var selectedEnvironment: DeveloperEnvironment? {
environments?.first { $0.id == selection }
@@ -24,12 +23,7 @@ final class DeveloperLibrary {
})
else { return }
environments = result
- let locations = result.flatMap(\.locations)
- selectedURLs = choices.update(
- selectedURLs,
- selectable: Set(locations.map(\.url)),
- suggested: Set(locations.filter(\.isRecommended).map(\.url))
- )
+ selectedURLs.formIntersection(Set(result.flatMap(\.locations).map(\.url)))
if let selection, !result.contains(where: { $0.id == selection }) {
self.selection = nil
}
diff --git a/Peel/Model/ProjectLibrary.swift b/Peel/Model/ProjectLibrary.swift
index be8a7436..df400e49 100644
--- a/Peel/Model/ProjectLibrary.swift
+++ b/Peel/Model/ProjectLibrary.swift
@@ -40,7 +40,6 @@ final class ProjectLibrary {
private(set) var refused: [(url: URL, reason: ProjectArtifacts.Refusal)] = []
var selection: URL?
var selectedURLs: Set<URL> = []
- private var choices = KeptSelection()
init() {
folders = (UserDefaults.standard.array(forKey: Self.foldersKey) as? [String] ?? [])
@@ -74,11 +73,7 @@ final class ProjectLibrary {
groups = result
excludedFromBackups = Set(standings.filter { $0.value != .included }.keys)
excludedFromAbove = Set(standings.filter { $0.value == .excludedFromAbove }.keys)
- selectedURLs = choices.update(
- selectedURLs,
- selectable: Set(artifacts.map(\.url)),
- suggested: Set(artifacts.filter(\.isRecommended).map(\.url))
- )
+ selectedURLs.formIntersection(Set(artifacts.map(\.url)))
if let selection, !result.contains(where: { $0.project == selection }) {
self.selection = nil
}
diff --git a/Peel/Model/SpaceLibrary.swift b/Peel/Model/SpaceLibrary.swift
index 3feb6e6b..60ab238d 100644
--- a/Peel/Model/SpaceLibrary.swift
+++ b/Peel/Model/SpaceLibrary.swift
@@ -16,8 +16,6 @@ final class SpaceLibrary: RowSelection {
private(set) var plans: [SpaceItem.ID: SpaceRemoval.Plan] = [:]
/// The area as it was, and the exclusions' revision, when its plan was made.
@ObservationIgnored private var plannedFor: [SpaceItem.ID: (item: SpaceItem, exclusions: Int)] = [:]
- /// What was chosen in each area, kept through its plans.
- @ObservationIgnored private var choices: [SpaceItem.ID: KeptSelection] = [:]
@ObservationIgnored private var canUseHelper = false
var selectedItem: SpaceItem? {
@@ -48,11 +46,7 @@ final class SpaceLibrary: RowSelection {
private func keep(_ plan: SpaceRemoval.Plan, for item: SpaceItem, madeWith revision: Int) {
let previous = plans[item.id]
- let chosen = plan.selection(
- keeping: selectedURLs,
- in: &choices[item.id, default: KeptSelection()],
- canUseHelper: canUseHelper
- )
+ let chosen = plan.selection(keeping: selectedURLs, canUseHelper: canUseHelper)
selectedURLs.subtract(previous?.removable ?? [])
selectedURLs.formUnion(chosen)
plans[item.id] = plan
@@ -83,12 +77,8 @@ final class SpaceLibrary: RowSelection {
func follow(canUseHelper: Bool) {
guard canUseHelper != self.canUseHelper else { return }
self.canUseHelper = canUseHelper
- for (id, plan) in plans {
- let chosen = plan.selection(
- keeping: selectedURLs,
- in: &choices[id, default: KeptSelection()],
- canUseHelper: canUseHelper
- )
+ for plan in plans.values {
+ let chosen = plan.selection(keeping: selectedURLs, canUseHelper: canUseHelper)
selectedURLs.subtract(plan.removable)
selectedURLs.formUnion(chosen)
}
@@ -117,7 +107,6 @@ final class SpaceLibrary: RowSelection {
selectedURLs.subtract(plans[id]?.removable ?? [])
plans[id] = nil
plannedFor[id] = nil
- choices[id] = nil
}
if let selection, !result.items.contains(where: { $0.id == selection }) {
self.selection = nil
diff --git a/SAFETY.md b/SAFETY.md
index 5f9f018e..805740ee 100644
--- a/SAFETY.md
+++ b/SAFETY.md
@@ -255,13 +255,16 @@ packages Xcode checks out into DerivedData or the clones Cargo and Swift Package
again when it needs them. Of Carthage's folder in a project, only `Carthage/Build`, which `carthage build` makes, is
offered: its checkouts, which people commit in, carry no such tag and are never listed.
-Build Artifacts selects what a build or a package manager makes again from the project's own files, such as
+Build Artifacts recommends what a build or a package manager makes again from the project's own files, such as
`DerivedData`, `.build`, and `.next`, once Peel can tell that nothing in the project has changed for a week. That
includes `node_modules` and `Pods`, which `npm install` and `pod install` put back from the project's `package.json` and
`Podfile`. A Python environment (`.venv`, `venv`) is listed and never selected, since packages are often installed into
one by hand, and so is Terraform's `.terraform`, which keeps the workspace you chose. A folder whose name says nothing
on its own, such as `target` or `build`, is listed and never selected either.
+Developer, Build Artifacts, Space, and Installers and Backups select nothing for you: opening a page selects nothing,
+and Select Recommended selects what Peel recommends there.
+
Orphaned Files selects nothing for you, and `peel orphans --remove` leaves these folders out as well: one in
`/Users/Shared`, one with a repository, a wallet, a signing key, or a password database inside, one that may hold what
exists only on this Mac, or one Peel could not read or measure in time, moves only when you select it yourself.
@@ -276,8 +279,7 @@ they only count toward the folder around them.
What you select on the pages that free space (Orphaned Files, Space, Developer, Build Artifacts, Installers and
Backups, Duplicates, and File Search) stays selected while you look at the others, and Move to Trash on any of
-them moves all of it. Only a page you have opened counts: Developer and Build Artifacts select for you in every
-tool and project they list, and what they selected on a page you never saw stays where it is. Before anything
+them moves all of it. Only a page you have opened counts, so nothing moves from a page you never saw. Before anything
moves, the question lists every page with how much it holds, and each page's part is moved by its own tool, with
that tool's checks at that moment: Developer waits for its app to quit, Space leaves out what an app opened since
is writing to, and Duplicates refuses a copy that changed. What a tool refuses for the item itself, such as a folder