diff --git a/changelog.d/models-catalog-not-downloaded-note.md b/changelog.d/models-catalog-not-downloaded-note.md new file mode 100644 index 0000000000..826f5e3b56 --- /dev/null +++ b/changelog.d/models-catalog-not-downloaded-note.md @@ -0,0 +1,5 @@ +### Models catalog names the models this Mac could add + +- `darkbloom models catalog` now ends with the catalog models that are not downloaded and that this Mac could select: at most three rows with id and download size, larger first, then `darkbloom models download ` and `darkbloom switch`. The note is printed only when there is at least one such model. +- A model is named when the `darkbloom start` picker would offer it to this Mac (required runtime capabilities present, not a hidden build or one replaced under a public alias), it is an active text model, its listed `min_ram_gb` is at most this Mac's memory, and it fits the provider's load budget alone. Free disk space, the memory reserve and memory in use at load time, the coordinator's minimum provider version and the provider's trust status are not checked, and the note says so. +- The note only prints: nothing is downloaded, selected or saved, and no request is added. The table's catalog request now also asks for the public aliases (`include_aliases=1`); the `--json` request and output are unchanged. diff --git a/docs/provider/cli-reference.md b/docs/provider/cli-reference.md index 58d444c53e..b69b872d1a 100644 --- a/docs/provider/cli-reference.md +++ b/docs/provider/cli-reference.md @@ -1,6 +1,6 @@ # Provider CLI reference -> Last updated: 2026-11-08 +> Last updated: 2026-11-10 Reference for the `darkbloom` command-line tool: every subcommand and flag, the files and identifiers it creates, the `provider.toml` keys it reads with their @@ -3070,6 +3070,39 @@ Show the coordinator's supported-model catalog. darkbloom models catalog [--coordinator ] [--json] [--type ] ``` +After the table, when there is at least one, the command names the catalog +models that are not downloaded and that this Mac could select: + +```text +Not downloaded (this Mac meets their listed requirements) + + Nemotron 3.5 Lightning [nvidia-nemotron-3.5-lightning] ~19.1 GB download + Qwen 3.5 9B [Qwen3.5-9B] ~6.1 GB download + + Not checked: free disk space, memory reserved or in use when a model loads, provider version and trust status. + Download one: darkbloom models download + Then choose what to serve: darkbloom switch (darkbloom start when the provider is stopped) +``` + +The note only prints: it downloads, selects and saves nothing, and it is absent +from `--json` output and when hardware detection fails. It adds no request; the +table's one catalog request now also asks for the public aliases +(`include_aliases=1`, as the picker does), and the `--json` request is as +before. At most three models are named, larger first, and one more line counts +the rest. A model is named (`ModelsCatalogHint.candidates`) when the +`darkbloom start` picker would offer it to this Mac (this Mac has its required +runtime capabilities, and it is not a hidden build or one replaced under a +public alias), it is an active text model, its listed `min_ram_gb` is at most +this Mac's memory (the coordinator's comparison for a listed tier; a model with +no listed tier is not named), and it fits the provider's load budget alone +([RAM tiers and catalog models](hardware-requirements.md#ram-tiers-and-catalog-models)). +The note does not promise that a named model will download, load or receive +requests: free disk space, the configured `memory_reserve_gb`, memory in use at +load time, the coordinator's minimum provider version and the provider's trust +status are not checked. `darkbloom models download` does not edit +`backend.enabled_models`; with an empty `enabled_models` the provider serves +every local model it can run. + ### `darkbloom models list` List local models. diff --git a/provider-swift/Sources/darkbloom/ModelsCatalogHint.swift b/provider-swift/Sources/darkbloom/ModelsCatalogHint.swift new file mode 100644 index 0000000000..7aa256e9e8 --- /dev/null +++ b/provider-swift/Sources/darkbloom/ModelsCatalogHint.swift @@ -0,0 +1,58 @@ +import Foundation +import ProviderCore + +/// The note `models catalog` prints under its table: catalog models this Mac +/// has not downloaded and that the `start`/`switch` picker would let it +/// select. It only prints: nothing is downloaded, selected or saved. +enum ModelsCatalogHint { + /// Rows printed before the rest are counted. + static let maximumRows = 3 + + /// The not-downloaded text models the picker would offer this Mac, larger + /// first as there: its runtime-capability, alias and hidden-build rules run + /// on the whole catalog. Of those, a model is named when it is active, + /// lists a `min_ram_gb` this Mac meets (the coordinator's rule for a listed + /// tier; its size estimate for an unlisted one is not copied, so those are + /// left out) and fits the provider's load budget alone, which the tier does + /// not guarantee. Free disk space, the configured memory reserve, memory in + /// use at load time, the coordinator's version floor and trust status are + /// not checked. + static func candidates( + entries: [CatalogModel], aliases: [CatalogAlias], downloadedIDs: Set, memoryGb: Double, + runtimeCapabilities: Set + ) -> [CatalogModel] { + let rows = Start.pickerCatalogRows( + catalog: Start.evaluateEligiblePickerCatalog( + models: entries.filter { $0.modelType == "text" }, aliases: aliases, + runtimeCapabilities: runtimeCapabilities)) + return Start.buildPickerEntries( + rows: rows, downloadedIDs: downloadedIDs, localMemoryByID: [:], resumableIDs: [], + memoryGb: memoryGb + ) + .filter { + !$0.downloaded && $0.catalogModel.active != false && ($0.catalogModel.minRamGb ?? 0) > 0 + && Start.pickerSelectionFitsBudget([$0], memoryGb: memoryGb) + } + .map(\.catalogModel) + } + + /// The lines to print after the catalog table; none without a candidate. + /// Sizes are the catalog's decimal `size_gb`, as in the table. + static func lines(candidates: [CatalogModel], cliName: String) -> [String] { + guard !candidates.isEmpty else { return [] } + var lines = ["", "Not downloaded (this Mac meets their listed requirements)", ""] + lines += candidates.prefix(maximumRows).map { + " \($0.displayName) [\($0.id)] ~\(String(format: "%.1f", $0.sizeGb)) GB download" + } + if candidates.count > maximumRows { + lines.append( + " … and \(candidates.count - maximumRows) more; the \(cliName) switch picker lists them all") + } + return lines + [ + "", + " Not checked: free disk space, memory reserved or in use when a model loads, provider version and trust status.", + " Download one: \(cliName) models download ", + " Then choose what to serve: \(cliName) switch (\(cliName) start when the provider is stopped)", + ] + } +} diff --git a/provider-swift/Sources/darkbloom/ModelsCommand.swift b/provider-swift/Sources/darkbloom/ModelsCommand.swift index cde7b6853e..8626b43a25 100644 --- a/provider-swift/Sources/darkbloom/ModelsCommand.swift +++ b/provider-swift/Sources/darkbloom/ModelsCommand.swift @@ -113,9 +113,13 @@ extension Models { let coordinatorURL = coordinator ?? snapshot.config.coordinator.url let client = ModelCatalogClient(coordinatorURL: coordinatorURL) + // The table's request also asks for the public aliases, which the + // note under the table needs; the `--json` request is as before. let entries: [CatalogModel] + let aliases: [CatalogAlias] do { - entries = try await client.fetchCatalog(typeFilter: type) + let catalog = try await client.fetchCatalogSnapshot(typeFilter: type, includeAliases: !json) + (entries, aliases) = (catalog.models, catalog.aliases) } catch let error as ModelCatalogError { printError("\(error)") throw ExitCode.failure @@ -188,6 +192,20 @@ extension Models { print(" These models are no longer served by the network.") print(" Remove with: \(BuildEnvironment.current.cliName) models remove ") } + + // -- Not downloaded, selectable on this Mac -- + // Skipped when hardware detection failed, so nothing is guessed. + // `runtimeCapabilities` is nil only when no entry is gated. + if let hardware = snapshot.hardware { + let candidates = ModelsCatalogHint.candidates( + entries: entries, aliases: aliases, downloadedIDs: downloadedIDs, + memoryGb: Double(hardware.memoryGb), runtimeCapabilities: runtimeCapabilities ?? []) + for line in ModelsCatalogHint.lines( + candidates: candidates, cliName: BuildEnvironment.current.cliName) + { + print(line) + } + } } } } diff --git a/provider-swift/Tests/DarkbloomCLITests/ModelsCatalogHintTests.swift b/provider-swift/Tests/DarkbloomCLITests/ModelsCatalogHintTests.swift new file mode 100644 index 0000000000..a7a33d6eed --- /dev/null +++ b/provider-swift/Tests/DarkbloomCLITests/ModelsCatalogHintTests.swift @@ -0,0 +1,145 @@ +import Foundation +import Testing + +@testable import ProviderCore +@testable import darkbloom + +/// The note `darkbloom models catalog` prints under its table. The Mac here +/// has 128 GB. Models meant to fit are at most 40 GB and the one meant not to +/// fit is larger than the Mac's memory, so the memory-cap overrides another +/// suite sets in this process cannot change a verdict. +@Suite("models catalog: not-downloaded models this Mac can select") +struct ModelsCatalogHintTests { + private func model( + _ id: String, displayName: String? = nil, sizeGb: Double = 10, minRamGb: Int? = 24, + modelType: String = "text", active: Bool? = nil, metadata: [String: JSONValue]? = nil, + requiredCapabilities: [ProviderRuntimeCapability]? = nil + ) -> CatalogModel { + CatalogModel( + id: id, s3Name: id, displayName: displayName ?? id, modelType: modelType, sizeGb: sizeGb, + minRamGb: minRamGb, active: active, r2Prefix: "v2/\(id)/v1", metadata: metadata, + requiredProviderCapabilities: requiredCapabilities) + } + + private func candidateIDs( + _ entries: [CatalogModel], aliases: [CatalogAlias] = [], downloaded: Set = [], + capabilities: Set = [] + ) -> [String] { + ModelsCatalogHint.candidates( + entries: entries, aliases: aliases, downloadedIDs: downloaded, memoryGb: 128, + runtimeCapabilities: capabilities + ).map(\.id) + } + + @Test("lists what is not downloaded, larger first, and leaves out what is") + func notDownloadedLargerFirst() { + let entries = [ + model("acme/small", sizeGb: 6), model("acme/have", sizeGb: 20), + model("acme/large", sizeGb: 40, minRamGb: 64), + ] + #expect(candidateIDs(entries, downloaded: ["acme/have"]) == ["acme/large", "acme/small"]) + #expect(candidateIDs(entries, downloaded: ["acme/small", "acme/have", "acme/large"]).isEmpty) + } + + @Test("a listed min_ram_gb is compared as the coordinator does; an unlisted tier is not guessed") + func memoryTier() { + let entries = [ + model("acme/at-tier", minRamGb: 128), model("acme/above-tier", minRamGb: 129), + model("acme/no-tier", minRamGb: nil), model("acme/zero-tier", minRamGb: 0), + ] + #expect(candidateIDs(entries) == ["acme/at-tier"]) + } + + @Test("a model whose required runtime capabilities this Mac lacks is left out") + func runtimeCapabilities() { + let entries = [ + model("acme/gated", requiredCapabilities: [.appleM5, .mlxNAX]), + // No catalog requirement: the embedded exact-ID rule still applies. + model(ModelRuntimeRequirements.qwen38ConcreteModelID, sizeGb: 16, minRamGb: 36), + ] + #expect(candidateIDs(entries, capabilities: [.appleM5]).isEmpty) + #expect( + candidateIDs(entries, capabilities: [.appleM5, .mlxNAX]) + == [ModelRuntimeRequirements.qwen38ConcreteModelID, "acme/gated"]) + } + + @Test("inactive, non-text and picker-hidden builds are left out") + func hiddenBuilds() { + let entries = [ + model("acme/image", modelType: "image"), model("acme/inactive", active: false), + model("acme/rollback", displayName: "Acme 8-bit (rollback)"), + model("acme/hidden", metadata: ["hidden_from_picker": .bool(true)]), + model("acme/not-standalone", metadata: ["hide_standalone": .bool(true)]), + // The picker's Gemma rollout rule: only the QAT build is offered. + model("gemma-4-26b", sizeGb: 28, minRamGb: 36), + model("gemma-4-26b-8bit", sizeGb: 28, minRamGb: 64), + model("gemma-4-26b-qat-4bit", sizeGb: 16, minRamGb: 36), + model("acme/active", active: true), + ] + #expect(candidateIDs(entries) == ["gemma-4-26b-qat-4bit", "acme/active"]) + // The picker hides the older Gemma build for a QAT row this note would not name either. + let inactiveQAT = [ + model("gemma-4-26b", sizeGb: 28, minRamGb: 36), + model("gemma-4-26b-qat-4bit", sizeGb: 16, minRamGb: 36, active: false), + ] + #expect(candidateIDs(inactiveQAT).isEmpty) + } + + @Test("under a public alias only the build the picker offers this Mac is named") + func aliasedBuilds() { + let entries = [ + model("acme/v2", sizeGb: 12, requiredCapabilities: [.appleM5]), model("acme/v1", sizeGb: 11), + model("acme/v0", sizeGb: 9), model("acme/other", sizeGb: 8), + ] + let alias = CatalogAlias( + id: "acme", displayName: "Acme", desiredBuild: "acme/v2", previousBuild: "acme/v1", + retiredBuilds: ["acme/v0"], primaryBuild: nil) + #expect(candidateIDs(entries, aliases: [alias], capabilities: [.appleM5]) == ["acme/v2", "acme/other"]) + // Without the desired build's capability the picker offers the previous build. + #expect(candidateIDs(entries, aliases: [alias]) == ["acme/v1", "acme/other"]) + } + + @Test("a model over the provider's load budget is left out although its tier is met") + func loadBudget() { + let entries = [ + model("acme/over-budget", sizeGb: 120, minRamGb: 128), + model("acme/fits", sizeGb: 40, minRamGb: 128), + ] + #expect(candidateIDs(entries) == ["acme/fits"]) + } + + @Test("each model is one row with its id and download size, then the commands; no model, no lines") + func exactLines() { + let candidates = [ + model("acme/large", displayName: "Acme Large", sizeGb: 19.05959583), + model("acme/small", displayName: "Acme Small", sizeGb: 6.11395223), + ] + #expect( + ModelsCatalogHint.lines(candidates: candidates, cliName: "darkbloom-dev") == [ + "", + "Not downloaded (this Mac meets their listed requirements)", + "", + " Acme Large [acme/large] ~19.1 GB download", + " Acme Small [acme/small] ~6.1 GB download", + "", + " Not checked: free disk space, memory reserved or in use when a model loads, provider version and trust status.", + " Download one: darkbloom-dev models download ", + " Then choose what to serve: darkbloom-dev switch (darkbloom-dev start when the provider is stopped)", + ]) + #expect(ModelsCatalogHint.lines(candidates: [], cliName: "darkbloom").isEmpty) + } + + @Test("at most three rows are printed; the rest are counted") + func rowLimit() { + let candidates = (1...5).map { model("acme/m\($0)", displayName: "M\($0)", sizeGb: Double($0)) } + let lines = ModelsCatalogHint.lines(candidates: candidates, cliName: "darkbloom") + #expect( + Array(lines.dropFirst(3).prefix(4)) == [ + " M1 [acme/m1] ~1.0 GB download", " M2 [acme/m2] ~2.0 GB download", + " M3 [acme/m3] ~3.0 GB download", + " … and 2 more; the darkbloom switch picker lists them all", + ]) + let three = ModelsCatalogHint.lines(candidates: Array(candidates.prefix(3)), cliName: "darkbloom") + #expect(three.count == lines.count - 1) + } +} diff --git a/provider-swift/Tests/DarkbloomCLITests/ModelsCommandRunTests.swift b/provider-swift/Tests/DarkbloomCLITests/ModelsCommandRunTests.swift index 367ccbcb58..0215d71f36 100644 --- a/provider-swift/Tests/DarkbloomCLITests/ModelsCommandRunTests.swift +++ b/provider-swift/Tests/DarkbloomCLITests/ModelsCommandRunTests.swift @@ -20,6 +20,19 @@ struct ModelsCommandRunTests { ]} """ + /// Alpha is downloaded by the test; Beta is not and fits any Mac with at + /// least 16 GB; Giant's memory tier is above any Mac. + static let noteCatalogJSON = """ + {"models":[ + {"id":"acme/Alpha-4bit","s3_name":"alpha","display_name":"Alpha","model_type":"text", + "size_gb":1.5,"min_ram_gb":8}, + {"id":"acme/Beta-4bit","s3_name":"beta","display_name":"Beta","model_type":"text", + "size_gb":2.5,"min_ram_gb":8}, + {"id":"acme/Giant-4bit","s3_name":"giant","display_name":"Giant","model_type":"text", + "size_gb":9000.0,"min_ram_gb":100000} + ]} + """ + @Test("list prints a table of local models, or the cache path when there are none") func listTable() async throws { let result = try await #require( @@ -121,7 +134,7 @@ struct ModelsCommandRunTests { try await runMarked( ["models", "catalog", "--config", sandbox.config.path, "--type", "text"], marker: "EMPTY") let query = CoordinatorStub.requests.first?.url?.query - #expect(query == "type=text") + #expect(query == "type=text&include_aliases=1") } let output = decodedText(result.standardOutputContent) let catalog = try #require(section(output, "CATALOG")) @@ -153,6 +166,7 @@ struct ModelsCommandRunTests { "--coordinator", "https://override.invalid"], marker: "JSON") #expect(CoordinatorStub.requests.map { $0.url?.host } == ["override.invalid"]) + #expect(CoordinatorStub.requests.first?.url?.query == nil) CoordinatorStub.install(["/v1/models/catalog": .json(500, "catalog offline")]) let error = try await runFailingCLICommand( @@ -166,6 +180,32 @@ struct ModelsCommandRunTests { #expect(entries.compactMap { $0["id"] as? String } == ["acme/Alpha-4bit", "acme/Remote-8bit"]) #expect(entries.first?["min_ram_gb"] as? Int == 16) #expect(!output.contains("Supported models")) + #expect(!output.contains("Not downloaded")) + } + + @Test("catalog ends with the not-downloaded models this Mac can select, from its one request") + func catalogNotDownloadedNote() async throws { + let result = try await #require( + processExitsWith: .success, observing: [\.standardOutputContent] + ) { + let sandbox = try CLICommandSandbox.enter() + defer { sandbox.remove() } + try sandbox.makeModel("acme/Alpha-4bit") + CoordinatorStub.install([ + "/v1/models/catalog": .json(200, ModelsCommandRunTests.noteCatalogJSON), + ]) + try await runMarked(["models", "catalog", "--config", sandbox.config.path], marker: "NOTE") + #expect(CoordinatorStub.requests.count == 1) + } + let note = try #require(section(decodedText(result.standardOutputContent), "NOTE")) + let cli = BuildEnvironment.current.cliName + // Beta fits the load budget of any Mac with 16 GB or more. + if ProcessInfo.processInfo.physicalMemory >= 16 << 30 { + #expect(note.contains("Not downloaded (this Mac meets their listed requirements)")) + #expect(note.contains(" Beta [acme/Beta-4bit] ~2.5 GB download")) + #expect(note.last == " Then choose what to serve: \(cli) switch (\(cli) start when the provider is stopped)") + } + #expect(!note.contains { $0.hasSuffix("GB download") && !$0.contains("acme/Beta-4bit") }) } @Test("remove deletes a model with --force or after 'yes', and keeps it otherwise")