Skip to content

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

Python

fix(tui): hover is a tint, the chevron already announces the fold

Rach Pradhanbb9e39a16e7a
diff --git a/TUI/hover.zig b/TUI/hover.zig
index 0434c0eb..76f464b0 100644
--- a/TUI/hover.zig
+++ b/TUI/hover.zig
@@ -6,8 +6,9 @@
//! image chip was DROPPED — the TUI knew where the pointer was and said
//! nothing. This is the other half: the row under the pointer is looked up in
//! the same map a click uses, and if it is a target it is painted with a
-//! background one step off the canvas and, when it is a collapsed group, with
-//! its leading mark swapped for the chevron that announces expandability.
+//! background one step off the canvas. The tint is the whole affordance: fold
+//! headers already carry their ›/⌄ disclosure chevron in both states
+//! (foldhdr.zig), so hover changes a row's colour and NEVER its text.
//!
//! ONE HIT TEST. `hitTest` is the single answer to "what is on screen row y",
//! and keys.mouseKey routes its click through the same function. Hover and
@@ -36,7 +37,6 @@
const std = @import("std");
const app = @import("app.zig");
-const glyphs = @import("glyphs.zig");
const key_mod = @import("key.zig");
const layout_cache = @import("layout_cache.zig");
const theme_mod = @import("theme.zig");
@@ -229,24 +229,10 @@ pub fn paint(m: *Model, a: std.mem.Allocator, frame: []const u8, width: usize) !
}
found = true;
try out.appendSlice(bg);
- if (m.hover.hit.collapsed) {
- try out.appendSlice(try swapMark(a, ln));
- } else try out.appendSlice(ln);
+ try out.appendSlice(ln);
}
// The pointer is parked on a row the frame no longer reaches (the transcript
// shrank under it). Nothing to tint, and the stale row must not paint.
if (!found) return frame;
return out.items;
}
-
-/// The affordance swap: a collapsed row's tool mark becomes the chevron, so
-/// "this opens" is said before the click rather than after it. Both glyphs are
-/// registered one-column (glyphs.zig), so nothing beside the mark moves.
-fn swapMark(a: std.mem.Allocator, ln: []const u8) ![]const u8 {
- const at = std.mem.indexOf(u8, ln, glyphs.tool) orelse return ln;
- return std.fmt.allocPrint(a, "{s}{s}{s}", .{
- ln[0..at],
- glyphs.expand,
- ln[at + glyphs.tool.len ..],
- });
-}
diff --git a/TUI/hover_tests.zig b/TUI/hover_tests.zig
index 895284bb..9b2cbf65 100644
--- a/TUI/hover_tests.zig
+++ b/TUI/hover_tests.zig
@@ -106,7 +106,7 @@ test "the hovered row is repainted with the theme's hover background" {
const cold = try render_mod.render(&m, testing.allocator, 80, 24, 0);
defer testing.allocator.free(cold);
try testing.expect(std.mem.indexOf(u8, cold, bg) == null);
- const summary: u16 = @intCast(rowOf(cold, "Called").? + 1);
+ const summary: u16 = @intCast(rowOf(cold, "Ran bash").? + 1);
motion(&m, 4, summary);
const warm = try render_mod.render(&m, testing.allocator, 80, 24, 0);
@@ -126,25 +126,33 @@ test "the hovered row is repainted with the theme's hover background" {
try testing.expectEqualStrings(cold, cooled);
}
-test "a collapsed row under the pointer swaps its tool mark for the chevron" {
+/// Screen row `want` of the composed frame, verbatim.
+fn nthRow(frame: []const u8, want: usize) []const u8 {
+ var r: usize = 0;
+ var it = std.mem.splitScalar(u8, frame, '\n');
+ while (it.next()) |ln| : (r += 1) if (r == want) return ln;
+ return "";
+}
+
+test "hover tints a collapsed row and never edits its text" {
var m: Model = undefined;
try folded(&m);
defer m.deinit();
const cold = try render_mod.render(&m, testing.allocator, 80, 24, 0);
defer testing.allocator.free(cold);
- try testing.expect(std.mem.indexOf(u8, cold, glyphs.tool) != null);
+ const row = rowOf(cold, "Ran bash").?;
+ // Disclosure is not a hover reveal: the closed chevron is already on the
+ // cold header (foldhdr.zig owns it), so hover has nothing to swap.
+ try testing.expect(std.mem.indexOf(u8, nthRow(cold, row), glyphs.expand) != null);
- motion(&m, 4, @intCast(rowOf(cold, "Called").? + 1));
+ motion(&m, 4, @intCast(row + 1));
const warm = try render_mod.render(&m, testing.allocator, 80, 24, 0);
defer testing.allocator.free(warm);
- // The one folded group's mark is gone, replaced by the expand chevron.
- try testing.expect(std.mem.indexOf(u8, warm, glyphs.tool) == null);
- try testing.expect(std.mem.indexOf(u8, warm, glyphs.expand) != null);
- // The swap costs no columns, so nothing beside the mark steps sideways.
- try testing.expectEqual(
- @import("theme.zig").visibleLen(glyphs.tool),
- @import("theme.zig").visibleLen(glyphs.expand),
- );
+ // The tint opens the row; every byte after it is the untouched cold row.
+ const bg = tint.hoverBg(m.theme_id);
+ const warm_row = nthRow(warm, row);
+ try testing.expect(std.mem.startsWith(u8, warm_row, bg));
+ try testing.expectEqualStrings(nthRow(cold, row), warm_row[bg.len..]);
}
test "an expanded row keeps its tool mark under the pointer" {
@@ -283,7 +291,7 @@ test "content arriving under a still pointer clears the hover instead of lying"
defer m.deinit();
const cold = try render_mod.render(&m, testing.allocator, 80, 24, 0);
defer testing.allocator.free(cold);
- motion(&m, 4, @intCast(rowOf(cold, "Called").? + 1));
+ motion(&m, 4, @intCast(rowOf(cold, "Ran bash").? + 1));
try testing.expectEqual(hover.Target.tool, m.hover.hit.target);
// Enough answer to overflow the viewport: following the tail slides the
diff --git a/TUI/root.zig b/TUI/root.zig
index 694e0e53..205af871 100644
--- a/TUI/root.zig
+++ b/TUI/root.zig
@@ -76,7 +76,6 @@ test {
_ = @import("models.zig");
_ = @import("markdown.zig");
_ = @import("markdown_stream_tests.zig");
- _ = @import("table.zig");
_ = @import("syntax.zig");
_ = @import("diff.zig");
_ = @import("dump.zig");
diff --git a/TUI/table.zig b/TUI/table.zig
deleted file mode 100644
index 123fcf31..00000000
--- a/TUI/table.zig
+++ /dev/null
@@ -1,243 +0,0 @@
-//! GitHub-flavoured markdown tables, drawn as a Grok-style box grid.
-//!
-//! Split out of markdown.zig, which the merge of the diff-banding and
-//! stream-markdown work pushed past the 600-line ceiling. The seam is a real
-//! one: everything here is about a GRID — which lines form a table, how wide
-//! each column may be, and how a row is padded — and none of it touches the
-//! inline/fence/heading machinery that surrounds it.
-//!
-//! `inlineSpans` is borrowed back from markdown.zig so a cell renders exactly
-//! the way prose does. That is a module cycle on purpose: the alternative is
-//! measuring markers by hand, which is how the grid used to shear — the render
-//! dropped an unmatched ` or ** and the measure kept it.
-//!
-//! The one hard rule: a table row is ONE visual line. The pager's row↔line map
-//! (clicks, the sticky header, the selection band) is built on that, so an
-//! over-long cell is clamped and ellipsised rather than allowed to wrap.
-
-const std = @import("std");
-
-const markdown = @import("markdown.zig");
-const theme_mod = @import("theme.zig");
-
-pub const max_cols: usize = 8;
-
-/// Widest a single column may grow before the fitting pass starts shaving.
-const cell_ceiling: usize = 36;
-/// Narrowest a column can be shaved to. Below this a cell is all ellipsis.
-const cell_floor: usize = 5;
-
-fn isRow(line: []const u8) bool {
- const t = std.mem.trim(u8, line, " \t");
- if (t.len < 3 or t[0] != '|') return false;
- return std.mem.indexOfScalar(u8, t[1..], '|') != null;
-}
-
-fn isSepRow(line: []const u8) bool {
- if (!isRow(line)) return false;
- var buf: [max_cols][]const u8 = undefined;
- const n = splitCells(line, &buf);
- if (n == 0) return false;
- for (buf[0..n]) |c| {
- if (c.len == 0) return false;
- for (c) |ch| {
- if (ch != '-' and ch != ':' and ch != ' ') return false;
- }
- }
- return true;
-}
-
-/// How many of `lines` form a table starting at line 0, or null for none. A
-/// header and its `---` separator are both required, which is what keeps a
-/// stray pipe-heavy prose line from being drawn as a grid.
-pub fn len(lines: []const []const u8) ?usize {
- if (lines.len < 2 or !isRow(lines[0]) or !isSepRow(lines[1])) return null;
- var n: usize = 2;
- while (n < lines.len and isRow(lines[n]) and !isSepRow(lines[n])) n += 1;
- return n;
-}
-
-fn splitCells(line: []const u8, out: [][]const u8) usize {
- var t = std.mem.trim(u8, line, " \t");
- if (t.len > 0 and t[0] == '|') t = t[1..];
- if (t.len > 0 and t[t.len - 1] == '|') t = t[0 .. t.len - 1];
- var n: usize = 0;
- var it = std.mem.splitScalar(u8, t, '|');
- while (it.next()) |raw| {
- if (n >= out.len) break;
- out[n] = std.mem.trim(u8, raw, " \t");
- n += 1;
- }
- return n;
-}
-
-/// Visible width of a cell AS RENDERED: run it through inlineSpans and count.
-/// Guessing at markers went wrong on every unmatched ` or ** (the render kept
-/// them, the measure dropped them, the pad math sheared the grid).
-fn cellWidth(a: std.mem.Allocator, s: []const u8) usize {
- var scratch = std.array_list.Managed(u8).init(a);
- defer scratch.deinit();
- markdown.inlineSpans(&scratch, s, "", "") catch return s.len;
- return theme_mod.visibleLen(scratch.items);
-}
-
-fn emitRule(out: *std.array_list.Managed(u8), muted: []const u8, widths: []const usize, left: []const u8, mid: []const u8, right: []const u8) !void {
- try out.appendSlice(muted);
- try out.appendSlice(left);
- for (widths, 0..) |w, i| {
- if (i > 0) try out.appendSlice(mid);
- var n: usize = 0;
- while (n < w + 2) : (n += 1) try out.appendSlice("─");
- }
- try out.appendSlice(right);
- try out.appendSlice(theme_mod.reset);
-}
-
-/// Column widths that fit `width` terminal columns. Every row costs
-/// `ncol*3 + 1` border/pad columns on top of its content; the widest column is
-/// shaved until the rest fits. `width == 0` means "no terminal to fit", which
-/// is the tinted (overlay/plain) path.
-fn fit(cols: []usize, width: usize) void {
- const chrome_cost = cols.len * 3 + 1;
- const budget = if (width == 0) 76 else if (width > chrome_cost) width - chrome_cost else cols.len * cell_floor;
- var total: usize = 0;
- for (cols) |w| total += w;
- while (total > budget) {
- var widest: usize = 0;
- for (cols, 0..) |w, ci| {
- if (w > cols[widest]) widest = ci;
- }
- if (cols[widest] <= cell_floor) break;
- cols[widest] -= 1;
- total -= 1;
- }
-}
-
-pub fn emit(
- out: *std.array_list.Managed(u8),
- a: std.mem.Allocator,
- rows: []const []const u8,
- accent: []const u8,
- muted: []const u8,
- text: []const u8,
- width: usize,
-) !void {
- var widths: [max_cols]usize = @splat(0);
- var ncol: usize = 0;
- for (rows, 0..) |row, ri| {
- if (ri == 1) continue; // the separator carries no content
- var cells: [max_cols][]const u8 = undefined;
- const n = splitCells(row, &cells);
- if (n > ncol) ncol = n;
- var c: usize = 0;
- while (c < n) : (c += 1) {
- const w = @min(cellWidth(a, cells[c]), cell_ceiling);
- if (w > widths[c]) widths[c] = w;
- }
- }
- if (ncol == 0) return;
- const cols = widths[0..ncol];
- fit(cols, width);
- try emitRule(out, muted, cols, "┌", "┬", "┐");
- try out.append('\n');
- for (rows, 0..) |row, ri| {
- if (ri == 1) {
- try emitRule(out, muted, cols, "├", "┼", "┤");
- try out.append('\n');
- continue;
- }
- try emitCells(out, a, row, cols, ri == 0, accent, muted, text);
- }
- try emitRule(out, muted, cols, "└", "┴", "┘");
-}
-
-/// One table row: `│ cell │ cell │`, every cell clamped to its column so an
-/// over-long one can never blow the grid onto a second visual line.
-fn emitCells(
- out: *std.array_list.Managed(u8),
- a: std.mem.Allocator,
- row: []const u8,
- cols: []const usize,
- header: bool,
- accent: []const u8,
- muted: []const u8,
- text: []const u8,
-) !void {
- var cells: [max_cols][]const u8 = undefined;
- const n = splitCells(row, &cells);
- var c: usize = 0;
- while (c < cols.len) : (c += 1) {
- try out.appendSlice(muted);
- try out.appendSlice("│");
- try out.appendSlice(theme_mod.reset);
- try out.append(' ');
- const cell = if (c < n) cells[c] else "";
- const want = cols[c];
- var scratch = std.array_list.Managed(u8).init(a);
- defer scratch.deinit();
- if (header) {
- try scratch.appendSlice(theme_mod.bold);
- try scratch.appendSlice(accent);
- try markdown.inlineSpans(&scratch, cell, accent, accent);
- } else {
- try scratch.appendSlice(text);
- try markdown.inlineSpans(&scratch, cell, accent, text);
- }
- const vis = cellWidth(a, cell);
- if (vis > want) {
- try out.appendSlice(theme_mod.takeCols(scratch.items, if (want > 1) want - 1 else want));
- if (want > 1) try out.appendSlice("\u{2026}");
- } else {
- try out.appendSlice(scratch.items);
- var p: usize = 0;
- while (p < want - vis) : (p += 1) try out.append(' ');
- }
- try out.appendSlice(theme_mod.reset);
- try out.append(' ');
- }
- try out.appendSlice(muted);
- try out.appendSlice("│");
- try out.appendSlice(theme_mod.reset);
- try out.append('\n');
-}
-
-// ------------------------------------------------------------------ tests
-
-const testing = std.testing;
-
-test "a table needs a header AND a separator" {
- try testing.expectEqual(@as(?usize, null), len(&.{"| a | b |"}));
- try testing.expectEqual(@as(?usize, null), len(&.{ "| a | b |", "| c | d |" }));
- try testing.expectEqual(@as(?usize, 3), len(&.{ "| a | b |", "|---|---|", "| c | d |" }));
- // Prose that merely contains pipes is not a grid.
- try testing.expectEqual(@as(?usize, null), len(&.{ "use a | b in the shell", "|---|---|" }));
-}
-
-test "the run stops at the first line that is not a row" {
- const lines = [_][]const u8{ "| a |", "|---|", "| c |", "plain prose", "| e |" };
- try testing.expectEqual(@as(?usize, 3), len(&lines));
-}
-
-test "cells split on pipes and lose their padding" {
- var buf: [max_cols][]const u8 = undefined;
- const n = splitCells("| one | two |", &buf);
- try testing.expectEqual(@as(usize, 2), n);
- try testing.expectEqualStrings("one", buf[0]);
- try testing.expectEqualStrings("two", buf[1]);
- // More columns than the ceiling: the extras are dropped, never overrun.
- const wide = "|a|b|c|d|e|f|g|h|i|j|k|";
- try testing.expectEqual(max_cols, splitCells(wide, &buf));
-}
-
-test "fitting shaves the widest column and never past the floor" {
- var cols = [_]usize{ 40, 8, 8 };
- fit(&cols, 40);
- var total: usize = 0;
- for (cols) |w| total += w;
- try testing.expect(total + cols.len * 3 + 1 <= 40);
- try testing.expect(cols[1] == 8 and cols[2] == 8); // only the widest shrank
- // A width no grid can fit still stops at the floor rather than at zero.
- var tight = [_]usize{ 30, 30, 30 };
- fit(&tight, 12);
- for (tight) |w| try testing.expect(w >= cell_floor);
-}
diff --git a/scripts/test-tui-hover.py b/scripts/test-tui-hover.py
index 6609a43f..b11cab95 100644
--- a/scripts/test-tui-hover.py
+++ b/scripts/test-tui-hover.py
@@ -8,10 +8,11 @@ SCREEN (scripts/ptyharness.py) and reads CELLS back — glyph plus the pen that
wrote it — so every assertion is about what a terminal would actually show:
1. a real tool loop against the codex mock (no network, no model) leaves one
- COLLAPSED tool summary row on screen,
+ COLLAPSED fold header on screen (its › disclosure chevron is always
+ there — foldhdr.zig owns it, hover does not reveal it),
2. a motion report over that row repaints it: its cells take the theme's
- hover background, one step off the canvas, and its leading ◆ becomes the
- chevron › that announces the row opens,
+ hover background, one step off the canvas, and its TEXT is untouched —
+ hover changes a row's colour and never its glyphs,
3. the row BELOW it is untouched — hover highlights a row, not a region,
4. moving the pointer away restores the row cell for cell,
5. a SINGLE click still expands the group, exactly as before,
@@ -43,8 +44,10 @@ ANSWER_MAX = 30.0
NOTE_BODY = "hover-probe payload"
FINAL_REPLY = "HOVER_OK the run is done"
-TOOL_MARK = "◆" # ◆ glyphs.tool
-EXPAND_MARK = "›" # › glyphs.expand
+TOOL_MARK = "◆" # ◆ glyphs.tool — the marks on the OPEN card's rows
+EXPAND_MARK = "›" # › glyphs.expand — the closed header's disclosure chevron
+CHEV_OPEN = "⌄" # U+2304 — the open header's chevron (foldhdr.zig)
+HEADER = "Read 1 file" # the settled verb header for this session's one read
STATS = re.compile(r"tui-paint-stats:((?: \w+=\d+)+)")
# TUI/theme_tint.zig: one step per channel, in the direction the canvas's own
@@ -79,9 +82,10 @@ def row_bgs(h, y):
def summary_row(h):
+ """The FOLDED header's row, or None while the group is open (⌄) or gone."""
for i, ln in enumerate(h.screen_lines()):
- if "Called" in ln and "tool" in ln:
- return i
+ if HEADER in ln:
+ return None if CHEV_OPEN in ln else i
return None
@@ -182,8 +186,8 @@ def check_affordance(h):
if y is None:
return f"no folded tool summary on screen\n{h.screen_contents()}"
line = h.screen_lines()[y]
- if TOOL_MARK not in line:
- return f"the folded summary carries no tool mark: {line!r}"
+ if EXPAND_MARK not in line:
+ return f"the folded header carries no disclosure chevron: {line!r}"
base_bgs = row_bgs(h, y)
if len(base_bgs) != 1:
return f"the resting row has {len(base_bgs)} backgrounds, expected the canvas alone: {base_bgs}"
@@ -201,10 +205,8 @@ def check_affordance(h):
if not stepped(base, tint):
return f"the hovered row's background is not one step off the canvas: {base} -> {tint}"
hot_line = h.screen_lines()[y]
- if EXPAND_MARK not in hot_line:
- return f"the hovered collapsed row never announced that it opens: {hot_line!r}"
- if TOOL_MARK in hot_line:
- return f"the tool mark survived the swap: {hot_line!r}"
+ if hot_line != line:
+ return f"hover edited the row's text:\n was {line!r}\n now {hot_line!r}"
# (3) a row is a row: the one under it is untouched, cell for cell.
if [c.tuple() for c in row_cells(h, below)] != below_before:
@@ -377,7 +379,7 @@ def main():
return 1
control, swept = stats
print(
- f" ✓ hover: the row tints and its ◆ becomes › under the pointer, restores on leave, "
+ f" ✓ hover: the row tints under the pointer with its text untouched, restores on leave, "
f"single click expands and a double click is one net toggle; "
f"120 hover reports cost {swept['paints'] - control['paints']} paints "
f"({time.time() - started:.0f}s)"
diff --git a/scripts/test-tui-screenstate.py b/scripts/test-tui-screenstate.py
index 40ee9126..a856978a 100644
--- a/scripts/test-tui-screenstate.py
+++ b/scripts/test-tui-screenstate.py
@@ -20,23 +20,15 @@ OUTSIDE the child and watching whether the TUI paints its way back.
3. repaint-heals positive control: a resize forces graff's full repaint,
and the grid must come back clean. Without this, check 4's
failure could just mean "the harness never updates".
- 4. self-heal XFAIL TODAY. Corrupt the frame, then poke the TUI so it
- paints again, and require screen_contents() to be the
- pre-corruption frame. graff repaints only rows whose
- rendered text CHANGED (TUI/run.zig paint()), so out-of-band
- damage to an unchanged row survives every diff paint. The
- self-heal repaint lives on the sibling branch
- fix/tui-painter; until that merges this check reports
- expected-fail and does not break the build. When it starts
- passing, delete the XFAIL branch below and make it a hard
- assert. The assertion is known to be measuring healing and
- not the harness: swap poke() for a repaint-forcing resize
- and it flips to pass on this very branch (check 3 is that
- control, inline).
+ 4. self-heal HARD ASSERT. Corrupt the frame, then wait on idle only,
+ and require screen_contents() to be the pre-corruption
+ frame. The painter's heal heartbeat (TUI/run.zig, from
+ fix/tui-painter) rewrites every row on a clock, so
+ out-of-band damage must not survive it. Check 3 is the
+ inline control proving the harness itself sees repaints.
Usage: python3 scripts/test-tui-screenstate.py [path/to/graff] (default zig-out/bin/graff)
-Exit 0 = pass (an expected-fail on check 4 is a pass). Skips (exit 0, notice)
-when no pty can be allocated.
+Exit 0 = pass. Skips (exit 0, notice) when no pty can be allocated.
"""
import os
import sys
@@ -195,14 +187,10 @@ def main():
else:
print(f" ✓ corruption: out-of-band {MARK} landed on the grid, a full repaint clears it")
if healed:
- # See the header: flip this to a hard assert once fix/tui-painter
- # is in and delete the XFAIL wording.
- print(" ✓ self-heal: XPASS — the painter repairs out-of-band damage now.")
- print(" fix/tui-painter has landed: make this a hard assert.")
+ print(" ✓ self-heal: the painter repairs out-of-band damage on its own clock")
else:
- print(" ~ self-heal: XFAIL (expected on this branch) — a diff paint leaves")
- print(f" out-of-band damage in place: {detail}")
- print(" The repair lives on fix/tui-painter; the harness proves the damage is visible.")
+ failures.append("self-heal")
+ print(f" ✗ self-heal: a diff paint left out-of-band damage in place: {detail}")
if failures:
print(f"tui-screenstate: {len(failures)} check(s) failed")