diff --git a/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.i18n.yaml b/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.i18n.yaml index dd561e1a74..2bbea41110 100644 --- a/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.i18n.yaml +++ b/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.i18n.yaml @@ -9,8 +9,8 @@ en: 37252a5d19c7fe09 zh: f1b33b7da3935155 /cua-reports-held-input-after-programs/change: - en: cf9c1397e07dffa5 - zh: f1cce9fadf321d43 + en: 80ab79f78e26ff43 + zh: e6ba8ac29eaabf50 /cua-reports-held-input-after-programs/migration: en: c26899347e7a24c9 zh: ae78a24c58d6f80f diff --git a/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.md b/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.md index b26416c840..e04619385b 100644 --- a/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.md +++ b/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.md @@ -8,7 +8,7 @@ English | [中文](guide.zh.md) ## Change -On macOS and Windows, explicit `sendKeyEvent('down')` and `toggleMouse('down')` remain held across programs and turns until an explicit `up`. Normal completion does not release them. After a successful `run_code` or `cua_run_code`, a system reminder lists any remaining keys and mouse buttons, their application or window and actual input mode. Program failure, user stop, connection closure, environment reset and disposal release owned input in reverse dispatch order. Complete `pressKey`, `typeText`, `click` and `drag` actions keep their operation-local cleanup. DSH and MCP both preserve input after successful programs. A client pause between completed MCP calls is not observable by the server and can leave input held. On Windows, cleanup sends an up for each input the helper still holds. If you also hold the same key or button, that up may interrupt your press. A focus change sends the up to the desktop without reactivating the original window. +On macOS and Windows, explicit `sendKeyEvent('down')` and `toggleMouse('down')` remain held across programs and turns until an explicit `up`. Normal completion does not release them. After a successful `run_code` or `cua_run_code`, a system reminder lists any remaining keys and mouse buttons, their application or window and actual input mode. Program failure, user stop, environment reset and disposal request release in reverse dispatch order. On disconnect the helper attempts a final release. Windows silently discards the disconnected owner’s records if that attempt fails or times out. Complete `pressKey`, `typeText`, `click` and `drag` actions keep their operation-local cleanup. DSH and MCP both preserve input after successful programs. A client pause between completed MCP calls is not observable by the server and can leave input held. On Windows, cleanup sends an up for each input the helper still holds. If you also hold the same key or button, that up may interrupt your press. A focus change sends the up to the desktop without reactivating the original window. ## Migration diff --git a/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.zh.md b/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.zh.md index f776b6de47..96527ce8c3 100644 --- a/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.zh.md +++ b/docs/upgrade-guide/v0.2.2-rc.5/cua-held-inputs/guide.zh.md @@ -8,7 +8,7 @@ description: macOS 和 Windows 的 CUA 显式输入跨程序和回合保持, ## 变更 -macOS 和 Windows 的显式 `sendKeyEvent('down')` 和 `toggleMouse('down')` 跨程序、跨回合保持,直到显式 `up`。正常结束不释放它们。成功结束的 `run_code` 或 `cua_run_code` 通过 system reminder 列出剩余键盘键和鼠标按钮、所属应用或窗口及实际输入方式。程序失败、用户停止、断连、环境重置和销毁按派发顺序的反序释放所属输入。完整的 `pressKey`、`typeText`、`click` 和 `drag` 保持操作内清理。DSH 和 MCP 都在程序成功后保持输入。客户端在两次 MCP 调用之间暂停时,服务端无法观察到,输入可能继续按住。Windows 清理时会为 helper 仍持有的输入发送 up。如果你也按住同一个键或按钮,这次 up 可能打断你的按压。焦点变化后,up 发往当前桌面,原窗口不会被重新激活。 +macOS 和 Windows 的显式 `sendKeyEvent('down')` 和 `toggleMouse('down')` 跨程序、跨回合保持,直到显式 `up`。正常结束不释放它们。成功结束的 `run_code` 或 `cua_run_code` 通过 system reminder 列出剩余键盘键和鼠标按钮、所属应用或窗口及实际输入方式。程序失败、用户停止、环境重置和销毁时会请求按派发顺序的反序释放。断连时,helper 会最后尝试释放。若失败或超时,Windows helper 会静默丢弃该连接的持有记录。完整的 `pressKey`、`typeText`、`click` 和 `drag` 保持操作内清理。DSH 和 MCP 都在程序成功后保持输入。客户端在两次 MCP 调用之间暂停时,服务端无法观察到,输入可能继续按住。Windows 清理时会为 helper 仍持有的输入发送 up。如果你也按住同一个键或按钮,这次 up 可能打断你的按压。焦点变化后,up 发往当前桌面,原窗口不会被重新激活。 ## 迁移 diff --git a/packages/experimental/cua-windows/README.i18n.yaml b/packages/experimental/cua-windows/README.i18n.yaml index 1d4df0039b..d8f5691b5c 100644 --- a/packages/experimental/cua-windows/README.i18n.yaml +++ b/packages/experimental/cua-windows/README.i18n.yaml @@ -36,8 +36,8 @@ en: 38b3250d6ae0f3d6 zh: 33d056c416e11d75 /deepseek-ai-dsh-cua-windows/model-experience/explicit-application-and-window-operations/what-the-model-sees: - en: d1c83b32631c2146 - zh: fff241be17b13885 + en: 8949441c259efd34 + zh: 5526a527eb02a0ac /deepseek-ai-dsh-cua-windows/model-experience/explicit-application-and-window-operations/token-effect: en: 39eebd53ee226af7 zh: ba7b352cf1e23c3c @@ -45,8 +45,8 @@ en: db3e2957041fafbb zh: 34f953887dff37f7 /deepseek-ai-dsh-cua-windows/known-limitations-and-deferred-work: - en: d778c226c2a8f2bd - zh: 27b06182ebf4ff66 + en: ff80ed2855470176 + zh: d3ff1f845594caa1 /deepseek-ai-dsh-cua-windows/known-limitations-and-deferred-work/dev-note: en: 0a1253c6f7b5e8b9 zh: 9f56528562c7c914 diff --git a/packages/experimental/cua-windows/README.md b/packages/experimental/cua-windows/README.md index 8bf999d3a6..9b3fb24228 100644 --- a/packages/experimental/cua-windows/README.md +++ b/packages/experimental/cua-windows/README.md @@ -65,7 +65,7 @@ Each result contains `id`, `displayName`, and `isRunning`. The ID is an AUMID, i #### What the model sees -The program receives application and window identifiers, observations, and action results. Selection alone does not provide an accessibility tree. After a successful program, a reminder lists any held keys and buttons with their window and desktop input mode. While one connection holds a key or button, another connection can use different keys or buttons. Program failure, cancellation, reset and disconnect release the input held by that connection in reverse dispatch order. +The program receives application and window identifiers, observations, and action results. Selection alone does not provide an accessibility tree. After a successful program, a reminder lists any held keys and buttons with their window and desktop input mode. While one connection holds a key or button, another connection can use different keys or buttons. Program failure, cancellation and reset request release in reverse dispatch order. At disconnect, the helper makes a final bounded release attempt. If it fails or times out, the helper silently discards that connection’s records. #### Token effect @@ -83,7 +83,7 @@ Inspected results append to model history. Retaining an App, Window, or returned - Hover, click, scroll and drag use the system pointer. `requireSystemInputApproval` does not prompt separately for Windows pointer operations. - Drag checks the topmost window only at its starting point. An overlay from another application along the path or at the destination can receive the drop even while the selected window stays in the foreground. - Held-input reminders and cleanup use the helper's own dispatches. If you press the same key or button while the helper holds it, its next up can also interrupt your press. -- Windows routes input through the desktop. After focus changes or the original window closes, a confirmed release means the desktop accepted the up. The original window may not receive the event. Releasing a held input does not check the current foreground window or lock state. The release uses the saved up event and reports `foregroundChanged: null` for an explicit up. If Windows refuses the up during cleanup, further CUA input for the task is blocked. Inspect the desktop before starting another task. +- Windows routes input through the desktop. After focus changes or the original window closes, a confirmed release means the desktop accepted the up. The original window may not receive the event. Releasing a held input does not check the current foreground window or lock state. The release uses the saved up event and reports `foregroundChanged: null` for an explicit up. If Windows refuses an explicit cleanup request, further CUA input for the task is blocked. Inspect the desktop before starting another task. - Cleanup of temporary input inside complete actions does not check each key or button release. If an input remains held after a failure, release it manually before continuing. - Helper identity hashes only the exe. Different DLLs with the same apphost can reuse the old service. Stop Hosts using the same output directory before rebuilding to avoid locked files. - The Windows handshake requires a positive `maxClickHoldMs`. With zero, it fails with `INVALID_CONFIG` before ordinary clicks or status queries can run. diff --git a/packages/experimental/cua-windows/README.zh.md b/packages/experimental/cua-windows/README.zh.md index 8f019d5ee8..5d4f5e18fa 100644 --- a/packages/experimental/cua-windows/README.zh.md +++ b/packages/experimental/cua-windows/README.zh.md @@ -65,7 +65,7 @@ kind: "package-reference" #### 模型看到什么 -程序可以读取应用和窗口标识、观察结果及动作结果。仅执行选择操作不会提供辅助功能树。程序成功后,提醒会列出仍按住的键和鼠标按钮、所属窗口和桌面输入方式。一条连接持有按键或鼠标按钮时,其他连接仍可使用不同的键或按钮。程序异常、取消、重置和断连时,按派发顺序的反序释放这条连接持有的输入。 +程序可以读取应用和窗口标识、观察结果及动作结果。仅执行选择操作不会提供辅助功能树。程序成功后,提醒会列出仍按住的键和鼠标按钮、所属窗口和桌面输入方式。一条连接持有按键或鼠标按钮时,其他连接仍可使用不同的键或按钮。程序异常、取消或重置时会请求按派发顺序的反序释放。断连时,helper 会在关闭时限内最后尝试一次。失败或超时后,它会静默丢弃这条连接的持有记录。 #### Token 影响 @@ -83,7 +83,7 @@ kind: "package-reference" - 悬停、点击、滚动和拖拽使用系统指针。`requireSystemInputApproval` 不会为 Windows 操作弹出单独的指针授权提示。 - 拖拽只检查起点处最上层的窗口。若其他应用遮住路径或终点,即使目标仍在前台,也可能把内容拖到其他应用。 - 持有提醒和清理只依据 helper 自己派发的输入。如果你也按住同一个键或按钮,helper 之后发送的 up 可能打断你的按压。 -- Windows 通过桌面派发输入。焦点变化或原窗口关闭后,确认释放表示桌面接受了 up,原窗口可能收不到该事件。释放时直接发送保存的 up 事件,无需检查当前前台窗口或锁屏状态。显式 up 返回 `foregroundChanged: null`。若 Windows 在清理时拒绝 up,本任务不能继续使用 CUA。请先检查桌面,再开始新任务。 +- Windows 通过桌面派发输入。焦点变化或原窗口关闭后,确认释放表示桌面接受了 up,原窗口可能收不到该事件。释放时直接发送保存的 up 事件,无需检查当前前台窗口或锁屏状态。显式 up 返回 `foregroundChanged: null`。若 Windows 在处理显式清理请求时拒绝 up,本任务不能继续使用 CUA。请先检查桌面,再开始新任务。 - 清理完整动作内的临时输入时,helper 不检查每个按键或鼠标按钮的释放结果。操作失败后如有按键或按钮仍处于按下状态,请先手动释放。 - helper 的身份摘要只覆盖 exe。同一 apphost 搭配不同 DLL 时可能复用旧服务。重新构建前请先关闭使用同一输出目录的 Host,避免文件被占用。 - Windows 握手要求 `maxClickHoldMs` 为正整数。设为 0 会使连接以 `INVALID_CONFIG` 失败,连普通点击和状态查询也不可用。 diff --git a/packages/experimental/cua-windows/native/entry/DesktopExecutor.cs b/packages/experimental/cua-windows/native/entry/DesktopExecutor.cs index a374db5376..a3fcba8c11 100644 --- a/packages/experimental/cua-windows/native/entry/DesktopExecutor.cs +++ b/packages/experimental/cua-windows/native/entry/DesktopExecutor.cs @@ -291,14 +291,8 @@ internal sealed class DesktopExecutor(MtaDispatcher mta, StaDispatcher sta) : IA finally { queue.Release(); } } - internal async Task ReleaseConnection(ClientState state, int graceMs) - { - if (!inputs.HasConnection(state.Connection)) return; - using var deadline = new CancellationTokenSource(graceMs); - await queue.WaitAsync(deadline.Token); - try { inputs.Release(state.Connection, deadline.Token); } - finally { queue.Release(); } - } + internal Task ReleaseConnection(ClientState state, int graceMs) => + inputs.ReleaseOnDisconnect(state.Connection, queue, graceMs); public ValueTask DisposeAsync() { diff --git a/packages/experimental/cua-windows/native/entry/HeldInputs.cs b/packages/experimental/cua-windows/native/entry/HeldInputs.cs index 56ca5b8807..1ba8f89d10 100644 --- a/packages/experimental/cua-windows/native/entry/HeldInputs.cs +++ b/packages/experimental/cua-windows/native/entry/HeldInputs.cs @@ -71,9 +71,23 @@ internal sealed class HeldInputs(Action send) return pressed.Where(press => press.Connection == connection).Select(press => press.Describe()).ToArray(); } - internal bool HasConnection(Guid connection) + internal async Task ReleaseOnDisconnect(Guid connection, SemaphoreSlim desktopQueue, int graceMs) { - lock (gate) return pressed.Exists(press => press.Connection == connection); + lock (gate) + if (!pressed.Exists(press => press.Connection == connection)) return; + + using var deadline = new CancellationTokenSource(graceMs); + try + { + await desktopQueue.WaitAsync(deadline.Token); + try { Release(connection, deadline.Token); } + finally { desktopQueue.Release(); } + } + catch (Exception error) + { + _ = error; // The disconnected owner cannot retry or receive a cleanup result. + lock (gate) pressed.RemoveAll(press => press.Connection == connection); + } } internal object[] Release(Guid connection, CancellationToken cancellation) diff --git a/packages/experimental/cua-windows/native/entry/NativeServer.cs b/packages/experimental/cua-windows/native/entry/NativeServer.cs index 9310b1dd27..2b4941c723 100644 --- a/packages/experimental/cua-windows/native/entry/NativeServer.cs +++ b/packages/experimental/cua-windows/native/entry/NativeServer.cs @@ -169,12 +169,7 @@ internal static class NativeServer finally { cancellation?.Dispose(); - try { await executor.ReleaseConnection(state, cleanupTimeoutMs); } - catch (Exception error) - { - Report("INPUT_CLEANUP_UNCONFIRMED", error); - throw; - } + await executor.ReleaseConnection(state, cleanupTimeoutMs); } state.Clear(); if (closeRequested) diff --git a/packages/experimental/cua-windows/native/tests/HeldInputChecks.cs b/packages/experimental/cua-windows/native/tests/HeldInputChecks.cs index d711dd6c7f..3b3b017ef3 100644 --- a/packages/experimental/cua-windows/native/tests/HeldInputChecks.cs +++ b/packages/experimental/cua-windows/native/tests/HeldInputChecks.cs @@ -78,8 +78,24 @@ internal static class HeldInputChecks check(described.GetArrayLength() == 1 && described[0].GetProperty("key").GetString() == "w", "The reminder still reports only the helper's W down"); var count = events.Count; - check(inputs.Release(a, default).Length == 1 && events.Skip(count).SequenceEqual(["87:up"]), + using var desktopQueue = new SemaphoreSlim(1, 1); + inputs.ReleaseOnDisconnect(a, desktopQueue, 1000).GetAwaiter().GetResult(); + check(inputs.Get(a).Length == 0 && events.Skip(count).SequenceEqual(["87:up"]), "Disconnect retries the helper's W release and leaves D alone"); - check(!inputs.HasConnection(a), "Accepted release removes the connection's last hold"); + + Key(b, 68, "d"); + foreach (var occupied in new[] { false, true }) + { + Key(a, 87, "w"); + if (occupied) desktopQueue.Wait(); + blocked = !occupied; + inputs.ReleaseOnDisconnect(a, desktopQueue, occupied ? 0 : 1000).GetAwaiter().GetResult(); + blocked = false; + check(inputs.Get(a).Length == 0 && inputs.Get(b).Length == 1, + "Refused or expired disconnect cleanup drops only the disconnected owner's records"); + if (occupied) desktopQueue.Release(); + } + check(Key(b, 87, "w"), "The remaining connection can use W after disconnect cleanup fails"); + inputs.Release(b, default); } }