xonecas.io
79113
Ma

mini-coding-agent / commit edc9841

feat: don't render massive diffs.

xonecas2026-10-14 edc984136560ff7a9a949d4bb77dd3578e586d44 parent f485f9a

5 files changed

README.md+2−0
@@ -95,6 +95,7 @@ A full example:
9595 "snapshotIgnoreDirs": [".git"],
9696 "snapshotUsesGitignore": true,
9797 "historySize": 100,
98+ "maxDiffLines": 2000,
9899 "customProviders": [
99100 {
100101 "id": "local",
@@ -137,6 +138,7 @@ Keys:
137138 | `snapshotIgnoreDirs` | `[]` | directory names skipped when the `bash` tool snapshots the cwd for diffs |
138139 | `snapshotUsesGitignore` | `true` | also skip directories named in `.gitignore` when snapshotting |
139140 | `historySize` | `100` | past inputs kept in `<state dir>/mini-coding-agent/history` for `Ctrl+R` |
141+| `maxDiffLines` | `2000` | diffs longer than this render as a "too large" notice instead of highlighting every line |
140142
141143 Unknown keys are rejected. `provider` and `model` must both be set to make a
142144 request; a custom provider must list the model in its `models`.
src/config.zig+4−0
@@ -48,10 +48,12 @@ pub const Config = struct {
4848 snapshot_ignore_dirs: []const []const u8,
4949 snapshot_uses_gitignore: bool,
5050 history_size: usize,
51+ max_diff_lines: usize,
5152 };
5253
5354 const File = struct {
5455 historySize: ?usize = null,
56+ maxDiffLines: ?usize = null,
5557 sessionsDir: ?[]const u8 = null,
5658 systemPrompt: ?[]const u8 = null,
5759 discoverAgentFiles: ?bool = null,
@@ -143,6 +145,7 @@ fn readInto(a: std.mem.Allocator, path: []const u8, required: bool, cfg: *Config
143145 if (file.snapshotIgnoreDirs) |v| cfg.snapshot_ignore_dirs = v;
144146 if (file.snapshotUsesGitignore) |v| cfg.snapshot_uses_gitignore = v;
145147 if (file.historySize) |v| cfg.history_size = v;
148+ if (file.maxDiffLines) |v| cfg.max_diff_lines = v;
146149 }
147150
148151 pub const Update = struct {
@@ -194,5 +197,6 @@ fn defaults(a: std.mem.Allocator) !Config {
194197 .snapshot_ignore_dirs = &.{},
195198 .snapshot_uses_gitignore = true,
196199 .history_size = 100,
200+ .max_diff_lines = 2000,
197201 };
198202 }
src/tui/diff_view.zig+11−3
@@ -59,7 +59,15 @@ fn rebaseSpans(a: std.mem.Allocator, spans: []const highlight.Span, lo: u32, hi:
5959 return out.items;
6060 }
6161
62-pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const u8) []const BodyLine {
62+pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const u8, max_diff_lines: usize) []const BodyLine {
63+ if (lines.len > max_diff_lines) {
64+ var warn: std.ArrayList(BodyLine) = .empty;
65+ warn.append(a, .{
66+ .text = "Diff too large to render efficiently. Full contents in session.jsonl",
67+ .style = .{ .fg = theme.current.comment },
68+ }) catch {};
69+ return warn.items;
70+ }
6371 var joined: std.ArrayList(u8) = .empty;
6472 var starts = a.alloc(u32, lines.len) catch return &.{};
6573 for (lines, 0..) |l, i| {
@@ -119,13 +127,13 @@ pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const
119127 return out.items;
120128 }
121129
122-pub fn diffBody(a: std.mem.Allocator, d: tools.FileDiff) []const BodyLine {
130+pub fn diffBody(a: std.mem.Allocator, d: tools.FileDiff, max_diff_lines: usize) []const BodyLine {
123131 if (d.patch) |patch| {
124132 const trimmed = std.mem.trimEnd(u8, patch, " \t\r\n");
125133 var it = std.mem.splitScalar(u8, trimmed, '\n');
126134 var body: std.ArrayList([]const u8) = .empty;
127135 while (it.next()) |l| body.append(a, l) catch {};
128- return diffLines(a, d.path, body.items);
136+ return diffLines(a, d.path, body.items, max_diff_lines);
129137 }
130138 var out: std.ArrayList(BodyLine) = .empty;
131139 if (d.note) |note| out.append(a, .{ .text = note, .style = .{ .fg = theme.current.comment } }) catch {};
src/tui/tool_view.zig+4−4
@@ -62,7 +62,7 @@ pub fn callBody(a: std.mem.Allocator, name: []const u8, summary: []const u8, met
6262 return out.items;
6363 }
6464
65-pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8) []const BodyLine {
65+pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8, max_diff_lines: usize) []const BodyLine {
6666 const trimmed = std.mem.trimEnd(u8, text, " \t\r\n");
6767 var lines: std.ArrayList([]const u8) = .empty;
6868 var it = std.mem.splitScalar(u8, trimmed, '\n');
@@ -81,7 +81,7 @@ pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8) []c
8181 if (verb.len > 0) {
8282 const path = lines.items[0][verb.len..];
8383 _ = lines.orderedRemove(0);
84- return diff_view.diffLines(a, path, lines.items);
84+ return diff_view.diffLines(a, path, lines.items, max_diff_lines);
8585 }
8686 }
8787 var out: std.ArrayList(BodyLine) = .empty;
@@ -89,10 +89,10 @@ pub fn resultLines(a: std.mem.Allocator, name: []const u8, text: []const u8) []c
8989 return out.items;
9090 }
9191
92-pub fn exitLine(a: std.mem.Allocator, text: []const u8, is_error: bool) ?[]const u8 {
92+pub fn exitLine(a: std.mem.Allocator, text: []const u8) ?[]const u8 {
9393 const trimmed = std.mem.trimEnd(u8, text, " \t\r\n");
9494 const last = if (std.mem.lastIndexOfScalar(u8, trimmed, '\n')) |i| trimmed[i + 1 ..] else trimmed;
9595 if (!std.mem.startsWith(u8, last, "exit code: ")) return null;
9696 const label = std.fmt.allocPrint(a, " └ exit {s}", .{last["exit code: ".len..]}) catch return null;
97- return if (is_error) styles.err(a, label) else styles.comment(a, label);
97+ return styles.comment(a, label);
9898 }
src/tui/tui.zig+3−3
@@ -483,8 +483,8 @@ const Tui = struct {
483483 if (meta == null) {
484484 const width = @max(self.term.width() - BODY_PREFIX.len, 1);
485485 const is_bash = std.mem.eql(u8, name, "bash");
486- const bash_exit: ?[]const u8 = if (is_bash) tool_view.exitLine(self.s, shown, is_error) else null;
487- const lines = tool_view.resultLines(self.s, name, shown);
486+ const bash_exit: ?[]const u8 = if (is_bash) tool_view.exitLine(self.s, shown) else null;
487+ const lines = tool_view.resultLines(self.s, name, shown, self.cfg.max_diff_lines);
488488 const rows = if (std.mem.eql(u8, name, "edit")) render.plainRows(self.s, lines) else render.bodyRows(self.s, lines, width);
489489 const mark_error = is_error and bash_exit == null;
490490 for (rows, 0..) |row, i| {
@@ -495,7 +495,7 @@ const Tui = struct {
495495 }
496496 for (diffs) |d| {
497497 self.push(tool_view.diffHead(self.s, name, d.path));
498- for (render.plainRows(self.s, diff_view.diffBody(self.s, d))) |row| {
498+ for (render.plainRows(self.s, diff_view.diffBody(self.s, d, self.cfg.max_diff_lines))) |row| {
499499 self.push(std.fmt.allocPrint(self.s, "{s}{s}", .{ styles.comment(self.s, BODY_PREFIX), row }) catch row);
500500 }
501501 }