Repository navigation
fix(acp-server): show a running command's output to editors without terminals - #5525
Merged
Merged
Conversation
…erminals When the editor does not offer terminals, kimi acp runs commands itself. The engine reports their output while they run as tool.updated events with an output chunk, but the ACP session only read the status field of those events, so the editor saw nothing until the command ended. Forward the output as tool_call_update text content. ACP replaces the content on every update, so each update carries the output so far: the latest 50,000 characters, marked as truncated once earlier output was cut, and at most one update every 250 ms per tool call, with the first one sent at once. Chunks whose byte offset does not continue the output are dropped. A call shown on an editor terminal is not forwarded, and nothing is sent for a call once it has its result, which also covers commands moved to the background. Bring back the three E2E cases that were left out on the bare editor for this gap.
🦋 Changeset detectedLatest commit: 22cd736 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
…output # Conflicts: # tests/e2e/AGENTS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Screenshots / Recordings
编辑器不声明终端时,
kimi acp跑printf 'rea%s\n' dy; sleep 30,编辑器收到的这张工具卡的通知(节选,省略了sessionId)。修复前的取自 E2Eacp-bare跑法的失败附件,修复后的取自 acp-server 新增的集成测试,所以调用 id 不同:修复前(
ready在第一秒就打印了,编辑器要到 30 秒后命令结束才看到):修复后(命令还在跑时就收到已打印的内容;用户停掉命令后,结果里也还在):
Requirement or Bug
编辑器在
initialize里不声明terminal时,kimi acp在本机自己跑命令。命令跑着的时候编辑器看不到任何输出,要等命令结束才一次给出。长命令(构建、测试)跑着时,用户看不到进度,也就判断不了要不要停。TUI、Web、Desktop,以及声明了终端的编辑器,都能看到运行中的输出。这个 PR 之后,这类编辑器在命令运行中就能看到它已经打印的内容。
Bug Reproduction Steps
terminal能力的 ACP 客户端连上kimi acp,让 agent 运行printf 'rea%s\n' dy; sleep 30。ready要到命令结束时才随结果一起出现。Root Cause
输出其实已经到了 ACP 宿主,是宿主自己丢掉的:
tool.updated,带output: { offset, text }(packages/agent-core-v2/src/agent/toolExecutor/toolExecutorService.ts的observe)。klient 的事件契约里也有这个字段。packages/acp-server/src/session.ts的onToolUpdated只读fields.status(「Running: …」标题),output整个被忽略了。声明了终端时没有这个问题:命令跑在编辑器的终端里,卡片内容是终端,编辑器自己显示输出。
这是根本修复:把引擎已经发出的运行中输出转给编辑器,和 KAP(Web、Desktop)、TUI 用的是同一份数据。
Code Changes
packages/acp-server/src/live-output.ts:按调用保存累积的文字、下一个 offset 和限频定时器。单独成模块是为了能用假时钟测限频,session.ts只负责判断哪些调用要转发、把结果发出去。tool_call_update.content是整体替换,没有追加。所以要截断、要限频,否则一条输出很多的命令会发出大量大消息。MAX_LIVE_OUTPUT_CHARS一样是 50,000 个字符。OUTPUT_POLL_MS一样是 250 ms。conversationFeed.ts一样,引擎的 offset 是输出日志的字节数。toolCallStreamArgs里」判断,这是现有的、从调用开始到结果之间的状态。content就是完整输出,会替换掉运行中的内容,补发只会多一条马上被覆盖的消息。阅读顺序:
live-output.ts,然后session.ts的onToolUpdated、onToolResult、attachTerminal。events-map.ts只多了一个构造通知的函数。用户文档docs/{en,zh}/reference/kimi-acp.md的terminal/create一行补了一句:不声明终端时,运行中的输出以tool_call_update的文字内容发出。Behavior Changes and Affected Users
tool_call_update,内容是已打印的输出(最后 50,000 个字符,每条命令最多每 250 ms 一次);卡片里原来的参数文字被输出替换,参数仍在rawInput里tool_call_updatetool_call_update,随即被结果替换session/load回放使用方:Zed 等 ACP 客户端,尤其是不声明
terminal能力的。packages/acp-server属于契约目录:通知的形状都是协议里已有的tool_call_update,只是运行中多发了几条,上一个版本的客户端不需要改动。覆盖:
packages/acp-server/test/live-output.test.ts(假时钟):第一段立即发出、之后每个间隔最多一条且带全部已打印内容;各调用互不影响;offset 对不上的块丢掉,offset 按字节算(含多字节字符);超长输出只留最后 50,000 个字符并标明截断;结束或 dispose 之后不再发送,包括还没发的那一条。packages/acp-server/test/e2e-turn.test.ts新增 2 条:ready;停掉之后,失败的结果里也还在。修复前它失败。acp-bare下原先排除的 3 条放回来了(turn/stop-running-command、expectTool和stop自测里各一条运行中输出的用例),tests/e2e/AGENTS.md里对应的说明一并更新。修复前这 3 条在acp-bare上都超时在「运行中、输出ready」这一步。没有覆盖:
本机验证(macOS)
ready;修复后通过。把session.ts里「接上终端就不转发」的判断临时去掉,终端用例失败;恢复后通过。session.ts临时换回 main 的版本并重新构建,放回的 3 条在acp-bare上都失败在「运行中、输出ready」;换回修复后通过。acp、acp-bare上各跑 10 遍,60/60 通过。这 3 个文件的全部用例在两种跑法上:72 通过,4 条是只在 TUI 上跑的用例,按设定跳过。acp和acp-bare):406 条,320 通过,86 条按场景设定跳过,没有失败。packages/acp-server的类型检查通过、全部 203 条测试通过;tests/e2e的类型检查通过;pnpm lint、pnpm run check:duplication以 0 退出。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.