graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(lean): drop catalog read_file; same-turn verify+complete
Cursor Agent4b71647407a2
diff --git a/lean-proofs/Graff/ToolCatalog.lean b/lean-proofs/Graff/ToolCatalog.leanindex 1b7d1a9e..3d75b3d5 100644--- a/lean-proofs/Graff/ToolCatalog.lean+++ b/lean-proofs/Graff/ToolCatalog.lean@@ -26,7 +26,7 @@ def localTools : List String :="write_file", "codedb", "read_tool_result", "imagegen"]def leanTools : List String :=- ["bash", "read_file", "edit_file", "write_file", "codedb",+ ["bash", "edit_file", "write_file", "codedb","subagent", "attempt_completion", "load_tool_schemas"]def optionalTools : List String :=@@ -128,6 +128,8 @@ example : mem "webfetch" localTools = false := by native_decideexample : mem "imagegen" localTools = true := by native_decideexample : mem "imagegen" leanTools = false := by native_decideexample : mem "subagent" leanTools = true := by native_decide+example : mem "read_file" leanTools = false := by native_decide+example : advertised { lean := true } "read_file" = false := by native_decideexample : unique (baseTools ++ metaTools ++ rootExtras) = true := by native_decideexample : catalog {} =diff --git a/spec/kernels/tool_catalog.json b/spec/kernels/tool_catalog.jsonindex 7d7726ba..abb91362 100644--- a/spec/kernels/tool_catalog.json+++ b/spec/kernels/tool_catalog.json@@ -50,7 +50,6 @@],"lean": ["bash",- "read_file","edit_file","write_file","codedb",@@ -600,7 +599,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",@@ -650,7 +648,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",@@ -700,7 +697,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",@@ -750,7 +746,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",@@ -800,7 +795,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",@@ -847,7 +841,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",@@ -894,7 +887,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",@@ -941,7 +933,6 @@},"advertised": ["bash",- "read_file","edit_file","write_file","codedb",diff --git a/spec/kernels/tool_catalog.md b/spec/kernels/tool_catalog.mdindex c734fd9a..40e71dc1 100644--- a/spec/kernels/tool_catalog.md+++ b/spec/kernels/tool_catalog.md@@ -11,8 +11,9 @@ always in this order:two compile-time optional rows).2. **Add** every `#352` optional whose flag is on (`imagegen` today).3. **Subtract** `#330` `--no-local-tools` (host-touching built-ins).-4. **Keep** `--lean` (eight one-shot tools). Description compaction does- not change names.+4. **Keep** `--lean` (seven one-shot tools; catalog `read_file` is+ dropped — reads go through `rlm` host functions or `codedb`).+ Description compaction does not change names.A subagent starts from `base_specs` only (no meta, no `subagent`), thenapplies (2) and (3). `--lean` is a root-prefix concern; children do not@@ -27,7 +28,7 @@ run the keep-list.| root extras | `subagent` `workflow` `agent_output` `learn_candidate` `peer_message` `workspace` || optional | `imagegen` || local (`#330`) | `bash` `bash_output` `bash_kill` `read_file` `edit_file` `write_file` `codedb` `read_tool_result` `imagegen` |-| lean keep | `bash` `read_file` `edit_file` `write_file` `codedb` `subagent` `attempt_completion` `load_tool_schemas` |+| lean keep | `bash` `edit_file` `write_file` `codedb` `subagent` `attempt_completion` `load_tool_schemas` |`webfetch`, every meta tool except the lean keepers, and every `mcp__*`name are **not** local. MCP is outside this kernel.diff --git a/spec/ref/tool_catalog.py b/spec/ref/tool_catalog.pyindex 4f09fdde..a258e3f2 100644--- a/spec/ref/tool_catalog.py+++ b/spec/ref/tool_catalog.py@@ -23,7 +23,6 @@ LOCAL_TOOLS = ()LEAN_TOOLS = ("bash",- "read_file","edit_file","write_file","codedb",diff --git a/src/agent_eval_control.zig b/src/agent_eval_control.zigindex b3048bec..78981526 100644--- a/src/agent_eval_control.zig+++ b/src/agent_eval_control.zig@@ -40,3 +40,43 @@ pub fn toolInvalidatesEval(call: ToolCall) bool {if (std.mem.startsWith(u8, call.name, "mcp__")) return !companionReadOnly(call.name, call.input);return true;}++/// edit/write/rlm/subagent in the same batch as attempt_completion still+/// refuse immediately: those calls change the tree the claim is about and+/// may fail. bash/read/codedb are verify/read — they run first, then+/// completion is accepted only if none failed (ADR 0024 turn tax vs grok).+pub fn batchBlocksCompletion(calls: []const ToolCall) bool {+ for (calls) |call| {+ if (std.mem.eql(u8, call.name, "edit_file") or+ std.mem.eql(u8, call.name, "write_file") or+ std.mem.eql(u8, call.name, "rlm") or+ std.mem.eql(u8, call.name, "subagent")) return true;+ if (std.mem.startsWith(u8, call.name, "mcp__")) return !companionReadOnly(call.name, call.input);+ }+ return false;+}++pub fn completionIndex(calls: []const ToolCall) ?usize {+ for (calls, 0..) |call, index| {+ if (std.mem.eql(u8, call.name, "attempt_completion")) return index;+ }+ return null;+}++/// True when attempt_completion shares the batch with a verify/read tool+/// and no workspace mutation. runTools executes those tools first, then+/// accepts completion only if none failed.+pub fn shouldDeferCompletion(calls: []const ToolCall) bool {+ if (completionIndex(calls) == null) return false;+ if (batchBlocksCompletion(calls)) return false;+ for (calls) |call| {+ if (!isMetaName(call.name)) return true;+ }+ return false;+}++pub const completion_with_mutation =+ "attempt_completion must be a separate post-verification action; this batch also contains a workspace-changing tool";++pub const completion_verify_failed =+ "attempt_completion was not accepted: a verify tool in this batch failed. Fix that result, then complete.";diff --git a/src/agent_eval_control_tests.zig b/src/agent_eval_control_tests.zigindex 680bca06..3937536d 100644--- a/src/agent_eval_control_tests.zig+++ b/src/agent_eval_control_tests.zig@@ -59,6 +59,42 @@ test "workspace-changing tools stale verification while read-only tools do not"try std.testing.expect(agent_tools.toolInvalidatesEval(try call(arena, "mcp__codedbpro__edit", "{}")));}+test "verify bash does not block same-batch attempt_completion; edit/rlm still do" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const arena = arena_state.allocator();+ const bash_done = [_]ToolCall{+ try call(arena, "bash", "{}"),+ try call(arena, "attempt_completion", "{\"result\":\"done\"}"),+ };+ try std.testing.expect(!eval_control.batchBlocksCompletion(&bash_done));+ try std.testing.expect(eval_control.shouldDeferCompletion(&bash_done));+ try std.testing.expectEqual(@as(?usize, 1), eval_control.completionIndex(&bash_done));++ const read_done = [_]ToolCall{+ try call(arena, "codedb", "{}"),+ try call(arena, "attempt_completion", "{\"result\":\"done\"}"),+ };+ try std.testing.expect(eval_control.shouldDeferCompletion(&read_done));++ const edit_done = [_]ToolCall{+ try call(arena, "edit_file", "{}"),+ try call(arena, "attempt_completion", "{\"result\":\"done\"}"),+ };+ try std.testing.expect(eval_control.batchBlocksCompletion(&edit_done));+ try std.testing.expect(!eval_control.shouldDeferCompletion(&edit_done));++ const rlm_done = [_]ToolCall{+ try call(arena, "rlm", "{}"),+ try call(arena, "attempt_completion", "{\"result\":\"done\"}"),+ };+ try std.testing.expect(eval_control.batchBlocksCompletion(&rlm_done));+ try std.testing.expect(!eval_control.shouldDeferCompletion(&rlm_done));++ const only_done = [_]ToolCall{try call(arena, "attempt_completion", "{\"result\":\"done\"}")};+ try std.testing.expect(!eval_control.shouldDeferCompletion(&only_done));+}+test "eval is a solo verifier boundary in a tool batch" {var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);defer arena_state.deinit();diff --git a/src/agent_tools.zig b/src/agent_tools.zigindex 9a5ed5ef..e6314dfa 100644--- a/src/agent_tools.zig+++ b/src/agent_tools.zig@@ -69,13 +69,8 @@ const rawNonblockStdin = Agent.rawNonblockStdin;pub fn runTools(self: *Agent, calls: []const ToolCall) ![]ExecResult {const results = try self.arena.alloc(ExecResult, calls.len);const eval_index = eval_control.evalCallIndex(calls);- var batch_may_change_workspace = false;- for (calls) |call| {- if (toolInvalidatesEval(call)) {- batch_may_change_workspace = true;- break;- }- }+ const blocks_completion = eval_control.batchBlocksCompletion(calls);+ const defer_completion = eval_control.shouldDeferCompletion(calls);// Collect the indices of external (non-meta) calls for parallel exec.var ext_idx: std.ArrayList(usize) = .empty;@@ -86,10 +81,12 @@ pub fn runTools(self: *Agent, calls: []const ToolCall) ![]ExecResult {results[i] = .{ .text = eval_control.verifier_boundary, .is_error = true };continue;};- if (batch_may_change_workspace and std.mem.eql(u8, call.name, "attempt_completion")) {- const message = "attempt_completion must be a separate post-verification action; this batch also contains a workspace-changing tool";- self.emitToolRejected(call, "eval_stale", message);- results[i] = .{ .text = message, .is_error = true };+ if (std.mem.eql(u8, call.name, "attempt_completion") and blocks_completion) {+ self.emitToolRejected(call, "eval_stale", eval_control.completion_with_mutation);+ results[i] = .{ .text = eval_control.completion_with_mutation, .is_error = true };+ continue;+ }+ if (std.mem.eql(u8, call.name, "attempt_completion") and defer_completion) {continue;}if (try self.rejectToolCall(call)) |denied| {@@ -195,6 +192,21 @@ pub fn runTools(self: *Agent, calls: []const ToolCall) ![]ExecResult {engine_sink.forAgent(self).emit(self.io, .{ .parallel_batch_finished = tally });}}+ if (defer_completion) if (eval_control.completionIndex(calls)) |i| {+ var verify_failed = ext_idx.items.len == 0;+ for (ext_idx.items) |j| {+ if (results[j].is_error or results[j].cancelled) verify_failed = true;+ }+ if (verify_failed) {+ self.emitToolRejected(calls[i], "eval_stale", eval_control.completion_verify_failed);+ results[i] = .{ .text = eval_control.completion_verify_failed, .is_error = true };+ } else if (try self.rejectToolCall(calls[i])) |denied| {+ results[i] = denied;+ } else {+ try self.sayToolUse(calls[i]);+ results[i] = try self.handleMeta(calls[i]);+ }+ };// Show a compact ✓/✗ + preview for each non-meta call (no-op for subs).for (calls, results) |call, r| self.sayToolResult(call.name, r);return results;diff --git a/src/no_local_tools.zig b/src/no_local_tools.zigindex 48f5d1ad..18c0381c 100644--- a/src/no_local_tools.zig+++ b/src/no_local_tools.zig@@ -74,11 +74,13 @@ pub var lean: bool = false;/// The lean keep-list. File/shell tools stay on the wire: an rlm-only/// catalog (ADR 0024 follow-up) made grok-4.6 retry scripts for 122-/// calls / 4/6. `load_tool_schemas` stays so MCP can unfold; it is-/// hidden on lean. Overflow paging (`read_tool_result`) is interactive.+/// calls / 4/6. Catalog `read_file` is the leftover re-read tax — the+/// model already printed those files via rlm, then called read_file+/// again (ADR 0024). Reads stay as rlm host functions + codedb.+/// `load_tool_schemas` stays so MCP can unfold; it is hidden on lean.+/// Overflow paging (`read_tool_result`) is interactive.pub const lean_tools = [_][]const u8{"bash",- "read_file","edit_file","write_file","codedb",@@ -220,13 +222,13 @@ test "lean: the filter keeps exactly the seven one-shot tools, and allocates notlean = true;const kept = try filterLeanSpecs(Spec, arena, &specs);- try std.testing.expectEqual(@as(usize, 4), kept.len);+ try std.testing.expectEqual(@as(usize, 3), kept.len);try std.testing.expectEqualStrings("bash", kept[0].name);- try std.testing.expectEqualStrings("read_file", kept[1].name);- try std.testing.expectEqualStrings("subagent", kept[2].name);- try std.testing.expectEqualStrings("attempt_completion", kept[3].name);- try std.testing.expectEqual(@as(usize, 8), lean_tools.len);+ try std.testing.expectEqualStrings("subagent", kept[1].name);+ try std.testing.expectEqualStrings("attempt_completion", kept[2].name);+ try std.testing.expectEqual(@as(usize, 7), lean_tools.len);try std.testing.expect(!leanKeeps("read_tool_result"));+ try std.testing.expect(!leanKeeps("read_file")); // host fn on rlm, not a catalog tool on -pfor (lean_tools) |tool| try std.testing.expect(leanKeeps(tool));try std.testing.expect(!leanKeeps("workflow"));try std.testing.expect(!leanKeeps("todo_write"));@@ -396,4 +398,5 @@ test "lean catalog drops overflow pager and empty load_tool_schemas" {try std.testing.expect(std.mem.indexOf(u8, json, "read_tool_result") == null);try std.testing.expect(std.mem.indexOf(u8, json, "load_tool_schemas") == null);try std.testing.expect(std.mem.indexOf(u8, json, "\"rlm\"") != null);+ try std.testing.expect(std.mem.indexOf(u8, json, "\"name\":\"read_file\"") == null);}diff --git a/src/prompt_text.zig b/src/prompt_text.zigindex 2d6f51f4..6d1b766f 100644--- a/src/prompt_text.zig+++ b/src/prompt_text.zig@@ -260,10 +260,10 @@ pub const parallel_tools_note = parallel_core_note ++ parallel_examples_note ++/// covers the !yolo map). Same edit discipline, ~1k fewer prefix bytes.pub const lean_local_tools_note =\\- \\read_file before editing; prefer edit_file for existing files and- \\write_file only for new files. Navigate with codedb (context, around,- \\callpath, list_dir, status) or one rlm script of those functions.- \\Independent reads belong in ONE response or one rlm script, not a chain of turns.+ \\Read files through one rlm script (host read_file/codedb) or codedb.+ \\Prefer edit_file for existing files and write_file only for new files.+ \\Independent reads belong in ONE rlm script, not a chain of turns.+ \\A passing verify command and attempt_completion belong in ONE response.;/// --lean swap-in for `parallel_core_note`. The long Parallelize / fan-out@@ -271,14 +271,15 @@ pub const lean_local_tools_note =/// model spends one API call per read (ADR 0024 leftover vs grok).pub const lean_parallel_note =\\- \\Independent reads and checks belong in ONE response; they run concurrently.+ \\Independent reads belong in one rlm script; they run as it streams.\\A call that needs an earlier result, or two writes to the same file, stays- \\in its own turn.+ \\in its own turn. A passing verify and attempt_completion share a response.;pub const lean_intro_note =\\You are a coding agent. Use the cataloged tools; never invent one.- \\Independent reads belong in ONE response (or one rlm script), not one per turn.+ \\Read files through rlm (or codedb), then edit. A passing test and+ \\attempt_completion belong in ONE response.;pub const lean_work_note =diff --git a/src/rlm.zig b/src/rlm.zigindex a39e5dcd..a812dbd0 100644--- a/src/rlm.zig+++ b/src/rlm.zig@@ -24,7 +24,7 @@ pub const tool_name = "rlm";pub const tool_desc = "Programmatic tool calling (RLM + sPTC). Script whose functions ARE this session's tools. Independent literal read_file/codedb/bash/webfetch/sleep_ms/llm_query/subagent calls start as the script streams. Binds persist across rlm calls. subagent(\"task\") is sidecar-only (keep the critical-path next step local; sync in v1; run_in_background=true returns an id). print() is the answer. Example: a = read_file(\"src/main.zig\"); b = codedb(\"status\"); print(a, b). No imports, no control flow. Prefer one rlm over N tool calls.";/// --lean catalog desc: same contract, no REPL essay. maybeAppend is after/// compactLeanSpecs, so this is the one-shot wire text.-pub const lean_tool_desc = "Batch independent read_file/edit_file/write_file/codedb/bash here. Those names are also catalog tools — use either a script or several catalog calls in ONE response. Literal calls start as it streams. Binds persist. print(...) is the answer.";+pub const lean_tool_desc = "Read files here (host read_file/codedb/bash). Those reads are not a catalog tool on -p — print() is the answer, then edit_file/write_file/bash as catalog tools. Literal calls start as it streams. Binds persist.";pub const tool_schema =\\{"type": "object", "properties": {"code": {"type": "string", "description": "Python-like script: name = read_file(\"path\") / codedb(\"command\") / bash(\"cmd\") / sleep_ms(ms) / llm_query(\"prompt\") / subagent(\"task\"); print(...) is the result. Assignments persist across rlm calls. Semicolons or newlines separate statements."}}, "required": ["code"]};