👾 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 cursor lifecycle and tool defaults
Leod46105273c20
diff --git a/apps/OpenComputerUse/Sources/OpenComputerUse/MCPAppRuntime.swift b/apps/OpenComputerUse/Sources/OpenComputerUse/MCPAppRuntime.swiftindex 461a5d8..cc6d657 100644--- a/apps/OpenComputerUse/Sources/OpenComputerUse/MCPAppRuntime.swift+++ b/apps/OpenComputerUse/Sources/OpenComputerUse/MCPAppRuntime.swift@@ -5,6 +5,7 @@ import OpenComputerUseKitfinal class MCPAppRuntime: NSObject, NSApplicationDelegate {private let server: StdioMCPServerprivate var runtimeError: Error?+ private var turnEndedObserver: NSObjectProtocol?private init(server: StdioMCPServer) {self.server = server@@ -25,9 +26,24 @@ final class MCPAppRuntime: NSObject, NSApplicationDelegate {}func applicationDidFinishLaunching(_ notification: Notification) {+ turnEndedObserver = DistributedNotificationCenter.default().addObserver(+ forName: openComputerUseTurnEndedNotificationName,+ object: nil,+ queue: .main+ ) { _ in+ Task { @MainActor in+ resetOpenComputerUseVisualCursor()+ }+ }Thread.detachNewThreadSelector(#selector(processStandardIO), toTarget: self, with: nil)}+ func applicationWillTerminate(_ notification: Notification) {+ if let turnEndedObserver {+ DistributedNotificationCenter.default().removeObserver(turnEndedObserver)+ }+ }+func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {false}diff --git a/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swift b/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swiftindex a4d70ff..7e764df 100644--- a/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swift+++ b/apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swift@@ -60,6 +60,7 @@ enum OpenComputerUseMain {exit(EXIT_FAILURE)}case .turnEnded:+ postOpenComputerUseTurnEndedNotification()print("turn-ended acknowledged")case let .help(command):print(openComputerUseHelpText(command: command))diff --git a/apps/OpenComputerUseFixture/Sources/OpenComputerUseFixture/main.swift b/apps/OpenComputerUseFixture/Sources/OpenComputerUseFixture/main.swiftindex b7adc7c..f09eb5a 100644--- a/apps/OpenComputerUseFixture/Sources/OpenComputerUseFixture/main.swift+++ b/apps/OpenComputerUseFixture/Sources/OpenComputerUseFixture/main.swift@@ -416,11 +416,15 @@ private func debugKeyName(for event: NSEvent) -> String {@mainenum OpenComputerUseFixtureMain {+ @MainActor+ private static var delegate: FixtureAppDelegate?+@MainActorstatic func main() {let application = NSApplication.sharedapplication.setActivationPolicy(.regular)let delegate = FixtureAppDelegate()+ Self.delegate = delegateapplication.delegate = delegateapplication.run()}diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.mdindex be23ba5..7adcd02 100644--- a/docs/ARCHITECTURE.md+++ b/docs/ARCHITECTURE.md@@ -45,9 +45,11 @@- 当前支持的 method:- `initialize`- `notifications/initialized`+ - `notifications/turn-ended`- `ping`- `tools/list`- `tools/call`+- `notifications/turn-ended` 是开源版显式的 turn boundary hook;收到后会清理当前进程里的 visual cursor overlay。CLI `open-computer-use turn-ended [payload]` 也会通过 macOS distributed notification 通知正在运行的 AppKit MCP 进程执行同一类清理,用于接 Codex legacy notify 的 after-agent payload。### 3. Tool Service 层@@ -58,7 +60,7 @@- `open-computer-use call <tool> --args '{...}'` 会直接输出 MCP-style JSON result;`open-computer-use call --calls '[...]'` 会在同一进程里顺序执行 JSON 数组里的 tool calls,并复用同一个 `ComputerUseService` 内存态,因此 `get_app_state` 之后的 action tool 可以继续使用同一轮 snapshot 的 `element_index`。序列执行遇到 `isError=true` 的 tool result 后停止。- 对真实 app 的 `get_app_state` / action tool 入口,当前新增了一层官方风格的高风险 bundle denylist:bundle-id 直传时直接返回 safety denial;名称匹配时默认不解析到这些 app,尽量贴近官方对终端、密码管理器、Chrome 与少量系统敏感组件的防护行为。- 普通 app 的 element frame 当前按“窗口左上角为原点”的 window-relative 坐标输出,便于后续把 `element_index` 和截图坐标统一到同一套参考系。-- `click` / `set_value` 在执行真实动作前后,会额外驱动一层透明 `SoftwareCursorOverlay` window:两者的移动阶段现在共用一条 heading-driven 的官方风格 motion 内核,显式把“当前 cursor 朝向”和“最终 resting pose”一起喂给选路器,优先生成需要时先掉头、再沿车头方向推进的 C 形/单侧大弧轨迹;首次显示时按官方 binary 的 fresh state 从 AppKit 全局 `(0,0)` window origin 生成起点,后续动作继续复用上一帧 visible tip。真正显示出来的 cursor 不再直接等于 path sample,而是经过一层独立的 visual dynamics 状态,把 visible tip、velocity、angle 和 fog/offset 持续推进。`click` 结尾会衔接 click pulse、idle sway 和自动淡出,`set_value` 则只做 settle / idle / hide,不给 pulse。+- `click` / `set_value` 在执行真实动作前后,会额外驱动一层透明 `SoftwareCursorOverlay` window:两者的移动阶段现在共用一条 heading-driven 的官方风格 motion 内核,显式把“当前 cursor 朝向”和“最终 resting pose”一起喂给选路器,优先生成需要时先掉头、再沿车头方向推进的 C 形/单侧大弧轨迹;首次显示时按官方 binary 的 fresh state 从 AppKit 全局 `(0,0)` window origin 生成起点,后续动作继续复用上一帧 visible tip。真正显示出来的 cursor 不再直接等于 path sample,而是经过一层独立的 visual dynamics 状态,把 visible tip、velocity、angle 和 fog/offset 持续推进。`click` 结尾会衔接 click pulse 和 idle sway,`set_value` 则只做 settle / idle,不给 pulse;两者收尾后都会像官方 service 一样保持短期 idle 状态,约 5 分钟无后续操作才做 cleanup,这样连续 tool call 不会反复从 fresh `(0,0)` 起步;如果宿主在任务 / turn 结束时发出 `turn-ended`,cursor 会立即消失并清掉本轮位置状态。- overlay 的 visual style 不再自己从官方 app bundle 裁 `SoftwareCursor` 小图;主 MCP runtime 现在和 `CursorMotion` 一样优先渲染仓库里沉淀的 `official-software-cursor-window-252.png` baseline,只有资源缺失时才退回 `OpenComputerUseKit` 内部的程序化 pointer/fog fallback。命中点 anchor 仍固定在 `126x126` 画布里的同一组 tip-offset 上;glyph 自身的 neutral heading 继续沿用 `CursorMotion` / 官方 baseline 的 `-3π/4`。主 runtime overlay window 按 AppKit 全局坐标移动;路径选路用屏幕上实际可见的 AppKit forward heading,进入 visual dynamics / render state 前则把 velocity 的 y 轴翻回 CursorMotion 的 y-down screen state,再交给 AppKit 绘制层做角度和 `dy` 翻转。程序化 fallback 保留 neutral artwork correction,把它的天然轮廓轴对齐到 `CursorMotion` / 官方 baseline 的 `-3π/4` forward 方向,但不让实验线依赖 runtime 代码。- 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。@@ -71,14 +73,16 @@- element-targeted `click` 的左键路径会先试 `AXPress`,再试窗口/根元素常见的 `AXRaise`、`kAXMainAttribute`、`kAXFocusedAttribute`;这里不再把 `AXUIElementIsAttributeSettable` 的结果当成硬门槛,因为像 `TextEdit` window 这类元素在 `kAXFocusedAttribute` 上会出现“`isSettable=false` 但直接 set 成功”的官方同款场景;`click_count > 1` 会优先重复可用的 AX action,而不是直接退到全局鼠标事件- `AXUIElementCopyElementAtPosition` 做坐标命中,尽量把 coordinate click 反解成可操作 AX 元素- `CGEvent.postToPid` 定向发送键盘事件,避免为了 `type_text` / `press_key` 抢前台- - `click` 不再默认退回全局 `CGEvent.post(tap: .cghidEventTap)`,因为该路径会发送 `.mouseMoved` 并移动系统硬件光标;只有设置 `OPEN_COMPUTER_USE_ALLOW_GLOBAL_POINTER_FALLBACKS=1` 时才允许这条物理指针兜底- - `drag` 当前仍是 coordinate-only API,无法通过 AX action 完整表达时会继续使用全局鼠标事件;这条路径后续需要继续向官方的 window / event-target aware 路由收敛+ - `scroll.pages` 对齐官方 `1.0.755` 的 `number` schema,支持小数页数;整数页且目标暴露 `AXScroll*ByPage` 时优先走 AX action,否则用 `CGEvent.postToPid` 向目标进程定向发送 scroll event+ - `drag` 仍是 coordinate-only API,但默认不再使用全局 `.cghidEventTap` mouse event;默认改为 `CGEvent.postToPid` 定向发送 mouse move / down / dragged / up 事件,避免移动用户真实硬件光标+ - `click` / `scroll` / `drag` 只有设置 `OPEN_COMPUTER_USE_ALLOW_GLOBAL_POINTER_FALLBACKS=1` 时才允许全局 `CGEvent.post(tap: .cghidEventTap)` 物理指针兜底;默认路径不再为了 fallback 调用 `NSRunningApplication.activate`### 4. Fixture Bridge- `OpenComputerUseFixture` 会把自己的窗口与元素状态写到临时 JSON 文件。- 对 fixture 的 `get_app_state` 和少量测试专用动作,会通过 `FixtureBridge` 走显式 command 通道。- 这个 bridge 只服务于仓库内 deterministic smoke path,不是面向真实第三方 app 的能力边界。+- 因为 SwiftPM 裸 executable 形式启动的 fixture 没有稳定的 bundle identifier,`list_apps` 会仅对 `OpenComputerUseFixture` 注入一个内部 synthetic identifier,保证 smoke suite 仍能覆盖 `list_apps`,普通第三方 app 仍按真实 bundle id 输出。### 5. Cursor Labdiff --git a/docs/exec-plans/active/20260422-remaining-tool-official-alignment.md b/docs/exec-plans/active/20260422-remaining-tool-official-alignment.mdnew file mode 100644index 0000000..83a4c38--- /dev/null+++ b/docs/exec-plans/active/20260422-remaining-tool-official-alignment.md@@ -0,0 +1,99 @@+# Remaining Computer Use Tool Alignment++## 目标++在 `click` 和 `set_value` 已完成官方姿势收口后,逐项逆向并对齐剩余 7 个 Computer Use tools,重点确认它们是否会抢用户真实鼠标或抢前台焦点,并把结论、实现差距、测试和文档状态落到仓库里。++## 范围++- 包含:+ - `list_apps`+ - `get_app_state`+ - `perform_secondary_action`+ - `scroll`+ - `drag`+ - `type_text`+ - `press_key`+ - 官方 bundled `computer-use` 当前版本的 `tools/list`、静态字符串、导入符号、必要时的反汇编定位。+ - 每个工具的本地实现差距、行为修正、测试、架构文档和 history。+- 不包含:+ - 重新打开已经完成的 `click` / `set_value` 行为修正,除非剩余工具逆向时发现共用底层需要补丁。+ - 复刻官方闭源 host authorization、私有 IPC、完整 visual cursor choreography。+ - 用全局物理鼠标事件作为默认兜底来换取表面通过率。++## 背景++- 相关文档:+ - `docs/ARCHITECTURE.md`+ - `docs/references/codex-computer-use-reverse-engineering/tool-call-samples-2026-04-17.md`+ - `docs/references/codex-computer-use-reverse-engineering/internal-ipc-surface.md`+ - `docs/histories/2026-04/20260421-2120-disable-click-global-pointer-default.md`+ - `docs/histories/2026-04/20260422-1050-align-set-value-settable-boundary.md`+- 相关代码路径:+ - `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift`+ - `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift`+ - `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift`+ - `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/InputSimulation.swift`+ - `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AccessibilitySnapshot.swift`+ - `apps/OpenComputerUseFixture/Sources/OpenComputerUseFixture/main.swift`+ - `apps/OpenComputerUseSmokeSuite/Sources/OpenComputerUseSmokeSuite/main.swift`+- 已知约束:+ - 官方 `1.0.755` 的 `tools/list` 里 `scroll.pages` 是 `number`,文案为 `Number of pages to scroll. Fractional values are supported. Defaults to 1`;旧安装根可能仍暴露 `integer` 旧 schema。+ - 官方 binary 暴露 `MouseEventTarget`、`KeyboardEventTarget`、`EventTap`、`SyntheticAppFocusEnforcer`、`SystemFocusStealPreventer`、`UIElementScrollOperation`、`ScrollAreaUIElement`、`ScrollBarUIElement` 等类型名,说明动作路由不是简单把所有 fallback 发到全局 HID 光标。+ - 本地 `drag` 当前直接走全局 mouse event,`scroll` 在 AX page action 不可用时也会走全局 scroll event,是剩余工具里最高风险的抢鼠标/焦点路径。++## 风险++- 风险:只对齐 schema,不处理全局事件 fallback,用户仍可能遇到鼠标或焦点被抢。+ - 缓解方式:每个动作工具都明确写下默认执行路径和 fallback 是否允许;高风险物理指针路径必须显式 opt-in 或替换为更窄的目标路由。+- 风险:官方行为通过私有 AccessibilitySupport 类型实现,开源版只能近似。+ - 缓解方式:区分“确认一致”、“确认不同但有安全替代”和“待逆向”;不要把猜测写成结论。+- 风险:改动 `drag` / `scroll` 可能影响 smoke fixture。+ - 缓解方式:fixture bridge 保持 deterministic;真实 app 路径另补单元测试覆盖参数解析和 fallback gate。++## 工具级 TODO++- [x] `click`: 已对齐 element-targeted AX 优先、`click_count` 重复 AX action、默认禁止全局物理指针 fallback。+- [x] `set_value`: 已对齐 `AXUIElementIsAttributeSettable(kAXValueAttribute)` 前置检查,非 settable 返回官方风格错误,不退到键盘/剪贴板/未公开文本替换。+- [ ] `list_apps`: 复核官方 `1.0.755` 输出字段、排序和 denylist 影响;确认本地 Spotlight + running app 合并仍一致。+- [ ] `get_app_state`: 复核官方 session/start-state、截图、AX tree rendering、stale-state 错误和不抢前台策略;确认本地不 `activate` 的边界。+- [ ] `perform_secondary_action`: 复核官方 action name 匹配、菜单项/secondary action 错误语义和是否需要 prepare interaction;确认本地 AX action 路径不会抢焦点。+- [ ] `scroll`: 对齐官方 `pages` number schema 和 fractional pages;逆向 `UIElementScrollOperation` / scroll bar 路径,消除默认全局物理事件 fallback。(当前已完成 schema / 参数错误 / 默认 pid-targeted event patch,scroll bar 细节仍待继续逆向)+- [ ] `drag`: 逆向 `MouseEventTarget` / drag dispatch;消除默认全局 mouse event fallback 或改为显式 opt-in。(当前已改成默认 pid-targeted mouse event,官方 `MouseEventTarget` 细节仍待继续逆向)+- [ ] `type_text`: 逆向 `KeyboardEventTarget` / keyboard layout 错误语义;确认本地 `postToPid` 不抢焦点,并对齐缺失 text / Unicode 边界。(当前已对齐 required string 为空时的 missing 错误)+- [ ] `press_key`: 逆向 xdotool key parser、keyboard layout、modifier 语义和错误文案;确认本地 `postToPid` 不抢焦点。(当前已对齐 required string 为空时的 missing 错误)++## 里程碑++1. 建立逐工具 TODO 和官方证据基线。+2. 先处理高风险 `scroll` / `drag`,再处理键盘类和只读类差异。+3. 完成测试、文档、history,并按需提交。++## 验证方式++- 命令:+ - `swift test`+ - `swift build --product OpenComputerUse`+ - `COMPUTER_USE_PLUGIN_ROOT="$HOME/.codex/plugins/cache/openai-bundled/computer-use/1.0.755" go run . list-tools --transport app-server`+ - `go run . list-tools --transport direct --server-bin ../../.build/debug/OpenComputerUse`+ - `./scripts/run-tool-smoke-tests.sh`+- 手工检查:+ - `tools/list` 与官方 `1.0.755` schema 对齐,尤其 `scroll.pages`。+ - 每个动作工具都能说明是否使用 AX、pid-targeted event、window-targeted event 或显式 opt-in 物理 pointer fallback。+ - 不允许在默认路径里调用会移动系统硬件光标的 mouse move / drag 兜底。+- 观测检查:+ - 运行真实 app 样本时,用户硬件鼠标位置不应因为默认工具调用改变。+ - action 后返回仍包含最新 state text 和截图。++## 进度记录++- [x] 里程碑 1+- [ ] 里程碑 2+- [ ] 里程碑 3++## 决策记录++- 2026-04-22:将剩余 7 个工具拆成独立 checklist;`drag` 和 `scroll` 因存在全局事件 fallback 排在最前,键盘类和只读类随后复核。+- 2026-04-22:官方 `1.0.755` 的 `scroll.pages` 已确认是 `number` schema;旧插件根返回的 `integer` 视为旧版本基线,不再作为当前对齐目标。+- 2026-04-22:官方 app-server 对 required string 的空字符串按 missing 处理;本地 dispatcher 统一改成非空 required string,并返回 `Missing required argument: <name>`。+- 2026-04-22:本地 `scroll` / `drag` 不再默认调用全局 `.cghidEventTap` 和 app activation fallback;未命中 AX scroll action 时先用 `CGEvent.postToPid` 定向发给目标进程,只有显式打开 `OPEN_COMPUTER_USE_ALLOW_GLOBAL_POINTER_FALLBACKS=1` 才走物理指针兜底。diff --git a/docs/histories/2026-04/20260422-1057-preserve-visual-cursor-idle-state.md b/docs/histories/2026-04/20260422-1057-preserve-visual-cursor-idle-state.mdnew file mode 100644index 0000000..e8dec78--- /dev/null+++ b/docs/histories/2026-04/20260422-1057-preserve-visual-cursor-idle-state.md@@ -0,0 +1,46 @@+## [2026-04-22 10:57] | Task: 保持 visual cursor 的 interaction 间 idle 状态++### Execution Context+* **Agent ID**: `Codex`+* **Base Model**: `GPT-5.4`+* **Runtime**: `Codex CLI on macOS + SwiftPM`++### User Query+> 逆向官方 `.app` 看它如何管理 overlay cursor 显示;当前本地 `click` / `set_value` 之间 cursor 会消失并反复从左下角 `(0,0)` 出发,而官方会 idle 在当前位置,下次操作继续移动。++### Changes Overview+**Scope:** `OpenComputerUseKit` visual cursor runtime、逆向文档、架构文档++**Key Actions:**+- **[官方生命周期复查]**: 对 bundled `computer-use` `1.0.755` 复查 Swift metadata,确认 `ComputerUseCursor.Window.currentInterpolatedOrigin` 和 `wantsToBeVisible` / `shouldFadeOut` 是分离状态。+- **[运行时日志对照]**: 通过 unified log 复查官方 service 的 cursor movement,确认多次 movement 之间复用同一个 cursor window,最后一次 movement 后约 5 分钟才由 service idle timeout 终止。+- **[本地 idle 生命周期修正]**: `SoftwareCursorOverlay` 不再在 `click` / `set_value` 收尾后 0.5 秒级清空状态,而是保留 idle 约 5 分钟,让后续 tool call 从当前 visible tip 继续。+- **[补测试和文档]**: 新增 idle timeout 常量回归测试,并同步 `ARCHITECTURE.md` 与 reverse-engineering 文档。++### Design Intent+官方的 `(0,0)` 起点是 fresh service / fresh cursor window 语义,不是每次 action 的收尾语义。把本地短延迟 hide 改成较长的 idle cleanup,可以保留当前进程内的 `displayedTipPosition` / visual dynamics 状态,避免连续工具调用时反复回到左下角。++### Files Modified+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `scripts/npm/build-packages.mjs`+- `docs/ARCHITECTURE.md`+- `docs/references/codex-computer-use-reverse-engineering/software-cursor-overlay.md`+- `docs/histories/2026-04/20260422-1057-preserve-visual-cursor-idle-state.md`++### Follow-up (2026-04-22, turn-ended cleanup)++- **[确认缺口]**: 复查后确认本地 `open-computer-use turn-ended` 只是单独 CLI 进程打印确认,不会影响正在运行的 MCP overlay;这不能满足“任务结束 cursor 消失”。+- **[MCP 内部 hook]**: `StdioMCPServer` 新增 `notifications/turn-ended`,收到后立即 reset 当前进程里的 visual cursor。+- **[Codex notify 兼容]**: CLI `turn-ended` 现在接受 Codex legacy notify 追加的 after-agent payload,并通过 macOS distributed notification 通知正在运行的 AppKit MCP 进程清理 cursor;`MCPAppRuntime` 会监听这条通知。+- **[同步测试文档]**: 新增 CLI payload 解析和 MCP notification 回归测试,并更新架构与逆向文档。++**Follow-up Files:**+- `apps/OpenComputerUse/Sources/OpenComputerUse/MCPAppRuntime.swift`+- `apps/OpenComputerUse/Sources/OpenComputerUse/OpenComputerUseMain.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/MCPServer.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `docs/ARCHITECTURE.md`+- `docs/references/codex-computer-use-reverse-engineering/software-cursor-overlay.md`diff --git a/docs/histories/2026-04/20260422-1113-align-remaining-tool-defaults.md b/docs/histories/2026-04/20260422-1113-align-remaining-tool-defaults.mdnew file mode 100644index 0000000..fbb575d--- /dev/null+++ b/docs/histories/2026-04/20260422-1113-align-remaining-tool-defaults.md@@ -0,0 +1,37 @@+## [2026-04-22 11:13] | Task: 对齐剩余 Computer Use tools 的默认行为++### 🤖 Execution Context+* **Agent ID**: `Codex`+* **Base Model**: `GPT-5`+* **Runtime**: `Codex CLI`++### 📥 User Query+> `click` 和 `set_value` 已经对齐,继续把其他 7 个 tool 一个一个过一遍,落 TODO,并按官方 `.app` 逆向结果对齐细节。++### 🛠 Changes Overview+**Scope:** `OpenComputerUseKit` tool surface / input routing, fixture smoke support, docs++**Key Actions:**+- **[Execution Plan]**: 新增 active plan,把剩余 7 个 tool 拆成 checklist,并记录官方 `1.0.755` 的静态类型线索和验证命令。+- **[scroll schema]**: 将 `scroll.pages` 从 `integer` 对齐到官方 `number` schema,支持 fractional pages,并补 `pages must be > 0` 与 invalid direction 的官方风格错误。+- **[required string]**: dispatcher 对 required string 统一拒绝空字符串,返回 `Missing required argument: <name>`,覆盖 `type_text` / `press_key` / `set_value` / `scroll` 等工具。+- **[非物理 pointer 默认路径]**: `scroll` / `drag` 默认改为 `CGEvent.postToPid` 定向事件;只有显式设置 `OPEN_COMPUTER_USE_ALLOW_GLOBAL_POINTER_FALLBACKS=1` 时才允许全局 `.cghidEventTap` 物理指针兜底。+- **[Smoke fixture]**: 为 SwiftPM 裸 executable fixture 保持强引用 delegate,并仅对内部 `OpenComputerUseFixture` 注入 synthetic list identifier,恢复 9-tool smoke suite 覆盖。++### 🧠 Design Intent (Why)++官方 binary 暴露 `MouseEventTarget`、`KeyboardEventTarget`、`EventTap`、`SystemFocusStealPreventer`、`UIElementScrollOperation` 等类型,说明默认动作路由不是简单把 fallback 全部发到系统级硬件光标。开源版先把仍会移动真实鼠标或激活 app 的默认路径收掉:能用 AX action 就走 AX,不能时走 pid-targeted event;物理指针 fallback 只保留为显式调试开关。++### 📁 Files Modified+- `docs/exec-plans/active/20260422-remaining-tool-official-alignment.md`+- `docs/ARCHITECTURE.md`+- `docs/references/codex-computer-use-reverse-engineering/baseline-architecture.md`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AppDiscovery.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Errors.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/FixtureBridge.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/InputSimulation.swift`+- `packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift`+- `packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift`+- `apps/OpenComputerUseFixture/Sources/OpenComputerUseFixture/main.swift`diff --git a/docs/references/codex-computer-use-reverse-engineering/baseline-architecture.md b/docs/references/codex-computer-use-reverse-engineering/baseline-architecture.mdindex 679f4a3..cca9ca8 100644--- a/docs/references/codex-computer-use-reverse-engineering/baseline-architecture.md+++ b/docs/references/codex-computer-use-reverse-engineering/baseline-architecture.md@@ -192,14 +192,14 @@ strings 和运行时都指向同一组 tools:"app": "string","direction": "string","element_index": "string",- "pages": "integer? = 1"+ "pages": "number? = 1"}```- `app`:目标 app。- `direction`:工具说明约束为 `up` / `down` / `left` / `right`。- `element_index`:必须是可滚动的 element。-- `pages`:滚动页数,默认 `1`。+- `pages`:滚动页数,默认 `1`;官方 `1.0.755` 的 tool schema 已改为 `number`,支持小数页数。- 这是 element-scoped scroll,不是全局屏幕滚动。#### `drag`diff --git a/docs/references/codex-computer-use-reverse-engineering/software-cursor-overlay.md b/docs/references/codex-computer-use-reverse-engineering/software-cursor-overlay.mdindex 5ae5053..9aa069b 100644--- a/docs/references/codex-computer-use-reverse-engineering/software-cursor-overlay.md+++ b/docs/references/codex-computer-use-reverse-engineering/software-cursor-overlay.md@@ -213,6 +213,43 @@ Bounds: X=1949 Y=796 Width=126 Height=126也就是说,官方实现更像是“按这次 interaction 最终走的是哪条执行链”来决定是否出 overlay,而不是简单按 public tool 名字一刀切。+### 8. 2026 年 4 月 22 日复查:cursor 位置状态不会在每次 interaction 后立刻销毁++这次针对 bundled `computer-use` `1.0.755` 又做了一次静态 + 运行时复查,重点看“多次 `click` / `set_value` 之间是否应该从 fresh `(0,0)` 重来”。++静态上,`SkyComputerUseService` 的 Swift metadata 仍然能恢复出同一组状态字段:++```text+ComputerUseCursor+ isMoving+ shouldFadeOut+ window+ style+ activityState++ComputerUseCursor.Window+ wantsToBeVisible+ cursorMotionProgressAnimation+ cursorMotionNextInteractionTimingHandler+ cursorMotionCompletionHandler+ cursorMotionDidSatisfyNextInteractionTiming+ currentInterpolatedOrigin+ useOverlayWindowLevel+ correspondingWindowID+```++这组字段的关键点是:`wantsToBeVisible` / `shouldFadeOut` 这类可见性状态,和 `currentInterpolatedOrigin` 这个位置状态是分开的。也就是说,官方结构上并不是“淡出或一次动作结束就把 cursor origin 清空”。++运行时日志也支持这个判断。同一轮官方 service 中,连续多次 `Move cursor to ...` / `Start Bezier cursor animation ...` / `Signal cursor movement completion ...` 之间,AppKit 反复把同一个 `ComputerUseCursor.Window` 对象对应的同一个 window number `orderFront`。最后一次 movement completion 后,约 5 分钟才出现 `Codex Computer Use idle timeout reached; terminating service`。++因此当前更准确的生命周期模型是:++- fresh service / fresh cursor window 初始化时,`currentInterpolatedOrigin` 和 window origin 从 `(0,0)` 起步。+- 每次 action move 会更新同一个 `ComputerUseCursor.Window` 的插值 origin 和 style 状态。+- movement completion 后 cursor 进入 idle / resting 姿态,并继续保留当前位置,短间隔的下一次 interaction 从当前 visible cursor 继续移动。+- task / turn 结束会通过 `turn-ended` lifecycle hook 触发清理,cursor 应该消失。+- `(0,0)` 应该是 fresh session / service reset 语义,不应该在每个 `click` 或 `set_value` 收尾后重放。+## 当前推断### 1. 黄色小鼠标是软件光标,不是系统硬件光标diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AppDiscovery.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AppDiscovery.swiftindex fd5bd57..a5135fe 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AppDiscovery.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/AppDiscovery.swift@@ -49,6 +49,7 @@ enum AppDiscovery {private static let lastUsedDateRankingAttribute = "kMDItemLastUsedDate_Ranking"private static let useCountAttribute = "kMDItemUseCount"private static let maxRecentNonRunningApps = 10+ private static let fixtureListBundleIdentifier = "dev.opencodex.opencomputeruse.fixture"static let usageDateFormatter: DateFormatter = {let formatter = DateFormatter()@@ -61,7 +62,7 @@ enum AppDiscovery {static func listCatalog() -> [ListedAppDescriptor] {let running = userFacingRunningApps()let runningByBundle = running.reduce(into: [String: RunningAppDescriptor]()) { result, descriptor in- guard let bundleIdentifier = descriptor.bundleIdentifier, !bundleIdentifier.isEmpty else {+ guard let bundleIdentifier = listedBundleIdentifier(for: descriptor) else {return}@@ -86,7 +87,7 @@ enum AppDiscovery {}for descriptor in running {- guard let bundleIdentifier = descriptor.bundleIdentifier, !bundleIdentifier.isEmpty else {+ guard let bundleIdentifier = listedBundleIdentifier(for: descriptor) else {continue}@@ -178,7 +179,7 @@ enum AppDiscovery {continue}- guard let bundleIdentifier = descriptor.bundleIdentifier, !bundleIdentifier.isEmpty else {+ guard let bundleIdentifier = listedBundleIdentifier(for: descriptor) else {continue}@@ -193,6 +194,18 @@ enum AppDiscovery {return descriptors}+ private static func listedBundleIdentifier(for descriptor: RunningAppDescriptor) -> String? {+ if let bundleIdentifier = descriptor.bundleIdentifier, !bundleIdentifier.isEmpty {+ return bundleIdentifier+ }++ guard descriptor.name == FixtureBridge.appName else {+ return nil+ }++ return fixtureListBundleIdentifier+ }+private static func compareListedApps(_ lhs: ListedAppDescriptor, _ rhs: ListedAppDescriptor) -> Bool {if lhs.isRunning != rhs.isRunning {return lhs.isRunning && !rhs.isRunningdiff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swiftindex 94cb289..8aeea2b 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseService.swift@@ -207,10 +207,13 @@ public final class ComputerUseService {return snapshotResult(for: try refreshSnapshot(for: query), style: .actionResult)}- public func scroll(app query: String, direction: String, elementIndex: String, pages: Int) throws -> ToolCallResult {+ public func scroll(app query: String, direction: String, elementIndex: String, pages: Double) throws -> ToolCallResult {let normalized = direction.lowercased()guard ["up", "down", "left", "right"].contains(normalized) else {- throw ComputerUseError.invalidArguments("scroll direction must be one of up/down/left/right")+ throw ComputerUseError.message("Invalid scroll direction: \(direction)")+ }+ guard pages.isFinite, pages > 0 else {+ throw ComputerUseError.message("pages must be > 0")}let snapshot = try currentSnapshot(for: query)@@ -225,14 +228,21 @@ public final class ComputerUseService {return snapshotResult(for: try refreshSnapshot(for: query), style: .actionResult)}- if let rawAction = record.rawActions.first(where: { $0.caseInsensitiveCompare("AXScroll\(normalized.capitalized)ByPage") == .orderedSame }), let element = record.element {- for _ in 0..<max(pages, 1) {+ if let repeatCount = integralScrollPageCount(pages),+ let rawAction = record.rawActions.first(where: { $0.caseInsensitiveCompare("AXScroll\(normalized.capitalized)ByPage") == .orderedSame }),+ let element = record.element {+ for _ in 0..<repeatCount {_ = AXUIElementPerformAction(element, rawAction as CFString)Thread.sleep(forTimeInterval: 0.05)}} else if let point = try globalPoint(for: record, snapshot: snapshot) {- InputSimulation.prepareAppForGlobalPointerInput(snapshot.app)- try InputSimulation.scrollGlobally(at: point, direction: normalized, pages: pages)+ try performScrollEvent(+ at: point,+ direction: normalized,+ pages: pages,+ targetDescription: "element_index=\(elementIndex)",+ snapshot: snapshot+ )} else {throw ComputerUseError.stateUnavailable("element \(elementIndex) has no scrollable frame")}@@ -248,10 +258,13 @@ public final class ComputerUseService {return snapshotResult(for: try refreshSnapshot(for: query), style: .actionResult)}- InputSimulation.prepareAppForGlobalPointerInput(snapshot.app)- try InputSimulation.dragGlobally(- from: try screenshotToGlobalPoint(snapshot: snapshot, x: fromX, y: fromY),- to: try screenshotToGlobalPoint(snapshot: snapshot, x: toX, y: toY)+ let start = try screenshotToGlobalPoint(snapshot: snapshot, x: fromX, y: fromY)+ let end = try screenshotToGlobalPoint(snapshot: snapshot, x: toX, y: toY)+ try performDragEvent(+ from: start,+ to: end,+ targetDescription: "from=(\(Int(fromX)), \(Int(fromY))) to=(\(Int(toX)), \(Int(toY)))",+ snapshot: snapshot)return snapshotResult(for: try refreshSnapshot(for: query), style: .actionResult)}@@ -657,6 +670,55 @@ public final class ComputerUseService {)}+ private func integralScrollPageCount(_ pages: Double) -> Int? {+ let rounded = pages.rounded(.toNearestOrAwayFromZero)+ guard abs(pages - rounded) < 0.000001 else {+ return nil+ }+ return max(Int(rounded), 1)+ }++ private func performScrollEvent(+ at point: CGPoint,+ direction: String,+ pages: Double,+ targetDescription: String,+ snapshot: AppSnapshot+ ) throws {+ if globalPointerFallbacksEnabled(environment: ProcessInfo.processInfo.environment) {+ debugInputFallback(+ tool: "scroll",+ targetDescription: targetDescription,+ snapshot: snapshot+ )+ InputSimulation.prepareAppForGlobalPointerInput(snapshot.app)+ try InputSimulation.scrollGlobally(at: point, direction: direction, pages: pages)+ return+ }++ try InputSimulation.scrollTargeted(at: point, direction: direction, pages: pages, pid: snapshot.app.pid)+ }++ private func performDragEvent(+ from start: CGPoint,+ to end: CGPoint,+ targetDescription: String,+ snapshot: AppSnapshot+ ) throws {+ if globalPointerFallbacksEnabled(environment: ProcessInfo.processInfo.environment) {+ debugInputFallback(+ tool: "drag",+ targetDescription: targetDescription,+ snapshot: snapshot+ )+ InputSimulation.prepareAppForGlobalPointerInput(snapshot.app)+ try InputSimulation.dragGlobally(from: start, to: end)+ return+ }++ try InputSimulation.dragTargeted(from: start, to: end, pid: snapshot.app.pid)+ }+private func performGlobalClickFallback(at point: CGPoint,button: MouseButtonKind,diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swiftindex 9f8ff5f..da66df1 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ComputerUseToolDispatcher.swift@@ -33,7 +33,7 @@ public final class ComputerUseToolDispatcher {app: requireString("app", in: arguments),direction: requireString("direction", in: arguments),elementIndex: requireString("element_index", in: arguments),- pages: Int(optionalDouble("pages", in: arguments) ?? 1)+ pages: optionalDouble("pages", in: arguments) ?? 1)case "drag":return try service.drag(@@ -79,7 +79,7 @@ public final class ComputerUseToolDispatcher {}private func requireString(_ key: String, in arguments: [String: Any]) throws -> String {- guard let value = arguments[key] as? String else {+ guard let value = arguments[key] as? String, !value.isEmpty else {throw ComputerUseError.missingArgument(key)}diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Errors.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Errors.swiftindex 7aecbfe..0e8a3e4 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Errors.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/Errors.swift@@ -32,6 +32,6 @@ public enum ComputerUseError: Error, LocalizedError {extension ComputerUseError {static func missingArgument(_ name: String) -> ComputerUseError {- .invalidArguments("missing argument '\(name)'")+ .message("Missing required argument: \(name)")}}diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/FixtureBridge.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/FixtureBridge.swiftindex c99f549..14cff5d 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/FixtureBridge.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/FixtureBridge.swift@@ -62,7 +62,7 @@ public struct FixtureCommand: Codable, Sendable {public let toX: Double?public let toY: Double?public let direction: String?- public let pages: Int?+ public let pages: Double?public init(kind: String,@@ -73,7 +73,7 @@ public struct FixtureCommand: Codable, Sendable {toX: Double? = nil,toY: Double? = nil,direction: String? = nil,- pages: Int? = nil+ pages: Double? = nil) {self.kind = kindself.identifier = identifierdiff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/InputSimulation.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/InputSimulation.swiftindex 1373db0..a5699ba 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/InputSimulation.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/InputSimulation.swift@@ -65,7 +65,17 @@ enum InputSimulation {}}- static func scrollGlobally(at point: CGPoint, direction: String, pages: Int) throws {+ static func scrollTargeted(at point: CGPoint, direction: String, pages: Double, pid: pid_t) throws {+ guard let event = CGEvent(scrollWheelEvent2Source: nil, units: .line, wheelCount: 2, wheel1: wheel1(direction: direction, pages: pages), wheel2: wheel2(direction: direction, pages: pages), wheel3: 0) else {+ throw ComputerUseError.message("Failed to create scroll event.")+ }++ event.location = point+ event.postToPid(pid)+ Thread.sleep(forTimeInterval: 0.1)+ }++ static func scrollGlobally(at point: CGPoint, direction: String, pages: Double) throws {guard let event = CGEvent(scrollWheelEvent2Source: nil, units: .line, wheelCount: 2, wheel1: wheel1(direction: direction, pages: pages), wheel2: wheel2(direction: direction, pages: pages), wheel3: 0) else {throw ComputerUseError.message("Failed to create scroll event.")}@@ -75,6 +85,26 @@ enum InputSimulation {Thread.sleep(forTimeInterval: 0.1)}+ static func dragTargeted(from start: CGPoint, to end: CGPoint, pid: pid_t) throws {+ guard let source = CGEventSource(stateID: .combinedSessionState) else {+ throw ComputerUseError.message("Failed to create targeted event source.")+ }++ try postMouseEventToPid(type: .mouseMoved, source: source, point: start, button: .left, clickState: 1, pid: pid)+ try postMouseEventToPid(type: .leftMouseDown, source: source, point: start, button: .left, clickState: 1, pid: pid)++ for step in 1...10 {+ let progress = CGFloat(step) / 10+ let point = CGPoint(+ x: start.x + ((end.x - start.x) * progress),+ y: start.y + ((end.y - start.y) * progress)+ )+ try postMouseEventToPid(type: .leftMouseDragged, source: source, point: point, button: .left, clickState: 1, pid: pid)+ }++ try postMouseEventToPid(type: .leftMouseUp, source: source, point: end, button: .left, clickState: 1, pid: pid)+ }+static func dragGlobally(from start: CGPoint, to end: CGPoint) throws {guard let source = CGEventSource(stateID: .hidSystemState) else {throw ComputerUseError.message("Failed to create HID event source.")@@ -158,6 +188,16 @@ enum InputSimulation {Thread.sleep(forTimeInterval: 0.03)}+ private static func postMouseEventToPid(type: CGEventType, source: CGEventSource, point: CGPoint, button: CGMouseButton, clickState: Int, pid: pid_t) throws {+ guard let event = CGEvent(mouseEventSource: source, mouseType: type, mouseCursorPosition: point, mouseButton: button) else {+ throw ComputerUseError.message("Failed to create mouse event \(type.rawValue).")+ }++ event.setIntegerValueField(.mouseEventClickState, value: Int64(clickState))+ event.postToPid(pid)+ Thread.sleep(forTimeInterval: 0.03)+ }+private static func raiseAppWindowViaAccessibility(pid: pid_t) -> Bool {let appElement = AXUIElementCreateApplication(pid)guard let window = preferredWindow(for: appElement) else {@@ -236,25 +276,31 @@ enum InputSimulation {return value as? [AXUIElement]}- private static func wheel1(direction: String, pages: Int) -> Int32 {+ private static func wheel1(direction: String, pages: Double) -> Int32 {switch direction {case "up":- return Int32(12 * max(pages, 1))+ return scrollWheelDelta(for: pages)case "down":- return Int32(-12 * max(pages, 1))+ return -scrollWheelDelta(for: pages)default:return 0}}- private static func wheel2(direction: String, pages: Int) -> Int32 {+ private static func wheel2(direction: String, pages: Double) -> Int32 {switch direction {case "left":- return Int32(12 * max(pages, 1))+ return scrollWheelDelta(for: pages)case "right":- return Int32(-12 * max(pages, 1))+ return -scrollWheelDelta(for: pages)default:return 0}}++ private static func scrollWheelDelta(for pages: Double) -> Int32 {+ let rawValue = (12.0 * pages).rounded(.toNearestOrAwayFromZero)+ let clamped = min(Double(Int32.max), max(1, rawValue))+ return Int32(clamped)+ }}diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/MCPServer.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/MCPServer.swiftindex ccec168..575bc71 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/MCPServer.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/MCPServer.swift@@ -66,6 +66,11 @@ public final class StdioMCPServer {)case "notifications/initialized":return nil+ case "notifications/turn-ended":+ VisualCursorSupport.performOnMain {+ SoftwareCursorOverlay.reset()+ }+ return nilcase "ping":return try encodeJSONRPCResult(id: id, result: [:])case "tools/list":diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swiftindex 428e30d..fd5fab3 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/OpenComputerUseCLI.swift@@ -7,7 +7,7 @@ public enum OpenComputerUseCLICommand: Equatable {case listAppscase snapshot(app: String)case call(OpenComputerUseCallInvocation)- case turnEnded+ case turnEnded(payload: String?)case help(command: String?)case version}@@ -61,7 +61,7 @@ public func parseOpenComputerUseCLI(arguments: [String]) throws -> OpenComputerUcase "call":return try parseCall(arguments: Array(arguments.dropFirst()))case "turn-ended":- return try parseSimpleCommand(name: "turn-ended", arguments: Array(arguments.dropFirst()), result: .turnEnded)+ return try parseTurnEnded(arguments: Array(arguments.dropFirst()))case "snapshot":return try parseSnapshot(arguments: Array(arguments.dropFirst()))default:@@ -89,7 +89,7 @@ public func openComputerUseHelpText(command: String? = nil) -> String {list-apps Print running or recently used apps.snapshot <app> Print the current accessibility snapshot for an app.call <tool> Call one tool, or run a JSON array of tool calls.- turn-ended Acknowledge the host turn boundary.+ turn-ended Notify the running MCP process that the host turn ended.help [command] Show general or command-specific help.version Print the CLI version.@@ -153,9 +153,10 @@ public func openComputerUseHelpText(command: String? = nil) -> String {case "turn-ended":return """Usage:- open-computer-use turn-ended+ open-computer-use turn-ended [--previous-notify <argv>] [payload]- Notify the local CLI that the current host turn has ended.+ Notify a running local MCP process that the current host turn has ended.+ Codex legacy notify appends the after-agent JSON payload as the last argument."""case "version":return """@@ -198,6 +199,43 @@ private func parseSimpleCommand(throw OpenComputerUseCLIError(message: "\(name) does not accept any arguments", helpCommand: name)}+private func parseTurnEnded(arguments: [String]) throws -> OpenComputerUseCLICommand {+ if arguments.count == 1, let option = arguments.first, option == "-h" || option == "--help" {+ return .help(command: "turn-ended")+ }++ var payload: String?+ var index = 0+ while index < arguments.count {+ let argument = arguments[index]++ switch argument {+ case "--previous-notify":+ let valueIndex = index + 1+ guard valueIndex < arguments.count else {+ throw OpenComputerUseCLIError(message: "--previous-notify requires a value", helpCommand: "turn-ended")+ }+ index = valueIndex+ case "-h", "--help":+ throw OpenComputerUseCLIError(message: "turn-ended help must be requested as `open-computer-use turn-ended --help`", helpCommand: "turn-ended")+ default:+ if argument.hasPrefix("-") {+ throw OpenComputerUseCLIError(message: "Unknown turn-ended option: \(argument)", helpCommand: "turn-ended")+ }++ guard payload == nil else {+ throw OpenComputerUseCLIError(message: "turn-ended accepts at most one payload argument", helpCommand: "turn-ended")+ }++ payload = argument+ }++ index += 1+ }++ return .turnEnded(payload: payload)+}+private func parseSnapshot(arguments: [String]) throws -> OpenComputerUseCLICommand {if arguments.count == 1 {let value = arguments[0]diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swiftindex 482276a..58149ce 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/SoftwareCursorOverlay.swift@@ -68,6 +68,26 @@ func visualCursorScreenStateVelocity(CGVector(dx: velocity.dx, dy: velocity.dy * yAxisMultiplier)}+func visualCursorPostInteractionIdleTimeout() -> TimeInterval {+ 5 * 60+}++public let openComputerUseTurnEndedNotificationName = Notification.Name("com.ifuryst.opencomputeruse.turn-ended")++public func postOpenComputerUseTurnEndedNotification() {+ DistributedNotificationCenter.default().postNotificationName(+ openComputerUseTurnEndedNotificationName,+ object: nil,+ userInfo: nil,+ deliverImmediately: true+ )+}++@MainActor+public func resetOpenComputerUseVisualCursor() {+ SoftwareCursorOverlay.reset()+}+struct CursorTargetWindow: Equatable, Sendable {let windowID: CGWindowIDlet layer: Int@@ -164,7 +184,7 @@ enum SoftwareCursorOverlay {restingTipPosition = constrainedTargetanimateClickPulse(at: constrainedTarget, clickCount: max(clickCount, 1), mouseButton: mouseButton)startIdleAnimation()- scheduleHide(after: 0.55)+ scheduleHide(after: visualCursorPostInteractionIdleTimeout())}static func settle(at targetPoint: CGPoint, in targetWindow: CursorTargetWindow?) {@@ -183,7 +203,7 @@ enum SoftwareCursorOverlay {clickProgress: 0)startIdleAnimation()- scheduleHide(after: 0.45)+ scheduleHide(after: visualCursorPostInteractionIdleTimeout())}static func reset() {diff --git a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swiftindex b2a8e29..cf67c95 100644--- a/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift+++ b/packages/OpenComputerUseKit/Sources/OpenComputerUseKit/ToolDefinitions.swift@@ -115,7 +115,7 @@ public enum ToolDefinitions {"app": stringProperty(description: "App name or bundle identifier"),"direction": stringProperty(description: "Scroll direction: up, down, left, or right"),"element_index": stringProperty(description: "Element identifier"),- "pages": integerProperty(description: "Number of page scroll actions. Defaults to 1"),+ "pages": numberProperty(description: "Number of pages to scroll. Fractional values are supported. Defaults to 1"),],required: ["app", "element_index", "direction"])diff --git a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swiftindex 26a3bc6..0d7373e 100644--- a/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift+++ b/packages/OpenComputerUseKit/Tests/OpenComputerUseKitTests/OpenComputerUseKitTests.swift@@ -38,6 +38,17 @@ final class OpenComputerUseKitTests: XCTestCase {)}+ func testCLIRecognizesTurnEndedNotifyPayload() throws {+ let payload = #"{"type":"agent-turn-complete","turn-id":"12345"}"#++ XCTAssertEqual(try parseOpenComputerUseCLI(arguments: ["turn-ended"]), .turnEnded(payload: nil))+ XCTAssertEqual(try parseOpenComputerUseCLI(arguments: ["turn-ended", payload]), .turnEnded(payload: payload))+ XCTAssertEqual(+ try parseOpenComputerUseCLI(arguments: ["turn-ended", "--previous-notify", #"["/bin/true"]"#, payload]),+ .turnEnded(payload: payload)+ )+ }+func testCLIRequiresSnapshotArgument() {XCTAssertThrowsError(try parseOpenComputerUseCLI(arguments: ["snapshot"])) { error inXCTAssertEqual(@@ -268,6 +279,13 @@ final class OpenComputerUseKitTests: XCTestCase {XCTAssertEqual(instructions, computerUseServerInstructions)}+ func testMCPAcceptsTurnEndedNotificationWithoutResponse() {+ let server = StdioMCPServer(service: ComputerUseService())+ let response = server.handle(line: #"{"jsonrpc":"2.0","method":"notifications/turn-ended","params":{"type":"agent-turn-complete"}}"#)++ XCTAssertNil(response)+ }+func testWindowRelativeFrameUsesSharedGlobalCoordinates() {let window = CGRect(x: 1486, y: 556, width: 919, height: 644)let child = CGRect(x: 1486, y: 556, width: 919, height: 644)@@ -302,6 +320,45 @@ final class OpenComputerUseKitTests: XCTestCase {((tools["click"]?.inputSchema["properties"] as? [String: [String: Any]])?["mouse_button"]?["enum"] as? [String]) ?? [],["left", "right", "middle"])+ let scrollPages = (tools["scroll"]?.inputSchema["properties"] as? [String: [String: Any]])?["pages"]+ XCTAssertEqual(scrollPages?["type"] as? String, "number")+ XCTAssertEqual(+ scrollPages?["description"] as? String,+ "Number of pages to scroll. Fractional values are supported. Defaults to 1"+ )+ }++ func testDispatcherMissingArgumentsMatchOfficialToolText() {+ let dispatcher = ComputerUseToolDispatcher()+ let result = dispatcher.callToolAsResult(name: "type_text", arguments: ["app": "Sublime Text"])+ let emptyResult = dispatcher.callToolAsResult(name: "type_text", arguments: ["app": "Sublime Text", "text": ""])++ XCTAssertTrue(result.isError)+ XCTAssertEqual(result.primaryText, "Missing required argument: text")+ XCTAssertTrue(emptyResult.isError)+ XCTAssertEqual(emptyResult.primaryText, "Missing required argument: text")+ }++ func testScrollRejectsInvalidDirectionWithOfficialMessage() {+ let dispatcher = ComputerUseToolDispatcher()+ let result = dispatcher.callToolAsResult(+ name: "scroll",+ arguments: ["app": "Sublime Text", "element_index": "14", "direction": "sideways", "pages": 1]+ )++ XCTAssertTrue(result.isError)+ XCTAssertEqual(result.primaryText, "Invalid scroll direction: sideways")+ }++ func testScrollRejectsNonPositivePagesWithOfficialMessage() {+ let dispatcher = ComputerUseToolDispatcher()+ let result = dispatcher.callToolAsResult(+ name: "scroll",+ arguments: ["app": "Sublime Text", "element_index": "14", "direction": "down", "pages": 0.0]+ )++ XCTAssertTrue(result.isError)+ XCTAssertEqual(result.primaryText, "pages must be > 0")}func testSnapshotRenderedTextStartsDirectlyWithAppHeader() {@@ -481,6 +538,11 @@ final class OpenComputerUseKitTests: XCTestCase {XCTAssertEqual(start.y, geometry.tipAnchor.y, accuracy: 0.0001)}+ func testVisualCursorKeepsPostInteractionIdleStateLongEnoughForFollowupTools() {+ XCTAssertEqual(visualCursorPostInteractionIdleTimeout(), 5 * 60)+ XCTAssertGreaterThan(visualCursorPostInteractionIdleTimeout(), 30)+ }+func testVisualCursorRuntimeMapsAppKitUpwardMotionToCursorMotionScreenState() {let renderBaseHeading = visualCursorRenderBaseHeading(artworkNeutralHeading: SoftwareCursorGlyphMetrics.targetNeutralHeadingdiff --git a/scripts/npm/build-packages.mjs b/scripts/npm/build-packages.mjsindex 2ba4faf..4cab4f0 100644--- a/scripts/npm/build-packages.mjs+++ b/scripts/npm/build-packages.mjs@@ -155,7 +155,7 @@ Commands:list-apps Print running or recently used apps.snapshot <app> Print the current accessibility snapshot for an app.call <tool> Call one tool, or run a JSON array of tool calls.- turn-ended Acknowledge the host turn boundary.+ turn-ended Notify the running MCP process that the host turn ended.install-claude-mcp Install the MCP server into ~/.claude.json for this project.install-codex-mcp Install the MCP server into ~/.codex/config.toml.install-codex-plugin Install this npm package into the local Codex plugin cache.