graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
pr: bound changed-source input for publication review
justrachfb700ab65cd5
diff --git a/docs/adr/0133-publication-review-binds-committed-inputs.md b/docs/adr/0133-publication-review-binds-committed-inputs.mdindex 9bcf878d..cccfe755 100644--- a/docs/adr/0133-publication-review-binds-committed-inputs.md+++ b/docs/adr/0133-publication-review-binds-committed-inputs.md@@ -12,16 +12,21 @@ the implementation support. Keyword checks cannot establish that coverage.Non-draft publication receives a bounded, tool-free review of the PR body,exact repository/base/head, changed committed source and tests, and separately-identified check observations. Missing, oversized or unsupported inputs and-unresolved or malformed review results do not establish readiness. Drafts-remain available. No particular wording is required to trigger review.--Changed files supply the proposed-head blob and a context diff for prior lines;-unchanged base blobs are not repeated. Test entry points follow committed-package scripts and runner imports through a bounded chain. The packet names-size and traversal limits when evidence is omitted. Successful local check-receipts remain bounded and survive session restore, with their observed head-and completion status; they are not immutable execution proof.+identified check observations. Missing required evidence, oversized diffs,+unsupported inputs, and unresolved or malformed review results do not establish+readiness. Drafts remain available. No particular wording is required to+trigger review.++Changed files supply the proposed-head blob when it fits and a context diff+for prior lines; unchanged base blobs are not repeated. When a complete+proposed-head blob exceeds the individual or aggregate source budget, its+committed context diff remains available with an explicit omission marker.+The reviewer must return unresolved if the missing source is needed to assess+a claim. An oversized diff still blocks publication. Test entry points follow+committed package scripts and runner imports through a bounded chain. The+packet names size and traversal limits when evidence is omitted. Successful+local check receipts remain bounded and survive session restore, with their+observed head and completion status; they are not immutable execution proof.The review supplements actual tests and fresh CI observations. It is not amechanical coverage certificate. Changed files may omit important callers;diff --git a/src/pr_claim_review.zig b/src/pr_claim_review.zigindex 22c81a8d..057ec3e6 100644--- a/src/pr_claim_review.zig+++ b/src/pr_claim_review.zig@@ -105,6 +105,8 @@ pub fn review(self: *Agent, target: evidence.Target, base_name: ?[]const u8, cre\\Do not infer execution or remote CI from prose. The harness supplies observed_head_ci separately.\\This review does not certify execution or CI coverage beyond the supplied observations.\\If support_omitted is true, use support_limit to identify the missing evidence and return unresolved when it is required.+ \\A changed file with after_omitted=true has only a committed context diff, not complete proposed-head source.+ \\If required behavior, callers, or tests lie outside that excerpt, return unresolved even when checks pass.\\If required callers or tests are missing, return unresolved. If a claim exceeds supported scope,\\return unsupported with a concrete counterexample or missing coverage. Do not accept claims\\just because the body says dispatch, integration, verified, or end-to-end.diff --git a/src/pr_review_input.zig b/src/pr_review_input.zigindex 66548a5b..13b7bbd0 100644--- a/src/pr_review_input.zig+++ b/src/pr_review_input.zig@@ -10,9 +10,9 @@ fn repositoryPath(arena: A, dir: []const u8, name: []const u8) ![]const u8 {return std.mem.trimStart(u8, path, "/");}-pub const File = struct { path: []const u8, before: ?[]const u8, after: ?[]const u8, change: ?[]const u8 = null };+pub const File = struct { path: []const u8, before: ?[]const u8, after: ?[]const u8, change: ?[]const u8 = null, after_omitted: bool = false };pub const Input = struct {- version: u8 = 2,+ version: u8 = 3,base: []const u8,head: []const u8,body: []const u8,@@ -21,7 +21,7 @@ pub const Input = struct {support_limit: ?[]const u8 = null,// Changed files plus unchanged callers/configuration that establish// how those files are reached by the repository's test runners.- scope: []const u8 = "changed committed files plus unchanged callers/configuration that establish test reachability",+ scope: []const u8 = "changed committed files (full head or marked context diff) plus unchanged callers/configuration that establish test reachability",};pub fn digest(arena: A, input: Input) ![64]u8 {const bytes = try std.json.Stringify.valueAlloc(arena, input, .{});@@ -152,13 +152,30 @@ pub fn gather(gpa: A, io: std.Io, arena: A, cwd: []const u8, base: []const u8, hwhile (paths.next()) |path| {if (path.len == 0) continue;if (files.items.len >= max_files) return error.ReviewTooLarge;- const after = try blob(gpa, io, arena, cwd, head, path);+ var after_omitted = false;+ const after = blob(gpa, io, arena, cwd, head, path) catch |err| blk: {+ if (err != error.ReviewTooLarge) return err;+ after_omitted = true;+ break :blk null;+ };// A context diff carries the old lines; repeating the complete base// blob would charge unchanged source twice and crowd out test evidence.- const change = try raw(gpa, io, arena, cwd, &.{ "git", "diff", "--no-ext-diff", "--no-renames", "--unified=3", base, head, "--", path });- size += change.len + (if (after) |text| text.len else 0);- if (size > max_bytes) return error.ReviewTooLarge;- try files.append(arena, .{ .path = path, .before = null, .after = after, .change = change });+ var change = try raw(gpa, io, arena, cwd, &.{ "git", "diff", "--no-ext-diff", "--no-renames", "--unified=3", base, head, "--", path });+ if (size + change.len > max_bytes) return error.ReviewTooLarge;+ if (after) |text| {+ if (size + change.len + text.len > max_bytes) after_omitted = true;+ }+ if (after_omitted) {+ // Preserve more committed context when it fits. Never label this+ // excerpt as the complete proposed-head source.+ if (raw(gpa, io, arena, cwd, &.{ "git", "diff", "--no-ext-diff", "--no-renames", "--unified=20", base, head, "--", path })) |expanded| {+ if (size + expanded.len <= max_bytes) change = expanded;+ } else |err| {+ if (err != error.ReviewTooLarge) return err;+ }+ }+ size += change.len + if (after_omitted) @as(usize, 0) else if (after) |text| text.len else 0;+ try files.append(arena, .{ .path = path, .before = null, .after = if (after_omitted) null else after, .change = change, .after_omitted = after_omitted });}if (files.items.len == 0) return error.NoChangedFiles;var support: Support = .{ .gpa = gpa, .io = io, .arena = arena, .cwd = cwd, .head = head, .files = &files, .size = &size, .seen = std.StringHashMap(void).init(arena) };@@ -262,6 +279,68 @@ test "claim review budgets changed hunks instead of the complete base blob" {try std.testing.expectError(error.ReviewTooLarge, gather(gpa, io, a, cwd, head, large_head, "claim"));}+test "claim review uses committed context when changed head source exceeds the budget" {+ const io = std.testing.io;+ var temp = std.testing.tmpDir(.{});+ defer temp.cleanup();+ var scratch = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer scratch.deinit();+ const a = scratch.allocator();+ const gpa = std.testing.allocator;+ var path: [std.fs.max_path_bytes]u8 = undefined;+ const cwd = path[0..try temp.dir.realPath(io, &path)];+ _ = try capture(gpa, io, a, cwd, &.{ "git", "init", "-q" });+ const source = try a.alloc(u8, 75 * 1024);+ @memset(source, 'a');+ for (source, 0..) |*byte, i| if (i % 80 == 79) {+ byte.* = '\n';+ };+ source[0] = 'x';+ source[source.len - 1] = '\n';+ try temp.dir.writeFile(io, .{ .sub_path = "alpha.txt", .data = source });+ try temp.dir.writeFile(io, .{ .sub_path = "beta.txt", .data = source });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "add", "." });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "-c", "user.name=Fixture", "-c", "[email protected]", "-c", "commit.gpgsign=false", "commit", "-qm", "base" });+ const base = try capture(gpa, io, a, cwd, &.{ "git", "rev-parse", "HEAD" });+ source[0] = 'y';+ try temp.dir.writeFile(io, .{ .sub_path = "alpha.txt", .data = source });+ try temp.dir.writeFile(io, .{ .sub_path = "beta.txt", .data = source });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "add", "." });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "-c", "user.name=Fixture", "-c", "[email protected]", "-c", "commit.gpgsign=false", "commit", "-qm", "head" });+ const head = try capture(gpa, io, a, cwd, &.{ "git", "rev-parse", "HEAD" });+ source[0] = 'u';+ try temp.dir.writeFile(io, .{ .sub_path = "beta.txt", .data = source });+ const input = try gather(gpa, io, a, cwd, base, head, "claim");+ try std.testing.expectEqual(@as(usize, 2), input.files.len);+ try std.testing.expectEqual(@as(u8, 'y'), input.files[0].after.?[0]);+ try std.testing.expect(!input.files[0].after_omitted);+ try std.testing.expect(input.files[1].after == null);+ try std.testing.expect(input.files[1].after_omitted);+ try std.testing.expect(std.mem.indexOf(u8, input.files[1].change.?, "+yaaa") != null);+ try std.testing.expect(std.mem.indexOf(u8, input.files[1].change.?, "+uaaa") == null);++ const large = try a.alloc(u8, max_bytes + 1024);+ @memset(large, 'a');+ for (large, 0..) |*byte, i| if (i % 80 == 79) {+ byte.* = '\n';+ };+ large[0] = 'x';+ large[large.len - 1] = '\n';+ try temp.dir.writeFile(io, .{ .sub_path = "large.txt", .data = large });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "add", "." });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "-c", "user.name=Fixture", "-c", "[email protected]", "-c", "commit.gpgsign=false", "commit", "-qm", "large-base" });+ const large_base = try capture(gpa, io, a, cwd, &.{ "git", "rev-parse", "HEAD" });+ large[0] = 'y';+ try temp.dir.writeFile(io, .{ .sub_path = "large.txt", .data = large });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "add", "." });+ _ = try capture(gpa, io, a, cwd, &.{ "git", "-c", "user.name=Fixture", "-c", "[email protected]", "-c", "commit.gpgsign=false", "commit", "-qm", "large-head" });+ const large_head = try capture(gpa, io, a, cwd, &.{ "git", "rev-parse", "HEAD" });+ const single = try gather(gpa, io, a, cwd, large_base, large_head, "claim");+ try std.testing.expectEqual(@as(usize, 1), single.files.len);+ try std.testing.expect(single.files[0].after == null and single.files[0].after_omitted);+ try std.testing.expect(std.mem.indexOf(u8, single.files[0].change.?, "+yaaa") != null);+}+test "claim review includes unchanged callers that establish test reachability" {const io = std.testing.io;var temp = std.testing.tmpDir(.{});@@ -304,6 +383,9 @@ test "claim review digest invalidates changed body head and committed source" {input.head = "head";files[0].after = "different committed source";try std.testing.expect(!std.mem.eql(u8, &original, &try digest(a, input)));+ files[0].after = "source";+ files[0].after_omitted = true;+ try std.testing.expect(!std.mem.eql(u8, &original, &try digest(a, input)));}test "claim review includes committed nested package runners and workflow reachability" {