Repository navigation
feat(mobile): publish richer remote workspace state #8112
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileAttachedView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
| /// 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 | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileViewPresence.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) ?? [] | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceAgentLifecycle.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceAgentStatus.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) ?? [] | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceCIStatus.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceGitState.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceNotificationState.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
19 changes: 19 additions & 0 deletions
19
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspacePullRequestLifecycle.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
40 changes: 40 additions & 0 deletions
40
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspacePullRequestState.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceRemoteState.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
123 changes: 123 additions & 0 deletions
123
...es/iOS/CmuxMobileRPC/Tests/CmuxMobileRPCTests/MobileWorkspaceRemoteStateDecodeTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 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
nonisolatedto prevent them from implicitly inheriting@MainActorisolation under Swift 6 strict concurrency defaults.Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileAttachedView.swift#L2-L2: Add thenonisolatedmodifier toMobileAttachedView.Packages/iOS/CmuxMobileRPC/Sources/CmuxMobileRPC/MobileWorkspaceGitState.swift#L2-L2: Add thenonisolatedmodifier toMobileWorkspaceGitState.📍 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
Source: Coding guidelines