xonecas.io
79113
Ma

mini-coding-agent / commit 6a5249f

feat: configurable snapshot ignore list

xonecas2026-10-06 6a5249f1f76f366e18b5e921074e48cc28b9bfdc parent 8a100eb

7 files changed

notes.md+0−10
@@ -33,16 +33,6 @@ A definite research about the best approach to a clean rendering method is requi
3333 I suggest the above structure, so we match the work we did for opencode. Basically the mistake here is assuming all providers use the same api for all models, which is not true. Not even for local envs.
3434 Another note here is that again, I'm shocked at how cumbersome it is to read and validate JSON.
3535
36-`src/snapshot.zig` - the list of ignored paths is meant to come from the config, not this incomplete hardcoded list.
37-
38-```json
39-{
40- // ... other fields
41- snapshotIgnoreDirs: ["./zig-out", "./.zig-cache"] // list of paths, each line like a gitignore line.
42- snapshotUsesGitignore: true, // merges the list above with gitignore, no dupes!
43-}
44-```
45-
4636 `src/main.zig` - has some headless concerns mixed into the entry point of the app. Worth considering extracting headless into `src/headless.zig`. Single concern files are easier to make a mental model around.
4737
4838 `src/diff.zig` - We are rendering a whole header with index and divider, just to strip it in the TUI. Seems counter productive.
src/agent.zig+4−0
@@ -4,6 +4,7 @@ const api = @import("api.zig");
44 const tools = @import("tools/index.zig");
55 const common = @import("tools/common.zig");
66 const session = @import("session.zig");
7+const config = @import("config.zig");
78 const util = @import("util.zig");
89
910 pub const Phase = enum { preparing, waiting_model, streaming, running_tool, pausing, idle };
@@ -58,6 +59,7 @@ pub const Options = struct {
5859 supports_images: bool,
5960 session: *session.Session,
6061 cancel: *const std.atomic.Value(bool),
62+ config: *const config.Config,
6163 };
6264
6365 const StreamCtx = struct { listener: Listener, started: bool = false };
@@ -214,6 +216,8 @@ pub fn runTurn(opts: Options, messages: *std.ArrayList(types.Message), interacti
214216 .cancel = opts.cancel,
215217 .supports_images = opts.supports_images,
216218 .on_output = .{ .ctx = &stream_ctx.listener, .on_chunk = onToolOutput },
219+ .snapshot_ignore_dirs = opts.config.snapshot_ignore_dirs,
220+ .snapshot_uses_gitignore = opts.config.snapshot_uses_gitignore,
217221 });
218222
219223 const tool_message = types.Message{ .tool_result = .{
src/config.zig+8−0
@@ -34,6 +34,8 @@ pub const Config = struct {
3434 thinking_effort: ?[]const u8,
3535 theme: []const u8,
3636 custom_providers: []const CustomProvider,
37+ snapshot_ignore_dirs: []const []const u8,
38+ snapshot_uses_gitignore: bool,
3739 };
3840
3941 const File = struct {
@@ -47,6 +49,8 @@ const File = struct {
4749 @"thinkingEffort": ?[]const u8 = null,
4850 @"customProviders": ?[]const CustomProvider = null,
4951 theme: ?[]const u8 = null,
52+ @"snapshotIgnoreDirs": ?[]const []const u8 = null,
53+ @"snapshotUsesGitignore": ?bool = null,
5054 };
5155
5256 fn configDir(a: std.mem.Allocator) []const u8 {
@@ -105,6 +109,8 @@ fn readInto(a: std.mem.Allocator, path: []const u8, required: bool, cfg: *Config
105109 if (file.@"customProviders") |v| cfg.custom_providers = v;
106110 if (file.@"thinkingEffort") |v| cfg.thinking_effort = v;
107111 if (file.theme) |v| cfg.theme = v;
112+ if (file.@"snapshotIgnoreDirs") |v| cfg.snapshot_ignore_dirs = v;
113+ if (file.@"snapshotUsesGitignore") |v| cfg.snapshot_uses_gitignore = v;
108114 }
109115
110116 pub const Update = struct {
@@ -152,5 +158,7 @@ fn defaults(a: std.mem.Allocator) !Config {
152158 .thinking_effort = null,
153159 .theme = theme.default_id,
154160 .custom_providers = &.{},
161+ .snapshot_ignore_dirs = &.{},
162+ .snapshot_uses_gitignore = false,
155163 };
156164 }
src/main.zig+1−0
@@ -172,6 +172,7 @@ fn run() !u8 {
172172 .supports_images = supports_images,
173173 .session = &sess,
174174 .cancel = &cancel,
175+ .config = &cfg,
175176 };
176177
177178 if (args.print) |print_text| {
src/tools/bash.zig+3−2
@@ -64,7 +64,8 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
6464 return fail(a, "bash failed: command must be a string", .{});
6565 };
6666
67- const before = snapshot.capture(scratch) catch return fail(a, "bash failed: out of memory", .{});
67+ const ignore = snapshot.Ignore{ .dirs = ctx.snapshot_ignore_dirs, .uses_gitignore = ctx.snapshot_uses_gitignore };
68+ const before = snapshot.capture(scratch, ignore) catch return fail(a, "bash failed: out of memory", .{});
6869
6970 var child = std.process.spawn(platform.io, .{
7071 .argv = &.{ "bash", "-c", args.command },
@@ -159,7 +160,7 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
159160 out.appendSlice(a, std.fmt.allocPrint(scratch, "exit code: {s}", .{label}) catch "exit code: unknown") catch
160161 return fail(a, "bash failed: out of memory", .{});
161162
162- const after = snapshot.capture(scratch) catch return fail(a, "bash failed: out of memory", .{});
163+ const after = snapshot.capture(scratch, ignore) catch return fail(a, "bash failed: out of memory", .{});
163164 const diffs = snapshot.diffTrees(scratch, before, after) catch return fail(a, "bash failed: out of memory", .{});
164165
165166 return .{
src/tools/common.zig+2−0
@@ -14,6 +14,8 @@ pub const Context = struct {
1414 cancel: *const std.atomic.Value(bool),
1515 supports_images: bool,
1616 on_output: ?OutputFn = null,
17+ snapshot_ignore_dirs: []const []const u8 = &.{},
18+ snapshot_uses_gitignore: bool = false,
1719 };
1820
1921 pub const FileDiff = struct {
src/tools/snapshot.zig+24−12
@@ -1,5 +1,6 @@
11 const std = @import("std");
22 const platform = @import("../platform.zig");
3+const util = @import("../util.zig");
34 const diff = @import("../diff.zig");
45 const common = @import("common.zig");
56
@@ -7,12 +8,6 @@ const max_file_bytes = 1 << 20;
78 const max_total_bytes = 32 << 20;
89 const binary_sniff = 8192;
910
10-const ignored_dirs = [_][]const u8{
11- ".git", ".hg", ".svn", "node_modules",
12- ".venv", "venv", "__pycache__", ".mypy_cache",
13- ".pytest_cache",
14-};
15-
1611 const Kind = enum { text, binary, large, link, untracked };
1712
1813 const FileState = struct {
@@ -25,20 +20,37 @@ const FileState = struct {
2520
2621 pub const Tree = std.StringHashMap(FileState);
2722
28-fn ignored(name: []const u8) bool {
29- for (ignored_dirs) |d| {
30- if (std.mem.eql(u8, d, name)) return true;
23+pub const Ignore = struct {
24+ dirs: []const []const u8 = &.{},
25+ uses_gitignore: bool = false,
26+};
27+
28+fn ignoreSet(tmp: std.mem.Allocator, ignore: Ignore) !std.StringHashMap(void) {
29+ var set = std.StringHashMap(void).init(tmp);
30+ var list: std.ArrayList([]const u8) = .empty;
31+ try list.appendSlice(tmp, ignore.dirs);
32+ if (ignore.uses_gitignore) {
33+ if (util.readFileAlloc(tmp, ".gitignore", 1 << 20)) |text| {
34+ var it = std.mem.tokenizeScalar(u8, text, '\n');
35+ while (it.next()) |line| try list.append(tmp, line);
36+ } else |_| {}
37+ }
38+ for (list.items) |dir| {
39+ const gop = try set.getOrPut(dir);
40+ if (!gop.found_existing) gop.key_ptr.* = dir;
3141 }
32- return false;
42+ return set;
3343 }
3444
35-pub fn capture(a: std.mem.Allocator) !Tree {
45+pub fn capture(a: std.mem.Allocator, ignore: Ignore) !Tree {
3646 var tree = Tree.init(a);
3747
3848 var arena = std.heap.ArenaAllocator.init(a);
3949 defer arena.deinit();
4050 const tmp = arena.allocator();
4151
52+ const ignores = try ignoreSet(tmp, ignore);
53+
4254 var stack: std.ArrayList([]const u8) = .empty;
4355 try stack.append(tmp, "");
4456
@@ -56,7 +68,7 @@ pub fn capture(a: std.mem.Allocator) !Tree {
5668 try std.fmt.allocPrint(a, "{s}/{s}", .{ dir_rel, entry.name });
5769
5870 if (entry.kind == .directory) {
59- if (!ignored(entry.name)) try stack.append(tmp, rel);
71+ if (!ignores.contains(entry.name)) try stack.append(tmp, rel);
6072 continue;
6173 }