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.

Uninstalling an app lists the crash reports macOS wrote for it

Țugui Dragoș5434e817e874
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index cc29875e..4b35c052 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -68217,6 +68217,112 @@
}
}
},
+ "Not selected: a report macOS wrote when the app crashed, which its developer may still ask you for." : {
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nevybráno: zpráva, kterou systém macOS zapsal při havárii aplikace a o kterou vás výrobce aplikace může ještě požádat."
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nicht ausgewählt: Ein Absturzbericht, den macOS geschrieben hat, als die App unerwartet beendet wurde, und den ihr Hersteller möglicherweise noch von dir anfordert."
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sin seleccionar: un informe de errores que macOS creó cuando la app se cerró inesperadamente, y que su desarrollador todavía puede pedirte."
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non sélectionné : un rapport de blocage que macOS a écrit lorsque l’app s’est fermée de manière inattendue, et que son développeur peut encore vous demander."
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Non selezionato: un resoconto che macOS ha scritto quando l’app si è chiusa inaspettatamente, e che la sua azienda di sviluppo potrebbe ancora chiederti."
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選択: アプリが予期しない理由で終了したときにmacOSが作成したクラッシュレポートで、開発元から提出を求められる可能性があります。"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "선택되지 않음: 앱이 충돌했을 때 macOS가 작성한 리포트로, 앱 제작자가 여전히 사용자에게 요청할 수 있습니다."
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Niet geselecteerd: een rapport dat macOS heeft geschreven toen de app crashte, en waar de maker je misschien nog om vraagt."
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Nie zaznaczono: raport, który macOS zapisał po awarii aplikacji, a o który jej producent może jeszcze Cię poprosić."
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Não selecionado: um relatório que o macOS criou quando o app falhou, e que o fabricante ainda pode pedir a você."
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Neselectat: un raport scris de macOS când aplicația s‑a oprit subit, pe care producătorul acesteia vi‑l mai poate cere."
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не выбрано: отчет, который macOS записала при сбое приложения и который производитель приложения может еще попросить у Вас."
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Inte markerad: en rapport som macOS skrev när appen kraschade, och som appens utvecklare kanske fortfarande ber dig om."
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Seçilmedi: uygulama çöktüğünde macOS’in yazdığı bir rapor; geliştiricisi bunu sizden hâlâ isteyebilir."
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Не вибрано: звіт, створений macOS під час аварійного завершення програми, який її розробник ще може у вас попросити."
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未选择:这是macOS在App崩溃时写下的报告,App的厂商可能仍会向你索要。"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "未選取:這是macOS在App當機時寫下的報告,App的廠商可能仍會向你索取。"
+ }
+ }
+ }
+ },
"Not selected: a wallet or a signing key is inside. Once the Trash is emptied, what it opens is gone for good unless you have a backup." : {
"localizations" : {
"cs" : {
diff --git a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
index a73b76cf..fc1e66ab 100644
--- a/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
+++ b/Packages/PeelCore/Sources/PeelCommandLine/Support/Output.swift
@@ -273,6 +273,7 @@ extension HoldBack {
case .beyondTheHelper: "needs an administrator, and Peel's helper may not move it"
case .keptByMacOS: "a cache macOS keeps for itself"
case .openedFromMail: "an attachment opened from Mail, which may be the only copy"
+ case .crashReport: "a crash report, which the app's developer may still ask for"
}
}
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/CrashReport.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/CrashReport.swift
new file mode 100644
index 00000000..a6f4231f
--- /dev/null
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/CrashReport.swift
@@ -0,0 +1,23 @@
+import Foundation
+
+/// A report macOS writes in a `DiagnosticReports` folder when a process crashes, named for the process and the time.
+/// Its first line is metadata whose `bundleID` is the bundle the report applies to (Apple's "Interpreting the JSON
+/// format of a crash report"), which is what says whose it is.
+enum CrashReport {
+ /// A report can be megabytes, and only the metadata on its first line is read.
+ private static let metadataLimit = 16 * 1_024
+
+ /// True for an `.ips` file in a `DiagnosticReports` folder or in the `Retired` folder inside one.
+ static func isOne(_ url: URL) -> Bool {
+ guard url.pathExtension == "ips" else { return false }
+ let folders = url.deletingLastPathComponent().pathComponents
+ return folders.last == "DiagnosticReports" || folders.suffix(2) == ["DiagnosticReports", "Retired"]
+ }
+
+ static func bundleIdentifier(of url: URL) -> String? {
+ guard isOne(url), let start = BoundedRead.prefix(of: url, count: metadataLimit) else { return nil }
+ let line = start.prefix { $0 != UInt8(ascii: "\n") }
+ let metadata = try? JSONSerialization.jsonObject(with: line) as? [String: Any]
+ return metadata?["bundleID"] as? String
+ }
+}
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/DeclaredIdentifier.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/DeclaredIdentifier.swift
index 766ea3b4..228e5584 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/DeclaredIdentifier.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/DeclaredIdentifier.swift
@@ -1,17 +1,23 @@
import Foundation
/// The identifier an item declares about itself, for when its file name matches nothing: a plug-in is named for
-/// what it does rather than for who made it, and a container is sometimes named by a UUID. The identifier is
-/// only a claim, so it goes through the same matching as a file name.
+/// what it does rather than for who made it, a crash report for the process and the time, and a container is
+/// sometimes named by a UUID. The identifier is only a claim, so it goes through the same matching as a file name.
enum DeclaredIdentifier {
static func of(_ url: URL, kind: SearchLocation.Kind) -> String? {
switch kind {
case .plugIns: Plugins.declaredIdentifier(at: url)
case .containers: container(at: url)
+ case .logs: CrashReport.bundleIdentifier(of: url)
default: nil
}
}
+ /// True for an item whose name never says whose it is, so what it declares is read even when the name matches.
+ static func outranksTheName(of url: URL, kind: SearchLocation.Kind) -> Bool {
+ kind == .plugIns || (kind == .logs && CrashReport.isOne(url))
+ }
+
/// The `MCMMetadataIdentifier` in a container's metadata, read only when the folder's name is not already an
/// identifier. On macOS 26, a container whose name is an identifier is named after that value, so reading
/// the file would add nothing.
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
index 0cc75588..86aab0d8 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/Leftover.swift
@@ -63,6 +63,8 @@ public enum HoldBack: String, Sendable, Hashable {
case keptByMacOS
/// A copy Mail keeps of an attachment that was opened. One that was edited may exist nowhere else.
case openedFromMail
+ /// A report macOS wrote when the app crashed, which its developer may still ask for.
+ case crashReport
/// True when the item cannot be selected at all, rather than only left unselected.
public var cannotBeMoved: Bool {
diff --git a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
index ae5986b8..5377033a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Leftovers/LeftoverScanner.swift
@@ -279,7 +279,7 @@ public struct LeftoverScanner: Sendable {
} else if contents?.couldNotBeRead == true {
.couldNotBeRead
} else if let contents {
- heldBack(match, in: kind, contents: contents, isInsideAnotherAppsFolder: isInsideAnotherAppsFolder)
+ heldBack(match, at: url, in: kind, contents: contents, isInsideAnotherAppsFolder: isInsideAnotherAppsFolder)
} else {
.notMeasured
}
@@ -303,6 +303,7 @@ public struct LeftoverScanner: Sendable {
/// unselected.
private static func heldBack(
_ match: LeftoverMatch,
+ at url: URL,
in kind: SearchLocation.Kind,
contents: FolderContents,
isInsideAnotherAppsFolder: Bool
@@ -311,6 +312,7 @@ public struct LeftoverScanner: Sendable {
// are. Holding it back costs a checkmark, and the row says what is inside.
if contents.holdsWallet { return .holdsAWallet }
if contents.holdsRepository { return .holdsRepository }
+ if kind == .logs, CrashReport.isOne(url) { return .crashReport }
if kind == .sharedFolder { return .sharedWithEveryone }
if Self.namedGroundOfSomebodyElse.contains(kind), match.restsOnAName { return .namedLikeTheApp }
// An identifier names the app wherever it sits. Its name, inside somebody else's folder, does not.
@@ -335,12 +337,12 @@ public struct LeftoverScanner: Sendable {
return byName?.confidence == .certain ? byName : inside
}
- /// This app's claim on an item from its name and from the identifier it declares, which is read for a plug-in
- /// and for an item whose name answers nothing. The identifier says who made a plug-in: a claim through it
- /// replaces a weaker one on the name, and a name it does not back makes the plug-in only possible.
+ /// This app's claim on an item from its name and from the identifier it declares, which is read for a plug-in, a
+ /// crash report, and an item whose name answers nothing. The identifier says whose such an item is: a claim
+ /// through it replaces a weaker one on the name, and a name it does not back makes the item only possible.
private static func match(_ name: String, at url: URL, kind: SearchLocation.Kind, matcher: LeftoverMatcher) -> LeftoverMatch? {
let byName = matcher.match(fileName: name, kind: kind, at: url)
- guard byName == nil || kind == .plugIns else { return byName }
+ guard byName == nil || DeclaredIdentifier.outranksTheName(of: url, kind: kind) else { return byName }
// `.elsewhere`, so no extension is taken off the identifier as if it were a file name.
let declared = DeclaredIdentifier.of(url, kind: kind).flatMap { matcher.match(fileName: $0, kind: .elsewhere, at: url) }
guard let byName else { return declared }
diff --git a/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift b/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift
index 68d3535b..2f62a60a 100644
--- a/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Support/BoundedRead.swift
@@ -35,6 +35,28 @@ enum BoundedRead {
return data.count <= maximum ? data : nil
}
+ /// The first `count` bytes of the regular file at `url`, or the whole file when it is shorter, whatever its size.
+ static func prefix(of url: URL, count: Int) -> Data? {
+ guard let descriptor = openRegularFile(at: url, maximum: .max) else { return nil }
+ defer { close(descriptor) }
+
+ var buffer = [UInt8](repeating: 0, count: count)
+ var filled = 0
+ while filled < count {
+ let read = buffer.withUnsafeMutableBytes { bytes in
+ Darwin.read(descriptor, bytes.baseAddress! + filled, count - filled)
+ }
+ if read > 0 {
+ filled += read
+ } else if read == 0 {
+ break
+ } else if errno != EINTR {
+ return nil
+ }
+ }
+ return Data(buffer[0..<filled])
+ }
+
/// Whether `url` opens as a regular file of at most `maximum` bytes, which is what `data(at:maximum:)` asks
/// before it reads.
static func opens(_ url: URL, maximum: Int = maximumBytes) -> Bool {
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeclaredIdentifierTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeclaredIdentifierTests.swift
index 8f81905c..5ef0c085 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeclaredIdentifierTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeclaredIdentifierTests.swift
@@ -30,4 +30,21 @@ struct DeclaredIdentifierTests {
#expect(DeclaredIdentifier.of(byUUID, kind: .containers) == "org.example.notes")
#expect(DeclaredIdentifier.of(byName, kind: .containers) == nil)
}
+
+ @Test func aCrashReportDeclaresTheBundleOnItsFirstLineHoweverLongItIs() throws {
+ let directory = try TemporaryDirectory()
+ let metadata = #"{"bug_type":"309","bundleID":"org.example.notes","name":"Notes Example"}"#
+ let body = String(repeating: "x", count: 2_000_000)
+ let contents = Data("\(metadata)\n\(body)".utf8)
+ let name = "Notes Example-2026-09-01-101010"
+ let report = try directory.file("Logs/DiagnosticReports/\(name).ips", contents: contents)
+ let loose = try directory.file("Logs/\(name).ips", contents: contents)
+ let text = try directory.file("Logs/DiagnosticReports/\(name).diag", contents: contents)
+
+ #expect(DeclaredIdentifier.of(report, kind: .logs) == "org.example.notes")
+ #expect(DeclaredIdentifier.outranksTheName(of: report, kind: .logs))
+ #expect(DeclaredIdentifier.of(loose, kind: .logs) == nil)
+ #expect(DeclaredIdentifier.of(text, kind: .logs) == nil)
+ #expect(!DeclaredIdentifier.outranksTheName(of: loose, kind: .logs))
+ }
}
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
index 4e05d131..397a119c 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/LeftoverScannerTests.swift
@@ -950,6 +950,32 @@ struct LeftoverScannerTests {
#expect(scan.leftovers.first?.match.confidence == .certain)
}
+ @Test func findsTheAppsCrashReportsByTheBundleTheyNameAndNeverSelectsThem() async throws {
+ let directory = try TemporaryDirectory()
+ let reports = "home/Library/Logs/DiagnosticReports"
+ let ours = report(bundleIdentifier: "net.example.client")
+ try directory.file("\(reports)/Tunewell-2026-09-01-101010.ips", contents: ours)
+ try directory.file("\(reports)/Retired/Tunewell-2026-08-01-090000.ips", contents: ours)
+ let another = report(bundleIdentifier: "org.example.tunewell")
+ try directory.file("\(reports)/Tunewell-2026-09-02-111111.ips", contents: another)
+
+ let scanner = LeftoverScanner(environment: environment(in: directory))
+ let scan = await scanner.scan(tunewell, installedApps: [tunewell])
+
+ #expect(scan.leftovers.map(\.url.lastPathComponent).sorted() == [
+ "Tunewell-2026-08-01-090000.ips", "Tunewell-2026-09-01-101010.ips",
+ ])
+ #expect(scan.leftovers.allSatisfy { $0.match.reason == .bundleIdentifier && $0.match.confidence == .certain })
+ #expect(scan.leftovers.allSatisfy { $0.match.heldBack == .crashReport })
+ }
+
+ private func report(bundleIdentifier: String) -> Data {
+ Data("""
+ {"app_name":"Tunewell","bug_type":"309","bundleID":"\(bundleIdentifier)","name":"Tunewell","incident_id":"1"}
+ {"procName":"Tunewell","exception":{"type":"EXC_CRASH"}}
+ """.utf8)
+ }
+
private func job(program: String) -> Data {
Data("""
<?xml version="1.0" encoding="UTF-8"?>
diff --git a/Peel/Views/Presentation.swift b/Peel/Views/Presentation.swift
index c0c8e4f0..b0a5c039 100644
--- a/Peel/Views/Presentation.swift
+++ b/Peel/Views/Presentation.swift
@@ -206,6 +206,8 @@ extension HoldBack {
"Not selected: macOS keeps this cache for its own services, which may be using it right now."
case .openedFromMail:
"Not selected: Mail keeps a copy here of each attachment you open, and one you edited may exist nowhere else."
+ case .crashReport:
+ "Not selected: a report macOS wrote when the app crashed, which its developer may still ask you for."
}
}
}