@@ -1648,36 +1648,44 @@ COMMAND, when present, may be a shell command string or an argv vector."
16481648 :expanded agent-shell-thought-process-expand-by-default))))
16491649 (map-put! state :last-entry-type "agent_thought_chunk")))
16501650 ((equal (map-nested-elt acp-notification '(params update sessionUpdate)) "agent_message_chunk")
1651- ;; Notification is out of context (session/prompt finished).
1652- ;; Cannot derive where to display, so show in minibuffer.
1653- (if (not (agent-shell--active-requests-p state))
1654- (when acp-logging-enabled
1655- (message "Agent message (stale, consider reporting to ACP agent): %s"
1656- (truncate-string-to-width (map-nested-elt acp-notification '(params update content text)) 100)))
1657- (unless (equal (map-elt state :last-entry-type) "agent_message_chunk")
1658- (map-put! state :chunked-group-count (1+ (map-elt state :chunked-group-count)))
1651+ (let ((chunk-text (map-nested-elt acp-notification '(params update content text))))
1652+ ;; An empty chunk while already streaming message text
1653+ ;; indicates a content block boundary (the model resumed
1654+ ;; after a tool call within the same turn). Convert to a
1655+ ;; paragraph break so the two blocks don't run together.
1656+ (when (and (equal (map-elt state :last-entry-type) "agent_message_chunk")
1657+ (stringp chunk-text)
1658+ (string-empty-p chunk-text))
1659+ (setq chunk-text "\n\n"))
1660+ ;; Notification is out of context (session/prompt finished).
1661+ ;; Cannot derive where to display, so show in minibuffer.
1662+ (if (not (agent-shell--active-requests-p state))
1663+ (when acp-logging-enabled
1664+ (message "Agent message (stale, consider reporting to ACP agent): %s"
1665+ (truncate-string-to-width chunk-text 100)))
1666+ (unless (equal (map-elt state :last-entry-type) "agent_message_chunk")
1667+ (map-put! state :chunked-group-count (1+ (map-elt state :chunked-group-count)))
1668+ (agent-shell--append-transcript
1669+ :text (format "\n## Agent (%s)\n\n" (format-time-string "%F %T"))
1670+ :file-path agent-shell--transcript-file))
1671+ ;; Indent markdown headers in LLM output so they nest
1672+ ;; below the transcript's ## section headers. Applied
1673+ ;; per-chunk: if a header is split across chunks it may
1674+ ;; not be indented (graceful degradation).
16591675 (agent-shell--append-transcript
1660- :text (format "\n## Agent (%s)\n\n" (format-time-string "%F %T"))
1661- :file-path agent-shell--transcript-file))
1662- ;; Indent markdown headers in LLM output so they nest
1663- ;; below the transcript's ## section headers. Applied
1664- ;; per-chunk: if a header is split across chunks it may
1665- ;; not be indented (graceful degradation).
1666- (agent-shell--append-transcript
1667- :text (agent-shell--indent-markdown-headers
1668- (map-nested-elt acp-notification '(params update content text)))
1669- :file-path agent-shell--transcript-file)
1670- (agent-shell--update-fragment
1671- :state state
1672- :block-id (format "%s-agent_message_chunk"
1673- (map-elt state :chunked-group-count))
1674- :body (map-nested-elt acp-notification '(params update content text))
1675- :create-new (not (equal (map-elt state :last-entry-type)
1676- "agent_message_chunk"))
1677- :append t
1678- :navigation 'never
1679- :render-body-images t)
1680- (map-put! state :last-entry-type "agent_message_chunk")))
1676+ :text (agent-shell--indent-markdown-headers chunk-text)
1677+ :file-path agent-shell--transcript-file)
1678+ (agent-shell--update-fragment
1679+ :state state
1680+ :block-id (format "%s-agent_message_chunk"
1681+ (map-elt state :chunked-group-count))
1682+ :body chunk-text
1683+ :create-new (not (equal (map-elt state :last-entry-type)
1684+ "agent_message_chunk"))
1685+ :append t
1686+ :navigation 'never
1687+ :render-body-images t)
1688+ (map-put! state :last-entry-type "agent_message_chunk"))))
16811689 ((equal (map-nested-elt acp-notification '(params update sessionUpdate)) "user_message_chunk")
16821690 ;; Only handle user_message_chunks when there's an active session/load
16831691 ;; or session/push to avoid inserting a redundant shell prompt
0 commit comments