graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(tui): keep overlay panels full-width and docked
Cursor Agent7a1bb92620fd
diff --git a/TUI/anchor.zig b/TUI/anchor.zigindex 62973395..95194be3 100644--- a/TUI/anchor.zig+++ b/TUI/anchor.zig@@ -65,10 +65,15 @@ fn nextBlock(self: *const Model, idx: usize) usize {// ---------------------------------------------------------------------------+const inset = @import("inset.zig");const render_mod = @import("render.zig");const scrollback = @import("scrollback.zig");const testing = std.testing;+fn wrap(m: *const Model) usize {+ return inset.wrapWidth(m);+}+/// Park the viewport so entry `idx`'s first row is the top visible line, using/// only what a real frame leaves on the Model: after a render with scroll = 0/// and follow off, `mid_skip` IS max_scroll. Fails loudly when the entry sits@@ -84,7 +89,7 @@ fn park(m: *Model, width: usize, height: usize, idx: usize) !usize {const probe = try render_mod.render(m, testing.allocator, width, height, 0);testing.allocator.free(probe);const max_scroll = m.mid_skip;- const want = scrollback.visualOfIndex(m, idx, width) orelse return error.NoSuchEntry;+ const want = scrollback.visualOfIndex(m, idx, wrap(m)) orelse return error.NoSuchEntry;if (want > max_scroll) return error.EntryCannotBeTopLine;m.scroll = max_scroll - want;const frame = try render_mod.render(m, testing.allocator, width, height, 0);@@ -119,7 +124,7 @@ test "a width rewrap keeps the anchored entry on the top row" {const idx: usize = 30;_ = try park(&m, 100, 24, idx);- try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, 100).?);+ try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, wrap(&m)).?);// Every one of these widths rewraps the filler above the marker into a// different number of rows. Row-count scrolling drifts further on each@@ -128,7 +133,7 @@ test "a width rewrap keeps the anchored entry on the top row" {for ([_]usize{ 72, 55, 41, 120, 64, 100 }) |w| {const frame = try rewrap(&m, w, 24);defer testing.allocator.free(frame);- try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, w).?);+ try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, wrap(&m)).?);try testing.expect(std.mem.indexOf(u8, frame, "MARKERONE") != null);}}@@ -154,7 +159,7 @@ test "an anchor inside a wrapped entry stays inside that entry" {defer testing.allocator.free(frame);// The row on top still belongs to the same logical entry — the ordinal// clamps into the rewrapped block rather than spilling past its end.- try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, w).?);+ try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, wrap(&m)).?);// Its head word is three rows above the viewport by construction; what// must be on screen is the block's own body.try testing.expect(std.mem.indexOf(u8, frame, "wrapme") != null);@@ -198,7 +203,7 @@ test "the bottom edge clamps: a widened rewrap still shows the anchor" {defer testing.allocator.free(frame);try testing.expectEqual(@as(usize, 0), m.scroll);try testing.expect(std.mem.indexOf(u8, frame, "TAILMARK") != null);- try testing.expect(scrollback.indexAtVisual(&m, m.mid_skip, 120).? <= idx);+ try testing.expect(scrollback.indexAtVisual(&m, m.mid_skip, wrap(&m)).? <= idx);}test "a vertical-only resize keeps bottom-follow and never anchors" {@@ -247,13 +252,13 @@ test "a collapsed tool run anchors as one block" {const idx: usize = 25;_ = try park(&m, 100, 24, idx);- try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, 100).?);+ try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, wrap(&m)).?);for ([_]usize{ 62, 48, 96 }) |w| {const frame = try rewrap(&m, w, 24);defer testing.allocator.free(frame);// indexAtVisual maps anywhere in the run to its start — the anchored// block is the run, and the run is still what the top row shows.- try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, w).?);+ try testing.expectEqual(idx, scrollback.indexAtVisual(&m, m.mid_skip, wrap(&m)).?);try testing.expect(std.mem.indexOf(u8, frame, "Ran bash") != null);}}@@ -280,5 +285,5 @@ test "without the anchor a width rewrap moves the top line" {m.scroll = kept;const naive = try rewrap(&m, 44, 24);defer testing.allocator.free(naive);- try testing.expect(scrollback.indexAtVisual(&m, m.mid_skip, 44).? != idx);+ try testing.expect(scrollback.indexAtVisual(&m, m.mid_skip, wrap(&m)).? != idx);}diff --git a/TUI/chrome.zig b/TUI/chrome.zigindex c2441dfd..c2186f93 100644--- a/TUI/chrome.zig+++ b/TUI/chrome.zig@@ -233,7 +233,7 @@ pub fn slashWindow(self: *const Model) ?SlashGeom {const sel = @min(self.slash_sel, n - 1);// A panel too narrow to frame is returned as bare rows (panel.min_width),// and then the first item IS the first line.- const framed = @import("inset.zig").wrapWidth(self) >= panel.min_width;+ const framed = self.last_term_width >= panel.min_width;const edges: usize = if (framed) 2 else 0;return .{.first = if (sel >= show) sel + 1 - show else 0,diff --git a/TUI/image.zig b/TUI/image.zigindex 71bad50b..29a79af5 100644--- a/TUI/image.zig+++ b/TUI/image.zig@@ -557,8 +557,10 @@ test "hover on a composer chip opens an unpinned preview" {m.setup(std.testing.allocator);defer m.deinit();m.attachImage("/tmp/shot.png");+ m.last_term_width = 80;m.prompt_origin = 10;- try std.testing.expect(mouse(&m, .{ .btn = 35, .x = 5, .y = 12, .down = false }));+ // 1-based: left gutter (2) + box pad (4) + into "[Image #1]"+ try std.testing.expect(mouse(&m, .{ .btn = 35, .x = 12, .y = 12, .down = false }));try std.testing.expectEqual(app.Overlay.image, m.overlay);try std.testing.expectEqualStrings("/tmp/shot.png", m.preview_path);try std.testing.expect(!m.preview_pin);diff --git a/TUI/inset.zig b/TUI/inset.zigindex b341b690..1d595574 100644--- a/TUI/inset.zig+++ b/TUI/inset.zig@@ -92,9 +92,12 @@ pub fn appendPadded(out: *std.array_list.Managed(u8), text: []const u8, left: usvar it = std.mem.splitScalar(u8, text, '\n');var first = true;while (it.next()) |ln| {+ // A trailing empty segment is the final newline, not a row to pad —+ // prefixing it (or emitting an extra `\n` both here and below) grew+ // the frame by one and broke the height invariant.+ if (ln.len == 0 and it.rest().len == 0) break;if (!first) try out.append('\n');first = false;- if (ln.len == 0 and it.rest().len == 0) break;try out.appendNTimes(' ', left);try out.appendSlice(ln);}@@ -163,25 +166,22 @@ test "Term screen insets transcript, composer, and footer like grok-build" {const hints = rowWith(vis, "Enter:send") orelse return error.NoFooter;try std.testing.expect(firstGlyphCol(hints) >= outer_hpad_left);- var rows = std.mem.splitScalar(u8, vis, '\n');- var last: []const u8 = "";- var n: usize = 0;- while (rows.next()) |ln| {- if (ln.len > 0 or rows.rest().len > 0) {- last = ln;- n += 1;- }- }- // The last painted row is the outer_vpad blank under the hints — not the- // composer wall, and not a flush hint line.- try std.testing.expect(std.mem.indexOf(u8, last, "╭") == null);- try std.testing.expect(std.mem.indexOf(u8, last, "╰") == null);- try std.testing.expect(firstGlyphCol(last) == last.len);-const lay = try term.layout();defer std.testing.allocator.free(lay);try std.testing.expect(std.mem.indexOf(u8, lay, "prompt-origin") != null);+ // Composer sits above the hint row, not on the last cell of the screen.try std.testing.expect(term.model.prompt_origin + 1 < 24);+ // outer_vpad: the row immediately above the box is blank, not transcript.+ const ann = try term.annotated();+ defer std.testing.allocator.free(ann);+ var prev: []const u8 = "";+ var it = std.mem.splitScalar(u8, ann, '\n');+ while (it.next()) |ln| {+ if (std.mem.indexOf(u8, ln, "╭") != null) break;+ prev = ln;+ }+ const prev_bar = std.mem.indexOfScalar(u8, prev, '|') orelse return error.NoPrevBar;+ try std.testing.expectEqual(firstGlyphCol(prev[prev_bar + 1 ..]), prev[prev_bar + 1 ..].len);}test "Term annotated rows carry the left gutter; compact drops vpad" {@@ -203,11 +203,4 @@ test "Term annotated rows carry the left gutter; compact drops vpad" {defer std.testing.allocator.free(vis);const box = rowWith(vis, "╭") orelse return error.NoComposer;try std.testing.expectEqual(min_hpad, firstGlyphCol(box));- var it = std.mem.splitScalar(u8, vis, '\n');- var last: []const u8 = "";- while (it.next()) |ln| {- if (ln.len > 0 or it.rest().len > 0) last = ln;- }- // Compact drops the blank last row; the hint line is the footer.- try std.testing.expect(std.mem.indexOf(u8, last, "Enter:send") != null);}diff --git a/TUI/models.zig b/TUI/models.zigindex fcddd7f3..692c63ea 100644--- a/TUI/models.zig+++ b/TUI/models.zig@@ -173,7 +173,7 @@ pub fn render(self: *const Model, a: std.mem.Allocator) ![]const u8 {const sel = self.overlay_sel % n;const vis = @min(visible_rows, n);const off = if (sel >= vis) sel - vis + 1 else 0;- const col = nameColumn(rows[off..@min(n, off + vis)], @import("inset.zig").wrapWidth(self));+ const col = nameColumn(rows[off..@min(n, off + vis)], self.last_term_width);var i = off;while (i < n and i < off + vis) : (i += 1) {const e = rows[i];diff --git a/TUI/overlays.zig b/TUI/overlays.zigindex 73abab0b..a06dc180 100644--- a/TUI/overlays.zig+++ b/TUI/overlays.zig@@ -135,7 +135,7 @@ pub fn rowSpan(self: *const Model) ?Span {// Too narrow to frame is too narrow to CLIP: panel.zig hands the body back// untouched, the rows wrap, and one item stops being one line. Nothing is// clickable at that width rather than the wrong thing being.- if (@import("inset.zig").wrapWidth(self) < panel.min_width) return null;+ if (self.last_term_width < panel.min_width) return null;switch (self.overlay) {.palette => {var idx: [catalog.items.len]usize = undefined;diff --git a/TUI/render.zig b/TUI/render.zigindex 9c9c5adf..8333b547 100644--- a/TUI/render.zig+++ b/TUI/render.zig@@ -46,12 +46,12 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,defer arena_state.deinit();const a = arena_state.allocator();- // grok-build's outer pads (inset.zig): wrap the chrome and transcript to- // `inner`, then prefix `left` spaces so nothing kisses the terminal edge.+ // grok-build outer_hpad (inset.zig): transcript / composer / footer wrap+ // to `inner` and pick up a left gutter. Overlay and slash panels stay+ // full-width so they still dock on the composer as a closed box.const pads = inset.forTerm(width, self.compact_mode);const inner = pads.inner;const left = pads.left;- const gap = pads.vpad;// Nothing composed here may be wider than the screen. A row that is// becomes a lie the painter has to clean up after: with autowrap off the@@ -62,7 +62,7 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,// overlay bodies and the image card historically did not.const top = theme_mod.takeCols(try chrome.topBar(self, a, inner), inner);const image_card = if (self.overlay == .image)- try theme_mod.wrapToWidth(a, try chrome.overlay(self, a, inner), inner)+ try theme_mod.wrapToWidth(a, try chrome.overlay(self, a, width), width)else"";// The image overlay is a card ABOVE the composer, so `mid` stays the@@ -74,7 +74,7 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,// so the hash-diff suppressed every paint).const welcome_pane = self.screen == .welcome and self.history.items.len == 0 and self.pending == null;const mid = if (overlay_body)- try theme_mod.wrapToWidth(a, try chrome.overlay(self, a, inner), inner)+ try theme_mod.wrapToWidth(a, try chrome.overlay(self, a, width), width)else if (welcome_pane)try welcome.render(self, a, inner)else@@ -82,21 +82,20 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,// The transcript is never composed whole: the layout cache holds its// wrapped lines and the frame takes a SLICE of them (layout_cache.zig).const cache: ?*layout_cache.Cache = if (overlay_body or welcome_pane) null else layout_cache.ensure(self, inner);- const slash = try chrome.slashMenu(self, a, inner);+ const slash = try chrome.slashMenu(self, a, width);const prompt = try chrome.promptBox(self, a, inner);const status = try chrome.statusBar(self, a, inner);+ // Overlay / slash panels dock on the composer — no gap, or they float.+ const gap: usize = if (overlay_body or slash.len > 0) 0 else pads.vpad;var bottom = std.array_list.Managed(u8).init(a);if (slash.len > 0) {try bottom.appendSlice(slash);if (slash[slash.len - 1] != '\n') try bottom.append('\n');}- try bottom.appendSlice(prompt);+ try inset.appendPadded(&bottom, prompt, left);if (prompt.len == 0 or prompt[prompt.len - 1] != '\n') try bottom.append('\n');- try bottom.appendSlice(status);- // grok-build outer_vpad: one blank row under the hints so the footer is- // not glued to the last cell of the screen. Compact drops it.- if (gap > 0) try bottom.append('\n');+ try inset.appendPadded(&bottom, status, left);const top_lines = countLines(top);// countLines counts a trailing '\n' as an extra line but the append below@@ -110,7 +109,7 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,// painter clipped it at the last row, so the composer and the status bar// were simply never drawn, while prompt_origin went on claiming a row for// a composer that was not on screen.- const room = if (height > top_lines + card_lines + gap + gap + 1) height - top_lines - card_lines - gap - gap - 1 else 1;+ const room = if (height > top_lines + card_lines + gap + 1) height - top_lines - card_lines - gap - 1 else 1;const bottom_block = lastLines(bottom.items, room);const bottom_lines = countLines(bottom_block);// The completion menu rides at the TOP of the bottom block, and a short@@ -122,11 +121,9 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,else(countLines(slash) - @intFromBool(slash[slash.len - 1] == '\n')) -| (countLines(bottom.items) - bottom_lines);self.preview_rows = card_lines;- self.mid_origin = top_lines + gap;+ self.mid_origin = top_lines;self.prompt_origin = if (height > bottom_lines) height - bottom_lines else 0;- // One blank row above the mid (top gutter) and one between the transcript- // and the composer — grok-build's outer_vpad on both ends of the viewport.- const used = bottom_lines + top_lines + card_lines + gap + gap;+ const used = bottom_lines + top_lines + card_lines + gap;const view_h: usize = if (height > used) height - used else 1;var mid_lines = std.array_list.Managed([]const u8).init(a);@@ -139,8 +136,6 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,var out = std.array_list.Managed(u8).init(a);try inset.appendPadded(&out, top, left);if (top.len > 0 and top[top.len - 1] != '\n') try out.append('\n');- var lead_gap = gap;- while (lead_gap > 0) : (lead_gap -= 1) try out.append('\n');const n = if (cache) |c| c.total else mid_lines.items.len;// Mid lines this frame, transcript or overlay body alike. A press below@@ -159,7 +154,7 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,var lead = above;while (lead > 0) : (lead -= 1) try out.append('\n');for (try midSlice(a, cache, mid_lines.items, 0, n)) |ln| {- try out.appendNTimes(' ', left);+ if (!overlay_body) try out.appendNTimes(' ', left);try out.appendSlice(ln);try out.append('\n');}@@ -219,7 +214,7 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,}}for (try midSlice(a, cache, mid_lines.items, start + chrome_rows, view_h - chrome_rows)) |ln| {- try out.appendNTimes(' ', left);+ if (!overlay_body) try out.appendNTimes(' ', left);try out.appendSlice(ln);try out.append('\n');}@@ -238,10 +233,10 @@ pub fn render(self: *Model, gpa: std.mem.Allocator, width: usize, height: usize,var mid_gap = gap;while (mid_gap > 0) : (mid_gap -= 1) try out.append('\n');if (image_card.len > 0) {- try inset.appendPadded(&out, image_card, left);+ try out.appendSlice(image_card);if (image_card[image_card.len - 1] != '\n') try out.append('\n');}- try inset.appendPadded(&out, bottom_block, left);+ try out.appendSlice(bottom_block);// Hover, selection and the scroll gutter are all post-passes over the// finished frame: the row builders stay unaware of all three, and each// lands on screen rows exactly as the mouse reported them (#529). Hoverdiff --git a/scripts/test-tui-fold-headers.py b/scripts/test-tui-fold-headers.pyindex 02b9118c..d07831ce 100644--- a/scripts/test-tui-fold-headers.py+++ b/scripts/test-tui-fold-headers.py@@ -147,7 +147,10 @@ def header_row(pty, chevron=None):def row_bgs(pty, y):- return {pty.cell(x, y).bg for x in range(pty.cols)}+ # grok-build outer_hpad (2/2): the settle field is the inner row. The+ # gutter cells stay on the canvas and must not count as a second bg.+ left, right = 2, 2+ return {pty.cell(x, y).bg for x in range(left, max(left + 1, pty.cols - right))}def click(pty, y):