Feature: Add window-relative remote_mouse coords and PTY pipes in terminal_exec
New Windows clients append an optional 20-byte WINDOWINFO_MCP_DESKTOP block (virtual desktop rect, magic 'VDCP') after the window list, so the server can map window-relative coordinates into the capture frame. remote_mouse accepts an optional window_hwnd; x/y and drag x2/y2 are then normalized against the intersection of the window and the virtual desktop, which is exactly the source rect of get_screenshot mode=window. The target window must be foreground by default, and window_hwnd/expect_hwnd must agree when both are given. structuredContent gains coordinateWindow and resolved (frame coords plus the basis rect), so callers can verify the mapping. terminal_exec now allows pipes, && and || in PTY sessions (ConPTY on Windows, POSIX PTY on Linux) because the sentinel runs on its own line; legacy non-PTY sessions still reject & and |. A read-only PeekTermSession lets the server reject unsupported syntax before BeginTermCommand. POSIX still rejects bare background & (&&, &>, 2>&1 stay allowed). Docs: Mcp_Design.md sections 12.1/20.2/22 and Mcp_Terminal_Design.md 4.4/4.6 are synchronized with the protocol, the new validation order, and the basis rect semantics. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
235a8a622c
commit
5501889d33
10 files changed
+383
-60
No files matched your search
@@ -237,15 +237,20 @@ SweepIdleTerminals(300)
|
||||
ResolveTerminalSessionHost
|
||||
session_id 为空 → -32602
|
||||
command 为空 → -32602
|
||||
command 含 & 或 | → -32012(正确性门,见 §4.6)
|
||||
PeekTermSession(devId, sid, isPty)
|
||||
→ 非 0 则按 -32002/-32003 返回(不存在/不匹配/未就绪/忙碌/已关)
|
||||
command 含 <0x20 控制字符 → -32012(换行会拆行,见 §4.6)
|
||||
!isPty && command 含 & 或 | → -32012(老非 PTY 单行哨兵,见 §4.6)
|
||||
posix && HasPosixBackgroundAmpersand(command)
|
||||
→ -32012(POSIX 裸后台 &,见 §4.6)
|
||||
nonce = 随机 8 hex
|
||||
BeginTermCommand(devId, sessionId, command, nonce, subCtx, isPty)
|
||||
→ false 则 -32002(不存在/不匹配/未就绪/忙碌/已关)
|
||||
sentLine = SendTerminalCommandLine(subCtx, isPty, command, nonce)
|
||||
→ 非 0 则 -32002/-32003(Peek 后被并发抢占:忙碌/已关等)
|
||||
sentLine = SendTerminalCommandLine(subCtx, isPty, posix, command, nonce, ...)
|
||||
WaitTermCommand(devId, raw, exitCode, closed, timeoutMs)
|
||||
→ 超时:subCtx->CancelIO() + -32001
|
||||
→ closed:subCtx->CancelIO()(会话已被清理,仅对称无害)
|
||||
stdoutStr = CleanTerminalOutput(raw, cp, sentLine)
|
||||
stdoutStr = CleanTerminalOutput(raw, cp, isPty, cmdLine, sentLine)
|
||||
审计 "term-exec [sessionId]: command"
|
||||
返回 { stdout, exit_code }
|
||||
```
|
||||
@@ -271,15 +276,29 @@ CloseTermSession(devId, sessionId)
|
||||
|
||||
`CloseTermSession` 返回值语义:**0**=已关闭;**1**=会话不存在(幂等,仍返回 `{closed:true}`);**2**=sessionId 不匹配(报错)。
|
||||
|
||||
### 4.6 正确性门 `&|`(非安全门)
|
||||
### 4.6 正确性门:`&` / `|` / 控制字符(非安全门)
|
||||
|
||||
`terminal_exec` **拒绝含 `&` 或 `|` 的命令**(`find_first_of("&|")`,含 `&&`/`||`/`|`),报 `-32012`(历史别名 `-32008`)。原因:哨兵包装 `cmd 2>&1 && echo ... || echo ...` 假定命令是「扁平」的,命令内含 `&`/`|` 会与包装的控制操作符合流、导致退出码失真/输出归属不清。
|
||||
门按**会话形态**分档,判定发生在 `BeginTermCommand` 之前:`PeekTermSession` 只读查询
|
||||
(不置 `busy`、不改状态),不支持的语法在碰会话之前就被拒绝;Peek 与 Begin 之间被并发
|
||||
抢占时 `BeginTermCommand` 返回忙碌,无竞态。全部报 `-32012`(历史别名 `-32008`)。
|
||||
|
||||
- **控制字符(`<0x20`,含 `\r`/`\n`)一律拒绝**:换行会把命令拆成多行、只有末行被哨兵
|
||||
包装,退出码与输出归属失真。
|
||||
- **老非 PTY 会话**(`is_pty=false`,单行哨兵 `cmd 2>&1 && echo ... || echo ...`):`&`/`|`
|
||||
会与包装的控制操作符合流,维持拒绝(`find_first_of("&|")`,含 `&&`/`||`/`|`)。
|
||||
- **PTY 会话**(`is_pty=true`:Windows ConPTY / Linux POSIX PTY):哨兵独立成行执行,
|
||||
`|`、`&&`、`||`(POSIX 还允许 `;`)由 shell 正常解析,退出码取整条管道/串联的结果,放行。
|
||||
- **POSIX 会话的裸后台 `&`**:`cmd & echo 哨兵` 会让哨兵在命令真正完成前执行,stdout 与
|
||||
退出码都不可信,拒绝。`&&`、`&>`/`&>>`、`>&`/`2>&1` 里的 `&` 放行;引号与反斜杠转义内的
|
||||
`&` 不算。判别器 `HasPosixBackgroundAmpersand` 对 `$((...))`、`${...}` 展开里的 `&` 会
|
||||
保守拒绝(误报,改写命令即可)。
|
||||
|
||||
- 这是**正确性限制,不是白名单**——持久终端本就不设白名单。
|
||||
- 同样拒绝 `<0x20` 的控制字符(`\r`/`\n`):换行会把命令拆成多行、只有末行被哨兵包装,导致退出码与输出归属失真。
|
||||
- `> < ^`(重定向 / 转义)**允许**:不破坏哨兵链。AI 把链式/管道命令拆成多条 `terminal_exec` 调用即可(cwd/env 保持,等价)。
|
||||
- `> < ^`(重定向 / 转义)**允许**:不破坏哨兵链。老非 PTY 会话请把链式/管道命令拆成
|
||||
多条 `terminal_exec` 调用(cwd/env 保持,等价)。
|
||||
|
||||
对比:一次性 `exec_command` 因有白名单,其元字符门更严(`&|<>^` 五元字符全拒,§3.1)。
|
||||
对比:一次性 `exec_command` 因有白名单,其元字符门更严(`&|<>^` 五元字符全拒,§3.1),
|
||||
且不因 PTY 放宽。
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user