xonecas.io
64875
Mc

mini-coder / commit c8ada3e

feat: add parallel tool call tests and manual UI one-shot script

- Add 5 parallel tool call tests to ui-audit.test.ts:
  - Two parallel shells with ordering verification
  - Three mixed tools (shell + subagent + readSkill)
  - Blank line separation between parallel calls
  - Mixed success/error in parallel calls
  - Reasoning → parallel calls → reasoning → reply
- Move eventsFrom/turnDone/shellResult helpers to test-helpers.ts,
  eliminating duplication between stream-render.test.ts and ui-audit.test.ts
- Add scripts/ui-oneshot.ts: 14 visual scenarios for manual inspection
  covering banner, user messages, reasoning, sequential/parallel tools,
  mixed tool types, errors, context pruning, MCP, and a realistic
  multi-turn session
- Add 'ui-oneshot' npm script; run with: bun run ui-oneshot

xonecas2026-03-16 c8ada3e4817362b57c6850d0c162a4a839816ea0 parent 47490f0

5 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

package.json+2−1
@@ -17,7 +17,8 @@
1717 "knip": "knip",
1818 "test": "bun test --only-failures",
1919 "test:verbose": "bun test",
20- "jscpd": "jscpd src"
20+ "jscpd": "jscpd src",
21+ "ui-oneshot": "bun scripts/ui-oneshot.ts"
2122 },
2223 "dependencies": {
2324 "@ai-sdk/anthropic": "^3.0.60",
scripts/ui-oneshot.ts+449−0
@@ -0,0 +1,449 @@
1+#!/usr/bin/env bun
2+/**
3+ * Manual one-shot UI test: renders example scenarios to stdout
4+ * so you can visually inspect the console output.
5+ *
6+ * Usage: bun scripts/ui-oneshot.ts
7+ */
8+import type { TurnEvent } from "../src/llm-api/types.ts";
9+import { renderBanner, renderError, renderUserMessage, writeln } from "../src/cli/output.ts";
10+import { Spinner } from "../src/cli/spinner.ts";
11+import { renderTurn } from "../src/cli/stream-render.ts";
12+import { renderToolCall, renderToolResult } from "../src/cli/tool-render.ts";
13+
14+function eventsFrom(events: TurnEvent[]): AsyncIterable<TurnEvent> {
15+ return (async function* () {
16+ for (const event of events) {
17+ yield event;
18+ }
19+ })();
20+}
21+
22+function done(): TurnEvent {
23+ return {
24+ type: "turn-complete",
25+ inputTokens: 1234,
26+ outputTokens: 567,
27+ contextTokens: 50000,
28+ messages: [],
29+ };
30+}
31+
32+function shell(opts: {
33+ stdout?: string;
34+ stderr?: string;
35+ exitCode?: number;
36+ success?: boolean;
37+}) {
38+ return {
39+ stdout: opts.stdout ?? "",
40+ stderr: opts.stderr ?? "",
41+ exitCode: opts.exitCode ?? 0,
42+ success: opts.success ?? true,
43+ timedOut: false,
44+ };
45+}
46+
47+function separator(title: string) {
48+ writeln(`\n${"─".repeat(60)}`);
49+ writeln(` ${title}`);
50+ writeln(`${"─".repeat(60)}\n`);
51+}
52+
53+async function main() {
54+ // ── Banner ──────────────────────────────────────────────
55+ separator("1. Banner");
56+ renderBanner("claude-sonnet-4-20250514", "~/projects/my-app");
57+
58+ // ── User message ───────────────────────────────────────
59+ separator("2. User message (single line)");
60+ renderUserMessage("Fix the failing tests in src/utils.ts");
61+
62+ separator("3. User message (multi-line)");
63+ renderUserMessage(
64+ "Please review these files:\n- src/index.ts\n- src/utils.ts\n- src/config.ts",
65+ );
66+
67+ // ── Simple text reply ──────────────────────────────────
68+ separator("4. Simple text reply (no reasoning)");
69+ await renderTurn(
70+ eventsFrom([
71+ { type: "text-delta", delta: "I'll take a look at those files for you." },
72+ done(),
73+ ]),
74+ new Spinner(),
75+ );
76+
77+ // ── Reasoning + text reply ─────────────────────────────
78+ separator("5. Reasoning → text reply");
79+ await renderTurn(
80+ eventsFrom([
81+ {
82+ type: "reasoning-delta",
83+ delta:
84+ "The user wants me to fix failing tests. Let me check the test file first to understand the failures.",
85+ },
86+ {
87+ type: "text-delta",
88+ delta:
89+ "I'll start by examining the test file to understand what's failing.",
90+ },
91+ done(),
92+ ]),
93+ new Spinner(),
94+ );
95+
96+ // ── Single tool call ───────────────────────────────────
97+ separator("6. Single tool call (shell)");
98+ await renderTurn(
99+ eventsFrom([
100+ {
101+ type: "tool-call-start",
102+ toolName: "shell",
103+ toolCallId: "t1",
104+ args: { command: "bun test src/utils.test.ts 2>&1 | tail -20" },
105+ },
106+ {
107+ type: "tool-result",
108+ toolName: "shell",
109+ toolCallId: "t1",
110+ isError: false,
111+ result: shell({
112+ stdout:
113+ "src/utils.test.ts:\n(pass) parseConfig > handles defaults\n(fail) parseConfig > validates required fields\n(pass) parseConfig > merges overrides\n\n 2 pass\n 1 fail\n 5 expect() calls",
114+ exitCode: 1,
115+ success: false,
116+ }),
117+ },
118+ {
119+ type: "text-delta",
120+ delta:
121+ "I can see one test is failing. Let me look at the test to understand the expected behavior.",
122+ },
123+ done(),
124+ ]),
125+ new Spinner(),
126+ );
127+
128+ // ── Parallel tool calls ────────────────────────────────
129+ separator("7. Parallel tool calls (2 shells)");
130+ await renderTurn(
131+ eventsFrom([
132+ {
133+ type: "reasoning-delta",
134+ delta: "I need to read both the source and test file to understand the issue.",
135+ },
136+ {
137+ type: "tool-call-start",
138+ toolName: "shell",
139+ toolCallId: "p1",
140+ args: { command: "cat src/utils.ts" },
141+ },
142+ {
143+ type: "tool-call-start",
144+ toolName: "shell",
145+ toolCallId: "p2",
146+ args: { command: "cat src/utils.test.ts" },
147+ },
148+ {
149+ type: "tool-result",
150+ toolName: "shell",
151+ toolCallId: "p1",
152+ isError: false,
153+ result: shell({
154+ stdout:
155+ 'export function parseConfig(raw: unknown): Config {\n if (typeof raw !== "object" || raw === null) {\n throw new Error("invalid config");\n }\n return { ...defaults, ...raw };\n}',
156+ }),
157+ },
158+ {
159+ type: "tool-result",
160+ toolName: "shell",
161+ toolCallId: "p2",
162+ isError: false,
163+ result: shell({
164+ stdout:
165+ 'test("validates required fields", () => {\n expect(() => parseConfig(null)).toThrow("invalid config");\n expect(() => parseConfig({})).toThrow("missing required");\n});',
166+ }),
167+ },
168+ {
169+ type: "text-delta",
170+ delta:
171+ "Found the issue! The test expects `parseConfig({})` to throw `\"missing required\"`, but the function only throws for non-objects.",
172+ },
173+ done(),
174+ ]),
175+ new Spinner(),
176+ );
177+
178+ // ── Parallel mixed tools ───────────────────────────────
179+ separator("8. Parallel mixed tools (shell + subagent + readSkill)");
180+ await renderTurn(
181+ eventsFrom([
182+ {
183+ type: "tool-call-start",
184+ toolName: "shell",
185+ toolCallId: "m1",
186+ args: { command: "wc -l src/**/*.ts" },
187+ },
188+ {
189+ type: "tool-call-start",
190+ toolName: "subagent",
191+ toolCallId: "m2",
192+ args: { prompt: "Review the error handling patterns in src/", agentName: "reviewer" },
193+ },
194+ {
195+ type: "tool-call-start",
196+ toolName: "readSkill",
197+ toolCallId: "m3",
198+ args: { name: "testing" },
199+ },
200+ {
201+ type: "tool-result",
202+ toolName: "shell",
203+ toolCallId: "m1",
204+ isError: false,
205+ result: shell({
206+ stdout: " 142 src/index.ts\n 87 src/utils.ts\n 45 src/config.ts\n 274 total",
207+ }),
208+ },
209+ {
210+ type: "tool-result",
211+ toolName: "subagent",
212+ toolCallId: "m2",
213+ isError: false,
214+ result: { inputTokens: 2500, outputTokens: 800, agentName: "reviewer" },
215+ },
216+ {
217+ type: "tool-result",
218+ toolName: "readSkill",
219+ toolCallId: "m3",
220+ isError: false,
221+ result: {
222+ skill: { name: "testing", description: "Testing best practices", source: "local" },
223+ },
224+ },
225+ {
226+ type: "text-delta",
227+ delta: "Based on the code review and testing guidelines, here are my recommendations.",
228+ },
229+ done(),
230+ ]),
231+ new Spinner(),
232+ );
233+
234+ // ── Tool error ─────────────────────────────────────────
235+ separator("9. Tool call with error");
236+ await renderTurn(
237+ eventsFrom([
238+ {
239+ type: "tool-call-start",
240+ toolName: "shell",
241+ toolCallId: "e1",
242+ args: { command: "rm -rf /protected" },
243+ },
244+ {
245+ type: "tool-result",
246+ toolName: "shell",
247+ toolCallId: "e1",
248+ isError: true,
249+ result: "permission denied: /protected",
250+ },
251+ {
252+ type: "text-delta",
253+ delta: "I don't have permission to modify that directory.",
254+ },
255+ done(),
256+ ]),
257+ new Spinner(),
258+ );
259+
260+ // ── Parallel with mixed success/error ──────────────────
261+ separator("10. Parallel calls: one success, one error");
262+ await renderTurn(
263+ eventsFrom([
264+ {
265+ type: "tool-call-start",
266+ toolName: "shell",
267+ toolCallId: "x1",
268+ args: { command: "cat README.md" },
269+ },
270+ {
271+ type: "tool-call-start",
272+ toolName: "shell",
273+ toolCallId: "x2",
274+ args: { command: "cat MISSING.md" },
275+ },
276+ {
277+ type: "tool-result",
278+ toolName: "shell",
279+ toolCallId: "x1",
280+ isError: false,
281+ result: shell({ stdout: "# My Project\n\nA cool project." }),
282+ },
283+ {
284+ type: "tool-result",
285+ toolName: "shell",
286+ toolCallId: "x2",
287+ isError: false,
288+ result: shell({
289+ stderr: "cat: MISSING.md: No such file or directory",
290+ exitCode: 1,
291+ success: false,
292+ }),
293+ },
294+ {
295+ type: "text-delta",
296+ delta: "README exists but MISSING.md doesn't. Let me create it.",
297+ },
298+ done(),
299+ ]),
300+ new Spinner(),
301+ );
302+
303+ // ── Context pruned ─────────────────────────────────────
304+ separator("11. Context pruned event");
305+ await renderTurn(
306+ eventsFrom([
307+ {
308+ type: "context-pruned",
309+ mode: "balanced",
310+ beforeMessageCount: 120,
311+ afterMessageCount: 80,
312+ removedMessageCount: 40,
313+ beforeTotalBytes: 65536,
314+ afterTotalBytes: 40960,
315+ removedBytes: 24576,
316+ },
317+ {
318+ type: "text-delta",
319+ delta: "I've been working on this for a while. Let me continue where I left off.",
320+ },
321+ done(),
322+ ]),
323+ new Spinner(),
324+ );
325+
326+ // ── Error rendering ────────────────────────────────────
327+ separator("12. Error messages");
328+ renderError("API rate limit exceeded. Retrying in 30s...");
329+ writeln("");
330+ renderError("Connection timed out after 60s", "Check your network connection and try again.");
331+
332+ // ── MCP tool ───────────────────────────────────────────
333+ separator("13. MCP tool call");
334+ await renderTurn(
335+ eventsFrom([
336+ {
337+ type: "tool-call-start",
338+ toolName: "mcp_github_create_issue",
339+ toolCallId: "mcp1",
340+ args: { repo: "my-org/my-repo", title: "Fix validation bug", body: "..." },
341+ },
342+ {
343+ type: "tool-result",
344+ toolName: "mcp_github_create_issue",
345+ toolCallId: "mcp1",
346+ isError: false,
347+ result: { url: "https://github.com/my-org/my-repo/issues/42" },
348+ },
349+ {
350+ type: "text-delta",
351+ delta: "Created issue #42 for tracking the validation bug.",
352+ },
353+ done(),
354+ ]),
355+ new Spinner(),
356+ );
357+
358+ // ── Full realistic session ─────────────────────────────
359+ separator("14. Realistic multi-turn snippet");
360+ renderUserMessage("Fix the type error in src/config.ts");
361+ writeln("");
362+ await renderTurn(
363+ eventsFrom([
364+ {
365+ type: "reasoning-delta",
366+ delta: "Let me look at the file to find the type error.",
367+ },
368+ {
369+ type: "tool-call-start",
370+ toolName: "shell",
371+ toolCallId: "r1",
372+ args: { command: "bun run typecheck 2>&1 | grep 'config.ts'" },
373+ },
374+ {
375+ type: "tool-result",
376+ toolName: "shell",
377+ toolCallId: "r1",
378+ isError: false,
379+ result: shell({
380+ stdout:
381+ "src/config.ts(12,5): error TS2322: Type 'string' is not assignable to type 'number'.",
382+ exitCode: 1,
383+ success: false,
384+ }),
385+ },
386+ {
387+ type: "reasoning-delta",
388+ delta:
389+ "Line 12 has a type mismatch. The port should be a number but is being set as a string.",
390+ },
391+ {
392+ type: "tool-call-start",
393+ toolName: "shell",
394+ toolCallId: "r2",
395+ args: { command: "sed -n '10,15p' src/config.ts" },
396+ },
397+ {
398+ type: "tool-result",
399+ toolName: "shell",
400+ toolCallId: "r2",
401+ isError: false,
402+ result: shell({
403+ stdout:
404+ ' const config = {\n host: env.HOST ?? "localhost",\n port: env.PORT ?? "3000",\n debug: env.DEBUG === "true",\n };',
405+ }),
406+ },
407+ {
408+ type: "tool-call-start",
409+ toolName: "shell",
410+ toolCallId: "r3",
411+ args: {
412+ command:
413+ 'mc-edit src/config.ts --old \'port: env.PORT ?? "3000"\' --new \'port: Number(env.PORT ?? "3000")\'',
414+ },
415+ },
416+ {
417+ type: "tool-result",
418+ toolName: "shell",
419+ toolCallId: "r3",
420+ isError: false,
421+ result: shell({ stdout: "ok: true\npath: src/config.ts\nchanged: true" }),
422+ },
423+ {
424+ type: "tool-call-start",
425+ toolName: "shell",
426+ toolCallId: "r4",
427+ args: { command: "bun run typecheck 2>&1" },
428+ },
429+ {
430+ type: "tool-result",
431+ toolName: "shell",
432+ toolCallId: "r4",
433+ isError: false,
434+ result: shell({ stdout: "" }),
435+ },
436+ {
437+ type: "text-delta",
438+ delta:
439+ 'Fixed the type error on line 12 of `src/config.ts`. The `port` field was being assigned a string from `env.PORT ?? "3000"` — wrapped it in `Number()` to coerce to the expected `number` type. Typecheck passes now.',
440+ },
441+ done(),
442+ ]),
443+ new Spinner(),
444+ );
445+
446+ writeln("");
447+}
448+
449+main();
src/cli/stream-render.test.ts+4−17
@@ -1,36 +1,23 @@
11 import { afterEach, describe, expect, test } from "bun:test";
22 import type { CoreMessage } from "../llm-api/turn.ts";
3-import type { TurnEvent } from "../llm-api/types.ts";
43 import { Spinner } from "./spinner.ts";
54 import { renderTurn } from "./stream-render.ts";
65 import {
76 captureStdout,
7+ eventsFrom,
88 getCapturedStdout,
99 restoreStdout,
1010 simulateTerminal,
1111 stripAnsi,
12+ turnDone,
1213 } from "./test-helpers.ts";
1314
1415 afterEach(() => {
1516 restoreStdout();
1617 });
1718
18-function eventsFrom(events: TurnEvent[]): AsyncIterable<TurnEvent> {
19- return (async function* () {
20- for (const event of events) {
21- yield event;
22- }
23- })();
24-}
25-
26-function done(messages: CoreMessage[] = []): TurnEvent {
27- return {
28- type: "turn-complete",
29- inputTokens: 1,
30- outputTokens: 2,
31- contextTokens: 3,
32- messages,
33- };
19+function done(messages: CoreMessage[] = []) {
20+ return turnDone(messages);
3421 }
3522
3623 function hasAnsi(s: string, code: string): boolean {
src/cli/test-helpers.ts+38−0
@@ -1,3 +1,5 @@
1+import type { CoreMessage } from "../llm-api/turn.ts";
2+import type { TurnEvent } from "../llm-api/types.ts";
13 import { terminal } from "./terminal-io.ts";
24
35 /** Temporarily set process.stdout.columns for terminal tests. */
@@ -111,3 +113,39 @@ export function simulateTerminal(raw: string): string {
111113
112114 return lines.join("\n");
113115 }
116+
117+/** Convert an array of TurnEvents into an AsyncIterable for renderTurn. */
118+export function eventsFrom(events: TurnEvent[]): AsyncIterable<TurnEvent> {
119+ return (async function* () {
120+ for (const event of events) {
121+ yield event;
122+ }
123+ })();
124+}
125+
126+/** Create a turn-complete event with sensible defaults. */
127+export function turnDone(messages: CoreMessage[] = []): TurnEvent {
128+ return {
129+ type: "turn-complete",
130+ inputTokens: 1,
131+ outputTokens: 2,
132+ contextTokens: 3,
133+ messages,
134+ };
135+}
136+
137+/** Shorthand for a shell result object. */
138+export function shellResult(opts: {
139+ stdout?: string;
140+ stderr?: string;
141+ exitCode?: number;
142+ success?: boolean;
143+}) {
144+ return {
145+ stdout: opts.stdout ?? "",
146+ stderr: opts.stderr ?? "",
147+ exitCode: opts.exitCode ?? 0,
148+ success: opts.success ?? true,
149+ timedOut: false,
150+ };
151+}
src/cli/ui-audit.test.ts+298−56
@@ -1,14 +1,16 @@
11 import { afterEach, describe, expect, test } from "bun:test";
2-import type { TurnEvent } from "../llm-api/types.ts";
32 import { renderError, renderUserMessage } from "./output.ts";
43 import { Spinner } from "./spinner.ts";
54 import { renderTurn } from "./stream-render.ts";
65 import {
76 captureStdout,
7+ eventsFrom,
88 getCapturedStdout,
99 restoreStdout,
10+ shellResult,
1011 simulateTerminal,
1112 stripAnsi,
13+ turnDone,
1214 } from "./test-helpers.ts";
1315 import { renderToolCall, renderToolResult } from "./tool-render.ts";
1416
@@ -16,39 +18,6 @@ afterEach(() => {
1618 restoreStdout();
1719 });
1820
19-function eventsFrom(events: TurnEvent[]): AsyncIterable<TurnEvent> {
20- return (async function* () {
21- for (const event of events) {
22- yield event;
23- }
24- })();
25-}
26-
27-function done(): TurnEvent {
28- return {
29- type: "turn-complete",
30- inputTokens: 10,
31- outputTokens: 20,
32- contextTokens: 100,
33- messages: [],
34- };
35-}
36-
37-function shellResult(opts: {
38- stdout?: string;
39- stderr?: string;
40- exitCode?: number;
41- success?: boolean;
42-}) {
43- return {
44- stdout: opts.stdout ?? "",
45- stderr: opts.stderr ?? "",
46- exitCode: opts.exitCode ?? 0,
47- success: opts.success ?? true,
48- timedOut: false,
49- };
50-}
51-
5221 // ─── Visual hierarchy documentation ───────────────────────────────────────────
5322 //
5423 // The output hierarchy from the user's perspective should be:
@@ -199,7 +168,7 @@ describe("UI audit: full turn scenarios", () => {
199168 eventsFrom([
200169 { type: "reasoning-delta", delta: "Let me think" },
201170 { type: "text-delta", delta: "Here is the answer." },
202- done(),
171+ turnDone(),
203172 ]),
204173 new Spinner(),
205174 );
@@ -229,21 +198,18 @@ describe("UI audit: full turn scenarios", () => {
229198 result: shellResult({ stdout: "file.txt" }),
230199 },
231200 { type: "text-delta", delta: "Found file.txt" },
232- done(),
201+ turnDone(),
233202 ]),
234203 new Spinner(),
235204 );
236205
237206 const plain = simulateTerminal(getCapturedStdout());
238- // Tool call at 2-space indent
239207 expect(plain).toContain(" $ ls");
240- // Tool result at 4-space indent
241208 expect(plain).toMatch(/^ {4}done/m);
242- // Reply at 0-indent with blank line before
243209 expect(plain).toContain("\n\n◆ Found file.txt");
244210 });
245211
246- test("multiple tools: each tool-call/result pair is visually grouped", async () => {
212+ test("multiple sequential tools: blank line between result and next call", async () => {
247213 captureStdout();
248214
249215 await renderTurn(
@@ -274,16 +240,12 @@ describe("UI audit: full turn scenarios", () => {
274240 isError: false,
275241 result: shellResult({ stdout: "world" }),
276242 },
277- done(),
243+ turnDone(),
278244 ]),
279245 new Spinner(),
280246 );
281247
282248 const plain = simulateTerminal(getCapturedStdout());
283- // Both tool calls present
284- expect(plain).toContain(" $ cat a.txt");
285- expect(plain).toContain(" $ cat b.txt");
286- // Blank line between first result and second call
287249 const lines = plain.split("\n");
288250 const firstResultIdx = lines.findIndex((l) =>
289251 l.match(/^ {4}done.*out: hello/),
@@ -291,7 +253,6 @@ describe("UI audit: full turn scenarios", () => {
291253 const secondCallIdx = lines.findIndex((l) => l.includes("$ cat b.txt"));
292254 expect(firstResultIdx).toBeGreaterThan(-1);
293255 expect(secondCallIdx).toBeGreaterThan(firstResultIdx);
294- // There should be a blank line between the first result and second tool call
295256 const between = lines.slice(firstResultIdx + 1, secondCallIdx);
296257 expect(between.some((l) => l.trim() === "")).toBe(true);
297258 });
@@ -317,13 +278,12 @@ describe("UI audit: full turn scenarios", () => {
317278 },
318279 { type: "reasoning-delta", delta: "plan B" },
319280 { type: "text-delta", delta: "done" },
320- done(),
281+ turnDone(),
321282 ]),
322283 new Spinner(),
323284 );
324285
325286 const plain = simulateTerminal(getCapturedStdout());
326- // Two separate reasoning blocks
327287 const reasoningCount = (plain.match(/· reasoning/g) ?? []).length;
328288 expect(reasoningCount).toBe(2);
329289 expect(plain).toContain("plan A");
@@ -346,7 +306,7 @@ describe("UI audit: full turn scenarios", () => {
346306 removedBytes: 10000,
347307 },
348308 { type: "text-delta", delta: "continuing" },
349- done(),
309+ turnDone(),
350310 ]),
351311 new Spinner(),
352312 );
@@ -361,7 +321,7 @@ describe("UI audit: full turn scenarios", () => {
361321 captureStdout();
362322
363323 await renderTurn(
364- eventsFrom([{ type: "text-delta", delta: "Hello!" }, done()]),
324+ eventsFrom([{ type: "text-delta", delta: "Hello!" }, turnDone()]),
365325 new Spinner(),
366326 );
367327
@@ -387,7 +347,7 @@ describe("UI audit: full turn scenarios", () => {
387347 isError: true,
388348 result: "command not found",
389349 },
390- done(),
350+ turnDone(),
391351 ]),
392352 new Spinner(),
393353 );
@@ -400,14 +360,298 @@ describe("UI audit: full turn scenarios", () => {
400360 test("empty turn (no text, no tools) still outputs a newline", async () => {
401361 captureStdout();
402362
403- await renderTurn(eventsFrom([done()]), new Spinner());
363+ await renderTurn(eventsFrom([turnDone()]), new Spinner());
404364
405365 const raw = getCapturedStdout();
406366 expect(raw).toContain("\n");
407367 });
408368 });
409369
410-describe("UI audit: spinner does not leak into output", () => {
370+describe("UI audit: parallel tool calls", () => {
371+ test("two parallel shell calls render both calls before any results", async () => {
372+ captureStdout();
373+
374+ await renderTurn(
375+ eventsFrom([
376+ {
377+ type: "tool-call-start",
378+ toolName: "shell",
379+ toolCallId: "p1",
380+ args: { command: "echo alpha" },
381+ },
382+ {
383+ type: "tool-call-start",
384+ toolName: "shell",
385+ toolCallId: "p2",
386+ args: { command: "echo bravo" },
387+ },
388+ {
389+ type: "tool-result",
390+ toolName: "shell",
391+ toolCallId: "p1",
392+ isError: false,
393+ result: shellResult({ stdout: "alpha" }),
394+ },
395+ {
396+ type: "tool-result",
397+ toolName: "shell",
398+ toolCallId: "p2",
399+ isError: false,
400+ result: shellResult({ stdout: "bravo" }),
401+ },
402+ { type: "text-delta", delta: "Both done." },
403+ turnDone(),
404+ ]),
405+ new Spinner(),
406+ );
407+
408+ const plain = simulateTerminal(getCapturedStdout());
409+ const lines = plain.split("\n");
410+
411+ // Both tool calls appear before the first result
412+ const call1 = lines.findIndex((l) => l.includes("$ echo alpha"));
413+ const call2 = lines.findIndex((l) => l.includes("$ echo bravo"));
414+ const result1 = lines.findIndex((l) => l.match(/^ {4}done.*alpha/));
415+ const result2 = lines.findIndex((l) => l.match(/^ {4}done.*bravo/));
416+
417+ expect(call1).toBeGreaterThan(-1);
418+ expect(call2).toBeGreaterThan(-1);
419+ expect(result1).toBeGreaterThan(-1);
420+ expect(result2).toBeGreaterThan(-1);
421+
422+ // Calls come before results
423+ expect(call1).toBeLessThan(result1);
424+ expect(call2).toBeLessThan(result2);
425+
426+ // Both calls appear before first result
427+ expect(call2).toBeLessThan(result1);
428+
429+ // Reply follows
430+ expect(plain).toContain("◆ Both done.");
431+ });
432+
433+ test("three parallel mixed tools: shell + subagent + readSkill", async () => {
434+ captureStdout();
435+
436+ await renderTurn(
437+ eventsFrom([
438+ {
439+ type: "tool-call-start",
440+ toolName: "shell",
441+ toolCallId: "m1",
442+ args: { command: "ls src" },
443+ },
444+ {
445+ type: "tool-call-start",
446+ toolName: "subagent",
447+ toolCallId: "m2",
448+ args: { prompt: "Analyze code" },
449+ },
450+ {
451+ type: "tool-call-start",
452+ toolName: "readSkill",
453+ toolCallId: "m3",
454+ args: { name: "deploy" },
455+ },
456+ {
457+ type: "tool-result",
458+ toolName: "shell",
459+ toolCallId: "m1",
460+ isError: false,
461+ result: shellResult({ stdout: "index.ts" }),
462+ },
463+ {
464+ type: "tool-result",
465+ toolName: "subagent",
466+ toolCallId: "m2",
467+ isError: false,
468+ result: { inputTokens: 50, outputTokens: 30 },
469+ },
470+ {
471+ type: "tool-result",
472+ toolName: "readSkill",
473+ toolCallId: "m3",
474+ isError: false,
475+ result: {
476+ skill: {
477+ name: "deploy",
478+ description: "Deploy stuff",
479+ source: "local",
480+ },
481+ },
482+ },
483+ turnDone(),
484+ ]),
485+ new Spinner(),
486+ );
487+
488+ const plain = simulateTerminal(getCapturedStdout());
489+
490+ // All three calls rendered
491+ expect(plain).toContain(" $ ls src");
492+ expect(plain).toMatch(/^ {2}⇢/m);
493+ expect(plain).toMatch(/^ {2}←/m);
494+
495+ // All three results at 4-space indent
496+ expect(plain).toMatch(/^ {4}done.*index\.ts/m);
497+ expect(plain).toMatch(/^ {4}⇢/m);
498+ // readSkill result uses · (info) glyph
499+ expect(plain).toMatch(/^ {4}·/m);
500+ });
501+
502+ test("parallel calls: blank line separates second call from first call", async () => {
503+ captureStdout();
504+
505+ await renderTurn(
506+ eventsFrom([
507+ {
508+ type: "tool-call-start",
509+ toolName: "shell",
510+ toolCallId: "s1",
511+ args: { command: "echo one" },
512+ },
513+ {
514+ type: "tool-call-start",
515+ toolName: "shell",
516+ toolCallId: "s2",
517+ args: { command: "echo two" },
518+ },
519+ {
520+ type: "tool-result",
521+ toolName: "shell",
522+ toolCallId: "s1",
523+ isError: false,
524+ result: shellResult({ stdout: "one" }),
525+ },
526+ {
527+ type: "tool-result",
528+ toolName: "shell",
529+ toolCallId: "s2",
530+ isError: false,
531+ result: shellResult({ stdout: "two" }),
532+ },
533+ turnDone(),
534+ ]),
535+ new Spinner(),
536+ );
537+
538+ const plain = simulateTerminal(getCapturedStdout());
539+ const lines = plain.split("\n");
540+
541+ // There should be a blank line between the two tool call lines
542+ const idx1 = lines.findIndex((l) => l.includes("$ echo one"));
543+ const idx2 = lines.findIndex((l) => l.includes("$ echo two"));
544+ expect(idx2).toBeGreaterThan(idx1);
545+ // At least one blank line between them
546+ const between = lines.slice(idx1 + 1, idx2);
547+ expect(between.some((l) => l.trim() === "")).toBe(true);
548+ });
549+
550+ test("parallel calls with one error and one success", async () => {
551+ captureStdout();
552+
553+ await renderTurn(
554+ eventsFrom([
555+ {
556+ type: "tool-call-start",
557+ toolName: "shell",
558+ toolCallId: "e1",
559+ args: { command: "good-cmd" },
560+ },
561+ {
562+ type: "tool-call-start",
563+ toolName: "shell",
564+ toolCallId: "e2",
565+ args: { command: "bad-cmd" },
566+ },
567+ {
568+ type: "tool-result",
569+ toolName: "shell",
570+ toolCallId: "e1",
571+ isError: false,
572+ result: shellResult({ stdout: "ok" }),
573+ },
574+ {
575+ type: "tool-result",
576+ toolName: "shell",
577+ toolCallId: "e2",
578+ isError: true,
579+ result: "permission denied",
580+ },
581+ { type: "text-delta", delta: "Partial failure." },
582+ turnDone(),
583+ ]),
584+ new Spinner(),
585+ );
586+
587+ const plain = simulateTerminal(getCapturedStdout());
588+ expect(plain).toContain(" $ good-cmd");
589+ expect(plain).toContain(" $ bad-cmd");
590+ expect(plain).toMatch(/^ {4}done/m);
591+ expect(plain).toMatch(/^ {4}✖ permission denied/m);
592+ expect(plain).toContain("◆ Partial failure.");
593+ });
594+
595+ test("reasoning → parallel calls → reasoning → reply", async () => {
596+ captureStdout();
597+
598+ await renderTurn(
599+ eventsFrom([
600+ { type: "reasoning-delta", delta: "I'll check two files" },
601+ {
602+ type: "tool-call-start",
603+ toolName: "shell",
604+ toolCallId: "r1",
605+ args: { command: "cat a.ts" },
606+ },
607+ {
608+ type: "tool-call-start",
609+ toolName: "shell",
610+ toolCallId: "r2",
611+ args: { command: "cat b.ts" },
612+ },
613+ {
614+ type: "tool-result",
615+ toolName: "shell",
616+ toolCallId: "r1",
617+ isError: false,
618+ result: shellResult({ stdout: "content A" }),
619+ },
620+ {
621+ type: "tool-result",
622+ toolName: "shell",
623+ toolCallId: "r2",
624+ isError: false,
625+ result: shellResult({ stdout: "content B" }),
626+ },
627+ { type: "reasoning-delta", delta: "Now I understand" },
628+ { type: "text-delta", delta: "Here's my analysis." },
629+ turnDone(),
630+ ]),
631+ new Spinner(),
632+ );
633+
634+ const plain = simulateTerminal(getCapturedStdout());
635+
636+ // Reasoning block before tools
637+ expect(plain).toContain("· reasoning");
638+ expect(plain).toContain("I'll check two files");
639+
640+ // Both parallel calls
641+ expect(plain).toContain("$ cat a.ts");
642+ expect(plain).toContain("$ cat b.ts");
643+
644+ // Second reasoning block
645+ const reasoningCount = (plain.match(/· reasoning/g) ?? []).length;
646+ expect(reasoningCount).toBe(2);
647+ expect(plain).toContain("Now I understand");
648+
649+ // Final reply
650+ expect(plain).toContain("◆ Here's my analysis.");
Cut short: this commit's diff is over 1000 lines.