Support streaming tool output and deduplication#7
Draft
timvisher-dd wants to merge 48 commits intomainfrom
Draft
Support streaming tool output and deduplication#7timvisher-dd wants to merge 48 commits intomainfrom
timvisher-dd wants to merge 48 commits intomainfrom
Conversation
3415d07 to
9101647
Compare
df9a77f to
68b7774
Compare
Point .claude, .codex, .gemini directories to .agents and their respective markdown files to AGENTS.md so all IDE agents share a single source of truth. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
CI runs four jobs: byte-compilation + ERT tests, agent config symlink verification, dependency DAG cycle detection, and README update check. bin/test drives all checks locally by parsing ci.yml with yq so the two stay in sync automatically. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ning - Quote agent-shell-mode-map symbol in shell-maker-define-major-mode (macros expect the symbol name, not the variable value) - Fix decorator tests: use setq-local inside let instead of let* shadowing the buffer-local, so buffer-local-value finds the binding - Suppress message output in copy-session-id test - Add forward declaration for agent-shell-text-file-capabilities in devcontainer module to silence byte-compiler Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New module for checking buffer-level invariants during agent-shell operation: process-mark ordering, fragment ordering per namespace, ui-state property contiguity, and content-store consistency. Includes a per-buffer event ring for tracing, rate-limited violation reporting with debug bundle capture, and comprehensive ERT tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New utility module for walking nested _meta namespaces in ACP tool call updates. Handles multiple agent response shapes (stdout string, content string, vector of text items) and provides clean accessors for toolResponse text and streaming terminal output data. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
New module for incremental tool call output rendering. Accumulates chunks from _meta.*.toolResponse and _meta.terminal_output, strips backtick fences and <persisted-output> tags, and appends deltas in-place to avoid O(n²) full-block rebuilds during streaming. Includes per-tool-call output markers, UI state caching, and comprehensive tests covering codex-acp terminal output, claude-agent batch results, and error handling. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Wire the new streaming, meta, and invariants libraries into the core agent-shell and UI layers: - Advertise _meta.terminal_output capability in session/new - Extract tool-call update handler into agent-shell-streaming - Deduplicate thought chunks via accumulated-delta tracking - Add insert-cursor (marker with insertion-type t) so fragments appear in creation order above the prompt - Preserve process-mark across fragment updates so context insertion and prompt position remain stable - Debounce markdown overlay application during streaming appends to avoid O(n²) re-parsing - In-place body append in agent-shell-ui to avoid delete-and-reinsert that displaces point - Fix context insertion: goto-char insert-start so point lands at the prompt after inserting context - Add context insertion regression tests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add live-validate command documentation for verifying rendering pipeline changes with a live batch session - Update AGENTS.md development workflow with live-validate step - Update README.org features list: expand CI sub-features, add streaming dedup, DWIM context insertion, and runtime invariants Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
62b5363 to
cb357ac
Compare
Signed-off-by: Rainer Poisel <rainer@embedded-focus.com>
The help functions require transient at compile time for the =transient-define-prefix= macro and the transient definitions need to be at the top level to satisfy the byte compiler.
This change replaces the use of =/tmp= (~temporary-file-directory~) for caching with the user's cache directory as given by the XDG Base Directory specification or a system-dependent fallback. This avoids permission conflicts when multiple users use agent-shell on a shared system.
Also document Codex non-standard use
If I see it correctly, pngpaste is for MacOS and xclip handles Xorg desktops. This adds ~wl-paste~ for Wayland environments.
`agent-shell-restart` kills the buffer and calls `agent-shell--start` directly after. Since `kill-buffer` will have the effect of changing the default directory to the "other buffer", `agent-shell--start` can possibly end up creating the new shell an unexpected project (e.g if the user's last buffer was in a different project, the new shell will be made for this project instead of the expected behavior of being for the same project the original shell was for). The fix is to bind `default-directory` around calling `agent-shell--start`, since this will retain the default directory across the `kill-buffer` call. `agent-shell-reload` was also affected, since it delegates to `agent-shell-restart`. A new test is added to ensure that, in a frame whose last buffer was another project than the current shell's, calling restart will still use the shell's project as expected. Without the fix, the test fails. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
`font-get :size` returns 0 when the default font is configured via `:height` (1/10pt units) rather than an explicit pixel size. This is common on macOS (e.g., Menlo at `:height 120`). The 0 propagates into the SVG `<text>` elements as `font-size="0"`, rendering all header text invisible while the icon still displays. Fall back to `frame-char-height` when `font-get :size` returns 0. Fixes xenodium#462
The old call to ~call-process~ would merge stdout and stderr into a single stream that would always create ~file-path~ even if no image was in the clipboard. This could then lead downstream code to erroneously assume that an image had been found even though an error was signaled.
Fixes xenodium#465 When loading a session with `agent-shell-prefer-session-resume` set to nil, `user_message_chunk` notifications replay the conversation history. Non-text content (e.g. images) lacks the `text` field, causing `(wrong-type-argument stringp nil)` when passed to `propertize`. Fall back to a `[type]` placeholder (e.g. `[image]`) when `text` is nil.
Skip make-frame in noninteractive mode; buffer-list ordering achieves the same fallback behavior without needing a terminal frame. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The rebase introduced an extra closing paren in the agent-shell--permission-title-execute-fenced-test, causing a read syntax error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
a2a672e to
95c8c17
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.