@@ -206,6 +206,7 @@ class Tui {
206206 // In-flight stream state, never persisted: all display-only.
207207 private readonly reply: StreamRenderer = new MarkdownStream();
208208 private readonly activity: StreamRenderer = new TailStream();
209+ private pendingCalls: BodyLine[] = [];
209210 private streamed = "";
210211 private turnStart = 0;
211212 private frame = 0;
@@ -378,12 +379,13 @@ class Tui {
378379 if (this.reply.pending().length === 0) this.activity.feed(event.delta);
379380 break;
380381 case "toolCall":
381- // Flush first so scrollback order matches execution order, then commit
382- // the call line: results land under the calls, in execution order.
382+ // Hold the call line until its result arrives: a message may carry
383+ // several calls, all announced before any of them runs, and each call
384+ // line pairs with its own output in execution order.
383385 this.writingTool = undefined;
384386 this.commitLines(this.reply.flush());
385387 this.activity.reset();
386- this.commitCall(event.name, event.arguments);
388+ this.pendingCalls.push({ text: `${callHead(event.name)} ${callSummary(event.name, event.arguments)}` });
387389 break;
388390 case "toolCallStart":
389391 this.writingTool = event.name;
@@ -419,6 +421,7 @@ class Tui {
419421 this.paused = false;
420422 this.activity.reset();
421423 this.commitLines(this.reply.flush());
424+ this.flushCalls();
422425 this.separator = true;
423426 this.push(line);
424427 }
@@ -433,12 +436,6 @@ class Tui {
433436 this.separator = true;
434437 }
435438
436- /** The call line lands the moment the model finishes writing it, never held. */
437- private commitCall(name: string, args: JsonObject): void {
438- this.separator = true;
439- this.commitLines([{ text: `${callHead(name)} ${callSummary(name, args)}` }]);
440- }
441-
442439 /** Commits a line the model emitted without streaming it, plus the in-flight tail. */
443440 private commitMessage(message: AssistantMessage): void {
444441 this.activity.reset();
@@ -455,6 +452,9 @@ class Tui {
455452 }
456453
457454 private commitToolResult(name: string, text: string, isError: boolean): void {
455+ const call = this.pendingCalls.shift();
456+ this.separator = true;
457+ if (call !== undefined) this.commitLines([call]);
458458 const width = Math.max(1, this.term.width - BODY_PREFIX.length);
459459 const lines = resultLines(name, text, isError);
460460 // Diffs are shown in full; other tool bodies stay elided.
@@ -471,6 +471,15 @@ class Tui {
471471 for (const row of renderRows(lines, Math.max(1, this.term.width))) this.push(row);
472472 }
473473
474+ /** Commits any call line whose result never arrived, e.g. after a cancel. */
475+ private flushCalls(): void {
476+ for (const call of this.pendingCalls) {
477+ this.separator = true;
478+ this.commitLines([call]);
479+ }
480+ this.pendingCalls = [];
481+ }
482+
474483 /**
475484 * Appends one scrollback line. A block boundary owes exactly one blank line,
476485 * and two blank lines never appear in a row.