Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
feat(spaces-macos): passphrase setup and unlock in the New UI (CUA-1411) (#5032)
Francesco Bonaccif982ea064bb1
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/KeyvaultViews.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/KeyvaultViews.swiftindex 661a199e39..ef0af231e4 100644--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/KeyvaultViews.swift+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Views/KeyvaultViews.swift@@ -74,10 +74,7 @@ struct CredentialForm: View {var body: some View {VStack(spacing: 8) {if form.method == .passphrase {- SecureField(form.passphraseLabel ?? "", text: $keyvault.passphrase)- if let confirm = form.confirmLabel {- SecureField(confirm, text: $keyvault.passphraseConfirm)- }+ PassphraseFields(keyvault: keyvault, form: form)}Button(form.submitLabel) { Task { await keyvault.submitCredential() } }.buttonStyle(.glassProminent)@@ -95,6 +92,63 @@ struct CredentialForm: View {}}+/// The passphrase and, at setup, its confirmation, typed into the model's+/// fields (`submitCredential` reads and clears them).+struct PassphraseFields: View {+ @Bindable var keyvault: KeyvaultModel+ let form: KvCredentialForm+ @FocusState private var focused: Bool++ var body: some View {+ SecureField(form.passphraseLabel ?? "", text: $keyvault.passphrase)+ .focused($focused)+ .onAppear { focused = true }+ if let confirm = form.confirmLabel {+ SecureField(confirm, text: $keyvault.passphraseConfirm)+ }+ }+}++/// The passphrase form as a sheet on the New UI window (`keyvault.setup`,+/// `keyvault.unlockVault`): the same fields and hint as `CredentialForm`,+/// with Cancel. `done(true)` sends it; the bridge then submits as the+/// SwiftUI form does, so the passphrase stays in this process.+struct PassphraseSheet: View {+ @Bindable var keyvault: KeyvaultModel+ let form: KvCredentialForm+ let done: (Bool) -> Void++ var body: some View {+ VStack(alignment: .leading, spacing: 8) {+ Text(form.mode == .setup ? "Set up Keyvault" : "Unlock Keyvault")+ .font(.headline)+ Text(form.help)+ .font(.callout)+ .foregroundStyle(.secondary)+ .fixedSize(horizontal: false, vertical: true)+ .padding(.bottom, 4)+ PassphraseFields(keyvault: keyvault, form: form)+ Text(keyvault.passphraseCheck?.hint ?? " ")+ .font(.caption)+ .foregroundStyle(.secondary)+ .fixedSize(horizontal: false, vertical: true)+ HStack {+ Spacer()+ Button("Cancel", role: .cancel) { done(false) }+ .keyboardShortcut(.cancelAction)+ Button(form.submitLabel) { done(true) }+ .keyboardShortcut(.defaultAction)+ .disabled(!keyvault.canSubmitCredential)+ }+ .padding(.top, 4)+ }+ .textFieldStyle(.roundedBorder)+ .padding(20)+ .frame(width: 380)+ .onSubmit { if keyvault.canSubmitCredential { done(true) } }+ }+}+struct Banner: View {let text: Stringlet error: Booldiff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swiftindex 6833fdec40..1e727dc001 100644--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIBridge.swift@@ -117,6 +117,9 @@ final class WebUIBridge: NSObject, WKScriptMessageHandlerWithReply {var teleportPlans: [String: (json: String, plan: TeleportPlan, providerId: String?)] = [:]/// Asks whether to delete (the native alert); tests answer it.var askDelete: (@MainActor (KvDeleteConfirm) async -> Bool)?+ /// Asks for the passphrase (the native sheet); tests fill the model's+ /// fields and answer it.+ var askPassphrase: (@MainActor (KvCredentialForm) async -> Bool)?/// Each Space's stream rows and picture-in-picture panels, as its/// detail view keeps them. A deleted Space's are closed and dropped/// (`pruneStreams`).@@ -805,40 +808,51 @@ final class WebUIBridge: NSObject, WKScriptMessageHandlerWithReply {}}- /// Unlocks (or sets up) the vault with Touch ID, the daemon's prompt. A- /// passphrase vault unlocks in the native window: a passphrase never- /// crosses the bridge.+ /// Unlocks the vault the way the core's form offers: Touch ID (the+ /// daemon's prompt), or a passphrase typed in a native sheet on this+ /// window (it never crosses the bridge).func unlockVault() async throws {let kv = model.keyvaultguard let form = kv.page.form else { return }- guard form.method == .touchId else {- actions?.openMain()- model.selection = .keyvault(.category(category: .all))- throw Failure(code: "native_only", message: "Enter the passphrase in the Cua Spaces window")- }+ try await askCredential(form, cancelled: "Unlock cancelled")await kv.submitCredential()}- /// "Set up Keyvault" on the web page: the core's setup form with Touch- /// ID, as the SwiftUI form sends it. A passphrase is typed only in the- /// native form (it never crosses the bridge). Answers the recovery key- /// to show once.+ /// "Set up Keyvault" on the web page: the core's setup form, Touch ID+ /// or a passphrase (asked as for unlock), sent as the SwiftUI form+ /// sends it. Answers the recovery key to show once.func setUpVault() async throws -> String? {let kv = model.keyvaultguard let form = kv.page.form, form.mode == .setup else {throw Failure(code: "failed", message: "Keyvault is already set up")}- guard form.method == .touchId else {- actions?.openMain()- model.selection = .keyvault(.category(category: .all))- throw Failure(code: "native_only", message: "Choose a passphrase in the Cua Spaces window")- }+ try await askCredential(form, cancelled: "Set up cancelled")kv.recoveryKey = nilawait kv.submitCredential()if let error = kv.error { throw Failure(code: "failed", message: error) }return kv.recoveryKey}+ /// A passphrase form: the sheet fills the model's fields. Closed+ /// without sending: `cancelled`, and the fields are cleared.+ func askCredential(_ form: KvCredentialForm, cancelled: String) async throws {+ guard form.method == .passphrase else { return }+ let kv = model.keyvault+ let sent: Bool+ if let askPassphrase {+ sent = await askPassphrase(form)+ } else if let host {+ sent = await host.askPassphrase(form, keyvault: kv)+ } else {+ sent = false+ }+ guard sent, kv.canSubmitCredential else {+ kv.passphrase = ""+ kv.passphraseConfirm = ""+ throw Failure(code: "cancelled", message: cancelled)+ }+ }+// MARK: - Argumentsfunc string(_ args: [String: Any], _ key: String) throws -> String {diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swiftindex 8b4e0be305..9f5bbe08c0 100644--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swift+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/WebUIWindow.swift@@ -382,6 +382,21 @@ public final class WebUIWindowController: NSWindowController, NSWindowDelegate,return response == .alertFirstButtonReturn}+ /// The Keyvault's passphrase form as a sheet on this window, bound to+ /// `keyvault`'s fields. True when the user sends it; the passphrase+ /// never reaches the page.+ func askPassphrase(_ form: KvCredentialForm, keyvault: KeyvaultModel) async -> Bool {+ showWindow(nil)+ guard let window else { return false }+ let sheet = NSWindow(contentRect: .zero, styleMask: [.titled], backing: .buffered, defer: false)+ sheet.isReleasedWhenClosed = false+ sheet.contentViewController = NSHostingController(rootView: PassphraseSheet(keyvault: keyvault, form: form) { [weak window, weak sheet] sent in+ guard let window, let sheet else { return }+ window.endSheet(sheet, returnCode: sent ? .OK : .cancel)+ })+ return await window.beginSheet(sheet) == .OK+ }+// MARK: - Windowpublic func windowDidEnterFullScreen(_ notification: Notification) { applyInset() }diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swiftindex 730f34a759..71bfa2ac38 100644--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/BridgeContractTests.swift@@ -274,8 +274,8 @@ struct BridgeContractTests {"devices.revoke": "changes the fixture account", "devices.confirmMachine": "changes the fixture account","stream.pip": "opens a picture-in-picture window","keyvault.delete": "asks in an alert; TeleportBridgeTests answers it",- "keyvault.unlock": "asks for Touch ID", "keyvault.unlockVault": "asks for Touch ID",- "keyvault.setup": "sets the vault up with Touch ID; keyvaultSetupRefusesASetUpVault covers the fixture",+ "keyvault.unlock": "asks for Touch ID", "keyvault.unlockVault": "asks for Touch ID or a passphrase in a sheet",+ "keyvault.setup": "asks for Touch ID or a passphrase in a sheet; keyvaultSetupRefusesASetUpVault covers the fixture","startup.act": "brings the app to the front; startupStatesHaveTheirShape covers the states",]diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/ViewModelTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/ViewModelTests.swiftindex a88abd5760..38c31e3d7e 100644--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/ViewModelTests.swift+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/ViewModelTests.swift@@ -111,6 +111,16 @@ final class FakeKeyvault: KeyvaultClientProtocol, @unchecked Sendable {}}+/// A case of the parity flow `keyvault-unlock.json` (setup or unlock, Touch+/// ID or a passphrase).+func keyvaultUnlockCase(_ name: String) throws -> KeyvaultOverview {+ let url = ParityTests.dir.appendingPathComponent("keyvault-unlock.json")+ let flow = try JSONSerialization.jsonObject(with: Data(contentsOf: url)) as! [String: Any]+ let c = (flow["cases"] as! [[String: Any]]).first { $0["name"] as? String == name }!+ let data = try JSONSerialization.data(withJSONObject: c["overview"]!)+ return try kvOverviewFromJson(json: String(decoding: data, as: UTF8.self))+}+func fixtureOverview() throws -> KeyvaultOverview {let url = ParityTests.dir.appendingPathComponent("keyvault-approve-deny.json")let flow = try JSONSerialization.jsonObject(with: Data(contentsOf: url)) as! [String: Any]@@ -1167,13 +1177,7 @@ struct ViewModelTests {#expect(w.view.address.error?.hasPrefix("The Space rejected the token") == true)}- func unlockCase(_ name: String) throws -> KeyvaultOverview {- let url = ParityTests.dir.appendingPathComponent("keyvault-unlock.json")- let flow = try JSONSerialization.jsonObject(with: Data(contentsOf: url)) as! [String: Any]- let c = (flow["cases"] as! [[String: Any]]).first { $0["name"] as? String == name }!- let data = try JSONSerialization.data(withJSONObject: c["overview"]!)- return try kvOverviewFromJson(json: String(decoding: data, as: UTF8.self))- }+ func unlockCase(_ name: String) throws -> KeyvaultOverview { try keyvaultUnlockCase(name) }@Test func passphraseSetupAndUnlockGoOnlyToTheBroker() async throws {let fake = FakeKeyvault(try unlockCase("setup-passphrase"))diff --git a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swiftindex ac0adfd2e2..f22e7d80ea 100644--- a/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift+++ b/apps/cua-spaces-macos/Tests/CuaSpacesMacTests/WebUIHostTests.swift@@ -171,8 +171,7 @@ struct WebUIHostTests {}/// "No Keyvault yet" on the web page: Set up Keyvault runs the core's- /// Touch ID setup and answers the recovery key once; a passphrase setup- /// stays in the native form.+ /// Touch ID setup and answers the recovery key once.@Test func setupFromTheWebPageAnswersTheRecoveryKey() async throws {var none = KeyvaultFixtures.overview()none.availability = "no_vault"@@ -191,11 +190,53 @@ struct WebUIHostTests {// Set up already: nothing to set up.#expect(await failure(bridge, "keyvault.setup", [:]) == "failed")- var passphraseOnly = none- passphraseOnly.status?.osProtectorAvailable = false- let (bridge2, model2) = self.bridge(kv: FakeKeyvault(passphraseOnly))- await model2.keyvault.refresh()- #expect(await failure(bridge2, "keyvault.setup", [:]) == "native_only")+ }++ /// A passphrase vault set up and unlocked from the web page: the native+ /// sheet fills the model's fields and the bridge submits them as the+ /// SwiftUI form does; the page's call carries no passphrase. Closing the+ /// sheet answers `cancelled` and clears the fields.+ @Test func passphraseSetupAndUnlockFromTheWebPageAskInTheSheet() async throws {+ let fake = FakeKeyvault(try keyvaultUnlockCase("setup-passphrase"))+ let (bridge, model) = bridge(kv: fake)+ let kv = model.keyvault+ await kv.refresh()+ #expect(kv.page.form?.method == .passphrase && kv.page.form?.mode == .setup)++ var asked: [KvCredentialForm] = []+ bridge.askPassphrase = { form in+ asked.append(form)+ kv.passphrase = "orbit lantern"+ return false+ }+ #expect(await failure(bridge, "keyvault.setup", [:]) == "cancelled")+ #expect(kv.passphrase.isEmpty && fake.passphrases.isEmpty)++ bridge.askPassphrase = { form in+ asked.append(form)+ kv.passphrase = "orbit lantern pickle harbor"+ kv.passphraseConfirm = "orbit lantern pickle harbor"+ return true+ }+ let r = try await bridge.handle("keyvault.setup", [:]) as? [String: Any]+ #expect(r?["recoveryKey"] as? String == "ABCDE-FGHJK")+ #expect(fake.passphrases == ["orbit lantern pickle harbor"])+ #expect(fake.commands.isEmpty)+ #expect(kv.passphrase.isEmpty && kv.passphraseConfirm.isEmpty)+ #expect(asked.allSatisfy { $0.mode == .setup && $0.confirmLabel != nil })++ fake.current = try keyvaultUnlockCase("unlock-passphrase")+ await kv.refresh()+ #expect(kv.page.canUnlock)+ bridge.askPassphrase = { form in+ asked.append(form)+ kv.passphrase = "orbit lantern pickle harbor"+ return true+ }+ _ = try await bridge.handle("keyvault.unlockVault", [:])+ #expect(asked.last?.mode == .unlock)+ #expect(fake.passphrases.count == 2)+ #expect(kv.page.ready)}@Test func cancelCreateAnswersWithTheSDKsWords() async throws {diff --git a/apps/cua-spaces-web/src/bridge/README.md b/apps/cua-spaces-web/src/bridge/README.mdindex 730968c2c8..e497ed0e34 100644--- a/apps/cua-spaces-web/src/bridge/README.md+++ b/apps/cua-spaces-web/src/bridge/README.md@@ -189,7 +189,9 @@ speaks it as is:`/settings`), and the page goes there.- `machines.list` carries `hostnames` (what each relay machine's cua-spacesdreported), so a machine and its enrolled device list once.-- `keyvault.unlock` with a passphrase fails with `native_only`.+- `keyvault.unlock` and `keyvault.setup` ask for a passphrase in the host's+ own prompt (a sheet on the Mac app's window, a window of the Electron+ shell); one sent from the page fails with `native_only`.Onboarding stays native. Appearance is kept in the page, and an appearancechange calls `window.setBackgroundColor`. The host registers ⌘⇧Spaceitself; `settings.get` carries `globalShortcut: {label, registered}`, anddiff --git a/apps/cua-spaces-web/src/bridge/adapters/webkit.ts b/apps/cua-spaces-web/src/bridge/adapters/webkit.tsindex 791cae3d1d..a9b5712f8b 100644--- a/apps/cua-spaces-web/src/bridge/adapters/webkit.ts+++ b/apps/cua-spaces-web/src/bridge/adapters/webkit.ts@@ -517,7 +517,7 @@ export function createWebkitAdapter(},"keyvault.overview": async () => toKeyvaultOverview(await request<WkKeyvault>("keyvault.get")),"keyvault.unlock": async ({ passphrase }) => {- if (passphrase) throw new HostError("Enter the passphrase in the Cua Spaces window", "native_only");+ if (passphrase) throw new HostError("Cua Spaces asks for the passphrase in its own prompt", "native_only");await request("keyvault.unlockVault");return null;},@@ -579,7 +579,7 @@ export function createWebkitAdapter(...webkitAgentDetailOps(request),...webkitAgentKeysOps(request),...webkitKeyvaultManageOps(request, toKeyvaultOverview as (wk: never) => KeyvaultOverview),- ...webkitKeyvaultSetupOps(request, () => new HostError("Enter the passphrase in the Cua Spaces window", "native_only")),+ ...webkitKeyvaultSetupOps(request, () => new HostError("Cua Spaces asks for the passphrase in its own prompt", "native_only")),// Electron draws a Space's video in the page, on a ticket from the// host; the Mac app draws it natively....(electrondiff --git a/apps/cua-spaces-web/src/bridge/coverage.ts b/apps/cua-spaces-web/src/bridge/coverage.tsindex a0bf221ac3..d4707e65cc 100644--- a/apps/cua-spaces-web/src/bridge/coverage.ts+++ b/apps/cua-spaces-web/src/bridge/coverage.ts@@ -81,7 +81,7 @@ export const HOST_COVERAGE = {},"keyvault.overview": { webkit: { methods: ["keyvault.get"] }, tauri: ["keyvault_overview"] },"keyvault.unlock": {- webkit: { methods: ["keyvault.unlockVault"], byDesign: "a passphrase never crosses the bridge: native_only" },+ webkit: { methods: ["keyvault.unlockVault"], byDesign: "the host asks for the passphrase itself: native_only" },tauri: ["keyvault_unlock", "keyvault_unlock_passphrase"],},"keyvault.setUnattended": {diff --git a/apps/cua-spaces-web/src/bridge/ops/keyvault-setup.ts b/apps/cua-spaces-web/src/bridge/ops/keyvault-setup.tsindex 73df5d8ed8..2fd76a9df4 100644--- a/apps/cua-spaces-web/src/bridge/ops/keyvault-setup.ts+++ b/apps/cua-spaces-web/src/bridge/ops/keyvault-setup.ts@@ -11,9 +11,10 @@* |---|---|---|* | `keyvault.setup {passphrase?}` | `keyvault_setup`, `keyvault_setup_passphrase` | `keyvault.setup` → `KeyvaultModel.submitCredential` |*- * A passphrase never crosses the SwiftUI bridge (`native_only`: the host- * opens its own form), as for `keyvault.unlock`; the Electron shell answers- * the same method.+ * A passphrase never crosses the webkit bridge: called without one, the+ * host asks in its own prompt (the Mac app's sheet, the Electron shell's+ * window) and a passphrase from the page is refused with `native_only`, as+ * for `keyvault.unlock`.*/import type { OpCoverage } from "../coverage";@@ -39,7 +40,7 @@ export const KEYVAULT_SETUP_WEBKIT_METHODS = KEYVAULT_SETUP_OPERATIONS;export const KEYVAULT_SETUP_COVERAGE = {"keyvault.setup": {- webkit: { methods: ["keyvault.setup"], byDesign: "a passphrase never crosses the bridge: native_only" },+ webkit: { methods: ["keyvault.setup"], byDesign: "the host asks for the passphrase itself: native_only" },tauri: ["keyvault_setup", "keyvault_setup_passphrase"],},} as const satisfies Record<KeyvaultSetupOp, OpCoverage>;@@ -71,7 +72,7 @@ export function tauriKeyvaultSetupOps(invoke: Invoke): Handlers {};}-/** The SwiftUI host: Touch ID setup only; it answers `{ recoveryKey }`. */+/** The Mac app and the Electron shell: the host asks for Touch ID or the passphrase itself; it answers `{ recoveryKey }`. */export function webkitKeyvaultSetupOps(request: Request, nativeOnly: () => Error): Handlers {return {"keyvault.setup": async ({ passphrase }) => {