Skip to content

Commit 163fecb

Browse files
committed
refactor(macos): name computer-use executors for their scope
The computer.act v1 wire contract is gone, but the naming that survived it still described a version split instead of the real one: screen-coordinate execution versus window/element-scoped execution. Both are live rungs of the same ladder. - Extract the screen-coordinate half of the 1334-line ComputerActionService into ComputerScreenActionExecutor (dispatch, typing, scroll, coordinate mapping, button-hold watchdog, raw CoreGraphics primitives). Moved code is unchanged apart from threading the queue authority check as a parameter instead of reaching back into the queue. - ComputerActionService keeps its name and becomes the coordinator that owns the execution queue, the permission probe, and the shared error vocabulary. - Rename ComputerActionServiceV2 to ComputerWindowActionExecutor, isV2Request to isWindowScopedRequest, isComputerActV2Only to isWindowScopedOnly, and ComputerActionError.invalidV2Request to .invalidRequest. The emitted COMPUTER_INVALID_REQUEST: prefix is unchanged. - cua-computer: v2-actions.ts becomes window-actions.ts, handleV2Act becomes handleWindowAct, and the stale v1Params local in handleDesktopAct becomes desktopParams. - Note at the computer.act idempotency key that its v1 prefix versions the key composition, not the wire contract. Behavior-neutral: no logic edits, no new branches, no changed error strings.
1 parent 1787fd6 commit 163fecb

10 files changed

Lines changed: 955 additions & 894 deletions

File tree

‎apps/macos/Sources/OpenClaw/ComputerActionService.swift‎

Lines changed: 28 additions & 772 deletions
Large diffs are not rendered by default.

‎apps/macos/Sources/OpenClaw/ComputerScreenActionExecutor.swift‎

Lines changed: 787 additions & 0 deletions
Large diffs are not rendered by default.

apps/macos/Sources/OpenClaw/ComputerActionServiceV2.swift renamed to apps/macos/Sources/OpenClaw/ComputerWindowActionExecutor.swift

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@ extension CGRect {
1212
}
1313

1414
extension OpenClawComputerActParams {
15-
var isV2Request: Bool {
16-
self.action.isComputerActV2Only || self.windowRef != nil || self.elementRef != nil ||
15+
/// True when the request names a window, element, or observation, or asks for
16+
/// an action that has no screen-coordinate form. Such requests must run on
17+
/// `ComputerWindowActionExecutor`; everything else is screen-coordinate work.
18+
var isWindowScopedRequest: Bool {
19+
self.action.isWindowScopedOnly || self.windowRef != nil || self.elementRef != nil ||
1720
self.observationId != nil
1821
}
1922
}
2023

2124
extension OpenClawComputerAction {
22-
var isComputerActV2Only: Bool {
25+
/// True for actions that cannot be expressed as screen-coordinate input and
26+
/// therefore always need a window/element target.
27+
var isWindowScopedOnly: Bool {
2328
switch self {
2429
case .leftClick, .rightClick, .middleClick, .doubleClick, .tripleClick, .mouseMove,
2530
.leftClickDrag, .leftMouseDown, .leftMouseUp, .scroll, .type, .key, .holdKey:
@@ -42,11 +47,14 @@ struct ComputerActionExecutionAuthority {
4247
}
4348
}
4449

45-
/// Implements the additive computer.act v2 surface without changing the v1
46-
/// coordinate path. All authority-bearing references are process-local,
47-
/// execution-local, and invalidated when the native lifecycle generation moves.
50+
/// Executes the window- and element-scoped half of `computer.act`: discovery,
51+
/// app/window lifecycle, and accessibility-targeted input. Its peer
52+
/// `ComputerScreenActionExecutor` owns the screen-coordinate half; both are
53+
/// routed by `ComputerActionService`. All authority-bearing references are
54+
/// process-local, execution-local, and invalidated when the native lifecycle
55+
/// generation moves.
4856
@MainActor
49-
final class ComputerActionServiceV2 {
57+
final class ComputerWindowActionExecutor {
5058
struct WindowTarget {
5159
let app: ServiceApplicationInfo
5260
let window: ServiceWindowInfo
@@ -365,7 +373,7 @@ final class ComputerActionServiceV2 {
365373
private func killApp(_ params: OpenClawComputerActParams) async throws -> OpenClawComputerActResult {
366374
let appRef = try Self.require(params.app, field: "app")
367375
guard let app = self.appRefs[appRef], let identity = app.processIdentity else {
368-
throw ComputerActionService.ComputerActionError.invalidV2Request(
376+
throw ComputerActionService.ComputerActionError.invalidRequest(
369377
"kill_app requires a running app reference from list_apps")
370378
}
371379
let quit = try await self.withExecutionAuthority {
@@ -406,7 +414,7 @@ final class ComputerActionServiceV2 {
406414
if mode == .foreground {
407415
try await self.focus(target)
408416
guard target.window.bounds.contains(resolved.point) else {
409-
throw ComputerActionService.ComputerActionError.invalidV2Request(
417+
throw ComputerActionService.ComputerActionError.invalidRequest(
410418
"foreground click target is outside the selected window")
411419
}
412420
try Self.postForegroundClick(
@@ -549,7 +557,7 @@ final class ComputerActionServiceV2 {
549557
guard let path = params.path, !path.isEmpty, path.count <= 16,
550558
path.allSatisfy({ !$0.isEmpty && $0.count <= 200 })
551559
else {
552-
throw ComputerActionService.ComputerActionError.invalidV2Request(
560+
throw ComputerActionService.ComputerActionError.invalidRequest(
553561
"path must contain 1 to 16 non-empty menu components")
554562
}
555563
try await self.withExecutionAuthority {
@@ -567,7 +575,7 @@ final class ComputerActionServiceV2 {
567575
let windowRef = try Self.require(params.windowRef, field: "windowRef")
568576
let target = try self.resolveWindow(windowRef)
569577
guard let direction = params.scrollDirection else {
570-
throw ComputerActionService.ComputerActionError.invalidV2Request(
578+
throw ComputerActionService.ComputerActionError.invalidRequest(
571579
"scrollDirection is required for scroll")
572580
}
573581
let mode = params.deliveryMode ?? .background
@@ -691,11 +699,11 @@ final class ComputerActionServiceV2 {
691699
return (.elementId(element.id), element.bounds.centerPoint, observation.snapshotId)
692700
}
693701
guard let x = params.x, let y = params.y else {
694-
throw ComputerActionService.ComputerActionError.invalidV2Request(
702+
throw ComputerActionService.ComputerActionError.invalidRequest(
695703
"coordinates or elementRef are required for \(params.action.rawValue)")
696704
}
697705
guard x >= 0, y >= 0 else {
698-
throw ComputerActionService.ComputerActionError.invalidV2Request(
706+
throw ComputerActionService.ComputerActionError.invalidRequest(
699707
"coordinates must be nonnegative")
700708
}
701709
let point = CGPoint(x: x, y: y)
@@ -711,11 +719,11 @@ final class ComputerActionServiceV2 {
711719
}
712720
if params.x == nil, params.y == nil { return nil }
713721
guard let x = params.x, let y = params.y else {
714-
throw ComputerActionService.ComputerActionError.invalidV2Request(
722+
throw ComputerActionService.ComputerActionError.invalidRequest(
715723
"both x and y are required")
716724
}
717725
guard x >= 0, y >= 0 else {
718-
throw ComputerActionService.ComputerActionError.invalidV2Request(
726+
throw ComputerActionService.ComputerActionError.invalidRequest(
719727
"coordinates must be nonnegative")
720728
}
721729
_ = try self.resolveObservation(params.observationId, windowRef: windowRef)
@@ -763,7 +771,7 @@ final class ComputerActionServiceV2 {
763771

764772
// MARK: - Projection and outcomes
765773

766-
extension ComputerActionServiceV2 {
774+
extension ComputerWindowActionExecutor {
767775
private static func result(
768776
from outcome: DesktopActionOutcome?,
769777
background: Bool) -> OpenClawComputerActResult
@@ -888,7 +896,7 @@ extension ComputerActionServiceV2 {
888896
let depth = params.depth ?? AXTraversalBudget.defaultMaxDepth
889897
let maxElements = params.maxElements ?? AXTraversalBudget.defaultMaxElementCount
890898
guard (0...64).contains(depth), (1...2000).contains(maxElements) else {
891-
throw ComputerActionService.ComputerActionError.invalidV2Request(
899+
throw ComputerActionService.ComputerActionError.invalidRequest(
892900
"depth must be 0...64 and maxElements must be 1...2000")
893901
}
894902
return (depth, maxElements)
@@ -900,7 +908,7 @@ extension ComputerActionServiceV2 {
900908
allowEmpty: Bool = false) throws -> String
901909
{
902910
guard let value, allowEmpty || !value.isEmpty else {
903-
throw ComputerActionService.ComputerActionError.invalidV2Request(
911+
throw ComputerActionService.ComputerActionError.invalidRequest(
904912
"\(field) is required")
905913
}
906914
return value
@@ -985,7 +993,7 @@ extension ComputerActionServiceV2 {
985993
case "alt", "option": flags.insert(.maskAlternate)
986994
case "fn", "function": flags.insert(.maskSecondaryFn)
987995
default:
988-
throw ComputerActionService.ComputerActionError.invalidV2Request(
996+
throw ComputerActionService.ComputerActionError.invalidRequest(
989997
"unsupported modifier '\(token)'")
990998
}
991999
}

‎apps/macos/Sources/OpenClaw/NodeMode/MacNodeRuntime.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ extension MacNodeRuntime {
632632
case .noDisplays, .invalidScreenIndex, .missingDisplayFrameId, .displayFrameChanged,
633633
.missingCoordinate, .coordinateOutOfBounds, .invalidReferenceWidth, .missingKeys,
634634
.emptyText, .invalidScroll, .invalidModifier, .buttonAlreadyHeld, .buttonNotHeld,
635-
.invalidV2Request, .staleObservation, .unsupportedAction:
635+
.invalidRequest, .staleObservation, .unsupportedAction:
636636
return Self.errorResponse(
637637
req,
638638
code: .invalidRequest,

0 commit comments

Comments
 (0)