Feature: Support the Tier 1 MCP tools on Linux clients
All of these tools already had a working wire protocol on the Linux
client (SystemManager.h, common/PTYHandler.h, ScreenHandler.h); only the
server-side client-type gates rejected LNX hosts. kill_process,
exec_command, terminal_open/exec/close and remote_open/close/mouse/
keyboard/clipboard now accept LNX and reject only MAC (plus APK where it
applied). No client change, no capability bit.
exec_command and terminal_exec needed platform-aware plumbing because a
POSIX shell understands none of the Windows constructs: the sentinel is
now "PS1=" / the command / "echo __MCP_DONE_<nonce>__$?" over the Linux
PTY, with output decoded as UTF-8. The PS1= line exists because
interactive bash prints its prompt after every line it reads, which
otherwise leaks into stdout; its echo sits ahead of the command echo and
is removed together with it. The Windows ConPTY and legacy non-PTY forms
are unchanged.
The default command whitelist is now platform-specific: identically named
POSIX commands can write files or change system state (find -exec,
sort -o, hostname), so kDefaultCmdWhitelistPosix only lists commands that
stay read-only even with arguments. env is deliberately excluded, since
"env <program>" runs arbitrary programs and would defeat the whitelist
entirely. An explicit McpCmdWhitelist still overrides both platforms. The
forbidden metacharacter set is split the same way: on Linux it covers
& | < > ; backtick and $( / ${ / !, where ! triggers history expansion in
interactive bash. ^ is not a POSIX metacharacter, so read-only commands
like "grep -v ^# /etc/hosts" are accepted on Linux while Windows keeps
rejecting them.
Input injection had to be sent one MSG64 per COMMAND_SCREEN_CONTROL
packet. The protocol allows batching and the Windows client handles it,
but linux/ScreenHandler.h only processes the first message of a packet,
so a batch left key_press stuck down (X11 autorepeat), click
half-pressed and type emitting only its first character. Splitting the
packets is equivalent for Windows, which processes one message at a time
anyway, and keeps already-deployed Linux clients working without an
upgrade.
Verified on a Debug server against a WSL Ubuntu 24.04 client and a
Windows client: exec_command returned real exit codes (0/1/2) with clean
output, -32007/-32008 negatives, and the POSIX-only ^ allowance;
persistent terminals kept cwd and environment, returned 1 for false and
the last exit code for ";" chains, and closed idempotently; kill_process
killed a test process, returned an empty remaining list and skipped
pid 1; remote_open reported 3840x1140, remote_mouse mapped (0.5,0.5) to
(1920,570), xev showed balanced press/release pairs for keys and buttons,
and a Chinese clipboard round-trip came back as UTF-8. The Windows
regression of the same tools was unchanged, including the multi-monitor
gate on remote_open.
Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
3a158a241c
commit
4d2abf34d0
4 files changed
+155
-64
No files matched your search
@@ -1,7 +1,7 @@
|
||||
# MCP 远程控制(Remote Control)设计文档
|
||||
|
||||
> 版本:v1(设计基线) 状态:待开发 关联:`docs/Mcp_Design.md`、`docs/Mcp_Terminal_Design.md`
|
||||
> 定位:本文件是「AI 远程控制一台 Windows 客户端(像人一样点鼠标、敲键盘、看画面完成任务)」功能的**唯一参照设计**,后续开发一律以本文为准,改需求先改本文。
|
||||
> 定位:本文件是「AI 远程控制一台 Windows 或 Linux 客户端(像人一样点鼠标、敲键盘、看画面完成任务)」功能的**唯一参照设计**,后续开发一律以本文为准,改需求先改本文。Linux 支持范围与限制见 §6.5、§12.1。
|
||||
|
||||
---
|
||||
|
||||
@@ -172,6 +172,7 @@ AI 无法「看懂」视频流。把 25fps 的远程画面直接丢给视觉模
|
||||
|
||||
- **包格式**:`[cmd:1][MSG64:48]`,可批量重复(`commands.h` `COMMAND_SCREEN_CONTROL=20`,`MSG64` 1581–1623)。
|
||||
- **MSG64 布局**:`{uint64 hwnd, message, wParam, lParam, time; POINT pt;}` = 48 字节(`_WIN64` 下 `MYMSG` 即 `MSG`;客户端亦接受 28 字节 `MSG32`,由 `ulLength % 28/48` 判定)。
|
||||
- **一条一包(重要)**:协议允许一包多消息,Windows 客户端也支持(`ProcessCommand` 按 `ulLength % 48 / % 28` 算出条数后逐条处理);但 Linux 客户端(`linux/ScreenHandler.h` `OnReceive`)**只处理包内第一条**。服务端因此统一按「一条 MSG64 一个 `COMMAND_SCREEN_CONTROL` 包」下发(`SendScreenCtrlEvents`):批量下发会让 Linux 上的 `key_press` 只按下不抬起(X11 自动重复)、`click` 只按下、`type` 只打出首字符。对 Windows 客户端完全等价。
|
||||
- **客户端解码**:`ScreenManager.cpp:1175` → `ProcessCommand(1727)` → `SendInput`:
|
||||
- 鼠标:坐标取 `LOWORD/HIWORD(lParam)`,`WM_MOUSEMOVE`→`MOUSEEVENTF_MOVE`,`WM_LBUTTONDOWN/UP`→`LEFTDOWN/LEFTUP`,`WM_LBUTTONDBLCLK`→额外 `LEFTDOWN`,`WM_MBUTTONDOWN/UP`,`WM_MOUSEWHEEL`→`MOUSEEVENTF_WHEEL`(`mouseData=GET_WHEEL_DELTA_WPARAM`)。
|
||||
- 键盘:`wVk=(WORD)wParam`,`wScan=(lParam>>16)&0xFF`,`KEYEVENTF_EXTENDEDKEY` 由 `(lParam>>24)&1`。
|
||||
@@ -205,6 +206,16 @@ AI 无法「看懂」视频流。把 25fps 的远程画面直接丢给视觉模
|
||||
- 随后 `remote_keyboard` 注入 `Ctrl+V` 粘贴、`Enter` 发送。
|
||||
- **编码注意(已核实)**:`UpdateClientClipboard` 用 `SetClipboardData(CF_TEXT,...)`——ANSI/GBK 格式(`CF_TEXT`,非 `CF_UNICODETEXT`)。MVP 下中文可经 `ToAnsi(utf8, 936)` 转 GBK 后直发(与终端命令同模式);但 emoji/非 GBK 字符会丢、部分新式聊天软件粘贴偏好 Unicode。更稳做法是复用 `COMMAND_C2C_TEXT`(90) 的 UTF-8→Unicode→`CF_UNICODETEXT` 逻辑(`KernelManager.cpp:1573-1587`,且已内置「设完剪贴板后自动模拟 Ctrl+V」),或新增一个 UTF-8 设剪贴板变体。见 §17 实验案例。
|
||||
|
||||
### 6.5 Linux 客户端(`RES_CLIENT_TYPE=LNX`)
|
||||
|
||||
服务端路径与 Windows 完全一致(`COMMAND_SCREEN_SPY` → `TOKEN_BITMAPINFO` → `COMMAND_SCREEN_CONTROL`),差异都在客户端(`linux/ScreenHandler.h`,本轮**未改客户端**):
|
||||
|
||||
- **注入**:走 XTest(`XTestFakeMotionEvent` / `XTestFakeButtonEvent` / `XTestFakeKeyEvent`),需要 `libXtst` 与可用的 X 连接(X11 或 XWayland)。
|
||||
- **按键映射**:`VKtoKeySym` 把 Windows VK 映射为 X11 keysym 后 `XKeysymToKeycode`。支持 A–Z、0–9、小键盘、F1–F12、方向键/编辑键、修饰键(`VK_SHIFT→Shift_L`、`VK_CONTROL→Control_L`、`VK_MENU→Alt_L`、`VK_LWIN→Super_L`)与 OEM 标点;**F13–F24 与 `VK_APPS` 无映射**(消息被忽略,不报错)。
|
||||
- **滚轮**:客户端收到 `WM_MOUSEWHEEL` 后按 120 的倍数换算成 Button4/Button5 的按放对,单条消息即可(服务端 `scroll` 只发一条)。
|
||||
- **剪贴板**:服务端按 GBK 下发(与 Windows 相同),Linux 客户端 `ClipboardHandler::SetTextRaw` 检测编码并用 iconv 转 UTF-8 后写 `xclip -selection clipboard`;需要 `xclip` 或 `xsel`。非 GBK 字符(emoji)在服务端就已变成 `?`,Linux 侧无法挽回。
|
||||
- **分辨率**:`TOKEN_BITMAPINFO` 的尺寸取自 root window,与服务端归一化坐标一致;多显示器判定依赖客户端心跳的 `RES_RESOLUTION`(`xrandr` 才能拿到显示器数),无 `xrandr` 时上报 `0:0*0`,服务端按「无法判定」放行。
|
||||
|
||||
---
|
||||
|
||||
## 7. 坐标约定与映射
|
||||
@@ -317,6 +328,7 @@ remote_open ──► 建立子连接 ──► [remote_mouse/remote_keyboard ×
|
||||
|
||||
- **单显示器**:Observe 抓主屏,坐标空间与虚拟桌面重合;多显示器 `remote_open` 显式报错(`-32005`,能力限制而非参数错误)。
|
||||
- 注入基于**绝对坐标** `SendInput`,要求客户端处于可注入的桌面会话(已登录、非锁屏/非 UAC 安全桌面);锁屏/UAC 提示场景注入无效(客户端 `SendInput` 限制),设计文档记录为已知限制。
|
||||
- **Linux 专属限制**(§6.5):纯 Wayland 会话不支持(需 X11/XWayland);需 `libX11`+`libXtst`,剪贴板需 `xclip`/`xsel`;F13–F24、`VK_APPS` 无 keysym 映射;非 ASCII 文本仍只能走剪贴板。
|
||||
- **代聊实验使能项**:窗口抓屏(`COMMAND_SCREEN_WINDOW`)、UTF-8 剪贴板、窗口聚焦随阶段一落地(§17)。
|
||||
|
||||
### 12.2 阶段二(后续)
|
||||
|
||||
Reference in new issue
Block a user