Skip to content

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

Python

feat(repl): WORKING block, bare ›, and a tool tree

Cursor Agentb20806aacd29
diff --git a/docs/adr/0012-line-repl-is-a-working-block.md b/docs/adr/0012-line-repl-is-a-working-block.md
new file mode 100644
index 00000000..07962832
--- /dev/null
+++ b/docs/adr/0012-line-repl-is-a-working-block.md
@@ -0,0 +1,32 @@
+# 0012. Line REPL chrome is a WORKING block plus a bare ›
+
+Status: accepted 2026-08-20
+
+## Context
+
+The default `graff` session is a line REPL, not `graff tui`. Stuffing goal,
+checklist, model, cwd, context, and cost into `[model · …] ›` and a
+`Goal … · 2/4 todos` row gave every fact the same visual weight. Tool lines
+that said `✓ bash ·` named the harness, not the work.
+
+Variations 4 (tool tree) and 5 (git-style status) were the ones we wanted:
+execution is a graph, standing work is persistent state, and the input line
+should be the eye's rest.
+
+## Decision
+
+- Standing goal and its checklist render as a `WORKING` block above the prompt,
+ not as badges on the input line.
+- The prompt is a bare `›`. Model, ctx, cost, `/resume N`, and a staged image
+ sit on one dim line above it.
+- Parallel tool batches are a `├─` / `└─` tree. Sequential calls are flat.
+ There is no `↯ N in parallel` tally when everything succeeded.
+- Result lines use a short verb (`test`, `edit`, `read`), never `bash`.
+ Announce lines stay off the default transcript.
+
+## Consequences
+
+The pager (`graff tui`) keeps its own chrome; it still receives the same
+`.prompt_ready` / tool events. Operational badges that change what the next
+turn will do (Plan, Strict, Fast, Fallback) remain on the dim status line.
+`/help` still lists keys; they are not reprinted every session.
diff --git a/docs/adr/README.md b/docs/adr/README.md
index 5619f8a2..0e98f0f7 100644
--- a/docs/adr/README.md
+++ b/docs/adr/README.md
@@ -22,6 +22,7 @@ record only when you need the evidence or the edge cases.
| [0009](0009-gpt-5-6-explicit-prompt-cache-boundary.md) | GPT-5.6 OpenAI Platform marks the stable prefix explicitly; Codex and xAI stay on their supported keyed automatic-cache paths. |
| [0010](0010-background-jobs-wait-for-exit.md) | `bash_output`/`agent_output` `wait_ms>0` blocks until exit (10h cap); do not poll every 30s. |
| [0011](0011-prompt-cache-max-is-visible.md) | Prompt-cache max is `/cache` posture, not a new default; `/btw` rides the parent prefix. |
+| [0012](0012-line-repl-is-a-working-block.md) | Line REPL chrome is a `WORKING` block plus a bare `›`; tool fan-out is a tree, never `✓ bash`. |
## When to write one
diff --git a/src/agent_prompt.zig b/src/agent_prompt.zig
index b86c5bda..c0f10c69 100644
--- a/src/agent_prompt.zig
+++ b/src/agent_prompt.zig
@@ -15,6 +15,8 @@ const engine_events = @import("engine_events.zig");
const engine_sink = @import("engine_sink.zig");
const agent_mod = @import("agent.zig");
const goal_state = @import("goal_state.zig");
+const session_index = @import("session_index.zig");
+const util = @import("util.zig");
const Agent = agent_mod.Agent;
/// The interactive status line printed before each human turn: model,
@@ -54,6 +56,7 @@ fn status(self: *Agent) engine_events.PromptStatus {
.strict = self.strict,
.ultracode = self.ultracode_mode,
.standing = standing(self),
+ .saved_sessions = @intCast(@min(session_index.countSavedSessions(self.io), std.math.maxInt(u32))),
};
}
@@ -79,11 +82,20 @@ fn standing(self: *const Agent) engine_events.StandingWork {
}
}
const epoch = goal_state.currentEpoch(self.goal);
+ var items: std.ArrayList(engine_events.StandingTodo) = .empty;
for (self.todos.items) |t| {
if (t.epoch != epoch or t.retired) continue;
out.todos_total += 1;
- if (std.mem.eql(u8, t.status, "completed")) out.todos_done += 1;
+ const done = std.mem.eql(u8, t.status, "completed");
+ if (done) out.todos_done += 1;
+ if (items.items.len < 8) {
+ items.append(self.arena, .{
+ .content = util.utf8Prefix(t.content, 48),
+ .done = done,
+ }) catch {};
+ }
}
+ out.todos = items.items;
out.image = self.pending_image != null;
return out;
}
@@ -225,6 +237,11 @@ test "standing work snapshots goal, checklist, session, and a staged image" {
try std.testing.expectEqualStrings("paused", sw.goal_status);
try std.testing.expectEqual(@as(u32, 2), sw.todos_total);
try std.testing.expectEqual(@as(u32, 1), sw.todos_done);
+ try std.testing.expectEqual(@as(usize, 2), sw.todos.len);
+ try std.testing.expectEqualStrings("done item", sw.todos[0].content);
+ try std.testing.expect(sw.todos[0].done);
+ try std.testing.expectEqualStrings("open item", sw.todos[1].content);
+ try std.testing.expect(!sw.todos[1].done);
try std.testing.expect(sw.image);
// A completed goal is not standing work; the default session name stays hidden.
diff --git a/src/agent_prompt_render.zig b/src/agent_prompt_render.zig
index fe84a468..dcec74a3 100644
--- a/src/agent_prompt_render.zig
+++ b/src/agent_prompt_render.zig
@@ -42,18 +42,6 @@ pub fn reasoningColor(effort: anytype) []const u8 {
};
}
-fn privacyColor(tier: engine_events.PrivacyTier) []const u8 {
- return switch (tier) {
- .local, .aggregate => style.green,
- .templates => style.yellow,
- .examples => style.red,
- };
-}
-
-pub fn writeBadge(writer: *Io.Writer, color: []const u8, label: []const u8) !void {
- try writer.print("{s} · {s}{s}{s}{s}", .{ style.dim, style.reset, color, label, style.reset });
-}
-
/// Include a status-line segment only if its width still fits the remaining
/// budget, charging it against `used` when it does. Lets the status line drop
/// low-priority metadata (cwd, context meter, cache/cost) instead of letting
@@ -90,145 +78,98 @@ pub fn promptLine(w: *Io.Writer, st: PromptStatus) void {
line(w, st, terminal.termCols()) catch return;
}
-fn standingActive(sw: engine_events.StandingWork) bool {
- return sw.goal.len > 0 or sw.todos_total > 0 or sw.image or sw.session.len > 0;
+fn workingActive(sw: engine_events.StandingWork) bool {
+ return sw.goal.len > 0 or sw.todos_total > 0;
}
-/// Dim row above `[model] ›` when the session has standing work. Drops from
-/// the right on a narrow pane (same #209 rule as the badges): Goal first,
-/// then the checklist, then the staged-image hint, then the session name.
-fn standingLine(w: *Io.Writer, sw: engine_events.StandingWork, cols: usize) !void {
- if (!standingActive(sw)) return;
- var parts: [4][]const u8 = undefined;
- var n: usize = 0;
- var goal_buf: [80]u8 = undefined;
+fn writeRule(w: *Io.Writer, cols: usize) !void {
+ const n = @min(if (cols > 2) cols else 2, 64);
+ try w.writeAll(style.dim);
+ var i: usize = 0;
+ while (i < n) : (i += 1) try w.writeAll("─");
+ try w.print("{s}\n", .{style.reset});
+}
+
+/// Git-style WORKING block: the goal and checklist live here, not in the
+/// agent narration and not mixed into the `›` prompt (variations 4+5).
+fn workingBlock(w: *Io.Writer, sw: engine_events.StandingWork, cols: usize) !void {
+ if (!workingActive(sw)) return;
+ try writeRule(w, cols);
+ try w.print("{s}WORKING", .{style.dim});
+ if (sw.goal_status.len > 0) try w.print(" ({s})", .{sw.goal_status});
+ try w.print("{s}\n", .{style.reset});
if (sw.goal.len > 0) {
- const clip = util.utf8Prefix(sw.goal, 40);
- parts[n] = if (sw.goal_status.len > 0)
- (std.fmt.bufPrint(&goal_buf, "Goal ({s}) {s}", .{ sw.goal_status, clip }) catch "Goal")
- else
- (std.fmt.bufPrint(&goal_buf, "Goal {s}", .{clip}) catch "Goal");
- n += 1;
+ const clip = util.utf8Prefix(sw.goal, if (cols > 8) cols - 2 else 40);
+ try w.print("{s}{s}{s}\n", .{ style.accent, clip, style.reset });
}
- var todo_buf: [24]u8 = undefined;
if (sw.todos_total > 0) {
- parts[n] = std.fmt.bufPrint(&todo_buf, "{d}/{d} todos", .{ sw.todos_done, sw.todos_total }) catch "";
- n += 1;
- }
- if (sw.image) {
- parts[n] = "image ready";
- n += 1;
- }
- if (sw.session.len > 0) {
- parts[n] = sw.session;
- n += 1;
- }
-
- // Two-space indent + the first segment, then ` · ` between survivors.
- const avail = if (cols > 2) cols - 2 else 0;
- var used: usize = 0;
- var show: usize = 0;
- while (show < n) : (show += 1) {
- const extra = if (show == 0) parts[show].len else 3 + parts[show].len;
- if (used + extra > avail) break;
- used += extra;
- }
- if (show == 0) return; // even the Goal clip will not fit — skip the row
-
- try w.print("{s} ", .{style.dim});
- var i: usize = 0;
- while (i < show) : (i += 1) {
- if (i > 0) try w.writeAll(" · ");
- if (i == 0 and sw.goal.len > 0) {
- try w.print("{s}{s}{s}{s}", .{ style.reset, style.accent, parts[i], style.dim });
- } else {
- try w.writeAll(parts[i]);
+ try w.print("{s}{d} of {d}{s}\n", .{ style.dim, sw.todos_done, sw.todos_total, style.reset });
+ for (sw.todos) |t| {
+ if (t.done) {
+ try w.print("{s}✓{s} {s}\n", .{ style.green, style.reset, t.content });
+ } else {
+ try w.print("{s}○{s} {s}\n", .{ style.dim, style.reset, t.content });
+ }
}
}
- try w.print("{s}\n", .{style.reset});
+ try writeRule(w, cols);
}
fn line(w: *Io.Writer, st: PromptStatus, cols: usize) !void {
try w.writeByte('\n');
- try standingLine(w, st.standing, cols);
- var cbuf: [40]u8 = undefined;
+ try workingBlock(w, st.standing, cols);
+
+ var cbuf: [24]u8 = undefined;
const cost: []const u8 = switch (st.cost) {
.hidden => "",
- .subscription => " · sub",
- .unpriced => " · $?",
- .usd => |usd| std.fmt.bufPrint(&cbuf, " · ${d:.4}", .{usd}) catch "",
+ .subscription => "sub",
+ .unpriced => "$?",
+ .usd => |usd| std.fmt.bufPrint(&cbuf, "${d:.2}", .{usd}) catch "",
};
- // Prompt-cache hit from the last response — proof caching is working.
- var kbuf: [32]u8 = undefined;
- var kval: [24]u8 = undefined;
- const cached: []const u8 = if (st.cache_read > 0)
- (std.fmt.bufPrint(&kbuf, " · ⚡{s} cached", .{compactTokenCount(&kval, st.cache_read)}) catch "")
+ var ctxbuf: [24]u8 = undefined;
+ const ctx: []const u8 = if (st.context) |meter|
+ (std.fmt.bufPrint(&ctxbuf, "ctx {d}%", .{contextPercent(meter.tokens, meter.window)}) catch "")
else
"";
- var ctxbuf: [80]u8 = undefined;
- var used_buf: [24]u8 = undefined;
- const ctx: []const u8 = if (st.context) |meter|
- (std.fmt.bufPrint(&ctxbuf, " · {s}/{d}k ctx ({d}% · compact@{d}k)", .{
- compactTokenCount(&used_buf, meter.tokens),
- meter.window / 1000,
- contextPercent(meter.tokens, meter.window),
- meter.compact_at / 1000,
- }) catch "")
+ var resumebuf: [24]u8 = undefined;
+ const resume_hint: []const u8 = if (st.saved_sessions > 0)
+ (std.fmt.bufPrint(&resumebuf, "/resume {d}", .{st.saved_sessions}) catch "")
else
"";
- // Budget the status line against terminal width so a narrow pane never
- // soft-wraps mid-badge (splitting e.g. `codex`) and strands the cursor
- // inside a label (#209). The model plus the badges that disambiguate the
- // cursor (effort/provider/mode/privacy) are offered first; cwd/context/
- // cache/cost are the first to drop when they no longer fit. readline.zig
- // still gives the input its own row if what remains is cramped. Byte
- // length (not display-column width) is used as the budget metric: for
- // UTF-8 it is always >= true display width, so the estimate only ever
- // errs conservative and can't itself cause an overflow/wrap.
- //
- // Reserve the fixed frame ('[' + '] › ' = 5 cols) plus 1 column of slack
- // so a width miscount can't tip the line into a wrap.
- const avail = cols -| 6;
+ // Dim meter above a bare `›`. Operational badges (Fast/Plan/Strict)
+ // stay; cwd and the old bracket frame do not — they competed with input.
+ // #209: drop from the right so a narrow pane never splits a label.
+ const avail = cols -| 1;
var used: usize = st.model.len;
const show_fast = st.fast and fitsSegment(&used, avail, 3 + "Fast".len);
const show_effort = st.effort != null and
fitsSegment(&used, avail, 3 + reasoningLabel(st.effort.?).len);
- const show_provider = fitsSegment(&used, avail, 3 + st.provider_id.len);
const show_fallback = st.fallback and
fitsSegment(&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_privacy = fitsSegment(&used, avail, 3 + st.privacy_label.len);
- // The context meter outranks cwd for the budget (it is the urgent,
- // changing signal near the compaction threshold) but still renders after
- // cwd below, preserving the familiar order when both fit.
- const show_ctx = ctx.len > 0 and fitsSegment(&used, avail, ctx.len);
- const show_cwd = fitsSegment(&used, avail, 7 + st.cwd.len);
- // cached only ever accompanies the context meter (both come from the
- // same response's usage payload), matching the pre-#209 layout.
- const show_cached = show_ctx and cached.len > 0 and fitsSegment(&used, avail, cached.len);
- const show_cost = cost.len > 0 and fitsSegment(&used, avail, cost.len);
-
- try w.print("{s}[{s}{s}{s}{s}", .{ style.dim, style.reset, style.accent, st.model, style.reset });
- // Fast is the most operationally important model setting, so keep it
- // immediately beside the model instead of letting permission modes push
- // it deeper into the status line.
- if (show_fast) try writeBadge(w, style.green, "Fast");
- if (show_effort) try writeBadge(w, reasoningColor(st.effort.?), reasoningLabel(st.effort.?));
- if (show_provider) try writeBadge(w, style.accent, st.provider_id);
- if (show_fallback) try writeBadge(w, style.yellow, "Fallback");
- if (show_plan) try writeBadge(w, style.yellow, "Plan");
- if (show_strict) try writeBadge(w, style.red, "Strict");
- if (show_ultra) try writeBadge(w, style.accent, "Ultracode");
- if (show_privacy) try writeBadge(w, privacyColor(st.privacy), st.privacy_label);
- try w.print("{s}", .{style.dim});
- if (show_cwd) try w.print(" · cwd {s}{s}{s}", .{ style.reset, st.cwd, style.dim });
- if (show_ctx) try w.print("{s}", .{ctx});
- if (show_cached) try w.print("{s}", .{cached});
- if (show_cost) try w.print("{s}", .{cost});
- try w.print("{s}]{s} {s}{s}›{s} ", .{ style.reset, style.reset, style.bold, style.accent, style.reset });
+ const show_ctx = ctx.len > 0 and fitsSegment(&used, avail, 3 + ctx.len);
+ const show_cost = cost.len > 0 and fitsSegment(&used, avail, 3 + cost.len);
+ const show_resume = resume_hint.len > 0 and fitsSegment(&used, avail, 3 + resume_hint.len);
+ const show_image = st.standing.image and fitsSegment(&used, avail, 3 + "image".len);
+ const show_session = st.standing.session.len > 0 and
+ fitsSegment(&used, avail, 3 + st.standing.session.len);
+
+ try w.print("{s}{s}", .{ style.dim, st.model });
+ if (show_fast) try w.print(" · Fast", .{});
+ if (show_effort) try w.print(" · {s}", .{reasoningLabel(st.effort.?)});
+ 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_cost) try w.print(" · {s}", .{cost});
+ if (show_resume) try w.print(" · {s}", .{resume_hint});
+ if (show_image) try w.print(" · image", .{});
+ if (show_session) try w.print(" · {s}", .{st.standing.session});
+ try w.print("{s}\n{s}{s}›{s} ", .{ style.reset, style.bold, style.accent, style.reset });
try w.flush();
}
@@ -330,15 +271,14 @@ test "batch 3: every status-line segment renders exactly as it did inline" {
.ultracode = true,
};
try std.testing.expectEqualStrings(
- "\n[gpt-5.6 · Fast · High · codex · Fallback · Plan · Strict · Ultracode · Privacy:Aggregate" ++
- " · cwd ~/src/graff · 12k/200k ctx (6% · compact@160k) · ⚡2k cached · $0.5000] › ",
+ "\ngpt-5.6 · Fast · High · Fallback · Plan · Strict · Ultracode · ctx 6% · $0.50\n› ",
renderPlain(&aw, full),
);
- // The bare line: no usage yet, no cache, meter off, no optional badge.
+ // The bare line: no usage yet, meter off, no optional badge.
aw.clearRetainingCapacity();
try std.testing.expectEqualStrings(
- "\n[lmstudio · lmstudio · Privacy:Local · cwd /w] › ",
+ "\nlmstudio\n› ",
renderPlain(&aw, .{
.model = "lmstudio",
.provider_id = "lmstudio",
@@ -352,7 +292,7 @@ test "batch 3: every status-line segment renders exactly as it did inline" {
// unpriced model admits it rather than printing a fabricated 0.0000.
aw.clearRetainingCapacity();
try std.testing.expectEqualStrings(
- "\n[m · p · Privacy:Local · cwd /w · sub] › ",
+ "\nm · sub\n› ",
renderPlain(&aw, .{
.model = "m",
.provider_id = "p",
@@ -364,7 +304,7 @@ test "batch 3: every status-line segment renders exactly as it did inline" {
);
aw.clearRetainingCapacity();
try std.testing.expectEqualStrings(
- "\n[m · p · Privacy:Local · cwd /w · $?] › ",
+ "\nm · $?\n› ",
renderPlain(&aw, .{
.model = "m",
.provider_id = "p",
@@ -397,16 +337,9 @@ test "batch 3: a shrinking pane sheds segments in the #209 priority order" {
.cost = .unpriced,
};
const cases = [_]struct { cols: usize, want: []const u8 }{
- // Roomy: everything, in the familiar order (cwd before the meter).
- .{ .cols = 130, .want = "\n[gpt-5.6 · High · codex · Privacy:Local · cwd ~/src/graff · 12k/200k ctx (6% · compact@160k) · ⚡2k cached · $?] › " },
- // Tighter: cwd is the first to go, but the meter it outranks stays.
- .{ .cols = 90, .want = "\n[gpt-5.6 · High · codex · Privacy:Local · 12k/200k ctx (6% · compact@160k) · $?] › " },
- // Cramped: the meter goes too, and the cache badge goes with it
- // rather than floating free of the usage it came from.
- .{ .cols = 50, .want = "\n[gpt-5.6 · High · codex · Privacy:Local · $?] › " },
- // Pathological: only the badges that disambiguate the cursor survive,
- // and never a half-drawn one.
- .{ .cols = 28, .want = "\n[gpt-5.6 · High · codex] › " },
+ .{ .cols = 80, .want = "\ngpt-5.6 · High · ctx 6% · $?\n› " },
+ .{ .cols = 28, .want = "\ngpt-5.6 · High · ctx 6%\n› " },
+ .{ .cols = 18, .want = "\ngpt-5.6 · High\n› " },
};
for (cases) |c| {
aw.clearRetainingCapacity();
@@ -435,7 +368,7 @@ test "batch 3: the cache badge rides with the context meter, never alone" {
try std.testing.expect(std.mem.indexOf(u8, out, "cached") == null);
}
-test "standing row sits above the model prompt and is skipped when empty" {
+test "WORKING block sits above a bare prompt and is skipped when empty" {
const saved = style.*;
style.* = .{};
defer style.* = saved;
@@ -449,11 +382,15 @@ test "standing row sits above the model prompt and is skipped when empty" {
.privacy = .local,
};
try std.testing.expectEqualStrings(
- "\n[m · p · Privacy:Local · cwd /w] › ",
+ "\nm\n› ",
renderPlain(&aw, bare),
);
aw.clearRetainingCapacity();
+ const items = [_]engine_events.StandingTodo{
+ .{ .content = "inspect current prompt", .done = true },
+ .{ .content = "update implementation", .done = false },
+ };
const full: PromptStatus = .{
.model = "m",
.provider_id = "p",
@@ -466,48 +403,15 @@ test "standing row sits above the model prompt and is skipped when empty" {
.goal_status = "paused",
.todos_done = 1,
.todos_total = 2,
+ .todos = &items,
.image = true,
},
};
- try line(&aw.writer, full, 100);
- try std.testing.expectEqualStrings(
- "\n Goal (paused) ship the repl standing line · 1/2 todos · image ready · login-fix\n" ++
- "[m · p · Privacy:Local · cwd /w] › ",
- aw.writer.buffered(),
- );
-}
-
-test "standing row drops session then image then todos on a narrow pane" {
- const saved = style.*;
- style.* = .{};
- 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",
- .privacy = .local,
- .standing = .{
- .session = "login-fix",
- .goal = "ship it",
- .todos_done = 1,
- .todos_total = 2,
- .image = true,
- },
- };
- // Room for Goal + checklist only (image + session drop). The model
- // badges still keep privacy at this width; cwd is the first to go.
- try line(&aw.writer, st, 36);
- try std.testing.expectEqualStrings(
- "\n Goal ship it · 1/2 todos\n[m · p · Privacy:Local · cwd /w] › ",
- aw.writer.buffered(),
- );
- aw.clearRetainingCapacity();
- try line(&aw.writer, st, 26);
+ try line(&aw.writer, full, 32);
+ const rule = "────────────────────────────────";
try std.testing.expectEqualStrings(
- "\n Goal ship it\n[m · p · cwd /w] › ",
+ "\n" ++ rule ++ "\nWORKING (paused)\nship the repl standing line\n1 of 2\n✓ inspect current prompt\n○ update implementation\n" ++
+ rule ++ "\nm · image · login-fix\n› ",
aw.writer.buffered(),
);
}
diff --git a/src/agent_tool_label.zig b/src/agent_tool_label.zig
new file mode 100644
index 00000000..737bc8d5
--- /dev/null
+++ b/src/agent_tool_label.zig
@@ -0,0 +1,223 @@
+//! Verb + detail + remembered args for line-REPL tool lines (variations 4+5).
+//! `bash` is never the label — the command (or a short verb) is.
+
+const std = @import("std");
+
+const engine_events = @import("engine_events.zig");
+const ToolInvocation = engine_events.ToolInvocation;
+
+pub const detail_preview_bytes: usize = 96;
+pub const result_preview_bytes: usize = 100;
+
+pub fn stringField(input: std.json.Value, field: []const u8) ?[]const u8 {
+ if (input != .object) return null;
+ const value = input.object.get(field) orelse return null;
+ return if (value == .string) value.string else null;
+}
+
+pub fn firstLine(s: []const u8) []const u8 {
+ const end = std.mem.indexOfScalar(u8, s, '\n') orelse s.len;
+ return std.mem.trim(u8, s[0..end], " \t\r");
+}
+
+pub fn firstToken(s: []const u8) []const u8 {
+ const line = firstLine(s);
+ const end = std.mem.indexOfAny(u8, line, " \t") orelse line.len;
+ return line[0..end];
+}
+
+pub fn newlineCount(s: []const u8) usize {
+ if (s.len == 0) return 0;
+ var n: usize = 1;
+ for (s) |c| {
+ if (c == '\n') n += 1;
+ }
+ if (s[s.len - 1] == '\n') n -= 1;
+ return n;
+}
+
+fn namedDetailField(name: []const u8, input: std.json.Value) ?[]const u8 {
+ if (std.mem.eql(u8, name, "bash") or std.mem.eql(u8, name, "codedb")) return "command";
+ if (std.mem.eql(u8, name, "read_file") or
+ std.mem.eql(u8, name, "write_file") or
+ std.mem.eql(u8, name, "edit_file")) return "path";
+ if (std.mem.eql(u8, name, "webfetch")) return "url";
+ if (std.mem.eql(u8, name, "subagent")) return "description";
+ if (std.mem.eql(u8, name, "imagegen")) return "prompt";
+ if (std.mem.eql(u8, name, "peer_message")) {
+ if (stringField(input, "action")) |act| {
+ if (act.len > 0 and !std.mem.eql(u8, act, "send")) return "action";
+ }
+ return "text";
+ }
+ if (std.mem.eql(u8, name, "workspace")) {
+ if (stringField(input, "path")) |p| if (p.len > 0) return "path";
+ return "action";
+ }
+ return null;
+}
+
+const fallback_fields = [_][]const u8{ "command", "path", "query", "url", "pattern", "file", "prompt", "uri", "text" };
+
+fn fallbackDetail(input: std.json.Value) []const u8 {
+ for (fallback_fields) |field| {
+ const raw = stringField(input, field) orelse continue;
+ const shown = firstLine(raw);
+ if (shown.len > 0) return shown;
+ }
+ return "";
+}
+
+fn addSpanDelta(old: []const u8, new: []const u8, plus: *usize, minus: *usize, spans: *usize) void {
+ plus.* += newlineCount(new);
+ minus.* += newlineCount(old);
+ spans.* += 1;
+}
+
+pub fn editDelta(input: std.json.Value, path: []const u8, buf: []u8) []const u8 {
+ var plus: usize = 0;
+ var minus: usize = 0;
+ var spans: usize = 0;
+ if (stringField(input, "old_string")) |old| {
+ if (stringField(input, "new_string")) |new| addSpanDelta(old, new, &plus, &minus, &spans);
+ }
+ if (input == .object) if (input.object.get("edits")) |v| if (v == .array) {
+ for (v.array.items) |item| {
+ const old = stringField(item, "old_string") orelse continue;
+ const new = stringField(item, "new_string") orelse continue;
+ addSpanDelta(old, new, &plus, &minus, &spans);
+ }
+ };
+ if (spans == 0) return path;
+ if (spans == 1)
+ return std.fmt.bufPrint(buf, "{s} · +{d}/-{d}", .{ path, plus, minus }) catch path;
+ return std.fmt.bufPrint(buf, "{s} · {d} spans · +{d}/-{d}", .{ path, spans, plus, minus }) catch path;
+}
+
+pub fn detail(t: ToolInvocation, buf: []u8) []const u8 {
+ if (std.mem.eql(u8, t.name, "edit_file")) {
+ const path = stringField(t.input, "path") orelse return "";
+ return editDelta(t.input, firstLine(path), buf);
+ }
+ if (namedDetailField(t.name, t.input)) |field| {
+ const raw = stringField(t.input, field) orelse return "";
+ return firstLine(raw);
+ }
+ return fallbackDetail(t.input);
+}
+
+fn copy(dst: []u8, src: []const u8) usize {
+ const n = @min(dst.len, src.len);
+ @memcpy(dst[0..n], src[0..n]);
+ return n;
+}
+
+/// Short verb the human reads. Never "bash".
+pub fn verb(name: []const u8, input: std.json.Value, buf: []u8) []const u8 {
+ if (std.mem.eql(u8, name, "bash")) {
+ const cmd = stringField(input, "command") orelse return "run";
+ const tok = firstToken(cmd);
+ if (std.mem.indexOf(u8, cmd, "test") != null) return "test";
+ if (tok.len > 0 and tok.len <= 12) {
+ const n = copy(buf, tok);
+ return buf[0..n];
+ }
+ return "run";
+ }
+ if (std.mem.eql(u8, name, "edit_file")) return "edit";
+ if (std.mem.eql(u8, name, "write_file")) return "write";
+ if (std.mem.eql(u8, name, "read_file")) return "read";
+ if (std.mem.eql(u8, name, "webfetch")) return "fetch";
+ if (std.mem.eql(u8, name, "codedb")) {
+ const cmd = stringField(input, "command") orelse return "search";
+ const tok = firstToken(cmd);
+ if (tok.len > 0) {
+ const n = copy(buf, tok);
+ return buf[0..n];
+ }
+ return "search";
+ }
+ if (std.mem.eql(u8, name, "subagent")) return "agent";
+ if (std.mem.eql(u8, name, "imagegen")) return "image";
+ if (std.mem.startsWith(u8, name, "mcp_")) {
+ const rest = name["mcp_".len..];
+ const n = copy(buf, if (rest.len > 12) rest[0..12] else rest);
+ return buf[0..n];
+ }
+ const n = copy(buf, if (name.len > 12) name[0..12] else name);
+ return buf[0..n];
+}
+
+const Pending = struct {
+ name: [64]u8 = undefined,
+ name_len: usize = 0,
+ verb: [16]u8 = undefined,
+ verb_len: usize = 0,
+ detail: [96]u8 = undefined,
+ detail_len: usize = 0,
+ used: bool = false,
+};
+
+fn emptyPending() [8]Pending {
+ var out: [8]Pending = undefined;
+ for (&out) |*p| p.* = .{};
+ return out;
+}
+
+var pending: [8]Pending = emptyPending();
+
+pub fn remember(name: []const u8, v: []const u8, d: []const u8) void {
+ var slot: ?*Pending = null;
+ for (&pending) |*p| {
+ if (!p.used) {
+ slot = p;
+ break;
+ }
+ }
+ if (slot == null) slot = &pending[0];
+ const p = slot.?;
+ p.used = true;
+ p.name_len = copy(&p.name, name);
+ p.verb_len = copy(&p.verb, v);
+ p.detail_len = copy(&p.detail, d);
+}
+
+pub const Remembered = struct { verb: []const u8, detail: []const u8 };
+
+pub fn take(name: []const u8) ?Remembered {
+ for (&pending) |*p| {
+ if (!p.used) continue;
+ if (!std.mem.eql(u8, p.name[0..p.name_len], name)) continue;
+ p.used = false;
+ return .{ .verb = p.verb[0..p.verb_len], .detail = p.detail[0..p.detail_len] };
+ }
+ return null;
+}
+
+pub fn resetPending() void {
+ for (&pending) |*p| p.used = false;
+}
+
+pub fn compactBash(line: []const u8, buf: []u8) []const u8 {
+ if (std.mem.startsWith(u8, line, "All ") and std.mem.endsWith(u8, line, " tests passed")) {
+ const n = line["All ".len .. line.len - " tests passed".len];
+ return std.fmt.bufPrint(buf, "{s} passed", .{n}) catch line;
+ }
+ return line;
+}
+
+test "verb never says bash" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ var buf: [16]u8 = undefined;
+ const input = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(), "{\"command\":\"zig build test\"}", .{});
+ try std.testing.expectEqualStrings("test", verb("bash", input, &buf));
+ try std.testing.expectEqualStrings("edit", verb("edit_file", .null, &buf));
+ try std.testing.expectEqualStrings("read", verb("read_file", .null, &buf));
+}
+
+test "compactBash keeps the count and drops the boilerplate" {
+ var buf: [24]u8 = undefined;
+ try std.testing.expectEqualStrings("1475 passed", compactBash("All 1475 tests passed", &buf));
+ try std.testing.expectEqualStrings("ok", compactBash("ok", &buf));
+}
diff --git a/src/agent_tool_render.zig b/src/agent_tool_render.zig
index 797ada20..43e606a2 100644
--- a/src/agent_tool_render.zig
+++ b/src/agent_tool_render.zig
@@ -36,123 +36,31 @@ const engine_events = @import("engine_events.zig");
const ToolInvocation = engine_events.ToolInvocation;
const ToolOutcome = engine_events.ToolOutcome;
const BatchOutcome = engine_events.BatchOutcome;
-
-/// Keep tool activity useful without dumping model-facing JSON into the REPL.
-const detail_preview_bytes: usize = 96;
-/// How much of a result's first line the ✓ line shows.
-const result_preview_bytes: usize = 100;
-
-fn stringField(input: std.json.Value, field: []const u8) ?[]const u8 {
- if (input != .object) return null;
- const value = input.object.get(field) orelse return null;
- return if (value == .string) value.string else null;
-}
-
-fn firstLine(s: []const u8) []const u8 {
- const end = std.mem.indexOfScalar(u8, s, '\n') orelse s.len;
- return std.mem.trim(u8, s[0..end], " \t\r");
-}
-
-fn newlineCount(s: []const u8) usize {
- if (s.len == 0) return 0;
- var n: usize = 1;
- for (s) |c| {
- if (c == '\n') n += 1;
- }
- if (s[s.len - 1] == '\n') n -= 1;
- return n;
-}
-
-/// MCP and unknown tools still get a one-liner when a common field is present.
-const fallback_fields = [_][]const u8{ "command", "path", "query", "url", "pattern", "file", "prompt", "uri", "text" };
-
-fn namedDetailField(name: []const u8, input: std.json.Value) ?[]const u8 {
- if (std.mem.eql(u8, name, "bash") or std.mem.eql(u8, name, "codedb")) return "command";
- if (std.mem.eql(u8, name, "read_file") or
- std.mem.eql(u8, name, "write_file") or
- std.mem.eql(u8, name, "edit_file")) return "path";
- if (std.mem.eql(u8, name, "webfetch")) return "url";
- if (std.mem.eql(u8, name, "subagent")) return "description";
- if (std.mem.eql(u8, name, "imagegen")) return "prompt";
- if (std.mem.eql(u8, name, "peer_message")) {
- if (stringField(input, "action")) |act| {
- if (act.len > 0 and !std.mem.eql(u8, act, "send")) return "action";
- }
- return "text";
- }
- if (std.mem.eql(u8, name, "workspace")) {
- if (stringField(input, "path")) |p| if (p.len > 0) return "path";
- return "action";
- }
- return null;
+const label = @import("agent_tool_label.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
+/// what shows fan-out (variation 4).
+var batch_left: usize = 0;
+
+fn treePrefix() []const u8 {
+ if (batch_left == 0) return " ";
+ const last = batch_left == 1;
+ batch_left -= 1;
+ return if (last) " └─ " else " ├─ ";
}
-fn fallbackDetail(input: std.json.Value) []const u8 {
- for (fallback_fields) |field| {
- const raw = stringField(input, field) orelse continue;
- const shown = firstLine(raw);
- if (shown.len > 0) return shown;
- }
- return "";
-}
-
-fn addSpanDelta(old: []const u8, new: []const u8, plus: *usize, minus: *usize, spans: *usize) void {
- plus.* += newlineCount(new);
- minus.* += newlineCount(old);
- spans.* += 1;
-}
-
-fn editDelta(input: std.json.Value, path: []const u8, buf: []u8) []const u8 {
- var plus: usize = 0;
- var minus: usize = 0;
- var spans: usize = 0;
- if (stringField(input, "old_string")) |old| {
- if (stringField(input, "new_string")) |new| addSpanDelta(old, new, &plus, &minus, &spans);
- }
- if (input == .object) if (input.object.get("edits")) |v| if (v == .array) {
- for (v.array.items) |item| {
- const old = stringField(item, "old_string") orelse continue;
- const new = stringField(item, "new_string") orelse continue;
- addSpanDelta(old, new, &plus, &minus, &spans);
- }
- };
- if (spans == 0) return path;
- if (spans == 1)
- return std.fmt.bufPrint(buf, "{s} · +{d}/-{d}", .{ path, plus, minus }) catch path;
- return std.fmt.bufPrint(buf, "{s} · {d} spans · +{d}/-{d}", .{ path, spans, plus, minus }) catch path;
-}
-
-/// One human-readable field (or an edit +N/-N). Never the raw argument object.
-fn toolDetail(t: ToolInvocation, buf: []u8) []const u8 {
- if (std.mem.eql(u8, t.name, "edit_file")) {
- const path = stringField(t.input, "path") orelse return "";
- return editDelta(t.input, firstLine(path), buf);
- }
- if (namedDetailField(t.name, t.input)) |field| {
- const raw = stringField(t.input, field) orelse return "";
- return firstLine(raw);
- }
- return fallbackDetail(t.input);
-}
-
-/// A terse activity line: always show ordinary tool calls, but never their raw
-/// argument object. Suppress only user-facing prose that already streamed live.
+/// Remember the call so the ✓ line can say `test` / `edit` instead of `bash`.
+/// Default session is result-only — announce lines doubled the visual weight.
pub fn toolUseLine(a: *Agent, t: ToolInvocation) void {
+ _ = a;
if (t.arg_streamed) return;
+ var vbuf: [16]u8 = undefined;
var dbuf: [128]u8 = undefined;
- const detail = toolDetail(t, &dbuf);
- const shown = if (detail.len > detail_preview_bytes) detail[0..detail_preview_bytes] else detail;
- var line: Io.Writer.Allocating = .init(a.gpa);
- defer line.deinit();
- line.writer.print("{s}⚙{s} {s}{s}{s}", .{ style.dim, style.reset, style.accent, t.name, style.reset }) catch return;
- if (shown.len > 0) line.writer.print("{s} · {s}{s}{s}", .{
- style.dim,
- shown,
- if (shown.len < detail.len) "…" else "",
- style.reset,
- }) catch return;
- line.writer.writeByte('\n') catch return;
- sayText(a, line.writer.buffered());
+ const v = label.verb(t.name, t.input, &vbuf);
+ const d = label.detail(t, &dbuf);
+ const shown = if (d.len > label.detail_preview_bytes) d[0..label.detail_preview_bytes] else d;
+ label.remember(t.name, v, shown);
}
/// The #440 marker prefixes forResult tags oversized results with. Detected
@@ -198,13 +106,14 @@ fn resultPreview(name: []const u8, all: []const u8, buf: []u8) Preview {
if (handleBadge(all) != null) return .{ .text = "", .clipped = false };
if (std.mem.startsWith(u8, all, handle_marker) or std.mem.startsWith(u8, all, truncated_marker))
return .{ .text = "", .clipped = false };
- const lines = newlineCount(all);
+ const lines = label.newlineCount(all);
if (std.mem.eql(u8, name, "read_file") and lines > 1) {
const text = std.fmt.bufPrint(buf, "{d} lines", .{lines}) catch all;
return .{ .text = text, .clipped = false };
}
- const raw = if (std.mem.eql(u8, name, "bash") and lines > 1) lastNonEmptyLine(all) else firstLine(all);
- if (raw.len > result_preview_bytes) return .{ .text = raw[0..result_preview_bytes], .clipped = true };
+ var raw = if (std.mem.eql(u8, name, "bash") and lines > 1) lastNonEmptyLine(all) else label.firstLine(all);
+ if (std.mem.eql(u8, name, "bash")) raw = label.compactBash(raw, buf);
+ if (raw.len > label.result_preview_bytes) return .{ .text = raw[0..label.result_preview_bytes], .clipped = true };
return .{ .text = raw, .clipped = false };
}
@@ -230,7 +139,6 @@ pub fn toolResultLine(a: *Agent, r: ToolOutcome) void {
(std.fmt.bufPrint(&tbuf, " ({d}ms)", .{r.ms}) catch "")
else
"";
- // Badge colors are self-contained; ordinary result lines stay byte-identical.
var bbuf: [48]u8 = undefined;
const badge = if (handleBadge(all)) |h| blk: {
const kib = @as(f64, @floatFromInt(h.bytes)) / 1024.0;
@@ -239,12 +147,16 @@ pub fn toolResultLine(a: *Agent, r: ToolOutcome) void {
else
std.fmt.bufPrint(&bbuf, "{s}⇢ {d:.1} KiB handle{s}", .{ style.accent, kib, style.reset }) catch "";
} else "";
- w.print(" {s}{s}{s} {s}{s}{s}{s}{s}{s}{s}{s}", .{
- mc, mark, style.reset, style.accent, r.name, style.reset, style.dim, timing,
- style.reset, if (badge.len > 0) " " else "", badge,
- }) catch return;
- if (shown.len > 0) w.print(" · {s}{s}", .{ shown, if (truncated) "…" else "" }) catch return;
- w.print("{s}\n", .{style.reset}) catch return;
+ const remembered = label.take(r.name);
+ const verb = if (remembered) |mem| mem.verb else r.name;
+ const detail = if (remembered) |mem| mem.detail else "";
+ 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.len > 0) w.print(" {s}{s}{s}{s}", .{ style.dim, shown, if (truncated) "…" else "", style.reset }) catch return;
+ w.writeAll("\n") catch return;
w.flush() catch return;
}
@@ -268,22 +180,20 @@ pub fn routedEffortLine(a: *Agent) void {
const notice_buf_bytes: usize = 192;
pub fn parallelBatchStarted(a: *Agent, count: usize) void {
- var buf: [notice_buf_bytes]u8 = undefined;
- const line = std.fmt.bufPrint(&buf, " {s}↯ {d} in parallel{s}\n", .{ style.dim, count, style.reset }) catch return;
- sayText(a, line);
+ _ = a;
+ batch_left = if (count >= 2) count else 0;
}
pub fn parallelBatchFinished(a: *Agent, o: BatchOutcome) void {
+ batch_left = 0;
+ if (o.failed == 0 and o.cancelled == 0) return;
var buf: [notice_buf_bytes]u8 = undefined;
- const total = o.done + o.failed + o.cancelled;
- const line = if (o.failed == 0 and o.cancelled == 0)
- std.fmt.bufPrint(&buf, " {s}↯ {d}/{d} done{s}\n", .{ style.dim, o.done, total, style.reset })
- else if (o.cancelled == 0)
- std.fmt.bufPrint(&buf, " {s}↯ {d} done · {d} failed{s}\n", .{ style.dim, o.done, o.failed, style.reset })
+ const line = if (o.cancelled == 0)
+ std.fmt.bufPrint(&buf, " {s}↯ {d} failed{s}\n", .{ style.dim, o.failed, style.reset })
else if (o.failed == 0)
- std.fmt.bufPrint(&buf, " {s}↯ {d} done · {d} cancelled{s}\n", .{ style.dim, o.done, o.cancelled, style.reset })
+ std.fmt.bufPrint(&buf, " {s}↯ {d} cancelled{s}\n", .{ style.dim, o.cancelled, style.reset })
else
- std.fmt.bufPrint(&buf, " {s}↯ {d} done · {d} failed · {d} cancelled{s}\n", .{ style.dim, o.done, o.failed, o.cancelled, style.reset });
+ std.fmt.bufPrint(&buf, " {s}↯ {d} failed · {d} cancelled{s}\n", .{ style.dim, o.failed, o.cancelled, style.reset });
sayText(a, line catch return);
}
@@ -306,6 +216,8 @@ pub fn toolTextLine(a: *Agent, text: []const u8) void {
}
fn testAgent(w: *Io.Writer) Agent {
+ batch_left = 0;
+ label.resetPending();
return .{
.gpa = std.testing.allocator,
.arena = std.testing.allocator,
@@ -319,13 +231,14 @@ fn testAgent(w: *Io.Writer) Agent {
};
}
-test "the ⚙ line reproduces the old inline announcement, cap and ellipsis included" {
+test "announce is silent and the ✓ line uses the remembered verb" {
const saved = ansi.style;
- ansi.style = .{}; // no color: assert the text, not the palette
+ ansi.style = .{};
defer ansi.style = saved;
- const saved_json = main_mod.json_mode; // sayText's root gate reads it
+ const saved_json = main_mod.json_mode;
main_mod.json_mode = false;
defer main_mod.json_mode = saved_json;
+ label.resetPending();
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
var aw: Io.Writer.Allocating = .init(std.testing.allocator);
@@ -334,32 +247,13 @@ test "the ⚙ line reproduces the old inline announcement, cap and ellipsis incl
const input = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(), "{\"path\":\"fixture.txt\"}", .{});
toolUseLine(&a, .{ .name = "read_file", .input = input });
- try std.testing.expectEqualStrings("⚙ read_file · fixture.txt\n", aw.writer.buffered());
+ 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());
- // Prose that already streamed live is not announced a second time.
aw.clearRetainingCapacity();
toolUseLine(&a, .{ .name = "attempt_completion", .input = input, .arg_streamed = true });
try std.testing.expectEqualStrings("", aw.writer.buffered());
-
- // Unknown tools stay visible; a common field becomes the one-liner, never JSON.
- aw.clearRetainingCapacity();
- toolUseLine(&a, .{ .name = "todo_write", .input = input });
- try std.testing.expectEqualStrings("⚙ todo_write · fixture.txt\n", aw.writer.buffered());
-
- aw.clearRetainingCapacity();
- const opaque_input = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(), "{\"foo\":1}", .{});
- toolUseLine(&a, .{ .name = "mystery_tool", .input = opaque_input });
- try std.testing.expectEqualStrings("⚙ mystery_tool\n", aw.writer.buffered());
-
- // Long readable details are capped to one terse line.
- aw.clearRetainingCapacity();
- const long = try std.fmt.allocPrint(arena_state.allocator(), "{{\"command\":\"{s}\"}}", .{&util.repeatBytes("x", 400)});
- const long_input = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(), long, .{});
- toolUseLine(&a, .{ .name = "bash", .input = long_input });
- const line = aw.writer.buffered();
- try std.testing.expect(std.mem.startsWith(u8, line, "⚙ bash · xxx"));
- try std.testing.expect(std.mem.endsWith(u8, line, "…\n"));
- try std.testing.expectEqual(@as(usize, 96), line.len - "⚙ bash · ".len - "…\n".len);
}
test "the result line marks success, failure and cancellation and previews one line" {
@@ -373,16 +267,17 @@ test "the result line marks success, failure and cancellation and previews one l
defer aw.deinit();
var a = testAgent(&aw.writer);
+ 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\n", aw.writer.buffered());
aw.clearRetainingCapacity();
toolResultLine(&a, .{ .name = "bash", .text = "boom", .is_error = true });
- try std.testing.expectEqualStrings(" ✗ bash · boom\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✗ bash boom\n", aw.writer.buffered());
aw.clearRetainingCapacity();
toolResultLine(&a, .{ .name = "bash", .text = "stopped", .is_error = true, .cancelled = true });
- try std.testing.expectEqualStrings(" ⊘ bash · stopped\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ⊘ bash stopped\n", aw.writer.buffered());
// Meta tools draw their own UX; the ✓ line stays out of their way.
aw.clearRetainingCapacity();
@@ -396,13 +291,12 @@ test "the result line marks success, failure and cancellation and previews one l
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.expectEqual(@as(usize, 100), rline.len - " ✓ bash ".len - "…\n".len);
- // --timing adds the measured duration between the mark and the preview.
aw.clearRetainingCapacity();
main_mod.show_timing = true;
toolResultLine(&a, .{ .name = "bash", .text = "ok", .is_error = false, .ms = 42 });
- try std.testing.expectEqualStrings(" ✓ bash (42ms) · ok\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ bash (42ms) ok\n", aw.writer.buffered());
// A #440 handle spill badges its size; the marker text stays off the line.
aw.clearRetainingCapacity();
@@ -450,15 +344,24 @@ test "batch tallies and meta notices render the old wording verbatim" {
var a = testAgent(&aw.writer);
parallelBatchStarted(&a, 3);
- try std.testing.expectEqualStrings(" ↯ 3 in parallel\n", aw.writer.buffered());
+ 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());
+ 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());
+ 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());
aw.clearRetainingCapacity();
parallelBatchFinished(&a, .{ .done = 2, .failed = 0, .cancelled = 0 });
- try std.testing.expectEqualStrings(" ↯ 2/2 done\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings("", aw.writer.buffered());
aw.clearRetainingCapacity();
parallelBatchFinished(&a, .{ .done = 2, .failed = 1, .cancelled = 0 });
- try std.testing.expectEqualStrings(" ↯ 2 done · 1 failed\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ↯ 1 failed\n", aw.writer.buffered());
aw.clearRetainingCapacity();
completionDeferred(&a);
@@ -491,9 +394,11 @@ test "unknown tools pick a readable field instead of staying name-only" {
defer aw.deinit();
var a = testAgent(&aw.writer);
+ label.resetPending();
const q = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(), "{\"query\":\"standing line\"}", .{});
toolUseLine(&a, .{ .name = "mcp_search", .input = q });
- try std.testing.expectEqualStrings("⚙ mcp_search · standing line\n", aw.writer.buffered());
+ toolResultLine(&a, .{ .name = "mcp_search", .text = "4 matches", .is_error = false });
+ try std.testing.expectEqualStrings(" ✓ search standing line 4 matches\n", aw.writer.buffered());
}
test "edit_file one-liner includes a +N/-N delta" {
@@ -512,15 +417,10 @@ test "edit_file one-liner includes a +N/-N delta" {
const one = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(),
\\{"path":"src/a.zig","old_string":"a\nb","new_string":"a\nb\nc"}
, .{});
+ label.resetPending();
toolUseLine(&a, .{ .name = "edit_file", .input = one });
- try std.testing.expectEqualStrings("⚙ edit_file · src/a.zig · +3/-2\n", aw.writer.buffered());
-
- aw.clearRetainingCapacity();
- const batch = try std.json.parseFromSliceLeaky(std.json.Value, arena_state.allocator(),
- \\{"path":"src/a.zig","edits":[{"old_string":"x","new_string":"x\ny"},{"old_string":"z\nz","new_string":"z"}]}
- , .{});
- toolUseLine(&a, .{ .name = "edit_file", .input = batch });
- try std.testing.expectEqualStrings("⚙ edit_file · src/a.zig · 2 spans · +3/-3\n", aw.writer.buffered());
+ 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 applied 1 edit span(s) to src/a.zig (each verified)\n", aw.writer.buffered());
}
test "bash result prefers the last line of a multi-line run" {
@@ -536,5 +436,5 @@ 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 · All 1475 tests passed\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ bash 1475 passed\n", aw.writer.buffered());
}
diff --git a/src/engine_events.zig b/src/engine_events.zig
index 4ada0f22..d421db0c 100644
--- a/src/engine_events.zig
+++ b/src/engine_events.zig
@@ -204,10 +204,16 @@ pub const ContextMeter = struct {
compact_at: u64,
};
+/// One current-epoch checklist row for the git-style WORKING block.
+pub const StandingTodo = struct {
+ content: []const u8 = "",
+ done: bool = false,
+};
+
/// Standing work the line REPL may draw above the model prompt. Empty
-/// strings and zeros mean "nothing to show" so a sink can skip the row.
+/// strings and zeros mean "nothing to show" so a sink can skip the block.
/// The engine snapshots facts the session already holds; the sink decides
-/// order, clip, and whether the row exists at all.
+/// order, clip, and whether the block exists at all.
pub const StandingWork = struct {
/// Human title, or a non-default session name. Empty = untitled `last`.
session: []const u8 = "",
@@ -218,6 +224,9 @@ pub const StandingWork = struct {
/// Current-epoch checklist. `todos_total == 0` means no list to show.
todos_done: u32 = 0,
todos_total: u32 = 0,
+ /// Current-epoch items in list order, already clipped. May be shorter
+ /// than `todos_total` when the snapshot capped the block.
+ todos: []const StandingTodo = &.{},
/// `/image` or Ctrl-V staged a picture for the next send.
image: bool = false,
};
@@ -249,6 +258,8 @@ pub const PromptStatus = struct {
strict: bool = false,
ultracode: bool = false,
standing: StandingWork = .{},
+ /// Saved conversations in `.graff/sessions` (0 = none / don't mention).
+ saved_sessions: u32 = 0,
};
/// Everything the streaming path tells a frontend. Each doc comment states
diff --git a/src/engine_sink_tests.zig b/src/engine_sink_tests.zig
index 97b2702e..7f784722 100644
--- a/src/engine_sink_tests.zig
+++ b/src/engine_sink_tests.zig
@@ -282,15 +282,15 @@ 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_file · fixture.txt\n ✓ read_file · 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines\n", aw.writer.buffered());
aw.clearRetainingCapacity();
s.emit(undefined, .{ .tool_call_announced = call });
- s.emit(undefined, .{ .tool_call_started = call }); // silent: the ⚙ line already said it
+ s.emit(undefined, .{ .tool_call_started = call }); // silent: the ✓ line is the record
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_file · fixture.txt\n ✓ read_file · 2 lines\n", aw.writer.buffered());
+ try std.testing.expectEqualStrings(" ✓ read fixture.txt 2 lines\n", aw.writer.buffered());
}
test "TuiSink renders a plain text delta exactly as the no-color TTY did" {
diff --git a/src/session_render.zig b/src/session_render.zig
index 08c1357f..0637ec7d 100644
--- a/src/session_render.zig
+++ b/src/session_render.zig
@@ -29,9 +29,6 @@ const EngineEvent = engine_events.EngineEvent;
/// The `-w` line's suffix when the session will checkpoint each turn.
const autocommit_suffix = " · auto-committing each turn (`graff worktree merge` to land it)";
-/// What the startup banner says a session can do. Frontend knowledge: these
-/// are this TUI's keys, and a different client's would differ.
-const banner_hints = " · / for commands · @ picks a file · esc interrupts · ↑/↓ history · tab completes · ctrl-d quits · trace → ";
/// Startup found a color-capable terminal. A capability handshake rather than
/// an event — nothing has been drawn yet — but the palette is this half's own
@@ -47,8 +44,8 @@ pub fn enableColor() void {
pub fn emit(w: ?*Io.Writer, ev: EngineEvent) void {
switch (ev) {
.session_notice => |n| notice(w, n),
- .session_banner => |b| line(w, "{s}codegraff{s} · folder: {s}{s}{s}" ++ banner_hints ++ "{s}\n", .{
- style.bold, style.reset, style.accent, b.cwd, style.reset, b.trace_path,
+ .session_banner => |b| line(w, "{s}codegraff{s} {s}{s}{s}\n", .{
+ style.bold, style.reset, style.accent, b.cwd, style.reset,
}),
.worktree_entered => |t| line(w, "{s}worktree:{s} {s}{s}{s} (branch {s}) — edits isolated from the main checkout{s}\n", .{
style.dim, style.reset, style.accent, t.path, style.reset, t.branch,
@@ -166,7 +163,7 @@ test "slice 2: the startup lines render exactly as the inline prints did" {
defer aw.deinit();
try std.testing.expectEqualStrings(
- "codegraff · folder: /repo · / for commands · @ picks a file · esc interrupts · ↑/↓ history · tab completes · ctrl-d quits · trace → .graff/traces/ab.jsonl\n",
+ "codegraff /repo\n",
renderTest(&aw, .{ .session_banner = .{ .cwd = "/repo", .trace_path = ".graff/traces/ab.jsonl" } }),
);
try std.testing.expectEqualStrings(
diff --git a/src/session_start.zig b/src/session_start.zig
index 45c51e90..ea08f093 100644
--- a/src/session_start.zig
+++ b/src/session_start.zig
@@ -59,7 +59,6 @@ const repl = @import("repl.zig");
const repl_glue = @import("repl_glue.zig");
const messages_mod = @import("messages.zig");
const session = @import("session.zig");
-const session_index = @import("session_index.zig");
/// `graff title <prompt>` — print the tab-title the model would generate for
/// that prompt (one title call, no session). For A/B-ing title prompts/styles.
@@ -150,9 +149,6 @@ pub fn setupWorktreeAndBanner(
// `graff tui --yolo` look like bare `graff` never left.
if (!main_mod.json_mode and flags.oneshot_prompt == null and !flags.isPager()) {
sink.emit(io, .{ .session_banner = .{ .cwd = main_mod.g_cwd_display, .trace_path = trace_path } });
- var hint_buf: [72]u8 = undefined;
- const hint = session_index.savedSessionsHint(session_index.countSavedSessions(io), &hint_buf);
- if (hint.len > 0) sink.emit(io, .{ .session_notice = .{ .text = try arena.dupe(u8, hint), .tone = .dim } });
if (environ_map.get("GRAFF_REPL_DEBUG") != null) if (codex_account) |acct| sink.emit(io, .{ .session_notice = .{
.text = try std.fmt.allocPrint(arena, "logged into Codex (ChatGPT account {s}…) — /model codex", .{acct[0..@min(acct.len, 8)]}),
} });