Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
410dbba
Add failing regression test: downward before-move lands one row too low
azooz2003-bit Jul 5, 2026
8e06d1b
iOS: native drag & drop in workspace list + create workspace in group
azooz2003-bit Jul 5, 2026
350cbd2
Add failing regression test: downward after-move lands one row too low
azooz2003-bit Jul 5, 2026
2c8f014
Fix downward after-move off-by-one in workspaceReorderPlan
azooz2003-bit Jul 5, 2026
92ec77e
iOS: make MobileWorkspaceDropIntentResolver a static namespace, cover…
azooz2003-bit Jul 5, 2026
b2d7428
workspace.move: re-query group membership after addWorkspaceToGroup
azooz2003-bit Jul 5, 2026
3ade789
iOS: fix in-list drop rejection with provider-based drag/drop, header…
azooz2003-bit Jul 5, 2026
32881e7
Mobile host: trim ticket workspaceID in workspace.move authorization
azooz2003-bit Jul 5, 2026
89fbc7e
iOS: switch workspace list drag to native List onMove
azooz2003-bit Jul 5, 2026
a80b2da
iOS: group context menu parity + failure toasts for disconnected actions
azooz2003-bit Jul 6, 2026
88af7ad
iOS: disambiguate workspace group drop gaps
azooz2003-bit Jul 7, 2026
fb7adb8
Add regression coverage for workspace create and move edge cases
azooz2003-bit Jul 7, 2026
182c6b2
Fix workspace create single-flight and blank group moves
azooz2003-bit Jul 7, 2026
a41dab2
Keep workspace regression tests under file budget
azooz2003-bit Jul 7, 2026
41aae36
Move mobile workspace move regression under budget
azooz2003-bit Jul 7, 2026
4e67cec
Fix workspace create target single-flight
azooz2003-bit Jul 7, 2026
f6b1b57
Fix disconnected workspace create request
azooz2003-bit Jul 7, 2026
772f290
Gate mobile workspace mutations by capability
azooz2003-bit Jul 7, 2026
2683546
Fix group action auth compatibility
azooz2003-bit Jul 7, 2026
f91bd22
Align workspace mutation auth contracts
azooz2003-bit Jul 7, 2026
96c9e55
Restore foreground create connection gate
azooz2003-bit Jul 7, 2026
2e90144
Fix mobile workspace move ordering
azooz2003-bit Jul 7, 2026
df653f2
Enforce mobile workspace mutation auth scope
azooz2003-bit Jul 7, 2026
7d9af09
Fix mobile group header moves and mutation auth
azooz2003-bit Jul 7, 2026
f9cc658
Fix mobile reorder window scope
azooz2003-bit Jul 7, 2026
185b0ed
Ignore stale tickets for broad mobile RPCs
azooz2003-bit Jul 7, 2026
8498bdd
Gate mobile workspace mutations by ticket scope
azooz2003-bit Jul 7, 2026
ddc8445
Enforce create-in-group ticket scope
azooz2003-bit Jul 7, 2026
60b91ee
Fix mobile host auth test macro expansion
azooz2003-bit Jul 7, 2026
f59df07
Import SwiftUI for workspace drag move helpers
azooz2003-bit Jul 7, 2026
d6918eb
Fail closed on stale mobile workspace mutation tickets
azooz2003-bit Jul 7, 2026
92f07e5
Keep mobile workspace move pending through refreshes
azooz2003-bit Jul 7, 2026
9a3bae2
Satisfy mobile workspace review policies
azooz2003-bit Jul 7, 2026
cc25ebd
Fix mobile workspace package convention lint
azooz2003-bit Jul 7, 2026
ca5ba5e
Surface detail workspace action failures
azooz2003-bit Jul 7, 2026
2d4de3b
Avoid duplicate workspace create errors
azooz2003-bit Jul 8, 2026
fee9254
Fix ticket authorization project reference
azooz2003-bit Jul 8, 2026
50e1e6f
Stabilize mobile workspace UI change keys
azooz2003-bit Jul 8, 2026
0651b5a
Merge remote-tracking branch 'origin/main' into feat-ios-workspace-dnd
azooz2003-bit Jul 8, 2026
1fdbe26
Fix iOS title menu compiler crash
azooz2003-bit Jul 8, 2026
2a1f294
Add workspace ticket authorization regression test
azooz2003-bit Jul 8, 2026
36c3137
Authorize mobile workspace actions for scoped tickets
azooz2003-bit Jul 8, 2026
58aaabf
Stabilize pairing retry deadline test
azooz2003-bit Jul 8, 2026
862d1b0
Fix workspace ticket auth test compile and reorder gating
azooz2003-bit Jul 8, 2026
8f3a563
Make workspace group pending action equatable
azooz2003-bit Jul 8, 2026
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
Expand Up @@ -310,7 +310,7 @@ public final class MobileCoreRPCClient: MobileSyncing, Sendable {
return false
case "workspace.create":
return false
case "workspace.action", "workspace.close":
case "workspace.action", "workspace.close", "workspace.move":
return !ticketCoverage.ticketCoversWorkspaceRequest(
ticket: ticket,
workspaceSelection: workspaceSelection.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,42 @@ import Testing
#expect(mappedOlder.lastActivityAt == nil)
}

@Test func workspaceMoveRequestEncodesGroupAndBeforeWorkspace() throws {
let data = try MobileCoreRPCClient.requestData(
method: "workspace.move",
params: [
"workspace_id": "workspace-dragged",
"group_id": "group-target",
"before_workspace_id": "workspace-before",
"client_id": "client-1",
],
id: "move-request"
)
let request = try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])
let params = try #require(request["params"] as? [String: Any])
#expect(request["id"] as? String == "move-request")
#expect(request["method"] as? String == "workspace.move")
#expect(params["workspace_id"] as? String == "workspace-dragged")
#expect(params["group_id"] as? String == "group-target")
#expect(params["before_workspace_id"] as? String == "workspace-before")
#expect(params["client_id"] as? String == "client-1")
}

@Test func workspaceCreateRequestEncodesGroupID() throws {
let data = try MobileCoreRPCClient.requestData(
method: "workspace.create",
params: [
"group_id": "group-target",
],
id: "create-request"
)
let request = try #require(JSONSerialization.jsonObject(with: data) as? [String: Any])
let params = try #require(request["params"] as? [String: Any])
#expect(request["id"] as? String == "create-request")
#expect(request["method"] as? String == "workspace.create")
#expect(params["group_id"] as? String == "group-target")
}

@Test func attachTicketInputDecodesAttachURL() throws {
let route = try CmxAttachRoute(
id: "tailscale",
Expand Down Expand Up @@ -363,4 +399,47 @@ import Testing
#expect(frame.stackAccessToken == "test-stack-token")
#expect(frame.hasAuth)
}

@Test func workspaceMoveCarriesMacWideAttachTicketContext() async throws {
let route = try hostPortRoute(kind: .tailscale, host: "100.64.0.5", port: 58465)
let transport = QueuedCancellationProbeTransport()
let runtime = TestMobileSyncRuntime(
transportFactory: QueuedCancellationProbeTransportFactory(transport: transport),
stackAccessToken: "test-stack-token"
)
let ticket = try CmxAttachTicket(
workspaceID: "",
terminalID: nil,
macDeviceID: "test-mac",
macDisplayName: "Test Mac",
routes: [route],
expiresAt: Date().addingTimeInterval(60),
authToken: "ticket-secret"
)
let client = MobileCoreRPCClient(
runtime: runtime,
route: route,
ticket: ticket,
allowsStackAuthFallback: true
)
let request = try MobileCoreRPCClient.requestData(
method: "workspace.move",
params: [
"workspace_id": "workspace-main",
"group_id": "group-main",
"before_workspace_id": "workspace-next",
]
)
let task = Task { try await client.sendRequest(request) }
let sent = try await transport.waitForSentRequestCount(1)
task.cancel()
_ = try? await task.value

let frame = try #require(sent.first)
#expect(frame.method == "workspace.move")
#expect(frame.workspaceID == "workspace-main")
#expect(frame.attachToken == "ticket-secret")
#expect(frame.stackAccessToken == "test-stack-token")
#expect(frame.hasAuth)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ extension MobileShellComposite {
)
}

/// Move a workspace to a new group/order on the Mac, then re-sync the list.
/// - Parameters:
/// - id: The workspace to move.
/// - groupID: The target group, or `nil` to ungroup.
/// - beforeWorkspaceID: The workspace that should follow the moved row.
public func moveWorkspace(
id: MobileWorkspacePreview.ID,
toGroup groupID: MobileWorkspaceGroupPreview.ID?,
before beforeWorkspaceID: MobileWorkspacePreview.ID?
) async {
guard workspaceActionCapabilities(for: id).supportsWorkspaceActions else { return }
var params = workspaceMutationParams(id: id)
if let groupID {
params["group_id"] = groupID.rawValue
}
if let beforeWorkspaceID {
params["before_workspace_id"] = remoteWorkspaceID(for: beforeWorkspaceID).rawValue
}
await sendWorkspaceMutation(
method: "workspace.move",
params: params,
id: id,
actionName: "move"
)
}

private func workspaceActionCapabilities(for id: MobileWorkspacePreview.ID) -> MobileWorkspaceActionCapabilities {
workspaces.first { $0.id == id }?.actionCapabilities ?? .none
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4103,20 +4103,20 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
body(&state.workspaces)
workspacesByMac[key] = state
}

/// Create a workspace locally or through the connected Mac, then select it.
public func createWorkspace() {
public func createWorkspace(inGroup groupID: MobileWorkspaceGroupPreview.ID? = nil) {
guard remoteClient == nil else {
guard createWorkspaceTask == nil else { return }
let taskID = UUID()
createWorkspaceTaskID = taskID
createWorkspaceTask = Task { @MainActor [weak self] in
defer { self?.clearCreateWorkspaceTask(id: taskID) }
guard let self else { return }
await self.createRemoteWorkspace()
await self.createRemoteWorkspace(inGroup: groupID)
}
return
}
guard groupID == nil else { return }
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
if createLocalWorkspaceWithoutTerminalForDelayedUITestIfNeeded() { return }
let nextIndex = workspaces.count + 1
let workspace = MobileWorkspacePreview(
Expand Down Expand Up @@ -5843,12 +5843,16 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
MobileTerminalViewportKey(workspaceID: workspaceID, terminalID: terminalID)
}

private func createRemoteWorkspace() async {
private func createRemoteWorkspace(inGroup groupID: MobileWorkspaceGroupPreview.ID? = nil) async {
guard let client = remoteClient else { return }
let generation = connectionGeneration
do {
var params: [String: Any] = [:]
if let groupID {
params["group_id"] = groupID.rawValue
}
let resultData = try await client.sendRequest(
MobileCoreRPCClient.requestData(method: "workspace.create")
MobileCoreRPCClient.requestData(method: "workspace.create", params: params)
)
let response = try MobileSyncWorkspaceListResponse.decode(resultData)
guard isCurrentRemoteOperation(client: client, generation: generation),
Expand All @@ -5863,10 +5867,7 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
}
syncSelectedTerminalForWorkspace()
if createdWorkspace != nil {
// A "+" actually created and selected a new workspace, so its
// terminal is freshly created: don't pop the keyboard on mount.
// When no workspace was created the selection never moved, so we
// must not suppress the user's current terminal.
// A "+" actually created and selected a new workspace, so its terminal is freshly created.
suppressTerminalAutoFocusOnNextAttach(for: selectedTerminalID)
}
} catch {
Expand All @@ -5876,7 +5877,6 @@ public final class MobileShellComposite: MobileTerminalOutputSinking {
applyOperationalError(error)
}
}

private func createRemoteTerminal(in explicitWorkspaceID: MobileWorkspacePreview.ID? = nil) async {
guard let client = remoteClient,
let rowWorkspaceID = explicitWorkspaceID ?? selectedWorkspace?.id else { return }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
public import Foundation

/// List-move helpers derived from rendered list-item snapshots.
public extension MobileWorkspaceListItem {
/// Resolves a SwiftUI `List` move into a Mac-facing workspace move intent.
///
/// The `destination` index is the pre-removal index space reported by
/// `ForEach.onMove`. Group headers are never movable, and ambiguous/no-op
/// landings resolve to `nil`.
///
/// - Parameters:
/// - items: The rendered workspace list snapshot backing the `List`.
/// - workspaces: The full workspace order from the Mac.
/// - groups: The group snapshots from the Mac.
/// - sourceOffsets: The moved row offsets from SwiftUI.
/// - destination: The destination offset from SwiftUI, in pre-removal space.
/// - Returns: A workspace move intent, or `nil` when the move should not fire.
static func moveIntent(
items: [MobileWorkspaceListItem],
workspaces: [MobileWorkspacePreview],
groups: [MobileWorkspaceGroupPreview],
sourceOffsets: IndexSet,
destination: Int
) -> MobileWorkspaceMoveIntent? {
guard sourceOffsets.count == 1,
let sourceIndex = sourceOffsets.first,
items.indices.contains(sourceIndex),
case .workspace(let movedWorkspace, _) = items[sourceIndex] else {
return nil
}

let rawDestination = min(max(destination, items.startIndex), items.endIndex)
guard rawDestination != sourceIndex, rawDestination != sourceIndex + 1 else {
return nil
}
let adjustedDestination = sourceIndex < rawDestination ? rawDestination - 1 : rawDestination
var remainingItems = items
remainingItems.remove(at: sourceIndex)
let insertionIndex = min(max(adjustedDestination, remainingItems.startIndex), remainingItems.endIndex)

let knownGroupIDs = Set(groups.map(\.id))
let currentGroupID = validGroupID(movedWorkspace.groupID, knownGroupIDs: knownGroupIDs)
let orderedWithoutMoved = workspaces.filter { $0.id != movedWorkspace.id }

let previousItem = insertionIndex > remainingItems.startIndex
? remainingItems[remainingItems.index(before: insertionIndex)]
: nil
let nextItem = insertionIndex < remainingItems.endIndex
? remainingItems[insertionIndex]
: nil

let proposed: MobileWorkspaceMoveIntent?
switch previousItem {
case .groupHeader(let group, _):
guard knownGroupIDs.contains(group.id) else { return nil }
proposed = MobileWorkspaceMoveIntent(
groupID: group.id,
beforeWorkspaceID: firstNonAnchorWorkspace(
in: group.id,
groups: groups,
workspaces: orderedWithoutMoved,
knownGroupIDs: knownGroupIDs
) ?? workspaceAfterGroup(
group.id,
workspaces: orderedWithoutMoved,
knownGroupIDs: knownGroupIDs
)
)

case .workspace(let previousWorkspace, _):
let previousGroupID = validGroupID(previousWorkspace.groupID, knownGroupIDs: knownGroupIDs)
if let previousGroupID {
let beforeWorkspaceID: MobileWorkspacePreview.ID?
if case .workspace(let nextWorkspace, _) = nextItem,
validGroupID(nextWorkspace.groupID, knownGroupIDs: knownGroupIDs) == previousGroupID {
beforeWorkspaceID = nextWorkspace.id
} else {
beforeWorkspaceID = workspaceAfterGroup(
previousGroupID,
workspaces: orderedWithoutMoved,
knownGroupIDs: knownGroupIDs
)
}
proposed = MobileWorkspaceMoveIntent(
groupID: previousGroupID,
beforeWorkspaceID: beforeWorkspaceID
)
} else {
proposed = MobileWorkspaceMoveIntent(
groupID: nil,
beforeWorkspaceID: ungroupedBeforeWorkspaceID(
nextItem: nextItem,
workspaces: orderedWithoutMoved,
knownGroupIDs: knownGroupIDs
)
)
}

case nil:
proposed = MobileWorkspaceMoveIntent(
groupID: nil,
beforeWorkspaceID: ungroupedBeforeWorkspaceID(
nextItem: nextItem,
workspaces: orderedWithoutMoved,
knownGroupIDs: knownGroupIDs
)
)
}

guard let intent = proposed else { return nil }
guard intent.groupID != currentGroupID || changesOrder(
draggedWorkspaceID: movedWorkspace.id,
beforeWorkspaceID: intent.beforeWorkspaceID,
workspaces: workspaces
) else {
return nil
}
return intent
}

private static func ungroupedBeforeWorkspaceID(
nextItem: MobileWorkspaceListItem?,
workspaces: [MobileWorkspacePreview],
knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID>
) -> MobileWorkspacePreview.ID? {
switch nextItem {
case .workspace(let nextWorkspace, _):
return nextWorkspace.id
case .groupHeader(let nextGroup, _):
return firstWorkspace(
in: nextGroup.id,
workspaces: workspaces,
knownGroupIDs: knownGroupIDs
)
case nil:
return nil
}
}

private static func validGroupID(
_ groupID: MobileWorkspaceGroupPreview.ID?,
knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID>
) -> MobileWorkspaceGroupPreview.ID? {
guard let groupID, knownGroupIDs.contains(groupID) else { return nil }
return groupID
}

private static func firstWorkspace(
in groupID: MobileWorkspaceGroupPreview.ID,
workspaces: [MobileWorkspacePreview],
knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID>
) -> MobileWorkspacePreview.ID? {
workspaces.first(where: { validGroupID($0.groupID, knownGroupIDs: knownGroupIDs) == groupID })?.id
}

private static func firstNonAnchorWorkspace(
in groupID: MobileWorkspaceGroupPreview.ID,
groups: [MobileWorkspaceGroupPreview],
workspaces: [MobileWorkspacePreview],
knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID>
) -> MobileWorkspacePreview.ID? {
guard let anchorWorkspaceID = groups.first(where: { $0.id == groupID })?.anchorWorkspaceID else {
return nil
}
return workspaces.first(where: {
validGroupID($0.groupID, knownGroupIDs: knownGroupIDs) == groupID && $0.id != anchorWorkspaceID
})?.id
}

private static func workspaceAfterGroup(
_ groupID: MobileWorkspaceGroupPreview.ID,
workspaces: [MobileWorkspacePreview],
knownGroupIDs: Set<MobileWorkspaceGroupPreview.ID>
) -> MobileWorkspacePreview.ID? {
guard let lastMemberIndex = workspaces.lastIndex(where: {
validGroupID($0.groupID, knownGroupIDs: knownGroupIDs) == groupID
}) else {
return nil
}
let nextIndex = workspaces.index(after: lastMemberIndex)
guard nextIndex < workspaces.endIndex else { return nil }
return workspaces[nextIndex].id
}

private static func changesOrder(
draggedWorkspaceID: MobileWorkspacePreview.ID,
beforeWorkspaceID: MobileWorkspacePreview.ID?,
workspaces: [MobileWorkspacePreview]
) -> Bool {
var ids = workspaces.map(\.id)
guard let currentIndex = ids.firstIndex(of: draggedWorkspaceID) else { return false }
ids.remove(at: currentIndex)
let targetIndex = beforeWorkspaceID.flatMap { ids.firstIndex(of: $0) } ?? ids.endIndex
ids.insert(draggedWorkspaceID, at: targetIndex)
return ids != workspaces.map(\.id)
}
}
Loading
Loading