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.

Each computer picks its route order: Auto (Wi-Fi or Tailscale, then Cloudflare), Cloudflare first with a direct fallback, or never Cloudflare; the switch lives on the computer's row

leepokai706700df1af3
diff --git a/apps/ios/Views/AccountSwitcherView.swift b/apps/ios/Views/AccountSwitcherView.swift
index 88dad65e..42911f5b 100644
--- a/apps/ios/Views/AccountSwitcherView.swift
+++ b/apps/ios/Views/AccountSwitcherView.swift
@@ -23,10 +23,8 @@ struct AccountSwitcherButton: View {
struct AccountSwitcherView: View {
@Environment(AppStore.self) private var app
@Environment(AccountSession.self) private var account
- @Environment(AccountStore.self) private var accounts
@State private var showSettings = false
@State private var confirmSignOut = false
- @State private var route = ConnectionRoute.current
@State private var pairing = false
var body: some View {
@@ -53,10 +51,6 @@ struct AccountSwitcherView: View {
switcher
}
- CardSection("Connection") {
- RoutePicker(selection: Binding(get: { route }, set: { setRoute($0) }))
- }
-
CardSection {
Button { showSettings = true } label: {
RowLabel("Computers", systemImage: "desktopcomputer", chevron: true)
@@ -100,13 +94,6 @@ struct AccountSwitcherView: View {
}
}
- /// Saved for this iPhone; every computer reconnects over the new route right away.
- private func setRoute(_ new: ConnectionRoute) {
- withAnimation(Motion.morph) { route = new }
- ConnectionRoute.current = new
- for computer in accounts.computers { accounts.store(for: computer.id)?.restartStream() }
- }
-
/// The big picture: your face and address when signed in, the Google button when not.
@ViewBuilder private var profile: some View {
if account.isSignedIn {
@@ -185,48 +172,6 @@ struct AccountSwitcherView: View {
}
}
-/// Three routes as icons; one line under them says what the chosen one does.
-private struct RoutePicker: View {
- @Binding var selection: ConnectionRoute
-
- private func info(_ route: ConnectionRoute) -> (icon: String, title: String, detail: String) {
- switch route {
- case .automatic: ("wand.and.sparkles", "Auto", "Wi-Fi or Tailscale when it answers, Cloudflare otherwise.")
- case .direct: ("point.3.connected.trianglepath.dotted", "Wi-Fi · Tailscale", "Direct only. Nothing goes through Cloudflare.")
- case .relay: ("cloud", "Cloudflare", "Always through Cloudflare, encrypted, from anywhere.")
- }
- }
-
- var body: some View {
- VStack(alignment: .leading, spacing: 12) {
- HStack(spacing: 8) {
- ForEach(ConnectionRoute.allCases, id: \.self) { route in
- let item = info(route)
- let on = route == selection
- Button { selection = route } label: {
- VStack(spacing: 6) {
- Image(systemName: item.icon).font(.system(size: 20))
- Text(item.title).font(.caption.weight(.medium))
- }
- .foregroundStyle(on ? Palette.onAccent : Palette.secondary)
- .frame(maxWidth: .infinity, minHeight: 64)
- .background(on ? Palette.accentFill : Palette.background, in: RoundedRectangle(cornerRadius: 14, style: .continuous))
- .contentShape(Rectangle())
- }
- .buttonStyle(PressScale())
- .accessibilityLabel(item.title)
- .accessibilityHint(item.detail)
- .accessibilityAddTraits(on ? .isSelected : [])
- }
- }
- Text(info(selection).detail)
- .font(.caption)
- .foregroundStyle(Palette.secondary)
- .contentTransition(.opacity)
- }
- }
-}
-
/// Google's mark plus the one line it needs; used wherever sign-in is offered.
struct GoogleSignInButton: View {
@Environment(AccountSession.self) private var account
diff --git a/apps/ios/Views/SettingsView.swift b/apps/ios/Views/SettingsView.swift
index 33a4b517..9b07e388 100644
--- a/apps/ios/Views/SettingsView.swift
+++ b/apps/ios/Views/SettingsView.swift
@@ -219,6 +219,7 @@ private struct ComputerRow: View {
let remove: () -> Void
@Environment(AccountStore.self) private var accounts
@State private var coloring = false
+ @State private var routing = false
var body: some View {
HStack(spacing: 12) {
@@ -236,6 +237,15 @@ private struct ComputerRow: View {
if store.screen != nil, store.connection == .online {
IconButton("Screen", systemImage: "display", action: openScreen)
}
+ // Which route goes first, and whether Cloudflare is a fallback at all.
+ IconButton("Connection", systemImage: preference.icon, selected: routing) { routing = true }
+ .codyncMenu(isPresented: $routing) {
+ ConnectionRoute.allCases.map { route in
+ MenuItem(route.title, icon: route.icon, selected: route == preference) {
+ accounts.setRoute(store.computer.id, route)
+ }
+ }
+ }
if inAccount != nil {
Image(systemName: "person.crop.circle.badge.checkmark")
.foregroundStyle(Palette.tertiary)
@@ -277,11 +287,13 @@ private struct ComputerRow: View {
}
}
+ private var preference: ConnectionRoute { store.computer.route ?? .automatic }
+
private var detail: String {
guard store.connection == .online else { return store.statusText }
let count = store.roster.count
let route = switch store.hostRoute {
- case .direct: " · Direct"
+ case .direct: " · Wi-Fi/Tailscale"
case .relay: " · Cloudflare"
default: ""
}
@@ -366,3 +378,21 @@ private struct SwatchPanel: View {
.padding(14)
}
}
+
+private extension ConnectionRoute {
+ var title: String {
+ switch self {
+ case .automatic: "Auto: Wi-Fi or Tailscale, then Cloudflare"
+ case .cloudflareFirst: "Cloudflare, then Wi-Fi or Tailscale"
+ case .directOnly: "Wi-Fi or Tailscale only, never Cloudflare"
+ }
+ }
+
+ var icon: String {
+ switch self {
+ case .automatic: "arrow.triangle.branch"
+ case .cloudflareFirst: "cloud"
+ case .directOnly: "wifi"
+ }
+ }
+}
diff --git a/apps/shared/ComputerStatus.swift b/apps/shared/ComputerStatus.swift
index b3998576..d11fc1cd 100644
--- a/apps/shared/ComputerStatus.swift
+++ b/apps/shared/ComputerStatus.swift
@@ -23,9 +23,9 @@ struct RouteIcon: View {
var body: some View {
switch route {
case .direct:
- Image(systemName: "wifi").accessibilityLabel("Direct connection")
+ Image(systemName: "wifi").accessibilityLabel("Wi-Fi or Tailscale")
case .relay:
- Image(systemName: "cloud").accessibilityLabel("Through the encrypted relay")
+ Image(systemName: "cloud").accessibilityLabel("Through Cloudflare")
case .loopback, nil:
EmptyView()
}
diff --git a/kit/Sources/CodyncKit/Client/ChannelTransport.swift b/kit/Sources/CodyncKit/Client/ChannelTransport.swift
index 9044b0e4..10b7c6f6 100644
--- a/kit/Sources/CodyncKit/Client/ChannelTransport.swift
+++ b/kit/Sources/CodyncKit/Client/ChannelTransport.swift
@@ -5,23 +5,6 @@ import os
private let log = Logger(subsystem: "com.pokai.Codync", category: "Channel")
-/// How this device reaches its computers; the user picks it, every channel reads it on each attempt.
-public enum ConnectionRoute: String, CaseIterable, Sendable {
- /// Direct (Wi-Fi, Tailscale) when it answers within 1.5 s, otherwise the Cloudflare relay.
- case automatic
- /// Wi-Fi and Tailscale only: nothing goes through the cloud.
- case direct
- /// Always the Cloudflare relay, even at home.
- case relay
-
- private static let key = "connectionRoute"
-
- public static var current: ConnectionRoute {
- get { UserDefaults(suiteName: SharedStore.appGroup)?.string(forKey: key).flatMap(Self.init(rawValue:)) ?? .automatic }
- set { UserDefaults(suiteName: SharedStore.appGroup)?.set(newValue.rawValue, forKey: key) }
- }
-}
-
/// The end-to-end encrypted channel to one computer (§6, §7): direct WebSocket on the LAN when it
/// answers within 1.5 s, otherwise the cloud relay. Inner RPC multiplexes calls and streams over
/// one channel; the relay adds presence and the offline mailbox. Reconnects by itself until `shutdown()`.
@@ -278,9 +261,13 @@ public actor ChannelTransport: RemoteTransport {
}
private func attempt() async -> Outcome {
- let route = ConnectionRoute.current
- // Relay only still goes direct for a computer that has no relay.
- let directURLs = route == .relay && computer.cloud != nil ? [] : computer.urls.compactMap(Self.channelURL)
+ let route = computer.route ?? .automatic
+ // Cloudflare first: the relay, and only if it can't be reached, the direct addresses below.
+ if route == .cloudflareFirst, let cloud = computer.cloud,
+ let socket = try? await dial(.relay(relayRequest(cloud))) {
+ return await serve(socket, route: .relay, keys: nil)
+ }
+ let directURLs = computer.urls.compactMap(Self.channelURL)
if !directURLs.isEmpty {
switch await raceDirect(directURLs) {
case let .connected(socket, keys): return await serve(socket, route: .direct, keys: keys)
@@ -299,7 +286,8 @@ public actor ChannelTransport: RemoteTransport {
case .none: break
}
}
- guard let cloud = computer.cloud, route != .direct else { return .retry(HostError.unreachable.localizedDescription) }
+ // Already tried first, or ruled out by the user (privacy): no second relay attempt.
+ guard let cloud = computer.cloud, route == .automatic else { return .retry(HostError.unreachable.localizedDescription) }
let socket: any ChannelSocket
do {
socket = try await dial(.relay(relayRequest(cloud)))
diff --git a/kit/Sources/CodyncKit/Models/Computer.swift b/kit/Sources/CodyncKit/Models/Computer.swift
index 7b6cbbab..2b59d83f 100644
--- a/kit/Sources/CodyncKit/Models/Computer.swift
+++ b/kit/Sources/CodyncKit/Models/Computer.swift
@@ -19,6 +19,8 @@ public struct Computer: Codable, Hashable, Sendable, Identifiable {
public var device: String?
/// The badge color picked on this device (an `AvatarPalette` id).
public var color: String?
+ /// How this device reaches the computer, picked per computer; nil = `.automatic`.
+ public var route: ConnectionRoute?
public init(id: ComputerID, name: String, signKey: String, boxKey: String? = nil, urls: [String] = [],
cloud: URL? = nil, device: String? = nil, color: String? = nil) {
@@ -38,6 +40,21 @@ public struct Computer: Codable, Hashable, Sendable, Identifiable {
}
}
+/// The order routes are tried in. Every paired computer has both routes; this only says which goes first
+/// and whether the other one is a fallback.
+public enum ConnectionRoute: String, Codable, CaseIterable, Sendable {
+ /// Wi-Fi or Tailscale when it answers within 1.5 s, Cloudflare when it doesn't.
+ case automatic
+ /// Cloudflare, falling back to Wi-Fi or Tailscale when Cloudflare can't be reached.
+ case cloudflareFirst
+ /// Wi-Fi and Tailscale only: nothing goes through Cloudflare, even when they fail.
+ case directOnly
+
+ public init(from decoder: any Decoder) throws {
+ self = Self(rawValue: try decoder.singleValueContainer().decode(String.self)) ?? .automatic
+ }
+}
+
/// A bot on a computer in an account context: bot IDs are only unique per computer.
/// (Multiple computers are future work; with one computer this is just the bot's address.)
public struct BotReference: Codable, Hashable, Sendable {
diff --git a/kit/Sources/CodyncUI/Store/AccountStore.swift b/kit/Sources/CodyncUI/Store/AccountStore.swift
index 8b1e8cf4..06f0e701 100644
--- a/kit/Sources/CodyncUI/Store/AccountStore.swift
+++ b/kit/Sources/CodyncUI/Store/AccountStore.swift
@@ -132,6 +132,19 @@ public final class AccountStore {
refreshList()
}
+ /// Saved with the computer on this device; its channel reconnects over the new order right away.
+ public func setRoute(_ id: ComputerID, _ route: ConnectionRoute) {
+ let value: ConnectionRoute? = route == .automatic ? nil : route
+ if let i = saved.firstIndex(where: { $0.id == id }) {
+ saved[i].route = value
+ persist()
+ }
+ if let i = attached.firstIndex(where: { $0.id == id }) { attached[i].route = value }
+ stores[id]?.updateComputer { $0.route = value }
+ stores[id]?.restartStream()
+ refreshList()
+ }
+
public func setColor(_ id: ComputerID, _ color: String) {
if let i = saved.firstIndex(where: { $0.id == id }) {
saved[i].color = color
diff --git a/kit/Tests/CodyncKitTests/ChannelTransportTests.swift b/kit/Tests/CodyncKitTests/ChannelTransportTests.swift
index 3cbe82e8..4ebd254e 100644
--- a/kit/Tests/CodyncKitTests/ChannelTransportTests.swift
+++ b/kit/Tests/CodyncKitTests/ChannelTransportTests.swift
@@ -253,6 +253,33 @@ private func waitFor(_ states: AsyncStream<LinkState>, _ match: (LinkState) -> B
await t.shutdown()
}
+@Test(.timeLimit(.minutes(1))) func routeOrderFollowsTheComputer() async throws {
+ var computer = v.computer
+ computer.urls = ["http://192.168.1.20:19222"]
+ computer.cloud = URL(string: "https://cloud.example.dev")
+
+ computer.route = .cloudflareFirst
+ let (dial, sockets) = fakeDialer()
+ let first = ChannelTransport(computer: computer, identity: v.identity, pairingCode: nil, dial: dial, watchesNetwork: false)
+ await first.start()
+ var it = sockets.makeAsyncIterator()
+ let socket = try #require(await it.next())
+ guard case .relay = socket.endpoint else { Issue.record("Cloudflare first dials the relay first"); return }
+ await first.shutdown()
+
+ computer.route = .directOnly
+ let (dial2, sockets2) = fakeDialer()
+ let second = ChannelTransport(computer: computer, identity: v.identity, pairingCode: nil, dial: dial2, watchesNetwork: false)
+ await second.start()
+ var it2 = sockets2.makeAsyncIterator()
+ let stranger = HostSide(try #require(await it2.next()))
+ _ = try await stranger.raw()
+ await stranger.push(["t": "reject", "code": "unauthorized"])
+ let retry = try #require(await it2.next())
+ if case .relay = retry.endpoint { Issue.record("direct only never dials the relay") }
+ await second.shutdown()
+}
+
@Test(.timeLimit(.minutes(1))) func relayPresenceAndMailbox() async throws {
let (dial, sockets) = fakeDialer()
var computer = v.computer