graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(lean): one-shots skip channel backlog; compact lean subagent schema
Rach Pradhana7aeb2eb71b3
diff --git a/src/no_local_tools.zig b/src/no_local_tools.zigindex f5d0f8da..3c9febf6 100644--- a/src/no_local_tools.zig+++ b/src/no_local_tools.zig@@ -113,6 +113,24 @@ pub fn filterLeanSpecs(comptime Spec: type, arena: Allocator, specs: []const Spereturn buf[0..kept];}+/// --lean's compact subagent description: same name and JSON schema, a+/// fraction of the prose. The full description is 1.9k bytes of workflow,+/// persona and tier/effort precedence detail a one-shot never exercises;+/// the lean seven keep this tool BECAUSE unattended delegation goes through+/// it, so its price is the one worth shrinking (~350 tokens/turn saved).+pub const lean_subagent_desc = "Spawn a subagent for a self-contained task. It has bash, read_file, edit_file, write_file, codedb and does NOT share your context — the prompt must say everything. Returns its final report. In an unattended session the root's bash/edit tools are approval-denied and a subagent's are not: delegate implementation and command execution to one (tier \"small\" for mechanical work).";++/// schema.zig chains this after filterLeanSpecs: identical names and JSON+/// schemas, compact prose. Returns the input untouched when lean is off.+pub fn compactLeanSpecs(comptime Spec: type, arena: Allocator, specs: []const Spec) ![]const Spec {+ if (!lean) return specs;+ const buf = try arena.dupe(Spec, specs);+ for (buf) |*spec| {+ if (std.mem.eql(u8, spec.name, "subagent")) spec.desc = lean_subagent_desc;+ }+ return buf;+}+/// Refusal text. Names the flag so the model stops retrying the same call, and/// points it at what does work in this deployment.pub const refusal_text = "--no-local-tools is set for this process: the built-in bash, bash_output, bash_kill, read_file, edit_file, write_file and codedb tools are hard-disabled and cannot be re-enabled by asking. Run commands and touch files through the sandbox tools the connected MCP server provides instead; webfetch still works.";@@ -181,7 +199,7 @@ test "#330: GRAFF_NO_LOCAL_TOOLS is affirmative-only" {}test "lean: the filter keeps exactly the seven one-shot tools, and allocates nothing when off" {- const Spec = struct { name: []const u8 };+ const Spec = struct { name: []const u8, desc: []const u8 = "" };const specs = [_]Spec{.{ .name = "bash" },.{ .name = "workflow" },@@ -215,6 +233,17 @@ test "lean: the filter keeps exactly the seven one-shot tools, and allocates nottry std.testing.expect(!leanKeeps("workflow"));try std.testing.expect(!leanKeeps("todo_write"));try std.testing.expect(!leanKeeps("webfetch"));+ // …and the compact pass shrinks subagent's prose, leaves its name/schema+ // and every other tool alone, and is a no-op when lean is off.+ lean = false;+ try std.testing.expectEqual(specs.len, (try compactLeanSpecs(Spec, arena, &specs)).len);+ lean = true;+ const compact = try compactLeanSpecs(Spec, arena, &specs);+ try std.testing.expectEqual(specs.len, compact.len);+ for (compact) |s| {+ if (std.mem.eql(u8, s.name, "subagent")) try std.testing.expectEqualStrings(lean_subagent_desc, s.desc) else try std.testing.expectEqualStrings("", s.desc);+ }+ try std.testing.expect(std.mem.indexOf(u8, lean_subagent_desc, "approval-denied") != null); // keeps the one fact delegation needs}test "#330: filterRootSpecs drops only the gated names, and does not allocate when the gate is off" {diff --git a/src/presence.zig b/src/presence.zigindex 7a5ba189..698726b8 100644--- a/src/presence.zig+++ b/src/presence.zig@@ -28,6 +28,7 @@ const Allocator = std.mem.Allocator;const proc_identity = @import("proc_identity.zig");const worktree_lease = @import("worktree_lease.zig");const util = @import("util.zig");+const main_mod = @import("main.zig"); // `unattended`: one-shots join channel rooms at the tail, not the backlogconst unixMs = util.unixMs;@@ -225,6 +226,7 @@ var g_self: proc_identity.Record = .{}; // own pid + start-id, settled by announvar g_chan: ?[]const u8 = null; // gpa-owned channel file name (hash of g_identity)var g_inbox_off: u64 = 0; // bytes of the shared channel already deliveredvar g_device_off: u64 = 0; // bytes of the device-wide room already delivered+var g_tail_seeked: bool = false; // one-shots fast-forward both rooms exactly once (empty room at join must not re-skip later arrivals)var g_acked: [max_peers]u64 = undefined;var g_acked_len: usize = 0;@@ -297,6 +299,7 @@ pub fn deinit(gpa: Allocator) void {g_chan = null;g_self = .{};g_inbox_off = 0;+ g_tail_seeked = false;g_acked_len = 0;}@@ -396,13 +399,25 @@ pub fn postTo(io: Io, arena: Allocator, text: []const u8, to: []const u8) bool {/// Drain the shared channel: every complete message since our last drain,// minus our own echo. Empty when unannounced or caught up. A session that/// joins late hears the channel's whole backlog once — context, not spam:-/// the room predates it.+/// the room predates it. EXCEPTION: a -p one-shot joins, works, and exits+/// inside a minute — the backlog is context it cannot use (measured ~4k+/// tokens of stale chatter injected on the first step of every benchmark+/// one-shot — and it made ephemeral workers ANSWER old messages, burning+/// turns on coordination theater). Unattended sessions start at the tail:+/// they hear what arrives while they run, not what predates them.pub fn drainChannel(io: Io, arena: Allocator) []const Message {const dir_path = g_dir orelse return &.{};const chan = g_chan orelse return &.{};if (g_self.pid == 0) return &.{};var dir = Io.Dir.cwd().openDir(io, dir_path, .{}) catch return &.{};defer dir.close(io);+ if (main_mod.unattended and !g_tail_seeked) {+ g_tail_seeked = true;+ if (dir.readFileAlloc(io, chan, arena, .limited(16 * 1024 * 1024)) catch null) |text| g_inbox_off = @intCast(text.len);+ // The device room too: deliverInbound always drains the worktree+ // channel first, so one fast-forward covers both rooms.+ if (dir.readFileAlloc(io, device_room, arena, .limited(16 * 1024 * 1024)) catch null) |text| g_device_off = @intCast(text.len);+ }const raw = presence_chan.readNewMessages(io, arena, dir, chan, &g_inbox_off);var out: std.ArrayList(Message) = .empty;for (raw) |m| {diff --git a/src/schema.zig b/src/schema.zigindex d7c3d1fb..cb9247b5 100644--- a/src/schema.zig+++ b/src/schema.zig@@ -326,7 +326,7 @@ pub fn effectiveRootSpecs(arena: Allocator) ![]const ToolSpec {else(if (learn_store.active_agent_loaded) &root_specs_without_clock else &root_specs_without_optional);// Optionals are appended BEFORE the #330 filter, never after (optional ≠ exempt); the --lean token filter chains last.- return no_local_tools.filterLeanSpecs(ToolSpec, arena, try no_local_tools.filterRootSpecs(ToolSpec, arena, try tool_gates.withAvailable(ToolSpec, arena, chosen, &optional_specs)));+ return no_local_tools.compactLeanSpecs(ToolSpec, arena, try no_local_tools.filterLeanSpecs(ToolSpec, arena, try no_local_tools.filterRootSpecs(ToolSpec, arena, try tool_gates.withAvailable(ToolSpec, arena, chosen, &optional_specs))));}const Schema = union(enum) { raw: []const u8, value: Value };