xonecas.io
79113
Ma

mini-coding-agent / commit 992468a

chore(tools): refactor into a single tools file.

Separates tool plumbing from the actual tools.

xonecas2026-10-09 992468ae6e9f7e02be6c99851da95bbda8f12040 parent 23b4522

10 files changed

src/agent.zig+3−4
@@ -3,7 +3,6 @@ const types = @import("types.zig");
33 const api = @import("api.zig");
44 const platform = @import("platform.zig");
55 const tools = @import("tools.zig");
6-const common = @import("tools/common.zig");
76 const session = @import("session.zig");
87 const config = @import("config.zig");
98 const time = @import("time.zig");
@@ -18,7 +17,7 @@ pub const Event = union(enum) {
1817 tool_args: usize,
1918 tool_call: struct { name: []const u8, arguments: []const u8 },
2019 tool_output: []const u8,
21- tool_result: struct { name: []const u8, text: []const u8, is_error: bool, diffs: []const common.FileDiff, body: ?[]const u8 },
20+ tool_result: struct { name: []const u8, text: []const u8, is_error: bool, diffs: []const tools.FileDiff, body: ?[]const u8 },
2221 message: *types.AssistantMessage,
2322 no_model,
2423 err: []const u8,
@@ -77,7 +76,7 @@ const StreamCtx = struct { listener: Listener, started: bool = false };
7776
7877 const ToolPhaseCtx = struct { listener: Listener, name: []const u8 };
7978
80-fn onToolPhase(ctx: *anyopaque, phase: common.ToolPhase) void {
79+fn onToolPhase(ctx: *anyopaque, phase: tools.ToolPhase) void {
8180 const c: *ToolPhaseCtx = @ptrCast(@alignCast(ctx));
8281 switch (phase) {
8382 .snapshotting => c.listener.emit(.{ .phase = .{ .phase = .snapshotting } }),
@@ -252,7 +251,7 @@ pub fn runTurn(opts: Options, messages: *std.ArrayList(types.Message), interacti
252251 }
253252 if (run_tools and opts.cancel.load(.acquire)) run_tools = false;
254253
255- var result: ?common.Result = null;
254+ var result: ?tools.Result = null;
256255 if (run_tools) {
257256 listener.emit(.{ .phase = .{ .phase = .running_tool, .detail = call.name } });
258257 var phase_ctx = ToolPhaseCtx{ .listener = listener, .name = call.name };
src/tools.zig+104−7
@@ -1,19 +1,116 @@
11 const std = @import("std");
22 const config = @import("config.zig");
3-const common = @import("tools/common.zig");
4-const spec = @import("tools/spec.zig");
3+const types = @import("types.zig");
54 const read_tool = @import("tools/read.zig");
65 const edit_tool = @import("tools/edit.zig");
76 const bash_tool = @import("tools/bash.zig");
87
9-const all = [_]spec.Descriptor{ read_tool.tool, edit_tool.tool, bash_tool.tool };
8+pub const OutputFn = struct {
9+ ctx: *anyopaque,
10+ on_chunk: *const fn (ctx: *anyopaque, chunk: []const u8) void,
1011
11-fn byName(name: config.ToolName) ?spec.Descriptor {
12+ pub fn call(self: OutputFn, chunk: []const u8) void {
13+ self.on_chunk(self.ctx, chunk);
14+ }
15+};
16+
17+pub const ToolPhase = enum { snapshotting, running };
18+
19+pub const PhaseFn = struct {
20+ ctx: *anyopaque,
21+ on_phase: *const fn (ctx: *anyopaque, phase: ToolPhase) void,
22+
23+ pub fn call(self: PhaseFn, phase: ToolPhase) void {
24+ self.on_phase(self.ctx, phase);
25+ }
26+};
27+
28+pub const Context = struct {
29+ cancel: *const std.atomic.Value(bool),
30+ supports_images: bool,
31+ tools: []const config.ToolName = &.{},
32+ on_output: ?OutputFn = null,
33+ on_phase: ?PhaseFn = null,
34+ snapshot_ignore_dirs: []const []const u8 = &.{},
35+ snapshot_uses_gitignore: bool = true,
36+};
37+
38+pub const FileDiff = struct {
39+ path: []const u8,
40+ patch: ?[]const u8 = null,
41+ note: ?[]const u8 = null,
42+};
43+
44+pub const Result = struct {
45+ text: []const u8,
46+ is_error: bool,
47+ images: []const types.ImageContent = &.{},
48+ diffs: []const FileDiff = &.{},
49+ body: ?[]const u8 = null,
50+};
51+
52+pub fn fail(a: std.mem.Allocator, fallback: []const u8, comptime fmt: []const u8, args: anytype) Result {
53+ return .{
54+ .text = std.fmt.allocPrint(a, fmt, args) catch fallback,
55+ .is_error = true,
56+ };
57+}
58+
59+pub const Kind = enum { string, integer };
60+
61+pub const Param = struct {
62+ name: []const u8,
63+ kind: Kind,
64+ description: []const u8,
65+ required: bool = true,
66+};
67+
68+pub const Describe = struct {
69+ with_images: bool = false,
70+ cwd: []const u8 = "",
71+};
72+
73+pub const Descriptor = struct {
74+ name: config.ToolName,
75+ description: *const fn (std.mem.Allocator, Describe) []const u8,
76+ params: []const Param,
77+ run: *const fn (std.mem.Allocator, std.mem.Allocator, []const u8, Context) Result,
78+};
79+
80+pub fn write(w: *std.Io.Writer, a: std.mem.Allocator, d: Descriptor, ctx: Describe) std.Io.Writer.Error!void {
81+ try w.writeAll("{\"name\":");
82+ try std.json.Stringify.encodeJsonString(@tagName(d.name), .{}, w);
83+ try w.writeAll(",\"description\":");
84+ try std.json.Stringify.encodeJsonString(d.description(a, ctx), .{}, w);
85+ try w.writeAll(",\"parameters\":{\"type\":\"object\",\"required\":[");
86+ var first = true;
87+ for (d.params) |p| {
88+ if (!p.required) continue;
89+ if (!first) try w.writeByte(',');
90+ first = false;
91+ try std.json.Stringify.encodeJsonString(p.name, .{}, w);
92+ }
93+ try w.writeAll("],\"properties\":{");
94+ for (d.params, 0..) |p, i| {
95+ if (i > 0) try w.writeByte(',');
96+ try std.json.Stringify.encodeJsonString(p.name, .{}, w);
97+ try w.writeAll(":{\"type\":");
98+ try std.json.Stringify.encodeJsonString(@tagName(p.kind), .{}, w);
99+ try w.writeAll(",\"description\":");
100+ try std.json.Stringify.encodeJsonString(p.description, .{}, w);
101+ try w.writeByte('}');
102+ }
103+ try w.writeAll("},\"additionalProperties\":false}}");
104+}
105+
106+const all = [_]Descriptor{ read_tool.tool, edit_tool.tool, bash_tool.tool };
107+
108+fn byName(name: config.ToolName) ?Descriptor {
12109 for (all) |tool| if (tool.name == name) return tool;
13110 return null;
14111 }
15112
16-pub fn execute(a: std.mem.Allocator, scratch: std.mem.Allocator, name: []const u8, args_json: []const u8, ctx: common.Context) common.Result {
113+pub fn execute(a: std.mem.Allocator, scratch: std.mem.Allocator, name: []const u8, args_json: []const u8, ctx: Context) Result {
17114 for (all) |tool| {
18115 if (!std.mem.eql(u8, name, @tagName(tool.name))) continue;
19116 for (ctx.tools) |enabled| if (enabled == tool.name) return tool.run(a, scratch, args_json, ctx);
@@ -26,7 +123,7 @@ pub fn execute(a: std.mem.Allocator, scratch: std.mem.Allocator, name: []const u
26123 }
27124
28125 pub fn json(a: std.mem.Allocator, names: []const config.ToolName, with_images: bool, cwd: []const u8) []const u8 {
29- const ctx = spec.Describe{ .with_images = with_images, .cwd = cwd };
126+ const ctx = Describe{ .with_images = with_images, .cwd = cwd };
30127 var out: std.Io.Writer.Allocating = .init(a);
31128 const w = &out.writer;
32129 w.writeByte('[') catch return "[]";
@@ -35,7 +132,7 @@ pub fn json(a: std.mem.Allocator, names: []const config.ToolName, with_images: b
35132 const tool = byName(name) orelse continue;
36133 if (!first) w.writeByte(',') catch return out.written();
37134 first = false;
38- spec.write(w, a, tool, ctx) catch return out.written();
135+ write(w, a, tool, ctx) catch return out.written();
39136 }
40137 w.writeByte(']') catch return out.written();
41138 return out.written();
src/tools/bash.zig+8−9
@@ -1,9 +1,8 @@
11 const std = @import("std");
22 const platform = @import("../platform.zig");
33 const text = @import("../text.zig");
4-const common = @import("common.zig");
4+const tools = @import("../tools.zig");
55 const snapshot = @import("snapshot.zig");
6-const spec = @import("spec.zig");
76
87 const max_head = 10_000;
98 const max_tail = 6_000;
@@ -17,16 +16,16 @@ const description_fmt =
1716 "builds, tests, git, package managers, and file work that read and edit do not cover. The output ends " ++
1817 "with an `exit code:` line. Pass `timeout` (seconds) to change the 120-second limit.";
1918
20-const params = [_]spec.Param{
19+const params = [_]tools.Param{
2120 .{ .name = "command", .kind = .string, .description = "Bash command line to execute." },
2221 .{ .name = "timeout", .kind = .integer, .required = false, .description = "Seconds to allow before the command is killed. Defaults to 120." },
2322 };
2423
25-fn describe(a: std.mem.Allocator, ctx: spec.Describe) []const u8 {
24+fn describe(a: std.mem.Allocator, ctx: tools.Describe) []const u8 {
2625 return std.fmt.allocPrint(a, description_fmt, .{ctx.cwd}) catch "Run a bash command.";
2726 }
2827
29-pub const tool = spec.Descriptor{
28+pub const tool = tools.Descriptor{
3029 .name = .bash,
3130 .description = describe,
3231 .params = &params,
@@ -40,7 +39,7 @@ const Acc = struct {
4039 head: std.ArrayList(u8) = .empty,
4140 tail: std.ArrayList(u8) = .empty,
4241 truncated: bool = false,
43- on_output: ?common.OutputFn,
42+ on_output: ?tools.OutputFn,
4443
4544 fn append(self: *Acc, chunk: []const u8) !void {
4645 if (self.on_output) |cb| cb.call(chunk);
@@ -75,11 +74,11 @@ fn killGroup(pid: i32) void {
7574 std.posix.kill(-pid, .KILL) catch {};
7675 }
7776
78-fn fail(a: std.mem.Allocator, comptime fmt: []const u8, args: anytype) common.Result {
79- return common.fail(a, "bash failed", fmt, args);
77+fn fail(a: std.mem.Allocator, comptime fmt: []const u8, args: anytype) tools.Result {
78+ return tools.fail(a, "bash failed", fmt, args);
8079 }
8180
82-pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const u8, ctx: common.Context) common.Result {
81+pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const u8, ctx: tools.Context) tools.Result {
8382 const args = std.json.parseFromSliceLeaky(Args, scratch, args_json, .{ .ignore_unknown_fields = true }) catch {
8483 return fail(a, "bash failed: command must be a string", .{});
8584 };
src/tools/common.zig+0−54
@@ -1,54 +0,0 @@
1-const std = @import("std");
2-const config = @import("../config.zig");
3-const types = @import("../types.zig");
4-
5-pub const OutputFn = struct {
6- ctx: *anyopaque,
7- on_chunk: *const fn (ctx: *anyopaque, chunk: []const u8) void,
8-
9- pub fn call(self: OutputFn, chunk: []const u8) void {
10- self.on_chunk(self.ctx, chunk);
11- }
12-};
13-
14-pub const ToolPhase = enum { snapshotting, running };
15-
16-pub const PhaseFn = struct {
17- ctx: *anyopaque,
18- on_phase: *const fn (ctx: *anyopaque, phase: ToolPhase) void,
19-
20- pub fn call(self: PhaseFn, phase: ToolPhase) void {
21- self.on_phase(self.ctx, phase);
22- }
23-};
24-
25-pub const Context = struct {
26- cancel: *const std.atomic.Value(bool),
27- supports_images: bool,
28- tools: []const config.ToolName = &.{},
29- on_output: ?OutputFn = null,
30- on_phase: ?PhaseFn = null,
31- snapshot_ignore_dirs: []const []const u8 = &.{},
32- snapshot_uses_gitignore: bool = true,
33-};
34-
35-pub const FileDiff = struct {
36- path: []const u8,
37- patch: ?[]const u8 = null,
38- note: ?[]const u8 = null,
39-};
40-
41-pub const Result = struct {
42- text: []const u8,
43- is_error: bool,
44- images: []const types.ImageContent = &.{},
45- diffs: []const FileDiff = &.{},
46- body: ?[]const u8 = null,
47-};
48-
49-pub fn fail(a: std.mem.Allocator, fallback: []const u8, comptime fmt: []const u8, args: anytype) Result {
50- return .{
51- .text = std.fmt.allocPrint(a, fmt, args) catch fallback,
52- .is_error = true,
53- };
54-}
src/tools/edit.zig+7−8
@@ -3,8 +3,7 @@ const filesystem = @import("../filesystem.zig");
33 const text = @import("../text.zig");
44 const platform = @import("../platform.zig");
55 const diff = @import("../diff.zig");
6-const common = @import("common.zig");
7-const spec = @import("spec.zig");
6+const tools = @import("../tools.zig");
87
98 const Args = struct {
109 path: []const u8,
@@ -20,28 +19,28 @@ const description =
2019 "To create a new file, pass an empty `oldText`; this fails if the file already exists. The result " ++
2120 "includes a unified diff of the change.";
2221
23-const params = [_]spec.Param{
22+const params = [_]tools.Param{
2423 .{ .name = "path", .kind = .string, .description = "File to edit, or to create when `oldText` is empty." },
2524 .{ .name = "oldText", .kind = .string, .description = "Exact text to replace. Must occur exactly once. Leave empty to create a new file." },
2625 .{ .name = "newText", .kind = .string, .description = "Replacement text." },
2726 };
2827
29-fn describe(_: std.mem.Allocator, _: spec.Describe) []const u8 {
28+fn describe(_: std.mem.Allocator, _: tools.Describe) []const u8 {
3029 return description;
3130 }
3231
33-pub const tool = spec.Descriptor{
32+pub const tool = tools.Descriptor{
3433 .name = .edit,
3534 .description = describe,
3635 .params = &params,
3736 .run = run,
3837 };
3938
40-fn fail(a: std.mem.Allocator, comptime fmt: []const u8, args: anytype) common.Result {
41- return common.fail(a, "edit failed", fmt, args);
39+fn fail(a: std.mem.Allocator, comptime fmt: []const u8, args: anytype) tools.Result {
40+ return tools.fail(a, "edit failed", fmt, args);
4241 }
4342
44-pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const u8, ctx: common.Context) common.Result {
43+pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const u8, ctx: tools.Context) tools.Result {
4544 const args = std.json.parseFromSliceLeaky(Args, scratch, args_json, .{ .ignore_unknown_fields = true }) catch {
4645 return fail(a, "edit failed: path, oldText and newText must be strings", .{});
4746 };
src/tools/read.zig+7−8
@@ -2,8 +2,7 @@ const std = @import("std");
22 const filesystem = @import("../filesystem.zig");
33 const text = @import("../text.zig");
44 const types = @import("../types.zig");
5-const common = @import("common.zig");
6-const spec = @import("spec.zig");
5+const tools = @import("../tools.zig");
76
87 const Args = struct {
98 path: []const u8,
@@ -24,17 +23,17 @@ const image_description = description_base ++
2423 "\n\nImages (png, jpg, jpeg, webp) are returned as image content. Text longer than 100,000 characters is " ++
2524 "truncated.";
2625
27-const params = [_]spec.Param{
26+const params = [_]tools.Param{
2827 .{ .name = "path", .kind = .string, .description = "File to read. Relative paths resolve against the working directory." },
2928 .{ .name = "offset", .kind = .integer, .required = false, .description = "First line to return, 1-based. Defaults to the beginning of the file." },
3029 .{ .name = "range", .kind = .integer, .required = false, .description = "Number of lines to return from `offset`. Defaults to the end of the file." },
3130 };
3231
33-fn describe(_: std.mem.Allocator, ctx: spec.Describe) []const u8 {
32+fn describe(_: std.mem.Allocator, ctx: tools.Describe) []const u8 {
3433 return if (ctx.with_images) image_description else text_description;
3534 }
3635
37-pub const tool = spec.Descriptor{
36+pub const tool = tools.Descriptor{
3837 .name = .read,
3938 .description = describe,
4039 .params = &params,
@@ -51,8 +50,8 @@ const image_mime = [_]struct { ext: []const u8, mime: []const u8 }{
5150 const max_text_chars = 100_000;
5251 const max_image_base64_bytes = 5 * 1024 * 1024;
5352
54-fn fail(a: std.mem.Allocator, comptime fmt: []const u8, args: anytype) common.Result {
55- return common.fail(a, "read failed", fmt, args);
53+fn fail(a: std.mem.Allocator, comptime fmt: []const u8, args: anytype) tools.Result {
54+ return tools.fail(a, "read failed", fmt, args);
5655 }
5756
5857 fn mimeFor(path: []const u8) ?[]const u8 {
@@ -104,7 +103,7 @@ fn bodyLine(a: std.mem.Allocator, args: Args, lines: usize, truncated: bool) ?[]
104103 return out.written();
105104 }
106105
107-pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const u8, ctx: common.Context) common.Result {
106+pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const u8, ctx: tools.Context) tools.Result {
108107 const args = std.json.parseFromSliceLeaky(Args, scratch, args_json, .{ .ignore_unknown_fields = true }) catch
109108 return fail(a, "read failed: invalid arguments", .{});
110109 const path = args.path;
src/tools/snapshot.zig+4−4
@@ -2,7 +2,7 @@ const std = @import("std");
22 const platform = @import("../platform.zig");
33 const filesystem = @import("../filesystem.zig");
44 const diff = @import("../diff.zig");
5-const common = @import("common.zig");
5+const tools = @import("../tools.zig");
66
77 const max_file_bytes = 1 << 20;
88 const max_total_bytes = 32 << 20;
@@ -131,7 +131,7 @@ fn noteFor(a: std.mem.Allocator, kind: Kind, verb: []const u8) []const u8 {
131131 };
132132 }
133133
134-fn diffOne(a: std.mem.Allocator, path: []const u8, before: ?FileState, after: ?FileState) !?common.FileDiff {
134+fn diffOne(a: std.mem.Allocator, path: []const u8, before: ?FileState, after: ?FileState) !?tools.FileDiff {
135135 if (before == null) {
136136 const af = after.?;
137137 if (af.kind == .link) return .{ .path = path, .note = "symlink created" };
@@ -157,7 +157,7 @@ fn diffOne(a: std.mem.Allocator, path: []const u8, before: ?FileState, after: ?F
157157 return .{ .path = path, .note = noteFor(a, if (af.content == null) af.kind else bf.kind, "changed") };
158158 }
159159
160-pub fn diffTrees(a: std.mem.Allocator, before: Tree, after: Tree) ![]common.FileDiff {
160+pub fn diffTrees(a: std.mem.Allocator, before: Tree, after: Tree) ![]tools.FileDiff {
161161 var paths: std.ArrayList([]const u8) = .empty;
162162 var it = before.iterator();
163163 while (it.next()) |e| try paths.append(a, e.key_ptr.*);
@@ -171,7 +171,7 @@ pub fn diffTrees(a: std.mem.Allocator, before: Tree, after: Tree) ![]common.File
171171 }
172172 }.lt);
173173
174- var out: std.ArrayList(common.FileDiff) = .empty;
174+ var out: std.ArrayList(tools.FileDiff) = .empty;
175175 for (paths.items) |p| {
176176 if (try diffOne(a, p, before.get(p), after.get(p))) |d| try out.append(a, d);
177177 }
src/tools/spec.zig+0−50
@@ -1,50 +0,0 @@
1-const std = @import("std");
2-const config = @import("../config.zig");
3-const common = @import("common.zig");
4-
5-pub const Kind = enum { string, integer };
6-
7-pub const Param = struct {
8- name: []const u8,
9- kind: Kind,
10- description: []const u8,
11- required: bool = true,
12-};
13-
14-pub const Describe = struct {
15- with_images: bool = false,
16- cwd: []const u8 = "",
17-};
18-
19-pub const Descriptor = struct {
20- name: config.ToolName,
21- description: *const fn (std.mem.Allocator, Describe) []const u8,
22- params: []const Param,
23- run: *const fn (std.mem.Allocator, std.mem.Allocator, []const u8, common.Context) common.Result,
24-};
25-
26-pub fn write(w: *std.Io.Writer, a: std.mem.Allocator, d: Descriptor, ctx: Describe) std.Io.Writer.Error!void {
27- try w.writeAll("{\"name\":");
28- try std.json.Stringify.encodeJsonString(@tagName(d.name), .{}, w);
29- try w.writeAll(",\"description\":");
30- try std.json.Stringify.encodeJsonString(d.description(a, ctx), .{}, w);
31- try w.writeAll(",\"parameters\":{\"type\":\"object\",\"required\":[");
32- var first = true;
33- for (d.params) |p| {
34- if (!p.required) continue;
35- if (!first) try w.writeByte(',');
36- first = false;
37- try std.json.Stringify.encodeJsonString(p.name, .{}, w);
38- }
39- try w.writeAll("],\"properties\":{");
40- for (d.params, 0..) |p, i| {
41- if (i > 0) try w.writeByte(',');
42- try std.json.Stringify.encodeJsonString(p.name, .{}, w);
43- try w.writeAll(":{\"type\":");
44- try std.json.Stringify.encodeJsonString(@tagName(p.kind), .{}, w);
45- try w.writeAll(",\"description\":");
46- try std.json.Stringify.encodeJsonString(p.description, .{}, w);
47- try w.writeByte('}');
48- }
49- try w.writeAll("},\"additionalProperties\":false}}");
50-}
src/tui/diff_view.zig+2−2
@@ -1,5 +1,5 @@
11 const std = @import("std");
2-const common = @import("../tools/common.zig");
2+const tools = @import("../tools.zig");
33 const theme = @import("theme.zig");
44 const highlight = @import("highlight.zig");
55 const render = @import("render.zig");
@@ -119,7 +119,7 @@ pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const
119119 return out.items;
120120 }
121121
122-pub fn diffBody(a: std.mem.Allocator, d: common.FileDiff) []const BodyLine {
122+pub fn diffBody(a: std.mem.Allocator, d: tools.FileDiff) []const BodyLine {
123123 if (d.patch) |patch| {
124124 const trimmed = std.mem.trimEnd(u8, patch, " \t\r\n");
125125 var it = std.mem.splitScalar(u8, trimmed, '\n');
src/tui/tui.zig+3−4
@@ -7,7 +7,6 @@ const types = @import("../types.zig");
77 const agent = @import("../agent.zig");
88 const models_mod = @import("../models.zig");
99 const tools_index = @import("../tools.zig");
10-const common = @import("../tools/common.zig");
1110 const render = @import("render.zig");
1211 const theme = @import("theme.zig");
1312 const styles = @import("styles.zig");
@@ -396,7 +395,7 @@ const Tui = struct {
396395 }
397396 }
398397
399- fn commitToolResult(self: *Tui, name: []const u8, text: []const u8, is_error: bool, diffs: []const common.FileDiff, body: ?[]const u8) void {
398+ fn commitToolResult(self: *Tui, name: []const u8, text: []const u8, is_error: bool, diffs: []const tools_index.FileDiff, body: ?[]const u8) void {
400399 self.scrollback.separator = true;
401400 const shown = render.stripAnsi(self.s, text);
402401 const meta: ?[]const u8 = if (!is_error) body else null;
@@ -815,8 +814,8 @@ fn copyEvent(a: std.mem.Allocator, e: agent.Event) agent.Event {
815814 .arguments = a.dupe(u8, tc.arguments) catch "",
816815 } },
817816 .tool_result => |tr| blk: {
818- var diffs: []const common.FileDiff = &.{};
819- if (a.alloc(common.FileDiff, tr.diffs.len)) |buf| {
817+ var diffs: []const tools_index.FileDiff = &.{};
818+ if (a.alloc(tools_index.FileDiff, tr.diffs.len)) |buf| {
820819 for (tr.diffs, 0..) |d, i| buf[i] = .{
821820 .path = a.dupe(u8, d.path) catch "",
822821 .patch = if (d.patch) |p| a.dupe(u8, p) catch "" else null,