Skip to content

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

Python

fix(goal): --goal is a standing objective the model cannot retire

Rach Pradhan77bf5bfde1d8
diff --git a/src/agent.zig b/src/agent.zig
index e04a383c..4b0ffe67 100644
--- a/src/agent.zig
+++ b/src/agent.zig
@@ -55,6 +55,7 @@ pub const Goal = struct {
objective: []const u8,
status: GoalStatus = .active,
epoch: u64 = 0, // monotonic per session; todos are stamped with it so a replaced goal cannot bequeath its checklist (#318)
+ standing: bool = false, // seeded by --goal: steering policy for the WHOLE session that the model can never retire; only the user can, with /goal clear|pause|<new> (#318)
created_ms: i64 = 0,
updated_ms: i64 = 0,
};
diff --git a/src/agent_tools.zig b/src/agent_tools.zig
index 9e09f121..4c5bdcc2 100644
--- a/src/agent_tools.zig
+++ b/src/agent_tools.zig
@@ -296,13 +296,13 @@ pub fn handleMeta(self: *Agent, call: ToolCall) !ExecResult {
}
const result = if (call.input.object.get("result")) |r| r.string else "";
self.completed = try self.arena.dupe(u8, result);
- if (goal_state.goalActive(self)) {
- // .complete retires the epoch (goal_state.currentEpoch): the checklist
- // parks - readable, no longer current - instead of being deleted (#318).
- self.goal.?.status = .complete; // a normal completion ends the goal - not only /loop's controller (#318)
- self.goal.?.updated_ms = util.unixMs(self.io);
+ // .complete retires the epoch (goal_state.currentEpoch) and the checklist parks - readable, no longer current, never deleted (#318).
+ // A --goal standing objective is exempt: the completion is recorded above, the steering stays, and only /goal clear|pause|<new> retires it.
+ if (goal_state.retireOnCompletion(self, util.unixMs(self.io))) {
if (self.tracer) |t| t.note("goal", "completed via attempt_completion");
try self.say("\xf0\x9f\x8e\xaf standing goal complete\n", .{});
+ } else if (goal_state.goalActive(self)) {
+ if (self.tracer) |t| t.note("goal", "completion; standing goal retained");
}
// Skip the re-print only when the result streamed live in full.
if (!self.sub and !self.argStreamedFully(call)) try self.say("{s}\n", .{result});
diff --git a/src/cli.zig b/src/cli.zig
index a491b316..74c86b3c 100644
--- a/src/cli.zig
+++ b/src/cli.zig
@@ -97,7 +97,7 @@ pub const usage_text =
\\ --no-resume ignore --resume and start fresh
\\ --system-prompt <text> replace the built-in system prompt
\\ --append-system-prompt <text> append extra text to the system prompt
- \\ --goal <text> seed a standing objective (tracked as a todo checklist) for every turn
+ \\ --goal <text> seed a standing objective (tracked as a todo checklist) for every turn; persists across completions
\\ --eval <cmd> scoring command for an eval-driven loop (the `eval` tool runs it)
\\ --until <0-100> eval-loop target score; stop when reached (default 90)
\\ --niche <name> fleet niche this eval optimizes (reviewer/researcher/implementer/skeptic or a custom agent); tags submitted scores so the DGM can promote a champion for that role
diff --git a/src/commands_session.zig b/src/commands_session.zig
index f182ea55..5563c00c 100644
--- a/src/commands_session.zig
+++ b/src/commands_session.zig
@@ -140,7 +140,8 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
const open = goal_state.openCount(root.todos.items, g.epoch);
const parked = goal_state.parkedOpenCount(root.todos.items, g.epoch);
const state = if (g.status == .complete) "parked unfinished" else "open"; // a retired goal has no open work, only parked work (#318)
- try out.print("\xf0\x9f\x8e\xaf Goal: {s}\nStatus: {s}. Checklist: {d} item(s) {s}. Commands: /goal pause | resume | clear.\n", .{ g.objective, @tagName(g.status), open, state });
+ const standing = if (g.standing) " (standing)" else ""; // seeded by --goal: only the user retires it (#318)
+ try out.print("\xf0\x9f\x8e\xaf Goal: {s}{s}\nStatus: {s}. Checklist: {d} item(s) {s}. Commands: /goal pause | resume | clear.\n", .{ g.objective, standing, @tagName(g.status), open, state });
if (parked > 0) try out.print("(+{d} unfinished item(s) parked from earlier goals \xe2\x80\x94 kept in the session, not steering)\n", .{parked});
} else try out.writeAll("No active goal. Set one with /goal <objective>.\n");
} else if (std.ascii.eqlIgnoreCase(text, "clear") or std.ascii.eqlIgnoreCase(text, "off")) {
diff --git a/src/goal_flow.zig b/src/goal_flow.zig
index b3f45874..de40b8be 100644
--- a/src/goal_flow.zig
+++ b/src/goal_flow.zig
@@ -12,6 +12,24 @@ const goal_state = @import("goal_state.zig");
const Agent = agent_mod.Agent;
const TodoItem = agent_mod.TodoItem;
+/// The Goal `--goal <text>` seeds: a STANDING objective (the flag's documented
+/// contract is "every turn, incl. --json/-p/SDK"), stamped above every epoch
+/// already present in `todos` so a resumed session's parked checklist can never
+/// become its work, and so it never aliases the epoch-0 no-goal bucket (#318).
+/// `objective` must already be owned by the session arena. Also used to
+/// RE-apply the flag after a resume: loadSession overwrites root.goal with the
+/// goal from disk, so `graff -r <session> --goal X` silently dropped X.
+pub fn standingGoalFromFlag(objective: []const u8, todos: []const TodoItem, now_ms: i64) agent_mod.Goal {
+ return .{
+ .objective = objective,
+ .status = .active,
+ .standing = true,
+ .epoch = goal_state.nextEpoch(null, todos),
+ .created_ms = now_ms,
+ .updated_ms = now_ms,
+ };
+}
+
/// A root agent in the shape the goal helpers read; no live turn behind it.
fn flowRoot(arena: Allocator) Agent {
var root: Agent = undefined;
@@ -23,9 +41,82 @@ fn flowRoot(arena: Allocator) Agent {
root.todos_dirty = false;
root.completion_gate_armed = false;
root.completion_refused = false;
+ root.completed = null;
return root;
}
+test "a --goal standing objective outlives the model's own completion (#318)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = flowRoot(ar);
+ root.goal = standingGoalFromFlag("keep the tree green", root.todos.items, 7);
+ try std.testing.expect(root.goal.?.standing);
+ try std.testing.expectEqual(@as(u64, 1), root.goal.?.epoch); // never epoch 0: that bucket is the no-goal one
+
+ // The gate never fires for it: there is no close event to double-check, so
+ // the arm never arms and open work never produces a refusal either.
+ try std.testing.expect((try goal_state.completionGate(ar, &root)) == null);
+ try root.todos.append(ar, .{ .content = "an open item", .status = "pending", .epoch = 1 });
+ try std.testing.expect((try goal_state.completionGate(ar, &root)) == null);
+ try std.testing.expect(!root.completion_gate_armed);
+
+ // attempt_completion: the result is recorded (the handler does that above
+ // the branch), but the objective stays active and keeps steering. Before
+ // this, one attempt_completion left every later turn of a headless/SDK
+ // session unsteered - and the note itself coached the model into making it.
+ root.completed = "shipped the first task";
+ try std.testing.expect(!goal_state.retireOnCompletion(&root, 99));
+ try std.testing.expectEqual(agent_mod.GoalStatus.active, root.goal.?.status);
+ try std.testing.expect(root.completed != null);
+ try std.testing.expect(goal_state.goalActive(&root));
+
+ // A /goal-typed objective is unchanged: it still retires on completion.
+ root.goal = .{ .objective = "ship phase 2", .epoch = 1 };
+ try std.testing.expect(goal_state.retireOnCompletion(&root, 99));
+ try std.testing.expectEqual(agent_mod.GoalStatus.complete, root.goal.?.status);
+ try std.testing.expectEqual(@as(i64, 99), root.goal.?.updated_ms);
+}
+
+test "resume never auto-retires a standing goal over a finished checklist (#318)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = flowRoot(ar);
+ // A restored session whose --goal checklist is all done. reconcileRestored
+ // retires a /goal objective here (the model finished and quit), but a
+ // standing one is the user's policy for the session, not a task that ended.
+ root.goal = standingGoalFromFlag("keep the tree green", root.todos.items, 7);
+ try root.todos.append(ar, .{ .content = "done", .status = "completed", .epoch = 1 });
+ try std.testing.expect(goal_state.allDone(root.todos.items, 1));
+ try std.testing.expect(!goal_state.reconcileRestored(&root));
+ try std.testing.expectEqual(agent_mod.GoalStatus.active, root.goal.?.status);
+ try std.testing.expectEqualStrings("[x] done", goal_state.renderCurrent(&root)); // still current, still steering
+ // The same list under a /goal objective does retire it.
+ root.goal.?.standing = false;
+ try std.testing.expect(goal_state.reconcileRestored(&root));
+}
+
+test "--goal seeded onto a resumed session lands above every restored epoch (#318)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = flowRoot(ar);
+ // What `graff -r <session> --goal X` finds after loadSession: an unscoped
+ // finished list plus a parked epoch. Seeding the flag goal at the default
+ // epoch 0 aliased the no-goal bucket, so the restored all-[x] items were
+ // instantly its "finished checklist" and completion was free.
+ try root.todos.append(ar, .{ .content = "old unscoped work", .status = "completed", .epoch = 0 });
+ try root.todos.append(ar, .{ .content = "parked", .status = "pending", .epoch = 3 });
+ root.goal = standingGoalFromFlag("keep the tree green", root.todos.items, 7);
+ try std.testing.expectEqual(@as(u64, 4), root.goal.?.epoch);
+ try std.testing.expectEqual(@as(u64, 4), goal_state.currentEpoch(root.goal));
+ try std.testing.expect(!goal_state.hasCurrent(root.todos.items, 4));
+ try std.testing.expectEqual(@as(usize, 0), goal_state.openCount(root.todos.items, 4));
+ try std.testing.expect(!goal_state.allDone(root.todos.items, 4)); // nothing of its own is "done"
+ try std.testing.expectEqual(@as(usize, 2), root.todos.items.len); // and nothing was deleted
+}
+
test "a cleared goal's finished checklist cannot be reborn as the next goal's list (#318)" {
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
diff --git a/src/goal_persist_tests.zig b/src/goal_persist_tests.zig
index 1a39e670..aa59ad2a 100644
--- a/src/goal_persist_tests.zig
+++ b/src/goal_persist_tests.zig
@@ -109,6 +109,45 @@ test "resume: a finished epoch-0 leftover cannot end a bare /loop (#318)" {
try std.testing.expect(goal_state.checklistFinished(&root));
}
+test "goalFromValue: epoch round-trips; legacy goals default to epoch 0 (#318)" {
+ // Moved here from session.zig, which is at the 600-line cap.
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const a = arena_state.allocator();
+ const v = try std.json.parseFromSliceLeaky(std.json.Value, a, "{\"objective\":\"x\",\"status\":\"active\",\"epoch\":3}", .{});
+ try std.testing.expectEqual(@as(u64, 3), session.goalFromValue(v, 1).?.epoch);
+ const legacy = try std.json.parseFromSliceLeaky(std.json.Value, a, "\"just a string\"", .{});
+ try std.testing.expectEqual(@as(u64, 0), session.goalFromValue(legacy, 1).?.epoch);
+}
+
+test "resume: a standing --goal round-trips and stays the user's policy (#318)" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const ar = arena_state.allocator();
+ var root = blankRoot(ar);
+ // The shape saveSession writes for a --goal session: `standing` alongside
+ // the epoch. Resume honors it, so the objective survives its own finished
+ // checklist instead of being reconciled away on the first resumed turn.
+ try resumeSession(ar, &root,
+ \\{"goal":{"objective":"keep the tree green","status":"active","epoch":2,"standing":true,"created_ms":1,"updated_ms":2},
+ \\ "todos":[{"content":"first task","status":"completed","epoch":2}]}
+ );
+ try std.testing.expect(root.goal.?.standing);
+ try std.testing.expectEqual(agent_mod.GoalStatus.active, root.goal.?.status);
+ try std.testing.expect(goal_state.goalActive(&root));
+ try std.testing.expectEqualStrings("[x] first task", goal_state.renderCurrent(&root));
+ try std.testing.expect((try goal_state.completionGate(ar, &root)) == null); // never gated
+ // Sessions written before the field (and every /goal objective) have no
+ // standing flag, so they keep the model-retirable behavior exactly.
+ var legacy = blankRoot(ar);
+ try resumeSession(ar, &legacy,
+ \\{"goal":{"objective":"ship phase 2","status":"active","epoch":2,"created_ms":1,"updated_ms":2},
+ \\ "todos":[{"content":"first task","status":"completed","epoch":2}]}
+ );
+ try std.testing.expect(!legacy.goal.?.standing);
+ try std.testing.expectEqual(agent_mod.GoalStatus.complete, legacy.goal.?.status);
+}
+
test "resume: a /goal set after restoring parked items lands above them (#318)" {
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
diff --git a/src/goal_state.zig b/src/goal_state.zig
index ee6b519a..a36236cb 100644
--- a/src/goal_state.zig
+++ b/src/goal_state.zig
@@ -155,11 +155,26 @@ pub fn noteTodoWrite(root: *Agent) void {
/// empty epoch (#226), so a goal that never wrote a checklist is left alone.
pub fn reconcileRestored(root: *Agent) bool {
const g = root.goal orelse return false;
+ if (g.standing) return false; // --goal is the user's policy for the session; a finished checklist is not their permission to drop it (#318)
if (g.status != .active or !allDone(root.todos.items, g.epoch)) return false;
root.goal.?.status = .complete;
return true;
}
+/// An accepted attempt_completion retires the goal - unless it is standing.
+/// Returns true when it retired, so the caller can print/trace the difference;
+/// the completion itself is recorded either way. A --goal objective is the
+/// user's policy for the whole session (--json/-p/SDK included), so the model
+/// finishing one task must not end the steering; only /goal clear|pause|<new>
+/// can (#318). Pure (no Io) so the rule is unit-tested; the caller passes the
+/// clock reading.
+pub fn retireOnCompletion(root: *Agent, now_ms: i64) bool {
+ if (!goalActive(root) or root.goal.?.standing) return false;
+ root.goal.?.status = .complete;
+ root.goal.?.updated_ms = now_ms;
+ return true;
+}
+
/// Reset the completion double-check because the evidence changed: todo_write
/// wrote a new current-epoch checklist, or /goal set|replace|clear moved the
/// objective. Clearing the arm makes the NEXT attempt_completion get checked
@@ -224,6 +239,7 @@ pub fn hasCurrent(todos: []const TodoItem, epoch: u64) bool {
/// ever can, since one attempt_completion per turn is all a model emits.
pub fn completionGate(arena: Allocator, agent: *Agent) !?[]const u8 {
if (!goalActive(agent)) return null;
+ if (agent.goal.?.standing) return null; // a standing --goal has no close event to gate: the arm never arms for it (#318)
if (agent.completion_gate_armed) return null;
const epoch = currentEpoch(agent.goal);
const open = openCount(agent.todos.items, epoch);
diff --git a/src/mainloop.zig b/src/mainloop.zig
index 4cdb3b4e..4bdd1ed0 100644
--- a/src/mainloop.zig
+++ b/src/mainloop.zig
@@ -579,7 +579,7 @@ pub fn run(ctx: *Ctx) !void {
loop_iters_left = 0;
loop_continue_armed = false;
if (outcome == .accepted and work_done) if (ctx.root.goal) |*g| {
- if (g.status == .active) g.status = .complete; // the loop drove the goal to done
+ if (g.status == .active and !g.standing) g.status = .complete; // the loop drove the goal to done; a --goal standing objective outlives it (#318)
};
try ctx.out.print("{s}↩ /loop stopped — {s}{s}\n", .{ style.dim, @tagName(outcome), style.reset });
try ctx.out.flush();
diff --git a/src/repl_glue.zig b/src/repl_glue.zig
index 9040bed5..8925e0ed 100644
--- a/src/repl_glue.zig
+++ b/src/repl_glue.zig
@@ -101,6 +101,12 @@ pub const ReplStreamSink = struct {
pub fn goalSteeringNote(arena: Allocator, goal: ?agent_mod.Goal) ![]const u8 {
const g = goal orelse return "";
if (g.status != .active) return ""; // paused/blocked/complete/budget_limited never steer (#223)
+ // A --goal objective is the user's policy for the session, so its note must
+ // not coach the model into ending it: the old text told every turn to call
+ // attempt_completion "to end this steering", and one such call left the rest
+ // of a headless/SDK session running unsteered (#318).
+ if (g.standing)
+ return std.fmt.allocPrint(arena, "[standing goal: {s} - keep this objective in view on every task; track multi-step work as a live todo_write checklist, marking each item in_progress when you start and completed when done. This steering persists for the whole session.]", .{g.objective});
return std.fmt.allocPrint(arena, "[standing goal: {s} - track this as a live todo_write checklist and work through it, marking each item in_progress when you start and completed when done. When the objective is verifiably done, call attempt_completion - that completes the goal and ends this steering.]", .{g.objective});
}
@@ -185,6 +191,18 @@ test "goalSteeringNote: active-only gate, completion contract, and no embedded c
try std.testing.expect(std.mem.indexOf(u8, n1, "attempt_completion") != null);
try std.testing.expect(std.mem.indexOf(u8, n1, "Checklist so far") == null);
try std.testing.expect(std.mem.indexOf(u8, n1, "(no todos)") == null);
+
+ // A --goal standing objective keeps the checklist guidance but drops the
+ // self-termination clause: the model cannot retire it, so telling it to
+ // "call attempt_completion and end this steering" was a lie that cost every
+ // later turn of a headless/SDK session its goal (#318).
+ const n2 = try goalSteeringNote(ar, .{ .objective = "close all issues", .standing = true });
+ try std.testing.expect(std.mem.startsWith(u8, n2, "[standing goal: close all issues - keep this objective in view"));
+ try std.testing.expect(std.mem.indexOf(u8, n2, "todo_write checklist") != null);
+ try std.testing.expect(std.mem.indexOf(u8, n2, "attempt_completion") == null);
+ try std.testing.expect(std.mem.indexOf(u8, n2, "persists for the whole session") != null);
+ // Still gated on .active: /goal pause silences a standing goal too.
+ try std.testing.expectEqualStrings("", try goalSteeringNote(ar, .{ .objective = "x", .standing = true, .status = .paused }));
}
/// #226 continuation gate — the outcome when a /loop turn finishes: the loop
diff --git a/src/session.zig b/src/session.zig
index 52eeaad1..25f62e28 100644
--- a/src/session.zig
+++ b/src/session.zig
@@ -238,6 +238,8 @@ pub fn saveSession(root: *Agent, arena: Allocator, name: []const u8) !void {
try s.write(@tagName(g.status));
try s.objectField("epoch");
try s.write(g.epoch);
+ try s.objectField("standing"); // a --goal objective resumes as one: the model still cannot retire it (#318)
+ try s.write(g.standing);
try s.objectField("created_ms");
try s.write(g.created_ms);
try s.objectField("updated_ms");
@@ -308,7 +310,8 @@ pub fn goalFromValue(v: Value, now_ms: i64) ?agent_mod.Goal {
const ep: u64 = if (go.get("epoch")) |e| (if (e == .integer and e.integer >= 0) @intCast(e.integer) else 0) else 0;
const cms: i64 = if (go.get("created_ms")) |c| (if (c == .integer) c.integer else 0) else 0;
const ums: i64 = if (go.get("updated_ms")) |u| (if (u == .integer) u.integer else 0) else 0;
- return .{ .objective = objective, .status = st, .epoch = ep, .created_ms = cms, .updated_ms = ums };
+ const standing = if (go.get("standing")) |b| (b == .bool and b.bool) else false; // absent in legacy sessions: a /goal objective the model may retire (#318)
+ return .{ .objective = objective, .status = st, .epoch = ep, .standing = standing, .created_ms = cms, .updated_ms = ums };
}
return null;
}
@@ -346,16 +349,6 @@ test "todos round-trip: appendTodosFromValue parses content/status/epoch, skips
try std.testing.expectEqual(@as(usize, 2), todos.items.len);
}
-test "goalFromValue: epoch round-trips; legacy goals default to epoch 0 (#318)" {
- var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
- defer arena_state.deinit();
- const a = arena_state.allocator();
- const v = try std.json.parseFromSliceLeaky(Value, a, "{\"objective\":\"x\",\"status\":\"active\",\"epoch\":3}", .{});
- try std.testing.expectEqual(@as(u64, 3), goalFromValue(v, 1).?.epoch);
- const legacy = try std.json.parseFromSliceLeaky(Value, a, "\"just a string\"", .{});
- try std.testing.expectEqual(@as(u64, 0), goalFromValue(legacy, 1).?.epoch);
-}
-
test "goalFromValue: legacy string -> active; object round-trips; paused stays paused (#223)" {
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
diff --git a/src/session_run.zig b/src/session_run.zig
index b44d8b78..719f2ac8 100644
--- a/src/session_run.zig
+++ b/src/session_run.zig
@@ -52,6 +52,7 @@ const eval_memory = @import("eval_memory.zig");
const providers = @import("providers.zig");
const messages_mod = @import("messages.zig");
const session = @import("session.zig");
+const goal_flow = @import("goal_flow.zig");
const fleet = @import("fleet.zig");
const hooks = @import("hooks.zig");
const learn_auto = @import("learn_auto.zig");
@@ -265,7 +266,7 @@ pub fn buildRootAgent(
const fresh_session_name = try std.fmt.allocPrint(arena, "session-{d}", .{util.unixMs(io)});
root.session_name = if (flags.resume_flag) |name| (if (!flags.new_session_flag and !flags.no_resume_flag) name else fresh_session_name) else fresh_session_name;
repl_glue.loadThinkingSettings(io, arena, &root); // {"effort":...,"fast":...} persisted by /effort and /fast
- if (flags.goal_flag) |g| root.goal = .{ .objective = try arena.dupe(u8, g), .status = .active, .created_ms = util.unixMs(io), .updated_ms = util.unixMs(io) }; // --goal applies to every turn (incl. --json/-p/SDK)
+ if (flags.goal_flag) |g| root.goal = goal_flow.standingGoalFromFlag(try arena.dupe(u8, g), root.todos.items, util.unixMs(io)); // --goal is STANDING (#318): it applies to every turn (incl. --json/-p/SDK) and the model can never retire it
if (flags.eval_cmd_flag) |c| root.eval_cmd = try arena.dupe(u8, c);
if (flags.eval_target_flag) |t| root.eval_target = t;
if (flags.eval_niche_flag) |n| root.eval_niche = try arena.dupe(u8, n);
@@ -294,6 +295,9 @@ pub fn saveOrResumeSession(root: *agent_mod.Agent, keys: *provider_mod.Keys, are
if (!will_resume) session.saveSession(root, arena, root.session_name) catch {};
if (flags.oneshot_prompt != null and flags.resume_flag != null and !flags.new_session_flag and !flags.no_resume_flag) {
session.loadSession(root, keys, arena, root.session_name) catch {};
+ // loadSession overwrites root.goal with the goal from disk, so `-r <s> --goal X`
+ // silently dropped X. The flag wins, on an epoch above every restored one (#318).
+ if (flags.goal_flag) |g| root.goal = goal_flow.standingGoalFromFlag(arena.dupe(u8, g) catch g, root.todos.items, util.unixMs(root.io));
}
}
@@ -306,6 +310,8 @@ pub fn saveOrResumeSession(root: *agent_mod.Agent, keys: *provider_mod.Keys, are
pub fn restoreResumedSession(arena: Allocator, out: *Io.Writer, root: *agent_mod.Agent, keys: *provider_mod.Keys, flags: args.Flags, json_mode: bool, cwd_display: []const u8) !void {
if (!(flags.oneshot_prompt == null and flags.resume_flag != null and !flags.new_session_flag and !flags.no_resume_flag)) return;
if (session.loadSession(root, keys, arena, root.session_name)) |_| {
+ // --goal outranks the restored goal here too (see saveOrResumeSession, #318).
+ if (flags.goal_flag) |g| root.goal = goal_flow.standingGoalFromFlag(try arena.dupe(u8, g), root.todos.items, util.unixMs(root.io));
if (root.messages.items.len > 0) {
if (!json_mode) {
// Prefer the saved AI summary; fall back to the first user