graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
fix: mark -p TTFT on stderr and nudge zero-tool named-file turns
Cursor Agent512432362757
diff --git a/graff-evals/hillclimb/baseline.md b/graff-evals/hillclimb/baseline.mdindex e7022242..641eb20c 100644--- a/graff-evals/hillclimb/baseline.md+++ b/graff-evals/hillclimb/baseline.md@@ -44,6 +44,25 @@ detached `learn init`; `-p` and REPL share one learn-auto path (nooneshot-only skip). `x_search` stays on (ADR 0031). Do not steal grokheap (~165M). Do not shrink to a 4-tool catalog (ADR 0024).+## Latest climb — `run-20260830-112125` spine (usage-fixed `-p`)++Same SuperGrok seat after the Responses SSE-end fix (`event: response.completed`+no longer drops the `data:` usage payload). **Not Pareto.**++| harness | pass | wall | first | calls | tokens | list$ | RSS |+|---|---:|---:|---:|---:|---:|---:|+| graff-dev | 3/3 | **28.5s** | 3.5s | 9 | 36822 | **$0.0612** | **101.7M** |+| grok | 3/3 | 33.4s | 4.1s | **7** | 116043 | $0.1246 | 156.4M |+| opencode | 3/3 | 30.4s | **2.6s** | 8 | 92176 | $0.1385 | 1057.6M |++This session graff wins wall / $ / RSS / tokens vs both. First-token loses+to OpenCode because file-ops is tool-first (6.55s ≈ wall 7.1s; exact-reply+2.21s and fix-fib 1.71s already beat 2.6s). Calls 9 vs grok 7 / OpenCode 8+is model extra-tool variance (file-ops 3 vs 2, fix-fib 5 vs 4), not a+catalog change. Residual: emit one `-p` stderr progress line at first+model SSE (including tool bytes) so first_out is TTFT, not the late+narration. Do not put that line on stdout.+Also compared: OpenCode (`opencode run`) and DeepSeek Harness (`dsh`).Same-model series is grok-4.6. Native-default series (`opencode-zen`,`dsh-deepseek`) is a **different chart** — do not read those points asdiff --git a/graff-evals/tasks/36-cache-gitroot.json b/graff-evals/tasks/36-cache-gitroot.jsonindex 1b57db98..7588d51f 100644--- a/graff-evals/tasks/36-cache-gitroot.json+++ b/graff-evals/tasks/36-cache-gitroot.json@@ -4,7 +4,7 @@"category": "inhouse","source": "codegraff cache-affinity-gitroot — key prompt-cache on git root, not cwd (distilled)","files_dir": "fixtures/cache-gitroot",- "prompt": "affinity_seed hashes the leaf cwd, so sibling worktrees miss the cache. Read SPEC.md and affinity.py, then make `python3 test_affinity.py` print OK. Do not edit the tests.",+ "prompt": "affinity.py:affinity_seed hashes the leaf cwd, so sibling worktrees miss the cache. Read SPEC.md and affinity.py, then edit affinity.py so `python3 test_affinity.py` prints OK. Do not only describe the fix. Do not edit the tests.","check": "python3 test_affinity.py && python3 \"$TASK_ROOT/hidden/cache-gitroot.py\"","timeout_s": 240}diff --git a/graff-evals/tasks/39-stall-warn.json b/graff-evals/tasks/39-stall-warn.jsonindex 64582650..54237190 100644--- a/graff-evals/tasks/39-stall-warn.json+++ b/graff-evals/tasks/39-stall-warn.json@@ -4,7 +4,7 @@"category": "inhouse","source": "codegraff stall-bus-silent — print the stall warning only when the reconnect budget is gone (distilled)","files_dir": "fixtures/stall-warn",- "prompt": "stall_notice prints a warning on every reconnect. Read SPEC.md and stall_notice.py, then make `python3 test_stall_notice.py` print OK. Do not edit the tests. Mid-turn reconnects are silent; the ending-turn notice fires only when the budget is gone.",+ "prompt": "stall_notice.py:stall_notice prints a warning on every reconnect. Read SPEC.md and stall_notice.py, then edit stall_notice.py so `python3 test_stall_notice.py` prints OK. Do not only describe the fix. Do not edit the tests. Mid-turn reconnects are silent; the ending-turn notice fires only when the budget is gone.","check": "python3 test_stall_notice.py && python3 \"$TASK_ROOT/hidden/stall-warn.py\"","timeout_s": 240}diff --git a/src/agent.zig b/src/agent.zigindex 7f3ad6ac..1cd9b2ef 100644--- a/src/agent.zig+++ b/src/agent.zig@@ -33,6 +33,7 @@ const run_budget_mod = @import("run_budget.zig");const prompt_ui = @import("agent_prompt.zig");const agent_tests = @import("agent_tests.zig");const empty_completion = @import("agent_empty_completion.zig");+const named_work = @import("named_work.zig");const goal_state = @import("goal_state.zig");const peer_channel = @import("peer_channel.zig"); // #469: turn-boundary peer message deliveryconst job_notify = @import("job_notify.zig");@@ -207,6 +208,7 @@ pub const Agent = struct {compact_summary_failures: u8 = 0, // #379: consecutive complete-but-unusable (empty/truncated) summariescompact_pin_degraded: bool = false, // #581: pinned suffix over budget — skip+say once per unresolved turnempty_completion_retries: u8 = 0, // degenerate empty completions re-asked this turn (agent_empty_completion.zig)+ named_work_nudges: u8 = 0, // named-file / zero-tool nudge this turn (named_work.zig)precompact_note_gen: ?u32 = null, // #391: history_rewrites at the last pre-compaction note-to-self, so one history generation buys at most one note however often compaction is retried (compact_note.decideCalls)ws_off: bool = false, // codex ws transport disabled for this session after a handshake/transport fallback to SSE (#codex-ws)ws_transport_failures: u8 = 0, // consecutive WS failures; retry once before latching persistent SSE@@ -326,6 +328,7 @@ pub const Agent = struct {try self.ensureRootTools(self.provider.kind);// 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;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;@@ -389,6 +392,7 @@ pub const Agent = struct {// A completion with no text and no tool calls used to end the turn// silently — mid-task that just looks like a dead session.if (try empty_completion.handle(self, final_text, hist_len)) continue;+ if (try named_work.handle(self, final_text)) continue;return final_text;}self.empty_completion_retries = 0;diff --git a/src/agent_observability.zig b/src/agent_observability.zigindex 731b4843..66d263be 100644--- a/src/agent_observability.zig+++ b/src/agent_observability.zig@@ -1,11 +1,46 @@//! Small per-request operational-observability helpers kept out of Agent's//! already-near-limit definition and the provider-specific stream parsers.+const std = @import("std");+const builtin = @import("builtin");++const main_mod = @import("main.zig");+const style = &@import("ansi.zig").style;++/// `-p` (unattended, not `--json`): emit one stderr progress line at the first+/// model-authored SSE event, including tool-call bytes. Eval `first_out` is+/// the first stdout or stderr line; tool-first turns used to stay silent until+/// the final answer, so first_out ≈ wall. REPL / `--json` stay quiet.+pub fn oneshotShouldMarkProgress(unattended: bool, json_mode: bool) bool {+ return unattended and !json_mode;+}++/// One dim `›` plus newline. Stderr only — stdout stays the answer (the+/// atomic-symlink-write miss captured turn-pulse chrome when it rode `g_out`).+pub fn oneshotProgressLine() []const u8 {+ return "›\n";+}++fn emitOneshotProgress() void {+ if (comptime builtin.is_test) return;+ if (!oneshotShouldMarkProgress(main_mod.unattended, main_mod.json_mode)) return;+ std.debug.print("{s}›{s}\n", .{ style.dim, style.reset });+}+pub fn firstToken(self: anytype) void {if (self.first_token_traced) return;const started = self.request_started orelse return;self.first_token_traced = true;+ emitOneshotProgress();const tracer = self.tracer orelse return;const ms: i64 = @intCast(@max(0, started.untilNow(self.io, .awake).toMilliseconds()));tracer.firstToken(self.label, self.sub, self.provider.model, ms);}++test "oneshot marks first progress on -p, not --json or the line REPL" {+ try std.testing.expect(oneshotShouldMarkProgress(true, false));+ try std.testing.expect(!oneshotShouldMarkProgress(false, false));+ try std.testing.expect(!oneshotShouldMarkProgress(true, true));+ try std.testing.expectEqualStrings("›\n", oneshotProgressLine());+ try std.testing.expect(std.mem.endsWith(u8, oneshotProgressLine(), "\n"));+}diff --git a/src/named_work.zig b/src/named_work.zignew file mode 100644index 00000000..ca41533e--- /dev/null+++ b/src/named_work.zig@@ -0,0 +1,71 @@+//! One bounded nudge when the user named a source file and the model+//! answered without touching the tree. The in-house 5/6 miss was this shape:+//! one call, "I'll read SPEC.md…", no edit, tests still fail.+//!+//! Shared by `-p` and the REPL (no oneshot-only skip). At most one extra+//! model call, and only when tools_used is still empty.++const std = @import("std");++const Agent = @import("agent.zig").Agent;+const messages_mod = @import("messages.zig");++pub const max_nudges: u8 = 1;++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.";++const source_needles = [_][]const u8{ ".py", ".zig", ".js", ".ts", "SPEC.md" };++/// 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| {+ if (std.mem.indexOf(u8, text, n) != null) return true;+ }+ return false;+}++pub fn shouldNudge(tools_used: u64, nudges: u8, prompt: []const u8) bool {+ if (nudges >= max_nudges) return false;+ if (tools_used != 0) return false;+ return hasNamedSource(prompt);+}++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 "";+}++/// Append the nudge and ask the caller to `continue` the turn loop.+pub fn handle(self: *Agent, _: []const u8) !bool {+ if (!shouldNudge(self.tools_used.count(), self.named_work_nudges, lastUserText(self)))+ return false;+ self.named_work_nudges += 1;+ try self.messages.append(try messages_mod.textMessage(self.arena, "user", nudge_text));+ return true;+}++test "hasNamedSource sees SPEC and .py, ignores greeting.txt and pong" {+ try std.testing.expect(hasNamedSource("Read SPEC.md and affinity.py"));+ try std.testing.expect(hasNamedSource("Fix fib.py"));+ try std.testing.expect(hasNamedSource("edit stall_notice.py"));+ try std.testing.expect(!hasNamedSource("Reply with exactly: pong"));+ try std.testing.expect(!hasNamedSource("Create hello.txt then rename it"));+}++test "shouldNudge is once, and only when no tools have run" {+ try std.testing.expect(shouldNudge(0, 0, "Fix fib.py"));+ try std.testing.expect(!shouldNudge(1, 0, "Fix fib.py"));+ try std.testing.expect(!shouldNudge(0, 1, "Fix fib.py"));+ try std.testing.expect(!shouldNudge(0, 0, "Reply with exactly: pong"));+}