Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

feat(kit): say which side to update when versions don't match

leepokai34e94d7c0a72
diff --git a/apps/ios/App/CodyncApp.swift b/apps/ios/App/CodyncApp.swift
index 6d18e804..bc5f7b85 100644
--- a/apps/ios/App/CodyncApp.swift
+++ b/apps/ios/App/CodyncApp.swift
@@ -11,6 +11,7 @@ struct CodyncApp: App {
@State private var app = AppStore.shared
@Environment(\.scenePhase) private var scenePhase
@AppStorage("onboardingCompleted") private var onboardingCompleted = false
+ private static let appStorePage = URL(string: "https://apps.apple.com/app/id6760984418")!
var body: some Scene {
WindowGroup {
@@ -19,6 +20,8 @@ struct CodyncApp: App {
.environment(app)
.environment(app.accounts)
.environment(app.account)
+ // A computer needs a newer app: its App Store page has the Update button.
+ .environment(\.appUpdate, AppUpdateAction { UIApplication.shared.open(Self.appStorePage) })
.tint(Palette.accent)
.codyncSheet(isPresented: Binding(
get: { (onboardingCompleted || app.account.isSignedIn) && app.account.showSwitcher },
diff --git a/apps/ios/Views/BotListView.swift b/apps/ios/Views/BotListView.swift
index f7585995..e33424ef 100644
--- a/apps/ios/Views/BotListView.swift
+++ b/apps/ios/Views/BotListView.swift
@@ -35,7 +35,7 @@ struct BotListView: View {
/// Computers that can take a new bot right now.
private var onlineStores: [BotStore] {
- allStores.filter { $0.connection == .online }
+ allStores.filter { $0.connection == .online && $0.mismatch == nil }
}
private var allStores: [BotStore] {
@@ -46,8 +46,13 @@ struct BotListView: View {
let roster = accounts.roster.filter { shownIDs.contains($0.ref.computerId) }
ScrollView {
LazyVStack(spacing: 0) {
- if roster.isEmpty {
- EmptyRoster(canCreate: !allStores.isEmpty, hasComputer: !accounts.computers.isEmpty,
+ if !grouped {
+ // One computer: its update notice leads the list.
+ ForEach(shownStores, id: \.computer.id) { updateCard($0) }
+ }
+ // A computer waiting for an update has its card instead; its bots aren't known yet.
+ if roster.isEmpty && shownStores.allSatisfy({ $0.mismatch == nil }) {
+ EmptyRoster(canCreate: allStores.contains { $0.mismatch == nil }, hasComputer: !accounts.computers.isEmpty,
create: newBot, showComputers: { app.showComputers = true })
}
@@ -56,8 +61,10 @@ struct BotListView: View {
ForEach(shownStores, id: \.computer.id) { store in
let id = store.computer.id
VStack(spacing: 0) {
- ComputerSection(store: store, empty: !roster.contains { $0.ref.computerId == id },
+ // Not synced while it needs an update: "No bots yet" wouldn't be true.
+ ComputerSection(store: store, empty: store.mismatch == nil && !roster.contains { $0.ref.computerId == id },
targeted: dropTarget == id, move: move)
+ updateCard(store)
ForEach(roster.filter { $0.ref.computerId == id }) { row($0, store: store) }
}
.dropDestination(for: String.self) { ids, _ in
@@ -97,7 +104,8 @@ struct BotListView: View {
Button("New group chat", systemImage: "person.2", action: newGroup)
.disabled(onlineStores.isEmpty)
}
- .disabled(allStores.isEmpty)
+ // A computer that needs an update can't take a new bot.
+ .disabled(!allStores.contains { $0.mismatch == nil })
}
}
.refreshable {
@@ -145,6 +153,14 @@ struct BotListView: View {
}
}
+ @ViewBuilder private func updateCard(_ store: BotStore) -> some View {
+ if let mismatch = store.mismatch {
+ UpdateNeededCard(store: store, mismatch: mismatch)
+ .padding(.vertical, 8)
+ .transition(.opacity)
+ }
+ }
+
private func row(_ item: RosterItem, store: BotStore) -> some View {
let bot = item.bot
// A plain button instead of a NavigationLink: same push, no chevron.
@@ -179,7 +195,7 @@ struct BotListView: View {
/// A new bot starts on the first computer online; the editor's Computer row can move it.
private func newBot() {
- guard let store = onlineStores.first ?? allStores.first else { return }
+ guard let store = onlineStores.first ?? allStores.first(where: { $0.mismatch == nil }) else { return }
editing = EditTarget(computerId: store.computer.id, draft: BotDraft())
}
}
diff --git a/apps/macos/Views/ChatWindow.swift b/apps/macos/Views/ChatWindow.swift
index 8fcbb5d3..98a3c235 100644
--- a/apps/macos/Views/ChatWindow.swift
+++ b/apps/macos/Views/ChatWindow.swift
@@ -411,7 +411,8 @@ private struct ChatSplitView: View {
private var accounts: AccountStore { host.accounts }
/// Every computer with a store, in the account's order.
private var stores: [BotStore] { accounts.computers.compactMap { accounts.store(for: $0.id) } }
- private var onlineStores: [BotStore] { stores.filter { shownIDs.contains($0.computer.id) && $0.connection == .online } }
+ /// Computers that can take a new chat: shown, online, and on versions that work together.
+ private var onlineStores: [BotStore] { stores.filter { shownIDs.contains($0.computer.id) && $0.connection == .online && $0.mismatch == nil } }
private var selectedStore: BotStore? { accounts.selection.flatMap { accounts.store(for: $0.computerId) } }
private var composeStore: BotStore? { composeComputer.flatMap { accounts.store(for: $0) } }
private var shownIDs: Set<ComputerID> {
@@ -457,6 +458,15 @@ private struct ChatSplitView: View {
}
ScrollView {
LazyVStack(spacing: 2) {
+ if !compact {
+ ForEach(stores.filter { shownIDs.contains($0.computer.id) }, id: \.computer.id) { store in
+ if let mismatch = store.mismatch {
+ UpdateNeededCard(store: store, mismatch: mismatch)
+ .padding(.bottom, 8)
+ .transition(.opacity)
+ }
+ }
+ }
ForEach(visibleRoster) { item in
if let store = accounts.store(for: item.ref.computerId) {
row(item.bot, store)
@@ -485,7 +495,9 @@ private struct ChatSplitView: View {
}
}
.overlay {
- if visibleRoster.isEmpty && !compact {
+ // A computer waiting for an update shows its card instead; its bots aren't known yet.
+ if visibleRoster.isEmpty && !compact
+ && !stores.contains(where: { shownIDs.contains($0.computer.id) && $0.mismatch != nil }) {
VStack(spacing: 8) {
Text(search.isEmpty ? "No bots yet" : "No matching bots")
.font(.system(size: 13, weight: .medium))
@@ -674,6 +686,11 @@ private struct ChatSplitView: View {
sidebarWidth = min(sidebarWidth, max(260, $0.width - 420))
}
.hiddenWindowTitle()
+ // A computer and this app on versions that don't work together: Sparkle updates the app;
+ // this Mac's own host is put back on the app's bundled copy.
+ .environment(\.appUpdate, updates.canCheckForUpdates || updates.hasStagedUpdate
+ ? AppUpdateAction { [updates] in updates.checkForUpdates() } : nil)
+ .environment(\.hostUpdate, HostUpdateAction(available: { [host] in $0 === host.store }) { [host] _ in host.restart() })
.codyncDialog("Start a new session?", isPresented: Binding(
get: { newSessionBot != nil },
set: { if !$0 { newSessionBot = nil } }
@@ -926,7 +943,7 @@ extension ChatSplitView {
fileprivate func compose(group: Bool = false) {
composingGroup = group
// The selected bot's computer if it's online, else this Mac, else any online one.
- let target = [selectedStore, host.store].compactMap { $0 }.first { shownIDs.contains($0.computer.id) && $0.connection == .online } ?? onlineStores.first
+ let target = [selectedStore, host.store].compactMap { $0 }.first { store in onlineStores.contains { $0 === store } } ?? onlineStores.first
guard let target else { return }
if !composing { previousSelection = accounts.selection }
composeComputer = target.computer.id
diff --git a/apps/shared/ComputerStatus.swift b/apps/shared/ComputerStatus.swift
index b6a9d806..4d333129 100644
--- a/apps/shared/ComputerStatus.swift
+++ b/apps/shared/ComputerStatus.swift
@@ -6,6 +6,7 @@ extension BotStore {
/// One short line for a computer's connection, used next to its name.
var statusText: String {
switch connection {
+ case .online where mismatch != nil: "Needs update"
case .online: "Online"
case .connecting: "Connecting…"
case let .computerOffline(lastSeen): lastSeen.map { "Offline · seen \(RelativeTime.day($0))" } ?? "Offline"
diff --git a/kit/Sources/CodyncKit/Models/Compatibility.swift b/kit/Sources/CodyncKit/Models/Compatibility.swift
new file mode 100644
index 00000000..ff4fa2bc
--- /dev/null
+++ b/kit/Sources/CodyncKit/Models/Compatibility.swift
@@ -0,0 +1,62 @@
+import Foundation
+
+/// Phone/host compatibility: each side names the oldest version of the other it still works
+/// with (docs/reference/compatibility.md). The host sends `minApp` in `hello`; this app keeps
+/// `minHost`. Mirrors `host/src/compat.rs`.
+public enum VersionMismatch: Equatable, Sendable {
+ /// This app is older than the host's `minApp`.
+ case updateApp(minimum: String)
+ /// The host is older than `minHost`.
+ case updateHost(version: String, minimum: String)
+
+ /// The oldest host this app works with. Raise it only when the app starts depending on
+ /// something older hosts don't have (an optional feature hides its control instead).
+ public static let minHost = "2.3.0"
+
+ /// Checks this app (`app`) against a host's version and `minApp` (nil from hosts that predate it).
+ public static func check(app: String, minHost: String = minHost, hostVersion: String, minApp: String?) -> VersionMismatch? {
+ if let minApp, AppVersion.isBelow(app, minApp) { return .updateApp(minimum: minApp) }
+ if AppVersion.isBelow(hostVersion, minHost) { return .updateHost(version: hostVersion, minimum: minHost) }
+ return nil
+ }
+}
+
+/// The two fields a compatibility check needs, readable even from a `hello` whose other
+/// fields this app version can't decode.
+public struct HostVersion: Codable, Equatable, Sendable {
+ public var version: String
+ public var minApp: String?
+
+ public init(version: String, minApp: String? = nil) {
+ self.version = version
+ self.minApp = minApp
+ }
+}
+
+public enum AppVersion {
+ /// This build's marketing version ("" when the bundle has none, e.g. in tests: never blocks).
+ public static let current = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? ""
+
+ /// `major.minor.patch`, ignoring a leading `v` and any pre-release or build suffix; missing
+ /// parts count as 0. `nil` for anything else.
+ public static func parse(_ version: String) -> [Int]? {
+ var core = Substring(version.trimmingCharacters(in: .whitespaces))
+ if core.first == "v" { core = core.dropFirst() }
+ guard let numbers = core.split(separator: "-", maxSplits: 1, omittingEmptySubsequences: false).first?
+ .split(separator: "+", maxSplits: 1, omittingEmptySubsequences: false).first else { return nil }
+ let parts = numbers.split(separator: ".", omittingEmptySubsequences: false)
+ guard (1...3).contains(parts.count) else { return nil }
+ var result: [Int] = []
+ for part in parts {
+ guard !part.isEmpty, part.allSatisfy(\.isASCII), part.allSatisfy(\.isNumber), let n = Int(part) else { return nil }
+ result.append(n)
+ }
+ return result + Array(repeating: 0, count: 3 - result.count)
+ }
+
+ /// Whether `version` is below `minimum`; an unreadable version never is.
+ public static func isBelow(_ version: String, _ minimum: String) -> Bool {
+ guard let v = parse(version), let m = parse(minimum) else { return false }
+ return v.lexicographicallyPrecedes(m)
+ }
+}
diff --git a/kit/Sources/CodyncKit/Models/Models.swift b/kit/Sources/CodyncKit/Models/Models.swift
index ed17dc69..dfb9c3e4 100644
--- a/kit/Sources/CodyncKit/Models/Models.swift
+++ b/kit/Sources/CodyncKit/Models/Models.swift
@@ -330,7 +330,8 @@ public struct Hello: Codable, Sendable {
public var computerId: ComputerID?
public var signKey: String?
public var boxKey: String?
- public var `protocol`: Int?
+ /// The oldest app version this host serves (missing from hosts that predate the check).
+ public var minApp: String?
/// The cloud relay the host uses; nil = cloud off.
public var cloud: String?
}
diff --git a/kit/Sources/CodyncUI/Bots/ComputerFilterHeader.swift b/kit/Sources/CodyncUI/Bots/ComputerFilterHeader.swift
index dd31e221..f5e392f1 100644
--- a/kit/Sources/CodyncUI/Bots/ComputerFilterHeader.swift
+++ b/kit/Sources/CodyncUI/Bots/ComputerFilterHeader.swift
@@ -103,6 +103,7 @@ public struct ComputerFilterHeader: View {
public extension BotStore {
var connectionLabel: String {
switch shownConnection {
+ case .online where mismatch != nil: "Needs update"
case .online: "Connected"
case .connecting: "Connecting…"
case .computerOffline, .offline: "Offline"
diff --git a/kit/Sources/CodyncUI/Store/BotStore.swift b/kit/Sources/CodyncUI/Store/BotStore.swift
index 3151f8e2..1156ddd1 100644
--- a/kit/Sources/CodyncUI/Store/BotStore.swift
+++ b/kit/Sources/CodyncUI/Store/BotStore.swift
@@ -52,6 +52,8 @@ public final class BotStore {
public private(set) var hostRoute: HostRoute?
public private(set) var client: HostClient?
public private(set) var hello: Hello?
+ /// The host's version and `minApp`, kept even when the rest of its `hello` can't be read.
+ public private(set) var hostVersion: HostVersion?
public private(set) var bots: [String: Bot] = [:]
public private(set) var entries: [String: [Entry]] = [:]
public private(set) var usage: Usage
@@ -111,6 +113,12 @@ public final class BotStore {
@ObservationIgnored private var voiceCalls: [UUID: VoiceCall] = [:]
private var saveTask: Task<Void, Never>?
private var rewound = false
+ /// Events stayed undecodable after the rewind.
+ private var unreadable = false
+ /// This app's marketing version, compared with the host's `minApp`.
+ private let appVersion: String
+ /// While one side needs an update there's nothing to sync; `hello` is asked again this often.
+ private static let mismatchRecheck: Duration = .seconds(30)
/// `.channel` loads this context's `DeviceIdentity` itself.
public convenience init(computer: Computer, route: Route, clientKind: String, storage: SharedStore.Context) {
@@ -124,7 +132,9 @@ public final class BotStore {
}
init(computer: Computer, route: Route, clientKind: String, storage: SharedStore.Context,
+ appVersion: String = AppVersion.current,
transport: @escaping @MainActor () async throws -> any HostTransport) {
+ self.appVersion = appVersion
self.computer = computer
self.route = route
self.clientKind = clientKind
@@ -156,6 +166,22 @@ public final class BotStore {
public var hostName: String { hello?.name ?? computer.name }
+ /// Which side must update before this app and the host can work together
+ /// (docs/reference/compatibility.md). `nil` until the host has answered, and whenever
+ /// a version can't be read: an unknown is never a reason to lock someone out.
+ public var mismatch: VersionMismatch? {
+ guard let hostVersion else { return nil }
+ if let found = VersionMismatch.check(app: appVersion, hostVersion: hostVersion.version, minApp: hostVersion.minApp) {
+ return found
+ }
+ // The host sends data this app can't read and is newer: this app is behind,
+ // whatever the host's `minApp` says.
+ if unreadable, AppVersion.isBelow(appVersion, hostVersion.version) {
+ return .updateApp(minimum: hostVersion.version)
+ }
+ return nil
+ }
+
/// Roster order: pinned first (manual order not tracked yet), then most recent activity.
public var roster: [Bot] {
bots.values.filter { !$0.hidden }.sorted {
@@ -413,21 +439,14 @@ public final class BotStore {
var backoff: Double = 1
while !Task.isCancelled {
do {
- if hello == nil || hello?.hostId != hostId {
- let h = try await client.hello()
- guard !Task.isCancelled, !retired else { return }
- hello = h
- if case .loopback = route {
- updateComputer { c in
- c.name = h.name
- if let device = h.device { c.device = device }
- }
- }
- // Host upgraded since the cache was written: its data may carry new fields.
- if let stamp = cacheStamp, stamp != "\(Self.appBuild)/\(h.version)" {
- rev = 0
- cacheStamp = nil
- }
+ try await refreshHello(client)
+ guard !Task.isCancelled, !retired else { return }
+ if mismatch != nil {
+ // Reached, but nothing to sync until one side updates. A host update restarts
+ // the link (and this loop) anyway; this catches one that doesn't.
+ setConnection(.online)
+ try await Task.sleep(for: Self.mismatchRecheck)
+ continue
}
if case .loopback = route {
accessRequests = (try? await client.accessRequests()) ?? accessRequests
@@ -462,6 +481,45 @@ public final class BotStore {
}
}
+ /// Asked on every (re)connect: the host may have been updated while this app was away.
+ private func refreshHello(_ client: HostClient) async throws {
+ let h: Hello
+ do {
+ h = try await client.hello()
+ } catch let error as DecodingError {
+ // Its version and `minApp` still say which side to update.
+ let version: HostVersion = try await client.call("hello")
+ guard !Task.isCancelled, !retired else { return }
+ log.error("undecodable hello from host \(version.version)")
+ noteHostVersion(version)
+ Motion.animate { unreadable = true }
+ if mismatch == nil { throw error }
+ return
+ }
+ guard !Task.isCancelled, !retired else { return }
+ noteHostVersion(HostVersion(version: h.version, minApp: h.minApp))
+ hello = h
+ if case .loopback = route {
+ updateComputer { c in
+ c.name = h.name
+ if let device = h.device { c.device = device }
+ }
+ }
+ }
+
+ private func noteHostVersion(_ new: HostVersion) {
+ let cached = cacheStamp.map { $0 != "\(Self.appBuild)/\(new.version)" } ?? false
+ if cached || (hostVersion.map { $0.version != new.version } ?? false) {
+ // A different host version: its data may carry new fields, so fetch it all again.
+ rev = 0
+ rewound = false
+ unreadable = false
+ }
+ cacheStamp = nil
+ // An update notice may appear or go away with it.
+ if new != hostVersion { Motion.animate { hostVersion = new } }
+ }
+
private func apply(_ event: HostEvent) {
switch event {
case let .hello(id, hostRev, newUsage, newScreen):
@@ -518,6 +576,10 @@ public final class BotStore {
rewound = true
rev = 0
restartEvents()
+ } else if !unreadable {
+ Motion.animate { unreadable = true }
+ // A newer host this app can't follow: stop syncing and ask for an update.
+ if mismatch != nil { restartEvents() }
}
}
scheduleSave()
diff --git a/kit/Sources/CodyncUI/Thread/RepliesView.swift b/kit/Sources/CodyncUI/Thread/RepliesView.swift
index d840d803..590d67a0 100644
--- a/kit/Sources/CodyncUI/Thread/RepliesView.swift
+++ b/kit/Sources/CodyncUI/Thread/RepliesView.swift
@@ -60,7 +60,15 @@ struct RepliesView: View {
}
.defaultScrollAnchor(.bottom)
.scrollDismissesKeyboard(.interactively)
- .safeAreaInset(edge: .bottom) { Composer(botId: botId, thread: rootId) }
+ .safeAreaInset(edge: .bottom) {
+ if let mismatch = model.mismatch {
+ UpdateNeededCard(store: model, mismatch: mismatch)
+ .padding(.horizontal, 16)
+ .padding(.bottom, 8)
+ } else {
+ Composer(botId: botId, thread: rootId)
+ }
+ }
}
.background(Palette.background)
.task(id: rootId) { await model.loadThread(botId, root: rootId) }
diff --git a/kit/Sources/CodyncUI/Thread/ThreadView.swift b/kit/Sources/CodyncUI/Thread/ThreadView.swift
index 0f58c1e2..2be87151 100644
--- a/kit/Sources/CodyncUI/Thread/ThreadView.swift
+++ b/kit/Sources/CodyncUI/Thread/ThreadView.swift
@@ -155,14 +155,23 @@ public struct ThreadView: View {
.background(Palette.background)
.safeAreaInset(edge: .bottom) {
VStack(spacing: 6) {
- #if os(iOS)
- Composer(botId: botId,
- onCall: !calling && bot?.isGroup == false ? { calling = true } : nil,
- onInterrupt: callSpeaking ? interruptCall : nil)
- #else
- Composer(botId: botId)
- #endif
+ if let mismatch = model.mismatch {
+ // Nothing sent now could be read on the other side.
+ UpdateNeededCard(store: model, mismatch: mismatch)
+ .padding(.horizontal, 16)
+ .padding(.bottom, 8)
+ .transition(.opacity)
+ } else {
+ #if os(iOS)
+ Composer(botId: botId,
+ onCall: !calling && bot?.isGroup == false ? { calling = true } : nil,
+ onInterrupt: callSpeaking ? interruptCall : nil)
+ #else
+ Composer(botId: botId)
+ #endif
+ }
}
+ .animation(Motion.reduced(Motion.layout, reduceMotion), value: model.mismatch)
}
#if os(iOS)
.navigationBarTitleDisplayMode(.inline)
@@ -329,6 +338,7 @@ public struct ThreadView: View {
case .unpaired: return "Not paired"
case .online: break
}
+ if model.mismatch != nil { return "Needs update" }
switch model.hostRoute {
case .relay: return "Connected through Cloudflare"
case .direct: return "Connected over Wi-Fi or Tailscale"
diff --git a/kit/Sources/CodyncUI/UpdateNeededCard.swift b/kit/Sources/CodyncUI/UpdateNeededCard.swift
new file mode 100644
index 00000000..fc068f7e
--- /dev/null
+++ b/kit/Sources/CodyncUI/UpdateNeededCard.swift
@@ -0,0 +1,114 @@
+import CodyncKit
+import SwiftUI
+
+/// Updates this app: the App Store on iPhone, Sparkle on the Mac.
+public struct AppUpdateAction: Sendable {
+ let action: @MainActor @Sendable () -> Void
+
+ public init(_ action: @escaping @MainActor @Sendable () -> Void) { self.action = action }
+
+ @MainActor public func callAsFunction() { action() }
+}
+
+/// Updates a computer's host from this app, for the computers it can (the Mac's own host).
+public struct HostUpdateAction: Sendable {
+ let available: @MainActor @Sendable (BotStore) -> Bool
+ let action: @MainActor @Sendable (BotStore) -> Void
+
+ public init(available: @escaping @MainActor @Sendable (BotStore) -> Bool,
+ _ action: @escaping @MainActor @Sendable (BotStore) -> Void) {
+ self.available = available
+ self.action = action
+ }
+}
+
+public extension EnvironmentValues {
+ @Entry var appUpdate: AppUpdateAction?
+ @Entry var hostUpdate: HostUpdateAction?
+}
+
+/// Says which side has to update before this app and a computer can work together, and offers
+/// the update where this app can start it. Shown instead of the composer and above the
+/// computer's bots (docs/reference/compatibility.md).
+public struct UpdateNeededCard: View {
+ let store: BotStore
+ let mismatch: VersionMismatch
+ @Environment(\.appUpdate) private var appUpdate
+ @Environment(\.hostUpdate) private var hostUpdate
+
+ public init(store: BotStore, mismatch: VersionMismatch) {
+ self.store = store
+ self.mismatch = mismatch
+ }
+
+ public var body: some View {
+ HStack(alignment: .top, spacing: 12) {
+ Image(systemName: "arrow.down.circle")
+ .font(.title3)
+ .foregroundStyle(Palette.warning)
+ .accessibilityHidden(true)
+ VStack(alignment: .leading, spacing: 6) {
+ Text(title).font(.subheadline.weight(.semibold)).foregroundStyle(Palette.text)
+ Text(detail)
+ .font(.footnote)
+ .foregroundStyle(Palette.secondary)
+ .fixedSize(horizontal: false, vertical: true)
+ if let action {
+ Button(action.title, action: action.run)
+ .buttonStyle(.primary)
+ .padding(.top, 4)
+ }
+ }
+ Spacer(minLength: 0)
+ }
+ .padding(14)
+ .background(Palette.surface, in: RoundedRectangle(cornerRadius: 16, style: .continuous))
+ .accessibilityElement(children: .contain)
+ }
+
+ var title: String { UpdateNeededText.title(mismatch, host: store.hostName) }
+ var detail: String {
+ UpdateNeededText.detail(mismatch, host: store.hostName, hostVersion: store.hostVersion?.version,
+ // With a button here, instructions for that computer would only confuse.
+ os: store.hello?.os, instructions: action == nil)
+ }
+
+ private var action: (title: String, run: () -> Void)? {
+ switch mismatch {
+ case .updateApp:
+ guard let appUpdate else { return nil }
+ return ("Update Codync", { appUpdate() })
+ case .updateHost:
+ guard let hostUpdate, hostUpdate.available(store) else { return nil }
+ return ("Update \(store.hostName)", { hostUpdate.action(store) })
+ }
+ }
+}
+
+/// The words every client uses for a version mismatch (the Linux app and the terminal client
+/// mirror them).
+public enum UpdateNeededText {
+ public static func title(_ mismatch: VersionMismatch, host: String) -> String {
+ switch mismatch {
+ case .updateApp: "Update this app"
+ case .updateHost: "Update Codync on \(host)"
+ }
+ }
+
+ public static func detail(_ mismatch: VersionMismatch, host: String, hostVersion: String?, os: String?,
+ instructions: Bool = true) -> String {
+ switch mismatch {
+ case let .updateApp(minimum):
+ let runs = hostVersion.map { "\(host) runs Codync \($0) and" } ?? host
+ return "\(runs) needs this app to be \(minimum) or newer. Your chats are safe on the computer."
+ case let .updateHost(version, minimum):
+ let how = switch os {
+ case "macos": "Open Codync on that Mac and choose Check for Updates."
+ case "linux": "Run codync-host update there, or use Check for updates in its Codync app."
+ default: "Update Codync on that computer."
+ }
+ let needs = "\(host) runs Codync \(version); this app needs \(minimum) or newer."
+ return instructions ? "\(needs) \(how)" : needs
+ }
+ }
+}
diff --git a/kit/Tests/CodyncKitTests/CodyncKitTests.swift b/kit/Tests/CodyncKitTests/CodyncKitTests.swift
index 42ca6f7a..4cb5e385 100644
--- a/kit/Tests/CodyncKitTests/CodyncKitTests.swift
+++ b/kit/Tests/CodyncKitTests/CodyncKitTests.swift
@@ -81,3 +81,31 @@ import Testing
#expect(UsageWindow.parseReset("5am (Asia/Taipei)", now: now) == at(9, 26, 5, 0, 2026))
#expect(UsageWindow.parseReset("soon") == nil)
}
+
+// MARK: - Version compatibility (mirrors host/src/compat.rs)
+
+@Test func versionsParseLikeTheHost() {
+ #expect(AppVersion.parse("2.4.1") == [2, 4, 1])
+ #expect(AppVersion.parse(" v2.4 ") == [2, 4, 0])
+ #expect(AppVersion.parse("3") == [3, 0, 0])
+ #expect(AppVersion.parse("2.4.0-beta.1+77") == [2, 4, 0])
+ for bad in ["", "abc", "2.x", "2.4.0.1", "-1.0.0", "2..0", "+1.0.0", "2.4.0"] {
+ #expect(AppVersion.parse(bad) == nil, "\(bad)")
+ }
+ #expect(AppVersion.isBelow("2.9.9", "2.10.0"))
+ #expect(!AppVersion.isBelow("2.4.0", "2.4.0"))
+ #expect(!AppVersion.isBelow("2.4.0-dev", "2.4.0"))
+ // Unreadable versions never lock anyone out.
+ #expect(!AppVersion.isBelow("", "2.4.0"))
+ #expect(!AppVersion.isBelow("2.0.0", "garbage"))
+}
+
+@Test func mismatchNamesTheSideToUpdate() {
+ #expect(VersionMismatch.check(app: "2.4.0", minHost: "2.3.0", hostVersion: "2.4.0", minApp: "2.3.0") == nil)
+ #expect(VersionMismatch.check(app: "2.4.0", minHost: "2.3.0", hostVersion: "2.6.0", minApp: "2.5.0") == .updateApp(minimum: "2.5.0"))
+ #expect(VersionMismatch.check(app: "2.6.0", minHost: "2.5.0", hostVersion: "2.4.0", minApp: "2.3.0") == .updateHost(version: "2.4.0", minimum: "2.5.0"))
+ // Hosts from before minApp: only this app's floor applies.
+ #expect(VersionMismatch.check(app: "2.4.0", minHost: "2.3.0", hostVersion: "2.3.1", minApp: nil) == nil)
+ #expect(VersionMismatch.check(app: "2.4.0", minHost: "2.3.0", hostVersion: "2.2.3", minApp: nil) == .updateHost(version: "2.2.3", minimum: "2.3.0"))
+ #expect(VersionMismatch.check(app: "", minHost: "2.3.0", hostVersion: "2.6.0", minApp: "2.5.0") == nil)
+}
diff --git a/kit/Tests/CodyncUITests/StoreTests.swift b/kit/Tests/CodyncUITests/StoreTests.swift
index 908ab778..202bd89d 100644
--- a/kit/Tests/CodyncUITests/StoreTests.swift
+++ b/kit/Tests/CodyncUITests/StoreTests.swift
@@ -25,6 +25,10 @@ actor FakeRemote: RemoteTransport {
private(set) var enqueued: [String] = []
var cancelResult = MailboxCancel.cancelled
+ private var hello = #"{"hostId":"h1","name":"Mac","version":"3.0.0","os":"macos","backends":[],"rev":0}"#
+ /// What `hello` answers from now on (a host updated in place keeps its link).
+ func setHello(_ json: String) { hello = json }
+
init(_ state: LinkState) { self.state = state }
var subscribed: Bool { !eventSinks.isEmpty }
@@ -52,7 +56,7 @@ actor FakeRemote: RemoteTransport {
}
switch method {
case "hello":
- return Data(#"{"hostId":"h1","name":"Mac","version":"3.0.0","os":"macos","backends":[],"rev":0}"#.utf8)
+ return Data(hello.utf8)
case "markRead":
readAttempts += 1
if failReadReceipts { throw HostError.unreachable }
@@ -556,3 +560,82 @@ extension FakeRemote {
try await Task.sleep(for: .milliseconds(100))
#expect(await fake.calls.filter { $0 == "respondPermission" }.count == 1)
}
+
+// MARK: - Version compatibility (docs/reference/compatibility.md)
+
+private func helloJSON(version: String, minApp: String? = nil, backends: String = "[]") -> String {
+ let min = minApp.map { #","minApp":"\#($0)""# } ?? ""
+ return #"{"hostId":"h1","name":"Mac","version":"\#(version)"\#(min),"os":"macos","backends":\#(backends),"rev":0}"#
+}
+
+@MainActor @Test func hostNeedingANewerAppStopsSyncAndAsksForTheUpdate() async throws {
+ let (storage, suite) = context()
+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }
+ let fake = FakeRemote(.ready(.relay))
+ await fake.setHello(helloJSON(version: "2.6.0", minApp: "2.5.0"))
+ let store = BotStore(computer: randomComputer("Mac"), route: .channel, clientKind: "ios", storage: storage, appVersion: "2.4.0") { fake }
+ defer { store.retire() }
+ store.setActive(true)
+ #expect(await until { store.mismatch == .updateApp(minimum: "2.5.0") })
+ #expect(await until { store.connection == .online })
+ try await Task.sleep(for: .milliseconds(200))
+ // Nothing this app can't read is synced.
+ #expect(await !fake.subscribed)
+}
+
+@MainActor @Test func updatedHostIsNoticedOnReconnect() async throws {
+ let (storage, suite) = context()
+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }
+ let fake = FakeRemote(.ready(.relay))
+ await fake.setHello(helloJSON(version: "2.2.0"))
+ let store = BotStore(computer: randomComputer("Mac"), route: .channel, clientKind: "ios", storage: storage, appVersion: "2.4.0") { fake }
+ defer { store.retire() }
+ store.setActive(true)
+ #expect(await until { store.mismatch == .updateHost(version: "2.2.0", minimum: VersionMismatch.minHost) })
+ // The host updates and restarts: the link drops and comes back.
+ await fake.setHello(helloJSON(version: "2.4.0", minApp: "2.3.0"))
+ await fake.set(.connecting)
+ await fake.set(.ready(.relay))
+ #expect(await until { store.mismatch == nil })
+ #expect(await until { await fake.subscribed })
+ #expect(store.hostVersion == HostVersion(version: "2.4.0", minApp: "2.3.0"))
+}
+
+@MainActor @Test func unreadableHelloStillSaysWhichSideToUpdate() async throws {
+ let (storage, suite) = context()
+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }
+ // A newer host whose hello this app can't decode, with or without a minApp that covers it.
+ for minApp in ["2.6.0", "2.0.0"] {
+ let fake = FakeRemote(.ready(.relay))
+ await fake.setHello(helloJSON(version: "2.6.0", minApp: minApp, backends: #""changed shape""#))
+ let store = BotStore(computer: randomComputer("Mac"), route: .channel, clientKind: "ios", storage: storage, appVersion: "2.4.0") { fake }
+ store.setActive(true)
+ #expect(await until { store.mismatch == .updateApp(minimum: "2.6.0") }, "minApp \(minApp)")
+ #expect(store.hello == nil)
+ store.retire()
+ }
+}
+
+@MainActor @Test func unreadableEventsAskForAnAppUpdateOnlyFromANewerHost() async throws {
+ let (storage, suite) = context()
+ defer { UserDefaults(suiteName: suite)?.removePersistentDomain(forName: suite) }
+ for (hostVersion, appIsBehind) in [("2.6.0", true), ("2.4.0", false)] {
+ let fake = FakeRemote(.ready(.relay))
+ await fake.setHello(helloJSON(version: hostVersion, minApp: "2.3.0"))
+ let store = BotStore(computer: randomComputer("Mac"), route: .channel, clientKind: "ios", storage: storage, appVersion: "2.4.0") { fake }
+ store.setActive(true)
+ let broken = #"{"type":"bot","bot":{"id":"b1","name":7}}"#
+ #expect(await until { await fake.eventSubscriptionCount == 1 })
+ await fake.emit(broken)
+ // The first one rewinds and subscribes again; the second one is final.
+ #expect(await until { await fake.eventSubscriptionCount == 2 })
+ await fake.emit(broken)
+ if appIsBehind {
+ #expect(await until { store.mismatch == .updateApp(minimum: hostVersion) })
+ } else {
+ try await Task.sleep(for: .milliseconds(200))
+ #expect(store.mismatch == nil)
+ }
+ store.retire()
+ }
+}