Skip to content

# Add agent-shell-quote-reply and DWIM context prefill for queue-compose#12

Draft
timvisher-dd wants to merge 1 commit into
mainfrom
quote-reply
Draft

# Add agent-shell-quote-reply and DWIM context prefill for queue-compose#12
timvisher-dd wants to merge 1 commit into
mainfrom
quote-reply

Conversation

@timvisher-dd
Copy link
Copy Markdown
Owner

Summary

Two related compose-buffer enhancements:

  • agent-shell-quote-reply (new) pops the queue-compose buffer
    prefilled with the agent's last prose reply, wrapped as a GFM
    block quote. Bound to q in the agent-shell-help-menu
    "Insert" group.
  • agent-shell-queue-request, when called interactively without
    a 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 a buffer-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 from point-max' to the most recent fragment whose
agent-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

  • 13 new ERT tests in tests/agent-shell-tests.el:
    • `agent-shell--gfm-blockquote' (single-line, multiline,
      nested code fence, already-quoted input)
    • `agent-shell--last-agent-message-text' (returns body,
      skips tool calls, picks last of many, nil when empty)
    • `agent-shell-quote-reply' (error outside shell, error when
      no reply, pops compose with quoted reply)
    • agent-shell-queue-compose-pop' :initial-content' (insert
      into 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)
    • Updated agent-shell-queue-request-without-prompt-pops- compose' for the new &key' signature.
  • Full bin/test: 259/260 passing, 1 pre-existing skip,
    all CI checks green.
  • Live-validate: not yet run (1Password CLI not signed in
    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

`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>
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