graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(lean): one-shot catalog is rlm plus attempt_completion
Cursor Agent608a9242357b
diff --git a/lean-proofs/Graff/ToolCatalog.lean b/lean-proofs/Graff/ToolCatalog.leanindex 1b7d1a9e..51836243 100644--- a/lean-proofs/Graff/ToolCatalog.lean+++ b/lean-proofs/Graff/ToolCatalog.lean@@ -26,8 +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",- "subagent", "attempt_completion", "load_tool_schemas"]+ ["attempt_completion", "load_tool_schemas"]def optionalTools : List String :=["imagegen"]@@ -127,7 +126,8 @@ theorem cube_unique :example : mem "webfetch" localTools = false := by native_decideexample : mem "imagegen" localTools = true := by native_decideexample : mem "imagegen" leanTools = false := by native_decide-example : mem "subagent" leanTools = true := by native_decide+example : mem "subagent" leanTools = false := by native_decide+example : mem "attempt_completion" leanTools = true := 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..bc196383 100644--- a/spec/kernels/tool_catalog.json+++ b/spec/kernels/tool_catalog.json@@ -49,12 +49,6 @@"imagegen"],"lean": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb",- "subagent","attempt_completion","load_tool_schemas"]@@ -599,14 +593,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["imagegen"@@ -649,14 +637,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["imagegen"@@ -699,14 +681,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["imagegen"@@ -749,14 +725,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["imagegen"@@ -799,14 +769,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": []},@@ -846,14 +810,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": []},@@ -893,14 +851,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": []},@@ -940,14 +892,8 @@"seat": "root"},"advertised": [- "bash",- "read_file",- "edit_file",- "write_file",- "codedb","attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": []},@@ -1524,8 +1470,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",@@ -1577,8 +1522,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",@@ -1630,8 +1574,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",@@ -1683,8 +1626,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",@@ -1736,8 +1678,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",@@ -1789,8 +1730,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",@@ -1842,8 +1782,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",@@ -1895,8 +1834,7 @@},"advertised": ["attempt_completion",- "load_tool_schemas",- "subagent"+ "load_tool_schemas"],"blocked": ["bash",diff --git a/spec/kernels/tool_catalog.md b/spec/kernels/tool_catalog.mdindex c734fd9a..2de7bd2f 100644--- a/spec/kernels/tool_catalog.md+++ b/spec/kernels/tool_catalog.md@@ -11,7 +11,8 @@ 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+4. **Keep** `--lean` (`attempt_completion` + `load_tool_schemas`;+ `rlm` is a session overlay, not this cube). Description compaction doesnot change names.A subagent starts from `base_specs` only (no meta, no `subagent`), then@@ -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 | `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..38b000db 100644--- a/spec/ref/tool_catalog.py+++ b/spec/ref/tool_catalog.py@@ -22,12 +22,6 @@ LOCAL_TOOLS = ("imagegen",)LEAN_TOOLS = (- "bash",- "read_file",- "edit_file",- "write_file",- "codedb",- "subagent","attempt_completion","load_tool_schemas",)diff --git a/src/cli.zig b/src/cli.zigindex 650b128a..7bd28085 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -251,7 +251,7 @@ pub const usage_text =\\ --yolo skip all permission prompts for the session\\ --rlm advertise the rlm REPL (default; persistent binds, subagent(), llm_query, mid-stream spec-ptc; GRAFF_RLM=1)\\ --old, --no-rlm restore the pre-rlm structured-only catalog (GRAFF_OLD=1 or GRAFF_RLM=0)- \\ --lean slim tool surface (8 core tools) + MCP deferred behind load_tool_schemas — the DEFAULT for -p one-shots (GRAFF_LEAN=1)+ \\ --lean slim tool surface (rlm + attempt_completion) + MCP deferred behind load_tool_schemas — the DEFAULT for -p one-shots (GRAFF_LEAN=1)\\ --no-lean opt a one-shot out of the implied --lean: full tool surface + eager MCP, the pre-default -p behavior\\ --no-local-tools embedder mode: hard-disable the built-in bash/bash_output/bash_kill/read_file/edit_file/write_file/codedb tools for the whole process (subagents included), so graff can run outside the sandbox and get its coding tools from an MCP server instead; webfetch, orchestration and MCP tools still work (GRAFF_NO_LOCAL_TOOLS=1)\\ -p, --print one-shot print mode (answer on stdout, progress on stderr)diff --git a/src/no_local_tools.zig b/src/no_local_tools.zigindex 012d5430..7fc7572e 100644--- a/src/no_local_tools.zig+++ b/src/no_local_tools.zig@@ -67,27 +67,21 @@ pub fn blocks(name: []const u8) bool {/// --lean / GRAFF_LEAN=1 tool surface — the token-cost counterpart of the MCP/// skip (session_start.leanSkipsMcp reads the same flag/env). A one-shot-/// coding task needs seven tools; every other schema is prefix re-sent on-/// EVERY model turn. Measured on the full root catalog: 25.9k schema bytes-/// (~6.5k tokens) against 8.6k (~2.1k) for this subset — ~4.3k tokens saved-/// per turn, the difference between a ~10.7k and a ~6.4k one-shot prefix.-/// Unlike #330 this is NOT a security boundary, so there is no dispatch-/// layer: an unadvertised tool is simply unknown to the model, and a-/// hallucinated call fails like any bad tool name.+/// coding task advertises rlm + attempt_completion; file/shell work is+/// rlm host functions so the prefix is not re-sent as five native schemas+/// on every turn. Unlike #330 this is NOT a security boundary, so there+/// is no dispatch layer: an unadvertised tool is simply unknown to the+/// model, and a hallucinated call fails like any bad tool name.pub var lean: bool = false;-/// The lean keep-list. `subagent` stays in the list (unattended !yolo-/// still delegates; catalogSkips folds it off the wire until loaded).+/// The lean keep-list. Structured file/shell tools stay callable as+/// `rlm` host functions (maybeAppend adds `rlm`); advertising them as+/// their own catalog entries made grok-4.6 do N read/edit turns+/// instead of one script (ADR 0024: 41 calls vs grok's 31)./// `load_tool_schemas` stays so a connected MCP server can unfold; it-/// is hidden on lean when nothing is deferred (schema.zig). Overflow-/// paging (`read_tool_result`) is interactive — drop it from -p.+/// is hidden on lean (schema.zig / hiddenSpec). Overflow paging+/// (`read_tool_result`) is interactive — drop it from -p.pub const lean_tools = [_][]const u8{- "bash",- "read_file",- "edit_file",- "write_file",- "codedb",- "subagent","attempt_completion","load_tool_schemas",};@@ -225,15 +219,15 @@ 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.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);- // Keep-list is eight names: subagent stays (unattended !yolo), load_tool_schemas- // stays (MCP unfold). Overflow pager is gone. Render may hide both.- try std.testing.expectEqual(@as(usize, 8), lean_tools.len);+ try std.testing.expectEqual(@as(usize, 1), kept.len);+ try std.testing.expectEqualStrings("attempt_completion", kept[0].name);+ // Keep-list is two names: attempt_completion + load_tool_schemas (MCP+ // unfold). File/shell work is rlm host functions, not catalog rows.+ try std.testing.expectEqual(@as(usize, 2), lean_tools.len);try std.testing.expect(!leanKeeps("read_tool_result"));+ try std.testing.expect(!leanKeeps("bash"));+ try std.testing.expect(!leanKeeps("read_file"));+ try std.testing.expect(!leanKeeps("subagent"));for (lean_tools) |tool| try std.testing.expect(leanKeeps(tool));try std.testing.expect(!leanKeeps("workflow"));try std.testing.expect(!leanKeeps("todo_write"));@@ -381,7 +375,7 @@ test "lean prompt diet: no fan-out / trace / issue-filing; short local-tools nottry std.testing.expect(std.mem.indexOf(u8, out, "gh issue create") == null);try std.testing.expect(std.mem.indexOf(u8, out, "fan out") == null);try std.testing.expect(std.mem.indexOf(u8, out, "not covered by /rewind") == null);- try std.testing.expect(std.mem.indexOf(u8, out, "list_dir") != null);+ try std.testing.expect(std.mem.indexOf(u8, out, "rlm") != null);try std.testing.expect(std.mem.indexOf(u8, out, "SPEC.md") != null);try std.testing.expect(std.mem.indexOf(u8, out, "discard work") == null);try std.testing.expect(std.mem.indexOf(u8, out, "Fix root causes") == null);@@ -400,5 +394,7 @@ test "lean catalog drops overflow pager and empty load_tool_schemas" {const json = try schema.renderRootTools(arena, .openai, specs, &.{});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, "\"bash\"") == null);+ try std.testing.expect(std.mem.indexOf(u8, json, "\"read_file\"") == null);try std.testing.expect(std.mem.indexOf(u8, json, "\"rlm\"") != null);}diff --git a/src/prompt_text.zig b/src/prompt_text.zigindex 293fdfb2..e5e290db 100644--- a/src/prompt_text.zig+++ b/src/prompt_text.zig@@ -260,16 +260,14 @@ 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 or full rewrites. Exact-key lookup:- \\read_file once with contains. Navigate with codedb (context, around,- \\callpath, list_dir, status), not bash grep/find/ls. Read one current- \\span, smallest edit, do not verify after success.+ \\File and shell work is inside rlm: read_file, edit_file, write_file,+ \\codedb, and bash are script functions, not catalog tools. print() is+ \\the answer. Prefer one rlm over a chain of calls.;pub const lean_intro_note =- \\You are a coding agent. Use only the tools in this session's catalog —- \\never invent a tool or a wrapper. Inspect, then do the work.+ \\You are a coding agent. Do the work with rlm — a script whose+ \\functions ARE this session's tools. Never invent a catalog tool.;pub const lean_work_note =diff --git a/src/rlm.zig b/src/rlm.zigindex 4ea249f1..8ecad31e 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 = "Script of this session's tools. Literal read_file/codedb/bash/llm_query start as it streams. Binds persist. print(...) is the answer. Prefer one rlm over N tool calls.";+pub const lean_tool_desc = "Script of this session's tools. read_file/edit_file/write_file/codedb/bash/llm_query are functions here, not catalog tools. Literal calls start as it streams. Binds persist. print(...) is the answer. Prefer one rlm over N calls.";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"]};@@ -465,7 +465,7 @@ test "maybeAppend keeps subagent and workflow; rlm is never the only catalog tootry std.testing.expect(!catalogHas(off, tool_name));}-test "effectiveRootSpecs: default rlm keeps subagent; --old and --lean do not drop it" {+test "effectiveRootSpecs: default rlm keeps subagent; --old keeps it; --lean drops structured tools" {const schema = @import("schema.zig");const root = @import("main.zig");const learn_store = @import("learn_store.zig");@@ -509,10 +509,11 @@ test "effectiveRootSpecs: default rlm keeps subagent; --old and --lean do not drno_local_tools.lean = true;sync();const lean_on = try schema.effectiveRootSpecs(arena);- try std.testing.expect(catalogHas(lean_on, "subagent"));+ try std.testing.expect(!catalogHas(lean_on, "subagent"));try std.testing.expect(catalogHas(lean_on, tool_name));try std.testing.expect(!catalogHas(lean_on, "workflow"));- try std.testing.expect(no_local_tools.leanKeeps("subagent"));+ try std.testing.expect(!catalogHas(lean_on, "bash"));+ try std.testing.expect(!no_local_tools.leanKeeps("subagent"));try std.testing.expect(!no_local_tools.leanKeeps(tool_name));}diff --git a/src/schema_protocol.zig b/src/schema_protocol.zigindex f350156c..bed155b2 100644--- a/src/schema_protocol.zig+++ b/src/schema_protocol.zig@@ -17,7 +17,7 @@ pub const flags =\\ {"flag": "--yolo", "arg": null, "description": "skip all permission prompts for the session"},\\ {"flag": "--rlm", "arg": null, "description": "advertise the rlm REPL (default). Last flag wins vs --old. GRAFF_RLM=1 is the env form"},\\ {"flag": "--old", "arg": null, "description": "restore the pre-rlm structured-only catalog. --no-rlm is an alias. GRAFF_OLD=1 or GRAFF_RLM=0"},- \\ {"flag": "--lean", "arg": null, "description": "slim the tool surface to 8 core tools and connect MCP servers DEFERRED behind the load_tool_schemas meta tool (names + one-line descriptions up front, full schemas on demand) instead of paying every server's schemas in every model turn. DEFAULT for -p one-shots; GRAFF_LEAN=1 forces it on anywhere"},+ \\ {"flag": "--lean", "arg": null, "description": "slim the tool surface to rlm plus attempt_completion and connect MCP servers DEFERRED behind the load_tool_schemas meta tool (names + one-line descriptions up front, full schemas on demand) instead of paying every server's schemas in every model turn. DEFAULT for -p one-shots; GRAFF_LEAN=1 forces it on anywhere"},\\ {"flag": "--no-lean", "arg": null, "description": "opt a one-shot out of the implied --lean: full tool surface and eager MCP schemas, the pre-default -p behavior"},\\ {"flag": "--add-dir", "arg": "path", "description": "extra workspace root file tools may touch (repeatable, max 16). Complementary to workspace switch; extra roots do not contribute skills or sessions"},\\ {"flag": "--context-limit", "arg": "name=N", "description": "named prefix byte cap: skill_catalog_bytes, mcp_schema_bytes, or agents_md_bytes (repeatable). GRAFF_CONTEXT_LIMIT is the env form"},diff --git a/src/spec_ptc.zig b/src/spec_ptc.zigindex 82045c01..67a6f2be 100644--- a/src/spec_ptc.zig+++ b/src/spec_ptc.zig@@ -289,6 +289,8 @@ fn canonicalize(arena: Allocator, tool: []const u8, args: []const Arg) ![]constfn hostField(tool: []const u8) []const u8 {if (std.mem.eql(u8, tool, "read_file")) return "path";+ if (std.mem.eql(u8, tool, "edit_file")) return "path";+ if (std.mem.eql(u8, tool, "write_file")) return "path";if (std.mem.eql(u8, tool, "codedb")) return "command";if (std.mem.eql(u8, tool, "sleep_ms")) return "ms";if (std.mem.eql(u8, tool, "llm_query")) return "prompt";