xonecas.io
79113
Ma

mini-coding-agent / commit da12484

feat(status reporting): support OSC 7501

xonecas2026-10-09 da12484068112b4bd93e7d98fbf30a857d56dbf8 parent 8bb729e

4 files changed

src/api/openai_completions.zig+5−1
@@ -87,6 +87,10 @@ fn imageParts(a: std.mem.Allocator, run: []const types.Message) ![]const Part {
8787
8888 fn buildMessages(a: std.mem.Allocator, req: api.Request) ![]const Message {
8989 var out: std.ArrayList(Message) = .empty;
90+ // Some upstreams reject a thinking-mode request whose assistant messages omit
91+ // reasoning_content, even when the turn produced none, so the field is always
92+ // sent (empty) while reasoning is on.
93+ const reasoning_on = req.effort.len > 0 and !std.mem.eql(u8, req.effort, "off");
9094 if (req.system_prompt.len > 0) {
9195 try out.append(a, .{ .system = .{ .content = req.system_prompt } });
9296 }
@@ -117,7 +121,7 @@ fn buildMessages(a: std.mem.Allocator, req: api.Request) ![]const Message {
117121 }
118122 try out.append(a, .{ .assistant = .{
119123 .content = try types.assistantText(a, am),
120- .reasoning_content = if (thinking.items.len > 0) thinking.items else null,
124+ .reasoning_content = if (thinking.items.len > 0 or reasoning_on) thinking.items else null,
121125 .tool_calls = if (calls.items.len > 0) calls.items else null,
122126 } });
123127 },
src/config.zig+4−0
@@ -44,6 +44,7 @@ pub const Config = struct {
4444 model: ?[]const u8,
4545 thinking_effort: ?[]const u8,
4646 theme: []const u8,
47+ program_status: bool,
4748 custom_providers: []const CustomProvider,
4849 snapshot_ignore_dirs: []const []const u8,
4950 snapshot_uses_gitignore: bool,
@@ -60,6 +61,7 @@ const File = struct {
6061 thinkingEffort: ?[]const u8 = null,
6162 customProviders: ?[]const CustomProvider = null,
6263 theme: ?[]const u8 = null,
64+ programStatus: ?bool = null,
6365 snapshotIgnoreDirs: ?[]const []const u8 = null,
6466 snapshotUsesGitignore: ?bool = null,
6567 };
@@ -120,6 +122,7 @@ fn readInto(a: std.mem.Allocator, path: []const u8, required: bool, cfg: *Config
120122 if (file.customProviders) |v| cfg.custom_providers = v;
121123 if (file.thinkingEffort) |v| cfg.thinking_effort = v;
122124 if (file.theme) |v| cfg.theme = v;
125+ if (file.programStatus) |v| cfg.program_status = v;
123126 if (file.snapshotIgnoreDirs) |v| cfg.snapshot_ignore_dirs = v;
124127 if (file.snapshotUsesGitignore) |v| cfg.snapshot_uses_gitignore = v;
125128 }
@@ -168,6 +171,7 @@ fn defaults(a: std.mem.Allocator) !Config {
168171 .model = null,
169172 .thinking_effort = null,
170173 .theme = theme.default_id,
174+ .program_status = true,
171175 .custom_providers = &.{},
172176 .snapshot_ignore_dirs = &.{},
173177 .snapshot_uses_gitignore = true,
src/status.zig+29−0
@@ -0,0 +1,29 @@
1+const std = @import("std");
2+const platform = @import("platform.zig");
3+
4+/// OSC 7501, the Program Status Protocol. The program reports what it is doing
5+/// so any consumer of the pty can react; well-behaved terminals ignore the
6+/// unknown sequence. See https://mitchellh.com/writing/program-status-osc7501
7+const app = "mini-coding-agent";
8+const max_msg = 256;
9+
10+pub fn report(state: []const u8, kind: ?[]const u8, msg: ?[]const u8) void {
11+ var buf: [1024]u8 = undefined;
12+ const head = "\x1b]7501;";
13+ @memcpy(buf[0..head.len], head);
14+ var len: usize = head.len;
15+
16+ len += (std.fmt.bufPrint(buf[len..], "state={s}:app={s}", .{ state, app }) catch return).len;
17+ if (kind) |k| len += (std.fmt.bufPrint(buf[len..], ":kind={s}", .{k}) catch return).len;
18+ if (msg) |m| {
19+ const clipped = m[0..@min(m.len, max_msg)];
20+ var encoded: [std.base64.standard.Encoder.calcSize(max_msg)]u8 = undefined;
21+ const b64 = std.base64.standard.Encoder.encode(&encoded, clipped);
22+ len += (std.fmt.bufPrint(buf[len..], ":msg={s}", .{b64}) catch return).len;
23+ }
24+ buf[len] = 0x1b;
25+ buf[len + 1] = '\\';
26+ len += 2;
27+
28+ platform.writeOut(buf[0..len]);
29+}
src/tui/tui.zig+32−7
@@ -20,6 +20,7 @@ const usage_mod = @import("usage.zig");
2020 const diff_view = @import("diff_view.zig");
2121 const tool_view = @import("tool_view.zig");
2222 const screen = @import("screen.zig");
23+const status = @import("../status.zig");
2324
2425 const SPINNER = "⠀⠁⠂⠃⠄⠅⠆⠇⡀⡁⡂⡃⡄⡅⡆⡇⠈⠉⠊⠋⠌⠍⠎⠏⡈⡉⡊⡋⡌⡍⡎⡏⠐⠑⠒⠓⠔⠕⠖⠗⡐⡑⡒⡓⡔⡕⡖⡗⠘⠙⠚⠛⠜⠝⠞⠟⡘⡙⡚⡛⡜⡝⡞⡟⠠⠡⠢⠣⠤⠥⠦⠧⡠⡡⡢⡣⡤⡥⡦⡧⠨⠩⠪⠫⠬⠭⠮⠯⡨⡩⡪⡫⡬⡭⡮⡯⠰⠱⠲⠳⠴⠵⠶⠷⡰⡱⡲⡳⡴⡵⡶⡷⠸⠹⠺⠻⠼⠽⠾⠿⡸⡹⡺⡻⡼⡽⡾⡿⢀⢁⢂⢃⢄⢅⢆⢇⣀⣁⣂⣃⣄⣅⣆⣇⢈⢉⢊⢋⢌⢍⢎⢏⣈⣉⣊⣋⣌⣍⣎⣏⢐ …
2526 const SPINNER_MS = 120;
@@ -295,13 +296,13 @@ const Tui = struct {
295296 self.resetScratch();
296297 const width = @max(self.term.width(), 1);
297298 const height = @max(self.term.height() - 1, 1);
298- const status = self.statusLine();
299- const status_rows = physicalRows(status, width);
299+ const status_line = self.statusLine();
300+ const status_rows = physicalRows(status_line, width);
300301 const editor_budget = height -| status_rows;
301302 const ed = self.editor.layout(width, @max(editor_budget, 1));
302303
303304 var lines: std.ArrayList([]const u8) = .empty;
304- lines.append(self.s, status) catch {};
305+ lines.append(self.s, status_line) catch {};
305306 const caret_line = lines.items.len + ed.cursor_row;
306307 for (ed.rows) |r| lines.append(self.s, r) catch {};
307308
@@ -331,6 +332,11 @@ const Tui = struct {
331332 self.text_bytes = 0;
332333 self.reasoning_bytes = 0;
333334 }
335+ self.reportStatus(switch (p.phase) {
336+ .preparing, .waiting_model, .streaming, .snapshotting, .running_tool => "working",
337+ .pausing => "blocked",
338+ .idle => "idle",
339+ }, if (p.phase == .pausing) "question" else null, if (p.phase == .pausing) "paused - type steering to continue" else null);
334340 },
335341 .text => |delta| {
336342 self.stream_kind = .text;
@@ -365,14 +371,31 @@ const Tui = struct {
365371 .tool_output => {},
366372 .message => |am| self.commitMessage(am),
367373 .tool_result => |tr| self.commitToolResult(tr.name, tr.text, tr.is_error, tr.diffs, tr.body),
368- .err => |m| self.endTurn(styles.red(self.s, std.fmt.allocPrint(self.s, "! {s}", .{m}) catch "! error")),
369- .no_model => self.endTurn(styles.red(self.s, "! no model configured")),
370- .cancelled => self.endTurn(styles.red(self.s, "! cancelled")),
371- .complete => self.endTurn(styles.dim(self.s, std.fmt.allocPrint(self.s, "[complete · {d}s]", .{@max(0, @divFloor(time.nowMs() - self.turn_start, 1000))}) catch "[complete]")),
374+ .err => |m| {
375+ self.reportStatus("error", null, m);
376+ self.endTurn(styles.red(self.s, std.fmt.allocPrint(self.s, "! {s}", .{m}) catch "! error"));
377+ },
378+ .no_model => {
379+ self.reportStatus("error", null, "no model configured");
380+ self.endTurn(styles.red(self.s, "! no model configured"));
381+ },
382+ .cancelled => {
383+ self.reportStatus("idle", null, null);
384+ self.endTurn(styles.red(self.s, "! cancelled"));
385+ },
386+ .complete => {
387+ self.reportStatus("done", null, null);
388+ self.endTurn(styles.dim(self.s, std.fmt.allocPrint(self.s, "[complete · {d}s]", .{@max(0, @divFloor(time.nowMs() - self.turn_start, 1000))}) catch "[complete]"));
389+ },
372390 }
373391 self.dirty = true;
374392 }
375393
394+ fn reportStatus(self: *Tui, state: []const u8, kind: ?[]const u8, msg: ?[]const u8) void {
395+ if (!self.cfg.program_status) return;
396+ status.report(state, kind, msg);
397+ }
398+
376399 fn endTurn(self: *Tui, line: []const u8) void {
377400 self.phase = .idle;
378401 self.keepName(&self.detail, null);
@@ -446,6 +469,7 @@ const Tui = struct {
446469 self.steering_text = "";
447470 if (!self.aborting) {
448471 self.aborting = true;
472+ self.reportStatus("idle", null, null);
449473 self.endTurn(styles.red(self.s, "! cancelled"));
450474 }
451475 self.dirty = true;
@@ -869,6 +893,7 @@ pub fn run(opts: agent.Options, cfg: *const config.Config, tool_names: []const c
869893 std.posix.sigaction(std.posix.SIG.HUP, &term_act, null);
870894 std.posix.sigaction(std.posix.SIG.QUIT, &term_act, null);
871895
896+ self.reportStatus("idle", null, null);
872897 self.pushBanner();
873898 self.draw();