xonecas.io
79113
Ma

mini-coding-agent / commit cbf113a

feat: further compaction of conversation log.

xonecas2026-10-28 cbf113acd9ac21c3b03be5cd16b353308a4f2782 parent d966d92

3 files changed

README.md+6−5
@@ -100,11 +100,12 @@ error.
100100 Both `read` and `edit` expand a leading `~/`. Tool arguments are parsed once at
101101 the boundary and validated there; a bad shape fails the call with a message.
102102
103-The TUI renders one line per call: the tool name and a clipped preview of its
104-arguments (the first line of a `bash` command, the path for `read`/`edit`).
105-`read` and a successful `bash` follow it with a `└` metadata line instead of
106-their output (`└ exit 0 · 12 lines`); a failed call still shows its output.
107-Changed files render as diffs with `+added -removed` counts.
103+The TUI renders one line per call: the tool name, a clipped preview of its
104+arguments (the first line of a `bash` command, the path for `read`/`edit`), and
105+the call's metadata (`exit 0 · 12 lines`). For `read` and a successful `bash`
106+that metadata replaces the output; a failed call still shows its output. Calls
107+are not separated by blank lines. Changed files render as diffs with
108+`+added -removed` counts.
108109
109110 ## Configure
110111
src/tui/tool_view.zig+12−9
@@ -5,7 +5,7 @@ const diff_view = @import("diff_view.zig");
55
66 const BodyLine = render.BodyLine;
77
8-pub const PendingCall = struct { name: []const u8, summary: []const u8, rendered: bool = false };
8+pub const PendingCall = struct { name: []const u8, summary: []const u8 };
99
1010 fn callHead(a: std.mem.Allocator, name: []const u8) []const u8 {
1111 return styles.accent(a, std.fmt.allocPrint(a, "{s}", .{name}) catch "tool");
@@ -44,11 +44,19 @@ pub fn callSummary(a: std.mem.Allocator, name: []const u8, args_json: []const u8
4444 return args_json;
4545 }
4646
47-pub fn callLine(a: std.mem.Allocator, name: []const u8, summary: []const u8, width: usize) []const u8 {
47+/// One line: the tool name, a clipped preview of its arguments, and the
48+/// result summary when there is one.
49+pub fn callLine(a: std.mem.Allocator, name: []const u8, summary: []const u8, meta: ?[]const u8, width: usize) []const u8 {
4850 const head = std.fmt.allocPrint(a, "{s} ", .{callHead(a, name)}) catch return summary;
49- const room = width -| render.displayWidth(head);
51+ var room = width -| render.displayWidth(head);
52+ var tail: []const u8 = "";
53+ if (meta) |m| {
54+ const raw = std.fmt.allocPrint(a, " {s}", .{m}) catch "";
55+ tail = styles.comment(a, render.clip(a, raw, room));
56+ room -|= render.displayWidth(tail);
57+ }
5058 const args = styles.styledWith(a, .{ .bold = true }, render.clip(a, render.expandTabs(a, summary, 4), room));
51- return std.fmt.allocPrint(a, "{s}{s}", .{ head, args }) catch summary;
59+ return std.fmt.allocPrint(a, "{s}{s}{s}", .{ head, args, tail }) catch summary;
5260 }
5361
5462 pub const Result = struct {
@@ -94,11 +102,6 @@ pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8, max
94102 return .{ .lines = out.items };
95103 }
96104
97-pub fn metaLine(a: std.mem.Allocator, meta: []const u8) []const u8 {
98- const label = std.fmt.allocPrint(a, " └ {s}", .{meta}) catch return "";
99- return styles.comment(a, label);
100-}
101-
102105 pub fn exitLine(a: std.mem.Allocator, text: []const u8) ?[]const u8 {
103106 const trimmed = std.mem.trimEnd(u8, text, " \t\r\n");
104107 const last = if (std.mem.lastIndexOfScalar(u8, trimmed, '\n')) |i| trimmed[i + 1 ..] else trimmed;
src/tui/tui.zig+20−21
@@ -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 }