Skip to content

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

Python

feat(repl): show standing work above the line-REPL prompt

Cursor Agent850a8387027e
diff --git a/src/agent_prompt.zig b/src/agent_prompt.zig
index 929818c9..b86c5bda 100644
--- a/src/agent_prompt.zig
+++ b/src/agent_prompt.zig
@@ -14,10 +14,12 @@ const learning_privacy = @import("learning_privacy.zig");
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 Agent = agent_mod.Agent;
/// The interactive status line printed before each human turn: model,
-/// mode/permission badges, cwd, and the live context/cache/cost meter.
+/// mode/permission badges, cwd, the live context/cache/cost meter, and
+/// (when present) a standing-work row for goal / todos / image / session.
pub fn prompt(self: *Agent) !void {
if (main_mod.json_mode) return; // SDK drives turns; no human prompt
if (self.out == null) return; // nothing to draw on
@@ -51,9 +53,41 @@ fn status(self: *Agent) engine_events.PromptStatus {
.plan = main_mod.plan_mode,
.strict = self.strict,
.ultracode = self.ultracode_mode,
+ .standing = standing(self),
};
}
+/// Facts the prompt row itself never carried: a standing goal, its
+/// checklist, a staged image, a named session. Empty means skip the row.
+fn standing(self: *const Agent) engine_events.StandingWork {
+ var out: engine_events.StandingWork = .{};
+ if (self.session_title) |t| {
+ if (t.len > 0) out.session = t;
+ }
+ if (out.session.len == 0 and self.session_name.len > 0 and
+ !std.mem.eql(u8, self.session_name, "last"))
+ out.session = self.session_name;
+ if (self.goal) |g| {
+ if (g.status != .complete and g.objective.len > 0) {
+ out.goal = g.objective;
+ out.goal_status = switch (g.status) {
+ .active => "",
+ .paused => "paused",
+ .blocked => "blocked",
+ .complete => "",
+ };
+ }
+ }
+ const epoch = goal_state.currentEpoch(self.goal);
+ 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;
+ }
+ out.image = self.pending_image != null;
+ return out;
+}
+
/// Same order of questions the inline meter asked: off, then flat-rate, then
/// unpriced, and only then is a real figure snapshotted.
fn cost(self: *Agent) engine_events.CostMeter {
@@ -150,3 +184,56 @@ test "kimi effort badge names the normalized wire effort, not the raw knob" {
agent.provider.model = "unknown-xyz";
try std.testing.expectEqual(@as(?engine_events.ReasoningEffort, null), effectiveEffort(&agent));
}
+
+test "standing work snapshots goal, checklist, session, and a staged image" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const arena = arena_state.allocator();
+ var agent: Agent = .{
+ .gpa = std.testing.allocator,
+ .arena = arena,
+ .io = std.testing.io,
+ .client = undefined,
+ .provider = .{ .id = "xai", .kind = .openai, .auth = .bearer, .url = "", .api_key = "", .model = "grok-4", .context = 200_000 },
+ .messages = std.json.Array.init(arena),
+ .sub = false,
+ .label = "",
+ .out = null,
+ .sys_normal = "",
+ };
+ defer agent.todos.deinit(agent.gpa);
+
+ // Default session `last` and no goal: the standing row stays empty.
+ var sw = standing(&agent);
+ try std.testing.expectEqualStrings("", sw.session);
+ try std.testing.expectEqualStrings("", sw.goal);
+ try std.testing.expectEqual(@as(u32, 0), sw.todos_total);
+ try std.testing.expect(!sw.image);
+
+ agent.session_name = "login-fix";
+ agent.session_title = "fix the login flash";
+ agent.goal = .{ .objective = "ship the repl standing line", .status = .paused, .epoch = 1 };
+ try agent.todos.append(agent.gpa, .{ .content = "done item", .status = "completed", .epoch = 1 });
+ try agent.todos.append(agent.gpa, .{ .content = "open item", .status = "pending", .epoch = 1 });
+ try agent.todos.append(agent.gpa, .{ .content = "parked other goal", .status = "pending", .epoch = 0 });
+ try agent.todos.append(agent.gpa, .{ .content = "retired", .status = "completed", .epoch = 1, .retired = true });
+ agent.pending_image = .{ .media_type = "image/png", .b64 = "xx", .label = "shot.png" };
+
+ sw = standing(&agent);
+ try std.testing.expectEqualStrings("fix the login flash", sw.session);
+ try std.testing.expectEqualStrings("ship the repl standing line", sw.goal);
+ 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.expect(sw.image);
+
+ // A completed goal is not standing work; the default session name stays hidden.
+ agent.goal.?.status = .complete;
+ agent.session_title = null;
+ agent.session_name = "last";
+ agent.pending_image = null;
+ sw = standing(&agent);
+ try std.testing.expectEqualStrings("", sw.goal);
+ try std.testing.expectEqualStrings("", sw.session);
+ try std.testing.expect(!sw.image);
+}
diff --git a/src/agent_prompt_render.zig b/src/agent_prompt_render.zig
index de5989b4..b4544a2e 100644
--- a/src/agent_prompt_render.zig
+++ b/src/agent_prompt_render.zig
@@ -17,6 +17,7 @@ const Io = std.Io;
const style = &@import("ansi.zig").style;
const terminal = @import("term.zig");
const engine_events = @import("engine_events.zig");
+const util = @import("util.zig");
const PromptStatus = engine_events.PromptStatus;
pub fn reasoningLabel(effort: anytype) []const u8 {
@@ -89,7 +90,67 @@ 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;
+}
+
+/// 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;
+ 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;
+ }
+ var todo_buf: [24]u8 = undefined;
+ if (sw.todos_total > 0) {
+ parts[n] = std.fmt.bufPrint(&todo_buf, "{d}/{d}", .{ 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}\n", .{style.reset});
+}
+
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;
const cost: []const u8 = switch (st.cost) {
.hidden => "",
@@ -150,7 +211,7 @@ fn line(w: *Io.Writer, st: PromptStatus, cols: usize) !void {
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("\n{s}[{s}{s}{s}{s}", .{ style.dim, style.reset, style.accent, st.model, style.reset });
+ 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.
@@ -373,3 +434,73 @@ 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" {
+ const saved = style.*;
+ style.* = .{};
+ defer style.* = saved;
+ var aw: Io.Writer.Allocating = .init(std.testing.allocator);
+ defer aw.deinit();
+ const bare: PromptStatus = .{
+ .model = "m",
+ .provider_id = "p",
+ .cwd = "/w",
+ .privacy_label = "Privacy:Local",
+ .privacy = .local,
+ };
+ try std.testing.expectEqualStrings(
+ "\n[m · p · Privacy:Local · cwd /w] › ",
+ renderPlain(&aw, bare),
+ );
+
+ aw.clearRetainingCapacity();
+ const out = renderPlain(&aw, .{
+ .model = "m",
+ .provider_id = "p",
+ .cwd = "/w",
+ .privacy_label = "Privacy:Local",
+ .privacy = .local,
+ .standing = .{
+ .session = "login-fix",
+ .goal = "ship the repl standing line",
+ .goal_status = "paused",
+ .todos_done = 1,
+ .todos_total = 2,
+ .image = true,
+ },
+ });
+ try std.testing.expectEqualStrings(
+ "\n Goal (paused) ship the repl standing line · 1/2 · image ready · login-fix\n" ++
+ "[m · p · Privacy:Local · cwd /w] › ",
+ out,
+ );
+}
+
+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, 28);
+ try std.testing.expectEqualStrings(
+ "\n Goal ship it · 1/2\n[m · p · Privacy:Local] › ",
+ aw.writer.buffered(),
+ );
+}
diff --git a/src/engine_events.zig b/src/engine_events.zig
index a8fcc28e..4ada0f22 100644
--- a/src/engine_events.zig
+++ b/src/engine_events.zig
@@ -204,6 +204,24 @@ pub const ContextMeter = struct {
compact_at: u64,
};
+/// 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.
+/// The engine snapshots facts the session already holds; the sink decides
+/// order, clip, and whether the row exists at all.
+pub const StandingWork = struct {
+ /// Human title, or a non-default session name. Empty = untitled `last`.
+ session: []const u8 = "",
+ /// Live standing goal (not complete). Empty = none.
+ goal: []const u8 = "",
+ /// Lifecycle when the goal is not the default active: "paused" / "blocked".
+ goal_status: []const u8 = "",
+ /// Current-epoch checklist. `todos_total == 0` means no list to show.
+ todos_done: u32 = 0,
+ todos_total: u32 = 0,
+ /// `/image` or Ctrl-V staged a picture for the next send.
+ image: bool = false,
+};
+
/// Everything the status line printed before a human turn actually says.
/// Deliberately semantic: no widths, no colors, no assembled segments. Which
/// badges survive a narrow pane is a rendering decision (#209) and belongs to
@@ -230,6 +248,7 @@ pub const PromptStatus = struct {
plan: bool = false,
strict: bool = false,
ultracode: bool = false,
+ standing: StandingWork = .{},
};
/// Everything the streaming path tells a frontend. Each doc comment states