graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(tui): collapse Thinking on interrupt, Grok ❙ + static label
Rach Pradhan4efde83e1c74
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 37193ddd..c011ff2b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ current is part of cutting a release.turned into Escape/Ctrl+C (which cancelled the turn).- Shift+number keys type the punctuation they should (`Shift+9` is `(`,`Shift+0` is `)`), including via Kitty CSI-u and modifyOtherKeys.+- Interrupting a turn collapses Thinking immediately (Grok ❙ + static+ "Thinking"; no leftover spinner next to ■ interrupted).- The pager appends raw stdin hex to `.graff/tui-traj.jsonl` and the lastvisible frame on exit so the next leak can be replayed.diff --git a/TUI/scrollback.zig b/TUI/scrollback.zigindex 094c3776..c6fa483d 100644--- a/TUI/scrollback.zig+++ b/TUI/scrollback.zig@@ -43,14 +43,16 @@ pub fn render(self: *const Model, a: std.mem.Allocator, width: usize, now_ms: u6i += 1;}if (self.pending) |job| {- if (job.stream.snapshot(a)) |live| {- if (!first) try out.append('\n');- first = false;- try out.appendSlice(try theme_mod.paint(a, self.theme().muted, try tail(a, strip(a, live), width, 4)));- }- if (self.steer_queue.items.len > 0) {- if (!first) try out.append('\n');- try out.appendSlice(try theme_mod.paint(a, self.theme().muted, try std.fmt.allocPrint(a, " ↳ {d} queued · empty Enter sends now", .{self.steer_queue.items.len})));+ if (!self.cancel_requested) {+ if (job.stream.snapshot(a)) |live| {+ if (!first) try out.append('\n');+ first = false;+ try out.appendSlice(try theme_mod.paint(a, self.theme().muted, try tail(a, strip(a, live), width, 4)));+ }+ if (self.steer_queue.items.len > 0) {+ if (!first) try out.append('\n');+ try out.appendSlice(try theme_mod.paint(a, self.theme().muted, try std.fmt.allocPrint(a, " ↳ {d} queued · empty Enter sends now", .{self.steer_queue.items.len})));+ }}}return out.items;@@ -127,7 +129,7 @@ fn summary(self: *const Model, a: std.mem.Allocator, start: usize, end: usize, sif (isSearch(t)) searches += 1 else calls += 1;}const sel: []const u8 = if (selected) "› " else " ";- const live = if (self.pending != null)+ const live = if (self.pending != null and !self.cancel_requested)try std.fmt.allocPrint(a, "{s}❙{s} ", .{ if (flickerOn(self.now_ms)) th.accent else th.muted, theme_mod.reset })else"";@@ -288,8 +290,9 @@ fn thinkingGlyph(now_ms: u64) []const u8 {}fn thinkingLabel(now_ms: u64) []const u8 {- const frames = [_][]const u8{ "thinking ", "thinking. ", "thinking.. ", "thinking..." };- return frames[(now_ms / 320) % frames.len];+ _ = now_ms;+ // Grok: static "Thinking" — motion is only the ❙ flicker.+ return "Thinking";}fn firstLine(s: []const u8) []const u8 {@@ -337,9 +340,9 @@ test "firstLine stops at newline" {try std.testing.expectEqualStrings("ab", firstLine("ab\ncd"));}-test "thinking animation is a word, not a lone spinner" {- try std.testing.expect(std.mem.startsWith(u8, thinkingLabel(0), "thinking"));- try std.testing.expect(!std.mem.eql(u8, thinkingLabel(0), thinkingLabel(320)));+test "thinking animation is Grok ❙ flicker plus static Thinking" {+ try std.testing.expectEqualStrings("Thinking", thinkingLabel(0));+ try std.testing.expectEqualStrings(thinkingLabel(0), thinkingLabel(320));try std.testing.expectEqualStrings("❙", thinkingGlyph(0));try std.testing.expect(flickerOn(0) != flickerOn(140));}diff --git a/TUI/turn.zig b/TUI/turn.zigindex ca8ed2b2..49a1a74d 100644--- a/TUI/turn.zig+++ b/TUI/turn.zig@@ -73,7 +73,7 @@ pub fn finishJob(self: *Model) void {self.push(.assistant, r) catch {};self.alloc.free(r);} else if (self.cancel_requested) {- self.push(.system, "⏹ interrupted") catch {};+ if (!hasInterrupted(self)) self.push(.system, "■ interrupted") catch {};} else {self.push(.err, "model call failed — check /model and your API key") catch {};}@@ -112,6 +112,23 @@ pub fn cancelTurn(self: *Model) void {if (self.pending == null) return;self.cancel_requested = true;if (engine.g_cancel_fn) |f| f(engine.g_turn_ctx);+ collapseThinking(self);+}++fn collapseThinking(self: *Model) void {+ const n = self.history.items.len;+ if (n == 0 or self.history.items[n - 1].kind != .pending) return;+ self.alloc.free(self.history.items[n - 1].text);+ const text = self.alloc.dupe(u8, "■ interrupted") catch {+ self.history.shrinkRetainingCapacity(n - 1);+ return;+ };+ self.history.items[n - 1] = .{ .kind = .system, .text = text, .folded = false };+}++fn hasInterrupted(self: *const Model) bool {+ if (self.history.items.len == 0) return false;+ return std.mem.eql(u8, self.history.items[self.history.items.len - 1].text, "■ interrupted");}pub fn isToolLine(line: []const u8) bool {@@ -124,6 +141,7 @@ pub fn isToolLine(line: []const u8) bool {/// Pull new ⚙/✓/✗ lines out of the live stream so they become clickable/// folded history *during* the turn, not only after finishJob.pub fn harvestLiveTools(self: *Model) void {+ if (self.cancel_requested) return;const job = self.pending orelse return;const live = job.stream.snapshot(self.alloc) orelse return;defer self.alloc.free(live);@@ -274,3 +292,33 @@ test "Ctrl+C during a turn cancels once then quits" {try std.testing.expect(m.pending != null);try std.testing.expectEqual(@import("app.zig").Effect.quit, keys.handle(&m, .{ .ctrl = 'c' }));}++test "cancelTurn collapses thinking immediately" {+ 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 = .{ .buf = &.{} },+ .threaded = false,+ .done = std.atomic.Value(bool).init(false),+ };+ try m.push(.pending, "");+ m.pending = job;+ cancelTurn(&m);+ try std.testing.expect(m.cancel_requested);+ try std.testing.expect(m.history.items.len == 1);+ try std.testing.expect(m.history.items[0].kind == .system);+ try std.testing.expectEqualStrings("■ interrupted", m.history.items[0].text);+ job.done.store(true, .release);+ finishJob(&m);+ try std.testing.expect(m.pending == null);+ var n: usize = 0;+ for (m.history.items) |e| {+ if (std.mem.eql(u8, e.text, "■ interrupted")) n += 1;+ }+ try std.testing.expectEqual(@as(usize, 1), n);+}diff --git a/docs/releases/v0.0.256.md b/docs/releases/v0.0.256.mdindex baa808bd..cb40951f 100644--- a/docs/releases/v0.0.256.md+++ b/docs/releases/v0.0.256.md@@ -9,5 +9,6 @@ killed the turn.- TUI stdin is appended to `.graff/tui-traj.jsonl` (hex, rotated at 512KiB)and the last visible frame is written on exit.- Shift+9 / Shift+0 type `(` / `)` (Kitty reports the unshifted key).+- Interrupt collapses Thinking immediately — Grok ❙ flicker + static "Thinking".Bare `graff` stays the line REPL. `graff tui` is the pager.