Skip to content

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

Python

feat(escalation): report anchors — review/research earn a real verifier

justrachcb91fb80bfb3
diff --git a/evals/harness_behavior.jsonl b/evals/harness_behavior.jsonl
index 69d1278f..4605ea35 100644
--- a/evals/harness_behavior.jsonl
+++ b/evals/harness_behavior.jsonl
@@ -9,4 +9,5 @@
{"id": "failed-bash-is-not-reported-as-success", "why": "#106: a command that fails must come back marked is_error with its exit status and stderr intact, so the next turn cannot mistake it for success. The regression is a swallowed failure - a non-zero exit finishing as an ok tool_call, or output trimmed away before the model sees why it broke.", "args": [], "prompt": "run the config check", "script": [{"tool": "bash", "arguments": {"command": "ls missing_config.yaml; exit 7"}}, {"text": "the config check failed, so I am not claiming it passed"}], "assert": [{"event": {"type": "tool_call_finished", "name": "bash", "is_error": true}}, {"events_at_most": {"match": {"type": "tool_call_finished", "name": "bash", "is_error": false}, "count": 0}}, {"request_contains": {"index": -1, "text": "[exit code 7]"}}, {"request_contains": {"index": -1, "text": "No such file or directory"}}, {"final_text_contains": "the config check failed"}]}
{"id": "subagent-compaction-pins-task", "why": "G2/H2: compact() must call pinChildTask before it summarizes a subagent's history, or a compacted child loses its own mandate. No unit test can prove the wiring (compact() hits the network right after the prelude), so this drives a real child through auto-compaction against the scripted model and checks the request sent right after: it must still carry the child's task, restated verbatim, not just the model's summary.", "args": [], "env": {"GRAFF_COMPACT_PCT": "5"}, "prompt": "spawn a subagent to survey the payments module", "script": [{"tool": "subagent", "arguments": {"description": "survey payments", "prompt": "SENTINEL-TASK-9f2c: read every file under payments/ and list the exported functions"}}, {"tool": "bash", "arguments": {"command": "python3 -c \"print('c0'*2000)\""}}, {"tool": "bash", "arguments": {"command": "python3 -c \"print('c1'*2000)\""}}, {"tool": "bash", "arguments": {"command": "python3 -c \"print('c2'*2000)\""}}, {"tool": "bash", "arguments": {"command": "python3 -c \"print('c3'*2000)\""}}, {"text": "the payments module has been surveyed so far"}, {"text": "functions listed: chargeCard, refund, listInvoices"}, {"text": "the subagent found chargeCard, refund, and listInvoices"}], "assert": [{"event": {"type": "tool_call", "name": "subagent"}}, {"event": {"type": "tool_result", "name": "subagent", "is_error": false}}, {"request_contains": {"index": 6, "text": "SENTINEL-TASK-9f2c"}}, {"request_contains": {"index": 6, "text": "restated verbatim"}}, {"final_text_contains": "the subagent found chargeCard, refund, and listInvoices"}]}
{"id": "escalation-r0-declines-then-r0d-revision", "why": "escalation R0d: a 1-file bugfix must be DECLINED solo (the 0.0.237 study's 30-calls-no-edit regression), and the SECOND ask of the same class must get the R0d revision prescription — evidence-carrying sequential revision before any fleet. The regression is a fleet on first ask, or a flat second decline that never prescribes the revision.", "args": [], "prompt": "ultracode fix the bug in stats.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find the defect", "tasks": [{"description": "find", "prompt": "read stats.py and locate the defect"}]}, {"title": "implement the fix", "tasks": [{"description": "fix", "prompt": "fix the defect in stats.py"}]}]}}, {"text": "declined by the ladder — I made the edit solo but the tests still fail"}, {"tool": "workflow", "arguments": {"phases": [{"title": "find the defect", "tasks": [{"description": "find", "prompt": "read stats.py and locate the defect"}]}, {"title": "implement the fix", "tasks": [{"description": "fix", "prompt": "fix the defect in stats.py"}]}]}}, {"text": "revising with deeper analysis as prescribed"}], "second_prompt": "the fix did not take — pytest still fails in stats.py", "assert": [{"event": {"type": "tool_result", "name": "workflow", "is_error": false}}, {"request_contains": {"index": 1, "text": "(escalation R0):"}}, {"request_contains": {"index": 1, "text": "Do it yourself"}}, {"request_lacks": {"index": 1, "text": "(escalation R0d):"}}, {"request_contains": {"index": -1, "text": "(escalation R0d):"}}, {"request_contains": {"index": -1, "text": "revision case"}}, {"request_contains": {"index": -1, "text": "second failure earns the fleet"}}, {"final_text_contains": "revising with deeper analysis"}]}
-{"id": "escalation-no-verifier-no-revision-loop", "why": "Weng's revision gate (failure_evidence.verifierFor): a review-class ask has no free verification signal, so a repeat failure must NOT be prescribed a solo revision — R0d stays shut, and with the fleet unaffordable the decline is the plain R0 advisory. The regression is a revision loop spun without external feedback, which converts right answers to wrong ones as often as the reverse.", "args": ["--max-model-calls", "8"], "prompt": "review the findings in report.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find problems", "tasks": [{"description": "find", "prompt": "read report.py and list the problems"}]}, {"title": "verify each finding", "tasks": [{"description": "verify", "prompt": "verify the problems in report.py"}]}]}}, {"text": "reviewed solo as told"}, {"tool": "workflow", "arguments": {"phases": [{"title": "find problems", "tasks": [{"description": "find", "prompt": "read report.py and list the problems"}]}, {"title": "verify each finding", "tasks": [{"description": "verify", "prompt": "verify the problems in report.py"}]}]}}, {"text": "continuing the review myself"}], "second_prompt": "that review missed real problems in report.py — go again", "assert": [{"request_contains": {"index": 1, "text": "(escalation R0):"}}, {"request_contains": {"index": -1, "text": "(escalation R0):"}}, {"request_lacks": {"index": -1, "text": "(escalation R0d):"}}, {"request_lacks": {"index": -1, "text": "revision case"}}, {"final_text_contains": "continuing the review myself"}]}
+{"id": "escalation-no-verifier-no-revision-loop", "why": "Weng's revision gate (failure_evidence.verifierFor): an `other`-class ask has no verifier — no diff contract, no eval, no citable anchors — so a repeat failure must NOT be prescribed a solo revision; R0d stays shut and with the fleet unaffordable the decline is the plain R0 advisory. The regression is a revision loop spun without external feedback.", "args": ["--max-model-calls", "8"], "prompt": "polish the onboarding copy in welcome.txt", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find problems", "tasks": [{"description": "find", "prompt": "read welcome.txt and list the problems"}]}, {"title": "verify each finding", "tasks": [{"description": "verify", "prompt": "verify the problems in welcome.txt"}]}]}}, {"text": "polished it solo as told"}, {"tool": "workflow", "arguments": {"phases": [{"title": "find problems", "tasks": [{"description": "find", "prompt": "read welcome.txt and list the problems"}]}, {"title": "verify each finding", "tasks": [{"description": "verify", "prompt": "verify the problems in welcome.txt"}]}]}}, {"text": "continuing the polish myself"}], "second_prompt": "the onboarding copy in welcome.txt still reads badly — go again", "assert": [{"request_contains": {"index": 1, "text": "(escalation R0):"}}, {"request_contains": {"index": -1, "text": "(escalation R0):"}}, {"request_lacks": {"index": -1, "text": "(escalation R0d):"}}, {"request_lacks": {"index": -1, "text": "revision case"}}, {"final_text_contains": "continuing the polish myself"}]}
+{"id": "review-repeat-failure-gets-anchor-revision", "why": "report_anchors gives review/research a real verifier (cited paths must resolve against the tree), so a review-class repeat failure now earns the R0d revision prescription instead of jumping to the judge fleet — the anchors are the external feedback Weng's gate demands.", "args": [], "prompt": "review the findings in report.py", "script": [{"tool": "workflow", "arguments": {"phases": [{"title": "find problems", "tasks": [{"description": "find", "prompt": "read report.py and list the problems"}]}, {"title": "verify each finding", "tasks": [{"description": "verify", "prompt": "verify the problems in report.py"}]}]}}, {"text": "reviewed solo as told"}, {"tool": "workflow", "arguments": {"phases": [{"title": "find problems", "tasks": [{"description": "find", "prompt": "read report.py and list the problems"}]}, {"title": "verify each finding", "tasks": [{"description": "verify", "prompt": "verify the problems in report.py"}]}]}}, {"text": "re-reviewing against the cited code as prescribed"}], "second_prompt": "that review missed real problems in report.py — go again", "assert": [{"request_contains": {"index": 1, "text": "(escalation R0):"}}, {"request_lacks": {"index": 1, "text": "(escalation R0d):"}}, {"request_contains": {"index": -1, "text": "(escalation R0d):"}}, {"request_contains": {"index": -1, "text": "revision case"}}, {"final_text_contains": "re-reviewing against the cited code"}]}
diff --git a/src/failure_evidence.zig b/src/failure_evidence.zig
index 5f342c46..2dd0b5d4 100644
--- a/src/failure_evidence.zig
+++ b/src/failure_evidence.zig
@@ -56,15 +56,19 @@ pub fn reset() void {
/// What could catch a second miss on this class of ask. `diff` is the edit
/// contract's porcelain probe: bugfix/refactor/feature work is contracted to
/// mutate, so "did the tree move, and do the checks pass on it" is checkable
-/// without a model. review/research/other have no free signal — for those the
-/// R3 judges ARE the external feedback, so a solo revision loop is refused.
-pub const Verifier = enum { none, diff, eval };
+/// without a model. `anchors` is the report contract (report_anchors.zig):
+/// review/research claims cite file paths, and whether those resolve against
+/// the tree is a stat — re-reading the cited code is real external feedback.
+/// `other` has no free signal — there the R3 judges ARE the feedback, so a
+/// solo revision loop is refused.
+pub const Verifier = enum { none, diff, eval, anchors };
pub fn verifierFor(tc: TaskClass, has_eval: bool) Verifier {
if (has_eval) return .eval;
return switch (tc) {
.bugfix, .refactor, .feature => .diff,
- .review, .research, .other => .none,
+ .review, .research => .anchors,
+ .other => .none,
};
}
@@ -89,12 +93,13 @@ test "note/evidence: flattened, capped on a UTF-8 boundary, latest wins whole" {
try std.testing.expect(std.unicode.utf8ValidateSlice(evidence(.feature)));
}
-test "verifierFor: diff-checkable classes gate open, report-only classes stay shut" {
+test "verifierFor: every class with a checkable signal gates open; only `other` stays shut" {
try std.testing.expectEqual(Verifier.diff, verifierFor(.bugfix, false));
try std.testing.expectEqual(Verifier.diff, verifierFor(.refactor, false));
try std.testing.expectEqual(Verifier.diff, verifierFor(.feature, false));
- try std.testing.expectEqual(Verifier.none, verifierFor(.review, false));
- try std.testing.expectEqual(Verifier.none, verifierFor(.research, false));
+ // Report classes verify through cited-anchor resolution (report_anchors).
+ try std.testing.expectEqual(Verifier.anchors, verifierFor(.review, false));
+ try std.testing.expectEqual(Verifier.anchors, verifierFor(.research, false));
try std.testing.expectEqual(Verifier.none, verifierFor(.other, false));
// A configured eval loop is the strongest verifier and covers any class.
try std.testing.expectEqual(Verifier.eval, verifierFor(.research, true));
diff --git a/src/report_anchors.zig b/src/report_anchors.zig
new file mode 100644
index 00000000..cde484d1
--- /dev/null
+++ b/src/report_anchors.zig
@@ -0,0 +1,241 @@
+//! The report contract: a finding must anchor to code that exists.
+//!
+//! The edit contract asks the filesystem whether an implement phase actually
+//! edited; this module asks it whether a REPORT actually read. A review or
+//! research report's claims cite file paths, and whether those paths resolve
+//! against the working tree is checkable with a stat — no model call, no
+//! network. That check is what makes `.anchors` a real verifier
+//! (failure_evidence.verifierFor): report classes used to fail closed out of
+//! the R0d revision rung because nothing automatic could catch a second
+//! miss; cited-anchor resolution is that catch, so review/research now earn
+//! the cheap revision instead of a judge fleet.
+//!
+//! The failure predicate is deliberately the HIGH-CONFIDENCE one: a report
+//! that cites paths of which NONE resolve is fabricated (or reviewed the
+//! wrong tree) and converts to a retryable error. Partially-unresolved
+//! citations only append a visible warning (#380's vision-warning pattern):
+//! a report may legitimately propose new files next to real ones, and a
+//! false error would burn the phase retry the fleet may still need.
+
+const std = @import("std");
+const Io = std.Io;
+const Allocator = std.mem.Allocator;
+
+/// Extensions that read as source/config files. A whitelist, not the
+/// any-extension rule escalation's scope counter uses, because reports cite
+/// dotted code identifiers (`std.debug.print`) and web hosts, and counting
+/// those as unresolvable paths would fail honest reviews.
+const file_exts = [_][]const u8{
+ "zig", "py", "ts", "tsx", "js", "jsx", "rs", "go", "c", "h",
+ "cpp", "hpp", "cc", "java", "kt", "rb", "php", "cs", "sh", "zsh",
+ "md", "json", "toml", "yaml", "yml", "txt", "css", "html", "sql", "swift",
+};
+
+fn isPathByte(c: u8) bool {
+ return std.ascii.isAlphanumeric(c) or c == '_' or c == '-' or c == '.' or c == '/' or c == '\\';
+}
+
+/// Does this token cite a source file? Needs a dot with a whitelisted
+/// extension and an alphanumeric before it — `stats.py` and `src/main.zig`
+/// yes; `std.mem.eql`, `example.com` and `3.11` no.
+pub fn looksLikeSourceFile(tok: []const u8) bool {
+ const dot = std.mem.lastIndexOfScalar(u8, tok, '.') orelse return false;
+ if (dot == 0 or dot + 1 >= tok.len) return false;
+ if (!std.ascii.isAlphanumeric(tok[dot - 1])) return false;
+ const ext = tok[dot + 1 ..];
+ for (file_exts) |known| if (std.ascii.eqlIgnoreCase(ext, known)) return true;
+ return false;
+}
+
+pub const max_anchors = 32;
+pub const max_token = 128;
+
+pub const Check = struct {
+ cited: usize = 0,
+ resolved: usize = 0,
+ /// Up to three unresolved tokens, for the error/warning text.
+ samples: [3][]const u8 = .{ "", "", "" },
+ n_samples: usize = 0,
+
+ pub fn allFabricated(self: Check) bool {
+ return self.cited > 0 and self.resolved == 0;
+ }
+};
+
+const TokenSet = struct {
+ hashes: [max_anchors]u64 = @splat(0),
+ n: usize = 0,
+
+ fn seen(self: *TokenSet, tok: []const u8) bool {
+ var buf: [max_token]u8 = undefined;
+ const m = @min(tok.len, buf.len);
+ for (buf[0..m], tok[0..m]) |*d, s| d.* = std.ascii.toLower(s);
+ const h = std.hash.Wyhash.hash(0, buf[0..m]);
+ for (self.hashes[0..self.n]) |x| if (x == h) return true;
+ if (self.n < self.hashes.len) {
+ self.hashes[self.n] = h;
+ self.n += 1;
+ }
+ return false;
+ }
+};
+
+/// Scan `text` for cited source paths and resolve each against the tree.
+/// `exists` is the probe (real stat in production, a table in tests), taken
+/// as anytype so this stays allocation-free and Io-free at the core.
+pub fn scan(text: []const u8, arena: Allocator, exists: anytype) Check {
+ var out: Check = .{};
+ var set: TokenSet = .{};
+ var i: usize = 0;
+ while (i < text.len) {
+ while (i < text.len and !isPathByte(text[i])) : (i += 1) {}
+ const start = i;
+ while (i < text.len and isPathByte(text[i])) : (i += 1) {}
+ if (i == start) continue;
+ const tok = std.mem.trim(u8, text[start..i], ".");
+ if (tok.len == 0 or tok.len > max_token or !looksLikeSourceFile(tok)) continue;
+ if (set.seen(tok)) continue;
+ out.cited += 1;
+ if (exists.check(tok)) {
+ out.resolved += 1;
+ } else if (out.n_samples < out.samples.len) {
+ out.samples[out.n_samples] = arena.dupe(u8, tok) catch tok;
+ out.n_samples += 1;
+ }
+ }
+ return out;
+}
+
+/// The production existence probe: stat relative to the worker's cwd.
+pub const FsProbe = struct {
+ io: Io,
+ cwd: ?[]const u8,
+
+ pub fn check(self: FsProbe, path: []const u8) bool {
+ var buf: [1024]u8 = undefined;
+ const full = if (self.cwd) |c|
+ std.fmt.bufPrint(&buf, "{s}/{s}", .{ c, path }) catch return false
+ else
+ path;
+ _ = Io.Dir.cwd().statFile(self.io, full, .{}) catch return false;
+ return true;
+ }
+};
+
+/// Appended to a report-slot phase's briefs, the way contract_brief_note is
+/// to an implement phase's: the contract is fair because the worker was told.
+pub const anchor_brief_note =
+ "Anchor every finding to real code: cite the file paths (and lines) you actually read, exactly " ++
+ "as they appear in the tree. The harness resolves cited paths after this phase; a report whose " ++
+ "citations do not resolve is rejected. Name a file you are proposing (not one that exists) as " ++
+ "`proposed: <path>`.";
+
+/// The retryable failure text for an all-fabricated report. No
+/// retry-unsafe marker, so the phase's single retry picks it up.
+pub fn fabricatedText(gpa: Allocator, c: Check) []u8 {
+ return std.fmt.allocPrint(
+ gpa,
+ "report anchors unresolved: none of the {d} file path(s) this report cites exist in the " ++
+ "working tree (e.g. {s}). A finding must anchor to code that is really there — re-read " ++
+ "the tree, cite paths that resolve, and mark genuinely new files as `proposed: <path>`.",
+ .{ c.cited, if (c.n_samples > 0) c.samples[0] else "?" },
+ ) catch gpa.dupe(u8, "report anchors unresolved: cited paths do not exist in the working tree") catch @constCast("");
+}
+
+/// Post-await gate for report-slot phases, shaped like escalation.contractCheck
+/// so the call site stays one composed expression. All-fabricated → is_error
+/// (the retry re-runs the worker with the failure named); partially
+/// unresolved → the report passes with a visible warning appended, which the
+/// root cannot mistake for silence.
+pub fn anchorCheck(gpa: Allocator, io: Io, cwd: ?[]const u8, report_slot: bool, out: anytype) @TypeOf(out) {
+ if (!report_slot or out.is_error) return out;
+ var arena_state = std.heap.ArenaAllocator.init(gpa);
+ defer arena_state.deinit();
+ const c = scan(out.text, arena_state.allocator(), FsProbe{ .io = io, .cwd = cwd });
+ if (c.allFabricated()) {
+ gpa.free(out.text);
+ return .{ .text = fabricatedText(gpa, c), .is_error = true };
+ }
+ if (c.n_samples > 0) {
+ const flagged = std.fmt.allocPrint(gpa, "{s}\n\n[anchor warning: {d} of {d} cited path(s) do not resolve, e.g. {s} — treat findings there as unverified]", .{ out.text, c.cited - c.resolved, c.cited, c.samples[0] }) catch return out;
+ gpa.free(out.text);
+ return .{ .text = flagged, .is_error = out.is_error };
+ }
+ return out;
+}
+
+/// Which canonical slots carry the report contract. Implement-class slots
+/// carry the edit contract instead; synthesize summarizes other workers'
+/// findings, so its citations are secondhand and not its own claim to check.
+pub fn isReportSlot(slot: []const u8) bool {
+ const report_slots = [_][]const u8{ "find", "verify", "sweep", "review" };
+ for (report_slots) |s| if (std.mem.eql(u8, slot, s)) return true;
+ return false;
+}
+
+const TableProbe = struct {
+ known: []const []const u8,
+ pub fn check(self: TableProbe, path: []const u8) bool {
+ for (self.known) |k| if (std.mem.eql(u8, k, path)) return true;
+ return false;
+ }
+};
+
+test "looksLikeSourceFile: files yes; identifiers, hosts and versions no" {
+ try std.testing.expect(looksLikeSourceFile("stats.py"));
+ try std.testing.expect(looksLikeSourceFile("src/main.zig"));
+ try std.testing.expect(looksLikeSourceFile("Welcome.TXT"));
+ // The false positives the whitelist exists for.
+ try std.testing.expect(!looksLikeSourceFile("std.debug.print"));
+ try std.testing.expect(!looksLikeSourceFile("std.mem.eql"));
+ try std.testing.expect(!looksLikeSourceFile("example.com"));
+ try std.testing.expect(!looksLikeSourceFile("3.11"));
+ try std.testing.expect(!looksLikeSourceFile("v0.0.237"));
+}
+
+test "scan: dedupes, resolves against the probe, samples the unresolved" {
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
+ defer arena_state.deinit();
+ const probe = TableProbe{ .known = &.{ "stats.py", "src/main.zig" } };
+ // stats.py:24 strips its line suffix; the duplicate counts once.
+ const c = scan(
+ "The bug is in stats.py:24 (also see stats.py) and src/main.zig; ghost.py has a second one.",
+ arena_state.allocator(),
+ probe,
+ );
+ try std.testing.expectEqual(@as(usize, 3), c.cited);
+ try std.testing.expectEqual(@as(usize, 2), c.resolved);
+ try std.testing.expectEqual(@as(usize, 1), c.n_samples);
+ try std.testing.expectEqualStrings("ghost.py", c.samples[0]);
+ try std.testing.expect(!c.allFabricated());
+ // A report citing ONLY phantoms is fabricated; one citing nothing is not.
+ const bad = scan("ghost.py and phantom.zig hold the defect", arena_state.allocator(), probe);
+ try std.testing.expect(bad.allFabricated());
+ const silent = scan("everything looks fine to me", arena_state.allocator(), probe);
+ try std.testing.expect(!silent.allFabricated());
+ try std.testing.expectEqual(@as(usize, 0), silent.cited);
+}
+
+test "the contract texts instruct, and the failure stays retry-safe" {
+ const gpa = std.testing.allocator;
+ var c: Check = .{ .cited = 2, .n_samples = 1 };
+ c.samples[0] = "ghost.py";
+ const text = fabricatedText(gpa, c);
+ defer gpa.free(text);
+ try std.testing.expect(std.mem.indexOf(u8, text, "ghost.py") != null);
+ try std.testing.expect(std.mem.indexOf(u8, text, "re-read") != null);
+ try std.testing.expect(std.mem.indexOf(u8, text, "retry is NOT safe") == null);
+ try std.testing.expect(std.mem.indexOf(u8, anchor_brief_note, "proposed:") != null);
+}
+
+test "isReportSlot: report slots carry it, implement/synthesize do not" {
+ try std.testing.expect(isReportSlot("find"));
+ try std.testing.expect(isReportSlot("verify"));
+ try std.testing.expect(isReportSlot("sweep"));
+ try std.testing.expect(isReportSlot("review"));
+ try std.testing.expect(!isReportSlot("implement"));
+ try std.testing.expect(!isReportSlot("build"));
+ try std.testing.expect(!isReportSlot("synthesize"));
+ try std.testing.expect(!isReportSlot("transform"));
+ try std.testing.expect(!isReportSlot(""));
+}
diff --git a/src/workflow.zig b/src/workflow.zig
index 08c037f5..1df97948 100644
--- a/src/workflow.zig
+++ b/src/workflow.zig
@@ -57,6 +57,7 @@ const wfp = @import("workflow_progress.zig");
// The ultracode escalation ladder (admission, the edit contract) and the
// reservation ledger it decides against.
const escalation = @import("escalation.zig");
+const report_anchors = @import("report_anchors.zig");
const phase_budget = @import("phase_budget.zig");
const shapes = @import("shapes.zig");
const pipeline_mode = @import("workflow_pipeline.zig");
@@ -168,6 +169,7 @@ pub const buildManifest = wfp.buildManifest;
test { // a new module's tests run only when something references it (see main.zig)
_ = wfp;
+ _ = report_anchors;
}
/// Dynamic workflows as data: sequential phases, parallel tasks. Each task
@@ -273,6 +275,10 @@ pub fn execWorkflow(ctx: ToolCtx, input: Value) !ToolOutput {
// §3b: this phase's slot is contracted to MUTATE files, so its briefs
// carry the changed-path contract and its results face a porcelain probe.
const contracted = escalation.isContracted(shapes.canonicalSlot(title));
+ // The report contract's mirror image: this phase's slot REPORTS, so
+ // its briefs carry the anchor contract and its results face a
+ // cited-path resolution probe (report_anchors.zig).
+ const report_phase = report_anchors.isReportSlot(shapes.canonicalSlot(title));
const tasks_val = phase.get("tasks") orelse return .{
.text = try gpa.dupe(u8, "each phase needs a tasks array"),
.is_error = true,
@@ -324,7 +330,13 @@ pub fn execWorkflow(ctx: ToolCtx, input: Value) !ToolOutput {
// §3b, stolen from codex's patch-biased delegation: a contracted
// worker is told to MAKE the edits and to end by listing every
// changed path, so verify and the root review a diff, not a claim.
- const based = try withContext(arena, run_context, if (contracted) try withContext(arena, escalation.contract_brief_note, raw) else raw);
+ const noted = if (contracted)
+ try withContext(arena, escalation.contract_brief_note, raw)
+ else if (report_phase)
+ try withContext(arena, report_anchors.anchor_brief_note, raw)
+ else
+ raw;
+ const based = try withContext(arena, run_context, noted);
if (phase_no == 1) {
prompt.* = based;
} else if (std.mem.indexOf(u8, based, "{{prev}}") != null) {
@@ -369,7 +381,7 @@ pub fn execWorkflow(ctx: ToolCtx, input: Value) !ToolOutput {
// §3b — the edit contract, post-await: a contracted phase whose
// porcelain never moved becomes is_error, which the retry below
// then picks up. #380's honesty flag composes inside it.
- out.* = escalation.contractCheck(gpa, ctx.io, ctx.agent_cwd, contracted, tree_before, vision_ask.flagReport(gpa, fut.await(ctx.io), vision_ask.forPrompt(prompt)));
+ out.* = escalation.contractCheck(gpa, ctx.io, ctx.agent_cwd, contracted, tree_before, report_anchors.anchorCheck(gpa, ctx.io, ctx.agent_cwd, report_phase, vision_ask.flagReport(gpa, fut.await(ctx.io), vision_ask.forPrompt(prompt))));
// #63 — terminal per task, so a UI can settle that row without
// waiting for the phase (and before the retry pass below reruns it).
wfp.task(ctx.io, arena, run_id, phase_no, i + 1, tasks.len, label, if (out.is_error) "failed" else "completed");