Skip to content

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

Python

fix(tui): verify the hovered row every frame instead of trusting it

Rach Pradhan69a5aacc50d6
diff --git a/TUI/hover.zig b/TUI/hover.zig
index 3651149b..0434c0eb 100644
--- a/TUI/hover.zig
+++ b/TUI/hover.zig
@@ -204,6 +204,18 @@ pub fn paint(m: *Model, a: std.mem.Allocator, frame: []const u8, width: usize) !
_ = width;
const row = m.hover.row orelse return frame;
if (m.hover.hit.target == .none) return frame;
+ // Re-ask, every frame. An explicit scroll drops the hover outright
+ // (`scrolled`), but content can also arrive under a pointer that never
+ // moved — a streaming answer, a tool card opening above. The remembered
+ // hit is then a claim about a row that has changed hands, so it is
+ // verified rather than trusted, and a stale one clears itself instead of
+ // announcing a click that would land somewhere else.
+ const now = hitTest(m, row);
+ if (now.target != m.hover.hit.target or now.idx != m.hover.hit.idx) {
+ clear(m);
+ return frame;
+ }
+ m.hover.hit = now; // the group may have folded or opened under the pointer
const bg = tint.hoverBg(m.theme_id);
var out = std.array_list.Managed(u8).init(a);
var r: usize = 0;
diff --git a/TUI/hover_tests.zig b/TUI/hover_tests.zig
index 1c465539..895284bb 100644
--- a/TUI/hover_tests.zig
+++ b/TUI/hover_tests.zig
@@ -274,6 +274,47 @@ test "a double click on the sticky pin scrolls its prompt back onto the screen"
try testing.expect(m.mid_skip < after_single);
}
+test "content arriving under a still pointer clears the hover instead of lying" {
+ // The pointer never moves; the transcript grows under it. The remembered
+ // row now names a different entry, so an unverified highlight would be
+ // announcing a click that lands somewhere else entirely.
+ 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);
+ motion(&m, 4, @intCast(rowOf(cold, "Called").? + 1));
+ try testing.expectEqual(hover.Target.tool, m.hover.hit.target);
+
+ // Enough answer to overflow the viewport: following the tail slides the
+ // group off the row the pointer is parked on, without the pointer moving.
+ var i: usize = 0;
+ while (i < 40) : (i += 1) try m.push(.assistant, "a streamed answer line");
+ const moved = try render_mod.render(&m, testing.allocator, 80, 24, 0);
+ defer testing.allocator.free(moved);
+ try testing.expectEqual(@as(?usize, null), m.hover.row);
+ try testing.expect(std.mem.indexOf(u8, moved, tint.hoverBg(m.theme_id)) == null);
+}
+
+test "a group that folds under the pointer starts announcing that it opens" {
+ var m: Model = undefined;
+ try folded(&m);
+ defer m.deinit();
+ m.toggleToolGroup(1); // open it first
+ const open = try render_mod.render(&m, testing.allocator, 80, 24, 0);
+ defer testing.allocator.free(open);
+ motion(&m, 4, @intCast(rowOf(open, "bash").? + 1));
+ try testing.expect(!m.hover.hit.collapsed);
+
+ // Folded by the keyboard, with the pointer still parked on the row: the
+ // mark has to start announcing the expansion without a new motion report.
+ m.toggleToolGroup(1);
+ const shut = try render_mod.render(&m, testing.allocator, 80, 24, 0);
+ defer testing.allocator.free(shut);
+ try testing.expect(m.hover.hit.collapsed);
+ try testing.expect(std.mem.indexOf(u8, shut, glyphs.expand) != null);
+}
+
test "hover clears when the pointer is over an overlay, which has no row targets" {
var m: Model = undefined;
try folded(&m);