graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Refine terminal REPL chrome for the next release
Rach Pradhaneb2436e20a60
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex bfb552ef..c69d128d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,13 @@ The release workflow uses a tag's section here as its release notes (ahand-written `docs/releases/<tag>.md` wins if present), so keeping this filecurrent is part of cutting a release.+## v0.302.52++- The terminal REPL has a clearer session strip, a subtle divider, and distinct styling for active and completed checklist items. The bare prompt, scrollback, and plain output remain intact; no native window or graphical toolkit is required.+- Operational modes stay visible before workspace metadata when a terminal pane is narrow.+- Includes independent conversation forks for subagents and workflow fan-out, optional retained workers, and bounded workflow synthesis that preserves earlier findings.+- Retains all changes from v0.302.51.+## v0.302.51- Kimi works again with an API key or `graff login kimi`. Every Kimi request had been failing with `network error: RstStream` (or a 400 over HTTP/1.1) because graff sent a corrupted device-id header; graff no longer sends a device id or keeps `~/.kimi/device_id`.diff --git a/docs/adr/0302-terminal-repl-chrome-stays-in-the-terminal.md b/docs/adr/0302-terminal-repl-chrome-stays-in-the-terminal.mdnew file mode 100644index 00000000..e96b0c7e--- /dev/null+++ b/docs/adr/0302-terminal-repl-chrome-stays-in-the-terminal.md@@ -0,0 +1,28 @@+# 0302. Terminal REPL chrome stays in the terminal renderer++## Context++A native UI toolkit provides windows and GPU rendering, not terminal cells.+Replacing the line REPL with a native window would change how it is launched,+its scrollback and its input contract. ADR 0245 already separates the external+fullscreen client from this repository's line REPL.++## Decision++Refine the existing terminal sinks rather than introducing a graphical toolkit+or another frontend. The status strip emphasizes session identity and operational+modes while keeping workspace and usage metadata quiet. Mode labels take width+priority over workspace metadata. A colored terminal replaces the existing blank+separator row with a dim rule, leaving one column free to avoid autowrap.++Standing work uses dim completed items and an emerald active item. Waiting work+remains explicit; styling never changes its state or implies completion. Keep the+bare `›`, editor behavior, scrollback, engine events and ACP unchanged. With+color disabled, omit the divider and all styling sequences.++## Consequences++This creates terminal-cell hierarchy, not native widgets, custom fonts or GPU+rendering. The external fullscreen client remains independent. Existing plain+rendering snapshots and PTY prompt-reflow checks retain the input contract;+rendering tests cover bounded dividers, active-work emphasis and mode priority.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex 967e4d16..18d7b823 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -325,6 +325,7 @@ record only when you need the evidence or the edge cases.| [0300](0300-a-session-shuts-down-the-simulators-it-booted.md) | Shell commands that look like simulator work are bracketed by booted-device snapshots; devices a session booted are leased under `~/.codegraff/simulators/` and shut down when the last live leaseholder ends, never devices booted before. `GRAFF_KEEP_SIMULATORS=1` opts out. || [0301](0301-failed-requests-settle-the-pending-turn.md) | Exhausted request retries leave a truthful failure boundary in history so an identical prompt can run after reconnecting, including after save/load; duplicate-host protection and bounded retries stay unchanged. |+| [0302](0302-terminal-repl-chrome-stays-in-the-terminal.md) | Refine the line REPL's terminal sinks: quiet status hierarchy, mode-first width priority and active-work emphasis, without native windows or changing the editor, engine or external fullscreen client. |## When to write onediff --git a/scripts/eval/tier1-manifest.json b/scripts/eval/tier1-manifest.jsonindex 1c170ff1..0cd4cd30 100644--- a/scripts/eval/tier1-manifest.json+++ b/scripts/eval/tier1-manifest.json@@ -14,7 +14,7 @@"src/main.zig","src/repl.zig"],- "test_count_baseline": 3484,+ "test_count_baseline": 3487,"test_count_slack": 25,"required_invariants": [{diff --git a/src/agent_prompt_render.zig b/src/agent_prompt_render.zigindex 3741151f..0bdd81df 100644--- a/src/agent_prompt_render.zig+++ b/src/agent_prompt_render.zig@@ -4,12 +4,10 @@//! agent_stream_render.zig and agent_tool_render.zig have for their clusters;//! this is one of the few files down here that may touch ansi/term.//!-//! Every function is the old inline agent_prompt.zig code path, gate for gate,-//! and the layout is asserted byte-for-byte by the tests at the bottom. The one-//! deliberate difference from the pre-#429 path: a write error is swallowed-//! rather than propagated, because a sink emit returns void. Every other-//! TuiSink branch already behaves that way, and the only way to reach it is a-//! terminal that has gone away mid-prompt.+//! The session strip separates identity, operational modes and quiet metrics.+//! A colored terminal replaces the existing blank row with a subtle divider;+//! plain output keeps the unframed status and bare prompt. This is terminal+//! presentation only: the engine still owns every fact in PromptStatus.const std = @import("std");const Io = std.Io;@@ -92,8 +90,19 @@ fn cwdName(cwd: []const u8) []const u8 {return t;}+fn modeSegment(w: *Io.Writer, text: []const u8) !void {+ try w.print(" · {s}{s}{s}{s}{s}{s}", .{ style.reset, style.accent, style.bold, text, style.reset, style.dim });+}+fn line(w: *Io.Writer, st: PromptStatus, cols: usize) !void {working.writeFromStanding(w, st.standing);+ // Reuse the blank separator row, not another panel or an editor border.+ // Leave a column free so the rule never triggers terminal autowrap.+ if (style.accent.len > 0 and cols > 1) {+ try w.writeAll(style.dim);+ for (0..cols - 1) |_| try w.writeAll("─");+ try w.writeAll(style.reset);+ }try w.writeByte('\n');var cbuf: [24]u8 = undefined;@@ -125,21 +134,21 @@ fn line(w: *Io.Writer, st: PromptStatus, cols: usize) !void {else"";- // Dim meter above a bare `›`. Operational badges (Fast/Plan/Strict)- // stay. Cwd is a high-priority one-liner (`~/folder`) so the Codegraff- // box does not have to restate the ask. #209: drop from the right.+ // Identity anchors the strip; modes that affect the next turn take+ // priority over workspace and usage. Everything stays above a bare `›`.+ // #209: drop lower-priority segments instead of wrapping the strip.const avail = cols -| 1;var used: usize = st.model.len;const folder = cwdName(st.cwd);const show_fast = st.fast and fitsSegment(&used, avail, 3 + "Fast".len);const show_effort = st.effort != null andfitsSegment(&used, avail, 3 + reasoningLabel(st.effort.?).len);- const show_cwd = folder.len > 0 and fitsSegment(&used, avail, 3 + 2 + folder.len);const show_fallback = st.fallback andfitsSegment(&used, avail, 3 + "Fallback".len);const show_plan = st.plan and fitsSegment(&used, avail, 3 + "Plan".len);const show_strict = st.strict and fitsSegment(&used, avail, 3 + "Strict".len);const show_ultra = st.ultracode and fitsSegment(&used, avail, 3 + "Ultracode".len);+ const show_cwd = folder.len > 0 and fitsSegment(&used, avail, 3 + 2 + folder.len);const show_ctx = ctx.len > 0 and fitsSegment(&used, avail, 3 + ctx.len);const show_cache = show_ctx and cache.len > 0 and fitsSegment(&used, avail, 3 + cache.len);const show_cost = cost.len > 0 and fitsSegment(&used, avail, 3 + cost.len);@@ -148,14 +157,14 @@ fn line(w: *Io.Writer, st: PromptStatus, cols: usize) !void {const show_session = st.standing.session.len > 0 andfitsSegment(&used, avail, 3 + st.standing.session.len);- try w.print("{s}{s}", .{ style.dim, st.model });- if (show_fast) try w.print(" · Fast", .{});+ try w.print("{s}{s}{s}{s}{s}", .{ style.bold, style.accent, st.model, style.reset, style.dim });+ if (show_fast) try modeSegment(w, "Fast");if (show_effort) try w.print(" · {s}", .{reasoningLabel(st.effort.?)});+ if (show_fallback) try modeSegment(w, "Fallback");+ if (show_plan) try modeSegment(w, "Plan");+ if (show_strict) try modeSegment(w, "Strict");+ if (show_ultra) try modeSegment(w, "Ultracode");if (show_cwd) try w.print(" · ~/{s}", .{folder});- if (show_fallback) try w.print(" · Fallback", .{});- if (show_plan) try w.print(" · Plan", .{});- if (show_strict) try w.print(" · Strict", .{});- if (show_ultra) try w.print(" · Ultracode", .{});if (show_ctx) try w.print(" · {s}", .{ctx});if (show_cache) try w.print(" · {s}", .{cache});if (show_cost) try w.print(" · {s}", .{cost});@@ -232,15 +241,14 @@ test "wide pane keeps every segment, matching the pre-#209 behaviour" {try std.testing.expect(fitsSegment(&used, avail, " · 12k/100k ctx (12% · compact@80k)".len));}-/// The status line as a plain-terminal reader sees it. Pins the exact bytes the-/// pre-#429 inline path produced, so the move behind the sink cannot quietly-/// reword, reorder or re-space a segment.+/// The unstyled strip as a plain-terminal reader sees it, with enough room+/// for every optional segment.fn renderPlain(buf: *Io.Writer.Allocating, st: PromptStatus) []const u8 {line(&buf.writer, st, 400) catch unreachable; // a pane wide enough to keep everythingreturn buf.writer.buffered();}-test "batch 3: every status-line segment renders exactly as it did inline" {+test "terminal status keeps every segment and prioritizes operational modes" {const saved = style.*;style.* = .{}; // assert the text, not the palettedefer style.* = saved;@@ -265,7 +273,7 @@ test "batch 3: every status-line segment renders exactly as it did inline" {.ultracode = true,};try std.testing.expectEqualStrings(- "\ngpt-5.6 · Fast · High · ~/graff · Fallback · Plan · Strict · Ultracode · ctx 6% · cache 16% · $0.50\n› ",+ "\ngpt-5.6 · Fast · High · Fallback · Plan · Strict · Ultracode · ~/graff · ctx 6% · cache 16% · $0.50\n› ",renderPlain(&aw, full),);@@ -432,6 +440,50 @@ test "standing work draws a WORKING block above the prompt" {);}+test "terminal chrome bounds its divider and separates identity from metadata" {+ const saved = style.*;+ style.* = @import("ansi.zig").Style.ansi;+ defer style.* = saved;+ var aw: Io.Writer.Allocating = .init(std.testing.allocator);+ defer aw.deinit();+ const st: PromptStatus = .{+ .model = "m",+ .provider_id = "p",+ .cwd = "/w",+ .privacy_label = "",+ .privacy = .local,+ .plan = true,+ };+ for ([_]usize{ 1, 18, 80 }) |cols| {+ aw.clearRetainingCapacity();+ try line(&aw.writer, st, cols);+ const text = aw.written();+ const end = std.mem.indexOfScalar(u8, text, '\n').?;+ try std.testing.expectEqual(cols - 1, std.mem.count(u8, text[0..end], "─"));+ try std.testing.expect(std.mem.indexOf(u8, text, "\x1b[1m\x1b[38;2;5;150;105mm\x1b[0m\x1b[2m") != null);+ try std.testing.expect(std.mem.endsWith(u8, text, "\n\x1b[1m\x1b[38;2;5;150;105m›\x1b[0m "));+ }+}++test "terminal status keeps operational modes before a long workspace" {+ const saved = style.*;+ style.* = .{};+ defer style.* = saved;+ var aw: Io.Writer.Allocating = .init(std.testing.allocator);+ defer aw.deinit();+ try line(&aw.writer, .{+ .model = "m",+ .provider_id = "p",+ .cwd = "/a-very-long-workspace-name",+ .privacy_label = "",+ .privacy = .local,+ .fallback = true,+ .plan = true,+ .strict = true,+ }, 36);+ try std.testing.expectEqualStrings("\nm · Fallback · Plan · Strict\n› ", aw.written());+}+test {_ = working;}diff --git a/src/agent_working.zig b/src/agent_working.zigindex 4f3f1e74..a1a2e702 100644--- a/src/agent_working.zig+++ b/src/agent_working.zig@@ -8,6 +8,7 @@ const Io = std.Io;const engine_events = @import("engine_events.zig");const util = @import("util.zig");+const style = &@import("ansi.zig").style;pub const Item = struct {content: []const u8,@@ -32,14 +33,18 @@ pub fn write(w: *Io.Writer, title: []const u8, items: []const Item) void {for (items) |it| {if (it.done) done += 1;}- w.print("WORKING {s}", .{shown}) catch return;- if (items.len > 0) w.print(" {d}/{d}", .{ done, items.len }) catch return;+ w.print("{s}WORKING{s} {s}{s}{s}", .{ style.dim, style.reset, style.bold, shown, style.reset }) catch return;+ if (items.len > 0) w.print(" {s}{d}/{d}{s}", .{ style.dim, done, items.len, style.reset }) catch return;w.writeByte('\n') catch return;const n = @min(items.len, max_items);for (items[0..n], 0..) |it, i| {const branch: []const u8 = if (i + 1 == n) "└ " else "├ ";const mark: []const u8 = if (it.done) "✓" else if (it.active) "◌" else "○";- w.print("{s}{s} {s}\n", .{ branch, mark, clip(it.content, item_clip) }) catch return;+ const color = if (it.done) style.dim else if (it.active) style.accent else "";+ const weight = if (it.active and !it.done) style.bold else "";+ w.print("{s}{s}{s}{s}{s}{s} {s}{s}\n", .{+ style.dim, branch, style.reset, color, weight, mark, clip(it.content, item_clip), style.reset,+ }) catch return;}}@@ -61,7 +66,9 @@ pub fn writeFromStanding(w: *Io.Writer, st: engine_events.StandingWork) void {/// session waits on so the `›` below it does not read as graff having stopped.fn writeWaiting(w: *Io.Writer, waiting: []const u8) void {if (waiting.len == 0) return;- w.print("↻ waiting on {s} — graff continues when it finishes\n", .{waiting}) catch return;+ w.print("{s}↻{s}{s} waiting on {s} — graff continues when it finishes{s}\n", .{+ style.accent, style.reset, style.dim, waiting, style.reset,+ }) catch return;}/// Parse the model's todo_write dump (`[x]` / `[~]` / `[ ]` lines) into the@@ -109,6 +116,25 @@ test "completed checklist stays out of idle prompt redraws" {try std.testing.expect(std.mem.indexOf(u8, aw.written(), "WORKING") != null);}+test "terminal working block highlights active work without hiding waiting" {+ const saved = style.*;+ style.* = @import("ansi.zig").Style.ansi;+ defer style.* = saved;+ var aw: Io.Writer.Allocating = .init(std.testing.allocator);+ defer aw.deinit();+ const items = [_]engine_events.StandingTodo{+ .{ .content = "finished", .done = true },+ .{ .content = "current", .active = true },+ .{ .content = "next" },+ };+ writeFromStanding(&aw.writer, .{ .goal = "ship it", .todos = &items, .todos_done = 1, .todos_total = 3, .waiting = "agent 4" });+ const text = aw.written();+ try std.testing.expect(std.mem.indexOf(u8, text, "\x1b[2m✓ finished\x1b[0m") != null);+ try std.testing.expect(std.mem.indexOf(u8, text, "\x1b[38;2;5;150;105m\x1b[1m◌ current\x1b[0m") != null);+ try std.testing.expect(std.mem.indexOf(u8, text, "○ next") != null);+ try std.testing.expect(std.mem.indexOf(u8, text, "waiting on agent 4 — graff continues when it finishes") != null);+}+test "empty standing work draws nothing" {var aw: Io.Writer.Allocating = .init(std.testing.allocator);defer aw.deinit();