Support streaming tool output and deduplication#7
Draft
timvisher-dd wants to merge 1 commit intomainfrom
Draft
Conversation
3415d07 to
9101647
Compare
f16181f to
083af54
Compare
083af54 to
95686f7
Compare
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.
Closes xenodium#342
Closes xenodium#343
Checklist
M-x checkdocandM-x byte-compile-file.Problem
The two most popular agent ACPs,
codex-acpandclaude-agent-acp, perform very poorly inagent-shellwhen tool executions emit a lot of text:codex-acp: O(n²) rendering and massive data transfer. A 35k-line bash command takes ~60s and transfers ~890 MB of JSON — a 3,000× amplification of ~280 KB actual output. Each
tool_call_updatecarries the full accumulated output; agent-shell replaces the entire fragment body and rerunsmarkdown-overlays-puton every update.claude-agent-acp: output is silently lost. The same command truncates to 241 of 35,001 lines. The user sees raw
<persisted-output>XML tags rendered verbatim in the shell buffer.Cause
agent-shell does not advertise
_meta.terminal_outputinclientCapabilitiesduring the ACPinitializehandshake. Without this capability:tool_call_update(O(n²) content growth).Fix
Advertise
_meta.terminal_outputduring initialize and handle the resulting streaming behavior:acp.elto accept:terminal-capabilityand:meta-capabilitiesonacp-make-initialize-request.agent-shell.elduring initialize._meta.terminal_output.datachunks (codex-acp) and batch_meta.terminal_outputresults (claude-agent-acp) in a new streaming handler with deduplication.<persisted-output>tags and render previews cleanly.Implementation
New files
agent-shell-meta.el— extractors for ACP_metapayloads:agent-shell--meta-lookup— key lookup handling both symbol and string keys in alists.agent-shell--meta-find-tool-response— walks any_metanamespace to find atoolResponsevalue.agent-shell--tool-call-meta-response-text— extracts stdout text from_meta.*.toolResponsein its various shapes (string, alist withstdoutkey, vector of content blocks).agent-shell--tool-call-terminal-output-data— extracts_meta.terminal_output.data.agent-shell-streaming.el— streaming tool call update handler:agent-shell--tool-call-normalize-output— strips markdown fences, strips<persisted-output>XML tags (rendering the preview withfont-lock-comment-face), and ensures trailing newlines.agent-shell--append-tool-call-output— accumulates streamed output in the state's:tool-callshash under an:accumulatedkey per tool call ID.agent-shell--handle-tool-call-update-streaming— the main handler, replacing the inlinetool_call_updateblock inagent-shell.el. Three branches:_meta.terminal_output.data): normalize the chunk, accumulate it, and immediately append it to the fragment body for live streaming._meta.*.toolResponse): normalize and accumulate silently (rendered only on final update to avoid duplication)."completed"or"failed"): render accumulated output (or fall back tocontenttext), log to transcript, clean up permission dialogs, and apply title/label updates.agent-shell--mark-tool-calls-cancelled— marks all in-progress tool calls as cancelled (called fromagent-shell-interrupt).Changes to
agent-shell.el(require 'agent-shell-streaming)added.tool_call_updaterendering block is replaced by a single call toagent-shell--handle-tool-call-update-streaming. The metadata save (title/description/command/raw-input/diff) remains inline before the handler call.initializerequest now passes:terminal-capability tand:meta-capabilities '((terminal_output . t))toacp-make-initialize-request.agent-shell-interruptcallsagent-shell--mark-tool-calls-cancelledafter sending the cancel notification.shell-maker-define-major-modecall passes'agent-shell-mode-map(quoted symbol) instead of the bare variable.Tests
7 new tests in
tests/agent-shell-streaming-tests.el:agent-shell--tool-call-meta-response-text-test— extracts text from_meta.claudeCode.toolResponse.stdout.agent-shell--tool-call-normalize-output-test— strips fences and ensures trailing newline.agent-shell--tool-call-normalize-output-persisted-output-test— strips<persisted-output>tags.agent-shell--tool-call-update-writes-output-test— verifies accumulated output is written to the fragment body.agent-shell--tool-call-meta-response-no-duplication-test— meta response text is rendered once, not duplicated with content.agent-shell-initialize-request-meta-capabilities-test— the initialize request includes_meta.terminal_output.agent-shell--tool-call-terminal-output-data-streaming-test— codex-style_meta.terminal_output.datachunks are accumulated and rendered incrementally.Perf measurements
Test:
for x in {0..35000}; do printf 'line %d\n' "$x"; done(35,001 lines)codex-acp
~8× faster. Content drops from ~900 MB to ~3 KB.
claude-agent-acp
No timing improvement (execution is server-side), but
<persisted-output>tags are handled cleanly.Prerequisite: acp.el changes
acp.elneeds to accept:terminal-capabilityand:meta-capabilitieskeyword arguments onacp-make-initialize-request. See xenodium/acp.el#15.