Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Merge pull request #356 from justrach/fix/read-file-images-ask-user-editor

Rach0e7fd99e1a39
diff --cc src/agent_tools.zig
index e34ba9e7,d3e11acb..187e3dcb
--- a/src/agent_tools.zig
+++ b/src/agent_tools.zig
@@@ -48,18 -43,39 +48,19 @@@ const ToolOutput = tools_mod.ToolOutput
const exec = @import("exec.zig");
const execTool = exec.execTool;
+const brief_diversity = @import("brief_diversity.zig"); // #382: N sibling spawns in one batch are a fleet
+const playbook_glue = @import("playbook_glue.zig"); // #381: the note_constraint meta arm
+const mcp_schema_gate = @import("mcp_schema_gate.zig"); // #416: the load_tool_schemas meta arm
const util = @import("util.zig"); // #225: unixMs, for the clock_sleep interrupted-elapsed measurement
+ const readline = @import("readline.zig"); // ask_user answers get the same full editor as the main prompt
const protocol_seq = @import("protocol_seq.zig"); // #330: monotonic `seq` on every --json event
-const tool_results_dir = ".graff/tool-results";
-pub const tool_preview_chars: usize = 2_000;
-var tool_result_seq: std.atomic.Value(u64) = .init(0);
-
-test {
- _ = @import("agent_eval_control_tests.zig");
-}
-
-pub fn toolPreviewText(arena: std.mem.Allocator, text: []const u8, path: ?[]const u8) ![]const u8 {
- if (text.len <= tool_preview_chars) return arena.dupe(u8, text);
- const marker = if (path) |p|
- try std.fmt.allocPrint(arena, "[full tool result: {s} — inspect with read_file]", .{p})
- else
- "[tool result truncated: full-result persistence failed]";
- const head = util.utf8Prefix(text, tool_preview_chars -| (marker.len + 2));
- return std.fmt.allocPrint(arena, "{s}\n\n{s}", .{ head, marker });
-}
-
-fn persistToolResult(self: *Agent, text: []const u8) ?[]const u8 {
- if (text.len <= tool_preview_chars) return null;
- // createDir reports PathAlreadyExists, which is the normal case because
- // trace setup creates `.graff` at launch. createDirPath is idempotent.
- Io.Dir.cwd().createDirPath(self.io, tool_results_dir) catch return null;
- const seq = tool_result_seq.fetchAdd(1, .monotonic);
- const run_id = if (self.tracer) |tr| tr.identity.run_id else "untraced";
- const path = std.fmt.allocPrint(self.arena, "{s}/{s}-{d}.txt", .{ tool_results_dir, run_id, seq }) catch return null;
- Io.Dir.cwd().writeFile(self.io, .{ .sub_path = path, .data = text, .flags = .{ .exclusive = true } }) catch return null;
- return path;
-}
+// #440: the ONE size contract for a tool result — preview + durable handle +
+// byte count + shape hint, applied here at tool time. It replaced this file's
+// old persistToolResult/toolPreviewText pair (a 2000-char head and a bare
+// path), and it clamps itself under the send-time per-output cap so the two are
+// ordered by construction rather than stacked.
+const tool_handle = @import("tool_handle.zig");
// escWatchTask/drainStdin/rawNonblockStdin live in agent_interrupt.zig;
// Agent.esc_watch_done is a struct-level pub var that STAYS declared inside the