# Add agent-shell-quote-reply and DWIM context prefill for queue-compose#12
Draft
timvisher-dd wants to merge 1 commit into
Draft
# Add agent-shell-quote-reply and DWIM context prefill for queue-compose#12timvisher-dd wants to merge 1 commit into
timvisher-dd wants to merge 1 commit into
Conversation
`agent-shell-quote-reply' pops the queue-compose buffer prefilled with the agent's last prose reply wrapped as a GFM block quote, and `agent-shell-queue-request' now gathers any DWIM context available in the source buffer (active region, error at point, dired marked files) and prefills the compose buffer with it. Regions from buffers with no file association are wrapped as GFM block quotes; file-visiting and dired context keep their existing purpose-built decoration. Cannot use `shell-maker--command-and-response-at-point' to find the last reply because `shell-maker--extract-history' returns the entire rendered turn span, including tool-call drawers and thought blocks. `agent-shell--last-agent-message-text' walks back to the most recent `agent_message_chunk' fragment and pulls the raw body from `agent-shell-ui--content-store' instead. `text-property-search-backward' returns nil when its predicate rejects the nearest match rather than continuing the walk, so the implementation loops over property changes and applies the suffix check manually — otherwise a tool-call fragment between point-max and the agent message silently swallows the result. Bound to `q' in the `agent-shell-help-menu' "Insert" group. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Two related compose-buffer enhancements:
agent-shell-quote-reply(new) pops the queue-compose bufferprefilled with the agent's last prose reply, wrapped as a GFM
block quote. Bound to
qin theagent-shell-help-menu"Insert" group.
agent-shell-queue-request, when called interactively withouta prompt, now gathers any DWIM context available in the source
buffer (active region, error at point, dired marked files) and
prefills the compose buffer with it. Regions from buffers with
no file association are wrapped as GFM block quotes; file-
visiting and dired context keep their existing purpose-built
decoration.
Why not just use
shell-maker--command-and-response-at-point?It returns the entire rendered turn span —
shell-maker--extract- history' takes abuffer-substring' between`' and the next prompt, so tool-call
drawers and thought blocks are included. For a quote-reply that's
not what you want.
agent-shell--last-agent-message-text' walks back frompoint-max' to the most recent fragment whoseagent-shell-ui-state' qualified-id ends in-agent_message_chunk' and pulls the raw body from`agent-shell-ui--content-store'. Tool-call and thought fragments
are skipped by the suffix check.
`text-property-search-backward' gotcha
When its predicate rejects the nearest match, it returns nil
rather than continuing the walk. The first implementation used
the built-in predicate path and silently returned nil whenever a
tool-call fragment sat between point-max and the agent message.
The fix loops over property changes manually and applies the
suffix check each step — the regression test
(`agent-shell--last-agent-message-text-skips-tool-calls') fails
without the loop.
Test plan
tests/agent-shell-tests.el:nested code fence, already-quoted input)
skips tool calls, picks last of many, nil when empty)
no reply, pops compose with quoted reply)
agent-shell-queue-compose-pop':initial-content' (insertinto fresh buffer, append to existing draft with blank-line
separator, no-op when omitted)
agent-shell--compose-initial-content' (quotes non-file region, delegates to--context' otherwise)agent-shell-queue-request-without-prompt-pops- compose' for the new&key' signature.bin/test: 259/260 passing, 1 pre-existing skip,all CI checks green.
when prepping the PR). Worth a manual run that produces a
reply with tool calls in the same turn, then exercising
`agent-shell-quote-reply' to confirm the quoted output
contains only the prose.
Refs
agent-shell-wafa