Skip to content

feat(agents): 用量速度排行、会话分页读取、Agent 命令行工具安装和 IDE 连接的会话搜索(API-45 0 内补充) - #217

Merged
xiaoyumuxi merged 7 commits into
mainfrom
feat/agents-usage-speeds
Nov 28, 2026
Merged

xiaoyumuxi merged 7 commits into
mainfrom
feat/agents-usage-speeds

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

概述 / Summary

API-45(Agent)的一组 agents 0 内补充,外加 API-23 的 commandInstallers 0 内补充,都是桌面端 1lck/Lithe-IDEA#2492 和三个 Agent 插件(Agent 管理、Claude Code、Codex)要用的:

  1. 输出速度排行:lithe/host/agents/usage 和宿主命令 agentSessions.stats 的回答多一个 speeds,按模型列出输出速度中位数(首个令牌之后每秒输出令牌数),最快的在前。
  2. 会话记录分页读取:agentSessions.list 可按 sessionID 查找、每个会话带 readBytes;agentSessions.read 回答下一页起点 end,只把完整的行交给插件后端。桌面端靠它查看已记录会话的消息。
  3. Agent 命令行工具的安装:命令安装声明的 commands 可以由本插件某个 Agent 的工具定义提供,requirements 列出 kind: "agent" 的使用方;受管命令目录也参与解析 Agent 工具。命令行工具缺失时,桌面端据此引导到插件管理安装。
  4. IDE 连接的会话搜索工具:新增只读 MCP 工具 lithe_sessions_search 和 lithe_sessions_read,让 MCP 客户端搜索和分页读取用户同意读取的 Agent 会话。宿主声明了才提供;没有声明工具清单的宿主不提供。

不新增宿主方法、通知、错误码、权限或能力版本。旧 Core 和旧宿主的行为写在协议更新记录里。

宿主方法与通知 / Host methods and notifications

原计划编号 方法 用途
API-45 lithe/host/agents/usage 回答新增 speeds: [{model, calls, medianTokensPerSecond, lowerBound}],只有模型名和数字

下面这些不是插件宿主方法,列出来方便评审:

原计划编号 名称 种类 用途
API-45 agentSessions.list / agentSessions.read 平台宿主命令 list 可按 sessionID 查找并带 readBytes;read 回答 end
API-45 agentSessions.stats 平台宿主命令 回答新增 speeds
API-23 commandInstallers 声明、plugins.commandInstallers.requirements 清单声明 / 平台宿主命令 安装命令也可以服务 Agent 的命令行工具,使用方 kind: "agent"
API-45 lithe_sessions_search IDE 连接 MCP 工具(read) 按查询词搜索已记录的会话,最多 20 条,带有界摘录,不返回路径
API-45 lithe_sessions_read IDE 连接 MCP 工具(read) 从头分页读取一个会话的消息,游标只在发出它的连接上有效

主要改动 / Changes

速度排行(85425cc、203c589)

  • rust/crates/agent-sessions/src/stats.rs:速度排行改成逐条累加的 SpeedRanker,每个模型只保留速度值;rank_speed 保留为它的简单包装。输出少于 100 令牌、失败、超过 10000 t/s 的调用不计;只给出首令牌时间或总时长时按下界计(≥1000 输出令牌、≥1 s)并标 lowerBound。
  • rust/crates/agent-runtime/src/records.rs:summarize 在同一次遍历里同时得到汇总和速度,usage 与 agentSessions.stats 都回答 speeds。
  • 契约 README 写明 speeds 的形状与计入规则;四种 SDK(Rust、Go、Node、Java)的 README 与 usage 方法注释同步。
  • 契约 README 写明 scan 的一个既有行为(b801e8f):之后的扫描可以用同一个 key 再报一次调用,range 在它自己的块里,后报的替换先报的。Codex 插件到一轮结束(task_complete)才知道计时,靠它给之前块里的调用补上 firstTokenMs 和 durationMs。自 feat(agent-sessions): add the local agent session record store #199 起 Core 都按 (file_id, call_key) 替换,agent-sessions 补测试 a_later_report_of_a_call_replaces_it。

分页读取(4e864f7)

  • agent-sessions/src/store.rs:list 支持 sessionID 条件,回答每个会话已读到的 readBytes。
  • agent-runtime/src/records.rs:read 在行中间结束时只把完整的行交给后端,回答 end;范围落在一行之内时 end 等于起点、不调用后端。
  • 契约 README、rust-core-api.md、更新记录同步;说明后端 messages 回答整体不能超过 1 MiB 的函数结果上限。

Agent 命令行工具的安装(8a8d13c)

  • plugin-manifest/src/command_installers.rs:安装声明的命令可以由 Agent 工具的 commands 提供,requirements 在 systemCommand 启动之后按声明顺序列出 Agent 使用方;只有 Agent 工具用到、又不在任何启动或 Agent 工具里的命令仍被拒绝。
  • 新 fixture command-installer-agent.plugin.json 和三个计划用例;契约 README、工具链参考页、能力版本表同步。

IDE 连接的会话工具(08ba94e、1cfc556)

  • ide-host/src/catalog.rs:两个工具的权限都是 read,参数里没有路径;DECLARED_ONLY 让没有声明工具清单的宿主不提供它们,调用返回 NOT_SUPPORTED。
  • rust/contracts/ide-api/v1.md:写明三个提供条件(IDE 连接打开、“允许 MCP 客户端搜索本地会话”打开、至少同意读取一个 Agent 的会话)、搜索和读取的结果与字节上限、错误码、不返回路径、不触发同步。读取一页最多 65,536 字节文字、2,000 条消息,单条消息截到 4,096 字节、工具名截到 128 字节;tooLong 表示单行超过 16 MiB,omitted 表示放大后的一次读取里放不下的消息数。游标用连接密钥签名,重连后旧游标返回 INVALID_ARGUMENTS,客户端要从头读。
  • 新日志事件 agent.records.inspected(由 Lithe 记):只记工具名、结果条数和耗时,不记查询词、会话 ID 和内容。
  • 调用 fixture 加上接受和拒绝的会话工具调用(含带路径参数、缺 query、多余的 limit),产品工具清单 fixture 加上两个工具。

更新记录:protocol-changelog.md 时间线的 #217 条目写明上面四项补充和旧版行为,“宿主方法(按 API 编号)”给 agents/usage 加一行。

验证 / Verification

在 1cfc556 上(b801e8f 只加了契约说明和一个测试,另跑了 cargo test -p lithe-agent-sessions:42 个通过,clippy 和 verify-docs 通过):

  • cargo test -p lithe-ide-host -p lithe-agent-runtime -p lithe-agent-sessions -p lithe-plugin-manifest -p lithe-diagnostics:五个 crate 共 164 个通过。
  • cargo test -p lithe-core declarative_plugins:67 个通过(含 Agent 命令安装的清单用例)。
  • cargo fmt --check、cargo clippy -p lithe-ide-host -p lithe-agent-runtime -p lithe-agent-sessions -p lithe-plugin-manifest -- -D warnings:通过。
  • node shared/plugins/scripts/verify-docs.mjs:Plugin docs and contract links are consistent.
  • 桌面端 feat(desktop): Agent 工具窗口接入 API-45 原生会话与本机会话记录 1lck/Lithe-IDEA#2492 固定 1cfc556,internal/workbench、internal/settingswindow、internal/agents、internal/core 全部测试通过;会话工具的 8 个测试另跑了计时检查(最长 290 ms)和 -race。

速度排行改成逐条累加的 SpeedRanker,只保留每个模型的速度值,大量历史不必一次读进内存。lithe/host/agents/usage 和 agentSessions.stats 都返回 speeds,契约、更新记录与四种 SDK 的说明同步。
读取范围在行中间结束时只把完整的行交给插件后端,范围落在一行之内时回答 end 等于起点、不调用后端。契约 README、Core API 表和更新记录同步;新字段都是 agents 0 内的补充。
安装声明的 commands 可以由本插件某个 Agent 的 tool 所指工具定义的 commands
提供;requirements 在 systemCommand 启动之后按声明顺序列出 kind 为 agent、
id 为 Agent ID 的使用方。新增 fixture command-installer-agent.plugin.json 和
三个计划用例(列出使用方、受管目录计划、拒绝没有启动或 Agent 工具用到的命令),
契约 README、工具链参考页、能力版本表和协议更新记录同步。
- lithe_sessions_search(query、可选 agent)和 lithe_sessions_read(sessionID、可选 agent、可选 cursor),权限都是 read,参数里没有路径
- 这两个工具只在宿主声明时提供:没有声明工具清单的宿主照旧提供其余全部工具,但不提供它们;宿主只在用户打开 IDE 连接、打开“允许 MCP 客户端搜索本地会话”并同意读取至少一个 Agent 的会话时声明
- 调用 fixture 加上接受和拒绝的会话工具调用,产品工具清单 fixture 加上两个工具;单测核对只读、无路径参数、撤回声明后拒绝调用
- 新日志事件 agent.records.inspected(由 Lithe 记):只记工具名、结果条数和耗时,不记查询词、会话 ID 和内容
- ide-api v1 契约写明三个条件、结果和字节上限、错误码、不返回路径、不触发同步;更新记录在 #217 条目里补一句
- 游标用连接的密钥签名,重连后旧游标返回 INVALID_ARGUMENTS,从头读取
- 页面最多 65,536 字节文字、2,000 条消息;tooLong 表示单行超过 16 MiB;omitted 表示为长行放大的一次读取里放不下的消息条数
- lithe_sessions_read 的工具说明写明游标只在本连接有效
@xiaoyumuxi xiaoyumuxi changed the title feat(agents): usage 与 stats 回答带按模型排列的输出速度中位数 speeds feat(agents): 用量速度排行、会话分页读取、Agent 命令行工具安装和 IDE 连接的会话搜索(API-45 0 内补充) Nov 28, 2026
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review November 28, 2026 06:21
@xiaoyumuxi
xiaoyumuxi merged commit 7fd652a into main Nov 28, 2026
11 checks passed
xiaoyumuxi added a commit that referenced this pull request Nov 28, 2026
* feat(agents): 会话列表按目录筛选与排序,回答消息数、子代理数、模型、最后一条消息位置和整表计数(API-45 0 内补充)

* docs(plugins): 协议更新记录加 #219,已合入的 #215、#216、#217 移到时间线
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant