👾 Open Computer Use – Open-Source Alternative to Codex Computer Use
Swift accessibilityai-agentai-agentsclaude-codecodexcodex-computer-usecomputer-usecomputer-use-agentcross-platformcuadesktop-automationgemini-cligui-automationmacosmcpmodel-context-protocolopen-computer-useopen-computer-use-mcpopenai-codexopencode
Align visual cursor overlay with shared procedural glyph
Leod8f38095882d
diff --git a/Package.swift b/Package.swiftindex 32ecdf1..49e3bbc 100644--- a/Package.swift+++ b/Package.swift@@ -55,6 +55,7 @@ let package = Package(),.executableTarget(name: "CursorMotion",+ dependencies: ["OpenComputerUseKit"],path: "experiments/CursorMotion/Sources/CursorMotion"),.target(diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex 9ee2476..2497d20 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -57,8 +57,8 @@- MCP `tools/list` 的 description / input schema 当前按官方 `computer-use` 的 9 个 tools 文案和参数面收敛,尽量减少 host 侧提示词和 tool surface 偏差。- 对真实 app 的 `get_app_state` / action tool 入口,当前新增了一层官方风格的高风险 bundle denylist:bundle-id 直传时直接返回 safety denial;名称匹配时默认不解析到这些 app,尽量贴近官方对终端、密码管理器、Chrome 与少量系统敏感组件的防护行为。- 普通 app 的 element frame 当前按“窗口左上角为原点”的 window-relative 坐标输出,便于后续把 `element_index` 和截图坐标统一到同一套参考系。-- `click` 在执行真实动作前后,会额外驱动一层透明 `SoftwareCursorOverlay` window:移动阶段现在走一条 heading-driven 的官方风格 motion 内核,显式把“当前 cursor 朝向”和“最终 resting pose”一起喂给选路器,优先生成需要时先掉头、再沿车头方向推进的 C 形/单侧大弧轨迹;真正显示出来的 cursor 不再直接等于 path sample,而是经过一层独立的 visual dynamics 状态,把 visible tip、velocity、angle 和 fog/offset 持续推进,再衔接 click pulse、idle sway 和自动淡出。-- overlay 的 visual style 优先在运行时从本机官方 `Codex Computer Use.app` 的 `Package_ComputerUse.bundle` / `Package_SlimCore.bundle` 读取 `SoftwareCursor` 资产并做一次本地处理;如果本机没有这份 bundle,则回退到仓库内的矢量样式。+- `click` / `set_value` 在执行真实动作前后,会额外驱动一层透明 `SoftwareCursorOverlay` window:两者的移动阶段现在共用一条 heading-driven 的官方风格 motion 内核,显式把“当前 cursor 朝向”和“最终 resting pose”一起喂给选路器,优先生成需要时先掉头、再沿车头方向推进的 C 形/单侧大弧轨迹;真正显示出来的 cursor 不再直接等于 path sample,而是经过一层独立的 visual dynamics 状态,把 visible tip、velocity、angle 和 fog/offset 持续推进。`click` 结尾会衔接 click pulse、idle sway 和自动淡出,`set_value` 则只做 settle / idle / hide,不给 pulse。+- overlay 的 visual style 不再自己从官方 app bundle 裁 `SoftwareCursor` 小图;runtime 现在直接复用 `CursorMotion` 同款的程序化 pointer/fog glyph 校准,命中点 anchor 固定在 `126x126` 画布里的同一组 tip-offset 上,避免实验室和主 MCP runtime 各自维护一套 cursor 轮廓。- overlay 的层级不再固定 `.floating`;现在会跟随 snapshot 命中的目标 window id / layer,把自己排到该目标 window 之上,而不是粗暴压到所有前台 app 最上层。- overlay 的曲线路径不再只按固定 Bezier 模板生成;当前主线采用 reverse-engineering 约束下的 heading-driven candidate 族,候选只保留 `direct` / `turn` / `brake` / `orbit` 这些能稳定产出单侧主弧的 family,并继续保留 target-window 命中策略作为同类候选间的 tie-break。原始 binary lift 恢复出来的 `20` 条路径和 score 仍然保留在独立的 `StandaloneCursor` viewer / Python 重建脚本里,用于对照分析,不再直接作为 runtime 默认 chooser。- overlay 的 progress 曲线也不再是固定 `easeInOut`;主线现在复用官方 `response=1.4`、`dampingFraction=0.9`、`dt=1/240` 的 spring/`VelocityVerlet` 形状,但 wall-clock duration 仍做本地校准,因为官方 transaction-level 时长映射还没有完全恢复。@@ -67,6 +67,7 @@- 动作型 tools 对普通 app 采用“非侵入优先,HID 兜底”策略:- `AXUIElementPerformAction`- `AXUIElementSetAttributeValue`+ - element-targeted `click` 的左键路径会先试 `AXPress`,再试窗口/根元素常见的 `AXRaise`、`kAXMainAttribute`、`kAXFocusedAttribute`;这里不再把 `AXUIElementIsAttributeSettable` 的结果当成硬门槛,因为像 `TextEdit` window 这类元素在 `kAXFocusedAttribute` 上会出现“`isSettable=false` 但直接 set 成功”的官方同款场景- `AXUIElementCopyElementAtPosition` 做坐标命中,尽量把 coordinate click 反解成可操作 AX 元素- `CGEvent.postToPid` 定向发送键盘事件,避免为了 `type_text` / `press_key` 抢前台- 当必须退回全局鼠标路径时,先尝试对目标窗口做 `AXRaise` / main-window 聚焦,只有这些 AX 提升失败后才调用 `NSRunningApplication.activate`diff --git a/docs/histories/2026-04/20260420-2033-integrate-set-value-visual-cursor.md b/docs/histories/2026-04/20260420-2033-integrate-set-value-visual-cursor.mdnew file mode 100644index 0000000..0929c8e--- /dev/null+++ b/docs/histories/2026-04/20260420-2033-integrate-set-value-visual-cursor.md@@ -0,0 +1,59 @@+## [2026-04-20 20:33] | Task: 集成 `set_value` visual cursor 移动链路++### 🤖 Execution Context+* **Agent ID**: `primary`+* **Base Model**: `gpt-5.4`+* **Runtime**: `Codex CLI on macOS + SwiftPM + Go`++### 📥 User Query+> 现在我们 Cursor Motion 已经具备了计算曲线的能力,要集成到 `open-computer-use` 里;范围先收窄到 `click` 和 `set_value`,并希望补一条可直接通过 MCP 触发的 `TextEdit` 对比序列,方便和官方 bundled `computer-use` 平行观察效果。++### 🛠 Changes Overview+**Scope:** `packages/OpenComputerUseKit/`、`packages/OpenComputerUseKit/Tests/`、`scripts/computer-use-cli/`、`docs/`++**Key Actions:**+- **[`set_value` 接入 visual cursor]**: 在 `ComputerUseService` 里新增 `VisualCursorTarget` 与目标点解析 helper,让真实 app 模式下的 `set_value` 在执行 `AXUIElementSetAttributeValue` 前先跑 `SoftwareCursorOverlay.moveCursor(...)`,成功和失败都统一走 `settle` 收尾。+- **[统一 click/set_value 内部目标解析]**: `click` 复用同一套 visual cursor target 表达,避免继续把 overlay point / window 组装逻辑散落在分支里,同时保持 `type_text`、`press_key`、`scroll`、`drag` 的现有行为不变。+- **[补测试与可复现样例]**: 新增 `makeVisualCursorTarget(...)` 单测;补 `scripts/computer-use-cli/examples/textedit-set-value-click-raise-seq.json`,并在 README 里写明如何把同一份 calls file 同时指向官方 app-server 和本地 `OpenComputerUse` direct MCP。+- **[同步架构文档]**: `docs/ARCHITECTURE.md` 更新为“`click` / `set_value` 都会驱动 visual cursor move”,并明确两者的收尾差异是 `click pulse` vs `settle only`。++### 🧠 Design Intent (Why)+这次不追求把所有动作型 tools 都挂上 overlay,而是先收敛到用户已经确认最需要对比的两条路径:`click` 和 `set_value`。`click` 已有官方风格的 motion / pulse 链路,`set_value` 缺的是“先把视觉 cursor 移到目标区域,再做值写入”的最小补齐。把目标点与 target window 封成可复用 helper 后,既能让 `set_value` 复用当前主线已经验证过的 cursor motion 参数,也能避免未来继续复制同类 glue code。++### 📁 Files Modified+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `scripts/computer-use-cli/examples/textedit-set-value-click-raise-seq.json`+- `scripts/computer-use-cli/README.md`+- `docs/ARCHITECTURE.md`+- `docs/histories/2026-04/20260420-2033-integrate-set-value-visual-cursor.md`++### 🔁 Follow-up (2026-04-20, fix non-intrusive `click 0` for window/root elements)++- **[官方行为复查]**: 重新对官方 bundled `computer-use` 跑 `TextEdit` 的 `click element_index=0` 样本,并配合 `SkyComputerUseService` unified log 过滤,确认官方日志链路是 `Prepare to interact with element 0` -> `Finished preparing interaction with element 0` -> `Dispatch click to element 0`;没有出现本仓库先前那种必须退回全局 pointer 才能完成的迹象。+- **[修正本地 click 决策]**: `ComputerUseService.performPreferredClick` 不再只会试 `AXPress` / `kAXFocusedAttribute` / `AXConfirm`;现在会把窗口/根元素常见的 `AXRaise`、`kAXMainAttribute`、`kAXFocusedAttribute` 都纳入 element-targeted 左键路径,只有这些都失败才允许 `clickGlobally(...)`。+- **[移除过严 settable 门槛]**: 针对 `TextEdit` window 这类 `AXUIElementIsAttributeSettable(kAXFocusedAttribute) == false`、但直接 `AXUIElementSetAttributeValue(..., true)` 仍成功的场景,`click` 相关的布尔属性写入不再把 `isSettable` 当作硬前置条件。+- **[补 fallback tracing]**: 新增默认关闭的 `OPEN_COMPUTER_USE_DEBUG_INPUT_FALLBACKS` 环境变量;打开后,只有真的命中全局 pointer fallback 才会往 stderr 打一行调试信息,便于继续做官方/本地 A/B。+- **[验证结果]**: 打开 `OPEN_COMPUTER_USE_DEBUG_INPUT_FALLBACKS=1` 后,当前 `scripts/computer-use-cli/examples/textedit-overlay-seq.json` 这条本地 direct MCP 序列已不再打印 `global pointer fallback`,同时 `swift test` 全绿。++**Follow-up Files:**+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `docs/ARCHITECTURE.md`+- `docs/histories/2026-04/20260420-2033-integrate-set-value-visual-cursor.md`++### 🔁 Follow-up (2026-04-20, align runtime cursor glyph with `CursorMotion`)++- **[移除 bundle 小图裁剪链]**: `SoftwareCursorOverlay` 不再扫描官方 `Codex Computer Use.app` bundle 里的 `SoftwareCursor` 资源再本地裁剪;这条路径和当前仓库对官方 overlay 的逆向结论不一致,也会让主 runtime 和 `CursorMotion` 各自维持不同的 glyph 形状。+- **[抽共享程序化 glyph renderer]**: 在 `OpenComputerUseKit` 里新增共享 `SoftwareCursorGlyphRenderer`,把 `CursorMotion` 当前那套灰色 pointer + 白边 + fog 的程序化绘制逻辑、`126x126` 画布尺寸和 tip-anchor 标定收敛成同一份实现。+- **[主 runtime 切到同款 cursor]**: `SoftwareCursorView` 现在直接调用共享 renderer,`click` / `set_value` 的 visual cursor 都会使用和 `CursorMotion` 同款的程序化 glyph,而不是旧的渐变三角指针或 bundle 裁出来的小图。+- **[补共享校准测试]**: 新增一条单测,固定 `126x126` 画布和 `60.35 x 70.3` 的 tip-anchor 标定,避免后续再次把主 runtime 的命中点校准漂走。++**Follow-up Files:**+- `Package.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorGlyphRenderer.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift`+- `experiments/CursorMotion/Sources/CursorMotion/SynthesizedCursorGlyphView.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `docs/ARCHITECTURE.md`+- `docs/histories/2026-04/20260420-2033-integrate-set-value-visual-cursor.md`diff --git a/experiments/CursorMotion/Sources/CursorMotion/SynthesizedCursorGlyphView.swift b/experiments/CursorMotion/Sources/CursorMotion/SynthesizedCursorGlyphView.swiftindex f2f85a1..ea712e5 100644--- a/experiments/CursorMotion/Sources/CursorMotion/SynthesizedCursorGlyphView.swift+++ b/experiments/CursorMotion/Sources/CursorMotion/SynthesizedCursorGlyphView.swift@@ -1,11 +1,7 @@import AppKitimport CoreGraphicsimport Foundation--private enum SynthesizedCursorColors {- static let pointerFill = NSColor(calibratedRed: 0.38, green: 0.36, blue: 0.35, alpha: 0.98)- static let pointerStroke = NSColor(calibratedWhite: 0.90, alpha: 0.92)-}+import OpenComputerUseKit@MainActorfinal class SynthesizedCursorGlyphView: NSView {@@ -89,141 +85,18 @@ final class SynthesizedCursorGlyphView: NSView {}private func drawProceduralGlyph(in context: CGContext) {- let pulse = clickProgress- let drawingFogOffset = drawingVector(from: fogOffset)- let drawingBodyOffset = drawingVector(from: cursorBodyOffset)- let fogCenter = CGPoint(- x: bounds.midX + drawingFogOffset.dx,- y: bounds.midY + drawingFogOffset.dy- )- let pointerCenter = CGPoint(- x: bounds.midX + 2.6 + drawingBodyOffset.dx,- y: bounds.midY - 3.2 + drawingBodyOffset.dy + (pulse * 0.35)- )-- drawFog(in: context, center: fogCenter, pulse: pulse)- drawPointer(in: context, center: pointerCenter, pulse: pulse)- }-- private func drawFog(in context: CGContext, center: CGPoint, pulse: CGFloat) {- let radius = ((66 * fogScale) / 2) + (pulse * 1.2)- let glowRadius = radius * (0.30 + (pulse * 0.025))- let opacityMultiplier = max(0.28, min(fogOpacity / 0.12, 2.2))- let colors = [- NSColor(calibratedRed: 0.38, green: 0.36, blue: 0.35, alpha: (0.40 + (pulse * 0.02)) * opacityMultiplier).cgColor,- NSColor(calibratedRed: 0.43, green: 0.41, blue: 0.40, alpha: (0.28 + (pulse * 0.015)) * opacityMultiplier).cgColor,- NSColor(calibratedRed: 0.46, green: 0.44, blue: 0.43, alpha: 0.11 * opacityMultiplier).cgColor,- NSColor(calibratedWhite: 0.60, alpha: 0.0).cgColor,- ] as CFArray- let locations: [CGFloat] = [0, 0.50, 0.82, 1]- let colorSpace = CGColorSpaceCreateDeviceRGB()-- guard let gradient = CGGradient(colorsSpace: colorSpace, colors: colors, locations: locations) else {- return- }-- context.saveGState()- context.drawRadialGradient(- gradient,- startCenter: center,- startRadius: 0,- endCenter: center,- endRadius: radius,- options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]- )- context.restoreGState()-- let coreColors = [- NSColor(calibratedRed: 0.41, green: 0.39, blue: 0.38, alpha: (0.020 + (pulse * 0.006)) * opacityMultiplier).cgColor,- NSColor(calibratedRed: 0.44, green: 0.41, blue: 0.40, alpha: 0.008 * opacityMultiplier).cgColor,- NSColor(calibratedWhite: 0.80, alpha: 0.0).cgColor,- ] as CFArray- let coreLocations: [CGFloat] = [0, 0.62, 1]- guard let coreGradient = CGGradient(colorsSpace: colorSpace, colors: coreColors, locations: coreLocations) else {- return- }-- context.saveGState()- context.drawRadialGradient(- coreGradient,- startCenter: center,- startRadius: 0,- endCenter: center,- endRadius: glowRadius,- options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]- )- context.restoreGState()- }-- private func drawPointer(in context: CGContext, center: CGPoint, pulse: CGFloat) {- let pointerRect = CGRect(- x: center.x - 10.5,- y: center.y - 10.5,- width: 21,- height: 21- )- let outerPath = pointerPath(in: pointerRect)-- context.saveGState()- let drawingBodyOffset = drawingVector(from: cursorBodyOffset)- context.translateBy(x: bounds.midX + drawingBodyOffset.dx, y: bounds.midY + drawingBodyOffset.dy)- context.rotate(by: drawingAngle(from: rotation - CursorGlyphCalibration.restingRotation))- context.scaleBy(x: 1 - (pulse * 0.04), y: 1 + (pulse * 0.02))- context.translateBy(x: -(bounds.midX + drawingBodyOffset.dx), y: -(bounds.midY + drawingBodyOffset.dy))-- NSGraphicsContext.saveGraphicsState()- let shadow = NSShadow()- shadow.shadowBlurRadius = 3.2 + (pulse * 1.4)- shadow.shadowOffset = CGSize(width: 0, height: -0.35)- shadow.shadowColor = NSColor.black.withAlphaComponent(0.11)- shadow.set()- NSColor.black.withAlphaComponent(0.05).setFill()- outerPath.fill()- NSGraphicsContext.restoreGraphicsState()-- SynthesizedCursorColors.pointerFill.setFill()- outerPath.fill()-- SynthesizedCursorColors.pointerStroke.setStroke()- outerPath.lineWidth = 1.55- outerPath.lineJoinStyle = .round- outerPath.lineCapStyle = .round- outerPath.stroke()-- context.restoreGState()- }-- private func pointerPath(in rect: CGRect) -> NSBezierPath {- let contourRows: [(y: CGFloat, minX: CGFloat, maxX: CGFloat)] = [- (39, 17, 21), (38, 16, 22), (37, 15, 22), (36, 15, 23), (35, 15, 24),- (34, 15, 24), (33, 14, 25), (32, 14, 25), (31, 14, 26), (30, 14, 27),- (29, 13, 29), (28, 13, 31), (27, 13, 34), (26, 13, 36), (25, 13, 37),- (24, 12, 37), (23, 12, 37), (22, 12, 37), (21, 12, 37), (20, 12, 36),- (19, 11, 36), (18, 11, 34), (17, 11, 32), (16, 11, 30), (15, 10, 27),- (14, 10, 25), (13, 10, 23), (12, 11, 21), (11, 11, 19), (10, 13, 16),- ]- let sourceMinX: CGFloat = 10- let sourceMaxX: CGFloat = 38- let sourceMinY: CGFloat = 10- let sourceMaxY: CGFloat = 39-- func mappedPoint(x: CGFloat, y: CGFloat) -> CGPoint {- CGPoint(- x: rect.minX + ((x - sourceMinX) / (sourceMaxX - sourceMinX) * rect.width),- y: rect.minY + ((y - sourceMinY) / (sourceMaxY - sourceMinY) * rect.height)+ SoftwareCursorGlyphRenderer.draw(+ in: bounds,+ context: context,+ state: SoftwareCursorGlyphRenderState(+ rotation: drawingAngle(from: rotation - CursorGlyphCalibration.restingRotation),+ cursorBodyOffset: drawingVector(from: cursorBodyOffset),+ fogOffset: drawingVector(from: fogOffset),+ fogOpacity: fogOpacity,+ fogScale: fogScale,+ clickProgress: clickProgress)- }-- let leftBoundary = contourRows.map { mappedPoint(x: $0.minX, y: $0.y) }- let rightBoundary = contourRows.reversed().map { mappedPoint(x: $0.maxX, y: $0.y) }-- let path = NSBezierPath()- path.move(to: leftBoundary[0])- leftBoundary.dropFirst().forEach { path.line(to: $0) }- rightBoundary.forEach { path.line(to: $0) }- path.close()- path.lineJoinStyle = .round- return path+ )}private func drawingVector(from screenVector: CGVector) -> CGVector {diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swiftindex 2bc2dc0..6c6cbcb 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift@@ -2,6 +2,54 @@ import AppKitimport ApplicationServicesimport Foundation+struct VisualCursorTarget: Equatable {+ let point: CGPoint+ let window: CursorTargetWindow?+}++func makeVisualCursorTarget(+ at point: CGPoint,+ targetWindowID: CGWindowID?,+ targetWindowLayer: Int?+) -> VisualCursorTarget {+ VisualCursorTarget(+ point: point,+ window: targetWindowID.map { CursorTargetWindow(windowID: $0, layer: targetWindowLayer ?? 0) }+ )+}++func makeVisualCursorTarget(+ localFrame: CGRect?,+ windowBounds: CGRect?,+ targetWindowID: CGWindowID?,+ targetWindowLayer: Int?+) -> VisualCursorTarget? {+ guard let localFrame, let windowBounds else {+ return nil+ }++ let point = CGPoint(+ x: windowBounds.minX + localFrame.midX,+ y: windowBounds.minY + localFrame.midY+ )+ return makeVisualCursorTarget(+ at: point,+ targetWindowID: targetWindowID,+ targetWindowLayer: targetWindowLayer+ )+}++func inputFallbackDebugEnabled(environment: [String: String]) -> Bool {+ guard let rawValue = environment["OPEN_COMPUTER_USE_DEBUG_INPUT_FALLBACKS"]?+ .trimmingCharacters(in: .whitespacesAndNewlines)+ .lowercased()+ else {+ return false+ }++ return ["1", "true", "yes", "on"].contains(rawValue)+}+public final class ComputerUseService {private var snapshotsByApp: [String: AppSnapshot] = [:]@@ -45,56 +93,62 @@ public final class ComputerUseService {guard let targetPoint = try globalPoint(for: record, snapshot: snapshot) else {throw ComputerUseError.stateUnavailable("element \(elementIndex) has no clickable frame")}- let targetWindow = cursorTargetWindow(for: snapshot)+ let cursorTarget = makeVisualCursorTarget(+ at: targetPoint,+ targetWindowID: snapshot.targetWindowID,+ targetWindowLayer: snapshot.targetWindowLayer+ )- VisualCursorSupport.performOnMain {- SoftwareCursorOverlay.moveCursor(to: targetPoint, in: targetWindow)- }+ moveVisualCursor(to: cursorTarget)do {if try performPreferredClick(on: record, button: button, clickCount: clickCount) {Thread.sleep(forTimeInterval: 0.15)} else {+ debugInputFallback(+ tool: "click",+ targetDescription: "element_index=\(elementIndex)",+ snapshot: snapshot+ )InputSimulation.prepareAppForGlobalPointerInput(snapshot.app)try InputSimulation.clickGlobally(at: targetPoint, button: button, clickCount: clickCount)}} catch {- VisualCursorSupport.performOnMain {- SoftwareCursorOverlay.settle(at: targetPoint, in: targetWindow)- }+ settleVisualCursor(at: cursorTarget)throw error}- VisualCursorSupport.performOnMain {- SoftwareCursorOverlay.pulseClick(at: targetPoint, clickCount: clickCount, mouseButton: button, in: targetWindow)- }+ pulseVisualCursor(at: cursorTarget, clickCount: clickCount, mouseButton: button)} else if let x, let y {let point = CGPoint(x: x, y: y)let targetPoint = try screenshotToGlobalPoint(snapshot: snapshot, x: x, y: y)- let targetWindow = cursorTargetWindow(for: snapshot)+ let cursorTarget = makeVisualCursorTarget(+ at: targetPoint,+ targetWindowID: snapshot.targetWindowID,+ targetWindowLayer: snapshot.targetWindowLayer+ )- VisualCursorSupport.performOnMain {- SoftwareCursorOverlay.moveCursor(to: targetPoint, in: targetWindow)- }+ moveVisualCursor(to: cursorTarget)do {if let record = try hitTestElement(at: point, in: snapshot) ?? bestElement(containing: point, in: snapshot),try performPreferredClick(on: record, button: button, clickCount: clickCount) {Thread.sleep(forTimeInterval: 0.15)} else {+ debugInputFallback(+ tool: "click",+ targetDescription: "x=\(Int(point.x)) y=\(Int(point.y))",+ snapshot: snapshot+ )InputSimulation.prepareAppForGlobalPointerInput(snapshot.app)try InputSimulation.clickGlobally(at: targetPoint, button: button, clickCount: clickCount)}} catch {- VisualCursorSupport.performOnMain {- SoftwareCursorOverlay.settle(at: targetPoint, in: targetWindow)- }+ settleVisualCursor(at: cursorTarget)throw error}- VisualCursorSupport.performOnMain {- SoftwareCursorOverlay.pulseClick(at: targetPoint, clickCount: clickCount, mouseButton: button, in: targetWindow)- }+ pulseVisualCursor(at: cursorTarget, clickCount: clickCount, mouseButton: button)} else {throw ComputerUseError.invalidArguments("click requires either element_index or x/y")}@@ -223,12 +277,22 @@ public final class ComputerUseService {throw ComputerUseError.stateUnavailable("element \(elementIndex) has no backing accessibility object")}- let result = AXUIElementSetAttributeValue(element, kAXValueAttribute as CFString, value as CFString)- guard result == .success else {- throw ComputerUseError.message("AXUIElementSetAttributeValue failed with \(result.rawValue)")+ let cursorTarget = visualCursorTarget(for: record, snapshot: snapshot)+ moveVisualCursor(to: cursorTarget)++ do {+ let result = AXUIElementSetAttributeValue(element, kAXValueAttribute as CFString, value as CFString)+ guard result == .success else {+ throw ComputerUseError.message("AXUIElementSetAttributeValue failed with \(result.rawValue)")+ }++ Thread.sleep(forTimeInterval: 0.1)+ } catch {+ settleVisualCursor(at: cursorTarget)+ throw error}- Thread.sleep(forTimeInterval: 0.1)+ settleVisualCursor(at: cursorTarget)return snapshotResult(for: try refreshSnapshot(for: query), style: .actionResult)}@@ -289,7 +353,7 @@ public final class ComputerUseService {return true}- if try focus(element: element) {+ if try activateClickTarget(element: element, availableActions: record.rawActions) {return true}@@ -323,19 +387,33 @@ public final class ComputerUseService {}}- private func focus(element: AXUIElement) throws -> Bool {- guard isSettable(element: element, attribute: kAXFocusedAttribute) else {- return false+ private func activateClickTarget(element: AXUIElement, availableActions: [String]) throws -> Bool {+ var activated = false++ if try performAction(named: kAXRaiseAction as String, on: element, availableActions: availableActions) {+ activated = true}- let result = AXUIElementSetAttributeValue(element, kAXFocusedAttribute as CFString, kCFBooleanTrue)+ if try setBoolAttribute(named: kAXMainAttribute, on: element) {+ activated = true+ }++ if try setBoolAttribute(named: kAXFocusedAttribute, on: element) {+ activated = true+ }++ return activated+ }++ private func setBoolAttribute(named attribute: String, on element: AXUIElement) throws -> Bool {+ let result = AXUIElementSetAttributeValue(element, attribute as CFString, kCFBooleanTrue)switch result {case .success:return true- case .attributeUnsupported, .cannotComplete, .noValue:+ case .attributeUnsupported, .actionUnsupported, .cannotComplete, .noValue:return falsedefault:- throw ComputerUseError.message("AXUIElementSetAttributeValue(\(kAXFocusedAttribute)) failed with \(result.rawValue)")+ throw ComputerUseError.message("AXUIElementSetAttributeValue(\(attribute)) failed with \(result.rawValue)")}}@@ -384,12 +462,15 @@ public final class ComputerUseService {if record.rawActions.contains(where: {$0.caseInsensitiveCompare(kAXPressAction as String) == .orderedSame ||$0.caseInsensitiveCompare(kAXConfirmAction as String) == .orderedSame ||- $0.caseInsensitiveCompare(kAXShowMenuAction as String) == .orderedSame+ $0.caseInsensitiveCompare(kAXShowMenuAction as String) == .orderedSame ||+ $0.caseInsensitiveCompare(kAXRaiseAction as String) == .orderedSame}) {return 0}- if let element = record.element, isSettable(element: element, attribute: kAXFocusedAttribute) {+ if let element = record.element,+ isSettable(element: element, attribute: kAXMainAttribute) ||+ isSettable(element: element, attribute: kAXFocusedAttribute) {return 1}@@ -478,14 +559,59 @@ public final class ComputerUseService {return identifier}- private func cursorTargetWindow(for snapshot: AppSnapshot) -> CursorTargetWindow? {- guard let windowID = snapshot.targetWindowID else {- return nil+ private func visualCursorTarget(for record: ElementRecord, snapshot: AppSnapshot) -> VisualCursorTarget? {+ makeVisualCursorTarget(+ localFrame: record.localFrame,+ windowBounds: snapshot.windowBounds,+ targetWindowID: snapshot.targetWindowID,+ targetWindowLayer: snapshot.targetWindowLayer+ )+ }++ private func moveVisualCursor(to target: VisualCursorTarget?) {+ guard let target else {+ return+ }++ VisualCursorSupport.performOnMain {+ SoftwareCursorOverlay.moveCursor(to: target.point, in: target.window)+ }+ }++ private func settleVisualCursor(at target: VisualCursorTarget?) {+ guard let target else {+ return+ }++ VisualCursorSupport.performOnMain {+ SoftwareCursorOverlay.settle(at: target.point, in: target.window)+ }+ }++ private func pulseVisualCursor(at target: VisualCursorTarget?, clickCount: Int, mouseButton: MouseButtonKind) {+ guard let target else {+ return+ }++ VisualCursorSupport.performOnMain {+ SoftwareCursorOverlay.pulseClick(+ at: target.point,+ clickCount: clickCount,+ mouseButton: mouseButton,+ in: target.window+ )+ }+ }++ private func debugInputFallback(tool: String, targetDescription: String, snapshot: AppSnapshot) {+ guard inputFallbackDebugEnabled(environment: ProcessInfo.processInfo.environment) else {+ return}- return CursorTargetWindow(- windowID: windowID,- layer: snapshot.targetWindowLayer ?? 0+ let appReference = snapshot.app.bundleIdentifier ?? snapshot.app.name+ fputs(+ "[open-computer-use] global pointer fallback tool=\(tool) app=\(appReference) target=\(targetDescription)\n",+ stderr)}diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorGlyphRenderer.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorGlyphRenderer.swiftnew file mode 100644index 0000000..370ac30--- /dev/null+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorGlyphRenderer.swift@@ -0,0 +1,214 @@+import AppKit+import CoreGraphics+import Foundation++package struct SoftwareCursorGlyphRenderState {+ package let rotation: CGFloat+ package let cursorBodyOffset: CGVector+ package let fogOffset: CGVector+ package let fogOpacity: CGFloat+ package let fogScale: CGFloat+ package let clickProgress: CGFloat++ package init(+ rotation: CGFloat,+ cursorBodyOffset: CGVector,+ fogOffset: CGVector,+ fogOpacity: CGFloat,+ fogScale: CGFloat,+ clickProgress: CGFloat+ ) {+ self.rotation = rotation+ self.cursorBodyOffset = cursorBodyOffset+ self.fogOffset = fogOffset+ self.fogOpacity = fogOpacity+ self.fogScale = fogScale+ self.clickProgress = clickProgress+ }+}++package enum SoftwareCursorGlyphMetrics {+ package static let windowSize = CGSize(width: 126, height: 126)+ package static let tipAnchor = CGPoint(x: 60.35, y: 70.3)++ static let pointerSize = CGSize(width: 21, height: 21)+ static let pointerOffset = CGPoint(x: 2.6, y: -3.2)+}++private enum SoftwareCursorGlyphColors {+ static let pointerFill = NSColor(calibratedRed: 0.38, green: 0.36, blue: 0.35, alpha: 0.98)+ static let pointerStroke = NSColor(calibratedWhite: 0.90, alpha: 0.92)+}++package enum SoftwareCursorGlyphRenderer {+ package static func draw(+ in bounds: CGRect,+ context: CGContext,+ state: SoftwareCursorGlyphRenderState+ ) {+ let pulse = state.clickProgress+ let fogCenter = CGPoint(+ x: bounds.midX + state.fogOffset.dx,+ y: bounds.midY + state.fogOffset.dy+ )+ let pointerCenter = CGPoint(+ x: bounds.midX + SoftwareCursorGlyphMetrics.pointerOffset.x + state.cursorBodyOffset.dx,+ y: bounds.midY + SoftwareCursorGlyphMetrics.pointerOffset.y + state.cursorBodyOffset.dy + (pulse * 0.35)+ )++ drawFog(+ in: context,+ center: fogCenter,+ pulse: pulse,+ fogOpacity: state.fogOpacity,+ fogScale: state.fogScale+ )+ drawPointer(+ in: context,+ center: pointerCenter,+ rotation: state.rotation,+ clickProgress: pulse,+ cursorBodyOffset: state.cursorBodyOffset,+ boundsMidpoint: CGPoint(x: bounds.midX, y: bounds.midY)+ )+ }++ private static func drawFog(+ in context: CGContext,+ center: CGPoint,+ pulse: CGFloat,+ fogOpacity: CGFloat,+ fogScale: CGFloat+ ) {+ let radius = ((66 * fogScale) / 2) + (pulse * 1.2)+ let glowRadius = radius * (0.30 + (pulse * 0.025))+ let opacityMultiplier = max(0.28, min(fogOpacity / 0.12, 2.2))+ let colors = [+ NSColor(calibratedRed: 0.38, green: 0.36, blue: 0.35, alpha: (0.40 + (pulse * 0.02)) * opacityMultiplier).cgColor,+ NSColor(calibratedRed: 0.43, green: 0.41, blue: 0.40, alpha: (0.28 + (pulse * 0.015)) * opacityMultiplier).cgColor,+ NSColor(calibratedRed: 0.46, green: 0.44, blue: 0.43, alpha: 0.11 * opacityMultiplier).cgColor,+ NSColor(calibratedWhite: 0.60, alpha: 0.0).cgColor,+ ] as CFArray+ let locations: [CGFloat] = [0, 0.50, 0.82, 1]+ let colorSpace = CGColorSpaceCreateDeviceRGB()++ guard let gradient = CGGradient(colorsSpace: colorSpace, colors: colors, locations: locations) else {+ return+ }++ context.saveGState()+ context.drawRadialGradient(+ gradient,+ startCenter: center,+ startRadius: 0,+ endCenter: center,+ endRadius: radius,+ options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]+ )+ context.restoreGState()++ let coreColors = [+ NSColor(calibratedRed: 0.41, green: 0.39, blue: 0.38, alpha: (0.020 + (pulse * 0.006)) * opacityMultiplier).cgColor,+ NSColor(calibratedRed: 0.44, green: 0.41, blue: 0.40, alpha: 0.008 * opacityMultiplier).cgColor,+ NSColor(calibratedWhite: 0.80, alpha: 0.0).cgColor,+ ] as CFArray+ let coreLocations: [CGFloat] = [0, 0.62, 1]+ guard let coreGradient = CGGradient(colorsSpace: colorSpace, colors: coreColors, locations: coreLocations) else {+ return+ }++ context.saveGState()+ context.drawRadialGradient(+ coreGradient,+ startCenter: center,+ startRadius: 0,+ endCenter: center,+ endRadius: glowRadius,+ options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]+ )+ context.restoreGState()+ }++ private static func drawPointer(+ in context: CGContext,+ center: CGPoint,+ rotation: CGFloat,+ clickProgress: CGFloat,+ cursorBodyOffset: CGVector,+ boundsMidpoint: CGPoint+ ) {+ let pointerRect = CGRect(+ x: center.x - (SoftwareCursorGlyphMetrics.pointerSize.width / 2),+ y: center.y - (SoftwareCursorGlyphMetrics.pointerSize.height / 2),+ width: SoftwareCursorGlyphMetrics.pointerSize.width,+ height: SoftwareCursorGlyphMetrics.pointerSize.height+ )+ let outerPath = pointerPath(in: pointerRect)++ context.saveGState()+ context.translateBy(+ x: boundsMidpoint.x + cursorBodyOffset.dx,+ y: boundsMidpoint.y + cursorBodyOffset.dy+ )+ context.rotate(by: rotation)+ context.scaleBy(x: 1 - (clickProgress * 0.04), y: 1 + (clickProgress * 0.02))+ context.translateBy(+ x: -(boundsMidpoint.x + cursorBodyOffset.dx),+ y: -(boundsMidpoint.y + cursorBodyOffset.dy)+ )++ NSGraphicsContext.saveGraphicsState()+ let shadow = NSShadow()+ shadow.shadowBlurRadius = 3.2 + (clickProgress * 1.4)+ shadow.shadowOffset = CGSize(width: 0, height: -0.35)+ shadow.shadowColor = NSColor.black.withAlphaComponent(0.11)+ shadow.set()+ NSColor.black.withAlphaComponent(0.05).setFill()+ outerPath.fill()+ NSGraphicsContext.restoreGraphicsState()++ SoftwareCursorGlyphColors.pointerFill.setFill()+ outerPath.fill()++ SoftwareCursorGlyphColors.pointerStroke.setStroke()+ outerPath.lineWidth = 1.55+ outerPath.lineJoinStyle = .round+ outerPath.lineCapStyle = .round+ outerPath.stroke()++ context.restoreGState()+ }++ private static func pointerPath(in rect: CGRect) -> NSBezierPath {+ let contourRows: [(y: CGFloat, minX: CGFloat, maxX: CGFloat)] = [+ (39, 17, 21), (38, 16, 22), (37, 15, 22), (36, 15, 23), (35, 15, 24),+ (34, 15, 24), (33, 14, 25), (32, 14, 25), (31, 14, 26), (30, 14, 27),+ (29, 13, 29), (28, 13, 31), (27, 13, 34), (26, 13, 36), (25, 13, 37),+ (24, 12, 37), (23, 12, 37), (22, 12, 37), (21, 12, 37), (20, 12, 36),+ (19, 11, 36), (18, 11, 34), (17, 11, 32), (16, 11, 30), (15, 10, 27),+ (14, 10, 25), (13, 10, 23), (12, 11, 21), (11, 11, 19), (10, 13, 16),+ ]+ let sourceMinX: CGFloat = 10+ let sourceMaxX: CGFloat = 38+ let sourceMinY: CGFloat = 10+ let sourceMaxY: CGFloat = 39++ func mappedPoint(x: CGFloat, y: CGFloat) -> CGPoint {+ CGPoint(+ x: rect.minX + ((x - sourceMinX) / (sourceMaxX - sourceMinX) * rect.width),+ y: rect.minY + ((y - sourceMinY) / (sourceMaxY - sourceMinY) * rect.height)+ )+ }++ let leftBoundary = contourRows.map { mappedPoint(x: $0.minX, y: $0.y) }+ let rightBoundary = contourRows.reversed().map { mappedPoint(x: $0.maxX, y: $0.y) }++ let path = NSBezierPath()+ path.move(to: leftBoundary[0])+ leftBoundary.dropFirst().forEach { path.line(to: $0) }+ rightBoundary.forEach { path.line(to: $0) }+ path.close()+ path.lineJoinStyle = .round+ return path+ }+}diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swiftindex ee896d4..ff36d99 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift@@ -56,209 +56,14 @@ struct CursorWindowGeometry {}}-private struct ProcessedCursorImage {- let image: NSImage- let tipAnchor: CGPoint-}-private struct CursorArtwork {- let image: NSImage?let geometry: CursorWindowGeometry- let drawRect: CGRect- let shadowBlur: CGFloat- let shadowOffset: CGSize- let shadowColor: NSColor- let vectorScale: CGFloat-- static let active: CursorArtwork = loadOfficialSoftwareCursor() ?? fallback-- private static let fallback = CursorArtwork(- image: nil,+ static let active = CursorArtwork(geometry: CursorWindowGeometry(- windowSize: CGSize(width: 56, height: 56),- tipAnchor: CGPoint(x: 10, y: 43)+ windowSize: SoftwareCursorGlyphMetrics.windowSize,+ tipAnchor: SoftwareCursorGlyphMetrics.tipAnchor),- drawRect: CGRect(x: 0, y: 0, width: 56, height: 56),- shadowBlur: 12,- shadowOffset: CGSize(width: 0, height: -2),- shadowColor: NSColor.black.withAlphaComponent(0.24),- vectorScale: 0.40)-- private static func loadOfficialSoftwareCursor() -> CursorArtwork? {- for bundle in officialCursorBundles() {- guard let image = bundle.image(forResource: NSImage.Name("SoftwareCursor")),- let processed = processOfficialCursor(image)- else {- continue- }-- let targetHeight: CGFloat = 26- let scale = targetHeight / processed.image.size.height- let imageSize = CGSize(- width: processed.image.size.width * scale,- height: processed.image.size.height * scale- )- let margin = NSEdgeInsets(top: 4, left: 3, bottom: 7, right: 5)- let tipAnchor = CGPoint(- x: margin.left + (processed.tipAnchor.x * scale),- y: margin.bottom + (processed.tipAnchor.y * scale)- )-- return CursorArtwork(- image: processed.image,- geometry: CursorWindowGeometry(- windowSize: CGSize(- width: imageSize.width + margin.left + margin.right,- height: imageSize.height + margin.top + margin.bottom- ),- tipAnchor: tipAnchor- ),- drawRect: CGRect(x: margin.left, y: margin.bottom, width: imageSize.width, height: imageSize.height),- shadowBlur: 17,- shadowOffset: CGSize(width: 0, height: -3),- shadowColor: NSColor.black.withAlphaComponent(0.26),- vectorScale: 0- )- }-- return nil- }-- private static func officialCursorBundles() -> [Bundle] {- let root = URL(fileURLWithPath: NSHomeDirectory())- .appendingPathComponent(".codex/plugins/cache/openai-bundled/computer-use", isDirectory: true)-- guard let versions = try? FileManager.default.contentsOfDirectory(- at: root,- includingPropertiesForKeys: [.isDirectoryKey],- options: [.skipsHiddenFiles]- ) else {- return []- }-- let sortedVersions = versions.sorted { $0.lastPathComponent.localizedStandardCompare($1.lastPathComponent) == .orderedDescending }-- let bundlePaths = sortedVersions.flatMap { versionURL in- [- versionURL.appendingPathComponent("Codex Computer Use.app/Contents/Resources/Package_ComputerUse.bundle", isDirectory: true),- versionURL.appendingPathComponent("Codex Computer Use.app/Contents/Resources/Package_SlimCore.bundle", isDirectory: true),- ]- }-- return bundlePaths.compactMap { Bundle(path: $0.path) }- }-- private static func processOfficialCursor(_ image: NSImage) -> ProcessedCursorImage? {- guard let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil) else {- return nil- }-- let bitmap = NSBitmapImageRep(cgImage: cgImage)- let width = bitmap.pixelsWide- let height = bitmap.pixelsHigh- guard width > 0, height > 0 else {- return nil- }-- let highlightThreshold: CGFloat = 0.83- let tint = NSColor(calibratedWhite: 0.92, alpha: 1).usingColorSpace(.deviceRGB) ?? NSColor.white- let tintRed = UInt8(tint.redComponent * 255)- let tintGreen = UInt8(tint.greenComponent * 255)- let tintBlue = UInt8(tint.blueComponent * 255)-- var minX = width- var maxX = 0- var minY = height- var maxY = 0- var tipPixel = CGPoint.zero- var tipScore = -CGFloat.greatestFiniteMagnitude-- for y in 0..<height {- for x in 0..<width {- guard let color = bitmap.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB) else {- continue- }-- let alpha = color.alphaComponent- let brightness = max(color.redComponent, color.greenComponent, color.blueComponent)- guard alpha > 0.08, brightness > highlightThreshold else {- continue- }-- minX = Swift.min(minX, x)- maxX = Swift.max(maxX, x)- minY = Swift.min(minY, y)- maxY = Swift.max(maxY, y)-- let score = (CGFloat(y) * 3) - CGFloat(x)- if score > tipScore {- tipScore = score- tipPixel = CGPoint(x: x, y: y)- }- }- }-- guard minX <= maxX, minY <= maxY else {- return nil- }-- let padding = 3- minX = Swift.max(0, minX - padding)- minY = Swift.max(0, minY - padding)- maxX = Swift.min(width - 1, maxX + padding)- maxY = Swift.min(height - 1, maxY + padding)-- let croppedWidth = maxX - minX + 1- let croppedHeight = maxY - minY + 1-- guard let output = NSBitmapImageRep(- bitmapDataPlanes: nil,- pixelsWide: croppedWidth,- pixelsHigh: croppedHeight,- bitsPerSample: 8,- samplesPerPixel: 4,- hasAlpha: true,- isPlanar: false,- colorSpaceName: .deviceRGB,- bytesPerRow: 0,- bitsPerPixel: 0- ), let bitmapData = output.bitmapData else {- return nil- }-- for y in minY...maxY {- for x in minX...maxX {- guard let color = bitmap.colorAt(x: x, y: y)?.usingColorSpace(.deviceRGB) else {- continue- }-- let alpha = color.alphaComponent- let brightness = max(color.redComponent, color.greenComponent, color.blueComponent)- let whiteness = CGFloat.clamped((brightness - highlightThreshold) / (1 - highlightThreshold), lower: 0, upper: 1)- let resultAlpha = UInt8((alpha * whiteness) * 255)-- let localX = x - minX- let localY = y - minY- let offset = (localY * output.bytesPerRow) + (localX * 4)- bitmapData[offset] = tintRed- bitmapData[offset + 1] = tintGreen- bitmapData[offset + 2] = tintBlue- bitmapData[offset + 3] = resultAlpha- }- }-- let processed = NSImage(size: CGSize(width: croppedWidth, height: croppedHeight))- processed.addRepresentation(output)-- return ProcessedCursorImage(- image: processed,- tipAnchor: CGPoint(- x: tipPixel.x - CGFloat(minX),- y: tipPixel.y - CGFloat(minY)- )- )- }}@MainActor@@ -371,7 +176,7 @@ enum SoftwareCursorOverlay {panel.collectionBehavior = [.canJoinAllSpaces, .fullScreenAuxiliary, .stationary, .ignoresCycle]panel.animationBehavior = .none- let view = SoftwareCursorView(frame: CGRect(origin: .zero, size: artwork.geometry.windowSize), artwork: artwork)+ let view = SoftwareCursorView(frame: CGRect(origin: .zero, size: artwork.geometry.windowSize))panel.contentView = viewself.panel = panel@@ -824,8 +629,6 @@ private final class CursorPanel: NSPanel {}private final class SoftwareCursorView: NSView {- private let artwork: CursorArtwork-var rotation: CGFloat = 0var cursorBodyOffset: CGVector = CGVector(dx: 0, dy: 0)var fogOffset: CGVector = CGVector(dx: 0, dy: 0)@@ -833,8 +636,7 @@ private final class SoftwareCursorView: NSView {var fogScale: CGFloat = 1var clickProgress: CGFloat = 0- init(frame frameRect: NSRect, artwork: CursorArtwork) {- self.artwork = artwork+ override init(frame frameRect: NSRect) {super.init(frame: frameRect)wantsLayer = true}@@ -854,113 +656,21 @@ private final class SoftwareCursorView: NSView {NSColor.clear.setFill()dirtyRect.fill()- let motionCompression = min(hypot(cursorBodyOffset.dx, cursorBodyOffset.dy) * 0.01, 0.02)- let compression = (clickProgress * 0.05) + motionCompression- let scaleX = 1 - compression- let scaleY = 1 + (compression * 0.24)-- let anchor = artwork.geometry.tipAnchor- let context = NSGraphicsContext.current?.cgContext- let fogRect = CGRect(- x: anchor.x - (12 * fogScale) + fogOffset.dx,- y: anchor.y - (51 * fogScale) + fogOffset.dy,- width: 24 * fogScale,- height: 8 * fogScale- )- let fogOval = NSBezierPath(ovalIn: fogRect)- NSGraphicsContext.saveGraphicsState()- let ovalShadow = NSShadow()- ovalShadow.shadowBlurRadius = (10 * fogScale) + (clickProgress * 2)- ovalShadow.shadowOffset = CGSize(width: 0, height: -1)- ovalShadow.shadowColor = NSColor.white.withAlphaComponent(fogOpacity * 0.55)- ovalShadow.set()- NSColor.white.withAlphaComponent(fogOpacity).setFill()- fogOval.fill()- NSGraphicsContext.restoreGraphicsState()-- context?.saveGState()- context?.translateBy(x: cursorBodyOffset.dx, y: cursorBodyOffset.dy)- context?.translateBy(x: anchor.x, y: anchor.y)- context?.rotate(by: rotation)- context?.scaleBy(x: scaleX, y: scaleY)- context?.translateBy(x: -anchor.x, y: -anchor.y)-- if let image = artwork.image {- NSGraphicsContext.saveGraphicsState()- let shadow = NSShadow()- shadow.shadowBlurRadius = artwork.shadowBlur + (clickProgress * 4)- shadow.shadowOffset = artwork.shadowOffset- shadow.shadowColor = artwork.shadowColor- shadow.set()- image.draw(in: artwork.drawRect, from: .zero, operation: .sourceOver, fraction: 1)- NSGraphicsContext.restoreGraphicsState()- } else {- let shadowPath = cursorPath(anchor: anchor, scale: artwork.vectorScale, xOffset: 2, yOffset: -2)- NSGraphicsContext.saveGraphicsState()- let shadow = NSShadow()- shadow.shadowBlurRadius = artwork.shadowBlur + (clickProgress * 5)- shadow.shadowOffset = artwork.shadowOffset- shadow.shadowColor = artwork.shadowColor- shadow.set()- NSColor.black.withAlphaComponent(0.22).setFill()- shadowPath.fill()- NSGraphicsContext.restoreGraphicsState()-- let path = cursorPath(anchor: anchor, scale: artwork.vectorScale, xOffset: 0, yOffset: 0)- let gradient = NSGradient(colors: [- NSColor(calibratedWhite: 0.97, alpha: 0.92),- NSColor(calibratedWhite: 0.84, alpha: 0.90),- ])!- gradient.draw(in: path, angle: -78)-- NSColor(calibratedWhite: 1, alpha: 0.85).setStroke()- path.lineWidth = 1.0- path.lineJoinStyle = .round- path.lineCapStyle = .round- path.stroke()- }-- context?.restoreGState()-- if clickProgress > 0.01 {- let ringRadius = 4 + (clickProgress * 7)- let ringRect = CGRect(- x: anchor.x - ringRadius,- y: anchor.y - ringRadius,- width: ringRadius * 2,- height: ringRadius * 2- )- let ring = NSBezierPath(ovalIn: ringRect)- NSColor.white.withAlphaComponent(0.22 * (1 - clickProgress * 0.45)).setStroke()- ring.lineWidth = 1.0- ring.stroke()+ guard let context = NSGraphicsContext.current?.cgContext else {+ return}- }- private func cursorPath(anchor: CGPoint, scale: CGFloat, xOffset: CGFloat, yOffset: CGFloat) -> NSBezierPath {- let points: [CGPoint] = [- CGPoint(x: 0, y: 0),- CGPoint(x: 0, y: -79 * scale),- CGPoint(x: 20 * scale, y: -60 * scale),- CGPoint(x: 32 * scale, y: -91 * scale),- CGPoint(x: 47 * scale, y: -84 * scale),- CGPoint(x: 35 * scale, y: -55 * scale),- CGPoint(x: 63 * scale, y: -50 * scale),- ]-- let translated = points.map {- CGPoint(- x: anchor.x + $0.x + xOffset,- y: anchor.y + $0.y + yOffset+ SoftwareCursorGlyphRenderer.draw(+ in: bounds,+ context: context,+ state: SoftwareCursorGlyphRenderState(+ rotation: rotation,+ cursorBodyOffset: cursorBodyOffset,+ fogOffset: fogOffset,+ fogOpacity: fogOpacity,+ fogScale: fogScale,+ clickProgress: clickProgress)- }-- let path = NSBezierPath()- path.move(to: translated[0])- for point in translated.dropFirst() {- path.line(to: point)- }- path.close()- return path+ )}}diff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swiftindex e634eeb..a42733c 100644--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift@@ -267,6 +267,42 @@ final class OpenComputerUseKitTests: XCTestCase {XCTAssertFalse(visualCursorEnabled(environment: ["OPEN_COMPUTER_USE_VISUAL_CURSOR": "false"]))}+ func testInputFallbackDebugFlagDefaultsToDisabled() {+ XCTAssertFalse(inputFallbackDebugEnabled(environment: [:]))+ XCTAssertTrue(inputFallbackDebugEnabled(environment: ["OPEN_COMPUTER_USE_DEBUG_INPUT_FALLBACKS": "1"]))+ XCTAssertTrue(inputFallbackDebugEnabled(environment: ["OPEN_COMPUTER_USE_DEBUG_INPUT_FALLBACKS": "true"]))+ XCTAssertFalse(inputFallbackDebugEnabled(environment: ["OPEN_COMPUTER_USE_DEBUG_INPUT_FALLBACKS": "0"]))+ XCTAssertFalse(inputFallbackDebugEnabled(environment: ["OPEN_COMPUTER_USE_DEBUG_INPUT_FALLBACKS": "off"]))+ }++ func testMakeVisualCursorTargetUsesWindowRelativeElementCenter() {+ let target = makeVisualCursorTarget(+ localFrame: CGRect(x: 24, y: 32, width: 120, height: 48),+ windowBounds: CGRect(x: 400, y: 220, width: 900, height: 640),+ targetWindowID: 321,+ targetWindowLayer: 8+ )++ XCTAssertEqual(+ target,+ VisualCursorTarget(+ point: CGPoint(x: 484, y: 276),+ window: CursorTargetWindow(windowID: 321, layer: 8)+ )+ )+ }++ func testMakeVisualCursorTargetReturnsNilWithoutWindowBounds() {+ XCTAssertNil(+ makeVisualCursorTarget(+ localFrame: CGRect(x: 24, y: 32, width: 120, height: 48),+ windowBounds: nil,+ targetWindowID: 321,+ targetWindowLayer: 8+ )+ )+ }+func testCursorWindowGeometryAnchorsTipPosition() {let geometry = CursorWindowGeometry(windowSize: CGSize(width: 128, height: 128),@@ -278,6 +314,12 @@ final class OpenComputerUseKitTests: XCTestCase {XCTAssertEqual(geometry.tipPosition(forOrigin: CGPoint(x: 1156, y: 712)), tipPosition)}+ func testSoftwareCursorGlyphMetricsMatchSharedProceduralCalibration() {+ XCTAssertEqual(SoftwareCursorGlyphMetrics.windowSize, CGSize(width: 126, height: 126))+ XCTAssertEqual(SoftwareCursorGlyphMetrics.tipAnchor.x, 60.35, accuracy: 0.01)+ XCTAssertEqual(SoftwareCursorGlyphMetrics.tipAnchor.y, 70.3, accuracy: 0.01)+ }+func testCursorMotionPathStartsAndEndsAtExpectedPoints() {let path = CursorMotionPath(start: CGPoint(x: 10, y: 20),diff --git a/scripts/computer-use-cli/README.md b/scripts/computer-use-cli/README.mdindex 06283cc..08e6736 100644--- a/scripts/computer-use-cli/README.md+++ b/scripts/computer-use-cli/README.md@@ -65,6 +65,12 @@ That sample covers all 9 official tools against `TextEdit`, and it intentionallyrepeats `get_app_state` between state-changing actions because the officialbundled `computer-use` invalidates the cached app state after each mutation.+For a smaller cursor-comparison path, use+`examples/textedit-set-value-click-raise-seq.json`.+That sample stays on the `set_value -> click -> Raise` flow so the same calls file+can be pointed at both the official bundled `computer-use` and the local+`open-computer-use` binary.+## Default targetBy default, the CLI auto-discovers the official bundled `computer-use` plugin under:@@ -109,6 +115,18 @@ go run . list-tools \--server-bin ~/.codex/plugins/cache/open-computer-use-local/open-computer-use/0.1.20/scripts/launch-open-computer-use.sh```+Example working comparison flow against a local repo build:++```bash+swift build --product OpenComputerUse+cd scripts/computer-use-cli+go run . call-seq \+ --transport direct \+ --plugin-root ../.. \+ --server-bin ../../.build/debug/OpenComputerUse \+ --calls-file examples/textedit-set-value-click-raise-seq.json+```+Example working invocation against the official bundled `computer-use`:```bashdiff --git a/scripts/computer-use-cli/examples/textedit-overlay-seq.json b/scripts/computer-use-cli/examples/textedit-overlay-seq.jsonindex 96028d2..25e2c64 100644--- a/scripts/computer-use-cli/examples/textedit-overlay-seq.json+++ b/scripts/computer-use-cli/examples/textedit-overlay-seq.json@@ -26,64 +26,7 @@"tool": "click","args": {"app": "TextEdit",- "element_index": "2"- }- },- {- "tool": "get_app_state",- "args": {- "app": "TextEdit"- }- },- {- "tool": "type_text",- "args": {- "app": "TextEdit",- "text": "\n[type_text] hello from call-seq"- }- },- {- "tool": "get_app_state",- "args": {- "app": "TextEdit"- }- },- {- "tool": "press_key",- "args": {- "app": "TextEdit",- "key": "Return"- }- },- {- "tool": "get_app_state",- "args": {- "app": "TextEdit"- }- },- {- "tool": "scroll",- "args": {- "app": "TextEdit",- "element_index": "1",- "direction": "down",- "pages": 1- }- },- {- "tool": "get_app_state",- "args": {- "app": "TextEdit"- }- },- {- "tool": "drag",- "args": {- "app": "TextEdit",- "from_x": 120,- "from_y": 120,- "to_x": 320,- "to_y": 120+ "element_index": "0"}},{diff --git a/scripts/computer-use-cli/examples/textedit-set-value-click-raise-seq.json b/scripts/computer-use-cli/examples/textedit-set-value-click-raise-seq.jsonnew file mode 100644index 0000000..25e2c64--- /dev/null+++ b/scripts/computer-use-cli/examples/textedit-set-value-click-raise-seq.json@@ -0,0 +1,46 @@+[+ {+ "tool": "list_apps"+ },+ {+ "tool": "get_app_state",+ "args": {+ "app": "TextEdit"+ }+ },+ {+ "tool": "set_value",+ "args": {+ "app": "TextEdit",+ "element_index": "2",+ "value": "line 01\nline 02\nline 03\nline 04\nline 05\nline 06\nline 07\nline 08\nline 09\nline 10\nline 11\nline 12\nline 13\nline 14\nline 15\nline 16\nline 17\nline 18\nline 19\nline 20"+ }+ },+ {+ "tool": "get_app_state",+ "args": {+ "app": "TextEdit"+ }+ },+ {+ "tool": "click",+ "args": {+ "app": "TextEdit",+ "element_index": "0"+ }+ },+ {+ "tool": "get_app_state",+ "args": {+ "app": "TextEdit"+ }+ },+ {+ "tool": "perform_secondary_action",+ "args": {+ "app": "TextEdit",+ "element_index": "0",+ "action": "Raise"+ }+ }+]