Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

fix(tui): steer and /btw queue composer image chips with the text

Cursor Agent9ae6f7840352
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 049185f1..5a94d836 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,9 @@ current is part of cutting a release.
only when the rejected body actually sent `previous_response_id`.
Unparseable Responses envelopes no longer copy raw bytes into
`last_api_error`. Follow-up hardening for `#692` / `#693`.
+- TUI mid-turn steer / `/btw` now bakes composer `[Image #N]` chips into
+ the queued payload as `@[path]`. Previously only the typed text was
+ queued, so the follow-up turn dropped the pixels.
## v0.0.284 (2026-09-01)
diff --git a/TUI/dispatch.zig b/TUI/dispatch.zig
index 49b3452c..ad31d82b 100644
--- a/TUI/dispatch.zig
+++ b/TUI/dispatch.zig
@@ -41,9 +41,7 @@ pub fn applyLine(self: *Model, raw: []const u8) Effect {
self.push(.system, busy_note) catch {};
return .stay;
}
- const prefix = self.takeImagesPrefix(self.alloc);
- const payload = if (prefix.len == 0) line else (std.fmt.allocPrint(self.alloc, "{s}{s}", .{ prefix, line }) catch line);
- if (prefix.len > 0) self.alloc.free(prefix);
+ const payload = withImages(self, line);
self.push(.user, payload) catch {};
if (payload.ptr != line.ptr) self.alloc.free(payload);
if (self.chat) {
@@ -59,6 +57,31 @@ fn rememberPrompt(self: *Model, line: []const u8) void {
@import("prompt_history.zig").remember(self, line);
}
+/// Bake live composer chips onto `line` as `@[path]` markers (same shape
+/// applyLine sends). Clears the chips. Returns `line` when there are none.
+fn withImages(self: *Model, line: []const u8) []const u8 {
+ const prefix = self.takeImagesPrefix(self.alloc);
+ if (prefix.len == 0) return line;
+ defer self.alloc.free(prefix);
+ return std.fmt.allocPrint(self.alloc, "{s}{s}", .{ prefix, line }) catch line;
+}
+
+/// Queue a mid-turn follow-up, including any attached chips. Idle applyLine
+/// already prefixes `@[path]`; steer used to copy only the typed text, so the
+/// pixels never left the composer.
+pub fn queueSteerLine(self: *Model, text: []const u8) void {
+ const line = std.mem.trim(u8, text, " \t\r\n");
+ if (line.len == 0 and self.images.items.len == 0) return;
+ const payload = withImages(self, line);
+ const dup = if (payload.ptr == line.ptr) self.alloc.dupe(u8, line) catch return else payload;
+ self.steer_queue.append(dup) catch {
+ if (dup.ptr != line.ptr) self.alloc.free(dup);
+ return;
+ };
+ self.input.setValue("") catch {};
+ self.pushFmt(.system, "↳ queued ({d} waiting)", .{self.steer_queue.items.len}) catch {};
+}
+
pub fn runCommand(self: *Model, line: []const u8) Effect {
const sp = std.mem.indexOfScalar(u8, line, ' ');
const cmd = if (sp) |i| line[0..i] else line;
@@ -217,10 +240,7 @@ pub fn runCommand(self: *Model, line: []const u8) Effect {
if (arg.len == 0) {
self.push(.system, "usage: /btw <aside> — queue a note without interrupting") catch {};
} else if (self.pending != null) {
- if (self.alloc.dupe(u8, arg)) |dup| {
- self.steer_queue.append(dup) catch self.alloc.free(dup);
- self.pushFmt(.system, "↳ aside queued ({d} waiting)", .{self.steer_queue.items.len}) catch {};
- } else |_| {}
+ queueSteerLine(self, arg);
} else {
return applyLine(self, arg);
}
diff --git a/TUI/dispatch_command_tests.zig b/TUI/dispatch_command_tests.zig
index 96078ed8..3e3bbb4c 100644
--- a/TUI/dispatch_command_tests.zig
+++ b/TUI/dispatch_command_tests.zig
@@ -5,6 +5,7 @@ const std = @import("std");
const app = @import("app.zig");
const dispatch = @import("dispatch.zig");
const engine = @import("engine.zig");
+const turn = @import("turn.zig");
const Effect = app.Effect;
const Model = app.Model;
const applyLine = dispatch.applyLine;
@@ -276,6 +277,56 @@ test "/btw queues an aside while a turn is pending" {
try std.testing.expectEqualStrings("remember the tests", m.steer_queue.items[0]);
}
+test "steer queues @[path] with the text so drain sends pixels" {
+ var m: Model = undefined;
+ m.setup(std.testing.allocator);
+ defer m.deinit();
+ const job = try std.testing.allocator.create(engine.Job);
+ job.* = .{ .gpa = std.testing.allocator, .history = &.{}, .params = .{}, .stream = .{}, .threaded = false };
+ m.pending = job;
+ defer {
+ m.pending = null;
+ std.testing.allocator.destroy(job);
+ }
+ m.attachImage("/tmp/shot.png");
+ try m.input.setValue("look at this");
+ turn.steerEnter(&m);
+ try std.testing.expectEqual(@as(usize, 1), m.steer_queue.items.len);
+ try std.testing.expect(std.mem.indexOf(u8, m.steer_queue.items[0], "@[/tmp/shot.png]") != null);
+ try std.testing.expect(std.mem.indexOf(u8, m.steer_queue.items[0], "look at this") != null);
+ try std.testing.expectEqual(@as(usize, 0), m.images.items.len);
+ try std.testing.expectEqualStrings("", m.input.getValue());
+
+ m.pending = null;
+ _ = turn.drainSteer(&m);
+ var user_text: []const u8 = "";
+ for (m.history.items) |e| {
+ if (e.kind == .user) user_text = e.text;
+ }
+ try std.testing.expect(std.mem.indexOf(u8, user_text, "@[/tmp/shot.png]") != null);
+ try std.testing.expect(std.mem.indexOf(u8, user_text, "look at this") != null);
+ try std.testing.expectEqual(@as(usize, 0), m.steer_queue.items.len);
+}
+
+test "image-only steer queues the chip, empty Enter does not cancel" {
+ var m: Model = undefined;
+ m.setup(std.testing.allocator);
+ defer m.deinit();
+ const job = try std.testing.allocator.create(engine.Job);
+ job.* = .{ .gpa = std.testing.allocator, .history = &.{}, .params = .{}, .stream = .{}, .threaded = false };
+ m.pending = job;
+ defer {
+ m.pending = null;
+ std.testing.allocator.destroy(job);
+ }
+ m.attachImage("/tmp/only.png");
+ turn.steerEnter(&m);
+ try std.testing.expectEqual(@as(usize, 1), m.steer_queue.items.len);
+ try std.testing.expect(std.mem.indexOf(u8, m.steer_queue.items[0], "@[/tmp/only.png]") != null);
+ try std.testing.expect(!m.cancel_requested);
+ try std.testing.expectEqual(@as(usize, 0), m.images.items.len);
+}
+
var captured_op: engine.GoalOp = .none;
var captured_goal: []const u8 = "";
var publish_count: u32 = 0;
diff --git a/TUI/turn.zig b/TUI/turn.zig
index 5298af63..4bf1d788 100644
--- a/TUI/turn.zig
+++ b/TUI/turn.zig
@@ -146,12 +146,8 @@ pub fn drainSteer(self: *Model) Effect {
pub fn steerEnter(self: *Model) void {
const v = std.mem.trim(u8, self.input.getValue(), " \t\r\n");
- if (v.len > 0) {
- if (self.alloc.dupe(u8, v)) |dup| {
- self.steer_queue.append(dup) catch self.alloc.free(dup);
- self.input.setValue("") catch {};
- self.pushFmt(.system, "↳ queued ({d} waiting)", .{self.steer_queue.items.len}) catch {};
- } else |_| {}
+ if (v.len > 0 or self.images.items.len > 0) {
+ @import("dispatch.zig").queueSteerLine(self, v);
} else if (self.steer_queue.items.len > 0) {
cancelTurn(self);
self.push(.system, "↳ force › interrupting…") catch {};
diff --git a/docs/releases/v0.0.285.md b/docs/releases/v0.0.285.md
index 460b7c53..b1eb4ce3 100644
--- a/docs/releases/v0.0.285.md
+++ b/docs/releases/v0.0.285.md
@@ -31,6 +31,15 @@ request that actually used the chain rebuilds.
`agent.zig` stays at the 600-line ceiling: the new field replaces a
tightened scratch-arena comment.
+## TUI steer carries image chips
+
+A follow-up typed while a turn is running (`Enter` to queue, or `/btw`)
+copied only `input.getValue()`. Composer chips live on `Model.images`,
+not in that string, so the queued line was text-only and the next turn
+never staged `@[path]` pixels. Queueing now prefixes the same `@[path]`
+markers a normal send uses, clears the chips, and an image-only Enter
+queues the chip instead of treating empty text as “force interrupt”.
+
## Tests
This fold adds `shouldReanchorRequest requires a rejected
diff --git a/src/cli.zig b/src/cli.zig
index 83c73305..07e9be3b 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -24,6 +24,7 @@ pub const changelog_text =
\\0.0.285
\\ • Codex WS type:error retires the socket immediately; last_api_error stays bounded (#717)
\\ • chain re-anchor only when the rejected body sent previous_response_id
+ \\ • TUI steer / /btw queues composer image chips with the text, not text alone
\\
\\0.0.284
\\ • ACP turns stage GUI @[image] attachments as native vision blocks — pasted images reach the model