graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Informational subagents keep read tools (#1360)
justrache0de842ef46d
diff --git a/src/agent.zig b/src/agent.zigindex f1f9d881..3e417582 100644--- a/src/agent.zig+++ b/src/agent.zig@@ -100,6 +100,7 @@ pub const Agent = struct {/// score re-reading files it had already been given. With no tools it must/// answer from the excerpt in one call, which is what it was designed for.text_only: bool = false,+ read_only: bool = false, // informational child: reads kept, writes refused (#1360, agent_tool_gate)label: []const u8,out: ?*Io.Writer,in: ?*Io.Reader = null, // stdin, root only — backs the ask_user tooldiff --git a/src/agent_tool_gate.zig b/src/agent_tool_gate.zigindex 15bb175a..414270cb 100644--- a/src/agent_tool_gate.zig+++ b/src/agent_tool_gate.zig@@ -148,6 +148,39 @@ fn gateHarnessPolicyWrite(self: *Agent, call: ToolCall) !?ExecResult {};}+/// An informational child keeps its read, search and read-only shell tools+/// (#1360); withholding the whole catalog left audits with nothing to inspect.+/// Writes are refused the way plan mode refuses them at the root.+fn readOnlyChildAllows(call: ToolCall) bool {+ for ([_][]const u8{ "write_file", "edit_file", "imagegen", "peer_message", "learn_candidate" }) |name|+ if (std.mem.eql(u8, call.name, name)) return false;+ if (mcp.Registry.isMcp(call.name)) return companionReadOnly(call.name, call.input);+ if (!shell_tool.runsCommand(call.name)) return true;+ const args = json_args.object(call.input) orelse return true;+ const cmd_val = args.get("command") orelse return true; // action=output / kill+ if (cmd_val != .string) return true;+ const cmd = std.mem.trim(u8, cmd_val.string, " \t");+ return Approvals.readOnlyAllowed(cmd) or Approvals.readOnlyExternal(cmd);+}++test "a read-only child keeps reads and read-only shell, not writes (#1360)" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const a = arena_state.allocator();+ const call = struct {+ fn f(al: std.mem.Allocator, name: []const u8, input: []const u8) ToolCall {+ const v = std.json.parseFromSliceLeaky(std.json.Value, al, input, .{}) catch unreachable;+ return .{ .id = "c", .name = name, .input = v };+ }+ }.f;+ try std.testing.expect(readOnlyChildAllows(call(a, "read_file", "{\"path\":\"src/main.zig\"}")));+ try std.testing.expect(readOnlyChildAllows(call(a, "bash", "{\"command\":\"ls src\"}")));+ try std.testing.expect(readOnlyChildAllows(call(a, "bash", "{\"action\":\"output\",\"id\":3}")));+ try std.testing.expect(!readOnlyChildAllows(call(a, "write_file", "{\"path\":\"a\",\"content\":\"b\"}")));+ try std.testing.expect(!readOnlyChildAllows(call(a, "edit_file", "{}")));+ try std.testing.expect(!readOnlyChildAllows(call(a, "bash", "{\"command\":\"rm -rf build\"}")));+}+pub fn gateTool(self: *Agent, call: ToolCall) !?ExecResult {if (try gateHarnessPolicyWrite(self, call)) |blocked| return blocked; // #366: before the sub branch — children are exactly who must not widen approvalsif (self.sub) {@@ -164,6 +197,10 @@ pub fn gateTool(self: *Agent, call: ToolCall) !?ExecResult {};};}+ if (self.read_only and !readOnlyChildAllows(call)) return .{+ .text = try self.arena.dupe(u8, "this subagent is read-only (an informational task) — read, search and run read-only commands, and report the change instead of making it"),+ .is_error = true,+ };return null;}if (try gateSmolifySecrets(self.arena, call)) |blocked| return blocked;diff --git a/src/subagent_retained.zig b/src/subagent_retained.zigindex 229bc2d5..81034bc2 100644--- a/src/subagent_retained.zig+++ b/src/subagent_retained.zig@@ -15,6 +15,7 @@ pub const Record = struct {model: []const u8,context: u64 = 128000,text_only: bool = false,+ read_only: bool = false,reasoning: @import("main.zig").ReasoningEffort = .medium,protocol: ?@import("provider.zig").Provider.Kind = null,deadline_ms: ?i64 = null,@@ -144,6 +145,7 @@ pub fn restore(agent: *Agent, ctx: tools.ToolCtx) !void {dir.close(ctx.io);agent.agent_cwd = cwd;agent.text_only = record.text_only;+ agent.read_only = record.read_only;agent.reasoning = record.reasoning;if (record.protocol) |kind| if (kind != agent.provider.kind) return error.RetainedWorkerProtocolChanged;if (record.deadline_ms) |deadline| agent.loop_deadline_ms = if (agent.loop_deadline_ms) |current| @min(current, deadline) else deadline;@@ -158,6 +160,7 @@ pub fn checkpoint(agent: *Agent, ctx: tools.ToolCtx) !void {state.record.model = agent.provider.model;state.record.context = agent.provider.context;state.record.text_only = agent.text_only;+ state.record.read_only = agent.read_only;state.record.reasoning = agent.reasoning;state.record.protocol = agent.provider.kind;state.record.deadline_ms = agent.loop_deadline_ms;diff --git a/src/subagent_run.zig b/src/subagent_run.zigindex e4c4e618..f0927f34 100644--- a/src/subagent_run.zig+++ b/src/subagent_run.zig@@ -296,7 +296,10 @@ pub fn runSub(ctx: ToolCtx, kind: []const u8, label: []const u8, prompt: []const// §2c: the judge is text-only. It ranks handed excerpts, so a toolset// only buys it the chance to go re-read the repo — which is where its// ~3 calls per score went. One judge, one call.- .text_only = std.mem.eql(u8, kind, "judge_task") or @import("task_intent.zig").classify(prompt) == .informational,+ .text_only = std.mem.eql(u8, kind, "judge_task"),+ // #1360: an informational child still needs its read tools; it is+ // read-only, not tool-less.+ .read_only = @import("task_intent.zig").classify(prompt) == .informational,.reasoning = effort orelse .medium, // #292 follow-up: effort pin; unpinned workers keep the default depth, not the root's /effort};const sub_start = Io.Timestamp.now(ctx.io, .awake);