graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(flags): --lean / GRAFF_LEAN=1 — skip MCP entirely for a smaller per-turn prefix
Rach Pradhand6679c9d79fb
diff --git a/src/args.zig b/src/args.zigindex 7c7a7f2a..7d60377b 100644--- a/src/args.zig+++ b/src/args.zig@@ -31,6 +31,7 @@ const no_local_tools = @import("no_local_tools.zig"); // #330: `--no-local-tools/// after the parse loop. One field per former local, same default.pub const Flags = struct {yolo_flag: bool = false,+ 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,schema_flag: bool = false,@@ -93,6 +94,8 @@ pub fn parse(init: std.process.Init) !Flags {} else if (std.mem.startsWith(u8, arg, "-")) {if (std.mem.eql(u8, arg, "--yolo")) {flags.yolo_flag = true;+ } else if (std.mem.eql(u8, arg, "--lean")) {+ flags.lean_flag = true;} 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")) {diff --git a/src/cli.zig b/src/cli.zigindex 03a63e4a..2e3c0a49 100644--- a/src/cli.zig+++ b/src/cli.zig@@ -124,6 +124,7 @@ 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 do not connect MCP servers at all — a smaller per-turn context prefix for one-shot/CI runs (GRAFF_LEAN=1)\\ --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/schema_protocol.zig b/src/schema_protocol.zigindex 9457c591..076df334 100644--- a/src/schema_protocol.zig+++ b/src/schema_protocol.zig@@ -15,6 +15,7 @@ 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": "do not connect MCP servers at all: a smaller per-turn context prefix for one-shot/CI runs (connected servers pay their tool schemas into every model turn). GRAFF_LEAN=1 is the equivalent"},\\ {"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 08366155..b0250869 100644--- a/src/session_start.zig+++ b/src/session_start.zig@@ -362,6 +362,15 @@ 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: skip MCP connection entirely. Connected servers pay+/// their tool schemas into the prefix of EVERY model turn — measured ~6k+/// tokens for a licensed codedbpro alone against a ~7.4k native baseline, so+/// an MCP-heavy config roughly doubles the context bill of a one-shot. Lean+/// is the one-shot/CI answer; interactive sessions keep the consent flow.+pub fn leanSkipsMcp(lean_flag: bool, environ_map: anytype) bool {+ return lean_flag 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 {const global_path = mcp_config.globalPath(arena, home, environ_map);const sink = engine_sink.writerSink(out);@@ -384,8 +393,9 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wrsink.emit(io, dimNotice(try std.fmt.allocPrint(arena, "ignoring ~/" ++ mcp_config.unsupported_rel_path ++ ": unsupported path — use ~/" ++ mcp_config.global_rel_path ++ " (global) or {s} (project)", .{mcp_config_path})));}const mcp_count = mcp_cli.countMcpServers(merged);- var connect_mcp = flags.yolo_flag or mcp_count == 0;- if (mcp_count > 0 and !flags.yolo_flag and !json_mode and use_color) {+ const lean = leanSkipsMcp(flags.lean_flag, environ_map);+ var connect_mcp = !lean and (flags.yolo_flag or mcp_count == 0);+ if (mcp_count > 0 and !lean and !flags.yolo_flag and !json_mode and use_color) {sink.emit(io, .{ .mcp_consent_prompt = .{ .count = mcp_count } });// Still an inline read: only the QUESTION is inverted here, and the// answer becomes a typed command in #430 (input inversion).@@ -408,6 +418,17 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wrreturn registry;}+/// Licensed startup path (main.zig): probe the companion's license, and when+/// paid ALSO pin the server eager in the #416 schema gate — a licensed user+/// pays for these tools, so their full schemas belong in every request rather+/// than behind a per-session load_tool_schemas toll that steers the model+/// back to the native defaults. Runs before the first catalog render.+pub fn probeLicensedPinEager(gpa: Allocator, arena: Allocator, io: Io) bool {+ if (!skills.probeCodedbproLicensed(gpa, io)) return false;+ mcp_schema_gate.pinEagerRuntime(arena, "codedbpro");+ return true;+}+/// Companion auto-activation: if the metered code-intelligence companion/// (codedb-pro, formerly muonry) is installed but nothing connected it (no/// workspace .mcp.json entry, or consent declined), spawn it directly — a@@ -418,6 +439,9 @@ pub fn initRegistryConsent(io: Io, gpa: Allocator, arena: Allocator, out: *Io.Wr/// already main()-owned and stable by the time this is called, so a pointer/// is all that's needed — no return-by-value trickery here).pub fn connectCompanion(io: Io, arena: Allocator, registry: *mcp.Registry, flags: args.Flags, out: *Io.Writer, json_mode: bool, environ_map: anytype) !void {+ // --lean / GRAFF_LEAN=1 skips ALL MCP, the auto-companion and the bundled+ // Smolify registration included — lean means no MCP tool schemas at all.+ if (leanSkipsMcp(flags.lean_flag, environ_map)) return;const sink = engine_sink.writerSink(out);const speak = !json_mode and flags.oneshot_prompt == null;connect: {@@ -452,6 +476,16 @@ fn dimNotice(text: []const u8) engine_events.EngineEvent {return .{ .session_notice = .{ .text = text, .tone = .dim } };}+test "lean skips MCP: flag or GRAFF_LEAN env, never the default" {+ var env = std.process.Environ.Map.init(std.testing.allocator);+ defer env.deinit();+ try std.testing.expect(!leanSkipsMcp(false, env)); // default: consent flow decides+ try std.testing.expect(leanSkipsMcp(true, env)); // --lean wins alone+ try env.put("GRAFF_LEAN", "1");+ try std.testing.expect(leanSkipsMcp(false, env)); // env wins alone+ try std.testing.expect(leanSkipsMcp(true, env));+}+test "core Smolify registration is offline and lazy" {var registry = mcp.Registry.empty(std.testing.allocator, std.testing.io);defer registry.deinit();