xonecas.io
79113
Ma

mini-coding-agent / commit c984a9b

chore: code organization, separate concerns into their own modules

xonecas2026-10-07 c984a9be2d93294a1a37db0b66079fdeedc60335 parent 320a3e3

28 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

notes.md+1−7
@@ -5,7 +5,7 @@
55 Some of my notes might be because of lack of Zig experience.
66 These are **my** notes. Use your own file for your notes...
77
8-## Notes
8+## Notes from my code review
99
1010 `src/config.zig` - When we fixed the issue with the model specific api being at provider level for opencode in a recent commit, apparently we didn't do it for custom providers. Again, the models need to carry the metadata, the provider is just a label grouping.
1111
@@ -27,10 +27,4 @@ These are **my** notes. Use your own file for your notes...
2727 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.
2828 Another note here is that again, I'm shocked at how cumbersome it is to read and validate JSON.
2929
30-**`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.
31-
32-`src/diff.zig` - We are rendering a whole header with index and divider, just to strip it in the TUI. Seems counter productive.
33-
34-`src/tui/tui.zig` - This file has a lot of responsibilities, making it very big. Token estimation and commands at least, could be extracted.
35-
3630 `src/tui/theme.zig` - will eventually grow too much, each theme we add will make that file worse. A refactor for later, since it's ok right now.
src/agent.zig+3−3
@@ -6,7 +6,7 @@ const tools = @import("tools/index.zig");
66 const common = @import("tools/common.zig");
77 const session = @import("session.zig");
88 const config = @import("config.zig");
9-const util = @import("util.zig");
9+const time = @import("time.zig");
1010
1111 pub const Phase = enum { preparing, waiting_model, streaming, running_tool, pausing, idle };
1212
@@ -102,7 +102,7 @@ fn pushMessage(opts: Options, messages: *std.ArrayList(types.Message), message:
102102
103103 fn steer(opts: Options, messages: *std.ArrayList(types.Message), content: []const u8) !void {
104104 if (content.len == 0) return;
105- const message = types.Message{ .user = .{ .content = content, .timestamp = util.nowMs() } };
105+ const message = types.Message{ .user = .{ .content = content, .timestamp = time.nowMs() } };
106106 try pushMessage(opts, messages, message);
107107 try opts.session.appendMessage(opts.a, message);
108108 }
@@ -259,7 +259,7 @@ pub fn runTurn(opts: Options, messages: *std.ArrayList(types.Message), interacti
259259 .text = if (result) |r| r.text else "aborted",
260260 .images = if (result) |r| r.images else &.{},
261261 .is_error = if (result) |r| r.is_error else true,
262- .timestamp = util.nowMs(),
262+ .timestamp = time.nowMs(),
263263 } };
264264 pushMessage(opts, messages, tool_message) catch {
265265 listener.emit(.{ .err = "out of memory" });
src/api.zig+2−2
@@ -1,7 +1,7 @@
11 const std = @import("std");
22 const types = @import("types.zig");
33 const http = @import("http.zig");
4-const util = @import("util.zig");
4+const time = @import("time.zig");
55
66 pub const Event = union(enum) {
77 text: []const u8,
@@ -166,7 +166,7 @@ fn newAssistant(req: Request) types.AssistantMessage {
166166 .api = req.model.api,
167167 .provider = req.model.provider,
168168 .model = req.model.id,
169- .timestamp = util.nowMs(),
169+ .timestamp = time.nowMs(),
170170 };
171171 }
172172
src/config.zig+9−9
@@ -1,6 +1,6 @@
11 const std = @import("std");
22 const platform = @import("platform.zig");
3-const util = @import("util.zig");
3+const filesystem = @import("filesystem.zig");
44 const theme = @import("tui/theme.zig");
55
66 pub const ToolName = enum { edit, read, bash };
@@ -55,20 +55,20 @@ const File = struct {
5555
5656 fn configDir(a: std.mem.Allocator) []const u8 {
5757 const base = platform.getEnv("XDG_CONFIG_HOME") orelse
58- util.join(a, &.{ platform.home() orelse "", ".config" }) catch "";
59- return util.join(a, &.{ base, "mini-coding-agent" }) catch "mini-coding-agent";
58+ filesystem.join(a, &.{ platform.home() orelse "", ".config" }) catch "";
59+ return filesystem.join(a, &.{ base, "mini-coding-agent" }) catch "mini-coding-agent";
6060 }
6161
6262 pub fn configPath(a: std.mem.Allocator) []const u8 {
63- return util.join(a, &.{ configDir(a), "config.json" }) catch "config.json";
63+ return filesystem.join(a, &.{ configDir(a), "config.json" }) catch "config.json";
6464 }
6565
6666 fn sessionsDir(a: std.mem.Allocator) []const u8 {
6767 const state = platform.getEnv("XDG_STATE_HOME") orelse blk: {
6868 const home = platform.home() orelse return "sessions";
69- break :blk util.join(a, &.{ home, ".local/state" }) catch return "sessions";
69+ break :blk filesystem.join(a, &.{ home, ".local/state" }) catch return "sessions";
7070 };
71- return util.join(a, &.{ state, "mini-coding-agent/sessions" }) catch "sessions";
71+ return filesystem.join(a, &.{ state, "mini-coding-agent/sessions" }) catch "sessions";
7272 }
7373
7474 pub fn load(a: std.mem.Allocator, override: ?[]const u8) !Config {
@@ -83,7 +83,7 @@ pub fn load(a: std.mem.Allocator, override: ?[]const u8) !Config {
8383 }
8484
8585 fn readInto(a: std.mem.Allocator, path: []const u8, required: bool, cfg: *Config) !void {
86- const text = util.readFileAlloc(a, path, 1 << 20) catch |e| switch (e) {
86+ const text = filesystem.readFileAlloc(a, path, 1 << 20) catch |e| switch (e) {
8787 error.FileNotFound => {
8888 if (!required) return;
8989 platform.printErr("config {s}: no such file\n", .{path});
@@ -126,7 +126,7 @@ pub fn save(a: std.mem.Allocator, cfg: *const Config, update: Update) !void {
126126
127127 const path = cfg.path;
128128 var root: std.json.Value = .{ .object = std.json.ObjectMap.empty };
129- if (util.readFileAlloc(tmp, path, 1 << 20)) |text| {
129+ if (filesystem.readFileAlloc(tmp, path, 1 << 20)) |text| {
130130 const parsed = std.json.parseFromSliceLeaky(std.json.Value, tmp, text, .{}) catch
131131 return error.InvalidConfig;
132132 if (parsed != .object) return error.InvalidConfig;
@@ -141,7 +141,7 @@ pub fn save(a: std.mem.Allocator, cfg: *const Config, update: Update) !void {
141141 return error.OutOfMemory;
142142 const out = try std.fmt.allocPrint(tmp, "{s}\n", .{json_text});
143143 const temp = try std.fmt.allocPrint(tmp, "{s}.tmp", .{path});
144- try util.writeFile(temp, out);
144+ try filesystem.writeFile(temp, out);
145145 try std.Io.Dir.cwd().rename(temp, std.Io.Dir.cwd(), path, platform.io);
146146 }
147147
src/diff.zig+1−2
@@ -129,7 +129,7 @@ fn addRange(w: *std.Io.Writer, start: usize, count: usize) !void {
129129 }
130130 }
131131
132-pub fn unified(a: std.mem.Allocator, path: []const u8, before: []const u8, after: []const u8) ![]u8 {
132+pub fn unified(a: std.mem.Allocator, before: []const u8, after: []const u8) ![]u8 {
133133 var arena = std.heap.ArenaAllocator.init(a);
134134 defer arena.deinit();
135135 const tmp = arena.allocator();
@@ -149,7 +149,6 @@ pub fn unified(a: std.mem.Allocator, path: []const u8, before: []const u8, after
149149
150150 var out: std.Io.Writer.Allocating = .init(a);
151151 const w = &out.writer;
152- try w.print("Index: {s}\n===================================================================\n--- {s}\n+++ {s}\n", .{ path, path, path });
153152
154153 var i: usize = 0;
155154 while (i < ops.len) {
src/filesystem.zig+36−0
@@ -0,0 +1,36 @@
1+const std = @import("std");
2+const platform = @import("platform.zig");
3+
4+pub fn join(a: std.mem.Allocator, parts: []const []const u8) ![]u8 {
5+ return std.fs.path.join(a, parts);
6+}
7+
8+pub fn readFileAlloc(a: std.mem.Allocator, path: []const u8, max: usize) ![]u8 {
9+ return std.Io.Dir.cwd().readFileAlloc(platform.io, path, a, .limited(max));
10+}
11+
12+pub fn writeFile(path: []const u8, data: []const u8) !void {
13+ if (std.fs.path.dirname(path)) |dir| {
14+ std.Io.Dir.cwd().createDirPath(platform.io, dir) catch {};
15+ }
16+ const f = try std.Io.Dir.cwd().createFile(platform.io, path, .{ .truncate = true });
17+ defer f.close(platform.io);
18+ try f.writeStreamingAll(platform.io, data);
19+}
20+
21+pub fn fileExists(path: []const u8) bool {
22+ std.Io.Dir.cwd().access(platform.io, path, .{}) catch return false;
23+ return true;
24+}
25+
26+pub fn listDir(a: std.mem.Allocator, root: []const u8) [][]u8 {
27+ var out: std.ArrayList([]u8) = .empty;
28+ const dir = std.Io.Dir.cwd().openDir(platform.io, root, .{ .iterate = true }) catch return &.{};
29+ defer dir.close(platform.io);
30+ var it = dir.iterate();
31+ while (it.next(platform.io) catch return out.toOwnedSlice(a) catch &.{}) |entry| {
32+ out.append(a, a.dupe(u8, entry.name) catch return out.toOwnedSlice(a) catch &.{}) catch
33+ return out.toOwnedSlice(a) catch &.{};
34+ }
35+ return out.toOwnedSlice(a) catch &.{};
36+}
src/headless.zig+78−0
@@ -0,0 +1,78 @@
1+const std = @import("std");
2+const platform = @import("platform.zig");
3+const time = @import("time.zig");
4+const config = @import("config.zig");
5+const types = @import("types.zig");
6+const agent = @import("agent.zig");
7+
8+var cancel = std.atomic.Value(bool).init(false);
9+
10+fn onSignal(_: std.posix.SIG) callconv(.c) void {
11+ cancel.store(true, .release);
12+}
13+
14+const PrintCtx = struct { failed: bool = false };
15+
16+fn printEvent(ctx: *anyopaque, event: agent.Event) void {
17+ const pc: *PrintCtx = @ptrCast(@alignCast(ctx));
18+ switch (event) {
19+ .tool_call => |call| platform.printErr("[tool] {s}\n", .{call.name}),
20+ .tool_output => |chunk| platform.writeErr(chunk),
21+ .no_model => {
22+ pc.failed = true;
23+ platform.printErr("[error] no model configured; add \"provider\" and \"model\" to {s}\n", .{config.configPath(platform.gpa)});
24+ },
25+ .err => |message| {
26+ pc.failed = true;
27+ platform.printErr("[error] {s}\n", .{message});
28+ },
29+ .cancelled => {
30+ pc.failed = true;
31+ platform.printErr("[cancelled]\n", .{});
32+ },
33+ else => {},
34+ }
35+}
36+
37+pub fn run(a: std.mem.Allocator, prompt_text: []const u8, opts: agent.Options) u8 {
38+ var messages: std.ArrayList(types.Message) = .empty;
39+ const user = types.Message{ .user = .{ .content = prompt_text, .timestamp = time.nowMs() } };
40+ messages.append(a, user) catch {
41+ platform.printErr("[error] out of memory\n", .{});
42+ return 1;
43+ };
44+ opts.session.appendMessage(a, user) catch |e| {
45+ platform.printErr("[error] {s}\n", .{@errorName(e)});
46+ return 1;
47+ };
48+
49+ const act = std.posix.Sigaction{
50+ .handler = .{ .handler = onSignal },
51+ .mask = std.posix.sigemptyset(),
52+ .flags = 0,
53+ };
54+ std.posix.sigaction(std.posix.SIG.INT, &act, null);
55+ std.posix.sigaction(std.posix.SIG.TERM, &act, null);
56+
57+ var pc = PrintCtx{};
58+ var o = opts;
59+ o.cancel = &cancel;
60+ agent.runTurn(o, &messages, null, .{ .ctx = &pc, .on_event = printEvent });
61+ opts.session.close();
62+ if (pc.failed) return 1;
63+
64+ var i = messages.items.len;
65+ const last = while (i > 0) {
66+ i -= 1;
67+ if (messages.items[i] == .assistant) break messages.items[i].assistant;
68+ } else return 0;
69+ const text = types.assistantText(a, last) catch {
70+ platform.printErr("[error] out of memory\n", .{});
71+ return 1;
72+ };
73+ if (text.len > 0) {
74+ platform.writeOut(text);
75+ if (text[text.len - 1] != '\n') platform.writeOut("\n");
76+ }
77+ return 0;
78+}
src/main.zig+2−70
@@ -1,6 +1,5 @@
11 const std = @import("std");
22 const platform = @import("platform.zig");
3-const util = @import("util.zig");
43 const config = @import("config.zig");
54 const prompt = @import("prompt.zig");
65 const models = @import("models.zig");
@@ -10,6 +9,7 @@ const agent = @import("agent.zig");
109 const tools = @import("tools/index.zig");
1110 const tui = @import("tui/tui.zig");
1211 const term = @import("tui/term.zig");
12+const headless = @import("headless.zig");
1313
1414 pub const panic = std.debug.FullPanic(panicRestore);
1515
@@ -27,10 +27,6 @@ pub const debug = struct {
2727
2828 var cancel = std.atomic.Value(bool).init(false);
2929
30-fn onSignal(_: std.posix.SIG) callconv(.c) void {
31- cancel.store(true, .release);
32-}
33-
3430 const ParsedArgs = struct { print: ?[]const u8 = null, config: ?[]const u8 = null };
3531
3632 fn parseArgs(a: std.mem.Allocator) !ParsedArgs {
@@ -58,70 +54,6 @@ fn parseArgs(a: std.mem.Allocator) !ParsedArgs {
5854 return result;
5955 }
6056
61-const PrintCtx = struct { failed: bool = false };
62-
63-fn printEvent(ctx: *anyopaque, event: agent.Event) void {
64- const pc: *PrintCtx = @ptrCast(@alignCast(ctx));
65- switch (event) {
66- .tool_call => |call| platform.printErr("[tool] {s}\n", .{call.name}),
67- .tool_output => |chunk| platform.writeErr(chunk),
68- .no_model => {
69- pc.failed = true;
70- platform.printErr("[error] no model configured; add \"provider\" and \"model\" to {s}\n", .{config.configPath(platform.gpa)});
71- },
72- .err => |message| {
73- pc.failed = true;
74- platform.printErr("[error] {s}\n", .{message});
75- },
76- .cancelled => {
77- pc.failed = true;
78- platform.printErr("[cancelled]\n", .{});
79- },
80- else => {},
81- }
82-}
83-
84-fn runPrint(a: std.mem.Allocator, prompt_text: []const u8, opts: agent.Options) u8 {
85- var messages: std.ArrayList(types.Message) = .empty;
86- const user = types.Message{ .user = .{ .content = prompt_text, .timestamp = util.nowMs() } };
87- messages.append(a, user) catch {
88- platform.printErr("[error] out of memory\n", .{});
89- return 1;
90- };
91- opts.session.appendMessage(a, user) catch |e| {
92- platform.printErr("[error] {s}\n", .{@errorName(e)});
93- return 1;
94- };
95-
96- const act = std.posix.Sigaction{
97- .handler = .{ .handler = onSignal },
98- .mask = std.posix.sigemptyset(),
99- .flags = 0,
100- };
101- std.posix.sigaction(std.posix.SIG.INT, &act, null);
102- std.posix.sigaction(std.posix.SIG.TERM, &act, null);
103-
104- var pc = PrintCtx{};
105- agent.runTurn(opts, &messages, null, .{ .ctx = &pc, .on_event = printEvent });
106- opts.session.close();
107- if (pc.failed) return 1;
108-
109- var i = messages.items.len;
110- const last = while (i > 0) {
111- i -= 1;
112- if (messages.items[i] == .assistant) break messages.items[i].assistant;
113- } else return 0;
114- const text = types.assistantText(a, last) catch {
115- platform.printErr("[error] out of memory\n", .{});
116- return 1;
117- };
118- if (text.len > 0) {
119- platform.writeOut(text);
120- if (text[text.len - 1] != '\n') platform.writeOut("\n");
121- }
122- return 0;
123-}
124-
12557 pub fn main(init: std.process.Init) void {
12658 platform.setup(init);
12759 const code = run() catch |e| {
@@ -180,7 +112,7 @@ fn run() !u8 {
180112 platform.printErr("[error] no model configured; add \"provider\" and \"model\" to {s}\n", .{config.configPath(a)});
181113 return 1;
182114 }
183- return runPrint(a, print_text, opts);
115+ return headless.run(a, print_text, opts);
184116 }
185117
186118 const stdin_tty = std.Io.File.stdin().isTty(platform.io) catch false;
src/prompt.zig+9−9
@@ -1,6 +1,6 @@
11 const std = @import("std");
22 const platform = @import("platform.zig");
3-const util = @import("util.zig");
3+const filesystem = @import("filesystem.zig");
44 const config = @import("config.zig");
55
66 const Skill = struct { name: []const u8, description: []const u8, path: []const u8 };
@@ -27,10 +27,10 @@ fn frontmatter(text: []const u8) Frontmatter {
2727 fn discoverSkills(a: std.mem.Allocator, dirs: []const []const u8) ![]Skill {
2828 var skills: std.ArrayList(Skill) = .empty;
2929 for (dirs) |root| {
30- for (util.listDir(a, root)) |entry| {
31- const path = util.join(a, &.{ root, entry, "SKILL.md" }) catch continue;
32- if (!util.fileExists(path)) continue;
33- const text = util.readFileAlloc(a, path, 1 << 20) catch continue;
30+ for (filesystem.listDir(a, root)) |entry| {
31+ const path = filesystem.join(a, &.{ root, entry, "SKILL.md" }) catch continue;
32+ if (!filesystem.fileExists(path)) continue;
33+ const text = filesystem.readFileAlloc(a, path, 1 << 20) catch continue;
3434 const meta = frontmatter(text);
3535 const name = meta.name orelse continue;
3636 try skills.append(a, .{
@@ -46,7 +46,7 @@ fn discoverSkills(a: std.mem.Allocator, dirs: []const []const u8) ![]Skill {
4646 fn agentFiles(a: std.mem.Allocator) ![]const []const u8 {
4747 var roots: std.ArrayList([]const u8) = .empty;
4848 if (platform.home()) |h| {
49- const agents = util.join(a, &.{ h, ".agents" }) catch "";
49+ const agents = filesystem.join(a, &.{ h, ".agents" }) catch "";
5050 if (agents.len > 0) try roots.append(a, agents);
5151 }
5252 const cwd = try std.process.currentPathAlloc(platform.io, a);
@@ -54,8 +54,8 @@ fn agentFiles(a: std.mem.Allocator) ![]const []const u8 {
5454 var found: std.ArrayList([]const u8) = .empty;
5555 for (roots.items) |root| {
5656 for ([_][]const u8{ "AGENTS.md", "CLAUDE.md" }) |name| {
57- const path = try util.join(a, &.{ root, name });
58- if (util.fileExists(path)) try found.append(a, path);
57+ const path = try filesystem.join(a, &.{ root, name });
58+ if (filesystem.fileExists(path)) try found.append(a, path);
5959 }
6060 }
6161 return found.items;
@@ -89,7 +89,7 @@ pub fn buildSystemPrompt(a: std.mem.Allocator, cfg: *const config.Config) !Built
8989 const files = try agentFiles(a);
9090 loaded.agent_files = files.len;
9191 for (files) |path| {
92- const text = try util.readFileAlloc(a, path, 1 << 24);
92+ const text = try filesystem.readFileAlloc(a, path, 1 << 24);
9393 try sections.append(a, try std.fmt.allocPrint(a, "## {s}\n\n{s}", .{
9494 path,
9595 std.mem.trim(u8, text, " \t\r\n"),
src/session.zig+15−9
@@ -1,6 +1,8 @@
11 const std = @import("std");
22 const platform = @import("platform.zig");
3-const util = @import("util.zig");
3+const time = @import("time.zig");
4+const filesystem = @import("filesystem.zig");
5+const text = @import("text.zig");
46 const types = @import("types.zig");
57
68 const alphabet = "0123456789abcdefghijklmnopqrstuvwxyz";
@@ -168,13 +170,13 @@ pub const Session = struct {
168170
169171 pub fn appendMessage(self: *Session, scratch: std.mem.Allocator, message: types.Message) !void {
170172 if (self.closed) return;
171- try self.ensure(if (message == .user) util.slugify(self.a, message.user.content) else "session");
173+ try self.ensure(if (message == .user) text.slugify(self.a, message.user.content) else "session");
172174
173175 var arena = std.heap.ArenaAllocator.init(scratch);
174176 defer arena.deinit();
175177 const a = arena.allocator();
176178 const line = try stringify(a, MessageLine{
177- .at = util.isoAlloc(a),
179+ .at = time.isoAlloc(a),
178180 .message = try messageRecord(a, message),
179181 });
180182 try self.commitLine(scratch, line);
@@ -188,7 +190,7 @@ pub const Session = struct {
188190 defer arena.deinit();
189191 const a = arena.allocator();
190192 const line = try stringify(a, RequestLine{
191- .at = util.isoAlloc(a),
193+ .at = time.isoAlloc(a),
192194 .provider = req.provider,
193195 .model = req.model,
194196 .api = req.api,
@@ -220,19 +222,19 @@ pub const Session = struct {
220222 if (self.file != null) return;
221223 std.Io.Dir.cwd().createDirPath(platform.io, self.sessions_dir) catch {};
222224 var stamp_buf: [15]u8 = undefined;
223- const stamp = util.stamp(&stamp_buf, util.nowMs());
225+ const stamp = time.stamp(&stamp_buf, time.nowMs());
224226
225227 var attempt: usize = 0;
226228 while (attempt < 16) : (attempt += 1) {
227229 var id_buf: [6]u8 = undefined;
228230 shortId(&id_buf);
229231 const name = try std.fmt.allocPrint(self.a, "{s}-{s}-{s}", .{ stamp, title, &id_buf });
230- const dir = try util.join(self.a, &.{ self.sessions_dir, name });
232+ const dir = try filesystem.join(self.a, &.{ self.sessions_dir, name });
231233 std.Io.Dir.cwd().createDir(platform.io, dir, .default_dir) catch |e| switch (e) {
232234 error.PathAlreadyExists => continue,
233235 else => return e,
234236 };
235- const log_path = try util.join(self.a, &.{ dir, "session.jsonl" });
237+ const log_path = try filesystem.join(self.a, &.{ dir, "session.jsonl" });
236238 const file = try std.Io.Dir.cwd().createFile(platform.io, log_path, .{ .truncate = false });
237239 self.id = name;
238240 self.file = file;
@@ -242,7 +244,7 @@ pub const Session = struct {
242244 try w.writeAll(try stringify(self.a, HeaderLine{
243245 .id = name,
244246 .cwd = self.cwd,
245- .createdAt = util.isoAlloc(self.a),
247+ .createdAt = time.isoAlloc(self.a),
246248 .title = title,
247249 }));
248250 try w.writeByte('\n');
@@ -260,11 +262,15 @@ pub const Session = struct {
260262
261263 fn shortId(buf: *[6]u8) void {
262264 var bytes: [6]u8 = undefined;
263- util.randomBytes(&bytes);
265+ randomBytes(&bytes);
264266 for (bytes, 0..) |b, i| buf[i] = alphabet[b % 36];
265267 }
266268 };
267269
270+fn randomBytes(buf: []u8) void {
271+ std.Io.random(platform.io, buf);
272+}
273+
268274 fn messageRecord(a: std.mem.Allocator, message: types.Message) !MessageRecord {
269275 switch (message) {
270276 .user => |u| return .{ .user = .{ .content = u.content, .timestamp = u.timestamp } },
src/text.zig+61−0
@@ -0,0 +1,61 @@
1+const std = @import("std");
2+
3+fn utf8SeqLen(p: []const u8) ?usize {
4+ if (p.len == 0) return null;
5+ const c = p[0];
6+ if (c >= 0xC2 and c <= 0xDF) {
7+ if (p.len >= 2 and p[1] & 0xC0 == 0x80) return 2;
8+ } else if (c == 0xE0) {
9+ if (p.len >= 3 and p[1] >= 0xA0 and p[1] <= 0xBF and p[2] & 0xC0 == 0x80) return 3;
10+ } else if (c >= 0xE1 and c <= 0xEC) {
11+ if (p.len >= 3 and p[1] & 0xC0 == 0x80 and p[2] & 0xC0 == 0x80) return 3;
12+ } else if (c == 0xED) {
13+ if (p.len >= 3 and p[1] >= 0x80 and p[1] <= 0x9F and p[2] & 0xC0 == 0x80) return 3;
14+ } else if (c >= 0xEE and c <= 0xEF) {
15+ if (p.len >= 3 and p[1] & 0xC0 == 0x80 and p[2] & 0xC0 == 0x80) return 3;
16+ } else if (c == 0xF0) {
17+ if (p.len >= 4 and p[1] >= 0x90 and p[1] <= 0xBF and p[2] & 0xC0 == 0x80 and p[3] & 0xC0 == 0x80) return 4;
18+ } else if (c >= 0xF1 and c <= 0xF3) {
19+ if (p.len >= 4 and p[1] & 0xC0 == 0x80 and p[2] & 0xC0 == 0x80 and p[3] & 0xC0 == 0x80) return 4;
20+ } else if (c == 0xF4) {
21+ if (p.len >= 4 and p[1] >= 0x80 and p[1] <= 0x8F and p[2] & 0xC0 == 0x80 and p[3] & 0xC0 == 0x80) return 4;
22+ }
23+ return null;
24+}
25+
26+pub fn utf8Clean(a: std.mem.Allocator, text: []const u8) ![]const u8 {
27+ if (std.unicode.utf8ValidateSlice(text)) return text;
28+ var out: std.ArrayList(u8) = .empty;
29+ var i: usize = 0;
30+ while (i < text.len) {
31+ if (text[i] < 0x80) {
32+ try out.append(a, text[i]);
33+ i += 1;
34+ } else if (utf8SeqLen(text[i..])) |len| {
35+ try out.appendSlice(a, text[i .. i + len]);
36+ i += len;
37+ } else {
38+ try out.appendSlice(a, "\u{FFFD}");
39+ i += 1;
40+ }
41+ }
42+ return out.items;
43+}
44+
45+pub fn slugify(a: std.mem.Allocator, text: []const u8) []const u8 {
46+ var out: std.ArrayList(u8) = .empty;
47+ var pending_dash = false;
48+ for (text) |c| {
49+ if (out.items.len >= 40) break;
50+ const lower = std.ascii.toLower(c);
51+ if (std.ascii.isAlphanumeric(lower)) {
52+ if (pending_dash and out.items.len > 0 and out.items.len < 40) out.append(a, '-') catch {};
53+ pending_dash = false;
54+ out.append(a, lower) catch {};
55+ } else {
56+ pending_dash = true;
57+ }
58+ }
59+ if (out.items.len == 0) return a.dupe(u8, "session") catch "session";
60+ return out.items;
61+}
src/time.zig+51−0
@@ -0,0 +1,51 @@
1+const std = @import("std");
2+const platform = @import("platform.zig");
3+
4+pub fn nowMs() i64 {
5+ return std.Io.Timestamp.now(platform.io, .real).toMilliseconds();
6+}
7+
8+const Date = struct {
9+ year: u16,
10+ month: u8,
11+ day: u8,
12+ hour: u8,
13+ minute: u8,
14+ second: u8,
15+ milli: u64,
16+
17+ fn fromMs(ms: i64) Date {
18+ const epoch = std.time.epoch.EpochSeconds{ .secs = @intCast(@divFloor(ms, 1000)) };
19+ const ymd = epoch.getEpochDay().calculateYearDay();
20+ const md = ymd.calculateMonthDay();
21+ const ds = epoch.getDaySeconds();
22+ return .{
23+ .year = ymd.year,
24+ .month = md.month.numeric(),
25+ .day = md.day_index + 1,
26+ .hour = ds.getHoursIntoDay(),
27+ .minute = ds.getMinutesIntoHour(),
28+ .second = ds.getSecondsIntoMinute(),
29+ .milli = @intCast(@mod(ms, 1000)),
30+ };
31+ }
32+};
33+
34+fn isoFromMs(buf: []u8, ms: i64) []const u8 {
35+ const d = Date.fromMs(ms);
36+ return std.fmt.bufPrint(buf, "{d:0>4}-{d:0>2}-{d:0>2}T{d:0>2}:{d:0>2}:{d:0>2}.{d:0>3}Z", .{
37+ d.year, d.month, d.day, d.hour, d.minute, d.second, d.milli,
38+ }) catch unreachable;
39+}
40+
41+pub fn isoAlloc(a: std.mem.Allocator) []const u8 {
42+ const buf = a.alloc(u8, 32) catch unreachable;
43+ return isoFromMs(buf, nowMs());
44+}
45+
46+pub fn stamp(buf: []u8, ms: i64) []const u8 {
47+ const d = Date.fromMs(ms);
48+ return std.fmt.bufPrint(buf, "{d:0>4}{d:0>2}{d:0>2}-{d:0>2}{d:0>2}{d:0>2}", .{
49+ d.year, d.month, d.day, d.hour, d.minute, d.second,
50+ }) catch unreachable;
51+}
src/tools/bash.zig+8−8
@@ -1,6 +1,6 @@
11 const std = @import("std");
22 const platform = @import("../platform.zig");
3-const util = @import("../util.zig");
3+const text = @import("../text.zig");
44 const common = @import("common.zig");
55 const snapshot = @import("snapshot.zig");
66
@@ -21,14 +21,14 @@ const Acc = struct {
2121
2222 fn append(self: *Acc, chunk: []const u8) !void {
2323 if (self.on_output) |cb| cb.call(chunk);
24- var text = chunk;
24+ var rest = chunk;
2525 if (self.head.items.len < max_head) {
26- const take = @min(max_head - self.head.items.len, text.len);
27- try self.head.appendSlice(self.a, text[0..take]);
28- text = text[take..];
26+ const take = @min(max_head - self.head.items.len, rest.len);
27+ try self.head.appendSlice(self.a, rest[0..take]);
28+ rest = rest[take..];
2929 }
30- if (text.len == 0) return;
31- try self.tail.appendSlice(self.a, text);
30+ if (rest.len == 0) return;
31+ try self.tail.appendSlice(self.a, rest);
3232 if (self.tail.items.len > max_tail) {
3333 self.truncated = true;
3434 const drop = self.tail.items.len - max_tail;
@@ -150,7 +150,7 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
150150 "unknown";
151151
152152 const raw_body = acc.body(scratch) catch return fail(a, "bash failed: out of memory", .{});
153- const body = util.utf8Clean(scratch, raw_body) catch return fail(a, "bash failed: out of memory", .{});
153+ const body = text.utf8Clean(scratch, raw_body) catch return fail(a, "bash failed: out of memory", .{});
154154 var out: std.ArrayList(u8) = .empty;
155155 out.appendSlice(a, body) catch return fail(a, "bash failed: out of memory", .{});
156156 if (body.len > 0 and body[body.len - 1] != '\n') out.append(a, '\n') catch return fail(a, "bash failed: out of memory", .{});
src/tools/edit.zig+9−8
@@ -1,5 +1,6 @@
11 const std = @import("std");
2-const util = @import("../util.zig");
2+const filesystem = @import("../filesystem.zig");
3+const text = @import("../text.zig");
34 const platform = @import("../platform.zig");
45 const diff = @import("../diff.zig");
56 const common = @import("common.zig");
@@ -21,18 +22,18 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
2122 const path = args.path;
2223
2324 if (args.oldText.len == 0) {
24- if (util.fileExists(path)) return fail(a, "edit failed: {s} already exists", .{path});
25+ if (filesystem.fileExists(path)) return fail(a, "edit failed: {s} already exists", .{path});
2526 if (ctx.cancel.load(.acquire)) return fail(a, "edit cancelled", .{});
2627 writeFile(path, args.newText) catch |e| return fail(a, "edit failed: {s}: {s}", .{ path, @errorName(e) });
27- const cleaned = util.utf8Clean(scratch, args.newText) catch return fail(a, "edit failed: out of memory", .{});
28- const patch = diff.unified(scratch, path, "", cleaned) catch return fail(a, "edit failed: out of memory", .{});
28+ const cleaned = text.utf8Clean(scratch, args.newText) catch return fail(a, "edit failed: out of memory", .{});
29+ const patch = diff.unified(scratch, "", cleaned) catch return fail(a, "edit failed: out of memory", .{});
2930 return .{
3031 .text = std.fmt.allocPrint(a, "created {s}\n{s}", .{ path, patch }) catch "created",
3132 .is_error = false,
3233 };
3334 }
3435
35- const before = util.readFileAlloc(scratch, path, 1 << 30) catch |e| {
36+ const before = filesystem.readFileAlloc(scratch, path, 1 << 30) catch |e| {
3637 return fail(a, "edit failed: {s}: {s}", .{ path, @errorName(e) });
3738 };
3839 const at = std.mem.indexOf(u8, before, args.oldText) orelse
@@ -49,9 +50,9 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
4950 return fail(a, "edit failed: out of memory", .{});
5051 if (ctx.cancel.load(.acquire)) return fail(a, "edit cancelled", .{});
5152 writeFile(path, after) catch |e| return fail(a, "edit failed: {s}: {s}", .{ path, @errorName(e) });
52- const clean_before = util.utf8Clean(scratch, before) catch return fail(a, "edit failed: out of memory", .{});
53- const clean_after = util.utf8Clean(scratch, after) catch return fail(a, "edit failed: out of memory", .{});
54- const patch = diff.unified(scratch, path, clean_before, clean_after) catch return fail(a, "edit failed: out of memory", .{});
53+ const clean_before = text.utf8Clean(scratch, before) catch return fail(a, "edit failed: out of memory", .{});
54+ const clean_after = text.utf8Clean(scratch, after) catch return fail(a, "edit failed: out of memory", .{});
55+ const patch = diff.unified(scratch, clean_before, clean_after) catch return fail(a, "edit failed: out of memory", .{});
5556 return .{
5657 .text = std.fmt.allocPrint(a, "edited {s}\n{s}", .{ path, patch }) catch "edited",
5758 .is_error = false,
src/tools/read.zig+15−14
@@ -1,5 +1,6 @@
11 const std = @import("std");
2-const util = @import("../util.zig");
2+const filesystem = @import("../filesystem.zig");
3+const text = @import("../text.zig");
34 const types = @import("../types.zig");
45 const common = @import("common.zig");
56
@@ -31,26 +32,26 @@ fn mimeFor(path: []const u8) ?[]const u8 {
3132 return null;
3233 }
3334
34-fn advance(text: []const u8, pos: usize, n: usize) ?usize {
35+fn advance(content: []const u8, pos: usize, n: usize) ?usize {
3536 var p = pos;
3637 var left = n;
3738 while (left > 0) : (left -= 1) {
38- const nl = std.mem.indexOfScalarPos(u8, text, p, '\n') orelse return null;
39+ const nl = std.mem.indexOfScalarPos(u8, content, p, '\n') orelse return null;
3940 p = nl + 1;
4041 }
4142 return p;
4243 }
4344
44-fn lineSlice(text: []const u8, offset: usize, range: ?usize) ?[]const u8 {
45- const start = advance(text, 0, offset - 1) orelse return null;
46- if (offset > 1 and start >= text.len) return null;
47- if (range) |r| if (advance(text, start, r)) |end| return text[start..end];
48- return text[start..];
45+fn lineSlice(content: []const u8, offset: usize, range: ?usize) ?[]const u8 {
46+ const start = advance(content, 0, offset - 1) orelse return null;
47+ if (offset > 1 and start >= content.len) return null;
48+ if (range) |r| if (advance(content, start, r)) |end| return content[start..end];
49+ return content[start..];
4950 }
5051
51-fn countLines(text: []const u8) usize {
52- if (text.len == 0) return 0;
53- return std.mem.count(u8, text, "\n") + @intFromBool(text[text.len - 1] != '\n');
52+fn countLines(content: []const u8) usize {
53+ if (content.len == 0) return 0;
54+ return std.mem.count(u8, content, "\n") + @intFromBool(content[content.len - 1] != '\n');
5455 }
5556
5657 fn bodyLine(a: std.mem.Allocator, args: Args, lines: usize, truncated: bool) ?[]const u8 {
@@ -79,7 +80,7 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
7980 if (args.offset) |o| if (o < 1) return fail(a, "read failed: offset must be at least 1", .{});
8081 if (args.range) |r| if (r < 1) return fail(a, "read failed: range must be at least 1", .{});
8182
82- const data = util.readFileAlloc(a, path, 1 << 30) catch |e|
83+ const data = filesystem.readFileAlloc(a, path, 1 << 30) catch |e|
8384 return fail(a, "read failed: {s}: {s}", .{ path, @errorName(e) });
8485
8586 if (mimeFor(path)) |mime| {
@@ -108,9 +109,9 @@ pub fn run(a: std.mem.Allocator, scratch: std.mem.Allocator, args_json: []const
108109 return fail(a, "read failed: {s} is binary; use bash (file, xxd)", .{path});
109110 }
110111
111- const text = util.utf8Clean(a, data) catch return fail(a, "read failed: out of memory", .{});
112+ const content = text.utf8Clean(a, data) catch return fail(a, "read failed: out of memory", .{});
112113 const offset = args.offset orelse 1;
113- const slice = lineSlice(text, offset, args.range) orelse
114+ const slice = lineSlice(content, offset, args.range) orelse
114115 return fail(a, "read failed: {s} has fewer than {d} lines", .{ path, offset });
115116
116117 var sent = slice;
src/tools/snapshot.zig+5−5
@@ -1,6 +1,6 @@
11 const std = @import("std");
22 const platform = @import("../platform.zig");
3-const util = @import("../util.zig");
3+const filesystem = @import("../filesystem.zig");
44 const diff = @import("../diff.zig");
55 const common = @import("common.zig");
66
@@ -38,7 +38,7 @@ fn ignoreSet(tmp: std.mem.Allocator, ignore: Ignore) !std.StringHashMap(void) {
3838 var list: std.ArrayList([]const u8) = .empty;
3939 try list.appendSlice(tmp, ignore.dirs);
4040 if (ignore.uses_gitignore) {
41- if (util.readFileAlloc(tmp, ".gitignore", 1 << 20)) |text| {
41+ if (filesystem.readFileAlloc(tmp, ".gitignore", 1 << 20)) |text| {
4242 var it = std.mem.tokenizeScalar(u8, text, '\n');
4343 while (it.next()) |line| try list.append(tmp, line);
4444 } else |_| {}
@@ -136,13 +136,13 @@ fn diffOne(a: std.mem.Allocator, path: []const u8, before: ?FileState, after: ?F
136136 const af = after.?;
137137 if (af.kind == .link) return .{ .path = path, .note = "symlink created" };
138138 if (af.content == null) return .{ .path = path, .note = noteFor(a, af.kind, "created") };
139- return .{ .path = path, .patch = try diff.unified(a, path, "", af.content.?) };
139+ return .{ .path = path, .patch = try diff.unified(a, "", af.content.?) };
140140 }
141141 if (after == null) {
142142 const bf = before.?;
143143 if (bf.kind == .link) return .{ .path = path, .note = "symlink removed" };
144144 if (bf.content == null) return .{ .path = path, .note = noteFor(a, bf.kind, "deleted") };
145- return .{ .path = path, .patch = try diff.unified(a, path, bf.content.?, "") };
145+ return .{ .path = path, .patch = try diff.unified(a, bf.content.?, "") };
146146 }
147147 const bf = before.?;
148148 const af = after.?;
@@ -151,7 +151,7 @@ fn diffOne(a: std.mem.Allocator, path: []const u8, before: ?FileState, after: ?F
151151 }
152152 if (bf.content != null and af.content != null) {
153153 if (std.mem.eql(u8, bf.content.?, af.content.?)) return null;
154- return .{ .path = path, .patch = try diff.unified(a, path, bf.content.?, af.content.?) };
154+ return .{ .path = path, .patch = try diff.unified(a, bf.content.?, af.content.?) };
155155 }
156156 if (sameStat(bf, af)) return null;
157157 return .{ .path = path, .note = noteFor(a, if (af.content == null) af.kind else bf.kind, "changed") };
src/tui/commands.zig+57−0
@@ -0,0 +1,57 @@
1+const std = @import("std");
2+const platform = @import("../platform.zig");
3+const complete = @import("complete.zig");
4+const styles = @import("styles.zig");
5+
6+pub const Command = enum {
7+ help,
8+ new,
9+ provider,
10+ model,
11+ thinking,
12+
13+ pub fn wire(self: Command) []const u8 {
14+ return @tagName(self);
15+ }
16+
17+ pub fn summary(self: Command) []const u8 {
18+ return switch (self) {
19+ .help => "list commands and keybindings",
20+ .new => "start a new session",
21+ .provider => "choose the provider and model",
22+ .model => "choose a model for the current provider",
23+ .thinking => "set the thinking level",
24+ };
25+ }
26+
27+ pub const all = [_]Command{ .help, .new, .provider, .model, .thinking };
28+};
29+
30+pub fn findCommand(text: []const u8) ?Command {
31+ if (text.len == 0 or text[0] != '/') return null;
32+ var i: usize = 1;
33+ while (i < text.len and text[i] != ' ' and text[i] != '\t' and text[i] != '\n') i += 1;
34+ return std.meta.stringToEnum(Command, text[1..i]);
35+}
36+
37+pub fn completeCommand(draft: []const u8) ?[]const u8 {
38+ if (draft.len == 0 or draft[0] != '/') return null;
39+ if (std.mem.indexOfAny(u8, draft, " \t\n") != null) return null;
40+ const typed = draft[1..];
41+ var matched: ?[]const u8 = null;
42+ for (Command.all) |c| {
43+ if (!std.mem.startsWith(u8, c.wire(), typed)) continue;
44+ matched = if (matched) |have| complete.commonPrefix(have, c.wire()) else c.wire();
45+ }
46+ const name = matched orelse return null;
47+ if (name.len <= typed.len) return null;
48+ return std.fmt.allocPrint(platform.gpa, "/{s}", .{name}) catch null;
49+}
50+
51+pub fn helpRow(a: std.mem.Allocator, key: []const u8, description: []const u8, width: usize) []const u8 {
52+ var padded: std.ArrayList(u8) = .empty;
53+ padded.appendSlice(a, key) catch {};
54+ var i = key.len;
55+ while (i < width) : (i += 1) padded.append(a, ' ') catch {};
56+ return std.fmt.allocPrint(a, " {s} {s}", .{ styles.dim(a, padded.items), description }) catch key;
57+}
src/tui/diff_view.zig+137−0
@@ -0,0 +1,137 @@
1+const std = @import("std");
2+const common = @import("../tools/common.zig");
3+const theme = @import("theme.zig");
4+const highlight = @import("highlight.zig");
5+const render = @import("render.zig");
6+
7+const BodyLine = render.BodyLine;
8+
9+fn diffHunk() theme.Style {
10+ return .{ .fg = theme.current.prompt };
11+}
12+
13+const DiffKind = enum { hunk, add, del, ctx, note };
14+
15+fn diffKindOf(kind: []const u8) ?DiffKind {
16+ if (std.mem.eql(u8, kind, "location")) return .hunk;
17+ if (std.mem.eql(u8, kind, "addition")) return .add;
18+ if (std.mem.eql(u8, kind, "deletion")) return .del;
19+ if (std.mem.eql(u8, kind, "context")) return .ctx;
20+ if (highlight.isDiffLineKind(kind)) return .note;
21+ return null;
22+}
23+
24+fn prefixKind(line: []const u8) DiffKind {
25+ if (std.mem.startsWith(u8, line, "@@")) return .hunk;
26+ if (std.mem.startsWith(u8, line, "+")) return .add;
27+ if (std.mem.startsWith(u8, line, "-")) return .del;
28+ if (std.mem.startsWith(u8, line, " ")) return .ctx;
29+ return .note;
30+}
31+
32+fn langFor(path: []const u8) []const u8 {
33+ const ext = std.fs.path.extension(path);
34+ const named = [_]struct { ext: []const u8, lang: []const u8 }{
35+ .{ .ext = ".js", .lang = "js" },
36+ .{ .ext = ".jsx", .lang = "jsx" },
37+ .{ .ext = ".mjs", .lang = "js" },
38+ .{ .ext = ".cjs", .lang = "js" },
39+ .{ .ext = ".ts", .lang = "ts" },
40+ .{ .ext = ".tsx", .lang = "tsx" },
41+ .{ .ext = ".py", .lang = "py" },
42+ .{ .ext = ".go", .lang = "go" },
43+ .{ .ext = ".zig", .lang = "zig" },
44+ };
45+ for (named) |entry| {
46+ if (std.ascii.eqlIgnoreCase(ext, entry.ext)) return entry.lang;
47+ }
48+ return "";
49+}
50+
51+fn rebaseSpans(a: std.mem.Allocator, spans: []const highlight.Span, lo: u32, hi: u32) []const highlight.Span {
52+ var out: std.ArrayList(highlight.Span) = .empty;
53+ for (spans) |s| {
54+ const start = @max(s.start, lo);
55+ const end = @min(s.end, hi);
56+ if (end <= start) continue;
57+ out.append(a, .{ .start = start - lo, .end = end - lo, .style = s.style }) catch {};
58+ }
59+ return out.items;
60+}
61+
62+pub fn diffLines(a: std.mem.Allocator, path: []const u8, lines: []const []const u8) []const BodyLine {
63+ var joined: std.ArrayList(u8) = .empty;
64+ var starts = a.alloc(u32, lines.len) catch return &.{};
65+ for (lines, 0..) |l, i| {
66+ if (i > 0) joined.append(a, '\n') catch {};
67+ starts[i] = @intCast(joined.items.len);
68+ joined.appendSlice(a, l) catch {};
69+ }
70+ const nodes = highlight.diffSpans(a, joined.items);
71+ std.mem.sort(highlight.NodeSpan, nodes, {}, struct {
72+ fn lt(_: void, x: highlight.NodeSpan, y: highlight.NodeSpan) bool {
73+ return x.start < y.start;
74+ }
75+ }.lt);
76+
77+ var code: std.ArrayList(u8) = .empty;
78+ var kinds = a.alloc(DiffKind, lines.len) catch return &.{};
79+ var los = a.alloc(u32, lines.len) catch return &.{};
80+ var his = a.alloc(u32, lines.len) catch return &.{};
81+ var cursor: usize = 0;
82+ for (lines, 0..) |l, i| {
83+ while (cursor < nodes.len and nodes[cursor].end <= starts[i]) cursor += 1;
84+ const parsed: ?DiffKind = if (cursor < nodes.len and nodes[cursor].start == starts[i])
85+ diffKindOf(nodes[cursor].kind)
86+ else
87+ null;
88+ const kind = parsed orelse prefixKind(l);
89+ kinds[i] = kind;
90+ los[i] = 0;
91+ his[i] = 0;
92+ if (kind != .add and kind != .del and kind != .ctx) continue;
93+ const content = l[1..];
94+ los[i] = @intCast(code.items.len);
95+ code.appendSlice(a, content) catch {};
96+ code.append(a, '\n') catch {};
97+ his[i] = @intCast(code.items.len - 1);
98+ }
99+
100+ const spans = highlight.spansFor(a, langFor(path), code.items);
101+
102+ var out: std.ArrayList(BodyLine) = .empty;
103+ for (lines, 0..) |l, i| {
104+ switch (kinds[i]) {
105+ .hunk => out.append(a, .{ .text = l, .style = diffHunk() }) catch {},
106+ .note => out.append(a, .{ .text = l, .style = .{ .fg = theme.current.comment } }) catch {},
107+ .ctx => out.append(a, .{ .text = l, .style = .{ .fg = theme.current.comment } }) catch {},
108+ .add, .del => {
109+ const bg = if (kinds[i] == .add) theme.current.diff_add else theme.current.diff_delete;
110+ const content = l[1..];
111+ const painted = highlight.paint(a, content, rebaseSpans(a, spans, los[i], his[i]), .{ .bg = bg });
112+ out.append(a, .{
113+ .text = std.fmt.allocPrint(a, "{c}{s}", .{ l[0], painted }) catch l,
114+ .bg = bg,
115+ }) catch {};
116+ },
117+ }
118+ }
119+ return out.items;
120+}
121+
122+pub fn diffRows(a: std.mem.Allocator, diffs: []const common.FileDiff) []const BodyLine {
123+ var out: std.ArrayList(BodyLine) = .empty;
124+ for (diffs) |d| {
125+ out.append(a, .{ .text = d.path, .style = .{ .fg = theme.current.prompt } }) catch {};
126+ if (d.patch) |patch| {
127+ const trimmed = std.mem.trimEnd(u8, patch, " \t\r\n");
128+ var it = std.mem.splitScalar(u8, trimmed, '\n');
129+ var body: std.ArrayList([]const u8) = .empty;
130+ while (it.next()) |l| body.append(a, l) catch {};
131+ out.appendSlice(a, diffLines(a, d.path, body.items)) catch {};
132+ } else if (d.note) |note| {
133+ out.append(a, .{ .text = note, .style = .{ .fg = theme.current.comment } }) catch {};
134+ }
135+ }
136+ return out.items;
Cut short: this commit's diff is over 1000 lines.
src/tui/editor.zig+6−6
Cut short: this commit's diff is over 1000 lines.
src/tui/input.zig+265−0
Cut short: this commit's diff is over 1000 lines.
src/tui/render.zig+64−0
Cut short: this commit's diff is over 1000 lines.
src/tui/screen.zig+119−0
Cut short: this commit's diff is over 1000 lines.
src/tui/stream.zig+1−5
Cut short: this commit's diff is over 1000 lines.
src/tui/term.zig+0−264
Cut short: this commit's diff is over 1000 lines.
src/tui/tool_view.zig+92−0
Cut short: this commit's diff is over 1000 lines.
src/tui/tui.zig+58−527
Cut short: this commit's diff is over 1000 lines.
src/tui/usage.zig+65−0
Cut short: this commit's diff is over 1000 lines.
src/util.zig+0−149
Cut short: this commit's diff is over 1000 lines.