Feature: Report activity history on Linux clients
Implement COMMAND_QUERY_ACTIVITY -> TOKEN_REPORT_ACTIVITY with two backends picked at startup. With a desktop, a sampler thread reads the foreground window every second and books dwell time like the Windows client: under five seconds is dropped, five idle minutes close the window, the last 500 records stay newest first, each line being "[YYYY-MM-DD HH:MM:SS] [title] duration". It uses its own ActivityChecker because an Xlib connection cannot be shared with the heartbeat thread, and it is stopped before main's locals go away. A reachable X server is not enough: the window backend is only chosen when the root window carries _NET_SUPPORTING_WM_CHECK, so Xvfb or a bare X without an EWMH window manager falls back to the headless backend instead of sampling a window id that never appears. Without a desktop the answer is computed on demand: logins from "last -n 100 -F" plus bash/zsh history of root and /home/*, tagged [登录] or [命令] after a [来源] header. Both halves are merged and sorted by timestamp; three fifths of the budget goes to logins and reboot records are capped at ten, since a WSL or container writes one reboot per start. activity_commands=0 drops the command half. A single detached thread builds and sends it, only while the main link is up. The MCP gate now admits Linux for get_activity_history and documents both shapes. test/unit/linux covers the parsers, ordering and UTF-8 truncation; 15 cases pass. Co-Authored-By: deepseek-flash
This commit is contained in:
1 parent
5f40f3726c
commit
d8048979e3
6 files changed
+940
-14
No files matched your search
@@ -2026,7 +2026,7 @@ std::string BuildToolsListResult(const Json::Value& id) {
|
||||
{
|
||||
Json::Value tool(Json::objectValue);
|
||||
tool["name"] = "get_activity_history";
|
||||
tool["description"] = u8"获取指定在线主机的历史活动记录(前台窗口驻留时长,每行一条「[时间] [标题] 时长」)。主连接 RPC。结果按 limit/offset 分页(默认 100 条、上限 1000),新在前:offset=0 就是最近 limit 条,想看更早的再往后翻。total 为本机现有记录总数,hasMore 表示还有更早的记录;客户端只保留最近 500 条,所以 total 最多约 501(含进行中的当前窗口)。";
|
||||
tool["description"] = u8"获取指定在线主机的历史活动记录。Windows 与有桌面的 Linux 客户端返回前台窗口驻留记录,每行一条「[时间] [标题] 时长」;无桌面的 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();
|
||||
@@ -8854,7 +8854,9 @@ const ToolPlatform kToolPlatforms[] = {
|
||||
// 注意别被 linux/SystemManager.h:38 和 macos/SystemManager.mm:39 的 case 骗到,
|
||||
// 那是给 SystemDlg 窗口管理用的,不是 MCP 这条路径。
|
||||
{ "list_windows", kPlatWin },
|
||||
{ "get_activity_history", kPlatWin },
|
||||
// Linux 客户端已实现 COMMAND_QUERY_ACTIVITY → TOKEN_REPORT_ACTIVITY(linux/LinuxActivityHistory.h,
|
||||
// 有桌面走 X11 窗口采样,无桌面走 last + shell 历史),与 Windows 同为主连接 RPC
|
||||
{ "get_activity_history", kPlatWin|kPlatLnx },
|
||||
{ "list_services", kPlatWin },
|
||||
{ "get_keylog", kPlatWin },
|
||||
{ "list_registry", kPlatWin },
|
||||
|
||||
Reference in new issue
Block a user