Fix: Paginate get_activity_history results
The tool was the only list-type tool without pagination. The client keeps ACTIVITY_HISTORY_MAX=500 records and Dump() prepends the in-progress window, so a single call returned up to 501 lines of "[time] [title] duration" -- enough to blow up the caller's context, especially since titles carry personal browsing history. Records come back newest-first (m_records uses push_front and the current window is prepended), so the standard limit/offset window applies directly: offset=0 is the most recent page, no need to read total first and count backwards. That ordering is now stated in the tool description so the model can rely on it. - inputSchema: BuildGetHostDetailInputSchema -> BuildPagedHostListInputSchema (adds limit, default 100 / max 1000, and offset) - outputSchema: append AppendPageOutputProps plus truncated - implementation: rename the full split to `all`, slice via ResolvePageWindow and ApplyPageWindow, write back with WritePageFields - activityHistory is rebuilt from the window instead of returning the whole Dump() text -- otherwise the raw copy would bypass pagination entirely - 64 KB byte budget (same as get_client_log), trimmed from the end so the newest records survive; hasMore is computed as offset+kept < total rather than hardcoded true, since a single oversized tail record must not claim there is another page Batch calls need no extra work: the tool is already in IsBatchReadOnlyTool, and BuildBatchCall forwards limit/offset to each host, so ids + limit means "the latest N records of every host". Compiles clean; not yet exercised against a running server (the exe was locked by the live instance). Verification cases are listed in docs/Mcp_Test_Report_2026-10-29.md section 8.
This commit is contained in:
1 parent
56a937fabb
commit
dcb5ae25c6
3 files changed
+154
-10
No files matched your search
@@ -955,3 +955,50 @@ schema 里写明这一点;同时根键分支补上 `path: ""`,让两个分
|
||||
三个 P0 内,留待下一轮。
|
||||
- 连接器会缓存 `tools/list`,`limit`/`filter` 在重连前对模型不可见(默认参数已覆盖
|
||||
P0-3 的场景),与既有的 `overwrite` 缓存问题同源。
|
||||
|
||||
## 19. 增补(2026-10-29:`get_activity_history` 分页,P2-1)
|
||||
|
||||
### 19.1 问题
|
||||
|
||||
`get_activity_history` 是全仓库唯一没有分页的列表类工具。客户端 `ACTIVITY_HISTORY_MAX`
|
||||
= 500,`Dump()` 还会把进行中的当前窗口作为第 1 条,所以一次返回上限约 501 条——实测
|
||||
正是 501 条。每行含窗口标题(可能很长),501 行直接把上下文冲爆;而报告里那份数据还
|
||||
混着大量个人浏览、求职、签证页面,属于「不该被整包塞进模型上下文」的典型。
|
||||
|
||||
### 19.2 顺序:为什么可以直接用 `limit`/`offset`
|
||||
|
||||
`ActivityHistory::Loop()` 用 `m_records.push_front(...)` 维护,`Dump()` 又把当前进行中
|
||||
的窗口拼在最前面——**返回顺序天然是「新在前」**。于是 `offset=0` 就是最近 `limit` 条,
|
||||
不必像「新在后」的日志那样先取一次 `total` 再倒算 `offset=total-limit`。这条顺序不是
|
||||
本次新增的约定,是客户端本来就这样,写进描述是为了让模型敢直接用 `offset=0`。
|
||||
|
||||
### 19.3 实现
|
||||
|
||||
- `inputSchema` 从 `BuildGetHostDetailInputSchema()` 换成 `BuildPagedHostListInputSchema()`
|
||||
(`{ id | ids }` + `limit`/`offset`,与 `list_processes` / `list_windows` 同一套);
|
||||
- `outputSchema` 追加 `AppendPageOutputProps()` 与 `truncated`;
|
||||
- 实现里把原来的 `records` 改名 `all`(全量拆行结果),再 `ResolvePageWindow` +
|
||||
`ApplyPageWindow` 切出 `records`,`WritePageFields` 写回 `total`/`totalAll`/`offset`/
|
||||
`limit`/`hasMore`;
|
||||
- **`activityHistory` 必须按窗口重建**:它原来是 `Dump()` 的整包原文,如果原样返回,
|
||||
501 行的正文照样进上下文,等于没分页。现在它是窗口内 `records` 的按行拼接,语义仍是
|
||||
「同一份数据的纯文本形态」;
|
||||
- 再加 64 KB 字节预算(与 `get_client_log` 同口径),从窗口**末尾**裁——保留最新的那些。
|
||||
裁断时 `truncated=true`;`hasMore` 按 `offset + returned < total` 算,而不是一律置 true
|
||||
(末尾单条自己超预算时不该再报还有下一页)。调用方用 `offset + returned` 继续取;
|
||||
- 至少保留 1 条:单条超预算时若不保底,`returned=0` 会让调用方在同一个 `offset` 上原地
|
||||
打转。窗口标题达到 64 KB 几乎不可能,这是纯兜底。
|
||||
|
||||
### 19.4 批量
|
||||
|
||||
`get_activity_history` 在 `IsBatchReadOnlyTool` 名单里,`BuildBatchCall` 会把 `ids` 摘掉、
|
||||
其余参数原样透传给单机调用,所以 `ids` + `limit` 等于「每台各取最近 N 条」,不需要额外
|
||||
处理。P0-1 的 `anyOf:[单机, 批量]` 包装也自动覆盖新增字段。
|
||||
|
||||
### 19.5 未做
|
||||
|
||||
- 没有 `filter`(按窗口标题子串)。报告没提,且客户端标题是 UTF-8、过滤要按字节子串做,
|
||||
与 `get_client_log` 的 `filter` 不同源,等有实际需求再加。
|
||||
- 没有 `since`(按时间起点取)。记录里的时间是 `[YYYY-MM-DD HH:MM:SS]` 文本前缀,做时间
|
||||
过滤得先解析每行;当前 `limit/offset` 已够用。
|
||||
|
||||
Reference in new issue
Block a user