graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Merge fix/U5-shared-context-slot
Rach Pradhan8957e5399b6b
diff --cc src/workflow.zigindex b4210b64,e493e898..f61eb30b--- a/src/workflow.zig+++ b/src/workflow.zig@@@ -529,39 -402,38 +547,57 @@@ test "cappedPrevBody bounds a wide phasdefer arena_state.deinit();const a = arena_state.allocator();- // A short result passes through untouched — most outputs never hit the cap.- try std.testing.expectEqualStrings("hi", cappedPrevBody(a, "hi"));+ // A short result passes through untouched — most outputs never hit the+ // cap, at any cap size.+ try std.testing.expectEqualStrings("hi", cappedPrevBody(a, "hi", phase_prev_budget));+ try std.testing.expectEqualStrings("hi", cappedPrevBody(a, "hi", min_task_prev_cap));- // A huge result is capped: head kept, the trailing inspect: pointer kept,- // a truncation marker added, and the full text never lands verbatim.+ // A huge result is capped at several different cap sizes (the divided+ // per-task cap varies with phase width): head kept, the trailing+ // inspect: pointer never truncated away, a truncation marker added, and+ // the full text never lands verbatim.const big = util.repeatBytes("X", 9000) ++ "\n[subagent sa-007-abcd · inspect: .graff/subagents/sa-007-abcd.md]";- const capped = cappedPrevBody(a, big);- try std.testing.expect(capped.len < big.len);- try std.testing.expect(capped.len <= max_prev_per_task + 200); // head + tail + marker overhead- try std.testing.expect(std.mem.indexOf(u8, capped, "truncated") != null);- try std.testing.expect(std.mem.indexOf(u8, capped, "inspect: .graff/subagents/sa-007-abcd.md") != null);- try std.testing.expect(std.mem.indexOf(u8, capped, big) == null);+ for ([_]usize{ phase_prev_budget, 3000, 1500, min_task_prev_cap }) |cap| {+ const capped = cappedPrevBody(a, big, cap);+ try std.testing.expect(capped.len < big.len);+ try std.testing.expect(capped.len <= cap + 200); // head + tail + marker overhead+ try std.testing.expect(std.mem.indexOf(u8, capped, "truncated") != null);+ try std.testing.expect(std.mem.indexOf(u8, capped, "inspect: .graff/subagents/sa-007-abcd.md") != null);+ try std.testing.expect(std.mem.indexOf(u8, capped, big) == null);+ }+}++test "phaseTaskCap divides the phase budget across tasks, floored at min_task_prev_cap (#U3)" {+ // Narrow phases: budget/n_tasks comfortably clears the floor.+ try std.testing.expectEqual(@as(usize, phase_prev_budget), phaseTaskCap(1));+ try std.testing.expectEqual(@as(usize, phase_prev_budget / 2), phaseTaskCap(2));++ // Wide phases (up to max_workflow_tasks, and beyond): the divided cap+ // would fall below min_task_prev_cap, so the floor wins — never an+ // unreadably tiny per-task slice.+ try std.testing.expect(phase_prev_budget / max_workflow_tasks < min_task_prev_cap);+ try std.testing.expectEqual(@as(usize, min_task_prev_cap), phaseTaskCap(max_workflow_tasks));+ try std.testing.expectEqual(@as(usize, min_task_prev_cap), phaseTaskCap(50));}+ test "withContext: set prepends context + blank line; absent/empty is byte-identical (U5)" {+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);+ defer arena_state.deinit();+ const a = arena_state.allocator();++ // Context set: context, blank line, raw task — nothing else.+ const with = try withContext(a, "Repo: zig 0.16, 600-line file cap.", "Implement the thing.");+ try std.testing.expectEqualStrings("Repo: zig 0.16, 600-line file cap.\n\nImplement the thing.", with);++ // Context absent → byte-identical to the raw task (no stray blank line).+ const absent = try withContext(a, "", "Implement the thing.");+ try std.testing.expectEqualStrings("Implement the thing.", absent);++ // Context present but empty string behaves the same as absent.+ const empty = try withContext(a, "", "Do the other thing.");+ try std.testing.expectEqualStrings("Do the other thing.", empty);+ }+test "gateAllows: empty when always runs, else case-insensitive substring (#5)" {try std.testing.expect(gateAllows("anything", "")); // no gate → always runtry std.testing.expect(gateAllows("found 3 ISSUES here", "issues")); // case-insensitive hit