xonecas.io
79113
Ma

mini-coding-agent / commit d9b8d01

feat: HTTP hardening, osc 9/bel notifications

xonecas2026-10-26 d9b8d01709f3cda7814d506216fe7c06f81aa4b2 parent dd21933

10 files changed

README.md+16−3
@@ -8,9 +8,10 @@ Requires Zig 0.17.0.
88
99 zig build
1010
11-The binary lands at `zig-out/bin/mini`. `zig build run -- <args>` builds and
12-runs it. Provider model metadata is embedded from `src/models_dev.json`; refresh
13-it with `python3 tools/gen_models_dev.py`.
11+A plain `zig build` is a release build, optimized for size. `-Doptimize=debug`
12+builds for development. The binary lands at `zig-out/bin/mini`. `zig build run
13+-- <args>` builds and runs it. Provider model metadata is embedded from
14+`src/models_dev.json`; refresh it with `python3 tools/gen_models_dev.py`.
1415
1516 ## Run
1617
@@ -34,6 +35,10 @@ tool output go to stderr, the assistant text to stdout; a failed turn exits 1.
3435 `SIGINT` and `SIGTERM` cancel the turn and then re-raise, so the exit status is
3536 the signal.
3637
38+A request that fails before any event reached the context is retried with an
39+exponential backoff. Every retry prints a `[retry]` line to stderr, and the TUI
40+shows it in the status line.
41+
3742 ## TUI commands
3843
3944 | Command | Meaning |
@@ -113,6 +118,10 @@ A full example:
113118 "tools": ["edit", "read", "bash"],
114119 "programStatus": false,
115120 "herdr": false,
121+ "notifications": "off",
122+ "retries": 3,
123+ "retryBaseMs": 1000,
124+ "streamIdleTimeoutMs": 120000,
116125 "snapshotIgnoreDirs": [".git"],
117126 "snapshotUsesGitignore": true,
118127 "snapshotDiffsInContext": false,
@@ -160,6 +169,10 @@ Keys:
160169 | `customProviders` | `[]` | in-tree provider definitions |
161170 | `programStatus` | `false` | report agent state to the terminal with OSC 7501 |
162171 | `herdr` | `false` | report agent state to a Herdr pane; only active inside one (`HERDR_ENV=1` with `HERDR_BIN_PATH` and `HERDR_PANE_ID`) |
172+| `notifications` | `off` | how the TUI asks for attention when a turn completes, fails, or pauses for steering: `off`, `osc9` (desktop notification), `bell`, or `both` |
173+| `retries` | `3` | retries after a failed request, when nothing has been streamed yet; transport failures, `429`, and `5xx` retry, other statuses do not |
174+| `retryBaseMs` | `1000` | first backoff step; each retry doubles it, capped at 30s |
175+| `streamIdleTimeoutMs` | `120000` | a stream that stays silent this long is dropped and retried; `0` disables the window |
163176 | `snapshotIgnoreDirs` | `[]` | directory names skipped when the `bash` tool snapshots the cwd for diffs |
164177 | `snapshotUsesGitignore` | `true` | also skip paths matched by the `.gitignore` files under the cwd when snapshotting |
165178 | `snapshotDiffsInContext` | `false` | send the `bash` tool's snapshot diffs to the model inside the tool result |
build.zig+2−1
@@ -3,7 +3,8 @@ const zon = @import("build.zig.zon");
33
44 pub fn build(b: *std.Build) void {
55 const target = b.standardTargetOptions(.{});
6- const optimize = b.standardOptimizeOption(.{});
6+ // A plain `zig build` ships the smallest binary; pass -Doptimize=debug to develop.
7+ const optimize = b.option(std.builtin.OptimizeMode, "optimize", "Optimization mode") orelse .small;
78
89 const exe = b.addExecutable(.{
910 .name = "mini",
src/agent.zig+18−0
@@ -13,6 +13,7 @@ pub const Phase = enum { preparing, waiting_model, streaming, running_tool, snap
1313
1414 pub const Event = union(enum) {
1515 phase: struct { phase: Phase, detail: ?[]const u8 = null },
16+ retry: struct { attempt: u32, total: u32, delay_ms: u64, reason: []const u8 },
1617 text: []const u8,
1718 reasoning: []const u8,
1819 tool_call_start: []const u8,
@@ -89,11 +90,23 @@ fn onToolPhase(ctx: *anyopaque, phase: tools.ToolPhase) void {
8990 fn onApiEvent(ctx: *anyopaque, event: api.Event) void {
9091 const stream_ctx: *StreamCtx = @ptrCast(@alignCast(ctx));
9192 const listener = stream_ctx.listener;
93+ // A retry is not output: it leaves the turn where it was, waiting.
94+ if (std.meta.activeTag(event) == .retry) {
95+ const r = event.retry;
96+ listener.emit(.{ .retry = .{
97+ .attempt = r.attempt,
98+ .total = r.total,
99+ .delay_ms = r.delay_ms,
100+ .reason = r.reason,
101+ } });
102+ return;
103+ }
92104 if (!stream_ctx.started) {
93105 stream_ctx.started = true;
94106 listener.emit(.{ .phase = .{ .phase = .streaming } });
95107 }
96108 switch (event) {
109+ .retry => unreachable,
97110 .text => |d| listener.emit(.{ .text = d }),
98111 .reasoning => |d| listener.emit(.{ .reasoning = d }),
99112 .tool_start => |name| listener.emit(.{ .tool_call_start = name }),
@@ -201,6 +214,11 @@ pub fn runTurn(opts: Options, messages: *std.ArrayList(message_mod.Message), int
201214 .effort = model.effort,
202215 .session_id = opts.session.id,
203216 .cancel = opts.cancel,
217+ .retry = .{
218+ .attempts = opts.config.retries,
219+ .base_ms = opts.config.retry_base_ms,
220+ .idle_ms = opts.config.stream_idle_timeout_ms,
221+ },
204222 }, .{ .ctx = &stream_ctx, .on_event = onApiEvent }) catch |e| {
205223 listener.emit(.{ .err = @errorName(e) });
206224 return;
src/api.zig+19−3
@@ -5,6 +5,7 @@ const http = @import("http.zig");
55 const time = @import("time.zig");
66
77 pub const Event = union(enum) {
8+ retry: struct { attempt: u32, total: u32, delay_ms: u64, reason: []const u8 },
89 text: []const u8,
910 reasoning: []const u8,
1011 tool_start: []const u8,
@@ -63,6 +64,7 @@ pub const Request = struct {
6364 effort: []const u8,
6465 session_id: ?[]const u8,
6566 cancel: *const std.atomic.Value(bool),
67+ retry: http.Retry = .{},
6668 };
6769
6870 pub const max_stream_index = 10_000;
@@ -98,7 +100,7 @@ pub fn run(
98100
99101 var st = State{ .req = req, .sink = sink, .arena = &arena, .msg = &msg };
100102
101- const complete = try post(req, url, hdrs, body, .{ .ctx = &st, .onEvent = onData(State, Chunk) }, &msg);
103+ const complete = try post(req, url, hdrs, body, .{ .ctx = &st, .onEvent = onData(State, Chunk) }, sink, &msg);
102104 st.failed = !complete;
103105 const reason = msg.stop_reason;
104106 const message = msg.error_message;
@@ -197,9 +199,22 @@ fn wireHeaders(a: std.mem.Allocator, req: Request, wire: Wire) ![]http.Header {
197199 return list.toOwnedSlice(a);
198200 }
199201
200-fn post(req: Request, url: []const u8, hdrs: []const http.Header, body: []const u8, handler: http.SseHandler, msg: *message_mod.AssistantMessage) std.mem.Allocator.Error!bool {
202+const RetryCtx = struct { sink: Sink };
203+
204+fn onRetry(ctx: *anyopaque, attempt: usize, total: usize, delay_ms: u64, reason: []const u8) void {
205+ const rc: *RetryCtx = @ptrCast(@alignCast(ctx));
206+ rc.sink.emit(.{ .retry = .{
207+ .attempt = @intCast(attempt),
208+ .total = @intCast(total),
209+ .delay_ms = delay_ms,
210+ .reason = reason,
211+ } });
212+}
213+
214+fn post(req: Request, url: []const u8, hdrs: []const http.Header, body: []const u8, handler: http.SseHandler, sink: Sink, msg: *message_mod.AssistantMessage) std.mem.Allocator.Error!bool {
201215 var err_body: ?[]const u8 = null;
202- http.postSse(req.scratch, url, hdrs, body, handler, req.cancel, &err_body) catch |e| {
216+ var notice_ctx = RetryCtx{ .sink = sink };
217+ http.postSse(req.scratch, url, hdrs, body, handler, req.cancel, &err_body, req.retry, .{ .ctx = &notice_ctx, .on_retry = onRetry }) catch |e| {
203218 if (e == error.OutOfMemory) return error.OutOfMemory;
204219 if (e == error.Aborted or req.cancel.load(.acquire)) {
205220 msg.stop_reason = .aborted;
@@ -208,6 +223,7 @@ fn post(req: Request, url: []const u8, hdrs: []const http.Header, body: []const
208223 const message = switch (e) {
209224 error.HttpStatus => err_body orelse "provider returned an error status",
210225 error.ReadFailed => "stream read failed",
226+ error.IdleTimeout => "provider went silent",
211227 else => "request failed",
212228 };
213229 msg.error_message = try req.pers.dupe(u8, message);
src/config.zig+19−0
@@ -4,6 +4,9 @@ const filesystem = @import("filesystem.zig");
44
55 pub const ToolName = enum { edit, read, bash };
66
7+/// How mini draws the user's attention when a turn needs them.
8+pub const Notifications = enum { off, osc9, bell, both };
9+
710 pub const Api = enum {
811 @"openai-completions",
912 @"openai-responses",
@@ -71,6 +74,10 @@ pub const Config = struct {
7174 thinking_effort: ?[]const u8,
7275 program_status: bool,
7376 herdr: bool,
77+ notifications: Notifications,
78+ retries: usize,
79+ retry_base_ms: u64,
80+ stream_idle_timeout_ms: u64,
7481 show_images: bool,
7582 custom_providers: []const CustomProvider,
7683 snapshot_ignore_dirs: []const []const u8,
@@ -95,6 +102,10 @@ const File = struct {
95102 customProviders: ?[]const CustomProvider = null,
96103 programStatus: ?bool = null,
97104 herdr: ?bool = null,
105+ notifications: ?Notifications = null,
106+ retries: ?usize = null,
107+ retryBaseMs: ?u64 = null,
108+ streamIdleTimeoutMs: ?u64 = null,
98109 showImages: ?bool = null,
99110 snapshotIgnoreDirs: ?[]const []const u8 = null,
100111 snapshotUsesGitignore: ?bool = null,
@@ -175,6 +186,10 @@ fn readInto(a: std.mem.Allocator, path: []const u8, required: bool, cfg: *Config
175186 if (file.thinkingEffort) |v| cfg.thinking_effort = v;
176187 if (file.programStatus) |v| cfg.program_status = v;
177188 if (file.herdr) |v| cfg.herdr = v;
189+ if (file.notifications) |v| cfg.notifications = v;
190+ if (file.retries) |v| cfg.retries = v;
191+ if (file.retryBaseMs) |v| cfg.retry_base_ms = v;
192+ if (file.streamIdleTimeoutMs) |v| cfg.stream_idle_timeout_ms = v;
178193 if (file.showImages) |v| cfg.show_images = v;
179194 if (file.snapshotIgnoreDirs) |v| cfg.snapshot_ignore_dirs = v;
180195 if (file.snapshotUsesGitignore) |v| cfg.snapshot_uses_gitignore = v;
@@ -239,6 +254,10 @@ fn defaults(a: std.mem.Allocator) !Config {
239254 .thinking_effort = null,
240255 .program_status = false,
241256 .herdr = false,
257+ .notifications = .off,
258+ .retries = 3,
259+ .retry_base_ms = 1000,
260+ .stream_idle_timeout_ms = 120_000,
242261 .show_images = false,
243262 .custom_providers = &.{},
244263 .snapshot_ignore_dirs = &.{},
src/headless.zig+1−0
@@ -18,6 +18,7 @@ const PrintCtx = struct { failed: bool = false };
1818 fn printEvent(ctx: *anyopaque, event: agent.Event) void {
1919 const pc: *PrintCtx = @ptrCast(@alignCast(ctx));
2020 switch (event) {
21+ .retry => |r| platform.printErr("[retry] {s}: attempt {d}/{d} in {d}ms\n", .{ r.reason, r.attempt, r.total, r.delay_ms }),
2122 .tool_call => |call| platform.printErr("[tool] {s}\n", .{call.name}),
2223 .tool_output => |chunk| platform.writeErr(chunk),
2324 .no_model => {
src/http.zig+192−20
@@ -1,5 +1,6 @@
11 const std = @import("std");
22 const platform = @import("platform.zig");
3+const time = @import("time.zig");
34 const build_options = @import("build_options");
45
56 const user_agent = "mini-coding-agent/" ++ build_options.version;
@@ -19,25 +20,61 @@ const HttpError = error{
1920 RequestFailed,
2021 HttpStatus,
2122 ReadFailed,
23+ IdleTimeout,
2224 Aborted,
2325 } || std.mem.Allocator.Error;
2426
25-// Blocking socket reads cannot observe the cancel token, so a watcher thread
26-// shuts the connection down when a cancel is requested, unblocking the read.
27-const CancelWatch = struct {
27+/// How a request fails over: the retries after the first attempt, the first
28+/// backoff step (each retry doubles it), and how long a stream may stay silent
29+/// before the connection is treated as dead.
30+pub const Retry = struct {
31+ attempts: usize = 3,
32+ base_ms: u64 = 1000,
33+ idle_ms: u64 = 120_000,
34+};
35+
36+const max_backoff_ms: u64 = 30_000;
37+
38+/// Told about every retry before it happens, so both front ends can say why the
39+/// request is being repeated.
40+pub const RetryNotice = struct {
41+ ctx: *anyopaque,
42+ on_retry: *const fn (ctx: *anyopaque, attempt: usize, total: usize, delay_ms: u64, reason: []const u8) void,
43+
44+ fn call(self: RetryNotice, attempt: usize, total: usize, delay_ms: u64, reason: []const u8) void {
45+ self.on_retry(self.ctx, attempt, total, delay_ms, reason);
46+ }
47+};
48+
49+/// Blocking socket reads cannot observe the cancel token or the idle window, so
50+/// a watcher thread shuts the connection down when either is spent, unblocking
51+/// the read that cannot see them.
52+const Watch = struct {
2853 cancel: *const std.atomic.Value(bool),
2954 connection: *std.http.Client.Connection,
55+ idle_ms: u64,
56+ last: std.atomic.Value(i64),
57+ idle: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
3058 done: std.atomic.Value(bool) = std.atomic.Value(bool).init(false),
3159
32- fn run(self: *CancelWatch) void {
60+ fn run(self: *Watch) void {
3361 while (!self.done.load(.acquire)) {
3462 if (self.cancel.load(.acquire)) {
35- self.connection.stream_reader.stream.shutdown(platform.io, .both) catch {};
63+ self.hangUp();
64+ return;
65+ }
66+ if (self.idle_ms > 0 and time.nowMs() - self.last.load(.acquire) >= self.idle_ms) {
67+ self.idle.store(true, .release);
68+ self.hangUp();
3669 return;
3770 }
3871 std.Io.sleep(platform.io, .{ .nanoseconds = 25 * std.time.ns_per_ms }, .boot) catch {};
3972 }
4073 }
74+
75+ fn hangUp(self: *Watch) void {
76+ self.connection.stream_reader.stream.shutdown(platform.io, .both) catch {};
77+ }
4178 };
4279
4380 /// One request and its response, with the buffers the response reader borrows.
@@ -97,17 +134,44 @@ const Exchange = struct {
97134 }
98135 };
99136
137+/// What one attempt achieved: the status it saw, whether the sink already
138+/// received events (a partial stream cannot be repeated), and how it ended.
139+const Attempt = struct {
140+ status: u16 = 0,
141+ sent: bool = false,
142+ err: ?HttpError = null,
143+};
144+
100145 pub fn get(
101146 a: std.mem.Allocator,
102147 url: []const u8,
103148 headers: []const Header,
104149 cancel: *const std.atomic.Value(bool),
150+ retry: Retry,
151+) HttpError![]u8 {
152+ var attempt: usize = 0;
153+ while (true) : (attempt += 1) {
154+ var out = Attempt{};
155+ if (getOnce(a, url, headers, cancel, &out)) |body| return body else |e| out.err = e;
156+ const e = out.err orelse error.ReadFailed;
157+ if (attempt + 1 >= retry.attempts + 1 or !retryable(e, out.status)) return e;
158+ try pause(cancel, backoff(retry.base_ms, attempt));
159+ }
160+}
161+
162+fn getOnce(
163+ a: std.mem.Allocator,
164+ url: []const u8,
165+ headers: []const Header,
166+ cancel: *const std.atomic.Value(bool),
167+ out: *Attempt,
105168 ) HttpError![]u8 {
106169 if (cancel.load(.acquire)) return error.Aborted;
107170 var ex: Exchange = undefined;
108171 try ex.open(a, .GET, url, headers, null);
109172 defer ex.close();
110173 try ex.receive();
174+ out.status = ex.status;
111175 if (!ex.ok()) return error.HttpStatus;
112176 return ex.reader.allocRemaining(a, .limited(1 << 22)) catch return error.ReadFailed;
113177 }
@@ -120,23 +184,62 @@ pub fn postSse(
120184 handler: SseHandler,
121185 cancel: *const std.atomic.Value(bool),
122186 err_body: *?[]const u8,
187+ retry: Retry,
188+ notice: ?RetryNotice,
123189 ) HttpError!void {
124- if (cancel.load(.acquire)) return error.Aborted;
190+ var attempt: usize = 0;
191+ while (true) : (attempt += 1) {
192+ err_body.* = null;
193+ const out = postOnce(a, url, headers, body, handler, cancel, err_body, retry.idle_ms);
194+ const e = out.err orelse return;
195+ if (out.sent or attempt + 1 >= retry.attempts + 1 or !retryable(e, out.status)) return e;
196+ const delay_ms = backoff(retry.base_ms, attempt);
197+ if (notice) |n| {
198+ var buf: [16]u8 = undefined;
199+ n.call(attempt + 2, retry.attempts + 1, delay_ms, describe(e, out.status, &buf));
200+ }
201+ try pause(cancel, delay_ms);
202+ }
203+}
204+
205+fn postOnce(
206+ a: std.mem.Allocator,
207+ url: []const u8,
208+ headers: []const Header,
209+ body: []const u8,
210+ handler: SseHandler,
211+ cancel: *const std.atomic.Value(bool),
212+ err_body: *?[]const u8,
213+ idle_ms: u64,
214+) Attempt {
215+ var out = Attempt{};
216+ if (cancel.load(.acquire)) {
217+ out.err = error.Aborted;
218+ return out;
219+ }
125220 var ex: Exchange = undefined;
126- try ex.open(a, .POST, url, headers, body);
221+ ex.open(a, .POST, url, headers, body) catch |e| {
222+ out.err = e;
223+ return out;
224+ };
127225 defer ex.close();
128226
129- var watch = CancelWatch{ .cancel = cancel, .connection = ex.req.connection.? };
130- const watcher = std.Thread.spawn(.{}, CancelWatch.run, .{&watch}) catch null;
227+ var watch = Watch{ .cancel = cancel, .connection = ex.req.connection.?, .idle_ms = idle_ms, .last = std.atomic.Value(i64).init(time.nowMs()) };
228+ const watcher = std.Thread.spawn(.{}, Watch.run, .{&watch}) catch null;
131229 defer {
132230 watch.done.store(true, .release);
133231 if (watcher) |t| t.join();
134232 }
135233
136- try ex.receive();
234+ ex.receive() catch {
235+ out.err = if (watch.idle.load(.acquire)) error.IdleTimeout else error.RequestFailed;
236+ return out;
237+ };
238+ out.status = ex.status;
137239 if (!ex.ok()) {
138240 err_body.* = ex.reader.allocRemaining(a, .limited(1 << 20)) catch null;
139- return error.HttpStatus;
241+ out.err = error.HttpStatus;
242+ return out;
140243 }
141244
142245 var data: std.ArrayList(u8) = .empty;
@@ -151,28 +254,97 @@ pub fn postSse(
151254 // reader's buffer sends the delimiter search down a failure path that
152255 // desynchronizes chunked transfer decoding.
153256 while (true) {
154- if (cancel.load(.acquire)) return error.Aborted;
155- const n = ex.reader.readSliceShort(&buf) catch return error.ReadFailed;
257+ if (cancel.load(.acquire)) {
258+ out.err = error.Aborted;
259+ return out;
260+ }
261+ const n = ex.reader.readSliceShort(&buf) catch {
262+ out.err = if (watch.idle.load(.acquire)) error.IdleTimeout else error.ReadFailed;
263+ return out;
264+ };
156265 if (n == 0) break;
266+ watch.last.store(time.nowMs(), .release);
157267 var rest: []const u8 = buf[0..n];
158268 while (std.mem.indexOfScalar(u8, rest, '\n')) |nl| {
159- try line.appendSlice(a, rest[0..nl]);
269+ line.appendSlice(a, rest[0..nl]) catch {
270+ out.err = error.OutOfMemory;
271+ return out;
272+ };
160273 rest = rest[nl + 1 ..];
161- if (try feedLine(a, line.items, &data, &have_data)) {
274+ const complete = feedLine(a, line.items, &data, &have_data) catch {
275+ out.err = error.OutOfMemory;
276+ return out;
277+ };
278+ if (complete) {
279+ out.sent = true;
162280 handler.call(data.items);
163281 data.clearRetainingCapacity();
164282 have_data = false;
165283 }
166284 line.clearRetainingCapacity();
167285 }
168- try line.appendSlice(a, rest);
286+ line.appendSlice(a, rest) catch {
287+ out.err = error.OutOfMemory;
288+ return out;
289+ };
290+ }
291+ // The watcher shuts a dead stream down, which can end the read cleanly; the
292+ // flag is what tells a finished stream from a silent one.
293+ if (watch.idle.load(.acquire)) {
294+ out.err = error.IdleTimeout;
295+ return out;
296+ }
297+ if (line.items.len > 0) {
298+ const complete = feedLine(a, line.items, &data, &have_data) catch {
299+ out.err = error.OutOfMemory;
300+ return out;
301+ };
302+ if (complete) {
303+ out.sent = true;
304+ handler.call(data.items);
305+ data.clearRetainingCapacity();
306+ have_data = false;
307+ }
169308 }
170- if (line.items.len > 0 and try feedLine(a, line.items, &data, &have_data)) {
309+ if (have_data) {
310+ out.sent = true;
171311 handler.call(data.items);
172- data.clearRetainingCapacity();
173- have_data = false;
174312 }
175- if (have_data) handler.call(data.items);
313+ return out;
314+}
315+
316+fn retryable(e: HttpError, status: u16) bool {
317+ return switch (e) {
318+ error.RequestFailed, error.ReadFailed, error.IdleTimeout => true,
319+ error.HttpStatus => status == 429 or status >= 500,
320+ error.Aborted, error.OutOfMemory => false,
321+ };
322+}
323+
324+fn backoff(base_ms: u64, attempt: usize) u64 {
325+ const shift: u6 = @intCast(@min(attempt, 6));
326+ return @min(base_ms << shift, max_backoff_ms);
327+}
328+
329+fn describe(e: HttpError, status: u16, buf: []u8) []const u8 {
330+ return switch (e) {
331+ error.HttpStatus => std.fmt.bufPrint(buf, "http {d}", .{status}) catch "http error",
332+ error.IdleTimeout => "idle timeout",
333+ error.ReadFailed => "stream interrupted",
334+ else => "connection failed",
335+ };
336+}
337+
338+/// Waits out the backoff in small steps, so a cancel lands promptly.
339+fn pause(cancel: *const std.atomic.Value(bool), delay_ms: u64) HttpError!void {
340+ var left = delay_ms;
341+ while (left > 0) {
342+ if (cancel.load(.acquire)) return error.Aborted;
343+ const step: u64 = @min(left, 25);
344+ std.Io.sleep(platform.io, .{ .nanoseconds = step * std.time.ns_per_ms }, .boot) catch {};
345+ left -= step;
346+ }
347+ if (cancel.load(.acquire)) return error.Aborted;
176348 }
177349
178350 /// Applies one SSE line to the pending event payload, returning whether the
src/models.zig+1−1
@@ -224,7 +224,7 @@ pub fn listing(
224224
225225 const url = try std.fmt.allocPrint(a, "{s}/models", .{base});
226226 const authorization = try std.fmt.allocPrint(a, "Bearer {s}", .{key});
227- const body = try http.get(a, url, &.{.{ .name = "Authorization", .value = authorization }}, cancel);
227+ const body = try http.get(a, url, &.{.{ .name = "Authorization", .value = authorization }}, cancel, .{});
228228
229229 const parsed = try std.json.parseFromSliceLeaky(Listed, a, body, .{ .ignore_unknown_fields = true });
230230 var out: std.ArrayList(Entry) = .empty;
src/status.zig+14−0
@@ -18,6 +18,7 @@ const herdr_report_timeout_ms = 2000;
1818 const herdr_release_timeout_ms = 1000;
1919
2020 var program_status = false;
21+var notify_mode: config.Notifications = .off;
2122 var herdr_on = false;
2223 var herdr_bin: []const u8 = "";
2324 var herdr_pane: []const u8 = "";
@@ -39,6 +40,7 @@ const Job = struct {
3940 /// inside a Herdr pane; anywhere else it stays off.
4041 pub fn init(cfg: *const config.Config) void {
4142 program_status = cfg.program_status;
43+ notify_mode = cfg.notifications;
4244 if (!cfg.herdr) return;
4345 if (!std.mem.eql(u8, platform.getEnv("HERDR_ENV") orelse "", "1")) return;
4446 herdr_bin = platform.getEnv("HERDR_BIN_PATH") orelse return;
@@ -74,6 +76,18 @@ pub fn report(state: []const u8, kind: ?[]const u8, msg: ?[]const u8) void {
7476 pending = .{ .state = mapped, .msg_len = text.len, .seq = seq };
7577 }
7678
79+/// Asks for the user's attention when a turn stops needing none of it. OSC 9 is
80+/// the desktop notification most terminals forward; the bell is the fallback
81+/// every terminal has.
82+pub fn notify(message: []const u8) void {
83+ if (notify_mode == .osc9 or notify_mode == .both) {
84+ var buf: [max_msg + 8]u8 = undefined;
85+ const out = std.fmt.bufPrint(&buf, "\x1b]9;{s}\x07", .{message[0..@min(message.len, max_msg)]}) catch return;
86+ platform.writeOut(out);
87+ }
88+ if (notify_mode == .bell or notify_mode == .both) platform.writeOut("\x07");
89+}
90+
7791 /// Clears our name, state, and resume command from the pane. Only for an exit,
7892 /// and the report must land before the process goes away.
7993 pub fn release() void {
src/tui/tui.zig+20−0
@@ -85,6 +85,7 @@ const Tui = struct {
8585
8686 phase: agent.Phase = .idle,
8787 detail: ?[]const u8 = null,
88+ retrying: ?[]const u8 = null,
8889 writing_tool: ?[]const u8 = null,
8990 writing_bytes: usize = 0,
9091 stream_kind: enum { none, reasoning, text, tool } = .none,
@@ -261,6 +262,7 @@ const Tui = struct {
261262
262263 fn stateLabel(self: *Tui) []const u8 {
263264 const a = self.s;
265+ if (self.retrying) |text| return styles.styledWith(a, styles.roles.warn, text);
264266 var text: []const u8 = "idle";
265267 var role: ?styles.Style = null;
266268 var bytes: usize = 0;
@@ -385,7 +387,15 @@ const Tui = struct {
385387 if (self.closed) return;
386388 if (self.aborting) return;
387389 self.resetScratch();
390+ if (std.meta.activeTag(event) != .retry) self.keepName(&self.retrying, null);
388391 switch (event) {
392+ .retry => |r| {
393+ const text = std.fmt.allocPrint(self.s, "retrying {d}/{d} in {d}s · {s}", .{
394+ r.attempt, r.total, @divFloor(r.delay_ms + 999, 1000), r.reason,
395+ }) catch "";
396+ self.keepName(&self.retrying, text);
397+ status.report("working", null, r.reason);
398+ },
389399 .phase => |p| {
390400 self.phase = p.phase;
391401 self.keepName(&self.detail, p.detail);
@@ -401,6 +411,7 @@ const Tui = struct {
401411 .pausing => "blocked",
402412 .idle => "idle",
403413 }, if (p.phase == .pausing) "question" else null, if (p.phase == .pausing) "paused - type steering to continue" else null);
414+ if (p.phase == .pausing) status.notify("mini: paused, waiting for steering");
404415 },
405416 .text => |delta| {
406417 self.stream_kind = .text;
@@ -437,6 +448,7 @@ const Tui = struct {
437448 .tool_result => |tr| self.commitToolResult(tr.name, tr.text, tr.is_error, tr.diffs, tr.body, tr.images),
438449 .err => |m| {
439450 status.report("error", null, m);
451+ status.notify("mini: turn failed");
440452 self.retry = true;
441453 self.endTurn(styles.err(self.s, std.fmt.allocPrint(self.s, "! {s}", .{m}) catch "! error"));
442454 },
@@ -450,6 +462,7 @@ const Tui = struct {
450462 },
451463 .complete => {
452464 status.report("done", null, null);
465+ status.notify("mini: turn complete");
453466 self.endTurn(styles.comment(self.s, std.fmt.allocPrint(self.s, "[complete · {d}s]", .{@max(0, @divFloor(time.nowMs() - self.turn_start, 1000))}) catch "[complete]"));
454467 },
455468 }
@@ -725,6 +738,7 @@ const Tui = struct {
725738 self.turn_done.store(false, .seq_cst);
726739 self.phase = .preparing;
727740 self.keepName(&self.detail, null);
741+ self.keepName(&self.retrying, null);
728742 self.turn_start = time.nowMs();
729743 self.frame = 0;
730744 self.event_mutex.lockUncancelable(platform.io);
@@ -1022,6 +1036,12 @@ fn turnThread(self: *Tui) void {
10221036 fn copyEvent(a: std.mem.Allocator, e: agent.Event, with_images: bool) agent.Event {
10231037 return switch (e) {
10241038 .phase => |p| .{ .phase = .{ .phase = p.phase, .detail = if (p.detail) |d| a.dupe(u8, d) catch "" else null } },
1039+ .retry => |r| .{ .retry = .{
1040+ .attempt = r.attempt,
1041+ .total = r.total,
1042+ .delay_ms = r.delay_ms,
1043+ .reason = a.dupe(u8, r.reason) catch "",
1044+ } },
10251045 .text => |s| .{ .text = a.dupe(u8, s) catch "" },
10261046 .reasoning => |s| .{ .reasoning = a.dupe(u8, s) catch "" },
10271047 .tool_call_start => |s| .{ .tool_call_start = a.dupe(u8, s) catch "" },