Skip to content

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

Python

fix: #716 typed TUI /goal is retirable, not a standing session flag

Cursor Agent9c916c13d6c1
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 994d3c43..0e55cf9d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,9 @@ current is part of cutting a release.
mention, not the whole history. A host re-submit that ends on the
same user row is skipped; three copies fail closed as stuck replay.
The same words after an answer still run.
+- `#716`: fullscreen `/goal` uses the shared lifecycle (set / pause /
+ resume / clear). A typed TUI goal is not standing, so recorded
+ completion retires it and `/resume` does not steer the next prompt.
- The gateway is a fallback seat, not the startup default.
- No tag until asked.
diff --git a/TUI/catalog.zig b/TUI/catalog.zig
index 0e47f134..a8dc3d5b 100644
--- a/TUI/catalog.zig
+++ b/TUI/catalog.zig
@@ -31,7 +31,7 @@ pub const items = [_]Item{
.{ .name = "/compact-mode", .desc = "Tighter padding" },
.{ .name = "/plan", .desc = "Toggle plan mode" },
.{ .name = "/theme", .desc = "Switch color theme", .aliases = &.{"/t"} },
- .{ .name = "/goal", .desc = "Set a standing objective" },
+ .{ .name = "/goal", .desc = "Set, pause, resume, or clear a goal" },
.{ .name = "/schedule", .desc = "Fire a prompt later (30s/5m/2h)" },
.{ .name = "/adapter", .desc = "Channel-worker send / inbox" },
.{ .name = "/thinking", .desc = "Show live reasoning" },
diff --git a/TUI/dispatch.zig b/TUI/dispatch.zig
index fadba2fc..49b3452c 100644
--- a/TUI/dispatch.zig
+++ b/TUI/dispatch.zig
@@ -164,10 +164,7 @@ pub fn runCommand(self: *Model, line: []const u8) Effect {
publishState(self);
self.pushFmt(.system, "strict: {s}", .{onOff(self.strict)}) catch {};
} else if (std.mem.eql(u8, canon, "/goal")) {
- if (self.goal) |g| self.alloc.free(g);
- self.goal = if (arg.len > 0) (self.alloc.dupe(u8, arg) catch null) else null;
- publishState(self);
- if (self.goal) |g| self.pushFmt(.system, "goal set: {s}", .{g}) catch {} else self.push(.system, "goal cleared") catch {};
+ applyGoal(self, arg);
} else if (std.mem.eql(u8, canon, "/rename")) {
if (self.session_name) |s| self.alloc.free(s);
self.session_name = if (arg.len > 0) (self.alloc.dupe(u8, arg) catch null) else null;
@@ -234,14 +231,59 @@ pub fn runCommand(self: *Model, line: []const u8) Effect {
}
fn publishState(self: *Model) void {
+ publishStateOp(self, .none);
+}
+
+fn publishStateOp(self: *Model, op: engine.GoalOp) void {
if (engine.g_state_fn) |f| f(engine.g_turn_ctx, .{
.session_name = self.session_name orelse "",
.goal = self.goal orelse "",
.strict = self.strict,
.ultracode = self.ultracode,
+ .goal_op = op,
});
}
+/// Line-REPL `/goal` verbs (`status`/`pause`/`resume`/`clear`), not a raw
+/// objective string. `/goal pause` used to mint a standing goal named "pause".
+fn applyGoal(self: *Model, raw: []const u8) void {
+ const verb = std.mem.trim(u8, raw, " \t\r\n");
+ if (verb.len == 0 or std.ascii.eqlIgnoreCase(verb, "status")) {
+ if (self.goal) |g|
+ self.pushFmt(.system, "Goal: {s}. Commands: /goal pause | resume | clear.", .{g}) catch {}
+ else
+ self.push(.system, "No active goal. Set one with /goal <objective>.") catch {};
+ return;
+ }
+ if (std.ascii.eqlIgnoreCase(verb, "clear") or std.ascii.eqlIgnoreCase(verb, "off")) {
+ if (self.goal) |g| self.alloc.free(g);
+ self.goal = null;
+ publishStateOp(self, .clear);
+ self.push(.system, "goal cleared") catch {};
+ return;
+ }
+ if (std.ascii.eqlIgnoreCase(verb, "pause")) {
+ publishStateOp(self, .pause);
+ if (self.goal) |g|
+ self.pushFmt(.system, "goal paused: {s}", .{g}) catch {}
+ else
+ self.push(.system, "No active goal to pause. Set one with /goal <objective>.") catch {};
+ return;
+ }
+ if (std.ascii.eqlIgnoreCase(verb, "resume")) {
+ publishStateOp(self, .unpause);
+ if (self.goal) |g|
+ self.pushFmt(.system, "goal resumed: {s}", .{g}) catch {}
+ else
+ self.push(.system, "No goal to resume. Set one with /goal <objective>.") catch {};
+ return;
+ }
+ if (self.goal) |g| self.alloc.free(g);
+ self.goal = self.alloc.dupe(u8, verb) catch null;
+ publishStateOp(self, .set);
+ if (self.goal) |g| self.pushFmt(.system, "goal set: {s}", .{g}) catch {};
+}
+
/// `!cmd` — run a shell line locally (grok-style bash mode) on a background
/// thread, so a slow command no longer freezes the frame for its whole 20s
/// cap (#533). Output stays out of the model history: EntryKind.system never
diff --git a/TUI/dispatch_command_tests.zig b/TUI/dispatch_command_tests.zig
index fd361753..96078ed8 100644
--- a/TUI/dispatch_command_tests.zig
+++ b/TUI/dispatch_command_tests.zig
@@ -276,6 +276,64 @@ test "/btw queues an aside while a turn is pending" {
try std.testing.expectEqualStrings("remember the tests", m.steer_queue.items[0]);
}
+var captured_op: engine.GoalOp = .none;
+var captured_goal: []const u8 = "";
+var publish_count: u32 = 0;
+
+fn captureGoal(_: ?*anyopaque, state: engine.SessionState) void {
+ captured_op = state.goal_op;
+ captured_goal = state.goal;
+ publish_count += 1;
+}
+
+test "/goal pause and clear are lifecycle verbs, not objectives (#716)" {
+ var m: Model = undefined;
+ m.setup(std.testing.allocator);
+ defer m.deinit();
+ engine.g_state_fn = captureGoal;
+ defer engine.g_state_fn = null;
+ publish_count = 0;
+
+ _ = applyLine(&m, "/goal ship it");
+ try std.testing.expectEqualStrings("ship it", m.goal.?);
+ try std.testing.expectEqual(engine.GoalOp.set, captured_op);
+ try std.testing.expectEqualStrings("ship it", captured_goal);
+
+ _ = applyLine(&m, "/goal pause");
+ try std.testing.expectEqualStrings("ship it", m.goal.?);
+ try std.testing.expectEqual(engine.GoalOp.pause, captured_op);
+ const paused = m.history.items[m.history.items.len - 1].text;
+ try std.testing.expect(std.mem.indexOf(u8, paused, "paused") != null);
+
+ _ = applyLine(&m, "/goal clear");
+ try std.testing.expect(m.goal == null);
+ try std.testing.expectEqual(engine.GoalOp.clear, captured_op);
+ try std.testing.expectEqualStrings("", captured_goal);
+}
+
+test "/goal status and bare /goal do not publish an objective (#716)" {
+ var m: Model = undefined;
+ m.setup(std.testing.allocator);
+ defer m.deinit();
+ engine.g_state_fn = captureGoal;
+ defer engine.g_state_fn = null;
+ publish_count = 0;
+
+ _ = applyLine(&m, "/goal");
+ try std.testing.expectEqual(@as(u32, 0), publish_count);
+ try std.testing.expect(m.goal == null);
+ const bare = m.history.items[m.history.items.len - 1].text;
+ try std.testing.expect(std.mem.indexOf(u8, bare, "No active goal") != null);
+
+ _ = applyLine(&m, "/goal ship it");
+ const after_set = publish_count;
+ _ = applyLine(&m, "/goal status");
+ try std.testing.expectEqual(after_set, publish_count);
+ try std.testing.expectEqualStrings("ship it", m.goal.?);
+ const status = m.history.items[m.history.items.len - 1].text;
+ try std.testing.expect(std.mem.indexOf(u8, status, "ship it") != null);
+}
+
test "lastLines caps ! output to the tail" {
try std.testing.expectEqualStrings("c\nd", lastLines("a\nb\nc\nd", 2));
try std.testing.expectEqualStrings("a\nb", lastLines("a\nb", 5));
diff --git a/TUI/engine.zig b/TUI/engine.zig
index 962efd57..5bbe84eb 100644
--- a/TUI/engine.zig
+++ b/TUI/engine.zig
@@ -154,11 +154,17 @@ pub const CompactFn = *const fn (turn_ctx: ?*anyopaque, gpa: std.mem.Allocator,
pub const HistoryOp = enum { reset, rewind };
pub const HistoryFn = *const fn (turn_ctx: ?*anyopaque, op: HistoryOp) void;
+/// Host-side `/goal` verb. `.none` is a snapshot (strict/ultracode/rename):
+/// the host must not re-apply or mint a goal. Typed TUI `/goal` is the same
+/// retirable lifecycle as the line REPL — never a standing `--goal` (#716).
+pub const GoalOp = enum { none, set, clear, pause, unpause };
+
pub const SessionState = struct {
session_name: []const u8 = "",
goal: []const u8 = "",
strict: bool = false,
ultracode: bool = false,
+ goal_op: GoalOp = .none,
};
pub const StateFn = *const fn (turn_ctx: ?*anyopaque, state: SessionState) void;
diff --git a/TUI/root.zig b/TUI/root.zig
index 1e330948..738c4302 100644
--- a/TUI/root.zig
+++ b/TUI/root.zig
@@ -38,6 +38,7 @@ pub const HistoryFn = engine.HistoryFn;
pub const ResumeOut = engine.ResumeOut;
pub const ResumeFn = engine.ResumeFn;
pub const SessionState = engine.SessionState;
+pub const GoalOp = engine.GoalOp;
pub const StateFn = engine.StateFn;
pub const PeerFn = engine.PeerFn;
pub const RunOpts = run_mod.RunOpts;
diff --git a/docs/releases/v0.0.284.md b/docs/releases/v0.0.284.md
index fb54da09..1732af72 100644
--- a/docs/releases/v0.0.284.md
+++ b/docs/releases/v0.0.284.md
@@ -53,7 +53,16 @@ message re-armed the gate on every later completion, and
when it was already the latest ask. The gate is now per unanswered
mention. Identical user injects are skipped; three copies fail closed.
+## Fullscreen `/goal` retires on completion (#716)
+
+A typed TUI `/goal` was published as a standing session flag, so
+`attempt_completion` recorded the finish and left the objective
+active. `/resume` restored it and the next unrelated prompt was
+steered toward finished work. The pager now sends `status` / `pause` /
+`resume` / `clear` through the same lifecycle as the line REPL;
+typed goals stay non-standing.
+
## Tests
-Suite floor stays **1882**. This fold adds the #711 / #712 / #714
-cases on top of the ACP-image and #708 work already on the branch.
+Suite floor stays **1882**. This fold adds the #711 / #712 / #714 /
+#716 cases on top of the ACP-image and #708 work already on the branch.
diff --git a/src/cli.zig b/src/cli.zig
index 450f701d..92ac16d8 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -27,6 +27,7 @@ pub const changelog_text =
\\ • parallel error bash results stay valid JSON on the next Codex request (#711)
\\ • /resume and /sessions find ~/.graff/sessions, not just cwd (#712)
\\ • named-source gate is per mention; identical user turns do not replay (#714)
+ \\ • fullscreen /goal is retirable; completion no longer resumes stale steering (#716)
\\
\\0.0.283
\\ • deleted composer image chips reuse #N; paste traces omit MIME/bytes until send (#702)
diff --git a/src/repl_turn.zig b/src/repl_turn.zig
index 23bff5a4..cef699bb 100644
--- a/src/repl_turn.zig
+++ b/src/repl_turn.zig
@@ -136,7 +136,9 @@ fn seedSessionState(c: *ReplCtx, agent: *Agent, arena: Allocator, goal_text: []c
}
}
const now = util.unixMs(agent.io);
- agent.goal = .{ .objective = try arena.dupe(u8, goal_text), .epoch = if (root.goal) |g| g.epoch + 1 else 1, .standing = true, .created_ms = now, .updated_ms = now };
+ // A TUI-typed goal that has not yet landed on root is still a task,
+ // not `--goal`. Minting standing here is how #716 resumed stale steering.
+ agent.goal = .{ .objective = try arena.dupe(u8, goal_text), .epoch = if (root.goal) |g| g.epoch + 1 else 1, .created_ms = now, .updated_ms = now };
}
}
diff --git a/src/test_hooks.zig b/src/test_hooks.zig
index 5ac03076..f7f13ef2 100644
--- a/src/test_hooks.zig
+++ b/src/test_hooks.zig
@@ -351,5 +351,6 @@ test {
_ = @import("commands_resume.zig"); // #697: --resume SOURCE --branch DEST parser
_ = @import("session_list.zig"); // #712: device-wide saved-session listing
_ = @import("turn_dedup.zig"); // #714: identical user turns do not replay
+ _ = @import("tui_goal.zig"); // #716: typed TUI /goal is retirable, not standing
_ = @import("net_efficiency_test.zig");
}
diff --git a/src/tui_goal.zig b/src/tui_goal.zig
new file mode 100644
index 00000000..85a7f734
--- /dev/null
+++ b/src/tui_goal.zig
@@ -0,0 +1,151 @@
+//! Host-side `/goal` lifecycle for the fullscreen TUI (#716).
+//!
+//! The pager publishes a `GoalOp`; this module applies the same transitions
+//! the line REPL uses (`goal_flow.applyGoalSet`, pause/resume/clear). Typed
+//! TUI goals stay non-standing so `attempt_completion` can retire them.
+//! Reached through `test_hooks.zig` — without that import these tests compile
+//! to nothing and the suite still reports green.
+
+const std = @import("std");
+const Allocator = std.mem.Allocator;
+
+const agent_mod = @import("agent.zig");
+const goal_flow = @import("goal_flow.zig");
+const goal_state = @import("goal_state.zig");
+const prompts = @import("prompts.zig");
+const repl_glue = @import("repl_glue.zig");
+const session = @import("session.zig");
+const Agent = agent_mod.Agent;
+
+pub const Op = enum { none, set, clear, pause, unpause };
+
+/// Apply one published TUI `/goal` verb to the live root. `.none` is a no-op
+/// so `/strict` and the exit snapshot cannot mint or wipe a goal.
+pub fn apply(root: *Agent, op: Op, text: []const u8, now_ms: i64) void {
+ switch (op) {
+ .none => {},
+ .set => {
+ const trimmed = std.mem.trim(u8, text, " \t\r\n");
+ if (trimmed.len == 0) return;
+ const owned = root.arena.dupe(u8, trimmed) catch return;
+ _ = goal_flow.applyGoalSet(root, owned, now_ms);
+ prompts.pinStandingGoal(root, root.arena);
+ },
+ .clear => {
+ if (root.goal == null) return;
+ root.goal = null;
+ goal_state.resetCompletionGate(root);
+ root.goal_note_fp = 0;
+ prompts.pinStandingGoal(root, root.arena);
+ },
+ .pause => {
+ if (root.goal) |*g| {
+ g.status = .paused;
+ g.updated_ms = now_ms;
+ prompts.pinStandingGoal(root, root.arena);
+ }
+ },
+ .unpause => {
+ if (root.goal) |*g| {
+ g.status = .active;
+ g.updated_ms = now_ms;
+ root.goal_note_fp = 0;
+ prompts.pinStandingGoal(root, root.arena);
+ }
+ },
+ }
+}
+
+fn flowRoot(arena: Allocator) Agent {
+ var root: Agent = undefined;
+ root.arena = arena;
+ root.sub = false;
+ root.review_mode = false;
+ root.todos = .empty;
+ root.goal = null;
+ root.todos_dirty = false;
+ root.completion_gate_armed = false;
+ root.completion_refused = false;
+ root.completed = null;
+ root.goal_note_fp = 0;
+ root.pending_goal_note = null;
+ root.history_rewrites = 0;
+ root.tool_calls_this_turn = 0;
+ root.loop_deadline_ms = null;
+ return root;
+}
+
+/// The loadSession goal slice: parse the saved object, then reconcile.
+fn resumeGoal(arena: Allocator, root: *Agent, json: []const u8) !void {
+ const parsed = try std.json.parseFromSliceLeaky(std.json.Value, arena, json, .{ .allocate = .alloc_always });
+ root.goal = if (parsed.object.get("goal")) |v| session.goalFromValue(v, 1_000) else null;
+ root.todos.clearRetainingCapacity();
+ if (parsed.object.get("todos")) |tv| try session.appendTodosFromValue(arena, &root.todos, tv);
+ root.todos_dirty = false;
+ root.completion_gate_armed = false;
+ root.completion_refused = false;
+ _ = goal_state.reconcileRestored(root);
+}
+
+test "#716 typed TUI /goal is retirable and does not steer after resume" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = flowRoot(ar);
+
+ apply(&root, .set, "ship it", 5_000);
+ try std.testing.expect(root.goal != null);
+ try std.testing.expect(!root.goal.?.standing);
+ try std.testing.expectEqual(agent_mod.GoalStatus.active, root.goal.?.status);
+ try std.testing.expect((try repl_glue.goalSteeringNote(ar, root.goal)).len > 0);
+
+ // The old host callback minted standing=true, so this returned false and
+ // the objective stayed active across /resume.
+ try std.testing.expect(goal_state.retireOnCompletion(&root, 9_000));
+ try std.testing.expectEqual(agent_mod.GoalStatus.complete, root.goal.?.status);
+ try std.testing.expectEqualStrings("", try repl_glue.goalSteeringNote(ar, root.goal));
+
+ const saved = try std.fmt.allocPrint(ar,
+ \\{{"goal":{{"objective":"{s}","status":"{s}","epoch":{d},"standing":{s},"created_ms":{d},"updated_ms":{d}}},"todos":[]}}
+ , .{
+ root.goal.?.objective,
+ @tagName(root.goal.?.status),
+ root.goal.?.epoch,
+ if (root.goal.?.standing) "true" else "false",
+ root.goal.?.created_ms,
+ root.goal.?.updated_ms,
+ });
+ var resumed = flowRoot(ar);
+ try resumeGoal(ar, &resumed, saved);
+ try std.testing.expect(resumed.goal != null);
+ try std.testing.expect(!resumed.goal.?.standing);
+ try std.testing.expectEqual(agent_mod.GoalStatus.complete, resumed.goal.?.status);
+ try std.testing.expectEqualStrings("", try repl_glue.goalSteeringNote(ar, resumed.goal));
+}
+
+test "#716 TUI /goal pause stops steering; none does not mint a standing goal" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = flowRoot(ar);
+
+ apply(&root, .none, "ship it", 1);
+ try std.testing.expect(root.goal == null);
+
+ apply(&root, .set, "ship it", 2);
+ apply(&root, .none, "", 3);
+ try std.testing.expect(root.goal != null);
+ try std.testing.expectEqual(agent_mod.GoalStatus.active, root.goal.?.status);
+
+ apply(&root, .pause, "ship it", 4);
+ try std.testing.expectEqual(agent_mod.GoalStatus.paused, root.goal.?.status);
+ try std.testing.expectEqualStrings("", try repl_glue.goalSteeringNote(ar, root.goal));
+
+ apply(&root, .unpause, "ship it", 5);
+ try std.testing.expectEqual(agent_mod.GoalStatus.active, root.goal.?.status);
+ try std.testing.expect((try repl_glue.goalSteeringNote(ar, root.goal)).len > 0);
+
+ apply(&root, .clear, "", 6);
+ try std.testing.expect(root.goal == null);
+ try std.testing.expectEqualStrings("", try repl_glue.goalSteeringNote(ar, root.goal));
+}
diff --git a/src/tui_launch.zig b/src/tui_launch.zig
index 1d8f88ef..03976dba 100644
--- a/src/tui_launch.zig
+++ b/src/tui_launch.zig
@@ -29,6 +29,7 @@ const util = @import("util.zig");
const obs = @import("obs.zig");
const vision = @import("vision.zig");
const doctor = @import("doctor.zig");
+const tui_goal = @import("tui_goal.zig");
const builtin = @import("builtin");
/// Live root for `/doctor`. The HUD callback has no ctx argument.
@@ -158,20 +159,18 @@ fn stateCb(ctx: ?*anyopaque, state: tui.SessionState) void {
root.ultracode_mode = state.ultracode;
if (state.session_name.len > 0 and !std.mem.eql(u8, state.session_name, root.session_name))
root.session_name = root.arena.dupe(u8, state.session_name) catch root.session_name;
- if (state.goal.len == 0) {
- root.goal = null;
- root.todos.clearRetainingCapacity();
- } else if (root.goal == null or !std.mem.eql(u8, root.goal.?.objective, state.goal)) {
- const now = util.unixMs(root.io);
- root.goal = .{
- .objective = root.arena.dupe(u8, state.goal) catch return,
- .epoch = if (root.goal) |goal| goal.epoch + 1 else 1,
- .standing = true,
- .created_ms = now,
- .updated_ms = now,
- };
- root.todos.clearRetainingCapacity();
- }
+ // Typed `/goal` is retirable (applyGoalSet, standing=false). `/strict` and
+ // the exit snapshot publish `.none` and must not mint a standing flag (#716).
+ const op: tui_goal.Op = switch (state.goal_op) {
+ .none => .none,
+ .set => .set,
+ .clear => .clear,
+ .pause => .pause,
+ .unpause => .unpause,
+ };
+ tui_goal.apply(root, op, state.goal, util.unixMs(root.io));
+ if (state.goal_op != .none)
+ session.saveSession(root, root.arena, root.session_name) catch {};
}
fn emergencyCb(_: ?*anyopaque) void {