fix(cua-macos): preserve optional geometry and reuse the selected click window

This commit is contained in:
creatixchu committed 2026-11-12 17:11:10 +08:00
1 parent bfef6e3942
commit 5bb6ae789c
7 files changed
+107 -51

No files matched your search

@@ -162,6 +162,13 @@ final class AXAccess {
})
}
}
private func processID(_ element: AXUIElement) throws -> pid_t {
try cancellation.check()
var pid: pid_t = 0
let error = AXUIElementGetPid(element, &pid)
guard error == .success else { throw failure(error, "identify element owner") }
return pid
}
func windowID(_ element: AXUIElement) throws -> UInt32? {
try prepare(element)
guard let windowFunction else { return nil }
@@ -432,10 +439,7 @@ final class AXAccess {
guard try string(node, "AXRole") == "AXMenuItem", try string(node, "AXMenuItemCmdChar")?.lowercased() == "v",
let raw = try attribute(node, "AXMenuItemCmdModifiers"), CFGetTypeID(raw) == CFNumberGetTypeID(),
let number = raw as? NSNumber, number.intValue == 0, try actions(node, requireKnown: true).contains("AXPress") else { return false }
var owner: pid_t = 0
let error = AXUIElementGetPid(node, &owner)
guard error == .success else { throw failure(error, "identify Paste command owner") }
guard owner == pid else { throw Self.beforeInput("UNSUPPORTED", "Paste command belongs to another process.") }
guard try processID(node) == pid else { throw Self.beforeInput("UNSUPPORTED", "Paste command belongs to another process.") }
return true
}, children: { try readChildren($0, budget: &budget) })
}
@@ -505,7 +509,7 @@ final class AXAccess {
return try bounds(position: position, size: attribute(element, "AXSize"))
}
/// WindowServer IDs identify a window or sheet even when other branches are incomplete.
func windowElement(_ id: UInt32, owner: ProcessIdentity, budget: inout AXChildRecoveryBudget) throws -> AXUIElement? {
func windowElement(_ id: UInt32, owner: ProcessIdentity, budget: inout AXChildRecoveryBudget, requireComplete: Bool) throws -> AXUIElement? {
let app = AXUIElementCreateApplication(owner.pid)
var seen = Set<AXUIElement>()
var windows: [AXUIElement] = []
@@ -528,7 +532,7 @@ final class AXAccess {
incomplete = incomplete || list.incomplete
index += 1
}
guard !incomplete else { throw Self.beforeInput("WINDOW_UNAVAILABLE", "Window or sheet discovery is incomplete.") }
guard !requireComplete || !incomplete else { throw Self.beforeInput("WINDOW_UNAVAILABLE", "Window or sheet discovery is incomplete.") }
return nil
}
private func bounds(position: CFTypeRef?, size: CFTypeRef?) throws -> WindowBounds? {
@@ -795,7 +799,12 @@ final class AXAccess {
}
/// A system file panel renders in its host window but receives input in the panel service's window.
func filePanelRecipient(_ node: AXUIElement, owner: ProcessIdentity, catalog: ApplicationCatalogSnapshot, budget: inout AXChildRecoveryBudget) throws -> (process: ProcessIdentity, windowID: UInt32)? {
let identifier = try stringValue(attribute(node, "AXIdentifier", allowMissingMetadata: false), attribute: "AXIdentifier")
let identifier: String?
do { identifier = try stringValue(attribute(node, "AXIdentifier", allowMissingMetadata: false), attribute: "AXIdentifier") }
catch let error as NativeFailure where error.attribute == "AXIdentifier" && error.accessibilityError == AXError.failure.rawValue {
if let role = try string(node, "AXRole"), role != "AXWindow" && role != "AXSheet" { return nil }
throw Self.beforeInput("PANEL_NOT_READY", "Could not identify the window or sheet.")
}
guard ["open-panel", "save-panel"].contains(identifier ?? "") else { return nil }
guard let hostID = try windowID(node) else { throw Self.beforeInput("PANEL_NOT_READY", "File panel has no window ID.") }
_ = try NativePlatform.ownedWindow(owner.pid, hostID)
@@ -804,7 +813,12 @@ final class AXAccess {
guard !children.incomplete else { throw Self.beforeInput("PANEL_NOT_READY", "File panel recipient discovery is incomplete.") }
let windows = NativePlatform.windows(allLayers: true)
for case let child? in children.entries {
guard let id = try windowID(child), let window = windows.first(where: { $0.windowID == id }) else {
guard let id = try windowID(child) else {
// A local control without a window cannot be the panel service's input window.
if try processID(child) == owner.pid, let role = try string(child, "AXRole"), role != "AXWindow" && role != "AXSheet" { continue }
throw Self.beforeInput("PANEL_NOT_READY", "File panel child window could not be identified.")
}
guard let window = windows.first(where: { $0.windowID == id }) else {
throw Self.beforeInput("PANEL_NOT_READY", "File panel child window could not be identified.")
}
guard window.pid != owner.pid else { continue }
@@ -825,8 +839,7 @@ final class AXAccess {
throw Self.beforeInput("PANEL_NOT_READY", "System file panel focus changed.")
}
func keyboardRecipient(_ owner: ProcessIdentity, catalog: ApplicationCatalogSnapshot) throws -> ProcessIdentity {
var budget = AXChildRecoveryBudget(timeout: timeout)
func keyboardRecipient(_ owner: ProcessIdentity, catalog: ApplicationCatalogSnapshot, budget: inout AXChildRecoveryBudget) throws -> ProcessIdentity {
var current = try element(AXUIElementCreateApplication(owner.pid), "AXFocusedWindow")
var visited: [AXUIElement] = []
for _ in 0..<100 {
@@ -7,7 +7,7 @@ struct AXChildRecoveryBudget: Sendable {
var requests: Int
var time: Duration
init(maxElements: Int = NativeProtocol.elementRange.upperBound, timeout: Float) {
init(maxElements: Int, timeout: Float) {
limit = maxElements
requests = maxElements
time = .seconds(Double(timeout))
@@ -173,25 +173,30 @@ actor AXWorker {
throw NativeFailure(code: "STALE_SNAPSHOT", message: "Snapshot belongs to window \(source); read getAccessibilityTree on window \(windowID)")
}
}
private func coordinateWindow(_ identity: ProcessIdentity, _ windowID: UInt32, budget: inout AXChildRecoveryBudget, trace: ScreenshotTrace? = nil) throws -> WindowInfo {
try WindowGeometry.resolve(owner: identity, windowID: windowID, readWindow: { pid, id in
private func coordinateWindow(_ identity: ProcessIdentity, _ windowID: UInt32, budget: inout AXChildRecoveryBudget, forClick: Bool = false,
trace: ScreenshotTrace? = nil) throws -> (window: WindowInfo, element: AXUIElement?) {
var element: AXUIElement?
let window = try WindowGeometry.resolve(owner: identity, windowID: windowID, readWindow: { pid, id in
trace?.mark("window-info.begin")
let window = try NativePlatform.ownedWindow(pid, id)
trace?.mark("window-info.end")
return window
}) {
// Capture without Accessibility permission retains its CG/SCK checks.
guard AXIsProcessTrusted() else { return nil }
guard forClick || AXIsProcessTrusted() else { return nil }
trace?.mark("ax-geometry.begin")
let bounds = try ax().windowElement(windowID, owner: identity, budget: &budget).flatMap { try ax().bounds($0) }
element = try ax().windowElement(windowID, owner: identity, budget: &budget, requireComplete: forClick)
let bounds = try element.flatMap { try ax().bounds($0) }
trace?.mark("ax-geometry.end")
return bounds
}
return (window, element)
}
private func observedCoordinateWindow(_ handle: String, _ identity: ProcessIdentity, _ windowID: UInt32, budget: inout AXChildRecoveryBudget) throws -> WindowInfo {
let window = try coordinateWindow(identity, windowID, budget: &budget)
try WindowGeometry.validateObservedSize(observed: observedWindowBounds[handle]?[windowID], current: window.bounds)
return window
private func observedCoordinateWindow(_ handle: String, _ identity: ProcessIdentity, _ windowID: UInt32, budget: inout AXChildRecoveryBudget,
forClick: Bool = false) throws -> (window: WindowInfo, element: AXUIElement?) {
let target = try coordinateWindow(identity, windowID, budget: &budget, forClick: forClick)
try WindowGeometry.validateObservedSize(observed: observedWindowBounds[handle]?[windowID], current: target.window.bounds)
return target
}
static var actionResult: JSONValue { .object(["dispatched": .bool(true)]) }
/// Select the element's default action; Press takes precedence over Pick.
@@ -216,12 +221,13 @@ actor AXWorker {
try keyboard?.releaseHeldKeys(run: params.string("runId"))
return .result(Self.actionResult)
}
var recovery = AXChildRecoveryBudget(maxElements: NativeProtocol.elementRange.upperBound, timeout: axTimeout)
if method == "sendKeyEvent", try params.string("direction") == "up" {
let handle = try params.string("appHandle")
let dispatched = try inputs().0.keyUp(params.string("key"), app: handle, run: params.string("runId")) {
try NativePlatform.requireUnlocked(observeSession())
try NativePlatform.requireAccessibility()
return try ax().keyboardRecipient(validateIdentity(handle), catalog: catalog)
return try ax().keyboardRecipient(validateIdentity(handle), catalog: catalog, budget: &recovery)
}
return .result(.object(["dispatched": .bool(dispatched)]))
}
@@ -297,7 +303,6 @@ actor AXWorker {
else { observedWindowBounds.removeValue(forKey: handle) }
}
if method != "screenshot" { try NativePlatform.requireAccessibility() }
var recovery = AXChildRecoveryBudget(timeout: axTimeout)
switch method {
case "show":
let windowID = try params.optionalWindowID()
@@ -350,7 +355,7 @@ actor AXWorker {
try NativePlatform.requireScreenRecording()
trace?.mark("screen-permission.end")
trace?.mark("geometry.before.begin")
let window = try coordinateWindow(identity, params.windowID(), budget: &recovery, trace: trace)
let window = try coordinateWindow(identity, params.windowID(), budget: &recovery, trace: trace).window
trace?.mark("geometry.before.end")
return .capture(CaptureTarget(appHandle: handle, process: identity, window: window, recovery: recovery))
case "listActions":
@@ -362,10 +367,10 @@ actor AXWorker {
maxElements: try params.integer("maxElements", in: NativeProtocol.elementRange), maxDepth: try params.integer("maxDepth", in: NativeProtocol.depthRange)))
case "sendKeyEvent":
try inputs().0.keyDown(params.string("key"), app: handle, run: params.string("runId")) {
try ax().keyboardRecipient(identity, catalog: catalog)
try ax().keyboardRecipient(identity, catalog: catalog, budget: &recovery)
}
case "typeText", "pressKey":
let recipient = try ax().keyboardRecipient(identity, catalog: catalog)
let recipient = try ax().keyboardRecipient(identity, catalog: catalog, budget: &recovery)
try NativePlatform.verify(recipient)
if method == "typeText" { try inputs().0.typeText(params.string("text"), to: recipient.pid) }
else { try inputs().0.pressKey(params.string("key"), modifiers: params.modifiers(), to: recipient.pid) }
@@ -415,7 +420,7 @@ actor AXWorker {
} else {
let id = try params.windowID()
try coordinateSnapshot(handle, params, id)
window = try observedCoordinateWindow(handle, identity, id, budget: &recovery)
(window, elementWindow) = try observedCoordinateWindow(handle, identity, id, budget: &recovery, forClick: method == "click")
point = try params.point()
}
let route = WindowRoute(owner: identity, windowID: window.windowID, bounds: window.bounds)
@@ -429,8 +434,7 @@ actor AXWorker {
return .mouseMove(route, point)
}
var clickRoute = route
try NativePlatform.requireAccessibility()
if let node = try elementWindow ?? ax().windowElement(window.windowID, owner: identity, budget: &recovery),
if let node = elementWindow,
let panel = try ax().filePanelRecipient(node, owner: identity, catalog: catalog, budget: &recovery) {
let serviceWindow = try NativePlatform.ownedWindow(panel.process.pid, panel.windowID)
guard serviceWindow.bounds == window.bounds else {
@@ -444,7 +448,7 @@ actor AXWorker {
case "scroll", "drag":
let id = try params.windowID()
try coordinateSnapshot(handle, params, id)
let window = try observedCoordinateWindow(handle, identity, id, budget: &recovery)
let window = try observedCoordinateWindow(handle, identity, id, budget: &recovery).window
let route = WindowRoute(owner: identity, windowID: id, bounds: window.bounds)
if method == "scroll" {
let dx = params.contains("deltaLinesX") ? try params.integer("deltaLinesX", in: -10...10) : 0
@@ -520,7 +524,7 @@ actor AXWorker {
try NativePlatform.requireScreenRecording()
trace?.mark("geometry.after.begin")
var recovery = target.recovery
let after = try coordinateWindow(identity, target.window.windowID, budget: &recovery, trace: trace)
let after = try coordinateWindow(identity, target.window.windowID, budget: &recovery, trace: trace).window
trace?.mark("geometry.after.end")
guard after.bounds == target.window.bounds else { throw NativeFailure(code: "WINDOW_CHANGED", message: "Window moved or resized during capture; observe again") }
observedWindowBounds[target.appHandle, default: [:]][after.windowID] = after.bounds
@@ -118,7 +118,7 @@ import ApplicationServices
let goodID = UInt32(good.windowNumber), badID = UInt32(bad.windowNumber)
app.setAccessibilityWindows([good, bad])
var exhausted = AXChildRecoveryBudget(maxElements: 0, timeout: 0)
let exact = try access.windowElement(badID, owner: identity, budget: &exhausted)
let exact = try access.windowElement(badID, owner: identity, budget: &exhausted, requireComplete: true)
try check(exact == badRoot, "An earlier window's unreadable children blocked an exact ID")
app.setAccessibilityWindows([good])
@@ -126,15 +126,18 @@ import ApplicationServices
for children: [Any] in [[bad, NSNull()], [NSNull(), bad]] {
good.childList = children
var budget = AXChildRecoveryBudget(maxElements: 16, timeout: 3)
let sheet = try access.windowElement(badID, owner: identity, budget: &budget)
let sheet = try access.windowElement(badID, owner: identity, budget: &budget, requireComplete: true)
try check(sheet == badRoot && budget.requests < 16, "A recovered sheet was lost at the gap")
let left = budget.requests
_ = try access.windowElement(goodID, owner: identity, budget: &budget)
_ = try access.windowElement(goodID, owner: identity, budget: &budget, requireComplete: true)
try check(budget.requests == left, "An exact window consumed additional recovery requests")
for (requests, time): (Int, Float) in [(1, 3), (16, 0)] {
var insufficient = AXChildRecoveryBudget(maxElements: requests, timeout: time)
var geometryBudget = insufficient
let geometry = try access.windowElement(badID, owner: identity, budget: &geometryBudget, requireComplete: false)
try check(geometry == nil, "Incomplete optional AX geometry should leave the CG frame available")
do {
_ = try access.windowElement(badID, owner: identity, budget: &insufficient)
_ = try access.windowElement(badID, owner: identity, budget: &insufficient, requireComplete: true)
throw NativeFailure(code: "FIXTURE", message: "Unseen sheet accepted after recovery exhausted")
} catch let failure as NativeFailure where failure.code == "WINDOW_UNAVAILABLE" {
try check(failure.message.contains("No input was dispatched. Read fresh state"), failure.message)
@@ -141,8 +141,12 @@ import Testing
let root = AXUIElementCreateApplication(10)
let first = AXUIElementCreateApplication(11)
let other = AXUIElementCreateApplication(12)
var requests = 2
let restored = AXObservedChildren.readRanges(count: 2, limit: 2, requests: &requests) { range in
.values(range.lowerBound == 0 ? [other] : [first])
}
let cases: [(AXObservedChildren, Set<AXUIElement>, String?)] = [
(.init(entries: [first, other]), [first], nil),
(restored, [first], nil),
(.init(entries: [other, first, first]), [first], nil),
(.init(entries: [first, nil]), [first], "incomplete"),
(.init(entries: [nil, first]), [first], "incomplete"),
@@ -174,3 +178,20 @@ import Testing
#expect(board.string(forType: .string) == "original")
}
}
@Test func pasteTraversalLimitsApplyAfterFindingACandidate() {
let root = AXUIElementCreateApplication(10), candidate = AXUIElementCreateApplication(11)
let nested = AXUIElementCreateApplication(12)
for (count, depth) in [(2, 5), (10, 1)] {
do {
_ = try AXAccess.pasteCommand(in: root, maxElements: count, maxDepth: depth, matches: { $0 == candidate }) {
if $0 == root { return .init(entries: [candidate]) }
return .init(entries: $0 == candidate ? [nested] : [])
}
Issue.record("A traversal limit hid a possible second Paste command")
} catch let error as NativeFailure {
#expect(error.code == "UNSUPPORTED")
#expect(error.message.contains("No input was dispatched. Read fresh state"))
} catch { Issue.record("Unexpected error: \(error)") }
}
}
@@ -35,7 +35,7 @@ private final class HeldCapture: @unchecked Sendable {
let target = CaptureTarget(appHandle: "fixture", process: ProcessIdentity(pid: 1, startedSeconds: 1, startedMicroseconds: 0),
window: WindowInfo(windowID: 1, pid: 1, appName: "fixture", title: "fixture",
bounds: WindowBounds(x: 0, y: 0, width: 1, height: 1), isOnScreen: true, onCurrentSpace: true),
recovery: AXChildRecoveryBudget(timeout: 1))
recovery: AXChildRecoveryBudget(maxElements: 1, timeout: 1))
func request() -> Task<JSONValue, any Error> {
Task {
try await scheduler.perform(cancellation: cancellation) {
+31 -16
View File
@@ -332,31 +332,46 @@
{"type":"tool/result","data":{"turn":1,"step":64,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-floating-verify"},"toolCallId":"cua-floating-verify","content":[{"type":"text","text":"{\"appHandle\":\"fixture-app\",\"windowId\":\"10\",\"focusedWindowId\":\"7\",\"snapshotId\":\"fixture-snapshot-17\",\"tree\":\"AX scope=window offsets=UTF-16\\n- AXWindow \\\"Floating panel\\\"\\n [One child could not be read.]\\n - AXStaticText \\\"Floating count: 1\\\"\",\"windows\":[{\"windowId\":\"7\",\"appName\":\"Fixture\",\"title\":\"CUA fixture\",\"bounds\":{\"x\":40,\"y\":60,\"width\":320,\"height\":200},\"isOnScreen\":true,\"onCurrentSpace\":true},{\"windowId\":\"8\",\"appName\":\"Fixture\",\"title\":\"AXless canvas\",\"bounds\":{\"x\":40,\"y\":60,\"width\":320,\"height\":200},\"isOnScreen\":true,\"onCurrentSpace\":true},{\"windowId\":\"9\",\"appName\":\"Fixture\",\"title\":\"Transformed window\",\"bounds\":{\"x\":16,\"y\":512,\"width\":131,\"height\":145},\"isOnScreen\":true,\"onCurrentSpace\":true},{\"windowId\":\"10\",\"appName\":\"Fixture\",\"title\":\"Floating panel\",\"bounds\":{\"x\":100,\"y\":120,\"width\":240,\"height\":140},\"isOnScreen\":true,\"onCurrentSpace\":true}],\"truncated\":false,\"hasUnreadableElements\":true}"}],"isError":false,"id":"{{message:131}}"}},"sourceEventSeqs":[329],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":64}}
{"type":"step/start","data":{"turn":1,"step":65}}
{"type":"assistant/message","data":{"turn":1,"step":65,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-debug-arm","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F12\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:132}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794214351968,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794214351968,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-debug-arm","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F12\"}}"}}},{"type":"chunk","time":1794214351968,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794214351968,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":65,"callId":"cua-debug-arm","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F12\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":65,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-debug-arm"},"toolCallId":"cua-debug-arm","content":[{"type":"text","text":"{\"dispatched\":true}"}],"isError":false,"id":"{{message:133}}"}},"sourceEventSeqs":[334],"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":65,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-incomplete-targets","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F6\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:132}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427280,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427280,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-incomplete-targets","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F6\"}}"}}},{"type":"chunk","time":1794474427280,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427280,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":65,"callId":"cua-incomplete-targets","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F6\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":65,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-incomplete-targets"},"toolCallId":"cua-incomplete-targets","content":[{"type":"text","text":"{\"dispatched\":true}"}],"isError":false,"id":"{{message:133}}"}},"sourceEventSeqs":[334],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":65}}
{"type":"step/start","data":{"turn":1,"step":66}}
{"type":"assistant/message","data":{"turn":1,"step":66,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-debug-screenshot","name":"cua","arguments":"{\"method\":\"screenshot\",\"params\":{\"appHandle\":\"fixture-app\",\"windowId\":\"7\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:134}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794214351994,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794214351994,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-debug-screenshot","name":"cua","arguments":"{\"method\":\"screenshot\",\"params\":{\"appHandle\":\"fixture-app\",\"windowId\":\"7\"}}"}}},{"type":"chunk","time":1794214351994,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794214351994,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":66,"callId":"cua-debug-screenshot","name":"cua","arguments":"{\"method\":\"screenshot\",\"params\":{\"appHandle\":\"fixture-app\",\"windowId\":\"7\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":66,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-debug-screenshot"},"toolCallId":"cua-debug-screenshot","content":[{"type":"text","text":"Error: NATIVE_PROTOCOL: Helper returned an invalid response; acquire fresh application handles\nScreenshot diagnostics:\n[cua-screenshot] {\"requestId\":\"cua-debug-screenshot\",\"stage\":\"capture-image.begin\",\"elapsedMs\":1}"}],"isError":true,"id":"{{message:135}}"},"error":{"name":"NativeError","code":"NATIVE_PROTOCOL"}},"sourceEventSeqs":[339],"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":66,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-incomplete-menu","name":"cua","arguments":"{\"method\":\"paste\",\"params\":{\"appHandle\":\"fixture-app\",\"text\":\"fixture\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:134}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427307,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427307,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-incomplete-menu","name":"cua","arguments":"{\"method\":\"paste\",\"params\":{\"appHandle\":\"fixture-app\",\"text\":\"fixture\"}}"}}},{"type":"chunk","time":1794474427307,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427307,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":66,"callId":"cua-incomplete-menu","name":"cua","arguments":"{\"method\":\"paste\",\"params\":{\"appHandle\":\"fixture-app\",\"text\":\"fixture\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":66,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-incomplete-menu"},"toolCallId":"cua-incomplete-menu","content":[{"type":"text","text":"Error: UNSUPPORTED: Paste menu discovery is incomplete. No input was dispatched. Read fresh state before retrying."}],"isError":true,"id":"{{message:135}}"},"error":{"name":"NativeError","code":"UNSUPPORTED"}},"sourceEventSeqs":[339],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":66}}
{"type":"step/start","data":{"turn":1,"step":67}}
{"type":"assistant/message","data":{"turn":1,"step":67,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-consent-denied","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Denied Fixture\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:136}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794214352032,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794214352032,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-consent-denied","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Denied Fixture\"}}"}}},{"type":"chunk","time":1794214352032,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794214352032,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":67,"callId":"cua-consent-denied","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Denied Fixture\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":67,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-consent-denied"},"toolCallId":"cua-consent-denied","content":[{"type":"text","text":"Error: APP_ACCESS_DENIED: The user denied access to Denied Fixture. Do not retry or use another tool to bypass this decision."}],"isError":true,"id":"{{message:137}}"},"error":{"name":"NativeError","code":"APP_ACCESS_DENIED"}},"sourceEventSeqs":[344],"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":67,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-incomplete-panel","name":"cua","arguments":"{\"method\":\"typeText\",\"params\":{\"appHandle\":\"fixture-app\",\"text\":\"fixture\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:136}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427336,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427336,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-incomplete-panel","name":"cua","arguments":"{\"method\":\"typeText\",\"params\":{\"appHandle\":\"fixture-app\",\"text\":\"fixture\"}}"}}},{"type":"chunk","time":1794474427336,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427336,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":67,"callId":"cua-incomplete-panel","name":"cua","arguments":"{\"method\":\"typeText\",\"params\":{\"appHandle\":\"fixture-app\",\"text\":\"fixture\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":67,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-incomplete-panel"},"toolCallId":"cua-incomplete-panel","content":[{"type":"text","text":"Error: PANEL_NOT_READY: File panel recipient discovery is incomplete. No input was dispatched. Read fresh state before retrying."}],"isError":true,"id":"{{message:137}}"},"error":{"name":"NativeError","code":"PANEL_NOT_READY"}},"sourceEventSeqs":[344],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":67}}
{"type":"step/start","data":{"turn":1,"step":68}}
{"type":"assistant/message","data":{"turn":1,"step":68,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-consent-revocable","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Revocable Fixture\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:138}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794214352213,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794214352213,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-consent-revocable","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Revocable Fixture\"}}"}}},{"type":"chunk","time":1794214352213,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794214352213,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":68,"callId":"cua-consent-revocable","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Revocable Fixture\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":68,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-consent-revocable"},"toolCallId":"cua-consent-revocable","content":[{"type":"text","text":"{\"appHandle\":\"revoked-app\",\"name\":\"Revocable Fixture\",\"running\":true}"}],"isError":false,"id":"{{message:139}}"}},"sourceEventSeqs":[349],"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":68,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-debug-arm","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F12\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:138}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427365,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427365,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-debug-arm","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F12\"}}"}}},{"type":"chunk","time":1794474427365,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427365,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":68,"callId":"cua-debug-arm","name":"cua","arguments":"{\"method\":\"pressKey\",\"params\":{\"appHandle\":\"fixture-app\",\"key\":\"F12\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":68,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-debug-arm"},"toolCallId":"cua-debug-arm","content":[{"type":"text","text":"{\"dispatched\":true}"}],"isError":false,"id":"{{message:139}}"}},"sourceEventSeqs":[349],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":68}}
{"type":"step/start","data":{"turn":1,"step":69}}
{"type":"assistant/message","data":{"turn":1,"step":69,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-consent-revoked","name":"cua","arguments":"{\"method\":\"getState\",\"params\":{\"appHandle\":\"revoked-app\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:140}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794214352404,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794214352404,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-consent-revoked","name":"cua","arguments":"{\"method\":\"getState\",\"params\":{\"appHandle\":\"revoked-app\"}}"}}},{"type":"chunk","time":1794214352404,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794214352404,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":69,"callId":"cua-consent-revoked","name":"cua","arguments":"{\"method\":\"getState\",\"params\":{\"appHandle\":\"revoked-app\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":69,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-consent-revoked"},"toolCallId":"cua-consent-revoked","content":[{"type":"text","text":"Error: APP_ACCESS_REVOKED: Application access was revoked; stop using this application"}],"isError":true,"id":"{{message:141}}"},"error":{"name":"NativeError","code":"APP_ACCESS_REVOKED"}},"sourceEventSeqs":[354],"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":69,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-debug-screenshot","name":"cua","arguments":"{\"method\":\"screenshot\",\"params\":{\"appHandle\":\"fixture-app\",\"windowId\":\"7\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:140}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427395,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427395,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-debug-screenshot","name":"cua","arguments":"{\"method\":\"screenshot\",\"params\":{\"appHandle\":\"fixture-app\",\"windowId\":\"7\"}}"}}},{"type":"chunk","time":1794474427395,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427395,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":69,"callId":"cua-debug-screenshot","name":"cua","arguments":"{\"method\":\"screenshot\",\"params\":{\"appHandle\":\"fixture-app\",\"windowId\":\"7\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":69,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-debug-screenshot"},"toolCallId":"cua-debug-screenshot","content":[{"type":"text","text":"Error: NATIVE_PROTOCOL: Helper returned an invalid response; acquire fresh application handles\nScreenshot diagnostics:\n[cua-screenshot] {\"requestId\":\"cua-debug-screenshot\",\"stage\":\"capture-image.begin\",\"elapsedMs\":1}"}],"isError":true,"id":"{{message:141}}"},"error":{"name":"NativeError","code":"NATIVE_PROTOCOL"}},"sourceEventSeqs":[354],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":69}}
{"type":"step/start","data":{"turn":1,"step":70}}
{"type":"assistant/message","data":{"turn":1,"step":70,"message":{"role":"assistant","content":[{"type":"text","text":"Observed Count: 4 after hovering, observing and clicking the revealed control. Moving away dismissed the hover information. Geometry conflicts rejected capture and coordinate gestures; the advertised AX button action remained available. No automatic activation or input retry was requested."}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:142}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794214352423,"chunk":{"type":"block-start","index":0,"blockType":"text"}},{"type":"chunk","time":1794214352423,"chunk":{"type":"block-end","index":0,"block":{"type":"text","text":"Observed Count: 4 after hovering, observing and clicking the revealed control. Moving away dismissed the hover information. Geometry conflicts rejected capture and coordinate gestures; the advertised AX button action remained available. No automatic activation or input retry was requested."}}},{"type":"chunk","time":1794214352423,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794214352423,"chunk":{"type":"finish","reason":{"kind":"stop"}}}]},"surfaceOp":"append"}
{"type":"assistant/message","data":{"turn":1,"step":70,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-consent-denied","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Denied Fixture\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:142}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427445,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427445,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-consent-denied","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Denied Fixture\"}}"}}},{"type":"chunk","time":1794474427445,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427445,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":70,"callId":"cua-consent-denied","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Denied Fixture\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":70,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-consent-denied"},"toolCallId":"cua-consent-denied","content":[{"type":"text","text":"Error: APP_ACCESS_DENIED: The user denied access to Denied Fixture. Do not retry or use another tool to bypass this decision."}],"isError":true,"id":"{{message:143}}"},"error":{"name":"NativeError","code":"APP_ACCESS_DENIED"}},"sourceEventSeqs":[359],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":70}}
{"type":"step/start","data":{"turn":1,"step":71}}
{"type":"assistant/message","data":{"turn":1,"step":71,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-consent-revocable","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Revocable Fixture\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:144}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427665,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427665,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-consent-revocable","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Revocable Fixture\"}}"}}},{"type":"chunk","time":1794474427665,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427665,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":71,"callId":"cua-consent-revocable","name":"cua","arguments":"{\"method\":\"getApp\",\"params\":{\"selector\":\"Revocable Fixture\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":71,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-consent-revocable"},"toolCallId":"cua-consent-revocable","content":[{"type":"text","text":"{\"appHandle\":\"revoked-app\",\"name\":\"Revocable Fixture\",\"running\":true}"}],"isError":false,"id":"{{message:145}}"}},"sourceEventSeqs":[364],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":71}}
{"type":"step/start","data":{"turn":1,"step":72}}
{"type":"assistant/message","data":{"turn":1,"step":72,"message":{"role":"assistant","content":[{"type":"tool-call","id":"cua-consent-revoked","name":"cua","arguments":"{\"method\":\"getState\",\"params\":{\"appHandle\":\"revoked-app\"}}"}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:146}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427920,"chunk":{"type":"block-start","index":0,"blockType":"tool-call"}},{"type":"chunk","time":1794474427920,"chunk":{"type":"block-end","index":0,"block":{"type":"tool-call","id":"cua-consent-revoked","name":"cua","arguments":"{\"method\":\"getState\",\"params\":{\"appHandle\":\"revoked-app\"}}"}}},{"type":"chunk","time":1794474427920,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427920,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":72,"callId":"cua-consent-revoked","name":"cua","arguments":"{\"method\":\"getState\",\"params\":{\"appHandle\":\"revoked-app\"}}"}}
{"type":"tool/result","data":{"turn":1,"step":72,"message":{"role":"tool","source":{"kind":"tool","callId":"cua-consent-revoked"},"toolCallId":"cua-consent-revoked","content":[{"type":"text","text":"Error: APP_ACCESS_REVOKED: Application access was revoked; stop using this application"}],"isError":true,"id":"{{message:147}}"},"error":{"name":"NativeError","code":"APP_ACCESS_REVOKED"}},"sourceEventSeqs":[369],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":72}}
{"type":"step/start","data":{"turn":1,"step":73}}
{"type":"assistant/message","data":{"turn":1,"step":73,"message":{"role":"assistant","content":[{"type":"text","text":"Observed Count: 4 after hovering, observing and clicking the revealed control. Moving away dismissed the hover information. Geometry conflicts rejected capture and coordinate gestures; the advertised AX button action remained available. No automatic activation or input retry was requested."}],"source":{"kind":"model","provider":"deepseek-official","model":"deepseek-v4-flash-vision-exp"},"id":"{{message:148}}"},"usage":{"inputTokens":3,"outputTokens":3},"stream":[{"type":"chunk","time":1794474427942,"chunk":{"type":"block-start","index":0,"blockType":"text"}},{"type":"chunk","time":1794474427942,"chunk":{"type":"block-end","index":0,"block":{"type":"text","text":"Observed Count: 4 after hovering, observing and clicking the revealed control. Moving away dismissed the hover information. Geometry conflicts rejected capture and coordinate gestures; the advertised AX button action remained available. No automatic activation or input retry was requested."}}},{"type":"chunk","time":1794474427942,"chunk":{"type":"usage","usage":{"inputTokens":3,"outputTokens":3}}},{"type":"chunk","time":1794474427942,"chunk":{"type":"finish","reason":{"kind":"stop"}}}]},"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":73}}
{"type":"turn/end","data":{"turn":1,"reason":{"kind":"completed"}}}