@@ -105,6 +105,7 @@ const Tui = struct {
105105
106106 reply: stream.MarkdownStream,
107107 pending_calls: std.ArrayList(PendingCall) = .empty,
108+ tool_block: bool = false,
108109 streamed: std.ArrayList(u8) = .empty,
109110 turn_start: i64 = 0,
110111 turn_msgs: usize = 0,
@@ -186,11 +187,15 @@ const Tui = struct {
186187 }
187188
188189 fn commitLines(self: *Tui, lines: []const render.BodyLine) void {
190+ if (lines.len == 0) return;
191+ if (self.tool_block) self.scrollback.separator = true;
192+ self.tool_block = false;
189193 self.scrollback.commitLines(lines);
190194 self.dirty = true;
191195 }
192196
193197 fn note(self: *Tui, line: []const u8) void {
198+ self.tool_block = false;
194199 self.scrollback.note(line);
195200 self.dirty = true;
196201 }
@@ -200,6 +205,7 @@ const Tui = struct {
200205 }
201206
202207 fn commitUser(self: *Tui, text: []const u8) void {
208+ self.tool_block = false;
203209 self.scrollback.commitUser(text);
204210 self.dirty = true;
205211 }
@@ -404,7 +410,6 @@ const Tui = struct {
404410 self.phase = p.phase;
405411 self.keepName(&self.detail, p.detail);
406412 if (p.phase == .pausing) self.paused = true;
407- if (p.phase == .running_tool) self.renderPendingCall();
408413 if (p.phase == .waiting_model) {
409414 self.stream_kind = .none;
410415 self.text_bytes = 0;
@@ -509,32 +514,28 @@ const Tui = struct {
509514 }
510515 }
511516
512- fn renderCall(self: *Tui, call: *PendingCall) void {
513- if (call.rendered) return;
514- self.scrollback.separator = true;
515- self.push(tool_view.callLine(self.s, call.name, call.summary, @max(self.term.width(), 1)));
516- call.rendered = true;
517+ fn beginToolBlock(self: *Tui) void {
518+ if (!self.tool_block) self.scrollback.separator = true;
519+ self.tool_block = true;
517520 }
518521
519- fn renderPendingCall(self: *Tui) void {
520- if (self.pending_calls.items.len == 0) return;
521- self.renderCall(&self.pending_calls.items[0]);
522+ fn renderCall(self: *Tui, call: *PendingCall, meta: ?[]const u8) void {
523+ self.beginToolBlock();
524+ self.push(tool_view.callLine(self.s, call.name, call.summary, meta, @max(self.term.width(), 1)));
522525 }
523526
524527 fn commitToolResult(self: *Tui, name: []const u8, text: []const u8, is_error: bool, diffs: []const tools_index.FileDiff, body: ?[]const u8, images: []const message_mod.ImageContent) void {
525528 const shown = render.stripAnsi(self.s, text);
526- const meta: ?[]const u8 = if (!is_error) body else null;
527- var head_committed = false;
528- if (self.pending_calls.items.len > 0) {
529+ const has_head = self.pending_calls.items.len > 0;
530+ const meta: ?[]const u8 = if (!is_error and has_head) body else null;
531+ if (has_head) {
529532 var call = self.pending_calls.orderedRemove(0);
530- head_committed = true;
531- self.renderCall(&call);
533+ self.renderCall(&call, meta);
534+ } else {
535+ self.beginToolBlock();
532536 }
533- if (!head_committed) self.scrollback.separator = true;
534537 if (self.cfg.show_images) self.commitImages(images);
535- if (meta) |m| {
536- self.push(tool_view.metaLine(self.s, m));
537- } else {
538+ if (meta == null) {
538539 const width = @max(self.term.width() - BODY_PREFIX.len, 1);
539540 const is_bash = std.mem.eql(u8, name, "bash");
540541 const bash_exit: ?[]const u8 = if (is_bash) tool_view.exitLine(self.s, shown) else null;
@@ -549,7 +550,6 @@ const Tui = struct {
549550 if (result.footer) |footer| self.push(footer);
550551 }
551552 for (diffs) |d| {
552- self.scrollback.separator = true;
553553 self.push(tool_view.diffHead(self.s, d.path));
554554 const r = diff_view.diffBody(self.s, d, self.cfg.max_diff_lines);
555555 for (render.plainRows(self.s, r.lines, styles.roles.output)) |row| {
@@ -557,7 +557,6 @@ const Tui = struct {
557557 }
558558 if (tool_view.diffFooter(self.s, r)) |footer| self.push(footer);
559559 }
560- self.scrollback.separator = true;
561560 }
562561
563562 fn commitImages(self: *Tui, images: []const message_mod.ImageContent) void {
@@ -576,7 +575,7 @@ const Tui = struct {
576575 }
577576
578577 fn flushCalls(self: *Tui) void {
579- for (self.pending_calls.items) |*call| self.renderCall(call);
578+ for (self.pending_calls.items) |*call| self.renderCall(call, null);
580579 self.pending_calls.clearRetainingCapacity();
581580 self.resetCalls();
582581 }