Repository navigation
iOS: show which features a Mac update unlocks when the connected Mac is older #7960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
e756965
df9b4eb
2a30214
b29224a
f825a82
06b3368
fc3c619
3644dfd
f52fcc8
e4d64c0
19e6ae9
542e5ff
8de2ae1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /// A strictly numeric dotted Mac marketing version used by the mobile update advisor. | ||
| /// | ||
| /// Valid versions contain one to three nonnegative decimal components. Missing trailing | ||
| /// components compare as zero, so `0.65` and `0.65.0` are equal. | ||
| public struct MobileMacAppVersion: Comparable, Equatable, Sendable, CustomStringConvertible { | ||
| /// The one to three numeric components parsed from the marketing version. | ||
| public let components: [Int] | ||
|
|
||
| /// Creates a version from a strictly numeric dotted marketing-version string. | ||
| /// | ||
| /// - Parameter string: A version containing one to three ASCII-decimal components. | ||
| /// - Returns: A parsed version, or `nil` for an empty, malformed, signed, suffixed, or oversized version. | ||
| public init?(parsing string: String) { | ||
| let substrings = string.split(separator: ".", omittingEmptySubsequences: false) | ||
| guard (1 ... 3).contains(substrings.count) else { return nil } | ||
|
|
||
| var parsedComponents: [Int] = [] | ||
| parsedComponents.reserveCapacity(substrings.count) | ||
| for substring in substrings { | ||
| guard !substring.isEmpty, | ||
| substring.utf8.allSatisfy({ (48 ... 57).contains($0) }), | ||
| let component = Int(substring) | ||
| else { | ||
| return nil | ||
| } | ||
| parsedComponents.append(component) | ||
| } | ||
|
|
||
| components = parsedComponents | ||
| } | ||
|
|
||
| /// The canonical dotted representation of the parsed numeric components. | ||
| public var description: String { | ||
| components.map(String.init).joined(separator: ".") | ||
| } | ||
|
|
||
| /// Returns whether two versions have equal numeric components after adding trailing zeroes. | ||
| /// | ||
| /// - Parameters: | ||
| /// - lhs: The first version to compare. | ||
| /// - rhs: The second version to compare. | ||
| /// - Returns: `true` when both versions represent the same numeric version. | ||
| public static func == (lhs: Self, rhs: Self) -> Bool { | ||
| !(lhs < rhs) && !(rhs < lhs) | ||
| } | ||
|
|
||
| /// Returns whether the first version numerically precedes the second version. | ||
| /// | ||
| /// - Parameters: | ||
| /// - lhs: The first version to compare. | ||
| /// - rhs: The second version to compare. | ||
| /// - Returns: `true` when `lhs` is numerically older than `rhs`. | ||
| public static func < (lhs: Self, rhs: Self) -> Bool { | ||
| for index in 0 ..< 3 { | ||
| let left = index < lhs.components.count ? lhs.components[index] : 0 | ||
| let right = index < rhs.components.count ? rhs.components[index] : 0 | ||
| if left != right { | ||
| return left < right | ||
| } | ||
| } | ||
| return false | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| /// A truthful recommendation that a released Mac update unlocks mobile-visible features. | ||
| public struct MobileMacUpdateHint: Equatable, Sendable { | ||
| /// The missing features that a released Mac update unlocks, in registry order without duplicates. | ||
| public let features: [MobileMacUpdateFeature] | ||
|
|
||
| /// The minimum Mac marketing version that unlocks every listed feature. | ||
| public let minimumMacVersion: MobileMacAppVersion | ||
|
|
||
| /// The connected Mac's current marketing version. | ||
| public let macAppVersion: MobileMacAppVersion | ||
|
|
||
| /// The stable missing-capability identifiers used to build the dismissal signature. | ||
| private let missingCapabilities: [String] | ||
|
|
||
| /// Creates a Mac update hint from contributing capability requirements. | ||
| /// | ||
| /// - Parameters: | ||
| /// - features: The unique features to present, in registry order. | ||
| /// - minimumMacVersion: The minimum Mac version that unlocks the features. | ||
| /// - macAppVersion: The connected Mac's current version. | ||
| /// - missingCapabilities: The contributing stable capability identifiers. | ||
| init( | ||
| features: [MobileMacUpdateFeature], | ||
| minimumMacVersion: MobileMacAppVersion, | ||
| macAppVersion: MobileMacAppVersion, | ||
| missingCapabilities: [String] | ||
| ) { | ||
| self.features = features | ||
| self.minimumMacVersion = minimumMacVersion | ||
| self.macAppVersion = macAppVersion | ||
| self.missingCapabilities = missingCapabilities | ||
| } | ||
|
|
||
| /// A stable signature that re-arms dismissal when the capability gap or target version changes. | ||
| public var dismissalSignature: String { | ||
| "\(Set(missingCapabilities).sorted().joined(separator: ","))>=\(minimumMacVersion)" | ||
| } | ||
| } | ||
|
|
||
| /// Decides whether a connected Mac has a released update that unlocks known mobile features. | ||
| // lint:allow namespace-enum, namespace-type — the Part A specification requires this stateless static API shape. | ||
| public enum MobileMacUpdateAdvisor { | ||
| /// Builds a truthful update hint for missing capabilities available in a newer released Mac version. | ||
| /// | ||
| /// - Parameters: | ||
| /// - hostCapabilities: Capabilities from a successfully decoded `mobile.host.status` response. | ||
| /// - versionString: The connected Mac's reported marketing version. | ||
| /// - requirements: The capability release registry known to the iOS build. | ||
| /// - Returns: A hint when at least one missing capability shipped after the Mac version, otherwise `nil`. | ||
| public static func hint( | ||
| hostCapabilities: Set<String>, | ||
| macAppVersion versionString: String?, | ||
| requirements: [MobileMacUpdateCapabilityRequirement] = MobileMacUpdateCapabilityRequirement.standard | ||
| ) -> MobileMacUpdateHint? { | ||
| guard let versionString, | ||
| let macAppVersion = MobileMacAppVersion(parsing: versionString) | ||
| else { | ||
| return nil | ||
| } | ||
|
|
||
| let contributors = requirements.filter { requirement in | ||
| guard let releaseVersion = requirement.firstReleasedMacVersion else { return false } | ||
| return !hostCapabilities.contains(requirement.capability) && macAppVersion < releaseVersion | ||
| } | ||
| guard !contributors.isEmpty, | ||
| let minimumMacVersion = contributors.compactMap(\.firstReleasedMacVersion).max() | ||
| else { | ||
| return nil | ||
| } | ||
|
|
||
| var seenFeatures: Set<MobileMacUpdateFeature> = [] | ||
| let features = contributors.compactMap { requirement in | ||
| seenFeatures.insert(requirement.feature).inserted ? requirement.feature : nil | ||
| } | ||
| return MobileMacUpdateHint( | ||
| features: features, | ||
| minimumMacVersion: minimumMacVersion, | ||
| macAppVersion: macAppVersion, | ||
| missingCapabilities: contributors.map(\.capability) | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /// A Mac host capability and the mobile-visible feature it enables. | ||
| public struct MobileMacUpdateCapabilityRequirement: Sendable, Equatable { | ||
| /// The stable capability identifier advertised by a Mac host. | ||
| public let capability: String | ||
|
|
||
| /// The mobile-visible feature enabled by the capability. | ||
| public let feature: MobileMacUpdateFeature | ||
|
|
||
| /// The first released Mac marketing version that advertises the capability. | ||
| /// | ||
| /// A `nil` value means the capability has not shipped in a Mac release, so the | ||
| /// update advisor never claims that updating unlocks it. | ||
| public let firstReleasedMacVersion: MobileMacAppVersion? | ||
|
|
||
| /// Creates a capability requirement for the update advisor. | ||
| /// | ||
| /// - Parameters: | ||
| /// - capability: The stable capability identifier advertised by a Mac host. | ||
| /// - feature: The mobile-visible feature enabled by the capability. | ||
| /// - firstReleasedMacVersion: The first released Mac version containing the capability, or `nil` if unreleased. | ||
| public init( | ||
| capability: String, | ||
| feature: MobileMacUpdateFeature, | ||
| firstReleasedMacVersion: MobileMacAppVersion? | ||
| ) { | ||
| self.capability = capability | ||
| self.feature = feature | ||
| self.firstReleasedMacVersion = firstReleasedMacVersion | ||
| } | ||
|
|
||
| /// The capability release registry known to this iOS build. | ||
| /// | ||
| /// Update an unreleased entry when its capability first ships in a Mac release. | ||
| // lint:allow singleton — `standard` is the spec-required immutable declaration registry, not runtime state. | ||
| public static let standard: [MobileMacUpdateCapabilityRequirement] = [ | ||
| .init( | ||
| capability: "workspace.actions.v1", | ||
| feature: .workspaceActions, | ||
| firstReleasedMacVersion: MobileMacAppVersion(parsing: "0.64.15") | ||
| ), | ||
| .init( | ||
| capability: "workspace.read_state.v1", | ||
| feature: .workspaceReadState, | ||
| firstReleasedMacVersion: MobileMacAppVersion(parsing: "0.64.16") | ||
| ), | ||
| .init( | ||
| capability: "workspace.close.v1", | ||
| feature: .workspaceClose, | ||
| firstReleasedMacVersion: MobileMacAppVersion(parsing: "0.64.16") | ||
| ), | ||
| .init( | ||
| capability: "workspace.groups.v1", | ||
| feature: .workspaceGroups, | ||
| firstReleasedMacVersion: MobileMacAppVersion(parsing: "0.64.16") | ||
| ), | ||
| .init(capability: "workspace.move.v1", feature: .workspaceMove, firstReleasedMacVersion: nil), | ||
| .init(capability: "workspace.group_actions.v1", feature: .workspaceGroupActions, firstReleasedMacVersion: nil), | ||
| .init(capability: "workspace.create_in_group.v1", feature: .workspaceCreateInGroup, firstReleasedMacVersion: nil), | ||
| .init(capability: "workspace.group_create.v1", feature: .workspaceGroupCreate, firstReleasedMacVersion: nil), | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| /// A mobile-visible feature gated on a Mac host capability. | ||
| /// | ||
| /// Raw values are stable identifiers used in dismissal signatures and analytics. | ||
| public enum MobileMacUpdateFeature: String, CaseIterable, Sendable { | ||
| /// Renaming and pinning workspaces. | ||
| case workspaceActions | ||
|
|
||
| /// Marking workspaces as read or unread. | ||
| case workspaceReadState | ||
|
|
||
| /// Closing workspaces. | ||
| case workspaceClose | ||
|
|
||
| /// Organizing workspaces into groups. | ||
| case workspaceGroups | ||
|
|
||
| /// Reordering workspaces. | ||
| case workspaceMove | ||
|
|
||
| /// Moving and grouping workspaces. | ||
| case workspaceGroupActions | ||
|
|
||
| /// Creating workspaces inside groups. | ||
| case workspaceCreateInGroup | ||
|
|
||
| /// Creating workspace groups. | ||
| case workspaceGroupCreate | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| public import Foundation | ||
|
|
||
| /// Persists per-Mac update-hint dismissal signatures in injected user defaults. | ||
| public struct MobileMacUpdateHintDismissalStore { | ||
| /// The key prefix for per-Mac dismissal signatures. | ||
| private static let keyPrefix = "cmux.mobile.macUpdateHint.dismissed." | ||
|
|
||
| /// The injected defaults domain used for persistence. | ||
| private let defaults: UserDefaults | ||
|
|
||
| /// Creates a dismissal store backed by the supplied defaults domain. | ||
| /// | ||
| /// - Parameter defaults: The defaults domain to use; production callers default to `UserDefaults.standard`. | ||
| public init(defaults: UserDefaults = .standard) { | ||
| self.defaults = defaults | ||
| } | ||
|
|
||
| /// Returns whether a Mac dismissed the exact capability-gap signature. | ||
| /// | ||
| /// - Parameters: | ||
| /// - macDeviceID: The stable identifier of the connected Mac. | ||
| /// - signature: The current hint's dismissal signature. | ||
| /// - Returns: `true` only when the stored signature exactly matches `signature`. | ||
| public func isDismissed(macDeviceID: String, signature: String) -> Bool { | ||
| defaults.string(forKey: Self.key(for: macDeviceID)) == signature | ||
| } | ||
|
|
||
| /// Persists dismissal of an exact capability gap for one Mac. | ||
| /// | ||
| /// - Parameters: | ||
| /// - macDeviceID: The stable identifier of the connected Mac. | ||
| /// - signature: The current hint's dismissal signature. | ||
| public func dismiss(macDeviceID: String, signature: String) { | ||
| defaults.set(signature, forKey: Self.key(for: macDeviceID)) | ||
| } | ||
|
|
||
| /// Builds the persistence key for a Mac device identifier. | ||
| /// | ||
| /// - Parameter macDeviceID: The stable identifier of the connected Mac. | ||
| /// - Returns: The defaults key scoped to that Mac. | ||
| private static func key(for macDeviceID: String) -> String { | ||
| keyPrefix + macDeviceID | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,76 @@ | ||||||||
| internal import CMUXMobileCore | ||||||||
| internal import CmuxMobileDiagnostics | ||||||||
|
|
||||||||
| extension MobileShellComposite { | ||||||||
| /// Whether the Mac supports workspace group sections and collapse/expand RPCs. | ||||||||
| public var supportsWorkspaceGroups: Bool { supportedHostCapabilities.contains(Self.workspaceGroupsCapability) } | ||||||||
| /// Whether the Mac supports rename/pin workspace actions. | ||||||||
| public var supportsWorkspaceActions: Bool { supportedHostCapabilities.contains(Self.workspaceActionsCapability) } | ||||||||
| /// Whether the Mac supports mark read/unread workspace actions. | ||||||||
| public var supportsWorkspaceReadStateActions: Bool { supportedHostCapabilities.contains(Self.workspaceReadStateCapability) } | ||||||||
|
|
||||||||
| /// Recomputes the visible Mac-update hint from an authoritative host status snapshot. | ||||||||
| /// | ||||||||
| /// - Parameters: | ||||||||
| /// - capabilities: Capabilities decoded from `mobile.host.status`. | ||||||||
| /// - statusMacAppVersion: The version carried by that status response, when available. | ||||||||
| /// - macDeviceID: The stable identifier of the host that supplied the status. | ||||||||
| func refreshMacUpdateHint( | ||||||||
| capabilities: Set<String>, | ||||||||
| statusMacAppVersion: String?, | ||||||||
| macDeviceID: String? | ||||||||
| ) { | ||||||||
| let version = statusMacAppVersion ?? activeTicket?.macAppVersion | ||||||||
| let hint = MobileMacUpdateAdvisor.hint( | ||||||||
| hostCapabilities: capabilities, | ||||||||
| macAppVersion: version | ||||||||
| ) | ||||||||
| MobileDebugLog.anchormux( | ||||||||
| "macupdate.hint caps=\(capabilities.count) version=\(version ?? "nil") hint=\(hint?.dismissalSignature ?? "nil")" | ||||||||
| ) | ||||||||
| guard let hint else { | ||||||||
| clearMacUpdateHint() | ||||||||
| return | ||||||||
| } | ||||||||
|
|
||||||||
| let resolvedMacDeviceID = macDeviceID ?? "unknown" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When both the status response and attach ticket lack a device ID, every Mac uses the persistent key for Rule Used: Flag correctness-critical detection/identity deriv... (source) |
||||||||
| guard !MobileMacUpdateHintDismissalStore().isDismissed( | ||||||||
| macDeviceID: resolvedMacDeviceID, | ||||||||
| signature: hint.dismissalSignature | ||||||||
| ) else { | ||||||||
| clearMacUpdateHint() | ||||||||
| return | ||||||||
| } | ||||||||
|
|
||||||||
| macUpdateHint = hint | ||||||||
| macUpdateHintMacDeviceID = resolvedMacDeviceID | ||||||||
| guard macUpdateHintShownSignatures.insert(hint.dismissalSignature).inserted else { return } | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The shown-event gate uses only the gap signature. If Mac A and Mac B have the same missing capabilities, both banners appear but only Mac A emits
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||
| analytics.capture("ios_mac_update_hint_shown", analyticsProperties(for: hint)) | ||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||||||||
| } | ||||||||
|
|
||||||||
| /// Permanently dismisses the currently visible gap for this Mac and version target. | ||||||||
| public func dismissMacUpdateHint() { | ||||||||
| guard let hint = macUpdateHint else { return } | ||||||||
| let macDeviceID = macUpdateHintMacDeviceID ?? "unknown" | ||||||||
| MobileMacUpdateHintDismissalStore().dismiss( | ||||||||
| macDeviceID: macDeviceID, | ||||||||
| signature: hint.dismissalSignature | ||||||||
| ) | ||||||||
| clearMacUpdateHint() | ||||||||
| analytics.capture("ios_mac_update_hint_dismissed", analyticsProperties(for: hint)) | ||||||||
| } | ||||||||
|
|
||||||||
| /// Clears connection-scoped hint state without resetting the session analytics gate. | ||||||||
| func clearMacUpdateHint() { | ||||||||
| macUpdateHint = nil | ||||||||
| macUpdateHintMacDeviceID = nil | ||||||||
| } | ||||||||
|
|
||||||||
| private func analyticsProperties(for hint: MobileMacUpdateHint) -> [String: AnalyticsValue] { | ||||||||
| [ | ||||||||
| "mac_app_version": .string(hint.macAppVersion.description), | ||||||||
| "minimum_mac_version": .string(hint.minimumMacVersion.description), | ||||||||
| "features": .string(hint.features.map(\.rawValue).joined(separator: ",")), | ||||||||
| ] | ||||||||
| } | ||||||||
| } | ||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 329
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 3241
🏁 Script executed:
Repository: manaflow-ai/cmux
Length of output: 1623
Add a registry invariant test for released capabilities
MobileMacAppVersion(parsing:)can returnnil, and the current advisor test only covers the.workspaceGroupshint path. Add a test that asserts everystandardentry with a declared release version still has a non-nilfirstReleasedMacVersion, so a typo in one of the literals fails fast instead of silently making that capability look unreleased.🤖 Prompt for AI Agents