Skip to content

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

Python

fix(#601): expand line-REPL tool results on Enter

Rach Pradhan917915632d39
diff --git a/docs/adr/0020-transcript-shows-decisions.md b/docs/adr/0020-transcript-shows-decisions.md
index 155649c1..8db8039f 100644
--- a/docs/adr/0020-transcript-shows-decisions.md
+++ b/docs/adr/0020-transcript-shows-decisions.md
@@ -25,5 +25,7 @@ lines. The user-relevant fact was "CI is red."
## Consequences
JSON `bash_output_chunk` events are unchanged. The hosted TUI sink still
-streams into the fold. Expanding a one-liner from the line REPL is not a
-feature yet; `/debug` is the escape hatch. ADR 0016's progress bar is retired.
+streams into the fold. In the line REPL, a row whose interpretation hid raw
+bytes carries `↵ raw`; empty Enter reveals the newest unseen result, explicitly
+and terminal-safely. `/debug` remains the continuous escape hatch. ADR 0016's
+progress bar is retired.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 06f5ee4c..2ce0b253 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -30,7 +30,7 @@ record only when you need the evidence or the edge cases.
| [0017](0017-model-election-ranks-signed-in-plans-first.md) | `/model` and `/models` on both frontends rank signed-in plan seats above credits and metered keys (`src/models_rank.zig`). |
| [0018](0018-standing-chrome-shows-last-turn-cache-hit.md) | Last-turn cache hit % rides with `ctx` on the line-REPL meter and the TUI footer; `/cache` stays the posture HUD. |
| [0019](0019-codedb-one-shot-over-hop-chains.md) | Advertise only `context` / `around` / `callpath` / `list_dir` / `status`; hop verbs stay callable, not on the menu. |
-| [0020](0020-transcript-shows-decisions.md) | Transcript shows decisions: one interpreted tool line, collapsed infra failures, compact WORKING; raw output is `/debug` / TUI-fold. |
+| [0020](0020-transcript-shows-decisions.md) | Transcript shows decisions: one interpreted tool line, collapsed infra failures, compact WORKING; `↵ raw`, `/debug`, and TUI-fold disclose the bytes explicitly. |
| [0021](0021-transcript-is-the-task-not-the-bus.md) | Transcript is the task, not the event bus: bookkeeping is silent, todos are WORKING, subagents are scouts. |
| [0022](0022-rlm-is-opt-in-speculative-ptc.md) | `rlm` (Alex Zhang spec-ptc + RLM, Zig) is the default loop. `--old` restores structured-only. Prime persist + `subagent()` only — no IPython. |
| [0023](0023-codex-subagent-is-sidecar-not-v8.md) | Codex check: take sidecar-vs-critical-path spawn prompts; reject V8 Code Mode, extra spawn tools, and parent-history fork. |
diff --git a/src/agent_tool_render.zig b/src/agent_tool_render.zig
index 99e7434e..6398e672 100644
--- a/src/agent_tool_render.zig
+++ b/src/agent_tool_render.zig
@@ -37,6 +37,7 @@ const ToolInvocation = engine_events.ToolInvocation;
const ToolOutcome = engine_events.ToolOutcome;
const BatchOutcome = engine_events.BatchOutcome;
const label = @import("agent_tool_label.zig");
+const disclosure = @import("line_repl_disclosure.zig");
/// How many sibling tools are still outstanding in the current parallel batch.
/// 0 = sequential (no tree). The layout, not a "↯ N in parallel" line, is
@@ -168,12 +169,14 @@ pub fn toolResultLine(a: *Agent, r: ToolOutcome) void {
const verb = if (remembered) |mem| mem.verb else r.name;
const detail = if (remembered) |mem| mem.detail else "";
const shown_final = label.usefulPreview(r.name, detail, shown);
+ const disclosed = disclosure.record(a.io, verb, detail, all, shown_final);
const prefix = treePrefix();
w.print("{s}{s}{s}{s} {s}", .{ prefix, mc, mark, style.reset, verb }) catch return;
if (detail.len > 0) w.print(" {s}", .{detail}) catch return;
w.print("{s}{s}{s}", .{ style.dim, timing, style.reset }) catch return;
if (badge.len > 0) w.print(" {s}", .{badge}) catch return;
if (shown_final.len > 0) w.print(" {s}{s}{s}{s}", .{ style.dim, shown_final, if (truncated) "…" else "", style.reset }) catch return;
+ if (disclosed) w.print(" {s}↵ raw{s}", .{ style.dim, style.reset }) catch return;
w.writeAll("\n") catch return;
w.flush() catch return;
}
@@ -243,10 +246,11 @@ fn testAgent(w: *Io.Writer) Agent {
batch_left = 0;
label.resetPending();
resetInfra();
+ disclosure.reset(std.testing.io);
return .{
.gpa = std.testing.allocator,
.arena = std.testing.allocator,
- .io = undefined,
+ .io = std.testing.io,
.client = undefined,
.provider = undefined,
.messages = undefined,
@@ -274,7 +278,7 @@ test "announce is silent and the ✓ line uses the remembered verb" {
toolUseLine(&a, .{ .name = "read_file", .input = input });
try std.testing.expectEqualStrings("", aw.writer.buffered());
toolResultLine(&a, .{ .name = "read_file", .text = "line one\nline two\n", .is_error = false });
- try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines ↵ raw\n", aw.writer.buffered());
aw.clearRetainingCapacity();
toolUseLine(&a, .{ .name = "attempt_completion", .input = input, .arg_streamed = true });
@@ -294,7 +298,7 @@ test "the result line marks success, failure and cancellation and previews one l
label.resetPending();
toolResultLine(&a, .{ .name = "read_file", .text = "line one\nline two\n", .is_error = false });
- try std.testing.expectEqualStrings(" ✓ read_file 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ read_file 2 lines ↵ raw\n", aw.writer.buffered());
aw.clearRetainingCapacity();
toolResultLine(&a, .{ .name = "bash", .text = "boom", .is_error = true });
@@ -322,8 +326,8 @@ test "the result line marks success, failure and cancellation and previews one l
const long = util.repeatBytes("z", 250);
toolResultLine(&a, .{ .name = "bash", .text = &long, .is_error = false });
const rline = aw.writer.buffered();
- try std.testing.expect(std.mem.endsWith(u8, rline, "…\n"));
- try std.testing.expectEqual(@as(usize, 100), rline.len - " ✓ bash ".len - "…\n".len);
+ try std.testing.expect(std.mem.endsWith(u8, rline, "… ↵ raw\n"));
+ try std.testing.expectEqual(@as(usize, 100), rline.len - " ✓ bash ".len - "… ↵ raw\n".len);
aw.clearRetainingCapacity();
main_mod.show_timing = true;
@@ -334,12 +338,12 @@ test "the result line marks success, failure and cancellation and previews one l
aw.clearRetainingCapacity();
main_mod.show_timing = false;
toolResultLine(&a, .{ .name = "bash", .text = "[tool result handle: 44690 bytes, JSON object — the COMPLETE result is at /tmp/h-0.txt. Slice what you need out of that file (read_file with start_line/end_line, a grep-style bash command, codedb) instead of re-running the tool (#440).]", .is_error = false });
- try std.testing.expectEqualStrings(" ✓ bash ⇢ 43.6 KiB handle\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ bash ⇢ 43.6 KiB handle ↵ raw\n", aw.writer.buffered());
// The no-handle truncation variant badges the loss instead.
aw.clearRetainingCapacity();
toolResultLine(&a, .{ .name = "bash", .text = "[tool result truncated to 16384 bytes: 90000 bytes total, JSON object. No handle could be written, so the rest is gone — narrow the command and run it again (#440).]", .is_error = false });
- try std.testing.expectEqualStrings(" ✓ bash ⇠ 87.9 KiB lost\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ bash ⇠ 87.9 KiB lost ↵ raw\n", aw.writer.buffered());
}
test "the effort-routing note draws in normal mode and stays quiet in debug mode" {
@@ -379,13 +383,13 @@ test "batch tallies and meta notices render the old wording verbatim" {
try std.testing.expectEqualStrings("", aw.writer.buffered());
label.resetPending();
toolResultLine(&a, .{ .name = "read_file", .text = "a\nb\n", .is_error = false });
- try std.testing.expectEqualStrings(" ├─ ✓ read_file 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ├─ ✓ read_file 2 lines ↵ raw\n", aw.writer.buffered());
aw.clearRetainingCapacity();
toolResultLine(&a, .{ .name = "read_file", .text = "a\nb\n", .is_error = false });
- try std.testing.expectEqualStrings(" ├─ ✓ read_file 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ├─ ✓ read_file 2 lines ↵ raw\n", aw.writer.buffered());
aw.clearRetainingCapacity();
toolResultLine(&a, .{ .name = "read_file", .text = "a\nb\n", .is_error = false });
- try std.testing.expectEqualStrings(" └─ ✓ read_file 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" └─ ✓ read_file 2 lines ↵ raw\n", aw.writer.buffered());
aw.clearRetainingCapacity();
parallelBatchFinished(&a, .{ .done = 2, .failed = 0, .cancelled = 0 });
@@ -452,7 +456,7 @@ test "edit_file one-liner includes a +N/-N delta" {
label.resetPending();
toolUseLine(&a, .{ .name = "edit_file", .input = one });
toolResultLine(&a, .{ .name = "edit_file", .text = "applied 1 edit span(s) to src/a.zig (each verified)", .is_error = false });
- try std.testing.expectEqualStrings(" ✓ edit src/a.zig · +3/-2\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ edit src/a.zig · +3/-2 ↵ raw\n", aw.writer.buffered());
}
test "bash result prefers the last line of a multi-line run" {
@@ -468,7 +472,7 @@ test "bash result prefers the last line of a multi-line run" {
.text = "[1/3] a...\n[2/3] b...\nAll 1475 tests passed\n",
.is_error = false,
});
- try std.testing.expectEqualStrings(" ✓ bash 1475 passed\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ bash 1475 passed ↵ raw\n", aw.writer.buffered());
}
test "bash git log is a count, never the command" {
@@ -487,7 +491,7 @@ test "bash git log is a count, never the command" {
.text = "d022479 feat(ui): cache\n8f75b5b fix(tui): chips\n4ba84b3 feat(models): seats\n",
.is_error = false,
});
- try std.testing.expectEqualStrings(" ✓ git 3 commits\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ git 3 commits ↵ raw\n", aw.writer.buffered());
}
test "repeated McpClosed collapses to one notice and skips the batch tally" {
@@ -527,5 +531,40 @@ test "codedb JSON read is basename plus mode, not the envelope" {
.text = "{\"ok\":true,\"file\":\"/Users/rachpradhan/codedb/docs/architecture.md\",\"mode\":\"section\",\"content\":\"a\\nb\\nc\"}",
.is_error = false,
});
- try std.testing.expectEqualStrings(" ✓ read architecture.md 3 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ read architecture.md 3 lines ↵ raw\n", aw.writer.buffered());
+}
+
+test "blank Enter reveals hidden tool results newest-first and terminal-safe" {
+ const saved = ansi.style;
+ ansi.style = .{};
+ defer ansi.style = saved;
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ var aw: Io.Writer.Allocating = .init(std.testing.allocator);
+ defer aw.deinit();
+ var a = testAgent(&aw.writer);
+
+ const input = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(), "{\"path\":\"fixture.txt\"}", .{});
+ toolUseLine(&a, .{ .name = "read_file", .input = input });
+ toolResultLine(&a, .{ .name = "read_file", .text = "line one\nline two", .is_error = false });
+ toolResultLine(&a, .{ .name = "bash", .text = "\x1b[31mred\x1b[0m\nlast", .is_error = false });
+ aw.clearRetainingCapacity();
+
+ try std.testing.expect(!disclosure.handleInput(a.io, &aw.writer, "next task"));
+ try std.testing.expectEqualStrings("", aw.writer.buffered());
+ try std.testing.expect(disclosure.handleInput(a.io, &aw.writer, ""));
+ try std.testing.expectEqualStrings(
+ " ┌ raw bash\n │ red\n │ last\n └\n",
+ aw.writer.buffered(),
+ );
+
+ aw.clearRetainingCapacity();
+ try std.testing.expect(disclosure.handleInput(a.io, &aw.writer, ""));
+ try std.testing.expectEqualStrings(
+ " ┌ raw read · fixture.txt\n │ line one\n │ line two\n └\n",
+ aw.writer.buffered(),
+ );
+ aw.clearRetainingCapacity();
+ try std.testing.expect(disclosure.handleInput(a.io, &aw.writer, ""));
+ try std.testing.expectEqualStrings("", aw.writer.buffered());
}
diff --git a/src/engine_sink_tests.zig b/src/engine_sink_tests.zig
index 7f784722..5cc6a788 100644
--- a/src/engine_sink_tests.zig
+++ b/src/engine_sink_tests.zig
@@ -67,13 +67,13 @@ test "a presentation sink never reserves sequence ids" {
}
/// The Agent shape every sink test renders through: allocator-backed, rooted
-/// (not a subagent), writing into the caller's buffer. `io` stays undefined —
-/// dispatch only touches it under the --json lock, which these tests pin off.
+/// (not a subagent), writing into the caller's buffer.
fn testAgent(w: *Io.Writer) Agent {
+ @import("line_repl_disclosure.zig").reset(std.testing.io);
return .{
.gpa = std.testing.allocator,
.arena = std.testing.allocator,
- .io = undefined,
+ .io = std.testing.io,
.client = undefined,
.provider = undefined,
.messages = undefined,
@@ -282,7 +282,7 @@ test "TuiSink shows tool one-liners with args and a result preview (slice 1c)" {
const done: engine_events.ToolOutcome = .{ .name = "read_file", .text = "line one\nline two\n", .is_error = false };
s.emit(undefined, .{ .tool_call_announced = call });
s.emit(undefined, .{ .tool_result = done });
- try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines ↵ raw\n", aw.writer.buffered());
aw.clearRetainingCapacity();
s.emit(undefined, .{ .tool_call_announced = call });
@@ -290,7 +290,7 @@ test "TuiSink shows tool one-liners with args and a result preview (slice 1c)" {
s.emit(undefined, .{ .tool_result = done });
s.emit(undefined, .{ .tool_call_finished = done }); // silent
s.emit(undefined, .{ .tool_rejected = .{ .name = "bash", .input = input, .reason = "budget", .message = "no" } }); // silent
- try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines ↵ raw\n", aw.writer.buffered());
}
test "TuiSink renders a plain text delta exactly as the no-color TTY did" {
diff --git a/src/line_repl_disclosure.zig b/src/line_repl_disclosure.zig
new file mode 100644
index 00000000..ffaae368
--- /dev/null
+++ b/src/line_repl_disclosure.zig
@@ -0,0 +1,167 @@
+//! Explicit raw-result disclosure for the default line REPL (#601).
+//!
+//! Semantic tool rows remain the transcript. Results whose raw bytes contain
+//! more than the interpreted row are retained in a small process-local ring;
+//! an empty Enter reveals the newest unseen one. Nothing is printed live.
+
+const std = @import("std");
+const Io = std.Io;
+
+const ansi = @import("ansi.zig");
+const style = &ansi.style;
+
+const max_entries = 16;
+
+const Entry = struct {
+ name: []u8,
+ detail: []u8,
+ raw: []u8,
+ shown: bool = false,
+};
+
+var mutex: Io.Mutex = .init;
+var entries: [max_entries]?Entry = @splat(null);
+var count: usize = 0;
+
+fn freeEntry(entry: Entry) void {
+ const alloc = std.heap.page_allocator;
+ alloc.free(entry.name);
+ alloc.free(entry.detail);
+ alloc.free(entry.raw);
+}
+
+fn clearLocked() void {
+ for (entries[0..count]) |entry| freeEntry(entry.?);
+ entries = @splat(null);
+ count = 0;
+}
+
+/// Test/session reset. The live ring is otherwise bounded and old entries are
+/// freed as new tool results replace them.
+pub fn reset(io: Io) void {
+ mutex.lockUncancelable(io);
+ defer mutex.unlock(io);
+ clearLocked();
+}
+
+/// Retain a result only when its interpreted row hid something. Returns true
+/// when the caller should draw the `↵ raw` disclosure affordance.
+pub fn record(io: Io, name: []const u8, detail: []const u8, raw: []const u8, interpreted: []const u8) bool {
+ if (raw.len == 0 or std.mem.eql(u8, raw, interpreted)) return false;
+ const alloc = std.heap.page_allocator;
+ const owned_name = alloc.dupe(u8, name) catch return false;
+ const owned_detail = alloc.dupe(u8, detail) catch {
+ alloc.free(owned_name);
+ return false;
+ };
+ const owned_raw = alloc.dupe(u8, raw) catch {
+ alloc.free(owned_name);
+ alloc.free(owned_detail);
+ return false;
+ };
+
+ mutex.lockUncancelable(io);
+ defer mutex.unlock(io);
+ if (count == max_entries) {
+ freeEntry(entries[0].?);
+ for (1..max_entries) |i| entries[i - 1] = entries[i];
+ entries[max_entries - 1] = null;
+ count -= 1;
+ }
+ entries[count] = .{ .name = owned_name, .detail = owned_detail, .raw = owned_raw };
+ count += 1;
+ return true;
+}
+
+fn skipEscape(text: []const u8, start: usize) usize {
+ if (start + 1 >= text.len) return text.len;
+ if (text[start + 1] == '[') {
+ var i = start + 2;
+ while (i < text.len) : (i += 1) {
+ if (text[i] >= 0x40 and text[i] <= 0x7e) return i + 1;
+ }
+ return text.len;
+ }
+ if (text[start + 1] == ']') {
+ var i = start + 2;
+ while (i < text.len) : (i += 1) {
+ if (text[i] == 0x07) return i + 1;
+ if (text[i] == 0x1b and i + 1 < text.len and text[i + 1] == '\\') return i + 2;
+ }
+ return text.len;
+ }
+ return @min(start + 2, text.len);
+}
+
+/// Raw means uninterpreted, not unsafe: terminal controls and invalid UTF-8
+/// never get a chance to repaint the user's terminal.
+fn sanitized(alloc: std.mem.Allocator, text: []const u8) ![]u8 {
+ var out = std.array_list.Managed(u8).init(alloc);
+ errdefer out.deinit();
+ var i: usize = 0;
+ while (i < text.len) {
+ const byte = text[i];
+ if (byte == 0x1b) {
+ i = skipEscape(text, i);
+ continue;
+ }
+ if (byte < 0x20 or byte == 0x7f) {
+ if (byte == '\n' or byte == '\t') try out.append(byte);
+ i += 1;
+ continue;
+ }
+ if (byte < 0x80) {
+ try out.append(byte);
+ i += 1;
+ continue;
+ }
+ const len = std.unicode.utf8ByteSequenceLength(byte) catch {
+ i += 1;
+ continue;
+ };
+ if (i + len > text.len) break;
+ _ = std.unicode.utf8Decode(text[i .. i + len]) catch {
+ i += 1;
+ continue;
+ };
+ try out.appendSlice(text[i .. i + len]);
+ i += len;
+ }
+ return out.toOwnedSlice();
+}
+
+fn render(out: *Io.Writer, entry: Entry) !void {
+ const alloc = std.heap.page_allocator;
+ const name = try sanitized(alloc, entry.name);
+ defer alloc.free(name);
+ const detail = try sanitized(alloc, entry.detail);
+ defer alloc.free(detail);
+ const raw = try sanitized(alloc, entry.raw);
+ defer alloc.free(raw);
+
+ try out.print(" {s}┌ raw {s}", .{ style.dim, name });
+ if (detail.len > 0) try out.print(" · {s}", .{detail});
+ try out.print("{s}\n", .{style.reset});
+ var lines = std.mem.splitScalar(u8, raw, '\n');
+ while (lines.next()) |line| try out.print(" {s}│{s} {s}\n", .{ style.dim, style.reset, line });
+ try out.print(" {s}└{s}\n", .{ style.dim, style.reset });
+ try out.flush();
+}
+
+/// Empty Enter is consumed by disclosure. A non-empty line continues through
+/// the ordinary command/model path unchanged.
+pub fn handleInput(io: Io, out: *Io.Writer, line: []const u8) bool {
+ if (line.len != 0) return false;
+ mutex.lockUncancelable(io);
+ defer mutex.unlock(io);
+ var i = count;
+ while (i > 0) {
+ i -= 1;
+ const entry = &entries[i].?;
+ if (entry.shown) continue;
+ render(out, entry.*) catch return true;
+ entry.shown = true;
+ break;
+ }
+ return true;
+}
diff --git a/src/mainloop.zig b/src/mainloop.zig
index cdf93ca9..5e0b9cb1 100644
--- a/src/mainloop.zig
+++ b/src/mainloop.zig
@@ -37,6 +37,7 @@ const messages = @import("messages.zig");
const anim = @import("anim.zig");
const hooks = @import("hooks.zig");
const readline = @import("readline.zig");
+const line_repl_disclosure = @import("line_repl_disclosure.zig");
const title_mod = @import("title.zig");
const mainloop_title = @import("mainloop_title.zig");
const mainloop_recap = @import("mainloop_recap.zig");
@@ -119,7 +120,7 @@ pub fn run(ctx: *Ctx) !void {
title_jobs.poll(ctx);
recap_jobs.poll(ctx);
const line = std.mem.trim(u8, raw_line, " \t\r");
- if (line.len == 0) continue;
+ if (line_repl_disclosure.handleInput(ctx.root.io, ctx.out, line)) continue;
// `/goal [30m] <objective>` and `/loop [30m] <prompt>` are ONE autonomous run: same
// plan-act-verify machine, same controller, same optional wall clock. Only /goal also
// adopts a standing objective (goal_pacing.autonomousFromLine).