Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// One attached view represented in a host's runtime-presence snapshot.
public struct MobileAttachedView: Decodable, Sendable, Equatable {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Mark pure value-model structs as nonisolated.

As per coding guidelines, please mark Codable, Identifiable, Sendable, and pure value-model structs as nonisolated to prevent them from implicitly inheriting @MainActor isolation under Swift 6 strict concurrency defaults.

  • Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileAttachedView.swift#L2-L2: Add the nonisolated modifier to MobileAttachedView.
  • Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceGitState.swift#L2-L2: Add the nonisolated modifier to MobileWorkspaceGitState.
📍 Affects 2 files
  • Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileAttachedView.swift#L2-L2 (this comment)
  • Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceGitState.swift#L2-L2
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileAttachedView.swift` at
line 2, Mark the pure value-model structs MobileAttachedView in
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileAttachedView.swift:2-2
and MobileWorkspaceGitState in
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceGitState.swift:2-2
as nonisolated, preserving their existing Codable, Sendable, and Equatable
declarations.

Source: Coding guidelines

/// The stable client identifier supplied by the attached view.
public let clientID: String
/// The number of active transports currently identifying as this client.
public let connectionCount: Int
/// A user-facing device name, when a newer client supplies one.
public let displayName: String?
/// The view kind, such as `ios` or `macos`, when supplied.
public let kind: String?

private enum CodingKeys: String, CodingKey {
case clientID = "client_id"
case connectionCount = "connection_count"
case displayName = "display_name"
case kind
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public struct MobileSyncWorkspaceListResponse: Decodable, Sendable {
/// Whether the workspace has unread activity on the Mac. `nil` on Macs
/// old enough not to emit it (the row then shows no unread dot).
public let hasUnread: Bool?
/// Versioned semantic state for richer remote views. `nil` on hosts
/// that predate `workspace.remote_state.v1`.
public let remoteState: MobileWorkspaceRemoteState?
/// Terminals belonging to this workspace.
public let terminals: [Terminal]

Expand All @@ -54,6 +57,7 @@ public struct MobileSyncWorkspaceListResponse: Decodable, Sendable {
case previewAt = "preview_at"
case lastActivityAt = "last_activity_at"
case hasUnread = "has_unread"
case remoteState = "remote_state"
case terminals
}
}
Expand Down Expand Up @@ -115,6 +119,9 @@ public struct MobileSyncWorkspaceListResponse: Decodable, Sendable {
/// Group sections, in section order. Empty on Macs old enough not to emit
/// groups (the field is decoded with `decodeIfPresent`).
public let groups: [Group]
/// Versioned presence for views currently attached to this runtime. `nil`
/// on hosts that predate `view.presence.v1`.
public let viewPresence: MobileViewPresence?
/// Identifier of a workspace created by the request, if any.
public let createdWorkspaceID: String?
/// Identifier of a terminal created by the request, if any.
Expand All @@ -123,6 +130,7 @@ public struct MobileSyncWorkspaceListResponse: Decodable, Sendable {
private enum CodingKeys: String, CodingKey {
case workspaces
case groups
case viewPresence = "view_presence"
case createdWorkspaceID = "created_workspace_id"
case createdTerminalID = "created_terminal_id"
}
Expand All @@ -136,6 +144,7 @@ public struct MobileSyncWorkspaceListResponse: Decodable, Sendable {
let container = try decoder.container(keyedBy: CodingKeys.self)
workspaces = try container.decode([Workspace].self, forKey: .workspaces)
groups = try container.decodeIfPresent([Group].self, forKey: .groups) ?? []
viewPresence = try container.decodeIfPresent(MobileViewPresence.self, forKey: .viewPresence)
createdWorkspaceID = try container.decodeIfPresent(String.self, forKey: .createdWorkspaceID)
createdTerminalID = try container.decodeIfPresent(String.self, forKey: .createdTerminalID)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// Versioned presence for views currently attached to a runtime.
public struct MobileViewPresence: Decodable, Sendable, Equatable {
/// The schema version of this presence object.
public let version: Int
/// Identified views, grouped by stable client identifier.
public let views: [MobileAttachedView]

private enum CodingKeys: String, CodingKey {
case version
case views
}

/// Decodes presence, accepting an early host that emits a version without view rows.
/// - Parameter decoder: The decoder for the presence object.
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
version = try container.decode(Int.self, forKey: .version)
views = try container.decodeIfPresent([MobileAttachedView].self, forKey: .views) ?? []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// The lifecycle state of an agent attached to a remote workspace.
public enum MobileWorkspaceAgentLifecycle: String, Decodable, Sendable, Equatable {
/// The agent is actively working.
case running
/// The agent is alive but waiting for more work.
case idle
/// The agent is blocked on a decision or other user input.
case needsInput = "needs_input"
/// The host reported a lifecycle value this client does not recognize.
case unknown

/// Decodes a lifecycle while preserving forward compatibility with newer hosts.
/// - Parameter decoder: The decoder for the lifecycle string.
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(String.self)
self = Self(rawValue: rawValue) ?? .unknown
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// One agent's aggregated state within a remote workspace.
public struct MobileWorkspaceAgentStatus: Decodable, Sendable, Equatable {
/// The host's stable agent identifier, such as `claude_code` or `codex`.
public let agent: String
/// The most important lifecycle currently reported for the agent.
public let state: MobileWorkspaceAgentLifecycle
/// Panel identifiers contributing to the aggregated lifecycle.
public let panelIDs: [String]

private enum CodingKeys: String, CodingKey {
case agent
case state
case panelIDs = "panel_ids"
}

/// Decodes an agent status, accepting hosts that omit the optional panel detail.
/// - Parameter decoder: The decoder for the agent-status object.
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
agent = try container.decode(String.self, forKey: .agent)
state = try container.decode(MobileWorkspaceAgentLifecycle.self, forKey: .state)
panelIDs = try container.decodeIfPresent([String].self, forKey: .panelIDs) ?? []
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// The aggregate CI state associated with a remote workspace's pull request.
public enum MobileWorkspaceCIStatus: String, Decodable, Sendable, Equatable {
/// All reported checks completed successfully.
case success
/// At least one reported check failed.
case failure
/// At least one reported check is still running or queued.
case pending
/// The host has no authoritative CI result or reported a newer value.
case unknown

/// Decodes a CI state while preserving forward compatibility with newer hosts.
/// - Parameter decoder: The decoder for the CI-state string.
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(String.self)
self = Self(rawValue: rawValue) ?? .unknown
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// Git state reported for a remote workspace.
public struct MobileWorkspaceGitState: Decodable, Sendable, Equatable {
/// The first branch in the host sidebar's spatial display order.
public let branch: String
/// Whether that branch's working tree has uncommitted changes.
public let isDirty: Bool

private enum CodingKeys: String, CodingKey {
case branch
case isDirty = "is_dirty"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// Notification and unread state reported for a remote workspace.
public struct MobileWorkspaceNotificationState: Decodable, Sendable, Equatable {
/// The authoritative workspace unread count on the host.
public let unreadCount: Int
/// Whether the host considers the workspace unread.
public let hasUnread: Bool
/// The latest notification identifier, when one exists.
public let latestNotificationID: String?

private enum CodingKeys: String, CodingKey {
case unreadCount = "unread_count"
case hasUnread = "has_unread"
case latestNotificationID = "latest_notification_id"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/// The lifecycle of a pull request associated with a remote workspace.
public enum MobileWorkspacePullRequestLifecycle: String, Decodable, Sendable, Equatable {
/// The pull request is open.
case open
/// The pull request was merged.
case merged
/// The pull request was closed without merging.
case closed
/// The host reported a lifecycle value this client does not recognize.
case unknown

/// Decodes a lifecycle while preserving forward compatibility with newer hosts.
/// - Parameter decoder: The decoder for the lifecycle string.
public init(from decoder: any Decoder) throws {
let container = try decoder.singleValueContainer()
let rawValue = try container.decode(String.self)
self = Self(rawValue: rawValue) ?? .unknown
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/// Pull-request state reported for a remote workspace.
public struct MobileWorkspacePullRequestState: Decodable, Sendable, Equatable {
/// The pull-request number.
public let number: Int
/// The pull-request lifecycle.
public let state: MobileWorkspacePullRequestLifecycle
/// The aggregate CI state known to the host.
public let ciStatus: MobileWorkspaceCIStatus
/// The pull-request URL, when the host supplied it.
public let url: String?
/// The repository or provider label shown by the host.
public let label: String?
/// The normalized head branch, when known.
public let branch: String?
/// Whether the host considers this row stale because it came from an inactive panel.
public let isStale: Bool

private enum CodingKeys: String, CodingKey {
case number
case state
case ciStatus = "ci_status"
case url
case label
case branch
case isStale = "is_stale"
}

/// Decodes pull-request state, defaulting absent CI data to ``MobileWorkspaceCIStatus/unknown``.
/// - Parameter decoder: The decoder for the pull-request object.
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
number = try container.decode(Int.self, forKey: .number)
state = try container.decode(MobileWorkspacePullRequestLifecycle.self, forKey: .state)
ciStatus = try container.decodeIfPresent(MobileWorkspaceCIStatus.self, forKey: .ciStatus) ?? .unknown
url = try container.decodeIfPresent(String.self, forKey: .url)
label = try container.decodeIfPresent(String.self, forKey: .label)
branch = try container.decodeIfPresent(String.self, forKey: .branch)
isStale = try container.decodeIfPresent(Bool.self, forKey: .isStale) ?? false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/// Versioned semantic state attached to one remote workspace-list entry.
public struct MobileWorkspaceRemoteState: Decodable, Sendable, Equatable {
/// The schema version of this nested state object.
public let version: Int
/// Agent lifecycles aggregated by agent identifier.
public let agents: [MobileWorkspaceAgentStatus]
/// Git state, when the host has observed a repository.
public let git: MobileWorkspaceGitState?
/// The first pull request in the host sidebar's spatial display order.
public let pullRequest: MobileWorkspacePullRequestState?
/// Notification and unread state for the workspace.
public let notifications: MobileWorkspaceNotificationState

private enum CodingKeys: String, CodingKey {
case version
case agents
case git
case pullRequest = "pull_request"
case notifications
}

/// Decodes versioned workspace state, accepting a host that omits agent detail.
/// - Parameter decoder: The decoder for the remote-state object.
public init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
version = try container.decode(Int.self, forKey: .version)
agents = try container.decodeIfPresent([MobileWorkspaceAgentStatus].self, forKey: .agents) ?? []
git = try container.decodeIfPresent(MobileWorkspaceGitState.self, forKey: .git)
pullRequest = try container.decodeIfPresent(MobileWorkspacePullRequestState.self, forKey: .pullRequest)
notifications = try container.decode(MobileWorkspaceNotificationState.self, forKey: .notifications)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import Foundation
import Testing
@testable import CmuxMobileRPC

@Suite
struct MobileWorkspaceRemoteStateDecodeTests {
@Test
func decodesVersionedWorkspaceStateAndViewPresence() throws {
let data = Data(#"""
{
"workspaces": [{
"id": "workspace-1",
"title": "Build",
"is_selected": true,
"remote_state": {
"version": 1,
"agents": [
{"agent": "codex", "state": "needs_input", "panel_ids": ["panel-1"]},
{"agent": "claude_code", "state": "idle"}
],
"git": {"branch": "feat/hive", "is_dirty": true},
"pull_request": {
"number": 8082,
"state": "open",
"ci_status": "pending",
"url": "https://github.com/manaflow-ai/cmux/pull/8082",
"label": "PR",
"branch": "feat/hive",
"is_stale": false
},
"notifications": {
"unread_count": 2,
"has_unread": true,
"latest_notification_id": "notification-1"
}
},
"terminals": []
}],
"view_presence": {
"version": 1,
"views": [{
"client_id": "phone-1",
"connection_count": 2,
"display_name": "Austin's iPhone",
"kind": "ios"
}]
}
}
"""#.utf8)

let response = try MobileSyncWorkspaceListResponse.decode(data)
let workspace = try #require(response.workspaces.first)
let state = try #require(workspace.remoteState)
#expect(state.version == 1)
#expect(state.agents.count == 2)
#expect(state.agents[0].state == .needsInput)
#expect(state.agents[0].panelIDs == ["panel-1"])
#expect(state.agents[1].panelIDs.isEmpty)
#expect(state.git == MobileWorkspaceGitState(branch: "feat/hive", isDirty: true))
#expect(state.pullRequest?.number == 8082)
#expect(state.pullRequest?.state == .open)
#expect(state.pullRequest?.ciStatus == .pending)
#expect(state.pullRequest?.isStale == false)
#expect(state.notifications.unreadCount == 2)
#expect(state.notifications.latestNotificationID == "notification-1")

let presence = try #require(response.viewPresence)
#expect(presence.version == 1)
#expect(presence.views.first?.clientID == "phone-1")
#expect(presence.views.first?.connectionCount == 2)
#expect(presence.views.first?.kind == "ios")
}

@Test
func legacyWorkspaceListStillDecodesWithoutAdditiveState() throws {
let data = Data(#"""
{
"workspaces": [{
"id": "workspace-legacy",
"title": "Legacy",
"is_selected": false,
"terminals": []
}]
}
"""#.utf8)

let response = try MobileSyncWorkspaceListResponse.decode(data)
#expect(response.groups.isEmpty)
#expect(response.viewPresence == nil)
#expect(response.workspaces.first?.remoteState == nil)
}

@Test
func unknownLifecycleValuesDegradeWithoutBreakingTheWorkspaceList() throws {
let data = Data(#"""
{
"workspaces": [{
"id": "workspace-future",
"title": "Future",
"is_selected": false,
"remote_state": {
"version": 2,
"agents": [{"agent": "future-agent", "state": "waiting_for_cloud"}],
"git": null,
"pull_request": {
"number": 1,
"state": "draft",
"ci_status": "cancelled"
},
"notifications": {"unread_count": 0, "has_unread": false}
},
"terminals": []
}]
}
"""#.utf8)

let state = try #require(MobileSyncWorkspaceListResponse.decode(data).workspaces.first?.remoteState)
#expect(state.version == 2)
#expect(state.agents.first?.state == .unknown)
#expect(state.pullRequest?.state == .unknown)
#expect(state.pullRequest?.ciStatus == .unknown)
}
}
Loading