xonecas.io
79113
Ma

mini-coding-agent / commit 09de22c

feat: compressed TUI output

xonecas2026-10-27 09de22c21504e2061019ac21305bde2a5de867e9 parent 45eb5ec

7 files changed

README.md+5−3
@@ -100,9 +100,11 @@ 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 a summary line per call (the command for `bash`, the path for
104-`read`/`edit`), the output body, and a diff with `+added -removed` counts.
105-`exit code: 0` folds into a `└ exit 0` line.
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.
106108
107109 ## Configure
108110
src/text.zig+5−0
@@ -6,6 +6,11 @@ pub fn isBinary(bytes: []const u8) bool {
66 return std.mem.indexOfScalar(u8, bytes[0..@min(bytes.len, binary_sniff)], 0) != null;
77 }
88
9+pub fn countLines(content: []const u8) usize {
10+ if (content.len == 0) return 0;
11+ return std.mem.count(u8, content, "\n") + @intFromBool(content[content.len - 1] != '\n');
12+}
13+
914 pub fn join(a: std.mem.Allocator, parts: []const []const u8, sep: []const u8) ![]const u8 {
1015 var out: std.ArrayList(u8) = .empty;
1116 for (parts, 0..) |part, i| {
src/tools/bash.zig+20−0
@@ -75,6 +75,25 @@ fn killGroup(pid: i32) void {
7575 std.posix.kill(-pid, .KILL) catch {};
7676 }
7777
78+/// What the TUI shows instead of the output. The status words match the exit line the model sees.
79+fn bodyLine(a: std.mem.Allocator, code: ?u8, timed_out: bool, timeout_s: u64, output: []const u8) ?[]const u8 {
80+ const label = if (code) |c|
81+ std.fmt.allocPrint(a, "exit {d}", .{c}) catch return null
82+ else if (timed_out)
83+ std.fmt.allocPrint(a, "timed out after {d}s", .{timeout_s}) catch return null
84+ else
85+ "aborted";
86+ const lines = text.countLines(output);
87+ if (lines == 0) return label;
88+ const truncated = std.mem.indexOf(u8, output, truncated_marker) != null;
89+ return std.fmt.allocPrint(a, "{s} · {d} line{s}{s}", .{
90+ label,
91+ lines,
92+ if (lines == 1) "" else "s",
93+ if (truncated) ", truncated" else "",
94+ }) catch null;
95+}
96+
7897 fn fail(a: std.mem.Allocator, comptime fmt: []const u8, args: anytype) tools.Result {
7998 return tools.fail(a, "bash failed", fmt, args);
8099 }
@@ -199,6 +218,7 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
199218 .text = out.items,
200219 .is_error = if (code) |c| c != 0 else true,
201220 .diffs = diffs,
221+ .body = bodyLine(a, code, timed_out, timeout_s, body),
202222 .model_text = model_text,
203223 };
204224 }
src/tools/read.zig+2−7
@@ -86,11 +86,6 @@ fn lineSlice(content: []const u8, offset: usize, range: ?usize) ?[]const u8 {
8686 return content[start..];
8787 }
8888
89-fn countLines(content: []const u8) usize {
90- if (content.len == 0) return 0;
91- return std.mem.count(u8, content, "\n") + @intFromBool(content[content.len - 1] != '\n');
92-}
93-
9489 fn bodyLine(a: std.mem.Allocator, args: Args, lines: usize, truncated: bool) ?[]const u8 {
9590 var out: std.Io.Writer.Allocating = .init(a);
9691 const w = &out.writer;
@@ -163,7 +158,7 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
163158 if (clipped) {
164159 return warn(a, "{s}: only the first {d} bytes were read, and offset {d} is past them", .{ path, content.len, offset });
165160 }
166- return warn(a, "{s} has {d} lines; offset {d} is past the end", .{ path, countLines(content), offset });
161+ return warn(a, "{s} has {d} lines; offset {d} is past the end", .{ path, text.countLines(content), offset });
167162 };
168163
169164 var sent = slice;
@@ -181,5 +176,5 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
181176 std.fmt.allocPrint(a, "{s}\n\n{s}", .{ sent, note }) catch "read failed"
182177 else
183178 sent;
184- return .{ .text = result_text, .is_error = false, .body = bodyLine(a, args, countLines(sent), truncated) };
179+ return .{ .text = result_text, .is_error = false, .body = bodyLine(a, args, text.countLines(sent), truncated) };
185180 }
src/tui/render.zig+20−0
@@ -202,6 +202,26 @@ pub fn wrapLine(a: std.mem.Allocator, text: []const u8, width: usize) []const []
202202 return rows.items;
203203 }
204204
205+/// Cuts `text` to `width` display columns, marking the cut with an ellipsis.
206+pub fn clip(a: std.mem.Allocator, text: []const u8, width: usize) []const u8 {
207+ if (width == 0) return "";
208+ if (displayWidth(text) <= width) return text;
209+ var out: std.ArrayList(u8) = .empty;
210+ var used: usize = 0;
211+ var i: usize = 0;
212+ while (nextPiece(text, &i)) |piece| {
213+ if (piece.sgr) {
214+ out.appendSlice(a, piece.text) catch {};
215+ continue;
216+ }
217+ if (used + piece.width > width - 1) break;
218+ out.appendSlice(a, piece.text) catch {};
219+ used += piece.width;
220+ }
221+ out.appendSlice(a, "…") catch {};
222+ return out.items;
223+}
224+
205225 pub const BodyLine = struct {
206226 text: []const u8,
207227 style: ?styles.Style = null,
src/tui/tool_view.zig+17−19
@@ -11,9 +11,8 @@ fn callHead(a: std.mem.Allocator, name: []const u8) []const u8 {
1111 return styles.accent(a, std.fmt.allocPrint(a, "{s}", .{name}) catch "tool");
1212 }
1313
14-pub fn diffHead(a: std.mem.Allocator, name: []const u8, path: []const u8) []const u8 {
15- const head = callHead(a, std.fmt.allocPrint(a, "{s} diff", .{name}) catch name);
16- return std.fmt.allocPrint(a, "{s} {s}", .{ head, path }) catch path;
14+pub fn diffHead(a: std.mem.Allocator, path: []const u8) []const u8 {
15+ return std.fmt.allocPrint(a, "{s} {s}", .{ callHead(a, "diff"), path }) catch path;
1716 }
1817
1918 pub fn relativize(cwd: []const u8, path: []const u8) []const u8 {
@@ -25,11 +24,19 @@ pub fn relativize(cwd: []const u8, path: []const u8) []const u8 {
2524 return rest[1..];
2625 }
2726
27+/// The first line of a command; more lines are dropped, not drawn.
28+fn preview(a: std.mem.Allocator, command: []const u8) []const u8 {
29+ const end = std.mem.indexOfScalar(u8, command, '\n') orelse return command;
30+ if (std.mem.indexOfNone(u8, command[end..], " \t\r\n") == null) return command[0..end];
31+ const first = std.mem.trimEnd(u8, command[0..end], " \t\r");
32+ return std.fmt.allocPrint(a, "{s} …", .{first}) catch first;
33+}
34+
2835 pub fn callSummary(a: std.mem.Allocator, name: []const u8, args_json: []const u8) []const u8 {
2936 const parsed = std.json.parseFromSliceLeaky(std.json.Value, a, args_json, .{}) catch return args_json;
3037 if (parsed == .object) {
3138 if (std.mem.eql(u8, name, "bash")) {
32- if (parsed.object.get("command")) |c| if (c == .string) return c.string;
39+ if (parsed.object.get("command")) |c| if (c == .string) return preview(a, c.string);
3340 }
3441 if (std.mem.eql(u8, name, "edit") or std.mem.eql(u8, name, "read")) {
3542 if (parsed.object.get("path")) |p| if (p == .string) return p.string;
@@ -38,21 +45,12 @@ pub fn callSummary(a: std.mem.Allocator, name: []const u8, args_json: []const u8
3845 return args_json;
3946 }
4047
41-pub fn callBody(a: std.mem.Allocator, name: []const u8, summary: []const u8, width: usize) []const []const u8 {
42- const head = callHead(a, name);
43- const body = summary;
44- var rows: std.ArrayList([]const u8) = .empty;
45- var it = std.mem.splitScalar(u8, body, '\n');
46- var i: usize = 0;
47- while (it.next()) |line| : (i += 1) {
48- const args = if (line.len == 0) line else styles.styledWith(a, .{ .bold = true }, line);
49- const text = if (i == 0)
50- std.fmt.allocPrint(a, "{s} {s}", .{ head, args }) catch line
51- else
52- args;
53- rows.append(a, text) catch {};
54- }
55- return render.elide(a, rows.items, width);
48+/// One line: the tool name and a clipped preview of its arguments.
49+pub fn callLine(a: std.mem.Allocator, name: []const u8, summary: []const u8, width: usize) []const u8 {
50+ const head = std.fmt.allocPrint(a, "{s} ", .{callHead(a, name)}) catch return summary;
51+ const room = width -| render.displayWidth(head);
52+ const args = styles.styledWith(a, .{ .bold = true }, render.clip(a, render.expandTabs(a, summary, 4), room));
53+ return std.fmt.allocPrint(a, "{s}{s}", .{ head, args }) catch summary;
5654 }
5755
5856 pub const Result = struct {
src/tui/tui.zig+3−2
@@ -499,7 +499,7 @@ const Tui = struct {
499499 fn renderCall(self: *Tui, call: *PendingCall) void {
500500 if (call.rendered) return;
501501 self.scrollback.separator = true;
502- for (tool_view.callBody(self.s, call.name, call.summary, @max(self.term.width(), 1))) |row| self.push(row);
502+ self.push(tool_view.callLine(self.s, call.name, call.summary, @max(self.term.width(), 1)));
503503 call.rendered = true;
504504 }
505505
@@ -536,7 +536,8 @@ const Tui = struct {
536536 if (result.footer) |footer| self.push(footer);
537537 }
538538 for (diffs) |d| {
539- self.push(tool_view.diffHead(self.s, name, d.path));
539+ self.scrollback.separator = true;
540+ self.push(tool_view.diffHead(self.s, d.path));
540541 const r = diff_view.diffBody(self.s, d, self.cfg.max_diff_lines);
541542 for (render.plainRows(self.s, r.lines, styles.roles.output)) |row| {
542543 self.push(std.fmt.allocPrint(self.s, "{s}{s}", .{ styles.comment(self.s, BODY_PREFIX), row }) catch row);