Bind palette actions to their window and verify Mac commands
12 files changed,
+293
−57
docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md+130 −22native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift+4 −1native/apple/Sources/EquipoKit/Push/PushRoute.swift+3 −2native/apple/Sources/EquipoKit/UI/NeedsViewFixture.swift+3 −0native/apple/Sources/EquipoMac/EquipoMacApp.swift+4 −1native/apple/Sources/EquipoMac/MacJumpPalette.swift+16 −8native/apple/Sources/EquipoMac/MacMainView.swift+3 −0native/apple/Sources/EquipoMac/MacPowerCommands.swift+7 −4native/apple/Sources/EquipoMac/MacPowerFixture.swift+43 −10native/apple/Sources/EquipoMac/MacWorkspace.swift+24 −5native/apple/Tests/EquipoKitTests/MacPowerTests.swift+23 −4native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift+33 −0
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md b/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md| index 75a03893..48e3409b 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-native-mac-power.md |
| @@ -1,28 +1,136 @@ |
| # Mac power use |
| -Branch `native/mac-power`, based on `602b91fe`. Paused for the controller's |
| -slice 7 review fixes before publication. No merge or release. |
| +Branch `native/mac-power`, based on `602b91fe`. No server change, merge or |
| +release. Slice 7's priority review fixes were completed first at `f9e00ea6` |
| +with passing Linux CI. |
| -Implementation in progress: local fuzzy palette; window-focused Task and Go |
| -commands; the task screen's existing action model and confirmations; task |
| -WindowGroup bound to a local, non-secret session UUID; task-window visibility |
| -and move/cancellation handling; navigation history and composer focus. |
| +## Behaviour |
| -Copy: the ten `native.mac.*` keys were accepted by Luna, 2026-11-27, with the |
| -controller's final casing. Existing action labels retain reviewed sentence |
| -case in Mac menus; follow-up for Luna to review menu-specific casing. |
| +Command-K searches the current task window, Needs you tasks, active projects |
| +and the four sidebar destinations. Matching folds case and diacritics and |
| +supports subsequences; duplicate task entries use the latest revision. Search |
| +is local and bounded by the existing task-list window, not a remote full-history |
| +search. The selected task's actions reuse `TaskDetailModel`, the task page's |
| +rules, confirmations, revision bindings, errors and allowlisted web opener. |
| +Merge and Cancel only open confirmations. Retry has no shortcut. |
| -Validation so far: |
| -- Test-first `swift test --package-path native/apple --jobs 4 --filter MacPowerTests` |
| - failed on missing new model types. |
| +Go provides Command-1 through Command-4, Command-R and Command-[ / Command-]. |
| +File provides Command-N, which opens and focuses Conversation, including when |
| +only a task window is open or all app windows have been closed. Command-Return |
| +sends in the composer; Shift-Return and marked text do not send. In the palette, |
| +Return opens the selection and Command-Return opens a selected task window. |
| +Command-Shift-M opens the existing merge confirmation. |
| + |
| +Each window publishes its own workspace with `focusedSceneValue`. The task |
| +WindowGroup identity contains a local session UUID and origin, never a token. |
| +It cannot follow an account switch or restore an old session. Task windows |
| +observe the event cursor and re-read detail; cancellation, moving, a changed |
| +repository, or verified 401/403/404 closes the window. Network errors preserve |
| +it with the existing read error. Selecting another task's action in a standalone |
| +window routes to the main window and retains the original window's identity. |
| +The queued action carries its context, and a fresh read precedes presentation; |
| +a navigation change discards that intent. |
| + |
| +## Copy and accessibility |
| + |
| +The ten `native.mac.*` keys use Luna's approved values and `Luna, 2026-11-27` |
| +comments. All 334 reused web strings remain byte-identical. Existing task action |
| +labels keep reviewed sentence case in menus, as ruled; menu-specific title case |
| +is a follow-up for Luna. No copy question remains. |
| + |
| +The palette uses native text fields and buttons, exposes selection traits and |
| +labels, and announces the selected result/action when VoiceOver is enabled. |
| +Arrow keys, Return, Command-Return and Escape are handled. Actual keyboard |
| +fixture checks covered Command-K and Down/Return reaching Merge confirmation; |
| +model tests pin the no-write-before-confirmation rule. Spoken VoiceOver output |
| +was not verified by a human in this run. |
| + |
| +## Validation and mutations |
| + |
| +Machine load, swap and other heavy jobs were checked before every build, |
| +filtered test invocation and fixture launch. One own heavy job at a time, |
| +`--jobs 4`, with timeouts. No simulator was booted. The full native/CI gate script |
| +was deliberately not run locally under the controller's latest machine rules. |
| + |
| +- Test-first: `swift test --package-path native/apple --jobs 4 --filter MacPowerTests` |
| + failed on missing model types. Later search and routing regressions were |
| + added before their implementation. |
| - `swift test --package-path native/apple --jobs 4 --filter |
| - 'MacPowerTests|MacWorkspaceTests|TaskDetailModelTests'`: 32 tests passed. |
| -- String catalog check, 334-string parity, Oficina ID and sign-in lifetime |
| - scripts passed. Full local gate deliberately not run under machine rules. |
| -- `swift build --package-path native/apple --jobs 4 --product EquipoMac` passed. |
| -- An offline bundled fixture opened the palette through the actual Command-K |
| - menu equivalent. An in-app NSView capture was inspected; regrouping actions |
| - ahead of the app destinations is implemented and awaits recapture. |
| - |
| -Still required: guard mutations (prepared, not yet run), keyboard/VoiceOver |
| -fixture checks, final screenshots, post-commit reference scan, push and CI. |
| + 'MacPowerTests|MacWorkspaceTests|TaskDetailModelTests'`: 34 tests passed. |
| +- `swift build --package-path native/apple --jobs 4 --product EquipoMac`: passed. |
| +- `python3 native/scripts/check-strings.py`, `check-parity.py`, |
| + `check-oficina-id.py` and `check-sign-in-lifetime.py`: passed. |
| +- Post-commit `python3 scripts/runner-dead-references.py`: recorded with the |
| + pushed head's CI evidence. |
| + |
| +Each mutation below was applied alone, its named filtered suite was run with |
| +`swift test --package-path native/apple --jobs 4 --filter <suite>`, and the |
| +source was restored. Every final run failed on test expectations, not a compiler |
| +error. The Merge confirmation mutant initially survived because the snapshot |
| +merge preserved an existing merge card. The test now closes that card at a |
| +new revision and asserts the task-action path as well as the separate card path. |
| + |
| +| Mutation | Suite | Result | |
| +| --- | --- | --- | |
| +| `search-revision` | `MacPowerTests` | killed | |
| +| `known-original-repo` | `MacPowerTests` | killed | |
| +| `palette-action-guard` | `MacWorkspaceTests` | killed | |
| +| `palette-other-window` | `MacWorkspaceTests` | killed | |
| +| `routed-action-selection` | `MacWorkspaceTests` | killed | |
| +| `fresh-search` | `MacPowerTests` | killed | |
| +| `archived-project` | `MacPowerTests` | killed | |
| +| `window-origin` | `MacWorkspaceTests` | killed | |
| +| `busy` | `MacPowerTests` | killed | |
| +| `refused` | `MacPowerTests` | killed | |
| +| `active-session` | `MacPowerTests` | killed | |
| +| `fresh-revision` | `MacPowerTests` | killed | |
| +| `read-failure` | `MacPowerTests` | killed | |
| +| `merge-offer` | `MacPowerTests` | killed | |
| +| `retry-guard` | `MacPowerTests` | killed | |
| +| `move-guard` | `MacPowerTests` | killed | |
| +| `cancel-guard` | `MacPowerTests` | killed | |
| +| `perform-guard` | `MacPowerTests` | killed | |
| +| `merge-confirmation` | `MacPowerTests` | killed | |
| +| `cancel-confirmation` | `MacPowerTests` | killed | |
| +| `merge-card` | `MacPowerTests` | killed | |
| +| `refusal-classification` | `MacPowerTests` | killed | |
| +| `cancelled-window` | `MacPowerTests` | killed | |
| +| `moving-window` | `MacPowerTests` | killed | |
| +| `moved-window` | `MacPowerTests` | killed | |
| +| `invisible-window` | `MacPowerTests` | killed | |
| +| `window-account` | `MacWorkspaceTests` | killed | |
| +| `window-lifetime` | `MacWorkspaceTests` | killed | |
| +| `history-forward` | `MacPowerTests` | killed | |
| +| `deduplicate` | `MacPowerTests` | killed | |
| +| `brief-search` | `MacPowerTests` | killed | |
| +| `branch-search` | `MacPowerTests` | killed | |
| + |
| +The mutation driver, individual logs and results JSON are retained beside the |
| +screenshots in `site/build/slice9/validation/`. |
| + |
| +## Mac evidence |
| + |
| +`site/build/slice9/mac-palette.png` and `mac-task-window.png` are in-app NSView |
| +snapshots from the actual offline Mac build and WindowGroup. Screen capture |
| +permission was unavailable, so these capture content, not WindowServer chrome. |
| +The fixture's current-candidate Review step now agrees with its Approved facts. |
| +The standalone-window shortcut check selected a retry task in main and a merge |
| +task in its own window; Command-Shift-M opened the latter's confirmation. |
| + |
| +The initial synthetic shortcut harness skipped NSMenu's normal opening |
| +lifecycle, leaving SwiftUI's cached menu validation and focused values stale. |
| +Running the menu delegate's opening callbacks before the key equivalent fixed |
| +it; a constant focus probe confirmed the diagnosis. The temporary explicit |
| +window registry was removed. Native SwiftUI focus remains the sole command |
| +source. The Paseo committee's normal-menu discriminator identified the issue. |
| + |
| +Confirmation sheets were reached through real keyboard/menu events. Their |
| +NSView bitmap omits AppKit vibrancy-rendered labels, so those incomplete images |
| +are not presented as screenshots; the fixture logs and model assertions are |
| +retained. No actual merge was sent by a capture. |
| + |
| +## Handoff |
| + |
| +Normal push with `agent-tools/push.sh`; exact head and Linux CI verdict are |
| +reported in the handoff and saved CI JSON. No merge, deployment or release. |
| +Own fixture processes and scratch are removed after validation. |
diff --git a/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift b/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift| index 1828a7ea..353d9e33 100644 |
| --- a/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift |
| +++ b/native/apple/Sources/EquipoKit/MacPower/MacJumpIndex.swift |
| @@ -20,8 +20,11 @@ public struct MacJumpIndex { |
| private var entries: [MacJumpResult] = [] |
| public init(tasks: [ThinTask], needs: [ThinTask], projects: [ThinProject]) { |
| let needsIDs = Set(needs.map(\.id)) |
| + var latest: [String: ThinTask] = [:] |
| + for task in needs + tasks where task.revision >= (latest[task.id]?.revision ?? -1) { latest[task.id] = task } |
| var seen = Set<String>() |
| - for task in needs + tasks where seen.insert(task.id).inserted { |
| + for entry in needs + tasks where seen.insert(entry.id).inserted { |
| + let task = latest[entry.id] ?? entry |
| entries.append(.init(target: .task(task.id), title: task.title, subtitle: task.project, |
| needsYou: needsIDs.contains(task.id), |
| search: [task.title, task.project, task.repo ?? "", task.branch, task.brief].joined(separator: " "))) |
diff --git a/native/apple/Sources/EquipoKit/Push/PushRoute.swift b/native/apple/Sources/EquipoKit/Push/PushRoute.swift| index 338869c3..910fe0fb 100644 |
| --- a/native/apple/Sources/EquipoKit/Push/PushRoute.swift |
| +++ b/native/apple/Sources/EquipoKit/Push/PushRoute.swift |
| @@ -51,8 +51,9 @@ public struct Destination: Equatable, Sendable { |
| public var cardID: String? |
| public var taskID: String? |
| public var projectID: String? |
| + public var macAction: MacTaskAction? |
| public var focusComposer: Bool |
| - public init(pane: Pane, cardID: String? = nil, taskID: String? = nil, projectID: String? = nil, focusComposer: Bool = false) { |
| - self.pane = pane; self.cardID = cardID; self.taskID = taskID; self.projectID = projectID; self.focusComposer = focusComposer |
| + public init(pane: Pane, cardID: String? = nil, taskID: String? = nil, projectID: String? = nil, focusComposer: Bool = false, macAction: MacTaskAction? = nil) { |
| + self.pane = pane; self.cardID = cardID; self.taskID = taskID; self.projectID = projectID; self.focusComposer = focusComposer; self.macAction = macAction |
| } |
| } |
diff --git a/native/apple/Sources/EquipoKit/UI/NeedsViewFixture.swift b/native/apple/Sources/EquipoKit/UI/NeedsViewFixture.swift| index 8b7ba1ae..dd008d37 100644 |
| --- a/native/apple/Sources/EquipoKit/UI/NeedsViewFixture.swift |
| +++ b/native/apple/Sources/EquipoKit/UI/NeedsViewFixture.swift |
| @@ -66,6 +66,9 @@ private struct NeedsFixtureTransport: EquipoTransport { |
| private var merge: [String: Any] { |
| var task = task("merge", "Keep the sign-in button visible", stage: "ready_to_merge", need: "merge") |
| task["checks"] = "passed"; task["verdict"] = "approve"; task["review_label"] = "other_family" |
| + var review = step("approved", specialist: "review", headline: "Keep the sign-in button visible") |
| + review["candidate_sha"] = task["candidate_sha"]; review["verdict"] = "approve"; review["review_label"] = "other_family" |
| + task["steps"] = [review] |
| return task |
| } |
| private var question: [String: Any] { |
diff --git a/native/apple/Sources/EquipoMac/EquipoMacApp.swift b/native/apple/Sources/EquipoMac/EquipoMacApp.swift| index b54fa150..9c54b46f 100644 |
| --- a/native/apple/Sources/EquipoMac/EquipoMacApp.swift |
| +++ b/native/apple/Sources/EquipoMac/EquipoMacApp.swift |
| @@ -51,7 +51,7 @@ import SwiftUI |
| .commands { |
| // First: About, Hide and Quit say "Equipo", not the Finder name. |
| PlainAppNameCommands() |
| - MacPowerCommands() |
| + MacPowerCommands(model: model) |
| #if canImport(RastrilloMacUpdates) |
| if let updater { NativeUpdateCommands(updater: updater) } |
| #endif |
| @@ -78,6 +78,9 @@ final class EquipoMacDelegate: NSObject, NSApplicationDelegate { |
| }() |
| func applicationWillFinishLaunching(_ notification: Notification) { |
| + #if DEBUG |
| + if ProcessInfo.processInfo.environment["EQUIPO_MAC_POWER_FIXTURE"] != nil { NSApp.appearance = NSAppearance(named: .aqua) } |
| + #endif |
| notifications.onRoute = { [weak self] route in |
| self?.model.open(route) |
| NSApp.activate() |
diff --git a/native/apple/Sources/EquipoMac/MacJumpPalette.swift b/native/apple/Sources/EquipoMac/MacJumpPalette.swift| index 94b33a6b..71896445 100644 |
| --- a/native/apple/Sources/EquipoMac/MacJumpPalette.swift |
| +++ b/native/apple/Sources/EquipoMac/MacJumpPalette.swift |
| @@ -1,3 +1,4 @@ |
| +import AppKit |
| import EquipoKit |
| import SwiftUI |
| @@ -14,7 +15,7 @@ struct MacJumpPalette: View { |
| private var results: [MacJumpResult] { workspace.index.results(query) } |
| private var taskResults: [MacJumpResult] { results.filter { if case .task = $0.target { true } else { false } } } |
| private var otherResults: [MacJumpResult] { results.filter { if case .task = $0.target { false } else { true } } } |
| - private var context: MacTaskContext? { workspace.standalone ? workspace.context : taskContext ?? workspace.context } |
| + private var context: MacTaskContext? { taskContext ?? workspace.context } |
| private var actions: [MacTaskAction] { |
| guard let context else { return [] } |
| // Task matches keep their actions visible while a title is typed. |
| @@ -63,7 +64,7 @@ struct MacJumpPalette: View { |
| .onAppear { |
| resetSelection() |
| #if DEBUG |
| - if ProcessInfo.processInfo.environment["EQUIPO_MAC_POWER_FIXTURE"] == "palette" { query = "button" } |
| + if ProcessInfo.processInfo.environment["EQUIPO_MAC_POWER_FIXTURE"] .map({ ["palette", "keyboard"].contains($0) }) == true { query = "button" } |
| #endif |
| } |
| .onChange(of: query) { resetSelection() } |
| @@ -119,6 +120,14 @@ struct MacJumpPalette: View { |
| let id = ids[index] |
| if let result = results.first(where: { String(describing: $0.id) == id }) { selectedAction = nil; select(result.target) } |
| else { selectedAction = actions.first { "action:" + $0.rawValue == id } } |
| + if NSWorkspace.shared.isVoiceOverEnabled { |
| + let label = selectedAction.map { $0.title + "\n" + (context?.title ?? "") } |
| + ?? results.first(where: { $0.target == selected }).map { $0.title + "\n" + $0.subtitle } |
| + if let label, let app = NSApp { |
| + NSAccessibility.post(element: app, notification: .announcementRequested, |
| + userInfo: [.announcement: label, .priority: NSAccessibilityPriorityLevel.medium.rawValue]) |
| + } |
| + } |
| } |
| private func activate(_ target: MacDestination, window: Bool) { |
| if window, case .task(let id) = target { |
| @@ -128,8 +137,7 @@ struct MacJumpPalette: View { |
| } |
| private func activate(_ action: MacTaskAction) { |
| guard let context, context.actions.contains(action) else { return } |
| - workspace.context = context; workspace.inspector = true |
| - workspace.pendingAction = action |
| + if workspace.queuePaletteAction(action, context: context) { openWindow(id: "main") } |
| dismiss() |
| } |
| private func symbol(_ target: MacDestination) -> String { |
| @@ -140,11 +148,11 @@ struct MacJumpPalette: View { |
| struct MacWorkspacePresenter: ViewModifier { |
| @Bindable var workspace: MacWorkspace |
| func body(content: Content) -> some View { |
| - content.focusedSceneValue(\.macWorkspace, workspace) |
| - .sheet(isPresented: $workspace.palette, onDismiss: { |
| - let action = workspace.pendingAction, context = workspace.context |
| + content.sheet(isPresented: $workspace.palette, onDismiss: { |
| + let pending = workspace.pendingAction |
| workspace.pendingAction = nil |
| - if let action { Task { await context?.perform(action) } } |
| + if let pending { Task { await workspace.performRoutedAction(pending.action, context: pending.context) } } |
| }) { MacJumpPalette(workspace: workspace) } |
| + .focusedSceneValue(workspace) |
| } |
| } |
diff --git a/native/apple/Sources/EquipoMac/MacMainView.swift b/native/apple/Sources/EquipoMac/MacMainView.swift| index d567e028..bdacf7c5 100644 |
| --- a/native/apple/Sources/EquipoMac/MacMainView.swift |
| +++ b/native/apple/Sources/EquipoMac/MacMainView.swift |
| @@ -114,6 +114,9 @@ struct MacMainView: View { |
| if destination.focusComposer { workspace.composerFocus += 1 } |
| if let project = destination.projectID { workspace.go(.project(project)) } |
| if let task = destination.taskID { open(task) } |
| + if let action = destination.macAction, let context = workspace.context { |
| + Task { await workspace.performRoutedAction(action, context: context) } |
| + } |
| } |
| private func open(_ taskID: String) { |
diff --git a/native/apple/Sources/EquipoMac/MacPowerCommands.swift b/native/apple/Sources/EquipoMac/MacPowerCommands.swift| index 0ad009e4..b838c28d 100644 |
| --- a/native/apple/Sources/EquipoMac/MacPowerCommands.swift |
| +++ b/native/apple/Sources/EquipoMac/MacPowerCommands.swift |
| @@ -3,17 +3,20 @@ import EquipoKit |
| import SwiftUI |
| struct MacPowerCommands: Commands { |
| - @FocusedValue(\.macWorkspace) private var workspace |
| + let model: EquipoAppModel |
| + @FocusedValue(MacWorkspace.self) private var workspace |
| @Environment(\.openWindow) private var openWindow |
| var body: some Commands { |
| CommandGroup(replacing: .newItem) { |
| Button(EquipoStrings.text("native.mac.new_message")) { |
| - if let workspace { workspace.newMessage(); if workspace.standalone { openWindow(id: "main") } } |
| - else { openWindow(id: "main") } |
| + MacWorkspace.newMessage(app: model, focused: workspace) |
| + if workspace == nil || workspace?.standalone == true { openWindow(id: "main") } |
| }.keyboardShortcut("n") |
| } |
| CommandMenu(EquipoStrings.text("native.mac.go")) { |
| - Button(EquipoStrings.text("native.mac.jump")) { workspace?.palette = true }.keyboardShortcut("k").disabled(workspace == nil) |
| + Button(EquipoStrings.text("native.mac.jump")) { |
| + workspace?.palette = true |
| + }.keyboardShortcut("k").disabled(workspace == nil) |
| Divider() |
| pane("tab.conversation", .conversation, "1") |
| pane("tab.needs", .needs, "2") |
diff --git a/native/apple/Sources/EquipoMac/MacPowerFixture.swift b/native/apple/Sources/EquipoMac/MacPowerFixture.swift| index 415ac0bf..fd235503 100644 |
| --- a/native/apple/Sources/EquipoMac/MacPowerFixture.swift |
| +++ b/native/apple/Sources/EquipoMac/MacPowerFixture.swift |
| @@ -14,24 +14,56 @@ struct MacPowerFixture: View { |
| .task { |
| await session.refresh() |
| guard let task = session.tasks.first(where: { $0.needsYou == "merge" }) else { return } |
| - model.destination = Destination(pane: .tasks, taskID: task.id) |
| - try? await Task.sleep(for: .seconds(2)) |
| let mode = ProcessInfo.processInfo.environment["EQUIPO_MAC_POWER_FIXTURE"] ?? "palette" |
| - if mode == "window" { |
| + model.destination = Destination(pane: .tasks, taskID: mode == "window-merge" ? "retry" : task.id) |
| + try? await Task.sleep(for: .seconds(2)) |
| + if mode.hasPrefix("window") { |
| openWindow(id: "task", value: MacTaskWindowID(taskID: task.id, session: session)) |
| - } else { |
| + try? await Task.sleep(for: .seconds(2)) |
| + } |
| + if mode != "window" { |
| NSApp.activate() |
| - NSApp.windows.first { $0.isVisible && !$0.isSheet }?.makeKeyAndOrderFront(nil) |
| - let event = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: mode == "merge" ? [.command, .shift] : .command, |
| + let target = mode == "window-merge" ? NSApp.windows.first { $0.title == task.title && !$0.isSheet } : NSApp.windows.first { $0.isVisible && !$0.isSheet } |
| + target?.makeKeyAndOrderFront(nil) |
| + try? await Task.sleep(for: .milliseconds(500)) |
| + // A direct performKeyEquivalent does not open SwiftUI's |
| + // menus. Run their normal opening lifecycle first, so |
| + // validation reads the current scene and task. |
| + @MainActor func prepare(_ menu: NSMenu) { |
| + menu.delegate?.menuNeedsUpdate?(menu) |
| + menu.delegate?.menuWillOpen?(menu) |
| + menu.update() |
| + for item in menu.items { |
| + if item.keyEquivalent == "k" { log("Jump enabled=\(item.isEnabled)") } |
| + if let submenu = item.submenu { prepare(submenu) } |
| + } |
| + } |
| + if let menu = NSApp.mainMenu { prepare(menu) } |
| + let event = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: mode.hasSuffix("merge") ? [.command, .shift] : .command, |
| timestamp: 0, windowNumber: NSApp.keyWindow?.windowNumber ?? 0, context: nil, |
| - characters: mode == "merge" ? "M" : "k", charactersIgnoringModifiers: mode == "merge" ? "m" : "k", isARepeat: false, keyCode: mode == "merge" ? 46 : 40)! |
| + characters: mode.hasSuffix("merge") ? "M" : "k", charactersIgnoringModifiers: mode.hasSuffix("merge") ? "m" : "k", isARepeat: false, keyCode: mode.hasSuffix("merge") ? 46 : 40)! |
| let invoked = NSApp.mainMenu?.performKeyEquivalent(with: event) == true |
| - print("Mac power fixture command invoked: \(invoked)") |
| + log("Mac power fixture command invoked: \(invoked)") |
| + guard invoked else { return } |
| + } |
| + try? await Task.sleep(for: .seconds(2)) |
| + if mode == "keyboard" { |
| + guard let sheet = NSApp.windows.first(where: { $0.isVisible && $0.isSheet }) else { log("Keyboard fixture: no palette sheet"); return } |
| + sheet.makeKeyAndOrderFront(nil) |
| + try? await Task.sleep(for: .milliseconds(300)) |
| + for (characters, code) in [(String(UnicodeScalar(0xF701)!), UInt16(125)), ("\r", UInt16(36))] { |
| + let event = NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: [], timestamp: 0, |
| + windowNumber: sheet.windowNumber, context: nil, |
| + characters: characters, charactersIgnoringModifiers: characters, |
| + isARepeat: false, keyCode: code)! |
| + sheet.sendEvent(event) |
| + try? await Task.sleep(for: .milliseconds(500)) |
| + } |
| } |
| try? await Task.sleep(for: .seconds(2)) |
| guard let path = ProcessInfo.processInfo.environment["EQUIPO_FIXTURE_CAPTURE"] else { return } |
| let windows = NSApp.windows.filter { $0.isVisible } |
| - let window = mode == "window" ? windows.last(where: { !$0.isSheet && $0.title != "Oficina" }) : windows.first(where: \.isSheet) ?? NSApp.keyWindow |
| + let window = mode == "window" ? windows.first(where: { !$0.isSheet && $0.title == task.title }) : windows.first(where: \.isSheet) ?? NSApp.keyWindow |
| guard let window, let view = window.contentView else { return } |
| window.appearance = NSAppearance(named: .aqua) |
| view.layoutSubtreeIfNeeded(); window.displayIfNeeded() |
| @@ -39,9 +71,10 @@ struct MacPowerFixture: View { |
| view.cacheDisplay(in: view.bounds, to: bitmap) |
| try? bitmap.representation(using: .png, properties: [:])?.write(to: URL(fileURLWithPath: path)) |
| } |
| - print("Mac power fixture captured: \(window.title)") |
| + log("Mac power fixture captured: \(window.title)") |
| } |
| } |
| } |
| + private func log(_ text: String) { try? FileHandle.standardOutput.write(contentsOf: Data((text + "\n").utf8)) } |
| } |
| #endif |
diff --git a/native/apple/Sources/EquipoMac/MacWorkspace.swift b/native/apple/Sources/EquipoMac/MacWorkspace.swift| index c4e32eaa..ee7287d7 100644 |
| --- a/native/apple/Sources/EquipoMac/MacWorkspace.swift |
| +++ b/native/apple/Sources/EquipoMac/MacWorkspace.swift |
| @@ -2,10 +2,6 @@ import EquipoKit |
| import Observation |
| import SwiftUI |
| -extension FocusedValues { |
| - @Entry var macWorkspace: MacWorkspace? |
| -} |
| - |
| /// One focused window's navigation and task selection. Commands never use a |
| /// global selected task, so moving focus between windows changes authority. |
| @MainActor @Observable final class MacWorkspace { |
| @@ -18,7 +14,8 @@ extension FocusedValues { |
| var focusCard: String? |
| var inspector = false |
| var palette = false |
| - var pendingAction: MacTaskAction? |
| + struct QueuedAction { let action: MacTaskAction; let context: MacTaskContext } |
| + var pendingAction: QueuedAction? |
| var composerFocus = 0 |
| var context: MacTaskContext? |
| var mainRequest = 0 |
| @@ -28,6 +25,7 @@ extension FocusedValues { |
| } |
| var index: MacJumpIndex { MacJumpIndex(tasks: session.tasks, needs: session.needsYou ?? [], projects: session.projectCatalog.items) } |
| func go(_ destination: MacDestination, record: Bool = true) { |
| + palette = false; pendingAction = nil |
| if standalone { |
| switch destination { |
| case .pane(let pane): app.destination = Destination(pane: pane) |
| @@ -53,6 +51,27 @@ extension FocusedValues { |
| go(.pane(.conversation)); composerFocus += 1 |
| if standalone { app.destination = Destination(pane: .conversation, focusComposer: true) } |
| } |
| + static func newMessage(app: EquipoAppModel, focused: MacWorkspace?) { |
| + if let focused { focused.newMessage() } |
| + else { app.destination = Destination(pane: .conversation, focusComposer: true) } |
| + } |
| + /// A task window keeps its identity. Actions for another highlighted task |
| + /// are presented in the main window, bound to that task and a fresh read. |
| + func queuePaletteAction(_ action: MacTaskAction, context: MacTaskContext) -> Bool { |
| + guard context.actions.contains(action) else { return false } |
| + if standalone && self.context?.taskID != context.taskID { |
| + app.destination = Destination(pane: .tasks, taskID: context.taskID, macAction: action) |
| + return true |
| + } |
| + self.context = context; inspector = true |
| + pendingAction = QueuedAction(action: action, context: context) |
| + return false |
| + } |
| + func performRoutedAction(_ action: MacTaskAction, context: MacTaskContext) async { |
| + await context.load() |
| + guard self.context === context else { return } |
| + await context.perform(action) |
| + } |
| func refresh() async { if let context { await context.refresh() } else { await session.refresh() } } |
| } |
diff --git a/native/apple/Tests/EquipoKitTests/MacPowerTests.swift b/native/apple/Tests/EquipoKitTests/MacPowerTests.swift| index 0d6eb821..e248e448 100644 |
| --- a/native/apple/Tests/EquipoKitTests/MacPowerTests.swift |
| +++ b/native/apple/Tests/EquipoKitTests/MacPowerTests.swift |
| @@ -20,6 +20,18 @@ import Testing |
| #expect(index.results("").contains { $0.target == .pane(.conversation) }) |
| #expect(index.results("").contains { if case .project = $0.target { true } else { false } }) |
| } |
| + @Test func duplicateSearchUsesTheLatestRevisionAndHidesArchivedProjects() throws { |
| + var old = try TaskDetailTests.task(); old.title = "Old title"; old.revision = 1 |
| + var latest = old; latest.title = "Latest title"; latest.revision = 2 |
| + var projects: ThinList<ThinProject> = try Fixture.decode("thin/projects") |
| + projects.items?[0].state = "archived" |
| + for (tasks, needs) in [([latest], [old]), ([old], [latest])] { |
| + let index = MacJumpIndex(tasks: tasks, needs: needs, projects: projects.items ?? []) |
| + #expect(index.results("Latest title").first?.title == "Latest title") |
| + #expect(index.results("").filter { $0.target == .task(old.id) }.count == 1) |
| + #expect(!index.results("").contains { $0.target == .project(projects.items![0].id) }) |
| + } |
| + } |
| @Test func historyDoesNotRepeatAndNewNavigationDropsForward() { |
| let history = MacNavigationHistory() |
| history.go(.pane(.tasks)); history.go(.task("a")); history.go(.task("a")) |
| @@ -33,6 +45,10 @@ import Testing |
| for action in [MacTaskAction.merge, .cancel] { |
| let server = TaskDetailServer(), detail = try TaskDetailModelTests.model(server) |
| await detail.load(); detail.loaded?.mergeOffered = true |
| + var snapshot: Snapshot = try Fixture.decode("thin/snapshot") |
| + snapshot.cards = snapshot.cards?.map { var card = $0; card.state = "answered"; card.revision += 1; return card } |
| + detail.session.apply(snapshot) |
| + #expect(detail.decision.card == nil) |
| let context = MacTaskContext(detail: detail) |
| #expect(context.actions.contains(action)) |
| await context.perform(action) |
| @@ -92,10 +108,12 @@ import Testing |
| detail.loaded?.revision = 0 |
| #expect(context.actions.isEmpty) |
| detail.loaded = loaded |
| - await server.refuseRead(403); await context.load() |
| - #expect(context.refused); #expect(context.actions.isEmpty) |
| - detail.readFailure = nil; #expect(context.actions.isEmpty) |
| - await context.perform(.cancel); #expect(detail.confirmation == nil) |
| + for status in [401, 403, 404] { |
| + await server.refuseRead(status); await context.load() |
| + #expect(context.refused); #expect(context.actions.isEmpty) |
| + detail.readFailure = nil; #expect(context.actions.isEmpty) |
| + await context.perform(.cancel); #expect(detail.confirmation == nil) |
| + } |
| await server.refuseRead(500); await context.load() |
| #expect(!context.refused); #expect(context.actions.isEmpty) |
| await server.refuseRead(200); await context.load() |
| @@ -107,6 +125,7 @@ import Testing |
| var task = try TaskDetailTests.task() |
| #expect(!MacTaskWindowPolicy.shouldClose(task: task, initialRepo: task.repo, status: nil)) |
| #expect(!MacTaskWindowPolicy.shouldClose(task: nil, initialRepo: task.repo, status: 500)) |
| + #expect(!MacTaskWindowPolicy.shouldClose(task: task, initialRepo: nil, status: nil)) |
| for status in [401, 403, 404] { #expect(MacTaskWindowPolicy.shouldClose(task: nil, initialRepo: task.repo, status: status)) } |
| task.stage = "cancelled" |
| #expect(MacTaskWindowPolicy.shouldClose(task: task, initialRepo: task.repo, status: nil)) |
diff --git a/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift b/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift| index c99a9b03..a9367259 100644 |
| --- a/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift |
| +++ b/native/apple/Tests/EquipoKitTests/MacWorkspaceTests.swift |
| @@ -30,6 +30,10 @@ import Testing |
| let encoded = try JSONEncoder().encode(identity) |
| #expect(try JSONDecoder().decode(MacTaskWindowID.self, from: encoded) == identity) |
| #expect(!String(decoding: encoded, as: UTF8.self).contains("token")) |
| + var changedOrigin = try #require(JSONSerialization.jsonObject(with: encoded) as? [String: Any]) |
| + changedOrigin["origin"] = "https://other-team.invalid" |
| + let changed = try JSONDecoder().decode(MacTaskWindowID.self, from: JSONSerialization.data(withJSONObject: changedOrigin)) |
| + #expect(!changed.matches(session)) |
| session.lifetime.end() |
| #expect(!identity.matches(session)) |
| } |
| @@ -43,12 +47,41 @@ import Testing |
| #expect(window.mainRequest == 1) |
| window.newMessage(); #expect(app.destination?.pane == .conversation) |
| } |
| + @Test func paletteActionForAnotherTaskRoutesWithoutReplacingItsWindow() async throws { |
| + let server = TaskDetailServer(), detail = try TaskDetailModelTests.model(server) |
| + await detail.load() |
| + let target = MacTaskContext(detail: detail) |
| + let app = EquipoAppModel(store: MemorySecretStore()) |
| + let window = MacWorkspace(app: app, session: detail.session, taskID: "original") |
| + detail.busy = true |
| + #expect(!window.queuePaletteAction(.cancel, context: target)); #expect(app.destination == nil) |
| + detail.busy = false |
| + #expect(window.queuePaletteAction(.cancel, context: target)) |
| + #expect(window.context?.taskID == "original") |
| + #expect(app.destination?.taskID == target.taskID) |
| + #expect(app.destination?.macAction == .cancel) |
| + #expect(await server.writes == 0) |
| + let main = MacWorkspace(app: app, session: detail.session) |
| + #expect(!main.queuePaletteAction(.cancel, context: target)) |
| + #expect(main.pendingAction?.action == .cancel && main.context === target) |
| + await main.performRoutedAction(.cancel, context: target) |
| + #expect(detail.confirmation?.action == .cancel) |
| + #expect(await server.writes == 0) |
| + detail.confirmation = nil; main.go(.pane(.conversation)) |
| + await main.performRoutedAction(.cancel, context: target) |
| + #expect(detail.confirmation == nil) |
| + MacWorkspace.newMessage(app: app, focused: nil) |
| + #expect(app.destination?.pane == .conversation && app.destination?.focusComposer == true) |
| + } |
| @Test func commandReturnSendsButShiftReturnAndMarkedTextDoNot() throws { |
| let editor = ComposerEditor(); var sends = 0 |
| editor.onSubmit = { sends += 1 } |
| let event = try #require(NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: .command, timestamp: 0, |
| windowNumber: 0, context: nil, characters: "\r", charactersIgnoringModifiers: "\r", isARepeat: false, keyCode: 36)) |
| editor.keyDown(with: event); #expect(sends == 1) |
| + let shifted = try #require(NSEvent.keyEvent(with: .keyDown, location: .zero, modifierFlags: [.command, .shift], timestamp: 0, |
| + windowNumber: 0, context: nil, characters: "\r", charactersIgnoringModifiers: "\r", isARepeat: false, keyCode: 36)) |
| + editor.keyDown(with: shifted); #expect(sends == 1) |
| editor.setMarkedText("unfinished", selectedRange: NSRange(location: 0, length: 0), replacementRange: NSRange(location: NSNotFound, length: 0)) |
| editor.keyDown(with: event); #expect(sends == 1) |
| } |