diff --git a/src/auto-reply/command-reply.ts b/src/auto-reply/command-reply.ts index 8a7c42fd3..e0b6c14c1 100644 --- a/src/auto-reply/command-reply.ts +++ b/src/auto-reply/command-reply.ts @@ -300,7 +300,7 @@ export async function runCommandReply( const parsed = trimmed ? agent.parseOutput(trimmed) : undefined; const parserProvided = !!parsed; - // Collect one message per assistant text from parseOutput (tau RPC can emit many). + // Collect assistant texts and tool results from parseOutput (tau RPC can emit many). const parsedTexts = parsed?.texts?.map((t) => t.trim()).filter(Boolean) ?? []; const parsedToolResults = @@ -309,15 +309,7 @@ export async function runCommandReply( type ReplyItem = { text: string; media?: string[] }; const replyItems: ReplyItem[] = []; - for (const t of parsedTexts) { - const { text: cleanedText, mediaUrls: mediaFound } = - splitMediaFromOutput(t); - replyItems.push({ - text: cleanedText, - media: mediaFound?.length ? mediaFound : undefined, - }); - } - + // When verbose is on, surface tool results first (before assistant summary) to mirror chat ordering. if (verboseLevel === "on") { for (const tr of parsedToolResults) { const prefixed = `🛠️ ${tr}`; @@ -330,6 +322,15 @@ export async function runCommandReply( } } + for (const t of parsedTexts) { + const { text: cleanedText, mediaUrls: mediaFound } = + splitMediaFromOutput(t); + replyItems.push({ + text: cleanedText, + media: mediaFound?.length ? mediaFound : undefined, + }); + } + // If parser gave nothing, fall back to raw stdout as a single message. if (replyItems.length === 0 && trimmed && !parserProvided) { const { text: cleanedText, mediaUrls: mediaFound } = diff --git a/src/index.core.test.ts b/src/index.core.test.ts index e97ee28d8..c2bf466ce 100644 --- a/src/index.core.test.ts +++ b/src/index.core.test.ts @@ -744,10 +744,9 @@ describe("config and templating", () => { expect(rpcSpy).toHaveBeenCalled(); const payloads = Array.isArray(res) ? res : res ? [res] : []; expect(payloads.length).toBeGreaterThanOrEqual(2); - expect(payloads[0]?.text).toContain("summary"); - expect(payloads.find((p) => p.text?.includes("🛠️"))?.text).toContain( - "ls output", - ); + expect(payloads[0]?.text).toContain("🛠️"); + expect(payloads[0]?.text).toContain("ls output"); + expect(payloads[1]?.text).toContain("summary"); }); it("prepends session hint when new session and verbose on", async () => {