Skip to content

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

Python

refactor(goal): name the gate reset for what it clears

Rach Pradhan4120f4149290
diff --git a/src/agent_tools.zig b/src/agent_tools.zig
index dbe8fbb8..b5d20bc5 100644
--- a/src/agent_tools.zig
+++ b/src/agent_tools.zig
@@ -315,7 +315,7 @@ pub fn handleMeta(self: *Agent, call: ToolCall) !ExecResult {
if (std.mem.eql(u8, call.name, "todo_write")) {
const epoch = goal_state.currentEpoch(self.goal); // items belong to the goal that authored them (#318)
_ = goal_state.clearEpoch(&self.todos, epoch); // replace THIS epoch's list; parked items from earlier goals survive
- goal_state.rearmCompletionGate(self); // a new checklist is new evidence for the completion double-check
+ goal_state.resetCompletionGate(self); // a new checklist is new evidence for the completion double-check
if (call.input.object.get("todos")) |list| if (list == .array) {
for (list.array.items) |item| {
if (item != .object) continue;
diff --git a/src/commands_session.zig b/src/commands_session.zig
index 03d89930..1b75a184 100644
--- a/src/commands_session.zig
+++ b/src/commands_session.zig
@@ -152,7 +152,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
}
const open = goal_state.openCount(root.todos.items, goal_state.currentEpoch(root.goal));
root.goal = null; // the checklist PARKS with the goal (#318): items keep their epoch and stay in the session, they just stop being current
- goal_state.rearmCompletionGate(root);
+ goal_state.resetCompletionGate(root);
root.goal_note_fp = 0;
if (root.tracer) |t| t.note("goal", "cleared");
saveSession(root, arena, root.session_name) catch {};
@@ -199,7 +199,7 @@ pub fn tryHandle(root: *Agent, keys: *Keys, arena: Allocator, line: []const u8,
}
root.goal = .{ .objective = try arena.dupe(u8, text), .status = .active, .epoch = epoch, .created_ms = now, .updated_ms = now };
root.goal_note_fp = 0;
- goal_state.rearmCompletionGate(root); // a new objective is new evidence for the completion double-check
+ goal_state.resetCompletionGate(root); // a new objective is new evidence for the completion double-check
saveSession(root, arena, root.session_name) catch {};
try out.print("\xf0\x9f\x8e\xaf Goal set: {s} \xe2\x80\x94 starting now (tracked as a live checklist; it steers every turn until /goal pause or /goal clear).\n", .{text});
}
diff --git a/src/goal_state.zig b/src/goal_state.zig
index d9e5f38c..245dc62f 100644
--- a/src/goal_state.zig
+++ b/src/goal_state.zig
@@ -111,10 +111,11 @@ pub fn noteCompletionRefused(root: *Agent) void {
root.completion_refused = true;
}
-/// Re-arm the completion double-check because the evidence changed: todo_write
+/// 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. The next attempt_completion is checked against the new state.
-pub fn rearmCompletionGate(root: *Agent) void {
+/// objective. Clearing the arm makes the NEXT attempt_completion get checked
+/// against the new state instead of riding a refusal the model already answered.
+pub fn resetCompletionGate(root: *Agent) void {
root.completion_gate_armed = false;
}
@@ -333,8 +334,8 @@ test "the completion double-check survives the turn boundary, re-arms on change
try std.testing.expect(!root.completion_refused);
try std.testing.expect(root.completion_gate_armed);
try std.testing.expect((try completionGate(ar, &root)) == null);
- // New evidence (todo_write, or a /goal change) re-arms the double-check.
- rearmCompletionGate(&root);
+ // New evidence (todo_write, or a /goal change) restores the double-check.
+ resetCompletionGate(&root);
try std.testing.expect((try completionGate(ar, &root)) != null);
}