graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix(goal): completion closes the checklist; surface the deferral on stdout
justrach4a4ff3969492
diff --git a/src/agent_tools.zig b/src/agent_tools.zigindex 0b5b48b4..7c71912a 100644--- a/src/agent_tools.zig+++ b/src/agent_tools.zig@@ -291,11 +291,13 @@ pub fn handleMeta(self: *Agent, call: ToolCall) !ExecResult {}if (try goal_state.completionGate(self.arena, self)) |refusal| {self.completion_gate_armed = true; // an explicit second call this turn closes anyway+ if (!self.sub) try self.say("\xe2\x8f\xb8 completion deferred \xe2\x80\x94 the standing goal's checklist isn't settled\n", .{});return .{ .text = refusal, .is_error = true };}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)) {+ _ = goal_state.closeEpoch(&self.todos, self.goal.?.epoch); // completion closes the checklist (the deferral text's parking promise)self.goal.?.status = .complete; // a normal completion ends the goal - not only /loop's controller (#318)self.goal.?.updated_ms = util.unixMs(self.io);if (self.tracer) |t| t.note("goal", "completed via attempt_completion");diff --git a/src/goal_state.zig b/src/goal_state.zigindex d328a622..68839580 100644--- a/src/goal_state.zig+++ b/src/goal_state.zig@@ -63,6 +63,21 @@ pub fn parkSuperseded(todos: *std.ArrayList(TodoItem), keep_epoch: u64) usize {return parked_open;}+/// Close `epoch`'s checklist: remove all its items. A completed (or force-+/// closed) goal takes its list with it - the deferral text promises open items+/// are parked, and /goal status must never read "complete" with items open.+pub fn closeEpoch(todos: *std.ArrayList(TodoItem), epoch: u64) usize {+ var removed: usize = 0;+ var i: usize = 0;+ while (i < todos.items.len) {+ if (todos.items[i].epoch == epoch) {+ _ = todos.orderedRemove(i);+ removed += 1;+ } else i += 1;+ }+ return removed;+}+/// A fresh goal set while an unscoped (pre-goal) checklist exists adopts it:/// the user just formalized the objective the plan was already serving.pub fn adoptTodos(todos: []TodoItem, epoch: u64) void {@@ -202,6 +217,9 @@ test "parkSuperseded drops other epochs, counts open ones, keeps the new epoch (try std.testing.expectEqual(@as(usize, 1), parked); // only the OPEN phase3 item countstry std.testing.expectEqual(@as(usize, 1), todos.items.len);try std.testing.expectEqualStrings("phase2 test", todos.items[0].content);+ // Completing epoch 2 closes its checklist entirely (the parking promise).+ try std.testing.expectEqual(@as(usize, 1), closeEpoch(&todos, 2));+ try std.testing.expectEqual(@as(usize, 0), todos.items.len);}test "adoptTodos re-stamps a pre-goal checklist into the new goal's epoch" {