Feat(client): complete the macOS feature set (phase 0 and 1)

Phase 0 makes implementations that already existed reachable. macOS now
declares TERMINAL, SCREEN_CLIPBOARD, PROCESS and C2C_RECV_ACK; PROCESS is a
new bit and Linux declares it too. SystemManager was dead code -- its
constructor took a second argument and it did not derive IOCPManager, so the
sub-connection skeleton could never instantiate it -- and now matches the
createHandler/OnReceive contract, so COMMAND_SYSTEM really spawns a
sub-connection (proc_listpids, SIGKILL). DataProcess always gets a NULL user,
so main.mm keeps a g_pMainClient handle and the V2 C2C receiver finally
answers TOKEN_C2C_RECV_RESULT. The server asks for SupportsTerminal() on MAC
for exec_command / terminal_* and for SupportsProcess() for kill_process, so
an old build gets "client is too old" instead of a command nobody answers;
kToolPlatforms and mcp/tools.json follow. http_probe stays win/lnx: the
terminal works on macOS, but the probe uses GNU-only base64 -w.

Phase 1 is POSIX parity. ScreenPreview captures through CGDisplayCreateImage,
scales and ships BGRX for the server to encode, and the capability is only
declared when preflight or a real capture says the display is readable.
ActivityHistory samples the frontmost layer-0 window once a second and prints
the same records as Windows and Linux. COMMAND_SCREEN_KEYFRAME_REQ is now
consumed by Linux (x264 IDR) and macOS (VideoToolbox force keyframe): the
receive thread raises a flag, the capture thread -- which owns the encoder --
consumes it and puts it back if the frame never went out. The macOS quality
level persists in NSUserDefaults because main.mm rewrites config.conf.

Linux client and Debug x64 server rebuild green; check_platform_table PASS.
Not built or run on a Mac.

Co-Authored-By: deepseek-flash
This commit is contained in:
yuanyuanxianganddeepseek-flash committed 2026-11-14 13:30:50 +01:00
1 parent c2b59f5d4a
commit 06b93f7bdb
19 files changed
+890 -121

No files matched your search

+46 -26
View File
@@ -2242,7 +2242,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
{
Json::Value tool(Json::objectValue);
tool["name"] = "get_activity_history";
tool["description"] = u8"获取指定在线主机的历史活动记录。Windows 与有桌面的 Linux 客户端返回前台窗口驻留记录,每行一条「[时间] [标题] 时长」;Android 客户端返回前台应用驻留记录(标题为「应用名 (包名)」,需开启无障碍服务);无桌面的 Linux 客户端返回登录记录与 shell 命令历史,每行带「[登录]」或「[命令]」标签(首行为「[来源]」说明)。主连接 RPC。结果按 limit/offset 分页(默认 100 条、上限 1000),新在前:offset=0 就是最近 limit 条,想看更早的再往后翻。total 为本机现有记录总数,hasMore 表示还有更早的记录;窗口后端只保留最近 500 条,所以 total 最多约 501(含进行中的当前窗口)。";
tool["description"] = u8"获取指定在线主机的历史活动记录。Windows、有桌面的 Linux 与 macOS 客户端返回前台窗口驻留记录,每行一条「[时间] [标题] 时长」(macOS 无录屏授权时标题退化为应用名);Android 客户端返回前台应用驻留记录(标题为「应用名 (包名)」,需开启无障碍服务);无桌面的 Linux 客户端返回登录记录与 shell 命令历史,每行带「[登录]」或「[命令]」标签(首行为「[来源]」说明)。主连接 RPC。结果按 limit/offset 分页(默认 100 条、上限 1000),新在前:offset=0 就是最近 limit 条,想看更早的再往后翻。total 为本机现有记录总数,hasMore 表示还有更早的记录;窗口后端只保留最近 500 条,所以 total 最多约 501(含进行中的当前窗口)。";
tool["inputSchema"] = BuildPagedHostListInputSchema(); // { id | ids } + limit/offset
tool["outputSchema"] = BuildActivityHistoryOutputSchema();
@@ -2254,7 +2254,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
{
Json::Value tool(Json::objectValue);
tool["name"] = "get_screenshot";
tool["description"] = u8"截取指定在线主机的一帧画面,返回 base64 编码的 JPEG 图片:图片在 content 的 image 块(data 为 base64,mimeType=image/jpeg);structuredContent.image 只有 mimeType/width/height/bytes 元数据,不含图片数据。支持 Windows 与带 X11 桌面的 Linux 客户端(能力位 CLIENT_CAP_SCREEN_PREVIEW),主连接 RPC、一次性返回。Android 客户端用无障碍服务 takeScreenshot 抓屏(Android 11+ 且开启无障碍服务,此时登录会声明该能力位;只支持 mode=screen)。mode 可选 screen(默认,整虚拟桌面)/region(指定矩形)/window(指定 hwnd)/monitor(指定显示器);后三种默认按源尺寸 1:1 原生分辨率抓取(适合 OCR/视觉读字),需要较新的 Windows 客户端(CLIENT_CAP_SCREEN_REGION,否则 -32005),结果在 structuredContent.capture 里回报实际源矩形与缩放比例。";
tool["description"] = u8"截取指定在线主机的一帧画面,返回 base64 编码的 JPEG 图片:图片在 content 的 image 块(data 为 base64,mimeType=image/jpeg);structuredContent.image 只有 mimeType/width/height/bytes 元数据,不含图片数据。支持 Windows、带 X11 桌面的 Linux 与 macOS(登录时已授予录屏权限)客户端(能力位 CLIENT_CAP_SCREEN_PREVIEW),主连接 RPC、一次性返回。Android 客户端用无障碍服务 takeScreenshot 抓屏(Android 11+ 且开启无障碍服务,此时登录会声明该能力位;只支持 mode=screen)。mode 可选 screen(默认,整虚拟桌面)/region(指定矩形)/window(指定 hwnd)/monitor(指定显示器);后三种默认按源尺寸 1:1 原生分辨率抓取(适合 OCR/视觉读字),需要较新的 Windows 客户端(CLIENT_CAP_SCREEN_REGION,否则 -32005),结果在 structuredContent.capture 里回报实际源矩形与缩放比例。";
tool["inputSchema"] = BuildGetScreenshotInputSchema(); // { id } 必填 + max_width 可选
tool["outputSchema"] = BuildScreenshotOutputSchema();
@@ -2676,7 +2676,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
if (CMcpServer::Instance().IsFileTransferEnabled() && !CMcpServer::Instance().IsReadonly()) {
Json::Value tool(Json::objectValue);
tool["name"] = "upload_file";
tool["description"] = u8"把主控本机文件或目录上传到指定在线主机的目录(V2 协议,主连接发送)。支持 Windows 与 Linux/macOS 主机;local_path 为主控本机绝对路径(文件或目录,目录递归上传);remote_dir 为远程保存目录(不存在自动创建),Windows 用 C:\\uploads 这类盘符路径,Linux/macOS 用 /home/user/uploads 这类绝对 POSIX 路径;overwrite=false 时跳过 remote_dir 下已存在的同名顶层项。返回 files[{path,size,sha256}] 与 total_bytes/skipped/receiver_ack;sha256 恒为空(发送端不计算)。receiver_ack=true 表示目标端已确认写入(Linux 客户端回执),false 表示目标端没有回执(Windows 目标、老客户端或 macOS),此时需要确证请用 list_files 复核。";
tool["description"] = u8"把主控本机文件或目录上传到指定在线主机的目录(V2 协议,主连接发送)。支持 Windows 与 Linux/macOS 主机;local_path 为主控本机绝对路径(文件或目录,目录递归上传);remote_dir 为远程保存目录(不存在自动创建),Windows 用 C:\\uploads 这类盘符路径,Linux/macOS 用 /home/user/uploads 这类绝对 POSIX 路径;overwrite=false 时跳过 remote_dir 下已存在的同名顶层项。返回 files[{path,size,sha256}] 与 total_bytes/skipped/receiver_ack;sha256 恒为空(发送端不计算)。receiver_ack=true 表示目标端已确认写入(Linux/macOS 客户端回执),false 表示目标端没有回执(Windows 目标或老客户端),此时需要确证请用 list_files 复核。";
tool["inputSchema"] = BuildUploadFileInputSchema();
tool["outputSchema"] = BuildUploadFileOutputSchema();
tools.append(tool);
@@ -2688,7 +2688,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
if (CMcpServer::Instance().IsFileTransferEnabled() && !CMcpServer::Instance().IsReadonly()) {
Json::Value tool(Json::objectValue);
tool["name"] = "copy_files_c2c";
tool["description"] = u8"在两个在线主机之间直接拷贝文件(V2 C2C:源主机自己发、目标主机自己收,服务端只中继,不在主控落盘)。源主机必须是 Windows;目标主机可以是 Windows 或 Linux/macOS。paths 为源主机绝对路径(文件或目录,目录递归、保留相对目录结构);dst_dir 为目标主机保存目录(不存在自动创建),Windows 目标用 D:\\Incoming 这类绝对路径,Linux/macOS 目标用 /home/user/incoming 这类绝对 POSIX 路径。overwrite 默认 false:目标目录已存在同名顶层项时跳过并计入 skipped(目标端是无条件覆盖写,不跳过就会每次全量重发);预检本身失败(目标主机忙/超时/拒绝访问)不报错,退回全发并置 skip_check_failed=true。返回 transfer_id/file_count/total_bytes/skipped/skip_check_failed/receiver_ack:receiver_ack=true 表示目标端已确认写入(Linux 客户端回执),false 表示目标端没有回执(Windows 目标、老客户端或 macOS),此时需要确证请用 list_files 复核。";
tool["description"] = u8"在两个在线主机之间直接拷贝文件(V2 C2C:源主机自己发、目标主机自己收,服务端只中继,不在主控落盘)。源主机必须是 Windows;目标主机可以是 Windows 或 Linux/macOS。paths 为源主机绝对路径(文件或目录,目录递归、保留相对目录结构);dst_dir 为目标主机保存目录(不存在自动创建),Windows 目标用 D:\\Incoming 这类绝对路径,Linux/macOS 目标用 /home/user/incoming 这类绝对 POSIX 路径。overwrite 默认 false:目标目录已存在同名顶层项时跳过并计入 skipped(目标端是无条件覆盖写,不跳过就会每次全量重发);预检本身失败(目标主机忙/超时/拒绝访问)不报错,退回全发并置 skip_check_failed=true。返回 transfer_id/file_count/total_bytes/skipped/skip_check_failed/receiver_ack:receiver_ack=true 表示目标端已确认写入(Linux/macOS 客户端回执),false 表示目标端没有回执(Windows 目标或老客户端),此时需要确证请用 list_files 复核。";
tool["inputSchema"] = BuildCopyFilesC2CInputSchema();
tool["outputSchema"] = BuildCopyFilesC2COutputSchema();
tools.append(tool);
@@ -4197,11 +4197,15 @@ std::string BuildExecCommand(const Json::Value& id, const Json::Value& args, CMy
if (!ctx)
return BuildError(id, -32002, "Host not found or offline: " + std::to_string(devId));
// Linux/Android 客户端同样走 PTY + POSIX 哨兵;macOS 本轮不开放。
// Linux/Android 客户端同样走 PTY + POSIX 哨兵;macOS 客户端也有完整 PTY
// (common/PTYHandler.h,zsh/bash 交互),是否可用改由 CLIENT_CAP_TERMINAL 判定:
// 老 macOS 构建收到 COMMAND_SHELL 只打一行 unimplemented,发下去只会拖到超时。
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
const bool posix = (clientType == "LNX" || clientType == "APK");
if (clientType == "MAC")
return BuildError(id, -32005, "exec_command is only supported on Windows, Linux and Android hosts");
const bool posix = (clientType == "LNX" || clientType == "APK" || clientType == "MAC");
if (clientType == "MAC" && !ctx->SupportsTerminal())
return BuildError(id, -32005,
"macOS client is too old for exec_command: "
"it does not declare CLIENT_CAP_TERMINAL; upgrade the client first");
// 老 APK 的 COMMAND_SHELL 是空实现,发下去只会拖到超时;按能力位提前拒绝。
if (clientType == "APK" && !ctx->SupportsTerminal())
return BuildError(id, -32005,
@@ -4854,8 +4858,10 @@ static bool ResolveTerminalSessionHost(const Json::Value& id, const Json::Value&
}
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
if (clientType == "MAC") {
errJson = BuildError(id, -32005, "Persistent terminal is only supported on Windows, Linux and Android hosts");
if (clientType == "MAC" && !ctx->SupportsTerminal()) {
errJson = BuildError(id, -32005,
"macOS client is too old for the persistent terminal: "
"it does not declare CLIENT_CAP_TERMINAL; upgrade the client first");
return false;
}
if (clientType == "APK" && !ctx->SupportsTerminal()) {
@@ -5196,7 +5202,8 @@ std::string BuildTerminalExec(const Json::Value& id, const Json::Value& args, CM
if (!ResolveTerminalSessionHost(id, args, parent, devId, ctx, errJson))
return errJson;
const bool posix = (ctx->GetAdditionalData(RES_CLIENT_TYPE) == "LNX" ||
ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK");
ctx->GetAdditionalData(RES_CLIENT_TYPE) == "APK" ||
ctx->GetAdditionalData(RES_CLIENT_TYPE) == "MAC");
// command 省略 = 轮询模式(P0-2);session_id 可省略(P0-1:带 command 时自动建/复用默认会话)。
std::string command = Trim(GetStringArg(args, "command"));
@@ -9803,8 +9810,14 @@ std::string BuildKillProcess(const Json::Value& id, const Json::Value& args, CMy
return BuildError(id, -32002, "Host not found or offline: " + std::to_string(devId));
CString clientType = ctx->GetAdditionalData(RES_CLIENT_TYPE);
if (clientType == "MAC" || clientType == "APK")
return BuildError(id, -32005, "kill_process is only supported on Windows and Linux hosts");
// macOS 客户端有 COMMAND_SYSTEM → SystemManager(proc_listpids + SIGKILL)分支,
// 但没有对应能力位的老构建收到 COMMAND_SYSTEM 只打一行日志 → 刷新永远等不到,故按位拒绝。
if (clientType == "MAC" && !ctx->SupportsProcess())
return BuildError(id, -32005,
"macOS client is too old for kill_process: "
"it does not declare CLIENT_CAP_PROCESS; upgrade the client first");
if (clientType == "APK")
return BuildError(id, -32005, "kill_process is only supported on Windows, Linux and macOS hosts");
CMcpServer& mcp = CMcpServer::Instance();
if (mcp.IsReadonly())
@@ -11988,7 +12001,9 @@ const ToolPlatform kToolPlatforms[] = {
{ "upload_file", kPlatWin|kPlatLnx|kPlatMac },
// ---- win+lnx(+apk) ---- 远程控制全族 + 需 SCREEN_PREVIEW 的截屏 + macOS 未开放项
// Android 用无障碍 takeScreenshot(API 30+,需开无障碍服务),只支持 mode=screen
{ "get_screenshot", kPlatWin|kPlatLnx|kPlatApk },
// macOS 走 macos/ScreenPreview.mm(CGDisplayCreateImage,声明 CLIENT_CAP_SCREEN_PREVIEW
// 的前提是登录时已授予录屏权限),与 Linux 一样回 BGRX 由服务端编码
{ "get_screenshot", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
// 窗口信息 RPC 只在 Windows 客户端实现(CLIENT_CAP_WINDOW_INFO)
{ "get_foreground_window", kPlatWin },
// Android 客户端把注入翻译成触摸手势 / 全局动作(android/.../ControlService.kt),
@@ -12000,17 +12015,21 @@ const ToolPlatform kToolPlatforms[] = {
{ "remote_clipboard", kPlatWin|kPlatLnx|kPlatApk },
// COMMAND_SCREEN_CTRL_ALT_DEL:只有 Android 客户端实现(映射为系统锁屏)
{ "remote_lock_screen", kPlatApk },
// macOS 客户端有 PTY 实现(macos/main.mm:753),但服务端刻意不开放
// (McpServer.cpp:3652「macOS 本轮不开放」),故实际不可用;
// Android 新版复用 common/PTYHandler.h(/system/bin/sh),声明 CLIENT_CAP_TERMINAL
{ "exec_command", kPlatWin|kPlatLnx|kPlatApk },
{ "terminal_open", kPlatWin|kPlatLnx|kPlatApk },
{ "terminal_exec", kPlatWin|kPlatLnx|kPlatApk },
{ "terminal_close", kPlatWin|kPlatLnx|kPlatApk },
// macOS 客户端有 COMMAND_KILLPROCESS 分支,服务端同样拦着(McpServer.cpp:6870)
{ "kill_process", kPlatWin|kPlatLnx },
// http_probe 要走终端通道(Windows 用 PowerShell、Linux 用 curl);macOS 终端未开放,
// Android 的 toybox 不保证有 curl/base64,故只标 win/lnx(工具内部对 MAC/APK 返回 -32005)。
// macOS 客户端同样是完整 PTY(common/PTYHandler.h,zsh/bash),新版声明
// CLIENT_CAP_TERMINAL;老 macOS 构建收到 COMMAND_SHELL 只打一行 unimplemented,
// 工具内部按能力位提前拒绝(McpServer.cpp 的 SupportsTerminal 判定)。
// Android 新版复用 common/PTYHandler.h(/system/bin/sh),同样声明 CLIENT_CAP_TERMINAL
{ "exec_command", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
{ "terminal_open", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
{ "terminal_exec", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
{ "terminal_close", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
// macOS 客户端有 COMMAND_SYSTEM → SystemManager(proc_listpids + SIGKILL),
// 新版声明 CLIENT_CAP_PROCESS;老构建按能力位提前拒绝。
{ "kill_process", kPlatWin|kPlatLnx|kPlatMac },
// http_probe 要走终端通道(Windows 用 PowerShell、Linux 用 curl)。
// macOS 终端已开放,但这里的 POSIX 命令用了 `base64 -w`(GNU 专有),BSD base64
// 没有这个开关,头和体都会解不出来——等换成两平台通用的折行写法再放行。
// Android 的 toybox 不保证有 curl/base64,故仍只标 win/lnx。
{ "http_probe", kPlatWin|kPlatLnx },
// ---- win ---- 服务 / 注册表 / 键日志 / 文件写 / host_* / chat_* / power_action
// list_windows 单列:BuildListWindows 把 COMMAND_WSLIST 发在**主连接**上
@@ -12023,7 +12042,8 @@ const ToolPlatform kToolPlatforms[] = {
// Linux 客户端已实现 COMMAND_QUERY_ACTIVITY → TOKEN_REPORT_ACTIVITY(linux/LinuxActivityHistory.h,
// 有桌面走 X11 窗口采样,无桌面走 last + shell 历史),Android 复用同一套采样机、
// 前台应用由无障碍服务提供,与 Windows 同为主连接 RPC
{ "get_activity_history", kPlatWin|kPlatLnx|kPlatApk },
// macOS 是 macos/ActivityHistory.mm(CGWindowList 前台窗口采样,同样主连接一次性快照)
{ "get_activity_history", kPlatWin|kPlatLnx|kPlatMac|kPlatApk },
{ "list_services", kPlatWin },
{ "get_keylog", kPlatWin },
{ "list_registry", kPlatWin },