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.

Developer lists the older versions two command line tools keep

Țugui Dragoș10e17a62f415
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index ce3fb28e..fdd2a84d 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -134,11 +134,14 @@ public enum DeveloperCaches {
/// for there as well as at `path`, where an earlier Xcode may have left it.
let movedByXcodeSetting: String?
let base: Base
+ /// The links, relative to the home folder, a tool's installer puts on the path to the version it runs. When
+ /// set, the folder's rows are the versions it keeps beside that one (`olderVersions(in:home:)`).
+ let launchers: [String]
init(
_ path: String, _ kind: DeveloperEnvironment.ContentKind, source: String, storeInside: String? = nil,
rowsDepth: Int = 0, rowEnding: String? = nil, rowsAreDerivedData: Bool = false,
- movedByXcodeSetting: String? = nil, base: Base = .home
+ movedByXcodeSetting: String? = nil, base: Base = .home, launchers: [String] = []
) {
self.path = path
self.kind = kind
@@ -149,6 +152,35 @@ public enum DeveloperCaches {
self.rowsAreDerivedData = rowsAreDerivedData
self.movedByXcodeSetting = movedByXcodeSetting
self.base = base
+ self.launchers = launchers
+ }
+
+ /// The versions in `folder` beside the ones its launchers run, or none when a launcher is not the installer's
+ /// link into it: a launcher of the person's own may run any version, so none can be called old.
+ func olderVersions(in folder: URL, home: URL) -> [URL] {
+ let base = PathComponents.of(PathPattern.comparablePath(of: folder))
+ var running: Set<String> = []
+ for launcher in launchers {
+ let link = home.appending(path: launcher)
+ let path = link.path(percentEncoded: false)
+ guard let destination = try? FileManager.default.destinationOfSymbolicLink(atPath: path) else {
+ if link.isMissing { continue }
+ return []
+ }
+ let target = URL(filePath: destination, relativeTo: link.deletingLastPathComponent())
+ .standardizedFileURL
+ let names = PathComponents.of(PathPattern.comparablePath(of: target))
+ guard names.count > base.count, names.starts(with: base) else { return [] }
+ running.insert(names[base.count])
+ }
+ guard !running.isEmpty else { return [] }
+ let entries = (try? FileManager.default.contentsOfDirectory(
+ at: folder, includingPropertiesForKeys: [.isSymbolicLinkKey], options: [.skipsHiddenFiles]
+ )) ?? []
+ return entries.filter { entry in
+ (try? entry.resourceValues(forKeys: [.isSymbolicLinkKey]).isSymbolicLink) != true
+ }.map { folder.appending(path: $0.lastPathComponent) }
+ .filter { !running.contains(PathComponents.of(PathPattern.comparablePath(of: $0)).last ?? "") }
}
/// Where the folder is: at `path` in its base, and where the Xcode setting that moves it says.
@@ -700,6 +732,18 @@ public enum DeveloperCaches {
Folder(".local/state/nvim/lazy", .cache, source: "https://github.com/folke/lazy.nvim/blob/main/lua/lazy/core/config.lua#L220-L225"),
Folder(".local/state/nvim/logs", .logs, source: "https://github.com/neovim/neovim/blob/master/runtime/doc/starting.txt#L1409-L1410"),
]),
+ Definition(id: "claudecode", name: "Claude Code", systemImage: "terminal", appBundleIdentifiers: [], folders: [
+ Folder(
+ ".local/share/claude/versions", .environments,
+ source: "https://code.claude.com/docs/en/setup#auto-updates", launchers: [".local/bin/claude"]
+ ),
+ ]),
+ Definition(id: "cursoragent", name: "Cursor CLI", systemImage: "terminal", appBundleIdentifiers: [], folders: [
+ Folder(
+ ".local/share/cursor-agent/versions", .environments,
+ source: "https://cursor.com/install", launchers: [".local/bin/agent", ".local/bin/cursor-agent"]
+ ),
+ ]),
Definition(id: "opencode", name: "opencode", systemImage: "terminal", appBundleIdentifiers: [], folders: [
Folder(".cache/opencode", .cache, source: "https://github.com/anomalyco/opencode/blob/dev/packages/core/src/global.ts#L12"),
]),
@@ -997,7 +1041,11 @@ public enum DeveloperCaches {
let places = folder.places(
home: homeDirectory, userCache: userCacheDirectory, preference: preference
)
- for url in places.flatMap(folder.rows) {
+ let rows = places.flatMap { place in
+ folder.launchers.isEmpty
+ ? folder.rows(in: place) : folder.olderVersions(in: place, home: homeDirectory)
+ }
+ for url in rows {
guard !exclusions.excludes(url), !exclusions.holds(url) else { continue }
// Skips a folder that holds work kept nowhere else, such as the state Deno's
// scripts keep in `location_data`. Removing it would lose that work.
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index f1d837a9..2c6a01bd 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -373,6 +373,22 @@ struct DeveloperCachesTests {
let foldersOnly = concrete.hasSuffix("/")
let base = folder.base == .userCache ? "UserCache/" : ""
let entry = base + (foldersOnly ? String(concrete.dropLast()) : concrete)
+ // A folder of versions lists those beside the one its launchers run.
+ if !folder.launchers.isEmpty {
+ try directory.file("\(entry)/old/content", bytes: 400_000)
+ try directory.file("\(entry)/current/content", bytes: 400_000)
+ let current = directory.url.appending(path: "\(entry)/current").path(percentEncoded: false)
+ for launcher in folder.launchers {
+ try directory.directory((launcher as NSString).deletingLastPathComponent)
+ try FileManager.default.createSymbolicLink(
+ atPath: directory.url.appending(path: launcher).path(percentEncoded: false),
+ withDestinationPath: current
+ )
+ }
+ expected.insert("\(entry)/old")
+ try directory.file("\(entry)/../elsewhere-\(definition.id)/content", bytes: 400_000)
+ continue
+ }
let row = entry + (0..<folder.rowsDepth).map { "/row \($0)" }.joined() + (folder.rowEnding ?? "")
try directory.file("\(row)/content", bytes: 400_000)
expected.insert(row)
@@ -907,6 +923,45 @@ struct DeveloperCachesTests {
#expect(locations.first?.isRecommended == false)
}
+ @Test func listsTheVersionsANativeInstallKeptAndNeverTheOneItsLauncherRuns() async throws {
+ let directory = try TemporaryDirectory()
+ let claude = ".local/share/claude/versions"
+ let cursor = ".local/share/cursor-agent/versions"
+ try directory.file("\(claude)/2.1.200", bytes: 400_000)
+ try directory.file("\(claude)/2.1.211", bytes: 400_000)
+ try directory.file("\(cursor)/2026.09.20-a1b2c3d/cursor-agent", bytes: 400_000)
+ try directory.file("\(cursor)/2026.09.26-dd393fe/cursor-agent", bytes: 400_000)
+ try directory.directory(".local/bin")
+ let link = { (name: String, target: String) in
+ try FileManager.default.createSymbolicLink(
+ atPath: directory.url.appending(path: ".local/bin/\(name)").path(percentEncoded: false),
+ withDestinationPath: directory.url.appending(path: target).path(percentEncoded: false)
+ )
+ }
+ try link("claude", "\(claude)/2.1.211")
+ try link("agent", "\(cursor)/2026.09.26-dd393fe/cursor-agent")
+ try link("cursor-agent", "\(cursor)/2026.09.26-dd393fe/cursor-agent")
+ let tools = DeveloperCaches.definitions.filter { $0.folders.contains { !$0.launchers.isEmpty } }
+
+ let locations = await DeveloperCaches.scan(tools, homeDirectory: directory.url).flatMap(\.locations)
+
+ #expect(Set(locations.map(\.url.lastPathComponent)) == ["2.1.200", "2026.09.20-a1b2c3d"])
+ #expect(locations.allSatisfy { $0.kind == .environments && !$0.isRecommended })
+ }
+
+ @Test func aLauncherThatIsNotTheInstallersLinkKeepsEveryVersion() async throws {
+ let directory = try TemporaryDirectory()
+ try directory.file(".local/share/claude/versions/2.1.200", bytes: 400_000)
+ try directory.file(".local/share/claude/versions/2.1.211", bytes: 400_000)
+ let script = "#!/bin/sh\nexec ~/.local/share/claude/versions/2.1.200\n"
+ try directory.file(".local/bin/claude", contents: Data(script.utf8))
+ let tools = DeveloperCaches.definitions.filter { $0.folders.contains { !$0.launchers.isEmpty } }
+
+ let locations = await DeveloperCaches.scan(tools, homeDirectory: directory.url).flatMap(\.locations)
+
+ #expect(locations.isEmpty)
+ }
+
/// virtualenvwrapper keeps the user's hook scripts beside the environments in `~/.virtualenvs`, so only the
/// environments are offered, and a link among them is left where it is, never followed.
@Test func offersVirtualenvwrappersEnvironmentsAndNotItsHooks() async throws {