graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Require concrete local and remote verification disclosures
justrach21e0d7d55d3b
diff --git a/docs/adr/0126-publication-retains-observed-check-failures.md b/docs/adr/0126-publication-retains-observed-check-failures.mdindex 45fdaa44..9ad5bcf9 100644--- a/docs/adr/0126-publication-retains-observed-check-failures.md+++ b/docs/adr/0126-publication-retains-observed-check-failures.md@@ -31,3 +31,11 @@ session supplies no historical observations; malformed new state fails restore.The production regression exercises failing checks, successful reruns, drafts,resumes and batched publication with local-only external-service fixtures.++The body disclosure must name a local command in backticks with its reported+result on a `Local:` line, and give a `Remote:` or `CI:` status. An empty+Verification heading is insufficient. No pre-PR runs remains a supported+remote status. This checks reporting completeness, not truth or semantic test+coverage; fresh CI observations and retained check failures still decide+readiness independently. The dispatch regression covers empty headings,+missing results, missing remote status, and complete disclosures.diff --git a/scripts/eval/github_fixture.py b/scripts/eval/github_fixture.pyindex fe558b77..2ff1d47e 100644--- a/scripts/eval/github_fixture.py+++ b/scripts/eval/github_fixture.py@@ -44,7 +44,7 @@ elif args[:2]==['pr','view']:remote=state.get('remote_head',head)status=state.get('checks','PENDING')checks=state.get('check_rollup', [] if status=='NONE' else [{'context':'fixture CI','state':status}])- print(json.dumps({'headRefOid':remote,'isDraft':state.get('draft',False),'body':'## Verification\nLocal tests passed.','statusCheckRollup':checks,'headRefName':state.get('head_branch','fixture'),'number':1,'url':url+'/pull/1','headRepository':{'nameWithOwner':state.get('head_repo',url.split('://',1)[-1].split('/',1)[1])}}))+ print(json.dumps({'headRefOid':remote,'isDraft':state.get('draft',False),'body':'## Verification\nLocal: `python3 -m unittest` passed.\nRemote: passed.','statusCheckRollup':checks,'headRefName':state.get('head_branch','fixture'),'number':1,'url':url+'/pull/1','headRepository':{'nameWithOwner':state.get('head_repo',url.split('://',1)[-1].split('/',1)[1])}}))sys.exit(state.get('pr_exit',0))elif args[:2] in (['pr','create'],['pr','ready'],['pr','edit'],['issue','edit']):with (root/'mutations.jsonl').open('a') as f:f.write(json.dumps(args)+'\n')@@ -70,5 +70,5 @@ def prepare(work, env, state):if fixture.get("remote_head") == "initial":fixture["remote_head"] = head(work / "gh-state.json").write_text(json.dumps(fixture))- (work / "notes.md").write_text("## Verification\nLocal regression passed.\n")+ (work / "notes.md").write_text("## Verification\nLocal: `python3 -m unittest` passed.\nRemote: passed.\n")env["PATH"] = str(bindir) + os.pathsep + env["PATH"]diff --git a/scripts/regression-release-297.py b/scripts/regression-release-297.pyindex f3b64f37..154b47b6 100644--- a/scripts/regression-release-297.py+++ b/scripts/regression-release-297.py@@ -45,7 +45,7 @@ def run_case(graff, name, script, state=None, expected_mutations=0, refused=0, efixture = dict(initial_head=head, **(state or {}))if fixture.get("remote_head") == "initial": fixture["remote_head"] = head(work / "gh-state.json").write_text(json.dumps(fixture))- (work / "notes.md").write_text("Fix the behavior.\n\n## Verification\nLocal regression passed.\n")+ (work / "notes.md").write_text("Fix the behavior.\n\n## Verification\nLocal: `python3 -m unittest` passed.\nRemote: passed.\n")env = {k: v for k, v in os.environ.items() if not k.endswith("_API_KEY")}env.update(HOME=temp, PATH=str(work / "bin") + os.pathsep + os.environ["PATH"],LMSTUDIO_API_KEY="local", GRAFF_NO_TELEMETRY="1", GRAFF_FLEET="off",@@ -134,7 +134,7 @@ def handoff(graff):bounded_run(["git", "-c", "user.name=Fixture", "-c", "[email protected]", "commit", "-q", "--allow-empty", "-m", "fixture"], cwd=work, check=True)head = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=work, text=True).strip()(work / "gh-state.json").write_text(json.dumps({"initial_head": head, "checks": "SUCCESS"}))- (work / "notes.md").write_text("## Verification\nFixture checks passed.\n")+ (work / "notes.md").write_text("## Verification\nLocal: `python3 -m unittest` passed.\nRemote: passed.\n")env = {k: v for k, v in os.environ.items() if not k.endswith("_API_KEY")}env.update(HOME=temp, PATH=str(work / "bin") + os.pathsep + os.environ["PATH"], LMSTUDIO_API_KEY="local",GRAFF_NO_TELEMETRY="1", GRAFF_FLEET="off", GRAFF_NO_SMOLIFY="1", GRAFF_NO_CODEDB_GUARD="1", NO_COLOR="1")diff --git a/scripts/test-pr-local-checks.py b/scripts/test-pr-local-checks.pyindex 07fa9e6e..0f8742d4 100644--- a/scripts/test-pr-local-checks.py+++ b/scripts/test-pr-local-checks.py@@ -23,13 +23,17 @@ def main():parser = argparse.ArgumentParser(description=__doc__)parser.add_argument("--graff", default="zig-out/bin/graff")parser.add_argument("--evidence", type=Path, required=True)+ parser.add_argument("--only", help="Run one regression case")args = parser.parse_args()binary = str(Path(args.graff).resolve())failing = "import unittest\nclass Check(unittest.TestCase):\n def test_observed_failure(self):\n self.assertEqual(1, 2)\n"check = bash("python3 -m unittest test_observed -v")publish = bash("gh pr create --title fixture --body-file notes.md")final = {"text": "Fixture finished."}- for case in ("failed", "rerun", "draft", "resume", "batch", "nested"):+ for case in ("failed", "rerun", "draft", "resume", "batch", "nested",+ "body-empty", "body-missing-result", "body-missing-remote", "body-valid"):+ if args.only and case != args.only:+ continuewith tempfile.TemporaryDirectory(prefix="graff-pr-local-checks-") as temp:work = Path(temp)env = {k: v for k, v in os.environ.items() if not k.endswith("_API_KEY")}@@ -45,9 +49,19 @@ def main():prepare(work, env, {"checks": "SUCCESS"})(work / "test_observed.py").write_text(failing)(work / "notes.md").write_text(- "Verification: local checks passed. Dispatch is covered."+ "## Verification\nLocal: `python3 -m unittest test_observed -v` — passed.\nRemote: passed.")- if case == "nested":+ if case.startswith("body-"):+ (work / "test_observed.py").write_text(failing.replace("1, 2", "2, 2"))+ bodies = {+ "body-empty": "## Verification",+ "body-missing-result": "Local: `python3 -m unittest test_observed -v`\nRemote: passed.",+ "body-missing-remote": "Local: `python3 -m unittest test_observed -v` — passed.",+ }+ if case in bodies:+ (work / "notes.md").write_text(bodies[case])+ script = [check, publish, final]+ elif case == "nested":nested = work / "checks space"nested.mkdir()(nested / "test_observed.py").write_text(failing)@@ -131,7 +145,7 @@ def main():if (work / "mutations.jsonl").exists()else "")- assert bool(mutations) == (case in ("rerun", "draft")), (+ assert bool(mutations) == (case in ("rerun", "draft", "body-valid")), (case,mutations,events,@@ -141,6 +155,8 @@ def main():"observed local check has no successful completion"in json.dumps(events))+ if case.startswith("body-") and case != "body-valid":+ assert "PR body needs" in json.dumps(events)if case == "batch":assert "separate tool call" in json.dumps(events)target = args.evidence / casediff --git a/src/pr_publish.zig b/src/pr_publish.zigindex d0e722fd..dd922c1b 100644--- a/src/pr_publish.zig+++ b/src/pr_publish.zig@@ -113,20 +113,50 @@ pub fn extractBody(cmd: []const u8) []const u8 {return "";}-pub fn hasVerificationSection(body: []const u8) bool {- const lower_needles = [_][]const u8{- "## verification", "## verify", "verification",- "commands run", "local:", "remote:",- "zig build test", "tier 1", "ci:",- };- var buf: [2048]u8 = undefined;- const n = @min(body.len, buf.len);- for (body[0..n], 0..) |c, i| buf[i] = std.ascii.toLower(c);- const slice = buf[0..n];- for (lower_needles) |need| if (std.mem.indexOf(u8, slice, need) != null) return true;+// A disclosure format check, not evidence that a command ran or covers a claim.+// Independent head observations and retained local failures remain authoritative.+fn containsInsensitive(text: []const u8, needle: []const u8) bool {+ if (text.len < needle.len) return false;+ for (0..text.len - needle.len + 1) |i| {+ if (std.ascii.eqlIgnoreCase(text[i..][0..needle.len], needle)) return true;+ }return false;}+fn reportedResult(text: []const u8) bool {+ var words = std.mem.tokenizeAny(u8, text, " \t\r\n.,:;()[]*!—");+ while (words.next()) |word| {+ for ([_][]const u8{ "pass", "passed", "fail", "failed", "success", "successful", "failure", "pending", "skipped", "blocked" }) |result| {+ if (std.ascii.eqlIgnoreCase(word, result)) return true;+ }+ }+ return containsInsensitive(text, "exit 0") or containsInsensitive(text, "exit code 0");+}++pub fn hasVerificationSection(body: []const u8) bool {+ var local = false;+ var remote = false;+ var lines = std.mem.splitScalar(u8, body, '\n');+ while (lines.next()) |raw| {+ const line = std.mem.trim(u8, raw, " \t\r-*#");+ if (std.ascii.startsWithIgnoreCase(line, "local:")) {+ const value = std.mem.trim(u8, line[6..], " \t");+ // Keep the command separate from the result: a script named+ // test_passed.py is not a reported successful execution.+ const begin = std.mem.indexOfScalar(u8, value, '`') orelse continue;+ const tail = value[begin + 1 ..];+ const end = std.mem.indexOfScalar(u8, tail, '`') orelse continue;+ if (std.mem.trim(u8, tail[0..end], " \t").len == 0) continue;+ local = local or reportedResult(tail[end + 1 ..]);+ } else if (std.ascii.startsWithIgnoreCase(line, "remote:") or std.ascii.startsWithIgnoreCase(line, "ci:")) {+ remote = remote or reportedResult(line) or containsInsensitive(line, "no pre-pr run") or+ containsInsensitive(line, "no runs") or containsInsensitive(line, "not run") or+ containsInsensitive(line, "unavailable") or containsInsensitive(line, "unknown");+ }+ }+ return local and remote;+}+pub fn hasAbsoluteClaim(body: []const u8) bool {var buf: [2048]u8 = undefined;const n = @min(body.len, buf.len);@@ -186,7 +216,7 @@ pub fn reason(decision: Decision, ev: Evidence) []const u8 {.block => if (claimOverreach(ev.body, ev.coverage))"behavior claim overreaches the committed regression (helper/one-separator coverage is not the changed dispatch path)"else if (!hasVerificationSection(ev.body))- "PR body needs a Verification section listing the commands and results actually run"+ "PR body needs Local: `command` — result and Remote: CI status (or no pre-PR runs); report the commands and results actually observed"else if (ev.head_status == .pending)"non-draft publication blocked: the exact head SHA still has a pending branch run"else if (ev.head_status == .failed)@@ -291,7 +321,7 @@ test "classifies create, draft, ready, and checks --watch" {}test "#847 failed or pending head blocks non-draft create" {- const body = "## Verification\nlocal: zig build test (pass)\nremote: pending";+ const body = "## Verification\nlocal: `zig build test` (pass)\nremote: pending";try std.testing.expectEqual(Decision.block, decide(false, .{ .head_status = .failed, .body = body }));try std.testing.expectEqual(Decision.block, decide(false, .{ .head_status = .pending, .body = body }));try std.testing.expectEqual(Decision.allow, decide(true, .{ .head_status = .failed, .body = body }));@@ -300,20 +330,20 @@ test "#847 failed or pending head blocks non-draft create" {test "#847 base-reproduced failure needs disclosure or a draft" {const bare = "## Verification\nzig build test";- const disclosed = "## Verification\nknown failure reproduced on the base branch\nzig build test";+ const disclosed = "## Verification\nknown failure reproduced on the base branch\nLocal: `zig build test` failed\nRemote: failed";try std.testing.expectEqual(Decision.block, decide(false, .{ .head_status = .failed, .base_reproduced = true, .body = bare }));try std.testing.expectEqual(Decision.draft_only, decide(false, .{ .head_status = .failed, .base_reproduced = true, .body = disclosed }));try std.testing.expectEqual(Decision.allow, decide(true, .{ .head_status = .failed, .base_reproduced = true, .body = disclosed }));}test "#847 PR-only workflows with no pre-PR run stay allowed" {- const body = "## Verification\nlocal: zig build test\nremote: no pre-PR run; CI is PR-triggered";+ const body = "## Verification\nlocal: `zig build test` passed\nremote: no pre-PR run; CI is PR-triggered";try std.testing.expectEqual(Decision.allow, decide(false, .{ .head_status = .none, .body = body }));}test "#847 missing verification section blocks non-draft" {try std.testing.expectEqual(Decision.block, decide(false, .{ .head_status = .passed, .body = "fixes the bug" }));- try std.testing.expectEqual(Decision.allow, decide(false, .{ .head_status = .passed, .body = "## Verification\nzig build test: pass" }));+ try std.testing.expectEqual(Decision.allow, decide(false, .{ .head_status = .passed, .body = "## Verification\nLocal: `zig build test`: pass\nRemote: passed" }));}test "#847 one-separator helper test cannot publish an atomic claim" {@@ -345,7 +375,7 @@ test "#847 gateCommand blocks a non-draft create with failed head" {setTestEvidence(.{.head_sha = "abc123",.head_status = .failed,- .body = "## Verification\nzig build test",+ .body = "Local: `zig build test` passed\nRemote: failed",});defer clearTestEvidence();const msg = gateCommand(arena_state.allocator(), "gh pr create --title t --body '## Verification\nzig build test'").?;@@ -370,7 +400,7 @@ test "#847 run-list JSON maps failed, pending, passed, and empty" {test "extractBody reads --body quoted text" {try std.testing.expectEqualStrings("hello", extractBody("gh pr create --body \"hello\" --title x"));- try std.testing.expect(hasVerificationSection("## Verification\nran zig build test"));+ try std.testing.expect(hasVerificationSection("Local: `zig build test` passed\nRemote: no pre-PR runs"));try std.testing.expect(hasAbsoluteClaim("atomic delete is preserved"));}@@ -381,3 +411,25 @@ test "#847 compound checks cannot hide a later publication and ready undo staystry std.testing.expect(!isPrReady("gh pr ready --undo"));try std.testing.expect(!isDraftFlag("gh pr create --body '--draft'"));}++test "#847 verification heading is not commands and results" {+ for ([_][]const u8{+ "verification",+ "## Verification\nLocal tests passed.",+ "Local: `zig build test`\nRemote: passed",+ "Local: `zig build test` passed",+ "Local: `test_passed.py`\nRemote: passed",+ "Local: `` passed\nRemote: passed",+ }) |body| {+ try std.testing.expectEqual(Decision.block, decide(false, .{ .head_status = .passed, .body = body }));+ try std.testing.expectEqual(Decision.allow, decide(true, .{ .head_status = .passed, .body = body }));+ }+}++test "#847 verification disclosure after long body is inspected" {+ var body: [3200]u8 = undefined;+ @memset(&body, 'x');+ const ending = "\n- LOCAL: `python3 -m unittest` — passed.\n- CI: no pre-PR runs.";+ @memcpy(body[body.len - ending.len ..], ending);+ try std.testing.expectEqual(Decision.allow, decide(false, .{ .head_status = .none, .body = &body }));+}diff --git a/src/prompt_golden.zig b/src/prompt_golden.zigindex 9f28e6b8..7405e5a7 100644--- a/src/prompt_golden.zig+++ b/src/prompt_golden.zig@@ -98,8 +98,8 @@ pub const full_prompt =\\A non-draft GitHub PR (`gh pr create` without --draft, or `gh pr ready`)\\is blocked until the exact head SHA is ready: inspect already-running\\or completed branch CI, disclose a failure that reproduces on the base- \\branch or create a draft, and include a Verification section that lists- \\the commands and results you actually ran. Absolute claims (atomic,+ \\branch or create a draft. Include a Local: line with a backtick-quoted+ \\command and observed result, plus Remote: CI status. Absolute claims (atomic,\\preserved) need a regression on the changed dispatch path, not only a\\helper or one-separator boundary. `gh pr checks --watch` after create\\is not that gate. Publication work on a claimed branch, issue, commit,diff --git a/src/prompt_text.zig b/src/prompt_text.zigindex 1df85b8e..9a6da034 100644--- a/src/prompt_text.zig+++ b/src/prompt_text.zig@@ -139,8 +139,8 @@ pub const publication_ready_note =\\A non-draft GitHub PR (`gh pr create` without --draft, or `gh pr ready`)\\is blocked until the exact head SHA is ready: inspect already-running\\or completed branch CI, disclose a failure that reproduces on the base- \\branch or create a draft, and include a Verification section that lists- \\the commands and results you actually ran. Absolute claims (atomic,+ \\branch or create a draft. Include a Local: line with a backtick-quoted+ \\command and observed result, plus Remote: CI status. Absolute claims (atomic,\\preserved) need a regression on the changed dispatch path, not only a\\helper or one-separator boundary. `gh pr checks --watch` after create\\is not that gate. Publication work on a claimed branch, issue, commit,