graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(lean): lean is the one-shot DEFAULT — -p implies --lean, --no-lean opts out
Rach Pradhanfe0602c4028f
diff --git a/src/args.zig b/src/args.zigindex b18b1d7a..02f95e07 100644--- a/src/args.zig+++ b/src/args.zig@@ -32,6 +32,7 @@ const no_local_tools = @import("no_local_tools.zig"); // #330: `--no-local-toolspub const Flags = struct {yolo_flag: bool = false,safe_flag: bool = false, // --safe: one-shot WITHOUT the implied --yolo (approval-gated, the old -p default)+ no_lean_flag: bool = false, // --no-lean: one-shot WITHOUT the implied --lean (full tool surface + eager MCP, the old -p default)lean_flag: bool = false, // --lean: skip connecting MCP servers entirely (GRAFF_LEAN=1) — a smaller per-turn prefix for one-shot/CI runsno_telemetry_flag: bool = false,learning_privacy_flag: ?learning_privacy.Mode = null,@@ -83,6 +84,15 @@ pub const Flags = struct {pub fn effectiveYolo(flags: Flags) bool {return flags.yolo_flag or (flags.oneshot_prompt != null and !flags.safe_flag);}++ /// --lean is the one-shot default (measured: full catalog + eager MCP+ /// roughly doubles a one-shot's per-turn prefix for capability one-shots+ /// rarely exercise); interactive sessions keep the full surface, where+ /// todos/workflow/peer tooling earn their bytes. --no-lean opts back+ /// into the old full-surface -p; explicit --lean always wins.+ pub fn effectiveLean(flags: Flags) bool {+ return flags.lean_flag or (flags.oneshot_prompt != null and !flags.no_lean_flag);+ }};/// Parses argv (via init.minimal.args) into a `Flags`. Fatals via@@ -106,9 +116,10 @@ pub fn parse(init: std.process.Init) !Flags {flags.yolo_flag = true;} else if (std.mem.eql(u8, arg, "--safe")) {flags.safe_flag = true;+ } else if (std.mem.eql(u8, arg, "--no-lean")) {+ flags.no_lean_flag = true;} else if (std.mem.eql(u8, arg, "--lean")) {flags.lean_flag = true;- no_local_tools.lean = true; // the tool-surface half of lean (the MCP half reads lean_flag via session_start.leanSkipsMcp)} else if (std.mem.eql(u8, arg, "--worktree") or std.mem.eql(u8, arg, "-w")) {flags.worktree_flag = it.next() orelse std.process.fatal("--worktree needs a name (e.g. --worktree agent1)", .{});} else if (std.mem.eql(u8, arg, "--goal")) {@@ -222,6 +233,12 @@ pub fn parse(init: std.process.Init) !Flags {}if (flags.print_flag and flags.oneshot_prompt == null) std.process.fatal("-p needs a prompt: harness -p \"do something\"", .{});+ // The tool-surface half of lean, set AFTER the one-shot prompt is+ // assembled: on for --lean and for every one-shot without --no-lean (the+ // MCP half reads effectiveLean through session_start.leanMode; env+ // GRAFF_LEAN sets the same global in session_settings.applyEnvKnobs).+ if (flags.effectiveLean()) no_local_tools.lean = true;+return flags;}@@ -232,3 +249,11 @@ test "effectiveYolo: -p implies yolo, --safe opts out, interactive untouched" {try std.testing.expect(!Flags.effectiveYolo(.{}));try std.testing.expect(Flags.effectiveYolo(.{ .oneshot_prompt = "fix it", .yolo_flag = true, .safe_flag = true })); // explicit --yolo wins over --safe}++test "effectiveLean: -p implies lean, --no-lean opts out, interactive keeps the full surface" {+ try std.testing.expect(Flags.effectiveLean(.{ .lean_flag = true }));+ try std.testing.expect(Flags.effectiveLean(.{ .oneshot_prompt = "fix it" }));+ try std.testing.expect(!Flags.effectiveLean(.{ .oneshot_prompt = "fix it", .no_lean_flag = true }));+ try std.testing.expect(!Flags.effectiveLean(.{}));+ try std.testing.expect(Flags.effectiveLean(.{ .oneshot_prompt = "fix it", .lean_flag = true, .no_lean_flag = true })); // explicit --lean wins over --no-lean+}diff --git a/src/cli.zig b/src/cli.zigindex 8c9130f6..8d02995e 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -124,7 +124,8 @@ pub const usage_text =\\ -w, --worktree <name> isolate this session in a git worktree (.graff/worktrees/<name>) so parallel agents don't collide on files\\ --no-autocommit with -w, don't auto-commit each turn (default on; land work with `graff worktree merge`)\\ --yolo skip all permission prompts for the session- \\ --lean one-shot/CI mode: slim tool surface (8 core tools), and MCP servers connect DEFERRED behind load_tool_schemas instead of paying full schemas every turn (GRAFF_LEAN=1)+ \\ --lean slim tool surface (8 core tools) + 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)\\ --timing show per-tool wall-clock on result linesdiff --git a/src/main.zig b/src/main.zigindex 78f234ec..360da848 100644--- a/src/main.zig+++ b/src/main.zig@@ -392,7 +392,7 @@ pub fn main(init: std.process.Init) !void {try session_start.connectCompanion(io, arena, ®istry_storage, flags, out, json_mode, init.environ_map);const mcp_tools: []const mcp.Tool = registry_storage.tools;// If the metered companion connected, probe its license once so the note below can lean into paid tools (vs the conservative free-codedb note).- if (!session_start.leanMode(flags.lean_flag, init.environ_map) and mcpServerConnected(mcp_tools, "codedbpro")) g_codedbpro_licensed = probeLicensedPinEager(gpa, arena, io);+ if (!session_start.leanMode(flags.effectiveLean(), init.environ_map) and mcpServerConnected(mcp_tools, "codedbpro")) g_codedbpro_licensed = probeLicensedPinEager(gpa, arena, io);boot.mark(io, "companion");var approvals: Approvals = undefined;diff --git a/src/schema_protocol.zig b/src/schema_protocol.zigindex 68ef4e57..5cc1457e 100644--- a/src/schema_protocol.zig+++ b/src/schema_protocol.zig@@ -15,7 +15,8 @@ pub const flags =\\ {"flag": "--allow-cross-provider-subagents", "arg": null, "description": "explicitly consent to sending worker prompts, code, and tool results to a provider different from the root"},\\ {"flag": "--no-subagent-tier", "arg": null, "description": "opt out of the default worker tier ladder; workers inherit the root model unless an explicit --subagent-model is given"},\\ {"flag": "--yolo", "arg": null, "description": "skip all permission prompts for the session"},- \\ {"flag": "--lean", "arg": null, "description": "one-shot/CI mode: 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. GRAFF_LEAN=1 is the equivalent"},+ \\ {"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": "--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": "--no-local-tools", "arg": null, "description": "embedder mode: hard-disable the built-in bash/bash_output/bash_kill/read_file/edit_file/write_file/codedb tools for the whole process, so the harness can run outside the sandbox and source its coding tools from an MCP server instead; webfetch, orchestration and MCP tools are unaffected, and subagents inherit the gate. GRAFF_NO_LOCAL_TOOLS=1 is the equivalent"},\\ {"flag": "--system-prompt", "arg": "text", "description": "replace the built-in system prompt (cwd project-instructions file is still appended)"},\\ {"flag": "--append-system-prompt", "arg": "text", "description": "append extra text to the end of the system prompt"},diff --git a/src/session_start.zig b/src/session_start.zigindex 036e8c05..bde1ff92 100644--- a/src/session_start.zig+++ b/src/session_start.zig@@ -362,15 +362,16 @@ pub fn initTelemetry(io: Io, gpa: Allocator, client: *std.http.Client, environ_m/// out of main() (600-line goal). Returns the Registry by value — mcp.Registry/// holds no self-references (its storage is ArrayList/HashMap-backed), so/// returning it is safe.-/// --lean / GRAFF_LEAN=1. Lean no longer SKIPS MCP — it folds every server-/// behind the load_tool_schemas meta tool (mcp_schema_gate.deferAllRuntime):-/// connected servers pay names + one-line descriptions instead of full-/// schemas, and capability survives a load call away. Measured prefix cost-/// of eager MCP: ~3.3k tokens for a licensed codedbpro alone, on EVERY-/// model turn. One-shot/CI runs count those; interactive keeps the consent-/// flow and eager pins.-pub fn leanMode(lean_flag: bool, environ_map: anytype) bool {- return lean_flag or environ_map.get("GRAFF_LEAN") != null;+/// --lean / GRAFF_LEAN=1, and (via Flags.effectiveLean) every one-shot that+/// did not --no-lean: lean is the one-shot DEFAULT. Lean no longer SKIPS+/// MCP — it folds every server behind the load_tool_schemas meta tool+/// (mcp_schema_gate.deferAllRuntime): connected servers pay names + one-line+/// descriptions instead of full schemas, and capability survives a load+/// call away. Measured prefix cost of eager MCP: ~3.3k tokens for a+/// licensed codedbpro alone, on EVERY model turn. Interactive sessions are+/// untouched: full surface, consent flow, eager pins.+pub fn leanMode(effective_lean: bool, environ_map: anytype) bool {+ return effective_lean or environ_map.get("GRAFF_LEAN") != null;}pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Writer, in: *Io.Reader, flags: args.Flags, mcp_config_path: []const u8, home: []const u8, use_color: bool, json_mode: bool, environ_map: anytype) !mcp.Registry {@@ -386,7 +387,7 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wrmcp_schema_gate.configure(arena, merged, environ_map);// --lean folds every server behind the meta tool (deferAllRuntime) rather// than skipping MCP: capability a load call away, ~zero schema prefix.- if (leanMode(flags.lean_flag, environ_map)) mcp_schema_gate.deferAllRuntime();+ if (leanMode(flags.effectiveLean(), environ_map)) mcp_schema_gate.deferAllRuntime();if (!quiet) {// Reported here rather than in `Registry.init`, which never runs when// consent is declined — a config that does not parse must be named