Feature: Add window info RPC for foreground checks and window activation

Add a capability-gated main-connection RPC (COMMAND_MCP_WINDOW_INFO=179 /
TOKEN_MCP_WINDOW_INFO=180) that returns visible top-level windows with UTF-8
titles, screen rectangles, foreground flag and z-order, so MCP can verify
focus before injecting input. New tool get_foreground_window; host_list_windows
switches to the richer fields; host_control_window and operate_window gain
action=activate; remote_keyboard and remote_mouse gain expect_hwnd,
require_foreground and report_foreground. Old clients keep the previous
behavior: the RPC is refused up front via CLIENT_CAP_WINDOW_INFO.

The client caps a response at 96 windows (about 101 KB, under MAX_SEND_BUFFER).
Signal the cut-off in the mode byte (0x80) instead of silently dropping windows:
host_list_windows now reports truncated=true and says the list is incomplete,
and activate verification reports state=unknown with reason=list_truncated
rather than claiming the window is gone. expect_hwnd is checked only after the
session is validated, so an invalid session_id no longer burns a window RPC and
no longer reports a window error for a session that does not exist. Nullable
output fields (foreground, window) are declared as ["object","null"] so strict
clients do not reject responses.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-10 15:09:24 +01:00
1 parent c7e23f750d
commit b2c0d81396
18 files changed
+1298 -68

No files matched your search

+4 -2
View File
@@ -97,8 +97,10 @@ AI 无法「看懂」视频流。把 25fps 的远程画面直接丢给视觉模
| `get_screenshot`(**已有,复用**) | Observe | `id`;可选 `max_width`(64..1920) | JPEG 图片(见 §5) |
| `remote_open` | 建立控制会话(屏幕子连接) | `id`;可选 `timeout_ms` | `session_id`(32hex)、`screen_w`/`screen_h`(物理虚拟桌面像素) |
| `remote_close` | 关闭会话 | `id`、`session_id` | `closed`(bool) |
| `remote_mouse` | 注入鼠标 | `id`、`session_id`、`action`、`x`、`y`(+ 按 action 需 `x2`/`y2`/`button`/`delta`/`clicks`) | `{}`(成功即空对象) |
| `remote_keyboard` | 注入键盘 | `id`、`session_id`、`action`(+ 按 action 需 `text`/`key`/`modifiers`) | `{}` |
| `remote_mouse` | 注入鼠标 | `id`、`session_id`、`action`、`x`、`y`(+ 按 action 需 `x2`/`y2`/`button`/`delta`/`clicks`;可选 `expect_hwnd`/`require_foreground`/`report_foreground`) | `{}`;带 `report_foreground`(或给了 `expect_hwnd`)时含 `foreground` |
| `remote_keyboard` | 注入键盘 | `id`、`session_id`、`action`(+ 按 action 需 `text`/`key`/`modifiers`;可选 `expect_hwnd`/`require_foreground`/`report_foreground`) | `{}`;同上 |
> **焦点校验(2026-11-10 增补)**:`expect_hwnd` 会在注入前用 `CLIENT_CAP_WINDOW_INFO` 的窗口信息 RPC 确认目标窗口仍在可见列表;`require_foreground=true` 还要求它已是前台,否则不发注入(`-32000`)。`report_foreground` 在注入后回报前台窗口(`structuredContent.foreground`),给了 `expect_hwnd` 时默认开启。仅新 Windows 客户端支持,其余客户端返回 `-32005`;会话本身仍走屏幕子连接,两条链路互不占用。
> 命名对齐现有 `terminal_*`(open/exec/close),Observe 沿用 `get_screenshot` 避免重复造轮子。鼠标/键盘各一个工具、用 `action` 枚举区分具体动作——既对齐 Anthropic 的 `computer` 工具动作集,又贴合现有 `WebService::HandleMouse/HandleKey` 的「鼠标/键盘分家」实现。