👾 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
fix: prevent secondary action selectors from shadowing raw actions
ifuryst7aa0a619f15e
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex 14f78ad..f2dd4c4 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -76,7 +76,7 @@- overlay 不再依赖临时 `terminal settle` 补丁来修尾;主线现在统一改成“路径层给目标点,visual dynamics 层给可见姿态”的双层模型,所以 move 末段、pulse 和 idle 共用同一套状态,不会再出现 endpoint 锁住后只剩原地翻角的收尾。- overlay 的渲染输入也从单一 `rotation` 扩展成 `rotation + cursorBodyOffset + fogOffset + fogScale`,让速度滞后能真正体现在画面上,而不是只存在于主循环内部状态;其中 `rotation` 现在按二进制里 `SoftwareCursorStyle.angle + CursorView._animatedAngleOffsetDegrees` 的分层去近似,不再把“跟随运动方向的主朝向”和“小幅 wiggle offset”压成同一个受限小角度。- 动作型 tools 对普通 app 采用“非侵入优先,物理指针路径显式 opt-in”策略:- - `perform_secondary_action` 只执行目标元素已经暴露出来的 AX action;Safari 这类 AppKit custom action descriptor(例如 `Name:close tab ...`)会显示为短名称并准确映射回过滤后的原始 AX action,避免 raw/rendered action 错配;无效或歧义 action 返回官方风格的 `... is not a valid secondary action for ...`,fixture 的 `Raise` 路径也不再为了测试去准备全局物理指针输入+ - `perform_secondary_action` 只执行目标元素已经暴露出来的 AX action;Safari 这类 AppKit custom action descriptor(例如 `Name:close tab ...`)会显示为短名称并准确映射回过滤后的原始 AX action,避免 raw/rendered action 错配;短名称与其他显示名称或任一其他原始 AX action(包括被过滤的动作,忽略大小写)冲突时保留完整 descriptor,保证输出 selector 不被原始动作精确匹配抢占;无效或歧义 action 返回官方风格的 `... is not a valid secondary action for ...`,fixture 的 `Raise` 路径也不再为了测试去准备全局物理指针输入- `set_value` 会先用 `AXUIElementIsAttributeSettable(kAXValueAttribute)` 判断目标是否真的是可设置值元素,只有 settable 时才调用 `AXUIElementSetAttributeValue`;不可设置时返回官方风格的 non-settable 错误,不退到键盘输入、剪贴板或未公开的文本替换接口- `click.click_method` 是开源版的可选扩展,支持 `auto`(默认)、`accessibility`、`app_post`、`sky_click` 和 `global`。未传参数时继续使用原有自动路由;显式模式不会静默 fallback 到其他实现。`accessibility` 只接受 `element_index`;其余 mouse 路径可以使用 `element_index` 的计算落点或原始 `x/y` 坐标。- element-targeted `click` 的 `auto` 左键路径会先试原生列表的 `AXSelectedChildren` 选择,再试 `AXPress` / `AXConfirm` / `AXOpen` 这类真正语义化的激活动作;如果目标本身不可点,还会继续尝试其子孙 AX 元素(例如 Finder sidebar row 下面暴露 `AXOpen` 的 cell)和命中点附近的 AX hit-test 结果,最后进入现有 non-AX 分支:未开启全局指针环境变量时使用 `postToPid` 定向鼠标事件,开启时直接使用全局 HID 事件。`AXRaise` / `kAXMainAttribute` / `kAXFocusedAttribute` 这类 activation-only fallback 只允许窗口级元素使用,避免普通静态文本或容器把“获得焦点”误报成“点击已处理”;`click_count > 1` 也会优先重复可用的 AX action。diff --git a/docs/histories/2026-09/20260906-1200-secondary-action-correctness.md b/docs/histories/2026-09/20260906-1200-secondary-action-correctness.mdindex 3749bd7..59b6093 100644--- a/docs/histories/2026-09/20260906-1200-secondary-action-correctness.md+++ b/docs/histories/2026-09/20260906-1200-secondary-action-correctness.md@@ -21,3 +21,11 @@- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`- `docs/ARCHITECTURE.md`- `docs/releases/feature-release-notes.md`++### PR #62 review follow-up++- 用户要求直接在 PR 分支补充修复 commit。+- 同步最新 main,解决 feature release note 冲突并保留应用名称解析与 secondary action 两条记录。+- 补齐短名称与其他原始 AX action 的冲突检测,包含被 renderer 过滤的动作,比较规则与 executor 的 case-insensitive exact lookup 一致。冲突时输出完整 descriptor,继续保留显式 raw action 调用兼容性。+- 回归测试覆盖隐藏的 `AXPress`、可见的 `AXRaise`、大小写差异、两种动作顺序,以及每个输出 selector 的执行映射。+- 验证:新增回归测试在修复前失败;修复后 `swift test` 共 161 项、0 失败、1 项 Chrome live test 按默认配置跳过;`make check-docs` 和 `git diff --check` 通过。未执行 Safari 实机验证。diff --git a/docs/releases/feature-release-notes.md b/docs/releases/feature-release-notes.mdindex 892ffc3..360832f 100644--- a/docs/releases/feature-release-notes.md+++ b/docs/releases/feature-release-notes.md@@ -4,8 +4,8 @@| 日期 | 功能域 | 用户价值 | 变更摘要 || --- | --- | --- | --- |+| 2026-09-06 | macOS secondary action | Agent 可以通过 Safari 暴露的 `close tab` secondary action 可靠关闭标签页,不会因内部动作被过滤而误执行另一项动作。 | macOS renderer 将 `Name:close tab ...` 形式的 AppKit custom action descriptor 显示为短名称,executor 从同一组过滤后的 raw actions 做等价名称匹配,并拒绝歧义匹配;短名称与其他原始 action 冲突时保留完整 descriptor,避免误执行同名原始动作。 || 2026-09-06 | macOS 应用名称解析 | 按名称定位 Safari 等应用时优先匹配真实应用,避免同名后台 helper 抢占匹配结果。 | 按普通应用名称、普通应用 executable、后台应用名称、后台 executable 分级匹配;同级保持原顺序,bundle identifier 和安全过滤规则不变。 |-| 2026-09-06 | macOS secondary action | Agent 可以通过 Safari 暴露的 `close tab` secondary action 可靠关闭标签页,不会因内部动作被过滤而误执行另一项动作。 | macOS renderer 将 `Name:close tab ...` 形式的 AppKit custom action descriptor 显示为短名称,executor 从同一组过滤后的 raw actions 做等价名称匹配,并拒绝歧义匹配。 || 2026-09-01 | 内嵌 App Agent Socket 隔离 | 使用内嵌 OCU 的宿主不会再与用户全局 OCU 争用同一个 App Agent Socket,避免一个实例意外终止或替换另一个实例。 | 发布 `0.3.3`,为显式配置 namespace 的宿主生成确定性、短且不泄露原值的 Socket 文件名;未配置时继续兼容旧路径。 |## 2026-08diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swiftindex a83b367..e0a56c0 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift@@ -1819,7 +1819,13 @@ func meaningfulActions(_ values: [String], role: String) -> [String] {let collides = names.indices.contains { other inother != index && secondaryActionNamesEquivalent(names[index], names[other])}- return collides ? rawActions[index] : names[index]+ // Exact raw-action lookup takes precedence over display-name lookup,+ // including actions omitted from the rendered list.+ let shadowsRawAction = values.contains { rawAction in+ rawAction != rawActions[index]+ && rawAction.caseInsensitiveCompare(names[index]) == .orderedSame+ }+ return collides || shadowsRawAction ? rawActions[index] : names[index]}}diff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swiftindex 6c4b224..cd89fae 100644--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift@@ -1167,6 +1167,37 @@ final class OpenComputerUseKitTests: XCTestCase {XCTAssertNil(service.matchingAction(requested: "Press", record: record))}+ func testSecondaryActionSelectorsDoNotShadowRawActionNames() {+ let service = ComputerUseService()+ // Include both a filtered action and a visible action, and exercise the+ // case-insensitive exact lookup used by the executor.+ for nativeAction in ["AXPress", "AXRaise"] {+ for customName in [nativeAction, nativeAction.lowercased()] {+ let customAction = "Name:\(customName) Target:CustomTarget Selector:_custom:"+ for rawActions in [[nativeAction, customAction], [customAction, nativeAction]] {+ let emitted = meaningfulActions(rawActions, role: kAXButtonRole as String)+ let visible = meaningfulRawActions(rawActions, role: kAXButtonRole as String)+ let record = ElementRecord(+ index: 50,+ identifier: nil,+ element: nil,+ localFrame: nil,+ role: kAXButtonRole as String,+ rawActions: rawActions,+ prettyActions: emitted+ )++ XCTAssertTrue(emitted.contains(customAction))+ XCTAssertEqual(emitted.count, visible.count)+ for (selector, expected) in zip(emitted, visible) {+ XCTAssertEqual(service.matchingAction(requested: selector, record: record), expected)+ }+ XCTAssertEqual(service.matchingAction(requested: nativeAction, record: record), nativeAction)+ }+ }+ }+ }+func testSecondaryActionMatchingRejectsAmbiguousDisplayNames() {let service = ComputerUseService()let record = ElementRecord(