graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
feat(prompt): lean sidecar desc; SPEC.md is the contract
Cursor Agent41f48eb780a8
diff --git a/docs/adr/0024-three-harness-compare-prompt-subagent-rss.md b/docs/adr/0024-three-harness-compare-prompt-subagent-rss.mdindex 9465698a..14dbfe47 100644--- a/docs/adr/0024-three-harness-compare-prompt-subagent-rss.md+++ b/docs/adr/0024-three-harness-compare-prompt-subagent-rss.md@@ -158,3 +158,42 @@ Zig process model, not a prompt trick. grok's token win is real (185kin vs 1.0–1.3M) — shorter catalog + fewer calls (39 vs 88–96). Do notcopy their V8/Rust heap to chase the pass; steal prompt brevity ifanything.++## Why grok-build looked better (and what we took)++Two separate facts. Neither is "their loop is smarter."++**1. `json-stream` is a spec-contract miss, not an architecture miss.**+The hidden check is `iter_json("application/json-seq", " ") == []`.+`SPEC.md` says "Empty payload yields nothing." Public tests never cover+whitespace-only json-seq. Grok's sandbox `lstrip`s JSON whitespace and+returns; graff treated `" "` as a record and `json.loads` failed. Do+not copy their heap for that extra pass.++**2. The lean catalog lied under `-p --yolo`.** Evals run `graff -p --yolo+--lean`. `unattended_note` (the real "AUTO-DENIED" sentence) is *not*+appended when yolo is on (`main.zig` passes `unattended and+!effectiveYolo()`). But `lean_subagent_desc` still said the root's+bash/edit tools are approval-denied and the model should delegate. That+is why graff spent 88–96 calls / 1.0–1.3M input tokens against grok's+39 / 185k: the model spawned children for work the root could do. Grok's+root prompt says do clear local work this turn; only launch Task when+the user asked or the work is independent (same Codex sidecar rule we+already put on the *full* `subagent` desc, not on lean).++**Take (this revision):**++- Rewrite `lean_subagent_desc` to sidecar-only. Keep critical path+ local. Drop the approval-denied claim — that fact lives on+ `unattended_note` only.+- Two sentences on `work_note`: a named `SPEC.md` is the contract; a+ green public test is not the whole spec; empty includes+ whitespace-only unless the spec says otherwise. Does not leak hidden+ checks.++**Still reject:** V8 / grok heap, extra spawn tools, parent-history+fork, share root `prompt_cache_key` with children, IPython.++Live A/B after this revision: `--suite swe --harness+graff-dev-old,graff-dev,grok -j 12`. Goal: graff passes `json-stream`+(5/6) and/or fewer calls/tokens, RSS stays ~9M.diff --git a/docs/adr/README.md b/docs/adr/README.mdindex d809240b..8826e382 100644--- a/docs/adr/README.md+++ b/docs/adr/README.md@@ -34,7 +34,7 @@ record only when you need the evidence or the edge cases.| [0021](0021-transcript-is-the-task-not-the-bus.md) | Transcript is the task, not the event bus: bookkeeping is silent, todos are WORKING, subagents are scouts. || [0022](0022-rlm-is-opt-in-speculative-ptc.md) | `rlm` (Alex Zhang spec-ptc + RLM, Zig) is the default loop. `--old` restores structured-only. Prime persist + `subagent()` only — no IPython. || [0023](0023-codex-subagent-is-sidecar-not-v8.md) | Codex check: take sidecar-vs-critical-path spawn prompts; reject V8 Code Mode, extra spawn tools, and parent-history fork. |-| [0024](0024-three-harness-compare-prompt-subagent-rss.md) | Steal short child briefs + sidecar spawn from grok-build/kimi/dsh; reject root conv-id share, datetime/tree prefix, fork-seed, Harbor. |+| [0024](0024-three-harness-compare-prompt-subagent-rss.md) | Steal short child briefs + sidecar spawn from grok-build/kimi/dsh; lean catalog must not claim root is approval-denied under yolo; reject root conv-id share, datetime/tree prefix, fork-seed, Harbor. |## When to write onediff --git a/src/no_local_tools.zig b/src/no_local_tools.zigindex 67ca4e34..63e661fd 100644--- a/src/no_local_tools.zig+++ b/src/no_local_tools.zig@@ -77,12 +77,14 @@ pub fn blocks(name: []const u8) bool {pub var lean: bool = false;/// The lean keep-list. `subagent` stays despite being the priciest schema-/// (5.1k bytes): in an unattended non-yolo one-shot the root is-/// approval-gated out of bash/edit_file and delegation is the sanctioned-/// path (prompts.unattended_note) — dropping it would strand exactly the-/// runs lean is built for. `load_tool_schemas` stays because lean folds MCP-/// behind that meta tool (mcp_schema_gate.deferAllRuntime) instead of-/// skipping it: the one-shot keeps full MCP capability a load call away.+/// (5.1k bytes): unattended non-yolo still needs a sanctioned delegation+/// path (`prompts.unattended_note` — that note is the approval-denied+/// fact, not this catalog), and yolo/`-p` still needs fan-out for+/// independent work. Dropping it would strand the first case. The compact+/// desc must not claim root is always approval-denied: evals and `-p`+/// run `--yolo`, so that claim was a token/call tax (ADR 0024).+/// `load_tool_schemas` stays because lean folds MCP behind that meta tool+/// (mcp_schema_gate.deferAllRuntime) instead of skipping it.pub const lean_tools = [_][]const u8{"bash","read_file",@@ -120,10 +122,12 @@ pub fn filterLeanSpecs(comptime Spec: type, arena: Allocator, specs: []const Spe/// --lean's compact subagent description: same name and JSON schema, a/// fraction of the prose. The full description is 1.9k bytes of workflow,-/// persona and tier/effort precedence detail a one-shot never exercises;-/// the lean seven keep this tool BECAUSE unattended delegation goes through-/// it, so its price is the one worth shrinking (~350 tokens/turn saved).-pub const lean_subagent_desc = "Spawn a subagent for a self-contained task. It has bash, read_file, edit_file, write_file, codedb and does NOT share your context — the prompt must say everything. Returns its final report. In an unattended session the root's bash/edit tools are approval-denied and a subagent's are not: delegate implementation and command execution to one (tier \"small\" for mechanical work).";+/// persona and tier/effort precedence detail a one-shot never exercises.+/// Sidecar-only (ADR 0023): keep the critical-path next step local. Do+/// not claim root bash/edit are approval-denied — that is true only when+/// `unattended_note` is appended (`unattended and !yolo`). `-p --yolo`+/// (evals) can act locally; the old lie forced extra child turns.+pub const lean_subagent_desc = "Spawn a sidecar for a self-contained task. Child has bash, read_file, edit_file, write_file, codedb; it does NOT share your context — the prompt must say everything. Returns the final report. Keep the critical-path next step local; do not hand off the blocker and wait. Do file and command work yourself this turn; spawn only for independent work.";/// schema.zig chains this after filterLeanSpecs: identical names and JSON/// schemas, compact prose. Returns the input untouched when lean is off.@@ -232,8 +236,8 @@ test "lean: the filter keeps exactly the seven one-shot tools, and allocates nottry std.testing.expectEqualStrings("subagent", kept[2].name);try std.testing.expectEqualStrings("attempt_completion", kept[3].name);// The keep-list is exactly the nine documented tools — subagent stays- // (the unattended delegation path), load_tool_schemas stays (lean folds- // MCP behind it), everything orchestration/meta goes.+ // (unattended-non-yolo delegation + independent fan-out), load_tool_schemas+ // stays (lean folds MCP behind it), everything orchestration/meta goes.try std.testing.expectEqual(@as(usize, 9), lean_tools.len);for (lean_tools) |tool| try std.testing.expect(leanKeeps(tool));try std.testing.expect(!leanKeeps("workflow"));@@ -249,7 +253,9 @@ test "lean: the filter keeps exactly the seven one-shot tools, and allocates notfor (compact) |s| {if (std.mem.eql(u8, s.name, "subagent")) try std.testing.expectEqualStrings(lean_subagent_desc, s.desc) else try std.testing.expectEqualStrings("", s.desc);}- try std.testing.expect(std.mem.indexOf(u8, lean_subagent_desc, "approval-denied") != null); // keeps the one fact delegation needs+ try std.testing.expect(std.mem.indexOf(u8, lean_subagent_desc, "sidecar") != null);+ try std.testing.expect(std.mem.indexOf(u8, lean_subagent_desc, "critical-path") != null);+ try std.testing.expect(std.mem.indexOf(u8, lean_subagent_desc, "approval-denied") == null); // that fact lives on unattended_note, not here}test "#330: filterRootSpecs drops only the gated names, and does not allocate when the gate is off" {diff --git a/src/prompt_snapshot_tests.zig b/src/prompt_snapshot_tests.zigindex 904780b9..0d312692 100644--- a/src/prompt_snapshot_tests.zig+++ b/src/prompt_snapshot_tests.zig@@ -114,6 +114,9 @@ const golden_full_prompt =\\will not change; reread only on stale source, ambiguity, or failure.\\When a Project layout segment is present, it is the tree — read the\\files you need straight from it instead of ls/find exploration turns.+ \\When a named SPEC.md (or equivalent contract) is in the task, satisfy+ \\every clause — a green public test is not the whole spec. Empty input+ \\includes whitespace-only unless the spec says otherwise.\\\\Before a large chunk of work, give a one- or two-sentence heads-up on what\\you are about to do; on long tasks, drop a brief note as each phase lands.diff --git a/src/prompt_text.zig b/src/prompt_text.zigindex ec36c3b3..b045683c 100644--- a/src/prompt_text.zig+++ b/src/prompt_text.zig@@ -160,6 +160,9 @@ pub const work_note =\\will not change; reread only on stale source, ambiguity, or failure.\\When a Project layout segment is present, it is the tree — read the\\files you need straight from it instead of ls/find exploration turns.+ \\When a named SPEC.md (or equivalent contract) is in the task, satisfy+ \\every clause — a green public test is not the whole spec. Empty input+ \\includes whitespace-only unless the spec says otherwise.;/// Always present: narration is a habit, not a capability.