graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: remember the -p prompt so the named-file nudge always sees it
Cursor Agent350b03c6f1fb
diff --git a/src/agent.zig b/src/agent.zigindex 1cd9b2ef..dc734828 100644--- a/src/agent.zig+++ b/src/agent.zig@@ -329,6 +329,7 @@ pub const Agent = struct {// No per-turn teardown: the socket and the chain span user turns, guarded by codex_chain.usable instead.self.completed = null;self.named_work_nudges = 0;+ named_work.rememberFrom(self);if (!self.sub and !root_turn_prepared.swap(false, .acq_rel)) esc_cancel.store(false, .release);while (true) {if (try @import("turn_chrome.zig").beforeRequest(self)) |paused| return paused;diff --git a/src/named_work.zig b/src/named_work.zigindex 9e40bfff..45c8cc24 100644--- a/src/named_work.zig+++ b/src/named_work.zig@@ -17,8 +17,37 @@ pub const nudge_text ="You named a source file and have not used a tool. Read the named path " ++"and edit it before answering — do not describe a fix you have not applied.";+/// The current turn's user text. Responses history often drops `role=user`+/// after the first step, so `handle` must not depend on walking messages.+var remembered_task: []const u8 = "";+const source_needles = [_][]const u8{ ".py", ".zig", ".js", ".ts", "SPEC.md" };+pub fn remember(text: []const u8) void {+ remembered_task = text;+}++fn lastUserText(self: *Agent) []const u8 {+ var i = self.messages.items.len;+ while (i > 0) {+ i -= 1;+ const msg = self.messages.items[i];+ if (msg != .object) continue;+ const role = msg.object.get("role") orelse continue;+ if (role != .string or !std.mem.eql(u8, role.string, "user")) continue;+ const content = msg.object.get("content") orelse continue;+ if (content == .string) return content.string;+ }+ return "";+}++/// Snapshot the user prompt at turn start, while `role=user` still exists.+/// Does not clear a `-p` remember() if history has no user string yet.+pub fn rememberFrom(self: *Agent) void {+ const t = lastUserText(self);+ if (t.len > 0) remember(t);+}+/// True when `text` names a source path (not a greeting.txt-style data file).pub fn hasNamedSource(text: []const u8) bool {for (source_needles) |n| {@@ -67,7 +96,8 @@ pub fn conversationNamesSource(messages: []const Value) bool {pub fn handle(self: *Agent, _: []const u8) !bool {if (self.named_work_nudges >= max_nudges) return false;if (self.tools_used.count() != 0) return false;- if (!conversationNamesSource(self.messages.items)) return false;+ const named = hasNamedSource(remembered_task) or conversationNamesSource(self.messages.items);+ if (!named) return false;self.named_work_nudges += 1;try self.messages.append(try messages_mod.textMessage(self.arena, "user", nudge_text));return true;@@ -88,6 +118,14 @@ test "shouldNudge is once, and only when no tools have run" {try std.testing.expect(!shouldNudge(0, 0, "Reply with exactly: pong"));}+test "remembered task is enough to shouldNudge even without history walk" {+ remember("Fix stall_notice.py");+ defer remember("");+ try std.testing.expect(hasNamedSource(remembered_task));+ remember("Reply with exactly: pong");+ try std.testing.expect(!hasNamedSource(remembered_task));+}+test "conversationNamesSource sees Responses input_text, not role=user" {const raw =\\{"type":"message","content":[{"type":"input_text","text":"Fix atomic_write.py"}]}diff --git a/src/session_run.zig b/src/session_run.zigindex 34a68544..7e9c9456 100644--- a/src/session_run.zig+++ b/src/session_run.zig@@ -124,6 +124,7 @@ pub fn runReplCommand(gpa: Allocator, io: Io, environ_map: anytype, root: *agentpub fn runOneshotPrompt(gpa: Allocator, io: Io, arena: Allocator, root: *agent_mod.Agent, keys: *provider_mod.Keys, tracer: *trace.Tracer, out: *Io.Writer, prompt_text: []const u8) !void {if (@import("goal_pacing.zig").oneshotSlashRefusal(prompt_text)) |why| std.process.fatal("{s}", .{why}); // usage error, not a promptmain_mod.unattended = true;+ @import("named_work.zig").remember(prompt_text);root.in = null; // gate: deny instead of prompt; ask_user: self-decideroot.out = null; // tool progress → stderr; stdout carries only the answerroot.stream_quiet = true;