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.

Find Jan's models where its own setting moved its data folder

Țugui Dragoș341f8a168245
diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md
index 56e545d2..212ab96f 100644
--- a/ARCHITECTURE.md
+++ b/ARCHITECTURE.md
@@ -409,13 +409,13 @@ macOS asks the user to approve it once. It talks to the app over XPC.
a file in its repository at a commit, which the tests hold. Only what one tool owns outright is listed: no toolchain
or tool version in use, nothing holding an account or a token, and of a folder that keeps work beside a cache only
the cache. A folder a tool's configuration moved is found where it went (`Relocation`, read by `ToolSettings` from
- the file the tool's `config set` writes, or from Homebrew's `brew.env` files, never by running the tool), the apps
- built on Electron by a rule over the installed apps (`electronDefinitions`), and some folders are listed entry by
- entry: each workspace Xcode built in DerivedData, each archive, an editor's state for a project that is gone, and
- the versions an installer keeps beside the one it runs. `Location.isRecommended` is what Peel suggests: build data,
- downloads, caches, and logs, once measured and not held back (a secret inside, a clone of another repository, a
- recent write or a listening port where a server may still use it, a workspace that may still be in use), and
- `peel caches` gives each other row's reason by the same rule. Nothing moves while one of the tool's apps runs
+ the file the tool's `config set` or its own settings write, or from Homebrew's `brew.env` files, never by running
+ the tool), the apps built on Electron by a rule over the installed apps (`electronDefinitions`), and some folders are
+ listed entry by entry: each workspace Xcode built in DerivedData, each archive, an editor's state for a project that
+ is gone, and the versions an installer keeps beside the one it runs. `Location.isRecommended` is what Peel suggests:
+ build data, downloads, caches, and logs, once measured and not held back (a secret inside, a clone of another
+ repository, a recent write or a listening port where a server may still use it, a workspace that may still be in use),
+ and `peel caches` gives each other row's reason by the same rule. Nothing moves while one of the tool's apps runs
(`runningApp`), and a folder in the temporary folder that a program holds open isn't listed.
- **Background Items.** `BackgroundItems.scan` reads the job files in `~/Library/LaunchAgents`,
`/Library/LaunchAgents`, and `/Library/LaunchDaemons`, and asks launchd which jobs are loaded, in the GUI domain, the
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
index cfa26c99..f3ecd15f 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/DeveloperCaches.swift
@@ -1253,8 +1253,9 @@ public enum DeveloperCaches {
Folder(".cache/kagglehub", .models, source: "https://github.com/Kaggle/kagglehub/blob/4fe0a176e0e9b815ca4101c371b504ff97239b97/src/kagglehub/config.py#L17"),
]),
Definition(id: "jan", name: "Jan", systemImage: "brain", appBundleIdentifiers: ["jan.ai.app"], folders: [
- Folder("Library/Application Support/Jan/data/llamacpp/models", .models, source: "https://jan.ai/docs/desktop/data-folder"),
- Folder("Library/Application Support/Jan/data/mlx/models", .models, source: "https://jan.ai/docs/desktop/data-folder"),
+ Folder("Library/Application Support/Jan/data/llamacpp/models", .models, source: "https://jan.ai/docs/desktop/data-folder", movedBy: .janDataFolder(inside: "llamacpp/models")),
+ Folder("Library/Application Support/Jan/data/mlx/models", .models, source: "https://jan.ai/docs/desktop/data-folder", movedBy: .janDataFolder(inside: "mlx/models")),
+ // Not followed to a moved data folder: the person chose that folder, and a `logs` there may be theirs.
Folder("Library/Application Support/Jan/data/logs", .logs, source: "https://jan.ai/docs/desktop/data-folder"),
]),
Definition(id: "anythingllm", name: "AnythingLLM", systemImage: "brain", appBundleIdentifiers: [], folders: [
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swift b/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swift
index c435bb63..7e62dbce 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/Relocation.swift
@@ -21,6 +21,8 @@ extension DeveloperCaches {
/// Homebrew's cache, with the folders inside it named by a pattern such as `*_cache`. It counts only while it
/// holds the `api` folder Homebrew keeps its definitions in, since the setting can name any folder.
case homebrewCache(inside: String)
+ /// Jan's data folder, with the folder inside it.
+ case janDataFolder(inside: String)
/// Where the tool says which file holds the setting and where the setting puts the folder.
var sources: [String] {
@@ -58,6 +60,12 @@ extension DeveloperCaches {
"https://github.com/Homebrew/brew/blob/3073d6a8c34f71da054b000cfdbb62594a07c969/Library/Homebrew/startup/config.rb#L22",
"https://github.com/Homebrew/brew/blob/3073d6a8c34f71da054b000cfdbb62594a07c969/Library/Homebrew/api.rb#L25",
]
+ case .janDataFolder: [
+ "https://github.com/janhq/jan/blob/a7752d5be16fc5d92df7809def274ffd2b27db07/src-tauri/src/core/app/constants.rs#L2",
+ "https://github.com/janhq/jan/blob/a7752d5be16fc5d92df7809def274ffd2b27db07/src-tauri/src/core/app/models.rs#L4-L5",
+ "https://github.com/janhq/jan/blob/a7752d5be16fc5d92df7809def274ffd2b27db07/src-tauri/src/core/app/commands.rs#L17-L35",
+ "https://github.com/janhq/jan/blob/a7752d5be16fc5d92df7809def274ffd2b27db07/src-tauri/src/core/app/commands.rs#L146-L175",
+ ]
}
}
@@ -88,6 +96,8 @@ extension DeveloperCaches {
case .homebrewCache(let inside):
settings.homebrewCaches.filter { $0.appending(path: "api", directoryHint: .isDirectory).isRealFolder }
.flatMap { cache in Self.entries(of: cache, named: inside).map { ($0, cache) } }
+ case .janDataFolder(let inside):
+ settings.janDataFolder.map { [($0.appending(path: inside, directoryHint: .isDirectory), $0)] } ?? []
}
return found.map { (Self.entry($0.place), Self.entry($0.named)) }.filter(\.place.isRealFolder)
}
diff --git a/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swift b/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swift
index 75d5fa8a..2d2c6284 100644
--- a/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swift
+++ b/Packages/PeelCore/Sources/PeelCore/Developer/ToolSettings.swift
@@ -21,6 +21,9 @@ struct ToolSettings: Sendable {
let goBuildCache: URL?
/// Homebrew's caches: `HOMEBREW_CACHE` in the `brew.env` files `bin/brew` reads.
let homebrewCaches: [URL]
+ /// Jan's data folder: `data_folder` in Jan's `settings.json`, or, while that file is missing, in the one in the
+ /// folder named for Jan's bundle, which Jan recovers it from.
+ let janDataFolder: URL?
/// The settings of the tools of `home`, with Homebrew's files for everyone read from `root`.
init(home: URL, root: URL = URL(filePath: "/", directoryHint: .isDirectory)) {
@@ -62,6 +65,17 @@ struct ToolSettings: Sendable {
goModuleCache = (goValue("GOMODCACHE") ?? goPath).flatMap(Self.absolute)
goBuildCache = goValue("GOCACHE").flatMap(Self.absolute)
homebrewCaches = Self.homebrewCaches(home: home, root: root)
+
+ let applicationSupport = home.appending(path: "Library/Application Support", directoryHint: .isDirectory)
+ let janSettings = applicationSupport.appending(path: "Jan/settings.json")
+ janDataFolder = Self.text(
+ at: janSettings.isMissing ? applicationSupport.appending(path: "jan.ai.app/settings.json") : janSettings
+ ).flatMap { Self.jsonValue(of: "data_folder", in: $0) }.flatMap(Self.absolute)
+ }
+
+ private static func jsonValue(of key: String, in text: String) -> String? {
+ let object = try? JSONSerialization.jsonObject(with: Data(text.utf8))
+ return (object as? [String: Any])?[key] as? String
}
/// Every place `HOMEBREW_CACHE` names in the `brew.env` files, for each prefix Homebrew may be in and each folder
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
index 484eee48..db517e49 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/DeveloperCachesTests.swift
@@ -1371,6 +1371,24 @@ struct DeveloperCachesTests {
])
}
+ @Test func findsJansModelsWhereItsSettingMovedItsDataFolder() async throws {
+ let directory = try TemporaryDirectory()
+ let moved = directory.url.appending(path: "Fast/jan").path(percentEncoded: false)
+ try directory.file("home/Library/Application Support/Jan/settings.json", contents: Data(#"{"data_folder":"\#(moved)"}"#.utf8))
+ try directory.file("Fast/jan/llamacpp/models/tiny/model.gguf", bytes: 400_000)
+ try directory.file("Fast/jan/mlx/models/small/weights.safetensors", bytes: 400_000)
+ try directory.file("Fast/jan/logs/app.log", bytes: 400_000)
+ let jan = DeveloperCaches.definitions.filter { $0.id == "jan" }
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+
+ let found = await DeveloperCaches.scan(jan, homeDirectory: home).flatMap(\.locations)
+
+ let temporary = directory.url.path(percentEncoded: false)
+ #expect(Set(found.map { $0.url.path(percentEncoded: false).replacingOccurrences(of: temporary, with: "") }) == [
+ "Fast/jan/llamacpp/models", "Fast/jan/mlx/models",
+ ])
+ }
+
/// A path that needs the tool's own environment, or a folder without the tool's mark, names no place.
@Test func aConfigurationThatNamesNoPlaceOfItsOwnMovesNothing() async throws {
let directory = try TemporaryDirectory()
diff --git a/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swift
index 2315755f..0ac7caa3 100644
--- a/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swift
+++ b/Packages/PeelCore/Tests/PeelCoreTests/ToolSettingsTests.swift
@@ -207,6 +207,25 @@ struct ToolSettingsTests {
#expect(left.inside(home.appending(path: "Library/Caches", directoryHint: .isDirectory)).contains(["brew"]))
}
+ @Test func readsJansDataFolderWhereJanLooksForIt() throws {
+ let directory = try TemporaryDirectory()
+ let home = directory.url.appending(path: "home", directoryHint: .isDirectory)
+ let write = { (path: String, text: String) throws in _ = try directory.file(path, contents: Data(text.utf8)) }
+ let dataFolder = { Self.path(ToolSettings(home: home).janDataFolder) }
+
+ try write("home/Library/Application Support/jan.ai.app/settings.json", #"{"data_folder":"/Volumes/Fast/jan-old"}"#)
+ #expect(dataFolder() == "/Volumes/Fast/jan-old", "Jan recovers its settings from its bundle's folder")
+
+ try write("home/Library/Application Support/Jan/settings.json", #"{"data_folder":"/Volumes/Fast/jan"}"#)
+ #expect(dataFolder() == "/Volumes/Fast/jan")
+
+ try write("home/Library/Application Support/Jan/settings.json", #"{"data_folder":"./data"}"#)
+ #expect(dataFolder() == nil, "a relative path names no place")
+
+ try write("home/Library/Application Support/Jan/settings.json", #"["/Volumes/Fast/jan"]"#)
+ #expect(dataFolder() == nil)
+ }
+
private static func path(_ url: URL?) -> String? {
url.map { $0.path(percentEncoded: false) }.map { $0.count > 1 && $0.hasSuffix("/") ? String($0.dropLast()) : $0 }
}